public function __construct() { $f = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'cache'); $f->create(); $this->_cacheFile = \GO::config()->file_storage_path . 'cache/script-'; if (\GO::user()) { $this->_cacheFile .= \GO::user()->username; } else { $this->_cacheFile .= "loggedoff"; } $this->_cacheFile .= '.js'; }
public function __construct($prefixString = '') { if (!\GO::modules()->isInstalled('files')) { throw new \Exception('The current action requires the files module to be activated for the current user.'); } // Make sure the current user's folder exists. $userFolderModel = \GO\Files\Model\Folder::model()->findHomeFolder(\GO::user()); if (empty($userFolderModel)) { $userFolder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'users/' . \GO::user()->username); $userFolder->create(); $userFolderModel = new \GO\Files\Model\Folder(); $userFolderModel->findByPath('users/' . \GO::user()->username, true); } parent::__construct(\GO::config()->file_storage_path . $userFolderModel->path . '/' . $prefixString . \GO\Base\Util\Date::get_timestamp(time(), true) . '.log'); }
protected function actionSend($params) { if (empty($params['addresslist_id'])) { throw new \Exception(\GO::t('feedbackNoReciepent', 'email')); } else { try { //$params = $this->_convertOldParams($params); if (\GO::modules()->isAvailable('campaigns') && isset($params['campaign_id']) && $params['campaign_id'] > 0 && (empty(\GO::config()->campaigns_imap_user) || empty(\GO::config()->campaigns_imap_pass) || empty(\GO::config()->campaigns_imap_server) || empty(\GO::config()->campaigns_imap_port) || !isset(\GO::config()->campaigns_smtp_user) || !isset(\GO::config()->campaigns_smtp_pass) || empty(\GO::config()->campaigns_smtp_server) || empty(\GO::config()->campaigns_smtp_port) || empty(\GO::config()->campaigns_from) || empty(\GO::config()->campaigns_max_mails_per_period))) { throw new \Exception(\GO::t('mustSetCampaignsConfig', 'campaigns')); } $message = \GO\Base\Mail\Message::newInstance(); $message->handleEmailFormInput($params); // insert the inline and regular attachments in the MIME message $mailing['alias_id'] = $params['alias_id']; $mailing['subject'] = $params['subject']; $mailing['addresslist_id'] = $params['addresslist_id']; $mailing['campaign_id'] = $params['campaign_id']; $mailing['message_path'] = 'mailings/' . \GO::user()->id . '_' . date('Ymd_Gis') . '.eml'; $folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'mailings'); $folder->create(); // Write message MIME source to message path file_put_contents(\GO::config()->file_storage_path . $mailing['message_path'], $message->toString()); \GO::debug('===== MAILING PARAMS ====='); \GO::debug(var_export($mailing, true)); $sentMailing = new \GO\Addressbook\Model\SentMailing(); $sentMailing->setAttributes($mailing); if (!$sentMailing->save()) { \GO::debug('===== VALIDATION ERRORS ====='); \GO::debug('Could not create new mailing:<br />' . implode('<br />', $sentMailing->getValidationErrors())); throw new \Exception('Could not create new mailing:<br />' . implode('<br />', $sentMailing->getValidationErrors()) . '<br />MAILING PARAMS:<br />' . var_export($mailing, true)); } $this->_launchBatchSend($sentMailing->id); $response['success'] = true; } catch (\Exception $e) { $response['feedback'] = \GO::t('feedbackUnexpectedError', 'email') . $e->getMessage(); } } return $response; }
/** * Deafult image logo used be the default Header() method. * Please set here your own logo or an empty string to disable it. */ //define ('PDF_HEADER_LOGO', ''); /** * Header logo image width in user units. */ //define ('PDF_HEADER_LOGO_WIDTH', 0); /** * Cache directory for temporary files (full path). */ //define ('K_PATH_CACHE', sys_get_temp_dir().'/'); define('K_PATH_CACHE', \GO::config()->file_storage_path . 'tcpdfcache/'); $f = new \GO\Base\Fs\Folder(K_PATH_CACHE); $f->create(); /** * Generic name for a blank image. */ define('K_BLANK_IMAGE', '_blank.png'); /** * Page format. */ define('PDF_PAGE_FORMAT', 'A4'); /** * Page orientation (P=portrait, L=landscape). */ define('PDF_PAGE_ORIENTATION', 'P'); /** * Document creator. */
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"}'); }
/** * @return string the root directory storing the published asset files. Defaults to 'WebRoot/assets'. */ public function getBasePath() { if ($this->_basePath === null) { $basePath = new \GO\Base\Fs\Folder(\Site::model()->getPublicPath() . 'assets'); $basePath->create(); $this->_basePath = $basePath->path(); } return $this->_basePath; }
public function setPhoto(\GO\Base\Fs\File $file) { if ($this->isNew) { throw new \Exception("Cannot save a photo on a new contact that is not yet saved."); } $this->getPhotoFile()->delete(); $photoPath = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'addressbook/photos/' . $this->addressbook_id . '/'); $photoPath->create(); // if(strtolower($file->extension())!='jpg'){ $filename = $photoPath->path() . '/com_' . $this->id . '.jpg'; $img = new \GO\Base\Util\Image(); if (!$img->load($file->path())) { throw new \Exception(\GO::t('imageNotSupported', 'addressbook')); } $aspectRatio = $img->getHeight() > $img->getWidth() ? $img->getHeight() / $img->getWidth() : $img->getWidth() / $img->getHeight(); //resize it to small image so we don't get in trouble with sync clients if ($img->getHeight() > $img->getWidth()) { $img->fitBox(320 / $aspectRatio, 320); } else { $img->fitBox(320, 320 / $aspectRatio); } if (!$img->save($filename, IMAGETYPE_JPEG)) { throw new \Exception("Could not save photo!"); } $file = new \GO\Base\Fs\File($filename); // }else // { // $file->move($photoPath, $this->id.'.'.strtolower($file->extension())); // } $this->photo = $file->stripFileStoragePath(); }
* LOGLEVEL_FATAL - log only critical errors * LOGLEVEL_ERROR - logs events which might require corrective actions * LOGLEVEL_WARN - might lead to an error or require corrective actions in the future * LOGLEVEL_INFO - usually completed actions * LOGLEVEL_DEBUG - debugging information, typically only meaningful to developers * LOGLEVEL_WBXML - also prints the WBXML sent to/from the device * LOGLEVEL_DEVICEID - also prints the device id for every log entry * LOGLEVEL_WBXMLSTACK - also prints the contents of WBXML stack * * The verbosity increases from top to bottom. More verbose levels include less verbose * ones, e.g. setting to LOGLEVEL_DEBUG will also output LOGLEVEL_FATAL, LOGLEVEL_ERROR, * LOGLEVEL_WARN and LOGLEVEL_INFO level entries. */ //define('LOGFILEDIR', '/var/log/z-push/'); $folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'log/z-push/'); $folder->create(); define('LOGFILEDIR', $folder->path() . '/'); define('LOGFILE', LOGFILEDIR . 'z-push.log'); define('LOGERRORFILE', LOGFILEDIR . 'z-push-error.log'); //note: you can't use z-push constants in the GO config file! //use 16 for debug or 32 for wbxml if (!isset(\GO::config()->zpush2_loglevel)) { \GO::config()->zpush2_loglevel = LOGLEVEL_OFF; } define('LOGLEVEL', \GO::config()->zpush2_loglevel); define('LOGAUTHFAIL', false); // To save e.g. WBXML data only for selected users, add the usernames to the array // The data will be saved into a dedicated file per user in the LOGFILEDIR // Users have to be encapusulated in quotes, several users are comma separated, like: // $specialLogUsers = array('*****@*****.**', 'myusername'); define('LOGUSERLEVEL', LOGLEVEL_DEVICEID);
protected function actionHandleUploads($params) { if (!isset(\GO::session()->values['files']['uploadqueue'])) { \GO::session()->values['files']['uploadqueue'] = array(); } try { $chunkTmpFolder = new \GO\Base\Fs\Folder(\GO::config()->tmpdir . 'juploadqueue/chunks'); $tmpFolder = new \GO\Base\Fs\Folder(\GO::config()->tmpdir . 'juploadqueue'); $tmpFolder->create(); $chunkTmpFolder->create(); $count = 0; while ($uploadedFile = array_shift($_FILES)) { if (isset($params['jupart'])) { $originalFileName = $uploadedFile['name']; $uploadedFile['name'] = $uploadedFile['name'] . '.part' . $params['jupart']; $chunkTmpFolder->create(); \GO\Base\Fs\File::moveUploadedFiles($uploadedFile, $chunkTmpFolder); if (!empty($params['jufinal'])) { $file = new \GO\Base\Fs\File($tmpFolder . '/' . $originalFileName); $fp = fopen($file->path(), 'w+'); for ($i = 1; $i <= $params['jupart']; $i++) { $part = new \GO\Base\Fs\File($chunkTmpFolder . '/' . $originalFileName . '.part' . $i); fwrite($fp, $part->contents()); $part->delete(); } fclose($fp); $chunkTmpFolder->delete(); } else { echo "SUCCESS\n"; return; } } else { $files = \GO\Base\Fs\File::moveUploadedFiles($uploadedFile, $tmpFolder); if (!$files) { throw new \Exception("No file received"); } $file = $files[0]; } $subdir = false; if (!empty($params['relpathinfo' . $count]) && !isset($params['jupart']) || !empty($params['relpathinfo' . $count]) && isset($params['jupart']) && !empty($params['jufinal'])) { $fullpath = \GO::config()->tmpdir . 'juploadqueue' . '/' . str_replace('\\', '/', $params['relpathinfo' . $count]); $dir = new \GO\Base\Fs\Folder($fullpath); $dir->create(); $subdir = true; $file->move($dir); } $count++; if ($subdir) { $parent = $this->_findHighestParent($dir); \GO::debug($parent); if (!in_array($parent->path(), \GO::session()->values['files']['uploadqueue'])) { \GO::session()->values['files']['uploadqueue'][] = $parent->path(); } } else { \GO::session()->values['files']['uploadqueue'][] = $file->path(); } } } catch (\Exception $e) { echo 'WARNING: ' . $e->getMessage() . "\n"; } echo "SUCCESS\n"; }
/** * Flush all values */ public function flush() { $this->_ttls = array(); $this->_ttlsDirty = true; $folder = new \GO\Base\Fs\Folder($this->_dir); $folder->delete(); $folder->create(0777); }
/** * Move the folder to another folder. * * @param Folder $destinationFolder * @param string $newFolderName Optionally rename the folder too. * @param boolean $appendNumberToNameIfDestinationExists Rename the folder like "folder (1)" if it already exists. * * @return Folder $destinationFolder */ public function move(Folder $destinationFolder, $newFolderName = false, $appendNumberToNameIfDestinationExists = false) { if (!$this->exists()) { throw new \Exception("Folder '" . $this->path() . "' does not exist"); } if (is_link($this->path)) { $link = new File($this->path); return $link->move($destinationFolder, $newFolderName, false, $appendNumberToNameIfDestinationExists); } $this->_validateSrcAndDestPath($destinationFolder->path(), $this->path()); if (!$newFolderName) { $newFolderName = $this->name(); } $newPath = $destinationFolder->path() . '/' . $newFolderName; if ($appendNumberToNameIfDestinationExists) { $folder = new Folder($newPath); $folder->appendNumberToNameIfExists(); $newPath = $folder->path(); } //do nothing if path is the same. if ($newPath == $this->path()) { return true; } if (!@rename($this->path(), $newPath)) { // Notice suppressed by @ // throw new Exception("Rename failed"); // If renaming is throwing an error then do it the old way. // This is done because of problems when moving items across partitions. // See https://bugs.php.net/bug.php?id=50676 for more info about this. // If rename fails then try the old method $movedFolder = new \GO\Base\Fs\Folder($newPath); $movedFolder->create(); $ls = $this->ls(true); foreach ($ls as $fsObject) { $fsObject->move($movedFolder); } $this->delete(); $newPath = $movedFolder->path(); } $this->path = $newPath; return true; }
public function getHome($uid) { $home = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'owncloud/' . $this->_getUser($uid)->username); $home->create(); return $home->path(); }
if (empty(\GO::config()->title)) { \GO::config()->title = 'Group-Office'; } //set this to a default otherwise GO will keep autodetecting values if (empty(\GO::config()->db_user)) { \GO::config()->db_user = '******'; } $f = new \GO\Base\Fs\Folder($_POST['file_storage_path']); if (!$f->exists()) { \GO\Base\Html\Input::setError("file_storage_path", "File storage folder doesn't exist. Please make sure it exists and it must be writable for the webserver user."); } elseif (!$f->isWritable()) { \GO\Base\Html\Input::setError("file_storage_path", "File storage must be writable for the webserver user."); } \GO::config()->file_storage_path = $f->path() . '/'; $f = new \GO\Base\Fs\Folder($_POST['tmpdir']); if (!$f->exists() && !$f->create(0777)) { \GO\Base\Html\Input::setError("tmpdir", "Temporary folder doesn't exist. Please make sure it exists and it must be writable for the webserver user."); } elseif (!$f->isWritable()) { \GO\Base\Html\Input::setError("tmpdir", "Temporary folder must be writable for the webserver user."); } \GO::config()->tmpdir = $f->path() . '/'; \GO::config()->save($config); if (!\GO\Base\Html\Input::hasErrors()) { redirect("regional.php"); } } } catch (Exception $e) { \GO\Base\Html\Input::setError("form", $e->getMessage()); } printHead(); //check if config root_path matches the current Group-Office in case an /etc/groupoffice/config.php was found that conflicts with this installation.
protected function actionUpload($params) { $relpath = 'public/bookmarks/'; $folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . $relpath); $folder->create(); $files = \GO\Base\Fs\File::moveUploadedFiles($_FILES['attachments'], $folder); $file = $files[0]; $file->rename($params['thumb_id'] . '.' . $file->extension()); $response['logo'] = $file->stripFileStoragePath(); $response['success'] = true; return $response; }
public static function infolog($message) { if (!empty(self::config()->info_log)) { if (empty(\GO::session()->values["logdircheck"])) { $folder = new \GO\Base\Fs\Folder(dirname(self::config()->info_log)); $folder->create(); \GO::session()->values["logdircheck"] = true; } $msg = '[' . date('Y-m-d H:i:s') . ']'; if (\GO::user()) { $msg .= '[' . self::user()->username . '] '; } $msg .= $message; @file_put_contents(self::config()->info_log, $msg . "\n", FILE_APPEND); } }