start stop in web
This commit is contained in:
parent
b6d400555e
commit
e418137c2e
3
nlvmi
3
nlvmi
|
@ -176,6 +176,9 @@ if [ $# -gt 0 ]; then
|
|||
vmstop $2
|
||||
done
|
||||
if [[ $VMFOUND == "no" ]]; then echo "no VM with that name found!"; exit 1; 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
|
||||
|
|
|
@ -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>";
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue