moved "Rank" attribute from language file to plugin code

added plugin "plugin_manager"
added plugin "user_manager"
This commit is contained in:
lars 2006-10-11 15:50:24 +00:00
parent ee82f91a64
commit 11c2873934
28 changed files with 368 additions and 21 deletions

View File

@ -5,6 +5,7 @@ class date(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = False
rank = 10
def doAction(self, store=None, year=0, month=0, day=0, hour=0, minute=0):
import datetime

View File

@ -1,6 +1,5 @@
Name = Change date and time
Link = Set date/time
Rank = 10
Title.ConfigDate = Date and time setting

View File

@ -4,6 +4,7 @@ class format_fs(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "volume" ]
requestAuth = True
rank = 60
## map filesystem types to the appropriate arguments for 'mkfs'
fsTypes = {
@ -67,11 +68,11 @@ class format_fs(CryptoBoxPlugin.CryptoBoxPlugin):
def __format_luks(self, fsType, pw, pw2):
if not pw:
self.hdf["Data.Warning"] = "EmptyCryptoPassword"
self.hdf["Data.Warning"] = "EmptyPassword"
self.cbox.log.warn("no crypto password was supplied for initialization of device '%s'" % self.device)
return "volume_format"
if pw != pw2:
self.hdf["Data.Warning"] = "DifferentCryptoPasswords"
self.hdf["Data.Warning"] = "DifferentPasswords"
self.cbox.log.warn("the crypto password was not repeated correctly for initialization of device '%s'" % self.device)
return "volume_format"
container = self.cbox.getContainer(self.device)

View File

@ -1,6 +1,5 @@
Name = Create filesystems
Link = Format
Rank = 60
Title.Format = Initializing filesystem

View File

@ -19,8 +19,8 @@
var:html_escape(Lang.Plugins.format_fs.Text.Yes) ?><?cs else ?><?cs
var:html_escape(Lang.Plugins.format_fs.Text.No) ?><?cs /if ?></p>
<p><label for="crypto_password"><?cs var:html_escape(Lang.Text.EnterNewCryptoPassword) ?></label> <input type="password" id="crypto_password" name="crypto_password" /></p>
<p><label for="crypto_password2"><?cs var:html_escape(Lang.Text.EnterSameCryptoPassword) ?></label> <input type="password" id="crypto_password2" name="crypto_password2" /></p>
<p><label for="crypto_password"><?cs var:html_escape(Lang.Text.EnterNewPassword) ?></label> <input type="password" id="crypto_password" name="crypto_password" /></p>
<p><label for="crypto_password2"><?cs var:html_escape(Lang.Text.EnterSamePassword) ?></label> <input type="password" id="crypto_password2" name="crypto_password2" /></p>
<input type="hidden" name="device" value="<?cs var:Data.CurrentDisk.device ?>" />
<input type="hidden" name="fs_type" value="<?cs var:html_escape(Data.Plugins.format_fs.fs_type) ?>" />
<input type="hidden" name="container_type" value="<?cs var:html_escape(Data.Plugins.format_fs.container_type) ?>" />

View File

@ -1,6 +1,5 @@
Name = Show the content of the log file
Link = Show log file
Rank = 90
Title.Log = CryptoBox logfiles

View File

@ -5,6 +5,7 @@ class logs(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = False
rank = 90
def doAction(self):
self.__prepareFormData()

View File

@ -1,6 +1,5 @@
Name = Configure network
Link = Configure network
Rank = 30
Title.Network = Network settings

View File

@ -10,6 +10,7 @@ class network(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = True
rank = 30
def doAction(self, store=None, redirected="", ip1="", ip2="", ip3="", ip4=""):
## if we were redirected, then we should display the default page

View File

@ -1,6 +1,5 @@
Name = Disk partitioning
Link = Disk partitioning
Rank = 80
Title.Partition = Disk partitions

View File

@ -8,6 +8,7 @@ class partition(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = True
rank = 80
PartTypes = {
"windows" : ["0xC", "vfat"],

View File

@ -29,6 +29,9 @@ Python code interface:
"volume")
- the class variable "requestAuth" is boolean and defines, if admin authentication is necessary
for this plugin
- the class variable "rank" is an integer in the range of 0..100 - it determines the order
of plugins in listings (lower value -> higher priority)
- the class variable "enabled" is boolean and detemines the default availability of the plugin
- volume plugins contain the attribute "device" (you may trust this value - a volume plugin will
never get called with an invalid device)

View File

@ -0,0 +1,15 @@
Name = Plugin Manager
Link = Plugin Manager
Title.PluginManager = Plugin Manager
Button.SaveSettings = Save settings
Text {
PluginName = Plugin
PluginRank = Priority
PluginEnabled = Enabled?
RequestsAuth = Requires admin?
VolumePlugins = Volume plugins
SystemPlugins = System plugins
}

View File

@ -0,0 +1,64 @@
<?cs # $Id$ ?>
<style type="text/css">
table.plugin_list {
text-align:center;
align:center;
}
table.plugin_list td, table.plugin_list th {
padding-left: 5px;
padding-right: 5px;
}
</style>
<h1><?cs var:html_escape(Lang.Plugins.plugin_manager.Title.PluginManager) ?></h1>
<?cs call:print_form_header("plugins/plugin_manager") ?>
<h2><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.SystemPlugins) ?></h2>
<p>
<table class="plugin_list" align="center">
<tr>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.PluginName) ?></th>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.PluginRank) ?></th>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.PluginEnabled) ?></th>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.RequestsAuth) ?></th>
</tr>
<?cs each:x = Settings.PluginList ?><?cs if:x.Types.system
?><input type="hidden" name="<?cs var:name(x) ?>_listed" value="1" /><tr>
<td style="text-align:left"><?cs var:html_escape(name(x)) ?></td>
<td><input style="text-align:right" type="text" size="3" name="<?cs var:name(x) ?>_rank" value="<?cs var:html_escape(x.Rank) ?>" /></td>
<td><input type="checkbox" name="<?cs var:name(x) ?>_enabled" <?cs if:x.Enabled ?>checked="checked"<?cs /if ?> /></td>
<td><input type="checkbox" name="<?cs var:name(x) ?>_auth" <?cs if:x.RequestAuth ?>checked="checked"<?cs /if ?> /></td>
</tr><?cs /if ?><?cs /each ?>
</table></p>
<h2><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.VolumePlugins) ?></h2>
<p>
<table class="plugin_list" align="center">
<tr>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.PluginName) ?></th>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.PluginRank) ?></th>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.PluginEnabled) ?></th>
<th><?cs var:html_escape(Lang.Plugins.plugin_manager.Text.RequestsAuth) ?></th>
</tr>
<?cs each:x = Settings.PluginList ?><?cs if:x.Types.volume
?><input type="hidden" name="<?cs var:name(x) ?>_listed" value="1" /><tr>
<td style="text-align:left"><?cs var:html_escape(name(x)) ?></td>
<td><input style="text-align:right" type="text" size="3" name="<?cs var:name(x) ?>_rank" value="<?cs var:html_escape(x.Rank) ?>" /></td>
<td><input type="checkbox" name="<?cs var:name(x) ?>_enabled" <?cs if:x.Enabled ?>checked="checked"<?cs /if ?> /></td>
<td><input type="checkbox" name="<?cs var:name(x) ?>_auth" <?cs if:x.RequestAuth ?>checked="checked"<?cs /if ?> /></td>
</tr><?cs /if ?><?cs /each ?>
</table></p>
<p>
<input type="hidden" name="store" value="1" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.plugin_manager.Button.SaveSettings) ?></button>
</p>
</form>

