-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbulk_account_settings_users_update.php
181 lines (167 loc) · 6.88 KB
/
bulk_account_settings_users_update.php
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
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <[email protected]>
Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
KonradSC <[email protected]>
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('bulk_account_settings_users')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//use connected database
$domain_uuid = $_SESSION['domain_uuid'] ?? '';
$user_uuid = $_SESSION['user_uuid'] ?? '';
$database = database::new(['config' => config::load(), 'domain_uuid' => $domain_uuid]);
$settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]);
//set valid user options
$user_options = [];
$user_options[] = 'user_enabled';
$user_options[] = 'user_status';
$user_options[] = 'password';
$user_options[] = 'time_zone';
$user_options[] = 'group';
//get list of groups where group_uuid => group_name
$groups = [];
$sql = "select group_uuid, group_name, group_level from v_groups";
$rows = $database->select($sql);
if (!empty($rows)) {
foreach ($rows as $row) {
$groups[$row['group_uuid']] = $row['group_name'];
$group_levels[$row['group_uuid']] = intval($row['group_level'] ?? 0);
}
}
//ensure the user level is available
if (empty($_SESSION['user_level'])) {
$sql = "select max(group_level) as level from v_user_groups ug";
$sql .= " left join v_groups g on g.group_uuid = ug.group_uuid";
$sql .= " where user_uuid = :user_uuid";
$parameters = [];
$parameters['user_uuid'] = $_SESSION['user_uuid'];
$result = $database->select($sql, $parameters, 'column');
if (!empty($result)) {
$_SESSION['user_level'] = intval($result);
}
} else {
$_SESSION['user_level'] = 0;
}
//check for the ids
if (!empty($_REQUEST)) {
$user_uuids = preg_replace('#[^a-fA-F0-9_\-]#', '', $_REQUEST['id'] ?? '');
$option_selected = preg_replace('#[^a-zA-Z0-9_]#', '', $_REQUEST['option_selected'] ?? '');
$action = preg_replace('#[^a-zA-Z0-9_]#', '', $_REQUEST['action'] ?? 'update');
if (!in_array($option_selected, $user_options, true)) {
header('HTTP/1.1 400 Bad Request');
echo "<!DOCTYPE html>\n";
echo "<html>\n";
echo " <head><title>400 Bad Request</title></head>\n";
echo " <body bgcolor=\"white\">\n";
echo " <center><h1>400 Bad Request</h1></center>\n";
echo " </body>\n";
echo "</html>\n";
exit();
}
$new_setting = $_REQUEST["new_setting"];
foreach($user_uuids as $i => $user_uuid) {
//ensure valid uuid
if (!is_uuid($user_uuid)) {
continue;
}
switch ($option_selected) {
case 'user_status':
case 'user_enabled':
$array["users"][$i]["domain_uuid"] = $domain_uuid;
$array["users"][$i]["user_uuid"] = $user_uuid;
$array["users"][$i][$option_selected] = $new_setting;
break;
case 'password':
$array["users"][$i]["domain_uuid"] = $domain_uuid;
$array["users"][$i]["user_uuid"] = $user_uuid;
// set strength from 0 to 4
$password_strength = 0;
$password_strength += intval($settings->get('user', 'password_number' , true));
$password_strength += intval($settings->get('user', 'password_lowercase', true));
$password_strength += intval($settings->get('user', 'password_uppercase', true));
$password_strength += intval($settings->get('user', 'password_special' , true));
//generate a password using strength and length (default of 20 characters if not set)
$array['users'][$i]['password'] = generate_password($settings->get('user', 'password_length', 20), $password_strength);
break;
case 'time_zone':
// get the existing user_setting_uuid
$sql = "select user_setting_uuid from v_user_settings"
. " where"
. " user_uuid = :user_uuid"
. " and user_setting_category = 'domain'"
. " and user_setting_subcategory = 'time_zone'"
. " and user_setting_enabled = 'true' "
. "limit 1";
$parameters = [];
$parameters['user_uuid'] = $user_uuid;
$user_setting_uuid = $database->select($sql, $parameters, 'column');
if (empty($user_setting_uuid) || !is_uuid($user_setting_uuid)) {
$user_setting_uuid = uuid();
//enable new records
$array["user_settings"][$i]["user_setting_enabled"] = true;
}
$array['user_settings'][$i]['domain_uuid' ] = $domain_uuid;
$array['user_settings'][$i]['user_uuid' ] = $user_uuid;
$array['user_settings'][$i]['user_setting_uuid' ] = $user_setting_uuid;
$array['user_settings'][$i]['user_setting_category' ] = 'domain';
$array['user_settings'][$i]['user_setting_name' ] = 'name';
$array['user_settings'][$i]['user_setting_subcategory'] = 'time_zone';
$array['user_settings'][$i]['user_setting_value' ] = $new_setting;
break;
case 'group':
$group_uuid = preg_replace('#[^a-fA-F0-9\-]#', '', $_REQUEST['group_uuid']);
if (is_uuid($group_uuid) && !empty($groups[$group_uuid])) {
//check current user is not trying to assign to a higher level group
if ($_SESSION['user_level'] >= $group_levels[$group_uuid]) {
$array['user_groups'][$i]['domain_uuid'] = $domain_uuid;
$array['user_groups'][$i]['user_uuid' ] = $user_uuid;
$array['user_groups'][$i]['group_uuid' ] = $group_uuid;
$array['user_groups'][$i]['group_name' ] = $groups[$group_uuid];
}
}
break;
}
}
if (!empty($array) && ($action == 'update' || $action == 'add')) {
$database->app_name = 'bulk_account_settings';
$database->app_uuid = '6b4e03c9-c302-4eaa-b16d-e1c5c08a2eb7';
$database->save($array);
//$message = $database->message;
}
if (!empty($array) && $action == 'remove') {
$database->app_name = 'bulk_account_settings';
$database->app_uuid = '6b4e03c9-c302-4eaa-b16d-e1c5c08a2eb7';
$database->delete($array);
//$message = $database->message;
}
}
//redirect the browser
$_SESSION["message"] = $text['message-update'];
header("Location: bulk_account_settings_users.php?option_selected=".$option_selected."");
return;