diff --git a/back/pialert.py b/back/pialert.py index 90d12458..c0ce2884 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -22,6 +22,7 @@ import subprocess import os import re import time +import decimal import datetime from datetime import timedelta # from datetime import datetime @@ -622,7 +623,7 @@ def main (): if runPholus: last_pholus_scheduled_run = datetime.datetime.now(tz).replace(microsecond=0) - performPholusScan() + performPholusScan(PHOLUS_RUN_TIMEOUT) # Perform an arp-scan if not disable with a file if last_network_scan + datetime.timedelta(minutes=SCAN_CYCLE_MINUTES) < time_started and os.path.exists(STOPARPSCAN) == False: @@ -1650,13 +1651,14 @@ def update_devices_names (): # perform Pholus scan if (unknown) devices found if PHOLUS_ACTIVE and (len(unknownDevices) > 0 or PHOLUS_FORCE): - performPholusScan() + performPholusScan(PHOLUS_TIMEOUT) # get names from Pholus scan sql.execute ('SELECT * FROM Pholus_Scan where "MAC" in (select "dev_MAC" from Devices where "dev_Name" IN ("(unknown)","")) and "Record_Type"="Answer"') pholusResults = sql.fetchall() - file_print("pholusResults: ", len(pholusResults)) + # Number of entries for unknown MACs from the Pholus scan + file_print(" Pholus entries: ", len(pholusResults)) for device in unknownDevices: # Resolve device name OLD @@ -1685,7 +1687,7 @@ def update_devices_names (): # file_print(sql.rowcount) #------------------------------------------------------------------------------- -def performPholusScan (): +def performPholusScan (timeout): subnetList = [] @@ -1706,9 +1708,9 @@ def performPholusScan (): file_print(" Pholus scan on interface: ", interface, " mask: " , mask) updateState("Scan: Pholus") - file_print('[', timeNow(), '] Scan: Pholus') + file_print('[', timeNow(), '] Scan: Pholus for ', str(timeout), 's ('+ str(round(int(timeout) / 60), 2) +'min)') - pholus_args = ['python3', '/home/pi/pialert/pholus/pholus3.py', interface, "-rdns_scanning", mask, "-stimeout", str(PHOLUS_TIMEOUT)] + pholus_args = ['python3', '/home/pi/pialert/pholus/pholus3.py', interface, "-rdns_scanning", mask, "-stimeout", str(timeout)] # Execute command try: @@ -1722,7 +1724,7 @@ def performPholusScan (): if output != "": file_print('[', timeNow(), '] Scan: Pholus SUCCESS') - write_file (logPath + '/pialert_pholus_old.log', output) + write_file (logPath + '/pialert_pholus_lastrun.log', output) for line in output.split("\n"): append_line_to_file (logPath + '/pialert_pholus.log', line +'\n') @@ -2922,9 +2924,6 @@ def hide_email(email): m = email.split('@') return f'{m[0][0]}{"*"*(len(m[0])-2)}{m[0][-1] if len(m[0]) > 1 else ""}@{m[1]}' -# Test -print(hide_email('emailsecreto@gmail.com')) - #------------------------------------------------------------------------------- def runSchedule(): @@ -2934,44 +2933,33 @@ def runSchedule(): result = False - # datetime.now() - timedelta(days=1) + # Initialize the last run time if never run before if last_pholus_scheduled_run == 0: - # last_pholus_scheduled_run = datetime.datetime.fromtimestamp(pd.Timestamp(year = 2000, month = 1, day = 1, hour = 1, second = 1, tz = TIMEZONE)) last_pholus_scheduled_run = (datetime.datetime.now(tz) - timedelta(days=365)).replace(microsecond=0) + # get the current time with the currently specified timezone nowTime = datetime.datetime.now(tz).replace(microsecond=0) + # # DEBUG + # file_print("now : ", nowTime.isoformat()) + # file_print("last_pholus_scheduled_run: ", last_pholus_scheduled_run.isoformat()) + # file_print("last_next_pholus_schedule: ", last_next_pholus_schedule.isoformat()) + # file_print("nowTime > last_next_pholus_schedule: ", nowTime > last_next_pholus_schedule) + # file_print("last_pholus_scheduled_run < last_next_pholus_schedule: ", last_pholus_scheduled_run < last_next_pholus_schedule) - file_print("now : ", nowTime.isoformat(), "Type: ", type(nowTime)) - file_print("last_pholus_scheduled_run: ", last_pholus_scheduled_run.isoformat(), "Type: ", type(last_pholus_scheduled_run)) - file_print("last_next_pholus_schedule: ", last_next_pholus_schedule.isoformat(), "Type: ", type(last_next_pholus_schedule)) - - - file_print("nowTime > last_next_pholus_schedule: ", nowTime > last_next_pholus_schedule) - file_print("last_pholus_scheduled_run < last_next_pholus_schedule: ", last_pholus_scheduled_run < last_next_pholus_schedule) - - + # Run the schedule if the current time is past the schedule time we saved last time and + # (maybe the following check is unnecessary:) + # if the last run is past the last time we run a scheduled Pholus scan if nowTime > last_next_pholus_schedule and last_pholus_scheduled_run < last_next_pholus_schedule: - file_print("run: YES") + print_log("Scheduler run: YES") last_next_pholus_schedule_used = True result = True else: - file_print("run: NO") - - - - - - # file_print("last_next_pholus_schedule lastRunDateTime: ", - - # Debug - + print_log("Scheduler run: NO") if last_next_pholus_schedule_used: last_next_pholus_schedule_used = False - last_next_pholus_schedule = schedule.next() - - file_print("runSchedule n : ", last_next_pholus_schedule.isoformat()) + last_next_pholus_schedule = schedule.next() return result diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 0b09e006..874b805f 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -11,6 +11,10 @@ var timerRefreshData = '' var modalCallbackFunction = ''; +// urlParams = new Proxy(new URLSearchParams(window.location.search), { +// get: (searchParams, prop) => searchParams.get(prop.toString()), +// }); + function getCache(key) { // check cache diff --git a/front/maintenance.php b/front/maintenance.php index b394c3e2..6b788b1c 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -353,7 +353,9 @@ if (submit && isset($_POST['skinselector_set'])) {
".$config_file." file.
".$new_name."SCAN_SUBNETS setting.',
'PHOLUS_TIMEOUT_name' => 'Pholus timeout',
-'PHOLUS_TIMEOUT_description' => 'How long (s) should Pholus be sniffing the network. Only used if an (unknown) device is found. The longer you leave it on, the more likely devices would broadcast more info. This timeout adds to the time it takes to perform an arp-scan on your network',
+'PHOLUS_TIMEOUT_description' => 'How long in seconds should Pholus be sniffing on each interface. Only used if an (unknown) device is found. The longer you leave it on, the more likely devices would broadcast more info. This timeout adds to the time it takes to perform an arp-scan on your network.',
'PHOLUS_FORCE_name' => 'Force scan',
'PHOLUS_FORCE_description' => 'Force scan every network scan, even if there are no (unknown) devices. Be careful enabling this as the sniffing can easily flood your network.',
'PHOLUS_DAYS_DATA_name' => 'Data retention',
-'PHOLUS_DAYS_DATA_description' => 'How many days of Pholus scan entries should be kept (gloablly, not device specific!). The pialert_pholus.log file is not touched.',
-'PHOLUS_RUN_name' => 'Run on schedule',
-'PHOLUS_RUN_description' => 'Enable a regular Pholus scan / sniff on your network.',
+'PHOLUS_DAYS_DATA_description' => 'How many days of Pholus scan entries should be kept (globally, not device specific!). The pialert_pholus.log file is not touched.',
+'PHOLUS_RUN_name' => 'Scheduled scan',
+'PHOLUS_RUN_description' => 'Enable a regular Pholus scan / sniff on your network. The scheduling settings can be found below.',
'PHOLUS_RUN_TIMEOUT_name' => 'Scheduled run timeout',
-'PHOLUS_RUN_TIMEOUT_description' => 'The timeout (s) for the scheduled Pholus scan.',
+'PHOLUS_RUN_TIMEOUT_description' => 'The timeout in seconds for the scheduled Pholus scan. Same notes regarding the duration apply as on the PHOLUS_TIMEOUT setting. A scheduled scan doesn\'t check if there are (unknown) devices, the scan is executed either way.',
'PHOLUS_RUN_SCHD_name' => 'Schedule',
-'PHOLUS_RUN_SCHD_description' => 'Schedule in cron format. Make sure you enter the schedule in the correct format (e.g. validate your format on crontab.guru). Will be run NEXT time the time passes.',
+'PHOLUS_RUN_SCHD_description' => 'Schedule in cron format. Make sure you enter the schedule in the correct format
+(e.g. validate at crontab.guru). Will be run NEXT time the time passes. For example 0 4 * * * will run the scan after 4 am in the TIMEZONE you set above.',
);
diff --git a/front/php/templates/language/lang.php b/front/php/templates/language/lang.php
index 95fe0c75..f08894ad 100644
--- a/front/php/templates/language/lang.php
+++ b/front/php/templates/language/lang.php
@@ -4,13 +4,15 @@
// ## Languages
// ###################################
+$defaultLang = "en_us";
+
if(!isset($_COOKIE["language"])) {
- $pia_lang_selected = "en_us";
+ $pia_lang_selected = $defaultLang;
} else {
$pia_lang_selected = $_COOKIE["language"];
}
-if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
+if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = defaultLang;}
require 'en_us.php';
require 'de_de.php';
@@ -18,26 +20,28 @@ require 'es_es.php';
function lang($key)
{
- global $pia_lang_selected, $lang ;
+ global $pia_lang_selected, $lang, $defaultLang;
- // try to get the selected language translation
- $temp = $lang[$pia_lang_selected][$key];
-
- if(isset($temp) == FALSE)
- {
- // if not found, use English
- $temp = $lang[$pia_lang_selected]["en_us"];
-
- // echo $temp;
- if(isset($temp) == FALSE)
+ // check if key exists in selected language
+ if(array_key_exists($key, $lang[$pia_lang_selected]) == FALSE)
+ {
+ // check if key exists in the default language if not available in the selected
+ if (array_key_exists($key, $lang[$defaultLang]) == TRUE)
{
- // if not found, in English, use placeholder
- $temp = "String not found";
- }
- }
+ // if found, use default language
+ $temp = $lang[$defaultLang][$key];
- // echo $temp;
-
+ } else
+ {
+ // String not found in the default or selected language
+ $temp = "String not found for key: ".$key;
+ }
+ } else
+ {
+ // use selected language translation
+ $temp = $lang[$pia_lang_selected][$key];
+ }
+
return $temp;
}
?>
\ No newline at end of file
diff --git a/pholus/pholus3.py b/pholus/pholus3.py
index 20026dec..c9dc51be 100644
--- a/pholus/pholus3.py
+++ b/pholus/pholus3.py
@@ -9,18 +9,45 @@ import logging
import itertools
import codecs
import ipaddress
+import os
+import sys
from scapy.utils import PcapWriter
sys.setrecursionlimit(30000)
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)#supress Scapy warnings`
+runPath = os.path.dirname(os.path.abspath(__file__))
+runPathTmp = runPath + "/.."
+logPath = runPathTmp + '/front/log'
#===============================================================================
# UTIL
#===============================================================================
+def write_file (pPath, pText):
+ # Write the text depending using the correct python version
+ if sys.version_info < (3, 0):
+ file = io.open (pPath , mode='w', encoding='utf-8')
+ file.write ( pText.decode('unicode_escape') )
+ file.close()
+ else:
+ file = open (pPath, 'w', encoding='utf-8')
+ file.write (pText)
+ file.close()
+
+def file_print(*args):
+
+ result = ''
+
+ file = open(logPath + "/pialert_pholus_subp.log", "a")
+ for arg in args:
+ result += str(arg)
+ print(result)
+ file.write(result + '\n')
+ file.close()
+
def sanitize_string(input):
if isinstance(input, bytes):
@@ -70,7 +97,7 @@ def get_my_ipv6_addr(interface):
myip=ifaces[0]
return myip
except:
- print("The interface",interface,"does not exist. Please, try again.")
+ file_print("The interface",interface,"does not exist. Please, try again.")
exit(0)
######################################
@@ -82,7 +109,7 @@ def get_my_ipv4_addr(interface):
myip=scapy.arch.get_if_addr(interface)
return myip
except:
- print("The interface",interface,"does not exist. Please, try again.")
+ file_print("The interface",interface,"does not exist. Please, try again.")
exit(0)
##########################
@@ -271,7 +298,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
srv_rrname=data+label_data
txt_record=""
rdata=['txtvers=1','qtotal=1','pdl=application/vnd.hp-PCL','ty=MyOfficejet100000','product=(Trexa gureue)','priority=0','adminur=http://'+source_IPv4]
- #print(type(rdata))
+ #file_print(type(rdata))
for r in rdata:
length=hex(len(r))[2:]
#check http://code.activestate.com/recipes/576617-converting-arbitrary-size-python-integers-to-packe/
@@ -417,7 +444,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
qname=dnsqr.qname
if qname.endswith('.'):
qname=qname[:-1]
- #print("Query Name = ",qname," Type=",dnsqr.qtype)
+ #file_print("Query Name = ",qname," Type=",dnsqr.qtype)
if unidns:
dns_packet=UDP(sport=5353,dport=5353)/DNS(qr=1,aa=1,rd=0,ancount=1)/DNSRR(rrname=qname,ttl=myttl,rdata=source_IPv4,type="A")
else:
@@ -432,13 +459,13 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
elif dnsqr.qclass==255:
res = res0 + " | Question | "+dnsqr.qname.decode("utf-8") + " "+ dns_type[dnsqr.qtype] + " QM Class:ANY"
else:
- print("DNSQR:")
- print("-----")
- print(dnsqr.show())
- print("DEBUGGING IS NEEDED")
+ file_print("DNSQR:")
+ file_print("-----")
+ file_print(dnsqr.show())
+ file_print("DEBUGGING IS NEEDED")
exit(0)
if print_res==1:
- print(res)
+ file_print(res)
queue.put(res)
block = block.payload
if dns.arcount>0:
@@ -466,7 +493,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
optcode=str(edns0tlv.optcode)
res = res + " EDNS0TLV: " + optcode + " " + codecs.encode(edns0tlv.optdata, 'hex_codec').decode("utf-8")
if print_res==1:
- print(res)
+ file_print(res)
queue.put(res)
block = block.payload
elif block.haslayer(DNSRR):
@@ -496,10 +523,10 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
res = str_res0 + " | Question | " + str_qname + " " + str_qtype + " QM Class:ANY"
else:
- print("DNSRR:")
- print("-----")
- print(dnsrr.show())
- print("DEBUGGING IS NEEDED HERE")
+ file_print("DNSRR:")
+ file_print("-----")
+ file_print(dnsrr.show())
+ file_print("DEBUGGING IS NEEDED HERE")
exit(0)
if dnsrr.type==33:#SRV Record
@@ -531,7 +558,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
if show_ttl:
res = res + " TTL:"+str(dnsrr.ttl)
if print_res==1:
- print(res)
+ file_print(res)
queue.put(res)
block = block.payload
if dns.ancount>0:
@@ -562,7 +589,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
if show_ttl:
res = res + " TTL:"+str(dnsrr.ttl)
if print_res==1:
- print(res)
+ file_print(res)
queue.put(res)
block = block.payload
if dns.nscount>0:
@@ -579,18 +606,18 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
if show_ttl:
res = res + " TTL:"+str(dnsrr.ttl)
if print_res==1:
- print(res)
+ file_print(res)
queue.put(res)
block = block.payload
else:
- print("not a DNS Query", dns.summary())
+ file_print("not a DNS Query", dns.summary())
########################################
########### REQUEST FUNCTION ###########
########################################
def requests(interface,v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,source_IPv6,d4,d6,hlimit,unidns,domain,query,types_of_queries,add_domain,query_class,flood,flooding_interval,flooding_timeout):
if add_domain:
- print("Sending mdns requests")
+ file_print("Sending mdns requests")
domain_list = domain.split(",")
query_list = query.split(",")
if add_domain:
@@ -630,7 +657,7 @@ def send_packets(v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,dst_ipv4,s
packets.append(pkt1)
if flood:
counter=0.0
- print("Stop flooding after ",flooding_timeout," sec.")
+ file_print("Stop flooding after ",flooding_timeout," sec.")
while(counter