【问题标题】:Ejabberd api set_vcard database_failureEjabberd api set_vcard database_failure
【发布时间】:2018-12-24 05:58:06
【问题描述】:

当我对 ejabberd API 使用以下命令时,我得到以下响应;

curl -ik -X POST -H 'Authorization: Bearer xxxxxxxxxxx' https://localhost:5280/api/set_vcard -d '{"user":"foo","host":"example.com","name":"FN","content":"foobar"}'

HTTP/1.1 400 Bad Request
Content-Length: 18
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, Authorization, X-Admin

"database_failure"

在 ejabberd 日志(5 级)上我看到了这个;

[info] (<0.607.0>) Accepted connection ::ffff:172.18.0.1:46622 -> ::ffff:172.18.0.3:5280
[debug] S: [{[<<"ws">>],ejabberd_http_ws},{[<<"bosh">>],mod_bosh},{[<<"oauth">>],ejabberd_oauth},{[<<"api">>],mod_http_api},{[<<"admin">>],ejabberd_web_admin}]
[debug] ({tlssock,#Port<0.18819>,#Ref<0.650175335.3240493057.203147>}) http query: 'POST' <<"/api/set_vcard">>
[debug] client data: <<"{\"user\":\"foo\",\"host\":\"example.com\",\"contents\":[\"FN:foobar\"]}">>
[debug] [<<"api">>,<<"set_vcard">>] matches [<<"api">>]
[info] API call set_vcard [{<<"user">>,<<"foo">>},{<<"host">>,<<"example.com">>},{<<"contents">>,[<<"FN:foobar">>]}] from ::ffff:172.18.0.1:46622
[debug] Command 'set_vcard' execution allowed by rule 'api service' (CallerInfo=#{caller_module => mod_http_api,caller_server => <<"example.com">>,ip => {0,0,0,0,0,65535,44050,1},oauth_scope => [<<"ejabberd:api-service">>],usr => {<<"admin">>,<<"example.com">>,<<>>}})
[debug] Executing command mod_admin_extra:set_vcard with Args=[<<"foo">>,<<"example.com">>,<<>>,<<>>,[<<"FN:foobar">>]]

它使用 MySQL 作为数据库(其他一切都可以正常工作)但是当我查看数据库一般查询日志时,我没有看到我的 API 请求触发任何查询。我看到所有其他正常的 ejabberd 查询,因此数据库连接没有问题,并且如前所述,其他一切正常。

$ ejabberdctl status
The node ejabberd@e87da11aa894 is started with status: started
ejabberd 18.4.0 is running in that node

有没有人有任何线索可以让我摆脱困境?我已经没有关于可能是什么问题的线索了。

!!!编辑!!!

解决方法

正如https://github.com/processone/ejabberd/issues/2629 中提到的,其他人也遇到过这个问题。更改配置以禁用缓存并清除数据库中的 vcard 表似乎是一种解决方法;

SQL:

DELETE FROM vcard;

配置:

...
mod_vcard:
  search: false
  use_cache: false
...

【问题讨论】:

标签: ejabberd


【解决方案1】:

API 在允许的范围内是相当宽松的,但是一旦它在数据库中,记录将无法加载。

对于“set_vcard”,“name”是您希望更改的字段名称,内容是该字段的内容。

{
  "user": "catman",
  "host": "the.host",
  "name": "FN",
  "content": "Cat Man"
}

ejabberd 还缓存查询,因此一旦您有一条被拒绝的记录,即使您已更正您的 api 调用或手动将其修复到数据库中,它也会返回“database_failed”。可以在模块配置下禁用缓存。

【讨论】:

    【解决方案2】:

    请注意您的日志中显示:

    [debug] 客户端数据:>

    contents怎么可能是FN:foobar?我安装了 18.04,设置了 mysql 存储,并运行了这个查询:

    $ curl -v -H "X-Admin: true" -H "Content-Type:application/json" http://localhost:5280/api/set_vcard -d '{"user":"user1","host":"localhost", "name":"FN","content":"mi nombre curlllll"}'

    日志说:

    21:42:29.638 [info] (<0.487.0>) Accepted connection 127.0.0.1:58412 -> 127.0.0.1:5280
    21:42:29.638 [debug] S: [{[<<"api">>],mod_http_api},{[<<"bosh">>],mod_bosh},{[<<"oauth">>],ejabberd_oauth},{[<<"presence">>],mod_webpresence},{[<<"register">>],mod_register_web},{[<<"rest">>],mod_rest},{[<<"ws">>],ejabberd_http_ws},{[<<"admin">>],ejabberd_web_admin}]
    21:42:29.639 [debug] (#Port<0.18079>) http query: 'POST' <<"/api/set_vcard">>
    21:42:29.639 [debug] client data: <<"{\"user\":\"user1\",\"host\":\"localhost\",\"name\":\"FN\",\"content\":\"mi nombre curllll\"}">>
    21:42:29.639 [debug] [<<"api">>,<<"set_vcard">>] matches [<<"api">>]
    21:42:29.639 [info] API call set_vcard [{<<"user">>,<<"user1">>},{<<"host">>,<<"localhost">>},{<<"name">>,<<"FN">>},{<<"content">>,<<"mi nombre curllll">>}] from 127.0.0.1:58412
    21:42:29.640 [debug] Command 'set_vcard' execution allowed by rule 'test commands' (CallerInfo=#{caller_module => mod_http_api,ip => {127,0,0,1}})
    21:42:29.640 [debug] Executing command mod_admin_extra:set_vcard with Args=[<<"user1">>,<<"localhost">>,<<"FN">>,<<"mi nombre curllll">>] 
    21:42:29.640 [debug] SQL: "select vcard from vcard where username='user1' and 0=0"
    21:42:29.642 [debug] SQL: "begin;"
    21:42:29.642 [debug] SQL: "UPDATE vcard SET vcard='<vCard xmlns=''vcard-temp''><FN>mi nombre curllll</FN><N><FAMILY>mi familia11</FAMILY></N><NICKNAME>mi apodoooooooooooooooooooo11</NICKNAME><PHOTO><BINVAL>R0lGODlhDwAPAJECAP//AAAAAP///wAAACH5BAEAAAIALAAAAAAPAA8AAAIulB2Zx5IA4WIhWnnqvQFJDTyhE4khaG5Wqn4tp4ErFnMY+Sll9naUfGpkFL5DAQA7</BINVAL><TYPE>image/gif</TYPE></PHOTO></vCard>' WHERE username='user1'"
    21:42:29.644 [debug] SQL: "UPDATE vcard_search SET username='user1', fn='mi nombre curllll', lfn='mi nombre curllll', family='mi familia11', lfamily='mi familia11', given='', lgiven='', middle='', lmiddle='', nickname='mi apodoooooooooooooooooooo11', lnickname='mi apodoooooooooooooooooooo11', bday='', lbday='', ctry='', lctry='', locality='', llocality='', email='', lemail='', orgname='', lorgname='', orgunit='', lorgunit='' WHERE lusername='user1'"
    21:42:29.658 [debug] SQL: "commit;"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 2018-10-07
      • 2017-10-16
      • 2021-06-21
      • 1970-01-01
      • 2018-11-07
      • 2016-06-25
      相关资源
      最近更新 更多