Audit Log

Got something cool to share with AppGini users? Feel free to post it here!
zkarwinkar
Veteran Member
Posts: 32
Joined: 2021-06-12 21:01

Re: Audit Log

Post by zkarwinkar » 2021-06-30 17:39

How to manually install this plugin ?

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2021-07-01 05:07

Hi,

please read the documentation provided in the ZIP file. This also explains how to install manually.
But I strongly recommend using the plugin, even if this means, you would need to by a plugin first - but it will safe you lot's of work and make the installation of future versions and in other files faster ... actually needing a few clicks only.

Olaf

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2021-07-01 14:46

I have installed the Audit log 1.93 via the plugins 'Audit log for Appgini', however Audit log menu was not shown in the admin page.

I am using XAMPP to run the application, the following is the structure of the folder:
Using Xampp (htdocs)
Application installed in test folder.
C:\xampp\htdocs\test

Plugins folder:
C:\xampp\htdocs\test\plugins

-plugins-resources
-projects
-audit (unzip the github contents into this folder- app-resources, etc...)

After run the plugin installation, audit folder is generated in hooks folder.
Hooks folder:
C:\xampp\htdocs\test\hooks
-audit (auditLog_functions.php, etc...)

I also have auditLog_functions.php in the hooks.

It seems that the application is trying to read the auditLog_functions in hooks, instead of hooks/audit folder. Wonder what went wrong here? Any suggestions?

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2021-07-07 09:04

Finally, I discovered that the menu was not showed up because I have to manually add it in the 'admin/incHeader.php' as shown in documentation pg. 11 section 3.2

After put the code, the menu will show up in the left instead of right.

I also also check on the config.php but no code was appending at the bottom as shown in pg. 11 section 3.1

I have manually copy and paste the code in config.php and refresh the page but the page doesn't render. I get a feeling something is not right in the code.

I wonder whether the plugin installation covers the appending of code in config.php and incHeader.php as well. Or, it required to be done manually.

It is because what happened in my case is only the files was properly generated and moved to the respective directories (admin and hooks/audit folder after enable the audit log for Appgini.

I need help here especially from those who have successfully installed it?

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2021-07-10 06:11

I would like to just share my own experience, despite encounter some clichés, but the overall audit is still functional.

After plugin installation:
I discovered that the menu was not showed up then I have to manually add it in the 'admin/incHeader.php' as shown in documentation pg. 11 section 3.2 I have seen the code, in _global.php, the code was require the scripts.php which associate to the js to render audit menu.

I am not proficient enough to address this. But, if you put the code manually, the menu will show up in the left instead of right. Just beware of overwriting of this code at every Appgini code generation.

I also also check on the config.php but no code was appending at the bottom as shown in pg. 11 section 3.1
The plugins installation will not append code in config.php, instead the code is put at _global.php which include the 'audit/scripts.php'

My installation [plugins]
1) create a folder named 'audit' in plugins folder (this folder exists if you have purchase plugins before)
2) download the code https://github.com/myappgini/sbm_audit_log and place the content in the zip in 'audit' folder
3) Go to admin page, under plugin+ menu, select 'Audit Log for Appgini'
4) Click the 'enable Audit' button. There you go..

I am grateful to Jsetzer and landinialejandro for creating this plugin and make it FREE anyway.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2021-07-29 07:49

Hi sacgtdev,

thank you for reporting your experience. I hope I will find the time soon to generate a completely new AG application and test plugin installation with that. I am sorry, that the plugin installation did not work for you as we expected - but it should have :-).
Also, when the Audit-menu in the admin area is shown on the left it seems, not the code from button.js is being used. This code should make the menu show up on the right.

Olaf

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2021-08-02 23:41

I have test in other environment and it works fine. The audit log menu appeared at top right.

Thank you.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2021-08-22 09:45

Hi,

thank you for clearing the problem. Hope you like the plugin & auditlog and you will find it useful.

Olaf

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2021-10-03 03:09

Hi, onoehring

I am experiencing a little annoyance after install the audit log on Appginin 5.97. When I navigate to admin page after the first login attempt, it will return me to an login page again. I have to re-login in order to access the Admin page.

May I know whether this is bug that ye to resolved or my installation step got problem.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2021-10-06 06:59

Hi,

I, sometimes, experience the same problem, but I don't think it's connected to the AuditLog.
What makes you think it is?

Olaf

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2021-10-08 00:18

I did the test before and after installation of audit log. However, I didn't meant that the flaw is from the audit log, it could be the conflict with existing setup. I will try on a fresh generated application using Appgini 5.97 (before and after) to confirm again.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2021-10-08 05:31

Hi,

I think this has not been reported as a bug. Maybe you want to do so (viewforum.php?f=11)?

Olaf

hareut
Posts: 3
Joined: 2021-11-25 00:36

