== Install guest registration with email confirmation ==
 * Install MIME::Lite::TT. On RHEL/CentOS: yum install perl-MIME-Lite-TT

 * Poke a hole in conf/templates/httpd.conf. Place the following statements next to cgi-bin rewrite rules under *:443 virtualhost section:
  RewriteCond %{REQUEST_URI} !^/cgi-bin/guest.cgi
  RewriteCond %{REQUEST_URI} !^/cgi-bin/email_activation.cgi

 * Add new rewrite rules allowing activation before the long series of RewriteCond under *:443 virtualhost:
  # Email activation clean URL to cgi conversion
  RewriteCond %{REQUEST_URI} ^/activate/.+$
  # [PT] here allows us to mix ScriptAlias and mod_rewrite stuff
  RewriteRule ^/activate/([0-9a-z]+)$ https://%%hostname%%.%%domain%%/cgi-bin/email_activation.cgi?code=$1 [PT]

 * Allow the normal VLAN to reach email_activation.cgi. First through firewall, then through apache access lists. Don't forget to include linked images and such in the LocationMatch.
  <LocationMatch ^/cgi-bin/email_activation.cgi>
    SSLOptions +StdEnvVars
        Options ExecCGI
    Order deny,allow
    Deny from all
    allow from %%internal-nets%% %%routed-nets%% 10.100.160.0/16 127.0.0.1
  </LocationMatch>

 * Create new database table. Run:
  mysql -u root -p pf -v < addons/guest-management/schema-email-activation.sql

 * Redirect the user to cgi-bin/guest.cgi for guest registration

 * Activate node expiration in conf/pf.conf. As a workaround for a bug, we need to set a ridiculous long window expiration. This will be fixed in the future. Under [registration] add:
  # Workaround to activate expiration
  expire_mode=window
  expire_window=999w

 * Reduce the maintenance_interval so nodes unregister quicker than every 10 minutes. In conf/pf.conf under [general] add:
  maintenance_interval=30s

 * Add a guest category. Do it with the web admin or Run the following:
  pfcmd nodecategory add name=guest

== Customization ==
 * HTML templates:
  Guest registration page: html/captive-portal/templates/guest.html
  Page shown once activated: html/captive-portal/templates/activated.html
 * The email template is: conf/templates/emails-guest_activation.txt.tt

== Temporary passwords ==
 * Requires: perl(Crypt::GeneratePassword)
 * SQL in addons/guest-management/schema-temporary-passwords.sql

== Pre-registered guests by staff authenticated against AD ==
 1. Installed MIME::Lite::TT, Crypt::GeneratePassword
 2. Applied schema-temporary-passwords.sql
 3. Poke proper holes in Apache config
 4. Overload web_user_authenticate so that it'll return properties hash from auth module
 5. Add glue in cgi-bin/register.cgi right before pf::web::web_node_register like:
    # CUSTOM pre-registered guests handling
    if ($session->param("authType") eq 'preregistered_guests') {

        # max 2 nodes per guest
        if (node_pid($pid) >= 2) {
          $logger->info("2 nodes are already registered to $pid");
          pf::web::generate_error_page($cgi, $session, "error: only register max nodes");
          return(0);
        }

        # set expiration
        my $expire_in = normalize_time($auth_param->{'access_duration'});
        $info{'unregdate'} = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime( time + $expire_in ));
        $logger->info("new guest $pid successfully authenticated. access expires at: ".$info{'unregdate'});

        # categorize
        $info{'category'} = "invite";
    }



