prefs.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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. function otpdisable() {
  658. $password = $_REQUEST["password"];
  659. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  660. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  661. $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE
  662. id = ?");
  663. $sth->execute([$_SESSION['uid']]);
  664. print "OK";
  665. } else {
  666. print "ERROR: ".__("Incorrect password");
  667. }
  668. }
  669. function setplugins() {
  670. if (is_array($_REQUEST["plugins"]))
  671. $plugins = join(",", $_REQUEST["plugins"]);
  672. else
  673. $plugins = "";
  674. set_pref("_ENABLED_PLUGINS", $plugins, $_SESSION["uid"]);
  675. }
  676. function clearplugindata() {
  677. $name = $_REQUEST["name"];
  678. PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
  679. }
  680. function customizeCSS() {
  681. $value = get_pref("USER_STYLESHEET");
  682. $value = str_replace("<br/>", "\n", $value);
  683. 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"));
  684. print_hidden("op", "rpc");
  685. print_hidden("method", "setpref");
  686. print_hidden("key", "USER_STYLESHEET");
  687. print "<table width='100%'><tr><td>";
  688. print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
  689. style='font-size : 12px; width : 98%; height: 200px;'
  690. placeHolder='body#ttrssMain { font-size : 14px; };'
  691. name='value'>$value</textarea>";
  692. print "</td></tr></table>";
  693. print "<div class='dlgButtons'>";
  694. print "<button dojoType=\"dijit.form.Button\"
  695. onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
  696. print "<button dojoType=\"dijit.form.Button\"
  697. onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
  698. print "</div>";
  699. }
  700. function editPrefProfiles() {
  701. print "<div dojoType=\"dijit.Toolbar\">";
  702. print "<div dojoType=\"dijit.form.DropDownButton\">".
  703. "<span>" . __('Select')."</span>";
  704. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  705. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
  706. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  707. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
  708. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  709. print "</div></div>";
  710. print "<div style=\"float : right\">";
  711. print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
  712. required=\"1\">
  713. <button dojoType=\"dijit.form.Button\"
  714. onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
  715. __('Create profile')."</button></div>";
  716. print "</div>";
  717. $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles
  718. WHERE owner_uid = ? ORDER BY title");
  719. $sth->execute([$_SESSION['uid']]);
  720. print "<div class=\"prefProfileHolder\">";
  721. print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
  722. print "<table width=\"100%\" class=\"prefFeedProfileList\"
  723. cellspacing=\"0\" id=\"prefFeedProfileList\">";
  724. print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
  725. print "<td width='5%' align='center'><input
  726. id='FCATC-0'
  727. onclick='toggleSelectRow2(this);'
  728. dojoType=\"dijit.form.CheckBox\"
  729. type=\"checkbox\"></td>";
  730. if (!$_SESSION["profile"]) {
  731. $is_active = __("(active)");
  732. } else {
  733. $is_active = "";
  734. }
  735. print "<td><span>" .
  736. __("Default profile") . " $is_active</span></td>";
  737. print "</tr>";
  738. $lnum = 1;
  739. while ($line = $sth->fetch()) {
  740. $profile_id = $line["id"];
  741. $this_row_id = "id=\"FCATR-$profile_id\"";
  742. print "<tr class=\"placeholder\" $this_row_id>";
  743. $edit_title = htmlspecialchars($line["title"]);
  744. print "<td width='5%' align='center'><input
  745. onclick='toggleSelectRow2(this);'
  746. id='FCATC-$profile_id'
  747. dojoType=\"dijit.form.CheckBox\"
  748. type=\"checkbox\"></td>";
  749. if ($_SESSION["profile"] == $line["id"]) {
  750. $is_active = __("(active)");
  751. } else {
  752. $is_active = "";
  753. }
  754. print "<td><span dojoType=\"dijit.InlineEditBox\"
  755. width=\"300px\" autoSave=\"false\"
  756. profile-id=\"$profile_id\">" . $edit_title .
  757. "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
  758. var elem = this;
  759. dojo.xhrPost({
  760. url: 'backend.php',
  761. content: {op: 'rpc', method: 'saveprofile',
  762. value: this.value,
  763. id: this.srcNodeRef.getAttribute('profile-id')},
  764. load: function(response) {
  765. elem.attr('value', response);
  766. }
  767. });
  768. </script>
  769. </span> $is_active</td>";
  770. print "</tr>";
  771. ++$lnum;
  772. }
  773. print "</table>";
  774. print "</form>";
  775. print "</div>";
  776. print "<div class='dlgButtons'>
  777. <div style='float : left'>
  778. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
  779. __('Remove selected profiles')."</button>
  780. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
  781. __('Activate profile')."</button>
  782. </div>";
  783. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
  784. __('Close this window')."</button>";
  785. print "</div>";
  786. }
  787. private function getShortDesc($pref_name) {
  788. if (isset($this->pref_help[$pref_name])) {
  789. return $this->pref_help[$pref_name][0];
  790. }
  791. return "";
  792. }
  793. private function getHelpText($pref_name) {
  794. if (isset($this->pref_help[$pref_name])) {
  795. return $this->pref_help[$pref_name][1];
  796. }
  797. return "";
  798. }
  799. private function getSectionName($id) {
  800. if (isset($this->pref_sections[$id])) {
  801. return $this->pref_sections[$id];
  802. }
  803. return "";
  804. }
  805. }