75
74
# ('/usr/local' for the usual install, '/usr' for distribution packages)""",
77
config_options.append(ConfigOption("paths/site_packages",
79
"""site-packages directory in Python, where Python libraries are to be
80
installed. May be left as the default, in which case the value will be
81
computed from prefix and the current Python version:""",
83
# 'site-packages' directory in Python, where Python libraries are to be
84
# installed. May be omitted (recommended), in which case the value will be
85
# computed from prefix and the current Python version.""", ask=False))
78
87
config_options.append(ConfigOption("paths/data",
80
89
"In the local file system, where user-modifiable data files should be "
104
112
# Private mode (normal mode) requires login, and only serves files relevant to
105
113
# the logged-in user."""))
107
config_options.append(ConfigOption("media/version", None,
108
"""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.
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))
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).""",
114
127
config_options.append(ConfigOption("database/host", "localhost",
115
128
"""PostgreSQL Database config
204
221
# 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
223
def query_user(default, prompt):
223
224
"""Prompts the user for a string, which is read from a line of stdin.
224
225
Exits silently if EOF is encountered. Returns the string, with spaces
298
295
(opts, args) = getopt.gnu_getopt(args, "", optnames)
301
print >>sys.stderr, "Invalid arguments:", ' '.join(args)
298
print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
305
302
# 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.
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.
314
311
Please hit Ctrl+C now if you do not wish to do this.
315
""" % (conffile, plugindefaultfile)
312
""" % (conffile, conf_hfile, phpBBconffile)
317
314
# Get information from the administrator
318
315
# If EOF is encountered at any time during the questioning, just exit
333
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'])
335
341
conf['database']['port'] = int(conf['database']['port'])
336
342
if (conf['database']['port'] < 0
337
343
or conf['database']['port'] >= 65536):
338
344
raise ValueError()
339
345
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']))
346
print >>sys.stderr, (
347
"Invalid DB port (%s).\n"
348
"Must be an integer between 0 and 65535." %
349
repr(conf['database']['port']))
349
352
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
350
353
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
363
366
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
365
clobber_permissions = not os.path.exists(conffile)
368
# Generate the forum secret
369
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
367
371
# Write ./etc/ivle.conf (even if we loaded from a different filename)
368
372
conf.filename = conffile
369
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
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
382
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
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"