2 # -*- coding: utf-8 -*-
4 # Requires at least python version 2.5
7 manageusers.py (add|changepass) <username> <password>
13 from pprint import pprint
18 print >> sys.stderr, "ERROR: sqlite3 module not available!"
19 print >> sys.stderr, "This script needs sqlite3 support which is part of Python 2.5"
20 print >> sys.stderr, "You probably need to upgrade your Python installation first."
23 class UserManager(object):
25 self.db = sqlite3.connect(os.environ['HOME'] + '/.quassel/quassel-storage.sqlite')
26 self.cursor = self.db.cursor()
32 def _shaCrypt(self, password):
33 return sha.new(password).hexdigest()
35 def add(self, username, password):
36 self.cursor.execute('INSERT INTO quasseluser (username, password) VALUES (:username, :password)',
37 {'username':username, 'password':self._shaCrypt(password)}).fetchone()
39 def changepass(self, username, password):
40 self.cursor.execute('UPDATE quasseluser SET password = :password WHERE username = :username',
41 {'username':username, 'password':self._shaCrypt(password)}).fetchone()
44 return self.cursor.execute("SELECT * FROM quasseluser").fetchall()
46 def callByName(self, name, *args, **kws):
47 return self.__getattribute__(name)(*args, **kws)
50 usermanager = UserManager()
53 action = sys.argv[1].lower()
59 pprint(usermanager.list())
60 elif action in ['add', 'changepass'] and len(sys.argv) > 3:
61 usermanager.callByName(action, sys.argv[2], sys.argv[3])
63 print("ERROR: Wrong arguments supplied.")
66 if __name__ == "__main__":