diff --git a/auth_changepassword.php b/auth_changepassword.php index edf554b77b..df3864b0ed 100644 --- a/auth_changepassword.php +++ b/auth_changepassword.php @@ -183,6 +183,7 @@ case 'changepassword': VALUES (?, 3, NOW(), ?)', array($user['username'], $_SERVER['REMOTE_ADDR'])); + db_check_password_length(); db_execute_prepared("UPDATE user_auth SET must_change_password = '', password = ? WHERE id = ?", diff --git a/auth_login.php b/auth_login.php index bf65649296..d04014e14f 100644 --- a/auth_login.php +++ b/auth_login.php @@ -202,6 +202,7 @@ if (get_nfilter_request_var('action') == 'login') { if (compat_password_needs_rehash($stored_pass, PASSWORD_DEFAULT)) { $p = compat_password_hash($p, PASSWORD_DEFAULT); + db_check_password_length(); db_execute_prepared('UPDATE user_auth SET password = ? WHERE username = ?', diff --git a/cacti.sql b/cacti.sql index b6d0444e1e..47c952c790 100644 --- a/cacti.sql +++ b/cacti.sql @@ -2465,7 +2465,7 @@ CREATE TABLE snmp_query_graph_sv ( CREATE TABLE user_auth ( `id` mediumint(8) unsigned NOT NULL auto_increment, `username` varchar(50) NOT NULL default '0', - `password` varchar(2048) NOT NULL default '', + `password` varchar(256) NOT NULL default '', `realm` mediumint(8) NOT NULL default '0', `full_name` varchar(100) default '0', `email_address` varchar(128) NULL, diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 817edf71cf..fa150b5e93 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -87,6 +87,7 @@ Cacti CHANGELOG -feature#1709: Dont warn when attempting to make updates in the past -feature#1711: Support specifying MySQL SSL file paths in the database API -feature#1731: Warn a user if they are going off page and there are unsaved changes +-feature: New Install/Upgrade user permission to limit access to being able to upgrade -feature: Make Graph and Data Source suggested naming more efficient -feature: Make tree editing responive -feature: Add support for DDERIVE and DCOUNTER to Cacti diff --git a/include/auth.php b/include/auth.php index 37c16ca242..740f1789d8 100644 --- a/include/auth.php +++ b/include/auth.php @@ -111,25 +111,80 @@ if (read_config_option('auth_method') != 0) { $realm_id = $user_auth_realm_filenames[get_current_page()]; } + /* Are we upgrading from a version before 1.2 which has the Install/Upgrade realm 26 */ + if ($realm_id == 26 && cacti_version_compare(get_cacti_version(), '1.2', '<')) { + /* See if we can find any users that are allowed to upgrade */ + $install_sql_query = ' + SELECT COUNT(*) + FROM ( + SELECT realm_id + FROM user_auth_realm AS uar + WHERE uar.realm_id = ?'; + $install_sql_params = array($realm_id); + + /* See if the group realms exist and if so, check if permission exists there too */ + if (db_table_exists('user_auth_group_realm')) { + $install_sql_query .= ' + UNION + SELECT realm_id + FROM user_auth_group_realm AS uagr + INNER JOIN user_auth_group_members AS uagm + ON uagr.group_id=uagm.group_id + INNER JOIN user_auth_group AS uag + ON uag.id=uagr.group_id + WHERE uag.enabled="on" + AND uagr.realm_id = ?'; + $install_sql_params = array_merge($install_sql_params, array($realm_id)); + } + $install_sql_query .= ' + ) AS authorized'; + $has_install_user = db_fetch_cell_prepared($install_sql_query, $install_sql_params); + + if (!$has_install_user) { + /* We did not find any existing users who can upgrade/install so add any admin * + * who has access to the system settings (realm 15) by default */ + db_execute('INSERT INTO `user_auth_realm` (realm_id, user_id) + SELECT 26 as realm_id, ua.id + FROM user_auth ua + INNER JOIN user_auth_realm uar + ON uar.user_id=ua.id + LEFT JOIN user_auth_realm uar2 + ON uar2.user_id=ua.id + AND uar2.realm_id=26 + WHERE uar.realm_id=15 + AND uar2.user_id IS NULL'); + } + } + if ($realm_id > 0) { - $authorized = db_fetch_cell_prepared('SELECT COUNT(*) - FROM ( - SELECT realm_id - FROM user_auth_realm AS uar - WHERE uar.user_id = ? - AND uar.realm_id = ? - UNION - SELECT realm_id - FROM user_auth_group_realm AS uagr - INNER JOIN user_auth_group_members AS uagm - ON uagr.group_id=uagm.group_id - INNER JOIN user_auth_group AS uag - ON uag.id=uagr.group_id - WHERE uag.enabled="on" - AND uagm.user_id = ? - AND uagr.realm_id = ? - ) AS authorized', - array($_SESSION['sess_user_id'], $realm_id, $_SESSION['sess_user_id'], $realm_id)); + $auth_sql_query = ' + SELECT COUNT(*) + FROM ( + SELECT realm_id + FROM user_auth_realm AS uar + WHERE uar.user_id = ? + AND uar.realm_id = ?'; + $auth_sql_params = array($_SESSION['sess_user_id'], $realm_id); + + /* Because we now expect installation to be done by authorized users, check the group_realm * + * exists before using it as this may not be present if upgrading from pre-1.x */ + if (db_table_exists('user_auth_group_realm')) { + $auth_sql_query .= ' + UNION + SELECT realm_id + FROM user_auth_group_realm AS uagr + INNER JOIN user_auth_group_members AS uagm + ON uagr.group_id=uagm.group_id + INNER JOIN user_auth_group AS uag + ON uag.id=uagr.group_id + WHERE uag.enabled="on" + AND uagm.user_id = ? + AND uagr.realm_id = ?'; + $auth_sql_params = array_merge($auth_sql_params, array($_SESSION['sess_user_id'], $realm_id)); + } + $auth_sql_query .= ' + ) AS authorized'; + $authorized = db_fetch_cell_prepared($auth_sql_query, $auth_sql_params); } else { $authorized = false; } @@ -141,20 +196,27 @@ if (read_config_option('auth_method') != 0) { $goBack = "[" . __('Login Again') . "]"; } + $title_header = __('Permission Denied'); + $title_body = '

