summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/radius_mysql_pam
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge/tasks/radius_mysql_pam')
-rw-r--r--kpov_judge/tasks/radius_mysql_pam/task.py70
1 files changed, 32 insertions, 38 deletions
diff --git a/kpov_judge/tasks/radius_mysql_pam/task.py b/kpov_judge/tasks/radius_mysql_pam/task.py
index a3f86f7..72b5a74 100644
--- a/kpov_judge/tasks/radius_mysql_pam/task.py
+++ b/kpov_judge/tasks/radius_mysql_pam/task.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# kpov_random_helpers should be imported by add_assignment.py
+# kpov_util should be imported by add_assignment.py
instructions = {
'si':"""
@@ -58,10 +56,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 +65,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 +86,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_random_helpers.username_gen(r)
- MYSQL_TEST_PASSWORD = kpov_random_helpers.alnum_gen(r, 7)
- RADIUS_NEW_PASSWORD = kpov_random_helpers.alnum_gen(r, 7)
- # Testiranje radius strtežnika
+ 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)
+
+ 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,33 +115,36 @@ 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):
params = dict()
r = random.Random(user_id)
- params['RADIUS_SECRET'] = kpov_random_helpers.alnum_gen(r, 8)
- params['RADIUS_PASSWORD'] = kpov_random_helpers.alnum_gen(r, 8)
- params['RADIUS_USERNAME'] = kpov_random_helpers.username_gen(r)
- params['MYSQL_ADMIN_USER'] = kpov_random_helpers.alnum_gen(r, 6)
- params['MYSQL_ADMIN_PASSWORD'] = kpov_random_helpers.alnum_gen(r, 6)
- params['MYSQL_DB_NAME'] = kpov_random_helpers.alnum_gen(r, 4)
+ params['RADIUS_SECRET'] = kpov_util.alnum_gen(r, 8)
+ params['RADIUS_PASSWORD'] = kpov_util.alnum_gen(r, 8)
+ params['RADIUS_USERNAME'] = kpov_util.username_gen(r)
+ params['MYSQL_ADMIN_USER'] = kpov_util.alnum_gen(r, 6)
+ params['MYSQL_ADMIN_PASSWORD'] = kpov_util.alnum_gen(r, 6)
+ params['MYSQL_DB_NAME'] = kpov_util.alnum_gen(r, 4)
params['MYSQL_SEED'] = str(r.random())
return params
@@ -159,9 +154,9 @@ def task_check(results, params):
score = 0
hints = []
r = random.Random(params['MYSQL_SEED'])
- MYSQL_TEST_USER = kpov_random_helpers.username_gen(r)
- MYSQL_TEST_PASSWORD = kpov_random_helpers.alnum_gen(r, 7)
- RADIUS_NEW_PASSWORD = kpov_random_helpers.alnum_gen(r, 7)
+ 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)
s = r"Sent Access-Request Id [0-9]+ from ([0-9]|\.)+:[0-9]+ to {IP_RS}:1812 length [0-9]+\r\n\tUser-Name = \"{RADIUS_USERNAME}\"\r\n\tUser-Password = \"{RADIUS_PASSWORD}\".*Access-Accept Id [0-9]+ from {IP_RS}".format(**params)
#with open('test.pickle', 'w') as f:
# pickle.dump({'pattern': s, 'res': results['Test_RadiusServer']}, f)
@@ -209,8 +204,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 +215,3 @@ def task_check(results, params):
def prepare_disks(templates, task_params, global_params):
write_default_config(templates['simpleArbiterDhcpGW'], global_params)
-