Roundcube Community Forum

 

Let Users Signup for email accounts. hMailServer + RoundCube

Started by MHOS, January 04, 2008, 05:17:30 PM

Previous topic - Next topic

MHOS

Hey fellas,

I was checking out the hMailServer Forums the other day and came across this script to allow users to signup for email accounts.
My questions is to anyone that can help that know there way around RoundCube is to incorperate this into the login page.
I was able to do alittle tweaking to get a Signup button and open an external window with the script in it, but i would like to keep it in the RoundCube window to make it seem more professional. Here is a screenshot of what im talking about. Also this script is working for me with the newest version of hMailServer with the exception of the admin notification email. If anyone can shead some light on that it would be much appreciated.



Here is the script:
<?php 
error_reporting
(E_ALL & ~E_NOTICE); 
//MySQL database connection information 
//MySQL connection information: 
$mysql_host = &quot;&quot;; //Host Name 
$mysql_user = &quot;&quot;; //Username 
$mysql_pass = &quot;&quot;; //Password 
$mysql_db = &quot;hmailserver&quot;; //Database 

//General Configuration: 
$form_title = &quot;Email Setup&quot;; //Name for this form 
$account_max = &quot;10000000&quot;; //Maximum size per account (1000000 = 1MB -> Do not uses spaces or commas!) 
$admin_notify = &quot;1&quot;; //1 = yes & 0 = no 
$admin_email = &quot;&quot;; //Administrators email to send notifications) 
$admin_default_activate = &quot;0&quot;; //1 = yes & 0 = no -> If no, the administrator has to authorise the account 
$accountisad 0// account is AD-account? 0 = no (default), 1 = yws; 
$encryption 2//Password encryption level - 2 means md5; 
$domain ''// the domain, where the account should be added too 

$serv_webmail_url ''// full URL to the webmail-application 

$url $_SERVER[&quot;HTTP_HOST&quot;]; 
$domain = (empty($domain))? $_SERVER[&quot;HTTP_HOST&quot;] : $domain
$domain = (substr($domain,0,4) == &quot;[url]www.&quot;[/url])? strstr($domain, &quot;.&quot;) : $domain

// Protect database entries and use MD5 encryption 
$strName  = (isset($_POST['name']))? addslashes$_POST['name'] ) : ''
$strUser  = (isset($_POST['user']))? addslashes$_POST['user'] ) : ''

$strDomain addslashes( &quot;$domain&quot; ); 
$strPass1 = (isset($_POST['pass1']))? addslashes$_POST['pass1'] ) : ''
 
//Connect to database using information from above 
$open mysql_connect($mysql_host$mysql_user$mysql_pass); 
$select mysql_select_db($mysql_db); 

