- @ldap_close($ds);
- } else {
- $this->loginStatus = 'Connect to LDAP server failed';
- }
-
- return $result;
- }
-
- public function getLoginStatus() {
- return $this->loginStatus;
- }
-
- public function isLoggedIn() {
- global $CFG;
- $loggedIn = false;
-
- if ($this->user) {
- $loggedIn = true;
- } else if (isset($_SESSION['user'])) {
- $this->user = $_SESSION['user'];
- $loggedIn = true;
- } else {
- if ($CFG->auth_method == 'HTTP_AUTH') {
- if (isset($this->server['PHP_AUTH_USER'])) {
- $this->user = $this->server['PHP_AUTH_USER'];
- $loggedIn = true;
- }
- }
- }
-
- return $loggedIn;
- }
-
- public function getUser() {
- $this->isLoggedIn();
- return $this->user;
- }
-
- public function getHeader() {
- return $this->header;
- }
-
- public function getFooter() {
- return $this->footer;
- }
-
- public function getHeading() {
- return $this->heading;
- }
-
- public function setHeading($heading) {
- global $CFG;
-
- $timeout = $CFG->session_timeout * 60 * 1000;
- $this->heading = str_replace('__TITLE__', $heading, $this->heading);
- $this->header = str_replace('__TITLE__', $heading, $this->header);
- $this->header = str_replace('__ROOT__', $CFG->wwwroot, $this->header);
- $this->header = str_replace('__TIMEOUT__', $timeout, $this->header);
- }
-
- public function convertContent($code) {
- $table = array(
- 'V' => 'Virus',
- 'B' => 'Banned',
- 'U' => 'Unchecked',
- 'S' => 'Spam',
- 'Y' => 'Spammy',
- 'M' => 'Bad Mime',
- 'H' => 'Bad Header',
- 'O' => 'Over sized',
- 'T' => 'MTA err',
- 'C' => 'Clean'
- );
-
- $string = $table[$code];
- if (empty($string))
- $string = 'Unknown';
-
- return $string;
- }
+ }
+
+ $_SESSION['settings'] = $this->settings;
+
+ return $result;
+ }
+
+ public function getLoginStatus() {
+ $status = 'Not logged in';
+
+ $this->log("getLoginStatus", 4);
+
+ if (isset($this->settings['loginStatus'])) {
+ $status = $this->settings['loginStatus'];
+ }
+
+ return $status;
+ }
+
+ public function isLoggedIn() {
+ global $CFG;
+ $loggedIn = false;
+
+ $this->log("isLoggedIn[1]: user ".var_export($this->settings['user'], true), 3);
+
+ if ('' == session_id()) {
+ $this->startSession();
+ }
+
+ $this->log("isLoggedIn[2]: user ".var_export($this->settings['user'], true), 3);
+ $this->checkSession();
+ $this->log("isLoggedIn[3]: user ".var_export($this->settings['user'], true), 3);
+
+ if (isset($this->settings['user'])) {
+ if ($this->settings['user'] != null) {
+ $loggedIn = true;
+ } else {
+ if ($CFG->auth_method == 'HTTP_AUTH') {
+ if (isset($_SERVER['PHP_AUTH_USER'])) {
+ $this->settings['user'] = $_SERVER['PHP_AUTH_USER'];
+ $loggedIn = true;
+ }
+ }
+ }
+ }
+
+ if ($loggedIn == false) {
+ $this->log('$this->settings: '.var_export($this->settings, true), 3);
+ $this->log('R_TIME: '.date('c', $_SERVER['REQUEST_TIME']).' L_ACT: '.date('c', $_SESSION['LAST_ACTIVITY']), 3);
+ }
+
+ $_SESSION['settings'] = $this->settings;
+
+ return $loggedIn;
+ }
+
+ public function getUser() {
+ $user = null;
+
+ $this->log("getUser", 4);
+
+ if ($this->isLoggedIn()) {
+ $user = $this->settings['user'];
+ }
+
+ return $user;
+ }
+
+ public function authorized($recipient) {
+ $authorized = false;
+
+ $this->log("authorized '$recipient'", 3);
+
+ if ($this->isAdmin() || $this->getUser() == $recipient) {
+ $authorized = true;
+ }
+ $msg = ($authorized) ? 'authorize' : 'not authorize';
+ $this->log("$msg '".$this->getUser()."' rcpt '$recipient'", 3);
+
+ return $authorized;
+ }
+
+ public function getHeader() {
+ $this->log("getHeader", 4);
+
+ return $this->header;
+ }
+
+ public function getFooter() {
+ $this->log("getFooter", 4);
+
+ return $this->footer;
+ }
+
+ public function getHeading() {
+ $this->log("getHeading", 4);
+
+ return $this->heading;
+ }
+
+ public function setHeading($heading) {
+ global $CFG;
+
+ $this->log("setHeading", 4);
+
+ $timeout = $CFG->session_timeout * 60 * 1000;
+ $this->heading = str_replace('__TITLE__', $heading, $this->heading);
+ $this->header = str_replace('__TITLE__', $heading, $this->header);
+ $this->header = str_replace('__ROOT__', $CFG->wwwroot, $this->header);
+ $this->header = str_replace('__TIMEOUT__', $timeout, $this->header);
+ }
+
+ public function convertContent($code) {
+ $this->log("convertContent", 4);
+
+ $table = array(
+ 'V' => 'Virus',
+ 'B' => 'Banned',
+ 'U' => 'Unchecked',
+ 'S' => 'Spam',
+ 'Y' => 'Spammy',
+ 'M' => 'Bad Mime',
+ 'H' => 'Bad Header',
+ 'O' => 'Over sized',
+ 'T' => 'MTA err',
+ 'C' => 'Clean'
+ );
+
+ $string = $table[$code];
+ if (empty($string))
+ $string = 'Unknown';
+
+ return $string;
+ }
+
+ public function RESTCall($url, $data = null, $cookiesIn = '', $headers = null) {
+ $options = array(
+ CURLOPT_RETURNTRANSFER => true, // return web page
+ CURLOPT_HEADER => true, //return headers in addition to content
+ CURLOPT_FOLLOWLOCATION => true, // follow redirects
+ CURLOPT_ENCODING => "", // handle all encodings
+ CURLOPT_AUTOREFERER => true, // set referer on redirect
+ CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
+ CURLOPT_TIMEOUT => 120, // timeout on response
+ CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
+ CURLINFO_HEADER_OUT => true,
+ CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+ CURLOPT_COOKIE => $cookiesIn
+ );
+
+ if ($data) {
+ $options[CURLOPT_POST] = 1;
+ $options[CURLOPT_POSTFIELDS] = $data;
+ }
+
+ if ($headers) {
+ $options[CURLOPT_HTTPHEADER] = $headers;
+ }
+
+ $ch = curl_init($url);
+ curl_setopt_array($ch, $options);
+ $rough_content = curl_exec($ch);
+ $err = curl_errno($ch);
+ $errmsg = curl_error($ch);
+ $header = curl_getinfo($ch);
+ curl_close($ch);
+
+ $header_content = substr($rough_content, 0, $header['header_size']);
+ $body_content = trim(str_replace($header_content, '', $rough_content));
+ $pattern = "#Set-Cookie:\\s+(?<cookie>[^=]+=[^;]+)#m";
+ preg_match_all($pattern, $header_content, $matches);
+ $cookiesOut = implode("; ", $matches['cookie']);
+
+ $header['errno'] = $err;
+ $header['errmsg'] = $errmsg;
+ $header['headers'] = $header_content;
+ $header['content'] = $body_content;
+ $header['cookies'] = $cookiesOut;