DD-WRT Uptime in Signature Image

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Goto page 1, 2  Next
Author Message
CaScAdE
DD-WRT Guru


Joined: 18 Jun 2006
Posts: 1110
Location: Kiel (54.4247,10.1721)

PostPosted: Wed Oct 25, 2006 9:34    Post subject: DD-WRT Uptime in Signature Image Reply with quote
Hi Folks,

since I've been asked about my signature including the uptime from some dd-wrt nodes I am now publishing the striped down rubbish code I hacked in 20min just to give php-newbies a starting point.

The script is <40 lines, no comments and whatnot, check out php.net to get more information.
To use this script you need a php (gd enabled) capaple webserver that can reach the dd-wrt nodes and the info sites enabled.
Please replace AAA.BBB.CCC.DDD and EEE.FFF.GGG.HHH with the IPs of you devices, delete last two $wrt54g_data lines or add more if you have fewer/more devices you whish to monitor.


Code:
<?php
        $wrt54g_data["S  v1.1"] = file("http://AAA.BBB.CCC.DDD/");
        $wrt54g_data_addi["S  v1.1"] = " (First router)";
        $wrt54g_data["   v5.0"]   = file("http://EEE.FFF.GGG.HHH/");
        $wrt54g_data_addi["   v5.0"] = " (WDS node)";

        foreach ($wrt54g_data as $version => $data) {
            foreach ($wrt54g_data[$version] as $zeile) {
                if (eregi("share.about",$zeile)) {
                    $splitted = split('"',strip_tags($zeile));
                    $splitted = split('"',$splitted[1]);
                    $line = "WRT54G".$version.": ".$splitted[0];
                };
                if (eregi(" up ",$zeile)) {
                    $splitted = split(' up ',ereg_replace(" +"," ",strip_tags($zeile)));
                    $splitted = split(', load',$splitted[1]);
                    $line .= " up: ".$splitted[0].$wrt54g_data_addi[$version];
                    if (strlen($line) > $maxlen) $maxlen = strlen($line);
                    $output[] = $line;
                };
            };
        };

        $font  = 2;
        $width  = ImageFontWidth($font) * $maxlen;
        $height = (ImageFontHeight($font)+1) * sizeof($output);

        $im = imagecreate ($width,$height);
        $background_color = imagecolorallocate ($im, 0, 255, 255);
        imagecolortransparent($im,$background_color);
        $text_color = imagecolorallocate ($im,   0,  0,  0);//black text
        foreach ($output as $zeile) {
                imagestring ($im, $font, 0, $y,  $zeile, $text_color);
                $y = $y + ImageFontHeight($font) + 1;
        };
        header("Content-type: image/png");
        imagepng ($im);
        imagedestroy($im)
?>


I know that I left out the different colors and whatnot but thats something you can add yourself... This ist just to get a grip...
To add comments go to the firs line and add $output[] = "My deviced:"; for top info or somewhere near $font = 2; for bottom notes...

Hope someone will find this one usefull...

_________________
DD-WRT F.A.Q.

Webcam Kiel


Last edited by CaScAdE on Mon Nov 06, 2006 23:46; edited 1 time in total
Sponsor
cyberde
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1488
Location: the Netherlands

PostPosted: Wed Oct 25, 2006 13:39    Post subject: Reply with quote
Also make sure you have Info Site-page set to enabled Wink
Nice piece of code btw.

_________________
Firmware: DD-WRT v24-sp2 (latest available) mega
WRT320N

Donater
rsriverrat
DD-WRT Novice


Joined: 22 Oct 2006
Posts: 1

PostPosted: Wed Oct 25, 2006 22:37    Post subject: thanks bro Reply with quote
hey cascade, i appreciate the info bro, i had started reading up on php a bit and was just totally lost.... very nice info... again thanks very much Smile

Ratt
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Wed Aug 22, 2007 2:32    Post subject: Reply with quote
hello

