diff --git a/util/webconfig/htdocs/cgi-bin/config.py b/util/webconfig/htdocs/cgi-bin/config.py new file mode 100755 index 0000000000..468a9efdde --- /dev/null +++ b/util/webconfig/htdocs/cgi-bin/config.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +import os +import sys +sys.path.insert(0, "../modules") +sys.path.insert(0, "./modules") +import blocks +import cgi + + +form = cgi.FieldStorage() +treedir = None + +if form.has_key('freebios'): + treedir = form['freebios'].value +else: + blocks.IncompleteData(form,"freebios") + sys.exit() + +if form.has_key('manufacturer'): + mfr = form['manufacturer'].value +else: + blocks.IncompleteData(form,"manufacturer") + sys.exit() + +if form.has_key('motherboard'): + mb = form['motherboard'].value +else: + blocks.IncompleteData(form,"motherboard") + sys.exit() + +blocks.PrintHeader() + +print '
' + +mbdir = treedir + mfr + "/" + mb + "/" + +dir_fail = None +try: + os.chdir(mbdir) +except: + dir_fail = "TRUE" + +if dir_fail: + print '

Cannot change to motherboard directory %s

' % mbdir + print '

Please reselect motherboard

' +else: + print '

Please fill in the following:

' + print '' + print '' +# print '' +print '
' + +blocks.PrintTrailer() diff --git a/util/webconfig/htdocs/cgi-bin/config2.py b/util/webconfig/htdocs/cgi-bin/config2.py new file mode 100755 index 0000000000..ab0296d02a --- /dev/null +++ b/util/webconfig/htdocs/cgi-bin/config2.py @@ -0,0 +1,88 @@ +#!/usr/bin/python +import os +import sys +sys.path.insert(0, "../modules") +sys.path.insert(0, "./modules") +import blocks +import cgi + + +form = cgi.FieldStorage() +treedir = None + +if form.has_key('freebios'): + treedir = form['freebios'].value +else: + blocks.IncompleteData(form,"freebios") + sys.exit() + +if form.has_key('manufacturer'): + mfr = form['manufacturer'].value +else: + blocks.IncompleteData(form,"manufacturer") + sys.exit() + +if form.has_key('motherboard'): + mb = form['motherboard'].value +else: + blocks.IncompleteData(form,"motherboard") + sys.exit() + +blocks.PrintHeader() + +print '
' + +mbdir = treedir + mfr + "/" + mb + "/" + +dir_fail = None +try: + os.chdir(mbdir) +except: + dir_fail = "TRUE" + +if dir_fail: + print '

Cannot change to motherboard directory %s

' % mbdir + print '

Please reselect motherboard

' +else: + print '

here I am, %s

' % mbdir + print '

Please select your options:
' + LBDefOptions = [ + 'CONFIGURE_L2_CACHE', + 'HAVE_FRAMEBUFFER', + 'PROTECTED_MODE_STARTUP', + 'SERIAL_CONSOLE', + 'SROM_CONSOLE', + 'UPDATE_MICROCODE', + 'USE_DOC_MIL' + ] + LBBoolOptions = [ + 'USE_CACHE_RAM', + 'USE_ELF_BOOT', + 'USE_GENERIC_ROM', + 'USE_TSUNAMI_TIGBUS_ROM' + ] + LBHexOptions = [ + 'TIG_KERNEL_START' + ] + LBTextOptions = [ + 'CMD_LINE' + ] + for Opt in LBDefOptions: + print '%s
' % (Opt,Opt) + for Opt in LBBoolOptions: + print '%s
' % (Opt,Opt) + print '


