feat(yeswiki-installer): first cli script and utils WIP
This commit is contained in:
parent
27b02fcc02
commit
12b6a9b0c2
4 changed files with 372 additions and 0 deletions
5
composer.json
Normal file
5
composer.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"league/climate": "^3.8"
|
||||||
|
}
|
||||||
|
}
|
189
composer.lock
generated
Normal file
189
composer.lock
generated
Normal file
|
@ -0,0 +1,189 @@
|
||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "7804f603c1e45b579e09b65c72451f75",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "league/climate",
|
||||||
|
"version": "3.8.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/thephpleague/climate.git",
|
||||||
|
"reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/thephpleague/climate/zipball/a785a3ac8f584eed4abd45e4e16fe64c46659a28",
|
||||||
|
"reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.3 || ^8.0",
|
||||||
|
"psr/log": "^1.0 || ^2.0 || ^3.0",
|
||||||
|
"seld/cli-prompt": "^1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mikey179/vfsstream": "^1.6.10",
|
||||||
|
"mockery/mockery": "^1.4.2",
|
||||||
|
"phpunit/phpunit": "^9.5.10"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"League\\CLImate\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Joe Tannenbaum",
|
||||||
|
"email": "hey@joe.codes",
|
||||||
|
"homepage": "http://joe.codes/",
|
||||||
|
"role": "Developer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Craig Duncan",
|
||||||
|
"email": "git@duncanc.co.uk",
|
||||||
|
"homepage": "https://github.com/duncan3dc",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.",
|
||||||
|
"keywords": [
|
||||||
|
"cli",
|
||||||
|
"colors",
|
||||||
|
"command",
|
||||||
|
"php",
|
||||||
|
"terminal"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/thephpleague/climate/issues",
|
||||||
|
"source": "https://github.com/thephpleague/climate/tree/3.8.2"
|
||||||
|
},
|
||||||
|
"time": "2022-06-18T14:42:08+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/log",
|
||||||
|
"version": "3.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/log.git",
|
||||||
|
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001",
|
||||||
|
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.0.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\Log\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "https://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common interface for logging libraries",
|
||||||
|
"homepage": "https://github.com/php-fig/log",
|
||||||
|
"keywords": [
|
||||||
|
"log",
|
||||||
|
"psr",
|
||||||
|
"psr-3"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/php-fig/log/tree/3.0.0"
|
||||||
|
},
|
||||||
|
"time": "2021-07-14T16:46:02+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "seld/cli-prompt",
|
||||||
|
"version": "1.0.4",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Seldaek/cli-prompt.git",
|
||||||
|
"reference": "b8dfcf02094b8c03b40322c229493bb2884423c5"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/Seldaek/cli-prompt/zipball/b8dfcf02094b8c03b40322c229493bb2884423c5",
|
||||||
|
"reference": "b8dfcf02094b8c03b40322c229493bb2884423c5",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpstan/phpstan": "^0.12.63"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Seld\\CliPrompt\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jordi Boggiano",
|
||||||
|
"email": "j.boggiano@seld.be"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Allows you to prompt for user input on the command line, and optionally hide the characters they type",
|
||||||
|
"keywords": [
|
||||||
|
"cli",
|
||||||
|
"console",
|
||||||
|
"hidden",
|
||||||
|
"input",
|
||||||
|
"prompt"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/Seldaek/cli-prompt/issues",
|
||||||
|
"source": "https://github.com/Seldaek/cli-prompt/tree/1.0.4"
|
||||||
|
},
|
||||||
|
"time": "2020-12-15T21:32:01+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": [],
|
||||||
|
"platform-dev": [],
|
||||||
|
"plugin-api-version": "2.3.0"
|
||||||
|
}
|
44
yeswiki-installer.php
Executable file
44
yeswiki-installer.php
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
require_once('vendor/autoload.php');
|
||||||
|
require_once('yeswiki-installer.utils.inc.php');
|
||||||
|
|
||||||
|
$climate = new League\CLImate\CLImate;
|
||||||
|
$climate->description('yeswiki-installer, install YesWiki like a professionnal 🌈🦄');
|
||||||
|
$climate->arguments->add([
|
||||||
|
'domain' => [
|
||||||
|
'prefix' => 'd',
|
||||||
|
'longPrefix' => 'domain',
|
||||||
|
'description' => 'Domain name used for installation',
|
||||||
|
'required' => true,
|
||||||
|
'defaultValue' => 'example.com'
|
||||||
|
],
|
||||||
|
'type' => [
|
||||||
|
'prefix' => 't',
|
||||||
|
'longPrefix' => 'type',
|
||||||
|
'description' => 'Type of installation, can be "solo" or "ferme"',
|
||||||
|
'required' => true,
|
||||||
|
'defaultValue' => 'solo'
|
||||||
|
],
|
||||||
|
'quota' => [
|
||||||
|
'prefix' => 'q',
|
||||||
|
'longPrefix' => 'quota',
|
||||||
|
'description' => 'User quota for hard drive space, in bytes',
|
||||||
|
'required' => true,
|
||||||
|
'defaultValue' => 2000000,
|
||||||
|
'castTo' => 'int'
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$climate->arguments->parse();
|
||||||
|
$domain = $climate->arguments->get('domain');
|
||||||
|
if (!empty($domain) && $domain !== 'example.com') {
|
||||||
|
$climate->bold()->underline()->out('Installation of YesWiki on '.$domain);
|
||||||
|
$res = installYesWiki($domain, $climate->arguments->get('quota'), $climate->arguments->get('type'));
|
||||||
|
if (!empty($res['error'])) {
|
||||||
|
$climate->error('ERROR : '.$res['error']);
|
||||||
|
} else {
|
||||||
|
$climate->dump($res);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$climate->usage();
|
||||||
|
}
|
134
yeswiki-installer.utils.inc.php
Normal file
134
yeswiki-installer.utils.inc.php
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function checkDNS($domain, $ip4 = '138.201.86.17', $ip6 = '2a01:4f8:172:21c9::2') {
|
||||||
|
if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) {
|
||||||
|
return ['error' => 'Not valid domain.'];
|
||||||
|
}
|
||||||
|
$currentip = dns_get_record($domain, DNS_A + DNS_AAAA);
|
||||||
|
if ($currentip[0]['ip'] !== $ip4) {
|
||||||
|
return ['error' => 'The current ip v4 address of '.$domain.' is '.$currentip[0]['ip'].'. it should be '.$ip4];
|
||||||
|
}
|
||||||
|
if ($currentip[1]['ipv6'] !== $ip6) {
|
||||||
|
return ['error' => 'The current ip v6 address of '.$domain.' is '.$currentip[1]['ipv6'].'. it should be '.$ip6];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIfInstalled($domain) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIfUserExist($user) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateUserFromDomain($domain, $recursive = null) {
|
||||||
|
$user = 'toto';
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
function generatePassword($length = 32, $add_dashes = false, $available_sets = 'luds') {
|
||||||
|
$sets = array();
|
||||||
|
if(strpos($available_sets, 'l') !== false)
|
||||||
|
$sets[] = 'abcdefghjkmnpqrstuvwxyz';
|
||||||
|
if(strpos($available_sets, 'u') !== false)
|
||||||
|
$sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';
|
||||||
|
if(strpos($available_sets, 'd') !== false)
|
||||||
|
$sets[] = '23456789';
|
||||||
|
if(strpos($available_sets, 's') !== false)
|
||||||
|
$sets[] = '!@#$%&*?';
|
||||||
|
|
||||||
|
$all = '';
|
||||||
|
$password = '';
|
||||||
|
foreach($sets as $set)
|
||||||
|
{
|
||||||
|
$password .= $set[array_rand(str_split($set))];
|
||||||
|
$all .= $set;
|
||||||
|
}
|
||||||
|
|
||||||
|
$all = str_split($all);
|
||||||
|
for($i = 0; $i < $length - count($sets); $i++)
|
||||||
|
$password .= $all[array_rand($all)];
|
||||||
|
|
||||||
|
$password = str_shuffle($password);
|
||||||
|
|
||||||
|
if(!$add_dashes)
|
||||||
|
return $password;
|
||||||
|
|
||||||
|
$dash_len = floor(sqrt($length));
|
||||||
|
$dash_str = '';
|
||||||
|
while(strlen($password) > $dash_len)
|
||||||
|
{
|
||||||
|
$dash_str .= substr($password, 0, $dash_len) . '-';
|
||||||
|
$password = substr($password, $dash_len);
|
||||||
|
}
|
||||||
|
$dash_str .= $password;
|
||||||
|
return $dash_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSQLUserAndDatabase($user) {
|
||||||
|
$pass = generatePassword();
|
||||||
|
return ['database' => 'dbtata', 'user' => 'dbtata', 'password' => $pass];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createUnixUserWithQuota($user, $quota) {
|
||||||
|
$pass = generatePassword();
|
||||||
|
return ['user' => 'toto', 'password' => $pass, 'quota' => $quota];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNginxConfig($domain, $user) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function createPhpFpmConfig($user) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyYesWikiFiles($domain, $user) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyYesWikiDatabase($databaseModel) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addHerse($id, $pass) {
|
||||||
|
return ['user' => $id, 'password' => $pass];
|
||||||
|
}
|
||||||
|
|
||||||
|
function installYesWiki($domain, $quota, $type) {
|
||||||
|
$res = checkDNS($domain);
|
||||||
|
if (!empty($res['error'])) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
$res = checkIfInstalled($domain);
|
||||||
|
if (!empty($res['error'])) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
$user = generateUserFromDomain($domain);
|
||||||
|
$unixUser = createUnixUserWithQuota($user, $quota);
|
||||||
|
$dbUser = createSQLUserAndDatabase($user);
|
||||||
|
createNginxConfig($domain, $user);
|
||||||
|
createPhpFpmConfig($user);
|
||||||
|
copyYesWikiFiles($domain, $user);
|
||||||
|
$databaseModel = ($type === 'solo') ? 'modelesolo' : 'modeleferme' ;
|
||||||
|
copyYesWikiDatabase($databaseModel);
|
||||||
|
|
||||||
|
$herseUser = [];
|
||||||
|
if (!empty($herseId) && !empty($hersePass)) {
|
||||||
|
$herseUser = addHerse($herseId, $hersePass);
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'domain'=> $domain,
|
||||||
|
'type' => $type,
|
||||||
|
'user' => $unixUser,
|
||||||
|
'db' => $dbUser,
|
||||||
|
'herse' => $herseUser
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeYesWiki($domain, $user) {
|
||||||
|
// enlever la db et le user sql
|
||||||
|
// enlever la config nginx et la conf php-fpm
|
||||||
|
// enlever le user unix et son home
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue