From 66665fba79c97dc3b96103e60945aedd0b9be676 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 14:00:36 +0400 Subject: add Pref_Users class --- classes/pref_users.php | 483 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 483 insertions(+) create mode 100644 classes/pref_users.php (limited to 'classes/pref_users.php') diff --git a/classes/pref_users.php b/classes/pref_users.php new file mode 100644 index 000000000..5f762b50e --- /dev/null +++ b/classes/pref_users.php @@ -0,0 +1,483 @@ +"; + + $uid = sprintf("%d", $_REQUEST["id"]); + + print "".__('User details').""; + + print "link, "SELECT login, + ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login, + access_level, + (SELECT COUNT(int_id) FROM ttrss_user_entries + WHERE owner_uid = id) AS stored_articles, + ".SUBSTRING_FOR_DATE."(created,1,16) AS created + FROM ttrss_users + WHERE id = '$uid'"); + + if (db_num_rows($result) == 0) { + print "

".__('User not found')."

"; + return; + } + + // print "

User Details

"; + + $login = db_fetch_result($result, 0, "login"); + + print ""; + + $last_login = make_local_datetime($this->link, + db_fetch_result($result, 0, "last_login"), true); + + $created = make_local_datetime($this->link, + db_fetch_result($result, 0, "created"), true); + + $access_level = db_fetch_result($result, 0, "access_level"); + $stored_articles = db_fetch_result($result, 0, "stored_articles"); + + print ""; + print ""; + + $result = db_query($this->link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds + WHERE owner_uid = '$uid'"); + + $num_feeds = db_fetch_result($result, 0, "num_feeds"); + + print ""; + + print "
".__('Registered')."$created
".__('Last logged in')."$last_login
".__('Subscribed feeds count')."$num_feeds
"; + + print "

".__('Subscribed feeds')."

