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

« back to all changes in this revision

Viewing changes to bin/ivle-config

ivle.chat now opens /dev/null as std{in,out,err} when daemonising.

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 ivle/conf/conf.py and bin/trampoline/trampoline/conf.h.
 
25
Creates etc/ivle.conf
26
26
'''
27
27
 
28
28
import optparse
29
29
import getopt
30
30
import os
31
31
import sys
 
32
import stat
32
33
import hashlib
33
34
import uuid
34
35
 
112
113
# Private mode (normal mode) requires login, and only serves files relevant to
113
114
# the logged-in user."""))
114
115
 
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")""",
120
 
    """
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))
126
 
 
127
116
config_options.append(ConfigOption("database/host", "localhost",
128
117
    """PostgreSQL Database config
129
118
==========================
141
130
    """
142
131
# Database name"""))
143
132
 
144
 
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum",
145
 
    """Forum Database name:""",
146
 
    """
147
 
# Forum Database name"""))
148
 
 
149
133
config_options.append(ConfigOption("database/username", "postgres",
150
134
    """Username for DB server login:""",
151
135
    """
153
137
 
154
138
config_options.append(ConfigOption("database/password", "",
155
139
    """Password for DB server login:
156
 
    (Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
 
140
    (Caution: This password is stored in plaintext!)""",
157
141
    """
158
142
# Database password"""))
159
143
 
283
267
    cwd = os.getcwd()
284
268
 
285
269
    # the files that will be created/overwritten
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")
 
270
    try:
 
271
        confdir = os.environ['IVLECONF']
 
272
    except KeyError:
 
273
        confdir = '/etc/ivle'
 
274
 
 
275
    conffile = os.path.join(confdir, 'ivle.conf')
 
276
    plugindefaultfile = os.path.join(confdir, 'plugins.d/000default.conf')
289
277
 
290
278
    # Get command-line arguments to avoid asking questions.
291
279
 
301
289
    if opts == []:
302
290
        # Interactive mode. Prompt the user for all the values.
303
291
 
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.
 
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.
 
296
 
 
297
%s will also be overwritten with the default list of plugins.
310
298
 
311
299
Please hit Ctrl+C now if you do not wish to do this.
312
 
""" % (conffile, conf_hfile, phpBBconffile)
 
300
""" % (conffile, plugindefaultfile)
313
301
 
314
302
        # Get information from the administrator
315
303
        # If EOF is encountered at any time during the questioning, just exit
329
317
 
330
318
    # Error handling on input values
331
319
    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:
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']))
350
 
        return 1
 
325
        if conf['database']['port'] == '' or conf['database']['port'] is None:
 
326
            pass
 
327
        else:
 
328
            print >>sys.stderr, (
 
329
            "Invalid DB port (%s).\n"
 
330
            "Must be an integer between 0 and 65535." %
 
331
                repr(conf['database']['port']))
 
332
            return 1
351
333
    try:
352
334
        conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
353
335
        if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
365
347
    except KeyError:
366
348
        conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
367
349
 
368
 
    # Generate the forum secret
369
 
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
350
    clobber_permissions = not os.path.exists(conffile)
370
351
 
371
352
    # Write ./etc/ivle.conf (even if we loaded from a different filename)
372
353
    conf.filename = conffile
373
 
 
374
354
    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
 
 
380
355
    conf.write()
381
356
 
 
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!
 
362
 
382
363
    print "Successfully wrote %s" % conffile
383
364
 
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
 
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]
 
383
""")
 
384
    plugindefault.close()
 
385
    print "Successfully wrote %s" % plugindefaultfile
 
386
 
 
387
    print
 
388
    print "You may modify the configuration at any time by editing " + conffile
467
389
    
468
390
    return 0
469
391