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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
38 function getDescription () {
39 return _("Display general and user specific auth information.");
42 function getVersion() {
43 return preg_replace("/[Revision: $]/", '',
47 function getDefaultArguments() {
48 return array('userid' => '');
51 function run($dbi, $argstr, &$request, $basepage) {
52 $args = $this->getArgs($argstr, $request);
54 if (empty($userid) or $userid == $request->_user->UserName()) {
55 $user = $request->_user;
56 $userid = $user->UserName();
58 $user = WikiUser($userid);
60 if (!$user->isAdmin() and ! (DEBUG && _DEBUG_LOGIN)) {
61 $request->_notAuthorized(WIKIAUTH_ADMIN);
62 $this->disabled("! user->isAdmin");
65 $html = HTML(HTML::h3(fmt("General Auth Settings")));
66 $table = HTML::table(array('border' => 1,
69 $table->pushContent($this->_showhash("AUTH DEFINES",
70 $this->_buildConstHash(
71 array("ENABLE_USER_NEW","ALLOW_ANON_USER",
72 "ALLOW_ANON_EDIT","ALLOW_BOGO_LOGIN",
73 "REQUIRE_SIGNIN_BEFORE_EDIT","ALLOW_USER_PASSWORDS",
74 "PASSWORD_LENGTH_MINIMUM","USE_DB_SESSION"))));
75 if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP",$GLOBALS['USER_AUTH_ORDER']))
76 $table->pushContent($this->_showhash("LDAP DEFINES",
77 $this->_buildConstHash(array("LDAP_AUTH_HOST","LDAP_BASE_DN"))));
78 if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP",$GLOBALS['USER_AUTH_ORDER']))
79 $table->pushContent($this->_showhash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
80 if (defined('AUTH_USER_FILE') or in_array("File",$GLOBALS['USER_AUTH_ORDER']))
81 $table->pushContent($this->_showhash("AUTH_USER_FILE",
82 $this->_buildConstHash(array("AUTH_USER_FILE",
83 "AUTH_USER_FILE_STORABLE"))));
84 if (defined('GROUP_METHOD'))
85 $table->pushContent($this->_showhash("GROUP_METHOD",
86 $this->_buildConstHash(array("GROUP_METHOD","AUTH_GROUP_FILE","GROUP_LDAP_QUERY"))));
87 $table->pushContent($this->_showhash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
88 $table->pushContent($this->_showhash("USER_AUTH_POLICY", array("USER_AUTH_POLICY"=>USER_AUTH_POLICY)));
89 $DBParams = $GLOBALS['DBParams'];
90 $DBParams['dsn'] = class_exists('WikiDB_SQL') ? WikiDB_SQL::view_dsn($DBParams['dsn']) : '';
91 $table->pushContent($this->_showhash("\$DBParams[]", $DBParams));
92 $DBAuthParams = $GLOBALS['DBAuthParams'];
93 if (isset($DBAuthParams['auth_dsn']) and class_exists('WikiDB_SQL'))
94 $DBAuthParams['auth_dsn'] = WikiDB_SQL::view_dsn($DBAuthParams['auth_dsn']);
96 $DBAuthParams['auth_dsn'] = '';
97 unset($DBAuthParams['dummy']);
98 $table->pushContent($this->_showhash("\$DBAuthParams[]", $DBAuthParams));
99 $html->pushContent($table);
100 $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for '%s'", $userid))));
102 $html->pushContent(HTML::p(fmt("No userid")));
104 $table = HTML::table(array('border' => 1,
106 'cellspacing' => 0));
107 //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
108 $userdata = obj2hash($user, array('_dbi','_request', 'password', 'passwd'));
109 if (isa($user, "_FilePassUser")) {
110 foreach ($userdata['_file']->users as $u => $p) {
111 $userdata['_file']->users[$u] = "<hidden>";
114 $table->pushContent($this->_showhash("User: Object of ".get_class($user), $userdata));
115 if (ENABLE_USER_NEW) {
116 $group = &$request->getGroup();
117 $groups = $group->getAllGroupsIn();
118 $groupdata = obj2hash($group, array('_dbi','_request', 'password', 'passwd'));
119 unset($groupdata['request']);
120 $table->pushContent($this->_showhash("Group: Object of ".get_class($group), $groupdata));
121 $groups = $group->getAllGroupsIn();
122 $groupdata = array('getAllGroupsIn' => $groups);
123 foreach ($groups as $g) {
124 $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
125 $groupdata["isMember($g)"] = $group->isMember($g);
127 $table->pushContent($this->_showhash("Group Methods: ", $groupdata));
129 $html->pushContent($table);
134 function _showhash ($heading, $hash, $depth = 0) {
135 static $seen = array();
136 static $maxdepth = 0;
139 if ($maxdepth > 35) return $heading;
142 $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
143 'style' => 'color:#000000'),
144 HTML::td(array('colspan' => 2,
145 'style' => 'color:#000000'),
147 if (is_object($hash))
148 $hash = obj2hash($hash);
151 foreach ($hash as $key => $val) {
152 if (is_object($val)) {
153 $heading = "Object of ".get_class($val);
154 if ($depth > 3) $val = $heading;
155 elseif ($heading == "Object of wikidb_sql") $val = $heading;
156 elseif (substr($heading,0,13) == "Object of db_") $val = $heading;
157 elseif (!isset($seen[$heading])) {
158 //if (empty($seen[$heading])) $seen[$heading] = 1;
159 $val = HTML::table(array('border' => 1,
162 $this->_showhash($heading, obj2hash($val), $depth+1));
166 } elseif (is_array($val)) {
167 $heading = $key."[]";
168 if ($depth > 3) $val = $heading;
169 elseif (!isset($seen[$heading])) {
170 //if (empty($seen[$heading])) $seen[$heading] = 1;
171 $val = HTML::table(array('border' => 1,
174 $this->_showhash($heading, $val, $depth+1));
179 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
180 'bgcolor' => '#cccccc',
181 'style' => 'color:#000000'),
182 HTML(HTML::raw(' '), $key,
183 HTML::raw(' '))),
184 HTML::td(array('bgcolor' => '#ffffff',
185 'style' => 'color:#000000'),
186 $val ? $val : HTML::raw(' '))
188 //if (empty($seen[$key])) $seen[$key] = 1;
194 function _buildConstHash($constants) {
196 foreach ($constants as $c) {
197 $hash[$c] = defined($c) ? constant($c) : '<empty>';
198 if ($hash[$c] === false) $hash[$c] = 'false';
199 elseif ($hash[$c] === true) $hash[$c] = 'true';
205 // (c-file-style: "gnu")
210 // c-hanging-comment-ender-p: nil
211 // indent-tabs-mode: nil