diff options
author | Srikant Patnaik | 2015-05-22 19:38:19 +0530 |
---|---|---|
committer | Srikant Patnaik | 2015-05-22 19:38:19 +0530 |
commit | 8de450aeac9cd8b797df05172bb89f1c92c25192 (patch) | |
tree | 4ba4a027206ceb6ec29d04a7c6ba896bd06d3467 | |
parent | a912442028c8d6e01faa04a147e80b0fcf3676e2 (diff) | |
download | tuxviewer-8de450aeac9cd8b797df05172bb89f1c92c25192.tar.gz tuxviewer-8de450aeac9cd8b797df05172bb89f1c92c25192.tar.bz2 tuxviewer-8de450aeac9cd8b797df05172bb89f1c92c25192.zip |
added support for random user and passwd generation
-rwxr-xr-x | server.cgi | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -1,8 +1,11 @@ #!/bin/bash incomingData='' -startPortRange=9000 +startPortRange=9000 #Ports to be released for ssh communications endPortRange=9010 +firstAvailablePort='' + +# -------------------------------------------------------------------------- function readRequest() { # To avoid internal server error (500), minimum text to echo @@ -16,19 +19,35 @@ read -n $CONTENT_LENGTH incomingData # of the ports it will allocate ssh credentials } +# -------------------------------------------------------------------------- + function checkRequest() { if [ "$incomingData" == "requestSshCredentials" ]; - then + then firstAvailablePort=$(nmap -p $startPortRange-$endPortRange localhost \ | grep -m 1 closed \ | cut -d '/' -f 1) + # Exit if no ports available if [ $(echo -n $firstAvailablePort | wc -m) == "0" ]; - then - echo "No ports available, please try again!" + then + echo "Sorry, NO ports available, please try again!" + exit 0 fi - echo $firstAvailablePort fi } +# ------------------------------------------------------------------------- + +function usernamePasswdforSSH() { + randomUser=$(date | md5sum | cut -c-5) + randomPasswd=$(date | md5sum | cut -c6-16) #just in case :) + encryptedPasswd=$(openssl passwd $randomPasswd) + sudo useradd -p $encryptedPasswd -r -s /bin/false $randomUser + echo $firstAvailablePort $randomPasswd $randomUser +} + +# ------------------------------------------------------------------------- + readRequest checkRequest +usernamePasswdforSSH |