From db5d2307bad7d0280d8e96b57e384dcb148de727 Mon Sep 17 00:00:00 2001 From: nativemad Date: Wed, 24 Oct 2018 17:53:40 +0200 Subject: [PATCH] vnc and nginx generator for wss support --- nlvmi | 25 +++++++++++++++++-------- web/index.php | 25 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/nlvmi b/nlvmi index 197e202..b8c61ec 100755 --- a/nlvmi +++ b/nlvmi @@ -4,13 +4,6 @@ source /etc/nlvmi/nlvmi.conf if [ $LOGLEVEL -gt "1" ]; then echo "configuration loaded"; fi -#checking directories -#echo $VMDIRECTORY | while read line; do IFS='|' read -r -a array -# for dir in "${array[@]}"; do -# if [ ! -d $dir ]; then echo "VMDIRECTORY wrong, $dir does not exist"; exit 1; fi -# done -#done <<< "$line" - #check if we are root and wrap if we are not U=`/usr/bin/whoami` if [ $U != "root" ]; then @@ -177,7 +170,7 @@ function vmstart { if [ ! -z ${array[26]} ]; then TAPDEV3="-netdev tap,ifname=${array[26]},script=no,id=net2"; echo "tunctl -t ${array[26]} -u ${array[2]} && ifconfig ${array[26]} up" >>$TMPF; fi if [ ! -z ${array[27]} ]; then MACADDR3="-net nic,macaddr=${array[27]},model=virtio,netdev=net2"; fi if [ ! -z ${array[28]} ]; then BRDEV3="${array[28]}"; echo "/sbin/brctl addif ${array[28]} ${array[26]}" >>$TMPF; fi - if [ ! -z ${array[30]} ]; then WEBSOCK=",websocket=${array[30]}"; else WEBSOCK=""; fi + 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 COMMAND=(su - ${array[2]} -s /bin/bash -c \"${array[4]} -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\") @@ -205,6 +198,17 @@ function vmstart { rm $TMPF fi fi + if [ -n $WPORT ] && [ -n $NGINXCONFIGPATH ]; then + echo "localtion /${array[1]}/ {" >$NGINXCONFIGPATH/${array[1]}.conf + echo " proxy_pass http://${array[3]}:$WPORT/;" >>$NGINXCONFIGPATH/${array[1]}.conf + echo " proxy_http_version 1.1;" >>$NGINXCONFIGPATH/${array[1]}.conf + echo " proxy_set_header Upgrade $http_upgrade;" >>$NGINXCONFIGPATH/${array[1]}.conf + echo " proxy_set_header Connection \"Upgrade\";" >>$NGINXCONFIGPATH/${array[1]}.conf + echo " proxy_read_timeout 61s;" >>$NGINXCONFIGPATH/${array[1]}.conf + echo " proxy_buffering off;" >>$NGINXCONFIGPATH/${array[1]}.conf + echo "}" >>$NGINXCONFIGPATH/${array[1]}.conf + if [ -n $NGINXRESTARTCOMMAND ]; then $NGINXRESTARTCOMMAND; fi + fi done export VMFOUND="yes" } @@ -307,6 +311,11 @@ if [ $# -gt 0 ]; then else su nlvmi -c "ssh $2 \"rm /home/nlvmi/start*-$3.tmp; rm /home/nlvmi/start*-$3.tmp.sha512\"" fi + elif [ $1 == "delnginx" ]; then + if [ $2 == "local" ]; then + rm $NGINXCONFIGPATH/$3.conf + if [ -n $NGINXRESTARTCOMMAND ]; then $NGINXRESTARTCOMMAND; fi + fi elif [ $1 == "start" ]; then if [ -z $2 ]; then echo "start needs a vmname!"; exit 1; fi VMFOUND="no" diff --git a/web/index.php b/web/index.php index 66e5a35..aefd91d 100644 --- a/web/index.php +++ b/web/index.php @@ -2,10 +2,10 @@ function clean($str) { $search = array('&' , '"' , "'" , '<' , '>' ); $replace = array('&', '"', ''', '<', '>' ); - $str = str_replace($search, $replace, $str); return $str; } + if(isset($_REQUEST['logout'])){ session_start(); session_unset(); @@ -13,6 +13,7 @@ if(isset($_REQUEST['logout'])){ } else { session_start(); } + $mode=""; function checkvm($vmname) { @@ -22,6 +23,7 @@ function checkvm($vmname) { } return 0; } + function serverdepropdown($server, $val, $what){ if ($what == "cdrom"){ $dir = "isodirectory"; @@ -44,6 +46,7 @@ function serverdepropdown($server, $val, $what){ } echo "$enddiv"; } + function formatbuttons($label, $val){ echo "
$label

";