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