27
29
# - Rebuild svn auth file
28
30
# - Rebuild passwd + push to nodes.
30
def activate_user(store, 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
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?'}
39
48
os.umask(0022) # Bad, but start_server sets it worse.
41
50
login = props['login']
46
55
user = ivle.database.User.get_by_login(store, login)
48
57
# make svn config/auth
49
repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
58
repopath = os.path.join(config['paths']['svn']['repo_path'],
50
60
logging.debug("Creating user's Subversion repository")
51
61
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
53
rebuild_svn_config(store, props)
63
rebuild_svn_config(store, props, config)
55
65
logging.debug("Adding Subversion authentication")
56
passwd = ivle.makeuser.make_svn_auth(store, login,
66
passwd = ivle.makeuser.make_svn_auth(store, login, config,
57
67
throw_on_error=True)
59
69
logging.debug("Creating jail")
60
ivle.makeuser.make_jail(user)
70
ivle.makeuser.make_jail(user, config)
62
72
logging.info("Enabling user")
63
73
user.state = u'enabled'
65
75
return {"response": "okay"}
67
def rebuild_svn_config(store, props):
77
def rebuild_svn_config(store, props, config):
68
78
"""Rebuilds the svn config file
70
response (okay, failure)
79
@param config: An ivle.config.Config object.
80
@return: response (okay, failure)
73
ivle.makeuser.rebuild_svn_config(store)
83
ivle.makeuser.rebuild_svn_config(store, config)
74
84
except Exception, e:
75
85
logging.warning('Rebuild of Subversion authorization config failed!')
76
86
return{'response': 'failure', 'msg': repr(e)}
78
88
return {'response': 'okay'}
80
def rebuild_svn_group_config(store, props):
90
def rebuild_svn_group_config(store, props, config):
81
91
"""Rebuilds the svn group config file
83
response (okay, failure)
92
@param config: An ivle.config.Config object.
93
@return: response (okay, failure)
86
ivle.makeuser.rebuild_svn_group_config(store)
96
ivle.makeuser.rebuild_svn_group_config(store, config)
87
97
except Exception, e:
89
99
'Rebuild of Subversion group authorization config failed!')
92
102
return {'response': 'okay'}
94
def create_group_repository(store, props):
104
def create_group_repository(store, props, config):
95
105
"""Creates on disk repository for the given group
106
@param config: An ivle.config.Config object.
96
107
Expected properties:
97
108
subj_short_name, year, semester, groupnm
99
response (okay, failure)
109
@return: response (okay, failure)
102
112
subj_short_name = props['subj_short_name']
105
115
groupnm = props['groupnm']
107
117
namespace = "_".join([subj_short_name, year, semester, groupnm])
108
repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
118
repopath = os.path.join(config['paths']['svn']['repo_path'],
109
120
logging.debug("Creating Subversion repository %s"%repopath)
111
122
ivle.makeuser.make_svn_repo(repopath)
126
137
def initializer():
127
138
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
128
139
logging.info("Starting usrmgt server on port %d (pid = %d)" %
129
(ivle.conf.usrmgt_port, pid))
140
(config['usrmgt']['port'], pid))
132
143
pidfile = open('/var/run/usrmgt-server.pid', 'w')
139
150
def dispatch(props):
140
151
logging.debug(repr(props))
142
store = ivle.database.get_store()
153
store = ivle.database.get_store(config)
143
154
action = props.keys()[0]
144
res = actions[action](store, props[action])
155
res = actions[action](store, props[action], config)
146
157
if res['response'] == 'okay':
153
164
if __name__ == "__main__":
154
165
pid = os.getpid()
156
ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
167
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
157
168
True, dispatch, initializer)