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