diff --git a/web/index.php b/web/index.php index 1c88c2b..399b34a 100644 --- a/web/index.php +++ b/web/index.php @@ -17,34 +17,32 @@ $mode=""; function checkvm($vmname) { $shellout = shell_exec("/usr/bin/nlvmi checkvm $vmname bla");//){ -// echo $shellout; if (preg_match_all('/not running/', $shellout)){ return 1; } return 0; } function serverdepropdown($server, $val, $what){ - if ($what == "cdrom"){ - $dir = "isodirectory"; - $enddiv = ""; - } elseif (preg_match('/drive/', $what)) { - $dir = "vmdirectory"; - $enddiv=""; - } - echo "
$what
"; + if ($what == "cdrom"){ + $dir = "isodirectory"; + $enddiv = "
"; + } elseif (preg_match('/drive/', $what)) { + $dir = "vmdirectory"; + $enddiv=""; + } + echo "
$what
"; } //read config file @@ -96,9 +94,6 @@ if ($usersfound=="no"){ $_SESSION['isadmin']="1"; if (!isset($_POST['newusername'])){ echo "

You have no users in the datbase!


"; -// echo "Aborting...."; -// exit; - $mode="usermgmt"; } } elseif ((isset($_POST['login']))&&(isset($_POST['username']))&&(isset($_POST['password']))){ @@ -198,7 +193,41 @@ if (isset($_SESSION['username'])){ } } } - +//insert new server in db + if(isset($_POST['newservername'])){ + if($_SESSION['isadmin']!=1){ + echo "you are not allowed to add servers!"; + } else { + $newservername = clean($_POST['newhostname']); + $connectstring = clean($_POST['connectstring']); + $vmdirectory = clean($_POST['vmdirectory']); + $isodirectory = clean($_POST['isodirectory']); + $sqlu="INSERT INTO servers ('hostname','connectstring','vmdirectory','isodirectory') VALUES('$newservername',$connectstring','$vmdirectory','$isodirectory')"; + $res = $db_handle->query($sqlu); + echo "success"; + exit; + } + } +//update server in db + if(isset($_POST['changehostname'])){ + if($_SESSION['isadmin']!=1){ + echo "you are not allowed to change servers!"; + } else { + $newservername = clean($_POST['changehostname']); + $connectstring = clean($_POST['connectstring']); + $vmdirectory = clean($_POST['vmdirectory']); + $isodirectory = clean($_POST['isodirectory']); + $changeid = clean($_POST['changeid']); + $sql="UPDATE servers SET hostname='$newservername', connectstring='$connectstring', vmdirectory='$vmdirectory', isodirectory='$isodirectory' where id='$changeid'"; + if($db_handle->query($sql)){ + echo "success"; + exit; + } else { + echo "$sql"; + exit; + } + } + } //insert or update vm in db if(isset($_REQUEST['mode'])){ if($_REQUEST['mode']=="newvm"){ @@ -232,10 +261,7 @@ if (isset($_SESSION['username'])){ $res = $db_handle->exec($sql); echo "success"; exit; - -// $mode=""; } elseif ($_REQUEST['mode']=="editvm"){ -// $mode=""; $sql="UPDATE vms SET "; foreach(array_keys($_REQUEST) as $rkey){ if (($rkey!="mode")&&($rkey!="editid")&&($rkey!="rand")){ @@ -256,18 +282,16 @@ if (isset($_SESSION['username'])){ $sql = rtrim($sql, ','); $eid=clean($_REQUEST['editid']); $sql .= " WHERE id='$eid'"; -// if($db_handle->exec($sql)){ $res = $db_handle->exec($sql); echo "success"; - //echo $res; exit; - //} } } if (isset($_POST['serverbuttoni'])){ serverdepropdown($_POST['serverbuttoni'], "no cdrom", 'cdrom'); exit; - } elseif (isset($_POST['serverbuttona'])){ +//not nice, i know... Will do a function later... + } elseif (isset($_POST['serverbuttona'])){ serverdepropdown($_POST['serverbuttona'], "no drive1", 'drive1'); echo "
format1
"; exit; } + //ajax queries are all done, time for the header include('header.php'); @@ -337,6 +362,31 @@ if (isset($_SESSION['username'])){ } +//servermanagement + if (isset($_POST['servermgmt'])){ + $mode="servermgmt"; + if ($_SESSION['isadmin']=="1"){ + $sql="SELECT * FROM servers"; + $res = $db_handle->query($sql); + echo "
"; + //echo "
Username
Is Admin
New Password
"; + echo "

Existing servers

"; + echo "
hostname
connectstring
VM directory
ISO directory
"; + while ($row = $res->fetchArray(SQLITE3_ASSOC)){ + echo "
"; + echo "
"; + echo "
"; + echo "
"; + echo "
"; + } +//newserverform + echo "

Create a new server

"; + echo "
"; + echo "
"; + echo "
"; + echo "
"; + } + } //start vm @@ -423,7 +473,6 @@ if (isset($_SESSION['username'])){ $val = ""; } $colname=$arrColnames[$col]; - //$placeh=$placehold[$arrColnames[$col]]; if ($arrColnames[$col] == "bootoption"){ if($val=="") { $val="c"; @@ -433,7 +482,6 @@ if (isset($_SESSION['username'])){ echo "c"; echo "d"; echo ""; -// echo "$arrColnames[$col]
"; } elseif ($arrColnames[$col] == "user"){ if ($val=="") { $val=$_SESSION['username']; @@ -470,8 +518,6 @@ if (isset($_SESSION['username'])){ echo "
"; serverdepropdown($server, $val, "cdrom"); echo "
"; -// } elseif (preg_match('/format/', $arrColnames[$col])) { -// echo "
$arrColnames[$col]
"; } elseif (preg_match('/tapdev/', $arrColnames[$col])) { echo "
$arrColnames[$col]
"; } elseif (preg_match('/macaddr/', $arrColnames[$col])) { @@ -491,14 +537,6 @@ if (isset($_SESSION['username'])){ echo "$rows[hostname]"; } -// $vmdirs = explode('|', $config['VMDIRECTORY']); -// foreach($vmdirs as $vmdir){ -// $files = array_diff(scandir($vmdir), array('.', '..')); -// $files = array_values(array_filter($files)); -// for ($f=0; $f$vmdir/$files[$f]"; -// } -// } echo "
"; } else {