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