diff options
author | gasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414> | 2015-01-20 06:51:53 +0000 |
---|---|---|
committer | gasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414> | 2015-01-20 06:51:53 +0000 |
commit | ccddccc70d213c797cc5bd89fece64ecf196819c (patch) | |
tree | 0d9efd2f234c1bd275a5c10adf2d1a0234f517c7 | |
parent | 9a4a0fc127db7d81aacf297c3e2cfbdb1fbc2817 (diff) |
fixed indent in radius_mysql_pam/task.py
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@214 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
-rwxr-xr-x | kpov_judge/kpov_random_helpers.py | 4 | ||||
-rw-r--r-- | kpov_judge/tasks/custom_rdate/task.py | 3 | ||||
-rw-r--r-- | kpov_judge/tasks/nat_vlc/task.py | 13 | ||||
-rw-r--r-- | kpov_judge/tasks/openvpn_simple_smb/task.py | 24 | ||||
-rw-r--r-- | kpov_judge/tasks/radius_mysql_pam/task.py | 48 | ||||
-rwxr-xr-x | kpov_judge/test_task.py | 25 |
6 files changed, 57 insertions, 60 deletions
diff --git a/kpov_judge/kpov_random_helpers.py b/kpov_judge/kpov_random_helpers.py index 3ce5b11..22dc352 100755 --- a/kpov_judge/kpov_random_helpers.py +++ b/kpov_judge/kpov_random_helpers.py @@ -128,5 +128,5 @@ def default_gen(userID, param_meta): if __name__ == '__main__': r = random.Random() for k, v in default_generators.iteritems(): - print "---", k, "---" - print v(r) + print ("---{}---".format(k)) + print (v(r)) diff --git a/kpov_judge/tasks/custom_rdate/task.py b/kpov_judge/tasks/custom_rdate/task.py index 515792d..1e3ad15 100644 --- a/kpov_judge/tasks/custom_rdate/task.py +++ b/kpov_judge/tasks/custom_rdate/task.py @@ -23,8 +23,7 @@ sestavljen iz crk in stevilk.Tega parametra student ne bo mogel nastavljati sam. S tem parametrom se bo preverjalo ali je prišlo do prepisovanja. -""" - +""", 'en':u""" Setup two virtual machines: -SimpleArbiterDhcpRdate from disk image simpleArbiterRdate and diff --git a/kpov_judge/tasks/nat_vlc/task.py b/kpov_judge/tasks/nat_vlc/task.py index fae3be5..b595961 100644 --- a/kpov_judge/tasks/nat_vlc/task.py +++ b/kpov_judge/tasks/nat_vlc/task.py @@ -12,9 +12,8 @@ instructions = { 'si':u""" Postavi dva navidezna računalnika - SimpleArbiter z diskom simpleArbiter ter NATServer. NATServer naj ima dva omrežna vmesnika - z enim naj bo povezan -na simpleArbiter, z drugim pa na Internet. Na NATServer z ukazom ifconfig in z datoteko /etc/network/interfaces skonfiguriraj omrene -vmesnike tako da bo en vmesnik povezan v WAN (Internet) in en vmesnik na LAN (simpleArbiter). SimpleArbiter skonfiguriraj tako, da -bo za privzeti prehod uporabljal NATServer. Nastavi DNS (etc/resolv.conf). e e ni, omogoi posredovanje IP naslovov. Nastavi NAT +na simpleArbiter, z drugim pa na Internet. Na NATServer z ukazom ifconfig in z datoteko /etc/network/interfaces skonfiguriraj omrežne vmesnike tako da bo en vmesnik povezan v WAN (Internet) in en vmesnik na LAN (simpleArbiter). SimpleArbiter skonfiguriraj tako, da +bo za privzeti prehod uporabljal NATServer. Nastavi DNS (etc/resolv.conf). če še ni, omogoči posredovanje IP naslovov. Nastavi NAT z uporabo paketa iptables. Na simpleArbiter z vlc preberi naslov, na katerem si lahko ogledaš kratek filmček. """, 'en':u""" @@ -76,7 +75,7 @@ params_meta = { # 'IP_NM': {'descriptions': {'si': 'Naslov maliNetworkManager'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True}, # 'DNS_NM': {'descriptions': {'si': 'DNS za maliNetworkManager'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True}, 'IP_simple': {'descriptions': {'si': 'Naslov SimpleArbiter'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, - 'IP_NAT': {'descriptions': {'si': 'Naslov NAT'} 'w': False, 'public': True, 'type': 'IP', 'generated': True }, + 'IP_NAT': {'descriptions': {'si': 'Naslov NAT'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True }, # 'DNS_static': {'descriptions': {'si': 'DNS za maliBrezNetworkManager'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, } @@ -107,11 +106,11 @@ def gen_params(user_id, params_meta): r = random.Random(user_id) # IP_NM, DNS_NM, IP_static, DNS_static) # dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220'] - net = kpov_random_helpers.IPv4_net_gen(r, 254, true, false) + net = kpov_random_helpers.IPv4_net_gen(r, 253, True, False) # params['DNS_NM'] = r.choice(dns_servers) - params['IP_NAT'] = net + params['IP_NAT'], params['IP_simple'] = kpov_random_helpers.IPv4_addr_gen(r, net, 2) # params['IP_NM'] - params['IP_simple'] = kpov_random_helpers.IPv4_addr_gen(r, net, 1) + # params['IP_simple'] = kpov_random_helpers.IPv4_addr_gen(r, net, 1) # params['DNS_static'] = r.choice(dns_servers) return params diff --git a/kpov_judge/tasks/openvpn_simple_smb/task.py b/kpov_judge/tasks/openvpn_simple_smb/task.py index e1bb9b0..efec2e3 100644 --- a/kpov_judge/tasks/openvpn_simple_smb/task.py +++ b/kpov_judge/tasks/openvpn_simple_smb/task.py @@ -10,17 +10,16 @@ VPNClient1 in VPNClient2, ki jima nastavite pravilne mrežne nastavitve (medsebo Na vse racunalnike namestite OpenVPN in program za nadzor nad virtualnimi napravami (s katerim kreirate napravo tap). Strežnik SimpleArbiterVPN naj generira skupno skrivnost (*.key), katero shranite v imenik /vpn in jo na VPNCLient uporabite skupaj z konfiguracijsko datoteko za OpenVPN povezavo. Nato poskrbite, da bo VPNClient na navideznem omrežju prek NFS omogočil -dostop do imenika /home/test/IME_IMENIKA, pri čemer IME_IMENIKA preberite na SimpleArbiter. +dostop do imenika /home/test/DIRNAME, pri čemer DIRNAME preberite na SimpleArbiter. V ta imenik skopirajte datoteke, ki so prek SMB dostopne na SimpleArbiter. -""" - +""", 'en':u""" Setup three virtual machines - SimpleArbiterVPN and two VPN clients (VPNClient1, VPNClient2). Set both clients network cards so that they will have access to internal network and internet. Install OpenVPN to all three machines and a program for supervising virtual devices (which you will use to create device tap). Server SimpleArbiterVPN should generate a common secret (*.key), which you should save to /vpn directory and use on VPNClient together with configuration file for OpenVPN connection. After that make sure that -VPNClient has enabled access to /home/test/IME_IMENIKA over NFS on it's virtual connection. You will get +VPNClient has enabled access to /home/test/DIRNAME over NFS on it's virtual connection. You will get IME_IMENIKA from SimpleArbiter. Copy files that should be available from AimpleArbiter over SMB to IME_IMENIKA. """ } @@ -63,7 +62,7 @@ computers = { { 'network': 'net1' } - }, + ], 'flavor': 'm1.tiny', 'config_drive': False @@ -81,7 +80,7 @@ computers = { { 'network': 'net1' } - }, + ], 'flavor': 'm1.tiny', 'config_drive': False @@ -99,11 +98,14 @@ networks = { } #Tukaj sem generiral tri parametre, prosil bi če se upoštevajo pri Tasku. params_meta = { - 'IME_IMENIKA': {}, 'IME_KLJUCA':{}, 'HASH': {} + 'IP_SimpleArbiterVPN': {'descriptions':{'si':'IP za SimpleArbiter'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, + 'IP_VPNClient1': {'descriptions':{'si':'IP za 1. klienta'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, + 'IP_VPNClient2': {'descriptions':{'si':'IP za 2. klienta'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, + 'DIRNAME': {'descriptions':{'si':'Imenik, dostopen prek NFS'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, } -def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient1, IP_VPNClient2, DNS_VPNClient2): +def task(IP_SimpleArbiterVPN, IP_VPNClient1, IP_VPNClient2, DIRNAME): import pxssh # Used to set up an SSH connection to a remote machine #import pexpect # Allows the script to spawn a child application and control it as if a human were typing commands @@ -227,7 +229,7 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient ###### # Ping the VPN server - sC1.sendLine('ping -c 3 {0}'.format( DNS_SimpleArbiterVPN )) + sC1.sendLine('ping -c 3 {0}'.format( IP_SimpleArbiterVPN )) sC1.prompt() output = sC1.before results['VPNClient1_ping_VPN_server'] = output @@ -238,7 +240,7 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient ###### # Ping the VPN server - sC2.sendLine('ping -c 3 {0}'.format( DNS_SimpleArbiterVPN )) + sC2.sendLine('ping -c 3 {0}'.format( IP_SimpleArbiterVPN )) sC2.prompt() output = sC2.before results['VPNClient2_ping_VPN_server'] = output @@ -263,7 +265,7 @@ def gen_params(user_id, params_meta): alpha=["1","2","3","4","5","6","7","8","9","0"] rnd = random.Random(alpha) for x in id: - hash+=chr(int(x)+80)+rnd + hash+=chr(int(x)+80)+rnd params['HASH']=hash return params diff --git a/kpov_judge/tasks/radius_mysql_pam/task.py b/kpov_judge/tasks/radius_mysql_pam/task.py index 70b1180..2e330cf 100644 --- a/kpov_judge/tasks/radius_mysql_pam/task.py +++ b/kpov_judge/tasks/radius_mysql_pam/task.py @@ -58,15 +58,15 @@ computers = { networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
params_meta = {
- 'IP_RS': {'descriptions': {'si': 'Naslov RadiusServer'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_RS': {'descriptions': {'si': 'Naslov RadiusServer'}, 'w': False, 'public':True, 'type': 'IP', 'generated': True},
'RADIUS_SECRET':{'descriptions': {'si': 'Skrivnost RADIUS'}, 'w': False, 'public':True, 'type': 'passwd', 'generated': True},
'RADIUS_USERNAME': {'descriptions': {'si': 'Username v RADIUS'}, 'w': True, 'public':True, 'type': 'username', 'generated': False},
'RADIUS_PASSWORD': {'descriptions': {'si': 'Geslo v RADIUS'}, 'w': False, 'public':True, 'type': '', 'generated': True},
- 'MYSQL_DB_NAME': {'descriptions': {'si': 'Ime baze v mysql'}, 'w': True, 'public':True, 'type': '', 'generated': False},
+ 'MYSQL_DB_NAME': {'descriptions': {'si': 'Ime baze v mysql'}, 'w': True, 'public':True, 'type': '', 'generated': False},
'MYSQL_ADMIN_USER':{'descriptions': {'si': 'Username za dostop do MySQL'}, 'w': True, 'public':True, 'type': 'username', 'generated': False},
'MYSQL_ADMIN_PASSWORD': {'descriptions': {'si': 'Geslo za dostop do MySQL'}, 'w': True, 'public':True, 'type': 'passwd', 'generated': True},
- 'MYSQL_TEST_USER':{'descriptions': {'si': 'Username za testiranje PA;M'}, 'w': False, 'public':False, 'type': 'username', 'generated': True},
- 'MYSQL_TEST_PASSWORD': {'descriptions': {'si': 'Geslo za testiranje PAM'}, 'w': False, 'public':False, 'type': 'passwd', 'generated': True},
+ 'MYSQL_TEST_USER':{'descriptions': {'si': 'Username za testiranje PA;M'}, 'w': False, 'public':False, 'type': 'username', 'generated': True},
+ 'MYSQL_TEST_PASSWORD': {'descriptions': {'si': 'Geslo za testiranje PAM'}, 'w': False, 'public':False, 'type': 'passwd', 'generated': True},
'MYSQL_PAM_USERNAME': {'descriptions': {'si': 'Username v MySQL'}, 'w': True, 'public': True, 'type': 'IP', 'generated': False},
'MYSQL_PAM_PASSWORD': {'descriptions': {'si': 'Geslo za uporabnika v MySQL'}, 'w': True, 'public': True, 'type': 'passwd', 'generated': False},
}
@@ -79,39 +79,33 @@ def task(IP_RS, RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, MYSQL_ADMIN_USE sR = pxssh.pxssh()
sR.login(IP_RS, peer_user, peer_passwd)
-
- # Testiranje radius strtežnika
+
+ # Testiranje radius strtežnika
results['Test_RadiusServer'] = sR.run('radtest {0} {1} {3} 1812 {4}'.format(
RADIUS_USERNAME, RADIUS_USERNAME,
RADIUS_PASSWORD, IP_RS, RADIUS_SECRET))
- # Testiranje podatkovne base mysql
- results['mysql_login'] = sR.run('mysql -u {MYSQL_ADMIN_USER} -p {MYSQL_ADMIN_PASSWORD}'.format(**locals()))
- results['database_connect'] = sR.run('USE {MYSQL_DB_NAME}'.format(**locals()))
- results['select_from_users'] = sR.run('SELECT username, password FROM users;')
- sR.run('INSERT INTO users (username, password) VALUES ({MYSQL_TEST_USER}, {MYSQL_TEST_PASSWORD});')
- sR.run('\q');
- # Testiranje PAM s testnim uporabnikom
- sT.login(IP_RS, MYSQL_TEST_USER, MYSQL_TEST_PASSWORD)
-
+ # Testiranje podatkovne base mysql
+ results['mysql_login'] = sR.run('mysql -u {MYSQL_ADMIN_USER} -p {MYSQL_ADMIN_PASSWORD}'.format(**locals()))
+ results['database_connect'] = sR.run('USE {MYSQL_DB_NAME}'.format(**locals()))
+ results['select_from_users'] = sR.run('SELECT username, password FROM users;')
+ sR.run('INSERT INTO users (username, password) VALUES ({MYSQL_TEST_USER}, {MYSQL_TEST_PASSWORD});')
+ sR.run('\q');
+ # Testiranje PAM s testnim uporabnikom
+ sT.login(IP_RS, MYSQL_TEST_USER, MYSQL_TEST_PASSWORD)
+
return results
def gen_params(user_id, params_meta):
params = dict()
r = random.Random(user_id)
- secrets = ['skupna', 'secret', 'skrivnost', 'mystery', 'tajna', 'skupnaskrivnost', 'nekadruga', 'spetnekaskrivnost']
- crke = list(string.ascii_lowercase)
for name, meta in param_meta.iteritems():
params[name] = default_generators[meta.get('type', None)](r)
- params['RADIUS_SECRET'] = r.choice(secrets)
- password = SQLpassword = ""
- for i in range(4):
- passowrd+=crke[randint(0,25)]
- SQLpassword+=crke[randint(0,25)]
- params['RADIUS_PASSWORD'] = password
- params['MYSQL_ADMIN_PASSWORD'] = SQLpassword
-
- ip_radius_server = ['10.0.2.7', '192.168.11.21', '192.168.0.47', '10.0.16.134', '10.0.16.17', '172.19.7.16']
- params['IP_RS'] = r.choice(ip_radius_server);
+ params['RADIUS_SECRET'] = alnum_gen(r, 8)
+ params['RADIUS_PASSWORD'] = alnum_gen(r, 4)
+ params['MYSQL_ADMIN_PASSWORD'] = alnum_gen(r, 4)
+ net = IPv4_subnet_gen(r)
+ ip_radius_server = IPv4_addr_gen(r, net, 1)[0]
+ params['IP_RS'] = ip_radius_server
return params
def task_check(results, params):
diff --git a/kpov_judge/test_task.py b/kpov_judge/test_task.py index 4658304..79521d4 100755 --- a/kpov_judge/test_task.py +++ b/kpov_judge/test_task.py @@ -5,7 +5,10 @@ import yaml import json import urllib import urllib2 -from dialog import Dialog +try: + from dialog import Dialog +except: + Dialog = None import os import inspect import sys @@ -61,7 +64,7 @@ def add_meta_to_argparser(argparser, meta, defaults = {}): desc = v['descriptions'][language].encode("utf-8") except: desc = k - print desc, type(desc) + print("{} {}".format(desc, type(desc))) argparser.add_argument('--'+k, nargs=1, help=desc, type=unicode, default=defaults.get(k, None)) return argparser @@ -141,7 +144,7 @@ if __name__ == '__main__': help='the language used', default=params.get('language', DEFAULT_LANGUAGE)) basic_args = basic_argparser.parse_args() params['language'] = basic_args.language - if not basic_args.quiet: + if not basic_args.quiet and Dialog is not None: dialog = Dialog(dialog="dialog") else: dialog = None @@ -157,8 +160,8 @@ if __name__ == '__main__': req = urllib2.Request("{task_url}/{task_name}/task.py".format(**params)) source = urllib2.urlopen(req) task, task_check, task_params_meta, gen_params = load_task(source) - except Exception, e: - print e + except Exception as e: + print(e) if basic_args.help: argparser.print_help() else: @@ -172,9 +175,9 @@ if __name__ == '__main__': task_params = params['task_params'][params['task_name']] if basic_args.generate_params: #prejema lahko samo stringe in ne številk (potrebno je str(int) - print "params before", params, task_params + print ("params before: {} {}".format(params, task_params)) task_params.update(gen_params(params['username'], task_params_meta)) - print "params after", params, task_params + print ("params after: {} {}".format(params, task_params)) if task_url.startswith('http'): req = urllib2.Request("{task_url}/{task_name}/params.json".format(**params)) web_task_params = json.load(urllib2.urlopen(req)) @@ -186,11 +189,11 @@ if __name__ == '__main__': if k in args and args[k] is not None: task_params[k] = args[k] if dialog is not None: - print task_params + print(task_params) task_params = get_params_dialog(task_params, task_params_meta, dialog=dialog, language = params['language']) if basic_args.help: # params_argparser.print_help() - print params_argparser.format_help() + print(params_argparser.format_help()) exit(0) # run task.task() public_params = dict() @@ -200,12 +203,12 @@ if __name__ == '__main__': try: task_result = task(**public_params) # run task.task_check() - except Exception, e: + except Exception as e: print("Error running task(...):") print(e) try: result = task_check(task_result, task_params) - except Exception, e: + except Exception as e: print("Error running task_check(results, params):") print(e) # print results |