root/trunk/wifidog-auth/wifidog/classes/MainUI.php @ 927

Revision 927, 19.1 KB (checked in by max-horvath, 7 years ago)

"2006-01-29 Max Horvath <max.horvath@…>

  • WiFiDog now detects APC PHP cache and eAccelerator PHP cache and disables both PHP caches, because WiFiDog currently doesn't run with either of those PHP caches (I'm still investigating why)
  • added a missing <ul> HTML tag on the administration page"
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * @package    WiFiDogAuthServer
38 * @author     Benoit Gregoire <bock@step.polymtl.ca>
39 * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc.
40 * @version    Subversion $Id$
41 * @link       http://www.wifidog.org/
42 */
43
44/**
45 * @internal We put a call to validate_schema() here so it systematically called
46 * from any UI page, but not from any machine readable pages
47 */
48require_once('include/schema_validate.php');
49validate_schema();
50
51if (CONF_USE_CRON_FOR_DB_CLEANUP == false)
52{
53    garbage_collect();
54}
55
56require_once('include/common_interface.php');
57
58/**
59 * Style contains functions managing headers, footers, stylesheet, etc.
60 *
61 * @package    WiFiDogAuthServer
62 * @author     Benoit Gregoire <bock@step.polymtl.ca>
63 * @copyright  2005-2006 Benoit Gregoire, Technologies Coeus inc.
64 */
65class MainUI
66{
67    private $main_content; /**<Content to be displayed in the main pane */
68    private $tool_content; /**<Content to be displayed in the tool pane */
69    private $smarty;
70    private $title;
71    private $html_headers;
72    private $tool_section_enabled = true;
73    private $footer_scripts = array ();
74
75    function __construct()
76    {
77        $this->smarty = new SmartyWifidog();
78        $this->title = Network :: getCurrentNetwork()->getName().' '._("authentication server"); //Default title
79    }
80
81    /** Check if the tool section is enabled
82     *
83     */
84    public function isToolSectionEnabled()
85    {
86        return $this->tool_section_enabled;
87    }
88
89    public function setToolSectionEnabled($status)
90    {
91        $this->tool_section_enabled = $status;
92    }
93
94    /** Set the content to be displayed in the main pane */
95    public function setMainContent($html)
96    {
97        $this->main_content = $html;
98    }
99
100    /** Set the title of the page */
101    public function setTitle($title_string)
102    {
103        $this->title = $title_string;
104    }
105
106    /** Add content at the very end of the <body>.  This is NOT meant to add footers or other display content, it is meant to add <script></script> tag pairs that have to be executed only once the page is loaded.
107     * @param $script A piece of script surrounded by <script></script> tags. */
108    public function addFooterScript($script)
109    {
110        $this->footer_scripts[] = $script;
111    }
112
113    /** Set the HTML page headers */
114    public function setHtmlHeader($headers_string)
115    {
116        $this->html_headers = $headers_string;
117    }
118
119    /** Set the section to be displayed in the tool pane */
120    public function setToolSection($section)
121    {
122        switch ($section)
123        {
124            case "ADMIN" :
125                $current_user = User :: getCurrentUser();
126                $html = '';
127
128                if ($current_user && $current_user->isNobody())
129                {
130                    $html .= _("You do not have permissions to access any administration functions.");
131                }
132                else
133                {
134
135                    if ($current_user && $current_user->isSuperAdmin())
136                    {
137                        $html .= "<ul>\n";
138                        $html .= "<li><a href='user_log.php'>"._("User logs")."</a></li>\n";
139                        $html .= "<li><a href='online_users.php'>"._("Online Users")."</a></li>\n";
140                        $html .= "<li><a href='stats.php'>"._("Statistics")."</a></li>\n";
141                        $html .= "<li><a href='import_user_database.php'>"._("Import NoCat user database")."</a></li>\n";
142                        $html .= "<li><a href='content_admin.php'>"._("Content manager")."</a></li>\n";
143                        $html .= "</ul>\n";
144                    }
145
146                    // If the user is super admin OR owner of at least one hotspot show the menu
147                    if ($current_user && ($current_user->isSuperAdmin() || $current_user->isOwner()))
148                    {
149                        /* Node admin */
150                        $html .= "<div class='admin_section_container'>\n";
151                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
152                        $html .= "<div class='admin_section_title'>"._("Node administration:")." </div>\n";
153
154                        $html .= "<div class='admin_section_data'>\n";
155
156                        if ($current_user->isSuperAdmin())
157                            $sql_additional_where = '';
158                        else
159                            $sql_additional_where = "AND node_id IN (SELECT node_id from node_stakeholders WHERE is_owner = true AND user_id='".$current_user->getId()."')";
160                        $html .= "<div id='NodeSelector'>\n";
161                        $html .= Node :: getSelectNodeUI('object_id', $sql_additional_where);
162                        $html .= "</div>\n";
163                        $html .= "</div>\n";
164                        $html .= "<div class='admin_section_tools'>\n";
165                        $html .= "<input type='hidden' name='object_class' value='Node'>\n";
166                        $html .= "<input type='hidden' name='action' value='edit'>\n";
167                        $html .= "<input type='submit' name='edit_submit' value='"._("Edit")."'>\n";
168                        $html .= '</form>';
169
170                        if($current_user->isSuperAdmin())
171                        {
172                            $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
173                            $html .= "<input type='hidden' name='action' value='new_ui'>\n";
174                            $html .= "<input type='hidden' name='object_class' value='Node'>\n";
175                            $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n";
176                            $html .= "</form>\n";
177
178                        }
179                        $html .= "</div>\n";
180                        $html .= "</div>\n";
181                    }
182
183                    /* Network admin */
184                    if ($current_user && $current_user->isSuperAdmin())
185                    {
186                        $html .= "<div class='admin_section_container'>\n";
187                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
188                        $html .= "<div class='admin_section_title'>"._("Network administration:")." </div>\n";
189
190                        $html .= "<div class='admin_section_data'>\n";
191                        $html .= "<input type='hidden' name='action' value='edit'>\n";
192                        $html .= "<input type='hidden' name='object_class' value='Network'><br>\n";
193                        $html .= Network :: getSelectNetworkUI('object_id');
194                        $html .= "</div>\n";
195                        $html .= "<div class='admin_section_tools'>\n";
196                        $html .= "<input type=submit name='edit_submit' value='"._("Edit")."'>\n";
197                        $html .= "</form>\n";
198                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">';
199                        $html .= "<input type='hidden' name='action' value='new_ui'>\n";
200                        $html .= "<input type='hidden' name='object_class' value='Network'>\n";
201                        $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n";
202                        $html .= "</form>\n";
203                        $html .= "</div>\n";
204                        $html .= "</div>\n";
205                    }
206                }
207                break;
208            default :
209                $html .= "<p class='errormsg'>"._("Unknown section:")." $section</p>\n";
210
211        }
212        $this->tool_content = $html;
213    }
214
215    /** Set the content to be displayed in the tool pane */
216    public function setToolContent($html)
217    {
218        $this->tool_content = $html;
219    }
220
221    /**
222     * Get the content to be displayed in the tool pane
223     *
224     * @param string $section One of:  START, LOGIN,
225     * @return string HTML markup
226     */
227    private function getToolContent($section = 'START')
228    {
229        global $session;
230        $html = '';
231        switch ($section)
232        {
233            case "NONE" :
234                break;
235            case "LOGIN" :
236                break;
237            case "START" :
238                $html .= '<div id="tool_section">'."\n";
239                $html .= '<div class="tool_user_info">'."\n";
240                $html .= '<span class="tool_user_info">'."\n";
241                $user = User :: getCurrentUser();
242                if ($user != null)
243                {
244                    $html .= '<p>'._("Logged in as:").' '.$user->getUsername().'</p>'."\n";
245                    $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'user_profile.php"><img class="administration" src="'.BASE_SSL_PATH.'images/profile.gif" border="0"> '._("My Profile").'</a>'."\n";
246
247                    $gw_id = $session->get(SESS_GW_ID_VAR);
248                    $gw_address = $session->get(SESS_GW_ADDRESS_VAR);
249                    $gw_port = $session->get(SESS_GW_PORT_VAR);
250
251                    if ($gw_id && $gw_address && $gw_port)
252                        $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'login/?logout=true&gw_id='.$gw_id.'&gw_address='.$gw_address.'&gw_port='.$gw_port.'"><img class="administration" src="'.BASE_SSL_PATH.'images/logout.gif" border="0"> '._("Logout").'</a>'."\n";
253                    else
254                        $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'login/?logout=true"><img class="administration" src="'.BASE_SSL_PATH.'images/logout.gif" border="0"> '._("Logout").'</a>'."\n";
255
256                }
257                else
258                {
259                    $gw_id = !empty ($_REQUEST['gw_id']) ? $_REQUEST['gw_id'] : $session->get(SESS_GW_ID_VAR);
260                    $gw_address = !empty ($_REQUEST['gw_address']) ? $_REQUEST['gw_address'] : $session->get(SESS_GW_ADDRESS_VAR);
261                    $gw_port = !empty ($_REQUEST['gw_port']) ? $_REQUEST['gw_port'] : $session->get(SESS_GW_PORT_VAR);
262
263                    // If the user connects physically ( through a gateway don't show the confusing login message )
264                    if (empty ($gw_id) || empty ($gw_address) || empty ($gw_port))
265                        $href = BASE_SSL_PATH.'login/';
266                    else
267                        $href = BASE_SSL_PATH.'login/?gw_id='.$gw_id.'&gw_address='.$gw_address.'&gw_port='.$gw_port;
268$html .= '<p>'._("I am not logged in.").'<br><a href="'.$href.'">'._("Login").'</a></p>'."\n";
269
270                    $html .= '<a class="administration" HREF="'.Network :: getCurrentNetwork()->getHomepageURL().'"><img class="administration" src="'.BASE_URL_PATH.'images/lien_ext.gif"> '.Network :: getCurrentNetwork()->getName().'</a>'."\n";
271                    $html .= '<a class="administration" HREF="'.BASE_SSL_PATH.'faq.php"><img class="administration" src="'.BASE_URL_PATH.'images/where.gif"> '._("Where am I?").'</a>'."\n";
272                }
273
274                $html .= "</span>"."\n"; //End tool_user_info
275                $html .= "</div>"."\n"; //End tool_user_info
276
277                $html .= '<div class="navigation">'."\n";
278                /*
279                $html .= '<a href="index.php" class="navigation">'._("Start").'</a>'."\n";
280                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
281                $html .= '<a href="users.php" class="navigation">'._("Users Online").'</a>'."\n";
282                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
283                $html .= '<a href="news.php" class="navigation">'._("News").'</a>'."\n";
284                $html .= '<img class="separator" src="'.BASE_NON_SSL_PATH.'/images/separator.gif">'."\n";
285                $html .= '<a href="hotspots.php" class="navigation">'._("Hotspots").'</a>'."\n";
286                */
287                $html .= '<span class="navigation">';
288                $html .= Network :: getCurrentNetwork()->getName()." "._("Building your wireless community");
289                $html .= '</span>';
290                $html .= "</div>"."\n"; //End navigation
291
292                $html .= '<div class="language">'."\n";
293                $html .= '<form class="language" name="lang_form" method="post" action="'.$_SERVER['REQUEST_URI'].'">'."\n";
294                $html .= _("Language:")."\n";
295                $html .= "<select name='wifidog_language' onChange='javascript: document.lang_form.submit();'>"."\n";
296                global $AVAIL_LOCALE_ARRAY; //From config file
297                foreach ($AVAIL_LOCALE_ARRAY as $lang_ids => $lang_names)
298                {
299                    if (Locale :: getCurrentLocale()->getId() == $lang_ids)
300                    {
301                        $selected = "SELECTED";
302                    }
303                    else
304                    {
305                        $selected = '';
306                    }
307                    $html .= '<option label="'.$lang_names.'" value="'.$lang_ids.'" '.$selected.'>'.$lang_names.'</option>'."\n";
308                }
309                $html .= "</select>"."\n";
310                $html .= "</form>"."\n";
311
312                $html .= "</div>"."\n"; //End language
313
314                $html .= "<div class='tool_content'>"."\n";
315                /******************************/
316                $html .= $this->tool_content;
317                /******************************/
318                $html .= "</div>"."\n"; //End tool_content
319                $html .= '<div class="avis">'."\n";
320                $html .= '<span class="avis">'."\n";
321                $html .= sprintf(_("Accounts on %s are and will stay completely free."), Network :: getCurrentNetwork()->getName());
322                $html .= _("Please inform us of any problem or service interruption at:");
323                $tech_support_email = Network :: getCurrentNetwork()->getTechSupportEmail();
324                $html .= '<a href="mailto:'.$tech_support_email.'">'.$tech_support_email.'</a>'."\n";
325                $html .= "</span>"."\n"; //End avis
326                $html .= "</div>"."\n"; //End avis
327                $html .= "</div>"."\n"; //End tool_section
328                break;
329            default :
330                $html .= '<p class="errmsg">MainUI::getToolContent(): Unknown section!</p>'."\n";
331        }
332        return $html;
333    }
334
335    /**
336     * Display the page
337     *
338     * @internal Uses a few request parameters to displaty debug information
339     * if $_REQUEST['debug_request'] is present, it will print out the $_REQUEST array at the top of the page
340     */
341    public function display()
342    {
343        $html = '';
344        //$this->smarty->display(DEFAULT_CONTENT_SMARTY_PATH."header.html");
345
346        /**** Headers ****/
347        $html .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'."\n";
348        $html .= '<html>'."\n";
349        $html .= '<head>'."\n";
350        $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
351        $html .= '<meta http-equiv="Pragma" CONTENT="no-cache">'."\n";
352        $html .= '<meta http-equiv="Expires" CONTENT="-1">'."\n";
353        // Add HTML headers
354        $html .= "{$this->html_headers}";
355        $html .= "<title>{$this->title}</title>\n";
356                $html .= "<link rel='stylesheet' type='text/css' href='".COMMON_CONTENT_URL.STYLESHEET_NAME."' />\n";
357        if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.STYLESHEET_NAME))
358        {
359            $stylesheet_file = NODE_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
360        }
361        else
362        {
363            $stylesheet_file = DEFAULT_CONTENT_SMARTY_PATH.STYLESHEET_NAME;
364        }
365        $html .= "<style type='text/css'>\n";
366        $html .= $this->smarty->fetch($stylesheet_file);
367        $html .= "</style>\n";
368        $html .= "</head>\n";
369
370        $html .= "<body class='bodyBackColor'>"."\n";
371        if (isset ($_REQUEST['debug_request']))
372        {
373            $html .= '<pre>';
374            $html .= print_r($_REQUEST, true);
375            $html .= '</pre>';
376        }
377        $html .= '<div class="outer_container">'."\n";
378
379        if ($this->isToolSectionEnabled())
380        {
381            /**** Tools ******/
382            $html .= $this->getToolContent();
383
384            /**** Main section ****/
385            $html .= "<div id='main_section'>"."\n";
386            $html .= $this->main_content;
387            $html .= "</div>"."\n"; //End main_section
388        }
389        else
390        {
391            /**** Main section ****/
392            $html .= $this->main_content;
393        }
394
395        $html .= '</div>'."\n"; //End outer_container
396
397        foreach ($this->footer_scripts as $script)
398        {
399            $html .= "{$script}\n";
400        }
401        $html .= "</body>"."\n";
402        $html .= "</html>"."\n";
403        echo $html;
404
405    }
406
407    function displayError($errmsg)
408    {
409        $html = "<p>$errmsg</p>\n";
410        $email = Network :: getCurrentNetwork()->getTechSupportEmail();
411        if (!empty ($email))
412        {
413            $html .= "<p>"._("Please get in touch with ")."<a href='{$email}'>{$email}</a></p>";
414        }
415        $this->setMainContent($html);
416        $this->display();
417    }
418
419}
420
421/*
422 * Local variables:
423 * tab-width: 4
424 * c-basic-offset: 4
425 * c-hanging-comment-ender-p: nil
426 * End:
427 */
428
429?>
Note: See TracBrowser for help on using the browser.