243
240
# the default values.
244
241
conf = ivle.config.Config(blank=True)
243
# Check that all the options are present, and if not, load the default
246
244
for opt in config_options:
248
conf_options[opt.option_name] = conf.get_by_path(opt.option_name)
246
conf.get_by_path(opt.option_name)
250
conf_options[opt.option_name] = opt.default
248
conf.set_by_path(opt.option_name, opt.default)
250
# Store comments in the conf object
251
for opt in config_options:
252
conf.set_by_path(opt.option_name, comment=opt.comment)
252
254
# Set up some variables
253
255
cwd = os.getcwd()
288
290
for opt in config_options:
290
conf_options[opt.option_name] = \
291
query_user(conf_options[opt.option_name], opt.prompt)
292
conf.set_by_path(opt.option_name,
293
query_user(conf.get_by_path(opt.option_name), opt.prompt))
293
295
opts = dict(opts)
294
296
# Non-interactive mode. Parse the options.
295
297
for opt in config_options:
296
298
if '--' + opt.option_name in opts:
297
conf_options[opt.option_name] = opts['--' + opt.option_name]
299
conf.set_by_path(opt.option_name,
300
opts['--' + opt.option_name])
299
302
# Error handling on input values
301
304
allowed_uids_list = map(int,
302
conf_options['os/allowed_uids'].split(','))
305
conf['os']['allowed_uids'].split(','))
303
306
except ValueError:
304
307
print >>sys.stderr, (
305
308
"Invalid UID list (%s).\n"
306
309
"Must be a comma-separated list of integers." %
307
conf_options['os/allowed_uids'])
310
conf['os']['allowed_uids'])
310
conf_options['database/port'] = int(conf_options['database/port'])
311
if (conf_options['database/port'] < 0
312
or conf_options['database/port'] >= 65536):
313
conf['database']['port'] = int(conf['database']['port'])
314
if (conf['database']['port'] < 0
315
or conf['database']['port'] >= 65536):
313
316
raise ValueError()
314
317
except ValueError:
315
318
print >>sys.stderr, (
316
319
"Invalid DB port (%s).\n"
317
320
"Must be an integer between 0 and 65535." %
318
repr(conf_options['database/port']))
321
repr(conf['database']['port']))
321
conf_options['usrmgt/port'] = int(conf_options['usrmgt/port'])
322
if (conf_options['usrmgt/port'] < 0
323
or conf_options['usrmgt/port'] >= 65536):
324
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
325
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
324
326
raise ValueError()
325
327
except ValueError:
326
328
print >>sys.stderr, (
327
329
"Invalid user management port (%s).\n"
328
330
"Must be an integer between 0 and 65535." %
329
repr(conf_options['usrmgt/port']))
331
repr(conf['usrmgt']['port']))
332
334
# By default we generate the magic randomly.
333
if conf_options['usrmgt/magic'] is None:
334
conf_options['usrmgt/magic'] = \
335
hashlib.md5(uuid.uuid4().bytes).hexdigest()
335
if conf['usrmgt']['magic'] is None:
336
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
337
338
# Generate the forum secret
338
339
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
345
346
# Add the forum secret to the config file (regenerated each config)
346
347
config_options.append(ConfigOption('plugins/forum/secret', None, '', ''))
347
conf_options['plugins/forum/secret'] = forum_secret
349
for opt in config_options:
350
value = conf_options[opt.option_name]
351
if value is not None:
352
conf.set_by_path(opt.option_name, value, opt.comment)
348
conf['plugins']['forum']['secret'] = forum_secret
362
358
# XXX Compute jail_base, jail_src_base and jail_system. These will
363
359
# ALSO be done by the boilerplate code, but we need them here in order
364
360
# to write to the C file.
365
jail_base = os.path.join(conf_options['paths/data'], 'jailmounts')
366
jail_src_base = os.path.join(conf_options['paths/data'], 'jails')
361
jail_base = os.path.join(conf['paths']['data'], 'jailmounts')
362
jail_src_base = os.path.join(conf['paths']['data'], 'jails')
367
363
jail_system = os.path.join(jail_src_base, '__base__')
369
365
conf_h.write("""/* IVLE Configuration File
403
399
conf_php = open(phpBBconffile, "w")
405
401
# php-pg work around
406
if conf_options['database/host'] == 'localhost':
402
if conf['database']['host'] == 'localhost':
407
403
forumdb_host = '127.0.0.1'
409
forumdb_host = conf_options['database/host']
405
forumdb_host = conf['database']['host']
411
407
conf_php.write( """<?php
412
408
// phpBB 3.0.x auto-generated configuration file
413
409
// Do not change anything in this file!
414
410
$dbms = 'postgres';
415
411
$dbhost = '""" + forumdb_host + """';
416
$dbport = '""" + str(conf_options['database/port']) + """';
417
$dbname = '""" + conf_options['plugins/forum/dbname'] + """';
418
$dbuser = '""" + conf_options['database/username'] + """';
419
$dbpasswd = '""" + conf_options['database/password'] + """';
412
$dbport = '""" + str(conf['database']['port']) + """';
413
$dbname = '""" + conf['plugins']['forum']['dbname'] + """';
414
$dbuser = '""" + conf['database']['username'] + """';
415
$dbpasswd = '""" + conf['database']['password'] + """';
421
417
$table_prefix = 'phpbb_';
422
418
$acm_type = 'file';