processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6k stars 1.5k forks source link

Replace default captcha script not working #4166

Open jabberdquestions opened 4 months ago

jabberdquestions commented 4 months ago

I have replaced the default script with a custom one but it is not working for now. Right now I am trying to replace the current script with one developed in PHP, this script takes the random number generated as argument, create a captcha based on that value and output a binary image as content

In my ejabberd configuration I have specified to use a different script in this way:

captcha_cmd: "php -f /usr/share/ejabberd/mycaptcha.php"

And this is how I am producing the binary image:

imagestring($this->image, 5, 3, 0, $this->text, $color);
imagepng($this->image);

If I execute the script directly from the terminal like this php -f /usr/share/ejabberd/mycaptcha.php 123456 > test.png The captcha is generated properly

But when I restart ejabberd is not working and I am getting the following output in the logs:

[error] <0.525.0>@ejabberd_captcha:do_create_image/2:431 Failed to process an output from "php -f /usr/share/ejabberd/mycaptcha.php 686389": efbig
[critical] <0.525.0>@ejabberd_captcha:check_captcha_setup/0:577 Captcha is enabled in the option captcha_cmd, but it can't generate images.

Am I missing something? Thanks

licaon-kter commented 4 months ago

Where is your script saving the captcha?

jabberdquestions commented 4 months ago

I was just directly outputing the binary image. But after reviewing more carefully the default captcha I see that conver/ImageMagick is using a pseudo-filename pipping the output using a standard stream STDOUT. I have modified my script as it follows:

imagestring($this->image, 5, 3, 0, $this->text, $color);
fwrite(STDOUT, imagepng($this->image));

But I still have the same output in the logs