summaryrefslogtreecommitdiff
path: root/kpov_judge
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge')
-rwxr-xr-xkpov_judge/add_assignment.py54
-rwxr-xr-xkpov_judge/create_disk_images.py164
-rw-r--r--kpov_judge/create_opstack.py118
-rw-r--r--kpov_judge/finalize_opstack.py122
-rwxr-xr-xkpov_judge/kpov_random_helpers.py127
-rw-r--r--kpov_judge/random_data/greek_gods.txt488
-rw-r--r--kpov_judge/random_data/roman_gods.txt184
-rw-r--r--kpov_judge/random_data/slavic_gods.txt72
-rw-r--r--kpov_judge/random_data/slovenian_names.txt20
-rw-r--r--kpov_judge/random_data/slovenian_surnames.txt10
-rwxr-xr-xkpov_judge/run_test.py109
-rw-r--r--kpov_judge/settings-example.py14
-rw-r--r--kpov_judge/tasks/copy_rename_40_files/evaluation/task.py120
-rw-r--r--kpov_judge/tasks/copy_rename_40_files/lecture/ideja.txt1
-rw-r--r--kpov_judge/tasks/copy_rename_40_files/preparation/task.py106
-rw-r--r--kpov_judge/tasks/dhcp_dns/evaluation/task.py118
-rw-r--r--kpov_judge/tasks/dhcp_dns/lecture/ideja.txt1
-rw-r--r--kpov_judge/tasks/dhcp_dns/preparation/task.py112
-rw-r--r--kpov_judge/tasks/ieee802/evaluation/task.py116
-rw-r--r--kpov_judge/tasks/ieee802/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/ieee802/preparation/task.py117
-rw-r--r--kpov_judge/tasks/ldap/evaluation/task.py123
-rw-r--r--kpov_judge/tasks/ldap/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/ldap/preparation/task.py111
-rw-r--r--kpov_judge/tasks/nat/evaluation/task.py122
-rw-r--r--kpov_judge/tasks/nat/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/nat/preparation/task.py125
-rw-r--r--kpov_judge/tasks/network_boot/evaluation/task.py121
-rw-r--r--kpov_judge/tasks/network_boot/lecture/ideja.txt1
-rw-r--r--kpov_judge/tasks/network_boot/preparation/task.py90
-rw-r--r--kpov_judge/tasks/openvpn/evaluation/task.py122
-rw-r--r--kpov_judge/tasks/openvpn/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/openvpn/preparation/task.py121
-rw-r--r--kpov_judge/tasks/openwrt/evaluation/task.py120
-rw-r--r--kpov_judge/tasks/openwrt/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/openwrt/preparation/task.py122
-rw-r--r--kpov_judge/tasks/radius/evaluation/task.py126
-rw-r--r--kpov_judge/tasks/radius/lecture/ideja.txt1
-rw-r--r--kpov_judge/tasks/radius/preparation/task.py91
-rw-r--r--kpov_judge/tasks/rdate/evaluation/task.py121
-rw-r--r--kpov_judge/tasks/rdate/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/rdate/preparation/TejoLicen/rServe.zipbin0 -> 499 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu1.pngbin0 -> 979 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu15.pngbin0 -> 679 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu2.pngbin0 -> 826 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu3.pngbin0 -> 13656 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu4.pngbin0 -> 1564 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu5.pngbin0 -> 11278 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu6.pngbin0 -> 15244 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu7.pngbin0 -> 3842 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu8.pngbin0 -> 3420 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/bu9.pngbin0 -> 4245 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/predvaja_clip_image003.gifbin0 -> 686 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/s1.pngbin0 -> 700 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/s2.pngbin0 -> 3882 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/images/s3.pngbin0 -> 3569 bytes
-rw-r--r--kpov_judge/tasks/rdate/preparation/howtos/si/index.html57
-rw-r--r--kpov_judge/tasks/rdate/preparation/task.py107
-rw-r--r--kpov_judge/tasks/remote_ssh/evaluation/task.py51
-rw-r--r--kpov_judge/tasks/remote_ssh/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/remote_ssh/preparation/task.py4
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/evaluation/navodila.html9
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/evaluation/task.py100
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/04.pngbin0 -> 11706 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/09.pngbin0 -> 187608 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/10.pngbin0 -> 193147 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/11.pngbin0 -> 189272 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/12.pngbin0 -> 163954 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/13.pngbin0 -> 175600 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/17.pngbin0 -> 7062 bytes
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/si/index.html73
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/preparation/task.py121
-rw-r--r--kpov_judge/tasks/set_motd/evaluation/navodila.txt8
-rw-r--r--kpov_judge/tasks/set_motd/evaluation/task.py72
-rw-r--r--kpov_judge/tasks/set_motd/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/set_motd/preparation/task.py94
-rw-r--r--kpov_judge/tasks/set_motd_egotrip/evaluation/task.py120
-rw-r--r--kpov_judge/tasks/set_motd_egotrip/lecture/ideja.txt1
-rw-r--r--kpov_judge/tasks/set_motd_egotrip/preparation/task.py2
-rw-r--r--kpov_judge/tasks/snmp/evaluation/task.py124
-rw-r--r--kpov_judge/tasks/snmp/lecture/ideja.txt2
-rw-r--r--kpov_judge/tasks/snmp/preparation/task.py104
-rw-r--r--kpov_judge/web/kpov.wsgi1
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py214
l---------kpov_judge/web/kpov_judge/settings.py1
-rw-r--r--kpov_judge/web/kpov_judge/templates/index.html17
-rw-r--r--kpov_judge/web/kpov_judge/templates/task.html35
88 files changed, 5025 insertions, 0 deletions
diff --git a/kpov_judge/add_assignment.py b/kpov_judge/add_assignment.py
new file mode 100755
index 0000000..2453eeb
--- /dev/null
+++ b/kpov_judge/add_assignment.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import pymongo
+from bson.son import SON
+import sys
+import inspect
+import kpov_random_helpers
+import settings
+import guestfs
+import glob
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ print "Usage: {0} task_name task_source.py"
+ print "The task_source should contain two functions - task(param1, param2, ...) and task_check(res, params)"
+ task_id = sys.argv[1]
+ fname = sys.argv[2]
+ db = pymongo.Connection(settings.DB_HOST).kpov
+ try:
+ db.authenticate(settings.USERNAME, settings.PASSWORD)
+ except Exception, e:
+ print "Not authenticated:"+str(e)
+ #no auth or auth config?
+ source = open(fname).read()
+ code = compile(source, fname, 'exec')
+ # the following line creates:
+ # task, task_check, gen_params, prepare_disks, computers, params_meta.
+ exec(code)
+ task_source = inspect.getsource(task)
+ task_check_source = inspect.getsource(task_check)
+ gen_params_source = inspect.getsource(gen_params)
+ prepare_disks_source = inspect.getsource(prepare_disks)
+ x = params_meta.keys() # check for existence
+ db.computers_meta.remove({'task_id': task_id})
+ auto_networks = set([None])
+ for k, v in computers.iteritems():
+ for n in v.get('networks_interfaces', []):
+ auto_networks.add(n.get('network', None))
+ db.computers_meta.update({'task_id': task_id, 'name': k}, {'$set': v}, upsert=True)
+ auto_networks.remove(None)
+ db.networks.remove({'task_id': task_id})
+ try:
+ net_list = networks.iteritems()
+ except:
+ net_list = [(k, {'public': False}) for k in auto_networks]
+ for k, v in net_list:
+ db.networks.update({'task_id': task_id, 'name': k}, {'$set': v}, upsert=True)
+ db.task_checkers.update({'task_id': task_id}, {'$set': {'source': task_check_source}}, upsert=True)
+ db.tasks.update({'task_id': task_id},{'$set': {'source': task_source}}, upsert=True)
+ db.prepare_disks.update({'task_id': task_id}, {'$set': {'source': prepare_disks_source}}, upsert=True)
+ db.gen_params.update({'task_id': task_id}, {'$set': {'source': gen_params_source}}, upsert=True)
+ db.task_params_meta.update({'task_id': task_id}, {'$set': {'params': params_meta}}, upsert=True)
+
diff --git a/kpov_judge/create_disk_images.py b/kpov_judge/create_disk_images.py
new file mode 100755
index 0000000..168aa5a
--- /dev/null
+++ b/kpov_judge/create_disk_images.py
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import pymongo
+import sys
+import inspect
+import kpov_random_helpers
+import settings
+import guestfs
+import os
+import glob
+import subprocess
+import fcntl
+
+def get_prepare_disks(db, task_id):
+ prepare_disks_source = db.prepare_disks.find_one({'task_id':task_id})['source']
+ prepare_disks_code = compile(prepare_disks_source, 'prepare_disks.py', 'exec')
+ exec(prepare_disks_code)
+ return prepare_disks
+
+def create_snapshot(task_id, student_id, disk_name, overwrite = True, cow = False):
+ print(os.path.join(settings.DISK_TEMPLATE_PATH, task_id, disk_name) + '.*')
+ template_paths = glob.glob(os.path.join(settings.DISK_TEMPLATE_PATH, task_id, disk_name) + '.*')
+ filtered_paths = filter((lambda x: os.path.splitext(x)[1] == '.' + settings.STUDENT_DISK_FORMAT), template_paths)
+ if filtered_paths:
+ template_path = filtered_paths[0]
+ else:
+ template_path = template_paths[0]
+ if cow:
+ d = os.path.join(student_id, task_id, disk_name) + os.path.splitext(template_path)[1]
+ else:
+ d = os.path.join(student_id, task_id, disk_name) + '.qcow2'
+ try:
+ os.makedirs(os.path.join(settings.STUDENT_DISK_PATH, student_id, task_id))
+ except:
+ pass
+ disk_file = os.path.join(settings.STUDENT_DISK_PATH, d)
+ if overwrite or not os.path.exists(disk_file):
+ if cow:
+ subprocess.call(['cp', '--reflink=always', template_path, disk_file])
+ else:
+ subprocess.call(['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file=' + template_path,
+ disk_file])
+ return d
+
+def publish_snapshot(d):
+ if os.path.splitext(d)[1][1:] != settings.STUDENT_DISK_FORMAT:
+ snap_name = os.path.splitext(d)[0] + '.' + settings.STUDENT_DISK_FORMAT
+ disk_file = os.path.join(settings.STUDENT_DISK_PATH, d)
+ snap_file = os.path.join(settings.STUDENT_DISK_PATH, snap_name)
+ subprocess.call(['qemu-img', 'convert', '-f', 'qcow2', '-O', settings.STUDENT_DISK_FORMAT, disk_file,
+ snap_file])
+ url = settings.STUDENT_DISK_URL + snap_name
+ else:
+ url = settings.STUDENT_DISK_URL + d
+ return url
+
+if __name__ == '__main__':
+ if len(sys.argv) != 1:
+ print "Usage: {0}"
+ print "Create the neccessarry disk images"
+ db = pymongo.Connection(settings.DB_HOST).kpov
+ try:
+ db.authenticate(settings.USERNAME, settings.PASSWORD)
+ except Exception, e:
+ print str(e)
+ dev_prefix = settings.GUESTFS_DEV_PREFIX
+ l = db.student_computers.find({"disk_urls": {"$exists": False}})
+ computers_by_task_student = dict()
+ for computer in l:
+ student_id, task_id = computer['student_id'], computer['task_id']
+ if (task_id, student_id) not in computers_by_task_student:
+ computers_by_task_student[(task_id, student_id)] = list()
+ computers_by_task_student[(task_id, student_id)].append(computer)
+ for (task_id, student_id), computers in computers_by_task_student.iteritems():
+ l = db.student_computers.find_one({'task_id': task_id, 'student_id':student_id, "disk_urls": {"$exists": False}})
+ if l is None:
+ continue
+ lock_file = os.path.join(settings.STUDENT_LOCKFILE_PATH,
+ '{0}-{1}.lock'.format(student_id, task_id))
+ lock_fp = open(lock_file, 'w')
+ try:
+ fcntl.lockf(lock_fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError:
+ continue
+ params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id})['params']
+ prepare_disks = get_prepare_disks(db, task_id)
+ # tule odpri, ustvari snapshote za vajo
+ templates = dict()
+ all_disks = dict()
+ parts = dict()
+ for computer in computers:
+ lock_fp.write('creating computer ' + computer['name'] + '\n')
+ all_disks[computer['name']] = dict()
+ manual_disks = list()
+ this_computers_disks = set()
+ try_automount = False
+ g = guestfs.GuestFS()
+ for disk in computer['disks']:
+ lock_fp.write("register " + disk['name'] + '\n')
+ snap = create_snapshot(task_id, student_id, disk['name'],
+ cow = settings.STUDENT_DISK_COW)
+ snap_file = os.path.join(settings.STUDENT_DISK_PATH, snap)
+ if 'options' in disk:
+ g.add_drive_opts(snap_file, **(disk['options']))
+ else:
+ g.add_drive(snap_file)
+ if 'parts' in disk:
+ for p in disk['parts']:
+ manual_disks.append((dev_prefix + p['dev'],
+ p['path'], p.get('options', None)))
+ else:
+ try_automount = True
+ templates[disk['name']] = g
+ all_disks[computer['name']][disk['name']] = snap
+ g.launch()
+ mounted = set()
+ if try_automount:
+ roots = g.inspect_os()
+ for root in roots:
+ mps = g.inspect_get_mountpoints(root)
+ lock_fp.write("detected:"+str(mps)+'\n')
+ for mountpoint, device in sorted(mps):
+ if mountpoint not in mounted:
+ try:
+ g.mount(device, mountpoint, )
+ lock_fp.write( 'mounted ' + device + ' on ' + mountpoint + '\n')
+ except RuntimeError as msg:
+ lock_fp.write( "%s (ignored)\n" % msg)
+ mounted.add(mountpoint)
+ for device, mountpoint, opts in manual_disks:
+ try:
+ if opts is not None:
+ g.mount_options(opts, device, mountpoint)
+ else:
+ g.mount(device, mountpoint)
+ lock_fp.write('manually mounted ' + device + " on " + mountpoint + '\n')
+ except RuntimeError as msg:
+ lock_fp.write( "%s (ignored)\n" % msg)
+ lock_fp.write("preparing disks\n")
+ prepare_disks(templates, params)
+ # pospravi za seboj.
+ lock_fp.write("unmounting\n")
+ for g in set(templates.values()):
+ g.umount_all()
+ g.close()
+ lock_fp.write("saving URLs\n")
+ for comp_name, d_dict in all_disks.iteritems():
+ disk_urls = list()
+ for d_name, d in d_dict.iteritems():
+ lock_fp.write('publishing '+ str(d) + '\n')
+ url = publish_snapshot(d)
+ lock_fp.write('published as '+ url + '\n')
+ disk_urls.append({'name': d_name, 'url': url})
+ lock_fp.write('urls: '+ str(disk_urls) + '\n')
+ l = db.student_computers.update({
+ "disk_urls": {"$exists": False},
+ 'student_id': student_id,
+ 'task_id': task_id,
+ 'name': comp_name},
+ {'$set': { 'disk_urls': disk_urls }})
+ # print "done for ", student_id, task_id
+ os.unlink(lock_file)
+ lock_fp.close()
diff --git a/kpov_judge/create_opstack.py b/kpov_judge/create_opstack.py
new file mode 100644
index 0000000..dfa5311
--- /dev/null
+++ b/kpov_judge/create_opstack.py
@@ -0,0 +1,118 @@
+import keystoneclient.v2_0.client as ksclient
+import quantumclient.quantum.client as qclient
+import novaclient.client as nclient
+import settings
+import pymongo
+import sys
+import os
+import fcntl
+
+##########################################################
+
+def create_network(qc, network_name, tenant_name):
+ net = {'name': network_name, 'admin_state_up': True, 'tenant_id': getattr(kc.tenants.find(name=tenant_name), 'id')}
+ network = qc.create_network({'network': net})
+ sub = {'name': network_name + "-subnet", 'cidr': '0.0.0.0/24', 'network_id': network['network']['id'], 'ip_version': 4, 'enable_dhcp': False, 'gateway_ip': None}
+ subnet = qc.create_subnet({'subnet': sub})
+ return network
+
+def get_nova_client(tenant_name):
+ return nclient.Client("1.1", username=settings.OS_ADMIN_USER, api_key=settings.OS_ADMIN_PASS, auth_url=settings.OS_AUTH_URL, project_id=tenant_name)
+
+def get_quantum_client(tenant_name):
+ kcsub = ksclient.Client(auth_url=settings.OS_AUTH_URL, username=settings.OS_ADMIN_USER, password=settings.OS_ADMIN_PASS, tenant_name=tenant_name)
+ client = qclient.Client('2.0', endpoint_url=settings.OS_QUANTUM_URL, token=kcsub.auth_token)
+ client.format = 'json'
+ return client
+
+
+##########################################################
+def main():
+ kc = ksclient.Client(endpoint=settings.OS_ADMIN_AUTH_URL, token=settings.OS_ADMIN_TOKEN)
+ admin_role = kc.roles.find(name='admin')
+ member_role = kc.roles.find(name='Member')
+
+ db = pymongo.Connection(settings.DB_HOST).kpov
+ try:
+ db.authenticate(settings.USERNAME, settings.PASSWORD)
+ except Exception, e:
+ print str(e)
+ #no auth or auth config?
+
+ l = db.student_tasks.find({'create_openstack': True})
+ projects = list()
+ for project in l:
+ task_id, student_id = project['task_id'], project['student_id']
+ if (task_id, student_id) not in projects:
+ projects.append((task_id, student_id))
+ #projects = [ ('01.predvaja','at9036@student.uni-lj.si'), ('01.predvaja', 'andrejtolic@fri1.uni-lj.si') ]
+ for task_id, student_id in projects:
+ l = db.student_tasks.find_one({'task_id': task_id, 'student_id': student_id, "create_openstack": True})
+ if l is None:
+ continue
+ lock_file = os.path.join(settings.OS_LOCKFILE_PATH, '{0}-{1}.lock'.format(student_id, task_id))
+ lock_fp = open(lock_file, 'w')
+ try:
+ fcntl.lockf(lock_fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError:
+ continue
+ # Ustvarimo projekt
+ project_name = "{0}-{1}".format(student_id, task_id)
+ project = kc.tenants.create(tenant_name=project_name)
+ lock_fp.write("Created project {0}.\n".format(project_name))
+ # Dodamo admin uporabnika v projekt
+ kc.roles.add_user_role(kc.users.find(name='admin'), admin_role, project)
+ lock_fp.write("Added user admin to project {0}.\n".format(project_name))
+ # Ustvarimo L2 omrezja
+ qc = get_quantum_client(tenant_name=project_name)
+ network_list = db.networks.find({'task_id': task_id})
+ nets = {}
+ for n in network_list:
+ net = create_network(qc, network_name=n['name'], tenant_name=project_name)
+ lock_fp.write("Created network {0}.".format(n['name']))
+ nets[n['name']] = {'net-id': net['network']['id']}
+ db.student_networks.update({'task_id': task_id, 'student_id': student_id, 'name': n['name']}, {'$set': {'network_id': net['network']['id'], 'public': n['public']}}, upsert=True)
+ #Ustvarimo instance
+ instance_list = db.computers_meta.find({'task_id': task_id})
+ nc = get_nova_client(tenant_name=project_name)
+ first_instance_in_project = True
+ for inst in instance_list:
+ image = nc.images.find(name=inst['image'])
+ flavor = nc.flavors.find(name=inst['flavor'])
+ instance_nets = [nets[iface['network']] for iface in inst['network_interfaces']]
+ if inst['config_drive']:
+ if 'string' in inst['userdata'].keys():
+ udata = inst['userdata']['string']
+ elif 'file' in inst['userdata'].keys():
+ try:
+ udata = open(inst['userdata']['file'], 'r')
+ except:
+ udata = None
+ lock_fp.write("Problem reading file {0} for config drive. Using None instead.".format(inst['userdata']['file']))
+ else:
+ udata = None
+ if first_instance_in_project:
+ scheduler_hints = None
+ first_instance_in_project = False
+ else:
+ s = db.student_computers.find_one({'task_id': task_id, 'student_id': student_id, 'name': inst['name']})
+ # Value corresponding to the 'same_host' key is a list (with just one element)
+ # of instances besides which to put the new instance.
+ scheduler_hints = {'same_host': [s['openstack_instance_id']] }
+ instance = nc.servers.create(name=project_name + "-" + inst['name'], image=image, flavor=flavor, nics=instance_nets, config_drive=inst['config_drive'], userdata=udata, scheduler_hints=scheduler_hints)
+ lock_fp.write("Created instance for computer {0}.".format(inst['name']))
+ # Write openstack instance id to mongo.
+ db.student_computers.update({'task_id': task_id, 'student_id': student_id, 'name': inst['name']}, {'$set': {'openstack_instance_id': instance['id'], 'openstack_host': instance['OS-EXT-SRV-ATTR:host'], 'openstack_finalized': False}, upsert=True)
+ # instance['status'] lahko BUILD, ACTIVE ali SHUTOFF
+ # instance = nova.servers.get(instance['id'])
+ db.student_tasks.update({'task_id': task_id, 'student_id': student_id}, {'$set': {'create_openstack': False, 'openstack_created': True}})
+ os.unlink(lock_file)
+ lock_fp.close()
+
+ # TODO v loceni skripti.
+ # povezi test-net na brarbiters, po izklopu instanc guestfs nad diski in create_image.
+ # Dodamo studenta v projekt
+ kc.roles.add_user_role(kc.users.find(name=student_id), member_role, project)
+
+if __name__ == '__main__':
+ main()
diff --git a/kpov_judge/finalize_opstack.py b/kpov_judge/finalize_opstack.py
new file mode 100644
index 0000000..f09ac5e
--- /dev/null
+++ b/kpov_judge/finalize_opstack.py
@@ -0,0 +1,122 @@
+import keystoneclient.v2_0.client as ksclient
+import quantumclient.quantum.client as qclient
+import novaclient.client as nclient
+import settings
+import pymongo
+import sys
+import os
+import fcntl
+
+##########################################################
+def create_project(project_name):
+ return kc.tenants.create(tenant_name=project_name)
+
+def get_project_by_name(project_name):
+ return kc.users.find(name=username)
+
+def get_user_by_name(username):
+ return kc.users.find(name=username)
+
+def create_network(network_name, tenant_name):
+ net = {'name': network_name, 'admin_state_up': True, 'tenant_id': getattr(kc.tenants.find(name=tenant_name), 'id')}
+ network = qc.create_network({'network': net})
+ sub = {'name': network_name + "-subnet", 'cidr': '0.0.0.0/24', 'network_id': network['network']['id'], 'ip_version': 4, 'enable_dhcp': False, 'gateway_ip': None}
+ subnet = qc.create_subnet({'subnet': sub})
+ return network
+
+def get_nova_client(tenant_name):
+ return nclient.Client("1.1", username=settings.OS_ADMIN_USER, api_key=settings.OS_ADMIN_PASS, auth_url=settings.OS_AUTH_URL, project_id=tenant_name)
+
+def get_quantum_client(tenant_name):
+ kcsub = ksclient.Client(auth_url=settings.OS_AUTH_URL, username=settings.OS_ADMIN_USER, password=settings.OS_ADMIN_PASS, tenant_name=tenant_name)
+ client = qclient.Client('2.0', endpoint_url=settings.OS_QUANTUM_URL, token=kcsub.auth_token)
+ client.format = 'json'
+ return client
+
+##########################################################
+
+kc = ksclient.Client(endpoint=settings.OS_ADMIN_AUTH_URL, token=settings.OS_ADMIN_TOKEN)
+member_role = kc.roles.find(name='Member')
+
+db = pymongo.Connection(settings.DB_HOST).kpov
+try:
+ db.authenticate(settings.USERNAME, settings.PASSWORD)
+except Exception, e:
+ print str(e)
+ #no auth or auth config?
+
+l = db.student_tasks.find({'create_openstack': True})
+projects = list()
+for project in l:
+ task_id, student_id = project['task_id'], project['student_id']
+ if (task_id, student_id) not in projects:
+ projects.append((task_id, student_id))
+#projects = [ ('01.predvaja','at9036@student.uni-lj.si'), ('01.predvaja', 'andrejtolic@fri1.uni-lj.si') ]
+for task_id, student_id in projects:
+ l = db.student_tasks.find_one({'task_id': task_id, 'student_id': student_id, "create_openstack": True})
+ if l is None:
+ continue
+ lock_file = os.path.join(settings.OS_LOCKFILE_PATH, '{0}-{1}.lock'.format(student_id, task_id))
+ lock_fp = open(lock_file, 'w')
+ try:
+ fcntl.lockf(lock_fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError:
+ continue
+ # Ustvarimo projekt
+ project_name = "{0}-{1}".format(student_id, task_id)
+ project = create_project(project_name=project_name)
+ lock_fp.write("Created project {0}.\n".format(project_name))
+ # Dodamo admin uporabnika v projekt
+ kc.roles.add_user_role(get_user_by_name('admin'), admin_role, project)
+ lock_fp.write("Added user admin to project {0}.\n".format(project_name))
+ # Ustvarimo L2 omrezja
+ qc = get_quantum_client(tenant_name=project_name)
+ network_list = db.networks.find({'task_id': task_id})
+ nets = []
+ for n in network_list:
+ net = create_network(network_name=n['name'], tenant_name=project_name)
+ lock_fp.write("Created network {0}.".format(n['name']))
+ nets.append( (n['name'], {'net-id': net['network']['id']}) )
+ db.student_networks.update({'task_id': task_id, 'student_id': student_id, 'name': n['name']}, {'$set': {'network_id': net['network']['id'], 'public': n['public']}}, upsert=True)
+ #Ustvarimo instance
+ instance_list = db.computers_meta.find({'task_id': task_id})
+ nc = get_nova_client(tenant_name=project_name)
+ first_instance_in_project = True
+ for inst in instance_list:
+ image = nc.images.find(name=inst['image'])
+ flavor = nc.flavors.find(name=inst['flavor'])
+ instance_net_names = inst['networks']
+ instance_nets = [net[1] for net in nets if net[0] in instance_net_names]
+ if inst['config_drive']:
+ if 'string' in inst['userdata'].keys():
+ udata = inst['userdata']['string']
+ elif 'file' in inst['userdata'].keys():
+ try:
+ udata = open(inst['userdata']['file'], 'r')
+ except:
+ udata = None
+ lock_fp.write("Problem reading file {0} for config drive. Using None instead.".format(inst['userdata']['file']))
+ else:
+ udata = None
+ if first_instance_in_project:
+ scheduler_hints = None
+ first_instance_in_project = False
+ else:
+ s = db.student_computers.find_one({'task_id': task_id, 'student_id': student_id, 'name': inst['name']})
+ # Value corresponding to the 'same_host' key is a list (with just one element)
+ # of instances besides which to put the new instance.
+ scheduler_hints = {'same_host': [s['openstack_instance_id']] }
+ instance = nc.servers.create(name=project_name + "-" + inst['name'], image=image, flavor=flavor, nics=instance_nets, config_drive=inst['config_drive'], userdata=udata, scheduler_hints=scheduler_hints)
+ lock_fp.write("Created instance for computer {0}.".format(inst['name']))
+ # Write openstack instance id to mongo.
+ db.student_computers.update({'task_id': task_id, 'student_id': student_id, 'name': inst['name']}, {'$set': {'openstack_instance_id': instance['id'], 'openstack_host': instance['OS-EXT-SRV-ATTR:host'], 'openstack_finalized': False}, upsert=True)
+ # instance['status'] lahko BUILD, ACTIVE ali SHUTOFF
+ # instance = nova.servers.get(instance['id'])
+ db.student_tasks.update({'task_id': task_id, 'student_id': student_id}, {'$set': {'create_openstack': False, 'openstack_created': True}})
+ os.unlink(lock_file)
+ lock_fp.close()
+
+# TODO v loceni skripti.
+# povezi test-net na brarbiters, po izklopu instanc guestfs nad diski in create_image.
+# Dodamo studenta v projekt
+kc.roles.add_user_role(get_user_by_name(student_id), member_role, project)
diff --git a/kpov_judge/kpov_random_helpers.py b/kpov_judge/kpov_random_helpers.py
new file mode 100755
index 0000000..775bd69
--- /dev/null
+++ b/kpov_judge/kpov_random_helpers.py
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import random
+import string
+import socket
+import struct
+import math
+import re
+import subprocess
+import glob
+
+def alnum_gen(r, l=1):
+ s = u""
+ for i in xrange(l):
+ s += random.choice(string.ascii_letters + string.digits)
+ return s
+
+def fortune(r, max_len):
+ all_fortunes = []
+ for fortune_file in glob.glob('/usr/share/games/fortunes/*.u8'):
+ f = open(fortune_file)
+ l = f.read().split('\n%\n')[:-1]
+ for i in l:
+ if len(i) < max_len:
+ all_fortunes.append(i)
+ return re.sub(r'\s+', ' ', r.choice(all_fortunes)).strip()
+
+def _net_to_int(s):
+ try:
+ net, subnet = s.split('/')
+ except ValueError:
+ subnet = '32'
+ try:
+ subnet_int = int(subnet)
+ except ValueError:
+ subnet_bytes = struct.unpack('>I', socket.inet_aton(subnet))[0]
+ max_bit = 1 << 31
+ subnet_int = 0
+ while (subnet_bytes & max_bit) > 0:
+ subnet_int += 1
+ max_bit >>= 1
+ return struct.unpack('>I', socket.inet_aton(net))[0], subnet_int
+
+def IPv4_subnet_gen(r, base_net, mask = 24):
+ base_addr, base_subnet = _net_to_int(base_net)
+ a = r.randint(1, 1 << mask - base_subnet) << (32 - mask)
+ if a >= 1<<32:
+ a = 0
+ net_addr = base_addr | a
+ return socket.inet_ntoa(struct.pack('>I', net_addr)) + '/{0}'.format(mask)
+
+def IPv4_net_gen(r, min_hosts=254, local=True, multicast=False):
+ mask = 32 - int(math.ceil(math.log(min_hosts, 2)))
+ if local and not multicast:
+ net = r.choice([
+ "192.168.0.0/16",
+ '10.0.0.0/8',
+ '172.16.0.0/12'])
+ if multicast:
+ if local:
+ net = "239.0.0.0/8"
+ else:
+ net = "224.0.0.0/4"
+ return IPv4_subnet_gen(r, net, mask)
+
+def IPv4_addr_gen(r, network, n_generated=1):
+ net, mask = _net_to_int(network)
+ hosts = []
+ l = random.sample(xrange(1, 2**(32 - mask)-1), n_generated)
+ for i in l:
+ hosts.append(socket.inet_ntoa(struct.pack('>I', net | i)))
+ return hosts
+
+common_file_extensions = ['jpg', 'png', 'txt', 'doc', 'cfg', 'pdf', 'odt', 'cpp', 'c', 'sh', 'java']
+def fname_gen(r, extension = True):
+ s = alnum_gen(r, 8)
+ if extension:
+ s += '.' + r.choice(common_file_extensions)
+ return s
+
+with open('random_data/greek_gods.txt') as f:
+ greek_gods = [i.strip() for i in f.readlines()]
+with open('random_data/roman_gods.txt') as f:
+ roman_gods = [i.strip() for i in f.readlines()]
+with open('random_data/slavic_gods.txt') as f:
+ slavic_gods = [i.strip() for i in f.readlines()]
+
+gods = greek_gods + roman_gods + slavic_gods
+
+def hostname_gen(r):
+ return "{0}-{1:02}".format(r.choice(gods), r.randint(1, 99))
+
+with open('random_data/slovenian_names.txt') as f:
+ names = [i.strip() for i in f.readlines()]
+
+with open('random_data/slovenian_surnames.txt') as f:
+ surnames = [i.strip() for i in f.readlines()]
+
+def username_gen(r):
+ return r.choice(names) + r.choice(surnames) + "{0}".format(r.randint(1, 99))
+
+default_generators = {
+ 'IP': lambda r: IPv4_addr_gen(r, IPv4_net_gen(r))[0],
+ 'localnet': lambda r: IPv4_net_gen(r, min_hosts = r.randint(16, 250), local=True, multicast=False),
+ 'filename': fname_gen,
+ 'dirname': lambda r: fname_gen(r, extension = False),
+ 'username': username_gen,
+ 'password': lambda r: alnum_gen(r, 8),
+ 'short_text': lambda r: fortune(r, 40),
+ 'hostname': lambda r: hostname_gen(r),
+ None: lambda r: alnum_gen(r, 8),
+}
+
+def default_gen(userID, param_meta):
+ r = random.Random(userID)
+ params = dict()
+ for name, meta in param_meta.iteritems():
+ if meta.get('generated', False):
+ params[name] = default_generators[meta.get('type', None)](r)
+ return params
+
+if __name__ == '__main__':
+ r = random.Random()
+ for k, v in default_generators.iteritems():
+ print "---", k, "---"
+ print v(r)
diff --git a/kpov_judge/random_data/greek_gods.txt b/kpov_judge/random_data/greek_gods.txt
new file mode 100644
index 0000000..33150aa
--- /dev/null
+++ b/kpov_judge/random_data/greek_gods.txt
@@ -0,0 +1,488 @@
+aceso
+achelois
+achelous
+acheron
+achlys
+achos
+acis
+acmon
+acratopotes
+actaeus
+adephagia
+adikia
+adonis
+adrastea
+adrasteia
+aegaeon
+aegle
+aello
+aeolus
+aergia
+aether
+aetna
+agdistis
+aglaea
+aglaope
+agon
+agrius
+aiakos
+aidos
+aisa
+aitnaios
+akmon
+akte
+alala
+alastor
+alcyone
+alcyoneus
+alecto
+alectrona
+aletheia
+alexiares
+alke
+alkon
+aloadae
+alpheus
+amechania
+amphiaraus
+amphictyonis
+amphitrite
+anaideia
+anatole
+anemoi
+angelia
+angelos
+ania
+antaeus
+anteros
+antheia
+anthousai
+aoide
+aparctias
+apate
+aphaea
+apheleia
+apheliotes
+aphroditus
+aphros
+apollo
+apollonis
+aporia
+arche
+arete
+arethusa
+arges
+argestes
+argus
+argyron
+aristaeus
+arke
+arktos
+artemis
+asbetos
+asbolus
+asclepius
+askalaphos
+asopus
+astraea
+astraios
+atabyrius
+atropos
+attis
+auge
+aura
+aurai
+auxesia
+auxo
+benthesikyme
+beroe
+bia
+boreas
+borysthenis
+briareus
+britomartis
+brizo
+brontes
+bythos
+cabeiri
+caerus
+caicias
+calleis
+calliope
+calypso
+carmanor
+carme
+celaeno
+centaurs
+cephisso
+ceraon
+cerberus
+ceto
+chalcon
+chaos
+chariclo
+charites
+charon
+charybdis
+cheimon
+chione
+chiron
+chloris
+chryson
+chrysothemis
+chrysus
+circe
+circios
+cladeus
+cleta
+clio
+clotho
+clytie
+cocytus
+companions
+comus
+corus
+corymbus
+cottus
+cronus
+cyamites
+cybele
+cyclopes
+cyllenus
+cymopoleia
+daemones
+damnameneus
+damneus
+damon
+daphne
+deimos
+deino
+deipneus
+delas
+delphin
+demeter
+despoina
+dexithea
+dikaiosyne
+dike
+dionysus
+dolos
+dryades
+dysis
+dysnomia
+dyssebeia
+echo
+eiar
+eidothea
+eidyia
+eileithyia
+eirene
+eiresione
+ekecheiria
+electra
+eleos
+elete
+elpis
+empusa
+enceladus
+enyalius
+enyo
+eos
+eosphorus
+ephialtes
+epiales
+epimedes
+epimeliades
+epione
+epiphron
+erato
+erebos
+eris
+eros
+ersa
+eucleia
+eudaimonia
+eulabeia
+eunomia
+eunostus
+eupheme
+euphrosyne
+euporie
+eupraxia
+euronotus
+eurotas
+eurus
+euryale
+eurymedon
+eurytion
+eusebeia
+euterpe
+euthenia
+euthymia
+gaia
+galene
+gelos
+geras
+geryon
+glaucus
+gorgons
+gorgyra
+gyges
+gymnastika
+hamadryades
+harmonia
+harpocrates
+hebe
+hecate
+hecaterus
+hedone
+hedylogos
+hegemone
+heimarmene
+hekaerge
+helios
+hemera
+hephaestus
+hera
+heracles
+hermaphroditus
+hermes
+hesperis
+hesperus
+hestia
+himerope
+himeros
+hippocampi
+homados
+homonoia
+horkos
+horme
+hybris
+hydros
+hygieia
+hymenaios
+hypate
+hypnos
+iasios
+iaso
+ichnaea
+idaios
+ioke
+iris
+iynx
+judges
+kakia
+kalokagathia
+karkinos
+karpo
+kelmis
+keuthonymos
+koalemos
+kokytos
+korybantes
+kratos
+krotos
+kydoimos
+kyrbas
+lachesis
+ladon
+lamia
+lampades
+lethe
+leucosia
+leucothea
+ligeia
+limos
+lips
+loxo
+lupe
+lycos
+lysagora
+lyssa
+macaria
+maenades
+maia
+makelo
+mania
+matton
+medusa
+megaera
+megalesius
+melete
+meliae
+melinoe
+melpomene
+menoetes
+merope
+mese
+mesembria
+methe
+metope
+minos
+minthe
+mneme
+molpe
+momus
+mormo
+moros
+morpheus
+mousika
+muses
+mylas
+naiades
+nemesis
+nephelai
+nereides
+nereus
+nerites
+nessus
+nete
+nicothoe
+nike
+nikon
+nomos
+notus
+nymphe
+nyx
+oceanides
+oceanus
+ocypete
+oizys
+okythoos
+olympian
+omodamos
+onnes
+oreades
+orion
+ormenos
+orphne
+orthosie
+otos
+oupis
+paidia
+palaemon
+palaestra
+palioxis
+pan
+panacea
+pandaisia
+pandia
+pannychis
+parthenope
+pasithea
+passalos
+peisinoe
+peitharchia
+peitho
+pemphredo
+peneus
+penia
+penthus
+pepromene
+persephone
+phaenna
+phaenon
+phaethon
+phantasos
+pheme
+pherousa
+philomelus
+philophrosyne
+philotes
+phlegethon
+phobetor
+phobos
+pholus
+phorcys
+phrike
+phthonus
+pistis
+plutus
+podarge
+poine
+polemos
+polyhymnia
+polymatheia
+polyphemus
+ponos
+pontos
+poros
+porphyrion
+poseidon
+potamoi
+pothos
+praxidike
+priapus
+proioxis
+prophasis
+proteus
+prymneus
+psamathe
+pthinoporon
+ptocheia
+pyroeis
+pyrrhichos
+raidne
+rhadamanthys
+rhapso
+rhea
+rivers
+sabaktes
+satyrs
+scamander
+scylla
+selene
+silenus
+simon
+skeiron
+skelmis
+skythes
+smaragos
+sophrosyne
+soter
+soteria
+sponde
+sterope
+steropes
+stheno
+stilbon
+styx
+syntribos
+talos
+tartarus
+taygete
+techne
+teles
+telesphorus
+telete
+terpsichore
+tethys
+thalassa
+thalia
+thallo
+thanatos
+thaumas
+thelchtereia
+thelxinoe
+thelxiope
+theros
+thetis
+thoosa
+thrasos
+tisiphone
+titan
+titias
+tityos
+tonnes
+triteia
+triton
+tritones
+tyche
+typhon
+urania
+uranus
+younger
+zagreus
+zelos
+zephyrus
+zeus
diff --git a/kpov_judge/random_data/roman_gods.txt b/kpov_judge/random_data/roman_gods.txt
new file mode 100644
index 0000000..dcf9cd7
--- /dev/null
+++ b/kpov_judge/random_data/roman_gods.txt
@@ -0,0 +1,184 @@
+abundantia
+acis
+aerecura
+aequitas
+aesculapius
+aeternitas
+aion
+alernus
+angerona
+angitia
+annona
+antevorta
+apollo
+arimanius
+aura
+aurora
+averruncus
+bacchus
+bellona
+bubona
+caca
+cacus
+caelus
+camenae
+cardea
+carmenta
+carmentes
+carna
+ceres
+clementia
+cloacina
+concordia
+consus
+cupid
+cura
+cybele
+decima
+devera
+diana
+disciplina
+egeria
+empanda
+epona
+falacer
+fama
+fascinus
+fauna
+faunus
+faustitas
+februus
+febris
+fecunditas
+felicitas
+ferentina
+feronia
+fides
+flora
+fornax
+fontus
+fortuna
+fufluns
+fulgora
+furrina
+genius
+gratiae
+hercules
+hermaphroditus
+honos
+hora
+indiges
+intercidona
+inuus
+inidia
+janus
+juno
+jupiter
+justitia
+juturna
+juventas
+lares
+laverna
+latona
+levana
+letum
+liber
+libera
+liberalitas
+libertas
+libitina
+lua
+lucifer
+lucina
+luna
+lupercus
+lympha
+manes
+mania
+mantus
+mars
+meditrina
+mefitis
+mellona
+mercury
+minerva
+mithras
+molae
+moneta
+mors
+morta
+murcia
+naenia
+nascio
+necessitas
+nemesis
+neptune
+nerio
+neverita
+nixi
+nona
+nox
+ops
+orcus
+palatua
+pales
+parcae
+pax
+penates
+picumnus
+picus
+pietas
+pilumnus
+pluto
+poena
+pomona
+porrima
+portunes
+postverta
+priapus
+proserpina
+providentia
+pudicitia
+querquetulanae
+quirinus
+quiritis
+robigo
+roma
+rumina
+salacia
+salus
+sancus
+saturn
+securitas
+silvanus
+somnus
+soranus
+sors
+spes
+sterquilinus
+suadela
+summanus
+tellumo
+tempestas
+terminus
+tiberinus
+tibertus
+tranquillitas
+trivia
+ubertas
+unxia
+vacuna
+vediovus
+venilia
+venti
+venus
+veritas
+verminus
+vertumnus
+vesta
+victoria
+virbius
+virtus
+volturnus
+voluptas
+vulcan
diff --git a/kpov_judge/random_data/slavic_gods.txt b/kpov_judge/random_data/slavic_gods.txt
new file mode 100644
index 0000000..bc9543c
--- /dev/null
+++ b/kpov_judge/random_data/slavic_gods.txt
@@ -0,0 +1,72 @@
+ dazbog
+ kresnik
+ jarilo
+ zemlja
+ perun
+ svarun
+ svetovid
+ triglav
+ veles
+ zarja
+ ziva
+ zora
+ belobog
+ rusalka
+ berstuk
+ crnobog
+ devana
+ dodola
+ flins
+ hors
+ karewit
+ koliada
+ kupala
+ marzanna
+ mokos
+ porenut
+ porewit
+ porvata
+ radegast
+ rod
+ rugiewit
+ stribog
+ zirnitra
+ alkonost
+ cikavac
+ zarptica
+ gamayun
+ ispolin
+ kolobok
+ raróg
+ raskovnik
+ simargl
+ sirin
+ ved
+ zmaj
+ ala
+ jagababa
+ bannik
+ bauk
+ bes
+ blud
+ bukavac
+ crt
+ jerina
+ dola
+ domovoj
+ drekavac
+ dukljan
+ kikimora
+ koscej
+ ovinnik
+ polevik
+ psoglav
+ rusalka
+ samodiva
+ skrzak
+ sudice
+ topilec
+ vampir
+ vesna
+ vila
+ povodnimoz
diff --git a/kpov_judge/random_data/slovenian_names.txt b/kpov_judge/random_data/slovenian_names.txt
new file mode 100644
index 0000000..6004e4c
--- /dev/null
+++ b/kpov_judge/random_data/slovenian_names.txt
@@ -0,0 +1,20 @@
+Franc
+Marija
+Janez
+Ana
+Anton
+Maja
+Ivan
+Irena
+Rok
+Mojca
+Andrej
+Mateja
+Marko
+Natalija
+Nik
+Ivana
+Marjan
+Nina
+Peter
+Barbara
diff --git a/kpov_judge/random_data/slovenian_surnames.txt b/kpov_judge/random_data/slovenian_surnames.txt
new file mode 100644
index 0000000..f50e952
--- /dev/null
+++ b/kpov_judge/random_data/slovenian_surnames.txt
@@ -0,0 +1,10 @@
+Novak
+Horvat
+Zmeda
+Krajnc
+Brglez
+Kolar
+Ribnikar
+Mlakar
+Vidmar
+Kos
diff --git a/kpov_judge/run_test.py b/kpov_judge/run_test.py
new file mode 100755
index 0000000..894bfe6
--- /dev/null
+++ b/kpov_judge/run_test.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import yaml
+import json
+import urllib
+import urllib2
+import dialog
+import os
+import inspect
+import sys
+
+# SERVER_URL = "http://localhost/kpov_judge/"
+SERVER_URL = "http://kpov.fri.uni-lj.si/kpov_judge/"
+TASK_URL = SERVER_URL + '{task_id}/task.py'
+PARAMS_URL = SERVER_URL + '{task_id}/params.json'
+SUBMIT_URL = SERVER_URL + '{task_id}/results.json'
+
+PARAMS_FILE = os.path.expanduser("~/.kpov_params.yaml")
+
+def get_params(params, param_names, meta, d):
+ for name in param_names:
+ m = meta.get(name, {})
+ if d is not None:
+ ret, s = d.inputbox(m.get('opis', name), init=params.get(name, ''))
+ if ret == 0 and m.get('w', False):
+ params[name] = s
+ else:
+ if name not in params:
+ raise "Missing param: {0}".format(name)
+ return params
+
+def auth_open(url, username, password):
+ password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
+# Add the username and password.
+# If we knew the realm, we could use it instead of None.
+ password_mgr.add_password(None, SERVER_URL, username, password)
+ handler = urllib2.HTTPBasicAuthHandler(password_mgr)
+# create "opener" (OpenerDirector instance)
+ opener = urllib2.build_opener(handler)
+# use the opener to fetch a URL
+# opener.open(SERVER_URL)
+# Install the opener.
+# Now all calls to urllib2.urlopen use our opener.
+ urllib2.install_opener(opener)
+
+def load_checker(request):
+ source = response.read()
+ t = compile(source, 'task.py', 'exec')
+ exec(t)
+ args_list = inspect.getargs(task.func_code)[0]
+ return task, args_list, param_meta
+
+if __name__ == '__main__':
+ try:
+ try:
+ saved_params = yaml.load(open(PARAMS_FILE))
+ except:
+ print "Missing - creating anew.", PARAMS_FILE
+ saved_params = dict()
+ if len(sys.argv) > 1 and sys.argv[1] == '-q':
+ d = None
+ else:
+ d = dialog.Dialog(dialog="dialog")
+ basic_params = {
+ # 'param_name': ('prompt', editable)
+ "student_id": {'opis':"Upor. ime:", 'w': True},
+ "student_password": {'opis':"Geslo:", 'w': True},
+ "task_id": {'opis': "Naloga:", 'w': True}}
+ saved_params = get_params(saved_params, ['student_id', 'student_password', 'task_id'], basic_params, d)
+ task_id = saved_params['task_id']
+ yaml.dump(saved_params, open(PARAMS_FILE, 'w'))
+ auth_open(SERVER_URL, saved_params['student_id'], saved_params['student_password'])
+ # get parameters
+ req = urllib2.Request(PARAMS_URL.format(**saved_params))
+ response = urllib2.urlopen(req)
+ web_params = json.load(response)
+ task_params_dict = saved_params.get('tasks', {})
+ task_params = task_params_dict.get(task_id, {})
+ saved_params['tasks'] = task_params_dict
+ task_params.update(web_params)
+ # get task source
+ req = urllib2.Request(TASK_URL.format(**saved_params))
+ response = urllib2.urlopen(req)
+ # load task_check over the net
+ task, args_list, meta = load_checker(response)
+ # get missing parameters from user
+ task_params = get_params(task_params, args_list, meta, d)
+ # save
+ # run checker
+ valid_task_params = dict()
+ for i in args_list:
+ valid_task_params[i] = task_params[i]
+ saved_params['tasks'][task_id] = valid_task_params
+ results = task(**valid_task_params)
+ data = urllib.urlencode({
+ 'results': json.dumps(results),
+ 'params': json.dumps(valid_task_params)
+ })
+ req = urllib2.Request(SUBMIT_URL.format(**saved_params), data)
+ response = urllib2.urlopen(req)
+ if d is not None:
+ d.msgbox(response.read())
+ yaml.dump(saved_params, open(PARAMS_FILE, 'w'))
+ # d.add_persistent_args([('background_title', 'KPOVv')])
+ except Exception, e:
+ yaml.dump(saved_params, open(PARAMS_FILE, 'w'))
+ print "problem!"
+ print e
diff --git a/kpov_judge/settings-example.py b/kpov_judge/settings-example.py
new file mode 100644
index 0000000..9bfde58
--- /dev/null
+++ b/kpov_judge/settings-example.py
@@ -0,0 +1,14 @@
+DEBUG=True
+
+DB_HOST='kpov.fri.uni-lj.si'
+DB_PORT=27017
+USERNAME='kpov'
+PASSWORD='SomeSuperSecretPassword'
+# SNAPSHOTS_ROOT='/home/andrejtolic/kpov/snapshots/'
+DISK_TEMPLATE_PATH = '/home/kpov/disks/templates'
+STUDENT_DISK_PATH='/home/kpov/disks/students'
+STUDENT_DISK_FORMAT='vdi'
+STUDENT_DISK_COW=False # dokler Andrej ne popravi...
+STUDENT_DISK_URL='http://my_html_server.com/kpov-disks/'
+STUDENT_LOCKFILE_PATH='/home/kpov/disks/lockfiles'
+GUESTFS_DEV_PREFIX = '/dev/vd'
diff --git a/kpov_judge/tasks/copy_rename_40_files/evaluation/task.py b/kpov_judge/tasks/copy_rename_40_files/evaluation/task.py
new file mode 100644
index 0000000..834cb2a
--- /dev/null
+++ b/kpov_judge/tasks/copy_rename_40_files/evaluation/task.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Ustvari dva navidezna računalnika. Za prvega uporabi sliko diska simpleArbiterDhcp. Na drugem računalniku
+ustvari uporabnika test z geslom test.
+Na sliki diska simpleArbiterDhcp najdeš imenik s 100 datotekami. Prekopiraj vse datoteke na drugi računalnik, v domači imenik uporabnika test.
+Spremeni vsebino datotek tako, da vse male črke spremeniš v velike. Poskrbi, da se bo s prvega računalnika (simpleArbiterDhcp) mogoče prek
+ssh prijaviti na drugi računalnik in prebrati predelane datoteke.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/copy_rename_40_files/lecture/ideja.txt b/kpov_judge/tasks/copy_rename_40_files/lecture/ideja.txt
new file mode 100644
index 0000000..1a29e34
--- /dev/null
+++ b/kpov_judge/tasks/copy_rename_40_files/lecture/ideja.txt
@@ -0,0 +1 @@
+Vprašanja/odgovori glede pristopnega kolokvija. Bashizmi. Morda window managerji.
diff --git a/kpov_judge/tasks/copy_rename_40_files/preparation/task.py b/kpov_judge/tasks/copy_rename_40_files/preparation/task.py
new file mode 100644
index 0000000..05bfd2c
--- /dev/null
+++ b/kpov_judge/tasks/copy_rename_40_files/preparation/task.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# TODO: finish this!
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Prijavi se na sistem.
+V domači mapi najdeš imenik Mapa z 20 datotekami.
+ - preimenuj vse datoteke tako, da zamenjaš minuse s podčrtaji
+ - Napiši čim krajši ukaz, ki vse datoteke iz /home/user/mapa/mojimenik premakne v /home/user/novi
+ - Napiši ukaz, ki s pomočjo ukaza grep v datoteko "mama.txt" izpiše vse navade (ne skrite) datoteke v trenutnem imeniku, ki vsebujejo niz "mama", v datoteko "napake.txt" pa izpiše vse morebitne napake (npr. to, da so nekateri objekti v trenutnem imeniku dejansko imeniki ali napačne simbolične povezave)
+ - Napiši ukaz, ki bo 5s sledil vsebini /var/log/syslog. V primeru, da se v syslogu pojavi niz "zmeda", naj program izpiše "imam ga". Poleg tega naj program med sledenjem syslog-u odšteva od 5 do 1 (vsako sekundo naj se izpiše naslednja številka.
+ - Nastavi okoljsko spremenljivko TEST, da bo imela isto vrednost kot okoljska spremenljivka USER + število okoljskih spremenljivk, ki v imenu ali vrednosti ne vsebujejo besede TEST. Primer: polz37
+
+"""
+}
+
+computers = {
+ 'malishell': {
+ 'disks': [
+ { 'name': 'malishell',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/dhcp_dns/evaluation/task.py b/kpov_judge/tasks/dhcp_dns/evaluation/task.py
new file mode 100644
index 0000000..5e443ce
--- /dev/null
+++ b/kpov_judge/tasks/dhcp_dns/evaluation/task.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Ustvari tri navidezne računalnike. Za enega (SimpleArbiter) uporabi sliko diska simpleArbiter. Na drugega (DHCP_server) postavi strežnika
+DHCP in DNS. Poskrbi, da bo preostali računalnik (DHCP_client) dobil naslov, ki ga prebereš na SimpleArbiterju. Na SimpleArbiterju preberi
+še ime in IP nekega računalnika (HOSTNAME_X in IP_X). Poskrbi, da bo DNS strežnik za HOSTNAME_X vrnil naslov IP_X.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/dhcp_dns/lecture/ideja.txt b/kpov_judge/tasks/dhcp_dns/lecture/ideja.txt
new file mode 100644
index 0000000..89f3a3a
--- /dev/null
+++ b/kpov_judge/tasks/dhcp_dns/lecture/ideja.txt
@@ -0,0 +1 @@
+Nastavi strežnik dhcp tako, da bodo računalniki v različnih skupinah dobili različna imena zagonskih datotek. Nastavi syslinux tako, da se bo ob zagonu syslinux pokazala slika.
diff --git a/kpov_judge/tasks/dhcp_dns/preparation/task.py b/kpov_judge/tasks/dhcp_dns/preparation/task.py
new file mode 100644
index 0000000..c060db6
--- /dev/null
+++ b/kpov_judge/tasks/dhcp_dns/preparation/task.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# TODO: dokoncaj!
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi štiri navidezne računalnike - simpleArbiter, DHCP_server,
+BootableClientA ter BootableClientB. Na simpleArbiter preberi naslove IP_GW, IP_DHCP,
+IP_B ter najdi datoteko A.
+
+Na DHCP_server postavi DHCP strežnik s pomočjo ISC dhcp 3 na naslovu IP_DHCP.
+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.
+"""
+}
+
+computers = {
+ 'DHCPServer': {
+ 'disks': [
+ { 'name': 'DHCPServer',
+ },
+ { 'name': 'bootable_iso',
+ 'options':{'readonly': True},
+ 'parts': [],
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ },
+ 'BootableClientA': {
+ 'disks': [
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ },
+ 'BootableClientB': {
+ 'disks': [
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_DHCP': {'opis': 'IP DHCP streznika', 'w': False, 'public': True, 'type':'IP', 'generated': True},
+ 'IP_GW': {'opis': 'IP SimpleArbiterja', 'w': False, 'public': True, 'type':'IP', 'generated': True},
+ 'MAC_BOOT': {'opis': 'MAC racunalnika, ki se zazene z ISO', 'w': True, 'public': True, 'type':'MAC', 'generated': False},
+ 'IP_BOOT': {'opis': 'IP racunalnika, ki se zazene z ISO', 'w': True, 'public': True, 'type':'IP', 'generated': False},
+ 'BOOT_FNAME': {'opis': 'Ime datoteke', 'w': False, 'public': True, 'type': 'filename', 'generated': True},
+}
+
+def task(IP_DHCP, IP_GW, MAC_BOOT, BOOT_FNAME):
+ # check the IP
+ # ping the DHCP server
+ # 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
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '10.75.0.0/10', 24)
+ params['IP_DHCP'], params['IP_GW'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['BOOT_FNAME'] = kpovRandomHelpers.filename_gen(r)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/ieee802/evaluation/task.py b/kpov_judge/tasks/ieee802/evaluation/task.py
new file mode 100644
index 0000000..a7a81d1
--- /dev/null
+++ b/kpov_judge/tasks/ieee802/evaluation/task.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Nastavi Radius strežnik. Postavi sistem za avtentikacijo s pomočjo IEEE 802.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/ieee802/lecture/ideja.txt b/kpov_judge/tasks/ieee802/lecture/ideja.txt
new file mode 100644
index 0000000..98380fc
--- /dev/null
+++ b/kpov_judge/tasks/ieee802/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Poveži se na omrežje IEEE 802 s pomočjo WPA supplicanta. Vzpostavi omrežje z avtentikacijo.
+
diff --git a/kpov_judge/tasks/ieee802/preparation/task.py b/kpov_judge/tasks/ieee802/preparation/task.py
new file mode 100644
index 0000000..29a02cd
--- /dev/null
+++ b/kpov_judge/tasks/ieee802/preparation/task.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# Poveži se na omrežje IEEE802.11 s pomočjo NetworkManagerja. Poglej ustvarjeno konfiguracijo za wpa supplicant.
+# http://oob.freeshell.org/nzwireless/intro.html
+instructions = {
+ 'si':u"""
+Poveži se na omrežje IEEE802 s pomočjo NetworkManagerja. Poglej ustvarjeno konfiguracijo za wpa supplicant.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/ldap/evaluation/task.py b/kpov_judge/tasks/ldap/evaluation/task.py
new file mode 100644
index 0000000..fee168a
--- /dev/null
+++ b/kpov_judge/tasks/ldap/evaluation/task.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Ustvari dva navidezna računalnika - SimpleArbiter z diskom simpleArbiterDhcp ter LDAPServer.
+Na LDAPServer namesti strežnik LDAP. Na SimpleArbiter preberi ime domene DOMENA,
+uporabniško ime BIND_DN ter geslo BIND_PASS. Poskrbi, da se bo lahko klient s simpleArbiterDhcp povezal na LDAP strežnik na LDAPServer.
+V primeru, da se klient poveže kot BIND_DN z geslom BIND_PASS, naj strežnik omogoči branje vseh podatkov za objekte v
+DC=DOMENA,DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si. Nato na LDAP strežniku poišči datoteko /home/test/users.txt. Vsaka vrstica
+v datoteki vsebuje uporabniško ime, ime ter priimek, ločene s tabulatorji. V bazi LDAP
+pod DC=DOMENA,DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si za vsako vrstico v users.txt ustvari svojega uporabnika.
+
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/ldap/lecture/ideja.txt b/kpov_judge/tasks/ldap/lecture/ideja.txt
new file mode 100644
index 0000000..e9647ce
--- /dev/null
+++ b/kpov_judge/tasks/ldap/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Postavi strežnik OpenLDAP. Ustvari shemo. Ustvari uporabnika. Uporabi LDAP kot backend za RADIUS.
+
diff --git a/kpov_judge/tasks/ldap/preparation/task.py b/kpov_judge/tasks/ldap/preparation/task.py
new file mode 100644
index 0000000..c123c92
--- /dev/null
+++ b/kpov_judge/tasks/ldap/preparation/task.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# Poveži se na strežnik LDAP prek spletnega vmesnika. Ustvari uporabnika z danim imenom in geslom.
+# Napiši skripto, ki izpiše podatke o tem uporabniku z ldapsearch.
+#
+# TODO: finish this!
+instructions = {
+ 'si':u"""
+Ustvari dva navidezna računalnika - SimpleArbiter z diskom simpleArbiterDhcp ter LDAPServer.
+Na LDAPServer namesti strežnik LDAP. Na SimpleArbiter preberi ime domene DOMENA, uporabniško ime USER_A, geslo PASS_A,
+uporabniško ime BIND_DN ter geslo BIND_PASS. Poskrbi, da se bo lahko klient s simpleArbiterDhcp povezal na LDAP strežnik na LDAPServer.
+V primeru, da se klient poveže kot BIND_DN z geslom BIND_PASS, naj strežnik omogoči spreminjanje podatkov za objekt
+CN=USER_A,DC=DOMENA,DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si ter ustvarjanje novih objektov v DC=DOMENA,DC=kpov,DC=lusy,DC=fri,DC=uni-lj,DC=si
+
+Na SimpleArbiter ustvari program, ki bo s pomočjo ldapsearch izpisala seznam lastnosti (otrok), ki jih ima poljuben objekt v domeni DOMENA.kpov.lusy.fri.uni-lj.si. Ime objekta (CN) naj program sprejme kot prvi argument.
+"""
+}
+
+computers = {
+ 'LDAPServer': {
+ 'disks': [
+ { 'name': 'LDAPServer',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'LDAP_USERNAME': {'opis': 'Uporabnisko ime v LDAP', 'w': False, 'public':True, 'type': 'username', 'generated': True},
+ 'LDAP_PASSWORD': {'opis': 'Geslo v LDAP', 'w': False, 'public':True, 'type': 'password', 'generated': True},
+ 'BIND_USERNAME': {'opis': 'Uporabnisko ime za dostop do LDAP', 'w': False, 'public':True, 'type': 'username', 'generated': True},
+ 'BIND_PASSWORD': {'opis': 'Geslo za dostop do LDAP', 'w': False, 'public':True, 'type': 'password', 'generated': True},
+}
+
+def task(LDAP_USERNAME, LDAP_PASSWORD, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/nat/evaluation/task.py b/kpov_judge/tasks/nat/evaluation/task.py
new file mode 100644
index 0000000..763dee4
--- /dev/null
+++ b/kpov_judge/tasks/nat/evaluation/task.py
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi dva računalnika - SimpleArbiter z diska simpleArbiter ter
+NATServer. NATServer naj ima dva omrežna vmesnika - z enim naj bo
+povezan v Internet, z drugim pa na SimpleArbiter. Poskrbi, da bo
+NATServer služil kot DHCP strežnik ter privzeti prehod za SimpleArbiter.
+Na SimpleArbiter preberi vrednosti NET, PORT_OUTER in PORT_INNER. Poskrbi, da
+bo omrežje med SimpleArbiter in NATServer na področju NET. Nato poskrbi, da se
+bo promet z Interneta na vrata PORT_OUTER prepošiljal na SimpleArbiter na vrata PORT_INNER.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/nat/lecture/ideja.txt b/kpov_judge/tasks/nat/lecture/ideja.txt
new file mode 100644
index 0000000..852ee43
--- /dev/null
+++ b/kpov_judge/tasks/nat/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Nastavi računalnik tako, da bo vse pakete za določene naslove prepošiljal na drug računalnik.
+Vzpostavi NAT.
diff --git a/kpov_judge/tasks/nat/preparation/task.py b/kpov_judge/tasks/nat/preparation/task.py
new file mode 100644
index 0000000..6fb5700
--- /dev/null
+++ b/kpov_judge/tasks/nat/preparation/task.py
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# Poglej nek film na nekem določenem URL.
+# (?md5 vsota filma?)
+
+# Nastavi nek računalnik tako, da bo izvajal NAT.
+#TODO: finish this
+
+instructions = {
+ 'si':u"""
+Postavi dva navidezna računalnika - SimpleArbiter z diskom simpleArbiter
+ter NATServer. NATServer naj ima dva omrežna vmesnika - z enim naj bo povezan
+na simpleArbiter, z drugim pa na Internet. Na simpleArbiter preberi naslov,
+na katerem si lahko ogledaš kratek filmček. Nastavi omrežje med NATServer in simpleArbiter
+tako, da bo na področju, ki ga vidiš v filmčku.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/network_boot/evaluation/task.py b/kpov_judge/tasks/network_boot/evaluation/task.py
new file mode 100644
index 0000000..8d1c308
--- /dev/null
+++ b/kpov_judge/tasks/network_boot/evaluation/task.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi tri navidezne računalnike - simpleArbiter, DHCP_server, DHCP_client.
+Na računalniku DHCP_server najdeš program A. DHCP_server nastavi tako, da se bo
+DHCP_client lahko zagnal prek mreže. Na datotečni sistem, s katerega
+se zaganja DHCP_client, spravi program A. Poskrbi, da se A požene ob zagonu DHCP_client.
+
+DHCP_client ne sme imeti priklopljenega nobenega trdega diska.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/network_boot/lecture/ideja.txt b/kpov_judge/tasks/network_boot/lecture/ideja.txt
new file mode 100644
index 0000000..a380311
--- /dev/null
+++ b/kpov_judge/tasks/network_boot/lecture/ideja.txt
@@ -0,0 +1 @@
+Zaženi računalnik. Spremeni initrd. Zaženi sistem prek NFS. Spremeni podatke v squashfs.
diff --git a/kpov_judge/tasks/network_boot/preparation/task.py b/kpov_judge/tasks/network_boot/preparation/task.py
new file mode 100644
index 0000000..8c54bf6
--- /dev/null
+++ b/kpov_judge/tasks/network_boot/preparation/task.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# TODO: dokoncaj!
+instructions = {
+ 'si':u"""
+Postavi dva navidezna računalnika (simpleArbiterDhcp in FileServer). Na SimpleArbiterDhcp poišči imenik
+Mapa ter preberi pot NFS_POT ter ime imenika v skupni rabi SAMBA_SHARE. Skopiraj datoteke iz imenika Mapa,
+na FileServer. Poskrbi, da bo imenik z datotekami dostopen prek NFS v imeniku NFS_POT in prek SMB na imeniku v skupni
+rabi SAMBA_SHARE. SimpleArbiterDhcp naj ima prek NFS pravico pisati po imeniku.
+"""
+}
+
+computers = {
+ 'FileServer': {
+ 'disks': [
+ { 'name': 'FileServer',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'SMB_NAME': {'opis': 'SMB ime streznika', 'w': False, 'public':True, 'type': 'hostname', 'generated': True},
+ 'SMB_SHARENAME': {'opis': 'Imenik v skupni rabi', 'w': False, 'public':True, 'type': 'filename', 'generated': True},
+ 'NFS_MOUNT': {'opis': 'Imenik, dostopen prek NFS', 'w': False, 'public': True, 'type': 'filename', 'generated': True},
+ 'SHARED_FILENAME': {'opis': 'Ime datoteke, ki je deljena', 'w': False, 'public': True, 'type': 'filename', 'generated': True},
+ 'SHARED_FILENAME_CONTENT': {'opis': 'Vsebina datoteke', 'w': False, 'public': True, 'type': 'filename', 'generated': True},
+}
+
+def task(SMB_NAME, NFS_MOUNT, SHARED_FILENAME, SHARED_FILENAME_CONTENT):
+ # mount the NFS mount
+ # mount the SMB mount
+ # read the filename content
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/openvpn/evaluation/task.py b/kpov_judge/tasks/openvpn/evaluation/task.py
new file mode 100644
index 0000000..679d136
--- /dev/null
+++ b/kpov_judge/tasks/openvpn/evaluation/task.py
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi 4 navidezne računalnike - SimpleArbiter z diska simpleArbiterDhcp, A, B ter C.
+Na računalnikih A, B in C ustvari uporabnika test z geslom test.
+Poskrbi, da bodo vsi štirje na istem navideznem fizičnem omrežju. Naslov omrežja (NET_PHYS) ter naslove
+(IP_A, IP_B, IP_C) preberi na SimpleArbiter. S pomočjo OpenVPN postavi navidezno omrežje med A in B na naslovih NET_VPN1.
+Nato s pomočjo OpenVPN postavi še navidezno omrežje med B in C na naslovih NET_VPN2.
+Poskrbi, da bo promet z A prek VPN prišel do C in obratno. Za avtentikacijo uporabi skupne skrivnosti, ki
+jih prebereš na SimpleArbiter - med A in B SECRET_AB ter med B in C SECRET_BC.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/openvpn/lecture/ideja.txt b/kpov_judge/tasks/openvpn/lecture/ideja.txt
new file mode 100644
index 0000000..3ae0c92
--- /dev/null
+++ b/kpov_judge/tasks/openvpn/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Namesti OpenVPN. Ustvari OpenVPN strežnik. Omogoči sosedu, da se nanj poveže.
+Ustvari javni in zasebni ključ. Omogoči več sosedom, da se povežejo na tvoj strežnik.
diff --git a/kpov_judge/tasks/openvpn/preparation/task.py b/kpov_judge/tasks/openvpn/preparation/task.py
new file mode 100644
index 0000000..2ca15fc
--- /dev/null
+++ b/kpov_judge/tasks/openvpn/preparation/task.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi dva navidezna računalnika - SimpleArbiter z diska SimpleArbiterVPN ter
+VPNClient. Na VPNClient nastavite OpenVPN klienta tako, da se bo povezal na SimpleArbiter.
+OpenVPN nastavite tako, da bosta strežnik in klient uporabila skupno skrivnost, ki jo
+preberete na SimpleArbiter. Nato poskrbite, da bo VPNClient na navideznem omrežju prek NFS omogočil
+dostop do imenika /home/test/IME_IMENIKA, pri čemer IME_IMENIKA preberite na SimpleArbiter.
+V ta imenik skopirajte datoteke, ki so prek SMB dostopne na SimpleArbiter.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/openwrt/evaluation/task.py b/kpov_judge/tasks/openwrt/evaluation/task.py
new file mode 100644
index 0000000..3326065
--- /dev/null
+++ b/kpov_judge/tasks/openwrt/evaluation/task.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi dva navidezna računalnika - simpleArbiter z diska SimpleArbiter ter
+OpenWRT z diska OpenWRT. Na disku OpenWRT je nameščena distribucija OpenWRT.
+Nastavi OpenWRT tako, da bo imel dva omrežna vmesnika - en naj bo povezan na Internet,
+drugo na omrežje, na katerem bo SimpleArbiter. Na SimpleArbiter preberi naslov omrežja
+med OpenWrt in SimpleArbiter ter njuna naslova.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/openwrt/lecture/ideja.txt b/kpov_judge/tasks/openwrt/lecture/ideja.txt
new file mode 100644
index 0000000..7e12372
--- /dev/null
+++ b/kpov_judge/tasks/openwrt/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Postavi OpenWRT na router. Usposobi predvajanje filmov na Raspberry PI.
+
diff --git a/kpov_judge/tasks/openwrt/preparation/task.py b/kpov_judge/tasks/openwrt/preparation/task.py
new file mode 100644
index 0000000..934dfe6
--- /dev/null
+++ b/kpov_judge/tasks/openwrt/preparation/task.py
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# Postavi nek film na Internet tako, da ga bodo lahko ostali videli.
+# TODO: finish this
+
+instructions = {
+ 'si':u"""
+Postavi navidezni računalnik SimpleArbiter z diska simpleArbiter.
+Na simpleArbiter preberi naslov filma ter ime toka TOK. Posnemi ali kako drugače ustvari
+film ter poskrbi, da bo film dostopen na Internetu prek RTP z imenom toka TOK. Računaj,
+da bodo film lahko videli tvoji sošolci. Kršenje avtorskih pravic je pri reševanju te naloge
+strogo prepovedano.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/radius/evaluation/task.py b/kpov_judge/tasks/radius/evaluation/task.py
new file mode 100644
index 0000000..5472d10
--- /dev/null
+++ b/kpov_judge/tasks/radius/evaluation/task.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi tri navidezne računalnike - SimpleArbiter z diska simpleArbiterDhcp,
+RadiusA ter RadiusB. Na simpleArbiterDhcp preberi imeni domen DOMENA_A ter DOMENA_B,
+uporabniški imeni USER_A in USER_B, gesli PASSWORD_A in PASSWORD_B ter skrivnosti
+SECRET_A in SECRET_B. Poskrbi, da se bo lahko radius klient s SimpleArbiter povezal
+na RadiusA s skrivnostjo SECRET_A ter na RadiusB s skrivnostjo SECRET_B. Poskrbi še,
+da bo v nastavitvah OpenRadius na RadiusA obstajal uporabnik USER_A z geslom PASSWORD_A ter
+na RadiusB uporabnik USER_B z geslom PASSWORD_B.
+
+Poskrbi, da bo strežnik RadiusA odgovarjal na zahtevke za avtentikacijo uporabnikov na domeni DOMENA_A,
+zahtevke za uporabnike na domeni DOMENA_B pa bo preposlal naprej na RadiusB. RadiusB naj odgovarja na
+zahtevke za uporabnike na domeni DOMENA_B, zahtevke za uporabnike na DOMENA_A pa naj preprosto zavrže.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/radius/lecture/ideja.txt b/kpov_judge/tasks/radius/lecture/ideja.txt
new file mode 100644
index 0000000..fd9d1a9
--- /dev/null
+++ b/kpov_judge/tasks/radius/lecture/ideja.txt
@@ -0,0 +1 @@
+Nastavi apache tako, da se boš nanj prijavila s pomočjo avtentikacije pri sosedu.
diff --git a/kpov_judge/tasks/radius/preparation/task.py b/kpov_judge/tasks/radius/preparation/task.py
new file mode 100644
index 0000000..c160464
--- /dev/null
+++ b/kpov_judge/tasks/radius/preparation/task.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Ustvari dva navidezna računalnika - SimpleArbiter z diska simpleArbiterDhcp ter
+RadiusServer. Na RadiusServer namesti OpenRadius. Na SimpleArbiter preberi ime in priimek
+uporabnika ter ga dodaj v konfiguracijo OpenRadius na RadiusServer. Na SimpleArbiter
+preberi skrivnost ter poskrbi, da se bo s to skrivnostjo SimpleArbiter lahko povezal
+na RadiusServer.
+
+Nato na OpenRadius namesti še podatkovno bazo mysql. Na SimpleArbiter preberi še ime podatkovne baze,
+uporabniško ime na bazi ter geslo, s katerim se bo lahko klient s SimpleArbiter na to bazo lahko povezal.
+Ustvari podatkovno bazo. V bazi ustvari tabelo "users" s stolpcema username ter password.
+Na RadiusServer ustvari uporabnika test. Nastavi PAM tako, da se bo geslo uporabnika primerjalo z vnosom
+v tabeli v mysql, namesto da se uporabi datoteka /etc/passwd oziroma /etc/shadow.
+"""
+}
+
+computers = {
+ 'RadiusServer': {
+ 'disks': [
+ { 'name': 'RadiusServer',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'RADIUS_SECRET':{'opis': 'Skrivnost RADIUS', 'w': False, 'public':True, 'type': 'passwd', 'generated': True},
+ 'RADIUS_USERNAME': {'opis': 'Username v RADIUS', 'w': True, 'public':True, 'type': 'username', 'generated': False},
+ 'RADIUS_PASSWORD': {'opis': 'Geslo v RADIUS', 'w': False, 'public':True, 'type': '', 'generated': True},
+ 'MYSQL_ADMIN_USER':{'opis': 'Username za dostop do MySQL', 'w': True, 'public':True, 'type': 'username', 'generated': False},
+ 'MYSQL_ADMIN_PASSWORD': {'opis': 'Geslo za dostop do MySQL', 'w': True, 'public':True, 'type': 'passwd', 'generated': True},
+ 'MYSQL_PAM_USERNAME': {'opis': 'Username v MySQL', 'w': True, 'public': True, 'type': 'IP', 'generated': False},
+ 'MYSQL_PAM_PASSWORD': {'opis': 'Geslo za uporabnika v MySQL', 'w': True, 'public': True, 'type': 'passwd', 'generated': False},
+}
+
+def task(RADIUS_SECRET, RADIUS_USERNAME, RADIUS_PASSWORD, MYSQL_ADMIN_USER, MYSQL_ADMIN_PASSWORD, MYSQL_PAM_USERNAME, MYSQL_PAM_PASSWORD):
+ results = dict()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/rdate/evaluation/task.py b/kpov_judge/tasks/rdate/evaluation/task.py
new file mode 100644
index 0000000..bd77c13
--- /dev/null
+++ b/kpov_judge/tasks/rdate/evaluation/task.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavi dva navidezna računalnika - SimpleArbiter z diska simpleArbiterDhcp ter
+RdateServer. Na RdateServer postavi strežnik, ki bo poslušal na vratih VRATA_X.
+Vsakič, ko se na vrata poveže klient, naj strežnik pošlje število sekund od DATUM_X.
+Število naj bo kodirano kot 64-bitno predznačeno število s tankim koncem.
+
+VRATA_X in DATUM_X preberi na SimpleArbiter.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/rdate/lecture/ideja.txt b/kpov_judge/tasks/rdate/lecture/ideja.txt
new file mode 100644
index 0000000..0fb111a
--- /dev/null
+++ b/kpov_judge/tasks/rdate/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Napiši svoj rdate klient. Nastavi računalnik, da bo uro sinhroniziral z NTP strežnika.
+
diff --git a/kpov_judge/tasks/rdate/preparation/TejoLicen/rServe.zip b/kpov_judge/tasks/rdate/preparation/TejoLicen/rServe.zip
new file mode 100644
index 0000000..9061692
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/TejoLicen/rServe.zip
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu1.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu1.png
new file mode 100644
index 0000000..c6eeac8
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu1.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu15.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu15.png
new file mode 100644
index 0000000..c2ac808
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu15.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu2.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu2.png
new file mode 100644
index 0000000..85fcfa8
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu2.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu3.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu3.png
new file mode 100644
index 0000000..831e764
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu3.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu4.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu4.png
new file mode 100644
index 0000000..495351a
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu4.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu5.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu5.png
new file mode 100644
index 0000000..103e0e6
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu5.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu6.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu6.png
new file mode 100644
index 0000000..b032223
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu6.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu7.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu7.png
new file mode 100644
index 0000000..bd50500
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu7.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu8.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu8.png
new file mode 100644
index 0000000..98f7812
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu8.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/bu9.png b/kpov_judge/tasks/rdate/preparation/howtos/images/bu9.png
new file mode 100644
index 0000000..9ed78ce
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/bu9.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/predvaja_clip_image003.gif b/kpov_judge/tasks/rdate/preparation/howtos/images/predvaja_clip_image003.gif
new file mode 100644
index 0000000..02be389
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/predvaja_clip_image003.gif
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/s1.png b/kpov_judge/tasks/rdate/preparation/howtos/images/s1.png
new file mode 100644
index 0000000..52b6ee5
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/s1.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/s2.png b/kpov_judge/tasks/rdate/preparation/howtos/images/s2.png
new file mode 100644
index 0000000..78a65ce
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/s2.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/images/s3.png b/kpov_judge/tasks/rdate/preparation/howtos/images/s3.png
new file mode 100644
index 0000000..c32eae1
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/images/s3.png
Binary files differ
diff --git a/kpov_judge/tasks/rdate/preparation/howtos/si/index.html b/kpov_judge/tasks/rdate/preparation/howtos/si/index.html
new file mode 100644
index 0000000..a22f5c2
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/howtos/si/index.html
@@ -0,0 +1,57 @@
+<html>
+
+<head>
+<meta http-equiv=Content-Type content="text/html; charset=windows-1250">
+</head>
+
+<body><font face="Georgia, Times New Roman, Times, serif">
+<strong><h1>XX. predvaja:</h1></strong><br>
+<p><strong><h2>Naloga na hitro:</h2></strong><br>
+ Nastavi uro na streniku s pomojo rdate. Napii program, ki pretvori 24-bitna tevila z dvojikim komplementom v decimalno obliko.</p>
+<p><strong><h2>Navodila:</h2></strong><br>
+ 1. Iz imenika s slikami virtualnih raunalnikov povlecite sliki Student.vdi(klient) in SimpleArbiter.vdi(strenik).<br>
+ 2. Z VirtualBoxom (ali ostalim programom za virtualne raunalnike) ustvarite dva virtualna raunalnika in jim kot disk za shranjevanje podajte Student.vdi ter SimpleArbiter.vdi.<br>
+ 3. Zaenite oba navidezna raunalnika.<br>
+ 4. Na Student se prijavite z uporabnikom <strong>root</strong> in geslom <strong>kaboom</strong> na SimpleArbiter pa z uporabnikom <strong>tester</strong> in geslom <strong>SedemKrogovPekla</strong>.</p>
+<img src="slike/bu15.png"> <img src="slike/bu1.png">
+<p><h3><u><strong><em>Prvi del naloge: posodobi uro raunalnika s pomojo rdate.</em></strong></u></h3><br>
+ 1. Preverite in si zapiite IP naslov na SimpleArbiter. (ifconfig)<br><img src="slike/bu2.png"><br><img src="slike/bu3.png"><br>
+ 2. Z ukazom <strong>sudo apt-get install</strong> rdate namestimo program rdate.<br>
+ 3. Na Student z pomojo rdate posodobi uro raunalnika. <strong>rdate IP_SIMPLE_ARBITER</strong><br><img src="slike/bu4.png"><br>
+ Opozorilo: NI napaka, e se posodobljen as ne ujema s pravilnim asom. <br>
+ </p>
+<p><br>
+ <u><strong><em><h3>Drugi del naloge: napii program, ki pretvori binarni zapis 32-bitnega tevila v decimalnega.</h3></em></strong></u><br>
+ Nalogo lahko reite v Javi ali v Pythonu. Prav tako pa lahko kodo piete v poljubnem tekstovnem urejevalniku.</p>
+<p><br>
+ JAVA------<br>
+ 1. Z ukazom nano bintodec3.java ustvarimo in odpremo prazen program s tekstovnim urejevalnikom nano<br>
+ 2. Napiemo program za pretvarjanje 24-bitnega tevila z dvojikim komplementom v decimalno obliko<br>
+<img src="slike/bu6.png"><br><img src="slike/bu7.png"><br>
+ 3. Pritisnemo Ctrl+X, nato Y in Enter, da program zapremo in shranimo.<br>
+ 4. e je e nimamo, naloimo Javo <strong>sudo apt-get install openjdk-6-jdk</strong><br><img src="slike/predvaja_clip_image003.gif"><br>
+ 5. Prevedemo program <strong>javac bintodec3.java</strong><br>
+ 6. Lahko ga e zaenemo ter preizkusimo <strong>java bintodec3</strong>. Na standardni vhod vnaamo 24-bitno tevilo v estnajstiki obliki<br><img src="slike/bu9.png"><br></p>
+<p>PYTHON------<br>
+ 1. Z ukazom nano bintodec3.py ustvarimo in odpremo prazen program s tekstovnim urejevalnikom nano<br>
+ 2. Napiemo program za pretvarjanje 24-bitnega tevila z dvojikim komplementom v decimalno obliko<br>
+<img src="slike/bu5.png"><br>
+ 3. Pritisnemo Ctrl+X, nato Y in Enter, da program zapremo in shranimo.<br>
+ 4. Program zaenemo z ukazom <strong>python bintodec3.py</strong><br><img src="slike/bu8.png"><br></p><br><br>
+
+
+ <p>
+ <h3> Testiranje </h3>
+ 1. Lahko poenemo tester; z ukazom ./run_test.py<br>
+ <img src="slike/s1.png"><br>
+ 2. Kot "Upor. Ime" in "Geslo" napiite vae podatke uilnice. (npr.: "pz1234@student.uni-lj.si" in "geslo123")<br>
+ <img src="slike/s2.png"> <img src="slike/s3.png"> <br>
+ 3. Kot ime naloge vpiite XX.predvaja.<br>
+ 4. Ko vas program vpraa po poti programa vnesite vao pot do programa za pretvarjanje. (npr.: e imate program bintodec3.py v isti mapi kot program run_test.py, vnesete: ./bintodec3.py)<br>
+ 5. Povpraa tudi po IP naslovu SimpleArbiterja, vnesite.<br>
+ 6. e je lo vse po srei, program vrne OK vi pa ste opravili nalogo.</p>
+
+ </font>
+</body>
+
+</html>
diff --git a/kpov_judge/tasks/rdate/preparation/task.py b/kpov_judge/tasks/rdate/preparation/task.py
new file mode 100644
index 0000000..caf6298
--- /dev/null
+++ b/kpov_judge/tasks/rdate/preparation/task.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# TODO: finish this!
+
+instructions = {
+ 'si':u"""
+Postavi dva navidezna računalnika - SimpleArbiterDhcpRdate s slike diska simpleArbiterRdate ter rdateClient.
+Na rdateClient ustvarite uporabnika test z geslom test. Nastavite čas na rdateClient tako, da kot rdate strežnik
+uporabite SimpleArbiterDhcpRdate. Nato v domačem imeniku uporabnika test spravite program z imenom guliver, ki prebere 4 byte
+podatkov s standardnega vhoda in jih pretvori v predznačeno celo število, pri čemer naj uporablja zapis z debelim koncem (big endian).
+Število naj program izpiše na standardni izhod.
+"""
+}
+
+computers = {
+ 'rdateClient': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcpRdate',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/remote_ssh/evaluation/task.py b/kpov_judge/tasks/remote_ssh/evaluation/task.py
new file mode 100644
index 0000000..0468b7d
--- /dev/null
+++ b/kpov_judge/tasks/remote_ssh/evaluation/task.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# bson.son.SON an
+# kpovRandomHelpers should be imported by add_assignment.py
+OrderedDict = SON
+
+instructions = {
+ 'si':u"""
+Ustvari dva navidezna računalnika. Za disk enega (imenujmo ga SimpleArbiter) uporabite
+sliko diska Test. Na drugega (imenujmo ga A) namesti poljubno Linux distribucijo. Na SimpleArbiter
+preberi uporabniško ime in geslo uporabnika, ki ga moraš ustvariti na A. Poskrbi, da se bo novoustvarjeni
+uporabnik s svojim geslom lahko na A prijavil z Interneta.
+"""
+}
+
+computers = {
+ 'SimpleArbiter': {
+ 'disks':[
+ { 'name': 'Test' }]
+ }
+}
+
+params_meta = {
+ 'peer_ip': {'opis': 'Naslov ssh strežnika', 'w': True, 'public':True, 'type': 'IP', 'generated': False},
+ 'peer_user': {'opis': 'ime uporabnika', 'w': False, 'public': True, 'type': 'username', 'generated': True},
+ 'peer_passwd': {'opis': 'geslo uporabnika', 'w': False, 'public': True, 'type': 'password', 'generated': True},
+}
+
+def task(peer_ip, peer_user, peer_passwd):
+ return dict()
+
+def gen_params(user_id, params_meta):
+ return kpovRandomHelpers.default_gen(user_id, params_meta)
+
+def task_check(results, params):
+ import pxssh
+ import pexpect
+ results = dict()
+ s = pxssh.pxssh()
+ peer_ip, peer_user, peer_passwd = params['peer_ip'], params['peer_user'], params['peer_passwd']
+ try:
+ s.login(peer_ip, peer_user, peer_passwd)
+ s.logout()
+ except:
+ return 0
+ return 10
+
+def prepare_disks(templates, params):
+ pass
+ # print d1.ls('/')
diff --git a/kpov_judge/tasks/remote_ssh/lecture/ideja.txt b/kpov_judge/tasks/remote_ssh/lecture/ideja.txt
new file mode 100644
index 0000000..23f5dcc
--- /dev/null
+++ b/kpov_judge/tasks/remote_ssh/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Primer pristopnega kolokvija. Odgovori na vprašanja. Pogoste težave v Virtualbox.
+X11, desktopi, nastavitve.
diff --git a/kpov_judge/tasks/remote_ssh/preparation/task.py b/kpov_judge/tasks/remote_ssh/preparation/task.py
new file mode 100644
index 0000000..ea2b361
--- /dev/null
+++ b/kpov_judge/tasks/remote_ssh/preparation/task.py
@@ -0,0 +1,4 @@
+instructions = {
+ 'si':u"""
+Reši poizkusni pristopni kolokvij."""
+}
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/evaluation/navodila.html b/kpov_judge/tasks/set_ip_static_dhcp/evaluation/navodila.html
new file mode 100644
index 0000000..df4c68d
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/evaluation/navodila.html
@@ -0,0 +1,9 @@
+<p>Usposobite tri računalnike:
+<ul>
+<li>SimpleArbiter - testni računalnik</li>
+<li>Z_DHCP - računalnik, ki bo svoje nastavitve dobil prek DHCP</li>
+<li>BREZ_DHCP - računalnik, ki bo imel svoj IP nastavljen statično.</li>
+</ul>
+</p>
+<p>Prvi omrežni vmesnik računalnika SimpleArbiter naj bo povezan na Internet. Drugi naj bo povezan na neko lokalno omrežje, na katerega bosta priklopljena računalnika Z_DHCP ter BREZ_DHCP. Na računalniku Z_DHCP poskrbite, da bo ob pridobivanju naslova DHCP strežniku poslal tudi posebej nastavljeno ime računalnika (hostname), ki ne bo enako dejanskemu imenu računalnika (tistemu, ki ga izpiše ukaz hostname).</p>
+<p>Naslov BREZ_DHCP ter ime računalnika za Z_DHCP dobite ob zagonu run_test.py na računalniku SimpleArbiter. Uporabniško ime ter geslo na SimpleArbiter sta <pre>tester</pre> in <pre>SedemKrogovPekla</pre>.</p>
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/evaluation/task.py b/kpov_judge/tasks/set_ip_static_dhcp/evaluation/task.py
new file mode 100644
index 0000000..0fad134
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/evaluation/task.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# TODO: finish thi
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Ustvari tri navidezne računalnike. Za disk prvega uporabi sliko diska simpleArbiterDhcp.
+Za enega od ostalih dveh (Z_DHCP) poskrbi, da bo dobil IP prek DHCP, pri čemer
+naj kot hostname strežniku pošlje ime, ki ga dobiš na simpleArbiterDhcp.
+Za drugega poskrbi, da bo imel statično nastavljen IP.
+"""
+}
+
+computers = {
+ 'Z_DHCP': {
+ 'disks': [
+ { 'name': 'Z_DHCP',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'BREZ_DHCP': {
+ 'disks': [
+ { 'name': 'BREZ_DHCP',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_DHCP': {'opis': 'Naslov za DHCP', 'w': False, 'public': False, 'type': 'IP', 'generated': True},
+ 'Hostname_DHCP': {'opis': 'Ime DHCP', 'w': False, 'public': True, 'type': 'hostname', 'generated': True},
+ 'IP_static': {'opis': 'Naslov BREZ_DHCP', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'IP_dhcp_static': {'opis': 'Dodeljen IP brez DHCP', 'w': False, 'public': False, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_DHCP, Hostname_DHCP, IP_static, MAC_static, IP_dhcp_static):
+ import pxssh
+ import pexpect
+ results = dict()
+ # check hostname of DHCP
+ # check the hostname in the response of IP_DHCP
+ # check availability of IP_static
+ # check non-availability of IP_dhcp_static
+ return results
+
+def gen_params(user_id, params_meta):
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['IP_DHCP'], params['IP_static'], params['IP_dhcp_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 3)
+ params['Hostname_DHCP'] = kpovRandomHelpers.hostname_gen(r)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ if results['bla']:
+ score += 3
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+# create config for static_DHCP
+# set static_DHCP hostname
+ pass
+
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/lecture/ideja.txt b/kpov_judge/tasks/set_ip_static_dhcp/lecture/ideja.txt
new file mode 100644
index 0000000..92d984c
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Mrežne nastavitve pod Linuxom. Ukazi za delo z mrežo. tcpdump. NetworkManager.
+dbus.
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/04.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/04.png
new file mode 100644
index 0000000..754c200
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/04.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/09.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/09.png
new file mode 100644
index 0000000..866a51d
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/09.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/10.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/10.png
new file mode 100644
index 0000000..d6ccf42
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/10.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/11.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/11.png
new file mode 100644
index 0000000..10b5ec7
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/11.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/12.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/12.png
new file mode 100644
index 0000000..0a87ae6
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/12.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/13.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/13.png
new file mode 100644
index 0000000..e71474a
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/13.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/17.png b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/17.png
new file mode 100644
index 0000000..d4bba87
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/images/17.png
Binary files differ
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/si/index.html b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/si/index.html
new file mode 100644
index 0000000..9b56a81
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/howtos/si/index.html
@@ -0,0 +1,73 @@
+<p>
+<h2>Namen vaje</h2>
+Naučite se, kako se nastavljajo omrežni vmesniki v večini sodobnih Linux distribucij (NetworkManager).
+</p>
+<p>
+<h2>Naloga na hitro</h2>
+Nastavi statičen IP v NetworkManager-ju, nastavi statični IP in DNS strežnik v /etc/network/interfaces. Oba naslova računalnikov in DNS strežnikov dobite ob zagonu run_test.py.
+</p>
+<p>
+<h2>Navodila</p>
+<ol>
+<li>Iz imenika s slikami virtualnih računalnikov povlecite slike maliNetworkManager, maliBrezNetworkManager, SimpleArbiterDhcp</li>
+
+<li>Nastavite omrežja navideznih računalnikov tako, da bo<br/>1. omrežni vmesnik SimpleArbiterDhcp povezan na isto omrežje kot edini omrežni vmesnik maliNetworkManager in maliBrezNetworkManager,<br/>
+ 2. vmesnik SimpleArbiterDhcp bo povezan na NAT ali fizično omrežje, kjer prek DHCP dobi naslov in pot (prehod, gateway) do Interneta.</li>
+
+<li>Zaženite SimpleArbiterDhcp. Prijavite se kot uporabnik tester z geslom SedemKrogovPekla</li>
+<li>
+<img alt="slika-04" src="/sites/lusy.fri.uni-lj.si/files/public_files/courses/fri-courses/kpov/Vaje/03.predvaja/sshots/04_0.png" style="width: 800px; height: 600px;" /><br/>
+Z ukazom <pre>ping 193.2.1.66</pre> preverite, ali je SimpleArbiterDhcp na Internetu. Če je, boste približno vsako sekundo dobili odziv. Ping prekinete
+s kombinacijo tipk CTRL+C.<br/>
+ Če SimpleArbiterDhcp ne pride do Interneta, v VirtualBox zamenjajte nastavitve 1. in 2. omrežni vmesnik ter ponovno zaženite navidezni računalnik.
+</li>
+<li>Poženite run_test.py.</li>
+
+<li>Kot ime naloge vpišite 03.predvaja</li>
+
+<li>Preberite statični IP maliNetworkManager. Pustite SimpleArbiterDhcp da teče v ozadju, dokler niste nastavili maliNetworkManager</li>
+
+<li>Zaženite maliNetworkManager.</li>
+
+<li>
+Prijavite se v grafično okolje z uporabniškim imenom student, geslom vaje</li>
+<li><img alt="ikona network manager" src="/sites/lusy.fri.uni-lj.si/files/public_files/courses/fri-courses/kpov/Vaje/03.predvaja/sshots/10.png" style="width: 800px; height: 600px;" /><br/>
+Desno-kliknite na ikono za mrežne nastavitve</br>
+
+<li>
+<img alt="Menu NetworkManager" src="/sites/lusy.fri.uni-lj.si/files/public_files/courses/fri-courses/kpov/Vaje/03.predvaja/sshots/11.png" style="width: 800px; height: 600px;" /><br/>
+Izberite "Edit Connections"</li>
+
+<li>
+<img alt="Menu NetworkManager" src="/sites/lusy.fri.uni-lj.si/files/public_files/courses/fri-courses/kpov/Vaje/03.predvaja/sshots/12.png" style="width: 800px; height: 600px;" /><br/>
+Kliknite "Edit"</li>
+
+<li>
+<img alt="Menu NetworkManager" src="/sites/lusy.fri.uni-lj.si/files/public_files/courses/fri-courses/kpov/Vaje/03.predvaja/sshots/13.png" style="width: 800px; height: 600px;" /><br/>
+V zavihku "IPv4" spremenite "Method" na "Manual". Kliknite na "Add". Nastavite statični IP, ki ste ga prebrali na SimpleArbiterDhcp kot statični IP A.<br/>
+V DNS servers dodajte naslov Arnesovega DNS: 193.2.1.66
+</li>
+<li>Kliknite "Save"</li>
+
+<li>Preklopite na SimpleArbiterDhcp. Pritisnite "Enter" oz. "OK".</li>
+
+<li>Preberite IP maliBrezNetworkManager. Pritisnite "OK". Preberite naslov DNS strežnika.</li>
+
+<li> Preklopite na maliBrezNetworkManager. Preklopite na prvo konzolo s kombinacijo CTRL+ALT+F1. Prijavite se kot root z geslom kaboom.</li>
+
+<li> Odprite datoteko /etc/network/interfaces. Popravite nastavitve v skladu s podatki, ki ste jih dobili na SimpleArbiter. Vnos za omrežni vmesnik mora izgledati približno takole:<br/>
+<pre>
+allow-hotplug eth0
+iface eth0 inet static
+ 10.0.1.2
+ netmask 255.255.255.128
+ dns-nameservers 10.0.1.5
+</pre>
+</li>
+
+<li> Shranite nastavitve. Z ukazom reboot ponovno zaženite maliBrezNetworkManager. NetworkManager ob zagonu računalnika
+prebere, kateri omrežni vmesniki so nastavljeni v /etc/network/interfaces. Za te vmesnike potem ne skrbi več.</li>
+
+</li>Na SimpleArbiterDhcp pritisnite OK. Če je šlo vse po sreči, ste opravili tokratno nalogo.</li>
+</ol>
+</p>
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/preparation/task.py b/kpov_judge/tasks/set_ip_static_dhcp/preparation/task.py
new file mode 100644
index 0000000..1d79a61
--- /dev/null
+++ b/kpov_judge/tasks/set_ip_static_dhcp/preparation/task.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Ustvari tri navidezne računalnike. Za prvega
+uporabi sliko diska simpleArbiterDhcp, za drugega sliko diska
+maliNetworkManager, za tretjega sliko diska maliBrezNetworkManager.
+Računalnike imenujmo enako kot slike diska.
+Na maliBrezNetworkManager izklopi networkmanager. Na
+Izklopi NetworkManager. Na obeh ročno nastavi IP naslova ter naslova
+DNS strežnikov. Naslove dobiš na simpleArbiterDhcp.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/set_motd/evaluation/navodila.txt b/kpov_judge/tasks/set_motd/evaluation/navodila.txt
new file mode 100644
index 0000000..755719f
--- /dev/null
+++ b/kpov_judge/tasks/set_motd/evaluation/navodila.txt
@@ -0,0 +1,8 @@
+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 na testnem računalniku je tester, geslo SedemKrogovPekla .
+
+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. Računalnik lahko namestite sami, lahko pa uporabite računalnik Student, na katerem imate uporabnika student z geslom vaje . Geslo uporabnika root je kaboom .
+
+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.
diff --git a/kpov_judge/tasks/set_motd/evaluation/task.py b/kpov_judge/tasks/set_motd/evaluation/task.py
new file mode 100644
index 0000000..3338c80
--- /dev/null
+++ b/kpov_judge/tasks/set_motd/evaluation/task.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# bson.son.SON an
+# kpovRandomHelpers 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.
+"""
+}
+
+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': {'opis': 'IP računalnika', 'w': True, 'public':True, 'type': 'IP', 'generated': False},
+ 'peer_user': {'opis': 'ime uporabnika', 'w': False, 'public': True, 'type': 'username', 'generated': True},
+ 'peer_passwd': {'opis': '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
+ results = dict()
+ s = pxssh.pxssh()
+ s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False)
+ results['motd'] = s.before # print everything before the prompt.
+ return results
+
+def gen_params(user_id, params_meta):
+ return kpovRandomHelpers.default_gen(user_id, params_meta)
+
+def task_check(results, params):
+ niz = params['niz']
+ score = 0
+ if (results['motd'].find(niz) > -1):
+ score += 10
+ return score
+
+def prepare_disks(templates, params):
+ # print d1.ls('/')
+ pass
diff --git a/kpov_judge/tasks/set_motd/lecture/ideja.txt b/kpov_judge/tasks/set_motd/lecture/ideja.txt
new file mode 100644
index 0000000..e05a775
--- /dev/null
+++ b/kpov_judge/tasks/set_motd/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Sistem dela pri vajah. Kako izgleda pristopni kolokvij. Kako se ocenjuje.
+Pogosti problemi pri VirtualBox. Dodajanje diskov. Problemi z mrežo.
diff --git a/kpov_judge/tasks/set_motd/preparation/task.py b/kpov_judge/tasks/set_motd/preparation/task.py
new file mode 100644
index 0000000..e634959
--- /dev/null
+++ b/kpov_judge/tasks/set_motd/preparation/task.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# bson.son.SON an
+# kpovRandomHelpers should be imported by add_assignment.py
+# OrderedDict = SON
+
+instructions = {
+ 'si':u"""
+Namesti VirtualBox. Ustvari dva navidezna računalnika. Pri enem od njiju (imenujmo ga TEST)
+kot disk uporabi datoteko Test_disk1. Na drugega (imenujmo ga A) namesti poljubno Linux distribucijo.
+Poskrbi, da bosta oba računalnika na istem omrežju. Na računalnik A namesti strežnik ssh.
+Z računalnika TEST se prek ssh poveži na A. Poskrbi, da bo TEST imel dostop tako do Interneta, kot
+tudi do računalnika A.
+"""
+}
+
+computers = {
+ 'A': {
+ 'disks': [
+ { 'name': 'A_disk1',
+ 'parts': [{'dev': 'a1', 'path': '/'}],
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'image': 'KPOV-bombica01',
+ 'flavor': 'm1.kpov',
+ 'network_interfaces': [{'network': 'net1'}],
+ 'config_drive': True,
+ 'userdata': {'string': "#!/bin/bash\nsed -i '/cloud/d' /etc/fstab\npoweroff &\n"}
+ },
+ 'TEST': {
+ 'disks': [
+ { 'name': 'Test_disk1',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'image': 'KPOV-bombica01',
+ 'flavor': 'm1.kpov',
+ 'network_interfaces': [{'network': 'net1'},{'network':'test-net'}],
+ 'config_drive': False
+ },
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'peer_ip': {'opis': 'Naslov ssh strežnika', 'w': True, 'public':True, 'type': 'IP', 'generated': False},
+ 'peer_user': {'opis': 'ime uporabnika', 'w': True, 'public': True, 'type': 'alnumstr', 'generated': False},
+ 'peer_passwd': {'opis': 'geslo uporabnika', 'w': True, 'public': True, 'type': 'alnumstr', 'generated': False},
+ 'addon_disk_filename': {'w': False, 'public': False, 'generated': True}, # datoteka na dodatnem disku
+}
+
+def task(peer_ip, peer_user, peer_passwd):
+ "Check whether ssh works"
+ import pxssh
+ import pexpect
+ results = dict()
+ s = pxssh.pxssh()
+ s.login (peer_ip, peer_user, peer_passwd)
+ results['motd'] = s.before # print everything before the prompt.
+ s.sendline('ls /mnt')
+ s.prompt()
+ results['ls_remote'] = s.before
+ s.logout()
+ results['ls_local'] = pexpect.run('ls ~/')
+ return results
+
+def gen_params(user_id, params_meta):
+ return kpovRandomHelpers.default_gen(user_id, params_meta)
+
+def task_check(results, params):
+ fname = params['addon_disk_filename']
+ score = 0
+ if (results['ls_remote'].find(fname) > -1):
+ score += 5
+ if (results['ls_local'].find(fname) > -1):
+ score += 5
+ return score
+
+def prepare_disks(templates, params):
+ d1 = templates['A_disk1']
+ # print "touching", d1
+ d1.touch('/{0}.txt'.format(params['addon_disk_filename']))
+ # print "writing to", '/{0}.txt'.format(params['addon_disk_filename'])
+ d1.write('/{0}.txt'.format(params['addon_disk_filename']), 'Studentje na KPOV ste ZAKON!')
+ # print d1.ls('/')
diff --git a/kpov_judge/tasks/set_motd_egotrip/evaluation/task.py b/kpov_judge/tasks/set_motd_egotrip/evaluation/task.py
new file mode 100644
index 0000000..cd3d970
--- /dev/null
+++ b/kpov_judge/tasks/set_motd_egotrip/evaluation/task.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Na internet postavi računalnik, ki bo dostopen prek ssh in http.
+Poskrbi, da bo na računalniku ustvarjen uporabnik test z geslom test. Ob prijavi naj se
+uporabniku v MOTD izpiše (le) zgodbica ali pesmica, ki vam je všeč, dolžine vsaj 50 znakov.
+Ista zgodbica ali pesmica naj se na strežniku izpiše, če se na strežnik kdorkoli poveže prek
+http.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/set_motd_egotrip/lecture/ideja.txt b/kpov_judge/tasks/set_motd_egotrip/lecture/ideja.txt
new file mode 100644
index 0000000..91c85c2
--- /dev/null
+++ b/kpov_judge/tasks/set_motd_egotrip/lecture/ideja.txt
@@ -0,0 +1 @@
+Reši pristopni kolokvij z visoko oceno.
diff --git a/kpov_judge/tasks/set_motd_egotrip/preparation/task.py b/kpov_judge/tasks/set_motd_egotrip/preparation/task.py
new file mode 100644
index 0000000..272407c
--- /dev/null
+++ b/kpov_judge/tasks/set_motd_egotrip/preparation/task.py
@@ -0,0 +1,2 @@
+instructions = {'si': u"""
+Reši poizkusni pristopni kolokvij z visoko oceno.""" }
diff --git a/kpov_judge/tasks/snmp/evaluation/task.py b/kpov_judge/tasks/snmp/evaluation/task.py
new file mode 100644
index 0000000..e8fb908
--- /dev/null
+++ b/kpov_judge/tasks/snmp/evaluation/task.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+
+instructions = {
+ 'si':u"""
+Postavite tri računalnike - SimpleArbiterSNMP s sliko diska simpleArbiterSNMP, ServerSNMP s sliko
+diska serverSNMP ter SNMPClient.
+
+Na SNMPClient ustvarite uporabnika test z geslom test. V datoteko /home/test/alarmi zapišite
+vse IP in vse OID, s katerih po SNMP prihajajo alarmi. Za vsak alarm zapišite eno vrstico,
+v kateri bosta najprej IP, nato OID, ločena s presledkom.
+
+V datoteko /home/test/vmesniki vpišite imena vseh omrežnih vmesnikov, ki jih prek SNMP dobite na
+ServerSNMP.
+"""
+}
+
+computers = {
+ 'maliNetworkManager': {
+ 'disks': [
+ { 'name': 'maliNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'maliBrezNetworkManager': {
+ 'disks': [
+ { 'name': 'maliBrezNetworkManager',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'IP_NM': {'opis': 'Naslov maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'DNS_NM': {'opis': 'DNS za maliNetworkManager', 'w': False, 'public':True, 'type': 'IP', 'generated': True},
+ 'IP_static': {'opis': 'Naslov maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+ 'DNS_static': {'opis': 'DNS za maliBrezNetworkManager', 'w': False, 'public': True, 'type': 'IP', 'generated': True},
+}
+
+def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import pxssh
+ import pexpect
+ 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()
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ # IP_NM, DNS_NM, IP_static, DNS_static)
+ dns_servers = ['193.2.1.66', '193.2.1.72', '8.8.8.8', '8.8.4.4', '208.67.222.222', '208.67.220.220']
+ net = kpovRandomHelpers.IPv4_subnet_gen(r, '172.23.128.0/18', 24)
+ params['DNS_NM'] = r.choice(dns_servers)
+ params['IP_NM'], params['IP_static'] = kpovRandomHelpers.IPv4_addr_gen(r, net, 2)
+ params['DNS_static'] = r.choice(dns_servers)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/tasks/snmp/lecture/ideja.txt b/kpov_judge/tasks/snmp/lecture/ideja.txt
new file mode 100644
index 0000000..0832279
--- /dev/null
+++ b/kpov_judge/tasks/snmp/lecture/ideja.txt
@@ -0,0 +1,2 @@
+Postavi SNMP strežnik. Preberi podatke z njega. Dodaj agenta za temp. procesorja. Namesti CACTI. Nastavi CACTI, da bo bral podatke s strežnika.
+
diff --git a/kpov_judge/tasks/snmp/preparation/task.py b/kpov_judge/tasks/snmp/preparation/task.py
new file mode 100644
index 0000000..7bd6069
--- /dev/null
+++ b/kpov_judge/tasks/snmp/preparation/task.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# kpovRandomHelpers should be imported by add_assignment.py
+# TODO: finish this.
+
+instructions = {
+ 'si':u"""
+Postavi tri navidezne računalnike - SimpleArbiter s sliko diska simpleArbiterDhcp,
+SNMPServer in SNMPClient. Napiši program upminutes, ki bo izpisal, kako dolgo je računalnik vklopljen v minutah.
+Postavi ga na SNMPClient v domači imenik uporabnika test z geslom test.
+
+Poskrbi, da bo SNMP strežnik prek SNMP pod NET-SNMP-EXTEND-MIB::nsExtendOutput2Table sporočal, kako dolgo je vklopljen v sekundah.
+
+Napiši skripto, poimenovano beri.sh, ki prek SNMP prebere vrednost s strežnika SNMPServer na OID 1.3.6.1.4.1.8072.1.3.2.4.1.4.
+Postavi jo na SNMP klienta, v domači imenik uporabnika test z geslom test.
+"""
+}
+
+
+computers = {
+ 'SNMPClient': {
+ 'disks': [
+ { 'name': 'SNMPClient',
+
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ },
+ 'SNMPServer': {
+ 'disks': [
+ { 'name': 'SNMPServer',
+ },
+ #{ 'name': 'CDROM',
+ # 'options':{'readonly': True},
+ # 'parts': [],# no parts, no mounting.
+ #}
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcp',
+ # attempt automount
+ },
+ #{ 'name': 'CDROM',
+ # 'options': {'readonly': True},
+ # 'parts': [{'dev': 'b1', 'path': '/cdrom'}],
+ #},
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+params_meta = {
+ 'SNMP_VALUE': {'opis': 'Vrednost, dostopna prek SNMP', 'w': False, 'public':True, 'type': 'number', 'generated': True},
+ 'SNMP_OID_ON_SERVER': {'opis': 'OID, na katerem je vrednost dostopna', 'w': False, 'public':True, 'type': 'OID', 'generated': True},
+ 'SNMP_OID_ON_CLIENT': {'opis': '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):
+ # run cpu temp script on client
+ # run SNMP read SNMP_OID_ON_CLIENT script on client
+ # read data on SNMP_OID_ON_CLIENT
+ # read data from SNMP server
+ return results
+
+def gen_params(user_id, params_meta):
+ params = dict()
+ r = random.Random(user_id)
+ return params
+
+def task_check(results, params):
+ import re
+ score = -9
+ 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
+ return score
+
+def prepare_disks(templates, params):
+# d = templates['simpleArbiterDhcp']
+ pass
+
diff --git a/kpov_judge/web/kpov.wsgi b/kpov_judge/web/kpov.wsgi
new file mode 100644
index 0000000..b55e6ac
--- /dev/null
+++ b/kpov_judge/web/kpov.wsgi
@@ -0,0 +1 @@
+from kpov_judge import app as kpovjudge
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
new file mode 100755
index 0000000..a2b1f5c
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -0,0 +1,214 @@
+#!/usr/bin/env python
+
+import flask
+from flask import Flask, g, session, redirect, url_for, abort, render_template, flash, app, request
+import pymongo
+import json
+import random
+import settings
+import datetime
+import kpov_random_helpers
+
+app = Flask(__name__)
+app.config.from_object(settings)
+
+dummy_task = """
+def task(neznano_ime_naloge):
+ \"""Preveri delovanje klienta.
+
+ Keyword arguments:
+ nesmiselen_parameter -- Poljuben parameter
+ \"""
+ print "Ta naloga ne obstaja!"
+ return {'odgovor': 'neznana naloga'}
+"""
+
+dummy_checker = """
+def task_check(results, params):
+ raise Exception("neznana naloga?")
+ return "Manjka preverjalnik naloge (neznana naloga?)"
+"""
+
+dummy_meta = {'neznano_ime_naloge': {'opis':'NEZNANA NALOGA', 'w': False}}
+
+@app.before_request
+def before_request():
+ g.db = pymongo.MongoClient(app.config['DB_HOST']).kpov
+ try:
+ user = app.config['USERNAME']
+ password = app.config['PASSWORD']
+ g.db.authenticate(user, password)
+ except:
+ #no auth or auth config?
+ pass
+
+@app.route('/')
+def root():
+ student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
+ tasks = g.db.tasks.find(dict(), {'task_id':1})
+ if tasks is not None:
+ task_list = [i['task_id'] for i in tasks]
+ else:
+ task_list = []
+ return render_template('index.html', student_id=student_id, tasks=task_list)
+
+@app.route('/kpov_judge/')
+def auth_greeting():
+ student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
+ return "To je past!" + str(flask.app.request.__dict__)
+
+@app.route('/<task_id>/results.json', methods=['GET', 'POST'])
+def results(task_id):
+ student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
+ db = g.db
+ if flask.app.request.method == 'POST':
+ results = json.loads(flask.app.request.form['results'])
+ params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id})
+ if params is None:
+ params = dict()
+ else:
+ params = params['params']
+ user_params = json.loads(flask.app.request.form['params'])
+ meta = db.task_params_meta.find_one({'task_id': task_id})
+ if meta is None:
+ meta = dict()
+ else:
+ meta = meta['params']
+ 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 = db.task_checkers.find_one({'task_id':task_id})
+ if task_check_source is None:
+ task_check_source = dummy_checker
+ else:
+ task_check_source = task_check_source['source']
+ try:
+ task_check_code = compile(task_check_source, 'checker.py', 'exec')
+ exec(task_check_code)
+ res = task_check(results, params)
+ except Exception, e:
+ res = "Checker crashed: " + str(e)
+ # flask.app.logger.error(str(e))
+ if (type(res) is int and res > 0):
+ res_status = 'OK'
+ else:
+ res_status = 'NOT OK'
+ db.results.insert({'task_id': task_id, 'result': res, 'status': res_status,'student_id': student_id, 'response': results, 'time': datetime.datetime.now()})
+ return json.dumps({'result': res, 'status': res_status})
+ else:
+ try:
+ entry = db.results.find_one({'$query': {'task_id': task_id, 'student_id': student_id}, '$orderby': {'status': -1}},
+ {'result': 1, 'status': 1, '_id': 0})
+ if entry is None:
+ return json.dumps({'result': 'Naloga ni bila nikdar ocenjena', 'status': 'NOT OK'})
+ return json.dumps(entry)
+ except Exception, e:
+ return json.dumps({'Error': str(e)})
+ # flask.app.logger.error(str(e))
+ return json.dumps({'result':"Mama! Zakaj si me zapustila? Sedaj se bom razstrelil."})
+
+def public_meta(db, task_id):
+ shown = dict()
+ try:
+ meta = db.task_params_meta.find_one({'task_id': task_id})['params']
+ for k, v in meta.iteritems():
+ try:
+ if v['public']:
+ shown[k] = v
+ except:
+ pass
+ except:
+ shown = dummy_meta
+ return shown
+
+@app.route('/<task_id>/task.py', methods=['GET'])
+def task_source(task_id):
+ db = g.db
+ try:
+ task_str = db.tasks.find_one({'task_id': task_id})['source']
+ meta_str = '\nparam_meta = ' + str(public_meta(db, task_id))
+ except:
+ return dummy_task + '\nparam_meta = ' + str(dummy_meta)
+ return task_str + meta_str
+
+def get_params(task_id, student_id, db):
+ try:
+ meta = db.task_params_meta.find_one({'task_id': task_id})['params']
+ except:
+ return {'mama': 'ZAKVAJ?'}, {'mama':{'public': True}}
+ params = db.task_params.find_one({'task_id': task_id, 'student_id': student_id})
+ s = ""
+ if params is None:
+ try:
+ gen_params_source = db.gen_params.find_one({'task_id':task_id})['source']
+ gen_params_code = compile(gen_params_source, 'generator.py', 'exec')
+ exec(gen_params_code)
+ params = gen_params(student_id, meta)
+ db.task_params.update({'task_id':task_id, 'student_id':student_id},
+ {'$set': {'params': params}}, upsert=True)
+ params = gen_params(student_id, meta)
+ for computer in db.computers_meta.find({'task_id': task_id}):
+ try:
+ name = computer.pop('name')
+ del computer['_id']
+ del computer['task_id']
+ except:
+ pass
+ db.student_computers.update({'task_id': task_id, 'student_id': student_id, 'name': name},
+ {'$set': computer}, upsert=True)
+ except Exception, e:
+ meta = {'crash':{'public': True}}
+ params = {'crash': "Parameter creator crashed or missing:" + str(e)}
+ else:
+ params = params['params']
+ return params, meta
+
+@app.route('/<task_id>/', methods = ['GET'])
+def task_greeting(task_id):
+ student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
+ db = g.db
+ # generate the parameters as soon as the student visits
+ params, meta = get_params(task_id, student_id, db)
+ computer_list = db.student_computers.find({'task_id':task_id, 'student_id': student_id})
+ if request.args.get('narediStack', 'false') == 'true':
+ #db.student_tasks.update({'task_id':task_id, 'student_id': student_id}, {'$set': {'create_openstack': True}}, upsert = True)
+ openstackCreated = False # Spremeni na True, ko odkomentiras zgornjo vrstico.
+ else:
+ if db.student_tasks.find({'task_id':task_id, 'student_id': student_id, 'openstack_created': True}).count() > 0:
+ openstackCreated = True
+ elif db.student_tasks.find({'task_id':task_id, 'student_id': student_id, 'create_openstack': True}).count() > 0:
+ openstackCreated = True
+ else:
+ openstackCreated = False
+ return render_template('task.html', computers = computer_list, openstack = openstackCreated)
+
+@app.route('/<task_id>/params.json', methods=['GET', 'POST'])
+def params(task_id):
+ student_id = flask.app.request.environ.get('REMOTE_USER', 'Nobody')
+ db = g.db
+ params, meta = get_params(task_id, student_id, db)
+ shown_params = dict()
+ for name, param in params.iteritems():
+ if meta.get(name, {'public': False})['public']:
+ shown_params[name] = param
+ if flask.app.request.method == 'POST':
+ shown_params = dict()
+ try:
+ new_params = json.loads(flask.app.request.form['params'])
+ except:
+ new_params = dict()
+ for name in params.iteritems():
+ if meta.get(name, {'w': False})['w'] and k in new_params:
+ params[name] = new_params[name]
+ if meta.get(name, {'public': False})['public']:
+ shown_params[name] = params[name]
+ db.task_params.update({'task_id':task_id, 'student_id':student_id}, {'$set': {'params': params}}, upsert=True)
+ return json.dumps(shown_params)
+
+@app.route('/<task_id>/params_meta.json', methods=['GET'])
+def params_meta(task_id):
+ db = g.db
+ return json.dumps(public_meta(db, task_id))
+
+if __name__ == '__main__':
+ app.run()
diff --git a/kpov_judge/web/kpov_judge/settings.py b/kpov_judge/web/kpov_judge/settings.py
new file mode 120000
index 0000000..8889b19
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/settings.py
@@ -0,0 +1 @@
+../../settings.py \ No newline at end of file
diff --git a/kpov_judge/web/kpov_judge/templates/index.html b/kpov_judge/web/kpov_judge/templates/index.html
new file mode 100644
index 0000000..c0c7924
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/templates/index.html
@@ -0,0 +1,17 @@
+<html>
+<body>
+<p>
+Zdravo, {{student_id}}
+</p>
+<p>
+Trenutno so na voljo naloge:
+<ul>
+{% for t in tasks %}
+<li><a href="{{t}}">{{t}}</a></li>
+{% endfor %}
+</ul>
+</li>
+</p>
+<p>Navodila lahko najdete <a href="http://lusy.fri.uni-lj.si/en/kpov-vaje">na strani LUSY</a>.
+</body>
+</html>
diff --git a/kpov_judge/web/kpov_judge/templates/task.html b/kpov_judge/web/kpov_judge/templates/task.html
new file mode 100644
index 0000000..11fd541
--- /dev/null
+++ b/kpov_judge/web/kpov_judge/templates/task.html
@@ -0,0 +1,35 @@
+<html>
+<body>
+<h1>
+{{task_id}}
+</h1>
+<p>
+<h2>Računalniki v vaji</h2>
+{% for c in computers %}
+ <h3>{{c['name']}}</h3>
+ {% if 'disk_urls' in c %}
+ <ul>
+ {% for u in c['disk_urls'] %}
+ <li><a href={{u['url']}}>{{u['name']}}</a></li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ Slike navideznih diskov so v izdelavi in bodo kmalu na voljo.
+ {% endif %}
+{% endfor %}
+</p>
+<p>
+Lahko si ogledate surove:
+<a href='results.json'>rezultate</a>
+<a href='params.json'>parametre</a>
+<a href='params_meta.json'>opise parametrov</a>
+<a href='task.py'>preverjalni program</a>
+</p>
+<p>
+{% if openstack %}
+Openstack projekt za to vajo je že ustvarjen ali v izdelavi (funkcionalnost še ne deluje).
+{% else %}
+<a href='?narediStack=true'>Ustvari</a> Openstack projekt za to vajo (funkcionalnost še ne deluje).
+{% endif %}
+</body>
+</html>