Prva inacica za Debian Jessie
[squirrelmail-change-pass.git] / options.php
1 <?php
2
3 /*
4  * Licensed under the GNU GPL. For full terms see the file COPYING.
5  *
6  * $Id: options.php,v 1.8 2009/12/09 00:21:11 indiri69 Exp $
7  */
8
9 define('SM_PATH', '../../');
10 require_once(SM_PATH . 'include/validate.php');
11 require_once(SM_PATH . 'functions/html.php');
12 require_once(SM_PATH . 'functions/forms.php');
13
14 $debug = false;
15
16 if(!sqgetGlobalVar('smtoken', $submitted_token, SQ_POST)) {
17     $submitted_token = '';
18 }
19
20 // Make sure the plugin is activated
21 global $plugins;
22 if(!in_array('change_pass', $plugins)) {
23     exit;
24 }
25
26 $min_pass_length = 0;
27 $max_pass_length = 99999999;
28
29 if (!@include(SM_PATH . 'config/config_change_pass.php')) {
30      @include(SM_PATH . 'plugins/change_pass/config.php');
31 }
32
33 include_once(SM_PATH . 'plugins/change_pass/functions.php');
34
35 global $color;
36 sqgetGlobalVar('change_pass_form', $change_pass_form, SQ_POST);
37
38 $error_messages = array();
39 $showform = true;
40
41 if (isset($change_pass_form)) {
42     sm_validate_security_token($submitted_token, 3600, TRUE);
43     sq_change_text_domain('change_pass');
44     sqgetGlobalVar('change_pass_old', $change_pass_old, SQ_POST);
45     sqgetGlobalVar('change_pass_new', $change_pass_new, SQ_POST);
46     sqgetGlobalVar('change_pass_verify', $change_pass_verify, SQ_POST);
47
48     if(!isset($change_pass_old) || $change_pass_old == '') {
49         $error_messages['cp_no_old'] = _("You must type in your current password.");
50     }
51
52     if(!isset($change_pass_new) || $change_pass_new == '') {
53         $error_messages['cp_no_new'] = _("You must type in a new password.");
54     }
55
56     if(!isset($change_pass_verify) || $change_pass_verify == '') {
57         $error_messages['cp_no_verify'] = _("You must also type in your new password in the verify box.");
58     }
59
60     if(!isset($error_messages['cp_no_new']) && !isset($error_messages['cp_no_verify'])) {
61         if($change_pass_new != $change_pass_verify) {
62             $error_messages['cp_new_mismatch'] = _("Your new password does not match the verify password.");
63         } else {
64             if (strlen($change_pass_new) < $min_pass_length ||
65                 strlen($change_pass_new) > $max_pass_length) {
66                     $error_messages[] = sprintf(_("Your new password should be %s to %s characters long."),
67                                                 $min_pass_length, $max_pass_length);
68             }
69         }
70     }
71
72     $old_pass = sqauth_read_password();
73     if(!isset($error_messages['cp_no_old']) && $change_pass_old != $old_pass) {
74         $error_messages['cp_wrong_old'] = _("Your current password is not correct.");
75     }
76
77     if(count($error_messages) == 0) {
78         $error_messages = change_pass_dochange($change_pass_old, $change_pass_new, $debug);
79         if(count($error_messages) == 0) {
80             $showform = false;
81         }
82     }
83     sq_change_text_domain('squirrelmail');
84 }
85 displayPageHeader($color, '');
86 sq_change_text_domain('change_pass');
87
88 echo
89     html_tag('table', "\n" .
90         html_tag('tr', "\n" .
91             html_tag('td', '<b>' . _("Change Password") . '</b>', 'center', $color[0])
92         ),
93         'center', $color[9], 'width="95%" border="0" cellpadding="1" cellspacing="0"') . "<br>\n";
94
95 if(count($error_messages) > 0) {
96     echo html_tag('table', '', 'center', '', 'width="100%" border="0" cellpadding="1" cellspacing="0"');
97     echo html_tag('tr');
98     echo html_tag('td', '', 'center');
99     echo html_tag('ul');
100     foreach($error_messages as $line) {
101         echo html_tag('li', htmlspecialchars($line), '', '', 'style="color: ' . $color[2] . '"');
102     }
103     echo html_tag('/ul');
104     echo html_tag('tr', html_tag('td', '&nbsp;')) . "\n";
105     echo html_tag('/table');
106 }
107
108 if($showform) {
109     echo addForm(sqm_baseuri() . 'plugins/change_pass/options.php');
110     echo addHidden('smtoken', sm_generate_security_token());
111     echo
112         html_tag('table', "\n" .
113             html_tag('tr', "\n" .
114                 html_tag('td', _("Current Password:"), 'right') .
115                 html_tag('td', addPwField('change_pass_old', ''), 'left')
116             ) .
117             html_tag('tr', "\n" .
118                 html_tag('td', _("New Password:"), 'right') .
119                 html_tag('td', addPwField('change_pass_new', ''), 'left')
120             ) .
121             html_tag('tr', "\n" .
122                 html_tag('td', _("Verify New Password:"), 'right') .
123                 html_tag('td', addPwField('change_pass_verify', ''), 'left')
124             ) .
125             html_tag('tr', "\n" .
126                 html_tag('td', addSubmit(_('Change Password'), 'change_pass_form'), 'center', '', 'colspan="2"')
127             ),
128             'center', '', 'border="0" cellpadding="1" cellspacing="0"') . "\n";
129     echo html_tag('/form');
130     echo html_tag('/body');
131     echo html_tag('/html');
132 }
133 sq_change_text_domain('squirrelmail');