- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 centOS 虚拟机中有一个 ejabberd 15.03 服务器,我需要使用 php 针对 SQL 服务器实现外部身份验证方法。官方文档展示了一个php/mysql的例子 php/mysql external authentification
有没有办法把这个例子改成php/sqlserver和mysql_ping等函数
这是我写的一个例子,把它放在/opt/auth/下,并配置 ejabberd.yml 来执行作为外部身份验证。
$auth = new JabberAuth();
$auth->dbhost = "hostIP";
$auth->dbuser = "user";
$auth->dbpass = "pass";
$auth->dbbase = "databaseName";
$auth->play(); // We simply start process !
class JabberAuth {
var $dbhost;
var $dbuser;
var $dbpass;
var $dbbase;
var $debug = false; /* Debug mode */
var $debugfile = "/opt/auth/log/pipe-debug.log"; /* Debug output */
var $logging = false; /* Do we log requests ? */
var $logfile = "/opt/auth/log/pipe-log.log" ; /* Log file ... */
/*
* For both debug and logging, ejabberd have to be able to write.
*/
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()
{
@define_syslog_variables();
@openlog("pipe-auth", LOG_NDELAY, LOG_SYSLOG);
if($this->debug) {
@error_reporting(E_ALL);
@ini_set("log_errors", "1");
@ini_set("error_log", $this->debugfile);
}
$this->logg("Starting pipe-auth ..."); // We notice that it's starting ...
$this->openstd();
}
function stop()
{
$this->logg("Shutting down ..."); // Sorry, have to go ...
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
$this->logg("Reading $len bytes ... "); // We notice ...
$data = @fgets($this->stdin, $len+1);
// $data = iconv("UTF-8", "ISO-8859-15", $data); // To be tested, not sure if still needed.
$this->data = $data; // We set what we got.
$this->logg("IN: ".$data);
}
}
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"];
$this->logg("OUT: ". $dump);
}
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 @mysql_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
if($length > 0 ) { // for debug mainly ...
$this->logg("GO: ".$this->data);
$this->logg("data length is : ".$length);
}
$ret = $this->command(); // play with data !
$this->logg("RE: " . $ret); // this is what WE send.
$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
if(strlen($data[0]) > 0 ) {
$this->logg("Command was : ".$data[0]);
}
switch($data[0]) {
case "isuser": // this is the "isuser" command, used to check for user existance
$this->jabber_user = $data[1];
$parms = $data[1]; // only for logging purpose
$return = $this->checkuser();
break;
case "auth": // check login, password
$this->jabber_user = $data[1];
$this->jabber_pass = $data[3];
$parms = $data[1].":".$data[2].":".md5($data[3]); // only for logging purpose
$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 = ($return) ? 1 : 0;
if(strlen($data[0]) > 0 && strlen($parms) > 0) {
$this->logg("Command : ".$data[0].":".$parms." ==> ".$return." ");
}
return @pack("nn", 2, $return);
} else {
// $this->prevenir(); // Maybe useful to tell somewhere there's a problem ...
return @pack("nn", 2, 0); // it's so bad.
}
}
function checkpass()
{
$hash=sha1($this->jabber_pass);
$query = mssql_query("SELECT [attribute] FROM [DatabaseName].[dbo].[table] where (S_USERNAME='$this->jabber_user') AND (SUBSTRING(S_PASSWORD,1,(LEN(S_PASSWORD)-3)))='$hash'");
// Check if there were any records
if (!mssql_num_rows($query)) {
return false;
} else {
return true;
}
}
function checkuser()
{
$query = mssql_query("SELECT [attribute] FROM [DatabaseName].[dbo].[table] where S_USERNAME='$this->jabber_user'");
// Check if there were any records
if (!mssql_num_rows($query)) {
return false;
} else {
return true;
}
}
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 = @mssql_pconnect($this->dbhost, $this->dbuser, $this->dbpass);
echo '1';
var_dump($this->mysock);
@mssql_select_db($this->dbbase, $this->mysock);
$this->logg("MsSql :: ". (is_resource($this->mysock) ? "Connecté" : "Déconnecté"));
}
function logg($message) // pretty simple, using syslog.
// some says it doesn't work ? perhaps, but AFAIR, it was working.
{
if($this->logging) {
@syslog(LOG_INFO, $message);
}
}
}
这没有产生任何 php 错误。但是在 ejabberd.log 中我总是得到'extauth 脚本突然退出,原因是'正常''
这是 crash.log 中的崩溃报告
2015-04-01 17:44:12 =CRASH REPORT==== crasher: initial call: ejabberd_http:init/2 pid: <0.8779.0> registered_name: [] exception error: bad argument: [{extauth,call_port,2,[{file,"src/extauth.erl"},{line,99}]},{ejabberd_auth_external,check_password_extauth,3,[{file,"src/ejabberd_auth_external.erl"},{line,182}]},{ejabberd_auth_external,check_password_external_cache,3,[{file,"src/ejabberd_auth_external.erl"},{line,244}]},{ejabberd_auth,check_password_loop,2,[{file,"src/ejabberd_auth.erl"},{line,158}]},{ejabberd_auth,check_password,3,[{file,"src/ejabberd_auth.erl"},{line,106}]},{ejabberd_web_admin,get_auth_account,5,[{file,"src/ejabberd_web_admin.erl"},{line,266}]},{ejabberd_web_admin,process,2,[{file,"src/ejabberd_web_admin.erl"},{line,221}]},{ejabberd_http,process,5,[{file,"src/ejabberd_http.erl"},{line,359}]}] ancestors: [ejabberd_http_sup,ejabberd_sup,<0.37.0>] messages: [] links: [<0.327.0>,#Port<0.12042>] dictionary: [{random_seed,{2036,6729,29501}}] trap_exit: false status: running heap_size: 2586 stack_size: 27 reductions: 1244 neighbours: 2015-04-01 17:44:12 =SUPERVISOR REPORT==== Supervisor: {local,ejabberd_http_sup} Context: child_terminated Reason: badarg Offender: [{pid,<0.8779.0>},{name,undefined},{mfargs,{ejabberd_http,start_link,undefined}},{restart_type,temporary},{shutdown,1000},{child_type,worker}]
这似乎是配置错误。这是我添加到 ejabberd.yml 的内容
auth_method: external
extauth_program: "php -f /etc/ejabberd-15.03/auth_script.php"
extauth_cache: 600
extauth_instances: 3
最佳答案
我认为最新版本的 ejabberd 不支持 SQL-server。所以我最终转向支持许多数据库的 openfire。
关于php - ejabberd 外部认证 php sql server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29370149/
我们正在使用 ejabberd_16.01-0_amd64.deb,我们希望将每个房间的最大用户数设置为 10000。根据文档:( https://docs.ejabberd.im/admin/con
我正在安装 ejabberd,但是当我使用 ./start 命令通过终端运行它时。它给出了 ejabberd 节点 ejabberd@localhost 已经运行的错误。 我已经卸载了 ejabber
我需要在 ejabberd 中存储每个用户的数据。我该怎么做?我的意思是我需要向用户表添加一个字段,并且我应该随时更新此数据。 我该怎么做? 最佳答案 这就是我正在做的事情。 在我的 Android
我是 ejabberd 的新手,我编译并运行了服务器,但在启动过程中出现此错误。该日志不是很有帮助,但也许有人比我更知道如何解析它。任何见解都会很棒。 =CRASH REPORT==== 17
我试图在 ejabberd 上启动 BOSH。我的 ejabberd.cfg 片段如下: {5280, ejabberd_http, [ {reques
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我正在按照本指南将 Ejabberd 嵌入到 Phoenix 应用程序 ( https://blog.process-one.net/embedding-ejabberd-into-an-elixir
我对 ejabberd 完全陌生。我已经下载了 Windows 和 Linux (Ubuntu) 的安装程序。我在网上的某个地方看到了如何安装和设置它的演示,但安装被配置为“演示”。我有 pidgin
按照 https://github.com/processone/ejabberd-contrib 中的说明进行操作我尝试运行: ejabberdctl module_install ejabberd
我想在 ejabberd 中配置 STUN/TURN,以便将 WebRTC 与“对话”XMPP 客户端一起使用。 我当然看了ejabberd STUN/TURN documentation以及如何操作
我在 Windows 中安装了 ejabberd。我在ejabberd文档查了半天,查了ejabberd安装文件夹(我电脑C:\Program Files\ejabberd-15.09),没找到文件e
我尝试将 Jitsi 与 ejabberd 连接,但在服务器运行并成功连接到 Pidgin 客户端时出现错误“未连接到服务器”。有人可以帮忙吗? 最佳答案 尝试在帐户配置文件中编辑连接设置: 连接服务
您好,我已经在我的服务器上安装了 ejabberd 16.04.43,它可以根据我的需要运行。 现在我有了新的要求,要阻止特定用户访问特定用户 让我考虑几个用户: kandan cash mani k
我想访问 ejabberd 服务器的 Mnesia 数据库,但我不知道如何读取、写入和更新数据,有没有办法可以做到这一点。 我可以将数据库更改为 MySQL 而不是 Mnesia。 我试过这个 {od
我正在尝试通过 docker 设置 ejabberd 服务器,以便我可以使用 pidgin 与我的队友聊天。 我有以下 docker compose 文件: version: "2" services
我想使用自定义 tsung 节(测试 ejabberd)。 假设我的看起来像这样: 我如何将其添加到 tsung 配置中,例如:
我正在开发这个 JavaScript 聊天应用程序,一切正常,除了我想为新(网站访问者)用户分配昵称时。 我只是想知道是否有一种方法可以通过 ejabberd XML 请求或 ejabberdctl“
我按照文档查看了多个链接以了解如何在 ejabberd 服务器上上传文件,但仍然无法在 ejabberd 服务器上上传文件。我的动机是在尝试使用 postman 之前从 android 应用程序上传文
ejabberd版本:16.04 操作系统:CentOS 7 我按照本文档设置 xmlrpc 支持,并需要一些帮助来配置访问控制: https://www.ejabberd.im/ejabberd_x
我刚刚在 mac os 中安装了 EJabberd 14.07。我是 EJabberd 的新手,我想学习基础知识,例如如何创建 Hello World 示例、项目的结构是什么、如何编译和运行 EJab
我是一名优秀的程序员,十分优秀!