Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
9 - 7 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     
userlog->getUser()) { $uid = $this->userlog->getUser()->getVar('uid'); $uname = $this->userlog->getUser()->getVar('uname'); $last_login = $this->userlog->getUser()->getVar('last_login'); $admin = $this->userlog->getUser()->isAdmin(); $groups = "g" . implode("g",$this->userlog->getUser()->getGroups()); // g1g2 } else { $uid = 0; $uname = ''; $last_login = 0; $admin = 0; $groups = "g" . XOOPS_GROUP_ANONYMOUS; // g3 } $options = array( "log_id" => array( "type" => "int", "title" => _AM_USERLOG_LOG_ID, "value" => null // null for now ), "log_time" => array( "type" => "int", "title" => _AM_USERLOG_LOG_TIME, "value" => time() ), "uid" => array( "type" => "int", "title" => _AM_USERLOG_UID, "value" => $uid ), "uname" => array( "type" => "text", "title" => _AM_USERLOG_UNAME, "value" => $uname ), "admin" => array( "type" => "bool", "title" => _AM_USERLOG_ADMIN, "value" => $admin ), "groups" => array( "type" => "text", "title" => _AM_USERLOG_GROUPS, "value" => $groups ), "last_login" => array( "type" => "int", "title" => _AM_USERLOG_LAST_LOGIN, "value" => $last_login ), "user_ip" => array( "type" => "text", "title" => _AM_USERLOG_USER_IP, "value" => $_SERVER['REMOTE_ADDR'] ), "user_agent" => array( "type" => "text", "title" => _AM_USERLOG_USER_AGENT, "value" => $_SERVER['HTTP_USER_AGENT'] ), "url" => array( "type" => "text", "title" => _AM_USERLOG_URL, "value" => $_SERVER['REQUEST_URI'] ), "script" => array( "type" => "text", "title" => _AM_USERLOG_SCRIPT, "value" => end(explode('/',$_SERVER['PHP_SELF'])) ), "referer" => array( "type" => "text", "title" => _AM_USERLOG_REFERER, "value" => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "" ), "pagetitle" => array( "type" => "text", "title" => _AM_USERLOG_PAGETITLE, "value" => isset($GLOBALS['xoopsTpl']) ? $GLOBALS['xoopsTpl']->get_template_vars("xoops_pagetitle") : "" ), "module" => array( "type" => "text", "title" => _AM_USERLOG_MODULE, "value" => $this->userlog->getLogModule()->getVar("dirname") ), "item_name" => array( "type" => "text", "title" => _AM_USERLOG_ITEM_NAME, "value" => null ), "item_id" => array( "type" => "text", "title" => _AM_USERLOG_ITEM_ID, "value" => null ), // user data input method "request_method" => array( "type" => "text", "title" => _AM_USERLOG_REQUEST_METHOD, "value" => $_SERVER['REQUEST_METHOD'] ), "get" => array( "type" => "text", "title" => _AM_USERLOG_GET, "value" => $_GET ), "post" => array( "type" => "text", "title" => _AM_USERLOG_POST, "value" => $_POST ), "request" => array( "type" => "text", "title" => _AM_USERLOG_REQUEST, "value" => $_REQUEST ), "files" => array( "type" => "text", "title" => _AM_USERLOG_FILES, "value" => $_FILES ), "env" => array( "type" => "text", "title" => _AM_USERLOG_ENV, "value" => $_ENV ), "session" => array( "type" => "text", "title" => _AM_USERLOG_SESSION, "value" => $_SESSION ), "cookie" => array( "type" => "text", "title" => _AM_USERLOG_COOKIE, "value" => $_COOKIE ), "header" => array( "type" => "text", "title" => _AM_USERLOG_HEADER, "value" => headers_list() ), "logger" => array( "type" => "text", "title" => _AM_USERLOG_LOGGER, "value" => $GLOBALS['xoopsLogger']->errors ), // settings will not be logged "store_file" => array( "type" => "int", "title" => _AM_USERLOG_STORE_FILE, "value" => 1 ), "store_db" => array( "type" => "int", "title" => _AM_USERLOG_STORE_DB, "value" => 1 ), "views" => array( "type" => "int", "title" => _AM_USERLOG_VIEWS, "value" => 1 // for item_name and item_id ), ); $ret = $this->userlog->getFromKeys($options, $option); if (empty($V)) return $ret; if ($V == "key") return array_keys($ret); $ret2 = null; foreach ($ret as $option=>$val) { $ret2[$option] = $val[$V]; } return $ret2; } [/code] 2- setting structure. i think we just need to log users based on "uid" or "gid" or "ip" and it will cover all possibilities. please let me know your idea. the table structure is: in userlog/sql/mysql.sql [code] CREATE TABLE mod_userlog_set ( set_id mediumint(8) unsigned NOT NULL auto_increment, name varchar(100) NOT NULL default '', logby varchar(10) NOT NULL default '', unique_id int(11) unsigned NOT NULL default 0, options TEXT NOT NULL, scope TEXT NOT NULL, PRIMARY KEY (set_id), UNIQUE logby_id (logby, unique_id) ) ENGINE=MyISAM; [/code] The above is clear. more information in module help. 3- performance. it checks every hit to see if the visitor have a setting or not. for the best performance i wrote a get function like this. in userlog/class/setting.php [code] public function get() { // if uid setting exist in File $unique_uid = ($this->userlog->getUser()) ? $this->userlog->getUser()->getVar('uid') : 0; if ($options = $this->getFile('uid', $unique_uid)) { return $options; } // if gid setting exist in File $unique_gid = ($this->userlog->getUser()) ? $this->userlog->getUser()->getGroups() : array(XOOPS_GROUP_ANONYMOUS); foreach ($unique_gid as $gid) { if ($options = $this->getFile('gid', $gid)) { return $options; } } // if ip setting exist in File $unique_ip = XoopsUserUtility::getIP(); // ip as int if ($options = $this->getFile('ip', $unique_ip)) { return $options; } // if all exist in File if ($options = $this->getFile('all', 0)) { return $options; } /////////////////////////////////////////////////////////// // database get All is better for performance??? $logsetsObj = $this->userlog->getHandler('setting')->getAll(); if (empty($logsetsObj)) return false; // if not set in db return false $uid_unique_uid = "uid" . $unique_uid; foreach($unique_gid as $key=>$gid) { $gid_unique_gid[$key] = "gid" . $gid; } $ip_unique_ip = "ip" . $unique_ip; foreach($logsetsObj as $setObj) { $sLobgy = $setObj->logby(); $sUnique_id = $setObj->unique_id(); $sLogbyId = $sLobgy . $sUnique_id; // if uid setting exist in db return it if($sLogbyId == $uid_unique_uid || // if gid setting exist in db return it in_array($sLogbyId, $gid_unique_gid) || // if ip setting exist in db return it $sLogbyId == $ip_unique_ip) { $sets = array($setObj->options(), $setObj->scope()); $this->setFile($sLobgy, $sUnique_id, $sets); // build cache return $sets; } // if all exist in db if($sUnique_id == 0) { $sets = array($setObj->options(), $setObj->scope()); $this->setFile('all', 0, $sets); // build cache return $sets; } } return false; } [/code] as you can see it create cache files for each settings. IMO it will help to reduce queries for users have a setting. for getting settings from db i firstly used criteria but then i decide to get all settings at once and then find if the user have setting or not. IMO it has the better performance. please let me know your opinion. what is the best performance? this function is important for your review. 4- views now every module have a counter for its item views. eg: news, publisher, page in xoops 2.6 but this counter is useless. we dont need forever views. we need views in a specific time period. in every news agency the first and top block is "today hot news" and it means news that had been most viewed today. for a long time that was an unsolved issue for me and i think in the whole xoops we have this problem in all modules. after starting userlog for a different purpose I suddenly reach to an innovative idea for gathering all views in all modules. i used module "notification" because every module item that should have views have a notification too. there we have all needed information about items. so i wrote this nice and tricky function: [code] public function setItem() { $not_config =& $this->userlog->getLogModule()->getInfo('notification'); if (!empty($not_config)) { foreach ($not_config['category'] as $category) { // if $item_id != 0 ---> return true if (!empty($category['item_name']) && $item_id = UserlogRequest::getInt($category['item_name'], 0)){ $this->setVar('item_name', $category['item_name']); $this->setVar('item_id', $item_id); return true; } } } return false; } [/code] so for example in news we only have these typical URLs: news/article.php?storyid=ITEM_ID news/index.php|article.php?storytopic=ITEM_ID as you can see i just need to store item_name and item_id because i have the module dirname and script name!!! IMO we should stick to this idea to have a overall item views in the XOOPS and drop all counters in all modules. i need your idea about this. [/quote] please if you have any opinion contribute here. Thank you. @Mamba: i dont have any issues in php 5.3.17 and 5.4.4 I just used Xoops core functions but i just can guess it needs pear for file classes. does your localhost have pear support? It sees it is required for this module!!![/quote]" />

Re: Userlog: a new module to log user activities
by irmtfan on 2013/4/24 4:25:49

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:
le="color: #000000"><?php echo "<div style='clear:both;'></div> "; $now = time(); $hours = 24; $count=0; $time = ( intval( $hours ) > 0 ) ? 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 "<div style='float: left; padding:2px;'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/avatars/blank.gif' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'></a></div>"; } else { echo "<div style='float: left; padding:2px;'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/".$user_avatar."' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'></a></div>"; } } echo "<div style='clear:both;'></div> ";

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/
Re: Userlog: a new module to log user activities
by blackrx on 2013/4/23 12:59:25

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

