73
# Import modules from the website is tricky since they're in the www
75
sys.path.append(os.path.join(os.getcwd(), 'lib'))
77
import common.makeuser
79
# Determine which Python version (2.4 or 2.5, for example) we are running,
80
# and use that as the filename to the Python directory.
81
# Just get the first 3 characters of sys.version.
82
PYTHON_VERSION = sys.version[0:3]
84
# Operating system files to copy over into the jail.
85
# These will be copied from the given place on the OS file system into the
86
# same place within the jail.
89
'/lib/tls/i686/cmov/libc.so.6',
90
'/lib/tls/i686/cmov/libdl.so.2',
91
'/lib/tls/i686/cmov/libm.so.6',
92
'/lib/tls/i686/cmov/libpthread.so.0',
93
'/lib/tls/i686/cmov/libutil.so.1',
96
# These 2 files do not exist in Ubuntu
97
#'/etc/ld.so.preload',
98
#'/etc/ld.so.nohwcap',
104
'/usr/bin/python%s' % PYTHON_VERSION,
105
# Needed by fileservice
106
'/lib/libcom_err.so.2',
107
'/lib/libcrypt.so.1',
108
'/lib/libkeyutils.so.1',
109
'/lib/libresolv.so.2',
112
'/usr/lib/libapr-1.so.0',
113
'/usr/lib/libaprutil-1.so.0',
114
'/usr/lib/libdb-4.4.so',
115
'/usr/lib/libexpat.so.1',
116
'/usr/lib/libgcrypt.so.11',
117
'/usr/lib/libgnutls.so.13',
118
'/usr/lib/libgpg-error.so.0',
119
'/usr/lib/libgssapi_krb5.so.2',
120
'/usr/lib/libk5crypto.so.3',
121
'/usr/lib/libkrb5.so.3',
122
'/usr/lib/libkrb5support.so.0',
123
'/usr/lib/liblber.so.2',
124
'/usr/lib/libldap_r.so.2',
125
'/usr/lib/libneon.so.26',
126
'/usr/lib/libpq.so.5',
127
'/usr/lib/libsasl2.so.2',
128
'/usr/lib/libsqlite3.so.0',
129
'/usr/lib/libsvn_client-1.so.1',
130
'/usr/lib/libsvn_delta-1.so.1',
131
'/usr/lib/libsvn_diff-1.so.1',
132
'/usr/lib/libsvn_fs-1.so.1',
133
'/usr/lib/libsvn_fs_base-1.so.1',
134
'/usr/lib/libsvn_fs_fs-1.so.1',
135
'/usr/lib/libsvn_ra-1.so.1',
136
'/usr/lib/libsvn_ra_dav-1.so.1',
137
'/usr/lib/libsvn_ra_local-1.so.1',
138
'/usr/lib/libsvn_ra_svn-1.so.1',
139
'/usr/lib/libsvn_repos-1.so.1',
140
'/usr/lib/libsvn_subr-1.so.1',
141
'/usr/lib/libsvn_wc-1.so.1',
142
'/usr/lib/libtasn1.so.3',
143
'/usr/lib/libxml2.so.2',
144
# Needed by matplotlib
145
'/usr/lib/i686/cmov/libssl.so.0.9.8',
146
'/usr/lib/i686/cmov/libcrypto.so.0.9.8',
147
'/lib/tls/i686/cmov/libnsl.so.1',
148
'/usr/lib/libz.so.1',
149
'/usr/lib/atlas/liblapack.so.3',
150
'/usr/lib/atlas/libblas.so.3',
151
'/usr/lib/libg2c.so.0',
152
'/usr/lib/libstdc++.so.6',
153
'/usr/lib/libfreetype.so.6',
154
'/usr/lib/libpng12.so.0',
155
'/usr/lib/libBLT.2.4.so.8.4',
156
'/usr/lib/libtk8.4.so.0',
157
'/usr/lib/libtcl8.4.so.0',
158
'/usr/lib/tcl8.4/init.tcl',
159
'/usr/lib/libX11.so.6',
160
'/usr/lib/libXau.so.6',
161
'/usr/lib/libXdmcp.so.6',
162
'/lib/libgcc_s.so.1',
165
'/lib/libnss_dns.so.2',
166
#'/lib/libnss_mdns4.so',
171
'/etc/nsswitch.conf',
172
'/lib/libnss_files.so.2',
174
# Symlinks to make within the jail. Src mapped to dst.
176
'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
178
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
180
'/usr/lib/python%s' % PYTHON_VERSION:
181
'jail/usr/lib/python%s' % PYTHON_VERSION,
182
'/usr/share/matplotlib': 'jail/usr/share/matplotlib',
183
'/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
187
"""A configuration option; one of the things written to conf.py."""
188
def __init__(self, option_name, default, prompt, comment):
189
"""Creates a configuration option.
190
option_name: Name of the variable in conf.py. Also name of the
191
command-line argument to setup.py conf.
192
default: Default value for this variable.
193
prompt: (Short) string presented during the interactive prompt in
195
comment: (Long) comment string stored in conf.py. Each line of this
196
string should begin with a '#'.
198
self.option_name = option_name
199
self.default = default
201
self.comment = comment
203
# Configuration options, defaults and descriptions
205
config_options.append(ConfigOption("root_dir", "/",
206
"""Root directory where IVLE is located (in URL space):""",
208
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
210
# eg. "/" or "/ivle"."""))
211
config_options.append(ConfigOption("ivle_install_dir", "/opt/ivle",
212
'Root directory where IVLE will be installed (on the local file '
215
# In the local file system, where IVLE is actually installed.
216
# This directory should contain the "www" and "bin" directories."""))
217
config_options.append(ConfigOption("jail_base", "/home/informatics/jails",
218
"""Location of Directories
219
=======================
220
Root directory where the jails (containing user files) are stored
221
(on the local file system):""",
223
# In the local file system, where are the student/user file spaces located.
224
# The user jails are expected to be located immediately in subdirectories of
225
# this location."""))
226
config_options.append(ConfigOption("subjects_base",
227
"/home/informatics/subjects",
228
"""Root directory where the subject directories (containing worksheets
229
and other per-subject files) are stored (on the local file system):""",
231
# In the local file system, where are the per-subject file spaces located.
232
# The individual subject directories are expected to be located immediately
233
# in subdirectories of this location."""))
234
config_options.append(ConfigOption("exercises_base",
235
"/home/informatics/exercises",
236
"""Root directory where the exercise directories (containing
237
subject-independent exercise sheets) are stored (on the local file
240
# In the local file system, where are the subject-independent exercise sheet
241
# file spaces located."""))
242
config_options.append(ConfigOption("tos_path",
243
"/home/informatics/tos.html",
244
"""Location where the Terms of Service document is stored (on the local
247
# In the local file system, where is the Terms of Service document located."""))
248
config_options.append(ConfigOption("public_host", "public.localhost",
249
"""Hostname which will cause the server to go into "public mode",
250
providing login-free access to student's published work:""",
252
# The server goes into "public mode" if the browser sends a request with this
253
# host. This is for security reasons - we only serve public student files on a
254
# separate domain to the main IVLE site.
255
# Public mode does not use cookies, and serves only public content.
256
# Private mode (normal mode) requires login, and only serves files relevant to
257
# the logged-in user."""))
258
config_options.append(ConfigOption("allowed_uids", "33",
259
"""UID of the web server process which will run IVLE.
260
Only this user may execute the trampoline. May specify multiple users as
261
a comma-separated list.
264
# The User-ID of the web server process which will run IVLE, and any other
265
# users who are allowed to run the trampoline. This is stores as a string of
266
# comma-separated integers, simply because it is not used within Python, only
267
# used by the setup program to write to conf.h (see setup.py config)."""))
268
config_options.append(ConfigOption("db_host", "localhost",
269
"""PostgreSQL Database config
270
==========================
271
Hostname of the DB server:""",
273
### PostgreSQL Database config ###
274
# Database server hostname"""))
275
config_options.append(ConfigOption("db_port", "5432",
276
"""Port of the DB server:""",
278
# Database server port"""))
279
config_options.append(ConfigOption("db_dbname", "ivle",
280
"""Database name:""",
283
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
284
"""Forum Database name:""",
286
# Forum Database name"""))
287
config_options.append(ConfigOption("db_user", "postgres",
288
"""Username for DB server login:""",
290
# Database username"""))
291
config_options.append(ConfigOption("db_password", "",
292
"""Password for DB server login:
293
(Caution: This password is stored in plaintext in lib/conf/conf.py)""",
295
# Database password"""))
296
config_options.append(ConfigOption("auth_modules", "ldap_auth",
297
"""Authentication config
298
=====================
299
Comma-separated list of authentication modules. Only "ldap" is available
302
# Comma-separated list of authentication modules.
303
# These refer to importable Python modules in the www/auth directory.
304
# Modules "ldap" and "guest" are available in the source tree, but
305
# other modules may be plugged in to auth against organisation-specific
306
# auth backends."""))
307
config_options.append(ConfigOption("ldap_url", "ldaps://www.example.com",
308
"""(LDAP options are only relevant if "ldap" is included in the list of
310
URL for LDAP authentication server:""",
312
# URL for LDAP authentication server"""))
313
config_options.append(ConfigOption("ldap_format_string",
314
"uid=%s,ou=users,o=example",
315
"""Format string for LDAP auth request:
316
(Must contain a single "%s" for the user's login name)""",
318
# Format string for LDAP auth request
319
# (Must contain a single "%s" for the user's login name)"""))
320
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
323
The base url for accessing subversion repositories:""",
325
# The base url for accessing subversion repositories."""))
326
config_options.append(ConfigOption("svn_conf", "/opt/ivle/svn/svn.conf",
327
"""The location of the subversion configuration file used by apache
328
to host the user repositories:""",
330
# The location of the subversion configuration file used by
331
# apache to host the user repositories."""))
332
config_options.append(ConfigOption("svn_repo_path", "/home/informatics/repositories",
333
"""The root directory for the subversion repositories:""",
335
# The root directory for the subversion repositories."""))
336
config_options.append(ConfigOption("svn_auth_ivle", "/opt/ivle/svn/ivle.auth",
337
"""The location of the password file used to authenticate users
338
of the subversion repository from the ivle server:""",
340
# The location of the password file used to authenticate users
341
# of the subversion repository from the ivle server."""))
342
config_options.append(ConfigOption("svn_auth_local", "/opt/ivle/svn/local.auth",
343
"""The location of the password file used to authenticate local users
344
of the subversion repository:""",
346
# The location of the password file used to authenticate local users
347
# of the subversion repository."""))
348
config_options.append(ConfigOption("usrmgt_host", "localhost",
349
"""User Management Server config
350
============================
351
The hostname where the usrmgt-server runs:""",
353
# The hostname where the usrmgt-server runs."""))
354
config_options.append(ConfigOption("usrmgt_port", "2178",
355
"""The port where the usrmgt-server runs:""",
357
# The port where the usrmgt-server runs."""))
358
config_options.append(ConfigOption("usrmgt_magic", "",
359
"""The password for the usrmgt-server:""",
361
# The password for the usrmgt-server."""))
363
71
# Try importing existing conf, but if we can't just set up defaults
364
72
# The reason for this is that these settings are used by other phases
365
73
# of setup besides conf, so we need to know them.
366
74
# Also this allows you to hit Return to accept the existing value.
368
confmodule = __import__("lib/conf/conf")
369
for opt in config_options:
371
globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
373
globals()[opt.option_name] = opt.default
76
confmodule = __import__("www/conf/conf")
78
root_dir = confmodule.root_dir
82
ivle_install_dir = confmodule.ivle_install_dir
84
ivle_install_dir = "/opt/ivle"
86
jail_base = confmodule.jail_base
88
jail_base = "/home/informatics/jails"
374
89
except ImportError:
375
90
# Just set reasonable defaults
376
for opt in config_options:
377
globals()[opt.option_name] = opt.default
92
ivle_install_dir = "/opt/ivle"
93
jail_base = "/home/informatics/jails"
379
97
# Try importing install_list, but don't fail if we can't, because listmake can
380
98
# function without it.
652
332
print """This tool will create the following files:
657
335
prompting you for details about your configuration. The file will be
658
336
overwritten if it already exists. It will *not* install or deploy IVLE.
660
338
Please hit Ctrl+C now if you do not wish to do this.
661
""" % (conffile, jailconffile, conf_hfile, phpBBconffile)
339
""" % (conffile, conf_hfile)
663
341
# Get information from the administrator
664
342
# If EOF is encountered at any time during the questioning, just exit
667
for opt in config_options:
668
globals()[opt.option_name] = \
669
query_user(globals()[opt.option_name], opt.prompt)
345
root_dir = query_user(root_dir,
346
"""Root directory where IVLE is located (in URL space):""")
347
ivle_install_dir = query_user(ivle_install_dir,
348
'Root directory where IVLE will be installed (on the local file '
350
jail_base = query_user(jail_base,
351
"""Root directory where the jails (containing user files) are stored
352
(on the local file system):""")
353
allowed_uids = query_user(allowed_uids,
354
"""UID of the web server process which will run IVLE.
355
Only this user may execute the trampoline. May specify multiple users as
356
a comma-separated list.
671
360
opts = dict(opts)
672
361
# Non-interactive mode. Parse the options.
673
for opt in config_options:
674
if '--' + opt.option_name in opts:
675
globals()[opt.option_name] = opts['--' + opt.option_name]
362
if '--root_dir' in opts:
363
root_dir = opts['--root_dir']
364
if '--ivle_install_dir' in opts:
365
ivle_install_dir = opts['--ivle_install_dir']
366
if '--jail_base' in opts:
367
jail_base = opts['--jail_base']
368
if '--allowed_uids' in opts:
369
allowed_uids = opts['--allowed_uids']
677
371
# Error handling on input values
679
allowed_uids_list = map(int, allowed_uids.split(','))
373
allowed_uids = map(int, allowed_uids.split(','))
680
374
except ValueError:
681
375
print >>sys.stderr, (
682
376
"Invalid UID list (%s).\n"
683
377
"Must be a comma-separated list of integers." % allowed_uids)
686
db_port = int(db_port)
687
if db_port < 0 or db_port >= 65536: raise ValueError()
689
print >>sys.stderr, (
690
"Invalid DB port (%s).\n"
691
"Must be an integer between 0 and 65535." % repr(db_port))
694
usrmgt_port = int(usrmgt_port)
695
if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
697
print >>sys.stderr, (
698
"Invalid user management port (%s).\n"
699
"Must be an integer between 0 and 65535." % repr(usrmgt_port))
702
# Generate the forum secret
703
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
705
# Write lib/conf/conf.py
380
# Write www/conf/conf.py
708
383
conf = open(conffile, "w")
948
522
# chown trampoline to root and set setuid bit
949
523
action_chown_setuid(tramppath, dry)
951
# Create a scripts directory to put the usrmgt-server in.
952
action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
953
usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
954
action_copyfile('scripts/usrmgt-server', usrmgtpath, dry)
955
action_chmod_x(usrmgtpath, dry)
957
# Copy the www and lib directories using the list
525
# Copy the www directory using the list
958
526
action_copylist(install_list.list_www, ivle_install_dir, dry)
959
action_copylist(install_list.list_lib, ivle_install_dir, dry)
961
# Copy the php directory
962
action_copytree('www/php/phpBB3',os.path.join(ivle_install_dir,'www/php/phpBB3'),
966
529
# Copy the local jail directory built by the build action
967
530
# to the jails template directory (it will be used as a template
968
531
# for all the students' jails).
969
532
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
971
# Copy the subjects and exercises directories across
972
action_copylist(install_list.list_subjects, subjects_base, dry,
974
action_copylist(install_list.list_exercises, exercises_base, dry,
975
srcdir="./exercises")
977
# Append IVLE path to ivle.pth in python site packages
978
# (Unless it's already there)
979
ivle_pth = os.path.join(sys.prefix,
980
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
981
ivle_www = os.path.join(ivle_install_dir, "www")
982
ivle_lib = os.path.join(ivle_install_dir, "lib")
983
write_ivle_pth = True
984
write_ivle_lib_pth = True
986
file = open(ivle_pth, 'r')
988
if line.strip() == ivle_www:
989
write_ivle_pth = False
990
elif line.strip() == ivle_lib:
991
write_ivle_lib_pth = False
993
except (IOError, OSError):
996
action_append(ivle_pth, ivle_www)
997
if write_ivle_lib_pth:
998
action_append(ivle_pth, ivle_lib)
1002
def updatejails(args):
1003
# Get "dry" variable from command line
1004
(opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
1006
dry = '-n' in opts or '--dry' in opts
1009
print "Dry run (no actions will be executed\n"
1011
if not dry and os.geteuid() != 0:
1012
print >>sys.stderr, "Must be root to run install"
1013
print >>sys.stderr, "(I need to chown some files)."
1016
# Update the template jail directory in case it hasn't been installed
1018
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
1020
# Re-link all the files in all students jails.
1021
for dir in os.listdir(jail_base):
1022
if dir == 'template': continue
1023
# First back up the student's home directory
1024
temp_home = os.tmpnam()
1025
action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
1026
# Delete the student's jail and relink the jail files
1027
action_linktree(os.path.join(jail_base, 'template'),
1028
os.path.join(jail_base, dir), dry)
1029
# Restore the student's home directory
1030
action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
1031
# Set up the user's home directory just in case they don't have a
1032
# directory for this yet
1033
action_mkdir(os.path.join(jail_base, dir, 'home', dir), dry)