コード例 #1
0
 /**
  * Import file entry point by using $this->service
  * Check POST method & get valid uploaded file
  */
 public function import()
 {
     $fileUploadName = "qtiPackage";
     if ($this->getRequestMethod() != Request::HTTP_POST) {
         throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.');
     }
     if (tao_helpers_Http::hasUploadedFile($fileUploadName)) {
         $file = tao_helpers_Http::getUploadedFile($fileUploadName);
         $mimeType = tao_helpers_File::getMimeType($file['tmp_name']);
         if (!in_array($mimeType, self::$accepted_types)) {
             $this->returnFailure(new common_exception_BadRequest());
         } else {
             $report = $this->service->importQtiTest($file['tmp_name']);
             if ($report->getType() === common_report_Report::TYPE_SUCCESS) {
                 $data = array();
                 foreach ($report as $r) {
                     $values = $r->getData();
                     $testid = $values->rdfsResource->getUri();
                     foreach ($values->items as $item) {
                         $itemsid[] = $item->getUri();
                     }
                     $data[] = array('testId' => $testid, 'testItems' => $itemsid);
                 }
                 return $this->returnSuccess($data);
             } else {
                 return $this->returnFailure(new common_exception_InconsistentData($report->getMessage()));
             }
         }
     } else {
         return $this->returnFailure(new common_exception_BadRequest());
     }
 }
コード例 #2
0
 /**
  *
  */
 public function apply()
 {
     $cssFileData = $file = \tao_helpers_Http::getUploadedFile('content');
     $batchTool = new CssBatchTool($cssFileData['tmp_name']);
     $report = $batchTool->applyToClass(\taoItems_models_classes_ItemsService::singleton()->getRootClass(), $cssFileData['name']);
     $this->returnJson($report);
 }
コード例 #3
0
 public function __construct()
 {
     parent::__construct();
     $authAdapter = new tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest());
     try {
         $user = $authAdapter->authenticate();
         $session = new common_session_RestSession($user);
         \common_session_SessionManager::startSession($session);
     } catch (common_user_auth_AuthFailedException $e) {
         $this->requireLogin();
     }
     /*
     	    $this->headers = tao_helpers_Http::getHeaders();
     	    $this->files = tao_helpers_Http::getFiles();
     */
     if ($this->hasHeader("Accept")) {
         try {
             $this->responseEncoding = tao_helpers_Http::acceptHeader($this->acceptedMimeTypes, $this->getHeader("Accept"));
         } catch (common_exception_ClientException $e) {
             $this->returnFailure($e);
         }
     }
     if ($this->hasHeader("Accept-Language")) {
         try {
         } catch (common_exception_ClientException $e) {
             $this->returnFailure($e);
         }
     }
     header('Content-Type: ' . $this->responseEncoding);
     //check auth method requested
     /**/
 }
コード例 #4
0
 /**
  * Check response encoding requested
  *
  * tao_actions_RestModule constructor.
  */
 public function __construct()
 {
     if ($this->hasHeader("Accept")) {
         try {
             $this->responseEncoding = tao_helpers_Http::acceptHeader($this->getAcceptableMimeTypes(), $this->getHeader("Accept"));
         } catch (common_exception_ClientException $e) {
             $this->returnFailure($e);
         }
     }
     header('Content-Type: ' . $this->responseEncoding);
 }
コード例 #5
0
 /**
  * (non-PHPdoc)
  * @see common_user_auth_Adapter::authenticate()
  */
 public function authenticate()
 {
     throw new common_exception_NotImplemented();
     $digest = tao_helpers_Http::getDigest();
     $data = tao_helpers_Http::parseDigest($digest);
     //store the hash A1 as a property to be updated on register/changepassword
     $trialLogin = '******';
     $trialPassword = '******';
     $A1 = md5($trialLogin . ':' . $this::realm . ':' . $trialPassword);
     $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);
     $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2);
 }
コード例 #6
0
 public function getFile()
 {
     if ($this->hasRequestParameter('uri')) {
         $uri = urldecode($this->getRequestParameter('uri'));
         $mediaSource = new MediaSource(array());
         $filepath = $mediaSource->download($uri);
         if ($this->hasRequestParameter('xml')) {
             $this->returnJson(htmlentities(file_get_contents($filepath)));
         } else {
             \tao_helpers_Http::returnFile($filepath, false);
         }
     } else {
         throw new \common_exception_Error('invalid media identifier');
     }
 }
