public function __construct(\GO\Site\Model\Site $siteModel) { $file = new \GO\Base\Fs\File($siteModel->getSiteModule()->moduleManager->path() . 'siteconfig.php'); if ($file->exists()) { require $file->path(); } if (isset($siteconfig)) { $this->_configOptions = $siteconfig; } }
/** * The code that needs to be called when the cron is running * * If $this->enableUserAndGroupSupport() returns TRUE then the run function * will be called for each $user. (The $user parameter will be given) * * If $this->enableUserAndGroupSupport() returns FALSE then the * $user parameter is null and the run function will be called only once. * * @param \GO\Base\Cron\CronJob $cronJob * @param \GO\Base\Model\User $user [OPTIONAL] */ public function run(\GO\Base\Cron\CronJob $cronJob, \GO\Base\Model\User $user = null) { \GO::session()->runAsRoot(); \GO::debug("Start updating public calendars."); $calendars = \GO\Calendar\Model\Calendar::model()->findByAttribute('public', true); foreach ($calendars as $calendar) { $file = new \GO\Base\Fs\File($calendar->getPublicIcsPath()); if (!$file->exists()) { \GO::debug("Creating " . $file->path() . "."); $file->touch(true); } $file->putContents($calendar->toVObject()); \GO::debug("Updating " . $calendar->name . " to " . $file->path() . "."); } \GO::debug("Finished updating public calendars."); }
public function createTempFile() { if (!$this->hasTempFile()) { $tmpFile = new \GO\Base\Fs\File($this->getTempDir() . \GO\Base\Fs\File::stripInvalidChars($this->name)); // This fix for duplicate filenames in forwards caused screwed up attachment names! // A possible new fix should be made in ImapMessage->getAttachments() // // $file = new \GO\Base\Fs\File($this->name); // $tmpFile = new \GO\Base\Fs\File($this->getTempDir().uniqid(time()).'.'.$file->extension()); if (!$tmpFile->exists()) { $imap = $this->account->openImapConnection($this->mailbox); $imap->save_to_file($this->uid, $tmpFile->path(), $this->number, $this->encoding, true); } $this->setTempFile($tmpFile); } return $this->getTempFile(); }
/** * Creates a new file in the directory * * data is a readable stream resource * * @param string $name Name of the file * @param resource $data Initial payload * @return void */ public function createFile($name, $data = null) { \GO::debug("FSD::createFile({$name})"); $folder = $this->_getFolder(); if (!$folder->checkPermissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION)) { throw new Sabre\DAV\Exception\Forbidden(); } $newFile = new \GO\Base\Fs\File($this->path . '/' . $name); if ($newFile->exists()) { throw new \Exception("File already exists!"); } $tmpFile = \GO\Base\Fs\File::tempFile(); $tmpFile->putContents($data); if (!\GO\Files\Model\File::checkQuota($tmpFile->size())) { $tmpFile->delete(); throw new Sabre\DAV\Exception\InsufficientStorage(); } // $newFile->putContents($data); $tmpFile->move($folder->fsFolder, $name); $folder->addFile($name); }
protected function afterSave($wasNew) { if ($wasNew && $this->group) { $stmt = $this->group->admins; foreach ($stmt as $user) { if ($user->user_id != $this->user_id) { //the owner has already been added automatically with manage permission $this->acl->addUser($user->user_id, \GO\Base\Model\Acl::DELETE_PERMISSION); } } } $file = new \GO\Base\Fs\File($this->getPublicIcsPath()); if (!$this->public) { if ($file->exists()) { $file->delete(); } } else { if (!$file->exists()) { $file->touch(true); } $file->putContents($this->toVObject()); } return parent::afterSave($wasNew); }
public static function handleUpload() { $tmpFolder = new \GO\Base\Fs\Folder(\GO::config()->tmpdir . 'uploadqueue'); //$tmpFolder->delete(); $tmpFolder->create(); // $files = \GO\Base\Fs\File::moveUploadedFiles($_FILES['attachments'], $tmpFolder); // \GO::session()->values['files']['uploadqueue'] = array(); // foreach ($files as $file) { // \GO::session()->values['files']['uploadqueue'][] = $file->path(); // } if (!isset(\GO::session()->values['files']['uploadqueue'])) { \GO::session()->values['files']['uploadqueue'] = array(); } $targetDir = $tmpFolder->path(); // Get parameters $chunk = isset($_POST["chunk"]) ? $_POST["chunk"] : 0; $chunks = isset($_POST["chunks"]) ? $_POST["chunks"] : 0; $fileName = isset($_POST["name"]) ? $_POST["name"] : ''; // Clean the fileName for security reasons $fileName = \GO\Base\Fs\File::stripInvalidChars($fileName); // Make sure the fileName is unique but only if chunking is disabled // if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) { // $ext = strrpos($fileName, '.'); // $fileName_a = substr($fileName, 0, $ext); // $fileName_b = substr($fileName, $ext); // // $count = 1; // while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) // $count++; // // $fileName = $fileName_a . '_' . $count . $fileName_b; // } // Look for the content type header if (isset($_SERVER["HTTP_CONTENT_TYPE"])) { $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; } if (isset($_SERVER["CONTENT_TYPE"])) { $contentType = $_SERVER["CONTENT_TYPE"]; } if (!in_array($targetDir . DIRECTORY_SEPARATOR . $fileName, \GO::session()->values['files']['uploadqueue'])) { \GO::session()->values['files']['uploadqueue'][] = $targetDir . DIRECTORY_SEPARATOR . $fileName; } $file = new \GO\Base\Fs\File($targetDir . DIRECTORY_SEPARATOR . $fileName); if ($file->exists() && $file->size() > \GO::config()->max_file_size) { throw new \Exception("File too large"); } // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 if (strpos($contentType, "multipart") !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen($_FILES['file']['tmp_name'], "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); @unlink($_FILES['file']['tmp_name']); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } } else { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } // Return JSON-RPC response die('{"jsonrpc" : "2.0", "result": null, "success":true, "id" : "id"}'); }
private function _getParts($structure, $part_number_prefix = '') { if (isset($structure->parts)) { $structure->ctype_primary = strtolower($structure->ctype_primary); $structure->ctype_secondary = strtolower($structure->ctype_secondary); //$part_number=0; foreach ($structure->parts as $part_number => $part) { $part->ctype_primary = strtolower($part->ctype_primary); $part->ctype_secondary = strtolower($part->ctype_secondary); //text part and no attachment so it must be the body if ($structure->ctype_primary == 'multipart' && $structure->ctype_secondary == 'alternative' && $part->ctype_primary == 'text' && $part->ctype_secondary == 'plain') { //check if html part is there if ($this->_hasHtmlPart($structure)) { continue; } } if ($part->ctype_primary == 'text' && ($part->ctype_secondary == 'plain' || $part->ctype_secondary == 'html') && (!isset($part->disposition) || $part->disposition != 'attachment') && empty($part->d_parameters['filename'])) { $charset = isset($part->ctype_parameters['charset']) ? $part->ctype_parameters['charset'] : 'UTF-8'; $body = \GO\Base\Util\String::clean_utf8($part->body, $charset); if (stripos($part->ctype_secondary, 'plain') !== false) { $body = nl2br($body); } else { $body = \GO\Base\Util\String::convertLinks($body); $body = \GO\Base\Util\String::sanitizeHtml($body); $body = $body; } $this->_loadedBody .= $body; } elseif ($part->ctype_primary == 'multipart') { } else { //attachment if (!empty($part->ctype_parameters['name'])) { $filename = $part->ctype_parameters['name']; } elseif (!empty($part->d_parameters['filename'])) { $filename = $part->d_parameters['filename']; } elseif (!empty($part->d_parameters['filename*'])) { $filename = $part->d_parameters['filename*']; } else { $filename = uniqid(time()); } $mime_type = $part->ctype_primary . '/' . $part->ctype_secondary; if (isset($part->headers['content-id'])) { $content_id = trim($part->headers['content-id']); if (strpos($content_id, '>')) { $content_id = substr($part->headers['content-id'], 1, strlen($part->headers['content-id']) - 2); } } else { $content_id = ''; } $f = new \GO\Base\Fs\File($filename); $a = new MessageAttachment(); $a->name = $filename; $a->number = $part_number_prefix . $part_number; $a->content_id = $content_id; $a->mime = $mime_type; $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename); if (!empty($part->body)) { $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename); if (!$tmp_file->exists()) { $tmp_file->putContents($part->body); } $a->setTempFile($tmp_file); } $a->index = count($this->attachments); $a->size = isset($part->body) ? strlen($part->body) : 0; $a->encoding = isset($part->headers['content-transfer-encoding']) ? $part->headers['content-transfer-encoding'] : ''; $a->disposition = isset($part->disposition) ? $part->disposition : ''; $this->addAttachment($a); } //$part_number++; if (isset($part->parts)) { $this->_getParts($part, $part_number_prefix . $part_number . '.'); } } } elseif (isset($structure->body)) { $charset = isset($structure->ctype_parameters['charset']) ? $structure->ctype_parameters['charset'] : 'UTF-8'; $text_part = \GO\Base\Util\String::clean_utf8($structure->body, $charset); //convert text to html if (stripos($structure->ctype_secondary, 'plain') !== false) { $this->extractUuencodedAttachments($text_part); $text_part = nl2br($text_part); } else { $text_part = \GO\Base\Util\String::convertLinks($text_part); $text_part = \GO\Base\Util\String::sanitizeHtml($text_part); } $this->_loadedBody .= $text_part; } }
/** * Get the holiday locale from the $countryCode that is provided. * * If no match can be found then the self::$systemDefaultLocale variable is used. * * @param string $countryCode * @return mixed the locale for the holidays or false when none found */ public static function localeFromCountry($countryCode) { if (key_exists($countryCode, self::$mapping)) { $countryCode = self::$mapping[$countryCode]; } else { if (key_exists(strtolower($countryCode), self::$mapping)) { $countryCode = self::$mapping[strtolower($countryCode)]; } } $languageFolderPath = \GO::config()->root_path . 'language/holidays/'; $file = new \GO\Base\Fs\File($languageFolderPath . $countryCode . '.php'); if ($file->exists()) { return $countryCode; } else { $file = new \GO\Base\Fs\File($languageFolderPath . strtolower($countryCode) . '.php'); if ($file->exists()) { return strtolower($countryCode); } } return false; }
/** * Returns the path to the viewfile based on the used template and module * It will search for a template first if not found look in the views/site/ folder * the default viewfile provided by the module * @param string $viewName name to the viewfile * @return string path of the viewfile */ public function getViewFile($viewName) { $module = \Site::model()->getSiteModule(); if (substr($viewName, 0, 1) != "/") { $classParts = explode('\\', get_class($this)); $moduleId = strtolower($classParts[1]); $viewName = '/' . $moduleId . '/' . $viewName; } $file = new \GO\Base\Fs\File($module->moduleManager->path() . 'views/site/' . $viewName . '.php'); if (!$file->exists()) { throw new \Exception("View '{$viewName}' not found!"); } return $file->path(); }
/** * Check if a file is encoded and if so check if it can be decrypted with * Ioncube. * * @param string $path * @return boolean */ public static function scriptCanBeDecoded($packagename = "Professional") { // if(!empty(self::$ioncubeWorks)){ // return true; // } $majorVersion = GO::config()->getMajorVersion(); switch ($packagename) { case 'Billing': $className = 'LicenseBilling'; $licenseFile = 'billing-' . $majorVersion . '-license.txt'; break; case 'Documents': $className = 'LicenseDocuments'; $licenseFile = 'documents-' . $majorVersion . '-license.txt'; break; default: $className = 'License'; $licenseFile = 'groupoffice-pro-' . $majorVersion . '-license.txt'; break; // default: // throw new Exception("Unkonwn package ".$packagename); } $path = GO::config()->root_path . 'modules/professional/' . $className . '.php'; if (!file_exists($path)) { return false; } //echo $path; //check data for presence of ionCube in code. $data = file_get_contents($path, false, null, -1, 100); if (strpos($data, 'ionCube') === false) { return true; } if (!extension_loaded('ionCube Loader')) { return false; } // $lf = self::getLicenseFile(); $file = new \GO\Base\Fs\File(GO::config()->root_path . $licenseFile); //Empty license file is provided in download so we must check the size. if (!$file->exists()) { return false; } $fullClassName = "\\GO\\Professional\\" . $className; $check = $fullClassName::check(); // var_dump($check); return $check; // self::$ioncubeWorks = true; // return self::$ioncubeWorks; }