101
101
def get_login(login, passwd, _realm, _login, _may_save):
102
102
"""Callback function used by pysvn for authentication.
104
log("Getting password for %s (realm %s)" % (login, _realm))
104
logging.debug("Getting password for %s (realm %s)" % (login, _realm))
105
105
return (True, login, passwd, False)
107
107
def activate_user(props):
126
126
# make svn config/auth
128
logging.debug("Creating repo")
129
129
common.makeuser.make_svn_repo(login, throw_on_error=False)
130
log("Creating svn config")
130
logging.debug("Creating svn config")
131
131
common.makeuser.make_svn_config(login, throw_on_error=False)
132
log("Creating svn auth")
132
logging.debug("Creating svn auth")
133
133
passwd = common.makeuser.make_svn_auth(login, throw_on_error=False)
134
log("passwd: %s" % passwd)
134
logging.debug("passwd: %s" % passwd)
136
136
svn = pysvn.Client()
137
137
svn.callback_get_login = partial(get_login, login, passwd)
146
146
# Instead, we're just going to use a single offering with
147
147
# a "short" name of "info1".
148
log("Creating /info1")
148
logging.debug("Creating /info1")
150
150
svn.mkdir(conf.svn_addr + login + "/info1",
151
151
"Initial creation of work directory for Informatics 1")
152
152
except Exception, exc:
153
log("While mkdiring info1: %s" % str(exc))
155
log("Creating /submissions")
157
svn.mkdir(conf.svn_addr + login + "/submissions",
158
"Initial creation of submissions directory")
159
except Exception, exc:
160
log("While mkdiring submissions: %s" % str(exc))
162
log("Creating /stuff")
153
logging.warning("While mkdiring info1: %s" % str(exc))
155
logging.debug("Creating /stuff")
164
157
svn.mkdir(conf.svn_addr + login + "/stuff",
165
158
"Initial creation of directory for miscellania")
166
159
except Exception, exc:
167
log("While mkdiring stuff: %s" % str(exc))
171
common.makeuser.make_jail(login, details.unixid)
175
tcf_path = os.path.join(conf.jail_base, 'template/opt/ivle/lib/conf/conf.py')
176
cf_path = os.path.join(conf.jail_base, login, 'opt/ivle/lib/conf/conf.py')
179
cf = open(cf_path, "w")
180
cf.write(open(tcf_path, "r").read())
181
cf.write("# The login name for the owner of the jail\n")
182
cf.write("login = %s\n" % repr(login))
184
cf.write("# The subversion-only password for the owner of the jail\n")
185
cf.write("svn_pass = %s\n" % repr(passwd))
190
log("Checking out directories in the jail")
192
svn.checkout(conf.svn_addr + login + "/stuff",
193
common.studpath.url_to_local(login + "/stuff")[1])
194
except Exception, exc:
195
log("While mkdiring stuff: %s" % str(exc))
198
svn.checkout(conf.svn_addr + login + "/submissions",
199
common.studpath.url_to_local(login + "/submissions")[1])
200
except Exception, exc:
201
log("While mkdiring submissions: %s" % str(exc))
204
svn.checkout(conf.svn_addr + login + "/info1",
205
common.studpath.url_to_local(login + "/info1")[1])
206
except Exception, exc:
207
log("While mkdiring info1: %s" % str(exc))
160
logging.warning("While mkdiring stuff: %s" % str(exc))
163
logging.debug("Creating jail")
164
common.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
166
do_checkout(props, svn_pass=passwd)
210
168
# FIXME: should this be nicer?
211
169
os.system("chown -R %d:%d %s" \
212
170
% (details.unixid, details.unixid,
213
171
common.studpath.url_to_local(login)[1]))
173
logging.info("Enabling user")
217
174
db.update_user(login, state='enabled')
219
176
return {"response": "okay"}
181
def do_checkout(props, svn_pass=None):
182
"""Create the default contents of a user's jail by checking out from the
184
If any directory already exists, just fail silently (so this is not a
185
"wipe-and-checkout", merely a checkout if it failed or something).
187
login - the user name for the jail
191
login = props['login']
193
# If svn_pass isn't supplied, grab it from the DB
196
user = db.get_user(login)
197
svn_pass = user.svn_pass
201
svn.callback_get_login = partial(get_login, login, svn_pass)
203
if conf.svn_addr[-1] != os.sep:
204
conf.svn_addr += os.sep
208
logging.debug("Checking out directories in the jail")
210
svn.checkout(conf.svn_addr + login + "/stuff",
211
common.studpath.url_to_local(login + "/stuff")[1])
212
os.system("chown -R %d:%d %s" \
213
% (user.unixid, user.unixid,
214
common.studpath.url_to_local(login + "/stuff")[1]))
215
except Exception, exc:
216
logging.warning("While mkdiring stuff: %s" % str(exc))
219
svn.checkout(conf.svn_addr + login + "/info1",
220
common.studpath.url_to_local(login + "/info1")[1])
221
os.system("chown -R %d:%d %s" \
222
% (user.unixid, user.unixid,
223
common.studpath.url_to_local(login + "/info1")[1]))
224
except Exception, exc:
225
logging.warning("While mkdiring info1: %s" % str(exc))
230
return {"response": "okay"}
225
233
'create_user':create_user,
226
234
'update_user':update_user,
227
235
'activate_user':activate_user,
236
'do_checkout':do_checkout,
231
"""Writes a message to stderr, but only if DEBUG_PRINT is True.
235
print >>sys.stderr, msg
241
pidfile = open('/var/run/usrmgt-server.pid', 'w')
242
pidfile.write('%d\n' % os.getpid())
244
except IOError, (errno, strerror):
245
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
237
248
def dispatch(props):
249
logging.debug(repr(props))
239
250
action = props.keys()[0]
240
251
return actions[action](props[action])
242
253
if __name__ == "__main__":
255
print >>sys.stderr, "Usage: usrmgt-server <port> <magic>"
243
257
port = int(sys.argv[1])
244
258
magic = sys.argv[2]
246
common.chat.start_server(port, magic, False, dispatch)
262
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
263
logging.info("Starting usrmgt server on port %d (pid = %d)" % (port, pid))
265
common.chat.start_server(port, magic, True, dispatch, initializer)