commit d28e418f7ad6add030b8e4dfcd40fba1c76c5d96
parent 75c618b87ccf8ed3099ffe9dfe334e0ece3f79ec
Author: markseu <mark2011@mayberg.se>
Date: Wed, 18 Nov 2020 19:33:26 +0100
Updated extensions, more information for troubleshooting
Diffstat:
5 files changed, 96 insertions(+), 108 deletions(-)
diff --git a/system/extensions/core.php b/system/extensions/core.php
@@ -2,7 +2,7 @@
// Core extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/core
class YellowCore {
- const VERSION = "0.8.31";
+ const VERSION = "0.8.32";
const RELEASE = "0.8.16";
public $page; // current page
public $content; // content files
@@ -90,8 +90,8 @@ class YellowCore {
// Handle initialisation
public function load() {
+ register_shutdown_function(array($this, "processFatalError"));
$this->system->load($this->system->get("coreExtensionDirectory").$this->system->get("coreSystemFile"));
- $this->lookup->detectFileSystem();
$this->user->load($this->system->get("coreExtensionDirectory").$this->system->get("coreUserFile"));
$this->language->load($this->system->get("coreExtensionDirectory"));
$this->language->load($this->system->get("coreExtensionDirectory").$this->system->get("coreLanguageFile"));
@@ -168,6 +168,18 @@ class YellowCore {
return $statusCode;
}
+ // Process fatal runtime error
+ public function processFatalError() {
+ $error = error_get_last();
+ if (!is_null($error) && ($error["type"]==E_ERROR || $error["type"]==E_PARSE)) {
+ $fileName = substru($error["file"], strlenu($this->system->get("coreServerInstallDirectory")));
+ $this->log("error", "Can't parse file '$fileName'!");
+ @header($this->toolbox->getHttpStatusFormatted(500));
+ $troubleshooting = PHP_SAPI!="cli" ? "<a href=\"".$this->getTroubleshootingUrl()."\">See troubleshooting</a>." : "";
+ echo "<br/>\nSomething went wrong. Please activate debug mode for more information. $troubleshooting\n";
+ }
+ }
+
// Read page
public function readPage($scheme, $address, $base, $location, $fileName, $cacheable, $statusCode, $pageError) {
if ($statusCode>=400) {
@@ -666,11 +678,11 @@ class YellowPage {
$fileNameLayoutTheme = $this->yellow->system->get("coreLayoutDirectory").
$this->yellow->lookup->normaliseName($this->get("theme"))."-".$this->yellow->lookup->normaliseName($name).".html";
if (is_file($fileNameLayoutTheme)) {
- if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutTheme<br>\n";
+ if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutTheme<br/>\n";
$this->setLastModified(filemtime($fileNameLayoutTheme));
require($fileNameLayoutTheme);
} elseif (is_file($fileNameLayoutNormal)) {
- if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutNormal<br>\n";
+ if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutNormal<br/>\n";
$this->setLastModified(filemtime($fileNameLayoutNormal));
require($fileNameLayoutNormal);
} else {
@@ -1552,6 +1564,11 @@ class YellowSystem {
echo "YellowSystem::load ".ucfirst($key).":$value<br/>\n";
}
}
+ list($pathInstall, $pathRoot, $pathHome) = $this->yellow->lookup->findFileSystemInformation();
+ $this->yellow->system->set("coreServerInstallDirectory", $pathInstall);
+ $this->yellow->system->set("coreContentRootDirectory", $pathRoot);
+ $this->yellow->system->set("coreContentHomeDirectory", $pathHome);
+ date_default_timezone_set($this->yellow->system->get("coreServerTimezone"));
}
// Save system settings to file
@@ -1916,7 +1933,6 @@ class YellowExtension {
// Load extensions
public function load($path) {
- if (empty($this->data)) register_shutdown_function(array($this, "processExtensionError"));
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.php$/", true, false) as $entry) {
if (defined("DEBUG") && DEBUG>=3) echo "YellowExtension::load file:$entry<br/>\n";
$this->modified = max($this->modified, filemtime($entry));
@@ -1933,26 +1949,6 @@ class YellowExtension {
}
}
- // Process extension error
- public function processExtensionError() {
- $error = error_get_last();
- if (!is_null($error)) {
- if ($error["type"]==E_ERROR || $error["type"]==E_PARSE) {
- $fileName = substru($error["file"], strlenu($this->yellow->system->get("coreServerInstallDirectory")));
- $extension = $this->yellow->lookup->normaliseName(basename($fileName), true, true);
- if ($this->isExisting($extension) && $this->yellow->toolbox->getFileType($fileName)=="php") {
- $version = $this->data[$extension]["version"];
- $this->yellow->log("error", "Can't run extension '".ucfirst($extension)." $version'!");
- } else {
- $this->yellow->log("error", "Can't parse file '$fileName'!");
- }
- @header($this->yellow->toolbox->getHttpStatusFormatted(500));
- $troubleshooting = "<a href=\"".$this->yellow->getTroubleshootingUrl()."\">See troubleshooting</a>.";
- echo "<br/>Something went wrong. Activate debug mode for more information. $troubleshooting\n";
- }
- }
- }
-
// Register extension
public function register($key, $class) {
if (!$this->isExisting($key) && class_exists($class)) {
@@ -1990,25 +1986,16 @@ class YellowLookup {
$this->yellow = $yellow;
}
- // Detect file system
- public function detectFileSystem() {
- list($pathRoot, $pathHome) = $this->findFileSystemInformation();
- $this->yellow->system->set("coreContentRootDirectory", $pathRoot);
- $this->yellow->system->set("coreContentHomeDirectory", $pathHome);
- $this->yellow->system->set("coreServerInstallDirectory",
- substru(dirname(__FILE__), 0, 1-strlenu($this->yellow->system->get("coreExtensionDirectory"))));
- date_default_timezone_set($this->yellow->system->get("coreServerTimezone"));
- }
-
// Return file system information
public function findFileSystemInformation() {
- $path = $this->yellow->system->get("coreContentDirectory");
+ $pathInstall = substru(__DIR__, 0, 1-strlenu($this->yellow->system->get("coreExtensionDirectory")));
+ $pathBase = $this->yellow->system->get("coreContentDirectory");
$pathRoot = $this->yellow->system->get("coreContentRootDirectory");
$pathHome = $this->yellow->system->get("coreContentHomeDirectory");
if (!$this->yellow->system->get("coreMultiLanguageMode")) $pathRoot = "";
if (!empty($pathRoot)) {
$token = $root = rtrim($pathRoot, "/");
- foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, false) as $entry) {
+ foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) {
if (empty($firstRoot)) $firstRoot = $token = $entry;
if ($this->normaliseToken($entry)==$root) {
$token = $entry;
@@ -2016,11 +2003,11 @@ class YellowLookup {
}
}
$pathRoot = $this->normaliseToken($token)."/";
- $path .= "$firstRoot/";
+ $pathBase .= "$firstRoot/";
}
if (!empty($pathHome)) {
$token = $home = rtrim($pathHome, "/");
- foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, false) as $entry) {
+ foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) {
if (empty($firstHome)) $firstHome = $token = $entry;
if ($this->normaliseToken($entry)==$home) {
$token = $entry;
@@ -2029,7 +2016,7 @@ class YellowLookup {
}
$pathHome = $this->normaliseToken($token)."/";
}
- return array($pathRoot, $pathHome);
+ return array($pathInstall, $pathRoot, $pathHome);
}
// Return root locations
@@ -2519,8 +2506,10 @@ class YellowToolbox {
case 400: $text = "Bad request"; break;
case 403: $text = "Forbidden"; break;
case 404: $text = "Not found"; break;
+ case 420: $text = "Not public"; break;
case 430: $text = "Login failed"; break;
- case 434: $text = "Not existing"; break;
+ case 434: $text = "Can create"; break;
+ case 435: $text = "Can restore"; break;
case 500: $text = "Server error"; break;
case 503: $text = "Service unavailable"; break;
default: $text = "Error $statusCode";
@@ -3051,9 +3040,6 @@ class YellowToolbox {
if (empty($dataBuffer) && function_exists("random_bytes")) {
$dataBuffer = @random_bytes($dataBufferSize);
}
- if (empty($dataBuffer) && function_exists("mcrypt_create_iv")) {
- $dataBuffer = @mcrypt_create_iv($dataBufferSize, MCRYPT_DEV_URANDOM);
- }
if (empty($dataBuffer) && function_exists("openssl_random_pseudo_bytes")) {
$dataBuffer = @openssl_random_pseudo_bytes($dataBufferSize);
}
@@ -3210,7 +3196,7 @@ class YellowToolbox {
return $timezone;
}
- // Detect server name and version
+ // Detect server name, version and operating system
public function detectServerInformation() {
if (preg_match("/^(\S+)\/(\S+)/", $this->getServer("SERVER_SOFTWARE"), $matches)) {
$name = $matches[1];
@@ -3222,7 +3208,14 @@ class YellowToolbox {
$name = "CLI";
$version = PHP_VERSION;
}
- return array($name, $version);
+ if (PHP_OS=="Darwin") {
+ $os = "Mac";
+ } else if (strtoupperu(substru(PHP_OS, 0, 3))=="WIN") {
+ $os = "Windows";
+ } else {
+ $os = PHP_OS;
+ }
+ return array($name, $version, $os);
}
// Detect browser language
diff --git a/system/extensions/install.php b/system/extensions/install.php
@@ -2,7 +2,7 @@
// Install extension, https://github.com/datenstrom/yellow
class YellowInstall {
- const VERSION = "0.8.42";
+ const VERSION = "0.8.43";
const PRIORITY = "1";
public $yellow; // access to API
@@ -77,8 +77,9 @@ class YellowInstall {
$statusCode = 200;
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLogFile");
if (!is_file($fileName)) {
- list($name, $version) = $this->yellow->toolbox->detectServerInformation();
- $this->yellow->log("info", "Datenstrom Yellow ".YellowCore::RELEASE.", PHP ".PHP_VERSION.", $name $version, ".$this->getOperatingSystem());
+ list($name, $version, $os) = $this->yellow->toolbox->detectServerInformation();
+ $product = "Datenstrom Yellow ".YellowCore::RELEASE;
+ $this->yellow->log("info", "Install $product, PHP ".PHP_VERSION.", $name $version, $os");
if (!is_file($fileName)) {
$statusCode = 500;
$this->yellow->page->error(500, "Can't write file '$fileName'!");
@@ -290,18 +291,6 @@ class YellowInstall {
return array_unique($languages);
}
- // Return operating system name
- public function getOperatingSystem() {
- if (PHP_OS=="Darwin") {
- $name = "Mac";
- } else if (strtoupperu(substru(PHP_OS, 0, 3))=="WIN") {
- $name = "Windows";
- } else {
- $name = PHP_OS;
- }
- return $name;
- }
-
// Return system data including static information
public function getSystemData() {
$data = array();
@@ -314,6 +303,7 @@ class YellowInstall {
$data["coreStaticUrl"] = $this->yellow->toolbox->detectServerUrl();
if ($this->yellow->isCommandLine()) $data["coreStaticUrl"] = getenv("URL");
if ($this->yellow->system->get("updateNotification")=="none") $data["updateNotification"] = "website/install";
+ $data["updateCurrentRelease"] = YellowCore::RELEASE;
return $data;
}
diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini
@@ -21,11 +21,11 @@ Tag: feature
system/extensions/command.php: command.php, create, update
Extension: Core
-Version: 0.8.31
+Version: 0.8.32
Description: Core functionality of the website.
HelpUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/core
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/core.zip
-Published: 2020-11-12 15:09:21
+Published: 2020-11-18 13:17:46
Developer: Datenstrom
Tag: feature
system/extensions/core.php: core.php, create, update
@@ -89,11 +89,11 @@ system/themes/stockholm-opensans-light.woff: stockholm-opensans-light.woff, crea
system/themes/stockholm-opensans-regular.woff: stockholm-opensans-regular.woff, create, update, careful
Extension: Update
-Version: 0.8.43
+Version: 0.8.44
Description: Keep your website up to date.
HelpUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/update
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/update.zip
-Published: 2020-11-13 20:47:06
+Published: 2020-11-18 13:36:10
Developer: Datenstrom
Tag: feature
system/extensions/update.php: update.php, create, update
diff --git a/system/extensions/update.php b/system/extensions/update.php
@@ -2,7 +2,7 @@
// Update extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/update
class YellowUpdate {
- const VERSION = "0.8.43";
+ const VERSION = "0.8.44";
const PRIORITY = "2";
public $yellow; // access to API
public $updates; // number of updates
@@ -12,27 +12,22 @@ class YellowUpdate {
$this->yellow = $yellow;
$this->yellow->system->setDefault("updateExtensionUrl", "https://github.com/datenstrom/yellow-extensions");
$this->yellow->system->setDefault("updateExtensionFile", "extension.ini");
- $this->yellow->system->setDefault("updateCurrentFile", "update-current.ini");
$this->yellow->system->setDefault("updateLatestFile", "update-latest.ini");
+ $this->yellow->system->setDefault("updateCurrentFile", "update-current.ini");
+ $this->yellow->system->setDefault("updateCurrentRelease", "0");
$this->yellow->system->setDefault("updateDailyTimestamp", "0");
- $this->yellow->system->setDefault("updateWeeklyTimestamp", "0");
- $this->yellow->system->setDefault("updateMonthlyTimestamp", "0");
+ $this->yellow->system->setDefault("updateTrashTimeout", "7776660");
$this->yellow->system->setDefault("updateNotification", "none");
}
// Handle request
public function onRequest($scheme, $address, $base, $location, $fileName) {
- $statusCode = 0;
- if ($this->yellow->lookup->isContentFile($fileName) && $this->isExtensionPending()) {
- $statusCode = $this->processRequestPending($scheme, $address, $base, $location, $fileName);
- }
- return $statusCode;
+ return $this->processRequestPending($scheme, $address, $base, $location, $fileName);
}
// Handle command
public function onCommand($command, $text) {
- $statusCode = 0;
- if ($this->isExtensionPending()) $statusCode = $this->processCommandPending();
+ $statusCode = $this->processCommandPending();
if ($statusCode==0) {
switch ($command) {
case "about": $statusCode = $this->processCommandAbout($command, $text); break;
@@ -73,26 +68,25 @@ class YellowUpdate {
$this->updateSystemSettings();
$this->updateLanguageSettings();
}
- if ($this->yellow->system->get("updateDailyTimestamp") <= time()) {
+ if ($this->yellow->system->get("updateDailyTimestamp")<=time()) {
foreach ($this->yellow->extension->data as $key=>$value) {
if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate("daily");
}
$this->updateTimestampSettings("updateDailyTimestamp");
}
- if ($this->yellow->system->get("updateWeeklyTimestamp") <= time()) {
- foreach ($this->yellow->extension->data as $key=>$value) {
- if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate("weekly");
- }
- $this->updateTimestampSettings("updateWeeklyTimestamp");
+ }
+ if ($action=="clean" || $action=="daily") {
+ $statusCode = 200;
+ $path = $this->yellow->system->get("coreTrashDirectory");
+ foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false) as $entry) {
+ $expire = $this->yellow->toolbox->getFileDeleted($entry) + $this->yellow->system->get("updateTrashTimeout");
+ if ($expire<=time() && !$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
- if ($this->yellow->system->get("updateMonthlyTimestamp") <= time()) {
- foreach ($this->yellow->extension->data as $key=>$value) {
- if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate("monthly");
- }
- $this->updateTimestampSettings("updateMonthlyTimestamp");
+ foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, true) as $entry) {
+ $expire = $this->yellow->toolbox->getFileDeleted($entry) + $this->yellow->system->get("updateTrashTimeout");
+ if ($expire<=time() && !$this->yellow->toolbox->deleteDirectory($entry)) $statusCode = 500;
}
- }
- if ($action=="clean") {
+ if ($statusCode==500) $this->yellow->log("error", "Can't delete files in directory '$path'!\n");
$statusCode = 200;
$path = $this->yellow->system->get("coreExtensionDirectory");
$regex = "/^.*\\".$this->yellow->system->get("coreDownloadExtension")."$/";
@@ -182,7 +176,7 @@ class YellowUpdate {
}
}
- // Update system settings after update notification
+ // Update system settings after update
public function updateSystemSettings() {
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
$fileData = $this->yellow->toolbox->readFile($fileName);
@@ -211,9 +205,18 @@ class YellowUpdate {
if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) {
$this->yellow->log("error", "Can't write file '$fileName'!");
}
+ if ($this->yellow->system->get("updateCurrentRelease")!=YellowCore::RELEASE) {
+ if (!$this->yellow->system->save($fileName, array("updateCurrentRelease" => YellowCore::RELEASE))) {
+ $this->yellow->log("error", "Can't write file '$fileName'!");
+ } else {
+ list($name, $version, $os) = $this->yellow->toolbox->detectServerInformation();
+ $product = "Datenstrom Yellow ".YellowCore::RELEASE;
+ $this->yellow->log("info", "Update $product, PHP ".PHP_VERSION.", $name $version, $os");
+ }
+ }
}
- // Update language settings after update notification
+ // Update language settings after update
public function updateLanguageSettings() {
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLanguageFile");
$fileData = $this->yellow->toolbox->readFile($fileName);
@@ -256,7 +259,7 @@ class YellowUpdate {
}
}
- // Update extension settings
+ // Update extension settings after update
public function updateExtensionSettings($extension, $settings, $action) {
$statusCode = 200;
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("updateCurrentFile");
@@ -295,10 +298,6 @@ class YellowUpdate {
}
if ($key=="updateDailyTimestamp") {
$timestamp = mktime(0, 0, 0) + 60*60*24 + $timeOffset;
- } elseif ($key=="updateWeeklyTimestamp") {
- $timestamp = mktime(0, 0, 0, date("n"), date("j")-date("N")+1) + 60*60*24*7 + $timeOffset;
- } elseif ($key=="updateMonthlyTimestamp") {
- $timestamp = mktime(0, 0, 0, date("n")+1, 1) + $timeOffset;
}
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
if (!$this->yellow->system->save($fileName, array($key => $timestamp))) {
@@ -376,18 +375,24 @@ class YellowUpdate {
// Process command to install pending extension
public function processCommandPending() {
- $statusCode = $this->updateExtensions("install");
- if ($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n";
- echo "Your website has ".($statusCode!=200 ? "not " : "")."been updated: Please run command again\n";
+ $statusCode = 0;
+ if ($this->isExtensionPending()) {
+ $statusCode = $this->updateExtensions("install");
+ if ($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n";
+ echo "Your website has ".($statusCode!=200 ? "not " : "")."been updated: Please run command again\n";
+ }
return $statusCode;
}
// Process request to install pending extension
public function processRequestPending($scheme, $address, $base, $location, $fileName) {
- $statusCode = $this->updateExtensions("install");
- if ($statusCode==200) {
- $location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
- $statusCode = $this->yellow->sendStatus(303, $location);
+ $statusCode = 0;
+ if ($this->yellow->lookup->isContentFile($fileName) && $this->isExtensionPending()) {
+ $statusCode = $this->updateExtensions("install");
+ if ($statusCode==200) {
+ $location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
+ $statusCode = $this->yellow->sendStatus(303, $location);
+ }
}
return $statusCode;
}
@@ -757,8 +762,8 @@ class YellowUpdate {
if (strposu($key, "/")) {
if (!$this->yellow->lookup->isValidFile($key)) $invalid = true;
list($entry, $flags) = $this->yellow->toolbox->getTextList($value, ",", 2);
- if (strposu($entry, ".")===false) $invalid = true;
- if ($oldModified==0 && is_file($key)) $oldModified = filemtime($key);
+ if (strposu($entry, ".")===false) $invalid = true; // TODO: remove later, detect old format
+ if ($oldModified==0) $oldModified = $this->yellow->toolbox->getFileModified($key);
}
}
if ($invalid) $extension = $version = "";
diff --git a/system/extensions/yellow-system.ini b/system/extensions/yellow-system.ini
@@ -39,11 +39,11 @@ CoreLanguageFile: yellow-language.ini
CoreLogFile: yellow.log
UpdateExtensionUrl: https://github.com/datenstrom/yellow-extensions
UpdateExtensionFile: extension.ini
-UpdateCurrentFile: update-current.ini
UpdateLatestFile: update-latest.ini
+UpdateCurrentFile: update-current.ini
+UpdateCurrentRelease: 0
UpdateDailyTimestamp: 0
-UpdateWeeklyTimestamp: 0
-UpdateMonthlyTimestamp: 0
+UpdateTrashTimeout: 7776660
UpdateNotification: none
CommandStaticBuildDirectory: public/
CommandStaticDefaultFile: index.html