Skip to content

Commit

Permalink
added docker-compose example files and updated scripts to include log…
Browse files Browse the repository at this point in the history
…s in the GUI
  • Loading branch information
geek-at committed Nov 18, 2023
1 parent 90f7bcb commit e7d3754
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 48 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 23 additions & 47 deletions docker/rootfs/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/ash
#!/bin/bash

echo 'Starting Open Trashmail'

Expand All @@ -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'

Expand All @@ -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

if [ "$ADMIN" != "" ]; then
echo "ADMIN=$ADMIN" >> /var/www/opentrashmail/config.ini
echo " [i] Set admin to: $ADMIN"
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}"

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 "[MAILSERVER]"
echo "MAILPORT=${MAILPORT:-25}"
echo "DISCARD_UNKNOWN=${DISCARD_UNKNOWN:-true}"

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 "[DATETIME]"
echo "DATEFORMAT='${DATEFORMAT:-D.M.YYYY HH:mm}'"

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
echo "[CLEANUP]"
echo "DELETE_OLDER_THAN_DAYS=${DELETE_OLDER_THAN_DAYS:-false}"
}

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 '
7 changes: 7 additions & 0 deletions example.config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
Empty file modified logs/.gitignore
100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions web/inc/OpenTrashmailBackend.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function run(){
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;
}
Expand Down
6 changes: 6 additions & 0 deletions web/inc/core.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions web/templates/index.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
27 changes: 27 additions & 0 deletions web/templates/logs.html.php
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit e7d3754

Please sign in to comment.