File size: 27,865 Bytes
17e971c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# coding: utf-8
# -------------------------------------------------------------------
# 宝塔Linux面板
# -------------------------------------------------------------------
# Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
# -------------------------------------------------------------------
# Author: sww <sww@bt.cn>
# -------------------------------------------------------------------
import json
import os
# ------------------------------
# 用户模型
# ------------------------------
import sys
import traceback
import psutil

if "/www/server/panel/class" not in sys.path:
    sys.path.insert(0, "/www/server/panel/class")

os.chdir("/www/server/panel")
import public
from typing import List, Dict, Any, Union


class RealUser:
    def __init__(self):
        self.groupList = self.get_group_list()['data']
        print(self.groupList)

    # --------------------获取用户列表 Start--------------------
    def get_user_list(self, search: str = '') -> Dict[str, Union[bool, str, List[Dict[str, Any]]]]:
        """
        获取用户列表
        :param search: 搜索关键词 可搜索 用户名、备注、shell、home、用户组
        :return: list
        """
        try:
            import pwd, grp
            ret_user_list = []
            user_list = pwd.getpwall()
            for u in user_list:
                try:
                    gp = grp.getgrgid(u.pw_gid).gr_name
                except:
                    gp = ''
                ret_user_list.append({
                    'username': u.pw_name,
                    'uid': u.pw_uid,
                    'gid': u.pw_gid,
                    'group': gp,
                    'ps': self._get_user_ps(u.pw_name, u.pw_gecos),
                    'home': u.pw_dir,
                    'login_shell': u.pw_shell
                })

            if search != '':
                ret_user_list = self._search_user(ret_user_list, search)
            return public.returnResult(code=1, data=ret_user_list, msg='获取用户列表成功!', status=True)
        except Exception as e:
            print(traceback.format_exc())
            return public.returnResult(code=0, data=[], msg='获取用户列表失败!错误:' + str(e), status=False)

    def _get_user_ps(self, name: str, ps: str) -> str:
        """
        获取用户备注
        :param name: 用户名
        :param ps: 备注
        :return: str
        """
        userPs = {'www': '宝塔面板', 'root': '超级管理员', 'mysql': '用于运行MySQL的用户',
                  'mongo': '用于运行MongoDB的用户',
                  'git': 'git用户', 'mail': 'mail', 'nginx': '第三方nginx用户', 'postfix': 'postfix邮局用户',
                  'lp': '打印服务帐号',
                  'daemon': '控制后台进程的系统帐号', 'nobody': '匿名帐户', 'bin': '管理大部分命令的帐号',
                  'adm': '管理某些管理文件的帐号', 'smtp': 'smtp邮件'}
        if name in userPs: return userPs[name]
        if not ps: return name
        return ps

    def _get_group_name(self, gid: str) -> str:
        """
        获取用户组名称
        :param gid: 用户组ID
        :return: str
        """
        for g in self.groupList:
            if g['gid'] == gid: return g['group']
        return ''

    def _search_user(self, data: List[Dict[str, Any]], search: str) -> List[Dict[str, Union[str, Any]]]:
        """
        搜索用户
        :param data: 用户列表
        :param search: 搜索关键词
        :return: list
        """
        try:
            ldata = []
            for i in data:
                if search in i['username'] or search in i['ps'] or search in i['login_shell'] or search in i['home'] or search in i['group']:
                    ldata.append(i)
            return ldata
        except:
            return data

    def get_group_list(self):
        """
        获取用户组列表
        :return:list

        """
        tmpList = public.readFile('/etc/group').split("\n")
        groupList = []
        for gl in tmpList:
            tmp = gl.split(':')
            if len(tmp) < 3: continue
            groupInfo = {}
            groupInfo['group'] = tmp[0]
            groupInfo['gid'] = tmp[2]
            groupList.append(groupInfo)
        return public.returnResult(code=1, data=groupList, msg='获取用户组列表成功!', status=True)

    # --------------------获取用户列表 End----------------------

    # --------------------删除用户 Start------------------------
    def remove_user(self, user: str) -> Dict[str, Any]:
        users = ['www', 'root', 'mysql', 'shutdown', 'postfix', 'smmsp', 'sshd', 'systemd-network', 'systemd-bus-proxy',
                 'avahi-autoipd', 'mail', 'sync', 'lp', 'adm', 'bin', 'mailnull', 'ntp', 'daemon', 'sys']
        if user in users: return public.returnResult(code=0, msg='系统用户或关键用户不能删除!', status=False)
        r = public.ExecShell("userdel " + user)
        if r[1].find('process') != -1:
            try:
                pid = r[1].split()[-1]
                p = psutil.Process(int(pid))
                pname = p.name()
                p.kill()
                public.ExecShell("pkill -9 " + pname)
                r = public.ExecShell("userdel " + user)
                public.ExecShell("rm -rf /home/" + user)
            except:
                pass
        if r[1].find('userdel:') != -1: return public.returnMsg(False, r[1])
        return public.returnResult(code=1, msg='删除成功!', status=True)

    # --------------------删除用户 End------------------------

    # --------------------添加用户 Start------------------------
    def add_user(self, user: str, pwd: str, group: str) -> Dict[str, Any]:
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if not pwd: return public.returnResult(code=0, msg='密码不能为空!', status=False)
            if not self._check_user(user): return public.returnResult(code=1, msg='用户已存在!', status=True)
            if not self._check_group(group): self.add_group(group)
            r = public.ExecShell("useradd -g " + group + " -m " + user + ' -p' + pwd)
            if r[1].find('useradd:') != -1 and r[1].find('already exists') == 1: return public.returnResult(code=0, msg=r[1], status=False)
            # public.ExecShell("echo \"" + user + ":" + pwd + "\" | chpasswd")
            return public.returnResult(code=1, msg='添加成功!', status=True)
        except:
            print(traceback.format_exc())
            return public.returnResult(code=0, msg='添加失败!', status=False)

    def _check_user(self, user: str) -> bool:
        """
        检查用户是否存在
        :param user: 用户名
        :return: bool
        """
        tmpList = public.readFile('/etc/passwd').split("\n")
        for ul in tmpList:
            tmp = ul.split(':')
            if len(tmp) < 6: continue
            if tmp[0] == user: return False
        return True

    def _check_group(self, group: str) -> bool:
        """
        检查用户组是否存在
        :param group: 用户组
        :return: bool
        """
        tmpList = public.readFile('/etc/group').split("\n")
        for gl in tmpList:
            tmp = gl.split(':')
            if len(tmp) < 3: continue
            if tmp[0] == group: return True
        return False

    # --------------------添加用户 End------------------------

    # --------------------修改用户密码 Start------------------------
    def edit_user_pwd(self, user: str, pwd: str) -> Dict[str, Any]:
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if not pwd: return public.returnResult(code=0, msg='密码不能为空!', status=False)
            if self._check_user(user): return public.returnResult(code=0, msg='用户不存在!', status=False)
            public.ExecShell("echo \"" + user + ":" + pwd + "\" | chpasswd")
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户密码 End------------------------

    # --------------------修改用户组 Start------------------------
    def edit_user_group(self, user: str, group: str) -> Dict[str, Any]:
        try:
            if not user: return public.returnMsg(False, '用户名不能为空!')
            if not group: return public.returnMsg(False, '用户组不能为空!')
            if self._check_user(user): return public.returnMsg(False, '用户不存在!')
            if not self._check_group(group): self.add_group(group)
            r = public.ExecShell("usermod -g " + group + " " + user)
            if r[1].find('usermod:') != -1: return public.returnMsg(False, r[1])
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户组 End------------------------

    # --------------------修改用户备注 Start------------------------
    def edit_user_ps(self, user: str, ps: str) -> Dict[str, Any]:
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if self._check_user(user): return public.returnResult(code=0, msg='用户不存在!', status=False)
            r = public.ExecShell("usermod -c " + ps + " " + user)
            if r[1].find('usermod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户备注 End------------------------

    # --------------------修改用户备注 Start------------------------
    def edit_user_status(self, user: str, status: int):
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if self._check_user(user): return public.returnResult(code=0, msg='用户不存在!', status=False)
            if int(status) == 1:
                r = public.ExecShell("usermod -L " + user)
            else:
                r = public.ExecShell("usermod -U " + user)
            if r[1].find('usermod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户备注 End------------------------

    # --------------------修改用户登录Shell Start------------------------
    def edit_user_login_shell(self, user: str, login_shell: str) -> Dict[str, Any]:
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if self._check_user(user): return public.returnResult(code=0, msg='用户不存在!', status=False)
            r = public.ExecShell("usermod -s " + login_shell + " " + user)
            if r[1].find('usermod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户登录Shell End------------------------

    # --------------------修改用户家目录 Start------------------------
    def edit_user_home(self, user: str, home: str) -> Dict[str, Any]:
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if self._check_user(user): return public.returnResult(code=0, msg='用户不存在!', status=False)
            r = public.ExecShell("usermod -d " + home + " " + user)
            if r[1].find('usermod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户家目录 End------------------------

    # --------------------获取用户信息 Start------------------------
    def get_user_info(self, user: str) -> Dict[str, Any]:
        try:
            user = user.strip()
            tmpList = public.readFile('/etc/passwd').split("\n")
            userInfo = {}
            for ul in tmpList:
                tmp = ul.split(':')
                if len(tmp) < 6: continue
                if tmp[0] == user:
                    userInfo['username'] = tmp[0]
                    userInfo['uid'] = tmp[2]
                    userInfo['gid'] = tmp[3]
                    userInfo['group'] = self._get_group_name(tmp[3])
                    userInfo['ps'] = self._get_user_ps(tmp[0], tmp[4])
                    userInfo['home'] = tmp[5]
                    userInfo['login_shell'] = tmp[6]
                    break
            return public.returnResult(code=1, data=userInfo, msg='获取用户信息成功!', status=True)
        except:
            print(traceback.format_exc())
            return public.returnResult(code=0, msg='获取用户信息失败!', status=False)

    # --------------------添加用户组 Start------------------------
    def add_group(self, group: str) -> Dict[str, Any]:
        """
        添加用户组
        :param group: 用户组
        :return: dict
        """
        try:
            if not group: return public.returnResult(code=0, msg='用户组不能为空!', status=False)
            if self._check_group(group): return public.returnResult(code=0, msg='用户组已存在!', status=False)
            r = public.ExecShell("groupadd " + group)
            if r[1].find('groupadd:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='添加成功!', status=True)
        except:
            return public.returnResult(code=0, msg='添加失败!', status=False)

    # --------------------添加用户组 End------------------------

    # --------------------删除用户组 Start------------------------
    def remove_group(self, group: str) -> Dict[str, Any]:
        """
        删除用户组
        :param group: 用户组
        :return: dict
        """
        try:
            if not group: return public.returnResult(code=0, msg='用户组不能为空!', status=False)
            if not self._check_group(group): return public.returnResult(code=0, msg='用户组不存在!', status=False)
            r = public.ExecShell("groupdel " + group)
            if r[1].find('groupdel:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='删除成功!', status=True)
        except:
            return public.returnResult(code=0, msg='删除失败!', status=False)

    # --------------------删除用户组 End------------------------

    # --------------------修改用户组名称 Start------------------------
    def edit_group_name(self, group: str, new_group: str) -> Dict[str, Any]:
        """
        修改用户组名称
        :param group: 用户组
        :param new_group: 新用户组
        :return: dict
        """
        try:
            if not group: return public.returnResult(code=0, msg='用户组不能为空!', status=False)
            if not new_group: return public.returnResult(code=0, msg='新用户组不能为空!', status=False)
            if not self._check_group(group): return public.returnResult(code=0, msg='用户组不存在!', status=False)
            if self._check_group(new_group): return public.returnResult(code=0, msg='新用户组已存在!', status=False)
            r = public.ExecShell("groupmod -n " + new_group + " " + group)
            if r[1].find('groupmod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------获取用户组列表 End------------------------

    # --------------------获取用户组信息 Start------------------------
    def get_group_info(self, group) -> Dict[str, Any]:
        """
        获取用户组信息
        :param group: 用户组
        :return: dict
        """
        try:
            group = group.strip()
            tmpList = public.readFile('/etc/group').split("\n")
            groupInfo = {}
            for gl in tmpList:
                tmp = gl.split(':')
                if len(tmp) < 3: continue
                if tmp[0] == group:
                    groupInfo['group'] = tmp[0]
                    groupInfo['gid'] = tmp[2]
                    break
            return public.returnResult(code=1, data=groupInfo, msg='获取用户组信息成功!', status=True)
        except:
            return public.returnResult(code=0, msg='获取用户组信息失败!', status=False)

    # --------------------获取用户组信息 End------------------------

    # --------------------获取用户组信息 Start------------------------
    def get_group_user(self, group: str) -> Dict[str, Any]:
        """
        获取用户组用户
        :param group: 用户组
        :return: dict
        """
        try:
            group = group.strip()
            tmpList = self.get_user_list()['data']
            userList = []
            for ul in tmpList:
                if ul['group'] == group:
                    userList.append(ul['username'])
            return public.returnResult(code=1, data=userList, msg='获取用户组用户成功!', status=True)
        except:
            return public.returnResult(code=0, msg='获取用户组用户失败!', status=False)

    # --------------------获取用户组信息 End------------------------

    # --------------------获取用户组信息 Start------------------------
    def get_user_group(self, user: str) -> Dict[str, Any]:
        """
        获取用户组用户
        :param user: 用户
        :return: dict
        """
        try:
            user = user.strip()
            tmpList = self.get_user_list()['data']
            groupList = []
            for gl in tmpList:
                if gl['username'] == user:
                    groupList.append(gl['group'])
            return public.returnResult(code=1, data=groupList, msg='获取用户组用户成功!', status=True)
        except:
            return public.returnResult(code=0, msg='获取用户组用户失败!', status=False)

    # --------------------获取用户组信息 End------------------------

    # --------------------修改用户权限 Start------------------------
    def edit_user_permission(self, user: str, permission: str) -> Dict[str, Any]:
        """
        修改用户权限
        :param user:
        :param permission:
        :return:
        """
        try:
            if not user: return public.returnResult(code=0, msg='用户名不能为空!', status=False)
            if self._check_user(user): return public.returnResult(code=0, msg='用户不存在!', status=False)
            r = public.ExecShell("chmod -R " + permission + " /home/" + user)
            if r[1].find('chmod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    # --------------------修改用户权限 End------------------------

    # --------------------修改用户组权限 Start------------------------
    def edit_group_permission(self, group: str, permission: str) -> Dict[str, Any]:
        """
        修改用户组权限
        :param group:
        :param permission:
        :return:
        """
        try:
            if not group: return public.returnResult(code=0, msg='用户组不能为空!', status=False)
            if not self._check_group(group): return public.returnResult(code=0, msg='用户组不存在!', status=False)
            r = public.ExecShell("chmod -R " + permission + " /home/" + group)
            if r[1].find('chmod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)

    def edit_user_name(self, user: str, new_user: str) -> Dict[str, Any]:
        try:
            user = user.strip()
            new_user = new_user.strip()
            r = public.ExecShell("usermod -l " + new_user + " " + user)
            if r[1].find('usermod:') != -1: return public.returnResult(code=0, msg=r[1], status=False)
            return public.returnResult(code=1, msg='修改成功!', status=True)
        except:
            return public.returnResult(code=0, msg='修改失败!', status=False)


class User(object):
    def __init__(self):
        self.real_user = RealUser()

    # 获取用户列表
    def get_user_list(self, get):
        search = ''
        if hasattr(get, 'search'):
            search = get.search
        return self.real_user.get_user_list(search)

    # 删除用户
    def remove_user(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户不存在!')
        user = get.user.strip()
        return self.real_user.remove_user(user)

    # 添加用户
    def add_user(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'pwd'):
            return public.returnMsg(False, '密码不能为空!')
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        user = get.user.strip()
        pwd = get.pwd.strip()
        group = get.group.strip()
        return self.real_user.add_user(user, pwd, group)

    # 修改用户密码
    def edit_user_pwd(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'pwd'):
            return public.returnMsg(False, '密码不能为空!')
        user = get.user.strip()
        pwd = get.pwd.strip()
        return self.real_user.edit_user(user, pwd)

    # 修改用户的用户组
    def edit_user_group(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        user = get.user.strip()
        group = get.group.strip()
        return self.real_user.edit_group(user, group)

    # 修改用户备注
    def edit_user_ps(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        user = get.user.strip()
        return self.real_user.edit_user_ps(user)

    # 添加用户组
    def add_group(self, get):
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        group = get.group.strip()
        return self.real_user.add_group(group)

    # 删除用户组
    def remove_group(self, get):
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        group = get.group.strip()
        return self.real_user.remove_group(group)

    # 修改用户组名称
    def edit_group_name(self, get):
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        if not hasattr(get, 'new_group'):
            return public.returnMsg(False, '新用户组不能为空!')
        group = get.group.strip()
        new_group = get.new_group.strip()
        return self.real_user.edit_group_name(group, new_group)

    # 获取用户组列表
    def get_group_list(self, get):
        return self.real_user.get_group_list()

    # 获取用户组信息
    def get_group_info(self, get):
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        group = get.group.strip()
        return self.real_user.get_group_info(group)

    # 获取用户组用户
    def get_group_user(self, get):
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        group = get.group.strip()
        return self.real_user.get_group_user(group)

    # 获取用户组用户
    def get_user_group(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户不能为空!')
        user = get.user.strip()
        return self.real_user.get_user_group(user)

    # 修改用户备注
    def edit_ps(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'ps'):
            return public.returnMsg(False, '备注不能为空!')
        user = get.user.strip()
        ps = get.ps.strip()
        return self.real_user.edit_ps(user, ps)

    # 修改用户登录Shell
    def edit_user_login_shell(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'login_shell'):
            return public.returnMsg(False, '登录Shell不能为空!')
        user = get.user.strip()
        login_shell = get.login_shell.strip()
        return self.real_user.edit_login_shell(user, login_shell)

    # 修改用户家目录
    def edit_user_home(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'home'):
            return public.returnMsg(False, '家目录不能为空!')
        user = get.user.strip()
        home = get.home.strip()
        return self.real_user.edit_home(user, home)

    # 修改用户权限
    def edit_user_permission(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'permission'):
            return public.returnMsg(False, '权限不能为空!')
        user = get.user.strip()
        permission = get.permission.strip()
        return self.real_user.edit_user_permission(user, permission)

    #   修改用户组权限
    def edit_group_permission(self, get):
        if not hasattr(get, 'group'):
            return public.returnMsg(False, '用户组不能为空!')
        if not hasattr(get, 'permission'):
            return public.returnMsg(False, '权限不能为空!')
        group = get.group.strip()
        permission = get.permission.strip()
        return self.real_user.edit_group_permission(group, permission)

    def edit_user_name(self, get):
        if not hasattr(get, 'user'):
            return public.returnMsg(False, '用户名不能为空!')
        if not hasattr(get, 'new_user'):
            return public.returnMsg(False, '新用户名不能为空!')
        user = get.user.strip()
        new_user = get.new_user.strip()
        return self.real_user.edit_user_name(user, new_user)


if __name__ == "__main__":
    user = User()
    print(user.get_user_list(public.to_dict_obj({})))