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

« back to all changes in this revision

Viewing changes to lib/common/makeuser.py

  • Committer: mattgiuca
  • Date: 2008-03-09 11:48:29 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:673
Rebuilt the way Terms of Service are displayed:
    Delegated displaying TOS to util.send_terms_of_service.
    dispatch/login.py and apps/tos now call this instead of doing it
    themselves.

setup.py: Added tos_path to config options.
util.py: Added send_terms_of_service. Reads the TOS file from the configured
    location, and if it isn't there, the code itself sends a default TOS
    message to administrators (note: used to be a default file, now there IS
    NO DEFAULT TOS file. This is so that it won't get blown away upon
    reinstall).
Removed apps/tos/license.html. Now admins are expected to create their own TOS
file. It explains how to do this in the TOS if there isn't one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
# TODO: When creating a new home directory, chown it to its owner
33
33
 
 
34
import md5
34
35
import os
35
36
import stat
36
37
import shutil
 
38
import time
 
39
import uuid
37
40
import warnings
38
41
 
39
42
import conf
40
43
import db
41
44
 
 
45
def make_svn_repo(login, throw_on_error=True):
 
46
    """Create a repository for the given user.
 
47
    """
 
48
    path = os.path.join(conf.svn_repo_path, login)
 
49
    try:
 
50
        res = os.system("svnadmin create '%s'" % path)
 
51
        if res != 0 and throw_on_error:
 
52
            raise Exception("Cannot create repository for %s" % login)
 
53
    except Exception, exc:
 
54
        print repr(exc)
 
55
        if throw_on_error:
 
56
            raise
 
57
    try:
 
58
        os.system("chown -R www-data:www-data %s" % path)
 
59
    except Exception:
 
60
        pass
 
61
 
 
62
def rebuild_svn_config():
 
63
    """Build the complete SVN configuration file.
 
64
    """
 
65
    conn = db.DB()
 
66
    res = conn.query("SELECT login, rolenm FROM login;").dictresult()
 
67
    groups = {}
 
68
    for r in res:
 
69
        role = r['rolenm']
 
70
        if role not in groups:
 
71
            groups[role] = []
 
72
        groups[role].append(r['login'])
 
73
    f = open(conf.svn_conf + ".new", "w")
 
74
    f.write("# IVLE SVN Repositories Configuration\n")
 
75
    f.write("# Auto-generated on %s\n" % time.asctime())
 
76
    f.write("\n")
 
77
    f.write("[groups]\n")
 
78
    for (g,ls) in groups.iteritems():
 
79
        f.write("%s = %s\n" % (g, ",".join(ls)))
 
80
    f.write("\n")
 
81
    for r in res:
 
82
        login = r['login']
 
83
        f.write("[%s:/]\n" % login)
 
84
        f.write("%s = rw\n" % login)
 
85
        #f.write("@tutor = r\n")
 
86
        #f.write("@lecturer = rw\n")
 
87
        #f.write("@admin = rw\n")
 
88
        f.write("\n")
 
89
    f.close()
 
90
    os.rename(conf.svn_conf + ".new", conf.svn_conf)
 
91
 
 
92
def make_svn_config(login, throw_on_error=True):
 
93
    """Add an entry to the apache-svn config file for the given user.
 
94
       Assumes the given user is either a guest or a student.
 
95
    """
 
96
    f = open(conf.svn_conf, "a")
 
97
    f.write("[%s:/]\n" % login)
 
98
    f.write("%s = rw\n" % login)
 
99
    #f.write("@tutor = r\n")
 
100
    #f.write("@lecturer = rw\n")
 
101
    #f.write("@admin = rw\n")
 
102
    f.write("\n")
 
103
    f.close()
 
104
 
 
105
def make_svn_auth(login, throw_on_error=True):
 
106
    """Setup svn authentication for the given user.
 
107
       FIXME: create local.auth entry
 
108
    """
 
109
    passwd = md5.new(uuid.uuid4().bytes).digest().encode('hex')
 
110
    if os.path.exists(conf.svn_auth_ivle):
 
111
        create = ""
 
112
    else:
 
113
        create = "c"
 
114
 
 
115
    db.DB().update_user(login, svn_pass=passwd)
 
116
 
 
117
    res = os.system("htpasswd -%smb %s %s %s" % (create,
 
118
                                              conf.svn_auth_ivle,
 
119
                                              login, passwd))
 
120
    if res != 0 and throw_on_error:
 
121
        raise Exception("Unable to create ivle-auth for %s" % login)
 
122
 
 
123
    return passwd
 
124
 
42
125
def make_jail(username, uid, force=True):
43
126
    """Creates a new user's jail space, in the jail directory as configured in
44
127
    conf.py.
165
248
    if errors:
166
249
        raise Exception, errors
167
250
 
168
 
def make_user_db(login, uid, password, nick, fullname, rolenm, studentid,
169
 
    force=True):
 
251
def make_user_db(throw_on_error = True, **kwargs):
170
252
    """Creates a user's entry in the database, filling in all the fields.
171
 
    If force is False, throws an exception if the user already exists.
172
 
    If True, overwrites the user's entry in the DB.
 
253
    All arguments must be keyword args. They are the fields in the table.
 
254
    However, instead of supplying a "passhash", you must supply a
 
255
    "password" argument, which will be hashed internally.
 
256
    Also do not supply a state. All users are created in the "no_agreement"
 
257
    state.
 
258
    Throws an exception if the user already exists.
173
259
    """
174
260
    dbconn = db.DB()
175
 
    if force:
176
 
        # Delete user if it exists
177
 
        try:
178
 
            dbconn.delete_user(login)
179
 
        except:
180
 
            pass
181
 
    dbconn.create_user(login, uid, password, nick, fullname, rolenm, studentid)
 
261
    dbconn.create_user(**kwargs)
182
262
    dbconn.close()
 
263
 
 
264
    if kwargs['password']:
 
265
        if os.path.exists(conf.svn_auth_local):
 
266
            create = ""
 
267
        else:
 
268
            create = "c"
 
269
        res = os.system("htpasswd -%smb %s %s %s" % (create,
 
270
                                                     conf.svn_auth_local,
 
271
                                                     kwargs['login'],
 
272
                                                     kwargs['password']))
 
273
        if res != 0 and throw_on_error:
 
274
            raise Exception("Unable to create local-auth for %s" % kwargs['login'])
 
275