Ejemplo n.º 1
0
function weathermap_memory_check($note = "MEM")
{
    if (function_exists("memory_get_usage")) {
        $mem_used = nice_bandwidth(memory_get_usage());
        $mem_allowed = ini_get("memory_limit");
        debug("{$note}: memory_get_usage() says " . $mem_used . "Bytes used. Limit is " . $mem_allowed . "\n");
    }
}
Ejemplo n.º 2
0
function WriteConfig($filename)
{
	global $WEATHERMAP_VERSION;

	$fd=fopen($filename, "w");
	$output="";

	if ($fd)
	{
		$output.="# Automatically generated by php-weathermap v$WEATHERMAP_VERSION\n\n";

		if (count($this->fonts) > 0)
		{
			foreach ($this->fonts as $fontnumber => $font)
			{
				if ($font->type == 'truetype')
					$output.=sprintf("FONTDEFINE %d %s %d\n", $fontnumber, $font->file, $font->size);

				if ($font->type == 'gd')
					$output.=sprintf("FONTDEFINE %d %s\n", $fontnumber, $font->file);
			}

			$output.="\n";
		}

		$basic_params = array(
				array('background','BACKGROUND',CONFIG_TYPE_LITERAL),
				array('width','WIDTH',CONFIG_TYPE_LITERAL),
				array('height','HEIGHT',CONFIG_TYPE_LITERAL),
				array('htmlstyle','HTMLSTYLE',CONFIG_TYPE_LITERAL),
				array('kilo','KILO',CONFIG_TYPE_LITERAL),
				array('keyfont','KEYFONT',CONFIG_TYPE_LITERAL),
				array('timefont','TIMEFONT',CONFIG_TYPE_LITERAL),
				array('titlefont','TITLEFONT',CONFIG_TYPE_LITERAL),
				array('title','TITLE',CONFIG_TYPE_LITERAL),
				array('htmloutputfile','HTMLOUTPUTFILE',CONFIG_TYPE_LITERAL),
				array('htmlstylesheet','HTMLSTYLESHEET',CONFIG_TYPE_LITERAL),
				array('imageuri','IMAGEURI',CONFIG_TYPE_LITERAL),
				array('imageoutputfile','IMAGEOUTPUTFILE',CONFIG_TYPE_LITERAL)
			);

		foreach ($basic_params as $param)
		{
			$field = $param[0];
			$keyword = $param[1];

			if ($this->$field != $this->inherit_fieldlist[$field])
			{
				if($param[2] == CONFIG_TYPE_COLOR) $output.="$keyword " . render_colour($this->$field) . "\n";
				if($param[2] == CONFIG_TYPE_LITERAL) $output.="$keyword " . $this->$field . "\n";
			}
		}

		if (($this->timex != $this->inherit_fieldlist['timex'])
			|| ($this->timey != $this->inherit_fieldlist['timey'])
			|| ($this->stamptext != $this->inherit_fieldlist['stamptext']))
				$output.="TIMEPOS " . $this->timex . " " . $this->timey . " " . $this->stamptext . "\n";

		if (($this->mintimex != $this->inherit_fieldlist['mintimex'])
			|| ($this->mintimey != $this->inherit_fieldlist['mintimey'])
			|| ($this->minstamptext != $this->inherit_fieldlist['minstamptext']))
				$output.="MINTIMEPOS " . $this->mintimex . " " . $this->mintimey . " " . $this->minstamptext . "\n";
		
		if (($this->maxtimex != $this->inherit_fieldlist['maxtimex'])
			|| ($this->maxtimey != $this->inherit_fieldlist['maxtimey'])
			|| ($this->maxstamptext != $this->inherit_fieldlist['maxstamptext']))
				$output.="MAXTIMEPOS " . $this->maxtimex . " " . $this->maxtimey . " " . $this->maxstamptext . "\n";
						
		if (($this->titlex != $this->inherit_fieldlist['titlex'])
			|| ($this->titley != $this->inherit_fieldlist['titley']))
				$output.="TITLEPOS " . $this->titlex . " " . $this->titley . "\n";

		$output.="\n";

		foreach ($this->colours as $scalename=>$colours)
		{
		  // not all keys will have keypos but if they do, then all three vars should be defined
		if ( (isset($this->keyx[$scalename])) && (isset($this->keyy[$scalename])) && (isset($this->keytext[$scalename]))
		    && (($this->keytext[$scalename] != $this->inherit_fieldlist['keytext'])
			|| ($this->keyx[$scalename] != $this->inherit_fieldlist['keyx'])
			|| ($this->keyy[$scalename] != $this->inherit_fieldlist['keyy'])))
			{
			     // sometimes a scale exists but without defaults. A proper scale object would sort this out...
			     if($this->keyx[$scalename] == '') { $this->keyx[$scalename] = -1; }
			     if($this->keyy[$scalename] == '') { $this->keyy[$scalename] = -1; }

				$output.="KEYPOS " . $scalename." ". $this->keyx[$scalename] . " " . $this->keyy[$scalename] . " " . $this->keytext[$scalename] . "\n";
            }

		if ( (isset($this->keystyle[$scalename])) &&  ($this->keystyle[$scalename] != $this->inherit_fieldlist['keystyle']['DEFAULT']) )
		{
			$extra='';
			if ( (isset($this->keysize[$scalename])) &&  ($this->keysize[$scalename] != $this->inherit_fieldlist['keysize']['DEFAULT']) )
			{
				$extra = " ".$this->keysize[$scalename];
			}
			$output.="KEYSTYLE  " . $scalename." ". $this->keystyle[$scalename] . $extra . "\n";
		}
		$locale = localeconv();
		$decimal_point = $locale['decimal_point'];

			foreach ($colours as $k => $colour)
			{
				if (!isset($colour['special']) || ! $colour['special'] )
				{
					$top = rtrim(rtrim(sprintf("%f",$colour['top']),"0"),$decimal_point);
					$bottom= rtrim(rtrim(sprintf("%f",$colour['bottom']),"0"),$decimal_point);

                                        if ($bottom > 1000) {
                                            $bottom = nice_bandwidth($colour['bottom'], $this->kilo);
                                        }

                                        if ($top > 1000) {
                                            $top = nice_bandwidth($colour['top'], $this->kilo);
                                        }

					$tag = (isset($colour['tag'])? $colour['tag']:'');

					if( ($colour['red1'] == -1) && ($colour['green1'] == -1) && ($colour['blue1'] == -1))
					{
						$output.=sprintf("SCALE %s %-4s %-4s   none   %s\n", $scalename,
							$bottom, $top, $tag);
					}
					elseif (!isset($colour['red2']))
					{
						$output.=sprintf("SCALE %s %-4s %-4s %3d %3d %3d  %s\n", $scalename,
							$bottom, $top,
							$colour['red1'],            $colour['green1'], $colour['blue1'],$tag);
					}
					else
					{
						$output.=sprintf("SCALE %s %-4s %-4s %3d %3d %3d   %3d %3d %3d    %s\n", $scalename,
							$bottom, $top,
							$colour['red1'],
							$colour['green1'],                     $colour['blue1'],
							$colour['red2'],                       $colour['green2'],
							$colour['blue2'], $tag);
					}
				}
				else { $output.=sprintf("%sCOLOR %d %d %d\n", $k, $colour['red1'], $colour['green1'],
					$colour['blue1']); }
			}
			$output .= "\n";
		}

		foreach ($this->hints as $hintname=>$hint)
		{
			$output .= "SET $hintname $hint\n";
		}
		
		// this doesn't really work right, but let's try anyway
		if($this->has_includes)
		{
			$output .= "\n# Included files\n";
			foreach ($this->included_files as $ifile)
			{
				$output .= "INCLUDE $ifile\n";
			}
		}

		$output.="\n# End of global section\n\n";

		fwrite($fd, $output);

		## fwrite($fd,$this->nodes['DEFAULT']->WriteConfig());
		## fwrite($fd,$this->links['DEFAULT']->WriteConfig());

		# fwrite($fd, "\n\n# Node definitions:\n");

		foreach (array("template","normal") as $which)
		{
			if($which == "template") fwrite($fd,"\n# TEMPLATE-only NODEs:\n");
			if($which == "normal") fwrite($fd,"\n# regular NODEs:\n");
			
			foreach ($this->nodes as $node)
			{
				if(!preg_match("/^::\s/",$node->name))
				{
					if($node->defined_in == $this->configfile)
					{

						if($which=="template" && $node->x === NULL)  { wm_debug("TEMPLATE\n"); fwrite($fd,$node->WriteConfig()); }
						if($which=="normal" && $node->x !== NULL) { fwrite($fd,$node->WriteConfig()); }
					}
				}
			}
			
			if($which == "template") fwrite($fd,"\n# TEMPLATE-only LINKs:\n");
			if($which == "normal") fwrite($fd,"\n# regular LINKs:\n");
			
			foreach ($this->links as $link)
			{
				if(!preg_match("/^::\s/",$link->name))
				{
					if($link->defined_in == $this->configfile)
					{
						if($which=="template" && $link->a === NULL) fwrite($fd,$link->WriteConfig());
						if($which=="normal" && $link->a !== NULL) fwrite($fd,$link->WriteConfig());
					}
				}
			}
		}		

		fwrite($fd, "\n\n# That's All Folks!\n");

		fclose($fd);
	}
	else
	{
		wm_warn ("Couldn't open config file $filename for writing");
		return (FALSE);
	}

	return (TRUE);
}
Ejemplo n.º 3
0
                            $map->links[$name]->overliburl[IN][] = $overlib;
                            $map->links[$name]->overliburl[OUT][] = $overlib;
                            $map->links[$name]->infourl[IN] = $infourl;
                            $map->links[$name]->infourl[OUT] = $infourl;
                        } else {
                            print " Couldn't find a graph that uses this rrd??\n";
                        }
                    } else {
                        print "  Failed to find RRD file for {$tgt_host}/{$interface}\n";
                    }
                }
                print "    SPEED {$total_speed}\n";
                $map->links[$name]->max_bandwidth_in = $total_speed;
                $map->links[$name]->max_bandwidth_out = $total_speed;
                $map->links[$name]->max_bandwidth_in_cfg = nice_bandwidth($total_speed);
                $map->links[$name]->max_bandwidth_out_cfg = nice_bandwidth($total_speed);
                if ($map_widths) {
                    foreach ($width_map as $map_speed => $map_width) {
                        if ($total_speed <= $map_speed) {
                            $map->links[$name]->width = $width_map[$map_speed];
                            print "    WIDTH " . $width_map[$map_speed] . "\n";
                            continue 2;
                        }
                    }
                }
            }
        } else {
            print "Skipping link with targets\n";
        }
    }
}