]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
don't display the SQL dsn connection password
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _AuthInfo.php,v 1.6 2004-02-15 15:21:24 rurban Exp $');
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  *
27  * Warning! This may display db and user passwords in cleartext.
28  * Fixme: How to avoid caching?
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 getVersion() {
42         return preg_replace("/[Revision: $]/", '',
43                             "\$Revision: 1.6 $");
44     }
45
46     function getDefaultArguments() {
47         return array('userid' => '');
48     }
49
50     function run($dbi, $argstr, $request) {
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
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         $DBAuthParams['auth_dsn'] = class_exists('WikiDB_SQL') ? WikiDB_SQL::view_dsn($DBAuthParams['auth_dsn']) : '';
89         unset($DBAuthParams['dummy']);
90         $table->pushContent($this->_showhash("\$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         }
96         else {
97             $table = HTML::table(array('border' => 1,
98                                        'cellpadding' => 2,
99                                        'cellspacing' => 0));
100             //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
101             $userdata = obj2hash($user);
102             $table->pushContent($this->_showhash("User: Object of ".get_class($user), $userdata));
103             $group = &WikiGroup::getGroup($request);
104             $table->pushContent($this->_showhash("Group: Object of ".get_class($group), $group));
105             $groups = $group->getAllGroupsIn();
106             $groupdata = array('getAllGroupsIn' => $groups);
107             foreach ($groups as $g) {
108                 $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
109                 $groupdata["isMember($g)"] = $group->isMember($g);
110             }
111             $table->pushContent($this->_showhash("Group Methods: ", $groupdata));
112             $html->pushContent($table);
113         }
114         return $html;
115     }
116
117     function _showhash ($heading, $hash) {
118         static $seen = array();
119         $rows = array();
120         if ($heading)
121             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
122                                      'style' => 'color:#000000'),
123                                HTML::td(array('colspan' => 2,
124                                               'style' => 'color:#000000'),
125                                         $heading));
126         if (is_object($hash))
127             $hash = obj2hash($hash);
128         if (!empty($hash)) {
129             ksort($hash);
130             foreach ($hash as $key => $val) {
131                 if (is_object($val)) {
132                     $heading = "Object of ".get_class($val);
133                     if ($heading == "Object of wikidb_sql") $val = $heading;
134                     elseif (substr($heading,0,13) == "Object of db_") $val = $heading;
135                     elseif (!isset($seen[$heading])) {
136                         if (empty($seen[$heading])) $seen[$heading] = 1;
137                         $val = HTML::table(array('border' => 1,
138                                                  'cellpadding' => 2,
139                                                  'cellspacing' => 0),
140                                            $this->_showhash($heading, obj2hash($val)));
141                     } else {
142                         $val = $heading;
143                     }
144                 } elseif (is_array($val)) {
145                     $heading = $key."[]";
146                     if (!isset($seen[$heading])) {
147                         if (empty($seen[$heading])) $seen[$heading] = 1;
148                         $val = HTML::table(array('border' => 1,
149                                                  'cellpadding' => 2,
150                                                  'cellspacing' => 0),
151                                            $this->_showhash($heading, $val));
152                     } else {
153                         $val = $heading;
154                     }
155                 }
156                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
157                                                   'bgcolor' => '#cccccc',
158                                                   'style' => 'color:#000000'),
159                                             HTML(HTML::raw('&nbsp;'), $key,
160                                                  HTML::raw('&nbsp;'))),
161                                    HTML::td(array('bgcolor' => '#ffffff',
162                                                   'style' => 'color:#000000'),
163                                             $val ? $val : HTML::raw('&nbsp;'))
164                                    );
165                 if (empty($seen[$key])) $seen[$key] = 1;
166             }
167         }
168         return $rows;
169     }
170     
171     function _buildConstHash($constants) {
172         $hash = array();
173         foreach ($constants as $c) {
174             $hash[$c] = defined($c) ? constant($c) : '<empty>';
175             if ($hash[$c] === false) $hash[$c] = 'false';
176             elseif ($hash[$c] === true) $hash[$c] = 'true';
177         }
178         return $hash;
179     }
180 };
181
182 // $Log: not supported by cvs2svn $
183 // Revision 1.5  2004/02/09 03:58:20  rurban
184 // for now default DB_SESSION to false
185 // PagePerm:
186 //   * not existing perms will now query the parent, and not
187 //     return the default perm
188 //   * added pagePermissions func which returns the object per page
189 //   * added getAccessDescription
190 // WikiUserNew:
191 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
192 //   * force init of authdbh in the 2 db classes
193 // main:
194 //   * fixed session handling (not triple auth request anymore)
195 //   * don't store cookie prefs with sessions
196 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
197 //
198 // Revision 1.4  2004/02/07 10:41:25  rurban
199 // fixed auth from session (still double code but works)
200 // fixed GroupDB
201 // fixed DbPassUser upgrade and policy=old
202 // added GroupLdap
203 //
204 // Revision 1.3  2004/02/02 05:36:29  rurban
205 // Simplification and more options, but no passwd or admin protection yet.
206 //
207 // Revision 1.2  2004/02/01 09:14:11  rurban
208 // Started with Group_Ldap (not yet ready)
209 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
210 // fixed some configurator vars
211 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
212 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
213 // USE_DB_SESSION defaults to true on SQL
214 // changed GROUP_METHOD definition to string, not constants
215 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
216 //   create users. (Not to be used with external databases generally, but
217 //   with the default internal user table)
218 //
219 // fixed the IndexAsConfigProblem logic. this was flawed:
220 //   scripts which are the same virtual path defined their own lib/main call
221 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
222 //
223 // Revision 1.1  2004/02/01 01:04:34  rurban
224 // Used to debug auth problems and settings.
225 // This may display passwords in cleartext.
226 // DB Objects are not displayed anymore.
227 //
228 // Revision 1.21  2003/02/21 04:22:28  dairiki
229 // Make this work for array-valued data.  Make display of cached markup
230 // readable.  Some code cleanups.  (This still needs more work.)
231 //
232 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
233 // Code cleanup:
234 // Reformatting; added copyleft, getVersion, getDescription
235 //
236
237 // (c-file-style: "gnu")
238 // Local Variables:
239 // mode: php
240 // tab-width: 8
241 // c-basic-offset: 4
242 // c-hanging-comment-ender-p: nil
243 // indent-tabs-mode: nil
244 // End:
245 ?>