From: <abe...@us...> - 2012-01-30 19:15:08
|
Revision: 5428 http://astlinux.svn.sourceforge.net/astlinux/?rev=5428&view=rev Author: abelbeck Date: 2012-01-30 19:14:56 +0000 (Mon, 30 Jan 2012) Log Message: ----------- web interface, add support for testmail via testmail.php Network sub-tab Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/network.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/testmail.php Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2012-01-30 18:08:07 UTC (rev 5427) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2012-01-30 19:14:56 UTC (rev 5428) @@ -735,6 +735,10 @@ header('Location: /admin/edit.php?file='.$file); exit; } + } elseif (isset($_POST['submit_test_smtp'])) { + $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); + header('Location: /admin/testmail.php'); + exit; } elseif (isset($_POST['submit_dns_hosts'])) { $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); header('Location: /admin/dnshosts.php'); @@ -1260,6 +1264,9 @@ putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); putHtml('<strong>Outbound SMTP Mail Relay:</strong>'); + if (is_file('/usr/sbin/testmail')) { + putHtml(' <input type="submit" value="Test SMTP Mail Relay" name="submit_test_smtp" class="button" />'); + } putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="3">'); $value = getVARdef($db, 'SMTP_SERVER', $cur_db); Added: branches/1.0/package/webinterface/altweb/admin/testmail.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/testmail.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/testmail.php 2012-01-30 19:14:56 UTC (rev 5428) @@ -0,0 +1,151 @@ +<?php + +// Copyright (C) 2008-2012 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// testmail.php for AstLinux +// 01-30-2012 +// +// System location of gui.network.conf file +$NETCONFFILE = '/mnt/kd/rc.conf.d/gui.network.conf'; + +$myself = $_SERVER['PHP_SELF']; + +require_once '../common/functions.php'; + +// Function: putACTIONresult +// +function putACTIONresult($result_str, $status) { + global $myself; + + if ($status == 0) { + $result = 100; + } else { + $result = 101; + } + if ($result == 100) { + $result_str = 'Test Email has been successfully sent.'; + } elseif ($result_str === '') { + $result_str = 'Error'; + } + header('Location: '.$myself.'?result_str='.rawurlencode($result_str).'&result='.$result); +} + +// Function: getACTIONresult +// +function getACTIONresult($result) { + $str = 'No Action.'; + + if (isset($_GET['result_str'])) { + $str = stripslashes(rawurldecode($_GET['result_str'])); + } + if ($result == 100) { + $color = 'green'; + } else { + $color = 'red'; + } + return('<p style="color: '.$color.';">'.$str.'</p>'); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $result = 1; + if (! $global_admin) { + $result = 999; + } elseif (isset($_POST['submit_send_email'])) { + $to = trim($_POST['to_email']); + $from = trim($_POST['from_email']); + if ($to !== '') { + // Sanitize to and from + if (preg_match('/^[a-zA-Z0-9._@-]*$/', $to) && preg_match('/^[a-zA-Z0-9._@-]*$/', $from)) { + $result = restartPROCESS('msmtp', 10, 99, 'init'); + if ($result == 10) { + @exec('cd /root;/usr/sbin/testmail "'.$to.'" "'.$from.'" 2>&1', $result_array, $status); + $result_str = ''; + foreach ($result_array as $value) { + $result_str .= $value.' '; + } + putACTIONresult(trim($result_str), $status); + exit; + } + } else { + $result = 106; + } + } else { + $result = 105; + } + } + header('Location: '.$myself.'?result='.$result); + exit; +} else { // Start of HTTP GET +$ACCESS_RIGHTS = 'admin'; +require_once '../common/header.php'; + + if (is_file($NETCONFFILE)) { + $db = parseRCconf($NETCONFFILE); + if (($to_email = getVARdef($db, 'SAFE_ASTERISK_NOTIFY')) === '') { + $to_email = getVARdef($db, 'UPS_NOTIFY'); + } + if (($from_email = getVARdef($db, 'SAFE_ASTERISK_NOTIFY_FROM')) === '') { + $from_email = getVARdef($db, 'UPS_NOTIFY_FROM'); + } + } else { + $to_email = ''; + $from_email = ''; + } + + putHtml('<center>'); + if (isset($_GET['result'])) { + $result = $_GET['result']; + if ($result == 0) { + putHtml('<p style="color: green;">Action Successful.</p>'); + } elseif ($result == 99) { + putHtml('<p style="color: red;">Action Failed.</p>'); + } elseif ($result == 100 || $result == 101) { + putHtml(getACTIONresult($result)); + } elseif ($result == 105) { + putHtml('<p style="color: red;">To Email Address is missing.</p>'); + } elseif ($result == 106) { + putHtml('<p style="color: red;">Invalid Email Address.</p>'); + } elseif ($result == 999) { + putHtml('<p style="color: red;">Permission denied for user "'.$global_user.'".</p>'); + } else { + putHtml('<p> </p>'); + } + } else { + putHtml('<p> </p>'); + } + putHtml('</center>'); +?> + <center> + <table class="layout"><tr><td><center> + <form method="post" action="<?php echo $myself;?>"> + <table width="100%" class="stdtable"> + <tr><td style="text-align: center;" colspan="3"> + <h2>Test SMTP Mail Relay:</h2> + </td></tr> + </table> +<?php + putHtml('<table class="stdtable">'); + putHtml('<tr><td class="dialogText" style="text-align: right;">'); + putHtml('To Email <i>(Required)</i>:<input type="text" size="42" maxlength="128" name="to_email" value="'.$to_email.'" />'); + putHtml('</td></tr>'); + putHtml('<tr><td class="dialogText" style="text-align: right;">'); + putHtml('From Email <i>(Optional)</i>:<input type="text" size="42" maxlength="128" name="from_email" value="'.$from_email.'" />'); + putHtml('</td></tr>'); + + putHtml('<tr><td class="dialogText" style="text-align: center;">'); + putHtml('<br />'); + putHtml('<input type="submit" value="Send Test Email" name="submit_send_email" />'); + putHtml('</td></tr>'); + putHtml('</table>'); + + putHtml("</form>"); + putHtml("</center></td></tr></table>"); + putHtml("</center>"); +} // End of HTTP GET +require_once '../common/footer.php'; + +?> Property changes on: branches/1.0/package/webinterface/altweb/admin/testmail.php ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |