Rebuilding all mapsNOTE: 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.
";
	weathermap_run_maps(dirname(__FILE__));
	print "
"; print "

Done.

"; 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(); include_once($config["base_path"]."/include/bottom_footer.php"); break; } /////////////////////////////////////////////////////////////////////////// // Repair the sort order column (for when something is deleted or inserted) function map_resort() { $list = db_fetch_assoc("select * from weathermap_maps order by sortorder;"); $i = 1; foreach ($list as $map) { $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]); } } } function map_move($mapid,$junk,$direction) { $source = db_fetch_assoc("select * from weathermap_maps where id=$mapid"); $oldorder = $source[0]['sortorder']; $neworder = $oldorder + $direction; $target = db_fetch_assoc("select * from weathermap_maps where 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 maplist() { global $colors; html_start_box("Weathermaps", "78%", $colors["header"], "3", "center", "weathermap-cacti-plugin-mgmt.php?action=addmap_picker"); html_header(array("Config File", "Title", "Active", "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 * from weathermap_maps order by sortorder"); // or die (mysql_error("Could not connect to database") ) $previous_id = -2; if( is_array($queryrows) ) { foreach ($queryrows as $map) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); print ''.htmlspecialchars($map['configfile']).''; print ''.htmlspecialchars($map['titlecache']).''; if($map['active'] == 'on') { print 'Yes'; } else { print 'No'; } print ''; print 'Move Map Up'; print 'Move Map Down'; // print $map['sortorder']; print ""; print ''; $UserSQL = 'select * from weathermap_auth where mapid='.$map['id'].' order by userid'; $userlist = db_fetch_assoc($UserSQL); $mapusers = array(); foreach ($userlist as $user) { if(array_key_exists($user['userid'],$users)) { $mapusers[] = $users[$user['userid']]; } } print ''; if(count($mapusers) == 0) { print "(no users)"; } else { print join(", ",$mapusers); } print ''; print ''; // print 'Edit Map'; print ''; print 'Delete Map'; print ''; print ''; $i++; } } if($i==0) { print "No Weathermaps Configured\n"; } html_end_box(); if($i>0) { print '
Rebuild All Maps Right Now
(Experimental)
'; } } function addmap_picker() { global $weathermap_confdir; global $colors; $loaded=array(); // find out what maps are already in the database, so we can skip those $queryrows = db_fetch_assoc("select * from weathermap_maps"); if( is_array($queryrows) ) { foreach ($queryrows as $map) { $loaded[]=$map['configfile']; } } html_start_box("Available Weathermap Configuration Files", "78%", $colors["header"], "2", "center", ""); if( is_dir($weathermap_confdir)) { $n=0; $dh = opendir($weathermap_confdir); if($dh) { $i = 0; $skipped = 0; html_header(array("Config File", "Title",""),2); while($file = readdir($dh)) { $realfile = $weathermap_confdir.'/'.$file; if(is_file($realfile) && ! in_array($file,$loaded) ) { if(in_array($file,$loaded)) { $skipped++; } else { $title = wmap_get_title($realfile); $titles[$file] = $title; $i++; } } } closedir($dh); if($i>0) { ksort($titles); $i=0; foreach ($titles as $file=>$title) { $title = $titles[$file]; form_alternate_row_color($colors["alternate"],$colors["light"],$i); print ''.htmlspecialchars($file).''; print ''.htmlspecialchars($title).''; print 'View'; print 'Add'; print ''; $i++; } } if( ($i + $skipped) == 0 ) { print "No files were found in the configs directory."; } if( ($i == 0) && $skipped>0) { print "($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(); } 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 "

Path mismatch

"; } else { html_start_box("Preview of $file", "98%", $colors["header"], "3", "center", ""); print ''; print '
';
		$realfile = $weathermap_confdir.'/'.$file;
		if( is_file($realfile) )
		{
			$fd = fopen($realfile,"r");
			while (!feof($fd))
			{
				$buffer = fgets($fd,4096);
				print $buffer;
			}
			fclose($fd);
		}
		print '
'; print ''; html_end_box(); } } function add_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 "

Path mismatch

"; } else { $realfile = $weathermap_confdir.DIRECTORY_SEPARATOR.$file; $title = wmap_get_title($realfile); $file = mysql_real_escape_string($file); $title = mysql_real_escape_string($title); $SQL = "insert into weathermap_maps (configfile,titlecache,active,imagefile,htmlfile) VALUES ('$file','$title','on','','')"; db_execute($SQL); // add auth for 'admin' $last_id = mysql_insert_id(); $myuid = (int)$_SESSION["sess_user_id"]; $SQL = "insert into weathermap_auth (mapid,userid) VALUES ($last_id,$myuid)"; db_execute($SQL); map_resort(); } } function wmap_get_title($filename) { $title = "(no title)"; $fd = fopen($filename,"r"); while (!feof($fd)) { $buffer = fgets($fd,4096); if(preg_match("/^\s*TITLE\s+(.*)/i",$buffer, $matches)) { $title = $matches[1]; } // this regexp is tweaked from the ReadConfig version, to only match TITLEPOS lines *with* a title appended if(preg_match("/^\s*TITLEPOS\s+\d+\s+\d+\s+(.+)/i",$buffer, $matches)) { $title = $matches[1]; } } fclose($fd); return($title); } function map_deactivate($id) { $SQL = "update weathermap_maps set active='off' where id=".$id; db_execute($SQL); } function map_activate($id) { $SQL = "update weathermap_maps set active='on' where id=".$id; db_execute($SQL); } function map_delete($id) { $SQL = "delete from weathermap_maps where id=".$id; db_execute($SQL); $SQL = "delete from weathermap_auth where mapid=".$id; db_execute($SQL); map_resort(); } function perms_add_user($mapid,$userid) { $SQL = "insert into weathermap_auth (mapid,userid) values($mapid,$userid)"; db_execute($SQL); } function perms_delete_user($mapid,$userid) { $SQL = "delete from weathermap_auth where mapid=$mapid and userid=$userid"; db_execute($SQL); } function perms_list($id) { global $colors; $title_sql = "select titlecache from weathermap_maps where id=$id"; $results = db_fetch_assoc($title_sql); $title = $results[0]['titlecache']; $auth_sql = "select * from weathermap_auth where mapid=$id order by userid"; $query = db_fetch_assoc("select id,username from user_auth order by username"); $users[0] = 'Anyone'; foreach ($query as $user) { $users[$user['id']] = $user['username']; } $auth_results = db_fetch_assoc($auth_sql); $mapusers = array(); $mapuserids = array(); foreach ($auth_results as $user) { if(isset($users[$user['userid']])) { $mapusers[] = $users[$user['userid']]; $mapuserids[] = $user['userid']; } } $userselect=""; foreach ($users as $uid => $name) { if(! in_array($uid,$mapuserids)) $userselect .= "\n"; } html_start_box("Edit permissions for Weathermap $id: $title", "70%", $colors["header"], "2", "center", ""); html_header(array("Username", "")); $n = 0; foreach($mapuserids as $user) { form_alternate_row_color($colors["alternate"],$colors["light"],$n); print "".$users[$user].""; print 'Remove permissions for this user to see this map'; print ""; $n++; } if($n==0) { print "nobody can see this map"; } html_end_box(); html_start_box("", "70%", $colors["header"], "3", "center", ""); print ""; if($userselect == '') { print "There aren't any users left to add!"; } else { print "
Allow to see this map
"; print ""; } html_end_box(); } // vim:ts=4:sw=4: ?> WebSVN - weathermap - Blame - Rev 3 - /weathermap-cacti-plugin-mgmt.php
  jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [weathermap-cacti-plugin-mgmt.php] - Blame information for rev 3

 

Line No. Rev Author Line

Powered by WebSVN 2.2.1