LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 08-21-2007, 02:29 AM   #1
cselph
LQ Newbie
 
Registered: Dec 2005
Location: Pullman, WA
Distribution: Gentoo,FreeBSD,Mac OS X
Posts: 17

Rep: Reputation: 0
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
 
Old 08-21-2007, 05:02 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
why not use a less restrictive ping like tcp or udp?
 
Old 08-21-2007, 05:06 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
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.
 
Old 08-21-2007, 11:36 AM   #4
cselph
LQ Newbie
 
Registered: Dec 2005
Location: Pullman, WA
Distribution: Gentoo,FreeBSD,Mac OS X
Posts: 17

Original Poster
Rep: Reputation: 0
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...
 
  


Reply

Tags
perl, ping, png


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl CGI:Can't locate CGI.pm supermyself Programming 13 09-10-2007 06:22 AM
Perl Net Ping jholl Programming 0 12-07-2004 10:22 AM
perl cgi neil Programming 3 07-07-2004 04:52 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl: Net::Ping and ipv6 Kostko Programming 1 05-11-2003 12:14 AM


All times are GMT -5. The time now is 01:31 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration