Compare commits
5 Commits
main
...
8a80ff8d93
| Author | SHA1 | Date | |
|---|---|---|---|
|
8a80ff8d93
|
|||
|
2b85ffac49
|
|||
|
24825cced3
|
|||
|
838c0f8064
|
|||
|
919fb1db15
|
@@ -26,7 +26,7 @@ namespace AniNIX.TheRaven {
|
|||||||
public List<String> channels; //This is the list of channels to join
|
public List<String> channels; //This is the list of channels to join
|
||||||
public List<String> whitelist; //This is the list of admin users.
|
public List<String> whitelist; //This is the list of admin users.
|
||||||
public List<String> blacklist; // This is the list of blocked people.
|
public List<String> blacklist; // This is the list of blocked people.
|
||||||
public String helpText = "Available commands are r.d <dice test>, r.heartbeat, r.magic8, r.math <math problem>, r.msg <memo for admin>, r.raven, r.searches, r.tinyurl <url>, r.wikidiff \"one\" \"other\", and r.uptime";
|
public String helpText = "Available commands are r.d <dice test>, r.ip, r.magic8, r.math <math problem>, r.msg <memo for admin>, r.raven, r.searches, r.tinyurl <url>, r.wikidiff \"one\" \"other\", and r.uptime";
|
||||||
// This is the text to send when people ask for help -- this is configurable to allow for skinning
|
// This is the text to send when people ask for help -- this is configurable to allow for skinning
|
||||||
public List<String> searches; //These are the searches
|
public List<String> searches; //These are the searches
|
||||||
public String searchesIndex; //This is the helptext for the searches
|
public String searchesIndex; //This is the helptext for the searches
|
||||||
@@ -75,11 +75,12 @@ namespace AniNIX.TheRaven {
|
|||||||
ReportMessage.Log(Verbosity.Verbose,"Reading login info");
|
ReportMessage.Log(Verbosity.Verbose,"Reading login info");
|
||||||
try {
|
try {
|
||||||
Dictionary<String,String> loginDefaults = conf.ReadSection("Login");
|
Dictionary<String,String> loginDefaults = conf.ReadSection("Login");
|
||||||
|
Dictionary<String,String> apiDefaults = conf.ReadSection("API");
|
||||||
this.Host = loginDefaults["host"];
|
this.Host = loginDefaults["host"];
|
||||||
this.Port = Int32.Parse(loginDefaults["port"]);
|
this.Port = Int32.Parse(loginDefaults["port"]);
|
||||||
this.Nick = loginDefaults["username"];
|
this.Nick = loginDefaults["username"];
|
||||||
this._nickServPass = loginDefaults["password"];
|
this._nickServPass = loginDefaults["password"];
|
||||||
this._netListener = new RavenNetListener(loginDefaults["password"]);
|
this._netListener = new RavenNetListener(apiDefaults["password"],Int32.Parse(apiDefaults["port"]));
|
||||||
|
|
||||||
channels=new List<String>();
|
channels=new List<String>();
|
||||||
foreach (String channel in conf.ReadSectionLines("Rooms")) {
|
foreach (String channel in conf.ReadSectionLines("Rooms")) {
|
||||||
@@ -268,7 +269,7 @@ namespace AniNIX.TheRaven {
|
|||||||
/// Read from the connection, and for each message act appropriately.
|
/// Read from the connection, and for each message act appropriately.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoopOnTraffic() {
|
public void LoopOnTraffic() {
|
||||||
ReportMessage.Log(Verbosity.Verbose,"Looping on trafffic now! We're useful!");
|
ReportMessage.Log(Verbosity.Verbose,"Looping on traffic now! We're useful!");
|
||||||
// Start a network listener to allow relaying traffic via ncat into IRCd.
|
// Start a network listener to allow relaying traffic via ncat into IRCd.
|
||||||
this._netListener.NetListener(this._connection);
|
this._netListener.NetListener(this._connection);
|
||||||
// Loop on main connect to ircd
|
// Loop on main connect to ircd
|
||||||
|
|||||||
@@ -126,17 +126,9 @@ namespace AniNIX.TheRaven {
|
|||||||
}
|
}
|
||||||
connection.Write(send);
|
connection.Write(send);
|
||||||
return;
|
return;
|
||||||
case "r.heartbeat":
|
case "r.ip":
|
||||||
try {
|
send.PrivMsg(ExecuteCommand.Run("curl -s $(ip r list | grep default | cut -f 3 -d \" \"):80 | grep \"WAN IP\" | cut -f 13 -d \">\" | cut -f 1 -d \"<\""),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
|
||||||
String[] byLine = ExecuteCommand.Run("heartbeat-client").Split('\n');
|
|
||||||
for (int i = 0; i < byLine.Length; i++) {
|
|
||||||
send.PrivMsg(byLine[i],incoming.user);
|
|
||||||
connection.Write(send);
|
connection.Write(send);
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.ToString();
|
|
||||||
send.PrivMsg("Can't get heartbeat",incoming.user);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
case "r.searches":
|
case "r.searches":
|
||||||
send.PrivMsg(theRaven.searchesIndex,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
|
send.PrivMsg(theRaven.searchesIndex,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace AniNIX.TheRaven {
|
|||||||
public class RavenNetListener {
|
public class RavenNetListener {
|
||||||
|
|
||||||
private String _key;
|
private String _key;
|
||||||
|
private int _port;
|
||||||
private Connection _ircdConnection;
|
private Connection _ircdConnection;
|
||||||
|
|
||||||
private void _RavenSend(Connection ircdConnection, String channel, String message) {
|
private void _RavenSend(Connection ircdConnection, String channel, String message) {
|
||||||
@@ -26,9 +27,9 @@ namespace AniNIX.TheRaven {
|
|||||||
while (true) {
|
while (true) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open a new listener on localhost port 9501
|
// Open a new listener on port
|
||||||
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
|
IPAddress ipAddress = IPAddress.Parse("0.0.0.0");
|
||||||
TcpListener listener = new TcpListener(ipAddress, 9501);
|
TcpListener listener = new TcpListener(ipAddress, this._port );
|
||||||
listener.Start();
|
listener.Start();
|
||||||
// Accept all connections
|
// Accept all connections
|
||||||
while (true)
|
while (true)
|
||||||
@@ -40,6 +41,7 @@ namespace AniNIX.TheRaven {
|
|||||||
string received = "";
|
string received = "";
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
received += Convert.ToChar(data[i]);
|
received += Convert.ToChar(data[i]);
|
||||||
|
ReportMessage.Log(Verbosity.Verbose,String.Format("RavenNetListener received: [{0}]",received));
|
||||||
String[] bySpace = received.Split(' ');
|
String[] bySpace = received.Split(' ');
|
||||||
// If the key matches, ...
|
// If the key matches, ...
|
||||||
if (this._key.Equals(bySpace[0])) {
|
if (this._key.Equals(bySpace[0])) {
|
||||||
@@ -73,8 +75,9 @@ namespace AniNIX.TheRaven {
|
|||||||
ReportMessage.Log(Verbosity.Verbose,"Started.");
|
ReportMessage.Log(Verbosity.Verbose,"Started.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public RavenNetListener(String key) {
|
public RavenNetListener(String key, int port) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
|
this._port = port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
ravensend/Makefile
Normal file
33
ravensend/Makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
CONFDIR = ${pkgdir}/usr/local/etc/TheRaven
|
||||||
|
LIST = ravensend ravensend-daemon
|
||||||
|
|
||||||
|
compile:
|
||||||
|
@echo Nothing to do.
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf pkg src
|
||||||
|
|
||||||
|
test: compile
|
||||||
|
./ravensend -h
|
||||||
|
|
||||||
|
install: compile
|
||||||
|
mkdir -p ${pkgdir}/usr/local/bin
|
||||||
|
for i in ${LIST}; do install -m 0755 -o raven -g raven $$i ${pkgdir}/usr/local/bin; done
|
||||||
|
# Hook for Systemd
|
||||||
|
mkdir -p ${pkgdir}/usr/lib/systemd/system/
|
||||||
|
install -m 0644 -o raven -g raven ./ravensend-daemon.service ${pkgdir}/usr/lib/systemd/system/
|
||||||
|
mkdir -p ${pkgdir}/usr/local/etc/
|
||||||
|
install -m 0640 -o raven -g raven ./ravensend-daemon.yml ${pkgdir}/usr/local/etc/
|
||||||
|
|
||||||
|
reverse: ${pkgdir}/usr/lib/systemd/system/ravensend-daemon.service
|
||||||
|
cp ${pkgdir}/usr/lib/systemd/system/ravensend-daemon.service .
|
||||||
|
for i in ${LIST}; do cp ${pkgdir}/usr/lib/systemd/system/$$i .; done
|
||||||
|
|
||||||
|
checkperm: ${pkgdir}/opt/raven.mono
|
||||||
|
for i in ${LIST}; do chown -R raven: ${pkgdir}/usr/local/bin/$$i; chmod 0755 ${pkgdir}/usr/local/bin/$$i; done
|
||||||
|
chown raven: ${pkgdir}/usr/lib/systemd/system/ravensend-daemon.service
|
||||||
|
chmod 0644 ${pkgdir}/usr/lib/systemd/system/ravensend-daemon.service
|
||||||
|
|
||||||
|
diff:
|
||||||
|
for i in ${LIST}; do diff ${pkgdir}/usr/lib/systemd/system/$$i $$i; done
|
||||||
|
diff ${pkgdir}/usr/lib/systemd/system/ravensend-daemon.service ./ravensend-daemon.service
|
||||||
47
ravensend/PKGBUILD
Normal file
47
ravensend/PKGBUILD
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Maintainer: DarkFeather <ircs://aninix.net:6697/darkfeather>
|
||||||
|
depends=('python' 'python-yaml' 'python-flask' 'bash' 'nmap>=7.91-1')
|
||||||
|
makedepends=('make>=4.2' 'Uniglot')
|
||||||
|
checkdepends=()
|
||||||
|
optdepends=()
|
||||||
|
pkgname="ravensend"
|
||||||
|
pkgver="$(git describe --tag --abbrev=0)"."$(git rev-parse --short HEAD)"
|
||||||
|
pkgrel=1
|
||||||
|
pkgrel() {
|
||||||
|
echo $(( `git log "$(git describe --tag --abbrev=0)"..HEAD | grep -c commit` + 1 ))
|
||||||
|
}
|
||||||
|
epoch="$(git log | grep -c commit)"
|
||||||
|
pkgdesc="$(head -n 1 README.md)"
|
||||||
|
arch=("x86_64")
|
||||||
|
url="$(git config remote.origin.url | sed 's/.git$//')"
|
||||||
|
license=('custom')
|
||||||
|
groups=()
|
||||||
|
provides=("${pkgname}")
|
||||||
|
conflicts=()
|
||||||
|
replaces=("${pkgname,,}", "aninix-${pkgname,,}")
|
||||||
|
backup=()
|
||||||
|
options=()
|
||||||
|
install=
|
||||||
|
changelog=
|
||||||
|
source=()
|
||||||
|
noextract=()
|
||||||
|
md5sums=()
|
||||||
|
validpgpkeys=()
|
||||||
|
|
||||||
|
prepare() {
|
||||||
|
git pull
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
make -C ..
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
chmod -R u+r ../pkg
|
||||||
|
make -C .. test
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
export pkgdir="${pkgdir}"
|
||||||
|
make -C .. install
|
||||||
|
install -D -m644 ../../LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||||
|
}
|
||||||
15
ravensend/README.md
Normal file
15
ravensend/README.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
This package provides a couple files that will allow you to send messages via TheRaven to an IRC daemon.
|
||||||
|
|
||||||
|
# ravensend
|
||||||
|
|
||||||
|
This CLI allows you to send a message to a channel using TheRaven. Simplest invocation is as below:
|
||||||
|
|
||||||
|
```
|
||||||
|
ravensend -c '#thechannel' -f ./the.conf -m 'some message'
|
||||||
|
```
|
||||||
|
|
||||||
|
Assuming TheRaven sits in #thechannel and the user has the rights to read the.conf, the message should go through.
|
||||||
|
|
||||||
|
# ravensend-daemon
|
||||||
|
|
||||||
|
This daemon allows you to translate webhook inputs from services like Graylog to be sent by TheRaven.
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# TODO Add comments
|
# File: ravensend
|
||||||
|
#
|
||||||
|
# Description: This file sends a message to the Raven API
|
||||||
|
#
|
||||||
|
# Package: AniNIX/ravensend
|
||||||
|
# Copyright: WTFPL
|
||||||
|
#
|
||||||
|
# Author: DarkFeather <ircs://aninix.net:6697/DarkFeather>
|
||||||
|
|
||||||
# Default variables
|
# Default variables
|
||||||
unset channel
|
unset channel
|
||||||
unset message
|
unset message
|
||||||
unset passphrase
|
unset passphrase
|
||||||
export file="/usr/local/etc/TheRaven/raven.conf"
|
export file="/usr/local/etc/TheRaven/raven.conf"
|
||||||
export port="8373"
|
unset port
|
||||||
export host="localhost"
|
export host="localhost"
|
||||||
|
|
||||||
# Show help
|
# Show help
|
||||||
@@ -17,8 +24,15 @@ function usage() {
|
|||||||
echo "Passphrase is pulled from Raven config, set to ${file}"
|
echo "Passphrase is pulled from Raven config, set to ${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAPIConfigValue() {
|
||||||
|
# Get the api config value
|
||||||
|
# param attr: the attribute to look for
|
||||||
|
# returns: the attribute's value
|
||||||
|
egrep -A 10 '^\[ API \]$' "$file" | egrep -m 1 '^'"$1"'=' | sed 's/^'"$1"'=//'
|
||||||
|
}
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while getopts 'c:hm:p:P:t:v' OPTION; do
|
while getopts 'c:f:hm:p:t:v' OPTION; do
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
c) channel="${OPTARG}" ;;
|
c) channel="${OPTARG}" ;;
|
||||||
f) file="${OPTARG}" ;;
|
f) file="${OPTARG}" ;;
|
||||||
@@ -30,6 +44,9 @@ while getopts 'c:hm:p:P:t:v' OPTION; do
|
|||||||
*) usage; exit 1 ;;
|
*) usage; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
if [ -z "$port" ]; then
|
||||||
|
port="$(getAPIConfigValue port)"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check inputs.
|
# Check inputs.
|
||||||
if [ -z "$channel" ] || [ -z "$message" ] || [ -z "$file" ] || [ -z "$port" ] || [ -z "$host" ]; then
|
if [ -z "$channel" ] || [ -z "$message" ] || [ -z "$file" ] || [ -z "$port" ] || [ -z "$host" ]; then
|
||||||
@@ -38,11 +55,12 @@ if [ -z "$channel" ] || [ -z "$message" ] || [ -z "$file" ] || [ -z "$port" ] ||
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to get the passphrase.
|
# Try to get the passphrase.
|
||||||
passphrase="$(egrep -m 1 '^password=' "$file" | sed 's/^password=//')"
|
passphrase="$(getAPIConfigValue password)"
|
||||||
if [ -z "$passphrase" ]; then
|
if [ -z "$passphrase" ]; then
|
||||||
echo Couldn\'t identify passphrase.
|
echo Couldn\'t identify passphrase.
|
||||||
exit 2;
|
exit 2;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Send format to socket
|
# Send format to socket
|
||||||
printf "%s %s %s" "$passphrase" "$channel" "$message" | ncat "$host" "$port"
|
printf "%s %s %s" "$passphrase" "$channel" "$message" | ncat "$host" "$port"
|
||||||
43
ravensend/ravensend-daemon
Executable file
43
ravensend/ravensend-daemon
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# File: ravensend-daemon
|
||||||
|
#
|
||||||
|
# Description: This daemon proxies Graylog-style webhooks to TheRaven
|
||||||
|
#
|
||||||
|
# Package: AniNIX/ravensend
|
||||||
|
# Copyright: WTFPL
|
||||||
|
#
|
||||||
|
# Author: DarkFeather <ircs://aninix.net:6697/DarkFeather>
|
||||||
|
|
||||||
|
# Thanks to https://towardsdatascience.com/intro-to-webhooks-and-how-to-receive-them-with-python-d5f6dd634476 for the tutorial
|
||||||
|
import socket
|
||||||
|
import yaml
|
||||||
|
from flask import Flask,request,json
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
configvars = []
|
||||||
|
|
||||||
|
@app.route('/',methods=['POST'])
|
||||||
|
def hello():
|
||||||
|
|
||||||
|
data = request.json
|
||||||
|
print(data["event"]["message"] + ' at ' + data["event"]["timestamp"])
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
|
try:
|
||||||
|
s.connect((configvars["server"],int(configvars["port"])))
|
||||||
|
s.settimeout(1)
|
||||||
|
mesg = configvars["password"] + ' #' + configvars["channel"] + ' ' + data["event"]["message"] + ' at ' + data["event"]["timestamp"]
|
||||||
|
print(mesg)
|
||||||
|
s.send(mesg.encode())
|
||||||
|
print('Sent to TheRaven')
|
||||||
|
except:
|
||||||
|
print('Could not send to TheRaven')
|
||||||
|
return data
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
config = open('./ravensend-daemon.yml','r')
|
||||||
|
configvars = yaml.safe_load(config)
|
||||||
|
print(configvars)
|
||||||
|
config.close()
|
||||||
|
app.run(host='0.0.0.0',port=configvars["webhookport"],debug=False)
|
||||||
15
ravensend/ravensend-daemon.service
Normal file
15
ravensend/ravensend-daemon.service
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=AniNIX/ravensend Daemon
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/local/bin/ravensend-daemon
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
KillMode=process
|
||||||
|
Restart=always
|
||||||
|
User=raven
|
||||||
|
Group=raven
|
||||||
|
WorkingDirectory=/usr/local/etc/
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
5
ravensend/ravensend-daemon.yml
Normal file
5
ravensend/ravensend-daemon.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
channel: test123
|
||||||
|
password: sample
|
||||||
|
port: 9902
|
||||||
|
server: 127.0.0.1
|
||||||
|
webhookport: 8374
|
||||||
34
ravensend/sample.conf
Normal file
34
ravensend/sample.conf
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[ Login ]
|
||||||
|
host=localhost
|
||||||
|
port=6667
|
||||||
|
username=TheRavenTest
|
||||||
|
password=dumb
|
||||||
|
|
||||||
|
[ API ]
|
||||||
|
port=9902
|
||||||
|
password=sample
|
||||||
|
|
||||||
|
[ Whitelist ]
|
||||||
|
DarkFeather
|
||||||
|
|
||||||
|
[ Blacklist ]
|
||||||
|
|
||||||
|
[ Notifications ]
|
||||||
|
|
||||||
|
[ Rooms ]
|
||||||
|
test123
|
||||||
|
|
||||||
|
[ Searches ]
|
||||||
|
r.google|http://google.com/search?q=|+|Google
|
||||||
|
r.image|http://images.google.com/search?tbm=isch&q=|+|Google Images
|
||||||
|
r.wiki|http://en.wikipedia.org/wiki/|_|Wikipedia
|
||||||
|
r.sound|http://www.soundcloud.com/search?q=|%20|Soundcloud
|
||||||
|
r.dict|http://www.merriam-webster.com/dictionary/|+|Dictionary
|
||||||
|
r.tropes|http://tvtropes.org/pmwiki/search_result.php?cx=partner-pub-6610802604051523%3Aamzitfn8e7v&cof=FORID%3A10&ie=ISO-8859-1&siteurl=&ref=&ss=&siteurl=tvtropes.org%2F&ref=www.google.com%2F&ss=5135j1581675j28&q=|+|Tropes
|
||||||
|
r.yt|https://www.youtube.com/results?search_query=|+|YouTube
|
||||||
|
r.urban|http://www.urbandictionary.com/define.php?term=|+|Urban Dictionary
|
||||||
|
r.man|http://www.die.net/search/?q=|+|Man-page
|
||||||
|
r.hoogle|https://www.haskell.org/hoogle/?hoogle=|+|Hoogle
|
||||||
|
r.so|http://stackoverflow.com/search?q=|+|Stack Overflow
|
||||||
|
r.aninix|https://aninix.net/|_|AniNIX
|
||||||
|
r.map|https://www.google.com/maps/search/|+|Google Maps
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
[ Login ]
|
[ Login ]
|
||||||
host=localhost
|
host=localhost
|
||||||
port=6667
|
port=6667
|
||||||
username=TheRaven
|
username=TheRavenTest
|
||||||
password=password
|
password=password
|
||||||
|
|
||||||
|
[ API ]
|
||||||
|
port=9902
|
||||||
|
password=sample
|
||||||
|
|
||||||
[ Whitelist ]
|
[ Whitelist ]
|
||||||
Admin
|
DarkFeather
|
||||||
|
|
||||||
[ Blacklist ]
|
[ Blacklist ]
|
||||||
|
|
||||||
[ Notifications ]
|
[ Notifications ]
|
||||||
|
|
||||||
[ Rooms ]
|
[ Rooms ]
|
||||||
TheRaven
|
test123
|
||||||
|
|
||||||
[ Searches ]
|
[ Searches ]
|
||||||
r.google|http://google.com/search?q=|+|Google
|
r.google|http://google.com/search?q=|+|Google
|
||||||
|
|||||||
Reference in New Issue
Block a user