prefs.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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("STRIP_UNSAFE_TAGS");
  85. /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
  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. $access_query = 'true';
  293. $result = db_query($this->link, "SELECT DISTINCT
  294. ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
  295. ttrss_prefs_sections.order_id,
  296. section_name,def_value,section_id
  297. FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
  298. WHERE type_id = ttrss_prefs_types.id AND
  299. $profile_qpart AND
  300. section_id = ttrss_prefs_sections.id AND
  301. ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
  302. $access_query AND
  303. short_desc != '' AND
  304. owner_uid = ".$_SESSION["uid"]."
  305. ORDER BY ttrss_prefs_sections.order_id,short_desc");
  306. $lnum = 0;
  307. $active_section = "";
  308. $listed_boolean_prefs = array();
  309. while ($line = db_fetch_assoc($result)) {
  310. if (in_array($line["pref_name"], $prefs_blacklist)) {
  311. continue;
  312. }
  313. if ($_SESSION["profile"] && in_array($line["pref_name"],
  314. $profile_blacklist)) {
  315. continue;
  316. }
  317. if ($active_section != $line["section_name"]) {
  318. if ($active_section != "") {
  319. print "</table>";
  320. }
  321. print "<table width=\"100%\" class=\"prefPrefsList\">";
  322. $active_section = $line["section_name"];
  323. print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
  324. $lnum = 0;
  325. }
  326. print "<tr>";
  327. $type_name = $line["type_name"];
  328. $pref_name = $line["pref_name"];
  329. $value = $line["value"];
  330. $def_value = $line["def_value"];
  331. $help_text = $line["help_text"];
  332. print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
  333. print "<label for='CB_$pref_name'>";
  334. print __($line["short_desc"]);
  335. print "</label>";
  336. if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
  337. print "</td>";
  338. print "<td class=\"prefValue\">";
  339. if ($pref_name == "USER_TIMEZONE") {
  340. $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
  341. print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
  342. } else if ($pref_name == "USER_STYLESHEET") {
  343. print "<button dojoType=\"dijit.form.Button\"
  344. onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
  345. } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
  346. $limits = array(15, 30, 45, 60);
  347. print_select($pref_name, $value, $limits,
  348. 'dojoType="dijit.form.Select"');
  349. } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
  350. global $update_intervals_nodefault;
  351. print_select_hash($pref_name, $value, $update_intervals_nodefault,
  352. 'dojoType="dijit.form.Select"');
  353. } else if ($type_name == "bool") {
  354. array_push($listed_boolean_prefs, $pref_name);
  355. $checked = ($value == "true") ? "checked=\"checked\"" : "";
  356. if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
  357. $disabled = "disabled=\"1\"";
  358. $checked = "checked=\"checked\"";
  359. } else {
  360. $disabled = "";
  361. }
  362. print "<input type='checkbox' name='$pref_name' $checked $disabled
  363. dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
  364. } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
  365. 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
  366. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  367. if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
  368. $disabled = "disabled=\"1\"";
  369. $value = FORCE_ARTICLE_PURGE;
  370. } else {
  371. $disabled = "";
  372. }
  373. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  374. required=\"1\" $regexp $disabled
  375. name=\"$pref_name\" value=\"$value\">";
  376. } else if ($pref_name == "SSL_CERT_SERIAL") {
  377. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  378. id=\"SSL_CERT_SERIAL\" readonly=\"1\"
  379. name=\"$pref_name\" value=\"$value\">";
  380. $cert_serial = htmlspecialchars(get_ssl_certificate_id());
  381. $has_serial = ($cert_serial) ? "false" : "true";
  382. print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
  383. onclick=\"insertSSLserial('$cert_serial')\">" .
  384. __('Register') . "</button>";
  385. print " <button dojoType=\"dijit.form.Button\"
  386. onclick=\"insertSSLserial('')\">" .
  387. __('Clear') . "</button>";
  388. } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
  389. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  390. id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
  391. name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
  392. T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
  393. } else {
  394. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  395. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  396. $regexp
  397. name=\"$pref_name\" value=\"$value\">";
  398. }
  399. print "</td>";
  400. print "</tr>";
  401. $lnum++;
  402. }
  403. print "</table>";
  404. $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
  405. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
  406. global $pluginhost;
  407. $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
  408. "hook_prefs_tab_section", "prefPrefsPrefsInside");
  409. print '</div>'; # inside pane
  410. print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
  411. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  412. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
  413. print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
  414. __('Save configuration')."</button> ";
  415. print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
  416. __('Manage profiles')."</button> ";
  417. print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
  418. __('Reset to defaults')."</button>";
  419. print "&nbsp;";
  420. /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
  421. print "<input onclick='toggleAdvancedPrefs()'
  422. id='prefs_show_advanced'
  423. dojoType=\"dijit.form.CheckBox\"
  424. $checked
  425. type=\"checkbox\"></input>
  426. <label for='prefs_show_advanced'>" .
  427. __("Show additional preferences") . "</label>"; */
  428. global $pluginhost;
  429. $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
  430. "hook_prefs_tab_section", "prefPrefsPrefsOutside");
  431. print "</form>";
  432. print '</div>'; # inner pane
  433. print '</div>'; # border container
  434. print "</div>"; #pane
  435. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
  436. print "<h2>".__("Plugins")."</h2>";
  437. print_notice(__("Download more plugins at tt-rss.org <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/forum/viewforum.php?f=22\">forums</a> or <a target=\"_blank\" class=\"visibleLink\" href=\"http://tt-rss.org/wiki/Plugins\">wiki</a>."));
  438. print "<p class='insensitive'>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
  439. print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
  440. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  441. evt.preventDefault();
  442. if (this.validate()) {
  443. notify_progress('Saving data...', true);
  444. new Ajax.Request('backend.php', {
  445. parameters: dojo.objectToQuery(this.getValues()),
  446. onComplete: function(transport) {
  447. notify('');
  448. if (confirm(__('Selected plugins have been enabled. Reload?'))) {
  449. window.location.reload();
  450. }
  451. } });
  452. }
  453. </script>";
  454. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  455. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
  456. print "<table width='100%' class='prefPluginsList'>";
  457. print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
  458. print "<tr class=\"title\">
  459. <td width=\"5%\">&nbsp;</td>
  460. <td width='10%'>".__('Plugin')."</td>
  461. <td width=''>".__('Description')."</td>
  462. <td width='5%'>".__('Version')."</td>
  463. <td width='10%'>".__('Author')."</td></tr>";
  464. $system_enabled = array_map("trim", explode(",", PLUGINS));
  465. $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
  466. $tmppluginhost = new PluginHost($this->link);
  467. $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
  468. $tmppluginhost->load_data(true);
  469. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  470. $about = $plugin->about();
  471. if ($about[3] && strpos($name, "example") === FALSE) {
  472. if (in_array($name, $system_enabled)) {
  473. $checked = "checked='1'";
  474. } else {
  475. $checked = "";
  476. }
  477. print "<tr>";
  478. print "<td align='center'><input disabled='1'
  479. dojoType=\"dijit.form.CheckBox\" $checked
  480. type=\"checkbox\"></td>";
  481. print "<td>$name</td>";
  482. print "<td>" . htmlspecialchars($about[1]);
  483. if (@$about[4]) {
  484. print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
  485. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  486. }
  487. print "</td>";
  488. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  489. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  490. if (count($tmppluginhost->get_all($plugin)) > 0) {
  491. if (in_array($name, $system_enabled)) {
  492. print "<td><a href='#' onclick=\"clearPluginData('$name')\"
  493. class='visibleLink'>".__("Clear data")."</a></td>";
  494. }
  495. }
  496. print "</tr>";
  497. }
  498. }
  499. print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
  500. print "<tr class=\"title\">
  501. <td width=\"5%\">&nbsp;</td>
  502. <td width='10%'>".__('Plugin')."</td>
  503. <td width=''>".__('Description')."</td>
  504. <td width='5%'>".__('Version')."</td>
  505. <td width='10%'>".__('Author')."</td></tr>";
  506. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  507. $about = $plugin->about();
  508. if (!$about[3] && strpos($name, "example") === FALSE) {
  509. if (in_array($name, $system_enabled)) {
  510. $checked = "checked='1'";
  511. $disabled = "disabled='1'";
  512. $rowclass = '';
  513. } else if (in_array($name, $user_enabled)) {
  514. $checked = "checked='1'";
  515. $disabled = "";
  516. $rowclass = "Selected";
  517. } else {
  518. $checked = "";
  519. $disabled = "";
  520. $rowclass = '';
  521. }
  522. print "<tr class='$rowclass'>";
  523. print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
  524. dojoType=\"dijit.form.CheckBox\" $checked $disabled
  525. type=\"checkbox\"></td>";
  526. print "<td><label for='FPCHK-$name'>$name</label></td>";
  527. print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
  528. if (@$about[4]) {
  529. print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
  530. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  531. }
  532. print "</td>";
  533. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  534. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  535. if (count($tmppluginhost->get_all($plugin)) > 0) {
  536. if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
  537. print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
  538. }
  539. }
  540. print "</tr>";
  541. }
  542. }
  543. print "</table>";
  544. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  545. __("Enable selected plugins")."</button></p>";
  546. print "</form>";
  547. print "</div>"; #pane
  548. global $pluginhost;
  549. $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
  550. "hook_prefs_tab", "prefPrefs");
  551. print "</div>"; #container
  552. }
  553. function toggleAdvanced() {
  554. $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
  555. }
  556. function otpqrcode() {
  557. require_once "lib/otphp/vendor/base32.php";
  558. require_once "lib/otphp/lib/otp.php";
  559. require_once "lib/otphp/lib/totp.php";
  560. require_once "lib/phpqrcode/phpqrcode.php";
  561. $result = db_query($this->link, "SELECT login,salt,otp_enabled
  562. FROM ttrss_users
  563. WHERE id = ".$_SESSION["uid"]);
  564. $base32 = new Base32();
  565. $login = db_fetch_result($result, 0, "login");
  566. $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
  567. if (!$otp_enabled) {
  568. $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
  569. $topt = new \OTPHP\TOTP($secret);
  570. print QRcode::png($topt->provisioning_uri($login));
  571. }
  572. }
  573. function otpenable() {
  574. $password = db_escape_string($this->link, $_REQUEST["password"]);
  575. $enable_otp = $_REQUEST["enable_otp"] == "on";
  576. global $pluginhost;
  577. $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
  578. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  579. if ($enable_otp) {
  580. db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
  581. id = " . $_SESSION["uid"]);
  582. print "OK";
  583. }
  584. } else {
  585. print "ERROR: ".__("Incorrect password");
  586. }
  587. }
  588. function otpdisable() {
  589. $password = db_escape_string($this->link, $_REQUEST["password"]);
  590. global $pluginhost;
  591. $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
  592. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  593. db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE
  594. id = " . $_SESSION["uid"]);
  595. print "OK";
  596. } else {
  597. print "ERROR: ".__("Incorrect password");
  598. }
  599. }
  600. function setplugins() {
  601. if (is_array($_REQUEST["plugins"]))
  602. $plugins = join(",", $_REQUEST["plugins"]);
  603. else
  604. $plugins = "";
  605. set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
  606. }
  607. function clearplugindata() {
  608. $name = db_escape_string($this->link, $_REQUEST["name"]);
  609. global $pluginhost;
  610. $pluginhost->clear_data($pluginhost->get_plugin($name));
  611. }
  612. }
  613. ?>