#!/bin/bash # Deploy the web security demos on virtual network # # Example usage: # vn-deploywebdemos # # Assumptions: # - topology 7 has already been created and nodes are running # # For more info see: http://sandilands.info/sgordon/virtnet # # $Revision$ # $Author$ # $Date$ # $URL$ # First inform user that topology must be created first echo "vn: To deploy the web demos, topology 7 must have been created and" echo "vn: all 5 nodes in the topology are running. If they are not running" echo "vn: then press 'n' now." echo "vn: Are you ready to proceed? y/n" read proceed if [ "${proceed}" != "y" ]; then echo "vn: If you haven't created topology 7 you can do so with:" echo "vn: bash vn-createtopology 7" echo "vn: If you haven't started the nodes you can do so with:" echo "vn: bash vn-ssh 1" echo "vn: bash vn-ssh 2" echo "vn: bash vn-ssh 3" echo "vn: bash vn-ssh 4" echo "vn: bash vn-ssh 5" echo "vn: Exiting vn-deploywebdemos as user is not ready to proceed."; exit 1; fi # Script parameters # Path for virtnet directory on host, e.g. /home/user/svn/virtnet/ virtnethostpath="`dirname $BASH_SOURCE`/../../" # Path for virtnet directory on guest, e.g. /home/network/virtnet virtnetpath="/home/network/virtnet" echo -n "vn: Checking if all nodes exist and are running ..." # Check that nodes 1 to 5 exist and are running for i in 1 2 3 4 5; do VBoxManage list vms | cut -d "\"" -f 2 | grep -w "node${i}" > /dev/null node_not_exist=$? if [ "${node_not_exist}" != "0" ]; then echo " " echo "vn: Error: node${i} does not exist. You must first create topology 7" echo "vn: before deploying the web demos. To create topology 7 run:" echo "vn: bash vn-createtopology 7" echo "vn: and then start all 5 nodes before running vn-deploywebdemos" exit 1; fi VBoxManage list runningvms | cut -d "\"" -f 2 | grep -w "node${i}" > /dev/null node_not_running=$? if [ "${node_not_running}" != "0" ]; then echo " " echo "vn: Error: node${i} exists but is not running. You must start all " echo "vn: 5 nodes before deploying web demos. To start them run:" echo "vn: bash vn-ssh 1" echo "vn: bash vn-ssh 2" echo "vn: bash vn-ssh 3" echo "vn: bash vn-ssh 4" echo "vn: bash vn-ssh 5" echo "vn: and then try vn-deploywebdemos again." exit 1; fi done echo "ok." # SSH command shortcuts: for both network and root users sn="ssh -o \"StrictHostKeyChecking no\" -l network -i ${virtnethostpath}data/defaults/home/network/.ssh/id_rsa localhost -p " sr="ssh -o \"StrictHostKeyChecking no\" -l root -i ${virtnethostpath}data/defaults/root/.ssh/id_rsa localhost -p " # node1 echo "vn: Deploying node 1 ..." port=2201 # Add domains to /etc/hosts files eval "${sr} ${port} 'echo "192.168.2.21 www.myuni.edu" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.freestuff.com" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.myuni.edu.gr" >> /etc/hosts'" # Copy Lynx configuration to save cookies eval "${sn} ${port} 'cp /home/network/virtnet/data/webdemos/grades/lynx.cfg /home/network/'" # node2 echo "vn: Deploying node 2 ..." port=2202 # Add domains to /etc/hosts files eval "${sr} ${port} 'echo "192.168.2.21 www.myuni.edu" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.freestuff.com" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.myuni.edu.gr" >> /etc/hosts'" # Copy Lynx configuration to save cookies eval "${sn} ${port} 'cp /home/network/virtnet/data/webdemos/grades/lynx.cfg /home/network/'" # node3 echo "vn: Deploying node 3 ..." port=2203 # Add domains to /etc/hosts files eval "${sr} ${port} 'echo "192.168.2.21 www.myuni.edu" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.freestuff.com" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.myuni.edu.gr" >> /etc/hosts'" # node4 echo "vn: Deploying node 4 ..." port=2204 # Add domains to /etc/hosts files eval "${sr} ${port} 'echo "192.168.2.21 www.myuni.edu" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.freestuff.com" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.myuni.edu.gr" >> /etc/hosts'" # Start mysql and apache servers eval "${sr} ${port} 'systemctl start mysql.service'" eval "${sr} ${port} 'systemctl start apache2.service'" # Create grades website eval "${sr} ${port} 'mkdir /var/www/html/grades'" eval "${sr} ${port} 'chown network.network /var/www/html/grades'" eval "${sn} ${port} 'cp /home/network/virtnet/data/webdemos/grades/www/* /var/www/html/grades/'" # Create databases eval "${sn} ${port} 'mysql --user=root --password=network < /home/network/virtnet/data/webdemos/grades/grades-users.sql'" eval "${sn} ${port} 'mysql --user=webdemo_grades --password=network webdemo_grades < /home/network/virtnet/data/webdemos/grades/grades-tables.sql'" # node5 echo "vn: Deploying node 5 ..." port=2205 # Add domains to /etc/hosts files eval "${sr} ${port} 'echo "192.168.2.21 www.myuni.edu" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.freestuff.com" >> /etc/hosts'" eval "${sr} ${port} 'echo "192.168.2.22 www.myuni.edu.gr" >> /etc/hosts'" # Start mysql and apache servers eval "${sr} ${port} 'systemctl start mysql.service'" eval "${sr} ${port} 'systemctl start apache2.service'" # Create ades fake website eval "${sr} ${port} 'mkdir /var/www/html/ades'" eval "${sr} ${port} 'chown network.network /var/www/html/ades'" eval "${sn} ${port} 'cp /home/network/virtnet/data/webdemos/ades/www/* /var/www/html/ades/'" # Create freestuff fake website eval "${sr} ${port} 'mkdir /var/www/html/freestuff'" eval "${sr} ${port} 'chown network.network /var/www/html/freestuff'" eval "${sn} ${port} 'cp /home/network/virtnet/data/webdemos/freestuff/www/* /var/www/html/freestuff/'" echo "vn: Deployment complete. Check above messages for any errors. A successful" echo "vn: deployment may print status/warning messages for nodes 4 and 5 such as:" echo "vn: mysql start/running, process xxxx" echo "vn: apache2: Could not reliably determine ..." echo "vn: These are NOT error messages. If you see messages other than these, then" echo "vn: maybe it is an error. If you cannot diagnose the error, try again with a" echo "vn: fresh set of 5 nodes."