mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-11 21:40:17 +02:00
SMF Forum Integration
* Added SMF Forum Support * removed comment * Fixed bugs. * removed unused SQL statement * Fixed Grammer in debug code * Fixed Null Bug * Update operationmanagement.html * fixed bug * fixed error * Users now show up on the posts correctly
This commit is contained in:
parent
d8d663519b
commit
cfe0e23430
@ -106,6 +106,14 @@ DATABASES = {
|
|||||||
'PASSWORD': os.environ.get('AA_DB_IPS4_PASSWORD', 'password'),
|
'PASSWORD': os.environ.get('AA_DB_IPS4_PASSWORD', 'password'),
|
||||||
'HOST': os.environ.get('AA_DB_IPS4_HOST', '127.0.0.1'),
|
'HOST': os.environ.get('AA_DB_IPS4_HOST', '127.0.0.1'),
|
||||||
'PORT': os.environ.get('AA_DB_IPS4_PORT', '3306'),
|
'PORT': os.environ.get('AA_DB_IPS4_PORT', '3306'),
|
||||||
|
},
|
||||||
|
'smf': {
|
||||||
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
|
'NAME': 'alliance_smf',
|
||||||
|
'USER': os.environ.get('AA_DB_SMF_USER', 'allianceserver'),
|
||||||
|
'PASSWORD': os.environ.get('AA_DB_SMF_PASSWORD', 'password'),
|
||||||
|
'HOST': os.environ.get('AA_DB_SMF_HOST', '127.0.0.1'),
|
||||||
|
'PORT': os.environ.get('AA_DB_SMF_PORT', '3306'),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -206,10 +214,12 @@ EMAIL_USE_TLS = 'True' == os.environ.get('AA_EMAIL_USE_TLS', 'True')
|
|||||||
# KILLBOARD_URL - URL for your killboard. Blank to hide link
|
# KILLBOARD_URL - URL for your killboard. Blank to hide link
|
||||||
# MEDIA_URL - URL for your media page (youtube etc). Blank to hide link
|
# MEDIA_URL - URL for your media page (youtube etc). Blank to hide link
|
||||||
# FORUM_URL - URL for your forums. Blank to hide link
|
# FORUM_URL - URL for your forums. Blank to hide link
|
||||||
|
# SMF_URL - URL for your SMF forums.
|
||||||
####################
|
####################
|
||||||
KILLBOARD_URL = os.environ.get('AA_KILLBOARD_URL', '')
|
KILLBOARD_URL = os.environ.get('AA_KILLBOARD_URL', '')
|
||||||
EXTERNAL_MEDIA_URL = os.environ.get('AA_EXTERNAL_MEDIA_URL', '')
|
EXTERNAL_MEDIA_URL = os.environ.get('AA_EXTERNAL_MEDIA_URL', '')
|
||||||
FORUM_URL = os.environ.get('AA_FORUM_URL', '')
|
FORUM_URL = os.environ.get('AA_FORUM_URL', '')
|
||||||
|
SMF_URL = os.environ.get('AA_SMF_URL', '')
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# Default Group Settings
|
# Default Group Settings
|
||||||
@ -235,6 +245,7 @@ BLUE_ALLIANCE_GROUPS = 'True' == os.environ.get('AA_BLUE_ALLIANCE_GROUPS', 'Fals
|
|||||||
# ENABLE_AUTH_IPBOARD - Enable IPBoard forum support in the auth for auth'd members
|
# ENABLE_AUTH_IPBOARD - Enable IPBoard forum support in the auth for auth'd members
|
||||||
# ENABLE_AUTH_DISCORD - Enable Discord support in the auth for auth'd members
|
# ENABLE_AUTH_DISCORD - Enable Discord support in the auth for auth'd members
|
||||||
# ENABLE_AUTH_IPS4 - Enable IPS4 support in the auth for auth'd members
|
# ENABLE_AUTH_IPS4 - Enable IPS4 support in the auth for auth'd members
|
||||||
|
# ENABLE_AUTH_SMF - Enable SMF forum support in the auth for auth'd members
|
||||||
#########################
|
#########################
|
||||||
ENABLE_AUTH_FORUM = 'True' == os.environ.get('AA_ENABLE_AUTH_FORUM', 'False')
|
ENABLE_AUTH_FORUM = 'True' == os.environ.get('AA_ENABLE_AUTH_FORUM', 'False')
|
||||||
ENABLE_AUTH_JABBER = 'True' == os.environ.get('AA_ENABLE_AUTH_JABBER', 'False')
|
ENABLE_AUTH_JABBER = 'True' == os.environ.get('AA_ENABLE_AUTH_JABBER', 'False')
|
||||||
@ -243,6 +254,7 @@ ENABLE_AUTH_IPBOARD = 'True' == os.environ.get('AA_ENABLE_AUTH_IPBOARD', 'False'
|
|||||||
ENABLE_AUTH_TEAMSPEAK3 = 'True' == os.environ.get('AA_ENABLE_AUTH_TEAMSPEAK3', 'False')
|
ENABLE_AUTH_TEAMSPEAK3 = 'True' == os.environ.get('AA_ENABLE_AUTH_TEAMSPEAK3', 'False')
|
||||||
ENABLE_AUTH_DISCORD = 'True' == os.environ.get('AA_ENABLE_AUTH_DISCORD', 'False')
|
ENABLE_AUTH_DISCORD = 'True' == os.environ.get('AA_ENABLE_AUTH_DISCORD', 'False')
|
||||||
ENABLE_AUTH_IPS4 = 'True' == os.environ.get('AA_ENABLE_AUTH_IPS4', 'False')
|
ENABLE_AUTH_IPS4 = 'True' == os.environ.get('AA_ENABLE_AUTH_IPS4', 'False')
|
||||||
|
ENABLE_AUTH_SMF = 'True' == os.environ.get('AA_ENABLE_AUTH_SMF', 'False')
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Blue service Setup
|
# Blue service Setup
|
||||||
@ -253,7 +265,8 @@ ENABLE_AUTH_IPS4 = 'True' == os.environ.get('AA_ENABLE_AUTH_IPS4', 'False')
|
|||||||
# ENABLE_BLUE_MUMBLE - Enable mumble support in the auth for blues
|
# ENABLE_BLUE_MUMBLE - Enable mumble support in the auth for blues
|
||||||
# ENABLE_BLUE_IPBOARD - Enable IPBoard forum support in the auth for blues
|
# ENABLE_BLUE_IPBOARD - Enable IPBoard forum support in the auth for blues
|
||||||
# ENABLE_BLUE_DISCORD - Enable Discord support in the auth for blues
|
# ENABLE_BLUE_DISCORD - Enable Discord support in the auth for blues
|
||||||
# ENABLE_BLUE_IPS4 - Enable IPS4 support in the auth for blues
|
# ENABLE_BLUE_IPS4 - Enable IPS4 forum support in the auth for blues
|
||||||
|
# ENABLE_BLUE_SMF - Enable SMF forum support in the auth for blues
|
||||||
#####################
|
#####################
|
||||||
BLUE_STANDING = float(os.environ.get('AA_BLUE_STANDING', '5.0'))
|
BLUE_STANDING = float(os.environ.get('AA_BLUE_STANDING', '5.0'))
|
||||||
ENABLE_BLUE_FORUM = 'True' == os.environ.get('AA_ENABLE_BLUE_FORUM', 'False')
|
ENABLE_BLUE_FORUM = 'True' == os.environ.get('AA_ENABLE_BLUE_FORUM', 'False')
|
||||||
@ -263,6 +276,7 @@ ENABLE_BLUE_IPBOARD = 'True' == os.environ.get('AA_ENABLE_BLUE_IPBOARD', 'False'
|
|||||||
ENABLE_BLUE_TEAMSPEAK3 = 'True' == os.environ.get('AA_ENABLE_BLUE_TEAMSPEAK3', 'False')
|
ENABLE_BLUE_TEAMSPEAK3 = 'True' == os.environ.get('AA_ENABLE_BLUE_TEAMSPEAK3', 'False')
|
||||||
ENABLE_BLUE_DISCORD = 'True' == os.environ.get('AA_ENABLE_BLUE_DISCORD', 'False')
|
ENABLE_BLUE_DISCORD = 'True' == os.environ.get('AA_ENABLE_BLUE_DISCORD', 'False')
|
||||||
ENABLE_BLUE_IPS4 = 'True' == os.environ.get('AA_ENABLE_BLUE_IPS4', 'False')
|
ENABLE_BLUE_IPS4 = 'True' == os.environ.get('AA_ENABLE_BLUE_IPS4', 'False')
|
||||||
|
ENABLE_BLUE_SMF = 'True' == os.environ.get('AA_ENABLE_BLUE_SMF', 'False')
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# Corp Configuration
|
# Corp Configuration
|
||||||
|
@ -146,6 +146,13 @@ urlpatterns = patterns('',
|
|||||||
name='auth_reset_ips4_password'),
|
name='auth_reset_ips4_password'),
|
||||||
url(r'^set_ips4_password/$', 'services.views.set_ips4_password', name='auth_set_ips4_password'),
|
url(r'^set_ips4_password/$', 'services.views.set_ips4_password', name='auth_set_ips4_password'),
|
||||||
|
|
||||||
|
# SMF Service Control
|
||||||
|
url(r'^activate_smf/$', 'services.views.activate_smf', name='auth_activate_smf'),
|
||||||
|
url(r'^deactivate_smf/$', 'services.views.deactivate_smf', name='auth_deactivate_smf'),
|
||||||
|
url(r'^reset_smf_password/$', 'services.views.reset_smf_password',
|
||||||
|
name='auth_reset_smf_password'),
|
||||||
|
url(r'^set_smf_password/$', 'services.views.set_smf_password', name='auth_set_smf_password'),
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
url(r'^tool/fleet_formatter_tool/$', 'services.views.fleet_formatter_view',
|
url(r'^tool/fleet_formatter_tool/$', 'services.views.fleet_formatter_view',
|
||||||
name='auth_fleet_format_tool_view'),
|
name='auth_fleet_format_tool_view'),
|
||||||
|
@ -135,3 +135,14 @@ class AuthServicesInfoManager:
|
|||||||
else:
|
else:
|
||||||
logger.error("Failed to update user %s IPS4 info: user does not exist." % user)
|
logger.error("Failed to update user %s IPS4 info: user does not exist." % user)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update_user_smf_info(username, password, user):
|
||||||
|
if User.objects.filter(username=user.username).exists():
|
||||||
|
logger.debug("Updating user %s forum info: username %s" % (user, username))
|
||||||
|
authserviceinfo = AuthServicesInfoManager.__get_or_create(user)
|
||||||
|
authserviceinfo.smf_username = username
|
||||||
|
authserviceinfo.smf_password = password
|
||||||
|
authserviceinfo.save(update_fields=['smf_username', 'smf_password'])
|
||||||
|
logger.info("Updated user %s smf info in authservicesinfo model." % user)
|
||||||
|
else:
|
||||||
|
logger.error("Failed to update user %s smf info: user does not exist." % user)
|
||||||
|
@ -17,6 +17,8 @@ class AuthServicesInfo(models.Model):
|
|||||||
ips4_username = models.CharField(max_length=254, blank=True, default="")
|
ips4_username = models.CharField(max_length=254, blank=True, default="")
|
||||||
ips4_password = models.CharField(max_length=254, blank=True, default="")
|
ips4_password = models.CharField(max_length=254, blank=True, default="")
|
||||||
ips4_id = models.CharField(max_length=254, blank=True, default="")
|
ips4_id = models.CharField(max_length=254, blank=True, default="")
|
||||||
|
smf_username = models.CharField(max_length=254, blank=True, default="")
|
||||||
|
smf_password = models.CharField(max_length=254, blank=True, default="")
|
||||||
main_char_id = models.CharField(max_length=64, blank=True, default="")
|
main_char_id = models.CharField(max_length=64, blank=True, default="")
|
||||||
is_blue = models.BooleanField(default=False)
|
is_blue = models.BooleanField(default=False)
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
|
@ -10,6 +10,7 @@ from .tasks import update_forum_groups
|
|||||||
from .tasks import update_ipboard_groups
|
from .tasks import update_ipboard_groups
|
||||||
from .tasks import update_discord_groups
|
from .tasks import update_discord_groups
|
||||||
from .tasks import update_teamspeak3_groups
|
from .tasks import update_teamspeak3_groups
|
||||||
|
from .tasks import update_smf_groups
|
||||||
from authentication.models import AuthServicesInfo
|
from authentication.models import AuthServicesInfo
|
||||||
from services.models import AuthTS
|
from services.models import AuthTS
|
||||||
|
|
||||||
@ -27,6 +28,8 @@ def m2m_changed_user_groups(sender, instance, action, *args, **kwargs):
|
|||||||
update_teamspeak3_groups.delay(instance.pk)
|
update_teamspeak3_groups.delay(instance.pk)
|
||||||
if auth.forum_username:
|
if auth.forum_username:
|
||||||
update_forum_groups.delay(instance.pk)
|
update_forum_groups.delay(instance.pk)
|
||||||
|
if auth.smf_username:
|
||||||
|
update_smf_groups.delay(instance.pk)
|
||||||
if auth.ipboard_username:
|
if auth.ipboard_username:
|
||||||
update_ipboard_groups.delay(instance.pk)
|
update_ipboard_groups.delay(instance.pk)
|
||||||
if auth.discord_uid:
|
if auth.discord_uid:
|
||||||
|
@ -11,6 +11,7 @@ from services.managers.phpbb3_manager import Phpbb3Manager
|
|||||||
from services.managers.ipboard_manager import IPBoardManager
|
from services.managers.ipboard_manager import IPBoardManager
|
||||||
from services.managers.teamspeak3_manager import Teamspeak3Manager
|
from services.managers.teamspeak3_manager import Teamspeak3Manager
|
||||||
from services.managers.discord_manager import DiscordManager, DiscordAPIManager
|
from services.managers.discord_manager import DiscordManager, DiscordAPIManager
|
||||||
|
from services.managers.smf_manager import smfManager
|
||||||
from services.models import AuthTS
|
from services.models import AuthTS
|
||||||
from services.models import TSgroup
|
from services.models import TSgroup
|
||||||
from authentication.models import AuthServicesInfo
|
from authentication.models import AuthServicesInfo
|
||||||
@ -107,6 +108,25 @@ def update_forum_groups(pk):
|
|||||||
raise self.retry(countdown = 60 * 10)
|
raise self.retry(countdown = 60 * 10)
|
||||||
logger.debug("Updated user %s forum groups." % user)
|
logger.debug("Updated user %s forum groups." % user)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def update_smf_groups(pk):
|
||||||
|
user = User.objects.get(pk=pk)
|
||||||
|
logger.debug("Updating smf groups for user %s" % user)
|
||||||
|
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||||
|
groups = []
|
||||||
|
for group in user.groups.all():
|
||||||
|
groups.append(str(group.name))
|
||||||
|
if len(groups) == 0:
|
||||||
|
groups.append('empty')
|
||||||
|
logger.debug("Updating user %s smf groups to %s" % (user, groups))
|
||||||
|
try:
|
||||||
|
smfManager.update_groups(authserviceinfo.smf_username, groups)
|
||||||
|
except:
|
||||||
|
logger.exception("smf group sync failed for %s, retrying in 10 mins" % user)
|
||||||
|
raise self.retry(countdown = 60 * 10)
|
||||||
|
logger.debug("Updated user %s smf groups." % user)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def update_ipboard_groups(pk):
|
def update_ipboard_groups(pk):
|
||||||
user = User.objects.get(pk=pk)
|
user = User.objects.get(pk=pk)
|
||||||
|
260
services/managers/smf_manager.py
Normal file
260
services/managers/smf_manager.py
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
import os
|
||||||
|
import calendar
|
||||||
|
from datetime import datetime
|
||||||
|
import hashlib
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from django.db import connections
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class smfManager:
|
||||||
|
SQL_ADD_USER = r"INSERT INTO smf_members (member_name, passwd, email_address, date_registered, real_name," \
|
||||||
|
r" buddy_list, message_labels, openid_uri, signature, ignore_boards) " \
|
||||||
|
r"VALUES (%s, %s, %s, %s, %s, 0, 0, 0, 0, 0)"
|
||||||
|
|
||||||
|
SQL_DEL_USER = r"DELETE FROM smf_members where member_name = %s"
|
||||||
|
|
||||||
|
SQL_DIS_USER = r"UPDATE smf_members SET email_address = %s, passwd = %s WHERE member_name = %s"
|
||||||
|
|
||||||
|
SQL_USER_ID_FROM_USERNAME = r"SELECT id_member from smf_members WHERE member_name = %s"
|
||||||
|
|
||||||
|
SQL_ADD_USER_GROUP = r"UPDATE smf_members SET additional_groups = %s WHERE id_member = %s"
|
||||||
|
|
||||||
|
SQL_GET_GROUP_ID = r"SELECT id_group from smf_membergroups WHERE group_name = %s"
|
||||||
|
|
||||||
|
SQL_ADD_GROUP = r"INSERT INTO smf_membergroups (group_name,description) VALUES (%s,%s)"
|
||||||
|
|
||||||
|
SQL_UPDATE_USER_PASSWORD = r"UPDATE smf_members SET passwd = %s WHERE member_name = %s"
|
||||||
|
|
||||||
|
SQL_REMOVE_USER_GROUP = r"UPDATE smf_members SET additional_groups = %s WHERE id_member = %s"
|
||||||
|
|
||||||
|
SQL_GET_ALL_GROUPS = r"SELECT id_group, group_name FROM smf_membergroups"
|
||||||
|
|
||||||
|
SQL_GET_USER_GROUPS = r"SELECT additional_groups FROM smf_members WHERE id_member = %s"
|
||||||
|
|
||||||
|
SQL_ADD_USER_AVATAR = r"UPDATE smf_members SET avatar = %s WHERE id_member = %s"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_random_pass():
|
||||||
|
return os.urandom(8).encode('hex')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def gen_hash(username_clean, passwd):
|
||||||
|
return hashlib.sha1((username_clean) + passwd).hexdigest()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def santatize_username(username):
|
||||||
|
sanatized = username.replace(" ", "_")
|
||||||
|
sanatized = sanatized.replace("'", "")
|
||||||
|
return sanatized.lower()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_current_utc_date():
|
||||||
|
d = datetime.utcnow()
|
||||||
|
unixtime = calendar.timegm(d.utctimetuple())
|
||||||
|
return unixtime
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_group(groupname):
|
||||||
|
logger.debug("Creating smf group %s" % groupname)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_ADD_GROUP, [groupname, groupname])
|
||||||
|
logger.info("Created smf group %s" % groupname)
|
||||||
|
return smfManager.get_group_id(groupname)
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_group_id(groupname):
|
||||||
|
logger.debug("Getting smf group id for groupname %s" % groupname)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_GET_GROUP_ID, [groupname])
|
||||||
|
row = cursor.fetchone()
|
||||||
|
logger.debug("Got smf group id %s for groupname %s" % (row[0], groupname))
|
||||||
|
return row[0]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_user(username):
|
||||||
|
logger.debug("Checking smf username %s" % username)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_USER_ID_FROM_USERNAME, [smfManager.santatize_username(username)])
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
logger.debug("Found user %s on smf" % username)
|
||||||
|
return True
|
||||||
|
logger.debug("User %s not found on smf" % username)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add_avatar(member_name, characterid):
|
||||||
|
logger.debug("Adding EVE character id %s portrait as smf avatar for user %s" % (characterid, member_name))
|
||||||
|
avatar_url = "https://image.eveonline.com/Character/" + characterid + "_64.jpg"
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
id_member = smfManager.get_user_id(member_name)
|
||||||
|
cursor.execute(smfManager.SQL_ADD_USER_AVATAR, [avatar_url, id_member])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_user_id(username):
|
||||||
|
logger.debug("Getting smf user id for username %s" % username)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_USER_ID_FROM_USERNAME, [username])
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if row is not None:
|
||||||
|
logger.debug("Got smf user id %s for username %s" % (row[0], username))
|
||||||
|
return row[0]
|
||||||
|
else:
|
||||||
|
logger.error("username %s not found on smf. Unable to determine user id ." % username)
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_all_groups():
|
||||||
|
logger.debug("Getting all smf groups.")
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_GET_ALL_GROUPS)
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
out = {}
|
||||||
|
for row in rows:
|
||||||
|
out[row[1]] = row[0]
|
||||||
|
logger.debug("Got smf groups %s" % out)
|
||||||
|
return out
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_user_groups(userid):
|
||||||
|
logger.debug("Getting smf user id %s groups" % userid)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_GET_USER_GROUPS, [userid])
|
||||||
|
out = [row[0] for row in cursor.fetchall()]
|
||||||
|
logger.debug("Got user %s smf groups %s" % (userid, out))
|
||||||
|
return out
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add_user(username, email_address, groups, characterid):
|
||||||
|
logger.debug("Adding smf user with member_name %s, email_address %s, characterid %s" % (username, email_address, characterid))
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
username_clean = smfManager.santatize_username(username)
|
||||||
|
passwd = smfManager.generate_random_pass()
|
||||||
|
pwhash = smfManager.gen_hash(username_clean, passwd)
|
||||||
|
logger.debug("Proceeding to add smf user %s and pwhash starting with %s" % (username, pwhash[0:5]))
|
||||||
|
register_date = smfManager.get_current_utc_date()
|
||||||
|
# check if the username was simply revoked
|
||||||
|
if smfManager.check_user(username)is True :
|
||||||
|
logger.warn("Unable to add smf user with username %s - already exists. Updating user instead." % username)
|
||||||
|
smfManager.__update_user_info(username_clean, email_address, pwhash)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
cursor.execute(smfManager.SQL_ADD_USER, [username_clean, passwd, email_address, register_date, username_clean])
|
||||||
|
smfManager.add_avatar(username_clean, characterid)
|
||||||
|
logger.info("Added smf member_name %s" % username_clean)
|
||||||
|
smfManager.update_groups(username_clean, groups)
|
||||||
|
except:
|
||||||
|
logger.warn("Unable to add smf user %s" % username_clean)
|
||||||
|
pass
|
||||||
|
return username_clean, passwd
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __update_user_info(username, email_address, passwd):
|
||||||
|
logger.debug("Updating smf user %s info: username %s password of length %s" % (username, email_address, len(passwd)))
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
try:
|
||||||
|
cursor.execute(smfManager.SQL_DIS_USER, [email_address, passwd, username])
|
||||||
|
logger.info("Updated smf user %s info" % username)
|
||||||
|
except:
|
||||||
|
logger.exception("Unable to update smf user %s info." % username)
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_user(username):
|
||||||
|
logger.debug("Deleting smf user %s" % username)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
|
||||||
|
if smfManager.check_user(username):
|
||||||
|
cursor.execute(smfManager.SQL_DEL_USER, [username])
|
||||||
|
logger.info("Deleted smf user %s" % username)
|
||||||
|
return True
|
||||||
|
logger.error("Unable to delete smf user %s - user not found on smf." % username)
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update_groups(username, groups):
|
||||||
|
userid = smfManager.get_user_id(username)
|
||||||
|
logger.debug("Updating smf user %s with id %s groups %s" % (username, userid, groups))
|
||||||
|
if userid is not None:
|
||||||
|
forum_groups = smfManager.get_all_groups()
|
||||||
|
user_groups = set(smfManager.get_user_groups(userid))
|
||||||
|
act_groups = set([g.replace(' ', '-') for g in groups])
|
||||||
|
addgroups = act_groups - user_groups
|
||||||
|
remgroups = user_groups - act_groups
|
||||||
|
logger.info("Updating smf user %s groups - adding %s, removing %s" % (username, addgroups, remgroups))
|
||||||
|
act_group_id = set()
|
||||||
|
for g in addgroups:
|
||||||
|
if not g in forum_groups:
|
||||||
|
forum_groups[g] = smfManager.create_group(g)
|
||||||
|
act_group_id.add(str(smfManager.get_group_id(g)))
|
||||||
|
string_groups = ','.join(act_group_id)
|
||||||
|
smfManager.add_user_to_group(userid, string_groups)
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add_user_to_group(userid, groupid):
|
||||||
|
logger.debug("Adding smf user id %s to group id %s" % (userid, groupid))
|
||||||
|
try:
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_ADD_USER_GROUP, [groupid, userid])
|
||||||
|
logger.info("Added smf user id %s to group id %s" % (userid, groupid))
|
||||||
|
except:
|
||||||
|
logger.exception("Unable to add smf user id %s to group id %s" % (userid, groupid))
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def remove_user_from_group(userid, groupid):
|
||||||
|
logger.debug("Removing smf user id %s from group id %s" % (userid, groupid))
|
||||||
|
try:
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
cursor.execute(smfManager.SQL_REMOVE_USER_GROUP, [groupid, userid])
|
||||||
|
logger.info("Removed smf user id %s from group id %s" % (userid, groupid))
|
||||||
|
except:
|
||||||
|
logger.exception("Unable to remove smf user id %s from group id %s" % (userid, groupid))
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def disable_user(username):
|
||||||
|
logger.debug("Disabling smf user %s" % username)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
|
||||||
|
password = smfManager.generate_random_pass()
|
||||||
|
revoke_email = "revoked@" + settings.DOMAIN
|
||||||
|
try:
|
||||||
|
pwhash = smfManager.gen_hash(username, password)
|
||||||
|
cursor.execute(smfManager.SQL_DIS_USER, [revoke_email, pwhash, username])
|
||||||
|
userid = smfManager.get_user_id(username)
|
||||||
|
smfManager.update_groups(username, [])
|
||||||
|
logger.info("Disabled smf user %s" % username)
|
||||||
|
return True
|
||||||
|
except TypeError as e:
|
||||||
|
logger.exception("TypeError occured while disabling user %s - failed to disable." % username)
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update_user_password(username, characterid, password=None):
|
||||||
|
logger.debug("Updating smf user %s password" % username)
|
||||||
|
cursor = connections['smf'].cursor()
|
||||||
|
if not password:
|
||||||
|
password = smfManager.generate_random_pass()
|
||||||
|
if smfManager.check_user(username):
|
||||||
|
username_clean = smfManager.santatize_username(username)
|
||||||
|
pwhash = smfManager.gen_hash(username_clean, password)
|
||||||
|
logger.debug("Proceeding to update smf user %s password with pwhash starting with %s" % (username, pwhash[0:5]))
|
||||||
|
cursor.execute(smfManager.SQL_UPDATE_USER_PASSWORD, [pwhash, username])
|
||||||
|
smfManager.add_avatar(username, characterid)
|
||||||
|
logger.info("Updated smf user %s password." % username)
|
||||||
|
return password
|
||||||
|
logger.error("Unable to update smf user %s password - user not found on smf." % username)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,12 +15,14 @@ from managers.ipboard_manager import IPBoardManager
|
|||||||
from managers.teamspeak3_manager import Teamspeak3Manager
|
from managers.teamspeak3_manager import Teamspeak3Manager
|
||||||
from managers.discord_manager import DiscordManager
|
from managers.discord_manager import DiscordManager
|
||||||
from managers.ips4_manager import Ips4Manager
|
from managers.ips4_manager import Ips4Manager
|
||||||
|
from managers.smf_manager import smfManager
|
||||||
from authentication.managers import AuthServicesInfoManager
|
from authentication.managers import AuthServicesInfoManager
|
||||||
from eveonline.managers import EveManager
|
from eveonline.managers import EveManager
|
||||||
from celerytask.tasks import update_jabber_groups
|
from celerytask.tasks import update_jabber_groups
|
||||||
from celerytask.tasks import update_mumble_groups
|
from celerytask.tasks import update_mumble_groups
|
||||||
from celerytask.tasks import update_forum_groups
|
from celerytask.tasks import update_forum_groups
|
||||||
from celerytask.tasks import update_ipboard_groups
|
from celerytask.tasks import update_ipboard_groups
|
||||||
|
from celerytask.tasks import update_smf_groups
|
||||||
from celerytask.tasks import update_teamspeak3_groups
|
from celerytask.tasks import update_teamspeak3_groups
|
||||||
from celerytask.tasks import update_discord_groups
|
from celerytask.tasks import update_discord_groups
|
||||||
from forms import JabberBroadcastForm
|
from forms import JabberBroadcastForm
|
||||||
@ -683,3 +685,83 @@ def deactivate_ips4(request):
|
|||||||
return HttpResponseRedirect("/services/")
|
return HttpResponseRedirect("/services/")
|
||||||
logger.error("Unsuccesful attempt to deactivate IPS4 for user %s" % request.user)
|
logger.error("Unsuccesful attempt to deactivate IPS4 for user %s" % request.user)
|
||||||
return HttpResponseRedirect("/dashboard")
|
return HttpResponseRedirect("/dashboard")
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@user_passes_test(service_blue_alliance_test)
|
||||||
|
def activate_smf(request):
|
||||||
|
logger.debug("activate_smf called by user %s" % request.user)
|
||||||
|
authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
|
||||||
|
# Valid now we get the main characters
|
||||||
|
character = EveManager.get_character_by_id(authinfo.main_char_id)
|
||||||
|
logger.debug("Adding smf user for user %s with main character %s" % (request.user, character))
|
||||||
|
result = smfManager.add_user(character.character_name, request.user.email, ['Member'], authinfo.main_char_id)
|
||||||
|
# if empty we failed
|
||||||
|
if result[0] != "":
|
||||||
|
AuthServicesInfoManager.update_user_smf_info(result[0], result[1], request.user)
|
||||||
|
logger.debug("Updated authserviceinfo for user %s with smf credentials. Updating groups." % request.user)
|
||||||
|
update_smf_groups.delay(request.user.pk)
|
||||||
|
logger.info("Succesfully activated smf for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/services/")
|
||||||
|
logger.error("Unsuccesful attempt to activate smf for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/dashboard")
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@user_passes_test(service_blue_alliance_test)
|
||||||
|
def deactivate_smf(request):
|
||||||
|
logger.debug("deactivate_smf called by user %s" % request.user)
|
||||||
|
authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
|
||||||
|
result = smfManager.disable_user(authinfo.smf_username)
|
||||||
|
# false we failed
|
||||||
|
if result:
|
||||||
|
AuthServicesInfoManager.update_user_smf_info("", "", request.user)
|
||||||
|
logger.info("Succesfully deactivated smf for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/services/")
|
||||||
|
logger.error("Unsuccesful attempt to activate smf for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/dashboard")
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@user_passes_test(service_blue_alliance_test)
|
||||||
|
def reset_smf_password(request):
|
||||||
|
logger.debug("reset_smf_password called by user %s" % request.user)
|
||||||
|
authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
|
||||||
|
result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id)
|
||||||
|
# false we failed
|
||||||
|
if result != "":
|
||||||
|
AuthServicesInfoManager.update_user_smf_info(authinfo.smf_username, result, request.user)
|
||||||
|
logger.info("Succesfully reset smf password for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/services/")
|
||||||
|
logger.error("Unsuccessful attempt to reset smf password for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/dashboard")
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@user_passes_test(service_blue_alliance_test)
|
||||||
|
def set_smf_password(request):
|
||||||
|
logger.debug("set_smf_password called by user %s" % request.user)
|
||||||
|
error = None
|
||||||
|
if request.method == 'POST':
|
||||||
|
logger.debug("Received POST request with form.")
|
||||||
|
form = ServicePasswordForm(request.POST)
|
||||||
|
logger.debug("Form is valid: %s" % form.is_valid())
|
||||||
|
if form.is_valid():
|
||||||
|
password = form.cleaned_data['password']
|
||||||
|
logger.debug("Form contains password of length %s" % len(password))
|
||||||
|
authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
|
||||||
|
result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id, password=password)
|
||||||
|
if result != "":
|
||||||
|
AuthServicesInfoManager.update_user_smf_info(authinfo.smf_username, result, request.user)
|
||||||
|
logger.info("Succesfully reset smf password for user %s" % request.user)
|
||||||
|
return HttpResponseRedirect("/services/")
|
||||||
|
else:
|
||||||
|
logger.error("Failed to install custom smf password for user %s" % request.user)
|
||||||
|
error = "Failed to install custom password."
|
||||||
|
else:
|
||||||
|
error = "Invalid password provided"
|
||||||
|
else:
|
||||||
|
logger.debug("Request is not type POST - providing empty form.")
|
||||||
|
form = ServicePasswordForm()
|
||||||
|
|
||||||
|
logger.debug("Rendering form for user %s" % request.user)
|
||||||
|
context = {'form': form, 'service': 'Forum'}
|
||||||
|
return render_to_response('registered/service_password.html', context, context_instance=RequestContext(request))
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<th class="text-center">Action</th>
|
<th class="text-center">Action</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% for ops in optimer %}
|
{% for ops in optimer %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:150px" class="text-center">{{ ops.operation_name }}</td>
|
<td style="width:150px" class="text-center">{{ ops.operation_name }}</td>
|
||||||
@ -54,7 +54,7 @@
|
|||||||
<td style="width:150px" class="text-center">{{ ops.duration }}</td>
|
<td style="width:150px" class="text-center">{{ ops.duration }}</td>
|
||||||
<td style="width:150px" class="text-center">{{ ops.fc }}</td>
|
<td style="width:150px" class="text-center">{{ ops.fc }}</td>
|
||||||
<td style="width:150px" class="text-center">{{ ops.details }}</td>
|
<td style="width:150px" class="text-center">{{ ops.details }}</td>
|
||||||
<td style="width:150px" class="text-center">{{ ops.post_time}}</td>
|
<td style="width:150px" class="text-center">{{ ops.post_time}}</td>
|
||||||
{% if perms.auth.optimer_management %}
|
{% if perms.auth.optimer_management %}
|
||||||
<td style="width:150px" class="text-center">{{ ops.eve_character }}</td>
|
<td style="width:150px" class="text-center">{{ ops.eve_character }}</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@ -67,15 +67,15 @@
|
|||||||
class="glyphicon glyphicon-pencil"></span></button>
|
class="glyphicon glyphicon-pencil"></span></button>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/dateformat.js"></script>
|
<script src="/static/js/dateformat.js"></script>
|
||||||
|
@ -45,6 +45,33 @@
|
|||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if ENABLE_BLUE_SMF %}
|
||||||
|
<td class="text-center">SMF Forums</td>
|
||||||
|
<td class="text-center">{{ authinfo.smf_username }}</td>
|
||||||
|
<td class="text-center">{{ authinfo.smf_password }}</td>
|
||||||
|
<td class="text-center"><a href="{{ SMF_URL }}">{{ SMF_URL }}</a></td>
|
||||||
|
<td class="text-center">
|
||||||
|
{% ifequal authinfo.smf_username "" %}
|
||||||
|
<a href="{% url 'auth_activate_smf' %}">
|
||||||
|
<button type="button" class="btn btn-warning"><span
|
||||||
|
class="glyphicon glyphicon-ok"></span></button>
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'auth_set_smf_password' %}">
|
||||||
|
<button type="button" class="btn btn-warning"><span
|
||||||
|
class="glyphicon glyphicon-pencil"></span></button>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'auth_reset_smf_password' %}">
|
||||||
|
<button type="button" class="btn btn-primary"><span
|
||||||
|
class="glyphicon glyphicon-refresh"></span></button>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'auth_deactivate_smf' %}">
|
||||||
|
<button type="button" class="btn btn-danger"><span
|
||||||
|
class="glyphicon glyphicon-remove"></span></button>
|
||||||
|
</a>
|
||||||
|
{% endifequal %}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
{% if ENABLE_BLUE_IPBOARD %}
|
{% if ENABLE_BLUE_IPBOARD %}
|
||||||
<td class="text-center">IPBoard Forums</td>
|
<td class="text-center">IPBoard Forums</td>
|
||||||
<td class="text-center">{{ authinfo.ipboard_username }}</td>
|
<td class="text-center">{{ authinfo.ipboard_username }}</td>
|
||||||
@ -260,6 +287,35 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if ENABLE_AUTH_SMF %}
|
||||||
|
<tr>
|
||||||
|
<td class="text-center">SMF Forums</td>
|
||||||
|
<td class="text-center">{{ authinfo.smf_username }}</td>
|
||||||
|
<td class="text-center">{{ authinfo.smf_password }}</td>
|
||||||
|
<td class="text-center"><a href="{{ SMF_URL }}">{{ SMF_URL }}</a></td>
|
||||||
|
<td class="text-center">
|
||||||
|
{% ifequal authinfo.smf_username "" %}
|
||||||
|
<a href="{% url 'auth_activate_smf' %}">
|
||||||
|
<button type="button" class="btn btn-warning"><span
|
||||||
|
class="glyphicon glyphicon-ok"></span></button>
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'auth_set_smf_password' %}">
|
||||||
|
<button type="button" class="btn btn-warning"><span
|
||||||
|
class="glyphicon glyphicon-pencil"></span></button>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'auth_reset_smf_password' %}">
|
||||||
|
<button type="button" class="btn btn-primary"><span
|
||||||
|
class="glyphicon glyphicon-refresh"></span></button>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'auth_deactivate_smf' %}">
|
||||||
|
<button type="button" class="btn btn-danger"><span
|
||||||
|
class="glyphicon glyphicon-remove"></span></button>
|
||||||
|
</a>
|
||||||
|
{% endifequal %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% if ENABLE_AUTH_IPBOARD %}
|
{% if ENABLE_AUTH_IPBOARD %}
|
||||||
<td class="text-center">IPBoard Forums</td>
|
<td class="text-center">IPBoard Forums</td>
|
||||||
<td class="text-center">{{ authinfo.ipboard_username }}</td>
|
<td class="text-center">{{ authinfo.ipboard_username }}</td>
|
||||||
|
@ -38,6 +38,7 @@ def domain_url(request):
|
|||||||
'ENABLE_AUTH_TEAMSPEAK3': settings.ENABLE_AUTH_TEAMSPEAK3,
|
'ENABLE_AUTH_TEAMSPEAK3': settings.ENABLE_AUTH_TEAMSPEAK3,
|
||||||
'ENABLE_AUTH_DISCORD': settings.ENABLE_AUTH_DISCORD,
|
'ENABLE_AUTH_DISCORD': settings.ENABLE_AUTH_DISCORD,
|
||||||
'ENABLE_AUTH_IPS4': settings.ENABLE_AUTH_IPS4,
|
'ENABLE_AUTH_IPS4': settings.ENABLE_AUTH_IPS4,
|
||||||
|
'ENABLE_AUTH_SMF': settings.ENABLE_AUTH_SMF,
|
||||||
'ENABLE_BLUE_JABBER': settings.ENABLE_BLUE_JABBER,
|
'ENABLE_BLUE_JABBER': settings.ENABLE_BLUE_JABBER,
|
||||||
'ENABLE_BLUE_FORUM': settings.ENABLE_BLUE_FORUM,
|
'ENABLE_BLUE_FORUM': settings.ENABLE_BLUE_FORUM,
|
||||||
'ENABLE_BLUE_MUMBLE': settings.ENABLE_BLUE_MUMBLE,
|
'ENABLE_BLUE_MUMBLE': settings.ENABLE_BLUE_MUMBLE,
|
||||||
@ -45,10 +46,12 @@ def domain_url(request):
|
|||||||
'ENABLE_BLUE_TEAMSPEAK3': settings.ENABLE_BLUE_TEAMSPEAK3,
|
'ENABLE_BLUE_TEAMSPEAK3': settings.ENABLE_BLUE_TEAMSPEAK3,
|
||||||
'ENABLE_BLUE_DISCORD': settings.ENABLE_BLUE_DISCORD,
|
'ENABLE_BLUE_DISCORD': settings.ENABLE_BLUE_DISCORD,
|
||||||
'ENABLE_BLUE_IPS4': settings.ENABLE_BLUE_IPS4,
|
'ENABLE_BLUE_IPS4': settings.ENABLE_BLUE_IPS4,
|
||||||
|
'ENABLE_BLUE_SMF': settings.ENABLE_BLUE_SMF,
|
||||||
'TEAMSPEAK3_PUBLIC_URL': settings.TEAMSPEAK3_PUBLIC_URL,
|
'TEAMSPEAK3_PUBLIC_URL': settings.TEAMSPEAK3_PUBLIC_URL,
|
||||||
'JACK_KNIFE_URL': settings.JACK_KNIFE_URL,
|
'JACK_KNIFE_URL': settings.JACK_KNIFE_URL,
|
||||||
'DISCORD_SERVER_ID': settings.DISCORD_SERVER_ID,
|
'DISCORD_SERVER_ID': settings.DISCORD_SERVER_ID,
|
||||||
'KILLBOARD_URL': settings.KILLBOARD_URL,
|
'KILLBOARD_URL': settings.KILLBOARD_URL,
|
||||||
'IPS4_URL': settings.IPS4_URL,
|
'IPS4_URL': settings.IPS4_URL,
|
||||||
|
'SMF_URL': settings.SMF_URL,
|
||||||
'EXTERNAL_MEDIA_URL': settings.EXTERNAL_MEDIA_URL,
|
'EXTERNAL_MEDIA_URL': settings.EXTERNAL_MEDIA_URL,
|
||||||
'CURRENT_UTC_TIME': timezone.now()}
|
'CURRENT_UTC_TIME': timezone.now()}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user