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(store, 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
# FIXME: check we're pending
45
# Get the full User object from the db associated with this
46
user = ivle.database.User.get_by_login(store, login)
48
# make svn config/auth
49
repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
50
logging.debug("Creating user's Subversion repository")
51
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
53
rebuild_svn_config(store, props)
55
logging.debug("Adding Subversion authentication")
56
passwd = ivle.makeuser.make_svn_auth(store, login,
59
logging.debug("Creating jail")
60
ivle.makeuser.make_jail(user)
62
logging.info("Enabling user")
63
user.state = u'enabled'
65
return {"response": "okay"}
67
def rebuild_svn_config(store, props):
68
"""Rebuilds the svn config file
70
response (okay, failure)
73
ivle.makeuser.rebuild_svn_config(store)
75
logging.warning('Rebuild of Subversion authorization config failed!')
76
return{'response': 'failure', 'msg': repr(e)}
78
return {'response': 'okay'}
80
def rebuild_svn_group_config(store, props):
81
"""Rebuilds the svn group config file
83
response (okay, failure)
86
ivle.makeuser.rebuild_svn_group_config(store)
89
'Rebuild of Subversion group authorization config failed!')
90
return{'response': 'failure', 'msg': repr(e)}
92
return {'response': 'okay'}
94
def create_group_repository(store, props):
95
"""Creates on disk repository for the given group
97
subj_short_name, year, semester, groupnm
99
response (okay, failure)
102
subj_short_name = props['subj_short_name']
104
semester = props['semester']
105
groupnm = props['groupnm']
107
namespace = "_".join([subj_short_name, year, semester, groupnm])
108
repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
109
logging.debug("Creating Subversion repository %s"%repopath)
111
ivle.makeuser.make_svn_repo(repopath)
113
logging.error("Failed to create Subversion repository %s: %s"%
115
return {'response': 'failure', 'msg': repr(e)}
117
return {'response': 'okay'}
120
'activate_user':activate_user,
121
'create_group_repository':create_group_repository,
122
'rebuild_svn_config':rebuild_svn_config,
123
'rebuild_svn_group_config':rebuild_svn_group_config,
127
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
128
logging.info("Starting usrmgt server on port %d (pid = %d)" %
129
(ivle.conf.usrmgt_port, pid))
132
pidfile = open('/var/run/usrmgt-server.pid', 'w')
133
pidfile.write('%d\n' % os.getpid())
135
except IOError, (errno, strerror):
136
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
140
logging.debug(repr(props))
142
store = ivle.database.get_store()
143
action = props.keys()[0]
144
res = actions[action](store, props[action])
146
if res['response'] == 'okay':
153
if __name__ == "__main__":
156
ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
157
True, dispatch, initializer)