start stop in web

This commit is contained in:
mad 2018-08-12 20:21:33 +02:00
parent b6d400555e
commit e418137c2e
2 changed files with 39 additions and 2 deletions

5
nlvmi
View File

@ -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

View File

@ -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 "<div class=row>";
while ($row = $res->fetchArray(SQLITE3_ASSOC)){
echo "<div class=col style=\"border:solid 1px;\">$row[vmname]</br><a href=?edit=$row[id]>edit</a></div>";
if (checkvm($row['vmname'])){
$button = "start";
} else {
$button = "stop";
}
echo "<div class=col style=\"border:solid 1px;\">$row[vmname]</br><a class=\"btn btn-primary\" href=?edit=$row[id]>edit</a> <a href=?$button=$row[vmname] class=\"btn btn-primary\">$button</a></div>";
}
echo "</div></div></body></html>";
?>