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

@ -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,7 +81,8 @@ 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'],

View File

@ -99,7 +99,10 @@ function um_db_update_setting ($key, $value = '') {
}
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 />';
@ -262,7 +265,9 @@ function um_db_create_package_log ($id_package, $client_key, $user_package, $res
}
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 />';
@ -279,12 +284,16 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit =
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 ();
@ -335,7 +344,8 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit =
}
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 />';
@ -392,13 +402,19 @@ 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;
}
@ -409,13 +425,19 @@ function um_db_get_component ($name) {
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;
}
@ -432,7 +454,8 @@ function um_db_get_component ($name) {
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,7 +481,10 @@ 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) {
@ -471,7 +497,9 @@ 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);
@ -506,7 +534,8 @@ function um_delete_directory($dirname) {
}
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 />';
@ -521,13 +550,19 @@ 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;
}
@ -538,13 +573,19 @@ function um_db_get_component_db ($id_component_db) {
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;
}
@ -558,11 +599,15 @@ 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;
}
@ -573,11 +618,15 @@ 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;
}
@ -603,7 +652,10 @@ function um_db_create_auth ($client_key, $subscription_limit, $description = '',
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) {
@ -637,7 +689,8 @@ 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 />';

View File

@ -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;
}
@ -353,14 +361,16 @@ function um_client_print_update ($update, $settings) {
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))
@ -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");
@ -611,14 +620,14 @@ 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("Content-Disposition: attachment; filename="
. $package_name);
header("Pragma: no-cache");
header("Expires: 0");
readfile($package_name);
return true;
}
}
return true;
@ -641,7 +650,8 @@ function um_client_upgrade_to_latest ($user_key, $force = true) {
$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) */
@ -652,6 +662,7 @@ function um_client_db_connect (&$settings = NULL) {
$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

@ -49,7 +49,8 @@ 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>';
}
}
@ -154,11 +155,14 @@ $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%';

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>