Revert "Handle write errors semi-gracefully"

This reverts commit 8dcbf1d462.
This commit is contained in:
Squidly271 2022-12-16 11:07:46 -05:00
parent 8dcbf1d462
commit 8b404c89d9
7 changed files with 35 additions and 57 deletions

View File

@ -2,9 +2,9 @@
4e55f7483b661af21a25b677179baffe ./CA_notices.page 4e55f7483b661af21a25b677179baffe ./CA_notices.page
600469ce287cb1ed78dc6cc11675cfaf ./ca_settings.page 600469ce287cb1ed78dc6cc11675cfaf ./ca_settings.page
e8d29607ec792ddf9f6832b10ee70fdc ./default.cfg e8d29607ec792ddf9f6832b10ee70fdc ./default.cfg
9ffd40aedffad25c998e947faf169ad3 ./include/exec.php 29f110f50c87f9e8285aca289bce6e57 ./include/exec.php
3a1e5abf962bd5700e286a48c941b2c9 ./include/helpers.php 8cb18002feb91c9eb07811a75aabb7b5 ./include/helpers.php
8d15446d4edf60a1f4ac4493a494a301 ./include/paths.php 116042a918060278e77379b0dd73482c ./include/paths.php
532fffdf939594c143e679da02bd841e ./javascript/libraries.js 532fffdf939594c143e679da02bd841e ./javascript/libraries.js
71f911a818d88d3d567f8a2898094ee2 ./README.md 71f911a818d88d3d567f8a2898094ee2 ./README.md
ebb6450725d05c53116c3c996b6abac1 ./scripts/checkForUpdates.php ebb6450725d05c53116c3c996b6abac1 ./scripts/checkForUpdates.php

View File

