summaryrefslogtreecommitdiffstats
path: root/py-bin
diff options
context:
space:
mode:
authoralice <alice@immerda.ch>2012-05-22 22:43:07 +0200
committeralice <alice@immerda.ch>2012-10-19 15:15:57 +0200
commita10f07258b1620049cc3ae62193c84062c20b3cc (patch)
tree584d3046eb006d105f4f8cb9ee4d03e9ab803610 /py-bin
parente8cc8d5c65d988c3dacb14de0ee9eaac0918718a (diff)
experimental JabberDB2 implementing validate_jid, create_jid, update_jid, is_jid
Diffstat (limited to 'py-bin')
-rw-r--r--py-bin/config.py-dist5
-rw-r--r--py-bin/jabberman.py61
2 files changed, 64 insertions, 2 deletions
diff --git a/py-bin/config.py-dist b/py-bin/config.py-dist
index 16d436a..31b0f6c 100644
--- a/py-bin/config.py-dist
+++ b/py-bin/config.py-dist
@@ -4,6 +4,9 @@
# never ever activate on production server!
debugmode = False
+#database configuration
+sqlite_path = "/path/to/sqlite.db"
+
# mail configuration:
mail_from_addr = "jabber@domain1.ch"
# to use sendmail for delivery, use this:
@@ -15,7 +18,7 @@ use_sendmail = True
#smtp_pass = ""
# domain name policy
-mail_domains = ["domain1.ch", "domain2.ch"
+mail_domains = ["domain1.ch", "domain2.ch"]
extra_domains = ["domain3.ch"]
# username and password policy
user_re ='^[a-zA-Z0-9_\-.]+$'
diff --git a/py-bin/jabberman.py b/py-bin/jabberman.py
index 1c53ff1..d486597 100644
--- a/py-bin/jabberman.py
+++ b/py-bin/jabberman.py
@@ -1,6 +1,6 @@
#jabber manager
-import shelve, atexit, sha, hmac, random, os, time, re, string
+import shelve, sqlite3, atexit, bcrypt, sha, hmac, random, os, time, re, string
import config
from ejabberdctl import EJabberdCtl
@@ -74,6 +74,65 @@ class JabberAccount:
def get_jabber_id(self):
return self.user + "@" + self.server
+# FIXME: error handling (especially sqlite)
+
+class JabberDB2:
+ def __init__(self):
+ self.__connection = sqlite3.connect(config.sqlite_path)
+
+ def generate_web_user(self, email):
+ return self.__token
+
+ def get_web_user(self, email):
+ pass
+
+ def update_web_user(self, email, plain_pwd, token):
+ pass
+
+ def validate_jid(self, jid, plain_pwd):
+ cur = self.__connection.cursor()
+ cur.execute("SELECT * FROM jabber_users where jid=?", (jid,))
+ row = cur.fetchone()
+
+ if row == None:
+ return False
+ crypted_pwd = row[2]
+ return crypted_pwd == bcrypt.hashpw(plain_pwd, crypted_pwd)
+
+ def create_jid(self, jid, plain_pwd, web_user_id):
+ crypted_pwd = bcrypt.hashpw(plain_pwd, bcrypt.gensalt());
+
+ cur = self.__connection.cursor()
+ cur.execute("INSERT INTO jabber_users VALUES (NULL,?,?,?)", (jid, crypted_pwd, web_user_id))
+ self.__connection.commit()
+
+ def update_jid(self, jid, plain_pwd):
+ crypted_pwd = bcrypt.hashpw(plain_pwd, bcrypt.gensalt());
+
+ cur = self.__connection.cursor()
+ cur.execute("UPDATE jabber_users SET password=?", (crypted_pwd,))
+ self.__connection.commit()
+ return True
+
+ def is_jid(self, jid):
+ cur = self.__connection.cursor()
+ cur.execute("SELECT * FROM jabber_users where jid=?", (jid,))
+ row = cur.fetchone()
+ return row != None and row[1] == jid
+
+ def delete_jid(self, jid):
+ pass
+
+ def delete_web_user(self, email):
+ pass
+
+ def select_jids(self, email):
+ pass
+
+ def select_web_users(self):
+ pass
+
+
class JabberDB:
def __init__(self):
self.db = shelve.open(config.jabberdb_path, 'c')