4 * Copyright 2004 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require_once 'lib/Template.php';
25 * Used to debug auth problems and settings.
26 * This plugin is only testing purposes.
27 * if DEBUG is false, only admin can call it, which is of no real use.
29 * Warning! This may display db and user passwords in cleartext.
31 class WikiPlugin__AuthInfo
34 function getDescription()
36 return _("Display general and user specific auth information.");
39 function getDefaultArguments()
41 return array('userid' => '');
44 function run($dbi, $argstr, &$request, $basepage)
46 $args = $this->getArgs($argstr, $request);
48 if (empty($userid) or $userid == $request->_user->UserName()) {
49 $user = $request->_user;
50 $userid = $user->UserName();
52 $user = WikiUser($userid);
54 if (!$user->isAdmin() and !(DEBUG && _DEBUG_LOGIN)) {
55 $request->_notAuthorized(WIKIAUTH_ADMIN);
56 $this->disabled("! user->isAdmin");
59 $html = HTML(HTML::h3(fmt("General Auth Settings")));
60 $table = HTML::table(array('border' => 1,
63 $table->pushContent($this->show_hash("AUTH DEFINES",
64 $this->buildConstHash(
65 array("ENABLE_USER_NEW", "ALLOW_ANON_USER",
66 "ALLOW_ANON_EDIT", "ALLOW_BOGO_LOGIN",
67 "REQUIRE_SIGNIN_BEFORE_EDIT", "ALLOW_USER_PASSWORDS",
68 "PASSWORD_LENGTH_MINIMUM", "USE_DB_SESSION"))));
69 if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP", $GLOBALS['USER_AUTH_ORDER']))
70 $table->pushContent($this->show_hash("LDAP DEFINES",
71 $this->buildConstHash(array("LDAP_AUTH_HOST", "LDAP_BASE_DN"))));
72 if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP", $GLOBALS['USER_AUTH_ORDER']))
73 $table->pushContent($this->show_hash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
74 if (defined('AUTH_USER_FILE') or in_array("File", $GLOBALS['USER_AUTH_ORDER']))
75 $table->pushContent($this->show_hash("AUTH_USER_FILE",
76 $this->buildConstHash(array("AUTH_USER_FILE",
77 "AUTH_USER_FILE_STORABLE"))));
78 if (defined('GROUP_METHOD'))
79 $table->pushContent($this->show_hash("GROUP_METHOD",
80 $this->buildConstHash(array("GROUP_METHOD", "AUTH_GROUP_FILE", "GROUP_LDAP_QUERY"))));
81 $table->pushContent($this->show_hash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
82 $table->pushContent($this->show_hash("USER_AUTH_POLICY", array("USER_AUTH_POLICY" => USER_AUTH_POLICY)));
83 $DBParams = $GLOBALS['DBParams'];
84 $DBParams['dsn'] = class_exists('WikiDB_SQL') ? WikiDB_SQL::view_dsn($DBParams['dsn']) : '';
85 $table->pushContent($this->show_hash("\$DBParams[]", $DBParams));
86 $DBAuthParams = $GLOBALS['DBAuthParams'];
87 if (isset($DBAuthParams['auth_dsn']) and class_exists('WikiDB_SQL'))
88 $DBAuthParams['auth_dsn'] = WikiDB_SQL::view_dsn($DBAuthParams['auth_dsn']);
90 $DBAuthParams['auth_dsn'] = '';
91 unset($DBAuthParams['dummy']);
92 $table->pushContent($this->show_hash("\$DBAuthParams[]", $DBAuthParams));
93 $html->pushContent($table);
94 $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for ā%sā", $userid))));
96 $html->pushContent(HTML::p(fmt("No userid")));
98 $table = HTML::table(array('border' => 1,
100 'cellspacing' => 0));
101 //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
102 $userdata = obj2hash($user, array('_dbi', '_request', 'password', 'passwd'));
103 if (isa($user, "_FilePassUser")) {
104 foreach ($userdata['_file']->users as $u => $p) {
105 $userdata['_file']->users[$u] = "<hidden>";
108 $table->pushContent($this->show_hash("User: Object of " . get_class($user), $userdata));
109 if (ENABLE_USER_NEW) {
110 $group = &$request->getGroup();
111 $groups = $group->getAllGroupsIn();
112 $groupdata = obj2hash($group, array('_dbi', '_request', 'password', 'passwd'));
113 unset($groupdata['request']);
114 $table->pushContent($this->show_hash("Group: Object of " . get_class($group), $groupdata));
115 $groups = $group->getAllGroupsIn();
116 $groupdata = array('getAllGroupsIn' => $groups);
117 foreach ($groups as $g) {
118 $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
119 $groupdata["isMember($g)"] = $group->isMember($g);
121 $table->pushContent($this->show_hash("Group Methods: ", $groupdata));
123 $html->pushContent($table);
128 private function show_hash($heading, $hash, $depth = 0)
130 static $seen = array();
131 static $max_depth = 0;
134 if ($max_depth > 35) return $heading;
137 $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
138 'style' => 'color:#000000'),
139 HTML::td(array('colspan' => 2,
140 'style' => 'color:#000000'),
142 if (is_object($hash))
143 $hash = obj2hash($hash);
146 foreach ($hash as $key => $val) {
147 if (is_object($val)) {
148 $heading = "Object of " . get_class($val);
149 if ($depth > 3) $val = $heading;
150 elseif ($heading == "Object of wikidb_sql") $val = $heading; elseif (substr($heading, 0, 13) == "Object of db_") $val = $heading; elseif (!isset($seen[$heading])) {
151 //if (empty($seen[$heading])) $seen[$heading] = 1;
152 $val = HTML::table(array('border' => 1,
155 $this->show_hash($heading, obj2hash($val), $depth + 1));
159 } elseif (is_array($val)) {
160 $heading = $key . "[]";
161 if ($depth > 3) $val = $heading;
162 elseif (!isset($seen[$heading])) {
163 //if (empty($seen[$heading])) $seen[$heading] = 1;
164 $val = HTML::table(array('border' => 1,
167 $this->show_hash($heading, $val, $depth + 1));
172 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
173 'bgcolor' => '#cccccc',
174 'style' => 'color:#000000'),
175 HTML(HTML::raw(' '), $key,
176 HTML::raw(' '))),
177 HTML::td(array('bgcolor' => '#ffffff',
178 'style' => 'color:#000000'),
179 $val ? $val : HTML::raw(' '))
181 //if (empty($seen[$key])) $seen[$key] = 1;
187 private function buildConstHash($constants)
190 foreach ($constants as $c) {
191 $hash[$c] = defined($c) ? constant($c) : '<empty>';
192 if ($hash[$c] === false) $hash[$c] = 'false';
193 elseif ($hash[$c] === true) $hash[$c] = 'true';
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil