summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--web/.gitignore2
-rw-r--r--web/html/form.html54
-rw-r--r--web/html/send.html48
-rw-r--r--web/index.html5
-rwxr-xr-xweb/mail-form.py74
5 files changed, 183 insertions, 0 deletions
diff --git a/web/.gitignore b/web/.gitignore
new file mode 100644
index 0000000..8609a37
--- /dev/null
+++ b/web/.gitignore
@@ -0,0 +1,2 @@
+*.log
+*.db
diff --git a/web/html/form.html b/web/html/form.html
new file mode 100644
index 0000000..75350eb
--- /dev/null
+++ b/web/html/form.html
@@ -0,0 +1,54 @@
+<html>
+ <head>
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />
+ <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
+
+ <title>Mail Form</title>
+ </head>
+
+ <body>
+ <div class="container">
+ <div style="margin-top: 2rem"></div>
+
+ <h1>Mail Form</h1>
+
+ <hr />
+
+ <form action="mail-form.py" method="post">
+ <div class="form-row">
+ <div class="col">
+ <input type="text" name="name" class="form-control" placeholder="Name">
+
+ </div>
+
+ <div class="col">
+ <input type="email" name="email" class="form-control" placeholder="Email">
+ </div>
+ </div>
+
+ <div style="margin-top: 1rem"></div>
+
+ <div class="form-group">
+ <input type="text" name="subject" class="form-control" placeholder="Subject">
+ </div>
+
+ <div class="form-group">
+ <textarea name="message" class="form-control" rows="10" placeholder="Your message..."></textarea>
+ </div>
+
+ <div style="margin-top: 1rem"></div>
+
+ <button type="submit" class="btn btn-success">Send</button>
+ </form>
+
+ <hr />
+
+ <footer>
+ <p><a class="text-muted" href="mailto:software@lists.open-infrastructure.net?subject=mail-form:%20Bug%20Report"><i class="fa fa-fw fa-bug" style="color: black;"></i> Report a Bug</a> <a class="text-muted pull-right" href="https://sources.open-infrastructure.net/software/mail-form"><i class="fa fa-fw fa-heart" style="color: #cc0000;"></i> Source Code</a></p>
+ </footer>
+ </div>
+
+ <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
+ </body>
+</html>
diff --git a/web/html/send.html b/web/html/send.html
new file mode 100644
index 0000000..765ddaa
--- /dev/null
+++ b/web/html/send.html
@@ -0,0 +1,48 @@
+<html>
+ <head>
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />
+ <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
+
+ <title>Mail Form</title>
+ </head>
+
+ <body>
+ <div class="container">
+ <div style="margin-top: 2rem"></div>
+
+ <h1>Mail Form</h1>
+
+ <hr />
+
+ <div class="card">
+ <div class="card-header">
+ Message send, thank you.
+ </div>
+
+ <div class="card-body">
+ <p class="card-text">
+ <b>Name:</b> {Name}<br />
+ <b>Email:</b> {Email}<br />
+ <br />
+ <b>Subject:</b> {Subject}<br />
+ <br />
+ <b>Message:</b><br />
+ <br />
+ {Message}<br />
+ <br />
+ <small>-- Send: {Date}</small>
+ </p>
+ </div>
+ </div>
+
+ <hr />
+
+ <footer>
+ <p><a class="text-muted" href="mailto:software@lists.open-infrastructure.net?subject=mail-form:%20Bug%20Report"><i class="fa fa-fw fa-bug" style="color: black;"></i> Report a Bug</a> <a class="text-muted pull-right" href="https://sources.open-infrastructure.net/software/mail-form"><i class="fa fa-fw fa-heart" style="color: #cc0000;"></i> Source Code</a></p>
+ </footer>
+ </div>
+
+ <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
+ </body>
+</html>
diff --git a/web/index.html b/web/index.html
new file mode 100644
index 0000000..c7d34d3
--- /dev/null
+++ b/web/index.html
@@ -0,0 +1,5 @@
+<html>
+
+<a href="mail-form.py">mail-form.py</a>
+
+</html>
diff --git a/web/mail-form.py b/web/mail-form.py
new file mode 100755
index 0000000..b669fad
--- /dev/null
+++ b/web/mail-form.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+
+from cgi import FieldStorage
+from datetime import datetime
+from sys import exit
+
+import smtplib
+from email.message import EmailMessage
+
+# Static settings
+From = 'mail-form@example.net'
+To = 'user@example.net'
+Prefix = 'mail-form'
+
+def print_html(html_file):
+ with open(html_file, 'r') as file:
+ html = file.read()
+
+ # FIXME
+ if form.getvalue('message'):
+ Name = form.getvalue('name')
+ Email = form.getvalue('email')
+ Subject = form.getvalue('subject')
+ Message = str(form.getvalue('message')).replace('\n', '<br />')
+ Date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+
+ print('Content-Type: text/html\n\n')
+ print(html.format(**locals()))
+
+if __name__ == '__main__':
+ form = FieldStorage()
+
+ # Send mail
+ if form.getvalue('message'):
+ Name = form.getvalue('name')
+ Email = form.getvalue('email')
+ Subject = form.getvalue('subject')
+ Message = form.getvalue('message')
+
+ Date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+
+ email = EmailMessage()
+
+ email['From'] = From
+ email['To'] = To
+ email['Subject'] = Prefix + ': ' + Subject
+
+ email.set_content(
+ 'Name: ' + Name + '\n' +
+ 'Email: ' + Email + '\n' +
+ '\n' +
+ 'Subject: ' + Subject + '\n' +
+ '\n' +
+ 'Message:\n' +
+ '\n' +
+ Message + '\n' +
+ '\n' +
+ '--\n' +
+ 'Send: ' + Date + '\n')
+
+ s = smtplib.SMTP('localhost')
+ s.send_message(email)
+ s.quit()
+
+ with open('mail-form.log', 'a') as file:
+ file.write(Date + ' ' + Name + ' <' + Email + '>\n')
+
+ print_html('html/send.html')
+
+ exit()
+
+ # Show html form
+ print_html('html/form.html')
+ exit()