Announcement

  •  » Engine
  •  » User Info Tracking

#1 2012-11-04 15:36:54

Charles2012
Member
2012-11-04
26

User Info Tracking

I use to be a user of gallery2 and created a module with the help of the gallery2 developers. The module named User Info tracks when people try to login either successful or not. I would like to have something like this added to 2.5 of Piwigo. The gallery2 module used smartys so I don't think it will much of a problem porting it over to Piwigo.

Here is more information and screenshots of my module  http://codex.gallery2.org/Gallery2:Modules:userinfo

I am a beginner programmer and would really like this ported over to Pieigo as I think it would be very useful to a lot of users.  I wanted to track who is logging in or attempting to login.  For other tracking I can use google or piwik.

Offline

 

#2 2012-11-04 15:43:40

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13786

Re: User Info Tracking

We need to investigate on the existing triggers in Piwigo 2.4, but I think you don't need to wait for Piwigo 2.5.

Very interesting plugin, indeed.

Offline

 

#3 2012-11-04 15:49:59

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

I think there may be a few missing event triggers. I don't know how hard or easy it would be to add them into the core engine.

Thanks

FYI The main reason I don't use gallery2 is because the lack of updates between major releases and how g3 lost some functions. Piwigo is very active and is "actively" updated.

Offline

 

#4 2012-11-18 21:58:53

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

I need some help with transferring my below code:
This is my admin.tpl page.
Having a few problems with converting the g-> parts of the code.


<!-- Show the title of the plugin -->
<div class="titlePage">
<h2>{'Skeleton plugin'|@translate}</h2>
</div>

<!-- Show content in a nice box -->
<fieldset>
<legend>{'A minimal plugin'|@translate}</legend>

{'Hello world!'|@translate}
</fieldset>



<br><br><br>

<!-- Gallery Stuff -->
<div class="gbBlock gcBackground1">
  <h2> {'User Info Page'|@translate} </h2>
</div>

<div class="gbTabBar">
  <span class="giSelected o"><span>
    {'User Info'|@translate}
  </span></span>

  <span class="o"><span>
    {capture name=getMoreLink}
    <a href="{g->url arg1="view=core.SiteAdmin" arg2="subView=userinfo.UserinfoSetup"}">{'Setup'|@translate}</a>
    {/capture}
    {$smarty.capture.getMoreLink}
  </span></span>

</div>

<div class="gbBlock">
  <p class="giDescription">
    {'This will display information about users when they Login, Logout, and Failed Login Attempts.'|@translate}
  </p>
</div>


<div class="gbBlock gcBackground1">
<table border="1">

<tr>
    {if ($Userinfo.data)}
    <td align="center" colspan="6">{'Number of Records:'|@translate}{$Userinfo.numRowsCount}</td>
    {else}
    <td align="center" colspan="6">{'Number of Records: 0'|@translate}</td>
    {/if}
</tr>

{if ($Userinfo.data)}
<tr>
    <td align="center" colspan="6">
        {if !empty($pagination.jumpRange)}
        <div class="gsPages">
            {'Page:'|@translate}
            {assign var="lastPage" value=0}
            {foreach name=jumpRange from=$pagination.jumpRange item=page}
                {if ($page - $lastPage >= 2)}
                    <span>
                    {if ($page - $lastPage == 2)}
                        <a href="{g->url params=$pagination.pageUrl arg1="page=`$page-1`"}">{$page-1}</a>
                    {else}
                        ...
                    {/if}
                    </span>
                {/if}

                <span>
                {if ($pagination.currentPage == $page)}
                    {$page}
                {else}
                    <a href="{g->url params=$pagination.pageUrl arg1="page=$page"}">{$page}</a>
                {/if}
                </span>
                {assign var="lastPage" value=$page}
            {/foreach}
        </div>
        {else}
              &nbsp;
        {/if}
    </td>
</tr>
{else}
<tr>
    <td></td>
</tr>
{/if}

