]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
php_closing_tag [PSR-2] The closing ?> tag MUST be omitted from files containing...
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 /**
3  * Copyright 2004 $ThePhpWikiProgrammingTeam
4  *
5  * This file is part of PhpWiki.
6  *
7  * PhpWiki is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * PhpWiki is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 require_once('lib/Template.php');
23 /**
24  * Used to debug auth problems and settings.
25  * This plugin is only testing purposes.
26  * if DEBUG is false, only admin can call it, which is of no real use.
27  *
28  * Warning! This may display db and user passwords in cleartext.
29  */
30 class WikiPlugin__AuthInfo
31 extends WikiPlugin
32 {
33     function getName () {
34         return _("AuthInfo");
35     }
36
37     function getDescription () {
38         return _("Display general and user specific auth information.");
39     }
40
41     function getDefaultArguments() {
42         return array('userid' => '');
43     }
44
45     function run($dbi, $argstr, &$request, $basepage) {
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('border' => 1,
61                                   'cellpadding' => 2,
62                                   'cellspacing' => 0));
63         $table->pushContent($this->_showhash("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->_showhash("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->_showhash("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->_showhash("AUTH_USER_FILE",
76                                     $this->_buildConstHash(array("AUTH_USER_FILE",
77                                                                  "AUTH_USER_FILE_STORABLE"))));
78         if (defined('GROUP_METHOD'))
79             $table->pushContent($this->_showhash("GROUP_METHOD",
80                                     $this->_buildConstHash(array("GROUP_METHOD","AUTH_GROUP_FILE","GROUP_LDAP_QUERY"))));
81         $table->pushContent($this->_showhash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
82         $table->pushContent($this->_showhash("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->_showhash("\$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']);
89         else
90             $DBAuthParams['auth_dsn'] = '';
91         unset($DBAuthParams['dummy']);
92         $table->pushContent($this->_showhash("\$DBAuthParams[]", $DBAuthParams));
93         $html->pushContent($table);
94         $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for '%s'", $userid))));
95         if (!$user) {
96             $html->pushContent(HTML::p(fmt("No userid")));
97         } else {
98             $table = HTML::table(array('border' => 1,
99                                        'cellpadding' => 2,
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>";
106                     }
107             }
108             $table->pushContent($this->_showhash("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->_showhash("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);
120               }
121               $table->pushContent($this->_showhash("Group Methods: ", $groupdata));
122             }
123             $html->pushContent($table);
124         }
125         return $html;
126     }
127
128     function _showhash ($heading, $hash, $depth = 0) {
129             static $seen = array();
130             static $maxdepth = 0;
131         $rows = array();
132         $maxdepth++;
133         if ($maxdepth > 35) return $heading;
134
135         if ($heading)
136             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
137                                      'style' => 'color:#000000'),
138                                HTML::td(array('colspan' => 2,
139                                               'style' => 'color:#000000'),
140                                         $heading));
141         if (is_object($hash))
142             $hash = obj2hash($hash);
143         if (!empty($hash)) {
144             ksort($hash);
145             foreach ($hash as $key => $val) {
146                 if (is_object($val)) {
147                     $heading = "Object of ".get_class($val);
148                     if ($depth > 3) $val = $heading;
149                     elseif ($heading == "Object of wikidb_sql") $val = $heading;
150                     elseif (substr($heading,0,13) == "Object of db_") $val = $heading;
151                     elseif (!isset($seen[$heading])) {
152                         //if (empty($seen[$heading])) $seen[$heading] = 1;
153                         $val = HTML::table(array('border' => 1,
154                                                  'cellpadding' => 2,
155                                                  'cellspacing' => 0),
156                                            $this->_showhash($heading, obj2hash($val), $depth+1));
157                     } else {
158                         $val = $heading;
159                     }
160                 } elseif (is_array($val)) {
161                     $heading = $key."[]";
162                     if ($depth > 3) $val = $heading;
163                     elseif (!isset($seen[$heading])) {
164                         //if (empty($seen[$heading])) $seen[$heading] = 1;
165                         $val = HTML::table(array('border' => 1,
166                                                  'cellpadding' => 2,
167                                                  'cellspacing' => 0),
168                                            $this->_showhash($heading, $val, $depth+1));
169                     } else {
170                         $val = $heading;
171                     }
172                 }
173                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
174                                                   'bgcolor' => '#cccccc',
175                                                   'style' => 'color:#000000'),
176                                             HTML(HTML::raw('&nbsp;'), $key,
177                                                  HTML::raw('&nbsp;'))),
178                                    HTML::td(array('bgcolor' => '#ffffff',
179                                                   'style' => 'color:#000000'),
180                                             $val ? $val : HTML::raw('&nbsp;'))
181                                    );
182                 //if (empty($seen[$key])) $seen[$key] = 1;
183             }
184         }
185         return $rows;
186     }
187
188     function _buildConstHash($constants) {
189         $hash = array();
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';
194         }
195         return $hash;
196     }
197 };
198
199 // Local Variables:
200 // mode: php
201 // tab-width: 8
202 // c-basic-offset: 4
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil
205 // End: