]> git.wh0rd.org - tt-rss.git/blame - classes/pref/prefs.php
feedlist_init: do not wait before calling viewfeed(-3)
[tt-rss.git] / classes / pref / prefs.php
CommitLineData
1395083e 1<?php
369dbc19 2class Pref_Prefs extends Handler_Protected {
1395083e 3
8484ce22 4 function csrf_ignore($method) {
27211afe 5 $csrf_ignored = array("index", "updateself");
8484ce22
AD
6
7 return array_search($method, $csrf_ignored) !== false;
8 }
9
1395083e
AD
10 function changepassword() {
11
12 $old_pw = $_POST["old_password"];
13 $new_pw = $_POST["new_password"];
14 $con_pw = $_POST["confirm_password"];
15
16 if ($old_pw == "") {
17 print "ERROR: ".__("Old password cannot be blank.");
18 return;
19 }
20
21 if ($new_pw == "") {
22 print "ERROR: ".__("New password cannot be blank.");
23 return;
24 }
25
26 if ($new_pw != $con_pw) {
27 print "ERROR: ".__("Entered passwords do not match.");
28 return;
29 }
30
d5fd183d
AD
31 $module_class = "auth_" . $_SESSION["auth_module"];
32 $authenticator = new $module_class($this->link);
1395083e 33
d5fd183d
AD
34 if (method_exists($authenticator, "change_password")) {
35 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
098df83b 36 } else {
d5fd183d 37 print "ERROR: ".__("Function not supported by authentication module.");
098df83b 38 }
1395083e
AD
39 }
40
41 function saveconfig() {
42
43 $_SESSION["prefs_cache"] = false;
44
45 $orig_theme = get_pref($this->link, "_THEME_ID");
46
47 foreach (array_keys($_POST) as $pref_name) {
48
49 $pref_name = db_escape_string($pref_name);
50 $value = db_escape_string($_POST[$pref_name]);
51
1b9b19af
AD
52 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
53 if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) {
54
55 db_query($this->link, "UPDATE ttrss_users SET
56 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
57
58 }
59 }
60
1395083e
AD
61 set_pref($this->link, $pref_name, $value);
62
63 }
64
65 if ($orig_theme != get_pref($this->link, "_THEME_ID")) {
66 print "PREFS_THEME_CHANGED";
67 } else {
68 print __("The configuration was saved.");
69 }
70 }
71
72 function getHelp() {
73
74 $pref_name = db_escape_string($_REQUEST["pn"]);
75
76 $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs
77 WHERE pref_name = '$pref_name'");
78
79 if (db_num_rows($result) > 0) {
80 $help_text = db_fetch_result($result, 0, "help_text");
81 print $help_text;
82 } else {
83 printf(__("Unknown option: %s"), $pref_name);
84 }
85 }
86
87 function changeemail() {
88
89 $email = db_escape_string($_POST["email"]);
90 $full_name = db_escape_string($_POST["full_name"]);
91
92 $active_uid = $_SESSION["uid"];
93
94 db_query($this->link, "UPDATE ttrss_users SET email = '$email',
95 full_name = '$full_name' WHERE id = '$active_uid'");
96
97 print __("Your personal data has been saved.");
98
99 return;
100 }
101
102 function resetconfig() {
103
104 $_SESSION["prefs_op_result"] = "reset-to-defaults";
105
106 if ($_SESSION["profile"]) {
107 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
108 } else {
109 $profile_qpart = "profile IS NULL";
110 }
111
112 db_query($this->link, "DELETE FROM ttrss_user_prefs
113 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
114
115 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
116
117 print "PREFS_THEME_CHANGED";
118 }
119
120 function index() {
121
122 global $access_level_names;
123
124 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
125 "STRIP_UNSAFE_TAGS");
126
127 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
128 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
129 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
130 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
6d9455e9 131 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
1395083e
AD
132
133
d4c64ecc 134 $_SESSION["prefs_op_result"] = "";
1395083e 135
d4c64ecc
AD
136 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
137 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
1395083e 138
d4c64ecc 139 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
1395083e 140
d4c64ecc
AD
141 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
142 evt.preventDefault();
143 if (this.validate()) {
144 notify_progress('Saving data...', true);
1395083e 145
d4c64ecc
AD
146 new Ajax.Request('backend.php', {
147 parameters: dojo.objectToQuery(this.getValues()),
148 onComplete: function(transport) {
149 notify_callback2(transport);
150 } });
1395083e 151
d4c64ecc
AD
152 }
153 </script>";
1395083e 154
d4c64ecc 155 print "<table width=\"100%\" class=\"prefPrefsList\">";
1395083e 156
fb70f26e
AD
157 print "<h2>" . __("Personal data") . "</h2>";
158
159 $result = db_query($this->link, "SELECT email,full_name,otp_enabled,
d4c64ecc
AD
160 access_level FROM ttrss_users
161 WHERE id = ".$_SESSION["uid"]);
1395083e 162
d4c64ecc
AD
163 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
164 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
fb70f26e 165 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
1395083e 166
d4c64ecc
AD
167 print "<tr><td width=\"40%\">".__('Full name')."</td>";
168 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
169 value=\"$full_name\"></td></tr>";
1395083e 170
d4c64ecc
AD
171 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
172 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
1395083e 173
0d421af8 174 if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
949b1a94 175
d4c64ecc
AD
176 $access_level = db_fetch_result($result, 0, "access_level");
177 print "<tr><td width=\"40%\">".__('Access level')."</td>";
178 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
179 }
1395083e 180
d4c64ecc 181 print "</table>";
1395083e 182
d4c64ecc
AD
183 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
184 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
1395083e 185
d4c64ecc
AD
186 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
187 __("Save data")."</button>";
1395083e 188
d4c64ecc 189 print "</form>";
1395083e 190
d5fd183d
AD
191 if ($_SESSION["auth_module"]) {
192 $module_class = "auth_" . $_SESSION["auth_module"];
193 $authenticator = new $module_class($this->link);
194 } else {
195 $authenticator = false;
196 }
197
198 if ($authenticator && method_exists($authenticator, "change_password")) {
1395083e 199
fb70f26e
AD
200 print "<h2>" . __("Password") . "</h2>";
201
1395083e
AD
202 $result = db_query($this->link, "SELECT id FROM ttrss_users
203 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
204 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
205
206 if (db_num_rows($result) != 0) {
207 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
208 }
209
210 print "<form dojoType=\"dijit.form.Form\">";
211
212 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
213 evt.preventDefault();
214 if (this.validate()) {
215 notify_progress('Changing password...', true);
216
217 new Ajax.Request('backend.php', {
218 parameters: dojo.objectToQuery(this.getValues()),
219 onComplete: function(transport) {
220 notify('');
221 if (transport.responseText.indexOf('ERROR: ') == 0) {
222 notify_error(transport.responseText.replace('ERROR: ', ''));
223 } else {
224 notify_info(transport.responseText);
225 var warn = $('default_pass_warning');
226 if (warn) Element.hide(warn);
227 }
228 }});
229 this.reset();
230 }
231 </script>";
232
3ca8af7f
AD
233 if ($otp_enabled) {
234 print_notice("Changing your current password will disable OTP.");
235 }
236
1395083e
AD
237 print "<table width=\"100%\" class=\"prefPrefsList\">";
238
239 print "<tr><td width=\"40%\">".__("Old password")."</td>";
240 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
241
242 print "<tr><td width=\"40%\">".__("New password")."</td>";
243
244 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
245 name=\"new_password\"></td></tr>";
246
247 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
248
249 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
250
251 print "</table>";
252
253 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
254 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
255
256 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
257 __("Change password")."</button>";
258
259 print "</form>";
260
d1e31c7a 261 if ($_SESSION["auth_module"] == "internal") {
fb70f26e
AD
262
263 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
264
265 if ($otp_enabled) {
266
3ca8af7f
AD
267 print_notice("One time passwords are currently enabled. Enter your current password below to disable.");
268
269 print "<form dojoType=\"dijit.form.Form\">";
270
271 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
272 evt.preventDefault();
273 if (this.validate()) {
274 notify_progress('Disabling OTP', true);
275
276 new Ajax.Request('backend.php', {
277 parameters: dojo.objectToQuery(this.getValues()),
278 onComplete: function(transport) {
279 notify('');
280 if (transport.responseText.indexOf('ERROR: ') == 0) {
281 notify_error(transport.responseText.replace('ERROR: ', ''));
282 } else {
283 window.location.reload();
284 }
285 }});
286 this.reset();
287 }
288 </script>";
289
290 print "<table width=\"100%\" class=\"prefPrefsList\">";
291
292 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
293
294 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
295 name=\"password\"></td></tr>";
296
297 print "</table>";
298
299 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
300 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
301
302 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
303 __("Disable OTP")."</button>";
304
305 print "</form>";
fb70f26e
AD
306
307 } else {
308
309 print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
310
311 print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
312
313 $csrf_token = $_SESSION["csrf_token"];
314
315 print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
316
317 print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
318
319 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
3ca8af7f 320 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
fb70f26e
AD
321
322 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
323 evt.preventDefault();
324 if (this.validate()) {
325 notify_progress('Saving data...', true);
326
327 new Ajax.Request('backend.php', {
328 parameters: dojo.objectToQuery(this.getValues()),
329 onComplete: function(transport) {
3ca8af7f
AD
330 notify('');
331 if (transport.responseText.indexOf('ERROR: ') == 0) {
332 notify_error(transport.responseText.replace('ERROR: ', ''));
333 } else {
334 window.location.reload();
335 }
fb70f26e
AD
336 } });
337
338 }
339 </script>";
340
3ca8af7f
AD
341 print "<table width=\"100%\" class=\"prefPrefsList\">";
342
343 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
344
345 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
346 name=\"password\"></td></tr>";
347
348 print "<tr><td colspan=\"2\">";
349
fb70f26e
AD
350 print "<input dojoType=\"dijit.form.CheckBox\" required=\"1\"
351 type=\"checkbox\" id=\"enable_otp\" name=\"enable_otp\"/> ";
352 print "<label for=\"enable_otp\">".__("I have scanned the code and would like to enable OTP")."</label>";
353
3ca8af7f
AD
354 print "</td></tr><tr><td colspan=\"2\">";
355
356 print "</td></tr>";
357 print "</table>";
358
fb70f26e 359 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
3ca8af7f 360 __("Enable OTP")."</button>";
fb70f26e
AD
361
362 print "</form>";
363
364 }
365
366 }
1395083e
AD
367 }
368
d4c64ecc
AD
369 print "</div>"; #pane
370
1395083e
AD
371 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
372
373 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
374
375 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
376 evt.preventDefault();
377 if (this.validate()) {
378 console.log(dojo.objectToQuery(this.getValues()));
379
380 new Ajax.Request('backend.php', {
381 parameters: dojo.objectToQuery(this.getValues()),
382 onComplete: function(transport) {
383 var msg = transport.responseText;
384 if (msg.match('PREFS_THEME_CHANGED')) {
385 window.location.reload();
386 } else {
387 notify_info(msg);
388 }
389 } });
390 }
391 </script>";
392
393 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
394
395 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
396
397 if ($_SESSION["profile"]) {
398 print_notice("Some preferences are only available in default profile.");
399 }
400
401 if ($_SESSION["profile"]) {
402 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
403 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
404 } else {
405 initialize_user_prefs($this->link, $_SESSION["uid"]);
406 $profile_qpart = "profile IS NULL";
407 }
408
f9ebb32c
AD
409 if ($_SESSION["prefs_show_advanced"])
410 $access_query = "true";
411 else
412 $access_query = "(access_level = 0 AND section_id != 3)";
413
ddb575c7 414 $result = db_query($this->link, "SELECT DISTINCT
1395083e 415 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
f9ebb32c 416 ttrss_prefs_sections.order_id,
1395083e
AD
417 section_name,def_value,section_id
418 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
419 WHERE type_id = ttrss_prefs_types.id AND
420 $profile_qpart AND
421 section_id = ttrss_prefs_sections.id AND
422 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
f9ebb32c 423 $access_query AND
1395083e
AD
424 short_desc != '' AND
425 owner_uid = ".$_SESSION["uid"]."
f9ebb32c 426 ORDER BY ttrss_prefs_sections.order_id,short_desc");
1395083e
AD
427
428 $lnum = 0;
429
430 $active_section = "";
431
432 while ($line = db_fetch_assoc($result)) {
433
434 if (in_array($line["pref_name"], $prefs_blacklist)) {
435 continue;
436 }
437
438 if ($_SESSION["profile"] && in_array($line["pref_name"],
439 $profile_blacklist)) {
440 continue;
441 }
442
443 if ($active_section != $line["section_name"]) {
444
445 if ($active_section != "") {
446 print "</table>";
447 }
448
449 print "<table width=\"100%\" class=\"prefPrefsList\">";
450
451 $active_section = $line["section_name"];
452
453 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
454
455 if ($line["section_id"] == 2) {
456 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
457
458 $user_theme = get_pref($this->link, "_THEME_ID");
459 $themes = get_all_themes();
460
461 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
462 print "<option value='Default'>".__('Default')."</option>";
463 print "<option value='----------------' disabled=\"1\">--------</option>";
464
465 foreach ($themes as $t) {
466 $base = $t['base'];
467 $name = $t['name'];
468
469 if ($base == $user_theme) {
470 $selected = "selected=\"1\"";
471 } else {
472 $selected = "";
473 }
474
475 print "<option $selected value='$base'>$name</option>";
476
477 }
478
479 print "</select></td></tr>";
480 }
481 $lnum = 0;
482 }
483
484 print "<tr>";
485
486 $type_name = $line["type_name"];
487 $pref_name = $line["pref_name"];
488 $value = $line["value"];
489 $def_value = $line["def_value"];
490 $help_text = $line["help_text"];
491
492 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
493
494 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
495
496 print "</td>";
497
498 print "<td class=\"prefValue\">";
499
500 if ($pref_name == "USER_TIMEZONE") {
501
502 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
503
504 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
505 } else if ($pref_name == "USER_STYLESHEET") {
506
507 print "<button dojoType=\"dijit.form.Button\"
508 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
509
510 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
511
512 $limits = array(15, 30, 45, 60);
513
514 print_select($pref_name, $value, $limits,
515 'dojoType="dijit.form.Select"');
516
517 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
518
519 global $update_intervals_nodefault;
520
521 print_select_hash($pref_name, $value, $update_intervals_nodefault,
522 'dojoType="dijit.form.Select"');
523
524 } else if ($type_name == "bool") {
525
526 if ($value == "true") {
527 $value = __("Yes");
528 } else {
529 $value = __("No");
530 }
531
532 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
533 $disabled = "disabled=\"1\"";
534 $value = __("Yes");
535 } else {
536 $disabled = "";
537 }
538
539 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
540 $disabled);
541
542 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
543 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
544
545 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
546
547 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
548 $disabled = "disabled=\"1\"";
549 $value = FORCE_ARTICLE_PURGE;
550 } else {
551 $disabled = "";
552 }
553
554 print "<input dojoType=\"dijit.form.ValidationTextBox\"
555 required=\"1\" $regexp $disabled
556 name=\"$pref_name\" value=\"$value\">";
557
558 } else if ($pref_name == "SSL_CERT_SERIAL") {
559
560 print "<input dojoType=\"dijit.form.ValidationTextBox\"
561 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
562 name=\"$pref_name\" value=\"$value\">";
563
564 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
565 $has_serial = ($cert_serial) ? "false" : "true";
566
567 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
568 onclick=\"insertSSLserial('$cert_serial')\">" .
569 __('Register') . "</button>";
570
571 print " <button dojoType=\"dijit.form.Button\"
572 onclick=\"insertSSLserial('')\">" .
573 __('Clear') . "</button>";
574
76c843a9 575 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
61c1812f 576 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1b92f543 577 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
61c1812f 578 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
8eba830f 579 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
1395083e
AD
580 } else {
581 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
582
583 print "<input dojoType=\"dijit.form.ValidationTextBox\"
584 $regexp
585 name=\"$pref_name\" value=\"$value\">";
586 }
587
588 print "</td>";
589
590 print "</tr>";
591
592 $lnum++;
593 }
594
595 print "</table>";
596
597 print '</div>'; # inside pane
598 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
599
600 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
601 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
602
603 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
604 __('Save configuration')."</button> ";
605
606 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
607 __('Manage profiles')."</button> ";
608
609 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
610 __('Reset to defaults')."</button>";
611
f9ebb32c
AD
612 print "&nbsp;";
613
614 $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
615
616 print "<input onclick='toggleAdvancedPrefs()'
617 id='prefs_show_advanced'
618 dojoType=\"dijit.form.CheckBox\"
619 $checked
620 type=\"checkbox\"></input>
621 <label for='prefs_show_advanced'>" .
622 __("Show additional preferences") . "</label>";
623
1395083e
AD
624 print '</div>'; # inner pane
625 print '</div>'; # border container
1395083e
AD
626 print "</form>";
627
628 print "</div>"; #pane
27211afe 629
6065f3ad
AD
630 global $pluginhost;
631 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
632 "hook_prefs_tab", "prefPrefs");
633
1395083e
AD
634 print "</div>"; #container
635 }
27211afe 636
f9ebb32c
AD
637 function toggleAdvanced() {
638 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
639 }
fb70f26e
AD
640
641 function otpqrcode() {
642 require_once "lib/otphp/vendor/base32.php";
643 require_once "lib/otphp/lib/otp.php";
644 require_once "lib/otphp/lib/totp.php";
645 require_once "lib/phpqrcode/phpqrcode.php";
646
973392b9 647 $result = db_query($this->link, "SELECT login,salt,otp_enabled
fb70f26e
AD
648 FROM ttrss_users
649 WHERE id = ".$_SESSION["uid"]);
650
651 $base32 = new Base32();
652
653 $login = db_fetch_result($result, 0, "login");
973392b9 654 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
fb70f26e 655
973392b9
AD
656 if (!$otp_enabled) {
657 $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
658 $topt = new \OTPHP\TOTP($secret);
659 print QRcode::png($topt->provisioning_uri($login));
660 }
fb70f26e
AD
661 }
662
3ca8af7f
AD
663 function otpenable() {
664 $password = db_escape_string($_REQUEST["password"]);
665
666 $module_class = "auth_" . $_SESSION["auth_module"];
667 $authenticator = new $module_class($this->link);
668 $enable_otp = $_REQUEST["enable_otp"] == "on";
669
670 if ($authenticator->check_password($_SESSION["uid"], $password)) {
671
672 if ($enable_otp) {
673 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
674 id = " . $_SESSION["uid"]);
675
676 print "OK";
677 }
678 } else {
679 print "ERROR: ".__("Incorrect password");
680 }
fb70f26e 681
3ca8af7f
AD
682 }
683
684 function otpdisable() {
685 $password = db_escape_string($_REQUEST["password"]);
686
687 $module_class = "auth_" . $_SESSION["auth_module"];
688 $authenticator = new $module_class($this->link);
689
690 if ($authenticator->check_password($_SESSION["uid"], $password)) {
691
692 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE
fb70f26e 693 id = " . $_SESSION["uid"]);
3ca8af7f
AD
694
695 print "OK";
696 } else {
697 print "ERROR: ".__("Incorrect password");
fb70f26e 698 }
3ca8af7f 699
fb70f26e 700 }
1395083e
AD
701}
702?>