From 4659d83ee6b84a53fb8fe7368f4168667861706b Mon Sep 17 00:00:00 2001
From: "mp7462@student.uni-lj.si"
 <mp7462@student.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>
Date: Mon, 15 Dec 2014 21:03:50 +0000
Subject: Added nmap and some other things in task() method

git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@81 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
---
 kpov_judge/tasks/openvpn_simple_smb/task.py | 39 ++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

(limited to 'kpov_judge/tasks')

diff --git a/kpov_judge/tasks/openvpn_simple_smb/task.py b/kpov_judge/tasks/openvpn_simple_smb/task.py
index 4ac5f76..86fba69 100644
--- a/kpov_judge/tasks/openvpn_simple_smb/task.py
+++ b/kpov_judge/tasks/openvpn_simple_smb/task.py
@@ -223,11 +223,44 @@ def task(IP_SimpleArbiterVPN, DNS_SimpleArbiterVPN, IP_VPNClient1, DNS_VPNClient
     output = sA.before
     results['SimpleArbiter_ping_C2'] = output
     
-    # TODO
+    ###
     # Check if both clients are connected to the correct VPN
     # (check if first 24 bits of IP addr are the same as the server's)
-    #sB.sendline('sudo apt-get install nmap --assume-yes')
-    #sB.sendline('sudo nmap -sP 10.8.0.0/24')
+    # a.k.a. the YES WE CAN method of checking things
+    # really, really hoping it has root privileges too
+    ###
+    ### Install nmap
+    # Check if root
+    sA.sendline('id -u')
+    sA.prompt()
+    uid = sA.before.split('\n')
+    uid = uid[1].rstrip()
+    #print uid
+    # If is isn't root
+    if ( uid != "0" ):
+        print "SimpleArbiter user must be root to continue with this step (installing nmap mostly)"
+    # If it is, we continue
+    else:
+        ### Install the nmap package
+        # Check if nmap is already installed
+        sA.sendline('dpkg-query -W nmap')
+        sA.prompt()
+        lines = sA.before.split('\n')
+        line = lines[1]
+        # If it isn't
+        if ( len(line.rstrip()) == 4 ):  # returns "nmap\r\n" if package isn't installed
+            sA.sendline('apt-get install nmap --assume-yes')
+        # If it is
+        else:
+            sA.sendline('')
+            #sA.wait()  # For some reason this hangs
+            sA.expect(".*#")  # Expecting a new line prompt (root's prompt ends with a #)
+            
+            # Run nmap on the VPN network
+            sA.sendline('nmap -sP 10.8.0.0/24')
+            sA.prompt()
+            results['SimpleArbiter_nmap_results'] = sA.before
+    
     
     
     ######
-- 
cgit v1.2.1