i already hosted the php script you have on the forum
its hosted here http://moreins.hyperphp.com/dd-wrt-sig/
im having trouble getting the png image. my router has the infosite enabled and is visible from the outside (you can check it out here: http://andresm.dnsalias.com)
i would really appreciate if you can help me out with this. it would be awesome if i get it to work.
here is the code im using. it the same exact one that you posted on the forum.
i would really appreciate if you give me any clue of why its not working the php script...im sooo frustrated right now...

Code:

<?php
        $wrt54g_data["S  v1.1"] = file("http://andresm.dnsalias.com");
        $wrt54g_data_addi["S  v1.1"] = " (First router)";
       
        foreach ($wrt54g_data as $version => $data) {
            foreach ($wrt54g_data[$version] as $zeile) {
                if (eregi("share.about",$zeile)) {
                    $splitted = split('"',strip_tags($zeile));
                    $splitted = split('"',$splitted[1]);
                    $line = "WRT54G".$version.": ".$splitted[0];
                };
                if (eregi(" up ",$zeile)) {
                    $splitted = split(' up ',ereg_replace(" +"," ",strip_tags($zeile)));
                    $splitted = split(', load',$splitted[1]);
                    $line .= " up: ".$splitted[0].$wrt54g_data_addi[$version];
                    if (strlen($line) > $maxlen) $maxlen = strlen($line);
                    $output[] = $line;
                };
            };
        };

        $font  = 2;
        $width  = ImageFontWidth($font) * $maxlen;
        $height = (ImageFontHeight($font)+1) * sizeof($output);

        $im = imagecreate ($width,$height);
        $background_color = imagecolorallocate ($im, 0, 255, 255);
        imagecolortransparent($im,$background_color);
        $text_color = imagecolorallocate ($im,   0,  0,  0);//black text
        foreach ($output as $zeile) {
                imagestring ($im, $font, 0, $y,  $zeile, $text_color);
                $y = $y + ImageFontHeight($font) + 1;
        };
        header("Content-type: image/png");
        imagepng ($im);
        imagedestroy($im)
?>

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
rsxhitman
DD-WRT User


Joined: 04 Dec 2007
Posts: 80

PostPosted: Sun Apr 20, 2008 6:09    Post subject: Reply with quote
im having problems with this, one is i dont know what variables dd-wrt gives off, and theres something wrong with the code

Code:
$splitted = split(', load',$splitted[1]);


something is wrong there, the split is suppose to start a new line if it stretches too far as im guessing, that line never shows, also theres no memory variable, im wondering how to do it like this guy



he has a memory variable as well
jbarbieri
DD-WRT Guru


Joined: 06 Apr 2007
Posts: 545
Location: New Hampshire

PostPosted: Mon Apr 21, 2008 13:52    Post subject: Reply with quote
split doesnt add a new line, split just splits up the line, so you can grab a "piece" of the line.

To add a new line, you add it to output[]

_________________


Linksys EA6500v2 | 5GHz 1st Floor AP | Advanced Tomato 1.28.0000 -2.9-131 K26ARM USB AIO-64K
Netgear WNR2000v3 | 2nd Floor AP | DD-WRT v3.0-r27805 std

Behind a Raspberry Pi Dual WAN router
jbarbieri
DD-WRT Guru


Joined: 06 Apr 2007
Posts: 545
Location: New Hampshire

PostPosted: Mon Apr 21, 2008 13:56    Post subject: Reply with quote
Heres my code, dirty, but it works....kinda:

Code:

<?php
        $wrt54g_data["S v2"] = file("http://aaa.bbb.ccc.ddd:/");
        $wrt54g_data_addi["S v2"] = " (Dual Wan Enabled Main Router)";
 //       $wrt54g_data["   v5.0"]   = file("http://EEE.FFF.GGG.HHH/");
 //       $wrt54g_data_addi["   v5.0"] = " (WDS node)";
$maxlen = 40;

        foreach ($wrt54g_data as $version => $data) {
            foreach ($wrt54g_data[$version] as $zeile) {
                if (eregi("share.about",$zeile)) {
                    $splitted = split('"',strip_tags($zeile));
                    $splitted = split('"',$splitted[1]);
                    $line = "Linksys WRT54G".$version.": Running ".$splitted[0];
                };
                if (eregi(" up ",$zeile)) {
                    $splitted = split(' up ',ereg_replace(" +"," ",strip_tags($zeile)));
                    $splitted = split(', load',$splitted[1]);
                    #$line2 = "  Current uptime: ".$splitted[0].$wrt54g_data_addi[$version];
                    $line2 = "  Current uptime: ".$splitted[0];
                    $line3 = "  Current one minute load".$splitted[1];
                    $splitted = split(',',$line3,3);
                    #$line3 = $splitted[0].", ".$splitted[1].", ".$splitted[2];
                    $line3 = $splitted[0];
                    if (strlen($line) > $maxlen) $maxlen = strlen($line);
                    $output[0] = $line;
                    $output[1] = $line2;
                    $output[2] = $line3;
                    $output[4] = "  Using 2x6mbit Cable Connections in Dual WAN mode";
                };
                if (eregi("MemFree:",$zeile)) {
                    $splitted = split('MemFree:\'\,\'',strip_tags($zeile));
                    $splitted = split('\'',$splitted[1]);
                    $line4 = "  Total Memory: 30228kB, Total Free: ".$splitted[0]."kB";
                    $output[3] = $line4;
                };
            };
        };

        $font  = 2;
        $width  = ImageFontWidth($font) * $maxlen;
        $height = (ImageFontHeight($font)+1) * sizeof($output);

        $im = imagecreate ($width,$height);
        $background_color = imagecolorallocate ($im, 0, 0, 0);
        imagecolortransparent($im,$background_color);
        $text_color = imagecolorallocate ($im,   255,  0,  0);//black text
        $text_color2 = imagecolorallocate ($im,   34, 139, 34);
        $text_color3 = imagecolorallocate ($im,   0, 0, 255);
        $text_color4 = imagecolorallocate ($im,   255, 170, 0);
        $text_color5 = imagecolorallocate ($im,   0, 0, 0);
        #foreach ($output as $zeile) {
        #        imagestring ($im, $font, 0, $y,  $zeile, $text_color);
        #        $y = $y + ImageFontHeight($font) + 1;
        #};
        $y=0;
        imagestring ($im, $font, 0, $y,  $output[0], $text_color);
        $y = $y + ImageFontHeight($font) + 1;
        imagestring ($im, $font, 0, $y,  $output[1], $text_color2);
        $y = $y + ImageFontHeight($font) + 1;
        imagestring ($im, $font, 0, $y,  $output[2], $text_color3);
         $y = $y + ImageFontHeight($font) + 1;
        imagestring ($im, $font, 0, $y,  $output[3], $text_color4);
         $y = $y + ImageFontHeight($font) + 1;
        imagestring ($im, $font, 0, $y,  $output[4], $text_color5);
        header("Content-type: image/png");
        imagepng ($im);
        imagedestroy($im)
?>

_________________


Linksys EA6500v2 | 5GHz 1st Floor AP | Advanced Tomato 1.28.0000 -2.9-131 K26ARM USB AIO-64K
Netgear WNR2000v3 | 2nd Floor AP | DD-WRT v3.0-r27805 std

Behind a Raspberry Pi Dual WAN router
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Sun Apr 27, 2008 1:16    Post subject: Reply with quote
jbarbieri, i have tried your code and works great.
the thing is that, in order to access the image, i need to type the php file. i was wondering on how can i access the image by going to the png or gif file.
in my ftp server, i created a folder called router. inside of it, there is only one file (sig.php). and i can access by typing this
http://moreins.x10hosting.com/router/sig.php

of course if i try to go
http://moreins.x10hosting.com/router/sig.png, i will get an error since theres not sig.png file.

i can see that your signature is a png file. so, how can i do that?

i hope you, or anyone else, can help me

thanx

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
jbarbieri
DD-WRT Guru


Joined: 06 Apr 2007
Posts: 545
Location: New Hampshire

PostPosted: Mon Apr 28, 2008 12:37    Post subject: Reply with quote
I just renamed the php file to png....and added a .htaccess file in the directory:

Code:
Options +All
AddType application/x-httpd-php gif


Or for PNG:
Code:
Options +All
AddType application/x-httpd-php png



This tells apache to treat gif files as php files, so it executes...the only downside, any gif file in that directory will try to execute as php.....so make sure you dont have any others, or just put the gif/png file in a directory on its own.

_________________


Linksys EA6500v2 | 5GHz 1st Floor AP | Advanced Tomato 1.28.0000 -2.9-131 K26ARM USB AIO-64K
Netgear WNR2000v3 | 2nd Floor AP | DD-WRT v3.0-r27805 std

Behind a Raspberry Pi Dual WAN router
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Mon Apr 28, 2008 17:06    Post subject: Reply with quote
hello
im still struggling with this. i cant get it to work. this is what i have done so far:

i renamed the PHP code (sig.php) to sig.png
i created a file .htaccess with the following data inside:
Code:
Options +All
AddType application/x-httpd-php png




and i uploaded them to my site
http://moreins.x10hosting.com/router/



the thing is that when i go to http://moreins.x10hosting.com/router/sig.png , my web browser wont show me the image.
would you please give me some help with this?

thanks

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
jbarbieri
DD-WRT Guru


Joined: 06 Apr 2007
Posts: 545
Location: New Hampshire

PostPosted: Mon Apr 28, 2008 17:50    Post subject: Reply with quote
does that webspace have php installed and enabled?
_________________


Linksys EA6500v2 | 5GHz 1st Floor AP | Advanced Tomato 1.28.0000 -2.9-131 K26ARM USB AIO-64K
Netgear WNR2000v3 | 2nd Floor AP | DD-WRT v3.0-r27805 std

Behind a Raspberry Pi Dual WAN router
jbarbieri
DD-WRT Guru


Joined: 06 Apr 2007
Posts: 545
Location: New Hampshire

PostPosted: Mon Apr 28, 2008 17:51    Post subject: Reply with quote
I get something when i goto http://moreins.x10hosting.com/

So somethings working there

_________________


Linksys EA6500v2 | 5GHz 1st Floor AP | Advanced Tomato 1.28.0000 -2.9-131 K26ARM USB AIO-64K
Netgear WNR2000v3 | 2nd Floor AP | DD-WRT v3.0-r27805 std

Behind a Raspberry Pi Dual WAN router
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Mon Apr 28, 2008 19:27    Post subject: Reply with quote
jbarbieri wrote:
does that webspace have php installed and enabled?

yes
100% functional

jbarbieri wrote:
I get something when i goto http://moreins.x10hosting.com/

So somethings working there


ur at the wrong place
go here http://moreins.x10hosting.com/router/
thats were i have the actual files and where im having the issue. (the ones i showed you in the screenshots)

this is what i get when i try to access the png file (http://moreins.x10hosting.com/router/sig.png)


php code has always worked. but only if i access it as a php. i want to have a png or gif image i could access.

hope u can help me

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
jbarbieri
DD-WRT Guru


Joined: 06 Apr 2007
Posts: 545
Location: New Hampshire

PostPosted: Mon Apr 28, 2008 19:54    Post subject: Reply with quote
just try changing it to a .gif and change the .htaccess too.
_________________


Linksys EA6500v2 | 5GHz 1st Floor AP | Advanced Tomato 1.28.0000 -2.9-131 K26ARM USB AIO-64K
Netgear WNR2000v3 | 2nd Floor AP | DD-WRT v3.0-r27805 std

Behind a Raspberry Pi Dual WAN router
moreins
DD-WRT User


Joined: 18 Nov 2006
Posts: 320
Location: Cali, Colombia

PostPosted: Mon Apr 28, 2008 20:08    Post subject: Reply with quote
jbarbieri wrote:
just try changing it to a .gif and change the .htaccess too.

i already did that in order to try if gif would work.
no luck at all Sad
do i need to have both php and png files in the same folder?

_________________
WRT54GS v2.1 > v24-sp2 (01/01/09) mega
WRT54GS v5 > v24-sp2 (01/01/09) micro
PPTP, WDS link and SD Mod
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum