]> git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
Report failed login attemps using user_error
[tt-rss.git] / classes / handler / public.php
1 <?php
2 class Handler_Public extends Handler {
3
4 private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
5 $limit, $offset, $search, $search_mode,
6 $view_mode = false, $format = 'atom', $order = false) {
7
8 require_once "lib/MiniTemplator.class.php";
9
10 $note_style = "background-color : #fff7d5;
11 border-width : 1px; ".
12 "padding : 5px; border-style : dashed; border-color : #e7d796;".
13 "margin-bottom : 1em; color : #9a8c59;";
14
15 if (!$limit) $limit = 60;
16
17 $date_sort_field = "date_entered DESC, updated DESC";
18
19 if ($feed == -2)
20 $date_sort_field = "last_published DESC";
21 else if ($feed == -1)
22 $date_sort_field = "last_marked DESC";
23
24 switch ($order) {
25 case "title":
26 $date_sort_field = "ttrss_entries.title";
27 break;
28 case "date_reverse":
29 $date_sort_field = "date_entered, updated";
30 break;
31 case "feed_dates":
32 $date_sort_field = "updated DESC";
33 break;
34 }
35
36 $qfh_ret = queryFeedHeadlines($feed,
37 1, $view_mode, $is_cat, $search, $search_mode,
38 $date_sort_field, $offset, $owner_uid,
39 false, 0, false, true);
40
41 $result = $qfh_ret[0];
42
43 if ($this->dbh->num_rows($result) != 0) {
44 $ts = strtotime($this->dbh->fetch_result($result, 0, "date_entered"));
45
46 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
47 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
48 header('HTTP/1.0 304 Not Modified');
49 return;
50 }
51
52 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
53 header("Last-Modified: $last_modified", true);
54 }
55
56 $qfh_ret = queryFeedHeadlines($feed,
57 $limit, $view_mode, $is_cat, $search, $search_mode,
58 $date_sort_field, $offset, $owner_uid,
59 false, 0, false, true);
60
61
62 $result = $qfh_ret[0];
63 $feed_title = htmlspecialchars($qfh_ret[1]);
64 $feed_site_url = $qfh_ret[2];
65 $last_error = $qfh_ret[3];
66
67 $feed_self_url = get_self_url_prefix() .
68 "/public.php?op=rss&id=-2&key=" .
69 get_feed_access_key(-2, false, $owner_uid);
70
71 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
72
73 if ($format == 'atom') {
74 $tpl = new MiniTemplator;
75
76 $tpl->readTemplateFromFile("templates/generated_feed.txt");
77
78 $tpl->setVariable('FEED_TITLE', $feed_title, true);
79 $tpl->setVariable('VERSION', VERSION, true);
80 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
81
82 if (PUBSUBHUBBUB_HUB && $feed == -2) {
83 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
84 $tpl->addBlock('feed_hub');
85 }
86
87 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
88
89 while ($line = $this->dbh->fetch_assoc($result)) {
90
91 $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
92 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
93 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
94 $tpl->setVariable('ARTICLE_EXCERPT',
95 truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
96
97 $content = sanitize($line["content_preview"], false, $owner_uid);
98
99 if ($line['note']) {
100 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
101 $content;
102 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
103 }
104
105 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
106
107 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
108 date('c', strtotime($line["updated"])), true);
109 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
110 date(DATE_RFC822, strtotime($line["updated"])), true);
111
112 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
113
114 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title']), true);
115
116 $tags = get_article_tags($line["id"], $owner_uid);
117
118 foreach ($tags as $tag) {
119 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
120 $tpl->addBlock('category');
121 }
122
123 $enclosures = get_article_enclosures($line["id"]);
124
125 foreach ($enclosures as $e) {
126 $type = htmlspecialchars($e['content_type']);
127 $url = htmlspecialchars($e['content_url']);
128 $length = $e['duration'];
129
130 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
131 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
132 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
133
134 $tpl->addBlock('enclosure');
135 }
136
137 $tpl->addBlock('entry');
138 }
139
140 $tmp = "";
141
142 $tpl->addBlock('feed');
143 $tpl->generateOutputToString($tmp);
144
145 if (@!$_REQUEST["noxml"]) {
146 header("Content-Type: text/xml; charset=utf-8");
147 } else {
148 header("Content-Type: text/plain; charset=utf-8");
149 }
150
151 print $tmp;
152 } else if ($format == 'json') {
153
154 $feed = array();
155
156 $feed['title'] = $feed_title;
157 $feed['version'] = VERSION;
158 $feed['feed_url'] = $feed_self_url;
159
160 if (PUBSUBHUBBUB_HUB && $feed == -2) {
161 $feed['hub_url'] = PUBSUBHUBBUB_HUB;
162 }
163
164 $feed['self_url'] = get_self_url_prefix();
165
166 $feed['articles'] = array();
167
168 while ($line = $this->dbh->fetch_assoc($result)) {
169 $article = array();
170
171 $article['id'] = $line['link'];
172 $article['link'] = $line['link'];
173 $article['title'] = $line['title'];
174 $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
175 $article['content'] = sanitize($line["content_preview"], false, $owner_uid);
176 $article['updated'] = date('c', strtotime($line["updated"]));
177
178 if ($line['note']) $article['note'] = $line['note'];
179 if ($article['author']) $article['author'] = $line['author'];
180
181 $tags = get_article_tags($line["id"], $owner_uid);
182
183 if (count($tags) > 0) {
184 $article['tags'] = array();
185
186 foreach ($tags as $tag) {
187 array_push($article['tags'], $tag);
188 }
189 }
190
191 $enclosures = get_article_enclosures($line["id"]);
192
193 if (count($enclosures) > 0) {
194 $article['enclosures'] = array();
195
196 foreach ($enclosures as $e) {
197 $type = $e['content_type'];
198 $url = $e['content_url'];
199 $length = $e['duration'];
200
201 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
202 }
203 }
204
205 array_push($feed['articles'], $article);
206 }
207
208 header("Content-Type: text/json; charset=utf-8");
209 print json_encode($feed);
210
211 } else {
212 header("Content-Type: text/plain; charset=utf-8");
213 print json_encode(array("error" => array("message" => "Unknown format")));
214 }
215 }
216
217 function getUnread() {
218 $login = $this->dbh->escape_string($_REQUEST["login"]);
219 $fresh = $_REQUEST["fresh"] == "1";
220
221 $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'");
222
223 if ($this->dbh->num_rows($result) == 1) {
224 $uid = $this->dbh->fetch_result($result, 0, "id");
225
226 print getGlobalUnread($uid);
227
228 if ($fresh) {
229 print ";";
230 print getFeedArticles(-3, false, true, $uid);
231 }
232
233 } else {
234 print "-1;User not found";
235 }
236
237 }
238
239 function getProfiles() {
240 $login = $this->dbh->escape_string($_REQUEST["login"]);
241
242 $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
243 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
244
245 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
246
247 print "<option value='0'>" . __("Default profile") . "</option>";
248
249 while ($line = $this->dbh->fetch_assoc($result)) {
250 $id = $line["id"];
251 $title = $line["title"];
252
253 print "<option value='$id'>$title</option>";
254 }
255
256 print "</select>";
257 }
258
259 function pubsub() {
260 $mode = $this->dbh->escape_string($_REQUEST['hub_mode']);
261 $feed_id = (int) $this->dbh->escape_string($_REQUEST['id']);
262 $feed_url = $this->dbh->escape_string($_REQUEST['hub_topic']);
263
264 if (!PUBSUBHUBBUB_ENABLED) {
265 header('HTTP/1.0 404 Not Found');
266 echo "404 Not found";
267 return;
268 }
269
270 // TODO: implement hub_verifytoken checking
271
272 $result = $this->dbh->query("SELECT feed_url FROM ttrss_feeds
273 WHERE id = '$feed_id'");
274
275 if ($this->dbh->num_rows($result) != 0) {
276
277 $check_feed_url = $this->dbh->fetch_result($result, 0, "feed_url");
278
279 if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
280 if ($mode == "subscribe") {
281
282 $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 2
283 WHERE id = '$feed_id'");
284
285 print $_REQUEST['hub_challenge'];
286 return;
287
288 } else if ($mode == "unsubscribe") {
289
290 $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0
291 WHERE id = '$feed_id'");
292
293 print $_REQUEST['hub_challenge'];
294 return;
295
296 } else if (!$mode) {
297
298 // Received update ping, schedule feed update.
299 //update_rss_feed($feed_id, true, true);
300
301 $this->dbh->query("UPDATE ttrss_feeds SET
302 last_update_started = '1970-01-01',
303 last_updated = '1970-01-01' WHERE id = '$feed_id'");
304
305 }
306 } else {
307 header('HTTP/1.0 404 Not Found');
308 echo "404 Not found";
309 }
310 } else {
311 header('HTTP/1.0 404 Not Found');
312 echo "404 Not found";
313 }
314
315 }
316
317 function logout() {
318 logout_user();
319 header("Location: index.php");
320 }
321
322 function share() {
323 $uuid = $this->dbh->escape_string($_REQUEST["key"]);
324
325 $result = $this->dbh->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
326 uuid = '$uuid'");
327
328 if ($this->dbh->num_rows($result) != 0) {
329 header("Content-Type: text/html");
330
331 $id = $this->dbh->fetch_result($result, 0, "ref_id");
332 $owner_uid = $this->dbh->fetch_result($result, 0, "owner_uid");
333
334 $article = format_article($id, false, true, $owner_uid);
335
336 print_r($article['content']);
337
338 } else {
339 print "Article not found.";
340 }
341
342 }
343
344 function rss() {
345 $feed = $this->dbh->escape_string($_REQUEST["id"]);
346 $key = $this->dbh->escape_string($_REQUEST["key"]);
347 $is_cat = $_REQUEST["is_cat"] != false;
348 $limit = (int)$this->dbh->escape_string($_REQUEST["limit"]);
349 $offset = (int)$this->dbh->escape_string($_REQUEST["offset"]);
350
351 $search = $this->dbh->escape_string($_REQUEST["q"]);
352 $search_mode = $this->dbh->escape_string($_REQUEST["smode"]);
353 $view_mode = $this->dbh->escape_string($_REQUEST["view-mode"]);
354 $order = $this->dbh->escape_string($_REQUEST["order"]);
355
356 $format = $this->dbh->escape_string($_REQUEST['format']);
357
358 if (!$format) $format = 'atom';
359
360 if (SINGLE_USER_MODE) {
361 authenticate_user("admin", null);
362 }
363
364 $owner_id = false;
365
366 if ($key) {
367 $result = $this->dbh->query("SELECT owner_uid FROM
368 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
369
370 if ($this->dbh->num_rows($result) == 1)
371 $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid");
372 }
373
374 if ($owner_id) {
375 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
376 $offset, $search, $search_mode, $view_mode, $format, $order);
377 } else {
378 header('HTTP/1.1 403 Forbidden');
379 }
380 }
381
382 function globalUpdateFeeds() {
383 include "rssfuncs.php";
384 // Update all feeds needing a update.
385 update_daemon_common(0, true, false);
386 housekeeping_common(false);
387
388 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
389
390 }
391
392 function sharepopup() {
393 if (SINGLE_USER_MODE) {
394 login_sequence();
395 }
396
397 header('Content-Type: text/html; charset=utf-8');
398 print "<html><head><title>Tiny Tiny RSS</title>";
399
400 stylesheet_tag("css/utility.css");
401 javascript_tag("lib/prototype.js");
402 javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls");
403 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
404 </head><body id='sharepopup'>";
405
406 $action = $_REQUEST["action"];
407
408 if ($_SESSION["uid"]) {
409
410 if ($action == 'share') {
411
412 $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"]));
413 $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"]));
414 $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"]));
415 $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"]));
416
417 Article::create_published_article($title, $url, $content, $labels,
418 $_SESSION["uid"]);
419
420 print "<script type='text/javascript'>";
421 print "window.close();";
422 print "</script>";
423
424 } else {
425 $title = htmlspecialchars($_REQUEST["title"]);
426 $url = htmlspecialchars($_REQUEST["url"]);
427
428 ?>
429
430 <table height='100%' width='100%'><tr><td colspan='2'>
431 <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
432 </td></tr>
433
434 <form id='share_form' name='share_form'>
435
436 <input type="hidden" name="op" value="sharepopup">
437 <input type="hidden" name="action" value="share">
438
439 <tr><td align='right'><?php echo __("Title:") ?></td>
440 <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
441 <tr><td align='right'><?php echo __("URL:") ?></td>
442 <td><input name='url' value="<?php echo $url ?>"></td></tr>
443 <tr><td align='right'><?php echo __("Content:") ?></td>
444 <td><input name='content' value=""></td></tr>
445 <tr><td align='right'><?php echo __("Labels:") ?></td>
446 <td><input name='labels' id="labels_value"
447 placeholder='Alpha, Beta, Gamma' value="">
448 </td></tr>
449
450 <tr><td>
451 <div class="autocomplete" id="labels_choices"
452 style="display : block"></div></td></tr>
453
454 <script type='text/javascript'>document.forms[0].title.focus();</script>
455
456 <script type='text/javascript'>
457 new Ajax.Autocompleter('labels_value', 'labels_choices',
458 "backend.php?op=rpc&method=completeLabels",
459 { tokens: ',', paramName: "search" });
460 </script>
461
462 <tr><td colspan='2'>
463 <div style='float : right' class='insensitive-small'>
464 <?php echo __("Shared article will appear in the Published feed.") ?>
465 </div>
466 <button type="submit"><?php echo __('Share') ?></button>
467 <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
468 </div>
469
470 </form>
471 </td></tr></table>
472 </body></html>
473 <?php
474
475 }
476
477 } else {
478
479 $return = urlencode($_SERVER["REQUEST_URI"])
480 ?>
481
482 <form action="public.php?return=<?php echo $return ?>"
483 method="POST" id="loginForm" name="loginForm">
484
485 <input type="hidden" name="op" value="login">
486
487 <table height='100%' width='100%'><tr><td colspan='2'>
488 <h1><?php echo __("Not logged in") ?></h1></td></tr>
489
490 <tr><td align="right"><?php echo __("Login:") ?></td>
491 <td align="right"><input name="login"
492 value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
493 <tr><td align="right"><?php echo __("Password:") ?></td>
494 <td align="right"><input type="password" name="password"
495 value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
496 <tr><td colspan='2'>
497 <button type="submit">
498 <?php echo __('Log in') ?></button>
499
500 <button onclick="return window.close()">
501 <?php echo __('Cancel') ?></button>
502 </td></tr>
503 </table>
504
505 </form>
506 <?php
507 }
508 }
509
510 function login() {
511 if (!SINGLE_USER_MODE) {
512
513 $login = $this->dbh->escape_string($_POST["login"]);
514 $password = $_POST["password"];
515 $remember_me = $_POST["remember_me"];
516
517 if ($remember_me) {
518 session_set_cookie_params(SESSION_COOKIE_LIFETIME);
519 } else {
520 session_set_cookie_params(0);
521 }
522
523 @session_start();
524
525 if (authenticate_user($login, $password)) {
526 $_POST["password"] = "";
527
528 if (get_schema_version() >= 120) {
529 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
530 }
531
532 $_SESSION["ref_schema_version"] = get_schema_version(true);
533 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
534
535 if ($_POST["profile"]) {
536
537 $profile = $this->dbh->escape_string($_POST["profile"]);
538
539 $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
540 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
541
542 if ($this->dbh->num_rows($result) != 0) {
543 $_SESSION["profile"] = $profile;
544 }
545 }
546 } else {
547 $_SESSION["login_error_msg"] = __("Incorrect username or password");
548 user_error("Failed login attempt from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
549 }
550
551 if ($_REQUEST['return']) {
552 header("Location: " . $_REQUEST['return']);
553 } else {
554 header("Location: " . SELF_URL_PATH);
555 }
556 }
557 }
558
559 function subscribe() {
560 if (SINGLE_USER_MODE) {
561 login_sequence();
562 }
563
564 if ($_SESSION["uid"]) {
565
566 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
567
568 header('Content-Type: text/html; charset=utf-8');
569 print "<html>
570 <head>
571 <title>Tiny Tiny RSS</title>
572 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
573 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
574 </head>
575 <body>
576 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
577 alt=\"Tiny Tiny RSS\"/>
578 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
579
580 $rc = subscribe_to_feed($feed_url);
581
582 switch ($rc['code']) {
583 case 0:
584 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
585 break;
586 case 1:
587 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
588 break;
589 case 2:
590 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
591 break;
592 case 3:
593 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
594 break;
595 case 4:
596 print_notice(__("Multiple feed URLs found."));
597 $feed_urls = $rc["feeds"];
598 break;
599 case 5:
600 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
601 break;
602 }
603
604 if ($feed_urls) {
605
606 print "<form action=\"public.php\">";
607 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
608
609 print "<select name=\"feed_url\">";
610
611 foreach ($feed_urls as $url => $name) {
612 $url = htmlspecialchars($url);
613 $name = htmlspecialchars($name);
614
615 print "<option value=\"$url\">$name</option>";
616 }
617
618 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
619 "\">";
620
621 print "</form>";
622 }
623
624 $tp_uri = get_self_url_prefix() . "/prefs.php";
625 $tt_uri = get_self_url_prefix();
626
627 if ($rc['code'] <= 2){
628 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
629 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
630
631 $feed_id = $this->dbh->fetch_result($result, 0, "id");
632 } else {
633 $feed_id = 0;
634 }
635 print "<p>";
636
637 if ($feed_id) {
638 print "<form method=\"GET\" style='display: inline'
639 action=\"$tp_uri\">
640 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
641 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
642 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
643 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
644 </form>";
645 }
646
647 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
648 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
649 </form></p>";
650
651 print "</div></body></html>";
652
653 } else {
654 render_login_form();
655 }
656 }
657
658 function subscribe2() {
659 $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
660 $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
661 $from = $this->dbh->escape_string($_REQUEST["from"]);
662 $feed_urls = array();
663
664 /* only read authentication information from POST */
665
666 $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
667 $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"]));
668
669 $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass);
670
671 switch ($rc) {
672 case 1:
673 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
674 break;
675 case 2:
676 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
677 break;
678 case 3:
679 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
680 break;
681 case 0:
682 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
683 break;
684 case 4:
685 print_notice(__("Multiple feed URLs found."));
686 $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
687 if (is_html($contents)) {
688 $feed_urls = get_feeds_from_html($url, $contents);
689 }
690 break;
691 case 5:
692 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
693 break;
694 }
695
696 if ($feed_urls) {
697 print "<form action=\"backend.php\">";
698 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
699 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
700 print "<input type=\"hidden\" name=\"method\" value=\"add\">";
701
702 print "<select name=\"feed_url\">";
703
704 foreach ($feed_urls as $url => $name) {
705 $url = htmlspecialchars($url);
706 $name = htmlspecialchars($name);
707 print "<option value=\"$url\">$name</option>";
708 }
709
710 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
711 print "</form>";
712 }
713
714 $tp_uri = get_self_url_prefix() . "/prefs.php";
715 $tt_uri = get_self_url_prefix();
716
717 if ($rc <= 2){
718 $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
719 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
720
721 $feed_id = $this->dbh->fetch_result($result, 0, "id");
722 } else {
723 $feed_id = 0;
724 }
725
726 print "<p>";
727
728 if ($feed_id) {
729 print "<form method=\"GET\" style='display: inline'
730 action=\"$tp_uri\">
731 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
732 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
733 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
734 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
735 </form>";
736 }
737
738 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
739 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
740 </form></p>";
741
742 print "</body></html>";
743 }
744
745 function index() {
746 header("Content-Type: text/plain");
747 print json_encode(array("error" => array("code" => 7)));
748 }
749
750 function forgotpass() {
751 startup_gettext();
752
753 header('Content-Type: text/html; charset=utf-8');
754 print "<html><head><title>Tiny Tiny RSS</title>";
755
756 stylesheet_tag("css/utility.css");
757 javascript_tag("lib/prototype.js");
758
759 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
760 </head><body id='forgotpass'>";
761
762 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
763 print "<h1>".__("Password recovery")."</h1>";
764 print "<div class='content'>";
765
766 @$method = $_POST['method'];
767
768 if (!$method) {
769 print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address."));
770
771 print "<form method='POST' action='public.php'>";
772 print "<input type='hidden' name='method' value='do'>";
773 print "<input type='hidden' name='op' value='forgotpass'>";
774
775 print "<fieldset>";
776 print "<label>".__("Login:")."</label>";
777 print "<input type='text' name='login' value='' required>";
778 print "</fieldset>";
779
780 print "<fieldset>";
781 print "<label>".__("Email:")."</label>";
782 print "<input type='email' name='email' value='' required>";
783 print "</fieldset>";
784
785 print "<fieldset>";
786 print "<label>".__("How much is two plus two:")."</label>";
787 print "<input type='text' name='test' value='' required>";
788 print "</fieldset>";
789
790 print "<p/>";
791 print "<button type='submit'>".__("Reset password")."</button>";
792
793 print "</form>";
794 } else if ($method == 'do') {
795
796 $login = $this->dbh->escape_string($_POST["login"]);
797 $email = $this->dbh->escape_string($_POST["email"]);
798 $test = $this->dbh->escape_string($_POST["test"]);
799
800 if (($test != 4 && $test != 'four') || !$email || !$login) {
801 print_error(__('Some of the required form parameters are missing or incorrect.'));
802
803 print "<form method=\"GET\" action=\"public.php\">
804 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
805 <input type=\"submit\" value=\"".__("Go back")."\">
806 </form>";
807
808 } else {
809
810 $result = $this->dbh->query("SELECT id FROM ttrss_users
811 WHERE login = '$login' AND email = '$email'");
812
813 if ($this->dbh->num_rows($result) != 0) {
814 $id = $this->dbh->fetch_result($result, 0, "id");
815
816 Pref_Users::resetUserPassword($id, false);
817
818 print "<p>";
819
820 print "<p>"."Completed."."</p>";
821
822 print "<form method=\"GET\" action=\"index.php\">
823 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
824 </form>";
825
826 } else {
827 print_error(__("Sorry, login and email combination not found."));
828
829 print "<form method=\"GET\" action=\"public.php\">
830 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
831 <input type=\"submit\" value=\"".__("Go back")."\">
832 </form>";
833
834 }
835 }
836
837 }
838
839 print "</div>";
840 print "</body>";
841 print "</html>";
842
843 }
844
845 function dbupdate() {
846 startup_gettext();
847
848 if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
849 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
850 render_login_form();
851 exit;
852 }
853
854 ?><html>
855 <head>
856 <title>Database Updater</title>
857 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
858 <link rel="stylesheet" type="text/css" href="css/utility.css"/>
859 </head>
860 <style type="text/css">
861 span.ok { color : #009000; font-weight : bold; }
862 span.err { color : #ff0000; font-weight : bold; }
863 </style>
864 <body>
865 <script type='text/javascript'>
866 function confirmOP() {
867 return confirm("Update the database?");
868 }
869 </script>
870
871 <div class="floatingLogo"><img src="images/logo_small.png"></div>
872
873 <h1><?php echo __("Database Updater") ?></h1>
874
875 <div class="content">
876
877 <?php
878 @$op = $_REQUEST["subop"];
879 $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
880
881 if ($op == "performupdate") {
882 if ($updater->isUpdateRequired()) {
883
884 print "<h2>Performing updates</h2>";
885
886 print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
887
888 print "<ul>";
889
890 for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
891 print "<li>Performing update up to version $i...";
892
893 $result = $updater->performUpdateTo($i);
894
895 if (!$result) {
896 print "<span class='err'>FAILED!</span></li></ul>";
897
898 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
899 print "<p><form method=\"GET\" action=\"index.php\">
900 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
901 </form>";
902
903 break;
904 } else {
905 print "<span class='ok'>OK!</span></li>";
906 }
907 }
908
909 print "</ul>";
910
911 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
912
913 print "<p><form method=\"GET\" action=\"index.php\">
914 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
915 </form>";
916
917 } else {
918 print "<h2>Your database is up to date.</h2>";
919
920 print "<p><form method=\"GET\" action=\"index.php\">
921 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
922 </form>";
923 }
924 } else {
925 if ($updater->isUpdateRequired()) {
926
927 print "<h2>Database update required</h2>";
928
929 print "<h3>";
930 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
931 $updater->getSchemaVersion(), SCHEMA_VERSION);
932 print "</h3>";
933
934 print_warning("Please backup your database before proceeding.");
935
936 print "<form method='POST'>
937 <input type='hidden' name='subop' value='performupdate'>
938 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
939 </form>";
940
941 } else {
942
943 print_notice("Tiny Tiny RSS database is up to date.");
944
945 print "<p><form method=\"GET\" action=\"index.php\">
946 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
947 </form>";
948
949 }
950 }
951 ?>
952
953 </div>
954 </body>
955 </html>
956 <?php
957 }
958
959 }
960 ?>