summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrikant Patnaik2015-05-20 17:07:55 +0530
committerSrikant Patnaik2015-05-20 17:07:55 +0530
commita912442028c8d6e01faa04a147e80b0fcf3676e2 (patch)
tree894c8b2b9524e3ef7cc49572a9c51d1fb9237143
parent4589de11890071732150d472ff1a0bbacd9839c6 (diff)
downloadtuxviewer-a912442028c8d6e01faa04a147e80b0fcf3676e2.tar.gz
tuxviewer-a912442028c8d6e01faa04a147e80b0fcf3676e2.tar.bz2
tuxviewer-a912442028c8d6e01faa04a147e80b0fcf3676e2.zip
a simple checkrequest function
-rwxr-xr-xserver.cgi34
1 files changed, 34 insertions, 0 deletions
diff --git a/server.cgi b/server.cgi
new file mode 100755
index 0000000..ecaf8e8
--- /dev/null
+++ b/server.cgi
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+incomingData=''
+startPortRange=9000
+endPortRange=9010
+
+function readRequest() {
+# To avoid internal server error (500), minimum text to echo
+echo ''
+# Read the number of bytes(mentioned in CONTENT_LENGTH header) and
+# store the content in incomingData variable
+read -n $CONTENT_LENGTH incomingData
+# To view the content of the incoming data, try a test URL with POST using curl
+# curl --data "requestSshCredentials" http://localhost/server
+# This will send the data to server(to this cgi script) and based on availablity
+# of the ports it will allocate ssh credentials
+}
+
+function checkRequest() {
+if [ "$incomingData" == "requestSshCredentials" ];
+ then
+ firstAvailablePort=$(nmap -p $startPortRange-$endPortRange localhost \
+ | grep -m 1 closed \
+ | cut -d '/' -f 1)
+ if [ $(echo -n $firstAvailablePort | wc -m) == "0" ];
+ then
+ echo "No ports available, please try again!"
+ fi
+ echo $firstAvailablePort
+fi
+}
+
+readRequest
+checkRequest