• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revision26896abedaa94b9c3b2af465f0d6c14fd2d076bc (tree)
Time2016-02-02 01:15:39
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack2/374 Record fullname of edit user(author)

Change Summary

Incremental Difference

--- a/lib/auth.php
+++ b/lib/auth.php
@@ -243,7 +243,8 @@ function basic_auth($page, $auth_flag, $exit_flag, $auth_pages, $title_cannot)
243243 function ensure_valid_auth_user()
244244 {
245245 global $auth_type, $auth_users, $_msg_auth, $auth_user, $auth_groups;
246- global $auth_user_groups;
246+ global $auth_user_groups, $auth_user_fullname;
247+ global $auth_provider_user_prefix;
247248 switch ($auth_type) {
248249 case AUTH_TYPE_BASIC:
249250 {
@@ -254,6 +255,7 @@ function ensure_valid_auth_user()
254255 $_SERVER['PHP_AUTH_PW'],
255256 $auth_users[$user]) === $auth_users[$user]) {
256257 $auth_user = $user;
258+ $auth_user_fullname = $auth_user;
257259 $auth_user_groups = get_groups_from_username($user);
258260 return true;
259261 }
@@ -269,22 +271,37 @@ function ensure_valid_auth_user()
269271 case AUTH_TYPE_EXTERNAL:
270272 {
271273 session_start();
272- // session_regenerate_id(true);
273274 $user = '';
275+ $fullname = '';
274276 if (isset($_SESSION['authenticated_user'])) {
275277 $user = $_SESSION['authenticated_user'];
278+ if (isset($_SESSION['authenticated_user_fullname'])) {
279+ $fullname = $_SESSION['authenticated_user_fullname'];
280+ } else {
281+ if ($auth_type === AUTH_TYPE_EXTERNAL && $ldap_user_account) {
282+ $ldap_user_info = ldap_get_simple_user_info($user);
283+ if ($ldap_user_info) {
284+ $fullname = $ldap_user_info['fullname'];
285+ $_SESSION['authenticated_user_fullname'] = $fullname;
286+ }
287+ }
288+ }
276289 }
277290 $auth_user = $user;
291+ $auth_user_fullname = $fullname;
278292 break;
279293 }
280294 case AUTH_TYPE_EXTERNAL_REMOTE_USER:
281295 $auth_user = $_SERVER['REMOTE_USER'];
296+ $auth_user_fullname = $auth_user;
282297 break;
283298 case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
284299 $auth_user = $_SERVER['HTTP_X_FORWARDED_USER'];
300+ $auth_user_fullname = $auth_user;
285301 break;
286302 default: // AUTH_TYPE_NONE
287303 $auth_user = '';
304+ $auth_user_fullname = '';
288305 break;
289306 }
290307 $auth_user_groups = get_groups_from_username($auth_user);
@@ -354,8 +371,10 @@ function form_auth($username, $password)
354371 if (pkwk_hash_compute(
355372 $password,
356373 $auth_users[$user]) === $auth_users[$user]) {
357- $_SESSION['authenticated_user'] = $user;
374+ session_start();
358375 session_regenerate_id(true); // require: PHP5.1+
376+ $_SESSION['authenticated_user'] = $user;
377+ $_SESSION['authenticated_user_fullname'] = $user;
359378 return true;
360379 }
361380 }
@@ -379,8 +398,9 @@ function ldap_auth($username, $password)
379398 if ($ldap_bind_user) {
380399 $user_info = get_ldap_user_info($ldapconn, $username, $ldap_base_dn);
381400 if ($user_info) {
382- $_SESSION['authenticated_user'] = $user_info['uid'];
383401 session_regenerate_id(true); // require: PHP5.1+
402+ $_SESSION['authenticated_user'] = $user_info['uid'];
403+ $_SESSION['authenticated_user_fullname'] = $user_info['fullname'];
384404 return true;
385405 }
386406 }
@@ -392,8 +412,9 @@ function ldap_auth($username, $password)
392412 if ($user_info) {
393413 $ldap_bind_user2 = ldap_bind($ldapconn, $user_info['dn'], $password);
394414 if ($ldap_bind_user2) {
395- $_SESSION['authenticated_user'] = $user_info['uid'];
396415 session_regenerate_id(true); // require: PHP5.1+
416+ $_SESSION['authenticated_user'] = $user_info['uid'];
417+ $_SESSION['authenticated_user_fullname'] = $user_info['fullname'];
397418 return true;
398419 }
399420 }
@@ -401,6 +422,30 @@ function ldap_auth($username, $password)
401422 }
402423 }
403424 }
425+ return false;
426+}
427+
428+// Get LDAP user info via bind DN
429+function ldap_get_simple_user_info($username)
430+{
431+ global $ldap_url, $ldap_bind_dn, $ldap_bind_password;
432+ if (preg_match('#^(ldap\:\/\/[^/]+/)(.*)$#', $ldap_url, $m)) {
433+ $ldap_server = $m[1];
434+ $ldap_base_dn = $m[2];
435+ $ldapconn = ldap_connect($ldap_server);
436+ if ($ldapconn) {
437+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
438+ // Bind by bind dn
439+ $ldap_bind = ldap_bind($ldapconn, $ldap_bind_dn, $ldap_bind_password);
440+ if ($ldap_bind) {
441+ $user_info = get_ldap_user_info($ldapconn, $username, $ldap_base_dn);
442+ if ($user_info) {
443+ return $user_info;
444+ }
445+ }
446+ }
447+ }
448+ return false;
404449 }
405450
406451 /**
--- a/lib/file.php
+++ b/lib/file.php
@@ -161,11 +161,31 @@ function make_str_rules($source)
161161
162162 function add_author_info($wikitext)
163163 {
164- global $auth_user;
164+ global $auth_user, $auth_user_fullname, $auth_type, $ldap_user_account;
165165 $author = preg_replace('/"/', '', $auth_user);
166- $displayname = preg_replace('/"/', '', $auth_user);
166+ $displayname = preg_replace('/"/', '', $auth_user_fullname);
167+ $user_prefix = '';
168+ switch ($auth_type) {
169+ case AUTH_TYPE_BASIC:
170+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_DEFAULT;
171+ break;
172+ case AUTH_TYPE_EXTERNAL:
173+ case AUTH_TYPE_EXTERNAL_REMOTE_USER:
174+ case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
175+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_EXTERNAL;
176+ break;
177+ case AUTH_TYPE_FORM:
178+ if ($ldap_user_account) {
179+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_LDAP;
180+ } else {
181+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_DEFAULT;
182+ }
183+ break;
184+ }
167185 $author_text = sprintf('#author("%s","%s","%s")',
168- get_date_atom(UTIME + LOCALZONE), $author, $displayname) . "\n";
186+ get_date_atom(UTIME + LOCALZONE),
187+ ($author ? $user_prefix . $author : ''),
188+ $displayname) . "\n";
169189 return $author_text . $wikitext;
170190 }
171191
Show on old repository browser