ARPSCAN to plugin rewrite

This commit is contained in:
Jokob-sk
2023-08-08 06:52:43 +10:00
parent 80bda24b5f
commit 9ddea01f12
4 changed files with 38 additions and 29 deletions

View File

@@ -26,7 +26,7 @@ from const import *
from logger import mylog from logger import mylog
from helper import filePermissions, isNewVersion, timeNowTZ, updateState from helper import filePermissions, isNewVersion, timeNowTZ, updateState
from api import update_api from api import update_api
from networkscan import process_scan, scan_network # from networkscan import process_scan, scan_network
from initialise import importConfigs from initialise import importConfigs
from mac_vendor import update_devices_MAC_vendors from mac_vendor import update_devices_MAC_vendors
from database import DB, get_all_devices from database import DB, get_all_devices
@@ -206,43 +206,43 @@ def main ():
# todo replace the scans with plugins # todo replace the scans with plugins
# Perform a network scan via arp-scan or pihole # Perform a network scan via arp-scan or pihole
if last_network_scan + datetime.timedelta(minutes=conf.SCAN_CYCLE_MINUTES) < loop_start_time: # if last_network_scan + datetime.timedelta(minutes=conf.SCAN_CYCLE_MINUTES) < loop_start_time:
last_network_scan = loop_start_time # last_network_scan = loop_start_time
conf.cycle = 1 # network scan # conf.cycle = 1 # network scan
mylog('verbose', ['[MAIN] cycle:',conf.cycle]) # mylog('verbose', ['[MAIN] cycle:',conf.cycle])
updateState(db,"Scan: Network") # updateState(db,"Scan: Network")
# scan_network() # # scan_network()
# DEBUG start ++++++++++++++++++++++++++++++++++++++++++++++++++++++ # # DEBUG start ++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Start scan_network as a process # # Start scan_network as a process
p = multiprocessing.Process(target=scan_network(db)) # p = multiprocessing.Process(target=scan_network(db))
p.start() # p.start()
# Wait for a maximum of 3600 seconds (1h) or until process finishes # # Wait for a maximum of 3600 seconds (1h) or until process finishes
p.join(3600) # p.join(3600)
# If thread is still active # # If thread is still active
if p.is_alive(): # if p.is_alive():
mylog('none', "[MAIN] scan_network running too long - let\'s kill it") # mylog('none', "[MAIN] scan_network running too long - let\'s kill it")
# Terminate - may not work if process is stuck for good # # Terminate - may not work if process is stuck for good
p.terminate() # p.terminate()
# OR Kill - will work for sure, no chance for process to finish nicely however # # OR Kill - will work for sure, no chance for process to finish nicely however
# p.kill() # # p.kill()
p.join() # p.join()
# DEBUG end ++++++++++++++++++++++++++++++++++++++++++++++++++++++ # # DEBUG end ++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Run splugin scripts which are set to run every timne after a scan finished # # Run splugin scripts which are set to run every timne after a scan finished
if conf.ENABLE_PLUGINS: if conf.ENABLE_PLUGINS:
run_plugin_scripts(db,'always_after_scan') run_plugin_scripts(db,'always_after_scan')
# -------------------------------------------------- # --------------------------------------------------
# process all the scanned data into new devices # process all the scanned data into new devices
mylog('debug', "[MAIN] start processig scan results") # mylog('debug', "[MAIN] start processig scan results")
process_scan (db) # process_scan (db)
# Reporting # Reporting
if conf.cycle in conf.check_report: if conf.cycle in conf.check_report:

View File

@@ -11,6 +11,7 @@ from const import pluginsPath, logPath
from logger import mylog from logger import mylog
from helper import timeNowTZ, updateState, get_file_content, write_file from helper import timeNowTZ, updateState, get_file_content, write_file
from api import update_api from api import update_api
from networkscan import process_scan
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def run_plugin_scripts(db, runType): def run_plugin_scripts(db, runType):
@@ -586,6 +587,12 @@ def process_plugin_events(db, plugin):
# This will insert multiple rows into the database in one go. # This will insert multiple rows into the database in one go.
sql.executemany(q, sqlParams) sql.executemany(q, sqlParams)
db.commitDB()
# perform scan if mapped to CurrentScan table
if dbTable == 'CurrentScan':
process_scan(db)
db.commitDB() db.commitDB()
@@ -593,6 +600,8 @@ def process_plugin_events(db, plugin):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class plugin_object_class: class plugin_object_class:
def __init__(self, plugin, objDbRow): def __init__(self, plugin, objDbRow):

View File

@@ -14,7 +14,7 @@ import conf
from const import pialertPath, logPath, apiPath from const import pialertPath, logPath, apiPath
from helper import noti_struc, generate_mac_links, removeDuplicateNewLines, timeNowTZ, hide_email, updateState, get_file_content, write_file from helper import noti_struc, generate_mac_links, removeDuplicateNewLines, timeNowTZ, hide_email, updateState, get_file_content, write_file
from logger import logResult, mylog, print_log from logger import logResult, mylog, print_log
from plugin import execute_plugin # from plugin import execute_plugin
from publishers.email import (check_config as email_check_config, from publishers.email import (check_config as email_check_config,