update scripts to use Opal instead of gmnisrv
This commit is contained in:
parent
f7e82f2b41
commit
47650deb33
15
check-email
Executable file
15
check-email
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import pprint
|
||||
import subprocess
|
||||
|
||||
import smolcgi
|
||||
|
||||
if not smolcgi.query_string_dec:
|
||||
smolcgi.require_input("Provide an email address to check.")
|
||||
|
||||
smolcgi.header(20, "text/plain")
|
||||
command = ["/usr/local/bin/check_if_email_exists", smolcgi.query_string_dec]
|
||||
output = subprocess.check_output(command).decode()
|
||||
pprint.pprint(json.loads(output)[0])
|
20
lists
20
lists
|
@ -3,7 +3,7 @@
|
|||
|
||||
import smolcgi as scgi
|
||||
|
||||
if not (user_hash := scgi.cert_hash):
|
||||
if not (user_hash := scgi.tls_client_hash):
|
||||
scgi.exit_with_header(60, "You need a certificate to use this app")
|
||||
|
||||
import string
|
||||
|
@ -11,7 +11,7 @@ import subprocess
|
|||
from os import getenv
|
||||
from pathlib import Path
|
||||
|
||||
STORAGE_PATH = Path(getenv("GEMINI_LISTS_PATH", "/var/gemini/lists"))
|
||||
STORAGE_PATH = Path(getenv("GEMINI_LISTS_PATH", "/home/gemini/storage/lists"))
|
||||
if not STORAGE_PATH.exists():
|
||||
STORAGE_PATH.mkdir(parents=True)
|
||||
|
||||
|
@ -29,8 +29,8 @@ def show_lists():
|
|||
print("# Lists")
|
||||
for child in user_dir.iterdir():
|
||||
if child.is_file():
|
||||
print(f"=> ./{child.name} 📄 {child.name}")
|
||||
print("=> ./_/create ✨ Create a new list")
|
||||
print(f"=> {scgi.script_name}/{child.name} 📄 {child.name}")
|
||||
print(f"=> {scgi.script_name}/_/create ✨ Create a new list")
|
||||
|
||||
def show_list(list_name):
|
||||
list_file = get_user_dir() / list_name
|
||||
|
@ -43,8 +43,8 @@ def show_list(list_name):
|
|||
scgi.header(20, "text/gemini")
|
||||
print("# " + list_name)
|
||||
print(content)
|
||||
print(f"=> ./{list_name}/add Append item")
|
||||
print(f"=> ./{list_name}/pop Pop first item")
|
||||
print(f"=> {scgi.script_name}/{list_name}/add Append item")
|
||||
print(f"=> {scgi.script_name}/{list_name}/pop Pop first item")
|
||||
|
||||
def process_action(list_name, action):
|
||||
if list_name == "_" and action == "create":
|
||||
|
@ -57,7 +57,7 @@ def process_action(list_name, action):
|
|||
scgi.not_found()
|
||||
|
||||
def process_creation():
|
||||
if not (new_list_name := scgi.query):
|
||||
if not (new_list_name := scgi.query_string_dec):
|
||||
meta = "List name (allowed chars: lowercase, digits, underscore)"
|
||||
scgi.require_input(meta)
|
||||
else:
|
||||
|
@ -69,7 +69,7 @@ def process_creation():
|
|||
redirect_to_list(new_list_name)
|
||||
|
||||
def process_add(list_name):
|
||||
if not (item := scgi.query):
|
||||
if not (item := scgi.query_string_dec):
|
||||
scgi.require_input("Enter your item")
|
||||
else:
|
||||
if "\n" in item:
|
||||
|
@ -90,9 +90,9 @@ def process_pop(list_name):
|
|||
redirect_to_list(list_name)
|
||||
|
||||
def redirect_to_list(list_name):
|
||||
scgi.redirect_temp(scgi.script + "/" + list_name)
|
||||
scgi.redirect_temp(scgi.script_name + "/" + list_name)
|
||||
|
||||
path_components = scgi.path.lstrip("/").split("/", maxsplit=1)
|
||||
path_components = scgi.path_info.lstrip("/").split("/", maxsplit=1)
|
||||
list_name = path_components[0]
|
||||
action = path_components[1] if len(path_components) > 1 else ''
|
||||
if not list_name:
|
||||
|
|
49
smolcgi.py
49
smolcgi.py
|
@ -1,30 +1,43 @@
|
|||
#!/bin/false
|
||||
from os import environ
|
||||
from urllib.parse import unquote
|
||||
|
||||
def getenv(name):
|
||||
return environ.get(name, "")
|
||||
|
||||
version = getenv("GATEWAY_INTERFACE")
|
||||
protocol = getenv("SERVER_PROTOCOL")
|
||||
software = getenv("SERVER_SOFTWARE")
|
||||
url = getenv("GEMINI_URL")
|
||||
script = getenv("SCRIPT_NAME")
|
||||
path = getenv("PATH_INFO")
|
||||
query = getenv("QUERY_STRING")
|
||||
host = getenv("SERVER_NAME")
|
||||
port = getenv("SERVER_PORT")
|
||||
remote = getenv("REMOTE_HOST")
|
||||
tls_cipher = getenv("TLS_CIPHER")
|
||||
gateway_interface = getenv("GATEWAY_INTERFACE")
|
||||
remote_addr = getenv("REMOTE_ADDR")
|
||||
remote_host = getenv("REMOTE_HOST")
|
||||
request_method = getenv("REQUEST_METHOD")
|
||||
script_name = getenv("SCRIPT_NAME")
|
||||
server_name = getenv("SERVER_NAME")
|
||||
server_port = getenv("SERVER_PORT")
|
||||
server_protocol = getenv("SERVER_PROTOCOL")
|
||||
server_software = getenv("SERVER_SOFTWARE")
|
||||
gemini_document_root = getenv("GEMINI_DOCUMENT_ROOT")
|
||||
gemini_script_filename = getenv("GEMINI_SCRIPT_FILENAME")
|
||||
gemini_url = getenv("GEMINI_URL")
|
||||
gemini_url_path = getenv("GEMINI_URL_PATH")
|
||||
tls_version = getenv("TLS_VERSION")
|
||||
tls_cipher = getenv("TLS_CIPHER")
|
||||
path_info = getenv("PATH_INFO")
|
||||
query_string = getenv("QUERY_STRING")
|
||||
auth_type = getenv("AUTH_TYPE")
|
||||
cert_hash = getenv("TLS_CLIENT_HASH")
|
||||
cert_sn = getenv("TLS_CLIENT_SERIAL_NUMBER")
|
||||
cert_name = getenv("REMOTE_USER")
|
||||
remote_user = getenv("REMOTE_USER")
|
||||
tls_client_issuer = getenv("TLS_CLIENT_ISSUER")
|
||||
tls_client_hash = getenv("TLS_CLIENT_HASH")
|
||||
tls_client_not_after = getenv("TLS_CLIENT_NOT_AFTER")
|
||||
tls_client_not_before = getenv("TLS_CLIENT_NOT_BEFORE")
|
||||
|
||||
query_string_dec = unquote(query_string)
|
||||
|
||||
cgi_vars = [
|
||||
"version", "protocol", "software", "url", "script", "path", "query", "host",
|
||||
"port", "remote", "tls_cipher", "tls_version", "auth_type", "cert_hash",
|
||||
"cert_sn", "cert_name"
|
||||
"gateway_interface", "remote_addr", "remote_host", "request_method",
|
||||
"script_name", "server_name", "server_port", "server_protocol",
|
||||
"server_software", "gemini_document_root", "gemini_script_filename",
|
||||
"gemini_url", "gemini_url_path", "tls_version", "tls_cipher", "path_info",
|
||||
"query_string", "auth_type", "remote_user", "tls_client_issuer",
|
||||
"tls_client_hash", "tls_client_not_after", "tls_client_not_before",
|
||||
"query_string_dec",
|
||||
]
|
||||
|
||||
def header(code, meta):
|
||||
|
|
Reference in a new issue