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
os.umask(0022) # Bad, but start_server sets it worse.
44
login = props['login']
46
# FIXME: check we're pending
48
# Get the full User object from the db associated with this
49
user = ivle.database.User.get_by_login(store, login)
51
# make svn config/auth
52
repopath = os.path.join(config['paths']['svn']['repo_path'],
54
logging.debug("Creating user's Subversion repository")
55
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
57
rebuild_svn_config(store, props, config)
59
logging.debug("Adding Subversion authentication")
60
passwd = ivle.makeuser.make_svn_auth(store, login, config,
63
logging.debug("Creating jail")
64
ivle.makeuser.make_jail(user, config)
66
logging.info("Enabling user")
67
user.state = u'enabled'
69
return {"response": "okay"}
71
def rebuild_svn_config(store, props, config):
72
"""Rebuilds the svn config file
73
@param config: An ivle.config.Config object.
74
@return: response (okay, failure)
77
ivle.makeuser.rebuild_svn_config(store, config)
79
logging.warning('Rebuild of Subversion authorization config failed!')
80
return{'response': 'failure', 'msg': repr(e)}
82
return {'response': 'okay'}
84
def rebuild_svn_group_config(store, props, config):
85
"""Rebuilds the svn group config file
86
@param config: An ivle.config.Config object.
87
@return: response (okay, failure)
90
ivle.makeuser.rebuild_svn_group_config(store, config)
93
'Rebuild of Subversion group authorization config failed!')
94
return{'response': 'failure', 'msg': repr(e)}
96
return {'response': 'okay'}
98
def create_group_repository(store, props, config):
99
"""Creates on disk repository for the given group
100
@param config: An ivle.config.Config object.
102
subj_short_name, year, semester, groupnm
103
@return: response (okay, failure)
106
subj_short_name = props['subj_short_name']
108
semester = props['semester']
109
groupnm = props['groupnm']
111
namespace = "_".join([subj_short_name, year, semester, groupnm])
112
repopath = os.path.join(config['paths']['svn']['repo_path'],
114
logging.debug("Creating Subversion repository %s"%repopath)
116
ivle.makeuser.make_svn_repo(repopath)
118
logging.error("Failed to create Subversion repository %s: %s"%
120
return {'response': 'failure', 'msg': repr(e)}
122
return {'response': 'okay'}
125
'activate_user':activate_user,
126
'create_group_repository':create_group_repository,
127
'rebuild_svn_config':rebuild_svn_config,
128
'rebuild_svn_group_config':rebuild_svn_group_config,
132
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
133
logging.info("Starting usrmgt server on port %d (pid = %d)" %
134
(config['usrmgt']['port'], pid))
137
pidfile = open('/var/run/usrmgt-server.pid', 'w')
138
pidfile.write('%d\n' % os.getpid())
140
except IOError, (errno, strerror):
141
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
145
logging.debug(repr(props))
147
store = ivle.database.get_store(config)
148
action = props.keys()[0]
149
res = actions[action](store, props[action], config)
151
if res['response'] == 'okay':
158
if __name__ == "__main__":
161
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
162
True, dispatch, initializer)