Exemplo n.º 1
0
function main_fetchmail_build(){
	include_once('ressources/class.user.inc');
	include_once('ressources/class.main_cf.inc');
	include_once('ressources/class.fetchmail.inc');
	
	
$failed=false;	
	
$isp_address_mail=$_GET["isp_address_mail"];
$isp_pop3_server=$_GET["isp_pop3_server"];
$isp_smtp_server=$_GET["isp_smtp_server"];
	
$isp_account=$_GET["isp_account"];
$isp_password=$_GET["isp_password"];
$local_email=$_GET["local_email"];
$local_password=$_GET["local_password"];
	
$isp_smtp_account=$_GET["isp_smtp_account"];
$isp_smtp_password=$_GET["isp_smtp_password"];
	
$relay_server=$_GET["relay_server"];


if($local_email==null){
	echo main_fetchmail_build_results(true,'local mail (False)');
	exit;
}

$ldap=new clladp();
writelogs("i try to found if user exists",__FUNCTION__,__FILE__);
$uid=$ldap->uid_from_email($local_email);
if($uid<>null){
	$user=new user($local_email);
	$ou=$user->ou;
}else{
	writelogs("no user found, create it",__FUNCTION__,__FILE__);
	$tb=explode("@",$local_email);
	$local_domain=$tb[1];  
	$user=new user($tb[0]);
	$ou=$ldap->ou_by_smtp_domain($local_domain);
	if($ou==null){
		$ou=$local_domain;
		writelogs("Adding new organization $ou",__FUNCTION__,__FILE__);
		$ldap->AddOrganization($ou);
	}	
	
}


	
	writelogs("Creating user",__FUNCTION__,__FILE__);
	$user=new user($local_email);
	$user->mail=$local_email;
	$user->password=$local_password;
	$user->ou=$ou;
	$user->SenderCanonical=$isp_address_mail;
	if(!$user->add_user()){
		echo main_fetchmail_build_results(true,$user->ldap_error);
		exit;
	}
	
	
	if($isp_smtp_account<>null){
		writelogs("Creating SMTP authentification for $isp_smtp_server width $isp_smtp_account",__FUNCTION__,__FILE__);
		$sasl=new smtp_sasl_password_maps();
		$sasl->add($isp_address_mail,$isp_smtp_account,$isp_password);
		$main=new main_cf();
		writelogs("Enable sasl engine in postfix",__FUNCTION__,__FILE__);
		$main->smtp_sasl_password_maps_enable_2();		
		
	}
	writelogs("Creating sender_dependent_relayhost_maps -> $isp_smtp_server",__FUNCTION__,__FILE__);
	$sender=new sender_dependent_relayhost_maps();
	if(!$sender->Add($isp_address_mail,$isp_smtp_server)){
		echo main_fetchmail_build_results(true,"sender_dependent_relayhost_maps:$sender->ldap_error");
		exit;
	}
	

	$fetchmail=new Fetchmail_settings();
	$array["poll"]=$isp_pop3_server;
	$array["proto"]="auto";
	$array["keep"]="yes";
	$array["user"]=$isp_account;
	$array["pass"]=$isp_password;
	$array["is"]=$local_email;
	$array["fetchall"]="yes";
	$line=$fetchmail->compile($array);
	if(!$user->fetchmail_add_rule($line)){
		echo main_fetchmail_build_results(true,"fetchmail rule:$user->ldap_error");
		exit;
	}
	
	$relay=new Routing($ou);
	if($relay_server<>null){
		if(!$relay->create_relay_server($local_domain,$relay_server,$ou)){
				echo main_fetchmail_build_results(true,"relay:$relay->ldap_error");
			}
		}else{
			if(!$relay->create_localdomain($ou,$local_domain)){
				echo main_fetchmail_build_results(true,"local domain:$relay->ldap_error");
			}
		}

	
	$fetchmail=new fetchmail();
	$fetchmail->Save();
	$main=new main_cf();
	$main->save_conf();
	$main->save_conf_to_server();
	
	
	
	$info="<table style='width:100%'>
	<tr>
		<td width=1%><img src='img/fw_bold.gif'></td>
		<td nowrap align='right'><strong>{organization}</strong>:</td>
		<td nowrap><strong>$ou</strong></td>
	</tr>
	<tr>
		<td width=1%><img src='img/fw_bold.gif'></td>
		<td nowrap align='right'><strong>{local_mail}</strong>:</td>
		<td nowrap><strong>$local_email</strong></td>
	</tr>
	<tr>
		<td width=1%><img src='img/fw_bold.gif'></td>
		<td nowrap align='right'><strong>{isp_address_mail}</strong>:</td>
		<td nowrap><strong>$isp_address_mail</strong></td>
	</tr>			
	</table>	
	";
	
	echo main_fetchmail_build_results(false,$info);
	
	
}
Exemplo n.º 2
0
function SenderTableSave(){
	$tpl=new templates();
	if($_GET["domain"]==null && $_GET["email"]==null){echo $tpl->_ENGINE_parse_body('{error_give_email_or_domain}');exit;}
	if($_GET["domain"]<>null && $_GET["email"]<>null){echo $tpl->_ENGINE_parse_body('{error_choose_email_or_domain}');exit;}			
	if($_GET["relay_address"]==null){echo $tpl->_ENGINE_parse_body('{error_no_server_specified}');exit;}
	
	if($_GET["MX_lookups"]=="no"){$_GET["relay_address"]="[" . $_GET["relay_address"] . "]";}
	if($_GET["domain"]==null){$_GET["domain"]=$_GET["email"];}
	
	$sender=new sender_dependent_relayhost_maps();
	if(!$sender->Add($_GET["domain"],$_GET["relay_address"])){
		echo $sender->last_error;
		exit;
	}
	
	if(isset($_GET["smtp_tls_policy_maps"])){
		$ldap->smtp_tls_policy_maps_add($_GET["domain"],null,$_GET["MX_lookups"],$_GET["smtp_tls_policy_maps"]);
	}
	
		$sock=new sockets();
	$sock->getFrameWork("services.php?postfix-single=yes");
}