prefs.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. <?php
  2. class Pref_Prefs extends Handler_Protected {
  3. private $pref_help = array();
  4. private $pref_sections = array();
  5. function csrf_ignore($method) {
  6. $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles");
  7. return array_search($method, $csrf_ignored) !== false;
  8. }
  9. function __construct($args) {
  10. parent::__construct($args);
  11. $this->pref_sections = array(
  12. 1 => __('General'),
  13. 2 => __('Interface'),
  14. 3 => __('Advanced'),
  15. 4 => __('Digest')
  16. );
  17. $this->pref_help = array(
  18. "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""),
  19. "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")),
  20. "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")),
  21. "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""),
  22. "COMBINED_DISPLAY_MODE" => array(__("Combined feed display"), __("Display expanded list of feed articles, instead of separate displays for headlines and article content")),
  23. "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feed as read"), ""),
  24. "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once"), ""),
  25. "DEFAULT_UPDATE_INTERVAL" => array(__("Default feed update interval"), __("Shortest interval at which a feed will be checked for updates regardless of update method")),
  26. "DIGEST_CATCHUP" => array(__("Mark articles in e-mail digest as read"), ""),
  27. "DIGEST_ENABLE" => array(__("Enable e-mail digest"), __("This option enables sending daily digest of new (and unread) headlines on your configured e-mail address")),
  28. "DIGEST_PREFERRED_TIME" => array(__("Try to send digests around specified time"), __("Uses UTC timezone")),
  29. "ENABLE_API_ACCESS" => array(__("Enable API access"), __("Allows external clients to access this account through the API")),
  30. "ENABLE_FEED_CATS" => array(__("Enable feed categories"), ""),
  31. "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""),
  32. "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""),
  33. "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""),
  34. "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""),
  35. "LONG_DATE_FORMAT" => array(__("Long date format"), __("The syntax used is identical to the PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")),
  36. "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")),
  37. "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""),
  38. "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""),
  39. "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)"), ""),
  40. "SHORT_DATE_FORMAT" => array(__("Short date format"), ""),
  41. "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines list"), ""),
  42. "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")),
  43. "SSL_CERT_SERIAL" => array(__("Login with an SSL certificate"), __("Click to register your SSL client certificate with tt-rss")),
  44. "STRIP_IMAGES" => array(__("Do not embed images in articles"), ""),
  45. "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")),
  46. "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
  47. "USER_TIMEZONE" => array(__("Time zone"), ""),
  48. "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
  49. "USER_LANGUAGE" => array(__("Language")),
  50. "USER_CSS_THEME" => array(__("Theme"), __("Select one of the available CSS themes"))
  51. );
  52. }
  53. function changepassword() {
  54. $old_pw = $_POST["old_password"];
  55. $new_pw = $_POST["new_password"];
  56. $con_pw = $_POST["confirm_password"];
  57. if ($old_pw == "") {
  58. print "ERROR: ".format_error("Old password cannot be blank.");
  59. return;
  60. }
  61. if ($new_pw == "") {
  62. print "ERROR: ".format_error("New password cannot be blank.");
  63. return;
  64. }
  65. if ($new_pw != $con_pw) {
  66. print "ERROR: ".format_error("Entered passwords do not match.");
  67. return;
  68. }
  69. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  70. if (method_exists($authenticator, "change_password")) {
  71. print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw));
  72. } else {
  73. print "ERROR: ".format_error("Function not supported by authentication module.");
  74. }
  75. }
  76. function saveconfig() {
  77. $boolean_prefs = explode(",", $_POST["boolean_prefs"]);
  78. foreach ($boolean_prefs as $pref) {
  79. if (!isset($_POST[$pref])) $_POST[$pref] = 'false';
  80. }
  81. $need_reload = false;
  82. foreach (array_keys($_POST) as $pref_name) {
  83. $pref_name = $pref_name;
  84. $value = $_POST[$pref_name];
  85. if ($pref_name == 'DIGEST_PREFERRED_TIME') {
  86. if (get_pref('DIGEST_PREFERRED_TIME') != $value) {
  87. $sth = $this->pdo->prepare("UPDATE ttrss_users SET
  88. last_digest_sent = NULL WHERE id = ?");
  89. $sth->execute([$_SESSION['uid']]);
  90. }
  91. }
  92. if ($pref_name == "USER_LANGUAGE") {
  93. if ($_SESSION["language"] != $value) {
  94. $need_reload = true;
  95. }
  96. }
  97. set_pref($pref_name, $value);
  98. }
  99. if ($need_reload) {
  100. print "PREFS_NEED_RELOAD";
  101. } else {
  102. print __("The configuration was saved.");
  103. }
  104. }
  105. function changeemail() {
  106. $email = $_POST["email"];
  107. $full_name = $_POST["full_name"];
  108. $active_uid = $_SESSION["uid"];
  109. $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?,
  110. full_name = ? WHERE id = ?");
  111. $sth->execute([$email, $full_name, $active_uid]);
  112. print __("Your personal data has been saved.");
  113. return;
  114. }
  115. function resetconfig() {
  116. $_SESSION["prefs_op_result"] = "reset-to-defaults";
  117. $sth = $this->pdo->query("DELETE FROM ttrss_user_prefs
  118. WHERE (profile = :profile OR (:profile IS NULL AND profile IS NULL))
  119. AND owner_uid = :uid");
  120. $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]);
  121. initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
  122. echo __("Your preferences are now set to default values.");
  123. }
  124. function index() {
  125. global $access_level_names;
  126. $prefs_blacklist = array("ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
  127. "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT",
  128. "FEEDS_SORT_BY_UNREAD");
  129. /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
  130. $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
  131. "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
  132. "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
  133. "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
  134. "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
  135. $_SESSION["prefs_op_result"] = "";
  136. print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
  137. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
  138. print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
  139. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  140. evt.preventDefault();
  141. if (this.validate()) {
  142. notify_progress('Saving data...', true);
  143. new Ajax.Request('backend.php', {
  144. parameters: dojo.objectToQuery(this.getValues()),
  145. onComplete: function(transport) {
  146. notify_callback2(transport);
  147. } });
  148. }
  149. </script>";
  150. print "<table width=\"100%\" class=\"prefPrefsList\">";
  151. print "<h2>" . __("Personal data") . "</h2>";
  152. $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled,
  153. access_level FROM ttrss_users
  154. WHERE id = ?");
  155. $sth->execute([$_SESSION["uid"]]);
  156. $row = $sth->fetch();
  157. $email = htmlspecialchars($row["email"]);
  158. $full_name = htmlspecialchars($row["full_name"]);
  159. $otp_enabled = sql_bool_to_bool($row["otp_enabled"]);
  160. print "<tr><td width=\"40%\">".__('Full name')."</td>";
  161. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
  162. value=\"$full_name\"></td></tr>";
  163. print "<tr><td width=\"40%\">".__('E-mail')."</td>";
  164. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
  165. if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
  166. $access_level = $row["access_level"];
  167. print "<tr><td width=\"40%\">".__('Access level')."</td>";
  168. print "<td>" . $access_level_names[$access_level] . "</td></tr>";
  169. }
  170. print "</table>";
  171. print_hidden("op", "pref-prefs");
  172. print_hidden("method", "changeemail");
  173. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  174. __("Save data")."</button>";
  175. print "</form>";
  176. if ($_SESSION["auth_module"]) {
  177. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  178. } else {
  179. $authenticator = false;
  180. }
  181. if ($authenticator && method_exists($authenticator, "change_password")) {
  182. print "<h2>" . __("Password") . "</h2>";
  183. print "<div style='display : none' id='pwd_change_infobox'></div>";
  184. print "<form dojoType=\"dijit.form.Form\">";
  185. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  186. evt.preventDefault();
  187. if (this.validate()) {
  188. notify_progress('Changing password...', true);
  189. new Ajax.Request('backend.php', {
  190. parameters: dojo.objectToQuery(this.getValues()),
  191. onComplete: function(transport) {
  192. notify('');
  193. if (transport.responseText.indexOf('ERROR: ') == 0) {
  194. $('pwd_change_infobox').innerHTML =
  195. transport.responseText.replace('ERROR: ', '');
  196. } else {
  197. $('pwd_change_infobox').innerHTML =
  198. transport.responseText.replace('ERROR: ', '');
  199. var warn = $('default_pass_warning');
  200. if (warn) Element.hide(warn);
  201. }
  202. new Effect.Appear('pwd_change_infobox');
  203. }});
  204. this.reset();
  205. }
  206. </script>";
  207. if ($otp_enabled) {
  208. print_notice(__("Changing your current password will disable OTP."));
  209. }
  210. print "<table width=\"100%\" class=\"prefPrefsList\">";
  211. print "<tr><td width=\"40%\">".__("Old password")."</td>";
  212. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
  213. print "<tr><td width=\"40%\">".__("New password")."</td>";
  214. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  215. name=\"new_password\"></td></tr>";
  216. print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
  217. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
  218. print "</table>";
  219. print_hidden("op", "pref-prefs");
  220. print_hidden("method", "changepassword");
  221. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  222. __("Change password")."</button>";
  223. print "</form>";
  224. if ($_SESSION["auth_module"] == "auth_internal") {
  225. print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
  226. if ($otp_enabled) {
  227. print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
  228. print "<form dojoType=\"dijit.form.Form\">";
  229. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  230. evt.preventDefault();
  231. if (this.validate()) {
  232. notify_progress('Disabling OTP', true);
  233. new Ajax.Request('backend.php', {
  234. parameters: dojo.objectToQuery(this.getValues()),
  235. onComplete: function(transport) {
  236. notify('');
  237. if (transport.responseText.indexOf('ERROR: ') == 0) {
  238. notify_error(transport.responseText.replace('ERROR: ', ''));
  239. } else {
  240. window.location.reload();
  241. }
  242. }});
  243. this.reset();
  244. }
  245. </script>";
  246. print "<table width=\"100%\" class=\"prefPrefsList\">";
  247. print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
  248. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  249. name=\"password\"></td></tr>";
  250. print "</table>";
  251. print_hidden("op", "pref-prefs");
  252. print_hidden("method", "otpdisable");
  253. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  254. __("Disable OTP")."</button>";
  255. print "</form>";
  256. } else if (function_exists("imagecreatefromstring")) {
  257. print_warning(__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."));
  258. print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
  259. $csrf_token = $_SESSION["csrf_token"];
  260. print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
  261. print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
  262. print_hidden("op", "pref-prefs");
  263. print_hidden("method", "otpenable");
  264. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  265. evt.preventDefault();
  266. if (this.validate()) {
  267. notify_progress('Saving data...', true);
  268. new Ajax.Request('backend.php', {
  269. parameters: dojo.objectToQuery(this.getValues()),
  270. onComplete: function(transport) {
  271. notify('');
  272. if (transport.responseText.indexOf('ERROR:') == 0) {
  273. notify_error(transport.responseText.replace('ERROR:', ''));
  274. } else {
  275. window.location.reload();
  276. }
  277. } });
  278. }
  279. </script>";
  280. print "<table width=\"100%\" class=\"prefPrefsList\">";
  281. print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
  282. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  283. name=\"password\"></td></tr>";
  284. print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
  285. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
  286. required=\"1\"
  287. name=\"otp\"></td></tr>";
  288. print "<tr><td colspan=\"2\">";
  289. print "</td></tr><tr><td colspan=\"2\">";
  290. print "</td></tr>";
  291. print "</table>";
  292. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  293. __("Enable OTP")."</button>";
  294. print "</form>";
  295. } else {
  296. print_notice(__("PHP GD functions are required for OTP support."));
  297. }
  298. }
  299. }
  300. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  301. "hook_prefs_tab_section", "prefPrefsAuth");
  302. print "</div>"; #pane
  303. print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
  304. print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
  305. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\">
  306. if (evt) evt.preventDefault();
  307. if (this.validate()) {
  308. console.log(dojo.objectToQuery(this.getValues()));
  309. new Ajax.Request('backend.php', {
  310. parameters: dojo.objectToQuery(this.getValues()),
  311. onComplete: function(transport) {
  312. var msg = transport.responseText;
  313. if (quit) {
  314. gotoMain();
  315. } else {
  316. if (msg == 'PREFS_NEED_RELOAD') {
  317. window.location.reload();
  318. } else {
  319. notify_info(msg);
  320. }
  321. }
  322. } });
  323. }
  324. </script>";
  325. print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
  326. print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
  327. if ($_SESSION["profile"]) {
  328. print_notice(__("Some preferences are only available in default profile."));
  329. }
  330. if ($_SESSION["profile"]) {
  331. initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
  332. } else {
  333. initialize_user_prefs($_SESSION["uid"]);
  334. }
  335. $sth = $this->pdo->prepare("SELECT DISTINCT
  336. ttrss_user_prefs.pref_name,value,type_name,
  337. ttrss_prefs_sections.order_id,
  338. def_value,section_id
  339. FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
  340. WHERE type_id = ttrss_prefs_types.id AND
  341. (profile = :profile OR (:profile IS NULL AND profile IS NULL)) AND
  342. section_id = ttrss_prefs_sections.id AND
  343. ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
  344. owner_uid = :uid
  345. ORDER BY ttrss_prefs_sections.order_id,pref_name");
  346. $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $_SESSION['profile']]);
  347. $lnum = 0;
  348. $active_section = "";
  349. $listed_boolean_prefs = array();
  350. while ($line = $sth->fetch()) {
  351. if (in_array($line["pref_name"], $prefs_blacklist)) {
  352. continue;
  353. }
  354. $type_name = $line["type_name"];
  355. $pref_name = $line["pref_name"];
  356. $section_name = $this->getSectionName($line["section_id"]);
  357. $value = $line["value"];
  358. $short_desc = $this->getShortDesc($pref_name);
  359. $help_text = $this->getHelpText($pref_name);
  360. if (!$short_desc) continue;
  361. if ($_SESSION["profile"] && in_array($line["pref_name"],
  362. $profile_blacklist)) {
  363. continue;
  364. }
  365. if ($active_section != $line["section_id"]) {
  366. if ($active_section != "") {
  367. print "</table>";
  368. }
  369. print "<table width=\"100%\" class=\"prefPrefsList\">";
  370. $active_section = $line["section_id"];
  371. print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
  372. $lnum = 0;
  373. }
  374. print "<tr>";
  375. print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
  376. print "<label for='CB_$pref_name'>";
  377. print $short_desc;
  378. print "</label>";
  379. if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
  380. print "</td>";
  381. print "<td class=\"prefValue\">";
  382. if ($pref_name == "USER_LANGUAGE") {
  383. print_select_hash($pref_name, $value, get_translations(),
  384. "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
  385. } else if ($pref_name == "USER_TIMEZONE") {
  386. $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
  387. print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
  388. } else if ($pref_name == "USER_STYLESHEET") {
  389. print "<button dojoType=\"dijit.form.Button\"
  390. onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
  391. } else if ($pref_name == "USER_CSS_THEME") {
  392. $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css"));
  393. $themes = array_map("basename", $themes);
  394. $themes = array_filter($themes, "theme_valid");
  395. asort($themes);
  396. if (!theme_valid($value)) $value = "default.php";
  397. print_select($pref_name, $value, $themes,
  398. 'dojoType="dijit.form.Select"');
  399. } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
  400. global $update_intervals_nodefault;
  401. print_select_hash($pref_name, $value, $update_intervals_nodefault,
  402. 'dojoType="dijit.form.Select"');
  403. } else if ($type_name == "bool") {
  404. array_push($listed_boolean_prefs, $pref_name);
  405. $checked = ($value == "true") ? "checked=\"checked\"" : "";
  406. if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
  407. $disabled = "disabled=\"1\"";
  408. $checked = "checked=\"checked\"";
  409. } else {
  410. $disabled = "";
  411. }
  412. print "<input type='checkbox' name='$pref_name' $checked $disabled
  413. dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
  414. } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
  415. 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
  416. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  417. if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
  418. $disabled = "disabled=\"1\"";
  419. $value = FORCE_ARTICLE_PURGE;
  420. } else {
  421. $disabled = "";
  422. }
  423. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  424. required=\"1\" $regexp $disabled
  425. name=\"$pref_name\" value=\"$value\">";
  426. } else if ($pref_name == "SSL_CERT_SERIAL") {
  427. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  428. id=\"SSL_CERT_SERIAL\" readonly=\"1\"
  429. name=\"$pref_name\" value=\"$value\">";
  430. $cert_serial = htmlspecialchars(get_ssl_certificate_id());
  431. $has_serial = ($cert_serial) ? "false" : "true";
  432. print "<br/>";
  433. print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
  434. onclick=\"insertSSLserial('$cert_serial')\">" .
  435. __('Register') . "</button>";
  436. print " <button dojoType=\"dijit.form.Button\"
  437. onclick=\"insertSSLserial('')\">" .
  438. __('Clear') . "</button>";
  439. } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
  440. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  441. id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
  442. name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
  443. T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
  444. } else {
  445. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  446. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  447. $regexp
  448. name=\"$pref_name\" value=\"$value\">";
  449. }
  450. print "</td>";
  451. print "</tr>";
  452. $lnum++;
  453. }
  454. print "</table>";
  455. $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
  456. print_hidden("boolean_prefs", "$listed_boolean_prefs");
  457. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  458. "hook_prefs_tab_section", "prefPrefsPrefsInside");
  459. print '</div>'; # inside pane
  460. print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
  461. print_hidden("op", "pref-prefs");
  462. print_hidden("method", "saveconfig");
  463. print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\">
  464. <span>".__('Save configuration')."</span>
  465. <div dojoType=\"dijit.DropDownMenu\">
  466. <div dojoType=\"dijit.MenuItem\"
  467. onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
  468. __("Save and exit preferences")."</div>
  469. </div>
  470. </div>";
  471. print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
  472. __('Manage profiles')."</button> ";
  473. print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
  474. __('Reset to defaults')."</button>";
  475. print "&nbsp;";
  476. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  477. "hook_prefs_tab_section", "prefPrefsPrefsOutside");
  478. print "</form>";
  479. print '</div>'; # inner pane
  480. print '</div>'; # border container
  481. print "</div>"; #pane
  482. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
  483. print_notice(__("You will need to reload Tiny Tiny RSS for plugin changes to take effect."));
  484. if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) {
  485. print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly.");
  486. }
  487. print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
  488. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  489. evt.preventDefault();
  490. if (this.validate()) {
  491. notify_progress('Saving data...', true);
  492. new Ajax.Request('backend.php', {
  493. parameters: dojo.objectToQuery(this.getValues()),
  494. onComplete: function(transport) {
  495. notify('');
  496. if (confirm(__('Selected plugins have been enabled. Reload?'))) {
  497. window.location.reload();
  498. }
  499. } });
  500. }
  501. </script>";
  502. print_hidden("op", "pref-prefs");
  503. print_hidden("method", "setplugins");
  504. print "<table width='100%' class='prefPluginsList'>";
  505. print "<tr><td colspan='5'><h3>".__("System plugins")."</h3>".
  506. format_notice(__("System plugins are enabled in <strong>config.php</strong> for all users.")).
  507. "</td></tr>";
  508. print "<tr class=\"title\">
  509. <td width=\"5%\">&nbsp;</td>
  510. <td width='10%'>".__('Plugin')."</td>
  511. <td width=''>".__('Description')."</td>
  512. <td width='5%'>".__('Version')."</td>
  513. <td width='10%'>".__('Author')."</td></tr>";
  514. $system_enabled = array_map("trim", explode(",", PLUGINS));
  515. $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS", $_SESSION['uid'])));
  516. $tmppluginhost = new PluginHost();
  517. $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
  518. $tmppluginhost->load_data(true);
  519. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  520. $about = $plugin->about();
  521. if ($about[3]) {
  522. if (in_array($name, $system_enabled)) {
  523. $checked = "checked='1'";
  524. } else {
  525. $checked = "";
  526. }
  527. print "<tr>";
  528. print "<td align='center'><input disabled='1'
  529. dojoType=\"dijit.form.CheckBox\" $checked
  530. type=\"checkbox\"></td>";
  531. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  532. print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>";
  533. print "<td>" . htmlspecialchars($about[1]);
  534. if (@$about[4]) {
  535. print " &mdash; <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\"
  536. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  537. }
  538. print "</td>";
  539. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  540. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  541. if (count($tmppluginhost->get_all($plugin)) > 0) {
  542. if (in_array($name, $system_enabled)) {
  543. print "<td><a href='#' onclick=\"clearPluginData('$name')\"
  544. class='visibleLink'>".__("Clear data")."</a></td>";
  545. }
  546. }
  547. print "</tr>";
  548. }
  549. }
  550. print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
  551. print "<tr class=\"title\">
  552. <td width=\"5%\">&nbsp;</td>
  553. <td width='10%'>".__('Plugin')."</td>
  554. <td width=''>".__('Description')."</td>
  555. <td width='5%'>".__('Version')."</td>
  556. <td width='10%'>".__('Author')."</td></tr>";
  557. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  558. $about = $plugin->about();
  559. if (!$about[3]) {
  560. if (in_array($name, $system_enabled)) {
  561. $checked = "checked='1'";
  562. $disabled = "disabled='1'";
  563. $rowclass = '';
  564. } else if (in_array($name, $user_enabled)) {
  565. $checked = "checked='1'";
  566. $disabled = "";
  567. $rowclass = "Selected";
  568. } else {
  569. $checked = "";
  570. $disabled = "";
  571. $rowclass = '';
  572. }
  573. print "<tr class='$rowclass'>";
  574. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  575. print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
  576. dojoType=\"dijit.form.CheckBox\" $checked $disabled
  577. type=\"checkbox\"></td>";
  578. print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>";
  579. print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
  580. if (@$about[4]) {
  581. print " &mdash; <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\"
  582. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  583. }
  584. print "</td>";
  585. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  586. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  587. if (count($tmppluginhost->get_all($plugin)) > 0) {
  588. if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
  589. print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
  590. }
  591. }
  592. print "</tr>";
  593. }
  594. }
  595. print "</table>";
  596. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  597. __("Enable selected plugins")."</button></p>";
  598. print "</form>";
  599. print "</div>"; #pane
  600. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  601. "hook_prefs_tab", "prefPrefs");
  602. print "</div>"; #container
  603. }
  604. function toggleAdvanced() {
  605. $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
  606. }
  607. function otpqrcode() {
  608. require_once "lib/otphp/vendor/base32.php";
  609. require_once "lib/otphp/lib/otp.php";
  610. require_once "lib/otphp/lib/totp.php";
  611. require_once "lib/phpqrcode/phpqrcode.php";
  612. $sth = $this->pdo->prepare("SELECT login,salt,otp_enabled
  613. FROM ttrss_users
  614. WHERE id = ?");
  615. $sth->execute([$_SESSION['uid']]);
  616. if ($row = $sth->fetch()) {
  617. $base32 = new Base32();
  618. $login = $row["login"];
  619. $otp_enabled = sql_bool_to_bool($row["otp_enabled"]);
  620. if (!$otp_enabled) {
  621. $secret = $base32->encode(sha1($row["salt"]));
  622. QRcode::png("otpauth://totp/".urlencode($login).
  623. "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS"));
  624. }
  625. }
  626. }
  627. function otpenable() {
  628. require_once "lib/otphp/vendor/base32.php";
  629. require_once "lib/otphp/lib/otp.php";
  630. require_once "lib/otphp/lib/totp.php";
  631. $password = $_REQUEST["password"];
  632. $otp = $_REQUEST["otp"];
  633. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  634. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  635. $sth = $this->pdo->query("SELECT salt
  636. FROM ttrss_users
  637. WHERE id = ?");
  638. $sth->execute([$_SESSION['uid']]);
  639. if ($row = $sth->fetch()) {
  640. $base32 = new Base32();
  641. $secret = $base32->encode(sha1($row["salt"]));
  642. $topt = new \OTPHP\TOTP($secret);
  643. $otp_check = $topt->now();
  644. if ($otp == $otp_check) {
  645. $sth = $this->pdo->prepare("UPDATE ttrss_users
  646. SET otp_enabled = true WHERE id = ?");
  647. $sth->execute([$_SESSION['uid']]);
  648. print "OK";
  649. } else {
  650. print "ERROR:".__("Incorrect one time password");
  651. }
  652. }
  653. } else {
  654. print "ERROR:".__("Incorrect password");
  655. }
  656. }
  657. static function isdefaultpassword() {
  658. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  659. if ($authenticator->check_password($_SESSION["uid"], "password")) {
  660. return true;
  661. }
  662. return false;
  663. }
  664. function otpdisable() {
  665. $password = $_REQUEST["password"];
  666. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  667. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  668. $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE
  669. id = ?");
  670. $sth->execute([$_SESSION['uid']]);
  671. print "OK";
  672. } else {
  673. print "ERROR: ".__("Incorrect password");
  674. }
  675. }
  676. function setplugins() {
  677. if (is_array($_REQUEST["plugins"]))
  678. $plugins = join(",", $_REQUEST["plugins"]);
  679. else
  680. $plugins = "";
  681. set_pref("_ENABLED_PLUGINS", $plugins, $_SESSION["uid"]);
  682. }
  683. function clearplugindata() {
  684. $name = $_REQUEST["name"];
  685. PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
  686. }
  687. function customizeCSS() {
  688. $value = get_pref("USER_STYLESHEET");
  689. $value = str_replace("<br/>", "\n", $value);
  690. 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.", "css/tt-rss.css"));
  691. print_hidden("op", "rpc");
  692. print_hidden("method", "setpref");
  693. print_hidden("key", "USER_STYLESHEET");
  694. print "<table width='100%'><tr><td>";
  695. print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
  696. style='font-size : 12px; width : 98%; height: 200px;'
  697. placeHolder='body#ttrssMain { font-size : 14px; };'
  698. name='value'>$value</textarea>";
  699. print "</td></tr></table>";
  700. print "<div class='dlgButtons'>";
  701. print "<button dojoType=\"dijit.form.Button\"
  702. onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
  703. print "<button dojoType=\"dijit.form.Button\"
  704. onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
  705. print "</div>";
  706. }
  707. function editPrefProfiles() {
  708. print "<div dojoType=\"dijit.Toolbar\">";
  709. print "<div dojoType=\"dijit.form.DropDownButton\">".
  710. "<span>" . __('Select')."</span>";
  711. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  712. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
  713. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  714. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
  715. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  716. print "</div></div>";
  717. print "<div style=\"float : right\">";
  718. print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
  719. required=\"1\">
  720. <button dojoType=\"dijit.form.Button\"
  721. onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
  722. __('Create profile')."</button></div>";
  723. print "</div>";
  724. $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles
  725. WHERE owner_uid = ? ORDER BY title");
  726. $sth->execute([$_SESSION['uid']]);
  727. print "<div class=\"prefProfileHolder\">";
  728. print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
  729. print "<table width=\"100%\" class=\"prefFeedProfileList\"
  730. cellspacing=\"0\" id=\"prefFeedProfileList\">";
  731. print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
  732. print "<td width='5%' align='center'><input
  733. id='FCATC-0'
  734. onclick='toggleSelectRow2(this);'
  735. dojoType=\"dijit.form.CheckBox\"
  736. type=\"checkbox\"></td>";
  737. if (!$_SESSION["profile"]) {
  738. $is_active = __("(active)");
  739. } else {
  740. $is_active = "";
  741. }
  742. print "<td><span>" .
  743. __("Default profile") . " $is_active</span></td>";
  744. print "</tr>";
  745. $lnum = 1;
  746. while ($line = $sth->fetch()) {
  747. $profile_id = $line["id"];
  748. $this_row_id = "id=\"FCATR-$profile_id\"";
  749. print "<tr class=\"placeholder\" $this_row_id>";
  750. $edit_title = htmlspecialchars($line["title"]);
  751. print "<td width='5%' align='center'><input
  752. onclick='toggleSelectRow2(this);'
  753. id='FCATC-$profile_id'
  754. dojoType=\"dijit.form.CheckBox\"
  755. type=\"checkbox\"></td>";
  756. if ($_SESSION["profile"] == $line["id"]) {
  757. $is_active = __("(active)");
  758. } else {
  759. $is_active = "";
  760. }
  761. print "<td><span dojoType=\"dijit.InlineEditBox\"
  762. width=\"300px\" autoSave=\"false\"
  763. profile-id=\"$profile_id\">" . $edit_title .
  764. "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
  765. var elem = this;
  766. dojo.xhrPost({
  767. url: 'backend.php',
  768. content: {op: 'rpc', method: 'saveprofile',
  769. value: this.value,
  770. id: this.srcNodeRef.getAttribute('profile-id')},
  771. load: function(response) {
  772. elem.attr('value', response);
  773. }
  774. });
  775. </script>
  776. </span> $is_active</td>";
  777. print "</tr>";
  778. ++$lnum;
  779. }
  780. print "</table>";
  781. print "</form>";
  782. print "</div>";
  783. print "<div class='dlgButtons'>
  784. <div style='float : left'>
  785. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
  786. __('Remove selected profiles')."</button>
  787. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
  788. __('Activate profile')."</button>
  789. </div>";
  790. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
  791. __('Close this window')."</button>";
  792. print "</div>";
  793. }
  794. private function getShortDesc($pref_name) {
  795. if (isset($this->pref_help[$pref_name])) {
  796. return $this->pref_help[$pref_name][0];
  797. }
  798. return "";
  799. }
  800. private function getHelpText($pref_name) {
  801. if (isset($this->pref_help[$pref_name])) {
  802. return $this->pref_help[$pref_name][1];
  803. }
  804. return "";
  805. }
  806. private function getSectionName($id) {
  807. if (isset($this->pref_sections[$id])) {
  808. return $this->pref_sections[$id];
  809. }
  810. return "";
  811. }
  812. }