10
import common.makeuser
11
import common.studpath
14
# usrmgt-server <port> <magic>
16
# User management operations:
18
# - [Re]Create jail for a user
19
# - Create a svn repository for a user
24
# - Disable a user's account
25
# - Enable a user's account
27
# - Rebuild svn config
28
# - Rebuild svn auth file
29
# - Rebuild passwd + push to nodes.
31
def activate_user(props):
32
"""Create the on-disk stuff for the given user.
33
Sets the state of the user in the db from pending to enabled.
35
login - the user name for the jail
40
os.umask(0022) # Bad, but start_server sets it worse.
42
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=False)
58
rebuild_svn_config(props)
60
logging.debug("Adding Subversion authentication")
61
passwd = common.makeuser.make_svn_auth(login, throw_on_error=False)
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):
76
"""Rebuilds the svn config file
78
response (okay, failure)
81
common.makeuser.rebuild_svn_config()
83
logging.warning('Rebuild of Subversion authorization config failed!')
84
return{'response': 'failure', 'msg': repr(e)}
86
return {'response': 'okay'}
88
def rebuild_svn_group_config(props):
89
"""Rebuilds the svn group config file
91
response (okay, failure)
94
common.makeuser.rebuild_svn_group_config()
97
'Rebuild of Subversion group authorization config failed!')
98
return{'response': 'failure', 'msg': repr(e)}
100
return {'response': 'okay'}
102
def create_group_repository(props):
103
"""Creates on disk repository for the given group
105
subj_short_name, year, semester, groupnm
107
response (okay, failure)
110
subj_short_name = props['subj_short_name']
112
semester = props['semester']
113
groupnm = props['groupnm']
115
namespace = "_".join([subj_short_name, year, semester, groupnm])
116
repopath = os.path.join(conf.svn_repo_path, 'groups', namespace)
117
logging.debug("Creating Subversion repository %s"%repopath)
119
common.makeuser.make_svn_repo(repopath)
121
logging.error("Failed to create Subversion repository %s: %s"%
123
return {'response': 'failure', 'msg': repr(e)}
125
return {'response': 'okay'}
128
'activate_user':activate_user,
129
'create_group_repository':create_group_repository,
130
'rebuild_svn_config':rebuild_svn_config,
131
'rebuild_svn_group_config':rebuild_svn_group_config,
136
pidfile = open('/var/run/usrmgt-server.pid', 'w')
137
pidfile.write('%d\n' % os.getpid())
139
except IOError, (errno, strerror):
140
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
144
logging.debug(repr(props))
145
action = props.keys()[0]
146
return actions[action](props[action])
148
if __name__ == "__main__":
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)