mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 15:30:16 +02:00
Update to rule all updates. group support and clean up
This commit is contained in:
parent
a8571dd1c0
commit
8ce453c6b6
7
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
7
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
20
README.md
20
README.md
@ -1,27 +1,41 @@
|
||||
allianceauth
|
||||
============
|
||||
|
||||
Note: THIS WAS RUSHED! IT DOES NOT FOLLOW GOOD CODING STANDARDS
|
||||
Note2: Most importantly though it works....
|
||||
Alliance service auth to help large scale alliances manage services.
|
||||
Built for "The 99 Percent" open for anyone to use
|
||||
|
||||
Requirments:
|
||||
|
||||
# Django Stuff #
|
||||
django 1.6.1
|
||||
django-evolution
|
||||
django-bootstrap-form
|
||||
django-celery
|
||||
|
||||
# Python Stuff #
|
||||
python-mysql-connector
|
||||
python-mysqld
|
||||
python-passlib
|
||||
python-evelink
|
||||
python-openfire
|
||||
|
||||
# Needed Apps
|
||||
rabbitmq
|
||||
bcrypt
|
||||
|
||||
Services Interaction:
|
||||
|
||||
# Supported services #
|
||||
Phpbb3 (Forums)
|
||||
Mumble (Voice)
|
||||
Openfire (Jabber)
|
||||
|
||||
|
||||
Startup Instructions:
|
||||
|
||||
python manage.py celeryd --verbosity=2 --loglevel=DEBUG
|
||||
python manage.py celerybeat --verbosity=2 --loglevel=DEBUG
|
||||
python manage.py runserver
|
||||
|
||||
|
||||
|
||||
Eve alliance auth for the 99 percent
|
||||
|
@ -10,6 +10,8 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
import os
|
||||
import djcelery
|
||||
djcelery.setup_loader()
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
|
||||
@ -26,12 +28,13 @@ TEMPLATE_DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
BROKER_URL = 'amqp://guest:guest@localhost:5672/'
|
||||
|
||||
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django_admin_bootstrapped.bootstrap3',
|
||||
'django_admin_bootstrapped',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
@ -39,6 +42,8 @@ INSTALLED_APPS = (
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django_evolution',
|
||||
'djcelery',
|
||||
'celerytask',
|
||||
'bootstrapform',
|
||||
'authentication',
|
||||
'portal',
|
||||
@ -141,9 +146,9 @@ ALLIANCE_ID = ''
|
||||
ALLIANCE_NAME = ''
|
||||
|
||||
# Jabber Prosody Info
|
||||
JABBER_URL = "@someaddress.com"
|
||||
OPENFIRE_ADDRESS = "http://someaddress.com:9090/"
|
||||
OPENFIRE_SECRET_KEY = "somekey"
|
||||
JABBER_URL = ""
|
||||
OPENFIRE_ADDRESS = ""
|
||||
OPENFIRE_SECRET_KEY = ""
|
||||
|
||||
# Mumble settings
|
||||
MUMBLE_SERVER_ID = 1
|
||||
MUMBLE_SERVER_ID = ''
|
||||
|
@ -146,4 +146,4 @@ OPENFIRE_ADDRESS = "http://the99eve.com:9090/"
|
||||
OPENFIRE_SECRET_KEY = "SrJ35I36"
|
||||
|
||||
# Mumble settings
|
||||
MUMBLE_SERVER_ID = 1
|
||||
MUMBLE_SERVER_ID = 1
|
||||
|
@ -18,8 +18,10 @@ urlpatterns = patterns('',
|
||||
|
||||
# Portal Urls
|
||||
url(r'^dashboard/$', 'portal.views.dashboard_view', name='auth_dashboard'),
|
||||
url(r'^help/$', 'portal.views.help_view', name='auth_help'),
|
||||
|
||||
# Eveonline Urls
|
||||
url(r'^add_api_key/', 'eveonline.views.add_api_key', name='auth_add_api_key'),
|
||||
url(r'^api_key_management/', 'eveonline.views.api_key_management_view', name='auth_api_key_management'),
|
||||
url(r'^delete_api_pair/(\w+)/$', 'eveonline.views.api_key_removal', name='auth_api_key_removal'),
|
||||
url(r'^characters/', 'eveonline.views.characters_view', name='auth_characters'),
|
||||
@ -27,6 +29,7 @@ urlpatterns = patterns('',
|
||||
|
||||
# Service Urls
|
||||
url(r'^services/', 'services.views.services_view', name='auth_services'),
|
||||
|
||||
# Forum Service Control
|
||||
url(r'^activate_forum/$', 'services.views.activate_forum', name='auth_activate_forum'),
|
||||
url(r'^deactivate_forum/$', 'services.views.deactivate_forum', name='auth_deactivate_forum'),
|
||||
|
0
celerytask/__init__.py
Normal file
0
celerytask/__init__.py
Normal file
3
celerytask/admin.py
Normal file
3
celerytask/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
10
celerytask/models.py
Normal file
10
celerytask/models.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class SyncGroupCache(models.Model):
|
||||
groupname = models.CharField(max_length=254)
|
||||
user = models.ForeignKey(User)
|
||||
|
||||
admin.site.register(SyncGroupCache)
|
95
celerytask/tasks.py
Normal file
95
celerytask/tasks.py
Normal file
@ -0,0 +1,95 @@
|
||||
from models import SyncGroupCache
|
||||
from celery import task
|
||||
from celery.task import periodic_task
|
||||
from celery.task.schedules import crontab
|
||||
from django.contrib.auth.models import User
|
||||
from services.managers.jabber_manager import JabberManager
|
||||
from services.managers.mumble_manager import MumbleManager
|
||||
from services.managers.forum_manager import ForumManager
|
||||
from authentication.models import AuthServicesInfo
|
||||
from django.utils.timezone import timedelta
|
||||
|
||||
|
||||
def update_jabber_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
groups = []
|
||||
for syncgroup in syncgroups:
|
||||
groups.append(str(syncgroup.groupname))
|
||||
|
||||
if len(groups) == 0:
|
||||
groups.append('empty')
|
||||
|
||||
JabberManager.update_user_groups(authserviceinfo.jabber_username, authserviceinfo.jabber_password, groups)
|
||||
|
||||
|
||||
def update_mumble_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
groups = []
|
||||
for syncgroup in syncgroups:
|
||||
groups.append(str(syncgroup.groupname))
|
||||
|
||||
if len(groups) == 0:
|
||||
groups.append('empty')
|
||||
|
||||
MumbleManager.update_groups(authserviceinfo.mumble_username, groups)
|
||||
|
||||
|
||||
def update_forum_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
groups = []
|
||||
for syncgroup in syncgroups:
|
||||
groups.append(str(syncgroup.groupname))
|
||||
|
||||
if len(groups) == 0:
|
||||
groups.append('empty')
|
||||
|
||||
ForumManager.update_groups(authserviceinfo.forum_username, groups)
|
||||
|
||||
|
||||
def add_to_databases(user, groups, syncgroups):
|
||||
update = False
|
||||
for group in groups:
|
||||
syncgroup = syncgroups.filter(groupname=group.name)
|
||||
if not syncgroup:
|
||||
# gotta create group
|
||||
# create syncgroup
|
||||
# create service groups
|
||||
synccache = SyncGroupCache()
|
||||
synccache.groupname = group.name
|
||||
synccache.user = user
|
||||
synccache.save()
|
||||
update = True
|
||||
|
||||
if update:
|
||||
update_jabber_groups(user)
|
||||
update_mumble_groups(user)
|
||||
update_forum_groups(user)
|
||||
|
||||
|
||||
def remove_from_databases(user, groups, syncgroups):
|
||||
update = False
|
||||
for syncgroup in syncgroups:
|
||||
group = groups.filter(name=syncgroup.groupname)
|
||||
|
||||
if not group:
|
||||
syncgroup.delete()
|
||||
update = True
|
||||
|
||||
if update:
|
||||
update_jabber_groups(user)
|
||||
update_mumble_groups(user)
|
||||
update_forum_groups(user)
|
||||
|
||||
|
||||
@periodic_task(run_every=timedelta(seconds=10))
|
||||
#@periodic_task(run_every=crontab(minute="*/1"))
|
||||
def run_databaseUpdate():
|
||||
users = User.objects.all()
|
||||
for user in users:
|
||||
groups = user.groups.all()
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
add_to_databases(user, groups, syncgroups)
|
||||
remove_from_databases(user, groups, syncgroups)
|
3
celerytask/tests.py
Normal file
3
celerytask/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
celerytask/views.py
Normal file
3
celerytask/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -12,10 +12,8 @@ from managers import EveManager
|
||||
from authentication.managers import AuthServicesInfoManager
|
||||
from services.managers.eve_api_manager import EveApiManager
|
||||
|
||||
|
||||
@login_required
|
||||
def api_key_management_view(request):
|
||||
|
||||
def add_api_key(request):
|
||||
if request.method == 'POST':
|
||||
form = UpdateKeyForm(request.POST)
|
||||
|
||||
@ -25,26 +23,35 @@ def api_key_management_view(request):
|
||||
request.user)
|
||||
|
||||
# Grab characters associated with the key pair
|
||||
|
||||
characters = EveApiManager.get_characters_from_api(form.cleaned_data['api_id'], form.cleaned_data['api_key'])
|
||||
EveManager.create_characters_from_list(characters, request.user, form.cleaned_data['api_id'])
|
||||
return HttpResponseRedirect("/api_key_management/")
|
||||
else:
|
||||
form = UpdateKeyForm()
|
||||
context = {'form': form, 'apikeypairs': EveManager.get_api_key_pairs(request.user.id)}
|
||||
return render_to_response('registered/addapikey.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def api_key_management_view(request):
|
||||
context = {'apikeypairs': EveManager.get_api_key_pairs(request.user.id)}
|
||||
|
||||
return render_to_response('registered/apikeymanagment.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def api_key_removal(request, api_id):
|
||||
authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
|
||||
# Check if our users main id is in the to be deleted characters
|
||||
characters = EveManager.get_characters_by_owner_id(request.user.id)
|
||||
if characters is not None:
|
||||
for character in characters:
|
||||
if character.character_id == request.user.main_char_id:
|
||||
# TODO: Remove servies also
|
||||
AuthServicesInfoManager.update_main_char_Id("", request.user.id)
|
||||
if character.character_id == authinfo.main_char_id:
|
||||
if character.api_id == api_id:
|
||||
# TODO: Remove servies also
|
||||
AuthServicesInfoManager.update_main_char_Id("", request.user)
|
||||
|
||||
EveManager.delete_api_key_pair(api_id, request.user.id)
|
||||
EveManager.delete_characters_by_api_id(api_id, request.user.id)
|
||||
|
@ -12,4 +12,9 @@ def index_view(request):
|
||||
|
||||
@login_required
|
||||
def dashboard_view(request):
|
||||
return render_to_response('registered/dashboard.html', None, context_instance=RequestContext(request))
|
||||
return render_to_response('registered/dashboard.html', None, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def help_view(request):
|
||||
return render_to_response('registered/help.html', None, context_instance=RequestContext(request))
|
||||
|
@ -13,16 +13,23 @@ class ForumManager:
|
||||
|
||||
SQL_DIS_USER = r"UPDATE phpbb_users SET user_email= %s, user_password=%s WHERE username = %s"
|
||||
|
||||
SQL_CHECK_USER = r"SELECT user_id from phpbb_users WHERE username = %s"
|
||||
SQL_USER_ID_FROM_USERNAME = 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_GET_GROUP_ID = r"SELECT group_id from phpbb_groups WHERE group_name = %s"
|
||||
|
||||
SQL_ADD_GROUP = r"INSERT INTO phpbb_groups (group_name) VALUES (%s)"
|
||||
SQL_ADD_GROUP = r"INSERT INTO phpbb_groups (group_name,group_desc) VALUES (%s,"")"
|
||||
|
||||
SQL_UPDATE_USER_PASSWORD = r"UPDATE phpbb_users SET user_password = %s WHERE username = %s"
|
||||
|
||||
SQL_REMOVE_USER_GROUP = r"DELETE FROM phpbb_user_group WHERE user_id=%s AND group_id=%s "
|
||||
|
||||
SQL_GET_ALL_GROUPS = r"SELECT group_id, group_name FROM phpbb_groups"
|
||||
|
||||
SQL_GET_USER_GROUPS = r"SELECT phpbb_groups.group_name FROM phpbb_groups , phpbb_user_group WHERE " \
|
||||
r"phpbb_user_group.group_id = phpbb_groups.group_id AND user_id=%s"
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@ -39,6 +46,55 @@ class ForumManager:
|
||||
sanatized = username.replace(" ", "_")
|
||||
return sanatized.lower()
|
||||
|
||||
@staticmethod
|
||||
def __get_group_id(groupname):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_GET_GROUP_ID, [groupname])
|
||||
row = cursor.fetchone()
|
||||
|
||||
return row[0]
|
||||
|
||||
@staticmethod
|
||||
def __get_user_id(username):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_USER_ID_FROM_USERNAME, [username])
|
||||
row = cursor.fetchone()
|
||||
return row[0]
|
||||
|
||||
@staticmethod
|
||||
def __get_all_groups():
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_GET_ALL_GROUPS)
|
||||
rows = cursor.fetchall()
|
||||
out = {}
|
||||
for row in rows:
|
||||
out[row[1]] = row[0]
|
||||
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def __get_user_groups(userid):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_GET_USER_GROUPS, [userid])
|
||||
return [row[0] for row in cursor.fetchall()]
|
||||
|
||||
@staticmethod
|
||||
def __create_group(groupname):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_ADD_GROUP, [groupname])
|
||||
return ForumManager.__get_group_id(groupname)
|
||||
|
||||
@staticmethod
|
||||
def __add_user_to_group(userid, groupid):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_ADD_USER_GROUP, [groupid, userid, 0])
|
||||
|
||||
@staticmethod
|
||||
def __remove_user_from_group(userid, groupid):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
cursor.execute(ForumManager.SQL_REMOVE_USER_GROUP, [userid, groupid])
|
||||
|
||||
|
||||
@staticmethod
|
||||
def add_user(username, email, groups):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
@ -85,27 +141,39 @@ class ForumManager:
|
||||
|
||||
@staticmethod
|
||||
def update_groups(username, groups):
|
||||
userid = ForumManager.__get_user_id(username)
|
||||
forum_groups = ForumManager.__get_all_groups()
|
||||
user_groups = set(ForumManager.__get_user_groups(userid))
|
||||
act_groups = set([g.replace(' ', '-') for g in groups])
|
||||
addgroups = act_groups - user_groups
|
||||
remgroups = user_groups - act_groups
|
||||
print addgroups
|
||||
print remgroups
|
||||
print userid
|
||||
for g in addgroups:
|
||||
if not g in forum_groups:
|
||||
forum_groups[g] = ForumManager.__create_group(g)
|
||||
ForumManager.__add_user_to_group(userid, forum_groups[g])
|
||||
|
||||
for g in remgroups:
|
||||
ForumManager.__remove_user_from_group(userid, forum_groups[g])
|
||||
|
||||
@staticmethod
|
||||
def remove_group(username, group):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
userid = ForumManager.__get_user_id(username)
|
||||
groupid = ForumManager.__get_group_id(group)
|
||||
|
||||
cursor.execute(ForumManager.SQL_CHECK_USER, [username])
|
||||
row = cursor.fetchone()
|
||||
userid = row[0]
|
||||
for group in groups:
|
||||
cursor.execute(ForumManager.SQL_GET_GROUP, [group])
|
||||
row = cursor.fetchone()
|
||||
print row
|
||||
if not row:
|
||||
cursor.execute(ForumManager.SQL_ADD_GROUP, [group])
|
||||
cursor.execute(ForumManager.SQL_GET_GROUP, [group])
|
||||
row = cursor.fetchone()
|
||||
if userid:
|
||||
if groupid:
|
||||
cursor.execute(ForumManager.SQL_REMOVE_USER_GROUP, [userid, groupid])
|
||||
|
||||
cursor.execute(ForumManager.SQL_ADD_USER_GROUP, [row[0], userid,0])
|
||||
|
||||
@staticmethod
|
||||
def check_user(username):
|
||||
cursor = connections['phpbb3'].cursor()
|
||||
""" Check if the username exists """
|
||||
cursor.execute(ForumManager.SQL_CHECK_USER, [ForumManager.__santatize_username(username)])
|
||||
cursor.execute(ForumManager.SQL_USER_ID_FROM_USERNAME, [ForumManager.__santatize_username(username)])
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
return True
|
||||
|
@ -67,4 +67,14 @@ class JabberManager:
|
||||
api.update_user(username, password)
|
||||
return password
|
||||
except exception.UserNotFoundException:
|
||||
return ""
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def update_user_groups(username, password, groups):
|
||||
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
|
||||
api.update_user(username, password, "", "", groups)
|
||||
|
||||
@staticmethod
|
||||
def delete_user_groups(username, groups):
|
||||
api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
|
||||
api.delete_group(username,groups)
|
@ -6,13 +6,39 @@ from django.conf import settings
|
||||
|
||||
class MumbleManager:
|
||||
|
||||
SQL_SELECT_MAX_ID = r"SELECT max(user_id)+1 as next_id from murmur_users"
|
||||
SQL_SELECT_USER_MAX_ID = r"SELECT max(user_id)+1 as next_id from murmur_users"
|
||||
|
||||
SQL_SELECT_GROUP_MAX_ID = r"SELECT MAX(group_id)+1 FROM murmur_groups"
|
||||
|
||||
SQL_CREATE_USER = r"INSERT INTO murmur_users (server_id, user_id, name, pw) VALUES (%s, %s, %s, %s)"
|
||||
|
||||
SQL_SELECT_GET_USER_ID_BY_NAME = r"SELECT user_id from murmur_users WHERE name = %s AND server_id = %s"
|
||||
|
||||
SQL_CHECK_USER_EXIST = r"SELECT name from murmur_users WHERE name = %s AND server_id = %s"
|
||||
|
||||
SQL_DELETE_USER = r"DELETE FROM murmur_users WHERE name = %s AND server_id = %s"
|
||||
|
||||
SQL_UPDATE_USER_PASSWORD = r"UPDATE murmur_users SET pw = %s WHERE name = %s AND server_id = %s"
|
||||
|
||||
SQL_GET_GROUPS = r"SELECT group_id, name FROM murmur_groups WHERE server_id = %s AND channel_id = 0"
|
||||
|
||||
SQL_GET_GROUP_FROM_NAME = r"SELECT group_id, name FROM murmur_groups " \
|
||||
r"WHERE server_id = %s AND channel_id = 0 AND name = %s"
|
||||
|
||||
SQL_GET_USER_GROUPS = r"SELECT murmur_groups.name FROM murmur_groups, murmur_group_members WHERE " \
|
||||
r"murmur_group_members.group_id = murmur_groups.group_id AND " \
|
||||
r"murmur_group_members.server_id = murmur_groups.server_id AND " \
|
||||
r"murmur_group_members.user_id = %s"
|
||||
|
||||
SQL_ADD_GROUP = r"INSERT INTO murmur_groups (group_id, server_id, name, channel_id, inherit, inheritable) " \
|
||||
r"VALUES (%s, %s, %s, 0, 1, 1)"
|
||||
|
||||
SQL_ADD_USER_TO_GROUP = r"INSERT INTO murmur_group_members (group_id, server_id, user_id, addit) " \
|
||||
r"VALUES (%s, %s, %s, 1)"
|
||||
|
||||
SQL_DELETE_USER_FROM_GROUP = r"DELETE FROM murmur_group_members WHERE group_id = %s " \
|
||||
r"AND server_id = %s AND user_id = %s"
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@ -33,6 +59,52 @@ class MumbleManager:
|
||||
def _gen_pwhash(password):
|
||||
return hashlib.sha1(password).hexdigest()
|
||||
|
||||
@staticmethod
|
||||
def _get_groups():
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
dbcursor.execute(MumbleManager.SQL_GET_GROUPS, [settings.MUMBLE_SERVER_ID])
|
||||
rows = dbcursor.fetchall()
|
||||
|
||||
out = {}
|
||||
for row in rows:
|
||||
out[row[1]] = row[0]
|
||||
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def _get_group(name):
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
dbcursor.execute(MumbleManager.SQL_GET_GROUP_FROM_NAME, [settings.MUMBLE_SERVER_ID, name])
|
||||
row = dbcursor.fetchone()
|
||||
if row:
|
||||
return row[0]
|
||||
|
||||
@staticmethod
|
||||
def _get_user_groups(name):
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
user_id = MumbleManager.get_user_id_by_name(name)
|
||||
dbcursor.execute(MumbleManager.SQL_GET_USER_GROUPS, [user_id])
|
||||
return [row[0] for row in dbcursor.fetchall()]
|
||||
|
||||
@staticmethod
|
||||
def _add_group(name):
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
dbcursor.execute(MumbleManager.SQL_SELECT_GROUP_MAX_ID)
|
||||
row = dbcursor.fetchone()
|
||||
groupid = row[0]
|
||||
dbcursor.execute(MumbleManager.SQL_ADD_GROUP, [groupid, settings.MUMBLE_SERVER_ID, name])
|
||||
return groupid
|
||||
|
||||
@staticmethod
|
||||
def _add_user_to_group(userid, groupid):
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
dbcursor.execute(MumbleManager.SQL_ADD_USER_TO_GROUP, [groupid, settings.MUMBLE_SERVER_ID, userid])
|
||||
|
||||
@staticmethod
|
||||
def _del_user_from_group(userid, groupid):
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
dbcursor.execute(MumbleManager.SQL_DELETE_USER_FROM_GROUP, [groupid, settings.MUMBLE_SERVER_ID, userid])
|
||||
|
||||
@staticmethod
|
||||
def get_user_id_by_name(name):
|
||||
dbcursor = connections['mumble'].cursor()
|
||||
@ -49,7 +121,7 @@ class MumbleManager:
|
||||
pwhash = MumbleManager._gen_pwhash(password)
|
||||
|
||||
try:
|
||||
dbcursor.execute(MumbleManager.SQL_SELECT_MAX_ID)
|
||||
dbcursor.execute(MumbleManager.SQL_SELECT_USER_MAX_ID)
|
||||
user_id = dbcursor.fetchone()[0]
|
||||
|
||||
dbcursor.execute(MumbleManager.SQL_CREATE_USER,
|
||||
@ -100,4 +172,21 @@ class MumbleManager:
|
||||
except:
|
||||
return ""
|
||||
|
||||
return ""
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def update_groups(username, groups):
|
||||
userid = MumbleManager.get_user_id_by_name(username)
|
||||
mumble_groups = MumbleManager._get_groups()
|
||||
user_groups = set(MumbleManager._get_user_groups(username))
|
||||
act_groups = set([g.replace(' ', '-') for g in groups])
|
||||
addgroups = act_groups - user_groups
|
||||
remgroups = user_groups - act_groups
|
||||
|
||||
for g in addgroups:
|
||||
if not g in mumble_groups:
|
||||
mumble_groups[g] = MumbleManager._add_group(g)
|
||||
MumbleManager._add_user_to_group(userid, mumble_groups[g])
|
||||
|
||||
for g in remgroups:
|
||||
MumbleManager._del_user_from_group(userid, mumble_groups[g])
|
||||
|
@ -12,6 +12,8 @@ from managers.mumble_manager import MumbleManager
|
||||
from authentication.managers import AuthServicesInfoManager
|
||||
from eveonline.managers import EveManager
|
||||
|
||||
from celerytask.tasks import update_jabber_groups
|
||||
from celerytask.tasks import update_mumble_groups
|
||||
|
||||
@login_required
|
||||
def services_view(request):
|
||||
@ -66,6 +68,7 @@ def activate_jabber(request):
|
||||
# If our username is blank means we already had a user
|
||||
if info[0] is not "":
|
||||
AuthServicesInfoManager.update_user_jabber_info(info[0], info[1], request.user)
|
||||
update_jabber_groups(request.user)
|
||||
return HttpResponseRedirect("/services/")
|
||||
return HttpResponseRedirect("/dashboard")
|
||||
|
||||
@ -103,8 +106,9 @@ def activate_mumble(request):
|
||||
# if its empty we failed
|
||||
if result[0] is not "":
|
||||
AuthServicesInfoManager.update_user_mumble_info(result[0], result[1], request.user)
|
||||
update_mumble_groups(request.user)
|
||||
return HttpResponseRedirect("/services/")
|
||||
return HttpResponseRedirect("/")
|
||||
return HttpResponseRedirect("/dashboard")
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -71,7 +71,7 @@
|
||||
<a {% ifequal request.path "/services/" %} class="active" {% endifequal %} href="{% url 'auth_services' %}"><i class="fa fa-cogs fa-fw"></i> Services</a>
|
||||
</li>
|
||||
<li>
|
||||
<a {% ifequal request.path "/help/" %} class="active" {% endifequal %} href=""><i class="fa fa-question fa-fw"></i> Help</a>
|
||||
<a {% ifequal request.path "/help/" %} class="active" {% endifequal %} href="{% url 'auth_help' %}"><i class="fa fa-question fa-fw"></i> Help</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
36
templates/registered/addapikey.html
Normal file
36
templates/registered/addapikey.html
Normal file
@ -0,0 +1,36 @@
|
||||
{% extends "public/base.html" %}
|
||||
{% load bootstrap %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Alliance Auth{% endblock %}
|
||||
|
||||
{% block page_title %}Something something here{% endblock page_title %}
|
||||
{% block extra_css %}{% endblock extra_css %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-lg-12">
|
||||
<h1 class="page-header text-center">Add Api Key</h1>
|
||||
<div class="container-fluid">
|
||||
<div class="col-md-4 col-md-offset-4">
|
||||
<div class="row">
|
||||
<p class="text-center">
|
||||
The minimum permission required for
|
||||
Alliance services: CharacterInfo
|
||||
</p>
|
||||
<p class="text-center">
|
||||
<a target="_blank" href="https://community.eveonline.com/support/api-key/CreatePredefined?accessMask=8921088">Create a standard API key</a>
|
||||
<br/>
|
||||
<a target="_blank" href="https://community.eveonline.com/support/api-key/CreatePredefined?accessMask=268435455">Create a full API key</a>
|
||||
</p>
|
||||
<form class="form-signin" role="form" action="{% url 'auth_add_api_key' %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form|bootstrap }}
|
||||
<br/>
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Add Key</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
@ -14,7 +14,13 @@
|
||||
{% else %}
|
||||
<div class="alert alert-danger" role="alert">No api keys found</div>
|
||||
{% endif %}
|
||||
<h1 class="page-header text-center">API Key Management</h1>
|
||||
<h1 class="page-header text-center">API Key Management
|
||||
<div class="text-right">
|
||||
<a href="{% url 'auth_add_api_key' %}">
|
||||
<button type="button" class="btn btn-success">Add Key</button>
|
||||
</a>
|
||||
</div>
|
||||
</h1>
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th class="text-center">API ID</th>
|
||||
@ -36,12 +42,6 @@
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<form class="form-signin" role="form" action="{% url 'auth_api_key_management' %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form|bootstrap_horizontal }}
|
||||
<br/>
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Add Key</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user