' + for Opt in LBHexOptions: + print '%s
' % (Opt,Opt) + print '
(enter Hex address e.g. 0x20000)
' % Opt + print '
' + for Opt in LBTextOptions: + print '%s
' % (Opt,Opt) + print '
(enter Text arguments e.g. "root=/dev/hda1")
' % Opt + print '
' + +print '' +# print '' +print '
' + +blocks.PrintTrailer() diff --git a/util/webconfig/htdocs/cgi-bin/index.py b/util/webconfig/htdocs/cgi-bin/index.py new file mode 100755 index 0000000000..07f8a08f49 --- /dev/null +++ b/util/webconfig/htdocs/cgi-bin/index.py @@ -0,0 +1,72 @@ +#!/usr/bin/python +import os +import sys +sys.path.insert(0, "../modules") +sys.path.insert(0, "./modules") +import blocks +import cgi + +blocks.PrintHeader() + +form = cgi.FieldStorage() +treedir = None +if form.has_key("freebios"): + showtderr = "TRUE" + treedir = form['freebios'].value +else: + showtderr = None + treedir = "/usr/src/freebios/src/mainboard/" + +mfr = None +if form.has_key('manufacturer'): + mfr = form['manufacturer'].value + +if mfr: + print '
' +else: + print '' + +dir_fail = None +try: + os.chdir(treedir) +except: + dir_fail = "TRUE" + +if dir_fail: + if showtderr: + print '

Cannot change to requested directory %s

' % treedir + print '

Please re-enter the location of the tree directory:
' + else: + print '

Please enter path to LinuxBIOS tree directory
or simply click "Enter" to accept the default %s

' % treedir + print '

' % treedir +else: + print '

Tree directory: %s

' % (treedir,treedir) + if mfr: + print '

Manufacturer: %s

' % (mfr,mfr) + print 'Motherboard:
' + else: + print 'Manufacturer:
' + +print '' +# print '' +print '
' + +blocks.PrintTrailer() diff --git a/util/webconfig/htdocs/cgi-bin/test.py b/util/webconfig/htdocs/cgi-bin/test.py new file mode 100755 index 0000000000..78053723d2 --- /dev/null +++ b/util/webconfig/htdocs/cgi-bin/test.py @@ -0,0 +1,3 @@ +#!/usr/bin/python +import cgi +cgi.test() diff --git a/util/webconfig/htdocs/images/linuxbioslogo.jpg b/util/webconfig/htdocs/images/linuxbioslogo.jpg new file mode 100644 index 0000000000..800b224f9a Binary files /dev/null and b/util/webconfig/htdocs/images/linuxbioslogo.jpg differ diff --git a/util/webconfig/htdocs/index.html b/util/webconfig/htdocs/index.html new file mode 100644 index 0000000000..2b95fab1aa --- /dev/null +++ b/util/webconfig/htdocs/index.html @@ -0,0 +1,5 @@ + + +Go to the LinuxBIOSConfiguration Script + + diff --git a/util/webconfig/htdocs/modules/blocks.py b/util/webconfig/htdocs/modules/blocks.py new file mode 100755 index 0000000000..f8a3bd2205 --- /dev/null +++ b/util/webconfig/htdocs/modules/blocks.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +def PrintHeader(): + print """Content-type: text/html + + + + + + + LinuxBIOS: Web Configuration new + + + + + + + + + + + + + + + + + + + +
+ The LinuxBIOS logo + +  
+ +  LinuxBIOS:
+ +    Configuration + +
+
+ +  
+ home
+ bogus
+
+
+    
+
+  
+""" + +def PrintTrailer(): + print """ +
 
