/** * Send by mail a digest of last articles. * * @param mixed $link The database connection. * @param integer $limit The maximum number of articles by digest. * @return boolean Return false if digests are not enabled. */ function send_headlines_digests($debug = false) { require_once 'classes/ttrssmailer.php'; $user_limit = 15; // amount of users to process (e.g. emails to send out) $limit = 1000; // maximum amount of headlines to include if ($debug) { _debug("Sending digests, batch of max {$user_limit} users, headline limit = {$limit}"); } if (DB_TYPE == "pgsql") { $interval_query = "last_digest_sent < NOW() - INTERVAL '1 days'"; } elseif (DB_TYPE == "mysql") { $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; } $result = db_query("SELECT id,email FROM ttrss_users\n WHERE email != '' AND (last_digest_sent IS NULL OR {$interval_query})"); while ($line = db_fetch_assoc($result)) { if (@get_pref('DIGEST_ENABLE', $line['id'], false)) { $preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00')); // try to send digests within 2 hours of preferred time if ($preferred_ts && time() >= $preferred_ts && time() - $preferred_ts <= 7200) { if ($debug) { _debug("Sending digest for UID:" . $line['id'] . " - " . $line["email"]); } $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false); global $tz_offset; // reset tz_offset global to prevent tz cache clash between users $tz_offset = -1; $tuple = prepare_headlines_digest($line["id"], 1, $limit); $digest = $tuple[0]; $headlines_count = $tuple[1]; $affected_ids = $tuple[2]; $digest_text = $tuple[3]; if ($headlines_count > 0) { $mail = new ttrssMailer(); $rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); if (!$rc && $debug) { _debug("ERROR: " . $mail->ErrorInfo); } if ($debug) { _debug("RC={$rc}"); } if ($rc && $do_catchup) { if ($debug) { _debug("Marking affected articles as read..."); } catchupArticlesById($affected_ids, 0, $line["id"]); } } elseif ($debug) { _debug("No headlines"); } db_query("UPDATE ttrss_users SET last_digest_sent = NOW()\n WHERE id = " . $line["id"]); } } } if ($debug) { _debug("All done."); } }
static function resetUserPassword($uid, $show_password) { $result = db_query("SELECT login,email\n\t\t\t\tFROM ttrss_users WHERE id = '{$uid}'"); $login = db_fetch_result($result, 0, "login"); $email = db_fetch_result($result, 0, "email"); $salt = db_fetch_result($result, 0, "salt"); $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); $tmp_user_pwd = make_password(8); $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true); db_query("UPDATE ttrss_users SET pwd_hash = '{$pwd_hash}', salt = '{$new_salt}', otp_enabled = false\n\t\t\t\tWHERE id = '{$uid}'"); if ($show_password) { print T_sprintf("Changed password of user <b>%s</b> to <b>%s</b>", $login, $tmp_user_pwd); } else { print_notice(T_sprintf("Sending new password of user <b>%s</b> to <b>%s</b>", $login, $email)); } require_once 'classes/ttrssmailer.php'; if ($email) { require_once "lib/MiniTemplator.class.php"; $tpl = new MiniTemplator(); $tpl->readTemplateFromFile("templates/resetpass_template.txt"); $tpl->setVariable('LOGIN', $login); $tpl->setVariable('NEWPASS', $tmp_user_pwd); $tpl->addBlock('message'); $message = ""; $tpl->generateOutputToString($message); $mail = new ttrssMailer(); $rc = $mail->quickMail($email, $login, __("[tt-rss] Password change notification"), $message, false); if (!$rc) { print_error($mail->ErrorInfo); } } }
print "<p><form method=\"GET\" action=\"index.php\">\n\t\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t\t</form>"; } else { $new_uid = db_fetch_result($result, 0, "id"); initialize_user($new_uid); $reg_text = "Hi!\n" . "\n" . "You are receiving this message, because you (or somebody else) have opened\n" . "an account at Tiny Tiny RSS.\n" . "\n" . "Your login information is as follows:\n" . "\n" . "Login: {$login}\n" . "Password: {$password}\n" . "\n" . "Don't forget to login at least once to your new account, otherwise\n" . "it will be deleted in 24 hours.\n" . "\n" . "If that wasn't you, just ignore this message. Thanks."; $mail = new ttrssMailer(); $mail->IsHTML(false); $rc = $mail->quickMail($email, "", "Registration information for Tiny Tiny RSS", $reg_text, false); if (!$rc) { print_error($mail->ErrorInfo); } unset($reg_text); unset($mail); unset($rc); $reg_text = "Hi!\n" . "\n" . "New user had registered at your Tiny Tiny RSS installation.\n" . "\n" . "Login: {$login}\n" . "Email: {$email}\n"; $mail = new ttrssMailer(); $mail->IsHTML(false); $rc = $mail->quickMail(REG_NOTIFY_ADDRESS, "", "Registration notice for Tiny Tiny RSS", $reg_text, false); if (!$rc) { print_error($mail->ErrorInfo); } print_notice(__("Account created successfully.")); print "<p><form method=\"GET\" action=\"index.php\">\n\t\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t\t</form>"; } } } else { print_error('Plese check the form again, you have failed the robot test.'); print "<p><form method=\"GET\" action=\"index.php\">\n\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t</form>"; } } }
function sendEmail() { require_once 'classes/ttrssmailer.php'; $reply = array(); $mail = new ttrssMailer(); $mail->From = strip_tags($_REQUEST['from_email']); $mail->FromName = strip_tags($_REQUEST['from_name']); //$mail->AddAddress($_REQUEST['destination']); $addresses = explode(';', $_REQUEST['destination']); foreach ($addresses as $nextaddr) { $mail->AddAddress($nextaddr); } $mail->IsHTML(false); $mail->Subject = $_REQUEST['subject']; $mail->Body = $_REQUEST['content']; $rc = $mail->Send(); if (!$rc) { $reply['error'] = $mail->ErrorInfo; } else { save_email_address(db_escape_string($destination)); $reply['message'] = "UPDATE_COUNTERS"; } print json_encode($reply); }
function forgotpass() { startup_gettext(); @($hash = $_REQUEST["hash"]); header('Content-Type: text/html; charset=utf-8'); print "<html><head><title>Tiny Tiny RSS</title>\n\t\t<link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">\n\t\t<link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">"; echo stylesheet_tag("css/utility.css"); echo javascript_tag("lib/prototype.js"); print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n\t\t\t</head><body id='forgotpass'>"; print '<div class="floatingLogo"><img src="images/logo_small.png"></div>'; print "<h1>" . __("Password recovery") . "</h1>"; print "<div class='content'>"; @($method = $_POST['method']); if ($hash) { $login = $_REQUEST["login"]; if ($login) { $result = $this->dbh->query("SELECT id, resetpass_token FROM ttrss_users\n\t\t\t\t\tWHERE login = '******'"); if ($this->dbh->num_rows($result) != 0) { $id = $this->dbh->fetch_result($result, 0, "id"); $resetpass_token_full = $this->dbh->fetch_result($result, 0, "resetpass_token"); list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); if ($timestamp && $resetpass_token && $timestamp >= time() - 15 * 60 * 60 && $resetpass_token == $hash) { $result = $this->dbh->query("UPDATE ttrss_users SET resetpass_token = NULL\n\t\t\t\t\t\t\t\tWHERE id = {$id}"); Pref_Users::resetUserPassword($id, true); print "<p>" . "Completed." . "</p>"; } else { print_error("Some of the information provided is missing or incorrect."); } } else { print_error("Some of the information provided is missing or incorrect."); } } else { print_error("Some of the information provided is missing or incorrect."); } print "<form method=\"GET\" action=\"index.php\">\n\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t</form>"; } else { if (!$method) { print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address.")); print "<form method='POST' action='public.php'>"; print "<input type='hidden' name='method' value='do'>"; print "<input type='hidden' name='op' value='forgotpass'>"; print "<fieldset>"; print "<label>" . __("Login:"******"</label>"; print "<input type='text' name='login' value='' required>"; print "</fieldset>"; print "<fieldset>"; print "<label>" . __("Email:") . "</label>"; print "<input type='email' name='email' value='' required>"; print "</fieldset>"; print "<fieldset>"; print "<label>" . __("How much is two plus two:") . "</label>"; print "<input type='text' name='test' value='' required>"; print "</fieldset>"; print "<p/>"; print "<button type='submit'>" . __("Reset password") . "</button>"; print "</form>"; } else { if ($method == 'do') { $login = $this->dbh->escape_string($_POST["login"]); $email = $this->dbh->escape_string($_POST["email"]); $test = $this->dbh->escape_string($_POST["test"]); if ($test != 4 && $test != 'four' || !$email || !$login) { print_error(__('Some of the required form parameters are missing or incorrect.')); print "<form method=\"GET\" action=\"public.php\">\n\t\t\t\t\t<input type=\"hidden\" name=\"op\" value=\"forgotpass\">\n\t\t\t\t\t<input type=\"submit\" value=\"" . __("Go back") . "\">\n\t\t\t\t\t</form>"; } else { print_notice("Password reset instructions are being sent to your email address."); $result = $this->dbh->query("SELECT id FROM ttrss_users\n\t\t\t\t\tWHERE login = '******' AND email = '{$email}'"); if ($this->dbh->num_rows($result) != 0) { $id = $this->dbh->fetch_result($result, 0, "id"); if ($id) { $resetpass_token = sha1(get_random_bytes(128)); $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . "&login="******"lib/MiniTemplator.class.php"; $tpl = new MiniTemplator(); $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); $tpl->setVariable('LOGIN', $login); $tpl->setVariable('RESETPASS_LINK', $resetpass_link); $tpl->addBlock('message'); $message = ""; $tpl->generateOutputToString($message); $mail = new ttrssMailer(); $rc = $mail->quickMail($email, $login, __("[tt-rss] Password reset request"), $message, false); if (!$rc) { print_error($mail->ErrorInfo); } $resetpass_token_full = $this->dbh->escape_string(time() . ":" . $resetpass_token); $result = $this->dbh->query("UPDATE ttrss_users\n\t\t\t\t\t\t\tSET resetpass_token = '{$resetpass_token_full}'\n\t\t\t\t\t\t\tWHERE login = '******' AND email = '{$email}'"); //Pref_Users::resetUserPassword($id, false); print "<p>"; print "<p>" . "Completed." . "</p>"; } else { print_error("User ID not found."); } print "<form method=\"GET\" action=\"index.php\">\n\t\t\t\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t\t\t\t</form>"; } else { print_error(__("Sorry, login and email combination not found.")); print "<form method=\"GET\" action=\"public.php\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"op\" value=\"forgotpass\">\n\t\t\t\t\t\t<input type=\"submit\" value=\"" . __("Go back") . "\">\n\t\t\t\t\t\t</form>"; } } } } } print "</div>"; print "</body>"; print "</html>"; }