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

« back to all changes in this revision

Viewing changes to scripts/usrmgt-server

  • Committer: William Grant
  • Date: 2009-12-14 03:43:51 UTC
  • Revision ID: me@williamgrant.id.au-20091214034351-j0gbqkrmp3b1iawz
Don't ask for the 'ivle' user password in loadsampledata; get it from the DB.

Show diffs side-by-side

added added

removed removed

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