]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
Started with Group_Ldap (not yet ready)
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _AuthInfo.php,v 1.2 2004-02-01 09:14:11 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.2 $");
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         $auth_defines = array();
63         foreach (array("ENABLE_USER_NEW","ALLOW_ANON_USER","ALLOW_ANON_EDIT","ALLOW_BOGO_LOGIN",
64                        "REQUIRE_SIGNIN_BEFORE_EDIT","ALLOW_USER_PASSWORDS",
65                        "PASSWORD_LENGTH_MINIMUM","USE_DB_SESSION") as $constant) {
66             $auth_defines[$constant] = constant($constant);
67         }
68         $table->pushContent($this->_showhash("AUTH DEFINES", $auth_defines));
69         if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP",$GLOBALS['USER_AUTH_ORDER']))
70             $table->pushContent($this->_showhash("LDAP DEFINES", array("LDAP_AUTH_HOST" => LDAP_AUTH_HOST,
71                                                                        "LDAP_AUTH_SEARCH" => LDAP_AUTH_SEARCH)));
72         if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP",$GLOBALS['USER_AUTH_ORDER']))
73             $table->pushContent($this->_showhash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
74         if (defined('AUTH_USER_FILE') or in_array("File",$GLOBALS['USER_AUTH_ORDER']))
75             $table->pushContent($this->_showhash("AUTH_USER_FILE", array("AUTH_USER_FILE" => AUTH_USER_FILE,
76                                                                          "AUTH_USER_FILE_STORABLE" => AUTH_USER_FILE_STORABLE,
77                                                                          "AUTH_GROUP_FILE" => AUTH_GROUP_FILE
78                                                                          )));
79         if (defined('GROUP_METHOD'))
80             $table->pushContent($this->_showhash("GROUP_METHOD", array("GROUP_METHOD" => GROUP_METHOD)));
81         $table->pushContent($this->_showhash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
82         $table->pushContent($this->_showhash("USER_AUTH_POLICY", array("USER_AUTH_POLICY"=>USER_AUTH_POLICY)));
83         $table->pushContent($this->_showhash("\$DBParams[]", $GLOBALS['DBParams']));
84         unset($GLOBALS['DBAuthParams']['dummy']);
85         $table->pushContent($this->_showhash("\$DBAuthParams[]", $GLOBALS['DBAuthParams']));
86         $html->pushContent($table);
87         $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for '%s'",$userid))));
88         if (!$user) {
89             $html->pushContent(HTML::p(fmt("No userid")));
90         }
91         else {
92             $table = HTML::table(array('border' => 1,
93                                        'cellpadding' => 2,
94                                        'cellspacing' => 0));
95             $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
96             $userdata = $this->_obj2hash($user);
97             $table->pushContent($this->_showhash("Object of ".get_class($user), $userdata));
98             $html->pushContent($table);
99         }
100         return $html;
101     }
102
103     function _obj2hash ($obj, $exclude = false, $fields = false) {
104         $a = array();
105         if (! $fields ) $fields = get_object_vars($obj);
106         foreach ($fields as $key => $val) {
107             if (is_array($exclude)) {
108                 if (in_array($key,$exclude)) continue;
109             }
110             $a[$key] = $val;
111         }
112         return $a;
113     }
114
115     function _showhash ($heading, $hash) {
116         static $seen = array();
117         $rows = array();
118         if ($heading)
119             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
120                                      'style' => 'color:#000000'),
121                                HTML::td(array('colspan' => 2,
122                                               'style' => 'color:#000000'),
123                                         $heading));
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, $this->_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
168 // $Log: not supported by cvs2svn $
169 // Revision 1.1  2004/02/01 01:04:34  rurban
170 // Used to debug auth problems and settings.
171 // This may display passwords in cleartext.
172 // DB Objects are not displayed anymore.
173 //
174 // Revision 1.21  2003/02/21 04:22:28  dairiki
175 // Make this work for array-valued data.  Make display of cached markup
176 // readable.  Some code cleanups.  (This still needs more work.)
177 //
178 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
179 // Code cleanup:
180 // Reformatting; added copyleft, getVersion, getDescription
181 //
182
183 // (c-file-style: "gnu")
184 // Local Variables:
185 // mode: php
186 // tab-width: 8
187 // c-basic-offset: 4
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil
190 // End:
191 ?>