private function __construct() { $variableEngine = VariableEngine::getInstance(); $variablesWanted[] = 'siteTitle'; $variablesWanted[] = 'siteEmail'; $variablesWanted[] = 'siteTheme'; $variablesWanted[] = 'siteWebAddress'; $variablesWanted[] = 'siteWebAddressSecure'; $variablesWanted[] = 'siteWebDirectory'; $variablesWanted[] = 'educaskVersion'; $variablesWanted[] = 'guestRoleID'; $variablesWanted[] = 'cleanURLsEnabled'; $variablesWanted[] = 'siteTimeZone'; $variablesWanted[] = 'maintenanceMode'; $variablesWanted[] = 'cronRunning'; $variablesWanted[] = 'cronFrequency'; $variablesWanted[] = 'lastCronRun'; $variablesWanted[] = 'maxSessionIdAge'; $variables = $variableEngine->getVariables($variablesWanted); $this->title = $variables['siteTitle']; $this->email = $variables['siteEmail']; $this->url = $variables['siteWebAddress']; $this->urlSecure = $variables['siteWebAddressSecure']; $this->baseDirectory = $variables['siteWebDirectory']; $this->theme = $variables['siteTheme']; $this->educaskVersion = $variables['educaskVersion']; $this->guestRoleID = $variables['guestRoleID']; $this->cleanURLs = $variables['cleanURLsEnabled']; $this->timeZone = $variables['siteTimeZone']; $this->maintenanceMode = $variables['maintenanceMode']; $this->cronRunning = $variables['cronRunning']; $this->cronFrequency = $variables['cronFrequency']; $this->lastCronRun = $variables['lastCronRun']; $this->maxSessionIdAge = $variables['maxSessionIdAge']; }
public function setNumberOfAttemptsBeforeLockout($inNumberOfAttempts) { if (!is_int($inNumberOfAttempts)) { return false; } $variableEngine = VariableEngine::getInstance(); $numberOfAttemptsBeforeLockout = $variableEngine->getVariable('numberOfAttemptsBeforeLockout'); $numberOfAttemptsBeforeLockout->setValue($inNumberOfAttempts); $success = $numberOfAttemptsBeforeLockout->save(); if ($success === false) { return false; } return true; }
public static function run($inContent = '') { $user = currentUser::getUserSession(); if ($user->isLoggedIn()) { return; } $pluginEnabled = VariableEngine::getInstance()->getVariable('ldapEnabled'); if ($pluginEnabled === false) { return; } if ($pluginEnabled->getValue() === 'false') { return; } $variableEngine = VariableEngine::getInstance(); $ldapServer = $variableEngine->getVariable('ldapServer'); if ($ldapServer === false) { return; } $ldapDomain = $variableEngine->getVariable('ldapDomain'); if ($ldapDomain === false) { return; } $ldapIsActiveDirectory = $variableEngine->getVariable('ldapIsActiveDirectory'); if ($ldapIsActiveDirectory === false) { return; } $ldapConnection = ldap_connect($ldapServer->getValue()); if (!$ldapConnection) { return; } ldap_set_option($ldapConnection, LDAP_OPT_REFERRALS, 0); ldap_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_start_tls($ldapConnection); $userName = htmlspecialchars($_POST['username']); $password = htmlspecialchars($_POST['password']); if ($userName === null) { return; } if ($userName === '') { return; } if ($password === null) { return; } if ($password === '') { return; } $authenticated = ldap_bind($ldapConnection, $userName . '@' . $ldapDomain->getValue(), $password); unset($password); if (!$authenticated) { ldap_close($ldapConnection); return; } $database = database::getInstance(); $userName = $database->escapeString($userName); $haveSeenBefore = $database->getData('userID', 'activeDirectory', 'WHERE adUsername=\'' . $userName . '\''); if ($haveSeenBefore === null) { $ou = $variableEngine->getVariable('ldapOrganizationUnit'); if ($ou === false) { ldap_close($ldapConnection); return; } $dn = 'cn=' . $userName . ',ou=' . $ou->getValue(); $domain = explode('.', $ldapDomain->getValue()); $numberOfSubServers = count($domain); for ($i = 0; $i < $numberOfSubServers; $i++) { $dn .= ',dc=' . $domain[$i]; } $search = ldap_read($ldapConnection, $dn, '(objectclass=*)', array('sn', 'givenname', 'mail')); if (!$search) { ldap_close($ldapConnection); return; } $info = ldap_get_entries($ldapConnection, $search); ldap_close($ldapConnection); if ($info['count'] !== 1) { return; } $function = new general('generateRandomString'); $password = $function->run(array('length' => 50)); $defaultRoleID = $variableEngine->getVariable('ldapDefaultRoleID'); if ($defaultRoleID === false) { return; } $defaultRoleID = $defaultRoleID->getValue(); //No email found in ad if ($info[0]['count'] === 2) { if ($info[0]['sn']['count'] !== 1) { return; } if ($info[0]['givenname']['count'] !== 1) { return; } $firstName = $info[0]['givenname'][0]; $lastName = $info[0]['sn'][0]; if (!self::addUser($firstName, $lastName, $userName, $password, $defaultRoleID)) { return; } self::logIn($userName); return; } //3 = the number of fields requested. if ($info[0]['count'] !== 3) { ldap_close($ldapConnection); return; } if ($info[0]['sn']['count'] !== 1) { ldap_close($ldapConnection); return; } if ($info[0]['givenname']['count'] !== 1) { ldap_close($ldapConnection); return; } if ($info[0]['mail']['count'] !== 1) { ldap_close($ldapConnection); return; } $firstName = $info[0]['givenname'][0]; $lastName = $info[0]['sn'][0]; $email = $info[0]['mail'][0]; if (!self::addUser($firstName, $lastName, $userName, $password, $defaultRoleID, $email)) { return; } self::logIn($userName); return; } ldap_close($ldapConnection); self::logIn($userName); }
public function getMinimumPasswordLength() { $variableEngine = VariableEngine::getInstance(); $minimumPasswordLength = $variableEngine->getVariable('minimumPasswordLength'); $default = 10; if ($minimumPasswordLength === null) { return $default; } if ($minimumPasswordLength === false) { return $default; } if (!is_numeric($minimumPasswordLength->getValue())) { return $default; } return intval($minimumPasswordLength->getValue()); }
public function sendMail() { $siteEmail = SITE_EMAIL; $variableEngine = VariableEngine::getInstance(); $smtpServer = $variableEngine->getVariable('smtpServer'); if ($smtpServer === false) { return false; } $smtpPort = $variableEngine->getVariable('smtpPort'); if ($smtpPort === false) { return false; } $smtpUserName = $variableEngine->getVariable('smtpUserName'); if ($smtpUserName === false) { return false; } $smtpPassword = $variableEngine->getVariable('smtpPassword'); if ($smtpPassword === false) { return false; } $smtpUseEncryption = $variableEngine->getVariable('smtpUseEncryption'); if ($smtpUseEncryption === false) { return false; } $smtpUseEncryption = $smtpUseEncryption->getValue(); if ($smtpUseEncryption === 'false') { $encryption = ""; } else { $encryption = "tls"; } $toSend = new PHPMailer(); $toSend->isSMTP(); $toSend->Host = $smtpServer->getValue(); $toSend->SMTPAuth = true; $toSend->Username = $smtpUserName->getValue(); $enc = new Encrypter(); $toSend->Password = $enc->decrypt($smtpPassword->getValue()); $toSend->SMTPSecure = $encryption; $toSend->Port = intval($smtpPort->getValue()); $toSend->From = $siteEmail; $toSend->FromName = $this->senderName; $toSend->addReplyTo($this->senderEmail, $this->senderName); $toSend->isHTML(true); $toSend->Subject = $this->subject; if ($this->isBulkMail) { foreach ($this->recipients as $recipient) { $toSend->addBCC($recipient); } $toSend->Body = $this->body; $toSend->AltBody = strip_tags($this->body); if (!$toSend->send()) { $this->errors[] = $toSend->ErrorInfo; return false; } return true; } $sent = true; foreach ($this->recipients as $recipient) { $body = $this->doReplacement($recipient); $altBody = strip_tags($body); $toSend->clearAddresses(); $toSend->addAddress($recipient); $toSend->Body = $body; $toSend->AltBody = $altBody; if (!$toSend->send()) { $this->errors = $toSend->ErrorInfo; $sent = false; } } return $sent; }
public function save() { return VariableEngine::getInstance()->saveVariable($this); }
public static function setCookie($name, $value) { if (!is_string($name)) { return; } if (!is_string($value)) { return; } $variableEngine = VariableEngine::getInstance(); $siteInfo = $variableEngine->getVariables(array("siteWebAddress", "siteWebDirectory")); $directory = $siteInfo['siteWebDirectory']->getValue(); $url = parse_url($siteInfo['siteWebAddress']->getValue()); if ($url === false) { setcookie($name, $value, 0, $directory, null, false, true); return; } setcookie($name, $value, 0, $directory, $url['host'], false, true); }