diff options
author | Cecil <knoppmyth@gmail.com> | 2011-12-09 17:18:27 (GMT) |
---|---|---|
committer | Cecil <knoppmyth@gmail.com> | 2011-12-09 17:18:27 (GMT) |
commit | c034db2c880091379f7e58c2938a9689d78fbaa9 (patch) | |
tree | 8a074205a2f3bf6ee7fb5945c53e1a1618d41973 /abs/core/supplemental-web/contents/mvp_process.py | |
parent | 73b42144585c603fc64e7b1d6a126ceb7c486870 (diff) | |
parent | b0c5755ade92ee5b76a6d56248e64254876bc931 (diff) | |
download | linhes_pkgbuild-c034db2c880091379f7e58c2938a9689d78fbaa9.zip linhes_pkgbuild-c034db2c880091379f7e58c2938a9689d78fbaa9.tar.gz linhes_pkgbuild-c034db2c880091379f7e58c2938a9689d78fbaa9.tar.bz2 |
Merge branch 'testing' of ssh://cesman@linhes.org/mount/repository/linhes_pkgbuild into testing
Diffstat (limited to 'abs/core/supplemental-web/contents/mvp_process.py')
-rw-r--r-- | abs/core/supplemental-web/contents/mvp_process.py | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/abs/core/supplemental-web/contents/mvp_process.py b/abs/core/supplemental-web/contents/mvp_process.py new file mode 100644 index 0000000..b01ed8b --- /dev/null +++ b/abs/core/supplemental-web/contents/mvp_process.py @@ -0,0 +1,195 @@ +#!/usr/bin/python +import sys +import cgi +import os +import socket +import time +import shutil +try: + import cgitb + cgitb.enable() +except ImportError: + sys.stderr = sys.stdout +def cgiprint(inline=''): + sys.stdout.write(inline) + sys.stdout.write('\r\n') + sys.stdout.flush() +contentheader = 'Content-Type: text/html' + +thepage = '''<html><head> +<title>%s</title> +</head><body> +%s +</body></html> +''' +h1 = '<h1>%s</h1>' + +def getform(theform, valuelist, notpresent='', nolist=False): + """ + This function, given a CGI form as a + FieldStorage instance, extracts the + data from it, based on valuelist + passed in. Any non-present values are + set to '' - although this can be + changed. (e.g. to return None so you + can test for missing keywords - where + '' is a valid answer but to have the + field missing isn't.) It also takes a + keyword argument 'nolist'. If this is + True list values only return their + first value. + """ + data = {} + for field in valuelist: + + + if not theform.has_key(field): + # if the field is not present (or was empty) + data[field] = notpresent + else: + # the field is present + data[field] = theform.getlist(field) + +# print type(theform[field]) + return data + +def getall(theform, nolist=False): + """ + Passed a form (cgi.FieldStorage + instance) return *all* the values. + This doesn't take into account + multipart form data (file uploads). + It also takes a keyword argument + 'nolist'. If this is True list values + only return their first value. + """ + data = {} + for field in theform.keys(): + # we can't just iterate over it, but must use the keys() method + if type(theform[field]) == type([]): + if not nolist: + data[field] = theform.getlist(field) + + else: + data[field] = theform.getfirst(field) + else: + data[field] = theform[field].value + + + return data + +def isblank(indict): + """ + Passed an indict of values it checks + if any of the values are set. Returns + True if the indict is empty, else + returns False. I use it on the a form + processed with getform to tell if my + CGI has been activated without any + form values. + """ + for key in indict.keys(): + if indict[key]: + return False + return True + + +def update_mvp_list(maclist): + outfile = open("/etc/dnsmasq.mvpmc.conf","w") + mvpline="dhcp-boot=net:mvp,dongle.bin" + mvpmacline='dhcp-host=net:mvp,%s' + results="The following media mvp devices have been added:" + results+='</br>' + havemvp = "false" + #print maclist + for i in range(len(maclist)): + if maclist[i] != '': +# print mvpmacline % maclist[i] + outfile.write(mvpmacline % maclist[i] + '\n' ) + havemvp="true" + results+=maclist[i] + results+='</br>' + if havemvp == "true": +# print mvpline + outfile.write(mvpline + '\n' ) + outfile.flush + outfile.close + #time.sleep(5) + + else: + outfile.close + return results + + +mainpage = ''' + <html><head> + <style type="text/css">@import "/frame.css";</style> + <!--<meta http-equiv="refresh" content="6">--> + <title>Receiving a Form</title> + </head><body>%s</body></html>''' + +error = ''' + + <h2>Removed all media mvp devices</h2>''' + +result = ''' + <h1>%s</h1> +''' +possible_parameters = ['activemvp', 'othermac','hiddenparam'] + +if __name__ == '__main__': + cgiprint(contentheader) # content header + cgiprint() # finish headers with blank line + + theform = cgi.FieldStorage() + #print theform + formdict = getform(theform, possible_parameters) + #print possible_parameters + #print formdict + oldurl = '/mvpmc.shtml' + if isblank(formdict): + body = error + all_active=[] + else: + all_active=[] + activemac_checkbox = formdict['activemvp'] + for i in range(len(activemac_checkbox)): + active_string=activemac_checkbox[i] + active_string=active_string.strip() + all_active.append(active_string) + body = result % ("MVP mac address") + + + + print mainpage % body + # mylogfile=update_mvp_list(all_active) + + + box=''' + <div style="border: 1px solid #aaa; width:600px; height:500px; overflow:auto; color:#FFF;text-align:left;"> + <code id="box" style="display: block; height: 500px; width: 600px; overflow: auto;"> + ''' + + endbox=''' + </code> + </div> + ''' + javascript=''' + <script type="text/javascript"> + var objDiv = document.getElementById("box"); + objDiv.scrollTop = objDiv.scrollHeight; + </script> + ''' + if all_active != []: + mylogfile=update_mvp_list(all_active) + command="sudo /sbin/sv stop dnsmasq" + os.system(command) + command="sudo /sbin/sv start dnsmasq" + os.system(command) + print box + print mylogfile + print endbox + print '<a href=', oldurl, ' > Back </a> ' + #print oldurl + print javascript + |