Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26c4168cab | ||
|
|
cd34ed0527 | ||
|
|
69e258e8ae | ||
|
|
928dd3ecfa | ||
|
|
b61e746b1e |
@@ -53,6 +53,11 @@ class authentication {
|
|||||||
$this->get_domain();
|
$this->get_domain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set the database as the default plugin
|
||||||
|
if (!isset($_SESSION['authentication']['methods'])) {
|
||||||
|
$_SESSION['authentication']['methods'][] = 'database';
|
||||||
|
}
|
||||||
|
|
||||||
//use the authentication plugins
|
//use the authentication plugins
|
||||||
foreach ($_SESSION['authentication']['methods'] as $name) {
|
foreach ($_SESSION['authentication']['methods'] as $name) {
|
||||||
$class_name = "plugin_".$name;
|
$class_name = "plugin_".$name;
|
||||||
@@ -108,20 +113,37 @@ class authentication {
|
|||||||
if ($_SESSION["user"]["unique"]["text"] != "global") {
|
if ($_SESSION["user"]["unique"]["text"] != "global") {
|
||||||
$username_array = explode("@", check_str($_REQUEST["username"]));
|
$username_array = explode("@", check_str($_REQUEST["username"]));
|
||||||
if (count($username_array) > 1) {
|
if (count($username_array) > 1) {
|
||||||
$this->domain_name = $username_array[count($username_array) -1];
|
//get the domain name
|
||||||
$_REQUEST["username"] = substr(check_str($_REQUEST["username"]), 0, -(strlen($this->domain_name)+1));
|
$domain_name = $username_array[count($username_array) -1];
|
||||||
|
//check if the domain from the username exists then set the domain_uuid
|
||||||
|
$domain_exists = false;
|
||||||
|
foreach ($_SESSION['domains'] as $row) {
|
||||||
|
if (lower_case($row['domain_name']) == lower_case($domain_name)) {
|
||||||
|
$this->domain_uuid = $row['domain_uuid'];
|
||||||
|
$domain_exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if the domain exists then set domain_name and update the username
|
||||||
|
if ($domain_exists) {
|
||||||
|
$this->domain_name = $domain_name;
|
||||||
|
$this->username = substr(check_str($_REQUEST["username"]), 0, -(strlen($domain_name)+1));
|
||||||
|
$_SESSION['domain_uuid'] = $this->domain_uuid;
|
||||||
|
}
|
||||||
|
//unset the domain name variable
|
||||||
|
unset($domain_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//get the domain name from the http value
|
//get the domain name from the http value
|
||||||
if (strlen(check_str($_REQUEST["domain_name"])) > 0) {
|
if (strlen(check_str($_REQUEST["domain_name"])) > 0) {
|
||||||
$this->domain_name = check_str($_REQUEST["domain_name"]);
|
$this->domain_name = check_str($_REQUEST["domain_name"]);
|
||||||
}
|
}
|
||||||
//set
|
//set the domain name
|
||||||
$_SESSION['domain_name'] = $this->domain_name;
|
$_SESSION['domain_name'] = $this->domain_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the domain uuid and domain settings
|
//get the domain uuid and domain settings
|
||||||
if (isset($this->domain_name)) {
|
if (isset($this->domain_name) && !isset($this->domain_uuid)) {
|
||||||
foreach ($_SESSION['domains'] as $row) {
|
foreach ($_SESSION['domains'] as $row) {
|
||||||
if (lower_case($row['domain_name']) == lower_case($this->domain_name)) {
|
if (lower_case($row['domain_name']) == lower_case($this->domain_name)) {
|
||||||
$this->domain_uuid = $row['domain_uuid'];
|
$this->domain_uuid = $row['domain_uuid'];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* plugin_database
|
* plugin_database
|
||||||
*
|
*
|
||||||
* @method validate uses authentication plugins to check if a user is authorized to login
|
* @method validate uses authentication plugins to check if a user is authorized to login
|
||||||
* @method get_domain used to get the domain name from the URL or username and then sets both domain_name and domain_uuid
|
* @method get_domain used to get the domain name from the URL or username and then sets both domain_name and domain_uuid
|
||||||
@@ -52,6 +52,8 @@ class plugin_database {
|
|||||||
//$sql .= "and domain_uuid='".$this->domain_uuid."' ";
|
//$sql .= "and domain_uuid='".$this->domain_uuid."' ";
|
||||||
}
|
}
|
||||||
$sql .= "and (user_enabled = 'true' or user_enabled is null) ";
|
$sql .= "and (user_enabled = 'true' or user_enabled is null) ";
|
||||||
|
//echo $sql."<br />\n";
|
||||||
|
//echo "domain name: ".$this->domain_name;
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
$prep_statement = $db->prepare(check_sql($sql));
|
||||||
if ($_SESSION["user"]["unique"]["text"] != "global") {
|
if ($_SESSION["user"]["unique"]["text"] != "global") {
|
||||||
$prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
|
$prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
|
||||||
@@ -67,7 +69,8 @@ class plugin_database {
|
|||||||
$user_authorized = false;
|
$user_authorized = false;
|
||||||
if (is_array($result)) {
|
if (is_array($result)) {
|
||||||
foreach ($result as &$row) {
|
foreach ($result as &$row) {
|
||||||
//get the domain uuid
|
|
||||||
|
//get the domain uuid when users are unique globally
|
||||||
if ($_SESSION["user"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
|
if ($_SESSION["user"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
|
||||||
//set the domain_uuid
|
//set the domain_uuid
|
||||||
$this->domain_uuid = $row["domain_uuid"];
|
$this->domain_uuid = $row["domain_uuid"];
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* plugin_ldap
|
* plugin_ldap
|
||||||
*
|
*
|
||||||
* @method dap checks a local or remove ldap database to authenticate the user
|
* @method ldap checks a local or remote ldap database to authenticate the user
|
||||||
*/
|
*/
|
||||||
class plugin_ldap {
|
class plugin_ldap {
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ class plugin_ldap {
|
|||||||
public $contact_uuid;
|
public $contact_uuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ldap checks a local or remove ldap database to authenticate the user
|
* ldap checks a local or remote ldap database to authenticate the user
|
||||||
* @return array [authorized] => true or false
|
* @return array [authorized] => true or false
|
||||||
*/
|
*/
|
||||||
function ldap() {
|
function ldap() {
|
||||||
|
|||||||
@@ -64,14 +64,24 @@
|
|||||||
$auth->debug = false;
|
$auth->debug = false;
|
||||||
$result = $auth->validate();
|
$result = $auth->validate();
|
||||||
if ($result["authorized"] == "true") {
|
if ($result["authorized"] == "true") {
|
||||||
// add the user settings
|
// set the session variables
|
||||||
|
$_SESSION["domain_uuid"] = $result["domain_uuid"];
|
||||||
$_SESSION["user_uuid"] = $result["user_uuid"];
|
$_SESSION["user_uuid"] = $result["user_uuid"];
|
||||||
|
|
||||||
// user session array
|
// user session array
|
||||||
$_SESSION["user"]["username"] = $result["username"];
|
$_SESSION["user"]["username"] = $result["username"];
|
||||||
$_SESSION["user"]["user_uuid"] = $result["user_uuid"];
|
$_SESSION["user"]["user_uuid"] = $result["user_uuid"];
|
||||||
$_SESSION["user"]["contact_uuid"] = $result["contact_uuid"];
|
$_SESSION["user"]["contact_uuid"] = $result["contact_uuid"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//debug
|
||||||
|
if ($debug) {
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($result);
|
||||||
|
echo "</pre>";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
//log the failed auth attempt to the system, to be available for fail2ban.
|
//log the failed auth attempt to the system, to be available for fail2ban.
|
||||||
openlog('FusionPBX', LOG_NDELAY, LOG_AUTH);
|
openlog('FusionPBX', LOG_NDELAY, LOG_AUTH);
|
||||||
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] authentication failed for ".$result["username"]);
|
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] authentication failed for ".$result["username"]);
|
||||||
@@ -91,7 +101,7 @@
|
|||||||
$sql .= "where domain_uuid=:domain_uuid ";
|
$sql .= "where domain_uuid=:domain_uuid ";
|
||||||
$sql .= "and user_uuid=:user_uuid ";
|
$sql .= "and user_uuid=:user_uuid ";
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
$prep_statement = $db->prepare(check_sql($sql));
|
||||||
$prep_statement->bindParam(':domain_uuid', $domain_uuid);
|
$prep_statement->bindParam(':domain_uuid', $_SESSION["domain_uuid"] );
|
||||||
$prep_statement->bindParam(':user_uuid', $_SESSION["user_uuid"]);
|
$prep_statement->bindParam(':user_uuid', $_SESSION["user_uuid"]);
|
||||||
$prep_statement->execute();
|
$prep_statement->execute();
|
||||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
@@ -105,10 +115,10 @@
|
|||||||
foreach($_SESSION["groups"] as $field) {
|
foreach($_SESSION["groups"] as $field) {
|
||||||
if (strlen($field['group_name']) > 0) {
|
if (strlen($field['group_name']) > 0) {
|
||||||
if ($x == 0) {
|
if ($x == 0) {
|
||||||
$sql .= "where (domain_uuid = '".$domain_uuid."' and domain_uuid = null) ";
|
$sql .= "where (domain_uuid = '".$_SESSION["domain_uuid"]."' and domain_uuid = null) ";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= "or (domain_uuid = '".$domain_uuid."' and domain_uuid = null) ";
|
$sql .= "or (domain_uuid = '".$_SESSION["domain_uuid"]."' and domain_uuid = null) ";
|
||||||
}
|
}
|
||||||
$sql .= "or group_name = '".$field['group_name']."' ";
|
$sql .= "or group_name = '".$field['group_name']."' ";
|
||||||
$x++;
|
$x++;
|
||||||
|
|||||||
Reference in New Issue
Block a user