2012-04-04 Miguel de Dios <miguel.dedios@artica.es>

* extensions/update_manager.php,
	extensions/update_manager/load_updatemanager.php,
	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/main.php: cleaned source code style.
	
	* extensions/update_manager/settings.php: disabled the path because this
	conf it is burned with each update of PHP files.

	Merged from the branch pandora_4.0



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5906 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-04-04 17:11:35 +00:00
parent 446b785b91
commit fdcefea66d
8 changed files with 359 additions and 258 deletions

View File

@ -1,3 +1,17 @@
2012-04-04 Miguel de Dios <miguel.dedios@artica.es>
* extensions/update_manager.php,
extensions/update_manager/load_updatemanager.php,
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/main.php: cleaned source code style.
* extensions/update_manager/settings.php: disabled the path because this
conf it is burned with each update of PHP files.
Merged from the branch pandora_4.0
2012-04-04 Sergio Martin <sergio.martin@artica.es>
* godmode/massive/massive_edit_agents.php

View File

@ -23,7 +23,7 @@ function update_settings_database_connection () {
global $config;
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
$config['dbpass'], $config['dbname']);
$config['dbpass'], $config['dbname']);
um_db_update_setting ('dbname', $config['dbname']);
um_db_update_setting ('dbuser', $config['dbuser']);
um_db_update_setting ('dbpass', $config['dbpass']);
@ -36,6 +36,16 @@ function pandora_update_manager_install () {
if (isset ($config['update_manager_installed'])) {
$update_server_path = db_get_value('value', 'tupdate_settings', '`key`', 'update_server_path');
////OVERWRITE EVER THE UPDATE SERVER PATH.//////////////////////
/*
The server path is ever the value from PHP. And you wonder
"Why?". Yes, I wonder too. And it is for when the user update
the Pandora Console PHP files to new version, this conf param
"automagic" change to new path for the new updates in the new
version.
*/
if ($update_server_path != '/pandoraupdate4/server.php') {
$result = db_process_sql_update('tupdate_settings',
array('value' => '/pandoraupdate4/server.php'),
@ -45,6 +55,7 @@ function pandora_update_manager_install () {
db_pandora_audit("ERROR update extension", "Error in the update the extension 'update manager' when update the 'update_server_path' field.");
}
}
////////////////////////////////////////////////////////////////
/* Already installed */
return;
@ -70,19 +81,20 @@ function pandora_update_manager_install () {
return;
}
$values = array("token" => "update_manager_installed", "value" => 1);
$values = array("token" => "update_manager_installed",
"value" => 1);
db_process_sql_insert('tconfig', $values);
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
$config['dbpass'], $config['dbname']);
$config['dbpass'], $config['dbname']);
um_db_update_setting ('updating_code_path',
dirname ($_SERVER['SCRIPT_FILENAME']));
dirname ($_SERVER['SCRIPT_FILENAME']));
update_settings_database_connection ();
}
function pandora_update_manager_uninstall () {
global $config;
switch ($config["dbtype"]) {
case "mysql":
db_process_sql ('DELETE FROM `tconfig` WHERE `token` = "update_manager_installed"');
@ -115,7 +127,7 @@ function pandora_update_manager_main () {
require ("general/noaccess.php");
return;
}
load_update_manager_lib ();
update_settings_database_connection ();
@ -131,10 +143,10 @@ function pandora_update_manager_login () {
db_process_sql_insert('tconfig', array('token' => 'autoupdate', 'value' => 0));
}
if ($config["autoupdate"] == 0)
return;
load_update_manager_lib ();
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
@ -142,7 +154,7 @@ function pandora_update_manager_login () {
$settings = um_db_load_settings ();
$user_key = get_user_key ($settings);
$package = um_client_check_latest_update ($settings, $user_key);
if (is_object ($package)) {

View File

@ -25,7 +25,7 @@ function um_db_load_settings () {
echo '<strong>Error reading settings</strong><br />';
return NULL;
}
$settings = new stdClass ();
$settings->proxy = '';
$settings->proxy_port = '';
@ -34,13 +34,13 @@ function um_db_load_settings () {
foreach($result as $field) {
$settings->$field['key'] = $field['value'];
}
return $settings;
}
function um_db_update_setting ($key, $value = '') {
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = db_get_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '`key`', $key);
@ -52,13 +52,13 @@ function um_db_update_setting ($key, $value = '') {
$result = db_get_value('COUNT(*)', DB_PREFIX.'tupdate_settings', 'key', $key);
break;
}
if ($result === false) {
echo '<strong>Error reading settings</strong> <br />';
return NULL;
}
if($result > 0) {
if ($result > 0) {
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('`key`' => $key));
@ -70,7 +70,7 @@ function um_db_update_setting ($key, $value = '') {
$result = db_process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('key' => $key));
break;
}
if ($result === false) {
echo '<strong>Error updating settings</strong> <br />';
return false;
@ -88,36 +88,39 @@ function um_db_update_setting ($key, $value = '') {
$result = db_process_sql_insert(DB_PREFIX.'tupdate_settings', array('key' => $key, 'value' => $value));
break;
}
if ($result === false) {
echo '<strong>Error creating settings</strong> <br />';
return false;
}
}
return true;
}
function um_db_get_latest_package_by_status ($id_package = '0', $status = 'public') {
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_package WHERE status = "'.$status.'" AND id > ' . $id_package . ' ORDER BY id DESC LIMIT 1');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_package
WHERE status = "'.$status.'" AND id > ' . $id_package . '
ORDER BY id DESC LIMIT 1');
if($result === false) {
echo '<strong>Error reading latest package with status ' . $status . '</strong><br />';
return false;
}
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_package WHERE status = "'.$status.'" AND id > ' . $id_package . ' ORDER BY id DESC LIMIT 1');
$package = um_std_from_result($result);
return $package;
}
function um_db_get_next_package ($id_package = '0', $development = false) {
$package = um_db_get_latest_package_by_status ($id_package, $status = 'public');
if (! $package && $development) {
$package = um_db_get_latest_package_by_status ($id_package, $status = 'development');
$package = um_db_get_latest_package_by_status ($id_package, $status = 'development');
}
return $package;
@ -125,30 +128,30 @@ function um_db_get_next_package ($id_package = '0', $development = false) {
function um_db_create_package ($description = '') {
$result = db_process_sql_insert(DB_PREFIX.'tupdate_package', array('description' => $description));
if($result === false) {
echo '<strong>Error creating package</strong><br />';
return false;
}
return true;
}
function um_db_update_package ($id_package, $description = '', $status = 'disabled') {
$values = array ('description' => $description, 'status' => $status);
$where = array ('id' => $id_package);
$result = db_process_sql_update(DB_PREFIX.'tupdate_package', $values, $where);
if($result === false) {
echo '<strong>Error updating package</strong><br />';
return false;
}
return true;
}
function um_db_delete_package ($id_package) {
function um_db_delete_package ($id_package) {
$package = um_db_get_package ($id_package);
if ($package->status != 'development') {
@ -157,7 +160,7 @@ function um_db_delete_package ($id_package) {
}
$result = db_process_sql_delete(DB_PREFIX.'tupdate_package', array('id' => $id_package));
if($result === false) {
echo '<strong>Error deleting package</strong><br />';
return false;
@ -182,14 +185,14 @@ 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;
}
@ -210,7 +213,7 @@ function um_db_get_all_packages () {
$packages[$package->id] = $package;
$cont++;
}
return $packages;
}
@ -222,7 +225,7 @@ function um_db_get_package_updates ($id_package) {
}
$result = db_process_sql ('SELECT * FROM '.DB_PREFIX.'tupdate WHERE id_update_package = ' . $id_package);
$cont = 0;
$updates = array();
while(true) {
@ -237,7 +240,7 @@ function um_db_get_package_updates ($id_package) {
$updates[$update->id] = $update;
$cont++;
}
return $updates;
}
@ -245,46 +248,52 @@ function um_db_create_package_log ($id_package, $client_key, $user_package, $res
global $db;
$values = array ('id_update_package' => $id_package,
'client_key' => $client_key,
'ip_address' => $_SERVER['REMOTE_ADDR'],
'user_package' => $user_package,
'user_subscription' => $user_subscription,
'result' => $result,
'description' => $description);
'client_key' => $client_key,
'ip_address' => $_SERVER['REMOTE_ADDR'],
'user_package' => $user_package,
'user_subscription' => $user_subscription,
'result' => $result,
'description' => $description);
$result = db_process_sql_insert (DB_PREFIX.'tupdate_package_log', $values);
if ($result === false) {
return false;
}
return true;
}
function um_db_get_total_package_logs ($ip = '') {
$result = db_process_sql('SELECT COUNT(*) total FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%"');
$result = db_process_sql('SELECT COUNT(*) total
FROM '.DB_PREFIX.'tupdate_package_log
WHERE ip_address LIKE "%'.$ip.'%"');
if ($result === false) {
echo '<strong>Error reading package log</strong> <br />';
return 0;
}
$logs = um_std_from_result($result);
return $logs->total;
}
function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit = 30, $offset = 0) {
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_package_log
WHERE ip_address LIKE "%'.$ip.'%"
ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
break;
case "postgresql":
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_package_log
WHERE ip_address LIKE \'%'.$ip.'%\' ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
WHERE ip_address LIKE \'%'.$ip.'%\'
ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
break;
case "oracle":
$set = array ();
@ -296,7 +305,7 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit =
break;
}
if ($result === false) {
echo '<strong>Error reading all package logs</strong> <br />';
return array();
@ -319,7 +328,7 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit =
}
break;
}
$cont = 0;
$logs = array();
while (true) {
@ -330,13 +339,14 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit =
$logs[$log->id] = $log;
$cont++;
}
return $logs;
}
function um_db_delete_package_logs ($ip) {
$result = db_process_sql_delete(DB_PREFIX.'tupdate_package_log', array('ip_address' => $ip));
$result = db_process_sql_delete(DB_PREFIX.'tupdate_package_log',
array('ip_address' => $ip));
if($result === false) {
echo '<strong>Error deleting logs</strong><br />';
return false;
@ -347,13 +357,13 @@ function um_db_delete_package_logs ($ip) {
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);
'name' => $name,
'path' => $path,
'`binary`' => $binary,
'relative_path' => $relative_path);
$result = db_process_sql_insert(DB_PREFIX.'tupdate_component', $values);
if($result === false) {
echo '<strong>Error creating component</strong><br />';
return false;
@ -365,9 +375,9 @@ function um_db_create_component ($type, $name, $path = '', $binary = false, $rel
function um_db_update_component ($name, $path = '', $binary = false, $relative_path = '') {
$values = array ('path' => $path, 'binary' => $binary, 'relative_path' => $relative_path);
$where = array ('name' => $name);
$result = db_process_sql_update(DB_PREFIX.'tupdate_component', $values, $where);
if($result === false) {
echo '<strong>Error updating component</strong><br />';
return false;
@ -392,33 +402,45 @@ function um_db_get_component ($name) {
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component
WHERE name = "'.$name.'" LIMIT 1');
break;
case "postgresql":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' LIMIT 1');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component
WHERE name = \''.$name.'\' LIMIT 1');
break;
case "oracle":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' AND rownum < 2');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component
WHERE name = \''.$name.'\' AND rownum < 2');
break;
}
if ($result === false) {
echo '<strong>Error getting component</strong> <br />';
return array();
}
}
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component
WHERE name = "'.$name.'" LIMIT 1');
break;
case "postgresql":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' LIMIT 1');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component
WHERE name = \''.$name.'\' LIMIT 1');
break;
case "oracle":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' AND rownum < 2');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component
WHERE name = \''.$name.'\' AND rownum < 2');
break;
}
$component = um_std_from_result($result);
if ($component->relative_path != '') {
@ -426,13 +448,14 @@ function um_db_get_component ($name) {
if ($last != '/')
$component->relative_path .= '/';
}
return $component;
}
function um_db_get_all_components ($type = '') {
if ($type != '') {
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE type = '.$type);
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component WHERE type = '.$type);
}
else {
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component');
@ -458,9 +481,12 @@ function um_db_get_all_components ($type = '') {
}
function um_db_create_component_db ($table_name, $field_name, $order, $component_name) {
$values = array('table_name' => $table_name, 'field_name' => $field_name, '`order`' => $order, 'component' => $component_name);
$values = array('table_name' => $table_name,
'field_name' => $field_name,
'`order`' => $order,
'component' => $component_name);
$result = db_process_sql_insert(DB_PREFIX.'tupdate_component_db', $values);
if ($result === false) {
echo '<strong>Error creating database component</strong> <br />';
@ -471,11 +497,13 @@ function um_db_create_component_db ($table_name, $field_name, $order, $component
}
function um_db_update_component_db ($id, $table_name = '', $field_name = '', $order = '') {
$values = array ('table_name' => $table_name, 'field_name' => $field_name, '`order`' => $order);
$values = array ('table_name' => $table_name,
'field_name' => $field_name,
'`order`' => $order);
$where = array ('id' => $id);
$result = db_process_sql_update(DB_PREFIX.'tupdate_component_db', $values, $where);
if($result === false) {
echo '<strong>Error updating database component</strong><br />';
@ -486,28 +514,29 @@ function um_db_update_component_db ($id, $table_name = '', $field_name = '', $or
}
function um_delete_directory($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
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;
while ($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
else
um_delete_directory($dirname.'/'.$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
function um_db_delete_component_db ($id) {
$result = db_process_sql_delete(DB_PREFIX.'tupdate_component_db', array('id' => $id));
$result = db_process_sql_delete(DB_PREFIX.'tupdate_component_db',
array('id' => $id));
if($result === false) {
echo '<strong>Error deleting database component</strong><br />';
return false;
@ -521,33 +550,45 @@ function um_db_get_component_db ($id_component_db) {
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component_db
WHERE id = "'.$id_component_db.'" LIMIT 1');
break;
case "postgresql":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' LIMIT 1');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component_db
WHERE id = \''.$id_component_db.'\' LIMIT 1');
break;
case "oracle":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' AND rownum < 2');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component_db
WHERE id = \''.$id_component_db.'\' AND rownum < 2');
break;
}
if ($result === false) {
echo '<strong>Error getting database component</strong> <br />';
return NULL;
}
}
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component_db
WHERE id = "'.$id_component_db.'" LIMIT 1');
break;
case "postgresql":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' LIMIT 1');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component_db
WHERE id = \''.$id_component_db.'\' LIMIT 1');
break;
case "oracle":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' AND rownum < 2');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component_db
WHERE id = \''.$id_component_db.'\' AND rownum < 2');
break;
}
$component = um_std_from_result($result);
return $component;
@ -558,14 +599,18 @@ function um_db_get_database_components ($component_name) {
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component_db
WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
break;
case "postgresql":
case "oracle":
$result = db_process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
$result = db_process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_component_db
WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
break;
}
if ($result === false) {
echo '<strong>Error getting database components </strong> <br />';
return array();
@ -573,17 +618,21 @@ function um_db_get_database_components ($component_name) {
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component_db
WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
break;
case "postgresql":
case "oracle":
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
$result = db_process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_component_db
WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
break;
}
$cont = 0;
$components = array();
while(true) {
while (true) {
$component = um_std_from_result($result, $cont);
if($component === false) {
break;
@ -602,10 +651,13 @@ 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' => $client_key, 'subscription_limit' => $subscription_limit, 'description' => $description, 'developer' => $developer);
$values = array ('client_key' => $client_key,
'subscription_limit' => $subscription_limit,
'description' => $description,
'developer' => $developer);
$result = db_process_sql_insert(DB_PREFIX.'tupdate_auth', $values);
if ($result === false) {
echo '<strong>Error creating authorization</strong> <br />';
return false;
@ -621,14 +673,14 @@ function um_db_update_auth ($id_auth, $client_key, $subscription_limit, $descrip
}
$values = array ('client_key' => $client_key,
'subscription_limit' => $subscription_limit,
'description' => $description,
'developer' => $developer);
'subscription_limit' => $subscription_limit,
'description' => $description,
'developer' => $developer);
$where = array ('id' => $id_auth);
$result = db_process_sql_update(DB_PREFIX.'tupdate_auth', $values, $where);
if($result === false) {
if ($result === false) {
echo '<strong>Error updating authorization</strong><br />';
return false;
}
@ -637,8 +689,9 @@ function um_db_update_auth ($id_auth, $client_key, $subscription_limit, $descrip
}
function um_db_delete_auth ($id_auth) {
$result = db_process_sql_delete(DB_PREFIX.'tupdate_auth', array('id' => $id_auth));
$result = db_process_sql_delete(DB_PREFIX.'tupdate_auth',
array('id' => $id_auth));
if($result === false) {
echo '<strong>Error deleting authorization</strong><br />';
return false;
@ -661,11 +714,11 @@ function um_db_get_auth ($id_auth) {
$result = db_process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = \''.$id_auth.'\' AND rownum < 2');
break;
}
if ($result === false) {
echo '<strong>Error getting authorization</strong> <br />';
return array();
}
}
$auth = um_std_from_result($result);

View File

@ -30,14 +30,14 @@ function um_xml_rpc_client_call ($server_host, $server_path, $server_port, $prox
$msg = new xmlrpcmsg ($function, $parameters);
$client = new xmlrpc_client($server_path, $server_host, $server_port);
$client->setProxy($proxy, $proxy_port, $proxy_user, $proxy_pass);
if (defined ('XMLRPC_DEBUG'))
$client->setDebug (XMLRPC_DEBUG);
$result = $client->send ($msg, XMLRPC_TIMEOUT, '');
if (! $result) {
trigger_error ('<strong>Open Update Manager</strong> Server comunication error. '.$client->errstr);
return 0;
@ -52,7 +52,7 @@ function um_xml_rpc_client_call ($server_host, $server_path, $server_port, $prox
trigger_error ('<strong>Open Update Manager</strong> XML-RPC error. '.$result->faultString ());
return 0;
}
return $result;
}
@ -75,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 ();
@ -94,44 +94,44 @@ 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 xmlrpcval ($settings->customer_key, 'string'),
new xmlrpcval ($user_key, 'string'),
new xmlrpcval ($settings->current_update, 'int'));
new xmlrpcval ($user_key, 'string'),
new xmlrpcval ($settings->current_update, 'int'));
$result = um_xml_rpc_client_call ($settings->update_server_host,
$settings->update_server_path,
$settings->update_server_port,
$settings->proxy,
$settings->proxy_port,
$settings->proxy_user,
$settings->proxy_pass,
'get_latest_package', $params);
$settings->update_server_path,
$settings->update_server_port,
$settings->proxy,
$settings->proxy_port,
$settings->proxy_user,
$settings->proxy_pass,
'get_latest_package', $params);
if ($result == false) {
return $result;
}
$value = $result->value ();
if ($value->kindOf () == 'scalar') {
/* No new updates */
return $value->scalarval ();
}
$package = um_xml_rpc_unpack_package ($value);
return $package;
}
function um_client_get_package ($settings, $user_key) {
$params = array (new xmlrpcval ($settings->customer_key, 'string'),
new xmlrpcval ($user_key, 'string'),
new xmlrpcval ($settings->current_update, 'int'));
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,
@ -157,23 +157,23 @@ function um_client_get_package ($settings, $user_key) {
function um_client_db_save_package ($package, $settings) {
$fields = array ('id' => $package->id,
'description' => $package->description,
'timestamp' => $package->timestamp);
'description' => $package->description,
'timestamp' => $package->timestamp);
um_client_db_connect($settings);
$result = db_process_sql_insert(DB_PREFIX.'tupdate_package', $fields);
if($result === false) {
return false;
}
return true;
}
function um_client_db_save_update ($update) {
$fields = get_object_vars ($update);
$fields['data'] = base64_encode($fields['data']);
if(isset($fields['data_rollback'])) {
@ -189,7 +189,7 @@ function um_client_db_save_update ($update) {
}
$result = db_process_sql_insert(DB_PREFIX.'tupdate', $fields);
if($result === false) {
return false;
}
@ -232,7 +232,7 @@ function um_client_create_update_file ($data, $md5path_name) {
function um_client_apply_update_database (&$update) {
if ($update->type == 'db_data') {
$exists = db_get_value('COUNT(*)', $update->db_table, $update->db_field, $update->db_field_value);
/* If it exists, it failed. */
if ($exists != 0) {
return false;
@ -241,7 +241,7 @@ function um_client_apply_update_database (&$update) {
$query_array = explode(';',um_data_decode($update->data));
$result = db_process_sql($query_array[0]);
if ($result === false) {
//echo $result->getMessage ();
return false;
@ -254,15 +254,18 @@ function um_client_apply_update (&$update, $settings, $force = true) {
// 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') {
}
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') {
}
else if ($update->type == 'db_data' || $update->type == 'db_schema') {
//mysql_select_db ($settings->dbname);
//mysql_connect ($settings->dbhost, $settings->dbuser, $settings->dbpass);
um_component_db_connect ();
$success = um_client_apply_update_database ($update);
} else {
}
else {
return false;
}
@ -277,10 +280,12 @@ function um_client_rollback_update_file (&$update, $destiny_filename) {
if (! isset ($update->data_rollback))
return true;
$result = file_put_contents ($destiny_filename, um_data_decode ($update->data_rollback));
$result = file_put_contents ($destiny_filename,
um_data_decode ($update->data_rollback));
if ($result === false)
return false;
return true;
}
@ -288,13 +293,16 @@ function um_client_rollback_update (&$update, $settings) {
if ($update->type == 'code') {
$filename = $settings->updating_code_path.'/'.$update->filename;
$success = um_client_rollback_update_file ($update, $filename);
} else if ($update->type == 'binary') {
}
else if ($update->type == 'binary') {
$filename = $settings->updating_binary_path.'/'.$update->filename;
$success = um_client_rollback_update_file ($update, $filename);
} else if ($update->type == 'db_data' || $update->type == 'db_schema') {
}
else if ($update->type == 'db_data' || $update->type == 'db_schema') {
db_process_sql_rollback();
$success = true;
} else {
}
else {
return false;
}
@ -335,11 +343,11 @@ function um_client_get_files ($dir_path) {
else {
$files[$element][] = $dir_path;
}
$cont++;
}
closedir($dir);
return $files;
}
@ -347,20 +355,22 @@ function um_client_print_update ($update, $settings) {
if(isset($update->id)) {
echo 'Update #'.$update->id;
}
echo '<ul>';
echo '<li><em>Type</em>: '.$update->type.'</li>';
if ($update->type == 'code' || $update->type == 'binary') {
if ($update->type == 'code') {
$realpath = HOME_DIR.'/'.$update->filename;
} else {
}
else {
$realpath = $settings->updating_binary_path.'/'.$update->filename;
}
echo '<li><em>Filename</em>: '.$update->filename.'</li>';
echo '<li><em>Realpath</em>: '.$realpath.'</li>';
echo '<li><em>Checksum</em>: '.$update->checksum.'</li>';
echo '<li><em>Writable</em>: '.(is_writable ($realpath) ? 'yes' : '<strong>no</strong>').'</li>';
} else {
}
else {
if(isset($update->db_table))
echo '<li><em>Table</em>: '.$update->db_table.'</li>';
if(isset($update->db_field))
@ -374,12 +384,12 @@ function um_client_print_update ($update, $settings) {
function um_package_info_from_paths ($tmpDir) {
$f = @fopen($tmpDir.'info_package', "r");
if ($f !== false) {
$f_content = fread($f, filesize($tmpDir.'info_package'));
fclose($f);
$f_array = array();
unset($f_content->status);
return json_decode($f_content);
@ -410,7 +420,7 @@ function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type)
$sql_data_file = '02_package_'.$num_package.'_data.oracle.sql';
break;
}
foreach($file_paths as $file_name => $paths) {
if($file_name == $sql_data_file && $type == 'sql') {
$filesize = filesize($tmpDir.$sql_data_file);
@ -423,9 +433,9 @@ function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type)
$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 != '') {
@ -438,14 +448,14 @@ function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type)
$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 != '') {
@ -456,7 +466,7 @@ function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type)
$update[$i]->id_update_package = $num_package;
$i++;
}
}
}
}
else {
foreach($paths as $path) {
@ -465,11 +475,11 @@ function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type)
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 = '';
@ -486,11 +496,11 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
$applied_updates = array ();
$rollback = false;
if(!is_object($package)) {
if (!is_object($package)) {
return false;
}
if(!$update_offline) {
um_client_db_connect ($settings);
um_component_db_connect ();
@ -502,10 +512,10 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
$rollback = true;
break;
}
array_push ($applied_updates, $update);
}
if ($rollback) {
foreach ($applied_updates as $update) {
$success = um_client_rollback_update ($update, $settings);
@ -514,11 +524,11 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
}
um_client_db_save_package ($package, $settings);
foreach ($package->updates as $update) {
um_client_db_save_update ($update);
}
um_db_update_setting ('current_update', $package->id);
db_process_sql_commit();
@ -529,7 +539,7 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
$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']);
@ -545,15 +555,15 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
$tempDirServer = '/'.implode('/',$path_script).'/temp/';
$package_name = 'package_'.$package->id.'.oum';
$zipArchive = $tempDir . $package_name;
$zipArchiveServer = $tempDirServer . $package_name;
$zipArchive = $tempDir . $package_name;
$zipArchiveServer = $tempDirServer . $package_name;
@unlink($zipArchive);
if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) {
if ($zip->open($zipArchive, ZIPARCHIVE::CREATE) === true) {
foreach ($package->updates as $update) {
$filename = '';
switch($update->type) {
case 'code':
case 'binary':
@ -581,7 +591,6 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
}
break;
}
}
// Creating the schema sql script
$success = um_client_create_update_file (um_data_encode($schema_queries), $tempDir."schema_db");
@ -596,11 +605,11 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
// 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
@ -609,18 +618,18 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
}
chdir($tempDir);
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=".$package_name);
header("Pragma: no-cache");
header("Expires: 0");
readfile($package_name);
header("Content-Disposition: attachment; filename="
. $package_name);
header("Pragma: no-cache");
header("Expires: 0");
readfile($package_name);
return true;
}
}
return true;
}
@ -629,20 +638,21 @@ function um_client_upgrade_to_latest ($user_key, $force = true) {
db_process_sql_begin();
do {
$package = um_client_get_package ($settings, $user_key);
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);
}
while (1);
/* Break on error, when there are no more packages on the server (server return true)
or on auth failure (server return false) */
}
@ -650,8 +660,9 @@ function um_client_upgrade_to_latest ($user_key, $force = true) {
function um_client_db_connect (&$settings = NULL) {
if (! $settings)
$settings = um_db_load_settings ();
//mysql_select_db (DB_NAME);
mysql_connect ($settings->dbhost, $settings->dbuser, $settings->dbpass);
mysql_connect ($settings->dbhost, $settings->dbuser,
$settings->dbpass);
}
?>

View File

@ -1048,7 +1048,7 @@
$this->proxy_pass = $proxypassword;
$this->proxy_authtype = $proxyauthtype;
}
/**
* Enables/disables reception of compressed xmlrpc responses.
* Note that enabling reception of compressed responses merely adds some standard
@ -1064,7 +1064,7 @@
else
$this->accepted_compression = array($compmethod);
}
/**
* Enables/disables http compression of xmlrpc request.
* Take care when sending compressed requests: servers might not support them
@ -1076,7 +1076,7 @@
{
$this->request_compression = $compmethod;
}
/**
* Adds a cookie to list of cookies that will be sent to server.
* NB: setting any param but name and value will turn the cookie into a 'version 1' cookie:
@ -1105,7 +1105,7 @@
$this->cookies[$name]['version'] = 0;
}
}
/**
* Directly set cURL options, for extra flexibility
* It allows eg. to bind client to a specific IP interface / address
@ -1115,7 +1115,7 @@
{
$this->extracurlopts = $options;
}
/**
* Set user-agent string that will be used by this client instance
* in http headers sent to the server
@ -1124,7 +1124,7 @@
{
$this->user_agent = $agentstring;
}
/**
* Send an xmlrpc request
* @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request
@ -1134,7 +1134,7 @@
* @access public
*/
function& send($msg, $timeout=0, $method='')
{
{
// if user deos not specify http protocol, use native method of this client
// (i.e. method set during call to constructor)
if($method == '')
@ -1155,10 +1155,10 @@
$n->payload = $msg;
$msg = $n;
}
// where msg is an xmlrpcmsg
$msg->debug=$this->debug;
if($method == 'https')
{
$r =& $this->sendPayloadHTTPS(
@ -1226,7 +1226,7 @@
return $r;
}
/**
* @access private
*/
@ -1238,13 +1238,13 @@
{
$port=80;
}
// Only create the payload if it was not created previously
if(empty($msg->payload))
{
$msg->createPayload($this->request_charset_encoding);
}
$payload = $msg->payload;
// Deflate request body and set appropriate request headers
if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
@ -1410,9 +1410,9 @@
$r =& $msg->parseResponse($ipd, false, $this->return_type);
return $r;
}
/**
* @access private
*/
@ -1426,7 +1426,7 @@
$proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
return $r;
}
/**
* Contributed by Justin Miller <justin@voxel.net>
* Requires curl to be built into PHP
@ -1454,7 +1454,7 @@
return $r;
}
}
if($port == 0)
{
if($method == 'http')
@ -1466,7 +1466,7 @@
$port = 443;
}
}
// Only create the payload if it was not created previously
if(empty($msg->payload))
{

View File

@ -47,17 +47,17 @@ function get_user_key ($settings) {
global $config;
$user_key = exec (escapeshellcmd ($settings->keygen_path.
' '.$settings->customer_key.' '.$config['dbhost'].
' '.$config['dbuser'].' '.$config['dbpass'].
' '.$config['dbname']));
' '.$settings->customer_key.' '.$config['dbhost'].
' '.$config['dbuser'].' '.$config['dbpass'].
' '.$config['dbname']));
return $user_key;
}
/* Free users.
We only want to know this for statistics records.
Feel free to disable this extension if you want.
*/
We only want to know this for statistics records.
Feel free to disable this extension if you want.
*/
global $build_version;
global $pandora_version;

View File

@ -18,7 +18,7 @@ global $config;
check_login ();
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
$config['dbpass'], $config['dbname']);
$config['dbpass'], $config['dbname']);
$settings = um_db_load_settings ();
$error = '';
@ -27,7 +27,7 @@ ui_print_page_header (__('Update manager'), "images/extensions.png", false, "",
if ($settings->customer_key == FREE_USER) {
echo '<div class="notify" style="width: 80%; text-align:left;" >';
echo html_print_image("images/information.png", true) . '&nbsp;';
echo html_print_image("images/information.png", true) . '&nbsp;';
/* Translators: Do not translade Update Manager, it's the name of the program */
echo __('The new <a href="http://updatemanager.sourceforge.net">Update Manager</a> client is shipped with Pandora FMS It helps system administrators to update their Pandora FMS automatically, since the Update Manager does the task of getting new modules, new plugins and new features (even full migrations tools for future versions) automatically.');
echo '<p />';
@ -48,8 +48,9 @@ if ($update_package) {
um_client_upgrade_to_latest ($user_key, $force);
/* TODO: Add a new in tnews */
} else {
}
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>';
}
}
@ -59,9 +60,9 @@ if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) {
if($extension != '.oum') {
$error = '<h5 class="error">'.__('Incorrect file extension').'</h5>';
}
else {
else {
$tempDir = sys_get_temp_dir()."/tmp_oum/";
$zip = new ZipArchive;
if ($zip->open($_FILES["fileloaded"]['tmp_name']) === TRUE) {
$zip->extractTo($tempDir);
@ -74,9 +75,9 @@ if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) {
if ($package === false) {
$error = '<h5 class="error">'.__('Error, the file package is empty or corrupted.').'</h5>';
}
else {
else {
$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>';
}
@ -89,7 +90,7 @@ if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) {
$binary_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path);
}
}
$code_paths = um_client_get_files ($tempDir."code/");
foreach($code_paths as $key => $paths) {
@ -107,7 +108,7 @@ if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) {
}
}
}
$updates_binary = array();
$updates_code = array();
$updates_sql = array();
@ -121,21 +122,21 @@ if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) {
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 ();
echo '<h5 class="suc">'.__('Successfully upgraded').'.</h5>';
$settings = um_db_load_settings ();
}
else {
echo '<h5 class="error">'.__('Cannot be upgraded').'</h5>';
echo '<h5 class="error">'.__('Cannot be upgraded').'</h5>';
}
}
}
@ -154,16 +155,19 @@ $package = um_client_check_latest_update ($settings, $user_key);
if (check_acl ($config['id_user'], 0, 'PM')) {
if ($package === true) {
echo '<h5 class="suc">'.__('Your system is up-to-date').'.</h5>';
} elseif ($package === false) {
}
elseif ($package === false) {
echo '<h5 class="error">'.__('Server authorization rejected').'</h5>';
} elseif ($package === 0) {
}
elseif ($package === 0) {
echo '<h5 class="error">'.__('Server connection failed').'</h5>';
} else {
}
else {
echo '<h5 class="suc">'.__('There\'s a new update for Pandora FMS').'</h5>';
$table->width = '98%';
$table->data = array ();
$table->data[0][0] = '<strong>'.__('Id').'</strong>';
$table->data[0][1] = $package->id;

View File

@ -49,8 +49,9 @@ $table->data[0][1] = html_print_input_text ('keys[customer_key]', $settings->cus
$table->data[1][0] = '<strong>'.__('Update server host').'</strong>';
$table->data[1][1] = html_print_input_text ('keys[update_server_host]', $settings->update_server_host, '', 20, 255, true);
$table->data[2][0] = '<strong>'.__('Update server path').'</strong>';
$table->data[2][1] = html_print_input_text ('keys[update_server_path]', $settings->update_server_path, '', 40, 255, true);
$table->data[2][0] = '<strong>'.__('Update server path').'</strong>'
. ui_print_help_tip (__('The server path is automatically updated with each Pandora Console version.'), true);
$table->data[2][1] = html_print_input_text ('keys[update_server_path]', $settings->update_server_path, '', 40, 255, true, true);
$table->data[3][0] = '<strong>'.__('Update server port').'</strong>';
$table->data[3][1] = html_print_input_text ('keys[update_server_port]', $settings->update_server_port, '', 5, 5, true);
@ -81,3 +82,9 @@ echo '</div>';
echo '</form>';
?>
<style>
#text-keys\[update_server_path\] {
color: grey;
background: #DDDDDD;
}
</style>