71
timgno
Re: Userlog: a new module to log user activities
  • 2013/4/21 9:12

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


Ok!

A question on the folder xoops_data:

If it is to be used by other modules in writing, we can not change the permissions to read-only.

If we feel that this folder by default must be read-only, it is a good idea to think that it should be set to read-only immediately after installing xoops.

What do you think?

72
Mamba
Re: Userlog: a new module to log user activities
  • 2013/4/21 9:26

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Quote:
If we feel that this folder by default must be read-only, it is a good idea to think that it should be set to read-only immediately after installing xoops

Why this thought?

xoops_data is for all Cache files, and for config files, so it has be writable. Unless I am missing something.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

73
timgno
Re: Userlog: a new module to log user activities
  • 2013/4/21 9:40

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


Quote:
Why this thought?


I think I said xoops, but I wanted to understand the only module Userlog

Then we must explain why irmtfan in his module userlog want to make it read-only in index.php

The folder 'C:/wamp/www/xoops-2.5.5test/htdocs/xoops_data/userlog' must be with a chmod '755' (it's now set on 777).'


This:
// if there is no file in working check the parent folder chmod
if ($stats["fileall"][0]["value"] == || $stats["file" $Userlog->getWorkingFile()][0]["value"] == 0) {
    
$indexAdmin->addConfigBoxLine(array($Userlog->getConfig('logfilepath'), 755) , 'chmod');
    
// core feature: if(!$indexAdmin->addConfigBoxLine())
    
if (substr(decoct(fileperms($Userlog->getConfig('logfilepath'))),2) < 755) {
        
$indexAdmin->addConfigBoxLine("sprintf(_AM_USERLOG_CONFIG_CHMOD_ERROR,$Userlog->getConfig('logfilepath'),755)  . ""
'default');
        
$indexAdmin->addConfigBoxLine("sprintf(_AM_USERLOG_CONFIG_CREATE_FOLDER,$Userlog->getConfig('logfilepath')."/"USERLOG_DIRNAME,755)  . ""'default');
    }
} else {
// if there is file in working check the log folder chmod
    
$indexAdmin->addConfigBoxLine(array($Userlog->getConfig('logfilepath') ."/"USERLOG_DIRNAME755) , 'chmod');
}


can be done from the install folder (include/install.php):
$userlog XOOPS_DATA.'/userlog';
if(!
is_dir($userlog)) {
    
mkdir($userlog0755);
    
chmod($userlog0755);
}

74
timgno
Re: Userlog: a new module to log user activities
  • 2013/4/21 10:24

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


systems windows you can not easily change after:

Resized Image

75
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/4/21 10:46

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Sorry for confusion.
Thank you for your test.
Actually the first question is: Where is the best and most reliable place to save logs?
I chose xoops_data, one can chose xoops_data/caches because he would be sure this folder is writable.
In my wesbite xoops_data is out of wwwroot so i set chmod at 755. but one may have it inside wwwroot and may prefer to make it read only.

Quote:

Then we must explain why irmtfan in his module userlog want to make it read-only in index.php
The folder 'C:/wamp/www/xoops-2.5.5test/htdocs/xoops_data/userlog' must be with a chmod '755' (it's now set on 777).'

I dont make it read-only.
755 is the minimum required chmod to write inside the folder, so any chmod above it is acceptable.

IMHO It is a displaying bug in moduleadmin class. (I forgot to post it )
In xoops255\Frameworks\moduleclasses\moduleadmin\moduleadmin.php Line 213:
if (substr(decoct(fileperms($value[0])),2) != $value[1]) {


should be changes to:
if (substr(decoct(fileperms($value[0])),2) < $value[1]) {

then it will show OK when the chmod is above 755.

Quote:

can be done from the install folder (include/install.php):


Userlog will not create folders in install because:
1- user may prefer to dont use log in file at all.
2- user can change the log folder location. ( currently xoops_data/userlog and uploads/userlog)
so once user choose to save logs in file the required folders will be created.

even you can add your folder easily in xoops_version.php
the log folder location is not hard-coded in the whole codes. so if you add a full path in xoops_version.php it will read it from there.

76
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/4/22 6:39

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Today i updated userlog to version 1.1

I noticed in some weird situations (eg: custom forms, hacks, ported modules like mediawiki, ...), there is no redirect message after submit. If you want to log any POST method regardless of redirect message you can set a config to yes.
changes:
Quote:

- add: check $_POST before load log module in preloads/core.php and xoops_version.php and include/postlog.php and language/english/modinfo.php and class/userlog.php(2013/04/21)
- add: show time update in admin/index.php and admin/stats.php (2013/04/22)
- add: add referral to stats table to show outside referer websites in class/stats.php and admin/stats.php(2013/04/22)


download trunk:
http://svn.code.sf.net/p/xoops/svn/XoopsModules/userlog/trunk/

version 1.01 is frozen and only will be updated if there are any bugs remained.
If everybody agreed we can release version 1.01 final.

77
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/4/23 11:16

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Today i finally add one of the wishes for a log module that i had for years.
A login/register history.
Quote:

There is a new login/register history which you can see all attempts by anonymous users (failed and successive) to login or register in your website.
To start a login/register history, you should add a setting for anonymous users (Group id = 3) or all users (Unique ID = 0) which log at least uid and $_POST.

Actually we need a login history because the last login field in users table is just one time not history. Even it is not last login at all!!! It is just the last visit of a logged-in user.
Once all tested passed OK in stats.php page I will implement those functionality to blocks easily.

download trunk and test:
http://svn.code.sf.net/p/xoops/svn/XoopsModules/userlog/trunk/

78
blackrx
Re: Userlog: a new module to log user activities
  • 2013/4/23 12:59

  • blackrx

  • Quite a regular

  • Posts: 227

  • Since: 2008/2/5 1


hi imrtfan very nice

btw can you make a special block for the success last login history where we can exclude any user etc

i forgot where i got this but i use this in my site all this while

echo "
 ";

function 
timeDifference($start,$end,$return='days') {
    
//change times to Unix timestamp.
    //$start = strtotime($start);
    //$end = strtotime($end);
    //subtract dates
//echo 'Start Timestamp: ' . $start . '
End Timestamp: ' . $end . '
';
    
$difference max($end$start) - min($end,$start);
    
$time NULL;
    
//calculate time difference.
    
switch($return) {
        case 
'days':
             
$days floor($difference/86400);
                
$difference $difference 86400;
                    
$time['days'] = $days;
        case 
'hours':
            
$hours floor($difference/3600);
                
$difference $difference 3600;
                    
$time['hours'] = $hours;
        case 
'minutes':
            
$minutes floor($difference/60);
                
$difference $difference 60;
                    
$time['minutes'] = $minutes;
        case 
'seconds':
            
$seconds $difference;
                
$time['seconds'] = $seconds;
    }
    
    
$output = array();
       if(
is_array($time)) {
        
$showSec true;
                    if(isset(
$time['hours']) && $time['hours'] > 0) {
                        
$output[] = $time['hours'] . ' Hour';
                        
$showSec false;
                    }
                    
                    if(isset(
$time['minutes']) && $time['minutes'] > 0) {
                        
$output[] = $time['minutes'] . ' minutes';
                        
$showSec false;
                    }
                    
                    if(isset(
$time['seconds']) && $showSec == true) {
                        return 
$time['seconds'] . ' Second';
                    }
                
        
            return 
implode(', ',$output);
        }
}  



$now time();
$hours 24;
$count=0;
$time = ( intval$hours ) > ) ? time() - ( intval$hours ) * 3600 ) : ( time() - 24*3600 );
global 
$xoopsDB;


$sql "SELECT distinct uid, uname, user_avatar, last_login FROM ".$xoopsDB->prefix("users")." WHERE level > 0 AND uid NOT IN (1) AND uid NOT IN (76) AND last_login >= '" $time "' ORDER BY last_login DESC";
$result $xoopsDB->query($sql);


while (list(
$uid$uname,$user_avatar,$last_login) = $xoopsDB->fetchRow($result) ) {
//Put this variable in the echo statements where you would like them to show up.
$sinceLastLogin ' ' timeDifference($last_login,$now,'hours') . ' ago';
$count++;
if (
$user_avatar == 'avatars/blank.gif')
{
echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>.XOOPS_URL."/uploads/avatars/blank.gif' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'>
";
}

else

{
echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>.XOOPS_URL."/uploads/".$user_avatar."' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'>
";
}

}

echo 
"
 ";

79
irmtfan
Re: Userlog: a new module to log user activities
  • 2013/4/24 4:25

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


good.
As i wrote in the last post the current defined task for last_login field in XOOPS CORE is keeping last visit of the user.(so last login is a confusing name !!!)
I know a couple of modules will provide you such a block for showing last visits.
I simplified your code to this:
echo "
 "
$now time(); 
$hours 24
$count=0
$time = ( intval$hours ) > ) ? time() - ( intval$hours ) * 3600 ) : ( time() - 24*3600 ); 
global 
$xoopsDB


$sql "SELECT distinct uid, uname, user_avatar, last_login FROM ".$xoopsDB->prefix("users")." WHERE level > 0 AND uid NOT IN (1) AND uid NOT IN (76) AND last_login >= '" $time "' ORDER BY last_login DESC"
$result $xoopsDB->query($sql); 


while (list(
$uid$uname,$user_avatar,$last_login) = $xoopsDB->fetchRow($result) ) { 
//Put this variable in the echo statements where you would like them to show up. 
$sinceLastLogin ' ' class_exists("XoopsLocal") ? XoopsLocal::formatTimestamp($last_login,"elapse") : ''
$count++; 
if (
$user_avatar == 'avatars/blank.gif'

echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>.XOOPS_URL."/uploads/avatars/blank.gif' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'>
"


else 


echo 
".XOOPS_URL."/userinfo.php?uid=".$uid."'>.XOOPS_URL."/uploads/".$user_avatar."' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'>
"




echo 
"
 ";

as you can see nowadays XoopsLocal::formatTimestamp($last_login,"elapse") will do the job perfectly
every module developers include me can add a last visit block to his module. because It is not related to any module. it is just some codes to get last_login from users table. (It is better to add to core )
yesterday Mamba told my via email that it would be good to have it in newbb. so i add it to newbb too
http://svn.code.sf.net/p/xoops/svn/XoopsModules/newbb/branches/irmtfan/newbb/
Therefore it is very easy to add it

but login/register history is a different concept. here you can find all real login/register attempts.(and find whether it is failed or successful)
Today i improved the login/register history functionality and for better performance I add a patch to all $_POST which contained "pass".
Now it is ready to make a block from.
download trunk and test:
http://svn.code.sf.net/p/xoops/svn/XoopsModules/userlog/trunk/

Login

Who's Online

289 user(s) are online (162 user(s) are browsing Support Forums)


Members: 0


Guests: 289


more...

Donat-O-Meter

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

Latest GitHub Commits