112
113
# Private mode (normal mode) requires login, and only serves files relevant to
113
114
# the logged-in user."""))
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.
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).""",
127
116
config_options.append(ConfigOption("database/host", "localhost",
128
117
"""PostgreSQL Database config
129
118
==========================
302
290
# Interactive mode. Prompt the user for all the values.
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.
292
print """This tool will create %s, prompting you for details about
293
your configuration. The file will be updated with modified options if it already
294
exists. If it does not already exist, it will be created with sane defaults and
295
restrictive permissions.
297
%s will also be overwritten with the default list of plugins.
311
299
Please hit Ctrl+C now if you do not wish to do this.
312
""" % (conffile, conf_hfile, phpBBconffile)
300
""" % (conffile, plugindefaultfile)
314
302
# Get information from the administrator
315
303
# If EOF is encountered at any time during the questioning, just exit
330
318
# 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'])
341
320
conf['database']['port'] = int(conf['database']['port'])
342
321
if (conf['database']['port'] < 0
343
322
or conf['database']['port'] >= 65536):
344
323
raise ValueError()
345
324
except ValueError:
346
print >>sys.stderr, (
347
"Invalid DB port (%s).\n"
348
"Must be an integer between 0 and 65535." %
349
repr(conf['database']['port']))
325
if conf['database']['port'] == '' or conf['database']['port'] is None:
328
print >>sys.stderr, (
329
"Invalid DB port (%s).\n"
330
"Must be an integer between 0 and 65535." %
331
repr(conf['database']['port']))
352
334
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
353
335
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
366
348
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
368
# Generate the forum secret
369
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
350
clobber_permissions = not os.path.exists(conffile)
371
352
# Write ./etc/ivle.conf (even if we loaded from a different filename)
372
353
conf.filename = conffile
374
354
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
357
# We need to restrict permissions on a new file, as it contains
358
# a nice database password.
359
if clobber_permissions:
360
os.chown(conffile, 33, 33) # chown to www-data
361
os.chmod(conffile, stat.S_IRUSR | stat.S_IWUSR) # No g/o perms!
382
363
print "Successfully wrote %s" % 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"
365
plugindefault = open(plugindefaultfile, 'w')
366
plugindefault.write("""# IVLE default plugin configuration file
367
[ivle.webapp.core#Plugin]
368
[ivle.webapp.admin.user#Plugin]
369
[ivle.webapp.tutorial#Plugin]
370
[ivle.webapp.admin.subject#Plugin]
371
[ivle.webapp.filesystem.browser#Plugin]
372
[ivle.webapp.filesystem.diff#Plugin]
373
[ivle.webapp.filesystem.svnlog#Plugin]
374
[ivle.webapp.filesystem.serve#Plugin]
375
[ivle.webapp.groups#Plugin]
376
[ivle.webapp.console#Plugin]
377
[ivle.webapp.security#Plugin]
378
[ivle.webapp.media#Plugin]
379
[ivle.webapp.help#Plugin]
380
[ivle.webapp.tos#Plugin]
381
[ivle.webapp.userservice#Plugin]
382
[ivle.webapp.fileservice#Plugin]
384
plugindefault.close()
385
print "Successfully wrote %s" % plugindefaultfile
388
print "You may modify the configuration at any time by editing " + conffile