Changeset 994 for trunk/wifidog-auth/wifidog/classes/Authenticator.php
- Timestamp:
- 03/16/06 18:47:35 (7 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Authenticator.php
r990 r994 38 38 * @subpackage Authenticators 39 39 * @author Benoit Gregoire <bock@step.polymtl.ca> 40 * @author Max Horvath <max.horvath@maxspot.de> 40 41 * @copyright 2005-2006 Benoit Gregoire, Technologies Coeus inc. 42 * @copyright 2006 Max Horvath, maxspot GmbH 41 43 * @version Subversion $Id$ 42 44 * @link http://www.wifidog.org/ … … 47 49 */ 48 50 require_once('classes/Network.php'); 51 require_once('classes/Node.php'); 49 52 require_once('classes/Session.php'); 53 require_once('classes/User.php'); 50 54 51 55 /** … … 55 59 * @subpackage Authenticators 56 60 * @author Benoit Gregoire <bock@step.polymtl.ca> 61 * @author Max Horvath <max.horvath@maxspot.de> 57 62 * @copyright 2005-2006 Benoit Gregoire, Technologies Coeus inc. 63 * @copyright 2006 Max Horvath, maxspot GmbH 58 64 */ 59 65 abstract class Authenticator 60 66 { 67 /** 68 * Object of current network 69 * 70 * @var object 71 * 72 * @access private 73 */ 61 74 private $mNetwork; 62 75 63 function __construct($network_id) 76 /** 77 * Constructor 78 * 79 * @param string $network_id Id of network 80 * 81 * @return void 82 * 83 * @access public 84 */ 85 public function __construct($network_id) 64 86 { 65 87 $this->mNetwork = Network::getObject($network_id); 66 88 } 67 89 90 /** 91 * Returns object of current network 92 * 93 * @return object Object of current network 94 * 95 * @access public 96 */ 68 97 public function getNetwork() 69 98 { … … 71 100 } 72 101 73 /** Attempts to login a user against the authentication source. If successfull, returns a User object */ 74 function login() 75 { 76 } 77 78 /** Logs out the user 79 * $conn_id: The connection id for the connection to work on. Optionnal. 80 * If it is not present, the behaviour depends if the network supports 81 * multiple logins. If it does not, all connections associated with the 82 * current user will be destroyed. If it does, only the connections 83 * tied to the current node will be destroyed */ 84 function logout($conn_id = null) 102 /** 103 * Attempts to login a user against the authentication source 104 * 105 * If successfull, returns a User object. 106 * 107 * @access public 108 */ 109 public function login() 110 { 111 // Must be defined in child class 112 } 113 114 /** 115 * Logs out the user 116 * 117 * @param string $conn_id The connection id for the connection to work on. 118 * If it is not present, the behaviour depends if 119 * the network supports multiple logins. If it does 120 * not, all connections associated with the current 121 * user will be destroyed. If it does, only the 122 * connections tied to the current node will be 123 * destroyed. 124 * 125 * @return void 126 * 127 * @access public 128 */ 129 public function logout($conn_id = null) 85 130 { 86 131 // Define globals … … 89 134 90 135 $conn_id = $db->escapeString($conn_id); 91 if (!empty ($conn_id)) 92 {136 137 if (!empty ($conn_id)) { 93 138 $db->execSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 94 139 95 $user = User ::getObject($info['user_id']);140 $user = User::getObject($info['user_id']); 96 141 $network = $user->getNetwork(); 97 142 $splash_user_id = $network->getSplashOnlyUser()->getId(); 98 143 $this->acctStop($conn_id); 99 } 100 else 101 { 102 $user = User :: getCurrentUser(); 144 } else { 145 $user = User::getCurrentUser(); 103 146 $network = $user->getNetwork(); 104 147 $splash_user_id = $network->getSplashOnlyUser()->getId(); 105 if ($splash_user_id != $user->getId() && $node = Node :: getCurrentNode()) 106 {107 // Try to destroy all connections tied to the current node108 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='".TOKEN_INUSE."'; \n";148 149 if ($splash_user_id != $user->getId() && $node = Node::getCurrentNode()) { 150 // Try to destroy all connections tied to the current node 151 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND node_id='{$node->getId()}' AND token_status='".TOKEN_INUSE."';"; 109 152 $conn_rows = null; 110 153 $db->execSql($sql, $conn_rows, false); 111 if ($conn_rows) 112 { 113 foreach ($conn_rows as $conn_row) 114 { 154 155 if ($conn_rows) { 156 foreach ($conn_rows as $conn_row) { 115 157 $this->acctStop($conn_row['conn_id']); 116 158 } … … 119 161 } 120 162 121 if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() == false) 122 { 123 /* The user isn't the splash_only user and the network config does not allow multiple logins. 124 * Logging in with a new token implies that all other active tokens should expire */ 125 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';\n"; 163 if ($splash_user_id != $user->getId() && $network->getMultipleLoginAllowed() === false) { 164 /* 165 * The user isn't the splash_only user and the network config does 166 * not allow multiple logins. Logging in with a new token implies 167 * that all other active tokens should expire 168 */ 169 $sql = "SELECT conn_id FROM connections WHERE user_id = '{$user->getId()}' AND token_status='".TOKEN_INUSE."';"; 126 170 $conn_rows = null; 127 171 $db->execSql($sql, $conn_rows, false); 128 if ($conn_rows) 129 { 130 foreach ($conn_rows as $conn_row) 131 { 172 173 if ($conn_rows) { 174 foreach ($conn_rows as $conn_row) { 132 175 $this->acctStop($conn_row['conn_id']); 133 176 } … … 141 184 } 142 185 143 /** Start accounting traffic for the user 144 * $conn_id: The connection id for the connection to work on */ 145 function acctStart($conn_id) 146 { 186 /** 187 * Start accounting traffic for the user 188 * 189 * @param string $conn_id The connection id for the connection to work on 190 * 191 * @return void 192 * 193 * @access public 194 */ 195 public function acctStart($conn_id) 196 { 197 // Define globals 147 198 global $db; 199 148 200 $conn_id = $db->escapeString($conn_id); 149 201 $db->execSqlUniqueRes("SELECT NOW(), *, CASE WHEN ((NOW() - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id='$conn_id'", $info, false); 150 $network = Network ::getObject($info['network_id']);202 $network = Network::getObject($info['network_id']); 151 203 $splash_user_id = $network->getSplashOnlyUser()->getId(); 152 204 $auth_response = $info['account_status']; 153 /* Login the user */ 205 206 // Login the user 154 207 $mac = $db->escapeString($_REQUEST['mac']); 155 208 $ip = $db->escapeString($_REQUEST['ip']); 156 $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}'; \n";209 $sql = "UPDATE connections SET "."token_status='".TOKEN_INUSE."',"."user_mac='$mac',"."user_ip='$ip',"."last_updated=NOW()"."WHERE conn_id='{$conn_id}';"; 157 210 $db->execSqlUpdate($sql, false); 158 if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() == false) 159 { 160 /* The user isn't the splash_only user and the network config does not allow multiple logins. 161 * Logging in with a new token implies that all other active tokens should expire */ 211 212 if ($splash_user_id != $info['user_id'] && $network->getMultipleLoginAllowed() === false) { 213 /* 214 * The user isn't the splash_only user and the network config does 215 * not allow multiple logins. Logging in with a new token implies 216 * that all other active tokens should expire 217 */ 162 218 $token = $db->escapeString($_REQUEST['token']); 163 $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token'; \n";219 $sql = "SELECT * FROM connections WHERE user_id = '{$info['user_id']}' AND token_status='".TOKEN_INUSE."' AND token!='$token';"; 164 220 $conn_rows = array (); 165 221 $db->execSql($sql, $conn_rows, false); 166 if (isset ($conn_rows)) 167 { 168 foreach ($conn_rows as $conn_row) 169 { 222 223 if (isset ($conn_rows)) { 224 foreach ($conn_rows as $conn_row) { 170 225 $this->acctStop($conn_row['conn_id']); 171 226 } … … 173 228 } 174 229 175 /* Delete all unused tokens for this user, so we don't fill the database with them */ 176 $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';\n"; 230 /* 231 * Delete all unused tokens for this user, so we don't fill the database 232 * with them 233 */ 234 $sql = "DELETE FROM connections "."WHERE token_status='".TOKEN_UNUSED."' AND user_id = '{$info['user_id']}';"; 177 235 $db->execSqlUpdate($sql, false); 178 236 } 179 237 180 /** Update traffic counters 181 * $conn_id: The connection id for the connection to work on */ 182 function acctUpdate($conn_id, $incoming, $outgoing) 183 { 238 /** 239 * Update traffic counters 240 * 241 * @param string $conn_id The connection id for the connection to work on 242 * @param int $incoming Incoming traffic in bytes 243 * @param int $outgoing Outgoing traffic in bytes 244 * 245 * @return void 246 * 247 * @access public 248 */ 249 public function acctUpdate($conn_id, $incoming, $outgoing) 250 { 251 // Define globals 252 global $db; 253 184 254 // Write traffic counters to database 185 global $db;186 255 $conn_id = $db->escapeString($conn_id); 187 256 $db->execSqlUpdate("UPDATE connections SET "."incoming='$incoming',"."outgoing='$outgoing',"."last_updated=NOW() "."WHERE conn_id='{$conn_id}'"); 188 257 } 189 258 190 /** Final update and stop accounting 191 * $conn_id: The connection id (the token id) for the connection to work on 259 /** 260 * Final update and stop accounting 261 * 262 * @param string $conn_id The connection id (the token id) for the 263 * connection to work on 264 * 265 * @return void 266 * 267 * @access public 192 268 * */ 193 function acctStop($conn_id) 194 { 269 public function acctStop($conn_id) 270 { 271 // Define globals 272 global $db; 273 195 274 // Stop traffic counters update 196 global $db;197 275 $conn_id = $db->escapeString($conn_id); 198 276 $db->execSqlUpdate("UPDATE connections SET "."timestamp_out=NOW(),"."token_status='".TOKEN_USED."' "."WHERE conn_id='{$conn_id}';\n", false); … … 201 279 /** 202 280 * Property method that tells if the class allows registration 203 */ 204 function isRegistrationPermitted() 281 * 282 * @return bool Returns if the class allows registration 283 * 284 * @access public 285 */ 286 public function isRegistrationPermitted() 205 287 { 206 288 return false;
