Handle write errors semi-gracefully
parent
b317cd6075
commit
8dcbf1d462
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||||
29f110f50c87f9e8285aca289bce6e57 ./include/exec.php
|
9ffd40aedffad25c998e947faf169ad3 ./include/exec.php
|
||||||
8cb18002feb91c9eb07811a75aabb7b5 ./include/helpers.php
|
3a1e5abf962bd5700e286a48c941b2c9 ./include/helpers.php
|
||||||
116042a918060278e77379b0dd73482c ./include/paths.php
|
8d15446d4edf60a1f4ac4493a494a301 ./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
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
# #
|
# #
|
||||||
###############################################################
|
###############################################################
|
||||||
|
|
||||||
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
|
||||||
|
@ -212,6 +211,7 @@ 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']);
|
||||||
file_put_contents($caPaths['appFeedDownloadError'],$downloadURL);
|
ca_file_put_contents($caPaths['appFeedDownloadError'],$downloadURL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
file_put_contents($caPaths['currentServer'],$currentFeed);
|
ca_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,6 +406,7 @@ function DownloadApplicationFeed() {
|
||||||
writeJsonFile($caPaths['extraDeprecated'],$ApplicationFeed['deprecated']);
|
writeJsonFile($caPaths['extraDeprecated'],$ApplicationFeed['deprecated']);
|
||||||
|
|
||||||
updatePluginSupport($myTemplates);
|
updatePluginSupport($myTemplates);
|
||||||
|
touch($caPaths['haveTemplates']);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +438,7 @@ function updatePluginSupport($templates) {
|
||||||
$dom->preserveWhiteSpace = false;
|
$dom->preserveWhiteSpace = false;
|
||||||
$dom->formatOutput = true;
|
$dom->formatOutput = true;
|
||||||
$dom->loadXML($xml->asXML());
|
$dom->loadXML($xml->asXML());
|
||||||
file_put_contents($plugin, $dom->saveXML());
|
ca_file_put_contents($plugin, $dom->saveXML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -733,7 +734,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
|
||||||
|
|
||||||
file_put_contents($caPaths['startupDisplayed'],"startup");
|
ca_file_put_contents($caPaths['startupDisplayed'],"startup");
|
||||||
$displayApplications = [];
|
$displayApplications = [];
|
||||||
$displayApplications['community'] = [];
|
$displayApplications['community'] = [];
|
||||||
if ( count($file) > 200) {
|
if ( count($file) > 200) {
|
||||||
|
@ -968,28 +969,24 @@ 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']); */
|
||||||
|
|
||||||
if (isset($badDownload)) {
|
exec("rm -rf '{$caPaths['tempFiles']}'");
|
||||||
if ( ! $badDownload ) {
|
$GLOBALS['templates'] = [];
|
||||||
@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']) {
|
||||||
|
@ -1051,13 +1048,13 @@ function display_content() {
|
||||||
function dismiss_warning() {
|
function dismiss_warning() {
|
||||||
global $caPaths;
|
global $caPaths;
|
||||||
|
|
||||||
file_put_contents($caPaths['warningAccepted'],"warning dismissed");
|
ca_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;
|
||||||
|
|
||||||
file_put_contents($caPaths['pluginWarning'],"disclaimer ok");
|
ca_file_put_contents($caPaths['pluginWarning'],"disclaimer ok");
|
||||||
postReturn(['status'=>"disclaimed"]);
|
postReturn(['status'=>"disclaimed"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1987,7 +1984,7 @@ function createXML() {
|
||||||
}
|
}
|
||||||
$xml = makeXML($template);
|
$xml = makeXML($template);
|
||||||
@mkdir(dirname($xmlFile));
|
@mkdir(dirname($xmlFile));
|
||||||
file_put_contents($xmlFile,$xml);
|
ca_file_put_contents($xmlFile,$xml);
|
||||||
}
|
}
|
||||||
postReturn(["status"=>"ok","cache"=>$cacheVolume ?? ""]);
|
postReturn(["status"=>"ok","cache"=>$cacheVolume ?? ""]);
|
||||||
}
|
}
|
||||||
|
@ -2191,7 +2188,7 @@ function convert_docker() {
|
||||||
|
|
||||||
$dockerXML = makeXML($dockerfile);
|
$dockerXML = makeXML($dockerfile);
|
||||||
|
|
||||||
file_put_contents($caPaths['dockerSearchInstall'],$dockerXML);
|
ca_file_put_contents($caPaths['dockerSearchInstall'],$dockerXML);
|
||||||
postReturn(['xml'=>$caPaths['dockerSearchInstall']]);
|
postReturn(['xml'=>$caPaths['dockerSearchInstall']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2331,7 +2328,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 ( ;; ) {
|
for ( $i=0;$i<100;$i++ ) {
|
||||||
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);
|
||||||
|
@ -2339,10 +2336,15 @@ 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
|
# wait til templates are downloaded
|
||||||
for ( ;; ) {
|
for ( $i=0;$i<100;$i++ ) {
|
||||||
$file = &$GLOBALS['templates'];
|
$file = readJsonFile($caPaths['community-templates-info']);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -2351,6 +2353,12 @@ 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']);
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,17 @@ function writeJsonFile($filename,$jsonArray) {
|
||||||
|
|
||||||
debug("Write JSON File $filename");
|
debug("Write JSON File $filename");
|
||||||
|
|
||||||
$result = file_put_contents($filename,json_encode($jsonArray, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
ca_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");
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! $result )
|
function ca_file_put_contents($filename,$data,$flags = null) {
|
||||||
debug("Write error $filename");
|
$result = @file_put_contents($filename,$data,$flags);
|
||||||
|
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) {
|
||||||
|
@ -94,7 +99,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 )
|
||||||
file_put_contents($path,$out);
|
ca_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));
|
||||||
|
@ -323,7 +328,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);
|
||||||
|
@ -434,6 +439,7 @@ 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']);
|
||||||
|
@ -574,6 +580,13 @@ 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
|
||||||
|
@ -636,7 +649,7 @@ function write_ini_file($file,$array) {
|
||||||
else
|
else
|
||||||
$res[] = $key.'="'.$val.'"';
|
$res[] = $key.'="'.$val.'"';
|
||||||
}
|
}
|
||||||
file_put_contents($file,implode("\r\n", $res),LOCK_EX);
|
ca_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 #
|
||||||
|
@ -646,7 +659,7 @@ function getAllInfo($force=false) {
|
||||||
|
|
||||||
$containers = [];
|
$containers = [];
|
||||||
if ( $force ) {
|
if ( $force ) {
|
||||||
if ( $caSettings['dockerRunning'] ?? false ) {
|
if ( $caSettings['dockerRunning'] ) {
|
||||||
$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) {
|
||||||
|
@ -681,7 +694,7 @@ function debug($str) {
|
||||||
debug("Language: $lingo");
|
debug("Language: $lingo");
|
||||||
debug("Settings:\n".print_r($caSettings,true));
|
debug("Settings:\n".print_r($caSettings,true));
|
||||||
}
|
}
|
||||||
file_put_contents($caPaths['logging'],date('Y-m-d H:i:s')." $str\n",FILE_APPEND);
|
ca_file_put_contents($caPaths['logging'],date('Y-m-d H:i:s')." $str\n",FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
########################################
|
########################################
|
||||||
|
|
|
@ -14,6 +14,7 @@ $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";
|
||||||
|
|
Loading…
Reference in New Issue