]> git.pld-linux.org Git - packages/cacti.git/blob - cacti-PA.patch
5871044f8c6671fd162c790459866d871460d136
[packages/cacti.git] / cacti-PA.patch
1 diff -Naur cacti-0.8.7g-old/auth_changepassword.php cacti-0.8.7g/auth_changepassword.php
2 --- cacti-0.8.7g-old/auth_changepassword.php    2010-07-09 18:33:46.000000000 -0400
3 +++ cacti-0.8.7g/auth_changepassword.php        2010-07-09 18:34:11.000000000 -0400
4 @@ -59,6 +59,8 @@
5                                         header("Location: index.php"); break;
6                                 case '3': /* default graph page */
7                                         header("Location: graph_view.php"); break;
8 +                               default:
9 +                                       api_plugin_hook_function('login_options_navigate', $user['login_opts']);
10                         }
11                 }else{
12                         header("Location: graph_view.php");
13 diff -Naur cacti-0.8.7g-old/auth_login.php cacti-0.8.7g/auth_login.php
14 --- cacti-0.8.7g-old/auth_login.php     2010-07-09 18:33:46.000000000 -0400
15 +++ cacti-0.8.7g/auth_login.php 2010-07-09 18:34:11.000000000 -0400
16 @@ -124,10 +124,12 @@
17                 }
18  
19         default:
20 -               /* Builtin Auth */
21 -               if ((!$user_auth) && (!$ldap_error)) {
22 -                       /* if auth has not occured process for builtin - AKA Ldap fall through */
23 -                       $user = db_fetch_row("SELECT * FROM user_auth WHERE username = '" . $username . "' AND password = '" . md5(get_request_var_post("login_password")) . "' AND realm = 0");
24 +               if (!api_plugin_hook_function('login_process', false)) {
25 +                       /* Builtin Auth */
26 +                       if ((!$user_auth) && (!$ldap_error)) {
27 +                               /* if auth has not occured process for builtin - AKA Ldap fall through */
28 +                               $user = db_fetch_row("SELECT * FROM user_auth WHERE username = '" . $username . "' AND password = '" . md5(get_request_var_post("login_password")) . "' AND realm = 0");
29 +                       }
30                 }
31         }
32         /* end of switch */
33 @@ -189,29 +191,42 @@
34                 decide what to do next */
35                 switch ($user["login_opts"]) {
36                         case '1': /* referer */
37 -                               if (sizeof(db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE realm_id = 8 AND user_id = " . $_SESSION["sess_user_id"])) == 0) {
38 -                                       header("Location: graph_view.php");
39 -                               }else{
40 -                                       if (isset($_SERVER["HTTP_REFERER"])) {
41 -                                               $referer = $_SERVER["HTTP_REFERER"];
42 -                                               if (basename($referer) == "logout.php") {
43 -                                                       $referer = "index.php";
44 -                                               }
45 -                                       } else if (isset($_SERVER["REQUEST_URI"])) {
46 -                                               $referer = $_SERVER["REQUEST_URI"];
47 -                                               if (basename($referer) == "logout.php") {
48 -                                                       $referer = "index.php";
49 -                                               }
50 -                                       } else {
51 -                                               $referer = "index.php";
52 +                               /* because we use plugins, we can't redirect back to graph_view.php if they don't
53 +                                * have console access
54 +                                */
55 +                               if (isset($_SERVER["HTTP_REFERER"])) {
56 +                                       $referer = $_SERVER["HTTP_REFERER"];
57 +                                       if (basename($referer) == "logout.php") {
58 +                                               $referer = $config['url_path'] . "index.php";
59 +                                       }
60 +                               } else if (isset($_SERVER["REQUEST_URI"])) {
61 +                                       $referer = $_SERVER["REQUEST_URI"];
62 +                                       if (basename($referer) == "logout.php") {
63 +                                               $referer = $config['url_path'] . "index.php";
64                                         }
65 +                               } else {
66 +                                       $referer = $config['url_path'] . "index.php";
67 +                               }
68 +
69 +                               if (substr_count($referer, "plugins")) {
70                                         header("Location: " . $referer);
71 +                               } elseif (sizeof(db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE realm_id = 8 AND user_id = " . $_SESSION["sess_user_id"])) == 0) {
72 +                                       header("Location: graph_view.php");
73 +                               } else {
74 +                                       header("Location: $referer");
75                                 }
76 +
77                                 break;
78                         case '2': /* default console page */
79 -                               header("Location: index.php"); break;
80 +                               header("Location: " . $config['url_path'] . "index.php");
81 +
82 +                               break;
83                         case '3': /* default graph page */
84 -                               header("Location: graph_view.php"); break;
85 +                               header("Location: " . $config['url_path'] . "graph_view.php");
86 +
87 +                               break;
88 +                       default:
89 +                               api_plugin_hook_function('login_options_navigate', $user['login_opts']);
90                 }
91                 exit;
92         }else{
93 @@ -264,9 +279,17 @@
94  <body bgcolor="#FFFFFF" onload="document.login.login_username.focus()">
95         <form name="login" method="post" action="<?php print basename($_SERVER["PHP_SELF"]);?>">
96         <input type="hidden" name="action" value="login">
97 +<?php
98 +
99 +api_plugin_hook("login_before");
100 +
101 +$cacti_logo = $config['url_path'] . 'images/auth_login.gif';
102 +$cacti_logo = api_plugin_hook_function('cacti_image', $cacti_logo);
103 +
104 +?>
105         <table align="center">
106                 <tr>
107 -                       <td colspan="2"><img src="images/auth_login.gif" border="0" alt=""></td>
108 +                       <td colspan="2"><center><?php if ($cacti_logo != '') { ?><img src="<?php echo $cacti_logo; ?>" border="0" alt=""><?php } ?></center></td>
109                 </tr>
110                 <?php
111  
112 @@ -303,22 +326,29 @@
113                         <td><input type="password" name="login_password" size="40" style="width: 295px;"></td>
114                 </tr>
115                 <?php
116 -               if (read_config_option("auth_method") == "3") {?>
117 +               if (read_config_option("auth_method") == "3" || api_plugin_hook_function('login_realms_exist')) {
118 +                       $realms = api_plugin_hook_function('login_realms', array("local" => array("name" => "Local", "selected" => false), "ldap" => array("name" => "LDAP", "selected" => true)));
119 +                       ?>
120                 <tr>
121                         <td>Realm:</td>
122                         <td>
123 -                               <select name="realm" style="width: 295px;">
124 -                                       <option value="local">Local</option>
125 -                                       <option value="ldap" selected>LDAP</option>
126 +                               <select name="realm" style="width: 295px;"><?php
127 +                               if (sizeof($realms)) {
128 +                               foreach($realms as $name => $realm) {
129 +                                       print "\t\t\t\t\t<option value='" . $name . "'" . ($realm["selected"] ? " selected":"") . ">" . htmlspecialchars($realm["name"]) . "</option>\n";
130 +                               }
131 +                               }
132 +                               ?>
133                                 </select>
134                         </td>
135 -                       </tr>
136 +               </tr>
137                 <?php }?>
138                 <tr style="height:10px;"><td></td></tr>
139                 <tr>
140                         <td><input type="submit" value="Login"></td>
141                 </tr>
142         </table>
143 +<?php api_plugin_hook('login_after'); ?>
144         </form>
145  </body>
146  </html>
147 --- cacti-0.8.7g/data_sources.php~      2010-12-13 11:59:32.000000000 +0200
148 +++ cacti-0.8.7g/data_sources.php       2010-12-13 12:00:13.152496733 +0200
149 @@ -44,6 +44,8 @@
150         7 => "Disable"
151         );
152  
153 +$ds_actions = api_plugin_hook_function('data_source_action_array', $ds_actions);
154 +
155  /* set default action */
156  if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
157  
158 @@ -402,6 +404,8 @@
159                                 api_reapply_suggested_data_source_title($selected_items[$i]);
160                                 update_data_source_title_cache($selected_items[$i]);
161                         }
162 +               } else {
163 +                       api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']);
164                 }
165                 header("Location: data_sources.php");
166                 exit;
167 @@ -545,6 +549,12 @@
168                                 </tr>\n
169                                 ";
170                         $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)'>";
171 +               }else{
172 +                       $save['drp_action'] = $_POST['drp_action'];
173 +                       $save['ds_list'] = $ds_list;
174 +                       $save['ds_array'] = (isset($ds_array)? $ds_array : array());
175 +                       api_plugin_hook_function('data_source_action_prepare', $save);
176 +                       $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
177                 }
178         }else{
179                 print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one data source.</span></td></tr>\n";
180 @@ -683,6 +693,8 @@
181         input_validate_input_number(get_request_var("host_id"));
182         /* ==================================================== */
183  
184 +       api_plugin_hook('data_source_edit_top');
185 +
186         $use_data_template = true;
187         $host_id = 0;
188  
189 @@ -975,8 +987,9 @@
190  
191         form_save_button("data_sources.php");
192  
193 -       include_once("./include/bottom_footer.php");
194 +       api_plugin_hook('data_source_edit_bottom');
195  
196 +       include_once("./include/bottom_footer.php");
197  }
198  
199  function get_poller_interval($seconds) {
200 @@ -1323,6 +1323,7 @@
201         $i = 0;
202         if (sizeof($data_sources) > 0) {
203                 foreach ($data_sources as $data_source) {
204 +                       $data_source = api_plugin_hook_function('data_sources_table', $data_source);
205                         /* we're escaping strings here, so no need to escape them on form_selectable_cell */
206                         $data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : htmlspecialchars($data_source["data_template_name"]));
207                         $data_input_name    = ((empty($data_source["data_input_name"])) ? "<em>External</em>" : htmlspecialchars($data_source["data_input_name"]));
208 diff -Naur cacti-0.8.7g-old/graph_image.php cacti-0.8.7g/graph_image.php
209 --- cacti-0.8.7g-old/graph_image.php    2010-07-09 18:33:46.000000000 -0400
210 +++ cacti-0.8.7g/graph_image.php        2010-07-09 18:34:11.000000000 -0400
211 @@ -44,6 +44,8 @@
212  /* flush the headers now */
213  ob_end_clean();
214  
215 +api_plugin_hook_function('graph_image');
216 +
217  session_write_close();
218  
219  $graph_data_array = array();
220 diff -Naur cacti-0.8.7g-old/graph.php cacti-0.8.7g/graph.php
221 --- cacti-0.8.7g-old/graph.php  2010-07-09 18:33:46.000000000 -0400
222 +++ cacti-0.8.7g/graph.php      2010-07-09 18:34:11.000000000 -0400
223 @@ -32,6 +32,8 @@
224  include_once("./lib/html_tree.php");
225  include_once("./include/top_graph_header.php");
226  
227 +api_plugin_hook_function('graph');
228 +
229  /* ================= input validation ================= */
230  input_validate_input_regex(get_request_var("rra_id"), "^([0-9]+|all)$");
231  input_validate_input_number(get_request_var("local_graph_id"));
232 @@ -94,17 +96,18 @@
233                                         <table width='1' cellpadding='0'>
234                                                 <tr>
235                                                         <td>
236 -                                                               <img class='graphimage' id='graph_<?php print $_GET["local_graph_id"] ?>' src='<?php print htmlspecialchars("graph_image.php?action=view&local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $rra["id"]);?>' border='0' alt='<?php print htmlspecialchars($graph_title);?>'>
237 +                                                                       <img class='graphimage' id='graph_<?php print $_GET["local_graph_id"] ?>' src='<?php print htmlspecialchars("graph_image.php?action=view&local_graph_id=" . $_GET["local_graph_id"] . "&rra_id=" . $rra["id"]);?>' border='0' alt='<?php print htmlspecialchars($graph_title);?>'>
238                                                         </td>
239                                                         <td valign='top' style='padding: 3px;' class='noprint'>
240                                                                 <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>
241                                                                 <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>
242                                                                 <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>
243 +                                                               <?php api_plugin_hook('graph_buttons', array('hook' => 'view', 'local_graph_id' => $_GET['local_graph_id'], 'rra' => $rra['id'], 'view_type' => $_REQUEST['view_type'])); ?>
244                                                         </td>
245                                                 </tr>
246                                                 <tr>
247                                                         <td colspan='2' align='center'>
248 -                                                               <strong><?php print htmlspecialchars($rra["name"]);?></strong>
249 +                                                                       <strong><?php print htmlspecialchars($rra["name"]);?></strong>
250                                                         </td>
251                                                 </tr>
252                                         </table>
253 @@ -215,6 +218,7 @@
254                                         <td valign='top' style='padding: 3px;' class='noprint'>
255                                                 <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>
256                                                 <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>
257 +                                               <?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'])); ?>
258                                         </td>
259                                 </tr>
260                                 <tr>
261 @@ -247,6 +251,7 @@
262                                         <td valign='top' style='padding: 3px;'>
263                                                 <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>
264                                                 <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>
265 +                                               <?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'])); ?>
266                                         </td>
267                                 </tr>
268                                 <tr>
269 diff -Naur cacti-0.8.7g-old/graphs_new.php cacti-0.8.7g/graphs_new.php
270 --- cacti-0.8.7g-old/graphs_new.php     2010-07-09 18:33:46.000000000 -0400
271 +++ cacti-0.8.7g/graphs_new.php 2010-07-09 18:34:11.000000000 -0400
272 @@ -511,7 +511,8 @@
273                         </td>
274                         <td nowrap style='white-space: nowrap;' class="textInfo" align="center" valign="top">
275                                 <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>
276 -                               <span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php print htmlspecialchars("host.php?action=edit");?>">Create New Host</a>
277 +                               <span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php print htmlspecialchars("host.php?action=edit");?>">Create New Host</a><br>
278 +                               <?php api_plugin_hook('graphs_new_top_links'); ?>
279                         </td>
280                 </tr>
281         </table>
282 diff -Naur cacti-0.8.7g-old/graphs.php cacti-0.8.7g/graphs.php
283 --- cacti-0.8.7g-old/graphs.php 2010-07-09 18:33:46.000000000 -0400
284 +++ cacti-0.8.7g/graphs.php     2010-07-09 18:34:11.000000000 -0400
285 @@ -45,6 +45,8 @@
286         4 => "Convert to Graph Template"
287         );
288  
289 +$graph_actions = api_plugin_hook_function('graphs_action_array', $graph_actions);
290 +
291  /* set default action */
292  if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
293  
294 @@ -362,6 +364,8 @@
295  
296                                 api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
297                         }
298 +               } else {
299 +                       api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
300                 }
301  
302                 header("Location: graphs.php");
303 @@ -514,6 +518,12 @@
304                                 ";
305  
306                         $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
307 +               } else {
308 +                       $save['drp_action'] = $_POST['drp_action'];
309 +                       $save['graph_list'] = $graph_list;
310 +                       $save['graph_array'] = (isset($graph_array) ? $graph_array : array());
311 +                       api_plugin_hook_function('graphs_action_prepare', $save);
312 +                       $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
313                 }
314         }else{
315                 print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
316 diff -Naur cacti-0.8.7g-old/host.php cacti-0.8.7g/host.php
317 --- cacti-0.8.7g-old/host.php   2010-07-09 18:33:46.000000000 -0400
318 +++ cacti-0.8.7g/host.php       2010-07-09 18:34:11.000000000 -0400
319 @@ -44,6 +44,8 @@
320         6 => "Change Availability Options"
321         );
322  
323 +$device_actions = api_plugin_hook_function('device_action_array', $device_actions);
324 +
325  /* set default action */
326  if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
327  
328 @@ -305,6 +307,8 @@
329  
330                                 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);
331                         }
332 +               } else {
333 +                       api_plugin_hook_function('device_action_execute', $_POST['drp_action']); 
334                 }
335  
336                 header("Location: host.php");
337 @@ -450,6 +454,12 @@
338                                 <input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
339                                 ";
340                         $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
341 +               } else {
342 +                       $save['drp_action'] = $_POST['drp_action'];
343 +                       $save['host_list'] = $host_list;
344 +                       $save['host_array'] = (isset($host_array)? $host_array : array());
345 +                       api_plugin_hook_function('device_action_prepare', $save);
346 +                       $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
347                 }
348         }else{
349                 print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
350 @@ -532,6 +542,8 @@
351         input_validate_input_number(get_request_var("id"));
352         /* ==================================================== */
353  
354 +       api_plugin_hook('host_edit_top');
355 +
356         if (!empty($_GET["id"])) {
357                 $host = db_fetch_row("select * from host where id=" . $_GET["id"]);
358                 $header_label = "[edit: " . htmlspecialchars($host["description"]) . "]";
359 @@ -643,6 +655,7 @@
360                                         <span style="color: #c16921;">*</span><a href="<?php print htmlspecialchars("graphs_new.php?host_id=" . $host["id"]);?>">Create Graphs for this Host</a><br>
361                                         <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>
362                                         <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>
363 +                                       <?php api_plugin_hook('device_edit_top_links'); ?>
364                                 </td>
365                         </tr>
366                 </table>
367 @@ -1107,6 +1120,8 @@
368         }
369  
370         form_save_button("host.php", "return");
371 +
372 +       api_plugin_hook('host_edit_bottom');
373  }
374  
375  function host() {
376 diff -Naur cacti-0.8.7g-old/include/auth.php cacti-0.8.7g/include/auth.php
377 --- cacti-0.8.7g-old/include/auth.php   2010-07-09 18:33:46.000000000 -0400
378 +++ cacti-0.8.7g/include/auth.php       2010-07-09 18:34:11.000000000 -0400
379 @@ -31,6 +31,9 @@
380  }
381  
382  if (read_config_option("auth_method") != 0) {
383 +       /* handle alternate authentication realms */
384 +       api_plugin_hook_function('auth_alternate_realms');
385 +
386         /* handle change password dialog */
387         if ((isset($_SESSION['sess_change_password'])) && (read_config_option("webbasic_enabled") != "on")) {
388                 header ("Location: auth_changepassword.php?ref=" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"));
389 @@ -72,9 +75,9 @@
390                         and user_auth_realm.realm_id='$realm_id'")) || (empty($realm_id)))) {
391  
392                         if (isset($_SERVER["HTTP_REFERER"])) {
393 -                               $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='" . htmlspecialchars($_SERVER["HTTP_REFERER"]) . "'>Return</a> | <a href='logout.php'>Login Again</a> )</td>";
394 +                               $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>";
395                         }else{
396 -                               $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='logout.php'>Login Again</a> )</td>";
397 +                               $goBack = "<td class='textArea' colspan='2' align='center'>( <a href='" . $config['url_path'] . "logout.php'>Login Again</a> )</td>";
398                         }
399  
400                         ?>
401 @@ -83,14 +86,14 @@
402                         <head>
403                                 <title>Cacti</title>
404                                 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
405 -                               <link href="include/main.css" type="text/css" rel="stylesheet">
406 +                               <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
407                         </head>
408                         <body>
409                         <br><br>
410  
411                         <table width="450" align='center'>
412                                 <tr>
413 -                                       <td colspan='2'><img src='images/auth_deny.gif' border='0' alt='Access Denied'></td>
414 +                                       <td colspan='2'><img src='<?php echo $config['url_path']; ?>images/auth_deny.gif' border='0' alt='Access Denied'></td>
415                                 </tr>
416                                 <tr style='height:10px;'><td></td></tr>
417                                 <tr>
418 diff -Naur cacti-0.8.7g-old/include/bottom_footer.php cacti-0.8.7g/include/bottom_footer.php
419 --- cacti-0.8.7g-old/include/bottom_footer.php  2010-07-09 18:33:46.000000000 -0400
420 +++ cacti-0.8.7g/include/bottom_footer.php      2010-07-09 18:34:11.000000000 -0400
421 @@ -21,6 +21,10 @@
422   | http://www.cacti.net/                                                   |
423   +-------------------------------------------------------------------------+
424  */
425 +
426 +$oper_mode = api_plugin_hook_function('top_header', OPER_MODE_NATIVE);
427 +if (($oper_mode == OPER_MODE_NATIVE) || ($oper_mode == OPER_MODE_IFRAME_NONAV)) {
428 +
429  ?>
430                         </div>
431                         <br>
432 @@ -32,6 +36,9 @@
433  </html>
434  
435  <?php
436 +
437 +}
438 +
439  /* we use this session var to store field values for when a save fails,
440  this way we can restore the field's previous values. we reset it here, because
441  they only need to be stored for a single page */
442 diff -Naur cacti-0.8.7g-old/include/config.php cacti-0.8.7g/include/config.php
443 --- cacti-0.8.7g-old/include/config.php 2010-07-09 18:33:46.000000000 -0400
444 +++ cacti-0.8.7g/include/config.php     2010-07-09 18:34:11.000000000 -0400
445 @@ -30,6 +30,17 @@
446  $database_password = "cactiuser";
447  $database_port = "3306";
448  
449 +/* load up old style plugins here */
450 +$plugins = array();
451 +//$plugins[] = 'thold';
452 +
453 +/*
454 +   Edit this to point to the default URL of your Cacti install
455 +   ex: if your cacti install as at http://serverip/cacti/ this
456 +   would be set to /cacti/
457 +*/
458 +$url_path = "/";
459 +
460  /* Default session name - Session name must contain alpha characters */
461  #$cacti_session_name = "Cacti";
462  
463 diff -Naur cacti-0.8.7g-old/include/global_arrays.php cacti-0.8.7g/include/global_arrays.php
464 --- cacti-0.8.7g-old/include/global_arrays.php  2010-07-09 18:33:46.000000000 -0400
465 +++ cacti-0.8.7g/include/global_arrays.php      2010-07-09 18:34:11.000000000 -0400
466 @@ -22,6 +22,8 @@
467   +-------------------------------------------------------------------------+
468  */
469  
470 +global $menu;
471 +
472  $messages = array(
473         1  => array(
474                 "message" => 'Save Successful.',
475 @@ -654,4 +656,10 @@
476         GDC_SLASH => "/"
477         );
478  
479 +$plugin_architecture = array(
480 +       'version' => '2.8'
481 +       );
482 +
483 +api_plugin_hook('config_arrays');
484 +
485  ?>
486 diff -Naur cacti-0.8.7g-old/include/global_constants.php cacti-0.8.7g/include/global_constants.php
487 --- cacti-0.8.7g-old/include/global_constants.php       2010-07-09 18:33:46.000000000 -0400
488 +++ cacti-0.8.7g/include/global_constants.php   2010-07-09 18:34:11.000000000 -0400
489 @@ -173,4 +173,8 @@
490  define("SNMP_CMDPHP", 1);
491  define("SNMP_WEBUI", 2);
492  
493 -?>
494 +define('OPER_MODE_NATIVE', 0);
495 +define('OPER_MODE_RESKIN', 1);
496 +define('OPER_MODE_IFRAME_NONAV', 2);
497 +
498 +?>
499 \ No newline at end of file
500 diff -Naur cacti-0.8.7g-old/include/global_form.php cacti-0.8.7g/include/global_form.php
501 --- cacti-0.8.7g-old/include/global_form.php    2010-07-09 18:33:46.000000000 -0400
502 +++ cacti-0.8.7g/include/global_form.php        2010-07-09 18:34:11.000000000 -0400
503 @@ -22,8 +22,9 @@
504   +-------------------------------------------------------------------------+
505  */
506  
507 -if (!defined("VALID_HOST_FIELDS")) {
508 -       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)");
509 +if (!defined('VALID_HOST_FIELDS')) {
510 +       $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)');
511 +       define('VALID_HOST_FIELDS', $string);
512  }
513  
514  /* file: cdef.php, action: edit */
515 @@ -1190,4 +1191,7 @@
516                 "dropdown_sql" => "select id,name from snmp_query order by name"
517                 )
518         );
519 -?>
520 +
521 +
522 +api_plugin_hook('config_form');
523 +
524 diff -Naur cacti-0.8.7g-old/include/global.php cacti-0.8.7g/include/global.php
525 --- cacti-0.8.7g-old/include/global.php 2010-07-09 18:33:46.000000000 -0400
526 +++ cacti-0.8.7g/include/global.php     2010-07-09 18:34:11.000000000 -0400
527 @@ -93,6 +93,13 @@
528  /* built-in snmp support */
529  $config["php_snmp_support"] = function_exists("snmpget");
530  
531 +/* set URL path */
532 +if (! isset($url_path)) { 
533 +       $url_path = "";
534 +}
535 +$config['url_path'] = $url_path;
536 +define('URL_PATH', $url_path);
537 +
538  /* used for includes */
539  $config["base_path"] = strtr(ereg_replace("(.*)[\\\/]include", "\\1", dirname(__FILE__)), "\\", "/");
540  $config["library_path"] = ereg_replace("(.*[\\\/])include", "\\1lib", dirname(__FILE__));
541 @@ -188,15 +195,17 @@
542  /* include base modules */
543  include($config["library_path"] . "/adodb/adodb.inc.php");
544  include($config["library_path"] . "/database.php");
545 -include_once($config["library_path"] . "/functions.php");
546 -include_once($config["include_path"] . "/global_constants.php");
547 -include_once($config["include_path"] . "/global_arrays.php");
548 -include_once($config["include_path"] . "/global_settings.php");
549  
550  /* connect to the database server */
551  db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port);
552  
553  /* include additional modules */
554 +include_once($config["library_path"] . "/functions.php");
555 +include_once($config["include_path"] . "/global_constants.php");
556 +include_once($config["library_path"] . "/plugins.php");
557 +include_once($config["include_path"] . "/plugins.php");
558 +include_once($config["include_path"] . "/global_arrays.php");
559 +include_once($config["include_path"] . "/global_settings.php");
560  include_once($config["include_path"] . "/global_form.php");
561  include_once($config["library_path"] . "/html.php");
562  include_once($config["library_path"] . "/html_form.php");
563 @@ -205,6 +214,8 @@
564  include_once($config["library_path"] . "/variables.php");
565  include_once($config["library_path"] . "/auth.php");
566  
567 +api_plugin_hook("config_insert");
568 +
569  /* current cacti version */
570  $config["cacti_version"] = "0.8.7g";
571  
572 diff -Naur cacti-0.8.7g-old/include/global_settings.php cacti-0.8.7g/include/global_settings.php
573 --- cacti-0.8.7g-old/include/global_settings.php        2010-07-09 18:33:46.000000000 -0400
574 +++ cacti-0.8.7g/include/global_settings.php    2010-07-09 18:34:11.000000000 -0400
575 @@ -1190,4 +1190,6 @@
576                 )
577         );
578  
579 +api_plugin_hook('config_settings');
580 +
581  ?>
582 diff -Naur cacti-0.8.7g-old/include/plugins.php cacti-0.8.7g/include/plugins.php
583 --- cacti-0.8.7g-old/include/plugins.php        1969-12-31 19:00:00.000000000 -0500
584 +++ cacti-0.8.7g/include/plugins.php    2010-07-09 18:34:11.000000000 -0400
585 @@ -0,0 +1,38 @@
586 +<?php
587 +
588 +/*
589 + * Copyright (c) 1999-2005 The SquirrelMail Project Team (http://squirrelmail.org)
590 + * Licensed under the GNU GPL. For full terms see the file COPYING.
591 + */
592 +
593 +global $plugin_hooks, $plugins_system;
594 +$plugin_hooks = array();
595 +$plugins_system = array('settings', 'boost', 'dsstats');
596 +
597 +function use_plugin ($name) {
598 +       global $config;
599 +       if (file_exists($config['base_path'] . "/plugins/$name/setup.php")) {
600 +               include_once($config['base_path'] . "/plugins/$name/setup.php");
601 +               $function = "plugin_init_$name";
602 +               if (function_exists($function)) {
603 +                       $function();
604 +               }
605 +       }
606 +}
607 +
608 +/**
609 + * This function executes a hook.
610 + * @param string $name Name of hook to fire
611 + * @return mixed $data
612 + */
613 +
614 +$oldplugins = read_config_option('oldplugins');
615 +$oldplugins = explode(',', $oldplugins);
616 +$plugins = array_merge($plugins, $oldplugins);
617 +
618 +/* On startup, register all plugins configured for use. */
619 +if (isset($plugins) && is_array($plugins)) {
620 +       foreach ($plugins as $name) {
621 +               use_plugin($name);
622 +       }
623 +}
624 diff -Naur cacti-0.8.7g-old/include/top_graph_header.php cacti-0.8.7g/include/top_graph_header.php
625 --- cacti-0.8.7g-old/include/top_graph_header.php       2010-07-09 18:33:46.000000000 -0400
626 +++ cacti-0.8.7g/include/top_graph_header.php   2010-07-09 18:34:11.000000000 -0400
627 @@ -25,6 +25,11 @@
628  $using_guest_account = false;
629  $show_console_tab = true;
630  
631 +$oper_mode = api_plugin_hook_function('top_header', OPER_MODE_NATIVE);
632 +if ($oper_mode == OPER_MODE_RESKIN) {
633 +       return;
634 +}
635 +
636  /* ================= input validation ================= */
637  input_validate_input_number(get_request_var_request("local_graph_id"));
638  input_validate_input_number(get_request_var_request("graph_start"));
639 @@ -52,41 +57,53 @@
640         $_SESSION["sess_nav_level_cache"][2]["url"] = "graph.php?local_graph_id=" . $_REQUEST["local_graph_id"] . "&rra_id=all";
641  }
642  
643 +$page_title = api_plugin_hook_function('page_title', draw_navigation_text("title"));
644 +
645  ?>
646  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
647  <html>
648  <head>
649 -       <title><?php echo draw_navigation_text("title");?></title>
650 +       <title><?php echo $page_title; ?></title>
651         <?php
652         if (isset($_SESSION["custom"]) && $_SESSION["custom"] == true) {
653                 print "<meta http-equiv=refresh content='99999'>\r\n";
654         }else{
655 -               print "<meta http-equiv=refresh content='" . htmlspecialchars(read_graph_config_option("page_refresh"),ENT_QUOTES) . "'>\r\n";
656 +               $refresh = api_plugin_hook_function('top_graph_refresh', htmlspecialchars(read_graph_config_option("page_refresh"),ENT_QUOTES));
657 +               print "<meta http-equiv=refresh content='" . $refresh . "'>\r\n";
658         }
659         ?>
660         <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
661 -       <link href="include/main.css" type="text/css" rel="stylesheet">
662 -       <link href="images/favicon.ico" rel="shortcut icon"/>
663 -       <script type="text/javascript" src="include/layout.js"></script>
664 -       <script type="text/javascript" src="include/treeview/ua.js"></script>
665 -       <script type="text/javascript" src="include/treeview/ftiens4.js"></script>
666 -       <script type="text/javascript" src="include/jscalendar/calendar.js"></script>
667 -       <script type="text/javascript" src="include/jscalendar/lang/calendar-en.js"></script>
668 -       <script type="text/javascript" src="include/jscalendar/calendar-setup.js"></script>
669 +       <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
670 +       <link href="<?php echo $config['url_path']; ?>images/favicon.ico" rel="shortcut icon"/>
671 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/layout.js"></script>
672 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/treeview/ua.js"></script>
673 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/treeview/ftiens4.js"></script>
674 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar.js"></script>
675 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/lang/calendar-en.js"></script>
676 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar-setup.js"></script>
677 +       <?php api_plugin_hook('page_head'); ?>
678  </head>
679  
680 -<body>
681 +<?php if ($oper_mode == OPER_MODE_NATIVE) {?>
682 +<body <?php print api_plugin_hook_function("body_style", "");?>>
683  <a name='page_top'></a>
684 +<?php }else{?>
685 +<body <?php print api_plugin_hook_function("body_style", "");?>>
686 +<?php }?>
687 +
688  <table style="width:100%;height:100%;" cellspacing="0" cellpadding="0">
689 +<?php if ($oper_mode == OPER_MODE_NATIVE) { ;?>
690         <tr style="height:25px;" bgcolor="#a9a9a9" class="noprint">
691                 <td colspan="2" valign="bottom" nowrap>
692                         <table width="100%" cellspacing="0" cellpadding="0">
693 -                               <tr style="background: transparent url('images/cacti_backdrop2.gif') no-repeat center right;">
694 +                               <tr style="background: transparent url('<?php echo $config['url_path']; ?>images/cacti_backdrop2.gif') no-repeat center right;">
695                                         <td id="tabs" nowrap>
696 -                                               &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;
697 +                                               &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
698 +                                               api_plugin_hook('top_graph_header_tabs');
699 +                                               ?>
700                                         </td>
701                                         <td id="gtabs" align="right" nowrap>
702 -                                               <?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>
703 +                                               <?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>
704                                         </td>
705                                 </tr>
706                         </table>
707 @@ -94,7 +111,7 @@
708         </tr>
709         <tr style="height:2px;" bgcolor="#183c8f" class="noprint">
710                 <td colspan="2">
711 -                       <img src="images/transparent_line.gif" style="height:2px;width:170px;" border="0"><br>
712 +                       <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:2px;width:170px;" border="0"><br>
713                 </td>
714         </tr>
715         <tr style="height:5px;" bgcolor="#e9e9e9" class="noprint">
716 @@ -106,7 +123,7 @@
717                                         </td>
718                                         <td align="right">
719                                                 <?php if ((isset($_SESSION["sess_user_id"])) && ($using_guest_account == false)) { ?>
720 -                                               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;
721 +                                               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;
722                                                 <?php } ?>
723                                         </td>
724                                 </tr>
725 @@ -114,10 +131,10 @@
726                 </td>
727         </tr>
728         <tr class="noprint">
729 -               <td bgcolor="#efefef" colspan="1" style="height:8px;background-image: url(images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;">
730 -                       <img src="images/transparent_line.gif" width="<?php print htmlspecialchars(read_graph_config_option("default_dual_pane_width"));?>" style="height:2px;" border="0"><br>
731 +               <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;">
732 +                       <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>
733                 </td>
734 -               <td bgcolor="#ffffff" colspan="1" style="height:8px;background-image: url(images/shadow.gif); background-repeat: repeat-x;">
735 +               <td bgcolor="#ffffff" colspan="1" style="height:8px;background-image: url(<?php echo $config['url_path']; ?>images/shadow.gif); background-repeat: repeat-x;">
736  
737                 </td>
738         </tr>
739 @@ -143,6 +160,8 @@
740                 </td>
741         </tr>
742         <?php }
743 +       }
744 +       global $graph_views;
745         load_current_session_value("action", "sess_cacti_graph_action", $graph_views[read_graph_config_option("default_tree_view_mode")]);
746         ?>
747         <tr>
748 diff -Naur cacti-0.8.7g-old/include/top_header.php cacti-0.8.7g/include/top_header.php
749 --- cacti-0.8.7g-old/include/top_header.php     2010-07-09 18:33:46.000000000 -0400
750 +++ cacti-0.8.7g/include/top_header.php 2010-07-09 18:34:11.000000000 -0400
751 @@ -22,38 +22,53 @@
752   +-------------------------------------------------------------------------+
753  */
754  
755 -global $colors;
756 +global $colors, $config;
757 +
758 +$oper_mode = api_plugin_hook_function('top_header', OPER_MODE_NATIVE);
759 +if ($oper_mode == OPER_MODE_RESKIN) {
760 +       return;
761 +}
762 +
763 +$page_title = api_plugin_hook_function('page_title', draw_navigation_text("title"));
764 +
765  ?>
766  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
767  <html>
768  <head>
769 -       <title><?php echo draw_navigation_text("title");?></title>
770 -       <link href="include/main.css" type="text/css" rel="stylesheet">
771 -       <link href="images/favicon.ico" rel="shortcut icon"/>
772 +       <title><?php echo $page_title; ?></title>
773 +       <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
774 +       <link href="<?php echo $config['url_path']; ?>images/favicon.ico" rel="shortcut icon">
775         <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
776 -       <script type="text/javascript" src="include/layout.js"></script>
777 +       <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/layout.js"></script>
778         <?php if (isset($refresh)) {
779         print "<meta http-equiv=refresh content=\"" . $refresh["seconds"] . "; url='" . $refresh["page"] . "'\">";
780 -       }?>
781 +       }
782 +       api_plugin_hook('page_head'); ?>
783  </head>
784  
785 -<body style="background-image:url('images/left_border.gif');background-repeat:repeat-y;">
786 +<?php if ($oper_mode == OPER_MODE_NATIVE) {?>
787 +<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", "");?>>
788 +<?php }else{?>
789 +<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", "");?>>
790 +<?php }?>
791  
792  <table width="100%" cellspacing="0" cellpadding="0">
793 +<?php if ($oper_mode == OPER_MODE_NATIVE) { ;?>
794         <tr style="height:1px;" bgcolor="#a9a9a9">
795                 <td valign="bottom" colspan="3" nowrap>
796                         <table width="100%" cellspacing="0" cellpadding="0">
797 -                               <tr style="background: transparent url('images/cacti_backdrop.gif') no-repeat center right;">
798 +                               <tr style="background: transparent url('<?php echo $config['url_path']; ?>images/cacti_backdrop.gif') no-repeat center right;">
799                                         <td id="tabs" valign="bottom">
800 -                                               &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>
801 -                                       </td>
802 +                                               &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
803 +                                               api_plugin_hook('top_header_tabs');
804 +                                       ?></td>
805                                 </tr>
806                         </table>
807                 </td>
808         </tr>
809         <tr style="height:2px;" bgcolor="#183c8f">
810                 <td colspan="3">
811 -                       <img src="images/transparent_line.gif" style="height:2px;" border="0"><br>
812 +                       <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:2px;" border="0"><br>
813                 </td>
814         </tr>
815         <tr style="height:5px;" bgcolor="#e9e9e9">
816 @@ -65,7 +80,7 @@
817                                         </td>
818                                         <td align="right">
819                                                 <?php if (read_config_option("auth_method") != 0) { ?>
820 -                                               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;
821 +                                               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;
822                                                 <?php } ?>
823                                         </td>
824                                 </tr>
825 @@ -73,10 +88,10 @@
826                 </td>
827         </tr>
828         <tr>
829 -               <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;">
830 -                       <img src="images/transparent_line.gif" style="height:2px;width:135px;" border="0"><br>
831 +               <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;">
832 +                       <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:2px;width:135px;" border="0"><br>
833                 </td>
834 -               <td colspan="2" style="height:8px;background-image: url(images/shadow.gif); background-repeat: repeat-x;" bgcolor="#ffffff">
835 +               <td colspan="2" style="height:8px;background-image: url(<?php echo $config['url_path']; ?>images/shadow.gif); background-repeat: repeat-x;" bgcolor="#ffffff">
836  
837                 </td>
838         </tr>
839 @@ -86,9 +101,12 @@
840                                 <?php draw_menu();?>
841                         </table>
842  
843 -                       <img src="images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
844 -                       <p align="center"><a href='about.php'><img src="images/cacti_logo.gif" border="0"></a></p>
845 -                       <img src="images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
846 +                       <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
847 +                       <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>
848 +                       <img src="<?php echo $config['url_path']; ?>images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br>
849                 </td>
850                 <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'>
851 -
852 +<?php }else{ ?>
853 +       <tr>
854 +               <td width="100%" valign="top"><?php display_output_messages();?>
855 +<?php } ?>
856 diff -Naur cacti-0.8.7g-old/index.php cacti-0.8.7g/index.php
857 --- cacti-0.8.7g-old/index.php  2010-07-09 18:33:46.000000000 -0400
858 +++ cacti-0.8.7g/index.php      2010-07-09 18:34:11.000000000 -0400
859 @@ -25,6 +25,8 @@
860  include("./include/auth.php");
861  include("./include/top_header.php");
862  
863 +api_plugin_hook('console_before');
864 +
865  ?>
866  <table width="100%" align="center">
867         <tr>
868 @@ -46,6 +48,8 @@
869  
870  <?php
871  
872 +api_plugin_hook('console_after');
873 +
874  include("./include/bottom_footer.php");
875  
876  ?>
877 diff -Naur cacti-0.8.7g-old/lib/api_device.php cacti-0.8.7g/lib/api_device.php
878 --- cacti-0.8.7g-old/lib/api_device.php 2010-07-09 18:33:46.000000000 -0400
879 +++ cacti-0.8.7g/lib/api_device.php     2010-07-09 18:34:11.000000000 -0400
880 @@ -137,6 +137,8 @@
881         $save["ping_retries"]         = form_input_validate($ping_retries, "ping_retries", "^[0-9]+$", true, 3);
882         $save["max_oids"]             = form_input_validate($max_oids, "max_oids", "^[0-9]+$", true, 3);
883  
884 +       $save = api_plugin_hook_function('api_device_save', $save);
885 +
886         $host_id = 0;
887  
888         if (!is_error_message()) {
889 diff -Naur cacti-0.8.7g-old/lib/auth.php cacti-0.8.7g/lib/auth.php
890 --- cacti-0.8.7g-old/lib/auth.php       2010-07-09 18:33:46.000000000 -0400
891 +++ cacti-0.8.7g/lib/auth.php   2010-07-09 18:34:11.000000000 -0400
892 @@ -121,8 +121,9 @@
893                 }
894         }
895  
896 -       return true;
897 +       api_plugin_hook_function('copy_user', array('template_id' => $template_id, 'new_id' => $new_id));
898  
899 +       return true;
900  }
901  
902  
903 @@ -152,6 +153,7 @@
904         db_execute("delete from settings_graphs where user_id=" . $user_id);
905         db_execute("delete from settings_tree where user_id=" . $user_id);
906  
907 +       api_plugin_hook_function('user_remove', $user_id);
908  }
909  
910  /* user_disable - disable a user account
911 diff -Naur cacti-0.8.7g-old/lib/functions.php cacti-0.8.7g/lib/functions.php
912 --- cacti-0.8.7g-old/lib/functions.php  2010-07-09 18:33:46.000000000 -0400
913 +++ cacti-0.8.7g/lib/functions.php      2010-07-09 18:34:11.000000000 -0400
914 @@ -1689,6 +1689,8 @@
915     @arg $type - (string) Either 'url' or 'title'
916     @returns (string> Either the navigation text or title */
917  function draw_navigation_text($type = "url") {
918 +       global $config;
919 +
920         $nav_level_cache = (isset($_SESSION["sess_nav_level_cache"]) ? $_SESSION["sess_nav_level_cache"] : array());
921  
922         $nav = array(
923 @@ -1701,8 +1703,8 @@
924                 "graph.php:zoom" => array("title" => "Zoom", "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"),
925                 "graph.php:properties" => array("title" => "Properties", "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"),
926                 "graph_settings.php:" => array("title" => "Settings", "mapping" => "graph_view.php:", "url" => "graph_settings.php", "level" => "1"),
927 -               "index.php:" => array("title" => "Console", "mapping" => "", "url" => "index.php", "level" => "0"),
928 -               "index.php:login" => array("title" => "Console", "mapping" => "", "url" => "index.php", "level" => "0"),
929 +               "index.php:" => array("title" => "Console", "mapping" => "", "url" => $config['url_path'] . "index.php", "level" => "0"),
930 +               "index.php:login" => array("title" => "Console", "mapping" => "", "url" => $config['url_path'] . "index.php", "level" => "0"),
931                 "graphs.php:" => array("title" => "Graph Management", "mapping" => "index.php:", "url" => "graphs.php", "level" => "1"),
932                 "graphs.php:graph_edit" => array("title" => "(Edit)", "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"),
933                 "graphs.php:graph_diff" => array("title" => "Change Graph Template", "mapping" => "index.php:,graphs.php:,graphs.php:graph_edit", "url" => "", "level" => "3"),
934 @@ -1780,6 +1782,8 @@
935                 "templates_import.php:" => array("title" => "Import Templates", "mapping" => "index.php:", "url" => "templates_import.php", "level" => "1"),
936                 );
937  
938 +       $nav =  api_plugin_hook_function('draw_navigation_text', $nav);
939 +
940         $current_page = basename($_SERVER["PHP_SELF"]);
941  
942         input_validate_input_regex(get_request_var_request("action"), "^([a-zA-Z0-9_-]+)$");
943 diff -Naur cacti-0.8.7g-old/lib/html_form.php cacti-0.8.7g/lib/html_form.php
944 --- cacti-0.8.7g-old/lib/html_form.php  2010-07-09 18:33:46.000000000 -0400
945 +++ cacti-0.8.7g/lib/html_form.php      2010-07-09 18:34:11.000000000 -0400
946 @@ -722,11 +722,13 @@
947       on a confirmation form
948     @arg $cancel_url - the url to go to when the user clicks 'cancel'
949     @arg $action_url - the url to go to when the user clicks 'delete' */
950 -function form_confirm_buttons($action_url, $cancel_url) { ?>
951 +function form_confirm_buttons($action_url, $cancel_url) {
952 +       global $config;
953 +       ?>
954         <tr>
955                 <td bgcolor="#E1E1E1">
956 -                       <input type='button' onClick='cactiReturnTo("<?php print $cancel_url;?>")' value='Cancel'>
957 -                       <input type='submit' onClick='cactiReturnTo("<?php print $action_url;?>&confirm=true")' value='Delete'>
958 +                       <input type='button' onClick='cactiReturnTo("<?php print $config['url_path'] . $cancel_url;?>")' value='Cancel'>
959 +                       <input type='submit' onClick='cactiReturnTo("<?php print $config['url_path'] . $action_url;?>&confirm=true")' value='Delete'>
960                 </td>
961         </tr>
962  <?php }
963 diff -Naur cacti-0.8.7g-old/lib/html.php cacti-0.8.7g/lib/html.php
964 --- cacti-0.8.7g-old/lib/html.php       2010-07-09 18:33:46.000000000 -0400
965 +++ cacti-0.8.7g/lib/html.php   2010-07-09 18:34:11.000000000 -0400
966 @@ -144,14 +144,15 @@
967                                         <table align='center' cellpadding='0'>
968                                                 <tr>
969                                                         <td align='center'>
970 -                                                               <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>
971 +                                                               <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>
972                                                                 <?php print (read_graph_config_option("show_graph_title") == "on" ? "<p style='font-size: 10;' align='center'><strong>" . htmlspecialchars($graph["title_cache"]) . "</strong></p>" : "");?>
973                                                         </td>
974                                                         <td valign='top' style='align: left; padding: 3px;' class='noprint'>
975 -                                                               <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>
976 -                                                               <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>
977 -                                                               <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>
978 -                                                               <a href='#page_top'><img src='images/graph_page_top.gif' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
979 +                                                               <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>
980 +                                                               <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>
981 +                                                               <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>
982 +                                                               <?php api_plugin_hook('graph_buttons', array('hook' => 'graphs_thumbnails', 'local_graph_id' => $graph['local_graph_id'], 'rra' =>  0, 'view_type' => 'view')); ?>
983 +                                                               <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>
984                                                         </td>
985                                                 </tr>
986                                         </table>
987 @@ -177,6 +178,7 @@
988     @arg $extra_url_args - extra arguments to append to the url
989     @arg $header - html to use as a header */
990  function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = "", $extra_url_args = "", $header = "") {
991 +       global $config;
992         $i = 0; $k = 0; $j = 0;
993  
994         $num_graphs = sizeof($graph_array);
995 @@ -268,14 +270,15 @@
996                                 <table align='center' cellpadding='0'>
997                                         <tr>
998                                                 <td align='center'>
999 -                                                       <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>
1000 +                                                       <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>
1001                                                         <?php print (read_graph_config_option("show_graph_title") == "on" ? "<p style='font-size: 10;' align='center'><strong>" . htmlspecialchars($graph["title_cache"]) . "</strong></p>" : "");?>
1002                                                 </td>
1003                                                 <td valign='top' style='align: left; padding: 3px;'>
1004 -                                                       <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>
1005 -                                                       <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>
1006 -                                                       <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>
1007 -                                                       <a href='#page_top'><img src='images/graph_page_top.gif' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br>
1008 +                                                       <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>
1009 +                                                       <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>
1010 +                                                       <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>
1011 +                                                       <?php api_plugin_hook('graph_buttons_thumbnails', array('hook' => 'graphs_thumbnails', 'local_graph_id' => $graph['local_graph_id'], 'rra' =>  0, 'view_type' => '')); ?>
1012 +                                                       <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>
1013                                                 </td>
1014                                         </tr>
1015                                 </table>
1016 @@ -638,9 +641,9 @@
1017                 print "<td style='$this_row_style'>" . $item["hex"] . "</td>\n";
1018  
1019                 if ($disable_controls == false) {
1020 -                       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>
1021 -                                       <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";
1022 -                       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";
1023 +                       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>
1024 +                                       <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";
1025 +                       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";
1026                 }
1027  
1028                 print "</tr>";
1029 @@ -706,6 +709,8 @@
1030                                         }
1031  
1032                                         while (list($item_sub_url, $item_sub_title) = each($item_title)) {
1033 +                                               $item_sub_url = $config['url_path'] . $item_sub_url;
1034 +
1035                                                 /* indent sub-items */
1036                                                 if ($i > 0) {
1037                                                         $prepend_string = "---&nbsp;";
1038 @@ -715,7 +720,7 @@
1039  
1040                                                 /* do not put a line between each sub-item */
1041                                                 if (($i == 0) || ($draw_sub_items == false)) {
1042 -                                                       $background = "images/menu_line.gif";
1043 +                                                       $background = $config['url_path'] . "images/menu_line.gif";
1044                                                 }else{
1045                                                         $background = "";
1046                                                 }
1047 @@ -744,17 +749,18 @@
1048                         }else{
1049                                 if ($current_realm_id == -1 || (isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) {
1050                                         /* draw normal (non sub-item) menu item */
1051 +                                       $item_url = $config['url_path'] . $item_url;
1052                                         if (basename($_SERVER["PHP_SELF"]) == basename($item_url)) {
1053 -                                               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";
1054 +                                               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";
1055                                         }else{
1056 -                                               print "<tr><td class='textMenuItem' style='background-image:url(\"images/menu_line.gif\");'><a href='" . htmlspecialchars($item_url) . "'>$item_title</a></td></tr>\n";
1057 +                                               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";
1058                                         }
1059                                 }
1060                         }
1061                 }
1062         }
1063  
1064 -       print "<tr><td class='textMenuItem' style='background-image:url(\"images/menu_line.gif\");'></td></tr>\n";
1065 +       print "<tr><td class='textMenuItem' style='background-image:url(\"" . $config['url_path'] . "images/menu_line.gif\");'></td></tr>\n";
1066  
1067         print "</table></td></tr>";
1068  }
1069 @@ -764,11 +770,12 @@
1070     @arg $actions_array - an array that contains a list of possible actions. this array should
1071       be compatible with the form_dropdown() function */
1072  function draw_actions_dropdown($actions_array) {
1073 +       global $config;
1074         ?>
1075         <table align='center' width='100%'>
1076                 <tr>
1077                         <td width='1' valign='top'>
1078 -                               <img src='images/arrow.gif' alt=''>&nbsp;
1079 +                               <img src='<?php echo $config['url_path']; ?>images/arrow.gif' alt='' align='middle'>&nbsp;
1080                         </td>
1081                         <td align='right'>
1082                                 Choose an action:
1083 diff -Naur cacti-0.8.7g-old/lib/plugins.php cacti-0.8.7g/lib/plugins.php
1084 --- cacti-0.8.7g-old/lib/plugins.php    1969-12-31 19:00:00.000000000 -0500
1085 +++ cacti-0.8.7g/lib/plugins.php        2010-07-09 18:34:11.000000000 -0400
1086 @@ -0,0 +1,476 @@
1087 +<?php
1088 +
1089 +
1090 +
1091 +function do_hook ($name) {
1092 +       $data = func_get_args();
1093 +       $data = api_plugin_hook ($name, $data);
1094 +       return $data;
1095 +}
1096 +
1097 +function do_hook_function($name,$parm=NULL) {
1098 +       return api_plugin_hook_function ($name, $parm);
1099 +}
1100 +
1101 +function api_user_realm_auth ($filename = '') {
1102 +       return api_plugin_user_realm_auth ($filename);
1103 +}
1104 +
1105 +/**
1106 + * This function executes a hook.
1107 + * @param string $name Name of hook to fire
1108 + * @return mixed $data
1109 + */
1110 +function api_plugin_hook ($name) {
1111 +       global $config, $plugin_hooks, $plugins_system;
1112 +       $data = func_get_args();
1113 +       $ret = '';
1114 +       $p = array();
1115 +
1116 +       $ps_where = '';
1117 +       if (sizeof($plugins_system)) {
1118 +               foreach($plugins_system as $plugin) {
1119 +                       $ps_where .= (strlen($ps_where) ? "', '":"('") . $plugin;
1120 +               }
1121 +               $ps_where .= "')";
1122 +       }
1123 +
1124 +       /* order the plugin functions by system first, then followed by order */
1125 +       $result = db_fetch_assoc("SELECT 1 AS id, ph.name, ph.file, ph.function
1126 +               FROM plugin_hooks AS ph
1127 +               LEFT JOIN plugin_config AS pc
1128 +               ON pc.directory=ph.name
1129 +               WHERE ph.status = 1 AND hook = '$name'
1130 +               AND ph.name IN $ps_where
1131 +               UNION
1132 +               SELECT pc.id, ph.name, ph.file, ph.function
1133 +               FROM plugin_hooks AS ph
1134 +               LEFT JOIN plugin_config AS pc
1135 +               ON pc.directory=ph.name
1136 +               WHERE ph.status = 1 AND hook = '$name'
1137 +               AND ph.name NOT IN $ps_where
1138 +               ORDER BY id ASC", true);
1139 +
1140 +       if (count($result)) {
1141 +               foreach ($result as $hdata) {
1142 +                       $p[] = $hdata['name'];
1143 +                       if (file_exists($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file'])) {
1144 +                               include_once($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file']);
1145 +                       }
1146 +                       $function = $hdata['function'];
1147 +                       if (function_exists($function)) {
1148 +                               $function($data);
1149 +                       }
1150 +               }
1151 +       }
1152 +
1153 +       if (isset($plugin_hooks[$name]) && is_array($plugin_hooks[$name])) {
1154 +               foreach ($plugin_hooks[$name] as $pname => $function) {
1155 +                       if (function_exists($function)  && !function_exists('plugin_' . $pname . '_install') && !in_array($pname, $p)) {
1156 +                               $function($data);
1157 +                       }
1158 +               }
1159 +       }
1160 +
1161 +       /* Variable-length argument lists have a slight problem when */
1162 +       /* passing values by reference. Pity. This is a workaround.  */
1163 +       return $data;
1164 +}
1165 +
1166 +function api_plugin_hook_function ($name, $parm=NULL) {
1167 +       global $config, $plugin_hooks, $plugins_system;
1168 +       $ret = $parm;
1169 +       $p = array();
1170 +       $ps_where = '';
1171 +
1172 +       if (sizeof($plugins_system)) {
1173 +               foreach($plugins_system as $plugin) {
1174 +                       $ps_where .= (strlen($ps_where) ? "', '":"('") . $plugin;
1175 +               }
1176 +               $ps_where .= "')";
1177 +       }
1178 +
1179 +       /* order the plugin functions by system first, then followed by order */
1180 +       $result = db_fetch_assoc("SELECT 1 AS id, ph.name, ph.file, ph.function
1181 +               FROM plugin_hooks AS ph
1182 +               LEFT JOIN plugin_config AS pc
1183 +               ON pc.directory=ph.name
1184 +               WHERE ph.status = 1 AND hook = '$name'
1185 +               AND ph.name IN $ps_where
1186 +               UNION
1187 +               SELECT pc.id, ph.name, ph.file, ph.function
1188 +               FROM plugin_hooks AS ph
1189 +               LEFT JOIN plugin_config AS pc
1190 +               ON pc.directory=ph.name
1191 +               WHERE ph.status = 1 AND hook = '$name'
1192 +               AND ph.name NOT IN $ps_where
1193 +               ORDER BY id ASC", true);
1194 +
1195 +       if (count($result)) {
1196 +               foreach ($result as $hdata) {
1197 +                       $p[] = $hdata['name'];
1198 +                       if (file_exists($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file'])) {
1199 +                               include_once($config['base_path'] . '/plugins/' . $hdata['name'] . '/' . $hdata['file']);
1200 +                       }
1201 +                       $function = $hdata['function'];
1202 +                       if (function_exists($function)) {
1203 +                               $ret = $function($ret);
1204 +                       }
1205 +               }
1206 +       }
1207 +
1208 +       if (isset($plugin_hooks[$name]) && is_array($plugin_hooks[$name])) {
1209 +               foreach ($plugin_hooks[$name] as $pname => $function) {
1210 +                       if (function_exists($function)  && !function_exists('plugin_' . $pname . '_install') && !in_array($pname, $p)) {
1211 +                               $ret = $function($ret);
1212 +                       }
1213 +               }
1214 +       }
1215 +
1216 +       /* Variable-length argument lists have a slight problem when */
1217 +       /* passing values by reference. Pity. This is a workaround.  */
1218 +       return $ret;
1219 +}
1220 +
1221 +function api_plugin_db_table_create ($plugin, $table, $data) {
1222 +       global $config, $database_default;
1223 +       include_once($config["library_path"] . "/database.php");
1224 +
1225 +       $result = db_fetch_assoc("show tables from `" . $database_default . "`") or die (mysql_error());
1226 +       $tables = array();
1227 +       foreach($result as $index => $arr) {
1228 +               foreach ($arr as $t) {
1229 +                       $tables[] = $t;
1230 +               }
1231 +       }
1232 +       if (!in_array($table, $tables)) {
1233 +               $c = 0;
1234 +               $sql = 'CREATE TABLE `' . $table . "` (\n";
1235 +               foreach ($data['columns'] as $column) {
1236 +                       if (isset($column['name'])) {
1237 +                               if ($c > 0)
1238 +                                       $sql .= ",\n";
1239 +                               $sql .= '`' . $column['name'] . '`';
1240 +                               if (isset($column['type']))
1241 +                                       $sql .= ' ' . $column['type'];
1242 +                               if (isset($column['unsigned']))
1243 +                                       $sql .= ' unsigned';
1244 +                               if (isset($column['NULL']) && $column['NULL'] == false)
1245 +                                       $sql .= ' NOT NULL';
1246 +                               if (isset($column['NULL']) && $column['NULL'] == true && !isset($column['default']))
1247 +                                       $sql .= ' default NULL';
1248 +                               if (isset($column['default']))
1249 +                                       $sql .= ' default ' . (is_numeric($column['default']) ? $column['default'] : "'" . $column['default'] . "'");
1250 +                               if (isset($column['auto_increment']))
1251 +                                       $sql .= ' auto_increment';
1252 +                               $c++;
1253 +                       }
1254 +               }
1255 +
1256 +               if (isset($data['primary'])) {
1257 +                       $sql .= ",\n PRIMARY KEY (`" . $data['primary'] . '`)';
1258 +               }
1259 +
1260 +               foreach ($data['keys'] as $key) {
1261 +                       if (isset($key['name'])) {
1262 +                               $sql .= ",\n KEY `" . $key['name'] . '` (`' . $key['columns'] . '`)';
1263 +                       }
1264 +               }
1265 +               $sql .= ') TYPE = ' . $data['type'];
1266 +
1267 +               if (isset($data['comment'])) {
1268 +                       $sql .= " COMMENT = '" . $data['comment'] . "'";
1269 +               }
1270 +               if (db_execute($sql)) {
1271 +                       db_execute("INSERT INTO plugin_db_changes (plugin, `table`, method) VALUES ('$plugin', '$table', 'create')");
1272 +               }
1273 +       } else {
1274 +               db_execute("INSERT INTO plugin_db_changes (plugin, `table`, method) VALUES ('$plugin', '$table', 'create')");
1275 +       }
1276 +}
1277 +
1278 +function api_plugin_db_changes_remove ($plugin) {
1279 +       // Example: api_plugin_db_changes_remove ('thold');
1280 +
1281 +       $tables = db_fetch_assoc("SELECT `table` FROM plugin_db_changes WHERE plugin = '$plugin' AND method ='create'", false);
1282 +       if (count($tables)) {
1283 +               foreach ($tables as $table) {
1284 +                       db_execute("DROP TABLE IF EXISTS `" . $table['table'] . "`;");
1285 +               }
1286 +               db_execute("DELETE FROM plugin_db_changes where plugin = '$plugin' AND method ='create'", false);
1287 +       }
1288 +       $columns = db_fetch_assoc("SELECT `table`, `column` FROM plugin_db_changes WHERE plugin = '$plugin' AND method ='addcolumn'", false);
1289 +       if (count($columns)) {
1290 +               foreach ($columns as $column) {
1291 +                       db_execute('ALTER TABLE `' . $column['table'] . '` DROP `' . $column['column'] . '`');
1292 +               }
1293 +               db_execute("DELETE FROM plugin_db_changes where plugin = '$plugin' AND method = 'addcolumn'", false);
1294 +       }
1295 +}
1296 +
1297 +function api_plugin_db_add_column ($plugin, $table, $column) {
1298 +       // Example: api_plugin_db_add_column ('thold', 'plugin_config', array('name' => 'test' . rand(1, 200), 'type' => 'varchar (255)', 'NULL' => false));
1299 +
1300 +       global $config, $database_default;
1301 +       include_once($config['library_path'] . '/database.php');
1302 +
1303 +       $result = db_fetch_assoc('show columns from `' . $table . '`') or die (mysql_error());
1304 +       $columns = array();
1305 +       foreach($result as $index => $arr) {
1306 +               foreach ($arr as $t) {
1307 +                       $columns[] = $t;
1308 +               }
1309 +       }
1310 +       if (isset($column['name']) && !in_array($column['name'], $columns)) {
1311 +               $sql = 'ALTER TABLE `' . $table . '` ADD `' . $column['name'] . '`';
1312 +               if (isset($column['type']))
1313 +                       $sql .= ' ' . $column['type'];
1314 +               if (isset($column['unsigned']))
1315 +                       $sql .= ' unsigned';
1316 +               if (isset($column['NULL']) && $column['NULL'] == false)
1317 +                       $sql .= ' NOT NULL';
1318 +               if (isset($column['NULL']) && $column['NULL'] == true && !isset($column['default']))
1319 +                       $sql .= ' default NULL';
1320 +               if (isset($column['default']))
1321 +                       $sql .= ' default ' . (is_numeric($column['default']) ? $column['default'] : "'" . $column['default'] . "'");
1322 +               if (isset($column['auto_increment']))
1323 +                       $sql .= ' auto_increment';
1324 +               if (isset($column['after']))
1325 +                       $sql .= ' AFTER ' . $column['after'];
1326 +
1327 +               if (db_execute($sql)) {
1328 +                       db_execute("INSERT INTO plugin_db_changes (plugin, `table`, `column`, `method`) VALUES ('$plugin', '$table', '" . $column['name'] . "', 'addcolumn')");
1329 +               }
1330 +       }
1331 +}
1332 +
1333 +function api_plugin_install ($plugin) {
1334 +       global $config;
1335 +       include_once($config['base_path'] . "/plugins/$plugin/setup.php");
1336 +
1337 +       $exists = db_fetch_assoc("SELECT id FROM plugin_config WHERE directory = '$plugin'", false);
1338 +       if (sizeof($exists)) {
1339 +               db_execute("DELETE FROM plugin_config WHERE directory = '$plugin'");
1340 +       }
1341 +
1342 +       $name = $author = $webpage = $version = '';
1343 +       $function = 'plugin_' . $plugin . '_version';
1344 +       if (function_exists($function)){
1345 +               $info = $function();
1346 +               $name = $info['longname'];
1347 +               if (isset($info['homepage'])) {
1348 +                       $webpage = $info['homepage'];
1349 +               }elseif (isset($info['webpage'])) {
1350 +                       $webpage = $info['webpage'];
1351 +               }else{
1352 +                       $webpage = "Not Stated";
1353 +               }
1354 +               $author = $info['author'];
1355 +               $version = $info['version'];
1356 +       }
1357 +
1358 +       db_execute("INSERT INTO plugin_config (directory, name, author, webpage, version) VALUES ('$plugin', '$name', '$author', '$webpage', '$version')");
1359 +
1360 +       $function = 'plugin_' . $plugin . '_install';
1361 +       if (function_exists($function)){
1362 +               $function();
1363 +               $ready = api_plugin_check_config ($plugin);
1364 +               if ($ready) {
1365 +                       // Set the plugin as "disabled" so it can go live
1366 +                       db_execute("UPDATE plugin_config SET status = 4 WHERE directory = '$plugin'");
1367 +               } else {
1368 +                       // Set the plugin as "needs configuration"
1369 +                       db_execute("UPDATE plugin_config SET status = 2 WHERE directory = '$plugin'");
1370 +               }
1371 +       }
1372 +}
1373 +
1374 +function api_plugin_uninstall ($plugin) {
1375 +       global $config;
1376 +       include_once($config['base_path'] . "/plugins/$plugin/setup.php");
1377 +       // Run the Plugin's Uninstall Function first
1378 +       $function = 'plugin_' . $plugin . '_uninstall';
1379 +       if (function_exists($function)) {
1380 +               $function();
1381 +       }
1382 +       api_plugin_remove_hooks ($plugin);
1383 +       api_plugin_remove_realms ($plugin);
1384 +       db_execute("DELETE FROM plugin_config WHERE directory = '$plugin'");
1385 +       api_plugin_db_changes_remove ($plugin);
1386 +}
1387 +
1388 +function api_plugin_check_config ($plugin) {
1389 +       global $config;
1390 +       include_once($config['base_path'] . "/plugins/$plugin/setup.php");
1391 +       $function = 'plugin_' . $plugin . '_check_config';
1392 +       if (function_exists($function)) {
1393 +               return $function();
1394 +       }
1395 +       return TRUE;
1396 +}
1397 +
1398 +function api_plugin_enable ($plugin) {
1399 +       $ready = api_plugin_check_config ($plugin);
1400 +       if ($ready) {
1401 +               api_plugin_enable_hooks ($plugin);
1402 +               db_execute("UPDATE plugin_config SET status = 1 WHERE directory = '$plugin'");
1403 +       }
1404 +}
1405 +
1406 +function api_plugin_is_enabled ($plugin) {
1407 +       $status = db_fetch_cell("SELECT status FROM plugin_config WHERE directory = '$plugin'", false);
1408 +       if ($status == '1')
1409 +               return true;
1410 +       return false;
1411 +}
1412 +
1413 +function api_plugin_disable ($plugin) {
1414 +       api_plugin_disable_hooks ($plugin);
1415 +       db_execute("UPDATE plugin_config SET status = 4 WHERE directory = '$plugin'");
1416 +}
1417 +
1418 +function api_plugin_moveup($plugin) {
1419 +       global $plugins_system;
1420 +
1421 +       $sql_where = "";
1422 +       if (sizeof($plugins_system)) {
1423 +               foreach($plugins_system as $s) {
1424 +                       $sql_where .= (strlen($sql_where) ? " AND ":"(") . " directory!='$s'";
1425 +               }
1426 +
1427 +               $sql_where .= ")";
1428 +       }
1429 +
1430 +       $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='$plugin'" . (strlen($sql_where) ? " AND " . $sql_where:""));
1431 +       $temp_id = db_fetch_cell("SELECT MAX(id) FROM plugin_config")+1;
1432 +       $prior_id = db_fetch_cell("SELECT MAX(id) FROM plugin_config WHERE id<$id" . (strlen($sql_where) ? " AND " . $sql_where:""));
1433 +
1434 +       /* update the above plugin to the prior temp id */
1435 +       db_execute("UPDATE plugin_config SET id=$temp_id WHERE id=$prior_id");
1436 +       db_execute("UPDATE plugin_config SET id=$prior_id WHERE id=$id");
1437 +       db_execute("UPDATE plugin_config SET id=$id WHERE id=$temp_id");
1438 +}
1439 +
1440 +function api_plugin_movedown($plugin) {
1441 +       global $plugins_system;
1442 +
1443 +       $sql_where = "";
1444 +       if (sizeof($plugins_system)) {
1445 +               foreach($plugins_system as $s) {
1446 +                       $sql_where .= (strlen($sql_where) ? " AND ":"(") . " directory!='$s'";
1447 +               }
1448 +
1449 +               $sql_where .= ")";
1450 +       }
1451 +
1452 +       $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='$plugin'" . (strlen($sql_where) ? " AND " . $sql_where:""));
1453 +       $temp_id = db_fetch_cell("SELECT MAX(id) FROM plugin_config")+1;
1454 +       $next_id = db_fetch_cell("SELECT MIN(id) FROM plugin_config WHERE id>$id" . (strlen($sql_where) ? " AND " . $sql_where:""));
1455 +
1456 +       /* update the above plugin to the prior temp id */
1457 +       db_execute("UPDATE plugin_config SET id=$temp_id WHERE id=$next_id");
1458 +       db_execute("UPDATE plugin_config SET id=$next_id WHERE id=$id");
1459 +       db_execute("UPDATE plugin_config SET id=$id WHERE id=$temp_id");
1460 +}
1461 +
1462 +function api_plugin_register_hook ($plugin, $hook, $function, $file) {
1463 +       $exists = db_fetch_assoc("SELECT id FROM plugin_hooks WHERE name = '$plugin' AND hook = '$hook'", false);
1464 +       if (!count($exists)) {
1465 +               $settings = array('config_settings', 'config_arrays', 'config_form');
1466 +               if (!in_array($hook, $settings)) {
1467 +                       db_execute("INSERT INTO plugin_hooks (name, hook, function, file) VALUES ('$plugin', '$hook', '$function', '$file')");
1468 +               } else {
1469 +                       db_execute("INSERT INTO plugin_hooks (name, hook, function, file, status) VALUES ('$plugin', '$hook', '$function', '$file', 1)");
1470 +               }
1471 +       }
1472 +}
1473 +
1474 +function api_plugin_remove_hooks ($plugin) {
1475 +       db_execute("DELETE FROM plugin_hooks WHERE name = '$plugin'");
1476 +}
1477 +
1478 +function api_plugin_enable_hooks ($plugin) {
1479 +       db_execute("UPDATE plugin_hooks SET status = 1 WHERE name = '$plugin'");
1480 +}
1481 +
1482 +function api_plugin_disable_hooks ($plugin) {
1483 +       db_execute("UPDATE plugin_hooks SET status = 0 WHERE name = '$plugin' AND hook != 'config_settings' AND hook != 'config_arrays' AND hook != 'config_form'");
1484 +}
1485 +
1486 +function api_plugin_register_realm ($plugin, $file, $display, $admin = false) {
1487 +       $exists = db_fetch_assoc("SELECT id FROM plugin_realms WHERE plugin = '$plugin' AND file = '$file'", false);
1488 +       if (!count($exists)) {
1489 +               db_execute("INSERT INTO plugin_realms (plugin, file, display) VALUES ('$plugin', '$file', '$display')");
1490 +               if ($admin) {
1491 +                       $realm_id = db_fetch_assoc("SELECT id FROM plugin_realms WHERE plugin = '$plugin' AND file = '$file'", false);
1492 +                       $realm_id = $realm_id[0]['id'] + 100;
1493 +                       $user_id = db_fetch_assoc("SELECT id FROM user_auth WHERE username = 'admin'", false);
1494 +                       if (count($user_id)) {
1495 +                               $user_id = $user_id[0]['id'];
1496 +                               $exists = db_fetch_assoc("SELECT realm_id FROM user_auth_realm WHERE user_id = $user_id and realm_id = $realm_id", false);
1497 +                               if (!count($exists)) {
1498 +                                       db_execute("INSERT INTO user_auth_realm (user_id, realm_id) VALUES ($user_id, $realm_id)");
1499 +                               }
1500 +                       }
1501 +               }
1502 +       }
1503 +}
1504 +
1505 +function api_plugin_remove_realms ($plugin) {
1506 +       $realms = db_fetch_assoc("SELECT id FROM plugin_realms WHERE plugin = '$plugin'", false);
1507 +       foreach ($realms as $realm) {
1508 +               $id = $realm['id'] + 100;
1509 +               db_execute("DELETE FROM user_auth_realm WHERE realm_id = '$id'");
1510 +       }
1511 +       db_execute("DELETE FROM plugin_realms WHERE plugin = '$plugin'");
1512 +}
1513 +
1514 +function api_plugin_load_realms () {
1515 +       global $user_auth_realms, $user_auth_realm_filenames;
1516 +       $plugin_realms = db_fetch_assoc("SELECT * FROM plugin_realms ORDER BY plugin, display", false);
1517 +       if (count($plugin_realms)) {
1518 +               foreach ($plugin_realms as $plugin_realm) {
1519 +                       $plugin_files = explode(',', $plugin_realm['file']);
1520 +                       foreach($plugin_files as $plugin_file) {
1521 +                               $user_auth_realm_filenames[$plugin_file] = $plugin_realm['id'] + 100;
1522 +                       }
1523 +                       $user_auth_realms[$plugin_realm['id'] + 100] = $plugin_realm['display'];
1524 +               }
1525 +       }
1526 +}
1527 +
1528 +function api_plugin_user_realm_auth ($filename = '') {
1529 +       global $user_realms, $user_auth_realms, $user_auth_realm_filenames;
1530 +       /* list all realms that this user has access to */
1531 +       if (!isset($user_realms)) {
1532 +               if (read_config_option('global_auth') == 'on' || read_config_option('auth_method') != 0) {
1533 +                       $user_realms = db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . $_SESSION["sess_user_id"], false);
1534 +                       $user_realms = array_rekey($user_realms, "realm_id", "realm_id");
1535 +               }else{
1536 +                       $user_realms = $user_auth_realms;
1537 +               }
1538 +       }
1539 +       if ($filename != '') {
1540 +               if (isset($user_realms[$user_auth_realm_filenames{basename($filename)}]))
1541 +                       return TRUE;
1542 +       }
1543 +       return FALSE;
1544 +}
1545 +
1546 +function plugin_config_arrays () {
1547 +       global $menu;
1548 +       $menu['Configuration']['plugins.php'] = 'Plugin Management';
1549 +       api_plugin_load_realms ();
1550 +}
1551 +
1552 +function plugin_draw_navigation_text ($nav) {
1553 +       $nav["plugins.php:"] = array("title" => "Plugin Management", "mapping" => "index.php:", "url" => "plugins.php", "level" => "1");
1554 +       return $nav;
1555 +}
1556 +
1557 +
1558 +
1559 +
1560 +
1561 +
1562 +
1563 diff -Naur cacti-0.8.7g-old/lib/poller.php cacti-0.8.7g/lib/poller.php
1564 --- cacti-0.8.7g-old/lib/poller.php     2010-07-09 18:33:46.000000000 -0400
1565 +++ cacti-0.8.7g/lib/poller.php 2010-07-09 18:34:11.000000000 -0400
1566 @@ -344,8 +344,11 @@
1567                                 }
1568                         }
1569                 }
1570 +               api_plugin_hook_function('poller_output', $rrd_update_array);
1571  
1572 -               $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
1573 +               if (api_plugin_hook_function('poller_on_demand', $results)) {
1574 +                       $rrds_processed = rrdtool_function_update($rrd_update_array, $rrdtool_pipe);
1575 +               }
1576         }
1577  
1578         return $rrds_processed;
1579 diff -Naur cacti-0.8.7g-old/lib/rrd.php cacti-0.8.7g/lib/rrd.php
1580 --- cacti-0.8.7g-old/lib/rrd.php        2010-07-09 18:33:46.000000000 -0400
1581 +++ cacti-0.8.7g/lib/rrd.php    2010-07-09 18:34:11.000000000 -0400
1582 @@ -419,6 +419,9 @@
1583  
1584         $data_source_path = get_data_source_path($local_data_id, true);
1585  
1586 +       /* update the rrdfile if performing a fetch */
1587 +       api_plugin_hook_function('rrdtool_function_fetch_cache_check', $local_data_id);
1588 +
1589         /* build and run the rrdtool fetch command with all of our data */
1590         $cmd_line = "fetch $data_source_path AVERAGE -s $start_time -e $end_time";
1591         if ($resolution > 0) {
1592 @@ -539,6 +542,10 @@
1593                 }
1594         }
1595  
1596 +       $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));
1597 +       if (isset($data['return']) && $data['return'] != false)
1598 +               return $data['return'];
1599 +
1600         /* find the step and how often this graph is updated with new data */
1601         $ds_step = db_fetch_cell("select
1602                 data_template_data.rrd_step
1603 @@ -1376,6 +1383,13 @@
1604         }
1605         }
1606  
1607 +       $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));
1608 +       if (!empty($graph_array)) {
1609 +               $graph_defs = $graph_array['graph_defs'];
1610 +               $txt_graph_items = $graph_array['txt_graph_items'];
1611 +               $graph_opts = $graph_array['graph_opts'];
1612 +       }
1613 +
1614         /* either print out the source or pass the source onto rrdtool to get us a nice PNG */
1615         if (isset($graph_data_array["print_source"])) {
1616                 print "<PRE>" . htmlspecialchars(read_config_option("path_rrdtool") . " graph " . $graph_opts . $graph_defs . $txt_graph_items) . "</PRE>";
1617 @@ -1384,13 +1398,19 @@
1618                         @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, RRDTOOL_OUTPUT_NULL, $rrdtool_pipe);
1619                         return 0;
1620                 }else{
1621 +                       $graph_data_array = api_plugin_hook_function('prep_graph_array', $graph_data_array);
1622 +
1623                         if (isset($graph_data_array["output_flag"])) {
1624                                 $output_flag = $graph_data_array["output_flag"];
1625                         }else{
1626                                 $output_flag = RRDTOOL_OUTPUT_GRAPH_DATA;
1627                         }
1628  
1629 -                       return @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag, $rrdtool_pipe);
1630 +                       $output = @rrdtool_execute("graph $graph_opts$graph_defs$txt_graph_items", false, $output_flag, $rrdtool_pipe);
1631 +
1632 +                       api_plugin_hook_function('rrdtool_function_graph_set_file', array('output' => $output, 'local_graph_id' => $local_graph_id, 'rra_id' => $rra_id));
1633 +
1634 +                       return $output;
1635                 }
1636         }
1637  }
1638 diff -Naur cacti-0.8.7g-old/lib/variables.php cacti-0.8.7g/lib/variables.php
1639 --- cacti-0.8.7g-old/lib/variables.php  2010-07-09 18:33:46.000000000 -0400
1640 +++ cacti-0.8.7g/lib/variables.php      2010-07-09 18:34:11.000000000 -0400
1641 @@ -183,6 +183,9 @@
1642         $string = str_replace($l_escape_string . "host_max_oids" . $r_escape_string, $_SESSION["sess_host_cache_array"][$host_id]["max_oids"], $string);
1643         $string = str_replace($l_escape_string . "host_id" . $r_escape_string, $_SESSION["sess_host_cache_array"][$host_id]["id"], $string);
1644  
1645 +       $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));
1646 +       $string = $temp['string'];
1647 +
1648         return $string;
1649  }
1650  
1651 diff -Naur cacti-0.8.7g-old/plugins/index.php cacti-0.8.7g/plugins/index.php
1652 --- cacti-0.8.7g-old/plugins/index.php  1969-12-31 19:00:00.000000000 -0500
1653 +++ cacti-0.8.7g/plugins/index.php      2010-07-09 18:34:11.000000000 -0400
1654 @@ -0,0 +1,5 @@
1655 +<?php
1656 +
1657 +header("Location:../index.php");
1658 +
1659 +?>
1660 diff -Naur cacti-0.8.7g-old/plugins.php cacti-0.8.7g/plugins.php
1661 --- cacti-0.8.7g-old/plugins.php        1969-12-31 19:00:00.000000000 -0500
1662 +++ cacti-0.8.7g/plugins.php    2010-07-09 18:34:11.000000000 -0400
1663 @@ -0,0 +1,647 @@
1664 +<?php
1665 +/*
1666 + +-------------------------------------------------------------------------+
1667 + | Copyright (C) 2004-2010 The Cacti Group                                 |
1668 + |                                                                         |
1669 + | This program is free software; you can redistribute it and/or           |
1670 + | modify it under the terms of the GNU General Public License             |
1671 + | as published by the Free Software Foundation; either version 2          |
1672 + | of the License, or (at your option) any later version.                  |
1673 + |                                                                         |
1674 + | This program is distributed in the hope that it will be useful,         |
1675 + | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
1676 + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
1677 + | GNU General Public License for more details.                            |
1678 + +-------------------------------------------------------------------------+
1679 + | Cacti: The Complete RRDTool-based Graphing Solution                     |
1680 + +-------------------------------------------------------------------------+
1681 + | This code is designed, written, and maintained by the Cacti Group. See  |
1682 + | about.php and/or the AUTHORS file for specific developer information.   |
1683 + +-------------------------------------------------------------------------+
1684 + | http://www.cacti.net/                                                   |
1685 + +-------------------------------------------------------------------------+
1686 +*/
1687 +
1688 +include("./include/auth.php");
1689 +
1690 +define("MAX_DISPLAY_PAGES", 21);
1691 +
1692 +$actions = array("install" => "Install",
1693 +       "enable" => "Enable",
1694 +       "disable" => "Disable",
1695 +       "uninstall" => "Uninstall",
1696 +//     "check" => "Check"
1697 +);
1698 +
1699 +$status_names = array(
1700 +       -2 => 'Disabled',
1701 +       -1 => 'Active',
1702 +       0 => 'Not Installed',
1703 +       1 => 'Active',
1704 +       2 => 'Awaiting Configuration',
1705 +       3 => 'Awaiting Upgrade',
1706 +       4 => 'Installed'
1707 +);
1708 +
1709 +/* get the comprehensive list of plugins */
1710 +$pluginslist = retrieve_plugin_list();
1711 +
1712 +/* Check to see if we are installing, etc... */
1713 +$modes = array('installold', 'uninstallold', 'install', 'uninstall', 'disable', 'enable', 'check', 'moveup', 'movedown');
1714 +
1715 +if (isset($_GET['mode']) && in_array($_GET['mode'], $modes)  && isset($_GET['id'])) {
1716 +       input_validate_input_regex(get_request_var("id"), "^([a-zA-Z0-9]+)$");
1717 +
1718 +       $mode = $_GET['mode'];
1719 +       $id   = sanitize_search_string($_GET['id']);
1720 +
1721 +       switch ($mode) {
1722 +               case 'installold':
1723 +                       api_plugin_install_old($id);
1724 +                       header("Location: plugins.php");
1725 +                       exit;
1726 +                       break;
1727 +               case 'uninstallold':
1728 +                       api_plugin_uninstall_old($id);
1729 +                       header("Location: plugins.php");
1730 +                       exit;
1731 +                       break;
1732 +               case 'install':
1733 +                       api_plugin_install($id);
1734 +                       header("Location: plugins.php");
1735 +                       exit;
1736 +                       break;
1737 +               case 'uninstall':
1738 +                       if (!in_array($id, $pluginslist)) break;
1739 +                       api_plugin_uninstall($id);
1740 +                       header("Location: plugins.php");
1741 +                       exit;
1742 +                       break;
1743 +               case 'disable':
1744 +                       if (!in_array($id, $pluginslist)) break;
1745 +                       api_plugin_disable($id);
1746 +                       header("Location: plugins.php");
1747 +                       exit;
1748 +                       break;
1749 +               case 'enable':
1750 +                       if (!in_array($id, $pluginslist)) break;
1751 +                       api_plugin_enable($id);
1752 +                       header("Location: plugins.php");
1753 +                       exit;
1754 +                       break;
1755 +               case 'check':
1756 +                       if (!in_array($id, $pluginslist)) break;
1757 +                       break;
1758 +               case 'moveup':
1759 +                       if (!in_array($id, $pluginslist)) break;
1760 +                       if (is_system_plugin($id)) break;
1761 +                       api_plugin_moveup($id);
1762 +                       header("Location: plugins.php");
1763 +                       exit;
1764 +                       break;
1765 +               case 'movedown':
1766 +                       if (!in_array($id, $pluginslist)) break;
1767 +                       if (is_system_plugin($id)) break;
1768 +                       api_plugin_movedown($id);
1769 +                       header("Location: plugins.php");
1770 +                       exit;
1771 +                       break;
1772 +       }
1773 +}
1774 +
1775 +function retrieve_plugin_list () {
1776 +       $pluginslist = array();
1777 +       $temp = db_fetch_assoc('SELECT directory FROM plugin_config ORDER BY name');
1778 +       foreach ($temp as $t) {
1779 +               $pluginslist[] = $t['directory'];
1780 +       }
1781 +       return $pluginslist;
1782 +}
1783 +
1784 +include("./include/top_header.php");
1785 +
1786 +update_show_current();
1787 +
1788 +include("./include/bottom_footer.php");
1789 +
1790 +
1791 +function api_plugin_install_old ($plugin) {
1792 +       global $config;
1793 +       if (!file_exists($config['base_path'] . "/plugins/$plugin/setup.php")) {
1794 +               return false;
1795 +       }
1796 +       $oldplugins = read_config_option('oldplugins');
1797 +       $oldplugins = explode(',', $oldplugins);
1798 +       if (!in_array($plugin, $oldplugins)) {
1799 +               include_once($config['base_path'] . "/plugins/$plugin/setup.php");
1800 +               $function = 'plugin_init_' . $plugin;
1801 +               if (function_exists($function)){
1802 +                       $oldplugins[] = $plugin;
1803 +                       $oldplugins = implode(',', $oldplugins);
1804 +                       set_config_option('oldplugins', $oldplugins);
1805 +                       unset($_SESSION['sess_config_array']['oldplugins']);
1806 +                       return true;
1807 +               } else {
1808 +                       return false;
1809 +               }
1810 +       }
1811 +       return false;
1812 +}
1813 +
1814 +function api_plugin_uninstall_old ($plugin) {
1815 +       global $config;
1816 +       $oldplugins = read_config_option('oldplugins');
1817 +       $oldplugins = explode(',', $oldplugins);
1818 +       if (!empty($oldplugins)) {
1819 +               if (in_array($plugin, $oldplugins)) {
1820 +                       for ($a = 0; $a < count($oldplugins); $a++) {
1821 +                               if ($oldplugins[$a] == $plugin) {
1822 +                                       unset($oldplugins[$a]);
1823 +                                       break;
1824 +                               }
1825 +                       }
1826 +                       $oldplugins = implode(',', $oldplugins);
1827 +                       set_config_option('oldplugins', $oldplugins);
1828 +                       unset($_SESSION['sess_config_array']['oldplugins']);
1829 +                       return true;
1830 +               }
1831 +       }
1832 +       return false;
1833 +}
1834 +
1835 +function update_show_updates () {
1836 +       global $pluginslist, $colors, $config, $plugin_architecture;
1837 +
1838 +       $cinfo = array();
1839 +       sort($pluginslist);
1840 +
1841 +       $cinfo = update_get_plugin_info ();
1842 +
1843 +       $x = 0;
1844 +
1845 +       $info = update_get_cached_plugin_info();
1846 +
1847 +       $cactinew = update_check_if_newer($cinfo['cacti']['version'], $info['cacti']['version']) ;
1848 +       if (isset($cinfo['cacti_plugin_arch']['version'])) {
1849 +               $archnew =  update_check_if_newer($cinfo['cacti_plugin_arch']['version'], $info['cacti_plugin_arch']['version']);
1850 +       } else {
1851 +               $archnew = 0;
1852 +       }
1853 +
1854 +       if ($cactinew) {
1855 +               $x++;
1856 +               print "<tr><td width='25%' valign=top><table width='100%'>";
1857 +               html_header(array("Cacti"), 2);
1858 +               form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1859 +               print "<td width='25%'><strong>Version:</strong></td><td>" . $config["cacti_version"] . "</td></tr>";
1860 +               form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1861 +               print "<td valign=top><strong>Changes:</strong></td><td>" . str_replace("\n", '<br>', $info['cacti']['changes']) . "</td></tr></table>";
1862 +       }
1863 +       if (isset($plugin_architecture['version']) && $archnew) {
1864 +               $x++;
1865 +               print "<table width='100%'>";
1866 +               html_header(array("Plugin Architecture"), 2);
1867 +               form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1868 +               print "<td width='25%'><strong>Version:</strong></td><td>" . $plugin_architecture['version'] . "</td>";
1869 +               form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1870 +               print "<td valign=top><strong>Changes:</strong></td><td>" . str_replace("\n", '<br>', $info['cacti_plugin_arch']['changes']) . "</td></tr></table>";
1871 +       }
1872 +       print "<table width='100%' cellspacing=0 cellpadding=3>";
1873 +
1874 +       foreach ($pluginslist as $plugin) {
1875 +               if (isset($cinfo[$plugin]) && update_check_if_newer($cinfo[$plugin]['version'], $info[$plugin]['version'])) {
1876 +                       $x++;
1877 +                       print "<table width='100%'>";
1878 +                       html_header(array((isset($cinfo[$plugin]['longname']) ? $cinfo[$plugin]['longname'] : $plugin)), 2);
1879 +                       form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1880 +                       print "<td width='50%'><strong>Directory:</strong></td><td>$plugin</td>";
1881 +                       form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1882 +                       print "<td><strong>Version:</strong></td><td>" . $info[$plugin]['version'] . "</td>";
1883 +                       form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1884 +                       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>";
1885 +                       form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1886 +                       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>";
1887 +                       form_alternate_row_color($colors["alternate"],$colors["light"], 0);
1888 +                       print "<td valign=top><strong>Changes:</strong></td><td>" . str_replace("\n", '<br>', $info[$plugin]['changes']) . "</td>";
1889 +
1890 +                       print "</tr></table>";
1891 +               }
1892 +       }
1893 +       if ($x == 0)
1894 +               print "<br><center><b>There are currently no Updates!</b></center><br>";
1895 +       print "</table>";
1896 +       html_end_box(TRUE);
1897 +}
1898 +
1899 +function update_check_if_newer() {
1900 +       return false;
1901 +}
1902 +
1903 +function plugins_temp_table_exists($table) {
1904 +       return sizeof(db_fetch_row("SHOW TABLES LIKE '$table'"));
1905 +}
1906 +
1907 +function plugins_load_temp_table() {
1908 +       global $config, $plugins;
1909 +
1910 +       $pluginslist = retrieve_plugin_list();
1911 +
1912 +       if (isset($_SESSION["plugin_temp_table"])) {
1913 +               $table = $_SESSION["plugin_temp_table"];
1914 +       }else{
1915 +               $table = "plugin_temp_table_" . rand();
1916 +       }
1917 +
1918 +       while (true) {
1919 +               if (!plugins_temp_table_exists($table)) {
1920 +                       $_SESSION["plugin_temp_table"] = $table;
1921 +                       db_execute("CREATE TEMPORARY TABLE $table LIKE plugin_config");
1922 +                       db_execute("INSERT INTO $table SELECT * FROM plugin_config");
1923 +                       break;
1924 +               }else{
1925 +                       $table = "plugin_temp_table_" . rand();
1926 +               }
1927 +       }
1928 +
1929 +       $path = $config['base_path'] . '/plugins/';
1930 +       $dh = opendir($path);
1931 +       while (($file = readdir($dh)) !== false) {
1932 +               if ((is_dir("$path/$file")) && (file_exists("$path/$file/setup.php")) && (!in_array($file, $pluginslist))) {
1933 +                       if (!function_exists('plugin_' . $file . '_install')) {
1934 +                               include_once("$path/$file/setup.php");
1935 +                               if (!function_exists('plugin_' . $file . '_install') && function_exists($file . '_version')) {
1936 +                                       $function = $file . '_version';
1937 +                                       $cinfo[$file] = $function();
1938 +                                       if (!isset($cinfo[$file]['author'])) $cinfo[$file]['author'] = 'Unknown';
1939 +                                       if (!isset($cinfo[$file]['homepage'])) $cinfo[$file]['homepage'] = 'Not Stated';
1940 +                                       if (isset($cinfo[$file]['webpage'])) $cinfo[$file]['homepage'] = $cinfo[$file]['webpage'];
1941 +                                       if (!isset($cinfo[$file]['longname'])) $cinfo[$file]['longname'] = ucfirst($file);
1942 +                                       $cinfo[$file]['status'] = -2;
1943 +                                       if (in_array($file, $plugins)) {
1944 +                                               $cinfo[$file]['status'] = -1;
1945 +                                       }
1946 +                                       db_execute("REPLACE INTO $table (directory, name, status, author, webpage, version)
1947 +                                               VALUES ('" .
1948 +                                                       $file . "', '" .
1949 +                                                       $cinfo[$file]['longname'] . "', '" .
1950 +                                                       $cinfo[$file]['status'] . "', '" .
1951 +                                                       $cinfo[$file]['author'] . "', '" .
1952 +                                                       $cinfo[$file]['homepage'] . "', '" .
1953 +                                                       $cinfo[$file]['version'] . "')");
1954 +                                       $pluginslist[] = $file;
1955 +                               } else if (function_exists('plugin_' . $file . '_install') && function_exists('plugin_' . $file . '_version')) {
1956 +                                       $function = $file . '_version';
1957 +                                       $cinfo[$file] = $function();
1958 +                                       $cinfo[$file]['status'] = 0;
1959 +                                       if (!isset($cinfo[$file]['author'])) $cinfo[$file]['author'] = 'Unknown';
1960 +                                       if (!isset($cinfo[$file]['homepage'])) $cinfo[$file]['homepage'] = 'Not Stated';
1961 +                                       if (isset($cinfo[$file]['webpage'])) $cinfo[$file]['homepage'] = $cinfo[$file]['webpage'];
1962 +                                       if (!isset($cinfo[$file]['longname'])) $cinfo[$file]['homepage'] = ucfirst($file);
1963 +                                       db_execute("REPLACE INTO $table (directory, name, status, author, webpage, version)
1964 +                                               VALUES ('" .
1965 +                                                       $file . "', '" .
1966 +                                                       $cinfo[$file]['longname'] . "', '" .
1967 +                                                       $cinfo[$file]['status'] . "', '" .
1968 +                                                       $cinfo[$file]['author'] . "', '" .
1969 +                                                       $cinfo[$file]['homepage'] . "', '" .
1970 +                                                       $cinfo[$file]['version'] . "')");
1971 +                                       $pluginslist[] = $file;
1972 +                               }
1973 +                       }else{
1974 +                               cacti_log("WARNING: Install function already exists for plugin directory '$file'", false);
1975 +                       }
1976 +               }
1977 +       }
1978 +       closedir($dh);
1979 +
1980 +       return $table;
1981 +}
1982 +
1983 +function update_show_current () {
1984 +       global $plugins, $pluginslist, $colors, $plugin_architecture, $config, $status_names, $actions;
1985 +
1986 +       /* ================= input validation ================= */
1987 +       input_validate_input_number(get_request_var_request("page"));
1988 +       /* ==================================================== */
1989 +
1990 +       /* clean up search string */
1991 +       if (isset($_REQUEST["filter"])) {
1992 +               $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
1993 +       }
1994 +
1995 +       /* clean up sort_column */
1996 +       if (isset($_REQUEST["sort_column"])) {
1997 +               $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
1998 +       }
1999 +
2000 +       /* clean up search string */
2001 +       if (isset($_REQUEST["sort_direction"])) {
2002 +               $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
2003 +       }
2004 +
2005 +       /* if the user pushed the 'clear' button */
2006 +       if (isset($_REQUEST["clear_x"])) {
2007 +               kill_session_var("sess_plugins_filter");
2008 +               kill_session_var("sess_plugins_sort_column");
2009 +               kill_session_var("sess_plugins_sort_direction");
2010 +
2011 +               unset($_REQUEST["page"]);
2012 +               unset($_REQUEST["filter"]);
2013 +               unset($_REQUEST["sort_column"]);
2014 +               unset($_REQUEST["sort_direction"]);
2015 +               $_REQUEST["page"] = 1;
2016 +       }
2017 +
2018 +       /* remember these search fields in session vars so we don't have to keep passing them around */
2019 +       load_current_session_value("filter", "sess_plugins_filter", "");
2020 +       load_current_session_value("sort_column", "sess_plugins_sort_column", "name");
2021 +       load_current_session_value("sort_direction", "sess_plugins_sort_direction", "ASC");
2022 +       load_current_session_value("page", "sess_plugins_current_page", "1");
2023 +
2024 +       $table = plugins_load_temp_table();
2025 +
2026 +       html_start_box("<strong>Plugin Management</strong> (Cacti Version: " . $config["cacti_version"] .
2027 +               (isset($plugin_architecture['version']) ? ", Plugin Architecture Version: " . $plugin_architecture['version']:"") .
2028 +               ")", "100%", $colors["header"], "3", "center", "");
2029 +
2030 +       ?>
2031 +       <tr bgcolor="#<?php print $colors['panel'];?>">
2032 +               <td class="noprint">
2033 +               <form name="form_plugins" method="get" action="plugins.php">
2034 +                       <table width="100%" cellpadding="0" cellspacing="0">
2035 +                               <tr class="noprint">
2036 +                                       <td nowrap style='white-space: nowrap;' width="50">
2037 +                                               Search:&nbsp;
2038 +                                       </td>
2039 +                                       <td width="1">
2040 +                                               <input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>">
2041 +                                       </td>
2042 +                                       <td nowrap style='white-space: nowrap;'>
2043 +                                               &nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
2044 +                                               <input type="submit" name="clear_x" value="Clear" title="Clear Filters">
2045 +                                       </td>
2046 +                               </tr>
2047 +                       </table>
2048 +                       <input type='hidden' name='page' value='1'>
2049 +               </form>
2050 +               </td>
2051 +       </tr>
2052 +       <?php
2053 +
2054 +       html_end_box();
2055 +
2056 +       /* print checkbox form for validation */
2057 +       print "<form name='chk' method='post' action='plugins.php'>\n";
2058 +
2059 +       html_start_box("", "100%", $colors["header"], "3", "center", "");
2060 +
2061 +       /* form the 'where' clause for our main sql query */
2062 +       $sql_where = "WHERE ($table.name LIKE '%%" . get_request_var_request("filter") . "%%')";
2063 +
2064 +       if (get_request_var_request("sort_column") == "version") {
2065 +               $sortc = "version+0";
2066 +       }else{
2067 +               $sortc = get_request_var_request("sort_column");
2068 +       }
2069 +
2070 +       if (get_request_var_request("sort_column") == "id") {
2071 +               $sortd = "ASC";
2072 +       }else{
2073 +               $sortd = get_request_var_request("sort_direction");
2074 +       }
2075 +
2076 +       $total_rows = db_fetch_cell("SELECT
2077 +               count(*)
2078 +               FROM $table
2079 +               $sql_where");
2080 +
2081 +       $plugins = db_fetch_assoc("SELECT *
2082 +               FROM $table
2083 +               $sql_where
2084 +               ORDER BY " . $sortc . " " . $sortd . "
2085 +               LIMIT " . (read_config_option("num_rows_device")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_device"));
2086 +
2087 +       db_execute("DROP TABLE $table");
2088 +
2089 +       /* generate page list */
2090 +       $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"));
2091 +
2092 +       if ($total_rows == 0) {
2093 +               $nav = "<tr bgcolor='#" . $colors["header"] . "'>
2094 +                               <td colspan='9'>
2095 +                                       <table width='100%' cellspacing='0' cellpadding='0' border='0'>
2096 +                                               <tr>
2097 +                                                       <td align='center' class='textHeaderDark'>
2098 +                                                               No Plugins Found
2099 +                                                       </td>\n
2100 +                                               </tr>
2101 +                                       </table>
2102 +                               </td>
2103 +                       </tr>\n";
2104 +       }elseif ($total_rows < read_config_option("num_rows_device")) {
2105 +               $nav = "<tr bgcolor='#" . $colors["header"] . "'>
2106 +                               <td colspan='9'>
2107 +                                       <table width='100%' cellspacing='0' cellpadding='0' border='0'>
2108 +                                               <tr>
2109 +                                                       <td align='center' class='textHeaderDark'>
2110 +                                                               Showing All $total_rows Rows
2111 +                                                       </td>\n
2112 +                                               </tr>
2113 +                                       </table>
2114 +                               </td>
2115 +                       </tr>\n";
2116 +       }else{
2117 +               $nav = "<tr bgcolor='#" . $colors["header"] . "'>
2118 +                               <td colspan='9'>
2119 +                                       <table width='100%' cellspacing='0' cellpadding='0' border='0'>
2120 +                                               <tr>
2121 +                                                       <td align='left' class='textHeaderDark'>
2122 +                                                               <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>
2123 +                                                       </td>\n
2124 +                                                       <td align='center' class='textHeaderDark'>
2125 +                                                               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]
2126 +                                                       </td>\n
2127 +                                                       <td align='right' class='textHeaderDark'>
2128 +                                                               <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>
2129 +                                                       </td>\n
2130 +                                               </tr>
2131 +                                       </table>
2132 +                               </td>
2133 +                       </tr>\n";
2134 +       }
2135 +
2136 +       print $nav;
2137 +
2138 +       $display_text = array(
2139 +               "nosort" => array("Actions", ""),
2140 +               "directory" => array("Name", "ASC"),
2141 +               "id" => array("Load Order", "ASC"),
2142 +               "name" => array("Description", "ASC"),
2143 +               "nosort1" => array("Type", "ASC"),
2144 +               "status" => array("Status", "ASC"),
2145 +               "author" => array("Author", "ASC"),
2146 +               "webpage" => array("Web Page", "ASC"),
2147 +               "version" => array("Version", "ASC"));
2148 +
2149 +       html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), 1);
2150 +
2151 +       $i = 0;
2152 +       if (sizeof($plugins)) {
2153 +               if (get_request_var_request("sort_column") == "id") {
2154 +                       $inst_system_plugins = get_system_plugins($plugins);
2155 +                       if (sizeof($inst_system_plugins)) {
2156 +                               foreach($inst_system_plugins as $plugin) {
2157 +                                       form_alternate_row_color($colors["alternate"], $colors["light"], $i); $i++;
2158 +                                       print format_plugin_row($plugin, false, false, true);
2159 +                               }
2160 +                       }
2161 +               }
2162 +
2163 +               $j = 0;
2164 +               foreach ($plugins as $plugin) {
2165 +                       if ((isset($plugins[$j+1]) && $plugins[$j+1]['status'] < 0) || (!isset($plugins[$j+1]))) {
2166 +                               $last_plugin = true;
2167 +                       }else{
2168 +                               $last_plugin = false;
2169 +                       }
2170 +                       if ($plugin['status'] <= 0 || is_system_plugin($plugin) || (get_request_var_request('sort_column') != 'id')) {
2171 +                               $load_ordering = false;
2172 +                       }else{
2173 +                               $load_ordering = true;
2174 +                       }
2175 +
2176 +                       if (get_request_var_request("sort_column") == "id") {
2177 +                               if (!is_system_plugin($plugin)) {
2178 +                                       form_alternate_row_color($colors["alternate"], $colors["light"], $i);
2179 +                                       print format_plugin_row($plugin, $last_plugin, $load_ordering, false);
2180 +                                       $i++;
2181 +                               }
2182 +                       }else{
2183 +                               form_alternate_row_color($colors["alternate"], $colors["light"], $i);
2184 +                               print format_plugin_row($plugin, $last_plugin, $load_ordering, is_system_plugin($plugin));
2185 +                               $i++;
2186 +                       }
2187 +
2188 +                       $j++;
2189 +               }
2190 +
2191 +               print $nav;
2192 +       }else{
2193 +               print "<tr><td><em>No Plugins Found</em></td></tr>";
2194 +       }
2195 +
2196 +       html_end_box(false);
2197 +
2198 +       html_start_box("", "100%", $colors["header"], "3", "center", "");
2199 +       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>";
2200 +       html_end_box();
2201 +
2202 +       print "</form>\n";
2203 +}
2204 +
2205 +function format_plugin_row($plugin, $last_plugin, $include_ordering, $system_plugin) {
2206 +       global $status_names;
2207 +       static $first_plugin = true;
2208 +
2209 +       $row = plugin_actions($plugin);
2210 +       $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>";
2211 +       if ($include_ordering) {
2212 +               $row .= "<td style='white-space:nowrap;'>";
2213 +               if (!$first_plugin) {
2214 +                       $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>";
2215 +               }else{
2216 +                       $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>";
2217 +               }
2218 +               if (!$last_plugin) {
2219 +                       $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>";
2220 +               }else{
2221 +                       $row .= "<a href='#' title='Can Increase Load Order' class='linkEditMain'><img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'></a>";
2222 +               }
2223 +               $row .= "</td>\n";
2224 +       }else{
2225 +               $row .= "<td></td>\n";
2226 +       }
2227 +
2228 +       $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";
2229 +       $row .= "<td style='white-space:nowrap;'>" . ($system_plugin ? "System": ($plugin['status'] < 0 ? "Old PIA":"General")) . "</td>\n";
2230 +       $row .= "<td style='white-space:nowrap;'>" . $status_names[$plugin["status"]] . "</td>\n";
2231 +       $row .= "<td style='white-space:nowrap;'>" . $plugin["author"] . "</td>\n";
2232 +       $row .= "<td><a href='" . htmlspecialchars($plugin["webpage"]) . "'>" . htmlspecialchars($plugin["webpage"]) . "</a></td>\n";
2233 +       $row .= "<td>" . $plugin["version"] . "</td>\n";
2234 +       $row .= "</tr>\n";
2235 +
2236 +       if ($include_ordering) {
2237 +               $first_plugin = false;
2238 +       }
2239 +
2240 +       return $row;
2241 +}
2242 +
2243 +function plugin_actions($plugin) {
2244 +       $link = "<td>";
2245 +       switch ($plugin['status']) {
2246 +               case "-2": // Old PA Not Installed
2247 +                       $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>";
2248 +                       $link .= "<img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'>";
2249 +                       break;
2250 +               case "-1":      // Old PA Currently Active
2251 +                       $oldplugins = read_config_option('oldplugins');
2252 +                       $oldplugins = explode(',', $oldplugins);
2253 +                       if (in_array($plugin['directory'], $oldplugins)) {
2254 +                               $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>";
2255 +                       } else {
2256 +                               $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>";
2257 +                       }
2258 +                       $link .= "<img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'>";
2259 +                       break;
2260 +               case "0": // Not Installed
2261 +                       $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>";
2262 +                       $link .= "<img style='padding:1px;' border='0' align='absmiddle' src='images/view_none.gif'>";
2263 +                       break;
2264 +               case "1":       // Currently Active
2265 +                       $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>";
2266 +                       $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>";
2267 +                       break;
2268 +               case "4":       // Installed but not active
2269 +                       $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>";
2270 +                       $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>";
2271 +                       break;
2272 +               default: // Old PIA
2273 +                       $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>";
2274 +                       $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>";
2275 +                       break;
2276 +       }
2277 +       $link .= "</td>";
2278 +
2279 +       return $link;
2280 +}
2281 +
2282 +function is_system_plugin($plugin) {
2283 +       global $plugins_system;
2284 +
2285 +       if (is_array($plugin)) {
2286 +               $plugin = $plugin["directory"];
2287 +       }
2288 +
2289 +       if (!in_array($plugin, $plugins_system)) {
2290 +               return false;
2291 +       }else{
2292 +               return true;
2293 +       }
2294 +}
2295 +
2296 +function get_system_plugins($plugins) {
2297 +       $inst_system_plugins = array();
2298 +
2299 +       if (sizeof($plugins)) {
2300 +               foreach($plugins as $plugin) {
2301 +                       if (is_system_plugin($plugin)) {
2302 +                               $inst_system_plugins[] = $plugin;
2303 +                       }
2304 +               }
2305 +       }
2306 +
2307 +       return $inst_system_plugins;
2308 +}
2309 +
2310 +
2311 diff -Naur cacti-0.8.7g-old/poller.php cacti-0.8.7g/poller.php
2312 --- cacti-0.8.7g-old/poller.php 2010-07-09 18:33:46.000000000 -0400
2313 +++ cacti-0.8.7g/poller.php     2010-07-09 18:34:11.000000000 -0400
2314 @@ -108,6 +108,8 @@
2315         pcntl_signal(SIGINT, "sig_handler");
2316  }
2317  
2318 +api_plugin_hook('poller_top');
2319 +
2320  /* record the start time */
2321  list($micro,$seconds) = split(" ", microtime());
2322  $poller_start         = $seconds + $micro;
2323 @@ -304,6 +306,8 @@
2324                         $total_procs    = $concurrent_processes;
2325                 }
2326  
2327 +               $extra_args = api_plugin_hook_function ('poller_command_args', $extra_args);
2328 +
2329                 /* Populate each execution file with appropriate information */
2330                 foreach ($polling_hosts as $item) {
2331                         if ($host_count == 1) {
2332 @@ -495,4 +501,6 @@
2333         echo "    --debug|-d     Output debug information.  Similar to cacti's DEBUG logging level.\n\n";
2334  }
2335  
2336 +api_plugin_hook('poller_bottom');
2337 +
2338  ?>
2339 diff -Naur cacti-0.8.7g-old/user_admin.php cacti-0.8.7g/user_admin.php
2340 --- cacti-0.8.7g-old/user_admin.php     2010-07-09 18:33:46.000000000 -0400
2341 +++ cacti-0.8.7g/user_admin.php 2010-07-09 18:34:11.000000000 -0400
2342 @@ -57,9 +57,11 @@
2343                 break;
2344  
2345         default:
2346 -               include_once("include/top_header.php");
2347 -               user();
2348 -               include_once("include/bottom_footer.php");
2349 +               if (!api_plugin_hook_function('user_admin_action', get_request_var_request("action"))) {
2350 +                       include_once("include/top_header.php");
2351 +                       user();
2352 +                       include_once("include/bottom_footer.php");
2353 +               }
2354                 break;
2355  }
2356  
2357 @@ -402,6 +404,7 @@
2358                 $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);
2359                 $save["realm"] = get_request_var_post("realm", 0);
2360                 $save["enabled"] = form_input_validate(get_request_var_post("enabled", ""), "enabled", "", true, 3);
2361 +               $save = api_plugin_hook_function('user_admin_setup_sql_save', $save);
2362  
2363                 if (!is_error_message()) {
2364                         $user_id = sql_save($save, "user_auth");
2365 @@ -444,6 +447,8 @@
2366                                         policy_hosts = " . get_request_var_post("policy_hosts") . ",
2367                                         policy_graph_templates = " . get_request_var_post("policy_graph_templates") . "
2368                                         WHERE id = " . get_request_var_post("id"));
2369 +                       } else {
2370 +                               api_plugin_hook('user_admin_user_save');
2371                         }
2372                 }
2373         }
2374 @@ -889,6 +894,8 @@
2375                 $header_label = "[new]";
2376         }
2377  
2378 +       api_plugin_hook_function('user_admin_edit', (isset($user) ? get_request_var("id") : 0));
2379 +
2380         html_start_box("<strong>User Management</strong> $header_label", "100%", $colors["header"], "3", "center", "");
2381  
2382         draw_edit_form(array(
2383 diff -Naur cacti-0.8.7g-old/utilities.php cacti-0.8.7g/utilities.php
2384 --- cacti-0.8.7g-old/utilities.php      2010-07-09 18:33:46.000000000 -0400
2385 +++ cacti-0.8.7g/utilities.php  2010-07-09 18:34:11.000000000 -0400
2386 @@ -123,11 +123,14 @@
2387                 include_once("./include/bottom_footer.php");
2388                 break;
2389         default:
2390 -               include_once("./include/top_header.php");
2391  
2392 -               utilities();
2393 +               if (!api_plugin_hook_function('utilities_action', $_REQUEST['action'])) {
2394 +                       include_once('./include/top_header.php');
2395  
2396 -               include_once("./include/bottom_footer.php");
2397 +                       utilities();
2398 +
2399 +                       include_once('./include/bottom_footer.php');
2400 +               }
2401                 break;
2402  }
2403  
2404 @@ -1644,6 +1647,8 @@
2405  
2406         <?php
2407  
2408 +       api_plugin_hook('utilities_list');
2409 +
2410         html_end_box();
2411  }
2412  
This page took 0.308046 seconds and 2 git commands to generate.