private function _CheckSchemaVersion() { $Config = $this->GetSys('Config'); // Get the schema version required $Version = $Config->GetConfiguration('schema_version'); $Model = new cModel('SchemaVersions'); // SchemaVersions doesn't exist, we must be upgrading from 0.7.8 and have not updated. if (!$Model->Get('Exists')) { echo __('Table Does Not Exist', array('tablename' => 'SchemaVersions')); exit; } // Retrieve the latest schema version information. $Model->Retrieve(null, 'Schema_PK DESC', array('start' => 0, 'step' => 1)); // No schema version info was found, so we must be upgrading from 0.7.8. if ($Model->Get('Total') == 0) { echo __('Schema Version Information Unavailable', array('version' => $Version)); exit; } $Model->Fetch(); $Current = $Model->Get('Version'); $Script = $Model->Get('Script'); // If the current and the expected schema version don't match, give a suggested update scripts to run. if ($Current != $Version) { echo __('Incorrect Schema Version', array('version' => $Version, 'current' => $Current, 'script' => $Script)); exit; } return true; }
public function EndFooterDisplay($pData = null) { $Model = new cModel('Janitor'); $Model->Retrieve(array('Task' => 'Janitorial')); $Model->Fetch(); $lastUpdated = strtotime($Model->Get('Updated')); $now = strtotime(NOW()); $diff = $now - $lastUpdated; $diffMinutes = $diff / 60; // If we've recently updated, don't ping the Janitor. if ($diffMinutes < 1) { return true; } $this->_Janitorial(); return true; }
public function Load($pUser) { $UserAccounts = new cModel("UserAccounts"); $UserAccounts->Structure(); if (is_int($pUser)) { $UserAccounts->Retrieve(array('Account_PK' => $pUser)); } else { $UserAccounts->Retrieve(array('Username' => $pUser)); } $UserAccounts->Fetch(); if (!$UserAccounts->Get("Username")) { return false; } $this->Username = $UserAccounts->Get("Username"); $this->Id = $UserAccounts->Get("Account_PK"); // Load the user profile information. $UserProfile = new cModel("UserProfile"); $UserProfile->Retrieve(array("Account_FK" => $UserAccounts->Get("Account_PK"))); $UserProfile->Fetch(); $this->Account_PK = $UserProfile->Get("Account_FK"); if ($UserProfile->Get("Alias")) { $this->Fullname = $UserProfile->Get("Alias"); } else { $this->Fullname = $UserProfile->Get("Fullname"); } $this->Description = $UserProfile->Get("Description"); $this->Domain = $_SERVER['HTTP_HOST']; $this->Account = $this->Username . '@' . $this->Domain; $this->Email = $UserAccounts->Get('Email'); $this->Remote = false; 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 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; }
public function Access($pData = null) { // Only allow internal components to get access information. $Source = $this->Get('Source'); if ($Source != 'Component') { return false; } $account = isset($pData['account']) ? $pData['account'] : null; $context = isset($pData['context']) ? $pData['context'] : null; $access = new cSecurityAccess(); if (!$account) { $user = $this->GetSys("Components")->Talk("User", "Current"); // No user is logged in, so send back the defaults. if (!$user) { $access->Set("Read", isset($pData['Read']) ? $pData['Read'] : false); $access->Set("Write", isset($pData['Write']) ? $pData['Write'] : false); $access->Set("Admin", isset($pData['Admin']) ? $pData['Admin'] : false); return $access; } $account = $user->Username . '@' . $user->Domain; } if (!$context) { $context = $_SERVER['REQUEST_URI']; } $account = strtolower($account); // Return cached value to avoid duplicate effort. if (isset($this->_Cache[$account][$context])) { return $this->_Cache[$account][$context]; } $accessModel = new cModel("AccessControl"); $domain = ASD_DOMAIN; $pattern = '/(.*)@' . $domain . '/'; if (preg_match($pattern, $account)) { list($username, $domain) = explode('@', $account); } // Load security settings from AccessControl. $criteria = array(array("account" => $account, "||account" => $username), "Location" => $context); $accessModel->Retrieve($criteria); $accessModel->Fetch(); // If no entries were found, go backwards for inheritance. if ($accessModel->Get("Total") == 0 and $context != '/') { // Remove top directory off of Location. $currentLocation = strrchr(rtrim($context, "/"), "/"); $currentLocationpos = strpos($context, $currentLocation); $parentLocation = substr($context, 0, $currentLocationpos + 1); // Use recursive call of this function. $parameters['account'] = $account; $parameters['context'] = $parentLocation; $parentAccess = $this->Access($parameters); if ($parentAccess->Get("Inheritance")) { // Inherit parent values. $access->Set("Inheritance", $parentAccess->Get("Inheritance")); $access->Set("Read", $parentAccess->Get("Read")); $access->Set("Write", $parentAccess->Get("Write")); $access->Set("Admin", $parentAccess->Get("Admin")); } else { // Use default values; $this->AccessControl->Location = $context; $access->Set("Read", isset($pData['Read']) ? $pData['Read'] : false); $access->Set("Write", isset($pData['Write']) ? $pData['Write'] : false); $access->Set("Admin", isset($pData['Admin']) ? $pData['Admin'] : false); } // if unset($parentAccess); } else { $access->Set("Read", $accessModel->Get("Read")); $access->Set("Write", $accessModel->Get("Write")); $access->Set("Admin", $accessModel->Get("Admin")); $access->Set("Inheritance", $accessModel->Get("Inheritance")); } // if // Store result in internal cache. $this->_Cache[$account][$context] = $access; return $access; }
public function CreateRelationship($pFirst, $pSecond) { $UserAccounts = new cModel('UserAccounts'); $UserAccounts->Retrieve(array('Account_PK' => $pFirst)); $UserAccounts->Fetch(); $firstUsername = $UserAccounts->Get('Username'); $UserAccounts->Retrieve(array('Account_PK' => $pSecond)); $UserAccounts->Fetch(); $secondUsername = $UserAccounts->Get('Username'); // Create first record $this->Set('Owner_FK', $pFirst); $this->Set('Username', $secondUsername); $this->Set('Domain', ASD_DOMAIN); $this->Set('Verification', 1); $this->Set("Created", NOW()); $this->Save(); // Create second record $this->Set('Friend_PK', NULL); $this->Set('Owner_FK', $pSecond); $this->Set('Username', $firstUsername); $this->Set('Domain', ASD_DOMAIN); $this->Set('Verification', 1); $this->Set("Created", NOW()); $this->Save(); return true; }
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; }