diff options
author | James Meyer <james.meyer@operamail.com> | 2013-01-05 02:40:34 (GMT) |
---|---|---|
committer | James Meyer <james.meyer@operamail.com> | 2013-01-05 02:40:34 (GMT) |
commit | 8535c8a04075454c676a548dbec40673b0ad62e0 (patch) | |
tree | ae7a7d6294cc96e1fd9e45556a51fec5a0fa14a3 /abs/core/supplemental-web/contents/process.py | |
parent | 6623efa259ecac69b28c204f6100700a774adb2d (diff) | |
download | linhes_pkgbuild-8535c8a04075454c676a548dbec40673b0ad62e0.zip linhes_pkgbuild-8535c8a04075454c676a548dbec40673b0ad62e0.tar.gz linhes_pkgbuild-8535c8a04075454c676a548dbec40673b0ad62e0.tar.bz2 |
supplemental-web: Two major additions here.
1) introduce the static dev node mapping as produced by autocard. Currently located under system->List static dev nodes for tuners. This link will pull in mappings from the MBE and all SLAVE boxes. The query will pull the data from the host each time it's requested, so the slave machines must be on to see the mapping. The data is pulled over http from the slave box by calling cardlist.cgi, which will read in /etc/udev/mv-persisten-video.description.
2) Add the ability to upload and download system backup files from the MBE. Also reworked the css to make it a tad prettier.
refs #893
refs #892
Diffstat (limited to 'abs/core/supplemental-web/contents/process.py')
-rw-r--r-- | abs/core/supplemental-web/contents/process.py | 124 |
1 files changed, 100 insertions, 24 deletions
diff --git a/abs/core/supplemental-web/contents/process.py b/abs/core/supplemental-web/contents/process.py index 22ffb0f..988ebfc 100644 --- a/abs/core/supplemental-web/contents/process.py +++ b/abs/core/supplemental-web/contents/process.py @@ -4,6 +4,8 @@ import cgi import os import socket import time +import StringIO + try: import cgitb cgitb.enable() @@ -45,10 +47,10 @@ def getform(theform, valuelist, notpresent='', nolist=False): data[field] = notpresent else: # the field is present - print type(theform[field]) + #print type(theform[field]) if type(theform[field]) != type([]): # is it a list or a single item - print type(theform[field]) + #print type(theform[field]) data[field] = theform[field].value else: if not nolist: @@ -100,18 +102,43 @@ def go_backup(myhost): myhostname = socket.gethostname() results="Nothing happened" command= "sudo /usr/LH/bin/lh_system_backup_job" - print command - command2="sleep 1; /home/xymon/server/ext/hbnotes.py" + #print command + + command2="sleep 1; sudo -u nobody /home/xymon/server/ext/hbnotes.py" results=os.popen(command,'r') os.popen(command2,'r') return results -def go_restore(restorefile,myhost): +def go_download_backup(dl_file): + # Actual File Content will go hear. + dlf = "/data/storage/disk0/backup/system_backups/%s" %dl_file + fo = open(dlf, "rb") + + str = fo.read() + fo.close() + + # HTTP Header + print "Content-Type:application/octet-stream; name=\"%s\"\r\n;" %(dl_file) + print "Content-Disposition: attachment; filename=\"%s\"\r\n;" %(dl_file) + print "Content-Length: %d" % len(str) + print "" + + print str + return results + + +def go_restore(restorefile,myhost,prestore): myhostname = socket.gethostname() + psc = '' + if prestore == "on": + psc = "partial" + + if myhostname.strip() == myhost.strip(): - localcommand="sudo /usr/LH/bin/lh_system_restore_job " - command= localcommand + restorefile + command="sudo /usr/LH/bin/lh_system_restore_job %s %s" %(restorefile , psc) + + else: #this should never execute @@ -119,15 +146,37 @@ def go_restore(restorefile,myhost): sshcmd+=myhost.strip() cmd=' "sudo /usr/bin/restore_job.sh " ' command=sshcmd + cmd + restorefile + " 2>&1 " - print command + #print command results=os.popen(command,'r') return results +def go_upload(up_file): + saveDir = "/data/storage/disk0/backup/system_backups/" + fPath = "%s/%s" % (saveDir, up_file.filename) + buf = up_file.file.read() + bytes = len(buf) + sFile = open(fPath, 'wb') + sFile.write(buf) + sFile.close() + results=["<b>%s</b> uploaded (%d bytes)." %(up_file.filename, bytes)] + line = '''The backup has been uploaded and is now available for restore. + To restore from the file, check "Restore database" then select the file from the drop down menu''' + + + results.append(line) + + command2="sleep 1; sudo -u nobody /home/xymon/server/ext/hbnotes.py" + os.popen(command2,'r') + + + return results + + def go_optimize(myhost): #myhostname = socket.gethostname() #if myhostname.strip() == myhost.strip(): command="/usr/LH/bin/optimize_mythdb.py" - print command + #print command results=os.popen(command,'r') #else: #results='This host does not run a database' @@ -137,17 +186,17 @@ def go_update(myhost,update_type): cmd=" call pacman update_system " cmd+=update_type command="/usr/bin/func \"" + myhost.strip() + "*\" " + cmd - print command + #print command results=os.popen(command,'r') return results def go_updateall(allupdate_type): - cmd=" sudo /usr/bin/update_system_all " - cmd+=allupdate_type - command= cmd + " 2>&1 " - results=os.popen(command,'r') - return results + cmd=" sudo /usr/bin/update_system_all " + cmd+=allupdate_type + command= cmd + " 2>&1 " + results=os.popen(command,'r') + return results def go_shutdown(myhost): @@ -209,6 +258,9 @@ def go_kill(myhost,kill_type): return results + + + mainpage = ''' <html><head> <style type="text/css">@import "/frame.css";</style> @@ -223,11 +275,12 @@ error = ''' result = ''' <h1>%s of %s</h1> ''' -possible_parameters = ['param1', 'param2', 'param3', 'param4','hiddenparam','param5','param6'] +possible_parameters = ['param1', 'param2', 'param3', 'param4','hiddenparam','param5','param6','param7','uFile','param8'] if __name__ == '__main__': - cgiprint(contentheader) # content header - cgiprint() # finish headers with blank line + + #cgiprint(contentheader) # content header + #cgiprint() # finish headers with blank line theform = cgi.FieldStorage() #print theform @@ -246,19 +299,31 @@ if __name__ == '__main__': hidden = formdict['hiddenparam'] all_update_type=formdict['param5'] kill_type = formdict['param6'] + dl_file = formdict['param7'] + try: + up_file = theform['uFile'] + except: + pass + try: + prestore = theform['param8'].value + except: + prestore = "off" body = result % (radio, hidden) - print mainpage % body + #print mainpage % body selection=radio myhost=hidden.lower() if selection == "Restore": - mylogfile=go_restore(name,myhost) + mylogfile=go_restore(name,myhost,prestore) elif selection == "Backup": mylogfile=go_backup(myhost) + elif selection == "Dbackup": + mylogfile=go_download_backup(dl_file) + elif selection == "Update": mylogfile=go_update(myhost,update_type) elif selection == "Shutdown": @@ -275,14 +340,25 @@ if __name__ == '__main__': mylogfile=go_shutdownall() elif selection == "Kill": mylogfile=go_kill(myhost,kill_type) + elif selection == "Upload": + mylogfile = go_upload(up_file) + + + cgiprint(contentheader) # content header + cgiprint() # finish headers with blank line + print mainpage % body + + #box=''' </br> </br> + #<div style="border: 1px solid #aaa; width:700px; height:700px; overflow:auto; color:#FFF;text-align:left;"> + #<code id="box" style="display: block; height: 700px; width: 700px; overflow: auto;"> + #''' + box='''</br> </br> + <div id="resultbox" > - box=''' </br> </br> - <div style="border: 1px solid #aaa; width:700px; height:700px; overflow:auto; color:#FFF;text-align:left;"> - <code id="box" style="display: block; height: 700px; width: 700px; overflow: auto;"> ''' endbox=''' - </code> + </div> ''' javascript=''' |