|
|
@ -5,6 +5,8 @@ import configparser
|
|
|
|
import lib.uis.default as default_cmd # Follows -u, -a, -f flags
|
|
|
|
import lib.uis.default as default_cmd # Follows -u, -a, -f flags
|
|
|
|
|
|
|
|
|
|
|
|
default_cmd.argparser.description += " - Lists Users from the Tilde database."
|
|
|
|
default_cmd.argparser.description += " - Lists Users from the Tilde database."
|
|
|
|
|
|
|
|
default_cmd.argparser.add_argument('--list', default=False, action="store_true",
|
|
|
|
|
|
|
|
help='Output a newline seperated list of users', required=False)
|
|
|
|
args = default_cmd.argparser.parse_args()
|
|
|
|
args = default_cmd.argparser.parse_args()
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(args.config)
|
|
|
|
config.read(args.config)
|
|
|
@ -17,13 +19,21 @@ class ListUsers:
|
|
|
|
def __init__(self, db: str, uap: bool = False, app: bool = True):
|
|
|
|
def __init__(self, db: str, uap: bool = False, app: bool = True):
|
|
|
|
self.db = SQLitedb(db)
|
|
|
|
self.db = SQLitedb(db)
|
|
|
|
if uap: # only unapproved users
|
|
|
|
if uap: # only unapproved users
|
|
|
|
query = "SELECT * FROM `applications` WHERE status = '0'"
|
|
|
|
query = "SELECT * FROM `applications` WHERE `status` = '0'"
|
|
|
|
elif app: # Approved users
|
|
|
|
elif app: # Approved users
|
|
|
|
query = "SELECT * FROM `applications` WHERE status = '1'"
|
|
|
|
query = "SELECT * FROM `applications` WHERE `status` = '1'"
|
|
|
|
else: # All users
|
|
|
|
else: # All users
|
|
|
|
query = "SELECT * FROM `applications`"
|
|
|
|
query = "SELECT * FROM `applications`"
|
|
|
|
self.usersFetch = self.db.query(query)
|
|
|
|
self.usersFetch = self.db.query(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def outputaslist(self) -> str:
|
|
|
|
|
|
|
|
list_str: str = ""
|
|
|
|
|
|
|
|
query = "SELECT `username` FROM `applications` WHERE `status` = '1' ORDER BY timestamp ASC"
|
|
|
|
|
|
|
|
self.usersFetch = self.db.query(query)
|
|
|
|
|
|
|
|
for users in self.usersFetch:
|
|
|
|
|
|
|
|
list_str += users["username"]+"\n"
|
|
|
|
|
|
|
|
return list_str
|
|
|
|
|
|
|
|
|
|
|
|
def prettyPrint(self) -> None:
|
|
|
|
def prettyPrint(self) -> None:
|
|
|
|
pass # see below why not implemented yet, texttable...
|
|
|
|
pass # see below why not implemented yet, texttable...
|
|
|
|
|
|
|
|
|
|
|
@ -36,14 +46,9 @@ class ListUsers:
|
|
|
|
return self.usersFetch
|
|
|
|
return self.usersFetch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# @TODO MAYBE best solution: https://pypi.org/project/texttable/
|
|
|
|
try:
|
|
|
|
# examle:
|
|
|
|
ret = ""
|
|
|
|
"""
|
|
|
|
L = ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved)
|
|
|
|
|
|
|
|
fetch = L.getFetch()
|
|
|
|
|
|
|
|
# @TODO MAYBE best solution: https://pypi.org/project/texttable/
|
|
|
|
|
|
|
|
# examle:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
from texttable import Texttable
|
|
|
|
from texttable import Texttable
|
|
|
|
t = Texttable()
|
|
|
|
t = Texttable()
|
|
|
|
t.add_rows([['Name', 'Age'], ['Alice', 24], ['Bob', 19]])
|
|
|
|
t.add_rows([['Name', 'Age'], ['Alice', 24], ['Bob', 19]])
|
|
|
@ -61,7 +66,16 @@ print(t.draw())
|
|
|
|
for user in fetch:
|
|
|
|
for user in fetch:
|
|
|
|
print("ID: {}; Username: \"{}\"; Mail: {}; Name: \"{}\"; Registered: {}; Status: {}".format(
|
|
|
|
print("ID: {}; Username: \"{}\"; Mail: {}; Name: \"{}\"; Registered: {}; Status: {}".format(
|
|
|
|
user["id"], user["username"], user["email"], user["name"], user["timestamp"], user["status"]
|
|
|
|
user["id"], user["username"], user["email"], user["name"], user["timestamp"], user["status"]
|
|
|
|
))"""
|
|
|
|
))
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
ret = ""
|
|
|
|
|
|
|
|
L = ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved)
|
|
|
|
|
|
|
|
if args.list:
|
|
|
|
|
|
|
|
ret = L.outputaslist()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
fetch = L.getFetch()
|
|
|
|
ret += "ID %-1s| Username %-5s| Mail %-20s| Name %-17s| Registered %-8s | State |\n" % (
|
|
|
|
ret += "ID %-1s| Username %-5s| Mail %-20s| Name %-17s| Registered %-8s | State |\n" % (
|
|
|
|
" ", " ", " ", " ", " "
|
|
|
|
" ", " ", " ", " ", " "
|
|
|
|
)
|
|
|
|
)
|
|
|
|