21
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/3/4 14:14

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Quote:

What screenshots would you like to have

From admin/logs.php
Im not a good designer. I hope a designer can help for better using of css and js.

Quote:
the module could have an option of being active or idle.

Nice idea. I add it to the module. Now we can deactivate log actions temporary.

Quote:

You mean, using json_encode instead of serialize?

yes.
for example in XOOPS255/kernel/object.php
case XOBJ_DTYPE_ARRAY:
                        
$cleanv = (array) $cleanv;
                        
$cleanv serialize($cleanv);
                        break;


Edit:
Also in xoops 26
in XOOPS26/xoops_lib/Xoops/Object/Dtype/Array.php

foreach (array_keys($value) as $key) {
            if (
$quote) {
                
$value[$key] = str_replace('"''"'addslashes($value[$key]));
            }
        }
        
// TODO: Not encoding safe, should try base64_encode -- phppp
        
$value "'" serialize($value) . "'";
        return 
$value;


you can see phppp didnt like it too. json_encode is the best current method.

22
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/3/5 3:00

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Mamba report me about possible white screens in logs.php page.
when i talked about impacts of this module on server resources i meant the performance in the whole site not in userlog/admin.

the admin side of this module is openly rendered logs. so it will be up to the user/webmaster how he will do it.

e.g.: he can render all files in all paths at once and it surely may cause issues when the number of logs are high.

i add a config to engine= file to show logs from working file instead of all files.

but the performance of this module in the whole site is really important.
in the worst case you may add a setting to log everything from all users/visitors
then with each hit this module will insert data to database.

Userlog will have many new usages. eg: a very powerful and smart backup/restore tool because you can store all $_POST.

Also may be a hit counter too. you can see your websites hits module by module and script by script.



23
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/3/7 3:17

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Today i add more GUI facilities to admin/logs.php.

1- a complete toggle formhead can remember the last status for each admin.

2- reset button

Also there are 3 known bugs/issues with this module that i wrote them in readme.txt:
Quote:

known bugs/malfunctioning in userlog module:
1- userlog will not work in XOOPS255/index.php (homepage) when no module is set for start page.
there is a bug in XOOPS255/header.php
solution:
in XOOPS255/header.php exit() should be commented.
$xoopsPreload->triggerEvent('core.header.checkcache');
    if (
$xoTheme->checkCache()) {
        
$xoopsPreload->triggerEvent('core.header.cacheend');
        
//exit(); // irmtfan comment this
    
}

more information here:http://sourceforge.net/p/xoops/bugs/1261/

2- You cannot select many items in userlog > blocks > views block.
It is because of a length limitation in options field in newblocks table in xoops 255 and xoops 26.
solution:
in XOOPS255/kernel/block.php and XOOPS26/kernel/block.php
line 40:
$this->initVar('options'XOBJ_DTYPE_TXTBOXnullfalse255);


with this:
[code]
        
$this->initVar('options'XOBJ_DTYPE_TXTBOXnullfalse600);

Then go to your database and change the field options length in newblocks table to higher number than 255.

3- When the URL or The REFERER is longer than 255 characters you have a warning and log will not be stored in database but it will be stored in file.
You can see this warning:
WarningInsert failed in method 'cleanVars' of object 'UserlogLog' in file /class/model/write.php line 280

It is because I decide to limit URL/Referer to 255 characters because of better performance.
solution:
If you really need to save URLs with more characters than 255. do the following.
a) go to userlog/class/log.php and change the below indicate lines to your desired values.
$this->initVar("url"XOBJ_DTYPE_TXTBOXnulltrue500); // change this
        
$this->initVar("script"XOBJ_DTYPE_TXTBOXnulltrue50);
        
$this->initVar("referer"XOBJ_DTYPE_TXTBOXnulltrue500);// change this

b) go to your database and change 'url' and 'referer' fields in table mod_userlog_log to your desired values.


@Mamba: in mastop_go2 that filter show/hide has these limitations:
1- It cannot remember the last click and it always will be hide by default.
2- It cannot change its own text/image/icon/alt/title when you click

In userlog i implement the final solution for these in a toggle that i learned from "newbb"

Also please let me know if you can find any good example for an export system.
I think export to excel, csv, json would be enough.

after adding that export system this module will be closed to final ALPHA. I mean then we have all needed features ready and can think about beta and final versions

24
Mamba
Re: Userlog: a new module to log user activities
  • 2013/3/8 11:14

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


