27
29
# - Rebuild svn auth file
28
30
# - Rebuild passwd + push to nodes.
30
def activate_user(props):
32
def activate_user(store, props, config):
31
33
"""Create the on-disk stuff for the given user.
32
34
Sets the state of the user in the db from pending to enabled.
35
@param config: An ivle.config.Config object.
33
36
Expected properties:
34
37
login - the user name for the jail
39
42
os.umask(0022) # Bad, but start_server sets it worse.
41
44
login = props['login']
47
# FIXME: check we're pending
49
details = db.get_user(login)
51
# make svn config/auth
53
repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
54
logging.debug("Creating user's Subversion repository")
55
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
57
rebuild_svn_config(props)
59
logging.debug("Adding Subversion authentication")
60
passwd = ivle.makeuser.make_svn_auth(login, throw_on_error=True)
61
logging.debug("passwd: %s" % passwd)
63
logging.debug("Creating jail")
64
ivle.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
66
logging.info("Enabling user")
67
db.update_user(login, state='enabled')
69
return {"response": "okay"}
74
def rebuild_svn_config(props):
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):
75
72
"""Rebuilds the svn config file
77
response (okay, failure)
73
@param config: An ivle.config.Config object.
74
@return: response (okay, failure)
80
ivle.makeuser.rebuild_svn_config()
77
ivle.makeuser.rebuild_svn_config(store, config)
81
78
except Exception, e:
82
79
logging.warning('Rebuild of Subversion authorization config failed!')
83
80
return{'response': 'failure', 'msg': repr(e)}
85
82
return {'response': 'okay'}
87
def rebuild_svn_group_config(props):
84
def rebuild_svn_group_config(store, props, config):
88
85
"""Rebuilds the svn group config file
90
response (okay, failure)
86
@param config: An ivle.config.Config object.
87
@return: response (okay, failure)
93
ivle.makeuser.rebuild_svn_group_config()
90
ivle.makeuser.rebuild_svn_group_config(store, config)
94
91
except Exception, e:
96
93
'Rebuild of Subversion group authorization config failed!')
99
96
return {'response': 'okay'}
101
def create_group_repository(props):
98
def create_group_repository(store, props, config):
102
99
"""Creates on disk repository for the given group
100
@param config: An ivle.config.Config object.
103
101
Expected properties:
104
102
subj_short_name, year, semester, groupnm
106
response (okay, failure)
103
@return: response (okay, failure)
109
106
subj_short_name = props['subj_short_name']
142
144
def dispatch(props):
143
145
logging.debug(repr(props))
147
store = ivle.database.get_store(config)
144
148
action = props.keys()[0]
145
return actions[action](props[action])
149
res = actions[action](store, props[action], config)
151
if res['response'] == 'okay':
147
158
if __name__ == "__main__":
148
159
pid = os.getpid()
150
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
151
logging.info("Starting usrmgt server on port %d (pid = %d)" %
152
(ivle.conf.usrmgt_port, pid))
154
ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
161
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
155
162
True, dispatch, initializer)