]> git.wh0rd.org - tt-rss.git/blob - modules/pref-prefs.php
remove pointless escaping of the password (refs #392)
[tt-rss.git] / modules / pref-prefs.php
1 <?php
2 function module_pref_prefs($link) {
3
4 global $access_level_names;
5
6 $subop = $_REQUEST["subop"];
7
8 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
9 "STRIP_UNSAFE_TAGS");
10
11 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
12 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
13 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
14 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
15 "SSL_CERT_SERIAL");
16
17 /* if (FORCE_ARTICLE_PURGE != 0) {
18 array_push($prefs_blacklist, "PURGE_OLD_DAYS");
19 array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
20 } */
21
22 if ($subop == "change-password") {
23
24 $old_pw = $_POST["old_password"];
25 $new_pw = $_POST["new_password"];
26 $con_pw = $_POST["confirm_password"];
27
28 if ($old_pw == "") {
29 print "ERROR: ".__("Old password cannot be blank.");
30 return;
31 }
32
33 if ($new_pw == "") {
34 print "ERROR: ".__("New password cannot be blank.");
35 return;
36 }
37
38 if ($new_pw != $con_pw) {
39 print "ERROR: ".__("Entered passwords do not match.");
40 return;
41 }
42
43 $old_pw_hash1 = encrypt_password($old_pw);
44 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
45 $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]);
46
47 $active_uid = $_SESSION["uid"];
48
49 if ($old_pw && $new_pw) {
50
51 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
52
53 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
54 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
55 pwd_hash = '$old_pw_hash2')");
56
57 if (db_num_rows($result) == 1) {
58 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
59 WHERE id = '$active_uid'");
60
61 $_SESSION["pwd_hash"] = $new_pw_hash;
62
63 print __("Password has been changed.");
64 } else {
65 print "ERROR: ".__('Old password is incorrect.');
66 }
67 }
68
69 return;
70
71 } else if ($subop == "save-config") {
72
73 # $_SESSION["prefs_op_result"] = "save-config";
74
75 $_SESSION["prefs_cache"] = false;
76
77 // print_r($_POST);
78
79 $orig_theme = get_pref($link, "_THEME_ID");
80
81 foreach (array_keys($_POST) as $pref_name) {
82
83 $pref_name = db_escape_string($pref_name);
84 $value = db_escape_string($_POST[$pref_name]);
85
86 set_pref($link, $pref_name, $value);
87
88 }
89
90 if ($orig_theme != get_pref($link, "_THEME_ID")) {
91 print "PREFS_THEME_CHANGED";
92 } else {
93 print __("The configuration was saved.");
94 }
95
96 return;
97
98 } else if ($subop == "getHelp") {
99
100 $pref_name = db_escape_string($_REQUEST["pn"]);
101
102 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
103 WHERE pref_name = '$pref_name'");
104
105 if (db_num_rows($result) > 0) {
106 $help_text = db_fetch_result($result, 0, "help_text");
107 print $help_text;
108 } else {
109 printf(__("Unknown option: %s"), $pref_name);
110 }
111
112 } else if ($subop == "change-email") {
113
114 $email = db_escape_string($_POST["email"]);
115 $full_name = db_escape_string($_POST["full_name"]);
116
117 $active_uid = $_SESSION["uid"];
118
119 db_query($link, "UPDATE ttrss_users SET email = '$email',
120 full_name = '$full_name' WHERE id = '$active_uid'");
121
122 print __("Your personal data has been saved.");
123
124 return;
125
126 } else if ($subop == "reset-config") {
127
128 $_SESSION["prefs_op_result"] = "reset-to-defaults";
129
130 if ($_SESSION["profile"]) {
131 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
132 } else {
133 $profile_qpart = "profile IS NULL";
134 }
135
136 db_query($link, "DELETE FROM ttrss_user_prefs
137 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
138
139 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
140
141 print "PREFS_THEME_CHANGED";
142
143 // print __("The configuration was reset to defaults.");
144
145 return;
146
147 } else {
148
149 if (!SINGLE_USER_MODE) {
150
151 $_SESSION["prefs_op_result"] = "";
152
153 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
154 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">";
155
156 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
157
158 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
159 evt.preventDefault();
160 if (this.validate()) {
161 notify_progress('Saving data...', true);
162
163 new Ajax.Request('backend.php', {
164 parameters: dojo.objectToQuery(this.getValues()),
165 onComplete: function(transport) {
166 notify_callback2(transport);
167 } });
168
169 }
170 </script>";
171
172 print "<table width=\"100%\" class=\"prefPrefsList\">";
173
174 $result = db_query($link, "SELECT email,full_name,
175 access_level FROM ttrss_users
176 WHERE id = ".$_SESSION["uid"]);
177
178 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
179 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
180
181 print "<tr><td width=\"40%\">".__('Full name')."</td>";
182 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
183 value=\"$full_name\"></td></tr>";
184
185 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
186 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
187
188 if (!SINGLE_USER_MODE) {
189 $access_level = db_fetch_result($result, 0, "access_level");
190 print "<tr><td width=\"40%\">".__('Access level')."</td>";
191 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
192 }
193
194 print "</table>";
195
196 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
197 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-email\">";
198
199 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
200 __("Save data")."</button>";
201
202 print "</form>";
203
204 print "</div>"; # pane
205 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">";
206
207 $result = db_query($link, "SELECT id FROM ttrss_users
208 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
209 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
210
211 if (db_num_rows($result) != 0) {
212 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
213 }
214
215 print "<form dojoType=\"dijit.form.Form\">";
216
217 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
218 evt.preventDefault();
219 if (this.validate()) {
220 notify_progress('Changing password...', true);
221
222 new Ajax.Request('backend.php', {
223 parameters: dojo.objectToQuery(this.getValues()),
224 onComplete: function(transport) {
225 notify('');
226 if (transport.responseText.indexOf('ERROR: ') == 0) {
227 notify_error(transport.responseText.replace('ERROR: ', ''));
228 } else {
229 notify_info(transport.responseText);
230 var warn = $('default_pass_warning');
231 if (warn) Element.hide(warn);
232 }
233 }});
234 this.reset();
235 }
236 </script>";
237
238 print "<table width=\"100%\" class=\"prefPrefsList\">";
239
240 print "<tr><td width=\"40%\">".__("Old password")."</td>";
241 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
242
243 print "<tr><td width=\"40%\">".__("New password")."</td>";
244
245 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
246 name=\"new_password\"></td></tr>";
247
248 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
249
250 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
251
252 print "</table>";
253
254 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
255 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"change-password\">";
256
257 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
258 __("Change password")."</button>";
259
260 print "</form>";
261
262 print "</div>"; #pane
263 }
264
265 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
266
267 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
268
269 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
270 evt.preventDefault();
271 if (this.validate()) {
272 console.log(dojo.objectToQuery(this.getValues()));
273
274 new Ajax.Request('backend.php', {
275 parameters: dojo.objectToQuery(this.getValues()),
276 onComplete: function(transport) {
277 var msg = transport.responseText;
278 if (msg.match('PREFS_THEME_CHANGED')) {
279 window.location.reload();
280 } else {
281 notify_info(msg);
282 }
283 } });
284 }
285 </script>";
286
287
288 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
289
290 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
291
292 if ($_SESSION["profile"]) {
293 print_notice("Some preferences are only available in default profile.");
294 }
295
296 if ($_SESSION["profile"]) {
297 initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
298 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
299 } else {
300 initialize_user_prefs($link, $_SESSION["uid"]);
301 $profile_qpart = "profile IS NULL";
302 }
303
304 $result = db_query($link, "SELECT
305 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
306 section_name,def_value,section_id
307 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
308 WHERE type_id = ttrss_prefs_types.id AND
309 $profile_qpart AND
310 section_id = ttrss_prefs_sections.id AND
311 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
312 short_desc != '' AND
313 owner_uid = ".$_SESSION["uid"]."
314 ORDER BY section_id,short_desc");
315
316 $lnum = 0;
317
318 $active_section = "";
319
320 while ($line = db_fetch_assoc($result)) {
321
322 if (in_array($line["pref_name"], $prefs_blacklist)) {
323 continue;
324 }
325
326 if ($_SESSION["profile"] && in_array($line["pref_name"],
327 $profile_blacklist)) {
328 continue;
329 }
330
331 if ($active_section != $line["section_name"]) {
332
333 if ($active_section != "") {
334 print "</table>";
335 }
336
337 print "<table width=\"100%\" class=\"prefPrefsList\">";
338
339 $active_section = $line["section_name"];
340
341 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
342
343 if ($line["section_id"] == 2) {
344 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
345
346 $user_theme = get_pref($link, "_THEME_ID");
347 $themes = get_all_themes();
348
349 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
350 print "<option value='Default'>".__('Default')."</option>";
351 print "<option value='----------------' disabled=\"1\">--------</option>";
352
353 foreach ($themes as $t) {
354 $base = $t['base'];
355 $name = $t['name'];
356
357 if ($base == $user_theme) {
358 $selected = "selected=\"1\"";
359 } else {
360 $selected = "";
361 }
362
363 print "<option $selected value='$base'>$name</option>";
364
365 }
366
367 print "</select></td></tr>";
368 }
369
370 // print "<tr class=\"title\">
371 // <td width=\"25%\">Option</td><td>Value</td></tr>";
372
373 $lnum = 0;
374 }
375
376 // $class = ($lnum % 2) ? "even" : "odd";
377
378 print "<tr>";
379
380 $type_name = $line["type_name"];
381 $pref_name = $line["pref_name"];
382 $value = $line["value"];
383 $def_value = $line["def_value"];
384 $help_text = $line["help_text"];
385
386 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
387
388 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
389
390 print "</td>";
391
392 print "<td class=\"prefValue\">";
393
394 if ($pref_name == "USER_TIMEZONE") {
395
396 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
397
398 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
399 } else if ($pref_name == "USER_STYLESHEET") {
400
401 print "<button dojoType=\"dijit.form.Button\"
402 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
403
404 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
405
406 $limits = array(15, 30, 45, 60);
407
408 print_select($pref_name, $value, $limits,
409 'dojoType="dijit.form.Select"');
410
411 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
412
413 global $update_intervals_nodefault;
414
415 print_select_hash($pref_name, $value, $update_intervals_nodefault,
416 'dojoType="dijit.form.Select"');
417
418 } else if ($type_name == "bool") {
419 // print_select($pref_name, $value, array("true", "false"));
420
421 if ($value == "true") {
422 $value = __("Yes");
423 } else {
424 $value = __("No");
425 }
426
427 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
428 $disabled = "disabled=\"1\"";
429 $value = __("Yes");
430 } else {
431 $disabled = "";
432 }
433
434 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
435 $disabled);
436
437 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
438 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
439
440 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
441
442 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
443 $disabled = "disabled=\"1\"";
444 $value = FORCE_ARTICLE_PURGE;
445 } else {
446 $disabled = "";
447 }
448
449 print "<input dojoType=\"dijit.form.ValidationTextBox\"
450 required=\"1\" $regexp $disabled
451 name=\"$pref_name\" value=\"$value\">";
452
453 } else if ($pref_name == "SSL_CERT_SERIAL") {
454
455 print "<input dojoType=\"dijit.form.ValidationTextBox\"
456 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
457 name=\"$pref_name\" value=\"$value\">";
458
459 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
460 $has_serial = ($cert_serial) ? "false" : "true";
461
462 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
463 onclick=\"insertSSLserial('$cert_serial')\">" .
464 __('Register') . "</button>";
465
466 print " <button dojoType=\"dijit.form.Button\"
467 onclick=\"insertSSLserial('')\">" .
468 __('Clear') . "</button>";
469
470 } else {
471 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
472
473 print "<input dojoType=\"dijit.form.ValidationTextBox\"
474 $regexp
475 name=\"$pref_name\" value=\"$value\">";
476 }
477
478 print "</td>";
479
480 print "</tr>";
481
482 $lnum++;
483 }
484
485 print "</table>";
486
487 print '</div>'; # inside pane
488 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
489
490 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
491 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save-config\">";
492
493 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
494 __('Save configuration')."</button> ";
495
496 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
497 __('Manage profiles')."</button> ";
498
499 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
500 __('Reset to defaults')."</button>";
501
502 print '</div>'; # inner pane
503 print '</div>'; # border container
504
505 print "</form>";
506
507 print "</div>"; #pane
508 print "</div>"; #container
509
510 }
511 }
512 ?>