<div id="primary_header">
  <h1><?php print $this->translate('SMTP Settings')?></h1>

</div>

<div id="primary_content">
  <div id="primary_content_inner">
  <div id="Flash" class="flash_notice"><?php print $this->translate('The settings have been updated') ?></div>
	
  <form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/services/smtpsave">

    <input type="hidden" name="save" value="1" />
	<!-- Specify default settings not available to edit -->
	<input name="fields[tlssmtp_remote]" type="hidden" id="tlssmtp_remote" value="1">
	<input name="fields[split_spool_directory]" type="hidden" id="split_spool_directory" value="1">
	<input name="fields[queue_run_in_order]" type="hidden" id="queue_run_in_order" value="0">

	<table class="settings">
	
		<tr>
			<td class="label"><?php print $this->translate('Enable SMTP Auth')?></td>
			<td>
				<input name="fields[smtp_auth]" type='hidden' value='0'/>
				<input name="fields[smtp_auth]" type="checkbox" class="iphoneStyle" id="smtp_auth" value="1" <?php echo ($this->exim['smtp_auth']) ? 'checked' : '' ?> />
				<small><?php print $this->translate('Allow SMTP Authentication. This allows users to relay messages via the SMTP server via authentication in their mail-client. Users must successfully authenticate against the SMTP server to send outgoing messages')?></small>
			</td>
		</tr>

		<tr>
			<td class="label"><?php print $this->translate('Enable SMTP TLS')?></td>
			<td>
				<input name="fields[tlssmtp]" type='hidden' value='0'/>
				<input name="fields[tlssmtp]" type="checkbox" class="iphoneStyle" id="tlssmtp" value="1" <?php echo ($this->exim['tlssmtp']) ? 'checked' : '' ?> />
				<small><?php print $this->translate('SMTP TLS allows users to connect to your SMTP server using TLS/SSL. They can then choose to send emails securely over the internet.')?></small>
			</td>
		</tr>

		<tr>
			<td class="label"><?php print $this->translate('Enable Email Filters')?></td>
        	<td>
				<input name="fields[enableMailFilters]" type='hidden' value='0'/>
				<input name="fields[enableMailFilters]" type="checkbox" class="iphoneStyle" id="enableMailFilters" value="1" <?php echo ($this->exim['enableMailFilters']) ? 'checked' : '' ?>>
				<small><?php print $this->translate('Enable Sieve Email filter support for end users. Users can define filters via the Webmail interface to divert messages to folders at SMTP delivery.')?></small>
			</td>
		</tr>

	</table>

	<div class="divider"></div>

	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('IMAP/POP before SMTP')?></td>
        <td>
			<input name="fields[smtp_popimaprelay]" type='hidden' value='0'/>
			<input name="fields[smtp_popimaprelay]" type="checkbox" class="iphoneStyle" id="smtp_popimaprelay" value="1" <?php echo ($this->exim['smtp_popimaprelay']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('Allow "IMAP/POP" before Relay. This option will append the users IP address to the Mail-relay database if their mail-client authenticates to the mail-server. This option will allow your users to send messages via the SMTP server.')?></small></td>
      </tr>

      <tr id="relayTimeout">
        <td class='label'><label class='settings_label'><?php print $this->translate('IMAP/POP relay timeout')?></label></td>
        <td>
			<input type="text" name="fields[smtp_popimaprelay_timeout]" id="smtp_popimaprelay_timeout" value="<?php echo $this->exim['smtp_popimaprelay_timeout'] ?>" size="4" />
			<small><?php print $this->translate('Specify the number of minutes a users IP session is permitted to relay until they must authenticate again.')?></small></td>
      </tr>

	</table>

	<div class="divider"></div>

	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Verify Senders')?></td>
        <td>
			<input name="fields[smtp_verify_senders]" type='hidden' value='0'/>
			<input name="fields[smtp_verify_senders]" type="checkbox" class="iphoneStyle" id="smtp_verify_senders" value="1" <?php echo ($this->exim['smtp_verify_senders']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('When a message is delivered to the local system, verify the remote user account has a valid domain/MX record. Useful to prevent unauthorized  messages from reaching the SMTP server.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Throttle Mail Recipients')?></td>
        <td>
			<input name="fields[smtp_throttle]" type='hidden' value='0'/>
			<input name="fields[smtp_throttle]" type="checkbox" class="iphoneStyle" id="smtp_throttle" value="1" <?php echo ($this->exim['smtp_throttle']) ? 'checked' : '' ?>>
			<small><?php print $this->translate('If a SMTP session is attempting to deliver a message to a large amount of recipients, automatically throttle the connection speed to avoid Spammers and abuse of the SMTP service.')?></small></td>
      </tr>

	</table>

	<div class="divider"></div>

	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Max Connections')?></td>
        <td>
			<input type="text" class="small" name="fields[smtp_max_connections]" id="smtp_max_connections" value="<?php echo $this->exim['smtp_max_connections'] ?>" />
			<small><?php print $this->translate('Specify the maximum number of concurrent SMTP connections to the server. This value is used to prevent any denial of service-attacks, or to throttle the load on a busy system.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Max Connections per IP')?></td>
        <td>
			<input type="text" class="small" name="fields[smtp_max_connections_perip]" id="smtp_max_connections_perip" value="<?php echo $this->exim['smtp_max_connections_perip'] ?>" />
			<small><?php print $this->translate('Specify the maximum number of connections per IP to the SMTP server. Useful to throttle load and avoid a set of IPs to consume all available connections.')?></small></td>
      </tr>

  </table>









	<table class="settings">
		<tbody>
			<tr>
				<td class="label"><?php print $this->translate('Limit Recipients')?></td>
				<td>
					<input name="fields[smtp_sendlimit_enable]" type='hidden' value='0'/>
					<input name="fields[smtp_sendlimit_enable]" type="checkbox" class="iphoneStyle" id="smtp_sendlimit_enable" value="1" <?php echo ($this->exim['smtp_sendlimit_enable']) ? 'checked' : '' ?>>
					<small><?php print $this->translate('Allow limiting of emails a local user can send per hour.')?></small>
				</td>
			</tr>
			<tr>
				<td class="label"><label class='settings_label'><?php print $this->translate('Max Recipients per Account/Hour')?></label></td>
				<td>
					<input type="text" class="small" name="fields[smtp_sendlimit]" id="smtp_sendlimit" value="<?php echo $this->exim['smtp_sendlimit'] ?>" />
					<small><?php print $this->translate('Specify the maximum amount of emails a local user can send per hour. Avoid abuse from end users which SMTP-authentication or IP relay from your server.')?></small>
				</td>
			</tr>
		</tbody>
	</table>


    <table class="settings">

	  <tr>
        <td class="label"><?php print $this->translate('Max recipients per SMTP session')?></td>
        <td>
			<input type="text" name="fields[smtp_max_rcpt]" class="small" id="smtp_max_rcpt" value="<?php echo $this->exim['smtp_max_rcpt'] ?>" />
			<small><?php print $this->translate('Specify the maximum number of recipients an SMTP connection can deliver messages to. This can be used to prevent unauthorized users from Spamming users on the SMTP server')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Load Reserve')?></td>
        <td>
			<input type="text" name="fields[smtp_load_reserve]" class="small" id="smtp_load_reserve" value="<?php echo $this->exim['smtp_load_reserve'] ?>" />
			<small><?php print $this->translate('If the load-averages on the server reach the specified value, incoming SMTP sessions are rejected. This is used to prevent from server from overloading due to high usage')?></small></td>
      </tr>

    </table>

<?php if($this->exim['dkim_installed']) :?>
	<div class="divider"></div>

	<table class="settings">
		<tbody>
			<!--
			<tr>
				<td class="label"><?php print $this->translate('Enable DKIM Checks')?></td>
				<td>
					<input name="fields[dkim_enable]" type='hidden' value='0'/>
					<input name="fields[dkim_enable]" type="checkbox" class="iphoneStyle" id="dkim_enable" value="1" <?php echo ($this->exim['dkim_enable']) ? 'checked' : '' ?>>

					<small><?php print $this->translate('Enable DKIM checking - this verifies emails from hosts that have DKIM signatures enabled. If messages appear to come from a DKIM-enabled domain, and do not have the signature, they are deferred.')?></small>
				</td>
			</tr>
			-->
			<input name="fields[dkim_enable]" type='hidden' value='0'/>

			<tr>
				<td class="label"><?php print $this->translate('Enable DKIM Outbound')?></td>
				<td>
					<input name="fields[dkim_enable_outbound]" type='hidden' value='0'/>
					<input name="fields[dkim_enable_outbound]" type="checkbox" class="iphoneStyle" id="dkim_enable_outbound" value="1" <?php echo ($this->exim['dkim_enable_outbound']) ? 'checked' : '' ?>>
			
					<small><?php print $this->translate('Enable DKIM signatures - this adds a verification signature on top of all emails sent from your server. This may help in cases where your emails are getting flagged as Spam by other hosts.')?></small>
				</td>
			</tr>
		
			<tr>
			 <td class="label"><label class='settings_label'>DKIM Signature</label></td>
			 <td>
				<textarea id='dkim_message'><?php echo $this->exim['dkim_message']; ?></textarea>
			 <small><?php print $this->translate('Append this line to your DNS records. This adds the entry that verifies that your domain has DKIM enabled.')?></small>
			 </td>
			</tr>
		
			<tr>
				<td class="label"><label class='settings_label'><?php print $this->translate('DKIM Domain')?></label></td>
				<td>
					<input type="text" name="fields[dkim_domain]" id="dkim_domain" value="<?php echo $this->exim['dkim_domain'] ?>" />
					<small><?php print $this->translate('Specify the domain to add a DKIM signature for.')?></small>
				</td>
			</tr>
		</tbody>
	</table>
<?php endif ?>

	<div class="divider"></div>
	
	<table class="settings">
      <tr>
        <td class="label"><?php print $this->translate('Queue Load')?></td>
        <td>			
			<input type="text" name="fields[smtp_load_queue]" class="small" id="smtp_load_queue" value="<?php echo $this->exim['smtp_load_queue'] ?>" />
			<small><?php print $this->translate('If the load-averages reach the specified value, messages are automatically placed in the queue for mail-delivery. Used to throttle the SMTP server from high-loads.')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Queue Delivery Load')?></td>
        <td>
			<input type="text" name="fields[smtp_load_queue_delivery]" class="small" id="smtp_load_queue_delivery" value="<?php echo $this->exim['smtp_load_queue_delivery'] ?>" />
			<small><?php print $this->translate('If the load-averages reach the specified value, messages in the queue will not be processed')?></small></td>
      </tr>

      <tr>
        <td class="label"><?php print $this->translate('Remote Parallel processes')?></td>
        <td>
			<input type="text" name="fields[remote_max_parallel]" class="small" id="remote_max_parallel" value="<?php echo $this->exim['remote_max_parallel'] ?>" />
			<small><?php print $this->translate('Maximum Parallel queue processes - This setting forces outbound messages to only be delivered to the specified number of destinations simultaneously.')?></small></td>
      </tr>

    </table>

  </div>
  </form>
	<div id="back_button">
		<a href="#"><span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span></a>
	</div>
</div>

<script type="text/javascript">
$( function()
{
	var tabId = "#SMTP";
	$('#settingsForm', tabId).submit(function()
	{
	    <?php if( file_exists("/usr/local/atmail/mailserver/bin/atmail-services-restart") ) //is appliance
    		echo '$.simpleFlash( "' . addslashes($this->translate('Saving, please wait while appliance services are restarted.')) . '", "important");';
    	?>
		return false;
	});

	function editsendlimit()
	{
		if($("#smtp_sendlimit_enable", tabId).attr('checked') == true)
		{
			$("#sendLimit", tabId).fadeTo("slow", 1);
			$("#smtp_sendlimit", tabId).removeAttr("disabled");
		}
		else
		{
			$("#sendLimit", tabId).fadeTo("fast", 0.5);
			$("#smtp_sendlimit", tabId).attr("disabled","disabled");
		}
	}

	function editsmarthost()
	{
		if($("#smtp_popimaprelay", tabId).attr('checked') == true)
		{
			$("#relayTimeout", tabId).fadeTo("slow", 1);
			$("#smtp_popimaprelay_timeout", tabId).removeAttr("disabled");
		}
		else
		{
			$("#relayTimeout", tabId).fadeTo("fast", 0.5);
			$("#smtp_popimaprelay_timeout", tabId).attr("disabled","disabled");
		}
	}
	$("#smtp_popimaprelay_timeout", tabId).numeric();
	$("#smtp_max_connections", tabId).numeric();
	$("#smtp_max_rcpt", tabId).numeric();
	$("#smtp_load_reserve", tabId).numeric();
	$("#smtp_load_queue", tabId).numeric();
	$("#smtp_load_queue_delivery", tabId).numeric();
	$("#remote_max_parallel", tabId).numeric();

	$("#smtp_sendlimit_enable", tabId).bind('click', function() { editsendlimit(); });

	$("#smtp_popimaprelay", tabId).change( function() { enableSettingsBox($("#smtp_popimaprelay", tabId)); });
	enableSettingsBox($("#smtp_popimaprelay", tabId));
	editsendlimit();

	$("#dkim_enable_outbound", tabId).change( function() { enableSettingsBox($("#dkim_enable_outbound", tabId)); });
	enableSettingsBox($("#dkim_enable_outbound", tabId));
	$("#smtp_sendlimit_enable", tabId).change( function() { enableSettingsBox($("#smtp_sendlimit_enable", tabId)); });
	enableSettingsBox($("#smtp_sendlimit_enable", tabId));
	perform_service_common_binds(tabId);

});

</script>