113
112
# Private mode (normal mode) requires login, and only serves files relevant to
114
113
# the logged-in user."""))
116
config_options.append(ConfigOption("media/version", None,
117
"""Version of IVLE media resources (must change on each upgrade):""",
115
config_options.append(ConfigOption("os/allowed_uids", "33",
116
"""UID of the web server process which will run IVLE.
117
Only this user may execute the trampoline. May specify multiple users as
118
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))
121
# The User-ID of the web server process which will run IVLE, and any other
122
# users who are allowed to run the trampoline. This is stores as a string of
123
# comma-separated integers, simply because it is not used within Python, only
124
# used by the setup program to write to conf.h (see setup.py config).""",
123
127
config_options.append(ConfigOption("database/host", "localhost",
124
128
"""PostgreSQL Database config
297
302
# Interactive mode. Prompt the user for all the values.
299
print """This tool will create %s, prompting you for details about
300
your configuration. The file will be updated with modified options if it already
301
exists. If it does not already exist, it will be created with sane defaults and
302
restrictive permissions.
304
%s will also be overwritten with the default list of plugins.
304
print """This tool will create the following files:
308
prompting you for details about your configuration. The file will be
309
overwritten if it already exists. It will *not* install or deploy IVLE.
306
311
Please hit Ctrl+C now if you do not wish to do this.
307
""" % (conffile, plugindefaultfile)
312
""" % (conffile, conf_hfile, phpBBconffile)
309
314
# Get information from the administrator
310
315
# If EOF is encountered at any time during the questioning, just exit
325
330
# Error handling on input values
332
allowed_uids_list = map(int,
333
conf['os']['allowed_uids'].split(','))
335
print >>sys.stderr, (
336
"Invalid UID list (%s).\n"
337
"Must be a comma-separated list of integers." %
338
conf['os']['allowed_uids'])
327
341
conf['database']['port'] = int(conf['database']['port'])
328
342
if (conf['database']['port'] < 0
329
343
or conf['database']['port'] >= 65536):
330
344
raise ValueError()
331
345
except ValueError:
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']))
346
print >>sys.stderr, (
347
"Invalid DB port (%s).\n"
348
"Must be an integer between 0 and 65535." %
349
repr(conf['database']['port']))
341
352
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
342
353
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
355
366
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
357
clobber_permissions = not os.path.exists(conffile)
368
# Generate the forum secret
369
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
359
371
# Write ./etc/ivle.conf (even if we loaded from a different filename)
360
372
conf.filename = conffile
361
374
conf.initial_comment = ["# IVLE Configuration File"]
376
# Add the forum secret to the config file (regenerated each config)
377
config_options.append(ConfigOption('plugins/forum/secret', None, '', ''))
378
conf['plugins']['forum']['secret'] = forum_secret
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!
370
382
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]
391
plugindefault.close()
392
print "Successfully wrote %s" % plugindefaultfile
395
print "You may modify the configuration at any time by editing " + conffile
384
# Write bin/trampoline/conf.h
386
conf_h = open(conf_hfile, "w")
388
# XXX Compute jail_base, jail_src_base and jail_system. These will
389
# ALSO be done by the boilerplate code, but we need them here in order
390
# to write to the C file.
391
jail_base = os.path.join(conf['paths']['data'], 'jailmounts')
392
jail_src_base = os.path.join(conf['paths']['data'], 'jails')
393
jail_system = os.path.join(jail_src_base, '__base__')
395
conf_h.write("""/* IVLE Configuration File
397
* Administrator settings required by trampoline.
398
* Note: trampoline will have to be rebuilt in order for changes to this file
402
#define IVLE_AUFS_JAILS
404
/* In the local file system, where are the jails located.
405
* The trampoline does not allow the creation of a jail anywhere besides
406
* jail_base or a subdirectory of jail_base.
408
static const char* jail_base = "%s";
409
static const char* jail_src_base = "%s";
410
static const char* jail_system = "%s";
412
/* Which user IDs are allowed to run the trampoline.
413
* This list should be limited to the web server user.
414
* (Note that root is an implicit member of this list).
416
static const int allowed_uids[] = { %s };
417
""" % (repr(jail_base)[1:-1], repr(jail_src_base)[1:-1],
418
repr(jail_system)[1:-1], repr(allowed_uids_list)[1:-1]))
419
# Note: The above uses PYTHON reprs, not C reprs
420
# However they should be the same with the exception of the outer
421
# characters, which are stripped off and replaced
425
print "Successfully wrote %s" % conf_hfile
427
# Write www/php/phpBB3/config.php
429
conf_php = open(phpBBconffile, "w")
432
if conf['database']['host'] == 'localhost':
433
forumdb_host = '127.0.0.1'
435
forumdb_host = conf['database']['host']
437
conf_php.write( """<?php
438
// phpBB 3.0.x auto-generated configuration file
439
// Do not change anything in this file!
441
$dbhost = '""" + forumdb_host + """';
442
$dbport = '""" + str(conf['database']['port']) + """';
443
$dbname = '""" + conf['plugins']['forum']['dbname'] + """';
444
$dbuser = '""" + conf['database']['username'] + """';
445
$dbpasswd = '""" + conf['database']['password'] + """';
447
$table_prefix = 'phpbb_';
449
$load_extensions = '';
450
@define('PHPBB_INSTALLED', true);
451
// @define('DEBUG', true);
452
//@define('DEBUG_EXTRA', true);
454
$forum_secret = '""" + forum_secret +"""';
459
print "Successfully wrote %s" % phpBBconffile
462
print "You may modify the configuration at any time by editing"