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); } }
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; } }
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; }
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 log() { Logging::logDebug("SESSION: is_active=" . $this->isActive() . ", user="******", data=" . Util::array2str($this->data)); }
public function rollback() { if (!$this->db->rollBack()) { throw new ServiceException("INVALID_CONFIGURATION", "Error rollbacking transaction: " . Util::array2str($this->db->errorInfo())); } $this->transaction = FALSE; }
public function log() { Logging::logDebug("REQUEST: method=" . $this->method . ", path=" . Util::array2str($this->parts) . ", ip=" . $this->ip . ", params=" . Util::array2str($this->params) . ", data=" . Util::toString($this->data)); }
public function log() { Logging::logDebug("FILESYSTEM: allowed_file_upload_types=" . Util::array2str($this->allowedUploadTypes)); }
function getOpts($args) { array_shift($args); $endofoptions = false; $ret = array('commands' => array(), 'options' => array(), 'flags' => array(), 'arguments' => array()); while ($arg = array_shift($args)) { // if we have reached end of options, //we cast all remaining argvs as arguments if ($endofoptions) { $ret['arguments'][] = $arg; continue; } // Is it a command? (prefixed with --) if (substr($arg, 0, 2) === '--') { // is it the end of options flag? if (!isset($arg[3])) { $endofoptions = true; // end of options; continue; } $value = ""; $com = substr($arg, 2); // is it the syntax '--option=argument'? if (strpos($com, '=')) { list($com, $value) = explode("=", $com, 2); } elseif (strpos($args[0], '-') !== 0) { while (strpos($args[0], '-') !== 0) { $value .= array_shift($args) . ' '; } $value = rtrim($value, ' '); } $ret['options'][$com] = !empty($value) ? $value : true; continue; } // Is it a flag or a serial of flags? (prefixed with -) if (substr($arg, 0, 1) === '-') { for ($i = 1; isset($arg[$i]); $i++) { $ret['flags'][] = $arg[$i]; } continue; } // finally, it is not option, nor flag, nor argument $ret['commands'][] = $arg; continue; } /*if (!count($ret['options']) && !count($ret['flags'])) { $ret['arguments'] = array_merge($ret['commands'], $ret['arguments']); $ret['commands'] = array(); }*/ Logging::logDebug("=>" . Util::array2str($ret)); return $ret; }
public function exec() { Logging::logDebug("WebDAV request: " . Util::array2str($this->httpRequest->getHeaders())); parent::exec(); }
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); }
private static function toStr($o) { if (is_array($o)) { return Util::array2str($o); } return (string) $o; }
private function addUserProperties($id, $registration, $plugin) { $name = $registration["name"]; $groups = $plugin->getSetting("groups", array()); if (count($groups) > 0) { $existing = array(); foreach ($this->env->configuration()->getAllUserGroups() as $group) { if (in_array($group['id'], $groups)) { $existing[] = $group['id']; } } if (count($existing) > 0) { $this->env->configuration()->addUsersGroups($id, $existing); } } $permissions = $plugin->getSetting("permissions", NULL); // add user default/generic permissions if ($permissions != NULL) { if (!is_array($permissions)) { $permissions = array("filesystem_item_access" => $permissions); } Logging::logDebug("Setting user permissions: " . Util::array2str($permissions)); foreach ($permissions as $pk => $pv) { //TODO validate permission key (pv) and value (pv) $this->env->permissions()->addGenericPermission($pk, $id, $pv); } } $folders = $plugin->getSetting("folders", array()); $folderIds = array(); $folderProps = array(); if (Util::isAssocArray($folders)) { $folderIds = array_keys($folders); $folderProps = $folders; } else { $folderIds = $folders; } if (count($folderIds) > 0) { $existing = array(); foreach ($this->env->configuration()->getFolders() as $folder) { if (in_array($folder['id'], $folderIds)) { $existing[] = $folder['id']; } } if (count($existing) > 0) { //$this->env->configuration()->addUserFolders($id, $existing); foreach ($existing as $f) { $fname = NULL; $fp = array_key_exists($f, $folderProps) ? $folderProps[$f] : array(); if (array_key_exists("name", $fp)) { $fname = $fp["name"]; } Logging::logDebug("Assigning user folder: " . $f . " (" . $fname . ")"); $this->env->configuration()->addUserFolder($id, $f, $fname); // add folder permissions if (array_key_exists("permissions", $fp)) { $fs = $this->env->filesystem()->filesystem($this->env->configuration()->getFolder($f)); $permissions = $fp["permissions"]; if (!is_array($permissions)) { $permissions = array("filesystem_item_access" => $permissions); } Logging::logDebug("Setting folder " . $f . " permissions: " . Util::array2str($permissions)); foreach ($permissions as $pk => $pv) { //TODO validate permission key (pv) and value (pv) $this->env->permissions()->addFilesystemPermission($fs->root(), $pk, $id, $pv); } } } } } $userFolder = $plugin->getSetting("user_folder", NULL); if ($userFolder == NULL) { return; } // automatic user folder if (!isset($userFolder["path"])) { Logging::logError("Registration: missing configuration for user folder"); return; } $basePath = $userFolder["path"]; $folderName = $name; if (isset($userFolder["folder_name"])) { $folderName = $userFolder["folder_name"]; } $folderPath = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $name; $type = "local"; $uf = array("type" => $type, "path" => $folderPath, "name" => $folderName); Logging::logDebug("Creating user folder " . Util::array2str($uf)); $fs = $this->env->filesystem()->filesystem($uf, FALSE); if ($fs->exists()) { Logging::logError("Registration: user folder [" . $folderPath . "] already exists, not added"); return; } if (!$fs->create()) { Logging::logError("Registration: user folder [" . $folderPath . "] could not be created, not added"); return; } $uf["id"] = $this->env->configuration()->addFolder($name, $folderPath); $this->env->configuration()->addUserFolder($id, $uf["id"], $uf["name"]); $fs = $this->env->filesystem()->filesystem($uf, FALSE); $fsroot = $fs->root(); // add user folder permissions $permissions = array(); if (isset($userFolder["permissions"])) { $permissions = $userFolder["permissions"]; if (!is_array($permissions)) { $permissions = array("filesystem_item_access" => $permissions); } } else { $permissions = array("filesystem_item_access" => FilesystemController::PERMISSION_LEVEL_READWRITEDELETE); } Logging::logDebug("Setting user folder permissions: " . Util::array2str($permissions)); foreach ($permissions as $pk => $pv) { //TODO validate permission key (pv) and value (pv) $this->env->permissions()->addFilesystemPermission($fsroot, $pk, $id, $pv); } // assign folder to other users if (isset($userFolder["add_to_users"]) and count($userFolder["add_to_users"]) > 0) { $users = $userFolder["add_to_users"]; $existing = array(); foreach ($this->env->configuration()->getAllUsers() as $user) { if (in_array($user['id'], $users)) { $existing[] = $user['id']; } } if (count($existing) > 0) { $this->env->configuration()->addFolderUsers($uf["id"], $existing); } } $this->env->events()->onEvent(RegistrationEvent::userFolderCreated($id, $registration['name'], $registration['email'], $registration["id"], $fsroot)); }
function log() { Logging::logDebug("FEATURES: " . Util::array2str($this->features)); }
private function processCopy($opts) { $ctx = array("src" => isset($opts["src"]) ? $opts["src"] : NULL, "target" => isset($opts["target"]) ? $opts["target"] : NULL, "name" => isset($opts["name"]) ? $opts["name"] : NULL); if (!$ctx["src"]) { echo "COPY: src missing\n"; return; } //validate target if (!$ctx["target"]) { echo "COPY: target missing\n"; return; } if (!strpos($ctx["target"], ":/")) { echo "COPY: target not right format: \"[FID]:[PATH]/\"\n"; return; } if (substr($ctx["target"], -1) != "/") { // make sure path is folder path $ctx["target"] = $ctx["target"] . "/"; } // validate src if (!file_exists($ctx["src"]) or !is_file($ctx["src"])) { echo "COPY: src does not exist: " . $ctx["src"] . "\n"; return; } if (!is_file($ctx["src"])) { echo "COPY: src is not a file: " . $ctx["src"] . "\n"; return; } echo "COPY: " . Util::array2str($ctx) . "\n"; $name = basename($ctx["src"]); if ($ctx["name"] != NULL) { $name = $ctx["name"]; } $target = $this->env->filesystem()->itemWithLocation($ctx["target"], TRUE); if (!$target->exists()) { echo "COPY: target folder does not exist: " . $ctx["target"] . "\n"; return; } if ($target->isFile()) { echo "COPY: target is not a folder: " . $ctx["target"] . "\n"; return; } if ($target->fileExists($name)) { echo "COPY: target (" . $ctx["target"] . ") already has a file with name \"" . $name . "\"\n"; return; } $created = $target->fileWithName($name); copy($ctx["src"], $created->internalPath()); echo "COPY: file copied successfully into " . $created->internalPath() . "\n"; }