Changeset 753

Show
Ignore:
Timestamp:
09/13/05 23:35:35 (8 years ago)
Author:
fproulx
Message:

2005-09-13 Francois Proulx <francois.proulx@…>

  • Added access permissions for statistics.
Location:
trunk/wifidog-auth
Files:
2 removed
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r752 r753  
     12005-09-13 Francois Proulx <francois.proulx@gmail.com> 
     2        * Added access permissions for statistics. 
     3 
    142005-09-12 Benoit Grégoire  <bock@step.polymtl.ca> 
    25        * schema_validate.php:  Fix a bug version 26.  The conversion of the old account_origin as a parameter  
  • trunk/wifidog-auth/wifidog/admin/stats.php

    r734 r753  
    7373} 
    7474 
    75 $security = new Security(); 
     75$current_user = User::getCurrentUser(); 
    7676 
    7777try { 
     
    174174            $html .= "<input type='hidden' id='network_id' name='network_id' value='{$_REQUEST['network_id']}'>"; 
    175175        } 
    176  
     176         
     177        $html .= "<b>"._("Select the time range for which statistics will be computed.")."</b>"; 
    177178        $html .= "<table>"; 
    178179        $html .= "<tr>"; 
     
    204205        $html .= "</table>\n"; 
    205206 
    206         if (isset($_REQUEST['node_id'])) { 
     207        if (isset($_REQUEST['node_id']) && $current_user->isSuperAdmin()) { 
    207208            $html .= "<em>" . _("Group connections") . "?</em><br>"; 
    208209 
     
    220221        } 
    221222 
    222         $html .= "<input type='submit' value='" . _("View") . "'>"; 
     223        $html .= "<input type='submit' value='" . _("Generate statistics") . "'>"; 
    223224        $html .= "</form>"; 
    224225        $html .= "<hr>"; 
     
    227228    //$sql = "select user_mac,count(user_mac) as nb,max(timestamp_in) as last_seen,substract(timestamp_in, timestamp_out) as time_spend from connections where node_id='{$node_id}' group by user_mac order by nb desc"; 
    228229 
    229     if (isset($node_id)) { 
     230    if (isset($node_id) && ($current_user->isSuperAdmin() || $current_user->isOwner())) { 
    230231        include "stats_node.inc.php"; 
    231     } elseif (isset($user_id)) { 
     232    } elseif (isset($user_id) && $current_user->isSuperAdmin()) { 
    232233        include "stats_user_id.inc.php"; 
    233     } elseif (isset($user_mac)) { 
     234    } elseif (isset($user_mac) && $current_user->isSuperAdmin()) { 
    234235        include "stats_user_mac.inc.php"; 
    235     } elseif (isset($network_id)) { 
     236    } elseif (isset($network_id) && $current_user->isSuperAdmin()) { 
    236237        include "stats_network.inc.php"; 
    237     } else { 
     238    } else if($current_user->isSuperAdmin()) { 
    238239        include "stats_all_networks.inc.php"; 
    239240    } 
  • trunk/wifidog-auth/wifidog/admin/stats_node.inc.php

    r734 r753  
    11<?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 stats_node.inc.php 
    22    * @author Copyright (C) 2005 Philippe April 
    23    */ 
     2 
     3/********************************************************************\ 
     4 * This program is free software; you can redistribute it and/or    * 
     5 * modify it under the terms of the GNU General Public License as   * 
     6 * published by the Free Software Foundation; either version 2 of   * 
     7 * the License, or (at your option) any later version.              * 
     8 *                                                                  * 
     9 * This program is distributed in the hope that it will be useful,  * 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   * 
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    * 
     12 * GNU General Public License for more details.                     * 
     13 *                                                                  * 
     14 * You should have received a copy of the GNU General Public License* 
     15 * along with this program; if not, contact:                        * 
     16 *                                                                  * 
     17 * Free Software Foundation           Voice:  +1-617-542-5942       * 
     18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       * 
     19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
     20 *                                                                  * 
     21 \********************************************************************/ 
     22/**@file stats_node.inc.php 
     23 * @author Copyright (C) 2005 Philippe April 
     24 */ 
    2425 
    2526require_once BASEPATH."admin/graph_common.inc.php"; 
    2627 
    27 $html .= "<fieldset class='pretty_fieldset'>"; 
    28 $html .= "<legend>Profile</legend>"; 
    29 $html .= "<table>"; 
    30  
    31 $html .= "<tr class='odd'>"; 
    32 $html .= "  <th>" . _("Name") . "</th>"; 
    33 $html .= "  <td>" . $nodeObject->getName() . "</td>"; 
    34 $html .= "</tr>"; 
    35 $html .= "<tr class='even'>"; 
    36 $html .= "  <th>" . _("Node ID") . "</th>"; 
    37 $html .= "  <td>" . $nodeObject->getId() . "</td>"; 
    38 $html .= "</tr>"; 
    39 $html .= "<tr class='odd'>"; 
    40 $html .= "  <th>" . _("Deployment Status") . "</th>"; 
    41 $html .= "  <td>" . $nodeObject->getDeploymentStatus() . "</td>"; 
    42 $html .= "</tr>"; 
    43 $html .= "<tr class='even'>"; 
    44 $html .= "  <th>" . _("Deployment date") . "</th>"; 
    45 $html .= "  <td>" . $nodeObject->getCreationDate() . "</td>"; 
    46 $html .= "</tr>"; 
    47 $html .= "<tr class='odd'>"; 
    48 $html .= "  <th>" . _("Description") . "</th>"; 
    49 $html .= "  <td>" . $nodeObject->getDescription() . "</td>"; 
    50 $html .= "</tr>"; 
    51 $html .= "<tr class='even'>"; 
    52 $html .= "  <th>" . _("Network") . "</th>"; 
    53 $html .= "  <td>" . $nodeObject->getNetwork()->getName() . "</td>"; 
    54 $html .= "</tr>"; 
    55 $html .= "<tr class='odd'>"; 
    56 $html .= "  <th>" . _("GIS Location") . "</th>"; 
    57 $html .= "  <td>"; 
    58 if ($nodeObject->getGisLocation()->getLatitude() && $nodeObject->getGisLocation()->getLongitude()) { 
    59     $html .= $nodeObject->getGisLocation()->getLatitude() . " " . $nodeObject->getGisLocation()->getLongitude(); 
    60     $html .= " <input type='button' name='google_maps_geocode' value='" . _("Map") . "' onClick='window.open(\"hotspot_location_map.php?node_id={$node_id}\", \"hotspot_location\", \"toolbar=0,scrollbars=1,resizable=1,location=0,statusbar=0,menubar=0,width=600,height=600\");'>"; 
    61 } else { 
    62     $html .= _("NOT SET"); 
     28if ($current_user->isSuperAdmin() || $nodeObject->isOwner($current_user)) 
     29{ 
     30        $html .= "<fieldset class='pretty_fieldset'>"; 
     31        $html .= "<legend>Profile</legend>"; 
     32        $html .= "<table>"; 
     33 
     34        $html .= "<tr class='odd'>"; 
     35        $html .= "  <th>"._("Name")."</th>"; 
     36        $html .= "  <td>".$nodeObject->getName()."</td>"; 
     37        $html .= "</tr>"; 
     38        $html .= "<tr class='even'>"; 
     39        $html .= "  <th>"._("Node ID")."</th>"; 
     40        $html .= "  <td>".$nodeObject->getId()."</td>"; 
     41        $html .= "</tr>"; 
     42        $html .= "<tr class='odd'>"; 
     43        $html .= "  <th>"._("Deployment Status")."</th>"; 
     44        $html .= "  <td>".$nodeObject->getDeploymentStatus()."</td>"; 
     45        $html .= "</tr>"; 
     46        $html .= "<tr class='even'>"; 
     47        $html .= "  <th>"._("Deployment date")."</th>"; 
     48        $html .= "  <td>".$nodeObject->getCreationDate()."</td>"; 
     49        $html .= "</tr>"; 
     50        $html .= "<tr class='odd'>"; 
     51        $html .= "  <th>"._("Description")."</th>"; 
     52        $html .= "  <td>".$nodeObject->getDescription()."</td>"; 
     53        $html .= "</tr>"; 
     54        $html .= "<tr class='even'>"; 
     55        $html .= "  <th>"._("Network")."</th>"; 
     56        $html .= "  <td>".$nodeObject->getNetwork()->getName()."</td>"; 
     57        $html .= "</tr>"; 
     58        $html .= "<tr class='odd'>"; 
     59        $html .= "  <th>"._("GIS Location")."</th>"; 
     60        $html .= "  <td>"; 
     61        if ($nodeObject->getGisLocation()->getLatitude() && $nodeObject->getGisLocation()->getLongitude()) 
     62        { 
     63                $html .= $nodeObject->getGisLocation()->getLatitude()." ".$nodeObject->getGisLocation()->getLongitude(); 
     64                $html .= " <input type='button' name='google_maps_geocode' value='"._("Map")."' onClick='window.open(\"hotspot_location_map.php?node_id={$node_id}\", \"hotspot_location\", \"toolbar=0,scrollbars=1,resizable=1,location=0,statusbar=0,menubar=0,width=600,height=600\");'>"; 
     65        } 
     66        else 
     67        { 
     68                $html .= _("NOT SET"); 
     69        } 
     70        $html .= "  </td>"; 
     71        $html .= "</tr>"; 
     72        $html .= "<tr class='even'>"; 
     73        $html .= "  <th>"._("Homepage")."</th>"; 
     74        $html .= "  <td><a href='".$nodeObject->getHomePageURL()."'>".$nodeObject->getHomePageURL()."</a></td>"; 
     75        $html .= "</tr>"; 
     76        $html .= "<tr class='odd'>"; 
     77        $html .= "  <th>"._("Address")."</th>"; 
     78        $html .= "  <td>"; 
     79        $html .= trim($nodeObject->getCivicNumber()." ".$nodeObject->getStreetName())."<br>"; 
     80        $html .= trim($nodeObject->getCity()." ".$nodeObject->getProvince())."<br>"; 
     81        $html .= trim($nodeObject->getCountry()." ".$nodeObject->getPostalCode()); 
     82        $html .= "</td>"; 
     83        $html .= "</tr>"; 
     84        $html .= "<tr class='even'>"; 
     85        $html .= "  <th>"._("Telephone")."</th>"; 
     86        $html .= "  <td>".$nodeObject->getTelephone()."</td>"; 
     87        $html .= "</tr>"; 
     88        $html .= "<tr class='odd'>"; 
     89        $html .= "  <th>"._("Email")."</th>"; 
     90        $html .= "  <td><a href='mailto:".$nodeObject->getEmail()."'>".$nodeObject->getEmail()."</a></td>"; 
     91        $html .= "</tr>"; 
     92        $html .= "<tr class='even'>"; 
     93        $html .= "  <th>"._("Transit Info")."</th>"; 
     94        $html .= "  <td>".$nodeObject->getTransitInfo()."</td>"; 
     95        $html .= "</tr>"; 
     96        $html .= "</table>"; 
     97        $html .= "</fieldset>"; 
     98 
     99        $html .= "<fieldset class='pretty_fieldset'>"; 
     100        $html .= "<legend>Status</legend>"; 
     101        $html .= "<table>"; 
     102 
     103        $db->ExecSql("SELECT node_id, name, (NOW()-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((NOW()-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up, creation_date FROM nodes WHERE node_id = '{$node_id}'", $rows, false); 
     104 
     105        $html .= ($rows[0]['is_up'] == 't') ? "<tr class='even'>" : "<tr class='red'>"; 
     106        $html .= "  <th>"._("WifiDog status")."</th>"; 
     107        $html .= "  <td>"; 
     108        $html .= ($rows[0]['is_up'] == 't') ? "UP" : "<span class='red'>DOWN</span>"; 
     109        $html .= "</td>"; 
     110        $html .= "<tr class='odd'>"; 
     111        $html .= "  <th>"._("Last heartbeat")."</th>"; 
     112        $html .= "  <td>".seconds_in_words(time() - strtotime($nodeObject->getLastHeartbeatTimestamp()))." ago</td>"; 
     113        $html .= "</tr>"; 
     114        $html .= "</tr>"; 
     115        $html .= "<tr class='even'>"; 
     116        $html .= "  <th>"._("WifiDog version")."</th>"; 
     117        $html .= "  <td>".$nodeObject->getLastHeartbeatUserAgent()."</td>"; 
     118        $html .= "</tr>"; 
     119        $html .= "<tr class='odd'>"; 
     120        $html .= "  <th>"._("IP Address")."</th>"; 
     121        $html .= "  <td>".$nodeObject->getLastHeartbeatIP()."</td>"; 
     122        $html .= "</tr>"; 
     123        $html .= "</table>"; 
     124        $html .= "</fieldset>"; 
     125 
     126        $html .= "<fieldset class='pretty_fieldset'>"; 
     127        $html .= "<legend>Statistics</legend>"; 
     128        $html .= "<table>"; 
     129 
     130        $db->ExecSql("SELECT round(CAST( (SELECT SUM(daily_connections) FROM (SELECT COUNT(DISTINCT user_id) AS daily_connections, date_trunc('day', timestamp_in) FROM connections WHERE node_id='${node_id}' AND (incoming!=0 OR outgoing!=0) GROUP BY date_trunc('day', timestamp_in)) AS daily_connections_table) / (EXTRACT(EPOCH FROM (NOW()-(SELECT timestamp_in FROM connections WHERE node_id='${node_id}' AND (incoming!=0 OR outgoing!=0) ORDER BY timestamp_in LIMIT 1)) )/(3600*24)) AS numeric),2) AS connections_per_day", $rows, false); 
     131        $html .= "<tr class='even'>"; 
     132        $html .= "  <th>"._("Average visits per day").":</th>"; 
     133        $html .= "  <td>".$rows[0]['connections_per_day']."  </td>"; 
     134        $html .= "</tr>"; 
     135 
     136        $db->ExecSql("SELECT SUM(incoming) AS in, SUM(outgoing) AS out FROM connections WHERE node_id='{$node_id}' ${date_constraint}", $rows, false); 
     137        $html .= "<tr class='odd'>"; 
     138        $html .= "  <th>"._("Traffic").":</th>"; 
     139        $html .= "  <td>"; 
     140        $html .= _("Incoming").": ".bytes_in_words($rows[0]['in']); 
     141        $html .= "<br>"; 
     142        $html .= _("Outgoing").": ".bytes_in_words($rows[0]['out']); 
     143        $html .= "<br>"; 
     144        $html .= "(for the selected period)"; 
     145        $html .= "</td>"; 
     146 
     147        $html .= "</table>"; 
     148        $html .= "</fieldset>"; 
     149 
     150        $html .= "<fieldset class='pretty_fieldset'>"; 
     151        $html .= "<legend>"._("Connections per hour of the day")."</legend>"; 
     152        if (Dependencies :: check("ImageGraph", $errmsg)) 
     153        { 
     154                $html .= "<div><img src='graph_per_hour.php?node_id={$node_id}&date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}'></div>"; 
     155        } 
     156        else 
     157        { 
     158                $html .= $errmsg; 
     159        } 
     160        $html .= "</fieldset>"; 
     161 
     162        $html .= "<fieldset class='pretty_fieldset'>"; 
     163        $html .= "<legend>"._("Connections per week day")."</legend>"; 
     164        if (Dependencies :: check("ImageGraph", $errmsg)) 
     165        { 
     166                $html .= "<div><img src='graph_per_weekday.php?node_id={$node_id}&date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}'></div>"; 
     167        } 
     168        else 
     169        { 
     170                $html .= $errmsg; 
     171        } 
     172        $html .= "</fieldset>"; 
     173 
     174        $html .= "<fieldset class='pretty_fieldset'>"; 
     175        $html .= "<legend>"._("Connections per month")."</legend>"; 
     176        if (Dependencies :: check("ImageGraph", $errmsg)) 
     177        { 
     178                $html .= "<div><img src='graph_per_month.php?node_id={$node_id}&date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}'></div>"; 
     179        } 
     180        else 
     181        { 
     182                $html .= $errmsg; 
     183        } 
     184        $html .= "</fieldset>"; 
     185 
     186        // Only Super admin 
     187        if ($current_user->isSuperAdmin()) 
     188        { 
     189                if (isset ($_REQUEST['group_connections']) && $_REQUEST['group_connections'] == "group_connections_by_mac") 
     190                { 
     191                        $sql = "SELECT user_mac,COUNT(DISTINCT user_id) AS nb_users,COUNT(user_mac) AS nb_connections,MAX(timestamp_in) AS last_seen FROM connections WHERE node_id='{$node_id}' {$date_constraint} GROUP BY user_mac ORDER BY last_seen DESC"; 
     192                        $db->ExecSql($sql, $rows, false); 
     193 
     194                        $number_of_macs = count($rows); 
     195 
     196                        $html .= "<fieldset class='pretty_fieldset'>"; 
     197                        $html .= "<legend>Number of unique MACs: {$number_of_macs}</legend>"; 
     198                        $html .= "<table>"; 
     199                        $html .= "<thead>"; 
     200                        $html .= "<tr>"; 
     201                        $html .= "<th>MAC</th>"; 
     202                        $html .= "<th>Users count</th>"; 
     203                        $html .= "<th>Cx count</th>"; 
     204                        $html .= "<th>Last seen</th>"; 
     205                        $html .= "</tr>"; 
     206                        $html .= "</thead>"; 
     207 
     208                        foreach ($rows as $row) 
     209                        { 
     210                                $html .= "<tr>\n"; 
     211                                $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_mac={$row['user_mac']}'>{$row['user_mac']}</a></td>\n"; 
     212                                $html .= "  <td>".$row['nb_users']."</td>\n"; 
     213                                $html .= "  <td>".$row['nb_connections']."</td>\n"; 
     214                                $html .= "  <td>".strftime("%Y-%m-%d %H:%M:%S", strtotime($row['last_seen']))."</td>\n"; 
     215                                $html .= "</tr>\n"; 
     216                        } 
     217 
     218                        $html .= "</table>"; 
     219                        $html .= "</fieldset>"; 
     220 
     221                } 
     222                elseif (isset ($_REQUEST['group_connections']) && $_REQUEST['group_connections'] == "group_connections_by_user") 
     223                { 
     224                        $sql = "select distinct(connections.user_id),count(distinct user_mac) as nb_mac,username,count(connections.user_id) as nb_cx,max(timestamp_in) as last_seen from connections,users where users.user_id=connections.user_id and node_id='{$node_id}' {$date_constraint} group by connections.user_id,username order by nb_cx desc,username"; 
     225                        $db->ExecSql($sql, $rows, false); 
     226 
     227                        $number_of_usernames = count($rows); 
     228 
     229                        $html .= "<fieldset class='pretty_fieldset'>"; 
     230                        $html .= "<legend>Number of unique Usernames: {$number_of_usernames}</legend>"; 
     231                        $html .= "<table>"; 
     232                        $html .= "<thead>"; 
     233                        $html .= "<tr>"; 
     234                        $html .= "<th>Username</th>"; 
     235                        $html .= "<th>MAC Count</th>"; 
     236                        $html .= "<th>Cx Count</th>"; 
     237                        $html .= "<th>Last seen</th>"; 
     238                        $html .= "</tr>"; 
     239                        $html .= "</thead>"; 
     240 
     241                        foreach ($rows as $row) 
     242                        { 
     243                                $html .= "<tr>\n"; 
     244                                $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_id={$row['user_id']}'>{$row['username']}</a></td>\n"; 
     245                                $html .= "  <td>".$row['nb_mac']."</td>\n"; 
     246                                $html .= "  <td>".$row['nb_cx']."</td>\n"; 
     247                                $html .= "  <td>".strftime("%Y-%m-%d %H:%M:%S", strtotime($row['last_seen']))."</td>\n"; 
     248                                $html .= "</tr>\n"; 
     249                        } 
     250 
     251                        $html .= "</table>"; 
     252                        $html .= "</fieldset>"; 
     253 
     254                } 
     255                else 
     256                { 
     257                        $sql = "select *,users.username from connections,users where users.user_id=connections.user_id and node_id='{$node_id}' {$date_constraint} order by timestamp_in desc"; 
     258                        $db->ExecSql($sql, $rows, false); 
     259 
     260                        $number_of_connections = count($rows); 
     261 
     262                        $html .= "<fieldset class='pretty_fieldset'>"; 
     263                        $html .= "<legend>Number of non-unique connections: {$number_of_connections}</legend>"; 
     264                        $html .= "<table>"; 
     265                        $html .= "<thead>"; 
     266                        $html .= "<tr>"; 
     267                        $html .= "<th>Username</th>"; 
     268                        $html .= "<th>MAC</th>"; 
     269                        $html .= "<th>Date</th>"; 
     270                        $html .= "<th>Time spent</th>"; 
     271                        $html .= "</tr>"; 
     272                        $html .= "</thead>"; 
     273 
     274                        $even = 0; 
     275                        if ($rows) 
     276                        { 
     277                                foreach ($rows as $row) 
     278                                { 
     279                                        if ($row['timestamp_in']) 
     280                                                $timestamp_in = strtotime($row['timestamp_in']); 
     281                                        else 
     282                                                $timestamp_in = -1; 
     283 
     284                                        if ($row['timestamp_out']) 
     285                                                $timestamp_out = strtotime($row['timestamp_out']); 
     286                                        else 
     287                                                $timestamp_out = -1; 
     288 
     289                                        if ($timestamp_in != -1 && $timestamp_out != -1) 
     290                                        { 
     291                                                $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; 
     292                                                if ($even == 0) 
     293                                                        $even = 1; 
     294                                                else 
     295                                                        $even = 0; 
     296                                                $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_id={$row['user_id']}'>{$row['username']}</a></td>\n"; 
     297                                                $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_mac={$row['user_mac']}'>{$row['user_mac']}</a></td>\n"; 
     298                                                $html .= "  <td>".utf8_encode(strftime("%c", strtotime($row['timestamp_in'])))."</td>\n"; 
     299                                                $html .= "  <td>"; 
     300                                                if ($timestamp_in != -1 && $timestamp_out != -1) 
     301                                                { 
     302                                                        $html .= seconds_in_words($timestamp_out - $timestamp_in); 
     303                                                } 
     304                                                $html .= "</td>\n"; 
     305                                                $html .= "</tr>\n"; 
     306                                        } 
     307                                } 
     308                        } 
     309 
     310                        $html .= "</table>\n"; 
     311                        $html .= "</fieldset>\n"; 
     312 
     313                        /* Users who signed up here */ 
     314                        $sql = "select connections.user_id,users.username,users.reg_date FROM connections,nodes,users where timestamp_in IN (SELECT MIN(timestamp_in) as first_connection FROM connections GROUP BY user_id) ${date_constraint} AND users.user_id=connections.user_id AND connections.node_id='{$node_id}' AND nodes.node_id='{$node_id}' AND reg_date >= creation_date ORDER BY reg_date DESC"; 
     315                        $db->ExecSql($sql, $rows, false); 
     316 
     317                        $html .= "<fieldset class='pretty_fieldset'>"; 
     318                        $html .= "<legend>"._("Users who signed up here")."</legend>"; 
     319                        $html .= "<table>"; 
     320                        $html .= "<thead>"; 
     321                        $html .= "<tr>"; 
     322                        $html .= "<th>"._("Username")."</th>"; 
     323                        $html .= "<th>"._("Registration date")."</th>"; 
     324                        $html .= "</tr>"; 
     325                        $html .= "</thead>"; 
     326 
     327                        $even = 0; 
     328                        $total = 0; 
     329                        if ($rows) 
     330                        { 
     331                                foreach ($rows as $row) 
     332                                { 
     333                                        $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; 
     334                                        if ($even == 0) 
     335                                                $even = 1; 
     336                                        else 
     337                                                $even = 0; 
     338 
     339                                        $total ++; 
     340 
     341                                        $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_id={$row['user_id']}'>{$row['username']}</a></td>\n"; 
     342                                        $html .= "  <td>".utf8_encode(strftime("%c", strtotime($row['reg_date'])))."</td>\n"; 
     343                                        $html .= "</tr>\n"; 
     344                                } 
     345                        } 
     346 
     347                        $html .= "<tr>\n"; 
     348                        $html .= "  <th>"._("Total").":</th>\n"; 
     349                        $html .= "  <th>".$total."</th>\n"; 
     350                        $html .= "</tr>\n"; 
     351                        $html .= "</table>\n"; 
     352                        $html .= "</fieldset>\n"; 
     353                } 
     354        } 
    63355} 
    64 $html .= "  </td>"; 
    65 $html .= "</tr>"; 
    66 $html .= "<tr class='even'>"; 
    67 $html .= "  <th>" . _("Homepage") . "</th>"; 
    68 $html .= "  <td><a href='" . $nodeObject->getHomePageURL() . "'>" . $nodeObject->getHomePageURL() . "</a></td>"; 
    69 $html .= "</tr>"; 
    70 $html .= "<tr class='odd'>"; 
    71 $html .= "  <th>" . _("Address") . "</th>"; 
    72 $html .= "  <td>"; 
    73 $html .= trim($nodeObject->getCivicNumber() . " " . $nodeObject->getStreetName()) . "<br>"; 
    74 $html .= trim($nodeObject->getCity() . " " . $nodeObject->getProvince()) . "<br>"; 
    75 $html .= trim($nodeObject->getCountry() . " " . $nodeObject->getPostalCode()); 
    76 $html .= "</td>"; 
    77 $html .= "</tr>"; 
    78 $html .= "<tr class='even'>"; 
    79 $html .= "  <th>" . _("Telephone") . "</th>"; 
    80 $html .= "  <td>" . $nodeObject->getTelephone() . "</td>"; 
    81 $html .= "</tr>"; 
    82 $html .= "<tr class='odd'>"; 
    83 $html .= "  <th>" . _("Email") . "</th>"; 
    84 $html .= "  <td><a href='mailto:" . $nodeObject->getEmail() . "'>" . $nodeObject->getEmail() . "</a></td>"; 
    85 $html .= "</tr>"; 
    86 $html .= "<tr class='even'>"; 
    87 $html .= "  <th>" . _("Transit Info") . "</th>"; 
    88 $html .= "  <td>" . $nodeObject->getTransitInfo() . "</td>"; 
    89 $html .= "</tr>"; 
    90 $html .= "</table>"; 
    91 $html .= "</fieldset>"; 
    92  
    93 $html .= "<fieldset class='pretty_fieldset'>"; 
    94 $html .= "<legend>Status</legend>"; 
    95 $html .= "<table>"; 
    96  
    97 $db->ExecSql("SELECT node_id, name, (NOW()-last_heartbeat_timestamp) AS since_last_heartbeat, last_heartbeat_ip, CASE WHEN ((NOW()-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up, creation_date FROM nodes WHERE node_id = '{$node_id}'", $rows, false); 
    98  
    99 $html .= ($rows[0]['is_up'] == 't') ? "<tr class='even'>" : "<tr class='red'>"; 
    100 $html .= "  <th>" . _("WifiDog status") . "</th>"; 
    101 $html .= "  <td>"; 
    102 $html .= ($rows[0]['is_up'] == 't') ? "UP" : "<span class='red'>DOWN</span>"; 
    103 $html .= "</td>"; 
    104 $html .= "<tr class='odd'>"; 
    105 $html .= "  <th>" . _("Last heartbeat") . "</th>"; 
    106 $html .= "  <td>" . seconds_in_words(time() - strtotime($nodeObject->getLastHeartbeatTimestamp())) . " ago</td>"; 
    107 $html .= "</tr>"; 
    108 $html .= "</tr>"; 
    109 $html .= "<tr class='even'>"; 
    110 $html .= "  <th>" . _("WifiDog version") . "</th>"; 
    111 $html .= "  <td>" . $nodeObject->getLastHeartbeatUserAgent() . "</td>"; 
    112 $html .= "</tr>"; 
    113 $html .= "<tr class='odd'>"; 
    114 $html .= "  <th>" . _("IP Address") . "</th>"; 
    115 $html .= "  <td>" . $nodeObject->getLastHeartbeatIP() . "</td>"; 
    116 $html .= "</tr>"; 
    117 $html .= "</table>"; 
    118 $html .= "</fieldset>"; 
    119  
    120 $html .= "<fieldset class='pretty_fieldset'>"; 
    121 $html .= "<legend>Statistics</legend>"; 
    122 $html .= "<table>"; 
    123  
    124 $db->ExecSql("SELECT round(CAST( (SELECT SUM(daily_connections) FROM (SELECT COUNT(DISTINCT user_id) AS daily_connections, date_trunc('day', timestamp_in) FROM connections WHERE node_id='${node_id}' AND (incoming!=0 OR outgoing!=0) GROUP BY date_trunc('day', timestamp_in)) AS daily_connections_table) / (EXTRACT(EPOCH FROM (NOW()-(SELECT timestamp_in FROM connections WHERE node_id='${node_id}' AND (incoming!=0 OR outgoing!=0) ORDER BY timestamp_in LIMIT 1)) )/(3600*24)) AS numeric),2) AS connections_per_day", $rows, false); 
    125 $html .= "<tr class='even'>"; 
    126 $html .= "  <th>" . _("Average visits per day") . ":</th>"; 
    127 $html .= "  <td>" . $rows[0]['connections_per_day'] . "  </td>"; 
    128 $html .= "</tr>"; 
    129  
    130 $db->ExecSql("SELECT SUM(incoming) AS in, SUM(outgoing) AS out FROM connections WHERE node_id='{$node_id}' ${date_constraint}", $rows, false); 
    131 $html .= "<tr class='odd'>"; 
    132 $html .= "  <th>" . _("Traffic") . ":</th>"; 
    133 $html .= "  <td>"; 
    134 $html .= _("Incoming") . ": " .  bytes_in_words($rows[0]['in']); 
    135 $html .= "<br>"; 
    136 $html .= _("Outgoing") . ": " .  bytes_in_words($rows[0]['out']); 
    137 $html .= "<br>"; 
    138 $html .= "(for the selected period)"; 
    139 $html .= "</td>"; 
    140  
    141 $html .= "</table>"; 
    142 $html .= "</fieldset>"; 
    143  
    144 $html .= "<fieldset class='pretty_fieldset'>"; 
    145 $html .= "<legend>" . _("Connections per hour of the day") . "</legend>"; 
    146 if (Dependencies::check("ImageGraph", $errmsg)) { 
    147     $html .= "<div><img src='graph_per_hour.php?node_id={$node_id}&date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}'></div>"; 
    148 } else { 
    149     $html .= $errmsg; 
    150 } 
    151 $html .= "</fieldset>"; 
    152  
    153 $html .= "<fieldset class='pretty_fieldset'>"; 
    154 $html .= "<legend>" . _("Connections per week day") . "</legend>"; 
    155 if (Dependencies::check("ImageGraph", $errmsg)) { 
    156     $html .= "<div><img src='graph_per_weekday.php?node_id={$node_id}&date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}'></div>"; 
    157 } else { 
    158     $html .= $errmsg; 
    159 } 
    160 $html .= "</fieldset>"; 
    161  
    162 $html .= "<fieldset class='pretty_fieldset'>"; 
    163 $html .= "<legend>" . _("Connections per month") . "</legend>"; 
    164 if (Dependencies::check("ImageGraph", $errmsg)) { 
    165     $html .= "<div><img src='graph_per_month.php?node_id={$node_id}&date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}'></div>"; 
    166 } else { 
    167     $html .= $errmsg; 
    168 } 
    169 $html .= "</fieldset>"; 
    170  
    171 if (isset($_REQUEST['group_connections']) && $_REQUEST['group_connections'] == "group_connections_by_mac") { 
    172     $sql = "SELECT user_mac,COUNT(DISTINCT user_id) AS nb_users,COUNT(user_mac) AS nb_connections,MAX(timestamp_in) AS last_seen FROM connections WHERE node_id='{$node_id}' {$date_constraint} GROUP BY user_mac ORDER BY last_seen DESC"; 
    173     $db->ExecSql($sql, $rows, false); 
    174  
    175     $number_of_macs = count($rows); 
    176  
    177     $html .= "<fieldset class='pretty_fieldset'>"; 
    178     $html .= "<legend>Number of unique MACs: {$number_of_macs}</legend>"; 
    179     $html .= "<table>"; 
    180     $html .= "<thead>"; 
    181     $html .= "<tr>"; 
    182     $html .= "<th>MAC</th>"; 
    183     $html .= "<th>Users count</th>"; 
    184     $html .= "<th>Cx count</th>"; 
    185     $html .= "<th>Last seen</th>"; 
    186     $html .= "</tr>"; 
    187     $html .= "</thead>"; 
    188  
    189     foreach ($rows as $row) { 
    190         $html .= "<tr>\n"; 
    191         $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_mac={$row['user_mac']}'>{$row['user_mac']}</a></td>\n"; 
    192         $html .= "  <td>" . $row['nb_users'] . "</td>\n"; 
    193         $html .= "  <td>" . $row['nb_connections'] . "</td>\n"; 
    194         $html .= "  <td>" . strftime("%Y-%m-%d %H:%M:%S", strtotime($row['last_seen'])) . "</td>\n"; 
    195         $html .= "</tr>\n"; 
    196     } 
    197  
    198     $html .= "</table>"; 
    199     $html .= "</fieldset>"; 
    200  
    201 } elseif (isset($_REQUEST['group_connections']) && $_REQUEST['group_connections'] == "group_connections_by_user") { 
    202     $sql = "select distinct(connections.user_id),count(distinct user_mac) as nb_mac,username,count(connections.user_id) as nb_cx,max(timestamp_in) as last_seen from connections,users where users.user_id=connections.user_id and node_id='{$node_id}' {$date_constraint} group by connections.user_id,username order by nb_cx desc,username"; 
    203     $db->ExecSql($sql, $rows, false); 
    204  
    205     $number_of_usernames = count($rows); 
    206  
    207     $html .= "<fieldset class='pretty_fieldset'>"; 
    208     $html .= "<legend>Number of unique Usernames: {$number_of_usernames}</legend>"; 
    209     $html .= "<table>"; 
    210     $html .= "<thead>"; 
    211     $html .= "<tr>"; 
    212     $html .= "<th>Username</th>"; 
    213     $html .= "<th>MAC Count</th>"; 
    214     $html .= "<th>Cx Count</th>"; 
    215     $html .= "<th>Last seen</th>"; 
    216     $html .= "</tr>"; 
    217     $html .= "</thead>"; 
    218  
    219     foreach ($rows as $row) { 
    220         $html .= "<tr>\n"; 
    221         $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_id={$row['user_id']}'>{$row['username']}</a></td>\n"; 
    222         $html .= "  <td>" . $row['nb_mac'] . "</td>\n"; 
    223         $html .= "  <td>" . $row['nb_cx'] . "</td>\n"; 
    224         $html .= "  <td>" . strftime("%Y-%m-%d %H:%M:%S", strtotime($row['last_seen'])) . "</td>\n"; 
    225         $html .= "</tr>\n"; 
    226     } 
    227  
    228     $html .= "</table>"; 
    229     $html .= "</fieldset>"; 
    230  
    231 } else { 
    232     $sql = "select *,users.username from connections,users where users.user_id=connections.user_id and node_id='{$node_id}' {$date_constraint} order by timestamp_in desc"; 
    233     $db->ExecSql($sql, $rows, false); 
    234  
    235     $number_of_connections = count($rows); 
    236  
    237     $html .= "<fieldset class='pretty_fieldset'>"; 
    238     $html .= "<legend>Number of non-unique connections: {$number_of_connections}</legend>"; 
    239     $html .= "<table>"; 
    240     $html .= "<thead>"; 
    241     $html .= "<tr>"; 
    242     $html .= "<th>Username</th>"; 
    243     $html .= "<th>MAC</th>"; 
    244     $html .= "<th>Date</th>"; 
    245     $html .= "<th>Time spent</th>"; 
    246     $html .= "</tr>"; 
    247     $html .= "</thead>"; 
    248  
    249     $even = 0; 
    250     if ($rows) { 
    251         foreach ($rows as $row) { 
    252             if ($row['timestamp_in']) 
    253                 $timestamp_in = strtotime($row['timestamp_in']); 
    254             else 
    255                 $timestamp_in = -1; 
    256  
    257             if ($row['timestamp_out']) 
    258                 $timestamp_out = strtotime($row['timestamp_out']); 
    259             else 
    260                 $timestamp_out = -1; 
    261  
    262             if ($timestamp_in != -1 && $timestamp_out != -1) { 
    263                 $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; 
    264                 if ($even == 0) 
    265                     $even = 1; 
    266                 else 
    267                     $even = 0; 
    268                 $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_id={$row['user_id']}'>{$row['username']}</a></td>\n"; 
    269                 $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_mac={$row['user_mac']}'>{$row['user_mac']}</a></td>\n"; 
    270                 $html .= "  <td>" . utf8_encode(strftime("%c", strtotime($row['timestamp_in']))) . "</td>\n"; 
    271                 $html .= "  <td>"; 
    272                 if ($timestamp_in != -1 && $timestamp_out != -1) { 
    273                     $html .= seconds_in_words($timestamp_out - $timestamp_in); 
    274                 } 
    275                 $html .= "</td>\n"; 
    276                 $html .= "</tr>\n"; 
    277             } 
    278         } 
    279     } 
    280  
    281     $html .= "</table>\n"; 
    282     $html .= "</fieldset>\n"; 
    283  
    284  
    285     /* Users who signed up here */ 
    286     $sql = "select connections.user_id,users.username,users.reg_date FROM connections,nodes,users where timestamp_in IN (SELECT MIN(timestamp_in) as first_connection FROM connections GROUP BY user_id) ${date_constraint} AND users.user_id=connections.user_id AND connections.node_id='{$node_id}' AND nodes.node_id='{$node_id}' AND reg_date >= creation_date ORDER BY reg_date DESC"; 
    287     $db->ExecSql($sql, $rows, false); 
    288  
    289     $html .= "<fieldset class='pretty_fieldset'>"; 
    290     $html .= "<legend>" . _("Users who signed up here") . "</legend>"; 
    291     $html .= "<table>"; 
    292     $html .= "<thead>"; 
    293     $html .= "<tr>"; 
    294     $html .= "<th>" . _("Username") . "</th>"; 
    295     $html .= "<th>" . _("Registration date") . "</th>"; 
    296     $html .= "</tr>"; 
    297     $html .= "</thead>"; 
    298  
    299     $even = 0; 
    300     $total = 0; 
    301     if ($rows) { 
    302         foreach ($rows as $row) { 
    303             $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; 
    304             if ($even == 0) 
    305                 $even = 1; 
    306             else 
    307                 $even = 0; 
    308              
    309             $total++; 
    310  
    311             $html .= "  <td><a href='?date_from={$_REQUEST['date_from']}&date_to={$_REQUEST['date_to']}&user_id={$row['user_id']}'>{$row['username']}</a></td>\n"; 
    312             $html .= "  <td>" . utf8_encode(strftime("%c", strtotime($row['reg_date']))) . "</td>\n"; 
    313             $html .= "</tr>\n"; 
    314         } 
    315     } 
    316  
    317     $html .= "<tr>\n"; 
    318     $html .= "  <th>" . _("Total") . ":</th>\n"; 
    319     $html .= "  <th>" . $total . "</th>\n"; 
    320     $html .= "</tr>\n"; 
    321     $html .= "</table>\n"; 
    322     $html .= "</fieldset>\n"; 
    323 } 
    324  
    325  
    326356?> 
  • trunk/wifidog-auth/wifidog/classes/Dependencies.php

    r751 r753  
    3535                if (isset ($components[$component])) 
    3636                { 
    37                         // Since file_exists does not take in account the include_path 
    38                         // Explode paths of include path 
    39                         $path_array = explode( PATH_SEPARATOR, get_include_path()); 
    4037                        $component_info = $components[$component]; 
    41                          
    42                         // For each path or the include path, check if the file exists 
    43                         foreach($path_array as $path) 
    44                                 if (file_exists ($path."/".$component_info["file"])) 
    45                                         return true; 
    46                                          
    47                         // Otherwise, the requirement is not met 
    48                         $errmsg = $component_info["name"]._(" is not installed"); 
    49                         return false; 
     38                        if(@include_once($component_info["file"])) 
     39                                return true; 
     40                        else 
     41                        { 
     42                                // Otherwise, the requirement is not met 
     43                                $errmsg = $component_info["name"]._(" is not installed"); 
     44                                return false; 
     45                        } 
    5046                } 
    5147                else 
  • trunk/wifidog-auth/wifidog/classes/MainUI.php

    r745 r753  
    145145                                                $html .= "</div>\n"; 
    146146                                                $html .= '</form>'; 
    147                                                 $html .= "<div class='admin_section_tools'>\n"; 
    148                                                 $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 
    149                                                 $html .= "<input type='hidden' name='action' value='new_ui'>\n"; 
    150                                                 $html .= "<input type='hidden' name='object_class' value='Node'><br>\n"; 
    151                                                 $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n"; 
    152                                                 $html .= "</form>\n"; 
    153                                                 $html .= "</div>\n"; 
     147                                                 
     148                                                if($current_user->isSuperAdmin()) 
     149                                                { 
     150                                                        $html .= "<div class='admin_section_tools'>\n"; 
     151                                                        $html .= '<form action="'.GENERIC_OBJECT_ADMIN_ABS_HREF.'" method="post">'; 
     152                                                        $html .= "<input type='hidden' name='action' value='new_ui'>\n"; 
     153                                                        $html .= "<input type='hidden' name='object_class' value='Node'><br>\n"; 
     154                                                        $html .= "<input type=submit name='new_submit' value='"._("Create")."'>\n"; 
     155                                                        $html .= "</form>\n"; 
     156                                                        $html .= "</div>\n"; 
     157                                                } 
     158                                                 
    154159                                                $html .= "</div>\n"; 
    155160                                        } 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r745 r753  
    642642                $html .= "<div class='admin_class'>Node (".get_class($this)." instance)</div>\n"; 
    643643                $html .= "<h3>"._("Edit a hotspot")."</h3>\n"; 
     644                 
     645                // Display stats 
     646                $html .= "<div class='admin_section_container'>\n"; 
     647                $html .= "<div class='admin_section_title'>"._("Statistics:")."</div>\n"; 
     648                $html .= "<div class='admin_section_data'>\n"; 
     649                $name = "node_".$this->id."_get_stats"; 
     650                $html .= "<input type='submit' name='$name' value='"._("Get access statistics")."'>"; 
     651                $html .= "</div>\n"; 
     652                $html .= "</div>\n"; 
    644653 
    645654                // Information about the node 
     
    942951                $html .= "</li>\n"; 
    943952                $html .= "</ul>\n"; 
    944                 $html .= "</div>\n"; 
    945                 $html .= "</div>\n"; 
    946  
    947                 // Display stats 
    948                 $html .= "<div class='admin_section_container'>\n"; 
    949                 $html .= "<div class='admin_section_title'>"._("Statistics:")."</div>\n"; 
    950                 $html .= "<div class='admin_section_data'>\n"; 
    951                 $name = "node_".$this->id."_get_stats"; 
    952                 $html .= "<input type='submit' name='$name' value='"._("Get access statistics")."'>"; 
    953953                $html .= "</div>\n"; 
    954954                $html .= "</div>\n"; 
  • trunk/wifidog-auth/wifidog/local_content/default/stylesheet.css

    r743 r753  
    187187display: none; 
    188188} 
    189 .admin_section_container { display: block; 
    190 border: 1px solid #DDDDFF; /*light blue*/ 
    191 background-color:       #FBFBFF;/*lighter blue*/ 
    192 margin: 5px; 
    193 width:auto;  
     189.admin_section_container {  
     190        display: block; 
     191        border: 1px solid #DDDDFF;  
     192        background-color: #FBFBFF; 
     193        margin: 5px; 
     194        width:auto;  
    194195} 
    195196#NodeSelector select { 
     
    198199.admin_section_title { display: inline; 
    199200                                                font-weight: bold;  } 
    200 .admin_section_data { display: inline;} 
     201.admin_section_data {  
     202        display: inline; 
     203} 
    201204.admin_section_tools { display: inline;} 
    202205 
  • trunk/wifidog-auth/wifidog/templates/hotspot_status.html

    r710 r753  
    1  
    21<div id="hotspot_status"> 
    32<table> 
     
    5453    <td> 
    5554    {if $nodes[node].civic_number}{$nodes[node].civic_number}, {/if} 
    56     {if $nodes[node].street_name}{$nodes[node].street_name}, {/if} 
     55    {if $nodes[node].street_name}{$nodes[node].street_name}{/if} 
     56    <br/> 
    5757    {if $nodes[node].city}{$nodes[node].city}, {/if} 
    5858    {if $nodes[node].province}{$nodes[node].province}, {/if}