Re: Audit Log

Post by hareut » 2021-11-29 12:27

Hi,

I am testing the audit log plugin and came across the same issue sacgtdev reported -
the plugin doesn't add the code to admin/incHeader.php and to config.php.
I added it manually and it works. The dropdown menu appears on the left, but I don't mind.

The plugin works great and it is very useful.
The only thing missing is handling the actions done via the csv import mechanism.
I added some code to handle it, would appreciate any comment on it.
I added it to the file resources/lib/CSVImport.php, in function insertOneRecord().
This is the function were each record from the csv file is added/updated to the DB.
I added my code after the sql statement that adds the record, therefore I don't have the old value, but it can easily be extracted before.

Code: Select all

$audit_table = makeSafe('auditor');
//audit table fields:
$res_id = $insertId;
$user = $this->memberInfo['username'];
$ipaddr = $this->memberInfo['IP'];
$timestamp = date('Y-m-d H:i:s');
$changeType = ($action == 'updated' ? "UPDATE" : "INSERTION" );
$tablename = $table;

$auditor_fields = array("`res_id`", "`username`", "`ipaddr`", "`time_stmp`","`change_type`", "`table_name`", "`fieldName`", "`OldValue`", "`NewValue`");
			
// table fields user updates/inserts
$user_fields = array_filter($this->config['csvMap']);
$user_values = $fields;

$query = "INSERT IGNORE INTO `{$audit_table}` ".'(' . implode(",", $auditor_fields) . ')'. " VALUES \n";
			
$count = count($user_fields);
for ($i = 0; $i < $count; $i++) {
	$fieldName = $user_fields[$i];
	$fieldNewVal = $user_values[$i];
				
	#if it's an update action, skip the 'id' field (it is not updated)
	if ($action == 'updated' && $fieldName == $this->config['pkFieldName']) {
		continue;
	}
	
	// not handling old values
	$fieldOldVal = ($action == 'updated' ? "csv_update-oldValue NA" : "-INSERTED-" );
	$values = array("'${res_id}'", "'${user}'", "'${ipaddr}'", "'${timestamp}'", "'${changeType}'", "'${tablename}'", "'${fieldName}'", "'${fieldOldVal}'", $fieldNewVal);
	$query = $query.'(' . implode(",", $values) . ')';
	
	//if it's not the last element- add comma
	if (($i+1)<$count) {
		$query = $query.",\n";    
	}		
}		

$eo = ['silentErrors' => true];
sql($query, $eo);
if ($eo['error']) { $this->debug[] = "audit DB error: {$eo['error']}" ;}
Would appreciate any thoughts/comments on this code.
Thanks in advance,
Reut.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2022-03-03 06:34

Hi Reut,

I have been away for a while and just checking in. Your hint is good and assuming the code works it's a great addition.
I will keep this in mind and add it to a next version. Hopefully the installer can be extended as well to adjust the CSVImport.php automatically.

Olaf

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Audit Log

Post by AhmedBR » 2022-08-27 13:38

Hi,

I am testing the audit log plugin and came across the same issues reported.

The plugin doesn't add the code to admin/incHeader.php and to config.php.
I added it manually and it works.
I am using 22.14 running on localhost PHP 7.4.29.

The drop down menu does not appear anywhere for me!
The audit is working fine (very good indeed), I checked the database and everything looks good.


Thanks
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Audit Log

Post by AhmedBR » 2022-08-28 12:34

Update about my experience with the installation, just in case someone is having a similar tiny problem and how I solved it:

I had to do the following changes for the menu to appear:

The button.js was not being called, I added this to header-extra.php

Code: Select all

<script src="../hooks/audit/button.js"></script>
and changed the ref at button.js from

