示例#1
0
 /**
  * Mail the user password reset link
  *
  * @since 1.0
  * @package facileManager
  *
  * @param string $fm_login Username to send the mail to
  * @param string $uniq_hash Unique password reset hash
  * @return boolean
  */
 function mailPwdResetLink($fm_login, $uniq_hash)
 {
     global $fm_name;
     $user_info = getUserInfo($fm_login);
     if (isEmailAddressValid($user_info['user_email']) === false) {
         return _('There is no valid e-mail address associated with this user.');
     }
     $phpmailer_file = ABSPATH . 'fm-modules' . DIRECTORY_SEPARATOR . $fm_name . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'class.phpmailer.php';
     if (!file_exists($phpmailer_file)) {
         return _('Unable to send email - PHPMailer class is missing.');
     } else {
         require $phpmailer_file;
     }
     $mail = new PHPMailer();
     /** Set PHPMailer options from database */
     $mail->Host = getOption('mail_smtp_host');
     $mail->SMTPAuth = getOption('mail_smtp_auth');
     if ($mail->SMTPAuth) {
         $mail->Username = getOption('mail_smtp_user');
         $mail->Password = getOption('mail_smtp_pass');
     }
     if (getOption('mail_smtp_tls')) {
         $mail->SMTPSecure = 'tls';
     }
     $mail->FromName = $fm_name;
     $mail->From = getOption('mail_from');
     $mail->AddAddress($user_info['user_email']);
     $mail->Subject = sprintf(_('%s Password Reset'), $fm_name);
     $mail->Body = $this->buildPwdResetEmail($user_info, $uniq_hash, true, $mail->Subject, $mail->From);
     $mail->AltBody = $this->buildPwdResetEmail($user_info, $uniq_hash, false);
     $mail->IsHTML(true);
     $mail->IsSMTP();
     if (!$mail->Send()) {
         return sprintf(_('Mailer Error: %s'), $mail->ErrorInfo);
     }
     return true;
 }
示例#2
0
 /**
  * Saves the options
  */
 function save()
 {
     global $fmdb, $__FM_CONFIG, $fm_name;
     if (!currentUserCan('manage_settings')) {
         return _('You do not have permission to make these changes.');
     }
     $force_logout = false;
     $exclude = array('save', 'item_type', 'gen_ssh');
     $ports = array('ldap_port', 'ldap_port_ssl', 'fm_port_ssl');
     $log_message = _('Set system settings to the following:') . "\n";
     foreach ($_POST as $key => $data) {
         if (!in_array($key, $exclude)) {
             unset($data_array);
             if (is_array($data)) {
                 $data_array = $data;
                 $account_id = $_SESSION['user']['account_id'];
                 $data = $data[$account_id];
             } else {
                 $account_id = 0;
             }
             /** Check if the option has changed */
             $current_value = getOption($key, $account_id);
             unset($account_id);
             if ($current_value == $data) {
                 continue;
             }
             if ($key == 'mail_from' && isEmailAddressValid($data) === false) {
                 return sprintf(_('%s is not a valid e-mail address.'), $data);
             }
             if (in_array($key, $ports)) {
                 if (!verifyNumber($data, 1, 65535, false)) {
                     return _('Invalid port number specified.');
                 }
             }
             if (isset($data_array)) {
                 $data = $data_array;
             }
             $new_array[$key] = $current_value === false ? array($data, 'insert') : array($data, 'update');
         }
     }
     if (isset($new_array) && is_array($new_array)) {
         foreach ($new_array as $option => $value) {
             list($option_value, $command) = $value;
             if (is_array($option_value)) {
                 $data_array = $option_value;
                 $account_id = $_SESSION['user']['account_id'];
                 $option_value = $option_value[$account_id];
             } else {
                 $account_id = 0;
             }
             /** Update with the new value */
             $result = setOption($option, $option_value, $command, false, $account_id);
             unset($account_id);
             if (!$result) {
                 return _('Could not save settings because a database error occurred.');
             }
             $log_value = trim($option_value);
             $log_message .= ucwords(str_replace('_', ' ', $option)) . ': ';
             if (@is_array($__FM_CONFIG['options'][$option][0])) {
                 foreach ($__FM_CONFIG['options'][$option] as $array) {
                     if ($log_value == $array[1]) {
                         $log_message .= $array[0];
                         break;
                     }
                 }
             } elseif ($option == 'mail_smtp_pass') {
                 $log_message .= str_repeat('*', 8);
             } elseif ($option == 'date_format' || $option == 'time_format') {
                 $log_message .= date($log_value);
             } elseif ($option == 'ldap_user_template') {
                 $log_message .= getNameFromID($log_value, 'fm_users', 'user_', 'user_id', 'user_login');
             } elseif ($option_value == '1') {
                 $log_message .= _('Yes');
             } elseif ($option_value == '0') {
                 $log_message .= _('No');
             } else {
                 $log_message .= $log_value;
             }
             $log_message .= "\n";
             if ($option == 'auth_method') {
                 $force_logout = true;
             }
             if (isset($data_array)) {
                 $data = $data_array;
                 unset($data_array);
             }
         }
         addLogEntry($log_message, $fm_name);
         if ($force_logout) {
             exit('force_logout');
         }
         return true;
     }
     return true;
 }