#!/usr/bin/env python # # Wireless Leiden webinterface for (embedded) nodes, printing some basic debug # information, for people who does not like SSH logins # # Rick van der Zwet # Richard van Mansom , stripped the webserver class MultiTracebackHook: """A hook to replace sys.excepthook that shows tracebacks in syslog & HTML (using cgitb)""" def __init__(self, ident=None, enable=False): self.ident = ident if enable: self.enable() def __call__(self, etype, evalue, etb): self.handle((etype, evalue, etb)) def handle(self, info=None): import cgitb import os import sys import syslog import traceback info = info or sys.exc_info() tb = traceback.format_exception(*info) if self.ident: syslog.openlog(self.ident) prefix = '[%i]' % os.getpid() for line in tb: syslog.syslog(line) cgitb.handler(info) def enable(self): import sys sys.excepthook = self MultiTracebackHook(ident='wlweb', enable=True) from subprocess import * import socket def tailFile(file, lines=10): return("Tail (%i): %s
%s
" % (lines,file,Popen(["/usr/bin/tail", '-%s' % lines, file], stdout=PIPE, shell=False).communicate()[0])) def catFile(file): return("File: %s
%s
" % (file,Popen(["/bin/cat", file], stdout=PIPE, shell=False).communicate()[0])) def allRoutes(): return("netstat -nr
%s
" % Popen(["/usr/bin/netstat", "-n", "-r"], stdout=PIPE, shell=False).communicate()[0]) def processList(): return("ps -ax
%s
" % Popen(["/bin/ps", "-a", "-x"], stdout=PIPE, shell=False).communicate()[0]) def interfaceList(): return("ifconfig -a
%s
" % Popen(["/sbin/ifconfig", "-a"], stdout=PIPE, shell=False).communicate()[0]) def arpList(): return("arp -n -a
%s
" % Popen(["/usr/sbin/arp", "-n", "-a"], stdout=PIPE, shell=False).communicate()[0]) if __name__ == '__main__': print "Content-Type: text/html\n\n" print "" print "Welcome to Stichting Wireless Leiden host/node %s" % socket.gethostname() items = ['motd', 'messages', 'debug.log', 'dmesg.boot', 'ps', 'ifconfig', 'arp', 'routes'] print "' def item_label(): return "Back to Top

" % items.pop(0) print item_label() print catFile('/etc/motd') print item_label() print tailFile('/var/log/messages') print item_label() print tailFile('/var/log/debug.log') print item_label() print catFile('/var/run/dmesg.boot') print item_label() print processList() + "

" print item_label() print interfaceList() + "

" print item_label() print arpList() + "

" print item_label() print allRoutes() + "

" print "$Id$"