| 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 Joe Bowser <bowserj@resist.ca> |
|---|
| 40 | * @author Max Horváth <max.horvath@freenet.de> |
|---|
| 41 | * @copyright 2006 Joe Bowser |
|---|
| 42 | * @copyright 2006 Max Horváth, Horvath Web Consulting |
|---|
| 43 | * @version Subversion $Id: Content.php 974 2006-02-25 15:08:12Z max-horvath $ |
|---|
| 44 | * @link http://www.wifidog.org/ |
|---|
| 45 | */ |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Load required classes |
|---|
| 49 | */ |
|---|
| 50 | require_once('classes/Network.php'); |
|---|
| 51 | require_once('classes/Node.php'); |
|---|
| 52 | require_once('classes/NodeList.php'); |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * Defines the KML type of node list |
|---|
| 56 | * |
|---|
| 57 | * @package WiFiDogAuthServer |
|---|
| 58 | * @subpackage NodeLists |
|---|
| 59 | * @author Joe Bowser <bowserj@resist.ca> |
|---|
| 60 | * @copyright 2006 Joe Bowser |
|---|
| 61 | */ |
|---|
| 62 | class NodeListKML extends NodeList{ |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * XML DOM Document that will contain all the data concerning the nodes |
|---|
| 66 | * |
|---|
| 67 | * @var object |
|---|
| 68 | |
|---|
| 69 | */ |
|---|
| 70 | private $_xmldoc; |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | * Network to generate the list from |
|---|
| 74 | * |
|---|
| 75 | * @var object |
|---|
| 76 | |
|---|
| 77 | */ |
|---|
| 78 | private $_network; |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * Nodes to generate the list from |
|---|
| 82 | * |
|---|
| 83 | * @var array |
|---|
| 84 | |
|---|
| 85 | */ |
|---|
| 86 | private $_nodes; |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | * Constructor |
|---|
| 90 | * |
|---|
| 91 | * @return void |
|---|
| 92 | */ |
|---|
| 93 | public function __construct(&$network) |
|---|
| 94 | { |
|---|
| 95 | |
|---|
| 96 | $db = AbstractDb::getObject(); |
|---|
| 97 | |
|---|
| 98 | // Init XML Document |
|---|
| 99 | $this->_xmldoc = new DOMDocument("1.0", "UTF-8"); |
|---|
| 100 | $this->_xmldoc->formatOutput = true; |
|---|
| 101 | |
|---|
| 102 | // Init network |
|---|
| 103 | $this->_network = $network; |
|---|
| 104 | |
|---|
| 105 | // Query the database, sorting by node name |
|---|
| 106 | $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); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * Sets header of output |
|---|
| 111 | * |
|---|
| 112 | * @return void |
|---|
| 113 | */ |
|---|
| 114 | public function setHeader() |
|---|
| 115 | { |
|---|
| 116 | header("Cache-control: private, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|---|
| 117 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date |
|---|
| 118 | header("Pragma: no-cache"); |
|---|
| 119 | header("Content-Transfer-Encoding: binary"); |
|---|
| 120 | header("Content-Type: application/vnd.google-earth.kml+xml; charset=UTF-8"); |
|---|
| 121 | header("Content-Disposition: attachment; filename=" . $this->_network->getId() . "_hotspot_status.kml"); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | /** |
|---|
| 125 | * Displays the output of this object. |
|---|
| 126 | * |
|---|
| 127 | * @return void |
|---|
| 128 | * |
|---|
| 129 | * @author Benoit Gregoire <bock@step.polymtl.ca> |
|---|
| 130 | * @author Francois Proulx <francois.proulx@gmail.com> |
|---|
| 131 | * @author Max Horváth <max.horvath@freenet.de> |
|---|
| 132 | * @author Joe Bowser <bowserj@resist.ca> |
|---|
| 133 | * @copyright 2004-2006 Benoit Gregoire, Technologies Coeus inc. |
|---|
| 134 | * @copyright 2004-2006 Francois Proulx, Technologies Coeus inc. |
|---|
| 135 | * @copyright 2006 Max Horváth, Horvath Web Consulting |
|---|
| 136 | * @copyright 2006 Joe Bowser |
|---|
| 137 | */ |
|---|
| 138 | public function getOutput() |
|---|
| 139 | { |
|---|
| 140 | $_kml = $this->_xmldoc->createElement("kml"); |
|---|
| 141 | $_kml->setAttribute('xmlns', 'http://earth.google.com/kml/2.0'); |
|---|
| 142 | $this->_xmldoc->appendChild($_kml); |
|---|
| 143 | |
|---|
| 144 | // Document |
|---|
| 145 | $_document = $this->_xmldoc->createElement("Document"); |
|---|
| 146 | $_kml->appendChild($_document); |
|---|
| 147 | |
|---|
| 148 | /* |
|---|
| 149 | * Style Elements (Up Nodes) |
|---|
| 150 | */ |
|---|
| 151 | $_style_up = $this->_xmldoc->createElement("Style"); |
|---|
| 152 | $_style_up->setAttribute('id', 'node_up'); |
|---|
| 153 | $_document->appendChild($_style_up); |
|---|
| 154 | $_iconStyle = $this->_xmldoc->createElement("IconStyle"); |
|---|
| 155 | $_style_up->appendChild($_iconStyle); |
|---|
| 156 | |
|---|
| 157 | /* Since scale is the same, we only have to define it once */ |
|---|
| 158 | $_scale = $this->_xmldoc->createElement("scale"); |
|---|
| 159 | $_iconStyle->appendChild($_scale); |
|---|
| 160 | $_textNode = $this->_xmldoc->createTextNode("0.5"); |
|---|
| 161 | $_scale->appendChild($_textNode); |
|---|
| 162 | |
|---|
| 163 | $_icon = $this->_xmldoc->createElement("Icon"); |
|---|
| 164 | $_iconStyle->appendChild($_icon); |
|---|
| 165 | $_href = $this->_xmldoc->createElement("href"); |
|---|
| 166 | $_icon->appendChild($_href); |
|---|
| 167 | $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/up.png"); |
|---|
| 168 | $_href->appendChild($_textNode); |
|---|
| 169 | |
|---|
| 170 | /* |
|---|
| 171 | * Style Elements (Down Nodes) |
|---|
| 172 | */ |
|---|
| 173 | $_style_down = $this->_xmldoc->createElement("Style"); |
|---|
| 174 | $_style_down->setAttribute('id', 'node_down'); |
|---|
| 175 | $_document->appendChild($_style_down); |
|---|
| 176 | $_iconStyle = $this->_xmldoc->createElement("IconStyle"); |
|---|
| 177 | $_style_down->appendChild($_iconStyle); |
|---|
| 178 | |
|---|
| 179 | $_scale = $this->_xmldoc->createElement("scale"); |
|---|
| 180 | $_iconStyle->appendChild($_scale); |
|---|
| 181 | $_textNode = $this->_xmldoc->createTextNode("0.5"); |
|---|
| 182 | $_scale->appendChild($_textNode); |
|---|
| 183 | |
|---|
| 184 | $_iconStyle->appendChild($_scale); |
|---|
| 185 | $_icon = $this->_xmldoc->createElement("Icon"); |
|---|
| 186 | $_iconStyle->appendChild($_icon); |
|---|
| 187 | $_href = $this->_xmldoc->createElement("href"); |
|---|
| 188 | $_icon->appendChild($_href); |
|---|
| 189 | $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/down.png"); |
|---|
| 190 | $_href->appendChild($_textNode); |
|---|
| 191 | |
|---|
| 192 | /* |
|---|
| 193 | * Style Elements (Unknown Nodes) |
|---|
| 194 | */ |
|---|
| 195 | |
|---|
| 196 | $_style_unknown = $this->_xmldoc->createElement("Style"); |
|---|
| 197 | $_style_unknown->setAttribute('id', 'node_unknown'); |
|---|
| 198 | $_document->appendChild($_style_unknown); |
|---|
| 199 | $_iconStyle = $this->_xmldoc->createElement("IconStyle"); |
|---|
| 200 | $_style_unknown->appendChild($_iconStyle); |
|---|
| 201 | |
|---|
| 202 | $_scale = $this->_xmldoc->createElement("scale"); |
|---|
| 203 | $_iconStyle->appendChild($_scale); |
|---|
| 204 | $_textNode = $this->_xmldoc->createTextNode("0.5"); |
|---|
| 205 | $_scale->appendChild($_textNode); |
|---|
| 206 | |
|---|
| 207 | $_icon = $this->_xmldoc->createElement("Icon"); |
|---|
| 208 | $_iconStyle->appendChild($_icon); |
|---|
| 209 | $_href = $this->_xmldoc->createElement("href"); |
|---|
| 210 | $_icon->appendChild($_href); |
|---|
| 211 | $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/unknown.png"); |
|---|
| 212 | $_href->appendChild($_textNode); |
|---|
| 213 | |
|---|
| 214 | /* |
|---|
| 215 | * Creating the Folder |
|---|
| 216 | */ |
|---|
| 217 | $_folder = $this->_xmldoc->createElement("Folder"); |
|---|
| 218 | $_document->appendChild($_folder); |
|---|
| 219 | $_name = $this->_xmldoc->createElement("name"); |
|---|
| 220 | $_folder->appendChild($_name); |
|---|
| 221 | $_textNode = $this->_xmldoc->createTextNode($this->_network->getName()); |
|---|
| 222 | $_name->appendChild($_textNode); |
|---|
| 223 | |
|---|
| 224 | /* |
|---|
| 225 | * Creating the Placemarks (Nodes) |
|---|
| 226 | */ |
|---|
| 227 | if ($this->_nodes) { |
|---|
| 228 | foreach ($this->_nodes as $_nodeData) { |
|---|
| 229 | $_node = Node::getObject($_nodeData['node_id']); |
|---|
| 230 | $this->_network = $_node->getNetwork(); |
|---|
| 231 | |
|---|
| 232 | $_placemark = $this->_xmldoc->createElement("Placemark"); |
|---|
| 233 | $_folder->appendChild($_placemark); |
|---|
| 234 | |
|---|
| 235 | // Hotspot name |
|---|
| 236 | $_hotspotName = $this->_xmldoc->createElement("name", htmlspecialchars($_node->getName(), ENT_QUOTES)); |
|---|
| 237 | $_placemark->appendChild($_hotspotName); |
|---|
| 238 | $_html_data = "<b>" . _("Address") . ":</b><br />" . $_node->getCivicNumber() . " " . $_node->getStreetName() . "<br />" . |
|---|
| 239 | $_node->getCity() . "," . $_node->getProvince() . "<br />" . $_node->getCountry() . "<br />" . |
|---|
| 240 | $_node->getPostalCode() . "<br /><br /> <b>" . _("URL") . ":</b> <a href='" . $_node->getWebSiteURL() . "'>" . |
|---|
| 241 | $_node->getWebSiteURL() . "</a> <br /> <b> " . _("Email") . ":</b> <a href='mailto:" . $_node->getEmail() . "'>" . |
|---|
| 242 | $_node->getEmail() . "</a>"; |
|---|
| 243 | // Creating the description node with the data from it |
|---|
| 244 | $_description = $this->_xmldoc->createElement("description"); |
|---|
| 245 | $_placemark->appendChild($_description); |
|---|
| 246 | $_cdata = $this->_xmldoc->createCDATASection($_html_data); |
|---|
| 247 | $_description->appendChild($_cdata); |
|---|
| 248 | // Description data goes here |
|---|
| 249 | $_point = $this->_xmldoc->createElement("Point"); |
|---|
| 250 | $_placemark->appendChild($_point); |
|---|
| 251 | // Get GIS Location |
|---|
| 252 | $_gis_loc = $_node->getGisLocation(); |
|---|
| 253 | $_gis_string = $_gis_loc->getLongitude() . "," |
|---|
| 254 | . $_gis_loc->getLatitude() ."," |
|---|
| 255 | . $_gis_loc->getAltitude(); |
|---|
| 256 | $_coordinates = $this->_xmldoc->createElement("coordinates", $_gis_string); |
|---|
| 257 | // Hotspot global status |
|---|
| 258 | if ($_node->getDeploymentStatus() != 'NON_WIFIDOG_NODE') { |
|---|
| 259 | if ($_nodeData['is_up'] == 't') { |
|---|
| 260 | $_styleURL = $this->_xmldoc->createElement("styleURL", "#node_up"); |
|---|
| 261 | } else { |
|---|
| 262 | $_styleURL = $this->_xmldoc->createElement("styleURL", "#node_down"); |
|---|
| 263 | } |
|---|
| 264 | } |
|---|
| 265 | else { |
|---|
| 266 | $_styleURL = $this->_xmldoc->createElement("styleURL", "#node_unknown"); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | $_point->appendChild($_coordinates); |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | echo $this->_xmldoc->saveXML(); |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | /* |
|---|
| 278 | * Local variables: |
|---|
| 279 | * tab-width: 4 |
|---|
| 280 | * c-basic-offset: 4 |
|---|
| 281 | * c-hanging-comment-ender-p: nil |
|---|
| 282 | * End: |
|---|
| 283 | */ |
|---|
| 284 | |
|---|
| 285 | ?> |
|---|