From cd05d9d4e8293243e2e9d7c1d8ec1009bee19f6b Mon Sep 17 00:00:00 2001 From: crispycat Date: Thu, 7 Dec 2023 17:10:41 -0500 Subject: [PATCH] installer --- .gitignore | 2 +- LICENSE | 0 README | 0 build.sh | 6 +- delete.list | 0 patch/core/app/assets/Asset.php | 0 patch/core/app/assets/AssetManager.php | 0 patch/core/app/assets/class/Module.php | 0 patch/core/app/assets/class/Plugin.php | 0 patch/core/app/assets/class/Role.php | 0 patch/core/app/assets/class/User.php | 0 patch/core/app/extensions/CoreExtensions.php | 0 patch/core/templates/default/layouts/api.php | 0 .../templates/default/layouts/default.php | 2 + patch/packages/.htaccess | 1 + .../_crispage/scripts/install.php | 314 ++++++++++++++++++ .../_crispage/scripts/uninstall.php | 13 + .../crispage.core/config_template.php | 109 ++++++ .../crispage.core/installer_config.php | 62 ++++ patch/packages/crispage.core/version | 1 + 20 files changed, 506 insertions(+), 4 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README mode change 100644 => 100755 delete.list mode change 100644 => 100755 patch/core/app/assets/Asset.php mode change 100644 => 100755 patch/core/app/assets/AssetManager.php mode change 100644 => 100755 patch/core/app/assets/class/Module.php mode change 100644 => 100755 patch/core/app/assets/class/Plugin.php mode change 100644 => 100755 patch/core/app/assets/class/Role.php mode change 100644 => 100755 patch/core/app/assets/class/User.php mode change 100644 => 100755 patch/core/app/extensions/CoreExtensions.php mode change 100644 => 100755 patch/core/templates/default/layouts/api.php mode change 100644 => 100755 patch/core/templates/default/layouts/default.php create mode 100755 patch/packages/.htaccess create mode 100755 patch/packages/crispage.core/_crispage/scripts/install.php create mode 100755 patch/packages/crispage.core/_crispage/scripts/uninstall.php create mode 100755 patch/packages/crispage.core/config_template.php create mode 100755 patch/packages/crispage.core/installer_config.php create mode 100755 patch/packages/crispage.core/version diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 7e5cd5f..95a6a8b --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ build -cache +source lite patch/config.php diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README b/README old mode 100644 new mode 100755 diff --git a/build.sh b/build.sh index ccdb282..04ed080 100755 --- a/build.sh +++ b/build.sh @@ -1,11 +1,11 @@ #!/bin/bash rm -rf build; -if [[ -d cache ]]; then - cp -r cache build; +if [[ -d source ]]; then + cp -r source build; else git clone https://git.calitabby.com/crispage/crispage.git build; - cp -r build cache; + cp -r build source; fi; while IFS= read -r line; do diff --git a/delete.list b/delete.list old mode 100644 new mode 100755 diff --git a/patch/core/app/assets/Asset.php b/patch/core/app/assets/Asset.php old mode 100644 new mode 100755 diff --git a/patch/core/app/assets/AssetManager.php b/patch/core/app/assets/AssetManager.php old mode 100644 new mode 100755 diff --git a/patch/core/app/assets/class/Module.php b/patch/core/app/assets/class/Module.php old mode 100644 new mode 100755 diff --git a/patch/core/app/assets/class/Plugin.php b/patch/core/app/assets/class/Plugin.php old mode 100644 new mode 100755 diff --git a/patch/core/app/assets/class/Role.php b/patch/core/app/assets/class/Role.php old mode 100644 new mode 100755 diff --git a/patch/core/app/assets/class/User.php b/patch/core/app/assets/class/User.php old mode 100644 new mode 100755 diff --git a/patch/core/app/extensions/CoreExtensions.php b/patch/core/app/extensions/CoreExtensions.php old mode 100644 new mode 100755 diff --git a/patch/core/templates/default/layouts/api.php b/patch/core/templates/default/layouts/api.php old mode 100644 new mode 100755 diff --git a/patch/core/templates/default/layouts/default.php b/patch/core/templates/default/layouts/default.php old mode 100644 new mode 100755 index 07da623..a35d0a4 --- a/patch/core/templates/default/layouts/default.php +++ b/patch/core/templates/default/layouts/default.php @@ -31,6 +31,8 @@ ); $this->app->page->renderComponent($com_msgs); $this->app->page->renderMainComponent(); + + echo "

