Beispiel #1
0
 public static function submitFile($path)
 {
     try {
         if (!isset($_FILES['Filedata'])) {
             echo '<div style="font-size:20px;font-family:Helvetica, Arial, Verdana, Sans, FreeSans;margin-top:80px;margin-right:15px;"><center>&nbsp;&nbsp;<img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files</center>';
             exit;
         }
         $Logger = Logger::getLogger('application.upload');
         foreach ($_FILES['Filedata']['name'] as $k => $v) {
             if (!empty($v)) {
                 $filename = $_FILES['Filedata']['name'][$k];
                 if (!isset($_POST['UPLOAD_IDENTIFIER'])) {
                     $filename = utf8_encode($filename);
                 }
                 $tmpPath = $_FILES['Filedata']['tmp_name'][$k];
                 $Logger->debug("Filename: " . $filename);
                 if (!is_uploaded_file($tmpPath)) {
                     throw new EyeFileNotFoundException('Uploaded file not found at "' . $tmpPath . '".');
                 }
                 $request = MMapManager::getCurrentRequest();
                 $destPath = $path;
                 $filename = str_replace('?', '_', $filename);
                 $filename = str_replace('#', '_', $filename);
                 $tmp = pathinfo($filename);
                 if (isset($tmp['extension']) && "lnk" == $tmp['extension']) {
                     throw new EyeFileNotFoundException('This file cannot be uploaded (file type banned)');
                 }
                 /*
                 if ( '?' == $filename{0} ) {
                 	$filename{0} = "_";
                 }
                 */
                 $destFile = FSI::getFile($destPath . '/' . $filename);
                 //The uploaded file is necessarily on the local filesystem and we want to avoid any
                 //permission check through EyeLocalFile, so we use LocalFile directly
                 $tmpFile = new LocalFile($tmpPath);
                 $num = 1;
                 $extension = AdvancedPathLib::pathinfo($filename, PATHINFO_EXTENSION);
                 $filename = AdvancedPathLib::pathinfo($filename, PATHINFO_FILENAME);
                 $Logger->debug("CLASS: " . get_class($destFile));
                 $Logger->debug("Exists: " . $destFile->exists());
                 //exit();
                 while ($destFile->exists()) {
                     $newBasename = $filename . ' (' . $num++ . ')' . ($extension ? '.' . $extension : '');
                     $destFile = FSI::getFile($destPath . '/' . $newBasename);
                 }
                 $destFile->checkWritePermission();
                 $tmpFile->moveTo($destFile);
                 $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
                 $settings = MetaManager::getInstance()->retrieveMeta($currentUser);
                 $message = new ClientBusMessage('file', 'uploadComplete', self::getFileInfo($destFile, $settings));
                 ClientMessageBusController::getInstance()->queueMessage($message);
                 $event = new FileEvent($destFile);
                 $destFile->fireEvent('fileWritten', $event);
             }
         }
         register_shutdown_function('endRequestUpload');
     } catch (EyeException $e) {
         echo '<div style="font-size:20px;font-family:Helvetica, Arial, Verdana, Sans, FreeSans;margin-top:80px;margin-right:15px;"><center>&nbsp;&nbsp;<img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files: ' . $e->getMessage() . '</center>';
         exit;
     }
 }
Beispiel #2
0
 private static function startLogin(MMapResponse $response)
 {
     // start Process
     $loginProcess = new Process('login');
     ProcManager::getInstance()->execute($loginProcess);
     // prepare context and execute application
     $loginAppDesc = new EyeosApplicationDescriptor('login');
     $appContext = new AppExecutionContext();
     $appContext->setApplicationDescriptor($loginAppDesc);
     $appContext->setIncludeBody(true);
     $appContext->setProcess($loginProcess);
     MMapGetApp::getInstance()->processRequest(MMapManager::getCurrentRequest(), $response, $appContext);
 }
