Project

General

Profile

« Previous | Next » 

Revision 1cddd59c

Added by Warren Baker almost 12 years ago

Split SSL/TLS into separate checkboxes so that plaintext connections can be made secured by using STARTTLS. Support for SMTPS connections should probably be done away with in future. Fixes #3180

View differences:

etc/inc/notices.inc
310 310

  
311 311
	$smtp->direct_delivery = 0;
312 312
	$smtp->ssl = ($config['notifications']['smtp']['ssl'] == "checked") ? 1 : 0;
313
	$smtp->tls = ($config['notifications']['smtp']['tls'] == "checked") ? 1 : 0;
313 314
	$smtp->debug = 0;
314 315
	$smtp->html_debug = 0;
315 316
	$smtp->localhost=$config['system']['hostname'].".".$config['system']['domain'];
etc/inc/smtp.inc
20 20
	var $host_name="";
21 21
	var $host_port=25;
22 22
	var $ssl=0;
23
	var $tls=0;
23 24
	var $localhost="";
24 25
	var $timeout=0;
25 26
	var $data_timeout=0;
......
213 214

  
214 215
	Function ConnectToHost($domain, $port, $resolve_message)
215 216
	{
216
		if($this->ssl)
217
		if($this->ssl || $this->tls)
217 218
		{
218 219
			$version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7");
219 220
			$php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]);
......
461 462
			socket_set_timeout($this->connection,$timeout,0);
462 463
		if($this->debug)
463 464
			$this->OutputDebug(sprintf(gettext("Connected to SMTP server \"%s\"."), $domain));
464
		if(!strcmp($localhost=$this->localhost,"")
465
		&& !strcmp($localhost=getenv("SERVER_NAME"),"")
466
		&& !strcmp($localhost=getenv("HOST"),"")
467
		&& !strcmp($localhost=getenv("HOSTNAME"),"")
468
		&& !strcmp($localhost=exec("/bin/hostname"),""))
469
			$localhost="localhost";
470
		$success=0;
471 465
		if($this->VerifyResultLines("220",$responses)>0)
