1 | #!/usr/bin/env python
|
---|
2 | #
|
---|
3 | # Wireless Leiden webinterface for (embedded) nodes, printing some basic debug
|
---|
4 | # information, for people who does not like SSH logins
|
---|
5 | #
|
---|
6 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
7 | # Richard van Mansom <richardvm@wirelessleiden.nl>, stripped the webserver
|
---|
8 |
|
---|
9 | class MultiTracebackHook:
|
---|
10 | """A hook to replace sys.excepthook that shows tracebacks in syslog & HTML (using cgitb)"""
|
---|
11 | def __init__(self, ident=None, enable=False):
|
---|
12 | self.ident = ident
|
---|
13 | if enable:
|
---|
14 | self.enable()
|
---|
15 |
|
---|
16 | def __call__(self, etype, evalue, etb):
|
---|
17 | self.handle((etype, evalue, etb))
|
---|
18 |
|
---|
19 | def handle(self, info=None):
|
---|
20 | import cgitb
|
---|
21 | import os
|
---|
22 | import sys
|
---|
23 | import syslog
|
---|
24 | import traceback
|
---|
25 | info = info or sys.exc_info()
|
---|
26 | tb = traceback.format_exception(*info)
|
---|
27 | if self.ident:
|
---|
28 | syslog.openlog(self.ident)
|
---|
29 | prefix = '[%i]' % os.getpid()
|
---|
30 | for line in tb:
|
---|
31 | syslog.syslog(line)
|
---|
32 | cgitb.handler(info)
|
---|
33 |
|
---|
34 | def enable(self):
|
---|
35 | import sys
|
---|
36 | sys.excepthook = self
|
---|
37 |
|
---|
38 | MultiTracebackHook(ident='wlweb', enable=True)
|
---|
39 |
|
---|
40 | from subprocess import *
|
---|
41 | import socket
|
---|
42 |
|
---|
43 | def tailFile(file, lines=10):
|
---|
44 | return("<em>Tail (%i): %s</em><br /><pre>%s</pre>" % (lines,file,Popen(["/usr/bin/tail", '-%s' % lines, file], stdout=PIPE, shell=False).communicate()[0]))
|
---|
45 |
|
---|
46 | def catFile(file):
|
---|
47 | return("<em>File: %s</em><br /><pre>%s</pre>" % (file,Popen(["/bin/cat", file], stdout=PIPE, shell=False).communicate()[0]))
|
---|
48 |
|
---|
49 | def allRoutes():
|
---|
50 | return("<em>netstat -nr</em><br /><pre>%s</pre>" % Popen(["/usr/bin/netstat", "-n", "-r"], stdout=PIPE, shell=False).communicate()[0])
|
---|
51 |
|
---|
52 | def processList():
|
---|
53 | return("<em>ps -ax</em><br /><pre>%s</pre>" % Popen(["/bin/ps", "-a", "-x"], stdout=PIPE, shell=False).communicate()[0])
|
---|
54 |
|
---|
55 | def interfaceList():
|
---|
56 | return("<em>ifconfig -a</em><br /><pre>%s</pre>" % Popen(["/sbin/ifconfig", "-a"], stdout=PIPE, shell=False).communicate()[0])
|
---|
57 |
|
---|
58 | def arpList():
|
---|
59 | return("<em>arp -n -a</em><br /><pre>%s</pre>" % Popen(["/usr/sbin/arp", "-n", "-a"], stdout=PIPE, shell=False).communicate()[0])
|
---|
60 |
|
---|
61 |
|
---|
62 | if __name__ == '__main__':
|
---|
63 | print "Content-Type: text/html\n\n"
|
---|
64 | print "<img src='/static/wl-logo.png' />"
|
---|
65 | print "Welcome to <a href='http://www.wirelessleiden.nl'>Stichting Wireless Leiden</a> host/node <em>%s</em>" % socket.gethostname()
|
---|
66 |
|
---|
67 | items = ['motd', 'messages', 'debug.log', 'dmesg.boot', 'ps', 'ifconfig', 'arp', 'routes']
|
---|
68 | print "<a name='top'><ul>"
|
---|
69 | for item in items:
|
---|
70 | print "<li><a href='#{0}'>{0}</a></li>".format(item)
|
---|
71 | print '</ul>'
|
---|
72 |
|
---|
73 | def item_label():
|
---|
74 | return "<a href='#top'>Back to Top</a><a name='%s'></a><p />" % items.pop(0)
|
---|
75 |
|
---|
76 | print item_label()
|
---|
77 | print catFile('/etc/motd')
|
---|
78 | print item_label()
|
---|
79 | print tailFile('/var/log/messages')
|
---|
80 | print item_label()
|
---|
81 | print tailFile('/var/log/debug.log')
|
---|
82 | print item_label()
|
---|
83 | print catFile('/var/run/dmesg.boot')
|
---|
84 | print item_label()
|
---|
85 | print processList() + "<p />"
|
---|
86 | print item_label()
|
---|
87 | print interfaceList() + "<p />"
|
---|
88 | print item_label()
|
---|
89 | print arpList() + "<p />"
|
---|
90 | print item_label()
|
---|
91 | print allRoutes() + "<p />"
|
---|
92 | print "<em>$Id$</em>"
|
---|