Set up logger instance in base constructor. Fixes #270
Signed-off-by: Holger Schletz <holger.schletz@web.de>
This commit is contained in:
@@ -9,6 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
namespace OCA\UserExternal;
|
namespace OCA\UserExternal;
|
||||||
|
|
||||||
|
use OCP\Server;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for external auth implementations that stores users
|
* Base class for external auth implementations that stores users
|
||||||
* on their first login in a local table.
|
* on their first login in a local table.
|
||||||
@@ -23,6 +26,7 @@ namespace OCA\UserExternal;
|
|||||||
*/
|
*/
|
||||||
abstract class Base extends \OC\User\Backend {
|
abstract class Base extends \OC\User\Backend {
|
||||||
protected $backend = '';
|
protected $backend = '';
|
||||||
|
protected readonly LoggerInterface $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new instance, set backend name
|
* Create new instance, set backend name
|
||||||
@@ -31,6 +35,7 @@ abstract class Base extends \OC\User\Backend {
|
|||||||
*/
|
*/
|
||||||
public function __construct($backend) {
|
public function __construct($backend) {
|
||||||
$this->backend = $backend;
|
$this->backend = $backend;
|
||||||
|
$this->logger = Server::get(LoggerInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,14 +37,14 @@ class BasicAuth extends Base {
|
|||||||
);
|
);
|
||||||
$canary = get_headers($this->authUrl, 1, $context);
|
$canary = get_headers($this->authUrl, 1, $context);
|
||||||
if (!$canary) {
|
if (!$canary) {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl,
|
'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl,
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isset(array_change_key_case($canary, CASE_LOWER)['www-authenticate'])) {
|
if (!isset(array_change_key_case($canary, CASE_LOWER)['www-authenticate'])) {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: Mis-configured BasicAuth Url: '.$this->authUrl.', provided URL does not do authentication!',
|
'ERROR: Mis-configured BasicAuth Url: '.$this->authUrl.', provided URL does not do authentication!',
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
@@ -61,7 +61,7 @@ class BasicAuth extends Base {
|
|||||||
$headers = get_headers($this->authUrl, 1, $context);
|
$headers = get_headers($this->authUrl, 1, $context);
|
||||||
|
|
||||||
if (!$headers) {
|
if (!$headers) {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl,
|
'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl,
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
@@ -82,7 +82,7 @@ class BasicAuth extends Base {
|
|||||||
$this->storeUser($uid);
|
$this->storeUser($uid);
|
||||||
return $uid;
|
return $uid;
|
||||||
case "3":
|
case "3":
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: Too many redirects from BasicAuth Url: '.$this->authUrl,
|
'ERROR: Too many redirects from BasicAuth Url: '.$this->authUrl,
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class FTP extends Base {
|
|||||||
*/
|
*/
|
||||||
public function checkPassword($uid, $password) {
|
public function checkPassword($uid, $password) {
|
||||||
if (false === array_search($this->protocol, stream_get_wrappers())) {
|
if (false === array_search($this->protocol, stream_get_wrappers())) {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: Stream wrapper not available: ' . $this->protocol,
|
'ERROR: Stream wrapper not available: ' . $this->protocol,
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class IMAP extends Base {
|
|||||||
$uid = $pieces[0];
|
$uid = $pieces[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: User has a wrong domain! Expecting: '.$this->domain,
|
'ERROR: User has a wrong domain! Expecting: '.$this->domain,
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
@@ -111,7 +111,7 @@ class IMAP extends Base {
|
|||||||
$errorcode === 28) {
|
$errorcode === 28) {
|
||||||
# This is not defined in PHP-8.x
|
# This is not defined in PHP-8.x
|
||||||
# 28: CURLE_OPERATION_TIMEDOUT
|
# 28: CURLE_OPERATION_TIMEDOUT
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: Could not connect to imap server via curl: ' . curl_strerror($errorcode),
|
'ERROR: Could not connect to imap server via curl: ' . curl_strerror($errorcode),
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
@@ -122,12 +122,12 @@ class IMAP extends Base {
|
|||||||
# 9: CURLE_REMOTE_ACCESS_DENIED
|
# 9: CURLE_REMOTE_ACCESS_DENIED
|
||||||
# 67: CURLE_LOGIN_DENIED
|
# 67: CURLE_LOGIN_DENIED
|
||||||
# 94: CURLE_AUTH_ERROR)
|
# 94: CURLE_AUTH_ERROR)
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: IMAP Login failed via curl: ' . curl_strerror($errorcode),
|
'ERROR: IMAP Login failed via curl: ' . curl_strerror($errorcode),
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: IMAP server returned an error: ' . $errorcode . ' / ' . curl_strerror($errorcode),
|
'ERROR: IMAP server returned an error: ' . $errorcode . ' / ' . curl_strerror($errorcode),
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class SMB extends Base {
|
|||||||
$command = self::SMBCLIENT.' '.escapeshellarg('//' . $this->host . '/dummy').' -U '.$uidEscaped.'%'.$password;
|
$command = self::SMBCLIENT.' '.escapeshellarg('//' . $this->host . '/dummy').' -U '.$uidEscaped.'%'.$password;
|
||||||
$lastline = exec($command, $output, $retval);
|
$lastline = exec($command, $output, $retval);
|
||||||
if ($retval === 127) {
|
if ($retval === 127) {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: smbclient executable missing',
|
'ERROR: smbclient executable missing',
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
@@ -56,7 +56,7 @@ class SMB extends Base {
|
|||||||
goto login;
|
goto login;
|
||||||
} elseif ($retval !== 0) {
|
} elseif ($retval !== 0) {
|
||||||
//some other error
|
//some other error
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: smbclient error: ' . trim($lastline),
|
'ERROR: smbclient error: ' . trim($lastline),
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class SSH extends Base {
|
|||||||
*/
|
*/
|
||||||
public function checkPassword($uid, $password) {
|
public function checkPassword($uid, $password) {
|
||||||
if (!extension_loaded('ssh2')) {
|
if (!extension_loaded('ssh2')) {
|
||||||
\OC::$server->getLogger()->error(
|
$this->logger->error(
|
||||||
'ERROR: php-ssh2 PECL module missing',
|
'ERROR: php-ssh2 PECL module missing',
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ class WebDavAuth extends Base {
|
|||||||
public function checkPassword($uid, $password) {
|
public function checkPassword($uid, $password) {
|
||||||
$arr = explode('://', $this->webDavAuthUrl, 2);
|
$arr = explode('://', $this->webDavAuthUrl, 2);
|
||||||
if (! isset($arr) or count($arr) !== 2) {
|
if (! isset($arr) or count($arr) !== 2) {
|
||||||
\OC::$server->getLogger()->error('ERROR: Invalid WebdavUrl: "'.$this->webDavAuthUrl.'" ', ['app' => 'user_external']);
|
$this->logger->error('ERROR: Invalid WebdavUrl: "'.$this->webDavAuthUrl.'" ', ['app' => 'user_external']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
list($protocol, $path) = $arr;
|
list($protocol, $path) = $arr;
|
||||||
$url = $protocol.'://'.urlencode($uid).':'.urlencode($password).'@'.$path;
|
$url = $protocol.'://'.urlencode($uid).':'.urlencode($password).'@'.$path;
|
||||||
$headers = get_headers($url);
|
$headers = get_headers($url);
|
||||||
if ($headers === false) {
|
if ($headers === false) {
|
||||||
\OC::$server->getLogger()->error('ERROR: Not possible to connect to WebDAV Url: "'.$protocol.'://'.$path.'" ', ['app' => 'user_external']);
|
$this->logger->error('ERROR: Not possible to connect to WebDAV Url: "'.$protocol.'://'.$path.'" ', ['app' => 'user_external']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$returnCode = substr($headers[0], 9, 3);
|
$returnCode = substr($headers[0], 9, 3);
|
||||||
|
|||||||
Reference in New Issue
Block a user