* Start general request parameter processing section */ if (!empty($_REQUEST['node_id'])) { try { $node = Node::getObject($_REQUEST['node_id']); $network = $node->getNetwork(); } catch (Exception $e) { $ui = MainUI::getObject(); $ui->displayError($e->getMessage()); exit; } } else { if (!empty($_REQUEST['gw_id'])) { //This section MUST remain, the gw_id calling convention is hard_coded into the gateway try { $node = Node::getObjectByGatewayId($_REQUEST['gw_id']); $network = $node->getNetwork(); } catch (Exception $e) { $ui = MainUI::getObject(); $ui->displayError($e->getMessage()); exit; } } else { $ui = MainUI::getObject(); $ui->displayError(_("No Hotspot specified!")); exit; } } $node_id = $node->getId(); Node::setCurrentNode($node); if (isset($session)) {
if (isset($_REQUEST["mac"])) { $session->set(SESS_USER_MAC_VAR, $_REQUEST['mac']); $mac = $_REQUEST['mac']; } /* * Store original URL typed by user */ if (!empty($_REQUEST['url'])) { $session->set(SESS_ORIGINAL_URL_VAR, $_REQUEST['url']); } /* * Start general request parameter processing section */ if (!empty($gw_id)) { try { $node = Node::getObjectByGatewayId($gw_id); } catch (Exception $e) { $returnedNodeIsNew = false; $node = Node::processStealOrCreateNewUI($gw_id, $returnedNodeIsNew); if (!$node) { $ui = MainUI::getObject(); $ui->addContent('main_area_middle', '<p class=errormsg>' . $e->getMessage() . "</p>\n", 1); $stealNodeForm = null; $stealNodeForm .= "<form action='' method='POST'>\n"; $stealNodeForm .= Node::getStealOrCreateNewUI($gw_id); $stealNodeForm .= "</form>\n"; $ui->addContent('main_area_middle', $stealNodeForm, 2); $ui->display(); exit; } else { if ($returnedNodeIsNew) {
/** * Create a new Node in the database * * @param string $gw_id The Id of the gatewqay to be associated with * thisnode. If not present, a dummy value will be assigned. * @param object $network Network object. The node's network. If not * present, the current Network will be assigned * * @return mixed The newly created Node object, or null if there was * an error * * @static * @access public */ public static function createNewObject($gw_id = null, $network = null) { $db = AbstractDb::getObject(); if (empty($gw_id)) { $gw_id = $db->escapeString(_('PUT_GATEWAY_ID_HERE')); } else { $gw_id = $db->escapeString($gw_id); } $node_id = get_guid(); if (empty($network)) { $network = Network::getCurrentNetwork(); } $network_id = $db->escapeString($network->getId()); $node_deployment_status = $db->escapeString("IN_PLANNING"); $node_name = _("New node"); $duplicate = null; try { $duplicate = Node::getObjectByGatewayId($gw_id); } catch (Exception $e) { } if ($duplicate) { throw new Exception(sprintf(_('Sorry, a node for the gateway %s already exists.'), $gw_id)); } $sql = "INSERT INTO nodes (node_id, gw_id, network_id, creation_date, node_deployment_status, name) VALUES ('{$node_id}', '{$gw_id}', '{$network_id}', CURRENT_TIMESTAMP,'{$node_deployment_status}', '{$node_name}')"; if (!$db->execSqlUpdate($sql, false)) { throw new Exception(_('Unable to insert new node into database!')); } HotspotGraphElement::createNewObject($node_id, 'Node', $network); $object = self::getObject($node_id); return $object; }
/** * Verify the given user credentials against the wifidog database * @param $username The username to authenticate * @param $pwdhash The password hash * @param $gw_id The gateway id * @param $gw_ip The gateway's ip addresss * @param $mac The mac address of the user * @param $gw_port The port of the gateway's http server * @param $from The ip address of the user on the node * @param $logout Whether the user wants to logout * @return unknown_type */ protected function executeAuth($username = null, $password = null, $gw_id = null, $gw_ip = null, $mac = null, $gw_port = null, $from = null, $logout = false) { $this->_outputArr['auth'] = 0; require_once 'classes/Node.php'; require_once 'classes/User.php'; require_once 'classes/Network.php'; require_once 'classes/Authenticator.php'; if (!is_null($gw_id)) { if (is_null($gw_ip) || is_null($gw_port) || is_null($from)) { throw new WSException("Missing information on the gateway. You must specify parameter 'gw_address' AND 'gw_port' AND 'from_ip' if the parameter 'gw_id' is specified.", WSException::INVALID_PARAMETER); } $node = Node::getObjectByGatewayId($gw_id); if ($node) { $network = $node->getNetwork(); } else { throw new WSException("Node identified by {$gw_id} cannot be found", WSException::PROCESS_ERROR); } } else { // Gateway ID is not set ... virtual login $network = Network::getCurrentNetwork(); $node = null; } /* * If this is a splash-only node, then the user is automatically authenticated */ $token = null; if (!empty($node) && $node->isSplashOnly()) { $this->_outputArr['auth'] = 1; $user = $network->getSplashOnlyUser(); $token = $user->generateConnectionTokenNoSession($node, $from, $mac); if (!$token) { throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR); } } else { if (!$logout) { // Authenticate the user on the requested network $user = $network->getAuthenticator()->login($username, $password, $errMsg, $errNo); if (!$user) { $this->_outputArr['auth'] = 0; $this->_outputArr['explanation'] = $errMsg; $this->_outputArr['errorcode'] = $errNo; } else { $this->_outputArr['auth'] = 1; if (!is_null($node)) { $token = $user->generateConnectionTokenNoSession($node, $from, $mac); if (!$token) { throw new WSException("User authenticated but cannot generate connection token.", WSException::PROCESS_ERROR); } } } } else { $user = User::getUserByUsernameOrEmail($username); User::setCurrentUser($user); $network->getAuthenticator()->logout(); $this->_outputArr['auth'] = 1; } } if ($this->_outputArr['auth'] == 1 && !is_null($token)) { $this->_outputArr['forwardTo'] = "http://" . $gw_ip . ":" . $gw_port . "/wifidog/auth?token=" . $token; } }