root/trunk/wifidog-auth/wifidog/hotspot_status.php @ 402

Revision 402, 10.3 KB (checked in by aprilp, 8 years ago)

Some kind of virtual login (we need to talk about this).
New User and Node classes
Modified all files to work with the classes.
Remove mgmt_helpers (all done in User class now)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2  /********************************************************************\
3   * This program is free software; you can redistribute it and/or    *
4   * modify it under the terms of the GNU General Public License as   *
5   * published by the Free Software Foundation; either version 2 of   *
6   * the License, or (at your option) any later version.              *
7   *                                                                  *
8   * This program is distributed in the hope that it will be useful,  *
9   * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
11   * GNU General Public License for more details.                     *
12   *                                                                  *
13   * You should have received a copy of the GNU General Public License*
14   * along with this program; if not, contact:                        *
15   *                                                                  *
16   * Free Software Foundation           Voice:  +1-617-542-5942       *
17   * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
18   * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
19   *                                                                  *
20   \********************************************************************/
21  /**@file hotspot_status.php
22   * Network status page
23   * @author Copyright (C) 2004 Benoit Gr�goire
24   */
25
26define('BASEPATH','./');
27require_once BASEPATH.'include/common.php';
28require_once BASEPATH.'include/common_interface.php';
29
30if(!empty($_REQUEST['format'])) {
31    $format = $_REQUEST['format'];
32} else {
33    $format = null;
34}
35
36$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 node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ORDER BY creation_date", $node_results, false);
37
38if ($format == 'RSS') {
39    Header("Cache-control: private, no-cache, must-revalidate");
40    Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
41    Header("Pragma: no-cache");
42    Header("Content-Type: text/xml; charset=UTF-8");
43
44    $xmldoc = new DOMDocument();
45    $xmldoc->formatOutput = true;
46    //$xmldoc->encoding="iso-8859-15";
47    $rss = $xmldoc->createElement("rss");
48    $xmldoc->appendChild($rss);
49    $rss->setAttribute('version', '2.0');
50
51    /* channel */
52    $channel = $xmldoc->createElement("channel");
53    $rss->appendChild($channel);
54
55    /**************** Required channel elements ********************/
56    /* title */
57    $title = $xmldoc->createElement("title");
58    $title = $channel->appendChild($title);
59
60    $textnode = $xmldoc->createTextNode(utf8_encode(_("Newest")." ".HOTSPOT_NETWORK_NAME. " ". _("Hotspots")));
61    $title->appendChild($textnode);
62
63    /* link */
64    $link = $xmldoc->createElement("link");
65    $channel->appendChild($link);
66    $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL));
67    $link->appendChild($textnode);
68
69    /* description */
70    $description = $xmldoc->createElement("description");
71    $channel->appendChild($description);
72    $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by ").HOTSPOT_NETWORK_NAME));
73    $description->appendChild($textnode);
74
75    /****************** Optional channel elements *******************/
76    /* language */
77    /**@todo Make language selectable */
78    $language = $xmldoc->createElement("language");
79    $channel->appendChild($language);
80    $textnode = $xmldoc->createTextNode("en-CA");
81    $language->appendChild($textnode);
82
83    /* copyright */
84    $copyright = $xmldoc->createElement("copyright");
85    $channel->appendChild($copyright);
86    $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME));
87    $copyright->appendChild($textnode);
88
89    /* managingEditor */
90               
91    /* webMaster */
92               
93    $webMaster = $xmldoc->createElement("webMaster");
94    $channel->appendChild($webMaster);
95    $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL));
96    $webMaster->appendChild($textnode);
97
98    /* pubDate */
99    $pubDate = $xmldoc->createElement("pubDate");
100    $channel->appendChild($pubDate);
101    $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time())));
102    $pubDate->appendChild($textnode);
103
104    /* lastBuildDate */
105    //<lastBuildDate> -- The date-time the last time the content of the channel changed.
106    /* Make a request through the database for the latest modification date of an object. 
107     * Maybe it should be an object property? */
108    $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false);
109
110    $lastBuildDate = $xmldoc->createElement("lastBuildDate");
111    $channel->appendChild($lastBuildDate);
112    $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened']));
113    $lastBuildDate->appendChild($textnode);
114               
115    /* category */
116    /* Specify one or more categories that the channel belongs to.
117     *  Follows the same rules as the <item>-level category element.*/
118                 
119    /* generator */
120    $generator = $xmldoc->createElement("generator");
121    $channel->appendChild($generator);
122    $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME . " " . WIFIDOG_VERSION));
123    $generator->appendChild($textnode);
124               
125    /* docs */
126    $docs = $xmldoc->createElement("docs");
127    $channel->appendChild($docs);
128    $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss"));
129    $docs->appendChild($textnode);
130               
131    /* cloud */
132    /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/
133
134    /* ttl */
135    /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/
136
137    /* image */
138    $image = $xmldoc->createElement("image");
139    $channel->appendChild($image);
140               
141    /* title */
142    $title = $xmldoc->createElement("title");
143    $image->appendChild($title);
144    $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME));
145    $title->appendChild($textnode);
146    /* url */
147    $url = $xmldoc->createElement("url");
148    $image->appendChild($url);
149    $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME));
150    $url->appendChild($textnode);
151    /* link */
152    $link = $xmldoc->createElement("link");
153    $image->appendChild($link);
154    $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL));
155    $link->appendChild($textnode);
156    /* width */
157    /*
158     $width = $xmldoc->createElement("width");
159     $image->appendChild($width);
160     $textnode = $xmldoc->createTextNode('135');
161     $width->appendChild($textnode);
162    */
163    /* height */
164    /*
165     $height = $xmldoc->createElement("height");
166     $image->appendChild($height);
167     $textnode = $xmldoc->createTextNode('109');
168     $height->appendChild($textnode);
169    */
170    /* description */
171    /*
172     $description = $xmldoc->createElement("description");
173     $image->appendChild($description);
174     $textnode = $xmldoc->createTextNode("Le portail des TIC");
175     $description->appendChild($textnode);
176    */
177
178    /* rating */
179    /* textInput */
180    /* skipHours */
181    /* skipDays */
182               
183$i=0;
184
185    foreach($node_results as $node_row) {
186
187      $item = $xmldoc->createElement("item");
188      $item = $channel->appendChild($item);
189
190      /* title */
191      /* lom_1_2_title_langstrings_id */
192      $title = $xmldoc->createElement("title");
193      $item->appendChild($title);
194      $title_str = $node_row['name'];
195
196      if($node_row['is_up']=='t')
197      {
198      $title_str .= " (Currently Up)";
199      }
200      else
201      {
202            $title_str .= " (Currently Down)";
203      }
204      $textnode = $xmldoc->createTextNode(utf8_encode($title_str));
205      $title->appendChild($textnode);
206
207      /* link */
208      if(!empty($node_row['home_page_url']))
209      {
210      $link = $xmldoc->createElement("link");
211      $item->appendChild($link);
212      $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url']));
213      $link->appendChild($textnode);
214      }
215
216      /* description */
217      /* lom_1_4_descriptions_has_langstrings */
218      $description = $xmldoc->createElement("description");
219      $item->appendChild($description);
220      $description_text='';
221      if(!empty($node_row['description']))
222      {
223          $description_text.=$node_row['description'];
224      }
225      if(!empty($node_row['street_address']))
226      {
227          $description_text.= " "._("Address:")." ".$node_row['street_address'];
228      }
229      if(!empty($node_row['mass_transit_info']))
230      {
231          $description_text.=" "._("Mass transit:")." ".$node_row['mass_transit_info'];
232      }
233      $textnode = $xmldoc->createTextNode(utf8_encode($description_text));
234      $description->appendChild($textnode);
235     
236      /* author */
237/*
238          $author = $xmldoc->createElement("author");
239          $item->appendChild($author);
240          $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')');
241          $author->appendChild($textnode);
242*/
243      /* category */
244
245      /* comments */
246      /** Link to page once page is available **/
247      /* enclosure */
248      /* guid */
249
250          $guid = $xmldoc->createElement("guid");
251          $guid->setAttribute('isPermaLink', 'false');
252          $item->appendChild($guid);
253          $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id']));
254          $guid->appendChild($textnode);
255
256    /* pubDate */
257    $pubDate = $xmldoc->createElement("pubDate");
258    $item->appendChild($pubDate);
259    $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch'])));
260    $pubDate->appendChild($textnode);
261
262      /* source */
263    }
264
265    echo $xmldoc->saveXML();
266} else {
267    foreach($node_results as $node_row) {
268        $node_row['num_online_users'] = $stats->getNumOnlineUsers($node_row['node_id']);
269        $smarty->append("nodes", $node_row);
270    }
271
272    $smarty->assign("title", "hotspot_status");
273    $smarty->display("templates/hotspot_status.html");
274}
275?>
Note: See TracBrowser for help on using the browser.