Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Status-Bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Freifunk Hochstift
Status-Bot
Commits
e57891fb
Commit
e57891fb
authored
10 years ago
by
Helge Jung
Browse files
Options
Downloads
Patches
Plain Diff
add ffpb-specific module + config
parent
c6526821
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ffpb.cfg
+28
-0
28 additions, 0 deletions
ffpb.cfg
modules/ffpb.py
+97
-0
97 additions, 0 deletions
modules/ffpb.py
with
125 additions
and
0 deletions
ffpb.cfg
0 → 100644
+
28
−
0
View file @
e57891fb
[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
This diff is collapsed.
Click to expand it.
modules/ffpb.py
0 → 100644
+
97
−
0
View file @
e57891fb
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment