71
# Import modules from the website is tricky since they're in the www
73
sys.path.append(os.path.join(os.getcwd(), 'www'))
75
import common.makeuser
77
# Determine which Python version (2.4 or 2.5, for example) we are running,
78
# and use that as the filename to the Python directory.
79
# Just get the first 3 characters of sys.version.
80
PYTHON_VERSION = sys.version[0:3]
82
# Operating system files to copy over into the jail.
83
# These will be copied from the given place on the OS file system into the
84
# same place within the jail.
87
'/lib/tls/i686/cmov/libc.so.6',
88
'/lib/tls/i686/cmov/libdl.so.2',
89
'/lib/tls/i686/cmov/libm.so.6',
90
'/lib/tls/i686/cmov/libpthread.so.0',
91
'/lib/tls/i686/cmov/libutil.so.1',
94
# These 2 files do not exist in Ubuntu
95
#'/etc/ld.so.preload',
96
#'/etc/ld.so.nohwcap',
102
'/usr/bin/python%s' % PYTHON_VERSION,
103
# Needed by matplotlib
104
'/usr/lib/i686/cmov/libssl.so.0.9.8',
105
'/usr/lib/i686/cmov/libcrypto.so.0.9.8',
106
'/lib/tls/i686/cmov/libnsl.so.1',
107
'/usr/lib/libz.so.1',
108
'/usr/lib/atlas/liblapack.so.3',
109
'/usr/lib/atlas/libblas.so.3',
110
'/usr/lib/libg2c.so.0',
111
'/usr/lib/libstdc++.so.6',
112
'/usr/lib/libfreetype.so.6',
113
'/usr/lib/libpng12.so.0',
114
'/usr/lib/libBLT.2.4.so.8.4',
115
'/usr/lib/libtk8.4.so.0',
116
'/usr/lib/libtcl8.4.so.0',
117
'/usr/lib/tcl8.4/init.tcl',
118
'/usr/lib/libX11.so.6',
119
'/usr/lib/libXau.so.6',
120
'/usr/lib/libXdmcp.so.6',
121
'/lib/libgcc_s.so.1',
124
# Symlinks to make within the jail. Src mapped to dst.
126
'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
128
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
130
'/usr/lib/python%s' % PYTHON_VERSION:
131
'jail/usr/lib/python%s' % PYTHON_VERSION,
132
'/usr/share/matplotlib': 'jail/usr/share/matplotlib',
133
'/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
137
"""A configuration option; one of the things written to conf.py."""
138
def __init__(self, option_name, default, prompt, comment):
139
"""Creates a configuration option.
140
option_name: Name of the variable in conf.py. Also name of the
141
command-line argument to setup.py conf.
142
default: Default value for this variable.
143
prompt: (Short) string presented during the interactive prompt in
145
comment: (Long) comment string stored in conf.py. Each line of this
146
string should begin with a '#'.
148
self.option_name = option_name
149
self.default = default
151
self.comment = comment
153
# Configuration options, defaults and descriptions
155
config_options.append(ConfigOption("root_dir", "/ivle",
156
"""Root directory where IVLE is located (in URL space):""",
158
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
160
# eg. "/" or "/ivle"."""))
161
config_options.append(ConfigOption("ivle_install_dir", "/opt/ivle",
162
'Root directory where IVLE will be installed (on the local file '
165
# In the local file system, where IVLE is actually installed.
166
# This directory should contain the "www" and "bin" directories."""))
167
config_options.append(ConfigOption("jail_base", "/home/informatics/jails",
168
"""Root directory where the jails (containing user files) are stored
169
(on the local file system):""",
171
# In the local file system, where are the student/user file spaces located.
172
# The user jails are expected to be located immediately in subdirectories of
173
# this location."""))
174
config_options.append(ConfigOption("subjects_base",
175
"/home/informatics/subjects",
176
"""Root directory where the subject directories (containing worksheets
177
and other per-subject files) are stored (on the local file system):""",
179
# In the local file system, where are the per-subject file spaces located.
180
# The individual subject directories are expected to be located immediately
181
# in subdirectories of this location."""))
182
config_options.append(ConfigOption("problems_base",
183
"/home/informatics/problems",
184
"""Root directory where the problem directories (containing
185
subject-independent problem sheets) are stored (on the local file
188
# In the local file system, where are the subject-independent problem sheet
189
# file spaces located."""))
190
config_options.append(ConfigOption("public_host", "public.localhost",
191
"""Hostname which will cause the server to go into "public mode",
192
providing login-free access to student's published work:""",
194
# The server goes into "public mode" if the browser sends a request with this
195
# host. This is for security reasons - we only serve public student files on a
196
# separate domain to the main IVLE site.
197
# Public mode does not use cookies, and serves only public content.
198
# Private mode (normal mode) requires login, and only serves files relevant to
199
# the logged-in user."""))
200
config_options.append(ConfigOption("allowed_uids", "33",
201
"""UID of the web server process which will run IVLE.
202
Only this user may execute the trampoline. May specify multiple users as
203
a comma-separated list.
206
# The User-ID of the web server process which will run IVLE, and any other
207
# users who are allowed to run the trampoline. This is stores as a string of
208
# comma-separated integers, simply because it is not used within Python, only
209
# used by the setup program to write to conf.h (see setup.py config)."""))
210
config_options.append(ConfigOption("db_host", "localhost",
211
"""PostgreSQL Database config
212
==========================
213
Hostname of the DB server:""",
215
### PostgreSQL Database config ###
216
# Database server hostname"""))
217
config_options.append(ConfigOption("db_port", "5432",
218
"""Port of the DB server:""",
220
# Database server port"""))
221
config_options.append(ConfigOption("db_dbname", "ivle",
222
"""Database name:""",
225
config_options.append(ConfigOption("db_user", "postgres",
226
"""Username for DB server login:""",
228
# Database username"""))
229
config_options.append(ConfigOption("db_password", "",
230
"""Password for DB server login:
231
(Caution: This password is stored in plaintext in www/conf/conf.py)""",
233
# Database password"""))
71
235
# Try importing existing conf, but if we can't just set up defaults
72
236
# The reason for this is that these settings are used by other phases
73
237
# of setup besides conf, so we need to know them.
74
238
# Also this allows you to hit Return to accept the existing value.
76
240
confmodule = __import__("www/conf/conf")
77
root_dir = confmodule.root_dir
78
ivle_install_dir = confmodule.ivle_install_dir
79
jail_base = confmodule.jail_base
241
for opt in config_options:
243
globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
245
globals()[opt.option_name] = opt.default
80
246
except ImportError:
81
247
# Just set reasonable defaults
83
ivle_install_dir = "/opt/ivle"
84
jail_base = "/home/informatics/jails"
248
for opt in config_options:
249
globals()[opt.option_name] = opt.default
88
251
# Try importing install_list, but don't fail if we can't, because listmake can
89
252
# function without it.
336
524
# If EOF is encountered at any time during the questioning, just exit
339
root_dir = query_user(root_dir,
340
"""Root directory where IVLE is located (in URL space):""")
341
ivle_install_dir = query_user(ivle_install_dir,
342
'Root directory where IVLE will be installed (on the local file '
344
jail_base = query_user(jail_base,
345
"""Root directory where the jails (containing user files) are stored
346
(on the local file system):""")
347
allowed_uids = query_user(allowed_uids,
348
"""UID of the web server process which will run IVLE.
349
Only this user may execute the trampoline. May specify multiple users as
350
a comma-separated list.
527
for opt in config_options:
528
globals()[opt.option_name] = \
529
query_user(globals()[opt.option_name], opt.prompt)
354
531
opts = dict(opts)
355
532
# Non-interactive mode. Parse the options.
356
if '--root_dir' in opts:
357
root_dir = opts['--root_dir']
358
if '--ivle_install_dir' in opts:
359
ivle_install_dir = opts['--ivle_install_dir']
360
if '--jail_base' in opts:
361
jail_base = opts['--jail_base']
362
if '--allowed_uids' in opts:
363
allowed_uids = opts['--allowed_uids']
533
for opt in config_options:
534
if '--' + opt.option_name in opts:
535
globals()[opt.option_name] = opts['--' + opt.option_name]
365
537
# Error handling on input values
367
allowed_uids = map(int, allowed_uids.split(','))
539
allowed_uids_list = map(int, allowed_uids.split(','))
368
540
except ValueError:
369
541
print >>sys.stderr, (
370
542
"Invalid UID list (%s).\n"
371
543
"Must be a comma-separated list of integers." % allowed_uids)
546
db_port = int(db_port)
547
if db_port < 0 or db_port >= 65536: raise ValueError()
549
print >>sys.stderr, (
550
"Invalid DB port (%s).\n"
551
"Must be an integer between 0 and 65535." % repr(db_port))
374
554
# Write www/conf/conf.py
481
649
"""Copies necessary Operating System files from their usual locations
482
650
into the jail/ directory of the cwd."""
483
651
# Currently source paths are configured for Ubuntu.
484
copy_file_to_jail('/lib/ld-linux.so.2', dry)
485
copy_file_to_jail('/lib/tls/i686/cmov/libc.so.6', dry)
486
copy_file_to_jail('/lib/tls/i686/cmov/libdl.so.2', dry)
487
copy_file_to_jail('/lib/tls/i686/cmov/libm.so.6', dry)
488
copy_file_to_jail('/lib/tls/i686/cmov/libpthread.so.0', dry)
489
copy_file_to_jail('/lib/tls/i686/cmov/libutil.so.1', dry)
490
copy_file_to_jail('/usr/bin/python2.5', dry)
491
action_symlink('python2.5', 'jail/usr/bin/python', dry)
492
action_copytree('/usr/lib/python2.5', 'jail/usr/lib/python2.5', dry)
652
for filename in JAIL_FILES:
653
copy_file_to_jail(filename, dry)
654
for src, dst in JAIL_LINKS.items():
655
action_symlink(src, dst, dry)
656
for src, dst in JAIL_COPYTREES.items():
657
action_copytree(src, dst, dry)
494
659
def copy_file_to_jail(src, dry):
495
660
"""Copies a single file from an absolute location into the same location
530
697
# to the jails template directory (it will be used as a template
531
698
# for all the students' jails).
532
699
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
701
# Copy the subjects and problems directories across
702
action_copylist(install_list.list_subjects, subjects_base, dry,
704
action_copylist(install_list.list_problems, problems_base, dry,
707
# Append IVLE path to ivle.pth in python site packages
708
# (Unless it's already there)
709
ivle_pth = os.path.join(sys.prefix,
710
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
711
ivle_www = os.path.join(ivle_install_dir, "www")
712
write_ivle_pth = True
714
file = open(ivle_pth, 'r')
716
if line.strip() == ivle_www:
717
write_ivle_pth = False
719
except (IOError, OSError):
722
action_append(ivle_pth, ivle_www)
726
def updatejails(args):
727
# Get "dry" variable from command line
728
(opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
730
dry = '-n' in opts or '--dry' in opts
733
print "Dry run (no actions will be executed\n"
735
if not dry and os.geteuid() != 0:
736
print >>sys.stderr, "Must be root to run install"
737
print >>sys.stderr, "(I need to chown some files)."
740
# Update the template jail directory in case it hasn't been installed
742
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
744
# Re-link all the files in all students jails.
745
for dir in os.listdir(jail_base):
746
if dir == 'template': continue
747
# First back up the student's home directory
748
temp_home = os.tmpnam()
749
action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
750
# Delete the student's jail and relink the jail files
751
action_linktree(os.path.join(jail_base, 'template'),
752
os.path.join(jail_base, dir), dry)
753
# Restore the student's home directory
754
action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
755
# Set up the user's home directory just in case they don't have a
756
# directory for this yet
757
action_mkdir(os.path.join(jail_base, dir, 'home', dir), dry)