'weathermap', 'version' => '0.97a', 'longname' => 'PHP Network Weathermap', 'author' => 'Howard Jones', 'homepage' => 'http://www.network-weathermap.com/', 'webpage' => 'http://www.network-weathermap.com/', 'email' => 'howie@thingy.com', 'url' => 'http://www.network-weathermap.com/versions.php' ); } function disabled_plugin_weathermap_uninstall() { // doesn't really do anything. Here to remind me. // not sure what it should really do. } function disabled_plugin_weathermap_check_config() { // doesn't really do anything either because it's not implemented yet in PIA. Would be handy if it was. if(!function_exists("imagecreate")) return FALSE; if(!function_exists("preg_match")) return FALSE; if(!function_exists("imagecreatetruecolor")) return FALSE; if(!function_exists("imagecreatefrompng")) return FALSE; if(!function_exists("imagepng")) return FALSE; if(!function_exists("imageSaveAlpha")) return FALSE; if(!function_exists("imagealphablending")) return FALSE; // if(!function_exists("imagecopyresampled")) return FALSE; return TRUE; } function disabled_plugin_weathermap_install () { api_plugin_register_hook('weathermap', 'config_arrays', 'weathermap_config_arrays', 'setup.php'); api_plugin_register_hook('weathermap', 'draw_navigation_text', 'weathermap_draw_navigation_text', 'setup.php'); api_plugin_register_hook('weathermap', 'config_settings', 'weathermap_config_settings', 'setup.php'); api_plugin_register_hook('weathermap', 'top_header_tabs', 'weathermap_show_tab', 'setup.php'); api_plugin_register_hook('weathermap', 'top_graph_header_tabs', 'weathermap_show_tab', 'setup.php'); api_plugin_register_hook('weathermap', 'poller_bottom', 'weathermap_poller_bottom', 'setup.php'); api_plugin_register_hook('weathermap', 'poller_top', 'weathermap_poller_top', 'setup.php'); api_plugin_register_hook('weathermap', 'poller_output', 'weathermap_poller_output', 'setup.php'); api_plugin_register_hook('weathermap', 'top_graph_refresh', 'weathermap_top_graph_refresh', 'setup.php'); api_plugin_register_hook('weathermap', 'page_title', 'weathermap_page_title', 'setup.php'); api_plugin_register_hook('weathermap', 'page_head', 'weathermap_page_head', 'setup.php'); weathermap_setup_table (); } function plugin_init_weathermap() { global $plugin_hooks; $plugin_hooks['top_header_tabs']['weathermap'] = 'weathermap_show_tab'; $plugin_hooks['top_graph_header_tabs']['weathermap'] = 'weathermap_show_tab'; $plugin_hooks['config_arrays']['weathermap'] = 'weathermap_config_arrays'; $plugin_hooks['draw_navigation_text']['weathermap'] = 'weathermap_draw_navigation_text'; $plugin_hooks['config_settings']['weathermap'] = 'weathermap_config_settings'; $plugin_hooks['poller_bottom']['weathermap'] = 'weathermap_poller_bottom'; $plugin_hooks['poller_top']['weathermap'] = 'weathermap_poller_top'; $plugin_hooks['poller_output']['weathermap'] = 'weathermap_poller_output'; $plugin_hooks['top_graph_refresh']['weathermap'] = 'weathermap_top_graph_refresh'; $plugin_hooks['page_title']['weathermap'] = 'weathermap_page_title'; $plugin_hooks['page_head']['weathermap'] = 'weathermap_page_head'; } // figure out if this poller run is hitting the 'cron' entry for any maps. function weathermap_poller_top() { global $weathermap_poller_start_time; $n = time(); // round to the nearest minute, since that's all we need for the crontab-style stuff $weathermap_poller_start_time = $n - ($n%60); } function weathermap_page_head() { global $config; // Add in a Media RSS link on the thumbnail view // - format isn't quite right, so it's disabled for now. // if(preg_match('/plugins\/weathermap\/weathermap\-cacti\-plugin\.php/',$_SERVER['REQUEST_URI'] ,$matches)) // { // print ''; // } if(preg_match('/plugins\/weathermap\//',$_SERVER['REQUEST_URI'] ,$matches)) { print ''; } } function weathermap_page_title( $t ) { if(preg_match('/plugins\/weathermap\//',$_SERVER['REQUEST_URI'] ,$matches)) { $t .= " - Weathermap"; if(preg_match('/plugins\/weathermap\/weathermap-cacti-plugin.php\?action=viewmap&id=([^&]+)/',$_SERVER['REQUEST_URI'],$matches)) { $mapid = $matches[1]; if(preg_match("/^\d+$/",$mapid)) { $title = db_fetch_cell("SELECT titlecache from weathermap_maps where ID=".intval($mapid)); } else { $title = db_fetch_cell("SELECT titlecache from weathermap_maps where filehash='".mysql_real_escape_string($mapid)."'"); } if(isset($title)) $t .= " - $title"; } } return($t); } function weathermap_top_graph_refresh($refresh) { if (basename($_SERVER["PHP_SELF"]) != "weathermap-cacti-plugin.php") return $refresh; // if we're cycling maps, then we want to handle reloads ourselves, thanks if(isset($_REQUEST["action"]) && $_REQUEST["action"] == 'viewmapcycle') { return(86400); } return ($refresh); } function weathermap_config_settings () { global $tabs, $settings; $tabs["misc"] = "Misc"; $temp = array( "weathermap_header" => array( "friendly_name" => "Network Weathermap", "method" => "spacer", ), "weathermap_pagestyle" => array( "friendly_name" => "Page style", "description" => "How to display multiple maps.", "method" => "drop_array", "array" => array(0 => "Thumbnail Overview", 1 => "Full Images", 2 => "Show Only First") ), "weathermap_thumbsize" => array( "friendly_name" => "Thumbnail Maximum Size", "description" => "The maximum width or height for thumbnails in thumbnail view, in pixels. Takes effect after the next poller run.", "method" => "textbox", "max_length" => 5, ), "weathermap_cycle_refresh" => array( "friendly_name" => "Refresh Time", "description" => "How often to refresh the page in Cycle mode. Automatic makes all available maps fit into 5 minutes.", "method" => "drop_array", "array" => array(0 => "Automatic", 5 => "5 Seconds", 15 => '15 Seconds', 30 => '30 Seconds', 60 => '1 Minute', 120 => '2 Minutes', 300 => '5 Minutes', ) ), "weathermap_output_format" => array( "friendly_name" => "Output Format", "description" => "What format do you prefer for the generated map images and thumbnails?", "method" => "drop_array", "array" => array('png' => "PNG (default)", 'jpg' => "JPEG", 'gif' => 'GIF' ) ), "weathermap_render_period" => array( "friendly_name" => "Map Rendering Interval", "description" => "How often do you want Weathermap to recalculate it's maps? You should not touch this unless you know what you are doing! It is mainly needed for people with non-standard polling setups.", "method" => "drop_array", "array" => array(-1 => "Never (manual updates)", 0 => "Every Poller Cycle (default)", 2 => 'Every 2 Poller Cycles', 3 => 'Every 3 Poller Cycles', 4 => 'Every 4 Poller Cycles', 5 => 'Every 5 Poller Cycles', 10 => 'Every 10 Poller Cycles', 12 => 'Every 12 Poller Cycles', 24 => 'Every 24 Poller Cycles', 36 => 'Every 36 Poller Cycles', 48 => 'Every 48 Poller Cycles', 72 => 'Every 72 Poller Cycles', 288 => 'Every 288 Poller Cycles', ), ), "weathermap_all_tab" => array( "friendly_name" => "Show 'All' Tab", "description" => "When using groups, add an 'All Maps' tab to the tab bar.", "method" => "drop_array", "array" => array(0=>"No (default)",1=>"Yes") ), "weathermap_map_selector" => array( "friendly_name" => "Show Map Selector", "description" => "Show a combo-box map selector on the full-screen map view.", "method" => "drop_array", "array" => array(0=>"No",1=>"Yes (default)") ), "weathermap_quiet_logging" => array( "friendly_name" => "Quiet Logging", "description" => "By default, even in LOW level logging, Weathermap logs normal activity. This makes it REALLY log only errors in LOW mode.", "method" => "drop_array", "array" => array(0=>"Chatty (default)",1=>"Quiet") ) ); if (isset($settings["misc"])) $settings["misc"] = array_merge($settings["misc"], $temp); else $settings["misc"]=$temp; } function weathermap_setup_table () { global $config, $database_default; global $WEATHERMAP_VERSION; include_once($config["library_path"] . DIRECTORY_SEPARATOR . "database.php"); $dbversion = read_config_option("weathermap_db_version"); $myversioninfo = weathermap_version(); $myversion = $myversioninfo['version']; // only bother with all this if it's a new install, a new version, or we're in a development version // - saves a handful of db hits per request! if( ($dbversion=="") || (preg_match("/dev$/",$myversion)) || ($dbversion != $myversion) ) { # cacti_log("Doing setup_table() \n",true,"WEATHERMAP"); $sql = "show tables"; $result = db_fetch_assoc($sql) or die (mysql_error()); $tables = array(); $sql = array(); foreach($result as $index => $arr) { foreach ($arr as $t) { $tables[] = $t; } } $sql[] = "update weathermap_maps set sortorder=id where sortorder is null;"; if (!in_array('weathermap_maps', $tables)) { $sql[] = "CREATE TABLE weathermap_maps ( id int(11) NOT NULL auto_increment, sortorder int(11) NOT NULL default 0, group_id int(11) NOT NULL default 1, active set('on','off') NOT NULL default 'on', configfile text NOT NULL, imagefile text NOT NULL, htmlfile text NOT NULL, titlecache text NOT NULL, filehash varchar (40) NOT NULL default '', warncount int(11) NOT NULL default 0, config text NOT NULL default '', thumb_width int(11) NOT NULL default 0, thumb_height int(11) NOT NULL default 0, schedule varchar(32) NOT NULL default '*', archiving set('on','off') NOT NULL default 'off', PRIMARY KEY (id) ) TYPE=MyISAM;"; } else { $colsql = "show columns from weathermap_maps from " . $database_default; $result = mysql_query($colsql) or die (mysql_error()); $found_so = false; $found_fh = false; $found_wc = false; $found_cf = false; $found_96changes = false; $found_96bchanges = false; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['Field'] == 'sortorder') $found_so = true; if ($row['Field'] == 'filehash') $found_fh = true; if ($row['Field'] == 'warncount') $found_wc = true; if ($row['Field'] == 'config') $found_cf = true; if ($row['Field'] == 'thumb_width') $found_96changes = true; if ($row['Field'] == 'group_id') $found_96bchanges = true; } if (!$found_so) $sql[] = "alter table weathermap_maps add sortorder int(11) NOT NULL default 0 after id"; if (!$found_fh) $sql[] = "alter table weathermap_maps add filehash varchar(40) NOT NULL default '' after titlecache"; if (!$found_wc) $sql[] = "alter table weathermap_maps add warncount int(11) NOT NULL default 0 after filehash"; if (!$found_cf) $sql[] = "alter table weathermap_maps add config text NOT NULL default '' after warncount"; if (!$found_96changes) { $sql[] = "alter table weathermap_maps add thumb_width int(11) NOT NULL default 0 after config"; $sql[] = "alter table weathermap_maps add thumb_height int(11) NOT NULL default 0 after thumb_width"; $sql[] = "alter table weathermap_maps add schedule varchar(32) NOT NULL default '*' after thumb_height"; $sql[] = "alter table weathermap_maps add archiving set('on','off') NOT NULL default 'off' after schedule"; } if (!$found_96bchanges) { $sql[] = "alter table weathermap_maps add group_id int(11) NOT NULL default 1 after sortorder"; $sql[] = "ALTER TABLE `weathermap_settings` ADD `groupid` INT NOT NULL DEFAULT '0' AFTER `mapid`"; } } $sql[] = "update weathermap_maps set filehash=LEFT(MD5(concat(id,configfile,rand())),20) where filehash = '';"; if (!in_array('weathermap_auth', $tables)) { $sql[] = "CREATE TABLE weathermap_auth ( userid mediumint(9) NOT NULL default '0', mapid int(11) NOT NULL default '0' ) TYPE=MyISAM;"; } if (!in_array('weathermap_groups', $tables)) { $sql[] = "CREATE TABLE weathermap_groups ( `id` INT(11) NOT NULL auto_increment, `name` VARCHAR( 128 ) NOT NULL default '', `sortorder` INT(11) NOT NULL default 0, PRIMARY KEY (id) ) TYPE=MyISAM;"; $sql[] = "INSERT INTO weathermap_groups (id,name,sortorder) VALUES (1,'Weathermaps',1)"; } if (!in_array('weathermap_settings', $tables)) { $sql[] = "CREATE TABLE weathermap_settings ( id int(11) NOT NULL auto_increment, mapid int(11) NOT NULL default '0', groupid int(11) NOT NULL default '0', optname varchar(128) NOT NULL default '', optvalue varchar(128) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM;"; } if (!in_array('weathermap_data', $tables)) { $sql[] = "CREATE TABLE IF NOT EXISTS weathermap_data (id int(11) NOT NULL auto_increment, rrdfile varchar(255) NOT NULL,data_source_name varchar(19) NOT NULL, last_time int(11) NOT NULL,last_value varchar(255) NOT NULL, last_calc varchar(255) NOT NULL, sequence int(11) NOT NULL, local_data_id int(11) NOT NULL DEFAULT 0, PRIMARY KEY (id), KEY rrdfile (rrdfile), KEY local_data_id (local_data_id), KEY data_source_name (data_source_name) ) TYPE=MyISAM"; } else { $colsql = "show columns from weathermap_data from " . $database_default; $result = mysql_query($colsql) or die (mysql_error()); $found_ldi = false; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['Field'] == 'local_data_id') $found_ldi = true; } if (!$found_ldi) { $sql[] = "alter table weathermap_data add local_data_id int(11) NOT NULL default 0 after sequence"; $sql[] = "alter table weathermap_data add index ( `local_data_id` )"; # if there is existing data without a local_data_id, ditch it $sql[] = "delete from weathermap_data"; } } // create the settings entries, if necessary $pagestyle = read_config_option("weathermap_pagestyle"); if($pagestyle == '' or $pagestyle < 0 or $pagestyle >2) { $sql[] = "replace into settings values('weathermap_pagestyle',0)"; } $cycledelay = read_config_option("weathermap_cycle_refresh"); if($cycledelay == '' or intval($cycledelay < 0) ) { $sql[] = "replace into settings values('weathermap_cycle_refresh',0)"; } $renderperiod = read_config_option("weathermap_render_period"); if($renderperiod == '' or intval($renderperiod < -1) ) { $sql[] = "replace into settings values('weathermap_render_period',0)"; } $quietlogging = read_config_option("weathermap_quiet_logging"); if($quietlogging == '' or intval($quietlogging < -1) ) { $sql[] = "replace into settings values('weathermap_quiet_logging',0)"; } $rendercounter = read_config_option("weathermap_render_counter"); if($rendercounter == '' or intval($rendercounter < 0) ) { $sql[] = "replace into settings values('weathermap_render_counter',0)"; } $outputformat = read_config_option("weathermap_output_format"); if($outputformat == '' ) { $sql[] = "replace into settings values('weathermap_output_format','png')"; } $tsize = read_config_option("weathermap_thumbsize"); if($tsize == '' or $tsize < 1) { $sql[] = "replace into settings values('weathermap_thumbsize',250)"; } $ms = read_config_option("weathermap_map_selector"); if($ms == '' or intval($ms) < 0 or intval($ms) > 1) { $sql[] = "replace into settings values('weathermap_map_selector',1)"; } $at = read_config_option("weathermap_all_tab"); if($at == '' or intval($at) < 0 or intval($at) > 1) { $sql[] = "replace into settings values('weathermap_all_tab',0)"; } // update the version, so we can skip this next time $sql[] = "replace into settings values('weathermap_db_version','$myversion')"; // patch up the sortorder for any maps that don't have one. $sql[] = "update weathermap_maps set sortorder=id where sortorder is null or sortorder=0;"; if (!empty($sql)) { for ($a = 0; $a < count($sql); $a++) { # cacti_log("Executing SQL: ".$sql[$a]."\n",true,"WEATHERMAP"); $result = db_execute($sql[$a]); } } } else { # cacti_log("Skipping SQL updates\n",true,"WEATHERMAP"); } } function weathermap_config_arrays () { global $user_auth_realms, $user_auth_realm_filenames, $menu; global $tree_item_types, $tree_item_handlers; if (function_exists('api_plugin_register_realm')) { api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin.php', 'Plugin -> Weathermap: View', 1); api_plugin_register_realm('weathermap', 'weathermap-cacti-plugin-mgmt.php', 'Plugin -> Weathermap: Configure/Manage', 1); } else { $user_auth_realms[42]='Plugin -> Weathermap: Configure/Manage'; $user_auth_realms[43]='Plugin -> Weathermap: View'; $user_auth_realm_filenames['weathermap-cacti-plugin.php'] = 43; $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt.php'] = 42; # $user_auth_realm_filenames['weathermap-cacti-plugin-mgmt-groups.php'] = 42; } // if there is support for custom graph tree types, then register ourselves if(isset($tree_item_handlers)) { $tree_item_types[10] = "Weathermap"; $tree_item_handlers[10] = array("render" => "weathermap_tree_item_render", "name" => "weathermap_tree_item_name", "edit" => "weathermap_tree_item_edit"); } $wm_menu = array( 'plugins/weathermap/weathermap-cacti-plugin-mgmt.php' => "Weathermaps", 'plugins/weathermap/weathermap-cacti-plugin-mgmt-groups.php' => "Groups" ); $menu["Management"]['plugins/weathermap/weathermap-cacti-plugin-mgmt.php'] = $wm_menu; } function weathermap_tree_item_render($leaf) { global $colors; $outdir = dirname(__FILE__).'/output/'; $confdir = dirname(__FILE__).'/configs/'; $map = db_fetch_assoc("select weathermap_maps.* from weathermap_auth,weathermap_maps where weathermap_maps.id=weathermap_auth.mapid and active='on' and (userid=".$_SESSION["sess_user_id"]." or userid=0) and weathermap_maps.id=".$leaf['item_id']); if(sizeof($map)) { $htmlfile = $outdir."weathermap_".$map[0]['id'].".html"; $maptitle = $map[0]['titlecache']; if($maptitle == '') $maptitle= "Map for config file: ".$map[0]['configfile']; html_graph_start_box(1,true); ?>
weathermap |
Subversion Repositories: |
Line No. | Rev | Author | Line |
---|