mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Reorganise the file structure into a project tree
This commit is contained in:
0
app/tools/management/commands/__init__.py
Normal file
0
app/tools/management/commands/__init__.py
Normal file
22
app/tools/management/commands/edk-apikeys.py
Executable file
22
app/tools/management/commands/edk-apikeys.py
Executable file
@@ -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
|
||||
45
app/tools/management/commands/extract-emails.py
Executable file
45
app/tools/management/commands/extract-emails.py
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import unicodedata
|
||||
import re
|
||||
from optparse import make_option
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from eve_api.models import EVEPlayerCharacter
|
||||
from eve_api.app_defines import API_STATUS_OK
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = ("Extracts a list of emails for a corp domain")
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('-a', '--alli', action='store', dest='alliance', help='Alliance ID of the extract'),
|
||||
make_option('-c', '--corp', action='store', dest='corporation', help='Corp ID of the extract'),
|
||||
make_option('-d', '--domain', action='store', dest='domain', help='Domain of the extract')
|
||||
)
|
||||
|
||||
requires_model_validation = False
|
||||
|
||||
def handle(self, **options):
|
||||
|
||||
if not options.get('alliance', None) and not options.get('corporation', None):
|
||||
raise CommandError("Please provide either a corporation or alliance")
|
||||
|
||||
if options.get('alliance', None) and options.get('corporation', None):
|
||||
raise CommandError("Use either alliance or corporation, not both")
|
||||
|
||||
if not options.get('domain', None):
|
||||
raise CommandError("You need to specify a domain")
|
||||
|
||||
alliance = options.get('alliance', None)
|
||||
corporation = options.get('corporation', None)
|
||||
domain = options.get('domain', None)
|
||||
|
||||
chars = EVEPlayerCharacter.objects.select_related('eveaccount__user').filter(eveaccount__api_status=API_STATUS_OK, eveaccount__isnull=False)
|
||||
if alliance:
|
||||
chars = chars.filter(corporation__alliance__id=alliance)
|
||||
elif corporation:
|
||||
chars = chars.filter(corporation__id=corporation)
|
||||
|
||||
for char in chars:
|
||||
charname = re.sub('[^a-zA-Z0-9_-]+', '', unicodedata.normalize('NFKD', char.name).encode('ASCII', 'ignore'))
|
||||
if charname and char.eveaccount_set.all()[0].user.email:
|
||||
print "%s@%s\t%s" % (charname.lower(), domain, char.eveaccount_set.all()[0].user.email)
|
||||
102
app/tools/management/commands/munin.py
Executable file
102
app/tools/management/commands/munin.py
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python
|
||||
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)
|
||||
|
||||
import getopt
|
||||
|
||||
from django.db.models import Count
|
||||
from eve_api.app_defines import *
|
||||
from eve_api.models import EVEAccount, EVEPlayerCorporation
|
||||
|
||||
from hr.app_defines import *
|
||||
from hr.models import Application
|
||||
|
||||
from eve_proxy.models import CachedDocument
|
||||
|
||||
accepted_names = ['munin.py', 'auth_apikeys', 'auth_hrapplications',
|
||||
'auth_eveapicache']
|
||||
|
||||
|
||||
class Usage(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
if os.path.basename(argv[0]) in accepted_names:
|
||||
execname = os.path.basename(argv[0])
|
||||
else:
|
||||
print argv[0]
|
||||
print >> sys.stderr, "Invalid symlink name, check the source"
|
||||
return 2
|
||||
try:
|
||||
try:
|
||||
opts, args = getopt.getopt(argv[1:], "", ["config"])
|
||||
except getopt.error, msg:
|
||||
raise Usage(msg)
|
||||
# more code, unchanged
|
||||
except Usage, err:
|
||||
print >> sys.stderr, "Invalid usage"
|
||||
return 2
|
||||
|
||||
for arg in args:
|
||||
if arg == 'config':
|
||||
if execname == 'auth_apikeys':
|
||||
print "graph_title Auth Active EVE API Keys"
|
||||
print "graph_vlabel Keys"
|
||||
print "graph_category auth"
|
||||
print "keys.label Keys"
|
||||
print "graph_args --base 1000"
|
||||
return 0
|
||||
if execname == 'auth_hrapplications':
|
||||
print "graph_title Auth - Open Applications"
|
||||
print "graph_vlabel Applications"
|
||||
print "graph_category auth"
|
||||
|
||||
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':
|
||||
print "graph_title Auth - Cached EVE API Requests"
|
||||
print "graph_vlabel Cached Requests"
|
||||
print "graph_category auth"
|
||||
print "requests.label Cached Requests"
|
||||
print "graph_args --base 1000"
|
||||
return 0
|
||||
|
||||
|
||||
if execname == 'auth_apikeys':
|
||||
key_count = EVEAccount.objects.filter(api_status=API_STATUS_OK).count()
|
||||
print "keys.value %s" % key_count
|
||||
elif execname == 'auth_hrapplications':
|
||||
view_status = [APPLICATION_STATUS_AWAITINGREVIEW,
|
||||
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()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
1160
app/tools/management/commands/pep8.py
Executable file
1160
app/tools/management/commands/pep8.py
Executable file
File diff suppressed because it is too large
Load Diff
68
app/tools/management/commands/ts3remove.py
Executable file
68
app/tools/management/commands/ts3remove.py
Executable file
@@ -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()
|
||||
|
||||
50
app/tools/management/commands/update-directors.py
Executable file
50
app/tools/management/commands/update-directors.py
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
"""Executes a Django cronjob"""
|
||||
|
||||
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))
|
||||
|
||||
from django.core.management import setup_environ
|
||||
import settings
|
||||
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):
|
||||
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)
|
||||
Reference in New Issue
Block a user