472 466
		{
473
			$fallback=1;
474
			if($this->esmtp
475
			|| strlen($this->user))
476
			{
477
				if($this->PutLine("EHLO $localhost"))
478
				{
479
					if(($success_code=$this->VerifyResultLines("250",$responses))>0)
480
					{
481
						$this->esmtp_host=$this->Tokenize($responses[0]," ");
482
						for($response=1;$response<count($responses);$response++)
483
						{
484
							$extension=strtoupper($this->Tokenize($responses[$response]," "));
485
							$this->esmtp_extensions[$extension]=$this->Tokenize("");
486
						}
487
						$success=1;
488
						$fallback=0;
489
					}
490
					else
491
					{
492
						if($success_code==0)
493
						{
494
							$code=$this->Tokenize($this->error," -");
495
							switch($code)
496
							{
497
								case "421":
498
									$fallback=0;
499
									break;
500
							}
501
						}
502
					}
503
				}
504
				else
505
					$fallback=0;
506
			}
507
			if($fallback)
508
			{
509
				if($this->PutLine("HELO $localhost")
510
				&& $this->VerifyResultLines("250",$responses)>0)
511
					$success=1;
512
			}
467
			// Send our HELLO
468
			$success = $this->hello($this->hostname());
469
			if ($this->tls)
470
				$success = $this->startTLS();
471

  
513 472
			if($success
514 473
			&& strlen($this->user)
515 474
			&& strlen($this->pop3_auth_host)==0)
516 475
			{
517 476
				if(!IsSet($this->esmtp_extensions["AUTH"]))
518 477
				{
519
					$this->error=gettext("server does not require authentication");
478
					$this->error = gettext("server does not require authentication");
520 479
					$success=0;
521 480
				}
522 481
				else
......
599 558
		return($success);
600 559
	}
601 560

  
561
	Function hostname() {
562
		if(!strcmp($localhost=$this->localhost,"")
563
		&& !strcmp($localhost=getenv("SERVER_NAME"),"")
564
		&& !strcmp($localhost=getenv("HOST"),"")
565
		&& !strcmp($localhost=getenv("HOSTNAME"),"")
566
		&& !strcmp($localhost=exec("/bin/hostname"),""))
567
			$localhost="localhost";
568

  
569
		return $localhost;
570
	}
571

  
572
	Function hello()
573
	{
574
		$success = 0;
575
		$fallback = 1;
576
		if ($this->esmtp || strlen($this->user)) {
577
			if ($this->PutLine("EHLO ".$this->hostname())) {
578
				if (($success_code = $this->VerifyResultLines("250",$responses)) > 0) {
579
					$this->esmtp_host = $this->Tokenize($responses[0]," ");
580
					for($response=1;$response<count($responses);$response++) {
581
						$extension = strtoupper($this->Tokenize($responses[$response]," "));
582
						$this->esmtp_extensions[$extension]=$this->Tokenize("");
583
					}
584
					$success = 1;
585
					$fallback = 0;
586
				} else {
587
					if ($success_code == 0) {
588
						$code = $this->Tokenize($this->error," -");
589
						switch($code) {
590
							case "421":
591
								$fallback=0;
592
								break;
593
						}
594
					}
595
				}
596
			} else
597
				$fallback=0;
598
		}
599

  
600
		if ($fallback) {
601
			if ($this->PutLine("HELO $localhost") && $this->VerifyResultLines("250",$responses)>0)
602
				$success=1;
603
		}
604
		return $success;
605
	}
606

  
607
	Function startTLS() {
608
		if ($this->PutLine("STARTTLS") && $this->VerifyResultLines("220",$responses)>0) {
609
			if (!stream_socket_enable_crypto($this->connection,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
610
				return false;
611
			} else {
612
				// Resend HELO since session has been reset
613
				return $this->hello($this->hostname);
614
			}
615
		} else
616
			return false;
617
	}
618

  
602 619
	Function MailFrom($sender)
603 620
	{
604 621
		if($this->direct_delivery)
usr/local/www/system_advanced_notifications.php
66 66
	$pconfig['smtpport'] = $config['notifications']['smtp']['port'];
67 67
if($config['notifications']['smtp']['ssl'])
68 68
	$pconfig['smtpssl'] = $config['notifications']['smtp']['ssl'];
69
if($config['notifications']['smtp']['tls'])
70
	$pconfig['smtptls'] = $config['notifications']['smtp']['tls'];
69 71
if($config['notifications']['smtp']['notifyemailaddress']) 
70 72
	$pconfig['smtpnotifyemailaddress'] = $config['notifications']['smtp']['notifyemailaddress'];
71 73
if($config['notifications']['smtp']['username']) 
......
113 115
		$config['notifications']['smtp']['ipaddress'] = $_POST['smtpipaddress'];
114 116
		$config['notifications']['smtp']['port'] = $_POST['smtpport'];
115 117
		$config['notifications']['smtp']['ssl'] = isset($_POST['smtpssl']) ? 'checked' : 'unchecked';
118
		$config['notifications']['smtp']['tls'] = isset($_POST['smtptls']) ? (isset($_POST['smtpssl']) ? 'unchecked' : 'checked') : 'unchecked';
116 119
		$config['notifications']['smtp']['notifyemailaddress'] = $_POST['smtpnotifyemailaddress'];
117 120
		$config['notifications']['smtp']['username'] = $_POST['smtpusername'];
118 121
		$config['notifications']['smtp']['password'] = $_POST['smtppassword'];
......
258 261
						<tr>
259 262
							<td width="22%" valign="top" class="vncell"><?=gettext("SMTP Port of E-Mail server"); ?></td>
260 263
							<td width="78%" class="vtable">
261
								<input name='smtpport' value='<?php echo $pconfig['smtpport']; ?>' />
262
								<input type='checkbox' name='smtpssl' <?php echo $pconfig['smtpssl']; ?> />Enable SSL/TLS Authentication<br/>
263
								<?=gettext("This is the port of the SMTP E-Mail server, typically 25, 587 (submission) or 465 (smtps, tick ssl/tls checkbox)"); ?>
264
								<input name='smtpport' value='<?php echo $pconfig['smtpport']; ?>' /><br/>
265
								<?=gettext("This is the port of the SMTP E-Mail server, typically 25, 587 (submission) or 465 (smtps)"); ?>
266
							</td>
267
						</tr>
268
						<tr>
269
							<td width="22%" valign="top" class="vncell"><?=gettext("Secure SMTP Connection"); ?></td>
270
							<td width="78%" class="vtable">
271
								<input type='checkbox' id='smtpssl' name='smtpssl' <?php echo $pconfig['smtpssl']; ?> />Enable SMTP over SSL/TLS<br/>
272
								<input type='checkbox' id='smtptls' name='smtptls' <?php echo $pconfig['smtptls']; ?> />Enable STARTTLS<br/>
264 273
							</td>
265 274
						</tr>
266 275
						<tr>
......
333 342
			</td>
334 343
		</tr>
335 344
	</table>
345
<script type="text/javascript">
346
	jQuery(document).ready(function() {
347
		if (jQuery('#smtpssl').is(':checked')) {
348
			jQuery('#smtptls').prop('disabled', true);
349
		} else if  (jQuery('#smtptls').is(':checked')) {
350
			jQuery('#smtpssl').prop('disabled', true);
351
		}
352
	});
353
	jQuery('#smtpssl').change( function() {
354
		jQuery('#smtptls').prop('disabled', this.checked);
355
	});
356
	jQuery('#smtptls').change( function() {
357
		jQuery('#smtpssl').prop('disabled', this.checked);
358
	});
359
</script>
336 360
<?php include("fend.inc"); ?>
337 361
</body>
338 362
</html>

Also available in: Unified diff