<?php
if(isset($_GET['ip']) AND !empty($_GET['ip']) AND filter_var($_GET['ip'], FILTER_VALIDATE_IP)) {
	$path = '/var/www/app/mailer/server/access/config.d/';
	$file = $path.'sources.txt';
	if(!file_exists($file)) {
		mkdir($path,0777);
	}
	$src = file_get_contents($file);
	if (FALSE === strpos($src,'<source ' . $_GET["ip"] . '>')) {
	  $fopen = fopen($file, 'a+');
		$content.= "<source ".$_GET["ip"].">\n".
			   "\talways-allow-relaying yes\n\t".
			   "smtp-service yes \n\t".
			   "process-x-envid true\n\t".
			   "process-x-job true\n\t".
			   "process-x-virtual-mta true\n\t".
			   "add-received-header no\n\t".
			   "hide-message-source     true\n\t".
			   "remove-header vectparam\n\t".
			   "log-connections yes\n\t".
			   "log-data no\n\t".
			   "log-commands no\n".
			"</source>\n";
		fwrite($fopen, $content);
		fclose($fopen);
	}
	exec('sudo /etc/init.d/pmta reload');
}
?>