| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 5 | |
|---|
| 6 | // +-------------------------------------------------------------------+ |
|---|
| 7 | // | WiFiDog Authentication Server | |
|---|
| 8 | // | ============================= | |
|---|
| 9 | // | | |
|---|
| 10 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 11 | // | portal suite. | |
|---|
| 12 | // +-------------------------------------------------------------------+ |
|---|
| 13 | // | PHP version 5 required. | |
|---|
| 14 | // +-------------------------------------------------------------------+ |
|---|
| 15 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 16 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 17 | // +-------------------------------------------------------------------+ |
|---|
| 18 | // | This program is free software; you can redistribute it and/or | |
|---|
| 19 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 20 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 21 | // | the License, or (at your option) any later version. | |
|---|
| 22 | // | | |
|---|
| 23 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 24 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 26 | // | GNU General Public License for more details. | |
|---|
| 27 | // | | |
|---|
| 28 | // | You should have received a copy of the GNU General Public License | |
|---|
| 29 | // | along with this program; if not, contact: | |
|---|
| 30 | // | | |
|---|
| 31 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 32 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 33 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 34 | // | | |
|---|
| 35 | // +-------------------------------------------------------------------+ |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * Network status page |
|---|
| 39 | * |
|---|
| 40 | * @package WiFiDogAuthServer |
|---|
| 41 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 42 | * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 43 | * @version Subversion $Id$ |
|---|
| 44 | * @link http://www.wifidog.org/ |
|---|
| 45 | */ |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Define default sort parameter |
|---|
| 49 | */ |
|---|
| 50 | define('DEFAULT_SORT_BY_PARAM', "name"); |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * Load required files |
|---|
| 54 | */ |
|---|
| 55 | require_once (dirname(__FILE__) . '/include/common.php'); |
|---|
| 56 | |
|---|
| 57 | require_once ('include/common_interface.php'); |
|---|
| 58 | require_once ('classes/Node.php'); |
|---|
| 59 | require_once ('classes/Utils.php'); |
|---|
| 60 | $smarty = SmartyWifidog :: getObject(); |
|---|
| 61 | $db = AbstractDb :: getObject(); |
|---|
| 62 | |
|---|
| 63 | // Set the sort parameter, defaults to name |
|---|
| 64 | if (empty ($_REQUEST["sort_by"])) { |
|---|
| 65 | $sort_by_param = DEFAULT_SORT_BY_PARAM; |
|---|
| 66 | $sort_by_using_sql = true; |
|---|
| 67 | } |
|---|
| 68 | else { |
|---|
| 69 | // Validate sort parameters |
|---|
| 70 | switch ($_REQUEST["sort_by"]) { |
|---|
| 71 | // SQL sort parameters |
|---|
| 72 | case "last_heartbeat_user_agent" : |
|---|
| 73 | case "name" : |
|---|
| 74 | case "creation_date" : |
|---|
| 75 | case "gw_id" : |
|---|
| 76 | // Fall-through valid parameters |
|---|
| 77 | $sort_by_param = $_REQUEST["sort_by"]; |
|---|
| 78 | $sort_by_using_sql = true; |
|---|
| 79 | break; |
|---|
| 80 | // Abstraction-driven sort parameters |
|---|
| 81 | case "node_id" : |
|---|
| 82 | case "num_online_users" : |
|---|
| 83 | $sort_by_param = $_REQUEST["sort_by"]; |
|---|
| 84 | $sort_by_using_sql = false; |
|---|
| 85 | break; |
|---|
| 86 | default : |
|---|
| 87 | $sort_by_param = DEFAULT_SORT_BY_PARAM; |
|---|
| 88 | $sort_by_using_sql = true; |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // Sort according to above instructions |
|---|
| 93 | if ($sort_by_using_sql === true) { |
|---|
| 94 | // Check if ordering should ignore uppper and lower case |
|---|
| 95 | if ($sort_by_param == "name" || $sort_by_param == "node_id") { |
|---|
| 96 | $sort_by_param_sql = "lower(" . $sort_by_param . ")"; |
|---|
| 97 | } |
|---|
| 98 | else { |
|---|
| 99 | $sort_by_param_sql = $sort_by_param; |
|---|
| 100 | } |
|---|
| 101 | $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_sql}"; |
|---|
| 102 | } |
|---|
| 103 | else { |
|---|
| 104 | $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; |
|---|
| 105 | } |
|---|
| 106 | $nodes_results = null; |
|---|
| 107 | $db->execSql($sql, $nodes_results, false); |
|---|
| 108 | |
|---|
| 109 | if ($nodes_results == null) |
|---|
| 110 | throw new Exception(_("No nodes could not be found in the database")); |
|---|
| 111 | |
|---|
| 112 | $deploymentStatuses = array ( |
|---|
| 113 | "DEPLOYED" => _("Deployed" |
|---|
| 114 | ), "IN_PLANNING" => _("In planning"), "IN_TESTING" => _("In testing"), "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), "PERMANENTLY_CLOSED" => _("Permanently closed"), "TEMPORARILY_CLOSED" => _("Temporarily closed")); |
|---|
| 115 | |
|---|
| 116 | $nodes_list = array (); |
|---|
| 117 | foreach ($nodes_results as $node_row) { |
|---|
| 118 | $node = Node :: getObject($node_row['node_id']); |
|---|
| 119 | $node_row['duration'] = $db->GetDurationArrayFromIntervalStr($node_row['since_last_heartbeat']); |
|---|
| 120 | $node_row['num_online_users'] = $node->getNumOnlineUsers(); |
|---|
| 121 | $nodeDeploymentStatus = $node_row['node_deployment_status']; |
|---|
| 122 | $node_row['node_deployment_status'] = $deploymentStatuses["$nodeDeploymentStatus"]; |
|---|
| 123 | $nodes_list[] = $node_row; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | // Sort using PHP |
|---|
| 127 | if ($sort_by_using_sql === false) { |
|---|
| 128 | // Using natural-sort algorithm . |
|---|
| 129 | switch ($sort_by_param) { |
|---|
| 130 | case "node_id" : |
|---|
| 131 | Utils :: natsort2d($nodes_list, "node_id"); |
|---|
| 132 | break; |
|---|
| 133 | case "num_online_users" : |
|---|
| 134 | Utils :: natsort2d($nodes_list, "num_online_users"); |
|---|
| 135 | break; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | // Pass values to Smarty |
|---|
| 140 | $smarty->assign("nodes", $nodes_list); |
|---|
| 141 | $smarty->assign("sort_by_param", $sort_by_param); |
|---|
| 142 | |
|---|
| 143 | require_once ('classes/MainUI.php'); |
|---|
| 144 | |
|---|
| 145 | $ui = MainUI :: getObject(); |
|---|
| 146 | $ui->addContent('main_area_middle', $smarty->fetch("templates/node_list.html")); |
|---|
| 147 | $ui->display(); |
|---|
| 148 | |
|---|
| 149 | /* |
|---|
| 150 | * Local variables: |
|---|
| 151 | * tab-width: 4 |
|---|
| 152 | * c-basic-offset: 4 |
|---|
| 153 | * c-hanging-comment-ender-p: nil |
|---|
| 154 | * End: |
|---|
| 155 | */ |
|---|
| 156 | ?> |
|---|