Skip to content

Commit

Permalink
Merge pull request #10 from wirecli/fix-config
Browse files Browse the repository at this point in the history
Fix config
  • Loading branch information
flydev-fr authored Oct 27, 2023
2 parents 35a0998 + d250942 commit b8df094
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ jobs:
run: npm run release --ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Contributors Images
uses: jaywcjlove/github-action-contributors@main
id: contributors
with:
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
avatarSize: 32
- name: Modify README.md
uses: jaywcjlove/github-action-modify-file-content@main
with:
path: README.md
body: '${{steps.contributors.outputs.htmlList}}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ phpunit.xml
ProcessWire
Tests/processwire.zip

Tests/pw
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ https://processwire.com/talk/topic/28788-wire-cli-a-cli-tool-for-processwire-dev

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please submit an issue or a pull request on the [GitHub repository](https://github.com/wirecli/wire-cli).

## Contributors

As always, thanks to all the contributors!

<!--GAMFC--><!--GAMFC-END-->


## Available commands

![Commands preview](https://github.com/wirecli/wire-cli/blob/main/docs/assets/capture-cmd.jpg)
Expand Down
68 changes: 43 additions & 25 deletions src/Helpers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Installer {
* Minimum required PHP version to install ProcessWire
*
*/
const MIN_REQUIRED_PHP_VERSION = '7.4.0';
const MIN_REQUIRED_PHP_VERSION = '5.3.8';

/**
* Test mode for installer development, non destructive
Expand All @@ -62,7 +62,7 @@ class Installer {
* Default site profile
*
*/
const PROFILE_DEFAULT = 'site-default';
const PROFILE_DEFAULT = 'site-blank';

/**
* File permissions, determined in the dbConfig function
Expand All @@ -79,15 +79,6 @@ class Installer {
*/
protected $numErrors = 0;

/**
* Available color themes
*
*/
protected $colors = array(
'classic',
'warm'
);

/**
* @param LoggerInterface $log
*/
Expand Down Expand Up @@ -354,7 +345,17 @@ public function checkDatabaseConnection($values, $out = true) {
* @param array $values
*/
protected function dbSaveConfigFile(array $values) {
$salt = md5(mt_rand() . microtime(true));
$file = __FILE__;
$time = time();
$host = empty($values['httpHosts']) ? '' : implode(',', $values['httpHosts']);

if(function_exists('random_bytes')) {
$authSalt = sha1(random_bytes(random_int(40, 128)));
$tableSalt = sha1(random_int(0, 65535) . "$host$file$time");
} else {
$authSalt = md5(mt_rand() . microtime(true));
$tableSalt = md5(mt_rand() . "$host$file$time");
}

$cfg = "\n/**" .
"\n * Installer: Database Configuration" .
Expand All @@ -366,14 +367,27 @@ protected function dbSaveConfigFile(array $values) {
"\n\$config->dbPass = '$values[dbPass]';" .
"\n\$config->dbPort = '$values[dbPort]';" .
"\n" .
"\n/**" .
"\n * Installer: User Authentication Salt " .
"\n * " .
"\n * Must be retained if you migrate your site from one server to another" .
"\n * " .
"\n */" .
"\n\$config->userAuthSalt = '$salt'; " .
"\n" .
"\n/**" .
"\n * Installer: User Authentication Salt " .
"\n * " .
"\n * This value was randomly generated for your system on " . date('Y/m/d') . "." .
"\n * This should be kept as private as a password and never stored in the database." .
"\n * Must be retained if you migrate your site from one server to another." .
"\n * Do not change this value, or user passwords will no longer work." .
"\n * " .
"\n */" .
"\n\$config->userAuthSalt = '$authSalt'; " .
"\n" .
"\n/**" .
"\n * Installer: Table Salt (General Purpose) " .
"\n * " .
"\n * Use this rather than userAuthSalt when a hashing salt is needed for non user " .
"\n * authentication purposes. Like with userAuthSalt, you should never change " .
"\n * this value or it may break internal system comparisons that use it. " .
"\n * " .
"\n */" .
"\n\$config->tableSalt = '$tableSalt'; " .
"\n" .
"\n/**" .
"\n * Installer: File Permission Configuration" .
"\n * " .
Expand All @@ -392,6 +406,15 @@ protected function dbSaveConfigFile(array $values) {
"\n *" .
"\n */".
"\n\$config->defaultAdminTheme = 'AdminThemeUikit';" .
"\n" .
"\n/**" .
"\n * Installer: Unix timestamp of date/time installed" .
"\n * " .
"\n * This is used to detect which when certain behaviors must be backwards compatible." .
"\n * Please leave this value as-is." .
"\n * " .
"\n */" .
"\n\$config->installed = " . time() . ";" .
"\n\n";

if (!empty($values['httpHosts'])) {
Expand Down Expand Up @@ -611,14 +634,9 @@ protected function adminAccountSave($accountInfo) {
$adminName = htmlentities($adminName, ENT_QUOTES, "UTF-8");

if ($this->v) $this->log->info("User account saved: <b>{$user->name}</b>");

$colors = $wire->sanitizer->pageName($accountInfo['colors']);
if (!in_array($colors, $this->colors)) $colors = reset($this->colors);
$theme = $wire->modules->getInstall('AdminThemeUikit');
$configData = $wire->modules->getModuleConfigData('AdminThemeUikit');
$configData['colors'] = $colors;
$wire->modules->saveModuleConfigData('AdminThemeUikit', $configData);
if ($this->v) $this->log->info("Saved admin color set <b>$colors</b> - you will see this when you login.");

if ($this->v) $this->log->info("It is recommended that you make <b>/site/config.php</b> non-writable, for security.");

Expand Down

0 comments on commit b8df094

Please sign in to comment.