/
changepasswd_AD.php
executable file
·142 lines (118 loc) · 4.75 KB
/
changepasswd_AD.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
class changepasswd_AD extends rcube_plugin
{
public $task = 'settings';
private $config;
private $db;
function init()
{
rcmail::get_instance()->output->add_label('password');
$this->add_texts('localization/', array('nocurpassword', 'nopassword', 'passwordinconsistency'));
$this->register_action('plugin.changepasswd_AD', array($this, 'init_html'));
$this->register_action('plugin.changepasswd_AD.save', array($this, 'save'));
$this->include_script('changepasswd_AD.js');
}
function init_html()
{
$this->api->output->add_handler('changepasswd', array($this, 'gen_form'));
$this->api->output->set_pagetitle($this->gettext('changepasswd'));
$this->api->output->send('changepasswd_AD.changepasswd');
}
function gen_form()
{
list($form_start, $form_end) = get_form_tags(null, 'plugin.changepasswd_AD.save');
// return the complete form as table
$out = $form_start;
$table = new html_table(array('cols' => 2));
// show old password field
$field_id = 'rcmfd_curpwd';
$input_curpasswd = new html_passwordfield(array('name' => '_curpasswd', 'id' => $field_id));
$table->add('title', html::label($field_id, Q($this->gettext('curpasswd'))));
$table->add(null, $input_curpasswd->show());
// show new password field
$field_id = 'rcmfd_newpwd';
$input_newpasswd = new html_passwordfield(array('name' => '_newpasswd', 'id' => $field_id,));
$table->add('title', html::label($field_id, Q($this->gettext('newpasswd'))));
$table->add(null, $input_newpasswd->show());
// show new password confirm field
$field_id = 'rcmfd_cnfpwd';
$input_confpasswd = new html_passwordfield(array('name' => '_confpasswd', 'id' => $field_id));
$table->add('title', html::label($field_id, Q($this->gettext('confpasswd'))));
$table->add(null, $input_confpasswd->show());
$out .= $table->show();
$out .= $form_end;
return $out;
}
function save()
{
$old_pw = $_POST['_curpasswd'];
$new_pw = $_POST['_newpasswd'];
$uid_parts = split("@", $_SESSION['username']);
$uid = $uid_parts[0];
$ret = $this->changePassword($uid, $old_pw, $new_pw);
switch ($ret) {
case 9:
$_SESSION['password'] = rcmail::get_instance()->encrypt($new_pw);
$this->api->output->command('display_message', $this->gettext('passwordchanged'), 'confirmation');
break;
case 1:
$this->api->output->command('display_message', $this->gettext('passwordfailed1'), 'error');
break;
case 2:
$this->api->output->command('display_message', $this->gettext('passwordfailed2'), 'error');
break;
case 3:
$this->api->output->command('display_message', $this->gettext('passwordfailed3'), 'error');
break;
case 4:
$this->api->output->command('display_message', $this->gettext('passwordfailed4'), 'error');
break;
case 5:
$this->api->output->command('display_message', $this->gettext('passwordfailed5'), 'error');
break;
case 6:
$this->api->output->command('display_message', $this->gettext('passwordfailed6'), 'error');
break;
case 7:
$this->api->output->command('display_message', $this->gettext('passwordfailed7'), 'error');
break;
case 8:
$this->api->output->command('display_message', $this->gettext('passwordfailed8'), 'error');
break;
case 0:
$this->api->output->command('display_message', $this->gettext('passwordfailed0'), 'error');
break;
}
// go to next step
rcmail_overwrite_action('plugin.changepasswd_AD');
$this->action = 'plugin.changepasswd_AD';
$this->init_html();
}
function changePassword($uid, $old_pw, $new_pw) {
include ("changepasswd_AD_config.php");
include ("csLogging.class.php");
$logwriter = new csLogging($errorlogfile,$debuglogfile,$debug);
$postData = array('uid'=>$uid,'curpwd'=>$old_pw,'newpwdone'=>$new_pw,'newpwdtwo'=>$new_pw,'successurl'=>$successurl,'failurl'=>$failurl);
$postData = http_build_query($postData);
$params = array('http' => array(
'method' => 'GET',
'content' => $postData
));
$ctx = stream_context_create($params);
$logwriter->debugwrite("DATA: $postData");
$logwriter->debugwrite("PARAMS: $params");
$logwriter->debugwrite("CTX: $ctx");
$logwriter->debugwrite("POSTURL: $posturl");
$fp = @fopen($posturl . "?" . $postData, 'r', false, $ctx);
if (!$fp) {
$logwriter->writelog("Problem with $posturl, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
$logwriter->writelog("Problem reading data from $posturl, $php_errormsg");
}
$logwriter->debugwrite("RESPONSE: $response");
return $response;
}
}
?>