diff --git a/nlvmi b/nlvmi index 0dcf6d9..db29daf 100755 --- a/nlvmi +++ b/nlvmi @@ -176,7 +176,10 @@ if [ $# -gt 0 ]; then vmstop $2 done if [[ $VMFOUND == "no" ]]; then echo "no VM with that name found!"; exit 1; fi) - fi + elif [ $1 == "checkvm" ]; then + if [ -z $2 ]; then echo "checkvm needs a vmname!"; exit 1; fi + if [ -e $RUNDIRECTORY/$2.pid ]; then echo $2 running; else echo $2 stopped; fi + fi else checkdb fi diff --git a/web/index.php b/web/index.php index ede6b68..02aa333 100644 --- a/web/index.php +++ b/web/index.php @@ -6,6 +6,15 @@ function clean($str) { $str = str_replace($search, $replace, $str); return $str; } + +function checkvm($vmname) { +$shellout = shell_exec("/usr/bin/wrap-nlvmi checkvm $vmname bla");//){ + if (preg_match_all('/running/', $shellout)){ + return 0; + } +return 1; +} + //read config file $configfile = new SplFileObject("/etc/nlvmi/nlvmi.conf"); while (!$configfile->eof()) { @@ -37,6 +46,26 @@ if ($config['DATABASETYPE']=="sqlite"){ } include('header.php'); $mode=""; +if (isset($_REQUEST['start'])){ + $vmname = clean($_REQUEST['start']); + $sql="SELECT * FROM vms WHERE vmname='$vmname'"; + $res = $db_handle->query($sql); + while ($row = $res->fetchArray(SQLITE3_ASSOC)){ + $shellout = shell_exec("/usr/bin/wrap-nlvmi start $vmname bla"); + echo $shellout; + } +} +if (isset($_REQUEST['stop'])){ + $vmname = clean($_REQUEST['stop']); + $sql="SELECT * FROM vms WHERE vmname='$vmname'"; + $res = $db_handle->query($sql); + while ($row = $res->fetchArray(SQLITE3_ASSOC)){ + if(checkvm($vmname)){ + $shellout = shell_exec("/usr/bin/wrap-nlvmi stop $vmname bla"); + echo $shellout; + } + } +} //form for edit and new vms if (isset($_REQUEST['edit'])){ @@ -173,7 +202,12 @@ $sql="SELECT * FROM vms"; $res = $db_handle->query($sql); echo "
"; while ($row = $res->fetchArray(SQLITE3_ASSOC)){ - echo "
$row[vmname]
edit
"; + if (checkvm($row['vmname'])){ + $button = "start"; + } else { + $button = "stop"; + } + echo "
$row[vmname]
edit $button
"; } echo "
"; ?>