4 from scp import SCPClient
7 yumOpt = "sudo -S yum -y --nogpgcheck "
9 # Functions used for the php module (you need to install an http server)
11 execute(yumOpt+" install php", ssh)
12 execute("sudo -S /sbin/service httpd restart", ssh)
15 execute(yumOpt+" remove php", ssh)
17 # Functions used for the X redirection using ssh
18 def setXRedirect(ssh):
19 # Installing X11 system and an alternate ssh server
20 execute(yumOpt+" install xorg-x11-xauth", ssh)
23 def removeXRedirect(ssh):
24 # Remove X11 system and the alternate ssh server
25 execute(yumOpt+" remove xorg-x11-xauth", ssh)
28 # Functions used for an http server
29 def setHttpd(ssh, port, hostUrl):
31 execute(yumOpt+" install -y httpd", ssh)
32 SCPClient(ssh.get_transport()).put("./configService/httpd.conf", "~")
33 SCPClient(ssh.get_transport()).put("./configService/index.html", "~")
34 execute("sudo -S mv ~/index.html /var/www/html/", ssh)
35 execute("sudo -S echo \"<html>You are on "+str(hostUrl)+"</html>\" >> /var/www/html/index.html", ssh)
36 execute("sudo -S dd if=/dev/zero of=/var/www/html/file1Mo bs=1M count=1", ssh)
37 execute("sudo -S chmod a+r /var/www/html/file1Mo", ssh)
38 execute("sudo -S mv ~/httpd.conf /etc/httpd/conf/", ssh, display = True)
39 execute("sudo -S chown root:root /etc/httpd/conf/httpd.conf", ssh, display = True)
40 execute("sudo -S sed -i -e \"s/Listen \\*:80/Listen \\*:"+str(port)+"/g\" /etc/httpd/conf/httpd.conf", ssh)
42 while(returnCode != 0):
44 returnCode = execute("sudo -S /sbin/service httpd restart", ssh, display = True)
47 execute("sudo -S sed -i -e \"s/Listen \\*:"+str(port)+"/Listen \\*:"+str(port+1)+"/g\" /etc/httpd/conf/httpd.conf", ssh)
52 #Remove the httpd service
53 execute(yumOpt+" remove httpd", ssh)
54 execute("sudo -S rm -rf /etc/httpd/*", ssh)
57 # Functions used for wireshark traffic analyzer (you have to install X redirection)
58 def setWireshark(ssh):
60 execute(yumOpt+" install wireshark wireshark-gnome", ssh)
61 execute(yumOpt+" install wireshark xorg-x11-fonts-Type1", ssh)
63 def removeWireshark(ssh):
65 execute(yumOpt+" remove wireshark wireshark-gnome", ssh)
66 execute(yumOpt+" remove wireshark xorg-x11-fonts-Type1", ssh)
68 # Functions used for the browser firefox (you have to install X redirection)
71 execute(yumOpt+" install firefox", ssh)
72 execute("sudo -S sh -c \"dbus-uuidgen > /var/lib/dbus/machine-id\"", ssh)
74 def removeFirefox(ssh):
76 execute(yumOpt+" remove firefox", ssh)
79 # Function used to execute a command on a remote host using ssh
80 def execute(command, ssh, display=False, retour=False):
82 stdin, stdout, stderr = ssh.exec_command(command)
84 # Wait for the end of the command
85 while not stdout.channel.exit_status_ready():
89 splitted = err.splitlines()
91 print "\tError in execution"
95 for line in stdout.read().splitlines():
99 return stdout.channel.recv_exit_status()