diff -puNr weathermap4rrd_old/config.php weathermap4rrd/config.php --- weathermap4rrd_old/config.php 2005-12-18 14:20:31.000000000 +0100 +++ weathermap4rrd/config.php 2007-12-30 19:22:18.000000000 +0100 @@ -6,13 +6,9 @@ $rrdtool = "/usr/bin/rrdtool"; # it will be used to read config file $weathermap4php= dirname($_SERVER['PATH_TRANSLATED']); #$configfile=$weathermap4php."/weathermap.conf"; -$configfile=$_GET['config']; -if (empty($configfile)) { - $configfile=$weathermap4php."/weathermap.conf"; -} else { - $configfile=$weathermap4php."/".$configfile; -} - +#$configfile=$_GET['config']; +$configfile="/etc/weathermap4rrd/weathermap.conf"; + $adminpage="index.php"; $VERSION="1.2"; $DEBUG=0; diff -puNr weathermap4rrd_old/config_tool.php weathermap4rrd/config_tool.php --- weathermap4rrd_old/config_tool.php 2005-12-18 14:20:12.000000000 +0100 +++ weathermap4rrd/config_tool.php 2008-01-04 02:12:01.000000000 +0100 @@ -15,7 +15,7 @@ function read_config($filename) { global $titleforeground_red,$titleforeground_green,$titleforeground_blue; global $titlebackground_red,$titlebackground_green,$titlebackground_blue; global $OUTPUTFILE, $HTMLFILE; - global $ipcheck,$refresh_display; + global $ipcheck,$check_timeout,$display_percent,$refresh_display,$to_stdout; # NODE directives global $node,$posx,$posy,$height,$width,$label,$labeltype,$labeltpt,$iconpng,$iconx,$icony,$iconresize,$icon_transparent; @@ -36,6 +36,9 @@ function read_config($filename) { } else { $lines=file($filename); $autoscale=0; + $display_percent = 1; + $check_timeout = 10; + $to_stdout = 1; foreach ($lines as $line_num => $line) { if ($DEBUG) { echo 'Ligne No ' . $line_num . ' : ' . $line . '
'."\n"; } @@ -242,6 +245,21 @@ function read_config($filename) { if ($DEBUG) echo "configuration : IPCHECK directive detected : ".$ipcheck."
";; } + if (preg_match("/^\s*\bCHECKTIMEOUT\b\s+(\S+)/i",$line,$out)) { + $check_timeout=$out[1]; + if ($DEBUG) echo "configuration : CHECKTIMEOUT directive detected : ".$check_timeout."
";; + } + + if (preg_match("/^\s*\bDISPLAYPERCENT\b\s+(\S+)/i",$line,$out)) { + $display_percent=$out[1]; + if ($DEBUG) echo "configuration : DISPLAYPERCENT directive detected : ".$display_percent."
";; + } + + if (preg_match("/^\s*\bTOSTDOUT\b\s+(\S+)/i",$line,$out)) { + $to_stdout=$out[1]; + if ($DEBUG) echo "configuration : TOSTDOUT directive detected : ".$to_stdout."
";; + } + # # Read link directives # diff -puNr weathermap4rrd_old/graphic.php weathermap4rrd/graphic.php --- weathermap4rrd_old/graphic.php 2005-12-18 12:58:14.000000000 +0100 +++ weathermap4rrd/graphic.php 2008-01-05 02:25:09.000000000 +0100 @@ -36,48 +36,90 @@ function getposx_line($y,$x1,$y1,$x2,$y2 return ($c*$y+$d); } +function surface_width ($surface) +{ + return cairo_image_surface_get_width ($surface); +} + +function surface_height ($surface) +{ + return cairo_image_surface_get_height ($surface); +} + +function set_font ($cr) { + cairo_select_font_face ($cr, "Monospace", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); +} + +function draw_text ($cr, $text, $size = 9, $bold = false) { + $size *= 1.2; + $wpad = 2; + $hpad = 1; + cairo_set_font_size ($cr, $size); + $extents = cairo_text_extends ($cr, $text); + $width = $extents["width"]; + $height = $extents["height"]; + $surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $width + 2 * $wpad, + $height + 2 * $hpad); + $cr2 = cairo_create ($surface); + set_font ($cr2); + cairo_set_font_size ($cr2, $size); + cairo_move_to ($cr2, + - $extents["x_bearing"] + $wpad, + - $extents["y_bearing"] + $hpad); + cairo_show_text ($cr2, $text); + cairo_destroy ($cr2); + return $surface; +} + function draw_rectangle($x1,$y1,$x2,$y2,$w,$solid,$color) { - global $im; + global $cr; global $black,$red,$white; - $point[0]=$x1 + newx($x2-$x1, $y2-$y1, 0, $w); - $point[1]=$y1 + newy($x2-$x1, $y2-$y1, 0, $w); + $points[0] = $x1 + newx($x2-$x1, $y2-$y1, 0, $w); + $points[1] = $y1 + newy($x2-$x1, $y2-$y1, 0, $w); - $point[2]=$x2 + newx($x2-$x1, $y2-$y1, 0, $w); - $point[3]=$y2 + newy($x2-$x1, $y2-$y1, 0, $w); + $points[2] = $x2 + newx($x2-$x1, $y2-$y1, 0, $w); + $points[3] = $y2 + newy($x2-$x1, $y2-$y1, 0, $w); - $point[4]=$x2 + newx($x2-$x1, $y2-$y1, 0, -$w); - $point[5]=$y2 + newy($x2-$x1, $y2-$y1, 0, -$w); + $points[4] = $x2 + newx($x2-$x1, $y2-$y1, 0, -$w); + $points[5] = $y2 + newy($x2-$x1, $y2-$y1, 0, -$w); - $point[6]=$x1 + newx($x2-$x1, $y2-$y1, 0, -$w); - $point[7]=$y1 + newy($x2-$x1, $y2-$y1, 0, -$w); + $points[6] = $x1 + newx($x2-$x1, $y2-$y1, 0, -$w); + $points[7] = $y1 + newy($x2-$x1, $y2-$y1, 0, -$w); if ($solid) { - imagefilledPolygon($im,$point,4,$color); - imagepolygon($im,$point,4,$black); - }else{ - imagepolygon($im,$point,4,$black); + cairo_draw_polygon ($cr, $points, 4); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); + cairo_fill_preserve ($cr); + cairo_set_source_rgb ($cr, $black[0], $black[1], $black[2]); + cairo_stroke ($cr); + } else { + cairo_draw_polygon ($cr, $points, 4); + cairo_set_source_rgb ($cr, $black[0], $black[1], $black[2]); + cairo_stroke ($cr); } } - function draw_rectangle_map($x1,$y1,$x2,$y2,$w,$linkname,$linkoverlibgraph,$linkinfourl) { - $point[0]=round($x1 + newx($x2-$x1, $y2-$y1, 0, $w)); - $point[1]=round($y1 + newy($x2-$x1, $y2-$y1, 0, $w)); + $points[0] = round($x1 + newx($x2-$x1, $y2-$y1, 0, $w)); + $points[1] = round($y1 + newy($x2-$x1, $y2-$y1, 0, $w)); - $point[2]=round($x2 + newx($x2-$x1, $y2-$y1, 0, $w)); - $point[3]=round($y2 + newy($x2-$x1, $y2-$y1, 0, $w)); + $points[2] = round($x2 + newx($x2-$x1, $y2-$y1, 0, $w)); + $points[3] = round($y2 + newy($x2-$x1, $y2-$y1, 0, $w)); - $point[4]=round($x2 + newx($x2-$x1, $y2-$y1, 0, -$w)); - $point[5]=round($y2 + newy($x2-$x1, $y2-$y1, 0, -$w)); + $points[4] = round($x2 + newx($x2-$x1, $y2-$y1, 0, -$w)); + $points[5] = round($y2 + newy($x2-$x1, $y2-$y1, 0, -$w)); - $point[6]=round($x1 + newx($x2-$x1, $y2-$y1, 0, -$w)); - $point[7]=round($y1 + newy($x2-$x1, $y2-$y1, 0, -$w)); + $points[6] = round($x1 + newx($x2-$x1, $y2-$y1, 0, -$w)); + $points[7] = round($y1 + newy($x2-$x1, $y2-$y1, 0, -$w)); $html_map_string="2*$w; $xi=$xi+2*$w+$step) { $yi=getposy_line($xi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } else { for ($xi = $x1-2*$w; dist_bw_points($xi,$yi,$x2,$y2)>2*$w; $xi=$xi-2*$w-$step) { $yi=getposy_line($xi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } @@ -322,29 +391,31 @@ function draw_circle3($x1,$y1,$x2,$y2,$w if ( ($y1<$y2) ) { for ($yi = $y1; dist_bw_points($xi,$yi,$x2,$y2)>2*$w; $yi=$yi+2*$w+$step) { $xi=getposx_line($yi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } else { for ($yi = $y1-2*$w; dist_bw_points($xi,$yi,$x2,$y2)>2*$w; $yi=$yi-2*$w-$step) { $xi=getposx_line($yi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } } } - - function draw_arrow_circle3($x1,$y1,$x2,$y2,$w,$step,$solid,$color) { - global $im; + global $cr; global $black,$red,$white,$orange; $dif_horizontal=abs($x1-$x2); $dif_vertical=abs($y1-$y2); @@ -352,19 +423,23 @@ function draw_arrow_circle3($x1,$y1,$x2, if ( ($x1 < $x2) ) { for ($xi = $x1; dist_bw_points($xi,$yi,$x2,$y2)>4*$w; $xi=$xi+2*$w+$step) { $yi=getposy_line($xi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } else { for ($xi = $x1; dist_bw_points($xi,$yi,$x2,$y2)>4*$w; $xi=$xi-2*$w-$step) { $yi=getposy_line($xi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } @@ -372,142 +447,165 @@ function draw_arrow_circle3($x1,$y1,$x2, if ( ($y1<$y2) ) { for ($yi = $y1+$w; dist_bw_points($xi,$yi,$x2,$y2)>4*$w; $yi=$yi+2*$w+$step) { $xi=getposx_line($yi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } else { for ($yi = $y1-$w; dist_bw_points($xi,$yi,$x2,$y2)>4*$w; $yi=$yi-2*$w-$step) { $xi=getposx_line($yi,$x1,$y1,$x2,$y2); + cairo_arc ($cr, $xi, $yi, $w, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); if ($solid) { - imagefilledarc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color,"IMG_ARC_PIE"); + cairo_fill ($cr); } else { - imagearc($im,$xi,$yi,2*$w, 2*$w, 0, 360, $color); + cairo_stroke ($cr); } } } } - $point[0]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, $w); - $point[1]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, $w); - $point[2]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, 2*$w); - $point[3]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, 2*$w); - $point[4]=$x2; - $point[5]=$y2; - $point[6]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, -2*$w); - $point[7]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, -2*$w); - $point[8]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, -$w); - $point[9]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, -$w); + $points[0] = $x2 + newx($x2-$x1, $y2-$y1, -4*$w, $w); + $points[1] = $y2 + newy($x2-$x1, $y2-$y1, -4*$w, $w); + $points[2] = $x2 + newx($x2-$x1, $y2-$y1, -4*$w, 2*$w); + $points[3] = $y2 + newy($x2-$x1, $y2-$y1, -4*$w, 2*$w); + $points[4] = $x2; + $points[5] = $y2; + $points[6] = $x2 + newx($x2-$x1, $y2-$y1, -4*$w, -2*$w); + $points[7] = $y2 + newy($x2-$x1, $y2-$y1, -4*$w, -2*$w); + $points[8] = $x2 + newx($x2-$x1, $y2-$y1, -4*$w, -$w); + $points[9] = $y2 + newy($x2-$x1, $y2-$y1, -4*$w, -$w); if ($solid) { - imagefilledpolygon($im,$point,5,$color); + cairo_draw_polygon ($cr, $points, 5); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); + cairo_fill ($cr); } else { - imagepolygon($im,$point,5,$color); - } -} - -function draw_arrow_dot($x1,$y1,$x2,$y2,$w,$solid,$color) { - global $im; - global $black,$red,$white; - - $point[0]=$x1 + newx($x2-$x1, $y2-$y1, 0, $w); - $point[1]=$y1 + newy($x2-$x1, $y2-$y1, 0, $w); - $point[2]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, $w); - $point[3]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, $w); - $point[4]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, 2*$w); - $point[5]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, 2*$w); - $point[6]=$x2; - $point[7]=$y2; - $point[8]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, -2*$w); - $point[9]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, -2*$w); - $point[10]=$x2 + newx($x2-$x1, $y2-$y1, -4*$w, -$w); - $point[11]=$y2 + newy($x2-$x1, $y2-$y1, -4*$w, -$w); - $point[12]=$x1 + newx($x2-$x1, $y2-$y1, 0, -$w); - $point[13]=$y1 + newy($x2-$x1, $y2-$y1, 0, -$w); - - #echo "point[$i]=".$point[$i]." point[".$i+1."]=".$point[$i+1]."
"; - #echo "test $point[$i]
"; - if ($solid) { - imagefilledPolygon($im,$point,7,$color); - $style=array($white, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT ); - imagesetstyle ($im, $style); - imagesetthickness($im,10); - imageline ($im, middle($point[0],$point[12]),middle($point[1],$point[13]),$point[6],$point[7], IMG_COLOR_STYLED); - imagesetthickness($im,1); - imagepolygon($im,$point,7,$black); - }else{ - imagepolygon($im,$point,7,$black); - } -} - -function labelv2($main_im,$string,$font,$textcolor,$bgcolor){ - $pix_width=imagefontwidth($font)*strlen($string); - $pix_height=imagefontheight($font); - $pad=2; - - $im = @imagecreate ($pix_width+$pad*2+4,$pix_height+$pad*2) or die ("Cannot Initialize new GD image stream"); - $color_tran_bg = imagecolorsforindex($main_im, $bgcolor); - $bgcolor=imagecolorallocate($im,$color_tran_bg[red],$color_tran_bg[green],$color_tran_bg[blue]); - $color_tran_fg = imagecolorsforindex($main_im, $textcolor); - $textcolor=imagecolorallocate($im,$color_tran_fg[red],$color_tran_fg[green],$color_tran_fg[blue]); - - imagefilledrectangle($im, 0, 0, $pix_width+$pad*2+4, $pix_height+$pad*2-1, $textcolor); - imagefilledrectangle($im, 1, 1, $pix_width+$pad*2+2, $pix_height+$pad*2-2, $bgcolor); - imagestring($im, $font, 0+$pad+2, 0+$pad/2, $string, $textcolor); - return ($im); -} - -function labelv2_map($string,$font,$textcolor,$bgcolor){ -} - -function draw_internode($string,$font,$textcolor,$bgcolor,$internodenumdisp){ - $radius=7; - $pix_width=2*$radius; - $pix_height=2*$radius; - - $im = @imagecreate ($pix_width+2,$pix_height+2) or die ("Cannot Initialize new GD image stream"); - $whiteinter=imagecolorallocate($im, 255, 255, 255); - imagecolortransparent($im,$whiteinter); - $black=imagecolorallocate($im, 0,0,0); - $grey=imagecolorallocate($im, 192,192,192); - $red=imagecolorallocate($im, 255, 0, 0); - $blue=imagecolorallocate($im, 0, 0, 255); - $yellow=imagecolorallocate($im, 255, 255, 0); - - imagefilledellipse($im,$radius+1, $radius+1,2*$radius,2*$radius,$grey); - imageellipse($im,$radius+1, $radius+1,2*$radius,2*$radius,$black); - if ($internodenumdisp) { imagestring($im, gdTinyFont, $radius, $radius-imagefontwidth(gdTinyFont)*strlen($string)/2, $string, $yellow); } - - return ($im); + cairo_draw_polygon ($cr, $points, 5); + cairo_set_source_rgb ($cr, $color[0], $color[1], $color[2]); + cairo_stroke ($cr); + } +} + +function labelv2 ($cr, $string, $font, $textcolor, $bgcolor) +{ + $textsurface = draw_text ($cr, $string); + $pix_width = surface_width ($textsurface); + $pix_height = surface_height ($textsurface); + $pad = 2; + + $surface = @cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $pix_width + $pad * 2, + $pix_height + $pad * 2) + or die ("Cannot Initialize new Cairo surface"); + $cr2 = cairo_create ($surface); + cairo_rectangle ($cr2, 0, 0, + $pix_width + $pad * 2, + $pix_height + $pad * 2); + cairo_set_source_rgb ($cr2, $bgcolor[0], $bgcolor[1], $bgcolor[2]); + cairo_fill_preserve ($cr2); + cairo_set_source_rgb ($cr2, $textcolor[0], $textcolor[1], $textcolor[2]); + cairo_stroke ($cr2); + cairo_set_source_surface ($cr2, $textsurface, $pad, $pad); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); + cairo_destroy ($cr2); + return $surface; +} + +function labelv2_map($string,$font,$textcolor,$bgcolor) +{ +} + +function draw_internode ($string,$font,$textcolor,$bgcolor,$internodenumdisp){ + global $black, $gray; + $radius = 7; + $pix_width = 2 * $radius; + $pix_height = 2 * $radius; + + $surface = @cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $pix_width + 2, + $pix_height + 2) + or die ("Cannot Initialize new Cairo surface"); + $cr = cairo_create ($surface); + + cairo_arc ($cr, $radius + 1, $radius + 1, $radius, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $gray[0], $gray[1], $gray[2]); + cairo_fill_preserve ($cr); + cairo_set_source_rgb ($cr, $black[0], $black[1], $black[2]); + cairo_stroke ($cr); + + if ($internodenumdisp) { + $textsurface = draw_text ($cr, $string, 7); + $pix_width = surface_width ($textsurface); + $pix_height = surface_height ($textsurface); + cairo_set_source_surface ($cr, $textsurface, + round ($radius - $pix_width / 2), + round ($radius - $pix_height / 2 + 1)); + cairo_paint ($cr); + cairo_surface_destroy ($textsurface); + } + + cairo_destroy ($cr); + + return $surface; +} + +function label ($cr,$string,$xpos,$ypos,$font,$textcolor,$bgcolor){ + $textsurface = draw_text ($cr, $string); + $pix_width = surface_width ($textsurface); + $pix_height = surface_height ($textsurface); + $pad = 2; + + $surface = @cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $pix_width + $pad * 2, + $pix_height + $pad * 2) + or die ("Cannot Initialize new Cairo surface"); + $cr2 = cairo_create ($surface); + cairo_rectangle ($cr2, 0, 0, + $pix_width + $pad * 2, + $pix_height + $pad * 2); + cairo_set_source_rgb ($cr2, $bgcolor[0], $bgcolor[1], $bgcolor[2]); + cairo_fill_preserve ($cr2); + cairo_set_source_rgb ($cr2, $textcolor[0], $textcolor[1], $textcolor[2]); + cairo_stroke ($cr2); + cairo_set_source_surface ($cr2, $textsurface, $pad, $pad); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); + cairo_destroy ($cr2); + cairo_set_source_surface ($cr, $surface, + floor ($xpos - $pix_width / 2), + floor ($ypos - $pix_height / 2)); + cairo_paint ($cr); + cairo_surface_destroy ($surface); +} + +function label_round($cr,$string,$xpos,$ypos,$font,$textcolor,$bgcolor){ + global $black; + $radius = 6; + $textsurface = draw_text ($cr, $string, 8, true); + $pix_width = surface_width ($textsurface); + $pix_height = surface_height ($textsurface); + + cairo_arc ($cr, $xpos, $ypos, 2 * $radius, 0, 2 * M_PI); + cairo_set_source_rgb ($cr, $bgcolor[0], $bgcolor[1], $bgcolor[2]); + cairo_fill_preserve ($cr); + cairo_set_source_rgb ($cr, $black[0], $black[1], $black[2]); + cairo_stroke ($cr); + cairo_set_source_surface ($cr, $textsurface, + floor ($xpos - $pix_width / 2), + floor ($ypos + 2 * $radius)); + cairo_paint ($cr); + cairo_surface_destroy ($textsurface); } - -function label($im,$string,$xpos,$ypos,$font,$textcolor,$bgcolor){ - $pix_width=imagefontwidth($font)*strlen($string); - $pix_height=imagefontheight($font); - $pad=2; - imagefilledrectangle($im, $xpos-$pix_width/2-$pad-2, $ypos-$pix_height/2-$pad+1, $xpos+$pix_width/2+$pad+1, $ypos+$pix_height/2+$pad, $textcolor); - imagefilledrectangle($im, $xpos-$pix_width/2-$pad-1, $ypos-$pix_height/2-$pad+2, $xpos+$pix_width/2+$pad, $ypos+$pix_height/2+$pad-1, $bgcolor); - imagestring($im, $font, $xpos-$pix_width/2, $ypos-$pix_height/2, $string, $textcolor); -} - -function label_round($im,$string,$xpos,$ypos,$font,$textcolor,$bgcolor){ - $radius=10; - $pix_width=imagefontwidth($font)*strlen($string); - $pix_height=imagefontheight($font); - $black=imagecolorallocate($im, 0,0,0); - - imagefilledellipse($im,$xpos, $ypos,2*$radius,2*$radius,$bgcolor); - imageellipse($im,$xpos, $ypos,2*$radius,2*$radius,$black); - imagestring($im, $font-1, $xpos-$pix_width/2, $ypos+$radius, $string, $textcolor); -} - - -function select_color($im,$rate,$scale_low, $scale_high, $scale_red, $scale_green, $scale_blue) { - global $scalecolor; +function select_color($cr,$rate,$scale_low, $scale_high, $scale_red, $scale_green, $scale_blue) { + global $scalecolor, $darkgray; if($rate=="0") return($darkgray); foreach ($scale_low as $i => $value) { @@ -518,169 +616,165 @@ function select_color($im,$rate,$scale_l return ($darkgray); } -function define_colors($im) { +function define_colors () { global $backgroundcolor_red,$backgroundcolor_green,$backgroundcolor_blue; global $titleforeground_red,$titleforeground_green,$titleforeground_blue,$titlebackground_red,$titlebackground_green,$titlebackground_blue; - global $black,$orange,$white,$darkgray,$gray,$red,$green,$titleforeground,$titlebackground; + global $black,$orange,$white,$darkgray,$gray,$red,$green,$yellow,$blue,$titleforeground,$titlebackground; global $scale_low,$scale_red,$scale_blue,$scale_green,$scalecolor; - if ( ($backgroundcolor=imagecolorallocate($im,$backgroundcolor_red,$backgroundcolor_green,$backgroundcolor_blue)) =="-1") { - $backgroundcolor=imagecolorclosest($im,$backgroundcolor_red,$backgroundcolor_green,$backgroundcolor_blue); - } - - if ( ($white=imagecolorallocate($im, 255, 255, 255)) =="-1") { - $white=imagecolorclosest($im,255,255,255); - } + $backgroundcolor = array ($backgroundcolor_red / 255, + $backgroundcolor_green / 255, + $backgroundcolor_blue / 255); + + $white = array (1, 1, 1); + $red = array (1, 0, 0); + $darkgray = array (0.5, 0.5, 0.5); + $gray = array (0.90, 0.90, 0.90); + $orange = array (0.86, 0.82, 0.24); + $black = array (0, 0, 0); + $green = array (0, 1, 0); + $blue = array (0, 0, 1); + $yellow = array (1, 1, 0); - if ( ($red=imagecolorallocate($im, 255, 0, 0)) =="-1") { - $red= imagecolorClosest($im, 255, 0, 0); - } - if ( ($darkgray=imagecolorallocate($im, 128, 128, 128)) =="-1") { - $darkgray = imagecolorClosest($im,128,128,128); - } - if ( ($gray=imagecolorallocate($im, 248, 248, 248)) =="-1") { - $gray = imagecolorClosest($im, 248, 248, 248); - } - if ( ($orange=imagecolorallocate($im, 220, 210, 60)) =="-1") { - $orange = imagecolorClosest($im, 220, 210, 60); - } - if ( ($black=imagecolorallocate($im, 0, 0, 0)) =="-1") { - $black = imagecolorClosest($im, 0, 0, 0); - } - if ( ($green=imagecolorallocate($im, 0, 255, 0)) =="-1") { - $green= imagecolorClosest($im, 0, 255, 0); - } - foreach ($scale_low as $indice => $value) { - if ( ($scalecolor[$indice]=imagecolorallocate($im, $scale_red[$indice], $scale_green[$indice], $scale_blue[$indice])) =="-1") { - $scalecolor[$indice]=imagecolorClosest($im, $scale_red[$indice], $scale_green[$indice], $scale_blue[$indice]); - } + $scalecolor[$indice] = array ($scale_red[$indice] / 255, + $scale_green[$indice] / 255, + $scale_blue[$indice] / 255); } - } function draw_title($title,$font,$titleforeground_red,$titleforeground_green,$titleforeground_blue,$titlebackground_red,$titlebackground_green,$titlebackground_blue,$unixtime) { + global $cr; - $t=date("D M d H:i:s Y",$unixtime); - #$t="$unixtime"; + $t = date ("D M d H:i:s Y", $unixtime); + $updatestring = "Last update on {$t}"; - if (imagefontwidth(2)*strlen("Last update on $t")>imagefontwidth($font)*strlen($title)) { - $titlewidth=imagefontwidth($font-2)*strlen("Last update on $t"); - } else { - $titlewidth=imagefontwidth($font)*strlen($title); - } - - $im = @imagecreate ($titlewidth+5,imagefontheight($font)*2+5) or die ("Cannot Initialize new GD image stream"); - - if ( ($titlebackground=imagecolorAllocate($im,$titlebackground_red,$titlebackground_green,$titlebackground_blue)) =="-1") { - $titlebackground=imagecolorClosest($im,$titlebackground_red,$titlebackground_green,$titlebackground_blue); - } - - if (($titleforeground=imagecolorAllocate($im,$titleforeground_red,$titleforeground_green,$titleforeground_blue)) =="-1") { - $titleforeground=imagecolorClosest($im,$titleforeground_red,$titleforeground_green,$titleforeground_blue); - } - - imagefilledrectangle($im, 0, 0, - $titlewidth+3, imagefontheight($font)*2+3, - $titlebackground); - imagerectangle($im, 0, 0, - $titlewidth+4, imagefontheight($font)*2+4, - $titleforeground); - imagestring($im, $font, 2, 2, $title, $titleforeground); - imagestring($im, $font-2, 2, imagefontheight($font)+4, "Last update on $t", $titleforeground); - return ($im); + $titlesurface = draw_text ($cr, $title); + $updatesurface = draw_text ($cr, $updatestring, 7); + $title_width = surface_width ($titlesurface); + $title_height = surface_height ($titlesurface); + $update_width = surface_width ($updatesurface); + $update_height = surface_height ($updatesurface); + + $titlewidth = max ($update_width, $title_width); + $titleheight = $title_height + $update_height; + + $surface = @cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $titlewidth + 5, + $titleheight + 5) + or die ("Cannot Initialize new Cairo surface"); + + $cr2 = cairo_create ($surface); + + cairo_rectangle ($cr2, 0, 0, $titlewidth + 5, $titleheight + 5); + cairo_set_source_rgb ($cr2, $titlebackground_red, + $titlebackground_green, $titlebackground_blue); + cairo_fill_preserve ($cr2); + cairo_set_source_rgb ($cr2, $titleforeground_red, + $titleforeground_green, $titleforeground_blue); + cairo_stroke ($cr2); + cairo_set_source_surface ($cr2, $titlesurface, 2, 2); + cairo_paint ($cr2); + cairo_surface_destroy ($titlesurface); + cairo_set_source_surface ($cr2, $updatesurface, + 2, $title_height + 3); + cairo_paint ($cr2); + cairo_surface_destroy ($updatesurface); + cairo_destroy ($cr2); + return $surface; } function draw_legend($label,$font,$scale_low,$scale_high,$scale_red, $scale_green, $scale_blue) { - global $VERSION; + global $cr; + global $white, $orange, $black, $gray, $scalecolor; - $strwidth=imagefontwidth($font); - $strheight=imagefontheight($font); + $textsurface = draw_text ($cr, $label); + $pix_width = surface_width ($textsurface); + $pix_height = surface_height ($textsurface); + + $surface = @cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $pix_width + 15, + $pix_height * (count ($scale_low) + 1) + 11) + or die ("Cannot Initialize new Cairo surface"); + + $cr2 = cairo_create ($surface); + $textcolor = $black; + + cairo_rectangle ($cr2, 0, 0, $pix_width + 15, + $pix_height * (count ($scale_low) + 1) + 11); + cairo_set_source_rgb ($cr2, $gray[0], $gray[1], $gray[2]); + cairo_fill_preserve ($cr2); + cairo_set_source_rgb ($cr2, $black[0], $black[1], $black[2]); + cairo_stroke ($cr2); + + cairo_set_source_surface ($cr2, $textsurface, 4, 4); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); - $im = @imagecreate ($strwidth*strlen($label)+11,$strheight*(count($scale_low)+1)+11+imagefontheight(1)*2) or die ("Cannot Initialize new GD image stream"); - $white=imagecolorallocate($im, 255, 255, 255); - $orange = imagecolorallocate($im, 220, 210, 60); - $black=imagecolorallocate($im, 0,0,0); - $gray=imagecolorallocate($im, 248, 248, 248); - $textcolor = imagecolorallocate($im, 0, 0, 0); + $i = 0; foreach ($scale_low as $indice => $value) { - if ( ($scalecolor[$indice]=imagecolorallocate($im, $scale_red[$indice], $scale_green[$indice], $scale_blue[$indice])) =="-1") { - $scalecolor[$indice]=imagecolorClosest($im, $scale_red[$indice], $scale_green[$indice], $scale_blue[$indice]); - } - } - - - imagefilledrectangle($im, 0, 0, - $strwidth*strlen($label)+10, $strheight*(count($scale_low)+1)+10+imagefontheight(1)*2, - $black); - imagefilledrectangle($im, 0, 0, - $strwidth*strlen($label)+10, $strheight*(count($scale_low)+1)+10+imagefontheight(1), - $gray); - imagerectangle($im, 0, 0, - $strwidth*strlen($label)+10, $strheight*(count($scale_low)+1)+10+imagefontheight(1)*2, - $black); - - imagestring($im, $font, 4, 4, $label, $black); - foreach ($scale_low as $indice => $value) { - imagefilledrectangle($im, 6, $strheight*($i+1)+8, - 6+16, $strheight*($i+1)+$strheight+6, - $scalecolor["$scale_low[$indice]:$scale_high[$indice]"]); - imagestring($im, $font, 6+20, $strheight*($i+1)+8,$scale_low[$indice]."-".$scale_high[$indice]."%", $black); - $i++; + $color = $scalecolor[$indice]; + cairo_set_source_rgb ($cr2, $color[0], $color[1], $color[2]); + cairo_rectangle ($cr2, 6, $pix_height * ($i + 1) + 8, + 16, $pix_height - 2); + cairo_fill ($cr2); + $string = $scale_low[$indice]."-".$scale_high[$indice]."%"; + $textsurface = draw_text ($cr2, $string); + cairo_set_source_surface ($cr2, $textsurface, 6 + 20, + $pix_height * ($i + 1) + 8); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); + $i++; } - - imagestring($im, 1, (($strwidth*strlen($label)+10)-imagefontwidth(1)*strlen("WeatherMap4RRD $VERSION"))/2, $strheight*($i+1)+18, "WeatherMap4RRD $VERSION", $white); - return ($im); + cairo_destroy ($cr2); + cairo_surface_write_to_png ($surface, "kthx.png"); + return $surface; } function draw_legend2($label,$font,$scale_low,$scale_high,$scale_red, $scale_green, $scale_blue) { - global $VERSION; - $strwidth=imagefontwidth($font); - $strheight=imagefontheight($font); - - #$im = @imagecreate ($strwidth*strlen($label)+11,$strheight*(count($scale_low)+1)+11+imagefontheight(1)*2) or die ("Cannot Initialize new GD image stream"); - - #$im = @imagecreate (280,55) or die ("Cannot Initialize new GD image stream"); - - $x=count($scale_low)*36+6+1+$strwidth*4; - $y=6+$strheight*2+23; - - $im = @imagecreate ($x,$y) or die ("Cannot Initialize new GD image stream"); - $white=imagecolorallocate($im, 255, 255, 255); - $orange = imagecolorallocate($im, 220, 210, 60); - $black=imagecolorallocate($im, 0,0,0); - $gray=imagecolorallocate($im, 248, 248, 248); - $textcolor = imagecolorallocate($im, 0, 0, 0); - foreach ($scale_low as $indice => $value) { - if ( ($scalecolor[$indice]=imagecolorallocate($im, $scale_red[$indice], $scale_green[$indice], $scale_blue[$indice])) =="-1") { - $scalecolor[$indice]=imagecolorClosest($im, $scale_red[$indice], $scale_green[$indice], $scale_blue[$indice]); - } - } + global $cr; + global $white, $orange, $black, $gray, $scalecolor; + + $textsurface = draw_text ($cr, $label); + $pix_width = surface_width ($textsurface); + $pix_height = surface_height ($textsurface); + + $x = count ($scale_low) * 36 + 6 + 1 + $pix_width * 4; + $y = 6 + $pix_height * 2 + 23; + + $surface = @cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + $x, $y) + or die ("Cannot Initialize new Cairo surface"); + $cr2 = cairo_create ($surface); + $textcolor = $black; -# imagefilledrectangle($im, 0, 0, -# $x,$y, -# $orange); + cairo_set_source_surface ($cr2, $textsurface, 4, 4); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); - imagestring($im, $font, 4, 4, $label, $black); + $i = 0; foreach ($scale_low as $indice => $value) { - imagefilledrectangle($im, - 6+36*$i, 23, - 6+($i+1)*36, 23+10, - $scalecolor["$scale_low[$indice]:$scale_high[$indice]"]); - imagerectangle($im, - 6+36*$i, 23, - 6+($i+1)*36, 23+10, - $black); - imagestring($im, $font, - 6+($i+1)*36-5, 23+12, - $scale_high[$indice], - #$scale_low[$indice]."-".$scale_high[$indice]."%", - $black); + $color = $scalecolor[$indice]; + cairo_set_source_rgb ($cr2, $color[0], $color[1], $color[2]); + cairo_rectangle ($cr2, 6 + 36 * $i, 23, 36, 10); + cairo_fill_preserve ($cr2); + cairo_set_source_rgb ($cr2, $black[0], $black[1], $black[2]); + cairo_stroke ($cr2); + $string = $scale_high[$indice]; + $textsurface = draw_text ($cr2, $string); + $width = surface_width ($textsurface); + cairo_set_source_surface ($cr2, $textsurface, 1 + ($i + 1) * 36, + 23 + 12); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); $i++; } - imagestring($im, $font,6+($i)*36+strlen($scale_high[$indice])*$strwidth, 23+12, "%", $black); - imagestring($im, 1,6+($i)*36-strlen("WeatherMap4RRD $VERSION")*imagefontwidth(1),23-10, "WeatherMap4RRD $VERSION", $black); - return ($im); + $textsurface = draw_text ($cr2, "%"); + cairo_set_source_surface ($cr2, $textsurface, + 6 + $i * 36 + $width, 23 + 12); + cairo_paint ($cr2); + cairo_surface_destroy ($textsurface); + return $surface; } ?> diff -puNr weathermap4rrd_old/net.php weathermap4rrd/net.php --- weathermap4rrd_old/net.php 2005-12-18 12:58:14.000000000 +0100 +++ weathermap4rrd/net.php 2008-01-04 19:23:58.000000000 +0100 @@ -1,13 +1,67 @@ 0) { + /* readable sockets either have data for us, or are failed + * connection attempts */ + foreach ($read as $r) { + $id = array_search ($r, $sockets); + $data = fread ($r, 8192); + if (strlen ($data) == 0) { + if ($status[$id] == -1) { + $status[$id] = 0; + } + fclose ($r); + unset ($sockets[$id]); + } + } + /* writeable sockets can accept an HTTP request */ + foreach ($write as $w) { + $id = array_search ($w, $sockets); + $status[$id] = 1; + @fclose ($w); + unset ($sockets[$id]); + } + } else { + /* timed out waiting; assume that all hosts associated + * with $sockets are faulty */ + foreach ($sockets as $id => $s) { + $status[$id] = 0; + } + break; + } + } + $___SERVICES_STATUS = $status; +} + +function checkservice($ip, $port) +{ + global $___SERVICES_STATUS; + return $___SERVICES_STATUS["{$ip}:{$port}"]; } function ping($ip){ diff -puNr weathermap4rrd_old/w4rrd.php weathermap4rrd/w4rrd.php --- weathermap4rrd_old/w4rrd.php 2005-12-18 14:27:17.000000000 +0100 +++ weathermap4rrd/w4rrd.php 2008-01-05 01:50:07.000000000 +0100 @@ -8,41 +8,34 @@ require "net.php"; $unixtime=$_REQUEST['unixtime']; -if (isset($_GET['config'])) { - $configfile=$_GET['config']; - if ($configfile=="") { $configfile="weathermap.conf"; } -} - if ($unixtime) { - $month=date("m",$unixtime); - $day=date("d",$unixtime); - $year=date("Y",$unixtime); - $hours=date("H",$unixtime); - $minutes=date("i",$unixtime); - $seconds=date("s",$unixtime); -} elseif ($month && $day && $year) { - $month=$_REQUEST['month']; - $day=$_REQUEST['day']; - $year=$_REQUEST['year']; - $hours=$_REQUEST['hours']; - $minutes=$_REQUEST['minutes']; - $seconds=$_REQUEST['seconds']; - - $unixtime=mktime($hours,$minutes,$seconds,$month,$day,$year); + $month = date("m", $unixtime); + $day = date("d", $unixtime); + $year = date("Y", $unixtime); + $hours = date("H", $unixtime); + $minutes = date("i", $unixtime); + $seconds = date("s", $unixtime); + $unixtime = mktime ($hours,$minutes,$seconds,$month,$day,$year); +} else { + $month = date("m"); + $day = date("d"); + $year = date("Y"); + $hours = date("H"); + $minutes = date("i"); + $seconds = date("s"); } if ($unixtime) { - $date=$unixtime; + $date = $unixtime; } # If no filter parameter is send to the script to only display link belonging to GROUP defined $filter=$_REQUEST["group"]; if ((! $filter) || $filter=="all") { $filter=""; } - - # Check if GD module is installed with PHP - if (! extension_loaded('gd')) { - error_display("PHP GD module is needed for Weathermap4RRD."); + # Check if cairo_wrapper is installed with PHP + if (! extension_loaded('cairo_wrapper')) { + error_display("PHP cairo_wrapper module is needed for Weathermap4RRD."); exit; } @@ -54,51 +47,73 @@ if ($unixtime) { exit; } - - # Create global GD image for network map + # Create global Cairo surface for network map # Size : X = $width+8 # Y = $height+4 if (empty($background)) { - $im = imagecreate($width+8,$height+4) or die ("Cannot Initialize new GD image stream"); + $surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, $width+8,$height+4) or die ("Cannot Initialize new Cairo surface"); } else { if (file_exists($background)) { - $im = @imagecreatefrompng($background); - if ($DEBUG) echo "Number of colors existing in $background : ".imagecolorstotal($im)."
"; + $surface = @cairo_image_surface_create_from_png ($background); } else { error_display("$background specified in configuration file has not been found. Check use of BACKGROUND directive."); exit; } } - # Define main colors of GD image - define_colors($im); + $display_percent = $display_percent ? 1 : 0; + + $cr = cairo_create ($surface); + set_font ($cr); + cairo_set_operator ($cr, CAIRO_OPERATOR_CLEAR); + cairo_paint ($cr); + + cairo_set_operator ($cr, CAIRO_OPERATOR_OVER); + + define_colors (); + $text = draw_text ($cr, "AB"); + $small_text = draw_text ($cr, "AB", 7); + $char_width = surface_width ($text) / 2; + $char_height = surface_height ($text); + $small_char_width = surface_width ($small_text) / 2; + $small_char_height = surface_height ($small_text); + cairo_surface_destroy ($text); + cairo_surface_destroy ($small_text); + # Display icons if ($iconpng) { foreach ($iconpng as $node => $i) { if ($iconpng[$node]) { if (file_exists($iconpng[$node])) { - $icone = @imagecreatefrompng($iconpng[$node]); - $iconwidth=imagesx($icone); - $iconheight=imagesy($icone); - $factor=$iconresize[$node]/100; - if (! $factor ) { + $icon = @cairo_image_surface_create_from_png ($iconpng[$node]); + $iconwidth = cairo_image_surface_get_width ($icon); + $iconheight = cairo_image_surface_get_height ($icon); + $factor = $iconresize[$node]/100; + if (!$factor) { $factor=1; } - $icone2=imagecreate($iconwidth*$factor,$iconheight*$factor); - $white2=imagecolorallocate($icone2, 255, 255, 255); - imagecolortransparent($icone2,$white2); - imagecopyresized($icone2,$icone,0,0,0,0,$iconwidth*$factor,$iconheight*$factor,$iconwidth,$iconheight); + $icon2 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, $iconwidth*$factor, $iconheight*$factor); + $cr2 = cairo_create ($icon2); + cairo_set_operator ($cr2, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface ($cr2, $icon, 0, 0); + cairo_scale ($cr2, $factor, $factor); + cairo_paint ($cr2); + cairo_surface_destroy ($icon); + cairo_destroy ($cr2); if ($iconx[$node]==0) { - $iconx[$node] = $posx[$node]-$iconwidth*$factor/2; - $icony[$node] = $posy[$node]-$iconheight*$factor/2; + $iconx[$node] = floor ($posx[$node]-$iconwidth*$factor/2); + $icony[$node] = floor ($posy[$node]-$iconheight*$factor/2); } + + if ($icon_transparent[$node]==0) { + $icon_transparent[$node]= 100; + } - if ($icon_transparent[$node]==0) { - $icon_transparent[$node]= 100; - } - imagecopymerge($im,$icone2,$iconx[$node],$icony[$node],0,0,$iconwidth*$factor,$iconheight*$factor,$icon_transparent[$node]); + cairo_set_source_surface ($cr, $icon2, $iconx[$node], $icony[$node]); + cairo_paint_with_alpha ($cr, $icon_transparent[$node] / 100); + cairo_surface_destroy ($icon2); } else { error_display("File \"".$iconpng[$node]."\" not found. Icon won't be displayed on graph. Please check use of ICON directive."); exit; @@ -189,22 +204,23 @@ if ($unixtime) { $output[$link]=$result["values"][$outpos[$link]-1][0]*$coef[$link]; } - # # # # #echo "input=$input[$link]
"; #echo "output=$output[$link]
"; - if ( (int)(($output[$link]/$maxbytesout[$link]+0.005)*100) > 100 ) { - $outrate=100; - } else { - $outrate=(int)(($output[$link]/$maxbytesout[$link]+0.005)*100); - } - - if ( (int)(($input[$link]/$maxbytesin[$link]+0.005)*100) > 100 ) { - $inrate=100; - } else { - $inrate=(int)(($input[$link]/$maxbytesin[$link]+0.005)*100); - } + if (!$maxbytesout[$link]) + $outrate = 0; + else if ((int)(($output[$link]/$maxbytesout[$link]+0.005)*100) > 100 ) + $outrate = 100; + else + $outrate = (int)(($output[$link]/$maxbytesout[$link]+0.005)*100); + + if (!$maxbytesin[$link]) + $inrate = 0; + else if ((int)(($input[$link]/$maxbytesin[$link]+0.005)*100) > 100 ) + $inrate = 100; + else + $inrate = (int)(($input[$link]/$maxbytesin[$link]+0.005)*100); # Not to display 0% if it is not exactly 0. It will display 1% if($output[$link] != 0 && $outrate == 0) $outrate=1; @@ -433,8 +449,8 @@ if ($unixtime) { break; endswitch; # Display bandwidth % links from node A to node B - if ($arrow[$link]=="halfarrow") { - label($im,"$outrate%", + if ($display_percent && $arrow[$link]=="halfarrow") { + label ($cr,"$outrate%", $posx[$nodeb[$link]]+newx( $posx[$nodeb[$link]]-$internodex[$link][$internodes[$link]], $posy[$nodeb[$link]]-$internodey[$link][$internodes[$link]], @@ -444,8 +460,8 @@ if ($unixtime) { $posy[$nodeb[$link]]-$internodey[$link][$internodes[$link]], -10*$width_arrow,-4*$width_arrow), $font-1,$black,$white); - } else { - label($im,"$outrate%", + } else if ($display_percent) { + label ($cr,"$outrate%", middle($posx[$nodea[$link]],$internodex[$link][1]), middle($posy[$nodea[$link]],$internodey[$link][1]), $font,$black,$white); @@ -463,27 +479,29 @@ if ($unixtime) { $todisplay=round($output[$link]*$coefdisplay,1). "$unitdisplay"; if ($arrow[$link]=="halfarrow") { - if ($posy[$nodeb[$link]] < $internodey[$link][$internodes[$link]]) { + if (!$display_percent) { + $factor = 0; + } else if ($posy[$nodeb[$link]] < $internodey[$link][$internodes[$link]]) { $factor=1; } else { $factor=-1; } - label($im,"$todisplay", + label ($cr,"$todisplay", $posx[$nodeb[$link]]+newx( $posx[$nodeb[$link]]-$internodex[$link][$internodes[$link]], $posy[$nodeb[$link]]-$internodey[$link][$internodes[$link]], - -10*$width_arrow,-4*$width_arrow)-$factor*imagefontwidth($font-1)*(strlen($todisplay)-strlen("$outrate%"))/2, + -10*$width_arrow,-4*$width_arrow)-$factor*$small_char_width*(strlen($todisplay)-strlen("$outrate%"))/2, $posy[$nodeb[$link]]+newy( $posx[$nodeb[$link]]-$internodex[$link][$internodes[$link]], $posy[$nodeb[$link]]-$internodey[$link][$internodes[$link]], - -10*$width_arrow,-4*$width_arrow)+imagefontheight($font-1)+($width_arrow+1), + -10*$width_arrow,-4*$width_arrow)+$small_char_height+($width_arrow+1), $font-1,$black,$white); } else { - label($im,"$todisplay", + label ($cr,"$todisplay", middle($posx[$nodea[$link]],$internodex[$link][1]), - middle($posy[$nodea[$link]],$internodey[$link][1])+19, + middle($posy[$nodea[$link]],$internodey[$link][1])+19 * $display_percent, $font,$black,$white); } } @@ -536,8 +554,8 @@ if ($unixtime) { break; endswitch; # Display bandwidth % links from node A to node B - if ($arrow[$link]=="halfarrow") { - label($im,"$outrate%", + if ($display_percent && $arrow[$link]=="halfarrow") { + label ($cr,"$outrate%", $posx[$nodeb[$link]]+newx( $posx[$nodeb[$link]]-$posx[$nodea[$link]], $posy[$nodeb[$link]]-$posy[$nodea[$link]], @@ -549,8 +567,8 @@ if ($unixtime) { $font-1,$black,$white); - } else { - label($im,"$outrate%", + } else if ($display_percent) { + label ($cr,"$outrate%", middle($posx[$nodea[$link]],middle($posx[$nodea[$link]],$posx[$nodeb[$link]])), middle($posy[$nodea[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]])), $font,$black,$white); @@ -569,26 +587,28 @@ if ($unixtime) { $todisplay=round($output[$link]*$coefdisplay,1). "$unitdisplay"; if ($arrow[$link]=="halfarrow") { - if ($posy[$nodeb[$link]] < $posy[$nodea[$link]]) { + if (!$display_percent) { + $factor = 0; + } else if ($posy[$nodeb[$link]] < $posy[$nodea[$link]]) { $factor=-1; } else { $factor=1; } - label($im,"$todisplay", + label ($cr,"$todisplay", $posx[$nodeb[$link]]+newx( $posx[$nodeb[$link]]-$posx[$nodea[$link]], $posy[$nodeb[$link]]-$posy[$nodea[$link]], - -10*$width_arrow,-3*$width_arrow)-$factor*imagefontwidth($font-1)*(strlen($todisplay)-strlen("$outrate%"))/2, + -10*$width_arrow,-3*$width_arrow)-$factor*$small_char_width*(strlen($todisplay)-strlen("$outrate%"))/2, $posy[$nodeb[$link]]+newy( $posx[$nodeb[$link]]-$posx[$nodea[$link]], $posy[$nodeb[$link]]-$posy[$nodea[$link]], - -10*$width_arrow,-3*$width_arrow)-imagefontheight($font-1)-5, + -10*$width_arrow,-3*$width_arrow)-$small_char_height-5, $font-1,$black,$white); } else { - label($im,"$todisplay",middle($posx[$nodea[$link]],middle($posx[$nodea[$link]],$posx[$nodeb[$link]])), - middle($posy[$nodea[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]]+70)), + label ($cr,"$todisplay",middle($posx[$nodea[$link]],middle($posx[$nodea[$link]],$posx[$nodeb[$link]])), + middle($posy[$nodea[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]]+70 * $display_percent)), $font,$black,$white); } } else { @@ -810,8 +830,8 @@ if ($unixtime) { break; endswitch; # Display bandwidth % links from node B to node A - if ($arrow[$link]=="halfarrow") { - label($im,"$inrate%", + if ($display_percent && $arrow[$link]=="halfarrow") { + label ($cr,"$inrate%", $posx[$nodea[$link]]+newx( $posx[$nodea[$link]]-$internodex[$link][1], $posy[$nodea[$link]]-$internodey[$link][1], @@ -822,8 +842,8 @@ if ($unixtime) { -15*$width_arrow,-5*$width_arrow), $font-1,$black,$white); - } else { - label($im,"$inrate%", + } else if ($display_percent) { + label ($cr,"$inrate%", middle($posx[$nodeb[$link]],$internodex[$link][$internodes[$link]]), middle($posy[$nodeb[$link]],$internodey[$link][$internodes[$link]]), $font,$black,$white); @@ -839,26 +859,28 @@ if ($unixtime) { $todisplay=round($input[$link]*$coefdisplay,1). "$unitdisplay"; if ($arrow[$link]=="halfarrow") { - if ($posy[$nodea[$link]] < $internodey[$link][1]) { + if (!$display_percent) { + $factor = 0; + } else if ($posy[$nodea[$link]] < $internodey[$link][1]) { $factor=-1; } else { $factor=1; } - label($im,"$todisplay", + label ($cr,"$todisplay", $posx[$nodea[$link]]+newx( $posx[$nodea[$link]]-$internodex[$link][1], $posy[$nodea[$link]]-$internodey[$link][1], - -15*$width_arrow,-5*$width_arrow)+$factor*imagefontwidth($font-1)*(strlen($todisplay)-strlen("$inrate%"))/2, + -15*$width_arrow,-5*$width_arrow)+$factor*$small_char_width*(strlen($todisplay)-strlen("$inrate%"))/2, $posy[$nodea[$link]]+newy( $posx[$nodea[$link]]-$internodex[$link][1], $posy[$nodea[$link]]-$internodey[$link][1], - -15*$width_arrow,-5*$width_arrow)+imagefontheight($font-1)+5, + -15*$width_arrow,-5*$width_arrow)+$small_char_height+5, $font-1,$black,$white); } else { - label($im,"$todisplay", + label ($cr,"$todisplay", middle($posx[$nodeb[$link]],$internodex[$link][$internodes[$link]]), - middle($posy[$nodeb[$link]],$internodey[$link][$internodes[$link]])+19, + middle($posy[$nodeb[$link]],$internodey[$link][$internodes[$link]])+19 * $display_percent, $font,$black,$white); } } @@ -910,23 +932,23 @@ if ($unixtime) { break; endswitch; # Display bandwidth % links from node B to node A - if ($arrow[$link]=="halfarrow") { - label($im,"$inrate%", - $posx[$nodea[$link]]+newx( - $posx[$nodea[$link]]-$posx[$nodeb[$link]], - $posy[$nodea[$link]]-$posy[$nodeb[$link]], - -10*$width_arrow,-3*$width_arrow), - $posy[$nodea[$link]]+newy( - $posx[$nodea[$link]]-$posx[$nodeb[$link]], - $posy[$nodea[$link]]-$posy[$nodeb[$link]], - -10*$width_arrow,-3*$width_arrow), - $font-1,$black,$white); - - } else { - label($im,"$inrate%", - middle($posx[$nodeb[$link]],middle($posx[$nodea[$link]],$posx[$nodeb[$link]])), - middle($posy[$nodeb[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]])), - $font,$black,$white); + if ($display_percent && $arrow[$link]=="halfarrow") { + label ($cr,"$inrate%", + $posx[$nodea[$link]]+newx( + $posx[$nodea[$link]]-$posx[$nodeb[$link]], + $posy[$nodea[$link]]-$posy[$nodeb[$link]], + -10*$width_arrow,-3*$width_arrow), + $posy[$nodea[$link]]+newy( + $posx[$nodea[$link]]-$posx[$nodeb[$link]], + $posy[$nodea[$link]]-$posy[$nodeb[$link]], + -10*$width_arrow,-3*$width_arrow), + $font-1,$black,$white); + + } else if ($display_percent) { + label ($cr,"$inrate%", + middle($posx[$nodeb[$link]],middle($posx[$nodea[$link]],$posx[$nodeb[$link]])), + middle($posy[$nodeb[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]])), + $font,$black,$white); } if ($displayvalue[$link]) { if ($input[$link] >=125999) { @@ -938,26 +960,28 @@ if ($unixtime) { } $todisplay=round($input[$link]*$coefdisplay,1). "$unitdisplay"; if ($arrow[$link]=="halfarrow") { - if ($posy[$nodea[$link]] < $posy[$nodeb[$link]]) { - $factor=-1; - } else { - $factor=1; - } + if (!$display_percent) { + $factor = 0; + } else if ($posy[$nodea[$link]] < $posy[$nodeb[$link]]) { + $factor=-1; + } else { + $factor=1; + } - label($im,"$todisplay", - $posx[$nodea[$link]]+newx( - $posx[$nodea[$link]]-$posx[$nodeb[$link]], - $posy[$nodea[$link]]-$posy[$nodeb[$link]], - -10*$width_arrow,-3*$width_arrow)+$factor*imagefontwidth($font-1)*(strlen($todisplay)-strlen("$outrate%"))/2, - $posy[$nodea[$link]]+newy( - $posx[$nodea[$link]]-$posx[$nodeb[$link]], - $posy[$nodea[$link]]-$posy[$nodeb[$link]], - -10*$width_arrow,-3*$width_arrow)+imagefontheight($font-1)+($width_arrow+1), - $font-1,$black,$white); + label ($cr,"$todisplay", + $posx[$nodea[$link]]+newx( + $posx[$nodea[$link]]-$posx[$nodeb[$link]], + $posy[$nodea[$link]]-$posy[$nodeb[$link]], + -10*$width_arrow,-3*$width_arrow)+$factor*$small_char_width*(strlen($todisplay)-strlen("$outrate%"))/2, + $posy[$nodea[$link]]+newy( + $posx[$nodea[$link]]-$posx[$nodeb[$link]], + $posy[$nodea[$link]]-$posy[$nodeb[$link]], + -10*$width_arrow,-3*$width_arrow)+$small_char_height+($width_arrow+1), + $font-1,$black,$white); } else { - label($im,"$todisplay", + label ($cr,"$todisplay", middle($posx[$nodeb[$link]],middle($posx[$nodea[$link]],$posx[$nodeb[$link]])), - middle($posy[$nodeb[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]]+70)), + middle($posy[$nodeb[$link]],middle($posy[$nodea[$link]],$posy[$nodeb[$link]]+70 * $display_percent)), $font,$black,$white); } } else { @@ -972,14 +996,28 @@ if ($unixtime) { } for ($i=1; $i<=($internodes[$link]); $i++) { if ( !((! $internodedisplaymid[$link]) && ($i==($internodes[$link]+1)/2) && ($internodes[$link] %2 <> 0) )) { - $gdinternode=draw_internode($i,$font,$black,$white,$internodenumdisp[$link]); - imagecopymerge($im,$gdinternode,$internodex[$link][$i]-imagesx($gdinternode)/2,$internodey[$link][$i]-imagesy($gdinternode)/2,0,0,imagesx($gdinternode),imagesy($gdinternode),$internodedisplay{$link}); + $internodetmp = draw_internode($i,$font,$black,$white,$internodenumdisp[$link]); + cairo_set_source_surface ($cr, $internodetmp, + floor ($internodex[$link][$i] - surface_width ($internodetmp) / 2), + floor ($internodey[$link][$i] - surface_height ($internodetmp) / 2)); + cairo_paint_with_alpha ($cr, $internodedisplay{$link} / 100); } } } } } + if ($ipcheck) + { + $services = array (); + foreach ($posx as $node => $i) { + if ($check[$node] == "tcp") + $services[] = array ($ip[$node], + $checkport[$node]); + } + checkservices ($services); + } + # Display all node labels foreach ($posx as $node => $i) { if ($check[$node] && $ipcheck) { @@ -988,32 +1026,30 @@ if ($unixtime) { if (ping($ip[$node])) { switch ($labeltype[$node]) : case "round" : - label_round($im,$label[$node],$posx[$node],$posy[$node],$font,$black,$green); + label_round ($cr, $label[$node], $posx[$node], $posy[$node], $font, $black, $green); break; default : - if ($label[$node]) { - $labeltmp=labelv2($im,$label[$node],$font,$black,$green); - imagecopymerge($im,$labeltmp, - $posx[$node]-imagesx($labeltmp)/2, - $posy[$node]-imagesy($labeltmp)/2, - 0,0, - imagesx($labeltmp),imagesy($labeltmp),($labeltpt[$node]>0) ? $labeltpt[$node]:100); + if ($label[$node]) { + $labeltmp = labelv2 ($cr, $label[$node], $font, $black, $green); + cairo_set_source_surface ($cr, $labeltmp, + floor ($posx[$node] - surface_width ($labeltmp) / 2), + floor ($posy[$node] - surface_height ($labeltmp) / 2)); + cairo_paint ($cr); } break; endswitch; } else { switch ($labeltype[$node]) : case "round" : - label_round($im,$label[$node],$posx[$node],$posy[$node],$font,$black,$red); + label_round ($cr, $label[$node], $posx[$node], $posy[$node], $font, $black, $red); break; default : if ($label[$node]) { - $labeltmp=labelv2($im,$label[$node],$font,$black,$red); - imagecopymerge($im,$labeltmp, - $posx[$node]-imagesx($labeltmp)/2, - $posy[$node]-imagesy($labeltmp)/2, - 0,0, - imagesx($labeltmp),imagesy($labeltmp),($labeltpt[$node]>0) ? $labeltpt[$node]:100); + $labeltmp = labelv2 ($cr, $label[$node], $font, $black, $red); + cairo_set_source_surface ($cr, $labeltmp, + floor ($posx[$node] - surface_width ($labeltmp) / 2), + floor ($posy[$node] - surface_height ($labeltmp) / 2)); + cairo_paint ($cr); } break; @@ -1025,16 +1061,15 @@ if ($unixtime) { if (checkservice($ip[$node],$checkport[$node])) { switch ($labeltype[$node]) : case "round" : - label_round($im,$label[$node],$posx[$node],$posy[$node],$font,$black,$green); + label_round($cr, $label[$node], $posx[$node], $posy[$node], $font, $black, $green); break; default : - if ($label[$node]) { - $labeltmp=labelv2($im,$label[$node],$font,$black,$green); - imagecopymerge($im,$labeltmp, - $posx[$node]-imagesx($labeltmp)/2, - $posy[$node]-imagesy($labeltmp)/2, - 0,0, - imagesx($labeltmp),imagesy($labeltmp),($labeltpt[$node]>0) ? $labeltpt[$node]:100); + if ($label[$node]) { + $labeltmp = labelv2 ($cr, $label[$node], $font, $black, $green); + cairo_set_source_surface ($cr, $labeltmp, + floor ($posx[$node] - surface_width ($labeltmp) / 2), + floor ($posy[$node] - surface_height ($labeltmp) / 2)); + cairo_paint ($cr); } break; @@ -1043,17 +1078,15 @@ if ($unixtime) { } else { switch ($labeltype[$node]) : case "round" : - label_round($im,$label[$node],$posx[$node],$posy[$node],$font,$black,$red); + label_round ($cr, $label[$node], $posx[$node], $posy[$node], $font, $black, $red); break; default : - if ($label[$node]) { - $labeltmp=labelv2($im,$label[$node],$font,$black,$red); - imagecopymerge($im,$labeltmp, - $posx[$node]-imagesx($labeltmp)/2, - $posy[$node]-imagesy($labeltmp)/2, - 0,0, - imagesx($labeltmp),imagesy($labeltmp),($labeltpt[$node]>0) ? $labeltpt[$node]:100); - + if ($label[$node]) { + $labeltmp = labelv2 ($cr, $label[$node], $font, $black, $red); + cairo_set_source_surface ($cr, $labeltmp, + floor ($posx[$node] - surface_width ($labeltmp) / 2), + floor ($posy[$node] - surface_height ($labeltmp) / 2)); + cairo_paint ($cr); } break; endswitch; @@ -1065,37 +1098,38 @@ if ($unixtime) { } else { switch ($labeltype[$node]) : case "round" : - label_round($im,$label[$node],$posx[$node],$posy[$node],$font,$black,$white); + label_round ($cr, $label[$node], $posx[$node], $posy[$node], $font, $black, $white); break; default : - label($im,$label[$node],$posx[$node],$posy[$node],$font,$black,$white); + label ($cr, $label[$node], $posx[$node], $posy[$node], $font, $black, $white); break; endswitch; } } - + # Display title of map - $gdtitle=draw_title($titlegraph,$font,$titleforeground_red,$titleforeground_green,$titleforeground_blue,$titlebackground_red,$titlebackground_green,$titlebackground_blue,$unixtime); - imagecopy($im,$gdtitle,$titlexpos,$titleypos-1,0,0,imagesx($gdtitle),imagesy($gdtitle)); + $cairotitle = draw_title ($titlegraph,$font,$titleforeground_red,$titleforeground_green,$titleforeground_blue,$titlebackground_red,$titlebackground_green,$titlebackground_blue,$unixtime); + cairo_set_source_surface ($cr, $cairotitle, $titlexpos, $titleypos - 1); + cairo_paint ($cr); # Display legend of map switch ($legendstyle) { case "line": - $gdlegend=draw_legend2("Link load",$font,$scale_low,$scale_high,$scale_red, $scale_green, $scale_blue); - break; + $cairolegend = draw_legend2("Link load",$font,$scale_low,$scale_high,$scale_red, $scale_green, $scale_blue); + break; default: - $gdlegend=draw_legend("Traffic load",$font,$scale_low,$scale_high,$scale_red, $scale_green, $scale_blue); + $cairolegend = draw_legend("Traffic load",$font,$scale_low,$scale_high,$scale_red, $scale_green, $scale_blue); break; } - imagecopy($im,$gdlegend,$keyxpos,$keyypos,0,0,imagesx($gdlegend),imagesy($gdlegend)); + cairo_set_source_surface ($cr, $cairolegend, $keyxpos, $keyypos); + cairo_paint ($cr); # write png file to disk if OUTPUTFILE directive is used if ($OUTPUTFILE) { - imagepng($im,$OUTPUTFILE); + cairo_surface_write_to_png ($surface, $OUTPUTFILE); } - if ( strlen($linkoverlibgraph) || strlen($nodeoverlibgraph) ) { if (! $HTMLFILE) { error_display("HTMLFILE directive is not correctly defined in configuration."); @@ -1117,6 +1151,9 @@ if ($unixtime) { fclose($handle); } + if (!$to_stdout) + exit; + # Generate PNG file for browser header('Content-type: image/png'); // HTTP/1.1 @@ -1124,6 +1161,7 @@ if ($unixtime) { header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0 header("Pragma: no-cache"); - imagepng($im); - imagedestroy($im); + cairo_surface_show_png ($surface); + cairo_destroy ($cr); + cairo_surface_destroy ($surface); ?>