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

Revision 1253, 7.2 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     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 */
47require_once('classes/Network.php');
48require_once('classes/Node.php');
49require_once('classes/NodeList.php');
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 */
58class NodeListJiWireCSV extends NodeList {
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     */
72    private $_network;
73
74    /**
75     * Nodes to generate the list from
76     *
77     * @var array
78
79     */
80    private $_nodes;
81
82    /**
83     * Constructor
84     *
85     * @return void
86     */
87    public function __construct(&$network)
88    {
89       
90        $db = AbstractDb::getObject();
91
92        // Init network
93        $this->_network = $network;
94
95        $this->_csv_document = "";
96
97        // Query the database, sorting by node name
98        $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);
99    }
100
101    /**
102     * Sets header of output
103     *
104     * @return void
105     */
106    public function setHeader()
107    {
108        header("Cache-control: private, no-cache, must-revalidate");
109        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
110        header("Pragma: no-cache");
111        header("Content-Type: text/csv; charset=UTF-8");
112    }
113
114    private function quoteForCsv($str)
115    {
116                return "\"".str_replace("\"", "\"\"", $str)."\"";
117    }
118
119    /**
120     * Retreives the output of this object.
121     *
122     * @return string The XML output
123     *
124     * @author     Benoit Grégoire <bock@step.polymtl.ca>
125     * @author     Francois Proulx <francois.proulx@gmail.com>
126     * @author     Max Horváth <max.horvath@freenet.de>
127     * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
128     * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
129     * @copyright  2006 Max Horváth, Horvath Web Consulting
130     */
131    public function getOutput()
132    {
133                $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";
134
135                if ($this->_nodes) {
136                        foreach ($this->_nodes as $_nodeData) {
137                                $_node = Node::getObject($_nodeData['node_id']);
138
139                                // No JiWire ref. number, status NEW
140                                $this->_csv_document .= "###,NEW,";
141
142                                // Provider Name = Wifidog node ID
143                                $this->_csv_document .= $this->quoteForCsv($_node->getId()).",";
144
145                                // Provider Id = Wifidog Network name
146                                $this->_csv_document .= $this->quoteForCsv($this->_network->getName()).",";
147
148                                // Address
149                                $this->_csv_document .= $this->quoteForCsv($_node->getCivicNumber().", ".$_node->getStreetName()).",";
150
151                                // Address 2 (skipped)
152                                $this->_csv_document .= ",";
153
154                                // City
155                                $this->_csv_document .= $this->quoteForCsv($_node->getCity()).",";
156
157                                // State
158                                $this->_csv_document .= $this->quoteForCsv($_node->getProvince()).",";
159
160                                // Country
161                                $this->_csv_document .= $this->quoteForCsv($_node->getCountry()).",";
162
163                                // Postal code
164                                $this->_csv_document .= $this->quoteForCsv($_node->getPostalCode()).",";
165
166                                // Web Site URL
167                                $this->_csv_document .= $this->quoteForCsv($_node->getWebSiteURL()).",";
168
169                                // Email
170                                $this->_csv_document .= $this->quoteForCsv($_node->getEmail()).",";
171
172                                // Phone number
173                                $this->_csv_document .= $this->quoteForCsv($_node->getTelephone()).",";
174
175                                // Fax (skipped)
176                                $this->_csv_document .= ",";
177
178                                // Node name
179                                $this->_csv_document .= $this->quoteForCsv($_node->getName()).",";
180
181                                // 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),
182                                $this->_csv_document .= "5,, 2,,,,,,,";
183
184                                // Latitude + longitude
185                                $this->_csv_document .= $_node->getGisLocation()->getLatitude().",".$_node->getGisLocation()->getLongitude();
186
187                                $this->_csv_document .= "\r\n";
188                        }
189                }
190
191        echo $this->_csv_document;
192    }
193
194}
195
196/*
197 * Local variables:
198 * tab-width: 4
199 * c-basic-offset: 4
200 * c-hanging-comment-ender-p: nil
201 * End:
202 */
203
Note: See TracBrowser for help on using the browser.