root/trunk/wifidog-auth/wifidog/node_list.php @ 1135

Revision 1135, 6.2 KB (checked in by benoitg, 6 years ago)

* Fix broken auth

  • 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 * Network status page
38 *
39 * @package    WiFiDogAuthServer
40 * @author     Benoit Grégoire <bock@step.polymtl.ca>
41 * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
42 * @version    Subversion $Id$
43 * @link       http://www.wifidog.org/
44 */
45
46/**
47 * Define default sort parameter
48 */
49define('DEFAULT_SORT_BY_PARAM', "name");
50
51/**
52 * Load required files
53 */
54require_once(dirname(__FILE__) . '/include/common.php');
55
56require_once('include/common_interface.php');
57require_once('classes/Node.php');
58require_once('classes/Utils.php');
59$smarty = SmartyWifidog::getObject();
60$db = AbstractDb::getObject();
61
62// Set the sort parameter, defaults to name
63if (empty ($_REQUEST["sort_by"]))
64{
65    $sort_by_param = DEFAULT_SORT_BY_PARAM;
66    $sort_by_using_sql = true;
67}
68else
69{
70    // Validate sort parameters
71    switch ($_REQUEST["sort_by"])
72    {
73        // SQL sort parameters
74        case "last_heartbeat_user_agent" :
75                case "name" :
76                case "creation_date" :
77                        // Fall-through valid parameters
78                        $sort_by_param = $_REQUEST["sort_by"];
79                        $sort_by_using_sql = true;
80                        break;
81                // Abstraction-driven sort parameters
82                case "node_id" :
83                case "num_online_users" :
84                        $sort_by_param = $_REQUEST["sort_by"];
85                        $sort_by_using_sql = false;
86                        break;
87                default :
88                        $sort_by_param = DEFAULT_SORT_BY_PARAM;
89                        $sort_by_using_sql = true;
90        }
91}
92
93// Check if ordering should ignore uppper and lower case
94if ($sort_by_param == "name" || $sort_by_param == "node_id") {
95    $sort_by_param = "lower(" . $sort_by_param . ")";
96}
97
98// Sort according to above instructions
99if ($sort_by_using_sql === true)
100    $sql = "SELECT node_id, gw_id, name, last_heartbeat_user_agent, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS online, creation_date, node_deployment_status FROM nodes WHERE node_deployment_status != 'PERMANENTLY_CLOSED' ORDER BY {$sort_by_param}";
101else
102    $sql = "SELECT node_id, gw_id, name, last_heartbeat_user_agent, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS online, creation_date, node_deployment_status FROM nodes WHERE node_deployment_status != 'PERMANENTLY_CLOSED' ORDER BY ".DEFAULT_SORT_BY_PARAM;
103$nodes_results = null;
104$db->execSql($sql, $nodes_results, false);
105
106if ($nodes_results == null)
107    throw new Exception(_("No nodes could not be found in the database"));
108
109$deploymentStatuses = array(
110    "DEPLOYED" => _("Deployed"),
111    "IN_PLANNING" => _("In planning"),
112    "IN_TESTING" => _("In testing"),
113    "NON_WIFIDOG_NODE" => _("Non-Wifidog node"),
114    "PERMANENTLY_CLOSED" => _("Permanently closed"),
115    "TEMPORARILY_CLOSED" => _("Temporarily closed")
116    );
117
118$nodes_list = array ();
119foreach ($nodes_results as $node_row)
120{
121    $node = Node :: getObject($node_row['node_id']);
122    $node_row['duration'] = $db->GetDurationArrayFromIntervalStr($node_row['since_last_heartbeat']);
123    $node_row['num_online_users'] = $node->getNumOnlineUsers();
124    $nodeDeploymentStatus = $node_row['node_deployment_status'];
125    $node_row['node_deployment_status'] = $deploymentStatuses["$nodeDeploymentStatus"];
126    $nodes_list[] = $node_row;
127}
128
129// Sort using PHP
130if ($sort_by_using_sql === false)
131{
132    // Using natural-sort algorithm .
133    switch ($sort_by_param)
134    {
135        case "node_id" :
136            Utils::natsort2d($nodes_list, "node_id");
137            break;
138        case "num_online_users" :
139            Utils::natsort2d($nodes_list, "num_online_users");
140            break;
141    }
142}
143
144// Pass values to Smarty
145$smarty->assign("nodes", $nodes_list);
146$smarty->assign("sort_by_param", $sort_by_param);
147
148require_once('classes/MainUI.php');
149
150$ui = MainUI::getObject();
151$ui->addContent('main_area_middle', $smarty->fetch("templates/node_list.html"));
152$ui->display();
153
154/*
155 * Local variables:
156 * tab-width: 4
157 * c-basic-offset: 4
158 * c-hanging-comment-ender-p: nil
159 * End:
160 */
161
162?>
Note: See TracBrowser for help on using the browser.