From b1b0d75831b3d81c41549358dde122b9fba0c054 Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Thu, 23 Mar 2017 07:40:07 +0000 Subject: the edit_find_grep_compile_convert task now works git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@407 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- .../tasks/edit_find_grep_compile_convert/task.py | 99 +++++++++++++++------- kpov_judge/tasks/ldap_search/task.py | 51 +++++------ .../tasks/mock_entrance_exam/howtos/en/index.html | 0 kpov_judge/tasks/vlc_stream_rtp/task.py | 19 +++-- 4 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 kpov_judge/tasks/mock_entrance_exam/howtos/en/index.html (limited to 'kpov_judge/tasks') diff --git a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py index 60353fd..705ddf6 100644 --- a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py +++ b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py @@ -28,8 +28,9 @@ Brati naj jo ima pravico samo lastnik, pisati lastnik in skupina, poganjati nih V {dstfile} zamenjaj vse vrstice oblike poXYZlz, kjer so XYZ poljubni znaki, tako, da bo namesto XYZ niz "kaka". Napiši program v poljubnem programskem jeziku, ki kot argument sprejme število B med 0 in 7. -Program naj prebere znak s standardnega izhoda in izpiše vrstico z nizom "ta", -če je B-ti bit v znaku nastavljen na 1, in "ti" sicer. +Program naj prebere znak s standardnega izhoda. +Če je B-ti bit v znaku nastavljen na 1, naj izpiše "ta". +Če je B-ti bit nastavljen na 0, naj program izpiše "ti". Program poimenuj {progname} in ga spravi v domači imenik {testuser}. """, 'en': u''' @@ -71,12 +72,14 @@ computers = { 'network_interfaces': [ { 'network': 'net1', + }, + { 'network': 'net2', }, ], 'flavor': 'm1.tiny', 'config_drive': False, - } + }, 'SmallStudent': { 'disks': [ { @@ -190,20 +193,31 @@ params_meta = { def task(testip, testuser, passwd, magicstr, dstfile, progname, pubseed): from pexpect import pxssh import random - # ideally, this would be done using a SFTP client instead of pxssh + N_TITA = 40 target = pxssh.pxssh() target.login(testip, testuser, passwd) + target.sendline('ls -l ~/{}'.format(dstfile)) + target.prompt() + dst_ls = target.before + target.sendline('cat ~/{}'.format(dstfile)) + target.prompt() + dst_file_contents = target.before + target.sendline('ls ~/'.format(dstfile)) + target.prompt() + home_ls = target.before results = { - 'dst_ls': target.run('ls -l ~/{}'.format(dstfile)) - 'dst_file_contents': target.run('cat ~/{}'.format(dstfile)) - 'home_ls': target.run('ls ~/') + 'dst_ls': dst_ls, + 'dst_file_contents': dst_file_contents, + 'home_ls': home_ls, } tita_return = "" r = random.Random(pubseed) - for i in range(10): + for i in range(N_TITA): b = r.randint(0, 7) x = oct(r.randint(37, 127)).replace('o', '') - tita_return += target.run('echo -e "\0{}" | ~/{} {}'.format(x, progname, b)) + target.sendline('echo -e "\\{}" | ~/{} {}'.format(x, progname, b)) + target.prompt() + tita_return += target.before results['tita_return'] = tita_return target.logout() return results @@ -221,49 +235,70 @@ def gen_params(user_id, params_meta): params['progname'] = kpov_random_helpers.default_generators['filename'](r) while params['dstfile'] == params['progname']: params['progname'] = kpov_random_helpers.default_generators['filename'](r) - params['pubseed'] = kpov_random_helpers.alnum_gen(8) - params['rndseed'] = kpov_random_helpers.alnum_gen(8) + params['pubseed'] = kpov_random_helpers.alnum_gen(r, 8) + params['rndseed'] = kpov_random_helpers.alnum_gen(r, 8) return params def task_check(results, params): import os import re + N_TITA = 40 hints = [] score = 0 hidden_contents = params['magicstr'] r = random.Random(params['rndseed']) for i in range(1000): - x = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)]) - x += "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)]) - x += r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"]) - hidden_contents += x + "\n\r" - expected_contents = re.sub("\n\rpo.*lz\n", - "\n\rpokakalz\n", - hidden_contents, - re.MULTILINE) - expected_contents = re.sub("\n\rpo.*lz$", - "\n\rpokakalz", - expected_contents, - re.MULTILINE) + start = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)]) + mid = "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)]) + end = r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"]) + if start[:2] == "po" and end == "lz": + start = "po" + mid = "kaka" + x = start + mid + end + hidden_contents += x + "\r\n" + expected_contents = hidden_contents + #expected_contents = re.sub(r"^po.*lz\r$", + # r"pokakalz\r", + # hidden_contents, + # re.MULTILINE) + expected_contents = "cat ~/{}\r\n".format(params['dstfile']) + expected_contents if results["dst_file_contents"] == expected_contents: score += 3 else: + #diff_pos = None + #for i, c in enumerate(results["dst_file_contents"]): + # if len(expected_contents) < i or c != expected_contents[i]: + # start = max(0, i-20) + # end = min(len(expected_contents), len(results["dst_file_contents"]), i+200) + # diff_pos = (i, expected_contents[start:end], results["dst_file_contents"][start:end]) + # break + #hints += ["wrong file contents\n" + str(diff_pos)] hints += ["wrong file contents"] - expected_ls = "-rw--w---- 1 {testuser} bilbo .* {dstfile}".format(**params) - if re.match(expected_ls, results["dstfile_ls"]): + expected_ls = u"ls -l ~/{dstfile}\r\n-rw--w---- 1 {testuser} bilbo .*{dstfile}\r\n".format(**params) + if re.match(expected_ls, results["dst_ls"]): score += 3 else: - hints += ["missing file or wrong user/permissions"] + hints += ["missing file or wrong user/permissions\n" + str((results["dst_ls"], expected_ls))] if results["home_ls"].find(params['progname']) > -1: score += 2 else: hints += ["missing program"] - expected_tita = "" + expected_tita = u"" + r = random.Random(params['pubseed']) + for i in range(N_TITA): + b = r.randint(0, 7) + x_i = r.randint(37, 127) + x = oct(x_i).replace('o', '') + expected_tita += u'echo -e "\\{}" | ~/{} {}\r\n'.format(x, params['progname'], b) + if x_i & (1 << b): + expected_tita += u"ta\r\n" + else: + expected_tita += u"ti\r\n" if results["tita_return"] == expected_tita: score += 2 else: - hints += ["program output incorrect" + results["tita_return"]] + hints += ["program output incorrect\n" + str((results["tita_return"],)) + "\n" + str((expected_tita,))] return score, hints @@ -273,7 +308,7 @@ def prepare_disks(templates, task_params, global_params): #print "Haha!" #print params #print templates - d = templates['SmallStudent'] + d = templates['student-entrance2'] # first create the file contents to make it easyer to check. hidden_contents = task_params['magicstr'] r = random.Random(task_params['rndseed']) @@ -292,16 +327,16 @@ def prepare_disks(templates, task_params, global_params): try: potential_dir = os.path.join('/home/bilbo/.config', potential_dir) d.mkdir(potential_dir) - d.chown(1002, 1002, potential_dir) + d.chown(1001, 1001, potential_dir) except: pass - for i in r.randint(2, 20): + for i in range(r.randint(2, 20)): rndstr2 = r.choice(start_list) + \ r.choice(file_letters) + r.choice(ending_list) hidden_file_name = os.path.join(potential_dir, rndstr2) - d.chown(1002, 1002, hidden_file_name) d.write(hidden_file_name, hidden_contents) + d.chown(1001, 1001, hidden_file_name) file_letters = ["stamp", "", "dev", "re"] hidden_contents = "".join([r.choice("asdfghjkyxcvbnm1234567890 \n") for j in range(10000)]) file_letters = file_letters + ["mod", "co"] diff --git a/kpov_judge/tasks/ldap_search/task.py b/kpov_judge/tasks/ldap_search/task.py index 6889b13..0e906ae 100644 --- a/kpov_judge/tasks/ldap_search/task.py +++ b/kpov_judge/tasks/ldap_search/task.py @@ -15,25 +15,22 @@ Na LDAPServer namesti strežnik LDAP. Strežnik naj skrbi za domeno DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si V imeniku ustvari uporabnika -CN={LDAP_USERNAME},ou=Users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si +CN={LDAP_USERNAME},ou=users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si z geslom {LDAP_PASSWORD} in uporabnika -CN={BIND_USERNAME},ou=Users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si +CN={BIND_USERNAME},ou=users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si z geslom {BIND_PASSWORD} Poskrbi, da se bo lahko klient s simpleArbiterDhcp povezal na LDAP strežnik na LDAPServer. V primeru, da se klient poveže kot {BIND_USERNAME} z geslom {BIND_PASSWORD}, naj strežnik omogoči spreminjanje podatkov za objekt -CN={LDAP_USERNAME},ou=Users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si +CN={LDAP_USERNAME},ou=users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si ter ustvarjanje novih objektov v DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si CN = Common Name +O = Organization OU = Organizational Unit DC = Domain Component - -Na SimpleArbiter ustvari program, ki bo s pomočjo ldapsearch izpisal seznam lastnosti (otrok), -ki jih ima poljuben objekt v domeni {DOMAIN}.kpov.lusy.fri.uni-lj.si. -Ime objekta (CN) naj program sprejme kot prvi argument. """, 'en': u""" Create two virtual machines - SimpleArbiter using the disk simpleArbiterDhcp @@ -43,10 +40,10 @@ Set up an LDAP server on LDAPServer. Make it responsible for DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si Create a user -CN={LDAP_USERNAME},ou=Users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si +CN={LDAP_USERNAME},ou=users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si with the password {LDAP_PASSWORD} and a user -CN={BIND_USERNAME},ou=Users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si +CN={BIND_USERNAME},ou=users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si with the password {LDAP_PASSWORD} . @@ -54,16 +51,14 @@ Make sure that a client from simpleArbiterDhcp can connect to the LDAP server on LDAPServer. If the client identifies themself as {BIND_USERNAME} with the password {BIND_PASSWORD}, allow it to change data for the object -CN={LDAP_USERNAME},ou=Users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si +CN={LDAP_USERNAME},ou=users,DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si and to create objects in DC={DOMAIN},DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si CN = Common Name +O = Organization OU = Organizational Unit DC = Domain Component -Create a program on SimpleArbiter which will use ldapsearch to output the list of properties -(children) of an arbitrary object under {DOMAIN}.kpov.lusy.fri.uni-lj.si. -The program will be given the CN of the object as it's first argument. """ } @@ -115,7 +110,7 @@ def task(LDAP_IP, DOMAIN, LDAP_USERNAME, LDAP_PASSWORD, BIND_USERNAME, BIND_PASS results = dict() FULLDOMAIN = "dc={DOMAIN},dc=kpov,dc=lusy,dc=fri,dc=uni-lj,dc=si".format( **locals()) - BIND_DN = "uid={BIND_USERNAME},ou=Users,{FULLDOMAIN}".format(**locals()) + BIND_DN = "cn={BIND_USERNAME},ou=Users,{FULLDOMAIN}".format(**locals()) s = "ldapsearch -D {BIND_DN} -b {FULLDOMAIN} -w {BIND_PASSWORD}\ -h {LDAP_IP}".format( **locals()) @@ -123,10 +118,10 @@ def task(LDAP_IP, DOMAIN, LDAP_USERNAME, LDAP_PASSWORD, BIND_USERNAME, BIND_PASS s = "ldapmodify -D {BIND_DN} -w {BIND_PASSWORD} -h {LDAP_IP}".format( **locals()) modify = pexpect.spawn(s) - FORTUNE = kpov_random_helpers.fortune(random.Random(), 20) - results['FORTUNE'] = FORTUNE + FORTUNE = kpov_random_helpers.hostname_gen(random.Random(str(LDAP_USERNAME))) + results['fortune'] = FORTUNE s1 = """ -dn: uid={LDAP_USERNAME},ou=Users,{FULLDOMAIN} +dn: cn={LDAP_USERNAME},ou=Users,{FULLDOMAIN} changetype: modify replace: description description: {FORTUNE} @@ -154,38 +149,38 @@ def task_check(results, params): import re score = 0 hints = [] - s = """.*dn: dc={DOMAIN},dc=kpov,dc=lusy,dc=fri,dc=uni-lj,dc=si\r + s = """.*dn: dc={DOMAIN},dc=kpov,dc=lusy,dc=fri,dc=uni-lj,dc=si\r[^#]* objectClass: top\r objectClass: dcObject\r objectClass: organization\r .*""".format(**params) #dc: {DOMAIN}\r - fortune = results['FORTUNE'] if re.match(s, results['ldapsearch_before'], re.DOTALL): score += 2 else: - hints += [s + str(results['ldapsearch_before'])] - s = ".*uid: {}.*".format(re.escape(params['LDAP_USERNAME'])) + hints += ["domain missing in ldapsearch result"] + s = ".*cn: {}.*".format(re.escape(params['LDAP_USERNAME'])) if re.search(s, results['ldapsearch_before']): score += 2 else: - hints += [s + str(results['ldapsearch_before'])] - s = ".*uid: {0}.*description: {1}.*".format( - re.escape(params['LDAP_USERNAME']), re.escape(fortune[:40])) + hints += ["LDAP_USERNAME missing in: " + s + str(results['ldapsearch_before'])] + fortune = kpov_random_helpers.hostname_gen(random.Random(str(params['LDAP_USERNAME']))) + s = ".*cn: {0}.*description: {1}.*".format( + re.escape(params['LDAP_USERNAME']), re.escape(fortune)) if re.match(s, results['ldapsearch_after'], re.DOTALL): score += 2 else: - hints += [s + str(results['ldapsearch_after'])] + hints += ["description missing after update:" + fortune + "\n" + s + str(results['modify']) + str(results['ldapsearch_after'])] if results['ldapsearch_before'][:100] == results['ldapsearch_after'][:100]: score += 2 else: - hints += ["ldapsearch wrong"] - s = '.*\r\nmodifying entry "uid={LDAP_USERNAME},ou=Users,dc={DOMAIN},dc=kpov,dc=lusy,dc=fri,dc=uni-lj,dc=si".*'.format( + hints += ["ldapsearch before equals after. This should not happen."] + s = '.*\r\nmodifying entry "cn={LDAP_USERNAME},ou=Users,dc={DOMAIN},dc=kpov,dc=lusy,dc=fri,dc=uni-lj,dc=si".*'.format( **params) if re.match(s, results['modify'], re.DOTALL): score += 2 else: - hints += [s + str(results['modify'])] + hints += ['Modify error' + s + str(results['modify'])] return score, hints def prepare_disks(templates, task_params, global_params): diff --git a/kpov_judge/tasks/mock_entrance_exam/howtos/en/index.html b/kpov_judge/tasks/mock_entrance_exam/howtos/en/index.html new file mode 100644 index 0000000..e69de29 diff --git a/kpov_judge/tasks/vlc_stream_rtp/task.py b/kpov_judge/tasks/vlc_stream_rtp/task.py index 4ae435d..ea9b905 100644 --- a/kpov_judge/tasks/vlc_stream_rtp/task.py +++ b/kpov_judge/tasks/vlc_stream_rtp/task.py @@ -9,12 +9,11 @@ instructions = { 'si':u""" Postavi navidezni računalnik SimpleArbiter z diska simpleArbiter ter StudentVLC z diska student-VLC. Poskrbi, da bosta na istem omrežju, od -koder bosta imela dostop tudi do Interneta -Na StudentVLC posodobi datoteko /etc/apt/sources.list, preveri posodobitve in -naloži VLC. +koder bosta imela dostop tudi do Interneta Na StudentVLC posodobi datoteko +/etc/apt/sources.list, preveri posodobitve in naloži VLC. Posnemi ali kako drugače ustvari film ter poskrbi, da bo film dostopen na -lokalnem omrežju prek RTP z imenom toka {TOK} na naslovu {NASLOV}. +lokalnem omrežju prek RTP z imenom toka {TOK} na naslovu {NASLOV}, vrata {PORT}. Računaj, da bodo film lahko videli tvoji sošolci. Kršenje avtorskih pravic je pri reševanju te naloge strogo prepovedano. """, @@ -27,7 +26,7 @@ VLC. Record or otherwise create a movie and make sure the movie is avaliable on your local network via RTP with the name of the stream {TOK} at the address -{NASLOV}. +{NASLOV} on port {PORT}. Take into account that the movie may be seen by your classmates. Copyright infrigement while solving this task is strictly prohibited. @@ -102,15 +101,19 @@ def task_check(results, params): p1_d = p1_l[1:-1] p1_s = "" for i in p1_d: - p1_s += "".join([j for j in i.split(' ')[1:]]) - sname = "".join([ hex(ord(i))[2:] for i in params['TOK']]) + p1_s = p1_s + "".join([j.strip() for j in i.split(' ')[1:]]) + sname = "".join([hex(ord(i))[2:] for i in params['TOK']]) if p1_s.find(sname) > 2: score += 5 - s = "IP [^ ]* > {}.{}: UDP, length [0-9]+\n\r".format( + else: + hints.append("stream name not found in stream announcement") + s = "IP [^ ]* > {}.{}: UDP, length [0-9]+".format( re.escape(params['NASLOV']), params['PORT']) if re.search(s, results['tcpdump']): score += 5 + else: + hints.append("RTP stream not detected in " + results['tcpdump']) return score, hints def prepare_disks(templates, task_params, global_params): -- cgit v1.2.1