@ -6,6 +6,7 @@
# # # #
############################################################### ###############################################################
error_reporting(E_ALL);
ini_set('log_errors',TRUE); ini_set('log_errors',TRUE);
ini_set('error_log',"/tmp/php"); ini_set('error_log',"/tmp/php");
ini_set('memory_limit','256M'); // REQUIRED LINE ini_set('memory_limit','256M'); // REQUIRED LINE
@ -211,7 +212,6 @@ switch ($_POST['action']) {
function DownloadApplicationFeed() { function DownloadApplicationFeed() {
global $caPaths, $caSettings, $statistics; global $caPaths, $caSettings, $statistics;
$lastUpdated = [];
$info = readJsonFile($caPaths['info']); $info = readJsonFile($caPaths['info']);
exec("rm -rf '{$caPaths['tempFiles']}'"); exec("rm -rf '{$caPaths['tempFiles']}'");
@mkdir($caPaths['templates-community'],0777,true); @mkdir($caPaths['templates-community'],0777,true);
@ -227,10 +227,10 @@ function DownloadApplicationFeed() {
@unlink($downloadURL); @unlink($downloadURL);
if ( ! is_array($ApplicationFeed['applist']) ) { if ( ! is_array($ApplicationFeed['applist']) ) {
@unlink($caPaths['currentServer']); @unlink($caPaths['currentServer']);
ca_file_put_contents($caPaths['appFeedDownloadError'],$downloadURL); file_put_contents($caPaths['appFeedDownloadError'],$downloadURL);
return false; return false;
} }
ca_file_put_contents($caPaths['currentServer'],$currentFeed); file_put_contents($caPaths['currentServer'],$currentFeed);
$i = 0; $i = 0;
$lastUpdated['last_updated_timestamp'] = $ApplicationFeed['last_updated_timestamp']; $lastUpdated['last_updated_timestamp'] = $ApplicationFeed['last_updated_timestamp'];
writeJsonFile($caPaths['lastUpdated-old'],$lastUpdated); writeJsonFile($caPaths['lastUpdated-old'],$lastUpdated);
@ -406,7 +406,6 @@ function DownloadApplicationFeed() {
writeJsonFile($caPaths['extraDeprecated'],$ApplicationFeed['deprecated']); writeJsonFile($caPaths['extraDeprecated'],$ApplicationFeed['deprecated']);
updatePluginSupport($myTemplates); updatePluginSupport($myTemplates);
touch($caPaths['haveTemplates']);
return true; return true;
} }
@ -438,7 +437,7 @@ function updatePluginSupport($templates) {
$dom->preserveWhiteSpace = false; $dom->preserveWhiteSpace = false;
$dom->formatOutput = true; $dom->formatOutput = true;
$dom->loadXML($xml->asXML()); $dom->loadXML($xml->asXML());
ca_file_put_contents($plugin, $dom->saveXML()); file_put_contents($plugin, $dom->saveXML());
} }
} }
} }
@ -734,7 +733,7 @@ function get_content() {
if ( !$filter && $category === "/NONE/i" ) { if ( !$filter && $category === "/NONE/i" ) {
getConvertedTemplates(); // Only scan for private XMLs when going HOME getConvertedTemplates(); // Only scan for private XMLs when going HOME
ca_file_put_contents($caPaths['startupDisplayed'],"startup"); file_put_contents($caPaths['startupDisplayed'],"startup");
$displayApplications = []; $displayApplications = [];
$displayApplications['community'] = []; $displayApplications['community'] = [];
if ( count($file) > 200) { if ( count($file) > 200) {
@ -969,24 +968,28 @@ function force_update() {
global $caPaths; global $caPaths;
$lastUpdatedOld = readJsonFile($caPaths['lastUpdated-old']); $lastUpdatedOld = readJsonFile($caPaths['lastUpdated-old']);
debug("old feed timestamp: {$lastUpdatedOld['last_updated_timestamp']}");
@unlink($caPaths['lastUpdated']); @unlink($caPaths['lastUpdated']);
$latestUpdate = download_json($caPaths['application-feed-last-updated'],$caPaths['lastUpdated'],"",5); $latestUpdate = download_json($caPaths['application-feed-last-updated'],$caPaths['lastUpdated'],"",5);
if ( ! $latestUpdate['last_updated_timestamp'] ) if ( ! $latestUpdate['last_updated_timestamp'] )
$latestUpdate = download_json($caPaths['application-feed-last-updatedBackup'],$caPaths['lastUpdated'],"",5); $latestUpdate = download_json($caPaths['application-feed-last-updatedBackup'],$caPaths['lastUpdated'],"",5);
debug("new appfeed timestamp: {$latestUpdate['last_updated_timestamp']}");
if ( ! isset($latestUpdate['last_updated_timestamp']) ) { if ( ! isset($latestUpdate['last_updated_timestamp']) ) {
$latestUpdate['last_updated_timestamp'] = INF; $latestUpdate['last_updated_timestamp'] = INF;
$badDownload = true; $badDownload = true;
@unlink($caPaths['lastUpdated']); @unlink($caPaths['lastUpdated']);
} }
if ( ($latestUpdate['last_updated_timestamp'] ?? 0) != ($lastUpdatedOld['last_updated_timestamp'] ?? 0) ) { if ( $latestUpdate['last_updated_timestamp'] ?? 0 > $lastUpdatedOld['last_updated_timestamp'] ?? 0) {
/* if ( $latestUpdate['last_updated_timestamp'] != INF ) if ( $latestUpdate['last_updated_timestamp'] != INF )
copy($caPaths['lastUpdated'],$caPaths['lastUpdated-old']); */ copy($caPaths['lastUpdated'],$caPaths['lastUpdated-old']);
exec("rm -rf '{$caPaths['tempFiles']}'"); if (isset($badDownload)) {
$GLOBALS['templates'] = []; if ( ! $badDownload ) {
@unlink($caPaths['community-templates-info']);
$GLOBALS['templates'] = [];
}
}
} }
if (!file_exists($caPaths['community-templates-info']) || ! $GLOBALS['templates']) { if (!file_exists($caPaths['community-templates-info']) || ! $GLOBALS['templates']) {
@ -1048,13 +1051,13 @@ function display_content() {
function dismiss_warning() { function dismiss_warning() {
global $caPaths; global $caPaths;
ca_file_put_contents($caPaths['warningAccepted'],"warning dismissed"); file_put_contents($caPaths['warningAccepted'],"warning dismissed");
postReturn(['status'=>"warning dismissed"]); postReturn(['status'=>"warning dismissed"]);
} }
function dismiss_plugin_warning() { function dismiss_plugin_warning() {
global $caPaths; global $caPaths;
ca_file_put_contents($caPaths['pluginWarning'],"disclaimer ok"); file_put_contents($caPaths['pluginWarning'],"disclaimer ok");
postReturn(['status'=>"disclaimed"]); postReturn(['status'=>"disclaimed"]);
} }
@ -1984,7 +1987,7 @@ function createXML() {
} }
$xml = makeXML($template); $xml = makeXML($template);
@mkdir(dirname($xmlFile)); @mkdir(dirname($xmlFile));
ca_file_put_contents($xmlFile,$xml); file_put_contents($xmlFile,$xml);
} }
postReturn(["status"=>"ok","cache"=>$cacheVolume ?? ""]); postReturn(["status"=>"ok","cache"=>$cacheVolume ?? ""]);
} }
@ -2188,7 +2191,7 @@ function convert_docker() {
$dockerXML = makeXML($dockerfile); $dockerXML = makeXML($dockerfile);
ca_file_put_contents($caPaths['dockerSearchInstall'],$dockerXML); file_put_contents($caPaths['dockerSearchInstall'],$dockerXML);
postReturn(['xml'=>$caPaths['dockerSearchInstall']]); postReturn(['xml'=>$caPaths['dockerSearchInstall']]);
} }
@ -2328,7 +2331,7 @@ function enableActionCentre() {
global $caPaths, $caSettings, $DockerClient; global $caPaths, $caSettings, $DockerClient;
# wait til check for updates is finished # wait til check for updates is finished
for ( $i=0;$i<100;$i++ ) { for ( ;; ) {
if ( is_file($caPaths['updateRunning']) && file_exists("/proc/".@file_get_contents($caPaths['updateRunning'])) ) { if ( is_file($caPaths['updateRunning']) && file_exists("/proc/".@file_get_contents($caPaths['updateRunning'])) ) {
debug("Action Centre sleeping -> update running"); debug("Action Centre sleeping -> update running");
sleep(5); sleep(5);
@ -2336,15 +2339,10 @@ function enableActionCentre() {
} }
else break; else break;
} }
if ( $i >= 100 ) {
debug("Something went wrong. EnableActionCentre ran longer than 500 seconds");
postReturn(['status'=>"noaction"]);
return;
}
# wait til templates are downloaded
for ( $i=0;$i<100;$i++ ) {
$file = readJsonFile($caPaths['community-templates-info']);
# wait til templates are downloaded
for ( ;; ) {
$file = &$GLOBALS['templates'];
if ( ! $file || empty($file) ) { if ( ! $file || empty($file) ) {
debug("Action Centre sleeping - no templates yet"); debug("Action Centre sleeping - no templates yet");
sleep(5); sleep(5);
@ -2353,12 +2351,6 @@ function enableActionCentre() {
break; break;
} }
} }
if ( $i >= 100 ) {
debug("Something went wrong. EnableActionCentre ran longer than 500 seconds");
postReturn(['status'=>"noaction"]);
return;
}
$extraBlacklist = readJsonFile($caPaths['extraBlacklist']); $extraBlacklist = readJsonFile($caPaths['extraBlacklist']);
$extraDeprecated = readJsonFile($caPaths['extraDeprecated']); $extraDeprecated = readJsonFile($caPaths['extraDeprecated']);

View File

@ -60,17 +60,12 @@ function writeJsonFile($filename,$jsonArray) {
debug("Write JSON File $filename"); debug("Write JSON File $filename");
ca_file_put_contents($filename,json_encode($jsonArray, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); $result = file_put_contents($filename,json_encode($jsonArray, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
debug("Memory Usage:".round(memory_get_usage()/1048576,2)." MB"); debug("Memory Usage:".round(memory_get_usage()/1048576,2)." MB");
}
function ca_file_put_contents($filename,$data,$flags = null) { if ( ! $result )
$result = @file_put_contents($filename,$data,$flags); debug("Write error $filename");
if ($result === false) {
debug("Unable to write to $filename");
$GLOBALS['script'] = "alert('Error writing to ".htmlentities($filename,ENT_QUOTES)."');";
}
} }
function download_url($url, $path = "", $bg = false, $timeout = 45) { function download_url($url, $path = "", $bg = false, $timeout = 45) {
@ -99,7 +94,7 @@ function download_url($url, $path = "", $bg = false, $timeout = 45) {
$out = curl_exec($ch); $out = curl_exec($ch);
curl_close($ch); curl_close($ch);
if ( $path ) if ( $path )
ca_file_put_contents($path,$out); file_put_contents($path,$out);
$totalTime = time() - $startTime; $totalTime = time() - $startTime;
debug("DOWNLOAD $url Time: $totalTime RESULT:\n".var_dump_ret($out)); debug("DOWNLOAD $url Time: $totalTime RESULT:\n".var_dump_ret($out));
@ -328,7 +323,7 @@ function versionCheck($template) {
function readXmlFile($xmlfile,$generic=false,$stats=true) { function readXmlFile($xmlfile,$generic=false,$stats=true) {
global $statistics; global $statistics;
if ( ! $xmlfile || ! is_file($xmlfile) ) return false; if ( $xmlfile && ! is_file($xmlfile) ) return false;
$xml = file_get_contents($xmlfile); $xml = file_get_contents($xmlfile);
$o = TypeConverter::xmlToArray($xml,TypeConverter::XML_GROUP); $o = TypeConverter::xmlToArray($xml,TypeConverter::XML_GROUP);
$o = addMissingVars($o); $o = addMissingVars($o);
@ -439,7 +434,6 @@ function pluginDupe() {
function checkInstalledPlugin($template) { function checkInstalledPlugin($template) {
global $caPaths; global $caPaths;
debug("checkInstalledPlugin $template");
$pluginName = basename($template['PluginURL']); $pluginName = basename($template['PluginURL']);
if ( ! file_exists("/var/log/plugins/$pluginName") ) return false; if ( ! file_exists("/var/log/plugins/$pluginName") ) return false;
$dupeList = readJsonFile($caPaths['pluginDupes']); $dupeList = readJsonFile($caPaths['pluginDupes']);
@ -580,13 +574,6 @@ function formatTags($leadTemplate,$rename="false") {
function postReturn($retArray) { function postReturn($retArray) {
global $caSettings, $caPaths; global $caSettings, $caPaths;
if ( isset($_GLOBALS['script']) ) {
if ( is_array($retArray) ) {
$retArray['script'] = $retArray['script'] ?? null;
$retArray['script'] .= $_GLOBALS['script'];
}
}
if (is_array($retArray)) if (is_array($retArray))
echo json_encode($retArray); echo json_encode($retArray);
else else
@ -649,7 +636,7 @@ function write_ini_file($file,$array) {
else else
$res[] = $key.'="'.$val.'"'; $res[] = $key.'="'.$val.'"';
} }
ca_file_put_contents($file,implode("\r\n", $res),LOCK_EX); file_put_contents($file,implode("\r\n", $res),LOCK_EX);
} }
################################################### ###################################################
# Gets all the information about what's installed # # Gets all the information about what's installed #
@ -659,7 +646,7 @@ function getAllInfo($force=false) {
$containers = []; $containers = [];
if ( $force ) { if ( $force ) {
if ( $caSettings['dockerRunning'] ) { if ( $caSettings['dockerRunning'] ?? false ) {
$info = $DockerTemplates->getAllInfo(false,true,true); $info = $DockerTemplates->getAllInfo(false,true,true);
$containers = $DockerClient->getDockerContainers(); $containers = $DockerClient->getDockerContainers();
foreach ($containers as &$container) { foreach ($containers as &$container) {
@ -694,7 +681,7 @@ function debug($str) {
debug("Language: $lingo"); debug("Language: $lingo");
debug("Settings:\n".print_r($caSettings,true)); debug("Settings:\n".print_r($caSettings,true));
} }
ca_file_put_contents($caPaths['logging'],date('Y-m-d H:i:s')." $str\n",FILE_APPEND); file_put_contents($caPaths['logging'],date('Y-m-d H:i:s')." $str\n",FILE_APPEND);
} }
} }
######################################## ########################################

View File

@ -14,7 +14,6 @@ $caPaths['templates-community'] = $caPaths['tempFiles']."/templa
$caPaths['community-templates-url'] = "https://raw.githubusercontent.com/Squidly271/Community-Applications-Moderators/master/Repositories.json"; $caPaths['community-templates-url'] = "https://raw.githubusercontent.com/Squidly271/Community-Applications-Moderators/master/Repositories.json";
$caPaths['PublicServiceAnnouncement'] = "https://raw.githubusercontent.com/Squidly271/Community-Applications-Moderators/master/PublicServiceAnnouncement.txt"; $caPaths['PublicServiceAnnouncement'] = "https://raw.githubusercontent.com/Squidly271/Community-Applications-Moderators/master/PublicServiceAnnouncement.txt";
$caPaths['community-templates-info'] = $caPaths['tempFiles']."/templates.json"; /* json file containing all of the templates */ $caPaths['community-templates-info'] = $caPaths['tempFiles']."/templates.json"; /* json file containing all of the templates */
$caPaths['haveTemplates'] = $caPaths['tempFiles']."/haveTemplates";
$caPaths['community-templates-displayed'] = $caPaths['tempFiles']."/displayed.json"; /* json file containing all of the templates currently displayed */ $caPaths['community-templates-displayed'] = $caPaths['tempFiles']."/displayed.json"; /* json file containing all of the templates currently displayed */
$caPaths['community-templates-allSearchResults']= $caPaths['tempFiles']."/allSearchResults.json"; $caPaths['community-templates-allSearchResults']= $caPaths['tempFiles']."/allSearchResults.json";
$caPaths['community-templates-catSearchResults']= $caPaths['tempFiles']."/catSearchResults.json"; $caPaths['community-templates-catSearchResults']= $caPaths['tempFiles']."/catSearchResults.json";