Skip to content
Snippets Groups Projects
Commit e69d3d5a authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Expand Readme

parent 37d5176d
Branches
No related tags found
No related merge requests found
# static_contact
static_contact is a server side tool that relays http POST requests with form fields like name, email, phone and message to email targets via SMTP.
This is meant to be a simple self-hosted solution for contact forms on static websites. You add a form and a little bit of javascript to a static website, it POSTs the message to a different server, does a few checks and sends it to an target adress via email. It is possible to connect multiple static websites to one single instance of the service. The most complicated thing is to get the [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) authentification right – just check the Examples.
static_contact is a Rust based server side service that relays http POST requests with form fields like name, email, phone and message to email targets via SMTP.
This is meant to be a simple self-hosted solution to allow contact forms on static websites. You add a form and a little bit of [javascript](###Javascript) to a [static website](###HTML), it POSTs the message to a different server, where it is sanitzed and HTML escaped, a few checks are made (e.g. validity of the email) and sends it to an target adress via email. It is possible to connect multiple websites to a single instance of the service and relay them to different target websites. The most complicated thing is to get the [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) authentification right – just check the Examples.
## Installation
static_contact runs as a systemd-service on a local port. Although it would be possible to expose this directly to the web, it is recommended to run this service behind a a reverse proxy server (like nginx).
......@@ -24,12 +24,12 @@ sudo vim /etc/static_contact/config.toml
Pay special attention to the SMTP configuration, it should reflect the values of your SMTP server.
## System Operation
Start the service via `sudo systemctl start static_contact`
Check the service status via `sudo systemctl status static_contact`
Check the logs via `journalctl -u static_contact`
Stop the service via `sudo systemctl stop static_contact`
Automatically start the service on boot via `sudo systemctl enable static_contact`
Update by running this in the downloaded repository: `git pull && cargo build --release && cargo deb && sudo dpkg -r static_contact && sudo dpkg -i target/debian/*.deb && sudo systemctl daemon-reload && sudo systemctl restart static_contact`
- Start the service via `sudo systemctl start static_contact`
- Check the service status via `sudo systemctl status static_contact`
- Check the logs via `journalctl -u static_contact`
- Stop the service via `sudo systemctl stop static_contact`
- Automatically start the service on boot via `sudo systemctl enable static_contact`
- Update by running this in the local repository: `git pull && cargo build --release && cargo deb && sudo dpkg -r static_contact && sudo dpkg -i target/debian/*.deb && sudo systemctl daemon-reload && sudo systemctl restart static_contact`
## Example Nginx Configuration
Note that this used Certbot to generate Let's Encrypt certificates, these are ommited for previty. Replace `post.example.com` with the Domain (or IP+port) your service runs under:
......@@ -47,7 +47,7 @@ server {
# listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
# Certs here omited for previty
# Certs here omited for
location / {
proxy_set_header Host $host;
......@@ -58,6 +58,7 @@ server {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Make sure this fits the port configured in your /etc/static_contact/config.toml
proxy_redirect http://127.0.0.1:8088/ /;
proxy_pass http://127.0.0.1:8088;
proxy_read_timeout 86400s;
......@@ -95,7 +96,7 @@ Replace the identifier value `mysitename` with the corresponding identifier set
<label id="messagelabel">Message *</label>
<textarea id="message" name="message" placeholder="Your message to us"></textarea>
<button id="submit" class="submit" type="submit" name="identifier" value="mysitename">Send</button>
<button id="submit" class="submit" type="submit" name="identifier" value="mysiteidentifier">Send</button>
</form>
<script src="js/submit.js"></script>
......@@ -134,4 +135,9 @@ You can send a test request to static_contact via curl, replace the adress at th
curl --header "Content-Type: application/json" --request POST --data '{"name":"Mr. Foo Bar", "email":"mrfoo@bar.com", "phone":"+49012345678", "message":"Media is the massage", "identifier":"mysiteidentifier"}' http://localhost:8088
```
This emulates a user with the name "Mr. Foo Bar", the email "mrfoo@bar.com" and the phone number "+49012345678" writing a message with the content "Media is the massage". Note the field `"identifier":"mysitename"` – this identifies the site against the server. If there is no endpoint with the identifier "mysiteidentifier" in the `config.toml`, the request is ignored. This message is checked for type and length, and will be sent via SMTP to the according `endpoint.target` email adress specified in the config.
\ No newline at end of file
This emulates a user with the name "Mr. Foo Bar", the email "mrfoo@bar.com" and the phone number "+49012345678" writing a message with the content "Media is the massage". Note the field `"identifier":"mysiteidentifier"` – this identifies the site against the server. If there is no endpoint with the identifier "mysiteidentifier" in the `config.toml`, the request is ignored. This message is checked for type and length, and will be sent via SMTP to the according `endpoint.target` email adress specified in the config.
## Todo
- [ ] Currently fields are fixed, allow for custom Forms per endpoint
- [ ] Make installation easier
- [ ] Implement SMTP settings like port and encryption types
\ No newline at end of file
......@@ -13,7 +13,7 @@ smtp_password = "yoursecretpassword" # Password for the SMTP server
[[endpoints]]
# Identifier to be sent via POST
identifier = "project_foo_9f1098f3c333"
identifier = "mysiteidentifier"
# The name gets displayed in the mail subject:
# [project foo] Contact from Mister X
name = "project foo"
......@@ -29,7 +29,7 @@ email_name = "John Doe (Project Foo Leader)" # Using this name
# Another Endpoint with a different target:
[[endpoints]]
identifier = "project_bar_6231dc2f8f03"
identifier = "mysecondsiteidentifier"
name = "project bar"
max_name_length = 254
max_message_length = 2000
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment