The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php";
print "
Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.
";
exit();
}
// sensible defaults
$mapdir='configs';
$cacti_base = '../../';
$cacti_url = '/';
$ignore_cacti=FALSE;
$configerror = '';
$config_loaded = @include_once 'editor-config.php';
// these are all set via the Editor Settings dialog, in the editor, now.
$use_overlay = FALSE; // set to TRUE to enable experimental overlay showing VIAs
$use_relative_overlay = FALSE; // set to TRUE to enable experimental overlay showing relative-positioning
$grid_snap_value = 0; // set non-zero to snap to a grid of that spacing
if( isset($_COOKIE['wmeditor']))
{
$parts = split(":",$_COOKIE['wmeditor']);
if( (isset($parts[0])) && (intval($parts[0]) == 1) ) { $use_overlay = TRUE; }
if( (isset($parts[1])) && (intval($parts[1]) == 1) ) { $use_relative_overlay = TRUE; }
if( (isset($parts[2])) && (intval($parts[2]) != 0) ) { $grid_snap_value = intval($parts[2]); }
}
if( isset($config) )
{
$configerror = 'OLD editor config file format. The format of this file changed in version 0.92 - please check the new editor-config.php-dist and update your editor-config.php file. [WMEDIT02]';
}
// check if the goalposts have moved
if( is_dir($cacti_base) && file_exists($cacti_base."/include/global.php") )
{
// include the cacti-config, so we know about the database
include_once($cacti_base."/include/global.php");
$config['base_url'] = $cacti_url;
$cacti_found = TRUE;
}
elseif( is_dir($cacti_base) && file_exists($cacti_base."/include/config.php") )
{
// include the cacti-config, so we know about the database
include_once($cacti_base."/include/config.php");
$config['base_url'] = $cacti_url;
$cacti_found = TRUE;
}
else
{
$cacti_found = FALSE;
}
if($cacti_found && isset($plugins))
{
# here, we know we're part of a plugin - do auth stuff
}
if(! is_writable($mapdir))
{
$configerror = "The map config directory is not writable by the web server user. You will not be able to edit any files until this is corrected. [WMEDIT01]";
}
chdir(dirname(__FILE__));
$action = '';
$mapname = '';
$selected = '';
$newaction = '';
$param = '';
$param2 = '';
$log = '';
if(!module_checks())
{
print "Required PHP extensions are not present in your mod_php/ISAPI PHP module. Please check your PHP setup to ensure you have the GD extension installed and enabled.
";
print "If you find that the weathermap tool itself is working, from the command-line or Cacti poller, then it is possible that you have two different PHP installations. The Editor uses the same PHP that webpages on your server use, but the main weathermap tool uses the command-line PHP interpreter.
";
print "
You should also run check.php to help make sure that there are no problems.
";
print "Here is a copy of the phpinfo() from your PHP web module, to help debugging this...";
phpinfo();
exit();
}
if(isset($_REQUEST['action'])) { $action = $_REQUEST['action']; }
if(isset($_REQUEST['mapname'])) { $mapname = $_REQUEST['mapname']; $mapname = str_replace('/','',$mapname); }
if(isset($_REQUEST['selected'])) { $selected = $_REQUEST['selected']; }
$weathermap_debugging=FALSE;
if($mapname == '')
{
// this is the file-picker/welcome page
show_editor_startpage();
}
else
{
// everything else in this file is inside this else
$mapfile = $mapdir.'/'.$mapname;
debug("==========================================================================================================\n");
debug("Starting Edit Run: action is $action on $mapname\n");
debug("==========================================================================================================\n");
# editor_log("\n\n-----------------------------------------------------------------------------\nNEW REQUEST:\n\n");
# editor_log(var_log($_REQUEST));
$map = new WeatherMap;
$map->context = 'editor';
$fromplug = FALSE;
if(isset($_REQUEST['plug']) && (intval($_REQUEST['plug'])==1) ) { $fromplug = TRUE; }
switch($action)
{
case 'newmap':
$map->WriteConfig($mapfile);
break;
case 'newmapcopy':
if(isset($_REQUEST['sourcemap'])) { $sourcemapname = $_REQUEST['sourcemap']; }
$sourcemap = $mapdir.'/'.$sourcemapname;
$map->ReadConfig($sourcemap);
$map->WriteConfig($mapfile);
break;
case 'font_samples':
$map->ReadConfig($mapfile);
ksort($map->fonts);
header('Content-type: image/png');
$keyfont = 2;
$keyheight = imagefontheight($keyfont)+2;
$sampleheight = 32;
// $im = imagecreate(250,imagefontheight(5)+5);
$im = imagecreate(2000,$sampleheight);
$imkey = imagecreate(2000,$keyheight);
$white = imagecolorallocate($im,255,255,255);
$black = imagecolorallocate($im,0,0,0);
$whitekey = imagecolorallocate($imkey,255,255,255);
$blackkey = imagecolorallocate($imkey,0,0,0);
$x = 3;
#for($i=1; $i< 6; $i++)
foreach ($map->fonts as $fontnumber => $font)
{
$string = "Abc123%";
$keystring = "Font $fontnumber";
list($width,$height) = $map->myimagestringsize($fontnumber,$string);
list($kwidth,$kheight) = $map->myimagestringsize($keyfont,$keystring);
if($kwidth > $width) $width = $kwidth;
$y = ($sampleheight/2) + $height/2;
$map->myimagestring($im, $fontnumber, $x, $y, $string, $black);
$map->myimagestring($imkey, $keyfont,$x,$keyheight,"Font $fontnumber",$blackkey);
$x = $x + $width + 6;
}
$im2 = imagecreate($x,$sampleheight + $keyheight);
imagecopy($im2,$im, 0,0, 0,0, $x, $sampleheight);
imagecopy($im2,$imkey, 0,$sampleheight, 0,0, $x, $keyheight);
imagedestroy($im);
imagepng($im2);
imagedestroy($im2);
exit();
break;
case 'draw':
header('Content-type: image/png');
$map->ReadConfig($mapfile);
if($selected != '')
{
if(substr($selected,0,5) == 'NODE:')
{
$nodename = substr($selected,5);
$map->nodes[$nodename]->selected=1;
}
if(substr($selected,0,5) == 'LINK:')
{
$linkname = substr($selected,5);
$map->links[$linkname]->selected=1;
}
}
$map->sizedebug = TRUE;
// $map->RandomData();
$map->DrawMap('','',250,TRUE,$use_overlay,$use_relative_overlay);
exit();
break;
case 'show_config':
header('Content-type: text/plain');
$fd = fopen($mapfile,'r');
while (!feof($fd))
{
$buffer = fgets($fd, 4096);
echo $buffer;
}
fclose($fd);
exit();
break;
case 'fetch_config':
$map->ReadConfig($mapfile);
header('Content-type: text/plain');
$item_name = $_REQUEST['item_name'];
$item_type = $_REQUEST['item_type'];
$ok=FALSE;
if($item_type == 'node'){
if (isset($map->nodes[$item_name])) {
print $map->nodes[$item_name]->WriteConfig();
$ok=TRUE;
}
}
if($item_type == 'link') {
if(isset($map->links[$item_name])) {
print $map->links[$item_name]->WriteConfig();
$ok=TRUE;
}
}
if (! $ok) {
print "# the request item didn't exist. That's probably a bug.\n";
}
exit();
break;
case "set_link_config":
$map->ReadConfig($mapfile);
$link_name = $_REQUEST['link_name'];
$link_config = fix_gpc_string($_REQUEST['item_configtext']);
$map->links[$link_name]->config_override = $link_config;
$map->WriteConfig($mapfile);
// now clear and reload the map object, because the in-memory one is out of sync
// - we don't know what changes the user made here, so we just have to reload.
unset($map);
$map = new WeatherMap;
$map->context = 'editor';
$map->ReadConfig($mapfile);
break;
case "set_node_config":
$map->ReadConfig($mapfile);
$node_name = $_REQUEST['node_name'];
$node_config = fix_gpc_string($_REQUEST['item_configtext']);
if (true == function_exists('get_magic_quotes_gpc') && 1 == get_magic_quotes_gpc()) {
$link_config = stripslashes($link_config);
}
$map->nodes[$node_name]->config_override = $node_config;
$map->WriteConfig($mapfile);
// now clear and reload the map object, because the in-memory one is out of sync
// - we don't know what changes the user made here, so we just have to reload.
unset($map);
$map = new WeatherMap;
$map->context = 'editor';
$map->ReadConfig($mapfile);
break;
case "set_node_properties":
$map->ReadConfig($mapfile);
$node_name = $_REQUEST['node_name'];
$new_node_name = $_REQUEST['node_new_name'];
if($node_name != $new_node_name)
{
if(!isset($map->nodes[$new_node_name]))
{
// we need to rename the node first.
$newnode = $map->nodes[$node_name];
$newnode->name = $new_node_name;
$map->nodes[$new_node_name] = $newnode;
unset($map->nodes[$node_name]);
// find the references elsewhere to the old node name.
// First, relatively-positioned NODEs
foreach ($map->nodes as $node)
{
if($node->relative_to == $node_name)
{
$map->nodes[$node->name]->relative_to = $new_node_name;
}
}
// Next, LINKs that use this NODE as an end.
foreach ($map->links as $link)
{
if(isset($link->a))
{
if($link->a->name == $node_name)
{
$map->links[$link->name]->a = $newnode;
}
if($link->b->name == $node_name)
{
$map->links[$link->name]->b = $newnode;
}
// while we're here, VIAs can also be relative to a NODE,
// so check if any of those need to change
if( (count($link->vialist)>0) )
{
$vv=0;
foreach($link->vialist as $v)
{
if(isset($v[2]) && $v[2] == $node_name)
{
// die PHP4, die!
$map->links[$link->name]->vialist[$vv][2] = $new_node_name;
}
$vv++;
}
}
}
}
}
else
{
// silently ignore attempts to rename a node to an existing name
$new_node_name = $node_name;
}
}
// by this point, and renaming has been done, and new_node_name will always be the right name
$map->nodes[$new_node_name]->label = $_REQUEST['node_label'];
$map->nodes[$new_node_name]->infourl[IN] = $_REQUEST['node_infourl'];
$urls = preg_split('/\s+/', $_REQUEST['node_hover'], -1, PREG_SPLIT_NO_EMPTY);
$map->nodes[$new_node_name]->overliburl[IN] = $urls;
$map->nodes[$new_node_name]->overliburl[OUT] = $urls;
$map->nodes[$new_node_name]->x = intval($_REQUEST['node_x']);
$map->nodes[$new_node_name]->y = intval($_REQUEST['node_y']);
if($_REQUEST['node_iconfilename'] == '--NONE--')
{
$map->nodes[$new_node_name]->iconfile='';
}
else
{
// AICONs mess this up, because they're not fully supported by the editor, but it can still break them
if($_REQUEST['node_iconfilename'] != '--AICON--')
$map->nodes[$new_node_name]->iconfile = stripslashes($_REQUEST['node_iconfilename']);
}
$map->WriteConfig($mapfile);
break;
case "set_link_properties":
$map->ReadConfig($mapfile);
$link_name = $_REQUEST['link_name'];
$map->links[$link_name]->width = floatval($_REQUEST['link_width']);
$map->links[$link_name]->infourl[IN] = $_REQUEST['link_infourl'];
$map->links[$link_name]->infourl[OUT] = $_REQUEST['link_infourl'];
$urls = preg_split('/\s+/', $_REQUEST['link_hover'], -1, PREG_SPLIT_NO_EMPTY);
$map->links[$link_name]->overliburl[IN] = $urls;
$map->links[$link_name]->overliburl[OUT] = $urls;
$map->links[$link_name]->comments[IN] = $_REQUEST['link_commentin'];
$map->links[$link_name]->comments[OUT] = $_REQUEST['link_commentout'];
$map->links[$link_name]->commentoffset_in = intval($_REQUEST['link_commentposin']);
$map->links[$link_name]->commentoffset_out = intval($_REQUEST['link_commentposout']);
// $map->links[$link_name]->target = $_REQUEST['link_target'];
$targets = preg_split('/\s+/',$_REQUEST['link_target'],-1,PREG_SPLIT_NO_EMPTY);
$new_target_list = array();
foreach ($targets as $target)
{
// we store the original TARGET string, and line number, along with the breakdown, to make nicer error messages later
$newtarget = array($target,'traffic_in','traffic_out',0,$target);
// if it's an RRD file, then allow for the user to specify the
// DSs to be used. The default is traffic_in, traffic_out, which is
// OK for Cacti (most of the time), but if you have other RRDs...
if(preg_match("/(.*\.rrd):([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/i",$target,$matches))
{
$newtarget[0] = $matches[1];
$newtarget[1] = $matches[2];
$newtarget[2] = $matches[3];
}
// now we've (maybe) messed with it, we'll store the array of target specs
$new_target_list[] = $newtarget;
}
$map->links[$link_name]->targets = $new_target_list;
$bwin = $_REQUEST['link_bandwidth_in'];
$bwout = $_REQUEST['link_bandwidth_out'];
if(isset($_REQUEST['link_bandwidth_out_cb']) && $_REQUEST['link_bandwidth_out_cb'] == 'symmetric')
{
$bwout = $bwin;
}
// $map->links[$link_name]->SetBandwidth($bwin,$bwout);
$map->links[$link_name]->max_bandwidth_in_cfg = $bwin;
$map->links[$link_name]->max_bandwidth_out_cfg = $bwout;
$map->links[$link_name]->max_bandwidth_in = unformat_number($bwin, $map->kilo);
$map->links[$link_name]->max_bandwidth_out = unformat_number($bwout, $map->kilo);
$map->WriteConfig($mapfile);
break;
case "set_map_properties":
$map->ReadConfig($mapfile);
$map->title = $_REQUEST['map_title'];
$map->keytext['DEFAULT'] = $_REQUEST['map_legend'];
$map->stamptext = $_REQUEST['map_stamp'];
$map->htmloutputfile = $_REQUEST['map_htmlfile'];
$map->imageoutputfile = $_REQUEST['map_pngfile'];
$map->width = intval($_REQUEST['map_width']);
$map->height = intval($_REQUEST['map_height']);
// XXX sanitise this a bit
if($_REQUEST['map_bgfile'] == '--NONE--')
{
$map->background='';
}
else
{
$map->background = stripslashes($_REQUEST['map_bgfile']);
}
$inheritables = array(
array('link','width','map_linkdefaultwidth'),
);
handle_inheritance($map, $inheritables);
$map->links['DEFAULT']->width = intval($_REQUEST['map_linkdefaultwidth']);
$map->links['DEFAULT']->add_note("my_width", intval($_REQUEST['map_linkdefaultwidth']));
$bwin = $_REQUEST['map_linkdefaultbwin'];
$bwout = $_REQUEST['map_linkdefaultbwout'];
$bwin_old = $map->links['DEFAULT']->max_bandwidth_in_cfg;
$bwout_old = $map->links['DEFAULT']->max_bandwidth_out_cfg;
if( ($bwin_old != $bwin) || ($bwout_old != $bwout) )
{
$map->links['DEFAULT']->max_bandwidth_in_cfg = $bwin;
$map->links['DEFAULT']->max_bandwidth_out_cfg = $bwout;
$map->links['DEFAULT']->max_bandwidth_in = unformat_number($bwin, $map->kilo);
$map->links['DEFAULT']->max_bandwidth_out = unformat_number($bwout, $map->kilo);
// $map->defaultlink->SetBandwidth($bwin,$bwout);
foreach ($map->links as $link)
{
if( ($link->max_bandwidth_in_cfg == $bwin_old) || ($link->max_bandwidth_out_cfg == $bwout_old) )
{
// $link->SetBandwidth($bwin,$bwout);
$link_name = $link->name;
$map->links[$link_name]->max_bandwidth_in_cfg = $bwin;
$map->links[$link_name]->max_bandwidth_out_cfg = $bwout;
$map->links[$link_name]->max_bandwidth_in = unformat_number($bwin, $map->kilo);
$map->links[$link_name]->max_bandwidth_out = unformat_number($bwout, $map->kilo);
}
}
}
$map->WriteConfig($mapfile);
break;
case 'set_map_style':
$map->ReadConfig($mapfile);
$map->htmlstyle = $_REQUEST['mapstyle_htmlstyle'];
$map->keyfont = intval($_REQUEST['mapstyle_legendfont']);
$inheritables = array(
array('link','labelstyle','mapstyle_linklabels'),
array('link','bwfont','mapstyle_linkfont'),
array('link','arrowstyle','mapstyle_arrowstyle'),
array('node','labelfont','mapstyle_nodefont')
);
handle_inheritance($map, $inheritables);
$map->WriteConfig($mapfile);
break;
case "add_link":
$map->ReadConfig($mapfile);
$param2 = $_REQUEST['param'];
# $param2 = substr($param2,0,-2);
$newaction = 'add_link2';
# print $newaction;
$selected = 'NODE:'.$param2;
break;
case "add_link2":
$map->ReadConfig($mapfile);
$a = $_REQUEST['param2'];
$b = $_REQUEST['param'];
# $b = substr($b,0,-2);
$log = "[$a -> $b]";
if($a != $b)
{
$newlink = new WeatherMapLink;
$newlink->Reset($map);
$newlink->a = $map->nodes[$a];
$newlink->b = $map->nodes[$b];
// $newlink->SetBandwidth($map->defaultlink->max_bandwidth_in_cfg, $map->defaultlink->max_bandwidth_out_cfg);
$newlink->width = $map->links['DEFAULT']->width;
// make sure the link name is unique. We can have multiple links between
// the same nodes, these days
$newlinkname = "$a-$b";
while(array_key_exists($newlinkname,$map->links))
{
$newlinkname .= "a";
}
$newlink->name = $newlinkname;
$newlink->defined_in = $map->configfile;
$map->links[$newlinkname] = $newlink;
array_push($map->seen_zlayers[$newlink->zorder], $newlink);
$map->WriteConfig($mapfile);
}
break;
case "place_legend":
$x = snap( intval($_REQUEST['x']) ,$grid_snap_value);
$y = snap( intval($_REQUEST['y']) ,$grid_snap_value);
$scalename = $_REQUEST['param'];
$map->ReadConfig($mapfile);
$map->keyx[$scalename] = $x;
$map->keyy[$scalename] = $y;
$map->WriteConfig($mapfile);
break;
case "place_stamp":
$x = snap( intval($_REQUEST['x']), $grid_snap_value);
$y = snap( intval($_REQUEST['y']), $grid_snap_value);
$map->ReadConfig($mapfile);
$map->timex = $x;
$map->timey = $y;
$map->WriteConfig($mapfile);
break;
case "via_link":
$x = intval($_REQUEST['x']);
$y = intval($_REQUEST['y']);
$link_name = $_REQUEST['link_name'];
$map->ReadConfig($mapfile);
$map->links[$link_name]->vialist = array(array(0 =>$x, 1=>$y));
$map->WriteConfig($mapfile);
break;
case "move_node":
$x = snap( intval($_REQUEST['x']), $grid_snap_value);
$y = snap( intval($_REQUEST['y']), $grid_snap_value);
$node_name = $_REQUEST['node_name'];
$map->ReadConfig($mapfile);
// This is a complicated bit. Find out if this node is involved in any
// links that have VIAs. If it is, we want to rotate those VIA points
// about the *other* node in the link
foreach ($map->links as $link)
{
if( (count($link->vialist)>0) && (($link->a->name == $node_name) || ($link->b->name == $node_name)) )
{
// get the other node from us
if($link->a->name == $node_name) $pivot = $link->b;
if($link->b->name == $node_name) $pivot = $link->a;
if( ($link->a->name == $node_name) && ($link->b->name == $node_name) )
{
// this is a wierd special case, but it is possible
# $log .= "Special case for node1->node1 links\n";
$dx = $link->a->x - $x;
$dy = $link->a->y - $y;
for($i=0; $ivialist); $i++)
{
$link->vialist[$i][0] = $link->vialist[$i][0]-$dx;
$link->vialist[$i][1] = $link->vialist[$i][1]-$dy;
}
}
else
{
$pivx = $pivot->x;
$pivy = $pivot->y;
$dx_old = $pivx - $map->nodes[$node_name]->x;
$dy_old = $pivy - $map->nodes[$node_name]->y;
$dx_new = $pivx - $x;
$dy_new = $pivy - $y;
$l_old = sqrt($dx_old*$dx_old + $dy_old*$dy_old);
$l_new = sqrt($dx_new*$dx_new + $dy_new*$dy_new);
$angle_old = rad2deg(atan2(-$dy_old,$dx_old));
$angle_new = rad2deg(atan2(-$dy_new,$dx_new));
# $log .= "$pivx,$pivy\n$dx_old $dy_old $l_old => $angle_old\n";
# $log .= "$dx_new $dy_new $l_new => $angle_new\n";
// the geometry stuff uses a different point format, helpfully
$points = array();
foreach($link->vialist as $via)
{
$points[] = $via[0];
$points[] = $via[1];
}
$scalefactor = $l_new/$l_old;
# $log .= "Scale by $scalefactor along link-line";
// rotate so that link is along the axis
RotateAboutPoint($points,$pivx, $pivy, deg2rad($angle_old));
// do the scaling in here
for($i=0; $i<(count($points)/2); $i++)
{
$basex = ($points[$i*2] - $pivx) * $scalefactor + $pivx;
$points[$i*2] = $basex;
}
// rotate back so that link is along the new direction
RotateAboutPoint($points,$pivx, $pivy, deg2rad(-$angle_new));
// now put the modified points back into the vialist again
$v = 0; $i = 0;
foreach($points as $p)
{
// skip a point if it positioned relative to a node. Those shouldn't be rotated (well, IMHO)
if(!isset($link->vialist[$v][2]))
{
$link->vialist[$v][$i]=$p;
}
$i++;
if($i==2) { $i=0; $v++;}
}
}
}
}
$map->nodes[$node_name]->x = $x;
$map->nodes[$node_name]->y = $y;
$map->WriteConfig($mapfile);
break;
case "link_align_horizontal":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "align link ".$target;
$a_y = $map->links[$target]->a->y;
$b_y = $map->links[$target]->b->y;
$diff = $b_y - $a_y;
$newoffset = "0:$diff";
// if we've already done this once, try the other way around...
if($map->links[$target]->a_offset == $newoffset)
{
$diff = $a_y - $b_y;
$newoffset = "0:$diff";
$map->links[$target]->b_offset = $newoffset;
$map->links[$target]->a_offset = "C";
}
else
{
// the standard thing
$map->links[$target]->a_offset = $newoffset;
$map->links[$target]->b_offset = "C";
}
$map->WriteConfig($mapfile);
break;
case "link_align_vertical":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "align link ".$target;
$a_x = $map->links[$target]->a->x;
$b_x = $map->links[$target]->b->x;
$diff = $b_x - $a_x;
$newoffset = "$diff:0";
// if we've already done this once, try the other way around...
if($map->links[$target]->a_offset == $newoffset)
{
$diff = $a_x - $b_x;
$newoffset = "$diff:0";
$map->links[$target]->b_offset = $newoffset;
$map->links[$target]->a_offset = "C";
}
else
{
// the standard thing
$map->links[$target]->a_offset = $newoffset;
$map->links[$target]->b_offset = "C";
}
$map->WriteConfig($mapfile);
break;
case "delete_link":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "delete link ".$target;
unset($map->links[$target]);
$map->WriteConfig($mapfile);
break;
case "add_node":
$x = snap(intval($_REQUEST['x']), $grid_snap_value);
$y = snap(intval($_REQUEST['y']), $grid_snap_value);
$map->ReadConfig($mapfile);
$newnodename = sprintf("node%05d",time()%10000);
while(array_key_exists($newnodename,$map->nodes))
{
$newnodename .= "a";
}
$node = new WeatherMapNode;
$node->name = $newnodename;
$node->template = "DEFAULT";
$node->Reset($map);
$node->x = $x;
$node->y = $y;
$node->defined_in = $map->configfile;
array_push($map->seen_zlayers[$node->zorder], $node);
// only insert a label if there's no LABEL in the DEFAULT node.
// otherwise, respect the template.
if($map->nodes['DEFAULT']->label == $map->nodes[':: DEFAULT ::']->label)
{
$node->label = "Node";
}
$map->nodes[$node->name] = $node;
$log = "added a node called $newnodename at $x,$y to $mapfile";
$map->WriteConfig($mapfile);
break;
case "editor_settings":
// have to do this, otherwise the editor will be unresponsive afterwards - not actually going to change anything!
$map->ReadConfig($mapfile);
$use_overlay = (isset($_REQUEST['editorsettings_showvias']) ? intval($_REQUEST['editorsettings_showvias']) : FALSE);
$use_relative_overlay = (isset($_REQUEST['editorsettings_showrelative']) ? intval($_REQUEST['editorsettings_showrelative']) : FALSE);
$grid_snap_value = (isset($_REQUEST['editorsettings_gridsnap']) ? intval($_REQUEST['editorsettings_gridsnap']) : 0);
break;
case "delete_node":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "delete node ".$target;
foreach ($map->links as $link)
{
if( isset($link->a) )
{
if( ($target == $link->a->name) || ($target == $link->b->name) )
{
unset($map->links[$link->name]);
}
}
}
unset($map->nodes[$target]);
$map->WriteConfig($mapfile);
break;
case "clone_node":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "clone node ".$target;
$newnodename = $target;
do
{
$newnodename = $newnodename."_copy";
} while(isset($map->nodes[$newnodename]));
$node = new WeatherMapNode;
$node->Reset($map);
$node->CopyFrom($map->nodes[$target]);
$node->name = $newnodename;
$node->x += 30;
$node->y += 30;
$node->defined_in = $mapfile;
$map->nodes[$newnodename] = $node;
array_push($map->seen_zlayers[$node->zorder], $node);
$map->WriteConfig($mapfile);
break;
// no action was defined - starting a new map?
default:
$map->ReadConfig($mapfile);
break;
}
//by here, there should be a valid $map - either a blank one, the existing one, or the existing one with requested changes
debug("Finished modifying\n");
// now we'll just draw the full editor page, with our new knowledge
$imageurl = '?mapname='.$mapname . '&action=draw';
if($selected != '')
{
$imageurl .= '&selected='.$selected;
}
$imageurl .= '&unique='.time();
// build up the editor's list of used images
if($map->background != '') $map->used_images[] = $map->background;
foreach ($map->nodes as $n)
{
if($n->iconfile != '' && ! preg_match("/^(none|nink|inpie|outpie|box|rbox|gauge|round)$/",$n->iconfile))
$map->used_images[] = $n->iconfile;
}
// get the list from the images/ folder too
$imlist = get_imagelist("images");
$fontlist = array();
setcookie("wmeditor", ($use_overlay ? "1":"0") .":". ($use_relative_overlay ? "1":"0") . ":" . intval($grid_snap_value), time()+60*60*24*30 );
?>
PHP Weathermap Editor <?php echo $WEATHERMAP_VERSION; ?>
Change File
Add Node
Add Link
Position Legend
Position Timestamp
Map Properties
Map Style
Manage Colors
Manage Images
Editor Settings
Position ---, ---
or click a Node or Link to edit it's properties
The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php";
print "
Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.
";
exit();
}
// sensible defaults
$mapdir='configs';
$cacti_base = '../../';
$cacti_url = '/';
$ignore_cacti=FALSE;
$configerror = '';
$config_loaded = @include_once 'editor-config.php';
// these are all set via the Editor Settings dialog, in the editor, now.
$use_overlay = FALSE; // set to TRUE to enable experimental overlay showing VIAs
$use_relative_overlay = FALSE; // set to TRUE to enable experimental overlay showing relative-positioning
$grid_snap_value = 0; // set non-zero to snap to a grid of that spacing
if( isset($_COOKIE['wmeditor']))
{
$parts = split(":",$_COOKIE['wmeditor']);
if( (isset($parts[0])) && (intval($parts[0]) == 1) ) { $use_overlay = TRUE; }
if( (isset($parts[1])) && (intval($parts[1]) == 1) ) { $use_relative_overlay = TRUE; }
if( (isset($parts[2])) && (intval($parts[2]) != 0) ) { $grid_snap_value = intval($parts[2]); }
}
if( isset($config) )
{
$configerror = 'OLD editor config file format. The format of this file changed in version 0.92 - please check the new editor-config.php-dist and update your editor-config.php file. [WMEDIT02]';
}
// check if the goalposts have moved
if( is_dir($cacti_base) && file_exists($cacti_base."/include/global.php") )
{
// include the cacti-config, so we know about the database
include_once($cacti_base."/include/global.php");
$config['base_url'] = $cacti_url;
$cacti_found = TRUE;
}
elseif( is_dir($cacti_base) && file_exists($cacti_base."/include/config.php") )
{
// include the cacti-config, so we know about the database
include_once($cacti_base."/include/config.php");
$config['base_url'] = $cacti_url;
$cacti_found = TRUE;
}
else
{
$cacti_found = FALSE;
}
if($cacti_found && isset($plugins))
{
# here, we know we're part of a plugin - do auth stuff
}
if(! is_writable($mapdir))
{
$configerror = "The map config directory is not writable by the web server user. You will not be able to edit any files until this is corrected. [WMEDIT01]";
}
chdir(dirname(__FILE__));
$action = '';
$mapname = '';
$selected = '';
$newaction = '';
$param = '';
$param2 = '';
$log = '';
if(!module_checks())
{
print "Required PHP extensions are not present in your mod_php/ISAPI PHP module. Please check your PHP setup to ensure you have the GD extension installed and enabled.
";
print "If you find that the weathermap tool itself is working, from the command-line or Cacti poller, then it is possible that you have two different PHP installations. The Editor uses the same PHP that webpages on your server use, but the main weathermap tool uses the command-line PHP interpreter.
";
print "
You should also run check.php to help make sure that there are no problems.
";
print "Here is a copy of the phpinfo() from your PHP web module, to help debugging this...";
phpinfo();
exit();
}
if(isset($_REQUEST['action'])) { $action = $_REQUEST['action']; }
if(isset($_REQUEST['mapname'])) { $mapname = $_REQUEST['mapname']; $mapname = str_replace('/','',$mapname); }
if(isset($_REQUEST['selected'])) { $selected = $_REQUEST['selected']; }
$weathermap_debugging=FALSE;
if($mapname == '')
{
// this is the file-picker/welcome page
show_editor_startpage();
}
else
{
// everything else in this file is inside this else
$mapfile = $mapdir.'/'.$mapname;
debug("==========================================================================================================\n");
debug("Starting Edit Run: action is $action on $mapname\n");
debug("==========================================================================================================\n");
# editor_log("\n\n-----------------------------------------------------------------------------\nNEW REQUEST:\n\n");
# editor_log(var_log($_REQUEST));
$map = new WeatherMap;
$map->context = 'editor';
$fromplug = FALSE;
if(isset($_REQUEST['plug']) && (intval($_REQUEST['plug'])==1) ) { $fromplug = TRUE; }
switch($action)
{
case 'newmap':
$map->WriteConfig($mapfile);
break;
case 'newmapcopy':
if(isset($_REQUEST['sourcemap'])) { $sourcemapname = $_REQUEST['sourcemap']; }
$sourcemap = $mapdir.'/'.$sourcemapname;
$map->ReadConfig($sourcemap);
$map->WriteConfig($mapfile);
break;
case 'font_samples':
$map->ReadConfig($mapfile);
ksort($map->fonts);
header('Content-type: image/png');
$keyfont = 2;
$keyheight = imagefontheight($keyfont)+2;
$sampleheight = 32;
// $im = imagecreate(250,imagefontheight(5)+5);
$im = imagecreate(2000,$sampleheight);
$imkey = imagecreate(2000,$keyheight);
$white = imagecolorallocate($im,255,255,255);
$black = imagecolorallocate($im,0,0,0);
$whitekey = imagecolorallocate($imkey,255,255,255);
$blackkey = imagecolorallocate($imkey,0,0,0);
$x = 3;
#for($i=1; $i< 6; $i++)
foreach ($map->fonts as $fontnumber => $font)
{
$string = "Abc123%";
$keystring = "Font $fontnumber";
list($width,$height) = $map->myimagestringsize($fontnumber,$string);
list($kwidth,$kheight) = $map->myimagestringsize($keyfont,$keystring);
if($kwidth > $width) $width = $kwidth;
$y = ($sampleheight/2) + $height/2;
$map->myimagestring($im, $fontnumber, $x, $y, $string, $black);
$map->myimagestring($imkey, $keyfont,$x,$keyheight,"Font $fontnumber",$blackkey);
$x = $x + $width + 6;
}
$im2 = imagecreate($x,$sampleheight + $keyheight);
imagecopy($im2,$im, 0,0, 0,0, $x, $sampleheight);
imagecopy($im2,$imkey, 0,$sampleheight, 0,0, $x, $keyheight);
imagedestroy($im);
imagepng($im2);
imagedestroy($im2);
exit();
break;
case 'draw':
header('Content-type: image/png');
$map->ReadConfig($mapfile);
if($selected != '')
{
if(substr($selected,0,5) == 'NODE:')
{
$nodename = substr($selected,5);
$map->nodes[$nodename]->selected=1;
}
if(substr($selected,0,5) == 'LINK:')
{
$linkname = substr($selected,5);
$map->links[$linkname]->selected=1;
}
}
$map->sizedebug = TRUE;
// $map->RandomData();
$map->DrawMap('','',250,TRUE,$use_overlay,$use_relative_overlay);
exit();
break;
case 'show_config':
header('Content-type: text/plain');
$fd = fopen($mapfile,'r');
while (!feof($fd))
{
$buffer = fgets($fd, 4096);
echo $buffer;
}
fclose($fd);
exit();
break;
case 'fetch_config':
$map->ReadConfig($mapfile);
header('Content-type: text/plain');
$item_name = $_REQUEST['item_name'];
$item_type = $_REQUEST['item_type'];
$ok=FALSE;
if($item_type == 'node'){
if (isset($map->nodes[$item_name])) {
print $map->nodes[$item_name]->WriteConfig();
$ok=TRUE;
}
}
if($item_type == 'link') {
if(isset($map->links[$item_name])) {
print $map->links[$item_name]->WriteConfig();
$ok=TRUE;
}
}
if (! $ok) {
print "# the request item didn't exist. That's probably a bug.\n";
}
exit();
break;
case "set_link_config":
$map->ReadConfig($mapfile);
$link_name = $_REQUEST['link_name'];
$link_config = fix_gpc_string($_REQUEST['item_configtext']);
$map->links[$link_name]->config_override = $link_config;
$map->WriteConfig($mapfile);
// now clear and reload the map object, because the in-memory one is out of sync
// - we don't know what changes the user made here, so we just have to reload.
unset($map);
$map = new WeatherMap;
$map->context = 'editor';
$map->ReadConfig($mapfile);
break;
case "set_node_config":
$map->ReadConfig($mapfile);
$node_name = $_REQUEST['node_name'];
$node_config = fix_gpc_string($_REQUEST['item_configtext']);
if (true == function_exists('get_magic_quotes_gpc') && 1 == get_magic_quotes_gpc()) {
$link_config = stripslashes($link_config);
}
$map->nodes[$node_name]->config_override = $node_config;
$map->WriteConfig($mapfile);
// now clear and reload the map object, because the in-memory one is out of sync
// - we don't know what changes the user made here, so we just have to reload.
unset($map);
$map = new WeatherMap;
$map->context = 'editor';
$map->ReadConfig($mapfile);
break;
case "set_node_properties":
$map->ReadConfig($mapfile);
$node_name = $_REQUEST['node_name'];
$new_node_name = $_REQUEST['node_new_name'];
if($node_name != $new_node_name)
{
if(!isset($map->nodes[$new_node_name]))
{
// we need to rename the node first.
$newnode = $map->nodes[$node_name];
$newnode->name = $new_node_name;
$map->nodes[$new_node_name] = $newnode;
unset($map->nodes[$node_name]);
// find the references elsewhere to the old node name.
// First, relatively-positioned NODEs
foreach ($map->nodes as $node)
{
if($node->relative_to == $node_name)
{
$map->nodes[$node->name]->relative_to = $new_node_name;
}
}
// Next, LINKs that use this NODE as an end.
foreach ($map->links as $link)
{
if(isset($link->a))
{
if($link->a->name == $node_name)
{
$map->links[$link->name]->a = $newnode;
}
if($link->b->name == $node_name)
{
$map->links[$link->name]->b = $newnode;
}
// while we're here, VIAs can also be relative to a NODE,
// so check if any of those need to change
if( (count($link->vialist)>0) )
{
$vv=0;
foreach($link->vialist as $v)
{
if(isset($v[2]) && $v[2] == $node_name)
{
// die PHP4, die!
$map->links[$link->name]->vialist[$vv][2] = $new_node_name;
}
$vv++;
}
}
}
}
}
else
{
// silently ignore attempts to rename a node to an existing name
$new_node_name = $node_name;
}
}
// by this point, and renaming has been done, and new_node_name will always be the right name
$map->nodes[$new_node_name]->label = $_REQUEST['node_label'];
$map->nodes[$new_node_name]->infourl[IN] = $_REQUEST['node_infourl'];
$urls = preg_split('/\s+/', $_REQUEST['node_hover'], -1, PREG_SPLIT_NO_EMPTY);
$map->nodes[$new_node_name]->overliburl[IN] = $urls;
$map->nodes[$new_node_name]->overliburl[OUT] = $urls;
$map->nodes[$new_node_name]->x = intval($_REQUEST['node_x']);
$map->nodes[$new_node_name]->y = intval($_REQUEST['node_y']);
if($_REQUEST['node_iconfilename'] == '--NONE--')
{
$map->nodes[$new_node_name]->iconfile='';
}
else
{
// AICONs mess this up, because they're not fully supported by the editor, but it can still break them
if($_REQUEST['node_iconfilename'] != '--AICON--')
$map->nodes[$new_node_name]->iconfile = stripslashes($_REQUEST['node_iconfilename']);
}
$map->WriteConfig($mapfile);
break;
case "set_link_properties":
$map->ReadConfig($mapfile);
$link_name = $_REQUEST['link_name'];
$map->links[$link_name]->width = floatval($_REQUEST['link_width']);
$map->links[$link_name]->infourl[IN] = $_REQUEST['link_infourl'];
$map->links[$link_name]->infourl[OUT] = $_REQUEST['link_infourl'];
$urls = preg_split('/\s+/', $_REQUEST['link_hover'], -1, PREG_SPLIT_NO_EMPTY);
$map->links[$link_name]->overliburl[IN] = $urls;
$map->links[$link_name]->overliburl[OUT] = $urls;
$map->links[$link_name]->comments[IN] = $_REQUEST['link_commentin'];
$map->links[$link_name]->comments[OUT] = $_REQUEST['link_commentout'];
$map->links[$link_name]->commentoffset_in = intval($_REQUEST['link_commentposin']);
$map->links[$link_name]->commentoffset_out = intval($_REQUEST['link_commentposout']);
// $map->links[$link_name]->target = $_REQUEST['link_target'];
$targets = preg_split('/\s+/',$_REQUEST['link_target'],-1,PREG_SPLIT_NO_EMPTY);
$new_target_list = array();
foreach ($targets as $target)
{
// we store the original TARGET string, and line number, along with the breakdown, to make nicer error messages later
$newtarget = array($target,'traffic_in','traffic_out',0,$target);
// if it's an RRD file, then allow for the user to specify the
// DSs to be used. The default is traffic_in, traffic_out, which is
// OK for Cacti (most of the time), but if you have other RRDs...
if(preg_match("/(.*\.rrd):([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/i",$target,$matches))
{
$newtarget[0] = $matches[1];
$newtarget[1] = $matches[2];
$newtarget[2] = $matches[3];
}
// now we've (maybe) messed with it, we'll store the array of target specs
$new_target_list[] = $newtarget;
}
$map->links[$link_name]->targets = $new_target_list;
$bwin = $_REQUEST['link_bandwidth_in'];
$bwout = $_REQUEST['link_bandwidth_out'];
if(isset($_REQUEST['link_bandwidth_out_cb']) && $_REQUEST['link_bandwidth_out_cb'] == 'symmetric')
{
$bwout = $bwin;
}
// $map->links[$link_name]->SetBandwidth($bwin,$bwout);
$map->links[$link_name]->max_bandwidth_in_cfg = $bwin;
$map->links[$link_name]->max_bandwidth_out_cfg = $bwout;
$map->links[$link_name]->max_bandwidth_in = unformat_number($bwin, $map->kilo);
$map->links[$link_name]->max_bandwidth_out = unformat_number($bwout, $map->kilo);
$map->WriteConfig($mapfile);
break;
case "set_map_properties":
$map->ReadConfig($mapfile);
$map->title = $_REQUEST['map_title'];
$map->keytext['DEFAULT'] = $_REQUEST['map_legend'];
$map->stamptext = $_REQUEST['map_stamp'];
$map->htmloutputfile = $_REQUEST['map_htmlfile'];
$map->imageoutputfile = $_REQUEST['map_pngfile'];
$map->width = intval($_REQUEST['map_width']);
$map->height = intval($_REQUEST['map_height']);
// XXX sanitise this a bit
if($_REQUEST['map_bgfile'] == '--NONE--')
{
$map->background='';
}
else
{
$map->background = stripslashes($_REQUEST['map_bgfile']);
}
$inheritables = array(
array('link','width','map_linkdefaultwidth'),
);
handle_inheritance($map, $inheritables);
$map->links['DEFAULT']->width = intval($_REQUEST['map_linkdefaultwidth']);
$map->links['DEFAULT']->add_note("my_width", intval($_REQUEST['map_linkdefaultwidth']));
$bwin = $_REQUEST['map_linkdefaultbwin'];
$bwout = $_REQUEST['map_linkdefaultbwout'];
$bwin_old = $map->links['DEFAULT']->max_bandwidth_in_cfg;
$bwout_old = $map->links['DEFAULT']->max_bandwidth_out_cfg;
if( ($bwin_old != $bwin) || ($bwout_old != $bwout) )
{
$map->links['DEFAULT']->max_bandwidth_in_cfg = $bwin;
$map->links['DEFAULT']->max_bandwidth_out_cfg = $bwout;
$map->links['DEFAULT']->max_bandwidth_in = unformat_number($bwin, $map->kilo);
$map->links['DEFAULT']->max_bandwidth_out = unformat_number($bwout, $map->kilo);
// $map->defaultlink->SetBandwidth($bwin,$bwout);
foreach ($map->links as $link)
{
if( ($link->max_bandwidth_in_cfg == $bwin_old) || ($link->max_bandwidth_out_cfg == $bwout_old) )
{
// $link->SetBandwidth($bwin,$bwout);
$link_name = $link->name;
$map->links[$link_name]->max_bandwidth_in_cfg = $bwin;
$map->links[$link_name]->max_bandwidth_out_cfg = $bwout;
$map->links[$link_name]->max_bandwidth_in = unformat_number($bwin, $map->kilo);
$map->links[$link_name]->max_bandwidth_out = unformat_number($bwout, $map->kilo);
}
}
}
$map->WriteConfig($mapfile);
break;
case 'set_map_style':
$map->ReadConfig($mapfile);
$map->htmlstyle = $_REQUEST['mapstyle_htmlstyle'];
$map->keyfont = intval($_REQUEST['mapstyle_legendfont']);
$inheritables = array(
array('link','labelstyle','mapstyle_linklabels'),
array('link','bwfont','mapstyle_linkfont'),
array('link','arrowstyle','mapstyle_arrowstyle'),
array('node','labelfont','mapstyle_nodefont')
);
handle_inheritance($map, $inheritables);
$map->WriteConfig($mapfile);
break;
case "add_link":
$map->ReadConfig($mapfile);
$param2 = $_REQUEST['param'];
# $param2 = substr($param2,0,-2);
$newaction = 'add_link2';
# print $newaction;
$selected = 'NODE:'.$param2;
break;
case "add_link2":
$map->ReadConfig($mapfile);
$a = $_REQUEST['param2'];
$b = $_REQUEST['param'];
# $b = substr($b,0,-2);
$log = "[$a -> $b]";
if($a != $b)
{
$newlink = new WeatherMapLink;
$newlink->Reset($map);
$newlink->a = $map->nodes[$a];
$newlink->b = $map->nodes[$b];
// $newlink->SetBandwidth($map->defaultlink->max_bandwidth_in_cfg, $map->defaultlink->max_bandwidth_out_cfg);
$newlink->width = $map->links['DEFAULT']->width;
// make sure the link name is unique. We can have multiple links between
// the same nodes, these days
$newlinkname = "$a-$b";
while(array_key_exists($newlinkname,$map->links))
{
$newlinkname .= "a";
}
$newlink->name = $newlinkname;
$newlink->defined_in = $map->configfile;
$map->links[$newlinkname] = $newlink;
array_push($map->seen_zlayers[$newlink->zorder], $newlink);
$map->WriteConfig($mapfile);
}
break;
case "place_legend":
$x = snap( intval($_REQUEST['x']) ,$grid_snap_value);
$y = snap( intval($_REQUEST['y']) ,$grid_snap_value);
$scalename = $_REQUEST['param'];
$map->ReadConfig($mapfile);
$map->keyx[$scalename] = $x;
$map->keyy[$scalename] = $y;
$map->WriteConfig($mapfile);
break;
case "place_stamp":
$x = snap( intval($_REQUEST['x']), $grid_snap_value);
$y = snap( intval($_REQUEST['y']), $grid_snap_value);
$map->ReadConfig($mapfile);
$map->timex = $x;
$map->timey = $y;
$map->WriteConfig($mapfile);
break;
case "via_link":
$x = intval($_REQUEST['x']);
$y = intval($_REQUEST['y']);
$link_name = $_REQUEST['link_name'];
$map->ReadConfig($mapfile);
$map->links[$link_name]->vialist = array(array(0 =>$x, 1=>$y));
$map->WriteConfig($mapfile);
break;
case "move_node":
$x = snap( intval($_REQUEST['x']), $grid_snap_value);
$y = snap( intval($_REQUEST['y']), $grid_snap_value);
$node_name = $_REQUEST['node_name'];
$map->ReadConfig($mapfile);
// This is a complicated bit. Find out if this node is involved in any
// links that have VIAs. If it is, we want to rotate those VIA points
// about the *other* node in the link
foreach ($map->links as $link)
{
if( (count($link->vialist)>0) && (($link->a->name == $node_name) || ($link->b->name == $node_name)) )
{
// get the other node from us
if($link->a->name == $node_name) $pivot = $link->b;
if($link->b->name == $node_name) $pivot = $link->a;
if( ($link->a->name == $node_name) && ($link->b->name == $node_name) )
{
// this is a wierd special case, but it is possible
# $log .= "Special case for node1->node1 links\n";
$dx = $link->a->x - $x;
$dy = $link->a->y - $y;
for($i=0; $ivialist); $i++)
{
$link->vialist[$i][0] = $link->vialist[$i][0]-$dx;
$link->vialist[$i][1] = $link->vialist[$i][1]-$dy;
}
}
else
{
$pivx = $pivot->x;
$pivy = $pivot->y;
$dx_old = $pivx - $map->nodes[$node_name]->x;
$dy_old = $pivy - $map->nodes[$node_name]->y;
$dx_new = $pivx - $x;
$dy_new = $pivy - $y;
$l_old = sqrt($dx_old*$dx_old + $dy_old*$dy_old);
$l_new = sqrt($dx_new*$dx_new + $dy_new*$dy_new);
$angle_old = rad2deg(atan2(-$dy_old,$dx_old));
$angle_new = rad2deg(atan2(-$dy_new,$dx_new));
# $log .= "$pivx,$pivy\n$dx_old $dy_old $l_old => $angle_old\n";
# $log .= "$dx_new $dy_new $l_new => $angle_new\n";
// the geometry stuff uses a different point format, helpfully
$points = array();
foreach($link->vialist as $via)
{
$points[] = $via[0];
$points[] = $via[1];
}
$scalefactor = $l_new/$l_old;
# $log .= "Scale by $scalefactor along link-line";
// rotate so that link is along the axis
RotateAboutPoint($points,$pivx, $pivy, deg2rad($angle_old));
// do the scaling in here
for($i=0; $i<(count($points)/2); $i++)
{
$basex = ($points[$i*2] - $pivx) * $scalefactor + $pivx;
$points[$i*2] = $basex;
}
// rotate back so that link is along the new direction
RotateAboutPoint($points,$pivx, $pivy, deg2rad(-$angle_new));
// now put the modified points back into the vialist again
$v = 0; $i = 0;
foreach($points as $p)
{
// skip a point if it positioned relative to a node. Those shouldn't be rotated (well, IMHO)
if(!isset($link->vialist[$v][2]))
{
$link->vialist[$v][$i]=$p;
}
$i++;
if($i==2) { $i=0; $v++;}
}
}
}
}
$map->nodes[$node_name]->x = $x;
$map->nodes[$node_name]->y = $y;
$map->WriteConfig($mapfile);
break;
case "link_align_horizontal":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "align link ".$target;
$a_y = $map->links[$target]->a->y;
$b_y = $map->links[$target]->b->y;
$diff = $b_y - $a_y;
$newoffset = "0:$diff";
// if we've already done this once, try the other way around...
if($map->links[$target]->a_offset == $newoffset)
{
$diff = $a_y - $b_y;
$newoffset = "0:$diff";
$map->links[$target]->b_offset = $newoffset;
$map->links[$target]->a_offset = "C";
}
else
{
// the standard thing
$map->links[$target]->a_offset = $newoffset;
$map->links[$target]->b_offset = "C";
}
$map->WriteConfig($mapfile);
break;
case "link_align_vertical":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "align link ".$target;
$a_x = $map->links[$target]->a->x;
$b_x = $map->links[$target]->b->x;
$diff = $b_x - $a_x;
$newoffset = "$diff:0";
// if we've already done this once, try the other way around...
if($map->links[$target]->a_offset == $newoffset)
{
$diff = $a_x - $b_x;
$newoffset = "$diff:0";
$map->links[$target]->b_offset = $newoffset;
$map->links[$target]->a_offset = "C";
}
else
{
// the standard thing
$map->links[$target]->a_offset = $newoffset;
$map->links[$target]->b_offset = "C";
}
$map->WriteConfig($mapfile);
break;
case "delete_link":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "delete link ".$target;
unset($map->links[$target]);
$map->WriteConfig($mapfile);
break;
case "add_node":
$x = snap(intval($_REQUEST['x']), $grid_snap_value);
$y = snap(intval($_REQUEST['y']), $grid_snap_value);
$map->ReadConfig($mapfile);
$newnodename = sprintf("node%05d",time()%10000);
while(array_key_exists($newnodename,$map->nodes))
{
$newnodename .= "a";
}
$node = new WeatherMapNode;
$node->name = $newnodename;
$node->template = "DEFAULT";
$node->Reset($map);
$node->x = $x;
$node->y = $y;
$node->defined_in = $map->configfile;
array_push($map->seen_zlayers[$node->zorder], $node);
// only insert a label if there's no LABEL in the DEFAULT node.
// otherwise, respect the template.
if($map->nodes['DEFAULT']->label == $map->nodes[':: DEFAULT ::']->label)
{
$node->label = "Node";
}
$map->nodes[$node->name] = $node;
$log = "added a node called $newnodename at $x,$y to $mapfile";
$map->WriteConfig($mapfile);
break;
case "editor_settings":
// have to do this, otherwise the editor will be unresponsive afterwards - not actually going to change anything!
$map->ReadConfig($mapfile);
$use_overlay = (isset($_REQUEST['editorsettings_showvias']) ? intval($_REQUEST['editorsettings_showvias']) : FALSE);
$use_relative_overlay = (isset($_REQUEST['editorsettings_showrelative']) ? intval($_REQUEST['editorsettings_showrelative']) : FALSE);
$grid_snap_value = (isset($_REQUEST['editorsettings_gridsnap']) ? intval($_REQUEST['editorsettings_gridsnap']) : 0);
break;
case "delete_node":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "delete node ".$target;
foreach ($map->links as $link)
{
if( isset($link->a) )
{
if( ($target == $link->a->name) || ($target == $link->b->name) )
{
unset($map->links[$link->name]);
}
}
}
unset($map->nodes[$target]);
$map->WriteConfig($mapfile);
break;
case "clone_node":
$map->ReadConfig($mapfile);
$target = $_REQUEST['param'];
$log = "clone node ".$target;
$newnodename = $target;
do
{
$newnodename = $newnodename."_copy";
} while(isset($map->nodes[$newnodename]));
$node = new WeatherMapNode;
$node->Reset($map);
$node->CopyFrom($map->nodes[$target]);
$node->name = $newnodename;
$node->x += 30;
$node->y += 30;
$node->defined_in = $mapfile;
$map->nodes[$newnodename] = $node;
array_push($map->seen_zlayers[$node->zorder], $node);
$map->WriteConfig($mapfile);
break;
// no action was defined - starting a new map?
default:
$map->ReadConfig($mapfile);
break;
}
//by here, there should be a valid $map - either a blank one, the existing one, or the existing one with requested changes
debug("Finished modifying\n");
// now we'll just draw the full editor page, with our new knowledge
$imageurl = '?mapname='.$mapname . '&action=draw';
if($selected != '')
{
$imageurl .= '&selected='.$selected;
}
$imageurl .= '&unique='.time();
// build up the editor's list of used images
if($map->background != '') $map->used_images[] = $map->background;
foreach ($map->nodes as $n)
{
if($n->iconfile != '' && ! preg_match("/^(none|nink|inpie|outpie|box|rbox|gauge|round)$/",$n->iconfile))
$map->used_images[] = $n->iconfile;
}
// get the list from the images/ folder too
$imlist = get_imagelist("images");
$fontlist = array();
setcookie("wmeditor", ($use_overlay ? "1":"0") .":". ($use_relative_overlay ? "1":"0") . ":" . intval($grid_snap_value), time()+60*60*24*30 );
?>
PHP Weathermap Editor <?php echo $WEATHERMAP_VERSION; ?>