First commit

This commit is contained in:
Matt Arnold 2020-06-20 22:42:29 -04:00
parent 5ce1c5d455
commit c3b1ab09a6
9 changed files with 160 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.pyc
*.db
.env
*.log

8
banner Normal file
View File

@ -0,0 +1,8 @@
mmmmm mmmm m"" m"" m
# # m m mmmmm mmmmm m" "m mm#mm mm#mm #
#mmmm" # # m" m" # # # # #
# # # # m" m" # # # # "
#mmmm" "mm"# #mmmm #mmmm #mm# # # #

8
banner1 Normal file
View File

@ -0,0 +1,8 @@
m m ""# m
# # # mmm # mmm mmm mmmmm mmm #
" #"# # #" # # #" " #" "# # # # #" # #
## ##" #"""" # # # # # # # #"""" "
# # "#mm" "mm "#mm" "#m#" # # # "#mm" #

12
dot-env.sample Normal file
View File

@ -0,0 +1,12 @@
# Settings for the neofinger program itself
NF_BASEDIR="."
NF_DBNAME="usermap.db"
NF_LOGFILE="query.log"
# Settings for uscpi-tcp
NF_PREPEND="sudo"
# these must be numaric
NF_RUNAS=`id`
NF_GROUP=`id -g`
NF_PORT="79"

23
initdb.py Normal file
View File

@ -0,0 +1,23 @@
import sqlite3
import os
from settings import *
schema = open("schema.sql").read()
banner1 = open("banner1").read()
banner = open("banner").read()
os.chdir(BASEDIR)
db = sqlite3.connect(DBNAME)
c = db.cursor()
c.execute(schema)
db.commit()
uname = os.getenv("USER")
sqls = "INSERT INTO lusers (unix_name, type, data) VALUES (?,?,?)"
c.execute(sqls, (uname, 255, "Created this foolishness"))
c.execute(sqls, ("__b1__", 11, banner1))
c.execute(sqls, ('__b__', 11, banner))
db.commit()
db.close()

89
neofinger.py Executable file
View File

@ -0,0 +1,89 @@
#!/usr/bin/python3
# Note We're doing this using uscpi-tcp for inital testing
# We'll add the socket stuff later
import sqlite3
import os
import random
import pickle
import sys
import logging
import subprocess
from settings import *
DYN_TYPE = 76
BANNER_TYPE = 11
PLAINTEXT_TYPE = 255
CRLF = '\r\n'
def eat_pickle(sP):
cmd = pickle.loads(sP)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return p.stdout.read().decode("ascii")
os.chdir(BASEDIR)
dbcon = None
try:
dbcon = sqlite3.connect(DBNAME)
except Exception as e:
sys.stdout.write(str(e))
def banner_query():
from random import choice
sqls = "SELECT data FROM lusers WHERE type=?"
cur = dbcon.cursor()
cur.execute(sqls, [BANNER_TYPE])
bList = cur.fetchall()
b = choice(bList)
return b[0] + CRLF
def parse_and_query(uname):
rv = "No such entity\r\n"
if uname == '':
banner_query()
else:
sqls = "SELECT type, data FROM lusers WHERE unix_name=?"
cur = dbcon.cursor()
cur.execute(sqls, [uname])
data = cur.fetchone()
if data:
rv = eat_pickle(data[1])+CRLF if int(data[0]
) == DYN_TYPE else data[1]+CRLF
return rv
def info_query(uname):
cur = dbcon.cursor()
cur.execute("SELECT data FROM lusers WHERE unix_name=?", [uname])
data = cur.fetchone()
rv = data[0] + CRLF if data else "404 No such entity\r\n"
return rv
def send_stdin():
return sys.stdin.readline()
recv_query = send_stdin
def send_msg(x): return sys.stdout.write(str(x))
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)

3
neofingerd.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
. .env
$NF_PREPEND tcpserver -v -u $NF_RUNAS -g $NF_GROUP 0 $NF_PORT $NF_BASEDIR/neofinger.py

7
schema.sql Normal file
View File

@ -0,0 +1,7 @@
CREATE TABLE lusers (
uid INTEGER PRIMARY KEY NOT NULL,
type INTEGER DEFAULT 255,
unix_name VARCHAR(32) NOT NULL UNIQUE,
data BLOB DEFAULT 'their a really nice person'
);

6
settings.py Normal file
View File

@ -0,0 +1,6 @@
from dotenv import load_dotenv
import os
load_dotenv()
LOGFILE = os.getenv("NF_LOGFILE")
BASEDIR = os.getenv("NF_BASEDIR")
DBNAME = os.getenv("NF_DBNAME")