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