MailWatch icon indicating copy to clipboard operation
MailWatch copied to clipboard

RPC not working (HTTP status 500)

Open kongsted opened this issue 11 months ago • 12 comments

Hi,

I'm trying to do a setup with three servers, where I want RPC to work between the servers. The servers are running Rocky Linux 9.2 with "native" PHP (8.0.30).

I have done the config.php to work with RPC, but despites that, I'm only getting "HTTP/1.1 500 Internal Server Error" returned from the other servers (they're using a copy of the config, to ensure it's working - and the web-interface with MailWatch are also working fine - except RPC - from the other servers).

I'm using MailWatch version 1.2.30.

Any clue how to troubleshoot this issue? :)

Br, Anders

kongsted avatar Feb 01 '25 20:02 kongsted

Do you see any error in the webserver log?

Skywalker-11 avatar Feb 01 '25 21:02 Skywalker-11

I'm "only" seeing the apache-log with the error.

1.2.3.4 - - [01/Feb/2025:22:07:51 +0100] "POST /rpcserver.php HTTP/1.0" 500 - "-" "XML-RPC for PHP 3.0.0.beta"

Or is there somewhere else to check some logs?

kongsted avatar Feb 01 '25 21:02 kongsted

The log message look like it is from the access log. In most cases (but depending on your specific config) apache has separate log files for logging general requests (the access log) and error messages.

If you use php-fpm these errors might also be logged on those logs.

Skywalker-11 avatar Feb 01 '25 21:02 Skywalker-11

Thank you for learning me something new - wasn't aware of those logs. :)

Error-out in php-fpm: [01-Feb-2025 22:54:53 Europe/Copenhagen] PHP Fatal error: Uncaught Error: Call to undefined function each() in /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc:2701 Stack trace: #0 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1854): xmlrpcval->serialize() #1 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpcs.inc(561): xmlrpcresp->serialize() #2 /opt/mailwatch/mailscanner/rpcserver.php(333): xmlrpc_server->service() #3 {main} thrown in /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc on line 2701

kongsted avatar Feb 01 '25 21:02 kongsted

The error should be fixed by 4b58985140947abcaff2332b3c21f9c710a325f8

Can you try the current code in the 1.2 branch and see if that fixes your issues?

Skywalker-11 avatar Feb 02 '25 00:02 Skywalker-11

I have tried with the latest code (downloaded the zip-file of the repo - not only the few changed files in the commit).

It fails, and very little are showed on the webpage (only the first elements).

Error in php-fpm log:

[02-Feb-2025 09:51:51 Europe/Copenhagen] PHP Warning:  Undefined array key "%rules-dir%" in /opt/mailwatch/mailscanner/functions.php on line 1916
[02-Feb-2025 09:51:51 Europe/Copenhagen] PHP Warning:  Undefined array key "%rules-dir%" in /opt/mailwatch/mailscanner/functions.php on line 1916
[02-Feb-2025 09:51:51 Europe/Copenhagen] PHP Fatal error:  Uncaught Error: Call to undefined function each() in /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc:2096
Stack trace:
#0 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(2239): xmlrpcmsg->parseResponseHeaders()
#1 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1520): xmlrpcmsg->parseResponse()
#2 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1300): xmlrpc_client->sendPayloadCURL()
#3 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1094): xmlrpc_client->sendPayloadHTTPS()
#4 /opt/mailwatch/mailscanner/functions.php(4176): xmlrpc_client->send()
#5 /opt/mailwatch/mailscanner/functions.php(588): xmlrpc_wrapper()
#6 /opt/mailwatch/mailscanner/functions.php(410): printMTAQueue()
#7 /opt/mailwatch/mailscanner/status.php(32): html_start()
#8 {main}
  thrown in /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc on line 2096

(I'm not sure why the warning - the variable are defined with the value '/etc/MailScanner/rules' when checking /msconfig.php)

kongsted avatar Feb 02 '25 08:02 kongsted

Looks like I missed an each last summer, my bad!

endelwar avatar Feb 03 '25 09:02 endelwar

No problem. :)

But new error occours. :)

[03-Feb-2025 18:22:17 Europe/Copenhagen] PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc:2329
Stack trace:
#0 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1520): xmlrpcmsg->parseResponse()
#1 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1300): xmlrpc_client->sendPayloadCURL()
#2 /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc(1094): xmlrpc_client->sendPayloadHTTPS()
#3 /opt/mailwatch/mailscanner/functions.php(4212): xmlrpc_client->send()
#4 /opt/mailwatch/mailscanner/functions.php(591): xmlrpc_wrapper()
#5 /opt/mailwatch/mailscanner/functions.php(413): printMTAQueue()
#6 /opt/mailwatch/mailscanner/status.php(32): html_start()
#7 {main}
  thrown in /opt/mailwatch/mailscanner/lib/xmlrpc/xmlrpc.inc on line 2329

kongsted avatar Feb 03 '25 17:02 kongsted

When I'm debugging, it seems like getting some kind of the expected response from remote server.

---GOT---
HTTP/1.1 200 OK
Date: Thu, 06 Feb 2025 21:11:58 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.2.2
X-Powered-By: PHP/8.0.30
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Set-Cookie: MW_LANG=en; path=/
Set-Cookie: PHPSESSID=<removed>; path=/; HttpOnly
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value><struct>
<member><name>inq</name>
<value><string>0</string></value>
</member>
<member><name>outq</name>
<value><string>0</string></value>
</member>
</struct></value>
</param>
</params>
</methodResponse>
---END---

HEADER: date: Thu, 06 Feb 2025 21:11:58 GMT
HEADER: server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.2.2
HEADER: x-powered-by: PHP/8.0.30
HEADER: x-xss-protection: 1; mode=block
HEADER: x-frame-options: SAMEORIGIN
HEADER: x-content-type-options: nosniff
HEADER: expires: Thu, 19 Nov 1981 08:52:00 GMT
HEADER: cache-control: no-store, no-cache, must-revalidate
HEADER: pragma: no-cache
HEADER: content-encoding: gzip
HEADER: vary: Accept-Encoding
HEADER: set-cookie: MW_LANG=en; path=/, PHPSESSID=<removed>; path=/; HttpOnly
HEADER: transfer-encoding: chunked
HEADER: content-type: text/xml; charset=UTF-8
COOKIE: MW_LANG=en
COOKIE: PHPSESSID=<removed>

The response above is identical if there is one or two servers listed in "RPC_REMOTE_SERVER" (there is 3 servers in total in the setup).

kongsted avatar Feb 06 '25 21:02 kongsted

Any idea to something I could test, to troubleshoot this issue? :) //Anders

kongsted avatar Feb 25 '25 20:02 kongsted

This commit should fix the TypeError but I see some other things that are currently not working correctly for a distributed setup (mainly regarding displaying the actual mails and quarantine management). But at least the page should load normally then.

https://github.com/mailwatch/MailWatch/commit/bf43faa6dc448928d721d182a38b2d2d8ebe1d00

Skywalker-11 avatar Feb 27 '25 23:02 Skywalker-11

@Skywalker-11 that fix solved the problem. I did only replace xmlrpc.inc, and it solved the problem.

As I can see, the current config works with removing all the status-boxes in the top of the page, if "define('DISTRIBUTED_SETUP', false);" is set to true instead. So yes, it could be more optimal in a distributed setup. Now you just have to be aware which server you're on, to get the status of the server. But at least it's now possible to open mails across the servers, and it's possible to learn spamassassin/bayes-database. :)

Thank you both for your help on this issue! 👍

kongsted avatar Mar 01 '25 11:03 kongsted