Skip to content

Commit dd9cf6b

Browse files
committed
Docker, phpfirewall on a stick
1 parent 953b702 commit dd9cf6b

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

docker/Dockerfile

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
11
#From PHP8.3-cli
2-
FROM php:8.3-cli-alpine
2+
FROM php:8.3-fpm-alpine
33

44
RUN adduser -h /home/admin -s /home/admin/vendor/bin/phpterminal -D admin
55
RUN echo -n 'admin:admin' | chpasswd
66

7-
WORKDIR /home/admin
7+
WORKDIR /home/admin/
88

99
RUN apk update
1010
RUN apk add --update --no-cache git
1111
RUN apk add --update --no-cache zip
12+
RUN apk add --update --no-cache vim
13+
RUN apk add --update --no-cache openssh
14+
RUN apk add --update --no-cache openrc
15+
RUN apk add --update --no-cache apache2
16+
RUN apk add --update --no-cache apache2-proxy
17+
RUN apk add --update --no-cache php83-apache2
18+
RUN apk add --update --no-cache shadow
19+
RUN mkdir -p /run/openrc/exclusive
20+
RUN touch /run/openrc/softlevel
21+
RUN rc-update add apache2
1222

1323
RUN docker-php-ext-configure pcntl --enable-pcntl && docker-php-ext-install pcntl
24+
RUN docker-php-ext-configure bcmath --enable-bcmath && docker-php-ext-install bcmath
25+
26+
RUN cat <<EOF > /etc/apache2/conf.d/phpfirewall.conf
27+
<VirtualHost *:80>
28+
DocumentRoot /home/admin/public/
29+
30+
ErrorLog ${APACHE_LOG_DIR}/error.log
31+
CustomLog ${APACHE_LOG_DIR}/access.log combined
32+
33+
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/home/admin/public/$1
34+
DirectoryIndex /index.php index.php
35+
36+
<Directory /home/admin/public/>
37+
Options -Indexes
38+
AllowOverride All
39+
Order allow,deny
40+
allow from all
41+
</Directory>
42+
</VirtualHost>
43+
<IfModule unixd_module>
44+
User admin
45+
Group admin
46+
</IfModule>
47+
EOF
1448

1549
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
1650
RUN php composer-setup.php
@@ -20,15 +54,20 @@ RUN chmod +x /home/admin/composer
2054
RUN /home/admin/composer require oyeaussie/phpfirewall
2155
ENV COMPOSER_ALLOW_SUPERUSER=1
2256

23-
RUN mkdir /home/admin/terminaldata
24-
25-
RUN apk add --update --no-cache openssh
2657
RUN echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
2758
RUN echo 'Port 2233' >> /etc/ssh/sshd_config
2859
ENTRYPOINT ["/entrypoint.sh"]
2960
COPY entrypoint.sh /
30-
RUN chown -R admin:admin /home/admin/
3161

62+
RUN echo 'user = admin' >> /usr/local/etc/php-fpm.d/www.conf
63+
RUN echo 'group = admin' >> /usr/local/etc/php-fpm.d/www.conf
64+
65+
RUN mkdir /home/admin/terminaldata
66+
RUN mkdir /home/admin/firewalldata
67+
RUN mkdir /home/admin/public
68+
69+
COPY index.php ./public/
70+
RUN chown -R admin:admin /home/admin
3271
# Running
3372
# docker run -d --name phpfirewall -h phpfirewall oyeaussie/phpfirewall
3473
# Grab IP

docker/entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/bin/sh
2+
php-fpm &
3+
rc-service apache2 start
24
ssh-keygen -A
35
exec /usr/sbin/sshd -D -e "$@"

docker/index.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
include '../vendor/autoload.php';
4+
5+
$response = [];
6+
7+
if (!isset($_GET['ip'])) {
8+
$response['code'] = 1;
9+
10+
$response['message'] = 'Please provide ip address in the query string.';
11+
} else {
12+
try {
13+
$firewall = new \PHPFirewall\Firewall;
14+
15+
$response['code'] = 0;
16+
17+
$response['allowed'] = $firewall->checkIp($_GET['ip']);
18+
19+
$response['details'] = $firewall->response->getAllData();
20+
21+
$response['lookup_details'] = $firewall->getProcessedMicroTimers();
22+
} catch (\throwable $e) {
23+
$response['code'] = 1;
24+
25+
$response['message'] = 'Error processing request. Please contact developer.';
26+
}
27+
}
28+
29+
echo json_encode($response);

0 commit comments

Comments
 (0)