Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.14 KB | None | 0 0
  1. <?
  2.  
  3.     # ----------------------------------------------------------------------------------------------------
  4.     # * FILE: /sitemgr/prefs/emailconfig.php
  5.     # ----------------------------------------------------------------------------------------------------
  6.  
  7.     # ----------------------------------------------------------------------------------------------------
  8.     # LOAD CONFIG
  9.     # ----------------------------------------------------------------------------------------------------
  10.     include("../../conf/loadconfig.inc.php");
  11.  
  12.     # ----------------------------------------------------------------------------------------------------
  13.     # SESSION
  14.     # ----------------------------------------------------------------------------------------------------
  15.     sess_validateSMSession();
  16.     permission_hasSMPerm();
  17.  
  18.     # ----------------------------------------------------------------------------------------------------
  19.     # SUBMIT
  20.     # ----------------------------------------------------------------------------------------------------
  21.     extract($_POST);
  22.     extract($_GET);
  23.  
  24.     //increases frequently actions
  25.     if (!isset($emailconf_host)); system_setFreqActions('prefs_emailsendconf','prefsemail');
  26.  
  27.     if ($ajaxVerify == 1) {
  28.         $json = new Services_JSON();
  29.  
  30.         $return_json = array();
  31.  
  32.         $str_server = ($emailconf_protocol ? $emailconf_protocol.'://' : '').$emailconf_host;
  33.        
  34.         //Getting tbe language for phpmailing
  35.         $edirmailer = new EDirMailer();
  36.         $lang = $edirmailer->getLang();
  37.        
  38.         $mail = new PHPMailer();
  39.         $mail->SetLanguage($lang, CLASSES_DIR.'/phpmailer/language/');
  40.         $mail->IsHTML(false);
  41.         $mail->Mailer = "smtp";
  42.         $mail->Port   = $emailconf_port;
  43.         $mail->Host   = $str_server;
  44.         if ($emailconf_auth == 'normal' || $emailconf_auth == 'secure') {
  45.             $mail->SMTPAuth = true;
  46.             $mail->Username = trim($emailconf_username);
  47.             $mail->Password = trim($emailconf_password);
  48.         } else {
  49.             $mail->SMTPAuth = false;
  50.         }
  51.         $mail->From    = trim($emailconf_email);
  52.         $mail->Subject = EDIRECTORY_TITLE." - Config SMTP Email";
  53.         $mail->Body    = EDIRECTORY_TITLE." - Config SMTP Email";
  54.         $mail->AddAddress(trim($emailconf_email));
  55.  
  56.         if ($mail->Send()) {
  57.             $return_json['status'] = 'success';
  58.         } else {
  59.             $return_json['status'] = 'failed';
  60.             $return_json['msg_error'] = $mail->ErrorInfo;
  61.             if ($mail->smtp->error['error']) {
  62.                 $return_json['msg_error'] .= ' ('.$mail->smtp->error['error'].')';
  63.             }
  64.         }
  65.  
  66.         die($json->encode($return_json));
  67.  
  68.     }
  69.  
  70.     // Default CSS class for message
  71.     $message_style = "errorMessage";
  72.  
  73.     if ($_SERVER['REQUEST_METHOD'] == "POST") {
  74.  
  75.         $error = false;
  76.  
  77.         $emailconf_method = str_replace(" ", "", $emailconf_method);
  78.         if (!setting_set("emailconf_method", $emailconf_method)) {
  79.             if (!setting_new("emailconf_method", $emailconf_method)) {
  80.                 $error = true;
  81.             }
  82.         }
  83.  
  84.         $emailconf_host = str_replace(" ", "", $emailconf_host);
  85.         if (!setting_set("emailconf_host", $emailconf_host)) {
  86.             if (!setting_new("emailconf_host", $emailconf_host)) {
  87.                 $error = true;
  88.             }
  89.         }
  90.  
  91.         $emailconf_port = str_replace(" ", "", $emailconf_port);
  92.         if (!setting_set("emailconf_port", $emailconf_port)) {
  93.             if (!setting_new("emailconf_port", $emailconf_port)) {
  94.                 $error = true;
  95.             }
  96.         }
  97.  
  98.         $emailconf_auth = str_replace(" ", "", $emailconf_auth);
  99.         if (!setting_set("emailconf_auth", $emailconf_auth)) {
  100.             if (!setting_new("emailconf_auth", $emailconf_auth)) {
  101.                 $error = true;
  102.             }
  103.         }
  104.  
  105.         $emailconf_email = str_replace(" ", "", $emailconf_email);
  106.         if (!setting_set("emailconf_email", $emailconf_email)) {
  107.             if (!setting_new("emailconf_email", $emailconf_email)) {
  108.                 $error = true;
  109.             }
  110.         }
  111.  
  112.         $emailconf_username = str_replace(" ", "", $emailconf_username);
  113.         if (!setting_set("emailconf_username", $emailconf_username)) {
  114.             if (!setting_new("emailconf_username", $emailconf_username)) {
  115.                 $error = true;
  116.             }
  117.         }
  118.  
  119.         if (isset($emailconf_password) && trim($emailconf_password) != "") {
  120.             $emailconf_password = crypt_encrypt(str_replace(" ", "", $emailconf_password));
  121.             if (!setting_set("emailconf_password", $emailconf_password)) {
  122.                 if (!setting_new("emailconf_password", $emailconf_password)) {
  123.                     $error = true;
  124.                 }
  125.             }  
  126.         }
  127.  
  128.         if (!$error) {
  129.             $actions[] = "&#149;&nbsp;".system_showText(LANG_SITEMGR_SETTINGS_YOURSETTINGSWERECHANGED);
  130.             $message_style = "successMessage";
  131.         } else {
  132.             $actions[] = "&#149;&nbsp;".system_showText(LANG_SITEMGR_MSGERROR_SYSTEMERROR);
  133.         }
  134.  
  135.         if($actions) {
  136.             $message_confemail .= implode("<br />", $actions);
  137.         }
  138.  
  139.     }
  140.  
  141.     # ----------------------------------------------------------------------------------------------------
  142.     # FORMS DEFINES
  143.     # ----------------------------------------------------------------------------------------------------
  144.     if (!$emailconf_method) setting_get("emailconf_method", $emailconf_method);
  145.     if (!$emailconf_host) setting_get("emailconf_host", $emailconf_host);
  146.     if (!$emailconf_port) setting_get("emailconf_port", $emailconf_port);
  147.     if (!$emailconf_auth) setting_get("emailconf_auth", $emailconf_auth);
  148.     if (!$emailconf_auth) $emailconf_auth = 'normal';
  149.     if (!$emailconf_email) setting_get("emailconf_email", $emailconf_email);
  150.     if (!$emailconf_username) setting_get("emailconf_username", $emailconf_username);
  151.     if (!$emailconf_password) setting_get("emailconf_password", $emailconf_password);
  152.  
  153.     # ----------------------------------------------------------------------------------------------------
  154.     # HEADER
  155.     # ----------------------------------------------------------------------------------------------------
  156.     include(SM_EDIRECTORY_ROOT."/layout/header.php");
  157.  
  158.     # ----------------------------------------------------------------------------------------------------
  159.     # NAVBAR
  160.     # ----------------------------------------------------------------------------------------------------
  161.     include(SM_EDIRECTORY_ROOT."/layout/navbar.php");
  162.  
  163. ?>
  164.  
  165.  
  166. <script type="text/javascript">
  167.     <!--
  168.     //top variables
  169.     html_testconn = "<a href=\"javascript:void(0)\" onclick=\"doVerifyConnect()\"><img src=\"<?=DEFAULT_URL.'/sitemgr/images/icon_connection.png'?>\" border=\"0\"> <?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_CLICKHERETOTEST)?></a> (<?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_PLEASEDOTHISBEFORESAVE)?>)";
  170.     html_animloading = "<img src=\"<?=DEFAULT_URL.'/sitemgr/images/anim_ajaxloading.gif'?>\" border=\"0\" align=\"absmiddle\" />";
  171.     radiovalues = {'normal':1,'secure':2,'noauth':3};
  172.     function initForm() {
  173.         switchAuth('<?=$emailconf_auth?>');
  174.         $('#response').html(html_testconn);
  175.     }
  176.     $("document").ready(initForm);
  177.     function changeMethod() {
  178.         if ($('#method').attr('value') == 'smtp') {
  179.             $('#form-smtp').css('display', '');
  180.             $("#bt_submit").attr('enabled', 'enabled');
  181.             $("#bt_submit").attr('class','input-button-form input-button-form-enabled');
  182.         } else {
  183.             $('#form-smtp').css('display', '');
  184.             $("#bt_submit").attr('enabled', '');
  185.             $("#bt_submit").attr('class','input-button-form');
  186.         }
  187.     }
  188.     function switchAuth(auth) {
  189.         array_default_ports = new Array('25', '465'); /* normal, secure (ssl/tls) */
  190.         $("#auth"+radiovalues[auth]).attr('checked', true);
  191.         if (auth == 'normal' || auth == 'secure') {
  192.             $('#username').attr('disabled', false);
  193.             $('#password').attr('disabled', false);
  194.             $('#username').attr('className', '');
  195.             $('#password').attr('className', '');
  196.         } else {
  197.             $('#username').attr('disabled', true);
  198.             $('#password').attr('disabled', true);
  199.             $('#username').attr('className', 'inputReadOnly');
  200.             $('#password').attr('className', 'inputReadOnly');
  201.         }
  202.         if (auth == 'secure') {
  203.             $('#port').attr('value', array_default_ports[1]);
  204.             $('#protocol').attr('value', 'ssl');
  205.         } else {
  206.             $('#port').attr('value', array_default_ports[0]);
  207.             $('#protocol').attr('value', '');
  208.         }
  209.     }
  210.     function isValidEmail (email_str) {
  211.         var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  212.         return emailPattern.test(email_str);
  213.     }
  214.     function emailChange(email) {
  215.         bufferHtml = "";
  216.         if (email != "") {
  217.             if (isValidEmail(email)) {
  218.                 bufferHtml = "<img src=\"<?=DEFAULT_URL.'/sitemgr/images/icon_accept.gif'?>\" border=\"0\" align=\"absmiddle\" />";
  219.             } else {
  220.                 bufferHtml = "<img src=\"<?=DEFAULT_URL.'/sitemgr/images/icon_reject.gif'?>\" border=\"0\" align=\"absmiddle\" />";
  221.             }
  222.         }
  223.         $('#email_status').html(bufferHtml);
  224.     }
  225.     function emailBlur(form) {
  226.         if (isValidEmail($('#email').attr('value')) && $('#username').attr('value') == "") {
  227.             if (!$('#username').attr('disabled')) $('#username').attr('value', $('#email').attr('value'));
  228.         }
  229.         emailChange($('#email').attr('value'));
  230.     }
  231.     function validateForm() {
  232.         if ($("#emailconf_method").attr("value") == 'smtp') {
  233.             if ($.trim($("#host").attr("value")) == "") {
  234.                 alert('<?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_MSGERROR_SERVERFIELD)?>');
  235.                 $("#host").focus();
  236.                 return false;
  237.             }
  238.             if ($.trim($("#port").attr("value")) == "") {
  239.                 alert('<?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_MSGERROR_PORTFIELD)?>');
  240.                 $("#port").focus();
  241.                 return false;
  242.             }
  243.             if ($.trim($("#email").attr("value")) == "") {
  244.                 alert('<?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_MSGERROR_EMAILFIELD)?>');
  245.                 $("#email").focus();
  246.                 return false;
  247.             }
  248.             if (!$('#auth3').attr("checked")) {
  249.                 if ($.trim($("#username").attr("value")) == "") {
  250.                     alert('<?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_MSGERROR_USERNAMEFIELD)?>');
  251.                     $("#username").focus();
  252.                     return false;
  253.                 }
  254.                 if ($.trim($("#password").attr("value")) == "") {
  255.                     alert('<?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_MSGERROR_PASSWORDFIELD)?>');
  256.                     $("#password").focus();
  257.                     return false;
  258.                 }
  259.             }
  260.         }
  261.         return true;
  262.     }
  263.     function doVerifyConnect() {
  264.         if (!validateForm()) return false;
  265.         $("#divSubmit").css('display', 'none');
  266.         $("#response").css('display', 'block');
  267.         $("#response").html(html_animloading);
  268.         $.getJSON('<?=$_SERVER['PHP_SELF']?>', $('#adminemail').serialize(), doVerifyConnect_onload);
  269.     }
  270.     function doVerifyConnect_onload(data, textStatus) {
  271.         $("#response").css('display', 'none');
  272.         if (textStatus == 'success') {
  273.             if (data.status == 'success') {
  274.                 $("#response").html('<p class="successMessage" style="margin-left:0px;"><?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_CONNECTEDSUCCESS)?></p>');
  275.                 $("#divSubmit").css('display', 'block');
  276.                 $("#bt_submit").attr('disabled', '');
  277.                 $("#bt_submit").attr('class','input-button-form');
  278.             } else {
  279.                 $("#response").html('<p class="errorMessage" style="margin-left:0px;"><?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_MSGERROR_ERRORWHILETESTCONNECTION)?><br />'+data.msg_error+'</p>');$("#divSubmit").css('display', 'none');
  280.                 $("#bt_submit").attr('disabled', 'disabled');
  281.                 $("#bt_submit").attr('class','input-button-form input-button-form-disabled');
  282.             }
  283.         }
  284.         $("#response").fadeIn('slow', function() {window.setTimeout(function() {$("#response").fadeOut('slow', function() { $('#response').html(html_testconn); $('#response').fadeIn('normal'); } );}, 2500)});
  285.     }
  286.     function submitForm() {
  287.         $("#ajaxVerify").attr('value', 0);
  288.         if (!validateForm()) return false;
  289.         return true;
  290.     }
  291.     -->
  292. </script>
  293.  
  294. <div id="main-right">
  295.  
  296.     <div id="top-content">
  297.         <div id="header-content">
  298.             <h1><?=system_showText(LANG_SITEMGR_SETTINGS_SITEMGRSETTINGS)?> - <?=system_showText(LANG_SITEMGR_SETTINGS_EMAILCONF_EMAILSENDINGCONFIGURATION)?></h1>
  299.         </div>
  300.     </div>
  301.  
  302.     <div id="content-content">
  303.         <div class="default-margin" style="padding-top:3px;">
  304.            
  305.             <br />
  306.  
  307.             <form name="adminemail" id="adminemail" action="<?=$_SERVER["PHP_SELF"]?>" method="post" onsubmit="return submitForm()">
  308.                 <? include(INCLUDES_DIR."/forms/form_adminemailconfig.php"); ?>
  309.                 <input type="hidden" name="ajaxVerify" id="ajaxVerify" value="1" />
  310.             </form>
  311.  
  312.         </div>
  313.     </div>
  314.  
  315.     <div id="bottom-content">
  316.         &nbsp;
  317.     </div>
  318.  
  319. </div>
  320.  
  321. <?
  322.     # ----------------------------------------------------------------------------------------------------
  323.     # FOOTER
  324.     # ----------------------------------------------------------------------------------------------------
  325.     include(SM_EDIRECTORY_ROOT."/layout/footer.php");
  326. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement