diff --git a/ravensend/Makefile b/ravensend/Makefile new file mode 100644 index 0000000..4eb8f51 --- /dev/null +++ b/ravensend/Makefile @@ -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 diff --git a/ravensend/PKGBUILD b/ravensend/PKGBUILD new file mode 100644 index 0000000..3e0af7c --- /dev/null +++ b/ravensend/PKGBUILD @@ -0,0 +1,47 @@ +# Maintainer: 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" +} diff --git a/ravensend/README.md b/ravensend/README.md new file mode 100644 index 0000000..3e95876 --- /dev/null +++ b/ravensend/README.md @@ -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. diff --git a/ravensend b/ravensend/ravensend similarity index 64% rename from ravensend rename to ravensend/ravensend index f6d686f..57431db 100755 --- a/ravensend +++ b/ravensend/ravensend @@ -1,13 +1,20 @@ #!/bin/bash -# TODO Add comments +# File: ravensend +# +# Description: This file sends a message to the Raven API +# +# Package: AniNIX/ravensend +# Copyright: WTFPL +# +# Author: DarkFeather # Default variables unset channel unset message unset passphrase export file="/usr/local/etc/TheRaven/raven.conf" -export port="8373" +unset port export host="localhost" # Show help @@ -17,8 +24,15 @@ function usage() { 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 -while getopts 'c:hm:p:P:t:v' OPTION; do +while getopts 'c:f:hm:p:t:v' OPTION; do case "$OPTION" in c) channel="${OPTARG}" ;; f) file="${OPTARG}" ;; @@ -30,6 +44,9 @@ while getopts 'c:hm:p:P:t:v' OPTION; do *) usage; exit 1 ;; esac done +if [ -z "$port" ]; then + port="$(getAPIConfigValue port)" +fi # Check inputs. 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 # Try to get the passphrase. -passphrase="$(egrep -m 1 '^password=' "$file" | sed 's/^password=//')" +passphrase="$(getAPIConfigValue password)" if [ -z "$passphrase" ]; then echo Couldn\'t identify passphrase. exit 2; fi + # Send format to socket printf "%s %s %s" "$passphrase" "$channel" "$message" | ncat "$host" "$port" diff --git a/ravensend/ravensend-daemon b/ravensend/ravensend-daemon new file mode 100755 index 0000000..2813e3b --- /dev/null +++ b/ravensend/ravensend-daemon @@ -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 + +# 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) diff --git a/ravensend/ravensend-daemon.service b/ravensend/ravensend-daemon.service new file mode 100644 index 0000000..d6cf38c --- /dev/null +++ b/ravensend/ravensend-daemon.service @@ -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 diff --git a/ravensend/ravensend-daemon.yml b/ravensend/ravensend-daemon.yml new file mode 100644 index 0000000..4ba848e --- /dev/null +++ b/ravensend/ravensend-daemon.yml @@ -0,0 +1,5 @@ +channel: test123 +password: sample +port: 9902 +server: 127.0.0.1 +webhookport: 8374 diff --git a/ravensend/sample.conf b/ravensend/sample.conf new file mode 100644 index 0000000..f88fec9 --- /dev/null +++ b/ravensend/sample.conf @@ -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