File: Finger.php

package info (click to toggle)
php-horde 5.2.13%2Bdebian0-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,652 kB
  • sloc: php: 11,153; xml: 6,751; javascript: 5,560; sh: 92; makefile: 33; sql: 1
file content (113 lines) | stat: -rw-r--r-- 2,938 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
 * Implements the Accounts API using finger to fetch information.
 *
 * Copyright 2001-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author  Peter Paul Elfferich <pp@lazyfox.org>
 * @author  Jan Schneider <jan@horde.org>
 * @package Horde
 */
class Horde_Block_Account_Finger extends Horde_Block_Account_Base
{
    /**
     * Constructor.
     *
     * @param array $params  Hash containing connection parameters.
     */
    public function __construct($params = array())
    {
        $params = array_merge(
            array('finger_path' => 'finger'),
            $params);
        parent::__construct($params);
    }

    /**
     * Returns a hash with parsed account information.
     *
     * @param array $output  Array of finger output strings
     *
     * @return array  A hash with account details parsed from output
     */
    protected function _parseAccount($output)
    {
        $info = array();

        foreach ($output as $line) {
            if (preg_match('/^.*Name: (.*)$/', $line, $regs)) {
                $info['fullname'] = $regs[1];
            } elseif (preg_match('/^Directory: (.*)Shell: (.*)$/', $line, $regs)) {
                $info['home'] = trim($regs[1]);
                $info['shell'] = $regs[2];
            }
        }

        return $info;
    }

    /**
     * Returns the user account.
     *
     * @return array  A hash with complete account details.
     */
    protected function _getAccount()
    {
        if (!isset($this->_information)) {
            $user = Horde_String::lower($this->getUsername());
            if (!empty($this->_params['host'])) {
                $user .= '@' . $this->_params['host'];
            }
            $command = $this->_params['finger_path'] . ' ' . escapeshellarg($user);
            exec($command, $output);
            $this->_information = $this->_parseAccount($output);
        }
        return $this->_information;
    }

    /**
     * Returns some user detail.
     *
     * @param string $what  Which information to return.
     *
     * @return string  The user's detail.
     */
    protected function _get($what)
    {
        $information = $this->_getAccount();
        return $information[$what];
    }

    /**
     * Returns the user's full name.
     *
     * @return string  The user's full name.
     */
    public function getFullname()
    {
        return $this->_get('fullname');
    }

    /**
     * Returns the user's home (login) directory.
     *
     * @return string  The user's directory.
     */
    public function getHome()
    {
        return $this->_get('home');
    }

    /**
     * Returns the user's default shell.
     *
     * @return string  The user's shell.
     */
    public function getShell()
    {
        return $this->_get('shell');
    }
}