2014-06-10 Miguel de Dios <miguel.dedios@artica.es>
* extensions/update_manager.php, extensions/update_manager/*, include/functions_config.php: remove the old update manager. Bye bye my old friend. * godmode/update_manager_xxx -> godmode/update_manager, godmode/update_manager/* -> godmode/update_manager/*, godmode/menu.php: rename the update manager. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10155 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
61144da653
commit
b4c3ed60bc
|
@ -1,3 +1,14 @@
|
|||
2014-06-10 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* extensions/update_manager.php, extensions/update_manager/*,
|
||||
include/functions_config.php: remove the old update manager. Bye bye
|
||||
my old friend.
|
||||
|
||||
* godmode/update_manager_xxx -> godmode/update_manager,
|
||||
godmode/update_manager/* -> godmode/update_manager/*,
|
||||
godmode/menu.php: rename
|
||||
the update manager.
|
||||
|
||||
2014-06-10 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/functions_config.php,
|
||||
|
|
|
@ -1,247 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// 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.
|
||||
|
||||
if (is_ajax ()) {
|
||||
global $config;
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('update_manager/lib/functions.ajax.php');
|
||||
|
||||
$checking_online_enterprise_package =
|
||||
(bool)get_parameter('checking_online_enterprise_package', false);
|
||||
|
||||
$get_license_info = get_parameter('get_license_info', 0);
|
||||
|
||||
if ($checking_online_enterprise_package) {
|
||||
checking_online_enterprise_package();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_license_info) {
|
||||
enterprise_include_once('include/functions_license.php');
|
||||
|
||||
// If Pandora enterprise check license
|
||||
$is_enteprise = enterprise_hook('license_show_info');
|
||||
|
||||
// If Open show info
|
||||
if ($is_enteprise === ENTERPRISE_NOT_HOOK) {
|
||||
$table->width = '98%';
|
||||
$table->data = array ();
|
||||
$table->style = array();
|
||||
$table->style[0] = 'text-align: left';
|
||||
|
||||
echo '<div style="float: left; width: 20%; margin-top: 40px; margin-left: 20px;">';
|
||||
html_print_image('images/lock_license.png', false);
|
||||
echo '</div>';
|
||||
|
||||
$table->data[0][0] = '<strong>'.__('Expires').'</strong>';
|
||||
$table->data[0][1] = __('Never');
|
||||
$table->data[1][0] = '<strong>'.__('Platform Limit').'</strong>';
|
||||
$table->data[1][1] = __('Unlimited');
|
||||
$table->data[2][0] = '<strong>'.__('Current Platform Count').'</strong>';
|
||||
$count_agents = db_get_value_sql ('SELECT count(*) FROM tagente');
|
||||
$table->data[2][1] = $count_agents;
|
||||
$table->data[3][0] = '<strong>'.__('License Mode').'</strong>';
|
||||
$table->data[3][1] = __('Open Source Version');
|
||||
|
||||
echo '<div style="width: 70%; margin-top: 30px; margin-left: 20px; float: right;">';
|
||||
html_print_table ($table);
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function load_update_manager_lib () {
|
||||
set_time_limit (0);
|
||||
require_once ('update_manager/load_updatemanager.php');
|
||||
}
|
||||
|
||||
function update_settings_database_connection () {
|
||||
global $config;
|
||||
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname'], $config['dbport']);
|
||||
um_db_update_setting ('dbport', $config['dbport']);
|
||||
um_db_update_setting ('dbname', $config['dbname']);
|
||||
um_db_update_setting ('dbuser', $config['dbuser']);
|
||||
um_db_update_setting ('dbpass', $config['dbpass']);
|
||||
um_db_update_setting ('dbhost', $config['dbhost']);
|
||||
}
|
||||
|
||||
function pandora_update_manager_install () {
|
||||
global $config;
|
||||
|
||||
load_update_manager_lib ();
|
||||
|
||||
if (isset($config['update_manager_installed'])) {
|
||||
if ($config['update_manager_installed'] == 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* SQL installation */
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
$sentences = file (EXTENSIONS_DIR.'/update_manager/sql/update_manager.sql');
|
||||
break;
|
||||
case 'postgresql':
|
||||
$sentences = file (EXTENSIONS_DIR.'/update_manager/sql/update_manager.postgreSQL.sql');
|
||||
break;
|
||||
case 'oracle':
|
||||
$sentences = file (EXTENSIONS_DIR.'/update_manager/sql/update_manager.oracle.sql');
|
||||
break;
|
||||
}
|
||||
foreach ($sentences as $sentence) {
|
||||
if (trim ($sentence) == "")
|
||||
continue;
|
||||
$success = db_process_sql ($sentence);
|
||||
if ($success === false)
|
||||
return;
|
||||
}
|
||||
|
||||
$values = array("token" => "update_manager_installed",
|
||||
"value" => 1);
|
||||
db_process_sql_insert('tconfig', $values);
|
||||
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname'], $config['dbport']);
|
||||
um_db_update_setting ('updating_code_path',
|
||||
dirname ($_SERVER['SCRIPT_FILENAME']));
|
||||
update_settings_database_connection ();
|
||||
}
|
||||
|
||||
function pandora_update_manager_uninstall () {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
db_process_sql ('DELETE FROM `tconfig`
|
||||
WHERE `token` = "update_manager_installed"');
|
||||
db_process_sql ('DROP TABLE `tupdate_settings`');
|
||||
db_process_sql ('DROP TABLE `tupdate_journal`');
|
||||
db_process_sql ('DROP TABLE `tupdate`');
|
||||
db_process_sql ('DROP TABLE `tupdate_package`');
|
||||
break;
|
||||
case "postgresql":
|
||||
db_process_sql ('DELETE FROM "tconfig"
|
||||
WHERE "token" = \'update_manager_installed\'');
|
||||
db_process_sql ('DROP TABLE "tupdate_settings"');
|
||||
db_process_sql ('DROP TABLE "tupdate_journal"');
|
||||
db_process_sql ('DROP TABLE "tupdate"');
|
||||
db_process_sql ('DROP TABLE "tupdate_package"');
|
||||
break;
|
||||
case "oracle":
|
||||
db_process_sql ('DELETE FROM tconfig
|
||||
WHERE token = \'update_manager_installed\'');
|
||||
db_process_sql ('DROP TABLE tupdate_settings');
|
||||
db_process_sql ('DROP TABLE tupdate_journal');
|
||||
db_process_sql ('DROP TABLE tupdate');
|
||||
db_process_sql ('DROP TABLE tupdate_package');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The code for to show in the operation menu entry.
|
||||
*/
|
||||
function pandora_update_manager_main () {
|
||||
global $config;
|
||||
|
||||
|
||||
if (! check_acl($config['id_user'], 0, "PM")) {
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
load_update_manager_lib ();
|
||||
update_settings_database_connection ();
|
||||
|
||||
require_once ('update_manager/main.php');
|
||||
|
||||
main_view();
|
||||
}
|
||||
|
||||
function pandora_update_manager_login () {
|
||||
global $config;
|
||||
|
||||
if ($config["autoupdate"] == 0)
|
||||
return;
|
||||
|
||||
unset($_SESSION['new_update']);
|
||||
|
||||
if (enterprise_installed()) {
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname'], $config['dbport']);
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$user_key = get_user_key ($settings);
|
||||
|
||||
$package = @um_client_check_latest_update ($settings, $user_key);
|
||||
|
||||
if (is_object ($package)) {
|
||||
if ($package->id != 'ERROR_NON_NUMERIC_FOUND') {
|
||||
$_SESSION['new_update'] = 'new';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
require_once(
|
||||
"extensions/update_manager/lib/functions.ajax.php");
|
||||
require_once("extensions/update_manager/lib/functions.php");
|
||||
|
||||
$return_installation_open = array();
|
||||
if (!update_pandora_check_installation()) {
|
||||
$return_installation_open = update_pandora_installation();
|
||||
}
|
||||
|
||||
$result = update_pandora_get_packages_online_ajax(false);
|
||||
|
||||
if ($result['correct']) {
|
||||
$_SESSION['new_update'] = 'new';
|
||||
$_SESSION['return_installation_open'] = $return_installation_open;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pandora_update_manager_godmode () {
|
||||
global $config;
|
||||
|
||||
load_update_manager_lib ();
|
||||
|
||||
require_once ('update_manager/settings.php');
|
||||
}
|
||||
|
||||
extensions_add_operation_menu_option (__('Update manager'), null, null, "v1r1");
|
||||
extensions_add_godmode_menu_option (__('Update manager settings'), 'PM', null, null, "v1r1");
|
||||
extensions_add_main_function ('pandora_update_manager_main');
|
||||
extensions_add_godmode_function ('pandora_update_manager_godmode');
|
||||
//extensions_add_login_function ('pandora_update_manager_login');
|
||||
|
||||
pandora_update_manager_install ();
|
||||
|
||||
$db = NULL;
|
||||
?>
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
///////PLEASE DONT TOUCH
|
||||
global $debug_update_manager;
|
||||
global $debug_mode_output;
|
||||
////////////////////////////////////
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
///////PLEASE ONLY CHANGE THESE VALUES
|
||||
$debug_update_manager = 0;
|
||||
//There are "notice_php" and "logDebug".
|
||||
$debug_mode_output = "notice_php";
|
||||
////////////////////////////////////
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
///////PLEASE DONT TOUCH
|
||||
function print_debug_message_trace($message) {
|
||||
global $debug_update_manager;
|
||||
global $debug_mode_output;
|
||||
|
||||
if ($debug_update_manager) {
|
||||
switch ($debug_mode_output) {
|
||||
case "notice_php":
|
||||
trigger_error("PRINT DEBUG TRACE",
|
||||
E_USER_NOTICE);
|
||||
|
||||
trigger_error($message, E_USER_NOTICE);
|
||||
|
||||
$backtrace = json_encode(debug_backtrace());
|
||||
$backtrace_chunks = str_split($backtrace, 1024);
|
||||
|
||||
trigger_error("INIT DEBUG BACKTRACE (JSON ENCODE) CHUNKS " .
|
||||
count($backtrace_chunks), E_USER_NOTICE);
|
||||
foreach ($backtrace_chunks as $chunk)
|
||||
trigger_error($chunk, E_USER_NOTICE);
|
||||
trigger_error("END DEBUG BACKTRACE (JSON ENCODE)",
|
||||
E_USER_NOTICE);
|
||||
break;
|
||||
case "logDebug":
|
||||
html_debug_print($message, true);
|
||||
html_debug_print(debug_backtrace(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////
|
||||
////////////////////////////////////
|
||||
?>
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Translation file for Open Update Manager in Pandora.
|
||||
*/
|
||||
|
||||
$lang_label['Update manager'] = 'Update manager';
|
||||
?>
|
|
@ -1,565 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// 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.
|
||||
|
||||
function check_keygen_online() {
|
||||
global $config;
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/lib/functions.php");
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager_client.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/load_updatemanager.php");
|
||||
|
||||
$last = get_parameter('last', 0);
|
||||
|
||||
db_clean_cache();
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
print_debug_message_trace("End Call check_keygen_online function.");
|
||||
|
||||
return check_keygen ($settings);
|
||||
}
|
||||
|
||||
function update_pandora_get_packages_online_ajax($ajax = true) {
|
||||
global $config;
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/lib/functions.php");
|
||||
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager_client.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/load_updatemanager.php");
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call update_pandora_get_packages_online_ajax function.");
|
||||
|
||||
$last = get_parameter('last', 0);
|
||||
|
||||
db_clean_cache();
|
||||
$settings = um_db_load_settings ();
|
||||
$user_key = get_user_key ($settings);
|
||||
|
||||
$params = array(
|
||||
new xmlrpcval((int)$conf_update_pandora['last_contact'], 'int'),
|
||||
new xmlrpcval($user_key, 'string'),
|
||||
new xmlrpcval($settings->customer_key, 'string'));
|
||||
|
||||
$result = @um_xml_rpc_client_call($settings->update_server_host,
|
||||
$settings->update_server_path,
|
||||
$settings->update_server_port,
|
||||
$settings->proxy,
|
||||
$settings->proxy_port,
|
||||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_lastest_package_update_open',
|
||||
$params);
|
||||
|
||||
if ($result == false) {
|
||||
$return['last'] = $last;
|
||||
$return['correct'] = 0;
|
||||
$return['package'] = __('Error download packages.');
|
||||
$return['end'] = 1;
|
||||
}
|
||||
else {
|
||||
$value = $result->value();
|
||||
list($k,$v) = $value->structeach();
|
||||
if ($k == 'package') {
|
||||
$package = $v->scalarval();
|
||||
}
|
||||
list($k,$v) = $value->structeach();
|
||||
if ($k == 'timestamp') {
|
||||
$timestamp = $v->scalarval();
|
||||
}
|
||||
|
||||
$return['correct'] = 1;
|
||||
if (empty($package)) {
|
||||
$return['correct'] = 0;
|
||||
}
|
||||
|
||||
$return['last'] = $last;
|
||||
$return['package'] = $package;
|
||||
if (!isset($config["date_format"]))
|
||||
$default_date_format = "F j, Y, g:i a";
|
||||
else
|
||||
$default_date_format = $config["date_format"];
|
||||
$return['timestamp'] = date($default_date_format, $timestamp);
|
||||
$return['text_adv'] = html_print_image('images/world.png', true);
|
||||
$return['end'] = 1;
|
||||
}
|
||||
|
||||
print_debug_message_trace("End Call update_pandora_get_packages_online_ajax function.");
|
||||
|
||||
if ($ajax)
|
||||
echo json_encode($return);
|
||||
else
|
||||
return $return;
|
||||
}
|
||||
|
||||
function update_pandora_download_package() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager_client.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/load_updatemanager.php");
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call update_pandora_download_package function.");
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
|
||||
$params = array(new xmlrpcval($package, 'string'));
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$result = @um_xml_rpc_client_call ($settings->update_server_host,
|
||||
$settings->update_server_path,
|
||||
$settings->update_server_port,
|
||||
$settings->proxy,
|
||||
$settings->proxy_port,
|
||||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_lastest_package_url_update_open',
|
||||
$params);
|
||||
|
||||
if ($result == false) {
|
||||
$info_json = json_encode(array('correct' => 0));
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX);
|
||||
|
||||
$return = array('correct' => 0);
|
||||
}
|
||||
else {
|
||||
$value = $result->value();
|
||||
$package_url = $value->scalarval();
|
||||
|
||||
if ($conf_update_pandora['download_mode'] == 'wget') {
|
||||
$command = "wget " .
|
||||
$package_url . " -O " . $dir . $package .
|
||||
" -o /tmp/" . $package . ".info.txt";
|
||||
|
||||
if (!empty($settings->proxy)) {
|
||||
$command .= ' -e http_proxy=' . $settings->proxy;
|
||||
if (!empty($settings->proxy_port))
|
||||
$command .= ':' . $settings->proxy_port;
|
||||
}
|
||||
if (!empty($settings->proxy_user))
|
||||
$command .= ' --proxy_user="' . $settings->proxy_user . '"';
|
||||
if (!empty($settings->proxy_pass))
|
||||
$command .= ' --proxy_password="' . $settings->proxy_pass . '"';
|
||||
|
||||
$return = array('correct' => 0);
|
||||
|
||||
exec($command, $output, $status);
|
||||
unlink('/tmp/' . $package . '.info.txt');
|
||||
|
||||
if ($status == 0)
|
||||
$return['correct'] = 1;
|
||||
}
|
||||
else {
|
||||
if (empty($package_url)) {
|
||||
$info_json = json_encode(array('correct' => 0));
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt',
|
||||
$info_json, LOCK_EX);
|
||||
|
||||
$return = array('correct' => 0);
|
||||
}
|
||||
else {
|
||||
$targz = $package;
|
||||
$url = $package_url;
|
||||
|
||||
$file = fopen($dir . $targz, "w");
|
||||
|
||||
$mch = curl_multi_init();
|
||||
$c = curl_init();
|
||||
|
||||
curl_setopt($c, CURLOPT_URL, $url);
|
||||
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($c, CURLOPT_FILE, $file);
|
||||
if (!empty($settings->proxy))
|
||||
curl_setopt($c, CURLOPT_PROXY, $settings->proxy);
|
||||
if (!empty($settings->proxy_port))
|
||||
curl_setopt($c, CURLOPT_PROXYPORT, $settings->proxy_port);
|
||||
if (!empty($settings->proxy_user) || !empty($settings->proxy_pass))
|
||||
curl_setopt($c, CURLOPT_PROXYUSERPWD, $settings->proxy_user . ':' . $settings->proxy_pass);
|
||||
|
||||
curl_multi_add_handle($mch ,$c);
|
||||
$running = null;
|
||||
do {
|
||||
curl_multi_exec($mch ,$running);
|
||||
if ($running == 0) {
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
$info = curl_getinfo ($c);
|
||||
|
||||
$data = array();
|
||||
$data['correct'] = 1;
|
||||
$data['filename'] = $targz;
|
||||
$data['size'] = $info['download_content_length'];
|
||||
$data['size_download'] = $info['size_download'];
|
||||
$data['speed_download'] = $info['speed_download'];
|
||||
$data['total_time'] = $info['total_time'];
|
||||
|
||||
$info_json = json_encode($data);
|
||||
|
||||
file_put_contents('/tmp/' . $package . '.info.txt',
|
||||
$info_json, LOCK_EX);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
while($running > 0);
|
||||
|
||||
if (curl_errno($c) == 0)
|
||||
$return = array('correct' => 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($return['correct']) {
|
||||
$conf_update_pandora['last_contact'] = time();
|
||||
update_pandora_update_conf();
|
||||
}
|
||||
}
|
||||
|
||||
$return['mode'] = $conf_update_pandora['download_mode'];
|
||||
$return['filename'] = $package;
|
||||
|
||||
print_debug_message_trace("End Call update_pandora_download_package function.");
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_check_download_package() {
|
||||
global $config;
|
||||
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call update_pandora_check_download_package function.");
|
||||
|
||||
sleep(1);
|
||||
|
||||
if ($conf_update_pandora['download_mode'] == 'wget') {
|
||||
$return = array('correct' => 1,
|
||||
'info_download' => __('In progress...') . html_print_image('images/spinner.gif', true),
|
||||
'mode' => 'wget');
|
||||
}
|
||||
else {
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$return = array('correct' => 1,
|
||||
'info_download' => "<b>" . __('Size') . ":</b> %s/%s " . __('bytes') . " " .
|
||||
"<b>" . __('Speed') . ":</b> %s " . __('bytes/second') ."<br />" .
|
||||
"<b>" . __('Time') . ":</b> %s",
|
||||
'progres_bar' => progress_bar(0, 300, 20, '0%', 1, false, "#00ff00"),
|
||||
'progres_bar_text' => '0%',
|
||||
'percent' => 0,
|
||||
'mode' => 'curl');
|
||||
|
||||
$info_json = @file_get_contents('/tmp/' . $package . '.info.txt');
|
||||
|
||||
$info = json_decode($info_json, true);
|
||||
|
||||
if ($info['correct'] == 0) {
|
||||
$return['correct'] = 0;
|
||||
unlink('/tmp/' . $package . '.info.txt');
|
||||
}
|
||||
else {
|
||||
$percent = 0;
|
||||
$size_download = 0;
|
||||
$size = 0;
|
||||
$speed_download = 0;
|
||||
$total_time = 0;
|
||||
if ($info['size_download'] > 0) {
|
||||
$percent = format_numeric(
|
||||
($info['size_download'] / $info['size']) * 100, 2);
|
||||
$return['percent'] = $percent;
|
||||
$size_download = $info['size_download'];
|
||||
$size = $info['size'];
|
||||
$speed_download = $info['speed_download'];
|
||||
$total_time = $info['total_time'];
|
||||
|
||||
$return['info_download'] = sprintf($return['info_download'],
|
||||
format_for_graph($size_download, 2), format_for_graph($size, 2),
|
||||
format_for_graph($speed_download, 2),
|
||||
human_time_description_raw($total_time));
|
||||
}
|
||||
else {
|
||||
$return['info_download'] = __('<b>Starting: </b> connect to server');
|
||||
}
|
||||
|
||||
$img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#00ff00");
|
||||
$return['progres_bar'] = $img;
|
||||
preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_src'] = $attr[1];
|
||||
preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_alt'] = $attr[1];
|
||||
preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['progres_bar_title'] = $attr[1];
|
||||
$return['filename'] = $info['filename'];
|
||||
}
|
||||
}
|
||||
|
||||
print_debug_message_trace("End Call update_pandora_check_download_package function.");
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function update_pandora_install_package() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call update_pandora_install_package function.");
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$filename = get_parameter('filename', '');
|
||||
|
||||
unlink("/tmp/$package.info.txt");
|
||||
|
||||
// check which tar is availble
|
||||
exec('tar --version', $output, $status);
|
||||
$tar_type = 'UNKNOWN';
|
||||
foreach ($output as $line) {
|
||||
if (preg_match('/GNU/', $line)) {
|
||||
$tar_type = 'GNU';
|
||||
break;
|
||||
} else if (preg_match('/bsdtar/', $line)) {
|
||||
$tar_type = 'BSD';
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($output);
|
||||
|
||||
//Get total files
|
||||
//The grep command is because the fucking tar don't apply
|
||||
//strip-components in mode "t"
|
||||
$command = 'tar tzvf ' . $dir . $filename .
|
||||
' --exclude="pandora_console/install.php" --exclude="pandora_console/include/config.php" | grep -v "pandora_console/$" | wc -l > /tmp/' . $package . '.info.txt';
|
||||
exec($command, $output, $status);
|
||||
print_debug_message_trace($command);
|
||||
//html_debug_print($command, true);
|
||||
|
||||
$command = 'tar xzvf ' . $dir . $filename .
|
||||
' --exclude="pandora_console/install.php" --exclude="pandora_console/include/config.php" ' .
|
||||
' --strip-components=1 -C ' . $config['homedir'] . ' 1>/tmp/' . $package . '.files.info.txt';
|
||||
|
||||
// bsdtar use stderr for verbose output
|
||||
if ($tar_type === 'BSD')
|
||||
$command .= ' 2>&1';
|
||||
|
||||
print_debug_message_trace($command);
|
||||
//html_debug_print($command, true);
|
||||
|
||||
//Maybe this line run for seconds or minutes
|
||||
exec($command, $output, $status);
|
||||
|
||||
if (($status == 0) || ($status == 2)) {
|
||||
$conf_update_pandora['last_installed'] = $filename;
|
||||
update_pandora_update_conf();
|
||||
echo json_encode(array('correct' => 1));
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('correct' => 0));
|
||||
}
|
||||
|
||||
print_debug_message_trace("End Call update_pandora_install_package function.");
|
||||
}
|
||||
|
||||
function update_pandora_check_install_package() {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call update_pandora_check_install_package function.");
|
||||
|
||||
sleep(1);
|
||||
|
||||
$package = get_parameter('package', '');
|
||||
$filename = get_parameter('filename', '');
|
||||
|
||||
$files = @file('/tmp/' . $package . '.files.info.txt');
|
||||
if (empty($files))
|
||||
$files = array();
|
||||
$total = (int)@file_get_contents('/tmp/' . $package . '.info.txt');
|
||||
|
||||
$return = array('correct' => 1,
|
||||
'info' => "<div id='list_files_install'
|
||||
style='text-align: left; margin: 10px; padding: 5px; width: 90%%; height: 100px;
|
||||
overflow: scroll; border: 1px solid #666'>%s</div>",
|
||||
'src' => progress_bar(0, 300, 20, '0%', 1, false, "#0000ff"),
|
||||
'alt' => '0%',
|
||||
'percent' => 0);
|
||||
|
||||
$percent = 0;
|
||||
if ((count($files) > 0) && ($total > 0)) {
|
||||
$percent = format_numeric((count($files) / $total) * 100, 2);
|
||||
if ($percent > 100)
|
||||
$percent = 100;
|
||||
}
|
||||
|
||||
$files_txtbox = (string)implode("<br />", $files);
|
||||
$return['info'] = sprintf($return['info'], $files_txtbox);
|
||||
$img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#0000ff");
|
||||
$return['percent'] = $percent;
|
||||
preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['src'] = $attr[1];
|
||||
preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['alt'] = $attr[1];
|
||||
preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr);
|
||||
$return['title'] = $attr[1];
|
||||
|
||||
if ($percent == 100) {
|
||||
unlink('/tmp/' . $package . '.files.info.txt');
|
||||
unlink('/tmp/' . $package . '.info.txt');
|
||||
}
|
||||
|
||||
print_debug_message_trace("End Call update_pandora_check_install_package function.");
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
function checking_online_enterprise_package() {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager_client.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/lib/libupdate_manager.php");
|
||||
require_once ($config["homedir"] .
|
||||
"/extensions/update_manager/load_updatemanager.php");
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call checking_online_enterprise_package function.");
|
||||
|
||||
$return = array('correct' => 1, 'text' => '',
|
||||
'enable_buttons' => false, 'details_text' => '',
|
||||
'version_package_text' => '');
|
||||
|
||||
$settings = um_db_load_settings();
|
||||
$user_key = get_user_key($settings);
|
||||
|
||||
if (is_array($user_key)) {
|
||||
if (!$user_key['result']) {
|
||||
$return['text'] = ui_print_error_message(
|
||||
array('message' => $user_key['message'],
|
||||
'no_close' => true), '', true);
|
||||
|
||||
echo json_encode($return);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Disabled output error messages
|
||||
$package = @um_client_check_latest_update ($settings, $user_key);
|
||||
//Get error message
|
||||
$error_message = '';
|
||||
$error = error_get_last();
|
||||
if (!empty($error)) {
|
||||
$error_message = $error['message'];
|
||||
}
|
||||
|
||||
if ($package === true) {
|
||||
$return['text'] = ui_print_success_message(
|
||||
array('message' => __('Your system is up-to-date'),
|
||||
'no_close' => true), '', true);
|
||||
}
|
||||
elseif ($package === false) {
|
||||
$return['text'] = ui_print_error_message(
|
||||
array('message' => __('Server authorization rejected'),
|
||||
'no_close' => true), '', true);
|
||||
}
|
||||
elseif ($package === 0) {
|
||||
$return['text'] = ui_print_error_message(
|
||||
array('message' => __('Server connection failed'),
|
||||
'no_close' => true), '', true) . '<br />' .
|
||||
$error_message;
|
||||
}
|
||||
else {
|
||||
if ($package->id == 'ERROR_NON_NUMERIC_FOUND') {
|
||||
$return['text'] = ui_print_error_message(
|
||||
array('message' => __('Server unknow error'),
|
||||
'no_close' => true), '', true);
|
||||
}
|
||||
else {
|
||||
$return['enable_buttons'] = true;
|
||||
$return['version_package_text'] = '<strong>'.__('Id').'</strong>: ' .
|
||||
$package->id .
|
||||
' <strong>'.__('Timestamp').'</strong>: ' .
|
||||
$package->timestamp;
|
||||
|
||||
$return['text'] = ui_print_success_message(
|
||||
array('message' => __('There\'s a new update for Pandora FMS'),
|
||||
'no_close' => true), '', true) .
|
||||
$return['version_package_text'];
|
||||
|
||||
$return['details_text'] = html_entity_decode($package->description);
|
||||
}
|
||||
}
|
||||
|
||||
print_debug_message_trace("End Call checking_online_enterprise_package function.");
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
?>
|
|
@ -1,622 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// 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.
|
||||
|
||||
function update_pandora_check_installation() {
|
||||
global $config;
|
||||
|
||||
$conf_update_pandora = db_get_row('tconfig', 'token', 'update_pandora_conf_url');
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
if (empty($conf_update_pandora) || !is_dir($dir))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
function update_pandora_get_conf() {
|
||||
global $config;
|
||||
|
||||
$conf = array();
|
||||
$row = db_get_row('tconfig', 'token', 'update_pandora_conf_url');
|
||||
$conf['url'] = $row['value'];
|
||||
$row = db_get_row('tconfig', 'token', 'update_pandora_conf_last_installed');
|
||||
$conf['last_installed'] = $row['value'];
|
||||
$row = db_get_row('tconfig', 'token', 'update_pandora_conf_last_contact');
|
||||
$conf['last_contact'] = $row['value'];
|
||||
$row = db_get_row('tconfig', 'token', 'update_pandora_conf_download_mode');
|
||||
$conf['download_mode'] = $row['value'];
|
||||
|
||||
$conf['dir'] = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
return $conf;
|
||||
}
|
||||
|
||||
function update_pandora_installation() {
|
||||
global $config;
|
||||
|
||||
$return_var = array('return' => true, 'text' => null);
|
||||
|
||||
$row = db_get_row_filter('tconfig', array('token' => 'update_pandora_conf_url'));
|
||||
|
||||
if (empty($row)) {
|
||||
//The url of update manager.
|
||||
$conf_update_pandora = array('url' => '',
|
||||
'last_installed' => '',
|
||||
'last_contact' => '',
|
||||
'download_mode' => 'wget');
|
||||
|
||||
$values = array('token' => 'update_pandora_conf_url',
|
||||
'value' => $conf_update_pandora['url']);
|
||||
$return = db_process_sql_insert('tconfig', $values);
|
||||
$values = array('token' => 'update_pandora_conf_last_installed',
|
||||
'value' => $conf_update_pandora['last_installed']);
|
||||
$return = db_process_sql_insert('tconfig', $values);
|
||||
$values = array('token' => 'update_pandora_conf_last_contact',
|
||||
'value' => $conf_update_pandora['last_contact']);
|
||||
$return = db_process_sql_insert('tconfig', $values);
|
||||
$values = array('token' => 'update_pandora_conf_download_mode',
|
||||
'value' => $conf_update_pandora['download_mode']);
|
||||
$return = db_process_sql_insert('tconfig', $values);
|
||||
|
||||
if (!$return) {
|
||||
$return_var['return'] = false;
|
||||
$return_var['text'][] = __('Unsuccesful store conf data in DB.');
|
||||
}
|
||||
}
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
$return = mkdir($dir);
|
||||
|
||||
if (!$return) {
|
||||
$return_var['return'] = false;
|
||||
$return_var['text'][] = __('Unsuccesful create a dir to save package in Pandora Console');
|
||||
}
|
||||
}
|
||||
|
||||
return $return_var;
|
||||
}
|
||||
|
||||
function update_pandora_update_conf() {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
|
||||
$values = array('value' => $conf_update_pandora['last_installed']);
|
||||
$return = db_process_sql_update('tconfig', $values,
|
||||
array('token' => 'update_pandora_conf_last_installed'));
|
||||
$values = array('value' => $conf_update_pandora['last_contact']);
|
||||
$return = db_process_sql_update('tconfig', $values,
|
||||
array('token' => 'update_pandora_conf_last_contact'));
|
||||
$values = array('value' => $conf_update_pandora['download_mode']);
|
||||
$return = db_process_sql_update('tconfig', $values,
|
||||
array('token' => 'update_pandora_conf_download_mode'));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function update_pandora_get_list_downloaded_packages($mode = 'operation') {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
|
||||
$dir = dir($conf_update_pandora['dir']);
|
||||
if ($dir === false) {
|
||||
ui_print_error_message(sprintf(
|
||||
__('Error reading the dir of packages in "%s".'), $conf_update_pandora['dir']));
|
||||
return;
|
||||
}
|
||||
|
||||
$packages = array();
|
||||
while (false !== ($entry = $dir->read())) {
|
||||
if (is_file($conf_update_pandora['dir'] . $entry)
|
||||
&& is_readable($conf_update_pandora['dir'] . $entry)) {
|
||||
if (strstr($entry, '.tar.gz') !== false) {
|
||||
if ($mode == 'operation') {
|
||||
$packages[] = $entry;
|
||||
}
|
||||
else {
|
||||
$time_file = date($config["date_format"],
|
||||
filemtime($conf_update_pandora['dir'] . $entry));
|
||||
|
||||
if ($conf_update_pandora['last_installed'] == $entry) {
|
||||
$packages[] = array('name' => $entry,
|
||||
'current' => true,
|
||||
'time' => $time_file);
|
||||
}
|
||||
else {
|
||||
$packages[] = array('name' => $entry,
|
||||
'current' => false,
|
||||
'time' => $time_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($packages)) {
|
||||
if ($mode == 'operation') {
|
||||
$packages[] = array('name' =>
|
||||
__('There are not downloaded packages in your Pandora Console.'),
|
||||
'time' => '');
|
||||
}
|
||||
else {
|
||||
$packages[] = array('empty' => true, 'name' =>
|
||||
__('There are not downloaded packages in your Pandora Console.'),
|
||||
'time' => '');
|
||||
}
|
||||
}
|
||||
|
||||
return $packages;
|
||||
}
|
||||
|
||||
function update_pandora_print_javascript() {
|
||||
$extension_php_file = 'extensions/update_pandora';
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var last = 0;
|
||||
$(document).ready(function() {
|
||||
ajax_get_online_package_list();
|
||||
});
|
||||
|
||||
function ajax_get_online_package_list() {
|
||||
var parameters = {};
|
||||
parameters['page'] = "<?php echo $extension_php_file;?>";
|
||||
parameters['get_packages_online'] = 1;
|
||||
parameters['last'] = last;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
var row = $("<tr class='package'></tr>")
|
||||
.append().html('<td>' + data['package'] + '</td>');
|
||||
$("tbody", "#online_packages").append($(row));
|
||||
|
||||
last = data['last'];
|
||||
|
||||
if (data['end'] == 1) {
|
||||
$(".spinner_row", "#online_packages").remove();
|
||||
}
|
||||
else {
|
||||
ajax_get_online_package_list();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(".spinner_row", "#online_packages").remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
function update_pandora_print_javascript_admin() {
|
||||
$extension_php_file = 'extensions/update_manager/update_pandora';
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var disabled_download_package = false;
|
||||
var last = 0;
|
||||
|
||||
$(document).ready(function() {
|
||||
ajax_get_online_package_list_admin();
|
||||
|
||||
$("#submit-hide_download_dialog").click (function () {
|
||||
//Better than fill the downloaded packages
|
||||
location.reload();
|
||||
//$("#dialog_download" ).dialog('close');
|
||||
});
|
||||
});
|
||||
|
||||
function delete_package(package) {
|
||||
url = window.location + "&delete_package=1"
|
||||
+ '&package=' + package;
|
||||
|
||||
window.location.replace(url);
|
||||
}
|
||||
|
||||
function ajax_start_install_package(package) {
|
||||
$(".package_name").html(package);
|
||||
|
||||
$("#dialog_download").dialog({
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
height: 400,
|
||||
width: 650,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
$(".ui-dialog-titlebar-close").hide();
|
||||
$("#dialog_download").show();
|
||||
|
||||
$("#title_downloading_update_pandora").hide();
|
||||
$("#title_downloaded_update_pandora").show();
|
||||
$("#title_installing_update_pandora").show();
|
||||
|
||||
install_package(package, package);
|
||||
}
|
||||
|
||||
function ajax_start_download_package(package) {
|
||||
$(".package_name").html(package);
|
||||
|
||||
$("#dialog_download").dialog({
|
||||
resizable: false,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
height: 400,
|
||||
width: 650,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
$(".ui-dialog-titlebar-close").hide();
|
||||
$("#dialog_download").show();
|
||||
|
||||
var parameters = {};
|
||||
parameters['page'] = "<?php echo $extension_php_file;?>";
|
||||
parameters['download_package'] = 1;
|
||||
parameters['package'] = package;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
if (data['mode'] == 'wget') {
|
||||
disabled_download_package = true;
|
||||
$("#progress_bar_img img").show();
|
||||
install_package(package, data['filename']);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
check_download_package(package);
|
||||
}
|
||||
|
||||
function check_download_package(package) {
|
||||
var parameters = {};
|
||||
parameters['page'] = "<?php echo $extension_php_file;?>";
|
||||
parameters['check_download_package'] = 1;
|
||||
parameters['package'] = package;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (disabled_download_package)
|
||||
return;
|
||||
|
||||
if (data['correct'] == 1) {
|
||||
if (data['mode'] == 'wget') {
|
||||
$("#info_text").show();
|
||||
$("#info_text").html(data['info_download']);
|
||||
$("#progress_bar_img img").hide();
|
||||
}
|
||||
else {
|
||||
$("#info_text").show();
|
||||
$("#info_text").html(data['info_download']);
|
||||
|
||||
$("#progress_bar_img img").attr('src', data['progres_bar_src']);
|
||||
$("#progress_bar_img img").attr('alt', data['progres_bar_alt']);
|
||||
$("#progress_bar_img img").attr('title', data['progres_bar_title']);
|
||||
|
||||
if (data['percent'] < 100) {
|
||||
check_download_package(package);
|
||||
}
|
||||
else {
|
||||
install_package(package, data['filename']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$("#title_downloading_update_pandora").hide();
|
||||
$("#title_error_update_pandora").show();
|
||||
$("#progress_bar_img").hide();
|
||||
|
||||
$("#info_text").html('');
|
||||
|
||||
$("#button_close_download_disabled").hide();
|
||||
$("#button_close_download").show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function install_package(package, filename) {
|
||||
var parameters = {};
|
||||
parameters['page'] = "<?php echo $extension_php_file;?>";
|
||||
parameters['install_package'] = 1;
|
||||
parameters['package'] = package;
|
||||
parameters['filename'] = filename;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
}
|
||||
});
|
||||
|
||||
$("#title_downloading_update_pandora").hide();
|
||||
$("#title_downloaded_update_pandora").show();
|
||||
$("#title_installing_update_pandora").show();
|
||||
|
||||
check_install_package(package, filename);
|
||||
}
|
||||
|
||||
function check_install_package(package, filename) {
|
||||
var parameters = {};
|
||||
parameters['page'] = "<?php echo $extension_php_file;?>";
|
||||
parameters['check_install_package'] = 1;
|
||||
parameters['package'] = package;
|
||||
parameters['filename'] = filename;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
$("#info_text").show();
|
||||
$("#info_text").html(data['info']);
|
||||
$("#list_files_install").scrollTop(
|
||||
$("#list_files_install").attr("scrollHeight"));
|
||||
|
||||
$("#progress_bar_img img").attr('src', data['src']);
|
||||
$("#progress_bar_img img").attr('alt', data['alt']);
|
||||
$("#progress_bar_img img").attr('title', data['title']);
|
||||
|
||||
if (data['percent'] < 100) {
|
||||
check_install_package(package, filename);
|
||||
}
|
||||
else {
|
||||
$("#title_installing_update_pandora").hide();
|
||||
$("#title_installed_update_pandora").show();
|
||||
$("#button_close_download_disabled").hide();
|
||||
$("#button_close_download").show();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function ajax_get_online_package_list_admin() {
|
||||
var buttonUpdateTemplate = '<?php
|
||||
html_print_button(__('Update'), 'update', false,
|
||||
'ajax_start_download_package(\\\'pandoraFMS\\\');', 'class="sub upd"');
|
||||
?>';
|
||||
|
||||
var parameters = {};
|
||||
parameters['page'] = "<?php echo $extension_php_file;?>";
|
||||
parameters['get_packages_online'] = 1;
|
||||
parameters['last'] = last;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
buttonUpdate = buttonUpdateTemplate.replace('pandoraFMS', data['package']);
|
||||
|
||||
$("tbody", "#online_packages").append(
|
||||
'<tr class="package_' + data['package'] + '">' +
|
||||
'<td style=" text-align:left; width:50%;" valign="top" class="name_package">' +
|
||||
'<?php echo '<b>' . __('There is a new version:') . '</b><br><br> '; ?>' +
|
||||
data['package'] +
|
||||
'</td>' +
|
||||
'<td style=" text-align:left; width:30%;" valign="bottom" class="timestamp_package">' +
|
||||
data['timestamp'] +
|
||||
'</td>' +
|
||||
'<td style=" text-align:center; width:50px;" valign="bottom">' +
|
||||
buttonUpdate +
|
||||
'</td>' +
|
||||
'</tr>');
|
||||
|
||||
last = data['last'];
|
||||
|
||||
if (data['end'] == 1) {
|
||||
$(".spinner_row", "#online_packages").remove();
|
||||
}
|
||||
else {
|
||||
ajax_get_online_package_list_admin();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(".spinner_row", "#online_packages").remove();
|
||||
row_html = '<tr class="package_' + data['package'] + '">' +
|
||||
'<td style=" text-align:left; width:80%;" class="name_package">' +
|
||||
data['package'] +
|
||||
'</td>' +
|
||||
'<td style=" text-align:center; width:50px;"></td>' +
|
||||
'</tr>';
|
||||
$("tbody", "#online_packages").append(row_html); return;
|
||||
$("tbody", "#online_packages").append(
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
function install_offline_enterprise_package(&$settings, $user_key) {
|
||||
global $config;
|
||||
|
||||
if (isset($_FILES["fileloaded"]["error"])
|
||||
&& !$_FILES["fileloaded"]["error"]) {
|
||||
$extension = substr($_FILES["fileloaded"]["name"],
|
||||
strlen($_FILES["fileloaded"]["name"])-4, 4);
|
||||
|
||||
switch ($extension) {
|
||||
case '.oum':
|
||||
case '.zip':
|
||||
$tempDir = sys_get_temp_dir();
|
||||
if ($extension == '.oum') {
|
||||
$tempDir .= "/tmp_oum/";
|
||||
}
|
||||
else {
|
||||
$tempDir .= "/tmp_zip";
|
||||
}
|
||||
delete_dir($tempDir);
|
||||
|
||||
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($_FILES["fileloaded"]['tmp_name']) === TRUE) {
|
||||
$zip->extractTo($tempDir);
|
||||
$zip->close();
|
||||
}
|
||||
else {
|
||||
$error = ui_print_error_message(__('Update cannot be opened'));
|
||||
}
|
||||
|
||||
|
||||
if ($extension == '.oum') {
|
||||
////////////////////////////////////////////////////
|
||||
$package = um_package_info_from_paths ($tempDir);
|
||||
if ($package === false) {
|
||||
ui_print_error_message(
|
||||
__('Error, the file package is empty or corrupted.'));
|
||||
}
|
||||
else {
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
if ($settings->current_update >= $package->id) {
|
||||
ui_print_error_message(
|
||||
__('Your system version is higher or equal than the loaded package'));
|
||||
}
|
||||
else {
|
||||
$binary_paths = um_client_get_files ($tempDir . "binary/");
|
||||
|
||||
foreach ($binary_paths as $key => $paths) {
|
||||
foreach($paths as $index => $path) {
|
||||
$tempDir_scaped = preg_replace('/\//',
|
||||
'\/', $tempDir . "binary");
|
||||
$binary_paths[$key][$index] = preg_replace(
|
||||
'/^' . $tempDir_scaped . '/', ' ', $path);
|
||||
}
|
||||
}
|
||||
|
||||
$code_paths = um_client_get_files ($tempDir . "code/");
|
||||
|
||||
foreach ($code_paths as $key => $paths) {
|
||||
foreach($paths as $index => $path) {
|
||||
$tempDir_scaped = preg_replace('/\//', '\/', $tempDir . "code");
|
||||
$code_paths[$key][$index] = preg_replace(
|
||||
'/^' . $tempDir_scaped . '/', ' ', $path);
|
||||
}
|
||||
}
|
||||
|
||||
$sql_paths = um_client_get_files ($tempDir);
|
||||
foreach ($sql_paths as $key => $paths) {
|
||||
foreach ($paths as $index => $path) {
|
||||
if ($path != $tempDir || ($key == 'info_package' && $path == $tempDir)) {
|
||||
unset($sql_paths[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$updates_binary = array();
|
||||
$updates_code = array();
|
||||
$updates_sql = array();
|
||||
|
||||
if (!empty($binary_paths)) {
|
||||
$updates_binary = um_client_update_from_paths(
|
||||
$binary_paths, $tempDir, $package->id, 'binary');
|
||||
}
|
||||
if (!empty($code_paths)) {
|
||||
$updates_code = um_client_update_from_paths(
|
||||
$code_paths, $tempDir, $package->id, 'code');
|
||||
}
|
||||
if (!empty($sql_paths)) {
|
||||
$updates_sql = um_client_update_from_paths(
|
||||
$sql_paths, $tempDir, $package->id, 'sql');
|
||||
}
|
||||
|
||||
um_delete_directory($tempDir);
|
||||
|
||||
$updates= array_merge((array) $updates_binary, (array) $updates_code, (array) $updates_sql);
|
||||
|
||||
$package->updates = $updates;
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
if (um_client_upgrade_to_package($package, $settings, true)) {
|
||||
ui_print_success_message(
|
||||
__('Successfully upgraded'));
|
||||
|
||||
//Refresh the settings object.
|
||||
$settings = um_db_load_settings ();
|
||||
}
|
||||
else {
|
||||
ui_print_error_message(__('Cannot be upgraded'));
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
}
|
||||
else {
|
||||
$correct = copy_dir($tempDir, $config['homedir']);
|
||||
|
||||
if ($correct) {
|
||||
ui_print_success_message(
|
||||
__('Successfully upgraded'));
|
||||
}
|
||||
else {
|
||||
ui_print_error_message(__('Cannot be upgraded'));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ui_print_error_message(__('Incorrect file extension'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//Check if the file is biggest than the limit in PHP
|
||||
if ($_FILES["fileloaded"]["error"] === 1) {
|
||||
$upload_max_filesize = ini_get('upload_max_filesize');
|
||||
|
||||
ui_print_error_message(
|
||||
sprintf(
|
||||
__('File is more biggest than the PHP limit (%s). Please change it in PHP configuration.'),
|
||||
$upload_max_filesize));
|
||||
}
|
||||
else {
|
||||
ui_print_error_message(__('File cannot be uploaded'));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,827 +0,0 @@
|
|||
<?php
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
if (! defined ('DB_PREFIX'))
|
||||
define ('DB_PREFIX', '');
|
||||
|
||||
require_once ('libupdate_manager_utils.php');
|
||||
require_once ('libupdate_manager_updates.php');
|
||||
require_once ('libupdate_manager_components.php');
|
||||
require_once ('libupdate_manager_client.php');
|
||||
|
||||
function um_db_load_settings () {
|
||||
db_clean_cache();
|
||||
$result = db_get_all_rows_in_table(DB_PREFIX . 'tupdate_settings');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error reading settings</strong><br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$settings = new stdClass ();
|
||||
$settings->proxy = '';
|
||||
$settings->proxy_port = '';
|
||||
$settings->proxy_user = '';
|
||||
$settings->proxy_pass = '';
|
||||
foreach($result as $field) {
|
||||
$settings->$field['key'] = $field['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
function um_db_update_setting ($key, $value = '') {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_get_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '`key`', $key);
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_get_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '"key"', $key);
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_get_value('COUNT(*)', DB_PREFIX.'tupdate_settings', 'key', $key);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>' . __('Error reading settings') . '</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($result > 0) {
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('`key`' => $key));
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('"key"' => $key));
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('key' => $key));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>' . __('Error updating settings') . '</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_settings', array('`key`' => $key, '`value`' => $value));
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_settings', array('"key"' => $key, '"value"' => $value));
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_settings', array('key' => $key, 'value' => $value));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>' . __('Error creating settings') . '</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_latest_package_by_status ($id_package = '0', $status = 'public') {
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_package
|
||||
WHERE status = "'.$status.'" AND id > ' . $id_package . '
|
||||
ORDER BY id DESC LIMIT 1');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error reading latest package with status ' . $status . '</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_package WHERE status = "'.$status.'" AND id > ' . $id_package . ' ORDER BY id DESC LIMIT 1');
|
||||
|
||||
$package = um_std_from_result($result);
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_db_get_next_package ($id_package = '0', $development = false) {
|
||||
$package = um_db_get_latest_package_by_status ($id_package, $status = 'public');
|
||||
|
||||
if (! $package && $development) {
|
||||
$package = um_db_get_latest_package_by_status ($id_package, $status = 'development');
|
||||
}
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_db_create_package ($description = '') {
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_package', array('description' => $description));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error creating package</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_update_package ($id_package, $description = '', $status = 'disabled') {
|
||||
$values = array ('description' => $description, 'status' => $status);
|
||||
$where = array ('id' => $id_package);
|
||||
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_package', $values, $where);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error updating package</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_delete_package ($id_package) {
|
||||
$package = um_db_get_package ($id_package);
|
||||
|
||||
if ($package->status != 'development') {
|
||||
echo '<strong>Error</strong>: '.'Only packages in development state can be deleted';
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = db_process_sql_delete(DB_PREFIX.'tupdate_package', array('id' => $id_package));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting package</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_package ($id_package) {
|
||||
$result = db_process_sql ('SELECT * FROM '.DB_PREFIX.'tupdate_package WHERE id = ' . $id_package . ' LIMIT 1');
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting package info</strong><br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$package = um_std_from_result($result);
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_std_from_result($array, $i = 0) {
|
||||
if(!isset($array[$i])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$object = new stdClass ();
|
||||
foreach($array[$i] as $key => $value) {
|
||||
if(!is_int($key)) {
|
||||
$object->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
function um_db_get_all_packages () {
|
||||
$result = db_process_sql ('SELECT * FROM '.DB_PREFIX.'tupdate_package');
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting all packages</strong><br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$packages = array();
|
||||
while(true) {
|
||||
$package = um_std_from_result($result, $cont);
|
||||
if($package === false) {
|
||||
break;
|
||||
}
|
||||
$packages[$package->id] = $package;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $packages;
|
||||
}
|
||||
|
||||
function um_db_get_package_updates ($id_package) {
|
||||
$result = db_process_sql ('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE id_update_package = ' . $id_package);
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting all packages '.$id_package.'</strong><br />'.'SELECT * FROM '.DB_PREFIX.'tupdate WHERE id_update_package = ' . $id_package;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result = db_process_sql ('SELECT * FROM '.DB_PREFIX.'tupdate WHERE id_update_package = ' . $id_package);
|
||||
|
||||
$cont = 0;
|
||||
$updates = array();
|
||||
while(true) {
|
||||
$update = um_std_from_result($result, $cont);
|
||||
if($update === false) {
|
||||
break;
|
||||
}
|
||||
$component_db = um_db_get_component_db ($update->id_component_db);
|
||||
$update->db_table = $component_db->table_name;
|
||||
$update->db_field = $component_db->field_name;
|
||||
$update->order = $component_db->order;
|
||||
$updates[$update->id] = $update;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
||||
function um_db_create_package_log ($id_package, $client_key, $user_package, $result = 'query', $user_subscription = '', $description = '') {
|
||||
global $db;
|
||||
|
||||
$values = array ('id_update_package' => $id_package,
|
||||
'client_key' => $client_key,
|
||||
'ip_address' => $_SERVER['REMOTE_ADDR'],
|
||||
'user_package' => $user_package,
|
||||
'user_subscription' => $user_subscription,
|
||||
'result' => $result,
|
||||
'description' => $description);
|
||||
|
||||
$result = db_process_sql_insert (DB_PREFIX.'tupdate_package_log', $values);
|
||||
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_total_package_logs ($ip = '') {
|
||||
$result = db_process_sql('SELECT COUNT(*) total
|
||||
FROM '.DB_PREFIX.'tupdate_package_log
|
||||
WHERE ip_address LIKE "%'.$ip.'%"');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error reading package log</strong> <br />';
|
||||
return 0;
|
||||
}
|
||||
|
||||
$logs = um_std_from_result($result);
|
||||
|
||||
return $logs->total;
|
||||
}
|
||||
|
||||
function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit = 30, $offset = 0) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_package_log
|
||||
WHERE ip_address LIKE "%'.$ip.'%"
|
||||
ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_package_log
|
||||
WHERE ip_address LIKE \'%'.$ip.'%\'
|
||||
ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
|
||||
break;
|
||||
case "oracle":
|
||||
$set = array ();
|
||||
$set['ip_address'] = '%' . $ip . '%';
|
||||
$set['order'] = $order_by . ' DESC';
|
||||
$set['limit'] = $limit;
|
||||
$set['offset'] = $offset;
|
||||
$result = db_get_num_rows(oracle_recode_query ('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE', $set, 'AND', true));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error reading all package logs</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_package_log
|
||||
WHERE ip_address LIKE \'%'.$ip.'%\' ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
|
||||
break;
|
||||
case "oracle":
|
||||
$result = oracle_recode_query ('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE', $set, 'AND', false);
|
||||
// Delete rnum row generated by oracle_recode_query() function
|
||||
for ($i=0; $i < count($result); $i++) {
|
||||
unset($result[$i]['rnum']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$logs = array();
|
||||
while (true) {
|
||||
$log = um_std_from_result($result, $cont);
|
||||
if($log === false) {
|
||||
break;
|
||||
}
|
||||
$logs[$log->id] = $log;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
function um_db_delete_package_logs ($ip) {
|
||||
$result = db_process_sql_delete(DB_PREFIX.'tupdate_package_log',
|
||||
array('ip_address' => $ip));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting logs</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_create_component ($type, $name, $path = '', $binary = false, $relative_path = '') {
|
||||
$values = array('type' => $type,
|
||||
'name' => $name,
|
||||
'path' => $path,
|
||||
'`binary`' => $binary,
|
||||
'relative_path' => $relative_path);
|
||||
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_component', $values);
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error creating component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_update_component ($name, $path = '', $binary = false, $relative_path = '') {
|
||||
$values = array ('path' => $path, 'binary' => $binary, 'relative_path' => $relative_path);
|
||||
$where = array ('name' => $name);
|
||||
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_component', $values, $where);
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error updating component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_delete_component ($name) {
|
||||
$result = db_process_sql_delete(DB_PREFIX.'tupdate_component', array('name' => $name));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_component ($name) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component
|
||||
WHERE name = "'.$name.'" LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component
|
||||
WHERE name = \''.$name.'\' LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component
|
||||
WHERE name = \''.$name.'\' AND rownum < 2');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting component</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component
|
||||
WHERE name = "'.$name.'" LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component
|
||||
WHERE name = \''.$name.'\' LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component
|
||||
WHERE name = \''.$name.'\' AND rownum < 2');
|
||||
break;
|
||||
}
|
||||
|
||||
$component = um_std_from_result($result);
|
||||
|
||||
if ($component->relative_path != '') {
|
||||
$last = $component->relative_path[strlen ($component->relative_path) - 1];
|
||||
if ($last != '/')
|
||||
$component->relative_path .= '/';
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
function um_db_get_all_components ($type = '') {
|
||||
if ($type != '') {
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component WHERE type = '.$type);
|
||||
}
|
||||
else {
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component');
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting component</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$components = array();
|
||||
while(true) {
|
||||
$component = um_std_from_result($result, $cont);
|
||||
if($component === false) {
|
||||
break;
|
||||
}
|
||||
$components[$component->name] = $component;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
function um_db_create_component_db ($table_name, $field_name, $order, $component_name) {
|
||||
$values = array('table_name' => $table_name,
|
||||
'field_name' => $field_name,
|
||||
'`order`' => $order,
|
||||
'component' => $component_name);
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_component_db', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating database component</strong> <br />';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_update_component_db ($id, $table_name = '', $field_name = '', $order = '') {
|
||||
$values = array ('table_name' => $table_name,
|
||||
'field_name' => $field_name,
|
||||
'`order`' => $order);
|
||||
$where = array ('id' => $id);
|
||||
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_component_db', $values, $where);
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error updating database component</strong><br />';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_delete_directory($dirname) {
|
||||
if (is_dir($dirname))
|
||||
$dir_handle = opendir($dirname);
|
||||
if (!$dir_handle)
|
||||
return false;
|
||||
|
||||
while ($file = readdir($dir_handle)) {
|
||||
if ($file != "." && $file != "..") {
|
||||
if (!is_dir($dirname."/".$file))
|
||||
unlink($dirname."/".$file);
|
||||
else
|
||||
um_delete_directory($dirname . '/' . $file);
|
||||
}
|
||||
}
|
||||
closedir($dir_handle);
|
||||
rmdir($dirname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_delete_component_db ($id) {
|
||||
$result = db_process_sql_delete(DB_PREFIX.'tupdate_component_db',
|
||||
array('id' => $id));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting database component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_component_db ($id_component_db) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE id = "'.$id_component_db.'" LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE id = \''.$id_component_db.'\' LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE id = \''.$id_component_db.'\' AND rownum < 2');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting database component</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE id = "'.$id_component_db.'" LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE id = \''.$id_component_db.'\' LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE id = \''.$id_component_db.'\' AND rownum < 2');
|
||||
break;
|
||||
}
|
||||
|
||||
$component = um_std_from_result($result);
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
function um_db_get_database_components ($component_name) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
|
||||
break;
|
||||
case "postgresql":
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT COUNT(*)
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting database components </strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
|
||||
break;
|
||||
case "postgresql":
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate_component_db
|
||||
WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
|
||||
break;
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$components = array();
|
||||
while (true) {
|
||||
$component = um_std_from_result($result, $cont);
|
||||
if($component === false) {
|
||||
break;
|
||||
}
|
||||
$components[$component->id] = $component;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
function um_db_create_auth ($client_key, $subscription_limit, $description = '', $developer = false) {
|
||||
global $db;
|
||||
|
||||
if (! is_numeric ($subscription_limit)) {
|
||||
echo '<strong>Error</strong>: Subscription must be numeric<br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$values = array ('client_key' => $client_key,
|
||||
'subscription_limit' => $subscription_limit,
|
||||
'description' => $description,
|
||||
'developer' => $developer);
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_auth', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating authorization</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_update_auth ($id_auth, $client_key, $subscription_limit, $description = '', $developer = false) {
|
||||
if (! is_numeric ($subscription_limit)) {
|
||||
echo '<strong>Error</strong>: Subscription must be numeric<br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$values = array ('client_key' => $client_key,
|
||||
'subscription_limit' => $subscription_limit,
|
||||
'description' => $description,
|
||||
'developer' => $developer);
|
||||
$where = array ('id' => $id_auth);
|
||||
|
||||
$result = db_process_sql_update(DB_PREFIX.'tupdate_auth', $values, $where);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error updating authorization</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_delete_auth ($id_auth) {
|
||||
$result = db_process_sql_delete(DB_PREFIX.'tupdate_auth',
|
||||
array('id' => $id_auth));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting authorization</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_auth ($id_auth) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = "'.$id_auth.'" LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = \''.$id_auth.'\' LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = \''.$id_auth.'\' AND rownum < 2');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting authorization</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$auth = um_std_from_result($result);
|
||||
|
||||
return $auth;
|
||||
}
|
||||
|
||||
function um_db_get_all_auths () {
|
||||
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_auth');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting authorizations</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth');
|
||||
|
||||
$cont = 0;
|
||||
$auths = array();
|
||||
while (true) {
|
||||
$auth = um_std_from_result($result, $cont);
|
||||
if ($auth === false) {
|
||||
break;
|
||||
}
|
||||
$auths[$auth->id] = $auth;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $auths;
|
||||
}
|
||||
|
||||
function um_db_check_auth ($client_key, $subscription_limit) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = "'.$client_key.'" LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = \''.$client_key.'\' LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = \''.$client_key.'\' AND rownum < 2');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error checking authorization</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$auth = um_std_from_result($result);
|
||||
|
||||
if (!$auth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($auth->developer == 1 || $auth->subscription_limit >= $subscription_limit) {
|
||||
return $auth->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function um_db_is_auth_developer ($id_auth) {
|
||||
$developer = db_get_value('developer', DB_PREFIX.'tupdate_auth', '`id`', $id_auth);
|
||||
|
||||
if ($developer === false) {
|
||||
echo '<strong>Error reading authorization developers bit</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $developer;
|
||||
}
|
||||
|
||||
function um_db_connect ($backend = 'mysql', $host = '', $user = '', $password = '', $db_name = '', $port = null) {
|
||||
return db_connect ($host, $db_name, $user, $password, null, $port);
|
||||
}
|
||||
|
||||
function um_component_db_connect () {
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
return db_connect ($settings->dbhost, $settings->dbname, $settings->dbuser, $settings->dbpass, null, $settings->dbport);
|
||||
}
|
||||
|
||||
function um_get_package_status () {
|
||||
$status = array ();
|
||||
|
||||
$status['development'] = __('Development');
|
||||
$status['testing'] = __('Testing');
|
||||
$status['public'] = __('Public');
|
||||
$status['disabled'] = __('Disabled');
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function um_get_component_types () {
|
||||
$types = array ();
|
||||
|
||||
$types['database'] = __('Database');
|
||||
$types['directory'] = __('Code / binary directory');
|
||||
|
||||
return $types;
|
||||
}
|
||||
?>
|
|
@ -1,690 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
$prev_level = error_reporting (0);
|
||||
error_reporting ($prev_level);
|
||||
|
||||
include("xmlrpc/xmlrpc.inc");
|
||||
include("xmlrpc/xmlrpcs.inc");
|
||||
include("xmlrpc/xmlrpc_wrappers.inc");
|
||||
|
||||
unset ($prev_level);
|
||||
|
||||
define ('XMLRPC_DEBUG', 0);
|
||||
define ('XMLRPC_TIMEOUT', 15);
|
||||
global $config;
|
||||
define('HOME_DIR', $config['homedir']);
|
||||
|
||||
function um_xml_rpc_client_call ($server_host, $server_path, $server_port, $proxy, $proxy_port, $proxy_user, $proxy_pass, $function, $parameters) {
|
||||
$msg = new xmlrpcmsg ($function, $parameters);
|
||||
|
||||
$client = new xmlrpc_client($server_path, $server_host, $server_port);
|
||||
|
||||
$client->setProxy($proxy, $proxy_port, $proxy_user, $proxy_pass);
|
||||
$client->setFollowLocation(true);
|
||||
|
||||
if (defined ('XMLRPC_DEBUG'))
|
||||
$client->setDebug (XMLRPC_DEBUG);
|
||||
|
||||
$result = $client->send ($msg, XMLRPC_TIMEOUT, '');
|
||||
|
||||
if (! $result) {
|
||||
trigger_error ('<strong>Open Update Manager</strong> Server comunication error. '.$client->errstr);
|
||||
return 0;
|
||||
}
|
||||
switch($result->faultCode ()) {
|
||||
case 0:
|
||||
break;
|
||||
case 5:
|
||||
trigger_error ('<strong>Open Update Manager</strong> Server comunication error. '.$result->faultString ());
|
||||
return 0;
|
||||
default:
|
||||
trigger_error ('<strong>Open Update Manager</strong> XML-RPC error. '.$result->faultString ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function um_xml_rpc_unpack_update ($update_xml_rpc) {
|
||||
if ($update_xml_rpc->kindOf () != 'struct') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = new stdClass ();
|
||||
$value = $update_xml_rpc->structeach ();
|
||||
while ($value) {
|
||||
$update->$value['key'] = $value[1]->scalarval ();
|
||||
$value = $update_xml_rpc->structeach ();
|
||||
}
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
function um_xml_rpc_unpack_package ($package_xml_rpc) {
|
||||
if ($package_xml_rpc->kindOf () != 'struct') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$package = new stdClass ();
|
||||
$value = $package_xml_rpc->structeach ();
|
||||
while ($value) {
|
||||
$package->$value['key'] = $value[1]->scalarval ();
|
||||
$value = $package_xml_rpc->structeach ();
|
||||
}
|
||||
|
||||
if (! isset ($package->updates))
|
||||
return $package;
|
||||
|
||||
$package->updates = array ();
|
||||
$updates = $package_xml_rpc->structmem ('updates');
|
||||
$size = $updates->arraysize ();
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$update = um_xml_rpc_unpack_update ($updates->arraymem ($i));
|
||||
$update->id_update_package = $package->id;
|
||||
array_push ($package->updates, $update);
|
||||
}
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_client_check_latest_update ($settings, $user_key) {
|
||||
$params = array (new xmlrpcval ($settings->customer_key, 'string'),
|
||||
new xmlrpcval ($user_key, 'string'),
|
||||
new xmlrpcval ($settings->current_update, 'int'));
|
||||
|
||||
$result = um_xml_rpc_client_call ($settings->update_server_host,
|
||||
$settings->update_server_path,
|
||||
$settings->update_server_port,
|
||||
$settings->proxy,
|
||||
$settings->proxy_port,
|
||||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_latest_package', $params);
|
||||
|
||||
if ($result == false) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$value = $result->value ();
|
||||
|
||||
if ($value->kindOf () == 'scalar') {
|
||||
/* No new updates */
|
||||
return $value->scalarval ();
|
||||
}
|
||||
$package = um_xml_rpc_unpack_package ($value);
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_client_get_package ($settings, $user_key) {
|
||||
$params = array (new xmlrpcval ($settings->customer_key, 'string'),
|
||||
new xmlrpcval ($user_key, 'string'),
|
||||
new xmlrpcval ($settings->current_update, 'int'));
|
||||
|
||||
$result = um_xml_rpc_client_call ($settings->update_server_host,
|
||||
$settings->update_server_path,
|
||||
$settings->update_server_port,
|
||||
$settings->proxy,
|
||||
$settings->proxy_port,
|
||||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_next_package', $params);
|
||||
|
||||
if (empty($result))
|
||||
return false;
|
||||
|
||||
$value = $result->value ();
|
||||
if ($value->kindOf () == 'scalar') {
|
||||
/* No new updates */
|
||||
return (int)$value->scalarval ();
|
||||
}
|
||||
|
||||
$package = um_xml_rpc_unpack_package ($value);
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_client_db_save_package ($package, $settings) {
|
||||
$fields = array ('id' => $package->id,
|
||||
'description' => $package->description,
|
||||
'timestamp' => $package->timestamp);
|
||||
|
||||
um_client_db_connect($settings);
|
||||
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_package', $fields);
|
||||
|
||||
if($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_db_save_update ($update) {
|
||||
$fields = get_object_vars ($update);
|
||||
|
||||
$fields['data'] = base64_encode($fields['data']);
|
||||
|
||||
if(isset($fields['data_rollback'])) {
|
||||
$fields['data_rollback'] = base64_encode($fields['data_rollback']);
|
||||
}
|
||||
|
||||
if($fields['type'] == 'db_data') {
|
||||
$fields['db_table_name'] = $fields['db_table'];
|
||||
unset($fields['db_table']);
|
||||
$fields['db_field_name'] = $fields['db_field'];
|
||||
unset($fields['db_field']);
|
||||
unset($fields['order']);
|
||||
}
|
||||
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate', $fields);
|
||||
|
||||
if($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_apply_update_file (&$update, $destiny_filename, $force = true) {
|
||||
@mkdir (dirname ($destiny_filename), 0755, true);
|
||||
|
||||
if (file_exists ($destiny_filename)) {
|
||||
if (! is_writable ($destiny_filename)) {
|
||||
return false;
|
||||
}
|
||||
$checksum = md5_file ($destiny_filename);
|
||||
if (! $force && $update->previous_checksum != '') {
|
||||
if ($update->previous_checksum != $checksum)
|
||||
/* Local changes in the file. Don't update */
|
||||
return false;
|
||||
}
|
||||
$content = file_get_contents ($destiny_filename);
|
||||
$update->data_rollback = um_data_encode ($content);
|
||||
$update->previous_checksum = $checksum;
|
||||
}
|
||||
$result = file_put_contents ($destiny_filename, um_data_decode ($update->data));
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function um_client_create_update_file ($data, $md5path_name) {
|
||||
@mkdir (dirname ($md5path_name), 0755, true);
|
||||
$result = file_put_contents ($md5path_name, um_data_decode ($data));
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_apply_update_database (&$update) {
|
||||
if ($update->type == 'db_data') {
|
||||
$exists = db_get_value('COUNT(*)', $update->db_table, $update->db_field, $update->db_field_value);
|
||||
|
||||
/* If it exists, it failed. */
|
||||
if ($exists != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$query_array = explode(';',um_data_decode($update->data));
|
||||
$result = db_process_sql($query_array[0]);
|
||||
|
||||
if ($result === false) {
|
||||
//echo $result->getMessage ();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_apply_update (&$update, $settings, $force = true) {
|
||||
if ($update->type == 'code') {
|
||||
// We use the Pandora Home dir of config to code files
|
||||
$filename = HOME_DIR.'/'.$update->filename;
|
||||
$success = um_client_apply_update_file ($update, $filename, $force);
|
||||
}
|
||||
else if ($update->type == 'binary') {
|
||||
$filename = $settings->updating_binary_path.'/'.$update->filename;
|
||||
$success = um_client_apply_update_file ($update, $filename);
|
||||
}
|
||||
else if ($update->type == 'db_data' || $update->type == 'db_schema') {
|
||||
//mysql_select_db ($settings->dbname);
|
||||
//mysql_connect ($settings->dbhost, $settings->dbuser, $settings->dbpass);
|
||||
um_component_db_connect ();
|
||||
$success = um_client_apply_update_database ($update);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $success)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_rollback_update_file (&$update, $destiny_filename) {
|
||||
/* If there's no data rollback, we suppose it's a new file, so it should
|
||||
not be a problem. In any case, it's better than deleting the file. */
|
||||
if (! isset ($update->data_rollback))
|
||||
return true;
|
||||
|
||||
$result = file_put_contents ($destiny_filename,
|
||||
um_data_decode ($update->data_rollback));
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_rollback_update (&$update, $settings) {
|
||||
if ($update->type == 'code') {
|
||||
$filename = $settings->updating_code_path.'/'.$update->filename;
|
||||
$success = um_client_rollback_update_file ($update, $filename);
|
||||
}
|
||||
else if ($update->type == 'binary') {
|
||||
$filename = $settings->updating_binary_path.'/'.$update->filename;
|
||||
$success = um_client_rollback_update_file ($update, $filename);
|
||||
}
|
||||
else if ($update->type == 'db_data' || $update->type == 'db_schema') {
|
||||
db_process_sql_rollback();
|
||||
$success = true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
function um_client_crypt ($data) {
|
||||
// Customizable crypt code
|
||||
return $data;
|
||||
}
|
||||
|
||||
function um_client_decrypt ($data) {
|
||||
// Customizable crypt code
|
||||
return $data;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Get a directory path and return an array //
|
||||
// with the path of all files into directory //
|
||||
///////////////////////////////////////////////
|
||||
function um_client_get_files ($dir_path) {
|
||||
if (!file_exists($dir_path)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$dir = opendir($dir_path);
|
||||
$files = array();
|
||||
$cont = 0;
|
||||
while ($element = readdir($dir))
|
||||
{
|
||||
if ($element == '.' || $element == '..') {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($dir_path.$element)) {
|
||||
$file_temp = um_client_get_files ("$dir_path$element/");
|
||||
$files = array_merge((array)$files,(array)$file_temp);
|
||||
}
|
||||
else {
|
||||
$files[$element][] = $dir_path;
|
||||
}
|
||||
|
||||
$cont++;
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
function um_client_print_update ($update, $settings) {
|
||||
if (isset($update->id)) {
|
||||
echo 'Update #'.$update->id;
|
||||
}
|
||||
|
||||
echo '<ul>';
|
||||
echo '<li><em>Type</em>: '.$update->type.'</li>';
|
||||
if ($update->type == 'code' || $update->type == 'binary') {
|
||||
if ($update->type == 'code') {
|
||||
$realpath = HOME_DIR.'/'.$update->filename;
|
||||
}
|
||||
else {
|
||||
$realpath = $settings->updating_binary_path.'/'.$update->filename;
|
||||
}
|
||||
echo '<li><em>Filename</em>: '.$update->filename.'</li>';
|
||||
echo '<li><em>Realpath</em>: '.$realpath.'</li>';
|
||||
echo '<li><em>Checksum</em>: '.$update->checksum.'</li>';
|
||||
echo '<li><em>Writable</em>: '.(is_writable ($realpath) ? 'yes' : '<strong>no</strong>').'</li>';
|
||||
}
|
||||
else {
|
||||
if(isset($update->db_table))
|
||||
echo '<li><em>Table</em>: '.$update->db_table.'</li>';
|
||||
if(isset($update->db_field))
|
||||
echo '<li><em>Field</em>: '.$update->db_field.'</li>';
|
||||
if(isset($update->db_field_value))
|
||||
echo '<li><em>Value</em>: '.$update->db_field_value.'</li>';
|
||||
echo '<li><em>Data</em>: '.um_data_decode($update->data).'</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
function um_package_info_from_paths ($tmpDir) {
|
||||
$f = @fopen($tmpDir.'info_package', "r");
|
||||
|
||||
if ($f !== false) {
|
||||
$f_content = fread($f, filesize($tmpDir.'info_package'));
|
||||
fclose($f);
|
||||
$f_array = array();
|
||||
|
||||
unset($f_content->status);
|
||||
|
||||
return json_decode($f_content);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type) {
|
||||
global $config;
|
||||
|
||||
$update = array();
|
||||
$i = 0;
|
||||
|
||||
// The number of the prefixs names is to keep alphabetic order to appliyng priority
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$sql_schema_file = '01_package_'.$num_package.'_schema.sql';
|
||||
$sql_data_file = '02_package_'.$num_package.'_data.sql';
|
||||
break;
|
||||
case "postgresql":
|
||||
$sql_schema_file = '01_package_'.$num_package.'_schema.postgreSQL.sql';
|
||||
$sql_data_file = '02_package_'.$num_package.'_data.postgreSQL.sql';
|
||||
break;
|
||||
case "oracle":
|
||||
$sql_schema_file = '01_package_'.$num_package.'_schema.oracle.sql';
|
||||
$sql_data_file = '02_package_'.$num_package.'_data.oracle.sql';
|
||||
break;
|
||||
}
|
||||
|
||||
foreach($file_paths as $file_name => $paths) {
|
||||
if($file_name == $sql_data_file && $type == 'sql') {
|
||||
$filesize = filesize($tmpDir.$sql_data_file);
|
||||
|
||||
if($filesize == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$f = fopen($tmpDir.$sql_data_file, "r");
|
||||
$f_content = fread($f, $filesize);
|
||||
fclose($f);
|
||||
$f_array = array();
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$f_array = explode(chr(10).chr(10),$f_content);
|
||||
foreach($f_array as $f_line) {
|
||||
if($f_line != '') {
|
||||
$segments = explode(";", $f_line);
|
||||
$update[$i]->data = um_data_encode($segments[0]);
|
||||
$update[$i]->db_table = $segments[1];
|
||||
$update[$i]->db_field = $segments[2];
|
||||
$update[$i]->db_field_value = $segments[3];
|
||||
$update[$i]->type = 'db_data';
|
||||
$update[$i]->id_update_package = $num_package;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($file_name == $sql_schema_file && $type == 'sql') {
|
||||
$f = fopen($tmpDir.$sql_schema_file, "r");
|
||||
$f_content = fread($f, filesize($tmpDir.$sql_schema_file));
|
||||
fclose($f);
|
||||
$f_array = array();
|
||||
|
||||
$f_array = explode(chr(10).chr(10),$f_content);
|
||||
foreach($f_array as $f_line) {
|
||||
if($f_line != '') {
|
||||
$segments = explode(";", $f_line);
|
||||
$update[$i]->data = um_data_encode($segments[0]);
|
||||
$update[$i]->id = $segments[1];
|
||||
$update[$i]->type = 'db_schema';
|
||||
$update[$i]->id_update_package = $num_package;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach($paths as $path) {
|
||||
$f = fopen($tmpDir.$type.preg_replace('/\s/','',$path).$file_name, "r");
|
||||
$f_content = fread($f, filesize($tmpDir.$type.preg_replace('/\s/','',$path).$file_name));
|
||||
fclose($f);
|
||||
// Delete the first character "/"
|
||||
$path = substr($path,2);
|
||||
|
||||
$update[$i]->filename = preg_replace('/\s/','',$path).$file_name;
|
||||
//$f_content = file_get_contents($tmpDir.$type.preg_replace('/\s/','',$path).$file_name);
|
||||
$data = um_data_encode($f_content);
|
||||
|
||||
$update[$i]->data = $data;
|
||||
$update[$i]->type = $type;
|
||||
$update[$i]->previous_checksum = '';
|
||||
$update[$i]->checksum = md5($f_content);
|
||||
$update[$i]->id_update_package = $num_package;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $update;
|
||||
}
|
||||
|
||||
function um_client_upgrade_to_package ($package, $settings, $force = true, $update_offline = false) {
|
||||
$applied_updates = array ();
|
||||
$rollback = false;
|
||||
|
||||
|
||||
if (!is_object($package)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$update_offline) {
|
||||
um_client_db_connect ($settings);
|
||||
um_component_db_connect ();
|
||||
foreach ($package->updates as $update) {
|
||||
$success = um_client_apply_update ($update, $settings, $force);
|
||||
if (! $success) {
|
||||
echo '<p /><strong>Failed</strong> on:<br />';
|
||||
um_client_print_update ($update, $settings);
|
||||
$rollback = true;
|
||||
break;
|
||||
}
|
||||
|
||||
array_push ($applied_updates, $update);
|
||||
}
|
||||
|
||||
if ($rollback) {
|
||||
foreach ($applied_updates as $update) {
|
||||
$success = um_client_rollback_update ($update, $settings);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
um_client_db_save_package ($package, $settings);
|
||||
|
||||
foreach ($package->updates as $update) {
|
||||
um_client_db_save_update ($update);
|
||||
}
|
||||
|
||||
um_db_update_setting ('current_update', $package->id);
|
||||
|
||||
db_process_sql_commit();
|
||||
}
|
||||
else {
|
||||
$data_queries = '';
|
||||
$schema_queries = '';
|
||||
$zip = new ZipArchive;
|
||||
$temp_files = array();
|
||||
$md5_dir = md5("update_".$package->id);
|
||||
|
||||
// Get the temp path on the server
|
||||
$path_script = explode('/',$_SERVER['SCRIPT_FILENAME']);
|
||||
$path_server = explode('/',$_SERVER['DOCUMENT_ROOT']);
|
||||
|
||||
unset($path_script[count($path_script)-1]);
|
||||
|
||||
$tempDir = implode('/',$path_script).'/temp/';
|
||||
|
||||
for($i=0; $i<count($path_server); $i++) {
|
||||
unset($path_script[$i]);
|
||||
}
|
||||
|
||||
$tempDirServer = '/'.implode('/',$path_script).'/temp/';
|
||||
|
||||
$package_name = 'package_'.$package->id.'.oum';
|
||||
$zipArchive = $tempDir . $package_name;
|
||||
$zipArchiveServer = $tempDirServer . $package_name;
|
||||
|
||||
@unlink($zipArchive);
|
||||
|
||||
if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) {
|
||||
foreach ($package->updates as $update) {
|
||||
$filename = '';
|
||||
|
||||
switch($update->type) {
|
||||
case 'code':
|
||||
case 'binary':
|
||||
$md5_name = md5($path_remote.$update->filename);
|
||||
$success = um_client_create_update_file ($update->data, $tempDir.$md5_name);
|
||||
$zip->addFile($tempDir.$md5_name, $update->type.'/'.$update->filename);
|
||||
$temp_files[] = $tempDir.$md5_name;
|
||||
break;
|
||||
case 'db_data':
|
||||
$data = um_data_decode($update->data);
|
||||
if(substr($data, strlen($data)-1,1) != ';') {
|
||||
$data_queries .= $data.";".$update->db_table.";".$update->db_field.";".$update->db_field_value.";".$update->id.";\n\n";
|
||||
}
|
||||
else {
|
||||
$data_queries .= $data.$update->db_table.";".$update->db_field.";".$update->db_field_value.";".$update->id.";\n\n";
|
||||
}
|
||||
break;
|
||||
case 'db_schema':
|
||||
$data = um_data_decode($update->data);
|
||||
if(substr($data, strlen($data)-1,1) != ';') {
|
||||
$schema_queries .= $data.";".$update->id.";\n\n";
|
||||
}
|
||||
else {
|
||||
$schema_queries .= $data.$update->id.";\n\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Creating the schema sql script
|
||||
$success = um_client_create_update_file (um_data_encode($schema_queries), $tempDir."schema_db");
|
||||
$zip->addFile($tempDir."schema_db", '01_package_'.$package->id.'_schema.sql');
|
||||
$temp_files[] = $tempDir."schema_db";
|
||||
|
||||
// Creating the data sql script
|
||||
$success = um_client_create_update_file (um_data_encode($data_queries), $tempDir."data_db");
|
||||
$zip->addFile($tempDir."data_db", '02_package_'.$package->id.'_data.sql');
|
||||
$temp_files[] = $tempDir."data_db";
|
||||
|
||||
// Creating the package info file
|
||||
$package_info = $package;
|
||||
unset($package_info->updates);
|
||||
|
||||
$success = um_client_create_update_file (um_data_encode(json_encode($package_info)), $tempDir."info_package");
|
||||
$zip->addFile($tempDir."info_package", 'info_package');
|
||||
$temp_files[] = $tempDir."info_package";
|
||||
|
||||
$zip->close();
|
||||
|
||||
// Clean temp files
|
||||
foreach($temp_files as $file) {
|
||||
@unlink($file);
|
||||
}
|
||||
|
||||
chdir($tempDir);
|
||||
|
||||
header("Content-type: application/zip");
|
||||
header("Content-Disposition: attachment; filename="
|
||||
. $package_name);
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
readfile($package_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_upgrade_to_latest ($user_key, $force = true) {
|
||||
global $config;
|
||||
|
||||
require_once($config["homedir"] .
|
||||
"/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call um_client_upgrade_to_latest function.");
|
||||
|
||||
$success = false;
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
db_process_sql_begin();
|
||||
do {
|
||||
$package = um_client_get_package ($settings, $user_key);
|
||||
|
||||
|
||||
if ($package === false || $package === true ||
|
||||
$package === 0 || $package === 1) {
|
||||
|
||||
print_debug_message_trace("Package download not is a object, it is " .
|
||||
(int)$package . ".");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$success = um_client_upgrade_to_package ($package, $settings, $force);
|
||||
|
||||
if (! $success)
|
||||
break;
|
||||
|
||||
print_debug_message_trace("Success update package " .
|
||||
(int)$package->id . ".");
|
||||
|
||||
$settings->current_update = $package->id;
|
||||
}
|
||||
while (1);
|
||||
|
||||
/* Break on error, when there are no more packages on the server (server return true)
|
||||
or on auth failure (server return false) */
|
||||
|
||||
print_debug_message_trace("End Call um_client_upgrade_to_latest function.");
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
function um_client_db_connect (&$settings = NULL) {
|
||||
if (! $settings)
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
//mysql_select_db (DB_NAME);
|
||||
mysql_connect ($settings->dbhost . ':' . $settings->dbport, $settings->dbuser,
|
||||
$settings->dbpass);
|
||||
}
|
||||
?>
|
|
@ -1,277 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
|
||||
function um_component_database_get_data ($component_db) {
|
||||
$db = um_component_db_connect ();
|
||||
|
||||
if ($db === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = um_component_database_get_table_fields ($component_db->table_name);
|
||||
|
||||
$result = db_process_sql('SELECT COUNT(*) FROM '.$component_db->table_name);
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting table fields</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result = db_process_sql('SELECT '.implode (',', $fields).' FROM '.$component_db->table_name);
|
||||
|
||||
$cont = 0;
|
||||
$resultdata = array();
|
||||
$field = $component_db->field_name;
|
||||
|
||||
while(true) {
|
||||
$data = um_std_from_result($result, $cont);
|
||||
if($data === false) {
|
||||
break;
|
||||
}
|
||||
$update = um_update_get_last_from_table_field_value ($component_db->component,
|
||||
$component_db->id,
|
||||
$data->$field);
|
||||
if ($update && $update->db_field_value == $data->$field)
|
||||
continue;
|
||||
$resultdata[] = $data;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $resultdata;
|
||||
}
|
||||
|
||||
function um_component_database_get_all_tables () {
|
||||
global $config;
|
||||
|
||||
$db = um_component_db_connect ();
|
||||
|
||||
if ($db === false) {
|
||||
return array ();
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SHOW TABLES');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\';');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT table_name FROM user_tables');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting tables</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$tables = array();
|
||||
foreach($result as $table) {
|
||||
if ($config["dbtype"] == 'oracle') {
|
||||
$tables[] = $table['table_name'];
|
||||
}
|
||||
else {
|
||||
$tables[] = $table[0];
|
||||
}
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
function um_component_database_get_available_tables ($component_name) {
|
||||
$all_tables = um_component_database_get_all_tables ();
|
||||
$components_db = um_db_get_database_components ($component_name);
|
||||
$defined_tables = array ();
|
||||
foreach ($components_db as $component_db) {
|
||||
array_push ($defined_tables, $component_db->table_name);
|
||||
}
|
||||
|
||||
return array_diff ($all_tables, $defined_tables);
|
||||
}
|
||||
|
||||
function um_component_database_get_table_fields ($table_name) {
|
||||
global $config;
|
||||
|
||||
$db = um_component_db_connect ();
|
||||
|
||||
if ($db === false) {
|
||||
return array ();
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SHOW COLUMNS FROM '.$table_name.' WHERE `Key` != "PRI"');
|
||||
break;
|
||||
case "postgresql":
|
||||
//TODO: verificar que se extraen todos los campos menos clave primaria
|
||||
$result = db_process_sql("SELECT * FROM pg_indexes WHERE tablename = '" . $table_name . "'");
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql("SELECT cols1.column_name as Fields, cols1.data_type as Type,
|
||||
CASE WHEN (cols1.nullable = 'Y') THEN 'YES' ELSE 'NO' END as \"Null\",
|
||||
cols1.data_default as \"Default\", '' as Extra
|
||||
FROM user_tab_columns cols1
|
||||
WHERE cols1.table_name ='".$table_name."'
|
||||
AND cols1.column_name NOT IN (select distinct usr.column_name
|
||||
from user_cons_columns usr, user_constraints co
|
||||
where usr.constraint_name = co.constraint_name and
|
||||
constraint_type = 'P' and co.table_name = '" . $table_name . "')
|
||||
order by cols1.column_id");
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting table fields</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$fields = array();
|
||||
while(true) {
|
||||
$field = um_std_from_result($result, $cont);
|
||||
if($field === false) {
|
||||
break;
|
||||
}
|
||||
$fields[$cont] = $field->Field;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function um_component_directory_get_all_files ($component, $binary = false) {
|
||||
if (! $component || ! isset ($component->path)) {
|
||||
return array ();
|
||||
}
|
||||
|
||||
if (! is_dir ($component->path)) {
|
||||
return array ();
|
||||
}
|
||||
|
||||
$path = $component->path;
|
||||
if (substr ($path, -1) != '/')
|
||||
$path .= "/";
|
||||
$files = directory_to_array ($path,
|
||||
array ('.svn', '.cvs', '.git', '.', '..'), $binary);
|
||||
$blacklisted = um_component_get_all_blacklisted ($component);
|
||||
|
||||
return (array_diff ($files, $blacklisted));
|
||||
}
|
||||
|
||||
function um_component_directory_get_modified_files ($component, $binary = false) {
|
||||
$all_files = um_component_directory_get_all_files ($component, $binary);
|
||||
|
||||
$files = array ();
|
||||
foreach ($all_files as $file) {
|
||||
if (um_component_is_blacklisted ($component, $file))
|
||||
continue;
|
||||
|
||||
$last_update = um_update_get_last_from_filename ($component->name,
|
||||
$file);
|
||||
if ($last_update) {
|
||||
$checksum = md5_file (realpath ($component->path.'/'.$file));
|
||||
if ($last_update->checksum == $checksum)
|
||||
continue;
|
||||
}
|
||||
array_push ($files, $file);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
function um_component_get_all_blacklisted ($component) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(name) FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
|
||||
break;
|
||||
case "postgresql":
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT COUNT(name)
|
||||
FROM '.DB_PREFIX.'tupdate_component_blacklist
|
||||
WHERE component = \''.$component->name.'\'');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting all blacklisted items</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT name FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
|
||||
break;
|
||||
case "postgresql":
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT name
|
||||
FROM '.DB_PREFIX.'tupdate_component_blacklist
|
||||
WHERE component = \''.$component->name.'\'');
|
||||
break;
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$list = array();
|
||||
while(true) {
|
||||
$element = um_std_from_result($result, $cont);
|
||||
if($element === false) {
|
||||
break;
|
||||
}
|
||||
$list[$cont] = $element->name;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
function um_component_is_blacklisted ($component, $name) {
|
||||
global $config;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(*) AS blacklisted FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'" AND name = "'.$name.'"');
|
||||
break;
|
||||
case "postgresql":
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT COUNT(*) AS blacklisted
|
||||
FROM '.DB_PREFIX.'tupdate_component_blacklist
|
||||
WHERE component = \''.$component->name.'\' AND name = \''.$name.'\'');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting blacklist item</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$retval = um_std_from_result($result);
|
||||
|
||||
return $retval->blacklisted ? true : false;
|
||||
}
|
||||
|
||||
function um_component_add_blacklist ($component, $name) {
|
||||
$values = array('component' => $component->name, 'name' => $name);
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate_component_blacklist', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating blacklist component</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
?>
|
|
@ -1,234 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
|
||||
|
||||
function um_update_get_last_from_filename ($component_name, $filename) {
|
||||
global $config;
|
||||
|
||||
$component = um_db_get_component ($component_name);
|
||||
|
||||
if (! $component)
|
||||
return;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = \''.$component_name.'\' AND filename = \''.$component->relative_path.$filename.'\' ORDER BY id DESC LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE (component = \''.$component_name.'\' AND filename = \''.$component->relative_path.$filename.'\') AND rownum < 2 ORDER BY id DESC');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting update from filename</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
|
||||
break;
|
||||
case "postgresql":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate
|
||||
WHERE component = \''.$component_name.'\'
|
||||
AND filename = \''.$component->relative_path.$filename.'\' ORDER BY id DESC LIMIT 1');
|
||||
break;
|
||||
case "oracle":
|
||||
$result = db_process_sql('SELECT *
|
||||
FROM '.DB_PREFIX.'tupdate
|
||||
WHERE (component = \''.$component_name.'\'
|
||||
AND filename = \''.$component->relative_path.$filename.'\') AND rownum < 2 ORDER BY id DESC');
|
||||
break;
|
||||
}
|
||||
|
||||
$update = um_std_from_result($result);
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
function um_update_get_last_from_table_field_value ($component_name, $id_component_db, $field_value) {
|
||||
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND id_component_db = "'.$id_component_db.'" AND db_field_value = "'.$field_value.'" ORDER BY id DESC LIMIT 1');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting last value</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND id_component_db = "'.$id_component_db.'" AND db_field_value = "'.$field_value.'" ORDER BY id DESC LIMIT 1');
|
||||
|
||||
$update = um_std_from_result($result);
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
function um_db_get_orphan_updates () {
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE id_update_package IS NULL');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting orphan updates</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$cont = 0;
|
||||
$updates = array();
|
||||
while (true) {
|
||||
$update = um_std_from_result($result, $cont);
|
||||
if ($update === false) {
|
||||
break;
|
||||
}
|
||||
$updates[$update['id']] = $update;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
||||
function um_db_get_update ($id_update) {
|
||||
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE id = "'.$id_update.'" LIMIT 1');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting update</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$update = um_std_from_result($result);
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
function um_db_delete_update ($id_update) {
|
||||
global $db;
|
||||
|
||||
$update = um_db_get_update ($id_update);
|
||||
$package = um_db_get_package ($update->id_update_package);
|
||||
if ($package->status != 'development') {
|
||||
echo '<strong>Error</strong>: '.'Only packages in development state can be deleted';
|
||||
return false;
|
||||
}
|
||||
$result = db_process_sql_delete(DB_PREFIX.'tupdate', array('id' => $id_update));
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error deleting update</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_create_update ($type, $component_name, $id_package, $update, $db_data = NULL) {
|
||||
global $db;
|
||||
global $config;
|
||||
|
||||
if ($id_package == 0)
|
||||
return false;
|
||||
$component = um_db_get_component ($component_name);
|
||||
if (! $component)
|
||||
return;
|
||||
$values = array ('type' => $type,
|
||||
'component' => $component_name,
|
||||
'id_update_package' => $id_package);
|
||||
switch ($type) {
|
||||
case 'code':
|
||||
$filepath = realpath ($component->path.'/'.$update->filename);
|
||||
$values['svn_version'] = um_file_get_svn_revision ($filepath);
|
||||
case 'binary':
|
||||
$last_update = um_update_get_last_from_filename ($component_name, $update->filename);
|
||||
$filepath = realpath ($component->path.'/'.$update->filename);
|
||||
$values['checksum'] = md5_file ($filepath);
|
||||
if ($last_update && $last_update->checksum == $values['checksum']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Add relative path if has one */
|
||||
if ($component->relative_path != '') {
|
||||
$values['filename'] = $component->relative_path.$update->filename;
|
||||
}
|
||||
else {
|
||||
$values['filename'] = $update->filename;
|
||||
}
|
||||
$values['data'] = um_file_uuencode ($filepath);
|
||||
if ($last_update && $last_update->checksum != '')
|
||||
$values['previous_checksum'] = $last_update->checksum;
|
||||
|
||||
break;
|
||||
case 'db_data':
|
||||
if ($db_data === NULL)
|
||||
return false;
|
||||
$component_db = um_db_get_component_db ($update->id_component_db);
|
||||
$field = $component_db->field_name;
|
||||
$values['db_field_value'] = $db_data->$field;
|
||||
$values['id_component_db'] = $update->id_component_db;
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
$values['data'] = um_data_encode('INSERT INTO `'.$component_db->table_name.'` (`'.implode('`,`', array_keys (get_object_vars ($db_data))).'`) VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')');
|
||||
break;
|
||||
case "postgresql":
|
||||
$values['data'] = um_data_encode('INSERT INTO "'.$component_db->table_name.'" ("'.implode('", "', array_keys (get_object_vars ($db_data))).'") VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')');
|
||||
break;
|
||||
case "oracle":
|
||||
$values['data'] = um_data_encode('INSERT INTO '.$component_db->table_name.' ('.implode(', ', array_keys (get_object_vars ($db_data))).') VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'db_schema':
|
||||
$values['data'] = um_data_encode($update->data);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = db_process_sql_insert(DB_PREFIX.'tupdate', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating update</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_get_update_types () {
|
||||
$types = array ();
|
||||
|
||||
$types['code'] = 'Code';
|
||||
$types['db_data'] = 'Database data';
|
||||
$types['db_schema'] = 'Database schema';
|
||||
$types['binary'] = 'Binary file';
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
function um_file_get_svn_revision ($file) {
|
||||
return (int) exec ('svn info '.$file.'| grep "Revis" | head -1 | cut -f2 -d":"');
|
||||
}
|
||||
|
||||
function um_file_uuencode ($file) {
|
||||
$content = file_get_contents ($file);
|
||||
return um_data_encode ($content);
|
||||
}
|
||||
|
||||
function um_data_decode ($data) {
|
||||
return convert_uudecode(base64_decode($data));
|
||||
}
|
||||
|
||||
function um_data_encode ($data) {
|
||||
return base64_encode(convert_uuencode ($data));
|
||||
}
|
||||
?>
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
|
||||
|
||||
function add_prefix (&$string, $key, $prefix) {
|
||||
$string = $prefix.'/'.$string;
|
||||
}
|
||||
|
||||
function is_binary ($filepath) {
|
||||
$output = array ();
|
||||
exec ('file -b -i '.$filepath.' | cut -f1 -d"/"', $output);
|
||||
|
||||
if (isset ($output[0]))
|
||||
return $output[0] != 'text';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function directory_to_array ($directory, $ignores = NULL, $only_binary_files = false) {
|
||||
if (! $ignores)
|
||||
$ignores = array ('.', '..');
|
||||
|
||||
$array_items = array ();
|
||||
$handle = @opendir ($directory);
|
||||
if (! $handle) {
|
||||
return array ();
|
||||
}
|
||||
$file = readdir ($handle);
|
||||
$dirs = array ();
|
||||
while ($file !== false) {
|
||||
if (in_array ($file, $ignores)) {
|
||||
$file = readdir ($handle);
|
||||
continue;
|
||||
}
|
||||
$filepath = realpath ($directory."/".$file);
|
||||
$dir = array_pop (explode ("/", $directory));
|
||||
if (! is_readable ($filepath)) {
|
||||
$file = readdir ($handle);
|
||||
continue;
|
||||
}
|
||||
if (is_dir ($filepath)) {
|
||||
array_push ($dirs, $filepath);
|
||||
}
|
||||
else {
|
||||
if ($only_binary_files && ! is_binary ($filepath)) {
|
||||
$file = readdir ($handle);
|
||||
continue;
|
||||
}
|
||||
$relative_path = $dir != '' ? $dir. "/" : '';
|
||||
$array_items[] = preg_replace("/\/\//si", "/", $relative_path.$file);
|
||||
}
|
||||
$file = readdir ($handle);
|
||||
}
|
||||
sort ($array_items);
|
||||
sort ($dirs);
|
||||
foreach ($dirs as $filepath) {
|
||||
$files = directory_to_array ($filepath, $ignores, $only_binary_files);
|
||||
if ($dir != '')
|
||||
array_walk ($files, 'add_prefix', $dir);
|
||||
$array_items = array_merge ($array_items, $files);
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
return $array_items;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
|
||||
|
||||
/* Change to E_ALL for development/debugging */
|
||||
error_reporting (E_ALL);
|
||||
|
||||
/* Database backend, not really tested with other backends, so it's
|
||||
not functional right now */
|
||||
define ('DB_BACKEND', 'mysql');
|
||||
|
||||
if (! extension_loaded ('mysql'))
|
||||
die ('Your PHP installation appears to be missing the MySQL extension which is required.');
|
||||
|
||||
require_once ('libupdate_manager.php');
|
||||
|
||||
um_db_connect (DB_BACKEND, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
|
||||
flush ();
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
|
@ -1,955 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP-XMLRPC "wrapper" functions
|
||||
* Generate stubs to transparently access xmlrpc methods as php functions and viceversa
|
||||
*
|
||||
* @version $Id: xmlrpc_wrappers.inc,v 1.13 2008/09/20 01:23:47 ggiunta Exp $
|
||||
* @author Gaetano Giunta
|
||||
* @copyright (C) 2006-2009 G. Giunta
|
||||
* @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
|
||||
*
|
||||
* @todo separate introspection from code generation for func-2-method wrapping
|
||||
* @todo use some better templating system for code generation?
|
||||
* @todo implement method wrapping with preservation of php objs in calls
|
||||
* @todo when wrapping methods without obj rebuilding, use return_type = 'phpvals' (faster)
|
||||
* @todo implement self-parsing of php code for PHP <= 4
|
||||
*/
|
||||
|
||||
// requires: xmlrpc.inc
|
||||
|
||||
/**
|
||||
* Given a string defining a php type or phpxmlrpc type (loosely defined: strings
|
||||
* accepted come from javadoc blocks), return corresponding phpxmlrpc type.
|
||||
* NB: for php 'resource' types returns empty string, since resources cannot be serialized;
|
||||
* for php class names returns 'struct', since php objects can be serialized as xmlrpc structs
|
||||
* for php arrays always return array, even though arrays sometiles serialize as json structs
|
||||
* @param string $phptype
|
||||
* @return string
|
||||
*/
|
||||
function php_2_xmlrpc_type($phptype)
|
||||
{
|
||||
switch(strtolower($phptype))
|
||||
{
|
||||
case 'string':
|
||||
return $GLOBALS['xmlrpcString'];
|
||||
case 'integer':
|
||||
case $GLOBALS['xmlrpcInt']: // 'int'
|
||||
case $GLOBALS['xmlrpcI4']:
|
||||
return $GLOBALS['xmlrpcInt'];
|
||||
case 'double':
|
||||
return $GLOBALS['xmlrpcDouble'];
|
||||
case 'boolean':
|
||||
return $GLOBALS['xmlrpcBoolean'];
|
||||
case 'array':
|
||||
return $GLOBALS['xmlrpcArray'];
|
||||
case 'object':
|
||||
return $GLOBALS['xmlrpcStruct'];
|
||||
case $GLOBALS['xmlrpcBase64']:
|
||||
case $GLOBALS['xmlrpcStruct']:
|
||||
return strtolower($phptype);
|
||||
case 'resource':
|
||||
return '';
|
||||
default:
|
||||
if(class_exists($phptype))
|
||||
{
|
||||
return $GLOBALS['xmlrpcStruct'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown: might be any 'extended' xmlrpc type
|
||||
return $GLOBALS['xmlrpcValue'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string defining a phpxmlrpc type return corresponding php type.
|
||||
* @param string $xmlrpctype
|
||||
* @return string
|
||||
*/
|
||||
function xmlrpc_2_php_type($xmlrpctype)
|
||||
{
|
||||
switch(strtolower($xmlrpctype))
|
||||
{
|
||||
case 'base64':
|
||||
case 'datetime.iso8601':
|
||||
case 'string':
|
||||
return $GLOBALS['xmlrpcString'];
|
||||
case 'int':
|
||||
case 'i4':
|
||||
return 'integer';
|
||||
case 'struct':
|
||||
case 'array':
|
||||
return 'array';
|
||||
case 'double':
|
||||
return 'float';
|
||||
case 'undefined':
|
||||
return 'mixed';
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
default:
|
||||
// unknown: might be any xmlrpc type
|
||||
return strtolower($xmlrpctype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a user-defined PHP function, create a PHP 'wrapper' function that can
|
||||
* be exposed as xmlrpc method from an xmlrpc_server object and called from remote
|
||||
* clients (as well as its corresponding signature info).
|
||||
*
|
||||
* Since php is a typeless language, to infer types of input and output parameters,
|
||||
* it relies on parsing the javadoc-style comment block associated with the given
|
||||
* function. Usage of xmlrpc native types (such as datetime.dateTime.iso8601 and base64)
|
||||
* in the @param tag is also allowed, if you need the php function to receive/send
|
||||
* data in that particular format (note that base64 encoding/decoding is transparently
|
||||
* carried out by the lib, while datetime vals are passed around as strings)
|
||||
*
|
||||
* Known limitations:
|
||||
* - requires PHP 5.0.3 +
|
||||
* - only works for user-defined functions, not for PHP internal functions
|
||||
* (reflection does not support retrieving number/type of params for those)
|
||||
* - functions returning php objects will generate special xmlrpc responses:
|
||||
* when the xmlrpc decoding of those responses is carried out by this same lib, using
|
||||
* the appropriate param in php_xmlrpc_decode, the php objects will be rebuilt.
|
||||
* In short: php objects can be serialized, too (except for their resource members),
|
||||
* using this function.
|
||||
* Other libs might choke on the very same xml that will be generated in this case
|
||||
* (i.e. it has a nonstandard attribute on struct element tags)
|
||||
* - usage of javadoc @param tags using param names in a different order from the
|
||||
* function prototype is not considered valid (to be fixed?)
|
||||
*
|
||||
* Note that since rel. 2.0RC3 the preferred method to have the server call 'standard'
|
||||
* php functions (ie. functions not expecting a single xmlrpcmsg obj as parameter)
|
||||
* is by making use of the functions_parameters_type class member.
|
||||
*
|
||||
* @param string $funcname the name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') and array('class', 'methodname') are ok too
|
||||
* @param string $newfuncname (optional) name for function to be created
|
||||
* @param array $extra_options (optional) array of options for conversion. valid values include:
|
||||
* bool return_source when true, php code w. function definition will be returned, not evaluated
|
||||
* bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
|
||||
* bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
|
||||
* bool suppress_warnings remove from produced xml any runtime warnings due to the php function being invoked
|
||||
* @return false on error, or an array containing the name of the new php function,
|
||||
* its signature and docs, to be used in the server dispatch map
|
||||
*
|
||||
* @todo decide how to deal with params passed by ref: bomb out or allow?
|
||||
* @todo finish using javadoc info to build method sig if all params are named but out of order
|
||||
* @todo add a check for params of 'resource' type
|
||||
* @todo add some trigger_errors / error_log when returning false?
|
||||
* @todo what to do when the PHP function returns NULL? we are currently returning an empty string value...
|
||||
* @todo add an option to suppress php warnings in invocation of user function, similar to server debug level 3?
|
||||
* @todo if $newfuncname is empty, we could use create_user_func instead of eval, as it is possibly faster
|
||||
* @todo add a verbatim_object_copy parameter to allow avoiding the same obj instance?
|
||||
*/
|
||||
function wrap_php_function($funcname, $newfuncname='', $extra_options=array())
|
||||
{
|
||||
$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
|
||||
$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
|
||||
$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
|
||||
$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
|
||||
$catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';
|
||||
|
||||
if(version_compare(phpversion(), '5.0.3') == -1)
|
||||
{
|
||||
// up to php 5.0.3 some useful reflection methods were missing
|
||||
error_log('XML-RPC: cannot not wrap php functions unless running php version bigger than 5.0.3');
|
||||
return false;
|
||||
}
|
||||
|
||||
$exists = false;
|
||||
if (is_string($funcname) && strpos($funcname, '::') !== false)
|
||||
{
|
||||
$funcname = explode('::', $funcname);
|
||||
}
|
||||
if(is_array($funcname))
|
||||
{
|
||||
if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))
|
||||
{
|
||||
error_log('XML-RPC: syntax for function to be wrapped is wrong');
|
||||
return false;
|
||||
}
|
||||
if(is_string($funcname[0]))
|
||||
{
|
||||
$plainfuncname = implode('::', $funcname);
|
||||
}
|
||||
elseif(is_object($funcname[0]))
|
||||
{
|
||||
$plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];
|
||||
}
|
||||
$exists = method_exists($funcname[0], $funcname[1]);
|
||||
if (!$exists && version_compare(phpversion(), '5.1') < 0)
|
||||
{
|
||||
// workaround for php 5.0: static class methods are not seen by method_exists
|
||||
$exists = is_callable( $funcname );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$plainfuncname = $funcname;
|
||||
$exists = function_exists($funcname);
|
||||
}
|
||||
|
||||
if(!$exists)
|
||||
{
|
||||
error_log('XML-RPC: function to be wrapped is not defined: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine name of new php function
|
||||
if($newfuncname == '')
|
||||
{
|
||||
if(is_array($funcname))
|
||||
{
|
||||
if(is_string($funcname[0]))
|
||||
$xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
|
||||
else
|
||||
$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlrpcfuncname = "{$prefix}_$funcname";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlrpcfuncname = $newfuncname;
|
||||
}
|
||||
while($buildit && function_exists($xmlrpcfuncname))
|
||||
{
|
||||
$xmlrpcfuncname .= 'x';
|
||||
}
|
||||
|
||||
// start to introspect PHP code
|
||||
if(is_array($funcname))
|
||||
{
|
||||
$func = new ReflectionMethod($funcname[0], $funcname[1]);
|
||||
if($func->isPrivate())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
if($func->isProtected())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
if($func->isConstructor())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
// php 503 always says isdestructor = true...
|
||||
if( version_compare(phpversion(), '5.0.3') != 0 && $func->isDestructor())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
if($func->isAbstract())
|
||||
{
|
||||
error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
/// @todo add more checks for static vs. nonstatic?
|
||||
}
|
||||
else
|
||||
{
|
||||
$func = new ReflectionFunction($funcname);
|
||||
}
|
||||
if($func->isInternal())
|
||||
{
|
||||
// Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs
|
||||
// instead of getparameters to fully reflect internal php functions ?
|
||||
error_log('XML-RPC: function to be wrapped is internal: '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
|
||||
// retrieve parameter names, types and description from javadoc comments
|
||||
|
||||
// function description
|
||||
$desc = '';
|
||||
// type of return val: by default 'any'
|
||||
$returns = $GLOBALS['xmlrpcValue'];
|
||||
// desc of return val
|
||||
$returnsDocs = '';
|
||||
// type + name of function parameters
|
||||
$paramDocs = array();
|
||||
|
||||
$docs = $func->getDocComment();
|
||||
if($docs != '')
|
||||
{
|
||||
$docs = explode("\n", $docs);
|
||||
$i = 0;
|
||||
foreach($docs as $doc)
|
||||
{
|
||||
$doc = trim($doc, " \r\t/*");
|
||||
if(strlen($doc) && strpos($doc, '@') !== 0 && !$i)
|
||||
{
|
||||
if($desc)
|
||||
{
|
||||
$desc .= "\n";
|
||||
}
|
||||
$desc .= $doc;
|
||||
}
|
||||
elseif(strpos($doc, '@param') === 0)
|
||||
{
|
||||
// syntax: @param type [$name] desc
|
||||
if(preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
|
||||
{
|
||||
if(strpos($matches[1], '|'))
|
||||
{
|
||||
//$paramDocs[$i]['type'] = explode('|', $matches[1]);
|
||||
$paramDocs[$i]['type'] = 'mixed';
|
||||
}
|
||||
else
|
||||
{
|
||||
$paramDocs[$i]['type'] = $matches[1];
|
||||
}
|
||||
$paramDocs[$i]['name'] = trim($matches[2]);
|
||||
$paramDocs[$i]['doc'] = $matches[3];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
elseif(strpos($doc, '@return') === 0)
|
||||
{
|
||||
// syntax: @return type desc
|
||||
//$returns = preg_split('/\s+/', $doc);
|
||||
if(preg_match('/@return\s+(\S+)\s+(.+)/', $doc, $matches))
|
||||
{
|
||||
$returns = php_2_xmlrpc_type($matches[1]);
|
||||
if(isset($matches[2]))
|
||||
{
|
||||
$returnsDocs = $matches[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// execute introspection of actual function prototype
|
||||
$params = array();
|
||||
$i = 0;
|
||||
foreach($func->getParameters() as $paramobj)
|
||||
{
|
||||
$params[$i] = array();
|
||||
$params[$i]['name'] = '$'.$paramobj->getName();
|
||||
$params[$i]['isoptional'] = $paramobj->isOptional();
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
// start building of PHP code to be eval'd
|
||||
$innercode = '';
|
||||
$i = 0;
|
||||
$parsvariations = array();
|
||||
$pars = array();
|
||||
$pnum = count($params);
|
||||
foreach($params as $param)
|
||||
{
|
||||
if (isset($paramDocs[$i]['name']) && $paramDocs[$i]['name'] && strtolower($paramDocs[$i]['name']) != strtolower($param['name']))
|
||||
{
|
||||
// param name from phpdoc info does not match param definition!
|
||||
$paramDocs[$i]['type'] = 'mixed';
|
||||
}
|
||||
|
||||
if($param['isoptional'])
|
||||
{
|
||||
// this particular parameter is optional. save as valid previous list of parameters
|
||||
$innercode .= "if (\$paramcount > $i) {\n";
|
||||
$parsvariations[] = $pars;
|
||||
}
|
||||
$innercode .= "\$p$i = \$msg->getParam($i);\n";
|
||||
if ($decode_php_objects)
|
||||
{
|
||||
$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i, array('decode_php_objs'));\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i);\n";
|
||||
}
|
||||
|
||||
$pars[] = "\$p$i";
|
||||
$i++;
|
||||
if($param['isoptional'])
|
||||
{
|
||||
$innercode .= "}\n";
|
||||
}
|
||||
if($i == $pnum)
|
||||
{
|
||||
// last allowed parameters combination
|
||||
$parsvariations[] = $pars;
|
||||
}
|
||||
}
|
||||
|
||||
$sigs = array();
|
||||
$psigs = array();
|
||||
if(count($parsvariations) == 0)
|
||||
{
|
||||
// only known good synopsis = no parameters
|
||||
$parsvariations[] = array();
|
||||
$minpars = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$minpars = count($parsvariations[0]);
|
||||
}
|
||||
|
||||
if($minpars)
|
||||
{
|
||||
// add to code the check for min params number
|
||||
// NB: this check needs to be done BEFORE decoding param values
|
||||
$innercode = "\$paramcount = \$msg->getNumParams();\n" .
|
||||
"if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n" . $innercode;
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode;
|
||||
}
|
||||
|
||||
$innercode .= "\$np = false;\n";
|
||||
// since there are no closures in php, if we are given an object instance,
|
||||
// we store a pointer to it in a global var...
|
||||
if ( is_array($funcname) && is_object($funcname[0]) )
|
||||
{
|
||||
$GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];
|
||||
$innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";
|
||||
$realfuncname = '$obj->'.$funcname[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$realfuncname = $plainfuncname;
|
||||
}
|
||||
foreach($parsvariations as $pars)
|
||||
{
|
||||
$innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";
|
||||
// build a 'generic' signature (only use an appropriate return type)
|
||||
$sig = array($returns);
|
||||
$psig = array($returnsDocs);
|
||||
for($i=0; $i < count($pars); $i++)
|
||||
{
|
||||
if (isset($paramDocs[$i]['type']))
|
||||
{
|
||||
$sig[] = php_2_xmlrpc_type($paramDocs[$i]['type']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sig[] = $GLOBALS['xmlrpcValue'];
|
||||
}
|
||||
$psig[] = isset($paramDocs[$i]['doc']) ? $paramDocs[$i]['doc'] : '';
|
||||
}
|
||||
$sigs[] = $sig;
|
||||
$psigs[] = $psig;
|
||||
}
|
||||
$innercode .= "\$np = true;\n";
|
||||
$innercode .= "if (\$np) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}'); else {\n";
|
||||
//$innercode .= "if (\$_xmlrpcs_error_occurred) return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n";
|
||||
$innercode .= "if (is_a(\$retval, '{$prefix}resp')) return \$retval; else\n";
|
||||
if($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
|
||||
{
|
||||
$innercode .= "return new {$prefix}resp(new {$prefix}val(\$retval, '$returns'));";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($encode_php_objects)
|
||||
$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval, array('encode_php_objs')));\n";
|
||||
else
|
||||
$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval));\n";
|
||||
}
|
||||
// shall we exclude functions returning by ref?
|
||||
// if($func->returnsReference())
|
||||
// return false;
|
||||
$code = "function $xmlrpcfuncname(\$msg) {\n" . $innercode . "}\n}";
|
||||
//print_r($code);
|
||||
if ($buildit)
|
||||
{
|
||||
$allOK = 0;
|
||||
eval($code.'$allOK=1;');
|
||||
// alternative
|
||||
//$xmlrpcfuncname = create_function('$m', $innercode);
|
||||
|
||||
if(!$allOK)
|
||||
{
|
||||
error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap php function '.$plainfuncname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo examine if $paramDocs matches $parsvariations and build array for
|
||||
/// usage as method signature, plus put together a nice string for docs
|
||||
|
||||
$ret = array('function' => $xmlrpcfuncname, 'signature' => $sigs, 'docstring' => $desc, 'signature_docs' => $psigs, 'source' => $code);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a user-defined PHP class or php object, map its methods onto a list of
|
||||
* PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server
|
||||
* object and called from remote clients (as well as their corresponding signature info).
|
||||
*
|
||||
* @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class
|
||||
* @param array $extra_options see the docs for wrap_php_method for more options
|
||||
* string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance
|
||||
* @return array or false on failure
|
||||
*
|
||||
* @todo get_class_methods will return both static and non-static methods.
|
||||
* we have to differentiate the action, depending on wheter we recived a class name or object
|
||||
*/
|
||||
function wrap_php_class($classname, $extra_options=array())
|
||||
{
|
||||
$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
|
||||
$methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';
|
||||
|
||||
if(version_compare(phpversion(), '5.0.3') == -1)
|
||||
{
|
||||
// up to php 5.0.3 some useful reflection methods were missing
|
||||
error_log('XML-RPC: cannot not wrap php functions unless running php version bigger than 5.0.3');
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$mlist = get_class_methods($classname);
|
||||
foreach($mlist as $mname)
|
||||
{
|
||||
if ($methodfilter == '' || preg_match($methodfilter, $mname))
|
||||
{
|
||||
// echo $mlist."\n";
|
||||
$func = new ReflectionMethod($classname, $mname);
|
||||
if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())
|
||||
{
|
||||
if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||
|
||||
(!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))
|
||||
{
|
||||
$methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);
|
||||
if ( $methodwrap )
|
||||
{
|
||||
$result[$methodwrap['function']] = $methodwrap['function'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an xmlrpc client and a method name, register a php wrapper function
|
||||
* that will call it and return results using native php types for both
|
||||
* params and results. The generated php function will return an xmlrpcresp
|
||||
* oject for failed xmlrpc calls
|
||||
*
|
||||
* Known limitations:
|
||||
* - server must support system.methodsignature for the wanted xmlrpc method
|
||||
* - for methods that expose many signatures, only one can be picked (we
|
||||
* could in priciple check if signatures differ only by number of params
|
||||
* and not by type, but it would be more complication than we can spare time)
|
||||
* - nested xmlrpc params: the caller of the generated php function has to
|
||||
* encode on its own the params passed to the php function if these are structs
|
||||
* or arrays whose (sub)members include values of type datetime or base64
|
||||
*
|
||||
* Notes: the connection properties of the given client will be copied
|
||||
* and reused for the connection used during the call to the generated
|
||||
* php function.
|
||||
* Calling the generated php function 'might' be slow: a new xmlrpc client
|
||||
* is created on every invocation and an xmlrpc-connection opened+closed.
|
||||
* An extra 'debug' param is appended to param list of xmlrpc method, useful
|
||||
* for debugging purposes.
|
||||
*
|
||||
* @param xmlrpc_client $client an xmlrpc client set up correctly to communicate with target server
|
||||
* @param string $methodname the xmlrpc method to be mapped to a php function
|
||||
* @param array $extra_options array of options that specify conversion details. valid ptions include
|
||||
* integer signum the index of the method signature to use in mapping (if method exposes many sigs)
|
||||
* integer timeout timeout (in secs) to be used when executing function/calling remote method
|
||||
* string protocol 'http' (default), 'http11' or 'https'
|
||||
* string new_function_name the name of php function to create. If unsepcified, lib will pick an appropriate name
|
||||
* string return_source if true return php code w. function definition instead fo function name
|
||||
* bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
|
||||
* bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
|
||||
* mixed return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the xmlrpcresp object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values
|
||||
* bool debug set it to 1 or 2 to see debug results of querying server for method synopsis
|
||||
* @return string the name of the generated php function (or false) - OR AN ARRAY...
|
||||
*/
|
||||
function wrap_xmlrpc_method($client, $methodname, $extra_options=0, $timeout=0, $protocol='', $newfuncname='')
|
||||
{
|
||||
// mind numbing: let caller use sane calling convention (as per javadoc, 3 params),
|
||||
// OR the 2.0 calling convention (no options) - we really love backward compat, don't we?
|
||||
if (!is_array($extra_options))
|
||||
{
|
||||
$signum = $extra_options;
|
||||
$extra_options = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
|
||||
$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
|
||||
$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
|
||||
$newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : '';
|
||||
}
|
||||
//$encode_php_objects = in_array('encode_php_objects', $extra_options);
|
||||
//$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 :
|
||||
// in_array('build_class_code', $extra_options) ? 2 : 0;
|
||||
|
||||
$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
|
||||
$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
|
||||
$simple_client_copy = isset($extra_options['simple_client_copy']) ? (int)($extra_options['simple_client_copy']) : 0;
|
||||
$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
|
||||
$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
|
||||
if (isset($extra_options['return_on_fault']))
|
||||
{
|
||||
$decode_fault = true;
|
||||
$fault_response = $extra_options['return_on_fault'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$decode_fault = false;
|
||||
$fault_response = '';
|
||||
}
|
||||
$debug = isset($extra_options['debug']) ? ($extra_options['debug']) : 0;
|
||||
|
||||
$msgclass = $prefix.'msg';
|
||||
$valclass = $prefix.'val';
|
||||
$decodefunc = 'php_'.$prefix.'_decode';
|
||||
|
||||
$msg = new $msgclass('system.methodSignature');
|
||||
$msg->addparam(new $valclass($methodname));
|
||||
$client->setDebug($debug);
|
||||
$response =& $client->send($msg, $timeout, $protocol);
|
||||
if($response->faultCode())
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve method signature from remote server for method '.$methodname);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$msig = $response->value();
|
||||
if ($client->return_type != 'phpvals')
|
||||
{
|
||||
$msig = $decodefunc($msig);
|
||||
}
|
||||
if(!is_array($msig) || count($msig) <= $signum)
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve method signature nr.'.$signum.' from remote server for method '.$methodname);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pick a suitable name for the new function, avoiding collisions
|
||||
if($newfuncname != '')
|
||||
{
|
||||
$xmlrpcfuncname = $newfuncname;
|
||||
}
|
||||
else
|
||||
{
|
||||
// take care to insure that methodname is translated to valid
|
||||
// php function name
|
||||
$xmlrpcfuncname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
|
||||
array('_', ''), $methodname);
|
||||
}
|
||||
while($buildit && function_exists($xmlrpcfuncname))
|
||||
{
|
||||
$xmlrpcfuncname .= 'x';
|
||||
}
|
||||
|
||||
$msig = $msig[$signum];
|
||||
$mdesc = '';
|
||||
// if in 'offline' mode, get method description too.
|
||||
// in online mode, favour speed of operation
|
||||
if(!$buildit)
|
||||
{
|
||||
$msg = new $msgclass('system.methodHelp');
|
||||
$msg->addparam(new $valclass($methodname));
|
||||
$response =& $client->send($msg, $timeout, $protocol);
|
||||
if (!$response->faultCode())
|
||||
{
|
||||
$mdesc = $response->value();
|
||||
if ($client->return_type != 'phpvals')
|
||||
{
|
||||
$mdesc = $mdesc->scalarval();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results = build_remote_method_wrapper_code($client, $methodname,
|
||||
$xmlrpcfuncname, $msig, $mdesc, $timeout, $protocol, $simple_client_copy,
|
||||
$prefix, $decode_php_objects, $encode_php_objects, $decode_fault,
|
||||
$fault_response);
|
||||
|
||||
//print_r($code);
|
||||
if ($buildit)
|
||||
{
|
||||
$allOK = 0;
|
||||
eval($results['source'].'$allOK=1;');
|
||||
// alternative
|
||||
//$xmlrpcfuncname = create_function('$m', $innercode);
|
||||
if($allOK)
|
||||
{
|
||||
return $xmlrpcfuncname;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap remote method '.$methodname);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$results['function'] = $xmlrpcfuncname;
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to wrap_xmlrpc_method, but will generate a php class that wraps
|
||||
* all xmlrpc methods exposed by the remote server as own methods.
|
||||
* For more details see wrap_xmlrpc_method.
|
||||
* @param xmlrpc_client $client the client obj all set to query the desired server
|
||||
* @param array $extra_options list of options for wrapped code
|
||||
* @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options)
|
||||
*/
|
||||
function wrap_xmlrpc_server($client, $extra_options=array())
|
||||
{
|
||||
$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
|
||||
//$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
|
||||
$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
|
||||
$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
|
||||
$newclassname = isset($extra_options['new_class_name']) ? $extra_options['new_class_name'] : '';
|
||||
$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
|
||||
$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
|
||||
$verbatim_client_copy = isset($extra_options['simple_client_copy']) ? !($extra_options['simple_client_copy']) : true;
|
||||
$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
|
||||
$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
|
||||
|
||||
$msgclass = $prefix.'msg';
|
||||
//$valclass = $prefix.'val';
|
||||
$decodefunc = 'php_'.$prefix.'_decode';
|
||||
|
||||
$msg = new $msgclass('system.listMethods');
|
||||
$response =& $client->send($msg, $timeout, $protocol);
|
||||
if($response->faultCode())
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve method list from remote server');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mlist = $response->value();
|
||||
if ($client->return_type != 'phpvals')
|
||||
{
|
||||
$mlist = $decodefunc($mlist);
|
||||
}
|
||||
if(!is_array($mlist) || !count($mlist))
|
||||
{
|
||||
error_log('XML-RPC: could not retrieve meaningful method list from remote server');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pick a suitable name for the new function, avoiding collisions
|
||||
if($newclassname != '')
|
||||
{
|
||||
$xmlrpcclassname = $newclassname;
|
||||
}
|
||||
else
|
||||
{
|
||||
$xmlrpcclassname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
|
||||
array('_', ''), $client->server).'_client';
|
||||
}
|
||||
while($buildit && class_exists($xmlrpcclassname))
|
||||
{
|
||||
$xmlrpcclassname .= 'x';
|
||||
}
|
||||
|
||||
/// @todo add function setdebug() to new class, to enable/disable debugging
|
||||
$source = "class $xmlrpcclassname\n{\nvar \$client;\n\n";
|
||||
$source .= "function $xmlrpcclassname()\n{\n";
|
||||
$source .= build_client_wrapper_code($client, $verbatim_client_copy, $prefix);
|
||||
$source .= "\$this->client =& \$client;\n}\n\n";
|
||||
$opts = array('simple_client_copy' => 2, 'return_source' => true,
|
||||
'timeout' => $timeout, 'protocol' => $protocol,
|
||||
'encode_php_objs' => $encode_php_objects, 'prefix' => $prefix,
|
||||
'decode_php_objs' => $decode_php_objects
|
||||
);
|
||||
/// @todo build javadoc for class definition, too
|
||||
foreach($mlist as $mname)
|
||||
{
|
||||
if ($methodfilter == '' || preg_match($methodfilter, $mname))
|
||||
{
|
||||
$opts['new_function_name'] = preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
|
||||
array('_', ''), $mname);
|
||||
$methodwrap = wrap_xmlrpc_method($client, $mname, $opts);
|
||||
if ($methodwrap)
|
||||
{
|
||||
if (!$buildit)
|
||||
{
|
||||
$source .= $methodwrap['docstring'];
|
||||
}
|
||||
$source .= $methodwrap['source']."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('XML-RPC: will not create class method to wrap remote method '.$mname);
|
||||
}
|
||||
}
|
||||
}
|
||||
$source .= "}\n";
|
||||
if ($buildit)
|
||||
{
|
||||
$allOK = 0;
|
||||
eval($source.'$allOK=1;');
|
||||
// alternative
|
||||
//$xmlrpcfuncname = create_function('$m', $innercode);
|
||||
if($allOK)
|
||||
{
|
||||
return $xmlrpcclassname;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('XML-RPC: could not create class '.$xmlrpcclassname.' to wrap remote server '.$client->server);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return array('class' => $xmlrpcclassname, 'code' => $source, 'docstring' => '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the necessary info, build php code that creates a new function to
|
||||
* invoke a remote xmlrpc method.
|
||||
* Take care that no full checking of input parameters is done to ensure that
|
||||
* valid php code is emitted.
|
||||
* Note: real spaghetti code follows...
|
||||
* @access private
|
||||
*/
|
||||
function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname,
|
||||
$msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc',
|
||||
$decode_php_objects=false, $encode_php_objects=false, $decode_fault=false,
|
||||
$fault_response='')
|
||||
{
|
||||
$code = "function $xmlrpcfuncname (";
|
||||
if ($client_copy_mode < 2)
|
||||
{
|
||||
// client copy mode 0 or 1 == partial / full client copy in emitted code
|
||||
$innercode = build_client_wrapper_code($client, $client_copy_mode, $prefix);
|
||||
$innercode .= "\$client->setDebug(\$debug);\n";
|
||||
$this_ = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
// client copy mode 2 == no client copy in emitted code
|
||||
$innercode = '';
|
||||
$this_ = 'this->';
|
||||
}
|
||||
$innercode .= "\$msg = new {$prefix}msg('$methodname');\n";
|
||||
|
||||
if ($mdesc != '')
|
||||
{
|
||||
// take care that PHP comment is not terminated unwillingly by method description
|
||||
$mdesc = "/**\n* ".str_replace('*/', '* /', $mdesc)."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdesc = "/**\nFunction $xmlrpcfuncname\n";
|
||||
}
|
||||
|
||||
// param parsing
|
||||
$plist = array();
|
||||
$pcount = count($msig);
|
||||
for($i = 1; $i < $pcount; $i++)
|
||||
{
|
||||
$plist[] = "\$p$i";
|
||||
$ptype = $msig[$i];
|
||||
if($ptype == 'i4' || $ptype == 'int' || $ptype == 'boolean' || $ptype == 'double' ||
|
||||
$ptype == 'string' || $ptype == 'dateTime.iso8601' || $ptype == 'base64' || $ptype == 'null')
|
||||
{
|
||||
// only build directly xmlrpcvals when type is known and scalar
|
||||
$innercode .= "\$p$i = new {$prefix}val(\$p$i, '$ptype');\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($encode_php_objects)
|
||||
{
|
||||
$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i, array('encode_php_objs'));\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i);\n";
|
||||
}
|
||||
}
|
||||
$innercode .= "\$msg->addparam(\$p$i);\n";
|
||||
$mdesc .= '* @param '.xmlrpc_2_php_type($ptype)." \$p$i\n";
|
||||
}
|
||||
if ($client_copy_mode < 2)
|
||||
{
|
||||
$plist[] = '$debug=0';
|
||||
$mdesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
|
||||
}
|
||||
$plist = implode(', ', $plist);
|
||||
$mdesc .= '* @return '.xmlrpc_2_php_type($msig[0])." (or an {$prefix}resp obj instance if call fails)\n*/\n";
|
||||
|
||||
$innercode .= "\$res =& \${$this_}client->send(\$msg, $timeout, '$protocol');\n";
|
||||
if ($decode_fault)
|
||||
{
|
||||
if (is_string($fault_response) && ((strpos($fault_response, '%faultCode%') !== false) || (strpos($fault_response, '%faultString%') !== false)))
|
||||
{
|
||||
$respcode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '".str_replace("'", "''", $fault_response)."')";
|
||||
}
|
||||
else
|
||||
{
|
||||
$respcode = var_export($fault_response, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$respcode = '$res';
|
||||
}
|
||||
if ($decode_php_objects)
|
||||
{
|
||||
$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value(), array('decode_php_objs'));";
|
||||
}
|
||||
else
|
||||
{
|
||||
$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value());";
|
||||
}
|
||||
|
||||
$code = $code . $plist. ") {\n" . $innercode . "\n}\n";
|
||||
|
||||
return array('source' => $code, 'docstring' => $mdesc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given necessary info, generate php code that will rebuild a client object
|
||||
* Take care that no full checking of input parameters is done to ensure that
|
||||
* valid php code is emitted.
|
||||
* @access private
|
||||
*/
|
||||
function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
|
||||
{
|
||||
$code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
|
||||
"', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
|
||||
|
||||
// copy all client fields to the client that will be generated runtime
|
||||
// (this provides for future expansion or subclassing of client obj)
|
||||
if ($verbatim_client_copy)
|
||||
{
|
||||
foreach($client as $fld => $val)
|
||||
{
|
||||
if($fld != 'debug' && $fld != 'return_type')
|
||||
{
|
||||
$val = var_export($val, true);
|
||||
$code .= "\$client->$fld = $val;\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
// only make sure that client always returns the correct data type
|
||||
$code .= "\$client->return_type = '{$prefix}vals';\n";
|
||||
//$code .= "\$client->setDebug(\$debug);\n";
|
||||
return $code;
|
||||
}
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
/* Change to E_ALL for development/debugging */
|
||||
error_reporting (E_ALL);
|
||||
|
||||
/* Database backend, not really tested with other backends, so it's
|
||||
not functional right now */
|
||||
define ('DB_BACKEND', 'mysql');
|
||||
define ('FREE_USER', 'PANDORA-FREE');
|
||||
|
||||
if (! extension_loaded ('mysql'))
|
||||
die ('Your PHP installation appears to be missing the MySQL extension which is required.');
|
||||
|
||||
require_once ('lib/libupdate_manager.php');
|
||||
|
||||
|
||||
function check_keygen ($settings) {
|
||||
global $config;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function get_user_key ($settings) {
|
||||
global $config;
|
||||
global $build_version;
|
||||
global $pandora_version;
|
||||
|
||||
require_once($config["homedir"] . "/extensions/update_manager/debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call get_user_key function.");
|
||||
|
||||
$s = $settings->customer_key;
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
$n = (int) db_get_value ('COUNT(`id_agente`)', 'tagente', 'disabled', 0);
|
||||
$m = (int) db_get_value ('COUNT(`id_agente_modulo`)', 'tagente_modulo', 'disabled', 0);
|
||||
$u = (int) db_get_value ('MAX(UNIX_TIMESTAMP()-UNIX_TIMESTAMP(keepalive))', 'tserver');
|
||||
break;
|
||||
case 'postgresql':
|
||||
$n = (int) db_get_value ('COUNT("id_agente")', 'tagente', 'disabled', 0);
|
||||
$m = (int) db_get_value ('COUNT("id_agente_modulo")', 'tagente_modulo', 'disabled', 0);
|
||||
$u = (int) db_get_value ('MAX(UNIX_TIMESTAMP()-UNIX_TIMESTAMP(keepalive))', 'tserver');
|
||||
break;
|
||||
case 'oracle':
|
||||
$n = (int) db_get_value ('COUNT(id_agente)', 'tagente', 'disabled', 0);
|
||||
$m = (int) db_get_value ('COUNT(id_agente_modulo)', 'tagente_modulo', 'disabled', 0);
|
||||
$u = (int) db_get_value ('MAX(UNIX_TIMESTAMP()-UNIX_TIMESTAMP(keepalive))', 'tserver');
|
||||
break;
|
||||
}
|
||||
$user_key = array ('S' => $s, 'A' => $n, 'U' => $u, 'M' => $m, 'B' => $build_version, 'P' => $pandora_version);
|
||||
|
||||
return json_encode ($user_key);
|
||||
}
|
||||
|
||||
flush ();
|
||||
|
||||
?>
|
|
@ -1,249 +0,0 @@
|
|||
<?php
|
||||
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
return;
|
||||
|
||||
/**
|
||||
* The code for to show in the operation menu entry.
|
||||
*/
|
||||
function main_view() {
|
||||
// Load global vars
|
||||
global $config;
|
||||
|
||||
require_once("update_pandora.php");
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname'], $config['dbport']);
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
$user_key = get_user_key ($settings);
|
||||
|
||||
$buttons = array(
|
||||
'admin' => array(
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gextensions&sec2=extensions/update_manager">' .
|
||||
html_print_image ("images/setup.png",
|
||||
true, array ("title" => __('Update manager'))) .'</a>'));
|
||||
|
||||
ui_print_page_header (__('Update manager'), "images/extensions.png",
|
||||
false, "", false, $buttons);
|
||||
|
||||
if (enterprise_installed()) {
|
||||
if (is_array($user_key)) {
|
||||
if (!$user_key['result']) {
|
||||
ui_print_error_message($user_key['message']);
|
||||
}
|
||||
}
|
||||
main_view_enterprise($settings, $user_key);
|
||||
}
|
||||
else {
|
||||
main_view_open($settings, $user_key);
|
||||
}
|
||||
}
|
||||
|
||||
function main_view_enterprise($settings, $user_key) {
|
||||
global $config;
|
||||
|
||||
require_once("debug.php");
|
||||
|
||||
print_debug_message_trace("Init Call main_view_enterprise function.");
|
||||
|
||||
$update_package = (bool) get_parameter_post ('update_package');
|
||||
|
||||
if ($update_package) {
|
||||
print_debug_message_trace("Enter in update package.");
|
||||
if (enterprise_installed()) {
|
||||
$force = (bool) get_parameter_post ('force_update');
|
||||
|
||||
$success = um_client_upgrade_to_latest ($user_key, $force);
|
||||
/* TODO: Add a new in tnews */
|
||||
|
||||
ui_print_result_message($success,
|
||||
__('Success update to the last package.'),
|
||||
__('Error update to the last package.'));
|
||||
|
||||
//Reload the update manager settings
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
$user_key = get_user_key ($settings);
|
||||
if (is_array($user_key)) {
|
||||
if (!$user_key['result']) {
|
||||
ui_print_error_message($user_key['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui_print_error_message(__('This is an Enterprise feature. Visit %s for more information.', '<a href="http://pandorafms.com">http://pandorafms.com</a>'));
|
||||
}
|
||||
}
|
||||
|
||||
$upload_package = (bool)get_parameter('upload_package');
|
||||
if ($upload_package) {
|
||||
if (!empty($_FILES)) {
|
||||
install_offline_enterprise_package($settings, $user_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo '<h4>';
|
||||
if ($settings->current_update == 0)
|
||||
echo __('You do not have installed any updates of Pandora FMS Enterprise');
|
||||
else
|
||||
echo __('Your Pandora FMS Enterprise version number is') . ' ' .
|
||||
$settings->current_update;
|
||||
echo '</h4>';
|
||||
|
||||
echo "<br><br>";
|
||||
|
||||
|
||||
/* Translators: Do not translade Update Manager, it's the name of the program */
|
||||
ui_print_info_message(
|
||||
'<p>' .
|
||||
__('The new <a href="http://updatemanager.sourceforge.net">Update Manager</a> client is shipped with Pandora FMS It helps system administrators to update their Pandora FMS automatically, since the Update Manager does the task of getting new modules, new plugins and new features (even full migrations tools for future versions) automatically.') .
|
||||
'</p>' .
|
||||
'<p>' .
|
||||
__('Update Manager is one of the most advanced features of Pandora FMS Enterprise version, for more information visit <a href="http://pandorafms.com">http://pandorafms.com</a>.') .
|
||||
'</p>' .
|
||||
'<p>' .
|
||||
__('Update Manager sends anonymous information about Pandora FMS usage (number of agents and modules running). To disable it, remove remote server address from Update Manager plugin setup.') .
|
||||
'</p>');
|
||||
|
||||
|
||||
echo '<h4>' . __('Online') . '</h4>';
|
||||
$table = null;
|
||||
$table->width = '98%';
|
||||
$table->size = array();
|
||||
$table->size[0] = '60%';
|
||||
$table->size[1] = '15%';
|
||||
$table->size[2] = '25%';
|
||||
$table->colspan = array();
|
||||
$table->colspan[0][0] = 3;
|
||||
$table->data = array();
|
||||
$table->data[1][0] = '<span id="box_ajax_checking_online">' .
|
||||
__('Checking for an update') . ' ' . html_print_image('images/spinner.gif', true) .
|
||||
'</span>';
|
||||
$table->data[1][1] = html_print_button(__('Details'),
|
||||
'details_online', true, 'show_details();', 'class="sub search"', true);
|
||||
$table->data[1][2] = __('Force') . ': ' .
|
||||
html_print_checkbox ('force_update', '1', false, true) .
|
||||
html_print_submit_button(__('Update'), 'update_online', true,
|
||||
'class="sub upd"', true);
|
||||
|
||||
echo '<form method="post">';
|
||||
html_print_input_hidden ('update_package', 1);
|
||||
html_print_table($table);
|
||||
echo '</form>';
|
||||
|
||||
|
||||
|
||||
?>
|
||||
<div id="dialog" title="<?php echo __('Details packge'); ?>"
|
||||
style="display: none;">
|
||||
<div style="position:absolute; top:20%; text-align: center; left: 0%; right: 0%; width: 600px;">
|
||||
<div id="dialog_version_package" style="margin-left: 40px; margin-bottom: 20px; text-align: left;">
|
||||
</div>
|
||||
<div id="dialog_description" style="margin-left: 40px; text-align: left; height: 250px; width: 550px; overflow: auto;">
|
||||
</div>
|
||||
<div id="button_close" style="position: absolute; top:280px; right:43%;">
|
||||
<?php
|
||||
html_print_submit_button(__("Close"),
|
||||
'hide_dialog', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only" style="width:100px;"');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
|
||||
echo '<h4>' . __('Offline') . '</h4>';
|
||||
$table = null;
|
||||
$table->width = '98%';
|
||||
$table->data = array();
|
||||
$table->data[1][0] = '<h5>'.__('Offline packages loader'). ' ' . ui_print_help_tip (__('Apply, in order, the packets corresponding to your current version'), true) . '</h5>' .
|
||||
'<input type="hidden" name="upload_package" value="1">' .
|
||||
'<input type="file" size="55" name="fileloaded">' .
|
||||
' <input class="sub next" type="submit" name="upload_button" value="' . __('Upload') . '">';
|
||||
|
||||
echo '<form method="post" enctype="multipart/form-data">';
|
||||
html_print_table($table);
|
||||
echo '</form>';
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#submit-hide_dialog").click (function () {
|
||||
$("#dialog" ).dialog('close');
|
||||
});
|
||||
|
||||
ajax_checking_online_enterprise_package();
|
||||
});
|
||||
|
||||
function show_details() {
|
||||
$("#dialog").dialog({
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
height: 430,
|
||||
width: 630,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
$("#dialog").show();
|
||||
}
|
||||
|
||||
function ajax_checking_online_enterprise_package() {
|
||||
var parameters = {};
|
||||
parameters['page'] = 'extensions/update_manager';
|
||||
parameters['checking_online_enterprise_package'] = 1;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
$("#box_ajax_checking_online").html(data['text']);
|
||||
$("#dialog_version_package").html(data['version_package_text']);
|
||||
$("#dialog_description").html(data['details_text']);
|
||||
|
||||
if (data['enable_buttons']) {
|
||||
$("input[name='details_online']").removeAttr("disabled");
|
||||
$("input[name='update_online']").removeAttr("disabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
|
||||
print_debug_message_trace("End Call main_view_enterprise function.");
|
||||
}
|
||||
|
||||
function main_view_open($settings, $user_key) {
|
||||
global $config;
|
||||
|
||||
update_pandora_administration($settings, $user_key);
|
||||
}
|
||||
?>
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// 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.
|
||||
|
||||
// Load global vars
|
||||
global $config;
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config['id_user'], 0, 'PM')) {
|
||||
db_pandora_audit("ACL Violation", "Trying to use Open Update Manager extension");
|
||||
include ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
include_once ("extensions/update_manager/lib/functions.php");
|
||||
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname'], $config['dbport']);
|
||||
|
||||
$update_settings = (bool) get_parameter_post ('update_settings');
|
||||
|
||||
$buttons = array(
|
||||
'admin' => array(
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=extensions&sec2=extensions/update_manager">' .
|
||||
html_print_image ("images/operation.png",
|
||||
true, array ("title" => __('Update manager'))) .'</a>'));
|
||||
|
||||
ui_print_page_header (__('Update manager').' - '. __('Settings'),
|
||||
"images/extensions.png", false, "", true, $buttons);
|
||||
|
||||
if ($update_settings) {
|
||||
foreach ($_POST['keys'] as $key => $value) {
|
||||
um_db_update_setting ($key, $value);
|
||||
}
|
||||
|
||||
if (!enterprise_installed()) {
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
$conf_update_pandora['download_mode'] =
|
||||
get_parameter('download_mode', 'curl');
|
||||
|
||||
update_pandora_update_conf();
|
||||
}
|
||||
|
||||
ui_print_success_message(__('Update manager settings updated'));
|
||||
}
|
||||
|
||||
$settings = null;
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
echo '<form method="post">';
|
||||
|
||||
$table->width = '95%';
|
||||
$table->data = array ();
|
||||
|
||||
$table->data[0][0] = '<strong>'.__('Update server host').'</strong>';
|
||||
$table->data[0][1] = html_print_input_text ('keys[update_server_host]', $settings->update_server_host, '', 20, 255, true);
|
||||
|
||||
$table->data[1][0] = '<strong>'.__('Update server path').'</strong>';
|
||||
$table->data[1][1] = html_print_input_text ('keys[update_server_path]', $settings->update_server_path, '', 40, 255, true);
|
||||
|
||||
$table->data[2][0] = '<strong>'.__('Update server port').'</strong>';
|
||||
$table->data[2][1] = html_print_input_text ('keys[update_server_port]', $settings->update_server_port, '', 5, 5, true);
|
||||
|
||||
$table->data[3][0] = '<strong>'.__('Proxy server').'</strong>';
|
||||
$table->data[3][1] = html_print_input_text ('keys[proxy]', $settings->proxy, '', 40, 255, true);
|
||||
|
||||
$table->data[4][0] = '<strong>'.__('Proxy port').'</strong>';
|
||||
$table->data[4][1] = html_print_input_text ('keys[proxy_port]', $settings->proxy_port, '', 40, 255, true);
|
||||
|
||||
$table->data[5][0] = '<strong>'.__('Proxy user').'</strong>';
|
||||
$table->data[5][1] = html_print_input_text ('keys[proxy_user]', $settings->proxy_user, '', 40, 255, true);
|
||||
|
||||
$table->data[6][0] = '<strong>'.__('Proxy password').'</strong>';
|
||||
$table->data[6][1] = html_print_input_password ('keys[proxy_pass]', $settings->proxy_pass, '', 40, 255, true);
|
||||
|
||||
if (!enterprise_installed()) {
|
||||
global $conf_update_pandora;
|
||||
if (empty($conf_update_pandora))
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
$methods = array(
|
||||
'wget' => __('WGET, no interactive, external command, fast'),
|
||||
'curl' =>__('CURL, interactive, internal command, slow'));
|
||||
|
||||
$table->data[10][0] = '<strong>' . __('Download Method') . '</strong>';
|
||||
$table->data[10][1] = html_print_select($methods,
|
||||
'download_mode', $conf_update_pandora['download_mode'], '', '',
|
||||
0, true);
|
||||
}
|
||||
|
||||
html_print_table ($table);
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
html_print_input_hidden ('update_settings', 1);
|
||||
html_print_submit_button (__('Update'), 'update_button', false, 'class="sub upd"');
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
|
||||
?>
|
|
@ -1,28 +0,0 @@
|
|||
CREATE TABLE tupdate_settings ( key VARCHAR2(255) default '' PRIMARY KEY, value VARCHAR2(255) default '')
|
||||
/INSERT INTO tupdate_settings VALUES ('current_update', '412')
|
||||
/INSERT INTO tupdate_settings VALUES ('customer_key', 'PANDORA-FREE')
|
||||
/INSERT INTO tupdate_settings VALUES ('update_server_host', 'www.artica.es')
|
||||
/INSERT INTO tupdate_settings VALUES ('update_server_port', '80')
|
||||
/INSERT INTO tupdate_settings VALUES ('update_server_path', '/pandoraupdate4/server.php')
|
||||
/INSERT INTO tupdate_settings VALUES ('updating_binary_path', 'Path where the updated binary files will be stored')
|
||||
/INSERT INTO tupdate_settings VALUES ('updating_code_path', 'Path where the updated code is stored')
|
||||
/INSERT INTO tupdate_settings VALUES ('dbname', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('dbhost', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('dbpass', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('dbuser', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('dbport', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('proxy', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('proxy_port', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('proxy_user', '')
|
||||
/INSERT INTO tupdate_settings VALUES ('proxy_pass', '')
|
||||
CREATE TABLE tupdate_package( id NUMBER(10, 0) NOT NULL PRIMARY KEY, timestamp TIMESTAMP default NULL, description VARCHAR2(255) default '')
|
||||
CREATE SEQUENCE tupdate_package_s INCREMENT BY 1 START WITH 1
|
||||
CREATE OR REPLACE TRIGGER tupdate_package_inc BEFORE INSERT ON tupdate_package REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tupdate_package_s.nextval INTO :NEW.ID FROM dual; END;
|
||||
CREATE TABLE tupdate ( id NUMBER(10, 0) NOT NULL PRIMARY KEY, type VARCHAR2(15), id_update_package NUMBER(10, 0) default 0 REFERENCES tupdate_package(id) ON DELETE CASCADE, filename VARCHAR2(250) default '', checksum VARCHAR2(250) default '', previous_checksum VARCHAR2(250) default '', svn_version NUMBER(10, 0) default 0, data CLOB default '', data_rollback CLOB default '', description CLOB default '', db_table_name VARCHAR2(140) default '', db_field_name VARCHAR2(140) default '', db_field_value VARCHAR2(1024) default '', CONSTRAINT tupdate_type_cons CHECK (type IN ('code', 'db_data', 'db_schema', 'binary')))
|
||||
CREATE OR REPLACE TRIGGER tupdate_update AFTER UPDATE OF ID ON tupdate_package FOR EACH ROW BEGIN UPDATE tupdate SET ID_UPDATE_PACKAGE = :NEW.ID WHERE ID_UPDATE_PACKAGE = :OLD.ID; END;
|
||||
CREATE SEQUENCE tupdate_s INCREMENT BY 1 START WITH 1
|
||||
CREATE OR REPLACE TRIGGER tupdate_inc BEFORE INSERT ON tupdate REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tupdate_s.nextval INTO :NEW.ID FROM dual; END;
|
||||
CREATE TABLE tupdate_journal ( id NUMBER(10, 0) NOT NULL PRIMARY KEY, id_update NUMBER(10, 0) default 0 REFERENCES tupdate(id) ON DELETE CASCADE)
|
||||
CREATE SEQUENCE tupdate_journal_s INCREMENT BY 1 START WITH 1
|
||||
CREATE OR REPLACE TRIGGER tupdate_journal_inc BEFORE INSERT ON tupdate_journal REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tupdate_journal_s.nextval INTO :NEW.ID FROM dual; END;
|
||||
CREATE OR REPLACE TRIGGER tupdate_journal_update AFTER UPDATE OF ID ON tupdate FOR EACH ROW BEGIN UPDATE tupdate_journal SET ID = :NEW.ID WHERE ID = :OLD.ID; END;
|
|
@ -1,6 +0,0 @@
|
|||
CREATE TABLE "tupdate_settings" ( "key" varchar(255) default '' PRIMARY KEY, "value" varchar(255) default '');
|
||||
INSERT INTO "tupdate_settings" VALUES ('current_update', '412'), ('customer_key', 'PANDORA-FREE'), ('update_server_host', 'www.artica.es'), ('update_server_port', '80'), ('update_server_path', '/pandoraupdate4/server.php'), ('updating_binary_path', 'Path where the updated binary files will be stored'), ('updating_code_path', 'Path where the updated code is stored'), ('dbname', ''), ('dbhost', ''), ('dbpass', ''), ('dbuser', ''), ('dbport', ''), ('proxy', ''), ('proxy_port', ''), ('proxy_user', ''), ('proxy_pass', '');
|
||||
CREATE TABLE "tupdate_package"( "id" SERIAL NOT NULL PRIMARY KEY, "timestamp" TIMESTAMP without time zone default NULL, "description" varchar(255) default '');
|
||||
CREATE TYPE type_tupdate_type AS ENUM ('code', 'db_data', 'db_schema', 'binary');
|
||||
CREATE TABLE "tupdate" ( "id" SERIAL NOT NULL PRIMARY KEY, "type" type_tupdate_type, "id_update_package" INTEGER default 0 REFERENCES "tupdate_package"("id") ON UPDATE CASCADE ON DELETE CASCADE, "filename" varchar(250) default '', "checksum" varchar(250) default '', "previous_checksum" varchar(250) default '', "svn_version" INTEGER default 0, "data" TEXT default '', "data_rollback" TEXT default '', "description" TEXT default '', "db_table_name" varchar(140) default '', "db_field_name" varchar(140) default '', "db_field_value" varchar(1024) default '');
|
||||
CREATE TABLE "tupdate_journal" ( "id" SERIAL NOT NULL PRIMARY KEY, "id_update" INTEGER default 0 REFERENCES "tupdate"("id") ON UPDATE CASCADE ON DELETE CASCADE);
|
|
@ -1,7 +0,0 @@
|
|||
CREATE TABLE `tupdate_settings` ( `key` varchar(255) default '', `value` varchar(255) default '', PRIMARY KEY (`key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
INSERT INTO `tupdate_settings` VALUES ('current_update', '412'), ('customer_key', 'PANDORA-FREE'), ('update_server_host', 'www.artica.es'), ('update_server_port', '80'), ('update_server_path', '/pandoraupdate4/server.php'), ('updating_binary_path', 'Path where the updated binary files will be stored'), ('updating_code_path', 'Path where the updated code is stored'), ('dbname', ''), ('dbhost', ''), ('dbpass', ''), ('dbuser', ''), ('dbport', ''), ('proxy', ''), ('proxy_port', ''), ('proxy_user', ''), ('proxy_pass', '');
|
||||
CREATE TABLE `tupdate_package` ( id int(11) unsigned NOT NULL auto_increment, timestamp datetime NOT NULL, description varchar(255) default '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
CREATE TABLE `tupdate` ( id int(11) unsigned NOT NULL auto_increment, type enum('code', 'db_data', 'db_schema', 'binary'), id_update_package int(11) unsigned NOT NULL default 0, filename varchar(250) default '', checksum varchar(250) default '', previous_checksum varchar(250) default '', svn_version int(4) unsigned NOT NULL default 0, data LONGTEXT default '', data_rollback LONGTEXT default '', description TEXT default '', db_table_name varchar(140) default '', db_field_name varchar(140) default '', db_field_value varchar(1024) default '', PRIMARY KEY (`id`), FOREIGN KEY (`id_update_package`) REFERENCES tupdate_package(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
CREATE TABLE `tupdate_journal` ( id int(11) unsigned NOT NULL auto_increment, id_update int(11) unsigned NOT NULL default 0, PRIMARY KEY (`id`), FOREIGN KEY (`id_update`) REFERENCES tupdate(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
UPDATE tupdate_settings SET `value` = 412 WHERE `key`= 'current_update';
|
|
@ -1,199 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// 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.
|
||||
|
||||
require_once('lib/functions.php');
|
||||
|
||||
if (is_ajax ()) {
|
||||
global $config;
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('lib/functions.ajax.php');
|
||||
|
||||
$get_packages_online = (bool) get_parameter('get_packages_online');
|
||||
$download_package = (bool) get_parameter('download_package');
|
||||
$check_download_package = (bool) get_parameter('check_download_package');
|
||||
$install_package = (bool) get_parameter('install_package');
|
||||
$check_install_package = (bool) get_parameter('check_install_package');
|
||||
|
||||
if ($get_packages_online)
|
||||
update_pandora_get_packages_online_ajax();
|
||||
if ($download_package)
|
||||
update_pandora_download_package();
|
||||
if ($check_download_package)
|
||||
update_pandora_check_download_package();
|
||||
if ($install_package)
|
||||
update_pandora_install_package();
|
||||
if ($check_install_package)
|
||||
update_pandora_check_install_package();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function update_pandora_administration($settings, $user_key) {
|
||||
global $config;
|
||||
global $conf_update_pandora;
|
||||
|
||||
require_once("include/functions_graph.php");
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!update_pandora_check_installation()) {
|
||||
ui_print_error_message(__('First execution of Update Pandora'));
|
||||
update_pandora_installation();
|
||||
}
|
||||
|
||||
$delete_package = (bool)get_parameter('delete_package');
|
||||
if ($delete_package) {
|
||||
$package = get_parameter('package');
|
||||
|
||||
$dir = $config['attachment_store'] . '/update_pandora/';
|
||||
|
||||
$result = unlink($dir . $package);
|
||||
}
|
||||
|
||||
$conf_update_pandora = update_pandora_get_conf();
|
||||
|
||||
if (!empty($conf_update_pandora['last_installed'])){
|
||||
echo '<h4>';
|
||||
echo __('Your Pandora FMS open source package installed is') .
|
||||
' ' . $conf_update_pandora['last_installed'];
|
||||
echo "</h4>";
|
||||
}
|
||||
else {
|
||||
echo '<h4>';
|
||||
echo __('Your Pandora FMS does not have any update installed yet');
|
||||
echo "</h4>";
|
||||
}
|
||||
|
||||
echo "<br><br>";
|
||||
|
||||
ui_print_info_message(
|
||||
'<p>' .
|
||||
__('This is a automatilly update Pandora Console only. Be careful if you have changed any php file of console, please make a backup this modified files php. Because the update action ovewrite all php files in Pandora console.') .
|
||||
'</p>' .
|
||||
'<p>' .
|
||||
__('Update Manager sends anonymous information about Pandora FMS usage (number of agents and modules running). To disable it, just delete extension or remove remote server address from Update Manager plugin setup.') .
|
||||
'</p>'
|
||||
);
|
||||
|
||||
echo "<h4>". __('Online') . '</h4>';
|
||||
|
||||
echo '<table id="online_packages" class="databox" width="95%" cellspacing="4" cellpadding="4" border="0" style="">' .
|
||||
'<tbody>
|
||||
<tr id="online_packages-0" class="spinner_row" style="">
|
||||
<td id="online_packages-0-0" style=" text-align:left; width:80%;">' .
|
||||
__('Get list online Package') . " " . html_print_image('images/spinner.gif', true) .
|
||||
'</td>
|
||||
<td id="online_packages-0-1" style=" text-align:center; width:50px;"></td>
|
||||
</tr>
|
||||
</tbody>' .
|
||||
'</table>';
|
||||
|
||||
?>
|
||||
<div id="dialog_download" title="<?php echo __('Processing package'); ?>"
|
||||
style="display:none;">
|
||||
<div style="position:absolute; top:10%; text-align: center; left:0%; right:0%; width:600px;">
|
||||
<?php
|
||||
echo '<h4 id="title_downloading_update_pandora">' . __('Downloading <span class="package_name">package</span> in progress') . " ";
|
||||
html_print_image('images/spinner.gif');
|
||||
echo '</h4>';
|
||||
echo '<h4 style="display: none;" id="title_downloaded_update_pandora">' . __('Downloaded <span class="package_name">package</span>') . '</h2>';
|
||||
echo '<h4 style="display: none;" id="title_installing_update_pandora">' . __('Installing <span class="package_name">package</span> in progress') . " ";
|
||||
html_print_image('images/spinner.gif');
|
||||
echo '</h4>';
|
||||
echo '<h4 style="display: none;" id="title_installed_update_pandora">' . __('Installed <span class="package_name">package</span> in progress') . '</h2>';
|
||||
echo '<h4 style="display: none;" id="title_error_update_pandora">' . __('Fail download <span class="package_name">package</span>') . '</h2>';
|
||||
echo '<br /><br />';
|
||||
echo "<div id='progress_bar_img'>";
|
||||
echo progress_bar(0, 300, 20, 0 . '%', 1, false, "#00ff00");
|
||||
echo "</div>";
|
||||
|
||||
echo "<div style='padding-top: 10px; display: none;' id='info_text'>
|
||||
<b>Size:</b> 666/666 kbytes <b>Speed:</b> 666 bytes/second
|
||||
</div>";
|
||||
|
||||
?>
|
||||
<div id="button_close_download_disabled" style="position: absolute; top:280px; right:43%;">
|
||||
<?php
|
||||
html_print_submit_button(__("Close"), 'hide_download_disabled_dialog', true, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only" style="width:100px;"');
|
||||
?>
|
||||
</div>
|
||||
<div id="button_close_download" style="display: none; position: absolute; top:280px; right:43%;">
|
||||
<?php
|
||||
html_print_submit_button(__("Close"), 'hide_download_dialog', false, 'class="ui-button-dialog ui-widget ui-state-default ui-corner-all ui-button-text-only" style="width:100px;"');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
echo '<h4>' . __('Downloaded Packages') . '</h4>';
|
||||
$tableMain = null;
|
||||
$tableMain->width = '95%';
|
||||
$tableMain->data = array();
|
||||
|
||||
$list_downloaded_packages = update_pandora_get_list_downloaded_packages('administration');
|
||||
if (empty($list_downloaded_packages))
|
||||
$list_downloaded_packages = array();
|
||||
$table = null;
|
||||
$table->width = '100%';
|
||||
$table->size = array('50%', '25%', '25%');
|
||||
$table->align = array('left', 'center');
|
||||
$table->data = array();
|
||||
foreach ($list_downloaded_packages as $package) {
|
||||
$actions = '';
|
||||
if (!isset($package['empty'])) {
|
||||
if (!$package['current']) {
|
||||
$actions = html_print_button(__('Install'),
|
||||
'install_' . uniqid(), false,
|
||||
'ajax_start_install_package(\'' . $package['name'] . '\');',
|
||||
'class="sub next" style="width: 40%;"', true);
|
||||
}
|
||||
else {
|
||||
$actions = html_print_button(__('Reinstall'),
|
||||
'reinstall_' . uniqid(), false,
|
||||
'ajax_start_install_package(\'' . $package['name'] . '\');',
|
||||
'class="sub upd" style="width: 40%;"', true);
|
||||
}
|
||||
$actions .= ' ' . html_print_button(__('Delete'),
|
||||
'delete' . uniqid(), false,
|
||||
'delete_package(\'' . $package['name'] . '\');',
|
||||
'class="sub delete" style="width: 40%;"', true);
|
||||
}
|
||||
$table->data[] = array($package['name'], $package['time'], $actions);
|
||||
}
|
||||
$tableMain->data[1][0] = html_print_table($table, true);
|
||||
|
||||
html_print_table($tableMain);
|
||||
|
||||
update_pandora_print_javascript_admin();
|
||||
}
|
||||
?>
|
|
@ -218,14 +218,12 @@ if (check_acl ($config['id_user'], 0, "PM")) {
|
|||
$sub["godmode/setup/os"]["text"] = __('Edit OS');
|
||||
$sub["godmode/setup/license"]["text"] = __('License');
|
||||
|
||||
$sub["godmode/update_manager_xxx/update_manager_xxx"]["text"] = __('xxxx');
|
||||
$sub["godmode/update_manager/update_manager"]["text"] = __('Update manager');
|
||||
|
||||
enterprise_hook ('enterprise_acl_submenu');
|
||||
enterprise_hook ('skins_submenu');
|
||||
$sub["extras/pandora_diag"]["text"] = __('Diagnostic info');
|
||||
|
||||
$sub["extensions/update_manager"]["text"] = __('Update manager');
|
||||
|
||||
$menu_godmode["gsetup"]["sub"] = $sub;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
global $config;
|
||||
|
||||
ui_require_css_file('update_manager', 'godmode/update_manager_xxx/');
|
||||
ui_require_css_file('update_manager', 'godmode/update_manager/');
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
global $config;
|
||||
|
||||
ui_require_css_file('update_manager', 'godmode/update_manager_xxx/');
|
||||
ui_require_css_file('update_manager', 'godmode/update_manager/');
|
||||
require_once("include/functions_update_manager.php");
|
||||
enterprise_include_once("include/functions_update_manager.php");
|
||||
|
|
@ -24,15 +24,15 @@ $tab = get_parameter('tab', 'online');
|
|||
$buttons = array(
|
||||
'setup' => array(
|
||||
'active' => ($tab == 'setup') ? true : false,
|
||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager_xxx/update_manager_xxx&tab=setup">' .
|
||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager_xxx&tab=setup">' .
|
||||
html_print_image ("images/gm_setup.png", true, array ("title" => __('Options'))) .'</a>'),
|
||||
'offline' => array(
|
||||
'active' => ($tab == 'offline') ? true : false,
|
||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager_xxx/update_manager_xxx&tab=offline">' .
|
||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager_xxx&tab=offline">' .
|
||||
html_print_image ("images/box.disabled.png", true, array ("title" => __('Offline update manager'))) .'</a>'),
|
||||
'online' => array(
|
||||
'active' => ($tab == 'online') ? true : false,
|
||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager_xxx/update_manager_xxx&tab=online">' .
|
||||
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager_xxx&tab=online">' .
|
||||
html_print_image("images/op_gis.png", true, array ("title" => __('Online update manager'))) .'</a>')
|
||||
);
|
||||
|
|
@ -30,7 +30,7 @@ if ($action_update_url_update_manager) {
|
|||
__('Unsuccesful Update the url config vars.'));
|
||||
}
|
||||
|
||||
echo '<form method="post" action="index.php?sec=gsetup&sec2=godmode/update_manager_xxx/update_manager_xxx&tab=setup">';
|
||||
echo '<form method="post" action="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager_xxx&tab=setup">';
|
||||
$table = null;
|
||||
$table->width = '98%';
|
||||
|
|
@ -1309,36 +1309,6 @@ function config_check () {
|
|||
}
|
||||
}
|
||||
|
||||
if (enterprise_installed()) {
|
||||
if ($config['update_manager_installed'] == 1) {
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname'], $config['dbport']);
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$result_check_keygen = check_keygen($settings);
|
||||
|
||||
if (!empty($result_check_keygen)) {
|
||||
$config["alert_cnt"]++;
|
||||
$_SESSION["alert_msg"] .= $result_check_keygen;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($config['update_manager_installed'])) {
|
||||
if ($config['update_manager_installed'] == 1) {
|
||||
require_once("extensions/update_manager/lib/functions.ajax.php");
|
||||
|
||||
$result_check_keygen = check_keygen_online();
|
||||
|
||||
if (!empty($result_check_keygen)) {
|
||||
$config["alert_cnt"]++;
|
||||
$_SESSION["alert_msg"] .= $result_check_keygen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PHP configuration values
|
||||
$PHPupload_max_filesize = config_return_in_bytes(ini_get('upload_max_filesize'));
|
||||
$PHPmax_input_time = ini_get('max_input_time');
|
||||
|
|
Loading…
Reference in New Issue