Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi-bin / html icmp ping specified address

Status
Not open for further replies.

tjbradford

Technical User
Dec 14, 2007
229
0
0
GB
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.
 
Hi

Pity. Bash 4 has associative arrays, which would be useful here. As far as I remember, I used this for Bash 3.
Code:
[b][COLOR=blue]<form[/color][/b] [COLOR=darkgreen]action[/color][COLOR=darkred]=[/color][COLOR=red]"/cgi-bin/ping.sh"[/color][b][COLOR=blue]>[/color][/b]
[b][COLOR=blue]<input[/color][/b] [COLOR=darkgreen]type[/color][COLOR=darkred]=[/color][COLOR=red]"text"[/color] [COLOR=darkgreen]name[/color][COLOR=darkred]=[/color][COLOR=red]"host"[/color][b][COLOR=blue]>[/color][/b]
[b][COLOR=blue]<input[/color][/b] [COLOR=darkgreen]type[/color][COLOR=darkred]=[/color][COLOR=red]"submit"[/color] [COLOR=darkgreen]value[/color][COLOR=darkred]=[/color][COLOR=red]"Ping !"[/color][b][COLOR=blue]>[/color][/b]
[b][COLOR=blue]</font>[/color][/b]
Bash:
[i][COLOR=maroon]#!/bin/bash[/color][/i]

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

[COLOR=darkred][[[/color] [COLOR=red]"$GET_host"[/color] [COLOR=darkred]]][/color] [COLOR=darkred]&&[/color] ping -c [COLOR=purple]10[/color] -w [COLOR=purple]10[/color] -W [COLOR=purple]10[/color] [COLOR=red]"$GET_host"[/color]
[small][maroon]Warning[/maroon] The above code was not tested[/small]

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

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

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

Feherke.
 
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 ?
 
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 ?
 
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 [tt]User[/tt] directive in httpd.conf . ) Then I would try to become that user and run [tt]ping[/tt] from the console.


Feherke.
 
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)
 
Hi

tjbradford said:
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:
[i][COLOR=maroon]#!/bin/bash[/color][/i]

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

[highlight]echo [COLOR=red]$'Content-type: text/plain[/color][COLOR=pink]\n[/color][COLOR=red]'[/color][/highlight]

[COLOR=darkred][[[/color] [COLOR=red]"$GET_host"[/color] [COLOR=darkred]]][/color] [COLOR=darkred]&&[/color] ping -c [COLOR=purple]10[/color] -w [COLOR=purple]10[/color] -W [COLOR=purple]10[/color] [COLOR=red]"$GET_host"[/color]


Feherke.
 
file permissions
-rwxrwxrwx 1 apache root 1939 May 20 12:59 /var/[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 ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top