introduce image management
This commit is contained in:
165
web/index.php
165
web/index.php
@@ -36,7 +36,7 @@ function serverdepropdown($server, $val, $what){
|
||||
echo "<div class=row><div class=col-md-1 style=text-align:right>$what</div><div class=col-md-2><div class=dropdown><button class=\"btn btn-secondary dropdown-toggle\" type=button id=".$what."button data-toggle=dropdown aria-haspopup=true aria-expanded=false>$val</button>";
|
||||
echo "<div class=dropdown-menu aria-labelledby=".$what."button>";
|
||||
echo "<a class=dropdown-item href=\"javascript:dropdown('".$what."button','')\">no $what</a><div class=dropdown-divider></div>";
|
||||
$shellout=shell_exec("/usr/bin/nlvmi listdir $server $dir");
|
||||
$shellout=shell_exec("/usr/bin/nlvmi listdirs $server $dir");
|
||||
$files = explode("\n", $shellout);
|
||||
for ($f=0; $f<count($files); $f++){
|
||||
$file = explode(" ", $files[$f]);
|
||||
@@ -57,6 +57,24 @@ function formatbuttons($label, $val){
|
||||
echo "<a class=dropdown-item href=\"javascript:dropdown('".$label."button$label','qcow2')\">qcow2</a>";
|
||||
echo "</div></div></div></div></div><input type=hidden id=".$label."button".$label."h name=$label value=\"$val\">";
|
||||
}
|
||||
|
||||
function listimg($server,$dir){
|
||||
$shellout=shell_exec("/usr/bin/nlvmi listdirs $server $dir");
|
||||
$files = explode("\n", $shellout);
|
||||
echo "<div id=listimgd class=form-group><label for=ld><select class=form-control id=ld>";
|
||||
for ($f=0; $f<count($files); $f++){
|
||||
$file = explode(" ", $files[$f]);
|
||||
$lastpart = count($file) -1;
|
||||
$filenames = explode('/', $file[$lastpart]);
|
||||
$filenamep = count($filenames) -1;
|
||||
$filename = $filenames[$filenamep];
|
||||
if((preg_match('/\//', $file[$lastpart]))&&(!preg_match('/^d/', $file[0]))){
|
||||
echo "<option>$filename</option>";
|
||||
}
|
||||
}
|
||||
echo "</select></label></div>";
|
||||
}
|
||||
|
||||
//read config file
|
||||
$configfile = new SplFileObject("/etc/nlvmi/nlvmi.conf");
|
||||
while (!$configfile->eof()) {
|
||||
@@ -217,9 +235,39 @@ if (isset($_SESSION['username'])){
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif
|
||||
//delete image
|
||||
((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="image")){
|
||||
if($_SESSION['isadmin']!=1){
|
||||
echo "you are not allowed to delete images!";
|
||||
} else {
|
||||
$server = clean($_POST['deletename']);
|
||||
$filec = explode(';', clean($_POST['deleteid']));
|
||||
|
||||
$sql="SELECT id FROM servers WHERE hostname='$server' AND (vmdirectory LIKE '%$filec[0]%' OR isodirectory LIKE '%$filec[0]%')";
|
||||
$res = $db_handle->query($sql);
|
||||
while ($row = $res->fetchArray(SQLITE3_ASSOC)){
|
||||
$shellout = shell_exec("/usr/bin/nlvmi delimg $server $filec[0]/$filec[1]");
|
||||
echo $shellout;
|
||||
}
|
||||
}
|
||||
} elseif
|
||||
//create new image
|
||||
(isset($_POST['createimg'])){
|
||||
$img = clean($_POST['createimg']);
|
||||
$server = clean($_POST['createimgs']);
|
||||
$dir = clean($_POST['createimgd']);
|
||||
$size = clean($_POST['createimgsize']);
|
||||
$sql="SELECT id FROM servers WHERE hostname='$server' AND (vmdirectory LIKE '%$dir%')";
|
||||
$res = $db_handle->query($sql);
|
||||
while ($row = $res->fetchArray(SQLITE3_ASSOC)){
|
||||
$shellout = shell_exec("/usr/bin/nlvmi createimg \"$server;$dir/$img\" $size");
|
||||
echo $shellout;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
//insert new user in db
|
||||
if(isset($_POST['newusername'])){
|
||||
elseif(isset($_POST['newusername'])){
|
||||
if($_SESSION['isadmin']!=1){
|
||||
echo "you are not allowed to add usernames!";
|
||||
} else {
|
||||
@@ -397,8 +445,6 @@ if (isset($_SESSION['username'])){
|
||||
$vid = clean($_REQUEST['vid']);
|
||||
$sql="SELECT prio FROM vms WHERE id='$vid'";
|
||||
$oldprio = $db_handle->query($sql)->fetchArray(SQLITE3_ASSOC)['prio'];
|
||||
//print_r($res);
|
||||
//echo "buu";
|
||||
if ($_REQUEST['neworder']=="up"){
|
||||
$newprio = $oldprio - 1;
|
||||
$sqlu="SELECT id FROM vms WHERE prio='$newprio'";
|
||||
@@ -409,7 +455,7 @@ if (isset($_SESSION['username'])){
|
||||
echo "success";
|
||||
exit;
|
||||
}
|
||||
}elseif ($_REQUEST['neworder']=="down"){
|
||||
} elseif ($_REQUEST['neworder']=="down"){
|
||||
$newprio = $oldprio + 1;
|
||||
$sqlu="SELECT id FROM vms WHERE prio='$newprio'";
|
||||
$oldid = $db_handle->query($sqlu)->fetchArray(SQLITE3_ASSOC)['id'];
|
||||
@@ -434,6 +480,113 @@ if (isset($_SESSION['username'])){
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['imagemgmt'])){
|
||||
$server = clean($_REQUEST['imagemgmt']);
|
||||
if ($server == "undefined"){
|
||||
$serverq = "";
|
||||
} else {
|
||||
$serverq = $server;
|
||||
}
|
||||
function imgdropdowns($db_handle, $server, $serverq, $dmode){
|
||||
$sqli="SELECT vmdirectory,isodirectory,hostname FROM servers";
|
||||
$resi = $db_handle->query($sqli);
|
||||
$sdropdown = "";
|
||||
$firstserver = "";
|
||||
while ($rowi = $resi->fetchArray(SQLITE3_ASSOC)){
|
||||
$hostname = $rowi['hostname'];
|
||||
if ($firstserver == ""){
|
||||
$firstserver = $hostname;
|
||||
}
|
||||
$vmdirs = explode(';', $rowi['vmdirectory']);
|
||||
$isodirs = explode(';', $rowi['isodirectory']);
|
||||
$imgdirs[$hostname] = array_merge($vmdirs, $isodirs);
|
||||
$sdropdown .= "<a class=dropdown-item href=\"javascript:imgdropdown('server','$hostname', '$vmdirs[0]', '$dmode')\">$hostname</a>";
|
||||
}
|
||||
if ($serverq == ""){
|
||||
$serverq = $firstserver;
|
||||
}
|
||||
$dropdowns = "<div class=row><div class=col-sm><div class=dropdown><button class=\"btn btn-secondary dropdown-toggle\" type=button id=imageserverbutton$dmode data-toggle=dropdown aria-haspopup=true aria-expanded=false>$serverq</button>";
|
||||
$dropdowns .= "<div class=dropdown-menu aria-labelledby=imageserverbutton>$sdropdown</div></div></div>";
|
||||
foreach(array_keys($imgdirs) as $iserver){
|
||||
$firstdir = $imgdirs[$iserver][0];
|
||||
$hiddend = "d-none";
|
||||
if(($server == "undefined")&&($imgdirs[$firstserver][0] == $firstdir)&&($firstserver == $iserver)){
|
||||
$hiddend = "";
|
||||
}
|
||||
$dropdowns .= "<div class=\"col-sm $hiddend\" id=imagedirdropd$iserver$dmode><div class=dropdown ><button class=\"btn btn-secondary dropdown-toggle\" type=button id=imagedirbutton$iserver$dmode data-toggle=dropdown aria-haspopup=true aria-expanded=false>$firstdir</button>";
|
||||
$dropdowns .= "<div class=dropdown-menu aria-labelledby=imagedirbutton$iserver>";
|
||||
for ($di=0; $di<count($imgdirs[$iserver]); $di++){
|
||||
$dir = $imgdirs[$iserver][$di];
|
||||
$dropdowns .= "<a class=dropdown-item href=\"javascript:imgdropdown('dir','$iserver','$dir', '$dmode')\">$dir</a>";
|
||||
}
|
||||
$dropdowns .= "</div></div></div>";
|
||||
}
|
||||
$dropdowns .= "</div><br/>";
|
||||
echo $dropdowns;
|
||||
if ($dmode == "source"){
|
||||
listimg($firstserver, $firstdir);
|
||||
}
|
||||
}
|
||||
imgdropdowns($db_handle, $server, $serverq, 'source');
|
||||
echo "<div class=d-none id=copytargetd>Target";
|
||||
imgdropdowns($db_handle, $server, $serverq, 'target');
|
||||
echo "<div class=row><div class=col-sm><input id=targetfilename name=targetfilenme type=text class=form-control placeholder=\"new filename\"></div></div><br/></div>";
|
||||
echo "<div class=row><div class=col-sm><a class=\"btn btn-primary\" id=copybtn onclick=imgcopy();>copy</a></div><div class=col-sm id=delimgbutton><button class=\"btn btn-danger\" data-delete-text=\"Delete image \" data-delete-what=image data-delete-id=\"\" data-delete-name=\"\" data-toggle=\"modal\" data-target=\"#confirm-delete\">Delete</button></div></div>";
|
||||
echo "<div id=newimgdiv><hr><div class=row ><div class=col-sm><input type=text class=form-control id=newimg placeholder=\"new image name\"></div><div class=col-md-3><input type=text class=form-control id=newimgsize placeholder=\"size in GB\"></div><div class=col-md-3><a class=\"btn btn-primary\" onclick=createimg();>create</a></div></div></div>";
|
||||
exit;
|
||||
}
|
||||
|
||||
if ((isset($_REQUEST['listdir']))&&(isset($_REQUEST['server']))){
|
||||
$listdir = clean($_REQUEST['listdir']);
|
||||
$server = clean($_REQUEST['server']);
|
||||
$sqld="SELECT id FROM servers WHERE hostname = '$server' AND (vmdirectory LIKE '%$listdir%' OR isodirectory LIKE '%$listdir%')";
|
||||
$resd = $db_handle->query($sqld);
|
||||
while ($rowd = $resd->fetchArray(SQLITE3_ASSOC)){
|
||||
listimg($server, $listdir);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['copyss'])){
|
||||
$sserver = clean($_REQUEST['copyss']);
|
||||
$sfile = clean($_REQUEST['copysf']);
|
||||
$tserver = clean($_REQUEST['copyts']);
|
||||
$tfile = clean($_REQUEST['copytf']);
|
||||
$shellout = shell_exec("export FID=\$\$; printf \"\$FID\"; /usr/bin/nlvmi copyimg \"$sserver;$sfile\" \"$tserver;$tfile\" 2&>/dev/null &");
|
||||
if (preg_match_all('/completed/', $shellout)){
|
||||
echo "success";
|
||||
} else {
|
||||
echo $shellout;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
if (isset($_REQUEST['progress'])){
|
||||
$txt_file = file_get_contents("/tmp/$_REQUEST[progress]");
|
||||
if (preg_match('/noprogressavailable/', $txt_file)){
|
||||
echo "sorry, no progress available";
|
||||
} elseif(preg_match('/fail/', $txt_file)){
|
||||
echo "fail";
|
||||
} elseif(!preg_match('/^done/', $txt_file)){
|
||||
$row = explode(" ", $txt_file);
|
||||
$c = count($row) - 1;
|
||||
$pfound="no";
|
||||
while ($pfound == "no"){
|
||||
$field = $row[$c];
|
||||
if (preg_match('/%/', $field)){
|
||||
$perc = explode('%', $field);
|
||||
echo $perc[0];
|
||||
$pfound="yes";
|
||||
}
|
||||
$c = $c -1;
|
||||
}
|
||||
} else {
|
||||
echo "done";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//ajax queries are all done, time for the header
|
||||
include('header.php');
|
||||
|
||||
@@ -652,8 +805,6 @@ if (isset($_SESSION['username'])){
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(($mode!="newvm")&&($mode!="editvm")&&($mode!='usermgmt')){
|
||||
if ($_SESSION['isadmin']=="1"){
|
||||
$sqllimit="";
|
||||
|
||||
Reference in New Issue
Block a user