~azzar1/unity/add-show-desktop-key

440 by drtomc
usrmgt: move the usrmgt sever to a better place.
1
#!/usr/bin/python
2
3
import sys
4
473 by drtomc
usrmgt: progress the skeleton a bit further.
5
import common.db
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
6
import common.chat
7
import common.makeuser
8
9
# usage:
10
#   usrmgt-server <port> <magic>
11
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
12
# User management operations:
13
#   - Create local user
14
#   - [Re]Create jail for a user
15
#       - Create a svn repository for a user
16
#           - create repository
17
#           - svn config
18
#           - svn auth
19
#       - Checkout repository as home directory
20
#       - /etc/passwd entry
21
#   - Disable a user's account
22
#   - Enable a user's account
23
#   - Remove a user
24
#   - Rebuild svn config
25
#   - Rebuild svn auth file
26
#   - Rebuild passwd + push to nodes.
27
28
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
29
def create_user(props):
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
30
    """Create the database record for the given user.
31
       Expected properties:
32
        username    - used as a unix login name and svn repository name.
33
                      STRING REQUIRED 
34
        uid         - the unix uid under which execution will take place
454 by drtomc
usrmgt-server: more work.
35
                      on the behalf of the user. Don't use 0! If not specified
36
                      or None, one will be allocated from the configured
37
                      numeric range.
38
                      INT OPTIONAL
39
        password    - the clear-text password for the user. If this property is
40
                      absent or None, this is an indication that external
41
                      authentication should be used (i.e. LDAP).
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
42
                      STRING OPTIONAL
464 by mattgiuca
usermgt-server: Added email.
43
        email       - the user's email address.
44
                      STRING OPTIONAL
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
45
        nick        - the display name to use.
46
                      STRING REQUIRED
47
        fullname    - The name of the user for results and/or other official
48
                      purposes.
49
                      STRING REQUIRED
50
        rolenm      - The user's role. Must be one of "anyone", "student",
51
                      "tutor", "lecturer", "admin".
52
                      STRING/ENUM REQUIRED
454 by drtomc
usrmgt-server: more work.
53
        studentid   - If supplied and not None, the student id of the user for
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
54
                      results and/or other official purposes.
55
                      STRING OPTIONAL
454 by drtomc
usrmgt-server: more work.
56
       Return Value: the uid associated with the user. INT
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
57
    """
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
58
473 by drtomc
usrmgt: progress the skeleton a bit further.
59
    # FIXME: the IVLE server must check that an admin is doing this!
60
456 by drtomc
usrmgt-server: a bit more work.
61
    if 'uid' not in props or props['uid'] is None:
464 by mattgiuca
usermgt-server: Added email.
62
        raise NotImplementedError, "No algorithm for creating uids yet!"
454 by drtomc
usrmgt-server: more work.
63
        # uid = invent-uid
64
        # props['uid'] = uid
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
65
464 by mattgiuca
usermgt-server: Added email.
66
    username = props['username']
67
    uid = props['uid']
68
    try:
69
        password = props['password']
70
    except KeyError:
71
        password = None
72
    try:
73
        email = props['email']
74
    except KeyError:
75
        email = None
76
    nick = props['nick']
77
    fullname = props['fullname']
78
    rolenm = props['rolenm']
79
    try:
80
        studentid = props['studentid']
81
    except KeyError:
82
        studentid = None
83
    common.makeuser.make_user_db(username, uid, password, email, nick,
84
                                 fullname, rolenm, studentid)
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
85
464 by mattgiuca
usermgt-server: Added email.
86
    return uid
454 by drtomc
usrmgt-server: more work.
87
473 by drtomc
usrmgt: progress the skeleton a bit further.
88
def activate_user(props):
89
    """Create the on-disk stuff for the given user.
90
       Sets the state of the user in the db from pending to enabled.
454 by drtomc
usrmgt-server: more work.
91
       Expected properties:
473 by drtomc
usrmgt: progress the skeleton a bit further.
92
        login       - the user name for the jail
454 by drtomc
usrmgt-server: more work.
93
                      STRING REQUIRED
456 by drtomc
usrmgt-server: a bit more work.
94
       Return Value: None
454 by drtomc
usrmgt-server: more work.
95
    """
456 by drtomc
usrmgt-server: a bit more work.
96
473 by drtomc
usrmgt: progress the skeleton a bit further.
97
    login = props['login']
98
99
    db = common.db.DB()
100
101
    try:
102
103
        # FIXME: check we're pending
104
105
        details = db.get_user(login)
106
107
        # FIXME: make svn config/auth
108
109
        # FIXME: etc, etc.
110
111
        common.makeuser.make_jail(login, details['unixid'])
112
113
        db.update_user(login, state='enabled')
114
115
        return None
116
117
    finally:
118
        db.close()
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
119
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
120
actions = {
454 by drtomc
usrmgt-server: more work.
121
        'create-user':create_user,
473 by drtomc
usrmgt: progress the skeleton a bit further.
122
        'activate-user':activate_user
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
123
    }
124
125
def dispatch(props):
126
    action = props.keys()[0]
127
    return actions[action](props[action])
128
440 by drtomc
usrmgt: move the usrmgt sever to a better place.
129
if __name__ == "__main__":
130
    port = int(sys.argv[1])
131
    magic = sys.argv[2]
132
452 by drtomc
usrmgt: checkpoint work on the usrmgt server.
133
    common.chat.start_server(port, magic, False, dispatch)