| 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"); |
| | 28 | if ($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 | } |
| 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 | | |