12
config = ivle.config.Config()
15
# usrmgt-server <port> <magic>
17
# User management operations:
19
# - [Re]Create jail for a user
20
# - Create a svn repository for a user
25
# - Disable a user's account
26
# - Enable a user's account
28
# - Rebuild svn config
29
# - Rebuild svn auth file
30
# - Rebuild passwd + push to nodes.
32
def activate_user(store, props, config):
33
"""Create the on-disk stuff for the given user.
34
Sets the state of the user in the db from pending to enabled.
35
@param config: An ivle.config.Config object.
37
login - the user name for the jail
42
if not os.path.exists(config['paths']['jails']['template']):
45
'message': 'Template jail has not been built -- '
46
'do you need to run ivle-buildjail?'}
48
os.umask(0022) # Bad, but start_server sets it worse.
50
login = props['login']
52
# FIXME: check we're pending
54
# Get the full User object from the db associated with this
55
user = ivle.database.User.get_by_login(store, login)
57
# make svn config/auth
58
repopath = os.path.join(config['paths']['svn']['repo_path'],
60
logging.debug("Creating user's Subversion repository")
61
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
63
rebuild_svn_config(store, props, config)
65
logging.debug("Adding Subversion authentication")
66
passwd = ivle.makeuser.make_svn_auth(store, login, config,
69
logging.debug("Creating jail")
70
ivle.makeuser.make_jail(user, config)
72
logging.info("Enabling user")
73
user.state = u'enabled'
75
return {"response": "okay"}
77
def rebuild_svn_config(store, props, config):
78
"""Rebuilds the svn config file
79
@param config: An ivle.config.Config object.
80
@return: response (okay, failure)
83
ivle.makeuser.rebuild_svn_config(store, config)
85
logging.warning('Rebuild of Subversion authorization config failed!')
86
return{'response': 'failure', 'msg': repr(e)}
88
return {'response': 'okay'}
90
def rebuild_svn_group_config(store, props, config):
91
"""Rebuilds the svn group config file
92
@param config: An ivle.config.Config object.
93
@return: response (okay, failure)
96
ivle.makeuser.rebuild_svn_group_config(store, config)
99
'Rebuild of Subversion group authorization config failed!')
100
return{'response': 'failure', 'msg': repr(e)}
102
return {'response': 'okay'}
104
def create_group_repository(store, props, config):
105
"""Creates on disk repository for the given group
106
@param config: An ivle.config.Config object.
108
subj_short_name, year, semester, groupnm
109
@return: response (okay, failure)
112
subj_short_name = props['subj_short_name']
114
semester = props['semester']
115
groupnm = props['groupnm']
117
namespace = "_".join([subj_short_name, year, semester, groupnm])
118
repopath = os.path.join(config['paths']['svn']['repo_path'],
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,
138
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
139
logging.info("Starting usrmgt server on port %d (pid = %d)" %
140
(config['usrmgt']['port'], pid))
143
pidfile = open('/var/run/usrmgt-server.pid', 'w')
144
pidfile.write('%d\n' % os.getpid())
146
except IOError, (errno, strerror):
147
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
151
logging.debug(repr(props))
153
store = ivle.database.get_store(config)
154
action = props.keys()[0]
155
res = actions[action](store, props[action], config)
157
if res['response'] == 'okay':
164
if __name__ == "__main__":
167
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
168
True, dispatch, initializer)