mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
INTERNET ip check curl #937
This commit is contained in:
@@ -1460,6 +1460,10 @@ input[readonly] {
|
|||||||
}
|
}
|
||||||
/* #panDetails .dataTables_wrapper .bottom .paging_simple_numbers */
|
/* #panDetails .dataTables_wrapper .bottom .paging_simple_numbers */
|
||||||
|
|
||||||
|
#panDetails #NEWDEV_devIcon
|
||||||
|
{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
#panDetails #NEWDEV_devCustomProps_label
|
#panDetails #NEWDEV_devCustomProps_label
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -463,8 +463,6 @@ function utf8ToBase64(str) {
|
|||||||
// General utilities
|
// General utilities
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// check if JSON object
|
// check if JSON object
|
||||||
function isJsonObject(value) {
|
function isJsonObject(value) {
|
||||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
|||||||
@@ -209,7 +209,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<!-- Clear cache & Reload -->
|
<!-- Clear cache & Reload -->
|
||||||
<li>
|
<li>
|
||||||
<a id="reload-button" href='#' role="button" span onclick='clearCache()'>🔃</a>
|
<a id="reload-button" href='#' role="button" span onclick='clearCache()' class='fa-solid fa-rotate'></a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Full Screen -->
|
<!-- Full Screen -->
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -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')
|
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
no_internet_ip = '0.0.0.0'
|
no_internet_ip = '0.0.0.0'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -55,10 +54,13 @@ def main():
|
|||||||
PREV_IP = values.prev_ip.split('=')[1]
|
PREV_IP = values.prev_ip.split('=')[1]
|
||||||
DIG_GET_IP_ARG = get_setting_value("INTRNT_DIG_GET_IP_ARG")
|
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])
|
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
|
# perform the new IP lookup N times specified by the INTRNT_TRIES setting
|
||||||
new_internet_IP = ""
|
|
||||||
INTRNT_RETRIES = get_setting_value("INTRNT_RETRIES")
|
INTRNT_RETRIES = get_setting_value("INTRNT_RETRIES")
|
||||||
retries_needed = 0
|
retries_needed = 0
|
||||||
|
|
||||||
@@ -66,12 +68,22 @@ def main():
|
|||||||
|
|
||||||
new_internet_IP, cmd_output = check_internet_IP( PREV_IP, DIG_GET_IP_ARG)
|
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:
|
if new_internet_IP == no_internet_ip:
|
||||||
time.sleep(1*i) # Exponential backoff strategy
|
time.sleep(1*i) # Exponential backoff strategy
|
||||||
else:
|
else:
|
||||||
retries_needed = i
|
retries_needed = i
|
||||||
break
|
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 = Plugin_Objects(RESULT_FILE)
|
||||||
|
|
||||||
plugin_objects.add_object(
|
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}'])
|
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
|
return internet_IP, cmd_output
|
||||||
|
|
||||||
|
|
||||||
@@ -139,6 +148,21 @@ def get_internet_IP (DIG_GET_IP_ARG):
|
|||||||
|
|
||||||
return IP, cmd_output
|
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
|
# BEGIN
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|||||||
@@ -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(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)
|
ccd('VERSION', buildTimestamp , c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", None, None, True)
|
||||||
|
|
||||||
write_notification(f'[Upgrade] : App upgraded 🚀 Please clear the cache: <ol> <li>Click OK below</li> <li>Clear the browser cache (shift + browser refresh button)</li> <li> Clear app cache with the 🔄 (reload) button in the header</li><li>Go to Settings and click Save</li> </ol> Check out new features and what has changed in the <a href="https://github.com/jokob-sk/NetAlertX/releases" target="_blank">📓 release notes</a>.', 'interrupt', timeNowTZ())
|
write_notification(f'[Upgrade] : App upgraded 🚀 Please clear the cache: <ol> <li>Click OK below</li> <li>Clear the browser cache (shift + browser refresh button)</li> <li> Clear app cache with the <i class="fa-solid fa-rotate"></i> (reload) button in the header</li><li>Go to Settings and click Save</li> </ol> Check out new features and what has changed in the <a href="https://github.com/jokob-sk/NetAlertX/releases" target="_blank">📓 release notes</a>.', 'interrupt', timeNowTZ())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user