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