This commit is contained in:
rald 2023-08-04 03:42:02 +08:00
commit c7d7471801
4 changed files with 172947 additions and 0 deletions

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# CGI Example Project
The goal of this project is to give a working example of a basic Gemini CGI application. User identities are driven by TLS Client Certificates. This project will serve as a reference for CGI authors and be explained in detail in an instructional video.
## Features
* (DONE) New TLS certificates automatically create a new user account
* (DONE) Users can set data on their own account (a name field for example)
* (DONE) Users can add additional certificates to the same account by using a special code
## Setup
Create database with:
``` sqlite command to create database
sqlite3 db/cgi-example.sqlite3 < create_schema.sql
```
Then give write permission to the both the database and the containing directory (`db`) to the user that your Gemini server runs as. It is important that the containing folder write permissions are in place or you will see `50` errors returned when trying to write to the database.

92
boggle.py Executable file
View File

@ -0,0 +1,92 @@
#!/usr/bin/env python3
import random
class Trie:
def __init__(self,letter):
self.letter=letter
self.mark=False
self.next=[None]*26
@staticmethod
def add(root,word):
curr=root
for i in word:
j=i.upper()
k=ord(j)-65
if curr.next[k]==None:
curr.next[k]=Trie(j)
curr=curr.next[k]
curr.mark=True
f=open('dice.txt','r')
dice=f.read().split('\n')
f.close()
dice=list(filter(None,dice))
random.shuffle(dice)
b=[]
for j in range(4):
b.append([])
for i in range(4):
die=dice[j*4+i]
b[j].append(die[random.randrange(0,len(die))].upper())
for j in range(4):
for i in range(4):
print(b[j][i],end=' ')
print()
def r(s):
return s and len(s)>=3 and len(s)<=16
f=open('enable.txt','r')
words=f.read().split('\n')
f.close()
words=list(filter(r,words))
trie=Trie(None)
for word in words:
Trie.add(trie,word.upper())
g=[]
for j in range(4):
g.append([])
for i in range(4):
g[j].append(False)
found=[]
l=['' for i in range(16)]
def dfs(x,y,d,trie):
if x<0 or x>=4 or y<0 or y>=4:
return
if g[y][x]:
return
k=ord(b[y][x].upper())-65
t=trie.next[k]
if not t:
return
l[d]=b[y][x].upper()
if t.mark:
w=''.join(l[0:d+1])
found.append(w)
g[y][x]=True
for j in [-1,0,1]:
for i in [-1,0,1]:
if i!=0 or j!=0:
dfs(x+i,y+j,d+1,t)
g[y][x]=False
for j in range(4):
for i in range(4):
dfs(i,j,0,trie)
found.sort(key=len,reverse=True)
print(found)

16
dice.txt Normal file
View File

@ -0,0 +1,16 @@
aaciot
abilty
abjmoq
acdemp
acelrs
adenvz
ahmors
biforx
denosw
dknotu
eefhiy
egkluy
egintv
ehinps
elpstu
gilruw

172820
enable.txt Normal file

File diff suppressed because it is too large Load Diff