【问题标题】:ejabberd External Auth (PHP & MySQL)ejabberd 外部身份验证(PHP 和 MySQL)
【发布时间】:2020-06-02 18:40:17
【问题描述】:

当我启动服务器时,它会循环显示以下错误消息:

C(<0.1211.0>:extauth:146) : extauth script has exitted abruptly with reason 'normal'

我正在使用在 ejabberd 网站上找到的 PHP 脚本。 https://www.ejabberd.im/files/efiles/check_mysql.php.txt

权限应该是正确的,并且该错误是我得到的唯一一个错误。剧本过时了吗?知道什么可能有帮助吗?

如果您能告诉我哪个更有帮助,我可以提供更多日志文件。

【问题讨论】:

  • 我认为脚本确实过时了。为什么不对 MySQL 数据库使用本机 ejabberd 身份验证?
  • 您还需要执行以下操作。告诉您正在使用哪个操作系统以及哪个 ejabberd 版本。向您显示配置文件,以确保它已为您的操作系统正确配置。
  • 其他问题:您是否正确调整脚本以连接到您的数据库?该脚本的日志文件输出是什么?
  • 感谢您的浏览!我正在使用 Ubuntu,我相信最新的 ejabberd 版本(2.1.11)。我想使用 PHP 外部身份验证脚本,因为我正在使用 password_verify 进行身份验证,但我不知道如何将该函数与本机 ejabberd 身份验证一起使用。我没有费心尝试检查脚本的日志(甚至没有记录),因为我认为问题出在执行/脚本本身。无论如何,该脚本已调整但配置为返回 true。
  • 如果没有日志记录,很难判断您的脚本是否已运行以及那里出现了什么问题。你有在某处改编的剧本的最终版本吗?

标签: php mysql ejabberd


【解决方案1】:

给定的脚本已过时。我将其稍微更改如下。这对我有用。试试看

#!/usr/bin/php
<?php

error_reporting(0);


$auth = new JabberAuth();
$auth->dbhost = "localhost";
$auth->dbuser = "root";
$auth->dbpass = "123456";
$auth->dbbase = "ejabberd";
$auth->play(); // We simply start process !

class JabberAuth {
    var $dbhost; /* MySQL server */
    var $dbuser; /* MySQL user */
    var $dbpass; /* MySQL password */
    var $dbbase; /* MySQL database where users are stored */

    var $jabber_user;   /* This is the jabber user passed to the script. filled by $this->command() */
    var $jabber_pass;   /* This is the jabber user password passed to the script. filled by $this->command() */
    var $jabber_server; /* This is the jabber server passed to the script. filled by $this->command(). Useful for VirtualHosts */
    var $jid;           /* Simply the JID, if you need it, you have to fill. */
    var $data;          /* This is what SM component send to us. */

    var $dateformat = "M d H:i:s"; /* Check date() for string format. */
    var $command; /* This is the command sent ... */
    var $mysock;  /* MySQL connection ressource */
    var $stdin;   /* stdin file pointer */
    var $stdout;  /* stdout file pointer */

    function JabberAuth()
    {

        $this->openstd();
    }

    function stop()
    {

        closelog();
        $this->closestd(); // Simply close files
        exit(0); // and exit cleanly
    }

    function openstd()
    {
        $this->stdout = @fopen("php://stdout", "w"); // We open STDOUT so we can read
        $this->stdin  = @fopen("php://stdin", "r"); // and STDIN so we can talk !
    }

    function readstdin()
    {
        $l      = @fgets($this->stdin, 3); // We take the length of string
        $length = @unpack("n", $l); // ejabberd give us something to play with ...
        $len    = $length["1"]; // and we now know how long to read.
        if($len > 0) { // if not, we'll fill logfile ... and disk full is just funny once
            $data   = @fgets($this->stdin, $len+1);
            $this->data = $data; // We set what we got.

        }
    }

    function closestd()
    {
        @fclose($this->stdin); // We close everything ...
        @fclose($this->stdout);
    }

    function out($message)
    {
        @fwrite($this->stdout, $message); // We reply ...
        $dump = @unpack("nn", $message);
        $dump = $dump["n"];
    }

    function myalive()
    {
        if(!is_resource($this->mysock) || !@mysql_ping($this->mysock)) { // check if we have a MySQL connection and if it's valid.
            $this->mysql(); // We try to reconnect if MySQL gone away ...
            return @mysqli_ping($this->mysock); // we simply try again, to be sure ...
        } else {
            return true; // so good !
        }
    }

    function play()
    {
        do {
            $this->readstdin(); // get data
            $length = strlen($this->data); // compute data length
            $ret = $this->command(); // play with data !
            $this->out($ret); // send what we reply.
            $this->data = NULL; // more clean. ...
        } while (true);
    }

    function command()
    {


        $data = $this->splitcomm(); // This is an array, where each node is part of what SM sent to us :
        // 0 => the command,
        // and the others are arguments .. e.g. : user, server, password ...

        if($this->myalive()) { // Check we can play with MySQL

            switch($data[0]) {
                case "isuser": // this is the "isuser" command, used to check for user existance
                        $this->jabber_user = $data[1];
                        $return = $this->checkuser();
                    break;

                case "auth": // check login, password
                        $this->jabber_user = $data[1];
                        $this->jabber_pass = $data[3];
                        $return = $this->checkpass();

                    break;

                case "setpass":
                        $return = false; // We do not want jabber to be able to change password
                    break;

                default:
                        $this->stop(); // if it's not something known, we have to leave.
                        // never had a problem with this using ejabberd, but might lead to problem ?
                    break;
            }



            return @pack("nn", 2, $return);
        } else {

            return @pack("nn", 2, 0); // it's so bad.
        }
    }

    function checkpass()
    {
        /*
         * Put here your code to check password
         * $this->jabber_user
         * $this->jabber_pass
         * $this->jabber_server
         */
        if(1) { // You need to modify this
            return true;
        } else {
            return false;
        }
    }

    function checkuser()
    {
        /*
         * Put here your code to check user
         * $this->jabber_user
         * $this->jabber_pass
         * $this->jabber_server
         */
        if(1) { // You need to modify this
            return true;
        } else {
            return false;
        }
    }

    function splitcomm() // simply split command and arugments into an array.
    {
        return explode(":", $this->data);
    }

    function mysql() // "MySQL abstraction", this opens a permanent MySQL connection, and fill the ressource
    {

        $this->mysock = mysqli_connect($this->dbhost,$this->dbuser,$this->dbpass,$this->dbbase);

    }
}

?>

【讨论】:

    猜你喜欢
    • 2015-06-04
    • 2015-10-03
    • 1970-01-01
    • 2015-07-29
    • 2013-12-20
    • 2023-03-22
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多