X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fauth_ejabberd.php;h=490ea0d1cb8e44982100690be9a92d229d456abb;hb=0cd9db9cb7f4c96f597e37590a536eaae123238d;hp=e1900dc7304df8501794b5f9537fc050d59f3e85;hpb=d489ba1510a2dcfaa7851d937d3c37a9541544c9;p=friendica.git diff --git a/include/auth_ejabberd.php b/include/auth_ejabberd.php index e1900dc730..490ea0d1cb 100755 --- a/include/auth_ejabberd.php +++ b/include/auth_ejabberd.php @@ -32,6 +32,8 @@ * */ +use Friendica\App; + if (sizeof($_SERVER["argv"]) == 0) die(); @@ -47,8 +49,9 @@ require_once("boot.php"); global $a, $db; -if (is_null($a)) - $a = new App; +if (is_null($a)) { + $a = new App(dirname(__DIR__)); +} if (is_null($db)) { @include(".htconfig.php"); @@ -86,7 +89,7 @@ class exAuth { // Open the logfile if the logfile name is defined if ($this->sLogFile != '') - $this->rLogFile = fopen($this->sLogFile, "a") or die("Error opening log file: ". $this->sLogFile); + $this->rLogFile = fopen($this->sLogFile, "a") || die("Error opening log file: ". $this->sLogFile); $this->writeLog("[exAuth] start"); @@ -146,7 +149,7 @@ class exAuth { * @param array $aCommand The command array */ private function isuser($aCommand) { - global $a; + $a = get_app(); // Check if there is a username if (!isset($aCommand[1])) { @@ -159,14 +162,19 @@ class exAuth { $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]); $this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]); - // If the hostnames doesn't match, we try to check remotely - if ($a->get_hostname() != $aCommand[2]) - $found = $this->check_user($aCommand[2], $aCommand[1], true); - else { + // Does the hostname match? So we try directly + if ($a->get_hostname() == $aCommand[2]) { $sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'"; $this->writeDebugLog("[debug] using query ". $sQuery); $r = q($sQuery); $found = dbm::is_result($r); + } else { + $found = false; + } + + // If the hostnames doesn't match or there is some failure, we try to check remotely + if (!$found) { + $found = $this->check_user($aCommand[2], $aCommand[1], true); } if ($found) { @@ -214,7 +222,7 @@ class exAuth { * @param array $aCommand The command array */ private function auth($aCommand) { - global $a; + $a = get_app(); // check user authentication if (sizeof($aCommand) != 4) { @@ -227,10 +235,8 @@ class exAuth { $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]); $this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]); - // If the hostnames doesn't match, we try to authenticate remotely - if ($a->get_hostname() != $aCommand[2]) - $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true); - else { + // Does the hostname match? So we try directly + if ($a->get_hostname() == $aCommand[2]) { $sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'"; $this->writeDebugLog("[debug] using query ". $sQuery); if ($oResult = q($sQuery)) { @@ -246,6 +252,13 @@ class exAuth { $this->writeLog("[exAuth] got password ".$oConfig[0]["v"]); $Error = ($aCommand[3] != $oConfig[0]["v"]); } + } else { + $Error = true; + } + + // If the hostnames doesn't match or there is some failure, we try to check remotely + if ($Error) { + $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true); } if ($Error) { @@ -322,4 +335,3 @@ class exAuth { fclose($this->rLogFile); } } -?>