Inital commit
This commit is contained in:
commit
6df8bfba35
|
@ -0,0 +1 @@
|
|||
.env
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os, sys, cgitb
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Log errors to disk only
|
||||
cgitb.enable(display=0, logdir="/var/log/gemini", format="plain")
|
||||
|
||||
# Load config
|
||||
load_dotenv()
|
||||
msg_file = os.getenv("MESSSAGE_FILE")
|
||||
admin_fp = os.getenv("ADMIN_CERT")
|
||||
|
||||
# Load CGI vars
|
||||
cert_fp = os.getenv("TLS_CLIENT_HASH")
|
||||
action = os.getenv("QUERY_STRING")
|
||||
|
||||
if None == cert_fp :
|
||||
# Prompt for client cert
|
||||
print("60 Admin only\r")
|
||||
sys.exit()
|
||||
|
||||
if admin_fp != cert_fp :
|
||||
# Incorrect cert
|
||||
print("61 Admin only\r")
|
||||
sys.exit()
|
||||
|
||||
print("20 text/gemini; lang=en-GB\r")
|
||||
|
||||
if "del" == action :
|
||||
f = open("/home/mark/gemini-msg", "w")
|
||||
f.write("")
|
||||
|
||||
print("# Messages Deleted")
|
||||
|
||||
else :
|
||||
f = open("/home/mark/gemini-msg", "r")
|
||||
|
||||
print("# Recieved Messages\n")
|
||||
|
||||
print( f.read() )
|
||||
f.close()
|
||||
|
||||
print("=>.. Back")
|
||||
print("=>read.cgi?del Delete")
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os, urllib, cgitb, dns.resolver
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Log errors to disk only
|
||||
cgitb.enable(display=0, logdir="/var/log/gemini", format="plain")
|
||||
|
||||
# Load config
|
||||
load_dotenv()
|
||||
msg_file = os.getenv("MESSAGE_FILE")
|
||||
|
||||
# Load CGI vars
|
||||
msg = os.getenv("QUERY_STRING")
|
||||
ip = os.getenv("REMOTE_ADDR")
|
||||
name = os.getenv("REMOTE_USER")
|
||||
|
||||
if msg == "":
|
||||
# Prompt for message
|
||||
print("10 Leave a Message\r")
|
||||
else:
|
||||
# Default name if no client cert provided
|
||||
name = name or "Anonymous"
|
||||
|
||||
try:
|
||||
# Look up client RDNS
|
||||
host = str( dns.resolver.resolve_address( ip )[0] )
|
||||
except dns.resolver.NXDOMAIN as e:
|
||||
# No RDNS set, use IP
|
||||
host = ip
|
||||
|
||||
# Message template
|
||||
fromLine = "## Message from " + name + " (" + host + ")\n"
|
||||
msgLine = urllib.parse.unquote(msg) + "\n"
|
||||
|
||||
# Save message to file
|
||||
f = open(msg_file, "a")
|
||||
f.write( fromLine + msgLine )
|
||||
|
||||
# Generate confirmation screen
|
||||
print("20 text/gemini; lang=en-GB\r")
|
||||
print("# Message Sent\n")
|
||||
print( msgLine )
|
||||
print("=> / Back")
|
Loading…
Reference in New Issue