Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit 976b74f

Browse files
committed
Add the posibility to secure the application
1 parent 5933d5f commit 976b74f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
# Pocs
22
Pocs stands for PHP Opcode Cache Status and provides a simple dashboard with some (OpCache)[http://php.net/manual/en/book.opcache.php]
33
status information's.
4+
5+
## Secure Pocs
6+
To secure Pocs just create a `pocs.config.php` file in the same directory as the pocs.phar is stored and define the
7+
following constants.
8+
9+
```php
10+
define('POCS_AUTH_USER', 'USERNAME');
11+
define('POCS_AUTH_PW', 'PASSWORD');
12+
```

web/index.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66
die("Module Zend OPcache is not loaded");
77
}
88

9+
$pocsConfigFile = str_replace(
10+
'phar://',
11+
'',
12+
dirname(dirname(__DIR__)). '/pocs.config.php'
13+
);
14+
15+
if (file_exists($pocsConfigFile)) {
16+
include $pocsConfigFile;
17+
18+
if (defined('POCS_AUTH_USER') && defined('POCS_AUTH_PW')) {
19+
$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null;
20+
$pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null;
21+
22+
if (false === (isset($user, $pass) && [POCS_AUTH_USER, POCS_AUTH_PW] === [$user, $pass])) {
23+
header('WWW-Authenticate: Basic realm="My Realm"');
24+
header('HTTP/1.0 401 Unauthorized');
25+
die("Not authorized");
26+
}
27+
}
28+
}
29+
930
class IndexView
1031
{
1132
private $configuration;

0 commit comments

Comments
 (0)