1: <?php
2: /**
3: * This class provides the credentials for the user currently accessing
4: * the export system.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_FreeBusy
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
13: */
14:
15: /**
16: * This class provides the credentials for the user currently accessing
17: * the export system.
18: *
19: * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you did not
22: * receive this file, see
23: * http://www.horde.org/licenses/lgpl21.
24: *
25: * @category Kolab
26: * @package Kolab_FreeBusy
27: * @author Gunnar Wrobel <wrobel@pardus.de>
28: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
29: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
30: */
31: class Horde_Kolab_FreeBusy_Params_User
32: {
33: /**
34: * The request.
35: *
36: * @var Horde_Controller_Request
37: */
38: private $_request;
39:
40: /**
41: * The user id.
42: *
43: * @var string
44: */
45: private $_user;
46:
47: /**
48: * The user password.
49: *
50: * @var string
51: */
52: private $_pass;
53:
54: /**
55: * Constructor.
56: *
57: * @param Horde_Controller_Request $request The request.
58: */
59: public function __construct(Horde_Controller_Request $request)
60: {
61: $this->_request = $request;
62: $this->_extractUserAndPassword();
63: }
64:
65: /**
66: * Return the user credentials extracted from the request.
67: *
68: * @return array The user credentials.
69: */
70: public function getCredentials()
71: {
72: return array($this->_user, $this->_pass);
73: }
74:
75: /**
76: * Return the user id.
77: *
78: * @return array The user id.
79: */
80: public function getUser()
81: {
82: return $this->_user;
83: }
84:
85: /**
86: * Extract user name and password from the request.
87: *
88: * @return NULL
89: */
90: private function _extractUserAndPassword()
91: {
92: $vars = $this->_request->getServerVars();
93: $this->_user = isset($vars['PHP_AUTH_USER']) ? $vars['PHP_AUTH_USER'] : null;
94: $this->_pass = isset($vars['PHP_AUTH_PW']) ? $vars['PHP_AUTH_PW'] : null;
95:
96: // This part allows you to use the PHP scripts with CGI rather than as
97: // an apache module. This will of course slow down things but on the
98: // other hand it allows you to reduce the memory footprint of the
99: // apache server. The default is to use PHP as a module and the CGI
100: // version requires specific Apache configuration.
101: //
102: // http://www.besthostratings.com/articles/http-auth-php-cgi.html
103: //
104: // The line you need to add to your configuration of the /freebusy
105: // location of your server looks like this:
106: //
107: // RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
108: //
109: // The complete section will probably look like this then:
110: //
111: // <IfModule mod_rewrite.c>
112: // RewriteEngine On
113: // # FreeBusy list handling
114: // RewriteBase /freebusy
115: // RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
116: // RewriteRule ^([^/]+)\.ifb freebusy.php?uid=$1 [L]
117: // RewriteRule ^([^/]+)\.vfb freebusy.php?uid=$1 [L]
118: // RewriteRule ^([^/]+)\.xfb freebusy.php?uid=$1&extended=1 [L]
119: // RewriteRule ^trigger/(.+)\.pfb pfb.php?folder=$1&cache=0 [L]
120: // RewriteRule ^(.+)\.pfb pfb.php?folder=$1&cache=1 [L]
121: // RewriteRule ^(.+)\.pxfb pfb.php?folder=$1&cache=1&extended=1 [L]
122: // </IfModule>
123: if (empty($this->_user)) {
124: $remote_user = isset($vars['REDIRECT_REDIRECT_REMOTE_USER']) ? $vars['REDIRECT_REDIRECT_REMOTE_USER'] : null;
125: if (!empty($remote_user)) {
126: $a = base64_decode(substr($remote_user, 6));
127: if (strlen($a) > 0 && strpos($a, ':') !== false) {
128: list($this->_user, $this->_pass) = explode(':', $a, 2);
129: }
130: } else {
131: $this->_user = '';
132: }
133: }
134: }
135: }