104
110
# Private mode (normal mode) requires login, and only serves files relevant to
105
111
# the logged-in user."""))
107
config_options.append(ConfigOption("media/version", None,
108
"""Version of IVLE media resources (must change on each upgrade):""",
113
config_options.append(ConfigOption("allowed_uids", "33",
114
"""UID of the web server process which will run IVLE.
115
Only this user may execute the trampoline. May specify multiple users as
116
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))
119
# The User-ID of the web server process which will run IVLE, and any other
120
# users who are allowed to run the trampoline. This is stores as a string of
121
# comma-separated integers, simply because it is not used within Python, only
122
# used by the setup program to write to conf.h (see setup.py config).""",
114
config_options.append(ConfigOption("database/host", "localhost",
125
config_options.append(ConfigOption("db_host", "localhost",
115
126
"""PostgreSQL Database config
116
127
==========================
117
128
Hostname of the DB server:""",
130
### PostgreSQL Database config ###
119
131
# Database server hostname"""))
121
config_options.append(ConfigOption("database/port", "5432",
133
config_options.append(ConfigOption("db_port", "5432",
122
134
"""Port of the DB server:""",
124
136
# Database server port"""))
126
config_options.append(ConfigOption("database/name", "ivle",
138
config_options.append(ConfigOption("db_dbname", "ivle",
127
139
"""Database name:""",
129
141
# Database name"""))
131
config_options.append(ConfigOption("database/username", "postgres",
143
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
144
"""Forum Database name:""",
146
# Forum Database name"""))
148
config_options.append(ConfigOption("db_user", "postgres",
132
149
"""Username for DB server login:""",
134
151
# Database username"""))
136
config_options.append(ConfigOption("database/password", "",
153
config_options.append(ConfigOption("db_password", "",
137
154
"""Password for DB server login:
138
(Caution: This password is stored in plaintext!)""",
155
(Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
140
157
# Database password"""))
142
config_options.append(ConfigOption("auth/modules", "",
159
config_options.append(ConfigOption("auth_modules", "",
143
160
"""Authentication config
144
161
=====================
145
162
Comma-separated list of authentication modules.""",
178
195
# other modules may be plugged in to pulldown against organisation-specific
179
196
# pulldown backends.""", ask=False))
181
config_options.append(ConfigOption("urls/svn_addr",
182
"http://svn.ivle.localhost/",
198
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
183
199
"""Subversion config
184
200
=================
185
201
The base url for accessing subversion repositories:""",
187
203
# The base url for accessing subversion repositories."""))
189
config_options.append(ConfigOption("usrmgt/host", "localhost",
205
config_options.append(ConfigOption("usrmgt_host", "localhost",
190
206
"""User Management Server config
191
207
============================
192
208
The hostname where the usrmgt-server runs:""",
194
210
# The hostname where the usrmgt-server runs."""))
196
config_options.append(ConfigOption("usrmgt/port", "2178",
212
config_options.append(ConfigOption("usrmgt_port", "2178",
197
213
"""The port where the usrmgt-server runs:""",
199
215
# The port where the usrmgt-server runs.""", ask=False))
201
config_options.append(ConfigOption("usrmgt/magic", None,
217
config_options.append(ConfigOption("usrmgt_magic", None,
202
218
"""The password for the usrmgt-server:""",
204
220
# 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
def query_user(default, prompt):
223
"""Prompts the user for a string, which is read from a line of stdin.
224
Exits silently if EOF is encountered. Returns the string, with spaces
225
removed from the beginning and end.
227
Returns default if a 0-length line (after spaces removed) was read.
230
# A default of None means the value will be computed specially, so we
231
# can't really tell you what it is
232
defaultstr = "computed"
233
elif isinstance(default, basestring):
234
defaultstr = '"%s"' % default
236
defaultstr = repr(default)
237
sys.stdout.write('%s\n (default: %s)\n>' % (prompt, defaultstr))
239
val = sys.stdin.readline()
240
except KeyboardInterrupt:
242
sys.stdout.write("\n")
244
sys.stdout.write("\n")
246
if val == '': sys.exit(1)
247
# If empty line, return default
249
if val == '': return default
252
222
def configure(args):
223
usage = """usage: %prog config [options]
224
Creates lib/conf/conf.py (and a few other config files).
225
Interactively asks questions to set this up."""
228
parser = optparse.OptionParser(usage)
229
(options, args) = parser.parse_args(args)
231
# Call the real function
232
return __configure(args)
234
def __configure(args):
235
global db_port, usrmgt_port
253
237
# Try importing existing conf, but if we can't just set up defaults
254
238
# The reason for this is that these settings are used by other phases
255
239
# of setup besides conf, so we need to know them.
256
240
# Also this allows you to hit Return to accept the existing value.
258
conf = ivle.config.Config()
259
except ivle.config.ConfigError:
260
# Couldn't find a config file anywhere.
261
# Create a new blank config object (not yet bound to a file)
262
# All lookups (below) will fail, so it will be initialised with all
263
# the default values.
264
conf = ivle.config.Config(blank=True)
266
# Check that all the options are present, and if not, load the default
267
for opt in config_options:
269
conf.get_by_path(opt.option_name)
271
# If the default is None, omit it
272
# Else ConfigObj will write the string 'None' to the conf file
273
if opt.default is not None:
274
conf.set_by_path(opt.option_name, opt.default)
276
# Store comments in the conf object
277
for opt in config_options:
278
# Omitted if the key doesn't exist
279
conf.set_by_path(opt.option_name, comment=opt.comment)
242
confmodule = __import__("ivle/conf/conf")
243
for opt in config_options:
245
globals()[opt.option_name] = \
246
confmodule.__dict__[opt.option_name]
248
globals()[opt.option_name] = opt.default
250
# Just set reasonable defaults
251
for opt in config_options:
252
globals()[opt.option_name] = opt.default
281
254
# Set up some variables
282
255
cwd = os.getcwd()
284
257
# the files that will be created/overwritten
286
confdir = os.environ['IVLECONF']
288
confdir = '/etc/ivle'
290
conffile = os.path.join(confdir, 'ivle.conf')
291
plugindefaultfile = os.path.join(confdir, 'plugins.d/000default.conf')
258
conffile = os.path.join(cwd, "ivle/conf/conf.py")
259
jailconffile = os.path.join(cwd, "ivle/conf/jailconf.py")
260
conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h")
261
phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
293
263
# Get command-line arguments to avoid asking questions.
321
292
for opt in config_options:
323
conf.set_by_path(opt.option_name,
324
query_user(conf.get_by_path(opt.option_name), opt.prompt))
294
globals()[opt.option_name] = \
295
query_user(globals()[opt.option_name], opt.prompt)
326
297
opts = dict(opts)
327
298
# Non-interactive mode. Parse the options.
328
299
for opt in config_options:
329
300
if '--' + opt.option_name in opts:
330
conf.set_by_path(opt.option_name,
331
opts['--' + opt.option_name])
301
globals()[opt.option_name] = opts['--' + opt.option_name]
333
303
# Error handling on input values
335
conf['database']['port'] = int(conf['database']['port'])
336
if (conf['database']['port'] < 0
337
or conf['database']['port'] >= 65536):
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']))
349
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
350
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
305
allowed_uids_list = map(int, allowed_uids.split(','))
307
print >>sys.stderr, (
308
"Invalid UID list (%s).\n"
309
"Must be a comma-separated list of integers." % allowed_uids)
312
db_port = int(db_port)
313
if db_port < 0 or db_port >= 65536: raise ValueError()
315
print >>sys.stderr, (
316
"Invalid DB port (%s).\n"
317
"Must be an integer between 0 and 65535." % repr(db_port))
320
usrmgt_port = int(usrmgt_port)
321
if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
352
322
except ValueError:
353
323
print >>sys.stderr, (
354
324
"Invalid user management port (%s).\n"
355
"Must be an integer between 0 and 65535." %
356
repr(conf['usrmgt']['port']))
325
"Must be an integer between 0 and 65535." % repr(usrmgt_port))
359
328
# By default we generate the magic randomly.
329
if globals()['usrmgt_magic'] is None:
330
globals()['usrmgt_magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
332
# Generate the forum secret
333
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
335
# Write lib/conf/conf.py
361
conf['usrmgt']['magic'] # Throw away; just check for KeyError
363
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
365
clobber_permissions = not os.path.exists(conffile)
367
# Write ./etc/ivle.conf (even if we loaded from a different filename)
368
conf.filename = conffile
369
conf.initial_comment = ["# IVLE Configuration File"]
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!
338
conf = open(conffile, "w")
340
conf.write("""# IVLE Configuration File
342
# Miscellaneous application settings
347
for opt in config_options:
348
conf.write('%s\n%s = %r\n' % (opt.comment, opt.option_name,
349
globals()[opt.option_name]))
351
# Add the forum secret to the config file (regenerated each config)
352
conf.write('forum_secret = "%s"\n\n' % (forum_secret))
354
write_conf_file_boilerplate(conf)
357
except IOError, (errno, strerror):
358
print "IO error(%s): %s" % (errno, strerror)
378
361
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
363
# Write conf/jailconf.py
366
conf = open(jailconffile, "w")
368
# In the "in-jail" version of conf, we don't need MOST of the details
369
# (it would be a security risk to have them here).
370
# So we just write root_dir, and jail_base is "/".
371
# (jail_base being "/" means "jail-relative" paths are relative to "/"
372
# when inside the jail.)
373
conf.write("""# IVLE Configuration File
375
# Miscellaneous application settings
376
# (User jail version)
379
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
381
# eg. "/" or "/ivle".
384
# In the local file system, where are the student/user file spaces located.
385
# The user jails are expected to be located immediately in subdirectories of
389
# The hostname for serving publicly accessible pages
392
# The URL under which the Subversion repositories are located.
394
""" % (repr(root_dir),repr(public_host),repr(svn_addr)))
397
except IOError, (errno, strerror):
398
print "IO error(%s): %s" % (errno, strerror)
401
print "Successfully wrote %s" % jailconffile
403
# Write bin/trampoline/conf.h
406
conf = open(conf_hfile, "w")
408
# XXX Compute jail_base, jail_src_base and jail_system. These will
409
# ALSO be done by the boilerplate code, but we need them here in order
410
# to write to the C file.
411
jail_base = os.path.join(data_path, 'jailmounts')
412
jail_src_base = os.path.join(data_path, 'jails')
413
jail_system = os.path.join(jail_src_base, '__base__')
415
conf.write("""/* IVLE Configuration File
417
* Administrator settings required by trampoline.
418
* Note: trampoline will have to be rebuilt in order for changes to this file
422
#define IVLE_AUFS_JAILS
424
/* In the local file system, where are the jails located.
425
* The trampoline does not allow the creation of a jail anywhere besides
426
* jail_base or a subdirectory of jail_base.
428
static const char* jail_base = "%s";
429
static const char* jail_src_base = "%s";
430
static const char* jail_system = "%s";
432
/* Which user IDs are allowed to run the trampoline.
433
* This list should be limited to the web server user.
434
* (Note that root is an implicit member of this list).
436
static const int allowed_uids[] = { %s };
437
""" % (repr(jail_base)[1:-1], repr(jail_src_base)[1:-1],
438
repr(jail_system)[1:-1], repr(allowed_uids_list)[1:-1]))
439
# Note: The above uses PYTHON reprs, not C reprs
440
# However they should be the same with the exception of the outer
441
# characters, which are stripped off and replaced
444
except IOError, (errno, strerror):
445
print "IO error(%s): %s" % (errno, strerror)
448
print "Successfully wrote %s" % conf_hfile
450
# Write www/php/phpBB3/config.php
453
conf = open(phpBBconffile, "w")
456
if db_host == 'localhost':
457
forumdb_host = '127.0.0.1'
459
forumdb_host = db_host
462
// phpBB 3.0.x auto-generated configuration file
463
// Do not change anything in this file!
465
$dbhost = '""" + forumdb_host + """';
466
$dbport = '""" + str(db_port) + """';
467
$dbname = '""" + db_forumdbname + """';
468
$dbuser = '""" + db_user + """';
469
$dbpasswd = '""" + db_password + """';
471
$table_prefix = 'phpbb_';
473
$load_extensions = '';
474
@define('PHPBB_INSTALLED', true);
475
// @define('DEBUG', true);
476
//@define('DEBUG_EXTRA', true);
478
$forum_secret = '""" + forum_secret +"""';
482
except IOError, (errno, strerror):
483
print "IO error(%s): %s" % (errno, strerror)
486
print "Successfully wrote %s" % phpBBconffile
489
print "You may modify the configuration at any time by editing"
412
# Print the opening spiel including the GPL notice
414
print """IVLE - Informatics Virtual Learning Environment Setup
415
Copyright (C) 2007-2009 The University of Melbourne
416
IVLE comes with ABSOLUTELY NO WARRANTY.
417
This is free software, and you are welcome to redistribute it
418
under certain conditions. See LICENSE.txt for details.
423
return configure(argv[1:])
425
if __name__ == "__main__":
498
def write_conf_file_boilerplate(conf_file):
500
### Below is boilerplate code, appended by ./setup.py config ###
502
# Path where architecture-dependent data (including non-user-executable
503
# binaries) is installed.
504
lib_path = os.path.join(prefix, 'lib/ivle')
506
# Path where arch-independent data is installed.
507
share_path = os.path.join(prefix, 'share/ivle')
509
# Path where user-executable binaries are installed.
510
bin_path = os.path.join(prefix, 'bin')
512
# 'site-packages' directory in Python, where Python libraries are to be
514
if python_site_packages_override is None:
515
PYTHON_VERSION = sys.version[0:3] # eg. "2.5"
516
python_site_packages = os.path.join(prefix,
517
'lib/python%s/site-packages' % PYTHON_VERSION)
519
python_site_packages = python_site_packages_override
521
# In the local file system, where the student/user jails will be mounted.
522
# Only a single copy of the jail's system components will be stored here -
523
# all user jails will be virtually mounted here.
524
jail_base = os.path.join(data_path, 'jailmounts')
526
# In the local file system, where are the student/user file spaces located.
527
# The user jails are expected to be located immediately in subdirectories of
528
# this location. Note that no complete jails reside here - only user
530
jail_src_base = os.path.join(data_path, 'jails')
532
# In the local file system, where the template system jail will be stored.
533
jail_system = os.path.join(jail_src_base, '__base__')
535
# In the local file system, where the subject content files are located.
536
# (The 'subjects' and 'exercises' directories).
537
content_path = os.path.join(data_path, 'content')
539
# In the local file system, where are the per-subject file spaces located.
540
# The individual subject directories are expected to be located immediately
541
# in subdirectories of this location.
542
subjects_base = os.path.join(content_path, 'subjects')
544
# In the local file system, where are the subject-independent exercise sheet
545
# file spaces located.
546
exercises_base = os.path.join(content_path, 'exercises')
548
# In the local file system, where the system notices are stored (such as terms
549
# of service and MOTD).
550
notices_path = os.path.join(data_path, 'notices')
552
# In the local file system, where is the Terms of Service document located.
553
tos_path = os.path.join(notices_path, 'tos.html')
555
# In the local file system, where is the Message of the Day document
556
# located. This is an HTML file (just the body fragment), which will
557
# be displayed on the login page. It is optional.
558
motd_path = os.path.join(notices_path, 'motd.html')
560
# The location of all the subversion config and repositories.
561
svn_path = os.path.join(data_path, 'svn')
563
# The location of the subversion configuration file used by
564
# apache to host the user repositories.
565
svn_conf = os.path.join(svn_path, 'svn.conf')
567
# The location of the subversion configuration file used by
568
# apache to host the user repositories.
569
svn_group_conf = os.path.join(svn_path, 'svn-group.conf')
571
# The root directory for the subversion repositories.
572
svn_repo_path = os.path.join(svn_path, 'repositories')
574
# The location of the password file used to authenticate users
575
# of the subversion repository from the ivle server.
576
svn_auth_ivle = os.path.join(svn_path, 'ivle.auth')