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