]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/users.php
2 class Pref_Users
extends Handler_Protected
{
3 function before($method) {
4 if (parent
::before($method)) {
5 if ($_SESSION["access_level"] < 10) {
6 print __("Your access level is insufficient to open this tab.");
14 function csrf_ignore($method) {
15 $csrf_ignored = array("index");
17 return array_search($method, $csrf_ignored) !== false;
20 function userdetails() {
22 $uid = sprintf("%d", $_REQUEST["id"]);
24 $result = $this->dbh
->query("SELECT login,
25 ".SUBSTRING_FOR_DATE
."(last_login,1,16) AS last_login,
27 (SELECT COUNT(int_id) FROM ttrss_user_entries
28 WHERE owner_uid = id) AS stored_articles,
29 ".SUBSTRING_FOR_DATE
."(created,1,16) AS created
33 if ($this->dbh
->num_rows($result) == 0) {
34 print "<h1>".__('User not found')."</h1>";
38 // print "<h1>User Details</h1>";
40 $login = $this->dbh
->fetch_result($result, 0, "login");
42 print "<table width='100%'>";
44 $last_login = make_local_datetime(
45 $this->dbh
->fetch_result($result, 0, "last_login"), true);
47 $created = make_local_datetime(
48 $this->dbh
->fetch_result($result, 0, "created"), true);
50 $access_level = $this->dbh
->fetch_result($result, 0, "access_level");
51 $stored_articles = $this->dbh
->fetch_result($result, 0, "stored_articles");
53 print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
54 print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
56 $result = $this->dbh
->query("SELECT COUNT(id) as num_feeds FROM ttrss_feeds
57 WHERE owner_uid = '$uid'");
59 $num_feeds = $this->dbh
->fetch_result($result, 0, "num_feeds");
61 print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
65 print "<h1>".__('Subscribed feeds')."</h1>";
67 $result = $this->dbh
->query("SELECT id,title,site_url FROM ttrss_feeds
68 WHERE owner_uid = '$uid' ORDER BY title");
70 print "<ul class=\"userFeedList\">";
74 while ($line = $this->dbh
->fetch_assoc($result)) {
76 $icon_file = ICONS_URL
."/".$line["id"].".ico";
78 if (file_exists($icon_file) && filesize($icon_file) > 0) {
79 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
81 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
84 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
86 $row_class = $row_class == "even" ?
"odd" : "even";
90 if ($this->dbh
->num_rows($result) < $num_feeds) {
91 // FIXME - add link to show ALL subscribed feeds here somewhere
93 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
98 print "<div align='center'>
99 <button onclick=\"closeInfoBox()\">".__("Close this window").
106 global $access_level_names;
108 $id = $this->dbh
->escape_string($_REQUEST["id"]);
109 print "<form id=\"user_edit_form\" onsubmit='return false'>";
111 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
112 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
113 print "<input type=\"hidden\" name=\"method\" value=\"editSave\">";
115 $result = $this->dbh
->query("SELECT * FROM ttrss_users WHERE id = '$id'");
117 $login = $this->dbh
->fetch_result($result, 0, "login");
118 $access_level = $this->dbh
->fetch_result($result, 0, "access_level");
119 $email = $this->dbh
->fetch_result($result, 0, "email");
121 $sel_disabled = ($id == $_SESSION["uid"]) ?
"disabled" : "";
123 print "<div class=\"dlgSec\">".__("User")."</div>";
124 print "<div class=\"dlgSecCont\">";
127 print "<input type=\"hidden\" name=\"login\" value=\"$login\">";
128 print "<input size=\"30\" style=\"font-size : 16px\"
129 onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
132 print "<input size=\"30\" style=\"font-size : 16px\"
133 onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
134 name=\"login\" value=\"$login\">";
139 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
140 print "<div class=\"dlgSecCont\">";
142 print __('Access level: ') . " ";
144 if (!$sel_disabled) {
145 print_select_hash("access_level", $access_level, $access_level_names,
148 print_select_hash("", $access_level, $access_level_names,
150 print "<input type=\"hidden\" name=\"access_level\" value=\"$access_level\">";
155 print __('Change password to') .
156 " <input type=\"password\" size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\"
161 print "<div class=\"dlgSec\">".__("Options")."</div>";
162 print "<div class=\"dlgSecCont\">";
164 print __('E-mail: ').
165 " <input size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\"
174 print "<div class=\"dlgButtons\">
175 <button onclick=\"return userEditSave()\">".
176 __('Save')."</button>
177 <button onclick=\"return userEditCancel()\">".
178 __('Cancel')."</button></div>";
183 function editSave() {
184 $login = $this->dbh
->escape_string(trim($_REQUEST["login"]));
185 $uid = $this->dbh
->escape_string($_REQUEST["id"]);
186 $access_level = (int) $_REQUEST["access_level"];
187 $email = $this->dbh
->escape_string(trim($_REQUEST["email"]));
188 $password = $_REQUEST["password"];
191 $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
192 $pwd_hash = encrypt_password($password, $salt, true);
193 $pass_query_part = "pwd_hash = '$pwd_hash', salt = '$salt',";
195 $pass_query_part = "";
198 $this->dbh
->query("UPDATE ttrss_users SET $pass_query_part login = '$login',
199 access_level = '$access_level', email = '$email', otp_enabled = false
205 $ids = explode(",", $this->dbh
->escape_string($_REQUEST["ids"]));
207 foreach ($ids as $id) {
208 if ($id != $_SESSION["uid"] && $id != 1) {
209 $this->dbh
->query("DELETE FROM ttrss_tags WHERE owner_uid = '$id'");
210 $this->dbh
->query("DELETE FROM ttrss_feeds WHERE owner_uid = '$id'");
211 $this->dbh
->query("DELETE FROM ttrss_users WHERE id = '$id'");
218 $login = $this->dbh
->escape_string(trim($_REQUEST["login"]));
219 $tmp_user_pwd = make_password(8);
220 $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
221 $pwd_hash = encrypt_password($tmp_user_pwd, $salt, true);
223 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE
226 if ($this->dbh
->num_rows($result) == 0) {
228 $this->dbh
->query("INSERT INTO ttrss_users
229 (login,pwd_hash,access_level,last_login,created, salt)
230 VALUES ('$login', '$pwd_hash', 0, null, NOW(), '$salt')");
233 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE
234 login = '$login' AND pwd_hash = '$pwd_hash'");
236 if ($this->dbh
->num_rows($result) == 1) {
238 $new_uid = $this->dbh
->fetch_result($result, 0, "id");
240 print format_notice(T_sprintf("Added user <b>%s</b> with password <b>%s</b>",
241 $login, $tmp_user_pwd));
243 initialize_user($new_uid);
247 print format_warning(T_sprintf("Could not create user <b>%s</b>", $login));
251 print format_warning(T_sprintf("User <b>%s</b> already exists.", $login));
255 static function resetUserPassword($link, $uid, $show_password) {
257 $result = db_query($link, "SELECT login,email
258 FROM ttrss_users WHERE id = '$uid'");
260 $login = db_fetch_result($result, 0, "login");
261 $email = db_fetch_result($result, 0, "email");
262 $salt = db_fetch_result($result, 0, "salt");
264 $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
265 $tmp_user_pwd = make_password(8);
267 $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
269 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash', salt = '$new_salt'
272 if ($show_password) {
273 print T_sprintf("Changed password of user <b>%s</b> to <b>%s</b>", $login, $tmp_user_pwd);
275 print_notice(T_sprintf("Sending new password of user <b>%s</b> to <b>%s</b>", $login, $email));
278 require_once 'classes/ttrssmailer.php';
281 require_once "lib/MiniTemplator.class.php";
283 $tpl = new MiniTemplator
;
285 $tpl->readTemplateFromFile("templates/resetpass_template.txt");
287 $tpl->setVariable('LOGIN', $login);
288 $tpl->setVariable('NEWPASS', $tmp_user_pwd);
290 $tpl->addBlock('message');
294 $tpl->generateOutputToString($message);
296 $mail = new ttrssMailer();
298 $rc = $mail->quickMail($email, $login,
299 __("[tt-rss] Password change notification"),
302 if (!$rc) print_error($mail->ErrorInfo
);
306 function resetPass() {
307 $uid = $this->dbh
->escape_string($_REQUEST["id"]);
308 Pref_Users
::resetUserPassword($uid, true);
313 global $access_level_names;
315 print "<div id=\"pref-user-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
316 print "<div id=\"pref-user-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
318 print "<div id=\"pref-user-toolbar\" dojoType=\"dijit.Toolbar\">";
320 $user_search = $this->dbh
->escape_string($_REQUEST["search"]);
322 if (array_key_exists("search", $_REQUEST)) {
323 $_SESSION["prefs_user_search"] = $user_search;
325 $user_search = $_SESSION["prefs_user_search"];
328 print "<div style='float : right; padding-right : 4px;'>
329 <input dojoType=\"dijit.form.TextBox\" id=\"user_search\" size=\"20\" type=\"search\"
330 value=\"$user_search\">
331 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateUsersList()\">".
332 __('Search')."</button>
335 $sort = $this->dbh
->escape_string($_REQUEST["sort"]);
337 if (!$sort ||
$sort == "undefined") {
341 print "<div dojoType=\"dijit.form.DropDownButton\">".
342 "<span>" . __('Select')."</span>";
343 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
344 print "<div onclick=\"selectTableRows('prefUserList', 'all')\"
345 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
346 print "<div onclick=\"selectTableRows('prefUserList', 'none')\"
347 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
348 print "</div></div>";
350 print "<button dojoType=\"dijit.form.Button\" onclick=\"javascript:addUser()\">".__('Create user')."</button>";
353 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:selectedUserDetails()\">".
354 __('Details')."</button dojoType=\"dijit.form.Button\">
355 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:editSelectedUser()\">".
356 __('Edit')."</button dojoType=\"dijit.form.Button\">
357 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:removeSelectedUsers()\">".
358 __('Remove')."</button dojoType=\"dijit.form.Button\">
359 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:resetSelectedUserPass()\">".
360 __('Reset password')."</button dojoType=\"dijit.form.Button\">";
362 print "</div>"; #toolbar
363 print "</div>"; #pane
364 print "<div id=\"pref-user-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
366 print "<div id=\"sticky-status-msg\"></div>";
370 $user_search = explode(" ", $user_search);
373 foreach ($user_search as $token) {
374 $token = trim($token);
375 array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))");
378 $user_search_query = "(" . join($tokens, " AND ") . ") AND ";
381 $user_search_query = "";
384 $result = $this->dbh
->query("SELECT
385 id,login,access_level,email,
386 ".SUBSTRING_FOR_DATE
."(last_login,1,16) as last_login,
387 ".SUBSTRING_FOR_DATE
."(created,1,16) as created
395 if ($this->dbh
->num_rows($result) > 0) {
397 print "<p><table width=\"100%\" cellspacing=\"0\"
398 class=\"prefUserList\" id=\"prefUserList\">";
400 print "<tr class=\"title\">
401 <td align='center' width=\"5%\"> </td>
402 <td width='30%'><a href=\"#\" onclick=\"updateUsersList('login')\">".__('Login')."</a></td>
403 <td width='30%'><a href=\"#\" onclick=\"updateUsersList('access_level')\">".__('Access Level')."</a></td>
404 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('created')\">".__('Registered')."</a></td>
405 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('last_login')\">".__('Last login')."</a></td></tr>";
409 while ($line = $this->dbh
->fetch_assoc($result)) {
411 $class = ($lnum %
2) ?
"even" : "odd";
415 print "<tr id=\"UMRR-$uid\">";
417 $line["login"] = htmlspecialchars($line["login"]);
419 $line["created"] = make_local_datetime($line["created"], false);
420 $line["last_login"] = make_local_datetime($line["last_login"], false);
422 print "<td align='center'><input onclick='toggleSelectRow2(this);'
423 dojoType=\"dijit.form.CheckBox\" type=\"checkbox\"
424 id=\"UMCHK-$uid\"></td>";
426 $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'";
428 print "<td $onclick>" . $line["login"] . "</td>";
430 if (!$line["email"]) $line["email"] = " ";
432 print "<td $onclick>" . $access_level_names[$line["access_level"]] . "</td>";
433 print "<td $onclick>" . $line["created"] . "</td>";
434 print "<td $onclick>" . $line["last_login"] . "</td>";
446 print_warning(__('No users defined.'));
448 print_warning(__('No matching users found.'));
454 print "</div>"; #pane
456 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_PREFS_TAB
,
457 "hook_prefs_tab", "prefUsers");
459 print "</div>"; #container