#!/usr/bin/env perl # # BEGIN COPYRIGHT BLOCK # This Program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; version 2 of the License. # # This Program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA. # # In addition, as a special exception, Red Hat, Inc. gives You the additional # right to link the code of this Program with code not covered under the GNU # General Public License ("Non-GPL Code") and to distribute linked combinations # including the two, subject to the limitations in this paragraph. Non-GPL Code # permitted under this exception must only link to the code of this Program # through those well defined interfaces identified in the file named EXCEPTION # found in the source code files (the "Approved Interfaces"). The files of # Non-GPL Code may instantiate templates or use macros or inline functions from # the Approved Interfaces without causing the resulting work to be covered by # the GNU General Public License. Only Red Hat, Inc. may make changes or # additions to the list of Approved Interfaces. You must obey the GNU General # Public License in all respects for all of the Program code and other code used # in conjunction with the Program except the Non-GPL Code covered by this # exception. If you modify this file, you may extend this exception to your # version of the file, but you are not obligated to do so. If you do not wish to # provide this exception without modification, you must delete this exception # statement from your version and license this file solely under the GPL without # exception. # # # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. # Copyright (C) 2005 Red Hat, Inc. # All rights reserved. # END COPYRIGHT BLOCK # # print begin message $now_time = gmtime; print "BEGIN DSGW migration at ", $now_time, " GMT\n"; # get the commandline options if (!getopts('s:d:h:') || !$opt_s || !$opt_d || !$opt_h ) { print "usage: dsgwmig options\n"; print "\noptions:\n"; print " -s directory\tdirectory containing the 3.0 Gateway\n"; print " -d directory\tdirectory containing the 4.1 Gateway\n"; print " -h host[:port]\tthe host and port of the directory server\n"; print " \t\t\tto which the migrated gateway will query\n"; print "\nexample:\n dsgwmig -s /usr/tmp/ds30/slapd-host/dsgw -d /usr/tmp/ds40/dsgw -h gargoyle:1974\n"; exit; } sub reportAndExit { my $now_time = gmtime; print "END DSGW migration at ", $now_time, " GMT\n"; print "DSGW Exit status is ", $exitCode, "\n"; if ($? == 0 && $exitCode == 0) { print "NMC_STATUS: 0\n"; } else { print '$?=', $?+0, ' $!=', $!+0, ' $exitCode=', $exitCode, "\n"; print shift, "\n"; print "NMC_STATUS: $exitCode\n"; } print "###DSGW MIGRATION FINISHED###\n"; exit($exitCode); } $SIG{__DIE__} = 'exit'; $SIG{'QUIT'} = 'exit'; $SIG{'INT'} = 'exit'; $SIG{'TERM'} = 'exit'; # the atexit handler END { $! = 0; $? = $exitCode; &reportAndExit; } # setup the path separator $isNT = -d '\\'; $PS = $isNT ? "\\" : "/"; #make sure that the target directory exists if (! -e $opt_d) { print "$opt_d does not exist\n"; exit; } print "Migrating the config directory...\n"; # First migrate the config directory migrate_html("config"); print "Migrating the html directory...\n"; # Then migrate the html directory migrate_html("html"); print "Migrating the dsgw.conf...\n"; # Then migrate dsgw.conf migrate_config(); # Then copy over certain files like alert.html, confirm.html and emptyFrame from # the regular *4.1* DSGW to the newly migrated *4.1* gateway. if (! -e "$opt_d"."$PS"."html-30"."$PS"."alert.html") { print "copy ", "$opt_d"."$PS"."html"."$PS"."alert.html", " $opt_d"."$PS"."html-30"."$PS"."alert.html", "\n"; copyFile("$opt_d"."$PS"."html"."$PS"."alert.html", "$opt_d"."$PS"."html-30"."$PS"."alert.html"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."confirm.html") { print "copy ", "$opt_d"."$PS"."html"."$PS"."confirm.html", " $opt_d"."$PS"."html-30"."$PS"."confirm.html", "\n"; copyFile("$opt_d"."$PS"."html"."$PS"."confirm.html", "$opt_d"."$PS"."html-30"."$PS"."confirm.html"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."confirm.gif") { copyFile("$opt_d"."$PS"."html"."$PS"."confirm.gif", "$opt_d"."$PS"."html-30"."$PS"."confirm.gif"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."alert.gif") { copyFile("$opt_d"."$PS"."html"."$PS"."alert.gif", "$opt_d"."$PS"."html-30"."$PS"."alert.gif"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."emptyFrame.html") { copyFile("$opt_d"."$PS"."html"."$PS"."emptyFrame.html", "$opt_d"."$PS"."html-30"."$PS"."emptyFrame.html"); } print "end of migratedsgw\n"; $exitCode = 0; exit $exitCode; sub migrate_html { my $target_dir = shift(@_); my $orig_target = "$target_dir"; my $full_target_dir; my @subdirlist; my @dsgwfiles; # cd into the source directory chdir "$opt_s"."$PS"."$target_dir" or die "Unable to cd to $opt_s$PS$target_dir: $!\n"; # read the files opendir DSGW_OLD, "." or die "$!"; @dsgwfiles = grep !/^\.\.?$/, readdir DSGW_OLD; closedir DSGW_OLD; # Before we go on, we need to make the directory # in the 4.1 space. If we're working on the config # or html directory, then we have to rename them. $target_dir =~ s/^(config|html)/$1\-30/; $full_target_dir = "$opt_d". "$PS". "$target_dir"; if (! -d $full_target_dir) { mkdir $full_target_dir, 0755 or die "can't create $opt_d$PS$target_dir. $!\n"; } # foreach file in the current directory, # either skip it (if it's a subdir) # copy it to the new directory # copy and modify it to the new directory foreach $file (@dsgwfiles){ # #Skip directories if (-d $file) { # print "Skipping Directory $file\n"; push @subdirlist, $file; next; } if ($file =~ m/.*?\.html/) { # open the old file open(OLDFILE, "$file") or die "Cannot read $file. $!\n"; # open the new file open(NEWFILE, ">"."$full_target_dir"."$PS"."$file") or die "Cannot write $full_target_dir$PS$file. $!\n"; for ($line=; $line ; $line=) { # replace all ACTION=/ds/cgi with ACTION=/dsgw/bin/cgi $line =~ s:(?i)(action\s*=\s*("){0,1}\s*(http(s){0,1}\://.*?){0,1})/ds/(\w*):$1/dsgw/bin/$5:g; #")) # Langify the gifs, but not those that are already langified. Look for ="blah.gif" $line =~ s:(?i)=\s*("){0,1}\s*([\w|\-|_]*)\.(gif|jpg|jpeg):=$1/dsgw/bin/lang?\