]>
Commit | Line | Data |
---|---|---|
1395083e | 1 | <?php |
dfad9d7a | 2 | |
369dbc19 | 3 | class Pref_Prefs extends Handler_Protected { |
1395083e | 4 | |
dfad9d7a AD |
5 | private $pref_help = array(); |
6 | private $pref_sections = array(); | |
7 | ||
8484ce22 | 8 | function csrf_ignore($method) { |
9d76e754 | 9 | $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles"); |
8484ce22 AD |
10 | |
11 | return array_search($method, $csrf_ignored) !== false; | |
12 | } | |
13 | ||
48ed517e AD |
14 | function __construct($args) { |
15 | parent::__construct($args); | |
dfad9d7a AD |
16 | |
17 | $this->pref_sections = array( | |
18 | 1 => __('General'), | |
19 | 2 => __('Interface'), | |
20 | 3 => __('Advanced'), | |
21 | 4 => __('Digest') | |
22 | ); | |
23 | ||
24 | $this->pref_help = array( | |
9db8e607 | 25 | "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""), |
9db8e607 AD |
26 | "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")), |
27 | "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")), | |
5f462963 | 28 | "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""), |
dfad9d7a | 29 | "COMBINED_DISPLAY_MODE" => array(__("Combined feed display"), __("Display expanded list of feed articles, instead of separate displays for headlines and article content")), |
5f462963 AD |
30 | "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feed as read"), ""), |
31 | "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once"), ""), | |
723bcdb2 | 32 | "DEFAULT_UPDATE_INTERVAL" => array(__("Default feed update interval"), __("Shortest interval at which a feed will be checked for updates regardless of update method")), |
5f462963 | 33 | "DIGEST_CATCHUP" => array(__("Mark articles in e-mail digest as read"), ""), |
9db8e607 | 34 | "DIGEST_ENABLE" => array(__("Enable e-mail digest"), __("This option enables sending daily digest of new (and unread) headlines on your configured e-mail address")), |
dfad9d7a | 35 | "DIGEST_PREFERRED_TIME" => array(__("Try to send digests around specified time"), __("Uses UTC timezone")), |
9db8e607 | 36 | "ENABLE_API_ACCESS" => array(__("Enable API access"), __("Allows external clients to access this account through the API")), |
5f462963 AD |
37 | "ENABLE_FEED_CATS" => array(__("Enable feed categories"), ""), |
38 | "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""), | |
39 | "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""), | |
40 | "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""), | |
9db8e607 | 41 | "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""), |
8429af52 | 42 | "LONG_DATE_FORMAT" => array(__("Long date format"), __("The syntax used is identical to the PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), |
dfad9d7a | 43 | "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")), |
5f462963 AD |
44 | "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""), |
45 | "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""), | |
46 | "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)"), ""), | |
47 | "SHORT_DATE_FORMAT" => array(__("Short date format"), ""), | |
48 | "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines list"), ""), | |
dfad9d7a AD |
49 | "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")), |
50 | "SSL_CERT_SERIAL" => array(__("Login with an SSL certificate"), __("Click to register your SSL client certificate with tt-rss")), | |
d4fef362 | 51 | "STRIP_IMAGES" => array(__("Do not embed media in articles"), ""), |
dfad9d7a | 52 | "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")), |
dfad9d7a | 53 | "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")), |
bd02d29e | 54 | "USER_TIMEZONE" => array(__("Time zone"), ""), |
8ef9645d | 55 | "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")), |
7b149552 | 56 | "USER_LANGUAGE" => array(__("Language")), |
bd02d29e | 57 | "USER_CSS_THEME" => array(__("Theme"), __("Select one of the available CSS themes")) |
dfad9d7a AD |
58 | ); |
59 | } | |
60 | ||
1395083e AD |
61 | function changepassword() { |
62 | ||
e6532439 AD |
63 | $old_pw = clean($_POST["old_password"]); |
64 | $new_pw = clean($_POST["new_password"]); | |
65 | $con_pw = clean($_POST["confirm_password"]); | |
1395083e AD |
66 | |
67 | if ($old_pw == "") { | |
5956f312 | 68 | print "ERROR: ".format_error("Old password cannot be blank."); |
1395083e AD |
69 | return; |
70 | } | |
71 | ||
72 | if ($new_pw == "") { | |
5956f312 | 73 | print "ERROR: ".format_error("New password cannot be blank."); |
1395083e AD |
74 | return; |
75 | } | |
76 | ||
77 | if ($new_pw != $con_pw) { | |
5956f312 | 78 | print "ERROR: ".format_error("Entered passwords do not match."); |
1395083e AD |
79 | return; |
80 | } | |
81 | ||
1ffe3391 | 82 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
1395083e | 83 | |
d5fd183d | 84 | if (method_exists($authenticator, "change_password")) { |
5956f312 | 85 | print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw)); |
098df83b | 86 | } else { |
5956f312 | 87 | print "ERROR: ".format_error("Function not supported by authentication module."); |
098df83b | 88 | } |
1395083e AD |
89 | } |
90 | ||
91 | function saveconfig() { | |
e6532439 | 92 | $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); |
451ff722 AD |
93 | |
94 | foreach ($boolean_prefs as $pref) { | |
95 | if (!isset($_POST[$pref])) $_POST[$pref] = 'false'; | |
96 | } | |
97 | ||
29c8fa08 AD |
98 | $need_reload = false; |
99 | ||
1395083e AD |
100 | foreach (array_keys($_POST) as $pref_name) { |
101 | ||
70393703 | 102 | $value = $_POST[$pref_name]; |
1395083e | 103 | |
1b9b19af | 104 | if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
a42c55f0 | 105 | if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
1b9b19af | 106 | |
70393703 AD |
107 | $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
108 | last_digest_sent = NULL WHERE id = ?"); | |
109 | $sth->execute([$_SESSION['uid']]); | |
1b9b19af AD |
110 | |
111 | } | |
112 | } | |
113 | ||
7b149552 | 114 | if ($pref_name == "USER_LANGUAGE") { |
29c8fa08 | 115 | if ($_SESSION["language"] != $value) { |
29c8fa08 AD |
116 | $need_reload = true; |
117 | } | |
29c8fa08 | 118 | } |
1395083e | 119 | |
7b149552 | 120 | set_pref($pref_name, $value); |
1395083e AD |
121 | } |
122 | ||
29c8fa08 AD |
123 | if ($need_reload) { |
124 | print "PREFS_NEED_RELOAD"; | |
125 | } else { | |
126 | print __("The configuration was saved."); | |
127 | } | |
1395083e AD |
128 | } |
129 | ||
1395083e AD |
130 | function changeemail() { |
131 | ||
e6532439 AD |
132 | $email = clean($_POST["email"]); |
133 | $full_name = clean($_POST["full_name"]); | |
1395083e AD |
134 | $active_uid = $_SESSION["uid"]; |
135 | ||
70393703 AD |
136 | $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?, |
137 | full_name = ? WHERE id = ?"); | |
138 | $sth->execute([$email, $full_name, $active_uid]); | |
1395083e AD |
139 | |
140 | print __("Your personal data has been saved."); | |
141 | ||
142 | return; | |
143 | } | |
144 | ||
145 | function resetconfig() { | |
146 | ||
147 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; | |
148 | ||
551f3c2c | 149 | $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs |
310c18e6 | 150 | WHERE (profile = :profile OR (:profile IS NULL AND profile IS NULL)) |
70393703 AD |
151 | AND owner_uid = :uid"); |
152 | $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); | |
1395083e | 153 | |
a42c55f0 | 154 | initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
bf878338 AD |
155 | |
156 | echo __("Your preferences are now set to default values."); | |
1395083e AD |
157 | } |
158 | ||
159 | function index() { | |
160 | ||
161 | global $access_level_names; | |
162 | ||
5bdcb8fd | 163 | $prefs_blacklist = array("ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES", |
78744d48 AD |
164 | "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT", |
165 | "FEEDS_SORT_BY_UNREAD"); | |
33b3db33 AD |
166 | |
167 | /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */ | |
1395083e AD |
168 | |
169 | $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", | |
170 | "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", | |
171 | "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", | |
172 | "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", | |
6d9455e9 | 173 | "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"); |
1395083e AD |
174 | |
175 | ||
d4c64ecc | 176 | $_SESSION["prefs_op_result"] = ""; |
1395083e | 177 | |
d4c64ecc AD |
178 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; |
179 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">"; | |
1395083e | 180 | |
d4c64ecc | 181 | print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">"; |
1395083e | 182 | |
d4c64ecc AD |
183 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
184 | evt.preventDefault(); | |
185 | if (this.validate()) { | |
186 | notify_progress('Saving data...', true); | |
1395083e | 187 | |
d4c64ecc AD |
188 | new Ajax.Request('backend.php', { |
189 | parameters: dojo.objectToQuery(this.getValues()), | |
190 | onComplete: function(transport) { | |
191 | notify_callback2(transport); | |
192 | } }); | |
1395083e | 193 | |
d4c64ecc AD |
194 | } |
195 | </script>"; | |
1395083e | 196 | |
d4c64ecc | 197 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
1395083e | 198 | |
fb70f26e AD |
199 | print "<h2>" . __("Personal data") . "</h2>"; |
200 | ||
70393703 | 201 | $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, |
d4c64ecc | 202 | access_level FROM ttrss_users |
70393703 AD |
203 | WHERE id = ?"); |
204 | $sth->execute([$_SESSION["uid"]]); | |
205 | $row = $sth->fetch(); | |
1395083e | 206 | |
70393703 AD |
207 | $email = htmlspecialchars($row["email"]); |
208 | $full_name = htmlspecialchars($row["full_name"]); | |
7c0eb1b6 | 209 | $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
1395083e | 210 | |
d4c64ecc AD |
211 | print "<tr><td width=\"40%\">".__('Full name')."</td>"; |
212 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\" | |
213 | value=\"$full_name\"></td></tr>"; | |
1395083e | 214 | |
d4c64ecc AD |
215 | print "<tr><td width=\"40%\">".__('E-mail')."</td>"; |
216 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>"; | |
1395083e | 217 | |
0d421af8 | 218 | if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
949b1a94 | 219 | |
70393703 | 220 | $access_level = $row["access_level"]; |
d4c64ecc AD |
221 | print "<tr><td width=\"40%\">".__('Access level')."</td>"; |
222 | print "<td>" . $access_level_names[$access_level] . "</td></tr>"; | |
223 | } | |
1395083e | 224 | |
d4c64ecc | 225 | print "</table>"; |
1395083e | 226 | |
328118d1 AD |
227 | print_hidden("op", "pref-prefs"); |
228 | print_hidden("method", "changeemail"); | |
1395083e | 229 | |
1bf468ba | 230 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\">". |
d4c64ecc | 231 | __("Save data")."</button>"; |
1395083e | 232 | |
d4c64ecc | 233 | print "</form>"; |
1395083e | 234 | |
0f28f81f | 235 | if ($_SESSION["auth_module"]) { |
1ffe3391 | 236 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
d5fd183d AD |
237 | } else { |
238 | $authenticator = false; | |
239 | } | |
240 | ||
241 | if ($authenticator && method_exists($authenticator, "change_password")) { | |
1395083e | 242 | |
fb70f26e AD |
243 | print "<h2>" . __("Password") . "</h2>"; |
244 | ||
5956f312 AD |
245 | print "<div style='display : none' id='pwd_change_infobox'></div>"; |
246 | ||
1395083e AD |
247 | print "<form dojoType=\"dijit.form.Form\">"; |
248 | ||
249 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
250 | evt.preventDefault(); | |
251 | if (this.validate()) { | |
252 | notify_progress('Changing password...', true); | |
253 | ||
254 | new Ajax.Request('backend.php', { | |
255 | parameters: dojo.objectToQuery(this.getValues()), | |
256 | onComplete: function(transport) { | |
257 | notify(''); | |
258 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
5956f312 AD |
259 | |
260 | $('pwd_change_infobox').innerHTML = | |
261 | transport.responseText.replace('ERROR: ', ''); | |
262 | ||
1395083e | 263 | } else { |
5956f312 AD |
264 | $('pwd_change_infobox').innerHTML = |
265 | transport.responseText.replace('ERROR: ', ''); | |
266 | ||
1395083e AD |
267 | var warn = $('default_pass_warning'); |
268 | if (warn) Element.hide(warn); | |
269 | } | |
5956f312 AD |
270 | |
271 | new Effect.Appear('pwd_change_infobox'); | |
272 | ||
1395083e AD |
273 | }}); |
274 | this.reset(); | |
275 | } | |
276 | </script>"; | |
277 | ||
3ca8af7f | 278 | if ($otp_enabled) { |
9a73994c | 279 | print_notice(__("Changing your current password will disable OTP.")); |
3ca8af7f AD |
280 | } |
281 | ||
1395083e AD |
282 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
283 | ||
284 | print "<tr><td width=\"40%\">".__("Old password")."</td>"; | |
285 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>"; | |
286 | ||
287 | print "<tr><td width=\"40%\">".__("New password")."</td>"; | |
288 | ||
289 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
290 | name=\"new_password\"></td></tr>"; | |
291 | ||
292 | print "<tr><td width=\"40%\">".__("Confirm password")."</td>"; | |
293 | ||
294 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>"; | |
295 | ||
296 | print "</table>"; | |
297 | ||
328118d1 AD |
298 | print_hidden("op", "pref-prefs"); |
299 | print_hidden("method", "changepassword"); | |
1395083e | 300 | |
1bf468ba | 301 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\">". |
1395083e AD |
302 | __("Change password")."</button>"; |
303 | ||
304 | print "</form>"; | |
305 | ||
0f28f81f | 306 | if ($_SESSION["auth_module"] == "auth_internal") { |
fb70f26e AD |
307 | |
308 | print "<h2>" . __("One time passwords / Authenticator") . "</h2>"; | |
309 | ||
310 | if ($otp_enabled) { | |
311 | ||
9a73994c | 312 | print_notice(__("One time passwords are currently enabled. Enter your current password below to disable.")); |
3ca8af7f AD |
313 | |
314 | print "<form dojoType=\"dijit.form.Form\">"; | |
315 | ||
316 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
317 | evt.preventDefault(); | |
318 | if (this.validate()) { | |
319 | notify_progress('Disabling OTP', true); | |
320 | ||
321 | new Ajax.Request('backend.php', { | |
322 | parameters: dojo.objectToQuery(this.getValues()), | |
323 | onComplete: function(transport) { | |
324 | notify(''); | |
325 | if (transport.responseText.indexOf('ERROR: ') == 0) { | |
326 | notify_error(transport.responseText.replace('ERROR: ', '')); | |
327 | } else { | |
328 | window.location.reload(); | |
329 | } | |
330 | }}); | |
331 | this.reset(); | |
332 | } | |
333 | </script>"; | |
334 | ||
335 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
336 | ||
337 | print "<tr><td width=\"40%\">".__("Enter your password")."</td>"; | |
338 | ||
339 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
340 | name=\"password\"></td></tr>"; | |
341 | ||
342 | print "</table>"; | |
343 | ||
328118d1 AD |
344 | print_hidden("op", "pref-prefs"); |
345 | print_hidden("method", "otpdisable"); | |
3ca8af7f AD |
346 | |
347 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
348 | __("Disable OTP")."</button>"; | |
349 | ||
350 | print "</form>"; | |
fb70f26e | 351 | |
a845a3d5 | 352 | } else if (function_exists("imagecreatefromstring")) { |
fb70f26e | 353 | |
11334fdf | 354 | print_warning(__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.")); |
fb70f26e AD |
355 | |
356 | print "<p>".__("Scan the following code by the Authenticator application:")."</p>"; | |
357 | ||
358 | $csrf_token = $_SESSION["csrf_token"]; | |
359 | ||
360 | print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">"; | |
361 | ||
362 | print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">"; | |
363 | ||
328118d1 AD |
364 | print_hidden("op", "pref-prefs"); |
365 | print_hidden("method", "otpenable"); | |
fb70f26e AD |
366 | |
367 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
368 | evt.preventDefault(); | |
369 | if (this.validate()) { | |
370 | notify_progress('Saving data...', true); | |
371 | ||
372 | new Ajax.Request('backend.php', { | |
373 | parameters: dojo.objectToQuery(this.getValues()), | |
374 | onComplete: function(transport) { | |
3ca8af7f | 375 | notify(''); |
9deca86d AD |
376 | if (transport.responseText.indexOf('ERROR:') == 0) { |
377 | notify_error(transport.responseText.replace('ERROR:', '')); | |
3ca8af7f AD |
378 | } else { |
379 | window.location.reload(); | |
380 | } | |
fb70f26e AD |
381 | } }); |
382 | ||
383 | } | |
384 | </script>"; | |
385 | ||
3ca8af7f AD |
386 | print "<table width=\"100%\" class=\"prefPrefsList\">"; |
387 | ||
388 | print "<tr><td width=\"40%\">".__("Enter your password")."</td>"; | |
389 | ||
390 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" | |
391 | name=\"password\"></td></tr>"; | |
392 | ||
9deca86d AD |
393 | print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>"; |
394 | ||
395 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\" | |
396 | required=\"1\" | |
397 | name=\"otp\"></td></tr>"; | |
3ca8af7f | 398 | |
9deca86d | 399 | print "<tr><td colspan=\"2\">"; |
fb70f26e | 400 | |
3ca8af7f AD |
401 | print "</td></tr><tr><td colspan=\"2\">"; |
402 | ||
403 | print "</td></tr>"; | |
404 | print "</table>"; | |
405 | ||
1bf468ba | 406 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\">". |
3ca8af7f | 407 | __("Enable OTP")."</button>"; |
fb70f26e AD |
408 | |
409 | print "</form>"; | |
410 | ||
a845a3d5 AD |
411 | } else { |
412 | ||
413 | print_notice(__("PHP GD functions are required for OTP support.")); | |
414 | ||
fb70f26e AD |
415 | } |
416 | ||
417 | } | |
1395083e AD |
418 | } |
419 | ||
1ffe3391 | 420 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
421 | "hook_prefs_tab_section", "prefPrefsAuth"); |
422 | ||
d4c64ecc AD |
423 | print "</div>"; #pane |
424 | ||
1395083e AD |
425 | print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">"; |
426 | ||
427 | print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">"; | |
428 | ||
122e9d78 AD |
429 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\"> |
430 | if (evt) evt.preventDefault(); | |
1395083e AD |
431 | if (this.validate()) { |
432 | console.log(dojo.objectToQuery(this.getValues())); | |
433 | ||
434 | new Ajax.Request('backend.php', { | |
435 | parameters: dojo.objectToQuery(this.getValues()), | |
436 | onComplete: function(transport) { | |
437 | var msg = transport.responseText; | |
29c8fa08 AD |
438 | if (quit) { |
439 | gotoMain(); | |
440 | } else { | |
441 | if (msg == 'PREFS_NEED_RELOAD') { | |
442 | window.location.reload(); | |
443 | } else { | |
444 | notify_info(msg); | |
445 | } | |
446 | } | |
1395083e AD |
447 | } }); |
448 | } | |
449 | </script>"; | |
450 | ||
451 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
452 | ||
453 | print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; | |
454 | ||
455 | if ($_SESSION["profile"]) { | |
9a73994c | 456 | print_notice(__("Some preferences are only available in default profile.")); |
1395083e AD |
457 | } |
458 | ||
459 | if ($_SESSION["profile"]) { | |
a42c55f0 | 460 | initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
1395083e | 461 | } else { |
a42c55f0 | 462 | initialize_user_prefs($_SESSION["uid"]); |
1395083e AD |
463 | } |
464 | ||
70393703 | 465 | $sth = $this->pdo->prepare("SELECT DISTINCT |
dfad9d7a | 466 | ttrss_user_prefs.pref_name,value,type_name, |
f9ebb32c | 467 | ttrss_prefs_sections.order_id, |
dfad9d7a | 468 | def_value,section_id |
1395083e AD |
469 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
470 | WHERE type_id = ttrss_prefs_types.id AND | |
70393703 | 471 | (profile = :profile OR (:profile IS NULL AND profile IS NULL)) AND |
1395083e AD |
472 | section_id = ttrss_prefs_sections.id AND |
473 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
70393703 | 474 | owner_uid = :uid |
dfad9d7a | 475 | ORDER BY ttrss_prefs_sections.order_id,pref_name"); |
70393703 | 476 | $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $_SESSION['profile']]); |
1395083e AD |
477 | |
478 | $lnum = 0; | |
479 | ||
480 | $active_section = ""; | |
481 | ||
451ff722 AD |
482 | $listed_boolean_prefs = array(); |
483 | ||
70393703 | 484 | while ($line = $sth->fetch()) { |
1395083e AD |
485 | |
486 | if (in_array($line["pref_name"], $prefs_blacklist)) { | |
487 | continue; | |
488 | } | |
489 | ||
dfad9d7a AD |
490 | $type_name = $line["type_name"]; |
491 | $pref_name = $line["pref_name"]; | |
492 | $section_name = $this->getSectionName($line["section_id"]); | |
493 | $value = $line["value"]; | |
494 | ||
495 | $short_desc = $this->getShortDesc($pref_name); | |
496 | $help_text = $this->getHelpText($pref_name); | |
497 | ||
498 | if (!$short_desc) continue; | |
499 | ||
1395083e AD |
500 | if ($_SESSION["profile"] && in_array($line["pref_name"], |
501 | $profile_blacklist)) { | |
502 | continue; | |
503 | } | |
504 | ||
dfad9d7a | 505 | if ($active_section != $line["section_id"]) { |
1395083e AD |
506 | |
507 | if ($active_section != "") { | |
508 | print "</table>"; | |
509 | } | |
510 | ||
511 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
512 | ||
dfad9d7a | 513 | $active_section = $line["section_id"]; |
1395083e | 514 | |
dfad9d7a | 515 | print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>"; |
1395083e | 516 | |
1395083e AD |
517 | $lnum = 0; |
518 | } | |
519 | ||
520 | print "<tr>"; | |
521 | ||
451ff722 AD |
522 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">"; |
523 | print "<label for='CB_$pref_name'>"; | |
dfad9d7a | 524 | print $short_desc; |
451ff722 | 525 | print "</label>"; |
1395083e AD |
526 | |
527 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; | |
528 | ||
529 | print "</td>"; | |
530 | ||
531 | print "<td class=\"prefValue\">"; | |
532 | ||
7b149552 AD |
533 | if ($pref_name == "USER_LANGUAGE") { |
534 | print_select_hash($pref_name, $value, get_translations(), | |
535 | "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'"); | |
536 | ||
537 | } else if ($pref_name == "USER_TIMEZONE") { | |
1395083e AD |
538 | |
539 | $timezones = explode("\n", file_get_contents("lib/timezones.txt")); | |
540 | ||
541 | print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); | |
542 | } else if ($pref_name == "USER_STYLESHEET") { | |
543 | ||
544 | print "<button dojoType=\"dijit.form.Button\" | |
545 | onclick=\"customizeCSS()\">" . __('Customize') . "</button>"; | |
546 | ||
5d40efc9 AD |
547 | } else if ($pref_name == "USER_CSS_THEME") { |
548 | ||
e432b8fb | 549 | $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css")); |
b9634eb8 AD |
550 | $themes = array_map("basename", $themes); |
551 | $themes = array_filter($themes, "theme_valid"); | |
552 | asort($themes); | |
5d40efc9 | 553 | |
22387de2 AD |
554 | if (!theme_valid($value)) $value = "default.php"; |
555 | ||
5d40efc9 AD |
556 | print_select($pref_name, $value, $themes, |
557 | 'dojoType="dijit.form.Select"'); | |
558 | ||
559 | ||
1395083e AD |
560 | } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
561 | ||
562 | global $update_intervals_nodefault; | |
563 | ||
564 | print_select_hash($pref_name, $value, $update_intervals_nodefault, | |
565 | 'dojoType="dijit.form.Select"'); | |
566 | ||
567 | } else if ($type_name == "bool") { | |
568 | ||
451ff722 AD |
569 | array_push($listed_boolean_prefs, $pref_name); |
570 | ||
571 | $checked = ($value == "true") ? "checked=\"checked\"" : ""; | |
1395083e AD |
572 | |
573 | if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { | |
574 | $disabled = "disabled=\"1\""; | |
451ff722 | 575 | $checked = "checked=\"checked\""; |
1395083e AD |
576 | } else { |
577 | $disabled = ""; | |
578 | } | |
579 | ||
451ff722 AD |
580 | print "<input type='checkbox' name='$pref_name' $checked $disabled |
581 | dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>"; | |
1395083e | 582 | |
f17cac6b | 583 | } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
1395083e AD |
584 | 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
585 | ||
586 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
587 | ||
588 | if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { | |
589 | $disabled = "disabled=\"1\""; | |
590 | $value = FORCE_ARTICLE_PURGE; | |
591 | } else { | |
592 | $disabled = ""; | |
593 | } | |
594 | ||
595 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
596 | required=\"1\" $regexp $disabled | |
597 | name=\"$pref_name\" value=\"$value\">"; | |
598 | ||
599 | } else if ($pref_name == "SSL_CERT_SERIAL") { | |
600 | ||
601 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
602 | id=\"SSL_CERT_SERIAL\" readonly=\"1\" | |
603 | name=\"$pref_name\" value=\"$value\">"; | |
604 | ||
605 | $cert_serial = htmlspecialchars(get_ssl_certificate_id()); | |
606 | $has_serial = ($cert_serial) ? "false" : "true"; | |
607 | ||
e79e274f AD |
608 | print "<br/>"; |
609 | ||
1395083e AD |
610 | print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\" |
611 | onclick=\"insertSSLserial('$cert_serial')\">" . | |
612 | __('Register') . "</button>"; | |
613 | ||
614 | print " <button dojoType=\"dijit.form.Button\" | |
615 | onclick=\"insertSSLserial('')\">" . | |
616 | __('Clear') . "</button>"; | |
617 | ||
76c843a9 | 618 | } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
61c1812f | 619 | print "<input dojoType=\"dijit.form.ValidationTextBox\" |
1b92f543 | 620 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
61c1812f | 621 | name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">". |
8eba830f | 622 | T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>"; |
1395083e AD |
623 | } else { |
624 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
625 | ||
626 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
627 | $regexp | |
628 | name=\"$pref_name\" value=\"$value\">"; | |
629 | } | |
630 | ||
631 | print "</td>"; | |
632 | ||
633 | print "</tr>"; | |
634 | ||
635 | $lnum++; | |
636 | } | |
637 | ||
638 | print "</table>"; | |
639 | ||
451ff722 AD |
640 | $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
641 | ||
328118d1 | 642 | print_hidden("boolean_prefs", "$listed_boolean_prefs"); |
451ff722 | 643 | |
1ffe3391 | 644 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
645 | "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
646 | ||
1395083e AD |
647 | print '</div>'; # inside pane |
648 | print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; | |
649 | ||
328118d1 AD |
650 | print_hidden("op", "pref-prefs"); |
651 | print_hidden("method", "saveconfig"); | |
1395083e | 652 | |
1bf468ba | 653 | print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\" class=\"btn-primary\"> |
122e9d78 AD |
654 | <span>".__('Save configuration')."</span> |
655 | <div dojoType=\"dijit.DropDownMenu\"> | |
656 | <div dojoType=\"dijit.MenuItem\" | |
657 | onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">". | |
658 | __("Save and exit preferences")."</div> | |
659 | </div> | |
660 | </div>"; | |
1395083e AD |
661 | |
662 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">". | |
663 | __('Manage profiles')."</button> "; | |
664 | ||
1bf468ba | 665 | print "<button dojoType=\"dijit.form.Button\" class=\"btn-danger\" onclick=\"return validatePrefsReset()\">". |
1395083e AD |
666 | __('Reset to defaults')."</button>"; |
667 | ||
f9ebb32c AD |
668 | print " "; |
669 | ||
1ffe3391 | 670 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
671 | "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
672 | ||
de612e7a | 673 | print "</form>"; |
1395083e AD |
674 | print '</div>'; # inner pane |
675 | print '</div>'; # border container | |
de612e7a AD |
676 | |
677 | print "</div>"; #pane | |
678 | ||
679 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">"; | |
680 | ||
667d32fd | 681 | print_notice(__("You will need to reload Tiny Tiny RSS for plugin changes to take effect.")); |
de612e7a | 682 | |
312742db AD |
683 | if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { |
684 | print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); | |
685 | } | |
686 | ||
de612e7a AD |
687 | print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; |
688 | ||
689 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
690 | evt.preventDefault(); | |
691 | if (this.validate()) { | |
692 | notify_progress('Saving data...', true); | |
693 | ||
694 | new Ajax.Request('backend.php', { | |
695 | parameters: dojo.objectToQuery(this.getValues()), | |
696 | onComplete: function(transport) { | |
697 | notify(''); | |
698 | if (confirm(__('Selected plugins have been enabled. Reload?'))) { | |
699 | window.location.reload(); | |
700 | } | |
701 | } }); | |
702 | ||
703 | } | |
704 | </script>"; | |
705 | ||
328118d1 AD |
706 | print_hidden("op", "pref-prefs"); |
707 | print_hidden("method", "setplugins"); | |
de612e7a | 708 | |
65d1e250 | 709 | print "<table width='100%' class='prefPluginsList'>"; |
de612e7a | 710 | |
667d32fd AD |
711 | print "<tr><td colspan='5'><h3>".__("System plugins")."</h3>". |
712 | format_notice(__("System plugins are enabled in <strong>config.php</strong> for all users.")). | |
713 | "</td></tr>"; | |
de612e7a AD |
714 | |
715 | print "<tr class=\"title\"> | |
716 | <td width=\"5%\"> </td> | |
717 | <td width='10%'>".__('Plugin')."</td> | |
718 | <td width=''>".__('Description')."</td> | |
719 | <td width='5%'>".__('Version')."</td> | |
720 | <td width='10%'>".__('Author')."</td></tr>"; | |
721 | ||
722 | $system_enabled = array_map("trim", explode(",", PLUGINS)); | |
e130b283 | 723 | $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS", $_SESSION['uid']))); |
de612e7a | 724 | |
6f7798b6 | 725 | $tmppluginhost = new PluginHost(); |
583f163f | 726 | $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); |
5d9abb1e | 727 | $tmppluginhost->load_data(true); |
de612e7a AD |
728 | |
729 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { | |
d2a421e3 | 730 | $about = $plugin->about(); |
de612e7a | 731 | |
b8774453 | 732 | if ($about[3]) { |
de612e7a AD |
733 | if (in_array($name, $system_enabled)) { |
734 | $checked = "checked='1'"; | |
735 | } else { | |
736 | $checked = ""; | |
737 | } | |
738 | ||
739 | print "<tr>"; | |
740 | ||
741 | print "<td align='center'><input disabled='1' | |
742 | dojoType=\"dijit.form.CheckBox\" $checked | |
743 | type=\"checkbox\"></td>"; | |
744 | ||
2f20dd58 AD |
745 | $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png"; |
746 | ||
06a39024 | 747 | print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>"; |
bb5e1a32 AD |
748 | print "<td>" . htmlspecialchars($about[1]); |
749 | if (@$about[4]) { | |
ba2853ca | 750 | print " — <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\" |
bb5e1a32 AD |
751 | href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>"; |
752 | } | |
753 | print "</td>"; | |
de612e7a AD |
754 | print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>"; |
755 | print "<td>" . htmlspecialchars($about[2]) . "</td>"; | |
756 | ||
5d9abb1e | 757 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
81c54e3d AD |
758 | if (in_array($name, $system_enabled)) { |
759 | print "<td><a href='#' onclick=\"clearPluginData('$name')\" | |
760 | class='visibleLink'>".__("Clear data")."</a></td>"; | |
761 | } | |
5d9abb1e AD |
762 | } |
763 | ||
de612e7a AD |
764 | print "</tr>"; |
765 | ||
766 | } | |
767 | } | |
768 | ||
769 | print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>"; | |
770 | ||
771 | print "<tr class=\"title\"> | |
772 | <td width=\"5%\"> </td> | |
773 | <td width='10%'>".__('Plugin')."</td> | |
774 | <td width=''>".__('Description')."</td> | |
775 | <td width='5%'>".__('Version')."</td> | |
776 | <td width='10%'>".__('Author')."</td></tr>"; | |
777 | ||
778 | ||
779 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { | |
d2a421e3 | 780 | $about = $plugin->about(); |
de612e7a | 781 | |
b8774453 | 782 | if (!$about[3]) { |
de612e7a AD |
783 | |
784 | if (in_array($name, $system_enabled)) { | |
785 | $checked = "checked='1'"; | |
786 | $disabled = "disabled='1'"; | |
65d1e250 | 787 | $rowclass = ''; |
de612e7a AD |
788 | } else if (in_array($name, $user_enabled)) { |
789 | $checked = "checked='1'"; | |
790 | $disabled = ""; | |
65d1e250 | 791 | $rowclass = "Selected"; |
de612e7a AD |
792 | } else { |
793 | $checked = ""; | |
794 | $disabled = ""; | |
65d1e250 | 795 | $rowclass = ''; |
de612e7a AD |
796 | } |
797 | ||
65d1e250 | 798 | print "<tr class='$rowclass'>"; |
de612e7a | 799 | |
2f20dd58 AD |
800 | $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png"; |
801 | ||
de612e7a AD |
802 | print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);' |
803 | dojoType=\"dijit.form.CheckBox\" $checked $disabled | |
804 | type=\"checkbox\"></td>"; | |
805 | ||
2f20dd58 | 806 | print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>"; |
bb5e1a32 AD |
807 | print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>"; |
808 | if (@$about[4]) { | |
ba2853ca | 809 | print " — <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\" |
bb5e1a32 AD |
810 | href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>"; |
811 | } | |
812 | print "</td>"; | |
813 | ||
de612e7a AD |
814 | print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>"; |
815 | print "<td>" . htmlspecialchars($about[2]) . "</td>"; | |
816 | ||
5d9abb1e | 817 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
81c54e3d AD |
818 | if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
819 | print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>"; | |
820 | } | |
5d9abb1e AD |
821 | } |
822 | ||
de612e7a AD |
823 | print "</tr>"; |
824 | ||
825 | ||
826 | ||
827 | } | |
828 | ||
829 | } | |
830 | ||
831 | print "</table>"; | |
832 | ||
833 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
834 | __("Enable selected plugins")."</button></p>"; | |
835 | ||
1395083e AD |
836 | print "</form>"; |
837 | ||
838 | print "</div>"; #pane | |
27211afe | 839 | |
1ffe3391 | 840 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
841 | "hook_prefs_tab", "prefPrefs"); |
842 | ||
1395083e AD |
843 | print "</div>"; #container |
844 | } | |
27211afe | 845 | |
f9ebb32c AD |
846 | function toggleAdvanced() { |
847 | $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; | |
848 | } | |
fb70f26e AD |
849 | |
850 | function otpqrcode() { | |
fb70f26e AD |
851 | require_once "lib/phpqrcode/phpqrcode.php"; |
852 | ||
70393703 | 853 | $sth = $this->pdo->prepare("SELECT login,salt,otp_enabled |
fb70f26e | 854 | FROM ttrss_users |
70393703 AD |
855 | WHERE id = ?"); |
856 | $sth->execute([$_SESSION['uid']]); | |
fb70f26e | 857 | |
70393703 | 858 | if ($row = $sth->fetch()) { |
fb70f26e | 859 | |
310c18e6 | 860 | $base32 = new \OTPHP\Base32(); |
fb70f26e | 861 | |
70393703 | 862 | $login = $row["login"]; |
7c0eb1b6 | 863 | $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
ab85ad89 | 864 | |
70393703 AD |
865 | if (!$otp_enabled) { |
866 | $secret = $base32->encode(sha1($row["salt"])); | |
867 | ||
868 | QRcode::png("otpauth://totp/".urlencode($login). | |
869 | "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS")); | |
870 | ||
871 | } | |
973392b9 | 872 | } |
fb70f26e AD |
873 | } |
874 | ||
3ca8af7f | 875 | function otpenable() { |
9deca86d | 876 | |
e6532439 AD |
877 | $password = clean($_REQUEST["password"]); |
878 | $otp = clean($_REQUEST["otp"]); | |
3ca8af7f | 879 | |
1ffe3391 | 880 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
0f28f81f | 881 | |
3ca8af7f AD |
882 | if ($authenticator->check_password($_SESSION["uid"], $password)) { |
883 | ||
1a727757 | 884 | $sth = $this->pdo->prepare("SELECT salt |
9deca86d | 885 | FROM ttrss_users |
70393703 AD |
886 | WHERE id = ?"); |
887 | $sth->execute([$_SESSION['uid']]); | |
9deca86d | 888 | |
70393703 | 889 | if ($row = $sth->fetch()) { |
9deca86d | 890 | |
310c18e6 | 891 | $base32 = new \OTPHP\Base32(); |
9deca86d | 892 | |
70393703 AD |
893 | $secret = $base32->encode(sha1($row["salt"])); |
894 | $topt = new \OTPHP\TOTP($secret); | |
9deca86d | 895 | |
70393703 | 896 | $otp_check = $topt->now(); |
3ca8af7f | 897 | |
70393703 | 898 | if ($otp == $otp_check) { |
310c18e6 | 899 | $sth = $this->pdo->prepare("UPDATE ttrss_users |
70393703 AD |
900 | SET otp_enabled = true WHERE id = ?"); |
901 | ||
902 | $sth->execute([$_SESSION['uid']]); | |
903 | ||
904 | print "OK"; | |
905 | } else { | |
906 | print "ERROR:".__("Incorrect one time password"); | |
907 | } | |
3ca8af7f | 908 | } |
70393703 | 909 | |
3ca8af7f | 910 | } else { |
9deca86d | 911 | print "ERROR:".__("Incorrect password"); |
3ca8af7f | 912 | } |
fb70f26e | 913 | |
3ca8af7f AD |
914 | } |
915 | ||
7c0eb1b6 AD |
916 | static function isdefaultpassword() { |
917 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); | |
918 | ||
d0cce0c7 AD |
919 | if ($authenticator && |
920 | method_exists($authenticator, "check_password") && | |
921 | $authenticator->check_password($_SESSION["uid"], "password")) { | |
922 | ||
7c0eb1b6 AD |
923 | return true; |
924 | } | |
925 | ||
926 | return false; | |
927 | } | |
928 | ||
3ca8af7f | 929 | function otpdisable() { |
e6532439 | 930 | $password = clean($_REQUEST["password"]); |
3ca8af7f | 931 | |
1ffe3391 | 932 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
3ca8af7f AD |
933 | |
934 | if ($authenticator->check_password($_SESSION["uid"], $password)) { | |
935 | ||
70393703 AD |
936 | $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE |
937 | id = ?"); | |
938 | $sth->execute([$_SESSION['uid']]); | |
3ca8af7f AD |
939 | |
940 | print "OK"; | |
941 | } else { | |
942 | print "ERROR: ".__("Incorrect password"); | |
fb70f26e | 943 | } |
3ca8af7f | 944 | |
fb70f26e | 945 | } |
de612e7a AD |
946 | |
947 | function setplugins() { | |
e6532439 AD |
948 | if (is_array(clean($_REQUEST["plugins"]))) |
949 | $plugins = join(",", clean($_REQUEST["plugins"])); | |
f4c02a15 AD |
950 | else |
951 | $plugins = ""; | |
de612e7a | 952 | |
e130b283 | 953 | set_pref("_ENABLED_PLUGINS", $plugins, $_SESSION["uid"]); |
de612e7a | 954 | } |
5d9abb1e AD |
955 | |
956 | function clearplugindata() { | |
e6532439 | 957 | $name = clean($_REQUEST["name"]); |
5d9abb1e | 958 | |
1ffe3391 | 959 | PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name)); |
5d9abb1e | 960 | } |
00e34741 AD |
961 | |
962 | function customizeCSS() { | |
a42c55f0 | 963 | $value = get_pref("USER_STYLESHEET"); |
00e34741 AD |
964 | |
965 | $value = str_replace("<br/>", "\n", $value); | |
966 | ||
5bbc4bb4 | 967 | 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.", "css/tt-rss.css")); |
00e34741 | 968 | |
328118d1 AD |
969 | print_hidden("op", "rpc"); |
970 | print_hidden("method", "setpref"); | |
971 | print_hidden("key", "USER_STYLESHEET"); | |
00e34741 AD |
972 | |
973 | print "<table width='100%'><tr><td>"; | |
974 | print "<textarea dojoType=\"dijit.form.SimpleTextarea\" | |
fb8a032a | 975 | style='font-size : 12px; width : 98%; height: 200px;' |
00e34741 AD |
976 | placeHolder='body#ttrssMain { font-size : 14px; };' |
977 | name='value'>$value</textarea>"; | |
978 | print "</td></tr></table>"; | |
979 | ||
980 | print "<div class='dlgButtons'>"; | |
981 | print "<button dojoType=\"dijit.form.Button\" | |
982 | onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> "; | |
983 | print "<button dojoType=\"dijit.form.Button\" | |
984 | onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>"; | |
985 | print "</div>"; | |
986 | ||
987 | } | |
988 | ||
9d76e754 AD |
989 | function editPrefProfiles() { |
990 | print "<div dojoType=\"dijit.Toolbar\">"; | |
991 | ||
992 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
993 | "<span>" . __('Select')."</span>"; | |
994 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
995 | print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\" | |
996 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
997 | print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\" | |
998 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
999 | print "</div></div>"; | |
1000 | ||
1001 | print "<div style=\"float : right\">"; | |
1002 | ||
1003 | print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\" | |
1004 | required=\"1\"> | |
1005 | <button dojoType=\"dijit.form.Button\" | |
1006 | onclick=\"dijit.byId('profileEditDlg').addProfile()\">". | |
1007 | __('Create profile')."</button></div>"; | |
1008 | ||
1009 | print "</div>"; | |
1010 | ||
70393703 AD |
1011 | $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles |
1012 | WHERE owner_uid = ? ORDER BY title"); | |
1013 | $sth->execute([$_SESSION['uid']]); | |
9d76e754 AD |
1014 | |
1015 | print "<div class=\"prefProfileHolder\">"; | |
1016 | ||
1017 | print "<form id=\"profile_edit_form\" onsubmit=\"return false\">"; | |
1018 | ||
1019 | print "<table width=\"100%\" class=\"prefFeedProfileList\" | |
1020 | cellspacing=\"0\" id=\"prefFeedProfileList\">"; | |
1021 | ||
1022 | print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd | |
1023 | ||
1024 | print "<td width='5%' align='center'><input | |
1025 | id='FCATC-0' | |
1026 | onclick='toggleSelectRow2(this);' | |
1027 | dojoType=\"dijit.form.CheckBox\" | |
1028 | type=\"checkbox\"></td>"; | |
1029 | ||
1030 | if (!$_SESSION["profile"]) { | |
1031 | $is_active = __("(active)"); | |
1032 | } else { | |
1033 | $is_active = ""; | |
1034 | } | |
1035 | ||
1036 | print "<td><span>" . | |
1037 | __("Default profile") . " $is_active</span></td>"; | |
1038 | ||
1039 | print "</tr>"; | |
1040 | ||
1041 | $lnum = 1; | |
1042 | ||
70393703 | 1043 | while ($line = $sth->fetch()) { |
9d76e754 | 1044 | |
9d76e754 AD |
1045 | $profile_id = $line["id"]; |
1046 | $this_row_id = "id=\"FCATR-$profile_id\""; | |
1047 | ||
1048 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1049 | ||
1050 | $edit_title = htmlspecialchars($line["title"]); | |
1051 | ||
1052 | print "<td width='5%' align='center'><input | |
1053 | onclick='toggleSelectRow2(this);' | |
1054 | id='FCATC-$profile_id' | |
1055 | dojoType=\"dijit.form.CheckBox\" | |
1056 | type=\"checkbox\"></td>"; | |
1057 | ||
1058 | if ($_SESSION["profile"] == $line["id"]) { | |
1059 | $is_active = __("(active)"); | |
1060 | } else { | |
1061 | $is_active = ""; | |
1062 | } | |
1063 | ||
1064 | print "<td><span dojoType=\"dijit.InlineEditBox\" | |
1065 | width=\"300px\" autoSave=\"false\" | |
1066 | profile-id=\"$profile_id\">" . $edit_title . | |
1067 | "<script type=\"dojo/method\" event=\"onChange\" args=\"item\"> | |
1068 | var elem = this; | |
1069 | dojo.xhrPost({ | |
1070 | url: 'backend.php', | |
1071 | content: {op: 'rpc', method: 'saveprofile', | |
1072 | value: this.value, | |
1073 | id: this.srcNodeRef.getAttribute('profile-id')}, | |
1074 | load: function(response) { | |
1075 | elem.attr('value', response); | |
1076 | } | |
1077 | }); | |
1078 | </script> | |
1079 | </span> $is_active</td>"; | |
1080 | ||
1081 | print "</tr>"; | |
1082 | ||
1083 | ++$lnum; | |
1084 | } | |
1085 | ||
1086 | print "</table>"; | |
1087 | print "</form>"; | |
1088 | print "</div>"; | |
1089 | ||
1090 | print "<div class='dlgButtons'> | |
1091 | <div style='float : left'> | |
1092 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">". | |
1093 | __('Remove selected profiles')."</button> | |
1094 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">". | |
1095 | __('Activate profile')."</button> | |
1096 | </div>"; | |
1097 | ||
1098 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">". | |
1099 | __('Close this window')."</button>"; | |
1100 | print "</div>"; | |
1101 | ||
1102 | } | |
1103 | ||
dfad9d7a AD |
1104 | private function getShortDesc($pref_name) { |
1105 | if (isset($this->pref_help[$pref_name])) { | |
1106 | return $this->pref_help[$pref_name][0]; | |
1107 | } | |
1108 | return ""; | |
1109 | } | |
9d76e754 | 1110 | |
dfad9d7a AD |
1111 | private function getHelpText($pref_name) { |
1112 | if (isset($this->pref_help[$pref_name])) { | |
1113 | return $this->pref_help[$pref_name][1]; | |
1114 | } | |
1115 | return ""; | |
1116 | } | |
1117 | ||
1118 | private function getSectionName($id) { | |
1119 | if (isset($this->pref_sections[$id])) { | |
1120 | return $this->pref_sections[$id]; | |
1121 | } | |
1122 | ||
1123 | return ""; | |
1124 | } | |
44c6a04b | 1125 | } |