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