diff --git a/.gitignore b/.gitignore
index 89052b7..21956d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.idea/*
*.save
*.swp
+.env
diff --git a/docker-compose.yml b/docker-compose.yml
index 8ca69dd..5a3f34e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -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}
diff --git a/src/html/bar/index.php b/src/html/bar/index.php
index 9e95bd5..427fbaf 100644
--- a/src/html/bar/index.php
+++ b/src/html/bar/index.php
@@ -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;
@@ -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 '';*/
+ } 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 '';*/
-
-
-
} else {
$message= "
Sorry, there was an error uploading your file.";
}
diff --git a/src/html/index.php b/src/html/index.php
index ba749f3..25358fb 100644
--- a/src/html/index.php
+++ b/src/html/index.php
@@ -4,6 +4,7 @@
if (MW_DEBUG == True) {
error_reporting(E_ALL);
ini_set('display_errors',1);
+ $OutputString = "";
}
@@ -21,7 +22,7 @@ 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;
}
@@ -29,26 +30,31 @@ function isAllowed($ip){
$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 "
"; - echo "HTTP_X_FORWARDED_FOR: " . $_SERVER['HTTP_X_FORWARDED_FOR'] . ""; } diff --git a/src/html/settings.php b/src/html/settings.php index c42d1c7..d12c46e 100644 --- a/src/html/settings.php +++ b/src/html/settings.php @@ -1,24 +1,17 @@ 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 "
" . "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'] . "
"; } + echo "REMOTE_ADDR: " . $_SERVER['REMOTE_ADDR'] . "
" . "MW_IP_WHITELIST:"; print_r(MW_IP_WHITELIST); echo "