]>
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 header("Content-Type: text/xml");
25 $uid = sprintf("%d", $_REQUEST["id"]);
27 print "<title>".__('User details')."</title>";
29 print "<content><![CDATA[";
31 $result = db_query($this->link
, "SELECT login,
32 ".SUBSTRING_FOR_DATE
."(last_login,1,16) AS last_login,
34 (SELECT COUNT(int_id) FROM ttrss_user_entries
35 WHERE owner_uid = id) AS stored_articles,
36 ".SUBSTRING_FOR_DATE
."(created,1,16) AS created
40 if (db_num_rows($result) == 0) {
41 print "<h1>".__('User not found')."</h1>";
45 // print "<h1>User Details</h1>";
47 $login = db_fetch_result($result, 0, "login");
49 print "<table width='100%'>";
51 $last_login = make_local_datetime($this->link
,
52 db_fetch_result($result, 0, "last_login"), true);
54 $created = make_local_datetime($this->link
,
55 db_fetch_result($result, 0, "created"), true);
57 $access_level = db_fetch_result($result, 0, "access_level");
58 $stored_articles = db_fetch_result($result, 0, "stored_articles");
60 print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
61 print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
63 $result = db_query($this->link
, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
64 WHERE owner_uid = '$uid'");
66 $num_feeds = db_fetch_result($result, 0, "num_feeds");
68 print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
72 print "<h1>".__('Subscribed feeds')."</h1>";
74 $result = db_query($this->link
, "SELECT id,title,site_url FROM ttrss_feeds
75 WHERE owner_uid = '$uid' ORDER BY title");
77 print "<ul class=\"userFeedList\">";
81 while ($line = db_fetch_assoc($result)) {
83 $icon_file = ICONS_URL
."/".$line["id"].".ico";
85 if (file_exists($icon_file) && filesize($icon_file) > 0) {
86 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
88 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
91 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
93 $row_class = $row_class == "even" ?
"odd" : "even";
97 if (db_num_rows($result) < $num_feeds) {
98 // FIXME - add link to show ALL subscribed feeds here somewhere
100 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
105 print "<div align='center'>
106 <button onclick=\"closeInfoBox()\">".__("Close this window").
109 print "]]></content></dlg>";
115 global $access_level_names;
117 header("Content-Type: text/xml");
119 $id = db_escape_string($this->link
, $_REQUEST["id"]);
121 print "<dlg id=\"$method\">";
122 print "<title>".__('User Editor')."</title>";
123 print "<content><![CDATA[";
125 print "<form id=\"user_edit_form\" onsubmit='return false'>";
127 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
128 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
129 print "<input type=\"hidden\" name=\"method\" value=\"editSave\">";
131 $result = db_query($this->link
, "SELECT * FROM ttrss_users WHERE id = '$id'");
133 $login = db_fetch_result($result, 0, "login");
134 $access_level = db_fetch_result($result, 0, "access_level");
135 $email = db_fetch_result($result, 0, "email");
137 $sel_disabled = ($id == $_SESSION["uid"]) ?
"disabled" : "";
139 print "<div class=\"dlgSec\">".__("User")."</div>";
140 print "<div class=\"dlgSecCont\">";
143 print "<input type=\"hidden\" name=\"login\" value=\"$login\">";
144 print "<input size=\"30\" style=\"font-size : 16px\"
145 onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
148 print "<input size=\"30\" style=\"font-size : 16px\"
149 onkeypress=\"return filterCR(event, userEditSave)\" $sel_disabled
150 name=\"login\" value=\"$login\">";
155 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
156 print "<div class=\"dlgSecCont\">";
158 print __('Access level: ') . " ";
160 if (!$sel_disabled) {
161 print_select_hash("access_level", $access_level, $access_level_names,
164 print_select_hash("", $access_level, $access_level_names,
166 print "<input type=\"hidden\" name=\"access_level\" value=\"$access_level\">";
171 print __('Change password to') .
172 " <input type=\"password\" size=\"20\" onkeypress=\"return filterCR(event, userEditSave)\"
177 print "<div class=\"dlgSec\">".__("Options")."</div>";
178 print "<div class=\"dlgSecCont\">";
180 print __('E-mail: ').
181 " <input size=\"30\" name=\"email\" onkeypress=\"return filterCR(event, userEditSave)\"
190 print "<div class=\"dlgButtons\">
191 <button onclick=\"return userEditSave()\">".
192 __('Save')."</button>
193 <button onclick=\"return userEditCancel()\">".
194 __('Cancel')."</button></div>";
196 print "]]></content></dlg>";
201 function editSave() {
202 $login = db_escape_string($this->link
, trim($_REQUEST["login"]));
203 $uid = db_escape_string($this->link
, $_REQUEST["id"]);
204 $access_level = (int) $_REQUEST["access_level"];
205 $email = db_escape_string($this->link
, trim($_REQUEST["email"]));
206 $password = $_REQUEST["password"];
209 $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
210 $pwd_hash = encrypt_password($password, $salt, true);
211 $pass_query_part = "pwd_hash = '$pwd_hash', salt = '$salt',";
213 $pass_query_part = "";
216 db_query($this->link
, "UPDATE ttrss_users SET $pass_query_part login = '$login',
217 access_level = '$access_level', email = '$email', otp_enabled = false
223 $ids = split(",", db_escape_string($this->link
, $_REQUEST["ids"]));
225 foreach ($ids as $id) {
226 if ($id != $_SESSION["uid"] && $id != 1) {
227 db_query($this->link
, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'");
228 db_query($this->link
, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'");
229 db_query($this->link
, "DELETE FROM ttrss_users WHERE id = '$id'");
236 $login = db_escape_string($this->link
, trim($_REQUEST["login"]));
237 $tmp_user_pwd = make_password(8);
238 $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
239 $pwd_hash = encrypt_password($tmp_user_pwd, $salt, true);
241 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE
244 if (db_num_rows($result) == 0) {
246 db_query($this->link
, "INSERT INTO ttrss_users
247 (login,pwd_hash,access_level,last_login,created, salt)
248 VALUES ('$login', '$pwd_hash', 0, null, NOW(), '$salt')");
251 $result = db_query($this->link
, "SELECT id FROM ttrss_users WHERE
252 login = '$login' AND pwd_hash = '$pwd_hash'");
254 if (db_num_rows($result) == 1) {
256 $new_uid = db_fetch_result($result, 0, "id");
258 print format_notice(T_sprintf("Added user <b>%s</b> with password <b>%s</b>",
259 $login, $tmp_user_pwd));
261 initialize_user($this->link
, $new_uid);
265 print format_warning(T_sprintf("Could not create user <b>%s</b>", $login));
269 print format_warning(T_sprintf("User <b>%s</b> already exists.", $login));
273 static function resetUserPassword($link, $uid, $show_password) {
275 $result = db_query($link, "SELECT login,email
276 FROM ttrss_users WHERE id = '$uid'");
278 $login = db_fetch_result($result, 0, "login");
279 $email = db_fetch_result($result, 0, "email");
280 $salt = db_fetch_result($result, 0, "salt");
282 $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
283 $tmp_user_pwd = make_password(8);
285 $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
287 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash', salt = '$new_salt'
290 if ($show_password) {
291 print T_sprintf("Changed password of user <b>%s</b> to <b>%s</b>", $login, $tmp_user_pwd);
293 print T_sprintf("Sending new password of user <b>%s</b> to <b>%s</b>", $login, $email);
296 require_once 'classes/ttrssmailer.php';
299 require_once "lib/MiniTemplator.class.php";
301 $tpl = new MiniTemplator
;
303 $tpl->readTemplateFromFile("templates/resetpass_template.txt");
305 $tpl->setVariable('LOGIN', $login);
306 $tpl->setVariable('NEWPASS', $tmp_user_pwd);
308 $tpl->addBlock('message');
312 $tpl->generateOutputToString($message);
314 $mail = new ttrssMailer();
316 $rc = $mail->quickMail($email, $login,
317 __("[tt-rss] Password change notification"),
320 if (!$rc) print_error($mail->ErrorInfo
);
324 function resetPass() {
325 $uid = db_escape_string($this->link
, $_REQUEST["id"]);
326 Pref_Users
::resetUserPassword($this->link
, $uid, true);
331 global $access_level_names;
333 print "<div id=\"pref-user-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
334 print "<div id=\"pref-user-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
336 print "<div id=\"pref-user-toolbar\" dojoType=\"dijit.Toolbar\">";
338 $user_search = db_escape_string($this->link
, $_REQUEST["search"]);
340 if (array_key_exists("search", $_REQUEST)) {
341 $_SESSION["prefs_user_search"] = $user_search;
343 $user_search = $_SESSION["prefs_user_search"];
346 print "<div style='float : right; padding-right : 4px;'>
347 <input dojoType=\"dijit.form.TextBox\" id=\"user_search\" size=\"20\" type=\"search\"
348 value=\"$user_search\">
349 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateUsersList()\">".
350 __('Search')."</button>
353 $sort = db_escape_string($this->link
, $_REQUEST["sort"]);
355 if (!$sort ||
$sort == "undefined") {
359 print "<div dojoType=\"dijit.form.DropDownButton\">".
360 "<span>" . __('Select')."</span>";
361 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
362 print "<div onclick=\"selectTableRows('prefUserList', 'all')\"
363 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
364 print "<div onclick=\"selectTableRows('prefUserList', 'none')\"
365 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
366 print "</div></div>";
368 print "<button dojoType=\"dijit.form.Button\" onclick=\"javascript:addUser()\">".__('Create user')."</button>";
371 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:selectedUserDetails()\">".
372 __('Details')."</button dojoType=\"dijit.form.Button\">
373 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:editSelectedUser()\">".
374 __('Edit')."</button dojoType=\"dijit.form.Button\">
375 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:removeSelectedUsers()\">".
376 __('Remove')."</button dojoType=\"dijit.form.Button\">
377 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:resetSelectedUserPass()\">".
378 __('Reset password')."</button dojoType=\"dijit.form.Button\">";
380 print "</div>"; #toolbar
381 print "</div>"; #pane
382 print "<div id=\"pref-user-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
384 print "<div id=\"sticky-status-msg\"></div>";
388 $user_search = split(" ", $user_search);
391 foreach ($user_search as $token) {
392 $token = trim($token);
393 array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))");
396 $user_search_query = "(" . join($tokens, " AND ") . ") AND ";
399 $user_search_query = "";
402 $result = db_query($this->link
, "SELECT
403 id,login,access_level,email,
404 ".SUBSTRING_FOR_DATE
."(last_login,1,16) as last_login,
405 ".SUBSTRING_FOR_DATE
."(created,1,16) as created
413 if (db_num_rows($result) > 0) {
415 print "<p><table width=\"100%\" cellspacing=\"0\"
416 class=\"prefUserList\" id=\"prefUserList\">";
418 print "<tr class=\"title\">
419 <td align='center' width=\"5%\"> </td>
420 <td width='30%'><a href=\"#\" onclick=\"updateUsersList('login')\">".__('Login')."</a></td>
421 <td width='30%'><a href=\"#\" onclick=\"updateUsersList('access_level')\">".__('Access Level')."</a></td>
422 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('created')\">".__('Registered')."</a></td>
423 <td width='20%'><a href=\"#\" onclick=\"updateUsersList('last_login')\">".__('Last login')."</a></td></tr>";
427 while ($line = db_fetch_assoc($result)) {
429 $class = ($lnum %
2) ?
"even" : "odd";
433 print "<tr id=\"UMRR-$uid\">";
435 $line["login"] = htmlspecialchars($line["login"]);
437 $line["created"] = make_local_datetime($this->link
, $line["created"], false);
438 $line["last_login"] = make_local_datetime($this->link
, $line["last_login"], false);
440 print "<td align='center'><input onclick='toggleSelectRow2(this);'
441 dojoType=\"dijit.form.CheckBox\" type=\"checkbox\"
442 id=\"UMCHK-$uid\"></td>";
444 $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'";
446 print "<td $onclick>" . $line["login"] . "</td>";
448 if (!$line["email"]) $line["email"] = " ";
450 print "<td $onclick>" . $access_level_names[$line["access_level"]] . "</td>";
451 print "<td $onclick>" . $line["created"] . "</td>";
452 print "<td $onclick>" . $line["last_login"] . "</td>";
464 print_warning(__('No users defined.'));
466 print_warning(__('No matching users found.'));
472 print "</div>"; #pane
475 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB
,
476 "hook_prefs_tab", "prefUsers");
478 print "</div>"; #container