Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
auth_apache.php
001 <?php
002 /**
003 * Apache auth plug-in for phpBB3
004 *
005 * Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
006 *
007 * @package login
008 * @version $Id$
009 * @copyright (c) 2005 phpBB Group
010 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
011 *
012 */
013
014 /**
015 * @ignore
016 */
017 if (!defined('IN_PHPBB'))
018 {
019 exit;
020 }
021
022 /**
023 * Checks whether the user is identified to apache
024 * Only allow changing authentication to apache if the user is identified
025 * Called in acp_board while setting authentication plugins
026 *
027 * @return boolean|string false if the user is identified and else an error message
028 */
029 function init_apache()
030 {
031 global $user;
032
033 if (!isset($_SERVER['PHP_AUTH_USER']) || $user->data['username'] !== $_SERVER['PHP_AUTH_USER'])
034 {
035 return $user->lang['APACHE_SETUP_BEFORE_USE'];
036 }
037 return false;
038 }
039
040 /**
041 * Login function
042 */
043 function login_apache(&$username, &$password)
044 {
045 global $db;
046
047 // do not allow empty password
048 if (!$password)
049 {
050 return array(
051 'status' => LOGIN_BREAK,
052 'error_msg' => 'NO_PASSWORD_SUPPLIED',
053 );
054 }
055
056 if (!isset($_SERVER['PHP_AUTH_USER']))
057 {
058 return array(
059 'status' => LOGIN_ERROR_EXTERNAL_AUTH,
060 'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE',
061 'user_row' => array('user_id' => ANONYMOUS),
062 );
063 }
064
065 $php_auth_user = $_SERVER['PHP_AUTH_USER'];
066 $php_auth_pw = $_SERVER['PHP_AUTH_PW'];
067
068 if (!empty($php_auth_user) && !empty($php_auth_pw))
069 {
070 if ($php_auth_user !== $username)
071 {
072 return array(
073 'status' => LOGIN_ERROR_USERNAME,
074 'error_msg' => 'LOGIN_ERROR_USERNAME',
075 'user_row' => array('user_id' => ANONYMOUS),
076 );
077 }
078
079 $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
080 FROM ' . USERS_TABLE . "
081 WHERE username = '" . $db->sql_escape($php_auth_user) . "'";
082 $result = $db->sql_query($sql);
083 $row = $db->sql_fetchrow($result);
084 $db->sql_freeresult($result);
085
086 if ($row)
087 {
088 // User inactive...
089 if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
090 {
091 return array(
092 'status' => LOGIN_ERROR_ACTIVE,
093 'error_msg' => 'ACTIVE_ERROR',
094 'user_row' => $row,
095 );
096 }
097
098 // Successful login...
099 return array(
100 'status' => LOGIN_SUCCESS,
101 'error_msg' => false,
102 'user_row' => $row,
103 );
104 }
105
106 // this is the user's first login so create an empty profile
107 return array(
108 'status' => LOGIN_SUCCESS_CREATE_PROFILE,
109 'error_msg' => false,
110 'user_row' => user_row_apache($php_auth_user, $php_auth_pw),
111 );
112 }
113
114 // Not logged into apache
115 return array(
116 'status' => LOGIN_ERROR_EXTERNAL_AUTH,
117 'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE',
118 'user_row' => array('user_id' => ANONYMOUS),
119 );
120 }
121
122 /**
123 * Autologin function
124 *
125 * @return array containing the user row or empty if no auto login should take place
126 */
127 function autologin_apache()
128 {
129 global $db;
130
131 if (!isset($_SERVER['PHP_AUTH_USER']))
132 {
133 return array();
134 }
135
136 $php_auth_user = $_SERVER['PHP_AUTH_USER'];
137 $php_auth_pw = $_SERVER['PHP_AUTH_PW'];
138
139 if (!empty($php_auth_user) && !empty($php_auth_pw))
140 {
141 set_var($php_auth_user, $php_auth_user, 'string');
142 set_var($php_auth_pw, $php_auth_pw, 'string');
143
144 $sql = 'SELECT *
145 FROM ' . USERS_TABLE . "
146 WHERE username = '" . $db->sql_escape($php_auth_user) . "'";
147 $result = $db->sql_query($sql);
148 $row = $db->sql_fetchrow($result);
149 $db->sql_freeresult($result);
150
151 if ($row)
152 {
153 return ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) ? array() : $row;
154 }
155
156 if (!function_exists('user_add'))
157 {
158 global $phpbb_root_path, $phpEx;
159
160 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
161 }
162
163 // create the user if he does not exist yet
164 user_add(user_row_apache($php_auth_user, $php_auth_pw));
165
166 $sql = 'SELECT *
167 FROM ' . USERS_TABLE . "
168 WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($php_auth_user)) . "'";
169 $result = $db->sql_query($sql);
170 $row = $db->sql_fetchrow($result);
171 $db->sql_freeresult($result);
172
173 if ($row)
174 {
175 return $row;
176 }
177 }
178
179 return array();
180 }
181
182 /**
183 * This function generates an array which can be passed to the user_add function in order to create a user
184 */
185 function user_row_apache($username, $password)
186 {
187 global $db, $config, $user;
188 // first retrieve default group id
189 $sql = 'SELECT group_id
190 FROM ' . GROUPS_TABLE . "
191 WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
192 AND group_type = " . GROUP_SPECIAL;
193 $result = $db->sql_query($sql);
194 $row = $db->sql_fetchrow($result);
195 $db->sql_freeresult($result);
196
197 if (!$row)
198 {
199 trigger_error('NO_GROUP');
200 }
201
202 // generate user account data
203 return array(
204 'username' => $username,
205 'user_password' => phpbb_hash($password),
206 'user_email' => '',
207 'group_id' => (int) $row['group_id'],
208 'user_type' => USER_NORMAL,
209 'user_ip' => $user->ip,
210 );
211 }
212
213 /**
214 * The session validation function checks whether the user is still logged in
215 *
216 * @return boolean true if the given user is authenticated or false if the session should be closed
217 */
218 function validate_session_apache(&$user)
219 {
220 if (!isset($_SERVER['PHP_AUTH_USER']))
221 {
222 return false;
223 }
224
225 $php_auth_user = '';
226 set_var($php_auth_user, $_SERVER['PHP_AUTH_USER'], 'string');
227
228 return ($php_auth_user === $user['username']) ? true : false;
229 }
230
231 ?>