]> git.wh0rd.org - tt-rss.git/blob - classes/pref/prefs.php
require entering current one time code to enable otp
[tt-rss.git] / classes / pref / prefs.php
1 <?php
2
3 class Pref_Prefs extends Handler_Protected {
4
5 private $pref_help = array();
6 private $pref_sections = array();
7
8 function csrf_ignore($method) {
9 $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles");
10
11 return array_search($method, $csrf_ignored) !== false;
12 }
13
14 function __construct($link, $args) {
15 parent::__construct($link, $args);
16
17 $this->pref_sections = array(
18 1 => __('General'),
19 2 => __('Interface'),
20 3 => __('Advanced'),
21 4 => __('Digest')
22 );
23
24 $this->pref_help = array(
25 "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""),
26 "AUTO_ASSIGN_LABELS" => array(__("Assign articles to labels automatically"), ""),
27 "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")),
28 "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")),
29 "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""),
30 "COMBINED_DISPLAY_MODE" => array(__("Combined feed display"), __("Display expanded list of feed articles, instead of separate displays for headlines and article content")),
31 "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feed as read"), ""),
32 "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once"), ""),
33 "DEFAULT_UPDATE_INTERVAL" => array(__("Default feed update interval"), __("Shortest interval at which a feed will be checked for updates regardless of update method")),
34 "DIGEST_CATCHUP" => array(__("Mark articles in e-mail digest as read"), ""),
35 "DIGEST_ENABLE" => array(__("Enable e-mail digest"), __("This option enables sending daily digest of new (and unread) headlines on your configured e-mail address")),
36 "DIGEST_PREFERRED_TIME" => array(__("Try to send digests around specified time"), __("Uses UTC timezone")),
37 "ENABLE_API_ACCESS" => array(__("Enable API access"), __("Allows external clients to access this account through the API")),
38 "ENABLE_FEED_CATS" => array(__("Enable feed categories"), ""),
39 "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""),
40 "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""),
41 "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""),
42 "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""),
43 "LONG_DATE_FORMAT" => array(__("Long date format"), ""),
44 "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")),
45 "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""),
46 "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""),
47 "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)"), ""),
48 "SHORT_DATE_FORMAT" => array(__("Short date format"), ""),
49 "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines list"), ""),
50 "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")),
51 "SSL_CERT_SERIAL" => array(__("Login with an SSL certificate"), __("Click to register your SSL client certificate with tt-rss")),
52 "STRIP_IMAGES" => array(__("Do not embed images in articles"), ""),
53 "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")),
54 "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
55 "USER_TIMEZONE" => array(__("User timezone"), ""),
56 "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
57 "USER_CSS_THEME" => array(__("Select theme"), __("Select one of the available CSS themes"))
58 );
59 }
60
61 function changepassword() {
62
63 $old_pw = $_POST["old_password"];
64 $new_pw = $_POST["new_password"];
65 $con_pw = $_POST["confirm_password"];
66
67 if ($old_pw == "") {
68 print "ERROR: ".__("Old password cannot be blank.");
69 return;
70 }
71
72 if ($new_pw == "") {
73 print "ERROR: ".__("New password cannot be blank.");
74 return;
75 }
76
77 if ($new_pw != $con_pw) {
78 print "ERROR: ".__("Entered passwords do not match.");
79 return;
80 }
81
82 global $pluginhost;
83 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
84
85 if (method_exists($authenticator, "change_password")) {
86 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
87 } else {
88 print "ERROR: ".__("Function not supported by authentication module.");
89 }
90 }
91
92 function saveconfig() {
93
94 $_SESSION["prefs_cache"] = false;
95
96 $boolean_prefs = explode(",", $_POST["boolean_prefs"]);
97
98 foreach ($boolean_prefs as $pref) {
99 if (!isset($_POST[$pref])) $_POST[$pref] = 'false';
100 }
101
102 $need_reload = false;
103
104 foreach (array_keys($_POST) as $pref_name) {
105
106 $pref_name = db_escape_string($this->link, $pref_name);
107 $value = db_escape_string($this->link, $_POST[$pref_name]);
108
109 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
110 if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) {
111
112 db_query($this->link, "UPDATE ttrss_users SET
113 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
114
115 }
116 }
117
118 if ($pref_name == "language") {
119 if ($_SESSION["language"] != $value) {
120 setcookie("ttrss_lang", $value,
121 time() + SESSION_COOKIE_LIFETIME);
122 $_SESSION["language"] = $value;
123
124 $need_reload = true;
125 }
126 } else {
127 set_pref($this->link, $pref_name, $value);
128 }
129
130 }
131
132 if ($need_reload) {
133 print "PREFS_NEED_RELOAD";
134 } else {
135 print __("The configuration was saved.");
136 }
137 }
138
139 function getHelp() {
140
141 $pref_name = db_escape_string($this->link, $_REQUEST["pn"]);
142
143 $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs
144 WHERE pref_name = '$pref_name'");
145
146 if (db_num_rows($result) > 0) {
147 $help_text = db_fetch_result($result, 0, "help_text");
148 print $help_text;
149 } else {
150 printf(__("Unknown option: %s"), $pref_name);
151 }
152 }
153
154 function changeemail() {
155
156 $email = db_escape_string($this->link, $_POST["email"]);
157 $full_name = db_escape_string($this->link, $_POST["full_name"]);
158
159 $active_uid = $_SESSION["uid"];
160
161 db_query($this->link, "UPDATE ttrss_users SET email = '$email',
162 full_name = '$full_name' WHERE id = '$active_uid'");
163
164 print __("Your personal data has been saved.");
165
166 return;
167 }
168
169 function resetconfig() {
170
171 $_SESSION["prefs_op_result"] = "reset-to-defaults";
172
173 if ($_SESSION["profile"]) {
174 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
175 } else {
176 $profile_qpart = "profile IS NULL";
177 }
178
179 db_query($this->link, "DELETE FROM ttrss_user_prefs
180 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
181
182 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
183
184 echo __("Your preferences are now set to default values.");
185 }
186
187 function index() {
188
189 global $access_level_names;
190
191 $prefs_blacklist = array("STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
192 "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT");
193
194 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
195
196 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
197 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
198 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
199 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
200 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
201
202
203 $_SESSION["prefs_op_result"] = "";
204
205 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
206 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
207
208 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
209
210 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
211 evt.preventDefault();
212 if (this.validate()) {
213 notify_progress('Saving data...', true);
214
215 new Ajax.Request('backend.php', {
216 parameters: dojo.objectToQuery(this.getValues()),
217 onComplete: function(transport) {
218 notify_callback2(transport);
219 } });
220
221 }
222 </script>";
223
224 print "<table width=\"100%\" class=\"prefPrefsList\">";
225
226 print "<h2>" . __("Personal data") . "</h2>";
227
228 $result = db_query($this->link, "SELECT email,full_name,otp_enabled,
229 access_level FROM ttrss_users
230 WHERE id = ".$_SESSION["uid"]);
231
232 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
233 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
234 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
235
236 print "<tr><td width=\"40%\">".__('Full name')."</td>";
237 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
238 value=\"$full_name\"></td></tr>";
239
240 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
241 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
242
243 if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
244
245 $access_level = db_fetch_result($result, 0, "access_level");
246 print "<tr><td width=\"40%\">".__('Access level')."</td>";
247 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
248 }
249
250 print "</table>";
251
252 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
253 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
254
255 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
256 __("Save data")."</button>";
257
258 print "</form>";
259
260 if ($_SESSION["auth_module"]) {
261 global $pluginhost;
262
263 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
264
265 } else {
266 $authenticator = false;
267 }
268
269 if ($authenticator && method_exists($authenticator, "change_password")) {
270
271 print "<h2>" . __("Password") . "</h2>";
272
273 $result = db_query($this->link, "SELECT id FROM ttrss_users
274 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
275 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
276
277 if (db_num_rows($result) != 0) {
278 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
279 }
280
281 print "<form dojoType=\"dijit.form.Form\">";
282
283 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
284 evt.preventDefault();
285 if (this.validate()) {
286 notify_progress('Changing password...', true);
287
288 new Ajax.Request('backend.php', {
289 parameters: dojo.objectToQuery(this.getValues()),
290 onComplete: function(transport) {
291 notify('');
292 if (transport.responseText.indexOf('ERROR: ') == 0) {
293 notify_error(transport.responseText.replace('ERROR: ', ''));
294 } else {
295 notify_info(transport.responseText);
296 var warn = $('default_pass_warning');
297 if (warn) Element.hide(warn);
298 }
299 }});
300 this.reset();
301 }
302 </script>";
303
304 if ($otp_enabled) {
305 print_notice(__("Changing your current password will disable OTP."));
306 }
307
308 print "<table width=\"100%\" class=\"prefPrefsList\">";
309
310 print "<tr><td width=\"40%\">".__("Old password")."</td>";
311 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
312
313 print "<tr><td width=\"40%\">".__("New password")."</td>";
314
315 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
316 name=\"new_password\"></td></tr>";
317
318 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
319
320 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
321
322 print "</table>";
323
324 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
325 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
326
327 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
328 __("Change password")."</button>";
329
330 print "</form>";
331
332 if ($_SESSION["auth_module"] == "auth_internal") {
333
334 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
335
336 if ($otp_enabled) {
337
338 print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
339
340 print "<form dojoType=\"dijit.form.Form\">";
341
342 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
343 evt.preventDefault();
344 if (this.validate()) {
345 notify_progress('Disabling OTP', true);
346
347 new Ajax.Request('backend.php', {
348 parameters: dojo.objectToQuery(this.getValues()),
349 onComplete: function(transport) {
350 notify('');
351 if (transport.responseText.indexOf('ERROR: ') == 0) {
352 notify_error(transport.responseText.replace('ERROR: ', ''));
353 } else {
354 window.location.reload();
355 }
356 }});
357 this.reset();
358 }
359 </script>";
360
361 print "<table width=\"100%\" class=\"prefPrefsList\">";
362
363 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
364
365 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
366 name=\"password\"></td></tr>";
367
368 print "</table>";
369
370 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
371 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
372
373 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
374 __("Disable OTP")."</button>";
375
376 print "</form>";
377
378 } else {
379
380 print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
381
382 print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
383
384 $csrf_token = $_SESSION["csrf_token"];
385
386 print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
387
388 print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
389
390 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
391 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
392
393 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
394 evt.preventDefault();
395 if (this.validate()) {
396 notify_progress('Saving data...', true);
397
398 new Ajax.Request('backend.php', {
399 parameters: dojo.objectToQuery(this.getValues()),
400 onComplete: function(transport) {
401 notify('');
402 if (transport.responseText.indexOf('ERROR:') == 0) {
403 notify_error(transport.responseText.replace('ERROR:', ''));
404 } else {
405 window.location.reload();
406 }
407 } });
408
409 }
410 </script>";
411
412 print "<table width=\"100%\" class=\"prefPrefsList\">";
413
414 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
415
416 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
417 name=\"password\"></td></tr>";
418
419 print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
420
421 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
422 required=\"1\"
423 name=\"otp\"></td></tr>";
424
425 print "<tr><td colspan=\"2\">";
426
427 print "</td></tr><tr><td colspan=\"2\">";
428
429 print "</td></tr>";
430 print "</table>";
431
432 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
433 __("Enable OTP")."</button>";
434
435 print "</form>";
436
437 }
438
439 }
440 }
441
442 global $pluginhost;
443 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
444 "hook_prefs_tab_section", "prefPrefsAuth");
445
446 print "</div>"; #pane
447
448 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
449
450 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
451
452 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\">
453 if (evt) evt.preventDefault();
454 if (this.validate()) {
455 console.log(dojo.objectToQuery(this.getValues()));
456
457 new Ajax.Request('backend.php', {
458 parameters: dojo.objectToQuery(this.getValues()),
459 onComplete: function(transport) {
460 var msg = transport.responseText;
461 if (quit) {
462 gotoMain();
463 } else {
464 if (msg == 'PREFS_NEED_RELOAD') {
465 window.location.reload();
466 } else {
467 notify_info(msg);
468 }
469 }
470 } });
471 }
472 </script>";
473
474 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
475
476 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
477
478 if ($_SESSION["profile"]) {
479 print_notice(__("Some preferences are only available in default profile."));
480 }
481
482 if ($_SESSION["profile"]) {
483 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
484 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
485 } else {
486 initialize_user_prefs($this->link, $_SESSION["uid"]);
487 $profile_qpart = "profile IS NULL";
488 }
489
490 /* if ($_SESSION["prefs_show_advanced"])
491 $access_query = "true";
492 else
493 $access_query = "(access_level = 0 AND section_id != 3)"; */
494
495 $access_query = 'true';
496
497 $result = db_query($this->link, "SELECT DISTINCT
498 ttrss_user_prefs.pref_name,value,type_name,
499 ttrss_prefs_sections.order_id,
500 def_value,section_id
501 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
502 WHERE type_id = ttrss_prefs_types.id AND
503 $profile_qpart AND
504 section_id = ttrss_prefs_sections.id AND
505 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
506 $access_query AND
507 owner_uid = ".$_SESSION["uid"]."
508 ORDER BY ttrss_prefs_sections.order_id,pref_name");
509
510 $lnum = 0;
511
512 $active_section = "";
513
514 $listed_boolean_prefs = array();
515
516 while ($line = db_fetch_assoc($result)) {
517
518 if (in_array($line["pref_name"], $prefs_blacklist)) {
519 continue;
520 }
521
522 $type_name = $line["type_name"];
523 $pref_name = $line["pref_name"];
524 $section_name = $this->getSectionName($line["section_id"]);
525 $value = $line["value"];
526
527 $short_desc = $this->getShortDesc($pref_name);
528 $help_text = $this->getHelpText($pref_name);
529
530 if (!$short_desc) continue;
531
532 if ($_SESSION["profile"] && in_array($line["pref_name"],
533 $profile_blacklist)) {
534 continue;
535 }
536
537 if ($active_section != $line["section_id"]) {
538
539 if ($active_section != "") {
540 print "</table>";
541 }
542
543 print "<table width=\"100%\" class=\"prefPrefsList\">";
544
545 $active_section = $line["section_id"];
546
547 print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
548
549 $lnum = 0;
550
551 if ($active_section == 2) {
552 print "<tr>";
553
554 print "<td width=\"40%\" class=\"prefName\">";
555 print "<label>";
556 print __("Language:");
557 print "</label>";
558
559 print "<td>";
560 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
561 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
562 print "</td>";
563 print "</tr>";
564 }
565
566 }
567
568 print "<tr>";
569
570 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
571 print "<label for='CB_$pref_name'>";
572 print $short_desc;
573 print "</label>";
574
575 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
576
577 print "</td>";
578
579 print "<td class=\"prefValue\">";
580
581 if ($pref_name == "USER_TIMEZONE") {
582
583 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
584
585 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
586 } else if ($pref_name == "USER_STYLESHEET") {
587
588 print "<button dojoType=\"dijit.form.Button\"
589 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
590
591 } else if ($pref_name == "USER_CSS_THEME") {
592
593 $themes = array_map("basename", glob("themes/*.css"));
594
595 print_select($pref_name, $value, $themes,
596 'dojoType="dijit.form.Select"');
597
598
599 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
600
601 global $update_intervals_nodefault;
602
603 print_select_hash($pref_name, $value, $update_intervals_nodefault,
604 'dojoType="dijit.form.Select"');
605
606 } else if ($type_name == "bool") {
607
608 array_push($listed_boolean_prefs, $pref_name);
609
610 $checked = ($value == "true") ? "checked=\"checked\"" : "";
611
612 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
613 $disabled = "disabled=\"1\"";
614 $checked = "checked=\"checked\"";
615 } else {
616 $disabled = "";
617 }
618
619 print "<input type='checkbox' name='$pref_name' $checked $disabled
620 dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
621
622 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
623 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
624
625 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
626
627 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
628 $disabled = "disabled=\"1\"";
629 $value = FORCE_ARTICLE_PURGE;
630 } else {
631 $disabled = "";
632 }
633
634 print "<input dojoType=\"dijit.form.ValidationTextBox\"
635 required=\"1\" $regexp $disabled
636 name=\"$pref_name\" value=\"$value\">";
637
638 } else if ($pref_name == "SSL_CERT_SERIAL") {
639
640 print "<input dojoType=\"dijit.form.ValidationTextBox\"
641 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
642 name=\"$pref_name\" value=\"$value\">";
643
644 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
645 $has_serial = ($cert_serial) ? "false" : "true";
646
647 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
648 onclick=\"insertSSLserial('$cert_serial')\">" .
649 __('Register') . "</button>";
650
651 print " <button dojoType=\"dijit.form.Button\"
652 onclick=\"insertSSLserial('')\">" .
653 __('Clear') . "</button>";
654
655 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
656 print "<input dojoType=\"dijit.form.ValidationTextBox\"
657 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
658 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
659 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
660 } else {
661 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
662
663 print "<input dojoType=\"dijit.form.ValidationTextBox\"
664 $regexp
665 name=\"$pref_name\" value=\"$value\">";
666 }
667
668 print "</td>";
669
670 print "</tr>";
671
672 $lnum++;
673 }
674
675 print "</table>";
676
677 $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
678
679 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
680
681 global $pluginhost;
682 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
683 "hook_prefs_tab_section", "prefPrefsPrefsInside");
684
685 print '</div>'; # inside pane
686 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
687
688 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
689 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
690
691 print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\">
692 <span>".__('Save configuration')."</span>
693 <div dojoType=\"dijit.DropDownMenu\">
694 <div dojoType=\"dijit.MenuItem\"
695 onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
696 __("Save and exit preferences")."</div>
697 </div>
698 </div>";
699
700 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
701 __('Manage profiles')."</button> ";
702
703 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
704 __('Reset to defaults')."</button>";
705
706 print "&nbsp;";
707
708 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
709
710 print "<input onclick='toggleAdvancedPrefs()'
711 id='prefs_show_advanced'
712 dojoType=\"dijit.form.CheckBox\"
713 $checked
714 type=\"checkbox\"></input>
715 <label for='prefs_show_advanced'>" .
716 __("Show additional preferences") . "</label>"; */
717
718 global $pluginhost;
719 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
720 "hook_prefs_tab_section", "prefPrefsPrefsOutside");
721
722 print "</form>";
723 print '</div>'; # inner pane
724 print '</div>'; # border container
725
726 print "</div>"; #pane
727
728 if ($_SESSION["access_level"] == 10) {
729
730 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Error Log')."\">";
731 print "<h2>".__("Error Log")."</h2>";
732
733 $result = db_query($this->link, "SELECT errno, errstr, filename, lineno,
734 created_at, login FROM ttrss_error_log
735 LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id)
736 ORDER BY ttrss_error_log.id DESC
737 LIMIT 100");
738
739 print "<p><table width=\"100%\" cellspacing=\"10\" class=\"prefErrorLog\">";
740
741 print "<tr class=\"title\">
742 <td width='5%'>".__("Error")."</td>
743 <td>".__("Filename")."</td>
744 <td>".__("Message")."</td>
745 <td width='5%'>".__("User")."</td>
746 <td width='5%'>".__("Date")."</td>
747 </tr>";
748
749 while ($line = db_fetch_assoc($result)) {
750 print "<tr class=\"errrow\">";
751
752 foreach ($line as $k => $v) {
753 $line[$k] = htmlspecialchars($v);
754 }
755
756 print "<td class='errno'>" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")</td>";
757 print "<td class='filename'>" . $line["filename"] . ":" . $line["lineno"] . "</td>";
758 print "<td class='errstr'>" . $line["errstr"] . "</td>";
759 print "<td class='login'>" . $line["login"] . "</td>";
760
761 print "<td class='timestamp'>" .
762 make_local_datetime($this->link,
763 $line["created_at"], false) . "</td>";
764
765 print "</tr>";
766 }
767
768 print "</table>";
769
770 print "</div>";
771 }
772
773 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
774
775 print "<h2>".__("Plugins")."</h2>";
776
777 print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
778
779 print_notice(__("Download more plugins at tt-rss.org <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/forum/viewforum.php?f=22\">forums</a> or <a target=\"_blank\" class=\"visibleLink\" href=\"http://tt-rss.org/wiki/Plugins\">wiki</a>."));
780
781 print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
782
783 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
784 evt.preventDefault();
785 if (this.validate()) {
786 notify_progress('Saving data...', true);
787
788 new Ajax.Request('backend.php', {
789 parameters: dojo.objectToQuery(this.getValues()),
790 onComplete: function(transport) {
791 notify('');
792 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
793 window.location.reload();
794 }
795 } });
796
797 }
798 </script>";
799
800 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
801 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
802
803 print "<table width='100%' class='prefPluginsList'>";
804
805 print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
806
807 print "<tr class=\"title\">
808 <td width=\"5%\">&nbsp;</td>
809 <td width='10%'>".__('Plugin')."</td>
810 <td width=''>".__('Description')."</td>
811 <td width='5%'>".__('Version')."</td>
812 <td width='10%'>".__('Author')."</td></tr>";
813
814 $system_enabled = array_map("trim", explode(",", PLUGINS));
815 $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
816
817 $tmppluginhost = new PluginHost($this->link);
818 $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
819 $tmppluginhost->load_data(true);
820
821 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
822 $about = $plugin->about();
823
824 if ($about[3] && strpos($name, "example") === FALSE) {
825 if (in_array($name, $system_enabled)) {
826 $checked = "checked='1'";
827 } else {
828 $checked = "";
829 }
830
831 print "<tr>";
832
833 print "<td align='center'><input disabled='1'
834 dojoType=\"dijit.form.CheckBox\" $checked
835 type=\"checkbox\"></td>";
836
837 print "<td>$name</td>";
838 print "<td>" . htmlspecialchars($about[1]);
839 if (@$about[4]) {
840 print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
841 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
842 }
843 print "</td>";
844 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
845 print "<td>" . htmlspecialchars($about[2]) . "</td>";
846
847 if (count($tmppluginhost->get_all($plugin)) > 0) {
848 if (in_array($name, $system_enabled)) {
849 print "<td><a href='#' onclick=\"clearPluginData('$name')\"
850 class='visibleLink'>".__("Clear data")."</a></td>";
851 }
852 }
853
854 print "</tr>";
855
856 }
857 }
858
859 print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
860
861 print "<tr class=\"title\">
862 <td width=\"5%\">&nbsp;</td>
863 <td width='10%'>".__('Plugin')."</td>
864 <td width=''>".__('Description')."</td>
865 <td width='5%'>".__('Version')."</td>
866 <td width='10%'>".__('Author')."</td></tr>";
867
868
869 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
870 $about = $plugin->about();
871
872 if (!$about[3] && strpos($name, "example") === FALSE) {
873
874 if (in_array($name, $system_enabled)) {
875 $checked = "checked='1'";
876 $disabled = "disabled='1'";
877 $rowclass = '';
878 } else if (in_array($name, $user_enabled)) {
879 $checked = "checked='1'";
880 $disabled = "";
881 $rowclass = "Selected";
882 } else {
883 $checked = "";
884 $disabled = "";
885 $rowclass = '';
886 }
887
888 print "<tr class='$rowclass'>";
889
890 print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
891 dojoType=\"dijit.form.CheckBox\" $checked $disabled
892 type=\"checkbox\"></td>";
893
894 print "<td><label for='FPCHK-$name'>$name</label></td>";
895 print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
896 if (@$about[4]) {
897 print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
898 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
899 }
900 print "</td>";
901
902 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
903 print "<td>" . htmlspecialchars($about[2]) . "</td>";
904
905 if (count($tmppluginhost->get_all($plugin)) > 0) {
906 if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
907 print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
908 }
909 }
910
911 print "</tr>";
912
913
914
915 }
916
917 }
918
919 print "</table>";
920
921 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
922 __("Enable selected plugins")."</button></p>";
923
924 print "</form>";
925
926 print "</div>"; #pane
927
928 global $pluginhost;
929 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
930 "hook_prefs_tab", "prefPrefs");
931
932 print "</div>"; #container
933 }
934
935 function toggleAdvanced() {
936 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
937 }
938
939 function otpqrcode() {
940 require_once "lib/otphp/vendor/base32.php";
941 require_once "lib/otphp/lib/otp.php";
942 require_once "lib/otphp/lib/totp.php";
943 require_once "lib/phpqrcode/phpqrcode.php";
944
945 $result = db_query($this->link, "SELECT login,salt,otp_enabled
946 FROM ttrss_users
947 WHERE id = ".$_SESSION["uid"]);
948
949 $base32 = new Base32();
950
951 $login = db_fetch_result($result, 0, "login");
952 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
953
954 if (!$otp_enabled) {
955 $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
956 $topt = new \OTPHP\TOTP($secret);
957 print QRcode::png($topt->provisioning_uri($login));
958 }
959 }
960
961 function otpenable() {
962 require_once "lib/otphp/vendor/base32.php";
963 require_once "lib/otphp/lib/otp.php";
964 require_once "lib/otphp/lib/totp.php";
965
966 $password = $_REQUEST["password"];
967 $otp = $_REQUEST["otp"];
968
969 global $pluginhost;
970 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
971
972 if ($authenticator->check_password($_SESSION["uid"], $password)) {
973
974 $result = db_query($this->link, "SELECT salt
975 FROM ttrss_users
976 WHERE id = ".$_SESSION["uid"]);
977
978 $base32 = new Base32();
979
980 $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
981 $topt = new \OTPHP\TOTP($secret);
982
983 $otp_check = $topt->now();
984
985 if ($otp == $otp_check) {
986 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
987 id = " . $_SESSION["uid"]);
988
989 print "OK";
990 } else {
991 print "ERROR:".__("Incorrect one time password");
992 }
993 } else {
994 print "ERROR:".__("Incorrect password");
995 }
996
997 }
998
999 function otpdisable() {
1000 $password = db_escape_string($this->link, $_REQUEST["password"]);
1001
1002 global $pluginhost;
1003 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
1004
1005 if ($authenticator->check_password($_SESSION["uid"], $password)) {
1006
1007 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE
1008 id = " . $_SESSION["uid"]);
1009
1010 print "OK";
1011 } else {
1012 print "ERROR: ".__("Incorrect password");
1013 }
1014
1015 }
1016
1017 function setplugins() {
1018 if (is_array($_REQUEST["plugins"]))
1019 $plugins = join(",", $_REQUEST["plugins"]);
1020 else
1021 $plugins = "";
1022
1023 set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
1024 }
1025
1026 function clearplugindata() {
1027 $name = db_escape_string($this->link, $_REQUEST["name"]);
1028
1029 global $pluginhost;
1030 $pluginhost->clear_data($pluginhost->get_plugin($name));
1031 }
1032
1033 function customizeCSS() {
1034 $value = get_pref($this->link, "USER_STYLESHEET");
1035
1036 $value = str_replace("<br/>", "\n", $value);
1037
1038 print_notice(T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "tt-rss.css"));
1039
1040 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1041 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">";
1042 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">";
1043
1044 print "<table width='100%'><tr><td>";
1045 print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
1046 style='font-size : 12px; width : 100%; height: 200px;'
1047 placeHolder='body#ttrssMain { font-size : 14px; };'
1048 name='value'>$value</textarea>";
1049 print "</td></tr></table>";
1050
1051 print "<div class='dlgButtons'>";
1052 print "<button dojoType=\"dijit.form.Button\"
1053 onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
1054 print "<button dojoType=\"dijit.form.Button\"
1055 onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
1056 print "</div>";
1057
1058 }
1059
1060 function editPrefProfiles() {
1061 print "<div dojoType=\"dijit.Toolbar\">";
1062
1063 print "<div dojoType=\"dijit.form.DropDownButton\">".
1064 "<span>" . __('Select')."</span>";
1065 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1066 print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
1067 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1068 print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
1069 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1070 print "</div></div>";
1071
1072 print "<div style=\"float : right\">";
1073
1074 print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
1075 required=\"1\">
1076 <button dojoType=\"dijit.form.Button\"
1077 onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
1078 __('Create profile')."</button></div>";
1079
1080 print "</div>";
1081
1082 $result = db_query($this->link, "SELECT title,id FROM ttrss_settings_profiles
1083 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1084
1085 print "<div class=\"prefProfileHolder\">";
1086
1087 print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
1088
1089 print "<table width=\"100%\" class=\"prefFeedProfileList\"
1090 cellspacing=\"0\" id=\"prefFeedProfileList\">";
1091
1092 print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
1093
1094 print "<td width='5%' align='center'><input
1095 id='FCATC-0'
1096 onclick='toggleSelectRow2(this);'
1097 dojoType=\"dijit.form.CheckBox\"
1098 type=\"checkbox\"></td>";
1099
1100 if (!$_SESSION["profile"]) {
1101 $is_active = __("(active)");
1102 } else {
1103 $is_active = "";
1104 }
1105
1106 print "<td><span>" .
1107 __("Default profile") . " $is_active</span></td>";
1108
1109 print "</tr>";
1110
1111 $lnum = 1;
1112
1113 while ($line = db_fetch_assoc($result)) {
1114
1115 $class = ($lnum % 2) ? "even" : "odd";
1116
1117 $profile_id = $line["id"];
1118 $this_row_id = "id=\"FCATR-$profile_id\"";
1119
1120 print "<tr class=\"placeholder\" $this_row_id>";
1121
1122 $edit_title = htmlspecialchars($line["title"]);
1123
1124 print "<td width='5%' align='center'><input
1125 onclick='toggleSelectRow2(this);'
1126 id='FCATC-$profile_id'
1127 dojoType=\"dijit.form.CheckBox\"
1128 type=\"checkbox\"></td>";
1129
1130 if ($_SESSION["profile"] == $line["id"]) {
1131 $is_active = __("(active)");
1132 } else {
1133 $is_active = "";
1134 }
1135
1136 print "<td><span dojoType=\"dijit.InlineEditBox\"
1137 width=\"300px\" autoSave=\"false\"
1138 profile-id=\"$profile_id\">" . $edit_title .
1139 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1140 var elem = this;
1141 dojo.xhrPost({
1142 url: 'backend.php',
1143 content: {op: 'rpc', method: 'saveprofile',
1144 value: this.value,
1145 id: this.srcNodeRef.getAttribute('profile-id')},
1146 load: function(response) {
1147 elem.attr('value', response);
1148 }
1149 });
1150 </script>
1151 </span> $is_active</td>";
1152
1153 print "</tr>";
1154
1155 ++$lnum;
1156 }
1157
1158 print "</table>";
1159 print "</form>";
1160 print "</div>";
1161
1162 print "<div class='dlgButtons'>
1163 <div style='float : left'>
1164 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
1165 __('Remove selected profiles')."</button>
1166 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
1167 __('Activate profile')."</button>
1168 </div>";
1169
1170 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
1171 __('Close this window')."</button>";
1172 print "</div>";
1173
1174 }
1175
1176 private function getShortDesc($pref_name) {
1177 if (isset($this->pref_help[$pref_name])) {
1178 return $this->pref_help[$pref_name][0];
1179 }
1180 return "";
1181 }
1182
1183 private function getHelpText($pref_name) {
1184 if (isset($this->pref_help[$pref_name])) {
1185 return $this->pref_help[$pref_name][1];
1186 }
1187 return "";
1188 }
1189
1190 private function getSectionName($id) {
1191 if (isset($this->pref_sections[$id])) {
1192 return $this->pref_sections[$id];
1193 }
1194
1195 return "";
1196 }
1197 }
1198 ?>