Code: Select all

 $j.get('hooks/audit/dropdown_menu.html', function(res){
to

Code: Select all

 $j.get('../hooks/audit/dropdown_menu.html', function(res){
After that, the menu appeared to the right as it should.

By the way, I found out that adding the lines to admin/incHeader.php does not make a difference!
(I removed them)
You only need to add the lines to config.php, all other files at hooks folder were done by the plugin.

The menu was added through the dropdown_menu.html
The last problem was the link in the dropdown_menu.html
I had to change the ref to the actual folder of the file: auditLogTimeLine.php to make it work.

With the above changes, the plugin is 100% operational.

Excellent plugin
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2023-03-27 06:27

Anybody has experienced using the audit log on nginx web server with php 8.0? I encountered 404 error when the audit functions (after_insert, before_insert, etc..) are applied in the hooks.

Example, when load the table_view url, says table_view.php, it is ok (200). But, when insert record in table_view, it will be redirected to 404. The redirected url is the same as the table url.

I didn't get any error recorded in access.log and error.log in nginx. Any suggestions on how to resolve this?

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2023-03-30 01:37

I found out the issue due to :

2023-03-30T00:26:05.490718327Z: [ERROR] 127.0.0.1 - 30/Mar/2023:00:26:05 +0000 "POST /palm_character_view.php" 500
2023-03-30T00:26:05.493239655Z: [ERROR] NOTICE: PHP message: PHP Fatal error: Uncaught TypeError: strlen(): Argument #1 ($str) must be of type string, array given in /home/site/wwwroot/admin/incFunctions.php:514
2023-03-30T00:26:05.493259655Z: [ERROR] Stack trace:
2023-03-30T00:26:05.493265355Z: [ERROR] #0 /home/site/wwwroot/hooks/audit/auditLog_functions.php(38): makeSafe(Array, true)
2023-03-30T00:26:05.493269556Z: [ERROR] #1 [internal function]: {closure}(Array)
2023-03-30T00:26:05.493273156Z: [ERROR] #2 /home/site/wwwroot/hooks/audit/auditLog_functions.php(39): array_map(Object(Closure), Array)
2023-03-30T00:26:05.493277156Z: [ERROR] #3 /home/site/wwwroot/hooks/audit/auditLog_functions.php(199): Audit_makeSafe_custom(Array)
2023-03-30T00:26:05.493290456Z: [ERROR] #4 /home/site/wwwroot/hooks/palm_character.php(152): table_after_change(Array, Array, Array, 'INSERTION')
2023-03-30T00:26:05.493294856Z: [ERROR] #5 /home/site/wwwroot/palm_character_dml.php(143): palm_character_after_insert(Array, Array, Array)
2023-03-30T00:26:05.493298656Z: [ERROR] #6 /home/site/wwwroot/datalist.php(246): palm_character_insert('')
2023-03-30T00:26:05.493302356Z: [ERROR] #7 /home/site/wwwroot/palm_character_view.php(181): DataList->Render()
2023-03-30T00:26:05.493306556Z: [ERROR] #8 {main}

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Audit Log

Post by sacgtdev » 2023-03-30 10:03

I modify the auditLog_functions.php for the following function, it works for me.


function Audit_makeSafe_custom($data, $is_gpc = true) {
if (!is_array($data) && !is_string($data)) {
return $data;
}

if (is_array($data)) {
return array_map(function ($entry) use ($is_gpc) {
return is_array($entry) ? Audit_makeSafe_custom($entry, $is_gpc) : makeSafe($entry, $is_gpc);
}, $data);
}

return makeSafe($data, $is_gpc);
}


ltlow
Posts: 15
Joined: 2021-07-29 09:37

Re: Audit Log

Post by ltlow » 2023-05-31 08:24

after changing the code as sacgtdev suggested, the auditor table work, but the auditor timeline has a blank page showing ?
Attachments
blank.png
blank.png (32.13 KiB) Viewed 15567 times

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2023-06-03 07:42

Hi itlow,

I can not reproduce your reported bug. For me the change works and the timeline is generated.
Maybe enable PHP error display and check what's going on.
You can do this (probably you do not want to do this on a life site) by adding the following code to the very end of config.php

Code: Select all

	//show errors
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);

Olaf

ltlow
Posts: 15
Joined: 2021-07-29 09:37

Re: Audit Log

Post by ltlow » 2023-06-06 06:55

onoehring wrote:
2023-06-03 07:42
Hi itlow,

I can not reproduce your reported bug. For me the change works and the timeline is generated.
Maybe enable PHP error display and check what's going on.
You can do this (probably you do not want to do this on a life site) by adding the following code to the very end of config.php

Code: Select all

	//show errors
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);

Olaf
Thanks for your help, found out that I put the auditLog_timeline.php to \hooks\auditLog_timeline.php but in the code it should be at \hooks\audit\auditLog_timeline.php

charmed_ones
Veteran Member
Posts: 32
Joined: 2013-03-22 13:31

Re: Audit Log

Post by charmed_ones » 2023-11-24 16:30

I installed this plug in on 8.2.15 PHP and Apache2.4, APPGINI 23.16 and everything looks right but it doesn't pick up the tables
in Admin when you go to SELECT TABLE the drop down is blank

any thoughts on why there is no tables to select?
2023-11-24_11-25-38.png
2023-11-24_11-25-38.png (39.4 KiB) Viewed 8046 times

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Audit Log

Post by onoehring » 2023-11-29 08:09

Hi,

thanks for reporting.
I do not remember ... but are there already some changed logged in the Audit?
It could be, that I did the code in the way that only tables are shown in the dropdown where already some data exists in the AuditLog table.
To make sure this is NOT the problem: If there are no entries in the AuditLog yet, please make sure there exist some.

Also: Did it work with older versions of PHP on that particular site?
Please let me know , then I can look into the code.

Olaf

Post Reply