gamenet / php-jabber-rpc

PHP wrapper for ejabberd xml-rpc module
MIT License
18 stars 13 forks source link

{error,account_unprivileged} always crashed. #2

Closed zyfmix closed 8 years ago

zyfmix commented 8 years ago

i am runing with ejabberd 15.11 and use the code below:

include_once '/data/home/yzhang/Home/www/public/ejabberd/rpc/vendor/autoload.php';

$rpc = new \GameNet\Jabber\RpcClient([
    'server' => 'http://42.96.194.60:4560',
    'host' => 'coopens.com',
    'debug' => true,
]);

$rpc->checkAccount('zyf');

but it just crash a error:

A problem '{error,account_unprivileged}' occurred executing the command check_account with arguments

and i have test python code success:

server_url = 'http://42.96.194.60:4560'
server = xmlrpclib.ServerProxy(server_url)

EJABBERD_XMLRPC_LOGIN = {'user': 'zyf', 'server': 'coopens.com', 'password': '123456'} # , 'token': 'k1iTItUPDgH9NB4yTFYyTttRtNIlHjyV'

def ejabberdctl(command, data):
    fn = getattr(server, command)
    return fn(EJABBERD_XMLRPC_LOGIN, data)

result = ejabberdctl('register', {'user':'ggeo224', 'host':'coopens.com', 'password':'gogo11'})
print result

it seems to have login with admin account to run this function in advance. i dont know how to deal with it,who can help me?

misterion commented 8 years ago

Hi zyfmix, looks like your python script test register command rather then check_account. Keep in mind that some commands from ejabberd rpc module require special grants from user executing them. You can execute register with any credentials you want, but check_account require special grants from ejabberd server.

Now, this library designed as ejabberd grants all to executing rpc calls. Please could you chech check_account with python script?

zyfmix commented 8 years ago

Thank you for your reply.I just test check_accout with my python code below:

server_url = 'http://42.96.194.60:4560'
server = xmlrpclib.ServerProxy(server_url)

EJABBERD_XMLRPC_LOGIN = {'user': 'zyf', 'server': 'coopens.com', 'password': '123456'} # , 'token': 'k1iTItUPDgH9NB4yTFYyTttRtNIlHjyV'

def ejabberdctl(command, data):
    fn = getattr(server, command)
    return fn(EJABBERD_XMLRPC_LOGIN, data)

result = ejabberdctl('check_account', {'user':'zyfer', 'host':'coopens.com'})
print result

it just return

{'res': 0}

but when it test with an non exist user account it return:

{'res': 1}

The result seem to be wrong,but it does't crashed.

misterion commented 8 years ago

The difference is you call RPC command with credentials in python. Curently this library not support this. But you are wellcome to add this feature - just need to pass user/password to RpcClient constructor arguments and extends params of sendRequest method with this.

I think we can do this (if you have no time) in nearest 2-3 weeks.

zyfmix commented 8 years ago

The Python auth admin user by code below:

    @property
    def auth(self):
        """
        Returns a dictionary containing the basic authorization info
        :rtype: dict
        :return: a dictionary containing the basic authorization info
        """
        return {
            'user': self.username,
            'server': self.user_domain,
            'password': self.password
        }

and extends param with above auth like below:

response = method(self.auth, arguments)

I was try add admin param to sendRequest like code below:

$request = xmlrpc_encode_request($command,
['user' => 'zyf', 'server' => 'coopens.com', 'password' => '123456'],
$params, ['encoding' => 'utf-8', 'escaping' => 'markup']);

but it test failed,I'm confused with xmlrpc,can you tell me how to extends params to sendRequest?

zyfmix commented 8 years ago

I have solved it by change sendRequest with code below and working:

$request = xmlrpc_encode_request(
    $command, 
    [['user' => 'zyf', 'server' => 'coopens.com', 'password' => '123456'], $params],
    ['encoding' => 'utf-8', 'escaping' => 'markup']
);

@misterion : Thank you very much!

misterion commented 8 years ago

I need to check it more, but as i remember it use http basic authorization. So, with curl under the hood:

curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
misterion commented 8 years ago

So can you add it as pull resuqest? I mean is user and password specifies in cofig pass it with params on every request.

zyfmix commented 8 years ago

Thank you for you reply.I have pull request and this question can be closed ^_^