1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_LoginTasks_Task_LastLogin extends Horde_LoginTasks_Task
16: {
17: 18: 19: 20: 21:
22: public $interval = Horde_LoginTasks::EVERY;
23:
24: 25: 26: 27: 28:
29: public $display = Horde_LoginTasks::DISPLAY_NONE;
30:
31: 32: 33:
34: public function execute()
35: {
36: global $injector, $notification, $prefs;
37:
38:
39: $old_login = @unserialize($prefs->getValue('last_login'));
40:
41: 42:
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:
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: