restructured app with subdirs for each feature
This commit is contained in:
parent
ae145b4a55
commit
f2ee12fc1e
|
@ -11,6 +11,9 @@ The goal of this project is to give a working example of a basic Gemini CGI appl
|
||||||
## Files
|
## 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.
|
* `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
|
* `db.py` - handles database connection and queries
|
||||||
* `helpers.py` - provides some Gemini header operations and environment variable fetching
|
* `helpers.py` - provides some Gemini header operations and environment variable fetching
|
||||||
* `create_schema.sql` - holds the database schema for sqlite used in this app.
|
* `create_schema.sql` - holds the database schema for sqlite used in this app.
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -1,5 +1,6 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from sqlite3 import Error
|
from sqlite3 import Error
|
||||||
|
import os
|
||||||
|
|
||||||
""" Create database with:
|
""" Create database with:
|
||||||
sqlite3 db/cgi-example.sqlite3 < create_schema.sql
|
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
|
and the containing directory "db" to the user that your
|
||||||
gemini server runs as
|
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():
|
def create_connection():
|
||||||
""" create a database connection to the SQLite database
|
""" create a database connection to the SQLite database
|
||||||
|
@ -18,7 +22,7 @@ def create_connection():
|
||||||
"""
|
"""
|
||||||
conn = None
|
conn = None
|
||||||
try:
|
try:
|
||||||
conn = sqlite3.connect(database)
|
conn = sqlite3.connect(db_file)
|
||||||
except Error as e:
|
except Error as e:
|
||||||
print(e)
|
print(e)
|
||||||
return conn
|
return conn
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from helpers import get_client_cert
|
from helpers import show_header_ok
|
||||||
from db import check_hash
|
show_header_ok()
|
||||||
|
|
||||||
TLS_CLIENT_HASH = get_client_cert()
|
|
||||||
user_id = check_hash(TLS_CLIENT_HASH)
|
|
||||||
|
|
||||||
with open('README.md') as f:
|
with open('README.md') as f:
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
print(contents)
|
print(contents)
|
||||||
|
|
||||||
print("## USER ID:")
|
print("## Project Source:")
|
||||||
print(user_id)
|
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
|
#vim:fenc=utf-8:ts=4:sw=4:sta:noet:sts=4:fdm=marker:ai
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue