commit f29dade7c20a0dc8f3e17b1fc88340e23a53e4ac
parent 615835e24fd7283e6c5c3712d8dc6b4f1548928e
Author: markseu <mark2011@mayberg.se>
Date: Mon, 29 Nov 2021 14:23:13 +0100
Updated installation with built-in web server
Diffstat:
9 files changed, 93 insertions(+), 73 deletions(-)
diff --git a/system/extensions/command.php b/system/extensions/command.php
@@ -2,7 +2,7 @@
// Command extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/command
class YellowCommand {
- const VERSION = "0.8.30";
+ const VERSION = "0.8.31";
public $yellow; // access to API
public $files; // number of files
public $links; // number of links
@@ -459,7 +459,7 @@ class YellowCommand {
// Check static settings
public function checkStaticSettings() {
- return !empty($this->yellow->system->get("coreStaticUrl"));
+ return preg_match("/^(http|https):/", $this->yellow->system->get("coreStaticUrl"));
}
// Check static directory
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.54";
+ const VERSION = "0.8.55";
const RELEASE = "0.8.18";
public $page; // current page
public $content; // content files
@@ -33,11 +33,10 @@ class YellowCore {
$this->system->setDefault("language", "en");
$this->system->setDefault("parser", "markdown");
$this->system->setDefault("status", "public");
- $this->system->setDefault("coreStaticUrl", "");
$this->system->setDefault("coreServerUrl", "auto");
- $this->system->setDefault("coreServerTimezone", "UTC");
+ $this->system->setDefault("coreStaticUrl", "auto");
+ $this->system->setDefault("coreTimezone", "UTC");
$this->system->setDefault("coreMultiLanguageMode", "0");
- $this->system->setDefault("coreTrashTimeout", "7776660");
$this->system->setDefault("coreMediaLocation", "/media/");
$this->system->setDefault("coreDownloadLocation", "/media/downloads/");
$this->system->setDefault("coreImageLocation", "/media/images/");
@@ -1566,7 +1565,7 @@ class YellowSystem {
$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"));
+ date_default_timezone_set($this->yellow->system->get("coreTimezone"));
}
// Save system settings to file
@@ -1837,7 +1836,7 @@ class YellowLanguage {
$monthNominative = $dateMonthsNominative[date("n", $timestamp) - 1];
$monthGenitive = $dateMonthsGenitive[date("n", $timestamp) - 1];
$weekday = $dateWeekdays[date("N", $timestamp) - 1];
- $timeZone = $this->yellow->system->get("coreServerTimezone");
+ $timeZone = $this->yellow->system->get("coreTimezone");
$timeZoneHelper = new DateTime(null, new DateTimeZone($timeZone));
$timeZoneOffset = $timeZoneHelper->getOffset();
$timeZoneAbbreviation = "GMT".($timeZoneOffset<0 ? "-" : "+").abs(intval($timeZoneOffset/3600));
@@ -3227,22 +3226,23 @@ class YellowToolbox {
// Detect server name, version and operating system
public function detectServerInformation() {
+ $name = "Unknown";
+ $version = "x.x.x";
+ $os = PHP_OS;
if (preg_match("/^(\S+)\/(\S+)/", $this->getServer("SERVER_SOFTWARE"), $matches)) {
$name = $matches[1];
$version = $matches[2];
- } elseif (preg_match("/^(\pL+)/u", $this->getServer("SERVER_SOFTWARE"), $matches)) {
+ } elseif (preg_match("/^(\S+)/u", $this->getServer("SERVER_SOFTWARE"), $matches)) {
$name = $matches[1];
- $version = "x.x.x";
- } else {
- $name = "CLI";
+ }
+ if (PHP_SAPI=="cli" || PHP_SAPI=="cli-server") {
+ $name = "Built-in";
$version = PHP_VERSION;
}
if (PHP_OS=="Darwin") {
$os = "Mac";
} elseif (strtoupperu(substru(PHP_OS, 0, 3))=="WIN") {
$os = "Windows";
- } else {
- $os = PHP_OS;
}
return array($name, $version, $os);
}
diff --git a/system/extensions/install-blog.zip b/system/extensions/install-blog.bin
Binary files differ.
diff --git a/system/extensions/install-language.bin b/system/extensions/install-language.bin
Binary files differ.
diff --git a/system/extensions/install-language.zip b/system/extensions/install-language.zip
Binary files differ.
diff --git a/system/extensions/install-wiki.zip b/system/extensions/install-wiki.bin
Binary files differ.
diff --git a/system/extensions/install.php b/system/extensions/install.php
@@ -2,7 +2,7 @@
// Install extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/install
class YellowInstall {
- const VERSION = "0.8.58";
+ const VERSION = "0.8.59";
const PRIORITY = "1";
public $yellow; // access to API
@@ -18,7 +18,7 @@ class YellowInstall {
// Handle command
public function onCommand($command, $text) {
- return $this->processCommandInstall();
+ return $this->processCommandInstall($command, $text);
}
// Process request to install website
@@ -48,7 +48,7 @@ class YellowInstall {
if ($status=="ok") $status = $this->updateContent($language, "installWiki", "/shared/page-new-wiki")==200 ? "ok" : "error";
if ($status=="ok") $status = $this->updateContent($language, "installBlog", "/shared/page-new-blog")==200 ? "ok" : "error";
if ($status=="ok") $status = $this->updateContent($language, "coreError404", "/shared/page-error-404")==200 ? "ok" : "error";
- if ($status=="ok") $status = $this->updateSettings($language)==200 ? "ok" : "error";
+ if ($status=="ok") $status = $this->updateSettings()==200 ? "ok" : "error";
if ($status=="ok") $status = $this->removeInstall()==200 ? "done" : "error";
} else {
$status = $this->removeInstall()==200 ? "done" : "error";
@@ -65,13 +65,15 @@ class YellowInstall {
}
// Process command to install website
- public function processCommandInstall() {
+ public function processCommandInstall($command, $text) {
if (!$this->isAlreadyInstalled()) {
$this->checkCommandRequirements();
$statusCode = $this->updateLog();
- if ($statusCode==200) $statusCode = $this->updateLanguages();
- if ($statusCode==200) $statusCode = $this->updateSettings("en");
- if ($statusCode==200) $statusCode = $this->removeInstall();
+ if ($command=="build" || $command=="clean") {
+ if ($statusCode==200) $statusCode = $this->updateLanguages();
+ if ($statusCode==200) $statusCode = $this->updateSettings();
+ if ($statusCode==200) $statusCode = $this->removeInstall();
+ }
} else {
$statusCode = $this->removeInstall();
$this->yellow->log($statusCode==200 ? "info" : "error", "Uninstall extension 'Install ".YellowInstall::VERSION."'");
@@ -85,7 +87,7 @@ class YellowInstall {
return $statusCode;
}
- // Update log
+ // Update log file
public function updateLog() {
$statusCode = 200;
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLogFile");
@@ -95,7 +97,7 @@ class YellowInstall {
$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'!");
+ $this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
}
}
return $statusCode;
@@ -104,7 +106,7 @@ class YellowInstall {
// Update languages
public function updateLanguages() {
$statusCode = 200;
- $path = $this->yellow->system->get("coreExtensionDirectory")."install-language.zip";
+ $path = $this->yellow->system->get("coreExtensionDirectory")."install-language.bin";
if (is_file($path) && $this->yellow->extension->isExisting("update")) {
$zip = new ZipArchive();
if ($zip->open($path)===true) {
@@ -122,7 +124,7 @@ class YellowInstall {
$zip->close();
} else {
$statusCode = 500;
- $this->yellow->page->error(500, "Can't open file '$path'!");
+ $this->yellow->page->error($statusCode, "Can't open file '$path'!");
}
}
return $statusCode;
@@ -153,7 +155,7 @@ class YellowInstall {
// Update extension
public function updateExtension($extension) {
$statusCode = 200;
- $path = $this->yellow->system->get("coreExtensionDirectory")."install-".$extension.".zip";
+ $path = $this->yellow->system->get("coreExtensionDirectory")."install-".$extension.".bin";
if (is_file($path) && $this->yellow->extension->isExisting("update")) {
$statusCode = $this->yellow->extension->get("update")->updateExtensionArchive($path, "install");
}
@@ -179,7 +181,7 @@ class YellowInstall {
"status" => "active");
if (!$this->yellow->user->save($fileNameUser, $email, $settings)) {
$statusCode = 500;
- $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
+ $this->yellow->page->error($statusCode, "Can't write file '$fileNameUser'!");
}
$this->yellow->log($statusCode==200 ? "info" : "error", "Add user '".strtok($name, " ")."'");
}
@@ -216,13 +218,14 @@ class YellowInstall {
}
// Update settings
- public function updateSettings($language) {
+ public function updateSettings() {
$statusCode = 200;
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
- if (!$this->yellow->system->save($fileName, $this->getSystemData())) {
+ if (!$this->yellow->system->save($fileName, $this->getSystemSettings())) {
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
}
+ $language = $this->yellow->system->get("language");
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLanguageFile");
$fileData = $this->yellow->toolbox->readFile($fileName);
if (strposu($fileData, "Language:")===false) {
@@ -242,7 +245,7 @@ class YellowInstall {
$statusCode = 200;
if (function_exists("opcache_reset")) opcache_reset();
$path = $this->yellow->system->get("coreExtensionDirectory");
- foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry) {
+ foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.bin$/", true, false) as $entry) {
if (preg_match("/^install-(.*?)\./", basename($entry), $matches)) {
if (!$this->yellow->toolbox->deleteFile($entry)) {
$statusCode = 500;
@@ -318,19 +321,23 @@ class YellowInstall {
// Check web server rewrite support
public function checkServerRewrite() {
- $curlHandle = curl_init();
- list($scheme, $address, $base) = $this->yellow->getRequestInformation();
- $location = $this->yellow->system->get("coreThemeLocation").$this->yellow->lookup->normaliseName($this->yellow->system->get("theme")).".css";
- $url = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
- curl_setopt($curlHandle, CURLOPT_URL, $url);
- curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::VERSION).")";
- curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
- $rawData = curl_exec($curlHandle);
- $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
- curl_close($curlHandle);
- return $statusCode==200;
+ $rewrite = true;
+ if (!$this->isServerBuiltin()) {
+ $curlHandle = curl_init();
+ list($scheme, $address, $base) = $this->yellow->getRequestInformation();
+ $location = $this->yellow->system->get("coreThemeLocation").$this->yellow->lookup->normaliseName($this->yellow->system->get("theme")).".css";
+ $url = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
+ curl_setopt($curlHandle, CURLOPT_URL, $url);
+ curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::VERSION).")";
+ curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30);
+ curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
+ $rawData = curl_exec($curlHandle);
+ $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
+ $rewrite = $statusCode==200;
+ curl_close($curlHandle);
+ }
+ return $rewrite;
}
// Check command line requirements
@@ -340,6 +347,7 @@ class YellowInstall {
echo "YellowInstall::checkCommandRequirements for $name $version, $os<br/>\n";
}
$this->checkServerComplete() || die("Datenstrom Yellow requires complete upload!\n");
+ $this->checkServerWrite() || die("Datenstrom Yellow requires write access!\n");
}
// Detect browser languages
@@ -355,21 +363,20 @@ class YellowInstall {
return array_unique($languages);
}
- // Return system data including static information
- public function getSystemData() {
- $data = array();
+ // Return system settings
+ public function getSystemSettings() {
+ $settings = array();
foreach ($_REQUEST as $key=>$value) {
if (!$this->yellow->system->isExisting($key)) continue;
if ($key=="password" || $key=="status") continue;
- $data[$key] = trim($value);
+ $settings[$key] = trim($value);
}
- $data["sitename"] = $this->yellow->toolbox->detectServerSitename();
- $data["coreServerTimezone"] = $this->yellow->toolbox->detectServerTimezone();
- $data["coreStaticUrl"] = $this->yellow->toolbox->detectServerUrl();
- if ($this->yellow->isCommandLine()) $data["coreStaticUrl"] = getenv("URL");
- if ($this->yellow->system->get("updateEventPending")=="none") $data["updateEventPending"] = "website/install";
- $data["updateCurrentRelease"] = YellowCore::RELEASE;
- return $data;
+ $settings["sitename"] = $this->yellow->toolbox->detectServerSitename();
+ $settings["coreTimezone"] = $this->yellow->toolbox->detectServerTimezone();
+ if ($this->yellow->system->get("coreStaticUrl")=="auto" && !empty(getenv("URL"))) $settings["coreStaticUrl"] = getenv("URL");
+ if ($this->yellow->system->get("updateEventPending")=="none") $settings["updateEventPending"] = "website/install";
+ $settings["updateCurrentRelease"] = YellowCore::RELEASE;
+ return $settings;
}
// Return raw data for install page
@@ -394,7 +401,7 @@ class YellowInstall {
$rawData .= "<label for=\"${extension}-extension\"><input type=\"radio\" name=\"extension\" id=\"${extension}-extension\" value=\"$extension\"$checked> ".$this->yellow->language->getTextHtml("installExtension".ucfirst($extension))."</label><br />";
}
$rawData .= "</p>\n";
- $rawData .= "<input class=\"btn\" type=\"submit\" value=\"".$this->yellow->language->getText("editOkButton")."\" />\n";
+ $rawData .= "<input class=\"btn\" type=\"submit\" value=\"".$this->yellow->language->getText("installButton")."\" />\n";
$rawData .= "<input type=\"hidden\" name=\"status\" value=\"install\" />\n";
$rawData .= "</form>\n";
return $rawData;
@@ -424,6 +431,12 @@ class YellowInstall {
return array_slice($extensions, 0, 3);
}
+ // Check if running built-in web server
+ public function isServerBuiltin() {
+ list($name) = $this->yellow->toolbox->detectServerInformation();
+ return strtoloweru($name)=="built-in";
+ }
+
// Check if website already installed
public function isAlreadyInstalled() {
return $this->yellow->system->get("updateCurrentRelease")!=0;
diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini
@@ -11,21 +11,21 @@ Tag: feature
system/extensions/bundle.php: bundle.php, create, update
Extension: Command
-Version: 0.8.30
+Version: 0.8.31
Description: Command line of the website.
HelpUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/command
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/command.zip
-Published: 2021-08-20 12:49:45
+Published: 2021-11-27 23:30:00
Developer: Datenstrom
Tag: feature
system/extensions/command.php: command.php, create, update
Extension: Core
-Version: 0.8.54
+Version: 0.8.55
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: 2021-11-25 21:11:28
+Published: 2021-11-29 11:41:36
Developer: Datenstrom
Tag: feature
system/extensions/core.php: core.php, create, update
@@ -64,17 +64,17 @@ media/images/photo.jpg: photo.jpg, create, optional
media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional
Extension: Install
-Version: 0.8.58
+Version: 0.8.59
Description: Install a brand new, shiny website.
HelpUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/install
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/install.zip
-Published: 2021-10-20 19:42:33
+Published: 2021-11-29 11:54:59
Developer: Datenstrom
Status: unlisted
system/extensions/install.php: install.php, create
-system/extensions/install-language.zip: @base/zip/language.zip, create
-system/extensions/install-wiki.zip: @base/zip/wiki.zip, create
-system/extensions/install-blog.zip: @base/zip/blog.zip, create
+system/extensions/install-language.bin: @base/zip/language.zip, create
+system/extensions/install-wiki.bin: @base/zip/wiki.zip, create
+system/extensions/install-blog.bin: @base/zip/blog.zip, create
system/extensions/yellow-system.ini: yellow-system.ini, create
system/extensions/yellow-user.ini: yellow-user.ini, create
system/extensions/yellow-language.ini: yellow-language.ini, create
@@ -129,11 +129,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.59
+Version: 0.8.60
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: 2021-11-19 14:35:39
+Published: 2021-11-29 12:29:53
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.59";
+ const VERSION = "0.8.60";
const PRIORITY = "2";
public $yellow; // access to API
public $updates; // number of updates
@@ -17,6 +17,7 @@ class YellowUpdate {
$this->yellow->system->setDefault("updateCurrentRelease", "0");
$this->yellow->system->setDefault("updateEventPending", "none");
$this->yellow->system->setDefault("updateEventDaily", "0");
+ $this->yellow->system->setDefault("updateTrashTimeout", "7776660");
}
// Handle update
@@ -32,11 +33,11 @@ class YellowUpdate {
$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("coreTrashTimeout");
+ $expire = $this->yellow->toolbox->getFileDeleted($entry) + $this->yellow->system->get("updateTrashTimeout");
if ($expire<=time() && !$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, true) as $entry) {
- $expire = $this->yellow->toolbox->getFileDeleted($entry) + $this->yellow->system->get("coreTrashTimeout");
+ $expire = $this->yellow->toolbox->getFileDeleted($entry) + $this->yellow->system->get("updateTrashTimeout");
if ($expire<=time() && !$this->yellow->toolbox->deleteDirectory($entry)) $statusCode = 500;
}
if ($statusCode==500) $this->yellow->log("error", "Can't delete files in directory '$path'!\n");
@@ -60,10 +61,10 @@ class YellowUpdate {
$fileDataCurrent = $this->yellow->toolbox->unsetTextSettings($fileDataCurrent, "extension", $key);
}
}
- if(!is_file($fileNameCurrent) && !$this->yellow->toolbox->createFile($fileNameCurrent, $fileDataCurrent)) {
+ if (!is_file($fileNameCurrent) && !$this->yellow->toolbox->createFile($fileNameCurrent, $fileDataCurrent)) {
$this->yellow->log("error", "Can't write file '$fileNameCurrent'!");
}
- if(!is_file($fileNameLatest) && !$this->yellow->toolbox->createFile($fileNameLatest, $fileDataLatest)) {
+ if (!is_file($fileNameLatest) && !$this->yellow->toolbox->createFile($fileNameLatest, $fileDataLatest)) {
$this->yellow->log("error", "Can't write file '$fileNameLatest'!");
}
}
@@ -90,7 +91,7 @@ class YellowUpdate {
if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($entry, $fileDataNew)) {
$this->yellow->log("error", "Can't write file '$entry'!");
}
- if(basename($entry)=="draftpages.html" &&
+ if (basename($entry)=="draftpages.html" &&
!$this->yellow->toolbox->deleteFile($entry, $this->yellow->system->get("coreTrashDirectory"))) {
$this->yellow->log("error", "Can't delete file '$entry'!");
}
@@ -109,6 +110,12 @@ class YellowUpdate {
$this->yellow->log("error", "Can't write file '$fileName'!");
}
}
+ if ($this->yellow->system->isExisting("coreServerTimezone")) {
+ $coreTimezone = $this->yellow->system->get("coreServerTimezone");
+ if (!$this->yellow->system->save($fileName, array("coreTimezone" => $coreTimezone))) {
+ $this->yellow->log("error", "Can't write file '$fileName'!");
+ }
+ }
if ($this->yellow->system->isExisting("blogLocation")) {
$blogStartLocation = $this->yellow->system->get("blogLocation");
if (!$this->yellow->system->save($fileName, array("blogStartLocation" => $blogStartLocation))) {
@@ -230,7 +237,7 @@ class YellowUpdate {
$statusCode = 0;
if ($this->yellow->lookup->isContentFile($fileName)) {
$this->updateEventPending();
- if($this->isExtensionPending()) {
+ if ($this->isExtensionPending()) {
$statusCode = $this->updateExtensions("install");
if ($statusCode==200) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);