+
+ www.linuxbios.org + + © 1999 University of California | + Disclaimer +
+ + +""" + +def IncompleteData(CForm,OffendingItem): + PrintHeader() + print "

ERROR: Missing Data for Field %s

" % OffendingItem + print "

Dump of form data follows:

" + print "" + print "" + for FormKey in CForm.keys(): + print "" % (FormKey, CForm[FormKey]) + print "
KeyValue
%s%s
" + PrintTrailer() diff --git a/util/webconfig/htdocs/modules/blocks.pyc b/util/webconfig/htdocs/modules/blocks.pyc new file mode 100644 index 0000000000..3cdd9ce8b8 Binary files /dev/null and b/util/webconfig/htdocs/modules/blocks.pyc differ diff --git a/util/webconfig/server/pyserv.py b/util/webconfig/server/pyserv.py new file mode 100755 index 0000000000..e3127e7ba5 --- /dev/null +++ b/util/webconfig/server/pyserv.py @@ -0,0 +1,328 @@ +#!/usr/bin/python +# +# pyserv.py: Minimal web server for the LinuxBIOS webconfig utility +# +# I typically edit in vim with ":set ts=2 sw=2 ai sm"; in case +# you're using emacs or something and this looks horrible to you, +# you now know why. +# +# Copyright 2001 Robert Drzyzgula, bob@drzyzgula.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# +# Release history +# +# 0.1 Initial release, July 18 2001, R. Drzyzgula +# 0.2 Fixed some typos, added environment variables, July 19 2001, R. Drzyzgula +# + +# +# Need some modules +# + +from BaseHTTPServer import HTTPServer +from CGIHTTPServer import CGIHTTPRequestHandler +import cgi +import os +import sys +import getopt + +# +# Print out the usage syntax +# + +def usage(): + print 'Usage: %s [-d] [-t] [-h] [-f freebios] [-s httpdir] [-c cgidir] \\' % sys.argv[0] + print ' [-l logdir] [-i ipaddr] [-p port]' + print ' %s [--debug] [--test] [--help] [--freebios=] [--httpdir=] \\' % sys.argv[0] + print ' [--cgidir=] [--log=] [--ip=] [--port=]' + print 'Where:' + print ' "-d" or "--debug" enables diagnostic output' + print ' "-t" or "--test" processes arguments but doesn\'t run the server' + print ' "-h" or "--help" prints this message' + print ' "freebios" is the top level of the freebios cvs tree' + print ' default is environment variable FREEBIOS or /usr/src/freebios' + print ' "httpdir" is the directory containing files to be served out ' + print ' default is environment variable HTTPDIR or /util/webconfig/htdocs/' + print ' "cgidir" is the directory containing cgi scripts to be served out ' + print ' default is environment variable CGIDIR or /cgi-bin/' + print ' cgidir is always a subdirectory of the httpdir root' + print ' "logdir" is the directory where the server logs should be written' + print ' default is environment variable LOGDIR or /util/webconfig/var/' + print ' "ipaddr" is the ip address to bind to; it can be a hostname' + print ' default is 127.0.0.1 (localhost)' + print ' CAUTION: Changing this could expose this server to external traffic!' + print ' "port" is the port number to bind to' + print ' default is 8083' + sys.exit() + +# +# sift through all the defaults, command-line arguments and envionment +# variables to get stuff set by the rules: Command line has precedance +# over environment, which has precedance over defaults... +# + +def process_args(): + # + + debug = testrun = freebios = httpdir = cgidir = logdir = ipaddr = port = None + + # + # Call getopt to parse any arguments... + # + + try: + optlist, tail = getopt.getopt(sys.argv[1:], 'dtf:h:c:l:i:p:', \ + ['debug','test','freebios=','httpdir=','cgidir=','log=','ip=','port=']) + except (getopt.GetoptError,RuntimeError), e: + usage() + + # + # Let's see what the user set... + # + + for option, argument in optlist: + if option in ("-d", "--debug"): + debug = "TRUE" + elif option in ("-t", "--test"): + testrun = "TRUE" + elif option in ("-h", "--help"): + usage() + sys.exit() + elif option in ("-f", "--freebios"): + freebios = argument + elif option in ("-s", "--httpdir"): + httpdir = argument + elif option in ("-c", "--cgidir"): + cgidir = argument + elif option in ("-l", "--log"): + logdir = argument + elif option in ("-i", "--ip"): + ipaddr = argument + elif option in ("-p", "--port"): + port = argument + # + # If it ain't a listed argument, we don't have any use for it... + # + + if debug: + if tail: + sys.stderr.write("extranious arguments ignored:\n") + sys.stderr.write(repr(tail)) + sys.stderr.write("\n") + + # + # set freebios; must end in /, environment has priority over default... + # + + if freebios == None: + try: + freebios = os.environ['FREEBIOS'] + except KeyError: + freebios = "/usr/src/freebios/" + if freebios[-1:] != "/": + freebios = freebios + "/" + + # + # set httpdir; environment has priority over default, + # if value doesn't start with "/", prefix with "freebios" + # Note that "freebios" better be settled by now... + # + + if httpdir == None: + try: + httpdir = os.environ['HTTPDIR'] + except KeyError: + httpdir = freebios + "util/webconfig/htdocs/" + if httpdir[:1] != "/": + httpdir = freebios + httpdir + if httpdir[-1:] != "/": + httpdir = httpdir + "/" + + # + # set cgidir... + # + + if cgidir == None: + try: + cgidir = os.environ['CGIDIR'] + except KeyError: + cgidir = "/cgi-bin" + + # + # set logdir... + # + + if logdir == None: + try: + logdir = os.environ['LOGDIR'] + except KeyError: + logdir = freebios + "util/webconfig/var/" + if logdir[:1] != "/": + logdir = freebios + logdir + if logdir[-1:] != "/": + logdir = logdir + "/" + + # + # set the IP address to bind to... + # by default we bind only to localhost, + # meaning that this web server should only + # be visible from the local system. + # setting ipaddr to be "ALL" will result in + # the server binding to all addresses on + # the local machine. + # + # WARNING: Setting this to anything but + # localhost (127.0.0.1) will expose this + # server to external networks -- this carries + # additional security risks. + # + + if ipaddr == None: + ipaddr = "127.0.0.1" + + # + # Set the port to bind to. Make sure you don't already + # have a server on that port. Ports 80, 8000 and 8080 + # are quite commonly use, we default to 8083 + # + + if port == None: + port = 8083 + + # + # send the results back on up... + # + + return(debug,testrun,freebios,httpdir,cgidir,logdir,ipaddr,port) + +# +# Main... +# + +(debug,testrun,freebios,httpdir,cgidir,logdir,ipaddr,port) = process_args() + +if debug: + sys.stderr.write("freebios = %s\n" % freebios) + sys.stderr.write("cgidir = %s\n" % cgidir) + sys.stderr.write("httpdir = %s\n" % httpdir) + sys.stderr.write("logdir = %s\n" % logdir) + sys.stderr.write("ipaddr = %s\n" % ipaddr) + sys.stderr.write("port = %s\n" % port) + +# +# Stuff some stuff away in environment variables so the +# CGI scripts can pick them up... +# +# +# Actually, this doesn't work because the CGIHTTPRequestHandler +# hand-crafts the environment according to CGI standards. +# It could be made to work by reworking a bunch of the +# handler code but I think that's probably a bad idea... +# +# os.environ['LBWC_FB'] = freebios +# os.environ['LBWC_CD'] = cgidir +# os.environ['LBWC_HD'] = httpdir +# os.environ['LBWC_LD'] = logdir +# +# +# We should now have everything we need to start up the web server... +# + +try: + os.chdir(httpdir) +except: + print "Cannot change directory to %s. Exiting now." % httpdir + sys.exit() + +# +# Extend the HTTPServer class +# We do this because the default log_message function doesn't +# flush the output after each write. +# + +class MyRequestHandler(CGIHTTPRequestHandler): + logfile = sys.stderr + def log_message(self,format, *args): + logfile.write("%s - - [%s] %s\n" % + (self.address_string(), self.log_date_time_string(), format%args)) + logfile.flush() + +# +# Instantiate the server +# + +if ipaddr == "ALL": + serv = HTTPServer(("",port),MyRequestHandler) +else: + serv = HTTPServer((ipaddr,port),MyRequestHandler) + +# +# Set the cgi directory +# + +MyRequestHandler.cgi_directories = [cgidir] + +# +# Switch stdout to logdir/pyservlog +# + +openerror = None +try: + logfile = open(logdir+"pyservlog","a+") +except: + openerror = "TRUE" +if openerror: + if debug: + sys.stderr.write("Caution: Can't create %s, logging to stdout\n" % logdir+"pyservlog") +else: + MyRequestHandler.logfile = logfile + +# +# Generate file containing this process's pid +# + +pid = os.getpid() +openerror = None +try: + pidlog = open(logdir+"pid","w+") +except: + openerror = "TRUE" +if openerror: + if debug: + sys.stderr.write("Caution: Can't create %s, writing to log\n" % logdir+"pid") + print pid + sys.stdout.flush() +else: + pidlog.write("%s\n" % pid) + pidlog.close() + +# +# Print a message and exit if this is just a test run... +# + +if testrun: + if debug: + sys.stderr.write("this is where we'd run serv.serve_forever()\n") + sys.exit() + +# +# Start the server... +# + +serv.serve_forever() + +# diff --git a/util/webconfig/var/pid b/util/webconfig/var/pid new file mode 100644 index 0000000000..3dc414fc05 --- /dev/null +++ b/util/webconfig/var/pid @@ -0,0 +1 @@ +12917 diff --git a/util/webconfig/var/pyservlog b/util/webconfig/var/pyservlog new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/util/webconfig/var/pyservlog @@ -0,0 +1 @@ +