]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
fixed auth from session (still double code but works)
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _AuthInfo.php,v 1.4 2004-02-07 10:41:25 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.4 $");
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("User: Object of ".get_class($user), $userdata));
97             $group = &WikiGroup::getGroup($request);
98             $table->pushContent($this->_showhash("Group: Object of ".get_class($group), $group));
99             $groups = $group->getAllGroupsIn();
100             $groupdata = array('getAllGroupsIn' => $groups);
101             foreach ($groups as $g) {
102                 $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
103                 $groupdata["isMember($g)"] = $group->isMember($g);
104             }
105             $table->pushContent($this->_showhash("Group Methods: ", $groupdata));
106             $html->pushContent($table);
107         }
108         return $html;
109     }
110
111     function _obj2hash ($obj, $exclude = false, $fields = false) {
112         $a = array();
113         if (! $fields ) $fields = get_object_vars($obj);
114         foreach ($fields as $key => $val) {
115             if (is_array($exclude)) {
116                 if (in_array($key,$exclude)) continue;
117             }
118             $a[$key] = $val;
119         }
120         return $a;
121     }
122
123     function _showhash ($heading, $hash) {
124         static $seen = array();
125         $rows = array();
126         if ($heading)
127             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
128                                      'style' => 'color:#000000'),
129                                HTML::td(array('colspan' => 2,
130                                               'style' => 'color:#000000'),
131                                         $heading));
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, $this->_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.3  2004/02/02 05:36:29  rurban
188 // Simplification and more options, but no passwd or admin protection yet.
189 //
190 // Revision 1.2  2004/02/01 09:14:11  rurban
191 // Started with Group_Ldap (not yet ready)
192 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
193 // fixed some configurator vars
194 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
195 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
196 // USE_DB_SESSION defaults to true on SQL
197 // changed GROUP_METHOD definition to string, not constants
198 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
199 //   create users. (Not to be used with external databases generally, but
200 //   with the default internal user table)
201 //
202 // fixed the IndexAsConfigProblem logic. this was flawed:
203 //   scripts which are the same virtual path defined their own lib/main call
204 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
205 //
206 // Revision 1.1  2004/02/01 01:04:34  rurban
207 // Used to debug auth problems and settings.
208 // This may display passwords in cleartext.
209 // DB Objects are not displayed anymore.
210 //
211 // Revision 1.21  2003/02/21 04:22:28  dairiki
212 // Make this work for array-valued data.  Make display of cached markup
213 // readable.  Some code cleanups.  (This still needs more work.)
214 //
215 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
216 // Code cleanup:
217 // Reformatting; added copyleft, getVersion, getDescription
218 //
219
220 // (c-file-style: "gnu")
221 // Local Variables:
222 // mode: php
223 // tab-width: 8
224 // c-basic-offset: 4
225 // c-hanging-comment-ender-p: nil
226 // indent-tabs-mode: nil
227 // End:
228 ?>