コード例 #7
0
ファイル: StreamRange.php プロジェクト: oat-sa/tao-core
 /**
  * Create array of StreamRange instances based on current request range headers
  * @param StreamInterface $stream
  * @param ServerRequestInterface $request
  * @throws StreamRangeException
  * @return StreamRange[]
  */
 public static function createFromRequest(StreamInterface $stream, ServerRequestInterface $request = null)
 {
     $result = [];
     if ($request === null) {
         $headers = \tao_helpers_Http::getHeaders();
         $rangeHeader = isset($headers['Range']) ? [$headers['Range']] : null;
     } else {
         $rangeHeader = $request->hasHeader('Range') ? $request->getHeader('Range') : null;
     }
     if ($rangeHeader) {
         $ranges = explode(',', $rangeHeader[0]);
         foreach ($ranges as $range) {
             $range = str_replace('bytes=', '', $range);
             $result[] = new StreamRange($stream, $range);
         }
     }
     return $result;
 }
コード例 #8
0
ファイル: getFile.php プロジェクト: oat-sa/tao-core
if (count($parts) < 2) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
list($subPath, $file) = $parts;
$configPath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'tao' . DIRECTORY_SEPARATOR . 'websource_' . $ap . '.conf.php';
if (!file_exists($configPath)) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
$config = (include $configPath);
$compiledPath = $config['options']['path'];
$secretPassphrase = $config['options']['secret'];
$ttl = $config['options']['ttl'];
$correctToken = md5($timestamp . $subPath . $secretPassphrase);
if (time() - $timestamp > $ttl || $token != $correctToken) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
$path = array();
foreach (explode('/', $subPath . $file) as $ele) {
    $path[] = rawurldecode($ele);
}
$filename = $compiledPath . implode(DIRECTORY_SEPARATOR, $path);
if (strpos($filename, '?')) {
    // A query string is provided with the file to be retrieved - clean up!
    $parts = explode('?', $filename);
    $filename = $parts[0];
}
tao_helpers_Http::returnFile($filename);
exit;
コード例 #9
0
 private function renderFile($item, $path, $lang)
 {
     if (tao_helpers_File::securityCheck($path, true)) {
         $resolver = new ItemMediaResolver($item, $lang);
         $asset = $resolver->resolve($path);
         $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier());
         \tao_helpers_Http::returnFile($filePath);
     } else {
         throw new common_exception_Error('invalid item preview file path');
     }
 }
コード例 #10
0
 public function getFile()
 {
     if ($this->hasRequestParameter('uri')) {
         $uri = urldecode($this->getRequestParameter('uri'));
         $mediaSource = new MediaSource(array());
         $fileInfo = $mediaSource->getFileInfo($uri);
         $link = $fileInfo['link'];
         $fileManagement = $this->getServiceManager()->get(FileManagement::SERVICE_ID);
         if ($fileInfo['mime'] === 'application/qti+xml') {
             \tao_helpers_Http::returnStream($fileManagement->getFileStream($link));
             return;
         }
         if ($this->hasRequestParameter('xml')) {
             $this->returnJson(htmlentities((string) $fileManagement->getFileStream($link)));
         } else {
             \tao_helpers_Http::returnStream($fileManagement->getFileStream($link), $fileInfo['mime']);
         }
     } else {
         throw new \common_exception_Error('invalid media identifier');
     }
 }
コード例 #11
0
 private function renderResource($item, $path)
 {
     $lang = common_session_SessionManager::getSession()->getDataLanguage();
     $resolver = new ItemMediaResolver($item, $lang);
     $asset = $resolver->resolve($path);
     $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier());
     \tao_helpers_Http::returnFile($filePath);
 }
コード例 #12
0
 public function upload()
 {
     if (!$this->hasRequestParameter('content')) {
         throw new \common_exception_MissingParameter('content');
     }
     $file = \tao_helpers_Http::getUploadedFile('content');
     $filename = $this->getPlatformService()->storeFile($file['tmp_name'], 'platformtheme.css');
     $theme = $this->getPlatformService()->retrieveThemingConfig();
     $theme['css-file'] = $filename;
     $this->getPlatformService()->syncThemingConfig($theme);
     $this->returnJson(array('success' => __('Style modified')));
 }
コード例 #13
0
 /**
  * render an item as a Qti zip package
  * @author christophe GARCIA <*****@*****.**>
  */
 public function export()
 {
     try {
         if ($this->getRequestMethod() != Request::HTTP_GET) {
             throw new \common_exception_NotImplemented('Only GET method is accepted to export QIT Item.');
         }
         if (!$this->hasRequestParameter('id')) {
             $this->returnFailure(new \common_exception_MissingParameter('required parameter `id` is missing'));
         }
         $id = $this->getRequestParameter('id');
         $item = new \core_kernel_classes_Resource($id);
         $itemService = \taoItems_models_classes_ItemsService::singleton();
         if ($itemService->hasItemModel($item, array(ItemModel::MODEL_URI))) {
             $path = \tao_helpers_Export::getExportFile();
             $tmpZip = new \ZipArchive();
             $tmpZip->open($path, \ZipArchive::CREATE);
             $exporter = new QTIPackedItemExporter($item, $tmpZip);
             $exporter->export(array('apip' => false));
             $exporter->getZip()->close();
             header('Content-Type: application/zip');
             \tao_helpers_Http::returnFile($path, false);
             return;
         } else {
             $this->returnFailure(new \common_exception_NotFound('item can\'t be found'));
         }
     } catch (\Exception $e) {
         $this->returnFailure($e);
     }
 }
コード例 #14
0
ファイル: getFileFlysystem.php プロジェクト: oat-sa/tao-core
$configService = $driver->connect('config', array('dir' => $root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, 'humanReadable' => true));
$serviceManager = new ServiceManager($configService);
$configPath = $root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'tao' . DIRECTORY_SEPARATOR . 'websource_' . $webSourceId . '.conf.php';
if (!file_exists($configPath)) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
$config = (include $configPath);
if (!is_array($config) || !isset($config['className'])) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
$className = $config['className'];
$options = isset($config['options']) ? $config['options'] : array();
$source = new $className($options);
if (!$source instanceof FlyTokenWebSource) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
$fsService = $serviceManager->get(FileSystemService::SERVICE_ID);
$fileSystem = $fsService->getFileSystem($source->getOption($source::OPTION_FILESYSTEM_ID));
$source->setFileSystem($fileSystem);
try {
    $path = $source->getFilePathFromUrl($url);
    $stream = $source->getFileStream($path);
    tao_helpers_Http::returnStream($stream, $source->getMimetype($path));
    $stream->detach();
} catch (\tao_models_classes_FileNotFoundException $e) {
    header("HTTP/1.0 404 Not Found");
}
exit;
コード例 #15
0
 /**
  * Download a file to the item directory* 
  * @throws common_exception_MissingParameter
  */
 public function download()
 {
     if (!$this->hasRequestParameter('uri') || !$this->hasRequestParameter('path') || !$this->hasRequestParameter('lang')) {
         throw new common_exception_MissingParameter();
     }
     $item = new core_kernel_classes_Resource($this->getRequestParameter('uri'));
     $itemLang = $this->getRequestParameter('lang');
     $resolver = new ItemMediaResolver($item, $itemLang);
     $asset = $resolver->resolve($this->getRequestParameter('path'));
     $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier());
     return \tao_helpers_Http::returnFile($filePath);
 }
コード例 #16
0
 /**
  * Download a file to the item directory* 
  * @throws common_exception_MissingParameter
  */
 public function download()
 {
     if (!$this->hasRequestParameter('uri')) {
         throw new common_exception_MissingParameter('uri', __METHOD__);
     }
     $testUri = $this->getRequestParameter('uri');
     $test = new core_kernel_classes_Resource($testUri);
     if (!$this->hasRequestParameter('path')) {
         throw new common_exception_MissingParameter('path', __METHOD__);
     }
     $baseDir = taoQtiTest_helpers_ResourceManager::getBaseDir($test);
     $path = $baseDir . ltrim($this->getRequestParameter('path'), '/');
     tao_helpers_Http::returnFile($path);
 }
コード例 #17
0
 /**
  * Add a new custom interaction from the uploaded zip package
  */
 public function add()
 {
     //as upload may be called multiple times, we remove the session lock as soon as possible
     session_write_close();
     try {
         $file = \tao_helpers_Http::getUploadedFile('content');
     } catch (\common_exception_Error $e) {
         throw new PortableElementParserException('Unable to handle uploaded package.', 0, $e);
     }
     $portableElement = $this->getService()->import(PciModel::PCI_IDENTIFIER, $file['tmp_name']);
     $this->returnJson($this->getMinifiedModel($portableElement));
 }
コード例 #18
0
 /**
  * Upload a file to the item directory
  * 
  * @throws common_exception_MissingParameter
  */
 public function upload()
 {
     //as upload may be called multiple times, we remove the session lock as soon as possible
     session_write_close();
     $options = array();
     if ($this->hasRequestParameter('uri')) {
         $itemUri = $this->getRequestParameter('uri');
         $item = new core_kernel_classes_Resource($itemUri);
         $options['item'] = $item;
     }
     if ($this->hasRequestParameter('lang')) {
         $itemLang = $this->getRequestParameter('lang');
         $options['lang'] = $itemLang;
     }
     if (!$this->hasRequestParameter('path')) {
         throw new common_exception_MissingParameter('path', __METHOD__);
     }
     $relPath = '';
     if ($this->hasRequestParameter('relPath')) {
         $relPath = $this->getRequestParameter('relPath');
     }
     //if the string contains something else than letters, numbers or / throw an exception
     if (!preg_match('#^$|^[\\w\\/\\-\\._]+$#', $relPath)) {
         throw new InvalidArgumentException('The request parameter is invalid');
     }
     if (strpos($relPath, '/') === false) {
         $identifier = $relPath;
         $subPath = '/';
     } else {
         $identifier = substr($relPath, 0, strpos($relPath, '/'));
         $subPath = substr($relPath, strpos($relPath, '/') + 1);
     }
     $identifier = trim($identifier);
     $subPath = empty($subPath) ? '' : $subPath . '/';
     $clazz = $this->getManagementImplementationClass($identifier);
     $mediaManagement = new $clazz($options);
     $file = tao_helpers_Http::getUploadedFile('content');
     if (!is_uploaded_file($file['tmp_name'])) {
         throw new common_exception_Error('Non uploaded file "' . $file['tmp_name'] . '" returned from tao_helpers_Http::getUploadedFile()');
     }
     $filedata = $mediaManagement->add($file['tmp_name'], $file['name'], $subPath);
     echo json_encode($filedata);
 }
コード例 #19
0
 /**
  * Invokes download of pregenerated delivery
  * @throws \common_exception_Error
  * @throws \tao_models_classes_MissingRequestParameterException
  */
 public function download()
 {
     $instance = $this->getCurrentInstance();
     $fileResource = $instance->getOnePropertyValue(new core_kernel_classes_Property(BookletClassService::PROPERTY_FILE_CONTENT));
     if ($fileResource instanceof core_kernel_classes_Resource) {
         $file = new core_kernel_versioning_File($fileResource);
         header('Content-Disposition: attachment; filename="' . basename($file->getAbsolutePath()) . '"');
         \tao_helpers_Http::returnFile($file->getAbsolutePath());
     }
 }
コード例 #20
0
 /**
  * Download a file to the item directory* 
  * @throws common_exception_MissingParameter
  * @throws common_exception_Error
  * @throws tao_models_classes_FileNotFoundException
  */
 public function download()
 {
     $svgzSupport = false;
     if (!$this->hasRequestParameter('uri') || !$this->hasRequestParameter('path') || !$this->hasRequestParameter('lang')) {
         throw new common_exception_MissingParameter();
     }
     if ($this->hasRequestParameter('svgzsupport')) {
         $svgzSupport = true;
     }
     $item = new core_kernel_classes_Resource($this->getRequestParameter('uri'));
     $itemLang = $this->getRequestParameter('lang');
     $resolver = new ItemMediaResolver($item, $itemLang);
     $rawParams = $this->getRequest()->getRawParameters();
     //have to use raw value to respect special characters in names
     $asset = $resolver->resolve($rawParams['path']);
     $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier());
     $info = $asset->getMediaSource()->getFileInfo($asset->getMediaIdentifier());
     if ($info['mime'] != 'application/qti+xml') {
         header('Content-Type: ' . $info['mime']);
     }
     \tao_helpers_Http::returnFile($filePath, false, $svgzSupport);
 }
コード例 #21
0
 /**
  * Convert uploaded resource to base 64 code
  *
  * @return mixed
  */
 public function convert()
 {
     $resource = $file = \tao_helpers_Http::getUploadedFile('content');
     $base64Converter = new Base64ConverterModel($resource);
     $this->returnJson($base64Converter->convertToBase64());
 }
コード例 #22
0
 private function renderResource($item, $path)
 {
     $lang = common_session_SessionManager::getSession()->getDataLanguage();
     $resolver = new ItemMediaResolver($item, $lang);
     $asset = $resolver->resolve($path);
     if ($asset->getMediaSource() instanceof HttpSource) {
         throw new common_Exception('Only tao files available for rendering through item preview');
     }
     $info = $asset->getMediaSource()->getFileInfo($asset->getMediaIdentifier());
     $stream = $asset->getMediaSource()->getFileStream($asset->getMediaIdentifier());
     \tao_helpers_Http::returnStream($stream, $info['mime']);
 }
コード例 #23
0
ファイル: class.File.php プロジェクト: nagyist/tao-core
 public function accessFile()
 {
     list($extension, $module, $action, $code, $filePath) = explode('/', tao_helpers_Request::getRelativeUrl(), 5);
     list($key, $subPath) = explode(' ', base64_decode($code), 2);
     $source = WebsourceManager::singleton()->getWebsource($key);
     if ($source instanceof ActionWebSource) {
         $path = $source->getFileSystem()->getPath() . $subPath . (empty($filePath) ? '' : DIRECTORY_SEPARATOR . $filePath);
         tao_helpers_Http::returnFile($path);
     }
 }
コード例 #24
0
 /**
  * (non-PHPdoc)
  * @see \oat\tao\model\media\MediaBrowser::download
  */
 public function download($filename)
 {
     $sysPath = $this->getSysPath($filename);
     tao_helpers_Http::returnFile($sysPath);
 }
コード例 #25
0
ファイル: class.Http.php プロジェクト: oat-sa/tao-core
 /**
  * Return array of HTTP headers from the current request
  * @return array|false
  */
 public static function getHeaders()
 {
     if (self::$headers === null) {
         if (function_exists('apache_request_headers')) {
             $headers = apache_request_headers();
         } else {
             $headers = array();
             if (isset($_SERVER['CONTENT_TYPE'])) {
                 $headers['Content-Type'] = $_SERVER['CONTENT_TYPE'];
             }
             if (isset($_ENV['CONTENT_TYPE'])) {
                 $headers['Content-Type'] = $_ENV['CONTENT_TYPE'];
             }
             foreach ($_SERVER as $key => $value) {
                 if (substr($key, 0, 5) == "HTTP_") {
                     // this is chaos, basically it is just there to capitalize the first
                     // letter of every word that is not an initial HTTP and strip HTTP
                     // code from przemek
                     $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
                     $headers[$key] = $value;
                 }
             }
         }
         self::$headers = $headers;
     }
     return self::$headers;
 }
コード例 #26
0
 private function renderResource($item, $path)
 {
     $identifier = '';
     $subPath = $path;
     if (strpos($path, '://') !== false) {
         $identifier = substr($path, 0, strpos($path, '://'));
         $subPath = substr($path, strpos($path, '://') + 3);
     }
     //@todo : allow preview in a language other than the one in the session
     $lang = common_session_SessionManager::getSession()->getDataLanguage();
     $folder = taoItems_models_classes_ItemsService::singleton()->getItemFolder($item, $lang);
     if (tao_helpers_File::securityCheck($path, true)) {
         if ($identifier === 'taomgr') {
             $fileManager = FileManager::getFileManagementModel();
             $filename = $fileManager->retrieveFile($subPath);
         } else {
             $filename = $folder . $path;
         }
         tao_helpers_Http::returnFile($filename);
     } else {
         throw new common_exception_Error('invalid item preview file path');
     }
 }