prefs.php 26 KB

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