language namespace for plugins separated
plugin interface changed ("prepareForm" removed) plugins do not raise exceptions anymore first part of the partitioning plugin device-specific stuff moved to CryptoBoxToolsmaster
parent
f2a7ceb61c
commit
de3280806f
@ -0,0 +1,117 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
logger = logging.getLogger("CryptoBox")
|
||||
|
||||
|
||||
def getAvailablePartitions():
|
||||
"retrieve a list of all available containers"
|
||||
ret_list = []
|
||||
try:
|
||||
"the following reads all lines of /proc/partitions and adds the mentioned devices"
|
||||
fpart = open("/proc/partitions", "r")
|
||||
try:
|
||||
line = fpart.readline()
|
||||
while line:
|
||||
p_details = line.split()
|
||||
if (len(p_details) == 4):
|
||||
"the following code prevents double entries like /dev/hda and /dev/hda1"
|
||||
(p_major, p_minor, p_size, p_device) = p_details
|
||||
if re.search('^[0-9]*$', p_major) and re.search('^[0-9]*$', p_minor):
|
||||
p_parent = re.sub('[1-9]?[0-9]$', '', p_device)
|
||||
if p_parent == p_device:
|
||||
if [e for e in ret_list if re.search('^' + p_parent + '[1-9]?[0-9]$', e)]:
|
||||
"major partition - its children are already in the list"
|
||||
pass
|
||||
else:
|
||||
"major partition - but there are no children for now"
|
||||
ret_list.append(p_device)
|
||||
else:
|
||||
"minor partition - remove parent if necessary"
|
||||
if p_parent in ret_list: ret_list.remove(p_parent)
|
||||
ret_list.append(p_device)
|
||||
line = fpart.readline()
|
||||
finally:
|
||||
fpart.close()
|
||||
return map(getAbsoluteDeviceName, ret_list)
|
||||
except IOError:
|
||||
logger.warning("Could not read /proc/partitions")
|
||||
return []
|
||||
|
||||
|
||||
def getAbsoluteDeviceName(shortname):
|
||||
""" returns the absolute file name of a device (e.g.: "hda1" -> "/dev/hda1")
|
||||
this does also work for device mapper devices
|
||||
if the result is non-unique, one arbitrary value is returned"""
|
||||
if re.search('^/', shortname): return shortname
|
||||
default = os.path.join("/dev", shortname)
|
||||
if os.path.exists(default): return default
|
||||
result = findMajorMinorOfDevice(shortname)
|
||||
"if no valid major/minor was found -> exit"
|
||||
if not result: return default
|
||||
(major, minor) = result
|
||||
"for device-mapper devices (major == 254) ..."
|
||||
if major == 254:
|
||||
result = findMajorMinorDeviceName("/dev/mapper", major, minor)
|
||||
if result: return result[0]
|
||||
"now check all files in /dev"
|
||||
result = findMajorMinorDeviceName("/dev", major, minor)
|
||||
if result: return result[0]
|
||||
return default
|
||||
|
||||
|
||||
def findMajorMinorOfDevice(device):
|
||||
"return the major/minor numbers of a block device by querying /sys/block/?/dev"
|
||||
if not os.path.exists(os.path.join(os.path.sep,"sys","block",device)): return None
|
||||
blockdev_info_file = os.path.join(os.path.join(os.path.sep,"sys","block", device), "dev")
|
||||
try:
|
||||
f_blockdev_info = open(blockdev_info_file, "r")
|
||||
blockdev_info = f_blockdev_info.read()
|
||||
f_blockdev_info.close()
|
||||
(str_major, str_minor) = blockdev_info.split(":")
|
||||
"numeric conversion"
|
||||
try:
|
||||
major = int(str_major)
|
||||
minor = int(str_minor)
|
||||
return (major, minor)
|
||||
except ValueError:
|
||||
"unknown device numbers -> stop guessing"
|
||||
return None
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
|
||||
def findMajorMinorDeviceName(dir, major, minor):
|
||||
"returns the names of devices with the specified major and minor number"
|
||||
collected = []
|
||||
try:
|
||||
subdirs = [os.path.join(dir, e) for e in os.listdir(dir) if (not os.path.islink(os.path.join(dir, e))) and os.path.isdir(os.path.join(dir, e))]
|
||||
"do a recursive call to parse the directory tree"
|
||||
for dirs in subdirs:
|
||||
collected.extend(findMajorMinorDeviceName(dirs, major, minor))
|
||||
"filter all device inodes in this directory"
|
||||
collected.extend([os.path.realpath(os.path.join(dir, e)) for e in os.listdir(dir) if (os.major(os.stat(os.path.join(dir, e)).st_rdev) == major) and (os.minor(os.stat(os.path.join(dir, e)).st_rdev) == minor)])
|
||||
## remove double entries
|
||||
result = []
|
||||
for e in collected:
|
||||
if e not in result: result.append(e)
|
||||
return result
|
||||
except OSError:
|
||||
return []
|
||||
|
||||
|
||||
def getParentBlockDevices():
|
||||
devs = []
|
||||
for line in file("/proc/partitions"):
|
||||
p_details = line.split()
|
||||
## we expect four values - otherwise continue with next iteration
|
||||
if len(p_details) != 4: continue
|
||||
(p_major, p_minor, p_size, p_device) = p_details
|
||||
## we expect numeric values in the first two columns
|
||||
if re.search(u'\D',p_major) or re.search(u'\D',p_minor): continue
|
||||
## now let us check, if it is a (parent) block device or a partition
|
||||
if not os.path.isdir(os.path.join(os.path.sep, "sys", "block", p_device)): continue
|
||||
devs.append(p_device)
|
||||
return map(getAbsoluteDeviceName, devs)
|
||||
|
@ -1,42 +1,42 @@
|
||||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Title.ConfigDate) ?></h1>
|
||||
<h1><?cs var:html_escape(Lang.Plugins.date.Title.ConfigDate) ?></h1>
|
||||
|
||||
<?cs call:print_form_header("module_date") ?>
|
||||
<?cs call:print_form_header("plugins/date") ?>
|
||||
|
||||
<p><label for="date"><?cs var:html_escape(Lang.Text.Date) ?>: </label><br/>
|
||||
<p><label for="date"><?cs var:html_escape(Lang.Plugins.date.Text.Date) ?>: </label><br/>
|
||||
<select name="day" size="0"><?cs
|
||||
loop: x = #1, #31, #1 ?>
|
||||
<?cs if:x == Data.Modules.date.day ?><option selected="selected"><?cs
|
||||
<?cs if:x == Data.Plugins.date.day ?><option selected="selected"><?cs
|
||||
else ?><option><?cs /if ?><?cs var:x ?></option><?cs /loop ?>
|
||||
</select>
|
||||
<select name="month" size="0"><?cs
|
||||
loop: x = #1, #12, #1 ?>
|
||||
<?cs if:x == Data.Modules.date.month ?><option selected="selected" <?cs
|
||||
<?cs if:x == Data.Plugins.date.month ?><option selected="selected" <?cs
|
||||
else ?><option <?cs /if ?>value="<?cs var:x ?>"><?cs
|
||||
var:html_escape(Lang.Text.Months[x]) ?></option><?cs /loop ?>
|
||||
var:html_escape(Lang.Plugins.date.Text.Months[x]) ?></option><?cs /loop ?>
|
||||
</select>
|
||||
<select name="year" size="0"><?cs
|
||||
loop: x = #2006, #2025, #1 ?>
|
||||
<?cs if:x == Data.Modules.date.year ?><option selected="selected"><?cs
|
||||
<?cs if:x == Data.Plugins.date.year ?><option selected="selected"><?cs
|
||||
else ?><option><?cs /if ?><?cs var:x ?></option><?cs /loop ?>
|
||||
</select></p>
|
||||
|
||||
<p><label for="time"><?cs var:html_escape(Lang.Text.Time) ?>: </label><br/>
|
||||
<p><label for="time"><?cs var:html_escape(Lang.Plugins.date.Text.Time) ?>: </label><br/>
|
||||
<select name="hour" size="0"><?cs
|
||||
loop: x = #0, #23, #1 ?>
|
||||
<?cs if:x == Data.Modules.date.hour ?><option selected="selected"><?cs
|
||||
<?cs if:x == Data.Plugins.date.hour ?><option selected="selected"><?cs
|
||||
else ?><option><?cs /if ?><?cs if:x<10 ?>0<?cs /if ?><?cs var:x ?></option><?cs /loop ?>
|
||||
</select> :
|
||||
<select name="minute" size="0"><?cs
|
||||
loop: x = #0, #59, #1 ?>
|
||||
<?cs if:x == Data.Modules.date.minute ?><option selected="selected"><?cs
|
||||
<?cs if:x == Data.Plugins.date.minute ?><option selected="selected"><?cs
|
||||
else ?><option><?cs /if ?><?cs if:x<10 ?>0<?cs /if ?><?cs var:x ?></option><?cs /loop ?>
|
||||
</select></p>
|
||||
|
||||
<input type="hidden" name="store" value="yes" />
|
||||
|
||||
<button type="submit"><?cs var:html_escape(Lang.Button.ConfigDate) ?></button>
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.date.Button.ConfigDate) ?></button>
|
||||
|
||||
</form>
|
||||
|
||||
|
@ -1,35 +1,29 @@
|
||||
Lang {
|
||||
Name = Change date and time
|
||||
Link = Set date/time
|
||||
Rank = 10
|
||||
|
||||
Title.ConfigDate = Date and time setting
|
||||
Title.ConfigDate = Date and time setting
|
||||
|
||||
Button.ConfigDate = Set date and time
|
||||
Button.ConfigDate = Set date and time
|
||||
|
||||
Text.Date = Date
|
||||
Text.Time = Time
|
||||
Text.Months {
|
||||
1 = January
|
||||
2 = February
|
||||
3 = March
|
||||
4 = April
|
||||
5 = May
|
||||
6 = June
|
||||
7 = July
|
||||
8 = August
|
||||
9 = September
|
||||
10 = October
|
||||
11 = November
|
||||
12 = December
|
||||
}
|
||||
|
||||
Modules.date {
|
||||
Name = Change date and time
|
||||
Link = Set date/time
|
||||
Rank = 10
|
||||
}
|
||||
|
||||
WarningMessage.InvalidDate {
|
||||
Title = Invalid value
|
||||
Text = An invalid value for date or time was supplied. Please try again.
|
||||
}
|
||||
Text.Date = Date
|
||||
Text.Time = Time
|
||||
Text.Months {
|
||||
1 = January
|
||||
2 = February
|
||||
3 = March
|
||||
4 = April
|
||||
5 = May
|
||||
6 = June
|
||||
7 = July
|
||||
8 = August
|
||||
9 = September
|
||||
10 = October
|
||||
11 = November
|
||||
12 = December
|
||||
}
|
||||
|
||||
WarningMessage.InvalidDate {
|
||||
Title = Invalid value
|
||||
Text = An invalid value for date or time was supplied. Please try again.
|
||||
}
|
||||
|
@ -1,13 +1,7 @@
|
||||
Lang {
|
||||
Name = Show the content of the log file
|
||||
Link = Show log file
|
||||
Rank = 90
|
||||
|
||||
Title.Log = CryptoBox logfiles
|
||||
Title.Log = CryptoBox logfiles
|
||||
|
||||
Text.EmptyLog = The logfile of the CryptoBox is empty.
|
||||
|
||||
Modules.logs {
|
||||
Name = Show the content of the log file
|
||||
Link = Show log file
|
||||
Rank = 90
|
||||
}
|
||||
|
||||
}
|
||||
Text.EmptyLog = The logfile of the CryptoBox is empty.
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?cs # $Id: show_log.cs 374 2006-05-30 18:47:34Z lars $ ?>
|
||||
<?cs # $Id$ ?>
|
||||
|
||||
<div id="log">
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Title.Log) ?></h1>
|
||||
<h1><?cs var:html_escape(Lang.Plugins.logs.Title.Log) ?></h1>
|
||||
|
||||
<?cs if:Data.Modules.logs.Content ?>
|
||||
<p class="console"><?cs var:Data.Modules.logs.Content ?></p>
|
||||
<?cs if:Data.Plugins.logs.Content ?>
|
||||
<p class="console"><?cs var:Data.Plugins.logs.Content ?></p>
|
||||
<?cs else ?>
|
||||
<p><?cs var:html_escape(Lang.Text.EmptyLog) ?></p>
|
||||
<p><?cs var:html_escape(Lang.Plugins.logs.Text.EmptyLog) ?></p>
|
||||
<?cs /if ?>
|
||||
|
||||
</div>
|
||||
|
@ -1,22 +1,22 @@
|
||||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Title.Network) ?></h1>
|
||||
<h1><?cs var:html_escape(Lang.Plugins.network.Title.Network) ?></h1>
|
||||
|
||||
<?cs call:print_form_header("module_network") ?>
|
||||
<?cs call:print_form_header("plugins/network") ?>
|
||||
|
||||
<p><label for="ip"><?cs var:html_escape(Lang.Text.IP) ?>: </label><br/>
|
||||
<p><label for="ip"><?cs var:html_escape(Lang.Plugins.network.Text.IP) ?>: </label><br/>
|
||||
<input type="text" name="ip1" size="3" id="ip" value="<?cs
|
||||
var:Data.Modules.network.ip.oc1 ?>" />.
|
||||
var:Data.Plugins.network.ip.oc1 ?>" />.
|
||||
<input type="text" name="ip2" size="3" value="<?cs
|
||||
var:Data.Modules.network.ip.oc2 ?>" />.
|
||||
var:Data.Plugins.network.ip.oc2 ?>" />.
|
||||
<input type="text" name="ip3" size="3" value="<?cs
|
||||
var:Data.Modules.network.ip.oc3 ?>" />.
|
||||
var:Data.Plugins.network.ip.oc3 ?>" />.
|
||||
<input type="text" name="ip4" size="3" value="<?cs
|
||||
var:Data.Modules.network.ip.oc4 ?>" /></p>
|
||||
var:Data.Plugins.network.ip.oc4 ?>" /></p>
|
||||
|
||||
<input type="hidden" name="store" value="yes" />
|
||||
|
||||
<button type="submit"><?cs var:html_escape(Lang.Button.Network) ?></button>
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.network.Button.Network) ?></button>
|
||||
|
||||
</form>
|
||||
|
||||
|
@ -1,20 +1,24 @@
|
||||
Lang {
|
||||
Name = Configure network
|
||||
Link = Configure network
|
||||
Rank = 30
|
||||
|
||||
Title.Network = Network settings
|
||||
Title.Network = Network settings
|
||||
|
||||
Button.Network = Update settings
|
||||
Button.Network = Update settings
|
||||
|
||||
Text.IP = Network address
|
||||
Text.IP = Network address
|
||||
|
||||
Modules.network {
|
||||
Name = Configure network
|
||||
Link = Configure network
|
||||
Rank = 30
|
||||
}
|
||||
|
||||
WarningMessage.InvalidIP {
|
||||
WarningMessage {
|
||||
InvalidIP {
|
||||
Title = Invalid value
|
||||
Text = An invalid network address (IP) was supplied. Please try again.
|
||||
}
|
||||
}
|
||||
|
||||
SuccessMessage {
|
||||
IPChanged {
|
||||
Title = Network address changed
|
||||
Text = The network address has been changed. In a few seconds you will get redirected to the new address.
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?cs loop: x = #0, subcount(Data.Plugins.partition.Parts)-1, #1 ?>
|
||||
<input type="hidden" name="part<?cs var:x ?>_size" value="<?cs var:Data.Plugins.partition.Parts[x].Size ?>" />
|
||||
<input type="hidden" name="part<?cs var:x ?>_type" value="<?cs var:Data.Plugins.partition.Parts[x].Type ?>" /><?cs
|
||||
/loop ?>
|
||||
|
||||
<input type="hidden" name="block_device" value="<?cs var:html_escape(Data.Plugins.partition.Device) ?>" />
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
Name = Disk partitioning
|
||||
Link = Disk partitioning
|
||||
Rank = 80
|
||||
|
||||
Title.Partition = Disk partitions
|
||||
|
||||
Button {
|
||||
SelectDevice = Repartition disk
|
||||
AddPartition = Add another partition
|
||||
Back = Back
|
||||
SavePartitions = Save changes
|
||||
AbortPartitions = Cancel
|
||||
}
|
||||
|
||||
Text {
|
||||
FS {
|
||||
Type = Filesystem type
|
||||
Fat = FAT (Windows)
|
||||
Ext2 = Ext2
|
||||
Ext3 = Ext3
|
||||
Reiser = Reiser
|
||||
}
|
||||
Size = Size (MB)
|
||||
SelectDevice = Choose a disk for partitioning
|
||||
NoDevicesAvailable = No suitable disks found - please check your configuration and hardware setup.
|
||||
|
||||
|
||||
WarningMessage {
|
||||
InvalidInput {
|
||||
Title = Invalid input
|
||||
Text = You entered an invalid value.
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
import re
|
||||
import subprocess
|
||||
import imp
|
||||
import os
|
||||
import logging
|
||||
import CryptoBoxTools
|
||||
|
||||
PartTypes = {
|
||||
"linux" : "L",
|
||||
"windows" : "0xC"}
|
||||
|
||||
logger = logging.getLogger("CryptoBox")
|
||||
|
||||
def doAction(hdf, cbox, **args):
|
||||
try:
|
||||
step = args["step"]
|
||||
del args["step"]
|
||||
except KeyError:
|
||||
step = "select_device"
|
||||
if step == "add_partition":
|
||||
return __actionAddPartition(hdf, cbox, args)
|
||||
if step == "del_partition":
|
||||
return __actionDelPartition(hdf, cbox, args)
|
||||
elif step == "finish":
|
||||
return __actionFinish(hdf, cbox, args)
|
||||
else: # for "select_device" and for invalid targets
|
||||
return __actionSelectDevice(hdf, cbox, args)
|
||||
|
||||
|
||||
def getStatus(cbox):
|
||||
return "%d.%d.%d.%d" % __getCurrentIP(cbox)
|
||||
|
||||
|
||||
def __isDeviceValid(device, cbox):
|
||||
if not cbox.isDeviceAllowed(device):
|
||||
return False
|
||||
if not device in CryptoBoxTools.getParentBlockDevices():
|
||||
return False
|
||||
|
||||
|
||||
def __actionSelectDevice(hdf, cbox, args):
|
||||
block_devices = [e
|
||||
for e in CryptoBoxTools.getParentBlockDevices()
|
||||
if cbox.isDeviceAllowed(e)]
|
||||
counter = 0
|
||||
for a in block_devices:
|
||||
hdf["Data.Plugins.partition.BlockDevices.%d" % counter] = a
|
||||
cbox.log.debug("found a suitable block device: %s" % a)
|
||||
counter += 1
|
||||
return "select_device"
|
||||
|
||||
|
||||
def __actionAddPartition(hdf, cbox, args):
|
||||
try:
|
||||
device = args["block_device"]
|
||||
except KeyError:
|
||||
return __actionSelectDevice(hdf, cbox, args)
|
||||
#FIXME: the following check should obviuosly get reversed
|
||||
if __isDeviceValid(device, cbox): return __actionSelectDevice(hdf, cbox, args)
|
||||
size = __getDeviceSize(device)
|
||||
hdf["Data.Plugins.partition.Device"] = device
|
||||
hdf["Data.Plugins.partition.Device.Size"] = size
|
||||
parts = __getPartitionsFromArgs(args, size)
|
||||
__setPartitionData(hdf, parts, size)
|
||||
return "set_partitions"
|
||||
|
||||
|
||||
def __actionDelPartition(hdf, cbox, args):
|
||||
try:
|
||||
device = args["block_device"]
|
||||
except KeyError:
|
||||
return __actionSelectDevice(hdf, cbox, args)
|
||||
#FIXME: the following check should obviuosly get reversed
|
||||
if __isDeviceValid(device, cbox): return __actionSelectDevice(hdf, cbox, args)
|
||||
size = __getDeviceSize(device)
|
||||
hdf["Data.Plugins.partition.Device"] = device
|
||||
hdf["Data.Plugins.partition.Device.Size"] = size
|
||||
parts = __getPartitionsFromArgs(args, size)
|
||||
__setPartitionData(hdf, parts[:-1], size)
|
||||
return "set_partitions"
|
||||
|
||||
|
||||
def __setPartitionData(hdf, parts, size):
|
||||
availSize = size
|
||||
i = 0
|
||||
for part in parts:
|
||||
logger.debug(part)
|
||||
hdf["Data.Plugins.partition.Parts.%d.Size" % i] = part["size"]
|
||||
hdf["Data.Plugins.partition.Parts.%d.Type" % i] = part["type"]
|
||||
availSize -= part["size"]
|
||||
i += 1
|
||||
hdf["Data.Plugins.partition.availSize"] = availSize
|
||||
for t in PartTypes.keys():
|
||||
hdf["Data.Plugins.partition.Types.%s" % t] = t
|
||||
|
||||
|
||||
def __getPartitionsFromArgs(args, maxSize):
|
||||
parts = []
|
||||
done = False
|
||||
availSize = maxSize
|
||||
i = -1
|
||||
while not done:
|
||||
i += 1
|
||||
try:
|
||||
size = int(args["part%d_size" % i])
|
||||
partType = args["part%d_type" % i]
|
||||
if int(size) > availSize: continue
|
||||
if int(size) <= 0: continue
|
||||
if not partType in PartTypes.keys(): continue
|
||||
parts.append({"size":size, "type":partType})
|
||||
availSize -= size
|
||||
except TypeError:
|
||||
pass
|
||||
except KeyError:
|
||||
done = True
|
||||
return parts
|
||||
|
||||
|
||||
def __getDeviceSize(device):
|
||||
rdev = os.stat(device).st_rdev
|
||||
minor = os.minor(rdev)
|
||||
major = os.major(rdev)
|
||||
for f in file("/proc/partitions"):
|
||||
try:
|
||||
elements = f.split()
|
||||
if len(elements) != 4: continue
|
||||
if (int(elements[0]) == major) and (int(elements[1]) == minor):
|
||||
return int(elements[2])
|
||||
except ValueError:
|
||||
pass
|
||||
return 0
|
||||
|
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python2.4
|
||||
|
||||
#TODO: add netmask and gateway
|
||||
|
||||
## necessary: otherwise CryptoBoxRootActions.py will refuse to execute this script
|
||||
PLUGIN_TYPE = "cryptobox"
|
||||
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
|
||||
self_bin =sys.argv[0]
|
||||
|
||||
if len(args) > 1:
|
||||
sys.stderr.write("%s: too many arguments (%s)\n" % (self_bin, args))
|
||||
sys.exit(1)
|
||||
|
||||
if len(args) == 0:
|
||||
sys.stderr.write("%s: no argument supplied\n" % self_bin)
|
||||
sys.exit(1)
|
||||
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [IFCONFIG_BIN, IFACE, args[0]])
|
||||
proc.communicate()
|
||||
sys.exit(proc.returncode)
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Plugins.partition.Title.Partition) ?></h1>
|
||||
|
||||
<?cs if:subcount(Data.Plugins.partition.BlockDevices) > 0 ?>
|
||||
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
|
||||
<p><label for="block_device"><?cs var:html_escape(Lang.Plugins.partition.Text.SelectDevice) ?>: </label><br/>
|
||||
<select name="block_device" id="block_device" size="0">
|
||||
<?cs each:x = Data.Plugins.partition.BlockDevices
|
||||
?><option><?cs var:html_escape(x) ?></option>
|
||||
<?cs /each ?>
|
||||
</select></p>
|
||||
|
||||
<input type="hidden" name="step" value="add_partition" />
|
||||
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.SelectDevice) ?></button>
|
||||
|
||||
</form>
|
||||
|
||||
<?cs else ?>
|
||||
|
||||
<p><?cs var:html_escape(Lang.Plugins.partition.Text.NoDevicesAvailable) ?></p>
|
||||
|
||||
<?cs /if ?>
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?cs # $Id$ ?>
|
||||
|
||||
<h1><?cs var:html_escape(Lang.Plugins.partition.Title.Partition) ?></h1>
|
||||
|
||||
<p> <?cs loop: x = #0, subcount(Data.Plugins.partition.Parts)-1, #1 ?>
|
||||
<p><?cs var:x ?> - <?cs var:Data.Plugins.partition.Parts[x].Size ?> - <?cs var:Data.Plugins.partition.Parts[x].Type ?></p><?cs
|
||||
/loop ?></p>
|
||||
|
||||
<?cs if:Data.Plugins.partition.availSize ?>
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
<?cs include:Settings.PluginDir + "/partition/current_partition_info.cs" ?><?cs
|
||||
|
||||
# new partition input if space is available ?><?cs
|
||||
set: x = subcount(Data.Plugins.partition.Parts) ?>
|
||||
<p><?cs var:x ?> - <input type="text" name="part<?cs var:x ?>_size" value="<?cs var:Data.Plugins.partition.availSize ?>" /> - <select name="part<?cs var:x ?>_type" size="0"><?cs each: t = Data.Plugins.partition.Types ?><option><?cs var:t ?></option><?cs /each ?></select></p>
|
||||
|
||||
<input type="hidden" name="step" value="add_partition" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.AddPartition) ?></button>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
||||
<?cs if:subcount(Data.Plugins.partition.Parts) > 0 ?>
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
<?cs include:Settings.PluginDir + "/partition/current_partition_info.cs" ?>
|
||||
<input type="hidden" name="step" value="del_partition" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.Back) ?></button>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
||||
<?cs if:subcount(Data.Plugins.partition.Parts) > 0 ?>
|
||||
<?cs call:print_form_header("plugins/partition") ?>
|
||||
<?cs include:Settings.PluginDir + "/partition/current_partition_info.cs" ?>
|
||||
<input type="hidden" name="step" value="finish" />
|
||||
<button type="submit"><?cs var:html_escape(Lang.Plugins.partition.Button.SavePartitions) ?></button>
|
||||
</form>
|
||||
<?cs /if ?>
|
||||
|
@ -1,36 +1,33 @@
|
||||
The following directory structure is required:
|
||||
- python code: plugins/MODULENAME/MODULENAME.py (all lower case is recommended)
|
||||
- language files: plugins/MODULENAME/lang/(en|de|??).hdf
|
||||
- clearsilver templates: plugins/MODULENAME/*.cs
|
||||
- python code: plugins/PLUGINNAME/PLUGINNAME.py (all lower case is recommended)
|
||||
- language files: plugins/PLUGINNAME/lang/(en|de|??).hdf
|
||||
- clearsilver templates: plugins/PLUGINNAME/*.cs
|
||||
|
||||
|
||||
Python code interface:
|
||||
def prepareForm(hdf, cbox):
|
||||
- here you may add some items to the hdf dataset used by the templates
|
||||
- the recommended namespace is Data.Modules.MODULENAME.???
|
||||
|
||||
def doAction(cbox, store=None, ???):
|
||||
- this function will get called whenever this module is involved in a request
|
||||
def doAction(hdf, cbox, store=None, ???):
|
||||
- this function will get called whenever this plugins is involved in a request
|
||||
- all arguments should be optional (e.g. for displaying a form without previous input values)
|
||||
- the argument "store" should be used to process a form submission (just a recommendation)
|
||||
- if the processing failed for some reason (invalid input, ...), it should raise a CBPluginException (e.g. CBPluginActionError) - the error message should be the name of a warning message (maybe defined in the plugin specific language file) - e.g. "InvalidDate" for Lang.WarningMessage.InvalidDate
|
||||
- the return value should be the name of the template that should be displayed after processing (a template file in the module directory takes precedence over global template files)
|
||||
- if the processing failed for some reason (invalid input, ...), it should manually set the "Data.Warning" (resp. "Data.Error" or "Data.Success") to a value of your choice (preferably you may want to use messages of your namespace (e.g. "Plugins.PLUGINNAME.InvalidInput"))
|
||||
- the return value should be the name of the template that should be displayed after processing (a template file in the plugin directory takes precedence over global template files)
|
||||
|
||||
def def getStatus(cbox):
|
||||
- returns a string, that described a state connected to this module (e.g. the current date and time (for the "date" plugin)
|
||||
- returns a string, that described a state connected to this plugin (e.g. the current date and time (for the "date" plugin)
|
||||
|
||||
|
||||
Language file structure:
|
||||
- the content of the language file will be added to the hdf dataset below "Lang.Plugins.PLUGINNAME" (this avoids namespace conflicts)
|
||||
- the following values _must_ be defined:
|
||||
Lang.Modules.MODULENAME.Name (a short description)
|
||||
Lang.Modules.MODULENAME.Link (the visible text for links to this module)
|
||||
Lang.Modules.MODULENAME.Rank (defines the order of the plugins displayed)
|
||||
- all other elements should follow the usual structure of language files
|
||||
Name (a short description)
|
||||
Link (the visible text for links to this plugin)
|
||||
Rank (defines the order of the plugins displayed (0..100))
|
||||
- all warnings, error and success messages should be stored below WarningMessage.??? (resp. ErrorMessage or SuccessMessage)
|
||||
|
||||
|
||||
Clearsilver template:
|
||||
- should start with a "<h1>" tag
|
||||
- links to the module (e.g. in form headers) could look like the following:
|
||||
<?cs call:link("module_MODULENAME",'','','','') ?>
|
||||
- links to the plugin (e.g. in form headers) could look like the following:
|
||||
<?cs call:link("plugins/PLUGINNAME",'','','','') ?>
|
||||
- a hidden input field called "store" should be used to indicate a form submission
|
||||
|
||||
|
@ -1,41 +1,45 @@
|
||||
<?cs # $Id$ ?><?cs
|
||||
|
||||
def:warning(warnname)
|
||||
?><div class="warning"><?cs
|
||||
if:?Lang.WarningMessage[warnname].Title
|
||||
?>
|
||||
<h1><?cs var:html_escape(Lang.WarningMessage[warnname].Title) ?></h1>
|
||||
<p><?cs var:html_escape(Lang.WarningMessage[warnname].Text) ?></p>
|
||||
<?cs else ?>
|
||||
<h1>unknown warning message</h1>
|
||||
<p>could not find warning message: '<?cs var:warnname ?>'</p>
|
||||
# the following macro is as ugly as possible - but somehow we have to manage
|
||||
to use 'normal' and 'plugin' messages in a clean way:
|
||||
Lang.WarningMessage.??? - used by core functions
|
||||
Lang.Plugins.PLUGINNAME.WarningMessage.??? - used by plugins ?><?cs
|
||||
def:message_dispatch(mname, type, category)
|
||||
?><?cs # split the message name into a (potentially existing) plugin-name prefix and the suffix (the python equivalent of the following three lines would be:
|
||||
plugPrefix, PlugSuffix = mname[0:mname.find(".",8), mname[mname.find(".",8)+1:]
|
||||
?><?cs loop:x = #8, #40, #1 ?><?cs if:(string.slice(mname,x,x+1) == ".") && !(?savedX) ?><?cs set:savedX = x ?><?cs /if ?><?cs /loop
|
||||
?><?cs set:plugPrefix = string.slice(mname,0,savedX)
|
||||
?><?cs set:plugSuffix = string.slice(mname,savedX+1,string.length(mname))
|
||||
?><?cs # preparations are done - now start writing
|
||||
?><div class="<?cs var:type ?>"><?cs
|
||||
# check if it is a 'normal' message ?><?cs
|
||||
if:?Lang[category][mname].Title ?>
|
||||
<h1><?cs var:html_escape(Lang[category][mname].Title) ?></h1>
|
||||
<p><?cs var:html_escape(Lang[category][mname].Text) ?></p>
|
||||
<?cs # check if the mname starts with "Plugins." ... ?><?cs
|
||||
elif:(string.slice(mname,0,8) == "Plugins.") && ?Lang[plugPrefix][category][plugSuffix].Title ?>
|
||||
<h1><?cs var:html_escape(Lang[plugPrefix][category][plugSuffix].Title) ?></h1>
|
||||
<p><?cs var:html_escape(Lang[plugPrefix][category][plugSuffix].Text) ?></p>
|
||||
<?cs # the message does not seem to exist ... ?><?cs
|
||||
else ?>
|
||||
<h1>unknown <?cs var:type ?> message</h1>
|
||||
<p>could not find <?cs var:type ?> message: '<?cs var:mname ?>'</p>
|
||||
<?cs /if ?></div><?cs
|
||||
/def ?><?cs
|
||||
|
||||
|
||||
def:error(errname)
|
||||
?><div class="error"><?cs
|
||||
if:?Lang.ErrorMessage[errname].Title
|
||||
?>
|
||||
<h1><?cs var:html_escape(Lang.ErrorMessage[errname].Title) ?></h1>
|
||||
<p><?cs var:html_escape(Lang.ErrorMessage[errname].Text) ?></p>
|
||||
<?cs else ?>
|
||||
<h1>unknown error message</h1>
|
||||
<p>could not find error message: '<?cs var:errname ?>'</p>
|
||||
<?cs /if ?></div><?cs
|
||||
def:warning(mname)
|
||||
?><?cs call:message_dispatch(mname, "warning", "WarningMessage") ?><?cs
|
||||
/def ?><?cs
|
||||
|
||||
|
||||
def:success(succname)
|
||||
?><div class="success"><?cs
|
||||
if:?Lang.SuccessMessage[succname].Title
|
||||
?>
|
||||
<h1><?cs var:html_escape(Lang.SuccessMessage[succname].Title) ?></h1>
|
||||
<p><?cs var:html_escape(Lang.SuccessMessage[succname].Text) ?></p>
|
||||
<?cs else ?>
|
||||
<h1>unknown success message</ |