added docker-compose example files and updated scripts to include logs in the GUI

This commit is contained in:
Chris 2023-11-18 10:16:59 +01:00
parent 90f7bcb1fd
commit e7d37545f3
11 changed files with 115 additions and 48 deletions

View File

@ -76,6 +76,7 @@ In Docker you can use the following environment variables:
| SHOW_ACCOUNT_LIST | If set to `true`, all accounts that have previously received emails can be listed via API or webinterface | true,false |
| ADMIN | If set to a valid email address and this address is entered in the API or webinterface, will show all emails of all accounts. Kind-of catch-all | test@test.com
| DATEFORMAT | Will format the received date in the web interface based on [moment.js](https://momentjs.com/) syntax | "MMMM Do YYYY, h:mm:ss a" |
| SKIP_FILEPERMISSIONS | If set to `true`, won't fix file permissions for the code data folder in the container. Useful for local dev. Default `false` | true,false |
# Roadmap

22
docker-compose-dev.yml Normal file
View File

@ -0,0 +1,22 @@
version: '3.9'
services:
opentrashmail:
build:
context: .
dockerfile: docker/Dockerfile
volumes:
- './data:/var/www/opentrashmail/data'
- './logs:/var/www/opentrashmail/logs'
environment:
- URL=http://localhost:8080
- DOMAINS=example.com
- DATEFORMAT=D.M.YYYY HH:mm
- SKIP_FILEPERMISSIONS=true
- DISCARD_UNKNOWN=false
- SHOW_ACCOUNT_LIST=true
- SHOW_LOGS=true
ports:
- '2525:25'
- '8080:80'

17
docker-compose.yml Normal file
View File

@ -0,0 +1,17 @@
version: '3.9'
services:
opentrashmail:
image: 'hascheksolutions/opentrashmail:1'
volumes:
- './data:/var/www/opentrashmail/data'
- './logs:/var/www/opentrashmail/logs'
environment:
- URL=http://localhost:8080
- DOMAINS=example.com
- DATEFORMAT=D.M.YYYY HH:mm
- SKIP_FILEPERMISSIONS=true
- DISCARD_UNKNOWN=false
ports:
- '2525:25'
- '8080:80'

View File

@ -2,7 +2,7 @@ FROM alpine:3.14.2
LABEL org.opencontainers.image.source = "https://github.com/HaschekSolutions/opentrashmail"
RUN apk add --no-cache python2 socat wget php7-fileinfo php7-session curl git php php-curl nginx php-openssl php-mbstring php-json php-gd php-dom php-fpm
RUN apk add --no-cache bash python2 socat wget php7-fileinfo php7-session curl git php php-curl nginx php-openssl php-mbstring php-json php-gd php-dom php-fpm
#RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
RUN mkdir -p /var/www/opentrashmail
WORKDIR /var/www/opentrashmail

View File

@ -1,4 +1,4 @@
#!/bin/ash
#!/bin/bash
echo 'Starting Open Trashmail'
@ -7,7 +7,11 @@ cd /var/www/opentrashmail
echo ' [+] Starting php'
php-fpm7
chown -R nginx:nginx /var/www/
if [[ ${SKIP_FILEPERMISSIONS:=false} != true ]]; then
chown -R nginx:nginx /var/www/
chown -R nginx:nginx /var/www/opentrashmail/data
fi
echo ' [+] Starting nginx'
@ -20,56 +24,28 @@ nginx
echo ' [+] Setting up config.ini'
echo "[GENERAL]" > /var/www/opentrashmail/config.ini
if [ "$DOMAINS" != "" ]; then
echo "DOMAINS=$DOMAINS" >> /var/www/opentrashmail/config.ini
echo " [i] Active Domain(s): $DOMAINS"
else
echo "DOMAINS=localhost" >> /var/www/opentrashmail/config.ini
fi
if [ "$URL" != "" ]; then
echo "URL=$URL" >> /var/www/opentrashmail/config.ini
echo " [i] URL of GUI is set to: $URL"
else
echo "URL=http://localhost:8080" >> /var/www/opentrashmail/config.ini
fi
if [ "$SHOW_ACCOUNT_LIST" != "" ]; then
echo "SHOW_ACCOUNT_LIST=$SHOW_ACCOUNT_LIST" >> /var/www/opentrashmail/config.ini
echo " [i] Set show account list to: $SHOW_ACCOUNT_LIST"
fi
_buildConfig() {
echo "[GENERAL]"
echo "DOMAINS=${DOMAINS:-localhost}"
echo "URL='${URL:-http://localhost:8080}'"
echo "SHOW_ACCOUNT_LIST=${SHOW_ACCOUNT_LIST:-false}"
echo "ADMIN=${ADMIN:-}"
echo "SHOW_LOGS=${SHOW_LOGS:-false}"
if [ "$ADMIN" != "" ]; then
echo "ADMIN=$ADMIN" >> /var/www/opentrashmail/config.ini
echo " [i] Set admin to: $ADMIN"
fi
echo "[MAILSERVER]"
echo "MAILPORT=${MAILPORT:-25}"
echo "DISCARD_UNKNOWN=${DISCARD_UNKNOWN:-true}"
echo "[MAILSERVER]" >> /var/www/opentrashmail/config.ini
echo "MAILPORT=25" >> /var/www/opentrashmail/config.ini
if [ "$DISCARD_UNKNOWN" != "" ]; then
echo "DISCARD_UNKNOWN=$DISCARD_UNKNOWN" >> /var/www/opentrashmail/config.ini
echo " [i] Setting up DISCARD_UNKNOWN to: $DISCARD_UNKNOWN"
else
echo "DISCARD_UNKNOWN=false" >> /var/www/opentrashmail/config.ini
fi
echo "[DATETIME]"
echo "DATEFORMAT='${DATEFORMAT:-D.M.YYYY HH:mm}'"
echo "[DATETIME]" >> /var/www/opentrashmail/config.ini
if [ "$DATEFORMAT" != "" ]; then
echo "DATEFORMAT=$DATEFORMAT" >> /var/www/opentrashmail/config.ini
echo " [i] Setting up dateformat to: $DATEFORMAT"
else
echo "DATEFORMAT='D.M.YYYY HH:mm'" >> /var/www/opentrashmail/config.ini
echo " [i] Using default dateformat"
fi
echo "[CLEANUP]"
echo "DELETE_OLDER_THAN_DAYS=${DELETE_OLDER_THAN_DAYS:-false}"
}
echo "[CLEANUP]" >> /var/www/opentrashmail/config.ini
if [ "$DELETE_OLDER_THAN_DAYS" != "" ]; then
echo "DELETE_OLDER_THAN_DAYS=$DELETE_OLDER_THAN_DAYS" >> /var/www/opentrashmail/config.ini
echo " [i] Setting up cleanup time to $DELETE_OLDER_THAN_DAYS days"
fi
chown -R nginx:nginx /var/www/opentrashmail/data
_buildConfig > /var/www/opentrashmail/config.ini
echo ' [+] Starting Mailserver'
su - nginx -s /bin/ash -c 'cd /var/www/opentrashmail/python;python mailserver.py > /var/www/opentrashmail/logs/mailserver.log 2>&1 '
su - nginx -s /bin/ash -c 'cd /var/www/opentrashmail/python;python -u mailserver.py > /var/www/opentrashmail/logs/mailserver.log 2>&1 '

View File

@ -16,6 +16,9 @@ URL="http://localhost:8080"
; The email doesn't really have to exist or have mail but must look like an email address
;ADMIN=some@random.email
; Enable to show logs on the website
;SHOW_LOGS=false
[MAILSERVER]
; Port that the Mailserver will run on (default 25 but that needs root)
MAILPORT=25
@ -36,6 +39,10 @@ DATEFORMAT="D.M.YYYY HH:mm"
DELETE_OLDER_THAN_DAYS=false
; NOT IMPLEMENTED YET
; NOT IMPLEMENTED YET
; NOT IMPLEMENTED YET
; These settings are related to the forwarding service of incoming emails to
; a single or multiple email addresses
[FORWARDING]

0
logs/.gitignore vendored Normal file → Executable file
View File

View File

@ -35,6 +35,16 @@ class OpenTrashmailBackend{
return $this->listAccount($addr);
case 'deleteaccount':
return $this->deleteAccount($_REQUEST['email']?:$this->url[2]);
case 'logs':
if($this->settings['SHOW_LOGS'])
return $this->renderTemplate('logs.html',[
'lines' => (is_numeric($this->url[2])&&$this->url[2]>0)?$this->url[2]:100,
'mailserverlogfile'=>ROOT.DS.'../logs'.DS.'mailserver.log',
'webservererrorlogfile'=>ROOT.DS.'../logs'.DS.'web.error.log',
'webserveraccesslogfile'=>ROOT.DS.'../logs'.DS.'web.access.log',
'configfile' => ROOT.DS.'../config.ini',
]);
else return '403 Forbidden';
default:
return false;
}

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,7 @@
<li><input id="email" hx-post="/api/address" hx-target="#main" name="email" type="email" hx-trigger="input changed delay:500ms" placeholder="email address" aria-label="email address"></li>
<li><button hx-get="/api/random" hx-target="#main"><i class="fas fa-random"></i> Generate random</button></li>
<?php if($settings['SHOW_ACCOUNT_LIST']): ?><li><button hx-get="/api/listaccounts" hx-target="#main" hx-push-url="/listaccounts"><i class="fas fa-list"></i> List accounts</button></li><?php endif; ?>
<?php if($settings['SHOW_LOGS']==true): ?><li><button hx-get="/api/logs" hx-target="#main" hx-push-url="/logs"><i class="fas fa-list"></i> Show logs</button></li><?php endif; ?>
</ul>
</nav>
</div>

View File

@ -0,0 +1,27 @@
<a href="#" hx-push-url="/logs/10" hx-get="/api/logs/10" <?= $lines==10?'disabled':'' ?> hx-target="#main" role="button">Last 10 lines</a>
<a href="#" hx-push-url="/logs/50" hx-get="/api/logs/50" <?= $lines==50?'disabled':'' ?> hx-target="#main" role="button">Last 50 lines</a>
<a href="#" hx-push-url="/logs/100" hx-get="/api/logs/100" <?= $lines==100?'disabled':'' ?> hx-target="#main" role="button">Last 100 lines</a>
<a href="#" hx-push-url="/logs/200" hx-get="/api/logs/200" <?= $lines==200?'disabled':'' ?> hx-target="#main" role="button">Last 200 lines</a>
<a href="#" hx-push-url="/logs/500" hx-get="/api/logs/500" <?= $lines==500?'disabled':'' ?> hx-target="#main" role="button">Last 500 lines</a>
<hr>
<h2>Mailserver log</h2>
<div>
<pre><code><?= file_exists($mailserverlogfile)?tailShell($mailserverlogfile, $lines):'- Mailserver log file not found -' ?></code><pre>
</div>
<h2>Webserver error log</h2>
<div>
<pre><code><?= file_exists($webservererrorlogfile)?tailShell($webservererrorlogfile, $lines):'- Webserver error log file not found -' ?></code><pre>
</div>
<h2>Webserver access log</h2>
<div>
<pre><code><?= file_exists($webserveraccesslogfile)?tailShell($webserveraccesslogfile, $lines):'- Webserver access log file not found -' ?></code><pre>
</div>
<h2>Current config</h2>
<div>
<pre><code><?= file_exists($configfile)?file_get_contents($configfile):'- Config file not found -' ?></code><pre>
</div>