Beispiel #3
0
 public static function __run(AppExecutionContext $context, MMapResponse $response)
 {
     $args = $context->getArgs();
     if (!isset($args[0]) || !is_string($args[0])) {
         throw new EyeMissingArgumentException('Missing filename to open.');
     }
     try {
         $file = FSI::getFile($args[0]);
     } catch (Exception $e) {
         throw new EyeInvalidArgumentException('args[0] must be a valid path to a file.', 0, $e);
     }
     $appName = false;
     if ($file->isDirectory()) {
         $appName = 'files';
     } else {
         $extension = utf8_strtolower($file->getExtension());
         // TODO: Currently hard-coded here but in the future associations will be read from a DB.
         // We must have general entries, common to all the users of the system, that will be used
         // as default, and then user-customized entries with a higher priority on the general ones.
         switch ($extension) {
             //
             //	VIEWER
             //
             case 'jpg':
             case 'gif':
             case 'jpeg':
             case 'png':
             case 'htm':
             case 'html':
             case 'flv':
             case 'm4a':
             case 'mp3':
                 $appName = 'viewer';
                 break;
                 //
                 //	EDITOR
                 //
             //
             //	EDITOR
             //
             case 'txt':
             case 'xml':
             case 'ini':
             case 'js':
             case 'sql':
             case 'log':
                 $appName = 'femto';
                 break;
         }
     }
     // Association found: execute matching application
     if ($appName) {
         $myProcess = ProcManager::getInstance()->getCurrentProcess();
         // prepare context and execute application
         $currentAppDesc = new EyeosApplicationDescriptor($appName);
         $appContext = new AppExecutionContext();
         $appContext->setParentProcess($myProcess);
         $appContext->setApplicationDescriptor($currentAppDesc);
         $appContext->setArgs(clone $args);
         MMapGetApp::getInstance()->processRequest(MMapManager::getCurrentRequest(), $response, $appContext);
         // Kill our process
         $context->setExecuteJavascript(false);
         ProcManager::getInstance()->kill($myProcess);
         return;
     }
     // Otherwise, show the OpenWith dialog
 }
Beispiel #4
0
 public static function getFile($params)
 {
     $instance = MemoryManager::getInstance();
     $request = MMapManager::getCurrentRequest();
     $response = MMapManager::getCurrentResponse();
     $plist = $instance->get('playList');
     $myFile = FSI::getFile($plist[$params]);
     $myFile->checkReadPermission();
     $myExt = strtolower($myFile->getExtension());
     $type = $request->issetGET('type') ? $request->getGET('type') : '';
     $myRealFile = $myFile->getRealFile();
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     //Convert file to a supported FLV
     if ($type == 'convert2FLV' || $myExt == 'mov' || $myExt == '3gp' || $myExt == 'wav' || $myExt == 'wma' || $myExt == '3gpp' || $myExt == '3g2' || $myExt == 'mp4' || $myExt == 'mpg' || $myExt == 'mpv' || $myExt == 'avi' || $myExt == 'ogg' || $myExt == 'ogv' || $myExt == 'webm') {
         Logger::getLogger('VIEWEEER')->debug('$fileNameDestination before transcode: ' . $myExt);
         $mediaConverter = new MediaConverter();
         $fileNameDestination = $mediaConverter->Convert($fileNameDestination, 'FLV');
         $type = 'flv';
         Logger::getLogger('VIEWEEER')->debug('$fileNameDestination after transcode: ' . $fileNameDestination);
     }
     // setting headers
     if ($type == 'image' || $myExt == 'png' || $myExt == 'jpg' || $myExt == 'gif') {
         header('Content-Type: image/' . $myExt);
     } else {
         if ($type == 'mp4' || $myExt == 'mp4') {
             header('Content-type: video/mp4');
         } else {
             if ($type == 'flv' || $myExt == 'flv') {
                 header('Content-type: video/x-flv');
             } else {
                 if ($type == 'mp3' || $myExt == 'mp3') {
                     header('Content-type: audio/mpeg3');
                 } else {
                     if ($type == 'm4a' || $myExt == 'm4a') {
                         header('Content-type: audio/mp4a-latm');
                     } else {
                         if (method_exists($myFile, 'getMimeType')) {
                             header('Content-type: ' . $myFile->getMimeType());
                         }
                     }
                 }
             }
         }
     }
     $len = filesize($fileNameDestination);
     header('Content-Length: ' . $len);
     header('Accept-Ranges: bytes');
     header('X-Pad: avoid browser bug');
     session_write_close();
     readFile($fileNameDestination);
     exit;
 }