ejabberd - Comments for "The simplest way to create a new ejabberd user with PHP" https://www.ejabberd.im/node/3126 en Hello, I have tried to apply https://www.ejabberd.im/node/3126#comment-67037 <p>Hello,<br /> I have tried to apply your code as shown above.But its not working for me. there is showing me that STARTTLS error. so would you like to suggest any other debug points ?</p> Sat, 10 Sep 2016 12:53:05 +0000 ankitdoshi2016 comment 67037 at https://www.ejabberd.im i can't able to create user https://www.ejabberd.im/node/3126#comment-57772 <p>i can't able to create user in ejabberd using this php scirpt, whenever i call this script i got this message:</p> <p>******** Exit of User Creation! ErrorCode=12001 ********</p> <p>******** Exit of Add Vcard! ErrorCode=14001 ********</p> <p>my steps are:<br /> 1.i install ejabberd 2.1.8 windows installer.<br /> 2.i also dowload "Jabber Client Library" - Version 0.9rc2 - Copyright 2002-2007, Centova Technologies Inc<br /> 3.i copy your script from <a href="http://www.ejabberd.im/node/3126" title="http://www.ejabberd.im/node/3126">http://www.ejabberd.im/node/3126</a><br /> 4.then i made changes to JABBER_SERVER to localhost,JABBER_USERNAME,JABBER_PASSWORD<br /> 5. set $UserLogin='test100'; $UserPass='test100'</p> <p>so please guide me where i m going wrong.also elobrate about the error code.</p> Tue, 23 Aug 2011 12:31:30 +0000 purshottam comment 57772 at https://www.ejabberd.im Doesn't do what it says... https://www.ejabberd.im/node/3126#comment-55414 <p>Anyone stumbling across this:</p> <blockquote><p>Also... to deny inband registration to everyone, but admins (accounts set in ACL as "admin") you should:</p> <div class="codeblock"><code>%% {access, register, [{allow, all}]}.<br />{access, register, [{allow, admin}, {deny, all}]}.</code></div> </blockquote> <p>doesn't actually do that. It would simply allow any user to register the 'admin' username.</p> Tue, 16 Mar 2010 14:06:57 +0000 aaronwinborn comment 55414 at https://www.ejabberd.im All info is deleted, except privacy lists https://www.ejabberd.im/node/3126#comment-53486 <div class="quote-msg"> <div class="quote-author"><em>philipj</em> wrote:</div> <p>if I, as admin, delete user - all user data (vcard, offline messages) also deleted as well?</p></div> <p>Using ejabberd SVN with internal (Mnesia) storage. I created an account, filled some data in several places, and then deleted the account using the Web Admin. Here are the results:</p> <ul> <li>last_activity: it is deleted</li> <li>offline_msg: it is deleted</li> <li>passwd: it is deleted, obviously :)</li> <li>privacy: it is NOT deleted!</li> <li>private_storage: it is deleted</li> <li>roster: it is deleted</li> <li>vcard: it is deleted</li> </ul> <p>So, all info is correctly deleted from Mnesia tables except the privacy lists. I've reported this bug here: <noindex><a href="https://support.process-one.net/browse/EJAB-720" rel="nofollow" >Privacy lists of a user are not removed when his account is deleted</a></noindex></p> Wed, 13 Aug 2008 21:20:00 +0000 mfoss comment 53486 at https://www.ejabberd.im My solution to create users :) https://www.ejabberd.im/node/3126#comment-53482 <p>Hello all!</p> <p>Finally, I managed to choose the most appropriate solution to automatically create users in ejabberd.</p> <p>As my needs is web... I'd like to create ejabberd users with PHP script.</p> <p>I have following restrictions:</p> <p>1. According with my tasks, inband registration is restricted. User should fill registration info on website, than be approved by local admin (this project for children)... and after that ejabberd account should be set up. Only this way.</p> <p>2. Due to my tasks, new account should be started with some minimum vcard info.</p> <p>---</p> <p>During my research... both methods (ejabberdctl and XML-RPC) is not good.</p> <p>Because... ejabberdctl, when I called it from PHP, as web-server user have a limitation on file access rules... even when I change ejabberdctl permissions, it failed because permissions to DB-files (as I understand).</p> <p>XML-RPC - is quite complex method... XML in, XML out.... I should write a parser, etc...</p> <p>And both things - absolutely unable to create a vcard entries on behalf of new user.</p> <p>So... I choosed another way - to emulate jabber-client with one Jabber-client class.<br /> I used a "Jabber Client Library" - Version 0.9rc2 - Copyright 2002-2007, Centova Technologies Inc.</p> <p>So... before use my solution, someone should download it from somewhere :)</p> <p>Also... to deny inband registration to everyone, but admins (accounts set in ACL as "admin") you should:</p> <div class="codeblock"><code>%% {access, register, [{allow, all}]}.<br />{access, register, [{allow, admin}, {deny, all}]}.</code></div> <p>And... finally... the PHP script to create new user and fill vcard:</p> <div class="codeblock"><code>// set your Jabber server hostname, username, and password here<br />define(&#039;JABBER_SERVER&#039;,&#039;mycoolserver&#039;);<br />define(&#039;JABBER_USERNAME&#039;,&#039;cooladmin&#039;);<br />define(&#039;JABBER_PASSWORD&#039;,&#039;coolpassword&#039;); <p>define(&#039;RUN_TIME&#039;,5); // set a maximum run time of 5 seconds<br />define(&#039;CBK_FREQ&#039;,1); // fire a callback event every second</p> <p>// This class handles events fired by the first call of CommandJabber client class (to create a user);</p> <p>class AddMessenger<br />{</p> <p>function AddMessenger(&amp;$jab,$name,$pass)<br />{<br />$this-&gt;jab = &amp;$jab;<br />$this-&gt;jab-&gt;NewUserName = $name;<br />$this-&gt;jab-&gt;NewUserPass = $pass;<br />}</p> <p>// called when a connection to the Jabber server is established<br />function handleConnected()<br />{<br />global $AddUserErrorCode;<br />$AddUserErrorCode=12002;<br />// now that we&#039;re connected, tell the Jabber class to login<br />$this-&gt;jab-&gt;login(JABBER_USERNAME,JABBER_PASSWORD);</p> <p>}</p> <p>// called after a login to indicate the the login was successful<br />function handleAuthenticated()<br />{<br />global $AddUserErrorCode;<br />$AddUserErrorCode=12003;<br />$this-&gt;jab-&gt;adduser_init();<br />}</p> <p>}<br />// End of AddMessenger class</p> <p>/******************************************************************************************************/</p> <p>// Here is class to handle second call to CommandJabber clase - to fill out vcard</p> <p>class AddVcard<br />{</p> <p>function AddVcard(&amp;$jab,$name,$pass,$firstn,$lastn,$patro,$sex,$role)<br />{<br />$this-&gt;jab = &amp;$jab;<br />$this-&gt;jab-&gt;NewUserName = $name;<br />$this-&gt;jab-&gt;NewUserPass = $pass;<br />$this-&gt;GivenName = iconv(&#039;CP1251&#039;,&#039;UTF-8&#039;,$firstn); // conversion from russian charset :)<br />$this-&gt;FamilyName = iconv(&#039;CP1251&#039;,&#039;UTF-8&#039;,$lastn);<br />$this-&gt;MiddleName = iconv(&#039;CP1251&#039;,&#039;UTF-8&#039;,$patro);<br />}</p> <p>function handleConnected()<br />{<br />global $AddVcardErrorCode;<br />$AddVcardErrorCode=14002;<br />$this-&gt;jab-&gt;login($this-&gt;jab-&gt;NewUserName,$this-&gt;jab-&gt;NewUserPass);<br />}</p> <p>function handleAuthenticated()<br />{<br />global $AddVcardErrorCode;<br />$AddVcardErrorCode=14003;<br />$this-&gt;jab-&gt;addvcard_request($this-&gt;GivenName, $this-&gt;FamilyName, $this-&gt;MiddleName, $this-&gt;UserRole);<br />}</p> <p>} // End of AddVcard class</p> <p>/******************************************************************************************************/</p> <p>// Including original &quot;Jabber Client Library&quot; - class<br />require_once($_SERVER[&#039;DOCUMENT_ROOT&#039;].&#039;/../sinc/jabber/class_Jabber.php&#039;);</p> <p>/******************************************************************************************************/</p> <p>// This is extension to basic Jabber class</p> <p>class CommandJabber extends Jabber<br />{<br />var $AddUserDialogID=0;<br />var $NewUserName, $NewUserPass;</p> <p>function adduser_init()<br />{<br />$this-&gt;AddUserDialogID = $this-&gt;_unique_id(&#039;adduserproc&#039;);</p> <p>$this-&gt;_set_iq_handler(&#039;_on_adduser_initanswer&#039;,$this-&gt;AddUserDialogID);</p> <p>$xml = &#039;&lt;iq from=&quot;&#039;.($this-&gt;jid).&#039;&quot; id=&quot;&#039;.$this-&gt;AddUserDialogID.&#039;&quot; to=&quot;&#039;.($this-&gt;_server_host).&#039;&quot; type=&quot;set&quot;&gt;<br />&lt;command xmlns=&quot;http://jabber.org/protocol/commands&quot; action=&quot;execute&quot; node=&quot;http://jabber.org/protocol/admin#add-user&quot;/&gt;<br />&lt;/iq&gt;&#039;;<br />return $this-&gt;_send($xml);<br />}</p> <p>function _on_adduser_initanswer(&amp;$packet)<br />{<br />global $AddUserErrorCode;<br />$AddUserErrorCode=12004;<br />if ($this-&gt;_node($packet,array(&#039;iq&#039;,&#039;@&#039;,&#039;type&#039;))==&#039;result&#039;) // if isn&#039;t an error response<br /> {<br /> $AddUserErrorCode=12005;<br /> $sessionid=$this-&gt;_node($packet,array(&#039;iq&#039;,&#039;#&#039;,&#039;command&#039;,&#039;0&#039;,&#039;@&#039;,&#039;sessionid&#039;));<br /> if (strlen($sessionid) &amp;&amp; $this-&gt;_node($packet,array(&#039;iq&#039;,&#039;#&#039;,&#039;command&#039;,&#039;0&#039;,&#039;@&#039;,&#039;status&#039;))==&#039;executing&#039;) // response seems to be OK<br />&nbsp; {<br />&nbsp; $AddUserErrorCode=12006;<br />&nbsp; $xml=&#039;&lt;iq from=&quot;&#039;.($this-&gt;jid).&#039;&quot; id=&quot;&#039;.$this-&gt;AddUserDialogID.&#039;&quot; to=&quot;&#039;.($this-&gt;_server_host).&#039;&quot; type=&quot;set&quot;&gt;&lt;command xmlns=&quot;http://jabber.org/protocol/commands&quot; node=&quot;http://jabber.org/protocol/admin#add-user&quot; sessionid=&quot;&#039;.$sessionid.&#039;&quot;&gt;&lt;x xmlns=&quot;jabber:x:data&quot; type=&quot;submit&quot;&gt;&#039;;<br />&nbsp; $fieldsnode=$this-&gt;_node($packet,array(&#039;iq&#039;,&#039;#&#039;,&#039;command&#039;,&#039;0&#039;,&#039;#&#039;,&#039;x&#039;,&#039;0&#039;,&#039;#&#039;,&#039;field&#039;));<br />&nbsp; $i=0;<br />&nbsp; do<br />&nbsp;&nbsp;&nbsp; {<br /> $field_type=$this-&gt;_node($fieldsnode,array($i,&#039;@&#039;,&#039;type&#039;));<br /> $field_var=$this-&gt;_node($fieldsnode,array($i,&#039;@&#039;,&#039;var&#039;));<br /> $field_value=$this-&gt;_node($fieldsnode,array($i,&#039;#&#039;,&#039;value&#039;,&#039;0&#039;,&#039;#&#039;));</p> <p> if ($field_type==&#039;hidden&#039;) $xml.=&#039;&lt;field type=&quot;hidden&quot; var=&quot;&#039;.$field_var.&#039;&quot;&gt;&lt;value&gt;&#039;.$field_value.&#039;&lt;/value&gt;&lt;/field&gt;&#039;;<br /> if ($field_var==&#039;accountjid&#039;) $xml.=&#039;&lt;field type=&quot;&#039;.$field_type.&#039;&quot; var=&quot;accountjid&quot;&gt;&lt;value&gt;&#039;.$this-&gt;NewUserName.&#039;@&#039;.$this-&gt;_server_host.&#039;&lt;/value&gt;&lt;/field&gt;&#039;;<br /> if ($field_var==&#039;password&#039;) $xml.=&#039;&lt;field type=&quot;&#039;.$field_type.&#039;&quot; var=&quot;password&quot;&gt;&lt;value&gt;&#039;.$this-&gt;NewUserPass.&#039;&lt;/value&gt;&lt;/field&gt;&#039;;<br /> if ($field_var==&#039;password-verify&#039;) $xml.=&#039;&lt;field type=&quot;&#039;.$field_type.&#039;&quot; var=&quot;password-verify&quot;&gt;&lt;value&gt;&#039;.$this-&gt;NewUserPass.&#039;&lt;/value&gt;&lt;/field&gt;&#039;;<br /> $i++;<br /> }<br />&nbsp; while (strlen(trim($field_type)) &amp;&amp; $i&lt;20);<br />&nbsp; <br />&nbsp; $xml.=&#039;&lt;/x&gt;&lt;/command&gt;&lt;/iq&gt;&#039;;<br />&nbsp; $this-&gt;_set_iq_handler(&#039;_on_adduser_getresult&#039;,$this-&gt;AddUserDialogID);<br />&nbsp; $this-&gt;_send($xml);<br />&nbsp; }<br /> }<br />}</p> <p>function _on_adduser_getresult(&amp;$packet)<br />{<br />global $AddUserErrorCode;<br />$AddUserErrorCode=12007;<br />if ($this-&gt;_node($packet,array(&#039;iq&#039;,&#039;@&#039;,&#039;type&#039;))==&#039;result&#039;)<br /> {<br /> if ($this-&gt;_node($packet,array(&#039;iq&#039;,&#039;#&#039;,&#039;command&#039;,&#039;0&#039;,&#039;@&#039;,&#039;status&#039;))==&#039;completed&#039;);<br /> $AddUserErrorCode=0;<br /> }</p> <p>$this-&gt;terminated = true;<br />}</p> <p>// following functions - for fill Vcard only</p> <p>function addvcard_request($GivenName, $FamilyName, $MiddleName)<br />{<br />$DialogID = $this-&gt;_unique_id(&#039;addvcard&#039;);</p> <p>$this-&gt;_set_iq_handler(&#039;_on_addvcard_reply&#039;,$DialogID);</p> <p>$xml = &#039;&lt;iq from=&quot;&#039;.($this-&gt;jid).&#039;&quot; id=&quot;&#039;.$DialogID.&#039;&quot; type=&quot;set&quot;&gt;<br />&lt;vCard xmlns=&quot;vcard-temp&quot;&gt;<br />&lt;N&gt;&lt;FAMILY&gt;&#039;.$FamilyName.&#039;&lt;/FAMILY&gt;&lt;GIVEN&gt;&#039;.$GivenName.&#039;&lt;/GIVEN&gt;&lt;MIDDLE&gt;&#039;.$MiddleName.&#039;&lt;/MIDDLE&gt;&lt;/N&gt;<br />&lt;/vCard&gt;<br />&lt;/iq&gt;&#039;;<br />return $this-&gt;_send($xml);<br />}</p> <p>function _on_addvcard_reply(&amp;$packet)<br />{<br />global $AddVcardErrorCode;<br />$AddVcardErrorCode=14004;</p> <p>if ($this-&gt;_node($packet,array(&#039;iq&#039;,&#039;@&#039;,&#039;type&#039;))==&#039;result&#039;) $AddVcardErrorCode=0;</p> <p>$this-&gt;terminated = true;<br />}</p> <p>} // End of Jabber class extension</p> <p>/******************************************************************************************************/<br />// NOW WE START TO USE ALL CLASSES ABOVE :)</p> <p>// create an instance of the Jabber class<br />$display_debug_info = false;<br />$AddUserErrorCode = 12000;<br />$UserLogin=&#039;test100&#039;; $UserPass=&#039;test100&#039;;<br />$FirstName=&#039;Philip&#039;; $LastName=&#039;J.&#039;; $Patronymic=&#039;Ivanovich :)&#039;;</p> <p>$jab = new CommandJabber($display_debug_info);<br />$addmsg = new AddMessenger($jab,$UserLogin,$UserPass);</p> <p>// set handlers for the events we wish to be notified about<br />$jab-&gt;set_handler(&quot;connected&quot;,$addmsg,&quot;handleConnected&quot;);<br />$jab-&gt;set_handler(&quot;authenticated&quot;,$addmsg,&quot;handleAuthenticated&quot;);<br />//$jab-&gt;set_handler(&quot;error&quot;,$addmsg,&quot;handleError&quot;);</p> <p>// connect to the Jabber server<br />if ($jab-&gt;connect(JABBER_SERVER))<br />{<br />$AddUserErrorCode=12001;<br />$jab-&gt;execute(CBK_FREQ,RUN_TIME);<br />}</p> <p>$jab-&gt;disconnect();</p> <p>unset($jab,$addmsg);</p> <p>echo &#039;&lt;P&gt;******** Exit of User Creation! ErrorCode=&#039;.$AddUserErrorCode.&#039; ********&lt;/P&gt;&#039;;</p> <p>// If AddUserErrorCode is 0, we can try to fill user&#039;s Vcard, using brand new credentials :)</p> <p>$AddVcardErrorCode = 14000;<br />$jab = new CommandJabber($display_debug_info);<br />$avcard = new AddVcard($jab,$UserLogin,$UserPass,$FirstName,$LastName,$Patronymic);</p> <p>$jab-&gt;set_handler(&quot;connected&quot;,$avcard,&quot;handleConnected&quot;);<br />$jab-&gt;set_handler(&quot;authenticated&quot;,$avcard,&quot;handleAuthenticated&quot;);</p> <p>if ($jab-&gt;connect(JABBER_SERVER))<br />{<br />$AddVcardErrorCode=14001;<br />$jab-&gt;execute(CBK_FREQ,RUN_TIME);<br />}</p> <p>$jab-&gt;disconnect();</p> <p>unset($jab,$avcard);</p> <p>echo &#039;&lt;P&gt;******** Exit of Add Vcard! ErrorCode=&#039;.$AddVcardErrorCode.&#039; ********&lt;/P&gt;&#039;;</p></code></div> <p>Of course, You can extend this, with class-functions to change user's password... or to delete user completely...</p> <p>Hope it helps somebody..</p> <p>I edited this script, delete some important my project specific data... So I can't guarantee, that ready for 100%.</p> <p>BTW - question to gurus :) - if I, as admin, delete user - all user data (vcard, offline messages) also deleted as well?</p> Wed, 13 Aug 2008 18:09:47 +0000 philipj comment 53482 at https://www.ejabberd.im All what I know is already https://www.ejabberd.im/node/3126#comment-53394 <p>All what I know is already documented in the README.txt in the mod_xmlrpc directory.</p> Tue, 08 Jul 2008 23:07:49 +0000 mfoss comment 53394 at https://www.ejabberd.im Thanx for info https://www.ejabberd.im/node/3126#comment-53373 <p>very much...</p> <p>But... can You tell, if there some guide or manual, how to configure mod_xmlrpc for as much secureness as possible :) and maybe, simple example, how to communicate with web-based scripts (e.g. PHP :)</p> Thu, 03 Jul 2008 19:10:23 +0000 philipj comment 53373 at https://www.ejabberd.im Two more ways to register an https://www.ejabberd.im/node/3126#comment-53368 <p>Two more ways to register an account in ejabberd:</p> <p>1) Using ejabberdctl. In the system shell:</p> <pre> $ sudo ejabberdctl register tomcat localhost PaSS556y $ echo $? 0 $ sudo ejabberdctl register tomcat localhost PaSSff User "tomcat@localhost" already registered at node ejabberd@localhost $ echo $? 1 $ sudo ejabberdctl register tom jabberrrr.example.org PaSS556y Can't register user "tom@jabberrrr.example.org" at node ejabberd@localhost: not_allowed $ echo $? 1</pre><p> 2) Using XML-RPC calls. You would need to install <noindex><a href="/mod_xmlrpc" rel="nofollow" >mod_xmlrpc</a></noindex></p> Tue, 01 Jul 2008 18:49:39 +0000 mfoss comment 53368 at https://www.ejabberd.im