Quote:
@Mamba: in mastop_go2 that filter show/hide has these limitations:
1- It cannot remember the last click and it always will be hide by default.
2- It cannot change its own text/image/icon/alt/title when you click

In userlog i implement the final solution for these in a toggle that i learned from "newbb"

Great job, Irmtfan! Thank you! It looks kind of busy, but this is because of the number of the columns there, so I don't think you can do anything about it. But toggle on/off is excellent.

When you finalize all of it, we'll need some tutorials on how to implement in in all other modules!

Quote:
Also please let me know if you can find any good example for an export system.
I think export to excel, csv, json would be enough.

You might try PHP Excel

There are also Excel and CVS classes on PHPClasses.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

25
zyspec
Re: Userlog: a new module to log user activities
  • 2013/3/8 14:07

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Outputting to a CSV file is pretty straight forward. Here's a snippet of code I've used to save the information from a table to a CSV file.

$regFields = array('field_1''field_2''field_3');
$rObjs $regform_handler->getAll(null$regFields);
$rCount count($rObjs);
if (!
$rCount) {
    echo 
"There are no records";
} else {
    
$delimiter ";";
    
$fp fopen(XOOPS_UPLOAD_PATH "/<mymodule>/list_" time() . ".csv"'w');
    
fputcsv($fp, array('Field 1 Title','Field 2 Title''Field 3 Title'), $delimiter);
    foreach(
$rObjs as $rObj) {
        
$rValues $rObj->getValues();
        
$thisRow = array($rValues['field_1'],
                         
$rValues['field_2'],
                         
$rValues['field_3']);
        
fputcsv($fp$thisRow$delimiter);
    }
    
fclose($fp);
}


Obviously you'll want to substitute your field names for 'field_1', your destination file name and the title fields in the fputcvs function but this gives you the idea. Technically, in this example, $thisRow, wouldn't need to be used because I just showed the data being dumped straight from $rValues but in 'real life' there's a couple of things you will need to do to the data to make sure this works reliably. For example - make sure that you do not allow your data to have the delimiter embedded in it. So, in this case, my data would not be allowed to have a semicolon (";"). You can do a simple str_replace in most instances or you can "change" your delimitter based on data - although this could get a little tricky...

Good luck!

26
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/3/9 2:27

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


@ zyspec:
That fputcsv guide me pefectly to this brief code in 5 minutes:
// form, elements, headers
list($form$elements$headers) = $logsetObj->logForm($options);
// START export
if ($opentry == "export" && !empty($export) ) {
    switch (
$export) {
        case 
'csv':
            
$delimiter ";";
            
$fp fopen($Userlog->getConfig("logfilepath") . "/" USERLOG_DIRNAME "/export/" $export "/" "total_ " $totalLogs "_" time() . ".csv"'w'); 
            
fputcsv($fp$headers$delimiter);
            foreach(
$logs as $thisRow) { 
                
fputcsv($fp$thisRow$delimiter);
            }
            
fclose($fp);
            
redirect_header("logs.php?op=" $query_entry . (!empty($query_page) ? "&amp;" $query_page ''), 1_AM_USERLOG_LOG_EXPORT_SUCCESS);
            break;
        default :
            break;
    }
}
// END export

Thank you.
I will work on the above to be less hard-code, have more options like export selected lines and whole pages.

Do you think export to csv would be enough?
Also i used JSON in this module so exporting to JSON will not need anything.
I hope You could take a look at this module. I try to write it very understandable.
I more need to have ideas from some experts like you about the performance of this module.

@ Mamba:
You sent me an important email but i missed it.
I will try to discuss about them here.

Quote:

- I have now 306 files, each 1 MB. How would it be possible to "merge" them together, if I would want to do some analytics (e.g. to find out where people go the most, or to retrace steps of a hacker)


1- That 1MB is just a threshold when you want to view files directly using Cpanel. but in general i cannot see any issue to have larger files like 10MB.

2- I can implement a merge tool too. it would be very easy as simple as combining files.
I used JSON method and it is more understandable for human reading than serialize so you dont need any special tool.

Quote:

- how can we have a cron job zipping them together into one file?

It is very easy too.
we can have a separate file browser tab and define merge, zip and ...
Also a cron job can be done in the module or outside the module in Cpanel with some guide lines.
honestly this module is not for very basic webmasters. so I assume webmaster could do some jobs himself.

Quote:

- maybe there could be another part of the application that could do some analytics, with charts (e.g. showing which continent/country people coming from, which module is the most popular)


yes. Honestly right now i only did 20% of what i had in my mind in this module. I did the setting section and storing logs and browsing them. several usages of these logs can be very amazing.
And finally those would be just my mind other minds have many other nice things too.

