// Path: src/core/exec/ManageExec.java
// public class ManageExec {
// 
// 	private String login;
// 	private String user;
// 	private String ip;
// 	private String port;
// 	private String cmd;
// 	private OutputStream out;
// 
// 	public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// 		this.login = login;
// 		this.user = user;
// 		this.ip = ip;
// 		this.port = port;
// 		this.cmd = cmd;
// 		this.out = out;
// 	}
// 
// 	public ProcessExec manage() {
// 		try {
// 			ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// 					+ this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// 			exec1.writeAllClose(this.cmd.getBytes());
// 			exec1.waitFor();
// 			ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// 					+ this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// 			Thread.sleep(500);
// 			PasswordExec pwd = new PasswordExec(login);
// 			String pass = pwd.getPassword() + "\n";
// 			exec2.writeAllOpen(pass.getBytes());
// 			return exec2;
// 		} catch (Exception e1) {
// 			e1.printStackTrace();
// 		}
// 		return null;
// 	}
// 
// 	public void manageBlock() {
// 		ProcessExec exec = manage();
// 		exec.waitFor();
// 	}
// 
// }
// 
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
// 
// 	public String[] getServerLabels();
// 
// 	public String[] getDeviceLabels();
// 
// 	public String[] getDeviceMacs();
// 
// 	public String[] getServerProfiles(String server);
// 
// 	public String getServerData(String server, String label);
// 
// 	public String getServerUser(String server);
// 
// 	public String getServerIP(String server);
// 
// 	public String getServerPort(String server);
// 	
// 	public String getServerUpdate(String server);
// }
// 
// Path: src/core/iface/IProfile.java
// public interface IProfile {
// 
// 	public String getLabel();
// 
// 	public boolean isSingleton();
// 
// 	public Vector<IProfile> getUnits(String server, INetworkData data);
// 
// }
// 
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
// 
// 	public String genAudit();
// 
// 	public String genConfig();
// 
// 	public String genDryRun();
// 
// }
// 
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
// 
// 	protected String test;
// 	protected String result;
// 
// 	protected SimpleUnit() {
// 	}
// 
// 	public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// 		super(name, precondition, config, audit);
// 		this.test = test;
// 		this.result = result;
// 	}
// 
// 	protected String getAudit() {
// 		String auditString = "out=$(" + super.getAudit() + ");\n";
// 		auditString += "test=\"" + getTest() + "\";\n";
// 		
// 		if (getResult().equals("fail"))
// 			auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// 		else
// 			auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// 		auditString += "\t" + getLabel() + "=0;\n";
// 		auditString += "else\n";
// 		auditString += "\t" + getLabel() + "=1;\n";
// 		auditString += "fi ;\n";
// 		return auditString;
// 	}
// 
// 	protected String getTest() {
// 		return this.test;
// 	}
// 
// 	protected String getResult() {
// 		return this.result;
// 	}
// 
// }


