diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 3a14f82930..13da9566f0 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,25 @@ +2008-09-02 Esteban Sanchez + + * extensions/update_manager.php: Style correction. Removed force + updating of the settings. + + * extensions/update_manager/load_updatemanager.php: Run the keygen if + the user is not the free one. + + * extensions/update_manager/main.php: Show information message to free + users. + + * extensions/update_manager/settings.php: Allow updating keygen and + binary path settings. + + * extensions/update_manager/lib/*: Updated to latest version of Open + Update Manager. + + * extensions/update_manager/sql/update_manager.sql: Set keygen path. + + * godmode/extensions.php: Bug solved that was avoiding to show defined + extensions. Fixed ACL check. + 2008-09-02 Esteban Sanchez * reporting/fgraph.php: Rollback to r1049. It still needs some tests, diff --git a/pandora_console/extensions/update_manager.php b/pandora_console/extensions/update_manager.php index 41be15c1bd..9bd89c4c1c 100644 --- a/pandora_console/extensions/update_manager.php +++ b/pandora_console/extensions/update_manager.php @@ -49,7 +49,8 @@ function pandora_update_manager_install () { if ($success === false) return; } - $sql = 'INSERT INTO `tconfig` (`token`, `value` ) VALUES ("update_manager_installed", 1)'; + $sql = 'INSERT INTO `tconfig` (`token`, `value`) + VALUES ("update_manager_installed", 1)'; process_sql ($sql); $db =& um_db_connect ('mysql', $config['dbhost'], $config['dbuser'], @@ -87,10 +88,7 @@ function pandora_update_manager_login () { $config['dbpass'], $config['dbname']); $settings = um_db_load_settings (); - um_db_update_setting ('update_server_host', 'www.artica.es'); - um_db_update_setting ('update_server_path', '/pandoraupdate/server.php'); - - $user_key = get_user_key (); + $user_key = get_user_key ($settings); $package = um_client_check_latest_update ($settings, $user_key); diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager.php b/pandora_console/extensions/update_manager/lib/libupdate_manager.php index dd57d15757..03996e8499 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager.php @@ -32,15 +32,30 @@ function um_db_load_settings () { function um_db_update_setting ($key, $value = '') { global $db; - $values = array ($value, $key); - - $sql =& $db->prepare ('UPDATE tupdate_settings SET value = ? WHERE `key` = ?'); - $result =& $db->execute ($sql, $values); + $sql =& $db->prepare ('SELECT COUNT(*) e FROM tupdate_settings WHERE `key` = ?'); + $result =& $db->execute ($sql, $key); if (PEAR::isError ($result)) { echo 'Error: '.$result->getMessage ().'
'; - return false; + 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 'Error: '.$result->getMessage ().'
'; + return false; + } + } else { + $sql =& $db->prepare ('INSERT INTO tupdate_settings (value, `key`) VALUES (?, ?)'); + $result =& $db->execute ($sql, $values); + if (PEAR::isError ($result)) { + echo 'Error: '.$result->getMessage ().'
'; + return false; + } + } return true; } @@ -197,11 +212,11 @@ function um_db_get_package_updates ($id_package) { return $updates; } -function um_db_create_package_log ($id_package, $client_key, $user_package, $result = 'query', $user_subscription = '') { +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); - $sql =& $db->prepare ('INSERT INTO tupdate_package_log (id_update_package, client_key, ip_address, user_package, user_subscription, result) VALUES (?, ?, ?, ?, ?, ?)'); + $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)) { return false; diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php index 3f6baa9a4b..90b4b46733 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php @@ -144,7 +144,7 @@ function um_client_db_save_update ($update) { return true; } -function um_client_apply_update_file ($update, $destiny_filename, $force = false) { +function um_client_apply_update_file (&$update, $destiny_filename, $force = false) { @mkdir (dirname ($destiny_filename), 0777, true); if (file_exists ($destiny_filename)) { @@ -169,7 +169,7 @@ function um_client_apply_update_file ($update, $destiny_filename, $force = false return true; } -function um_client_apply_update_database ($update, $db) { +function um_client_apply_update_database (&$update, &$db) { if ($update->type == 'db_data') { $values = array ($update->db_table, $update->db_field, @@ -191,7 +191,7 @@ function um_client_apply_update_database ($update, $db) { return true; } -function um_client_apply_update ($update, $settings, $db, $force = false) { +function um_client_apply_update (&$update, $settings, $db, $force = false) { if ($update->type == 'code') { $filename = realpath ($settings->updating_code_path.'/'.$update->filename); $success = um_client_apply_update_file ($update, $filename, $force); @@ -209,7 +209,7 @@ function um_client_apply_update ($update, $settings, $db, $force = false) { return true; } -function um_client_rollback_update_file ($update, $destiny_filename) { +function um_client_rollback_update_file (&$update, $destiny_filename) { /* If there's no data rollback, we suppose it's a new file, so it should not be a problem. In any case, it's better than deleting the file. */ if (! isset ($update->data_rollback)) @@ -222,7 +222,7 @@ function um_client_rollback_update_file ($update, $destiny_filename) { return true; } -function um_client_rollback_update ($update, $settings, $db) { +function um_client_rollback_update (&$update, $settings, $db) { if ($update->type == 'code') { $filename = realpath ($settings->updating_code_path.'/'.$update->filename); $success = um_client_rollback_update_file ($update, $filename); @@ -313,7 +313,7 @@ function um_client_upgrade_to_latest ($user_key, $force) { or on auth failure (server return false) */ } -function um_client_db_connect ($settings = NULL) { +function um_client_db_connect (&$settings = NULL) { if (! $settings) $settings = um_db_load_settings (); diff --git a/pandora_console/extensions/update_manager/load_updatemanager.php b/pandora_console/extensions/update_manager/load_updatemanager.php index c42b2277c7..0183bbab88 100644 --- a/pandora_console/extensions/update_manager/load_updatemanager.php +++ b/pandora_console/extensions/update_manager/load_updatemanager.php @@ -7,15 +7,43 @@ error_reporting (E_ALL); /* Database backend, not really tested with other backends, so it's not functional right now */ define ('DB_BACKEND', 'mysql'); +define ('FREE_USER', 'PANDORA-FREE'); if (! extension_loaded ('mysql')) die ('Your PHP installation appears to be missing the MySQL extension which is required.'); require_once ('lib/libupdate_manager.php'); -function get_user_key () { - /* We only want to know this for statistics records. - Feel free to disable if you want. We don't want to hide anything. +function get_user_key ($settings) { + if ($settings->customer_key != FREE_USER) { + if (! file_exists ($settings->keygen_path)) { + echo '

'; + echo __('Keygen file does not exists'); + echo '

'; + + return ''; + } + if (! is_executable ($settings->keygen_path)) { + echo '

'; + echo __('Keygen file is not executable'); + echo '

'; + + return ''; + } + + global $config; + + $user_key = exec (escapeshellcmd ($settings->keygen_path. + ' '.$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. */ $n = (int) get_db_value ('COUNT(`id_agente`)', 'tagente', 'disabled', 0); $m = (int) get_db_value ('COUNT(`id_agente_modulo`)', 'tagente_modulo', diff --git a/pandora_console/extensions/update_manager/main.php b/pandora_console/extensions/update_manager/main.php index 7dd90defb1..637fbe7961 100644 --- a/pandora_console/extensions/update_manager/main.php +++ b/pandora_console/extensions/update_manager/main.php @@ -34,15 +34,17 @@ $settings = um_db_load_settings (); echo '

'.__('Update manager').'

'; -echo '
'; -echo ' '; -/* Translators: Do not translade Update Manager, it's the name of the program */ -echo __('The new Update Manager client is shipped with the new Pandora FMS 2.0. It lets systems administrators to do not need to update their PandoraFMS manually since the Update Manager is the one getting new modules, new plugins and new features (even full migrations tools for future versions) automatically'); -echo '

'; -echo __('Update Manager is one of the most advanced features of PandoraFMS 2.0 Enterprise version, for more information visit http://pandorafms.com'); -echo '

'; +if ($settings->customer_key == FREE_USER) { + echo '
'; + echo ' '; + /* Translators: Do not translade Update Manager, it's the name of the program */ + echo __('The new Update Manager client is shipped with the new Pandora FMS 2.0. It lets systems administrators to do not need to update their PandoraFMS manually since the Update Manager is the one getting new modules, new plugins and new features (even full migrations tools for future versions) automatically'); + echo '

'; + echo __('Update Manager is one of the most advanced features of PandoraFMS 2.0 Enterprise version, for more information visit http://pandorafms.com'); + echo '

'; +} -$user_key = get_user_key (); +$user_key = get_user_key ($settings); $package = um_client_check_latest_update ($settings, $user_key); if (is_int ($package) && $package == 1) { diff --git a/pandora_console/extensions/update_manager/settings.php b/pandora_console/extensions/update_manager/settings.php index 086d6bd6f8..3fa27e4c58 100644 --- a/pandora_console/extensions/update_manager/settings.php +++ b/pandora_console/extensions/update_manager/settings.php @@ -58,6 +58,12 @@ $table->data[2][1] = print_input_text ('keys[update_server_path]', $settings->up $table->data[3][0] = ''.__('Update server port').''; $table->data[3][1] = print_input_text ('keys[update_server_port]', $settings->update_server_port, '', 5, 5, true); +$table->data[4][0] = ''.__('Binary input path').''; +$table->data[4][1] = print_input_text ('keys[updating_binary_path]', $settings->updating_binary_path, '', 40, 255, true); + +$table->data[5][0] = ''.__('Keygen path').''; +$table->data[5][1] = print_input_text ('keys[keygen_path]', $settings->keygen_path, '', 40, 255, true); + print_table ($table); echo '
'; print_input_hidden ('update_settings', 1); diff --git a/pandora_console/extensions/update_manager/sql/update_manager.sql b/pandora_console/extensions/update_manager/sql/update_manager.sql index 0ddaa7ff16..55e35c254e 100644 --- a/pandora_console/extensions/update_manager/sql/update_manager.sql +++ b/pandora_console/extensions/update_manager/sql/update_manager.sql @@ -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', ''), ('update_server_host', 'www.artica.es'), ('update_server_port', '80'), ('update_server_path', '/pandoraupdate/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', ''); +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', '/pandoraupdate/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', ''); CREATE TABLE `tupdate_package` ( id int(11) unsigned NOT NULL auto_increment, timestamp datetime NOT NULL, description mediumtext NOT NULL 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; diff --git a/pandora_console/godmode/extensions.php b/pandora_console/godmode/extensions.php index c8fc4ba703..58ed4a9f1a 100644 --- a/pandora_console/godmode/extensions.php +++ b/pandora_console/godmode/extensions.php @@ -16,12 +16,9 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// Login check -require ("include/config.php"); - check_login (); -if (! give_acl ($config['id_user'], 0, "AR") && ! dame_admin ($config['id_user'])) { +if (! give_acl ($config['id_user'], 0, "PM")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access extensions list"); include ("general/noaccess.php");