From 173d160b19811eb77fdd36c9c0eacf90b65a83f3 Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Mon, 26 Oct 2015 20:29:07 +0000 Subject: Fixed web program after first exam git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@342 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/kpov_random_helpers.py | 4 ++- .../howtos/si/index.html | 19 ++++++----- kpov_judge/tasks/ldap_search/task.py | 2 +- kpov_judge/tasks/mock_entrance_exam/task.py | 35 +++++---------------- kpov_judge/tasks/set_motd/howtos/images/img7.png | Bin 7107 -> 32530 bytes kpov_judge/web/kpov_judge/kpov_judge.py | 33 +++++++++---------- kpov_judge/web/kpov_judge/templates/task.html | 2 ++ .../web/kpov_judge/templates/task_greeting.html | 2 ++ 8 files changed, 45 insertions(+), 52 deletions(-) (limited to 'kpov_judge') diff --git a/kpov_judge/kpov_random_helpers.py b/kpov_judge/kpov_random_helpers.py index fc422fa..5fb2593 100755 --- a/kpov_judge/kpov_random_helpers.py +++ b/kpov_judge/kpov_random_helpers.py @@ -25,7 +25,9 @@ def fortune(r, max_len): for i in l: if len(i) < max_len: all_fortunes.append(i) - return re.sub(r'\s+', ' ', r.choice(all_fortunes)).strip() + stripped = re.sub(r'\s+', ' ', r.choice(all_fortunes)) + s = re.sub(r'[^\w?:;!./&%$=,]+', ' ', stripped) + return s.strip() def _net_to_int(s): try: diff --git a/kpov_judge/tasks/copy_rename_20_files_tail_env/howtos/si/index.html b/kpov_judge/tasks/copy_rename_20_files_tail_env/howtos/si/index.html index 4d3ccd4..1ce8b44 100644 --- a/kpov_judge/tasks/copy_rename_20_files_tail_env/howtos/si/index.html +++ b/kpov_judge/tasks/copy_rename_20_files_tail_env/howtos/si/index.html @@ -1,3 +1,6 @@ + + +

Namen vaje

-

Nau?ite se uporabe nekaj BASH ukazov.

+

Naučite se uporabe nekaj BASH ukazov.

Naloga na hitro

Uporabljali boste BASH ukaze kot so: mv, grep, env in druge.

Navodila

    -
  1. Prijavite se v sistem in v domaÄŤem imeniku najdete imenik Mapa z 20 datotekami.
  2. -
  3. Preimenujete vse datoteke tako, da zamenjate minuse s pod?rtaji z ukazom: "rename 's/-/_/' *".
  4. -
  5. Premaknite vse datoteke mkdir iz /home/user/mapa/mojimenik v /home/user/novi z ukazom: "mkdir-p /home/user/novi && mv /home/user/mapa/mojimenik/* /home/user/novi"
  6. -
  7. V datoteko "mama.txt" zapi¨ite vse navadne datoteke v trenutnem imeniku, ki vsebujejo niz "mama", v datoteko "napake.txt" pa zapi¨ite vse morebitne napake z ukazom: "find . -type f | grep mama 1> mama.txt 2> napake.txt".
  8. -
  9. Sledite vsebini /var/log/syslog za 5 sekund in v primeru, da se v syslogu pojavi niz "zmeda", izpi¨ite "imam ga". Poleg tega med sledenjem syslog-u od¨tevajte od 5 do 1 z ukazom: "for i in 5 4 3 2 1; do echo $i; echo $(sed -n "$i p" /var/log/syslog | grep zmeda > /dev/null && echo "imam ga"); sleep 1; done".
  10. -
  11. Nastavite okoljsko spremenljivko TEST, da bo imela isto vrednost kot okoljska spremenljivka USER + ¨tevilo okoljskih spremenljivk, ki v imenu ali vrednosti ne vsebujejo besede TEST tako, da na koncu datoteke ~/.bashrc dodate: "export TEST=$USER" + "$(env | grep -v TEST | wc -l)"
  12. +
  13. Prijavite se v sistem. V domačem imeniku najdete imenik Mapa z 20 datotekami.
  14. +
  15. Preimenujete vse datoteke tako, da zamenjate minuse s podčrtaji z ukazom: "rename 's/-/_/' *".
  16. +
  17. Premaknite vse datoteke /home/user/mapa/mojimenik v /home/user/novi z ukazom: "mkdir-p /home/user/novi && mv /home/user/mapa/mojimenik/* /home/user/novi"
  18. +
  19. V datoteko "mama.txt" zapišite vse navadne datoteke v trenutnem imeniku, ki vsebujejo niz "mama", v datoteko "napake.txt" pa zapišite vse morebitne napake z ukazom: "find . -type f | grep mama 1> mama.txt 2> napake.txt".
  20. +
  21. Sledite vsebini /var/log/syslog za 5 sekund in v primeru, da se v syslogu pojavi niz "zmeda", izpišite "imam ga". Poleg tega med sledenjem syslog-u odštevajte od 5 do 1 z ukazom: "for i in 5 4 3 2 1; do echo $i; echo $(sed -n "$i p" /var/log/syslog | grep zmeda > /dev/null && echo "imam ga"); sleep 1; done".
  22. +
  23. Nastavite okoljsko spremenljivko TEST, da bo imela isto vrednost kot okoljska spremenljivka USER + število okoljskih spremenljivk, ki v imenu ali vrednosti ne vsebujejo besede TEST tako, da na koncu datoteke ~/.bashrc dodate: "export TEST=$USER" + "$(env | grep -v TEST | wc -l)"

