add yeswiki-move, fix shebangs, chore deps
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Florian Schmitt 2024-12-05 21:49:11 +03:00
parent cc25c7f947
commit 5de62d801c
6 changed files with 252 additions and 185 deletions

View file

@ -1,9 +1,9 @@
{ {
"require": { "require": {
"league/climate": "^3.8", "league/climate": "^3.8",
"devcoder-xyz/php-dotenv": "^1.1",
"league/plates": "^3.4", "league/plates": "^3.4",
"amphp/parallel": "^2.2", "amphp/parallel": "^2.2",
"amphp/http-client": "^5.0" "amphp/http-client": "^5.0",
"phpdevcommunity/php-dotenv": "^3.0"
} }
} }

151
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f4d486f76bc0e2d76db29133b0909637", "content-hash": "e3d3e7ac1605e6943e9c35a1317d6e7e",
"packages": [ "packages": [
{ {
"name": "amphp/amp", "name": "amphp/amp",
@ -391,16 +391,16 @@
}, },
{ {
"name": "amphp/http", "name": "amphp/http",
"version": "v2.1.1", "version": "v2.1.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/http.git", "url": "https://github.com/amphp/http.git",
"reference": "fe6b4dd50c1e70caf823092398074b5082e1d6da" "reference": "3680d80bd38b5d6f3c2cef2214ca6dd6cef26588"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/http/zipball/fe6b4dd50c1e70caf823092398074b5082e1d6da", "url": "https://api.github.com/repos/amphp/http/zipball/3680d80bd38b5d6f3c2cef2214ca6dd6cef26588",
"reference": "fe6b4dd50c1e70caf823092398074b5082e1d6da", "reference": "3680d80bd38b5d6f3c2cef2214ca6dd6cef26588",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -414,7 +414,7 @@
"amphp/php-cs-fixer-config": "^2", "amphp/php-cs-fixer-config": "^2",
"league/uri": "^6.8 | ^7.1", "league/uri": "^6.8 | ^7.1",
"phpunit/phpunit": "^9", "phpunit/phpunit": "^9",
"psalm/phar": "^5.4" "psalm/phar": "^5.26.1"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -443,7 +443,7 @@
"description": "Basic HTTP primitives which can be shared by servers and clients.", "description": "Basic HTTP primitives which can be shared by servers and clients.",
"support": { "support": {
"issues": "https://github.com/amphp/http/issues", "issues": "https://github.com/amphp/http/issues",
"source": "https://github.com/amphp/http/tree/v2.1.1" "source": "https://github.com/amphp/http/tree/v2.1.2"
}, },
"funding": [ "funding": [
{ {
@ -451,7 +451,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-04-03T18:00:53+00:00" "time": "2024-11-23T14:57:26+00:00"
}, },
{ {
"name": "amphp/http-client", "name": "amphp/http-client",
@ -550,16 +550,16 @@
}, },
{ {
"name": "amphp/parallel", "name": "amphp/parallel",
"version": "v2.2.9", "version": "v2.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/parallel.git", "url": "https://github.com/amphp/parallel.git",
"reference": "73d293f1fc4df1bebc3c4fce1432e82dd7032238" "reference": "9777db1460d1535bc2a843840684fb1205225b87"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/parallel/zipball/73d293f1fc4df1bebc3c4fce1432e82dd7032238", "url": "https://api.github.com/repos/amphp/parallel/zipball/9777db1460d1535bc2a843840684fb1205225b87",
"reference": "73d293f1fc4df1bebc3c4fce1432e82dd7032238", "reference": "9777db1460d1535bc2a843840684fb1205225b87",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -622,7 +622,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/amphp/parallel/issues", "issues": "https://github.com/amphp/parallel/issues",
"source": "https://github.com/amphp/parallel/tree/v2.2.9" "source": "https://github.com/amphp/parallel/tree/v2.3.0"
}, },
"funding": [ "funding": [
{ {
@ -630,7 +630,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-03-24T18:27:44+00:00" "time": "2024-09-14T19:16:14+00:00"
}, },
{ {
"name": "amphp/parser", "name": "amphp/parser",
@ -1142,50 +1142,6 @@
}, },
"time": "2024-04-12T12:12:48+00:00" "time": "2024-04-12T12:12:48+00:00"
}, },
{
"name": "devcoder-xyz/php-dotenv",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/devcoder-xyz/php-dotenv.git",
"reference": "1f478184b7fd199f5ffb0f89c1547f61c8172042"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/devcoder-xyz/php-dotenv/zipball/1f478184b7fd199f5ffb0f89c1547f61c8172042",
"reference": "1f478184b7fd199f5ffb0f89c1547f61c8172042",
"shasum": ""
},
"require": {
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.4"
},
"type": "library",
"autoload": {
"psr-4": {
"DevCoder\\": "src",
"Test\\DevCoder\\": "tests"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fad M.R",
"email": "fadymichel@devcoder.xyz"
}
],
"description": "Parses .env files",
"support": {
"issues": "https://github.com/devcoder-xyz/php-dotenv/issues",
"source": "https://github.com/devcoder-xyz/php-dotenv/tree/1.1.1"
},
"time": "2021-07-17T21:19:15+00:00"
},
{ {
"name": "kelunik/certificate", "name": "kelunik/certificate",
"version": "v1.1.3", "version": "v1.1.3",
@ -1246,16 +1202,16 @@
}, },
{ {
"name": "league/climate", "name": "league/climate",
"version": "3.8.2", "version": "3.10.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/climate.git", "url": "https://github.com/thephpleague/climate.git",
"reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28" "reference": "237f70e1032b16d32ff3f65dcda68706911e1c74"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/climate/zipball/a785a3ac8f584eed4abd45e4e16fe64c46659a28", "url": "https://api.github.com/repos/thephpleague/climate/zipball/237f70e1032b16d32ff3f65dcda68706911e1c74",
"reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28", "reference": "237f70e1032b16d32ff3f65dcda68706911e1c74",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1264,9 +1220,10 @@
"seld/cli-prompt": "^1.0" "seld/cli-prompt": "^1.0"
}, },
"require-dev": { "require-dev": {
"mikey179/vfsstream": "^1.6.10", "mikey179/vfsstream": "^1.6.12",
"mockery/mockery": "^1.4.2", "mockery/mockery": "^1.6.12",
"phpunit/phpunit": "^9.5.10" "phpunit/phpunit": "^9.5.10",
"squizlabs/php_codesniffer": "^3.10"
}, },
"suggest": { "suggest": {
"ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring" "ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring"
@ -1305,30 +1262,30 @@
], ],
"support": { "support": {
"issues": "https://github.com/thephpleague/climate/issues", "issues": "https://github.com/thephpleague/climate/issues",
"source": "https://github.com/thephpleague/climate/tree/3.8.2" "source": "https://github.com/thephpleague/climate/tree/3.10.0"
}, },
"time": "2022-06-18T14:42:08+00:00" "time": "2024-11-18T09:09:55+00:00"
}, },
{ {
"name": "league/plates", "name": "league/plates",
"version": "v3.5.0", "version": "v3.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/plates.git", "url": "https://github.com/thephpleague/plates.git",
"reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231" "reference": "12ee65166adbc6fb5916fb80b0c0758e49a2d996"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/plates/zipball/a6a3238e46c6e19af7318fdc36bfbe49b0620231", "url": "https://api.github.com/repos/thephpleague/plates/zipball/12ee65166adbc6fb5916fb80b0c0758e49a2d996",
"reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231", "reference": "12ee65166adbc6fb5916fb80b0c0758e49a2d996",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.0|^8.0" "php": "^8.0"
}, },
"require-dev": { "require-dev": {
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^11.4",
"squizlabs/php_codesniffer": "^3.5" "squizlabs/php_codesniffer": "^3.5"
}, },
"type": "library", "type": "library",
@ -1369,9 +1326,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/thephpleague/plates/issues", "issues": "https://github.com/thephpleague/plates/issues",
"source": "https://github.com/thephpleague/plates/tree/v3.5.0" "source": "https://github.com/thephpleague/plates/tree/v3.6.0"
}, },
"time": "2023-01-16T20:25:45+00:00" "time": "2024-11-02T15:03:35+00:00"
}, },
{ {
"name": "league/uri", "name": "league/uri",
@ -1629,6 +1586,50 @@
], ],
"time": "2024-03-23T07:42:40+00:00" "time": "2024-03-23T07:42:40+00:00"
}, },
{
"name": "phpdevcommunity/php-dotenv",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpdevcommunity/php-dotenv.git",
"reference": "cf8a190daca8fa504be1d85c0eb18d55001d4060"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpdevcommunity/php-dotenv/zipball/cf8a190daca8fa504be1d85c0eb18d55001d4060",
"reference": "cf8a190daca8fa504be1d85c0eb18d55001d4060",
"shasum": ""
},
"require": {
"php": ">=7.4"
},
"require-dev": {
"phpdevcommunity/unitester": "^0.1.0@alpha"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpDevCommunity\\": "src",
"Test\\PhpDevCommunity\\": "tests"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "F. Michel",
"homepage": "https://www.phpdevcommunity.com"
}
],
"description": "PHP-DotEnv is a lightweight PHP library designed to simplify the management of environment variables in your PHP applications.",
"support": {
"issues": "https://github.com/phpdevcommunity/php-dotenv/issues",
"source": "https://github.com/phpdevcommunity/php-dotenv/tree/3.0.0"
},
"time": "2024-10-07T08:33:46+00:00"
},
{ {
"name": "psr/http-factory", "name": "psr/http-factory",
"version": "1.1.0", "version": "1.1.0",

View file

@ -1,12 +1,13 @@
#!/usr/bin/php #!/usr/bin/env php
<?php <?php
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
require_once('utils.inc.php'); require_once('utils.inc.php');
use DevCoder\DotEnv; use PhpDevCommunity\DotEnv;
use League\CLImate\CLImate;
$climate = new League\CLImate\CLImate(); $climate = new CLImate();
$climate->description('yeswiki-installer, install YesWiki like a professionnal 🌈🦄'); $climate->description('yeswiki-installer, install YesWiki like a professionnal 🌈🦄');
if (0 == posix_getuid()) { if (0 == posix_getuid()) {

61
yeswiki-move.php Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env php
<?php
require_once('vendor/autoload.php');
require_once('utils.inc.php');
use PhpDevCommunity\DotEnv;
use League\CLImate\CLImate;
$climate = new CLImate();
$climate->description('yeswiki-move, move YesWiki like a professionnal 🌈🦄');
if (posix_getuid() != 0) {
$climate->error('ERROR : this script needs root privilege to run.');
exit;
}
$absolutePathToEnvFile = __DIR__ . '/.env';
if (file_exists($absolutePathToEnvFile)) {
(new DotEnv($absolutePathToEnvFile))->load();
} else {
$climate->error('ERROR : No .env file found.');
exit;
}
$climate->arguments->add([
'from' => [
'prefix' => 'f',
'longPrefix' => 'from',
'description' => 'Url of source wiki',
'required' => true,
'defaultValue' => 'https://example.com'
],
'to' => [
'prefix' => 't',
'longPrefix' => 'to',
'description' => 'Url of destination wiki',
'required' => true,
'defaultValue' => 'https://destination.com'
],
]);
$climate->arguments->parse();
$from = $climate->arguments->get('from');
$to = $climate->arguments->get('to');
if (empty($from) || $from == 'https://example.com' || empty($to) || $to == 'https://destination.com') {
$climate->error('ERROR : you need a --from (the source url) and a --to (the destination url).'."\n");
$climate->usage();
exit;
}
$climate->bold()->underline()->out('Move a YesWiki');
$climate->out('This will move yeswiki on <bold>'.$from.'</bold> to <bold>'.$to.'</bold>, CAREFULL the destination yeswiki will be rreplaced'."\n");
$input = $climate->confirm('Is it all good ?');
if ($input->confirmed()) {
$climate->shout(
'The yeswiki <bold>'.$from.'</bold> was successfully moved to <bold>'.$to.'</bold>, congrats ! 🎉'."\n"
);
} else {
$climate->info('Ok, let\'s stop here...');
}

View file

@ -1,11 +1,13 @@
#!/usr/bin/php #!/usr/bin/env php
<?php <?php
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
require_once('utils.inc.php'); require_once('utils.inc.php');
use DevCoder\DotEnv; use PhpDevCommunity\DotEnv;
use League\CLImate\CLImate;
$climate = new League\CLImate\CLImate(); $climate = new CLImate();
$climate->description('yeswiki-remover, remove a domain used for YesWiki because death is not the end 💀😈'); $climate->description('yeswiki-remover, remove a domain used for YesWiki because death is not the end 💀😈');
if (0 == posix_getuid()) { if (0 == posix_getuid()) {
@ -54,7 +56,7 @@ if (0 == posix_getuid()) {
$climate->shout( $climate->shout(
'The yeswiki on <bold>'.$domain.'</bold> was successfully removed, congrats ! 🎉'."\n" 'The yeswiki on <bold>'.$domain.'</bold> was successfully removed, congrats ! 🎉'."\n"
); );
// TODO : send log, send email // TODO : send log, send email
} else { } else {
$climate->info('Ok, let\'s stop here...'); $climate->info('Ok, let\'s stop here...');
} }

View file

@ -1,114 +1,116 @@
#!php #!/usr/bin/env php
<?php <?php
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
require_once('utils.inc.php'); require_once('utils.inc.php');
use DevCoder\DotEnv; use PhpDevCommunity\DotEnv;
use League\CLImate\CLImate;
$climate = new League\CLImate\CLImate(); $climate = new CLImate();
$climate->description('yeswiki-updater, find and update YesWiki like a professionnal 🌈🦄'); $climate->description('yeswiki-updater, find and update YesWiki like a professionnal 🌈🦄');
$isRoot = (0 == posix_getuid()); $isRoot = (0 == posix_getuid());
if ($isRoot) { if ($isRoot) {
$absolutePathToEnvFile = __DIR__ . '/.env'; $absolutePathToEnvFile = __DIR__ . '/.env';
if (file_exists($absolutePathToEnvFile)) { if (file_exists($absolutePathToEnvFile)) {
(new DotEnv($absolutePathToEnvFile))->load(); (new DotEnv($absolutePathToEnvFile))->load();
} else { } else {
$climate->error('ERROR : No .env file found.'); $climate->error('ERROR : No .env file found.');
exit;
}
$climate->arguments->add([
'path' => [
'prefix' => 'p',
'longPrefix' => 'path',
'description' => 'Path to scan for wikis',
'required' => true,
],
'output' => [
'prefix' => 'o',
'longPrefix' => 'output',
'description' => 'Output results in table format, json or csv',
'defaultValue' => 'table'
],
'update' => [
'prefix' => 'u',
'longPrefix' => 'update',
'description' => 'Update to latest version of stable yeswiki',
'noValue' => true
],
'depth' => [
'prefix' => 'd',
'longPrefix' => 'depth',
'description' => 'Depth to scan folders for wikis',
'defaultValue' => 1
],
]);
try {
$climate->arguments->parse();
} catch (\Throwable $th) {
if (!$climate->arguments->defined('path')) {
$climate->error('This command needs a valid path argument for example : -p /var/www/html');
$climate->usage();
return;
}
}
$path = $climate->arguments->get('path');
if (!empty($path) && is_dir($path)) {
try {
$update = $climate->arguments->get('update');
$output = $climate->arguments->get('output');
$depth = $climate->arguments->get('depth');
$matches = searchWikis($path, 'wakka.config.php', $depth);
if (count($matches) == 0) {
$climate->info('No yeswiki found on path ' . $path . ' with depth ' . $depth);
exit; exit;
}
if (count($matches) > 0 && $update) { // update yeswiki list
$climate->info('Update yeswiki');
$tmpFile = '/tmp/yeswiki.zip';
$destDir = '/tmp/yeswiki_for_update';
exec('rm -rf ' . $destDir . ' && mkdir -p ' . $destDir, $output);
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
exec('curl --insecure -s -o ' . $tmpFile . ' ' . $_SERVER['source_archive_url']);
exec('unzip ' . $tmpFile . ' "doryphore/*" -d ' . $destDir);
exec('mv ' . $destDir . '/doryphore/* ' . $destDir . '/');
exec('rm -rf ' . $destDir . '/doryphore');
unlink($tmpFile);
foreach ($matches as $k => $wiki) {
$climate->info(upgradeWiki($destDir, $wiki['PATH']));
}
} else { // show yeswiki list info
$climate->info(count($matches) . ' yeswikis found on ' . $path);
switch ($output) {
case 'table':
$climate->table($matches);
break;
case 'json':
$climate->json($matches);
break;
case 'csv':
$fileName = 'yeswiki-list.csv';
$file = fopen($fileName, "w");
foreach ($matches as $line) {
fputcsv($file, $line);
}
$climate->info($fileName . ' was created.');
break;
}
}
} catch (Exception $e) {
$climate->error('ERROR : ' . $e->getMessage());
} }
} else {
$climate->usage(); $climate->arguments->add([
} 'path' => [
'prefix' => 'p',
'longPrefix' => 'path',
'description' => 'Path to scan for wikis',
'required' => true,
],
'output' => [
'prefix' => 'o',
'longPrefix' => 'output',
'description' => 'Output results in table format, json or csv',
'defaultValue' => 'table'
],
'update' => [
'prefix' => 'u',
'longPrefix' => 'update',
'description' => 'Update to latest version of stable yeswiki',
'noValue' => true
],
'depth' => [
'prefix' => 'd',
'longPrefix' => 'depth',
'description' => 'Depth to scan folders for wikis',
'defaultValue' => 1
],
]);
try {
$climate->arguments->parse();
} catch (\Throwable $th) {
if (!$climate->arguments->defined('path')) {
$climate->error('This command needs a valid path argument for example : -p /var/www/html');
$climate->usage();
return;
}
}
$path = $climate->arguments->get('path');
if (!empty($path) && is_dir($path)) {
try {
$update = $climate->arguments->get('update');
$output = $climate->arguments->get('output');
$depth = $climate->arguments->get('depth');
$matches = searchWikis($path, 'wakka.config.php', $depth);
if (count($matches) == 0) {
$climate->info('No yeswiki found on path ' . $path . ' with depth ' . $depth);
exit;
}
if (count($matches) > 0 && $update) { // update yeswiki list
$climate->info('Update yeswiki');
$tmpFile = '/tmp/yeswiki.zip';
$destDir = '/tmp/yeswiki_for_update';
exec('rm -rf ' . $destDir . ' && mkdir -p ' . $destDir, $output);
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
exec('curl --insecure -s -o ' . $tmpFile . ' ' . $_SERVER['source_archive_url']);
exec('unzip ' . $tmpFile . ' "doryphore/*" -d ' . $destDir);
exec('mv ' . $destDir . '/doryphore/* ' . $destDir . '/');
exec('rm -rf ' . $destDir . '/doryphore');
unlink($tmpFile);
foreach ($matches as $k => $wiki) {
$climate->info(upgradeWiki($destDir, $wiki['PATH']));
}
} else { // show yeswiki list info
$climate->info(count($matches) . ' yeswikis found on ' . $path);
switch ($output) {
case 'table':
$climate->table($matches);
break;
case 'json':
$climate->json($matches);
break;
case 'csv':
$fileName = 'yeswiki-list.csv';
$file = fopen($fileName, "w");
foreach ($matches as $line) {
fputcsv($file, $line);
}
$climate->info($fileName . ' was created.');
break;
}
}
} catch (Exception $e) {
$climate->error('ERROR : ' . $e->getMessage());
}
} else {
$climate->usage();
}
} else { } else {
$climate->error('ERROR : this script needs root privilege to run.'); $climate->error('ERROR : this script needs root privilege to run.');
exit; exit;
} }