function requestpassword($admin_name) { $cfg = EasySCP_Registry::get('Config'); $sql = EasySCP_Registry::get('Db'); $query = "\n\t\tSELECT\n\t\t\t`created_by`, `fname`, `lname`, `email`\n\t\tFROM\n\t\t\t`admin`\n\t\tWHERE\n\t\t\t`admin_name` = ?\n\t"; $res = exec_query($sql, $query, $admin_name); if ($res->recordCount() == 0) { return false; } $created_by = $res->fields['created_by']; $admin_fname = $res->fields['fname']; $admin_lname = $res->fields['lname']; $to = $res->fields['email']; $uniqkey = uniqkeygen(); setUniqKey($admin_name, $uniqkey); write_log("Lostpassword: "******": uniqkey created", E_USER_NOTICE); if ($created_by == 0) { $created_by = 1; } $data = get_lostpassword_activation_email($created_by); $from_name = $data['sender_name']; $from_email = $data['sender_email']; $subject = $data['subject']; $message = $data['message']; $base_vhost = $cfg->BASE_SERVER_VHOST; $base_vhost_prefix = $cfg->BASE_SERVER_VHOST_PREFIX; if ($from_name) { $from = '"' . $from_name . "\" <" . $from_email . ">"; } else { $from = $from_email; } $prot = isset($_SERVER['https']) ? 'https' : 'http'; $link = $prot . '://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] . '?key=' . $uniqkey; $search = array(); $replace = array(); $search[] = '{USERNAME}'; $replace[] = $admin_name; $search[] = '{NAME}'; $replace[] = $admin_fname . " " . $admin_lname; $search[] = '{LINK}'; $replace[] = $link; $search[] = '{BASE_SERVER_VHOST}'; $replace[] = $base_vhost; $search[] = '{BASE_SERVER_VHOST_PREFIX}'; $replace[] = $base_vhost_prefix; $subject = str_replace($search, $replace, $subject); $message = str_replace($search, $replace, $message); $headers = 'From: ' . $from . "\n"; $headers .= "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n"; $headers .= 'X-Mailer: EasySCP lostpassword mailer'; $mail_result = mail($to, mb_encode_mimeheader($subject, 'UTF-8'), $message, $headers); $mail_status = $mail_result ? 'OK' : 'NOT OK'; $from = tohtml($from); write_log("Lostpassword send: To: |{$to}|, From: |{$from}|, Status: |{$mail_status}| !", E_USER_NOTICE); return true; }
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @link http://www.easyscp.net * @author EasySCP Team */ require '../../include/easyscp-lib.php'; check_login(__FILE__); $cfg = EasySCP_Registry::get('Config'); $tpl = EasySCP_TemplateEngine::getInstance(); $template = 'admin/settings_lostpassword.tpl'; $user_id = $_SESSION['user_id']; $selected_on = ''; $selected_off = ''; $data_1 = get_lostpassword_activation_email($user_id); $data_2 = get_lostpassword_password_email($user_id); if (isset($_POST['uaction']) && $_POST['uaction'] == 'apply') { $err_message = ''; $data_1['subject'] = clean_input($_POST['subject1'], false); $data_1['message'] = clean_input($_POST['message1'], false); $data_2['subject'] = clean_input($_POST['subject2'], false); $data_2['message'] = clean_input($_POST['message2'], false); if (empty($data_1['subject']) || empty($data_2['subject'])) { $err_message = tr('Please specify a subject!'); } if (empty($data_1['message']) || empty($data_2['message'])) { $err_message = tr('Please specify message!'); } if (!empty($err_message)) { set_page_message($err_message, 'warning');
/** * Request password * * @param string $adminName * @return bool TRUE on success, FALSE otherwise */ function requestPassword($adminName) { /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); $stmt = exec_query('SELECT `created_by`, `fname`, `lname`, `email` FROM `admin` WHERE `admin_name` = ?', $adminName); if (!$stmt->rowCount()) { return false; } $createdBy = $stmt->fields['created_by']; $adminFirstName = $stmt->fields['fname']; $adminLastName = $stmt->fields['lname']; $to = $stmt->fields['email']; $uniqueKey = uniqkeygen(); setUniqKey($adminName, $uniqueKey); write_log('Lostpassword: '******': uniqkey created', E_USER_NOTICE); if ($createdBy == 0) { $createdBy = 1; } $data = get_lostpassword_activation_email($createdBy); $fromName = $data['sender_name']; $fromEmail = $data['sender_email']; $subject = $data['subject']; $message = $data['message']; $baseServerVhostPrefix = $cfg['BASE_SERVER_VHOST_PREFIX']; $baseServerVhost = $cfg['BASE_SERVER_VHOST']; $baseServerVhostPort = $baseServerVhostPrefix == 'http://' ? $cfg['BASE_SERVER_VHOST_HTTP_PORT'] : $cfg['BASE_SERVER_VHOST_HTTPS_PORT']; if ($fromName) { $from = encode_mime_header($fromName) . " <{$fromEmail}>"; } else { $from = $fromEmail; } $link = $baseServerVhostPrefix . $baseServerVhost . ':' . $baseServerVhostPort . $_SERVER["PHP_SELF"] . '?key=' . $uniqueKey; $search = array(); $replace = array(); $search[] = '{USERNAME}'; $replace[] = $adminName; $search[] = '{NAME}'; $replace[] = "{$adminFirstName} {$adminLastName}"; $search[] = '{LINK}'; $replace[] = $link; $search[] = '{BASE_SERVER_VHOST_PREFIX}'; $replace[] = $baseServerVhostPrefix; $search[] = '{BASE_SERVER_VHOST}'; $replace[] = $baseServerVhost; $search[] = '{BASE_SERVER_VHOST_PORT}'; $replace[] = $baseServerVhostPort; $subject = str_replace($search, $replace, $subject); $message = str_replace($search, $replace, $message); $headers = "From: {$from}\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/plain; charset=utf-8\r\n"; $headers .= "Content-Transfer-Encoding: 8bit\r\n"; $headers .= 'X-Mailer: i-MSCP Mailer'; $mailResult = mail($to, encode_mime_header($subject), $message, $headers, "-f {$fromEmail}"); $mailStatus = $mailResult ? 'OK' : 'NOT OK'; $from = tohtml($from); write_log("Lostpassword send: To: |{$to}|, From: |{$from}|, Status: |{$mailStatus}| !", E_USER_NOTICE); return true; }