From 8081a5520a441b43a8a7a73f3a90c7aacfaa8e10 Mon Sep 17 00:00:00 2001
From: Timotej Lazar
Date: Sun, 24 Feb 2019 21:05:27 +0100
Subject: Move everything one level up
---
tasks/custom_rdate/CustomRDate.java | 21 +++
tasks/custom_rdate/TejoLicen/rServe.zip | Bin 0 -> 499 bytes
tasks/custom_rdate/howtos/en/index.html | 65 +++++++++
tasks/custom_rdate/howtos/images/bu1.png | Bin 0 -> 979 bytes
tasks/custom_rdate/howtos/images/bu15.png | Bin 0 -> 679 bytes
tasks/custom_rdate/howtos/images/bu2.png | Bin 0 -> 826 bytes
tasks/custom_rdate/howtos/images/bu3.png | Bin 0 -> 13656 bytes
tasks/custom_rdate/howtos/images/bu4.png | Bin 0 -> 1564 bytes
tasks/custom_rdate/howtos/images/bu5.png | Bin 0 -> 11278 bytes
tasks/custom_rdate/howtos/images/bu6.png | Bin 0 -> 15244 bytes
tasks/custom_rdate/howtos/images/bu7.png | Bin 0 -> 3842 bytes
tasks/custom_rdate/howtos/images/bu8.png | Bin 0 -> 3420 bytes
tasks/custom_rdate/howtos/images/bu9.png | Bin 0 -> 4245 bytes
.../howtos/images/predvaja_clip_image003.gif | Bin 0 -> 686 bytes
tasks/custom_rdate/howtos/images/s1.png | Bin 0 -> 700 bytes
tasks/custom_rdate/howtos/images/s2.png | Bin 0 -> 3882 bytes
tasks/custom_rdate/howtos/images/s3.png | Bin 0 -> 3569 bytes
tasks/custom_rdate/howtos/si/index.html | 67 ++++++++++
tasks/custom_rdate/rDate.java | 34 +++++
tasks/custom_rdate/rDate.py | 18 +++
tasks/custom_rdate/task.py | 146 +++++++++++++++++++++
21 files changed, 351 insertions(+)
create mode 100644 tasks/custom_rdate/CustomRDate.java
create mode 100644 tasks/custom_rdate/TejoLicen/rServe.zip
create mode 100644 tasks/custom_rdate/howtos/en/index.html
create mode 100644 tasks/custom_rdate/howtos/images/bu1.png
create mode 100644 tasks/custom_rdate/howtos/images/bu15.png
create mode 100644 tasks/custom_rdate/howtos/images/bu2.png
create mode 100644 tasks/custom_rdate/howtos/images/bu3.png
create mode 100644 tasks/custom_rdate/howtos/images/bu4.png
create mode 100644 tasks/custom_rdate/howtos/images/bu5.png
create mode 100644 tasks/custom_rdate/howtos/images/bu6.png
create mode 100644 tasks/custom_rdate/howtos/images/bu7.png
create mode 100644 tasks/custom_rdate/howtos/images/bu8.png
create mode 100644 tasks/custom_rdate/howtos/images/bu9.png
create mode 100644 tasks/custom_rdate/howtos/images/predvaja_clip_image003.gif
create mode 100644 tasks/custom_rdate/howtos/images/s1.png
create mode 100644 tasks/custom_rdate/howtos/images/s2.png
create mode 100644 tasks/custom_rdate/howtos/images/s3.png
create mode 100644 tasks/custom_rdate/howtos/si/index.html
create mode 100644 tasks/custom_rdate/rDate.java
create mode 100644 tasks/custom_rdate/rDate.py
create mode 100644 tasks/custom_rdate/task.py
(limited to 'tasks/custom_rdate')
diff --git a/tasks/custom_rdate/CustomRDate.java b/tasks/custom_rdate/CustomRDate.java
new file mode 100644
index 0000000..426dece
--- /dev/null
+++ b/tasks/custom_rdate/CustomRDate.java
@@ -0,0 +1,21 @@
+import java.io.InputStream;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+public class CustomRDate {
+ public static void main(String main[]) throws Exception{
+ try {
+ Socket s = new Socket("ntp1.arnes.si", 37);
+ InputStream vhod = s.getInputStream();
+ byte podatek[] = new byte[8];
+ int dejanskoPrebranih = vhod.read(podatek, 4, 4);
+ ByteBuffer buf = ByteBuffer.wrap(podatek);
+ long stevilka = buf.getLong() - 2208988800L;
+ Date d = new Date(stevilka*1000);
+ System.out.println(d);
+ } catch(Exception e) {
+ System.out.println("Nedosegljiv streznik.");
+ }
+ }
+}
\ No newline at end of file
diff --git a/tasks/custom_rdate/TejoLicen/rServe.zip b/tasks/custom_rdate/TejoLicen/rServe.zip
new file mode 100644
index 0000000..9061692
Binary files /dev/null and b/tasks/custom_rdate/TejoLicen/rServe.zip differ
diff --git a/tasks/custom_rdate/howtos/en/index.html b/tasks/custom_rdate/howtos/en/index.html
new file mode 100644
index 0000000..18ebfc1
--- /dev/null
+++ b/tasks/custom_rdate/howtos/en/index.html
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+ Custom rdate
+ Short preview:
+ Set time on server using rdate. Write a program that converts 32-bit numbers into a readable time format.
+ Instructions:
+ 1. Downlaod Student.vdi (client) and SimpleArbiter.vdi (server) from the virtual machine images folder
+ 2. Use VirtualBox (or similar) to create two virtual machines, select the virtual disk images from the previous step as hard drives
+ 3. Run both virtual machines.
+ 4. Login on client user: root pass: kaboom and server user: tester pass: tester
+
+
+ First part: update time using rdate.
+
+ 1. Find and remember your server IP address. (ifconfig)
+ 2. Install rdate with sudo apt-get install rdate
+ 3. On Student client use rdate to update the machine time rdate SERVER_IP
+ Note: It's NOT an error if the updated time does not match the correct time.
+
+ Second part: write a program that converts 32bit numbers into a readable time format.
+
+ You can write a program in Java or Python using your favourite text editor.
+
+ Java
+
+ 1. We use nano guliver.java to create a new blank file
+ 2. Write a program that converts 32bit numbers into a readable time format.
+
+ 3. Press Ctrl+X, then Y and Enter to save the program
+ 4. In case you don't have java installed use sudo apt-get install openjdk-6-jdk
+
+ 5. To compile use javac bintodec3.java
+ 6. Run the created program with java guliver and input the server IP or name...
+
+
+ Python
+ 1. Use nano guliver.py to create a new empty python file.
+ 2. Write a program that converts 32bit numbers into a readable time format.
+
+ 3. Press Ctrl+X, then Y and Enter to save our program
+ 4. Run the created program with python guliver.py
+
+ Testing
+
+ 1. Use command ./run_test.py to run the tester
+
+ 2. Your username and password are the same as on ucilnica (npr.: "pz1234@student.uni-lj.si" in "geslo123").
+
+ 3. Name of the task should look like 09.predvaja.
+ 4. When prompted for file path insert your program path (example: if bintodec3.py is in the same folder as program run_test.py run with ./bintodec3.py).
+ 5. Then input your server IP address (SimpleArbiterRDate).
+ 6. If all goes well the program should give you an OK that means you've completed your task successfully.
+
+
+
diff --git a/tasks/custom_rdate/howtos/images/bu1.png b/tasks/custom_rdate/howtos/images/bu1.png
new file mode 100644
index 0000000..c6eeac8
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu1.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu15.png b/tasks/custom_rdate/howtos/images/bu15.png
new file mode 100644
index 0000000..c2ac808
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu15.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu2.png b/tasks/custom_rdate/howtos/images/bu2.png
new file mode 100644
index 0000000..85fcfa8
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu2.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu3.png b/tasks/custom_rdate/howtos/images/bu3.png
new file mode 100644
index 0000000..831e764
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu3.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu4.png b/tasks/custom_rdate/howtos/images/bu4.png
new file mode 100644
index 0000000..495351a
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu4.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu5.png b/tasks/custom_rdate/howtos/images/bu5.png
new file mode 100644
index 0000000..103e0e6
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu5.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu6.png b/tasks/custom_rdate/howtos/images/bu6.png
new file mode 100644
index 0000000..b032223
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu6.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu7.png b/tasks/custom_rdate/howtos/images/bu7.png
new file mode 100644
index 0000000..bd50500
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu7.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu8.png b/tasks/custom_rdate/howtos/images/bu8.png
new file mode 100644
index 0000000..98f7812
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu8.png differ
diff --git a/tasks/custom_rdate/howtos/images/bu9.png b/tasks/custom_rdate/howtos/images/bu9.png
new file mode 100644
index 0000000..9ed78ce
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/bu9.png differ
diff --git a/tasks/custom_rdate/howtos/images/predvaja_clip_image003.gif b/tasks/custom_rdate/howtos/images/predvaja_clip_image003.gif
new file mode 100644
index 0000000..02be389
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/predvaja_clip_image003.gif differ
diff --git a/tasks/custom_rdate/howtos/images/s1.png b/tasks/custom_rdate/howtos/images/s1.png
new file mode 100644
index 0000000..52b6ee5
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/s1.png differ
diff --git a/tasks/custom_rdate/howtos/images/s2.png b/tasks/custom_rdate/howtos/images/s2.png
new file mode 100644
index 0000000..78a65ce
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/s2.png differ
diff --git a/tasks/custom_rdate/howtos/images/s3.png b/tasks/custom_rdate/howtos/images/s3.png
new file mode 100644
index 0000000..c32eae1
Binary files /dev/null and b/tasks/custom_rdate/howtos/images/s3.png differ
diff --git a/tasks/custom_rdate/howtos/si/index.html b/tasks/custom_rdate/howtos/si/index.html
new file mode 100644
index 0000000..e68221c
--- /dev/null
+++ b/tasks/custom_rdate/howtos/si/index.html
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+ Custom rdate
+ Naloga na hitro:
+
+ Nastavi uro na strežniku s pomočjo rdate. Napiši program, ki pretvori 32-bitna števila v čas.
+
+ Navodila:
+
+ 1. Z imenika s slikami virtualnih računalnikov povlecite sliki Student.vdi(klient) in SimpleArbiterRDate.vdi(strežnik).
+ 2. Z VirtualBoxom (ali podobnim) ustvarite dva virtualna računalnika in jim kot disk za shranjevanje podajte Student.vdi ter SimpleArbiterRDate.vdi.
+ 3. Zaženite oba navidezna računalnika.
+ 4. Na Student se prijavite z uporabnikom root in geslom kaboom
+ na SimpleArbiterRDate pa z uporabnikom tester in geslom tester.
+
+
+ Prvi del naloge: posodobi uro računalnika s pomočjo rdate.
+
+ 1. Preverite in si zapišite IP naslov na SimpleArbiterRDate. (ifconfig)
+ 2. Z ukazom sudo apt-get install rdate namestimo program rdate.
+ 3. Na Student z pomočjo rdate posodobi uro računalnika. rdate IP_SIMPLE_ARBITER
+ Opozorilo: NI napaka, če se posodobljen čas ne ujema s pravilnim časom.
+
+ Drugi del naloge: napiši program, ki pretvori binarni zapis 32-bitnega števila v časovni format.
+
+ Nalogo lahko rešite v Javi ali v Pythonu. Prav tako pa lahko kodo pišete v poljubnem tekstovnem urejevalniku.
+
+
Java
+
+ 1. Z ukazom nano guliver.java ustvarimo in odpremo prazen program s tekstovnim urejevalnikom nano
+ 2. Napišemo program za pretvarjanje 32-bitnega števila v čas
+ 3. Pritisnemo Ctrl+X, nato Y in Enter, da program zapremo in shranimo.
+ 4. Če je še nimamo, naložimo Javo sudo apt-get install openjdk-6-jdk
+ 5. Prevedemo program javac bintodec3.java
+ 6. Lahko ga še zaženemo ter preizkusimo java guliver.Na standardni vhod vnasemo IP naslov ali ime strežnika NTP strežnikom, ki nam pošlje 32 bitno število in pretvori v čas
+
+ Python
+
+ 1. Z ukazom nano guliver.py ustvarimo in odpremo prazen program s tekstovnim urejevalnikom nano
+ 2. Napišemo program za pretvarjanje 32-bitnega števila v čas
+ 3. Pritisnemo Ctrl+X, nato Y in Enter, da program zapremo in shranimo.
+ 4. Program zaženemo z ukazom python guliver.py
+
+
+ Testiranje
+
+ 1. Lahko poženemo tester; z ukazom ./run_test.py
+
+ 2. Kot "Upor. Ime" in "Geslo" napišite vaše podatke učilnice. (npr.: "pz1234@student.uni-lj.si" in "geslo123")
+
+ 3. Kot ime naloge vpišite 09.predvaja.
+ 4. Ko vas program vpraša po poti programa vnesite vašo pot do programa za pretvarjanje. (npr.: če imate program bintodec3.py v isti mapi kot program run_test.py, vnesete: ./bintodec3.py)
+ 5. Povpraša tudi po IP naslovu SimpleArbiterjaRDate, vnesite.
+ 6. Če je šlo vse po sreči, program vrne OK vi pa ste opravili nalogo.
+
+
+
diff --git a/tasks/custom_rdate/rDate.java b/tasks/custom_rdate/rDate.java
new file mode 100644
index 0000000..8c8bae7
--- /dev/null
+++ b/tasks/custom_rdate/rDate.java
@@ -0,0 +1,34 @@
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.net.Socket;
+import java.net.SocketException;
+import java.nio.ByteBuffer;
+import java.uti.Date;
+import java.util.Scanner;
+
+public class rDate{
+
+ public static void main(String[] args) throw IOException{
+ Scanner sc=new Scanner(System.in);
+ String niz=sc.next();
+
+ try{
+ Socket s=new Socket(niz,37);
+ OutputStreamWriter izhod=new OutputStreamWriter(s.getOutputStream());
+ InputStream vhod=s.getInputStream();
+ byte[] podatek=new byte[4];
+ ByteBuffer buf=ByteBuffer.wrap(podatek);
+ int stevilka=buf.getInt();
+ long dolga=stevilka
+ long maska=-1;
+ maska =~(maska <<32);
+ dolga = dolga & maska;
+ Date d=new Date(dolga *1000 - 2208988800000L);
+ System.out.print(d);
+ izhod.write(d.toString());
+ }catch(SocketException e){
+ System.out.println("Strežnik ne obstaja");
+ }
+ }
+}
diff --git a/tasks/custom_rdate/rDate.py b/tasks/custom_rdate/rDate.py
new file mode 100644
index 0000000..97885b0
--- /dev/null
+++ b/tasks/custom_rdate/rDate.py
@@ -0,0 +1,18 @@
+
+#!/usr/bin/env python
+#-*- coding utf-8 -*-
+
+import socket
+import struct
+import time
+
+niz=input("Vnesi IP ali ime strežnika:")
+s = socket.socket(
+ socket.AF_Inet, socket.SOCK_STREAm)
+s.connect((niz,37))
+podatek = s.recv(4)
+stevilka = struct.unpack("!I", podatek)
+st= stevilka[0]-220898800
+date = time.localtime(st)
+print((time.strftime('%Y-%m-%d %H:%M:%S'), date))
+s.send(date)
diff --git a/tasks/custom_rdate/task.py b/tasks/custom_rdate/task.py
new file mode 100644
index 0000000..4c5ff9f
--- /dev/null
+++ b/tasks/custom_rdate/task.py
@@ -0,0 +1,146 @@
+# kpov_util should be imported by add_assignment.py
+
+# TODO: finish this!
+instructions = {
+ 'si': '''\
+
+Postavite dva navidezna računalnika: SimpleArbiterDhcpRdate in rdateClient.
+
+
+Nastavite čas na rdateClient tako, da kot rdate strežnik uporabite SimpleArbiterDhcpRdate.
+
+
+Na rdateClient ustvarite uporabnika test
z geslom test
. V domačem imeniku uporabnika test
ustvarite program z imenom {{PROGRAM_FILENAME}}
. Program naj prebere štiri bajte podatkov s standardnega vhoda in jih pretvori v predznačeno celo število, pri čemer naj uporablja zapis z debelim koncem (angl. big endian). Število naj program izpiše na standardni izhod v obliki niza.
+''',
+ 'en': '''\
+
+Set up two virtual machines: SimpleArbiterDhcpRdate and rdateClient.
+
+
+Set the time on rdateClient using rdate with SimpleArbiterDhcpRdate as
+the server.
+
+
+On rdateClient create a user with the username test
and password test
. Then, write a program called {{PROGRAM_FILENAME}}
and put it in user test
’s home directory. The program should read four bytes of data from standard input, convert them into a signed integer using big endian byte ordering and output the resulting integer (as a string) to standard output.
+''',
+}
+
+computers = {
+ 'rdateClient': {
+ 'disks': [
+ { 'name': 'student-rdate',
+ },
+ ],
+ 'network_interfaces': [{'network': 'net1'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+
+ },
+ 'SimpleArbiter': {
+ 'disks': [
+ { 'name': 'simpleArbiterDhcpGWRdate',
+ },
+ ],
+ 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}],
+ 'flavor': 'm1.tiny',
+ 'config_drive': False
+ }
+}
+
+networks = { 'net1': {'public': False}, 'test-net': {'public': True} }
+
+# Tu sem dolocil parametre
+params_meta = {
+ 'RDATE_OFFSET':{'descriptions': {'si': 'Napaka v času pri rdate', 'en': 'Timekeeping error for rdate'}, 'w': False, 'public': False, 'type': 'integer', 'generated': True},
+ 'PROGRAM_FILENAME':{'descriptions': {'si': 'Ime programa', 'en': 'program filename'}, 'w': False, 'public': True, 'type': 'integer', 'generated': True},
+ 'IP_RDATECLIENT':{'descriptions': {'si': 'IP rdateClient', "en": "rdateClient's IP"}, 'w': True, 'public': True, 'type': 'IP', 'generated': False},
+}
+
+def task(IP_RDATECLIENT, PROGRAM_FILENAME):
+ import collections
+ import base64
+ import random
+ import struct
+ import pexpect
+
+ r = random.Random(PROGRAM_FILENAME)
+ results = collections.defaultdict(str)
+ tests = []
+ for i in range(10):
+ data = struct.pack("!I", r.randint(0, 2**32))
+ results['in_'+str(i)] = data_ascii = base64.encodestring(data)
+ tests += [('out_'+str(i), 'echo "{}" | base64 -d | ~/{}'.format(data_ascii.decode().strip(), PROGRAM_FILENAME))]
+ tests += [('date', 'date -u +"%s"')]
+
+ results.update(
+ kpov_util.ssh_test(IP_RDATECLIENT, 'test', 'test', tests))
+ results['ldate'] = pexpect.run('date -u +"%s"')
+
+ return results
+
+#Dolocil sem tri parametre in sicer jih lahko vidite v prams_meta,
+#zato prosim da jih upostevate v naslednih nalogah.
+
+def gen_params(user_id, params_meta):
+ import socket
+ import struct
+ import datetime
+ params = dict()
+ r = random.Random(user_id)
+ params['PROGRAM_FILENAME'] = kpov_util.fname_gen(r, False)
+ params['RDATE_OFFSET'] = str(r.randint(-2**24, 2**24))
+ return params
+
+def task_check(results, params):
+ import random
+ import struct
+ import base64
+
+ r = random.Random(params['PROGRAM_FILENAME'])
+ score = 0.0
+ hints = []
+ for i in range(10):
+ data = base64.decodestring(results['in_' + str(i)])
+ x = struct.pack("!I", r.randint(0, 2**32))
+ if data != x:
+ hints += ["data: " + str((data,)) + " != " + str((x,))]
+ break
+ res = results['out_' + str(i)]
+ if str(struct.unpack("!i", data)[0]) == res.strip():
+ score += 0.5
+ else:
+ hints += ["wrong convert"]
+
+ if abs(int(results['ldate']) + \
+ int(params['RDATE_OFFSET']) - int(results['date'])) < 3:
+ score += 5
+ else:
+ hints += ["wrong offset"]
+ return score, hints
+
+def prepare_disks(templates, task_params, global_params):
+ d = templates['simpleArbiterDhcpGWRdate']
+ s1 = """service "time_tcp" {{
+ enabled yes;
+ protocol tcp;
+ port "time";
+ user "nobody";
+ exec "/usr/local/bin/kpovrdate {RDATE_OFFSET}";
+ server "/usr/sbin/tcpd";
+ wait no;
+}}
+""".format(**task_params)
+ d.write('/etc/rlinetd.d/time', s1)
+ s2 = """#!/usr/bin/python
+
+import struct
+import time
+import sys
+
+offset = int(sys.argv[1])
+t = time.time() + offset # used to have + 2208988800
+sys.stdout.write(struct.pack("!I", int(t)))
+"""
+ d.write('/usr/local/bin/kpovrdate', s2)
+ d.chmod(0o775, '/usr/local/bin/kpovrdate')
+ write_default_config(templates['simpleArbiterDhcpGWRdate'], global_params)
--
cgit v1.2.1