if (!
$open || !$select

 echo &
quot;Unable to open databasecontact your administrator!&quot;; 
} else { 
 echo &
quot;<font size=\&quot;+1\&quot;>$form_title</font><br /><br />&quot;; 
  
 if ( isset(
$_POST['submit']) && $_POST['submit'] == 'create account' 
 { 
  
$domain_res mysql_query(&quot;SELECT FROM `hm_domainsWHERE `domainname` = '{$strDomain}' LIMIT 1&quot;); 
   if (!
$domain_res
   { 
    die(
'Error while selecting data: ' mysql_error()); 
   } 
   
$domain_info mysql_fetch_array($domain_resMYSQL_ASSOC); 

  
//Check to see if email account exists, if not process signup 
  
$account_res mysql_query(&quot;SELECT FROM `hm_accountsWHERE `accountaddress` = '{$strUser}@$strDomain' LIMIT 1&quot;); 
  
$v1 mysql_num_rows($account_res); 
    
  If (
$v1 >= 1
  { 
   echo &
quot;A subscriber with this email already exists!<br /><br />Please <a href=\&quot;javascript:history.go(-1)\&quot;>click here</ato go back.&quot;; 
   return 
false
  } else { 
   if ( !
$_POST['pass1'] || !$_POST['pass2'] ) 
   { 
    echo &
quot;You did not enter both passwords!<br /><br />Please <a href=\&quot;javascript:history.go(-1)\&quot;>click here</ato go back.&quot;; 
   } 
   elseif ( 
$_POST['pass1'] != $_POST['pass2'] ) 
   { 
    echo &
quot;The passwords entered do not match!<br /><br />Please <a href=\&quot;javascript:history.go(-1)\&quot;>click here</ato go back.&quot;; 
   } else { 
    
$domain_id $domain_info['domainid']; 
    
$account_pass = ($encryption == 2)? md5$strPass1 ) : $strPass1
     
    
$account_add mysql_query(&quot;INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$domain_id','$strUser@$strDomain','$account_pass','$admin_default_activate','$accountisad','$account_max','$encryption')&quot;); 
   } 
  } 
  
  if (!
$account_add
   { 
    die(
'<br /><br />Database error, unable to add account. Please contact your administrator!<br /> ' mysql_error()); 
   } 
    
  If (
$admin_default_activate == 0
  { 
   echo &
quot;Your account has been created but <b>requires activation</bby administration.&quot;; 
   echo &
quot;Once your application has been approvedyou will receive a confirmation message.<br /><br />&quot;; 
  } else { 
   echo &
quot;Your account has been created and is ready for use!<br /><br />&quot;; 
   echo &
quot;Username$strUser@$strDomain<br /><br />&quot;; 
   if ( !empty(
$serv_webmail_url) ) echo &quot;Webmail: <a href=\&quot;$serv_webmail_url\&quot;>www.$strDomain/webmail</a><br />&quot;; 
   echo &
quot;POP3mail.$strDomain<br />&quot;; 
   echo &
quot;IMAPmail.$strDomain<br />&quot;; 
   echo &
quot;SMTPmail.$strDomain<br />&quot;; 
    
   
$subject = &quot;Welcome To $strDomain Email!&quot;; 
   
$message = &quot;This is confirmation that your account has been createdYou may now login to your account and start using it.&quot;; 

   
mail(&quot;{$_POST['user']}@$strDomain&quot;, $subject$message); //Send welcome message 
  

    
  if (
$admin_default_activate == && $admin_notIfy == 1
  { 
   
$admin_mail_subject = &quot;Account Requires Activation!&quot;; 
   
$admin_mail_message = &quot;The email account {$_POST['user']}@$strDomain has been created by {$_POST['name']} and requires administration activation!\r\n\r\nPlease login to the admin control panel to verIfy and activate user account.\r\n\r\n&quot;; 
   
mail($admin_email$admin_mail_subject$admin_mail_message); 
  } 
  elseif (
$admin_default_activate == && $admin_notIfy == 1
  { 
   
$admin_mail_subject = &quot;New Account Created!&quot;; 
   
$admin_mail_message = &quot;{$_POST['user']}@$strDomain has been created by {$_POST['name']}!&quot;; 
   
mail($admin_email$admin_mail_subject$admin_mail_message); 
  } 
 } 

  
 
//Email account signup page 
 
echo &quot
  <
table width=\&quot;350\&quotborder=\&quot;0\&quotcellpadding=\&quot;0\&quotcellspacing=\&quot;2\&quot;> 
  <
form action=\&quot;\&quotmethod=\&quot;POST\&quot;> 
   <
tr><td>Full Name:</td><td><input type=\&quot;text\&quotname=\&quot;name\&quotsize=\&quot;21\&quot;></td></tr
   <
tr><td>E-Mail:</td><td><input type=\&quot;text\&quotname=\&quot;user\&quotsize=\&quot;21\&quot;> @ &quot;.$domain.&quot;</td></tr
   <
tr><td>Password:</td><td><input type=\&quot;password\&quotname=\&quot;pass1\&quotsize=\&quot;21\&quot;></td></tr
   <
tr><td>Password:</td><td><input type=\&quot;password\&quotname=\&quot;pass2\&quotsize=\&quot;21\&quot;> (For Confirmation)</td></tr
   <
tr><td colspan=\&quot;2\&quotalign=\&quot;center\&quot;><input type=\&quot;submit\&quotname=\&quot;submit\&quotvalue=\&quot;create account\&quotstyle=\&quot;width98%\&quot;></td></tr
  </
form
  </
table>&quot;; 
?>

If anyone would like to try this out like I have it, here is what I did to incoperate it into the login.

First you need to copy the above code and edit it to spec and save it to what ever you want to name it.
Then find and open /skins/default/templates/login.html and edit it with you fav editor.

Once open search for the line:

" />Now go to the end of that line and press enter.

Add this line on the new blank line:


In the end it should look similar to this:

" />


Hope everything goes well.
MHOS

bpat1434

Well, easiest thing would be to edit the login template and add a "Don't have an email account? Register for a free one!" link under the login form. Have that point to this script (call it "register.php") and that's it. You can add your HTML styling to that as you need.
 
 

MHOS

Ok

Thanks for the info. I was not sure if just editing the login.html would be the best method of adding it.

bpat1434

Well, there are other methods to do this. One would be to modify the source to add an action called "register" that would pull up a new template which allows them to register. But that's a lot of work.

I just gave you the easiest answer. You can go whichever way you want.
 
 

surfsurf

Does this create accounts that the admin can't access, e.g. different from those created under cPanel?

raju_midatha

Can you please provide SQL table structure for Table  'hm_domains'

mangesh

signup script provided here is not running on my wampserver,
please send me complete settings with example

amail

could you help me install that registration form script  yair@amail.mobi


amail

regarding the new window for sign up  NAME="btnNewWindow" ?