"; + + $result = db_query($this->link, "SELECT id,title,site_url FROM ttrss_feeds + WHERE owner_uid = '$uid' ORDER BY title"); + + print ""; + + print "
+
"; + + print "]]>
"; + + return; + } + + function edit() { + global $access_level_names; + + header("Content-Type: text/xml"); + + $id = db_escape_string($_REQUEST["id"]); + + print ""; + print "".__('User Editor').""; + print ""; + + print ""; + print ""; + print ""; + + $result = db_query($this->link, "SELECT * FROM ttrss_users WHERE id = '$id'"); + + $login = db_fetch_result($result, 0, "login"); + $access_level = db_fetch_result($result, 0, "access_level"); + $email = db_fetch_result($result, 0, "email"); + + $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : ""; + + print "
".__("User")."
"; + print "
"; + + if ($sel_disabled) { + print ""; + print ""; + } else { + print ""; + } + + print "
"; + + print "
".__("Authentication")."
"; + print "
"; + + print __('Access level: ') . " "; + + if (!$sel_disabled) { + print_select_hash("access_level", $access_level, $access_level_names, + $sel_disabled); + } else { + print_select_hash("", $access_level, $access_level_names, + $sel_disabled); + print ""; + } + + print "
"; + + print __('Change password to') . + " "; + + print "
"; + + print "
".__("Options")."
"; + print "
"; + + print __('E-mail: '). + " "; + + print "
"; + + print ""; + + print ""; + + print "
+ +
"; + + print "]]>
"; + + return; + } + + function editSave() { + $login = db_escape_string(trim($_REQUEST["login"])); + $uid = db_escape_string($_REQUEST["id"]); + $access_level = (int) $_REQUEST["access_level"]; + $email = db_escape_string(trim($_REQUEST["email"])); + $password = db_escape_string(trim($_REQUEST["password"])); + + if ($password) { + $pwd_hash = encrypt_password($password, $login); + $pass_query_part = "pwd_hash = '$pwd_hash', "; + } else { + $pass_query_part = ""; + } + + db_query($this->link, "UPDATE ttrss_users SET $pass_query_part login = '$login', + access_level = '$access_level', email = '$email' WHERE id = '$uid'"); + + } + + function remove() { + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + if ($id != $_SESSION["uid"] && $id != 1) { + db_query($this->link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'"); + db_query($this->link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'"); + db_query($this->link, "DELETE FROM ttrss_users WHERE id = '$id'"); + } + } + } + + function add() { + + $login = db_escape_string(trim($_REQUEST["login"])); + $tmp_user_pwd = make_password(8); + $pwd_hash = encrypt_password($tmp_user_pwd, $login); + + $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE + login = '$login'"); + + if (db_num_rows($result) == 0) { + + db_query($this->link, "INSERT INTO ttrss_users + (login,pwd_hash,access_level,last_login,created) + VALUES ('$login', '$pwd_hash', 0, null, NOW())"); + + + $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE + login = '$login' AND pwd_hash = '$pwd_hash'"); + + if (db_num_rows($result) == 1) { + + $new_uid = db_fetch_result($result, 0, "id"); + + print format_notice(T_sprintf("Added user %s with password %s", + $login, $tmp_user_pwd)); + + initialize_user($this->link, $new_uid); + + } else { + + print format_warning(T_sprintf("Could not create user %s", $login)); + + } + } else { + print format_warning(T_sprintf("User %s already exists.", $login)); + } + } + + function resetPass() { + + $uid = db_escape_string($_REQUEST["id"]); + + $result = db_query($this->link, "SELECT login,email + FROM ttrss_users WHERE id = '$uid'"); + + $login = db_fetch_result($result, 0, "login"); + $email = db_fetch_result($result, 0, "email"); + $tmp_user_pwd = make_password(8); + $pwd_hash = encrypt_password($tmp_user_pwd, $login); + + db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' + WHERE id = '$uid'"); + + print T_sprintf("Changed password of user %s + to %s", $login, $tmp_user_pwd); + + require_once 'lib/phpmailer/class.phpmailer.php'; + + if ($email) { + print " "; + print T_sprintf("Notifying %s.", $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 PHPMailer(); + + $mail->PluginDir = "lib/phpmailer/"; + $mail->SetLanguage("en", "lib/phpmailer/language/"); + + $mail->CharSet = "UTF-8"; + + $mail->From = DIGEST_FROM_ADDRESS; + $mail->FromName = DIGEST_FROM_NAME; + $mail->AddAddress($email, $login); + + if (DIGEST_SMTP_HOST) { + $mail->Host = DIGEST_SMTP_HOST; + $mail->Mailer = "smtp"; + $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; + $mail->Username = DIGEST_SMTP_LOGIN; + $mail->Password = DIGEST_SMTP_PASSWORD; + } + + $mail->IsHTML(false); + $mail->Subject = __("[tt-rss] Password change notification"); + $mail->Body = $message; + + $rc = $mail->Send(); + + if (!$rc) print_error($mail->ErrorInfo); + } + + print ""; + } + + function index() { + + global $access_level_names; + + print "
"; + print "
"; + + print "
"; + + $user_search = db_escape_string($_REQUEST["search"]); + + if (array_key_exists("search", $_REQUEST)) { + $_SESSION["prefs_user_search"] = $user_search; + } else { + $user_search = $_SESSION["prefs_user_search"]; + } + + print "
+ + +
"; + + $sort = db_escape_string($_REQUEST["sort"]); + + if (!$sort || $sort == "undefined") { + $sort = "login"; + } + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print ""; + + print " + + + + "; + + print "
"; #toolbar + print "
"; #pane + print "
"; + + print "
"; + + if ($user_search) { + + $user_search = split(" ", $user_search); + $tokens = array(); + + foreach ($user_search as $token) { + $token = trim($token); + array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))"); + } + + $user_search_query = "(" . join($tokens, " AND ") . ") AND "; + + } else { + $user_search_query = ""; + } + + $result = db_query($this->link, "SELECT + id,login,access_level,email, + ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, + ".SUBSTRING_FOR_DATE."(created,1,16) as created + FROM + ttrss_users + WHERE + $user_search_query + id > 0 + ORDER BY $sort"); + + if (db_num_rows($result) > 0) { + + print "

"; + + print " + + + + + "; + + $lnum = 0; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + + $uid = $line["id"]; + + print ""; + + $line["login"] = htmlspecialchars($line["login"]); + + $line["created"] = make_local_datetime($this->link, $line["created"], false); + $line["last_login"] = make_local_datetime($this->link, $line["last_login"], false); + + print ""; + + $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; + + print ""; + + if (!$line["email"]) $line["email"] = " "; + + print ""; + print ""; + print ""; + + print ""; + + ++$lnum; + } + + print "
 ".__('Login')."".__('Access Level')."".__('Registered')."".__('Last login')."
" . $line["login"] . "" . $access_level_names[$line["access_level"]] . "" . $line["created"] . "" . $line["last_login"] . "
"; + + } else { + print "

"; + if (!$user_search) { + print_warning(__('No users defined.')); + } else { + print_warning(__('No matching users found.')); + } + print "

"; + + } + + print "
"; #pane + print "
"; #container + + } + + } +?> -- cgit v1.2.3-54-g00ecf From 46da73c255353a3f874d9742d7b2f9c64e7607b5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 14:15:42 +0400 Subject: implement ProtectedHandler --- classes/article.php | 2 +- classes/dlg.php | 16 ++++---- classes/feeds.php | 94 +++++++++++++++++++++---------------------- classes/pref_feeds.php | 12 +++--- classes/pref_filters.php | 2 +- classes/pref_labels.php | 2 +- classes/pref_prefs.php | 2 +- classes/pref_users.php | 2 +- classes/protected_handler.php | 8 ++++ classes/rpc.php | 10 ++--- 10 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 classes/protected_handler.php (limited to 'classes/pref_users.php') diff --git a/classes/article.php b/classes/article.php index 70ecd2653..90ca129b9 100644 --- a/classes/article.php +++ b/classes/article.php @@ -1,5 +1,5 @@ "; } function importOpml() { header("Content-Type: text/html"); # required for iframe - + print "
"; $owner_uid = $_SESSION["uid"]; @@ -534,7 +534,7 @@ class Dlg extends Handler { } function inactiveFeeds() { - + if (DB_TYPE == "pgsql") { $interval_qpart = "NOW() - INTERVAL '3 months'"; } else { @@ -714,7 +714,7 @@ class Dlg extends Handler { } function printTagSelect() { - + print "" . __('Select item(s) by tags') . ""; print "".__('View as RSS').""; print "link); $version = $version_data['version']; $id = $version_data['version_id']; diff --git a/classes/feeds.php b/classes/feeds.php index a654c92ae..f4d19c00c 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -1,11 +1,11 @@ link, "UPDATE ttrss_user_entries SET last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); ccache_zero_all($this->link, $_SESSION["uid"]); - } + } function collapse() { $cat_id = db_escape_string($_REQUEST["cid"]); @@ -15,36 +15,36 @@ class Feeds extends Handler { function index() { $root = (bool)$_REQUEST["root"]; - + if (!$root) { print json_encode(outputFeedList($this->link)); } else { - + $feeds = outputFeedList($this->link, false); - + $root = array(); $root['id'] = 'root'; $root['name'] = __('Feeds'); $root['items'] = $feeds['items']; - + $fl = array(); $fl['identifier'] = 'id'; $fl['label'] = 'name'; $fl['items'] = array($root); - + print json_encode($fl); } - } - + } + function view() { $timing_info = getmicrotime(); - + $reply = array(); - + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); - + $omode = db_escape_string($_REQUEST["omode"]); - + $feed = db_escape_string($_REQUEST["feed"]); $method = db_escape_string($_REQUEST["m"]); $view_mode = db_escape_string($_REQUEST["view_mode"]); @@ -54,19 +54,19 @@ class Feeds extends Handler { @$offset = db_escape_string($_REQUEST["skip"]); @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); $order_by = db_escape_string($_REQUEST["order_by"]); - + if (is_numeric($feed)) $feed = (int) $feed; - + /* Feed -5 is a special case: it is used to display auxiliary information * when there's nothing to load - e.g. no stuff in fresh feed */ - + if ($feed == -5) { print json_encode(generate_dashboard_feed($this->link)); return; } - + $result = false; - + if ($feed < -10) { $label_feed = -11-$feed; $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE @@ -78,45 +78,45 @@ class Feeds extends Handler { $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE id = '$feed' AND owner_uid = " . $_SESSION['uid']); } - + if ($result && db_num_rows($result) == 0) { print json_encode(generate_error_feed($this->link, __("Feed not found."))); return; } - + /* Updating a label ccache means recalculating all of the caches * so for performance reasons we don't do that here */ - + if ($feed >= 0) { ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view); } - + set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode); set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit); set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by); - + if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW() WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); } - + $reply['headlines'] = array(); - + if (!$next_unread_feed) $reply['headlines']['id'] = $feed; else $reply['headlines']['id'] = $next_unread_feed; - + $reply['headlines']['is_cat'] = (bool) $cat_view; - + $override_order = false; - + if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { $date_sort_field = "updated"; } else { $date_sort_field = "date_entered"; } - + switch ($order_by) { case "date": if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { @@ -125,7 +125,7 @@ class Feeds extends Handler { $override_order = "$date_sort_field DESC"; } break; - + case "title": if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { $override_order = "title DESC, $date_sort_field"; @@ -133,7 +133,7 @@ class Feeds extends Handler { $override_order = "title, $date_sort_field DESC"; } break; - + case "score": if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { $override_order = "score, $date_sort_field"; @@ -142,46 +142,46 @@ class Feeds extends Handler { } break; } - + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); - + $ret = format_headlines_list($this->link, $feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgroup_last_feed, $override_order); - + $topmost_article_ids = $ret[0]; $headlines_count = $ret[1]; $returned_feed = $ret[2]; $disable_cache = $ret[3]; $vgroup_last_feed = $ret[4]; - + $reply['headlines']['content'] =& $ret[5]['content']; $reply['headlines']['toolbar'] =& $ret[5]['toolbar']; - + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); - + $reply['headlines-info'] = array("count" => (int) $headlines_count, "vgroup_last_feed" => $vgroup_last_feed, "disable_cache" => (bool) $disable_cache); - + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); - + if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { $articles = array(); - + foreach ($topmost_article_ids as $id) { array_push($articles, format_article($this->link, $id, false)); } - + $reply['articles'] = $articles; } - + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); - + $reply['runtime-info'] = make_runtime_info($this->link); - + print json_encode($reply); - + } } -?> \ No newline at end of file +?> diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index bf15bf25a..783d29f79 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -1,5 +1,5 @@ "; @@ -529,7 +529,7 @@ class Pref_Feeds extends Handler { global $purge_intervals; global $update_intervals; global $update_methods; - + $feed_ids = db_escape_string($_REQUEST["ids"]); print ""; @@ -688,13 +688,13 @@ class Pref_Feeds extends Handler { function batchEditSave() { return editsaveops(true); } - + function editSave() { return editsaveops(false); } - - function editsaveops($batch) { - + + function editsaveops($batch) { + $feed_title = db_escape_string(trim($_POST["title"])); $feed_link = db_escape_string(trim($_POST["feed_url"])); $upd_intl = (int) db_escape_string($_POST["update_interval"]); diff --git a/classes/pref_filters.php b/classes/pref_filters.php index 754e8d211..fdae5f59e 100644 --- a/classes/pref_filters.php +++ b/classes/pref_filters.php @@ -1,5 +1,5 @@ diff --git a/classes/rpc.php b/classes/rpc.php index 8f03381f8..c6fc8c263 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -1,9 +1,9 @@ link)) { $omode = $_REQUEST["omode"]; - + if ($omode != "T") $reply['counters'] = getAllCounters($this->link, $omode); else @@ -403,11 +403,11 @@ class RPC extends Handler { function assigntolabel() { return labelops(true); } - + function removefromlabel() { return labelops(false); } - + function labelops($assign) { $reply = array(); -- cgit v1.2.3-54-g00ecf