plugin interface changed: now we use classes (inherited by CryptoBoxPlugin) instead of plain scripts
added some log entries use threading module instead of "fork" for background formatting redirection for "network" plugin fixed empty return value of plugins defaults to plugin overview pagemaster
parent
52ccaeb530
commit
56e954d1c4
@ -1,49 +1,64 @@
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
def doAction(hdf, cbox, store=None, year=0, month=0, day=0, hour=0, minute=0):
|
||||
import datetime
|
||||
__prepareFormData(hdf, cbox)
|
||||
if store:
|
||||
try:
|
||||
year, month, day = int(year), int(month), int(day)
|
||||
hour, minute = int(hour), int(minute)
|
||||
new_date = datetime.datetime(year, month, day, hour, minute)
|
||||
except ValueError:
|
||||
hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [
|
||||
cbox.prefs["Programs"]["super"],
|
||||
cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
||||
"plugin",
|
||||
os.path.join(os.path.dirname(__file__), "root_action.py"),
|
||||
"%02d%02d%02d%02d%d" % (month, day, hour, minute, year)])
|
||||
proc.communicate()
|
||||
if proc.returncode == 0:
|
||||
return "form_system"
|
||||
import CryptoBoxPlugin
|
||||
|
||||
|
||||
class date(CryptoBoxPlugin.CryptoBoxPlugin):
|
||||
|
||||
def doAction(self, store=None, year=0, month=0, day=0, hour=0, minute=0):
|
||||
import datetime
|
||||
if store:
|
||||
try:
|
||||
year, month, day = int(year), int(month), int(day)
|
||||
hour, minute = int(hour), int(minute)
|
||||
new_date = datetime.datetime(year, month, day, hour, minute)
|
||||
except ValueError:
|
||||
self.hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
||||
self.__prepareFormData()
|
||||
return "form_date"
|
||||
date = "%02d%02d%02d%02d%d" % (month, day, hour, minute, year)
|
||||
if self.__setDate(date):
|
||||
self.cbox.log.info("changed date to: %s" % date)
|
||||
self.hdf["Data.Success"] = "Plugins.date.DateChanged"
|
||||
return None
|
||||
else:
|
||||
## a failure should usually be an invalid date (we do not check it really)
|
||||
self.cbox.log.info("failed to set date: %s" % date)
|
||||
self.hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
||||
self.__prepareFormData()
|
||||
return "form_date"
|
||||
else:
|
||||
hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
||||
self.__prepareFormData()
|
||||
return "form_date"
|
||||
else:
|
||||
return "form_date"
|
||||
|
||||
|
||||
def getStatus(cbox):
|
||||
return str(__getCurrentDate())
|
||||
def getStatus(self):
|
||||
return str(self.__getCurrentDate())
|
||||
|
||||
|
||||
def __prepareFormData(self):
|
||||
date = self.__getCurrentDate()
|
||||
self.hdf[self.hdf_prefix + "year"] = date.year
|
||||
self.hdf[self.hdf_prefix + "month"] = date.month
|
||||
self.hdf[self.hdf_prefix + "day"] = date.day
|
||||
self.hdf[self.hdf_prefix + "hour"] = date.hour
|
||||
self.hdf[self.hdf_prefix + "minute"] = date.minute
|
||||
|
||||
def __prepareFormData(hdf, cbox):
|
||||
date = __getCurrentDate()
|
||||
hdf["Data.Plugins.date.year"] = date.year
|
||||
hdf["Data.Plugins.date.month"] = date.month
|
||||
hdf["Data.Plugins.date.day"] = date.day
|
||||
hdf["Data.Plugins.date.hour"] = date.hour
|
||||
hdf["Data.Plugins.date.minute"] = date.minute
|
||||
|
||||
def __getCurrentDate(self):
|
||||
import datetime
|
||||
return datetime.datetime(2000,1,1).now()
|
||||
|
||||
|
||||
def __getCurrentDate():
|
||||
import datetime
|
||||
return datetime.datetime(2000,1,1).now()
|
||||
def __setDate(self, date):
|
||||
import subprocess
|
||||
import os
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [
|
||||
self.cbox.prefs["Programs"]["super"],
|
||||
self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
||||
"plugin",
|
||||
os.path.join(self.pluginDir, "root_action.py"),
|
||||
date])
|
||||
proc.communicate()
|
||||
return proc.returncode == 0
|
||||
|
||||
|
@ -1,20 +1,23 @@
|
||||
import CryptoBoxPlugin
|
||||
|
||||
def doAction(hdf, cbox):
|
||||
__prepareFormData(hdf,cbox)
|
||||
return "show_log"
|
||||
class logs(CryptoBoxPlugin.CryptoBoxPlugin):
|
||||
|
||||
def doAction(self):
|
||||
self.__prepareFormData()
|
||||
return "show_log"
|
||||
|
||||
def getStatus(cbox):
|
||||
return "%s:%s:%s" % (
|
||||
cbox.prefs["Log"]["Level"],
|
||||
cbox.prefs["Log"]["Destination"],
|
||||
cbox.prefs["Log"]["Details"])
|
||||
|
||||
def getStatus(self):
|
||||
return "%s:%s:%s" % (
|
||||
self.cbox.prefs["Log"]["Level"],
|
||||
self.cbox.prefs["Log"]["Destination"],
|
||||
self.cbox.prefs["Log"]["Details"])
|
||||
|
||||
def __prepareFormData(hdf, cbox):
|
||||
hdf["Data.Plugins.logs.Content"] = __getLogContent(cbox)
|
||||
|
||||
def __prepareFormData(self):
|
||||
self.hdf[self.hdf_prefix + "Content"] = self.__getLogContent()
|
||||
|
||||
def __getLogContent(cbox, lines=30, maxSize=2000):
|
||||
return "<br/>".join(cbox.getLogData(lines, maxSize))
|
||||
|
||||
def __getLogContent(self, lines=30, maxSize=2000):
|
||||
return "<br/>".join(self.cbox.getLogData(lines, maxSize))
|
||||
|
||||
|
@ -1,71 +1,110 @@
|
||||
import re
|
||||
import subprocess
|
||||
import imp
|
||||
import os
|
||||
import CryptoBoxPlugin
|
||||
|
||||
## specify (in seconds), how long we should wait before redirecting and ip change
|
||||
REDIRECT_DELAY=20
|
||||
CHANGE_IP_DELAY=5
|
||||
|
||||
def doAction(hdf, cbox, store=None, ip1="", ip2="", ip3="", ip4=""):
|
||||
__prepareFormData(hdf, cbox)
|
||||
if store:
|
||||
try:
|
||||
for ip_in in (ip1, ip2, ip3, ip4):
|
||||
if (int(ip_in) < 0) or (int(ip_in) > 255):
|
||||
cbox.log.debug("invalid IP supplied: %s" % str((ip1,ip2,ip3,ip4)))
|
||||
raise ValueError
|
||||
ip = "%d.%d.%d.%d" % (int(ip1), int(ip2), int(ip3), int(ip4))
|
||||
except ValueError:
|
||||
hdf["Data.Warning"] = "Plugins.network.InvalidIP"
|
||||
return "form_system"
|
||||
if __setIP(cbox, ip):
|
||||
hdf["Data.Success"] = "Plugins.network.IPChanged"
|
||||
hdf["Data.Redirect.URL"] = ""
|
||||
hdf["Data.Redirect.Delay"] = 30
|
||||
return "form_system"
|
||||
class network(CryptoBoxPlugin.CryptoBoxPlugin):
|
||||
|
||||
def doAction(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4=""):
|
||||
## if we were redirected, then we should display the default page
|
||||
if redirected == "1":
|
||||
return None
|
||||
## request for IP change?
|
||||
if store:
|
||||
try:
|
||||
for ip_in in (ip1, ip2, ip3, ip4):
|
||||
if (int(ip_in) < 0) or (int(ip_in) > 255):
|
||||
self.cbox.log.info("invalid IP supplied: %s" % str((ip1,ip2,ip3,ip4)))
|
||||
raise ValueError
|
||||
ip = "%d.%d.%d.%d" % (int(ip1), int(ip2), int(ip3), int(ip4))
|
||||
except ValueError:
|
||||
self.hdf["Data.Warning"] = "Plugins.network.InvalidIP"
|
||||
return None
|
||||
if self.__setIP(ip):
|
||||
self.cbox.log.info("the IP was successfully changed: %s" % ip)
|
||||
self.hdf["Data.Success"] = "Plugins.network.IPChanged"
|
||||
self.hdf["Data.Redirect.URL"] = self.__getRedirectDestination(ip)
|
||||
self.hdf["Data.Redirect.Delay"] = REDIRECT_DELAY
|
||||
return None
|
||||
else:
|
||||
self.cbox.log.warn("failed to change IP address to: %s" % ip)
|
||||
self.hdf["Data.Warning"] = "Plugins.network.InvalidIP"
|
||||
self.__prepareFormData()
|
||||
return "form_network"
|
||||
else:
|
||||
hdf["Data.Warning"] = "Plugins.network.InvalidIP"
|
||||
## just show the form
|
||||
self.__prepareFormData()
|
||||
return "form_network"
|
||||
else:
|
||||
return "form_network"
|
||||
|
||||
|
||||
def getStatus(cbox):
|
||||
return "%d.%d.%d.%d" % __getCurrentIP(cbox)
|
||||
def getStatus(self):
|
||||
return "%d.%d.%d.%d" % self.__getCurrentIP()
|
||||
|
||||
|
||||
def __getRedirectDestionation(self, ip):
|
||||
import cherrypy
|
||||
req = cherrypy.request
|
||||
dest = ip
|
||||
base_parts = req.base.split(":")
|
||||
if len(base_parts) == 3:
|
||||
dest += ":%s" % base_parts[2]
|
||||
return dest
|
||||
|
||||
def __prepareFormData(hdf, cbox):
|
||||
(oc1, oc2, oc3, oc4) = __getCurrentIP(cbox)
|
||||
hdf["Data.Plugins.network.ip.oc1"] = oc1
|
||||
hdf["Data.Plugins.network.ip.oc2"] = oc2
|
||||
hdf["Data.Plugins.network.ip.oc3"] = oc3
|
||||
hdf["Data.Plugins.network.ip.oc4"] = oc4
|
||||
|
||||
def __prepareFormData(self):
|
||||
(oc1, oc2, oc3, oc4) = self.__getCurrentIP()
|
||||
self.hdf[self.hdf_prefix + "ip.oc1"] = oc1
|
||||
self.hdf[self.hdf_prefix + "ip.oc2"] = oc2
|
||||
self.hdf[self.hdf_prefix + "ip.oc3"] = oc3
|
||||
self.hdf[self.hdf_prefix + "ip.oc4"] = oc4
|
||||
|
||||
def __getCurrentIP(cbox):
|
||||
root_action_plug = imp.load_source("root_action", os.path.join(os.path.dirname(__file__), "root_action.py"))
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdout = subprocess.PIPE,
|
||||
args = [
|
||||
root_action_plug.IFCONFIG_BIN,
|
||||
root_action_plug.IFACE])
|
||||
(output, error) = proc.communicate()
|
||||
if proc.returncode != 0: return (0,0,0,0)
|
||||
match = re.search(u'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s',output)
|
||||
if match:
|
||||
return tuple([int(e) for e in match.groups()])
|
||||
else:
|
||||
return (0,0,0,0)
|
||||
|
||||
def __getCurrentIP(self):
|
||||
import re
|
||||
import imp
|
||||
## load some values from the root_action.py script
|
||||
root_action_plug = imp.load_source("root_action", os.path.join(self.pluginDir, "root_action.py"))
|
||||
## get the current IP of the network interface
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdout = subprocess.PIPE,
|
||||
args = [
|
||||
root_action_plug.IFCONFIG_BIN,
|
||||
root_action_plug.IFACE])
|
||||
(output, error) = proc.communicate()
|
||||
if proc.returncode != 0: return (0,0,0,0)
|
||||
## this regex matches the four numbers of the IP
|
||||
match = re.search(u'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s',output)
|
||||
if match:
|
||||
## use the previously matched numbers
|
||||
return tuple([int(e) for e in match.groups()])
|
||||
else:
|
||||
return (0,0,0,0)
|
||||
|
||||
|
||||
def __setIP(cbox, ip):
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [
|
||||
cbox.prefs["Programs"]["super"],
|
||||
cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
||||
"plugin",
|
||||
os.path.join(os.path.dirname(__file__), "root_action.py"),
|
||||
ip])
|
||||
proc.communicate()
|
||||
return proc.returncode == 0
|
||||
def __setIP(self, ip):
|
||||
import threading
|
||||
## call the root_action script after some seconds - so we can deliver the page before
|
||||
def delayedIPchange():
|
||||
import time
|
||||
time.sleep(CHANGE_IP_DELAY)
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [
|
||||
self.cbox.prefs["Programs"]["super"],
|
||||
self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
||||
"plugin",
|
||||
os.path.join(self.pluginDir, "root_action.py"),
|
||||
ip])
|
||||
proc.communicate()
|
||||
return
|
||||
thread = threading.Thread()
|
||||
thread.run = delayedIPchange
|
||||
thread.setDaemon(True)
|
||||
thread.start()
|
||||
# TODO: how could we guess, if it failed?
|
||||
return True
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Plugins.partition.Title.Partition) ?></h1>
|
||||
|
||||
<p><?cs var:html_escape(Lang.Plugins.partition.Text.ProgressInfo) ?>
|
||||
<ul>
|
||||
<?cs loop: x = #0, subcount(Data.Plugins.partition.Parts)-1, #1 ?>
|
||||
<li><!-- CONTENT_DUMMY -->:
|
||||
<!-- CONTENT_DUMMY --></li>
|
||||
<?cs /loop ?>
|
||||
</ul>
|
||||
</p>
|
||||
|
Loading…
Reference in New Issue