From 5533a0f039c97de623d310af38fda03aeb0b5b9b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 31 May 2020 22:49:58 +0200 Subject: [PATCH] add ip support for auditor --- Controller/ApiController.php | 18 +++++++++----- Models/Audit.php | 17 ++++++++++++- Theme/Backend/audit-list.tpl.php | 4 ++-- Theme/Backend/audit-single.tpl.php | 38 +++++++++++++++++++++++------- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index c1b5619..5bd31d4 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -47,6 +47,7 @@ final class ApiController extends Controller * @param string $module Module name * @param string $ref Reference to other model * @param string $content Message + * @param string $ip Ip * * @return void * @@ -62,11 +63,12 @@ final class ApiController extends Controller int $subtype = 0, string $module = null, string $ref = null, - string $content = null + string $content = null, + string $ip = null ) : void { $newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT); - $audit = new Audit(new NullAccount($account), null, $newString, $type, $subtype, $module, $ref, $content); + $audit = new Audit(new NullAccount($account), null, $newString, $type, $subtype, $module, $ref, $content, \ip2long($ip ?? '127.0.0.1')); AuditMapper::create($audit); } @@ -82,6 +84,7 @@ final class ApiController extends Controller * @param string $module Module name * @param string $ref Reference to other model * @param string $content Message + * @param string $ip Ip * * @return void * @@ -97,12 +100,13 @@ final class ApiController extends Controller int $subtype = 0, string $module = null, string $ref = null, - string $content = null + string $content = null, + string $ip = null ) : void { $oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT); $newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT); - $audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $subtype, $module, $ref, $content); + $audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $subtype, $module, $ref, $content, \ip2long($ip ?? '127.0.0.1')); AuditMapper::create($audit); } @@ -118,6 +122,7 @@ final class ApiController extends Controller * @param string $module Module name * @param string $ref Reference to other model * @param string $content Message + * @param string $ip Ip * * @return void * @@ -133,11 +138,12 @@ final class ApiController extends Controller int $subtype = 0, string $module = null, string $ref = null, - string $content = null + string $content = null, + string $ip = null ) : void { $oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT); - $audit = new Audit(new NullAccount($account), $oldString, null, $type, $subtype, $module, $ref, $content); + $audit = new Audit(new NullAccount($account), $oldString, null, $type, $subtype, $module, $ref, $content, \ip2long($ip ?? '127.0.0.1')); AuditMapper::create($audit); } diff --git a/Models/Audit.php b/Models/Audit.php index d97a7ec..04df210 100644 --- a/Models/Audit.php +++ b/Models/Audit.php @@ -130,6 +130,7 @@ class Audit * @param null|string $module Module id * @param null|string $ref Dynamic reference to model * @param null|string $content Additional audit information + * @param int $ip Ip * * @since 1.0.0 */ @@ -141,7 +142,8 @@ class Audit int $subtype = 0, string $module = null, string $ref = null, - string $content = null + string $content = null, + int $ip = 0 ) { $this->createdAt = new \DateTime('now'); $this->createdBy = $account ?? new NullAccount(); @@ -152,6 +154,7 @@ class Audit $this->module = $module; $this->ref = $ref; $this->content = $content; + $this->ip = $ip; } /** @@ -275,4 +278,16 @@ class Audit { return $this->createdAt; } + + /** + * Get ip. + * + * @return int + * + * @since 1.0.0 + */ + public function getIp() : int + { + return $this->ip; + } } diff --git a/Theme/Backend/audit-list.tpl.php b/Theme/Backend/audit-list.tpl.php index f934eba..bef7bbd 100644 --- a/Theme/Backend/audit-list.tpl.php +++ b/Theme/Backend/audit-list.tpl.php @@ -71,8 +71,8 @@ echo $this->getData('nav')->render(); ?>
- getHtml('Previous', '0', '0'); ?> - getHtml('Next', '0', '0'); ?> + getHtml('Previous', '0', '0'); ?> + getHtml('Next', '0', '0'); ?>
diff --git a/Theme/Backend/audit-single.tpl.php b/Theme/Backend/audit-single.tpl.php index 707d292..aa0c959 100644 --- a/Theme/Backend/audit-single.tpl.php +++ b/Theme/Backend/audit-single.tpl.php @@ -12,24 +12,44 @@ */ declare(strict_types=1); +use phpOMS\Views\ViewAbstract; + +/** @var \Modules\Auditor\Models\Audit $audit */ +$audit = $this->getData('audit'); + /** * @var \phpOMS\Views\View $this */ - echo $this->getData('nav')->render(); ?>
-
-
getData('audit')->getOld() ?? ''),
-                        \phpOMS\Views\ViewAbstract::html($this->getData('audit')->getNew() ?? ''),
-                        "\n"
-                    ); ?>
-                
-
+
+ + + + + +
Created By + getCreatedBy()->getName1(); ?> +
Created At + getDateTime($audit->getCreatedAt(), 'long'); ?> +
Module + getModule(); ?> +
IP + getIp()); ?> +
+
+
getOld() ?? ''),
+                            ViewAbstract::html($audit->getNew() ?? ''),
+                            "\n"
+                        ); ?>
+                    
+
+
\ No newline at end of file