From b65642cd0af0d86ed0086abdcd26f805cb036128 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Sun, 8 Aug 2021 19:23:49 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 + config.example.php | 25 + config.php | 27 + configure_nginx.php | 34 + index.php | 71 ++ load_config.php | 14 + modules/date/date.php | 10 + modules/date/date_help.php | 1073 +++++++++++++++++++++++++++ modules/httpbin/httpbin.php | 9 + modules/logator/logator.php | 112 +++ modules/logator/logator_help.php | 18 + modules/printip/printip.php | 3 + modules/quicknote/quicknote.php | 31 + modules/quickupload/quickupload.php | 29 + modules/random/random.php | 9 + modules/random/random_help.php | 23 + nginx.conf.template | 15 + utils.php | 38 + 18 files changed, 1543 insertions(+) create mode 100644 .gitignore create mode 100644 config.example.php create mode 100644 config.php create mode 100644 configure_nginx.php create mode 100644 index.php create mode 100644 load_config.php create mode 100644 modules/date/date.php create mode 100644 modules/date/date_help.php create mode 100644 modules/httpbin/httpbin.php create mode 100644 modules/logator/logator.php create mode 100644 modules/logator/logator_help.php create mode 100644 modules/printip/printip.php create mode 100644 modules/quicknote/quicknote.php create mode 100644 modules/quickupload/quickupload.php create mode 100644 modules/random/random.php create mode 100644 modules/random/random_help.php create mode 100644 nginx.conf.template create mode 100644 utils.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1586e95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tmp + diff --git a/config.example.php b/config.example.php new file mode 100644 index 0000000..99b9340 --- /dev/null +++ b/config.example.php @@ -0,0 +1,25 @@ + 'lefuturiste.fr', + 'modules' => [ + 'random' => [], + 'date' => [ + 'alias' => ['printdate'] + ], + 'httpbin' => [], + 'printip' => [ + 'alias' => ['ip', 'getip'] + ], + 'quicknote' => [ + 'auth' => true + ], + 'quickupload' => [ + 'auth' => true + ], + 'logator' => [] + ], + 'auth' => [ + 'root' => 'password' + ] +]; \ No newline at end of file diff --git a/config.php b/config.php new file mode 100644 index 0000000..347a8b2 --- /dev/null +++ b/config.php @@ -0,0 +1,27 @@ + 'lefuturiste.fr', + 'modules' => [ + 'random' => [], + 'date' => [ + 'alias' => ['printdate'] + ], + 'httpbin' => [], + 'printip' => [ + 'alias' => ['ip', 'getip'] + ], + 'quicknote' => [ + 'auth' => true + ], + 'quickupload' => [ + 'auth' => true + ], + 'logator' => [ + 'alias' => ['logme'] + ] + ], + 'auth' => [ + 'root' => 'password' + ] +]; \ No newline at end of file diff --git a/configure_nginx.php b/configure_nginx.php new file mode 100644 index 0000000..f26006c --- /dev/null +++ b/configure_nginx.php @@ -0,0 +1,34 @@ + This script will generate a folder in the current directory where you can find every config file to use to make this thing works with nginx \n"; +echo "\n"; + +$appBasePath = __DIR__; + +$path = $appBasePath . '/tmp/generated_nginx_conf'; +if (!file_exists($path)) { + mkdir($path, 0777, true); +} + +require('./load_config.php'); + +$template = file_get_contents('./nginx.conf.template'); +$phpSocket = '/var/run/php/php8.0-fpm.sock'; + +foreach ($config['modules'] as $moduleName => $moduleConfig) { + $domains = array_merge([$moduleName], $moduleConfig['alias'] ?? []); + $domains = array_map(fn ($d) => $d . '.' . $config['domain'], $domains); + $serverName = implode(' ', $domains); + + $rootPath = $appBasePath . '/' . $domains[0]; + + $nginxConfig = $template; + $nginxConfig = str_replace('{{ROOT_PATH}}', $rootPath, $nginxConfig); + $nginxConfig = str_replace('{{SERVER_NAME}}', $serverName, $nginxConfig); + $nginxConfig = str_replace('{{PHP_SOCKET}}', $phpSocket, $nginxConfig); + + file_put_contents($path . '/' . $domains[0], $nginxConfig); + echo "> Wrote " . strlen($nginxConfig) . " bytes in " . $path . '/' . $domains[0] . "\n"; +} +echo "\n"; +echo "> Done.\n"; diff --git a/index.php b/index.php new file mode 100644 index 0000000..b637648 --- /dev/null +++ b/index.php @@ -0,0 +1,71 @@ +Help for module \"$selectedModule\""; + echo "