]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
Simplification and more options, but no passwd or admin protection yet.
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _AuthInfo.php,v 1.3 2004-02-02 05:36:29 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  * This may display passwords in cleartext.
26  * Used to debug auth problems and settings.
27  */
28 class WikiPlugin__AuthInfo
29 extends WikiPlugin
30 {
31     function getName () {
32         return _("AuthInfo");
33     }
34
35     function getDescription () {
36         return _("Display general and user specific auth information.");
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision: 1.3 $");
42     }
43
44     function getDefaultArguments() {
45         return array('userid' => '');
46     }
47
48     function run($dbi, $argstr, $request) {
49         $args = $this->getArgs($argstr, $request);
50         extract($args);
51         if (empty($userid) or $userid == $request->_user->UserName()) {
52             $user = & $request->_user;
53             $userid = $user->UserName();
54         } else {
55             $user = WikiUser($userid);
56         }
57
58         $html = HTML(HTML::h3(fmt("General Auth Settings")));
59         $table = HTML::table(array('border' => 1,
60                                   'cellpadding' => 2,
61                                   'cellspacing' => 0));
62         $table->pushContent($this->_showhash("AUTH DEFINES", 
63                                 $this->_buildConstHash(
64                                     array("ENABLE_USER_NEW","ALLOW_ANON_USER",
65                                           "ALLOW_ANON_EDIT","ALLOW_BOGO_LOGIN",
66                                           "REQUIRE_SIGNIN_BEFORE_EDIT","ALLOW_USER_PASSWORDS",
67                                           "PASSWORD_LENGTH_MINIMUM","USE_DB_SESSION"))));
68         if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP",$GLOBALS['USER_AUTH_ORDER']))
69             $table->pushContent($this->_showhash("LDAP DEFINES", 
70                                                  $this->_buildConstHash(array("LDAP_AUTH_HOST","LDAP_AUTH_SEARCH"))));
71         if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP",$GLOBALS['USER_AUTH_ORDER']))
72             $table->pushContent($this->_showhash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
73         if (defined('AUTH_USER_FILE') or in_array("File",$GLOBALS['USER_AUTH_ORDER']))
74             $table->pushContent($this->_showhash("AUTH_USER_FILE", 
75                                     $this->_buildConstHash(array("AUTH_USER_FILE",
76                                                                  "AUTH_USER_FILE_STORABLE"))));
77         if (defined('GROUP_METHOD'))
78             $table->pushContent($this->_showhash("GROUP_METHOD", 
79                                     $this->_buildConstHash(array("GROUP_METHOD","AUTH_GROUP_FILE","GROUP_LDAP_QUERY"))));
80         $table->pushContent($this->_showhash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
81         $table->pushContent($this->_showhash("USER_AUTH_POLICY", array("USER_AUTH_POLICY"=>USER_AUTH_POLICY)));
82         $table->pushContent($this->_showhash("\$DBParams[]", $GLOBALS['DBParams']));
83         unset($GLOBALS['DBAuthParams']['dummy']);
84         $table->pushContent($this->_showhash("\$DBAuthParams[]", $GLOBALS['DBAuthParams']));
85         $html->pushContent($table);
86         $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for '%s'",$userid))));
87         if (!$user) {
88             $html->pushContent(HTML::p(fmt("No userid")));
89         }
90         else {
91             $table = HTML::table(array('border' => 1,
92                                        'cellpadding' => 2,
93                                        'cellspacing' => 0));
94             $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
95             $userdata = $this->_obj2hash($user);
96             $table->pushContent($this->_showhash("Object of ".get_class($user), $userdata));
97             $html->pushContent($table);
98         }
99         return $html;
100     }
101
102     function _obj2hash ($obj, $exclude = false, $fields = false) {
103         $a = array();
104         if (! $fields ) $fields = get_object_vars($obj);
105         foreach ($fields as $key => $val) {
106             if (is_array($exclude)) {
107                 if (in_array($key,$exclude)) continue;
108             }
109             $a[$key] = $val;
110         }
111         return $a;
112     }
113
114     function _showhash ($heading, $hash) {
115         static $seen = array();
116         $rows = array();
117         if ($heading)
118             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
119                                      'style' => 'color:#000000'),
120                                HTML::td(array('colspan' => 2,
121                                               'style' => 'color:#000000'),
122                                         $heading));
123         if (!empty($hash)) {
124             ksort($hash);
125             foreach ($hash as $key => $val) {
126                 if (is_object($val)) {
127                     $heading = "Object of ".get_class($val);
128                     if ($heading == "Object of wikidb_sql") $val = $heading;
129                     elseif (substr($heading,0,13) == "Object of db_") $val = $heading;
130                     elseif (!isset($seen[$heading])) {
131                         if (empty($seen[$heading])) $seen[$heading] = 1;
132                         $val = HTML::table(array('border' => 1,
133                                                  'cellpadding' => 2,
134                                                  'cellspacing' => 0),
135                                            $this->_showhash($heading, $this->_obj2hash($val)));
136                     } else {
137                         $val = $heading;
138                     }
139                 } elseif (is_array($val)) {
140                     $heading = $key."[]";
141                     if (!isset($seen[$heading])) {
142                         if (empty($seen[$heading])) $seen[$heading] = 1;
143                         $val = HTML::table(array('border' => 1,
144                                                  'cellpadding' => 2,
145                                                  'cellspacing' => 0),
146                                            $this->_showhash($heading, $val));
147                     } else {
148                         $val = $heading;
149                     }
150                 }
151                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
152                                                   'bgcolor' => '#cccccc',
153                                                   'style' => 'color:#000000'),
154                                             HTML(HTML::raw('&nbsp;'), $key,
155                                                  HTML::raw('&nbsp;'))),
156                                    HTML::td(array('bgcolor' => '#ffffff',
157                                                   'style' => 'color:#000000'),
158                                             $val ? $val : HTML::raw('&nbsp;'))
159                                    );
160                 if (empty($seen[$key])) $seen[$key] = 1;
161             }
162         }
163         return $rows;
164     }
165     
166     function _buildConstHash($constants) {
167         $hash = array();
168         foreach ($constants as $c) {
169             $hash[$c] = defined($c) ? constant($c) : '<empty>';
170             if ($hash[$c] === false) $hash[$c] = 'false';
171             elseif ($hash[$c] === true) $hash[$c] = 'true';
172         }
173         return $hash;
174     }
175 };
176
177 // $Log: not supported by cvs2svn $
178 // Revision 1.2  2004/02/01 09:14:11  rurban
179 // Started with Group_Ldap (not yet ready)
180 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
181 // fixed some configurator vars
182 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
183 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
184 // USE_DB_SESSION defaults to true on SQL
185 // changed GROUP_METHOD definition to string, not constants
186 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
187 //   create users. (Not to be used with external databases generally, but
188 //   with the default internal user table)
189 //
190 // fixed the IndexAsConfigProblem logic. this was flawed:
191 //   scripts which are the same virtual path defined their own lib/main call
192 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
193 //
194 // Revision 1.1  2004/02/01 01:04:34  rurban
195 // Used to debug auth problems and settings.
196 // This may display passwords in cleartext.
197 // DB Objects are not displayed anymore.
198 //
199 // Revision 1.21  2003/02/21 04:22:28  dairiki
200 // Make this work for array-valued data.  Make display of cached markup
201 // readable.  Some code cleanups.  (This still needs more work.)
202 //
203 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
204 // Code cleanup:
205 // Reformatting; added copyleft, getVersion, getDescription
206 //
207
208 // (c-file-style: "gnu")
209 // Local Variables:
210 // mode: php
211 // tab-width: 8
212 // c-basic-offset: 4
213 // c-hanging-comment-ender-p: nil
214 // indent-tabs-mode: nil
215 // End:
216 ?>