×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

cgi-bin / html icmp ping specified address

cgi-bin / html icmp ping specified address

cgi-bin / html icmp ping specified address

(OP)
i have done a large amount of googling but must have the search fileds wrong or there is no info on my question "unlightly"

i want a basic webpage that has a text box that i input an ip address or hostname and the server goes off pings the address then displays the results in the browser.

i can bash script a fixed ip in cgi-bin but the bit i can't work out is passing the textbox input across to the script

S1 being the ip or alike


is anyone able to show me this or point me to a simple guide.  

RE: cgi-bin / html icmp ping specified address

Hi

Quote (Feherke in the original thread):

When re-posting, also specify the version of your Bash.

Feherke.
http://free.rootshell.be/~feherke/

RE: cgi-bin / html icmp ping specified address

(OP)
whoops

3.00.15(1)  

RE: cgi-bin / html icmp ping specified address

Hi

Pity. Bash 4 has associative arrays, which would be useful here. As far as I remember, I used this for Bash 3.

CODE --> HTML ( fragment )

<form action="/cgi-bin/ping.sh">
<input type="text" name="host">
<input type="submit" value="Ping !">
</font>

CODE --> Bash

#!/bin/bash

[[ "$QUERY_STRING" ]] && {
  while IFS='=' read -d '&' key val; do
    key="${key//%??/_}"
    val="${val//+/ }"
    val="$( eval echo -e "${val//%/\\\\x}" )"
    eval "GET_$key[\${#GET_$key[*]}]=\"$val\""
  done <<< "${QUERY_STRING//;/&}&"
}

[[ "$GET_host" ]] && ping -c 10 -w 10 -W 10 "$GET_host"
Warning The above code was not tested

If you want to add more form elements, for example to let specify the count of packets to send, just add <input type="text" name="count"> to the HTML and change [[ "$GET_host" ]] && ping -c "${GET_count:-10}" -w 10 -W 10 "$GET_host" in the script.

Note that you should test the $GET_* variables' value before using them.

As I remember, I found no security flow with that way to set the $GET_* variables, but do some tests your self. ( Enter `date`, $(date), echo $HOME and alike int form, then see if they appear in the output exactly, or they were executed/substituted. )

Feherke.
http://free.rootshell.be/~feherke/

RE: cgi-bin / html icmp ping specified address

(OP)
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

i have checked the permissions of the ping.sh

-rwsr-xr-x 1 root root

what would be causing this issue ?  

RE: cgi-bin / html icmp ping specified address

(OP)
[Thu May 20 09:41:42 2010] [error] [client 172.30.137.41] Premature end of scrip
t headers: ping.sh, referer: http://svr-mrtg-1/cgi-snmp.html

RE: cgi-bin / html icmp ping specified address

(OP)
ok i have crack the script

i now seem to be gettng the error bash: ping: permission denied, this is permissions to run the ping command.

i need to and some form of permission ?  

RE: cgi-bin / html icmp ping specified address

Hi

Oops. Sorry, I forgot to output the HTTP header before the content.

Regarding the permission, it is really strange. I am not expert in permission problems, so I have no idea for now.

Anyway I would take a look at the user who's permission is using your web server. ( In case of Apache it is specified with the User directive in httpd.conf . ) Then I would try to become that user and run ping from the console.
 

Feherke.
http://free.rootshell.be/~feherke/

RE: cgi-bin / html icmp ping specified address

(OP)
Can you post the correction if possible please so I know it's working as it should before I try to su the apache user :0)

RE: cgi-bin / html icmp ping specified address

Hi

Quote (tjbradford):

Can you post the correction
Sure. Just I understood that you solved it.

I added only the highlighted line, the rest is working to me :

CODE

#!/bin/bash

[[ "$QUERY_STRING" ]] && {
  while IFS='=' read -d '&' key val; do
    key="${key//%??/_}"
    val="${val//+/ }"
    val="$( eval echo -e "${val//%/\\\\x}" )"
    eval "GET_$key[\${#GET_$key[*]}]=\"$val\""
  done <<< "${QUERY_STRING//;/&}&"
}

echo $'Content-type: text/plain\n'

[[ "$GET_host" ]] && ping -c 10 -w 10 -W 10 "$GET_host"
 

Feherke.
http://free.rootshell.be/~feherke/

RE: cgi-bin / html icmp ping specified address

(OP)
file permissions
-rwxrwxrwx  1 apache root 1939 May 20 12:59 /var/www/cgi-bin/iso
[root@svr-cache-1 /]#

/var/log/httpd/error_log shows the following

[Fri May 21 13:55:08 2010] [error] [client 172.30.137.41] bash: iso: Permission
denied


how do i give apache permission to execute the bash file called iso ?  

RE: cgi-bin / html icmp ping specified address

(OP)
php worked the magic for this in the end

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close