Improve commandline for updating plan files. Change neofinger to better reflect best practices.

Will be integrating the server into the main body of code later
This commit is contained in:
Matt Arnold 2020-08-17 21:25:19 -04:00
parent 6a1feedde7
commit 598ed89f71
3 changed files with 56 additions and 36 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python3
# Note We're doing this using uscpi-tcp for inital testing
# We'll add the socket stuff later
import sqlite3
@ -74,16 +74,19 @@ recv_query = send_stdin
def send_msg(x): return sys.stdout.write(str(x))
def entry():
logging.basicConfig(filename=LOGFILE, filemode='w',
format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')
line = recv_query()
if line == "\r\n" or line == "\n":
logging.warning("Query was blank sending banner")
send_msg(banner_query())
else:
resp = parse_and_query(line.strip(CRLF))
logging.warning("Query was %s sent %s", line.strip(
CRLF), str(resp).strip(CRLF))
send_msg(resp)
sys.exit(0)
logging.basicConfig(filename=LOGFILE, filemode='w',
format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')
line = recv_query()
if line == "\r\n" or line == "\n":
logging.warning("Query was blank sending banner")
send_msg(banner_query())
else:
resp = parse_and_query(line.strip(CRLF))
logging.warning("Query was %s sent %s", line.strip(
CRLF), str(resp).strip(CRLF))
send_msg(resp)
sys.exit(0)
if __name__ == '__main__':
entry()

View File

@ -1 +1,11 @@
astroid==2.4.2
click==7.1.2
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
pylint==2.5.3
python-dotenv==0.13.0
six==1.15.0
toml==0.10.1
typed-ast==1.4.1
wrapt==1.12.1

View File

@ -5,60 +5,67 @@ import sqlite3
import random
import string
import pickle
from settings import *
from settings import DBNAME
from utypes import *
import click
sqls = """
INSERT OR REPLACE INTO lusers (unix_name, type, data) VALUES (?,?,?)
"""
def type_ff():
delete_sqls = "DELETE FROM lusers WHERE unix_name='?';"
@click.group()
def cli():
pass
@click.command()
@click.argument('unixname')
@click.argument('planfile')
def luseradd(unixname, planfile):
db = sqlite3.connect(DBNAME)
c = db.cursor()
planfile = open(sys.argv[2]).read()
c.execute(sqls, (sys.argv[1], PLAINTEXT_TYPE, planfile))
c.execute(sqls, (unixname, PLAINTEXT_TYPE, planfile))
db.commit()
db.close()
sys.exit(0)
click.echo("user added!")
def rndname(stringLength=8):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def type_b():
@cli.command()
@click.argument('planfile')
def banner(planfile):
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)
click.echo("banner will appear in rotation")
def type_4c():
@cli.command()
@click.argument("name")
@click.argument("cmd")
def cgiadd(name,cmd):
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(' ')
raw = cmd.strip().split(' ')
planfile = pickle.dumps(raw)
c.execute(sqls, (name, DYN_TYPE, planfile))
db.commit()
db.close()
sys.exit(0)
click.echo("Please test your cgi")
def luserdel(name):
pass
cli.add_command(luseradd)
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)
cli()