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