diff --git a/nlvmi b/nlvmi index a5a1348..7417c9b 100755 --- a/nlvmi +++ b/nlvmi @@ -81,7 +81,8 @@ function createdb { brdev3 VARCHAR(50), vncport INTEGER, websocket INTEGER, - vncpassword VARCHAR(50) + vncpassword VARCHAR(50), + prio INTEGER );" sqlite3 $SQLITEFILE "CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -147,8 +148,9 @@ function vmstart { sqlite3 $SQLITEFILE "SELECT * FROM vms LEFT JOIN servers on vms.server = servers.hostname WHERE vms.id=$1" | while read line; do IFS='|' read -r -a array <<< "$line" #prepare tmpfile - TMPF=/home/nlvmi/start${array[1]}.tmp - rm $TMPF &>/dev/null + TMPF=/home/nlvmi/start${array[32]}-${array[1]}.tmp + rm /home/nlvmi/start*-${array[1]}.tmp &>/dev/null + touch $TMPF && chmod 660 $TMPF #add user if necessary echo "if ! \`id -u ${array[2]} &>/dev/null\`; then useradd ${array[2]} -d /run/nlvmi -g nlvmi -M -s /bin/false -G kvm; fi" >>$TMPF #chown mon and pid files @@ -183,14 +185,18 @@ function vmstart { echo "${COMMAND[@]}" >>$TMPF #Set VNC Password echo "echo \"change vnc password ${array[31]}\" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null" >>$TMPF - if [ ! -z "${array[34]}" ]; then + if [ ! -z "${array[35]}" ]; then echo "chmod g+w $RUNDIRECTORY/${array[1]}.mon" >>$TMPF echo "chmod g+r $RUNDIRECTORY/${array[1]}.pid" >>$TMPF openssl dgst -sha512 -sign "/etc/nlvmi/nlvmi_priv.key" -out /home/nlvmi/${array[1]}.tmp.sha512 $TMPF - su nlvmi -c "scp $TMPF* ${array[34]}:/home/nlvmi/" - su nlvmi -c "ssh ${array[34]} \"/usr/bin/nlvmi remote $TMPF run\"" + TMPFR="/home/nlvmi/rstart{array[32]}-${array[1]}.tmp" + mv $TMPF $TMPFR + su nlvmi -c "ssh ${array[35]} \"rm /home/nlvmi/start*-${array[1]}.tmp\"" + mv $TMPFR $TMPF + su nlvmi -c "scp $TMPF* ${array[35]}:/home/nlvmi/" + su nlvmi -c "ssh ${array[35]} \"/usr/bin/nlvmi remote $TMPF run\"" if [ ${array[12]} == "0" ]; then - su nlvmi -c "ssh ${array[34]} \"rm $TMPF $TMPF.sha512\"" + su nlvmi -c "ssh ${array[35]} \"rm $TMPF $TMPF.sha512\"" fi rm $TMPF $TMPF.sha512 else diff --git a/web/arrowdown.png b/web/arrowdown.png new file mode 100644 index 0000000..d9292ab Binary files /dev/null and b/web/arrowdown.png differ diff --git a/web/arrowup.png b/web/arrowup.png new file mode 100644 index 0000000..b0cae3f Binary files /dev/null and b/web/arrowup.png differ diff --git a/web/index.php b/web/index.php index 937b7b0..4b79e23 100644 --- a/web/index.php +++ b/web/index.php @@ -141,7 +141,7 @@ if (isset($_SESSION['username'])){ } else { $vmname = clean($_POST['deletename']); $vmid = clean($_POST['deleteid']); - $sql="SELECT id FROM vms WHERE vmname='$vmname' AND id='$vmid'"; + $sql="SELECT id,prio FROM vms WHERE vmname='$vmname' AND id='$vmid'"; $res = $db_handle->query($sql); while ($row = $res->fetchArray(SQLITE3_ASSOC)){ $sqld="DELETE FROM vms WHERE id='$vmid'"; @@ -150,7 +150,9 @@ if (isset($_SESSION['username'])){ } } } - } elseif ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="user")){ + } elseif +//delete user + ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="user")){ if($_SESSION['isadmin']!=1){ echo "you are not allowed to delete users!"; } else { @@ -165,7 +167,9 @@ if (isset($_SESSION['username'])){ } } } - } elseif ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="server")){ + } elseif +//delete server + ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="server")){ if($_SESSION['isadmin']!=1){ echo "you are not allowed to delete vms!"; } else { @@ -274,6 +278,11 @@ if (isset($_SESSION['username'])){ //insert or update vm in db if(isset($_REQUEST['mode'])){ if($_REQUEST['mode']=="newvm"){ + $psql = "SELECT MAX(prio) AS prio FROM vms"; + $pres = $db_handle->query($psql); + $prioa = $pres->fetchArray(SQLITE3_ASSOC); + $prio = $prioa['prio'] + 1; + $mode="newvm"; $sqls="INSERT INTO vms "; $sqlc="("; @@ -304,10 +313,10 @@ if (isset($_SESSION['username'])){ $sqlv .= "'$rvalue',"; } } - $sqlc = rtrim($sqlc, ','); - $sqlc.=")"; - $sqlv = rtrim($sqlv, ','); - $sqlv.=")"; +// $sqlc = rtrim($sqlc, ','); + $sqlc.=" 'prio')"; +// $sqlv = rtrim($sqlv, ','); + $sqlv.=" '$prio')"; $sql = "$sqls$sqlc$sqlv"; //echo $sql; $res = $db_handle->exec($sql); @@ -354,6 +363,37 @@ if (isset($_SESSION['username'])){ exit; } } + if (isset($_REQUEST['neworder'])){ + if (isset($_REQUEST['vid'])){ + $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'"; + $oldid = $db_handle->query($sqlu)->fetchArray(SQLITE3_ASSOC)['id']; + $sqlm="UPDATE vms SET prio='$newprio' WHERE id='$vid'"; + $sqln="UPDATE vms SET prio='$oldprio' WHERE id='$oldid'"; + if(($db_handle->exec($sqlm))&&($db_handle->exec($sqln))){ + echo "success"; + exit; + } + }elseif ($_REQUEST['neworder']=="down"){ + $newprio = $oldprio + 1; + $sqlu="SELECT id FROM vms WHERE prio='$newprio'"; + $oldid = $db_handle->query($sqlu)->fetchArray(SQLITE3_ASSOC)['id']; + $sqlm="UPDATE vms SET prio='$newprio' WHERE id='$vid'"; + $sqln="UPDATE vms SET prio='$oldprio' WHERE id='$oldid'"; + if(($db_handle->exec($sqlm))&&($db_handle->exec($sqln))){ + echo "success"; + exit; + } + } + + } + } if (isset($_POST['serverbuttoni'])){ serverdepropdown($_POST['serverbuttoni'], "no drive1", 'drive1'); formatbuttons('format1', ''); @@ -598,10 +638,11 @@ if (isset($_SESSION['username'])){ } //getting vms from DB - $sql="SELECT * FROM vms $sqllimit"; + $sql="SELECT * FROM vms $sqllimit ORDER BY prio"; $res = $db_handle->query($sql); - echo "