{foreach name=currentPage from=$pagination.currentPage item=pageNum}
<tr>
    <th>ID
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=id" arg3="order=DES"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=id" arg3="order=ASC"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>User ID
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=userId" arg3="order=DES"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=userId" arg3="order=ASC"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>User Name
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=userName" arg3="order=DES"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=userName" arg3="order=ASC"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>IP Address
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=ipAddress" arg3="order=DES"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=ipAddress" arg3="order=ASC"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>Time Stamp
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=timeStamp" arg3="order=DES"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=timeStamp" arg3="order=ASC"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>Action
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=action" arg3="order=DES"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->url params=$pagination.pageUrl arg1="page=$pageNum" arg2="sort=action" arg3="order=ASC"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
</tr>
{foreachelse}
<tr>
    <th>ID
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>User ID
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>User Name
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>IP Address
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>Time Stamp
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
    <th>Action
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/down.gif"}"/></a>
        <a href="{g->text text="#"}"><img src="{g->url href="modules/userinfo/images/up.gif"}"/></a>
    </th>
</tr>
{/foreach}

{foreach from=$Userinfo.data item=id}
<tr>
    <td>{$id.id}</td>
    <td>{$id.userId}</td>
    <td>
        {if ($id.userId)}
            <a href="{g->url arg1="view=members.MembersProfile" arg2="userId=`$id.userId`"}" target="_blank">{$id.userName}</a>
        {else}
            {$id.userName}
        {/if}
    </td>
    <td><a href="{g->text text="#"}" onclick="window.open('{g->url href="modules/userinfo/lookupip.php?ip=`$id.ipAddress`"}','popup','width=300,height=120,scrollbars');">{$id.ipAddress}</a></td>
    <td>
        {capture name="date"}{g->date timestamp=$id.timeStamp style="datetime" format=$Userinfo.uiDateFormat}{/capture}
        {g->text text="%s" arg1=$smarty.capture.date}
    </td>
    <td>
        {if ($id.action == "Login")}
            <h2 class="giSuccess">{$id.action}</h2>
        {else}
            {if ($id.action == "Logout")}
                {$id.action}
            {else}
                {if ($id.action == "Failed Login")}
                    <h2 class="giError">{$id.action}</h2>
                {else}
                    {$id.action}
                {/if}           
            {/if}
        {/if}
    </td>
</tr>
{foreachelse}
<tr>
    <td colspan="6"><center><b>{'No records in Database'|@translate}</b></center></td>
</tr>
{/foreach}

</table>
</div>

Offline

 

#5 2012-11-18 22:04:53

flop25
Piwigo Team
2006-07-06
7037

Re: User Info Tracking

What are you trying to do exactly?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#6 2012-11-18 22:09:11

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

I am trying to port the module that I did for gallery2 over to Piwigo.  Gallery2 also uses Smarty.
I was trying to get the admin.tpl page converted as I figured it wouldn't be that hard since it is Smarty.

Edit:
It is named UserInfo.tpl in my Gallery2 Module
http://gallery-contrib.svn.sourceforge. … l?view=log

Last edited by Charles2012 (2012-11-18 22:12:14)

Offline

 

#7 2012-11-19 12:29:19

flop25
Piwigo Team
2006-07-06
7037

Re: User Info Tracking

It's hard because of the specificity of Gallery added to Smarty.
Like g->date timestamp=$id.timeStamp style="datetime" format=$Userinfo.uiDateFormat
For Piwigo and for usual Smarty, you need to handle variables with php, then assign them :
http://www.smarty.net/docsv2/en/
http://www.smarty.net/docsv2/en/languag … .variables => gives in Piwigo :

global $template;
            $template->assign(array(
                    'MY_VAR' => $my_variable
            ));
with {$MY_VAR} in the tpl file.
see http://piwigo.org/dev/browser/extension … nc.php#L25 OR http://piwigo.org/dev/browser/extension … ecteur.php for an independent page (it's pop-up for a player)

admin.tpl page => is this your option page for the admin?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#8 2012-11-24 22:42:56

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

I installed the event tracer plugin and had $conf['show_queries'] set to true.

I noticed what when I login successfully, it shows this
login_success 0 calls
    50 UAM_LoginTasks

