1: <?php
2: /**
3: * Implements the Accounts API using finger to fetch information.
4: *
5: * Copyright 2001-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 Peter Paul Elfferich <pp@lazyfox.org>
11: * @author Jan Schneider <jan@horde.org>
12: * @package Horde
13: */
14: class Horde_Block_Account_Finger extends Horde_Block_Account_Base
15: {
16: /**
17: * Constructor.
18: *
19: * @param array $params Hash containing connection parameters.
20: */
21: public function __construct($params = array())
22: {
23: $params = array_merge(
24: array('finger_path' => 'finger'),
25: $params);
26: parent::__construct($params);
27: }
28:
29: /**
30: * Returns a hash with parsed account information.
31: *
32: * @param array $output Array of finger output strings
33: *
34: * @return array A hash with account details parsed from output
35: */
36: protected function _parseAccount($output)
37: {
38: $info = array();
39:
40: foreach ($output as $line) {
41: if (preg_match('/^.*Name: (.*)$/', $line, $regs)) {
42: $info['fullname'] = $regs[1];
43: } elseif (preg_match('/^Directory: (.*)Shell: (.*)$/', $line, $regs)) {
44: $info['home'] = trim($regs[1]);
45: $info['shell'] = $regs[2];
46: }
47: }
48:
49: return $info;
50: }
51:
52: /**
53: * Returns the user account.
54: *
55: * @return array A hash with complete account details.
56: */
57: protected function _getAccount()
58: {
59: if (!isset($this->_information)) {
60: $user = Horde_String::lower($this->getUsername());
61: if (!empty($this->_params['host'])) {
62: $user .= '@' . $this->_params['host'];
63: }
64: $command = $this->_params['finger_path'] . ' ' . escapeshellarg($user);
65: exec($command, $output);
66: $this->_information = $this->_parseAccount($output);
67: }
68: return $this->_information;
69: }
70:
71: /**
72: * Returns some user detail.
73: *
74: * @param string $what Which information to return.
75: *
76: * @return string The user's detail.
77: */
78: protected function _get($what)
79: {
80: $information = $this->_getAccount();
81: return $information[$what];
82: }
83:
84: /**
85: * Returns the user's full name.
86: *
87: * @return string The user's full name.
88: */
89: public function getFullname()
90: {
91: return $this->_get('fullname');
92: }
93:
94: /**
95: * Returns the user's home (login) directory.
96: *
97: * @return string The user's directory.
98: */
99: public function getHome()
100: {
101: return $this->_get('home');
102: }
103:
104: /**
105: * Returns the user's default shell.
106: *
107: * @return string The user's shell.
108: */
109: public function getShell()
110: {
111: return $this->_get('shell');
112: }
113: }
114: