NOTE: Because your Cacti poller process probably doesn't run as the same user as your webserver, it's possible this will fail with file permission problems even though the normal poller process runs fine. In some situations, it MAY have memory_limit problems, if your mod_php/ISAPI module uses a different php.ini to your command-line PHP.";
print "
It is recommended that you don't use this feature, unless you understand and accept the problems it may cause.
";
include_once($config["base_path"]."/include/bottom_footer.php");
break;
case 'rebuildnow2':
include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."Weathermap.class.php");
include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."poller-common.php");
include_once($config["base_path"]."/include/top_header.php");
print "
Rebuilding all maps
NOTE: Because your Cacti poller process probably doesn't run as the same user as your webserver, it's possible this will fail with file permission problems even though the normal poller process runs fine. In some situations, it MAY have memory_limit problems, if your mod_php/ISAPI module uses a different php.ini to your command-line PHP.
";
include_once($config["base_path"]."/include/bottom_footer.php");
break;
// by default, just list the map setup
default:
include_once($config["base_path"]."/include/top_header.php");
maplist();
weathermap_footer_links();
include_once($config["base_path"]."/include/bottom_footer.php");
break;
}
///////////////////////////////////////////////////////////////////////////
function weathermap_footer_links()
{
global $colors;
global $WEATHERMAP_VERSION;
print ' ';
html_start_box("
", "78%", $colors["header"], "2", "center", "");
html_end_box();
}
// Repair the sort order column (for when something is deleted or inserted, or moved between groups)
// our primary concern is to make the sort order consistent, rather than any special 'correctness'
function map_resort()
{
$list = db_fetch_assoc("select * from weathermap_maps order by group_id,sortorder;");
$i = 1;
$last_group = -1020.5;
foreach ($list as $map)
{
if($last_group != $map['group_id'])
{
$last_group = $map['group_id'];
$i=1;
}
$sql[] = "update weathermap_maps set sortorder = $i where id = ".$map['id'];
$i++;
}
if (!empty($sql)) {
for ($a = 0; $a < count($sql); $a++) {
$result = db_execute($sql[$a]);
}
}
}
// Repair the sort order column (for when something is deleted or inserted)
function weathermap_group_resort()
{
$list = db_fetch_assoc("select * from weathermap_groups order by sortorder;");
$i = 1;
foreach ($list as $group)
{
$sql[] = "update weathermap_groups set sortorder = $i where id = ".$group['id'];
$i++;
}
if (!empty($sql)) {
for ($a = 0; $a < count($sql); $a++) {
$result = db_execute($sql[$a]);
}
}
}
function map_move($mapid,$junk,$direction)
{
$source = db_fetch_assoc("select * from weathermap_maps where id=$mapid");
$oldorder = $source[0]['sortorder'];
$group = $source[0]['group_id'];
$neworder = $oldorder + $direction;
$target = db_fetch_assoc("select * from weathermap_maps where group_id=$group and sortorder = $neworder");
if(!empty($target[0]['id']))
{
$otherid = $target[0]['id'];
// move $mapid in direction $direction
$sql[] = "update weathermap_maps set sortorder = $neworder where id=$mapid";
// then find the other one with the same sortorder and move that in the opposite direction
$sql[] = "update weathermap_maps set sortorder = $oldorder where id=$otherid";
}
if (!empty($sql)) {
for ($a = 0; $a < count($sql); $a++) {
$result = db_execute($sql[$a]);
}
}
}
function weathermap_group_move($id,$junk,$direction)
{
$source = db_fetch_assoc("select * from weathermap_groups where id=$id");
$oldorder = $source[0]['sortorder'];
$neworder = $oldorder + $direction;
$target = db_fetch_assoc("select * from weathermap_groups where sortorder = $neworder");
if(!empty($target[0]['id']))
{
$otherid = $target[0]['id'];
// move $mapid in direction $direction
$sql[] = "update weathermap_groups set sortorder = $neworder where id=$id";
// then find the other one with the same sortorder and move that in the opposite direction
$sql[] = "update weathermap_groups set sortorder = $oldorder where id=$otherid";
}
if (!empty($sql)) {
for ($a = 0; $a < count($sql); $a++) {
$result = db_execute($sql[$a]);
}
}
}
function maplist()
{
global $colors, $menu;
global $i_understand_file_permissions_and_how_to_fix_them;
#print "
';
print "Last time it ran, Weathermap did NOT complete it's run. It failed during processing for '$last_started'. ";
print "This may have affected other plugins that run during the poller process.
";
print "You should either disable this map, or fault-find. Possible causes include memory_limit issues. The log may have more information.";
print '
';
}
}
html_start_box("Weathermaps", "78%", $colors["header"], "3", "center", "weathermap-cacti-plugin-mgmt.php?action=addmap_picker");
html_header(array("Config File", "Title", "Group", "Active", "Settings", "Sort Order", "Accessible By",""));
$query = db_fetch_assoc("select id,username from user_auth");
$users[0] = 'Anyone';
foreach ($query as $user)
{
$users[$user['id']] = $user['username'];
}
$i = 0;
$queryrows = db_fetch_assoc("select weathermap_maps.*, weathermap_groups.name as groupname from weathermap_maps, weathermap_groups where weathermap_maps.group_id=weathermap_groups.id order by weathermap_groups.sortorder,sortorder");
// or die (mysql_error("Could not connect to database") )
$previous_id = -2;
$had_warnings = 0;
if( is_array($queryrows) )
{
form_alternate_row_color($colors["alternate"],$colors["light"],$i);
print "
'.$had_warnings.' of your maps had warnings last time '.($had_warnings>1?"they":"it").' ran. You can try to find these in your Cacti log file or by clicking on the warning sign next to that map (you might need to increase the log line count).
($skipped files weren't shown because they are already in the database
";
}
}
else
{
print "
Can't open $weathermap_confdir to read - you should set it to be readable by the webserver.
";
}
}
else
{
print "
There is no directory named $weathermap_confdir - you will need to create it, and set it to be readable by the webserver. If you want to upload configuration files from inside Cacti, then it should be writable by the webserver too.
";
}
html_end_box();
if($skipped>0)
{
print "
Some files are not shown because they have already been added. You can show these files too, if you need to.
";
}
if($show_all)
{
print "
Some files are shown even though they have already been added. You can hide those files too, if you need to.
";
}
}
function preview_config($file)
{
global $weathermap_confdir;
global $colors;
chdir($weathermap_confdir);
$path_parts = pathinfo($file);
$file_dir = realpath($path_parts['dirname']);
if($file_dir != $weathermap_confdir)
{
// someone is trying to read arbitrary files?
// print "$file_dir != $weathermap_confdir";
print "
";
print "";
}
html_end_box();
}
function weathermap_map_settings($id)
{
global $colors, $config;
if($id==0)
{
$title = "Additional settings for ALL maps";
$nonemsg = "There are no settings for all maps yet. You can add some by clicking Add up in the top-right, or choose a single map from the management screen to add settings for that map.";
$type = "global";
$settingrows = db_fetch_assoc("select * from weathermap_settings where mapid=0 and groupid=0");
}
elseif($id<0)
{
$group_id = -intval($id);
$groupname = db_fetch_cell("select name from weathermap_groups where id=".$group_id);
$title = "Edit per-map settings for Group ". $group_id . ": " . $groupname;
$nonemsg = "There are no per-group settings for this group yet. You can add some by clicking Add up in the top-right.";
$type="group";
$settingrows = db_fetch_assoc("select * from weathermap_settings where groupid=".$group_id);
}
else
{
// print "Per-map settings for map $id";
$map = db_fetch_row("select * from weathermap_maps where id=".intval($id));
$groupname = db_fetch_cell("select name from weathermap_groups where id=".intval($map['group_id']));
$title = "Edit per-map settings for Weathermap $id: " . $map['titlecache'];
$nonemsg = "There are no per-map settings for this map yet. You can add some by clicking Add up in the top-right.";
$type = "map";
$settingrows = db_fetch_assoc("select * from weathermap_settings where mapid=".intval($id));
}
if($type == "group")
{
print "
All maps in this group are also affected by the following GLOBAL settings (group overrides global, map overrides group, but BOTH override SET commands within the map config file):
This map is also affected by the following GLOBAL and GROUP settings (group overrides global, map overrides group, but BOTH override SET commands within the map config file):
";
}
}
html_end_box();
}
function weathermap_group_create($newname)
{
$sortorder = db_fetch_cell("select max(sortorder)+1 from weathermap_groups");
$SQL = sprintf("insert into weathermap_groups (name, sortorder) values ('%s',%d)", mysql_escape_string($newname), $sortorder);
# print $SQL;
db_execute($SQL);
}
function weathermap_group_update($id, $newname)
{
$SQL = sprintf("update weathermap_groups set name='%s' where id=%d", mysql_escape_string($newname), $id);
# print $SQL;
db_execute($SQL);
}
function weathermap_group_delete($id)
{
$SQL1 = "SELECT MIN(id) from weathermap_groups where id <> ". $id;
$newid = db_fetch_cell($SQL1);
# move any maps out of this group into a still-existing one
$SQL2 = "UPDATE weathermap_maps set group_id=$newid where group_id=".$id;
# then delete the group
$SQL3 = "DELETE from weathermap_groups where id=".$id;
db_execute($SQL2);
db_execute($SQL3);
}
// vim:ts=4:sw=4:
?>
WebSVN
- weathermap
- Blame
- Rev 97
- /weathermap-cacti-plugin-mgmt.php
weathermap
Subversion Repositories:
[/] [weathermap-cacti-plugin-mgmt.php] - Blame information for rev 97