2008-08-04 10:15:16 +02:00
|
|
|
<?php
|
|
|
|
|
2008-08-22 20:07:32 +02:00
|
|
|
// Pandora FMS - the Flexible Monitoring System
|
|
|
|
// ============================================
|
|
|
|
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
|
|
|
|
// Please see http://pandora.sourceforge.net for full contribution list
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
2008-09-01 06:22:26 +02:00
|
|
|
// modify it under the terms of the GNU Lesser General Public License (LGPL)
|
2008-08-22 20:07:32 +02:00
|
|
|
// as published by the Free Software Foundation for version 2.
|
2008-09-01 06:22:26 +02:00
|
|
|
//
|
2008-08-22 20:07:32 +02:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2008-08-04 10:15:16 +02:00
|
|
|
$extension_file = '';
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
*/
|
2008-08-05 12:47:40 +02:00
|
|
|
function extension_call_main_function ($filename) {
|
2008-08-04 10:15:16 +02:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
$extension = &$config['extensions'][$filename];
|
|
|
|
if ($extension['main_function'] != '') {
|
|
|
|
$params = array ();
|
|
|
|
call_user_func_array ($extension['main_function'], $params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $filename
|
|
|
|
*/
|
2008-08-05 12:47:40 +02:00
|
|
|
function extension_call_godmode_function ($filename) {
|
2008-08-04 10:15:16 +02:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
$extension = &$config['extensions'][$filename];
|
|
|
|
if ($extension['godmode_function'] != '') {
|
|
|
|
$params = array ();
|
|
|
|
call_user_func_array ($extension['godmode_function'], $params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*/
|
2008-08-05 12:47:40 +02:00
|
|
|
function extensions_call_login_function () {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$params = array ();
|
|
|
|
foreach ($config['extensions'] as $extension) {
|
|
|
|
if ($extension['login_function'] == '')
|
|
|
|
continue;
|
|
|
|
call_user_func_array ($extension['login_function'], $params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $page
|
|
|
|
*/
|
2008-08-04 10:15:16 +02:00
|
|
|
function is_extension ($page) {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$filename = basename ($page);
|
|
|
|
return isset ($config['extensions'][$filename]);
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param bool $enterprise
|
|
|
|
*/
|
2008-10-14 11:19:19 +02:00
|
|
|
function get_extensions ($enterprise = false) {
|
|
|
|
$dir = EXTENSIONS_DIR;
|
2009-03-05 18:40:40 +01:00
|
|
|
$handle = false;
|
2008-10-14 11:19:19 +02:00
|
|
|
if ($enterprise)
|
|
|
|
$dir = ENTERPRISE_DIR.'/'.EXTENSIONS_DIR;
|
2009-03-05 18:40:40 +01:00
|
|
|
|
|
|
|
if (file_exists ($dir))
|
|
|
|
$handle = @opendir ($dir);
|
|
|
|
|
|
|
|
if (empty ($handle))
|
2008-08-04 10:15:16 +02:00
|
|
|
return;
|
2009-03-05 18:40:40 +01:00
|
|
|
|
2008-08-04 10:15:16 +02:00
|
|
|
$file = readdir ($handle);
|
|
|
|
$extensions = array ();
|
|
|
|
$ignores = array ('.', '..');
|
|
|
|
while ($file !== false) {
|
|
|
|
if (in_array ($file, $ignores)) {
|
|
|
|
$file = readdir ($handle);
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-14 11:19:19 +02:00
|
|
|
$filepath = realpath ($dir."/".$file);
|
2008-08-04 10:15:16 +02:00
|
|
|
if (! is_readable ($filepath) || is_dir ($filepath) || ! preg_match ("/.*\.php$/", $filepath)) {
|
|
|
|
$file = readdir ($handle);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$extension['file'] = $file;
|
|
|
|
$extension['operation_menu'] = '';
|
|
|
|
$extension['godmode_menu'] = '';
|
|
|
|
$extension['main_function'] = '';
|
|
|
|
$extension['godmode_function'] = '';
|
|
|
|
$extension['login_function'] = '';
|
2008-10-14 11:19:19 +02:00
|
|
|
$extension['enterprise'] = $enterprise;
|
|
|
|
$extension['dir'] = $dir;
|
2008-08-04 10:15:16 +02:00
|
|
|
$extensions[$file] = $extension;
|
|
|
|
$file = readdir ($handle);
|
|
|
|
}
|
2008-10-14 11:19:19 +02:00
|
|
|
|
|
|
|
/* Load extensions in enterprise directory */
|
|
|
|
if (! $enterprise && file_exists (ENTERPRISE_DIR.'/'.EXTENSIONS_DIR))
|
|
|
|
return array_merge ($extensions, get_extensions (true));
|
|
|
|
|
2008-08-04 10:15:16 +02:00
|
|
|
return $extensions;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param array $extensions
|
|
|
|
*/
|
2008-08-04 10:15:16 +02:00
|
|
|
function load_extensions ($extensions) {
|
|
|
|
global $config;
|
|
|
|
global $extension_file;
|
|
|
|
|
|
|
|
foreach ($extensions as $extension) {
|
|
|
|
$extension_file = $extension['file'];
|
2008-10-14 11:19:19 +02:00
|
|
|
include_once (realpath ($extension['dir']."/".$extension_file));
|
2008-08-04 10:15:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2008-08-04 10:15:16 +02:00
|
|
|
function add_operation_menu_option ($name) {
|
|
|
|
global $config;
|
|
|
|
global $extension_file;
|
|
|
|
|
|
|
|
/* $config['extension_file'] is set in load_extensions(), since that function must
|
|
|
|
be called before any function the extension call, we are sure it will
|
|
|
|
be set. */
|
|
|
|
$option_menu['name'] = substr ($name, 0, 15);
|
|
|
|
$extension = &$config['extensions'][$extension_file];
|
2008-10-14 11:19:19 +02:00
|
|
|
$option_menu['sec2'] = $extension['dir'].'/'.substr ($extension_file, 0, -4);
|
2008-08-04 10:15:16 +02:00
|
|
|
$extension['operation_menu'] = $option_menu;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $acl
|
|
|
|
*/
|
2008-08-04 10:15:16 +02:00
|
|
|
function add_godmode_menu_option ($name, $acl) {
|
|
|
|
global $config;
|
|
|
|
global $extension_file;
|
|
|
|
|
|
|
|
/* $config['extension_file'] is set in load_extensions(), since that function must
|
|
|
|
be called before any function the extension call, we are sure it will
|
|
|
|
be set. */
|
|
|
|
$option_menu['acl'] = $acl;
|
|
|
|
$option_menu['name'] = substr ($name, 0, 15);
|
|
|
|
$extension = &$config['extensions'][$extension_file];
|
2008-10-14 11:19:19 +02:00
|
|
|
$option_menu['sec2'] = $extension['dir'].'/'.substr ($extension_file, 0, -4);
|
2008-08-04 10:15:16 +02:00
|
|
|
$extension['godmode_menu'] = $option_menu;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $function_name
|
|
|
|
*/
|
2008-08-04 10:15:16 +02:00
|
|
|
function add_extension_main_function ($function_name) {
|
|
|
|
global $config;
|
|
|
|
global $extension_file;
|
|
|
|
|
|
|
|
$extension = &$config['extensions'][$extension_file];
|
|
|
|
$extension['main_function'] = $function_name;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $function_name
|
|
|
|
*/
|
2008-08-04 10:15:16 +02:00
|
|
|
function add_extension_godmode_function ($function_name) {
|
|
|
|
global $config;
|
|
|
|
global $extension_file;
|
|
|
|
|
|
|
|
$extension = &$config['extensions'][$extension_file];
|
|
|
|
$extension['godmode_function'] = $function_name;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:52:13 +01:00
|
|
|
/**
|
|
|
|
* TODO: Document extensions
|
|
|
|
*
|
|
|
|
* @param string $function_name
|
|
|
|
*/
|
2008-08-05 12:47:40 +02:00
|
|
|
function add_extension_login_function ($function_name) {
|
2008-08-04 10:15:16 +02:00
|
|
|
global $config;
|
|
|
|
global $extension_file;
|
|
|
|
|
|
|
|
$extension = &$config['extensions'][$extension_file];
|
|
|
|
$extension['login_function'] = $function_name;
|
|
|
|
}
|
|
|
|
?>
|