diff --git a/.gitignore b/.gitignore index a2d9a85..4897e6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .idea config.php -www.bat diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b2458ea --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [1.0.0] - 14-04-2022 +### Fixed +- Undefined warning when refreshing a page after execution. +- Traceroute error when there is no PID found. + +### Added +- Added Docker support. +- This CHANGELOG.md to track changes. + +## [0.1.0] - 17-01-2022 +### Changed +- First release. \ No newline at end of file diff --git a/LookingGlass.php b/LookingGlass.php index 9f28782..043b651 100644 --- a/LookingGlass.php +++ b/LookingGlass.php @@ -311,14 +311,16 @@ class LookingGlass foreach ($pipes as $pipe) { fclose($pipe); } - // retrieve parent pid - $ppid = $status['pid']; - // use ps to get all the children of this process - $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); - // kill remaining processes - foreach($pids as $pid) { - if (is_numeric($pid)) { - posix_kill($pid, 9); + if ($status['pid']) { + // retrieve parent pid + //$ppid = $status['pid']; + // use ps to get all the children of this process + $pids = preg_split('/\s+/', 'ps -o pid --no-heading --ppid '.$status['pid']); + // kill remaining processes + foreach ($pids as $pid) { + if (is_numeric($pid)) { + posix_kill($pid, 9); + } } } proc_close($process); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..96bbc10 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3.8" + +services: + nginx: + image: hybula/lookingglass-nginx:1 + build: + context: docker/nginx + dockerfile: Dockerfile + ports: + - "80:80" + restart: unless-stopped + + php-fpm: + image: hybula/lookingglass-php:1 + build: + context: . + dockerfile: docker/php-fpm/Dockerfile + restart: unless-stopped \ No newline at end of file diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..e06e03e --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:mainline-alpine + +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/docker/nginx/Dockerfile.dockerignore b/docker/nginx/Dockerfile.dockerignore new file mode 100644 index 0000000..0595005 --- /dev/null +++ b/docker/nginx/Dockerfile.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +Dockerfile.dockerignore \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 0000000..660563d --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,49 @@ +user nginx; +worker_processes 1; + +error_log /dev/stderr warn; +pid /run/nginx.pid; + +events { + worker_connections 1024; + multi_accept on; + use epoll; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /dev/stdout combined; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + client_max_body_size 100m; + server_tokens off; + gzip on; + open_file_cache max=100; + + server { + listen 80 default_server; + listen [::]:80 default_server; + server_name _; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + root /var/www/html; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass php-fpm:9000; + fastcgi_index index.php; + include fastcgi.conf; + fastcgi_buffering on; + fastcgi_buffer_size 1k; + fastcgi_buffers 128 1k; + fastcgi_max_temp_file_size 0; + gzip off; + } + } +} \ No newline at end of file diff --git a/docker/php-fpm/Dockerfile b/docker/php-fpm/Dockerfile new file mode 100644 index 0000000..e24d62f --- /dev/null +++ b/docker/php-fpm/Dockerfile @@ -0,0 +1,8 @@ +FROM php:8.1-fpm-bullseye + +RUN apt update && apt install iputils-ping mtr traceroute -y + +WORKDIR /var/www/html + +COPY . . +COPY docker/php-fpm/src/config.php config.php diff --git a/docker/php-fpm/Dockerfile.dockerignore b/docker/php-fpm/Dockerfile.dockerignore new file mode 100644 index 0000000..1037ac9 --- /dev/null +++ b/docker/php-fpm/Dockerfile.dockerignore @@ -0,0 +1,3 @@ +Dockerfile +Dockerfile.dockerignore +.git \ No newline at end of file diff --git a/index.php b/index.php index c75b4cd..6999eef 100644 --- a/index.php +++ b/index.php @@ -24,9 +24,9 @@ $detectIpAddress = LookingGlass::detectIpAddress(); if (!empty($_POST)) { do { - if (!isset($_POST['csrfToken']) || ($_POST['csrfToken'] != $_SESSION['CSRF'])) { + if (!isset($_POST['csrfToken']) || !isset($_SESSION['CSRF']) || ($_POST['csrfToken'] != $_SESSION['CSRF'])) { $errorMessage = 'Missing or incorrect CSRF token.'; - break; + break; } if (isset($_POST['submitForm'])) { if (!in_array($_POST['backendMethod'], LG_METHODS)) {