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

« back to all changes in this revision

Viewing changes to bin/ivle-config

ivle-config now sets appropriate permissions (www-data:, 600) on any config
file that it creates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
136
137
 
137
138
config_options.append(ConfigOption("database/password", "",
138
139
    """Password for DB server login:
139
 
    (Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
 
140
    (Caution: This password is stored in plaintext!)""",
140
141
    """
141
142
# Database password"""))
142
143
 
288
289
        # Interactive mode. Prompt the user for all the values.
289
290
 
290
291
        print """This tool will create %s, prompting you for details about
291
 
your configuration. The file will be overwritten if it already exists.
 
292
your configuration. The file will be updated with modified options if it already
 
293
exists. If it does not already exist, it will be created with sane defaults and
 
294
restrictive permissions.
292
295
 
293
296
Please hit Ctrl+C now if you do not wish to do this.
294
297
""" % conffile
338
341
    except KeyError:
339
342
        conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
340
343
 
 
344
    clobber_permissions = not os.path.exists(conffile)
341
345
 
342
346
    # Write ./etc/ivle.conf (even if we loaded from a different filename)
343
347
    conf.filename = conffile
344
 
 
345
348
    conf.initial_comment = ["# IVLE Configuration File"]
346
349
 
347
350
    try:
353
356
 
354
357
    conf.write()
355
358
 
 
359
    # We need to restrict permissions on a new file, as it contains
 
360
    # a nice database password.
 
361
    if clobber_permissions:
 
362
        os.chown(conffile, 33, 33) # chown to www-data
 
363
        os.chmod(conffile, stat.S_IRUSR | stat.S_IWUSR) # No g/o perms!
 
364
 
356
365
    print "Successfully wrote %s" % conffile
357
366
    print
358
367
    print "You may modify the configuration at any time by editing " + conffile