]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
No underscore for private function
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.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__AuthInfo
32     extends WikiPlugin
33 {
34     function getName()
35     {
36         return _("AuthInfo");
37     }
38
39     function getDescription()
40     {
41         return _("Display general and user specific auth information.");
42     }
43
44     function getDefaultArguments()
45     {
46         return array('userid' => '');
47     }
48
49     function run($dbi, $argstr, &$request, $basepage)
50     {
51         $args = $this->getArgs($argstr, $request);
52         extract($args);
53         if (empty($userid) or $userid == $request->_user->UserName()) {
54             $user = $request->_user;
55             $userid = $user->UserName();
56         } else {
57             $user = WikiUser($userid);
58         }
59         if (!$user->isAdmin() and !(DEBUG && _DEBUG_LOGIN)) {
60             $request->_notAuthorized(WIKIAUTH_ADMIN);
61             $this->disabled("! user->isAdmin");
62         }
63
64         $html = HTML(HTML::h3(fmt("General Auth Settings")));
65         $table = HTML::table(array('border' => 1,
66             'cellpadding' => 2,
67             'cellspacing' => 0));
68         $table->pushContent($this->show_hash("AUTH DEFINES",
69             $this->buildConstHash(
70                 array("ENABLE_USER_NEW", "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::h3(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('border' => 1,
104                 'cellpadding' => 2,
105                 'cellspacing' => 0));
106             //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
107             $userdata = obj2hash($user, array('_dbi', '_request', 'password', 'passwd'));
108             if (isa($user, "_FilePassUser")) {
109                 foreach ($userdata['_file']->users as $u => $p) {
110                     $userdata['_file']->users[$u] = "<hidden>";
111                 }
112             }
113             $table->pushContent($this->show_hash("User: Object of " . get_class($user), $userdata));
114             if (ENABLE_USER_NEW) {
115                 $group = &$request->getGroup();
116                 $groups = $group->getAllGroupsIn();
117                 $groupdata = obj2hash($group, array('_dbi', '_request', 'password', 'passwd'));
118                 unset($groupdata['request']);
119                 $table->pushContent($this->show_hash("Group: Object of " . get_class($group), $groupdata));
120                 $groups = $group->getAllGroupsIn();
121                 $groupdata = array('getAllGroupsIn' => $groups);
122                 foreach ($groups as $g) {
123                     $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
124                     $groupdata["isMember($g)"] = $group->isMember($g);
125                 }
126                 $table->pushContent($this->show_hash("Group Methods: ", $groupdata));
127             }
128             $html->pushContent($table);
129         }
130         return $html;
131     }
132
133     private function show_hash($heading, $hash, $depth = 0)
134     {
135         static $seen = array();
136         static $max_depth = 0;
137         $rows = array();
138         $max_depth++;
139         if ($max_depth > 35) return $heading;
140
141         if ($heading)
142             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
143                     'style' => 'color:#000000'),
144                 HTML::td(array('colspan' => 2,
145                         'style' => 'color:#000000'),
146                     $heading));
147         if (is_object($hash))
148             $hash = obj2hash($hash);
149         if (!empty($hash)) {
150             ksort($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; elseif (substr($heading, 0, 13) == "Object of db_") $val = $heading; elseif (!isset($seen[$heading])) {
156                         //if (empty($seen[$heading])) $seen[$heading] = 1;
157                         $val = HTML::table(array('border' => 1,
158                                 'cellpadding' => 2,
159                                 'cellspacing' => 0),
160                             $this->show_hash($heading, obj2hash($val), $depth + 1));
161                     } else {
162                         $val = $heading;
163                     }
164                 } elseif (is_array($val)) {
165                     $heading = $key . "[]";
166                     if ($depth > 3) $val = $heading;
167                     elseif (!isset($seen[$heading])) {
168                         //if (empty($seen[$heading])) $seen[$heading] = 1;
169                         $val = HTML::table(array('border' => 1,
170                                 'cellpadding' => 2,
171                                 'cellspacing' => 0),
172                             $this->show_hash($heading, $val, $depth + 1));
173                     } else {
174                         $val = $heading;
175                     }
176                 }
177                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
178                             'bgcolor' => '#cccccc',
179                             'style' => 'color:#000000'),
180                         HTML(HTML::raw('&nbsp;'), $key,
181                             HTML::raw('&nbsp;'))),
182                     HTML::td(array('bgcolor' => '#ffffff',
183                             'style' => 'color:#000000'),
184                         $val ? $val : HTML::raw('&nbsp;'))
185                 );
186                 //if (empty($seen[$key])) $seen[$key] = 1;
187             }
188         }
189         return $rows;
190     }
191
192     private function buildConstHash($constants)
193     {
194         $hash = array();
195         foreach ($constants as $c) {
196             $hash[$c] = defined($c) ? constant($c) : '<empty>';
197             if ($hash[$c] === false) $hash[$c] = 'false';
198             elseif ($hash[$c] === true) $hash[$c] = 'true';
199         }
200         return $hash;
201     }
202 }
203
204 // Local Variables:
205 // mode: php
206 // tab-width: 8
207 // c-basic-offset: 4
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil
210 // End: