public function send($to, $subject, $message, $from = NULL, $attachments = NULL) { if ($attachments != NULL) { throw new ServiceException("INVALID_CONFIGURATION", "Default mailer does not support sending attachments"); } if (Logging::isDebug()) { Logging::logDebug("Sending mail to [" . Util::array2str($to) . "]: [" . $message . "]"); } if (!$this->enabled) { return; } $isHtml = stripos($message, "<html>") !== FALSE; $f = $from != NULL ? $from : $this->env->settings()->setting("mail_notification_from"); $validRecipients = $this->getValidRecipients($to); if (count($validRecipients) === 0) { Logging::logDebug("No valid recipient email addresses, no mail sent"); return; } $toAddress = ''; $headers = $isHtml ? 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8' . "\r\n" : 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=utf-8' . "\r\n"; $headers .= 'From:' . $f; if (count($validRecipients) == 1) { $toAddress = $this->getRecipientString($validRecipients[0]); } else { $headers .= PHP_EOL . $this->getBccHeaders($validRecipients); } mail($toAddress, $subject, $isHtml ? $message : str_replace("\n", "\r\n", wordwrap($message)), $headers); }
public function processPost() { $data = $this->request->data; if (!isset($data['to']) or !isset($data['title']) or !isset($data['msg']) or !isset($data['items'])) { throw $this->invalidRequestException("Data missing"); } $to = $data['to']; $message = $data['msg']; $title = $data['title']; $items = $this->items($data['items']); if (count($items) == 0) { throw $this->invalidRequestException("Items missing"); } if (Logging::isDebug()) { Logging::logDebug("SENDVIAEMAIL: Sending mail " . $to . ":" . Util::array2str($items)); } $attachments = array(); foreach ($items as $i) { $attachments[] = $i->internalPath(); } //TODO stream if ($this->env->mailer()->send(array($to), $title, $message, NULL, $attachments)) { $this->response()->success(array()); } else { $this->response()->error("REQUEST_FAILED", NULL); } }
function log() { if (!Logging::isDebug()) { return; } Logging::logDebug("PLUGIN (" . get_class($this) . ")"); }
public function send($to, $subject, $message, $from = NULL, $attachments = NULL) { if (!$this->enabled) { return; } $isHtml = stripos($message, "<html>") !== FALSE; $f = $from != NULL ? $from : $this->env->settings()->setting("mail_notification_from"); $validRecipients = $this->getValidRecipients($to); if (count($validRecipients) === 0) { Logging::logDebug("No valid recipient email addresses, no mail sent"); return; } if (Logging::isDebug()) { Logging::logDebug("Sending mail from [" . $f . "] to [" . Util::array2str($validRecipients) . "]: [" . $message . "]"); } set_include_path("vendor/PHPMailer" . DIRECTORY_SEPARATOR . PATH_SEPARATOR . get_include_path()); require 'class.phpmailer.php'; $mailer = new PHPMailer(); $smtp = $this->env->settings()->setting("mail_smtp"); if ($smtp != NULL and isset($smtp["host"])) { $mailer->isSMTP(); $mailer->Host = $smtp["host"]; if (isset($smtp["username"]) and isset($smtp["password"])) { $mailer->SMTPAuth = true; $mailer->Username = $smtp["username"]; $mailer->Password = $smtp["password"]; } if (isset($smtp["secure"])) { $mailer->SMTPSecure = $smtp["secure"]; } } $mailer->From = $f; foreach ($validRecipients as $recipient) { $mailer->addBCC($recipient["email"], $recipient["name"]); } if (!$isHtml) { $mailer->WordWrap = 50; } else { $mailer->isHTML(true); } if ($attachments != NULL) { //TODO use stream foreach ($attachments as $attachment) { $mailer->addAttachment($attachment); } } $mailer->Subject = $subject; $mailer->Body = $message; try { if (!$mailer->send()) { Logging::logError('Message could not be sent: ' . $mailer->ErrorInfo); return FALSE; } return TRUE; } catch (Exception $e) { Logging::logError('Message could not be sent: ' . $e); return FALSE; } }
public function retrieve($url) { if (Logging::isDebug()) { Logging::logDebug("Retrieving [{$url}]"); } $h = curl_init(); if (!$h) { throw new ServiceException("INVALID_CONFIGURATION", "Failed to initialize curl: " . curl_errno() . " " . curl_error()); } if (!curl_setopt($h, CURLOPT_URL, $url)) { curl_close($h); throw new ServiceException("INVALID_CONFIGURATION", "Failed to initialize curl: " . curl_errno() . " " . curl_error()); } $tempFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('Kloudspeaker', true); $fh = @fopen($tempFile, "wb"); if (!$fh) { curl_close($h); throw new ServiceException("INVALID_CONFIGURATION", "Could not open temporary file for writing: " . $tempFile); } if (!curl_setopt($h, CURLOPT_FILE, $fh) or !curl_setopt($h, CURLOPT_HEADER, 0)) { fclose($fh); curl_close($h); throw new ServiceException("INVALID_CONFIGURATION", "Failed to initialize curl: " . curl_errno() . " " . curl_error()); } set_time_limit(0); $success = curl_exec($h); $status = FALSE; $errorNo = 0; $error = NULL; if ($success) { $status = curl_getinfo($h, CURLINFO_HTTP_CODE); } else { $errorNo = curl_errno($h); $error = curl_error($h); Logging::logDebug("Failed to retrieve url: {$errorNo} {$error}"); } fclose($fh); curl_close($h); if (!$success) { if ($errorNo === 6) { return array("success" => false, "result" => 404); } throw new ServiceException("REQUEST_FAILED", $error); } if ($status !== 200) { if (file_exists($tempFile)) { unlink($tempFile); } return array("success" => false, "result" => $status); } return array("success" => true, "file" => $tempFile, "stream" => @fopen($tempFile, "rb"), "name" => $this->getName($url)); }
private function setup() { $this->environment->addService("authentication", "AuthenticationServices"); $this->environment->addService("session", "SessionServices"); $this->environment->addService("configuration", "ConfigurationServices"); $this->environment->addService("filesystem", "FilesystemServices"); $this->environment->addService("events", "EventServices"); $this->environment->addService("permissions", "PermissionServices"); if (Logging::isDebug()) { $this->environment->addService("debug", "DebugServices"); $this->environment->response()->addListener($this); } UserEvent::register($this->environment->events()); $this->environment->permissions()->registerPermission("change_password"); $this->environment->plugins()->setup(); }
function log() { if (!Logging::isDebug()) { return; } $logged = array_merge(array(), $this->settings); // remove db password if (Util::isArrayKey($logged, "db") and is_array($logged["db"])) { if (Util::isArrayKey($logged["db"], "pw")) { $logged["db"]["pw"] = ""; } if (Util::isArrayKey($logged["db"], "password")) { $logged["db"]["password"] = ""; } } Logging::logDebug("SETTINGS: " . Util::array2str($logged)); }
function globalErrorHandler($errno, $errstr, $errfile, $errline) { global $responseHandler; $info = "PHP error #" . $errno . ", " . $errstr . " (" . $errfile . ":" . $errline . ")"; if (Logging::isDebug()) { $data = debug_backtrace(); } else { $msg = "Backtrace disabled as it may contain passwords. "; $msg .= "Enable 'debug' setting in configuration.php to see "; $msg .= "backtrace."; $data = array("NOTE" => $msg); } Logging::logError($info . "\n" . Util::array2str($data)); if ($responseHandler == NULL) { $responseHandler = new ResponseHandler(new OutputHandler()); } $responseHandler->unknownServerError($info); die; }
public function onEvent($e) { if ($this->env->authentication()->isAuthenticated()) { $e->setUser(array('user_id' => $this->env->session()->userId(), 'username' => $this->env->session()->username())); } else { $e->setUser(NULL); } $e->setIp($this->env->request()->ip()); if (Logging::isDebug()) { Logging::logDebug("EVENT HANDLER: onEvent: '" . $e->type() . "'"); } foreach ($this->listeners as $type => $listeners) { if (strcasecmp($type, '*') == 0 or strpos($e->typeId(), $type) === 0) { foreach ($listeners as $listener) { $listener->onEvent($e); } } } }
public function onEvent($e) { if ($this->env->authentication()->isAuthenticated()) { $user = $this->env->session()->user(); $e->setUser(array('id' => $user["id"], 'name' => $user["name"], 'email' => $user["email"])); } else { $e->setUser(NULL); } $e->setIp($this->env->request()->ip()); if (Logging::isDebug()) { Logging::logDebug("EVENT HANDLER: onEvent: " . $e->type() . "/" . $e->subType()); } foreach ($this->listeners as $type => $listeners) { if (strcasecmp($type, '*') == 0 or strpos($e->typeId(), $type) === 0) { foreach ($listeners as $listener) { $listener->onEvent($e); } } } }
function is_devurandom() { if (Logging::isDebug()) { Logging::logDebug("/dev/urandom: " . ($this->no_devurandom ? "0" : "1")); } if ($this->no_devurandom) { return FALSE; } if (Logging::isDebug()) { Logging::logDebug("Trying /dev/urandom"); } try { if (@is_readable('/dev/urandom')) { return TRUE; } } catch (Exception $e) { } if (Logging::isDebug()) { Logging::logDebug("/dev/urandom not accessible"); } return FALSE; }
private function sendNotification($notification, $e) { $values = $e->values($this->env->formatter()); $title = $this->getTitle($notification, $values); $message = $this->getMessage($notification, $values); if (Logging::isDebug()) { Logging::logDebug("NOTIFICATOR: Sending notification " . $notification->id() . ":" . $message); } $this->env->mailer()->send($notification->getRecipients(), $title, $message); }
private function getErrorResponse($err, $details, $data = NULL) { if (Logging::isDebug()) { Logging::logDebug("RESPONSE error " . Util::toString($err) . " " . Util::toString($details) . " " . Util::toString($data)); return array("code" => $err[0], "error" => $err[1], "details" => $details, "data" => $data, "trace" => Logging::getTrace()); } return array("code" => $err[0], "error" => $err[1], "details" => $details, "data" => $data); }
public function rollback() { try { $result = @mysqli_query($this->db, "ROLLBACK;"); } catch (mysqli_sql_exception $e) { if (Logging::isDebug()) { Logging::logDebug("ERROR: " . $e); } throw new ServiceException("INVALID_CONFIGURATION", "Error rollbacking transaction: " . mysqli_error($this->db)); } if (!$result) { throw new ServiceException("INVALID_CONFIGURATION", "Error rollbacking transaction: " . mysqli_error($this->db)); } $this->transaction = FALSE; }
public function queries($query) { if (Logging::isDebug()) { Logging::logDebug("DB: " . $query); } @sqlite_query($query, $this->db, SQLITE_NUM, $err); if ($err) { throw new ServiceException("INVALID_CONFIGURATION", "Error executing query (" . $query . "): " . $err); } return TRUE; }
public function query($query) { if (Logging::isDebug()) { Logging::logDebug("DB: " . $query); } $result = @mysql_query($query, $this->db); if (!$result) { throw new ServiceException("INVALID_CONFIGURATION", "Error executing query (" . $query . "): " . mysql_error($this->db)); } return new Result($this->db, $result); }
public function log() { if (!Logging::isDebug()) { return; } Logging::logSystem(); $this->settings->log(); $this->configuration->log(); $this->features->log(); $this->filesystem->log(); $this->session->log(); $this->authentication->log(); if ($this->request) { $this->request->log(); } }
function Footer() { if (!$this->isInFooter()) { return; } $y = 0 - $this->opt["height"]; if (Logging::isDebug()) { Logging::logDebug("Footer " . Util::array2str(array("x" => $this->xd, "y" => $y, "w" => $this->wd, "align" => $this->align, "opt" => $this->opt))); } $this->setTextProperties(); $this->setXY($this->xd, $y); $this->Cell($this->wd, $this->opt["height"], $this->opt["text"], 0, 0, $this->align == "X" ? "L" : $this->align); }
public function queries($sql) { if (Logging::isDebug()) { Logging::logDebug("DB: " . $sql); } try { $this->db->exec($sql); //$stmt->execute(); } catch (PDOException $e) { if (Logging::isDebug()) { Logging::logDebug("ERROR: " . $e->getMessage()); } throw new ServiceException("INVALID_CONFIGURATION", "Error executing queries (" . (strlen($sql) > 40 ? substr($sql, 0, 40) . "..." : $sql) . "...): " . $e->getMessage()); } }
public function uploadFrom($folder, $name, $stream, $src = '[Unknown]') { $this->assertUploadFileType($name); $this->assertRights($folder, self::PERMISSION_LEVEL_READWRITE, "upload"); $targetItem = $folder->createFile($name); if (Logging::isDebug()) { Logging::logDebug("Upload from {$src} ({$name}) to " . $targetItem->id()); } $targetItem->write($stream, FALSE); $this->env->events()->onEvent(FileEvent::upload($targetItem)); }
public function queries($query) { if (Logging::isDebug()) { Logging::logDebug("DB: " . $query); } $result = $this->db->exec($query); if (!$result) { throw new ServiceException("INVALID_CONFIGURATION", "Error executing query (" . $query . "): " . $this->db->lastErrorMsg()); } return TRUE; }