introduce image management

This commit is contained in:
nativemad 2018-12-01 17:52:19 +01:00
parent a8353787ed
commit d57893514d
4 changed files with 464 additions and 51 deletions

143
nlvmi
View File

@ -7,10 +7,10 @@ if [ $LOGLEVEL -gt "2" ]; then echo "configuration loaded"; fi
#check if we are root and wrap if we are not
U=`/usr/bin/whoami`
if [ $U != "root" ]; then
if [ ! -z $1 ]; then A=$1; else A="bla"; fi
if [ ! -z $2 ]; then B=$2; else B="bla"; fi
if [ ! -z $3 ]; then C=$3; else C="bla"; fi
/usr/bin/wrap-nlvmi $A $B $C && exit
if [ ! -z $1 ]; then A="$1"; else A="bla"; fi
if [ ! -z $2 ]; then B="$2"; else B="bla"; fi
if [ ! -z $3 ]; then C="$3"; else C="bla"; fi
/usr/bin/wrap-nlvmi \"$A\" \"$B\" \"$C\" && exit
fi
if [ ! -d $RUNDIRECTORY ]; then if [ $LOGLEVEL -gt "1" ]; then echo "creating $RUNDIRECTORY"; fi; mkdir -p $RUNDIRECTORY; chown root:nlvmi -R $RUNDIRECTORY; chmod g+w $RUNDIRECTORY; fi
@ -172,8 +172,8 @@ function vmstart {
if [ ! -z ${array[30]} ]; then WPORT=$((${array[30]} + 5700)); WEBSOCK=",websocket=$WPORT"; else WEBSOCK=""; fi
if [ ! -z ${array[31]} ]; then VNCPASS=",password"; fi
if [ ! -z ${array[29]} ]; then VNCPORT="-vnc :${array[29]}$WEBSOCK$VNCPASS"; fi
echo "which ${array[4]} && QEMUCONNAMD=${array[4]} || QEMUCOMMAND=/usr/libexec/qemu-kvm" >>$TMPF
COMMAND=(su - ${array[2]} -s /bin/bash -c \"\$QEMUCOMMAND -name ${array[1]} -enable-kvm ${array[10]} $CPUTYPE $MEMORY $SMP -device virtio-rng-pci -boot ${array[11]} $USBDEV $KB -daemonize $DRIVE1$FORMAT1 $DRIVE2$FORMAT2 $DRIVE3$FORMAT3 $CDROM $MACADDR1 $TAPDEV1 $MACADDR2 $TAPDEV2 $MACADDR3 $TAPDEV3 $VNCPORT $CUSTOM -pidfile $RUNDIRECTORY/${array[1]}.pid -monitor unix:$RUNDIRECTORY/${array[1]}.mon,server,nowait\")
# echo "which ${array[4]} && QEMUCOMMAND=/usr/bin/${array[4]} || QEMUCOMMAND=/usr/libexec/qemu-kvm" >>$TMPF
COMMAND=(su - ${array[2]} -s /bin/bash -c \"which ${array[4]} \&\& QEMUCOMMAND=/usr/bin/${array[4]} \|\| QEMUCOMMAND=/usr/libexec/qemu-kvm\; \\\$QEMUCOMMAND -name ${array[1]} -enable-kvm ${array[10]} $CPUTYPE $MEMORY $SMP -device virtio-rng-pci -boot ${array[11]} $USBDEV $KB -daemonize $DRIVE1$FORMAT1 $DRIVE2$FORMAT2 $DRIVE3$FORMAT3 $CDROM $MACADDR1 $TAPDEV1 $MACADDR2 $TAPDEV2 $MACADDR3 $TAPDEV3 $VNCPORT $CUSTOM -pidfile $RUNDIRECTORY/${array[1]}.pid -monitor unix:$RUNDIRECTORY/${array[1]}.mon,server,nowait\")
if [ $LOGLEVEL -gt "1" ]; then echo ${COMMAND[@]}; fi
echo "${COMMAND[@]}" >>$TMPF
#Set VNC Password
@ -283,10 +283,17 @@ function stopall {
done
}
function listdir {
#echo $1 $2
sqlite3 $SQLITEFILE "SELECT $2,connectstring FROM servers WHERE hostname='$1'" | while read line; do
function listdirs {
if [ $2 == "isodirectory" ] || [ $2 == "vmdirectory" ]; then
COLNAMES=$2
MODE="vm"
else
COLNAMES="isodirectory,vmdirectory"
MODE="img"
fi
sqlite3 $SQLITEFILE "SELECT $COLNAMES,connectstring FROM servers WHERE hostname='$1'" | while read line; do
IFS='|' read -r -a array <<< "$line"
if [ $MODE == "vm" ]; then
IFS=';' read -r -a dirs <<< "${array[0]}"
for di in ${dirs[@]}; do
if [ -z ${array[1]} ]; then
@ -295,7 +302,110 @@ function listdir {
su nlvmi -c "ssh ${array[1]} \"ls -lrt -d -1 $di/{*,.*}\""
fi
done
elif [ $MODE == "img" ]; then
IFS=';' read -r -a dirs <<< "${array[0]};${array[1]}"
for di in ${dirs[@]}; do
if [ $di == $2 ]; then
if [ -z ${array[2]} ]; then
ls -lrt -d -1 $di/{*,.*}
else
su nlvmi -c "ssh ${array[2]} \"ls -lrt -d -1 $di/{*,.*}\""
fi
fi
done
fi
done
}
function delimg {
DDIR=`echo $2 | rev | cut -d "/" -f 2- | rev`
sqlite3 $SQLITEFILE "SELECT vmdirectory,isodirectory,connectstring FROM servers WHERE hostname='$1'" | while read line; do
IFS="|" read -r -a array <<< "$line"
IFS=";" read -r -a dirs <<< "${array[0]};${array[1]}"
for dir in ${dirs[@]}; do
if [ $dir == $DDIR ]; then
if [ -z ${array[2]} ]; then
if [ -e $2 ]; then rm $2 && echo "delete completed"; fi
else
su nlvmi -c "ssh ${array[2]} \"if [ -e $2 ]; then rm $2 && echo delete completed; fi\""
fi
fi
done
done
}
function createimg {
re='^[0-9]+$'
if ! [[ $2 =~ $re ]] ; then
echo "size argument is not numeric" >&2; exit 1
fi
IFS=';' read -r -a T <<< "$1"
TDIR=`echo ${T[1]} | rev | cut -d "/" -f 2- | rev`
TFOUND="no"
declare -a A=`sqlite3 $SQLITEFILE "SELECT vmdirectory,connectstring FROM servers WHERE hostname='${T[0]}'" | while read line; do
IFS="|" read -r -a array <<< "$line"
IFS=";" read -r -a dirs <<< "${array[0]}"
for di in ${dirs[@]}; do
if [ $di == $TDIR ]; then
TFOUND="yes"
TCONN=${array[1]}
fi
done
echo "($TFOUND $TCONN)"
done`
if [ ${A[0]} == "yes" ]; then
if [ -z ${A[1]} ]; then
qemu-img create -f qcow2 ${T[1]} ${2}G && echo "creatimg completed"
else
su nlvmi -c "ssh ${A[1]} \"qemu-img create -f qcow2 ${T[1]} ${2}G\"" && echo "createimg completed"
fi
fi
}
function copyimg {
IFS=';' read -r -a S <<< "$1"
IFS=';' read -r -a T <<< "$2"
SDIR=`echo ${S[1]} | rev | cut -d "/" -f 2- | rev`
TDIR=`echo ${T[1]} | rev | cut -d "/" -f 2- | rev`
SFOUND="no"
TFOUND="no"
for m in S T; do
A="$m"DIR
declare -a B=`sqlite3 $SQLITEFILE "SELECT vmdirectory,isodirectory,connectstring FROM servers WHERE hostname='${!m[0]}'" | while read line; do
IFS='|' read -r -a array <<< "$line"
IFS=';' read -r -a dirs <<< "${array[0]};${array[1]}"
for di in ${dirs[@]}; do
if [ $di == ${!A} ]; then
if [ $m == "S" ]; then
if [ -z ${array[2]} ]; then
if [ -e ${S[1]} ]; then FOUND="yes"; CONN="empty"; fi
else
su nlvmi -c "ssh ${array[2]} \"if [ ! -e ${S[1]} ]; then exit 1; fi\"" && FOUND="yes"; CONN=${array[2]}
fi
elif [ $m == "T" ]; then FOUND="yes"; CONN=${array[2]}; if [ -z $CONN ]; then CONN="empty"; fi; fi
fi
done
echo "($FOUND $CONN)"
done`
export ${m}FOUND=${B[0]}
export ${m}CONN=${B[1]}
done
if [ $SFOUND == "yes" ] && [ $TFOUND == "yes" ]; then
if [ $SCONN == "empty" ] && [ $TCONN == "empty" ]; then
if [ -z $FID ]; then
FID="nldebugger"
fi
rsync --progress ${S[1]} ${T[1]} >/tmp/$FID && echo done >/tmp/$FID || echo fail >/tmp/$FID
elif [ $SCONN == "empty" ]; then
su nlvmi -c "rsync --progress ${S[1]} $TCONN:${T[1]} >/tmp/$FID && echo done >/tmp/$FID || echo fail >/tmp/$FID"
elif [ $SCONN == $TCONN ]; then
su nlvmi -c "ssh $TCONN \"rsync --progress ${S[1]} ${T[1]}\"" >/tmp/$FID && echo done >/tmp/$FID || echo fail >/tmp/$FID
elif [ $TCONN == "empty" ]; then
su nlvmi -c "rsync --progress $SCONN:${S[1]} ${T[1]} >/tmp/$FID && echo done >/tmp/$FID || echo fail >/tmp/$FID"
else
su nlvmi -c "echo "noprogressavailable" >/tmp/$FID && scp -3 $SCONN:${S[1]} $TCONN:${T[1]}" && echo done >/tmp/$FID || echo fail >/tmp/$FID
fi
fi
}
#mainloop
@ -343,9 +453,18 @@ if [ $# -gt 0 ]; then
if [[ $VMFOUND == "no" ]]; then echo "no VM with that name found!"; exit 1; fi)
elif [ $1 == "stopall" ]; then
stopall
elif [ $1 == "listdir" ]; then
if [ -z $2 ] || [ -z $3 ]; then echo listdir needs two more arguments; exit 1; fi
listdir $2 $3
elif [ $1 == "listdirs" ]; then
if [ -z $2 ] || [ -z $3 ]; then echo listdirs needs two arguments; exit 1; fi
listdirs $2 $3
elif [ $1 == "createimg" ]; then
if [ -z $2 ] || [ -z $3 ]; then echo createimg needs two arguments; exit 1; fi
createimg $2 $3
elif [ $1 == "copyimg" ]; then
if [ -z $2 ] || [ -z $3 ]; then echo copyimg needs two arguments; exit 1; fi
copyimg $2 $3
elif [ $1 == "delimg" ]; then
if [ -z $2 ] || [ -z $3 ]; then echo delimg needs two arguments; exit 1; fi
delimg $2 $3
elif [ $1 == "remote" ]; then
if [ ! -z $MASTERSERVER ]; then
if `echo $SSH_CLIENT | grep "$MASTERSERVER " &>/dev/null`; then

View File

@ -12,6 +12,23 @@
<title>nlvmi</title>
</head>
<body>
<div class="modal fade" id="imagemgmt" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="imagemodaltext1">
Imagemanagement
</div>
<div class="modal-body" id="imagemodaltext2">
...
</div>
<div id="imgprogr" class="d-none row"><div id="imgprogd" style="text-align:center;" class="col"></div></div>
<div id="imgprog" class="d-none row"><div class="col" style="text-align:center;"><progress style="max-width:80%;" max="100" value="0" id=imgprogbar></progress></div></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
@ -28,10 +45,10 @@
</div>
</div>
</div>
<script src="nlvmi.js?4"></script>
<script src="nlvmi.js?5"></script>
<div class=container-fluid><div class="row" style="background-color:lightgreen;"><div class="col-sm"><h1><a href="?" style=color:white;>nlvmi</a><a href="?" style="color:black;font-size:10px;">@<?php echo gethostname();?></a></h1></div><div class=col-sm style=text-align:right>
<?php if($_SESSION['isadmin']==1){ echo "<a style=color:black href=# onclick=\"javascript:post('?', {'usermgmt': 'show'});\">usermanagement</a></br><a style=color:black href=# onclick=\"javascript:post('?', {'servermgmt': 'show'});\">servers</a></br>";} ?>
<a style=color:black href=# onclick="javascript:post('?', {'logout': 'logout'});">logout</a></div></div>
<?php if($_SESSION['isadmin']==1){ echo "<a style=padding-right:2em;color:black href=#imagemgmt onclick=\"javascript:imagemgmt('show');\"> images </a> <a style=padding-right:2em;color:black href=# onclick=\"javascript:post('?', {'servermgmt': 'show'});\"> servers </a> <a style=padding-right:2em;color:black href=# onclick=\"javascript:post('?', {'usermgmt': 'show'});\"> usermanagement </a> ";} ?>
<a style=padding-right:2em;color:black href=# onclick="javascript:post('?', {'logout': 'logout'});"> logout </a></div></div>

View File

@ -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'";
@ -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="";

View File

@ -1,10 +1,8 @@
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
@ -28,18 +26,15 @@ function post(path, params, method) {
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
@ -54,8 +49,17 @@ $('#confirm-delete').on('click', '.btn-ok', function(e) {
$('#confirm-delete').on('show.bs.modal', function(e) {
var data = $(e.relatedTarget).data();
$('.title', this).text(data.deleteVm);
if (data.deleteWhat == "image"){
var server = $('#imageserverbuttonsource').html();
var dir = $('#imagedirbutton'+ server +'source').html();
var img = $('#ld').find(":selected").text();
document.getElementById('modaltext2').innerHTML = data.deleteText + img;
$('.btn-ok', this).data({'deleteWhat': data.deleteWhat,'deleteName': server,'deleteId': dir +";"+ img});
} else {
document.getElementById('modaltext2').innerHTML = data.deleteText;
$('.btn-ok', this).data({'deleteWhat': data.deleteWhat,'deleteName': data.deleteName,'deleteId': data.deleteId});
}
});
function submitbutton(formid){
@ -89,3 +93,125 @@ function arrow(dir, id){
},
});
}
function imagemgmt(mode, server){
if(mode == "show") {
$('#imagemgmt').modal('show');
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "&imagemgmt="+ server,
success: function(response) {
$('#imagemodaltext2').html(response);
var server = $('#imageserverbuttonsource').html();
imgdropdown('dir', server, $('#imagedirbutton'+ server +'source').html(), 'source')
},
});
}
}
function imgdropdown(mode,server,dir,dmode){
$('#imagedirbutton'+ server +""+ dmode).html(dir);
if(mode == "server"){
$('#imageserverbutton'+ dmode).html(server);
$("[id^=imagedirdropd][id$="+ dmode +"]").addClass('d-none');
$('#imagedirdropd'+ server +''+ dmode).removeClass('d-none');
}
if(dmode == "source"){
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "&listdir="+ dir +"&server="+ server,
success: function(response) {
$('#listimgd').html(response);
},
});
}
}
function actioncheck(){
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "&progress="+ jresponse,
success: function(response) {
if (response == "done") {
cdone = "yes";
} else {
if (response == "sorry, no progress available"){
$('#imgprogd').html(response);
}
if (response == "fail"){
cdone = "yes";
window.alert("Failed to copy!");
} else {
$('#imgprogbar').val(response);
$('#imgprogd').html(response +"%");
}
}
}
});
if (cdone == "yes") {
$('#imgprog').addClass('d-none');
$('#imgprogr').addClass('d-none');
$('#imagemodaltext2').removeClass('d-none');
$('#imgprogbar').val("0");
clearInterval(interval);
}
}
function imgcopy(){
if ($('#copybtn').html() == "copy"){
$('#copytargetd').removeClass('d-none');
$('#copybtn').html("start copy");
$('#copybtn').removeClass('btn-primary');
$('#copybtn').addClass('btn-warning');
$('#newimgdiv').addClass('d-none');
$('#delimgbutton').addClass('d-none');
} else {
var sserver = $('#imageserverbuttonsource').html();
var sdir = $('#imagedirbutton'+ sserver +"source").html();
var sfile = $('#ld').val();
var tserver = $('#imageserverbuttontarget').html();
var tdir = $('#imagedirbutton'+ tserver +"target").html();
var tfile = $('#targetfilename').val();
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "&copyss="+ sserver +"&copysf="+ sdir +"/"+ sfile +"&copyts="+ tserver +"&copytf="+ tdir +"/"+ tfile,
success: function(response) {
jresponse = response;
if (Number.isInteger(+jresponse)){
$('#imgprogr').removeClass('d-none');
$('#imgprog').removeClass('d-none');
$('#imagemodaltext2').addClass('d-none');
interval= setInterval(actioncheck,3000);
cdone = "no";
} else {
cdone = "fail";
window.alert("FAIL! nana"+ jresponse +"nana");
}
},
});
}
}
function createimg(){
var server = $('#imageserverbuttonsource').html();
var dir = $('#imagedirbutton'+ server +'source').html();
var imgname = $('#newimg').val();
var imgsize = $('#newimgsize').val();
$.ajax({
type: 'POST',
url: "?rand="+ makeid(),
data: "createimgs="+ server +"&createimgd="+ dir +"&createimg="+ imgname +"&createimgsize="+ imgsize,
success: function(response){
var imgsuc = new RegExp("createimg completed")
if (imgsuc.test(response)){
window.location.href = "";
} else {
window.alert("Failure\r "+ response);
}
}
});
}