示例#1
0
 /**
  *
  */
 public function actionGet()
 {
     $_service = FilterInput::get(INPUT_GET, 'service', '');
     try {
         /** @var BaseFileSvc $_obj */
         $_obj = ServiceHandler::getServiceObject($_service);
         switch ($_obj->getType()) {
             case 'Local File Storage':
             case 'Remote File Storage':
                 $_fullPath = FilterInput::get(INPUT_GET, 'path', '');
                 if (!empty($_obj->privatePaths)) {
                     // match path pieces to public accessible
                     $_count = substr_count($_fullPath, '/');
                     $_pos = -1;
                     for ($_ndx = 0; $_ndx < $_count; $_ndx++) {
                         $_pos = strpos($_fullPath, '/', $_pos + 1);
                         $_piece = substr($_fullPath, 0, $_pos) . '/';
                         if (false !== array_search($_piece, $_obj->privatePaths)) {
                             $_statusHeader = 'HTTP/1.1 403 Forbidden. You have no access to this file or folder.';
                             header($_statusHeader);
                             header('Content-Type: text/html');
                             Pii::end();
                         }
                     }
                     // check for full file path
                     if (false !== array_search($_fullPath, $_obj->privatePaths)) {
                         $_statusHeader = 'HTTP/1.1 403 Forbidden. You have no access to this file or folder.';
                         header($_statusHeader);
                         header('Content-Type: text/html');
                         Pii::end();
                     }
                 }
                 $_container = substr($_fullPath, 0, strpos($_fullPath, '/'));
                 $_path = ltrim(substr($_fullPath, strpos($_fullPath, '/') + 1), '/');
                 $_obj->streamFile($_container, $_path);
                 Pii::end();
                 break;
         }
         $_statusHeader = 'HTTP/1.1 403 Forbidden. You have no access to this file or folder.';
         header($_statusHeader);
         header('Content-Type: text/html');
         Pii::end();
     } catch (\Exception $ex) {
         die($ex->getMessage());
     }
 }
示例#2
0
 public function testServiceRequestEvents()
 {
     //	A post test
     Platform::on('user.list', 'http://dsp.local/web/eventReceiver', static::API_KEY);
     //	An inline test
     Platform::on('user.list', function ($event, $eventName, $dispatcher) {
         $this->assertEquals('user.list', $eventName);
         $this->_actionEventFired = 1;
         echo 'event "user.list" has been fired.';
     }, static::API_KEY);
     $this->_preProcessFired = $this->_postProcessFired = 0;
     $_config = (require dirname(dirname(__DIR__)) . '/config/web.php');
     /** @var \RestController $_controller */
     list($_controller, $_actionId) = Pii::app()->createController('rest/user');
     try {
         $_controller->setService('user');
         $_service = ServiceHandler::getService($_controller->getService());
         $_service->on(PlatformServiceEvents::PRE_PROCESS, function ($event, $eventName, $dispatcher) {
             $this->assertEquals('user.get.pre_process', $eventName);
             $this->_preProcessFired = 1;
         });
         $_service->on(PlatformServiceEvents::POST_PROCESS, function ($event, $eventName, $dispatcher) {
             $this->assertEquals('user.get.post_process', $eventName);
             $this->_postProcessFired = 1;
         });
         //	Test GET
         $_request = Pii::app()->getRequestObject();
         $_request->query->set('app_name', Inflector::neutralize(__CLASS__));
         $_request->overrideGlobals();
         $_response = $_service->processRequest(null, HttpMethod::GET, false);
         $this->assertTrue(is_array($_response) && isset($_response['resource']));
         $this->assertTrue(1 == $this->_preProcessFired && 1 == $this->_postProcessFired && 1 == $this->_actionEventFired);
     } catch (\Exception $ex) {
         RestResponse::sendErrors($ex);
     }
 }
示例#3
0
 /**
  * Generic action handler
  *
  * @param string $action
  *
  * @return mixed
  */
 protected function _handleAction($action)
 {
     try {
         $_service = ServiceHandler::getService($this->_service);
         return $_service->processRequest($this->_resource, $action);
     } catch (\Exception $ex) {
         RestResponse::sendErrors($ex, isset($_service) ? $_service->getOutputFormat() : DataFormats::JSON, false, false);
         return null;
     }
 }