root/trunk/wifidog-auth/wifidog/classes/NodeLists/NodeListXML.php @ 1253

Revision 1253, 15.1 KB (checked in by benoitg, 6 years ago)
  • Node.php: Improve getCurrentRealNode()
  • Implement #4: Allow the user to easily come back to the portal by typing in the root auth server adress from a hotspot.
  • Log the system information sent with the gateway since almost forever: sys_uptime, sys_memfree, sys_load, wifidog_uptime
  • NodeStatus?.php: Include the above information
  • node_list.html: Include wifidog_uptime if the hotspot is up.
  • Menu.php: Sort menus alphabetically according to the user's locale. TODO: Implement menu weights.
  • NodeLists?: Only list node types that have dependencies met in the menu. Refactor the NodeLists? for proper object-orientation.


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 * @subpackage NodeLists
39 * @author     Benoit Grégoire <bock@step.polymtl.ca>
40 * @author     Francois Proulx <francois.proulx@gmail.com>
41 * @author     Max Horváth <max.horvath@freenet.de>
42 * @copyright  2004-2007 Benoit Grégoire, Technologies Coeus inc.
43 * @copyright  2006 Max Horváth, Horvath Web Consulting
44 * @version    Subversion $Id: $
45 * @link       http://www.wifidog.org/
46 */
47
48/**
49 * Load required classes
50 */
51require_once('classes/NodeList.php');
52require_once('classes/Network.php');
53require_once('classes/Node.php');
54
55/**
56 * Defines the XML type of node list
57 *
58 * @package    WiFiDogAuthServer
59 * @subpackage NodeLists
60 * @author     Benoit Grégoire <bock@step.polymtl.ca>
61 * @author     Francois Proulx <francois.proulx@gmail.com>
62 * @author     Max Horváth <max.horvath@freenet.de>
63 * @copyright  2004-2007 Benoit Grégoire, Technologies Coeus inc.
64 * @copyright  2006 Max Horváth, Horvath Web Consulting
65 */
66class NodeListXML extends NodeList{
67
68    /**
69     * XML DOM Document that will contain all the data concerning the nodes
70     *
71     * @var object
72
73     */
74    private $_xmldoc;
75
76    /**
77     * Network to generate the list from
78     *
79     * @var object
80
81     */
82    private $_network;
83
84    /**
85     * Nodes to generate the list from
86     *
87     * @var array
88
89     */
90    private $_nodes;
91
92    /**
93     * Constructor
94     *
95     * @return void
96     */
97    public function __construct(&$network)
98    {
99
100        $db = AbstractDb::getObject();
101
102        // Init XML Document
103        $this->_xmldoc = new DOMDocument("1.0", "UTF-8");
104        $this->_xmldoc->formatOutput = true;
105
106        // Init network
107        $this->_network = $network;
108
109        // Query the database, sorting by node name
110        $db->execSql("SELECT *, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, EXTRACT(epoch FROM creation_date) as creation_date_epoch, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up FROM nodes WHERE network_id = '" . $db->escapeString($this->_network->getId()) . "' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE') ORDER BY lower(name)", $this->_nodes, false);
111    }
112
113    /**
114     * Sets header of output
115     *
116     * @return void
117     */
118    public function setHeader()
119    {
120        header("Cache-control: private, no-cache, must-revalidate");
121        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
122        header("Pragma: no-cache");
123        header("Content-Type: text/xml; charset=UTF-8");
124    }
125
126    /**
127     * Retreives the output of this object.
128     *
129     * @param bool $return_object If true this function only returns the DOM object
130     *
131     * @return string The XML output
132     *
133     * @author     Benoit Grégoire <bock@step.polymtl.ca>
134     * @author     Francois Proulx <francois.proulx@gmail.com>
135     * @author     Max Horváth <max.horvath@freenet.de>
136     * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
137     * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
138     * @copyright  2006 Max Horváth, Horvath Web Consulting
139     */
140    public function getOutput($return_object = false)
141    {
142        // Root node
143        $_hotspotStatusRootNode = $this->_xmldoc->createElement("wifidogHotspotsStatus");
144        $_hotspotStatusRootNode->setAttribute('version', '1.0');
145        $this->_xmldoc->appendChild($_hotspotStatusRootNode);
146
147        // Document metadata
148        $_documentGendateNode = $this->_xmldoc->createElement("generationDateTime", gmdate("Y-m-d\Th:m:s\Z"));
149        $_hotspotStatusRootNode->appendChild($_documentGendateNode);
150
151        // Network metadata
152        $_networkMetadataNode = $this->_xmldoc->createElement("networkMetadata");
153        $_networkMetadataNode = $_hotspotStatusRootNode->appendChild($_networkMetadataNode);
154
155        $_networkUriNode = $this->_xmldoc->createElement("networkUri", htmlspecialchars($this->_network->getWebSiteURL(), ENT_QUOTES));
156        $_networkMetadataNode->appendChild($_networkUriNode);
157
158        $_networkNameNode = $this->_xmldoc->createElement("name", htmlspecialchars($this->_network->getName(), ENT_QUOTES));
159        $_networkMetadataNode->appendChild($_networkNameNode);
160
161        $_networkUrlNode = $this->_xmldoc->createElement("websiteUrl", htmlspecialchars($this->_network->getWebSiteURL(), ENT_QUOTES));
162        $_networkMetadataNode->appendChild($_networkUrlNode);
163
164        $_email = $this->_network->getTechSupportEmail();
165        if (!empty($email)) {
166            $_networkEmailNode = $this->_xmldoc->createElement("techSupportEmail", $_email);
167            $_networkMetadataNode->appendChild($_networkEmailNode);
168        }
169
170        $_nodesCountNode = $this->_xmldoc->createElement("hotspotsCount", count($this->_nodes));
171        $_networkMetadataNode->appendChild($_nodesCountNode);
172
173        $_networkValidUsersNode = $this->_xmldoc->createElement("validSubscribedUsersCount", $this->_network->getNumValidUsers());
174        $_networkMetadataNode->appendChild($_networkValidUsersNode);
175
176        // Get number of online users
177        $_networkOnlineUsersNode = $this->_xmldoc->createElement("onlineUsersCount", $this->_network->getNumOnlineUsers());
178        $_networkMetadataNode->appendChild($_networkOnlineUsersNode);
179
180        // Node details
181        if ($this->_nodes) {
182            // Hotspots metadata
183            $_hotspotsMetadataNode = $this->_xmldoc->createElement("hotspots");
184            $_hotspotsMetadataNode = $_hotspotStatusRootNode->appendChild($_hotspotsMetadataNode);
185
186            foreach ($this->_nodes as $_nodeData) {
187                $_node = Node::getObject($_nodeData['node_id']);
188                $this->_network = $_node->getNetwork();
189
190                $_hotspot = $this->_xmldoc->createElement("hotspot");
191                $_hotspot = $_hotspotsMetadataNode->appendChild($_hotspot);
192
193                // Hotspot ID
194                $_hotspotId = $this->_xmldoc->createElement("hotspotId", $_node->getId());
195                $_hotspot->appendChild($_hotspotId);
196
197                // Hotspot name
198                $_hotspotName = $this->_xmldoc->createElement("name", htmlspecialchars($_node->getName(), ENT_QUOTES));
199                $_hotspot->appendChild($_hotspotName);
200
201                /**
202                 * (1..n) A Hotspot has many node
203                 *
204                 * WARNING For now, we are simply duplicating the hotspot data in node
205                 * Until wifidog implements full abstractiong hotspot vs nodes.
206                 */
207                $_nodes = $this->_xmldoc->createElement("nodes");
208                $_hotspot->appendChild($_nodes);
209
210                $_nodeMetadataNode = $this->_xmldoc->createElement("node");
211                $_nodes->appendChild($_nodeMetadataNode);
212
213                // Node ID
214                $_nodeId = $this->_xmldoc->createElement("nodeId", $_node->getId());
215                $_nodeMetadataNode->appendChild($_nodeId);
216
217                // Online Users
218                $_nodeUserNum = $this->_xmldoc->createElement("numOnlineUsers", $_node->GetNumOnlineUsers());
219                $_nodeMetadataNode->appendChild($_nodeUserNum);
220
221                $_nodeCreationDate = $this->_xmldoc->createElement("creationDate", $_node->getCreationDate());
222                $_nodeMetadataNode->appendChild($_nodeCreationDate);
223
224                if ($_node->getDeploymentStatus() != 'NON_WIFIDOG_NODE') {
225                    if ($_nodeData['is_up'] == 't') {
226                        $_nodeStatus = $this->_xmldoc->createElement("status", "up");
227                    } else {
228                        $_nodeStatus = $this->_xmldoc->createElement("status", "down");
229                    }
230
231                    $_nodeMetadataNode->appendChild($_nodeStatus);
232                }
233
234                if (($_gisData = $_node->getGisLocation()) !== null) {
235                    $_nodeGis = $this->_xmldoc->createElement("gisLatLong");
236                    $_nodeGis->setAttribute("lat", $_gisData->getLatitude());
237                    $_nodeGis->setAttribute("long", $_gisData->getLongitude());
238                    $_nodeMetadataNode->appendChild($_nodeGis);
239                }
240
241                // Hotspot opening date ( for now it's called creation_date )
242                $_hotspotOpeningDate = $this->_xmldoc->createElement("openingDate", $_node->getCreationDate());
243                $_hotspot->appendChild($_hotspotOpeningDate);
244
245                // Hotspot Website URL
246                if ($_node->getWebSiteURL() != "") {
247                    $_hotspotUrl = $this->_xmldoc->createElement("webSiteUrl", htmlspecialchars($_node->getWebSiteURL(), ENT_QUOTES));
248                    $_hotspot->appendChild($_hotspotUrl);
249                }
250
251                // Hotspot global status
252                if ($_node->getDeploymentStatus() != 'NON_WIFIDOG_NODE') {
253                    if ($_nodeData['is_up'] == 't') {
254                        $_hotspotStatus = $this->_xmldoc->createElement("globalStatus", "100");
255                    } else {
256                        $_hotspotStatus = $this->_xmldoc->createElement("globalStatus", "0");
257                    }
258
259                    $_hotspot->appendChild($_hotspotStatus);
260                }
261
262                // Description
263                if ($_node->getDescription() != "") {
264                    $_hotspotDesc = $this->_xmldoc->createElement("description", htmlspecialchars($_node->getDescription(), ENT_QUOTES));
265                    $_hotspot->appendChild($_hotspotDesc);
266                }
267
268                // Map Url
269                if ($_node->getMapURL() != "") {
270                    $_hotspotMapUrl = $this->_xmldoc->createElement("mapUrl", htmlspecialchars($_node->getMapURL(), ENT_QUOTES));
271                    $_hotspot->appendChild($_hotspotMapUrl);
272                }
273
274                // Mass transit info
275                if ($_node->getTransitInfo() != "") {
276                    $_hotspotTransit = $this->_xmldoc->createElement("massTransitInfo", htmlspecialchars($_node->getTransitInfo(), ENT_QUOTES));
277                    $_hotspot->appendChild($_hotspotTransit);
278                }
279
280                // Contact e-mail
281                if ($_node->getEmail() != "") {
282                    $_hotspotContactEmail = $this->_xmldoc->createElement("contactEmail", $_node->getEmail());
283                    $_hotspot->appendChild($_hotspotContactEmail);
284                }
285
286                // Contact phone
287                if ($_node->getTelephone() != "") {
288                    $_hotspotContactPhone = $this->_xmldoc->createElement("contactPhoneNumber", $_node->getTelephone());
289                    $_hotspot->appendChild($_hotspotContactPhone);
290                }
291
292                // Civic number
293                if ($_node->getCivicNumber() != "") {
294                    $_hotspotCivicNr = $this->_xmldoc->createElement("civicNumber", $_node->getCivicNumber());
295                    $_hotspot->appendChild($_hotspotCivicNr);
296                }
297
298                // Street address
299                if ($_node->getStreetName() != "") {
300                    $_hotspotStreet = $this->_xmldoc->createElement("streetAddress", htmlspecialchars($_node->getStreetName(), ENT_QUOTES));
301                    $_hotspot->appendChild($_hotspotStreet);
302                }
303
304                // City
305                if ($_node->getCity() != "") {
306                    $_hotspotCity = $this->_xmldoc->createElement("city", htmlspecialchars($_node->getCity(), ENT_QUOTES));
307                    $_hotspot->appendChild($_hotspotCity);
308                }
309
310                // Province
311                if ($_node->getProvince() != "") {
312                    $_hotspotProvince = $this->_xmldoc->createElement("province", htmlspecialchars($_node->getProvince(), ENT_QUOTES));
313                    $_hotspot->appendChild($_hotspotProvince);
314                }
315
316                // Postal code
317                if ($_node->getPostalCode() != "") {
318                    $_hotspotPostalCode = $this->_xmldoc->createElement("postalCode", $_node->getPostalCode());
319                    $_hotspot->appendChild($_hotspotPostalCode);
320                }
321
322                // Country
323                if ($_node->getCountry() != "") {
324                    $_hotspotCountry = $this->_xmldoc->createElement("country", htmlspecialchars($_node->getCountry(), ENT_QUOTES));
325                    $_hotspot->appendChild($_hotspotCountry);
326                }
327
328                // Long / Lat
329                if (($_gisData = $_node->getGisLocation()) !== null) {
330                    $_hotspotGis = $this->_xmldoc->createElement("gisCenterLatLong");
331                    $_hotspotGis->setAttribute("lat", $_gisData->getLatitude());
332                    $_hotspotGis->setAttribute("long", $_gisData->getLongitude());
333                    $_hotspot->appendChild($_hotspotGis);
334                }
335            }
336        }
337
338        if ($return_object) {
339            return $this->_xmldoc;
340        } else {
341            echo $this->_xmldoc->saveXML();
342        }
343    }
344
345}
346
347/*
348 * Local variables:
349 * tab-width: 4
350 * c-basic-offset: 4
351 * c-hanging-comment-ender-p: nil
352 * End:
353 */
354
Note: See TracBrowser for help on using the browser.