Enhance, simplify and beautify DRAC & HPiLO support with expect scripts
[pcucontrol.git] / pcucontrol / support / pcuProxy.php
diff --git a/pcucontrol/support/pcuProxy.php b/pcucontrol/support/pcuProxy.php
new file mode 100644 (file)
index 0000000..3cfcc47
--- /dev/null
@@ -0,0 +1,62 @@
+<?php 
+
+function logit($string){
+               $f = fopen("output.log", 'a');
+               fwrite($f, $string);
+               fclose($f);
+}
+
+function run_hp_script($script, $host, $username, $password)
+{
+       $cmd = "hpilo/locfg.pl -s $host -f $script -u $username -p '$password' 2>&1"; 
+       logit("cmd: " . $cmd);
+       return system($cmd);
+
+               $f = fopen("output.log", 'a');
+               fwrite($f, print_r($_REQUEST, TRUE));
+               fclose($f);
+
+}
+
+       if ( isset($_REQUEST['hostname']) && 
+                isset($_REQUEST['username']) && 
+                isset($_REQUEST['password']) &&
+                isset($_REQUEST['model']) )
+       {
+               $host=$_REQUEST['hostname'];
+               $username=$_REQUEST['username'];
+               $password=$_REQUEST['password'];
+               $model=$_REQUEST['model'];
+               if ( isset($_REQUEST['dryrun']) ) 
+               {
+                       $dryrun = $_REQUEST['dryrun'];
+                       settype($dryrun, "boolean");
+               } else {
+                       $dryrun = TRUE;
+               }
+
+               logit(print_r($_REQUEST, TRUE));
+
+               if (strcmp($model,"HPiLOProxy") == 0) {
+                       if ( $dryrun ) 
+                       {
+                               run_hp_script("hpilo/iloxml/Get_Network.xml", $host, $username, $password);
+                       } else {
+                               run_hp_script("hpilo/iloxml/PowerOn_Server.xml", $host, $username, $password);
+                               echo run_hp_script("hpilo/iloxml/Reset_Server.xml", $host, $username, $password);
+                       }
+               } elseif ( strcmp($model,"OpenIPMIProxy") == 0 )
+               {
+                       # cmd = "ipmitool -I lanplus -H $host -U $username -P '$password' user list"
+                       # cmd = "ipmitool -I lanplus -H $host -U $username -P '$password' power cycle"
+                       echo system("which ipmitool 2>&1");
+               } else 
+               {
+                       echo "what do you want me to do with this?";
+               }
+
+       } else {
+               echo "Please provide hostname, username, and password";
+       }
+
+?>