119
124
# Symlinks to make within the jail. Src mapped to dst.
121
'python2.5': 'jail/usr/bin/python',
126
'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
123
128
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
124
129
JAIL_COPYTREES = {
125
'/usr/lib/python2.5': 'jail/usr/lib/python2.5',
130
'/usr/lib/python%s' % PYTHON_VERSION:
131
'jail/usr/lib/python%s' % PYTHON_VERSION,
126
132
'/usr/share/matplotlib': 'jail/usr/share/matplotlib',
127
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 lib/conf/conf.py)""",
233
# Database password"""))
130
235
# Try importing existing conf, but if we can't just set up defaults
131
236
# The reason for this is that these settings are used by other phases
132
237
# of setup besides conf, so we need to know them.
133
238
# Also this allows you to hit Return to accept the existing value.
135
confmodule = __import__("www/conf/conf")
137
root_dir = confmodule.root_dir
141
ivle_install_dir = confmodule.ivle_install_dir
143
ivle_install_dir = "/opt/ivle"
145
jail_base = confmodule.jail_base
147
jail_base = "/home/informatics/jails"
240
confmodule = __import__("lib/conf/conf")
241
for opt in config_options:
243
globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
245
globals()[opt.option_name] = opt.default
148
246
except ImportError:
149
247
# Just set reasonable defaults
151
ivle_install_dir = "/opt/ivle"
152
jail_base = "/home/informatics/jails"
248
for opt in config_options:
249
globals()[opt.option_name] = opt.default
156
251
# Try importing install_list, but don't fail if we can't, because listmake can
157
252
# function without it.
409
529
# If EOF is encountered at any time during the questioning, just exit
412
root_dir = query_user(root_dir,
413
"""Root directory where IVLE is located (in URL space):""")
414
ivle_install_dir = query_user(ivle_install_dir,
415
'Root directory where IVLE will be installed (on the local file '
417
jail_base = query_user(jail_base,
418
"""Root directory where the jails (containing user files) are stored
419
(on the local file system):""")
420
allowed_uids = query_user(allowed_uids,
421
"""UID of the web server process which will run IVLE.
422
Only this user may execute the trampoline. May specify multiple users as
423
a comma-separated list.
532
for opt in config_options:
533
globals()[opt.option_name] = \
534
query_user(globals()[opt.option_name], opt.prompt)
427
536
opts = dict(opts)
428
537
# Non-interactive mode. Parse the options.
429
if '--root_dir' in opts:
430
root_dir = opts['--root_dir']
431
if '--ivle_install_dir' in opts:
432
ivle_install_dir = opts['--ivle_install_dir']
433
if '--jail_base' in opts:
434
jail_base = opts['--jail_base']
435
if '--allowed_uids' in opts:
436
allowed_uids = opts['--allowed_uids']
538
for opt in config_options:
539
if '--' + opt.option_name in opts:
540
globals()[opt.option_name] = opts['--' + opt.option_name]
438
542
# Error handling on input values
440
allowed_uids = map(int, allowed_uids.split(','))
544
allowed_uids_list = map(int, allowed_uids.split(','))
441
545
except ValueError:
442
546
print >>sys.stderr, (
443
547
"Invalid UID list (%s).\n"
444
548
"Must be a comma-separated list of integers." % allowed_uids)
551
db_port = int(db_port)
552
if db_port < 0 or db_port >= 65536: raise ValueError()
554
print >>sys.stderr, (
555
"Invalid DB port (%s).\n"
556
"Must be an integer between 0 and 65535." % repr(db_port))
447
# Write www/conf/conf.py
559
# Write lib/conf/conf.py
450
562
conf = open(conffile, "w")
589
694
# chown trampoline to root and set setuid bit
590
695
action_chown_setuid(tramppath, dry)
592
# Copy the www directory using the list
697
# Copy the www and lib directories using the list
593
698
action_copylist(install_list.list_www, ivle_install_dir, dry)
699
action_copylist(install_list.list_lib, ivle_install_dir, dry)
596
702
# Copy the local jail directory built by the build action
597
703
# to the jails template directory (it will be used as a template
598
704
# for all the students' jails).
599
705
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
707
# Copy the subjects and problems directories across
708
action_copylist(install_list.list_subjects, subjects_base, dry,
710
action_copylist(install_list.list_problems, problems_base, dry,
601
713
# Append IVLE path to ivle.pth in python site packages
602
714
# (Unless it's already there)
603
715
ivle_pth = os.path.join(sys.prefix,
604
"lib/python2.5/site-packages/ivle.pth")
716
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
605
717
ivle_www = os.path.join(ivle_install_dir, "www")
718
ivle_lib = os.path.join(ivle_install_dir, "lib")
606
719
write_ivle_pth = True
720
write_ivle_lib_pth = True
608
722
file = open(ivle_pth, 'r')
609
723
for line in file:
610
724
if line.strip() == ivle_www:
611
725
write_ivle_pth = False
726
elif line.strip() == ivle_lib:
727
write_ivle_lib_pth = False
613
729
except (IOError, OSError):
615
731
if write_ivle_pth:
616
732
action_append(ivle_pth, ivle_www)
733
if write_ivle_lib_pth:
734
action_append(ivle_pth, ivle_lib)