neofinger: Add the ability to render static .plan files for users not in db

updateplan: fix failure to read plan files when inserting into db
This commit is contained in:
Matt Arnold 2021-08-06 12:03:28 -04:00
parent ac1f2b4cc9
commit 9d785058f7
2 changed files with 9 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import pickle
import sys
import logging
import subprocess
import os.path
from settings import *
DYN_TYPE = 76
BANNER_TYPE = 11
@ -53,6 +54,10 @@ def parse_and_query(uname):
if data:
rv = eat_pickle(data[1])+CRLF if int(data[0]
) == DYN_TYPE else data[1]+CRLF
else:
if os.path.exists(f'/home/{uname}/.plan'):
fp = open(f"/home/{uname}/.plan")
rv = fp.read() + CRLF
return rv

View File

@ -25,9 +25,8 @@ def cli():
def luseradd(unixname, planfile):
db = sqlite3.connect(DBNAME)
c = db.cursor()
c.execute(sqls, (unixname, PLAINTEXT_TYPE, planfile))
contents = open(planfile).read()
c.execute(sqls, (unixname, PLAINTEXT_TYPE, contents))
db.commit()
db.close()
click.echo("user added!")
@ -42,8 +41,8 @@ def rndname(stringLength=8):
def banner(planfile):
db = sqlite3.connect(DBNAME)
c = db.cursor()
c.execute(sqls, (rndname(), BANNER_TYPE, planfile))
contents = open(planfile).read()
c.execute(sqls, (rndname(), BANNER_TYPE, contents))
db.commit()
db.close()
click.echo("banner will appear in rotation")