129
122
# used by the setup program to write to conf.h (see setup.py config).""",
132
config_options.append(ConfigOption("database/host", "localhost",
125
config_options.append(ConfigOption("db_host", "localhost",
133
126
"""PostgreSQL Database config
134
127
==========================
135
128
Hostname of the DB server:""",
130
### PostgreSQL Database config ###
137
131
# Database server hostname"""))
139
config_options.append(ConfigOption("database/port", "5432",
133
config_options.append(ConfigOption("db_port", "5432",
140
134
"""Port of the DB server:""",
142
136
# Database server port"""))
144
config_options.append(ConfigOption("database/name", "ivle",
138
config_options.append(ConfigOption("db_dbname", "ivle",
145
139
"""Database name:""",
147
141
# Database name"""))
149
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum",
143
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
150
144
"""Forum Database name:""",
152
146
# Forum Database name"""))
154
config_options.append(ConfigOption("database/username", "postgres",
148
config_options.append(ConfigOption("db_user", "postgres",
155
149
"""Username for DB server login:""",
157
151
# Database username"""))
159
config_options.append(ConfigOption("database/password", "",
153
config_options.append(ConfigOption("db_password", "",
160
154
"""Password for DB server login:
161
155
(Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
163
157
# Database password"""))
165
config_options.append(ConfigOption("auth/modules", "",
159
config_options.append(ConfigOption("auth_modules", "",
166
160
"""Authentication config
167
161
=====================
168
162
Comma-separated list of authentication modules.""",
201
195
# other modules may be plugged in to pulldown against organisation-specific
202
196
# pulldown backends.""", ask=False))
204
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/",
198
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
205
199
"""Subversion config
206
200
=================
207
201
The base url for accessing subversion repositories:""",
209
203
# The base url for accessing subversion repositories."""))
211
config_options.append(ConfigOption("usrmgt/host", "localhost",
205
config_options.append(ConfigOption("usrmgt_host", "localhost",
212
206
"""User Management Server config
213
207
============================
214
208
The hostname where the usrmgt-server runs:""",
216
210
# The hostname where the usrmgt-server runs."""))
218
config_options.append(ConfigOption("usrmgt/port", "2178",
212
config_options.append(ConfigOption("usrmgt_port", "2178",
219
213
"""The port where the usrmgt-server runs:""",
221
215
# The port where the usrmgt-server runs.""", ask=False))
223
config_options.append(ConfigOption("usrmgt/magic", None,
217
config_options.append(ConfigOption("usrmgt_magic", None,
224
218
"""The password for the usrmgt-server:""",
226
220
# The password for the usrmgt-server.""", ask=False))
228
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)
229
231
# Call the real function
230
232
return __configure(args)
232
234
def __configure(args):
235
global db_port, usrmgt_port
233
237
# Try importing existing conf, but if we can't just set up defaults
234
238
# The reason for this is that these settings are used by other phases
235
239
# of setup besides conf, so we need to know them.
236
240
# Also this allows you to hit Return to accept the existing value.
238
conf = ivle.config.Config()
239
except ivle.config.ConfigError:
240
# Couldn't find a config file anywhere.
241
# Create a new blank config object (not yet bound to a file)
242
# All lookups (below) will fail, so it will be initialised with all
243
# the default values.
244
conf = ivle.config.Config(blank=True)
246
for opt in config_options:
248
conf_options[opt.option_name] = conf.get_by_path(opt.option_name)
250
conf_options[opt.option_name] = opt.default
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
252
254
# Set up some variables
253
255
cwd = os.getcwd()
255
257
# the files that will be created/overwritten
256
conffile = os.path.join(cwd, "etc/ivle.conf")
258
conffile = os.path.join(cwd, "ivle/conf/conf.py")
259
jailconffile = os.path.join(cwd, "ivle/conf/jailconf.py")
257
260
conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h")
258
261
phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
288
292
for opt in config_options:
290
conf_options[opt.option_name] = \
291
query_user(conf_options[opt.option_name], opt.prompt)
294
globals()[opt.option_name] = \
295
query_user(globals()[opt.option_name], opt.prompt)
293
297
opts = dict(opts)
294
298
# Non-interactive mode. Parse the options.
295
299
for opt in config_options:
296
300
if '--' + opt.option_name in opts:
297
conf_options[opt.option_name] = opts['--' + opt.option_name]
301
globals()[opt.option_name] = opts['--' + opt.option_name]
299
303
# Error handling on input values
301
allowed_uids_list = map(int,
302
conf_options['os/allowed_uids'].split(','))
305
allowed_uids_list = map(int, allowed_uids.split(','))
303
306
except ValueError:
304
307
print >>sys.stderr, (
305
308
"Invalid UID list (%s).\n"
306
"Must be a comma-separated list of integers." %
307
conf_options['os/allowed_uids'])
309
"Must be a comma-separated list of integers." % 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):
312
db_port = int(db_port)
313
if db_port < 0 or db_port >= 65536: raise ValueError()
314
314
except ValueError:
315
315
print >>sys.stderr, (
316
316
"Invalid DB port (%s).\n"
317
"Must be an integer between 0 and 65535." %
318
repr(conf_options['database/port']))
317
"Must be an integer between 0 and 65535." % repr(db_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):
320
usrmgt_port = int(usrmgt_port)
321
if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
325
322
except ValueError:
326
323
print >>sys.stderr, (
327
324
"Invalid user management port (%s).\n"
328
"Must be an integer between 0 and 65535." %
329
repr(conf_options['usrmgt/port']))
325
"Must be an integer between 0 and 65535." % repr(usrmgt_port))
332
328
# 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()
329
if globals()['usrmgt_magic'] is None:
330
globals()['usrmgt_magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
337
332
# Generate the forum secret
338
333
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
340
# Write ./etc/ivle.conf (even if we loaded from a different filename)
341
conf.filename = conffile
343
conf.initial_comment = ["# IVLE Configuration File"]
345
# Add the forum secret to the config file (regenerated each config)
346
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)
335
# Write lib/conf/conf.py
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)
356
361
print "Successfully wrote %s" % 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
358
403
# Write bin/trampoline/conf.h
360
conf = open(conf_hfile, "w")
362
# XXX Compute jail_base, jail_src_base and jail_system. These will
363
# ALSO be done by the boilerplate code, but we need them here in order
364
# 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')
367
jail_system = os.path.join(jail_src_base, '__base__')
369
conf.write("""/* IVLE Configuration File
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
371
417
* Administrator settings required by trampoline.
372
418
* Note: trampoline will have to be rebuilt in order for changes to this file
394
440
# However they should be the same with the exception of the outer
395
441
# characters, which are stripped off and replaced
444
except IOError, (errno, strerror):
445
print "IO error(%s): %s" % (errno, strerror)
399
448
print "Successfully wrote %s" % conf_hfile
401
450
# Write www/php/phpBB3/config.php
403
conf = open(phpBBconffile, "w")
406
if conf_options['database/host'] == 'localhost':
407
forumdb_host = '127.0.0.1'
409
forumdb_host = conf_options['database/host']
453
conf = open(phpBBconffile, "w")
456
if db_host == 'localhost':
457
forumdb_host = '127.0.0.1'
459
forumdb_host = db_host
412
462
// phpBB 3.0.x auto-generated configuration file
413
463
// Do not change anything in this file!
414
464
$dbms = 'postgres';
415
465
$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'] + """';
466
$dbport = '""" + str(db_port) + """';
467
$dbname = '""" + db_forumdbname + """';
468
$dbuser = '""" + db_user + """';
469
$dbpasswd = '""" + db_password + """';
421
471
$table_prefix = 'phpbb_';
422
472
$acm_type = 'file';
428
478
$forum_secret = '""" + forum_secret +"""';
482
except IOError, (errno, strerror):
483
print "IO error(%s): %s" % (errno, strerror)
433
486
print "Successfully wrote %s" % phpBBconffile
436
489
print "You may modify the configuration at any time by editing"
439
493
print phpBBconffile
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')