v" . VERSION . "

"; ?> diff --git a/patch/packages/.htaccess b/patch/packages/.htaccess new file mode 100755 index 0000000..b66e808 --- /dev/null +++ b/patch/packages/.htaccess @@ -0,0 +1 @@ +Require all denied diff --git a/patch/packages/crispage.core/_crispage/scripts/install.php b/patch/packages/crispage.core/_crispage/scripts/install.php new file mode 100755 index 0000000..64ca311 --- /dev/null +++ b/patch/packages/crispage.core/_crispage/scripts/install.php @@ -0,0 +1,314 @@ + + https://crispy.cat/software/crispage + + Crispage is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + */ + + use \Crispage\Auth\CorePermissions; + use \Crispage\CoreSettings; + use \Crispage\Utils\FileUtils; + use \Crispage\Request\Route; + + if (IS_INSTALLED) throw new Exception("Crispage is already installed"); + + $this->log("Starting Crispage Lite Installation"); + + // Check PHP + if (PHP_VERSION_ID < 80100) + throw new Exception("PHP version 8.1 or higher is required to install Crispage!"); + + $exts = [ + "bz2", + "fileinfo", + "filter", + "json", + "mcrypt", + "openssl", + "PDO", + "pdo_mysql", + "Phar", + "random", + "zip", + "zlib" + ]; + + foreach ($exts as $ext) { + if (!extension_loaded($ext)) + $this->log("Extension $ext is not loaded. Please enable it to ensure proper functionality.", $this::L_WARNING); + } + + + // Get installation options + $iopts = $this->app->request->params["iopts"] ?? []; + if (!is_array($iopts) || empty($iopts)) { + $this->log("Please continue after providing the following information:", $this::L_ERROR); +?> +
+ + + + " required /> +
+ + + +
+ +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ +
+ + + +
+ + + +
+ + + +
+ +
+ + +
+log("Connecting to database"); + + $db_type = "\\Crispage\\Database\\MySQLDatabase"; + $db_loc = strval($iopts["DB_LOC"] ?? "localhost"); + $db_port = intval($iopts["DB_PORT"] ?? 3306); + $db_name = strval($iopts["DB_NAME"] ?? ""); + $db_user = strval($iopts["DB_USER"] ?? ""); + $db_passwd = strval($iopts["DB_PASSWD"] ?? ""); + $db_prefix = strval($iopts["DB_PREFIX"] ?? "cspg_"); + $db_opts = []; + + if (!class_exists($db_type)) + throw new Exception("DB type $db_type not available"); + + $this->app->database = new $db_type([ + "location" => $db_loc, + "port" => $db_port, + "username" => $db_user, + "password" => $db_passwd, + "dbname" => $db_name, + "prefix" => $db_prefix, + "options" => $db_opts + ]); + + $this->app->database->connect(); + + // Create database tables + $this->log("Creating database tables"); + + $this->app->database->createTable("system", [ + "iid" => $this->app->database::TYPE_STRING, + "version" => $this->app->database::TYPE_STRING, + "next_asset_id" => $this->app->database::TYPE_INT + ]); + + $this->app->database->createTable("settings", [ + "setting" => $this->app->database::TYPE_STRING, + "value" => [$this->app->database::TYPE_STRING, true], + "component" => [$this->app->database::TYPE_STRING, true], + "com_data" => [$this->app->database::TYPE_STRING, true] + ]); + $this->app->database->addUnique("settings", "setting"); + + $this->app->database->createTable("routes", [ + "id" => $this->app->database::TYPE_STRING, + "action" => $this->app->database::TYPE_STRING, + "data" => $this->app->database::TYPE_STRING + ]); + $this->app->database->addUnique("routes", "id"); + + $this->app->database->createTable("extensions", [ + "id" => $this->app->database::TYPE_STRING, + "version" => $this->app->database::TYPE_STRING, + "package" => $this->app->database::TYPE_STRING, + "classname" => $this->app->database::TYPE_STRING, + "type" => $this->app->database::TYPE_STRING, + "data" => $this->app->database::TYPE_STRING + ]); + $this->app->database->addUnique("extensions", "id"); + + $this->app->database->createTable("assets", [ + "id" => $this->app->database::TYPE_INT, + "classname" => $this->app->database::TYPE_STRING, + "tablename" => $this->app->database::TYPE_STRING, + "slug" => $this->app->database::TYPE_STRING + ]); + $this->app->database->addPrimaryKey("assets", "id"); + + $this->app->assets->createTable("\\Crispage\\Assets\\Module"); + $this->app->assets->createTable("\\Crispage\\Assets\\Plugin"); + $this->app->assets->createTable("\\Crispage\\Assets\\Role"); + $this->app->assets->createTable("\\Crispage\\Assets\\User"); + + $this->app->database->createTable("sessions", [ + "id" => $this->app->database::TYPE_STRING, + "token_hash" => $this->app->database::TYPE_STRING, + "user_id" => $this->app->database::TYPE_INT, + "expire_time" => $this->app->database::TYPE_INT, + "ip_hash" => $this->app->database::TYPE_STRING + ]); + $this->app->database->addUnique("sessions", "id"); + + $this->app->database->createTable("passwd", [ + "user_id" => $this->app->database::TYPE_INT, + "password_hash" => $this->app->database::TYPE_STRING, + "expire_time" => $this->app->database::TYPE_INT + ]); + $this->app->database->addPrimaryKey("passwd", "user_id"); + + $this->app->database->createTable("rme", [ + "id" => $this->app->database::TYPE_STRING, + "token_hash" => $this->app->database::TYPE_STRING, + "user_id" => $this->app->database::TYPE_INT, + "expire_time" => $this->app->database::TYPE_INT + ]); + $this->app->database->addUnique("rme", "id"); + + $this->app->database->createTable("userconfirmation", [ + "user_id" => $this->app->database::TYPE_INT, + "token_hash" => $this->app->database::TYPE_STRING, + "expire_time" => $this->app->database::TYPE_INT + ]); + $this->app->database->addPrimaryKey("userconfirmation", "user_id"); + + $this->app->database->createTable("passwdreset", [ + "user_id" => $this->app->database::TYPE_INT, + "token_hash" => $this->app->database::TYPE_STRING, + "expire_time" => $this->app->database::TYPE_INT + ]); + $this->app->database->addPrimaryKey("passwdreset", "user_id"); + + // Create system table + $this->log("Filling system table"); + + $this->app->database->insert("system", [ + "iid" => uniqid("crispage_lite\${$db_prefix}$", true), + "version" => VERSION, + "next_asset_id" => 1 + ]); + + $this->log("Setting defaults"); + + $drole = $this->app->assets->create("\\Crispage\\Assets\\Role", [ + "slug" => "default", + "name" => "Default", + "rank" => "255", + "permissions" => CorePermissions::LOG_IN | CorePermissions::POST_COMMENT + ]); + + $settings = [ + "crispage.page.default_template" => "default", + "crispage.page.default_layout" => "default", + "crispage.date_format_short" => "Y-m-d", + "crispage.date_format_long" => "Y F j", + "crispage.time_format_short" => "H:i T", + "crispage.time_format_long" => "H:i:s T", + "crispage.timezone" => "Etc/UTC", + "crispage.auth.default_roles" => "[$drole->id]" + ]; + + foreach (CoreSettings::get() as $key => $_) + $this->app->settings->set($key, $settings[$key] ?? ""); + + $this->log("Creating super user"); + + $username = strval($iopts["ADMIN_ACCOUNT"] ?? "admin"); + $email = strval($iopts["ADMIN_EMAIL"] ?? ""); + $password = strval($this->app->request->params["admpasswd"] ?? ""); + + $role = $this->app->assets->create("\\Crispage\\Assets\\Role", [ + "slug" => "superuser", + "name" => "Super User", + "rank" => 0, + "permissions" => CorePermissions::ALL + ]); + + $user = $this->app->assets->create("\\Crispage\\Assets\\User", [ + "slug" => $username, + "displayname" => $username, + "email" => $email, + "state" => \Crispage\Assets\User::ACTIVATED, + "role_ids" => "[$role->id]" + ]); + + $this->app->auth->setPassword($user, $password); + $this->app->router->setRoute(new Route("/", "\\CrispageLite\\DefaultAction", [])); + + // Create config + $this->log("Creating configuration file"); + + $template = file_get_contents(PACKAGE_PATH . "/config_template.php"); + $nmatches = preg_match_all(\Crispage\Text\I18n::TS_REGEX, $template, $matches, PREG_OFFSET_CAPTURE); + $pos = 0; + $config = ""; + for ($i = 0; $i < $nmatches; $i++) { + $start = $matches[0][$i][1]; + $length = strlen($matches[0][$i][0]); + $key = $matches[1][$i][0]; + $config .= substr($template, $pos, $start - $pos); + $config .= $iopts[$key] ?? $key; + $pos = $start + $length; + } + $config .= substr($template, $pos); + if (file_put_contents(ROOT . "/config.php", $config) === false) + throw new Exception("Could not write configuration file! Is `" . ROOT . "/config.php` writable?"); + + $this->log("Removing update files"); + if (file_exists(ROOT . "/_crispage")) FileUtils::emptyDirectory(ROOT . "/_crispage"); + rmdir(ROOT . "/_crispage"); + file_put_contents(PACKAGE_PATH . "/version", VERSION); + + // Finish + $this->log("Crispage has been installed successfully!", $this::L_SUCCESS); +?> + + + + diff --git a/patch/packages/crispage.core/_crispage/scripts/uninstall.php b/patch/packages/crispage.core/_crispage/scripts/uninstall.php new file mode 100755 index 0000000..f206c24 --- /dev/null +++ b/patch/packages/crispage.core/_crispage/scripts/uninstall.php @@ -0,0 +1,13 @@ + + https://crispy.cat/software/crispage + + Crispage is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + */ + $this->log("Crispage can't (and doesn't want to) uninstall itself!", $this::L_FATAL); +?> diff --git a/patch/packages/crispage.core/config_template.php b/patch/packages/crispage.core/config_template.php new file mode 100755 index 0000000..7d6730e --- /dev/null +++ b/patch/packages/crispage.core/config_template.php @@ -0,0 +1,109 @@ + {>=12}] + public const PASSWD_OPTS = ["cost" => 12]; + // random token length in bytes prod: {>16} + public const TOKEN_BYTES = 16; + // Enable public user registration + public const ENABLE_USER_REGISTRATION = {%ENABLE_USER_REGISTRATION}; + // Media folders to which users can upload and delete files + public const MEDIA_WRITABLE_PATHS = [ + "/uploads", + "/assets" + ]; + // Mimetypes to disallow + public const MEDIA_MIMETYPE_BLACKLIST = [ + "text/x-php" + ]; + + /* + ⋄ Database settings + */ + public const DB_TYPE = "\Crispage\Database\MySQLDatabase"; + // Database location or host + public const DB_LOC = "{%DB_LOC}"; + // Database port + public const DB_PORT = {%DB_PORT}; + // Database name + public const DB_NAME = "{%DB_NAME}"; + // Database credentials + public const DB_USER = "{%DB_USER}"; + public const DB_PASSWD = "{%DB_PASSWD}"; + // Database table prefix + public const DB_PREFIX = "{%DB_PREFIX}"; + // Database PDO options + public const DB_OPTS = null; + + /* + ⋄ Development settings, modify at your own risk + */ + // Force error messages, even on 404 prod: false + public const DEV_FORCE_ERRMSGS = false; + // Disable output buffering prod: false + public const DEV_DISABLE_OB = false; + // Run modules in unsafe maode (debug) prod: false + public const DEV_MODULES_UNSAFE = false; + // PHP error level prod: E_ALL & ~E_DEPRECATED & ~E_STRICT + public const ERRLVL = E_ALL & ~E_DEPRECATED & ~E_STRICT; + // PHPMailer SMTP debug level <0-4> prod: 0 + public const SMTP_DEBUG = 0; + // Show database errors (should never be enabled on production servers) + public const SHOW_DB_ERRORS = false; + // Paths are relative to ROOT + public const CLASS_PATHS = [ + // Component paths + "\\Crispage\\Response\\Component" => [ + "/user/components", + "/core/components" + ], + // Action paths + "\\Crispage\\Response\\Action" => [ + "/user/actions", + "/core/actions" + ], + // Plugin paths + "\\Crispage\\PluginRunnable" => [ + "/user/plugins", + "/core/plugins" + ] + ]; + // Template path + public const TEMPLATE_PATH = [ + "/user/templates", + "/core/templates" + ]; + // Translation path + public const TRANSLATION_PATH = [ + "/user/translations", + "/core/translations", + ]; + // Media path + public const MEDIA_PATH = "/media"; + // URL to media server; set to null to use MEDIA_PATH + public const MEDIA_CUSTOM_PREFIX= null; + // Packages path + public const PACKAGE_PATH = "/packages"; + // Temporary files path + public const TEMP_PATH = "/temp"; + } +?> diff --git a/patch/packages/crispage.core/installer_config.php b/patch/packages/crispage.core/installer_config.php new file mode 100755 index 0000000..6c76027 --- /dev/null +++ b/patch/packages/crispage.core/installer_config.php @@ -0,0 +1,62 @@ + 12]; + public const TOKEN_BYTES = 16; + public const ENABLE_USER_REGISTRATION = true; + public const MEDIA_WRITABLE_PATHS = ["/"]; + public const MEDIA_MIMETYPE_BLACKLIST = []; + + public const DB_TYPE = "\Crispage\Database\MySQLDatabase"; + public const DB_LOC = "localhost"; + public const DB_PORT = 3306; + public const DB_NAME = "molyb_crispage"; + public const DB_USER = "crispage"; + public const DB_PASSWD = "Crispage20221110$$"; + public const DB_PREFIX = "cspg_"; + public const DB_OPTS = null; + + public const DEV_FORCE_ERRMSGS = true; + public const DEV_DISABLE_OB = true; + public const DEV_MODULES_UNSAFE = true; + public const ERRLVL = E_ALL; + public const SMTP_DEBUG = 1; + public const SHOW_DB_ERRORS = true; + public const CLASS_PATHS = [ + "\\Crispage\\Response\\Component" => [ + "/user/components", + "/core/components" + ], + "\\Crispage\\Response\\Action" => [ + "/user/actions", + "/core/actions" + ], + "\\Crispage\\PluginRunnable" => [ + "/user/plugins", + "/core/plugins" + ] + ]; + public const TEMPLATE_PATH = [ + "/user/templates", + "/core/templates" + ]; + public const TRANSLATION_PATH = [ + "/user/translations", + "/core/translations", + ]; + public const MEDIA_PATH = "/media"; + public const MEDIA_CUSTOM_PREFIX= null; + public const PACKAGE_PATH = "/packages"; + public const TEMP_PATH = "/temp"; + } +?> diff --git a/patch/packages/crispage.core/version b/patch/packages/crispage.core/version new file mode 100755 index 0000000..20d1e76 --- /dev/null +++ b/patch/packages/crispage.core/version @@ -0,0 +1 @@ +lite_0.20.1a_1 \ No newline at end of file