View File

@ -0,0 +1,52 @@
import CryptoBoxPlugin
class plugin_manager(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = True
rank = 90
def doAction(self, store=None, **args):
import re
if store:
for key in args.keys():
if key.endswith("_listed"):
if not re.search(u'\W',key):
self.__setConfig(key[:-7], args)
else:
self.cbox.log.info("plugin_manager: invalid plugin name (%s)" % str(key[:-7]))
try:
self.cbox.prefs.pluginConf.write()
except IOError:
self.cbox.log.warn("failed to write plugin configuration")
return "plugin_list"
def getStatus(self):
return "no status"
def __setConfig(self, name, args):
setting = {}
setting["enabled"] = False
try:
if args[name + "_enabled"]:
setting["enabled"] = True
except KeyError:
pass
setting["rank"] = "80"
try:
r = int(args[name + "_rank"])
if r>=0 and r<=100:
setting["rank"] = r
except KeyError, ValueError:
pass
setting["requestAuth"] = False
try:
if args[name + "_auth"]:
setting["requestAuth"] = True
except KeyError, ValueError:
pass
self.cbox.prefs.pluginConf[name] = setting

View File

@ -1,6 +1,5 @@
Name = Shutdown or reboot the computer
Link = Shutdown/Reboot
Rank = 70
Title.Shutdown = Shutdown computer

View File

@ -6,6 +6,7 @@ class shutdown(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = False
rank = 70
def doAction(self, type=None):
if not type:

View File

@ -0,0 +1,51 @@
Name = User Manager
Link = User Manager
Title {
UserManager = Manage users
AddUser = Add new user
DelUser = Remove user
ChangePassword = Change password
}
Button {
AddUser = Add new user
DelUser = Remove
ChangePassword = Change password
}
Text {
NewUser = Name of the new user
DelUser = User to remove
ChangePasswordUser = Change user's password
}
SuccessMessage {
UserAdded {
Title = User added
Text = The new user was added successfully.
}
UserRemoved {
Title = User removed
Text = The user was removed successfully.
}
PasswordChanged {
Title = Password changed
Text = The password was changed successfully.
}
}
WarningMessage {
InvalidUserName {
Title = Invalid username
Text = The choosen username is invalid: only letters and digits are allowed.
}
UserAlreadyExists {
Title = User exists
Text = The choosen username does already exist. Please choose another one.
}
}

View File

@ -0,0 +1,80 @@
<?cs # $Id$ ?>
<style type="text/css">
td.left_column {
text-align:right;
padding-left:30px;
padding-right:5px;
}
</style>
<h1><?cs var:html_escape(Lang.Plugins.user_manager.Title.UserManager) ?></h1>
<h2><?cs var:html_escape(Lang.Plugins.user_manager.Title.AddUser) ?></h2>
<p>
<?cs call:print_form_header("plugins/user_manager") ?>
<table>
<tr><td class="left_column">
<label for="new_user"><?cs var:html_escape(Lang.Plugins.user_manager.Text.NewUser) ?>:</label></td>
<td><input id="new_user" type="text" name="user" size="12" /></td>
<td></td></tr>
<tr><td class="left_column">
<label for="new_pw"><?cs var:html_escape(Lang.Text.EnterNewPassword) ?>:</label></td>
<td><input id="new_pw" type="password" name="new_pw" size="12" /></td>
<td></td></tr>
<tr><td class="left_column">
<label for="new_pw2"><?cs var:html_escape(Lang.Text.EnterSamePassword) ?>:</label></td>
<td><input id="new_pw2" type="password" name="new_pw2" size="12" /></td>
<td>
<input type="hidden" name="store" value="add_user" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.user_manager.Button.AddUser) ?></button></td></tr>
</table>
</form>
</p>
<h2><?cs var:html_escape(Lang.Plugins.user_manager.Title.ChangePassword) ?></h2>
<p>
<?cs call:print_form_header("plugins/user_manager") ?>
<table>
<tr><td class="left_column">
<label for="chpw_user"><?cs var:html_escape(Lang.Plugins.user_manager.Text.ChangePasswordUser) ?>:</label></td>
<td style="text-align:left"><select id="user" name="user" size="0">
<?cs each:x=Data.Plugins.user_manager.Users ?>
<option><?cs var:html_escape(x) ?></option>
<?cs /each ?></select></td>
<td></td></tr>
<tr><td class="left_column">
<label for="new_pw"><?cs var:html_escape(Lang.Text.EnterNewPassword) ?>:</label></td>
<td><input id="new_pw" type="password" name="new_pw" size="12" /></td>
<td></td></tr>
<tr><td class="left_column">
<label for="new_pw2"><?cs var:html_escape(Lang.Text.EnterSamePassword) ?>:</label></td>
<td><input id="new_pw2" type="password" name="new_pw2" size="12" /></td>
<td>
<input type="hidden" name="store" value="change_password" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.user_manager.Button.ChangePassword) ?></button></td></tr>
</table>
</form>
</p>
<?cs if:subcount(Data.Plugins.user_manager.Users) > 1 ?>
<h2><?cs var:html_escape(Lang.Plugins.user_manager.Title.DelUser) ?></h2>
<p>
<table><tr><td class="left_column">
<?cs call:print_form_header("plugins/user_manager") ?>
<label for="user"><?cs var:html_escape(Lang.Plugins.user_manager.Text.DelUser) ?>: </label><select id="user" name="user" size="0">
<?cs each:x=Data.Plugins.user_manager.Users ?><?cs if:x != "admin" ?>
<option><?cs var:html_escape(x) ?></option>
<?cs /if ?><?cs /each ?>
</select>
<input type="hidden" name="store" value="del_user" />
<button type="submit"><?cs var:html_escape(Lang.Plugins.user_manager.Button.DelUser) ?></button>
</form></td></tr></table>
</p>
<?cs /if ?>

