Hello,
I am using Proxmox Mail Gateway, I am trying to pull requests in PHP language in JSON format to an external platform.
I want to access spam mail on quarantine.
When I try to do this with the PHP code below, I get the following error.
As for my PHP codes, I am working with a structure like this.
I am using Proxmox Mail Gateway, I am trying to pull requests in PHP language in JSON format to an external platform.
I want to access spam mail on quarantine.
When I try to do this with the PHP code below, I get the following error.
Code:
* Trying 192.168.1.15:8006... * Connected to antispam.company.com (192.168.1.15) port 8006 (#0) * ALPN, offering http/1.1 * CAfile: /etc/apache2/ssl/curl/pmg-tls.pem * CApath: /etc/ssl/certs * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN, server did not agree to a protocol * Server certificate: * subject: CN=*.company.com * start date: Apr 25 00:00:00 2024 GMT * expire date: May 26 23:59:59 2025 GMT * subjectAltName: host "antispam.company.com" matched cert's "*.company.com" * issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust TLS RSA CA G1 * SSL certificate verify ok. > POST /api2/json/access/ticket HTTP/1.1 Host: antispam.company.com:8006 User-Agent: GuzzleHttp/7 Content-Type: application/x-www-form-urlencoded Content-Length: 38 * old SSL session ID is stale, removing * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Cache-Control: max-age=0 < Connection: close < Connection: Keep-Alive < Date: Tue, 10 Sep 2024 14:47:49 GMT < Pragma: no-cache < Server: pve-api-daemon/3.0 < Content-Length: 502 < Content-Type: application/json;charset=UTF-8 < Expires: Tue, 10 Sep 2024 14:47:49 GMT < * Closing connection 0 * Hostname antispam.company.com was found in DNS cache * Trying 192.168.1.15:8006... * Connected to antispam.company.com (192.168.1.15) port 8006 (#1) * ALPN, offering http/1.1 * CAfile: /etc/apache2/ssl/curl/pmg-tls.pem * CApath: /etc/ssl/certs * SSL re-using session ID * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN, server did not agree to a protocol * Server certificate: * subject: CN=*.company.com * start date: Apr 25 00:00:00 2024 GMT * expire date: May 26 23:59:59 2025 GMT * subjectAltName: host "antispam.company.com" matched cert's "*.company.com" * issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust TLS RSA CA G1 * SSL certificate verify ok. > GET /api2/json/quarantine/spam HTTP/1.1 Host: antispam.company.com:8006 User-Agent: GuzzleHttp/7 Cookie: PVEAuthCookie=PMG:root@pam:66E05C15::SmTCtsh6ttbEB9ccqfBLS3tK7J3nh/XJgRMhCD6wpHrKijHfDBVSkuFf6quRVPR1LJszsV95847SYewBz0R4i/x0Qt0yFGmYcj8LLQm67Kdmrsk+WcnpHspgdB/ZJpo+CrakQOABI7SOPiNfrkmqZx5YeWdXbuPXpoHSE84feDkP6WbL2PCjob+SgSFY9vYjVnmU/tBLwPEeNZGOCSSxNKRdB9KCdS6B4FVYml9dh8UL2Z63Vath/EL5k6sxrUiq2tLD9AQFLxu+g86+axiOKGPqroLJ7xfjxOLpKAh6Ge6Kgq5oHWMYhve+pklPuvm1D6PBpm4ByKquV9MN+jg/oQ== CSRFPreventionToken: 66E05C15:dAai7E5+k4VHJl0irZErBLrtjIEMXcjgqrHqVjtIaTc Connection: keep-alive * old SSL session ID is stale, removing * Mark bundle as not supporting multiuse < HTTP/1.1 401 No ticket < Cache-Control: max-age=0 < Connection: close < Date: Tue, 10 Sep 2024 14:47:49 GMT < Pragma: no-cache < Server: pve-api-daemon/3.0 < Expires: Tue, 10 Sep 2024 14:47:49 GMT < * OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0 * Closing connection 1 Response Error:
As for my PHP codes, I am working with a structure like this.
PHP:
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$username = 'root@pam';
$password = 'password';
$client = new Client([
'base_uri' => 'https://antispam.company.com:8006/api2/json/',
'verify' => '/etc/apache2/ssl/curl/pmg-tls.pem',
'timeout' => 60,
'debug' => true,
]);
try {
$loginResponse = $client->post('access/ticket', [
'form_params' => [
'username' => $username,
'password' => $password,
],
]);
$loginBody = json_decode($loginResponse->getBody(), true);
$ticket = $loginBody['data']['ticket'];
$csrfToken = $loginBody['data']['CSRFPreventionToken'];
$response = $client->get('quarantine/spam', [
'headers' => [
'Cookie' => "PVEAuthCookie=$ticket",
'CSRFPreventionToken' => $csrfToken,
'Connection' => 'keep-alive',
],
]);
$body = $response->getBody();
$data = json_decode($body, true);
print_r($data);
} catch (RequestException $e) {
if ($e->hasResponse()) {
echo 'Response Error: ', $e->getResponse()->getBody()->getContents(), "\n";
} else {
echo 'Request failed: ', $e->getMessage(), "\n";
}
}
?>