' . __('You are not permitted to access this section of Cacti.') . '

' . __('If you feel that this is an error. Please contact your Cacti Administrator.'); + + if ($realm_id == 26) { + $title_header = __('Installation In Progress'); + $title_body = '

' . __('There is an Installation or Upgrade in progress.') . '

' . __('Only Cacti Administrators with Install/Upgrade privilege may login at this time') . '

'; + } print "\n"; print "\n"; print "\n"; - html_common_header(__('Permission Denied')); + html_common_header($title_header); print "\n"; print "
- " . __('Permission Denied') . " + " . $title_header . "
-

" . __('You are not permitted to access this section of Cacti.') . '

' . __('If you feel that this is an error. Please contact your Cacti Administrator.') . - "

+ " . $title_body . " +

" . $goBack . "
diff --git a/include/global_arrays.php b/include/global_arrays.php index d8ffa924ef..feeb3c91f2 100644 --- a/include/global_arrays.php +++ b/include/global_arrays.php @@ -251,6 +251,12 @@ $messages = array( 'nopassword' => array( 'message' => __('You are not allowed to change your password.'), 'type' => 'error'), + 'nopasswordlen' => array( + 'message' => __('Unable to determine size of password field, please check permissions of db user'), + 'type' => 'error'), + 'nopasswordinc' => array( + 'message' => __('Unable to increase size of password field, pleas check permission of db user'), + 'type' => 'error'), 'nodomainpassword' => array( 'message' => __('LDAP/AD based password change not supported.'), 'type' => 'error'), @@ -1007,6 +1013,7 @@ $user_auth_realms = array( 1 => __('User Management'), 15 => __('Settings and Utilities'), 23 => __('Automation Settings'), + 26 => __('Installation And Upgrades'), 2 => __('Data Input Methods'), 13 => __('Data Queries'), @@ -1037,7 +1044,7 @@ $user_auth_roles = array( 'Normal User' => array(7, 19, 20, 22, 24, 25), 'Template Editor' => array(8, 2, 9, 10, 11, 12, 13, 14, 16, 17), 'General Administration' => array(8, 3, 4, 5, 23, 1043), - 'System Administration' => array(8, 15, 1, 18, 21, 101) + 'System Administration' => array(8, 15, 26, 1, 18, 21, 101) ); $user_auth_realm_filenames = array( @@ -1068,7 +1075,8 @@ $user_auth_realm_filenames = array( 'host.php' => 3, 'host_templates.php' => 12, 'index.php' => 8, - 'step_json.php' => 8, + 'install.php' => 26, + 'step_json.php' => 26, 'managers.php' => 15, 'rrdcleaner.php' => 15, 'settings.php' => 15, diff --git a/install/index.php b/install/index.php index 117274ec6d..e43f5eafbb 100644 --- a/install/index.php +++ b/install/index.php @@ -23,81 +23,4 @@ */ error_reporting(E_ALL); -define('IN_CACTI_INSTALL', 1); - -include_once('../include/auth.php'); -include_once('../lib/api_data_source.php'); -include_once('../lib/api_device.php'); -include_once('../lib/utility.php'); -include_once('../lib/import.php'); -include_once('./functions.php'); - -set_default_action(); - -if (isset_request_var('theme')) { - $theme = get_nfilter_request_var('theme'); - $_SESSION['install_theme'] = get_nfilter_request_var('theme'); -} elseif (isset($_SESSION['install_theme'])) { - $theme = $_SESSION['install_theme']; -} else { - $theme = 'modern'; -} - -if (isset_request_var('language')) { - $language = get_nfilter_request_var('language'); - $_SESSION['install_language'] = get_nfilter_request_var('language'); - set_user_setting('user_language', $language); -} elseif (isset($_SESSION['install_language'])) { - $language = $_SESSION['install_language']; -} else { - $language = read_user_setting('user_language', get_new_user_default_language(), true); -} - -// database test -if (get_nfilter_request_var('action') == 'testdb') { - if (get_nfilter_request_var('location') == 'local') { - install_test_local_database_connection(); - } else { - install_test_remote_database_connection(); - } - - exit; -} - -include_once('../lib/installer.php'); -?> - - - - - - - - - -
-
-
-
-
-
- -
-
-
- - - - -
-
-
-
- - - +header('location: install.php'); diff --git a/install/install.php b/install/install.php new file mode 100644 index 0000000000..117274ec6d --- /dev/null +++ b/install/install.php @@ -0,0 +1,103 @@ + + + + + + + + + + +
+
+
+
+
+
+ +
+
+
+ + + + +
+
+
+
+ + + diff --git a/install/upgrades/1_2_0.php b/install/upgrades/1_2_0.php index bc0355ab23..146bfafe8b 100644 --- a/install/upgrades/1_2_0.php +++ b/install/upgrades/1_2_0.php @@ -80,7 +80,10 @@ function upgrade_to_1_2_0() { ADD COLUMN `same_sysname` char(2) DEFAULT '' AFTER `add_to_cacti`"); } - db_install_execute("ALTER TABLE graph_tree_items + db_install_execute("ALTER TABLE user_auth + MODIFY COLUMN password varchar(256) NOT NULL DEFAULT ''"); + + db_install_execute("ALTER TABLE graph_tree_items MODIFY COLUMN sort_children_type tinyint(3) unsigned NOT NULL DEFAULT '0'"); db_install_execute('UPDATE graph_templates_graph diff --git a/lib/auth.php b/lib/auth.php index 68c08a1ac1..376e68ffcf 100644 --- a/lib/auth.php +++ b/lib/auth.php @@ -2385,5 +2385,5 @@ function compat_password_needs_rehash($password, $algo, $options = array()) { password_needs_rehash($password, $algo); } - return md5($password); + return true; } diff --git a/lib/database.php b/lib/database.php index 4e2d1725e9..9980a91af9 100644 --- a/lib/database.php +++ b/lib/database.php @@ -1109,3 +1109,56 @@ function db_qstr($s, $db_conn = false) { function db_strip_control_chars($sql) { return trim(clean_up_lines($sql), ';'); } + +function db_get_column_attributes($table, $columns) { + if (empty($columns) || empty($table)) { + return false; + } + + if (!is_array($columns)) { + $columns = explode(',', $columns); + } + + $sql = 'SELECT * FROM information_schema.columns WHERE table_name = ? and column_name IN ('; + $column_names = array(); + foreach ($columns as $column) { + if (!empty($column)) { + $sql .= (sizeof($column_names) ? ',' : '') . '?'; + $column_names[] = $column; + } + } + $sql .= ')'; + + $params = array_merge(array($table), $column_names); + return db_fetch_assoc_prepared($sql, $params); +} + +function db_get_columns_length($table, $columns) { + $column_data = db_get_column_attributes($table, $columns); + if (!empty($column_data)) { + return array_rekey($column_data, 'COLUMN_NAME','CHARACTER_MAXIMUM_LENGTH'); + } + return false; +} + +function db_get_column_length($table, $column) { + $column_data = db_get_columns_length($table, $column); + if (!empty($column_data) && isset($column_data[$column])) { + return $column_data[$column]; + } + return false; +} + +function db_check_password_length() { + $len = db_get_column_length('user_auth','password'); + if ($len === false) { + die(__('Failed to determine password field length, can not continue as may corrupt password')); + } else if ($len < 80) { + /* Ensure that the password length is increased before we start updating it */ + db_execute("ALTER TABLE user_auth MODIFY COLUMN password varchar(256) NOT NULL default ''"); + $len = db_get_column_length('user_auth','password'); + if ($len < 80) { + die(__('Failed to alter password field length, can not continue as may corrupt password')); + } + } +} diff --git a/resource/snmp_queries/interface.xml b/resource/snmp_queries/interface.xml index 7bf3c3308b..97b1a86436 100644 --- a/resource/snmp_queries/interface.xml +++ b/resource/snmp_queries/interface.xml @@ -39,6 +39,7 @@ Alias (IF-MIB) walk + ascii value input .1.3.6.1.2.1.31.1.1.1.18 @@ -46,6 +47,7 @@ Type walk + ascii value input .1.3.6.1.2.1.2.2.1.3