ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.