-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin.php
196 lines (170 loc) · 5.54 KB
/
admin.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
<?php
require('common.php');
if(empty($_GET['a'])){
if(check_login()){
header('location:./admin.php?a=show');
exit();
}else{
require('login.tpl');
exit();
}
}
$ii=0;
if($_GET['a'] == 'login'){
$username = !empty($_POST['username']) ? $_POST['username'] : '';
$password = !empty($_POST['password']) ? $_POST['password'] : '';
if($username == $admin['username'] && md5($password) == $admin['password']){
$_SESSION['token'] = md5($admin['username'] . $admin['password']);
$_SESSION['account'] = !empty($_POST['account']) ? $_POST['account'] : '0';
header('location:./admin.php?a=show');
exit();
}else{
require('login.tpl');
exit();
}
}
if($_GET['a'] == 'show'){
if(!check_login()){
require('login.tpl');
exit();
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$domains = getdomains($token);
require('admin.tpl');
exit();
}
if($_GET['a'] == 'getusers'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$data = getusers($token);
foreach($data as $k =>$v){
if($v['assignedLicenses'][0]['skuId'] == ""){
$data[$k]['sku'] = '无许可';
}
elseif ($v['assignedLicenses'][0]['skuId'] == "314c4481-f395-4525-be8b-2ec4bb1e9d91"){
$data[$k]['sku'] = 'A1学生';
}
elseif($v['assignedLicenses'][0]['skuId'] == "94763226-9b3c-4e75-a931-5c89701abe66"){
$data[$k]['sku'] = 'A1教职工';
}
elseif($v['assignedLicenses'][0]['skuId'] == "e82ae690-a2d5-4d76-8d30-7c6e01e6022e"){
$data[$k]['sku'] = 'A1P学生';
}
elseif($v['assignedLicenses'][0]['skuId'] == "78e66a63-337a-4a9a-8959-41c6654dfb56"){
$data[$k]['sku'] = 'A1P教职工';
}
else{
$data[$k]['sku'] = '未知';
};
}
response(0,"获取成员信息成功",$data,count($data));
//echo "aaaaaaaaaaaaaaaaaaaaaaaa";
}
if($_GET['a'] == 'admin_add_account'){
if(!check_login()){
response(1,"登录已失效");
}
$domain=$_POST['domain'];
$password=$_POST['password'];
$forceChangePassword=$_POST['forceChangePassword'];
$location=$_POST['location'];
$sku_id=$_POST['sku'];
$request = [
'username'=>$_POST['add_user'],
'firstname'=>$_POST['firstname'],
'lastname'=>$_POST['lastname'],
];
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
if(empty($token)){
response(1,'获取token失败,请检查参数配置是否正确');
}
admin_create_user($request,$token,$domain,$sku_id,$password,$forceChangePassword,$location);
response(0,'创建用户成功');
}
if($_GET['a'] == 'admin_delete'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$user_email = !empty($_POST['email']) ? $_POST['email'] : 0;
if($user_email){
$resultaccount=accountdelete($user_email,$token);
}else{
$resultaccount=false;
}
if(!empty($resultaccount)){
response(0,"用户账户删除成功");
}
else{
response(1,"删除失败");
}
}
if($_GET['a'] == 'invitation_code_activeaccount'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$user_email = !empty($_POST['email']) ? $_POST['email'] : 0;
$result=accountactive($user_email,$token);
if(!empty($result)){
response(0,$user_email."解锁失败");
}else{
response(1,$user_email."解锁成功");
}
}
if($_GET['a'] == 'invitation_code_inactiveaccount'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$user_email = !empty($_POST['email']) ? $_POST['email'] : 0;
$result=accountinactive($user_email,$token);
if(!empty($result)){
response(0,$user_email."禁用失败");
}else{
response(1,$user_email."成功禁用");
}
}
if($_GET['a'] == 'invitation_code_setuserasadminbyid'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$user_id = !empty($_POST['id']) ? $_POST['id'] : 0;
$result=setuserasadminbyid($user_id,$token);
if(!empty($result)){
response(0,"设置管理失败".$result);
}else{
response(1,"设置管理成功");
}
}
if($_GET['a'] == 'invitation_code_deluserasadminbyid'){
if(!check_login()){
response(1,"登录已失效");
}
$token = get_ms_token($accounts[$ii]['tenant_id'],$accounts[$ii]['client_id'],$accounts[$ii]['client_secret']);
$user_id = !empty($_POST['id']) ? $_POST['id'] : 0;
$result=deluserasadminbyid($user_id,$token);
if(!empty($result)){
response(0,"取消管理失败".$result);
}else{
response(1,"取消管理成功");
}
}
if($_GET['a'] == 'changeaccount'){
$_SESSION['account']=$_POST['account'];
if(!check_login()){
response(1,"登录已失效");
}
response(1,"切换全局成功");
}
if($_GET['a'] == 'logout'){
$_SESSION['account']=$_POST['account'];
$_SESSION['token']="";
session_stop;
if(!check_login()){
response(1,"登录已失效");
}
}