+ function checkForSecureConnection() {
+ $errors = array();
+ if (($_SERVER['SERVER_PORT'] != 443) && !$this->running_on_localhost) {
+ $errors[] = _('You are not accessing this site on a secure connection, so authentication doesn\'t work.');
+ }
+ return $errors;
+ }
+
+ function initSession() {
+ $session = null;
+ if (strlen(@$_COOKIE['sessionkey'])) {
+ // Fetch the session - or at least try to.
+ $result = $this->db->prepare('SELECT * FROM `auth_sessions` WHERE `sesskey` = :sesskey AND `time_expire` > :expire;');
+ $result->execute(array(':sesskey' => $_COOKIE['sessionkey'], ':expire' => gmdate('Y-m-d H:i:s')));
+ $row = $result->fetch(PDO::FETCH_ASSOC);
+ if ($row) {
+ $session = $row;
+ }
+ }
+ if (is_null($session)) {
+ // Create new session and set cookie.
+ $sesskey = $this->createSessionKey();
+ setcookie('sessionkey', $sesskey, 0, "", "", !$this->running_on_localhost, true); // Last two params are secure and httponly, secure is not set on localhost.
+ $result = $this->db->prepare('INSERT INTO `auth_sessions` (`sesskey`, `time_expire`) VALUES (:sesskey, :expire);');
+ $result->execute(array(':sesskey' => $sesskey, ':expire' => gmdate('Y-m-d H:i:s', strtotime('+5 minutes'))));
+ // After insert, actually fetch the session row from the DB so we have all values.
+ $result = $this->db->prepare('SELECT * FROM auth_sessions WHERE `sesskey` = :sesskey AND `time_expire` > :expire;');
+ $result->execute(array(':sesskey' => $sesskey, ':expire' => gmdate('Y-m-d H:i:s')));
+ $row = $result->fetch(PDO::FETCH_ASSOC);
+ if ($row) {
+ $session = $row;
+ }
+ else {
+ $this->log('session_create_failure', 'key: '.$sesskey);
+ }
+ }
+ return $session;
+ }
+