2011-03-10 Sergio Martin <sergio.martin@artica.es>
* extensions/update_manager/sql/update_manager.sql extensions/update_manager/load_updatemanager.php extensions/update_manager/lib/load_updatemanager.php extensions/update_manager/lib/xmlrpc extensions/update_manager/lib/xmlrpc/xmlrpcs.inc extensions/update_manager/lib/xmlrpc/xmlrpc_wrappers.inc extensions/update_manager/lib/xmlrpc/xmlrpc.inc extensions/update_manager/lib/libupdate_manager_client.php extensions/update_manager/lib/libupdate_manager.php extensions/update_manager/lib/libupdate_manager_utils.php extensions/update_manager/lib/libupdate_manager_components.php extensions/update_manager/lib/libupdate_manager_updates.php extensions/update_manager/settings.php extensions/update_manager/main.php: Upgraded the open update manager client to v2. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4082 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
2dec070b79
commit
12cc101b7a
|
@ -1,3 +1,21 @@
|
|||
2011-03-10 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* extensions/update_manager/sql/update_manager.sql
|
||||
extensions/update_manager/load_updatemanager.php
|
||||
extensions/update_manager/lib/load_updatemanager.php
|
||||
extensions/update_manager/lib/xmlrpc
|
||||
extensions/update_manager/lib/xmlrpc/xmlrpcs.inc
|
||||
extensions/update_manager/lib/xmlrpc/xmlrpc_wrappers.inc
|
||||
extensions/update_manager/lib/xmlrpc/xmlrpc.inc
|
||||
extensions/update_manager/lib/libupdate_manager_client.php
|
||||
extensions/update_manager/lib/libupdate_manager.php
|
||||
extensions/update_manager/lib/libupdate_manager_utils.php
|
||||
extensions/update_manager/lib/libupdate_manager_components.php
|
||||
extensions/update_manager/lib/libupdate_manager_updates.php
|
||||
extensions/update_manager/settings.php
|
||||
extensions/update_manager/main.php: Upgraded the open update
|
||||
manager client to v2.
|
||||
|
||||
2011-03-09 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* ChangeLog: fixed date of one my previous commit.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -19,9 +19,8 @@ function load_update_manager_lib () {
|
|||
|
||||
function update_settings_database_connection () {
|
||||
global $config;
|
||||
global $db;
|
||||
|
||||
$db =& um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname']);
|
||||
um_db_update_setting ('dbname', $config['dbname']);
|
||||
um_db_update_setting ('dbuser', $config['dbuser']);
|
||||
|
@ -31,7 +30,6 @@ function update_settings_database_connection () {
|
|||
|
||||
function pandora_update_manager_install () {
|
||||
global $config;
|
||||
global $db;
|
||||
|
||||
if (isset ($config['update_manager_installed']))
|
||||
/* Already installed */
|
||||
|
@ -50,7 +48,7 @@ function pandora_update_manager_install () {
|
|||
VALUES ("update_manager_installed", 1)';
|
||||
process_sql ($sql);
|
||||
|
||||
$db =& um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname']);
|
||||
um_db_update_setting ('updating_code_path',
|
||||
dirname ($_SERVER['SCRIPT_FILENAME']));
|
||||
|
@ -67,7 +65,6 @@ function pandora_update_manager_uninstall () {
|
|||
|
||||
function pandora_update_manager_main () {
|
||||
global $config;
|
||||
global $db;
|
||||
|
||||
if (! check_acl($config['id_user'], 0, "PM")) {
|
||||
require ("general/noaccess.php");
|
||||
|
@ -82,7 +79,6 @@ function pandora_update_manager_main () {
|
|||
|
||||
function pandora_update_manager_login () {
|
||||
global $config;
|
||||
global $db;
|
||||
|
||||
// If first time, make the first autoupdate and disable it in DB
|
||||
if (!isset($config["autoupdate"])){
|
||||
|
@ -96,17 +92,17 @@ function pandora_update_manager_login () {
|
|||
|
||||
load_update_manager_lib ();
|
||||
|
||||
$db =& um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname']);
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$user_key = get_user_key ($settings);
|
||||
|
||||
|
||||
$package = um_client_check_latest_update ($settings, $user_key);
|
||||
|
||||
if (is_object ($package)) {
|
||||
echo '<div class="notify">';
|
||||
echo print_image("images/information.png", true, array("alt" => 'info'));
|
||||
echo '<img src="images/information.png" alt="info" /> ';
|
||||
echo __('There\'s a new update for Pandora');
|
||||
echo '. <a href="index.php?sec=extensions&sec2=extensions/update_manager">';
|
||||
echo __('More info');
|
||||
|
@ -117,7 +113,6 @@ function pandora_update_manager_login () {
|
|||
|
||||
function pandora_update_manager_godmode () {
|
||||
global $config;
|
||||
global $db;
|
||||
|
||||
load_update_manager_lib ();
|
||||
|
||||
|
@ -134,6 +129,8 @@ if(isset($config['id_user'])) {
|
|||
}
|
||||
}
|
||||
|
||||
pandora_update_manager_install ();
|
||||
|
||||
$db = NULL;
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -11,49 +11,8 @@
|
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
|
||||
/* PEAR DB manage abstraction */
|
||||
$prev_level = error_reporting (0);
|
||||
if ((include_once ('DB.php')) != 1)
|
||||
die ('
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Pandora FMS - The Flexible Monitoring System - Console error</title>
|
||||
<meta http-equiv="expires" content="0">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf8">
|
||||
<meta name="resource-type" content="document">
|
||||
<meta name="distribution" content="global">
|
||||
<meta name="author" content="Sancho Lerena">
|
||||
<meta name="copyright" content="This is GPL software. Created by Sancho Lerena and others">
|
||||
<meta name="keywords" content="pandora, monitoring, system, GPL, software">
|
||||
<meta name="robots" content="index, follow">
|
||||
<link rel="icon" href="images/pandora.ico" type="image/ico">
|
||||
<link rel="stylesheet" href="include/styles/pandora.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="main" style="float:left; margin-left: 100px">
|
||||
<div align="center">
|
||||
<div id="login_f">
|
||||
<h1 id="log_f" class="error">PEAR::DB not found</h1>
|
||||
<div>
|
||||
<img src="images/pandora_logo.png" border="0"></a>
|
||||
</div>
|
||||
<div class="msg">
|
||||
<span class="error"><b>ERROR:</b> PEAR::DB not found</span>
|
||||
<p>
|
||||
Please install it from command line with:
|
||||
<pre>sudo pear install DB</pre>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
');
|
||||
|
||||
error_reporting ($prev_level);
|
||||
unset ($prev_level);
|
||||
if (! defined ('DB_PREFIX'))
|
||||
define ('DB_PREFIX', '');
|
||||
|
||||
require_once ('libupdate_manager_utils.php');
|
||||
require_once ('libupdate_manager_updates.php');
|
||||
|
@ -61,259 +20,287 @@ require_once ('libupdate_manager_components.php');
|
|||
require_once ('libupdate_manager_client.php');
|
||||
|
||||
function um_db_load_settings () {
|
||||
global $db;
|
||||
|
||||
$result =& $db->query ('SELECT * FROM tupdate_settings');
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql('SELECT * FROM '.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 = '';
|
||||
while ($result->fetchInto ($setting)) {
|
||||
$key = $setting->key;
|
||||
$settings->$key = $setting->value;
|
||||
foreach($result as $field) {
|
||||
$settings->$field['key'] = $field['value'];
|
||||
}
|
||||
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
function um_db_update_setting ($key, $value = '') {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT COUNT(*) e FROM tupdate_settings WHERE `key` = ?');
|
||||
$result =& $db->execute ($sql, $key);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = get_db_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '`key`', $key);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error reading settings</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result->fetchInto ($exists);
|
||||
$values = array ($value, $key);
|
||||
if ($exists->e) {
|
||||
$sql =& $db->prepare ('UPDATE tupdate_settings SET value = ? WHERE `key` = ?');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
if($result > 0) {
|
||||
$result = process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('`key`' => $key));
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error updating settings</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_settings (value, `key`) VALUES (?, ?)');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql_insert(DB_PREFIX.'tupdate_settings', array('`key`' => $key, '`value`' => $value));
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating settings</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_latest_public_package ($id_package = '0') {
|
||||
global $db;
|
||||
|
||||
$values = array ('public', $id_package);
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_package WHERE status = ? AND id > ? ORDER BY id DESC LIMIT 1');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$result->fetchInto ($package);
|
||||
|
||||
return $package;
|
||||
}
|
||||
function um_db_get_latest_package_by_status ($id_package = '0', $status = 'public') {
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_package WHERE status = "'.$status.'" AND id > ' . $id_package . ' ORDER BY id DESC LIMIT 1');
|
||||
|
||||
function um_db_get_latest_development_package ($id_package = '0') {
|
||||
global $db;
|
||||
|
||||
$values = array ('development', $id_package);
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_package WHERE status = ? AND id > ? ORDER BY id DESC LIMIT 1');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
if($result === false) {
|
||||
echo '<strong>Error reading latest package with status ' . $status . '</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$result->fetchInto ($package);
|
||||
|
||||
$result = 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) {
|
||||
global $db;
|
||||
|
||||
$values = array ('public', $id_package);
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_package WHERE status = ? AND id > ? ORDER BY id ASC LIMIT 1');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$result->fetchInto ($package);
|
||||
|
||||
$package = um_db_get_latest_package_by_status ($id_package, $status = 'public');
|
||||
|
||||
if (! $package && $development) {
|
||||
$values = array ('development', $id_package);
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_package WHERE status = ? AND id > ? ORDER BY id ASC LIMIT 1');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return false;
|
||||
}
|
||||
$result->fetchInto ($package);
|
||||
$package = um_db_get_latest_package_by_status ($id_package, $status = 'development');
|
||||
}
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
function um_db_create_package ($description = '') {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_package (description) VALUES (?)');
|
||||
$result =& $db->execute ($sql, $description);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = 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') {
|
||||
global $db;
|
||||
|
||||
$values = array ($description, $status, $id_package);
|
||||
|
||||
$sql =& $db->prepare ('UPDATE tupdate_package SET description = ?, status = ? WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$values = array ('description' => $description, 'status' => $status);
|
||||
$where = array ('id' => $id_package);
|
||||
|
||||
$result = 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) {
|
||||
global $db;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$sql =& $db->prepare ('DELETE FROM tupdate_package WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $id_package);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = 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) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_package WHERE id = ? LIMIT 1');
|
||||
$result =& $db->execute ($sql, $id_package);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
function um_db_get_package ($id_package) {
|
||||
$result = 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;
|
||||
}
|
||||
$result->fetchInto ($package);
|
||||
|
||||
$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 () {
|
||||
global $db;
|
||||
|
||||
$result =& $db->query ('SELECT * FROM tupdate_package');
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return array ();
|
||||
$result = process_sql ('SELECT * FROM '.DB_PREFIX.'tupdate_package');
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting all packages</strong><br />';
|
||||
return NULL;
|
||||
}
|
||||
$packages = array ();
|
||||
while ($result->fetchInto ($package)) {
|
||||
|
||||
$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) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate WHERE id_update_package = ?');
|
||||
$result =& $db->execute ($sql, $id_package);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = 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;
|
||||
}
|
||||
$updates = array ();
|
||||
while ($result->fetchInto ($update)) {
|
||||
$updates[$update->id] = $update;
|
||||
}
|
||||
|
||||
$result = 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_package, $client_key, $_SERVER['REMOTE_ADDR'], $user_package, $user_subscription, $result, $description);
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_package_log (id_update_package, client_key, ip_address, user_package, user_subscription, result, description) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
$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 = process_sql_insert (DB_PREFIX.'tupdate_package_log', $values);
|
||||
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_db_get_all_package_logs () {
|
||||
global $db;
|
||||
|
||||
$result =& $db->query ('SELECT * FROM tupdate_package_log ORDER BY `timestamp` DESC');
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return array ();
|
||||
function um_db_get_total_package_logs ($ip = '') {
|
||||
$result = 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 = array ();
|
||||
while ($result->fetchInto ($log)) {
|
||||
|
||||
$logs = um_std_from_result($result);
|
||||
|
||||
return $logs->total;
|
||||
}
|
||||
|
||||
function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit = 30, $offset = 0) {
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error reading all package logs</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
|
||||
|
||||
$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_create_component ($type, $name, $path = '') {
|
||||
global $db;
|
||||
|
||||
$values = array ($type, $name, $path);
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_component (type, name, path) VALUES (?, ?, ?)');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
function um_db_delete_package_logs ($ip) {
|
||||
$result = 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_update_component ($name, $path = '') {
|
||||
global $db;
|
||||
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 = process_sql_insert(DB_PREFIX.'tupdate_component', $values);
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error creating component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
$values = array ($path, $name);
|
||||
|
||||
$sql =& $db->prepare ('UPDATE tupdate_component SET path = ? WHERE name = ?');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
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 = process_sql_update(DB_PREFIX.'tupdate_component', $values, $where);
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error updating component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -321,12 +308,10 @@ function um_db_update_component ($name, $path = '') {
|
|||
}
|
||||
|
||||
function um_db_delete_component ($name) {
|
||||
global $db;
|
||||
$result = process_sql_delete(DB_PREFIX.'tupdate_component', array('name' => $name));
|
||||
|
||||
$sql =& $db->prepare ('DELETE FROM tupdate_component WHERE name = ?');
|
||||
$result =& $db->execute ($sql, $name);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -334,48 +319,58 @@ function um_db_delete_component ($name) {
|
|||
}
|
||||
|
||||
function um_db_get_component ($name) {
|
||||
global $db;
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting component</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_component WHERE name = ? LIMIT 1');
|
||||
$result =& $db->execute ($sql, $name);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return NULL;
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
|
||||
|
||||
$component = um_std_from_result($result);
|
||||
|
||||
if ($component->relative_path != '') {
|
||||
$last = $component->relative_path[strlen ($component->relative_path) - 1];
|
||||
if ($last != '/')
|
||||
$component->relative_path .= '/';
|
||||
}
|
||||
$result->fetchInto ($component);
|
||||
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
function um_db_get_all_components ($type = '') {
|
||||
global $db;
|
||||
|
||||
if ($type != '') {
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_component WHERE type = ?');
|
||||
$result =& $db->execute ($sql, $type);
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE type = '.$type);
|
||||
} else {
|
||||
$result =& $db->query ('SELECT * FROM tupdate_component');
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component');
|
||||
}
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return array ();
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting component</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
$components = array ();
|
||||
while ($result->fetchInto ($component)) {
|
||||
|
||||
$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) {
|
||||
global $db;
|
||||
|
||||
$values = array ($table_name, $field_name, $order, $component_name);
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_component_db (table_name, field_name, `order`, component) VALUES (?, ?, ?, ?)');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$values = array('table_name' => $table_name, 'field_name' => $field_name, '`order`' => $order, 'component' => $component_name);
|
||||
$result = process_sql_insert(DB_PREFIX.'tupdate_component_db', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating database component</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -383,26 +378,42 @@ function um_db_create_component_db ($table_name, $field_name, $order, $component
|
|||
}
|
||||
|
||||
function um_db_update_component_db ($id, $table_name = '', $field_name = '', $order = '') {
|
||||
global $db;
|
||||
|
||||
$values = array ($table_name, $field_name, $order, $id);
|
||||
$sql =& $db->prepare ('UPDATE tupdate_component_db SET table_name = ?, field_name = ?, `order` = ? WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$values = array ('table_name' => $table_name, 'field_name' => $field_name, '`order`' => $order);
|
||||
$where = array ('id' => $id);
|
||||
|
||||
$result = 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) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('DELETE FROM tupdate_component_db WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $id);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql_delete(DB_PREFIX.'tupdate_component_db', array('id' => $id));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting database component</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -410,31 +421,39 @@ function um_db_delete_component_db ($id) {
|
|||
}
|
||||
|
||||
function um_db_get_component_db ($id_component_db) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_component_db WHERE id = ? LIMIT 1');
|
||||
$result =& $db->execute ($sql, $id_component_db);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting database component</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
$result->fetchInto ($component);
|
||||
}
|
||||
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
|
||||
|
||||
$component = um_std_from_result($result);
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
function um_db_get_database_components ($component_name) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_component_db WHERE component = ? ORDER BY `order` ASC');
|
||||
$result =& $db->execute ($sql, $component_name);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return NULL;
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting database components </strong> <br />';
|
||||
return array();
|
||||
}
|
||||
$components = array ();
|
||||
while ($result->fetchInto ($component)) {
|
||||
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
|
||||
|
||||
$cont = 0;
|
||||
$components = array();
|
||||
while(true) {
|
||||
$component = um_std_from_result($result, $cont);
|
||||
if($component === false) {
|
||||
break;
|
||||
}
|
||||
$components[$component->id] = $component;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $components;
|
||||
|
@ -447,29 +466,34 @@ function um_db_create_auth ($client_key, $subscription_limit, $description = '',
|
|||
echo '<strong>Error</strong>: Subscription must be numeric<br />';
|
||||
return false;
|
||||
}
|
||||
$values = array ($client_key, $subscription_limit, $description, $developer);
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_auth (client_key, subscription_limit, description, developer) VALUES (?, ?, ?, ?)');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
|
||||
$values = array ('client_key' => $client_key, 'subscription_limit' => $subscription_limit, 'description' => $description, 'developer' => $developer);
|
||||
$result = 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) {
|
||||
global $db;
|
||||
|
||||
if (! is_numeric ($subscription_limit)) {
|
||||
echo '<strong>Error</strong>: Subscription must be numeric<br />';
|
||||
return false;
|
||||
}
|
||||
$values = array ($client_key, $subscription_limit, $description,
|
||||
$developer, $id_auth);
|
||||
$sql =& $db->prepare ('UPDATE tupdate_auth SET client_key = ?, subscription_limit = ?, description = ?, developer = ? WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
|
||||
$values = array ('client_key' => $client_key,
|
||||
'subscription_limit' => $subscription_limit,
|
||||
'description' => $description,
|
||||
'developer' => $developer);
|
||||
$where = array ('id' => $id_auth);
|
||||
|
||||
$result = process_sql_update(DB_PREFIX.'tupdate_auth', $values, $where);
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error updating authorization</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -477,12 +501,10 @@ function um_db_update_auth ($id_auth, $client_key, $subscription_limit, $descrip
|
|||
}
|
||||
|
||||
function um_db_delete_auth ($id_auth) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('DELETE FROM tupdate_auth WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $id_auth);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql_delete(DB_PREFIX.'tupdate_auth', array('id' => $id_auth));
|
||||
|
||||
if($result === false) {
|
||||
echo '<strong>Error deleting authorization</strong><br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -490,96 +512,82 @@ function um_db_delete_auth ($id_auth) {
|
|||
}
|
||||
|
||||
function um_db_get_auth ($id_auth) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_auth WHERE id = ? LIMIT 1');
|
||||
$result =& $db->execute ($sql, $id_auth);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return NULL;
|
||||
}
|
||||
$result->fetchInto ($auth);
|
||||
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = "'.$id_auth.'" LIMIT 1');
|
||||
|
||||
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 () {
|
||||
global $db;
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_auth');
|
||||
|
||||
$result =& $db->query ('SELECT * FROM tupdate_auth');
|
||||
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return array ();
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting authorizations</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
$auths = array ();
|
||||
while ($result->fetchInto ($auth)) {
|
||||
|
||||
$result = 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 $db;
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = "'.$client_key.'" LIMIT 1');
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate_auth WHERE client_key = ? LIMIT 1');
|
||||
$result =& $db->execute ($sql, $client_key);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
if ($result === false) {
|
||||
echo '<strong>Error checking authorization</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$auth = um_std_from_result($result);
|
||||
|
||||
if (!$auth) {
|
||||
return false;
|
||||
}
|
||||
$result->fetchInto ($auth);
|
||||
if (! $auth)
|
||||
return false;
|
||||
|
||||
if ($auth->developer == 1)
|
||||
return $auth->id;
|
||||
|
||||
if ($auth->subscription_limit >= $subscription_limit)
|
||||
if ($auth->developer == 1 || $auth->subscription_limit >= $subscription_limit) {
|
||||
return $auth->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function um_db_is_auth_developer ($id_auth) {
|
||||
global $db;
|
||||
|
||||
$developer =& $db->getOne ('SELECT developer FROM tupdate_auth WHERE id = ? LIMIT 1', $id_auth);
|
||||
if (PEAR::isError ($developer)) {
|
||||
echo '<strong>Error</strong>: '.$developer->getMessage ().'<br />';
|
||||
$developer = get_db_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 = '') {
|
||||
static $db = NULL;
|
||||
|
||||
if ($db)
|
||||
return $db;
|
||||
|
||||
$dsn = $backend.'://'.$user.':'.$password.'@'.$host.'/'.$db_name;
|
||||
$db =& DB::Connect ($dsn, array ());
|
||||
if (PEAR::isError ($db)) {
|
||||
echo '<strong>Error</strong>: '.$db->getMessage ().'<br />';
|
||||
die;
|
||||
}
|
||||
$db->setFetchMode (DB_FETCHMODE_OBJECT);
|
||||
|
||||
return $db;
|
||||
return connect_db ($host, $db_name, $user, $password);
|
||||
}
|
||||
|
||||
function um_component_db_connect () {
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$dsn = 'mysql://'.$settings->dbuser.':'.$settings->dbpass.'@'.$settings->dbhost.'/'.$settings->dbname;
|
||||
$db =& DB::Connect ($dsn, array ());
|
||||
if (PEAR::isError ($db)) {
|
||||
return false;
|
||||
}
|
||||
$db->setFetchMode (DB_FETCHMODE_ORDERED);
|
||||
|
||||
return $db;
|
||||
return connect_db ($settings->dbhost, $settings->dbname, $settings->dbuser, $settings->dbpass);
|
||||
}
|
||||
|
||||
function um_get_package_status () {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -12,75 +12,47 @@
|
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
|
||||
$prev_level = error_reporting (0);
|
||||
if ((include_once ('XML/RPC.php')) != 1)
|
||||
die ('
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Pandora FMS - The Flexible Monitoring System - Console error</title>
|
||||
<meta http-equiv="expires" content="0">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf8">
|
||||
<meta name="resource-type" content="document">
|
||||
<meta name="distribution" content="global">
|
||||
<meta name="author" content="Sancho Lerena">
|
||||
<meta name="copyright" content="This is GPL software. Created by Sancho Lerena and others">
|
||||
<meta name="keywords" content="pandora, monitoring, system, GPL, software">
|
||||
<meta name="robots" content="index, follow">
|
||||
<link rel="icon" href="images/pandora.ico" type="image/ico">
|
||||
<link rel="stylesheet" href="include/styles/pandora.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="main" style="float:left; margin-left: 100px">
|
||||
<div align="center">
|
||||
<div id="login_f">
|
||||
<h1 id="log_f" class="error">PEAR::XML_RPC not found</h1>
|
||||
<div>
|
||||
<img src="images/pandora_logo.png" border="0"></a>
|
||||
</div>
|
||||
<div class="msg">
|
||||
<span class="error"><b>ERROR:</b> PEAR::XML_RPC not found</span>
|
||||
<p>
|
||||
Please install it from command line with:
|
||||
<pre>sudo pear install XML_RPC</pre>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
');
|
||||
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) {
|
||||
//Test conection of host
|
||||
$fp = @fsockopen($server_host, $server_port, $errno, $errstr);
|
||||
if ($errstr == "php_network_getaddresses: getaddrinfo failed: Name or service not known") {
|
||||
echo '<strong>Open Update Manager</strong> Server comunication error: failed check connection to server.';
|
||||
return false;
|
||||
}
|
||||
fclose($fp);
|
||||
$msg = new xmlrpcmsg ($function, $parameters);
|
||||
|
||||
$client = new xmlrpc_client($server_path, $server_host, $server_port);
|
||||
|
||||
$client->setProxy($proxy, $proxy_port, $proxy_user, $proxy_pass);
|
||||
|
||||
$msg = new XML_RPC_Message ($function, $parameters);
|
||||
$client = new XML_RPC_Client ($server_path, $server_host, $server_port, $proxy, $proxy_port, $proxy_user, $proxy_pass);
|
||||
if (defined ('XMLRPC_DEBUG'))
|
||||
$client->setDebug (XMLRPC_DEBUG);
|
||||
$result = $client->send ($msg, XMLRPC_TIMEOUT);
|
||||
|
||||
$result = $client->send ($msg, XMLRPC_TIMEOUT, '');
|
||||
|
||||
if (! $result) {
|
||||
echo '<strong>Open Update Manager</strong> Server comunication error: '.$client->errstr;
|
||||
return false;
|
||||
trigger_error ('<strong>Open Update Manager</strong> Server comunication error. '.$client->errstr);
|
||||
return 0;
|
||||
}
|
||||
if ($result->faultCode ()) {
|
||||
echo '<strong>Open Update Manager</strong> XML-RPC error: '.$result->faultString ();
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -103,17 +75,17 @@ 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 ();
|
||||
|
@ -122,14 +94,15 @@ function um_xml_rpc_unpack_package ($package_xml_rpc) {
|
|||
$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 XML_RPC_Value ($settings->customer_key, 'string'),
|
||||
new XML_RPC_Value ($user_key, 'string'),
|
||||
new XML_RPC_Value ($settings->current_update, 'int'));
|
||||
$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,
|
||||
|
@ -138,26 +111,27 @@ function um_client_check_latest_update ($settings, $user_key) {
|
|||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_latest_package', $params);
|
||||
|
||||
if ($result === false) {
|
||||
return false;
|
||||
|
||||
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 XML_RPC_Value ($settings->customer_key, 'string'),
|
||||
new XML_RPC_Value ($user_key, 'string'),
|
||||
new XML_RPC_Value ($settings->current_update, 'int'));
|
||||
$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,
|
||||
|
@ -166,14 +140,14 @@ function um_client_get_package ($settings, $user_key) {
|
|||
$settings->proxy_user,
|
||||
$settings->proxy_pass,
|
||||
'get_next_package', $params);
|
||||
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
||||
$value = $result->value ();
|
||||
if ($value->kindOf () == 'scalar') {
|
||||
/* No new updates */
|
||||
return (bool) $value->scalarval ();
|
||||
return (int)$value->scalarval ();
|
||||
}
|
||||
|
||||
$package = um_xml_rpc_unpack_package ($value);
|
||||
|
@ -181,44 +155,50 @@ function um_client_get_package ($settings, $user_key) {
|
|||
return $package;
|
||||
}
|
||||
|
||||
function um_client_db_save_package ($package) {
|
||||
global $db;
|
||||
|
||||
function um_client_db_save_package ($package, $settings) {
|
||||
$fields = array ('id' => $package->id,
|
||||
'description' => $package->description);
|
||||
$replace = array ();
|
||||
for ($i = 0; $i < sizeof ($fields); $i++) {
|
||||
$replace[] = '?';
|
||||
}
|
||||
'description' => $package->description,
|
||||
'timestamp' => $package->timestamp);
|
||||
|
||||
um_client_db_connect($settings);
|
||||
|
||||
$result = process_sql_insert(DB_PREFIX.'tupdate_package', $fields);
|
||||
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate_package ('.implode(',', array_keys ($fields)).') VALUES ('.implode(',', $replace).')');
|
||||
$result =& $db->execute ($sql, $fields);
|
||||
if (PEAR::isError ($result)) {
|
||||
if($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_db_save_update ($update) {
|
||||
global $db;
|
||||
function um_client_db_save_update ($update) {
|
||||
$fields = get_object_vars ($update);
|
||||
|
||||
$fields['data'] = base64_encode($fields['data']);
|
||||
|
||||
$fields = array_keys (get_object_vars ($update));
|
||||
$values = array_values (get_object_vars ($update));
|
||||
$replace = array ();
|
||||
for ($i = 0; $i < sizeof ($values); $i++) {
|
||||
$replace[] = '?';
|
||||
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']);
|
||||
}
|
||||
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate ('.implode(',', $fields).') VALUES ('.implode(',', $replace).')');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
$result = process_sql_insert(DB_PREFIX.'tupdate', $fields);
|
||||
|
||||
if($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_apply_update_file (&$update, $destiny_filename, $force = false) {
|
||||
@mkdir (dirname ($destiny_filename), 0777, 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)) {
|
||||
|
@ -231,47 +211,57 @@ function um_client_apply_update_file (&$update, $destiny_filename, $force = fals
|
|||
return false;
|
||||
}
|
||||
$content = file_get_contents ($destiny_filename);
|
||||
$update->data_rollback = convert_uuencode ($content);
|
||||
$update->data_rollback = um_data_encode ($content);
|
||||
$update->previous_checksum = $checksum;
|
||||
}
|
||||
$result = file_put_contents ($destiny_filename, convert_uudecode ($update->data));
|
||||
$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, &$db) {
|
||||
function um_client_apply_update_database (&$update) {
|
||||
if ($update->type == 'db_data') {
|
||||
$values = array ($update->db_table,
|
||||
$update->db_field,
|
||||
$update->db_field_value);
|
||||
$exists =& $db->getOne ('SELECT COUNT(*) FROM `!` WHERE ? = ?', $values);
|
||||
if (PEAR::isError ($exists)) {
|
||||
$exists = get_db_value('COUNT(*)', $update->db_table, $update->db_field, $update->db_field_value);
|
||||
|
||||
/* If it exists, it failed. */
|
||||
if ($exists != 0) {
|
||||
return false;
|
||||
}
|
||||
/* If it exists, it failed. */
|
||||
if ($exists)
|
||||
return false;
|
||||
}
|
||||
|
||||
$result =& $db->query ($update->data);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo $result->getMessage ();
|
||||
$query_array = explode(';',um_data_decode($update->data));
|
||||
$result = process_sql($query_array[0]);
|
||||
|
||||
if ($result === false) {
|
||||
//echo $result->getMessage ();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function um_client_apply_update (&$update, $settings, $db, $force = false) {
|
||||
function um_client_apply_update (&$update, $settings, $force = true) {
|
||||
if ($update->type == 'code') {
|
||||
$filename = $settings->updating_code_path.'/'.$update->filename;
|
||||
// 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') {
|
||||
$success = um_client_apply_update_database ($update, $db);
|
||||
//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;
|
||||
}
|
||||
|
@ -287,14 +277,14 @@ function um_client_rollback_update_file (&$update, $destiny_filename) {
|
|||
if (! isset ($update->data_rollback))
|
||||
return true;
|
||||
|
||||
$result = file_put_contents ($destiny_filename, convert_uudecode ($update->data_rollback));
|
||||
$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, $db) {
|
||||
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);
|
||||
|
@ -302,7 +292,7 @@ function um_client_rollback_update (&$update, $settings, $db) {
|
|||
$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->rollback ();
|
||||
process_sql_rollback();
|
||||
$success = true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -311,13 +301,58 @@ function um_client_rollback_update (&$update, $settings, $db) {
|
|||
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) {
|
||||
echo 'Update #'.$update->id;
|
||||
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 = $settings->updating_code_path.'/'.$update->filename;
|
||||
$realpath = HOME_DIR.'/'.$update->filename;
|
||||
} else {
|
||||
$realpath = $settings->updating_binary_path.'/'.$update->filename;
|
||||
}
|
||||
|
@ -326,61 +361,268 @@ function um_client_print_update ($update, $settings) {
|
|||
echo '<li><em>Checksum</em>: '.$update->checksum.'</li>';
|
||||
echo '<li><em>Writable</em>: '.(is_writable ($realpath) ? 'yes' : '<strong>no</strong>').'</li>';
|
||||
} else {
|
||||
echo '<li><em>Table</em>: '.$update->db_table.'</li>';
|
||||
echo '<li><em>Field</em>: '.$update->db_field.'</li>';
|
||||
echo '<li><em>Value</em>: '.$update->db_field_value.'</li>';
|
||||
echo '<li><em>Data</em>: '.$update->data.'</li>';
|
||||
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_client_upgrade_to_package ($package, $settings, $force = false) {
|
||||
function um_package_info_from_paths ($tmpDir) {
|
||||
$f = fopen($tmpDir.'info_package', "r");
|
||||
$f_content = fread($f, filesize($tmpDir.'info_package'));
|
||||
fclose($f);
|
||||
$f_array = array();
|
||||
|
||||
unset($f_content->status);
|
||||
|
||||
return json_decode($f_content);
|
||||
}
|
||||
|
||||
function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type) {
|
||||
$update = array();
|
||||
$i = 0;
|
||||
|
||||
// The number of the prefixs names is to keep alphabetic order to appliyng priority
|
||||
$sql_schema_file = '01_package_'.$num_package.'_schema.sql';
|
||||
$sql_data_file = '02_package_'.$num_package.'_data.sql';
|
||||
|
||||
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;
|
||||
|
||||
$db = um_client_db_connect ($settings);
|
||||
if ($db === false)
|
||||
return false;
|
||||
foreach ($package->updates as $update) {
|
||||
$success = um_client_apply_update ($update, $settings, $db, $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, $db);
|
||||
}
|
||||
|
||||
if(!is_object($package)) {
|
||||
return false;
|
||||
}
|
||||
$db->commit ();
|
||||
um_client_db_save_package ($package);
|
||||
foreach ($package->updates as $update) {
|
||||
um_client_db_save_update ($update);
|
||||
|
||||
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);
|
||||
|
||||
process_sql_commit();
|
||||
}
|
||||
|
||||
um_db_update_setting ('current_update', $package->id);
|
||||
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) {
|
||||
function um_client_upgrade_to_latest ($user_key, $force = true) {
|
||||
$settings = um_db_load_settings ();
|
||||
process_sql_begin();
|
||||
do {
|
||||
$package = um_client_get_package ($settings, $user_key);
|
||||
if ($package === false || $package === true)
|
||||
|
||||
if ($package === false || $package === true) {
|
||||
break;
|
||||
}
|
||||
|
||||
$success = um_client_upgrade_to_package ($package, $settings, $force);
|
||||
|
||||
if (! $success)
|
||||
break;
|
||||
|
||||
|
||||
|
||||
$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) */
|
||||
}
|
||||
|
@ -388,15 +630,8 @@ function um_client_upgrade_to_latest ($user_key, $force) {
|
|||
function um_client_db_connect (&$settings = NULL) {
|
||||
if (! $settings)
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
$dsn = 'mysql://'.$settings->dbuser.':'.$settings->dbpass.'@'.$settings->dbhost.'/'.$settings->dbname;
|
||||
$db =& DB::Connect ($dsn, array ());
|
||||
if (PEAR::isError ($db)) {
|
||||
return false;
|
||||
}
|
||||
$db->setFetchMode (DB_FETCHMODE_ASSOC);
|
||||
$db->autoCommit (false);
|
||||
|
||||
return $db;
|
||||
|
||||
//mysql_select_db (DB_NAME);
|
||||
mysql_connect ($settings->dbhost, $settings->dbuser, $settings->dbpass);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -19,24 +19,33 @@ function um_component_database_get_data ($component_db) {
|
|||
if ($db === false) {
|
||||
return false;
|
||||
}
|
||||
$db->setFetchMode (DB_FETCHMODE_OBJECT);
|
||||
|
||||
|
||||
$fields = um_component_database_get_table_fields ($component_db->table_name);
|
||||
$sql =& $db->prepare ('SELECT '.implode (',', $fields).' FROM !');
|
||||
$result =& $db->execute ($sql, $component_db->table_name);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.$component_db->table_name);
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting table fields</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
$resultdata = array ();
|
||||
|
||||
$result = process_sql('SELECT '.implode (',', $fields).' FROM '.$component_db->table_name);
|
||||
|
||||
$cont = 0;
|
||||
$resultdata = array();
|
||||
$field = $component_db->field_name;
|
||||
while ($result->fetchInto ($data)) {
|
||||
|
||||
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);
|
||||
$component_db->id,
|
||||
$data->$field);
|
||||
if ($update && $update->db_field_value == $data->$field)
|
||||
continue;
|
||||
array_push ($resultdata, $data);
|
||||
$resultdata[] = $data;
|
||||
$cont++;
|
||||
}
|
||||
|
||||
return $resultdata;
|
||||
|
@ -49,14 +58,17 @@ function um_component_database_get_all_tables () {
|
|||
return array ();
|
||||
}
|
||||
|
||||
$result =& $db->query ('SHOW TABLES');
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return array ();
|
||||
$result = process_sql('SHOW TABLES');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting tables</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
$tables = array ();
|
||||
while ($result->fetchInto ($table)) {
|
||||
array_push ($tables, $table[0]);
|
||||
|
||||
$cont = 0;
|
||||
$tables = array();
|
||||
foreach($result as $table) {
|
||||
$tables[] = $table[0];
|
||||
}
|
||||
|
||||
return $tables;
|
||||
|
@ -75,22 +87,29 @@ function um_component_database_get_available_tables ($component_name) {
|
|||
|
||||
function um_component_database_get_table_fields ($table_name) {
|
||||
$db = um_component_db_connect ();
|
||||
|
||||
|
||||
if ($db === false) {
|
||||
return array ();
|
||||
}
|
||||
|
||||
$sql =& $db->prepare ('SHOW COLUMNS FROM ! WHERE `Key` \!= "PRI"');
|
||||
$result =& $db->execute ($sql, $table_name);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
return array ();
|
||||
|
||||
$result = process_sql('SHOW COLUMNS FROM '.$table_name.' WHERE `Key` != "PRI"');
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
$fields = array ();
|
||||
while ($result->fetchInto ($field)) {
|
||||
array_push ($fields, $field[0]);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
@ -107,9 +126,10 @@ function um_component_directory_get_all_files ($component, $binary = false) {
|
|||
if (substr ($path, -1) != '/')
|
||||
$path .= "/";
|
||||
$files = directory_to_array ($path,
|
||||
array ('.svn', '.cvs', '.git', '.', '..' ), $binary);
|
||||
array ('.svn', '.cvs', '.git', '.', '..'), $binary);
|
||||
$blacklisted = um_component_get_all_blacklisted ($component);
|
||||
|
||||
return $files;
|
||||
return (array_diff ($files, $blacklisted));
|
||||
}
|
||||
|
||||
function um_component_directory_get_modified_files ($component, $binary = false) {
|
||||
|
@ -117,16 +137,68 @@ function um_component_directory_get_modified_files ($component, $binary = false)
|
|||
|
||||
$files = array ();
|
||||
foreach ($all_files as $file) {
|
||||
$last_update = um_update_get_last_from_filename ($component->name, $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) {
|
||||
$result = process_sql('SELECT COUNT(name) FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting all blacklisted items</strong> <br />';
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = process_sql('SELECT name FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
|
||||
|
||||
$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) {
|
||||
$result = process_sql('SELECT COUNT(*) AS blacklisted FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'" AND name = "'.$name.'"');
|
||||
|
||||
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 = process_sql_insert(DB_PREFIX.'tupdate_component_blacklist', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating blacklist component</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -15,58 +15,70 @@
|
|||
|
||||
|
||||
function um_update_get_last_from_filename ($component_name, $filename) {
|
||||
global $db;
|
||||
$component = um_db_get_component ($component_name);
|
||||
if (! $component)
|
||||
return;
|
||||
|
||||
$values = array ($component_name, $filename);
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate WHERE component = ? AND filename = ? ORDER BY id DESC LIMIT 1');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error getting update from filename</strong> <br />';
|
||||
return NULL;
|
||||
}
|
||||
$result->fetchInto ($update);
|
||||
|
||||
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
|
||||
|
||||
$update = um_std_from_result($result);
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
||||
function um_update_get_last_from_table_field_value ($component_name, $id_component_db, $field_value) {
|
||||
global $db;
|
||||
|
||||
$values = array ($component_name, $id_component_db, $field_value);
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate WHERE component = ? AND id_component_db = ? AND db_field_value = ? ORDER BY id DESC LIMIT 1');
|
||||
$result =& $db->execute ($sql, $values);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = 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->fetchInto ($update);
|
||||
|
||||
$result = 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 () {
|
||||
global $db;
|
||||
|
||||
$result =& $db->query ('SELECT * FROM tupdate WHERE id_update_package IS NULL');
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = 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;
|
||||
}
|
||||
$updates = array ();
|
||||
while ($result->fetchInto ($update)) {
|
||||
|
||||
$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) {
|
||||
global $db;
|
||||
|
||||
$sql =& $db->prepare ('SELECT * FROM tupdate WHERE id = ? LIMIT 1');
|
||||
$result =& $db->execute ($sql, $id_update);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = 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;
|
||||
}
|
||||
$result->fetchInto ($update);
|
||||
|
||||
$update = um_std_from_result($result);
|
||||
|
||||
return $update;
|
||||
}
|
||||
|
@ -80,13 +92,13 @@ function um_db_delete_update ($id_update) {
|
|||
echo '<strong>Error</strong>: '.'Only packages in development state can be deleted';
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql =& $db->prepare ('DELETE FROM tupdate WHERE id = ?');
|
||||
$result =& $db->execute ($sql, $id_update);
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
$result = process_sql_delete(DB_PREFIX.'tupdate', array('id' => $id_update));
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error deleting update</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -96,6 +108,8 @@ function um_db_create_update ($type, $component_name, $id_package, $update, $db_
|
|||
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);
|
||||
|
@ -110,7 +124,13 @@ function um_db_create_update ($type, $component_name, $id_package, $update, $db_
|
|||
if ($last_update && $last_update->checksum == $values['checksum']) {
|
||||
return false;
|
||||
}
|
||||
$values['filename'] = $update->filename;
|
||||
|
||||
/* 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;
|
||||
|
@ -123,26 +143,24 @@ function um_db_create_update ($type, $component_name, $id_package, $update, $db_
|
|||
$field = $component_db->field_name;
|
||||
$values['db_field_value'] = $db_data->$field;
|
||||
$values['id_component_db'] = $update->id_component_db;
|
||||
$values['data'] = 'INSERT INTO `'.$component_db->table_name.'` (`'.implode('`,`', array_keys (get_object_vars ($db_data))).'`) VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')';
|
||||
$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 'db_schema':
|
||||
$values['data'] = $update->data;
|
||||
$values['data'] = um_data_encode($update->data);
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
$replace = array ();
|
||||
for ($i = 0; $i < sizeof ($values); $i++) {
|
||||
$replace[] = '?';
|
||||
}
|
||||
$sql =& $db->prepare ('INSERT INTO tupdate ('.implode(',', array_keys ($values)).') VALUES ('.implode(',', $replace).')');
|
||||
$result =& $db->execute ($sql, array_values ($values));
|
||||
if (PEAR::isError ($result)) {
|
||||
echo '<strong>Error</strong>: '.$result->getMessage ().'<br />';
|
||||
|
||||
$result = process_sql_insert(DB_PREFIX.'tupdate', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo '<strong>Error creating update</strong> <br />';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -163,6 +181,14 @@ function um_file_get_svn_revision ($file) {
|
|||
|
||||
function um_file_uuencode ($file) {
|
||||
$content = file_get_contents ($file);
|
||||
return convert_uuencode ($content);
|
||||
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));
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -26,6 +26,6 @@ if (! extension_loaded ('mysql'))
|
|||
|
||||
require_once ('libupdate_manager.php');
|
||||
|
||||
$db =& um_db_connect (DB_BACKEND, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
|
||||
um_db_connect (DB_BACKEND, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
|
||||
flush ();
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,955 @@
|
|||
<?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
|
@ -2,7 +2,7 @@
|
|||
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -12,7 +12,6 @@
|
|||
// 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);
|
||||
|
||||
|
@ -59,7 +58,7 @@ function get_user_key ($settings) {
|
|||
*/
|
||||
global $build_version;
|
||||
global $pandora_version;
|
||||
|
||||
|
||||
$n = (int) get_db_value ('COUNT(`id_agente`)', 'tagente', 'disabled', 0);
|
||||
$m = (int) get_db_value ('COUNT(`id_agente_modulo`)', 'tagente_modulo',
|
||||
'disabled', 0);
|
||||
|
@ -69,4 +68,5 @@ function get_user_key ($settings) {
|
|||
}
|
||||
|
||||
flush ();
|
||||
|
||||
?>
|
||||
|
|
|
@ -17,10 +17,11 @@ global $config;
|
|||
|
||||
check_login ();
|
||||
|
||||
$db =& um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname']);
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
$error = '';
|
||||
|
||||
print_page_header (__('Update manager'), "images/extensions.png", false, "", false, "" );
|
||||
|
||||
|
@ -38,7 +39,7 @@ if ($settings->customer_key == FREE_USER) {
|
|||
|
||||
$user_key = get_user_key ($settings);
|
||||
$update_package = (bool) get_parameter_post ('update_package');
|
||||
|
||||
|
||||
if ($update_package) {
|
||||
if ($config['enterprise_installed'] == 1) {
|
||||
echo '<h2>'.__('Updating').'...</h2>';
|
||||
|
@ -47,28 +48,118 @@ if ($update_package) {
|
|||
|
||||
um_client_upgrade_to_latest ($user_key, $force);
|
||||
/* TODO: Add a new in tnews */
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
} else {
|
||||
echo '<h5 class="error">' . __('This is an Enterprise feature. Visit %s for more information.', '<a href="http://pandorafms.com">http://pandorafms.com</a>') . '</h5>';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) {
|
||||
$extension = substr($_FILES["fileloaded"]["name"], strlen($_FILES["fileloaded"]["name"])-4, 4);
|
||||
if($extension != '.oum') {
|
||||
$error = '<h5 class="error">'.__('Incorrect file extension').'</h5>';
|
||||
}
|
||||
else {
|
||||
$tempDir = sys_get_temp_dir()."/tmp_oum/";
|
||||
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($_FILES["fileloaded"]['tmp_name']) === TRUE) {
|
||||
$zip->extractTo($tempDir);
|
||||
$zip->close();
|
||||
} else {
|
||||
$error = '<h5 class="error">'.__('Update cannot be opened').'</h5>';
|
||||
}
|
||||
|
||||
$package = um_package_info_from_paths ($tempDir);
|
||||
|
||||
$settings = um_db_load_settings ();
|
||||
|
||||
if($settings->current_update >= $package->id) {
|
||||
$error = '<h5 class="error">'.__('Your system version is higher or equal than the loaded package').'</h5>';
|
||||
}
|
||||
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)) {
|
||||
echo '<h5 class="suc">'.__('Successfully upgraded').'.</h5>';
|
||||
$settings = um_db_load_settings ();
|
||||
}
|
||||
else {
|
||||
echo '<h5 class="error">'.__('Cannot be upgraded').'</h5>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = '<h5 class="error">'.__('File cannot be uploaded').'</h5>';
|
||||
}
|
||||
|
||||
clean_cache();
|
||||
$settings = um_db_load_settings ();
|
||||
$user_key = get_user_key ($settings);
|
||||
|
||||
$package = um_client_check_latest_update ($settings, $user_key);
|
||||
|
||||
if (check_acl ($config['id_user'], 0, 'PM')) {
|
||||
|
||||
if (is_int ($package) && $package == 1) {
|
||||
if ($package === true) {
|
||||
echo '<h5 class="suc">'.__('Your system is up-to-date').'.</h5>';
|
||||
} elseif ($package === false) {
|
||||
echo '<h5 class="error">'.__('Server connection failed')."</h5>";
|
||||
} elseif (is_int ($package) && $package == 0) {
|
||||
echo '<h5 class="error">'.__('Server authorization rejected')."</h5>";
|
||||
echo '<h5 class="error">'.__('Server authorization rejected').'</h5>';
|
||||
} elseif ($package === 0) {
|
||||
echo '<h5 class="error">'.__('Server connection failed').'</h5>';
|
||||
} else {
|
||||
echo '<h5 class="suc">'.__('There\'s a new update for Pandora FMS')."</h5>";
|
||||
echo '<h5 class="suc">'.__('There\'s a new update for Pandora FMS').'</h5>';
|
||||
|
||||
$table->width = '80%';
|
||||
$table->data = array ();
|
||||
|
||||
|
||||
$table->data[0][0] = '<strong>'.__('Id').'</strong>';
|
||||
$table->data[0][1] = $package->id;
|
||||
|
||||
|
@ -89,6 +180,26 @@ if (check_acl ($config['id_user'], 0, 'PM')) {
|
|||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if($error != '' && isset($_FILES["fileloaded"]["error"])) {
|
||||
echo $error;
|
||||
}
|
||||
|
||||
unset($table);
|
||||
|
||||
$table->width = '80%';
|
||||
$table->data = array ();
|
||||
$table->colspan[0][0] = 2;
|
||||
|
||||
$table->data[0][0] = '<h3>'.__('Offline packages loader').'</h3>';
|
||||
$table->data[1][0] = '<input type="hidden" name="upload_package" value="1">';
|
||||
$table->data[1][0] .= '<input type="file" size="55" name="fileloaded">';
|
||||
$table->data[1][1] = '<input type="submit" name="upload_button" value="'.__('Upload').'">';
|
||||
|
||||
echo '<form method="post" enctype="multipart/form-data">';
|
||||
print_table($table);
|
||||
echo '</form>';
|
||||
|
||||
}
|
||||
|
||||
echo '<h4>'.__('Your system version number is').': '.$settings->current_update.'</h4>';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// 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
|
||||
|
@ -22,7 +22,7 @@ if (! check_acl ($config['id_user'], 0, 'PM')) {
|
|||
return;
|
||||
}
|
||||
|
||||
$db =& um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
|
||||
$config['dbpass'], $config['dbname']);
|
||||
|
||||
$update_settings = (bool) get_parameter_post ('update_settings');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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', '0'), ('customer_key', 'PANDORA-FREE'), ('keygen_path', '/usr/share/pandora/util/keygen'), ('update_server_host', 'www.artica.es'), ('update_server_port', '80'), ('update_server_path', '/pandoraupdate32/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', ''), ('proxy', ''), ('proxy_port', ''), ('proxy_user', ''), ('proxy_pass', '');
|
||||
INSERT INTO `tupdate_settings` VALUES ('current_update', '0'), ('customer_key', 'PANDORA-FREE'), ('keygen_path', '/usr/share/pandora/util/keygen'), ('update_server_host', 'www.artica.es'), ('update_server_port', '80'), ('update_server_path', '/pandoraupdate321/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', ''), ('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;
|
||||
|
|
Loading…
Reference in New Issue