Beispiel #1
0
 public function processRequest(MMapRequest $request, MMapResponse $response)
 {
     ob_start('mb_output_handler');
     $extern = EYE_ROOT . '/' . EXTERN_DIR . '/' . $request->getGET('extern');
     $type = $request->issetGET('type') ? $request->getGET('type') : '';
     // Check if an extern file is called
     if (strpos(realpath($extern), realpath(EYE_ROOT . '/' . EXTERN_DIR . '/')) === 0) {
         $info = pathinfo($extern);
         $myExt = strtolower($info['extension']);
         if (is_readable($extern)) {
             $len = filesize($extern);
             if ($type == 'text') {
                 $response->getHeaders()->append('Content-type: text/plain');
             } else {
                 if ($type == 'js' || $myExt == 'js') {
                     $response->getHeaders()->append('Content-type: text/javascript');
                 } else {
                     if ($myExt == 'htm' || $myExt == 'html' || $myExt == 'xhtml') {
                         Logger::getLogger('debug')->debug($extern);
                         $response->getHeaders()->append('Content-type: text/html');
                     } else {
                         if ($type == 'image' || $myExt == 'png' || $myExt == 'jpg' || $myExt == 'gif') {
                             $response->getHeaders()->append('Content-Type: image/' . $myExt);
                         } else {
                             if ($type == 'download') {
                                 $response->getHeaders()->append('Content-Type: application/force-download');
                                 $response->getHeaders()->append('Content-Description: File Transfer');
                                 $response->getHeaders()->append('Content-Disposition: attachment; filename="' . basename($extern) . '"');
                             } else {
                                 if ($type == 'css' || $myExt == 'css') {
                                     $response->getHeaders()->append(array('Content-type: text/css', true));
                                 } else {
                                     if ($type == 'xml' || $myExt == 'xml' || $myExt == 'xsl') {
                                         $response->getHeaders()->append('Content-type: text/xml');
                                     } else {
                                         if ($type == 'swf' || $myExt == 'swf') {
                                             $response->getHeaders()->append('Content-type: application/x-shockwave-flash');
                                         } else {
                                             if ($type == 'mp3' || $myExt == 'mp3') {
                                                 $response->getHeaders()->append('Content-type: audio/mpeg3');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $response->getHeaders()->append('Content-Length: ' . $len);
             $response->getHeaders()->append('Accept-Ranges: bytes');
             $response->getHeaders()->append('X-Pad: avoid browser bug');
             //FIXME: we really need cache here, its absolutely needed because if not
             //the system gets really slow, so, I remove this form the headers because its preventing the
             //browser from caching.
             //however, maybe there is a better method to avoid this? PHP directive?
             $response->getHeaders()->append('Cache-Control: ');
             $response->getHeaders()->append('pragma: ');
             if (self::$Logger->isDebugEnabled()) {
                 self::$Logger->debug('Preparing to output file: ' . $extern);
             }
             $response->setBodyRenderer(new FileReaderBodyRenderer(new FileInputStream($extern)));
         }
     } else {
         self::$Logger->warn('Specified path does not point a valid file: ' . $extern . '. Operation cancelled.');
     }
 }
Beispiel #2
0
 public function processRequest(MMapRequest $request, MMapResponse $response)
 {
     ob_start('mb_output_handler');
     $return = null;
     $dataManager = DataManager::getInstance();
     $POST = $request->getPOST();
     $params = array();
     if (isset($POST['params'])) {
         $params = $dataManager->doInput($POST['params']);
     } else {
         if ($request->issetGET('params')) {
             $params = $request->getGET('params');
         }
     }
     //login in the system and get a valid login context
     $subject = new Subject();
     $loginContext = new LoginContext('eyeos-login', $subject);
     $cred = new EyeosPasswordCredential();
     $cred->setUsername($_REQUEST['username']);
     $cred->setPassword($_REQUEST['password'], true);
     $subject->getPrivateCredentials()->append($cred);
     $loginContext->login();
     //now create fake process called api
     Kernel::enterSystemMode();
     $appProcess = new Process('api');
     $appProcess->setPid('31337');
     $mem = MemoryManager::getInstance();
     $processTable = $mem->get('processTable', array());
     $processTable[31337] = $appProcess;
     $mem->set('processTable', $processTable);
     $appProcess->setLoginContext($loginContext);
     ProcManager::getInstance()->setCurrentProcess($appProcess);
     kernel::exitSystemMode();
     $return = call_user_func_array(array('EyeosApplicationExecutable', '__callModule'), array($request->getPOST('module'), $request->getPOST('name'), $params));
     //try to force mime type. If there is a previous mime type defined at application level
     //this have no effect
     if (!headers_sent()) {
         $response->getHeaders()->append('Content-type:text/plain');
     }
     if ($response->getBodyRenderer() === null && $response->getBody() == '') {
         $response->setBodyRenderer(new DataManagerBodyRenderer($return));
     }
 }
Beispiel #3
0
 public function processRequest(MMapRequest $request, MMapResponse $response)
 {
     ob_start('mb_output_handler');
     MMapManager::startSession();
     //check if the session has expired
     MMapManager::checkSessionExpiration();
     $return = null;
     $dataManager = DataManager::getInstance();
     // restore current process using checknum
     $myProcManager = ProcManager::getInstance();
     $myProcess = $myProcManager->getProcessByChecknum($request->getGET('checknum'));
     $myProcManager->setCurrentProcess($myProcess);
     $appDesc = new EyeosApplicationDescriptor($myProcess->getName());
     $POST = $request->getPOST();
     $params = array();
     if (isset($POST['params'])) {
         $params = $dataManager->doInput($POST['params']);
     } else {
         if ($request->issetGET('params')) {
             $params = $request->getGET('params');
         }
     }
     $methodName = $request->getGET('message');
     // calling an ExecModule
     if (strpos($methodName, '__') === 0) {
         $moduleName = explode('_', substr($methodName, 2));
         $methodName = $moduleName[1];
         //ex: "FileChooser"
         $moduleName = $moduleName[0];
         //ex: "browsePath"
         $return = call_user_func_array(array($appDesc->getApplicationClassName(), '__callModule'), array($moduleName, $methodName, $params));
     } else {
         if ($appDesc->isJavascriptOnlyApplication()) {
             $return = call_user_func(array('EyeosJavascriptApplicationExecutable', $methodName), $params);
         } else {
             $return = call_user_func(array($appDesc->getApplicationClassName(), $methodName), $params);
         }
     }
     //try to force mime type. If there is a previous mime type defined at application level
     //this have no effect
     if (!headers_sent()) {
         $response->getHeaders()->append('Content-type:text/plain');
     }
     if ($response->getBodyRenderer() === null && $response->getBody() == '') {
         $response->setBodyRenderer(new DataManagerBodyRenderer($return));
     }
 }
Beispiel #4
0
 private function handleClientMessageQueue(MMapResponse $response)
 {
     $messages = ClientMessageBusController::getInstance()->getQueue();
     // Check for client bus messages to be appended to the response
     if ($messages->count() > 0) {
         self::$Logger->info($messages->count() . ' client bus message(s) found, processing...');
         // Only if the current body/bodyrenderer is mappable to a control message
         $currentBodyRenderer = $response->getBodyRenderer();
         if ($currentBodyRenderer !== null && !$currentBodyRenderer instanceof DataManagerBodyRenderer) {
             self::$Logger->error('Cannot append client bus messages: unable to replace current BodyRenderer from class ' . get_class($currentBodyRenderer) . ', ignoring.');
             return;
         }
         $messages = $messages->getArrayCopy();
         foreach ($messages as &$message) {
             $message = $message->toArray();
         }
         if ($currentBodyRenderer !== null) {
             if ($currentBodyRenderer instanceof ControlMessageBodyRenderer) {
                 $data = $currentBodyRenderer->getBodyData();
             } else {
                 $data = $currentBodyRenderer->getRenderedBody();
             }
         } else {
             $data = $response->getBody();
         }
         $newBody = array('messages' => $messages, 'data' => $data);
         $controlMessageBodyRenderer = new ControlMessageBodyRenderer(ControlMessageBodyRenderer::TYPE_ENHANCEDDATA, $newBody);
         $response->setBodyRenderer($controlMessageBodyRenderer);
     }
 }
Beispiel #5
0
 public function processRequest(MMapRequest $request, MMapResponse $response)
 {
     ob_start('mb_output_handler');
     MMapManager::startSession();
     // restore process context
     $myProcManager = ProcManager::getInstance();
     $myProcess = $myProcManager->getProcessByChecknum($request->getGET('checknum'));
     $myProcManager->setCurrentProcess($myProcess);
     // process request
     $externFile = FSI::getFile('sys:///' . APPS_DIR . '/' . $request->getGET('appName') . '/' . $request->getGET('appFile'));
     $type = $request->issetGET('type') ? $request->getGET('type') : '';
     if (strpos($externFile->getAbsolutePath(), 'sys:///' . APPS_DIR . '/') === 0) {
         $myExt = $externFile->getExtension();
         if ($externFile->isReadable()) {
             $len = $externFile->getSize();
             if ($type == 'text') {
                 $response->getHeaders()->append('Content-type: text/plain');
             } else {
                 if ($type == 'js' || $myExt == 'js') {
                     $response->getHeaders()->append('Content-type: text/javascript');
                 } else {
                     if ($myExt == 'htm' || $myExt == 'html' || $myExt == 'xhtml') {
                         $response->getHeaders()->append('Content-type: text/html');
                     } else {
                         if ($type == 'image' && !empty($myExt) || $myExt == 'png' || $myExt == 'jpg' || $myExt == 'gif') {
                             $response->getHeaders()->append('Content-Type: image/' . $myExt);
                         } else {
                             if ($type == 'download') {
                                 $response->getHeaders()->append('Content-Type: application/force-download');
                                 $response->getHeaders()->append('Content-Description: File Transfer');
                                 $response->getHeaders()->append('Content-Disposition: attachment; filename="' . $externFile->getName() . '"');
                             } else {
                                 if ($type == 'css' || $myExt == 'css') {
                                     $response->getHeaders()->append(array('Content-type: text/css', true));
                                 } else {
                                     if ($type == 'xml' || $myExt == 'xml' || $myExt == 'xsl') {
                                         $response->getHeaders()->append('Content-type: text/xml');
                                     } else {
                                         if ($type == 'swf' || $myExt == 'swf') {
                                             $response->getHeaders()->append('Content-type: application/x-shockwave-flash');
                                         } else {
                                             if ($type == 'mp3' || $myExt == 'mp3') {
                                                 $response->getHeaders()->append('Content-type: audio/mpeg3');
                                             } else {
                                                 if ($type == 'mp4' || $myExt == 'mp4') {
                                                     $response->getHeaders()->append('Content-type: video/mp4');
                                                 } else {
                                                     if ($type == 'flv' || $myExt == 'flv') {
                                                         $response->getHeaders()->append('Content-type: video/x-flv');
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $response->getHeaders()->append('Content-Length: ' . $len);
             $response->getHeaders()->append('Accept-Ranges: bytes');
             $response->getHeaders()->append('X-Pad: avoid browser bug');
             $response->getHeaders()->append('Cache-Control: ');
             $response->getHeaders()->append('pragma: ');
             if (self::$Logger->isDebugEnabled()) {
                 self::$Logger->debug('Preparing to output file: ' . $externFile->getAbsolutePath());
             }
             $response->setBodyRenderer(new FileReaderBodyRenderer($externFile->getInputStream()));
         }
     } else {
         self::$Logger->warn('Illegal path given: ' . $externFile->getAbsolutePath() . '. Operation cancelled.');
     }
 }