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