13
# usrmgt-server <port> <magic>
15
# User management operations:
17
# - [Re]Create jail for a user
18
# - Create a svn repository for a user
23
# - Disable a user's account
24
# - Enable a user's account
26
# - Rebuild svn config
27
# - Rebuild svn auth file
28
# - Rebuild passwd + push to nodes.
30
def activate_user(props):
31
"""Create the on-disk stuff for the given user.
32
Sets the state of the user in the db from pending to enabled.
34
login - the user name for the jail
39
os.umask(0022) # Bad, but start_server sets it worse.
41
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):
75
"""Rebuilds the svn config file
77
response (okay, failure)
80
ivle.makeuser.rebuild_svn_config()
82
logging.warning('Rebuild of Subversion authorization config failed!')
83
return{'response': 'failure', 'msg': repr(e)}
85
return {'response': 'okay'}
87
def rebuild_svn_group_config(props):
88
"""Rebuilds the svn group config file
90
response (okay, failure)
93
ivle.makeuser.rebuild_svn_group_config()
96
'Rebuild of Subversion group authorization config failed!')
97
return{'response': 'failure', 'msg': repr(e)}
99
return {'response': 'okay'}
101
def create_group_repository(props):
102
"""Creates on disk repository for the given group
104
subj_short_name, year, semester, groupnm
106
response (okay, failure)
109
subj_short_name = props['subj_short_name']
111
semester = props['semester']
112
groupnm = props['groupnm']
114
namespace = "_".join([subj_short_name, year, semester, groupnm])
115
repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
116
logging.debug("Creating Subversion repository %s"%repopath)
118
ivle.makeuser.make_svn_repo(repopath)
120
logging.error("Failed to create Subversion repository %s: %s"%
122
return {'response': 'failure', 'msg': repr(e)}
124
return {'response': 'okay'}
127
'activate_user':activate_user,
128
'create_group_repository':create_group_repository,
129
'rebuild_svn_config':rebuild_svn_config,
130
'rebuild_svn_group_config':rebuild_svn_group_config,
135
pidfile = open('/var/run/usrmgt-server.pid', 'w')
136
pidfile.write('%d\n' % os.getpid())
138
except IOError, (errno, strerror):
139
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
143
logging.debug(repr(props))
144
action = props.keys()[0]
145
return actions[action](props[action])
147
if __name__ == "__main__":
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,
155
True, dispatch, initializer)