| 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 Statistics |
|---|
| 39 | * @author Philippe April |
|---|
| 40 | * @copyright 2005-2006 Philippe April |
|---|
| 41 | * @version Subversion $Id$ |
|---|
| 42 | * @link http://www.wifidog.org/ |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | * Load required classes |
|---|
| 47 | */ |
|---|
| 48 | require_once('classes/StatisticReport.php'); |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * General report about a user |
|---|
| 52 | * |
|---|
| 53 | * @package WiFiDogAuthServer |
|---|
| 54 | * @subpackage Statistics |
|---|
| 55 | * @author Philippe April |
|---|
| 56 | * @copyright 2005-2006 Philippe April |
|---|
| 57 | */ |
|---|
| 58 | class UserReport extends StatisticReport |
|---|
| 59 | { |
|---|
| 60 | /** Get the report's name. Must be overriden by the report class |
|---|
| 61 | * @return a localised string */ |
|---|
| 62 | public static function getReportName() |
|---|
| 63 | { |
|---|
| 64 | return _("Individual user report"); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** Constructor |
|---|
| 68 | * @param $statistics_object Mandatory to give the report it's context */ |
|---|
| 69 | protected function __construct(Statistics $statistics_object) |
|---|
| 70 | { |
|---|
| 71 | parent :: __construct($statistics_object); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** Get the actual report. |
|---|
| 75 | * Classes must override this, but must call the parent's method with what |
|---|
| 76 | * would otherwise be their return value and return that instead. |
|---|
| 77 | * @param $child_html The child method's return value |
|---|
| 78 | * @return A html fragment |
|---|
| 79 | */ |
|---|
| 80 | public function getReportUI($child_html = null) |
|---|
| 81 | { |
|---|
| 82 | |
|---|
| 83 | $db = AbstractDb::getObject(); |
|---|
| 84 | global $account_status_to_text; |
|---|
| 85 | global $token_to_text; |
|---|
| 86 | |
|---|
| 87 | // Init values |
|---|
| 88 | $html = ""; |
|---|
| 89 | $_date_from = ""; |
|---|
| 90 | $_date_to = ""; |
|---|
| 91 | |
|---|
| 92 | // Process input |
|---|
| 93 | if (isset($_REQUEST['date_from'])) { |
|---|
| 94 | $_date_from = $_REQUEST['date_from']; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | if (isset($_REQUEST['date_to'])) { |
|---|
| 98 | $_date_to = $_REQUEST['date_to']; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | $selected_users = $this->stats->getSelectedUsers(); |
|---|
| 102 | if ($selected_users) { |
|---|
| 103 | foreach ($selected_users as $user_id => $userObject) { |
|---|
| 104 | if ($userObject) { |
|---|
| 105 | $userinfo = null; |
|---|
| 106 | $user_id = $db->escapeString($user_id); |
|---|
| 107 | $sql = "SELECT * FROM users WHERE user_id='{$user_id}'"; |
|---|
| 108 | $db->execSqlUniqueRes($sql, $userinfo, false); |
|---|
| 109 | |
|---|
| 110 | if ($userinfo == null) { |
|---|
| 111 | throw new Exception(sprintf(_("User id: %s could not be found in the database"), $user_id)); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | $userinfo['account_status_description'] = $account_status_to_text[$userinfo['account_status']]; |
|---|
| 115 | |
|---|
| 116 | $html .= "<fieldset>\n"; |
|---|
| 117 | $html .= "<legend>"._("Profile")."</legend>\n"; |
|---|
| 118 | |
|---|
| 119 | $html .= "<table>\n"; |
|---|
| 120 | |
|---|
| 121 | $html .= "<tr class='odd'>\n"; |
|---|
| 122 | $html .= " <th>"._("Username").":</th>\n"; |
|---|
| 123 | $html .= " <td>".$userinfo['username']."</td>\n"; |
|---|
| 124 | $html .= "</tr>\n"; |
|---|
| 125 | |
|---|
| 126 | $html .= "<tr class='odd'>\n"; |
|---|
| 127 | $html .= " <th>"._("Email").":</th>\n"; |
|---|
| 128 | $html .= " <td>".$userinfo['email']."</td>\n"; |
|---|
| 129 | $html .= "</tr>\n"; |
|---|
| 130 | |
|---|
| 131 | $html .= "<tr>\n"; |
|---|
| 132 | $html .= " <th>"._("Network").":</th>\n"; |
|---|
| 133 | $html .= " <td><a href='?date_from={$_date_from}&date_to={$_date_to}&network_id={$userinfo['account_origin']}'>{$userinfo['account_origin']}</a></td>\n"; |
|---|
| 134 | $html .= "</tr>\n"; |
|---|
| 135 | |
|---|
| 136 | $html .= "<tr class='odd'>\n"; |
|---|
| 137 | $html .= " <th>"._("Unique ID").":</th>\n"; |
|---|
| 138 | $html .= " <td>".$userinfo['user_id']."</td>\n"; |
|---|
| 139 | $html .= "</tr>\n"; |
|---|
| 140 | |
|---|
| 141 | $html .= "<tr>\n"; |
|---|
| 142 | $html .= " <th>"._("Member since").":</th>\n"; |
|---|
| 143 | $html .= " <td>".strftime("%c", strtotime($userinfo['reg_date']))."</td>\n"; |
|---|
| 144 | $html .= "</tr>\n"; |
|---|
| 145 | |
|---|
| 146 | $html .= "<tr class='odd'>\n"; |
|---|
| 147 | $html .= " <th>"._("Account Status").":</th>\n"; |
|---|
| 148 | $html .= " <td>".$userinfo['account_status_description']."</td>\n"; |
|---|
| 149 | $html .= "</tr>\n"; |
|---|
| 150 | |
|---|
| 151 | $html .= "<tr class='odd'>\n"; |
|---|
| 152 | $html .= " <th>"._("Prefered Locale").":</th>\n"; |
|---|
| 153 | $html .= " <td>".$userinfo['prefered_locale']."</td>\n"; |
|---|
| 154 | $html .= "</tr>\n"; |
|---|
| 155 | |
|---|
| 156 | $html .= "</table>\n"; |
|---|
| 157 | $html .= "</fieldset>\n"; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /******* Connections **********/ |
|---|
| 161 | $html .= "<fieldset>\n"; |
|---|
| 162 | $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("*"); |
|---|
| 163 | $sql = "$candidate_connections_sql ORDER BY timestamp_in DESC"; |
|---|
| 164 | $db->execSql($sql, $connections, false); |
|---|
| 165 | $html .= "<legend>".sprintf(_("%d Connections"), count($connections))."</legend>\n"; |
|---|
| 166 | |
|---|
| 167 | // Variables init |
|---|
| 168 | $even = 0; |
|---|
| 169 | $total = array (); |
|---|
| 170 | $total['incoming'] = 0; |
|---|
| 171 | $total['outgoing'] = 0; |
|---|
| 172 | $total['time_spent'] = 0; |
|---|
| 173 | if (count($connections) == 0) { |
|---|
| 174 | $html .= _("No information found matching the report configuration"); |
|---|
| 175 | } else { |
|---|
| 176 | $html .= "<table class='smaller'>\n"; |
|---|
| 177 | $html .= "<thead>\n"; |
|---|
| 178 | $html .= "<tr>\n"; |
|---|
| 179 | $html .= " <th>"._("Logged in")."</th>\n"; |
|---|
| 180 | $html .= " <th>"._("Time spent")."</th>\n"; |
|---|
| 181 | $html .= " <th>"._("Token status")."</th>\n"; |
|---|
| 182 | $html .= " <th>"._("Node")."</th>\n"; |
|---|
| 183 | $html .= " <th>"._("IP")."</th>\n"; |
|---|
| 184 | $html .= " <th>"._("D")."</th>\n"; |
|---|
| 185 | $html .= " <th>"._("U")."</th>\n"; |
|---|
| 186 | $html .= "</tr>\n"; |
|---|
| 187 | $html .= "</thead>\n"; |
|---|
| 188 | |
|---|
| 189 | foreach ($connections as $connection) { |
|---|
| 190 | $timestamp_in = !empty ($connection['timestamp_in']) ? strtotime($connection['timestamp_in']) : null; |
|---|
| 191 | $timestamp_out = !empty ($connection['timestamp_out']) ? strtotime($connection['timestamp_out']) : null; |
|---|
| 192 | |
|---|
| 193 | $nodeObject = Node :: getObject($connection['node_id']); |
|---|
| 194 | $total['incoming'] += $connection['incoming']; |
|---|
| 195 | $total['outgoing'] += $connection['outgoing']; |
|---|
| 196 | |
|---|
| 197 | $connection['token_status_description'] = $token_to_text[$connection['token_status']]; |
|---|
| 198 | $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; |
|---|
| 199 | |
|---|
| 200 | if ($even == 0) { |
|---|
| 201 | $even = 1; |
|---|
| 202 | } else { |
|---|
| 203 | $even = 0; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | $html .= " <td>".strftime("%c", $timestamp_in)."</td>\n"; |
|---|
| 207 | |
|---|
| 208 | if (!empty ($timestamp_in) && !empty ($timestamp_out)) { |
|---|
| 209 | $total['time_spent'] += ($timestamp_out - $timestamp_in); |
|---|
| 210 | $html .= "<td>".Utils :: convertSecondsToWords($timestamp_out - $timestamp_in)."</td>\n"; |
|---|
| 211 | } else { |
|---|
| 212 | $html .= "<td>"._("N/A")."</td>\n"; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | $html .= " <td>".$connection['token_status']."</td>\n"; |
|---|
| 216 | $html .= " <td><a href='?date_from={$_date_from}&date_to={$_date_to}&node_id={$nodeObject->getId()}'>{$nodeObject->getName()}</a></td>\n"; |
|---|
| 217 | $html .= " <td>".$connection['user_ip']."</td>\n"; |
|---|
| 218 | $html .= " <td>".Utils :: convertBytesToWords($connection['incoming'])."</td>\n"; |
|---|
| 219 | $html .= " <td>".Utils :: convertBytesToWords($connection['outgoing'])."</td>\n"; |
|---|
| 220 | $html .= "</tr>\n"; |
|---|
| 221 | } |
|---|
| 222 | $html .= "<tr>\n"; |
|---|
| 223 | $html .= " <th>"._("Total").":</th>\n"; |
|---|
| 224 | $html .= " <th>".Utils :: convertSecondsToWords($total['time_spent'])."</th>\n"; |
|---|
| 225 | $html .= " <td></td>\n"; |
|---|
| 226 | $html .= " <td></td>\n"; |
|---|
| 227 | $html .= " <td></td>\n"; |
|---|
| 228 | |
|---|
| 229 | $html .= " <th>".Utils :: convertBytesToWords($total['incoming'])."</th>\n"; |
|---|
| 230 | $html .= " <th>".Utils :: convertBytesToWords($total['outgoing'])."</th>\n"; |
|---|
| 231 | $html .= "</tr>\n"; |
|---|
| 232 | $html .= "</table>\n"; |
|---|
| 233 | $html .= "</fieldset>\n"; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | if ($this->stats->getDistinguishUsersBy() == 'user_id') { |
|---|
| 237 | /******* MAC addresses **********/ |
|---|
| 238 | $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("user_mac,count(user_mac) as nb "); |
|---|
| 239 | |
|---|
| 240 | $sql = "$candidate_connections_sql group by user_mac order by nb desc"; |
|---|
| 241 | $db->execSql($sql, $rows, false); |
|---|
| 242 | |
|---|
| 243 | $html .= "<fieldset>\n"; |
|---|
| 244 | $html .= "<legend>".sprintf(_("%d MAC addresses"), count($rows))."</legend>\n"; |
|---|
| 245 | $html .= "<table>\n"; |
|---|
| 246 | $html .= "<thead>\n"; |
|---|
| 247 | $html .= "<tr>\n"; |
|---|
| 248 | $html .= " <th>"._("MAC")."</th>\n"; |
|---|
| 249 | $html .= " <th>"._("Count")."</th>\n"; |
|---|
| 250 | $html .= "</tr>\n"; |
|---|
| 251 | $html .= "</thead>\n"; |
|---|
| 252 | |
|---|
| 253 | $even = 0; |
|---|
| 254 | if ($rows) { |
|---|
| 255 | foreach ($rows as $row) { |
|---|
| 256 | $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; |
|---|
| 257 | |
|---|
| 258 | if ($even == 0) { |
|---|
| 259 | $even = 1; |
|---|
| 260 | } else { |
|---|
| 261 | $even = 0; |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | $html .= " <td>{$row['user_mac']}</td>\n"; |
|---|
| 265 | $html .= " <td>".$row['nb']."</td>\n"; |
|---|
| 266 | $html .= "</tr>\n"; |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | $html .= "</table>\n"; |
|---|
| 271 | $html .= "</fieldset>\n"; |
|---|
| 272 | } else { |
|---|
| 273 | /******* Usernames **********/ |
|---|
| 274 | $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("connections.user_id,username, count(connections.user_id) as nb ", true); |
|---|
| 275 | |
|---|
| 276 | $sql = "$candidate_connections_sql group by connections.user_id, username order by nb desc, connections.user_id,username"; |
|---|
| 277 | $db->execSql($sql, $rows, false); |
|---|
| 278 | |
|---|
| 279 | $html .= "<fieldset>\n"; |
|---|
| 280 | $html .= "<legend>".sprintf(_("%d users"), count($rows))."</legend>\n"; |
|---|
| 281 | $html .= "<table>\n"; |
|---|
| 282 | $html .= "<thead>\n"; |
|---|
| 283 | $html .= "<tr>\n"; |
|---|
| 284 | $html .= " <th>"._("Username")."</th>\n"; |
|---|
| 285 | $html .= " <th>"._("Count")."</th>\n"; |
|---|
| 286 | $html .= "</tr>\n"; |
|---|
| 287 | $html .= "</thead>\n"; |
|---|
| 288 | |
|---|
| 289 | $even = 0; |
|---|
| 290 | |
|---|
| 291 | if ($rows) { |
|---|
| 292 | foreach ($rows as $row) { |
|---|
| 293 | $html .= $even ? "<tr>\n" : "<tr class='odd'>\n"; |
|---|
| 294 | |
|---|
| 295 | if ($even == 0) { |
|---|
| 296 | $even = 1; |
|---|
| 297 | } else { |
|---|
| 298 | $even = 0; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | $html .= " <td>{$row['username']}</td>\n"; |
|---|
| 302 | $html .= " <td>".$row['nb']."</td>\n"; |
|---|
| 303 | $html .= "</tr>\n"; |
|---|
| 304 | } |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | $html .= "</table>\n"; |
|---|
| 308 | $html .= "</fieldset>\n"; |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | return parent :: getReportUI($html); |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | /* |
|---|
| 319 | * Local variables: |
|---|
| 320 | * tab-width: 4 |
|---|
| 321 | * c-basic-offset: 4 |
|---|
| 322 | * c-hanging-comment-ender-p: nil |
|---|
| 323 | * End: |
|---|
| 324 | */ |
|---|
| 325 | |
|---|