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; } }
private function putToCache($name, $subject, $value) { if (!array_key_exists($name, $this->permissionCaches)) { $this->permissionCaches[$name] = array(); } $this->permissionCaches[$name][$subject] = $value; Logging::logDebug("Permission cache put [" . $name . "/" . $subject . "]=" . $value); }
public function getShareInfo($id, $share) { $ic = $this->dao()->getItemCollection($id); if (!$ic) { Logging::logDebug("Invalid share request, no item collection found with id " . $id); return NULL; } return array("name" => $ic["name"], "type" => "prepared_download"); }
public function getShareItem($id) { $ic = $this->dao()->getItemCollection($id); if (!$ic) { Logging::logDebug("Invalid share request, no item collection found with id " . $id); return NULL; } return array("name" => $ic["name"]); }
function globalExceptionHandler($e) { global $responseHandler; Logging::logException($e); Logging::logDebug(Util::array2str(debug_backtrace())); if ($responseHandler == NULL) { $responseHandler = new ResponseHandler(new OutputHandler()); } $responseHandler->unknownServerError($e->getMessage()); die; }
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)); }
public function loadTexts($file, $curDir) { $file .= ".txt"; $cl = $this->getCustomizationsAbsoluteLocation($file); if ($cl != NULL) { Logging::logDebug("ResourceLoader: Seeking " . $cl); if (file_exists($cl)) { return $this->loadTextFile($cl); } } Logging::logDebug("ResourceLoader: Seeking " . $curDir . DIRECTORY_SEPARATOR . $file); return $this->loadTextFile($curDir . DIRECTORY_SEPARATOR . $file); }
public function processGet() { if (count($this->path) != 1) { throw $this->invalidRequestException(); } $item = $this->item($this->path[0]); $comments = $this->handler()->getComments($item); $permission = $this->env->request()->hasParamValue("p", "1"); Logging::logDebug("PERM" . ($permission ? "1" : "0")); if (!$permission) { $this->response()->success($comments); } else { $this->response()->success(array("comments" => $comments, "permission" => $this->env->permissions()->getFilesystemPermission("comment_item", $item))); } }
public function authenticate($user, $pw, $auth) { if ($auth["salt"] == "-" and $auth["hash"] == "-") { $oldPw = $this->env->configuration()->getUserLegacyPw($user["id"]); // old pw auth if (strcmp($oldPw, md5($pw)) != 0) { return FALSE; } //convert old pws into hash Logging::logDebug("Adding new user hash for " . $user["id"]); $this->env->configuration()->storeUserAuth($user["id"], $user["name"], $auth["type"], $pw); return TRUE; } return $this->env->passwordHash()->isEqual($pw, $auth["hash"], $auth["salt"]); }
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)); }
private function updateIds($tables, $ids, $db) { if (strcmp("mysql", $db->type()) === 0) { mysqli_report(MYSQLI_REPORT_OFF); } Logging::logDebug("Converting " . count($ids) . " ids in " . Util::array2str($tables)); foreach ($ids as $old => $new) { $db->update(sprintf("INSERT INTO " . $db->table("item_id") . " (id, path) VALUES (%s,%s)", $db->string($new, TRUE), $db->string($old, TRUE))); } foreach ($tables as $t) { foreach ($ids as $old => $new) { $db->update(sprintf("update " . $db->table($t) . " set item_id=%s where item_id=%s", $db->string($new, TRUE), $db->string($old, TRUE))); } } if (strcmp("mysql", $db->type()) === 0) { mysqli_report(MYSQLI_REPORT_ALL); } }
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); } } } }
private function convertItems($id, $items) { $result = array(); if (!$items or $items == NULL) { return $result; } $missing = array(); foreach ($items as $i) { if (!$i->exists()) { $missing[] = array("id" => $i->id()); continue; } $result[] = $i->data(); } if (count($missing) > 0) { Logging::logDebug("Items missing, removing: " . count($missing)); $this->handler()->removeCollectionItems($id, $missing); } return $result; }
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 generate($item, $maxWidth = 400, $maxHeight = 400) { $img = null; $ext = $item->extension(); if (strcasecmp('jpg', $ext) == 0 || strcasecmp('jpeg', $ext) == 0) { $img = @imagecreatefromjpeg($item->internalPath()); } else { if (strcasecmp('png', $ext) == 0) { $img = @imagecreatefrompng($item->internalPath()); } else { if (strcasecmp('gif', $ext) == 0) { $img = @imagecreatefromgif($item->internalPath()); } } } if ($img == NULL) { Logging::logDebug("Could not create thumbnail, format not supported"); return FALSE; } $w = imagesx($img); $h = imagesy($img); $s = min($maxWidth / $w, $maxHeight / $h); if ($s >= 1) { Logging::logDebug("Skipping thumbnail, image smaller than thumbnail"); return FALSE; } $tw = floor($s * $w); $th = floor($s * $h); $thumb = imagecreatetruecolor($tw, $th); imagecopyresized($thumb, $img, 0, 0, 0, 0, $tw, $th, $w, $h); imagedestroy($img); if ($thumb == NULL) { Logging::logDebug("Failed to create thumbnail"); return FALSE; } header("Content-type: image/jpeg"); imagejpeg($thumb); return TRUE; }
public function authenticate($user, $pw, $auth) { $server = $this->env->settings()->setting("ldap_server"); $connString = $this->env->settings()->setting("ldap_conn_string"); if (strpos($connString, "[USER]") === FALSE) { $connString = $user["name"] . $connString; } else { $connString = str_replace("[USER]", $user["name"], $connString); } Logging::logDebug("Authenticating with LDAP (server " . $server . "): " . $connString); $conn = @ldap_connect($server); if (!$conn) { throw new ServiceException("INVALID_CONFIGURATION", "Could not connect to LDAP server"); } $bind = @ldap_bind($conn, $connString, $pw); if (!$bind) { Logging::logDebug("LDAP error: " . ldap_error($conn)); return FALSE; } ldap_close($conn); return TRUE; }
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 notifyApproved($registration) { $texts = $this->env->resources()->loadTexts("PluginRegistrationMessages", dirname(__FILE__)); if (!isset($texts["registration_notification_approved_subject"]) or !isset($texts["registration_notification_approved_message"])) { Logging::logDebug("No approved messages found, notification mail not sent"); return; } $loginLink = $this->env->getClientUrl(""); $values = array("name" => $registration["name"], "email" => $registration["email"], "link" => $loginLink); $subject = Util::replaceParams($texts["registration_notification_approved_subject"], $values); $msg = Util::replaceParams($texts["registration_notification_approved_message"], $values); $recipient = array(array("name" => $registration["name"], "email" => $registration["email"])); $this->env->mailer()->send($recipient, $subject, $msg); }
public function process() { $this->checkSystem(); if (!$this->isConfigured()) { $this->processor->showPage("configuration"); } try { $this->init(); } catch (ServiceException $e) { $this->processor->setError("Could not connect to database", '<code>' . $e->details() . '</code>'); $this->processor->showPage("configuration"); die; } $this->checkInstalled(); $phase = $this->processor->phase(); if ($phase == NULL) { $phase = 'db'; } Logging::logDebug("Installer phase: [" . $phase . "]"); $this->onPhase($phase); }
function log() { Logging::logDebug("FEATURES: " . Util::array2str($this->features)); }
public function createFile($folder, $name) { self::assertFilename($name); $target = self::joinPath($this->internalPath($folder), $name); $nativeTarget = $this->filesystemInfo->env()->convertCharset($target, FALSE); Logging::logDebug("create " . $target . ": " . $this->publicPath($target)); if (file_exists($nativeTarget)) { throw new ServiceException("FILE_ALREADY_EXISTS"); } touch($nativeTarget); return $this->itemWithPath($this->publicPath($target)); }
private function processPostFolder($item) { if (count($this->path) != 2) { throw $this->invalidRequestException(); } switch (strtolower($this->path[1])) { case 'details': $data = isset($this->request->data["data"]) ? $this->request->data["data"] : null; $this->response()->success($this->env->filesystem()->details($item, $data)); return; case 'info': $includeHierarchy = ($this->request->hasParam("h") and strcmp($this->request->param("h"), "1") == 0); $this->response()->success($this->getFolderInfo($item, $includeHierarchy, $this->request->data["data"])); return; case 'check': if (!isset($this->request->data["files"])) { throw $this->invalidRequestException(); } $stripped = array(); foreach ($this->request->data["files"] as $file) { $p = strrpos($file, "/"); if ($p === FALSE) { $p = -1; } $p = max($p, strrpos($file, "\\")); if ($p !== FALSE and $p >= 0) { $stripped[] = substr($file, $p + 1); } else { $stripped[] = $file; } } $existing = $this->env->filesystem()->checkExisting($item, $stripped); $this->response()->success(array("ok" => count($existing) == 0, "existing" => $existing)); return; case 'empty_file': if (!isset($this->request->data["name"])) { throw $this->invalidRequestException(); } $file = $item->fileWithName($this->request->data["name"]); $this->response()->success($this->env->filesystem()->createItem($file)); return; case 'files': $this->env->filesystem()->uploadTo($item); $this->response()->html(json_encode(array("result" => TRUE))); die; break; case 'folders': $data = $this->request->data; if (!isset($data['name'])) { throw $this->invalidRequestException(); } $this->env->filesystem()->createFolder($item, $data['name']); break; case 'copy': $data = $this->request->data; if (!isset($data['folder'])) { throw $this->invalidRequestException(); } $folder = $this->item($data['folder']); $to = $folder->folderWithName($item->name()); Logging::logDebug("COPY TO " . $to->internalPath()); if ($to->exists()) { throw new ServiceException("DIR_ALREADY_EXISTS"); } $this->env->filesystem()->copy($item, $to); break; case 'move': $data = $this->request->data; if (!isset($data['id'])) { throw $this->invalidRequestException(); } $this->env->filesystem()->move($item, $this->item($data['id'], FALSE)); break; case 'retrieve': $this->env->features()->assertFeature("retrieve_url"); $data = $this->request->data; if (!isset($data['url'])) { throw $this->invalidRequestException(); } $retrieved = $this->env->urlRetriever()->retrieve($data['url']); if (!$retrieved["success"]) { if ($retrieved["result"] === 404) { $this->response()->fail(301, "Resource not found [" . $data['url'] . "]"); } else { if ($retrieved["result"] === 401) { $this->response()->fail(302, "Unauthorized"); } else { $this->response()->fail(108, "Failed to retrieve resource [" . $data['url'] . "], http status " . $retrieved["result"]); } } return; } $this->env->filesystem()->uploadFrom($item, $retrieved["name"], $retrieved["stream"], $data['url']); fclose($retrieved["stream"]); unlink($retrieved["file"]); break; case 'search': $data = $this->request->data; if (!isset($data['text'])) { throw $this->invalidRequestException(); } $this->response()->success($this->env->filesystem()->search($item, $data['text'])); return; default: throw $this->invalidRequestException(); } $this->response()->success(TRUE); }
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 log() { Logging::logDebug("SESSION: is_active=" . $this->isActive() . ", user="******", data=" . Util::array2str($this->data)); }
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); }