diff --git a/docs/REVERSE_PROXY.md b/docs/REVERSE_PROXY.md new file mode 100755 index 00000000..667bef05 --- /dev/null +++ b/docs/REVERSE_PROXY.md @@ -0,0 +1,41 @@ +## Reverse proxy configuration + +Submitted by [s33d1ing](https://github.com/s33d1ing). + + +Reverse proxy example by using LinuxServer's SWAG container. + +### nginx config + + +``` nginx +location /pialert { + return 301 $scheme://$host/pialert/; +} + +location ^~ /pialert/ { + include /config/nginx/proxy.conf; + include /config/nginx/resolver.conf; + + set $upstream_app pialert; + set $upstream_port 20211; + set $upstream_proto http; + + proxy_pass $upstream_proto://$upstream_app:$upstream_port; + proxy_set_header Accept-Encoding ""; + + proxy_redirect ~^/(.*)$ /pialert/$1; + rewrite ^/pialert/?(.*)$ /$1 break; + + sub_filter_once off; + sub_filter_types *; + + sub_filter 'href="/' 'href="/pialert/'; + + sub_filter '(?>$host)/css' '/pialert/css'; + sub_filter '(?>$host)/img' '/pialert/img'; + sub_filter '(?>$host)/js' '/pialert/js'; + sub_filter '(?>$host)/lib' '/pialert/lib'; + sub_filter '(?>$host)/php' '/pialert/php'; +} +``` \ No newline at end of file diff --git a/pialert/helper.py b/pialert/helper.py index 58006d15..05d710c0 100755 --- a/pialert/helper.py +++ b/pialert/helper.py @@ -302,17 +302,26 @@ def get_file_content(path): return content #------------------------------------------------------------------------------- -def write_file (pPath, pText): - # Write the text depending using the correct python version +def write_file(pPath, pText): + # Convert pText to a string if it's a dictionary + if isinstance(pText, dict): + pText = json.dumps(pText) + + # Convert pText to a string if it's a list + if isinstance(pText, list): + for item in pText: + write_file(pPath, item) + + # Write the text 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 = 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 = open(pPath, 'w', encoding='utf-8') if pText is None: pText = "" - file.write (pText) + file.write(pText) file.close() #------------------------------------------------------------------------------- diff --git a/pialert/initialise.py b/pialert/initialise.py index 61f12078..33cbbaf2 100755 --- a/pialert/initialise.py +++ b/pialert/initialise.py @@ -144,7 +144,7 @@ def importConfigs (db): conf.PHOLUS_ACTIVE = ccd('PHOLUS_ACTIVE', False , c_d, 'Enable Pholus scans', 'boolean', '', 'Pholus') conf.PHOLUS_TIMEOUT = ccd('PHOLUS_TIMEOUT', 20 , c_d, 'Pholus timeout', 'integer', '', 'Pholus') conf.PHOLUS_FORCE = ccd('PHOLUS_FORCE', False , c_d, 'Pholus force check', 'boolean', '', 'Pholus') - conf.PHOLUS_RUN = ccd('PHOLUS_RUN', 'once' , c_d, 'Pholus enable schedule', 'selecttext', "['none', 'once', 'schedule']", 'Pholus') + conf.PHOLUS_RUN = ccd('PHOLUS_RUN', 'once' , c_d, 'Pholus enable schedule', 'selecttext', "['disabled', 'once', 'schedule']", 'Pholus') conf.PHOLUS_RUN_TIMEOUT = ccd('PHOLUS_RUN_TIMEOUT', 600 , c_d, 'Pholus timeout schedule', 'integer', '', 'Pholus') conf.PHOLUS_RUN_SCHD = ccd('PHOLUS_RUN_SCHD', '0 4 * * *' , c_d, 'Pholus schedule', 'text', '', 'Pholus') conf.PHOLUS_DAYS_DATA = ccd('PHOLUS_DAYS_DATA', 0 , c_d, 'Pholus keep days', 'integer', '', 'Pholus') @@ -152,7 +152,7 @@ def importConfigs (db): # Nmap conf.NMAP_ACTIVE = ccd('NMAP_ACTIVE', True , c_d, 'Enable Nmap scans', 'boolean', '', 'Nmap') conf.NMAP_TIMEOUT = ccd('NMAP_TIMEOUT', 150 , c_d, 'Nmap timeout', 'integer', '', 'Nmap') - conf.NMAP_RUN = ccd('NMAP_RUN', 'none' , c_d, 'Nmap enable schedule', 'selecttext', "['none', 'once', 'schedule']", 'Nmap') + conf.NMAP_RUN = ccd('NMAP_RUN', 'disabled' , c_d, 'Nmap enable schedule', 'selecttext', "['disabled', 'once', 'schedule']", 'Nmap') conf.NMAP_RUN_SCHD = ccd('NMAP_RUN_SCHD', '0 2 * * *' , c_d, 'Nmap schedule', 'text', '', 'Nmap') conf.NMAP_ARGS = ccd('NMAP_ARGS', '-p -10000' , c_d, 'Nmap custom arguments', 'text', '', 'Nmap') diff --git a/pialert/publishers/webhook.py b/pialert/publishers/webhook.py index d575dfb5..56f80283 100755 --- a/pialert/publishers/webhook.py +++ b/pialert/publishers/webhook.py @@ -60,7 +60,7 @@ def send (msg: noti_struc): logResult (stdout, stderr) # TO-DO should be changed to mylog except subprocess.CalledProcessError as e: # An error occured, handle it - mylog('none', ['[send_webhook]', e.output]) + mylog('none', ['[send_webhook] Error', e.output]) diff --git a/pialert/reporting.py b/pialert/reporting.py index d6c94c2c..c3f6abaa 100755 --- a/pialert/reporting.py +++ b/pialert/reporting.py @@ -271,7 +271,7 @@ def send_notifications (db): msg = noti_struc(json_final, mail_text, mail_html) - mylog('info', ['[Notification] Udateing API files']) + mylog('info', ['[Notification] Udating API files']) send_api() if conf.REPORT_MAIL and check_config('email'): diff --git a/pialert/scanners/pholusscan.py b/pialert/scanners/pholusscan.py index 17fc3a64..8a31946d 100755 --- a/pialert/scanners/pholusscan.py +++ b/pialert/scanners/pholusscan.py @@ -85,7 +85,7 @@ def cleanResult(str): if str.endswith('.'): str = str[:-1] - return str(str) + return str # Disclaimer - I'm interfacing with a script I didn't write (pholus3.py) so it's possible I'm missing types of answers @@ -157,7 +157,8 @@ def resolve_device_name_pholus (pMAC, pIP, allRes): # _esphomelib._tcp.local. PTR Class:IN "ceiling-light-1._esphomelib._tcp.local." for i in pholusMatchesIndexes: if checkIPV4(allRes[i]['IP_v4_or_v6']) and 'PTR Class:IN' in allRes[i]["Value"]: - return cleanResult(allRes[i]["Value"].split('"')[1]) + if allRes[i]["Value"] and len(allRes[i]["Value"].split('"')) > 1: + return cleanResult(allRes[i]["Value"].split('"')[1]) return -1