Overview

Packages

  • Horde
  • None

Classes

  • Horde_Ajax_Application
  • Horde_Api
  • Horde_Block_Account
  • Horde_Block_Account_Base
  • Horde_Block_Account_Finger
  • Horde_Block_Account_Ldap
  • Horde_Block_Account_Localhost
  • Horde_Block_Cloud
  • Horde_Block_FbStream
  • Horde_Block_Feed
  • Horde_Block_Fortune
  • Horde_Block_Google
  • Horde_Block_Iframe
  • Horde_Block_Metar
  • Horde_Block_Moon
  • Horde_Block_Sunrise
  • Horde_Block_Time
  • Horde_Block_TwitterTimeline
  • Horde_Block_Vatid
  • Horde_Block_Weather
  • Horde_LoginTasks_SystemTask_GarbageCollection
  • Horde_LoginTasks_SystemTask_Upgrade
  • Horde_LoginTasks_Task_AdminCheck
  • Horde_LoginTasks_Task_LastLogin
  • Horde_LoginTasks_Task_TosAgreement
  • Horde_Prefs_Ui
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Login task to output last login information.
 4:  *
 5:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file COPYING for license information (LGPL). If you
 8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 9:  *
10:  * @author   Michael Slusarz <slusarz@horde.org>
11:  * @category Horde
12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
13:  * @package  Horde
14:  */
15: class Horde_LoginTasks_Task_LastLogin extends Horde_LoginTasks_Task
16: {
17:     /**
18:      * The interval at which to run the task.
19:      *
20:      * @var integer
21:      */
22:     public $interval = Horde_LoginTasks::EVERY;
23: 
24:     /**
25:      * Display type.
26:      *
27:      * @var integer
28:      */
29:     public $display = Horde_LoginTasks::DISPLAY_NONE;
30: 
31:     /**
32:      * Perform all functions for this task.
33:      */
34:     public function execute()
35:     {
36:         global $injector, $notification, $prefs;
37: 
38:         /* Fetch the user's last login time. */
39:         $old_login = @unserialize($prefs->getValue('last_login'));
40: 
41:         /* Display it, if we have a notification object and the
42:          * show_last_login preference is active. */
43:         if (isset($notification) && $prefs->getValue('show_last_login')) {
44:             $date_format = $prefs->getValue('date_format') . ' (' . $prefs->getValue('time_format') . ')';
45: 
46:             if (empty($old_login['time'])) {
47:                 $notification->push(_("Last login: Never"), 'horde.message');
48:             } elseif (empty($old_login['host'])) {
49:                 $notification->push(sprintf(_("Last login: %s"), strftime($date_format, $old_login['time'])), 'horde.message');
50:             } else {
51:                 $notification->push(sprintf(_("Last login: %s from %s"), strftime($date_format, $old_login['time']), $old_login['host']), 'horde.message');
52:             }
53:         }
54: 
55:         /* Set the user's last_login information. */
56:         $host = empty($_SERVER['HTTP_X_FORWARDED_FOR'])
57:             ? $_SERVER['REMOTE_ADDR']
58:             : $_SERVER['HTTP_X_FORWARDED_FOR'];
59: 
60:         if ($dns = $injector->getInstance('Net_DNS2_Resolver')) {
61:             $ptrdname = $host;
62:             try {
63:                 if ($response = $dns->query($host, 'PTR')) {
64:                     foreach ($response->answer as $val) {
65:                         if (isset($val->ptrdname)) {
66:                             $ptrdname = $val->ptrdname;
67:                             break;
68:                         }
69:                     }
70:                 }
71:             } catch (Net_DNS2_Exception $e) {}
72:         } else {
73:             $ptrdname = @gethostbyaddr($host);
74:         }
75: 
76:         $prefs->setValue('last_login', serialize(array(
77:             'host' => $ptrdname,
78:             'time' => time()
79:         )));
80:     }
81: 
82: }
83: 
API documentation generated by ApiGen