Changeset 1262
- Timestamp:
- 07/21/07 02:40:43 (5 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 3 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/classes/AbstractDb.php (modified) (1 diff)
-
wifidog/classes/StatisticReport/AnonymisedDataExport.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1261 r1262 1 1 # $Id$ 2 2 2007-07-21 Benoit Grégoire <bock@step.polymtl.ca> 3 * AnonymisedDataExport.php: Work around the huge memory requirements this report used to have. 4 3 5 2007-07-20 Benoit Grégoire <bock@step.polymtl.ca> 4 6 * At long last, implement #9: Automatic new node creation. When attempting to login from an unknown node, the user (if he has the permissions) will be prompted to create the node, or "steal" en existing one (for hardware swaps). -
trunk/wifidog-auth/wifidog/classes/AbstractDb.php
r1249 r1262 192 192 } 193 193 194 /** 195 * Execute an SQL query and returns the RAW postgresql result handle or throws an error 196 * This is NOT for general use, as it breaks abstraction 197 * @param $sql SQL query to execute 198 * @param $resultSet The postgresql result handle 199 * @param $debug When set to true the function will spit out debug informations 200 * @return TRUE indicated the query went fine, FALSE something went wrong 201 */ 202 function execSqlRaw($sql, & $resultSet, $debug = false) 203 { 204 // Get a connection handle 205 $connection = $this->connect(NULL); 206 207 // In debug mode spit out the SQL query 208 if ($debug == TRUE) 209 { 210 // Header 211 echo "<hr/><p/>execSql() : "._("SQL Query")."<br/>\n<pre>{$sql}</pre></p>\n"; 212 213 // Prepend EXPLAIN statement to the SQL query 214 $result = @pg_query($connection, "EXPLAIN ".$sql); 215 if($result) { 216 echo "<p>"._("Query plan")." :<br/>\n"; 217 $plan_array = pg_fetch_all($result); 218 219 foreach ($plan_array as $plan_line) 220 echo $plan_line['QUERY PLAN']."<br/>\n"; 221 echo "</p>\n"; 222 } 223 224 } 225 226 // Start the clockwatch 227 $sql_starttime = microtime(); 228 $result = @pg_query($connection, $sql); 229 $sql_endtime = microtime(); 230 231 $sql_timetaken = $this->logQueries($sql, 'SELECT', $sql_starttime, $sql_endtime); 232 233 if ($debug == TRUE) 234 echo "<p>".sprintf(_("Elapsed time for query execution : %.6f second(s)"), $sql_timetaken)."</p>\n"; 235 236 if ($result == FALSE) 237 { 238 echo "<p>execSql() : "._("An error occured while executing the following SQL query")." :<br>{$sql}</p>"; 239 echo "<p>"._("Error message")." : <br/>".pg_last_error($connection)."</p>"; 240 echo "<p>"._("Backtrace:")."</p>"; 241 echo "<pre>"; 242 $btArray = debug_backtrace(); 243 foreach($btArray as $index=>$bt) { 244 printf("#%d %s(%d): %s%s%s()\n", $index, $bt['file'], $bt['line'], $bt['class'], $bt['type'], $bt['function']); 245 } 246 echo "</pre>"; 247 $resultSet = NULL; 248 $return_value = FALSE; 249 } 250 else 251 if (pg_num_rows($result) == 0) 252 { 253 $resultSet = NULL; 254 $return_value = TRUE; 255 } 256 else 257 { 258 $resultSet = $result; 259 $return_value = TRUE; 260 } 261 return $return_value; 262 } 263 194 264 /* Logs a sql query for profiling purposes */ 195 265 function logQueries($sql, $type, $sql_starttime, $sql_endtime) -
trunk/wifidog-auth/wifidog/classes/StatisticReport/AnonymisedDataExport.php
r1249 r1262 99 99 else 100 100 { 101 header('Content-Type: application/octet-stream'); 102 header('Content-Disposition: inline; filename="anonymised_data.sql"'); 103 header("Content-Transfer-Encoding: binary"); 104 101 105 $html .= <<<EOT 102 106 CREATE TABLE connections_anonymised … … 113 117 EOT; 114 118 $html .= "\n"; 119 echo $html; 115 120 $distinguish_users_by = $this->stats->getDistinguishUsersBy(); 116 121 … … 118 123 119 124 $sql = "$candidate_connections_sql ORDER BY timestamp_in DESC"; 120 $db->execSql($sql, $rows, false); 121 foreach ($rows as $row) 122 { 123 $keys = null; 124 $values = null; 125 $first = true; 126 foreach ($row as $key=>$value) 125 $db->execSqlRaw($sql, $resultHandle, false); 126 if($resultHandle) { 127 while($row=pg_fetch_array($resultHandle,null,PGSQL_ASSOC)) 127 128 { 128 if($key == 'user_id' || $key == 'node_id' || $key == 'conn_id' || $key == 'user_mac' ) { 129 $value = "'".$this->getNonRepeatableHash($value)."'"; 129 130 $keys = null; 131 $values = null; 132 $first = true; 133 foreach ($row as $key=>$value) 134 { 135 if($key == 'user_id' || $key == 'node_id' || $key == 'conn_id' || $key == 'user_mac' ) { 136 $value = "'".$this->getNonRepeatableHash($value)."'"; 137 } 138 else if ($key == 'timestamp_out' && empty ($value)) { 139 $value = 'NULL'; 140 } 141 else { 142 $value = "'$value'"; 143 } 144 if(!$first) { 145 $keys .= ', '; 146 $values .= ', '; 147 } 148 else { 149 $first = false; 150 } 151 $keys .= $key; 152 $values .= $value; 130 153 } 131 else if ($key == 'timestamp_out' && empty ($value)) { 132 $value = 'NULL'; 133 } 134 else { 135 $value = "'$value'"; 136 } 137 if(!$first) { 138 $keys .= ', '; 139 $values .= ', '; 140 } 141 else { 142 $first = false; 143 } 144 $keys .= $key; 145 $values .= $value; 154 //fwrite($temp, "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"); 155 echo "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"; 146 156 } 147 $html .= "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n";148 //$html .= "<br/>\n";149 157 } 158 exit; 150 159 } 151 header('Content-Type: text/plain'); 152 header('Content-Disposition: inline; filename="anonymised_data.sql"'); 153 header("Content-Transfer-Encoding: binary"); 154 echo $html; 155 exit; 160 return $html; 156 161 } 157 162