Also the form in logs.php is just a very first attempt. you can see all of them are text boxes. i will improve them to more understandable elements:
eg: radio YES/No for isAdmin?
module checkbox and ...

27
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/3/9 13:00

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I suddenlly encounter an issue in "fputcsv"
the result csv is not utf-8. It is a big issue in multibyte languages.

i tried iconv and XoopsLocal::utf8_encode($text) but failed.

look at this simple example:
<?php
include "define.php";
$list =  array( array(_AM_USERLOG_LOG_ID_AM_USERLOG_LOG_TIME'ccc''dddd'),
    array(
'123''456''789''777'),
    array(
'123''456''789''777')
);
$fName 'file'time() . '.csv';
touch($fName);
mb_internal_encoding("UTF-8");
$fp fopen($fName'w');
fwrite($fppack("CCC",0xef,0xbb,0xbf));
 foreach (
$list as $fields) {
    foreach(
$fields as $key=>$field) {
        
$fields[$key] = mb_convert_encoding($field'UTF-8''auto');
    }
    
fputcsv($fp$fields);
}

fclose($fp);
?>


and define.php is just 2 defines in persian:
<?php
define
("_AM_USERLOG_LOG_ID","شماره ثبت");
define("_AM_USERLOG_LOG_TIME","زمان ثبت");
?>


As you can see i did everything but .csv file is still is not utf-8

28
Cesagonchu
Re: Userlog: a new module to log user activities

With your latest version (r11215), I got a blank page when installing, without error on the debug mode, and the module is still installed properly when I return to the Administration page modules.

By cons, I get an error in debug mode here, for each module I have already installed:
modules/userlog/admin/stats.php

NoticeUndefined indexsystem in file /modules/userlog/admin/stats.php

line 59 NoticeUndefined indexsystem in file /modules/userlog/admin/stats.php

line 60 NoticeUndefined indexpm in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexpm in file /modules/userlog/admin/stats.php line 60

NoticeUndefined indexprofile in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexprofile in file /modules/userlog/admin/stats.php line 60

NoticeUndefined indexprotector in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexprotector in file /modules/userlog/admin/stats.php line 60

NoticeUndefined indexcontact in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexcontact in file /modules/userlog/admin/stats.php line 60

NoticeUndefined indexmastop_go2 in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexmastop_go2 in file /modules/userlog/admin/stats.php line 60

NoticeUndefined indexcricketstats in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexcricketstats in file /modules/userlog/admin/stats.php line 60

NoticeUndefined indexuserlog in file /modules/userlog/admin/stats.php line 59

NoticeUndefined indexuserlog in file /modules/userlog/admin/stats.php line 60



When I display the block "All views in site", I have this error:
Warningarray_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in file /modules/userlog/blocks/views.php line 139


My config:

PHP version : 5.3.10-1ubuntu3.5
MYSQL version : 5.5.29-0ubuntu0.12.04.2
XOOPS : 2.5.5
ModuleAdmin : 1.1

29
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/3/15 2:48

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Thank you Cesag for this report.

bugs in stats.php and views block was because you didnt have any log in database. Anyway i add some if parts to check if the logs are exist or not.
bug after installation was very strange. I think it is a bug in module admin class because only right after installation you have this bug.
I add a quick fix to userlog to solve that.
the admin/stats.php is incomplete. I will add more statistics like views by users/ groups/ items/ ...

My deadlines for this module is:

- VERSION 1 ALPHA 2 (FINAL ALPHA) 2013/3/21 please report your needed features ASAP. features will be closed after this ALPHA.

- VERSION 1 BETA/RC series until 2013/04/10 It will focus on bugs and performance issues.

- VERSION 1 FINAL 2013/04/15 I hope we can release it in one month

I will be in vacation from 2013/3/21 for 10 days so my accessing to the web would be very limited.




30
Cesagonchu
Re: Userlog: a new module to log user activities

After creating a setting, I have this error:

Errors Warningmkdir() [function.mkdir]: Permission denied in file /class/file/folder.php line 529


and after that I can not edit the settings (/modules/userlog/admin/setting.php?set_id=1).


My config:

PHP version : 5.3.10-1ubuntu3.5
MYSQL version : 5.5.29-0ubuntu0.12.04.2
XOOPS : 2.5.5
ModuleAdmin : 1.1

Login

Who's Online

203 user(s) are online (111 user(s) are browsing Support Forums)


Members: 0


Guests: 203


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits