@@ -35,7 +35,7 @@ before_install: | |||||
# install core | # install core | ||||
- cd ../ | - cd ../ | ||||
- git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH nextcloud | - git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH nextcloud | ||||
- mv "$TRAVIS_BUILD_DIR" nextcloud/apps/static | |||||
- mv "$TRAVIS_BUILD_DIR" nextcloud/apps/raw | |||||
before_script: | before_script: | ||||
- if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s oc_autotest; fi | - if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s oc_autotest; fi | ||||
@@ -45,9 +45,9 @@ before_script: | |||||
- cd nextcloud | - cd nextcloud | ||||
- mkdir data | - mkdir data | ||||
- ./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass='' | - ./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass='' | ||||
- ./occ app:enable static | |||||
- ./occ app:enable raw | |||||
- php -S localhost:8080 & | - php -S localhost:8080 & | ||||
- cd apps/static | |||||
- cd apps/raw | |||||
script: | script: | ||||
- make test | - make test | ||||
@@ -1,4 +1,4 @@ | |||||
# Static | |||||
# Raw | |||||
Place this app in **nextcloud/apps/** | Place this app in **nextcloud/apps/** | ||||
## Building the app | ## Building the app | ||||
@@ -1,14 +1,14 @@ | |||||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||||
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" | <info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" | ||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd"> | xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd"> | ||||
<id>static</id> | |||||
<name>Static</name> | |||||
<id>raw</id> | |||||
<name>Raw</name> | |||||
<summary>a</summary> | <summary>a</summary> | ||||
<description><![CDATA[a]]></description> | <description><![CDATA[a]]></description> | ||||
<version>0.0.1</version> | <version>0.0.1</version> | ||||
<licence>agpl</licence> | <licence>agpl</licence> | ||||
<author mail="b@c.de" >a</author> | <author mail="b@c.de" >a</author> | ||||
<namespace>Static</namespace> | |||||
<namespace>Raw</namespace> | |||||
<category>files</category> | <category>files</category> | ||||
<bugs>https://example.com</bugs> | <bugs>https://example.com</bugs> | ||||
<dependencies> | <dependencies> | ||||
@@ -16,8 +16,8 @@ | |||||
</dependencies> | </dependencies> | ||||
<navigations> | <navigations> | ||||
<navigation> | <navigation> | ||||
<name>Static</name> | |||||
<route>static.page.index</route> | |||||
<name>Raw</name> | |||||
<route>raw.page.index</route> | |||||
</navigation> | </navigation> | ||||
</navigations> | </navigations> | ||||
</info> | </info> |
@@ -1,15 +1,9 @@ | |||||
<?php | <?php | ||||
/** | |||||
* Create your routes in here. The name is the lowercase name of the controller | |||||
* without the controller part, the stuff after the hash is the method. | |||||
* e.g. page#index -> OCA\Static\Controller\PageController->index() | |||||
* | |||||
* The controller class has to be registered in the application.php file since | |||||
* it's instantiated in there | |||||
*/ | |||||
return [ | return [ | ||||
'routes' => [ | |||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], | |||||
['name' => 'page#do_echo', 'url' => '/echo', 'verb' => 'POST'], | |||||
] | |||||
'routes' => [ | |||||
['name' => 'pubPage#getByToken', 'url' => '/s/{token}', 'verb' => 'GET'], | |||||
['name' => 'privatePage#getByPath', 'url' => '/files/{path}', 'verb' => 'GET', | |||||
'requirements' => array('path' => '.+')], | |||||
] | |||||
]; | ]; |
@@ -1,5 +1,5 @@ | |||||
{ | { | ||||
"name": "Static", | |||||
"name": "Raw", | |||||
"description": "a", | "description": "a", | ||||
"type": "project", | "type": "project", | ||||
"license": "AGPL", | "license": "AGPL", | ||||
@@ -1,31 +0,0 @@ | |||||
<?php | |||||
namespace OCA\Static\Controller; | |||||
use OCP\IRequest; | |||||
use OCP\AppFramework\Http\TemplateResponse; | |||||
use OCP\AppFramework\Http\DataResponse; | |||||
use OCP\AppFramework\Controller; | |||||
class PageController extends Controller { | |||||
private $userId; | |||||
public function __construct($AppName, IRequest $request, $UserId){ | |||||
parent::__construct($AppName, $request); | |||||
$this->userId = $UserId; | |||||
} | |||||
/** | |||||
* CAUTION: the @Stuff turns off security checks; for this page no admin is | |||||
* required and no CSRF check. If you don't know what CSRF is, read | |||||
* it up in the docs or you might create a security hole. This is | |||||
* basically the only required method to add this exemption, don't | |||||
* add it to any other method if you don't exactly know what it does | |||||
* | |||||
* @NoAdminRequired | |||||
* @NoCSRFRequired | |||||
*/ | |||||
public function index() { | |||||
return new TemplateResponse('static', 'index'); // templates/index.php | |||||
} | |||||
} |
@@ -0,0 +1,43 @@ | |||||
<?php | |||||
namespace OCA\Raw\Controller; | |||||
use OCP\IRequest; | |||||
use OCP\IServerContainer; | |||||
use OCP\AppFramework\Http\NotFoundResponse; | |||||
use OCP\AppFramework\Controller; | |||||
use OCP\Files\Folder; | |||||
use OCP\Files\NotFoundException; | |||||
class PrivatePageController extends Controller { | |||||
use RawResponse; | |||||
private $userFolder; | |||||
public function __construct( | |||||
$AppName, | |||||
$UserId, | |||||
IRequest $request, | |||||
IServerContainer $serverContainer | |||||
) { | |||||
parent::__construct($AppName, $request); | |||||
$this->userFolder = $serverContainer->getUserFolder($UserId); | |||||
} | |||||
/** | |||||
* @NoAdminRequired | |||||
* @NoCSRFRequired | |||||
*/ | |||||
public function getByPath($path) { | |||||
if (!$this->userFolder) { | |||||
return new NotFoundResponse(); | |||||
} | |||||
try { | |||||
$node = $this->userFolder->get($path); | |||||
} catch (NotFoundException $e) { | |||||
return new NotFoundResponse(); | |||||
} | |||||
$content = $node->getContent(); | |||||
$mimetype = $node->getMimeType(); | |||||
$this->returnRawResponse($content, $mimetype); | |||||
} | |||||
} |
@@ -0,0 +1,36 @@ | |||||
<?php | |||||
namespace OCA\Raw\Controller; | |||||
use OCP\IRequest; | |||||
use OCP\Share\IManager; | |||||
use OCP\AppFramework\Controller; | |||||
use OCP\Files\Folder; | |||||
class PubPageController extends Controller { | |||||
use RawResponse; | |||||
private $manager; | |||||
public function __construct( | |||||
$AppName, | |||||
IRequest $request, | |||||
IManager $shareManager | |||||
) { | |||||
parent::__construct($AppName, $request); | |||||
$this->manager = $shareManager; | |||||
} | |||||
/** | |||||
* @PublicPage | |||||
* @NoAdminRequired | |||||
* @NoCSRFRequired | |||||
*/ | |||||
public function getByToken($token) { | |||||
$share = $this->manager->getShareByToken($token); | |||||
$node = $share->getNode(); | |||||
// if ($node->getType() === 'dir') { TODO } | |||||
$content = $node->getContent(); | |||||
$mimetype = $node->getMimeType(); | |||||
$this->returnRawResponse($content, $mimetype); | |||||
} | |||||
} |
@@ -0,0 +1,15 @@ | |||||
<?php | |||||
namespace OCA\Raw\Controller; | |||||
trait RawResponse { | |||||
protected function returnRawResponse($content, $mimetype) { | |||||
// Ugly hack to prevent security middleware messing up the CSP. | |||||
header( | |||||
"Content-Security-Policy: sandbox; default-src 'none'; img-src data:; media-src data; " | |||||
. "style-src data: 'unsafe-inline'; font-src data:; frame-src data:" | |||||
); | |||||
header("Content-Type: ${mimetype}"); | |||||
echo $content; | |||||
exit; | |||||
} | |||||
} |
@@ -1,6 +1,6 @@ | |||||
<?php | <?php | ||||
script('static', 'script'); | |||||
style('static', 'style'); | |||||
script('raw', 'script'); | |||||
style('raw', 'style'); | |||||
?> | ?> | ||||
<div id="app"> | <div id="app"> | ||||
@@ -1,6 +1,6 @@ | |||||
<?php | <?php | ||||
namespace OCA\Static\Tests\Integration\Controller; | |||||
namespace OCA\Raw\Tests\Integration\Controller; | |||||
use OCP\AppFramework\App; | use OCP\AppFramework\App; | ||||
use Test\TestCase; | use Test\TestCase; | ||||
@@ -17,13 +17,13 @@ class AppTest extends TestCase { | |||||
public function setUp() { | public function setUp() { | ||||
parent::setUp(); | parent::setUp(); | ||||
$app = new App('static'); | |||||
$app = new App('raw'); | |||||
$this->container = $app->getContainer(); | $this->container = $app->getContainer(); | ||||
} | } | ||||
public function testAppInstalled() { | public function testAppInstalled() { | ||||
$appManager = $this->container->query('OCP\App\IAppManager'); | $appManager = $this->container->query('OCP\App\IAppManager'); | ||||
$this->assertTrue($appManager->isInstalled('static')); | |||||
$this->assertTrue($appManager->isInstalled('raw')); | |||||
} | } | ||||
} | } |
@@ -1,12 +1,12 @@ | |||||
<?php | <?php | ||||
namespace OCA\Static\Tests\Unit\Controller; | |||||
namespace OCA\Raw\Tests\Unit\Controller; | |||||
use PHPUnit_Framework_TestCase; | use PHPUnit_Framework_TestCase; | ||||
use OCP\AppFramework\Http\TemplateResponse; | use OCP\AppFramework\Http\TemplateResponse; | ||||
use OCA\Static\Controller\PageController; | |||||
use OCA\Raw\Controller\PageController; | |||||
class PageControllerTest extends PHPUnit_Framework_TestCase { | class PageControllerTest extends PHPUnit_Framework_TestCase { | ||||
@@ -17,7 +17,7 @@ class PageControllerTest extends PHPUnit_Framework_TestCase { | |||||
$request = $this->getMockBuilder('OCP\IRequest')->getMock(); | $request = $this->getMockBuilder('OCP\IRequest')->getMock(); | ||||
$this->controller = new PageController( | $this->controller = new PageController( | ||||
'static', $request, $this->userId | |||||
'raw', $request, $this->userId | |||||
); | ); | ||||
} | } | ||||
@@ -9,8 +9,8 @@ require_once __DIR__.'/../../../lib/base.php'; | |||||
// Fix for "Autoload path not allowed: .../tests/lib/testcase.php" | // Fix for "Autoload path not allowed: .../tests/lib/testcase.php" | ||||
\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); | \OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); | ||||
// Fix for "Autoload path not allowed: .../static/tests/testcase.php" | |||||
\OC_App::loadApp('static'); | |||||
// Fix for "Autoload path not allowed: .../raw/tests/testcase.php" | |||||
\OC_App::loadApp('raw'); | |||||
if(!class_exists('PHPUnit_Framework_TestCase')) { | if(!class_exists('PHPUnit_Framework_TestCase')) { | ||||
require_once('PHPUnit/Autoload.php'); | require_once('PHPUnit/Autoload.php'); | ||||