diff options
author | gasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414> | 2015-02-15 12:17:16 +0000 |
---|---|---|
committer | gasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414> | 2015-02-15 12:17:16 +0000 |
commit | 7527183f963f3da5a6db8462fa38700aa374981b (patch) | |
tree | 35ed68800526d6add0d3d5332ca92a343cd7f4c1 /kpov_judge | |
parent | 8bad4c041b3fa583444bce5b39ae09f74251e4aa (diff) |
Task custom_rdate done (task, task_check)
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@275 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge')
-rw-r--r-- | kpov_judge/tasks/custom_rdate/task.py | 164 |
1 files changed, 85 insertions, 79 deletions
diff --git a/kpov_judge/tasks/custom_rdate/task.py b/kpov_judge/tasks/custom_rdate/task.py index fd5d070..c619122 100644 --- a/kpov_judge/tasks/custom_rdate/task.py +++ b/kpov_judge/tasks/custom_rdate/task.py @@ -6,38 +6,22 @@ instructions = { 'si':u""" -Postavi dva navidezna racunalnika: +Postavite dva navidezna racunalnika: - SimpleArbiterDhcpRdate s slike diska simpleArbiterRdate ter --rdateClient. +- rdateClient. Na rdateClient ustvarite uporabnika test z geslom test. Nastavite cas na rdateClient tako, da kot rdate strežnik uporabite SimpleArbiterDhcpRdate. -Nato v domacem imeniku uporabnika test spravite program z imenom guliver, -ki prebere 4 byte podatkov s standardnega vhoda in jih pretvori v -predznaceno celo število, pri cemer naj uporablja zapis z debelim koncem +Nato v domacem imeniku uporabnika test ustvarite program z imenom +PROGRAM_FILENAME. Vrednost PROGRAM_FILENAME preberete na SimpleArbiterDhcpRdate.Program naj prebere 4 byte podatkov s standardnega vhoda in jih pretvori v +predznaceno celo število, pri čemer naj uporablja zapis z debelim koncem (big endian). -Število naj program izpiše na standardni izhod. - -V param_meta dodajte parameter, katerega vrednost bo nakljucen string -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. - +Število naj program izpiše na standardni izhod v obliki niza. """, 'en':u""" Setup two virtual machines: --SimpleArbiterDhcpRdate from disk image simpleArbiterRdate and --rdateClient. - -On rdateClient create a user "test" with password "test". Set time on rdateClient -so that it will use SimpleArbiterDhcpRdate as it's rdate server. After that create -a program named guliver in the root directory of user "test". This program has to -read 4bytes from standard input and convert them to signed number using big endian rule. -Write this number to standard output. - -Generate a random string from both letters and numbers and add it as a parameter -to param_meta. This parameter will not be accessible to students and will be used -to check if student copied his work from someone else. +- SimpleArbiterDhcpRdate from disk image simpleArbiterRdate and +- rdateClient. """ } @@ -45,7 +29,7 @@ to check if student copied his work from someone else. computers = { 'rdateClient': { 'disks': [ - { 'name': 'maliBrezNetworkManager', + { 'name': 'rdateClient', }, #{ 'name': 'CDROM', # 'options':{'readonly': True}, @@ -77,31 +61,40 @@ networks = { 'net1': {'public': False}, 'test-net': {'public': True} } # Tu sem dolocil parametre params_meta = { - 'Ime':{}, - 'Datum':{}, - 'Sifra':{}, + 'RDATE_OFFSET':{'descriptions': {'si': 'Napaka v času pri rdate'}, 'w': False, 'public': False, 'type': 'integer', 'generated': True}, + 'PROGRAM_FILENAME':{'descriptions': {'si': 'Ime programa'}, 'w': False, 'public': True, 'type': 'integer', 'generated': True}, + 'IP_RDATECLIENT':{'descriptions': {'si': 'IP rdateClient'}, 'w': True, 'public': False, 'type': 'IP', 'generated': False}, } -def task(IP_NM, DNS_NM, IP_static, DNS_static): - import pxssh +def task(IP_RDATECLIENT, PROGRAM_FILENAME): import pexpect + import paramiko + from paramiko import SSHClient + import random + import struct 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() + peer_user = 'test' + peer_passwd = 'test' + client = SSHClient() + client.load_system_host_keys() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + client.connect(IP_RDATECLIENT, username=peer_user, password=peer_passwd) + #client.login(IP_RDATECLIENT, peer_user, peer_passwd) + r = random.Random(PROGRAM_FILENAME) + for i in xrange(10): + stdin, stdout, stderr = client.exec_command( + '~/{}'.format(PROGRAM_FILENAME)) + data = struct.pack("!I", r.randint(0, 2**32)) + stdin.write(data) + results['in_' + str(i)] = data + results['out_' + str(i)] = stdout.read() + stdin, stdout, stderr = client.exec_command( + 'date -u +"%s"') + #client.sendline('date -u "%s"') + #client.prompt() + results['date'] = stdout.read() + results['ldate'] = pexpect.run('date -u +"%s"') + client.close() return results @@ -112,45 +105,58 @@ def gen_params(user_id, params_meta): import socket import struct import datetime - params = dict() r = random.Random(user_id) - params['Ime'] = "guliver" - - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect(("ntp1.arnes.si",37)) - - podatek = s.recv(4) - stevilka = struct.unpack("!I",podatek) - stevilka = stevilka[0] - t = datetime.date(year=1850,month=1,day=1) - t = t + datetime.timedelta(seconds=stevilka) - params['Datum'] = t - - rez = "" - crke = "ABCDEFGHIJKLMNOPRSTUVZXYQ" - c = random.Random(crke) - for x in user_id: - rez += x + c.choice() - - params['Sifra'] = rez + params['PROGRAM_FILENAME'] = kpov_random_helpers.fname_gen(r, False) + params['RDATE_OFFSET'] = str(r.randint(-2**24, 2**24)) return params def task_check(results, params): - import re - score = 0 - 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: - score += 3 - if re.search(r'eth0 +802-.*connected', results['NM_nmcli']): - score += 2 - if not re.search(r'eth0 +802-.*connected', results['static_nmcli']): - score += 2 - #score = 0 + import random + import struct + # print results + r = random.Random(params['PROGRAM_FILENAME']) + score = 0.0 + for i in xrange(10): + data = results['in_' + str(i)] + if data != struct.pack("!I", r.randint(0, 2**32)): + break + res = results['out_' + str(i)] + if str(struct.unpack("!I", data)[0]) == res.strip(): + score += 0.5 + else: + pass + # print str(struct.unpack("!I", data)[0]), res.strip() + if abs(int(results['ldate']) + \ + int(params['RDATE_OFFSET']) - int(results['date'])) < 3: + score += 5 return score def prepare_disks(templates, params): # d = templates['simpleArbiterDhcp'] - pass - +# print templates +# print params + d = templates['simpleArbiterDhcpRdate'] + s1 = """service "time_tcp" {{ + enabled yes; + protocol tcp; + port "time"; + user "nobody"; + exec "/usr/local/bin/kpovrdate {RDATE_OFFSET}"; + server "/usr/sbin/tcpd"; + wait no; +}} +""".format(**params) + d.write('/etc/rlinetd.d/time', s1) + s2 = """#!/usr/bin/python + +import struct +import time +import sys + +offset = int(sys.argv[1]) +t = time.time() + 2208988800 + offset +sys.stdout.write(struct.pack("!I", int(t))) +""" + d.write('/usr/local/bin/kpovrdate', s2) + d.chmod('0775', '/usr/local/bin/kpovrdate') |