Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 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"}');
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 *  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);
$specialLogUsers = isset(\GO::config()->zpush2_special_log_users) ? \GO::config()->zpush2_special_log_users : array();
Exemplo n.º 5
0
 public function getFileStorageCronJobClasses($folderName = 'cron')
 {
     $foundCronJobClasses = array();
     $folderPath = \GO::config()->file_storage_path . 'php/' . $folderName;
     $folder = new \GO\Base\Fs\Folder($folderPath);
     \GO::debug("CRONFILE SEARCH IN FOLDER: " . $folder->path());
     if ($folder->exists()) {
         $items = $folder->ls();
         $reflectionClasses = array();
         foreach ($items as $item) {
             if (is_file($item)) {
                 $className = 'GOFS\\Cron\\' . $item->nameWithoutExtension();
                 $reflectionClasses[] = new \ReflectionClass($className);
             }
         }
         foreach ($reflectionClasses as $reflectionClass) {
             if ($this->_checkIsCronJobClassFile($reflectionClass)) {
                 \GO::debug("CRONFILE FOUND: " . $reflectionClass->name);
                 $cronJob = new $reflectionClass->name();
                 $foundCronJobClasses[$reflectionClass->name] = $cronJob->getLabel();
             }
         }
     }
     return $foundCronJobClasses;
 }
 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();
 }
Exemplo n.º 7
0
             \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.
 $filepath = str_replace("\\", "/", __FILE__);
 if (strpos($filepath, \GO::config()->root_path) !== 0) {
     errorMessage("WARNING: The config file {$configFile} was found but the root path points to another location " . \GO::config()->root_path . " while you are installing in " . dirname(dirname($filepath)) . " now. You probably want to create a new config.php file for this installation.");
 }
 if (!is_writable($configFile)) {