-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add config parameter for usage in iframe
- Loading branch information
Radoslav Štofko
committed
Jan 13, 2022
1 parent
eea01d7
commit 5836545
Showing
8 changed files
with
133 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace OCA\Hidesidebars\AppInfo; | ||
|
||
use OCA\Files\Event\LoadAdditionalScriptsEvent; | ||
use OCA\Hidesidebars\Listener\CSPListener; | ||
use OCA\Hidesidebars\Listener\HidesidebarScripts; | ||
use OCP\AppFramework\App; | ||
use OCP\AppFramework\Bootstrap\IBootContext; | ||
use OCP\AppFramework\Bootstrap\IBootstrap; | ||
use OCP\AppFramework\Bootstrap\IRegistrationContext; | ||
use OCP\Security\CSP\AddContentSecurityPolicyEvent; | ||
|
||
class Application extends App implements IBootstrap | ||
{ | ||
public const APP_ID = 'hidesidebars'; | ||
public const CONFIG_FRAME_KEY = 'addAllowedFrameAncestorDomain'; | ||
|
||
public function __construct(array $params = []) | ||
{ | ||
parent::__construct(self::APP_ID, $params); | ||
} | ||
|
||
public function register(IRegistrationContext $context): void | ||
{ | ||
$context->registerEventListener(LoadAdditionalScriptsEvent::class, HidesidebarScripts::class); | ||
$context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class); | ||
} | ||
|
||
public function boot(IBootContext $context): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Hidesidebars\Listener; | ||
|
||
use OCA\Hidesidebars\AppInfo\Application; | ||
use OCP\AppFramework\Http\EmptyContentSecurityPolicy; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\IConfig; | ||
use OCP\Security\CSP\AddContentSecurityPolicyEvent; | ||
|
||
class CSPListener implements IEventListener { | ||
|
||
/** @var IConfig */ | ||
private $config; | ||
|
||
public function __construct(IConfig $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!$event instanceof AddContentSecurityPolicyEvent) { | ||
return; | ||
} | ||
|
||
$csp = new EmptyContentSecurityPolicy(); | ||
$csp->addAllowedFrameAncestorDomain($this->config->getSystemValue(Application::CONFIG_FRAME_KEY)); //'*.pointcz.com:*' | ||
$event->addPolicy($csp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Hidesidebars\Listener; | ||
|
||
use OC\User\Session; | ||
use OCA\Hidesidebars\AppInfo\Application; | ||
use OCA\Files\Event\LoadAdditionalScriptsEvent; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Util; | ||
|
||
class HidesidebarScripts implements IEventListener | ||
{ | ||
|
||
/** @var Session */ | ||
private $userSession; | ||
|
||
public function __construct(Session $userSession) | ||
{ | ||
$this->userSession = $userSession; | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!($event instanceof LoadAdditionalScriptsEvent)) { | ||
return; | ||
} | ||
|
||
if ($this->userSession->isLoggedIn()) { | ||
Util::addScript(Application::APP_ID, 'script'); | ||
} | ||
} | ||
} |