cryptonas/plugins/user_manager/user_manager.py
lars 77324ae946 added minor parts of slovene translation
fixed samba integration script
added syslog support
replaced 'pattern' with 'level' for 'logs' plugin
improved fetch_po_files script
improved output of log plugin
recursively storing setting files fixed
umask set to 022
defining bootup and shutdown handler for the server
implementing volume_automount mounting
simplified the output preperation of the partition plugin
"busy" flag handling moved from core/container to core/main
2006-12-11 14:16:10 +00:00

106 lines
3.4 KiB
Python

#
# Copyright 2006 sense.lab e.V.
#
# This file is part of the CryptoBox.
#
# The CryptoBox is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# The CryptoBox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the CryptoBox; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
__revision__ = "$Id"
import cryptobox.plugins.base
RESERVED_USERS = [ "admin" ]
class user_manager(cryptobox.plugins.base.CryptoBoxPlugin):
plugin_capabilities = [ "system" ]
plugin_visibility = [ "preferences" ]
request_auth = True
rank = 45
def do_action(self, store=None, user=None, new_pw=None, new_pw2=None):
import re
admin_dict = self.cbox.prefs.user_db["admins"]
self.__clean_hdf()
if store is None:
pass
elif store == "add_user":
if (user is None) or (re.search(r'\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 admin_dict.keys():
self.hdf["Data.Warning"] = "Plugins.user_manager.UserAlreadyExists"
else:
admin_dict[user] = self.cbox.prefs.user_db.get_digest(new_pw)
self.hdf["Data.Success"] = "Plugins.user_manager.UserAdded"
try:
self.cbox.prefs.user_db.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 admin_dict.keys():
admin_dict[user] = self.cbox.prefs.user_db.get_digest(new_pw)
self.hdf["Data.Success"] = "Plugins.user_manager.PasswordChanged"
try:
self.cbox.prefs.user_db.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 RESERVED_USERS:
self.cbox.log.info("user_manager: tried to remove reserved user (%s)" % user)
self.hdf["Data.Warning"] = "NeverRemoveReservedUser"
elif user in admin_dict.keys():
del admin_dict[user]
self.hdf["Data.Success"] = "Plugins.user_manager.UserRemoved"
try:
self.cbox.prefs.user_db.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.__prepare_hdf(admin_dict)
return "user_list"
def get_status(self):
return ":".join(self.cbox.prefs.user_db["admins"].keys())
def __clean_hdf(self):
for key in self.hdf.keys():
del self.hdf[key]
def __prepare_hdf(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