diff --git a/manage.py b/manage.py index 5e78ea9..b643a76 100755 --- a/manage.py +++ b/manage.py @@ -1,4 +1,15 @@ #!/usr/bin/env python +import sys +import os.path + +pwd = os.path.dirname(os.path.abspath(__file__)) +activate_this = os.path.join(pwd,'env','bin','activate_this.py') +try: + execfile(activate_this, dict(__file__=activate_this)) +except IOError: + sys.stderr.write('Error activating virtualenv\n') + sys.exit(1) + from django.core.management import execute_manager try: import settings # Assumed to be in the same directory. diff --git a/tools/extract-emails.py b/tools/extract-emails.py deleted file mode 100755 index 783be87..0000000 --- a/tools/extract-emails.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -"""Executes a Django cronjob""" - -import os - -# Set niceness -os.nice(20) - -# Activate the virtualenv -path = os.path.dirname(os.path.realpath( __file__ )) -activate_this = os.path.join(path, 'env/bin/activate_this.py') -execfile(activate_this, dict(__file__=activate_this)) - -import sys -import logging -from django.core.management import setup_environ -import settings - -setup_environ(settings) - -from eve_api.models import EVEPlayerCharacter -import unicodedata -import re - -chars = set(EVEPlayerCharacter.objects.filter(corporation__alliance__name='Test Alliance Please Ignore')) - -#f =open('/home/dreddit/email.txt', 'w') - -out = {} - -for char in chars: - if len(char.eveaccount_set.all()) > 0: - name = unicodedata.normalize('NFKD', char.name).encode('ASCII', 'ignore') - charname = re.sub('[^a-zA-Z0-9_-]+', '', name) - if char.eveaccount_set.all()[0].user: - out[charname.lower()] = char.eveaccount_set.all()[0].user.email - - -for key in out: - print("%s\t%s" % (key, out[key])) - -#f.close() diff --git a/tools/management/commands/__init__.py b/tools/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/management/commands/edk-apikeys.py b/tools/management/commands/edk-apikeys.py new file mode 100755 index 0000000..fecc0a1 --- /dev/null +++ b/tools/management/commands/edk-apikeys.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python2.5 + +from django.core.management.base import NoArgsCommand +from eve_api.models import EVEPlayerCharacter +from eve_api.app_defines import * + +class Command(NoArgsCommand): + help = "Extracts a list of director's full API keys in CSV format for uploading to EDK" + + def handle_noargs(self, **options): + chars = EVEPlayerCharacter.objects.filter(director=True, eveaccount__api_keytype=API_KEYTYPE_FULL, eveaccount__api_status=API_STATUS_OK) + donekeys = [] + + i = 0 + for c in chars: + i = i + 1 + print "\"TEST\",\"API_CharID_%s\",\"%s\"" % (i, c.id) + print "\"TEST\",\"API_UserID_%s\",\"%s\"" % (i, c.eveaccount_set.all()[0].id) + print "\"TEST\",\"API_Key_%s\",\"%s\"" % (i, c.eveaccount_set.all()[0].api_key) + print "\"TEST\",\"API_Name_%s\",\"%s - %s\"" % (i, c.corporation.name, c.name) + print "\"TEST\",\"API_Type_%s\",\"corp\"" % (i) + print "\"TEST\",\"API_Key_count\",\"%s\"" % i diff --git a/tools/munin.py b/tools/management/commands/munin.py similarity index 80% rename from tools/munin.py rename to tools/management/commands/munin.py index f9ac7ff..1448287 100755 --- a/tools/munin.py +++ b/tools/management/commands/munin.py @@ -17,8 +17,10 @@ import settings setup_environ(settings) import getopt + +from django.db.models import Count from eve_api.app_defines import * -from eve_api.models import EVEAccount +from eve_api.models import EVEAccount, EVEPlayerCorporation from hr.app_defines import * from hr.models import Application @@ -66,9 +68,11 @@ def main(argv=None): print "graph_title Auth - Open Applications" print "graph_vlabel Applications" print "graph_category auth" - print "apps.label Applications" - print "apps.warning 10" - print "apps.critical 20" + + for i, n in EVEPlayerCorporation.objects.filter(applications=True).values_list('id', 'name'): + print "%s.label %s" % (i, n) + print "%s.warning 10" % i + print "%s.critical 20" % i print "graph_args --base 1000" return 0 if execname == 'auth_eveapicache': @@ -85,9 +89,11 @@ def main(argv=None): print "keys.value %s" % key_count elif execname == 'auth_hrapplications': view_status = [APPLICATION_STATUS_AWAITINGREVIEW, - APPLICATION_STATUS_ACCEPTED, APPLICATION_STATUS_QUERY] - apps = Application.objects.filter(status__in=view_status) - print "apps.value %s" % apps.count() + APPLICATION_STATUS_ACCEPTED, APPLICATION_STATUS_QUERY, APPLICATION_STATUS_FLAGGED] + + corps = EVEPlayerCorporation.objects.filter(applications=True, application__status__in=view_status).annotate(num_apps=Count('application')).values_list('id', 'num_apps') + for c,n in corps: + print "%s.value %s" % (c, n) elif execname == 'auth_eveapicache': print "requests.value %s" % CachedDocument.objects.count() diff --git a/tools/pep8.py b/tools/management/commands/pep8.py similarity index 100% rename from tools/pep8.py rename to tools/management/commands/pep8.py diff --git a/tools/management/commands/ts3remove.py b/tools/management/commands/ts3remove.py new file mode 100755 index 0000000..a00ed51 --- /dev/null +++ b/tools/management/commands/ts3remove.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +"""Executes a Django cronjob""" + +import os + +# Activate the virtualenv +path = os.path.dirname(os.path.realpath( __file__ )) +os.chdir(os.path.join(path, '..')) +print os.path.cwd() +activate_this = os.path.realpath(os.path.join(path, '../env/bin/activate_this.py')) +execfile(activate_this, dict(__file__=activate_this)) + +import sys +import logging +from django.core.management import setup_environ +import settings + +setup_environ(settings) + +logging.basicConfig(level=logging.INFO) +log = logging.getLogger('ts3remove') + +from sso.models import Service, ServiceAccount + +srv = Service.objects.get(id=14) +api = srv.api_class + +#def send_command(self, command, keys=None, opts=None) + +duration = 200 +out = {} +offset = 0 +x = False +while not x: + ret = api.conn.send_command('clientdblist', keys={'start': offset, 'duration': 200} ) + for rec in ret: + if type(rec) == type({}): + out[rec['keys']['cldbid']] = rec['keys'] + if len(ret) < 25: x = True + offset = offset + duration + log.info("Got %s" % offset) + +groupcheck = [] +for k in out.keys()[200:]: + ret = api.conn.send_command('custominfo', keys={'cldbid': out[k]['cldbid']}) + + keys = {} + for rec in ret: + if not type(rec) == type(''): + keys[rec['keys']['ident']] = rec['keys']['value'] + + if 'sso_uid' in keys: + log.info("Processing %s" % keys['sso_uid']) + + try: + ServiceAccount.objects.get(service_uid=keys['sso_uid'], service=srv) + except ServiceAccount.DoesNotExist: + log.info("Deleting %s" % keys['sso_uid']) + for client in api.conn.send_command('clientlist'): + if client['keys']['client_database_id'] == k: + print log.info("Kicking from TS3 - %s" % keys['sso_uid']) + api.conn.send_command('clientkick', {'clid': client['keys']['clid'], 'reasonid': 5, 'reasonmsg': 'Auth service deleted'}) + ret = api.conn.send_command('clientdbdelete', {'cldbid': k }) + print ret + except ServiceAccount.MultipleObjectsReturned: + log.info("Deleting multiple service accounts for %s" % keys['sso_uid']) + ServiceAccount.objects.filter(service_uid=keys['sso_uid'], service=srv).delete() + diff --git a/tools/update-directors.py b/tools/management/commands/update-directors.py similarity index 62% rename from tools/update-directors.py rename to tools/management/commands/update-directors.py index 1684ece..1bc6277 100755 --- a/tools/update-directors.py +++ b/tools/management/commands/update-directors.py @@ -1,13 +1,16 @@ #!/usr/bin/env python """Executes a Django cronjob""" -import os +PACS = 29 + +import os, sys # Set niceness os.nice(20) # Activate the virtualenv path = os.path.dirname(os.path.realpath( __file__ )) +os.chdir(path) activate_this = os.path.join(path, 'env/bin/activate_this.py') execfile(activate_this, dict(__file__=activate_this)) @@ -18,17 +21,30 @@ setup_environ(settings) from eve_api.models import EVEPlayerCharacter from django.contrib.auth.models import Group, User +from sso.tasks import update_user_access + g = Group.objects.get(name="Alliance Directors") users = [] for char in EVEPlayerCharacter.objects.filter(corporation__alliance__name="Test Alliance Please Ignore",director=True): - users.append(char.eveaccount_set.all()[0].user) + if char.eveaccount_set.count() and char.eveaccount_set.all()[0].user and not (char.corporation.group and char.corporation.group.id == PACS): + users.append(char.eveaccount_set.all()[0].user) add = set(users) - set(g.user_set.all()) rem = set(g.user_set.all()) - set(users) +print "Add:", add +print "Rem:", rem + + for m in rem: m.groups.remove(g) + update_user_access.delay(m.id) for m in add: m.groups.add(g) + update_user_access.delay(m.id) + +#for u in set(users): +# print "Updating %s" % u +# update_user_access.delay(u.id)