Splitting ravensend to its own package
This commit is contained in:
parent
59ae84bbbb
commit
919fb1db15
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
|
||||
|
||||
# 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
|
||||
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"
|
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
|
Loading…
Reference in New Issue
Block a user