public function GetToken() { $Current = $this->Talk('User', 'Current'); if (!$Current) { // User is not locally authenticated. $return['error'] = '403'; $return['message'] = 'Forbidden'; return $return; } $Secret = $Current->Secret; $Identity = $Current->Account; $Origin = ASD_DOMAIN; $Destination = ASD_DOMAIN; // 1. Check for existing, unexpired token. $tokensModel = new cModel("AuthorizationTokens"); $Graph = Wob::_('Graph'); // Create the callback function pointer for saving tokens. $fSaveToken = array($this, '_SaveToken'); $fLoadToken = array($this, '_LoadToken'); list($Token, $Expiration) = $Graph->Token($Identity, $Origin, $Destination, $pSecret, 24 * 60, $fSaveToken, $fLoadToken); $Date = Wob::_('Date'); // Check for Created is > 24h ago. $createdStamp = time() - 60 * 60 * 24; $createdMysql = $Date->ToMysql($createdStamp); // Find a corresponding token which is less than 24 hours old. $tokensModel->Query('SELECT * FROM #__AuthorizationTokens'); $criteria = array('Identity' => $Identity, 'Origin' => $Origin, 'Destination' => $Destination, 'Created' => '>>' . $createdMysql); $tokensModel->Retrieve($criteria); // 2. Create new token. if ($tokensModel->Get('Total') == 0) { $createdStamp = time(); $expirationStamp = time() + 60 * 60 * 24; $createdMysql = $Date->ToMysql($createdStamp); $expirationMysql = $Date->ToMysql($expirationStamp); $Expiration = $Date->ToGraph($expirationStamp); # 1P = hmac_sha512 ( Identity + Origin + Destination + Expiration, Secret ); $String = $Identity . $Origin . $Destination . $Expiration; $Token = hash_hmac('sha512', $String, $Secret); $tokensModel->Set('Identity', $Identity); $tokensModel->Set('Origin', $Origin); $tokensModel->Set('Destination', $Destination); $tokensModel->Set('Created', $createdMysql); $tokensModel->Set('Token', $Token); $tokensModel->Set('Token', $Token); $tokensModel->Set('Host', $_SERVER['HTTP_HOST']); $tokensModel->Set('Address', $_SERVER['REMOTE_ADDR']); $tokensModel->Save(); } else { $tokensModel->Fetch(); $Token = $tokensModel->Get('Token'); $Expiration = $Date->ToGraph(strtotime($tokensModel->Get('Created')) + 24 * 60 * 60); } // 3. Return the token. $return = array('account' => $Identity, 'origin' => $Origin, 'destination' => $Destination, 'token' => $Token, 'expiration' => $Expiration); return $return; }
public function UpdateNetworkNode($pDomain, $pEntryPoint, $pVersion, $pProtocols = 'http') { $Model = new cModel('NetworkNodes'); $Model->Retrieve(array('Domain' => $pDomain)); if ($Model->Get('Total') == 0) { // New record. $Model->Set('Trust', 'discovered'); $Model->Set('Access', 'public'); $Model->Set('Inherit', '0'); $Model->Set('Source', ASD_DOMAIN); $Model->Set('Created', NOW()); } else { $Model->Fetch(); } $Model->Set('Domain', $pDomain); $Model->Set('Entry', $pEntryPoint); $Model->Set('Version', $pVersion); $Model->Set('Protocols', $pProtocols); $Model->Set('Updated', NOW()); $Model->Set('Contacted', NOW()); $Model->Save(); return true; }
function Forgot($pView = null, $pData = null) { $username = ltrim(rtrim($this->GetSys("Request")->Get("Username"))); if (!$username) { $this->GetSys("Session")->Context("login.login.(\\d+).login"); $this->GetSys("Session")->Set("Message", "Invalid Username"); $this->GetSys("Session")->Set("Error", 1); return $this->Display($pView, $pData); } $this->Mailer = $this->GetSys("Mailer"); $newpassword = $this->_GeneratePassword('##XX##XX#XX!'); $UserAccounts = new cModel('UserAccounts'); $UserAccounts->Retrieve(array("Username" => $username)); if (!$UserAccounts->Fetch()) { $this->GetSys("Session")->Context("login.login.(\\d+).login"); $this->GetSys("Session")->Set("Message", __("Username Not Found", array("username" => $username))); $this->GetSys("Session")->Set("Error", 1); return $this->Display($pView, $pData); } $UserProfile = new cModel('UserProfile'); $UserProfile->Retrieve($UserAccounts->Get("Account_PK")); $UserProfile->Fetch(); $newpass = $this->GetSys("Crypt")->Encrypt($newpassword); $to = $UserAccounts->Get("Email"); $toName = $UserProfile->Get("Fullname"); if (!$this->ForgotEmail($to, $username, $newpassword)) { // Couldn't send out the message, so error without resetting the pw. $this->GetSys("Session")->Context("login.login.(\\d+).login"); $this->GetSys("Session")->Set("Message", "Error Sending Message"); $this->GetSys("Session")->Set("Error", 1); } else { // Reset the pw. $UserAccounts->Set("Pass", $newpass); $UserAccounts->Save(); $this->GetSys("Session")->Context("login.login.(\\d+).login"); $this->GetSys("Session")->Set("Message", __("Password Has Been Reset", array("username" => $username))); $this->GetSys("Session")->Set("Error", 0); } return $this->Display($pView, $pData); }
public function _StoreNodeNetwork($pSource, $pMethods, $pDescription, $pVersion, $pTrusted = array(), $pDiscovered = array(), $pBlocked = array()) { if (!$pTrusted) { $pTrusted = array(); } if (!$pDiscovered) { $pDiscovered = array(); } if (!$pBlocked) { $pBlocked = array(); } $nodes = $this->_CachedNodeInformation; $inherit = false; $All = array_unique(array_merge($pTrusted, $pDiscovered, $pBlocked)); $NodeNetwork = array_merge($this->_CachedNodeNetwork[0], $this->_CachedNodeNetwork[1], $this->_CachedNodeNetwork[2]); $NodeNetwork = array_map("strtolower", $NodeNetwork); $model = new cModel('NetworkNodes'); // Update the recieved information if (in_array(strtolower($pSource), $NodeNetwork)) { $model->Retrieve(array('Domain' => $pSource)); $model->Fetch(); $model->Set('Description', $pDescription); $model->Set('Methods', $pMethods); $model->Set('Version', $pVersion); $model->Set('Updated', NOW()); $model->Set('Contacted', NOW()); $model->Set('Status', true); $model->Save(); } else { $model->Destroy('Node_PK'); $model->Set('Description', $pDescription); $model->Set('Domain', $pSource); $model->Set('Source', $pSource); $model->Set('Methods', $pMethods); $model->Set('Inherit', false); $model->Set('Trust', 'discovered'); $model->Set('Access', 'public'); $model->Set('Created', NOW()); $model->Set('Updated', NOW()); $model->Set('Contacted', NOW()); $model->Set('Version', $pVersion); $model->Set('Status', true); $model->Save(); } foreach ($nodes as $n => $node) { // Check if we are inheriting this source's values. if ($node['Domain'] == $pSource) { if ($node['Inherit'] == true) { $inherit = true; } } if (in_array(strtolower($node['Domain']), $pTrusted) or in_array(strtolower($node['Domain']), $pDiscovered) or in_array(strtolower($node['Domain']), $pBlocked)) { $update[$node['Node_PK']] = $node['Domain']; } if (!in_array(strtolower($node['Domain']), $All)) { $insert[] = $node['Domain']; } } // Add the trusted nodes. foreach ($pTrusted as $t => $trusted) { if (strtolower($trusted) == strtolower(QUICKSOCIAL_DOMAIN)) { continue; } if (strtolower($trusted) == 'localhost') { continue; } if (strtolower($trusted) == '127.0.0.1') { continue; } // Update the recieved information if (!in_array(strtolower($trusted), $NodeNetwork)) { $model->Destroy('Node_PK'); $model->Set('Description', null); $model->Set('Domain', $trusted); $model->Set('Source', $pSource); $model->Set('Methods', null); $model->Set('Inherit', false); if ($inherit) { $model->Set('Trust', 'trusted'); } else { $model->Set('Trust', 'discovered'); } $model->Set('Access', 'public'); $model->Set('Created', NOW()); $model->Set('Updated', NOW()); $model->Set('Contacted', NOW()); $model->Set('Version', null); $model->Set('Status', false); $model->Save(); } } // Add the discovered nodes. foreach ($pDiscovered as $d => $discovered) { if (strtolower($discovered) == strtolower(QUICKSOCIAL_DOMAIN)) { continue; } if (strtolower($discovered) == 'localhost') { continue; } if (strtolower($discovered) == '127.0.0.1') { continue; } // Update the recieved information if (!in_array(strtolower($discovered), $NodeNetwork)) { $model->Destroy('Node_PK'); $model->Set('Description', null); $model->Set('Domain', $discovered); $model->Set('Source', $pSource); $model->Set('Methods', null); $model->Set('Inherit', false); $model->Set('Trust', 'discovered'); $model->Set('Access', 'public'); $model->Set('Created', NOW()); $model->Set('Updated', NOW()); $model->Set('Contacted', NOW()); $model->Set('Version', null); $model->Set('Status', false); $model->Save(); } } // Only add the blocked nodes if we're inheriting. if ($inherit) { // Add the blocked nodes. foreach ($pBlocked as $b => $blocked) { if (strtolower($blocked) == strtolower(QUICKSOCIAL_DOMAIN)) { continue; } if (strtolower($blocked) == 'localhost') { continue; } if (strtolower($blocked) == '127.0.0.1') { continue; } // Update the recieved information if (in_array(strtolower($blocked), $NodeNetwork)) { $model->Retrieve(array('Domain' => $blocked)); $model->Fetch(); $model->Set('Trust', 'blocked'); $model->Save(); } else { $model->Destroy('Node_PK'); $model->Set('Description', null); $model->Set('Domain', $blocked); $model->Set('Source', $pSource); $model->Set('Methods', null); $model->Set('Inherit', false); $model->Set('Trust', 'blocked'); $model->Set('Access', 'public'); $model->Set('Created', NOW()); $model->Set('Updated', NOW()); $model->Set('Contacted', NOW()); $model->Set('Version', null); $model->Set('Status', false); $model->Save(); } } } // For some reason, duplicate entries are getting created. For now, delete duplicates. $query = "\n\t\t\tDELETE FROM #__NetworkNodes\n\t\t\t\tUSING #__NetworkNodes, #__NetworkNodes as vtable\n\t\t\t\tWHERE (#__NetworkNodes.Node_PK > vtable.Node_PK)\n\t\t\t\tAND (#__NetworkNodes.Domain=vtable.Domain);\n\t\t"; $model->Query($query); return true; }