| 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 François Proulx <francois.proulx@gmail.com> |
|---|
| 40 | * @copyright (c)2006 François Proulx |
|---|
| 41 | * @link http://www.wifidog.org/ |
|---|
| 42 | */ |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Load required classes |
|---|
| 46 | */ |
|---|
| 47 | require_once('classes/Network.php'); |
|---|
| 48 | require_once('classes/Node.php'); |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * Defines the JiWire CSV type of node list |
|---|
| 52 | * |
|---|
| 53 | * @package WiFiDogAuthServer |
|---|
| 54 | * @subpackage NodeLists |
|---|
| 55 | * @author François Proulx <francois.proulx@gmail.com> |
|---|
| 56 | * @copyright (c) 2006 François Proulx |
|---|
| 57 | */ |
|---|
| 58 | class NodeListJiWireCSV { |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * |
|---|
| 62 | * The JiWire formatted CSV document |
|---|
| 63 | */ |
|---|
| 64 | private $_csv_document; |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * Network to generate the list from |
|---|
| 68 | * |
|---|
| 69 | * @var object |
|---|
| 70 | * |
|---|
| 71 | * @access private |
|---|
| 72 | */ |
|---|
| 73 | private $_network; |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Nodes to generate the list from |
|---|
| 77 | * |
|---|
| 78 | * @var array |
|---|
| 79 | * |
|---|
| 80 | * @access private |
|---|
| 81 | */ |
|---|
| 82 | private $_nodes; |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Constructor |
|---|
| 86 | * |
|---|
| 87 | * @return void |
|---|
| 88 | * |
|---|
| 89 | * @access public |
|---|
| 90 | */ |
|---|
| 91 | public function __construct(&$network) |
|---|
| 92 | { |
|---|
| 93 | // Define globals |
|---|
| 94 | global $db; |
|---|
| 95 | |
|---|
| 96 | // Init network |
|---|
| 97 | $this->_network = $network; |
|---|
| 98 | |
|---|
| 99 | $this->_csv_document = ""; |
|---|
| 100 | |
|---|
| 101 | // Query the database, sorting by node name |
|---|
| 102 | $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 lower(name)", $this->_nodes, false); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Sets header of output |
|---|
| 107 | * |
|---|
| 108 | * @return void |
|---|
| 109 | * |
|---|
| 110 | * @access public |
|---|
| 111 | */ |
|---|
| 112 | public function setHeader() |
|---|
| 113 | { |
|---|
| 114 | header("Cache-control: private, no-cache, must-revalidate"); |
|---|
| 115 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date |
|---|
| 116 | header("Pragma: no-cache"); |
|---|
| 117 | header("Content-Type: text/csv; charset=UTF-8"); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | private function quoteForCsv($str) |
|---|
| 121 | { |
|---|
| 122 | return "\"".str_replace("\"", "\"\"", $str)."\""; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | * Retreives the output of this object. |
|---|
| 127 | * |
|---|
| 128 | * @param bool $return_object If true this function only returns the DOM object |
|---|
| 129 | * |
|---|
| 130 | * @return string The XML output |
|---|
| 131 | * |
|---|
| 132 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 133 | * @author Francois Proulx <francois.proulx@gmail.com> |
|---|
| 134 | * @author Max Horvath <max.horvath@maxspot.de> |
|---|
| 135 | * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 136 | * @copyright 2004-2006 Francois Proulx, Technologies Coeus inc. |
|---|
| 137 | * @copyright 2006 Max Horvath, maxspot GmbH |
|---|
| 138 | * |
|---|
| 139 | * @access public |
|---|
| 140 | */ |
|---|
| 141 | public function getOutput($return_object = false) |
|---|
| 142 | { |
|---|
| 143 | $this->_csv_document = "jiwire_ref, status, provider_id, provider_name, address, address2, city, state, country, postal_code, website_url, email, phone, fax, location_name, location_type_id, field17, node_type, ssid, fee_comments, equipement, standard_802_11, MAC_address, network_drop, latitude, longitude\r\n"; |
|---|
| 144 | |
|---|
| 145 | if ($this->_nodes) { |
|---|
| 146 | foreach ($this->_nodes as $_nodeData) { |
|---|
| 147 | $_node = Node::getObject($_nodeData['node_id']); |
|---|
| 148 | |
|---|
| 149 | // No JiWire ref. number, status NEW |
|---|
| 150 | $this->_csv_document .= "###,NEW,"; |
|---|
| 151 | |
|---|
| 152 | // Provider Name = Wifidog node ID |
|---|
| 153 | $this->_csv_document .= $this->quoteForCsv($_node->getId()).","; |
|---|
| 154 | |
|---|
| 155 | // Provider Id = Wifidog Network name |
|---|
| 156 | $this->_csv_document .= $this->quoteForCsv($this->_network->getName()).","; |
|---|
| 157 | |
|---|
| 158 | // Address |
|---|
| 159 | $this->_csv_document .= $this->quoteForCsv($_node->getCivicNumber().", ".$_node->getStreetName()).","; |
|---|
| 160 | |
|---|
| 161 | // Address 2 (skipped) |
|---|
| 162 | $this->_csv_document .= ","; |
|---|
| 163 | |
|---|
| 164 | // City |
|---|
| 165 | $this->_csv_document .= $this->quoteForCsv($_node->getCity()).","; |
|---|
| 166 | |
|---|
| 167 | // State |
|---|
| 168 | $this->_csv_document .= $this->quoteForCsv($_node->getProvince()).","; |
|---|
| 169 | |
|---|
| 170 | // Country |
|---|
| 171 | $this->_csv_document .= $this->quoteForCsv($_node->getCountry()).","; |
|---|
| 172 | |
|---|
| 173 | // Postal code |
|---|
| 174 | $this->_csv_document .= $this->quoteForCsv($_node->getPostalCode()).","; |
|---|
| 175 | |
|---|
| 176 | // Web Site URL |
|---|
| 177 | $this->_csv_document .= $this->quoteForCsv($_node->getHomePageURL()).","; |
|---|
| 178 | |
|---|
| 179 | // Email |
|---|
| 180 | $this->_csv_document .= $this->quoteForCsv($_node->getEmail()).","; |
|---|
| 181 | |
|---|
| 182 | // Phone number |
|---|
| 183 | $this->_csv_document .= $this->quoteForCsv($_node->getTelephone()).","; |
|---|
| 184 | |
|---|
| 185 | // Fax (skipped) |
|---|
| 186 | $this->_csv_document .= ","; |
|---|
| 187 | |
|---|
| 188 | // Node name |
|---|
| 189 | $this->_csv_document .= $this->quoteForCsv($_node->getName()).","; |
|---|
| 190 | |
|---|
| 191 | // Location type (JiWite Appendix A --> 5 = Café), field17 (skipped), node_type (2 = free), SSID (skipped), fee comment (skipped), 802.11 type (b or g, skipped), |
|---|
| 192 | $this->_csv_document .= "5,, 2,,,,,,,"; |
|---|
| 193 | |
|---|
| 194 | // Latitude + longitude |
|---|
| 195 | $this->_csv_document .= $_node->getGisLocation()->getLatitude().",".$_node->getGisLocation()->getLongitude(); |
|---|
| 196 | |
|---|
| 197 | $this->_csv_document .= "\r\n"; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | echo $this->_csv_document; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | /* |
|---|
| 207 | * Local variables: |
|---|
| 208 | * tab-width: 4 |
|---|
| 209 | * c-basic-offset: 4 |
|---|
| 210 | * c-hanging-comment-ender-p: nil |
|---|
| 211 | * End: |
|---|
| 212 | */ |
|---|
| 213 | |
|---|