dns-ops/dns-rest-api1.sunet.se/overlay/usr/sbin/knot_lastlogin

29 lines
846 B
Python
Executable file

#!/usr/bin/env python3
import yaml
import sqlite3
try:
with open('/etc/knot_rest/knot_rest.yaml') as stream:
yamlconf = yaml.safe_load(stream)
except Exception as e:
print(e)
knotrestdb = yamlconf["database"].removeprefix("sqlite:///")
try:
with sqlite3.connect(knotrestdb) as conn:
cur = conn.cursor()
cur.execute('select username, description, logged_in from user')
rows = cur.fetchall()
for row in rows:
username = row[0]
description = row[1]
if description == None:
description = "(no description)"
lastlogin = row[2]
if lastlogin == None:
lastlogin = "**never logged in**"
print(f"{username:<27}{description:<27}{lastlogin:<23}")
except sqlite3.OperationalError as e:
print(e)