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