mirror of
				https://github.com/vdsm/virtual-dsm.git
				synced 2025-11-04 17:04:52 +08:00 
			
		
		
		
	Retrieve IP from VM
This commit is contained in:
		
							parent
							
								
									63ca30d62d
								
							
						
					
					
						commit
						d1bcc3955a
					
				@ -1,17 +1,49 @@
 | 
				
			|||||||
#!/usr/bin/env bash
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
set -eu
 | 
					set -eu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
trap 'kill 0' EXIT
 | 
					trap 'pkill -f nc || true' EXIT
 | 
				
			||||||
trap exit SIGINT SIGTERM
 | 
					trap exit SIGINT SIGTERM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Serve the page
 | 
					if [ "$2" != "ipinfo" ]; then
 | 
				
			||||||
HTML="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\
 | 
					 | 
				
			||||||
Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
LENGTH="${#HTML}"
 | 
					  # Serve the page
 | 
				
			||||||
 | 
					  HTML="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\
 | 
				
			||||||
 | 
					        Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"
 | 
					  LENGTH="${#HTML}"
 | 
				
			||||||
 | 
					  RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while true; do
 | 
					  while true; do
 | 
				
			||||||
    echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $!
 | 
					    echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $!
 | 
				
			||||||
 | 
					  done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  exit 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SH_SCRIPT="/run/ipinfo.sh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{ echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>&1)"
 | 
				
			||||||
 | 
					  echo "rest=\${INFO#*http_port}"
 | 
				
			||||||
 | 
					  echo "rest=\${rest#*:}"
 | 
				
			||||||
 | 
					  echo "rest=\${rest%%,*}"
 | 
				
			||||||
 | 
					  echo 'PORT=\${rest%%\"*}'
 | 
				
			||||||
 | 
					  echo "rest=\${INFO#*eth0}"
 | 
				
			||||||
 | 
					  echo "rest=\${rest#*ip}"
 | 
				
			||||||
 | 
					  echo "rest=\${rest#*:}"
 | 
				
			||||||
 | 
					  echo 'rest=\${rest#*\"}'
 | 
				
			||||||
 | 
					  echo 'IP=\${rest%%\"*}'
 | 
				
			||||||
 | 
					  echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}<script>\ "
 | 
				
			||||||
 | 
					  echo "setTimeout(function(){ window.location.replace('http://\${IP}:\${PORT}'); }, 2000);</script>\""
 | 
				
			||||||
 | 
					  echo "HTML=\"<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\ "
 | 
				
			||||||
 | 
					  echo "Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>\$BODY</CENTER></H1></BODY></HTML>\""
 | 
				
			||||||
 | 
					  echo 'LENGTH="\${#HTML}"'
 | 
				
			||||||
 | 
					  echo 'RESPONSE="HTTP/1.1 200 OK\nContent-Length: \${LENGTH}\nConnection: close\n\n\$HTML\n\n"'
 | 
				
			||||||
 | 
					  echo 'echo \$RESPONSE'
 | 
				
			||||||
 | 
					} > "$SH_SCRIPT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chmod +x "$SH_SCRIPT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while true ; do
 | 
				
			||||||
 | 
					  nc -lp "${1:-5000}" -e "$SH_SCRIPT" & wait $!
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user