Skip to content
Snippets Groups Projects
Commit e57891fb authored by Helge Jung's avatar Helge Jung
Browse files

add ffpb-specific module + config

parent c6526821
No related branches found
No related tags found
No related merge requests found
ffpb.cfg 0 → 100644
[core]
nick = ffpb-status
user = ffpb-statusbot
name = Status-Bot von Freifunk Paderborn - http://paderborn.freifunk.net
#host = irc.hackint.org
host = kthx.de
use_ssl = True
verify_ssl = False
port = 9999
owner = HeJ
admins = oscar-, Barbarossa
channels = #ffpb-gurus, #ffpb
prefix = !
enable = admin,ffpb,ip,reload
timeout = 120
extra = modules/
logdir = ../logs
pid_dir = ..
[db]
userdb_type = sqlite
userdb_file = ffpb.sqlite
from __future__ import print_function
import willie
import netaddr
import urllib2
import re
import os
import subprocess
@willie.module.commands('status')
def ffpb_status(bot, trigger):
"""Status des FFPB-Netzes: Anzahl (aktiver) Knoten + Clients"""
response = urllib2.urlopen('http://nodecount.paderborn.freifunk.net/')
html = response.read()
m = re.search('<div id="nodecount">\s*(\d+)\s*</div>', html)
nodecount = int(m.group(1))
bot.say('nodecount = {}'.format(nodecount))
def ffpb_get_address(name):
peerfilename = '/home/ffpb-statusbot/knoten/' + name
peer_mac = None
if os.path.exists(peerfilename):
peerfile = open(peerfilename, "r")
for line in peerfile:
if line.startswith("# MAC:"):
peer_mac = line[6:].strip()
peerfile.close()
print("peer '", name, "': file '", peerfilename, "', MAC ", peer_mac, sep='')
if not (peer_mac is None):
return str(netaddr.EUI(peer_mac).ipv6_link_local())
return None
@willie.module.commands('ping')
def ffpb_ping(bot, trigger):
"""Ping FFPB-Knoten"""
target_name = trigger.group(2)
if target_name is None or len(target_name) == 0:
bot.say('Alter, wen soll ich denn pingen? Einmal mit Profis arbeiten -.-')
return
target = ffpb_get_address(target_name)
if target is None:
bot.say('Kein Plan wer mit \'' + target_name + '\' gemeint ist :/')
return
if target.startswith('fe80::'):
target = 'fdca:ffee:ff12:132:' + target[6:]
print("ping '", target , '"', sep='')
result = os.system('ping6 -c 1 -W 2 ' + target + ' 2>/dev/null')
if result == 0:
bot.say('Knoten "' + target_name + '" antwortet \o/')
elif result == 1 or result == 256:
bot.say('Keine Antwort von "' + target_name + '" :-(')
else:
bot.say('Uh oh, irgendwas ist kaputt. Chef, ping result = ' + str(result) + ' - darf ich das essen?')
@willie.module.commands('exec-on-peer')
def ffpb_remoteexec(bot, trigger):
"""Remote Execution fuer FFPB_Knoten"""
bot_params = trigger.group(2).split(' ',1)
if len(bot_params) != 2:
bot.say('Wenn du nicht sagst wo mach ich remote execution bei dir!')
bot.say('Tipp: !exec-on-peer <peer> <cmd>')
return
target_name = bot_params[0]
target_cmd = bot_params[1]
if not trigger.admin:
bot.say('Captcha required: https://xkcd.com/565/')
return
target = ffpb_get_address(target_name)
if target is None:
bot.say('Kein Plan wer mit \'' + target_name + '\' gemeint ist :/')
if target.startswith('fe80::'):
target = 'fdca:ffee:ff12:132:' + target[6:]
cmd = 'ssh -6 -l root ' + target + ' -- "' + target_cmd + '"'
print("REMOTE EXEC = " + cmd)
try:
result = subprocess.check_output(['ssh', '-6n', '-l', 'root', '-o', 'BatchMode=yes', '-o','StrictHostKeyChecking=no', target, target_cmd], stderr=subprocess.STDOUT, shell=False)
lines = str(result).splitlines()
bot.say('exec-on-peer(' + target_name + '): ' + str(len(lines)) + ' Zeilen (zeige max. 8):')
for line in lines[0:8]:
bot.say(line)
except subprocess.CalledProcessError, e:
bot.say('Fehler '+str(e.returncode)+' bei exec-on-peer('+target_name+'): ' + e.output)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment