summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kpov_judge/tasks/copy_rename_100_files/task.py21
-rw-r--r--kpov_judge/tasks/copy_rename_20_files_tail_env/task.py129
-rw-r--r--kpov_judge/tasks/mock_entrance_exam/task.py63
-rw-r--r--kpov_judge/tasks/public_ip_ssh/task.py16
-rw-r--r--kpov_judge/tasks/rename_grep_network/task.py74
-rw-r--r--kpov_judge/tasks/set_ip_static_dhcp/task.py68
-rw-r--r--kpov_judge/tasks/set_motd/task.py41
7 files changed, 184 insertions, 228 deletions
diff --git a/kpov_judge/tasks/copy_rename_100_files/task.py b/kpov_judge/tasks/copy_rename_100_files/task.py
index 9ad4d66..c658d27 100644
--- a/kpov_judge/tasks/copy_rename_100_files/task.py
+++ b/kpov_judge/tasks/copy_rename_100_files/task.py
@@ -73,16 +73,19 @@ params_meta = {
}
def task(host, folder):
+ import collections
from pexpect import pxssh
-
- # ideally, this would be done using a SFTP client instead of pxssh
- target = pxssh.pxssh()
- target.login(host, 'test', 'test')
- results = {
- 'files': target.run('ls -1').split('\n'), # XXX: file may have newlines
- 'contents': target.run("cat *"), # XXX: may include other files in $HOME
- }
- target.logout()
+ results = collections.defaultdict(str)
+ try:
+ # ideally, this would be done using a SFTP client instead of pxssh
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(host, 'test', 'test')
+ results['ssh'] = True
+ results['files'] = s.run('ls -1').split('\n'), # XXX: file may have newlines
+ results['contents'] = s.run('cat *'), # XXX: may include other files in $HOME
+ s.logout()
+ except Exception as ex:
+ results['ssh'] = str(ex)
return results
def gen_params(user_id, params_meta):
diff --git a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
index 7e3c3c8..d817083 100644
--- a/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
+++ b/kpov_judge/tasks/copy_rename_20_files_tail_env/task.py
@@ -116,9 +116,37 @@ params_meta = {
}
def task(IP_malishell, file_rename_dirname, mv_src_dir, mv_dst_dir, cowsay_string, curl_fname, wc_dirname):
- from pexpect import pxssh
+ import collections
import os
- # TODO: (polz) this has to be changed! Get a move on!
+ from pexpect import pxssh
+
+ commands = [
+ ('preimenuj', '/bin/ls -a1 {}'.format(file_rename_dirname)),
+ ('pre_mv_src', '/bin/ls -a1 {}'.format(mv_src_dir)),
+ ('pre_mv_dst', '/bin/ls -a1 {}'.format(mv_dst_dir)),
+ ('mv_ls_size', '/bin/ls -l ~/mv_ukaz'),
+ (None, '. ~/mv_ukaz'),
+ ('post_mv_src', '/bin/ls -a1 {}'.format(mv_src_dir)),
+ ('post_mv_dst', '/bin/ls -a1 {}'.format(mv_dst_dir)),
+
+ # mama_ukaz
+ (None, 'cd /home/student/grep_test_dir'),
+ (None, '. ~/mama_ukaz'),
+ ('grep_napake', 'cat ~/napake.txt'),
+ ('grep_mama', 'cat ~/mama.txt'),
+
+ # sledenje syslog
+ (None, 'date'),
+ ('syslog_start_time', '/usr/local/bin/syslog_spammer &'),
+ ('syslog_result', '/home/student/syslog_ukaz.sh'),
+ ('syslog_end_time', 'date'),
+
+ ('cowsay', 'cowsay "{}"'.format(cowsay_string)),
+ ('wc_origfile', 'cat {}/count.txt'.format(wc_dirname)),
+ ('wc_lines', 'cat {}/lines.txt'.format(wc_dirname)),
+ ]
+
+ # TOD: (polz) this has to be changed! Get a move on!
#
# sv: Z primozem lavricem sva skusala nekaj narediti
# Ker gen params ni narejen, sklepam da je "Mapa" na namizju,
@@ -126,80 +154,31 @@ def task(IP_malishell, file_rename_dirname, mv_src_dir, mv_dst_dir, cowsay_strin
# v mojimenik se nahaja mojimenikfile
# mama2 vsebuje "mama"
#Stirje subt-aski dodani.By Mihec.
- results = dict()
- conn = pxssh.pxssh()
- conn.login(IP_malishell, 'student', 'vaje')
- # preimenuj datoteke
- conn.sendline('/bin/ls -a1 {}'.format(file_rename_dirname))
- conn.prompt()
- results['preimenuj'] = conn.before
- # premakni datoteke s cim krajsim ukazom
- conn.sendline('/bin/ls -a1 {}'.format(mv_src_dir))
- conn.prompt()
- results['pre_mv_src'] = conn.before
- conn.sendline('/bin/ls -a1 {}'.format(mv_dst_dir))
- conn.prompt()
- results['pre_mv_dst'] = conn.before
- conn.sendline('/bin/ls -l ~/mv_ukaz')
- conn.prompt()
- results['mv_ls_size'] = conn.before
- conn.sendline('. ~/mv_ukaz')
- conn.prompt()
- conn.sendline('/bin/ls -a1 {}'.format(mv_src_dir))
- conn.prompt()
- results['post_mv_src'] = conn.before
- conn.sendline('/bin/ls -a1 {}'.format(mv_dst_dir))
- conn.prompt()
- results['post_mv_dst'] = conn.before
- # mama_ukaz
- #
- conn.sendline('cd /home/student/grep_test_dir')
- conn.prompt()
- conn.sendline('. ~/mama_ukaz')
- conn.prompt()
- conn.sendline('cat ~/napake.txt')
- conn.prompt()
- results['grep_napake'] = conn.before
- conn.sendline('cat ~/mama.txt')
- conn.prompt()
- results['grep_mama'] = conn.before
- # sledenje syslog
- conn.sendline('date')
- conn.prompt()
- conn.sendline('/usr/local/bin/syslog_spammer &')
- conn.prompt()
- results['syslog_start_time'] = conn.before
- conn.sendline('/home/student/syslog_ukaz.sh')
- conn.prompt()
- results['syslog_result'] = conn.before
- conn.sendline('date')
- conn.prompt()
- results['syslog_end_time'] = conn.before
- conn.sendline('cowsay "{}"'.format(cowsay_string))
- conn.prompt()
- results['cowsay'] = conn.before
+ results = collections.defaultdict(str)
+ try:
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(IP_malishell, 'student', 'vaje')
+ results['ssh'] = True
+ for test, command in commands:
+ s.sendline(command)
+ s.prompt()
+ if test:
+ results[test] = s.before
+ s.logout()
+ except Exception as ex:
+ results['ssh'] = str(ex)
+
try:
results['curl_env'] = os.environ['images']
except:
results['curl_env'] = ''
- conn.sendline('cat {}/count.txt'.format(wc_dirname))
- conn.prompt()
- results['wc_origfile'] = conn.before
- conn.sendline('cat {}/lines.txt'.format(wc_dirname))
- conn.prompt()
- results['wc_lines'] = conn.before
- conn.logout()
- #results['curl'] = subprocess.check_output(["cat","/home/student/Desktop/website.txt"])
+ #results['curl'] = subprocess.check_output(["cat","/home/student/Desktop/website.txt"])
#results['chkimages'] = subprocess.check_output(["curl www.24ur.com >> dlg.txt && cat dlg.txt | grep -c ","images"])
-
#results['count'] = subprocess.check_output(["wc","/home/student/Desktop/count.txt"])
-
#results['lines'] = subprocess.check_output(["cat","/home/student/Desktop/lines.txt"])
-
#results['cowsay'] = subprocess.check_output(["dpkg --get-selections | grep","cowsay"])
- #results['phttp'] = subprocess.check_output(["lsof -i ",":8080"])
return results
def gen_params(user_id, params_meta):
@@ -218,7 +197,6 @@ def gen_params(user_id, params_meta):
params['curl_n_images'] = str(r.randint(30,100))
params['wc_dirname'] = homedir + "".join([r.choice("rstuvxz") for i in range(8)])
params['wc_n_lines'] = str(r.randint(200, 600))
- #params['phttp'] = "8080"
#params['images'] = subprocess.check_output(["echo","$images"])
return params
@@ -232,22 +210,20 @@ def task_check(results, params):
for i in range(20):
fnames.append("".join([ r.choice("_abcdefghijk") for j in range(8)]))
#TO FINISH SCORING WE REQUIRE DICT KEYS AND FUNCTIONS gen_params AND task TO BE FINISHED
- #POINTS FOR EACH TASK MAY BE ADJUSTED IN THE FUTURE
- #TASK 1
- # print( results['preimenuj'])
+
+ # preimenuj 1
lines = results['preimenuj'].split("\n")
task1_ok = len(lines) == len(fnames) + 4
task1_ok = task1_ok and lines[0].find(params['file_rename_dirname']) >= 0
task1_ok = task1_ok and lines[1].strip() == "."
task1_ok = task1_ok and lines[2].strip() == ".."
- # print task1_ok
for fname in fnames:
- # print task1_ok, fname, results['preimenuj'].find(fname)
task1_ok = task1_ok and results['preimenuj'].find(fname) > 0
if task1_ok:
score += 2
else:
hints += ["wrong dash rename"]
+
# premakni datoteke s cim krajsim ukazom
fnames = []
try:
@@ -264,6 +240,8 @@ def task_check(results, params):
score += 1
else:
hints += ["wrong mv_command size or owner"]
+
+ # rename files
pre_src = set([i.strip() for i in results['pre_mv_src'].split('\n')[3:-1]])
pre_dst = set([i.strip() for i in results['pre_mv_dst'].split('\n')[3:-1]])
task2_ok = task2_ok and pre_src == set(fnames)
@@ -276,8 +254,8 @@ def task_check(results, params):
score += 1
else:
hints += ["wrong rename files"]
+
# mama_ukaz
- #
task3_ok = True
mama_fnames = []
for i in range(20):
@@ -291,8 +269,6 @@ def task_check(results, params):
linknames = []
for i in range(20):
linknames.append("".join([ r.choice("123456789abcdefghijk") for j in range(8)]))
- #print( results['grep_mama'])
- #print( results['grep_napake'])
for i in dirnames + linknames + papa_fnames:
if (i not in papa_fnames) and results['grep_napake'].find(i) < 0:
task3_ok = False
@@ -310,6 +286,7 @@ def task_check(results, params):
score += 2
else:
hints += ["mama cries"]
+
# sledenje syslog
#print( results['syslog_start_time'])
#print( results['syslog_result'])
@@ -321,7 +298,7 @@ def task_check(results, params):
score += 1
else:
hints += ["wrong syslog count"]
- #
+
task5_ok = True
try:
assert int(results['curl_env'].strip()) == int(params['curl_n_images'])
diff --git a/kpov_judge/tasks/mock_entrance_exam/task.py b/kpov_judge/tasks/mock_entrance_exam/task.py
index a6e3c8c..682ec0d 100644
--- a/kpov_judge/tasks/mock_entrance_exam/task.py
+++ b/kpov_judge/tasks/mock_entrance_exam/task.py
@@ -138,36 +138,39 @@ def task(student_IP, net_prog_name,
param_gen_seed):
from pexpect import pxssh
import random
- conn = pxssh.pxssh()
- conn.login(student_IP, 'student', 'vaje')
- results = dict()
+ results = {}
r = random.Random(int(param_gen_seed))
- env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
-
- arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
- stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
- conn.sendline('ls -l {}'.format(P_script))
- conn.prompt()
- results['script_ls'] = conn.before
- conn.sendline('ls -l {}'.format(P_executable))
- conn.prompt()
- results['executable_ls'] = conn.before
- conn.sendline('export {}={}; {}'.format(env_c, env_val, P_script))
- conn.prompt()
- results['script_run'] = conn.before
- conn.sendline('cat {}'.format(out_stderr_c))
- conn.prompt()
- results['script_stderr'] = conn.before
- conn.sendline('cat {}'.format(out_stdout_c))
- conn.prompt()
- results['script_stdout'] = conn.before
- conn.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val))
- conn.prompt()
- results['prog_stdout'] = conn.before
- conn.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val))
- conn.prompt()
- results['prog_stderr'] = conn.before
- conn.logout()
+ try:
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(student_IP, 'student', 'vaje')
+ results['ssh'] = True
+ env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
+ arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
+ stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
+ s.sendline('ls -l {}'.format(P_script))
+ s.prompt()
+ results['script_ls'] = s.before
+ s.sendline('ls -l {}'.format(P_executable))
+ s.prompt()
+ results['executable_ls'] = s.before
+ s.sendline('export {}={}; {}'.format(env_c, env_val, P_script))
+ s.prompt()
+ results['script_run'] = s.before
+ s.sendline('cat {}'.format(out_stderr_c))
+ s.prompt()
+ results['script_stderr'] = s.before
+ s.sendline('cat {}'.format(out_stdout_c))
+ s.prompt()
+ results['script_stdout'] = s.before
+ s.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val))
+ s.prompt()
+ results['prog_stdout'] = s.before
+ s.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val))
+ s.prompt()
+ results['prog_stderr'] = s.before
+ s.logout()
+ except pxssh.ExceptionPxssh as ex:
+ results['ssh'] = str(ex)
return results
def gen_params(user_id, params_meta):
@@ -209,6 +212,8 @@ def task_check(results, params):
return(s_out, s_err, retval)
score = 0
hints = []
+ if results['ssh'] is not True:
+ hints += ['ssh failed: ' + results['ssh']]
r = random.Random(int(params['param_gen_seed']))
env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
diff --git a/kpov_judge/tasks/public_ip_ssh/task.py b/kpov_judge/tasks/public_ip_ssh/task.py
index a566aa5..02c4ac5 100644
--- a/kpov_judge/tasks/public_ip_ssh/task.py
+++ b/kpov_judge/tasks/public_ip_ssh/task.py
@@ -43,17 +43,15 @@ def gen_params(user_id, params_meta):
def task_check(results, params):
from pexpect import pxssh
- import pexpect
- results = dict()
- s = pxssh.pxssh()
- peer_ip, peer_user, peer_passwd = params['peer_ip'], params['peer_user'], params['peer_passwd']
+ ip, user, passwd = params['peer_ip'], params['peer_user'], params['peer_passwd']
+ results = {}
try:
- s.login(peer_ip, peer_user, peer_passwd)
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(ip, user, passwd)
s.logout()
- except Exception as e:
- return 0, [str(e)]
- return 10, []
+ return 10, []
+ except Exception as ex:
+ return 0, [str(ex)]
def prepare_disks(templates, task_params, global_params):
write_default_config(templates['simpleArbiter'], global_params)
- # print d1.ls('/')
diff --git a/kpov_judge/tasks/rename_grep_network/task.py b/kpov_judge/tasks/rename_grep_network/task.py
index e8ce0b2..948edcf 100644
--- a/kpov_judge/tasks/rename_grep_network/task.py
+++ b/kpov_judge/tasks/rename_grep_network/task.py
@@ -139,26 +139,6 @@ params_meta = {
'generated': True,
},
- # 'progname': {
- # 'descriptions': {
- # 'si': 'Ime programa',
- # 'en': 'Program filename',
- # },
- # 'w': False,
- # 'public': True,
- # 'type': 'filename',
- # 'generated': True,
- # },
- 'pubseed': {
- 'descriptions': {
- 'si': 'Nekaj nepredvidenega',
- 'en': 'A random seed',
- },
- 'w': False,
- 'public': True,
- 'type': None,
- 'generated': True,
- },
'rndseed': {
'descriptions': {
'si': 'random seed za skrito datoteko',
@@ -171,30 +151,30 @@ params_meta = {
},
}
-def task(testip, testuser, passwd, mntdir, magicstr, pubseed):
+def task(testip, testuser, passwd, mntdir, magicstr):
+ import collections
from pexpect import pxssh
- import random
- target = pxssh.pxssh()
- target.login(testip, testuser, passwd)
- target.sendline('ls ~/')
- target.prompt()
- home_ls = target.before
- target.sendline('cat ~/*I*.txt')
- target.prompt()
- dst_file_contents = target.before
- target.sendline('ls -l ~/*I*.txt')
- target.prompt()
- dst_ls = target.before
- target.sendline('mount')
- target.prompt()
- mnt = target.before
- results = {
- 'home_ls': home_ls,
- 'dst_ls': dst_ls,
- 'mnt': mnt,
- 'dst_file_contents': dst_file_contents,
- }
- target.logout()
+
+ commands = [
+ ('home_ls', 'ls ~/'),
+ ('dst_file_contents', 'cat ~/*I*.txt'),
+ ('dst_ls', 'ls -l ~/*I*.txt'),
+ ('mnt', 'mount'),
+ ]
+
+ results = collections.defaultdict(str)
+ try:
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(testip, testuser, passwd)
+ results['ssh'] = True
+ for test, command in commands:
+ s.sendline(command)
+ s.prompt()
+ if test:
+ results[test] = s.before
+ s.logout()
+ except Exception as ex:
+ results['ssh'] = str(ex)
return results
def gen_params(user_id, params_meta):
@@ -207,10 +187,6 @@ def gen_params(user_id, params_meta):
params['passwd'] = kpov_random_helpers.alnum_gen(r, 8)
params['magicstr'] = "".join([r.choice("qwerztlpoQWERTPOL") for i in range(10)])
params['mntdir'] = "/" + kpov_random_helpers.default_generators['filename'](r)
- # params['progname'] = kpov_random_helpers.default_generators['filename'](r)
- # while params['dstfile'] == params['progname']:
- # params['progname'] = kpov_random_helpers.default_generators['filename'](r)
- params['pubseed'] = kpov_random_helpers.alnum_gen(r, 8)
params['rndseed'] = kpov_random_helpers.alnum_gen(r, 8)
return params
@@ -220,6 +196,8 @@ def task_check(results, params):
import re
hints = []
score = 0
+ if results['ssh'] is not True:
+ hints += ['ssh failed: ' + results['ssh']]
hidden_contents = params['magicstr']
r = random.Random(params['rndseed'])
dstfile = "".join([r.choice("qQoOp") for i in range(64)]) + "I.txt"
@@ -242,7 +220,7 @@ def task_check(results, params):
if results["dst_file_contents"] == expected_contents:
score += 3
else:
- diff_pos = ""
+ diff_pos = (0, "")
for i, c in enumerate(results["dst_file_contents"]):
if len(expected_contents) < i or c != expected_contents[i]:
start = max(0, i-10)
diff --git a/kpov_judge/tasks/set_ip_static_dhcp/task.py b/kpov_judge/tasks/set_ip_static_dhcp/task.py
index 0553585..f400b6e 100644
--- a/kpov_judge/tasks/set_ip_static_dhcp/task.py
+++ b/kpov_judge/tasks/set_ip_static_dhcp/task.py
@@ -84,37 +84,29 @@ params_meta = {
}
def task(IP_NM, DNS_NM, IP_static, DNS_static):
+ import collections
from pexpect import pxssh
- import pexpect
- results = dict()
- peer_user = 'student'
- peer_passwd = 'vaje'
- # sA - network manager
- sA = pxssh.pxssh()
- sA.login(IP_NM, peer_user, peer_passwd)
- sA.sendline('nmcli -c no d')
- sA.prompt()
- results['NM_nmcli'] = sA.before
- sA.sendline('nslookup www.arnes.si')
- sA.prompt()
- results['NM_nslookup'] = sA.before
- sA.logout()
- # sB - brez network manager
- sB = pxssh.pxssh()
- sB.login(IP_static, peer_user, peer_passwd)
- sB.sendline('nmcli -c no d')
- sB.prompt()
- results['static_nmcli'] = sB.before
- sB.sendline('nslookup www.arnes.si')
- sB.prompt()
- results['static_nslookup'] = sB.before
- sB.logout()
+
+ tests = ['nmcli -c no d', 'nslookup www.arnes.si']
+ results = collections.defaultdict(str)
+
+ for name, host in [('nm', IP_NM), ('static', IP_static)]:
+ try:
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(host, 'student', 'vaje')
+ results['ssh-'+name] = True
+ for test in tests:
+ s.sendline(test)
+ s.prompt()
+ results[test.split()[0]+'-'+name] = s.before
+ s.logout()
+ except Exception as ex:
+ results['ssh'] = str(ex)
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 = kpov_random_helpers.IPv4_subnet_gen(r, '10.94.96.0/19', 25)
params['DNS_NM'] = r.choice(dns_servers)
@@ -126,29 +118,31 @@ def task_check(results, params):
import re
score = 0
hints = []
- #print results, params
- if results['NM_nslookup'].find(params['DNS_NM']) > -1:
- # print "NM_nslookup OK"
+ if results['ssh-nm'] is True:
+ score += 1
+ else:
+ hints += ['mali ssh failed: ' + results['ssh-nm']]
+ if results['ssh-static'] is True:
+ score += 1
+ else:
+ hints += ['malibrez ssh failed: ' + results['ssh-static']]
+ if params['DNS_NM'] in results['nslookup-nm']:
score += 2
else:
hints += ['NM nslookup incorrect']
- if results['static_nslookup'].find(params['DNS_static']) > -1:
- # print "static_nslookup OK"
+ if params['DNS_static'] in results['nslookup-static']:
score += 2
else:
hints += ['static nslookup incorrect']
- if re.search(r'e(th0|np0s3|ns3) +ethernet +connected', results['NM_nmcli']):
- # print "NM_nmcli OK"
- score += 3
+ if re.search(r'e(th0|np0s3|ns3) +ethernet +connected', results['nmcli-nm']):
+ score += 2
else:
hints += ['nmcli incorrect']
- if re.search(r'e(th0|np0s3|ns3) +ethernet +unmanaged', results['static_nmcli']):
- # print "static_nmcli OK"
- score += 3
+ if re.search(r'e(th0|np0s3|ns3) +ethernet +unmanaged', results['nmcli-static']):
+ score += 2
else:
hints += ['nmcli on malibrez incorrect']
return score, hints
def prepare_disks(templates, task_params, global_params):
write_default_config(templates['simpleArbiterDhcpGW'], global_params)
-
diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py
index eadcca7..2e83ead 100644
--- a/kpov_judge/tasks/set_motd/task.py
+++ b/kpov_judge/tasks/set_motd/task.py
@@ -76,35 +76,36 @@ params_meta = {
def task(peer_ip, peer_user, peer_passwd, niz):
"Check whether ssh works"
+ import collections
from pexpect import pxssh
- import pexpect
- # return {"hello": 'kitty'}
- results = dict()
- s = pxssh.pxssh()
- #TODO (polz): tole bi utegnilo delovati http://pexpect.sourceforge.net/pxssh.html. Testirajte
- s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False)
- # print s.before
- # s.prompt()
- #Ce na serverju iz datoteke /var/run/motd.dynamic pobrisemo znak '#' bi moralo delovati.
-
- # temp = s.before # print everything before the prompt.
- #TODO (polz): tole ni pravi pristop. Problem je bil v tem, da pxssh ni prav zaznal, kdaj je prijavljen. Glej link zgoraj.
- results['motd'] = s.before # print everything before the prompt.
+ results = collections.defaultdict(str)
+ try:
+ s = pxssh.pxssh(encoding='utf-8')
+ s.login(peer_ip, peer_user, peer_passwd,
+ original_prompt=r'{0}@.*:\~\$'.format(peer_user),
+ auto_prompt_reset=False)
+ results['ssh'] = True
+ results['motd'] = s.before
+ s.logout()
+ except Exception as ex:
+ results['ssh'] = str(ex)
return results
- #
-
+
def gen_params(user_id, params_meta):
return kpov_random_helpers.default_gen(user_id, params_meta)
def task_check(results, params):
- #print task_url
- #print params
- #print results
niz = params['niz']
score = 0
hints = []
- if (results['motd'].find(niz) > -1):
- score += 10
+ if results['ssh'] is True:
+ score += 2
+ else:
+ hints += ['ssh failed: ' + results['ssh']]
+ if niz in results['motd']:
+ score += 8
+ else:
+ hints += ['wrong motd:\n' + results['motd'] + '\n']
return score, hints
def prepare_disks(templates, task_params, global_params):