diff options
Diffstat (limited to 'kpov_judge/tasks/radius_mysql_pam')
-rw-r--r-- | kpov_judge/tasks/radius_mysql_pam/task.py | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/kpov_judge/tasks/radius_mysql_pam/task.py b/kpov_judge/tasks/radius_mysql_pam/task.py index 1a11ef8..be99e6a 100644 --- a/kpov_judge/tasks/radius_mysql_pam/task.py +++ b/kpov_judge/tasks/radius_mysql_pam/task.py @@ -58,10 +58,6 @@ computers = { 'disks': [ { 'name': 'student-RadiusServer', }, - #{ 'name': 'CDROM', - # 'options':{'readonly': True}, - # 'parts': [],# no parts, no mounting. - #} ], 'network_interfaces': [{'network': 'net1'}], 'flavor': 'm1.tiny', @@ -71,12 +67,7 @@ computers = { 'SimpleArbiter': { 'disks': [ { 'name': 'simpleArbiterDhcpGW', - # attempt automount }, - #{ 'name': 'CDROM', - # 'options': {'readonly': True}, - # 'parts': [{'dev': 'b1', 'path': '/cdrom'}], - #}, ], 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}], 'flavor': 'm1.tiny', @@ -97,20 +88,23 @@ params_meta = { 'MYSQL_SEED':{'descriptions': {'si': 'seed', 'en': 'seed'}, 'w': False, 'public':True, 'type': None, 'generated': True}, } -def task(IP_RS, RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, MYSQL_DB_NAME, MYSQL_ADMIN_USER, MYSQL_ADMIN_PASSWORD, MYSQL_SEED): - from pexpect import pxssh - import pexpect +def task(IP_RS, RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, + MYSQL_DB_NAME, MYSQL_ADMIN_USER, MYSQL_ADMIN_PASSWORD, MYSQL_SEED): + import collections import random - results = dict() - peer_user = 'student' - peer_passwd = 'vaje' + import pexpect + r = random.Random(MYSQL_SEED) MYSQL_TEST_USER = kpov_util.username_gen(r) MYSQL_TEST_PASSWORD = kpov_util.alnum_gen(r, 7) RADIUS_NEW_PASSWORD = kpov_util.alnum_gen(r, 7) - # Testiranje radius strtežnika + + results = collections.defaultdict(str) + + # Testiranje radius strežnika results['Test_RadiusServer'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format( RADIUS_USERNAME, RADIUS_PASSWORD, IP_RS, RADIUS_SECRET)) + # Testiranje podatkovne base mysql mysql = pexpect.spawn('mysql -u {MYSQL_ADMIN_USER} -p{MYSQL_ADMIN_PASSWORD} -h {IP_RS}'.format(**locals())) mysql.expect("mysql>") @@ -123,22 +117,25 @@ def task(IP_RS, RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, MYSQL_DB_NAME, results['select_from_users'] = mysql.before mysql.sendline("INSERT INTO radcheck (UserName, Attribute, Value, Op) VALUES ('{MYSQL_TEST_USER}', 'Cleartext-Password', '{MYSQL_TEST_PASSWORD}', ':=');".format(**locals())) mysql.expect("mysql>") + results['radtest_OK'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format( MYSQL_TEST_USER, MYSQL_TEST_PASSWORD, IP_RS, RADIUS_SECRET)) results['radtest_NOK'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format( MYSQL_TEST_USER, "Flügzeug", IP_RS, RADIUS_SECRET)) results['radtest_NOK'] = pexpect.run('radtest {0} {1} {2} 1812 {3}'.format( MYSQL_TEST_USER, "Flügzeug", IP_RS, RADIUS_SECRET)) - sT = pxssh.pxssh() + mysql.sendline("UPDATE radcheck SET value='{RADIUS_NEW_PASSWORD}' where UserName='{RADIUS_USERNAME}' and Attribute='Cleartext-Password';".format(**locals())) - sT.login(IP_RS, RADIUS_USERNAME, RADIUS_NEW_PASSWORD) - results['login_test'] = sT.before + + results.update(kpov_util.ssh_test(IP_RS, RADIUS_USERNAME, RADIUS_NEW_PASSWORD)) + mysql.sendline("UPDATE radcheck SET value='{RADIUS_PASSWORD}' where UserName='{RADIUS_USERNAME}' and Attribute='Cleartext-Password';".format(**locals())) mysql.expect('mysql>') mysql.sendline("DELETE FROM radcheck where UserName='{MYSQL_TEST_USER}' and Attribute='Cleartext-Password';".format(**locals())) mysql.expect('mysql>') mysql.sendline('\q'); - # Testiranje PAM s testnim uporabnikom + # TODO Testiranje PAM s testnim uporabnikom + return results def gen_params(user_id, params_meta): @@ -209,8 +206,8 @@ def task_check(results, params): else: hints.append('radtest negative output incorrect: ' + results['radtest_NOK']) print((results['radtest_NOK'], s)) - s = "{RADIUS_USERNAME}@.*:~\\$".format(**params) - if re.search(s, results['login_test'], flags=re.DOTALL): + s = "{RADIUS_USERNAME}@.*:".format(**params) + if re.search(s, results['motd'], flags=re.DOTALL): # print "login_test OK" score += 1 else: @@ -220,4 +217,3 @@ def task_check(results, params): def prepare_disks(templates, task_params, global_params): write_default_config(templates['simpleArbiterDhcpGW'], global_params) - |