You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
neeble/utils/ipm.py

24 lines
828 B
Python

## IPM (Integrated Permissions Module)
# The Integrated Permissions Module will allow for individual sets of rules for individual users
import MySQLdb
from models.ipm import Ipm
from settings.config import MYSQL_CONFIG, SQLACHEMY
from sqlalchemy.orm import Session
import json
def ipm_check(user: str, ipmstring: str) -> bool:
ipmjson = {}
ipmstring = ipmstring.split('.')
with Session(SQLACHEMY) as session:
ipmlist = session.query(Ipm).filter(Ipm.user==user)
ipmlist = session.execute(ipmlist)
ipmlist = [obj.ipmlist for obj in ipmlist.scalars()]
ipmjson = json.loads(str(ipmlist[0])) if ipmlist else None
if ipmjson is None:
return False
if ipmstring[1] in ipmjson[ipmstring[0]] or "*" in ipmjson[ipmstring[0]]:
return True
else:
return False