diff --git a/html/includes/functions.php b/html/includes/functions.php index 89471abf1..e77024132 100644 --- a/html/includes/functions.php +++ b/html/includes/functions.php @@ -23,33 +23,47 @@ // Read and decode a json file, returning the decoded results or null. // On error, display the specified error message -function get_decoded_json_file($file, $associative, $errorMsg) { +function get_decoded_json_file($file, $associative, $errorMsg, &$returnedMsg=null) { if (! file_exists($file)) { - echo "
"; - echo "$errorMsg:"; - echo "
File '$file' missing!"; - echo "
"; + $retMsg = "
"; + $retMsg .= "$errorMsg"; + $retMsg .= "
File '$file' missing!"; + $retMsg .= "
"; + if ($returnedMsg === null) echo "$retMsg"; + else $returnedMsg = $retMsg; return null; } $str = file_get_contents($file, true); if ($str === "") { - echo "
"; - echo "$errorMsg:"; - echo "
File '$file' is empty!"; - echo "
"; + $retMsg = "
"; + $retMsg .= "$errorMsg"; + $retMsg .= "
File '$file' is empty!"; + $retMsg .= "
"; + if ($returnedMsg === null) echo "$retMsg"; + else $returnedMsg = $retMsg; + return null; + } else if ($str === false) { + $retMsg = "
"; + $retMsg .= "$errorMsg:"; + $retMsg .= "
Error reading '$file'!"; + $retMsg .= "
"; + if ($returnedMsg === null) echo "$retMsg"; + else $returnedMsg = $retMsg; return null; } $str_array = json_decode($str, $associative); if ($str_array == null) { - echo "
"; - echo "$errorMsg:"; - echo "
" . json_last_error_msg(); + $retMsg = "
"; + $retMsg .= "$errorMsg"; + $retMsg .= "
" . json_last_error_msg(); $cmd = "json_pp < $file 2>&1"; exec($cmd, $output); - echo "
" . implode("
", $output); - echo "
"; + $retMsg .= "
" . implode("
", $output); + $retMsg .= "
"; + if ($returnedMsg === null) echo "$retMsg"; + else $returnedMsg = $retMsg; return null; } return $str_array; diff --git a/html/index.php b/html/index.php index d3853323b..be6f9e714 100644 --- a/html/index.php +++ b/html/index.php @@ -107,13 +107,16 @@ function SaveTORAndVPNConfig() {} $remoteWebsiteVersion = ""; $f = ALLSKY_WEBSITE_REMOTE_CONFIG; if (file_exists($f)) { - $errorMsg = "ERROR: Unable to process '$f'."; - $a_array = get_decoded_json_file($f, true, $errorMsg); + $errorMsg = "WARNING: Unable to process '$f'."; + $retMsg = ""; + $a_array = get_decoded_json_file($f, true, $errorMsg, $retMsg); if ($a_array === null) { - exit; + echo "$retMsg"; + } else { + $c = getVariableOrDefault($a_array, 'config', ''); + if ($c !== "") + $remoteWebsiteVersion = getVariableOrDefault($c, 'AllskyWebsiteVersion', '[unknown]'); } - $c = getVariableOrDefault($a_array, 'config', ''); - $remoteWebsiteVersion = getVariableOrDefault($c, 'AllskyWebsiteVersion', '[unknown]'); } ?>