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