Add tool for updating the user database, edit README slightly

This commit is contained in:
Matt Arnold 2020-06-29 21:45:08 -04:00
parent 5dbabed01c
commit 26ea6ff316
3 changed files with 73 additions and 0 deletions

View File

@ -12,3 +12,8 @@ to .env and adjusted it Run initdb.py, and have fun!
I was Bored, and making old internet gizmos work again is fun
# Features
* Users are mapped not by the system but by an sqlite3 database
* Multiple randomized banners
* Dynamic Content entities

64
updateplan.py Normal file
View File

@ -0,0 +1,64 @@
# upsertplan UPSERT a plan file for a type 255 (normal entity)
import sys
import sqlite3
import random
import string
import pickle
from settings import *
from utypes import *
sqls = """
INSERT OR REPLACE INTO lusers (unix_name, type, data) VALUES (?,?,?)
"""
def type_ff():
db = sqlite3.connect(DBNAME)
c = db.cursor()
planfile = open(sys.argv[2]).read()
c.execute(sqls, (sys.argv[1], PLAINTEXT_TYPE, planfile))
db.commit()
db.close()
sys.exit(0)
def rndname(stringLength=8):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def type_b():
db = sqlite3.connect(DBNAME)
c = db.cursor()
planfile = open(sys.argv[1]).read()
c.execute(sqls, (rndname(), BANNER_TYPE, planfile))
db.commit()
db.close()
sys.exit(0)
def type_4c():
db = sqlite3.connect(DBNAME)
c = db.cursor()
name = input("Name of dynamic user:")
print("Enter Dynamic command to use with full paths to all files\n")
raw = sys.stdin.readline().strip().split(' ')
planfile = pickle.dumps(raw)
c.execute(sqls, (name, DYN_TYPE, planfile))
db.commit()
db.close()
sys.exit(0)
if __name__ == '__main__':
if len(sys.argv ) == 3:
type_ff()
elif len(sys.argv) == 2:
type_b()
elif len(sys.argv) == 1:
type_4c()
else:
print("Error unknown invocation\n")
sys.exit(1)

4
utypes.py Normal file
View File

@ -0,0 +1,4 @@
DYN_TYPE = 76
BANNER_TYPE = 11
PLAINTEXT_TYPE = 255