]> git.wh0rd.org - tt-rss.git/blob - classes/pref/prefs.php
only allow clearing data of active plugins
[tt-rss.git] / classes / pref / prefs.php
1 <?php
2 class Pref_Prefs extends Handler_Protected {
3
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index", "updateself");
6
7 return array_search($method, $csrf_ignored) !== false;
8 }
9
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
31 global $pluginhost;
32 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
33
34 if (method_exists($authenticator, "change_password")) {
35 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
36 } else {
37 print "ERROR: ".__("Function not supported by authentication module.");
38 }
39 }
40
41 function saveconfig() {
42
43 $_SESSION["prefs_cache"] = false;
44
45 foreach (array_keys($_POST) as $pref_name) {
46
47 $pref_name = db_escape_string($pref_name);
48 $value = db_escape_string($_POST[$pref_name]);
49
50 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
51 if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) {
52
53 db_query($this->link, "UPDATE ttrss_users SET
54 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
55
56 }
57 }
58
59 set_pref($this->link, $pref_name, $value);
60
61 }
62
63 print __("The configuration was saved.");
64 }
65
66 function getHelp() {
67
68 $pref_name = db_escape_string($_REQUEST["pn"]);
69
70 $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs
71 WHERE pref_name = '$pref_name'");
72
73 if (db_num_rows($result) > 0) {
74 $help_text = db_fetch_result($result, 0, "help_text");
75 print $help_text;
76 } else {
77 printf(__("Unknown option: %s"), $pref_name);
78 }
79 }
80
81 function changeemail() {
82
83 $email = db_escape_string($_POST["email"]);
84 $full_name = db_escape_string($_POST["full_name"]);
85
86 $active_uid = $_SESSION["uid"];
87
88 db_query($this->link, "UPDATE ttrss_users SET email = '$email',
89 full_name = '$full_name' WHERE id = '$active_uid'");
90
91 print __("Your personal data has been saved.");
92
93 return;
94 }
95
96 function resetconfig() {
97
98 $_SESSION["prefs_op_result"] = "reset-to-defaults";
99
100 if ($_SESSION["profile"]) {
101 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
102 } else {
103 $profile_qpart = "profile IS NULL";
104 }
105
106 db_query($this->link, "DELETE FROM ttrss_user_prefs
107 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
108
109 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
110
111 print "PREFS_THEME_CHANGED";
112 }
113
114 function index() {
115
116 global $access_level_names;
117
118 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
119 "STRIP_UNSAFE_TAGS");
120
121 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
122 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
123 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
124 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
125 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
126
127
128 $_SESSION["prefs_op_result"] = "";
129
130 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
131 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
132
133 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
134
135 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
136 evt.preventDefault();
137 if (this.validate()) {
138 notify_progress('Saving data...', true);
139
140 new Ajax.Request('backend.php', {
141 parameters: dojo.objectToQuery(this.getValues()),
142 onComplete: function(transport) {
143 notify_callback2(transport);
144 } });
145
146 }
147 </script>";
148
149 print "<table width=\"100%\" class=\"prefPrefsList\">";
150
151 print "<h2>" . __("Personal data") . "</h2>";
152
153 $result = db_query($this->link, "SELECT email,full_name,otp_enabled,
154 access_level FROM ttrss_users
155 WHERE id = ".$_SESSION["uid"]);
156
157 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
158 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
159 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
160
161 print "<tr><td width=\"40%\">".__('Full name')."</td>";
162 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
163 value=\"$full_name\"></td></tr>";
164
165 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
166 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
167
168 if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
169
170 $access_level = db_fetch_result($result, 0, "access_level");
171 print "<tr><td width=\"40%\">".__('Access level')."</td>";
172 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
173 }
174
175 print "</table>";
176
177 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
178 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
179
180 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
181 __("Save data")."</button>";
182
183 print "</form>";
184
185 if ($_SESSION["auth_module"]) {
186 global $pluginhost;
187
188 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
189
190 } else {
191 $authenticator = false;
192 }
193
194 if ($authenticator && method_exists($authenticator, "change_password")) {
195
196 print "<h2>" . __("Password") . "</h2>";
197
198 $result = db_query($this->link, "SELECT id FROM ttrss_users
199 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
200 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
201
202 if (db_num_rows($result) != 0) {
203 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
204 }
205
206 print "<form dojoType=\"dijit.form.Form\">";
207
208 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
209 evt.preventDefault();
210 if (this.validate()) {
211 notify_progress('Changing password...', true);
212
213 new Ajax.Request('backend.php', {
214 parameters: dojo.objectToQuery(this.getValues()),
215 onComplete: function(transport) {
216 notify('');
217 if (transport.responseText.indexOf('ERROR: ') == 0) {
218 notify_error(transport.responseText.replace('ERROR: ', ''));
219 } else {
220 notify_info(transport.responseText);
221 var warn = $('default_pass_warning');
222 if (warn) Element.hide(warn);
223 }
224 }});
225 this.reset();
226 }
227 </script>";
228
229 if ($otp_enabled) {
230 print_notice("Changing your current password will disable OTP.");
231 }
232
233 print "<table width=\"100%\" class=\"prefPrefsList\">";
234
235 print "<tr><td width=\"40%\">".__("Old password")."</td>";
236 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
237
238 print "<tr><td width=\"40%\">".__("New password")."</td>";
239
240 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
241 name=\"new_password\"></td></tr>";
242
243 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
244
245 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
246
247 print "</table>";
248
249 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
250 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
251
252 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
253 __("Change password")."</button>";
254
255 print "</form>";
256
257 if ($_SESSION["auth_module"] == "auth_internal") {
258
259 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
260
261 if ($otp_enabled) {
262
263 print_notice("One time passwords are currently enabled. Enter your current password below to disable.");
264
265 print "<form dojoType=\"dijit.form.Form\">";
266
267 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
268 evt.preventDefault();
269 if (this.validate()) {
270 notify_progress('Disabling OTP', true);
271
272 new Ajax.Request('backend.php', {
273 parameters: dojo.objectToQuery(this.getValues()),
274 onComplete: function(transport) {
275 notify('');
276 if (transport.responseText.indexOf('ERROR: ') == 0) {
277 notify_error(transport.responseText.replace('ERROR: ', ''));
278 } else {
279 window.location.reload();
280 }
281 }});
282 this.reset();
283 }
284 </script>";
285
286 print "<table width=\"100%\" class=\"prefPrefsList\">";
287
288 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
289
290 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
291 name=\"password\"></td></tr>";
292
293 print "</table>";
294
295 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
296 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
297
298 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
299 __("Disable OTP")."</button>";
300
301 print "</form>";
302
303 } else {
304
305 print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
306
307 print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
308
309 $csrf_token = $_SESSION["csrf_token"];
310
311 print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
312
313 print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
314
315 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
316 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
317
318 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
319 evt.preventDefault();
320 if (this.validate()) {
321 notify_progress('Saving data...', true);
322
323 new Ajax.Request('backend.php', {
324 parameters: dojo.objectToQuery(this.getValues()),
325 onComplete: function(transport) {
326 notify('');
327 if (transport.responseText.indexOf('ERROR: ') == 0) {
328 notify_error(transport.responseText.replace('ERROR: ', ''));
329 } else {
330 window.location.reload();
331 }
332 } });
333
334 }
335 </script>";
336
337 print "<table width=\"100%\" class=\"prefPrefsList\">";
338
339 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
340
341 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
342 name=\"password\"></td></tr>";
343
344 print "<tr><td colspan=\"2\">";
345
346 print "<input dojoType=\"dijit.form.CheckBox\" required=\"1\"
347 type=\"checkbox\" id=\"enable_otp\" name=\"enable_otp\"/> ";
348 print "<label for=\"enable_otp\">".__("I have scanned the code and would like to enable OTP")."</label>";
349
350 print "</td></tr><tr><td colspan=\"2\">";
351
352 print "</td></tr>";
353 print "</table>";
354
355 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
356 __("Enable OTP")."</button>";
357
358 print "</form>";
359
360 }
361
362 }
363 }
364
365 global $pluginhost;
366 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
367 "hook_prefs_tab_section", "prefPrefsAuth");
368
369 print "</div>"; #pane
370
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
409 if ($_SESSION["prefs_show_advanced"])
410 $access_query = "true";
411 else
412 $access_query = "(access_level = 0 AND section_id != 3)";
413
414 $result = db_query($this->link, "SELECT DISTINCT
415 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
416 ttrss_prefs_sections.order_id,
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
423 $access_query AND
424 short_desc != '' AND
425 owner_uid = ".$_SESSION["uid"]."
426 ORDER BY ttrss_prefs_sections.order_id,short_desc");
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 $lnum = 0;
456 }
457
458 print "<tr>";
459
460 $type_name = $line["type_name"];
461 $pref_name = $line["pref_name"];
462 $value = $line["value"];
463 $def_value = $line["def_value"];
464 $help_text = $line["help_text"];
465
466 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
467
468 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
469
470 print "</td>";
471
472 print "<td class=\"prefValue\">";
473
474 if ($pref_name == "USER_TIMEZONE") {
475
476 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
477
478 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
479 } else if ($pref_name == "USER_STYLESHEET") {
480
481 print "<button dojoType=\"dijit.form.Button\"
482 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
483
484 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
485
486 $limits = array(15, 30, 45, 60);
487
488 print_select($pref_name, $value, $limits,
489 'dojoType="dijit.form.Select"');
490
491 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
492
493 global $update_intervals_nodefault;
494
495 print_select_hash($pref_name, $value, $update_intervals_nodefault,
496 'dojoType="dijit.form.Select"');
497
498 } else if ($type_name == "bool") {
499
500 if ($value == "true") {
501 $value = __("Yes");
502 } else {
503 $value = __("No");
504 }
505
506 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
507 $disabled = "disabled=\"1\"";
508 $value = __("Yes");
509 } else {
510 $disabled = "";
511 }
512
513 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
514 $disabled);
515
516 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
517 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
518
519 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
520
521 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
522 $disabled = "disabled=\"1\"";
523 $value = FORCE_ARTICLE_PURGE;
524 } else {
525 $disabled = "";
526 }
527
528 print "<input dojoType=\"dijit.form.ValidationTextBox\"
529 required=\"1\" $regexp $disabled
530 name=\"$pref_name\" value=\"$value\">";
531
532 } else if ($pref_name == "SSL_CERT_SERIAL") {
533
534 print "<input dojoType=\"dijit.form.ValidationTextBox\"
535 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
536 name=\"$pref_name\" value=\"$value\">";
537
538 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
539 $has_serial = ($cert_serial) ? "false" : "true";
540
541 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
542 onclick=\"insertSSLserial('$cert_serial')\">" .
543 __('Register') . "</button>";
544
545 print " <button dojoType=\"dijit.form.Button\"
546 onclick=\"insertSSLserial('')\">" .
547 __('Clear') . "</button>";
548
549 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
550 print "<input dojoType=\"dijit.form.ValidationTextBox\"
551 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
552 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
553 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
554 } else {
555 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
556
557 print "<input dojoType=\"dijit.form.ValidationTextBox\"
558 $regexp
559 name=\"$pref_name\" value=\"$value\">";
560 }
561
562 print "</td>";
563
564 print "</tr>";
565
566 $lnum++;
567 }
568
569 print "</table>";
570
571 global $pluginhost;
572 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
573 "hook_prefs_tab_section", "prefPrefsPrefsInside");
574
575 print '</div>'; # inside pane
576 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
577
578 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
579 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
580
581 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
582 __('Save configuration')."</button> ";
583
584 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
585 __('Manage profiles')."</button> ";
586
587 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
588 __('Reset to defaults')."</button>";
589
590 print "&nbsp;";
591
592 $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
593
594 print "<input onclick='toggleAdvancedPrefs()'
595 id='prefs_show_advanced'
596 dojoType=\"dijit.form.CheckBox\"
597 $checked
598 type=\"checkbox\"></input>
599 <label for='prefs_show_advanced'>" .
600 __("Show additional preferences") . "</label>";
601
602 global $pluginhost;
603 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
604 "hook_prefs_tab_section", "prefPrefsPrefsOutside");
605
606 print "</form>";
607 print '</div>'; # inner pane
608 print '</div>'; # border container
609
610 print "</div>"; #pane
611
612 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
613
614 print "<h2>".__("Plugins")."</h2>";
615
616 print_notice("You will need to reload Tiny Tiny RSS for plugin changes to take effect.");
617
618 print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
619
620 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
621 evt.preventDefault();
622 if (this.validate()) {
623 notify_progress('Saving data...', true);
624
625 new Ajax.Request('backend.php', {
626 parameters: dojo.objectToQuery(this.getValues()),
627 onComplete: function(transport) {
628 notify('');
629 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
630 window.location.reload();
631 }
632 } });
633
634 }
635 </script>";
636
637 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
638 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
639
640 print "<table width='100%' class='prefPluginsList'>";
641
642 print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
643
644 print "<tr class=\"title\">
645 <td width=\"5%\">&nbsp;</td>
646 <td width='10%'>".__('Plugin')."</td>
647 <td width=''>".__('Description')."</td>
648 <td width='5%'>".__('Version')."</td>
649 <td width='10%'>".__('Author')."</td></tr>";
650
651 $system_enabled = array_map("trim", explode(",", PLUGINS));
652 $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
653
654 $tmppluginhost = new PluginHost($this->link);
655 $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
656 $tmppluginhost->load_data(true);
657
658 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
659 $about = $plugin->about();
660
661 if ($about[3] && strpos($name, "example") === FALSE) {
662 if (in_array($name, $system_enabled)) {
663 $checked = "checked='1'";
664 } else {
665 $checked = "";
666 }
667
668 print "<tr>";
669
670 print "<td align='center'><input disabled='1'
671 dojoType=\"dijit.form.CheckBox\" $checked
672 type=\"checkbox\"></td>";
673
674 print "<td>$name</td>";
675 print "<td>" . htmlspecialchars($about[1]) . "</td>";
676 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
677 print "<td>" . htmlspecialchars($about[2]) . "</td>";
678
679 if (count($tmppluginhost->get_all($plugin)) > 0) {
680 if (in_array($name, $system_enabled)) {
681 print "<td><a href='#' onclick=\"clearPluginData('$name')\"
682 class='visibleLink'>".__("Clear data")."</a></td>";
683 }
684 }
685
686 print "</tr>";
687
688 }
689 }
690
691 print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
692
693 print "<tr class=\"title\">
694 <td width=\"5%\">&nbsp;</td>
695 <td width='10%'>".__('Plugin')."</td>
696 <td width=''>".__('Description')."</td>
697 <td width='5%'>".__('Version')."</td>
698 <td width='10%'>".__('Author')."</td></tr>";
699
700
701 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
702 $about = $plugin->about();
703
704 if (!$about[3] && strpos($name, "example") === FALSE) {
705
706 if (in_array($name, $system_enabled)) {
707 $checked = "checked='1'";
708 $disabled = "disabled='1'";
709 $rowclass = '';
710 } else if (in_array($name, $user_enabled)) {
711 $checked = "checked='1'";
712 $disabled = "";
713 $rowclass = "Selected";
714 } else {
715 $checked = "";
716 $disabled = "";
717 $rowclass = '';
718 }
719
720 print "<tr class='$rowclass'>";
721
722 print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
723 dojoType=\"dijit.form.CheckBox\" $checked $disabled
724 type=\"checkbox\"></td>";
725
726 print "<td><label for='FPCHK-$name'>$name</label></td>";
727 print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label></td>";
728 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
729 print "<td>" . htmlspecialchars($about[2]) . "</td>";
730
731 if (count($tmppluginhost->get_all($plugin)) > 0) {
732 if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
733 print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
734 }
735 }
736
737 print "</tr>";
738
739
740
741 }
742
743 }
744
745 print "</table>";
746
747 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
748 __("Enable selected plugins")."</button></p>";
749
750 print "</form>";
751
752 print "</div>"; #pane
753
754 global $pluginhost;
755 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
756 "hook_prefs_tab", "prefPrefs");
757
758 print "</div>"; #container
759 }
760
761 function toggleAdvanced() {
762 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
763 }
764
765 function otpqrcode() {
766 require_once "lib/otphp/vendor/base32.php";
767 require_once "lib/otphp/lib/otp.php";
768 require_once "lib/otphp/lib/totp.php";
769 require_once "lib/phpqrcode/phpqrcode.php";
770
771 $result = db_query($this->link, "SELECT login,salt,otp_enabled
772 FROM ttrss_users
773 WHERE id = ".$_SESSION["uid"]);
774
775 $base32 = new Base32();
776
777 $login = db_fetch_result($result, 0, "login");
778 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
779
780 if (!$otp_enabled) {
781 $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
782 $topt = new \OTPHP\TOTP($secret);
783 print QRcode::png($topt->provisioning_uri($login));
784 }
785 }
786
787 function otpenable() {
788 $password = db_escape_string($_REQUEST["password"]);
789 $enable_otp = $_REQUEST["enable_otp"] == "on";
790
791 global $pluginhost;
792 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
793
794 if ($authenticator->check_password($_SESSION["uid"], $password)) {
795
796 if ($enable_otp) {
797 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
798 id = " . $_SESSION["uid"]);
799
800 print "OK";
801 }
802 } else {
803 print "ERROR: ".__("Incorrect password");
804 }
805
806 }
807
808 function otpdisable() {
809 $password = db_escape_string($_REQUEST["password"]);
810
811 global $pluginhost;
812 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
813
814 if ($authenticator->check_password($_SESSION["uid"], $password)) {
815
816 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE
817 id = " . $_SESSION["uid"]);
818
819 print "OK";
820 } else {
821 print "ERROR: ".__("Incorrect password");
822 }
823
824 }
825
826 function setplugins() {
827 $plugins = join(",", $_REQUEST["plugins"]);
828
829 set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
830 }
831
832 function clearplugindata() {
833 $name = db_escape_string($_REQUEST["name"]);
834
835 global $pluginhost;
836 $pluginhost->clear_data($pluginhost->get_plugin($name));
837 }
838 }
839 ?>