ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

app_plugin_list.inc.php
Go to the documentation of this file.
1 <?php
2 
3 //
4 // So, the basic flow of this script is like this:
5 // * When the window is initially opened we define the normal window
6 // parameters for building an almost empty window. After that new
7 // empty window is created it's instructed to run an xajax callback
8 // to the display_list() function. display_list() builds an
9 // html list of groups and pushes it into the empty window.
10 // * If a search is entered into the "quick filter" another xajax
11 // call is made to display_list(), this time passing a search
12 // query. display_list() grabs the refined list of groups
13 // and pushes them to the window just like the first time.
14 //
15 //
16 //
17 
18 
19 // Check permissions
20 if (!auth('advanced')) {
21  $window['js'] = "alert('Permission denied!'); removeElement('{$window_name}');";
22  return;
23 }
24 
25 
26 // Set the window title:
27 $window['title'] = "Plugin Management";
28 
29 // Load some html into $window['html']
30 $form_id = "{$window_name}_filter_form";
31 $tab = 'plugins';
32 $submit_window = $window_name;
33 $content_id = "{$window_name}_list";
34 $window['html'] .= <<<EOL
35  <!-- Tabs & Quick Filter -->
36  <table width="100%" cellspacing="0" border="0" cellpadding="0" >
37  <tr>
38  <td id="{$form_id}_{$tab}_tab" nowrap="true" class="table-tab-active">
39  Plugins <span id="{$form_id}_{$tab}_count"></span>
40  </td>
41 
42  <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
43  <form id="{$form_id}" onSubmit="return false;">
44  <input id="{$form_id}_page" name="page" value="1" type="hidden">
45  <input name="content_id" value="{$content_id}" type="hidden">
46  <input name="form_id" value="{$form_id}" type="hidden">
47  <div id="{$form_id}_filter_overlay"
48  style="position: relative;
49  display: inline;
50  color: #CACACA;
51  cursor: text;"
52  onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
53  >Name</div>
54  <input
55  id="{$form_id}_filter"
56  name="filter"
57  class="filter"
58  type="text"
59  value=""
60  size="10"
61  maxlength="20"
62  alt="Quick Filter"
63  onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
64  onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
65  onKeyUp="
66  if (typeof(timer) != 'undefined') clearTimeout(timer);
67  code = 'if ({$form_id}_last_search != el(\'{$form_id}_filter\').value) {' +
68  ' {$form_id}_last_search = el(\'{$form_id}_filter\').value;' +
69  ' document.getElementById(\'{$form_id}_page\').value = 1;' +
70  ' xajax_window_submit(\'{$submit_window}\', xajax.getFormValues(\'{$form_id}\'), \'display_list\');' +
71  '}';
72  timer = setTimeout(code, 700);"
73  >
74  </form>
75  </td>
76 
77  </tr>
78  </table>
79 
80  <!-- Item List -->
81  <div id='{$content_id}'>
82  {$conf['loading_icon']}
83  </div>
84 EOL;
85 
86 
87 
88 
89 
90 
91 
92 // Define javascript to run after the window is created
93 $window['js'] = <<<EOL
94  /* Put a minimize icon in the title bar */
95  el('{$window_name}_title_r').innerHTML =
96  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
97  el('{$window_name}_title_r').innerHTML;
98 
99  /* Put a help icon in the title bar */
100  el('{$window_name}_title_r').innerHTML =
101  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
102  el('{$window_name}_title_r').innerHTML;
103 
104  /* Setup the quick filter */
105  el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
106  {$form_id}_last_search = '';
107 
108  /* Tell the browser to load/display the list */
109  xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 // This function displays a list (all?) groups in the
124 function ws_display_list($window_name, $form) {
125  global $conf, $self, $onadb, $base;
126  global $font_family, $color, $style, $images;
127 
128  // Check permissions
129  if (!auth('advanced')) {
130  $response = new xajaxResponse();
131  $response->addScript("alert('Permission denied!');");
132  return($response->getXML());
133  }
134 
135  // If the group supplied an array in a string, build the array and store it in $form
136  $form = parse_options_string($form);
137 
138  // Find out what page we're on
139  $page = 1;
140  if ($form['page'] and is_numeric($form['page'])) { $page = $form['page']; }
141 
142 
143  $html = <<<EOL
144 
145  <!-- Results Table -->
146  <table cellspacing="0" border="0" cellpadding="0" width="100%" class="list-box">
147 
148  <!-- Table Header -->
149  <tr>
150  <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
151  <td class="list-header" align="center" style="{$style['borderR']};">Version</td>
152  <td class="list-header" align="center" style="{$style['borderR']};">Description</td>
153  <td class="list-header" align="center">&nbsp;</td>
154  </tr>
155 
156 EOL;
157 
158 
159  // Generate a list of reports available
160  $records = array();
161 
162 
163  // Check the usual directories, now includes the local reports as well.
164  // local plugins should override the builtin stuff if they are named the same.
165  $directories = array($base.'/local/plugins/',$base.'/plugins/');
166 
167  // Scan the directories to find the report include file
168  foreach ($directories as $directory) {
169  if (is_dir($directory)) {
170  $d = dir($directory);
171  while (false!== ($filename = $d->read())) {
172  if ($filename != '.' and $filename != '..' and $filename != 'README' and $filename != '.svn' and substr($filename, -7) != '.tar.gz') {
173  //include "$directory$filename";
174  if (is_array($form) and $form['filter']) {
175  if (preg_match("/{$form['filter']}/i", $filename))
176  array_push($records, $directory.$filename);
177  } else {
178  array_push($records, $directory.$filename);
179  }
180  }
181  }
182  $d->close();
183  }
184  }
185 
186  $count = count($records);
187  @sort($records);
188 
189  // split the array into chunks of result size
190  $records = @array_chunk($records, $conf['search_results_per_page']);
191 
192  if (!$records[0]) {
193  $html .= <<<EOL
194 <tr><td colspan=4><center>There are currently no plugins installed OR <br> the search returned no results. Please<br>visit <a href="http://opennetadmin.com">OpenNetAdmin.com</a> to download new plugins.</center></td></tr>
195 EOL;
196  } else {
197 
198  // Loop through and display the groups
199  foreach ($records[$page-1] as $entry) {
200 
201  $plugin_description = '';
202  $plugin_version = '';
203  $plugin_help_url = '';
204  $record['name'] = basename($entry);
205 
206  @include_once $entry.'/plugin_info.php';
207  $record['desc'] = $plugin_description;
208  $record['version'] = ($plugin_version) ? $plugin_version : 'Unknown';
209  $record['help_url'] = $plugin_help_url;
210 
211  $record['disabled'] = (file_exists($entry.'/plugin_disabled')) ? true : false;
212  $record['installed'] = (file_exists($entry.'/install.php')) ? true : false;
213 
214  // Escape data for display in html
215  foreach(array_keys($record) as $key) {
216  $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
217  }
218 
219  $html .= <<<EOL
220  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
221 
222  <td class="list-row">
223  {$record['name']}&nbsp;
224  </td>
225 
226  <td class="list-row">
227  {$record['version']}&nbsp;
228  </td>
229 
230  <td class="list-row">
231  {$record['desc']}&nbsp;
232  </td>
233 
234  <td align="right" class="list-row" nowrap="true">
235 EOL;
236 
237  if ($record['installed']) {
238  $html .= <<<EOL
239  <a title="Execute install steps: {$record['name']}"
240  class="act"
241  onClick="toggle_window('{$record['name']}');"
242  ><img src="{$images}/silk/plugin_error.png" border="0"></a>&nbsp;
243 EOL;
244  }
245 
246  if ($record['help_url']) {
247  $html .= <<<EOL
248  <a title="Plugin help and info URL"
249  class="act"
250  target="_blank"
251  href="{$record['help_url']}"
252  ><img src="{$images}/silk/help.png" border="0"></a>&nbsp;
253 EOL;
254  }
255 
256  if ($record['disabled']) {
257  $html .= <<<EOL
258  <a title="Enable plugin: {$record['name']}"
259  class="act"
260  onClick="xajax_window_submit('app_plugin_list', 'plugin=>{$record['name']},state=>enable,path=>{$entry}', 'toggleenable');"
261  ><img src="{$images}/silk/plugin_disabled.png" border="0"></a>&nbsp;
262 EOL;
263 
264  } else {
265 
266  $html .= <<<EOL
267  <a title="Disable plugin: {$record['name']}"
268  class="act"
269  onClick="xajax_window_submit('app_plugin_list', 'plugin=>{$record['name']},state=>disable,path=>{$entry}', 'toggleenable');"
270  ><img src="{$images}/silk/plugin.png" border="0"></a>&nbsp;
271 EOL;
272 
273  }
274 
275 // $html .= <<<EOL
276 // <a title="Uninstall plugin: {$record['name']}"
277 // class="act"
278 // onClick="xajax_window_submit('app_plugin_list', 'plugin=>{$record['name']},state=>disable', 'uninstall')');"
279 // ><img src="{$images}/silk/plugin_delete.png" border="0"></a>&nbsp;
280 // EOL;
281 
282 
283 
284 
285  $html .= <<<EOL
286  </td>
287 
288  </tr>
289 EOL;
290  }
291 
292  $html .= <<<EOL
293  </table>
294 
295 EOL;
296 }
297 
298  // Build page links if there are any
299  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
300 
301 
302  // Insert the new table into the window
303  // Instantiate the xajaxResponse object
304  $response = new xajaxResponse();
305  $response->addAssign("{$form['form_id']}_plugins_count", "innerHTML", "({$count})");
306  $response->addAssign("{$form['content_id']}", "innerHTML", $html);
307  $response->addScript($js);
308  return($response->getXML());
309 }
310 
311 
312 
313 
314 
315 
316 
317 
318 
319 
321 // Function:
322 // Toggle plugin enable Form
323 //
324 // Description:
325 // toggles a plugins state by touching or removing the plugin_disabled file
326 
328 function ws_toggleenable($window_name, $form='') {
329  global $include, $conf, $self, $onadb;
330 
331  // Check permissions
332  if (!auth('advanced')) {
333  $response = new xajaxResponse();
334  $response->addScript("alert('Permission denied!');");
335  return($response->getXML());
336  }
337 
338  // If an array in a string was provided, build the array and store it in $form
339  $form = parse_options_string($form);
340 
341  // Instantiate the xajaxResponse object
342  $response = new xajaxResponse();
343  $js = "xajax_window_submit('app_plugin_list', xajax.getFormValues('app_plugin_list_filter_form'), 'display_list');";
344 
345  if (is_writable($form['path'])) {
346  if ($form['state'] == 'disable') {
347  touch($form['path'].'/plugin_disabled');
348  }
349  if ($form['state'] == 'enable') {
350  unlink($form['path'].'/plugin_disabled');
351  }
352  } else {
353  $js .= "alert('Plugin path {$form['path']} is not writeable by the web server!');";
354  }
355 
356  if ($form['task'] == 'install') {
357  return(window_open('', $window));
358  }
359 
360  if ($form['js'])
361  $js .= $form['js']; // usually js will refresh the window we got called from
362 
363  // Return an XML response
364  $response->addScript($js);
365  return($response->getXML());
366 }
367 
368 
369 
370 
371 
372 
373 
374 ?>
$content_id
$content_id
Definition: app_plugin_list.inc.php:33
$submit_window
$submit_window
Definition: app_plugin_list.inc.php:32
$form_id
$form_id
Definition: app_plugin_list.inc.php:30
$window
if(!auth('advanced')) $window['title']
Definition: app_plugin_list.inc.php:27
Name
Full Name
Definition: app_user_info.inc.php:101
ws_display_list
ws_display_list($window_name, $form)
Definition: app_plugin_list.inc.php:124
$plugin_description
$plugin_description
Definition: plugin_info.php:6
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
xajax
$plugin_version
$plugin_version
Definition: plugin_info.php:7
ws_toggleenable
ws_toggleenable($window_name, $form='')
Definition: app_plugin_list.inc.php:328
$include
$include
Definition: 2-to-3.php:10
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
$plugin_help_url
$plugin_help_url
Definition: plugin_info.php:8
$images
$images
Definition: config.inc.php:26
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
nbsp
& nbsp
Definition: install.php:36
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
get_page_links
get_page_links($page=1, $per_page=1, $total=1, $window_name='', $form_id='')
Definition: xajax_setup.inc.php:115
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$base
$base
Definition: 2-to-3.php:8
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
EOL
EOL
Definition: app_plugin_list.inc.php:110
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88
$tab
$tab
Definition: app_plugin_list.inc.php:31