Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-21-2007, 02:29 AM
|
#1
|
|
LQ Newbie
Registered: Dec 2005
Location: Pullman, WA
Distribution: Gentoo,FreeBSD,Mac OS X
Posts: 17
Rep:
|
using perl with PNGs, Net::Ping, and CGI
I have a web page that pulls a list of computers from a DHCP database and I would like to add a column to see if the computers were online. My idea was simple enough, a perl script that pings the host and returns either a red PNG or a green PNG...as you can see...
Code:
#!/usr/local/bin/perl -w
use GD;
use Net::Ping;
print ("Content-type: image/png\n\n");
$im = new GD::Image(100,100);
$white = $im->colorAllocate(255,255,255);
$im->transparent($white);
$p = Net::Ping->new("icmp", 1, 64);
my $host = $ENV{'QUERY_STRING'};
if( $p->ping($host,0.09))
{
$colour=$im->colorAllocate(0,255,0);
}
else
{
$colour = $im->colorAllocate(255,0,0);
}
$im->filledEllipse(5,5,10,10,$colour);
# make sure we are writing to a binary stream
binmode STDOUT;
# Convert the image to PNG and print it on standard output
print $im->png;
However, the script does not run in a apache, as apache's user is not root and root access is required for ICMP stuff, apparently. I saw something about setuid, but I was too scared to look into it, as I am taking direct input from a user (potentially, I guess I could lock it down by IP) and don't want someone breaking out and gaining root access. But other than locking it down by IP, does anyone have a hint for me how to do this effectively? I've been using perl for about a month now, so i'm probably not familiar with a lot of the basics.
thanks
Last edited by cselph; 08-21-2007 at 02:30 AM.
Reason: messed up code tag
|
|
|
|
08-21-2007, 05:02 AM
|
#2
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
why not use a less restrictive ping like tcp or udp?
|
|
|
|
08-21-2007, 05:06 AM
|
#3
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
or...
write a separate ping server, run as root which you query from your CGI script.
so, you have a separate ping-ing server, you send it a hostname, it does the ping for you and replies
yes or no.
|
|
|
|
08-21-2007, 11:36 AM
|
#4
|
|
LQ Newbie
Registered: Dec 2005
Location: Pullman, WA
Distribution: Gentoo,FreeBSD,Mac OS X
Posts: 17
Original Poster
Rep:
|
thanks for the replies.
I thought about writing it in 2 parts, but I couldnt figure out if that would actually be more secure. I suppose I could always just valid my input with a regular expression right? I've heard that's one of the main reasons to using perl.
I had some problems with the upd thing, probably my own fault. (It always fails) Does there need to be a port listening to reply to a UDP packet? I don't know much about networking yet...
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:39 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|