]>
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 | ||
d5fd183d AD |
31 | $module_class = "auth_" . $_SESSION["auth_module"]; |
32 | $authenticator = new $module_class($this->link); | |
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 | ||
45 | $orig_theme = get_pref($this->link, "_THEME_ID"); | |
46 | ||
47 | foreach (array_keys($_POST) as $pref_name) { | |
48 | ||
49 | $pref_name = db_escape_string($pref_name); | |
50 | $value = db_escape_string($_POST[$pref_name]); | |
51 | ||
1b9b19af AD |
52 | if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
53 | if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) { | |
54 | ||
55 | db_query($this->link, "UPDATE ttrss_users SET | |
56 | last_digest_sent = NULL WHERE id = " . $_SESSION['uid']); | |
57 | ||
58 | } | |
59 | } | |
60 | ||
1395083e AD |
61 | set_pref($this->link, $pref_name, $value); |
62 | ||
63 | } | |
64 | ||
65 | if ($orig_theme != get_pref($this->link, "_THEME_ID")) { | |
66 | print "PREFS_THEME_CHANGED"; | |
67 | } else { | |
68 | print __("The configuration was saved."); | |
69 | } | |
70 | } | |
71 | ||
72 | function getHelp() { | |
73 | ||
74 | $pref_name = db_escape_string($_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($_POST["email"]); | |
90 | $full_name = db_escape_string($_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("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD", | |
125 | "STRIP_UNSAFE_TAGS"); | |
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", | |
6d9455e9 | 131 | "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"); |
1395083e AD |
132 | |
133 | ||
d4c64ecc | 134 | $_SESSION["prefs_op_result"] = ""; |
1395083e | 135 | |
d4c64ecc AD |
136 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; |
137 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">"; | |
1395083e | 138 | |
d4c64ecc | 139 | print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">"; |
1395083e | 140 | |
d4c64ecc AD |
141 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
142 | evt.preventDefault(); | |
143 | if (this.validate()) { | |
144 | notify_progress('Saving data...', true); | |
1395083e | 145 | |
d4c64ecc AD |
146 | new Ajax.Request('backend.php', { |
147 | parameters: dojo.objectToQuery(this.getValues()), | |
148 | onComplete: function(transport) { | |
149 | notify_callback2(transport); | |
150 | } }); | |
1395083e | 151 | |
d4c64ecc AD |
152 | } |
153 | </script>"; | |
1395083e | 154 | |
d4c64ecc | 155 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
1395083e | 156 | |
fb70f26e AD |
157 | print "<h2>" . __("Personal data") . "</h2>"; |
158 | ||
159 | $result = db_query($this->link, "SELECT email,full_name,otp_enabled, | |
d4c64ecc AD |
160 | access_level FROM ttrss_users |
161 | WHERE id = ".$_SESSION["uid"]); | |
1395083e | 162 | |
d4c64ecc AD |
163 | $email = htmlspecialchars(db_fetch_result($result, 0, "email")); |
164 | $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); | |
fb70f26e | 165 | $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled")); |
1395083e | 166 | |
d4c64ecc AD |
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>"; | |
1395083e | 170 | |
d4c64ecc AD |
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>"; | |
1395083e | 173 | |
0d421af8 | 174 | if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
949b1a94 | 175 | |
d4c64ecc AD |
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 | } | |
1395083e | 180 | |
d4c64ecc | 181 | print "</table>"; |
1395083e | 182 | |
d4c64ecc AD |
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\">"; | |
1395083e | 185 | |
d4c64ecc AD |
186 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". |
187 | __("Save data")."</button>"; | |
1395083e | 188 | |
d4c64ecc | 189 | print "</form>"; |
1395083e | 190 | |
d5fd183d AD |
191 | if ($_SESSION["auth_module"]) { |
192 | $module_class = "auth_" . $_SESSION["auth_module"]; | |
193 | $authenticator = new $module_class($this->link); | |
194 | } else { | |
195 | $authenticator = false; | |
196 | } | |
197 | ||
198 | if ($authenticator && method_exists($authenticator, "change_password")) { | |
1395083e | 199 | |
fb70f26e AD |
200 | print "<h2>" . __("Password") . "</h2>"; |
201 | ||
1395083e AD |
202 | $result = db_query($this->link, "SELECT id FROM ttrss_users |
203 | WHERE id = ".$_SESSION["uid"]." AND pwd_hash | |
204 | = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); | |
205 | ||
206 | if (db_num_rows($result) != 0) { | |
207 | print format_warning(__("Your password is at default value, please change it."), "default_pass_warning"); | |
208 | } | |
209 | ||
210 | print "<form dojoType=\"dijit.form.Form\">"; | |
211 | ||
212 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
213 | evt.preventDefault(); | |
214 | if (this.validate()) { | |
215 | notify_progress('Changing password...', true); | |
216 | ||
217 | new Ajax.Request('backend.php', { | |
218 | parameters: dojo.objectToQuery(this.getValues()), | |
219 | onComplete: function(transport) { | |
220 | notify(''); | |
221 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
222 | notify_error(transport.responseText.replace('ERROR: ', '')); | |
223 | } else { | |
224 | notify_info(transport.responseText); | |
225 | var warn = $('default_pass_warning'); | |
226 | if (warn) Element.hide(warn); | |
227 | } | |
228 | }}); | |
229 | this.reset(); | |
230 | } | |
231 | </script>"; | |
232 | ||
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 | ||
fb70f26e AD |
257 | if ($_SESSION["auth_module"] == "internal") { |
258 | ||
259 | print "<h2>" . __("One time passwords / Authenticator") . "</h2>"; | |
260 | ||
261 | if ($otp_enabled) { | |
262 | ||
263 | print "<p>".__("One time passwords are currently enabled. Change your current password and refresh this page to reconfigure.") . "</p>"; | |
264 | ||
265 | } else { | |
266 | ||
267 | print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>"; | |
268 | ||
269 | print "<p>".__("Scan the following code by the Authenticator application:")."</p>"; | |
270 | ||
271 | $csrf_token = $_SESSION["csrf_token"]; | |
272 | ||
273 | print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">"; | |
274 | ||
275 | print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">"; | |
276 | ||
277 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
278 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeotp\">"; | |
279 | ||
280 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
281 | evt.preventDefault(); | |
282 | if (this.validate()) { | |
283 | notify_progress('Saving data...', true); | |
284 | ||
285 | new Ajax.Request('backend.php', { | |
286 | parameters: dojo.objectToQuery(this.getValues()), | |
287 | onComplete: function(transport) { | |
288 | window.location.reload(); | |
289 | } }); | |
290 | ||
291 | } | |
292 | </script>"; | |
293 | ||
294 | print "<input dojoType=\"dijit.form.CheckBox\" required=\"1\" | |
295 | type=\"checkbox\" id=\"enable_otp\" name=\"enable_otp\"/> "; | |
296 | print "<label for=\"enable_otp\">".__("I have scanned the code and would like to enable OTP")."</label>"; | |
297 | ||
298 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
299 | __("Save OTP setting")."</button>"; | |
300 | ||
301 | print "</form>"; | |
302 | ||
303 | } | |
304 | ||
305 | } | |
1395083e AD |
306 | } |
307 | ||
d4c64ecc AD |
308 | print "</div>"; #pane |
309 | ||
1395083e AD |
310 | print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">"; |
311 | ||
312 | print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">"; | |
313 | ||
314 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
315 | evt.preventDefault(); | |
316 | if (this.validate()) { | |
317 | console.log(dojo.objectToQuery(this.getValues())); | |
318 | ||
319 | new Ajax.Request('backend.php', { | |
320 | parameters: dojo.objectToQuery(this.getValues()), | |
321 | onComplete: function(transport) { | |
322 | var msg = transport.responseText; | |
323 | if (msg.match('PREFS_THEME_CHANGED')) { | |
324 | window.location.reload(); | |
325 | } else { | |
326 | notify_info(msg); | |
327 | } | |
328 | } }); | |
329 | } | |
330 | </script>"; | |
331 | ||
332 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
333 | ||
334 | print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; | |
335 | ||
336 | if ($_SESSION["profile"]) { | |
337 | print_notice("Some preferences are only available in default profile."); | |
338 | } | |
339 | ||
340 | if ($_SESSION["profile"]) { | |
341 | initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]); | |
342 | $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; | |
343 | } else { | |
344 | initialize_user_prefs($this->link, $_SESSION["uid"]); | |
345 | $profile_qpart = "profile IS NULL"; | |
346 | } | |
347 | ||
f9ebb32c AD |
348 | if ($_SESSION["prefs_show_advanced"]) |
349 | $access_query = "true"; | |
350 | else | |
351 | $access_query = "(access_level = 0 AND section_id != 3)"; | |
352 | ||
ddb575c7 | 353 | $result = db_query($this->link, "SELECT DISTINCT |
1395083e | 354 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, |
f9ebb32c | 355 | ttrss_prefs_sections.order_id, |
1395083e AD |
356 | section_name,def_value,section_id |
357 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs | |
358 | WHERE type_id = ttrss_prefs_types.id AND | |
359 | $profile_qpart AND | |
360 | section_id = ttrss_prefs_sections.id AND | |
361 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
f9ebb32c | 362 | $access_query AND |
1395083e AD |
363 | short_desc != '' AND |
364 | owner_uid = ".$_SESSION["uid"]." | |
f9ebb32c | 365 | ORDER BY ttrss_prefs_sections.order_id,short_desc"); |
1395083e AD |
366 | |
367 | $lnum = 0; | |
368 | ||
369 | $active_section = ""; | |
370 | ||
371 | while ($line = db_fetch_assoc($result)) { | |
372 | ||
373 | if (in_array($line["pref_name"], $prefs_blacklist)) { | |
374 | continue; | |
375 | } | |
376 | ||
377 | if ($_SESSION["profile"] && in_array($line["pref_name"], | |
378 | $profile_blacklist)) { | |
379 | continue; | |
380 | } | |
381 | ||
382 | if ($active_section != $line["section_name"]) { | |
383 | ||
384 | if ($active_section != "") { | |
385 | print "</table>"; | |
386 | } | |
387 | ||
388 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
389 | ||
390 | $active_section = $line["section_name"]; | |
391 | ||
392 | print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>"; | |
393 | ||
394 | if ($line["section_id"] == 2) { | |
395 | print "<tr><td width=\"40%\">".__("Select theme")."</td>"; | |
396 | ||
397 | $user_theme = get_pref($this->link, "_THEME_ID"); | |
398 | $themes = get_all_themes(); | |
399 | ||
400 | print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">"; | |
401 | print "<option value='Default'>".__('Default')."</option>"; | |
402 | print "<option value='----------------' disabled=\"1\">--------</option>"; | |
403 | ||
404 | foreach ($themes as $t) { | |
405 | $base = $t['base']; | |
406 | $name = $t['name']; | |
407 | ||
408 | if ($base == $user_theme) { | |
409 | $selected = "selected=\"1\""; | |
410 | } else { | |
411 | $selected = ""; | |
412 | } | |
413 | ||
414 | print "<option $selected value='$base'>$name</option>"; | |
415 | ||
416 | } | |
417 | ||
418 | print "</select></td></tr>"; | |
419 | } | |
420 | $lnum = 0; | |
421 | } | |
422 | ||
423 | print "<tr>"; | |
424 | ||
425 | $type_name = $line["type_name"]; | |
426 | $pref_name = $line["pref_name"]; | |
427 | $value = $line["value"]; | |
428 | $def_value = $line["def_value"]; | |
429 | $help_text = $line["help_text"]; | |
430 | ||
431 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]); | |
432 | ||
433 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; | |
434 | ||
435 | print "</td>"; | |
436 | ||
437 | print "<td class=\"prefValue\">"; | |
438 | ||
439 | if ($pref_name == "USER_TIMEZONE") { | |
440 | ||
441 | $timezones = explode("\n", file_get_contents("lib/timezones.txt")); | |
442 | ||
443 | print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); | |
444 | } else if ($pref_name == "USER_STYLESHEET") { | |
445 | ||
446 | print "<button dojoType=\"dijit.form.Button\" | |
447 | onclick=\"customizeCSS()\">" . __('Customize') . "</button>"; | |
448 | ||
449 | } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") { | |
450 | ||
451 | $limits = array(15, 30, 45, 60); | |
452 | ||
453 | print_select($pref_name, $value, $limits, | |
454 | 'dojoType="dijit.form.Select"'); | |
455 | ||
456 | } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { | |
457 | ||
458 | global $update_intervals_nodefault; | |
459 | ||
460 | print_select_hash($pref_name, $value, $update_intervals_nodefault, | |
461 | 'dojoType="dijit.form.Select"'); | |
462 | ||
463 | } else if ($type_name == "bool") { | |
464 | ||
465 | if ($value == "true") { | |
466 | $value = __("Yes"); | |
467 | } else { | |
468 | $value = __("No"); | |
469 | } | |
470 | ||
471 | if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { | |
472 | $disabled = "disabled=\"1\""; | |
473 | $value = __("Yes"); | |
474 | } else { | |
475 | $disabled = ""; | |
476 | } | |
477 | ||
478 | print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")), | |
479 | $disabled); | |
480 | ||
481 | } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT', | |
482 | 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { | |
483 | ||
484 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
485 | ||
486 | if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { | |
487 | $disabled = "disabled=\"1\""; | |
488 | $value = FORCE_ARTICLE_PURGE; | |
489 | } else { | |
490 | $disabled = ""; | |
491 | } | |
492 | ||
493 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
494 | required=\"1\" $regexp $disabled | |
495 | name=\"$pref_name\" value=\"$value\">"; | |
496 | ||
497 | } else if ($pref_name == "SSL_CERT_SERIAL") { | |
498 | ||
499 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
500 | id=\"SSL_CERT_SERIAL\" readonly=\"1\" | |
501 | name=\"$pref_name\" value=\"$value\">"; | |
502 | ||
503 | $cert_serial = htmlspecialchars(get_ssl_certificate_id()); | |
504 | $has_serial = ($cert_serial) ? "false" : "true"; | |
505 | ||
506 | print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\" | |
507 | onclick=\"insertSSLserial('$cert_serial')\">" . | |
508 | __('Register') . "</button>"; | |
509 | ||
510 | print " <button dojoType=\"dijit.form.Button\" | |
511 | onclick=\"insertSSLserial('')\">" . | |
512 | __('Clear') . "</button>"; | |
513 | ||
76c843a9 | 514 | } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
61c1812f | 515 | print "<input dojoType=\"dijit.form.ValidationTextBox\" |
1b92f543 | 516 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
61c1812f | 517 | name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">". |
8eba830f | 518 | T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>"; |
1395083e AD |
519 | } else { |
520 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
521 | ||
522 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
523 | $regexp | |
524 | name=\"$pref_name\" value=\"$value\">"; | |
525 | } | |
526 | ||
527 | print "</td>"; | |
528 | ||
529 | print "</tr>"; | |
530 | ||
531 | $lnum++; | |
532 | } | |
533 | ||
534 | print "</table>"; | |
535 | ||
536 | print '</div>'; # inside pane | |
537 | print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; | |
538 | ||
539 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
540 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">"; | |
541 | ||
542 | print "<button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
543 | __('Save configuration')."</button> "; | |
544 | ||
545 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">". | |
546 | __('Manage profiles')."</button> "; | |
547 | ||
548 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">". | |
549 | __('Reset to defaults')."</button>"; | |
550 | ||
f9ebb32c AD |
551 | print " "; |
552 | ||
553 | $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : ""; | |
554 | ||
555 | print "<input onclick='toggleAdvancedPrefs()' | |
556 | id='prefs_show_advanced' | |
557 | dojoType=\"dijit.form.CheckBox\" | |
558 | $checked | |
559 | type=\"checkbox\"></input> | |
560 | <label for='prefs_show_advanced'>" . | |
561 | __("Show additional preferences") . "</label>"; | |
562 | ||
1395083e AD |
563 | print '</div>'; # inner pane |
564 | print '</div>'; # border container | |
1395083e AD |
565 | print "</form>"; |
566 | ||
567 | print "</div>"; #pane | |
27211afe AD |
568 | |
569 | ||
570 | if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE) && CHECK_FOR_NEW_VERSION) { | |
571 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Update Tiny Tiny RSS')."\">"; | |
572 | ||
573 | if ($_SESSION["pref_last_version_check"] + 86400 + rand(-1000, 1000) < time()) { | |
574 | $_SESSION["version_data"] = @check_for_update($this->link); | |
575 | $_SESSION["pref_last_version_check"] = time(); | |
576 | } | |
577 | ||
578 | if (is_array($_SESSION["version_data"])) { | |
579 | $version = $_SESSION["version_data"]["version"]; | |
580 | print_notice(T_sprintf("New version of Tiny Tiny RSS is available (%s).", "<b>$version</b>")); | |
581 | ||
582 | print "<p><button dojoType=\"dijit.form.Button\" onclick=\"return updateSelf()\">". | |
583 | __('Update Tiny Tiny RSS')."</button></p>"; | |
584 | ||
585 | } else { | |
12806125 | 586 | print_notice(__("Your Tiny Tiny RSS installation is up to date.")); |
27211afe AD |
587 | } |
588 | ||
589 | print "</div>"; #pane | |
590 | } | |
591 | ||
1395083e AD |
592 | print "</div>"; #container |
593 | } | |
27211afe AD |
594 | |
595 | function updateSelf() { | |
596 | print "<form style='display : block' name='self_update_form' id='self_update_form'>"; | |
597 | ||
598 | print "<div class='error'>".__("Do not close this dialog until updating is finished. Backup your tt-rss directory before continuing.")."</div>"; | |
599 | ||
808dd053 AD |
600 | print "<ul class='selfUpdateList' id='self_update_log'>"; |
601 | print "<li>" . __("Ready to update.") . "</li>"; | |
602 | print "</ul>"; | |
27211afe AD |
603 | |
604 | print "<div class='dlgButtons'>"; | |
605 | print "<button id=\"self_update_start_btn\" dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('updateSelfDlg').start()\" >". | |
606 | __("Start update")."</button>"; | |
808dd053 | 607 | print "<button id=\"self_update_stop_btn\" onclick=\"return dijit.byId('updateSelfDlg').close()\" dojoType=\"dijit.form.Button\">". |
27211afe AD |
608 | __("Close this window")."</button>"; |
609 | print "</div>"; | |
610 | print "</form>"; | |
611 | } | |
612 | ||
613 | function performUpdate() { | |
808dd053 AD |
614 | $step = (int) $_REQUEST["step"]; |
615 | $params = json_decode($_REQUEST["params"], true); | |
616 | $force = (bool) $_REQUEST["force"]; | |
617 | ||
27211afe AD |
618 | if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE) && CHECK_FOR_NEW_VERSION) { |
619 | include "update_self.php"; | |
808dd053 AD |
620 | |
621 | print json_encode(update_self_step($this->link, $step, $params, $force)); | |
27211afe AD |
622 | } |
623 | } | |
624 | ||
f9ebb32c AD |
625 | function toggleAdvanced() { |
626 | $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; | |
627 | } | |
fb70f26e AD |
628 | |
629 | function otpqrcode() { | |
630 | require_once "lib/otphp/vendor/base32.php"; | |
631 | require_once "lib/otphp/lib/otp.php"; | |
632 | require_once "lib/otphp/lib/totp.php"; | |
633 | require_once "lib/phpqrcode/phpqrcode.php"; | |
634 | ||
973392b9 | 635 | $result = db_query($this->link, "SELECT login,salt,otp_enabled |
fb70f26e AD |
636 | FROM ttrss_users |
637 | WHERE id = ".$_SESSION["uid"]); | |
638 | ||
639 | $base32 = new Base32(); | |
640 | ||
641 | $login = db_fetch_result($result, 0, "login"); | |
973392b9 | 642 | $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled")); |
fb70f26e | 643 | |
973392b9 AD |
644 | if (!$otp_enabled) { |
645 | $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt"))); | |
646 | $topt = new \OTPHP\TOTP($secret); | |
647 | print QRcode::png($topt->provisioning_uri($login)); | |
648 | } | |
fb70f26e AD |
649 | } |
650 | ||
651 | function changeotp() { | |
652 | $enable_otp = $_REQUEST["enable_otp"]; | |
653 | ||
654 | if ($enable_otp == "on") { | |
655 | db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE | |
656 | id = " . $_SESSION["uid"]); | |
657 | } | |
658 | } | |
1395083e AD |
659 | } |
660 | ?> |