Skip to content

Commit

Permalink
Merge pull request #56 from HaschekSolutions/htmx
Browse files Browse the repository at this point in the history
Big overhaul of web and API. Breaking old API
  • Loading branch information
geek-at authored Nov 11, 2023
2 parents 2cc5156 + 75e4684 commit 492c641
Show file tree
Hide file tree
Showing 32 changed files with 719 additions and 7,830 deletions.
34 changes: 28 additions & 6 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches: [ master ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')

jobs:
Expand All @@ -20,7 +19,8 @@ jobs:
- name: Prepare
id: prep
run: |
DOCKER_IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
DOCKER_IMAGE="ghcr.io/${{ env.IMAGE_NAME }}"
DOCKER_IMAGE_HUB="docker.io/${{ env.IMAGE_NAME }}"
VERSION=latest
SHORTREF=${GITHUB_SHA::8}
Expand All @@ -29,18 +29,23 @@ jobs:
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}"
TAGS_HUB="${DOCKER_IMAGE_HUB}:${VERSION},${DOCKER_IMAGE_HUB}:${SHORTREF}"
# If the VERSION looks like a version number, assume that
# this is the most recent version of the image and also
# tag it 'latest'.
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
TAGS_HUB="$TAGS_HUB,${DOCKER_IMAGE_HUB}:latest"
fi
# Set output parameters.
echo ::set-output name=tags::${TAGS}
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=tags_hub::${TAGS_HUB}
echo ::set-output name=docker_image_hub::${DOCKER_IMAGE_HUB}
- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
Expand All @@ -50,19 +55,36 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@master

- name: Log in to the Container registry
- name: Log in to Github Packages
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push to GHCR
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.prep.outputs.tags }}

