Try to develop on a brandnew Hetzner nextcloud install.
Tried to set up a new app but whatever I do I never get access to it. Either βnot foundβ or CSFR errors. I spent hours of debugging but canβt find any solution by myself.
The setup is like this:
root@wartungs:/var/www/html# tree apps/registrationapp/
apps/registrationapp/
βββ appinfo
β βββ bootstrap.php
β βββ info.xml
β βββ routes.php
βββ lib
β βββ Controller
β βββ RegistrationController.php
βββ templates
βββ register.php
5 directories, 5 files
bootstrap:
<?php
declare(strict_types=1);
namespace OCA\RegistrationApp\AppInfo;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Services\IRouterService;
use OCA\RegistrationApp\Controller\RegistrationController;
class Application implements IBootstrap {
public function register(IRegistrationContext $context): void {
$context->registerController(RegistrationController::class);
}
public function boot(IBootContext $context): void {
$routerService = $context->getAppContainer()->get(IRouterService::class);
// β‘ Route PUBLIC !!!
$routerService->registerPublicRoute('registrationapp', 'registration#showForm');
}
}
info.xml:
<?xml version="1.0"?>
<info>
<id>registrationapp</id>
<name>Wartungsapp Registration</name>
<description>Benutzerregistrierung fΓΌr nextcloud.wartungs.app</description>
<licence>agpl</licence>
<author>Steffen Mutter</author>
<version>0.2.0</version>
<namespace>RegistrationApp</namespace>
<category>tools</category>
<types>
<type>authentication</type>
</types>
<dependencies>
<nextcloud min-version="27" max-version="30" />
</dependencies>
<routes>appinfo/routes.php</routes>
<bootstrap>appinfo/bootstrap.php</bootstrap>
</info>
routes.php:
<?php
declare(strict_types=1);
return [
'routes' => [
[
'name' => 'registrationapp#registration.showForm',
'url' => '/registrieren', // <-- NO Apps dir mentioned: otherwise CSFR!
'verb' => 'GET',
'defaults' => [
'_public' => true,
],
],
]
];
RegistrationController.php:
<?php
declare(strict_types=1);
namespace OCA\RegistrationApp\Controller;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
/**
* @PublicPage
* @NoCSRFRequired
*/
class RegistrationController extends Controller {
public function __construct(IRequest $request) {
parent::__construct('registrationapp', $request);
}
public function showForm(): TemplateResponse {
return new TemplateResponse('registrationapp', 'register');
}
}
register.php:
<div style="text-align: center; margin-top: 20px;">
<h1>Registrier</h1>
<p>content 2 come</p>
</div>
This app MUST be accessible always. But it is either never found, nextcloud crashes, or claims to be a CSFR. WTF?!?
Canβt be so difficult to create an public accessible php script. Nextcloud seems to be closed like Fort Knox.
Help highly appreciated!
Kind regards,
Steffen