-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUsers.php
More file actions
188 lines (153 loc) · 8.42 KB
/
Users.php
File metadata and controls
188 lines (153 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Controller\Admin;
use FeatherBB\Core\AdminUtils;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Url;
use FeatherBB\Core\Utils;
class Users
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Admin\Users();
Lang::load('admin/users');
}
public function display($req, $res, $args)
{
Hooks::fire('controller.admin.users.display');
// Move multiple users to other user groups
if (Input::post('move_users') || Input::post('move_users_comply')) {
AdminUtils::generateAdminMenu('users');
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users'), __('Move users')],
'active_page' => 'moderate',
'admin_console' => true,
'move' => $this->model->moveUsers(),
]
)->addTemplate('@forum/admin/users/move_users')->display();
}
// Delete multiple users
if (Input::post('delete_users') || Input::post('delete_users_comply')) {
AdminUtils::generateAdminMenu('users');
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users'), __('Delete users')],
'active_page' => 'moderate',
'admin_console' => true,
'user_ids' => $this->model->deleteUsers(),
]
)->addTemplate('@forum/admin/users/delete_users')->display();
}
// Ban multiple users
if (Input::post('ban_users') || Input::post('ban_users_comply')) {
if (!User::can('mod.bans')) {
throw new Error(__('No permission'), '403');
}
AdminUtils::generateAdminMenu('users');
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users'), __('Bans')],
'active_page' => 'moderate',
'admin_console' => true,
'user_ids' => $this->model->banUsers(),
]
)->addTemplate('@forum/admin/users/ban_users')->display();
}
// Display bans
if (Input::query('find_user')) {
// Return conditions and query string for the URL
$search = $this->model->getUserSearch();
// Fetch user count
$numUsers = $this->model->getNumUsersSearch($search['conditions']);
// Determine the user offset (based on $_gET['p'])
$numPages = ceil($numUsers / 50);
$p = (!Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $numPages) ? 1 : intval(Input::query('p'));
$startFrom = 50 * ($p - 1);
// Generate paging links
$pagingLinks = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginateOld($numPages, $p, '?find_user=&'.implode('&', $search['query_str']));
// Some helper variables for permissions
$canDelete = $canMove = User::isAdmin();
$canBan = User::isAdmin() || (User::isAdminMod() && User::can('mod.ban_users'));
$canAction = ($canDelete || $canBan || $canMove) && $numUsers > 0;
View::addAsset('js', 'style/imports/common.js', ['type' => 'text/javascript']);
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users'), __('Results head')],
'active_page' => 'admin',
'admin_console' => true,
'paging_links' => $pagingLinks,
'search' => $search,
'start_from' => $startFrom,
'can_delete' => $canDelete,
'can_ban' => $canBan,
'can_action' => $canAction,
'can_move' => $canMove,
'user_data' => $this->model->printUsers($search['conditions'], $search['order_by'], $search['direction'], $startFrom),
]
)->addTemplate('@forum/admin/users/find_users')->display();
} else {
AdminUtils::generateAdminMenu('users');
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users')],
'active_page' => 'admin',
'admin_console' => true,
'group_list' => $this->model->getGroupList(),
]
)->addTemplate('@forum/admin/users/admin_users')->display();
}
}
// Show IP statistics for a certain user ID
public function ipstats($req, $res, $args)
{
Hooks::fire('controller.admin.users.ipstats');
// Fetch ip count
$numIps = $this->model->getNumIp($args['id']);
// Determine the ip offset (based on $_gET['p'])
$numPages = ceil($numIps / 50);
$p = (!Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $numPages) ? 1 : intval(Input::query('p'));
$startFrom = 50 * ($p - 1);
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users'), __('Results head')],
'active_page' => 'admin',
'admin_console' => true,
'page' => $p,
'paging_links' => '<span class="pages-label">'.__('Pages').' </span>'.Url::paginateOld($numPages, $p, '?ip_stats='.$args['id']),
'start_from' => $startFrom,
'ip_data' => $this->model->getIpStats($args['id'], $startFrom),
]
)->addTemplate('@forum/admin/users/search_ip')->display();
}
// Show IP statistics for a certain user IP
public function showusers($req, $res, $args)
{
Hooks::fire('controller.admin.users.showusers');
$searchIp = Input::query('ip');
if (!@preg_match('%^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$%', $searchIp) && !@preg_match('%^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$%', $searchIp)) {
throw new Error(__('Bad IP message'), 400);
}
// Fetch user count
$numUsers = $this->model->getNumUsersIp($searchIp);
// Determine the user offset (based on $_gET['p'])
$numPages = ceil($numUsers / 50);
$p = (!Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $numPages) ? 1 : intval(Input::query('p'));
$startFrom = 50 * ($p - 1);
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Users'), __('Results head')],
'active_page' => 'admin',
'admin_console' => true,
'paging_links' => '<span class="pages-label">'.__('Pages').' </span>'.Url::paginateOld($numPages, $p, '?ip_stats='.$searchIp),
'page' => $p,
'start_from' => $startFrom,
'info' => $this->model->getInfoPoster($searchIp, $startFrom),
]
)->addTemplate('@forum/admin/users/show_users')->display();
}
}