Fixed Firmware download from the Mikrotik website when there are multiple npk available
Fixed Mikrowizard system permission error when it is set to None
Fixed user device group permissions
Some minor UI improvements
Fix IP scan for one IP scan / Fix not scanning the last IP in the range
Fix manual snippet execution not working when device groups are selected
Some minor bug fixes and improvements

New:
Show background tasks and be able to stop them while running in the background (like an IP scanner)
Add support for manual MikroWizard update dashboard/settings page
update to version 1.0.5

Enhancement:
Show permission error in some pages when the  user doesn't have permission for that page/action
show better charts/graphs in the dashboard and device interface details
show more info on the dashboard about update and version information and license
This commit is contained in:
sepehr 2025-01-02 20:12:00 +03:00
parent a26bd6ae55
commit 70dc0ddc55
15 changed files with 296 additions and 63 deletions

View file

@ -105,9 +105,10 @@ def devs2(groupid):
.join(DevGroupRel, on=DevGroupRel.device_id)
.where(DevGroupRel.group_id == groupid)
.order_by(Devices.name))
def get_devs_of_groups(group_ids):
try:
group_ids=[group.id for group in group_ids]
group_ids=[group if isinstance(group, int) else group.id for group in group_ids]
if 1 in group_ids:
return list(Devices
.select()
@ -122,9 +123,12 @@ def get_devs_of_groups(group_ids):
return []
#get all groups including devices in each group
def query_groups_api():
def query_groups_api(group_ids=[]):
t3=DevGroups.alias()
q=DevGroups.select(DevGroups.id,DevGroups.name,DevGroups.created,fn.array_agg(DevGroupRel.device_id)).join(DevGroupRel,JOIN.LEFT_OUTER, on=(DevGroupRel.group_id == DevGroups.id)).order_by(DevGroups.id).group_by(DevGroups.id)
if not isinstance(group_ids, list):
q=DevGroups.select(DevGroups.id,DevGroups.name,DevGroups.created,fn.array_agg(DevGroupRel.device_id)).join(DevGroupRel,JOIN.LEFT_OUTER, on=(DevGroupRel.group_id == DevGroups.id)).order_by(DevGroups.id).group_by(DevGroups.id)
else:
q=DevGroups.select(DevGroups.id,DevGroups.name,DevGroups.created,fn.array_agg(DevGroupRel.device_id)).join(DevGroupRel,JOIN.LEFT_OUTER, on=(DevGroupRel.group_id == DevGroups.id)).where(DevGroups.id << group_ids).order_by(DevGroups.id).group_by(DevGroups.id)
return list(q.dicts())
def get_groups_by_id(ids):
@ -143,7 +147,6 @@ def delete_from_group(devids):
def delete_device(devid):
try:
delete_from_group([devid])
dev = get_object_or_none(Devices, id=devid)
dev.delete_instance(recursive=True)

View file

@ -17,7 +17,8 @@ class Tasks(BaseModel):
starttime = DateTimeField()
endtime = DateTimeField()
status = BooleanField()
action = TextField()
name = TextField()
class Meta:
# `indexes` is a tuple of 2-tuples, where the 2-tuples are
# a tuple of column names to index and a boolean indicating
@ -32,7 +33,6 @@ def update_check_status():
def update_job_status():
return (Tasks.select().where(Tasks.signal == 110).get())
#Get groups of device
def backup_job_status():
return (Tasks.select().where(Tasks.signal == 120).get())
@ -51,6 +51,14 @@ def firmware_service_status():
def exec_snipet_status():
return (Tasks.select().where(Tasks.signal == 160).get())
def get_running_tasks():
return (Tasks.select().where(Tasks.status == True))
def get_task_by_signal(signal):
return (Tasks.select().where(Tasks.signal == signal).get())
def get_all():
return (Tasks.select())
class TaskResults(BaseModel):
task_type = TextField()

View file

@ -11,7 +11,7 @@ import time
import uuid
import socket
import config
from libs.db import db_sysconfig,db_firmware,db_backups,db_events
from libs.db import db_sysconfig,db_firmware,db_tasks,db_events
from cryptography.fernet import Fernet
from libs.check_routeros.routeros_check.resource import RouterOSCheckResource
from libs.check_routeros.routeros_check.helper import RouterOSVersion
@ -37,26 +37,31 @@ except ImportError:
import zipfile
def extract_from_link(link,all_package=False):
if all_package:
regex = r"https:\/\/download\.mikrotik\.com\/routeros\/(\d{1,3}.*)?\/all_packages-(.*)-(.*).zip"
matches = re.match(regex, link)
if not matches:
return False
res=matches.groups()
version=res[0]
arch = res[1]
return {"link":link, "arch":arch, "version":version, "all_package":True}
else:
regex = r"https:\/\/download\.mikrotik\.com\/routeros\/(\d{1,3}.*)?\/routeros-(.*).npk"
matches = re.match(regex,link)
res=matches.groups()
version=res[0]
arch = res[1].replace(version, "")
if arch == "":
arch = "x86"
try:
if all_package:
regex = r"https:\/\/download\.mikrotik\.com\/routeros\/(\d{1,3}.*)?\/all_packages-(.*)-(.*).zip"
matches = re.match(regex, link)
if not matches:
return False
res=matches.groups()
version=res[0]
arch = res[1]
return {"link":link, "arch":arch, "version":version, "all_package":True}
else:
arch=arch.replace("-","")
return {"link":link,"arch":arch, "version":version}
regex = r"https:\/\/download\.mikrotik\.com\/routeros\/(\d{1,3}.*)?\/routeros-(.*).npk"
matches = re.match(regex,link)
res=matches.groups()
version=res[0]
arch = res[1].replace(version, "")
if arch == "":
arch = "x86"
else:
arch=arch.replace("-","")
return {"link":link,"arch":arch, "version":version}
except Exception as e:
log.info("unable to extract from link : {}".format(link))
log.info(e)
return False
def get_mikrotik_latest_firmware_link():
@ -68,6 +73,8 @@ def get_mikrotik_latest_firmware_link():
link=str(link.get('href'))
if ".npk" in link:
frimware=extract_from_link(link)
if not frimware:
continue
firms.setdefault(frimware["version"],{})
firms[frimware["version"]][frimware["arch"]]={"link":frimware["link"],"mark":"latest"}
# firms.append(link)
@ -87,7 +94,10 @@ def get_mikrotik_download_links(version,all_package=False):
lnk=str(link[0].get('href'))
sha=str(link[1].get('data-checksum-sha256'))
if ".npk" in lnk:
log.error(lnk)
frimware=extract_from_link(lnk)
if not frimware:
continue
firms.setdefault(frimware["version"], {})
firms[frimware["version"]][frimware["arch"]]={"link":frimware["link"],"sha":sha}
# firms.append(link)
@ -206,6 +216,12 @@ def download_firmware_to_repository(version,q,arch="all",all_package=False):
links=links[version]
firm=db_firmware.Firmware()
for lnk in links:
task=db_tasks.downloader_job_status()
if task.action=="cancel":
log.info("Firmware Download Task Canceled")
if q:
q.put({"status":False})
return False
if all_package and arch+"-allpackage" == lnk:
arch_togo=lnk
link=links[lnk]["link"]

View file

@ -280,7 +280,7 @@ def grab_device_data(dev, q):
if d['name'] in excluded_keys:
continue
health_vals[d['name']]=d['value']
elif result['board-name']=='x86':
elif result['board-name']=='x86' or 'x86' in result['architecture-name']:
health_vals={}
else:
health_vals: Dict[str, str] = health[0]
@ -579,7 +579,7 @@ def check_update(options,router=False):
log.error(e)
pass
upgrade=False
if result['board-name']!='x86' and result['current-firmware']!= result['upgrade-firmware'] and result['board-name']!='x86':
if 'x86' not in result['board-name'] and result['current-firmware']!= result['upgrade-firmware'] and result['board-name']!='x86':
upgrade=True
if _latest_version and _installed_version < _latest_version:
return True, _installed_version,arch,upgrade

View file

@ -261,10 +261,12 @@ def _is_role_atleast(myrole, rolebase, perm):
return "userid" in session
userperms=session.get("perms") or {}
perms = { "None":1,"read":2, "write":3, "full":4}
res=True;
res=True
if len(perm)>0:
for key, value in perm.items():
if key in userperms:
if userperms[key]=='none':
res=False
res=res and perms[userperms[key]]>=perms[value]
else:
return False