Skip to content

Commit a2d19c0

Browse files
authored
Merge pull request #148 from moufmouf/ui_disable
Allows disabling UI via an environment variable
2 parents 693a63c + 3fa93f9 commit a2d19c0

File tree

5 files changed

+63
-22
lines changed

5 files changed

+63
-22
lines changed

doc/installing_mouf.md

+8
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,11 @@ Mouf UI is designed to be used on a development environment, not on a production
107107
If you are running a production server (if you are not on a development environment), it is more secure
108108
to prevent Apache from writing to the application directories (or to open those rights on a very
109109
restrictive basis). In this scenario, you don't need to share write rights with Apache.
110+
111+
Also, you might want to completely prevent users from accessing the UI. You can disable Mouf UI
112+
by setting the `MOUF_UI` environment variable to 0.
113+
114+
```
115+
# Disable Mouf UI via environment variable:
116+
MOUF_UI=0
117+
```

src-dev/Mouf/Controllers/MoufInstallController.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* For the full copyright and license information, please view the LICENSE.txt
88
* file that was distributed with this source code.
99
*/
10-
namespace Mouf\Controllers;
11-
10+
namespace Mouf\Controllers;
11+
1212
use Mouf\Html\Template\TemplateInterface;
1313

1414
use Mouf\Html\Widgets\MessageService\Service\UserMessageInterface;
@@ -19,7 +19,7 @@
1919

2020
use Mouf\Html\HtmlElement\HtmlBlock;
2121

22-
use Mouf\Mvc\Splash\Controllers\Controller;
22+
use Mouf\Mvc\Splash\Controllers\Controller;
2323

2424

2525
/**
@@ -49,6 +49,17 @@ class MoufInstallController extends Controller {
4949
*/
5050
public function index() {
5151

52+
$moufUI = getenv('MOUF_UI');
53+
if ($moufUI !== false) {
54+
$moufUI = (bool) $moufUI;
55+
if (!$moufUI) {
56+
header('HTTP/1.1 403 Forbidden');
57+
echo 'Error! Access to Mouf UI is forbidden on this environment (env variable MOUF_UI is set to 0)';
58+
exit;
59+
}
60+
}
61+
unset($moufUI);
62+
5263
if (!extension_loaded("curl")) {
5364
$this->contentBlock->addFile(dirname(__FILE__)."/../../views/mouf_installer/missing_curl.php", $this);
5465
} else {

src/direct/utils/check_rights.php

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
<?php
2-
/*
3-
* This file is part of the Mouf core package.
4-
*
5-
* (c) 2012 David Negrier <[email protected]>
6-
*
7-
* For the full copyright and license information, please view the LICENSE.txt
8-
* file that was distributed with this source code.
9-
*/
10-
2+
/*
3+
* This file is part of the Mouf core package.
4+
*
5+
* (c) 2012 David Negrier <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE.txt
8+
* file that was distributed with this source code.
9+
*/
10+
1111
/**
1212
* This file should be included at the beginning of each file of the "/direct" folder.
1313
* It checks that the rights are ok.
1414
* The user is allowed access to the file if he is logged, or if he is requesting the file from localhost
1515
* (because it could be a request from Mouf itself via Curl, and therefore not logged).
1616
*/
1717

18+
$moufUI = getenv('MOUF_UI');
19+
if ($moufUI !== false) {
20+
$moufUI = (bool) $moufUI;
21+
if (!$moufUI) {
22+
header('HTTP/1.1 403 Forbidden');
23+
echo 'Error! Access to Mouf UI is forbidden on this environment (env variable MOUF_UI is set to 0)';
24+
exit;
25+
}
26+
}
27+
unset($moufUI);
28+
1829
// TODO: remove this condition when everything is migrated to the new cookie propagation method.
1930
if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR'] /*|| $_SERVER['REMOTE_ADDR'] == '::1'*/) {
2031
return;

src/mouf_router.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
<?php
1+
<?php
2+
$moufUI = getenv('MOUF_UI');
3+
if ($moufUI !== false) {
4+
$moufUI = (bool) $moufUI;
5+
if (!$moufUI) {
6+
header('HTTP/1.1 403 Forbidden');
7+
echo 'Error! Access to Mouf UI is forbidden on this environment (env variable MOUF_UI is set to 0)';
8+
exit;
9+
}
10+
}
11+
unset($moufUI);
12+
213
if (!file_exists(__DIR__.'/../../../../mouf/no_commit/MoufUsers.php')) {
314

415
$rootUrl = $_SERVER['BASE']."/";

src/splash.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
2-
/*
3-
* This file is part of the Mouf core package.
4-
*
5-
* (c) 2012 David Negrier <[email protected]>
6-
*
7-
* For the full copyright and license information, please view the LICENSE.txt
8-
* file that was distributed with this source code.
9-
*/
10-
2+
/*
3+
* This file is part of the Mouf core package.
4+
*
5+
* (c) 2012 David Negrier <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE.txt
8+
* file that was distributed with this source code.
9+
*/
10+
1111
// Let's load the Mouf file, and the MoufAdmin file.
1212
// The MoufAdmin will replace the Mouf configuration file.
1313
if (file_exists(dirname(__FILE__).'/../MoufComponents.php')) {

0 commit comments

Comments
 (0)