aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-12-01 16:30:45 +0100
committerJoas Schilling <coding@schilljs.com>2021-12-01 22:33:41 +0100
commit168c673755eca62008d9bfa81d0185beba1ff24b (patch)
tree11a6a7c57788af6bb5dbdef9216e305e37c2f99d /apps/user_ldap
parent44ecd0d1d5f77e6798c1dd08da8120ba86585758 (diff)
downloadnextcloud-server-168c673755eca62008d9bfa81d0185beba1ff24b.tar.gz
nextcloud-server-168c673755eca62008d9bfa81d0185beba1ff24b.zip
Allow to log DB, redis and LDAP requests into files
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/AppInfo/Application.php9
-rw-r--r--apps/user_ldap/lib/Jobs/Sync.php2
-rw-r--r--apps/user_ldap/lib/LDAP.php16
3 files changed, 23 insertions, 4 deletions
diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php
index 8c48682eddb..79998a580e5 100644
--- a/apps/user_ldap/lib/AppInfo/Application.php
+++ b/apps/user_ldap/lib/AppInfo/Application.php
@@ -75,8 +75,13 @@ class Application extends App implements IBootstrap {
);
});
- $container->registerService(ILDAPWrapper::class, function () {
- return new LDAP();
+ $container->registerService(ILDAPWrapper::class, function (IAppContainer $appContainer) {
+ /** @var IServerContainer $server */
+ $server = $appContainer->get(IServerContainer::class);
+
+ return new LDAP(
+ $server->getConfig()->getSystemValueString('ldap_log_file')
+ );
});
}
diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php
index 10036f8dc12..3d0dd88dfd2 100644
--- a/apps/user_ldap/lib/Jobs/Sync.php
+++ b/apps/user_ldap/lib/Jobs/Sync.php
@@ -317,7 +317,7 @@ class Sync extends TimedJob {
if (isset($argument['ldapWrapper'])) {
$this->ldap = $argument['ldapWrapper'];
} else {
- $this->ldap = new LDAP();
+ $this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
}
if (isset($argument['avatarManager'])) {
diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php
index 7210977e0e4..900f5a7030f 100644
--- a/apps/user_ldap/lib/LDAP.php
+++ b/apps/user_ldap/lib/LDAP.php
@@ -38,14 +38,16 @@ use OCA\User_LDAP\PagedResults\IAdapter;
use OCA\User_LDAP\PagedResults\Php73;
class LDAP implements ILDAPWrapper {
+ protected $logFile = '';
protected $curFunc = '';
protected $curArgs = [];
/** @var IAdapter */
protected $pagedResultsAdapter;
- public function __construct() {
+ public function __construct(string $logFile = '') {
$this->pagedResultsAdapter = new Php73();
+ $this->logFile = $logFile;
}
/**
@@ -349,6 +351,18 @@ class LDAP implements ILDAPWrapper {
private function preFunctionCall($functionName, $args) {
$this->curFunc = $functionName;
$this->curArgs = $args;
+
+ if ($this->logFile !== '' && is_writable($this->logFile)) {
+ $args = array_reduce($this->curArgs, static function (array $carry, $item): array {
+ $carry[] = !is_resource($item) ? $item : '(resource)';
+ return $carry;
+ }, []);
+ file_put_contents(
+ $this->logFile,
+ $this->curFunc . '::' . json_encode($args) . "\n",
+ FILE_APPEND
+ );
+ }
}
/**