From 8cc220f80154a22761bf775296fe1e47d9849979 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 10 Jan 2023 19:05:32 +0000 Subject: [PATCH] add a cli command runner; update docs --- .gitattributes | 24 +++++------ .gitignore | 3 ++ INSTALL.md | 14 ++++--- NEWS.md | 10 +++-- debugger/controller.php | 10 +++-- doc/manual/phpxmlrpc_manual.adoc | 2 +- taskfile | 71 ++++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 26 deletions(-) create mode 100755 taskfile diff --git a/.gitattributes b/.gitattributes index 8faacf8b..bf515ae0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1,15 @@ *.inc diff=php -.githooks/ export-ignore -.github/ export-ignore -demo/ export-ignore -doc/api_changes_v4.md export-ignore -doc/build/ export-ignore -doc/Changelog -extras/ export-ignore -tests/ export-ignore +/.githooks/ export-ignore +/.github/ export-ignore +/demo/ export-ignore +/doc/api_changes_v4.md export-ignore +/doc/build/ export-ignore +/doc/Changelog +/extras/ export-ignore +/tests/ export-ignore -.editorconfig export-ignore -.gitattributes export-ignore -.gitignore export-ignore -phpunit.xml.dist export-ignore +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index 0f22b822..afccab0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ /.scannerwork /.idea +/debugger/jsxmlrpc +/debugger/node_modules +/debugger/vendor /doc/api /doc/build/.phpdoc /doc/build/.phive diff --git a/INSTALL.md b/INSTALL.md index 40a36b88..a5d00a48 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -51,17 +51,13 @@ Installation of the library is quite easy: use PhpXmlRpc\Request; use PhpXmlRpc\Client; - $client = new Client('http://some/server'); + $client = new Client('https://some/server'); $response = $client->send(new Request('method', array(new Value('parameter')))); 5. IMPORTANT! Make sure that the vendor/phpxmlrpc directory is not directly accessible from the internet, as leaving it open to access means that any visitor can trigger execution of php code such as the built-in debugger. - Tip: to reduce the size of the download, the demo files are not part of the default package installed with Composer. - You can either check them out online at https://github.com/gggeek/phpxmlrpc/tree/master/demo, or make sure they are - available locally, by installing the library using Composer option `--prefer-install=source`. - 2. Via manual download and autoload configuration 1. download the zip or tarball version of the phpxmlrpc library from GitHub and unzip it in a temporary folder @@ -83,9 +79,15 @@ Installation of the library is quite easy: use PhpXmlRpc\Request; use PhpXmlRpc\Client; - $client = new Client('http://some/server'); + $client = new Client('https://some/server'); $response = $client->send(new Request('method', array(new Value('parameter')))); 5. IMPORTANT! Make sure that the phpxmlrpc root directory is not directly accessible from the internet, as leaving it open to access means that any visitor can trigger execution of php code such as the built-in debugger. + +Tip: to reduce the size of the download, the demo files are not part of the default package installed with Composer. +You can either check them out online at https://github.com/gggeek/phpxmlrpc/tree/master/demo, or make sure they are +available locally, by either installing the library using Composer option `--prefer-install=source`, running +`./taskfile download_demos` (requires bash, curl, tar commands), or manually downloading them from +https://github.com/gggeek/phpxmlrpc/releases. diff --git a/NEWS.md b/NEWS.md index 5b1c5941..e0a76c5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,11 @@ ## XML-RPC for PHP version 4.xx - unreleased * improved: revised all demo files. Showcase more features in client demos; isolate better testsuite functions in - server demos and make sure they are not active unless triggered by running the tests + server demos and make sure they are not active unless triggered by running the tests; add demos for code-generation + for both clients and servers + +* improved: added command `taskfile`, which can be used to download the demo files or the visualeditor component for + the debugger (requires bash, curl) * improved: for php 7 and up, catch php Errors besides Exceptions thrown by method handler functions (ie. server-side) @@ -9,7 +13,7 @@ fault Code 0, as it breaks response serialization -## XML-RPC for PHP version 4.9.4 - 2023-1-7 +## XML-RPC for PHP version 4.9.4 - 2023/1/7 * improved: updated the user's manual to be inline with the version4 API and modern coding practices. The manual is now bundled in the default distribution tarball, and is easily viewable as html, provided you can @@ -25,7 +29,7 @@ * fixed: the value for error 'no_http2' has been switched from 15 to 19 to avoid a collision -## XML-RPC for PHP version 4.9.3 - 2022-12-20 +## XML-RPC for PHP version 4.9.3 - 2022/12/20 * improved: avoid stalling the webserver when using the debugger with the php cli-webserver and testing the demo server within the same install diff --git a/debugger/controller.php b/debugger/controller.php index 286071f3..6cc65d5c 100644 --- a/debugger/controller.php +++ b/debugger/controller.php @@ -38,9 +38,11 @@ if (defined('JSXMLRPC_BASEURL')) { $editorpaths = array( __DIR__ . '/vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer in debugger __DIR__ . '/node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm in debugger + __DIR__ . '/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via taskfile in debugger __DIR__ . '/../vendor/phpxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via composer __DIR__ . '/../node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is top-level, jsxmlrpc installed via npm __DIR__ . '/../../jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc too + __DIR__ . '/../../../../web/node_modules/@jsxmlrpc/jsxmlrpc/debugger/', // this package is a composer dependency, jsxmlrpc installed via npm ); } foreach($editorpaths as $editorpath) { @@ -50,10 +52,10 @@ if (defined('JSXMLRPC_BASEURL')) { } } if ($haseditor) { - $editorurlpath = preg_replace('|^' . preg_quote(__DIR__, '|') .'|', '', $editorpath); - - /// @todo for cases 3, 4 and 5 above, look at `parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)` and check if the - /// web root is not pointing directly at this folder, as in that case the link to the visualeditor will not + $controllerRootUrl = str_replace('/controller.php', '', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); + $editorurlpath = $controllerRootUrl . '/' . preg_replace('|^' . preg_quote(__DIR__, '|') .'|', '', $editorpath); + /// @todo for cases above 4, 5 and up, look at $controllerRootUrl and check if the web root is not pointing directly + /// at this folder, as in that case the link to the visualeditor will not /// work, as it will be in the form http(s)://domain/../../jsxmlrpc/debugger/visualeditor.html } } diff --git a/doc/manual/phpxmlrpc_manual.adoc b/doc/manual/phpxmlrpc_manual.adoc index fd554b41..3e3efc68 100644 --- a/doc/manual/phpxmlrpc_manual.adoc +++ b/doc/manual/phpxmlrpc_manual.adoc @@ -1752,7 +1752,7 @@ tests/*:: the test suite for the library, written using PhpUnit, and the configu *Note* the standard procedure to download locally the demo and test files is to use Composer with the option `--prefer-install=source` on the command line. That requires to have `git` installed. If that is not the case on your server, you might be able to -download the complete source code from GitHub with other tools, such as f.e. TortoiseSVN. Staring with release 4.9.4, +download the complete source code from GitHub with other tools, such as f.e. TortoiseSVN. Starting with release 4.9.4, the demo files are also available for download as a separate tarball from the releases page on GitHub. *Note* when downloading the demo files, make sure that the demo folder is not directly accessible from the internet, i.e. diff --git a/taskfile b/taskfile new file mode 100755 index 00000000..68430911 --- /dev/null +++ b/taskfile @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -e + +# @todo test all commands on mac, windows-wsl. If there are issues, rewrite this in (plain, no dependencies) php or make it a polyglot? + +function download_demos() { + # @todo check for presence of curl, tar, grep, sed and tr first + # NB: we always get the demos matching the current version, not the last one available + #TAG=$(curl -s https://api.github.com/repos/gggeek/phpxmlrpc/releases/latest | grep "tag_name" | cut -d : -f 2,3 | tr -d \" | tr -d , | tr -d ' ') + TAG=$(grep 'public \+static \+$xmlrpcVersion *=' src/PhpXmlRpc.php | sed 's/public \+static \+$xmlrpcVersion *= *//' | tr -d ' ' | tr -d \" | tr -d ';' | tr -d "'") + curl -fsSL -o demofiles.tgz "https://github.com/gggeek/phpxmlrpc/releases/download/${TAG}/demofiles.tgz" + tar -xvzf demofiles.tgz + rm demofiles.tgz +} + +function remove_demos() { + ROOT_DIR="$(pwd)" + if [ -d "${ROOT_DIR}/demo" ]; then rm -rf "${ROOT_DIR}/demo"; fi +} + +# @todo can we find a better name than this? +function setup_debugger_visualeditor() { + ROOT_DIR="$(pwd)" + cd "${TMPDIR-/tmp}" + # avoid use of npm - use as few dependencies as possible + # @todo check for presence of npm first and use it if found - note that that would leave on disk much more stuff than the manual method... + # @todo check for presence of curl, grep, cut, tr and unzip first; if unzip is missing but tar is present, download tarball instead + # @todo should we filter the release number, eg. removing betas and anything above 0.6.x (or 0.x) ? + TAG=$(curl -s https://api.github.com/repos/gggeek/jsxmlrpc/releases/latest | grep "tag_name" | cut -d : -f 2,3 | tr -d \" | tr -d , | tr -d ' ') + #TAG="$(npm show @jsxmlrpc/jsxmlrpc@0.6 version | tail -1 | awk '{print $2}' | tr -d "'")" + curl -fsSL -o jsxmlrpc.zip "https://github.com/gggeek/jsxmlrpc/archive/refs/tags/${TAG}.zip" + unzip jsxmlrpc.zip + mv jsxmlrpc-* jsxmlrpc + if [ ! -d "${ROOT_DIR}/debugger/jsxmlrpc" ]; then mkdir -p "${ROOT_DIR}/debugger/jsxmlrpc"; fi + cp -R jsxmlrpc/lib "${ROOT_DIR}/debugger/jsxmlrpc" + cp -R jsxmlrpc/debugger "${ROOT_DIR}/debugger/jsxmlrpc" + rm -rf jsxmlrpc* +} + +function remove_debugger_visualeditor() { + ROOT_DIR="$(pwd)" + if [ -d "${ROOT_DIR}/debugger/jsxmlrpc" ]; then rm -rf "${ROOT_DIR}/debugger/jsxmlrpc"; fi +} + +function tag_code() { + TAG="$1" + if [ -n "${TAG}" ]; then + echo "Error: miss first argument: tag" >&2 + exit 1 + fi + sed -i -e "s/public \+static \+\$xmlrpcVersion *=.\+/public \+static \+\$xmlrpcVersion = \"$TAG\";/" src/PhpXmlRpc.php + sed -i -e "s/PhpxmlRpc\\\\PhpXmlRpc::\$xmlrpcVersion *=.\+/PhpXmlRpc\PhpXmlRpc::\$xmlrpcVersion = \"$TAG\"/" doc/manual/phpxmlrpc_manual.adoc + sed -i -e "3s/.*/$TAG/" doc/manual/phpxmlrpc_manual.adoc + sed -i -e "1s/.*/## XML-RPC for PHP version $TAG - $(date +%Y/%m/%d)/" NEWS.md +} + +function help() { + echo "$0 " + echo "Tasks:" + compgen -A function | cat -n +} + +if [ $# -eq 0 ]; then + help +else + cd "$(dirname -- "$(realpath "${BASH_SOURCE[0]}")")" + + TIMEFORMAT="Task completed in %3lR" + time ${@} +fi -- 2.47.0