Index: src/perl/ldapweb.cgi
===================================================================
--- src/perl/ldapweb.cgi	(revision 4393)
+++ src/perl/ldapweb.cgi	(revision 4394)
@@ -26,10 +26,11 @@
 # This is a web-based application for allowing users to register a new
 # account for Metacat access.  We currently only support LDAP even
 # though metacat could potentially support other types of directories.
-#
+
+use lib '../WEB-INF/lib';
 use strict;             # turn on strict syntax checking
 use Template;           # load the template-toolkit module
-use CGI;                # load the CGI module 
+use CGI qw/:standard :html3/; # load the CGI module 
 use Net::LDAP;          # load the LDAP net libraries
 use Net::SMTP;          # load the SMTP net libraries
 use Digest::SHA1;       # for creating the password hash
@@ -37,14 +38,16 @@
 use URI;                # for parsing URL syntax
 use Config::Properties; # for parsing Java .properties files
 use File::Basename;     # for path name parsing
+use Cwd 'abs_path';
 
 # Global configuration paramters
+# This entire block (including skin parsing) could be pushed out to a separate .pm file
 my $cgiUrl = $ENV{'SCRIPT_FILENAME'};
 my $workingDirectory = dirname($cgiUrl);
 my $metacatProps = "${workingDirectory}/../WEB-INF/metacat.properties";
 my $properties = new Config::Properties();
 unless (open (METACAT_PROPERTIES, $metacatProps)) {
-    #print "Content-type: text/html\n\n";
+    print "Content-type: text/html\n\n";
     print "Unable to locate Metacat properties. Working directory is set as " . 
         $workingDirectory .", is this correct?";
     exit(0);
@@ -54,21 +57,77 @@
 
 ## Set up our default configuration
 my $ldapProps = $properties->splitToTree(qr/\./, 'ldap');
+# local directory configuration
+my $skinsDir = "${workingDirectory}/../style/skins";
+my $templatesDir = abs_path("${workingDirectory}/../style/common/templates");
+my $tempDir = $properties->getProperty('application.tempDir');
+
+# url configuration
+my $server = $properties->splitToTree(qr/\./, 'server');
+my $contextUrl = 'http://' . $properties->getProperty('server.name') . ':' .
+                 $properties->getProperty('server.httpPort') . '/' .
+                 $properties->getProperty('application.context');
+
+my $metacatUrl = $contextUrl . "/metacat";
+my $cgiPrefix = "/" . $properties->getProperty('application.context') . "/cgi-bin";
+my $styleSkinsPath = $contextUrl . "/style/skins";
+my $styleCommonPath = $contextUrl . "/style/common";
+
+my @errorMessages;
+my $error = 0;
+
+# Import all of the HTML form fields as variables
+import_names('FORM');
+
+# Must have a config to use Metacat
+my $skinName = "";
+if ($FORM::cfg) {
+    $skinName = $FORM::cfg;
+} elsif ($ARGV[0]) {
+    $skinName = $ARGV[0];
+} else {
+    debug("Registry: No configuration set.");
+    print "Content-type: text/html\n\n";
+    print 'Registry Error: The registry requires a skin name to continue.';
+    exit();
+}
+
+# Metacat isn't initialized, the registry will fail in strange ways.
+if (!($metacatUrl)) {
+    debug("Registry: No Metacat.");
+    print "Content-type: text/html\n\n";
+    'Registry Error: Metacat is not initialized! Make sure' .
+        ' MetacatUrl is set correctly in ' .  $skinName . '.cfg';
+    exit();
+}
+
+my $skinProperties = new Config::Properties();
+if (!($skinName)) {
+    $error = "Application misconfigured.  Please contact the administrator.";
+    push(@errorMessages, $error);
+} else {
+    my $skinProps = "$skinsDir/$skinName/$skinName.properties";
+    unless (open (SKIN_PROPERTIES, $skinProps)) {
+        print "Content-type: text/html\n\n";
+        print "Unable to locate skin properties at $skinProps.  Is this path correct?";
+        exit(0);
+    }
+    $skinProperties->load(*SKIN_PROPERTIES);
+}
+
+my $config = $skinProperties->splitToTree(qr/\./, 'registry.config');
+
+my $searchBase;
+my $ldapUsername;
+my $ldapPassword;
 my $ldapurl = $ldapProps->{'url'};
-my $mainldapurl = $ldapProps->{'mainurl'};
-my $ldapUsername = $ldapProps->{'user'};
-my $ldapPassword = $ldapProps->{'password'};
-my $searchBase = $ldapProps->{'searchbase'};
-my $mailhost = $properties->getProperty('email.mailhost');
-my $sender = $properties->getProperty('email.sender');
 
 # Java uses miliseconds, Perl expects whole seconds
-my $TIMEOUT = $ldapProps->{'connectTimeLimit'} / 1000;
-my $mainldapdownmessage = "The main ldap server $mainldapurl is down!";
+my $timeout = $ldapProps->{'connectTimeLimit'} / 1000;
+my $ldapdownmessage = "The main ldap server $ldapProps->{'url'} is down!";
 
 # Get the CGI input variables
 my $query = new CGI;
-
 my $debug = 0;
 
 #--------------------------------------------------------------------------80c->
@@ -76,35 +135,43 @@
 
 # templates hash, imported from ldap.templates tree in metacat.properties
 my $templates = $properties->splitToTree(qr/\./, 'ldap.templates');
+$$templates{'header'} = $skinProperties->getProperty("registry.templates.header");
+$$templates{'footer'} = $skinProperties->getProperty("registry.templates.footer");
 
 # set some configuration options for the template object
-my $config_templates = {
-             INCLUDE_PATH => $properties->getProperty('templates-dir'),
-             INTERPOLATE  => 0,                    
-             POST_CHOMP   => 1,                   
+my $ttConfig = {
+             INCLUDE_PATH => $templatesDir,
+             INTERPOLATE  => 0,
+             POST_CHOMP   => 1,
+             DEBUG        => 1, 
              };
 
 # create an instance of the template
-my $template = Template->new($config_templates) || handleGeneralServerFailure($Template::ERROR);
+my $template = Template->new($ttConfig) || handleGeneralServerFailure($Template::ERROR);
 
 # custom LDAP properties hash
 my $ldapCustom = $properties->splitToTree(qr/\./, 'ldap');
 
-my @orgList = split(/,/, $properties->getProperty('ldap.organizations'));
+my $orgProps = $properties->splitToTree(qr/\./, 'organization');
+my $orgNames = $properties->splitToTree(qr/\./, 'organization.name');
+# pull out properties available e.g. 'name', 'base'
+my @orgData = keys(%$orgProps);
+my @orgList;
+while (my ($oKey, $oVal) = each(%$orgNames)) {
+    push(@orgList, $oKey);
+}
+
 my $ldapConfig;
-
 foreach my $o (@orgList) {
-    debug($o);
-    # pull the raw tree in to prevent Perl pass-by-value shenanigans
-    $ldapConfig->{$o} = $properties->splitToTree(qr/\./, 'ldap');
-
-    # override the defaults set in ldap with the custom values
-    if (defined $ldapCustom->{$o}) {
-        my $custom = $ldapCustom->{$o};
-        while (my ($key, $value) = each(%$custom)) {
-            $ldapConfig->{$o}{$key} = $value;
-        }
+    foreach my $d (@orgData) {
+        $ldapConfig->{$o}{$d} = $properties->getProperty("organization.$d.$o");
     }
+    # also include DN, which is just org + base
+    if ($ldapConfig->{$o}{'org'}) {
+        $ldapConfig->{$o}{'dn'} = $ldapConfig->{$o}{'org'} . "," . $ldapConfig->{$o}{'base'};
+    } else {
+        $ldapConfig->{$o}{'dn'} = $ldapConfig->{$o}{'base'};
+    }
 }
 
 #--------------------------------------------------------------------------80c->
@@ -132,6 +199,7 @@
               'resetpass'         => \&handleResetPassword,
               'initresetpass'     => \&handleInitialResetPassword,
              );
+
 # call the appropriate routine based on the stage
 if ( $stages{$stage} ) {
   $stages{$stage}->();
@@ -185,7 +253,6 @@
         exit();
     } else {
         my $o = $query->param('o');    
-        $ldapurl = $ldapConfig->{$o}{'url'};
         $searchBase = $ldapConfig->{$o}{'base'};  
     }
 
@@ -263,7 +330,6 @@
         $$allParams{'o'} = $query->param('o');
         my $o = $query->param('o');
         
-        $ldapurl = $ldapConfig->{$o}{'url'};
         $searchBase = $ldapConfig->{$o}{'base'};
     }
 
@@ -284,7 +350,6 @@
     if ($query->param('userPassword') =~ $query->param('userPassword2')) {
 
         my $o = $query->param('o');
-        $ldapurl = $ldapConfig->{$o}{'url'};
         $searchBase = $ldapConfig->{$o}{'base'};
         $ldapUsername = $ldapConfig->{$o}{'user'};
         $ldapPassword = $ldapConfig->{$o}{'password'};
@@ -345,7 +410,6 @@
         $$allParams{'o'} = $query->param('o');
         my $o = $query->param('o');
         
-        $ldapurl = $ldapConfig->{$o}{'url'};
         $searchBase = $ldapConfig->{$o}{'base'};
         $ldapUsername = $ldapConfig->{$o}{'user'};
         $ldapPassword = $ldapConfig->{$o}{'password'};
@@ -436,20 +500,15 @@
     my $bindPass = shift;
     my $o = shift;
 
-    my $ldapurl = $ldapConfig->{$o}{'url'};
     my $searchBase = $ldapConfig->{$o}{'base'};
     
     my $errorMessage = 0;
     my $ldap;
-    if ($ldapurl =~ $mainldapurl){
-        #if main ldap server is down, a html file containing warning message will be returned
-        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure($mainldapdownmessage);
-    }
-    else{
-        #if a referral ldap server is down, we will ignore it silently
-        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or return;
-    } 
-    #$ldap->start_tls( verify => 'require',
+    
+		#if main ldap server is down, a html file containing warning message will be returned
+    $ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleGeneralServerFailure($ldapdownmessage);
+    
+		#$ldap->start_tls( verify => 'require',
                       #cafile => '/usr/share/ssl/ldapcerts/cacert.pem');
     $ldap->start_tls( verify => 'none');
     my $bindresult = $ldap->bind( version => 3, dn => $bindDN, 
@@ -506,14 +565,9 @@
     my $mesg;
     my $ldap;
     print("ldap server ", $ldapurl, "\n");
-    if ($ldapurl =~ $mainldapurl){
-        #if main ldap server is down, a html file containing warning message will be returned
-        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure($mainldapdownmessage);
-    }
-    else{
-        #if a referral ldap server is down, we will ignore it silently
-        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or return;
-    }
+
+    #if main ldap server is down, a html file containing warning message will be returned
+    $ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleGeneralServerFailure($ldapdownmessage);
     $ldap->start_tls( verify => 'none');
     my $bindresult = $ldap->bind;
     if ($bindresult->code) {
@@ -560,6 +614,8 @@
 
     my $errorMessage = "";
     if ($recipient) {
+				my $mailhost = $properties->getProperty('email.mailhost');
+				my $sender =  $properties->getProperty('email.sender');
         # Send the email message to them
         my $smtp = Net::SMTP->new($mailhost);
         $smtp->mail($sender);
@@ -607,14 +663,8 @@
 
     my $foundAccounts = 0;
     #print("the ldapurl in findExstingAccounts is ", $ldapurl, "\n");
-    if ($ldapurl =~ $mainldapurl){
-        #if main ldap server is down, a html file containing warning message will be returned
-        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure($mainldapdownmessage);
-    }
-    else{
-        #if a referral ldap server is down, we will ignore it silently
-        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or return;
-    }
+    #if main ldap server is down, a html file containing warning message will be returned
+    $ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleGeneralServerFailure($ldapdownmessage);
     $ldap->start_tls( verify => 'none');
     $ldap->bind( version => 3, anonymous => 1);
     my $mesg = $ldap->search (
@@ -703,15 +753,13 @@
 
         my $o = $query->param('o');
 
-        my $ldapurl = $ldapConfig->{$o}{'url'};
         my $ldapUsername = $ldapConfig->{$o}{'user'};
         my $ldapPassword = $ldapConfig->{$o}{'password'};
         my $searchBase = $ldapConfig->{$o}{'base'};
         my $dnBase = $ldapConfig->{$o}{'dn'};
-
         
         #if main ldap server is down, a html file containing warning message will be returned
-        my $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure("The ldap server " . $ldapurl . " is down!");
+        my $ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleGeneralServerFailure("The ldap server " . $ldapurl . " is down!");
         
         
         $ldap->start_tls( verify => 'none');
@@ -851,11 +899,9 @@
     my $attref = shift;
 
     my $foundAccounts = 0;
-
     
-    
     #if ldap server is down, a html file containing warning message will be returned
-    my $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure("The ldap server " . $ldapurl . " is down!");
+    my $ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleGeneralServerFailure("The ldap server " . $ldapurl . " is down!");
     
     $ldap->start_tls( verify => 'none');
     $ldap->bind( version => 3, anonymous => 1);
@@ -922,10 +968,11 @@
     my $paramVars = shift;
     # initialize default parameters 
     my $templateVars = { cfg => $cfg,
-                         styleSkinsPath => $properties->getProperty('style-skins-path'),
-                         styleCommonPath => $properties->getProperty('style-common-path'),
-                         baseUrl => $properties->getProperty('baseUrl'),
+                         styleSkinsPath => $contextUrl . "/style/skins",
+                         styleCommonPath => $contextUrl . "/style/common",
+                         contextUrl => $contextUrl,
                          orgList => \@orgList,
+                         config  => $config,
     };
     
     # append customized params
@@ -939,11 +986,10 @@
 sub fullTemplate {
     my $templateList = shift;
     my $templateVars = setVars(shift);
-
+    
     $template->process( $templates->{'header'}, $templateVars );
-    
     foreach my $tmpl (@{$templateList}) {
         $template->process( $templates->{$tmpl}, $templateVars );
-    }    
+    }
     $template->process( $templates->{'footer'}, $templateVars );
 }
Index: src/perl/register-dataset.cgi
===================================================================
--- src/perl/register-dataset.cgi	(revision 4393)
+++ src/perl/register-dataset.cgi	(revision 4394)
@@ -43,7 +43,6 @@
 use File::Basename;
 use strict;
 
-debug("at top...");
 # Global configuration paramters
 my $cgiUrl = $ENV{'SCRIPT_FILENAME'};
 my $workingDirectory = ".";
