<h1>Examination of the configuration for
The webserver is the personal web server of Sean Woods. It manages several virtual hosts as well as a mix of dynamically generated content and static files. This page is an explaination of how the site is configured to run <b>toadhttpd</b> in the hopes that the example may answer one or more questions you may have about your own setup.

<h2> Overview</h2>

To keep things ... sane... Sean has broken his configuration file up into several chunks. <b>config.tcl</b> is just the launching point to get to those files.

Files on his linode are hosted from Under that directory is:
<table>
<tr><th doc_root for the default host
<tr><th align=left>sites/gbeefabrics </th><td>The configuration file and static content for
<tr><th configuration file and static content for
<tr><th configuration file and static content Sean's personal website
<tr><th align=left configuration file, static content, customizations, etc for an online volunteer registration database the Sean runs for the Philadelphia Folk Festivals' Camping Committee.
</table>

To make things extra interesting, Sean builds all of his content at home, and synchronizes the file systems on linode via rsync. So there are several points in the configuration where an alternate URL is provided if the request was for localhost, and not a public domain name.

<h3>config.tcl</h3>
Sean's config.tcl is less a configuration file than a launching point to load other configuration files:

<verbatim>
###
# The server's configuration can be modified with calls to "my config set"
###
my config set doc_ttl 900

###
# Package require the stock plugins we need
###
package require toadhttpd::sqlite
package require toadhttpd::bouncer
package require toadhttpd::clique
package require toadhttpd::fossil
package require toadhttpd::trivia
package require toadhttpd::bootstrap
package require toadhttpd::nadger

###
# Some plugins inject behavior into the server object
# do that process
###
my plugin bouncer
my plugin sqlite
my plugin clique
my plugin bootstrap
my plugin nadger

# Remember this location
set srvhere [file dirname [file normalize [info script]]]

###
# Some plugins require additional site specific configuration
# information
###
my config set notifier_sender     {The Blue Fairy}
my config set notifier_originator REDACTED_EMAIL_ADDRESS
my config set notifier_ports        REDACTED_SMTP_PORTS
my config set notifier_server       REDACTED_SMTP_SERVER
my config set notifier_username  REDACTED_SMTP_USER
my config set notifier_password  REDACTED_SMTP_PASSWORD

namespace eval ::etoyoc {}
###
# Load long-form customizations from the libtml directory
###
foreach file [glob -nocomplain [file join $srvhere libtml *.tcl]] {
  try {
    source $file
  } on error {err errdat} {
    puts "File: $file"
    puts "Error: $err"
    puts "Trace: [dict get $errdat -errorinfo]"
  }
}
###
# Go out to each site and load any customizations they need
###
foreach site [glob -nocomplain [file join $srvhere sites *]] {
  foreach file [glob -nocomplain [file join $site libtml *.tcl]] {
    try {
      source $file
    } on error {err errdat} {
      puts "File: $file"
      puts "Error: $err"
      puts "Trace: [dict get $errdat -errorinfo]"
    }
  }
}
###
# Send requests for popular script attack vectors to
# the black hole implemented in the bouncer plugin
###
my uri add % {
  /ccvv
  /admin%

  /wp-login.php%
  /PhpMyAdmin% %.php

  /wls-wsat% /.DS_Store% /.git%  /.hg%  /.idea%  /.ssh%
  /.well-known%  %phpunit%  /sftp_config.%
} {
  mixin toadhttpd::content.honeypot
}

###
#  Load the site specific URL rules
###
foreach site [glob -nocomplain [file join $srvhere sites *]] {
  if {![file exists [file join $site config.tcl]]} continue
  try {
    set sitename [file tail $site]
    source [file join $site config.tcl]
  } on error {err errdat} {
    puts "Site: $site"
    puts "Error: $err"
    puts "Trace: [dict get $errdat -errorinfo]"
  }
}
</verbatim>


<verbatim>
###
# Sites can load their own packages
###
package require toadhttpd::fossil
set here [file dirname [info script]]

if {[file exists {
  ###
  # On the server we only deliver fossil repos in the directory
  ###
  foreach file [glob -nocomplain {
    set proj [file rootname [file tail $file]]
    ###
    # Add to the global robots.txt file that we REALLY do not want to see robots hitting
    # any of the following URIs that fossil hosts
    ###
    foreach area {login leaves files brlist taglist reportlist setup test tkthistory help vdiff} {
      my robots.txt add
    }
  }
  my uri add {
    mixin httpd::content.redirect LOCATION
  }
  my uri add /fossil {
    mixin toadhttpd::content.fossil_root
    fossil_root
    prefix fossil
  }
  my uri add {
    mixin toadhttpd::content.fossil_node_scgi
    prefix fossil
    fossil_root
  }
} else {
  ###
  # On the dev machine, offer up any fossil repository
  # that can be located by "fossil list"
  ##
  my uri add localhost {/fossil {
    mixin toadhttpd::content.fossil_root
    prefix fossil
  }
  my uri add localhost {
    TTL 0
    mixin toadhttpd::content.fossil_node_scgi
    prefix fossil
  }
}
</verbatim>


This file add some customized behaviors
<verbatim>
namespace eval ::gbee {}
tool::define ::gbee::style {
  superclass ::etoyoc::style

  method html_css {} {
    upvar 1 is_localhost is_localhost
    if {$is_localhost} {
      set site_root /gbee
      set site_rel {}
      set stylesheet
    } else {
      set site_root {}
      set site_rel {}
      set stylesheet /style.css
    }
    append result "<link
    append result \n [uplevel 1 {subst {<style media="screen" type="text/css">
body {
	background:  repeat;
	font-family: serif;
	color:#000066;
	font-size: 12pt;
}
.container {
    background-color: white;
}
.normal {
    background-color: white;
}
</style>}}]

  }
  method html_header {title args} {
    set result {}
    uplevel 1 {
set is_localhost [expr {[lindex [split [my http_info getnull HTTP_HOST] :] 0] eq "localhost"}]
    }
    upvar 1 is_localhost is_localhost
    if {$is_localhost} {
      set site_root /gbee
      set site_rel {}
      set stylesheet
    } else {
      set site_root {}
      set site_rel {}
      set stylesheet /style.css
    }
    append result "<HTML><HEAD>"
    if {$title ne {}} {
      append result "<TITLE>$title</TITLE>"
    }
    append result [my html_css]
    append result "</HEAD><BODY><!-- Gbee header -->"
    append result \n {<div id="top-menu">}
    if {[dict exists $args banner]} {
      append result "<img src=\"[dict get $args banner]\">"
    } else {
      append result "<img
    }
    if {[dict exists $args sideimg]} {
      append result "\n<div align=right src=\"[dict get $args sideimg]\" width=25%></div>"
    }
    append result {<div id="content">}
    return $result
  }
  method html_footer_content {args} {
     return [subst {<font size="-1">All content copyright [clock format [clock seconds] -format %Y], GBee Fabrics | <tt>email: <a
  }
}

</verbatim>


<verbatim>
set here [file dirname [file normalize [info script]]]

###
# Gbeefabrics uses a custom content generator to deliver
# news and events
###
my uri add {/news% /events%} {
  CONTENT_TTL 86400
  mixinmap {reply ::etoyoc::content.news style ::gbee::style}
  prefix /news
  path [file join $here htdocs news]
}
###
# All other traffic for gbee fabrics is static content
# served from
# Note: We use an alternate style plugin
###
my uri add % {
  TTL 86400
  mixinmap {reply httpd::content.file style ::gbee::style}
  path [file join $here htdocs]
}
###
# The website has had a few different names that
# have been printed to buisness cards, redirect them
# to the canonical location
###
my uri add % {
  mixin httpd::content.redirect
  LOCATION
}

###
# On the dev box, I just need some rules to deliver the website
# to
###
my uri add localhost {
  TTL 0
  mixinmap {reply ::etoyoc::content.news style ::gbee::style}
  prefix
  path [file join $here htdocs news]
}
my uri add localhost /gbee% {
  CONTENT_TTL 0
  mixinmap {reply httpd::content.file style ::gbee::style}
  path [file join $here htdocs]
  prefix /gbee
}
</verbatim>