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

« back to all changes in this revision

Viewing changes to scripts/usrmgt-server

  • Committer: drtomc
  • Date: 2008-02-20 09:41:48 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:522
Add quite a lot of stuff to get usrmgt happening.

login.py: A little bit of robustifying logic that logs you out if your account
    is still pending when you try to auth. Basically, this forces usrmgt-server
    to have another try.

authenticate.py: A small code rearrangement to produce the right behaviour
    (a generic login/passwd error) when an unknown user logs in (better than
    an internal server error :-) ).

usrmgt-server, makeuser.py: Lots of stuff to setup users. Quite a bit of stuff
    that should be db-driven is hard coded at the moment. (Only a week and a
    half till students will be hitting it, and we can't do everything!)

setup.py: Add an extra bit of svn related config.

users.sql,user.py,db.py: Add the svn_pass column to allow ivle to auth to the
    subversion server.

studpath.py: update a couple of comments to reflect a newer view of the world.

python-console: Add some timeout magic. Actually, I don't think this works,
    but it's well after bedtime, and I've still got to ride home from work.
    The morning will be soon enough.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
 
3
import os
 
4
import pysvn
 
5
import subprocess
3
6
import sys
 
7
import urllib
 
8
from functools import partial
4
9
 
 
10
import conf
5
11
import common.db
6
12
import common.chat
7
13
import common.makeuser
 
14
import common.studpath
8
15
 
9
16
# usage:
10
17
#   usrmgt-server <port> <magic>
85
92
 
86
93
    return uid
87
94
 
 
95
def get_login(login, passwd, _realm, _login, _may_save):
 
96
    """Callback function used by pysvn for authentication.
 
97
    """
 
98
    # print >> sys.stderr, "Getting password for %s (realm %s)" % (login, _realm)
 
99
    return (True, login, passwd, False)
 
100
 
88
101
def activate_user(props):
89
102
    """Create the on-disk stuff for the given user.
90
103
       Sets the state of the user in the db from pending to enabled.
104
117
 
105
118
        details = db.get_user(login)
106
119
 
107
 
        # FIXME: make svn config/auth
108
 
 
109
 
        # FIXME: etc, etc.
110
 
 
111
 
        common.makeuser.make_jail(login, details['unixid'])
112
 
 
 
120
        # make svn config/auth
 
121
 
 
122
        # print >> sys.stderr, "Creating repo"
 
123
        common.makeuser.make_svn_repo(login, throw_on_error=False)
 
124
        # print >> sys.stderr, "Creating svn config"
 
125
        common.makeuser.make_svn_config(login, throw_on_error=False)
 
126
        # print >> sys.stderr, "Creating svn auth"
 
127
        passwd = common.makeuser.make_svn_auth(login, throw_on_error=False)
 
128
        # print >> sys.stderr, "passwd: %s" % passwd
 
129
 
 
130
        svn = pysvn.Client()
 
131
        svn.callback_get_login = partial(get_login, login, passwd)
 
132
    
 
133
        # FIXME: This should be a loop over enrolements.
 
134
        #        We're not going to fix this now because it requires
 
135
        #        a large amount of admin console work to manage subject
 
136
        #        offerings.
 
137
        #        Instead, we're just going to use a single offering with
 
138
        #        a "short" name of "info1".
 
139
        # print >> sys.stderr, "Creating /info1"
 
140
        try:
 
141
            svn.mkdir(conf.svn_addr + login + "/info1",
 
142
                      "Initial creation of work directory for Informatics 1")
 
143
        except Exception, exc:
 
144
            pass
 
145
        # print >> sys.stderr, "Creating /submissions"
 
146
        try:
 
147
            svn.mkdir(conf.svn_addr + login + "/submissions",
 
148
                      "Initial creation of submissions directory")
 
149
        except Exception, exc:
 
150
            pass
 
151
        # print >> sys.stderr, "Creating /stuff"
 
152
        try:
 
153
            svn.mkdir(conf.svn_addr + login + "/stuff",
 
154
                      "Initial creation of directory for miscellania")
 
155
        except Exception, exc:
 
156
            pass
 
157
 
 
158
        # print >> sys.stderr, "Creating jail"
 
159
        common.makeuser.make_jail(login, details.unixid)
 
160
 
 
161
        # FIXME: <hack>
 
162
 
 
163
        tcf_path = os.path.join(conf.jail_base, 'template/opt/ivle/lib/conf/conf.py')
 
164
        cf_path = os.path.join(conf.jail_base, login, 'opt/ivle/lib/conf/conf.py')
 
165
 
 
166
        os.remove(cf_path)
 
167
        cf = open(cf_path, "w")
 
168
        cf.write(open(tcf_path, "r").read())
 
169
        cf.write("# The login name for the owner of the jail\n")
 
170
        cf.write("login = %s\n" % repr(login))
 
171
        cf.write("\n")
 
172
        cf.write("# The subversion-only password for the owner of the jail\n")
 
173
        cf.write("svn_pass = %s\n" % repr(passwd))
 
174
        cf.close()
 
175
 
 
176
        # FIXME: </hack>
 
177
 
 
178
        # print >> sys.stderr, "Checking out directories in the jail"
 
179
        try:
 
180
            svn.checkout(conf.svn_addr + "/" + login + "/stuff",
 
181
                         common.studpath.url_to_local(login + "/stuff")[1])
 
182
        except Exception, exc:
 
183
            pass
 
184
        try:
 
185
            svn.checkout(conf.svn_addr + "/" + login + "/submissions",
 
186
                         common.studpath.url_to_local(login + "/submissions")[1])
 
187
        except Exception, exc:
 
188
            pass
 
189
        try:
 
190
            svn.checkout(conf.svn_addr + "/" + login + "/info1",
 
191
                         common.studpath.url_to_local(login + "/info1")[1])
 
192
        except Exception, exc:
 
193
            pass
 
194
 
 
195
        # FIXME: should this be nicer?
 
196
        os.system("chown -R %d:%d %s" \
 
197
                % (details.unixid, details.unixid,
 
198
                   common.studpath.url_to_local(login)[1]))
 
199
 
 
200
 
 
201
        # print >> sys.stderr, "Enabling user"
113
202
        db.update_user(login, state='enabled')
114
203
 
115
204
        return {"response": "okay"}
 
205
    
 
206
    except Exception, exc:
 
207
        print >> sys.stderr, exc
116
208
 
117
209
    finally:
118
210
        db.close()
123
215
    }
124
216
 
125
217
def dispatch(props):
 
218
    # print >> sys.stderr, repr(props)
126
219
    action = props.keys()[0]
127
220
    return actions[action](props[action])
128
221