104
114
# Private mode (normal mode) requires login, and only serves files relevant to
105
115
# the logged-in user."""))
107
config_options.append(ConfigOption("media/version", None,
108
"""Version of IVLE media resources (must change on each upgrade):""",
117
config_options.append(ConfigOption("os/allowed_uids", "33",
118
"""UID of the web server process which will run IVLE.
119
Only this user may execute the trampoline. May specify multiple users as
120
a comma-separated list.
110
# Version string for IVLE media resource URLs. When set, they are aggressively
111
# cached by the browser, so it must be either left unset or changed each time
112
# a media file is changed.""", ask=False))
123
# The User-ID of the web server process which will run IVLE, and any other
124
# users who are allowed to run the trampoline. This is stores as a string of
125
# comma-separated integers, simply because it is not used within Python, only
126
# used by the setup program to write to conf.h (see setup.py config).""",
114
129
config_options.append(ConfigOption("database/host", "localhost",
115
130
"""PostgreSQL Database config
204
223
# The password for the usrmgt-server.""", ask=False))
206
config_options.append(ConfigOption("jail/suite", "hardy",
207
"""The distribution release to use to build the jail:""",
209
# The distribution release to use to build the jail.""", ask=True))
211
config_options.append(ConfigOption("jail/mirror", "archive.ubuntu.com",
212
"""The archive mirror to use to build the jail:""",
214
# The archive mirror to use to build the jail.""", ask=True))
216
config_options.append(ConfigOption("jail/devmode", False,
217
"""Whether jail development mode be activated:""",
219
# Should jail development mode be activated?""", ask=False))
221
# The password for the usrmgt-server.""", ask=False))
222
def query_user(default, prompt):
223
"""Prompts the user for a string, which is read from a line of stdin.
224
Exits silently if EOF is encountered. Returns the string, with spaces
225
removed from the beginning and end.
227
Returns default if a 0-length line (after spaces removed) was read.
230
# A default of None means the value will be computed specially, so we
231
# can't really tell you what it is
232
defaultstr = "computed"
233
elif isinstance(default, basestring):
234
defaultstr = '"%s"' % default
236
defaultstr = repr(default)
237
sys.stdout.write('%s\n (default: %s)\n>' % (prompt, defaultstr))
239
val = sys.stdin.readline()
240
except KeyboardInterrupt:
242
sys.stdout.write("\n")
244
sys.stdout.write("\n")
246
if val == '': sys.exit(1)
247
# If empty line, return default
249
if val == '': return default
252
225
def configure(args):
226
# Call the real function
227
return __configure(args)
229
def __configure(args):
253
230
# Try importing existing conf, but if we can't just set up defaults
254
231
# The reason for this is that these settings are used by other phases
255
232
# of setup besides conf, so we need to know them.
269
246
conf.get_by_path(opt.option_name)
271
# If the default is None, omit it
272
# Else ConfigObj will write the string 'None' to the conf file
273
if opt.default is not None:
274
conf.set_by_path(opt.option_name, opt.default)
248
conf.set_by_path(opt.option_name, opt.default)
276
250
# Store comments in the conf object
277
251
for opt in config_options:
278
# Omitted if the key doesn't exist
279
252
conf.set_by_path(opt.option_name, comment=opt.comment)
281
254
# Set up some variables
282
255
cwd = os.getcwd()
284
257
# the files that will be created/overwritten
286
confdir = os.environ['IVLECONF']
288
confdir = '/etc/ivle'
290
conffile = os.path.join(confdir, 'ivle.conf')
291
plugindefaultfile = os.path.join(confdir, 'plugins.d/000default.conf')
258
conffile = os.path.join(cwd, "etc/ivle.conf")
259
conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h")
260
phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
293
262
# Get command-line arguments to avoid asking questions.
298
267
(opts, args) = getopt.gnu_getopt(args, "", optnames)
301
print >>sys.stderr, "Invalid arguments:", ' '.join(args)
270
print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
305
274
# Interactive mode. Prompt the user for all the values.
307
print """This tool will create %s, prompting you for details about
308
your configuration. The file will be updated with modified options if it already
309
exists. If it does not already exist, it will be created with sane defaults and
310
restrictive permissions.
312
%s will also be overwritten with the default list of plugins.
276
print """This tool will create the following files:
280
prompting you for details about your configuration. The file will be
281
overwritten if it already exists. It will *not* install or deploy IVLE.
314
283
Please hit Ctrl+C now if you do not wish to do this.
315
""" % (conffile, plugindefaultfile)
284
""" % (conffile, conf_hfile, phpBBconffile)
317
286
# Get information from the administrator
318
287
# If EOF is encountered at any time during the questioning, just exit
333
302
# Error handling on input values
304
allowed_uids_list = map(int,
305
conf['os']['allowed_uids'].split(','))
307
print >>sys.stderr, (
308
"Invalid UID list (%s).\n"
309
"Must be a comma-separated list of integers." %
310
conf['os']['allowed_uids'])
335
313
conf['database']['port'] = int(conf['database']['port'])
336
314
if (conf['database']['port'] < 0
337
315
or conf['database']['port'] >= 65536):
338
316
raise ValueError()
339
317
except ValueError:
340
if conf['database']['port'] == '' or conf['database']['port'] is None:
343
print >>sys.stderr, (
344
"Invalid DB port (%s).\n"
345
"Must be an integer between 0 and 65535." %
346
repr(conf['database']['port']))
318
print >>sys.stderr, (
319
"Invalid DB port (%s).\n"
320
"Must be an integer between 0 and 65535." %
321
repr(conf['database']['port']))
349
324
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
350
325
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
359
334
# By default we generate the magic randomly.
361
conf['usrmgt']['magic'] # Throw away; just check for KeyError
335
if conf['usrmgt']['magic'] is None:
363
336
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
365
clobber_permissions = not os.path.exists(conffile)
338
# Generate the forum secret
339
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
367
341
# Write ./etc/ivle.conf (even if we loaded from a different filename)
368
342
conf.filename = conffile
369
344
conf.initial_comment = ["# IVLE Configuration File"]
346
# Add the forum secret to the config file (regenerated each config)
347
config_options.append(ConfigOption('plugins/forum/secret', None, '', ''))
348
conf['plugins']['forum']['secret'] = forum_secret
372
# We need to restrict permissions on a new file, as it contains
373
# a nice database password.
374
if clobber_permissions:
375
os.chown(conffile, 33, 33) # chown to www-data
376
os.chmod(conffile, stat.S_IRUSR | stat.S_IWUSR) # No g/o perms!
378
352
print "Successfully wrote %s" % conffile
380
plugindefault = open(plugindefaultfile, 'w')
381
plugindefault.write("""# IVLE default plugin configuration file
382
[ivle.webapp.core#Plugin]
383
[ivle.webapp.admin.user#Plugin]
384
[ivle.webapp.tutorial#Plugin]
385
[ivle.webapp.admin.subject#Plugin]
386
[ivle.webapp.filesystem.browser#Plugin]
387
[ivle.webapp.filesystem.diff#Plugin]
388
[ivle.webapp.filesystem.svnlog#Plugin]
389
[ivle.webapp.filesystem.serve#Plugin]
390
[ivle.webapp.groups#Plugin]
391
[ivle.webapp.console#Plugin]
392
[ivle.webapp.security#Plugin]
393
[ivle.webapp.media#Plugin]
394
[ivle.webapp.help#Plugin]
395
[ivle.webapp.tos#Plugin]
396
[ivle.webapp.userservice#Plugin]
397
[ivle.webapp.fileservice#Plugin]
398
[ivle.webapp.submit#Plugin]
400
plugindefault.close()
401
print "Successfully wrote %s" % plugindefaultfile
404
print "You may modify the configuration at any time by editing " + conffile
354
# Write bin/trampoline/conf.h
356
conf_h = open(conf_hfile, "w")
358
# XXX Compute jail_base, jail_src_base and jail_system. These will
359
# ALSO be done by the boilerplate code, but we need them here in order
360
# to write to the C file.
361
jail_base = os.path.join(conf['paths']['data'], 'jailmounts')
362
jail_src_base = os.path.join(conf['paths']['data'], 'jails')
363
jail_system = os.path.join(jail_src_base, '__base__')
365
conf_h.write("""/* IVLE Configuration File
367
* Administrator settings required by trampoline.
368
* Note: trampoline will have to be rebuilt in order for changes to this file
372
#define IVLE_AUFS_JAILS
374
/* In the local file system, where are the jails located.
375
* The trampoline does not allow the creation of a jail anywhere besides
376
* jail_base or a subdirectory of jail_base.
378
static const char* jail_base = "%s";
379
static const char* jail_src_base = "%s";
380
static const char* jail_system = "%s";
382
/* Which user IDs are allowed to run the trampoline.
383
* This list should be limited to the web server user.
384
* (Note that root is an implicit member of this list).
386
static const int allowed_uids[] = { %s };
387
""" % (repr(jail_base)[1:-1], repr(jail_src_base)[1:-1],
388
repr(jail_system)[1:-1], repr(allowed_uids_list)[1:-1]))
389
# Note: The above uses PYTHON reprs, not C reprs
390
# However they should be the same with the exception of the outer
391
# characters, which are stripped off and replaced
395
print "Successfully wrote %s" % conf_hfile
397
# Write www/php/phpBB3/config.php
399
conf_php = open(phpBBconffile, "w")
402
if conf['database']['host'] == 'localhost':
403
forumdb_host = '127.0.0.1'
405
forumdb_host = conf['database']['host']
407
conf_php.write( """<?php
408
// phpBB 3.0.x auto-generated configuration file
409
// Do not change anything in this file!
411
$dbhost = '""" + forumdb_host + """';
412
$dbport = '""" + str(conf['database']['port']) + """';
413
$dbname = '""" + conf['plugins']['forum']['dbname'] + """';
414
$dbuser = '""" + conf['database']['username'] + """';
415
$dbpasswd = '""" + conf['database']['password'] + """';
417
$table_prefix = 'phpbb_';
419
$load_extensions = '';
420
@define('PHPBB_INSTALLED', true);
421
// @define('DEBUG', true);
422
//@define('DEBUG_EXTRA', true);
424
$forum_secret = '""" + forum_secret +"""';
429
print "Successfully wrote %s" % phpBBconffile
432
print "You may modify the configuration at any time by editing"
412
# Print the opening spiel including the GPL notice
414
print """IVLE - Informatics Virtual Learning Environment Setup
415
Copyright (C) 2007-2009 The University of Melbourne
416
IVLE comes with ABSOLUTELY NO WARRANTY.
417
This is free software, and you are welcome to redistribute it
418
under certain conditions. See LICENSE.txt for details.
423
return configure(argv[1:])
425
if __name__ == "__main__":