Changeset 1453
- Timestamp:
- 02/25/10 15:56:33 (2 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 12 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/admin/stats.php (modified) (1 diff)
-
wifidog/classes/Authenticators/AuthenticatorLocalUser.php (modified) (4 diffs)
-
wifidog/classes/Node.php (modified) (3 diffs)
-
wifidog/classes/NodeLists/NodeListXML.php (modified) (1 diff)
-
wifidog/classes/StatisticReport/AnonymisedDataExport.php (modified) (1 diff)
-
wifidog/classes/User.php (modified) (3 diffs)
-
wifidog/include/common.php (modified) (1 diff)
-
wifidog/include/schema_validate.php (modified) (2 diffs)
-
wifidog/js/hotspots_status_map.js (modified) (1 diff)
-
wifidog/ws/classes/WifidogWS/V1.php (modified) (8 diffs)
-
wifidog/ws/index.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1440 r1453 1 1 # $Id$ 2 3 2010-02-25 Geneviève Bastien <gbastien@versatic.net> 4 * Added constraint to hotspot_graph_element_has_content (#701) 5 * Bug fix: when creating new nodes and node groups, they are now automatically added as children of the network in the new hierarchy structure. 6 * Added possibility to have a deployed geolocated node not show on map (quick fix) (#706) 7 * When producing anonymised data export, two files are produced, one for the geolocated nodes and one for the connections (#705) 8 * Additions and bug fixes to web service: can now logout and auth returns both error code and message 9 * Starting work on #707 as needed 2 10 3 11 2010-01-28 Geneviève Bastien <gbastien@versatic.net> -
trunk/wifidog-auth/wifidog/admin/stats.php
r1292 r1453 83 83 $stats_title = _("Network information for")." '".$networkObject->getName()."'"; 84 84 } 85 elseif (isset($_REQUEST['file']) && isset($_REQUEST['type'])) { 86 $filename = $_REQUEST['file']; 87 $type = $_REQUEST['type']; 88 if (User :: getCurrentUser()->DEPRECATEDisSuperAdmin()) { 89 // The file is valid for one hour, because it contains sensitive data and we don't want to open a security breach 90 if (file_exists($filename) && (filectime($filename) > (time() - 60*60)) ) { 91 header('Content-Type: application/octet-stream'); 92 header('Content-Disposition: inline; filename="anonymised_'.$type.'.sql"'); 93 header("Content-Transfer-Encoding: binary"); 94 header("Pragma: no-cache"); 95 header("Expires: 0"); 96 $fp=fopen($filename,"r"); 97 print fread($fp,filesize($filename)); 98 fclose($fp); 99 exit(); 100 } else { 101 if (!file_exists($filename)) { 102 throw new Exception(sprintf(_("File %s does not exist"), $filename)); 103 } 104 if (filectime($filename) > (time() - 60*60)) { 105 throw new Exception(sprintf(_("The statistics file for anonymised_%s.sql has expired."), $type)); 106 } 107 } 108 } else { 109 throw new Exception(_("These reports are only available to server administrators.")); 110 } 111 } 85 112 else { 86 113 $stats_title = null; -
trunk/wifidog-auth/wifidog/classes/Authenticators/AuthenticatorLocalUser.php
r1428 r1453 101 101 * @param string $password Clear text password. 102 102 * @param string $errmsg Reference of error message 103 * @param int $errno Reference to error code 103 104 * 104 105 * @return object The actual User object if login was successfull, false 105 106 * otherwise. 106 107 */ 107 public function login($username, $password, &$errmsg = null )108 public function login($username, $password, &$errmsg = null, &$errno = 0) 108 109 { 109 110 //echo "DEBUG: login($username, $password, $errmsg)<br/>"; … … 115 116 $username = $db->escapeString($username); 116 117 if (empty($username)) { 117 $errmsg .= sprintf(_("Fatal error: Username cannot be empty")); 118 $errmsg .= sprintf(getErrorText(ERR_NO_USERNAME)); 119 $errno = ERR_NO_USERNAME; 118 120 $retval = false; 119 121 } … … 131 133 $user = User::getObject($user_info['user_id']); 132 134 133 if ($user->isUserValid($errmsg )) {135 if ($user->isUserValid($errmsg, $errno)) { 134 136 $retval = &$user; 135 137 $errmsg = _("Login successfull"); … … 147 149 148 150 if ($user_info == null) { 149 $errmsg = _('Unknown username or email'); 151 $errmsg = getErrorText(ERR_UNKNOWN_USERNAME); 152 $errno = ERR_UNKNOWN_USERNAME; 150 153 } else { 151 $errmsg = _('Incorrect password (Maybe you have CAPS LOCK on?)'); 154 $errmsg = getErrorText(ERR_WRONG_PASSWORD); 155 $errno = ERR_WRONG_PASSWORD; 152 156 } 153 157 -
trunk/wifidog-auth/wifidog/classes/Node.php
r1444 r1453 825 825 $this->refresh(); 826 826 } 827 827 828 /** 829 * Returns whether the node should be shown on a map or is invisible 830 * 831 */ 832 833 public function showOnMap() 834 { 835 return (($this->_row['show_node_on_map'] == 't') ? true : false); 836 } 837 838 /** Set if this node be shown on map 839 * @param $value The new value, true or false 840 * @return true on success, false on failure */ 841 function setShowOnMap($value) 842 { 843 $retval = true; 844 if ($value != $this->showOnMap()) 845 { 846 $db = AbstractDb::getObject(); 847 $value ? $value = 'TRUE' : $value = 'FALSE'; 848 $retval = $db->execSqlUpdate("UPDATE nodes SET show_node_on_map = {$value} WHERE node_id = '{$this->getId()}'", false); 849 $this->refresh(); 850 } 851 return $retval; 852 } 853 828 854 public function getCivicNumber() 829 855 { … … 1307 1333 $_data = InterfaceElements::generateInputText("node_" . $node_id . "_map_url", $this->getMapURL(), "node_map_url_input"); 1308 1334 $_html_node_gis_data[] = InterfaceElements::generateAdminSectionContainer("node_map_url", $_title, $_data); 1335 1336 $_title = _("Show node on map"); 1337 $help = _("Should this node be visible on the map when deployed?"); 1338 $_data = InterfaceElements::generateInputCheckbox("node_" . $node_id . "_show_on_map", "", _("Yes"), $this->showOnMap(), "node_show_on_map_input"); 1339 $_html_node_gis_data[] = InterfaceElements::generateAdminSectionContainer("node_show_on_map", $_title, $_data, $help); 1309 1340 1310 1341 // Build section … … 1509 1540 $this->setGisLocation(new GisPoint($_REQUEST[$gis_lat_name], $_REQUEST[$gis_long_name], .0)); 1510 1541 } 1542 1543 $name = "node_".$node_id."_show_on_map"; 1544 $this->setShowOnMap(empty ($_REQUEST[$name]) ? false : true); 1511 1545 1512 1546 // Statistics -
trunk/wifidog-auth/wifidog/classes/NodeLists/NodeListXML.php
r1421 r1453 331 331 $_hotspotGis->setAttribute("lat", $_gisData->getLatitude()); 332 332 $_hotspotGis->setAttribute("long", $_gisData->getLongitude()); 333 $_hotspotGis->setAttribute("show", $_node->showOnMap()); 333 334 $_hotspot->appendChild($_hotspotGis); 334 335 } -
trunk/wifidog-auth/wifidog/classes/StatisticReport/AnonymisedDataExport.php
r1421 r1453 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 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 ); 117 123 EOT; 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 ); 190 EOT; 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)) 134 202 { 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; 137 227 } 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"); 153 230 } 154 //fwrite($temp, "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n");155 echo "INSERT INTO connections_anonymised ($keys) VALUES ($values);\n";156 231 } 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> 240 EOS; 241 242 157 243 } 158 exit;159 244 } 160 245 return $html; -
trunk/wifidog-auth/wifidog/classes/User.php
r1439 r1453 516 516 517 517 /** Is the user valid? Valid means that the account is validated or hasn't exhausted it's validation period. 518 $errmsg: Returs the reason why the account is or isn't valid */ 519 function isUserValid(& $errmsg = null) { 518 $errmsg: Returs the reason why the account is or isn't valid 519 $errno: Returns an error code identifying the error */ 520 function isUserValid(& $errmsg = null, &$errno = 0) { 520 521 global $account_status_to_text; 521 522 $db = AbstractDb::getObject(); … … 530 531 531 532 if ($user_info['validation_grace_time_expired'] == 't') { 532 $errmsg = sprintf(_("Sorry, your %.0f minutes grace period to retrieve your email and validate your account has now expired. You will have to connect to the internet and validate your account from another location."), $user_info['validation_grace_time']/60); 533 $errmsg = sprintf(getErrorText(ERR_VALIDATION_EXPIRED), $user_info['validation_grace_time']/60); 534 $errno = ERR_VALIDATION_EXPIRED; 533 535 $retval = false; 534 536 } else { … … 537 539 } 538 540 } else { 539 $errmsg = _("Sorry, your account is not valid: ") . $account_status_to_text[$account_status]; 541 $errmsg = getErrorText(ERR_ACCOUNT_INVALID) . $account_status_to_text[$account_status]; 542 $errno = ERR_ACCOUNT_INVALID; 540 543 $retval = false; 541 544 } -
trunk/wifidog-auth/wifidog/include/common.php
r1428 r1453 158 158 /* End of Other constants */ 159 159 160 /* defin error codes */ 161 define ('ERR_UNKNOWN_USERNAME', 20001); 162 define ('ERR_WRONG_PASSWORD', 20002); 163 define ('ERR_NO_USERNAME', 20003); 164 define ('ERR_VALIDATION_EXPIRED', 20004); 165 define ('ERR_ACCOUNT_INVALID', 20005); 166 167 function getErrorText($errorCode) { 168 switch ($errorCode) { 169 case ERR_UNKNOWN_USERNAME: $text = _('Unknown username or email'); break; 170 case ERR_WRONG_PASSWORD: $text = _('Incorrect password (Maybe you have CAPS LOCK on?)'); break; 171 case ERR_NO_USERNAME: $text = _("Fatal error: Username cannot be empty"); break; 172 case ERR_VALIDATION_EXPIRED: $text = _("Sorry, your %.0f minutes grace period to retrieve your email and validate your account has now expired. You will have to connect to the internet and validate your account from another location."); break; 173 case ERR_ACCOUNT_INVALID: $text = _("Sorry, your account is not valid: "); break; 174 default: $text = $errorCode; break; 175 } 176 return $text; 177 } 178 /* End error code definitions */ 179 160 180 /** Convert a password hash form a NoCat passwd file into the same format as get_password_hash(). 161 181 * @return The 32 character hash. -
trunk/wifidog-auth/wifidog/include/schema_validate.php
r1452 r1453 48 48 * Define current database schema version 49 49 */ 50 define('REQUIRED_SCHEMA_VERSION', 69);50 define('REQUIRED_SCHEMA_VERSION', 70); 51 51 /** Used to test a new shecma version before modyfying the database */ 52 52 define('SCHEMA_UPDATE_TEST_MODE', false); … … 1534 1534 $sql .= "\n\nALTER TABLE hotspot_graph_element_has_content ADD CONSTRAINT contentfk FOREIGN KEY (content_id) REFERENCES content(content_id) ON UPDATE CASCADE ON DELETE CASCADE;\n"; 1535 1535 } 1536 1537 $new_schema_version = 70; 1538 if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 1539 printUpdateVersion($new_schema_version); 1540 $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 1541 $sql .= "\nALTER TABLE nodes ADD COLUMN show_node_on_map boolean NOT NULL DEFAULT true;"; 1542 } 1536 1543 1537 1544 /* -
trunk/wifidog-auth/wifidog/js/hotspots_status_map.js
r1409 r1453 321 321 var gis = hotspots[i].getElementsByTagName("gisCenterLatLong"); 322 322 323 if (hotspotId.length == 1 && gis.length == 1 && gis[0].getAttribute("lat") != "" && gis[0].getAttribute("long") != "" ) {323 if (hotspotId.length == 1 && gis.length == 1 && gis[0].getAttribute("lat") != "" && gis[0].getAttribute("long") != "" && gis[0].getAttribute("show") == "1") { 324 324 // Extract GIS data 325 325 var point = new GLatLng(parseFloat(gis[0].getAttribute("lat")), parseFloat(gis[0].getAttribute("long"))); -
trunk/wifidog-auth/wifidog/ws/classes/WifidogWS/V1.php
r1439 r1453 103 103 'NumOnlineUsers' => 'NumOnlineUsers', 104 104 'CreationDate' => 'CreationDate', 105 'Status' => ' Status',105 'Status' => 'DeploymentStatus', 106 106 'OpeningDate' => 'CreationDate', 107 107 'Connected_users' => 'OnlineUsers'), … … 150 150 foreach($infields as $field) { 151 151 if (isset(self::$_allowedFields[$objectClass][$field])) 152 $fields[ ] = self::$_allowedFields[$objectClass][$field];152 $fields[$field] = self::$_allowedFields[$objectClass][$field]; 153 153 else 154 $fields[ ] = "$field.forbidden";154 $fields[$field] = "$field.forbidden"; 155 155 } 156 156 return $fields; … … 189 189 $username = (isset($this->_params['username']) ? $this->_params['username']:''); 190 190 $password = (isset($this->_params['password']) ? $this->_params['password']:''); 191 $this->executeAuth($username, $password, $gw_id, $gw_address, $mac, $gw_port, $from); 191 $logout = (isset($this->_params['logout']) ? $this->_params['logout']:false); 192 $this->executeAuth($username, $password, $gw_id, $gw_address, $mac, $gw_port, $from, $logout); 192 193 break; 193 194 default: … … 204 205 * @param $gw_id The gateway id 205 206 * @param $gw_ip The gateway's ip addresss 207 * @param $mac The mac address of the user 208 * @param $gw_port The port of the gateway's http server 209 * @param $from The ip address of the user on the node 210 * @param $logout Whether the user wants to logout 206 211 * @return unknown_type 207 212 */ 208 protected function executeAuth($username = null, $password = null, $gw_id = null, $gw_ip = null, $mac = null, $gw_port = null, $from = null ) {213 protected function executeAuth($username = null, $password = null, $gw_id = null, $gw_ip = null, $mac = null, $gw_port = null, $from = null, $logout = false) { 209 214 $this->_outputArr['auth'] = 0; 210 215 … … 240 245 if (!$token) throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR); 241 246 } else { 242 // Authenticate the user on the requested network 243 $user = $network->getAuthenticator()->login($username, $password, $errMsg); 244 if (!$user) { 245 $this->_outputArr['auth'] = 0; 246 $this->_outputArr['explanation'] = $errMsg; 247 if (!$logout) { 248 // Authenticate the user on the requested network 249 $user = $network->getAuthenticator()->login($username, $password, $errMsg, $errNo); 250 if (!$user) { 251 $this->_outputArr['auth'] = 0; 252 $this->_outputArr['explanation'] = $errMsg; 253 $this->_outputArr['errorcode'] = $errNo; 254 } else { 255 $this->_outputArr['auth'] = 1; 256 if (!is_null($node)) { 257 $token = $user->generateConnectionTokenNoSession($node, $from, $mac); 258 259 if (!$token) throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR); 260 } 261 } 247 262 } else { 263 $user = User::getUserByUsernameOrEmail($username); 264 User::setCurrentUser($user); 265 $network->getAuthenticator()->logout(); 248 266 $this->_outputArr['auth'] = 1; 249 if (!is_null($node)) {250 $token = $user->generateConnectionTokenNoSession($node, $from, $mac);251 252 if (!$token) throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR);253 }254 267 } 255 268 } … … 298 311 $fields = $this->mapFields($objectClass, $fields); 299 312 if (empty($fields)) { 300 $fields = array_keys(self::$_allowedFields[$objectClass]);313 $fields = self::$_allowedFields[$objectClass]; 301 314 } 302 315 $allowedFields = self::$_allowedFields[$objectClass]; … … 362 375 } 363 376 377 if (!isset($objectList)) { 378 throw new WSException("Object list for '{$objectClass}' is not supported.", WSException::GENERIC_EXCEPTION); 379 } 364 380 $this->_outputArr = self::filterRet($objectList, $fields); 365 381 } … … 389 405 } 390 406 $retFields = array(); 391 foreach ($fields as $f ield) {407 foreach ($fields as $fkey => $field) { 392 408 $forbiddenfield = explode(".", $field); 393 409 if (! (count($forbiddenfield) == 2)) { 394 410 $methodName = 'get'.$field; 395 411 if (method_exists($value, $methodName)) { 396 397 $retFields[$field] = self::filterRet($value->$methodName()); 412 $retFields[is_string($fkey)?$fkey:$field] = self::filterRet($value->$methodName()); 398 413 } else { 399 $retFields[ $field] = 'unknown';414 $retFields[is_string($fkey)?$fkey:$field] = 'unknown'; 400 415 } 401 416 } else -
trunk/wifidog-auth/wifidog/ws/index.php
r1444 r1453 71 71 */ 72 72 require_once('../include/common.php'); 73 require_once('../include/language.php'); 73 74 require_once('ws/classes/WifidogWS.php'); 74 75 require_once('ws/classes/WSOutput.php');
