WHMCS - Virtualmin Username Standardization

3 posts / 0 new
Last post
#1 Mon, 08/15/2011 - 11:06
xtremeservices

WHMCS - Virtualmin Username Standardization

The way I was able to get around the default WHMCS username generated (first 8 chars of domain) and create usernames consistent with my settings in Virtualmin :

Created a file named virtualmin-domain-usernames.php inside of includes/hooks/

Pasted the following content into that file :

<div class="codeblock"><pre><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">&</span><span style="color: #FF8000">#10;function apply_custom_username_fulldomain($vars) {&#10;    $orderID = $vars[&#039;OrderID&#039;];&#10;    $result = mysql_query(&quot;SELECT * FROM tblhosting WHERE orderid=$orderID&quot;);&#10;    while ($data = mysql_fetch_array($result)) {&#10;        $id = $data[&quot;id&quot;];&#10;        // make custom $username var here based on full domain&#10;        $username = $data[&quot;domain&quot;];&#10;        $queryresult = mysql_query(&quot;UPDATE tblhosting SET username=&#039;$username&#039; WHERE id=$id&quot;);&#10;    }&#10;}&#10;&#10;function apply_custom_username_firstpartofdomain($vars) {&#10;    $orderID = $vars[&#039;OrderID&#039;];&#10;    $result = mysql_query(&quot;SELECT * FROM tblhosting WHERE orderid=$orderID&quot;);&#10;    while ($data = mysql_fetch_array($result)) {&#10;        $id = $data[&quot;id&quot;];&#10;        $domainparts = explode(&quot;.&quot;,$data[&quot;domain&quot;]);&#10;        // make custom $username var here based on first part of domain&#10;        $username = $domainparts[0];&#10;        $queryresult = mysql_query(&quot;UPDATE tblhosting SET username=&#039;$username&#039; WHERE id=$id&quot;);&#10;    }&#10;}&#10; add_hook(&quot;AfterShoppingCartCheckout&quot;,1,&quot;apply_custom_username_firstpartofdomain&quot;);&#10;// add_hook(&quot;AfterShoppingCartCheckout&quot;,1,&quot;apply_custom_username_fulldomain&quot;);&#10;<br /></span><span style="color: #0000BB">?></span></span></code></pre></div>

If you use the entire domain.TLD as the username, comment out the first add_hook line and uncomment the second.

~Jeremy

Mon, 08/15/2011 - 13:17
andreychek

Thanks good info, thanks for sharing how you solved that!

-Eric

Tue, 08/16/2011 - 04:54
Locutus

Did you run into the issue that WHMCS ignores the custom username you set for Virtualmin service setup, and always reverts to its default scheme?

I submitted that as a bug report to the WHMCS people and received a corrected "virtualmin.php" file for use in WHMCS, which fixed the issue for me.

If you're interested, I can send you that file. :)

Topic locked