<?php
#
# This file is part of Roundcube "register" plugin.
#
# Your are not allowed to distribute this file or parts of it.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Copyright (c) 2012 - 2013 Roland 'Rosali' Liebl - all rights reserved.
# dev-team [at] myroundcube [dot] com
# http://myroundcube.com
#
class register extends rcube_plugin{var$task='login|logout|settings';var$noframe=true;static private$plugin='register';static private$author='[email protected]';static private$authors_comments='NOTE: If you use global_config plugin, you have to configure the driver in global_config\'s configuration.<br />News: cPanel xmlapi driver<br /><a href="http://myroundcube.com/myroundcube-plugins/register-plugin" target="_new">Documentation</a>';static private$download='http://myroundcube.googlecode.com';static private$version='2.7.9.2';static private$date='27-05-2013';static private$licence='All Rights reserved';static private$requirements=array('Roundcube'=>'0.7.1','hMailserver'=>'5.2','PHP'=>'5.2.1','recommended_plugins'=>array('taskbar'=>'config'),);static private$prefs=null;static private$config_dist='config.inc.php.dist';function init(){$A=rcmail::get_instance();if(!in_array('global_config',$A->config->get('plugins'))){$this->load_config();if($J=$A->config->get('register_driver',false)){if(file_exists("./plugins/register/drivers/$J/config.inc.php")){$this->load_config("drivers/$J/config.inc.php");}}else{return;}}$this->add_texts('localization/',true);$this->include_script('register.js');$this->add_hook('startup',array($this,'register_form'));$this->add_hook('template_object_domaingroups',array($this,'register_domain_groups'));$this->add_hook('template_object_domainselector',array($this,'register_domain_selector'));}static function about($R=false){$L=self::$requirements;foreach(array('required_','recommended_')as$M){if(is_array($L[$M.'plugins'])){foreach($L[$M.'plugins']as$I=>$S){if(class_exists($I)&&method_exists($I,'about')){$Z=new$I(false);$L[$M.'plugins'][$I]=array('method'=>$S,'plugin'=>$Z->about($R),);}else{$L[$M.'plugins'][$I]=array('method'=>$S,'plugin'=>$I,);}}}}$V=array();if(is_string(self::$config_dist)){if(is_file($a=INSTALL_PATH.'plugins/'.self::$plugin.'/'.self::$config_dist))include$a;else write_log('errors',self::$plugin.': '.self::$config_dist.' is missing!');}$E=array('plugin'=>self::$plugin,'version'=>self::$version,'date'=>self::$date,'author'=>self::$author,'comments'=>self::$authors_comments,'licence'=>self::$licence,'download'=>self::$download,'requirements'=>$L,);if(is_array(self::$prefs))$E['config']=array_merge($V,array_flip(self::$prefs));else$E['config']=$V;if(is_array($R)){$W=array('plugin'=>self::$plugin);foreach($R as$B){$W[$B]=$E[$B];}return$W;}else{return$E;}}function register_form($F){if($_GET['_action']!='register'){return$F;}if(isset($_GET['_ajax'])){$this->register_ajax();}$A=rcmail::get_instance();$Q=$A->config->get('skin');if(!file_exists("plugins/register/skins/$Q/register.css"))$Q="default";$this->include_stylesheet('skins/'.$Q.'/register.css');$A->output->add_script("var password_min_length = '".$A->config->get('password_min_length')."';");if(!$_SESSION['captcha_solved'])$A->config->set('captcha_auth',true);$A->output->send("register.register");exit;}function register_ajax(){$A=rcmail::get_instance();if(isset($_POST['_username'])&&!empty($_POST['_username'])&&isset($_POST['_domain'])&&!empty($_POST['_domain'])&&isset($_POST['_pass'])&&!empty($_POST['_pass'])){foreach($_POST as$B=>$G){$_POST[$B]=trim($G);}$b=strtolower($_POST['_username']);$Y=array_flip($A->config->get('disallowedaccounts'));if(isset($Y[$b])){echo"error:register.disallowedaccount:_username";exit;}$N=strtolower($_POST['_username'])."@".strtolower($_POST['_domain']);$A=rcmail::get_instance();$J=$A->config->get('register_driver');if(file_exists("./plugins/register/drivers/$J/driver.inc.php"))require_once("./plugins/register/drivers/$J/driver.inc.php");else die("Plugin Register: Self Registration Driver not found");if(rcube_register_user_exists($N)){echo"error:register.userexists:_username";exit;}if(rcube_register_alias_exists($N)){echo"error:register.userexists:_username";exit;}$X=$_POST['_pass'];$E=rcube_register_new_imap_user($N,$X);if($E===true){if(class_exists('correo')){correo::save($this->getVisitorIP());}echo"ok:$N";}else if($E===false){echo"error:register.createuserfailed:_username";}else{echo"error:$E:_username";}exit;}else{echo"error:register.failure:_username";}exit;}function register_domain_groups($F){$A=rcmail::get_instance();$D=$A->config->get('webadddoms');if(count($D)<=1)return$F;$P="";if(isset($_GET['_group'])){$P=trim(urldecode($_GET['_group']));}else if(isset($_POST['_group'])){$P=trim($_POST['_group']);}$C="<tr>\n<td class=\"title\" nowrap>".$this->gettext('register.domain_groups')."</td>\n<td>\n";$C.="\n".'<select id="sel_group" name="_group" onchange="javascript:register_change_group()">'."\n";foreach($D as$B=>$G){if($P==$B){$U="selected";}else{$U="";}$C.="\t<option $U value=\"$B\">$B</option>\n";}$C.="</select>\n</td>\n</tr>\n";$F['content']=$C;return$F;}function register_domain_selector($F){$A=rcmail::get_instance();$D=$A->config->get('webadddoms');if(isset($_GET['_group'])){$H=urldecode(trim($_GET['_group']));}else if(isset($_POST['_group'])){$H=trim($_POST['_group']);}else{foreach($D as$B=>$G){$H=$B;break;}}if(count($D[$H])<=1){$C="<input type=\"hidden\" name=\"_domain\" value=\"".$D[$H][0]."\" /><span>".$D[$H][0]."</span>";}else{$C="\n".'<select name="_domain">';foreach($D[$H]as$B=>$G){$C.="\t<option value=\"".$G."\">".$G."</option>\n";}$C.="</select>\n";}$F['content']=$C;return$F;}function getVisitorIP(){$c="/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/";if(isset($K["HTTP_X_FORWARDED_FOR"])&&!empty($K["HTTP_X_FORWARDED_FOR"])){$T=(!empty($K["HTTP_X_FORWARDED_FOR"]))?$K["HTTP_X_FORWARDED_FOR"]:((!empty($O['HTTP_X_FORWARDED_FOR']))?$O['HTTP_X_FORWARDED_FOR']:@getenv('HTTP_X_FORWARDED_FOR'));}else{$T=(!empty($K['REMOTE_ADDR']))?$K['REMOTE_ADDR']:((!empty($O['REMOTE_ADDR']))?$O['REMOTE_ADDR']:@getenv('REMOTE_ADDR'));}return$T;}}
Code (PHP)
/***************************************************************************
* This file is part of Roundcube "##PLUGIN##" plugin.
*
* Your are not allowed to distribute this file or parts of it.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Copyright (c) 2012 - ##YEAR## Roland 'Rosali' Liebl - all rights reserved
* dev-team [at] myroundcube [dot] com
* http://myroundcube.com
***************************************************************************/
$(document).ready(function(){window.rcmail&&rcmail.addEventListener("init",function(){$("[name='_username']").select();rcmail.register_command("plugin.register-save",function(){var a=rcmail.set_busy(!0,"loading"),b;b=register(!1);rcmail.set_busy(!1,"loading",a);return b},!0)})});$(document).keypress(function(a){13==a.charCode&&$(".mainaction").trigger("click")});
function register(a){var b=$("[name='_username']"),e=$("[name='_domain']"),c=$("[name='_pass']"),f=$("[name='_confirm_pass']"),g=$("[name='_firstname']"),h=$("[name='_lastname']"),i=$("[name='_gender']"),j=$("[name='_country']"),k=$("[name='_birthday']"),l=b.val()+"@"+e.val();if(!rcube_check_email(l,!1))return $("input.focus:last").focus(),rcmail.display_message(rcmail.gettext("invalidemail","register"),"error"),!1;if(c.val().length<password_min_length)return c.select(),a=rcmail.gettext("passwordshort",
"register"),a=a.replace("%s",password_min_length),rcmail.display_message(a,"error"),!1;if(c.val()!=f.val())return f.select(),rcmail.display_message(rcmail.gettext("passwordnotmatch","register"),"error"),!1;if(!a&&"function"==typeof captchaValidate)return captchaValidate("register(true)"),!1;$.post("./?_action=register&_ajax=1",{_username:""+b.val()+"",_domain:""+e.val()+"",_pass:""+c.val()+"",_firstname:""+g.val()+"",_lastname:""+h.val()+"",_gender:""+i.val()+"",_country:""+j.val()+"",_birthday:""+
k.val()+""},function(a){if(0<a.length){var d=a.split(":"),c=d[0],a=d[1],d=d[2];if("ok"==c)register_login(a);else return"js"==c?(eval(a),b.val(repl),b.focus(),rcmail.display_message(rcmail.gettext("emailmodified","register"),"error")):(rcmail.display_message(rcmail.gettext(a,"register"),"error"),d&&$("[name='"+d+"']").select()),!1}});return!0}
function register_login(a){rcmail.display_message(rcmail.gettext("createusersuccess","register"),"confirmation");document.forms.registerform._user.value=a;document.forms.registerform.action="./";document.getElementById("register_submit").disabled="disabled";rcmail.set_busy(!0,"loading");window.setTimeout("document.forms.registerform.submit()","5000")}function register_change_group(){var a=$("[name='_group']");document.location.href=document.location.href+"&_group="+escape(a.val())};