summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/set_motd/task.py
blob: 2c4ae0fc3f2b6ba8d70acdc1ab42cf995370ff2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102


#!/usr/bin/env python
# -*- coding: utf-8 -*-

# bson.son.SON an
# kpov_random_helpers should be imported by add_assignment.py
# OrderedDict = SON


instructions = {
    "si":u"""
Ustvari dva navidezna računalnika - imenujmo ju Test in Student. Za računalnik Test uporabite
sliko diska, poimenovano Test. Na računalniku Test dobite kratek niz. Poskrbite, da se bo ta
kratki niz pojavil v sporočilu, ki se ob prijavi izpiše na računalniku Student. Temu sporočilu v
angleščini rečemo "message of the day" - MOTD.

Poskrbite, da se bo ob prijavi uporabnika (v Message Of The Day, MOTD) prek ssh izpisal nek niz.
Računalnik nastavite tako, da bo dostopen s testnega računalnika (Test).

Uporabniško ime in niz dobite kot parametre ob zagonu run_test.py. Pri nizu pazite, saj utegne biti dovolj dolg, da brez premikanja kurzorja ne bo takoj viden.

IP navideznega računalnika ter geslo nastavite sami.

Ocenjevalni program pričakuje, da se bo ob koncu prijave pojavila ukazna vrstica oblike uporabnisko_ime@ime_racunalnika:~$ . Pazite, da se bo takšna vrstica pojavila šele po nizu, ki ste ga dobili v navodilih.


Create two virtual machines - named Test and Student. For the 'Test' use disc image named Test. You receive short string on machine 'Test'. Make sure that this string appears in the message which is displayed after you login to machine 'Student'. This is so called 'message of the day'MOTD.

Make sure that when the user logins via ssh some string is displayed. Set the machine, so that you can reach it from test computer (Test)

You get username and string as parameters when you run run_test.py. Pay attention to the string length, it might not be visible right away without moving the cursor.

Set up IP and password of virtual machine yourself.

Grading system expects, that at the end of login, a command line similar to uporabnisko_ime@ime_racunalnika:~$ appears. Make sure that this line shows up after the string you got in the instructions.
"""
}

computers = {
    'Test': {
        'disks': [
            {   'name': 'Test',
            },
        ],
        'flavor': 'm1.tiny',
        'network_interfaces': [{'network': 'net1'}],
        'config_drive': True,
        'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"}
    },
    'Student': {
        'disks': [
            { 'name': 'Student', }
        ],
        'flavor': 'm1.tiny',
        'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
        'config_drive': True,
        'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"}
    }
    
}

networks = { 'net1': {'public': False}, 'test-net': {'public': True} }

params_meta = {
    'peer_ip': {'descriptions': {'si': u'IP računalnika'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False},
    'peer_user': {'descriptions': {'si': 'ime uporabnika'}, 'w': False, 'public': True, 'type': 'username', 'generated': True},
    'peer_passwd': {'descriptions': {'si': 'geslo uporabnika'}, 'w': True, 'public': True, 'type': 'alnumstr', 'generated': False},
    'niz': {'w': False, 'public': True, 'type': 'short_text', 'generated': True},
}

def task(peer_ip, peer_user, peer_passwd, niz):
    "Check whether ssh works"
    import pxssh
    import pexpect
    return {"hello": 'kitty'}
    results = dict()
    s = pxssh.pxssh()
    #TODO (polz): tole bi utegnilo delovati http://pexpect.sourceforge.net/pxssh.html. Testirajte
    s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False)
    #TODO original_prompt je za popravit	
    temp = s.before # print everything before the prompt.
    #TODO (polz): tole ni pravi pristop. Problem je bil v tem, da pxssh ni prav zaznal, kdaj je prijavljen. Glej link zgoraj.
    results['motd'] = temp.replace("#","")     #zamenja vse pojavitve "#" s praznim stringom    
    #results['motd'] = s.before         # print everything before the prompt. prvotna verzija
    return results
    #
    
def gen_params(user_id, params_meta):
    return kpov_random_helpers.default_gen(user_id, params_meta)

def task_check(results, params):
    print task_url
    niz = params['niz']
    score = 0
    if (results['motd'].find(niz) > -1):
        score += 10
    return score

def prepare_disks(templates, params):
    # print d1.ls('/')
    pass