cryptonas-branches/pythonrewrite/bin2/CryptoBoxWebserverSites.py
age 697d5f9b0c webserver, sites and settings splitted
included some new functions from the perl file
the clearsilver templates have to be modified next
2006-08-24 00:06:19 +00:00

152 lines
5.4 KiB
Python
Executable file

import CryptoBox
import CryptoBoxWebserverSettings
import CryptoBoxWebserverRender
website = CryptoBoxWebserverRender.CryptoBoxWebserverRender()
class CryptoBoxWebserverSites(CryptoBox.CryptoBoxProps, CryptoBoxWebserverSettings.CryptoBoxWebserverSettings):
'''
url2func = {'index':'show_status','doc':'show_doc','logs':'show_log'}
'''
def __prepare(self, csname="show_status"):
'''this method handles stuff that all sites need as preparation
self.settings is filled be the following methodcall
thus every rendered site will get actual values from the configfile
after that the site-method may set individual values too
'''
self.setSettings(self)
self.settings
## default site to render is 'show_status'
self.settings["Data.Action"] = csname
#TODO: check ssl status
def __sanitize_input(self,data):
#TODO: don't let evil cracker fuck up your code
return data
def __check_config(self):
pass
def __check_init_running(self):
pass
######################################################################
## put real sites down here and don't forget to expose the mat the end
def logs(self):
'''be careful to name this method just "log" seems to be a
reserved word'''
self.__prepare("show_log")
return website.render(self)
def status(self):
self.__prepare("show_status")
if not self.__check_config():
self.settings["Data.Warning"] = "NotInitialized"
self.settings["Data.Action"] = "form_init"
elif self.__check_init_running():
self.settings["Data.Warning"] = "InitNotFinished"
self.settings["Data.Action"] = "empty"
self.settings["Data.Redirect.Action"] = "form_config"
self.settings["Data.Redirect.Delay"] = "30"
else:
self.settings["Data.Action"] = "show_status"
self.settings["Data.Redirect.Delay"] = "60"
return website.render(self)
def doc(self,action="",page="",weblang=""):
#TODO: action is unnessessary, remove here and from all templates
self.__prepare("show_doc")
if not page == "":
self.settings["Data.Doc.Page"] = page
#self.log.info(page)
#self.log.info(self.settings)
else:
self.settings["Data.Doc.Page"] ="CryptoBoxUser"
#self.log.info(page)
#self.log.info(self.settings)
return website.render(self)
def system(self,type=""):
self.__prepare("form_system")
if type == "reboot":
self.settings["Data.Success"] = "ReBoot"
self.settings["Data.Redirect.Action"] = "show_status"
self.settings["Data.Redirect.Delay"] = "180"
self.log.info("TODO: call function for system reboot")
elif type == "poweroff":
self.settings["Data.Success"] = "PowerOff"
self.log.info("TODO: call function for system shutdown")
else:
self.log.warn("someone tried to shutdown the system")
return website.render(self)
def index(self):
self.__prepare("show_status")
return website.render(self)
'''
## DONE: this functions are pythonized
#################### show_log #######################
##################### doc ############################
##################### poweroff ######################
##################### reboot ########################
## but there are even more TODO
##################### check for a harddisk ##########################
# catch this error, to prevent all following actions from execution #
#####################################################################
elif not True: #TODO: replace True with check for hard disk is_harddisk_available()
settings["Data.Error"] = "NoHardDisk"
#-------------------------------------------------------#
# here you may define all cases that require a harddisk #
#-------------------------------------------------------#
################ umount_do #######################
elif action == "unmount_do":
if device == "":
#TODO: debug message: "invalid device: "+ device
settings["Data.Warning"] = "InvalidDevice"
settings["Data.Action"] = "empty"
elif not True: #TODO: replace True with check_config()
settings["Data.Warning"] = "NotInitialized"
settings["Data.Action"] = "form_init"
elif True: #TODO: replace True with check_init_running()
settings["Data.Warning"] = "InitNotFinished"
settings["Data.Action"] = "empty"
settings["Data.Redirect.Action"] = "form_config"
settings["Data.Redirect.Delay"] = "30"
elif not True: #TODO: replace True with check_mounted(device)
settings["Data.Warning"] = "NotMounted"
settings["Data.Action"] = "show_volume"
else: #unmount
#TODO: replace this line with umount_vol(device)
if True: #TODO: replace True with check_mounted(device)
settings["Data.Warning"] = "UmountFailed"
settings["Data.Action"] = "show_volume"
else:
settings["Data.Action"] = "show_volume"
################ mount_do ########################
elif action == "mount_do":
if device != "":
pass #TODO: is_encrypted = check_device_encryption(device)
if device == "":
#TODO: debug_msg(DEBUG_INFO, "invalid device: " + device)
settings["Data.Warning"] = "InvalidDevice"
settings["Data.Action"] = "empty"
elif not True: #TODO: replace True with check_config()
settings["Data.Warning"] = "NotInitialized"
settings["Data.Action"] = "form_init"
#at cryptobox.pl line 568
'''
############################################################################
## to make the sites visible through the webserver they must be exposed here
index.exposed = True
doc.exposed = True
logs.exposed = True
system.exposed = True
status.exposed = True