Browse Source

otadmin - improve logging and error reporting

Olivier Massot 5 years ago
parent
commit
ce88022c13

+ 7 - 2
ot_admin/Classes/Middleware/OtBackendUserAuthenticator.php

@@ -23,8 +23,13 @@ class OtBackendUserAuthenticator extends BackendUserAuthenticator
     {
         $isOtAdminRoute = (bool)preg_match('/\/otadmin\/.+/', $routePath);
         $ipAllowed = ApiController::isIpAllowed($_SERVER['REMOTE_ADDR']);
-        if ($isOtAdminRoute && $ipAllowed) {
-            return true;
+        if ($isOtAdminRoute) {
+            if ($ipAllowed) {
+                return true;
+            } else {
+                throw new \RuntimeException('An unauthorized IP (' . $_SERVER['REMOTE_ADDR'] . ') ' .
+                                                    'tried to run the following ot-admin command: ' . $_SERVER['QUERY_STRING']);
+            }
         }
         return parent::isLoggedInBackendUserRequired($routePath);
     }

+ 23 - 0
ot_admin/ext_localconf.php

@@ -1,6 +1,11 @@
 <?php
 defined('TYPO3_MODE') || die();
 
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\Log\LogLevel;
+use TYPO3\CMS\Core\Log\Writer\DatabaseWriter;
+use TYPO3\CMS\Core\Log\Writer\FileWriter;
+
 // Because of this issue https://forge.typo3.org/issues/89449,
 // we have to xclass the BackendUserAuthenticator backend middleware
 // to allow routes to be public (but restricted to authorized ips)
@@ -8,3 +13,21 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Backend\Middleware\Backe
     'className' => Opentalent\OtAdmin\Middleware\OtBackendUserAuthenticator::class
 ];
 
+
+$GLOBALS['TYPO3_CONF_VARS']['LOG']['Opentalent']['OtAdmin']['writerConfiguration'] = [
+    // configuration for ERROR level log entries
+    LogLevel::DEBUG => [
+        // add a FileWriter
+        FileWriter::class => [
+            // configuration for the writer
+            'logFile' => Environment::getVarPath() . '/log/typo3_otadmin.log'
+        ]
+    ],
+    LogLevel::WARNING => [
+        // add a DatabaseWriter
+        DatabaseWriter::class => [
+            'logTable' => 'tx_opentalent_log'
+        ]
+    ]
+];
+