Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web UI don't exit if unable to read remote website config #2547

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions html/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<div style='color: red; font-size: 200%;'>";
echo "$errorMsg:";
echo "<br>File '$file' missing!";
echo "</div>";
$retMsg = "<div style='color: red; font-size: 200%;'>";
$retMsg .= "$errorMsg";
$retMsg .= "<br>File '$file' missing!";
$retMsg .= "</div>";
if ($returnedMsg === null) echo "$retMsg";
else $returnedMsg = $retMsg;
return null;
}

$str = file_get_contents($file, true);
if ($str === "") {
echo "<div style='color: red; font-size: 200%;'>";
echo "$errorMsg:";
echo "<br>File '$file' is empty!";
echo "</div>";
$retMsg = "<div style='color: red; font-size: 200%;'>";
$retMsg .= "$errorMsg";
$retMsg .= "<br>File '$file' is empty!";
$retMsg .= "</div>";
if ($returnedMsg === null) echo "$retMsg";
else $returnedMsg = $retMsg;
return null;
} else if ($str === false) {
$retMsg = "<div style='color: red; font-size: 200%;'>";
$retMsg .= "$errorMsg:";
$retMsg .= "<br>Error reading '$file'!";
$retMsg .= "</div>";
if ($returnedMsg === null) echo "$retMsg";
else $returnedMsg = $retMsg;
return null;
}

$str_array = json_decode($str, $associative);
if ($str_array == null) {
echo "<div style='color: red; font-size: 200%;'>";
echo "$errorMsg:";
echo "<br>" . json_last_error_msg();
$retMsg = "<div style='color: red; font-size: 200%;'>";
$retMsg .= "$errorMsg";
$retMsg .= "<br>" . json_last_error_msg();
$cmd = "json_pp < $file 2>&1";
exec($cmd, $output);
echo "<br>" . implode("<br>", $output);
echo "</div>";
$retMsg .= "<br>" . implode("<br>", $output);
$retMsg .= "</div>";
if ($returnedMsg === null) echo "$retMsg";
else $returnedMsg = $retMsg;
return null;
}
return $str_array;
Expand Down
13 changes: 8 additions & 5 deletions html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<span class="errorMsg">[unknown]</span>');
}
$c = getVariableOrDefault($a_array, 'config', '');
$remoteWebsiteVersion = getVariableOrDefault($c, 'AllskyWebsiteVersion', '<span class="errorMsg">[unknown]</span>');
}
?>

Expand Down