~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to setup/ivle-config

Remove the setup.configure import from setup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
Either prompts the administrator for these details or accepts them as
23
23
command-line args.
24
24
 
25
 
Creates etc/ivle.conf
 
25
Creates ivle/conf/conf.py and bin/trampoline/trampoline/conf.h.
26
26
'''
27
27
 
28
28
import optparse
29
29
import getopt
30
30
import os
31
31
import sys
32
 
import stat
33
32
import hashlib
34
33
import uuid
35
34
 
113
112
# Private mode (normal mode) requires login, and only serves files relevant to
114
113
# the logged-in user."""))
115
114
 
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
    (eg. "1002,78")""",
118
120
    """
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).""",
 
125
    ask=False))
122
126
 
123
127
config_options.append(ConfigOption("database/host", "localhost",
124
128
    """PostgreSQL Database config
137
141
    """
138
142
# Database name"""))
139
143
 
 
144
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum",
 
145
    """Forum Database name:""",
 
146
    """
 
147
# Forum Database name"""))
 
148
 
140
149
config_options.append(ConfigOption("database/username", "postgres",
141
150
    """Username for DB server login:""",
142
151
    """
144
153
 
145
154
config_options.append(ConfigOption("database/password", "",
146
155
    """Password for DB server login:
147
 
    (Caution: This password is stored in plaintext!)""",
 
156
    (Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
148
157
    """
149
158
# Database password"""))
150
159
 
274
283
    cwd = os.getcwd()
275
284
 
276
285
    # the files that will be created/overwritten
277
 
    try:
278
 
        confdir = os.environ['IVLECONF']
279
 
    except KeyError:
280
 
        confdir = '/etc/ivle'
281
 
 
282
 
    conffile = os.path.join(confdir, 'ivle.conf')
283
 
    plugindefaultfile = os.path.join(confdir, 'plugins.d/000default.conf')
 
286
    conffile = os.path.join(cwd, "etc/ivle.conf")
 
287
    conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h")
 
288
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
284
289
 
285
290
    # Get command-line arguments to avoid asking questions.
286
291
 
296
301
    if opts == []:
297
302
        # Interactive mode. Prompt the user for all the values.
298
303
 
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.
303
 
 
304
 
%s will also be overwritten with the default list of plugins.
 
304
        print """This tool will create the following files:
 
305
    %s
 
306
    %s
 
307
    %s
 
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.
305
310
 
306
311
Please hit Ctrl+C now if you do not wish to do this.
307
 
""" % (conffile, plugindefaultfile)
 
312
""" % (conffile, conf_hfile, phpBBconffile)
308
313
 
309
314
        # Get information from the administrator
310
315
        # If EOF is encountered at any time during the questioning, just exit
324
329
 
325
330
    # Error handling on input values
326
331
    try:
 
332
        allowed_uids_list = map(int,
 
333
                                conf['os']['allowed_uids'].split(','))
 
334
    except ValueError:
 
335
        print >>sys.stderr, (
 
336
        "Invalid UID list (%s).\n"
 
337
        "Must be a comma-separated list of integers." %
 
338
            conf['os']['allowed_uids'])
 
339
        return 1
 
340
    try:
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:
333
 
            pass
334
 
        else:
335
 
            print >>sys.stderr, (
336
 
            "Invalid DB port (%s).\n"
337
 
            "Must be an integer between 0 and 65535." %
338
 
                repr(conf['database']['port']))
339
 
            return 1
 
346
        print >>sys.stderr, (
 
347
        "Invalid DB port (%s).\n"
 
348
        "Must be an integer between 0 and 65535." %
 
349
            repr(conf['database']['port']))
 
350
        return 1
340
351
    try:
341
352
        conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
342
353
        if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
354
365
    except KeyError:
355
366
        conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
356
367
 
357
 
    clobber_permissions = not os.path.exists(conffile)
 
368
    # Generate the forum secret
 
369
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
358
370
 
359
371
    # Write ./etc/ivle.conf (even if we loaded from a different filename)
360
372
    conf.filename = conffile
 
373
 
361
374
    conf.initial_comment = ["# IVLE Configuration File"]
 
375
 
 
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
 
379
 
362
380
    conf.write()
363
381
 
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!
369
 
 
370
382
    print "Successfully wrote %s" % conffile
371
383
 
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]
390
 
""")
391
 
    plugindefault.close()
392
 
    print "Successfully wrote %s" % plugindefaultfile
393
 
 
394
 
    print
395
 
    print "You may modify the configuration at any time by editing " + conffile
 
384
    # Write bin/trampoline/conf.h
 
385
 
 
386
    conf_h = open(conf_hfile, "w")
 
387
 
 
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__')
 
394
 
 
395
    conf_h.write("""/* IVLE Configuration File
 
396
 * conf.h
 
397
 * Administrator settings required by trampoline.
 
398
 * Note: trampoline will have to be rebuilt in order for changes to this file
 
399
 * to take effect.
 
400
 */
 
401
 
 
402
#define IVLE_AUFS_JAILS
 
403
 
 
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.
 
407
 */
 
408
static const char* jail_base = "%s";
 
409
static const char* jail_src_base = "%s";
 
410
static const char* jail_system = "%s";
 
411
 
 
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).
 
415
 */
 
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
 
422
 
 
423
    conf_h.close()
 
424
 
 
425
    print "Successfully wrote %s" % conf_hfile
 
426
 
 
427
    # Write www/php/phpBB3/config.php
 
428
 
 
429
    conf_php = open(phpBBconffile, "w")
 
430
    
 
431
    # php-pg work around
 
432
    if conf['database']['host'] == 'localhost':
 
433
        forumdb_host = '127.0.0.1'
 
434
    else:
 
435
        forumdb_host = conf['database']['host']
 
436
 
 
437
    conf_php.write( """<?php
 
438
// phpBB 3.0.x auto-generated configuration file
 
439
// Do not change anything in this file!
 
440
$dbms = 'postgres';
 
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'] + """';
 
446
 
 
447
$table_prefix = 'phpbb_';
 
448
$acm_type = 'file';
 
449
$load_extensions = '';
 
450
@define('PHPBB_INSTALLED', true);
 
451
// @define('DEBUG', true);
 
452
//@define('DEBUG_EXTRA', true);
 
453
 
 
454
$forum_secret = '""" + forum_secret +"""';
 
455
?>"""   )
 
456
    
 
457
    conf_php.close()
 
458
 
 
459
    print "Successfully wrote %s" % phpBBconffile
 
460
 
 
461
    print
 
462
    print "You may modify the configuration at any time by editing"
 
463
    print conffile
 
464
    print conf_hfile
 
465
    print phpBBconffile
 
466
    print
396
467
    
397
468
    return 0
398
469