Show
Ignore:
Timestamp:
02/25/10 15:56:33 (2 years ago)
Author:
gbastien
Message:
  • Added possibility to have a deployed geolocated node not show on map (quick fix) (#706)
  • When producing anonymised data export, two files are produced, one for the geolocated nodes and one for the connections (#705)
  • Additions and bug fixes to web service: can now logout and auth returns both error code and message
  • Starting work on #707 as needed
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/StatisticReport/AnonymisedDataExport.php

    r1421 r1453  
    9999        else 
    100100        { 
    101             header('Content-Type: application/octet-stream'); 
    102             header('Content-Disposition: inline; filename="anonymised_data.sql"'); 
    103             header("Content-Transfer-Encoding: binary"); 
    104  
    105             $html  .= <<<EOT 
    106             CREATE TABLE connections_anonymised 
    107             ( 
    108             conn_id text NOT NULL, 
    109             timestamp_in timestamp, 
    110             node_id text, 
    111             timestamp_out timestamp, 
    112             user_id text NOT NULL DEFAULT '', 
    113             user_mac text, 
    114             incoming int8, 
    115             outgoing int8 
    116             ); 
     101            /** Starting   sql file with geolocation data */ 
     102            $tmpdir = sys_get_temp_dir(); 
     103            $nodefile = tempnam($tmpdir, 'wd'); 
     104            $nfilehndl = fopen($nodefile, 'w'); 
     105            $datafile = tempnam($tmpdir, 'wd'); 
     106            $datahndl = fopen($datafile, 'w'); 
     107             
     108            if (!$nfilehndl || !$datahndl) { 
     109                $html .= "<p class='error'>"._("Could not create files for anonymised data")."</p>"; 
     110                 
     111            } else { 
     112                /* header('Content-Type: application/octet-stream'); 
     113                header('Content-Disposition: inline; filename="anonymised_nodes.sql"'); 
     114                header("Content-Transfer-Encoding: binary"); */ 
     115                 
     116                $text  = <<<EOT 
     117                CREATE TABLE nodes_anonymised 
     118                ( 
     119                node_id text NOT NULL, 
     120                latitude  NUMERIC(16, 6), 
     121                longitude  NUMERIC(16, 6) 
     122                ); 
    117123EOT; 
    118 $html .= "\n"; 
    119             echo $html; 
    120             $distinguish_users_by = $this->stats->getDistinguishUsersBy(); 
    121  
    122             $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("conn_id, users.user_id, nodes.node_id, connections.user_id, user_mac, timestamp_in, timestamp_out, incoming, outgoing ", true); 
    123  
    124             $sql = "$candidate_connections_sql ORDER BY timestamp_in DESC"; 
    125             $db->execSqlRaw($sql, $resultHandle, false); 
    126             if($resultHandle) { 
    127                 while($row=pg_fetch_array($resultHandle,null,PGSQL_ASSOC)) 
    128                 { 
    129  
    130                     $keys = null; 
    131                     $values = null; 
    132                     $first = true; 
    133                     foreach ($row as $key=>$value) 
     124                $text .= "\n"; 
     125     
     126                fwrite($nfilehndl, $text); 
     127                 
     128                $node_constraint = $this->stats->getSqlNodeConstraint('nodes.node_id'); 
     129                $network_constraint = $this->stats->getSqlNetworkConstraint('nodes.network_id'); 
     130                $sql = "SELECT node_id, latitude, longitude \n"; 
     131                $sql .= "FROM nodes \n"; 
     132                $sql .= "WHERE 1=1 {$node_constraint} {$network_constraint}"; 
     133                 
     134                $db->execSql($sql, $nodes); 
     135                 
     136                if ($nodes) { 
     137                    foreach($nodes as $row) { 
     138                        $keys = null; 
     139                        $values = null; 
     140                        $first = true; 
     141                        foreach ($row as $key=>$value) 
     142                        { 
     143                            if($key == 'user_id' || $key == 'node_id' || $key == 'conn_id' || $key == 'user_mac' ) { 
     144                                $value = "'".$this->getNonRepeatableHash($value)."'"; 
     145                            } 
     146                            else if ($key == 'latitude' && empty ($value)) { 
     147                                $value = 'NULL'; 
     148                            } 
     149                            else if ($key == 'longitude' && empty ($value)) { 
     150                                $value = 'NULL'; 
     151                            } 
     152                            else { 
     153                                $value = "'$value'"; 
     154                            } 
     155                            if(!$first) { 
     156                                $keys .= ', '; 
     157                                $values .= ', '; 
     158                            } 
     159                            else { 
     160                                $first = false; 
     161                            } 
     162                            $keys .= $key; 
     163                            $values .= $value; 
     164                        } 
     165                        //fwrite($temp, "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"); 
     166                        fwrite($nfilehndl, "INSERT INTO nodes_anonymised ($keys) VALUES ($values);\n"); 
     167                    } 
     168                } 
     169                 
     170                 
     171                /** End sql file with node data */ 
     172                 
     173                /** Get the sql file with anonymised connection data */ 
     174              /*  header('Content-Type: application/octet-stream'); 
     175                header('Content-Disposition: inline; filename="anonymised_data.sql"'); 
     176                header("Content-Transfer-Encoding: binary");*/ 
     177     
     178                $text = <<<EOT 
     179                CREATE TABLE connections_anonymised 
     180                ( 
     181                conn_id text NOT NULL, 
     182                timestamp_in timestamp, 
     183                node_id text, 
     184                timestamp_out timestamp, 
     185                user_id text NOT NULL DEFAULT '', 
     186                user_mac text, 
     187                incoming int8, 
     188                outgoing int8 
     189                ); 
     190EOT; 
     191                $text .= "\n"; 
     192             
     193                fwrite($datahndl,  $text); 
     194                $distinguish_users_by = $this->stats->getDistinguishUsersBy(); 
     195     
     196                $candidate_connections_sql = $this->stats->getSqlCandidateConnectionsQuery("conn_id, users.user_id, nodes.node_id, connections.user_id, user_mac, timestamp_in, timestamp_out, incoming, outgoing ", true); 
     197     
     198                $sql = "$candidate_connections_sql ORDER BY timestamp_in DESC"; 
     199                $db->execSqlRaw($sql, $resultHandle, false); 
     200                if($resultHandle) { 
     201                    while($row=pg_fetch_array($resultHandle,null,PGSQL_ASSOC)) 
    134202                    { 
    135                         if($key == 'user_id' || $key == 'node_id' || $key == 'conn_id' || $key == 'user_mac' ) { 
    136                             $value = "'".$this->getNonRepeatableHash($value)."'"; 
     203     
     204                        $keys = null; 
     205                        $values = null; 
     206                        $first = true; 
     207                        foreach ($row as $key=>$value) 
     208                        { 
     209                            if($key == 'user_id' || $key == 'node_id' || $key == 'conn_id' || $key == 'user_mac' ) { 
     210                                $value = "'".$this->getNonRepeatableHash($value)."'"; 
     211                            } 
     212                            else if ($key == 'timestamp_out' && empty ($value)) { 
     213                                $value = 'NULL'; 
     214                            } 
     215                            else { 
     216                                $value = "'$value'"; 
     217                            } 
     218                            if(!$first) { 
     219                                $keys .= ', '; 
     220                                $values .= ', '; 
     221                            } 
     222                            else { 
     223                                $first = false; 
     224                            } 
     225                            $keys .= $key; 
     226                            $values .= $value; 
    137227                        } 
    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; 
     228                        //fwrite($temp, "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"); 
     229                        fwrite($datahndl, "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"); 
    153230                    } 
    154                     //fwrite($temp, "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"); 
    155                     echo "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n"; 
    156231                } 
     232                fclose($datahndl); 
     233                fclose($nfilehndl); 
     234                 
     235                $html .= <<<EOS 
     236                <script type="text/javascript"> 
     237                                window.open('/admin/stats.php?file=$nodefile&type=node', 'Node File'); 
     238                                window.open('/admin/stats.php?file=$datafile&type=data', 'Data file'); 
     239                                                                </script> 
     240EOS; 
     241                 
     242                 
    157243            } 
    158             exit; 
    159244        } 
    160245        return $html;