Added basic mumble support

This commit is contained in:
Raynaldo Rivera
2014-10-05 16:16:11 -07:00
parent bf5a5b4bef
commit 89aa4fdcd3
10 changed files with 111 additions and 21 deletions

0
services/__init__.py Normal file
View File

View File

@@ -0,0 +1,34 @@
from django.conf import settings
from openfire import UserService
class JabberManager():
def __init__(self):
pass
def add_user(self, username, password):
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
print str(username)
print str(password)
api.add_user(self.__santatize_username(username), str(password))
def delete_user(self, username):
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
api.delete_user(username)
def lock_user(self, username):
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
api.lock_user(username)
def unlock_user(self, username):
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
api.unlock_user(username)
def update_user_pass(self, username, password):
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
api.update_user(username, password)
def __santatize_username(self, username):
sanatized = username.replace(" ","_")
return sanatized.lower()

View File

@@ -0,0 +1,52 @@
import uuid
import hashlib
import random
from django.db import connections
from django.conf import settings
class MumbleManager:
def __init__(self):
self.dbcursor = connections['mumble'].cursor()
@staticmethod
def _gen_pwhash(password):
return hashlib.sha1(password).hexdigest()
def get_user_id_by_name(self, name):
self.dbcursor.execute(r"SELECT user_id from murmur_users WHERE name = %s AND server_id = %s",
[name, settings.MUMBLE_SERVER_ID])
row = self.dbcursor.fetchone()
if row:
return row[0]
def create_user(self, username, password):
""" Add a user """
self.dbcursor.execute(r"SELECT max(user_id)+1 as next_id from murmur_users")
user_id = self.dbcursor.fetchone()[0]
self.dbcursor.execute(r"INSERT INTO murmur_users (server_id, user_id, name, pw) VALUES (%s, %s, %s, %s)",
[settings.MUMBLE_SERVER_ID, user_id, self.__santatize_username(username), self._gen_pwhash(password)])
return {'username': username, 'password': password }
def check_user_exist(self, username):
""" Check if the username exists """
self.dbcursor.execute(r"SELECT name from murmur_users WHERE name = %s AND server_id = %s",
[username, settings.MUMBLE_SERVER_ID])
row = self.dbcursor.fetchone()
if row and row[0].lower() == username.lower():
return True
return False
def delete_user(self, uid):
""" Delete a user """
id = self.get_user_id_by_name(uid)
self.dbcursor.execute(r"DELETE FROM murmur_users WHERE user_id = %s AND server_id = %s",
[id, settings.MUMBLE_SERVER_ID])
return True
def __santatize_username(self, username):
sanatized = username.replace(" ","_")
return sanatized.lower()

View File

@@ -0,0 +1,67 @@
import random
from passlib.apps import phpbb3_context
from django.db import connections
class Phpbb3Manager():
SQL_ADD_USER = r"INSERT INTO phpbb_users (username, username_clean, " \
r"user_password, user_email, group_id , user_permissions, " \
r"user_sig, user_occ, user_interests) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
SQL_DIS_USER = r"DELETE FROM phpbb_user_groups where user_id = " \
r"(SELECT user_id FROM phpbb_users WHERE username = %s)"
SQL_CHECK_USER = r"SELECT user_id from phpbb_users WHERE username = %s"
SQL_ADD_USER_GROUP = r"INSERT INTO phpbb_user_group (group_id, user_id, user_pending) VALUES (%s, %s, %s)"
SQL_GET_GROUP = r"SELECT group_id from phpbb_groups WHERE group_name = %s"
SQL_ADD_GROUP = r"INSERT INTO phpbb_groups (group_name) VALUES (%s)"
def __init__(self):
pass
def _gen_salt(self):
return "%x" % random.randint(0, 2147483647)
def _gen_hash(self, password):
return phpbb3_context.encrypt(password)
def add_user(self, username, password, email, groups):
cursor = connections['phpbb3'].cursor()
""" Add a user """
username_clean = username.lower()
pwhash = self._gen_hash(password)
cursor.execute(self.SQL_ADD_USER, [username, username_clean, pwhash, email, 2, "", "","", ""])
self.update_groups(username,groups)
return { 'username': username, 'password': password }
def update_groups(self, username, groups):
cursor = connections['phpbb3'].cursor()
cursor.execute(self.SQL_CHECK_USER, [username])
row = cursor.fetchone()
userid = row[0]
for group in groups:
cursor.execute(self.SQL_GET_GROUP, [group])
row = cursor.fetchone()
print row
if not row:
cursor.execute(self.SQL_ADD_GROUP, [group])
cursor.execute(self.SQL_GET_GROUP, [group])
row = cursor.fetchone()
cursor.execute(self.SQL_ADD_USER_GROUP, [row[0], userid,0])
def check_user(self, username):
cursor = connections['phpbb3'].cursor()
""" Check if the username exists """
cursor.execute(self.SQL_CHECK_USER, [username])
row = cursor.fetchone()
if row:
return True
return False