]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/DebugAuthInfo.php
Use CSS
[SourceForge/phpwiki.git] / lib / plugin / DebugAuthInfo.php
1 <?php
2
3 /**
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 require_once 'lib/Template.php';
24 /**
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.
28  *
29  * Warning! This may display db and user passwords in cleartext.
30  */
31 class WikiPlugin_DebugAuthInfo
32     extends WikiPlugin
33 {
34     function getDescription()
35     {
36         return _("Display general and user specific auth information.");
37     }
38
39     function getDefaultArguments()
40     {
41         return array('userid' => '');
42     }
43
44     function run($dbi, $argstr, &$request, $basepage)
45     {
46         $args = $this->getArgs($argstr, $request);
47         extract($args);
48         if (empty($userid) or $userid == $request->_user->UserName()) {
49             $user = $request->_user;
50             $userid = $user->UserName();
51         } else {
52             $user = WikiUser($userid);
53         }
54         if (!$user->isAdmin() and !(DEBUG && _DEBUG_LOGIN)) {
55             $request->_notAuthorized(WIKIAUTH_ADMIN);
56             $this->disabled("! user->isAdmin");
57         }
58
59         $html = HTML(HTML::h3(fmt("General Auth Settings")));
60         $table = HTML::table(array('class' => 'bordered'));
61         $table->pushContent($this->show_hash("AUTH DEFINES",
62             $this->buildConstHash(
63                 array("ENABLE_USER_NEW", "ALLOW_ANON_USER",
64                     "ALLOW_ANON_EDIT", "ALLOW_BOGO_LOGIN",
65                     "REQUIRE_SIGNIN_BEFORE_EDIT", "ALLOW_USER_PASSWORDS",
66                     "PASSWORD_LENGTH_MINIMUM", "USE_DB_SESSION"))));
67         if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP", $GLOBALS['USER_AUTH_ORDER']))
68             $table->pushContent($this->show_hash("LDAP DEFINES",
69                 $this->buildConstHash(array("LDAP_AUTH_HOST", "LDAP_BASE_DN"))));
70         if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP", $GLOBALS['USER_AUTH_ORDER']))
71             $table->pushContent($this->show_hash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
72         if (defined('AUTH_USER_FILE') or in_array("File", $GLOBALS['USER_AUTH_ORDER']))
73             $table->pushContent($this->show_hash("AUTH_USER_FILE",
74                 $this->buildConstHash(array("AUTH_USER_FILE",
75                     "AUTH_USER_FILE_STORABLE"))));
76         if (defined('GROUP_METHOD'))
77             $table->pushContent($this->show_hash("GROUP_METHOD",
78                 $this->buildConstHash(array("GROUP_METHOD", "AUTH_GROUP_FILE", "GROUP_LDAP_QUERY"))));
79         $table->pushContent($this->show_hash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
80         $table->pushContent($this->show_hash("USER_AUTH_POLICY", array("USER_AUTH_POLICY" => USER_AUTH_POLICY)));
81         $DBParams = $GLOBALS['DBParams'];
82         $DBParams['dsn'] = class_exists('WikiDB_SQL') ? WikiDB_SQL::view_dsn($DBParams['dsn']) : '';
83         $table->pushContent($this->show_hash("\$DBParams[]", $DBParams));
84         $DBAuthParams = $GLOBALS['DBAuthParams'];
85         if (isset($DBAuthParams['auth_dsn']) and class_exists('WikiDB_SQL'))
86             $DBAuthParams['auth_dsn'] = WikiDB_SQL::view_dsn($DBAuthParams['auth_dsn']);
87         else
88             $DBAuthParams['auth_dsn'] = '';
89         unset($DBAuthParams['dummy']);
90         $table->pushContent($this->show_hash("\$DBAuthParams[]", $DBAuthParams));
91         $html->pushContent($table);
92         $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for ā€œ%sā€", $userid))));
93         if (!$user) {
94             $html->pushContent(HTML::p(fmt("No userid")));
95         } else {
96             $table = HTML::table(array('class' => 'bordered'));
97             //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
98             $userdata = obj2hash($user, array('_dbi', '_request', 'password', 'passwd'));
99             if (isa($user, "_FilePassUser")) {
100                 foreach ($userdata['_file']->users as $u => $p) {
101                     $userdata['_file']->users[$u] = "<hidden>";
102                 }
103             }
104             $table->pushContent($this->show_hash("User: Object of " . get_class($user), $userdata));
105             if (ENABLE_USER_NEW) {
106                 $group = &$request->getGroup();
107                 $groups = $group->getAllGroupsIn();
108                 $groupdata = obj2hash($group, array('_dbi', '_request', 'password', 'passwd'));
109                 unset($groupdata['request']);
110                 $table->pushContent($this->show_hash("Group: Object of " . get_class($group), $groupdata));
111                 $groups = $group->getAllGroupsIn();
112                 $groupdata = array('getAllGroupsIn' => $groups);
113                 foreach ($groups as $g) {
114                     $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
115                     $groupdata["isMember($g)"] = $group->isMember($g);
116                 }
117                 $table->pushContent($this->show_hash("Group Methods: ", $groupdata));
118             }
119             $html->pushContent($table);
120         }
121         return $html;
122     }
123
124     private function show_hash($heading, $hash, $depth = 0)
125     {
126         static $seen = array();
127         static $max_depth = 0;
128         $rows = array();
129         $max_depth++;
130         if ($max_depth > 35) return $heading;
131
132         if ($heading)
133             $rows[] = HTML::tr(array(
134                     'style' => 'color:#000;background-color:#ffcccc'),
135                 HTML::td(array('colspan' => 2,
136                         'style' => 'color:#000'),
137                     $heading));
138         if (is_object($hash))
139             $hash = obj2hash($hash);
140         if (!empty($hash)) {
141             ksort($hash);
142             foreach ($hash as $key => $val) {
143                 if (is_object($val)) {
144                     $heading = "Object of " . get_class($val);
145                     if ($depth > 3) $val = $heading;
146                     elseif ($heading == "Object of wikidb_sql") $val = $heading; elseif (substr($heading, 0, 13) == "Object of db_") $val = $heading; elseif (!isset($seen[$heading])) {
147                         //if (empty($seen[$heading])) $seen[$heading] = 1;
148                         $val = HTML::table(array('class' => 'bordered'),
149                             $this->show_hash($heading, obj2hash($val), $depth + 1));
150                     } else {
151                         $val = $heading;
152                     }
153                 } elseif (is_array($val)) {
154                     $heading = $key . "[]";
155                     if ($depth > 3) $val = $heading;
156                     elseif (!isset($seen[$heading])) {
157                         //if (empty($seen[$heading])) $seen[$heading] = 1;
158                         $val = HTML::table(array('class' => 'bordered'),
159                             $this->show_hash($heading, $val, $depth + 1));
160                     } else {
161                         $val = $heading;
162                     }
163                 }
164                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
165                             'bgcolor' => '#ccc',
166                             'style' => 'color:#000000'),
167                         HTML(HTML::raw('&nbsp;'), $key,
168                             HTML::raw('&nbsp;'))),
169                     HTML::td(array('bgcolor' => '#fff',
170                             'style' => 'color:#000000'),
171                         $val ? $val : HTML::raw('&nbsp;'))
172                 );
173                 //if (empty($seen[$key])) $seen[$key] = 1;
174             }
175         }
176         return $rows;
177     }
178
179     private function buildConstHash($constants)
180     {
181         $hash = array();
182         foreach ($constants as $c) {
183             $hash[$c] = defined($c) ? constant($c) : '<empty>';
184             if ($hash[$c] === false) $hash[$c] = 'false';
185             elseif ($hash[$c] === true) $hash[$c] = 'true';
186         }
187         return $hash;
188     }
189 }
190
191 // Local Variables:
192 // mode: php
193 // tab-width: 8
194 // c-basic-offset: 4
195 // c-hanging-comment-ender-p: nil
196 // indent-tabs-mode: nil
197 // End: