From 7512e2c7555c6e3536e1bcb6b3a328d4e9aced77 Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Wed, 17 Dec 2014 18:18:53 +0000 Subject: Added some comments/instructions in the task.py files, answered some questions in DEVELOPMENT-FAQ.txt git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@95 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/DEVELOPMENT-FAQ.txt | 56 +++++++++++- .../tasks/copy_rename_20_files_tail_env/task.py | 10 +- kpov_judge/tasks/custom_rdate/task.py | 7 +- kpov_judge/tasks/isc_dhcp_live_boot/task.py | 101 +++++++++++---------- kpov_judge/tasks/openvpn_simple_smb/task.py | 10 +- kpov_judge/tasks/set_ip_static_dhcp/task.py | 1 + kpov_judge/tasks/set_motd/task.py | 2 + kpov_judge/tasks/smb_nfs/task.py | 6 +- kpov_judge/tasks/snmp_agent_uptime/task.py | 14 ++- 9 files changed, 142 insertions(+), 65 deletions(-) diff --git a/kpov_judge/DEVELOPMENT-FAQ.txt b/kpov_judge/DEVELOPMENT-FAQ.txt index 40a7c4b..11a3121 100644 --- a/kpov_judge/DEVELOPMENT-FAQ.txt +++ b/kpov_judge/DEVELOPMENT-FAQ.txt @@ -12,5 +12,57 @@ Vprašanje: Vprašanje (06-isc_live_boot): - lahko prosim razložite bolj potrobno prvi del navodil (ne razumemo kaj naj bi bila ta datoteka A, ter kako so mišljeni ti IP-ji pri parametru IP_DHCP ter IP_GW). -Vprašanje (in general) -What is the difference between simpleArbiter, simpleArbiterDhcp, simpleArbiter-base? + +Question: + - What is the difference between simpleArbiter, simpleArbiterDhcp, simpleArbiter-base? + +Answer: + - The image simpleArbiter-base is a base image which should not be altered. simpleArbiter is derived from simpleArbiter-base + and is the minimal system that should be used for testing. simpleArbiterDhcp is the same as simpleArbiter, but includes a DHCP server. + simpleArbiterGW includes a DHCP server and is configured to act as a router using NAT. + +Question: + - How do I add a translation of the instructions? + +Answer: + - Add a key, value pair into the instructions dictionary. For example (orig): + instructions = {'en':'Do the locomotion'} + corrected: + instructions = {'en':'Do the locomotion', 'si':'Izvedi gibanje'} + +Question: + - How do I add a parameter to params_meta / what is the meaning of each field? + +Answer: + - params_meta is a simple dictionary. If, for example, the parameters are SOME_IP, SOME_MAC and SOME_FNAME and + if the student is supposed to be shown SOME_IP and SOME_MAC but is supposed to find SOME_FNAME by inspecting the + filesystem of their computer, params_meta might look like this: + +params_meta = { + 'SOME_IP': { + 'descriptions': {'en': 'THE IP of the server'}, # this will be shown in the dialog when test_task.py is run + 'w': False, # the student is not allowed to change the value of SOME_IP + 'public': True, # the student should be shown the value of SOME_IP if they run test_task.py + 'type':'IP', # this can be used to pick the right function to generate the random value + # Look at kpov_random_helpers.default_generators and kpov_random_helpers.IPv4_addr_gen + # for more info. + 'generated': True # this parameter should be generated by gen_params + }, + 'SOME_MAC': { + 'descriptions': {'en': 'The MAC of the server', 'si': u'MAC naslov strežnika'}, + 'w': True, # the student can change this value + 'public': True, # the student should see this parameter when they run test_task.py + 'type':'MAC', # if 'MAC' were a key in kpov_random_helpers.default_generators, the value + # in that dictionary should be a random function for generating MAC addresses. + # Also, in the future, the 'type' field could be used for validation. + 'generated': False # the student should enter this value his or herself. + }, + 'SOME_FNAME': { + 'descriptions': {'en': 'The name of the file to find'}, # this won't be shown anywhere + 'w': False, # the student is not allowed to change this + 'public': False, # the student will not be shown this parameter when they run test_task.py + 'type': 'filename', # this can be used by gen_params or kpov_random_helpers for generation + 'generated': True # the value should be generated in gen_params + }, +} + diff --git a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py index 6758e34..508185d 100644 --- a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py +++ b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# TODO: finish this! # kpov_random_helpers should be imported by add_assignment.py +# TODO (polz): instructions = { 'si':u""" Prijavi se na sistem. @@ -17,10 +17,7 @@ V domači mapi najdeš imenik Mapa z 20 datotekami. - Napiši ukaz brez uporabe programa cron, kateri 5 minut po izvedbi izpiše vsebino imenika v katerem se trenutno nahajaš - Napiši najkrajši ukaz, ki s pomočjo Pythona zažene preprost (integriran) HTTP strežnik kateri streže datoteke iz imenika iz katerega je bil pognan na vratih 8000 -""" -} - -instructios = { +""", 'en':u""" Log into the system. In your home folder you will find a directory called Folder containing 20 files. @@ -39,7 +36,7 @@ TEST, for example polz37. - With the help of cURL fetch the website content of www.google.com and save it into file named website.txt - Write a command which will count the number of
tags in the filename website.txt and will then append the result to this same file. Command should not be logged in "bash history"! - Write a command (don't use cron!) which will list all the files in the current directory 5 minutes after execution -- Write shortest command possible which will with the help of Python start a simple (integrated) HTTP server and will serve the files from the current directory on port 8000. +- Write shortest command possible which will with the help of Python start a simple (integrated) HTTP server and will serve the files from the current directory on port 8000.""" } computers = { @@ -80,6 +77,7 @@ params_meta = { } def task(IP_NM, DNS_NM, IP_static, DNS_static): + # TODO: (polz) this has to be changed! Get a move on! import pxssh import pexpect results = dict() diff --git a/kpov_judge/tasks/custom_rdate/task.py b/kpov_judge/tasks/custom_rdate/task.py index 2986242..573be62 100644 --- a/kpov_judge/tasks/custom_rdate/task.py +++ b/kpov_judge/tasks/custom_rdate/task.py @@ -59,6 +59,7 @@ computers = { networks = { 'net1': {'public': False}, 'test-net': {'public': True} } +# TODO: (polz) pick the parameters you need! ASAP! 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}, @@ -91,8 +92,12 @@ def task(IP_NM, DNS_NM, IP_static, DNS_static): import datetime import random def gen_params(user_id, params_meta): + # TODO: (polz) tole nima smisla. Za začetek datetime in random + # ne bosta importana v test_task.py, kjer se bo tale koda izvajala. + # Prosim, s kolegi se pogovorite in si izmislite, katere parametre bi + # lahko uporabili. crke = "ABCDEFGHIJKLMNOPRSTUVZXYQW" - time = datetime.datetime.now().strftime("%Y%m%d%H%M%S) + time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") sifra = "" for x in time: for i in x: diff --git a/kpov_judge/tasks/isc_dhcp_live_boot/task.py b/kpov_judge/tasks/isc_dhcp_live_boot/task.py index 3667f8c..60616e5 100644 --- a/kpov_judge/tasks/isc_dhcp_live_boot/task.py +++ b/kpov_judge/tasks/isc_dhcp_live_boot/task.py @@ -15,19 +15,14 @@ SimpleArbiter naj dobi IP_GW. DHCP_server naj ga uporabi kot gateway. Če se zaganja BootableClientB, naj se sistem zažene z live ISO in dobi svoj IP. Če se zaganja katerikoli drug, naj se sistem zažene v datoteko z imenom A. Tako BootableClientA kot BootableClientB naj bosta brez diskov. -""" -} -instructions_en= { -Set up 4 virtual computers - simpleArbiter, DHCP_server, BootableClientA and +""", 'en': """Set up 4 virtual computers - simpleArbiter, DHCP_server, BootableClientA and BootableClientB. The simpleArbiter reads the address IP_GW, IP_DHCP and finds the file A. On the DHCP_server set up a DHCP server with the help of ISC dhcp 3 on the address IP_DHCP. Get SimpleArbiter to find IP_GW. Make the DHCP_server use it as a gateway. If there is BootableClientB loading, make the system start-up with a live ISO and make it get hit own IP. If there is anyone else loading, make the system load the file with the name A. -Make BootableClientA and BootableClientB be without discs. - - +Make BootableClientA and BootableClientB be without discs. """ } computers = { 'DHCPServer': { @@ -88,38 +83,50 @@ params_meta = { def task(IP_DHCP, IP_GW, MAC_BOOT, BOOT_FNAME): # check the IP - import socket - import os - results={} - try: - if IP_DHCP.count('.')!=3 or IP_GW.count('.')!=3: - results['IPcheck']=False - socket.inet_pton(socket.AF_INET,IP_DHCP) - socket.inet_pton(socket.AF_INET,IP_GW) - results['IPcheck']=True - # ping the DHCP server - if os.system("ping "+IP_DHCP)==0: - results[PingDHCP]=True - print("Povezava z DHCP strežnikom je OK") - # check whether the fname served by the dhcp server is - # correct - datoteka=open(BOOT_FNAME,"r") - array=[] - for line in datoteka: - array.append(line) - datoteka.close() - #greš skozi array preverit ce je vse ok - else: - print("Povezava s strežnikom ni OK") - results['PingDHCP']=False - except FileNotFoundError: - results['BootFname']=False - return "Datoteka ne obstaja" - except IOError: - results['BootFname']=False - return "I/O napaka" - except OSError: - results['IPcheck']=False + # TODO (polz): Do not use tabs instead of spaces! + import socket + import os + results={} + try: + # TODO (polz): What purpose does this check serve? + if IP_DHCP.count('.')!=3 or IP_GW.count('.')!=3: + results['IPcheck']=False + socket.inet_pton(socket.AF_INET,IP_DHCP) + socket.inet_pton(socket.AF_INET,IP_GW) + results['IPcheck']=True + # ping the DHCP server + # TODO (polz): Please use pexpect instead of os.system, it's much nicer. + # Also, test your functions. This function was obviously never run. + # + if os.system("ping "+IP_DHCP)==0: + results[PingDHCP]=True + print("Povezava z DHCP strežnikom je OK") + # check whether the fname served by the dhcp server is + # correct + # you should check the DHCP response from the server. + # You can use dhcpdump to get some packets, dhcping to create a + # DHCP Request. You may also use any other tool. + # If you choose to use dhcping, do not forget to set the hw address + # and ip arguments. You can simply feed it MAC_BOOT and IP_BOOT. + # dhcping -h MAC_BOOT -c IP_BOOT -V -r + # could work (but you should test it) + datoteka=open(BOOT_FNAME,"r") + array=[] + for line in datoteka: + array.append(line) + datoteka.close() + #greš skozi array preverit ce je vse ok + else: + print("Povezava s strežnikom ni OK") + results['PingDHCP']=False + except FileNotFoundError: + results['BootFname']=False + return "Datoteka ne obstaja" + except IOError: + results['BootFname']=False + return "I/O napaka" + except OSError: + results['IPcheck']=False # check whether the fname served by the dhcp server is correct # connect to the service in the special ISO # check the MAC of the server on IP_BOOT @@ -138,24 +145,24 @@ def task_check(results, params): import re score = 0 - #TO FINISH SCORING WE REQUIRE DICT KEYS AND FUNCTIONS gen_params AND task TO BE FINISHED - #POINTS FOR EACH TASK MAY BE ADJUSTED IN THE FUTURE + #TO FINISH SCORING WE REQUIRE DICT KEYS AND FUNCTIONS gen_params AND task TO BE FINISHED + #POINTS FOR EACH TASK MAY BE ADJUSTED IN THE FUTURE - #TASK1: all computers up + #TASK1: all computers up if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1: score += 3 - #TASK2: SimpleArbeiter IP_GW + #TASK2: SimpleArbeiter IP_GW if results['static_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_static'])) > -1: score += 3 - #TASK3: SimpleArbeiter IP_DHCP + #TASK3: SimpleArbeiter IP_DHCP if re.search(r'eth0 +802-.*connected', results['NM_nmcli']): score += 2 - #TASK4: SimpleArbaiter IP_B + #TASK4: SimpleArbaiter IP_B if re.search(r'eth0 +802-.*connected', results['static_nmcli']): score += 2 if results['NoNameATM'].find('NoFormatATM'.format(params['NoNameAtm]))> -1: - score +=2 - #Same pattern for other tasks + score +=2 + #Same pattern for other tasks return score def prepare_disks(templates, params): diff --git a/kpov_judge/tasks/openvpn_simple_smb/task.py b/kpov_judge/tasks/openvpn_simple_smb/task.py index 705eb18..0b497ca 100644 --- a/kpov_judge/tasks/openvpn_simple_smb/task.py +++ b/kpov_judge/tasks/openvpn_simple_smb/task.py @@ -188,7 +188,8 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient ###### # sA ###### - + # TODO: (polz) you can remove nmcli and nslookup - these were only used in the task that + # was used as the template for other taps # Make sure NM is not handling eth0 results['SimpleArbiter_nmcli'] = sA.run('nmcli d') @@ -230,6 +231,8 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient # really, really hoping it has root privileges too ### ### Install nmap + # TODO: (polz) Don't install nmap here - tell me that you + # need nmap to be present on simpleArbiter and I'll install it. # Check if root sA.sendline('id -u') sA.prompt() @@ -266,7 +269,7 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient ###### # sC1 ###### - + # TODO: (polz) again, no need for this results['VPNClient1_nmcli'] = sC1.run('nmcli d') results['VPNClient1_nslookup'] = sC1.run('nslookup www.arnes.si') @@ -297,7 +300,8 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient sA.logout() sC1.logout() sC2.logout() - + # TODO: (polz) please, add some sort of check to verify that the user created the neccessarry keys. + # return results diff --git a/kpov_judge/tasks/set_ip_static_dhcp/task.py b/kpov_judge/tasks/set_ip_static_dhcp/task.py index c505490..5321f9b 100644 --- a/kpov_judge/tasks/set_ip_static_dhcp/task.py +++ b/kpov_judge/tasks/set_ip_static_dhcp/task.py @@ -104,6 +104,7 @@ def gen_params(user_id, params_meta): def task_check(results, params): import re + # TODO: (polz) preveri, da na maliNetworkManager NetworkManager skrbi za eth0. score = -9 if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1: score += 3 diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py index 2b44188..2c4ae0f 100644 --- a/kpov_judge/tasks/set_motd/task.py +++ b/kpov_judge/tasks/set_motd/task.py @@ -76,9 +76,11 @@ def task(peer_ip, peer_user, peer_passwd, niz): 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 diff --git a/kpov_judge/tasks/smb_nfs/task.py b/kpov_judge/tasks/smb_nfs/task.py index a586e33..8fd97e7 100644 --- a/kpov_judge/tasks/smb_nfs/task.py +++ b/kpov_judge/tasks/smb_nfs/task.py @@ -16,9 +16,6 @@ datoteke iz imenika MAPA (ta mapa naj vsebuje datoteko z imenom SHARED_FILENAME Naloga za studenta, ki pise gen_params() in params_meta je da nazreba opisane parametre. V task() napisi zaporedje ukazov, ki bodo preverili, ali je student res postavil delujoca streznika NFS in SMB in ali je nanju postavil datoteko SHARED_FILENAME. Vecina logike te funkcije gre v task_check. Izpis teh rezultatov spravi v results. Naloga student, ki pise task_check(results, params) je da napise funkcijo, ki pregleda ustvarjeni results in pove, ali je student opravil nalogo v skladu z navodili. - - - """, 'en':u""" @@ -81,6 +78,7 @@ def task(SMB_NAME, NFS_MOUNT, SHARED_FILENAME, SHARED_FILENAME_CONTENT): # Naslov, na katerem se nahaja streznik. address = SMB_NAME + # TODO: (polz) Try using pexpect instead of subprocess, it's much nicer. # Tabela vseh mountov. mounts = subprocess.check_output("mount").split("\n") # Samo mounti na streznik. @@ -93,6 +91,8 @@ def task(SMB_NAME, NFS_MOUNT, SHARED_FILENAME, SHARED_FILENAME_CONTENT): # example: ["//192.168.1.92/srv/samba on /mnt/samba type cifs (rw)", ... ] # Seznam mora imeti vnos za NFS in SMB, morata biti obesena na pravo pot in (rw) # ++ PIKE za namountan SMB/NFS + # TODO: (polz) prej ali slej tole kodo premaknite v task_check, v results pa porinite + # le mounts (npr. results['mounts'] = mounts for m in srvmounts: # Dobimo pot, filesystem in pravice iz mounta: split = m.split() diff --git a/kpov_judge/tasks/snmp_agent_uptime/task.py b/kpov_judge/tasks/snmp_agent_uptime/task.py index 0d876ac..88e6438 100644 --- a/kpov_judge/tasks/snmp_agent_uptime/task.py +++ b/kpov_judge/tasks/snmp_agent_uptime/task.py @@ -95,12 +95,13 @@ computers = { networks = { 'net1': {'public': False}, 'test-net': {'public': True} } params_meta = { - 'SNMP_VALUE': {'descriptions': {'si': 'Vrednost, dostopna prek SNMP'}Value:0, 'w': False, 'public':True, 'type': 'number', 'generated': True}, - 'SNMP_OID_ON_SERVER': {'descriptions': {'si': 'OID, na katerem je vrednost dostopna'},'OID':'1.3.6.1.4.1.8072.1.3.2.4', 'w': False, 'public':True, 'type': 'OID', 'generated': True}, - 'SNMP_OID_ON_CLIENT': {'descriptions': {'si': 'OID, ki naj ga klient bere'}'OID':'1.3.6.1.4.1.8072.1.3.2.4.1.4', 'w': False, 'public':True, 'type': 'OID', 'generated': True}, + 'SNMP_VALUE': {'descriptions': {'si': 'Vrednost, dostopna prek SNMP'}, 'w': False, 'public':True, 'type': 'number', 'generated': True}, + 'SNMP_OID_ON_SERVER': {'descriptions': {'si': 'OID, na katerem je vrednost dostopna'}, 'w': False, 'public':True, 'type': 'OID', 'generated': True}, + 'SNMP_OID_ON_CLIENT': {'descriptions': {'si': 'OID, ki naj ga klient bere'}, 'w': False, 'public':True, 'type': 'OID', 'generated': True}, } def task(SNMP_VALUE, SNMP_OID_ON_SERVER, SNMP_OID_ON_CLIENT): + # TODO (polz) start working on this. If gen_params doesn't yet work, change it to set the parameter values manually # run cpu temp script on client # run SNMP read SNMP_OID_ON_CLIENT script on client # read data on SNMP_OID_ON_CLIENT @@ -118,12 +119,19 @@ def task(SNMP_VALUE, SNMP_OID_ON_SERVER, SNMP_OID_ON_CLIENT): def gen_params(user_id, params_meta): params = dict() + # TODO (polz) this is wrong. Try something like: + # r = random.Random(user_id) + # params_meta['SNMP_VALUE'] = r.randInt() + # params_meta['SNMP_OID_ON_SERVER'] = '1.3.6.1.4.1.8072.1.3.2.4.1.4' + # You can also create an OID creation function in kpov_random_helpers. r = random.randrange(1,255,1) params_meta[SNMP_VAULE[Value]]=r + # this should probably return params_meta return r def task_check(results, params): #cakam na predhodnike in pomagam tistim ki kaj ne vejo +# TODO (polz) Zacnite s pisanjem testov glede na to, kar vidite v task() import re score = 0 if results['NM_nslookup'].find('Server:\t\t{0}\r'.format(params['DNS_NM'])) > -1: -- cgit v1.2.1