From f70bb40ef4b77ad2abb653560e61a9e9d9215527 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sun, 19 Jan 2025 13:41:48 +1100 Subject: [PATCH] INTERNET ip check curl #937 --- front/css/app.css | 4 ++++ front/js/common.js | 2 -- front/php/templates/header.php | 2 +- front/plugins/internet_ip/script.py | 34 ++++++++++++++++++++++++----- server/initialise.py | 2 +- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/front/css/app.css b/front/css/app.css index f2e89d99..524a03a4 100755 --- a/front/css/app.css +++ b/front/css/app.css @@ -1460,6 +1460,10 @@ input[readonly] { } /* #panDetails .dataTables_wrapper .bottom .paging_simple_numbers */ +#panDetails #NEWDEV_devIcon +{ + display: none; +} #panDetails #NEWDEV_devCustomProps_label { diff --git a/front/js/common.js b/front/js/common.js index f0314f02..ebe2a936 100755 --- a/front/js/common.js +++ b/front/js/common.js @@ -463,8 +463,6 @@ function utf8ToBase64(str) { // General utilities // ----------------------------------------------------------------------------- - - // check if JSON object function isJsonObject(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); diff --git a/front/php/templates/header.php b/front/php/templates/header.php index 667d10a7..756ab493 100755 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -209,7 +209,7 @@
  • - 🔃 +
  • diff --git a/front/plugins/internet_ip/script.py b/front/plugins/internet_ip/script.py index 58e47852..73579058 100755 --- a/front/plugins/internet_ip/script.py +++ b/front/plugins/internet_ip/script.py @@ -38,7 +38,6 @@ LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') - no_internet_ip = '0.0.0.0' def main(): @@ -55,10 +54,13 @@ def main(): PREV_IP = values.prev_ip.split('=')[1] DIG_GET_IP_ARG = get_setting_value("INTRNT_DIG_GET_IP_ARG") + new_internet_IP = no_internet_ip + mylog('verbose', [f'[{pluginName}] INTRNT_DIG_GET_IP_ARG: ', DIG_GET_IP_ARG]) + # METHOD 1: dig # perform the new IP lookup N times specified by the INTRNT_TRIES setting - new_internet_IP = "" + INTRNT_RETRIES = get_setting_value("INTRNT_RETRIES") retries_needed = 0 @@ -66,12 +68,22 @@ def main(): new_internet_IP, cmd_output = check_internet_IP( PREV_IP, DIG_GET_IP_ARG) + #todo: use `curl ifconfig.me/ip` if above fails + if new_internet_IP == no_internet_ip: time.sleep(1*i) # Exponential backoff strategy else: retries_needed = i break + # METHOD 2: curl + if new_internet_IP == no_internet_ip: + new_internet_IP, cmd_output = fallback_check_ip() + mylog('verbose', [f'[{pluginName}] Curl Fallback (new_internet_IP|cmd_output): {new_internet_IP} | {cmd_output}']) + + # logging + append_line_to_file (logPath + '/IP_changes.log', '['+str(timeNowTZ()) +']\t'+ new_internet_IP +'\n') + plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects.add_object( @@ -110,9 +122,6 @@ def check_internet_IP ( PREV_IP, DIG_GET_IP_ARG ): mylog('verbose', [f'[{pluginName}] previous_IP : {previous_IP}']) - # logging - append_line_to_file (logPath + '/IP_changes.log', '['+str(timeNowTZ()) +']\t'+ internet_IP +'\n') - return internet_IP, cmd_output @@ -139,6 +148,21 @@ def get_internet_IP (DIG_GET_IP_ARG): return IP, cmd_output +#------------------------------------------------------------------------------- +def fallback_check_ip(): + """Fallback mechanism using `curl ifconfig.me/ip`.""" + try: + cmd_output = subprocess.check_output(['curl', '-s', 'ifconfig.me/ip'], text=True).strip() + if cmd_output and re.match(r"^\d{1,3}(\.\d{1,3}){3}$", cmd_output): + mylog('verbose', [f'[{pluginName}] Fallback IP retrieved via curl: {cmd_output}']) + return cmd_output, f'Fallback via curl: "{cmd_output}"' + else: + mylog('verbose', [f'[{pluginName}] Invalid IP received from fallback']) + return no_internet_ip, f'Fallback via curl failed: "{cmd_output}"' + except Exception as e: + mylog('none', [f'[{pluginName}] Fallback curl exception: {e}']) + return no_internet_ip, f'Fallback via curl exception: "{e}"' + #=============================================================================== # BEGIN #=============================================================================== diff --git a/server/initialise.py b/server/initialise.py index f9fbe6c7..6f3abdea 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -376,7 +376,7 @@ def importConfigs (db, all_plugins): # ccd(key, default, config_dir, name, inputtype, options, group, events=None, desc="", setJsonMetadata=None, overrideTemplate=None, forceDefault=False) ccd('VERSION', buildTimestamp , c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", None, None, True) - write_notification(f'[Upgrade] : App upgraded 🚀 Please clear the cache:
    1. Click OK below
    2. Clear the browser cache (shift + browser refresh button)
    3. Clear app cache with the 🔄 (reload) button in the header
    4. Go to Settings and click Save
    Check out new features and what has changed in the 📓 release notes.', 'interrupt', timeNowTZ()) + write_notification(f'[Upgrade] : App upgraded 🚀 Please clear the cache:
    1. Click OK below
    2. Clear the browser cache (shift + browser refresh button)
    3. Clear app cache with the (reload) button in the header
    4. Go to Settings and click Save
    Check out new features and what has changed in the 📓 release notes.', 'interrupt', timeNowTZ())