ejabberd - Comments for "Using mod_rest to update the roster" https://www.ejabberd.im/node/3979 en Hi please can you help how to https://www.ejabberd.im/node/3979#comment-66458 <p>Hi please can you help how to configured mod_rest and mod_admin_extra in my ubuntu machine</p> Wed, 16 Dec 2015 14:20:54 +0000 varunjoshi919 comment 66458 at https://www.ejabberd.im Hi i want to make friend on https://www.ejabberd.im/node/3979#comment-66457 <p>Hi i want to make friend on ejabberd using php code &amp; for this i use this command Install mod_admin_extra to install roster on my ubuntu machine it shows command not found,please help me,Thanks in Advance.</p> Wed, 16 Dec 2015 13:53:24 +0000 varunjoshi919 comment 66457 at https://www.ejabberd.im XMPP Domain https://www.ejabberd.im/node/3979#comment-56942 <div class="quote-msg"> <div class="quote-author"><em>nouralk</em> wrote:</div> <p>$file = file_get_contents("http://ejabberd.ip.address.here:5280/rest/", false, $context); </p></div> <p>Instead of IP address, put the XMPP domain (im.mysite.com). If that still fails, then describe what ejabberd and mod_rest versions you use.</p> Tue, 04 Jan 2011 15:49:21 +0000 mfoss comment 56942 at https://www.ejabberd.im add_rosteritem not working from external script https://www.ejabberd.im/node/3979#comment-56929 <p>i installed mod_admin_extra, and am trying to add 2 users to each other user , when i try from shell its working perfectly, but when i try to call it from an external php script its not working, same happens using TCL script, here is what i get in my error log:</p> <div class="codeblock"><code>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />I(&lt;0.356.0&gt;:ejabberd_listener:232) : (#Port&lt;0.1687&gt;) Accepted connection {{my,ip,address,here},37081} -&gt; {{ejabberd,ip,address,here},5280} <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />D(&lt;0.1108.0&gt;:ejabberd_http:135) : S: [{[&quot;rest&quot;],mod_rest},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {[&quot;admin&quot;],ejabberd_web_admin},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {[&quot;http-bind&quot;],mod_http_bind}, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {[&quot;http-poll&quot;],ejabberd_http_poll}]</p> <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />I(&lt;0.1108.0&gt;:ejabberd_http:137) : started: {gen_tcp,#Port&lt;0.1687&gt;}</p> <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />D(&lt;0.1108.0&gt;:ejabberd_http:254) : (#Port&lt;0.1687&gt;) http query: &#039;POST&#039; /rest/</p> <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />D(&lt;0.1108.0&gt;:ejabberd_http:420) : client data: &quot;add_rosteritem anna im.mysite.com karen im.mysite.com someOne Friends both&quot;</p> <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />D(&lt;0.1108.0&gt;:ejabberd_http:323) : [&quot;rest&quot;] matches [&quot;rest&quot;]</p> <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />I(&lt;0.1108.0&gt;:mod_rest:92) : Data: &quot;add_rosteritem anna im.mysite.com karen im.mysite.com someOne Friends both&quot;</p> <p>=INFO REPORT==== 2011-01-02 10:02:27 ===<br />D(&lt;0.1108.0&gt;:mod_rest:58) : Error when processing REST request:<br />Data: &quot;add_rosteritem anna im.mysite.com karen im.mysite.com someOne Friends both&quot;<br />Error: {badmatch,false}</p></code></div> <p>here is the php script i tried:</p> <div class="codeblock"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$param</span><span style="color: #007700">=array(</span><span style="color: #DD0000">"user"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"admin"</span><span style="color: #007700">, </span><span style="color: #DD0000">"host"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"ejabberd.ip.address.here"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$request </span><span style="color: #007700">= </span><span style="color: #DD0000">"add_rosteritem anna im.mysite.com karen im.mysite.com someOne Friends both"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$context </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'http' </span><span style="color: #007700">=&gt; array(<br />&nbsp;&nbsp; </span><span style="color: #DD0000">'method' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"POST"</span><span style="color: #007700">,<br />&nbsp;&nbsp; </span><span style="color: #DD0000">'header' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Content-Type: text/xml\r\n" </span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #DD0000">"Content-Length: "</span><span style="color: #007700">.</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$request</span><span style="color: #007700">),<br />&nbsp;&nbsp; </span><span style="color: #DD0000">'content' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$request<br /></span><span style="color: #007700">))); <p></p></span><span style="color: #0000BB">$file </span><span style="color: #007700">= </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://ejabberd.ip.address.here:5280/rest/"</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$context</span><span style="color: #007700">); <p>echo </p></span><span style="color: #0000BB">$file</span><span style="color: #007700">; <p></p></span><span style="color: #FF8000">/*$response = xmlrpc_decode($file); <p>if (xmlrpc_is_fault($response)) {<br />&nbsp;&nbsp; trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");<br />} else {<br />&nbsp;&nbsp; print_r($response);<br />}<br />*/</p> <p></p></span><span style="color: #0000BB">?&gt;</span></span></code></div> <p>What am i doing wrong? can anyone advise me?</p> Sun, 02 Jan 2011 10:51:01 +0000 nouralk comment 56929 at https://www.ejabberd.im Return at least the code https://www.ejabberd.im/node/3979#comment-56858 <p>With this change, when the response contains no text, at least the status code number is returned, and doesn't return 500 in case of response==false:</p> <pre> --- src/mod_rest.erl (revision: 1099) +++ src/mod_rest.erl (copia de trabajo) @@ -93,10 +93,14 @@ Args = split_line(Data), AccessCommands = get_option_access(Host), case ejabberd_ctl:process2(Args, AccessCommands) of + {"", ?STATUS_SUCCESS} -&gt; + {200, [], integer_to_list(?STATUS_SUCCESS)}; {String, ?STATUS_SUCCESS} -&gt; {200, [], String}; + {"", Code} -&gt; + {200, [], integer_to_list(Code)}; {String, _Code} -&gt; - {500, [], String} + {200, [], String} end. %% This function throws an error if the module is not started in that VHost. </pre><p> Try it and tell me if that solves the problem, and it's worth including in SVN.</p> Mon, 06 Dec 2010 18:21:27 +0000 mfoss comment 56858 at https://www.ejabberd.im Return codes https://www.ejabberd.im/node/3979#comment-56841 <p>I'm having issues with the way ejabberdctl returns error codes.</p> <p>If I run a command like </p> <pre>ejabberdctl check_account garth localhost</pre><p>and the account exists, nothing is returned. To actually check the error code, I have to do</p> <pre>echo $?</pre><p>If the account exists, it returns a 0, if it doesn't exist, it reutrns a 1. Nevermind the fact that the error codes seem the wrong way around, I have no way of checking these codes when doing a POST to the server in php, using a function as outlined above.</p> <p>It seems to me, if using the check account exmaple, that if I do a post and the account doesn't exist, then the fopen fails, if it does exist, then the fopen succeeds, but no content is returned.</p> <p>The problem with this is, I have no way of knowing the difference between the actual post failing or the account simply not existing.</p> <p>Is there another way I can communicate with the server and actually get the return codes back?</p> Wed, 01 Dec 2010 10:51:15 +0000 synack comment 56841 at https://www.ejabberd.im Try recent SVN and look at logs https://www.ejabberd.im/node/3979#comment-56477 <div class="quote-msg"> <div class="quote-author"><em>salin</em> wrote:</div> <p>when I tried through PHP client, I'm getting the following error.</p> <p>2010-08-02 18:38:00 ERROR <strong>406: Not Acceptable.</strong></p></div> <p>The problem happens when processing your request, maybe it lacks some argument, or the arguments are wrongly formatted, or escaped.</p> <p>I've added some debug lines to mod_rest in SVN. You can download it, recompile, install, configure {loglevel, 5} in ejabberd.cfg, start ejabberd, make your request, and then search in the log files for the word "REST".</p> Wed, 04 Aug 2010 09:03:06 +0000 mfoss comment 56477 at https://www.ejabberd.im able to add_rosteritem using ejabberdctl but not with mod_rest. https://www.ejabberd.im/node/3979#comment-56473 <p>Hi,</p> <p>I have configured mod_rest and mod_admin_extra.<br /> I am able to do following command using shell:<br /> ejabberdctl add_rosteritem ashley ashley garth ashley garth Buddies both</p> <p>but when I tried through PHP client, I'm getting the following error.</p> <p>Resolving mydomain.net... xxx.xxx.xxx.xxx<br /> Connecting to mydomain.net|xxx.xxx.xxx.xxx|:5280... connected.<br /> HTTP request sent, awaiting response...<br /> HTTP/1.0 406 Not Acceptable<br /> Connection: keep-alive<br /> Content-Type: text/html; charset=utf-8<br /> Content-Length: 43<br /> 2010-08-02 18:38:00 ERROR <strong>406: Not Acceptable.</strong></p> <p>Could you please point out what else I need to configure?</p> <p>Best Regards,<br /> Sa Lin</p> Tue, 03 Aug 2010 00:04:31 +0000 salin comment 56473 at https://www.ejabberd.im Ok, I've update the code in https://www.ejabberd.im/node/3979#comment-55585 <p>Ok, I've update the code in the README.</p> Thu, 15 Apr 2010 10:11:43 +0000 mfoss comment 55585 at https://www.ejabberd.im Streamlined sendRESTRequest function for PHP4 as well as PHP5 https://www.ejabberd.im/node/3979#comment-55580 <p>I have streamlined the sendRESTRequest function so that it can support PHP5 using file_get_contents and implement the alternative solution for PHP4:</p> <pre> function sendRESTRequest ($url, $request) { // Create a stream context so that we can POST the REST request to $url $context = stream_context_create (array ('http' =&gt; array ('method' =&gt; 'POST' ,'header' =&gt; "Content-Length: ".strlen($request) ,'content' =&gt; $request))); // Use file_get_contents for PHP 5+ otherwise use fopen, fread, fclose if (version_compare(PHP_VERSION, '5.0.0', '&gt;=')) { $result = file_get_contents($url, false, $context); } else { // This is the PHP4 workaround which is slightly less elegant // Supress fopen warnings, otherwise they interfere with the page headers $fp = @fopen($url, 'r', false, $context); $result = ''; // Only proceed if we have a file handle, otherwise we enter an infinite loop if ($fp) { while(!feof($fp)) { $result .= fread($fp, 4096); } fclose($fp); } } return $result; } </pre> Wed, 14 Apr 2010 14:57:13 +0000 qu1cksand comment 55580 at https://www.ejabberd.im example for mod_rest only works in PHP 5 - example in PHP 4 https://www.ejabberd.im/node/3979#comment-55577 <p>Thanks for adding the example PHP code to the mod_rest README.txt.</p> <p>Unfortunately the example PHP code only works in PHP 5 but does not work in PHP 4.</p> <p>It would be better to change the sendRESTRequest function as follows in order for the example code to work in both PHP 4 and PHP 5.</p> <pre> function sendRESTRequest ($url, $xml) { $context = stream_context_create( array('http' =&gt; array( 'method' =&gt; "POST", 'header' =&gt; "Content-Length: ".strlen($xml), 'content' =&gt; $xml ) ) ); $fp = fopen($url, 'r', false, $context); $response = ''; while(!feof($fp)) { $response .= fread($fp, 4096); } fclose($fp); echo "Response: $response\n"; return $response; } </pre> Tue, 13 Apr 2010 15:56:15 +0000 qu1cksand comment 55577 at https://www.ejabberd.im Oh, but in that case it's https://www.ejabberd.im/node/3979#comment-55575 <p>Oh, but in that case it's necessary to parse the response to know if there was any error. I'll keep the code as it is now.</p> <p>I've added your example PHP code to mod_rest README.txt</p> Tue, 13 Apr 2010 11:52:25 +0000 mfoss comment 55575 at https://www.ejabberd.im Update the HTTP status code in mod_rest.erl from 500 to 200 https://www.ejabberd.im/node/3979#comment-55574 <p>If you update the HTTP status code on line 93 of mod_rest.erl from 500 (Internal Server Error) to 200 (OK), then the correct message will be displayed in Python as well as PHP.</p> Tue, 13 Apr 2010 10:35:40 +0000 qu1cksand comment 55574 at https://www.ejabberd.im This is problem with mod_rest not PHP https://www.ejabberd.im/node/3979#comment-55571 <p>This is problem is generic to mod_rest and not a problem with PHP.</p> <p>If you execute the same command in Python, you get the same result:</p> <pre> $ python rest.py Traceback (most recent call last): File "rest.py", line 16, in resp = urllib2.urlopen(server_url, call) File "/usr/lib/python2.6/urllib2.py", line 124, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 395, in open response = meth(req, response) File "/usr/lib/python2.6/urllib2.py", line 508, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.6/urllib2.py", line 433, in error return self._call_chain(*args) File "/usr/lib/python2.6/urllib2.py", line 367, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 516, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Internal Server Error </pre> Mon, 12 Apr 2010 15:43:03 +0000 qu1cksand comment 55571 at https://www.ejabberd.im More changes in PHP, and last problem https://www.ejabberd.im/node/3979#comment-55569 <p>Ok, I made some progress. In fact I don't need the allowed_ips option. Then, in the PHP code I changed the array code to indicate explicitely the Host header:</p> <pre> array( 'method' =&gt; "POST", 'header' =&gt; "Host: localhost:5280\nContent-Type: text/html; charset=utf-8", 'content' =&gt; $xml ) </pre><p> Now I can call:</p> <pre> $ php aa.php file:[User user12@localhost succesfully registered] </pre><p> The only problem is that, when there is some error returned, the PHP code doesn't show the exact error reason:</p> <pre> $ php aa.php PHP Warning: file_get_contents(<noindex><a href="http://127.0.0.1:5280/rest" title="http://127.0.0.1:5280/rest" rel="nofollow" >http://127.0.0.1:5280/rest</a></noindex>): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /modules/mod_rest/trunk/aa.php on line 12 file:[] </pre><p> It's only seen in the network traffic:</p> <pre> HTTP/1.0 500 Internal Server Error Connection: close Content-Type: text/html; charset=utf-8 Content-Length: 65 User user12@localhost already registered at node ejabberd@galleta </pre> Mon, 12 Apr 2010 15:21:11 +0000 mfoss comment 55569 at https://www.ejabberd.im