Skip to content

Commit

Permalink
Development (#27)
Browse files Browse the repository at this point in the history
* Fix: boolean

* add .env to .gitignore

* Fix: Debug env variables

* Fix: Debug texts

* Fix: when imagick is not installed
  • Loading branch information
Kipjr authored Aug 29, 2023
1 parent 747a2fa commit ae341ca
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/*
*.save
*.swp
.env
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ services:
MW_DB_DATABASE: ${DB_DATABASE:-marktwerking}
MW_BAR_PASSWORD: ${MW_ADMIN_PASSWORD:-MW23}
MW_IP_WHITELIST: ${MW_IP_WHITELIST:-"192.168.4.0/24,192.168.40.0/24"}
MW_DEBUG: ${MW_DEBUG:-False}
MW_DEBUG: ${MW_DEBUG:-0}
TITLE: Marktwerking 2023
tty: true
# volumes:
# - ./src/html:/var/www/html
# volumes:
# - ./src/html:/var/www/html
ports:
- target: 80
host_ip: ${MW_CHOST_IP:-0.0.0.0}
Expand Down
43 changes: 23 additions & 20 deletions src/html/bar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@


if (isset($_POST["submit"])) {

$check = getimagesize($files[$key]["tmp_name"]);
list($width, $height) = getimagesize('path to image');
$size = getimagesize($files[$key]["tmp_name"]);
$type = image_type_to_mime_type($files[$key]["tmp_name"]);
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
finfo_file($finfo,$files[$key]["tmp_name"]);
if ($check !== false) {
/*echo "File is an image - " . $check["mime"] . ".";*/
$uploadOk = 1;
Expand Down Expand Up @@ -60,25 +63,25 @@
unlink("$target_file");
if (move_uploaded_file($files[$key]["tmp_name"], $target_file)) {
/*echo "The file " . basename($files[$key]["name"]) . " has been uploaded.";*/

$im = new imagick($target_file);
$imageprops = $im->getImageGeometry();
$width = $imageprops['width'];
$height = $imageprops['height'];
if($width > $height){
$newHeight = 200;
$newWidth = (200 / $height) * $width;
}else{
$newWidth = 200;
$newHeight = (200 / $width) * $height;
if(get_loaded_extensions('imagick')){
$im = new imagick($target_file);
$imageprops = $im->getImageGeometry();
$width = $imageprops['width'];
$height = $imageprops['height'];
if($width > $height){
$newHeight = 200;
$newWidth = (200 / $height) * $width;
} else {
$newWidth = 200;
$newHeight = (200 / $width) * $height;
}
$im->resizeImage($newWidth,$newHeight, imagick::FILTER_LANCZOS, 0.9, true);
$im->cropImage (200,200,0,0);
$im->writeImage( $target_file );
/* echo '<img src=' . $target_file . '>';*/
} else {
// no imagick installed
}
$im->resizeImage($newWidth,$newHeight, imagick::FILTER_LANCZOS, 0.9, true);
$im->cropImage (200,200,0,0);
$im->writeImage( $target_file );
/* echo '<img src=' . $target_file . '>';*/



} else {
$message= "<br>Sorry, there was an error uploading your file.";
}
Expand Down
18 changes: 12 additions & 6 deletions src/html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
if (MW_DEBUG == True) {
error_reporting(E_ALL);
ini_set('display_errors',1);
$OutputString = "";
}


Expand All @@ -21,34 +22,39 @@ function ipCIDRCheck ($IP, $CIDR) {
function isAllowed($ip){
// If the ip is matched, return true
if(in_array($ip, MW_IP_WHITELIST)) {
if(MW_DEBUG == True){echo "\nIP is in whitelist\n";}
if(MW_DEBUG == True){$OutputString = "\nIP is in whitelist\n";}
return true;
}

foreach(MW_IP_WHITELIST as $i){
$wildcardPos = strpos($i, "*");
// Check if the ip has a wildcard
if($wildcardPos !== false && substr($ip, 0, $wildcardPos) . "*" == $i) {
if(MW_DEBUG == True){echo "\nIP $ip in wildcard\n";}
if(MW_DEBUG == True){$OutputString = "\nIP $ip in wildcard\n";}
return true;
}
if(str_contains($i,"/")){
if(ipCIDRCheck ($ip, $i)){
if(MW_DEBUG == True){echo "\nIP $ip in CIDR $i\n";}
if(MW_DEBUG == True){$OutputString = "\nIP $ip in CIDR $i\n";}
return true;
}
}
}
if(MW_DEBUG == True){echo "\nIP $ip not in whitelist\n";}
if(MW_DEBUG == True){$OutputString = "\nIP $ip not in whitelist\n";}
return false;
}

if(! isAllowed($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$RemoteIP = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'] ;

if(! isAllowed($RemoteIP)) {
if(MW_DEBUG !=True){
header('Location: about:blank');
} else {
echo "<pre>";
echo "HTTP_X_FORWARDED_FOR: " . $_SERVER['HTTP_X_FORWARDED_FOR'] . "<br>" . "MW_IP_WHITELIST:";
echo $OutputString;
echo "MW_DEBUG: " . (MW_DEBUG === True) . "\n";
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { echo "HTTP_X_FORWARDED_FOR: " . $_SERVER['HTTP_X_FORWARDED_FOR'] . "<br>"; }
echo "REMOTE_ADDR: " . $_SERVER['REMOTE_ADDR'] . "<br>" . "MW_IP_WHITELIST:";
print_r(MW_IP_WHITELIST);
echo "</pre>";
}
Expand Down
21 changes: 7 additions & 14 deletions src/html/settings.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
<?php
define('DEBUG',False);

if (!function_exists('getenv_docker')) {
global $debug;
$debug = 0;
function getenv_docker($env, $default)
{
if ($fileEnv = getenv($env . '_FILE')) {
if ($GLOBALS['debug']) {
echo "<br>file:";
print_r(rtrim(file_get_contents($fileEnv), "\r\n"));
}
return rtrim(file_get_contents($fileEnv), "\r\n");
} else if (($val = getenv($env)) !== false) {
if ($GLOBALS['debug']) {
if (($val = getenv($env)) !== false) {
if (DEBUG) {
echo "<br>getenv:";
print_r($val);
}
return $val;
} else {
if ($GLOBALS['debug']) {
if (DEBUG) {
echo "<br>default:";
print_r($default);
}
Expand All @@ -32,8 +25,8 @@ function getenv_docker($env, $default)
define('DB_PASSWORD', getenv_docker('MW_DB_PASSWORD', 'dbpassword'));
define('DB_DATABASE', getenv_docker('MW_DB_DATABASE', 'marktwerking'));

define('BAR_PASSWORD', getenv_docker('MW_BAR_PASSWORD', 'MW2021'));
define('BAR_PASSWORD', getenv_docker('MW_BAR_PASSWORD', 'MW2023'));
define('TITLE', getenv_docker('MW_TITLE', 'Marktwerking'));
define('MW_DEBUG',(boolean) getenv_docker('MW_DEBUG', False));
$whitelist = getenv_docker('MW_IP_WHITELIST', '127.0.0.1');
define('MW_DEBUG',(bool) getenv_docker('MW_DEBUG', False));
$whitelist = str_replace('"', '', getenv_docker('MW_IP_WHITELIST', '127.0.0.1'));
define('MW_IP_WHITELIST', array_unique(array_merge(explode(',', $whitelist), array('127.0.0.1'))));

0 comments on commit ae341ca

Please sign in to comment.