From 8de450aeac9cd8b797df05172bb89f1c92c25192 Mon Sep 17 00:00:00 2001 From: Srikant Patnaik Date: Fri, 22 May 2015 19:38:19 +0530 Subject: added support for random user and passwd generation --- server.cgi | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/server.cgi b/server.cgi index ecaf8e8..e23da25 100755 --- a/server.cgi +++ b/server.cgi @@ -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 -- cgit