restructured app with subdirs for each feature

This commit is contained in:
James Tomasino 2022-02-20 23:43:08 +00:00
parent ae145b4a55
commit f2ee12fc1e
6 changed files with 89 additions and 9 deletions

View File

@ -11,6 +11,9 @@ The goal of this project is to give a working example of a basic Gemini CGI appl
## Files
* `index.gmi` - a python script using the `gmi` extension. It is an executable file to enable CGI use. Your server must be configured for CGI for this to work. Depending on your server software you may need to house this project within a special `cgi-bin` directory.
Several sub-directories exist with their own index.gmi files to perform specific app actions.
* `db.py` - handles database connection and queries
* `helpers.py` - provides some Gemini header operations and environment variable fetching
* `create_schema.sql` - holds the database schema for sqlite used in this app.

20
cgi-example/add-cert/index.gmi Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
# modules are all in the parent directory
import sys
sys.path.append('..')
# import helpers from modules
from helpers import get_client_cert
from db import check_hash
TLS_CLIENT_HASH = get_client_cert()
user_id = check_hash(TLS_CLIENT_HASH)
user_name = "[Not Set]"
user_cert_count = 1
print("# Add another cert")
print()
print("This feature coming soon.")
#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
# modules are all in the parent directory
import sys
sys.path.append('..')
# import helpers from modules
from helpers import get_client_cert
from db import check_hash
TLS_CLIENT_HASH = get_client_cert()
user_id = check_hash(TLS_CLIENT_HASH)
user_name = "[Not Set]"
print("# Name Change Page")
print()
print("This feature coming soon.")
#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai

View File

@ -1,5 +1,6 @@
import sqlite3
from sqlite3 import Error
import os
""" Create database with:
sqlite3 db/cgi-example.sqlite3 < create_schema.sql
@ -8,7 +9,10 @@ from sqlite3 import Error
and the containing directory "db" to the user that your
gemini server runs as
"""
database = r"db/cgi-example.sqlite3"
dir_name = os.path.dirname(__file__)
db_name = r"db/cgi-example.sqlite3"
db_file = os.path.join(dir_name, db_name)
def create_connection():
""" create a database connection to the SQLite database
@ -18,7 +22,7 @@ def create_connection():
"""
conn = None
try:
conn = sqlite3.connect(database)
conn = sqlite3.connect(db_file)
except Error as e:
print(e)
return conn

View File

@ -1,16 +1,16 @@
#!/usr/bin/env python3
from helpers import get_client_cert
from db import check_hash
TLS_CLIENT_HASH = get_client_cert()
user_id = check_hash(TLS_CLIENT_HASH)
from helpers import show_header_ok
show_header_ok()
with open('README.md') as f:
contents = f.read()
print(contents)
print("## USER ID:")
print(user_id)
print("## Project Source:")
print("=> https://tildegit.org/tomasino/gemspace/src/branch/master/cgi-example CGI Example Source on tildegit.org")
print("")
print("## Get Started")
print("=> login Login with your client certificate to begin")
#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai

33
cgi-example/login/index.gmi Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
# modules are all in the parent directory
import sys
sys.path.append('..')
# import helpers from modules
from helpers import get_client_cert
from db import check_hash
TLS_CLIENT_HASH = get_client_cert()
user_id = check_hash(TLS_CLIENT_HASH)
user_name = "[Not Set]"
user_cert_count = 1
print("# Welcome: User Logged In")
print()
print("## Your USER ID:")
print(user_id)
print()
print("## Your USER NAME:")
print(user_name)
print("=> ../change-name Change User Name")
print()
print("## Number of TLS Certs associated with account")
print(user_cert_count)
print("=> ../add-cert Add another cert to your account")
print()
#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai