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