View File

@ -0,0 +1,82 @@
import CryptoBoxPlugin
class user_manager(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
requestAuth = True
rank = 45
reservedUsers = [ "admin" ]
def doAction(self, store=None, user=None, new_pw=None, new_pw2=None):
import re
adminDict = self.cbox.prefs.userDB["admins"]
self.__cleanHDF()
if store is None:
pass
elif store == "add_user":
if (user is None) or (re.search(u'\W', user)):
self.hdf["Data.Warning"] = "Plugins.user_manager.InvalidUserName"
elif not new_pw:
self.hdf["Data.Warning"] = "EmptyNewPassword"
elif new_pw != new_pw2:
self.hdf["Data.Warning"] = "DifferentPasswords"
elif user in adminDict.keys():
self.hdf["Data.Warning"] = "Plugins.user_manager.UserAlreadyExists"
else:
adminDict[user] = self.cbox.prefs.userDB.getDigest(new_pw)
self.hdf["Data.Success"] = "Plugins.user_manager.UserAdded"
try:
self.cbox.prefs.userDB.write()
except IOError:
self.cbox.log.warn("failed to write user database")
elif store == "change_password":
if not new_pw:
self.hdf["Data.Warning"] = "EmptyNewPassword"
elif new_pw != new_pw2:
self.hdf["Data.Warning"] = "DifferentPasswords"
elif user in adminDict.keys():
adminDict[user] = self.cbox.prefs.userDB.getDigest(new_pw)
self.hdf["Data.Success"] = "Plugins.user_manager.PasswordChanged"
try:
self.cbox.prefs.userDB.write()
except IOError:
self.cbox.log.warn("failed to write user database")
else:
self.cbox.log.info("user_manager: invalid user choosen (%s)" % str(user))
elif store == "del_user":
if user in self.reservedUsers:
self.cbox.log.info("user_manager: tried to remove reserved user (%s)" % user)
elif user in adminDict.keys():
del adminDict[user]
self.hdf["Data.Success"] = "Plugins.user_manager.UserAdded"
try:
self.cbox.prefs.userDB.write()
except IOError:
self.cbox.log.warn("failed to write user database")
else:
self.cbox.log.info("user_manager: tried to remove non-existing user (%s)" % str(user))
else:
self.cbox.log.info("user_manager: invalid value of 'store' (%s)" % store)
self.__prepareHDF(adminDict)
return "user_list"
def getStatus(self):
return str(self.cbox.prefs.userDB["admins"].keys())
def __cleanHDF(self):
for key in self.hdf.keys():
del self.hdf[key]
def __prepareHDF(self, dict):
## sort by name
users = dict.keys()
users.sort()
## export all users
for name in users:
self.hdf[self.hdf_prefix + "Users." + name] = name

View File

@ -1,6 +1,5 @@
Name = Technical details of a volume
Link = Details
Rank = 100
Title.Details = Technical details

View File

@ -5,6 +5,7 @@ class volume_details(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "volume" ]
requestAuth = False
rank = 100
def doAction(self):

View File

@ -1,6 +1,5 @@
Name = Mount and umount volumes
Link = Main
Rank = 0
Title {

View File

@ -8,7 +8,7 @@
<input type="hidden" name="action" value="mount_plain" />
<?cs /if ?>
<?cs if:Data.CurrentDisk.encryption ?>
<label for="pw"><?cs var:html_escape(Lang.Text.EnterCurrentCryptoPassword) ?>: </label>
<label for="pw"><?cs var:html_escape(Lang.Text.EnterCurrentPassword) ?>: </label>
<input type="password" tabindex="1" id="pw" name="pw" size="20" maxlength="60" />
<?cs /if ?>
<button type="submit" tabindex="2"><?cs var:html_escape(Lang.Plugins.volume_mount.Button.Mount) ?></button>

View File

@ -6,6 +6,7 @@ class volume_mount(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "volume" ]
requestAuth = False
rank = 0
def doAction(self, action=None, pw=None):
@ -63,7 +64,7 @@ class volume_mount(CryptoBoxPlugin.CryptoBoxPlugin):
self.cbox.log.info("the device (%s) is already mounted" % device)
return "volume_status"
if not pw:
self.dataset["Data.Warning"] = "EmptyCryptoPassword"
self.dataset["Data.Warning"] = "EmptyPassword"
self.log.info("no password was supplied for mounting of device: '%s'" % device)
return "volume_status"
if self.container.getType() != self.container.Types["luks"]:

View File

@ -1,6 +1,5 @@
Name = Volume properties
Link = Properties
Rank = 40
Title {
Properties = Properties

View File

@ -35,17 +35,17 @@
</td></tr>
<?cs call:print_form_header("plugins/volume_props") ?>
<tr>
<td align="right"><label for="old_pw"><?cs var:html_escape(Lang.Text.EnterCurrentCryptoPassword) ?>: </label></td>
<td align="right"><label for="old_pw"><?cs var:html_escape(Lang.Text.EnterCurrentPassword) ?>: </label></td>
<td><input type="password" name="old_pw" tabindex="20" size="15" id="old_pw" /></td>
<td></td>
</tr>
<tr>
<td align="right"><label for="new_pw"><?cs var:html_escape(Lang.Text.EnterNewCryptoPassword) ?>: </label></td>
<td align="right"><label for="new_pw"><?cs var:html_escape(Lang.Text.EnterNewPassword) ?>: </label></td>
<td><input type="password" name="new_pw" tabindex="21" size="15" id="new_pw" /></td>
<td></td>
</tr>
<tr>
<td align="right"><label for="new_pw2"><?cs var:html_escape(Lang.Text.EnterSameCryptoPassword) ?>: </label></td>
<td align="right"><label for="new_pw2"><?cs var:html_escape(Lang.Text.EnterSamePassword) ?>: </label></td>
<td><input type="password" name="new_pw2" tabindex="22" size="15" id="new_pw2" /></td>
<td align="right">
<input type="hidden" name="device" value="<?cs var:html_escape(Data.CurrentDisk.device) ?>" />

View File

@ -6,6 +6,7 @@ class volume_props(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "volume" ]
requestAuth = False
rank = 40
def doAction(self, store=None, vol_name=None, old_pw=None, new_pw=None, new_pw2=None):
@ -57,11 +58,11 @@ class volume_props(CryptoBoxPlugin.CryptoBoxPlugin):
def __changePassword(self, old_pw, new_pw, new_pw2):
if not old_pw:
self.hdf["Data.Warning"] = "EmptyCryptoPassword"
self.hdf["Data.Warning"] = "EmptyPassword"
elif not new_pw:
self.hdf["Data.Warning"] = "EmptyNewCryptoPassword"
self.hdf["Data.Warning"] = "EmptyNewPassword"
elif new_pw != new_pw2:
self.hdf["Data.Warning"] = "DifferentCryptoPasswords"
self.hdf["Data.Warning"] = "DifferentPasswords"
elif old_pw == new_pw:
## do nothing
pass