]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
fixed explodePageList: wrong sortby argument order in UnfoldSubpages
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _AuthInfo.php,v 1.12 2004-03-12 15:48:08 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  * 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 getVersion() {
43         return preg_replace("/[Revision: $]/", '',
44                             "\$Revision: 1.12 $");
45     }
46
47     function getDefaultArguments() {
48         return array('userid' => '');
49     }
50
51     function run($dbi, $argstr, &$request, $basepage) {
52         $args = $this->getArgs($argstr, $request);
53         extract($args);
54         if (empty($userid) or $userid == $request->_user->UserName()) {
55             $user = & $request->_user;
56             $userid = $user->UserName();
57         } else {
58             $user = WikiUser($userid);
59         }
60         if (!$user->isAdmin() and !DEBUG) {
61             $request->_notAuthorized(WIKIAUTH_ADMIN);
62             $this->disabled("! user->isAdmin");
63         }
64
65         $html = HTML(HTML::h3(fmt("General Auth Settings")));
66         $table = HTML::table(array('border' => 1,
67                                   'cellpadding' => 2,
68                                   'cellspacing' => 0));
69         $table->pushContent($this->_showhash("AUTH DEFINES", 
70                                 $this->_buildConstHash(
71                                     array("ENABLE_USER_NEW","ALLOW_ANON_USER",
72                                           "ALLOW_ANON_EDIT","ALLOW_BOGO_LOGIN",
73                                           "REQUIRE_SIGNIN_BEFORE_EDIT","ALLOW_USER_PASSWORDS",
74                                           "PASSWORD_LENGTH_MINIMUM","USE_DB_SESSION"))));
75         if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP",$GLOBALS['USER_AUTH_ORDER']))
76             $table->pushContent($this->_showhash("LDAP DEFINES", 
77                                                  $this->_buildConstHash(array("LDAP_AUTH_HOST","LDAP_BASE_DN"))));
78         if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP",$GLOBALS['USER_AUTH_ORDER']))
79             $table->pushContent($this->_showhash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
80         if (defined('AUTH_USER_FILE') or in_array("File",$GLOBALS['USER_AUTH_ORDER']))
81             $table->pushContent($this->_showhash("AUTH_USER_FILE", 
82                                     $this->_buildConstHash(array("AUTH_USER_FILE",
83                                                                  "AUTH_USER_FILE_STORABLE"))));
84         if (defined('GROUP_METHOD'))
85             $table->pushContent($this->_showhash("GROUP_METHOD", 
86                                     $this->_buildConstHash(array("GROUP_METHOD","AUTH_GROUP_FILE","GROUP_LDAP_QUERY"))));
87         $table->pushContent($this->_showhash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
88         $table->pushContent($this->_showhash("USER_AUTH_POLICY", array("USER_AUTH_POLICY"=>USER_AUTH_POLICY)));
89         $DBParams = $GLOBALS['DBParams'];
90         $DBParams['dsn'] = class_exists('WikiDB_SQL') ? WikiDB_SQL::view_dsn($DBParams['dsn']) : '';
91         $table->pushContent($this->_showhash("\$DBParams[]", $DBParams));
92         $DBAuthParams = $GLOBALS['DBAuthParams'];
93         if (isset($DBAuthParams['auth_dsn']) and class_exists('WikiDB_SQL'))
94             $DBAuthParams['auth_dsn'] = WikiDB_SQL::view_dsn($DBAuthParams['auth_dsn']);
95         else
96             $DBAuthParams['auth_dsn'] = '';
97         unset($DBAuthParams['dummy']);
98         $table->pushContent($this->_showhash("\$DBAuthParams[]", $DBAuthParams));
99         $html->pushContent($table);
100         $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for '%s'",$userid))));
101         if (!$user) {
102             $html->pushContent(HTML::p(fmt("No userid")));
103         } else {
104             $table = HTML::table(array('border' => 1,
105                                        'cellpadding' => 2,
106                                        'cellspacing' => 0));
107             //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
108             $userdata = obj2hash($user);
109             $table->pushContent($this->_showhash("User: Object of ".get_class($user), $userdata));
110             $group = &WikiGroup::getGroup($request);
111             $groups = $group->getAllGroupsIn();
112             $groupdata = obj2hash($group);
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             $html->pushContent($table);
123         }
124         return $html;
125     }
126
127     function _showhash ($heading, $hash) {
128         static $seen = array();
129         $rows = array();
130         if ($heading)
131             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
132                                      'style' => 'color:#000000'),
133                                HTML::td(array('colspan' => 2,
134                                               'style' => 'color:#000000'),
135                                         $heading));
136         if (is_object($hash))
137             $hash = obj2hash($hash);
138         if (!empty($hash)) {
139             ksort($hash);
140             foreach ($hash as $key => $val) {
141                 if (is_object($val)) {
142                     $heading = "Object of ".get_class($val);
143                     if ($heading == "Object of wikidb_sql") $val = $heading;
144                     elseif (substr($heading,0,13) == "Object of db_") $val = $heading;
145                     elseif (!isset($seen[$heading])) {
146                         if (empty($seen[$heading])) $seen[$heading] = 1;
147                         $val = HTML::table(array('border' => 1,
148                                                  'cellpadding' => 2,
149                                                  'cellspacing' => 0),
150                                            $this->_showhash($heading, obj2hash($val)));
151                     } else {
152                         $val = $heading;
153                     }
154                 } elseif (is_array($val)) {
155                     $heading = $key."[]";
156                     if (!isset($seen[$heading])) {
157                         if (empty($seen[$heading])) $seen[$heading] = 1;
158                         $val = HTML::table(array('border' => 1,
159                                                  'cellpadding' => 2,
160                                                  'cellspacing' => 0),
161                                            $this->_showhash($heading, $val));
162                     } else {
163                         $val = $heading;
164                     }
165                 }
166                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
167                                                   'bgcolor' => '#cccccc',
168                                                   'style' => 'color:#000000'),
169                                             HTML(HTML::raw('&nbsp;'), $key,
170                                                  HTML::raw('&nbsp;'))),
171                                    HTML::td(array('bgcolor' => '#ffffff',
172                                                   'style' => 'color:#000000'),
173                                             $val ? $val : HTML::raw('&nbsp;'))
174                                    );
175                 if (empty($seen[$key])) $seen[$key] = 1;
176             }
177         }
178         return $rows;
179     }
180     
181     function _buildConstHash($constants) {
182         $hash = array();
183         foreach ($constants as $c) {
184             $hash[$c] = defined($c) ? constant($c) : '<empty>';
185             if ($hash[$c] === false) $hash[$c] = 'false';
186             elseif ($hash[$c] === true) $hash[$c] = 'true';
187         }
188         return $hash;
189     }
190 };
191
192 // $Log: not supported by cvs2svn $
193 // Revision 1.11  2004/03/12 11:18:25  rurban
194 // fixed ->membership chache
195 //
196 // Revision 1.10  2004/03/10 13:54:53  rurban
197 // adodb WikiGroup fix
198 //
199 // Revision 1.9  2004/03/08 18:17:10  rurban
200 // added more WikiGroup::getMembersOf methods, esp. for special groups
201 // fixed $LDAP_SET_OPTIONS
202 // fixed _AuthInfo group methods
203 //
204 // Revision 1.8  2004/03/08 16:35:23  rurban
205 // fixed "Undefined index: auth_dsn" warning
206 //
207 // Revision 1.7  2004/02/17 12:11:36  rurban
208 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
209 //
210 // Revision 1.6  2004/02/15 15:21:24  rurban
211 // don't display the SQL dsn connection password
212 //
213 // Revision 1.5  2004/02/09 03:58:20  rurban
214 // for now default DB_SESSION to false
215 // PagePerm:
216 //   * not existing perms will now query the parent, and not
217 //     return the default perm
218 //   * added pagePermissions func which returns the object per page
219 //   * added getAccessDescription
220 // WikiUserNew:
221 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
222 //   * force init of authdbh in the 2 db classes
223 // main:
224 //   * fixed session handling (not triple auth request anymore)
225 //   * don't store cookie prefs with sessions
226 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
227 //
228 // Revision 1.4  2004/02/07 10:41:25  rurban
229 // fixed auth from session (still double code but works)
230 // fixed GroupDB
231 // fixed DbPassUser upgrade and policy=old
232 // added GroupLdap
233 //
234 // Revision 1.3  2004/02/02 05:36:29  rurban
235 // Simplification and more options, but no passwd or admin protection yet.
236 //
237 // Revision 1.2  2004/02/01 09:14:11  rurban
238 // Started with Group_Ldap (not yet ready)
239 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
240 // fixed some configurator vars
241 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
242 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
243 // USE_DB_SESSION defaults to true on SQL
244 // changed GROUP_METHOD definition to string, not constants
245 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
246 //   create users. (Not to be used with external databases generally, but
247 //   with the default internal user table)
248 //
249 // fixed the IndexAsConfigProblem logic. this was flawed:
250 //   scripts which are the same virtual path defined their own lib/main call
251 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
252 //
253 // Revision 1.1  2004/02/01 01:04:34  rurban
254 // Used to debug auth problems and settings.
255 // This may display passwords in cleartext.
256 // DB Objects are not displayed anymore.
257 //
258 // Revision 1.21  2003/02/21 04:22:28  dairiki
259 // Make this work for array-valued data.  Make display of cached markup
260 // readable.  Some code cleanups.  (This still needs more work.)
261 //
262 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
263 // Code cleanup:
264 // Reformatting; added copyleft, getVersion, getDescription
265 //
266
267 // (c-file-style: "gnu")
268 // Local Variables:
269 // mode: php
270 // tab-width: 8
271 // c-basic-offset: 4
272 // c-hanging-comment-ender-p: nil
273 // indent-tabs-mode: nil
274 // End:
275 ?>