]>
Commit | Line | Data |
---|---|---|
1395083e | 1 | <?php |
369dbc19 | 2 | class Pref_Prefs extends Handler_Protected { |
1395083e | 3 | |
8484ce22 | 4 | function csrf_ignore($method) { |
27211afe | 5 | $csrf_ignored = array("index", "updateself"); |
8484ce22 AD |
6 | |
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
1395083e AD |
10 | function changepassword() { |
11 | ||
12 | $old_pw = $_POST["old_password"]; | |
13 | $new_pw = $_POST["new_password"]; | |
14 | $con_pw = $_POST["confirm_password"]; | |
15 | ||
16 | if ($old_pw == "") { | |
17 | print "ERROR: ".__("Old password cannot be blank."); | |
18 | return; | |
19 | } | |
20 | ||
21 | if ($new_pw == "") { | |
22 | print "ERROR: ".__("New password cannot be blank."); | |
23 | return; | |
24 | } | |
25 | ||
26 | if ($new_pw != $con_pw) { | |
27 | print "ERROR: ".__("Entered passwords do not match."); | |
28 | return; | |
29 | } | |
30 | ||
0f28f81f AD |
31 | global $pluginhost; |
32 | $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]); | |
1395083e | 33 | |
d5fd183d AD |
34 | if (method_exists($authenticator, "change_password")) { |
35 | print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw); | |
098df83b | 36 | } else { |
d5fd183d | 37 | print "ERROR: ".__("Function not supported by authentication module."); |
098df83b | 38 | } |
1395083e AD |
39 | } |
40 | ||
41 | function saveconfig() { | |
42 | ||
43 | $_SESSION["prefs_cache"] = false; | |
44 | ||
1395083e AD |
45 | foreach (array_keys($_POST) as $pref_name) { |
46 | ||
47 | $pref_name = db_escape_string($pref_name); | |
48 | $value = db_escape_string($_POST[$pref_name]); | |
49 | ||
1b9b19af AD |
50 | if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
51 | if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) { | |
52 | ||
53 | db_query($this->link, "UPDATE ttrss_users SET | |
54 | last_digest_sent = NULL WHERE id = " . $_SESSION['uid']); | |
55 | ||
56 | } | |
57 | } | |
58 | ||
1395083e AD |
59 | set_pref($this->link, $pref_name, $value); |
60 | ||
61 | } | |
62 | ||
96f0a3e7 | 63 | print __("The configuration was saved."); |
1395083e AD |
64 | } |
65 | ||
66 | function getHelp() { | |
67 | ||
68 | $pref_name = db_escape_string($_REQUEST["pn"]); | |
69 | ||
70 | $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs | |
71 | WHERE pref_name = '$pref_name'"); | |
72 | ||
73 | if (db_num_rows($result) > 0) { | |
74 | $help_text = db_fetch_result($result, 0, "help_text"); | |
75 | print $help_text; | |
76 | } else { | |
77 | printf(__("Unknown option: %s"), $pref_name); | |
78 | } | |
79 | } | |
80 | ||
81 | function changeemail() { | |
82 | ||
83 | $email = db_escape_string($_POST["email"]); | |
84 | $full_name = db_escape_string($_POST["full_name"]); | |
85 | ||
86 | $active_uid = $_SESSION["uid"]; | |
87 | ||
88 | db_query($this->link, "UPDATE ttrss_users SET email = '$email', | |
89 | full_name = '$full_name' WHERE id = '$active_uid'"); | |
90 | ||
91 | print __("Your personal data has been saved."); | |
92 | ||
93 | return; | |
94 | } | |
95 | ||
96 | function resetconfig() { | |
97 | ||
98 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; | |
99 | ||
100 | if ($_SESSION["profile"]) { | |
101 | $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; | |
102 | } else { | |
103 | $profile_qpart = "profile IS NULL"; | |
104 | } | |
105 | ||
106 | db_query($this->link, "DELETE FROM ttrss_user_prefs | |
107 | WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]); | |
108 | ||
109 | initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]); | |
110 | ||
111 | print "PREFS_THEME_CHANGED"; | |
112 | } | |
113 | ||
114 | function index() { | |
115 | ||
116 | global $access_level_names; | |
117 | ||
118 | $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD", | |
119 | "STRIP_UNSAFE_TAGS"); | |
120 | ||
121 | $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", | |
122 | "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", | |
123 | "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", | |
124 | "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", | |
6d9455e9 | 125 | "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"); |
1395083e AD |
126 | |
127 | ||
d4c64ecc | 128 | $_SESSION["prefs_op_result"] = ""; |
1395083e | 129 | |
d4c64ecc AD |
130 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; |
131 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">"; | |
1395083e | 132 | |
d4c64ecc | 133 | print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">"; |
1395083e | 134 | |
d4c64ecc AD |
135 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
136 | evt.preventDefault(); | |
137 | if (this.validate()) { | |
138 | notify_progress('Saving data...', true); | |
1395083e | 139 | |
d4c64ecc AD |
140 | new Ajax.Request('backend.php', { |
141 | parameters: dojo.objectToQuery(this.getValues()), | |
142 | onComplete: function(transport) { | |
143 | notify_callback2(transport); | |
144 | } }); | |
1395083e | 145 | |
d4c64ecc AD |
146 | } |
147 | </script>"; | |
1395083e | 148 | |
d4c64ecc | 149 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
1395083e | 150 | |
fb70f26e AD |
151 | print "<h2>" . __("Personal data") . "</h2>"; |
152 | ||
153 | $result = db_query($this->link, "SELECT email,full_name,otp_enabled, | |
d4c64ecc AD |
154 | access_level FROM ttrss_users |
155 | WHERE id = ".$_SESSION["uid"]); | |
1395083e | 156 | |
d4c64ecc AD |
157 | $email = htmlspecialchars(db_fetch_result($result, 0, "email")); |
158 | $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); | |
fb70f26e | 159 | $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled")); |
1395083e | 160 | |
d4c64ecc AD |
161 | print "<tr><td width=\"40%\">".__('Full name')."</td>"; |
162 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\" | |
163 | value=\"$full_name\"></td></tr>"; | |
1395083e | 164 | |
d4c64ecc AD |
165 | print "<tr><td width=\"40%\">".__('E-mail')."</td>"; |
166 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>"; | |
1395083e | 167 | |
0d421af8 | 168 | if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
949b1a94 | 169 | |
d4c64ecc AD |
170 | $access_level = db_fetch_result($result, 0, "access_level"); |
171 | print "<tr><td width=\"40%\">".__('Access level')."</td>"; | |
172 | print "<td>" . $access_level_names[$access_level] . "</td></tr>"; | |
173 | } | |
1395083e | 174 | |
d4c64ecc | 175 | print "</table>"; |
1395083e | 176 | |
d4c64ecc AD |
177 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; |
178 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">"; | |
1395083e | 179 | |
d4c64ecc AD |
180 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". |
181 | __("Save data")."</button>"; | |
1395083e | 182 | |
d4c64ecc | 183 | print "</form>"; |
1395083e | 184 | |
0f28f81f AD |
185 | if ($_SESSION["auth_module"]) { |
186 | global $pluginhost; | |
187 | ||
188 | $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]); | |
189 | ||
d5fd183d AD |
190 | } else { |
191 | $authenticator = false; | |
192 | } | |
193 | ||
194 | if ($authenticator && method_exists($authenticator, "change_password")) { | |
1395083e | 195 | |
fb70f26e AD |
196 | print "<h2>" . __("Password") . "</h2>"; |
197 | ||
1395083e AD |
198 | $result = db_query($this->link, "SELECT id FROM ttrss_users |
199 | WHERE id = ".$_SESSION["uid"]." AND pwd_hash | |
200 | = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); | |
201 | ||
202 | if (db_num_rows($result) != 0) { | |
203 | print format_warning(__("Your password is at default value, please change it."), "default_pass_warning"); | |
204 | } | |
205 | ||
206 | print "<form dojoType=\"dijit.form.Form\">"; | |
207 | ||
208 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
209 | evt.preventDefault(); | |
210 | if (this.validate()) { | |
211 | notify_progress('Changing password...', true); | |
212 | ||
213 | new Ajax.Request('backend.php', { | |
214 | parameters: dojo.objectToQuery(this.getValues()), | |
215 | onComplete: function(transport) { | |
216 | notify(''); | |
217 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
218 | notify_error(transport.responseText.replace('ERROR: ', '')); | |
219 | } else { | |
220 | notify_info(transport.responseText); | |
221 | var warn = $('default_pass_warning'); | |
222 | if (warn) Element.hide(warn); | |
223 | } | |
224 | }}); | |
225 | this.reset(); | |
226 | } | |
227 | </script>"; | |
228 | ||
3ca8af7f AD |
229 | if ($otp_enabled) { |
230 | print_notice("Changing your current password will disable OTP."); | |
231 | } | |
232 | ||
1395083e AD |
233 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
234 | ||
235 | print "<tr><td width=\"40%\">".__("Old password")."</td>"; | |
236 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>"; | |
237 | ||
238 | print "<tr><td width=\"40%\">".__("New password")."</td>"; | |
239 | ||
240 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
241 | name=\"new_password\"></td></tr>"; | |
242 | ||
243 | print "<tr><td width=\"40%\">".__("Confirm password")."</td>"; | |
244 | ||
245 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>"; | |
246 | ||
247 | print "</table>"; | |
248 | ||
249 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
250 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">"; | |
251 | ||
252 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
253 | __("Change password")."</button>"; | |
254 | ||
255 | print "</form>"; | |
256 | ||
0f28f81f | 257 | if ($_SESSION["auth_module"] == "auth_internal") { |
fb70f26e AD |
258 | |
259 | print "<h2>" . __("One time passwords / Authenticator") . "</h2>"; | |
260 | ||
261 | if ($otp_enabled) { | |
262 | ||
3ca8af7f AD |
263 | print_notice("One time passwords are currently enabled. Enter your current password below to disable."); |
264 | ||
265 | print "<form dojoType=\"dijit.form.Form\">"; | |
266 | ||
267 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
268 | evt.preventDefault(); | |
269 | if (this.validate()) { | |
270 | notify_progress('Disabling OTP', true); | |
271 | ||
272 | new Ajax.Request('backend.php', { | |
273 | parameters: dojo.objectToQuery(this.getValues()), | |
274 | onComplete: function(transport) { | |
275 | notify(''); | |
276 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
277 | notify_error(transport.responseText.replace('ERROR: ', '')); | |
278 | } else { | |
279 | window.location.reload(); | |
280 | } | |
281 | }}); | |
282 | this.reset(); | |
283 | } | |
284 | </script>"; | |
285 | ||
286 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
287 | ||
288 | print "<tr><td width=\"40%\">".__("Enter your password")."</td>"; | |
289 | ||
290 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
291 | name=\"password\"></td></tr>"; | |
292 | ||
293 | print "</table>"; | |
294 | ||
295 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
296 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">"; | |
297 | ||
298 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
299 | __("Disable OTP")."</button>"; | |
300 | ||
301 | print "</form>"; | |
fb70f26e AD |
302 | |
303 | } else { | |
304 | ||
305 | print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>"; | |
306 | ||
307 | print "<p>".__("Scan the following code by the Authenticator application:")."</p>"; | |
308 | ||
309 | $csrf_token = $_SESSION["csrf_token"]; | |
310 | ||
311 | print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">"; | |
312 | ||
313 | print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">"; | |
314 | ||
315 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
3ca8af7f | 316 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">"; |
fb70f26e AD |
317 | |
318 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
319 | evt.preventDefault(); | |
320 | if (this.validate()) { | |
321 | notify_progress('Saving data...', true); | |
322 | ||
323 | new Ajax.Request('backend.php', { | |
324 | parameters: dojo.objectToQuery(this.getValues()), | |
325 | onComplete: function(transport) { | |
3ca8af7f AD |
326 | notify(''); |
327 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
328 | notify_error(transport.responseText.replace('ERROR: ', '')); | |
329 | } else { | |
330 | window.location.reload(); | |
331 | } | |
fb70f26e AD |
332 | } }); |
333 | ||
334 | } | |
335 | </script>"; | |
336 | ||
3ca8af7f AD |
337 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
338 | ||
339 | print "<tr><td width=\"40%\">".__("Enter your password")."</td>"; | |
340 | ||
341 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
342 | name=\"password\"></td></tr>"; | |
343 | ||
344 | print "<tr><td colspan=\"2\">"; | |
345 | ||
fb70f26e AD |
346 | print "<input dojoType=\"dijit.form.CheckBox\" required=\"1\" |
347 | type=\"checkbox\" id=\"enable_otp\" name=\"enable_otp\"/> "; | |
348 | print "<label for=\"enable_otp\">".__("I have scanned the code and would like to enable OTP")."</label>"; | |
349 | ||
3ca8af7f AD |
350 | print "</td></tr><tr><td colspan=\"2\">"; |
351 | ||
352 | print "</td></tr>"; | |
353 | print "</table>"; | |
354 | ||
fb70f26e | 355 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". |
3ca8af7f | 356 | __("Enable OTP")."</button>"; |
fb70f26e AD |
357 | |
358 | print "</form>"; | |
359 | ||
360 | } | |
361 | ||
362 | } | |
1395083e AD |
363 | } |
364 | ||
699daf58 AD |
365 | global $pluginhost; |
366 | $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION, | |
367 | "hook_prefs_tab_section", "prefPrefsAuth"); | |
368 | ||
d4c64ecc AD |
369 | print "</div>"; #pane |
370 | ||
1395083e AD |
371 | print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">"; |
372 | ||
373 | print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">"; | |
374 | ||
375 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
376 | evt.preventDefault(); | |
377 | if (this.validate()) { | |
378 | console.log(dojo.objectToQuery(this.getValues())); | |
379 | ||
380 | new Ajax.Request('backend.php', { | |
381 | parameters: dojo.objectToQuery(this.getValues()), | |
382 | onComplete: function(transport) { | |
383 | var msg = transport.responseText; | |
384 | if (msg.match('PREFS_THEME_CHANGED')) { | |
385 | window.location.reload(); | |
386 | } else { | |
387 | notify_info(msg); | |
388 | } | |
389 | } }); | |
390 | } | |
391 | </script>"; | |
392 | ||
393 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
394 | ||
395 | print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; | |
396 | ||
397 | if ($_SESSION["profile"]) { | |
398 | print_notice("Some preferences are only available in default profile."); | |
399 | } | |
400 | ||
401 | if ($_SESSION["profile"]) { | |
402 | initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]); | |
403 | $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; | |
404 | } else { | |
405 | initialize_user_prefs($this->link, $_SESSION["uid"]); | |
406 | $profile_qpart = "profile IS NULL"; | |
407 | } | |
408 | ||
f9ebb32c AD |
409 | if ($_SESSION["prefs_show_advanced"]) |
410 | $access_query = "true"; | |
411 | else | |
412 | $access_query = "(access_level = 0 AND section_id != 3)"; | |
413 | ||
ddb575c7 | 414 | $result = db_query($this->link, "SELECT DISTINCT |
1395083e | 415 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
f9ebb32c | 416 | ttrss_prefs_sections.order_id, |
1395083e AD |
417 | section_name,def_value,section_id |
418 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs | |
419 | WHERE type_id = ttrss_prefs_types.id AND | |
420 | $profile_qpart AND | |
421 | section_id = ttrss_prefs_sections.id AND | |
422 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
f9ebb32c | 423 | $access_query AND |
1395083e AD |
424 | short_desc != '' AND |
425 | owner_uid = ".$_SESSION["uid"]." | |
f9ebb32c | 426 | ORDER BY ttrss_prefs_sections.order_id,short_desc"); |
1395083e AD |
427 | |
428 | $lnum = 0; | |
429 | ||
430 | $active_section = ""; | |
431 | ||
432 | while ($line = db_fetch_assoc($result)) { | |
433 | ||
434 | if (in_array($line["pref_name"], $prefs_blacklist)) { | |
435 | continue; | |
436 | } | |
437 | ||
438 | if ($_SESSION["profile"] && in_array($line["pref_name"], | |
439 | $profile_blacklist)) { | |
440 | continue; | |
441 | } | |
442 | ||
443 | if ($active_section != $line["section_name"]) { | |
444 | ||
445 | if ($active_section != "") { | |
446 | print "</table>"; | |
447 | } | |
448 | ||
449 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
450 | ||
451 | $active_section = $line["section_name"]; | |
452 | ||
453 | print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>"; | |
454 | ||
1395083e AD |
455 | $lnum = 0; |
456 | } | |
457 | ||
458 | print "<tr>"; | |
459 | ||
460 | $type_name = $line["type_name"]; | |
461 | $pref_name = $line["pref_name"]; | |
462 | $value = $line["value"]; | |
463 | $def_value = $line["def_value"]; | |
464 | $help_text = $line["help_text"]; | |
465 | ||
466 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]); | |
467 | ||
468 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; | |
469 | ||
470 | print "</td>"; | |
471 | ||
472 | print "<td class=\"prefValue\">"; | |
473 | ||
474 | if ($pref_name == "USER_TIMEZONE") { | |
475 | ||
476 | $timezones = explode("\n", file_get_contents("lib/timezones.txt")); | |
477 | ||
478 | print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); | |
479 | } else if ($pref_name == "USER_STYLESHEET") { | |
480 | ||
481 | print "<button dojoType=\"dijit.form.Button\" | |
482 | onclick=\"customizeCSS()\">" . __('Customize') . "</button>"; | |
483 | ||
484 | } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") { | |
485 | ||
486 | $limits = array(15, 30, 45, 60); | |
487 | ||
488 | print_select($pref_name, $value, $limits, | |
489 | 'dojoType="dijit.form.Select"'); | |
490 | ||
491 | } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { | |
492 | ||
493 | global $update_intervals_nodefault; | |
494 | ||
495 | print_select_hash($pref_name, $value, $update_intervals_nodefault, | |
496 | 'dojoType="dijit.form.Select"'); | |
497 | ||
498 | } else if ($type_name == "bool") { | |
499 | ||
500 | if ($value == "true") { | |
501 | $value = __("Yes"); | |
502 | } else { | |
503 | $value = __("No"); | |
504 | } | |
505 | ||
506 | if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { | |
507 | $disabled = "disabled=\"1\""; | |
508 | $value = __("Yes"); | |
509 | } else { | |
510 | $disabled = ""; | |
511 | } | |
512 | ||
513 | print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")), | |
514 | $disabled); | |
515 | ||
516 | } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT', | |
517 | 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { | |
518 | ||
519 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
520 | ||
521 | if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { | |
522 | $disabled = "disabled=\"1\""; | |
523 | $value = FORCE_ARTICLE_PURGE; | |
524 | } else { | |
525 | $disabled = ""; | |
526 | } | |
527 | ||
528 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
529 | required=\"1\" $regexp $disabled | |
530 | name=\"$pref_name\" value=\"$value\">"; | |
531 | ||
532 | } else if ($pref_name == "SSL_CERT_SERIAL") { | |
533 | ||
534 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
535 | id=\"SSL_CERT_SERIAL\" readonly=\"1\" | |
536 | name=\"$pref_name\" value=\"$value\">"; | |
537 | ||
538 | $cert_serial = htmlspecialchars(get_ssl_certificate_id()); | |
539 | $has_serial = ($cert_serial) ? "false" : "true"; | |
540 | ||
541 | print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\" | |
542 | onclick=\"insertSSLserial('$cert_serial')\">" . | |
543 | __('Register') . "</button>"; | |
544 | ||
545 | print " <button dojoType=\"dijit.form.Button\" | |
546 | onclick=\"insertSSLserial('')\">" . | |
547 | __('Clear') . "</button>"; | |
548 | ||
76c843a9 | 549 | } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
61c1812f | 550 | print "<input dojoType=\"dijit.form.ValidationTextBox\" |
1b92f543 | 551 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
61c1812f | 552 | name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">". |
8eba830f | 553 | T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>"; |
1395083e AD |
554 | } else { |
555 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
556 | ||
557 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
558 | $regexp | |
559 | name=\"$pref_name\" value=\"$value\">"; | |
560 | } | |
561 | ||
562 | print "</td>"; | |
563 | ||
564 | print "</tr>"; | |
565 | ||
566 | $lnum++; | |
567 | } | |
568 | ||
569 | print "</table>"; | |
570 | ||
699daf58 AD |
571 | global $pluginhost; |
572 | $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION, | |
573 | "hook_prefs_tab_section", "prefPrefsPrefsInside"); | |
574 | ||
1395083e AD |
575 | print '</div>'; # inside pane |
576 | print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; | |
577 | ||
578 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
579 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">"; | |
580 | ||
581 | print "<button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
582 | __('Save configuration')."</button> "; | |
583 | ||
584 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">". | |
585 | __('Manage profiles')."</button> "; | |
586 | ||
587 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">". | |
588 | __('Reset to defaults')."</button>"; | |
589 | ||
f9ebb32c AD |
590 | print " "; |
591 | ||
592 | $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : ""; | |
593 | ||
594 | print "<input onclick='toggleAdvancedPrefs()' | |
595 | id='prefs_show_advanced' | |
596 | dojoType=\"dijit.form.CheckBox\" | |
597 | $checked | |
598 | type=\"checkbox\"></input> | |
599 | <label for='prefs_show_advanced'>" . | |
600 | __("Show additional preferences") . "</label>"; | |
601 | ||
699daf58 AD |
602 | global $pluginhost; |
603 | $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION, | |
604 | "hook_prefs_tab_section", "prefPrefsPrefsOutside"); | |
605 | ||
de612e7a | 606 | print "</form>"; |
1395083e AD |
607 | print '</div>'; # inner pane |
608 | print '</div>'; # border container | |
de612e7a AD |
609 | |
610 | print "</div>"; #pane | |
611 | ||
612 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">"; | |
613 | ||
614 | print "<h2>".__("Plugins")."</h2>"; | |
615 | ||
616 | print_notice("You will need to reload Tiny Tiny RSS for plugin changes to take effect."); | |
617 | ||
618 | print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; | |
619 | ||
620 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
621 | evt.preventDefault(); | |
622 | if (this.validate()) { | |
623 | notify_progress('Saving data...', true); | |
624 | ||
625 | new Ajax.Request('backend.php', { | |
626 | parameters: dojo.objectToQuery(this.getValues()), | |
627 | onComplete: function(transport) { | |
628 | notify(''); | |
629 | if (confirm(__('Selected plugins have been enabled. Reload?'))) { | |
630 | window.location.reload(); | |
631 | } | |
632 | } }); | |
633 | ||
634 | } | |
635 | </script>"; | |
636 | ||
637 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
638 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">"; | |
639 | ||
65d1e250 | 640 | print "<table width='100%' class='prefPluginsList'>"; |
de612e7a AD |
641 | |
642 | print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>"; | |
643 | ||
644 | print "<tr class=\"title\"> | |
645 | <td width=\"5%\"> </td> | |
646 | <td width='10%'>".__('Plugin')."</td> | |
647 | <td width=''>".__('Description')."</td> | |
648 | <td width='5%'>".__('Version')."</td> | |
649 | <td width='10%'>".__('Author')."</td></tr>"; | |
650 | ||
651 | $system_enabled = array_map("trim", explode(",", PLUGINS)); | |
652 | $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS"))); | |
653 | ||
5d9abb1e AD |
654 | $tmppluginhost = new PluginHost($this->link); |
655 | $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]); | |
656 | $tmppluginhost->load_data(true); | |
de612e7a AD |
657 | |
658 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { | |
d2a421e3 | 659 | $about = $plugin->about(); |
de612e7a | 660 | |
23be0bd3 | 661 | if ($about[3] && strpos($name, "example") === FALSE) { |
de612e7a AD |
662 | if (in_array($name, $system_enabled)) { |
663 | $checked = "checked='1'"; | |
664 | } else { | |
665 | $checked = ""; | |
666 | } | |
667 | ||
668 | print "<tr>"; | |
669 | ||
670 | print "<td align='center'><input disabled='1' | |
671 | dojoType=\"dijit.form.CheckBox\" $checked | |
672 | type=\"checkbox\"></td>"; | |
673 | ||
674 | print "<td>$name</td>"; | |
675 | print "<td>" . htmlspecialchars($about[1]) . "</td>"; | |
676 | print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>"; | |
677 | print "<td>" . htmlspecialchars($about[2]) . "</td>"; | |
678 | ||
5d9abb1e AD |
679 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
680 | print "<td><a href='#' onclick=\"clearPluginData('$name')\" | |
681 | class='visibleLink'>".__("Clear data")."</a></td>"; | |
682 | } | |
683 | ||
de612e7a AD |
684 | print "</tr>"; |
685 | ||
686 | } | |
687 | } | |
688 | ||
689 | print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>"; | |
690 | ||
691 | print "<tr class=\"title\"> | |
692 | <td width=\"5%\"> </td> | |
693 | <td width='10%'>".__('Plugin')."</td> | |
694 | <td width=''>".__('Description')."</td> | |
695 | <td width='5%'>".__('Version')."</td> | |
696 | <td width='10%'>".__('Author')."</td></tr>"; | |
697 | ||
698 | ||
699 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { | |
d2a421e3 | 700 | $about = $plugin->about(); |
de612e7a | 701 | |
23be0bd3 | 702 | if (!$about[3] && strpos($name, "example") === FALSE) { |
de612e7a AD |
703 | |
704 | if (in_array($name, $system_enabled)) { | |
705 | $checked = "checked='1'"; | |
706 | $disabled = "disabled='1'"; | |
65d1e250 | 707 | $rowclass = ''; |
de612e7a AD |
708 | } else if (in_array($name, $user_enabled)) { |
709 | $checked = "checked='1'"; | |
710 | $disabled = ""; | |
65d1e250 | 711 | $rowclass = "Selected"; |
de612e7a AD |
712 | } else { |
713 | $checked = ""; | |
714 | $disabled = ""; | |
65d1e250 | 715 | $rowclass = ''; |
de612e7a AD |
716 | } |
717 | ||
65d1e250 | 718 | print "<tr class='$rowclass'>"; |
de612e7a AD |
719 | |
720 | print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);' | |
721 | dojoType=\"dijit.form.CheckBox\" $checked $disabled | |
722 | type=\"checkbox\"></td>"; | |
723 | ||
65d1e250 AD |
724 | print "<td><label for='FPCHK-$name'>$name</label></td>"; |
725 | print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label></td>"; | |
de612e7a AD |
726 | print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>"; |
727 | print "<td>" . htmlspecialchars($about[2]) . "</td>"; | |
728 | ||
5d9abb1e AD |
729 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
730 | print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>"; | |
731 | } | |
732 | ||
de612e7a AD |
733 | print "</tr>"; |
734 | ||
735 | ||
736 | ||
737 | } | |
738 | ||
739 | } | |
740 | ||
741 | print "</table>"; | |
742 | ||
743 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
744 | __("Enable selected plugins")."</button></p>"; | |
745 | ||
1395083e AD |
746 | print "</form>"; |
747 | ||
748 | print "</div>"; #pane | |
27211afe | 749 | |
6065f3ad AD |
750 | global $pluginhost; |
751 | $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB, | |
752 | "hook_prefs_tab", "prefPrefs"); | |
753 | ||
1395083e AD |
754 | print "</div>"; #container |
755 | } | |
27211afe | 756 | |
f9ebb32c AD |
757 | function toggleAdvanced() { |
758 | $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; | |
759 | } | |
fb70f26e AD |
760 | |
761 | function otpqrcode() { | |
762 | require_once "lib/otphp/vendor/base32.php"; | |
763 | require_once "lib/otphp/lib/otp.php"; | |
764 | require_once "lib/otphp/lib/totp.php"; | |
765 | require_once "lib/phpqrcode/phpqrcode.php"; | |
766 | ||
973392b9 | 767 | $result = db_query($this->link, "SELECT login,salt,otp_enabled |
fb70f26e AD |
768 | FROM ttrss_users |
769 | WHERE id = ".$_SESSION["uid"]); | |
770 | ||
771 | $base32 = new Base32(); | |
772 | ||
773 | $login = db_fetch_result($result, 0, "login"); | |
973392b9 | 774 | $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled")); |
fb70f26e | 775 | |
973392b9 AD |
776 | if (!$otp_enabled) { |
777 | $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt"))); | |
778 | $topt = new \OTPHP\TOTP($secret); | |
779 | print QRcode::png($topt->provisioning_uri($login)); | |
780 | } | |
fb70f26e AD |
781 | } |
782 | ||
3ca8af7f AD |
783 | function otpenable() { |
784 | $password = db_escape_string($_REQUEST["password"]); | |
3ca8af7f AD |
785 | $enable_otp = $_REQUEST["enable_otp"] == "on"; |
786 | ||
0f28f81f AD |
787 | global $pluginhost; |
788 | $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]); | |
789 | ||
3ca8af7f AD |
790 | if ($authenticator->check_password($_SESSION["uid"], $password)) { |
791 | ||
792 | if ($enable_otp) { | |
793 | db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE | |
794 | id = " . $_SESSION["uid"]); | |
795 | ||
796 | print "OK"; | |
797 | } | |
798 | } else { | |
799 | print "ERROR: ".__("Incorrect password"); | |
800 | } | |
fb70f26e | 801 | |
3ca8af7f AD |
802 | } |
803 | ||
804 | function otpdisable() { | |
805 | $password = db_escape_string($_REQUEST["password"]); | |
806 | ||
0f28f81f AD |
807 | global $pluginhost; |
808 | $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]); | |
3ca8af7f AD |
809 | |
810 | if ($authenticator->check_password($_SESSION["uid"], $password)) { | |
811 | ||
812 | db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE | |
fb70f26e | 813 | id = " . $_SESSION["uid"]); |
3ca8af7f AD |
814 | |
815 | print "OK"; | |
816 | } else { | |
817 | print "ERROR: ".__("Incorrect password"); | |
fb70f26e | 818 | } |
3ca8af7f | 819 | |
fb70f26e | 820 | } |
de612e7a AD |
821 | |
822 | function setplugins() { | |
823 | $plugins = join(",", $_REQUEST["plugins"]); | |
824 | ||
825 | set_pref($this->link, "_ENABLED_PLUGINS", $plugins); | |
826 | } | |
5d9abb1e AD |
827 | |
828 | function clearplugindata() { | |
829 | $name = db_escape_string($_REQUEST["name"]); | |
830 | ||
831 | global $pluginhost; | |
832 | $pluginhost->clear_data($pluginhost->get_plugin($name)); | |
833 | } | |
1395083e AD |
834 | } |
835 | ?> |