- name: Build and push to Docker Hub
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.prep.outputs.tags }}
tags: ${{ steps.prep.outputs.tags_hub }}
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
![](https://img.shields.io/badge/php-7.1%2B-brightgreen.svg)
![](https://img.shields.io/badge/python-2.7%2B-brightgreen.svg)
[![](https://img.shields.io/docker/pulls/hascheksolutions/opentrashmail?color=brightgreen)](https://hub.docker.com/r/hascheksolutions/opentrashmail)
[![](https://img.shields.io/docker/cloud/build/hascheksolutions/opentrashmail?color=brightgreen)](https://hub.docker.com/r/hascheksolutions/opentrashmail/builds)
[![](https://github.com/hascheksolutions/opentrashmail/actions/workflows/build-docker.yml/badge.svg?color=brightgreen)](https://github.com/HaschekSolutions/opentrashmail/actions)
[![Apache License](https://img.shields.io/badge/license-Apache-blue.svg?style=flat)](https://github.com/HaschekSolutions/opentrashmail/blob/master/LICENSE)
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FHaschekSolutions%2Fopentrashmail&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
[![](https://img.shields.io/github/stars/HaschekSolutions/opentrashmail.svg?label=Stars&style=social)](https://github.com/HaschekSolutions/opentrashmail)
Expand All @@ -22,24 +22,31 @@
</div>


![Screenshot of Open Trashmail](https://pictshare.net/shz4tq.png)
![Screenshot of Open Trashmail](https://pictshare.net/9tim7k.png)

# Features
- Python-powered mail server that works out of the box for any domain you throw at it
- API for integrating it in your own projects. Can be used to give users individual email addresses and read what they send to it
- RSS feed for every email address
- JSON API for integrating it in your own projects. Can be used to automate 2fa emails
- Handles attachments
- Web interface to manage emails
- Generates random email addresses
- 100% file based, no database needed
- Can be used as Email Honeypot

# JSON API

| Endpoint | Explanation | Example output |
|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| /json/`[email-address]` | Returns an array of received emails with links to the attachments and the parsed text based body of the email. If `ADMIN` email is entered, will return all emails of all accounts | [![](https://pictshare.net/100x100/sflw6t.png)](https://pictshare.net/sflw6t.png) |
| /json/`[email-address]/[id]` | To see all the data of a received email, take the ID from the previous call and poll this to get the raw and HTML body of the email. Can be huge since the body can contain all attachments in base64 | [![](https://pictshare.net/100x100/eltku4.png)](https://pictshare.net/eltku4.png) |
| /json/listaccounts | If `SHOW_ACCOUNT_LIST` is set to true in the config.ini, this endpoint will return an array of all email addresses which have received at least one email | [![](https://pictshare.net/100x100/u6agji.png)](https://pictshare.net/u6agji.png) |

## [INFO] March '23
Since Docker Hub won't allow team Organizations anymore, we moved our images to GitHub Container Registry. So if you want to use the latest version, please use the new image ghcr.io/hascheksolutions/opentrashmail instead of hascheksolutions/opentrashmail

# Configuration
Just edit the `config.ini` You can use the following settings

- `URL` -> The url under which the GUI will be hosted. No tailing slash! example: https://trashmail.mydomain.eu
- `DOMAINS` -> Comma separated list of domains this mail server will be receiving emails on. It's just so the web interface can generate random addresses
- `MAILPORT`-> The port the Python-powered SMTP server will listen on. `Default: 25`
- `ADMIN` -> An email address (doesn't have to exist, just has to be valid) that will list all emails of all addresses the server has received. Kind of a catch-all
Expand All @@ -60,9 +67,9 @@ Just edit the `config.ini` You can use the following settings
- [x] Admin overview for all available email addresses
- [x] Option to show raw email
- [x] Delete messages
- [ ] Secure HTML, so no malicious things can be loaded
- [x] Make better theme
- [x] Secure HTML, so no malicious things can be loaded
- [ ] Display embedded images inline using Content-ID
- [ ] Make better theme
- [ ] Configurable settings
- [x] Choose domains for random generation
- [x] Choose if out-of-scope emails are discarded
Expand Down
17 changes: 2 additions & 15 deletions docker/rootfs/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@ server {
set $base /var/www/opentrashmail;
root /var/www/opentrashmail/web/;

index index.html;
index index.php;

client_max_body_size 10M;

location / {
try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php;
}

location /rss {
index rss.php;
if (!-e $request_filename){
rewrite ^(.*)$ /rss.php?url=$1 last;
}
}

location /api {
index api.php;
if (!-e $request_filename){
rewrite ^(.*)$ /api.php?url=$1 last;
}
}

# logging
access_log /var/log/nginx/opentrashmail/web.access.log;
Expand Down
7 changes: 7 additions & 0 deletions docker/rootfs/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ 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"
Expand Down
19 changes: 19 additions & 0 deletions docs/Dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Quick testing

From the main directory run

```bash
docker build -f docker/Dockerfile -t opentrashmail . && docker run --rm -it --name trashmail -p 3000:80 -p 2525:25 opentrashmail
```

And check if it works on http://localhost:3000

## Sending debug emails from the command line

Using the text file `tools/testmail.txt` and the following line of bash you can send emails to your python mailserver and test if it's acceping emails like you want.

Note that if you change cour config.ini, the mail server needs to be restarted before it takes effect.

```bash
cat "tools/testmail.txt" | while read L; do sleep "0.2"; echo "$L"; done | "nc" -C -v "localhost" "2525"
```
9 changes: 0 additions & 9 deletions docs/Docker.md

This file was deleted.

4 changes: 4 additions & 0 deletions example.config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
; pro tip: Use a wildcard domain like *.yourdomain.com to auto-generate the subdomains (you'll need to add a wildcard dns record too)
DOMAINS=yourdomain,sub.yourdomain,*.mydom.com

; This variable needs to be set in order for RSS to work
; The URL of your webserver hosting the GUI. No trailing slash
URL="http://localhost:8080"

; Enable to show a list of all existing accounts with mail
;SHOW_ACCOUNT_LIST=true

Expand Down
2 changes: 2 additions & 0 deletions python/mailserver.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def process_message(self, peer, mailfrom, rcpttos, data):
DELETE_OLDER_THAN_DAYS = (Config.get("CLEANUP","DELETE_OLDER_THAN_DAYS").lower() == "true")

print "[i] Starting Mailserver on port",port
print "[i] Discard unknown domains:",DISCARD_UNKNOWN
print "[i] Listening for domains:",DOMAINS

server = CustomSMTPServer(('0.0.0.0', port), None) # use your public IP here
print "[i] Ready to receive Emails"
Expand Down
14 changes: 14 additions & 0 deletions tools/testmail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HELO localhost
MAIL FROM:<system@example.com>
RCPT TO:<random.user@rand.domain.tld>
DATA
Subject: Test Message

Hi there! This is supposed to be an email...

Have a good day!
-- System


.
QUIT
Loading

0 comments on commit 492c641

Please sign in to comment.