le="color: #000000"><?php echo "<div style='clear:both;'></div> "; function timeDifference($start,$end,$return='days') { //change times to Unix timestamp. //$start = strtotime($start); //$end = strtotime($end); //subtract dates //echo 'Start Timestamp: ' . $start . '<br/>End Timestamp: ' . $end . '<br/>'; $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 ) > 0 ) ? 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 "<div style='float: left; padding:2px;'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/avatars/blank.gif' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'></a></div>"; } else { echo "<div style='float: left; padding:2px;'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/".$user_avatar."' title='$uname | $sinceLastLogin' border='0' alt='".$uname."' height='48' width='48'></a></div>"; } } echo "<div style='clear:both;'></div> ";
Re: Userlog: a new module to log user activities
by irmtfan on 2013/4/23 11:16:28

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/
Re: Userlog: a new module to log user activities
by irmtfan on 2013/4/22 6:39:57

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.
Re: Userlog: a new module to log user activities
by irmtfan on 2013/4/21 10:46:46

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:
le="color: #000000"><?php if (substr(decoct(fileperms($value[0])),2) != $value[1]) {


should be changes to:
le="color: #000000"><?php 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.

Who's Online

196 user(s) are online (160 user(s) are browsing Support Forums)


Members: 0


Guests: 196


more...

Donat-O-Meter

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

Latest GitHub Commits