import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit;
		ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
				data.getServerPort(server), line, out);
		exec.manageBlock();
	}
	
	private String getAction(String action, String server) {
		System.out.println("=======================" + this.getLabel() + ":" + server + "==========================");
		String line = this.getHeader(server, action) + "\n";
		Vector<IProfile> serverRules = this.rules.get(server);
		
		String configcmd = "";
		if (data.getServerUpdate(server).equals("true")) {
			configcmd = "sudo apt-get --assume-yes upgrade;";
		} else {
			configcmd = "echo \"$out\";";
		}
		serverRules.insertElementAt(new SimpleUnit("update", "proceed", configcmd,
				"sudo apt-get update > /dev/null; sudo apt-get --assume-no upgrade | grep \"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\";",
				"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "pass"), 0);
		
		for (int i = 0; i < serverRules.size(); i++) {
			IUnit unit = (IUnit) serverRules.elementAt(i);
			System.out.println(unit.getLabel());
			line += "#============ " + serverRules.elementAt(i).getLabel() + " =============\n";
			line += getText(action, unit) + "\n";
		}
		line += this.getFooter(server, action);
		return line;
	}
	
// Path: src/core/exec/ManageExec.java
// public class ManageExec {
// 
// 	private String login;
// 	private String user;
// 	private String ip;
// 	private String port;
// 	private String cmd;
// 	private OutputStream out;
// 
// 	public ManageExec(String login, String user, String ip, String port, String cmd, OutputStream out) {
// 		this.login = login;
// 		this.user = user;
// 		this.ip = ip;
// 		this.port = port;
// 		this.cmd = cmd;
// 		this.out = out;
// 	}
// 
// 	public ProcessExec manage() {
// 		try {
// 			ProcessExec exec1 = new ProcessExec("ssh -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// 					+ this.ip + " cat > script.sh; chmod +x script.sh;", out, System.err);
// 			exec1.writeAllClose(this.cmd.getBytes());
// 			exec1.waitFor();
// 			ProcessExec exec2 = new ProcessExec("ssh -t -t -o ConnectTimeout=3 -p " + this.port + " " + this.user + "@"
// 					+ this.ip + " ./script.sh; rm -rf script.sh; exit;", out, System.err);
// 			Thread.sleep(500);
// 			PasswordExec pwd = new PasswordExec(login);
// 			String pass = pwd.getPassword() + "\n";
// 			exec2.writeAllOpen(pass.getBytes());
// 			return exec2;
// 		} catch (Exception e1) {
// 			e1.printStackTrace();
// 		}
// 		return null;
// 	}
// 
// 	public void manageBlock() {
// 		ProcessExec exec = manage();
// 		exec.waitFor();
// 	}
// 
// }
// 
// Path: src/core/iface/INetworkData.java
// public interface INetworkData extends IData {
// 
// 	public String[] getServerLabels();
// 
// 	public String[] getDeviceLabels();
// 
// 	public String[] getDeviceMacs();
// 
// 	public String[] getServerProfiles(String server);
// 
// 	public String getServerData(String server, String label);
// 
// 	public String getServerUser(String server);
// 
// 	public String getServerIP(String server);
// 
// 	public String getServerPort(String server);
// 	
// 	public String getServerUpdate(String server);
// }
// 
// Path: src/core/iface/IProfile.java
// public interface IProfile {
// 
// 	public String getLabel();
// 
// 	public boolean isSingleton();
// 
// 	public Vector<IProfile> getUnits(String server, INetworkData data);
// 
// }
// 
// Path: src/core/iface/IUnit.java
// public interface IUnit extends IProfile {
// 
// 	public String genAudit();
// 
// 	public String genConfig();
// 
// 	public String genDryRun();
// 
// }
// 
// Path: src/core/unit/SimpleUnit.java
// public class SimpleUnit extends ComplexUnit {
// 
// 	protected String test;
// 	protected String result;
// 
// 	protected SimpleUnit() {
// 	}
// 
// 	public SimpleUnit(String name, String precondition, String config, String audit, String test, String result) {
// 		super(name, precondition, config, audit);
// 		this.test = test;
// 		this.result = result;
// 	}
// 
// 	protected String getAudit() {
// 		String auditString = "out=$(" + super.getAudit() + ");\n";
// 		auditString += "test=\"" + getTest() + "\";\n";
// 		
// 		if (getResult().equals("fail"))
// 			auditString += "if [ \"$out\" = \"$test\" ] ; then\n";
// 		else
// 			auditString += "if [ \"$out\" != \"$test\" ] ; then\n";
// 		auditString += "\t" + getLabel() + "=0;\n";
// 		auditString += "else\n";
// 		auditString += "\t" + getLabel() + "=1;\n";
// 		auditString += "fi ;\n";
// 		return auditString;
// 	}
// 
// 	protected String getTest() {
// 		return this.test;
// 	}
// 
// 	protected String getResult() {
// 		return this.result;
// 	}
// 
// }


// Path: src/core/model/NetworkModel.java
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
import core.exec.ManageExec;
import core.iface.INetworkData;
import core.iface.IProfile;
import core.iface.IUnit;
import core.unit.SimpleUnit;

		ManageExec exec = new ManageExec("testlogin", data.getServerUser(server), data.getServerIP(server),
				data.getServerPort(server), line, out);
		exec.manageBlock();
	}
	
	private String getAction(String action, String server) {
		System.out.println("=======================" + this.getLabel() + ":" + server + "==========================");
		String line = this.getHeader(server, action) + "\n";
		Vector<IProfile> serverRules = this.rules.get(server);
		
		String configcmd = "";
		if (data.getServerUpdate(server).equals("true")) {
			configcmd = "sudo apt-get --assume-yes upgrade;";
		} else {
			configcmd = "echo \"$out\";";
		}
		serverRules.insertElementAt(new SimpleUnit("update", "proceed", configcmd,
				"sudo apt-get update > /dev/null; sudo apt-get --assume-no upgrade | grep \"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\";",
				"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "pass"), 0);
		
		for (int i = 0; i < serverRules.size(); i++) {
			IUnit unit = (IUnit) serverRules.elementAt(i);
			System.out.println(unit.getLabel());
			line += "#============ " + serverRules.elementAt(i).getLabel() + " =============\n";
			line += getText(action, unit) + "\n";
		}
		line += this.getFooter(server, action);
		return line;
	}
	
	private String getText(String action, IUnit unit) {