Improved login errors,

Added user disable option,
Fix groups selection in tasks,
Improved Auto updater,
Fixed sorting of scan reports,
Some pro feature
This commit is contained in:
sepehr 2024-08-26 11:22:04 +03:30
parent c39721de96
commit 30d60a72ad
12 changed files with 115 additions and 38 deletions

View file

@ -26,6 +26,12 @@ try:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except:
pass
try:
from libs import utilpro
ISPRO=True
except ImportError:
ISPRO=False
pass
log = logging.getLogger("Radius")
@ -103,17 +109,17 @@ class RadServer(ServerAsync):
if not dev:
self.send_auth_reject(protocol,pkt,addr)
return
u = db.get_user_by_username(username)
if not u:
if not u or u.role=='disabled':
self.send_auth_reject(protocol,pkt,addr)
db_AA.Auth.add_log(dev.id, 'failed', username , userip , by=None,sessionid=None,timestamp=tz,message="User Not Exist")
return
else:
#get user permision related to device
if not dev:
self.send_auth_reject(protocol, pkt, addr)
db_AA.Auth.add_log(dev.id, 'failed', username, userip, by=None, sessionid=None, timestamp=tz, message="Device Not Exist")
db_AA.Auth.add_log(dev.id, 'failed', u.username, userip, by=None, sessionid=None, timestamp=tz, message="Device Not Exist")
return
force_perms=True if db_sysconfig.get_sysconfig('force_perms')=="True" else False
if force_perms:
@ -128,9 +134,16 @@ class RadServer(ServerAsync):
res2=FourcePermToRouter(dev,perm)
if not res2:
self.send_auth_reject(protocol,pkt,addr)
db_AA.Auth.add_log(dev.id, 'failed', username , userip , by=None,sessionid=None,timestamp=tz,message="Unable to verify group")
db_AA.Auth.add_log(dev.id, 'failed', u.username , userip , by=None,sessionid=None,timestamp=tz,message="Unable to verify group")
return
nthash=u.hash
if(ISPRO):
nthash = utilpro.GetNThash(u)
respro=utilpro.verfyRadius(u,userip)
if not respro:
db_AA.Auth.add_log(dev.id, 'failed', u.username , userip , by=None,sessionid=None,timestamp=tz,message="IP not allowed: {}".format(userip))
self.send_auth_reject(protocol, pkt, addr)
return
if force_perms:
reply=self.verifyMsChapV2(pkt,"password",perm[0].perm_id.name,nthash)
else:
@ -138,7 +151,7 @@ class RadServer(ServerAsync):
if reply:
protocol.send_response(reply, addr)
return
db_AA.Auth.add_log(dev.id, 'failed', username , userip , by=None,sessionid=None,timestamp=tz,message="Wrong Password")
db_AA.Auth.add_log(dev.id, 'failed', u.username , userip , by=None,sessionid=None,timestamp=tz,message="Wrong Password")
self.send_auth_reject(protocol,pkt,addr)
except Exception as e:
print(e)

View file

@ -17,6 +17,20 @@ import hashlib
import zipfile
import subprocess
log = logging.getLogger("Updater_mule")
import pip
def import_or_install(package):
try:
__import__(package)
except ImportError:
pip.main(['install', package])
def install_package(package):
try:
pip.main(['install', package])
except Exception as e:
log.error(e)
def set_get_install_date():
@ -66,8 +80,27 @@ def extract_zip_reload(filename,dst):
(output, err) = p.communicate()
#This makes the wait possible
p_status = p.wait()
#touch server reload file /app/reload
#install requirments
try:
from libs import utilpro
ISPRO=True
proreqs="/app/py/pro-reqs.txt"
with open(proreqs, "r") as f:
for line in f:
import_or_install(line.strip())
log.info("Installed {}".format(line.strip()))
time.sleep(1)
except ImportError:
pass
reqs="/app/reqs.txt"
with open(reqs, "r") as f:
for line in f:
try:
install_package(line.strip())
except:
pass
os.remove(filename)
#touch server reload file /app/reload
Path('/app/reload').touch()