Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allow restriction of resources by IP #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow restriction of resources by IP
  • Loading branch information
rawbertp committed Nov 5, 2019
commit c0201bbb907ec609fe99efd74421eb84a9e4b17d
17 changes: 15 additions & 2 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

require_once('../lib/config.php');
require_once('../lib/configsetup.inc.php');

if ($config['use_privileged_access'] === true && !in_array($_SERVER['REMOTE_ADDR'], $config['privileged_ips']) ) {
die(sprintf("%s is not allowed to access this page", $_SERVER['REMOTE_ADDR']));
}

?>
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -66,8 +71,16 @@
echo '<div class="form-row">';
switch($field['type']) {
case 'input':
echo '<label data-l10n="'.$panel.'_'.$key.'">'.$panel.'_'.$key.'</label><input type="text" name="'.$field['name'].'" value="'.$field[
'value'].'" placeholder="'.$field['placeholder'].'"/>';
echo '<label data-l10n="'.$panel.'_'.$key.'">'.$panel.'_'.$key.'</label>';

if (is_array($field['value']) && !empty($field['value'])) {
foreach($field['value'] as $input_key => $input_value) {
echo '<input type="text" name="' . $field['name'] . '" value="' .$input_value . '" placeholder="' . $field['placeholder'] . '"/>';
}
}
else {
echo '<input type="text" name="'.$field['name'].'" value="'.$field['value'].'" placeholder="'.$field['placeholder'].'"/>';
}
break;
case 'checkbox':
$checked = '';
Expand Down
5 changes: 5 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@
$config['jpeg_quality_chroma'] = 70;
$config['jpeg_quality_image'] = 80;

// TODO (Documentation) For this feature to work the webserver must be configured
// to listen on IPv4 interfaces only. It does not work with IPv6!
$config['use_privileged_access'] = false; //TODO default to false
$config['privileged_ips']['0'] = '127.0.0.1';
//TODO there could be an option for 'guest_ips' - which, if empty, allows guest access for any IP
5 changes: 5 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
require_once('lib/db.php');
require_once('lib/filter.php');

if ($config['use_privileged_access'] === true && !in_array($_SERVER['REMOTE_ADDR'], $config['privileged_ips']) ) {
header('Location: gallery.php');
die(sprintf("%s is not allowed to access this page", $_SERVER['REMOTE_ADDR']));
}

$images = getImagesFromDB();
$imagelist = ($config['newest_first'] === true) ? array_reverse($images) : $images;
?>
Expand Down
13 changes: 13 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,18 @@
'name' => 'print[msg]',
'value' => $config['print']['msg']
]
],
'security' => [
'use_privileged_access' => [
'type' => 'checkbox',
'name' => 'use_privileged_access',
'value' => $config['use_privileged_access']
],
'privileged_ips' => [
'type' => 'input',
'placeholder' => '',
'name' => 'privileged_ips[]',
'value' => $config['privileged_ips']
]
]
];