+ + diff --git a/kpov_judge/tasks/ldap_search/task.py b/kpov_judge/tasks/ldap_search/task.py index eeaf8cd..75dcde2 100644 --- a/kpov_judge/tasks/ldap_search/task.py +++ b/kpov_judge/tasks/ldap_search/task.py @@ -84,7 +84,7 @@ computers = { }, 'SimpleArbiter': { 'disks': [ - { 'name': 'simpleArbiterDhcpGW', + { 'name': 'simpleArbiterDhcpGWLDAP', # attempt automount }, #{ 'name': 'CDROM', diff --git a/kpov_judge/tasks/mock_entrance_exam/task.py b/kpov_judge/tasks/mock_entrance_exam/task.py index 46fc7da..1ee2d3f 100644 --- a/kpov_judge/tasks/mock_entrance_exam/task.py +++ b/kpov_judge/tasks/mock_entrance_exam/task.py @@ -5,25 +5,7 @@ # - switch to a real SSH/SFTP client to properly handle filenames instructions = { - 'si':u""" -Ustvari dva navidezna računalnika - simpleArbiter in Student. - -Poskrbi, da bosta oba na istem omrežju in da bo imel Student naslov {student_IP}. Obenem mora biti -simpleArbiter povezan na Internet. Računajte, da se na studentGUI ob zagonu zažene program {net_prog_name}, -ki vam spreminja nastavitve mrežne kartice. - -V domačem imeniku uporabnika student (geslo je "vaje") obstaja datoteka {P_c} v programskem jeziku C. Z uporabo gcc ga prevedite v program z imenom {P_executable}. Izvorna koda je namenoma pokvarjena tako, da so vanjo vrinjeni nepotrebni znaki. Pred prevajanjem jo morate popraviti. - -Napišite skripto ali program {P_script} v domačem imeniku uporabnika student, ki: -- požene {P_c} z argumentom {arg_c} in mu na standardni vhod pripelje vrednost spremenljivke {env_c} -- vse, kar {P_c} izpiše na stderr, spravi v datoteko {out_stderr_c}. -- vse vrstice, ki jih {P_c} izpiše na stdout in vsebujejo zaporedje znakov "ma", zapiše v {out_stdout_c}. - - -Lastnik vseh ustvarjenih datotek mora biti uporabnik student. Gesla uporabnika student -ne smete spreminjati. - -""", + 'si': u'Navodil ni.', 'en': u''' ''', } @@ -87,7 +69,7 @@ params_meta = { }, 'out_stderr_c': { 'descriptions': { 'si': 'Datoteka z napakami', 'en': 'File to store errors', - }, 'w': True, 'public': True, 'type': 'filename', 'generated': True, + }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'P_script': { 'descriptions': { 'si': 'Ime skripte', 'en': 'Filename of the script', @@ -116,7 +98,7 @@ def task(student_IP, net_prog_name, conn = pxssh.pxssh() conn.login(student_IP, 'student', 'vaje') results = dict() - r = random.Random(param_gen_seed) + r = random.Random(int(param_gen_seed)) env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(11)]) arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(13)]) @@ -167,23 +149,22 @@ def task_check(results, params): arg_len = len(arg) env_len = len(var) for i in xrange(100): - s_out += chr(20 + (ord(arg[i % arg_len]) ^ ord(var[i % env_len]) % 64)) + s_out += chr(32 + ((ord(arg[i % arg_len]) ^ ord(var[i % env_len])) % 64)) r += ord(arg[i % arg_len]) + ord(var[i % env_len]) + i; if (i % 20 == 0): s_out += "RAUS\r\n"; if (i % 31 == 0): s_out += 'ma' - s_err += chr(r % 32 + ord('A')); + s_err += chr((r % 32) + ord('A')); if (i % 23 == 0): s_err += "PATACIS\r\n" retval = r % 16 s_err += '\r\n' s_out += '\r\n' return(s_out, s_err, retval) - score = 0 hints = [] - r = random.Random(params['param_gen_seed']) + r = random.Random(int(params['param_gen_seed'])) env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(11)]) arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(13)]) stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(17)]) @@ -191,6 +172,7 @@ def task_check(results, params): params['arg_c'], env_val ) expected_script_stderr = 'cat {}\r\n'.format(params['out_stderr_c']) + expected_script_stderr + # hints += [expected_script_stderr, results['script_run'], results['script_stderr'], params['arg_c'], env_val] if expected_script_stderr != results['script_stderr']: hints += ['wrong script stderr'] else: @@ -239,7 +221,7 @@ int main(int argc, char **argv){ env_len = strlen(var); r = 0; for (i = 0; i<100; i++){ - printf("%c", 20 + (arg[i % arg_len] ^ var[i % env_len] % 64)); + printf("%c", 32 + (arg[i % arg_len] ^ var[i % env_len]) % 64); r += (int)arg[i % arg_len] + (int)var[i % env_len] + i; if (i % 20 == 0){ printf("RAUS\\n"); @@ -279,7 +261,6 @@ done destroyed_c_source += 'QX' destroyed_c_source += c d.write(params['P_c'], destroyed_c_source) - print params['P_c'] d.chown(1000, 1000, params['P_c']) sh_path ='/usr/local/bin/' + params['net_prog_name'] d.write(sh_path, evil_shell_source) diff --git a/kpov_judge/tasks/set_motd/howtos/images/img7.png b/kpov_judge/tasks/set_motd/howtos/images/img7.png index ef61212..40ce63d 100644 Binary files a/kpov_judge/tasks/set_motd/howtos/images/img7.png and b/kpov_judge/tasks/set_motd/howtos/images/img7.png differ diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py index 3242c9d..6302c3a 100755 --- a/kpov_judge/web/kpov_judge/kpov_judge.py +++ b/kpov_judge/web/kpov_judge/kpov_judge.py @@ -52,7 +52,7 @@ def root(): def results_post(task_id, results): student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody') db = g.db - params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id}) + params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id})['params'] if params is None: # params = {} #else: @@ -67,13 +67,14 @@ def results_post(task_id, results): for param_name, param_meta in meta.iteritems(): if param_meta.get('w', False) and param_name in user_params: params[param_name] = user_params[param_name] - task_check_source = task_source(task_id) try: + task_check_source = db.task_checkers.find_one({'task_id': task_id})['source'] task_check_code = compile(task_check_source, 'checker.py', 'exec') exec(task_check_code) - res, hints = task_check(results, params) + # raise Exception(str(params)) + hints, res = task_check(results, params) except Exception as e: - hints = ["Checker crashed: " + str(e)] + hints = ["Checker died: " + str(e)] res = 0 if isinstance(res, int) and res > 0: res_status = 'OK' @@ -96,13 +97,13 @@ def results_dict(task_id): except Exception as e: return {'Error': str(e)} -@app.route('/tasks//results.json', methods=['GET', 'POST']) +@app.route('/tasks//results.json', methods=['GET', 'POST']) def results_json(task_id): if flask.app.request.method == 'POST': - return results_post(task_id, json.loads(flask.app.request.form['results'])) + return json.dumps(results_post(task_id, json.loads(flask.app.request.form['results']))) return json.dumps(results_dict(task_id)) -@app.route('/tasks///results.html') +@app.route('/tasks///results.html') def results_html(task_id, lang): return render_template('results.html', results=results_dict(task_id)) @@ -121,7 +122,7 @@ def public_meta(db, task_id): return shown -@app.route('/tasks//task.py') +@app.route('/tasks//task.py') def task_source(task_id): db = g.db try: @@ -130,7 +131,7 @@ def task_source(task_id): return dummy_task return task_str -@app.route('/tasks//task.html') +@app.route('/tasks//task.html') def task_html(task_id): return render_template('task.html', task=task_source(task_id)) @@ -166,21 +167,21 @@ def get_params(task_id, student_id, db): params = params['params'] return params, meta -@app.route('/tasks//') +@app.route('/tasks//') def task_lang_redirect(task_id): return redirect(url_for('task_greeting', task_id=task_id, lang=app.config['DEFAULT_LANG'])) -@app.route('/tasks///howto/') +@app.route('/tasks///howto/') def task_howto(task_id, lang): db = g.db return db.howtos.find({'task_id': task_id, 'lang': lang})[0].get('text', '') -@app.route('/tasks///images/') +@app.route('/tasks///images/') def task_image(task_id, lang, fname): db = g.db return db.howto_images.find({'task_id': task_id, 'fname': fname})[0].get('data', '') -@app.route('/tasks///') +@app.route('/tasks///') def task_greeting(task_id, lang): student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody') db = g.db @@ -219,7 +220,7 @@ def task_greeting(task_id, lang): openstackCreated = False return render_template('task_greeting.html', computers=computer_list, lang=lang, openstack=openstackCreated, instructions=instructions) -@app.route('/tasks//params.json', methods=['GET', 'POST']) +@app.route('/tasks//params.json', methods=['GET', 'POST']) def params_json(task_id): student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody') db = g.db @@ -242,7 +243,7 @@ def params_json(task_id): shown_params[name] = param return json.dumps(shown_params) -@app.route('/tasks///params.html', methods=['GET', 'POST']) +@app.route('/tasks///params.html', methods=['GET', 'POST']) def params_html(task_id, lang): student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody') db = g.db @@ -263,7 +264,7 @@ def params_html(task_id, lang): return render_template('params.html', params=shown_params, params_meta=meta) -@app.route('/tasks//params_meta.json') +@app.route('/tasks//params_meta.json') def params_meta(task_id): db = g.db return json.dumps(public_meta(db, task_id)) diff --git a/kpov_judge/web/kpov_judge/templates/task.html b/kpov_judge/web/kpov_judge/templates/task.html index 98147ab..ddad5d8 100644 --- a/kpov_judge/web/kpov_judge/templates/task.html +++ b/kpov_judge/web/kpov_judge/templates/task.html @@ -1,3 +1,5 @@ +

diff --git a/kpov_judge/web/kpov_judge/templates/task_greeting.html b/kpov_judge/web/kpov_judge/templates/task_greeting.html index b1ede6c..f19f534 100644 --- a/kpov_judge/web/kpov_judge/templates/task_greeting.html +++ b/kpov_judge/web/kpov_judge/templates/task_greeting.html @@ -1,3 +1,5 @@ +

-- cgit v1.2.1