28
29
# - Rebuild svn auth file
29
30
# - Rebuild passwd + push to nodes.
31
def activate_user(props):
32
def activate_user(store, props, config):
32
33
"""Create the on-disk stuff for the given user.
33
34
Sets the state of the user in the db from pending to enabled.
35
@param config: An ivle.config.Config object.
34
36
Expected properties:
35
37
login - the user name for the jail
40
42
os.umask(0022) # Bad, but start_server sets it worse.
42
44
login = props['login']
48
# FIXME: check we're pending
50
details = db.get_user(login)
52
# make svn config/auth
54
repopath = os.path.join(conf.svn_repo_path, 'users', login)
55
logging.debug("Creating user's Subversion repository")
56
common.makeuser.make_svn_repo(repopath, throw_on_error=True)
58
rebuild_svn_config(props)
60
logging.debug("Adding Subversion authentication")
61
passwd = common.makeuser.make_svn_auth(login, throw_on_error=True)
62
logging.debug("passwd: %s" % passwd)
64
logging.debug("Creating jail")
65
common.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
67
logging.info("Enabling user")
68
db.update_user(login, state='enabled')
70
return {"response": "okay"}
75
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):
76
72
"""Rebuilds the svn config file
78
response (okay, failure)
73
@param config: An ivle.config.Config object.
74
@return: response (okay, failure)
81
common.makeuser.rebuild_svn_config()
77
ivle.makeuser.rebuild_svn_config(store, config)
82
78
except Exception, e:
83
79
logging.warning('Rebuild of Subversion authorization config failed!')
84
80
return{'response': 'failure', 'msg': repr(e)}
86
82
return {'response': 'okay'}
88
def rebuild_svn_group_config(props):
84
def rebuild_svn_group_config(store, props, config):
89
85
"""Rebuilds the svn group config file
91
response (okay, failure)
86
@param config: An ivle.config.Config object.
87
@return: response (okay, failure)
94
common.makeuser.rebuild_svn_group_config()
90
ivle.makeuser.rebuild_svn_group_config(store, config)
95
91
except Exception, e:
97
93
'Rebuild of Subversion group authorization config failed!')
100
96
return {'response': 'okay'}
102
def create_group_repository(props):
98
def create_group_repository(store, props, config):
103
99
"""Creates on disk repository for the given group
100
@param config: An ivle.config.Config object.
104
101
Expected properties:
105
102
subj_short_name, year, semester, groupnm
107
response (okay, failure)
103
@return: response (okay, failure)
110
106
subj_short_name = props['subj_short_name']
113
109
groupnm = props['groupnm']
115
111
namespace = "_".join([subj_short_name, year, semester, groupnm])
116
repopath = os.path.join(conf.svn_repo_path, 'groups', namespace)
112
repopath = os.path.join(config['paths']['svn']['repo_path'],
117
114
logging.debug("Creating Subversion repository %s"%repopath)
119
common.makeuser.make_svn_repo(repopath)
116
ivle.makeuser.make_svn_repo(repopath)
120
117
except Exception, e:
121
118
logging.error("Failed to create Subversion repository %s: %s"%
122
119
(repopath,repr(e)))
143
144
def dispatch(props):
144
145
logging.debug(repr(props))
147
store = ivle.database.get_store(config)
145
148
action = props.keys()[0]
146
return actions[action](props[action])
149
res = actions[action](store, props[action], config)
151
if res['response'] == 'okay':
148
158
if __name__ == "__main__":
149
159
pid = os.getpid()
151
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
152
logging.info("Starting usrmgt server on port %d (pid = %d)" %
153
(conf.usrmgt_port, pid))
155
common.chat.start_server(conf.usrmgt_port, conf.usrmgt_magic, True, dispatch, initializer)
161
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
162
True, dispatch, initializer)