1: <?php
2:
3: /**
4: * @package modules
5: * @subpackage recover_settings
6: */
7:
8: if (!defined('DEBUG_MODE')) { die(); }
9:
10: /**
11: * @subpackage recover_settings/handler
12: */
13: class Hm_Handler_process_recover_settings_form extends Hm_Handler_login {
14: public function process() {
15: list($success, $form) = $this->process_form(array('recover_settings', 'old_password_recover', 'new_password_recover'));
16: if ($success) {
17: $user = $this->session->get('username');
18: if (!$this->session->auth($user, $form['new_password_recover'])) {
19: Hm_Msgs::add('Error validating your current password', 'warning');
20: return;
21: }
22: $data = $this->session->get('old_settings_str');
23: if (!$data) {
24: Hm_Msgs::add('No old settings to recover', 'warning');
25: return;
26: }
27: $settings = $this->user_config->decode(Hm_Crypt::plaintext($data, $form['old_password_recover']));
28: if (!is_array($settings) || count($settings) == 0) {
29: Hm_Msgs::add('Unable to recover your settings', 'danger');
30: return;
31: }
32: foreach ($settings as $name => $val) {
33: $this->user_config->set($name, $val);
34: }
35: try {
36: $this->user_config->save($user, $form['new_password_recover']);
37: } catch (Exception $e) {
38: Hm_Msgs::add('Could not save settings: ' . $e->getMessage(), 'warning');
39: }
40: Hm_Msgs::add('Settings recovered');
41: $this->session->set('load_recover_options', false);
42: $this->session->set('old_settings_str', '');
43: $this->out('reload_folders', true, false);
44: }
45: }
46: }
47:
48: /**
49: * @subpackage recover_settings/handler
50: */
51: class Hm_Handler_check_for_lost_settings extends Hm_Handler_login {
52: public function process() {
53: if ($this->session->loaded && $this->get('load_settings_failed') &&
54: in_array($this->session->auth_class, array('Hm_Auth_IMAP', true))) {
55: $this->session->set('load_recover_options', true);
56: $this->session->set('old_settings_str', $this->user_config->encrypted_str);
57: Hm_Msgs::add('Unable to load your settings! You may be able to recover them on the "Recover Settings" page in the Main menu.', 'danger');
58: }
59: $this->out('load_recover_options', $this->session->get('load_recover_options'));
60: $this->out('auth_type', $this->session->auth_class);
61: }
62: }
63:
64: /**
65: * @subpackage recover_settings/output
66: */
67: class Hm_Output_recover_settings_page_link extends Hm_Output_Module {
68: protected function output() {
69: if ($this->get('load_recover_options')) {
70: $res = '<li class="menu_recover_settings"><a class="unread_link" href="?page=recover_settings">'.
71: '<i class="bi bi-unlock-fill account_icon"></i> '.$this->trans('Recover Settings').'</a></li>';
72: if ($this->format == 'HTML5') {
73: return $res;
74: }
75: $this->concat('formatted_folder_list', $res);
76: }
77: }
78: }
79:
80: /**
81: * @subpackage recover_settings/output
82: */
83: class Hm_Output_recover_settings_page extends Hm_Output_Module {
84: protected function output() {
85: $auth = $this->get('auth_type');
86: if ($auth == 'Hm_Auth_IMAP') {
87: $type = 'IMAP';
88: }
89: $res = '<div class="recover_settings_content"><div class="content_title">'.$this->trans('Recover Settings').'</div>';
90: $res .= '<div class="recover_form">'.$this->trans('Settings detected that we could not decrypt.').' <b>';
91: $res .= sprintf($this->trans('Did your %s password change since you last logged into Cypht?'), $type);
92: $res .= '</b> Your settings may be recovered by entering your old and new passwords in the form below.';
93: $res .= '<form method="post" action="?page=recover_settings"><br />';
94: $res .= '<input type="hidden" name="hm_page_key" value="'.$this->html_safe(Hm_Request_Key::generate()).'" />';
95: $res .= '<input required type="password" name="old_password_recover" placeholder="'.$this->trans('Old password').'" /><br />';
96: $res .= '<input required type="password" name="new_password_recover" placeholder="'.$this->trans('Current password').'" /><br />';
97: $res .= '<input type="submit" name="recover_settings" value="'.$this->trans('Recover').'" />';
98: $res .= '</form></div></div>';
99: return $res;
100: }
101: }
102: