[json-arg ...] // JSON args are decoded (so '["openscribe","/var/www/openscribe"]'-style or bare values work). $key = trim((string)file_get_contents('C:/temp/claudetemp/apiscp.key')); if ($key === '') { fwrite(STDERR, "no api key\n"); exit(2); } $endpoint = 'https://howler.qsplace.co.uk:2083'; // Use a locally-cached WSDL to avoid a second HTTPS fetch; fall back to remote. $wsdl = is_file('C:/temp/claudetemp/apnscp.wsdl') ? 'C:/temp/claudetemp/apnscp.wsdl' : $endpoint . '/apnscp.wsdl'; // The panel cert is valid, but this PHP build ships no CA bundle, so relax verify. $ctx = stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]); $client = new SoapClient($wsdl, [ 'connection_timeout' => 30, 'location' => $endpoint . '/soap?authkey=' . $key, 'uri' => 'urn:net.apnscp.soap', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_MEMORY, 'stream_context' => $ctx, ]); $cmd = $argv[1] ?? ''; // Drive wp-cli with the command string read from a file (avoids all shell-quoting pain // when passing large HTML content). Usage: --wpcli-file if ($cmd === '--wpcli-file') { $command = rtrim((string)file_get_contents($argv[2]), "\r\n"); $host = $argv[3]; $path = $argv[4] ?? ''; try { $res = $client->__soapCall('wordpress_cli', [$command, [], $host, $path]); echo json_encode($res, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), "\n"; exit(isset($res['success']) && !$res['success'] ? 1 : 0); } catch (Throwable $e) { fwrite(STDERR, 'ERROR: ' . $e->getMessage() . "\n"); exit(1); } } if ($cmd === '--functions') { $filter = strtolower($argv[2] ?? ''); foreach ($client->__getFunctions() as $fn) { if ($filter === '' || strpos(strtolower($fn), $filter) !== false) { echo $fn, "\n"; } } exit(0); } if ($cmd === '') { fwrite(STDERR, "usage: php apiscp.php [json-arg ...]\n"); exit(2); } $args = []; foreach (array_slice($argv, 2) as $a) { if (strncmp($a, '@@', 2) === 0) { // @@path -> file contents as a string arg $args[] = (string)file_get_contents(substr($a, 2)); continue; } $d = json_decode($a, true); $args[] = ($d === null && $a !== 'null') ? $a : $d; } try { $res = $client->__soapCall($cmd, $args); echo json_encode($res, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), "\n"; } catch (Throwable $e) { fwrite(STDERR, 'ERROR: ' . $e->getMessage() . "\n"); // surface the raw response for debugging (no secrets in it) if (method_exists($client, '__getLastResponse')) { fwrite(STDERR, "LAST RESPONSE: " . substr((string)$client->__getLastResponse(), 0, 600) . "\n"); } exit(1); }