From a2f791bde9aef13909bbf74b5d4acf8f12b1fd78 Mon Sep 17 00:00:00 2001 From: "mp7462@student.uni-lj.si" Date: Fri, 12 Dec 2014 16:05:17 +0000 Subject: Code changes for better readability git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@49 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/tasks/openvpn_simple_smb/task.py | 107 ++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 15 deletions(-) (limited to 'kpov_judge/tasks') diff --git a/kpov_judge/tasks/openvpn_simple_smb/task.py b/kpov_judge/tasks/openvpn_simple_smb/task.py index 0a671c0..4783486 100644 --- a/kpov_judge/tasks/openvpn_simple_smb/task.py +++ b/kpov_judge/tasks/openvpn_simple_smb/task.py @@ -6,7 +6,10 @@ instructions = { 'si':u""" Postavi dva navidezna računalnika - SimpleArbiter z diska SimpleArbiterVPN ter -VPNClient, ki jima nastavite pravilne mrežne nastavitve (medsebojna povezava in povezava na splet). Na oba računalnika namestite OpenVPN in program za nadzor nad virtualnimi napravami (s katerim kreirate napravo tap).Strežnik SimpleArbiterVPN naj generira skupno skrivnost (*.key), ki jo na VPNCLient uporabite skupaj z konfiguracijsko datoteko za OpenVPN povezavo. Nato poskrbite, da bo VPNClient na navideznem omrežju prek NFS omogočil +VPNClient, ki jima nastavite pravilne mrežne nastavitve (medsebojna povezava in povezava na splet). +Na oba računalnika namestite OpenVPN in program za nadzor nad virtualnimi napravami (s katerim kreirate napravo tap). +Strežnik SimpleArbiterVPN naj generira skupno skrivnost (*.key), ki 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. V ta imenik skopirajte datoteke, ki so prek SMB dostopne na SimpleArbiter. """ @@ -57,65 +60,133 @@ computers = { } } -networks = { 'net1': {'public': False}, 'test-net': {'public': True} } +networks = { + 'net1': { + 'public': False + }, + 'test-net': { + 'public': True + } +} 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_static': {'descriptions': {'si': 'Naslov maliBrezNetworkManager'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, - 'DNS_static': {'descriptions': {'si': 'DNS za maliBrezNetworkManager'}, 'w': False, 'public': True, 'type': 'IP', 'generated': True}, + '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_static': { + 'descriptions': { + 'si': 'Naslov maliBrezNetworkManager' + }, + 'w': False, + 'public': True, + 'type': 'IP', + 'generated': True + }, + 'DNS_static': { + 'descriptions': { + 'si': 'DNS za maliBrezNetworkManager' + }, + 'w': False, + 'public': True, + 'type': 'IP', + 'generated': True + }, } + def task(IP_NM, DNS_NM, IP_static, DNS_static): + import pxssh import pexpect + + results = dict() + peer_user = 'student' peer_passwd = 'vaje' + sA = pxssh.pxssh() sB = pxssh.pxssh() + sA.login(IP_NM, peer_user, peer_passwd) sB.login(IP_static, peer_user, peer_passwd) + # sA # make sure NM is not handling eth0 results['NM_nmcli'] = sA.run('nmcli d') results['NM_nslookup'] = sA.run('nslookup www.arnes.si') + # sB # check whether NM is handling eth0 results['static_nmcli'] = sB.run('nmcli d') results['static_nslookup'] = sB.run('nslookup www.arnes.si') + sA.logout() sB.logout() - return results + return results + + def gen_params(user_id, params_meta): + alpha = "abcdefghijklmnoprstuvzxyqw" alphaupp = "ABCDEFGHIJKLMNOPRSTUVZQWXY" alpha2 = ['$','?','!',"%","&"] alpha3 = ['IT','DH','JF','PO','LZ'] + + temp = datetime.datetime.now().strftime("%Y%m%d%H%M%S") hash = "" + for x in temp: - for i in x: - if int(i)<5: - hash+=random.choice(alpha)+alpha2[int(i)] - else: - hash+=random.choice(alphaupp)+alpha3[int(i)-5] - hash+=":"+temp + for i in x: + if int(i)<5: + hash+=random.choice(alpha)+alpha2[int(i)] + else: + hash+=random.choice(alphaupp)+alpha3[int(i)-5] + hash+=":"+temp + + params = dict() + 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_subnet_gen(r, '172.23.128.0/18', 24) + params['DNS_NM'] = r.choice(dns_servers) params['IP_NM'], params['IP_static'] = kpov_random_helpers.IPv4_addr_gen(r, net, 2) params['DNS_static'] = r.choice(dns_servers) - params[user_id]=hash + + params[user_id] = hash + + return params + def task_check(results, params): + import re + score = -9 + if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1: score += 3 if results['static_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_static'])) > -1: @@ -124,11 +195,17 @@ def task_check(results, params): score += 2 if not re.search(r'eth0 +802-.*connected', results['static_nmcli']): score += 2 + score = 0 + return score + def prepare_disks(templates, params): + d = templates['simpleArbiterDhcp'] + guestmount -a d -m /dev/VG/LV -m /dev/sda1:/boot --ro /mnt - pass + + pass -- cgit v1.2.1