13
# usrmgt-server <port> <magic>
15
# User management operations:
17
# - [Re]Create jail for a user
18
# - Create a svn repository for a user
23
# - Disable a user's account
24
# - Enable a user's account
26
# - Rebuild svn config
27
# - Rebuild svn auth file
28
# - Rebuild passwd + push to nodes.
30
def activate_user(props):
31
"""Create the on-disk stuff for the given user.
32
Sets the state of the user in the db from pending to enabled.
34
login - the user name for the jail
39
os.umask(0022) # Bad, but start_server sets it worse.
41
login = props['login']
43
store = ivle.database.get_store()
47
# FIXME: check we're pending
49
# Get the full User object from the db associated with this
50
user = ivle.database.User.get_by_login(store, login)
52
# make svn config/auth
54
repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
55
logging.debug("Creating user's Subversion repository")
56
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
58
rebuild_svn_config(props)
60
logging.debug("Adding Subversion authentication")
61
passwd = ivle.makeuser.make_svn_auth(store, login,
63
logging.debug("passwd: %s" % passwd)
65
logging.debug("Creating jail")
66
ivle.makeuser.make_jail(login, user.unixid, svn_pass=passwd)
68
logging.info("Enabling user")
69
user.state = u'enabled'
73
return {"response": "okay"}
78
def rebuild_svn_config(props):
79
"""Rebuilds the svn config file
81
response (okay, failure)
84
ivle.makeuser.rebuild_svn_config()
86
logging.warning('Rebuild of Subversion authorization config failed!')
87
return{'response': 'failure', 'msg': repr(e)}
89
return {'response': 'okay'}
91
def rebuild_svn_group_config(props):
92
"""Rebuilds the svn group config file
94
response (okay, failure)
97
ivle.makeuser.rebuild_svn_group_config()
100
'Rebuild of Subversion group authorization config failed!')
101
return{'response': 'failure', 'msg': repr(e)}
103
return {'response': 'okay'}
105
def create_group_repository(props):
106
"""Creates on disk repository for the given group
108
subj_short_name, year, semester, groupnm
110
response (okay, failure)
113
subj_short_name = props['subj_short_name']
115
semester = props['semester']
116
groupnm = props['groupnm']
118
namespace = "_".join([subj_short_name, year, semester, groupnm])
119
repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
120
logging.debug("Creating Subversion repository %s"%repopath)
122
ivle.makeuser.make_svn_repo(repopath)
124
logging.error("Failed to create Subversion repository %s: %s"%
126
return {'response': 'failure', 'msg': repr(e)}
128
return {'response': 'okay'}
131
'activate_user':activate_user,
132
'create_group_repository':create_group_repository,
133
'rebuild_svn_config':rebuild_svn_config,
134
'rebuild_svn_group_config':rebuild_svn_group_config,
139
pidfile = open('/var/run/usrmgt-server.pid', 'w')
140
pidfile.write('%d\n' % os.getpid())
142
except IOError, (errno, strerror):
143
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
147
logging.debug(repr(props))
148
action = props.keys()[0]
149
return actions[action](props[action])
151
if __name__ == "__main__":
154
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
155
logging.info("Starting usrmgt server on port %d (pid = %d)" %
156
(ivle.conf.usrmgt_port, pid))
158
ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
159
True, dispatch, initializer)