]>
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"), ""), |
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, | |
e57a1507 | 117 | time() + COOKIE_LIFETIME_LONG); |
29c8fa08 AD |
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 | 370 | |
a845a3d5 | 371 | } else if (function_exists("imagecreatefromstring")) { |
fb70f26e AD |
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 | ||
a845a3d5 AD |
430 | } else { |
431 | ||
432 | print_notice(__("PHP GD functions are required for OTP support.")); | |
433 | ||
fb70f26e AD |
434 | } |
435 | ||
436 | } | |
1395083e AD |
437 | } |
438 | ||
1ffe3391 | 439 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
440 | "hook_prefs_tab_section", "prefPrefsAuth"); |
441 | ||
d4c64ecc AD |
442 | print "</div>"; #pane |
443 | ||
1395083e AD |
444 | print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">"; |
445 | ||
446 | print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">"; | |
447 | ||
122e9d78 AD |
448 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\"> |
449 | if (evt) evt.preventDefault(); | |
1395083e AD |
450 | if (this.validate()) { |
451 | console.log(dojo.objectToQuery(this.getValues())); | |
452 | ||
453 | new Ajax.Request('backend.php', { | |
454 | parameters: dojo.objectToQuery(this.getValues()), | |
455 | onComplete: function(transport) { | |
456 | var msg = transport.responseText; | |
29c8fa08 AD |
457 | if (quit) { |
458 | gotoMain(); | |
459 | } else { | |
460 | if (msg == 'PREFS_NEED_RELOAD') { | |
461 | window.location.reload(); | |
462 | } else { | |
463 | notify_info(msg); | |
464 | } | |
465 | } | |
1395083e AD |
466 | } }); |
467 | } | |
468 | </script>"; | |
469 | ||
470 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
471 | ||
472 | print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; | |
473 | ||
474 | if ($_SESSION["profile"]) { | |
9a73994c | 475 | print_notice(__("Some preferences are only available in default profile.")); |
1395083e AD |
476 | } |
477 | ||
478 | if ($_SESSION["profile"]) { | |
a42c55f0 | 479 | initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
1395083e AD |
480 | $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; |
481 | } else { | |
a42c55f0 | 482 | initialize_user_prefs($_SESSION["uid"]); |
1395083e AD |
483 | $profile_qpart = "profile IS NULL"; |
484 | } | |
485 | ||
744a1b00 | 486 | /* if ($_SESSION["prefs_show_advanced"]) |
f9ebb32c AD |
487 | $access_query = "true"; |
488 | else | |
744a1b00 AD |
489 | $access_query = "(access_level = 0 AND section_id != 3)"; */ |
490 | ||
491 | $access_query = 'true'; | |
f9ebb32c | 492 | |
d9c85e0f | 493 | $result = $this->dbh->query("SELECT DISTINCT |
dfad9d7a | 494 | ttrss_user_prefs.pref_name,value,type_name, |
f9ebb32c | 495 | ttrss_prefs_sections.order_id, |
dfad9d7a | 496 | def_value,section_id |
1395083e AD |
497 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
498 | WHERE type_id = ttrss_prefs_types.id AND | |
499 | $profile_qpart AND | |
500 | section_id = ttrss_prefs_sections.id AND | |
501 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
f9ebb32c | 502 | $access_query AND |
1395083e | 503 | owner_uid = ".$_SESSION["uid"]." |
dfad9d7a | 504 | ORDER BY ttrss_prefs_sections.order_id,pref_name"); |
1395083e AD |
505 | |
506 | $lnum = 0; | |
507 | ||
508 | $active_section = ""; | |
509 | ||
451ff722 AD |
510 | $listed_boolean_prefs = array(); |
511 | ||
d9c85e0f | 512 | while ($line = $this->dbh->fetch_assoc($result)) { |
1395083e AD |
513 | |
514 | if (in_array($line["pref_name"], $prefs_blacklist)) { | |
515 | continue; | |
516 | } | |
517 | ||
dfad9d7a AD |
518 | $type_name = $line["type_name"]; |
519 | $pref_name = $line["pref_name"]; | |
520 | $section_name = $this->getSectionName($line["section_id"]); | |
521 | $value = $line["value"]; | |
522 | ||
523 | $short_desc = $this->getShortDesc($pref_name); | |
524 | $help_text = $this->getHelpText($pref_name); | |
525 | ||
526 | if (!$short_desc) continue; | |
527 | ||
1395083e AD |
528 | if ($_SESSION["profile"] && in_array($line["pref_name"], |
529 | $profile_blacklist)) { | |
530 | continue; | |
531 | } | |
532 | ||
dfad9d7a | 533 | if ($active_section != $line["section_id"]) { |
1395083e AD |
534 | |
535 | if ($active_section != "") { | |
536 | print "</table>"; | |
537 | } | |
538 | ||
539 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
540 | ||
dfad9d7a | 541 | $active_section = $line["section_id"]; |
1395083e | 542 | |
dfad9d7a | 543 | print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>"; |
1395083e | 544 | |
1395083e | 545 | $lnum = 0; |
29c8fa08 AD |
546 | |
547 | if ($active_section == 2) { | |
548 | print "<tr>"; | |
549 | ||
550 | print "<td width=\"40%\" class=\"prefName\">"; | |
551 | print "<label>"; | |
552 | print __("Language:"); | |
553 | print "</label>"; | |
554 | ||
555 | print "<td>"; | |
556 | print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(), | |
557 | "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'"); | |
558 | print "</td>"; | |
559 | print "</tr>"; | |
560 | } | |
561 | ||
1395083e AD |
562 | } |
563 | ||
564 | print "<tr>"; | |
565 | ||
451ff722 AD |
566 | print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">"; |
567 | print "<label for='CB_$pref_name'>"; | |
dfad9d7a | 568 | print $short_desc; |
451ff722 | 569 | print "</label>"; |
1395083e AD |
570 | |
571 | if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; | |
572 | ||
573 | print "</td>"; | |
574 | ||
575 | print "<td class=\"prefValue\">"; | |
576 | ||
577 | if ($pref_name == "USER_TIMEZONE") { | |
578 | ||
579 | $timezones = explode("\n", file_get_contents("lib/timezones.txt")); | |
580 | ||
581 | print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); | |
582 | } else if ($pref_name == "USER_STYLESHEET") { | |
583 | ||
584 | print "<button dojoType=\"dijit.form.Button\" | |
585 | onclick=\"customizeCSS()\">" . __('Customize') . "</button>"; | |
586 | ||
5d40efc9 AD |
587 | } else if ($pref_name == "USER_CSS_THEME") { |
588 | ||
589 | $themes = array_map("basename", glob("themes/*.css")); | |
590 | ||
591 | print_select($pref_name, $value, $themes, | |
592 | 'dojoType="dijit.form.Select"'); | |
593 | ||
594 | ||
1395083e AD |
595 | } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
596 | ||
597 | global $update_intervals_nodefault; | |
598 | ||
599 | print_select_hash($pref_name, $value, $update_intervals_nodefault, | |
600 | 'dojoType="dijit.form.Select"'); | |
601 | ||
602 | } else if ($type_name == "bool") { | |
603 | ||
451ff722 AD |
604 | array_push($listed_boolean_prefs, $pref_name); |
605 | ||
606 | $checked = ($value == "true") ? "checked=\"checked\"" : ""; | |
1395083e AD |
607 | |
608 | if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { | |
609 | $disabled = "disabled=\"1\""; | |
451ff722 | 610 | $checked = "checked=\"checked\""; |
1395083e AD |
611 | } else { |
612 | $disabled = ""; | |
613 | } | |
614 | ||
451ff722 AD |
615 | print "<input type='checkbox' name='$pref_name' $checked $disabled |
616 | dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>"; | |
1395083e | 617 | |
f17cac6b | 618 | } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
1395083e AD |
619 | 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
620 | ||
621 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
622 | ||
623 | if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { | |
624 | $disabled = "disabled=\"1\""; | |
625 | $value = FORCE_ARTICLE_PURGE; | |
626 | } else { | |
627 | $disabled = ""; | |
628 | } | |
629 | ||
630 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
631 | required=\"1\" $regexp $disabled | |
632 | name=\"$pref_name\" value=\"$value\">"; | |
633 | ||
634 | } else if ($pref_name == "SSL_CERT_SERIAL") { | |
635 | ||
636 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
637 | id=\"SSL_CERT_SERIAL\" readonly=\"1\" | |
638 | name=\"$pref_name\" value=\"$value\">"; | |
639 | ||
640 | $cert_serial = htmlspecialchars(get_ssl_certificate_id()); | |
641 | $has_serial = ($cert_serial) ? "false" : "true"; | |
642 | ||
643 | print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\" | |
644 | onclick=\"insertSSLserial('$cert_serial')\">" . | |
645 | __('Register') . "</button>"; | |
646 | ||
647 | print " <button dojoType=\"dijit.form.Button\" | |
648 | onclick=\"insertSSLserial('')\">" . | |
649 | __('Clear') . "</button>"; | |
650 | ||
76c843a9 | 651 | } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
61c1812f | 652 | print "<input dojoType=\"dijit.form.ValidationTextBox\" |
1b92f543 | 653 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
61c1812f | 654 | name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">". |
8eba830f | 655 | T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>"; |
1395083e AD |
656 | } else { |
657 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; | |
658 | ||
659 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
660 | $regexp | |
661 | name=\"$pref_name\" value=\"$value\">"; | |
662 | } | |
663 | ||
664 | print "</td>"; | |
665 | ||
666 | print "</tr>"; | |
667 | ||
668 | $lnum++; | |
669 | } | |
670 | ||
671 | print "</table>"; | |
672 | ||
451ff722 AD |
673 | $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
674 | ||
675 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">"; | |
676 | ||
1ffe3391 | 677 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
678 | "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
679 | ||
1395083e AD |
680 | print '</div>'; # inside pane |
681 | print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; | |
682 | ||
683 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
684 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">"; | |
685 | ||
122e9d78 AD |
686 | print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\"> |
687 | <span>".__('Save configuration')."</span> | |
688 | <div dojoType=\"dijit.DropDownMenu\"> | |
689 | <div dojoType=\"dijit.MenuItem\" | |
690 | onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">". | |
691 | __("Save and exit preferences")."</div> | |
692 | </div> | |
693 | </div>"; | |
1395083e AD |
694 | |
695 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">". | |
696 | __('Manage profiles')."</button> "; | |
697 | ||
698 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">". | |
699 | __('Reset to defaults')."</button>"; | |
700 | ||
f9ebb32c AD |
701 | print " "; |
702 | ||
744a1b00 | 703 | /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : ""; |
f9ebb32c AD |
704 | |
705 | print "<input onclick='toggleAdvancedPrefs()' | |
706 | id='prefs_show_advanced' | |
707 | dojoType=\"dijit.form.CheckBox\" | |
708 | $checked | |
709 | type=\"checkbox\"></input> | |
710 | <label for='prefs_show_advanced'>" . | |
744a1b00 | 711 | __("Show additional preferences") . "</label>"; */ |
f9ebb32c | 712 | |
1ffe3391 | 713 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
714 | "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
715 | ||
de612e7a | 716 | print "</form>"; |
1395083e AD |
717 | print '</div>'; # inner pane |
718 | print '</div>'; # border container | |
de612e7a AD |
719 | |
720 | print "</div>"; #pane | |
721 | ||
722 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">"; | |
723 | ||
724 | print "<h2>".__("Plugins")."</h2>"; | |
725 | ||
6deafe90 | 726 | print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>"; |
65f85248 | 727 | |
6deafe90 | 728 | 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 |
729 | |
730 | print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; | |
731 | ||
732 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
733 | evt.preventDefault(); | |
734 | if (this.validate()) { | |
735 | notify_progress('Saving data...', true); | |
736 | ||
737 | new Ajax.Request('backend.php', { | |
738 | parameters: dojo.objectToQuery(this.getValues()), | |
739 | onComplete: function(transport) { | |
740 | notify(''); | |
741 | if (confirm(__('Selected plugins have been enabled. Reload?'))) { | |
742 | window.location.reload(); | |
743 | } | |
744 | } }); | |
745 | ||
746 | } | |
747 | </script>"; | |
748 | ||
749 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; | |
750 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">"; | |
751 | ||
65d1e250 | 752 | print "<table width='100%' class='prefPluginsList'>"; |
de612e7a AD |
753 | |
754 | print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>"; | |
755 | ||
756 | print "<tr class=\"title\"> | |
757 | <td width=\"5%\"> </td> | |
758 | <td width='10%'>".__('Plugin')."</td> | |
759 | <td width=''>".__('Description')."</td> | |
760 | <td width='5%'>".__('Version')."</td> | |
761 | <td width='10%'>".__('Author')."</td></tr>"; | |
762 | ||
763 | $system_enabled = array_map("trim", explode(",", PLUGINS)); | |
a42c55f0 | 764 | $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); |
de612e7a | 765 | |
72ff0137 | 766 | $tmppluginhost = new PluginHost(Db::get()); |
5d9abb1e AD |
767 | $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]); |
768 | $tmppluginhost->load_data(true); | |
de612e7a AD |
769 | |
770 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { | |
d2a421e3 | 771 | $about = $plugin->about(); |
de612e7a | 772 | |
23be0bd3 | 773 | if ($about[3] && strpos($name, "example") === FALSE) { |
de612e7a AD |
774 | if (in_array($name, $system_enabled)) { |
775 | $checked = "checked='1'"; | |
776 | } else { | |
777 | $checked = ""; | |
778 | } | |
779 | ||
780 | print "<tr>"; | |
781 | ||
782 | print "<td align='center'><input disabled='1' | |
783 | dojoType=\"dijit.form.CheckBox\" $checked | |
784 | type=\"checkbox\"></td>"; | |
785 | ||
786 | print "<td>$name</td>"; | |
bb5e1a32 AD |
787 | print "<td>" . htmlspecialchars($about[1]); |
788 | if (@$about[4]) { | |
789 | print " — <a target=\"_blank\" class=\"visibleLink\" | |
790 | href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>"; | |
791 | } | |
792 | print "</td>"; | |
de612e7a AD |
793 | print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>"; |
794 | print "<td>" . htmlspecialchars($about[2]) . "</td>"; | |
795 | ||
5d9abb1e | 796 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
81c54e3d AD |
797 | if (in_array($name, $system_enabled)) { |
798 | print "<td><a href='#' onclick=\"clearPluginData('$name')\" | |
799 | class='visibleLink'>".__("Clear data")."</a></td>"; | |
800 | } | |
5d9abb1e AD |
801 | } |
802 | ||
de612e7a AD |
803 | print "</tr>"; |
804 | ||
805 | } | |
806 | } | |
807 | ||
808 | print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>"; | |
809 | ||
810 | print "<tr class=\"title\"> | |
811 | <td width=\"5%\"> </td> | |
812 | <td width='10%'>".__('Plugin')."</td> | |
813 | <td width=''>".__('Description')."</td> | |
814 | <td width='5%'>".__('Version')."</td> | |
815 | <td width='10%'>".__('Author')."</td></tr>"; | |
816 | ||
817 | ||
818 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { | |
d2a421e3 | 819 | $about = $plugin->about(); |
de612e7a | 820 | |
23be0bd3 | 821 | if (!$about[3] && strpos($name, "example") === FALSE) { |
de612e7a AD |
822 | |
823 | if (in_array($name, $system_enabled)) { | |
824 | $checked = "checked='1'"; | |
825 | $disabled = "disabled='1'"; | |
65d1e250 | 826 | $rowclass = ''; |
de612e7a AD |
827 | } else if (in_array($name, $user_enabled)) { |
828 | $checked = "checked='1'"; | |
829 | $disabled = ""; | |
65d1e250 | 830 | $rowclass = "Selected"; |
de612e7a AD |
831 | } else { |
832 | $checked = ""; | |
833 | $disabled = ""; | |
65d1e250 | 834 | $rowclass = ''; |
de612e7a AD |
835 | } |
836 | ||
65d1e250 | 837 | print "<tr class='$rowclass'>"; |
de612e7a AD |
838 | |
839 | print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);' | |
840 | dojoType=\"dijit.form.CheckBox\" $checked $disabled | |
841 | type=\"checkbox\"></td>"; | |
842 | ||
65d1e250 | 843 | print "<td><label for='FPCHK-$name'>$name</label></td>"; |
bb5e1a32 AD |
844 | print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>"; |
845 | if (@$about[4]) { | |
846 | print " — <a target=\"_blank\" class=\"visibleLink\" | |
847 | href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>"; | |
848 | } | |
849 | print "</td>"; | |
850 | ||
de612e7a AD |
851 | print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>"; |
852 | print "<td>" . htmlspecialchars($about[2]) . "</td>"; | |
853 | ||
5d9abb1e | 854 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
81c54e3d AD |
855 | if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
856 | print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>"; | |
857 | } | |
5d9abb1e AD |
858 | } |
859 | ||
de612e7a AD |
860 | print "</tr>"; |
861 | ||
862 | ||
863 | ||
864 | } | |
865 | ||
866 | } | |
867 | ||
868 | print "</table>"; | |
869 | ||
870 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
871 | __("Enable selected plugins")."</button></p>"; | |
872 | ||
1395083e AD |
873 | print "</form>"; |
874 | ||
875 | print "</div>"; #pane | |
27211afe | 876 | |
1ffe3391 | 877 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
878 | "hook_prefs_tab", "prefPrefs"); |
879 | ||
1395083e AD |
880 | print "</div>"; #container |
881 | } | |
27211afe | 882 | |
f9ebb32c AD |
883 | function toggleAdvanced() { |
884 | $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; | |
885 | } | |
fb70f26e AD |
886 | |
887 | function otpqrcode() { | |
888 | require_once "lib/otphp/vendor/base32.php"; | |
889 | require_once "lib/otphp/lib/otp.php"; | |
890 | require_once "lib/otphp/lib/totp.php"; | |
891 | require_once "lib/phpqrcode/phpqrcode.php"; | |
892 | ||
d9c85e0f | 893 | $result = $this->dbh->query("SELECT login,salt,otp_enabled |
fb70f26e AD |
894 | FROM ttrss_users |
895 | WHERE id = ".$_SESSION["uid"]); | |
896 | ||
897 | $base32 = new Base32(); | |
898 | ||
d9c85e0f AD |
899 | $login = $this->dbh->fetch_result($result, 0, "login"); |
900 | $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled")); | |
fb70f26e | 901 | |
973392b9 | 902 | if (!$otp_enabled) { |
d9c85e0f | 903 | $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt"))); |
973392b9 AD |
904 | $topt = new \OTPHP\TOTP($secret); |
905 | print QRcode::png($topt->provisioning_uri($login)); | |
906 | } | |
fb70f26e AD |
907 | } |
908 | ||
3ca8af7f | 909 | function otpenable() { |
9deca86d AD |
910 | require_once "lib/otphp/vendor/base32.php"; |
911 | require_once "lib/otphp/lib/otp.php"; | |
912 | require_once "lib/otphp/lib/totp.php"; | |
913 | ||
914 | $password = $_REQUEST["password"]; | |
915 | $otp = $_REQUEST["otp"]; | |
3ca8af7f | 916 | |
1ffe3391 | 917 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
0f28f81f | 918 | |
3ca8af7f AD |
919 | if ($authenticator->check_password($_SESSION["uid"], $password)) { |
920 | ||
d9c85e0f | 921 | $result = $this->dbh->query("SELECT salt |
9deca86d AD |
922 | FROM ttrss_users |
923 | WHERE id = ".$_SESSION["uid"]); | |
924 | ||
925 | $base32 = new Base32(); | |
926 | ||
d9c85e0f | 927 | $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt"))); |
9deca86d AD |
928 | $topt = new \OTPHP\TOTP($secret); |
929 | ||
930 | $otp_check = $topt->now(); | |
931 | ||
932 | if ($otp == $otp_check) { | |
d9c85e0f | 933 | $this->dbh->query("UPDATE ttrss_users SET otp_enabled = true WHERE |
3ca8af7f AD |
934 | id = " . $_SESSION["uid"]); |
935 | ||
936 | print "OK"; | |
9deca86d AD |
937 | } else { |
938 | print "ERROR:".__("Incorrect one time password"); | |
3ca8af7f AD |
939 | } |
940 | } else { | |
9deca86d | 941 | print "ERROR:".__("Incorrect password"); |
3ca8af7f | 942 | } |
fb70f26e | 943 | |
3ca8af7f AD |
944 | } |
945 | ||
946 | function otpdisable() { | |
d9c85e0f | 947 | $password = $this->dbh->escape_string($_REQUEST["password"]); |
3ca8af7f | 948 | |
1ffe3391 | 949 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
3ca8af7f AD |
950 | |
951 | if ($authenticator->check_password($_SESSION["uid"], $password)) { | |
952 | ||
d9c85e0f | 953 | $this->dbh->query("UPDATE ttrss_users SET otp_enabled = false WHERE |
fb70f26e | 954 | id = " . $_SESSION["uid"]); |
3ca8af7f AD |
955 | |
956 | print "OK"; | |
957 | } else { | |
958 | print "ERROR: ".__("Incorrect password"); | |
fb70f26e | 959 | } |
3ca8af7f | 960 | |
fb70f26e | 961 | } |
de612e7a AD |
962 | |
963 | function setplugins() { | |
f4c02a15 AD |
964 | if (is_array($_REQUEST["plugins"])) |
965 | $plugins = join(",", $_REQUEST["plugins"]); | |
966 | else | |
967 | $plugins = ""; | |
de612e7a | 968 | |
a42c55f0 | 969 | set_pref("_ENABLED_PLUGINS", $plugins); |
de612e7a | 970 | } |
5d9abb1e AD |
971 | |
972 | function clearplugindata() { | |
d9c85e0f | 973 | $name = $this->dbh->escape_string($_REQUEST["name"]); |
5d9abb1e | 974 | |
1ffe3391 | 975 | PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name)); |
5d9abb1e | 976 | } |
00e34741 AD |
977 | |
978 | function customizeCSS() { | |
a42c55f0 | 979 | $value = get_pref("USER_STYLESHEET"); |
00e34741 AD |
980 | |
981 | $value = str_replace("<br/>", "\n", $value); | |
982 | ||
983 | 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")); | |
984 | ||
985 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; | |
986 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">"; | |
987 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">"; | |
988 | ||
989 | print "<table width='100%'><tr><td>"; | |
990 | print "<textarea dojoType=\"dijit.form.SimpleTextarea\" | |
991 | style='font-size : 12px; width : 100%; height: 200px;' | |
992 | placeHolder='body#ttrssMain { font-size : 14px; };' | |
993 | name='value'>$value</textarea>"; | |
994 | print "</td></tr></table>"; | |
995 | ||
996 | print "<div class='dlgButtons'>"; | |
997 | print "<button dojoType=\"dijit.form.Button\" | |
998 | onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> "; | |
999 | print "<button dojoType=\"dijit.form.Button\" | |
1000 | onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>"; | |
1001 | print "</div>"; | |
1002 | ||
1003 | } | |
1004 | ||
9d76e754 AD |
1005 | function editPrefProfiles() { |
1006 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1007 | ||
1008 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1009 | "<span>" . __('Select')."</span>"; | |
1010 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1011 | print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\" | |
1012 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1013 | print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\" | |
1014 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1015 | print "</div></div>"; | |
1016 | ||
1017 | print "<div style=\"float : right\">"; | |
1018 | ||
1019 | print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\" | |
1020 | required=\"1\"> | |
1021 | <button dojoType=\"dijit.form.Button\" | |
1022 | onclick=\"dijit.byId('profileEditDlg').addProfile()\">". | |
1023 | __('Create profile')."</button></div>"; | |
1024 | ||
1025 | print "</div>"; | |
1026 | ||
d9c85e0f | 1027 | $result = $this->dbh->query("SELECT title,id FROM ttrss_settings_profiles |
9d76e754 AD |
1028 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); |
1029 | ||
1030 | print "<div class=\"prefProfileHolder\">"; | |
1031 | ||
1032 | print "<form id=\"profile_edit_form\" onsubmit=\"return false\">"; | |
1033 | ||
1034 | print "<table width=\"100%\" class=\"prefFeedProfileList\" | |
1035 | cellspacing=\"0\" id=\"prefFeedProfileList\">"; | |
1036 | ||
1037 | print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd | |
1038 | ||
1039 | print "<td width='5%' align='center'><input | |
1040 | id='FCATC-0' | |
1041 | onclick='toggleSelectRow2(this);' | |
1042 | dojoType=\"dijit.form.CheckBox\" | |
1043 | type=\"checkbox\"></td>"; | |
1044 | ||
1045 | if (!$_SESSION["profile"]) { | |
1046 | $is_active = __("(active)"); | |
1047 | } else { | |
1048 | $is_active = ""; | |
1049 | } | |
1050 | ||
1051 | print "<td><span>" . | |
1052 | __("Default profile") . " $is_active</span></td>"; | |
1053 | ||
1054 | print "</tr>"; | |
1055 | ||
1056 | $lnum = 1; | |
1057 | ||
d9c85e0f | 1058 | while ($line = $this->dbh->fetch_assoc($result)) { |
9d76e754 AD |
1059 | |
1060 | $class = ($lnum % 2) ? "even" : "odd"; | |
1061 | ||
1062 | $profile_id = $line["id"]; | |
1063 | $this_row_id = "id=\"FCATR-$profile_id\""; | |
1064 | ||
1065 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1066 | ||
1067 | $edit_title = htmlspecialchars($line["title"]); | |
1068 | ||
1069 | print "<td width='5%' align='center'><input | |
1070 | onclick='toggleSelectRow2(this);' | |
1071 | id='FCATC-$profile_id' | |
1072 | dojoType=\"dijit.form.CheckBox\" | |
1073 | type=\"checkbox\"></td>"; | |
1074 | ||
1075 | if ($_SESSION["profile"] == $line["id"]) { | |
1076 | $is_active = __("(active)"); | |
1077 | } else { | |
1078 | $is_active = ""; | |
1079 | } | |
1080 | ||
1081 | print "<td><span dojoType=\"dijit.InlineEditBox\" | |
1082 | width=\"300px\" autoSave=\"false\" | |
1083 | profile-id=\"$profile_id\">" . $edit_title . | |
1084 | "<script type=\"dojo/method\" event=\"onChange\" args=\"item\"> | |
1085 | var elem = this; | |
1086 | dojo.xhrPost({ | |
1087 | url: 'backend.php', | |
1088 | content: {op: 'rpc', method: 'saveprofile', | |
1089 | value: this.value, | |
1090 | id: this.srcNodeRef.getAttribute('profile-id')}, | |
1091 | load: function(response) { | |
1092 | elem.attr('value', response); | |
1093 | } | |
1094 | }); | |
1095 | </script> | |
1096 | </span> $is_active</td>"; | |
1097 | ||
1098 | print "</tr>"; | |
1099 | ||
1100 | ++$lnum; | |
1101 | } | |
1102 | ||
1103 | print "</table>"; | |
1104 | print "</form>"; | |
1105 | print "</div>"; | |
1106 | ||
1107 | print "<div class='dlgButtons'> | |
1108 | <div style='float : left'> | |
1109 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">". | |
1110 | __('Remove selected profiles')."</button> | |
1111 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">". | |
1112 | __('Activate profile')."</button> | |
1113 | </div>"; | |
1114 | ||
1115 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">". | |
1116 | __('Close this window')."</button>"; | |
1117 | print "</div>"; | |
1118 | ||
1119 | } | |
1120 | ||
dfad9d7a AD |
1121 | private function getShortDesc($pref_name) { |
1122 | if (isset($this->pref_help[$pref_name])) { | |
1123 | return $this->pref_help[$pref_name][0]; | |
1124 | } | |
1125 | return ""; | |
1126 | } | |
9d76e754 | 1127 | |
dfad9d7a AD |
1128 | private function getHelpText($pref_name) { |
1129 | if (isset($this->pref_help[$pref_name])) { | |
1130 | return $this->pref_help[$pref_name][1]; | |
1131 | } | |
1132 | return ""; | |
1133 | } | |
1134 | ||
1135 | private function getSectionName($id) { | |
1136 | if (isset($this->pref_sections[$id])) { | |
1137 | return $this->pref_sections[$id]; | |
1138 | } | |
1139 | ||
1140 | return ""; | |
1141 | } | |
1395083e AD |
1142 | } |
1143 | ?> |