-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad_inputs.php
executable file
·219 lines (198 loc) · 8.66 KB
/
ad_inputs.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/*
Файл с проверкой и обработкой входящих файлов
*/
if ($main_var != 'parol') exit;
// Обработка команды выхода пользователя, пришедшей GET'ом
if (isset($_GET['exit'])) {
logout();
}
//###########################################################
//Если пришло что-то постом/гетом, то обюрабатываем
if (isset($_POST['act']) || isset($_GET['act'])) {
//Проверка авторизации
if ($_POST['act'] == "auth") {
$input_username = trim(addslashes($_POST['login']));
$input_userpass = trim(addslashes($_POST['pass']));
$ad_host = $_POST["dc"];
$_SESSION['dc'] = $ad_host;
// выделяем имя домена
$ad_domain = substr(strstr($ad_host,"."),1);
// создаем DN-путь домена
$ad_dn = "DC=".implode(",DC=",explode(".", $ad_domain));
// Подготавливаем настройки подключения к домену
$_SESSION["ad_conf"] = array (
'base_dn'=>$ad_dn,
'account_suffix'=>'@'.$ad_domain,
'use_tls'=>false,
'use_ssl'=>true,
'domain_controllers'=>array($ad_host));
autorization($input_username, $input_userpass);
}
elseif (isset($_SESSION['admin']) && $_SESSION['admin'] === true) {
//Получить список заблокированых пользователей
if ($_GET['act'] == "get_locked_users") {
$aLu = get_locked_users();
$aRes = array();
if ($aLu) {
foreach ($aLu as $i => $user) {
$aRes[$i]["title"] = $user["displayname"];
$aRes[$i]["key"] = $user["samaccountname"];
$aRes[$i]["data"]["tstamp"] = $user["lockouttime"];
$aRes[$i]["icon"] = "user16.png";
$aRes[$i]["selected"] = true;
}
$jRes = json_encode($aRes);
print_r($jRes);
} else {
echo "false";
}
exit;
}
//Разблокировать пользователей
if ($_GET['act'] == "unlock_users") {
if (isset($_GET['ul'])) {
foreach ($_GET['ul'] as $user) {
$unlock = unlock_user($user);
if (!$unlock) {
echo "Ошибка разблокировки пользователя " . $user . "\n" . $adldap->getLastError();
exit;
}
}
$few_users = count($_GET['ul']) - 1;
echo ($few_users) ? "Пользователи успешно разблокированыю" : "Пользователь успешно разблокирвван";
} else {
echo "Не передано ни одного пользователя";
}
exit;
}
//Получить дерево объектов
if ($_GET['act'] == "get_tree") {
$ob_type = (isset($_GET['type'])) ? $_GET['type'] : NULL;
if (isset($_GET['pNode'])) {
$par_node = ($_GET['pNode'] == "NULL") ? $_GET['pNode'] : explode("__", $_GET['pNode']);
//$par_node = ($_GET['pNode']=="NULL")?$_GET['pNode']:explode("__",explode(":",$_GET['pNode'])[1]);
echo(build_tree($par_node, $ob_type));
}
exit;
}
//Удаление пользователя
if ($_GET['act'] == "del_users") {
if (isset($_GET['u']) and is_array($_GET["u"])) {
$users = $_GET['u'];
$res = true;
foreach ($users as $user) {
$del = $adldap->user()->delete($user);
if (!$del) $res = false;
}
}
echo $res;
exit;
}
//Cмена пароля пользователя
if (($_POST['act'] == "change_pass")
and (isset($_POST['newpass']))
and (isset($_POST['user']))
) {
if ($_POST['newpass'] != $_POST['newpass2']) {
echo "Пароли не совпадают";
exit;
}
$result = $adldap->user()->password($_POST['user'],$_POST['newpass']);
echo $result;
exit;
}
if (($_GET['act']=="get_user_prop") and (isset($_GET['user']))) {
//указываем список необходимых нам полей.
//primarygroupid необходим для получения группы по умолчанию, которой нет в memberOf
$fields = array(
"sn",
"givenName",
"displayName",
"sAMAccountName",
"company",
"department",
"physicalDeliveryOfficeName",
"title",
"telephoneNumber",
"mail",
"description",
"memberof",
"primarygroupid"
);
$result = $adldap->user()->info($_GET["user"],$fields);
// ищем и исключаем из массива ненужные служебные поля
$res_count = $result[0]["count"];
for ($i=0; $i < $res_count; $i++) {
if ($result[0][$i] == "objectsid" || $result[0][$i] == "primarygroupid") {
unset($result[0][$result[0][$i]]);
$result[0]["count"]--;
}
unset($result[0][$i]);
}
// преобразуем список групп для работы с fancytree
unset($result[0]["memberof"]["count"]);
foreach ($result[0]["memberof"] as $key=>$group) {
unset($result[0]["memberof"][$key]);
$result[0]["memberof"][$key]["title"] = get_cn($group);
$result[0]["memberof"][$key]["key"] = $group;
$result[0]["memberof"][$key]["icon"] = "group16.png";
}
echo(json_encode($result));
exit;
}
//Создать нового пользователя
if (($_POST['act'] == "cr_user")
and (isset($_POST["cr_user_surn"]) and strlen($_POST["cr_user_surn"])>0)
and (isset($_POST["cr_user_name"]) and strlen($_POST["cr_user_name"])>0)
and (isset($_POST["cr_user_fullname"]) and strlen($_POST["cr_user_fullname"])>0)
and (isset($_POST["cr_user_logon"]) and strlen($_POST["cr_user_logon"])>0)
and (isset($_POST["cr_user_pass"]) and strlen($_POST["cr_user_pass"])>0)
and (isset($_POST["cr_user_cont"]) and strlen($_POST["cr_user_cont"])>0)
) {
$cont = str_replace(":", "=", explode("__", $_POST["cr_user_cont"]));
//$cont= explode("__", $_POST["cr_user_cont"]);
if ($_POST["cr_user_chpas"] == "on") {
$require_pch = 1;
} else {
$require_pch = 0;
}
if (isset($_POST["cr_user_descr"])) {
$description = $_POST["cr_user_descr"];
} else {
$description = "";
}
$attributes = array(
"logon_name" => $_POST["cr_user_logon"].$ad_conf["account_suffix"],
"username" => $_POST["cr_user_logon"], "Windows-1252",
"firstname" => $_POST["cr_user_name"],
"surname" => $_POST["cr_user_surn"], "Windows-1252",
"email" => $_POST["cr_user_email"],
"container" => $cont,
"enabled" => 1,
"password" => $_POST["cr_user_pass"],
"display_name" => $_POST["cr_user_fullname"],
"change_password" => $require_pch,
"office" => $_POST["cr_user_cab"],
"title" => $_POST["cr_user_dol"],
"telephone" => $_POST["cr_user_tel"],
"company" => $_POST["cr_user_org"],
"description" => $_POST["cr_user_descr"],
"department" => $_POST["cr_user_otd"]
);
//echo "cont=". $cont;
//print_r($cont);
$result = $adldap->user()->create($attributes);
if ($result === true) {
//echo build_tree(explode("__", $_POST["cr_user_cont"]), "objects");
echo true;
} else {
echo $result;
}
exit;
}
}
else {
header("Location: index.php", true, 200);
}
}