Why is it not showing a login_success?

When I failed a login I get this:

SELECT id AS id,
       password AS password
  FROM piwi_users
  WHERE username = 'test'
;
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.069 s)
(num rows        : 1 )

[0.069 s, 10 queries] : action "login_failure" 1 calls

'test'


When I log out there is nothing. At least in the way of an event/action listener.
I am making progress slowly.  Trying to figure out when is being picked when an action event occurs.
IE IP Address, Time, etc... so that I can log it into the database.

Offline

 

#9 2012-11-25 02:46:45

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

Can someone look at my sql syntax and see what I am doing incorrectly?
I want to get the username that is posted and find a match in the piwi_users table and get the id that is in that table for that user otherwise return a null value.



$myIpAddress2 = $_SERVER['REMOTE_ADDR'];

  $query = "SELECT * FROM piwi_users WHERE username = '" . $_POST['username'] . "';";
  $message = pwg_query($query);

IF($message) {
    $myid = $message['id'];
}else{
    $myid = "";
}
      pwg_query("INSERT INTO `". SKELETON_TABLE2 ."`(
          userID,
          userName,
          ipAddress,
          timeStamp,
          action
        )
        VALUES(
          '". $myid ."',
          '". $_POST['username'] ."',
          '". $myIpAddress2 ."',
          '". time() ."',
          'Failed Login'
        );");

Offline

 

#10 2012-11-26 13:10:06

flop25
Piwigo Team
2006-07-06
7037

Re: User Info Tracking

If I understand what you're tying to do, it's to add more info on login?
as you seen you need to use the trigger login_success (and if you need login_failure)

I want to get the username that is posted

on login and /or registration? On registration a practical example http://piwigo.org/dev/browser/extension … c.php#L310
for a login successful, you just need to use the global $user and $user['id']


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#11 2012-12-09 05:14:30

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

I have got the Successful Login and Failed Login going good now.
I noticed that there is not an action for when a user logs out.  I added
  trigger_action('logout', stripslashes($username));
to the below code from the include/functions_user.inc.php file

Code:

/** Performs all the cleanup on user logout */
function logout_user()
{
  global $conf;

  trigger_action('logout', stripslashes($username));

  $_SESSION = array();
  session_unset();
  session_destroy();
  setcookie(session_name(),'',0,
      ini_get('session.cookie_path'),
      ini_get('session.cookie_domain')
    );
  setcookie($conf['remember_me_name'], '', 0, cookie_path(),ini_get('session.cookie_domain'));
}

I have added the event handler in the correct area for the logout.
When I try to log the username that is logging out, it is only getting the guest.
Below is my function

Code:

function ui_logout()
{
  global $conf, $user;
  
  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
  $myIpAddress = $_SERVER['REMOTE_ADDR'];

      pwg_query("INSERT INTO `". SKELETON_TABLE2 ."`(
          userID,
          userName,
          ipAddress,
          timeStamp,
          action
        )
        VALUES(
          '". $user['id'] ."',
          '". $user['username'] ."',
          '". $myIpAddress ."',
          '". time() ."',
          'Logout'
        );");
}

The $user variable is being cleared before hand.
Any advice on how to go about this?

Last edited by Charles2012 (2012-12-16 18:42:55)

Offline

 

#12 2012-12-10 11:28:56

flop25
Piwigo Team
2006-07-06
7037

Re: User Info Tracking

sry I don't have any better idea : I notified someone else...


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#13 2012-12-14 05:05:33

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

Any suggestions?
Could a logout action be added to the core?

Offline

 

#14 2012-12-16 18:33:16

flop25
Piwigo Team
2006-07-06
7037

Re: User Info Tracking

Yes the logout action can be added : but if I understood well, it didn't solve your problem?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#15 2012-12-16 18:39:12

Charles2012
Member
2012-11-04
26

Re: User Info Tracking

That would be great. That is correct as in my code above I inserted the logout trigger before the cookies are deleted. don't understand why it is not picking up the user name that is logging out.

Offline

 
  •  » Engine
  •  » User Info Tracking

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact