2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
<?php
|
|
|
|
|
2009-06-08 20:26:14 +02:00
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2009-06-08 20:26:14 +02:00
|
|
|
// Please see http://pandorafms.org for full contribution list
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
// This program is free software; you can redistribute it and/or
|
2009-06-08 20:26:14 +02:00
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2009-06-08 20:26:14 +02:00
|
|
|
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/dev.php,
include/auth/ldap.php, include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FusionCharts.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/help/en/help_plugin_parameters.php,
include/help/en/help_snmpcommunity.php, include/help/en/help_wmiquery.php,
include/help/en/help_postprocess.php,
include/help/en/help_prediction_source_module.php,
include/help/en/help_date_format.php, include/help/en/help_recontask.php,
include/help/en/help_alert-matches.php, include/help/en/help_tcp_send.php,
include/help/en/help_wmifield.php, include/help/en/help_duplicateconfig.php,
include/help/en/help_agent_status.php,
include/help/en/help_manage_alerts.php, include/help/en/help_wmikey.php,
include/help/en/help_alert_type.php,
include/help/en/help_network_component.php,
include/help/en/help_time_stamp-comparation.php,
include/help/en/help_eventview.php, include/help/en/help_timesource.php,
include/help/en/help_alert_validation.php,
include/help/en/help_map_builder.php,
include/help/en/help_alert_recovery.php,
include/help/en/help_module_type.php,
include/help/en/help_planned_downtime.php,
include/help/en/help_serverlag.php, include/help/en/help_alerts.php,
include/help/en/help_snmpwalk.php,
include/help/en/help_module_definition.php,
include/help/en/help_plugin_definition.php,
include/help/en/help_wminamespace.php, include/help/en/help_snmpoid.php
include/help/en/help_manageconfig.php,
include/help/es/help_alert_validation.php,
include/help/es/help_plugin_parameters.php,
include/help/es/help_snmpcommunity.php, include/help/es/help_wmiquery.php,
include/help/es/help_map_builder.php, include/help/es/help_postprocess.php,
include/help/es/help_date_format.php,
include/help/es/help_alert_recovery.php,
include/help/es/help_prediction_source_module.php,
include/help/es/help_module_type.php,
include/help/es/help_planned_downtime.php,
include/help/es/help_alert-matches.php, include/help/es/help_recontask.php,
include/help/es/help_alerts.php, include/help/es/help_serverlag.php,
include/help/es/help_snmpwalk.php,
include/help/es/help_module_definition.php,
include/help/es/help_tcp_send.php, include/help/es/help_duplicateconfig.php,
include/help/es/help_wmifield.php, include/help/es/help_manage_alerts.php,
include/help/es/help_wmikey.php, include/help/es/help_plugin_definition.php,
include/help/es/help_alert_type.php, include/help/es/help_snmpoid.php,
include/help/es/help_wminamespace.php,
include/help/es/help_network_component.php,
include/help/es/help_time_stamp-comparation.php,
include/help/es/help_manageconfig.php, include/help/es/help_timesource.php,
include/config_process.php, include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change comments blocks for delete the
warnings to construct phpDoc Files, give a struct and order in the
phpDoc files.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1881 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-25 19:39:28 +02:00
|
|
|
/**
|
|
|
|
* @package Include/auth
|
|
|
|
*/
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!isset($config)) {
|
|
|
|
die(
|
|
|
|
'
|
2009-12-08 15:48:59 +01:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
2012-08-20 Miguel de Dios <miguel.dedios@artica.es>
* index.php, extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
general/login_page.php, general/logon_failed.php,
godmode/users/configure_user.php, include/api.php,
include/auth/mysql.php, pandoradb.sql, pandoradb.postgreSQL.sql,
pandoradb.oracle.sql: added the feature to set any user with
"not login" for only the user can work across the API.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-20 20:06:04 +02:00
|
|
|
<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">
|
2018-05-23 18:19:24 +02:00
|
|
|
<meta name="author" content="Artica ST">
|
|
|
|
<meta name="copyright" content="(c) Artica ST">
|
2012-08-20 Miguel de Dios <miguel.dedios@artica.es>
* index.php, extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
general/login_page.php, general/logon_failed.php,
godmode/users/configure_user.php, include/api.php,
include/auth/mysql.php, pandoradb.sql, pandoradb.postgreSQL.sql,
pandoradb.oracle.sql: added the feature to set any user with
"not login" for only the user can work across the API.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-20 20:06:04 +02:00
|
|
|
<meta name="robots" content="index, follow">
|
|
|
|
<link rel="icon" href="../../images/pandora.ico" type="image/ico">
|
|
|
|
<link rel="stylesheet" href="../styles/pandora.css" type="text/css">
|
|
|
|
</head>
|
|
|
|
<body>
|
2021-03-11 15:40:23 +01:00
|
|
|
<div id="main" class="float-left mrgn_lft_100px">
|
2012-08-20 Miguel de Dios <miguel.dedios@artica.es>
* index.php, extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
general/login_page.php, general/logon_failed.php,
godmode/users/configure_user.php, include/api.php,
include/auth/mysql.php, pandoradb.sql, pandoradb.postgreSQL.sql,
pandoradb.oracle.sql: added the feature to set any user with
"not login" for only the user can work across the API.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-20 20:06:04 +02:00
|
|
|
<div align="center">
|
|
|
|
<div id="login_f">
|
|
|
|
<h1 id="log_f" class="error">You cannot access this file</h1>
|
|
|
|
<div>
|
|
|
|
<img src="../../images/pandora_logo.png" border="0" />
|
|
|
|
</div>
|
|
|
|
<div class="msg">
|
|
|
|
<span class="error">
|
|
|
|
<b>ERROR:</b> You can\'t access this file directly!
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
2009-12-08 15:48:59 +01:00
|
|
|
</html>
|
2019-01-30 16:18:44 +01:00
|
|
|
'
|
|
|
|
);
|
2009-06-08 20:26:14 +02:00
|
|
|
}
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
require_once $config['homedir'].'/include/functions_profile.php';
|
|
|
|
enterprise_include('include/auth/mysql.php');
|
|
|
|
|
|
|
|
$config['user_can_update_info'] = true;
|
|
|
|
$config['user_can_update_password'] = true;
|
|
|
|
$config['admin_can_add_user'] = true;
|
|
|
|
$config['admin_can_delete_user'] = true;
|
|
|
|
$config['admin_can_disable_user'] = false;
|
|
|
|
// currently not implemented
|
|
|
|
$config['admin_can_make_admin'] = true;
|
2010-08-10 10:58:03 +02:00
|
|
|
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-11 11:31:18 +01:00
|
|
|
* Process_user_login accepts $login and $pass and handles it according to
|
|
|
|
* current authentication scheme.
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*
|
2020-12-11 11:31:18 +01:00
|
|
|
* @param string $login Login.
|
|
|
|
* @param string $pass Pass.
|
|
|
|
* @param boolean $api Api.
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*
|
2020-12-11 11:31:18 +01:00
|
|
|
* @return mixed False in case of error or invalid credentials, the username in
|
|
|
|
* case it's correct.
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function process_user_login($login, $pass, $api=false)
|
|
|
|
{
|
2020-12-11 11:31:18 +01:00
|
|
|
global $config;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2022-02-16 14:25:25 +01:00
|
|
|
// 0. Check first is user y set as local user.
|
|
|
|
$local_user = (bool) db_get_value_filter(
|
|
|
|
'local_user',
|
|
|
|
'tusuario',
|
|
|
|
['id_user' => $login]
|
|
|
|
);
|
|
|
|
|
2020-12-11 11:26:45 +01:00
|
|
|
// 1. Try remote.
|
2022-02-16 14:25:25 +01:00
|
|
|
if ($local_user !== true && strtolower($config['auth']) != 'mysql') {
|
2020-12-11 11:31:18 +01:00
|
|
|
$login_remote = process_user_login_remote(
|
|
|
|
$login,
|
|
|
|
io_safe_output($pass),
|
|
|
|
$api
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$login_remote = false;
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-12-11 11:26:45 +01:00
|
|
|
// 2. Try local.
|
2021-10-19 13:59:59 +02:00
|
|
|
if ($login_remote === false) {
|
|
|
|
if ($api === true) {
|
|
|
|
$user_not_login = db_get_value(
|
|
|
|
'not_login',
|
|
|
|
'tusuario',
|
|
|
|
'id_user',
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($config['fallback_local_auth']
|
|
|
|
|| is_user_admin($login)
|
2022-04-18 17:46:36 +02:00
|
|
|
|| $local_user === true
|
2021-10-19 13:59:59 +02:00
|
|
|
|| strtolower($config['auth']) == 'mysql'
|
|
|
|
|| (bool) $user_not_login === true
|
|
|
|
) {
|
|
|
|
return process_user_login_local($login, $pass, $api);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
} else {
|
2020-12-11 11:26:45 +01:00
|
|
|
return $login_remote;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2014-03-30 13:30:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
function process_user_login_local($login, $pass, $api=false)
|
|
|
|
{
|
|
|
|
global $config, $mysql_cache;
|
|
|
|
|
|
|
|
// Connect to Database
|
|
|
|
switch ($config['dbtype']) {
|
|
|
|
case 'mysql':
|
|
|
|
if (!$api) {
|
|
|
|
$sql = sprintf(
|
|
|
|
"SELECT `id_user`, `password`
|
2014-03-30 13:30:46 +02:00
|
|
|
FROM `tusuario`
|
|
|
|
WHERE `id_user` = '%s' AND `not_login` = 0
|
2019-01-30 16:18:44 +01:00
|
|
|
AND `disabled` = 0",
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$sql = sprintf(
|
|
|
|
"SELECT `id_user`, `password`
|
2014-03-30 13:30:46 +02:00
|
|
|
FROM `tusuario`
|
|
|
|
WHERE `id_user` = '%s'
|
2019-01-30 16:18:44 +01:00
|
|
|
AND `disabled` = 0",
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'postgresql':
|
|
|
|
if (!$api) {
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT "id_user", "password"
|
2014-03-30 13:30:46 +02:00
|
|
|
FROM "tusuario"
|
|
|
|
WHERE "id_user" = \'%s\' AND "not_login" = 0
|
2019-01-30 16:18:44 +01:00
|
|
|
AND "disabled" = 0',
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT "id_user", "password"
|
2014-03-30 13:30:46 +02:00
|
|
|
FROM "tusuario"
|
|
|
|
WHERE "id_user" = \'%s\'
|
2019-01-30 16:18:44 +01:00
|
|
|
AND "disabled" = 0',
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'oracle':
|
|
|
|
if (!$api) {
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT id_user, password
|
2014-03-30 13:30:46 +02:00
|
|
|
FROM tusuario
|
|
|
|
WHERE id_user = \'%s\' AND not_login = 0
|
2019-01-30 16:18:44 +01:00
|
|
|
AND disabled = 0',
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT id_user, password
|
2014-03-30 13:30:46 +02:00
|
|
|
FROM tusuario
|
|
|
|
WHERE id_user = \'%s\'
|
2019-01-30 16:18:44 +01:00
|
|
|
AND disabled = 0',
|
|
|
|
$login
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$row = db_get_row_sql($sql);
|
|
|
|
|
|
|
|
// Check that row exists, that password is not empty and that password is the same hash
|
|
|
|
if ($row !== false && $row['password'] !== md5('')
|
|
|
|
&& $row['password'] == md5($pass)
|
|
|
|
) {
|
|
|
|
// Login OK
|
|
|
|
// Nick could be uppercase or lowercase (select in MySQL
|
|
|
|
// is not case sensitive)
|
|
|
|
// We get DB nick to put in PHP Session variable,
|
|
|
|
// to avoid problems with case-sensitive usernames.
|
|
|
|
// Thanks to David Muñiz for Bug discovery :)
|
|
|
|
$filter = ['id_usuario' => $login];
|
|
|
|
$user_profile = db_get_row_filter('tusuario_perfil', $filter);
|
|
|
|
if (!users_is_admin($login) && !$user_profile) {
|
|
|
|
$mysql_cache['auth_error'] = 'User does not have any profile';
|
|
|
|
$config['auth_error'] = 'User does not have any profile';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $row['id_user'];
|
|
|
|
} else {
|
|
|
|
if (!user_can_login($login)) {
|
|
|
|
$mysql_cache['auth_error'] = 'User only can use the API.';
|
|
|
|
$config['auth_error'] = 'User only can use the API.';
|
|
|
|
} else {
|
|
|
|
$mysql_cache['auth_error'] = 'User not found in database or incorrect password';
|
|
|
|
$config['auth_error'] = 'User not found in database or incorrect password';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-03-30 13:30:46 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function process_user_login_remote($login, $pass, $api=false)
|
|
|
|
{
|
|
|
|
global $config, $mysql_cache;
|
|
|
|
|
|
|
|
// Remote authentication
|
|
|
|
switch ($config['auth']) {
|
|
|
|
// LDAP
|
|
|
|
case 'ldap':
|
|
|
|
$sr = ldap_process_user_login($login, $pass);
|
2022-03-29 18:59:27 +02:00
|
|
|
// Try with secondary server if not login.
|
|
|
|
if ($sr === false && (bool) $config['secondary_ldap_enabled'] === true) {
|
|
|
|
$sr = ldap_process_user_login($login, $pass, true);
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if (!$sr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Active Directory
|
|
|
|
case 'ad':
|
|
|
|
if (enterprise_hook('ad_process_user_login', [$login, $pass]) === false) {
|
|
|
|
$config['auth_error'] = 'User not found in database or incorrect password';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Remote Pandora FMS
|
|
|
|
case 'pandora':
|
|
|
|
if (enterprise_hook('remote_pandora_process_user_login', [$login, $pass]) === false) {
|
|
|
|
$config['auth_error'] = 'User not found in database or incorrect password';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Remote Integria
|
|
|
|
case 'integria':
|
|
|
|
if (enterprise_hook('remote_integria_process_user_login', [$login, $pass]) === false) {
|
|
|
|
$config['auth_error'] = 'User not found in database or incorrect password';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Unknown authentication method
|
|
|
|
default:
|
2020-10-16 14:00:38 +02:00
|
|
|
$config['auth_error'] = 'User not found in database or incorrect password';
|
2019-01-30 16:18:44 +01:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($config['auth'] === 'ldap') {
|
|
|
|
$login_user_attribute = $login;
|
|
|
|
if ($config['ldap_login_user_attr'] == 'mail') {
|
|
|
|
$login = $sr['mail'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authentication ok, check if the user exists in the local database
|
|
|
|
if (is_user($login)) {
|
|
|
|
if (!user_can_login($login)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-03 17:37:12 +02:00
|
|
|
if (($config['auth'] === 'ad')) {
|
|
|
|
// Check if autocreate remote users is active.
|
|
|
|
if ($config['autocreate_remote_users'] == 1) {
|
2020-09-18 14:50:50 +02:00
|
|
|
if ($config['ad_save_password']) {
|
|
|
|
$update_credentials = change_local_user_pass_ldap($login, $pass);
|
|
|
|
} else {
|
|
|
|
delete_user_pass_ldap($login);
|
|
|
|
}
|
2020-06-03 17:37:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['ad_advanced_config']) && $config['ad_advanced_config']) {
|
|
|
|
$return = enterprise_hook(
|
|
|
|
'prepare_permissions_groups_of_user_ad',
|
|
|
|
[
|
|
|
|
$login,
|
|
|
|
$pass,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
defined('METACONSOLE'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($return === 'error_permissions') {
|
|
|
|
$config['auth_error'] = __('Problems with configuration permissions. Please contact with Administrator');
|
2019-01-30 16:18:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($config['auth'] === 'ldap') {
|
2019-02-27 17:23:59 +01:00
|
|
|
// Check if autocreate remote users is active.
|
|
|
|
if ($config['autocreate_remote_users'] == 1) {
|
|
|
|
if ($config['ldap_save_password']) {
|
|
|
|
$update_credentials = change_local_user_pass_ldap($login, $pass);
|
|
|
|
} else {
|
|
|
|
delete_user_pass_ldap($login);
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 17:23:59 +01:00
|
|
|
$permissions = fill_permissions_ldap($sr);
|
|
|
|
if (empty($permissions)) {
|
|
|
|
$config['auth_error'] = __('User not found in database or incorrect password');
|
2019-01-30 16:18:44 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2019-02-27 17:23:59 +01:00
|
|
|
// check permissions
|
|
|
|
$result = check_permission_ad(
|
|
|
|
$login,
|
|
|
|
$pass,
|
|
|
|
false,
|
|
|
|
$permissions,
|
|
|
|
defined('METACONSOLE')
|
|
|
|
);
|
|
|
|
|
2021-07-27 19:11:04 +02:00
|
|
|
if ($result === 'error_permissions') {
|
2019-02-27 17:23:59 +01:00
|
|
|
$config['auth_error'] = __('Problems with configuration permissions. Please contact with Administrator');
|
2019-01-30 16:18:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $login;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The user does not exist and can not be created
|
|
|
|
if ($config['autocreate_remote_users'] == 0 || is_user_blacklisted($login)) {
|
|
|
|
$config['auth_error'] = __(
|
|
|
|
'Ooops User not found in
|
|
|
|
database or incorrect password'
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($config['auth'] === 'ad'
|
|
|
|
&& (isset($config['ad_advanced_config'])
|
|
|
|
&& $config['ad_advanced_config'])
|
|
|
|
) {
|
2021-05-19 17:08:13 +02:00
|
|
|
if (is_management_allowed() === false) {
|
|
|
|
$config['auth_error'] = __('Please, login into metaconsole first');
|
|
|
|
return false;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2021-10-29 16:12:23 +02:00
|
|
|
$user_info = [
|
|
|
|
'fullname' => $login,
|
|
|
|
'comments' => 'Imported from '.$config['auth'],
|
|
|
|
];
|
|
|
|
|
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
$user_info['metaconsole_access_node'] = $config['ad_adv_user_node'];
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:08:13 +02:00
|
|
|
// Create the user.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (enterprise_hook(
|
|
|
|
'prepare_permissions_groups_of_user_ad',
|
|
|
|
[
|
|
|
|
$login,
|
|
|
|
$pass,
|
2021-10-29 16:12:23 +02:00
|
|
|
$user_info,
|
2019-01-30 16:18:44 +01:00
|
|
|
false,
|
2021-10-29 16:12:23 +02:00
|
|
|
defined('METACONSOLE') && is_centralized() === false,
|
2019-01-30 16:18:44 +01:00
|
|
|
]
|
|
|
|
) === false
|
|
|
|
) {
|
2021-05-19 17:08:13 +02:00
|
|
|
$config['auth_error'] = __('User not found in database or incorrect password');
|
2019-01-30 16:18:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if ($config['auth'] === 'ldap') {
|
2021-05-19 17:08:13 +02:00
|
|
|
if (is_management_allowed() === false) {
|
|
|
|
$config['auth_error'] = __('Please, login into metaconsole first');
|
|
|
|
return false;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 12:48:42 +02:00
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
$user_info['metaconsole_access_node'] = $config['ldap_adv_user_node'];
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$permissions = fill_permissions_ldap($sr);
|
2021-05-19 17:08:13 +02:00
|
|
|
if (empty($permissions) === true) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$config['auth_error'] = __('User not found in database or incorrect password');
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$user_info['fullname'] = $sr['cn'][0];
|
|
|
|
$user_info['email'] = $sr['mail'][0];
|
|
|
|
|
2021-05-19 17:08:13 +02:00
|
|
|
// Create the user.
|
|
|
|
$create_user = create_user_and_permisions_ldap(
|
|
|
|
$login,
|
|
|
|
$pass,
|
|
|
|
$user_info,
|
|
|
|
$permissions,
|
2021-10-19 19:19:55 +02:00
|
|
|
is_metaconsole() && is_centralized() === false
|
2021-05-19 17:08:13 +02:00
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$user_info = [
|
|
|
|
'fullname' => $login,
|
|
|
|
'comments' => 'Imported from '.$config['auth'],
|
|
|
|
];
|
2021-05-19 17:08:13 +02:00
|
|
|
if (is_metaconsole() === true && $config['auth'] === 'ad') {
|
2019-01-30 16:18:44 +01:00
|
|
|
$user_info['metaconsole_access_node'] = $config['ad_adv_user_node'];
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:08:13 +02:00
|
|
|
if (is_management_allowed() === false) {
|
|
|
|
$config['auth_error'] = __('Please, login into metaconsole first');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the user in the local database.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (create_user($login, $pass, $user_info) === false) {
|
|
|
|
$config['auth_error'] = __('User not found in database or incorrect password');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile_create_user_profile(
|
|
|
|
$login,
|
|
|
|
$config['default_remote_profile'],
|
|
|
|
$config['default_remote_group'],
|
|
|
|
false,
|
|
|
|
$config['default_assign_tags']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $login;
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
2016-01-04 16:46:18 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
/**
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* Checks if a user is administrator.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* @param string User id.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
|
|
|
* @return boolean True is the user is admin
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function is_user_admin($id_user)
|
|
|
|
{
|
|
|
|
include_once __DIR__.'/../functions_users.php';
|
|
|
|
return users_is_admin($id_user);
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2009-02-24 12:20:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user id field on a mixed structure.
|
|
|
|
*
|
|
|
|
* This function is needed to make auth system more compatible and independant.
|
|
|
|
*
|
|
|
|
* @param mixed User structure to get id. It might be a row returned from
|
|
|
|
* tusuario or tusuario_perfil. If it's not a row, the int value is returned.
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return integer User id of the mixed parameter.
|
2009-02-24 12:20:34 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function get_user_id($user)
|
|
|
|
{
|
|
|
|
if (is_array($user)) {
|
|
|
|
if (isset($user['id_user'])) {
|
|
|
|
return $user['id_user'];
|
|
|
|
} else if (isset($user['id_usuario'])) {
|
|
|
|
return $user['id_usuario'];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $user;
|
|
|
|
}
|
2009-02-24 12:20:34 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
/**
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* Check is a user exists in the system
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-02-24 12:20:34 +01:00
|
|
|
* @param mixed User id.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
|
|
|
* @return boolean True if the user exists.
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function is_user($user)
|
|
|
|
{
|
|
|
|
$user = db_get_row('tusuario', 'id_user', get_user_id($user));
|
|
|
|
|
|
|
|
if (! $user) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-08-20 Miguel de Dios <miguel.dedios@artica.es>
* index.php, extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
general/login_page.php, general/logon_failed.php,
godmode/users/configure_user.php, include/api.php,
include/auth/mysql.php, pandoradb.sql, pandoradb.postgreSQL.sql,
pandoradb.oracle.sql: added the feature to set any user with
"not login" for only the user can work across the API.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-20 20:06:04 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function user_can_login($user)
|
|
|
|
{
|
|
|
|
$not_login = db_get_value('not_login', 'tusuario', 'id_user', $user);
|
|
|
|
|
|
|
|
if ($not_login != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
/**
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* Gets the users real name
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-02-24 12:20:34 +01:00
|
|
|
* @param mixed User id.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* @return string The users full name
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function get_user_fullname($user)
|
|
|
|
{
|
|
|
|
return (string) db_get_value('fullname', 'tusuario', 'id_user', get_user_id($user));
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
/**
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* Gets the users email
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-02-24 12:20:34 +01:00
|
|
|
* @param mixed User id.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
* @return string The users email address
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function get_user_email($user)
|
|
|
|
{
|
|
|
|
return (string) db_get_value('email', 'tusuario', 'id_user', get_user_id($user));
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
/**
|
|
|
|
* Gets a Users info
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-02-24 12:20:34 +01:00
|
|
|
* @param mixed User id
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*
|
|
|
|
* @return mixed An array of users
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function get_user_info($user)
|
|
|
|
{
|
|
|
|
static $cache_user_info = [];
|
|
|
|
if (array_key_exists($user, $cache_user_info)) {
|
|
|
|
return $cache_user_info[$user];
|
|
|
|
} else {
|
|
|
|
$return = db_get_row('tusuario', 'id_user', get_user_id($user));
|
|
|
|
$cache_user_info[$user] = $return;
|
|
|
|
return $return;
|
|
|
|
}
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
/**
|
|
|
|
* Get a list of all users in an array [username] => array (userinfo)
|
|
|
|
* We can't simplify this because some auth schemes (like LDAP) automatically (or it's at least cheaper to) return all the information
|
|
|
|
* Functions like get_user_info allow selection of specifics (in functions_db)
|
|
|
|
*
|
2009-01-22 18:44:33 +01:00
|
|
|
* @param string Field to order by (id_user, fullname or registered)
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
*
|
|
|
|
* @return array An array of user information
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function get_users($order='fullname', $filter=false, $fields=false)
|
|
|
|
{
|
|
|
|
if (is_array($order)) {
|
|
|
|
$filter['order'] = $order['field'].' '.$order['order'];
|
|
|
|
} else {
|
|
|
|
switch ($order) {
|
|
|
|
case 'registered':
|
|
|
|
case 'last_connect':
|
|
|
|
case 'fullname':
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$order = 'fullname';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$filter['order'] = $order.' ASC';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
|
|
|
|
$result = db_get_all_rows_filter('tusuario', $filter, $fields);
|
|
|
|
if ($result !== false) {
|
|
|
|
foreach ($result as $row) {
|
|
|
|
$output[$row['id_user']] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
2012-08-20 Miguel de Dios <miguel.dedios@artica.es>
* index.php, extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
general/login_page.php, general/logon_failed.php,
godmode/users/configure_user.php, include/api.php,
include/auth/mysql.php, pandoradb.sql, pandoradb.postgreSQL.sql,
pandoradb.oracle.sql: added the feature to set any user with
"not login" for only the user can work across the API.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-20 20:06:04 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
/**
|
|
|
|
* Sets the last login for a user
|
|
|
|
*
|
|
|
|
* @param string User id
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function process_user_contact($id_user)
|
|
|
|
{
|
|
|
|
return db_process_sql_update(
|
|
|
|
'tusuario',
|
|
|
|
['last_connect' => get_system_time()],
|
|
|
|
['id_user' => $id_user]
|
|
|
|
);
|
2009-01-22 18:44:33 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-01-22 18:44:33 +01:00
|
|
|
/**
|
|
|
|
* Create a new user
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return boolean false
|
2009-01-22 18:44:33 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function create_user($id_user, $password, $user_info)
|
|
|
|
{
|
|
|
|
$values = $user_info;
|
|
|
|
$values['id_user'] = $id_user;
|
|
|
|
$values['password'] = md5($password);
|
|
|
|
$values['last_connect'] = 0;
|
|
|
|
$values['registered'] = get_system_time();
|
|
|
|
|
|
|
|
return (@db_process_sql_insert('tusuario', $values)) !== false;
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2012-05-30 14:07:26 +02:00
|
|
|
/**
|
|
|
|
* Save password history
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return boolean false
|
2012-05-30 14:07:26 +02:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function save_pass_history($id_user, $password)
|
|
|
|
{
|
|
|
|
$values['id_user'] = $id_user;
|
|
|
|
$values['password'] = md5($password);
|
|
|
|
$values['date_begin'] = date('Y/m/d H:i:s', get_system_time());
|
|
|
|
|
|
|
|
return (@db_process_sql_insert('tpassword_history', $values)) !== false;
|
2012-05-30 14:07:26 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
/**
|
|
|
|
* Deletes the user
|
|
|
|
*
|
|
|
|
* @param string User id
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function delete_user($id_user)
|
|
|
|
{
|
|
|
|
$result = db_process_sql_delete(
|
|
|
|
'tusuario_perfil',
|
|
|
|
['id_usuario' => $id_user]
|
|
|
|
);
|
|
|
|
if ($result === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = db_process_sql_delete(
|
|
|
|
'tusuario',
|
|
|
|
['id_user' => $id_user]
|
|
|
|
);
|
|
|
|
if ($result === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-01-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* ajax.php, include/config.inc.php, include/config_process.php,
include/functions.php, include/functions_db.php,
include/functions_ui.php, index.php, install.php,
operation/users/user.php, operation/users/user_edit.php,
reporting/fgraph.php: Added pluggable authentication and moved functions
* general/login_page.php, general/logon_ok.php,
godmode/agentes/modificar_agente.php,
godmode/users/configure_users.php, godmode/users/user_list.php,
operation/agentes/estado_agente.php, operation/incidents/incident.php,
operation/incidents/incident_search.php: Updated functions
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-01-20 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
|
|
|
/**
|
|
|
|
* Update the password in MD5 for user pass as id_user with
|
|
|
|
* password in plain text.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
|
|
|
* @param string user User ID
|
|
|
|
* @param string password Password in plain text.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
|
|
|
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function update_user_password($user, $password_new)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
if (isset($config['auth']) && $config['auth'] == 'pandora') {
|
|
|
|
$sql = sprintf(
|
|
|
|
"UPDATE tusuario SET password = '".md5($password_new)."', last_pass_change = '".date('Y-m-d H:i:s', get_system_time())."' WHERE id_user = '".$user."'"
|
|
|
|
);
|
|
|
|
|
|
|
|
$connection = mysql_connect_db(
|
|
|
|
$config['rpandora_server'],
|
|
|
|
$config['rpandora_dbname'],
|
|
|
|
$config['rpandora_user'],
|
|
|
|
$config['rpandora_pass']
|
|
|
|
);
|
|
|
|
$remote_pass_update = db_process_sql($sql, 'affected_rows', $connection);
|
|
|
|
|
|
|
|
if (!$remote_pass_update) {
|
|
|
|
$config['auth_error'] = __('Could not changes password on remote pandora');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return db_process_sql_update(
|
|
|
|
'tusuario',
|
|
|
|
[
|
|
|
|
'password' => md5($password_new),
|
|
|
|
'last_pass_change' => date('Y/m/d H:i:s', get_system_time()),
|
|
|
|
],
|
|
|
|
['id_user' => $user]
|
|
|
|
);
|
2009-01-22 18:44:33 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
|
|
|
/**
|
|
|
|
* Update the data of a user that user is choose with
|
|
|
|
* id_user.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
|
|
|
* @param string user User ID
|
|
|
|
* @param array values Associative array with index as name of field and content.
|
2019-01-30 16:18:44 +01:00
|
|
|
*
|
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
|
|
|
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function update_user($id_user, $values)
|
|
|
|
{
|
|
|
|
if (! is_array($values)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return db_process_sql_update('tusuario', $values, ['id_user' => $id_user]);
|
2009-01-22 18:44:33 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2010-08-10 10:58:03 +02:00
|
|
|
/**
|
|
|
|
* Authenticate against an LDAP server.
|
|
|
|
*
|
|
|
|
* @param string User login
|
|
|
|
* @param string User password (plain text)
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return boolean True if the login is correct, false in other case
|
2010-08-10 10:58:03 +02:00
|
|
|
*/
|
2022-03-29 18:59:27 +02:00
|
|
|
function ldap_process_user_login($login, $password, $secondary_server=false)
|
2019-01-30 16:18:44 +01:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (! function_exists('ldap_connect')) {
|
|
|
|
$config['auth_error'] = __('Your installation of PHP does not support LDAP');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-29 18:59:27 +02:00
|
|
|
$ldap_tokens = [
|
|
|
|
'ldap_server',
|
|
|
|
'ldap_port',
|
|
|
|
'ldap_version',
|
|
|
|
'ldap_base_dn',
|
|
|
|
'ldap_login_attr',
|
|
|
|
'ldap_admin_login',
|
|
|
|
'ldap_admin_pass',
|
|
|
|
'ldap_start_tls',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($ldap_tokens as $token) {
|
|
|
|
$ldap[$token] = $secondary_server === true ? $config[$token.'_secondary'] : $config[$token];
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Connect to the LDAP server
|
2022-03-29 18:59:27 +02:00
|
|
|
if (stripos($ldap['ldap_server'], 'ldap://') !== false
|
|
|
|
|| stripos($ldap['ldap_server'], 'ldaps://') !== false
|
|
|
|
|| stripos($ldap['ldap_server'], 'ldapi://') !== false
|
2021-07-27 19:11:04 +02:00
|
|
|
) {
|
2022-03-29 18:59:27 +02:00
|
|
|
$ds = @ldap_connect($ldap['ldap_server'].':'.$ldap['ldap_port']);
|
2021-07-27 19:11:04 +02:00
|
|
|
} else {
|
2022-03-29 18:59:27 +02:00
|
|
|
$ds = @ldap_connect($ldap['ldap_server'], $ldap['ldap_port']);
|
2021-07-27 19:11:04 +02:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if (!$ds) {
|
|
|
|
$config['auth_error'] = 'Error connecting to LDAP server';
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the LDAP version
|
2022-03-29 18:59:27 +02:00
|
|
|
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $ldap['ldap_version']);
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2022-03-29 18:59:27 +02:00
|
|
|
if ($ldap['ldap_start_tls']) {
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!@ldap_start_tls($ds)) {
|
|
|
|
$config['auth_error'] = 'Could not start TLS for LDAP connection';
|
|
|
|
@ldap_close($ds);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($config['ldap_function'] == 'local') {
|
|
|
|
$sr = local_ldap_search(
|
2022-03-29 18:59:27 +02:00
|
|
|
$ldap['ldap_server'],
|
|
|
|
$ldap['ldap_port'],
|
|
|
|
$ldap['ldap_version'],
|
|
|
|
io_safe_output($ldap['ldap_base_dn']),
|
|
|
|
$ldap['ldap_login_attr'],
|
|
|
|
io_safe_output($ldap['ldap_admin_login']),
|
|
|
|
io_output_password($ldap['ldap_admin_pass']),
|
|
|
|
io_safe_output($login),
|
|
|
|
$ldap['ldap_start_tls']
|
2019-01-30 16:18:44 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($sr) {
|
|
|
|
$user_dn = $sr['dn'][0];
|
|
|
|
|
2022-03-29 18:59:27 +02:00
|
|
|
$ldap_base_dn = !empty($ldap['ldap_base_dn']) ? ','.io_safe_output($ldap['ldap_base_dn']) : '';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if (!empty($ldap_base_dn)) {
|
|
|
|
if (strlen($password) != 0 && @ldap_bind($ds, io_safe_output($user_dn), $password)) {
|
|
|
|
@ldap_close($ds);
|
|
|
|
return $sr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strlen($password) != 0 && @ldap_bind($ds, io_safe_output($login), $password)) {
|
|
|
|
@ldap_close($ds);
|
|
|
|
return $sr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// PHP LDAP function
|
2022-03-29 18:59:27 +02:00
|
|
|
if ($ldap['ldap_admin_login'] != '' && $ldap['ldap_admin_pass'] != '') {
|
|
|
|
if (!@ldap_bind($ds, io_safe_output($ldap['ldap_admin_login']), io_output_password($ldap['ldap_admin_pass']))) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$config['auth_error'] = 'Admin ldap connection fail';
|
|
|
|
@ldap_close($ds);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-29 18:59:27 +02:00
|
|
|
$filter = '('.$ldap['ldap_login_attr'].'='.io_safe_output($login).')';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2022-03-29 18:59:27 +02:00
|
|
|
$sr = ldap_search($ds, io_safe_output($ldap['ldap_base_dn']), $filter);
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
$memberof = ldap_get_entries($ds, $sr);
|
|
|
|
|
|
|
|
if ($memberof['count'] == 0 && !isset($memberof[0]['memberof'])) {
|
|
|
|
@ldap_close($ds);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$memberof = $memberof[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($memberof['count']);
|
2022-03-29 18:59:27 +02:00
|
|
|
$ldap_base_dn = !empty($ldap['ldap_base_dn']) ? ','.io_safe_output($ldap['ldap_base_dn']) : '';
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if (!empty($ldap_base_dn)) {
|
|
|
|
if (strlen($password) != 0 && @ldap_bind($ds, io_safe_output($memberof['dn']), $password)) {
|
|
|
|
@ldap_close($ds);
|
|
|
|
return $memberof;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strlen($password) != 0 && @ldap_bind($ds, io_safe_output($login), $password)) {
|
|
|
|
@ldap_close($ds);
|
|
|
|
return $memberof;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ldap_close($ds);
|
|
|
|
$config['auth_error'] = 'User not found in database or incorrect password';
|
|
|
|
return false;
|
|
|
|
|
2017-11-15 11:57:56 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2010-08-10 13:25:44 +02:00
|
|
|
/**
|
|
|
|
* Checks if a user is in the autocreate blacklist.
|
|
|
|
*
|
|
|
|
* @param string User
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return boolean True if the user is in the blacklist, false otherwise.
|
2010-08-10 13:25:44 +02:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function is_user_blacklisted($user)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$blisted_users = explode(',', $config['autocreate_blacklist']);
|
|
|
|
foreach ($blisted_users as $blisted_user) {
|
|
|
|
if ($user == $blisted_user) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-08-10 13:25:44 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2017-11-15 11:57:56 +01:00
|
|
|
/**
|
|
|
|
* Create progile with data obtaint from AD
|
|
|
|
*
|
|
|
|
* @param string Login
|
|
|
|
* @param string Password
|
|
|
|
* @param array user_info
|
|
|
|
* @param array permiisons
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return boolean
|
2017-11-15 11:57:56 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function create_user_and_permisions_ldap(
|
|
|
|
$id_user,
|
|
|
|
$password,
|
|
|
|
$user_info,
|
|
|
|
$permissions,
|
|
|
|
$syncronize=false
|
|
|
|
) {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$values = $user_info;
|
|
|
|
$values['id_user'] = $id_user;
|
|
|
|
|
2020-09-18 14:50:50 +02:00
|
|
|
if ($config['ldap_save_password'] || $config['ad_save_password']) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$values['password'] = md5($password);
|
|
|
|
}
|
|
|
|
|
|
|
|
$values['last_connect'] = 0;
|
|
|
|
$values['registered'] = get_system_time();
|
|
|
|
if (defined('METACONSOLE') && $syncronize) {
|
|
|
|
$values['metaconsole_access_node'] = $config['ldap_adv_user_node'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = (@db_process_sql_insert('tusuario', $values)) !== false;
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
if (!empty($permissions)) {
|
|
|
|
foreach ($permissions as $permission) {
|
|
|
|
$id_profile = $permission['profile'];
|
|
|
|
$id_groups = $permission['groups'];
|
|
|
|
$tags = $permission['tags'];
|
|
|
|
$no_hierarchy = (bool) $permission['no_hierarchy'] ? 1 : 0;
|
|
|
|
|
|
|
|
foreach ($id_groups as $id_group) {
|
|
|
|
$profile = profile_create_user_profile(
|
|
|
|
$id_user,
|
|
|
|
$id_profile,
|
|
|
|
$id_group,
|
|
|
|
false,
|
|
|
|
$tags,
|
|
|
|
$no_hierarchy
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined('METACONSOLE') && $syncronize) {
|
|
|
|
enterprise_include_once('include/functions_metaconsole.php');
|
|
|
|
|
|
|
|
unset($values['metaconsole_access_node']);
|
|
|
|
$values['not_login'] = (int) !$config['ldap_adv_user_node'];
|
|
|
|
|
|
|
|
$servers = metaconsole_get_servers();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
$perfil_maestro = db_get_row(
|
|
|
|
'tperfil',
|
|
|
|
'id_perfil',
|
|
|
|
$permission['profile']
|
|
|
|
);
|
|
|
|
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
if (!profile_exist($perfil_maestro['name'])) {
|
|
|
|
unset($perfil_maestro['id_perfil']);
|
|
|
|
$id_profile = db_process_sql_insert('tperfil', $perfil_maestro);
|
|
|
|
} else {
|
|
|
|
$id_profile = db_get_value('id_perfil', 'tperfil', 'name', $perfil_maestro['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
db_process_sql_insert('tusuario', $values);
|
|
|
|
foreach ($id_groups as $id_group) {
|
|
|
|
$profile = profile_create_user_profile(
|
|
|
|
$id_user,
|
|
|
|
$id_profile,
|
|
|
|
$id_group,
|
|
|
|
false,
|
|
|
|
$tags,
|
|
|
|
$no_hierarchy
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$profile) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$profile = profile_create_user_profile(
|
|
|
|
$id_user,
|
|
|
|
$config['default_remote_profile'],
|
|
|
|
$config['default_remote_group'],
|
|
|
|
false,
|
|
|
|
$config['default_assign_tags']
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$profile) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-11-15 11:57:56 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2017-11-15 11:57:56 +01:00
|
|
|
/**
|
|
|
|
* Check if user have right permission in pandora. This
|
|
|
|
* permission depend of ldap.
|
|
|
|
*
|
|
|
|
* @param string Login
|
|
|
|
* @param string Password
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function check_permission_ldap(
|
|
|
|
$id_user,
|
|
|
|
$password,
|
|
|
|
$user_info,
|
|
|
|
$permissions,
|
|
|
|
$syncronize=false
|
|
|
|
) {
|
|
|
|
global $config;
|
|
|
|
include_once $config['homedir'].'/enterprise/include/functions_metaconsole.php';
|
|
|
|
|
|
|
|
$result_user = users_get_user_by_id($id_user);
|
|
|
|
$filter = ['id_usuario' => $id_user];
|
|
|
|
$profiles_user = [];
|
|
|
|
$user_profiles = db_get_all_rows_filter('tusuario_perfil', $filter);
|
|
|
|
|
|
|
|
foreach ($user_profiles as $user_profile) {
|
|
|
|
$profiles_user[$user_profile['id_up']] = $user_profile['id_perfil'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$profiles_user_nodes = [];
|
|
|
|
$permissions_nodes = [];
|
|
|
|
if (is_metaconsole() && $syncronize) {
|
|
|
|
$servers = metaconsole_get_servers();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
$user_profiles_nodes = db_get_all_rows_filter('tusuario_perfil', $filter);
|
|
|
|
foreach ($user_profiles_nodes as $user_profile_node) {
|
|
|
|
$profiles_user_nodes[$server['server_name']][$user_profile_node['id_up']] = $user_profile_node['id_perfil'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($permissions as $key => $permission) {
|
|
|
|
$perfil_maestro = db_get_row(
|
|
|
|
'tperfil',
|
|
|
|
'id_perfil',
|
|
|
|
$permission['profile']
|
|
|
|
);
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
if (profile_exist($perfil_maestro['name'])) {
|
|
|
|
$id_profile = db_get_value('id_perfil', 'tperfil', 'name', $perfil_maestro['name']);
|
|
|
|
$permissions_nodes[$server['server_name']][$key] = $permission;
|
|
|
|
$permissions_nodes[$server['server_name']][$key]['profile'] = $id_profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$no_found = [];
|
|
|
|
if ($result_user) {
|
|
|
|
foreach ($permissions as $permission) {
|
|
|
|
$id_profile = $permission['profile'];
|
|
|
|
$id_groups = $permission['groups'];
|
|
|
|
$tags = $permission['tags'];
|
|
|
|
|
|
|
|
foreach ($id_groups as $id_group) {
|
|
|
|
$filter = [
|
|
|
|
'id_usuario' => $id_user,
|
|
|
|
'id_perfil' => $id_profile,
|
|
|
|
'id_grupo' => $id_group,
|
|
|
|
];
|
|
|
|
// ~ Find perfil with advance permissions in
|
|
|
|
// ~ authentication menu. This data depends on
|
|
|
|
// ~ groups where this user it belong.
|
|
|
|
$result_profiles = db_get_row_filter('tusuario_perfil', $filter);
|
|
|
|
if (!$result_profiles) {
|
|
|
|
// If not found save in array.
|
|
|
|
$no_found[] = [
|
|
|
|
'id_perfil' => $id_profile,
|
|
|
|
'id_grupo' => $id_group,
|
|
|
|
'tags' => $tags,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// if profile is find, delete from array.
|
|
|
|
db_process_sql_update(
|
|
|
|
'tusuario_perfil',
|
|
|
|
['tags' => $tags],
|
|
|
|
[
|
|
|
|
'id_usuario' => $id_user,
|
|
|
|
'id_up' => $profiles_user[$id_profile],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
unset($profiles_user[$result_profiles['id_up']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_metaconsole() && $syncronize) {
|
|
|
|
$servers = metaconsole_get_servers();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
foreach ($permissions_nodes[$server['server_name']] as $permission_node) {
|
|
|
|
$id_profile = $permission_node['profile'];
|
|
|
|
$id_groups = $permission_node['groups'];
|
|
|
|
$tags = $permission_node['tags'];
|
|
|
|
|
|
|
|
foreach ($id_groups as $id_group) {
|
|
|
|
$filter = [
|
|
|
|
'id_usuario' => $id_user,
|
|
|
|
'id_perfil' => $id_profile,
|
|
|
|
'id_grupo' => $id_group,
|
|
|
|
];
|
|
|
|
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
$result_profiles = db_get_row_filter('tusuario_perfil', $filter);
|
|
|
|
|
|
|
|
if (!$result_profiles) {
|
|
|
|
// If not found save in array.
|
|
|
|
$no_found_server[$server['server_name']][] = [
|
|
|
|
'id_perfil' => $id_profile,
|
|
|
|
'id_grupo' => $id_group,
|
|
|
|
'tags' => $tags,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// if profile is find, delete from array.
|
|
|
|
db_process_sql_update(
|
|
|
|
'tusuario_perfil',
|
|
|
|
['tags' => $tags],
|
|
|
|
[
|
|
|
|
'id_usuario' => $id_user,
|
|
|
|
'id_up' => $profiles_user_nodes[$server_name][$id_profile],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
unset($profiles_user_nodes[$server_name][$result_profiles['id_up']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($profiles_user) && empty($no_found)) {
|
|
|
|
// The permmisions of user not changed
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
foreach ($profiles_user as $key => $profile_user) {
|
|
|
|
// The other profiles are deleted
|
|
|
|
profile_delete_user_profile($id_user, $key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_metaconsole() && $syncronize) {
|
|
|
|
foreach ($profiles_user_nodes as $server_name => $profile_users) {
|
|
|
|
$server = metaconsole_get_connection($server_name);
|
|
|
|
foreach ($profile_users as $key => $profile_user) {
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
profile_delete_user_profile($id_user, $key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($no_found as $new_profiles) {
|
|
|
|
// Add the missing permissions
|
|
|
|
profile_create_user_profile(
|
|
|
|
$id_user,
|
|
|
|
$new_profiles['id_perfil'],
|
|
|
|
$new_profiles['id_grupo'],
|
|
|
|
false,
|
|
|
|
$new_profiles['tags']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_metaconsole() && $syncronize) {
|
|
|
|
$servers = metaconsole_get_servers();
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (metaconsole_connect($server) == NOERR) {
|
|
|
|
foreach ($no_found_server[$server['server_name']] as $new_profiles) {
|
|
|
|
profile_create_user_profile(
|
|
|
|
$id_user,
|
|
|
|
$new_profiles['id_perfil'],
|
|
|
|
$new_profiles['id_grupo'],
|
|
|
|
false,
|
|
|
|
$new_profiles['tags']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metaconsole_restore_db();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'permissions_changed';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 'error_permissions';
|
|
|
|
}
|
2017-11-15 11:57:56 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-01-08 16:42:23 +01:00
|
|
|
/**
|
|
|
|
* Fill permissions array with setup values
|
|
|
|
*
|
|
|
|
* @param string sr return value from LDAP connection
|
|
|
|
*
|
|
|
|
* @return array with all permission on LDAP authentication
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function fill_permissions_ldap($sr)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$permissions = [];
|
2019-04-10 16:12:22 +02:00
|
|
|
$permissions_profile = [];
|
2019-05-22 13:57:31 +02:00
|
|
|
|
2019-06-20 09:49:54 +02:00
|
|
|
if ((bool) $config['ldap_save_profile'] === false && ($config['ldap_advanced_config'] == 0 || $config['ldap_advanced_config'] == '')) {
|
2019-05-22 13:57:31 +02:00
|
|
|
$result = 0;
|
|
|
|
$result = db_get_all_rows_filter(
|
|
|
|
'tusuario_perfil',
|
|
|
|
['id_usuario' => $sr['uid'][0]]
|
|
|
|
);
|
|
|
|
if ($result == false) {
|
|
|
|
$permissions[0]['profile'] = $config['default_remote_profile'];
|
|
|
|
$permissions[0]['groups'][] = $config['default_remote_group'];
|
|
|
|
$permissions[0]['tags'] = $config['default_assign_tags'];
|
|
|
|
$permissions[0]['no_hierarchy'] = $config['default_no_hierarchy'];
|
|
|
|
return $permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($result as $perms) {
|
|
|
|
$permissions_profile[] = [
|
|
|
|
'profile' => $perms['id_perfil'],
|
|
|
|
'groups' => [$perms['id_grupo']],
|
|
|
|
'tags' => $perms['tags'],
|
|
|
|
'no_hierarchy' => (bool) $perms['no_hierarchy'] ? 1 : 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $permissions_profile;
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:58:34 +02:00
|
|
|
if ($config['ldap_advanced_config'] == 1 && $config['ldap_save_profile'] == 1) {
|
2019-05-14 15:59:35 +02:00
|
|
|
$ldap_adv_perms = json_decode(io_safe_output($config['ldap_adv_perms']), true);
|
2019-06-20 09:49:54 +02:00
|
|
|
return get_advanced_permissions($ldap_adv_perms, $sr);
|
2019-05-14 15:59:35 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 13:57:31 +02:00
|
|
|
if ($config['ldap_advanced_config'] == 1 && $config['ldap_save_profile'] == 0) {
|
2019-05-14 15:59:35 +02:00
|
|
|
$result = db_get_all_rows_filter(
|
|
|
|
'tusuario_perfil',
|
|
|
|
['id_usuario' => $sr['uid'][0]]
|
|
|
|
);
|
|
|
|
if ($result == false) {
|
|
|
|
$ldap_adv_perms = json_decode(io_safe_output($config['ldap_adv_perms']), true);
|
2019-06-20 09:49:54 +02:00
|
|
|
return get_advanced_permissions($ldap_adv_perms, $sr);
|
2019-05-14 15:59:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($result as $perms) {
|
2019-06-20 09:49:54 +02:00
|
|
|
$permissions_profile[] = [
|
|
|
|
'profile' => $perms['id_perfil'],
|
|
|
|
'groups' => [$perms['id_grupo']],
|
|
|
|
'tags' => $perms['tags'],
|
|
|
|
'no_hierarchy' => (bool) $perms['no_hierarchy'] ? 1 : 0,
|
|
|
|
];
|
2019-05-14 15:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return $permissions_profile;
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:58:34 +02:00
|
|
|
if ($config['autocreate_remote_users'] && $config['ldap_save_profile'] == 1) {
|
|
|
|
$permissions[0]['profile'] = $config['default_remote_profile'];
|
|
|
|
$permissions[0]['groups'][] = $config['default_remote_group'];
|
|
|
|
$permissions[0]['tags'] = $config['default_assign_tags'];
|
|
|
|
$permissions[0]['no_hierarchy'] = $config['default_no_hierarchy'];
|
|
|
|
return $permissions;
|
|
|
|
}
|
|
|
|
|
2019-06-20 09:49:54 +02:00
|
|
|
return $permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get permissions in advanced mode.
|
|
|
|
*
|
|
|
|
* @param array ldap_adv_perms
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function get_advanced_permissions($ldap_adv_perms, $sr)
|
|
|
|
{
|
|
|
|
$permissions = [];
|
2019-01-30 16:18:44 +01:00
|
|
|
foreach ($ldap_adv_perms as $ldap_adv_perm) {
|
|
|
|
$attributes = $ldap_adv_perm['groups_ldap'];
|
2019-06-20 09:49:54 +02:00
|
|
|
if (!empty($attributes[0])) {
|
|
|
|
foreach ($attributes as $attr) {
|
|
|
|
$attr = explode('=', $attr, 2);
|
|
|
|
foreach ($sr[$attr[0]] as $s_attr) {
|
|
|
|
if (preg_match('/'.$attr[1].'/', $s_attr)) {
|
|
|
|
$permissions[] = [
|
|
|
|
'profile' => $ldap_adv_perm['profile'],
|
|
|
|
'groups' => $ldap_adv_perm['group'],
|
|
|
|
'tags' => implode(',', $ldap_adv_perm['tags']),
|
|
|
|
'no_hierarchy' => (bool) $ldap_adv_perm['no_hierarchy'] ? 1 : 0,
|
|
|
|
];
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 09:49:54 +02:00
|
|
|
} else {
|
|
|
|
$permissions[] = [
|
|
|
|
'profile' => $ldap_adv_perm['profile'],
|
|
|
|
'groups' => $ldap_adv_perm['group'],
|
|
|
|
'tags' => implode(',', $ldap_adv_perm['tags']),
|
|
|
|
'no_hierarchy' => (bool) $ldap_adv_perm['no_hierarchy'] ? 1 : 0,
|
|
|
|
];
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $permissions;
|
2019-01-08 16:42:23 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2017-09-26 15:41:04 +02:00
|
|
|
/**
|
|
|
|
* Update local user pass from ldap user
|
|
|
|
*
|
|
|
|
* @param string Login
|
|
|
|
* @param string Password
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @return boolean
|
2017-09-26 15:41:04 +02:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function change_local_user_pass_ldap($id_user, $password)
|
|
|
|
{
|
|
|
|
$local_user_pass = db_get_value_filter('password', 'tusuario', ['id_user' => $id_user]);
|
2017-09-26 15:41:04 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return = false;
|
|
|
|
if (md5($password) !== $local_user_pass) {
|
|
|
|
$values_update = [];
|
|
|
|
$values_update['password'] = md5($password);
|
2017-09-26 15:41:04 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return = db_process_sql_update('tusuario', $values_update, ['id_user' => $id_user]);
|
|
|
|
}
|
2017-09-26 15:41:04 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return $return;
|
2017-11-14 16:20:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
function delete_user_pass_ldap($id_user)
|
|
|
|
{
|
|
|
|
$values_update = [];
|
|
|
|
$values_update['password'] = null;
|
|
|
|
|
|
|
|
$return = db_process_sql_update('tusuario', $values_update, ['id_user' => $id_user]);
|
2017-11-14 16:20:26 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return;
|
2017-09-26 15:41:04 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function safe_output_accute($string)
|
|
|
|
{
|
|
|
|
$no_allowed = [
|
|
|
|
'á',
|
|
|
|
'é',
|
|
|
|
'í',
|
|
|
|
'ó',
|
|
|
|
'ú',
|
|
|
|
'Á',
|
|
|
|
'É',
|
|
|
|
'Í',
|
|
|
|
'Ó',
|
|
|
|
'Ú',
|
|
|
|
'ñ',
|
|
|
|
'Ñ',
|
|
|
|
];
|
|
|
|
$allowed = [
|
|
|
|
'a',
|
|
|
|
'e',
|
|
|
|
'i',
|
|
|
|
'o',
|
|
|
|
'u',
|
|
|
|
'A',
|
|
|
|
'E',
|
|
|
|
'I',
|
|
|
|
'O',
|
|
|
|
'U',
|
|
|
|
'n',
|
|
|
|
'N',
|
|
|
|
];
|
|
|
|
$result = str_replace($no_allowed, $allowed, $string);
|
|
|
|
return $result;
|
2017-12-21 11:35:02 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2022-01-21 17:39:11 +01:00
|
|
|
function local_ldap_search(
|
|
|
|
$ldap_host,
|
|
|
|
$ldap_port=389,
|
|
|
|
$ldap_version=3,
|
|
|
|
$dn=null,
|
|
|
|
$access_attr=null,
|
|
|
|
$ldap_admin_user=null,
|
|
|
|
$ldap_admin_pass=null,
|
2022-03-29 18:59:27 +02:00
|
|
|
$user=null,
|
|
|
|
$ldap_start_tls=null
|
2022-01-21 17:39:11 +01:00
|
|
|
) {
|
2019-01-30 16:18:44 +01:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
$filter = '';
|
|
|
|
if (!empty($access_attr) && !empty($user)) {
|
|
|
|
$filter = " -s sub '(".$access_attr.'='.$user.")' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
$tls = '';
|
2022-03-29 18:59:27 +02:00
|
|
|
if ($ldap_start_tls) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$tls = ' -ZZ ';
|
|
|
|
}
|
|
|
|
|
2019-03-27 15:18:37 +01:00
|
|
|
if (stripos($ldap_host, 'ldap://') !== false
|
|
|
|
|| stripos($ldap_host, 'ldaps://') !== false
|
|
|
|
|| stripos($ldap_host, 'ldapi://') !== false
|
|
|
|
) {
|
2019-02-15 09:10:21 +01:00
|
|
|
$ldap_host = ' -H '.$ldap_host.':'.$ldap_port;
|
|
|
|
} else {
|
|
|
|
$ldap_host = ' -h '.$ldap_host.' -p '.$ldap_port;
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$ldap_version = ' -P '.$ldap_version;
|
|
|
|
if (!empty($ldap_admin_user)) {
|
|
|
|
$ldap_admin_user = " -D '".$ldap_admin_user."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($ldap_admin_pass)) {
|
2021-07-27 19:11:04 +02:00
|
|
|
$ldap_admin_pass = ' -w '.escapeshellarg($ldap_admin_pass);
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$dn = " -b '".$dn."'";
|
|
|
|
|
2019-02-08 11:34:47 +01:00
|
|
|
$shell_ldap_search = explode("\n", shell_exec('ldapsearch -LLL -o ldif-wrap=no -x'.$ldap_host.$ldap_version.' -E pr=10000/noprompt '.$ldap_admin_user.$ldap_admin_pass.$dn.$filter.$tls.' | grep -v "^#\|^$" | sed "s/:\+ /=>/g"'));
|
2019-01-30 16:18:44 +01:00
|
|
|
foreach ($shell_ldap_search as $line) {
|
|
|
|
$values = explode('=>', $line);
|
|
|
|
if (!empty($values[0]) && !empty($values[1])) {
|
|
|
|
$user_attr[$values[0]][] = $values[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($user_attr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$base64 = preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $user_attr['dn'][0]);
|
|
|
|
if ($base64) {
|
|
|
|
$user_dn = safe_output_accute(base64_decode($user_attr['dn'][0]));
|
|
|
|
} else {
|
|
|
|
$user_dn = safe_output_accute($user_attr['dn'][0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($user_dn) > 0) {
|
|
|
|
$user_attr['dn'][0] = $user_dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $user_attr;
|
|
|
|
|
2017-12-11 17:19:52 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
// Reference the global use authorization error to last auth error.
|
|
|
|
$config['auth_error'] = &$mysql_cache['auth_error'];
|