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