113
111
# Private mode (normal mode) requires login, and only serves files relevant to
114
112
# the logged-in user."""))
116
config_options.append(ConfigOption("media/version", None,
117
"""Version of IVLE media resources (must change on each upgrade):""",
114
config_options.append(ConfigOption("allowed_uids", "33",
115
"""UID of the web server process which will run IVLE.
116
Only this user may execute the trampoline. May specify multiple users as
117
a comma-separated list.
119
# Version string for IVLE media resource URLs. When set, they are aggressively
120
# cached by the browser, so it must be either left unset or changed each time
121
# a media file is changed.""", ask=False))
120
# The User-ID of the web server process which will run IVLE, and any other
121
# users who are allowed to run the trampoline. This is stores as a string of
122
# comma-separated integers, simply because it is not used within Python, only
123
# used by the setup program to write to conf.h (see setup.py config).""",
123
config_options.append(ConfigOption("database/host", "localhost",
126
config_options.append(ConfigOption("db_host", "localhost",
124
127
"""PostgreSQL Database config
125
128
==========================
126
129
Hostname of the DB server:""",
131
### PostgreSQL Database config ###
128
132
# Database server hostname"""))
130
config_options.append(ConfigOption("database/port", "5432",
134
config_options.append(ConfigOption("db_port", "5432",
131
135
"""Port of the DB server:""",
133
137
# Database server port"""))
135
config_options.append(ConfigOption("database/name", "ivle",
139
config_options.append(ConfigOption("db_dbname", "ivle",
136
140
"""Database name:""",
138
142
# Database name"""))
140
config_options.append(ConfigOption("database/username", "postgres",
144
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
145
"""Forum Database name:""",
147
# Forum Database name"""))
149
config_options.append(ConfigOption("db_user", "postgres",
141
150
"""Username for DB server login:""",
143
152
# Database username"""))
145
config_options.append(ConfigOption("database/password", "",
154
config_options.append(ConfigOption("db_password", "",
146
155
"""Password for DB server login:
147
(Caution: This password is stored in plaintext!)""",
156
(Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
149
158
# Database password"""))
151
config_options.append(ConfigOption("auth/modules", "",
160
config_options.append(ConfigOption("auth_modules", "",
152
161
"""Authentication config
153
162
=====================
154
163
Comma-separated list of authentication modules.""",
187
196
# other modules may be plugged in to pulldown against organisation-specific
188
197
# pulldown backends.""", ask=False))
190
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/",
199
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
191
200
"""Subversion config
192
201
=================
193
202
The base url for accessing subversion repositories:""",
195
204
# The base url for accessing subversion repositories."""))
197
config_options.append(ConfigOption("usrmgt/host", "localhost",
206
config_options.append(ConfigOption("usrmgt_host", "localhost",
198
207
"""User Management Server config
199
208
============================
200
209
The hostname where the usrmgt-server runs:""",
202
211
# The hostname where the usrmgt-server runs."""))
204
config_options.append(ConfigOption("usrmgt/port", "2178",
213
config_options.append(ConfigOption("usrmgt_port", "2178",
205
214
"""The port where the usrmgt-server runs:""",
207
216
# The port where the usrmgt-server runs.""", ask=False))
209
config_options.append(ConfigOption("usrmgt/magic", None,
218
config_options.append(ConfigOption("usrmgt_magic", None,
210
219
"""The password for the usrmgt-server:""",
212
221
# The password for the usrmgt-server.""", ask=False))
214
def query_user(default, prompt):
215
"""Prompts the user for a string, which is read from a line of stdin.
216
Exits silently if EOF is encountered. Returns the string, with spaces
217
removed from the beginning and end.
219
Returns default if a 0-length line (after spaces removed) was read.
222
# A default of None means the value will be computed specially, so we
223
# can't really tell you what it is
224
defaultstr = "computed"
225
elif isinstance(default, basestring):
226
defaultstr = '"%s"' % default
228
defaultstr = repr(default)
229
sys.stdout.write('%s\n (default: %s)\n>' % (prompt, defaultstr))
231
val = sys.stdin.readline()
232
except KeyboardInterrupt:
234
sys.stdout.write("\n")
236
sys.stdout.write("\n")
238
if val == '': sys.exit(1)
239
# If empty line, return default
241
if val == '': return default
244
223
def configure(args):
224
# Call the real function
225
return __configure(args)
227
def __configure(args):
228
global db_port, usrmgt_port
245
230
# Try importing existing conf, but if we can't just set up defaults
246
231
# The reason for this is that these settings are used by other phases
247
232
# of setup besides conf, so we need to know them.
248
233
# Also this allows you to hit Return to accept the existing value.
250
conf = ivle.config.Config()
251
except ivle.config.ConfigError:
252
# Couldn't find a config file anywhere.
253
# Create a new blank config object (not yet bound to a file)
254
# All lookups (below) will fail, so it will be initialised with all
255
# the default values.
256
conf = ivle.config.Config(blank=True)
258
# Check that all the options are present, and if not, load the default
259
for opt in config_options:
261
conf.get_by_path(opt.option_name)
263
# If the default is None, omit it
264
# Else ConfigObj will write the string 'None' to the conf file
265
if opt.default is not None:
266
conf.set_by_path(opt.option_name, opt.default)
268
# Store comments in the conf object
269
for opt in config_options:
270
# Omitted if the key doesn't exist
271
conf.set_by_path(opt.option_name, comment=opt.comment)
235
confmodule = __import__("ivle/conf/conf")
236
for opt in config_options:
238
globals()[opt.option_name] = \
239
confmodule.__dict__[opt.option_name]
241
globals()[opt.option_name] = opt.default
243
# Just set reasonable defaults
244
for opt in config_options:
245
globals()[opt.option_name] = opt.default
273
247
# Set up some variables
274
248
cwd = os.getcwd()
276
250
# the files that will be created/overwritten
278
confdir = os.environ['IVLECONF']
280
confdir = '/etc/ivle'
282
conffile = os.path.join(confdir, 'ivle.conf')
283
plugindefaultfile = os.path.join(confdir, 'plugins.d/000default.conf')
251
conffile = os.path.join(cwd, "ivle/conf/conf.py")
252
conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h")
253
phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
285
255
# Get command-line arguments to avoid asking questions.
313
283
for opt in config_options:
315
conf.set_by_path(opt.option_name,
316
query_user(conf.get_by_path(opt.option_name), opt.prompt))
285
globals()[opt.option_name] = \
286
query_user(globals()[opt.option_name], opt.prompt)
318
288
opts = dict(opts)
319
289
# Non-interactive mode. Parse the options.
320
290
for opt in config_options:
321
291
if '--' + opt.option_name in opts:
322
conf.set_by_path(opt.option_name,
323
opts['--' + opt.option_name])
292
globals()[opt.option_name] = opts['--' + opt.option_name]
325
294
# Error handling on input values
327
conf['database']['port'] = int(conf['database']['port'])
328
if (conf['database']['port'] < 0
329
or conf['database']['port'] >= 65536):
332
if conf['database']['port'] == '' or conf['database']['port'] is None:
335
print >>sys.stderr, (
336
"Invalid DB port (%s).\n"
337
"Must be an integer between 0 and 65535." %
338
repr(conf['database']['port']))
341
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
342
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
296
allowed_uids_list = map(int, allowed_uids.split(','))
298
print >>sys.stderr, (
299
"Invalid UID list (%s).\n"
300
"Must be a comma-separated list of integers." % allowed_uids)
303
db_port = int(db_port)
304
if db_port < 0 or db_port >= 65536: raise ValueError()
306
print >>sys.stderr, (
307
"Invalid DB port (%s).\n"
308
"Must be an integer between 0 and 65535." % repr(db_port))
311
usrmgt_port = int(usrmgt_port)
312
if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
344
313
except ValueError:
345
314
print >>sys.stderr, (
346
315
"Invalid user management port (%s).\n"
347
"Must be an integer between 0 and 65535." %
348
repr(conf['usrmgt']['port']))
316
"Must be an integer between 0 and 65535." % repr(usrmgt_port))
351
319
# By default we generate the magic randomly.
320
if globals()['usrmgt_magic'] is None:
321
globals()['usrmgt_magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
323
# Generate the forum secret
324
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
326
# Write lib/conf/conf.py
353
conf['usrmgt']['magic'] # Throw away; just check for KeyError
355
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
357
clobber_permissions = not os.path.exists(conffile)
359
# Write ./etc/ivle.conf (even if we loaded from a different filename)
360
conf.filename = conffile
361
conf.initial_comment = ["# IVLE Configuration File"]
364
# We need to restrict permissions on a new file, as it contains
365
# a nice database password.
366
if clobber_permissions:
367
os.chown(conffile, 33, 33) # chown to www-data
368
os.chmod(conffile, stat.S_IRUSR | stat.S_IWUSR) # No g/o perms!
329
conf = open(conffile, "w")
331
conf.write("""# IVLE Configuration File
333
# Miscellaneous application settings
338
for opt in config_options:
339
conf.write('%s\n%s = %r\n' % (opt.comment, opt.option_name,
340
globals()[opt.option_name]))
342
# Add the forum secret to the config file (regenerated each config)
343
conf.write('forum_secret = "%s"\n\n' % (forum_secret))
345
write_conf_file_boilerplate(conf)
348
except IOError, (errno, strerror):
349
print "IO error(%s): %s" % (errno, strerror)
370
352
print "Successfully wrote %s" % conffile
372
plugindefault = open(plugindefaultfile, 'w')
373
plugindefault.write("""# IVLE default plugin configuration file
374
[ivle.webapp.core#Plugin]
375
[ivle.webapp.admin.user#Plugin]
376
[ivle.webapp.tutorial#Plugin]
377
[ivle.webapp.admin.subject#Plugin]
378
[ivle.webapp.filesystem.browser#Plugin]
379
[ivle.webapp.filesystem.diff#Plugin]
380
[ivle.webapp.filesystem.svnlog#Plugin]
381
[ivle.webapp.filesystem.serve#Plugin]
382
[ivle.webapp.groups#Plugin]
383
[ivle.webapp.console#Plugin]
384
[ivle.webapp.security#Plugin]
385
[ivle.webapp.media#Plugin]
386
[ivle.webapp.help#Plugin]
387
[ivle.webapp.tos#Plugin]
388
[ivle.webapp.userservice#Plugin]
389
[ivle.webapp.fileservice#Plugin]
390
[ivle.webapp.submit#Plugin]
392
plugindefault.close()
393
print "Successfully wrote %s" % plugindefaultfile
396
print "You may modify the configuration at any time by editing " + conffile
354
# Write bin/trampoline/conf.h
357
conf = open(conf_hfile, "w")
359
# XXX Compute jail_base, jail_src_base and jail_system. These will
360
# ALSO be done by the boilerplate code, but we need them here in order
361
# to write to the C file.
362
jail_base = os.path.join(data_path, 'jailmounts')
363
jail_src_base = os.path.join(data_path, 'jails')
364
jail_system = os.path.join(jail_src_base, '__base__')
366
conf.write("""/* IVLE Configuration File
368
* Administrator settings required by trampoline.
369
* Note: trampoline will have to be rebuilt in order for changes to this file
373
#define IVLE_AUFS_JAILS
375
/* In the local file system, where are the jails located.
376
* The trampoline does not allow the creation of a jail anywhere besides
377
* jail_base or a subdirectory of jail_base.
379
static const char* jail_base = "%s";
380
static const char* jail_src_base = "%s";
381
static const char* jail_system = "%s";
383
/* Which user IDs are allowed to run the trampoline.
384
* This list should be limited to the web server user.
385
* (Note that root is an implicit member of this list).
387
static const int allowed_uids[] = { %s };
388
""" % (repr(jail_base)[1:-1], repr(jail_src_base)[1:-1],
389
repr(jail_system)[1:-1], repr(allowed_uids_list)[1:-1]))
390
# Note: The above uses PYTHON reprs, not C reprs
391
# However they should be the same with the exception of the outer
392
# characters, which are stripped off and replaced
395
except IOError, (errno, strerror):
396
print "IO error(%s): %s" % (errno, strerror)
399
print "Successfully wrote %s" % conf_hfile
401
# Write www/php/phpBB3/config.php
404
conf = open(phpBBconffile, "w")
407
if db_host == 'localhost':
408
forumdb_host = '127.0.0.1'
410
forumdb_host = db_host
413
// phpBB 3.0.x auto-generated configuration file
414
// Do not change anything in this file!
416
$dbhost = '""" + forumdb_host + """';
417
$dbport = '""" + str(db_port) + """';
418
$dbname = '""" + db_forumdbname + """';
419
$dbuser = '""" + db_user + """';
420
$dbpasswd = '""" + db_password + """';
422
$table_prefix = 'phpbb_';
424
$load_extensions = '';
425
@define('PHPBB_INSTALLED', true);
426
// @define('DEBUG', true);
427
//@define('DEBUG_EXTRA', true);
429
$forum_secret = '""" + forum_secret +"""';
433
except IOError, (errno, strerror):
434
print "IO error(%s): %s" % (errno, strerror)
437
print "Successfully wrote %s" % phpBBconffile
440
print "You may modify the configuration at any time by editing"
404
# Print the opening spiel including the GPL notice
406
print """IVLE - Informatics Virtual Learning Environment Setup
407
Copyright (C) 2007-2009 The University of Melbourne
408
IVLE comes with ABSOLUTELY NO WARRANTY.
409
This is free software, and you are welcome to redistribute it
410
under certain conditions. See LICENSE.txt for details.
415
return configure(argv[1:])
417
if __name__ == "__main__":
448
def write_conf_file_boilerplate(conf_file):
450
### Below is boilerplate code, appended by ./setup.py config ###
452
# Path where architecture-dependent data (including non-user-executable
453
# binaries) is installed.
454
lib_path = os.path.join(prefix, 'lib/ivle')
456
# Path where arch-independent data is installed.
457
share_path = os.path.join(prefix, 'share/ivle')
459
# Path where user-executable binaries are installed.
460
bin_path = os.path.join(prefix, 'bin')
462
# 'site-packages' directory in Python, where Python libraries are to be
464
if python_site_packages_override is None:
465
PYTHON_VERSION = sys.version[0:3] # eg. "2.5"
466
python_site_packages = os.path.join(prefix,
467
'lib/python%s/site-packages' % PYTHON_VERSION)
469
python_site_packages = python_site_packages_override
471
# In the local file system, where the student/user jails will be mounted.
472
# Only a single copy of the jail's system components will be stored here -
473
# all user jails will be virtually mounted here.
474
jail_base = os.path.join(data_path, 'jailmounts')
476
# In the local file system, where are the student/user file spaces located.
477
# The user jails are expected to be located immediately in subdirectories of
478
# this location. Note that no complete jails reside here - only user
480
jail_src_base = os.path.join(data_path, 'jails')
482
# In the local file system, where the template system jail will be stored.
483
jail_system = os.path.join(jail_src_base, '__base__')
485
# In the local file system, where the template system jail will be stored.
486
jail_system_build = os.path.join(jail_src_base, '__base_build__')
488
# In the local file system, where the subject content files are located.
489
# (The 'subjects' and 'exercises' directories).
490
content_path = os.path.join(data_path, 'content')
492
# In the local file system, where are the per-subject file spaces located.
493
# The individual subject directories are expected to be located immediately
494
# in subdirectories of this location.
495
subjects_base = os.path.join(content_path, 'subjects')
497
# In the local file system, where are the subject-independent exercise sheet
498
# file spaces located.
499
exercises_base = os.path.join(content_path, 'exercises')
501
# In the local file system, where the system notices are stored (such as terms
502
# of service and MOTD).
503
notices_path = os.path.join(data_path, 'notices')
505
# In the local file system, where is the Terms of Service document located.
506
tos_path = os.path.join(notices_path, 'tos.html')
508
# In the local file system, where is the Message of the Day document
509
# located. This is an HTML file (just the body fragment), which will
510
# be displayed on the login page. It is optional.
511
motd_path = os.path.join(notices_path, 'motd.html')
513
# The location of all the subversion config and repositories.
514
svn_path = os.path.join(data_path, 'svn')
516
# The location of the subversion configuration file used by
517
# apache to host the user repositories.
518
svn_conf = os.path.join(svn_path, 'svn.conf')
520
# The location of the subversion configuration file used by
521
# apache to host the user repositories.
522
svn_group_conf = os.path.join(svn_path, 'svn-group.conf')
524
# The root directory for the subversion repositories.
525
svn_repo_path = os.path.join(svn_path, 'repositories')
527
# The location of the password file used to authenticate users
528
# of the subversion repository from the ivle server.
529
svn_auth_ivle = os.path.join(svn_path, 'ivle.auth')