3670a36ed14e7f82d536c77b61056f8f4a91e77d
3 * Merakchange password backend
5 * @author Edwin van Elk <Edwin@eve-software.com>
8 * @subpackage change_password
15 global $merak_url, $merak_selfpage, $merak_action;
19 $merak_url = "http://localhost:32000/";
20 $merak_selfpage = "self.html";
21 $merak_action = "self_edit";
23 // NO NEED TO CHANGE ANYTHING BELOW THIS LINE
25 global $squirrelmail_plugin_hooks;
26 $squirrelmail_plugin_hooks['change_password_dochange']['merak'] =
30 * This is the function that is specific to your backend. It takes
31 * the current password (as supplied by the user) and the desired
32 * new password. It will return an array of messages. If everything
33 * was successful, the array will be empty. Else, it will contain
34 * the errormessage(s).
35 * Constants to be used for these messages:
36 * CPW_CURRENT_NOMATCH -> "Your current password is not correct."
37 * CPW_INVALID_PW -> "Your new password contains invalid characters."
39 * @param array data The username/currentpw/newpw data.
40 * @return array Array of error messages.
42 function cpw_merak_dochange($data)
44 // unfortunately, we can only pass one parameter to a hook function,
45 // so we have to pass it as an array.
46 $username = $data['username'];
47 $curpw = $data['curpw'];
48 $newpw = $data['newpw'];
52 global $merak_url, $merak_selfpage, $merak_action;
54 if (!function_exists('curl_init')) {
56 // user_error('Curl module NOT available!', E_USER_ERROR);
57 array_push($msgs, _("Curl module NOT available! Unable to change password!"));
62 curl_setopt ($ch, CURLOPT_URL
, $merak_url . $merak_selfpage);
63 curl_setopt ($ch, CURLOPT_RETURNTRANSFER
, 1);
64 curl_setopt ($ch, CURLOPT_TIMEOUT
, 10);
65 curl_setopt ($ch, CURLOPT_USERPWD
, "$username:$curpw");
66 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION
, 1);
67 $result = curl_exec ($ch);
70 if (strpos($result, "401 Access denied") <> 0) {
71 array_push($msgs, _("Cannot change password! (Is user 'Self Configurable User' ?) (401)"));
75 // Get URL from: <FORM METHOD="POST" ACTION="success.html?id=a9375ee5e445775e871d5e1401a963aa">
77 $str = stristr($result, "<FORM");
78 $str = substr($str, 0, strpos($str, ">") +
1);
79 $str = stristr($str, "ACTION=");
80 $str = substr(stristr($str, "\""),1);
81 $str = substr($str, 0, strpos($str, "\""));
83 // Extra check to see if the result contains 'html'
84 if (!stristr($str, "html")) {
85 array_push($msgs, _("Cannot change password!") . " (1)" );
89 $newurl = $merak_url . $str;
91 // Get useraddr from: $useraddr = <INPUT TYPE="HIDDEN" NAME="usraddr" VALUE="mail@hostname.com">
93 $str = stristr($result, "usraddr");
94 $str = substr($str, 0, strpos($str, ">") +
1);
95 $str = stristr($str, "VALUE=");
96 $str = substr(stristr($str, "\""),1);
97 $str = substr($str, 0, strpos($str, "\""));
99 // Extra check to see if the result contains '@'
100 if (!stristr($str, "@")) {
101 array_push($msgs, _("Cannot change password!") . " (2)" );
107 //Include (almost) all input fields from screen
109 $contents2 = $result;
111 $tag = stristr($contents2, "<INPUT");
114 $contents2 = stristr($contents2, "<INPUT");
115 $tag = substr($contents2, 0, strpos($contents2, ">") +
1);
117 if (GetSub($tag, "TYPE") == "TEXT" ||
118 GetSub($tag, "TYPE") == "HIDDEN" ||
119 GetSub($tag, "TYPE") == "PASSWORD") {
120 $tags[GetSub($tag, "NAME")] = GetSub($tag, "VALUE");
123 if ((GetSub($tag, "TYPE") == "RADIO" ||
124 GetSub($tag, "TYPE") == "CHECKBOX") &&
126 $tags[GetSub($tag, "NAME")] = GetSub($tag, "VALUE");
128 $contents2 = substr($contents2, 1);
131 $tags["action"] = $merak_action;
132 $tags["usraddr"] = $useraddr;
133 $tags["usr_pass"] = $newpw;
134 $tags["usr_conf"] = $newpw;
137 foreach ($tags as $key => $value) {
138 $str2 .= $key . "=" . urlencode($value) . "&";
141 $str2 = trim($str2, "&");
146 curl_setopt ($ch, CURLOPT_URL
, $newurl);
147 curl_setopt ($ch, CURLOPT_POST
, 1);
148 curl_setopt ($ch, CURLOPT_RETURNTRANSFER
, 1);
149 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION
, 1);
150 curl_setopt ($ch, CURLOPT_POSTFIELDS
, $str2);
151 $result=curl_exec ($ch);
154 if (strpos($result, "Failure") <> 0) {
155 array_push($msgs, _("Cannot change password!") . " (3)");
162 function GetSub($tag, $type) {
164 $str = stristr($tag, $type . "=");
165 $str = substr($str, strlen($type) +
1);
166 $str = trim($str, '"');
168 if (!strpos($str, " ") === false) {
169 $str = substr($str, 0, strpos($str, " "));
170 $str = trim($str, '"');
173 if (!(strpos($str, '"') === false)) {
174 $str = substr($str, 0, strpos($str, '"'));
177 $str = trim($str, '>');
182 function IsChecked($tag) {
184 if (!(strpos(strtolower($tag), 'checked') === false)) {