Add Plugin Architecture (PIA)
authorNeutron Soutmun <neo.neutron@gmail.com>
Thu, 15 Dec 2011 17:44:05 +0000 (00:44 +0700)
committerNeutron Soutmun <neo.neutron@gmail.com>
Thu, 15 Dec 2011 17:44:05 +0000 (00:44 +0700)
* debian/patches/cacti-plugin-0.8.7g-PA-v2.9.patch:
  - Import Plugin Architecture patch from upstream site.
* debian/patches/cacti-pa-sql.patch:
  - Prepare the sql installation patch to support PIA.
* debian/patches/series:
  - New patches added.

debian/patches/cacti-pa-sql.patch [new file with mode: 0644]
debian/patches/cacti-plugin-0.8.7g-PA-v2.9.patch [new file with mode: 0644]
debian/patches/series

diff --git a/debian/patches/cacti-pa-sql.patch b/debian/patches/cacti-pa-sql.patch
new file mode 100644 (file)
index 0000000..b283a21
--- /dev/null
@@ -0,0 +1,78 @@
+Description: Plugin Architecture (PIA) - SQL install
+Origin: upstream, http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7g-PA-v2.9.tar.gz
+
+Index: b/cacti.sql
+===================================================================
+--- a/cacti.sql        2011-12-16 00:18:35.009883693 +0700
++++ b/cacti.sql        2011-12-16 00:32:29.855269733 +0700
+@@ -2639,3 +2639,70 @@
+ --
+ INSERT INTO version VALUES ('new_install');
++
++--
++-- Table structure for table `plugin_config`
++--
++
++CREATE TABLE `plugin_config` (
++  `id` int(8) NOT NULL auto_increment,
++  `directory` varchar(32) NOT NULL default '',
++  `name` varchar(64) NOT NULL default '',
++  `status` tinyint(2) NOT NULL default '0',
++  `author` varchar(64) NOT NULL default '',
++  `webpage` varchar(255) NOT NULL default '',
++  `version` varchar(8) NOT NULL default '',
++  PRIMARY KEY  (`id`),
++  KEY `status` (`status`),
++  KEY `directory` (`directory`)
++) TYPE=MyISAM;
++
++-- --------------------------------------------------------
++
++--
++-- Table structure for table `plugin_hooks`
++--
++
++CREATE TABLE `plugin_hooks` (
++  `id` int(8) NOT NULL auto_increment,
++  `name` varchar(32) NOT NULL default '',
++  `hook` varchar(64) NOT NULL default '',
++  `file` varchar(255) NOT NULL default '',
++  `function` varchar(128) NOT NULL default '',
++  `status` int(8) NOT NULL default '0',
++  PRIMARY KEY  (`id`),
++  KEY `hook` (`hook`),
++  KEY `status` (`status`)
++) TYPE=MyISAM;
++
++-- --------------------------------------------------------
++
++--
++-- Table structure for table `plugin_realms`
++--
++
++CREATE TABLE `plugin_realms` (
++  `id` int(8) NOT NULL auto_increment,
++  `plugin` varchar(32) NOT NULL default '',
++  `file` text NOT NULL,
++  `display` varchar(64) NOT NULL default '',
++  PRIMARY KEY  (`id`),
++  KEY `plugin` (`plugin`)
++) TYPE=MyISAM;
++
++
++CREATE TABLE `plugin_db_changes` (
++  `id` int(10) NOT NULL auto_increment,
++  `plugin` varchar(16) NOT NULL default '',
++  `table` varchar(64) NOT NULL default '',
++  `column` varchar(64) NOT NULL,
++  `method` varchar(16) NOT NULL default '',
++  PRIMARY KEY  (`id`),
++  KEY `plugin` (`plugin`),
++  KEY `method` (`method`)
++) TYPE=MyISAM;
++
++
++REPLACE INTO `plugin_realms` VALUES (1, 'internal', 'plugins.php', 'Plugin Management');
++INSERT INTO `plugin_hooks` VALUES (1, 'internal', 'config_arrays', '', 'plugin_config_arrays', 1);
++INSERT INTO `plugin_hooks` VALUES (2, 'internal', 'draw_navigation_text', '', 'plugin_draw_navigation_text', 1);
diff --git a/debian/patches/cacti-plugin-0.8.7g-PA-v2.9.patch b/debian/patches/cacti-plugin-0.8.7g-PA-v2.9.patch
new file mode 100644 (file)
index 0000000..ad79aac
--- /dev/null
@@ -0,0 +1,2897 @@
+Description: Plugin Architecture (PIA)
+Origin: upstream, http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7g-PA-v2.9.tar.gz
+
+diff -Naur cacti-0.8.7g/auth_changepassword.php cacti-0.8.7g-PA-v2.9/auth_changepassword.php
+--- cacti-0.8.7g/auth_changepassword.php       2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/auth_changepassword.php       2010-10-17 20:09:52.000000000 -0400
+@@ -59,6 +59,8 @@
+                                       header("Location: index.php"); break;
+                               case '3': /* default graph page */
+                                       header("Location: graph_view.php"); break;
++                              default:
++                                      api_plugin_hook_function('login_options_navigate', $user['login_opts']);
+                       }
+               }else{
+                       header("Location: graph_view.php");
+diff -Naur cacti-0.8.7g/auth_login.php cacti-0.8.7g-PA-v2.9/auth_login.php
+--- cacti-0.8.7g/auth_login.php        2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/auth_login.php        2010-10-17 20:09:52.000000000 -0400
+@@ -124,10 +124,12 @@
+               }
+       default:
+-              /* Builtin Auth */
+-              if ((!$user_auth) && (!$ldap_error)) {
+-                      /* if auth has not occured process for builtin - AKA Ldap fall through */
+-                      $user = db_fetch_row("SELECT * FROM user_auth WHERE username = '" . $username . "' AND password = '" . md5(get_request_var_post("login_password")) . "' AND realm = 0");
++              if (!api_plugin_hook_function('login_process', false)) {
++                      /* Builtin Auth */
++                      if ((!$user_auth) && (!$ldap_error)) {
++                              /* if auth has not occured process for builtin - AKA Ldap fall through */
++                              $user = db_fetch_row("SELECT * FROM user_auth WHERE username = '" . $username . "' AND password = '" . md5(get_request_var_post("login_password")) . "' AND realm = 0");
++                      }
+               }
+       }
+       /* end of switch */
+@@ -189,29 +191,42 @@
+               decide what to do next */
+               switch ($user["login_opts"]) {
+                       case '1': /* referer */
+-                              if (sizeof(db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE realm_id = 8 AND user_id = " . $_SESSION["sess_user_id"])) == 0) {
+-                                      header("Location: graph_view.php");
+-                              }else{
+-                                      if (isset($_SERVER["HTTP_REFERER"])) {
+-                                              $referer = $_SERVER["HTTP_REFERER"];
+-                                              if (basename($referer) == "logout.php") {
+-                                                      $referer = "index.php";
+-                                              }
+-                                      } else if (isset($_SERVER["REQUEST_URI"])) {
+-                                              $referer = $_SERVER["REQUEST_URI"];
+-                                              if (basename($referer) == "logout.php") {
+-                                                      $referer = "index.php";
+-                                              }
+-                                      } else {
+-                                              $referer = "index.php";
++                              /* because we use plugins, we can't redirect back to graph_view.php if they don't
++                               * have console access
++                               */
++                              if (isset($_SERVER["HTTP_REFERER"])) {
++                                      $referer = $_SERVER["HTTP_REFERER"];
++                                      if (basename($referer) == "logout.php") {
++                                              $referer = $config['url_path'] . "index.php";
++                                      }
++                              } else if (isset($_SERVER["REQUEST_URI"])) {
++                                      $referer = $_SERVER["REQUEST_URI"];
++                                      if (basename($referer) == "logout.php") {
++                                              $referer = $config['url_path'] . "index.php";
+                                       }
++                              } else {
++                                      $referer = $config['url_path'] . "index.php";
++                              }
++
++                              if (substr_count($referer, "plugins")) {
+                                       header("Location: " . $referer);
++                              } elseif (sizeof(db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE realm_id = 8 AND user_id = " . $_SESSION["sess_user_id"])) == 0) {
++                                      header("Location: graph_view.php");
++                              } else {
++                                      header("Location: $referer");
+                               }
++
+                               break;
+                       case '2': /* default console page */
+-                              header("Location: index.php"); break;
++                              header("Location: " . $config['url_path'] . "index.php");
++
++                              break;
+                       case '3': /* default graph page */
+-                              header("Location: graph_view.php"); break;
++                              header("Location: " . $config['url_path'] . "graph_view.php");
++
++                              break;
++                      default:
++                              api_plugin_hook_function('login_options_navigate', $user['login_opts']);
+               }
+               exit;
+       }else{
+@@ -264,9 +279,17 @@
+ <body bgcolor="#FFFFFF" onload="document.login.login_username.focus()">
+       <form name="login" method="post" action="<?php print basename($_SERVER["PHP_SELF"]);?>">
+       <input type="hidden" name="action" value="login">
++<?php
++
++api_plugin_hook("login_before");
++
++$cacti_logo = $config['url_path'] . 'images/auth_login.gif';
++$cacti_logo = api_plugin_hook_function('cacti_image', $cacti_logo);
++
++?>
+       <table align="center">
+               <tr>
+-                      <td colspan="2"><img src="images/auth_login.gif" border="0" alt=""></td>
++                      <td colspan="2"><center><?php if ($cacti_logo != '') { ?><img src="<?php echo $cacti_logo; ?>" border="0" alt=""><?php } ?></center></td>
+               </tr>
+               <?php
+@@ -303,22 +326,29 @@
+                       <td><input type="password" name="login_password" size="40" style="width: 295px;"></td>
+               </tr>
+               <?php
+-              if (read_config_option("auth_method") == "3") {?>
++              if (read_config_option("auth_method") == "3" || api_plugin_hook_function('login_realms_exist')) {
++                      $realms = api_plugin_hook_function('login_realms', array("local" => array("name" => "Local", "selected" => false), "ldap" => array("name" => "LDAP", "selected" => true)));
++                      ?>
+               <tr>
+                       <td>Realm:</td>
+                       <td>
+-                              <select name="realm" style="width: 295px;">
+-                                      <option value="local">Local</option>
+-                                      <option value="ldap" selected>LDAP</option>
++                              <select name="realm" style="width: 295px;"><?php
++                              if (sizeof($realms)) {
++                              foreach($realms as $name => $realm) {
++                                      print "\t\t\t\t\t<option value='" . $name . "'" . ($realm["selected"] ? " selected":"") . ">" . htmlspecialchars($realm["name"]) . "</option>\n";
++                              }
++                              }
++                              ?>
+                               </select>
+                       </td>
+-                      </tr>
++              </tr>
+               <?php }?>
+               <tr style="height:10px;"><td></td></tr>
+               <tr>
+                       <td><input type="submit" value="Login"></td>
+               </tr>
+       </table>
++<?php api_plugin_hook('login_after'); ?>
+       </form>
+ </body>
+ </html>
+diff -Naur cacti-0.8.7g/cli/add_graph_template.php cacti-0.8.7g-PA-v2.9/cli/add_graph_template.php
+--- cacti-0.8.7g/cli/add_graph_template.php    2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/cli/add_graph_template.php    2010-10-17 20:09:52.000000000 -0400
+@@ -144,6 +144,7 @@
+               exit(1);
+       }else{
+               db_execute("replace into host_graph (host_id,graph_template_id) values (" . $host_id . "," . $graph_template_id . ")");
++              api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $host_id, "graph_template_id" => $graph_template_id));
+       }
+       if (is_error_message()) {
+diff -Naur cacti-0.8.7g/cli/add_tree.php cacti-0.8.7g-PA-v2.9/cli/add_tree.php
+--- cacti-0.8.7g/cli/add_tree.php      2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/cli/add_tree.php      2010-10-17 20:09:52.000000000 -0400
+@@ -33,6 +33,7 @@
+ include(dirname(__FILE__)."/../include/global.php");
+ include_once($config["base_path"]."/lib/api_automation_tools.php");
+ include_once($config["base_path"].'/lib/tree.php');
++include_once($config["base_path"].'/lib/api_tree.php');
+ /* process calling arguments */
+ $parms = $_SERVER["argv"];
+diff -Naur cacti-0.8.7g/cli/host_update_template.php cacti-0.8.7g-PA-v2.9/cli/host_update_template.php
+--- cacti-0.8.7g/cli/host_update_template.php  2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/cli/host_update_template.php  2010-10-17 20:09:52.000000000 -0400
+@@ -136,6 +136,7 @@
+                       foreach ($graph_templates as $graph_template) {
+                               db_execute("REPLACE INTO host_graph (host_id, graph_template_id) VALUES (" . $host["id"] . ", " . $graph_template["graph_template_id"] . ")");
++                              api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $host_id, "graph_template_id" => $graph_template["graph_template_id"]));
+                       }
+               }
+       }
+diff -Naur cacti-0.8.7g/data_sources.php cacti-0.8.7g-PA-v2.9/data_sources.php
+--- cacti-0.8.7g/data_sources.php      2010-09-19 21:39:05.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/data_sources.php      2010-10-17 20:09:52.000000000 -0400
+@@ -44,6 +44,8 @@
+       7 => "Disable"
+       );
++$ds_actions = api_plugin_hook_function('data_source_action_array', $ds_actions);
++
+ /* set default action */
+ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
+@@ -402,6 +404,8 @@
+                               api_reapply_suggested_data_source_title($selected_items[$i]);
+                               update_data_source_title_cache($selected_items[$i]);
+                       }
++              } else {
++                      api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']);
+               }
+               header("Location: data_sources.php");
+               exit;
+@@ -545,6 +549,12 @@
+                               </tr>\n
+                               ";
+                       $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>";
++              }else{
++                      $save['drp_action'] = $_POST['drp_action'];
++                      $save['ds_list'] = $ds_list;
++                      $save['ds_array'] = (isset($ds_array)? $ds_array : array());
++                      api_plugin_hook_function('data_source_action_prepare', $save);
++                      $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
+               }
+       }else{
+               print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one data source.</span></td></tr>\n";
+@@ -683,6 +693,8 @@
+       input_validate_input_number(get_request_var("host_id"));
+       /* ==================================================== */
++      api_plugin_hook('data_source_edit_top');
++
+       $use_data_template = true;
+       $host_id = 0;
+@@ -975,8 +987,9 @@
+       form_save_button("data_sources.php");
+-      include_once("./include/bottom_footer.php");
++      api_plugin_hook('data_source_edit_bottom');
++      include_once("./include/bottom_footer.php");
+ }
+ function get_poller_interval($seconds) {
+@@ -1310,8 +1323,10 @@
+       $i = 0;
+       if (sizeof($data_sources) > 0) {
+               foreach ($data_sources as $data_source) {
++                      $data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]);
++                      $data_source = api_plugin_hook_function('data_sources_table', $data_source);
+                       /* we're escaping strings here, so no need to escape them on form_selectable_cell */
+-                      $data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : htmlspecialchars($data_source["data_template_name"]));
++                      $data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : $data_source["data_template_name"]);
+                       $data_input_name    = ((empty($data_source["data_input_name"])) ? "<em>External</em>" : htmlspecialchars($data_source["data_input_name"]));
+                       $poller_interval    = ((isset($poller_intervals[$data_source["local_data_id"]])) ? $poller_intervals[$data_source["local_data_id"]] : 0);
+                       form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]); $i++;
+diff -Naur cacti-0.8.7g/graph_image.php cacti-0.8.7g-PA-v2.9/graph_image.php
+--- cacti-0.8.7g/graph_image.php       2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/graph_image.php       2010-10-17 20:09:52.000000000 -0400
+@@ -44,6 +44,8 @@
+ /* flush the headers now */
+ ob_end_clean();
++api_plugin_hook_function('graph_image');
++
+ session_write_close();
+ $graph_data_array = array();
+diff -Naur cacti-0.8.7g/graph.php cacti-0.8.7g-PA-v2.9/graph.php
+--- cacti-0.8.7g/graph.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/graph.php     2010-10-17 20:09:52.000000000 -0400
+@@ -32,6 +32,8 @@
+ include_once("./lib/html_tree.php");
+ include_once("./include/top_graph_header.php");
++api_plugin_hook_function('graph');
++
+ /* ================= input validation ================= */
+ input_validate_input_regex(get_request_var("rra_id"), "^([0-9]+|all)$");
+ input_validate_input_number(get_request_var("local_graph_id"));
+@@ -77,6 +79,12 @@
+ switch ($_REQUEST["action"]) {
+ case 'view':
++      do_hook_function('page_buttons',
++              array('lgid' => $_GET["local_graph_id"],
++                      'leafid' => '',//$leaf_id,
++                      'mode' => 'mrtg',
++                      'rraid' => $_GET["rra_id"])
++              );
+       ?>
+       <tr bgcolor='#<?php print $colors["header"];?>'>
+               <td colspan='3' class='textHeaderDark'>
+@@ -100,6 +108,7 @@
+                                                               <a href='<?php print htmlspecialchars("graph.php?action=zoom&local_graph_id=" . $_GET["local_graph_id"]. "&rra_id=" . $rra["id"] . "&view_type=" . $_REQUEST["view_type"]);?>'><img src='images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
+                                                               <a href='<?php print htmlspecialchars("graph_xport.php?local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $rra["id"] . "&view_type=" . $_REQUEST["view_type"]);?>'><img src='images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
+                                                               <a href='<?php print htmlspecialchars("graph.php?action=properties&local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $rra["id"] . "&view_type=" . $_REQUEST["view_type"]);?>'><img src='images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a>
++                                                              <?php api_plugin_hook('graph_buttons', array('hook' => 'view', 'local_graph_id' => $_GET['local_graph_id'], 'rra' => $rra['id'], 'view_type' => $_REQUEST['view_type'])); ?>
+                                                       </td>
+                                               </tr>
+                                               <tr>
+@@ -113,6 +122,7 @@
+                       <?php
+                       $i++;
+               }
++              do_hook_function('tree_view_page_end');
+       }
+       break;
+@@ -215,6 +225,7 @@
+                                       <td valign='top' style='padding: 3px;' class='noprint'>
+                                               <a href='<?php print htmlspecialchars("graph.php?action=properties&local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $_GET["rra_id"] . "&view_type=" . $_REQUEST["view_type"] . "&graph_start=" . $graph_start . "&graph_end=" . $graph_end);?>'><img src='images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a>
+                                               <a href='<?php print htmlspecialchars("graph_xport.php?local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $_GET["rra_id"] . "&view_type=" . $_REQUEST["view_type"]);?>&graph_start=<?php print $graph_start;?>&graph_end=<?php print $graph_end;?>'><img src='images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
++                                              <?php api_plugin_hook('graph_buttons', array('hook' => 'zoom', 'local_graph_id' => $_GET['local_graph_id'], 'rra' =>  $_GET['rra_id'], 'view_type' => $_REQUEST['view_type'])); ?>
+                                       </td>
+                               </tr>
+                               <tr>
+@@ -247,6 +258,7 @@
+                                       <td valign='top' style='padding: 3px;'>
+                                               <a href='<?php print htmlspecialchars("graph.php?action=zoom&local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $_GET["rra_id"] . "&view_type=" . $_REQUEST["view_type"]);?>'><img src='images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
+                                               <a href='<?php print htmlspecialchars("graph_xport.php?local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $_GET["rra_id"] . "&view_type=" . $_REQUEST["view_type"]);?>'><img src='images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
++                                              <?php api_plugin_hook('graph_buttons', array('hook' => 'properties', 'local_graph_id' => $_GET['local_graph_id'], 'rra' =>  $_GET['rra_id'], 'view_type' => $_REQUEST['view_type'])); ?>
+                                       </td>
+                               </tr>
+                               <tr>
+diff -Naur cacti-0.8.7g/graphs_new.php cacti-0.8.7g-PA-v2.9/graphs_new.php
+--- cacti-0.8.7g/graphs_new.php        2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/graphs_new.php        2010-10-17 20:09:52.000000000 -0400
+@@ -511,7 +511,8 @@
+                       </td>
+                       <td nowrap style='white-space: nowrap;' class="textInfo" align="center" valign="top">
+                               <span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]);?>">Edit this Host</a><br>
+-                              <span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php print htmlspecialchars("host.php?action=edit");?>">Create New Host</a>
++                              <span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php print htmlspecialchars("host.php?action=edit");?>">Create New Host</a><br>
++                              <?php api_plugin_hook('graphs_new_top_links'); ?>
+                       </td>
+               </tr>
+       </table>
+diff -Naur cacti-0.8.7g/graphs.php cacti-0.8.7g-PA-v2.9/graphs.php
+--- cacti-0.8.7g/graphs.php    2010-09-19 21:39:05.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/graphs.php    2010-10-17 20:09:52.000000000 -0400
+@@ -45,6 +45,8 @@
+       4 => "Convert to Graph Template"
+       );
++$graph_actions = api_plugin_hook_function('graphs_action_array', $graph_actions);
++
+ /* set default action */
+ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
+@@ -362,6 +364,8 @@
+                               api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
+                       }
++              } else {
++                      api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
+               }
+               header("Location: graphs.php");
+@@ -514,6 +518,12 @@
+                               ";
+                       $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
++              } else {
++                      $save['drp_action'] = $_POST['drp_action'];
++                      $save['graph_list'] = $graph_list;
++                      $save['graph_array'] = (isset($graph_array) ? $graph_array : array());
++                      api_plugin_hook_function('graphs_action_prepare', $save);
++                      $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
+               }
+       }else{
+               print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
+diff -Naur cacti-0.8.7g/host.php cacti-0.8.7g-PA-v2.9/host.php
+--- cacti-0.8.7g/host.php      2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/host.php      2010-10-17 20:09:52.000000000 -0400
+@@ -44,6 +44,8 @@
+       6 => "Change Availability Options"
+       );
++$device_actions = api_plugin_hook_function('device_action_array', $device_actions);
++
+ /* set default action */
+ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
+@@ -137,6 +139,7 @@
+               /* ==================================================== */
+               db_execute("replace into host_graph (host_id,graph_template_id) values (" . $_POST["id"] . "," . $_POST["graph_template_id"] . ")");
++              api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $_POST["id"], "graph_template_id" => $_POST["graph_template_id"]));
+               header("Location: host.php?action=edit&id=" . $_POST["id"]);
+               exit;
+@@ -305,6 +308,8 @@
+                               api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
+                       }
++              } else {
++                      api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
+               }
+               header("Location: host.php");
+@@ -450,6 +455,12 @@
+                               <input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
+                               ";
+                       $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
++              } else {
++                      $save['drp_action'] = $_POST['drp_action'];
++                      $save['host_list'] = $host_list;
++                      $save['host_array'] = (isset($host_array)? $host_array : array());
++                      api_plugin_hook_function('device_action_prepare', $save);
++                      $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
+               }
+       }else{
+               print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
+@@ -532,6 +543,8 @@
+       input_validate_input_number(get_request_var("id"));
+       /* ==================================================== */
++      api_plugin_hook('host_edit_top');
++
+       if (!empty($_GET["id"])) {
+               $host = db_fetch_row("select * from host where id=" . $_GET["id"]);
+               $header_label = "[edit: " . htmlspecialchars($host["description"]) . "]";
+@@ -643,6 +656,7 @@
+                                       <span style="color: #c16921;">*</span><a href="<?php print htmlspecialchars("graphs_new.php?host_id=" . $host["id"]);?>">Create Graphs for this Host</a><br>
+                                       <span style="color: #c16921;">*</span><a href="<?php print htmlspecialchars("data_sources.php?host_id=" . $host["id"] . "&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1");?>">Data Source List</a><br>
+                                       <span style="color: #c16921;">*</span><a href="<?php print htmlspecialchars("graphs.php?host_id=" . $host["id"] . "&graph_rows=30&filter=&template_id=-1&page=1");?>">Graph List</a>
++                                      <?php api_plugin_hook('device_edit_top_links'); ?>
+                               </td>
+                       </tr>
+               </table>
+@@ -1107,6 +1121,8 @@
+       }
+       form_save_button("host.php", "return");
++
++      api_plugin_hook('host_edit_bottom');
+ }
+ function host() {
+diff -Naur cacti-0.8.7g/images/disable_icon.png cacti-0.8.7g-PA-v2.9/images/disable_icon.png
+--- cacti-0.8.7g/images/disable_icon.png       1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/disable_icon.png       2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,4 @@
++‰PNG\r
++\1a
++\0\0\0\rIHDR\0\0\0\10\0\0\0\10\b\ 3\0\0\0(-\ fS\0\0\ 3\0PLTE€€€¾/\aµ0\ f·9\1a¸6\16¹9\17º9\19½B#À,\ 2À2
++Á3\vÂ8\12À<\18×2\ 1Ô8\11à9\ 4á>\bÙD\1fÞA\19ØG#ßH"ÞN%ÛQ,ÚQ/ÜP*ÜS0àB\réH\ eàG\15àK\1câN&äP$áP,èV$é],âT1ãZ8ã];ã`?èc7äaBåeFågHælOçoSçpTèuZèv[èy^è}cѐ\7fêgî‡eéƒkê…kìvìyðkñ’qµ&\0ܖ…Þ›Ší—€î‰ï Œð¨•ñ®ö±˜ò²¢ô½°ô¿²õ·õÆ»øǶûäÜûèâüðîÿÿÿ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0Úú\r¤\0\0\0\ 1tRNS\0@æØf\0\0\0\ 1bKGD\0ˆ\ 5\1dH\0\0\0   pHYs\0\0\ eÄ\0\0\ eÄ\ 1•+\ e\e\0\0\0ÇIDATxœeÏ[o‚@\14\ 4\15ã­¦!ي¶T6š\ 3h¤!»à\ 5EK´”ùÿ\7fÇ\ 3öÍyü’™djµ§d:\¯<Ï¥…tÞ\ e\fú|Št\18\ 4¬$^\18Ô)Qi\ 1\14Dž¬`\13é\1fdJeHÅ{‡ÁW)"—¤­ E   ^P\}\17°?²¼\ 2Z#©à3„YnH\1f‰û\ f³>ƒã=*ó¯ß|Úc\10tDB´œo\11\f¦¤3nq|ÃÅz5\18ƶCÑ\1fo-kTÂp,ʘ³éd4Ø1ì\ef³Ýjw놱û~>\7f\a®‚"X_\1e\0\0\0\0IEND®B`‚
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/images/enable_icon_disabled.png cacti-0.8.7g-PA-v2.9/images/enable_icon_disabled.png
+--- cacti-0.8.7g/images/enable_icon_disabled.png       1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/enable_icon_disabled.png       2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,3 @@
++‰PNG\r
++\1a
++\0\0\0\rIHDR\0\0\0\10\0\0\0\10\b\ 3\0\0\0(-\ fS\0\0\ 3\0PLTE€€€PPPUUUWWWXXXYYYZZZ[[[\\\^^^```bbbiiijjjssstttuuuvvvwwwxxx|||}}}~~~\7f\7f\7fKKK‚‚‚………†††‡‡‡ŠŠŠ‹‹‹ŒŒŒŽŽŽ’’’–––———ššš›››   £££¤¤¤¦¦¦«««³³³´´´¾¾¾ÅÅÅËËËÿÿÿ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15øÝ2\0\0\0\ 1bKGD\0ˆ\ 5\1dH\0\0\0 pHYs\0\0\ eÄ\0\0\ eÄ\ 1•+\ e\e\0\0\0ªIDATxÚ]ÎÍJBQ\18@Ñ¥|WiRrA'M:\bŽ\ 5ßÿ\11œ\ 659D3ƒ\ 6Â%åüØ(¨ö\v¬\1d\a\7f\v·KmÌ¦–§E¸,†¢¶­nò¼\ fuèU{˜}š˜   ­Ðú̘)K¡W­ç|^‡á,Р'»\\by»b\ 4)\7f   ›þï£:&ÓɁŒ`J²4ò\1e• N'iäht\13®ËÊ´š\1f7j!\çÃX꛱–¡¯…ÝËúã‡Xß\vw{¿Øo"ÍH“ì>]î\0\0\0\0IEND®B`‚
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/images/enable_icon.png cacti-0.8.7g-PA-v2.9/images/enable_icon.png
+--- cacti-0.8.7g/images/enable_icon.png        1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/enable_icon.png        2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,5 @@
++‰PNG\r
++\1a
++\0\0\0\rIHDR\0\0\0\10\0\0\0\10\b\ 3\0\0\0(-\ fS\0\0\ 3\0PLTE€€€\ fo\ f\ 5~\ 5\16t\16\17y\17\19w\19\1ez\1e#}#\v€\v\ 1‘\ 1\12‚\12\19\19\1fŒ\1f\1fž\1f\b£\b\ f£\ f\r¤\r
++­
++\15¤\15\14¯\14\18¢\18\19¬\19#Œ#%š%)—).”.0•00˜01˜1;ž;$¯$!µ!? ?8ª8BŸBB BA¨AO§OR¦RT©T[­[a¯ag³gkµkv»v\7f°\7fy¼y\0o\0…·…Š»Š€À€ŒÆŒÏ£Ö£±Ø±ÿÿÿ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0×\1fX4\0\0\0\ 1tRNS\0@æØf\0\0\0\ 1bKGD\0ˆ\ 5\1dH\0\0\0   pHYs\0\0\ eÄ\0\0\ eÄ\ 1•+\ e\e\0\0\0®IDATxœeÏÛ\ e‚0\f\ 6`ä Ó`2\ 4%3› £c\1c\ 4\15eïÿfv˜è\ 5½û¿¦ië8‹šºFW\0 sÁO\ f„î5ö]SkTÉ\ 2„v|¶ž\f€\10l û®ÖÊ\18sæœm\10*ì+(P\18›\ 1\1a­U!8J:Hm~•Z\10Õ\1fö;\ 4\ eJ,¯˜\ f‰\ 5VØ«JÌqL‰\ 5.圳,¢.Bˆ’ços9F_ !îgiš$”n\a„ûÊó\ 2Ï÷     qÝá¶|þ\ 3@{\1aIÇ=\1eþ\0\0\0\0IEND®B`‚
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/images/install_icon_disabled.png cacti-0.8.7g-PA-v2.9/images/install_icon_disabled.png
+--- cacti-0.8.7g/images/install_icon_disabled.png      1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/install_icon_disabled.png      2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,5 @@
++‰PNG\r
++\1a
++\0\0\0\rIHDR\0\0\0\10\0\0\0\10\b\ 3\0\0\0(-\ fS\0\0\ 3\0PLTE€€€dddfffgggnnnrrrxxx}}}```‹‹‹•••œœœ¢¢¢©©©­­­µµµ¹¹¹ºººÁÁÁÈÈÈÏÏÏÛÛÛéééíííñññýýýþýý\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0g\ 6Óö\0\0\0\ 1tRNS\0@æØf\0\0\0\ 1bKGD\0ˆ\ 5\1dH\0\0\0    pHYs\0\0\ eÄ\0\0\ eÄ\ 1•+\ e\e\0\0\0IDATxœmÎÁ
++\ 41\b\ 3Ð"+RK TŠôÿ\7fté\ eìarË;D[{͔JØ_uҋžî«’‰#)\1e\13±\18\e’\ 5\10\ 2È\rF
++\vDáÝ3‡p¹ÀjÑ2\rt\1cе™É½¬ß ZRÉ~\0êÚóê:”÷Yà\1eí8g\e\01ùù½J\193búóz     MÕÈö–/›¶\bÆ'¸ãï\0\0\0\0IEND®B`‚
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/images/install_icon.png cacti-0.8.7g-PA-v2.9/images/install_icon.png
+--- cacti-0.8.7g/images/install_icon.png       1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/install_icon.png       2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,5 @@
++‰PNG\r
++\1a
++\0\0\0\rIHDR\0\0\0\10\0\0\0\10\b\ 3\0\0\0(-\ fS\0\0\ 3\0PLTE€€€\1a\ f\1c;¢",‘$,&6™+6™&D­%U¼2[º)JÃ)NÉ#TÛ1UÊ2gÆ4kÐ;vÝ*\7fÿ/yÿ>\7fðFU¤NV§RU£Z]¨LdµN}ÏAyä0ƒÿ5‚ÿ;…ÿ?“ÿ^†ÒB„ûM…ÿOŠÿN’ûRˆÿW‘úV˜ü^õZ¤ÿa“ÿg—ÿ`˜ÿkšÿr—ót˜ðu›õrŸÿc£öd«ÿh¨ûi±ÿhµÿ}¦ÿ{¼ý~Äÿ\11&š•˜Ä‘ Ò…«ÿŠ¯ÿ±ÿ’¿ÿ—¹ÿ›»ÿ«¬Ð¥²Ú¦¶ß±²Ó¹ºØ¡·ãª»ã‡Ìÿ‰ÈÿÉÿ“ÑÿºÆå³Ëþ¸×ÿºÕÿÅÅÝÅÖþÇÛÿËÝûÉÞÿÃáÿÏâÿÖãÿÙæüßëüßîÿÜòÿêí÷îîõèïÿæúÿìòÿõõùòÿÿÿÿÿ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\bÜ`á\0\0\0\ 1tRNS\0@æØf\0\0\0\ 1bKGD\0ˆ\ 5\1dH\0\0\0    pHYs\0\0\ eÄ\0\0\ eÄ\ 1•+\ e\e\0\0\0ÍIDATxœc`À
++Ü%XXÄÝàÜ vn\ 3''=\1e\16w(ßÊ61:4$"\› ¬(™Í6%Ø)4ØÞ)PÛ*\1e(àÌ\17ëïd—šdnkïÈk\r\14\103\b4×6LNÒÕÖ¶U\14\ 5
++0š\e:Ú©&%(99é*1\ 3\ 5˜u”#S\1d“\12œRC\14…8€\ 2’j2j‘©@\10ª($'  \14p•6\16RNMR‘Ñ\14±\ 1YËef&o\12\15m$olÆ   ²–ÁOÀÒËÌÂÂÌËKÐ\15âT?~\ro__o#~W˜g’<\15¤¤\14\19°\ 1\0ëz%àÝÔ\1c²\0\0\0\0IEND®B`‚
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/images/uninstall_icon.gif cacti-0.8.7g-PA-v2.9/images/uninstall_icon.gif
+--- cacti-0.8.7g/images/uninstall_icon.gif     1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/uninstall_icon.gif     2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,4 @@
++GIF89a\10\0\10\0÷N\0\0\0\0\ 1\ 1\ 1\ 2\ 2\ 2\ 3\ 3\ 3\ 4\ 4\ 4\ 5\ 5\ 5\ 6\ 6\ 6\a\a\a\b\b\b                      
++
++
++\v\v\v\f\f\f\r\r\r\ e\ e\ e\ f\ f\ f\10\10\10\11\11\11\12\12\12\13\13\13\14\14\14\15\15\15\16\16\16\17\17\17\18\18\18\19\19\19\1a\1a\1a\e\e\e\1c\1c\1c\1d\1d\1d\1e\1e\1e\1f\1f\1f   !!!"""###$$$%%%&&&'''((()))***+++,,,---...///000111222333444555666777888999:::;;;<<<===>>>???A??C??D??F@@H??J>>M<<N::O99O88P88P77P77P77Q66Q66P66P66P77O77O77X99c==m??xBB‚EEŠGGŽJJ“LL™NNžPP SSŸVV XX YYŸZZ›\\Ÿ]]¦``±cc½ggÄiiÈooÎvvÐzzÑ}}Ò\7f\7fӁÓ‚‚Ô‚‚Ô„„Õ††Õ‡‡ÕˆˆÖŠŠÖŠŠÖ‹‹Ö‹‹ÖŒŒÖÖÒŒŒÌ‹‹ÃŠŠ¸‰‰©‡‡ž……”„„‹‚‚ƒ€€€€€€€€€€€€€€€€€€€€€€€€€€€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f€\7f\7f\7f\7f‚\7f\7fƒ~~†~~Š}}{{–zzxx¦uu¯ss¸qq»ppºpp»uu¼yy»~~»ƒƒ¿ŒŒÂ““Æ™™ÉžžÌ¡¡Ï££Ñ¥¥Ó¥¥Õ¥¥Ö¥¥Ö¥¥×¤¤×££×¢¢×  ×ŸŸÖžžÖžžÖÖÖžž×ŸŸ×  ×¡¡Ø££Ú§§ÛªªÛ­­Ü°°Þ´´ß¶¶ß¸¸àººá»»á¼¼â½½ã¿¿äÁÁåÃÃæÅÅçÈÈèÉÉèÊÊéËËéÌÌéÍÍêÎÎëÐÐìÒÒíÓÓîÔÔîÕÕïÖÖïØØðÚÚñÝÝòááóååôèèôêêôêêôêêôêêôëëõëëõììõííõîîõïïõððöññ÷òòøóóùôôúööûøøüùùüûûýüüýüüþýýþýýþýý!ù\ 4    \0\0ˆ\0,\0\0\0\0\10\0\10\0\0\bÅ\0\11      \1cH°`AyÇԄ       £&™<ƒˆ’}±ÃLš4fq¾H+(ñX³_ƌýjvLã@w]~ýbcǝ¹=lTvyˆèW\1a;iؘû÷Ï\1c›4{Â$\13\b&Ñp<yúÌIF ’£ÿŽ¹swì_85lœ\bt¢&αci¦ªùu,Î\1e­ˆÈ¤ù\15‡M\1cwòìı£-NӚ^ŽýÚ³GÞ?²ÒÜy\19ŠHž“8ژ\rÓ\16¿HÜ\rLv8œåppÏZ+ÈÌI\17¯e» Ù\f1\19™'OÈl„Ⱥ`@\0;
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/images/view_none.gif cacti-0.8.7g-PA-v2.9/images/view_none.gif
+--- cacti-0.8.7g/images/view_none.gif  1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/images/view_none.gif  2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,4 @@
++GIF89a\10\0\10\0÷\0\0\0\0\0\ 1\ 1\ 1\ 2\ 2\ 2\ 3\ 3\ 3\ 4\ 4\ 4\ 5\ 5\ 5\ 6\ 6\ 6\a\a\a\b\b\b                      
++
++
++\v\v\v\f\f\f\r\r\r\ e\ e\ e\ f\ f\ f\10\10\10\11\11\11\12\12\12\13\13\13\14\14\14\15\15\15\16\16\16\17\17\17\18\18\18\19\19\19\1a\1a\1a\e\e\e\1c\1c\1c\1d\1d\1d\1e\1e\1e\1f\1f\1f   !!!"""###$$$%%%&&&'''((()))***+++,,,---...///000111222333444555666777888999:::;;;<<<===>>>???@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSSTTTUUUVVVWWWXXXYYYZZZ[[[\\\]]]^^^___```dddhhhnnntttyyy}}}~~~\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f\7f€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€‚‚‚†††‹‹‹‘‘‘———›››   ¡¡¡¢¢¢£££¤¤¤¥¥¥¦¦¦§§§¨¨¨©©©ªªª«««¬¬¬­­­®®®¯¯¯°°°±±±²²²³³³´´´µµµ¶¶¶···¸¸¸¹¹¹ººº»»»¼¼¼½½½¾¾¾¿¿¿ÀÀÀÁÁÁÂÂÂÃÃÃÄÄÄÅÅÅÆÆÆÇÇÇÈÈÈÉÉÉÊÊÊËËËÌÌÌÍÍÍÎÎÎÏÏÏÐÐÐÑÑÑÒÒÒÓÓÓÔÔÔÕÕÕÖÖÖ×××ØØØÙÙÙÚÚÚÛÛÛÜÜÜÝÝÝÞÞÞßßßàààáááâââãããäääåååæææçççèèèéééêêêëëëìììíííîîîïïïðððñññòòòóóóôôôõõõööö÷÷÷øøøùùùúúúûûûüüüýýýþþþÿÿÿ!ù\ 4    \0\0Œ\0,\0\0\0\0\10\0\10\0\0\b\1d\0\19      \1cH° Áƒ\b\13*\È°¡Ã‡\10#JœH±¢Å\ 1\ 1\0;
+\ No newline at end of file
+diff -Naur cacti-0.8.7g/include/auth.php cacti-0.8.7g-PA-v2.9/include/auth.php
+--- cacti-0.8.7g/include/auth.php      2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/auth.php      2010-10-17 20:09:52.000000000 -0400
+@@ -26,14 +26,17 @@
+ /* check to see if this is a new installation */
+ if (db_fetch_cell("select cacti from version") != $config["cacti_version"]) {
+-      header ("Location: install/");
++      header ("Location: " . $config['url_path'] . "install/");
+       exit;
+ }
+ if (read_config_option("auth_method") != 0) {
++      /* handle alternate authentication realms */
++      api_plugin_hook_function('auth_alternate_realms');
++
+       /* handle change password dialog */
+       if ((isset($_SESSION['sess_change_password'])) && (read_config_option("webbasic_enabled") != "on")) {
+-              header ("Location: auth_changepassword.php?ref=" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"));
++              header ("Location: " . $config['url_path'] . "auth_changepassword.php?ref=" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"));
+               exit;
+       }
+@@ -72,9 +75,9 @@
+                       and user_auth_realm.realm_id='$realm_id'")) || (empty($realm_id)))) {
+                       if (isset($_SERVER["HTTP_REFERER"])) {
+-                              $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='" . htmlspecialchars($_SERVER["HTTP_REFERER"]) . "'>Return</a> | <a href='logout.php'>Login Again</a> )</td>";
++                              $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='" . htmlspecialchars($_SERVER["HTTP_REFERER"]) . "'>Return</a> | <a href='" . $config['url_path'] . "logout.php'>Login Again</a> )</td>";
+                       }else{
+-                              $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='logout.php'>Login Again</a> )</td>";
++                              $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='" . $config['url_path'] . "logout.php'>Login Again</a> )</td>";
+                       }
+                       ?>
+@@ -83,14 +86,14 @@
+                       <head>
+                               <title>Cacti</title>
+                               <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+-                              <link href="include/main.css" type="text/css" rel="stylesheet">
++                              <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
+                       </head>
+                       <body>
+                       <br><br>
+                       <table width="450" align='center'>
+                               <tr>
+-                                      <td colspan='2'><img src='images/auth_deny.gif' border='0' alt='Access Denied'></td>
++                                      <td colspan='2'><img src='<?php echo $config['url_path']; ?>images/auth_deny.gif' border='0' alt='Access Denied'></td>
+                               </tr>
+                               <tr style='height:10px;'><td></td></tr>
+                               <tr>
+diff -Naur cacti-0.8.7g/include/bottom_footer.php cacti-0.8.7g-PA-v2.9/include/bottom_footer.php
+--- cacti-0.8.7g/include/bottom_footer.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/bottom_footer.php     2010-10-17 20:09:52.000000000 -0400
+@@ -21,6 +21,10 @@
+  | http://www.cacti.net/                                                   |
+  +-------------------------------------------------------------------------+
+ */
++
++$oper_mode = api_plugin_hook_function('top_header', OPER_MODE_NATIVE);
++if (($oper_mode == OPER_MODE_NATIVE) || ($oper_mode == OPER_MODE_IFRAME_NONAV)) {
++
+ ?>
+                       </div>
+                       <br>
+@@ -32,6 +36,9 @@
+ </html>
+ <?php
++
++}
++
+ /* we use this session var to store field values for when a save fails,
+ this way we can restore the field's previous values. we reset it here, because
+ they only need to be stored for a single page */
+diff -Naur cacti-0.8.7g/include/config.php cacti-0.8.7g-PA-v2.9/include/config.php
+--- cacti-0.8.7g/include/config.php    2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/config.php    2010-10-17 20:09:52.000000000 -0400
+@@ -30,6 +30,17 @@
+ $database_password = "cactiuser";
+ $database_port = "3306";
++/* load up old style plugins here */
++$plugins = array();
++//$plugins[] = 'thold';
++
++/*
++   Edit this to point to the default URL of your Cacti install
++   ex: if your cacti install as at http://serverip/cacti/ this
++   would be set to /cacti/
++*/
++$url_path = "/";
++
+ /* Default session name - Session name must contain alpha characters */
+ #$cacti_session_name = "Cacti";
+diff -Naur cacti-0.8.7g/include/global_arrays.php cacti-0.8.7g-PA-v2.9/include/global_arrays.php
+--- cacti-0.8.7g/include/global_arrays.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/global_arrays.php     2010-10-17 20:09:52.000000000 -0400
+@@ -22,6 +22,8 @@
+  +-------------------------------------------------------------------------+
+ */
++global $menu;
++
+ $messages = array(
+       1  => array(
+               "message" => 'Save Successful.',
+@@ -654,4 +656,10 @@
+       GDC_SLASH => "/"
+       );
++$plugin_architecture = array(
++      'version' => '2.9'
++      );
++
++api_plugin_hook('config_arrays');
++
+ ?>
+diff -Naur cacti-0.8.7g/include/global_constants.php cacti-0.8.7g-PA-v2.9/include/global_constants.php
+--- cacti-0.8.7g/include/global_constants.php  2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/global_constants.php  2010-10-17 20:09:52.000000000 -0400
+@@ -173,4 +173,9 @@
+ define("SNMP_CMDPHP", 1);
+ define("SNMP_WEBUI", 2);
++define('OPER_MODE_NATIVE', 0);
++define('OPER_MODE_RESKIN', 1);
++define('OPER_MODE_IFRAME_NONAV', 2);
++define('OPER_MODE_NOTABS', 3);
++
+ ?>
+diff -Naur cacti-0.8.7g/include/global_form.php cacti-0.8.7g-PA-v2.9/include/global_form.php
+--- cacti-0.8.7g/include/global_form.php       2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/global_form.php       2010-10-17 20:09:52.000000000 -0400
+@@ -22,8 +22,9 @@
+  +-------------------------------------------------------------------------+
+ */
+-if (!defined("VALID_HOST_FIELDS")) {
+-      define("VALID_HOST_FIELDS", "(hostname|snmp_community|snmp_username|snmp_password|snmp_auth_protocol|snmp_priv_passphrase|snmp_priv_protocol|snmp_context|snmp_version|snmp_port|snmp_timeout)");
++if (!defined('VALID_HOST_FIELDS')) {
++      $string = api_plugin_hook_function('valid_host_fields', '(hostname|snmp_community|snmp_username|snmp_password|snmp_auth_protocol|snmp_priv_passphrase|snmp_priv_protocol|snmp_context|snmp_version|snmp_port|snmp_timeout)');
++      define('VALID_HOST_FIELDS', $string);
+ }
+ /* file: cdef.php, action: edit */
+@@ -1190,4 +1191,7 @@
+               "dropdown_sql" => "select id,name from snmp_query order by name"
+               )
+       );
+-?>
++
++
++api_plugin_hook('config_form');
++
+diff -Naur cacti-0.8.7g/include/global.php cacti-0.8.7g-PA-v2.9/include/global.php
+--- cacti-0.8.7g/include/global.php    2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/global.php    2010-10-17 20:09:52.000000000 -0400
+@@ -93,6 +93,13 @@
+ /* built-in snmp support */
+ $config["php_snmp_support"] = function_exists("snmpget");
++/* set URL path */
++if (! isset($url_path)) { 
++      $url_path = "";
++}
++$config['url_path'] = $url_path;
++define('URL_PATH', $url_path);
++
+ /* used for includes */
+ $config["base_path"] = strtr(ereg_replace("(.*)[\\\/]include", "\\1", dirname(__FILE__)), "\\", "/");
+ $config["library_path"] = ereg_replace("(.*[\\\/])include", "\\1lib", dirname(__FILE__));
+@@ -188,15 +195,17 @@
+ /* include base modules */
+ include($config["library_path"] . "/adodb/adodb.inc.php");
+ include($config["library_path"] . "/database.php");
+-include_once($config["library_path"] . "/functions.php");
+-include_once($config["include_path"] . "/global_constants.php");
+-include_once($config["include_path"] . "/global_arrays.php");
+-include_once($config["include_path"] . "/global_settings.php");
+ /* connect to the database server */
+ db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port);
+ /* include additional modules */
++include_once($config["library_path"] . "/functions.php");
++include_once($config["include_path"] . "/global_constants.php");
++include_once($config["library_path"] . "/plugins.php");
++include_once($config["include_path"] . "/plugins.php");
++include_once($config["include_path"] . "/global_arrays.php");
++include_once($config["include_path"] . "/global_settings.php");
+ include_once($config["include_path"] . "/global_form.php");
+ include_once($config["library_path"] . "/html.php");
+ include_once($config["library_path"] . "/html_form.php");
+@@ -205,6 +214,8 @@
+ include_once($config["library_path"] . "/variables.php");
+ include_once($config["library_path"] . "/auth.php");
++api_plugin_hook("config_insert");
++
+ /* current cacti version */
+ $config["cacti_version"] = "0.8.7g";
+diff -Naur cacti-0.8.7g/include/global_settings.php cacti-0.8.7g-PA-v2.9/include/global_settings.php
+--- cacti-0.8.7g/include/global_settings.php   2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/global_settings.php   2010-10-17 20:09:52.000000000 -0400
+@@ -1190,4 +1190,6 @@
+               )
+       );
++api_plugin_hook('config_settings');
++
+ ?>
+diff -Naur cacti-0.8.7g/include/plugins.php cacti-0.8.7g-PA-v2.9/include/plugins.php
+--- cacti-0.8.7g/include/plugins.php   1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/include/plugins.php   2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,43 @@
++<?php
++
++/*
++ * Copyright (c) 1999-2005 The SquirrelMail Project Team (http://squirrelmail.org)
++ * Licensed under the GNU GPL. For full terms see the file COPYING.
++ */
++
++global $plugin_hooks, $plugins_system, $plugins;
++$plugin_hooks = array();
++$plugins_system = array('settings', 'boost', 'dsstats');
++
++function use_plugin ($name) {
++      global $config;
++      if (file_exists($config['base_path'] . "/plugins/$name/setup.php")) {
++              include_once($config['base_path'] . "/plugins/$name/setup.php");
++              $function = "plugin_init_$name";
++              if (function_exists($function)) {
++                      $function();
++              }
++      }
++}
++
++/**
++ * This function executes a hook.
++ * @param string $name Name of hook to fire
++ * @return mixed $data
++ */
++if (!is_array($plugins)) {
++      $plugins = array();
++}
++
++$oldplugins = read_config_option('oldplugins');
++if (strlen(trim($oldplugins))) {
++      $oldplugins = explode(',', $oldplugins);
++      $plugins    = array_merge($plugins, $oldplugins);
++}
++
++/* On startup, register all plugins configured for use. */
++if (isset($plugins) && is_array($plugins)) {
++      foreach ($plugins as $name) {
++              use_plugin($name);
++      }
++}
+diff -Naur cacti-0.8.7g/include/top_graph_header.php cacti-0.8.7g-PA-v2.9/include/top_graph_header.php
+--- cacti-0.8.7g/include/top_graph_header.php  2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/top_graph_header.php  2010-10-17 20:09:52.000000000 -0400
+@@ -25,6 +25,8 @@
+ $using_guest_account = false;
+ $show_console_tab = true;
++$oper_mode = api_plugin_hook_function('top_header', OPER_MODE_NATIVE);
++
+ /* ================= input validation ================= */
+ input_validate_input_number(get_request_var_request("local_graph_id"));
+ input_validate_input_number(get_request_var_request("graph_start"));
+@@ -52,49 +54,62 @@
+       $_SESSION["sess_nav_level_cache"][2]["url"] = "graph.php?local_graph_id=" . $_REQUEST["local_graph_id"] . "&rra_id=all";
+ }
++$page_title = api_plugin_hook_function('page_title', draw_navigation_text("title"));
++
+ ?>
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+ <html>
+ <head>
+-      <title><?php echo draw_navigation_text("title");?></title>
++      <title><?php echo $page_title; ?></title>
+       <?php
+       if (isset($_SESSION["custom"]) && $_SESSION["custom"] == true) {
+               print "<meta http-equiv=refresh content='99999'>\r\n";
+       }else{
+-              print "<meta http-equiv=refresh content='" . htmlspecialchars(read_graph_config_option("page_refresh"),ENT_QUOTES) . "'>\r\n";
++              $refresh = api_plugin_hook_function('top_graph_refresh', htmlspecialchars(read_graph_config_option("page_refresh"),ENT_QUOTES));
++              print "<meta http-equiv=refresh content='" . $refresh . "'>\r\n";
+       }
+       ?>
+       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+-      <link href="include/main.css" type="text/css" rel="stylesheet">
+-      <link href="images/favicon.ico" rel="shortcut icon"/>
+-      <script type="text/javascript" src="include/layout.js"></script>
+-      <script type="text/javascript" src="include/treeview/ua.js"></script>
+-      <script type="text/javascript" src="include/treeview/ftiens4.js"></script>
+-      <script type="text/javascript" src="include/jscalendar/calendar.js"></script>
+-      <script type="text/javascript" src="include/jscalendar/lang/calendar-en.js"></script>
+-      <script type="text/javascript" src="include/jscalendar/calendar-setup.js"></script>
++      <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
++      <link href="<?php echo $config['url_path']; ?>images/favicon.ico" rel="shortcut icon"/>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/layout.js"></script>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/treeview/ua.js"></script>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/treeview/ftiens4.js"></script>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar.js"></script>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/lang/calendar-en.js"></script>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar-setup.js"></script>
++      <?php api_plugin_hook('page_head'); ?>
+ </head>
+-<body>
++<?php if ($oper_mode == OPER_MODE_NATIVE) {?>
++<body <?php print api_plugin_hook_function("body_style", "");?>>
+ <a name='page_top'></a>
++<?php }else{?>
++<body <?php print api_plugin_hook_function("body_style", "");?>>
++<?php }?>
++
+ <table style="width:100%;height:100%;" cellspacing="0" cellpadding="0">
++<?php if ($oper_mode == OPER_MODE_NATIVE) { ;?>
+       <tr style="height:25px;" bgcolor="#a9a9a9" class="noprint">
+               <td colspan="2" valign="bottom" nowrap>
+                       <table width="100%" cellspacing="0" cellpadding="0">
+-                              <tr style="background: transparent url('images/cacti_backdrop2.gif') no-repeat center right;">
++                              <tr style="background: transparent url('<?php echo $config['url_path']; ?>images/cacti_backdrop2.gif') no-repeat center right;">
+                                       <td id="tabs" nowrap>
+-                                              &nbsp;<?php if ($show_console_tab == true) {?><a href="index.php"><img src="images/tab_console.gif" alt="Console" align="absmiddle" border="0"></a><?php }?><a href="graph_view.php"><img src="images/tab_graphs<?php if ((substr(basename($_SERVER["PHP_SELF"]),0,5) == "graph") || (basename($_SERVER["PHP_SELF"]) == "graph_settings.php")) { print "_down"; } print ".gif";?>" alt="Graphs" align="absmiddle" border="0"></a>&nbsp;
++                                              &nbsp;<?php if ($show_console_tab == true) {?><a href="<?php echo $config['url_path']; ?>index.php"><img src="<?php echo $config['url_path']; ?>images/tab_console.gif" alt="Console" align="absmiddle" border="0"></a><?php }?><a href="<?php echo $config['url_path']; ?>graph_view.php"><img src="<?php echo $config['url_path']; ?>images/tab_graphs<?php if ((substr(basename($_SERVER["PHP_SELF"]),0,5) == "graph") || (basename($_SERVER["PHP_SELF"]) == "graph_settings.php")) { print "_down"; } print ".gif";?>" alt="Graphs" align="absmiddle" border="0"></a><?php
++                                              api_plugin_hook('top_graph_header_tabs');
++                                              ?>
+                                       </td>
+                                       <td id="gtabs" align="right" nowrap>
+-                                              <?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["graph_settings"] == "on")) { print '<a href="graph_settings.php"><img src="images/tab_settings'; if (basename($_SERVER["PHP_SELF"]) == "graph_settings.php") { print "_down"; } print '.gif" border="0" alt="Settings" align="absmiddle"></a>';}?>&nbsp;&nbsp;<?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["show_tree"] == "on")) {?><a href="<?php print htmlspecialchars("graph_view.php?action=tree");?>"><img src="images/tab_mode_tree<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "tree") { print "_down"; }?>.gif" border="0" title="Tree View" alt="Tree View" align="absmiddle"></a><?php }?><?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["show_list"] == "on")) {?><a href="graph_view.php?action=list"><img src="images/tab_mode_list<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "list") { print "_down"; }?>.gif" border="0" title="List View" alt="List View" align="absmiddle"></a><?php }?><?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["show_preview"] == "on")) {?><a href="graph_view.php?action=preview"><img src="images/tab_mode_preview<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "preview") { print "_down"; }?>.gif" border="0" title="Preview View" alt="Preview View" align="absmiddle"></a><?php }?>&nbsp;<br>
++                                              <?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["graph_settings"] == "on")) { print '<a href="' . $config['url_path'] . 'graph_settings.php"><img src="' . $config['url_path'] . 'images/tab_settings'; if (basename($_SERVER["PHP_SELF"]) == "graph_settings.php") { print "_down"; } print '.gif" border="0" alt="Settings" align="absmiddle"></a>';}?>&nbsp;&nbsp;<?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["show_tree"] == "on")) {?><a href="<?php print htmlspecialchars($config['url_path'] . "graph_view.php?action=tree");?>"><img src="<?php echo $config['url_path']; ?>images/tab_mode_tree<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "tree") { print "_down"; }?>.gif" border="0" title="Tree View" alt="Tree View" align="absmiddle"></a><?php }?><?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["show_list"] == "on")) {?><a href="<?php print htmlspecialchars($config['url_path'] . "graph_view.php?action=list");?>"><img src="<?php echo $config['url_path']; ?>images/tab_mode_list<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "list") { print "_down"; }?>.gif" border="0" title="List View" alt="List View" align="absmiddle"></a><?php }?><?php if ((!isset($_SESSION["sess_user_id"])) || ($current_user["show_preview"] == "on")) {?><a href="<?php print htmlspecialchars($config['url_path'] . "graph_view.php?action=preview");?>"><img src="<?php echo $config['url_path']; ?>images/tab_mode_preview<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "preview") { print "_down"; }?>.gif" border="0" title="Preview View" alt="Preview View" align="absmiddle"></a><?php }?>&nbsp;<br>
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
++<?php } elseif ($oper_mode == OPER_MODE_NOTABS) { api_plugin_hook_function('print_top_header'); } ?>
+       <tr style="height:2px;" bgcolor="#183c8f" class="noprint">
+               <td colspan="2">
+-                      <img src="images/transparent_line.gif" style="height:2px;width:170px;" border="0"><br>
++                      <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:2px;width:170px;" border="0"><br>
+               </td>
+       </tr>
+       <tr style="height:5px;" bgcolor="#e9e9e9" class="noprint">
+@@ -106,7 +121,7 @@
+                                       </td>
+                                       <td align="right">
+                                               <?php if ((isset($_SESSION["sess_user_id"])) && ($using_guest_account == false)) { ?>
+-                                              Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="logout.php">Logout</a>)&nbsp;
++                                              Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="<?php echo $config['url_path']; ?>logout.php">Logout</a>)&nbsp;
+                                               <?php } ?>
+                                       </td>
+                               </tr>
+@@ -114,10 +129,10 @@
+               </td>
+       </tr>
+       <tr class="noprint">
+-              <td bgcolor="#efefef" colspan="1" style="height:8px;background-image: url(images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;">
+-                      <img src="images/transparent_line.gif" width="<?php print htmlspecialchars(read_graph_config_option("default_dual_pane_width"));?>" style="height:2px;" border="0"><br>
++              <td bgcolor="#efefef" colspan="1" style="height:8px;background-image: url(<?php echo $config['url_path']; ?>images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;">
++                      <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" width="<?php print htmlspecialchars(read_graph_config_option("default_dual_pane_width"));?>" style="height:2px;" border="0"><br>
+               </td>
+-              <td bgcolor="#ffffff" colspan="1" style="height:8px;background-image: url(images/shadow.gif); background-repeat: repeat-x;">
++              <td bgcolor="#ffffff" colspan="1" style="height:8px;background-image: url(<?php echo $config['url_path']; ?>images/shadow.gif); background-repeat: repeat-x;">
+               </td>
+       </tr>
+@@ -143,6 +158,8 @@
+               </td>
+       </tr>
+       <?php }
++
++      global $graph_views;
+       load_current_session_value("action", "sess_cacti_graph_action", $graph_views[read_graph_config_option("default_tree_view_mode")]);
+       ?>
+       <tr>
+diff -Naur cacti-0.8.7g/include/top_header.php cacti-0.8.7g-PA-v2.9/include/top_header.php
+--- cacti-0.8.7g/include/top_header.php        2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/include/top_header.php        2010-10-17 20:09:52.000000000 -0400
+@@ -22,38 +22,53 @@
+  +-------------------------------------------------------------------------+
+ */
+-global $colors;
++global $colors, $config;
++
++$oper_mode = api_plugin_hook_function('top_header', OPER_MODE_NATIVE);
++if ($oper_mode == OPER_MODE_RESKIN || $oper_mode == OPER_MODE_NOTABS) {
++      return;
++}
++
++$page_title = api_plugin_hook_function('page_title', draw_navigation_text("title"));
++
+ ?>
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+ <html>
+ <head>
+-      <title><?php echo draw_navigation_text("title");?></title>
+-      <link href="include/main.css" type="text/css" rel="stylesheet">
+-      <link href="images/favicon.ico" rel="shortcut icon"/>
++      <title><?php echo $page_title; ?></title>
++      <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
++      <link href="<?php echo $config['url_path']; ?>images/favicon.ico" rel="shortcut icon">
+       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+-      <script type="text/javascript" src="include/layout.js"></script>
++      <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/layout.js"></script>
+       <?php if (isset($refresh)) {
+       print "<meta http-equiv=refresh content=\"" . $refresh["seconds"] . "; url='" . $refresh["page"] . "'\">";
+-      }?>
++      }
++      api_plugin_hook('page_head'); ?>
+ </head>
+-<body style="background-image:url('images/left_border.gif');background-repeat:repeat-y;">
++<?php if ($oper_mode == OPER_MODE_NATIVE) {?>
++<body style="background-image:url('<?php print $config['url_path'];?>images/left_border.gif');background-repeat:repeat-y;" <?php print api_plugin_hook_function("body_style", "");?>>
++<?php }else{?>
++<body style="background-image:url('<?php print $config['url_path'];?>images/left_border.gif');background-repeat:repeat-y;" <?php print api_plugin_hook_function("body_style", "");?>>
++<?php }?>
+ <table width="100%" cellspacing="0" cellpadding="0">
++<?php if ($oper_mode == OPER_MODE_NATIVE) { ;?>
+       <tr style="height:1px;" bgcolor="#a9a9a9">
+               <td valign="bottom" colspan="3" nowrap>
+                       <table width="100%" cellspacing="0" cellpadding="0">
+-                              <tr style="background: transparent url('images/cacti_backdrop.gif') no-repeat center right;">
++                              <tr style="background: transparent url('<?php echo $config['url_path']; ?>images/cacti_backdrop.gif') no-repeat center right;">
+                                       <td id="tabs" valign="bottom">
+-                                              &nbsp;<a href="index.php"><img src="images/tab_console_down.gif" alt="Console" align="absmiddle" border="0"></a><a href="graph_view.php"><img src="images/tab_graphs.gif" alt="Graphs" align="absmiddle" border="0"></a>
+-                                      </td>
++                                              &nbsp;<a href="<?php echo $config['url_path']; ?>index.php"><img src="<?php echo $config['url_path']; ?>images/tab_console_down.gif" alt="Console" align="absmiddle" border="0"></a><a href="<?php echo $config['url_path']; ?>graph_view.php"><img src="<?php echo $config['url_path']; ?>images/tab_graphs.gif" alt="Graphs" align="absmiddle" border="0"></a><?php
++                                              api_plugin_hook('top_header_tabs');
++                                      ?></td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
+       <tr style="height:2px;" bgcolor="#183c8f">
+               <td colspan="3">
+-                      <img src="images/transparent_line.gif" style="height:2px;" border="0"><br>
++                      <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:2px;" border="0"><br>
+               </td>
+       </tr>
+       <tr style="height:5px;" bgcolor="#e9e9e9">
+@@ -65,7 +80,7 @@
+                                       </td>
+                                       <td align="right">
+                                               <?php if (read_config_option("auth_method") != 0) { ?>
+-                                              Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="logout.php">Logout</a>)&nbsp;
++                                              Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="<?php echo $config['url_path']; ?>logout.php">Logout</a>)&nbsp;
+                                               <?php } ?>
+                                       </td>
+                               </tr>
+@@ -73,10 +88,10 @@
+               </td>
+       </tr>
+       <tr>
+-              <td bgcolor="#f5f5f5" colspan="1" style="height:8px;width:135px;background-image: url(images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;">
+-                      <img src="images/transparent_line.gif" style="height:2px;width:135px;" border="0"><br>
++              <td bgcolor="#f5f5f5" colspan="1" style="height:8px;width:135px;background-image: url(<?php echo $config['url_path']; ?>images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;">
++                      <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:2px;width:135px;" border="0"><br>
+               </td>
+-              <td colspan="2" style="height:8px;background-image: url(images/shadow.gif); background-repeat: repeat-x;" bgcolor="#ffffff">
++              <td colspan="2" style="height:8px;background-image: url(<?php echo $config['url_path']; ?>images/shadow.gif); background-repeat: repeat-x;" bgcolor="#ffffff">
+               </td>
+       </tr>
+@@ -86,9 +101,12 @@
+                               <?php draw_menu();?>
+                       </table>
+-                      <img src="images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
+-                      <p align="center"><a href='about.php'><img src="images/cacti_logo.gif" border="0"></a></p>
+-                      <img src="images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
++                      <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
++                      <p align="center"><a href='<?php echo $config['url_path']; ?>about.php'><img src="<?php echo $config['url_path']; ?>images/cacti_logo.gif" border="0"></a></p>
++                      <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
+               </td>
+               <td width="100%" colspan="2" valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;"><?php display_output_messages();?><div style='position:relative;' id='main'>
+-
++<?php }else{ ?>
++      <tr>
++              <td width="100%" valign="top"><?php display_output_messages();?>
++<?php } ?>
+diff -Naur cacti-0.8.7g/index.php cacti-0.8.7g-PA-v2.9/index.php
+--- cacti-0.8.7g/index.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/index.php     2010-10-17 20:09:52.000000000 -0400
+@@ -25,6 +25,8 @@
+ include("./include/auth.php");
+ include("./include/top_header.php");
++api_plugin_hook('console_before');
++
+ ?>
+ <table width="100%" align="center">
+       <tr>
+@@ -46,6 +48,8 @@
+ <?php
++api_plugin_hook('console_after');
++
+ include("./include/bottom_footer.php");
+ ?>
+diff -Naur cacti-0.8.7g/lib/api_automation_tools.php cacti-0.8.7g-PA-v2.9/lib/api_automation_tools.php
+--- cacti-0.8.7g/lib/api_automation_tools.php  2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/api_automation_tools.php  2010-10-17 20:09:52.000000000 -0400
+@@ -22,117 +22,6 @@
+  +-------------------------------------------------------------------------+
+  */
+-function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id,
+-      $title, $local_graph_id, $rra_id, $host_id, $host_grouping_type,
+-      $sort_children_type, $propagate_changes) {
+-
+-      global $config;
+-
+-      include_once($config["library_path"] . "/tree.php");
+-
+-      $parent_order_key = db_fetch_cell("select order_key from graph_tree_items where id=$parent_tree_item_id");
+-
+-      /* fetch some cache variables */
+-      if (empty($id)) {
+-              /* new/save - generate new order key */
+-              $order_key = get_next_tree_id($parent_order_key, "graph_tree_items", "order_key", "graph_tree_id=$tree_id");
+-      }else{
+-              /* edit/save - use old order_key */
+-              $order_key = db_fetch_cell("select order_key from graph_tree_items where id=$id");
+-      }
+-
+-      /* duplicate graph check */
+-      $search_key = substr($parent_order_key, 0, (tree_tier($parent_order_key) * CHARS_PER_TIER));
+-      if (($type == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='$local_graph_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
+-              return db_fetch_cell("select id from graph_tree_items where local_graph_id='$local_graph_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'");
+-      }
+-
+-      /* Duplicate header check */
+-      if (($type == TREE_ITEM_TYPE_HEADER)) {
+-              if ((sizeof(db_fetch_assoc("select id from graph_tree_items where title='$title' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
+-                      return db_fetch_cell("select id from graph_tree_items where title='$title' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'");
+-              }
+-      }
+-
+-      $save["id"]                 = $id;
+-      $save["graph_tree_id"]      = $tree_id;
+-      $save["title"]              = form_input_validate($title, "title", "", ($type == TREE_ITEM_TYPE_HEADER ? false : true), 3);
+-      $save["order_key"]          = $order_key;
+-      $save["local_graph_id"]     = form_input_validate($local_graph_id, "local_graph_id", "", true, 3);
+-      $save["rra_id"]             = form_input_validate($rra_id, "rra_id", "", true, 3);
+-      $save["host_id"]            = form_input_validate($host_id, "host_id", "", true, 3);
+-      $save["host_grouping_type"] = form_input_validate($host_grouping_type, "host_grouping_type", "", true, 3);
+-      $save["sort_children_type"] = form_input_validate($sort_children_type, "sort_children_type", "", true, 3);
+-
+-      $tree_item_id = 0;
+-
+-      if (!is_error_message()) {
+-              $tree_item_id = sql_save($save, "graph_tree_items");
+-
+-              if ($tree_item_id) {
+-                      raise_message(1);
+-
+-                      /* re-parent the branch if the parent item has changed */
+-                      if ($parent_tree_item_id != $tree_item_id) {
+-                              reparent_branch($parent_tree_item_id, $tree_item_id);
+-                      }
+-
+-                      $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='$tree_id'");
+-
+-                      /* tree item ordering */
+-                      if ($tree_sort_type == TREE_ORDERING_NONE) {
+-                              /* resort our parent */
+-                              $parent_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=$parent_tree_item_id");
+-
+-                              if ((!empty($parent_tree_item_id)) && ($parent_sorting_type != TREE_ORDERING_NONE)) {
+-                                      sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $parent_sorting_type);
+-                              }
+-
+-                              /* if this is a header, sort direct children */
+-                              if (($type == TREE_ITEM_TYPE_HEADER) && ($sort_children_type != TREE_ORDERING_NONE)) {
+-                                      sort_tree(SORT_TYPE_TREE_ITEM, $tree_item_id, $sort_children_type);
+-                              }
+-                              /* tree ordering */
+-                      }else{
+-                              /* potential speed savings for large trees */
+-                              if (tree_tier($save["order_key"]) == 1) {
+-                                      sort_tree(SORT_TYPE_TREE, $tree_id, $tree_sort_type);
+-                              }else{
+-                                      sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $tree_sort_type);
+-                              }
+-                      }
+-
+-                      /* if the user checked the 'Propagate Changes' box */
+-                      if (($type == TREE_ITEM_TYPE_HEADER) && ($propagate_changes == true)) {
+-                              $search_key = preg_replace("/0+$/", "", $order_key);
+-
+-                              $tree_items = db_fetch_assoc("select
+-                                      graph_tree_items.id
+-                                      from graph_tree_items
+-                                      where graph_tree_items.host_id = 0
+-                                      and graph_tree_items.local_graph_id = 0
+-                                      and graph_tree_items.title != ''
+-                                      and graph_tree_items.order_key like '$search_key%%'
+-                                      and graph_tree_items.graph_tree_id='$tree_id'");
+-
+-                              if (sizeof($tree_items) > 0) {
+-                                      foreach ($tree_items as $item) {
+-                                              db_execute("update graph_tree_items set sort_children_type = '$sort_children_type' where id = '" . $item["id"] . "'");
+-
+-                                              if ($sort_children_type != TREE_ORDERING_NONE) {
+-                                                      sort_tree(SORT_TYPE_TREE_ITEM, $item["id"], $sort_children_type);
+-                                              }
+-                                      }
+-                              }
+-                      }
+-              }else{
+-                      raise_message(2);
+-              }
+-      }
+-
+-      return $tree_item_id;
+-}
+-
+ function getHostTemplates() {
+       $tmpArray = db_fetch_assoc("select id, name from host_template order by id");
+diff -Naur cacti-0.8.7g/lib/api_device.php cacti-0.8.7g-PA-v2.9/lib/api_device.php
+--- cacti-0.8.7g/lib/api_device.php    2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/api_device.php    2010-10-17 20:09:52.000000000 -0400
+@@ -137,6 +137,8 @@
+       $save["ping_retries"]         = form_input_validate($ping_retries, "ping_retries", "^[0-9]+$", true, 3);
+       $save["max_oids"]             = form_input_validate($max_oids, "max_oids", "^[0-9]+$", true, 3);
++      $save = api_plugin_hook_function('api_device_save', $save);
++
+       $host_id = 0;
+       if (!is_error_message()) {
+@@ -176,11 +178,16 @@
+                       if (sizeof($graph_templates) > 0) {
+                       foreach ($graph_templates as $graph_template) {
+                               db_execute("replace into host_graph (host_id,graph_template_id) values ($host_id," . $graph_template["graph_template_id"] . ")");
++                              api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $host_id, "graph_template_id" => $graph_template["graph_template_id"]));
+                       }
+                       }
+               }
+       }
++      # now that we have the id of the new host, we may plugin postprocessing code
++      $save["id"] = $host_id;
++      api_plugin_hook_function('api_device_new', $save);
++
+       return $host_id;
+ }
+diff -Naur cacti-0.8.7g/lib/api_graph.php cacti-0.8.7g-PA-v2.9/lib/api_graph.php
+--- cacti-0.8.7g/lib/api_graph.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/api_graph.php     2010-10-17 20:09:52.000000000 -0400
+@@ -82,7 +82,7 @@
+ }
+ /* api_reapply_suggested_graph_title - reapplies the suggested name to a graph title
+-   @arg $graph_templates_graph_id - the id of the graph to reapply the name to
++   @param int $graph_templates_graph_id - the id of the graph to reapply the name to
+ */
+ function api_reapply_suggested_graph_title($local_graph_id) {
+       global $config;
+@@ -95,11 +95,21 @@
+               return;
+       }
+-      /* get the host associated with this graph */
+-      $graph_local = db_fetch_row("select host_id, graph_template_id, snmp_query_id, snmp_index from graph_local where id=" . $local_graph_id);
++      /* get the host associated with this graph for data queries only
++       * there's no "reapply suggested title" for "simple" graph templates */
++      $graph_local = db_fetch_row("select host_id, graph_template_id, snmp_query_id, snmp_index from graph_local where snmp_query_id>0 AND id=" . $local_graph_id);
++      /* if this is not a data query graph, simply return */
++      if (!isset($graph_local["host_id"])) {
++              return;
++      }
+       $snmp_query_graph_id = db_fetch_cell("select id from snmp_query_graph where graph_template_id=" . $graph_local["graph_template_id"] .
+                                                                               " and snmp_query_id=" . $graph_local["snmp_query_id"]);
++      /* no snmp query graph id found */
++      if ($snmp_query_graph_id == 0) {
++              return;
++      }
++
+       /* get the suggested values from the suggested values cache */
+       $suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_sv where snmp_query_graph_id=" . $snmp_query_graph_id . " order by sequence");
+diff -Naur cacti-0.8.7g/lib/api_tree.php cacti-0.8.7g-PA-v2.9/lib/api_tree.php
+--- cacti-0.8.7g/lib/api_tree.php      2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/api_tree.php      2010-10-17 20:09:52.000000000 -0400
+@@ -44,8 +44,20 @@
+       /* duplicate graph check */
+       $search_key = substr($parent_order_key, 0, (tree_tier($parent_order_key) * CHARS_PER_TIER));
+-      if (($type == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='$local_graph_id' and rra_id='$rra_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
+-              return 0;
++      if (($type == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='$local_graph_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
++              return db_fetch_cell("select id from graph_tree_items where local_graph_id='$local_graph_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'");
++      }
++
++      /* Duplicate header check */
++      if (($type == TREE_ITEM_TYPE_HEADER)) {
++              if ((sizeof(db_fetch_assoc("select id from graph_tree_items where title='$title' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
++                      return db_fetch_cell("select id from graph_tree_items where title='$title' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'");
++              }
++      }
++
++      /* Duplicate host check */
++      if (($type == TREE_ITEM_TYPE_HOST) && (sizeof(db_fetch_assoc("select id from graph_tree_items where host_id='$host_id' and local_graph_id='$local_graph_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
++                      return db_fetch_cell("select id from graph_tree_items where host_id='$host_id' and local_graph_id='$local_graph_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'");
+       }
+       $save["id"] = $id;
+diff -Naur cacti-0.8.7g/lib/auth.php cacti-0.8.7g-PA-v2.9/lib/auth.php
+--- cacti-0.8.7g/lib/auth.php  2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/auth.php  2010-10-17 20:09:52.000000000 -0400
+@@ -121,8 +121,9 @@
+               }
+       }
+-      return true;
++      api_plugin_hook_function('copy_user', array('template_id' => $template_id, 'new_id' => $new_id));
++      return true;
+ }
+@@ -152,6 +153,7 @@
+       db_execute("delete from settings_graphs where user_id=" . $user_id);
+       db_execute("delete from settings_tree where user_id=" . $user_id);
++      api_plugin_hook_function('user_remove', $user_id);
+ }
+ /* user_disable - disable a user account
+diff -Naur cacti-0.8.7g/lib/data_query.php cacti-0.8.7g-PA-v2.9/lib/data_query.php
+--- cacti-0.8.7g/lib/data_query.php    2010-09-19 21:39:05.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/data_query.php    2010-10-17 20:09:52.000000000 -0400
+@@ -56,6 +56,8 @@
+       /* update the poller cache */
+       update_poller_cache_from_query($host_id, $snmp_query_id);
++      api_plugin_hook_function('run_data_query', array("host_id" => $host_id, "snmp_query_id" => $snmp_query_id));
++
+       return (isset($result) ? $result : true);
+ }
+@@ -215,7 +217,7 @@
+                               for ($i=0; $i<sizeof($snmp_indexes); $i++) {
+                                       $oid = $field_array["oid"] .  "." . $snmp_indexes[$i]["value"];
+                                       $oid .= isset($field_array["oid_suffix"]) ? ("." . $field_array["oid_suffix"]) : "";
+-                                      
++
+                                       $value = cacti_snmp_get($host["hostname"], $host["snmp_community"], $oid,
+                                               $host["snmp_version"], $host["snmp_username"], $host["snmp_password"],
+                                               $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
+diff -Naur cacti-0.8.7g/lib/functions.php cacti-0.8.7g-PA-v2.9/lib/functions.php
+--- cacti-0.8.7g/lib/functions.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/functions.php     2010-10-17 20:09:52.000000000 -0400
+@@ -1689,6 +1689,8 @@
+    @arg $type - (string) Either 'url' or 'title'
+    @returns (string> Either the navigation text or title */
+ function draw_navigation_text($type = "url") {
++      global $config;
++
+       $nav_level_cache = (isset($_SESSION["sess_nav_level_cache"]) ? $_SESSION["sess_nav_level_cache"] : array());
+       $nav = array(
+@@ -1701,8 +1703,8 @@
+               "graph.php:zoom" => array("title" => "Zoom", "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"),
+               "graph.php:properties" => array("title" => "Properties", "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"),
+               "graph_settings.php:" => array("title" => "Settings", "mapping" => "graph_view.php:", "url" => "graph_settings.php", "level" => "1"),
+-              "index.php:" => array("title" => "Console", "mapping" => "", "url" => "index.php", "level" => "0"),
+-              "index.php:login" => array("title" => "Console", "mapping" => "", "url" => "index.php", "level" => "0"),
++              "index.php:" => array("title" => "Console", "mapping" => "", "url" => $config['url_path'] . "index.php", "level" => "0"),
++              "index.php:login" => array("title" => "Console", "mapping" => "", "url" => $config['url_path'] . "index.php", "level" => "0"),
+               "graphs.php:" => array("title" => "Graph Management", "mapping" => "index.php:", "url" => "graphs.php", "level" => "1"),
+               "graphs.php:graph_edit" => array("title" => "(Edit)", "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"),
+               "graphs.php:graph_diff" => array("title" => "Change Graph Template", "mapping" => "index.php:,graphs.php:,graphs.php:graph_edit", "url" => "", "level" => "3"),
+@@ -1780,6 +1782,8 @@
+               "templates_import.php:" => array("title" => "Import Templates", "mapping" => "index.php:", "url" => "templates_import.php", "level" => "1"),
+               );
++      $nav =  api_plugin_hook_function('draw_navigation_text', $nav);
++
+       $current_page = basename($_SERVER["PHP_SELF"]);
+       input_validate_input_regex(get_request_var_request("action"), "^([a-zA-Z0-9_-]+)$");
+diff -Naur cacti-0.8.7g/lib/html_form.php cacti-0.8.7g-PA-v2.9/lib/html_form.php
+--- cacti-0.8.7g/lib/html_form.php     2010-09-19 21:39:05.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/html_form.php     2010-10-17 20:24:33.000000000 -0400
+@@ -1,4 +1,5 @@
+ <?php
++// $Id: html_form.php 2993 2010-10-14 14:30:36Z ladams $
+ /*
+  +-------------------------------------------------------------------------+
+  | Copyright (C) 2004-2010 The Cacti Group                                 |
+@@ -530,6 +531,13 @@
+               $form_previous_value = $form_default_value;
+       }
++      if (isset($_SESSION["sess_error_fields"])) {
++              if (!empty($_SESSION["sess_error_fields"][$form_name])) {
++                      $class .= (strlen($class) ? " ":"") . "txtErrorTextBox";
++                      unset($_SESSION["sess_error_fields"][$form_name]);
++              }
++      }
++
+       if (isset($_SESSION["sess_field_values"])) {
+               if (!empty($_SESSION["sess_field_values"][$form_name])) {
+                       $form_previous_value = $_SESSION["sess_field_values"][$form_name];
+@@ -722,11 +730,13 @@
+      on a confirmation form
+    @arg $cancel_url - the url to go to when the user clicks 'cancel'
+    @arg $action_url - the url to go to when the user clicks 'delete' */
+-function form_confirm_buttons($action_url, $cancel_url) { ?>
++function form_confirm_buttons($action_url, $cancel_url) {
++      global $config;
++      ?>
+       <tr>
+               <td bgcolor="#E1E1E1">
+-                      <input type='button' onClick='cactiReturnTo("<?php print $cancel_url;?>")' value='Cancel'>
+-                      <input type='submit' onClick='cactiReturnTo("<?php print $action_url;?>&confirm=true")' value='Delete'>
++                      <input type='button' onClick='cactiReturnTo("<?php print $config['url_path'] . $cancel_url;?>")' value='Cancel'>
++                      <input type='submit' onClick='cactiReturnTo("<?php print $config['url_path'] . $action_url;?>&confirm=true")' value='Delete'>
+               </td>
+       </tr>
+ <?php }
+diff -Naur cacti-0.8.7g/lib/html.php cacti-0.8.7g-PA-v2.9/lib/html.php
+--- cacti-0.8.7g/lib/html.php  2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/html.php  2010-10-17 20:09:52.000000000 -0400
+@@ -144,14 +144,15 @@
+                                       <table align='center' cellpadding='0'>
+                                               <tr>
+                                                       <td align='center'>
+-                                                              <div style="min-height: <?php echo (1.6 * $graph["height"]) . "px"?>;"><a href='<?php print htmlspecialchars("graph.php?action=view&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=all");?>'><img class='graphimage' id='graph_<?php print $graph["local_graph_id"] ?>' src='<?php print htmlspecialchars("graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0" . (($extra_url_args == "") ? "" : "&$extra_url_args"));?>' border='0' alt='<?php print htmlspecialchars($graph["title_cache"]);?>'></a></div>
++                                                              <div style="min-height: <?php echo (1.6 * $graph["height"]) . "px"?>;"><a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=view&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=all");?>'><img class='graphimage' id='graph_<?php print $graph["local_graph_id"] ?>' src='<?php print htmlspecialchars($config['url_path'] . "graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0" . (($extra_url_args == "") ? "" : "&$extra_url_args"));?>' border='0' alt='<?php print htmlspecialchars($graph["title_cache"]);?>'></a></div>
+                                                               <?php print (read_graph_config_option("show_graph_title") == "on" ? "<p style='font-size: 10;' align='center'><strong>" . htmlspecialchars($graph["title_cache"]) . "</strong></p>" : "");?>
+                                                       </td>
+                                                       <td valign='top' style='align: left; padding: 3px;' class='noprint'>
+-                                                              <a href='<?php print htmlspecialchars("graph.php?action=zoom&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&". $extra_url_args);?>'><img src='images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
+-                                                              <a href='<?php print htmlspecialchars("graph_xport.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
+-                                                              <a href='<?php print htmlspecialchars("graph.php?action=properties&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br>
+-                                                              <a href='#page_top'><img src='images/graph_page_top.gif' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
++                                                              <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=zoom&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&". $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
++                                                              <a href='<?php print htmlspecialchars($config['url_path'] . "graph_xport.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
++                                                              <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=properties&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br>
++                                                              <?php api_plugin_hook('graph_buttons', array('hook' => 'graphs_thumbnails', 'local_graph_id' => $graph['local_graph_id'], 'rra' =>  0, 'view_type' => 'view')); ?>
++                                                              <a href='#page_top'><img src='<?php print $config['url_path']; ?>images/graph_page_top.gif' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
+                                                       </td>
+                                               </tr>
+                                       </table>
+@@ -177,6 +178,7 @@
+    @arg $extra_url_args - extra arguments to append to the url
+    @arg $header - html to use as a header */
+ function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = "", $extra_url_args = "", $header = "") {
++      global $config;
+       $i = 0; $k = 0; $j = 0;
+       $num_graphs = sizeof($graph_array);
+@@ -268,14 +270,15 @@
+                               <table align='center' cellpadding='0'>
+                                       <tr>
+                                               <td align='center'>
+-                                                      <div style="min-height: <?php echo (1.6 * read_graph_config_option("default_height")) . "px"?>;"><a href='<?php print htmlspecialchars("graph.php?action=view&rra_id=all&local_graph_id=" . $graph["local_graph_id"]);?>'><img class='graphimage' id='graph_<?php print $graph["local_graph_id"] ?>' src='<?php print htmlspecialchars("graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&graph_height=" . read_graph_config_option("default_height") . "&graph_width=" . read_graph_config_option("default_width") . "&graph_nolegend=true" . (($extra_url_args == "") ? "" : "&$extra_url_args"));?>' border='0' alt='<?php print htmlspecialchars($graph["title_cache"]);?>'></a></div>
++                                                      <div style="min-height: <?php echo (1.6 * read_graph_config_option("default_height")) . "px"?>;"><a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=view&rra_id=all&local_graph_id=" . $graph["local_graph_id"]);?>'><img class='graphimage' id='graph_<?php print $graph["local_graph_id"] ?>' src='<?php print htmlspecialchars($config["url_path"] . "graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&graph_height=" . read_graph_config_option("default_height") . "&graph_width=" . read_graph_config_option("default_width") . "&graph_nolegend=true" . (($extra_url_args == "") ? "" : "&$extra_url_args"));?>' border='0' alt='<?php print htmlspecialchars($graph["title_cache"]);?>'></a></div>
+                                                       <?php print (read_graph_config_option("show_graph_title") == "on" ? "<p style='font-size: 10;' align='center'><strong>" . htmlspecialchars($graph["title_cache"]) . "</strong></p>" : "");?>
+                                               </td>
+                                               <td valign='top' style='align: left; padding: 3px;'>
+-                                                      <a href='<?php print htmlspecialchars("graph.php?action=zoom&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
+-                                                      <a href='<?php print htmlspecialchars("graph_xport.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
+-                                                      <a href='<?php print htmlspecialchars("graph.php?action=properties&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br>
+-                                                      <a href='#page_top'><img src='images/graph_page_top.gif' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
++                                                      <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=zoom&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br>
++                                                      <a href='<?php print htmlspecialchars($config['url_path'] . "graph_xport.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br>
++                                                      <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=properties&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args);?>'><img src='<?php print $config['url_path'];?>images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br>
++                                                      <?php api_plugin_hook('graph_buttons_thumbnails', array('hook' => 'graphs_thumbnails', 'local_graph_id' => $graph['local_graph_id'], 'rra' =>  0, 'view_type' => '')); ?>
++                                                      <a href='#page_top'><img src='<?php print $config['url_path'] . "images/graph_page_top.gif";?>' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
+                                               </td>
+                                       </tr>
+                               </table>
+@@ -638,9 +641,9 @@
+               print "<td style='$this_row_style'>" . $item["hex"] . "</td>\n";
+               if ($disable_controls == false) {
+-                      print "<td><a href='" . htmlspecialchars("$filename?action=item_movedown&id=" . $item["id"] . "&$url_data") . "'><img src='images/move_down.gif' border='0' alt='Move Down'></a>
+-                                      <a href='" . htmlspecialchars("$filename?action=item_moveup&id=" . $item["id"] . "&$url_data") . "'><img src='images/move_up.gif' border='0' alt='Move Up'></a></td>\n";
+-                      print "<td align='right'><a href='" . htmlspecialchars("$filename?action=item_remove&id=" . $item["id"] . "&$url_data") . "'><img src='images/delete_icon.gif' style='height:10px;width:10px;' border='0' alt='Delete'></a></td>\n";
++                      print "<td><a href='" . htmlspecialchars("$filename?action=item_movedown&id=" . $item["id"] . "&$url_data") . "'><img src='" . $config['url_path'] . "images/move_down.gif' border='0' alt='Move Down'></a>
++                                      <a href='" . htmlspecialchars("$filename?action=item_moveup&id=" . $item["id"] . "&$url_data") . "'><img src='" . $config['url_path'] . "images/move_up.gif' border='0' alt='Move Up'></a></td>\n";
++                      print "<td align='right'><a href='" . htmlspecialchars("$filename?action=item_remove&id=" . $item["id"] . "&$url_data") . "'><img src='" . $config['url_path'] . "images/delete_icon.gif' style='height:10px;width:10px;' border='0' alt='Delete'></a></td>\n";
+               }
+               print "</tr>";
+@@ -706,6 +709,8 @@
+                                       }
+                                       while (list($item_sub_url, $item_sub_title) = each($item_title)) {
++                                              $item_sub_url = $config['url_path'] . $item_sub_url;
++
+                                               /* indent sub-items */
+                                               if ($i > 0) {
+                                                       $prepend_string = "---&nbsp;";
+@@ -715,7 +720,7 @@
+                                               /* do not put a line between each sub-item */
+                                               if (($i == 0) || ($draw_sub_items == false)) {
+-                                                      $background = "images/menu_line.gif";
++                                                      $background = $config['url_path'] . "images/menu_line.gif";
+                                               }else{
+                                                       $background = "";
+                                               }
+@@ -744,17 +749,18 @@
+                       }else{
+                               if ($current_realm_id == -1 || (isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) {
+                                       /* draw normal (non sub-item) menu item */
++                                      $item_url = $config['url_path'] . $item_url;
+                                       if (basename($_SERVER["PHP_SELF"]) == basename($item_url)) {
+-                                              print "<tr><td class='textMenuItemSelected' style='background-image:url(\"images/menu_line.gif\");'><strong><a href='" . htmlspecialchars($item_url) . "'>$item_title</a></strong></td></tr>\n";
++                                              print "<tr><td class='textMenuItemSelected' style='background-image:url(\"" . $config['url_path'] . "images/menu_line.gif\");'><strong><a href='" . htmlspecialchars($item_url) . "'>$item_title</a></strong></td></tr>\n";
+                                       }else{
+-                                              print "<tr><td class='textMenuItem' style='background-image:url(\"images/menu_line.gif\");'><a href='" . htmlspecialchars($item_url) . "'>$item_title</a></td></tr>\n";
++                                              print "<tr><td class='textMenuItem' style='background-image:url(\"" . $config['url_path'] . "images/menu_line.gif\");'><a href='" . htmlspecialchars($item_url) . "'>$item_title</a></td></tr>\n";
+                                       }
+                               }
+                       }
+               }
+       }
+-      print "<tr><td class='textMenuItem' style='background-image:url(\"images/menu_line.gif\");'></td></tr>\n";
++      print "<tr><td class='textMenuItem' style='background-image:url(\"" . $config['url_path'] . "images/menu_line.gif\");'></td></tr>\n";
+       print "</table></td></tr>";
+ }
+@@ -764,11 +770,12 @@
+    @arg $actions_array - an array that contains a list of possible actions. this array should
+      be compatible with the form_dropdown() function */
+ function draw_actions_dropdown($actions_array) {
++      global $config;
+       ?>
+       <table align='center' width='100%'>
+               <tr>
+                       <td width='1' valign='top'>
+-                              <img src='images/arrow.gif' alt=''>&nbsp;
++                              <img src='<?php echo $config['url_path']; ?>images/arrow.gif' alt='' align='middle'>&nbsp;
+                       </td>
+                       <td align='right'>
+                               Choose an action:
+diff -Naur cacti-0.8.7g/lib/html_tree.php cacti-0.8.7g-PA-v2.9/lib/html_tree.php
+--- cacti-0.8.7g/lib/html_tree.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/html_tree.php     2010-10-17 20:09:52.000000000 -0400
+@@ -543,7 +543,7 @@
+       $dhtml_tree[0] = $start;
+       $dhtml_tree[1] = read_graph_config_option("expand_hosts");
+-      $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
++      $dhtml_tree[2] = "var foldersTree = gFld(\"\", \"\")\n";
+       $dhtml_tree[3] = "foldersTree.xID = \"root\"\n";
+       $i = 3;
+@@ -985,6 +985,16 @@
+       <?php
+       html_end_box();
++      do_hook_function('graph_tree_page_buttons',
++              array(
++                      'treeid' => $tree_id,
++                      'leafid' => $leaf_id,
++                      'mode' => 'tree',
++                      'timespan' => $_SESSION["sess_current_timespan"],
++                      'starttime' => get_current_graph_start(),
++                      'endtime' => get_current_graph_end())
++      );
++
+       html_start_box("", "100%", $colors["header"], "3", "center", "");
+       $graph_list = array();
+@@ -1189,6 +1199,19 @@
+               html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
+       }
++
++      /* nmid start */
++      if (!empty($leaf_id)) {
++              do_hook_function('tree_after',$host_name.','.get_request_var("leaf_id"));
++      }
++
++        //print '</div>';
++        //print "</td></tr>";
++
++      do_hook_function('tree_view_page_end');
++
++      /* nmid end */
++
+       print $nav;
+       html_end_box();
+diff -Naur cacti-0.8.7g/lib/plugins.php cacti-0.8.7g-PA-v2.9/lib/plugins.php
+--- cacti-0.8.7g/lib/plugins.php       1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/lib/plugins.php       2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,478 @@
++<?php
++
++
++
++function do_hook ($name) {
++      $data = func_get_args();
++      $data = api_plugin_hook ($name, $data);
++      return $data;
++}
++
++function do_hook_function($name,$parm=NULL) {
++      return api_plugin_hook_function ($name, $parm);
++}
++
++function api_user_realm_auth ($filename = '') {
++      return api_plugin_user_realm_auth ($filename);
++}
++
++/**
++ * This function executes a hook.
++ * @param string $name Name of hook to fire
++ * @return mixed $data
++ */
++function api_plugin_hook ($name) {
++      global $config, $plugin_hooks, $plugins_system;
++      $data = func_get_args();
++      $ret = '';
++      $p = array();
++
++      $ps_where = '';
++      if (sizeof($plugins_system)) {
++              foreach($plugins_system as $plugin) {
++                      $ps_where .= (strlen($ps_where) ? "', '":"('") . $plugin;
++              }
++              $ps_where .= "')";
++      }
++
++      /* order the plugin functions by system first, then followed by order */
++      $result = db_fetch_assoc("SELECT 1 AS id, ph.name, ph.file, ph.function
++              FROM plugin_hooks AS ph
++              LEFT JOIN plugin_config AS pc
++              ON pc.directory=ph.name
++              WHERE ph.status = 1 AND hook = '$name'
++              AND ph.name IN $ps_where
++              UNION
++              SELECT pc.id, ph.name, ph.file, ph.function
++              FROM plugin_hooks AS ph
++              LEFT JOIN plugin_config AS pc
++              ON pc.directory=ph.name
++              WHERE ph.status = 1 AND hook = '$name'
++              AND ph.name NOT IN $ps_where
++              ORDER BY id ASC", true);
++
++      if (count($result)) {
++              foreach ($result as $hdata) {
++                      $p[] = $hdata['name'];
++                      if (file_exists($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file'])) {
++                              include_once($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file']);
++                      }
++                      $function = $hdata['function'];
++                      if (function_exists($function)) {
++                              $function($data);
++                      }
++              }
++      }
++
++      if (isset($plugin_hooks[$name]) && is_array($plugin_hooks[$name])) {
++              foreach ($plugin_hooks[$name] as $pname => $function) {
++                      if (function_exists($function)  && !function_exists('plugin_' . $pname . '_install') && !in_array($pname, $p)) {
++                              $function($data);
++                      }
++              }
++      }
++
++      /* Variable-length argument lists have a slight problem when */
++      /* passing values by reference. Pity. This is a workaround.  */
++      return $data;
++}
++
++function api_plugin_hook_function ($name, $parm=NULL) {
++      global $config, $plugin_hooks, $plugins_system;
++      $ret = $parm;
++      $p = array();
++      $ps_where = '';
++
++      if (sizeof($plugins_system)) {
++              foreach($plugins_system as $plugin) {
++                      $ps_where .= (strlen($ps_where) ? "', '":"('") . $plugin;
++              }
++              $ps_where .= "')";
++      }
++
++      /* order the plugin functions by system first, then followed by order */
++      $result = db_fetch_assoc("SELECT 1 AS id, ph.name, ph.file, ph.function
++              FROM plugin_hooks AS ph
++              LEFT JOIN plugin_config AS pc
++              ON pc.directory=ph.name
++              WHERE ph.status = 1 AND hook = '$name'
++              AND ph.name IN $ps_where
++              UNION
++              SELECT pc.id, ph.name, ph.file, ph.function
++              FROM plugin_hooks AS ph
++              LEFT JOIN plugin_config AS pc
++              ON pc.directory=ph.name
++              WHERE ph.status = 1 AND hook = '$name'
++              AND ph.name NOT IN $ps_where
++              ORDER BY id ASC", true);
++
++      if (count($result)) {
++              foreach ($result as $hdata) {
++                      $p[] = $hdata['name'];
++                      if (file_exists($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file'])) {
++                              include_once($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file']);
++                      }
++                      $function = $hdata['function'];
++                      if (function_exists($function)) {
++                              $ret = $function($ret);
++                      }
++              }
++      }
++
++      if (isset($plugin_hooks[$name]) && is_array($plugin_hooks[$name])) {
++              foreach ($plugin_hooks[$name] as $pname => $function) {
++                      if (function_exists($function)  && !function_exists('plugin_' . $pname . '_install') && !in_array($pname, $p)) {
++                              $ret = $function($ret);
++                      }
++              }
++      }
++
++      /* Variable-length argument lists have a slight problem when */
++      /* passing values by reference. Pity. This is a workaround.  */
++      return $ret;
++}
++
++function api_plugin_db_table_create ($plugin, $table, $data) {
++      global $config, $database_default;
++      include_once($config["library_path"] . "/database.php");
++
++      $result = db_fetch_assoc("show tables from `" . $database_default . "`") or die (mysql_error());
++      $tables = array();
++      foreach($result as $index => $arr) {
++              foreach ($arr as $t) {
++                      $tables[] = $t;
++              }
++      }
++      if (!in_array($table, $tables)) {
++              $c = 0;
++              $sql = 'CREATE TABLE `' . $table . "` (\n";
++              foreach ($data['columns'] as $column) {
++                      if (isset($column['name'])) {
++                              if ($c > 0)
++                                      $sql .= ",\n";
++                              $sql .= '`' . $column['name'] . '`';
++                              if (isset($column['type']))
++                                      $sql .= ' ' . $column['type'];
++                              if (isset($column['unsigned']))
++                                      $sql .= ' unsigned';
++                              if (isset($column['NULL']) && $column['NULL'] == false)
++                                      $sql .= ' NOT NULL';
++                              if (isset($column['NULL']) && $column['NULL'] == true && !isset($column['default']))
++                                      $sql .= ' default NULL';
++                              if (isset($column['default']))
++                                      $sql .= ' default ' . (is_numeric($column['default']) ? $column['default'] : "'" . $column['default'] . "'");
++                              if (isset($column['auto_increment']))
++                                      $sql .= ' auto_increment';
++                              $c++;
++                      }
++              }
++
++              if (isset($data['primary'])) {
++                      $sql .= ",\n PRIMARY KEY (`" . $data['primary'] . '`)';
++              }
++
++              if (sizeof($data['keys'])) {
++              foreach ($data['keys'] as $key) {
++                      if (isset($key['name'])) {
++                              $sql .= ",\n KEY `" . $key['name'] . '` (`' . $key['columns'] . '`)';
++                      }
++              }
++              }
++              $sql .= ') TYPE = ' . $data['type'];
++
++              if (isset($data['comment'])) {
++                      $sql .= " COMMENT = '" . $data['comment'] . "'";
++              }
++              if (db_execute($sql)) {
++                      db_execute("INSERT INTO plugin_db_changes (plugin, `table`, method) VALUES ('$plugin', '$table', 'create')");
++              }
++      } else {
++              db_execute("INSERT INTO plugin_db_changes (plugin, `table`, method) VALUES ('$plugin', '$table', 'create')");
++      }
++}
++
++function api_plugin_db_changes_remove ($plugin) {
++      // Example: api_plugin_db_changes_remove ('thold');
++
++      $tables = db_fetch_assoc("SELECT `table` FROM plugin_db_changes WHERE plugin = '$plugin' AND method ='create'", false);
++      if (count($tables)) {
++              foreach ($tables as $table) {
++                      db_execute("DROP TABLE IF EXISTS `" . $table['table'] . "`;");
++              }
++              db_execute("DELETE FROM plugin_db_changes where plugin = '$plugin' AND method ='create'", false);
++      }
++      $columns = db_fetch_assoc("SELECT `table`, `column` FROM plugin_db_changes WHERE plugin = '$plugin' AND method ='addcolumn'", false);
++      if (count($columns)) {
++              foreach ($columns as $column) {
++                      db_execute('ALTER TABLE `' . $column['table'] . '` DROP `' . $column['column'] . '`');
++              }
++              db_execute("DELETE FROM plugin_db_changes where plugin = '$plugin' AND method = 'addcolumn'", false);
++      }
++}
++
++function api_plugin_db_add_column ($plugin, $table, $column) {
++      // Example: api_plugin_db_add_column ('thold', 'plugin_config', array('name' => 'test' . rand(1, 200), 'type' => 'varchar (255)', 'NULL' => false));
++
++      global $config, $database_default;
++      include_once($config['library_path'] . '/database.php');
++
++      $result = db_fetch_assoc('show columns from `' . $table . '`') or die (mysql_error());
++      $columns = array();
++      foreach($result as $index => $arr) {
++              foreach ($arr as $t) {
++                      $columns[] = $t;
++              }
++      }
++      if (isset($column['name']) && !in_array($column['name'], $columns)) {
++              $sql = 'ALTER TABLE `' . $table . '` ADD `' . $column['name'] . '`';
++              if (isset($column['type']))
++                      $sql .= ' ' . $column['type'];
++              if (isset($column['unsigned']))
++                      $sql .= ' unsigned';
++              if (isset($column['NULL']) && $column['NULL'] == false)
++                      $sql .= ' NOT NULL';
++              if (isset($column['NULL']) && $column['NULL'] == true && !isset($column['default']))
++                      $sql .= ' default NULL';
++              if (isset($column['default']))
++                      $sql .= ' default ' . (is_numeric($column['default']) ? $column['default'] : "'" . $column['default'] . "'");
++              if (isset($column['auto_increment']))
++                      $sql .= ' auto_increment';
++              if (isset($column['after']))
++                      $sql .= ' AFTER ' . $column['after'];
++
++              if (db_execute($sql)) {
++                      db_execute("INSERT INTO plugin_db_changes (plugin, `table`, `column`, `method`) VALUES ('$plugin', '$table', '" . $column['name'] . "', 'addcolumn')");
++              }
++      }
++}
++
++function api_plugin_install ($plugin) {
++      global $config;
++      include_once($config['base_path'] . "/plugins/$plugin/setup.php");
++
++      $exists = db_fetch_assoc("SELECT id FROM plugin_config WHERE directory = '$plugin'", false);
++      if (sizeof($exists)) {
++              db_execute("DELETE FROM plugin_config WHERE directory = '$plugin'");
++      }
++
++      $name = $author = $webpage = $version = '';
++      $function = 'plugin_' . $plugin . '_version';
++      if (function_exists($function)){
++              $info = $function();
++              $name = $info['longname'];
++              if (isset($info['homepage'])) {
++                      $webpage = $info['homepage'];
++              }elseif (isset($info['webpage'])) {
++                      $webpage = $info['webpage'];
++              }else{
++                      $webpage = "Not Stated";
++              }
++              $author = $info['author'];
++              $version = $info['version'];
++      }
++
++      db_execute("INSERT INTO plugin_config (directory, name, author, webpage, version) VALUES ('$plugin', '$name', '$author', '$webpage', '$version')");
++
++      $function = 'plugin_' . $plugin . '_install';
++      if (function_exists($function)){
++              $function();
++              $ready = api_plugin_check_config ($plugin);
++              if ($ready) {
++                      // Set the plugin as "disabled" so it can go live
++                      db_execute("UPDATE plugin_config SET status = 4 WHERE directory = '$plugin'");
++              } else {
++                      // Set the plugin as "needs configuration"
++                      db_execute("UPDATE plugin_config SET status = 2 WHERE directory = '$plugin'");
++              }
++      }
++}
++
++function api_plugin_uninstall ($plugin) {
++      global $config;
++      include_once($config['base_path'] . "/plugins/$plugin/setup.php");
++      // Run the Plugin's Uninstall Function first
++      $function = 'plugin_' . $plugin . '_uninstall';
++      if (function_exists($function)) {
++              $function();
++      }
++      api_plugin_remove_hooks ($plugin);
++      api_plugin_remove_realms ($plugin);
++      db_execute("DELETE FROM plugin_config WHERE directory = '$plugin'");
++      api_plugin_db_changes_remove ($plugin);
++}
++
++function api_plugin_check_config ($plugin) {
++      global $config;
++      include_once($config['base_path'] . "/plugins/$plugin/setup.php");
++      $function = 'plugin_' . $plugin . '_check_config';
++      if (function_exists($function)) {
++              return $function();
++      }
++      return TRUE;
++}
++
++function api_plugin_enable ($plugin) {
++      $ready = api_plugin_check_config ($plugin);
++      if ($ready) {
++              api_plugin_enable_hooks ($plugin);
++              db_execute("UPDATE plugin_config SET status = 1 WHERE directory = '$plugin'");
++      }
++}
++
++function api_plugin_is_enabled ($plugin) {
++      $status = db_fetch_cell("SELECT status FROM plugin_config WHERE directory = '$plugin'", false);
++      if ($status == '1')
++              return true;
++      return false;
++}
++
++function api_plugin_disable ($plugin) {
++      api_plugin_disable_hooks ($plugin);
++      db_execute("UPDATE plugin_config SET status = 4 WHERE directory = '$plugin'");
++}
++
++function api_plugin_moveup($plugin) {
++      global $plugins_system;
++
++      $sql_where = "";
++      if (sizeof($plugins_system)) {
++              foreach($plugins_system as $s) {
++                      $sql_where .= (strlen($sql_where) ? " AND ":"(") . " directory!='$s'";
++              }
++
++              $sql_where .= ")";
++      }
++
++      $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='$plugin'" . (strlen($sql_where) ? " AND " . $sql_where:""));
++      $temp_id = db_fetch_cell("SELECT MAX(id) FROM plugin_config")+1;
++      $prior_id = db_fetch_cell("SELECT MAX(id) FROM plugin_config WHERE id<$id" . (strlen($sql_where) ? " AND " . $sql_where:""));
++
++      /* update the above plugin to the prior temp id */
++      db_execute("UPDATE plugin_config SET id=$temp_id WHERE id=$prior_id");
++      db_execute("UPDATE plugin_config SET id=$prior_id WHERE id=$id");
++      db_execute("UPDATE plugin_config SET id=$id WHERE id=$temp_id");
++}
++
++function api_plugin_movedown($plugin) {
++      global $plugins_system;
++
++      $sql_where = "";
++      if (sizeof($plugins_system)) {
++              foreach($plugins_system as $s) {
++                      $sql_where .= (strlen($sql_where) ? " AND ":"(") . " directory!='$s'";
++              }
++
++              $sql_where .= ")";
++      }
++
++      $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='$plugin'" . (strlen($sql_where) ? " AND " . $sql_where:""));
++      $temp_id = db_fetch_cell("SELECT MAX(id) FROM plugin_config")+1;
++      $next_id = db_fetch_cell("SELECT MIN(id) FROM plugin_config WHERE id>$id" . (strlen($sql_where) ? " AND " . $sql_where:""));
++
++      /* update the above plugin to the prior temp id */
++      db_execute("UPDATE plugin_config SET id=$temp_id WHERE id=$next_id");
++      db_execute("UPDATE plugin_config SET id=$next_id WHERE id=$id");
++      db_execute("UPDATE plugin_config SET id=$id WHERE id=$temp_id");
++}
++
++function api_plugin_register_hook ($plugin, $hook, $function, $file) {
++      $exists = db_fetch_assoc("SELECT id FROM plugin_hooks WHERE name = '$plugin' AND hook = '$hook'", false);
++      if (!count($exists)) {
++              $settings = array('config_settings', 'config_arrays', 'config_form');
++              if (!in_array($hook, $settings)) {
++                      db_execute("INSERT INTO plugin_hooks (name, hook, function, file) VALUES ('$plugin', '$hook', '$function', '$file')");
++              } else {
++                      db_execute("INSERT INTO plugin_hooks (name, hook, function, file, status) VALUES ('$plugin', '$hook', '$function', '$file', 1)");
++              }
++      }
++}
++
++function api_plugin_remove_hooks ($plugin) {
++      db_execute("DELETE FROM plugin_hooks WHERE name = '$plugin'");
++}
++
++function api_plugin_enable_hooks ($plugin) {
++      db_execute("UPDATE plugin_hooks SET status = 1 WHERE name = '$plugin'");
++}
++
++function api_plugin_disable_hooks ($plugin) {
++      db_execute("UPDATE plugin_hooks SET status = 0 WHERE name = '$plugin' AND hook != 'config_settings' AND hook != 'config_arrays' AND hook != 'config_form'");
++}
++
++function api_plugin_register_realm ($plugin, $file, $display, $admin = false) {
++      $exists = db_fetch_assoc("SELECT id FROM plugin_realms WHERE plugin = '$plugin' AND file = '$file'", false);
++      if (!count($exists)) {
++              db_execute("INSERT INTO plugin_realms (plugin, file, display) VALUES ('$plugin', '$file', '$display')");
++              if ($admin) {
++                      $realm_id = db_fetch_assoc("SELECT id FROM plugin_realms WHERE plugin = '$plugin' AND file = '$file'", false);
++                      $realm_id = $realm_id[0]['id'] + 100;
++                      $user_id = db_fetch_assoc("SELECT id FROM user_auth WHERE username = 'admin'", false);
++                      if (count($user_id)) {
++                              $user_id = $user_id[0]['id'];
++                              $exists = db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE user_id = $user_id and realm_id = $realm_id", false);
++                              if (!count($exists)) {
++                                      db_execute("INSERT INTO user_auth_realm (user_id, realm_id) VALUES ($user_id, $realm_id)");
++                              }
++                      }
++              }
++      }
++}
++
++function api_plugin_remove_realms ($plugin) {
++      $realms = db_fetch_assoc("SELECT id FROM plugin_realms WHERE plugin = '$plugin'", false);
++      foreach ($realms as $realm) {
++              $id = $realm['id'] + 100;
++              db_execute("DELETE FROM user_auth_realm WHERE realm_id = '$id'");
++      }
++      db_execute("DELETE FROM plugin_realms WHERE plugin = '$plugin'");
++}
++
++function api_plugin_load_realms () {
++      global $user_auth_realms, $user_auth_realm_filenames;
++      $plugin_realms = db_fetch_assoc("SELECT * FROM plugin_realms ORDER BY plugin, display", false);
++      if (count($plugin_realms)) {
++              foreach ($plugin_realms as $plugin_realm) {
++                      $plugin_files = explode(',', $plugin_realm['file']);
++                      foreach($plugin_files as $plugin_file) {
++                              $user_auth_realm_filenames[$plugin_file] = $plugin_realm['id'] + 100;
++                      }
++                      $user_auth_realms[$plugin_realm['id'] + 100] = $plugin_realm['display'];
++              }
++      }
++}
++
++function api_plugin_user_realm_auth ($filename = '') {
++      global $user_realms, $user_auth_realms, $user_auth_realm_filenames;
++      /* list all realms that this user has access to */
++      if (!isset($user_realms)) {
++              if (read_config_option('global_auth') == 'on' || read_config_option('auth_method') != 0) {
++                      $user_realms = db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . $_SESSION["sess_user_id"], false);
++                      $user_realms = array_rekey($user_realms, "realm_id", "realm_id");
++              }else{
++                      $user_realms = $user_auth_realms;
++              }
++      }
++      if ($filename != '' && isset($user_auth_realm_filenames[basename($filename)])) {
++              if (isset($user_realms[$user_auth_realm_filenames[basename($filename)]]))
++                      return TRUE;
++      }
++      return FALSE;
++}
++
++function plugin_config_arrays () {
++      global $menu;
++      $menu['Configuration']['plugins.php'] = 'Plugin Management';
++      api_plugin_load_realms ();
++}
++
++function plugin_draw_navigation_text ($nav) {
++      $nav["plugins.php:"] = array("title" => "Plugin Management", "mapping" => "index.php:", "url" => "plugins.php", "level" => "1");
++      return $nav;
++}
++
++
++
++
++
++
++
+diff -Naur cacti-0.8.7g/lib/poller.php cacti-0.8.7g-PA-v2.9/lib/poller.php
+--- cacti-0.8.7g/lib/poller.php        2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/poller.php        2010-10-17 20:09:52.000000000 -0400
+@@ -344,8 +344,11 @@
+                               }
+                       }
+               }
++              api_plugin_hook_function('poller_output', $rrd_update_array);
+-              $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
++              if (api_plugin_hook_function('poller_on_demand', $results)) {
++                      $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
++              }
+       }
+       return $rrds_processed;
+diff -Naur cacti-0.8.7g/lib/rrd.php cacti-0.8.7g-PA-v2.9/lib/rrd.php
+--- cacti-0.8.7g/lib/rrd.php   2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/rrd.php   2010-10-17 20:09:52.000000000 -0400
+@@ -419,6 +419,9 @@
+       $data_source_path = get_data_source_path($local_data_id, true);
++      /* update the rrdfile if performing a fetch */
++      api_plugin_hook_function('rrdtool_function_fetch_cache_check', $local_data_id);
++
+       /* build and run the rrdtool fetch command with all of our data */
+       $cmd_line = "fetch $data_source_path AVERAGE -s $start_time -e $end_time";
+       if ($resolution > 0) {
+@@ -539,6 +542,10 @@
+               }
+       }
++      $data = api_plugin_hook_function('rrdtool_function_graph_cache_check', array('local_graph_id' => $local_graph_id,'rra_id' => $rra_id,'rrd_struc' => $rrdtool_pipe,'graph_data_array' => $graph_data_array, 'return' => false));
++      if (isset($data['return']) && $data['return'] != false)
++              return $data['return'];
++
+       /* find the step and how often this graph is updated with new data */
+       $ds_step = db_fetch_cell("select
+               data_template_data.rrd_step
+@@ -1376,6 +1383,13 @@
+       }
+       }
++      $graph_array = api_plugin_hook_function('rrd_graph_graph_options', array('graph_opts' => $graph_opts, 'graph_defs' => $graph_defs, 'txt_graph_items' => $txt_graph_items, 'graph_id' => $local_graph_id, 'start' => $graph_start, 'end' => $graph_end));
++      if (!empty($graph_array)) {
++              $graph_defs = $graph_array['graph_defs'];
++              $txt_graph_items = $graph_array['txt_graph_items'];
++              $graph_opts = $graph_array['graph_opts'];
++      }
++
+       /* either print out the source or pass the source onto rrdtool to get us a nice PNG */
+       if (isset($graph_data_array["print_source"])) {
+               print "<PRE>" . htmlspecialchars(read_config_option("path_rrdtool") . " graph " . $graph_opts . $graph_defs . $txt_graph_items) . "</PRE>";
+@@ -1384,13 +1398,19 @@
+                       @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, RRDTOOL_OUTPUT_NULL, $rrdtool_pipe);
+                       return 0;
+               }else{
++                      $graph_data_array = api_plugin_hook_function('prep_graph_array', $graph_data_array);
++
+                       if (isset($graph_data_array["output_flag"])) {
+                               $output_flag = $graph_data_array["output_flag"];
+                       }else{
+                               $output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
+                       }
+-                      return @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag, $rrdtool_pipe);
++                      $output = @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag, $rrdtool_pipe);
++
++                      api_plugin_hook_function('rrdtool_function_graph_set_file', array('output' => $output, 'local_graph_id' => $local_graph_id, 'rra_id' => $rra_id));
++
++                      return $output;
+               }
+       }
+ }
+diff -Naur cacti-0.8.7g/lib/template.php cacti-0.8.7g-PA-v2.9/lib/template.php
+--- cacti-0.8.7g/lib/template.php      2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/template.php      2010-10-17 20:09:52.000000000 -0400
+@@ -786,6 +786,18 @@
+               update_graph_data_query_cache($cache_array["local_graph_id"]);
+       }
++      # now that we have the id of the new host, we may plugin postprocessing code
++      $save["id"] = $cache_array["local_graph_id"];
++      $save["graph_template_id"] = $graph_template_id;        // attention: unset!
++      if (is_array($snmp_query_array)) {
++              $save["snmp_query_id"] = $snmp_query_array["snmp_query_id"];
++              $save["snmp_index"] = $snmp_query_array["snmp_index"];
++      } else {
++              $save["snmp_query_id"] = 0;
++              $save["snmp_index"] = 0;
++      }
++      api_plugin_hook_function('create_complete_graph_from_template', $save);
++
+       return $cache_array;
+ }
+diff -Naur cacti-0.8.7g/lib/variables.php cacti-0.8.7g-PA-v2.9/lib/variables.php
+--- cacti-0.8.7g/lib/variables.php     2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/lib/variables.php     2010-10-17 20:09:52.000000000 -0400
+@@ -183,6 +183,9 @@
+       $string = str_replace($l_escape_string . "host_max_oids" . $r_escape_string, $_SESSION["sess_host_cache_array"][$host_id]["max_oids"], $string);
+       $string = str_replace($l_escape_string . "host_id" . $r_escape_string, $_SESSION["sess_host_cache_array"][$host_id]["id"], $string);
++      $temp = api_plugin_hook_function('substitute_host_data', array('string' => $string, 'l_escape_string' => $l_escape_string, 'r_escape_string' => $r_escape_string, 'host_id' => $host_id));
++      $string = $temp['string'];
++
+       return $string;
+ }
+diff -Naur cacti-0.8.7g/plugins/index.php cacti-0.8.7g-PA-v2.9/plugins/index.php
+--- cacti-0.8.7g/plugins/index.php     1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/plugins/index.php     2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,5 @@
++<?php
++
++header("Location:../index.php");
++
++?>
+diff -Naur cacti-0.8.7g/plugins.php cacti-0.8.7g-PA-v2.9/plugins.php
+--- cacti-0.8.7g/plugins.php   1969-12-31 19:00:00.000000000 -0500
++++ cacti-0.8.7g-PA-v2.9/plugins.php   2010-10-17 20:09:52.000000000 -0400
+@@ -0,0 +1,665 @@
++<?php
++/*
++ +-------------------------------------------------------------------------+
++ | Copyright (C) 2004-2010 The Cacti Group                                 |
++ |                                                                         |
++ | This program is free software; you can redistribute it and/or           |
++ | modify it under the terms of the GNU General Public License             |
++ | as published by the Free Software Foundation; either version 2          |
++ | of the License, or (at your option) any later version.                  |
++ |                                                                         |
++ | This program is distributed in the hope that it will be useful,         |
++ | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
++ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
++ | GNU General Public License for more details.                            |
++ +-------------------------------------------------------------------------+
++ | Cacti: The Complete RRDTool-based Graphing Solution                     |
++ +-------------------------------------------------------------------------+
++ | This code is designed, written, and maintained by the Cacti Group. See  |
++ | about.php and/or the AUTHORS file for specific developer information.   |
++ +-------------------------------------------------------------------------+
++ | http://www.cacti.net/                                                   |
++ +-------------------------------------------------------------------------+
++*/
++
++include("./include/auth.php");
++
++define("MAX_DISPLAY_PAGES", 21);
++
++$actions = array("install" => "Install",
++      "enable" => "Enable",
++      "disable" => "Disable",
++      "uninstall" => "Uninstall",
++//    "check" => "Check"
++);
++
++$status_names = array(
++      -2 => 'Disabled',
++      -1 => 'Active',
++      0 => 'Not Installed',
++      1 => 'Active',
++      2 => 'Awaiting Configuration',
++      3 => 'Awaiting Upgrade',
++      4 => 'Installed'
++);
++
++/* get the comprehensive list of plugins */
++$pluginslist = retrieve_plugin_list();
++
++/* Check to see if we are installing, etc... */
++$modes = array('installold', 'uninstallold', 'install', 'uninstall', 'disable', 'enable', 'check', 'moveup', 'movedown');
++
++if (isset($_GET['mode']) && in_array($_GET['mode'], $modes)  && isset($_GET['id'])) {
++      input_validate_input_regex(get_request_var("id"), "^([a-zA-Z0-9]+)$");
++
++      $mode = $_GET['mode'];
++      $id   = sanitize_search_string($_GET['id']);
++
++      switch ($mode) {
++              case 'installold':
++                      api_plugin_install_old($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'uninstallold':
++                      api_plugin_uninstall_old($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'install':
++                      api_plugin_install($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'uninstall':
++                      if (!in_array($id, $pluginslist)) break;
++                      api_plugin_uninstall($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'disable':
++                      if (!in_array($id, $pluginslist)) break;
++                      api_plugin_disable($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'enable':
++                      if (!in_array($id, $pluginslist)) break;
++                      api_plugin_enable($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'check':
++                      if (!in_array($id, $pluginslist)) break;
++                      break;
++              case 'moveup':
++                      if (!in_array($id, $pluginslist)) break;
++                      if (is_system_plugin($id)) break;
++                      api_plugin_moveup($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++              case 'movedown':
++                      if (!in_array($id, $pluginslist)) break;
++                      if (is_system_plugin($id)) break;
++                      api_plugin_movedown($id);
++                      header("Location: plugins.php");
++                      exit;
++                      break;
++      }
++}
++
++function retrieve_plugin_list () {
++      $pluginslist = array();
++      $temp = db_fetch_assoc('SELECT directory FROM plugin_config ORDER BY name');
++      foreach ($temp as $t) {
++              $pluginslist[] = $t['directory'];
++      }
++      return $pluginslist;
++}
++
++include("./include/top_header.php");
++
++update_show_current();
++
++include("./include/bottom_footer.php");
++
++function api_plugin_install_old ($plugin) {
++      global $config;
++      if (!file_exists($config['base_path'] . "/plugins/$plugin/setup.php")) {
++              return false;
++      }
++      $oldplugins = read_config_option('oldplugins');
++      if (strlen(trim($oldplugins))) {
++      $oldplugins = explode(',', $oldplugins);
++      }else{
++              $oldplugins = array();
++      }
++      if (!in_array($plugin, $oldplugins)) {
++              include_once($config['base_path'] . "/plugins/$plugin/setup.php");
++              $function = 'plugin_init_' . $plugin;
++              if (function_exists($function)){
++                      $oldplugins[] = $plugin;
++                      $oldplugins   = implode(',', $oldplugins);
++                      set_config_option('oldplugins', $oldplugins);
++                      unset($_SESSION['sess_config_array']['oldplugins']);
++                      return true;
++              } else {
++                      return false;
++              }
++      }
++      return false;
++}
++
++function api_plugin_uninstall_old ($plugin) {
++      global $config;
++      $oldplugins = read_config_option('oldplugins');
++      if (strlen(trim($oldplugins))) {
++      $oldplugins = explode(',', $oldplugins);
++      }else{
++              $oldplugins = array();
++      }
++      if (!empty($oldplugins)) {
++              if (in_array($plugin, $oldplugins)) {
++                      for ($a = 0; $a < count($oldplugins); $a++) {
++                              if ($oldplugins[$a] == $plugin) {
++                                      unset($oldplugins[$a]);
++                                      break;
++                              }
++                      }
++                      $oldplugins = implode(',', $oldplugins);
++                      set_config_option('oldplugins', $oldplugins);
++                      unset($_SESSION['sess_config_array']['oldplugins']);
++                      return true;
++              }
++      }
++      return false;
++}
++
++function update_show_updates () {
++      global $pluginslist, $colors, $config, $plugin_architecture;
++
++      $cinfo = array();
++      sort($pluginslist);
++
++      $cinfo = update_get_plugin_info ();
++
++      $x = 0;
++
++      $info = update_get_cached_plugin_info();
++
++      $cactinew = update_check_if_newer($cinfo['cacti']['version'], $info['cacti']['version']) ;
++      if (isset($cinfo['cacti_plugin_arch']['version'])) {
++              $archnew =  update_check_if_newer($cinfo['cacti_plugin_arch']['version'], $info['cacti_plugin_arch']['version']);
++      } else {
++              $archnew = 0;
++      }
++
++      if ($cactinew) {
++              $x++;
++              print "<tr><td width='25%' valign=top><table width='100%'>";
++              html_header(array("Cacti"), 2);
++              form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++              print "<td width='25%'><strong>Version:</strong></td><td>" . $config["cacti_version"] . "</td></tr>";
++              form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++              print "<td valign=top><strong>Changes:</strong></td><td>" . str_replace("\n", '<br>', $info['cacti']['changes']) . "</td></tr></table>";
++      }
++      if (isset($plugin_architecture['version']) && $archnew) {
++              $x++;
++              print "<table width='100%'>";
++              html_header(array("Plugin Architecture"), 2);
++              form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++              print "<td width='25%'><strong>Version:</strong></td><td>" . $plugin_architecture['version'] . "</td>";
++              form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++              print "<td valign=top><strong>Changes:</strong></td><td>" . str_replace("\n", '<br>', $info['cacti_plugin_arch']['changes']) . "</td></tr></table>";
++      }
++      print "<table width='100%' cellspacing=0 cellpadding=3>";
++
++      foreach ($pluginslist as $plugin) {
++              if (isset($cinfo[$plugin]) && update_check_if_newer($cinfo[$plugin]['version'], $info[$plugin]['version'])) {
++                      $x++;
++                      print "<table width='100%'>";
++                      html_header(array((isset($cinfo[$plugin]['longname']) ? $cinfo[$plugin]['longname'] : $plugin)), 2);
++                      form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++                      print "<td width='50%'><strong>Directory:</strong></td><td>$plugin</td>";
++                      form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++                      print "<td><strong>Version:</strong></td><td>" . $info[$plugin]['version'] . "</td>";
++                      form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++                      print "<td><strong>Author:</strong></td><td>" . (isset($cinfo[$plugin]['author']) && $cinfo[$plugin]['author'] != '' ? (isset($cinfo[$plugin]['email']) && $cinfo[$plugin]['email'] != '' ? "<a href='mailto:" . $cinfo[$plugin]['email'] . "'>" . $cinfo[$plugin]['author'] . "</a>"  : $cinfo[$plugin]['author']) : "") . "</td>";
++                      form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++                      print "<td><strong>Home Page:</strong></td><td>" . (isset($cinfo[$plugin]['webpage']) && $cinfo[$plugin]['webpage'] != '' ? "<a href='" . $cinfo[$plugin]['webpage'] . "'>" . $cinfo[$plugin]['webpage'] . "</a>" : "") . "</td>";
++                      form_alternate_row_color($colors["alternate"],$colors["light"], 0);
++                      print "<td valign=top><strong>Changes:</strong></td><td>" . str_replace("\n", '<br>', $info[$plugin]['changes']) . "</td>";
++
++                      print "</tr></table>";
++              }
++      }
++      if ($x == 0)
++              print "<br><center><b>There are currently no Updates!</b></center><br>";
++      print "</table>";
++      html_end_box(TRUE);
++}
++
++function update_check_if_newer() {
++      return false;
++}
++
++function plugins_temp_table_exists($table) {
++      return sizeof(db_fetch_row("SHOW TABLES LIKE '$table'"));
++}
++
++function plugins_load_temp_table() {
++      global $config, $plugins;
++
++      $pluginslist = retrieve_plugin_list();
++
++      if (isset($_SESSION["plugin_temp_table"])) {
++              $table = $_SESSION["plugin_temp_table"];
++      }else{
++              $table = "plugin_temp_table_" . rand();
++      }
++
++      while (true) {
++              if (!plugins_temp_table_exists($table)) {
++                      $_SESSION["plugin_temp_table"] = $table;
++                      db_execute("CREATE TEMPORARY TABLE $table LIKE plugin_config");
++                      db_execute("INSERT INTO $table SELECT * FROM plugin_config");
++                      break;
++              }else{
++                      $table = "plugin_temp_table_" . rand();
++              }
++      }
++
++      $path = $config['base_path'] . '/plugins/';
++      $dh = opendir($path);
++      while (($file = readdir($dh)) !== false) {
++              if ((is_dir("$path/$file")) && (file_exists("$path/$file/setup.php")) && (!in_array($file, $pluginslist))) {
++                      include_once("$path/$file/setup.php");
++                      if (!function_exists('plugin_' . $file . '_install') && function_exists($file . '_version')) {
++                              $function = $file . '_version';
++                              $cinfo[$file] = $function();
++                              if (!isset($cinfo[$file]['author']))   $cinfo[$file]['author']   = 'Unknown';
++                              if (!isset($cinfo[$file]['homepage'])) $cinfo[$file]['homepage'] = 'Not Stated';
++                              if (isset($cinfo[$file]['webpage']))   $cinfo[$file]['homepage'] = $cinfo[$file]['webpage'];
++                              if (!isset($cinfo[$file]['longname'])) $cinfo[$file]['longname'] = ucfirst($file);
++                              $cinfo[$file]['status'] = -2;
++                              if (in_array($file, $plugins)) {
++                                      $cinfo[$file]['status'] = -1;
++                              }
++                              db_execute("REPLACE INTO $table (directory, name, status, author, webpage, version)
++                                      VALUES ('" .
++                                              $file . "', '" .
++                                              $cinfo[$file]['longname'] . "', '" .
++                                              $cinfo[$file]['status']   . "', '" .
++                                              $cinfo[$file]['author']   . "', '" .
++                                              $cinfo[$file]['homepage'] . "', '" .
++                                              $cinfo[$file]['version']  . "')");
++                              $pluginslist[] = $file;
++                      } elseif (function_exists('plugin_' . $file . '_install') && function_exists('plugin_' . $file . '_version')) {
++                              $function               = $file . '_version';
++                              $cinfo[$file]           = $function();
++                              $cinfo[$file]['status'] = 0;
++                              if (!isset($cinfo[$file]['author']))   $cinfo[$file]['author']   = 'Unknown';
++                              if (!isset($cinfo[$file]['homepage'])) $cinfo[$file]['homepage'] = 'Not Stated';
++                              if (isset($cinfo[$file]['webpage']))   $cinfo[$file]['homepage'] = $cinfo[$file]['webpage'];
++                              if (!isset($cinfo[$file]['longname'])) $cinfo[$file]['homepage'] = ucfirst($file);
++
++                              /* see if it's been installed as old, if so, remove from oldplugins array and session */
++                              $oldplugins = read_config_option("oldplugins");
++                              if (substr_count($oldplugins, $file)) {
++                                      $oldplugins = str_replace($file, "", $oldplugins);
++                                      $oldplugins = str_replace(",,", ",", $oldplugins);
++                                      $oldplugins = trim($oldplugins, ",");
++                                      set_config_option('oldplugins', $oldplugins);
++                                      $_SESSION['sess_config_array']['oldplugins'] = $oldplugins;
++                              }
++
++                              db_execute("REPLACE INTO $table (directory, name, status, author, webpage, version)
++                                      VALUES ('" .
++                                              $file . "', '" .
++                                              $cinfo[$file]['longname'] . "', '" .
++                                              $cinfo[$file]['status'] . "', '" .
++                                              $cinfo[$file]['author'] . "', '" .
++                                              $cinfo[$file]['homepage'] . "', '" .
++                                              $cinfo[$file]['version'] . "')");
++                              $pluginslist[] = $file;
++                      }
++              }
++      }
++      closedir($dh);
++
++      return $table;
++}
++
++function update_show_current () {
++      global $plugins, $pluginslist, $colors, $plugin_architecture, $config, $status_names, $actions;
++
++      /* ================= input validation ================= */
++      input_validate_input_number(get_request_var_request("page"));
++      /* ==================================================== */
++
++      /* clean up search string */
++      if (isset($_REQUEST["filter"])) {
++              $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
++      }
++
++      /* clean up sort_column */
++      if (isset($_REQUEST["sort_column"])) {
++              $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
++      }
++
++      /* clean up search string */
++      if (isset($_REQUEST["sort_direction"])) {
++              $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
++      }
++
++      /* if the user pushed the 'clear' button */
++      if (isset($_REQUEST["clear_x"])) {
++              kill_session_var("sess_plugins_filter");
++              kill_session_var("sess_plugins_sort_column");
++              kill_session_var("sess_plugins_sort_direction");
++
++              unset($_REQUEST["page"]);
++              unset($_REQUEST["filter"]);
++              unset($_REQUEST["sort_column"]);
++              unset($_REQUEST["sort_direction"]);
++              $_REQUEST["page"] = 1;
++      }
++
++      /* remember these search fields in session vars so we don't have to keep passing them around */
++      load_current_session_value("filter", "sess_plugins_filter", "");
++      load_current_session_value("sort_column", "sess_plugins_sort_column", "name");
++      load_current_session_value("sort_direction", "sess_plugins_sort_direction", "ASC");
++      load_current_session_value("page", "sess_plugins_current_page", "1");
++
++      $table = plugins_load_temp_table();
++
++      html_start_box("<strong>Plugin Management</strong> (Cacti Version: " . $config["cacti_version"] .
++              (isset($plugin_architecture['version']) ? ", Plugin Architecture Version: " . $plugin_architecture['version']:"") .
++              ")", "100%", $colors["header"], "3", "center", "");
++
++      ?>
++      <tr bgcolor="#<?php print $colors['panel'];?>">
++              <td class="noprint">
++              <form name="form_plugins" method="get" action="plugins.php">
++                      <table width="100%" cellpadding="0" cellspacing="0">
++                              <tr class="noprint">
++                                      <td nowrap style='white-space: nowrap;' width="50">
++                                              Search:&nbsp;
++                                      </td>
++                                      <td width="1">
++                                              <input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>">
++                                      </td>
++                                      <td nowrap style='white-space: nowrap;'>
++                                              &nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
++                                              <input type="submit" name="clear_x" value="Clear" title="Clear Filters">
++                                      </td>
++                              </tr>
++                      </table>
++                      <input type='hidden' name='page' value='1'>
++              </form>
++              </td>
++      </tr>
++      <?php
++
++      html_end_box();
++
++      /* print checkbox form for validation */
++      print "<form name='chk' method='post' action='plugins.php'>\n";
++
++      html_start_box("", "100%", $colors["header"], "3", "center", "");
++
++      /* form the 'where' clause for our main sql query */
++      $sql_where = "WHERE ($table.name LIKE '%%" . get_request_var_request("filter") . "%%')";
++
++      if (get_request_var_request("sort_column") == "version") {
++              $sortc = "version+0";
++      }else{
++              $sortc = get_request_var_request("sort_column");
++      }
++
++      if (get_request_var_request("sort_column") == "id") {
++              $sortd = "ASC";
++      }else{
++              $sortd = get_request_var_request("sort_direction");
++      }
++
++      $total_rows = db_fetch_cell("SELECT
++              count(*)
++              FROM $table
++              $sql_where");
++
++      $plugins = db_fetch_assoc("SELECT *
++              FROM $table
++              $sql_where
++              ORDER BY " . $sortc . " " . $sortd . "
++              LIMIT " . (read_config_option("num_rows_device")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_device"));
++
++      db_execute("DROP TABLE $table");
++
++      /* generate page list */
++      $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "plugins.php?filter=" . get_request_var_request("filter"));
++
++      if ($total_rows == 0) {
++              $nav = "<tr bgcolor='#" . $colors["header"] . "'>
++                              <td colspan='9'>
++                                      <table width='100%' cellspacing='0' cellpadding='0' border='0'>
++                                              <tr>
++                                                      <td align='center' class='textHeaderDark'>
++                                                              No Plugins Found
++                                                      </td>\n
++                                              </tr>
++                                      </table>
++                              </td>
++                      </tr>\n";
++      }elseif ($total_rows < read_config_option("num_rows_device")) {
++              $nav = "<tr bgcolor='#" . $colors["header"] . "'>
++                              <td colspan='9'>
++                                      <table width='100%' cellspacing='0' cellpadding='0' border='0'>
++                                              <tr>
++                                                      <td align='center' class='textHeaderDark'>
++                                                              Showing All $total_rows Rows
++                                                      </td>\n
++                                              </tr>
++                                      </table>
++                              </td>
++                      </tr>\n";
++      }else{
++              $nav = "<tr bgcolor='#" . $colors["header"] . "'>
++                              <td colspan='9'>
++                                      <table width='100%' cellspacing='0' cellpadding='0' border='0'>
++                                              <tr>
++                                                      <td align='left' class='textHeaderDark'>
++                                                              <strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("plugins.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")-1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
++                                                      </td>\n
++                                                      <td align='center' class='textHeaderDark'>
++                                                              Showing Rows " . ((read_config_option("num_rows_device")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_device")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
++                                                      </td>\n
++                                                      <td align='right' class='textHeaderDark'>
++                                                              <strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("plugins.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")+1)) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
++                                                      </td>\n
++                                              </tr>
++                                      </table>
++                              </td>
++                      </tr>\n";
++      }
++
++      print $nav;
++
++      $display_text = array(
++              "nosort" => array("Actions", ""),
++              "directory" => array("Name", "ASC"),
++              "id" => array("Load Order", "ASC"),
++              "name" => array("Description", "ASC"),
++              "nosort1" => array("Type", "ASC"),
++              "status" => array("Status", "ASC"),
++              "author" => array("Author", "ASC"),
++              "webpage" => array("Web Page", "ASC"),
++              "version" => array("Version", "ASC"));
++
++      html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), 1);
++
++      $i = 0;
++      if (sizeof($plugins)) {
++              if (get_request_var_request("sort_column") == "id") {
++                      $inst_system_plugins = get_system_plugins($plugins);
++                      if (sizeof($inst_system_plugins)) {
++                              foreach($inst_system_plugins as $plugin) {
++                                      form_alternate_row_color($colors["alternate"], $colors["light"], $i); $i++;
++                                      print format_plugin_row($plugin, false, false, true);
++                              }
++                      }
++              }
++
++              $j = 0;
++              foreach ($plugins as $plugin) {
++                      if ((isset($plugins[$j+1]) && $plugins[$j+1]['status'] < 0) || (!isset($plugins[$j+1]))) {
++                              $last_plugin = true;
++                      }else{
++                              $last_plugin = false;
++                      }
++                      if ($plugin['status'] <= 0 || is_system_plugin($plugin) || (get_request_var_request('sort_column') != 'id')) {
++                              $load_ordering = false;
++                      }else{
++                              $load_ordering = true;
++                      }
++
++                      if (get_request_var_request("sort_column") == "id") {
++                              if (!is_system_plugin($plugin)) {
++                                      form_alternate_row_color($colors["alternate"], $colors["light"], $i);
++                                      print format_plugin_row($plugin, $last_plugin, $load_ordering, false);
++                                      $i++;
++                              }
++                      }else{
++                              form_alternate_row_color($colors["alternate"], $colors["light"], $i);
++                              print format_plugin_row($plugin, $last_plugin, $load_ordering, is_system_plugin($plugin));
++                              $i++;
++                      }
++
++                      $j++;
++              }
++
++              print $nav;
++      }else{
++              print "<tr><td><em>No Plugins Found</em></td></tr>";
++      }
++
++      html_end_box(false);
++
++      html_start_box("", "100%", $colors["header"], "3", "center", "");
++      echo "<tr><td colspan=10><strong>NOTE:</strong> Please sort by 'Load Order' to change plugin load ordering.<br><strong>NOTE:</strong> SYSTEM plugins can not be ordered.</td></tr>";
++      html_end_box();
++
++      print "</form>\n";
++}
++
++function format_plugin_row($plugin, $last_plugin, $include_ordering, $system_plugin) {
++      global $status_names;
++      static $first_plugin = true;
++
++      $row = plugin_actions($plugin);
++      $row .= "<td><strong>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", ucfirst($plugin["directory"])) : ucfirst($plugin["directory"])) . "</strong></td>";
++      if ($include_ordering) {
++              $row .= "<td style='white-space:nowrap;'>";
++              if (!$first_plugin) {
++                      $row .= "<a href='" . htmlspecialchars("plugins.php?mode=moveup&id=" . $plugin['directory']) . "' title='Order Before Prevous Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/move_up.gif'></a>";
++              }else{
++                      $row .= "<a href='#' title='Can NOT Reduce Load Order' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'></a>";
++              }
++              if (!$last_plugin) {
++                      $row .= "<a href='" . htmlspecialchars("plugins.php?mode=movedown&id=" . $plugin['directory']) . "' title='Order After Next Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/move_down.gif'></a>";
++              }else{
++                      $row .= "<a href='#' title='Can Increase Load Order' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'></a>";
++              }
++              $row .= "</td>\n";
++      }else{
++              $row .= "<td></td>\n";
++      }
++
++      $row .= "<td style='white-space:nowrap;'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $plugin["name"]) : $plugin["name"]) . "</td>\n";
++      $row .= "<td style='white-space:nowrap;'>" . ($system_plugin ? "System": ($plugin['status'] < 0 ? "Old PIA":"General")) . "</td>\n";
++      $row .= "<td style='white-space:nowrap;'>" . $status_names[$plugin["status"]] . "</td>\n";
++      $row .= "<td style='white-space:nowrap;'>" . $plugin["author"] . "</td>\n";
++      $row .= "<td><a href='" . htmlspecialchars($plugin["webpage"]) . "'>" . htmlspecialchars($plugin["webpage"]) . "</a></td>\n";
++      $row .= "<td>" . $plugin["version"] . "</td>\n";
++      $row .= "</tr>\n";
++
++      if ($include_ordering) {
++              $first_plugin = false;
++      }
++
++      return $row;
++}
++
++function plugin_actions($plugin) {
++      $link = "<td>";
++      switch ($plugin['status']) {
++              case "-2": // Old PA Not Installed
++                      $link .= "<a href='" . htmlspecialchars("plugins.php?mode=installold&id=" . $plugin['directory']) . "' title='Install Old Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/install_icon.png'></a>";
++                      $link .= "<img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'>";
++                      break;
++              case "-1":      // Old PA Currently Active
++                      $oldplugins = read_config_option('oldplugins');
++                      if (strlen(trim($oldplugins))) {
++                              $oldplugins = explode(',', $oldplugins);
++                      }else{
++                              $oldplugins = array();
++                      }
++                      if (in_array($plugin['directory'], $oldplugins)) {
++                              $link .= "<a href='" . htmlspecialchars("plugins.php?mode=uninstallold&id=" . $plugin['directory']) . "' title='Uninstall Old Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/uninstall_icon.gif'></a>";
++                      } else {
++                              $link .= "<a href='#' title='Please Uninstall from config.php' class='linkEditMain'><img style='padding:1px;' align='absmiddle' border='0' src='images/install_icon_disabled.png'></a>";
++                      }
++                      $link .= "<img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'>";
++                      break;
++              case "0": // Not Installed
++                      $link .= "<a href='" . htmlspecialchars("plugins.php?mode=install&id=" . $plugin['directory']) . "' title='Install Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/install_icon.png'></a>";
++                      $link .= "<img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'>";
++                      break;
++              case "1":       // Currently Active
++                      $link .= "<a href='" . htmlspecialchars("plugins.php?mode=uninstall&id=" . $plugin['directory']) . "' title='Uninstall Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/uninstall_icon.gif'></a>";
++                      $link .= "<a href='" . htmlspecialchars("plugins.php?mode=disable&id=" . $plugin['directory']) . "' title='Disable Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/disable_icon.png'></a>";
++                      break;
++              case "4":       // Installed but not active
++                      $link .= "<a href='" . htmlspecialchars("plugins.php?mode=uninstall&id=" . $plugin['directory']) . "' title='Uninstall Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/uninstall_icon.gif'></a>";
++                      $link .= "<a href='" . htmlspecialchars("plugins.php?mode=enable&id=" . $plugin['directory']) . "' title='Enable Plugin' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/enable_icon.png'></a>";
++                      break;
++              default: // Old PIA
++                      $link .= "<a href='#' title='Please Install/Uninstall from config.php' class='linkEditMain'><img style='padding:1px;' align='absmiddle' border='0' src='images/install_icon_disabled.png'></a>";
++                      $link .= "<a href='#' title='Enabling from the UI is not supported' class='linkEditMain'><img style='padding:1px;' align='absmiddle' border='0' src='images/enable_icon_disabled.png'></a>";
++                      break;
++      }
++      $link .= "</td>";
++
++      return $link;
++}
++
++function is_system_plugin($plugin) {
++      global $plugins_system;
++
++      if (is_array($plugin)) {
++              $plugin = $plugin["directory"];
++      }
++
++      if (!in_array($plugin, $plugins_system)) {
++              return false;
++      }else{
++              return true;
++      }
++}
++
++function get_system_plugins($plugins) {
++      $inst_system_plugins = array();
++
++      if (sizeof($plugins)) {
++              foreach($plugins as $plugin) {
++                      if (is_system_plugin($plugin)) {
++                              $inst_system_plugins[] = $plugin;
++                      }
++              }
++      }
++
++      return $inst_system_plugins;
++}
++
++
+diff -Naur cacti-0.8.7g/poller.php cacti-0.8.7g-PA-v2.9/poller.php
+--- cacti-0.8.7g/poller.php    2010-09-19 21:39:06.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/poller.php    2010-10-17 20:09:52.000000000 -0400
+@@ -108,6 +108,8 @@
+       pcntl_signal(SIGINT, "sig_handler");
+ }
++api_plugin_hook('poller_top');
++
+ /* record the start time */
+ list($micro,$seconds) = explode(" ", microtime());
+ $poller_start         = $seconds + $micro;
+@@ -303,6 +305,8 @@
+                       $total_procs    = $concurrent_processes;
+               }
++              $extra_args = api_plugin_hook_function ('poller_command_args', $extra_args);
++
+               /* Populate each execution file with appropriate information */
+               foreach ($polling_hosts as $item) {
+                       if ($host_count == 1) {
+@@ -427,7 +431,7 @@
+       /* record the start time for this loop */
+       list($micro,$seconds) = explode(" ", microtime());
+-      $loop_end = $seconds + $micro;
++      $loop_end  = $seconds + $micro;
+       $loop_time = $loop_end - $loop_start;
+       if ($loop_time < $poller_interval) {
+@@ -446,7 +450,9 @@
+               /* sleep the appripriate amount of time */
+               if ($poller_runs_completed < $poller_runs) {
++                      api_plugin_hook('poller_bottom');
+                       usleep($sleep_time * 1000000);
++                      api_plugin_hook('poller_top');
+               }
+       }else if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM || $debug) {
+               cacti_log("WARNING: Cacti Polling Cycle Exceeded Poller Interval by " . $loop_end-$loop_start-$poller_interval . " seconds", TRUE, "POLLER");
+@@ -493,4 +499,6 @@
+       echo "    --debug|-d     Output debug information.  Similar to cacti's DEBUG logging level.\n\n";
+ }
++api_plugin_hook('poller_bottom');
++
+ ?>
+diff -Naur cacti-0.8.7g/user_admin.php cacti-0.8.7g-PA-v2.9/user_admin.php
+--- cacti-0.8.7g/user_admin.php        2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/user_admin.php        2010-10-17 20:09:52.000000000 -0400
+@@ -57,9 +57,11 @@
+               break;
+       default:
+-              include_once("include/top_header.php");
+-              user();
+-              include_once("include/bottom_footer.php");
++              if (!api_plugin_hook_function('user_admin_action', get_request_var_request("action"))) {
++                      include_once("include/top_header.php");
++                      user();
++                      include_once("include/bottom_footer.php");
++              }
+               break;
+ }
+@@ -402,6 +404,7 @@
+               $save["policy_graph_templates"] = form_input_validate(get_request_var_post("policy_graph_templates", get_request_var_post("_policy_graph_templates")), "policy_graph_templates", "", true, 3);
+               $save["realm"] = get_request_var_post("realm", 0);
+               $save["enabled"] = form_input_validate(get_request_var_post("enabled", ""), "enabled", "", true, 3);
++              $save = api_plugin_hook_function('user_admin_setup_sql_save', $save);
+               if (!is_error_message()) {
+                       $user_id = sql_save($save, "user_auth");
+@@ -444,6 +447,8 @@
+                                       policy_hosts = " . get_request_var_post("policy_hosts") . ",
+                                       policy_graph_templates = " . get_request_var_post("policy_graph_templates") . "
+                                       WHERE id = " . get_request_var_post("id"));
++                      } else {
++                              api_plugin_hook('user_admin_user_save');
+                       }
+               }
+       }
+@@ -889,6 +894,8 @@
+               $header_label = "[new]";
+       }
++      api_plugin_hook_function('user_admin_edit', (isset($user) ? get_request_var("id") : 0));
++
+       html_start_box("<strong>User Management</strong> $header_label", "100%", $colors["header"], "3", "center", "");
+       draw_edit_form(array(
+diff -Naur cacti-0.8.7g/utilities.php cacti-0.8.7g-PA-v2.9/utilities.php
+--- cacti-0.8.7g/utilities.php 2010-07-09 18:33:46.000000000 -0400
++++ cacti-0.8.7g-PA-v2.9/utilities.php 2010-10-17 20:09:52.000000000 -0400
+@@ -123,11 +123,14 @@
+               include_once("./include/bottom_footer.php");
+               break;
+       default:
+-              include_once("./include/top_header.php");
+-              utilities();
++              if (!api_plugin_hook_function('utilities_action', $_REQUEST['action'])) {
++                      include_once('./include/top_header.php');
+-              include_once("./include/bottom_footer.php");
++                      utilities();
++
++                      include_once('./include/bottom_footer.php');
++              }
+               break;
+ }
+@@ -1644,6 +1647,8 @@
+       <?php
++      api_plugin_hook('utilities_list');
++
+       html_end_box();
+ }
index f9d0a7f..f66fd06 100644 (file)
@@ -11,3 +11,5 @@ ping.patch
 poller_interval.patch
 606062_ping.pl.patch
 563955_local_data_id.patch
+cacti-plugin-0.8.7g-PA-v2.9.patch
+cacti-pa-sql.patch