#!/usr/local/bin/perl ################################################# # dbfileutil.pl Ver 1.1 # # By Po-Han Lin # # pohanl@hotmail.com # # # # Export/Import between DB_File and SDBM_File # # from Windows and Unix platforms # # # # SDBM_Files can be ftp'ed across Unix/Windows # # platforms and work without a hitch. (pag and # # dir files). DB_Files can't be ftp'ed across # # platform. (something to do with edian) # # I like to use DB_File instead of SDBM_File # # This util will export a DB_File to SDBM_Files # # for you to ftp. Then you can import the # # files (after ftping) by coverting to DB_File # # at destination workstation using this same # # util. You can also clean up the SDBM_Files # # after you are done ftping (source side) and # # done importing (destination side) # # This same code will work on the unix or win # # side. NOTE: be sure DB_File has less than # # 1024 bytes per entry, or it wont fit into a # # SDBM_File (unless you recompile the SDBM_File # # to support bigger buckets. # # # # By Po-Han Lin # # pohanl@hotmail.com # # http://www.edepot.com/phl.html # # This program is free. Donations accepted # # # # Send Cashiers Check to... # # P.O. Box 1266 # # Alhambra, CA 91802 # # USA # # # # Ver 1.1 # ################################################# # Modify these.... $maindomain = "www.yourhostname.com"; $mainwwwpath="/home/www/wwwdirectory"; $mainwwwurl="http://$maindomain"; $maincgiurl="$mainwwwurl/cgi-bin"; # RENAME THIS SCRIPT TO THE FOLLOWING $scriptName = "$maincgiurl/dbfileutil.pl"; use DB_File; use SDBM_File; use Fcntl; print "Content-type: text/html\n\n"; # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach my $pairentry (@pairs) { my($name, $value) = split(/=/, $pairentry); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; if ($name =~ /term/i) { $value =~ s/^\s+//; $value =~ s/\s+$//; } $FORM{$name} = $value; } # Process GET requests $param=$FORM{'param'}; if ($FORM{'action'} eq "Import") { print "Imported"; $eGlossaryPath = "$mainwwwpath/$param"; tie %oldhash, "SDBM_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644; tie %newhash, "DB_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644; %newhash = %oldhash; } elsif ($FORM{'action'} eq "Export") { print "Exported"; $eGlossaryPath = "$mainwwwpath/$param"; tie %oldhash, "DB_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644; tie %newhash, "SDBM_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644; %newhash = %oldhash; } elsif ($FORM{'action'} eq "CleanWindows") { print "Cleaned"; $pathname = $mainwwwpath . "\\$param.pag"; system("del \"$pathname\" ") == 0 or die "failed"; $pathname = $mainwwwpath . "\\$param.dir"; system("del \"$pathname\" ") == 0 or die "failed"; } elsif ($FORM{'action'} eq "CleanUnix") { print "Cleaned"; $pathname = $mainwwwpath . "/$param.pag"; system("rm \"$pathname\" ") == 0 or die "failed"; $pathname = $mainwwwpath . "/$param.dir"; system("rm \"$pathname\" ") == 0 or die "failed"; } else { &printInputForm; } sub printInputForm { print "
"; print ""; print ""; print ""; print "
"; } 1; =head1 NAME dbfileutil.pl - Export/Import between DB_File and SDBM_File =head1 DESCRIPTION (See README) =head1 README Export/Import between DB_File and SDBM_File from Windows and Unix platforms SDBM_Files can be ftp'ed across Unix/Windows platforms and work without a hitch. (pag and dir files). DB_Files can't be ftp'ed across platform. (something to do with edian) I like to use DB_File instead of SDBM_File This util will export a DB_File to SDBM_Files for you to ftp. Then you can import the files (after ftping) by coverting to DB_File at destination workstation using this same util. You can also clean up the SDBM_Files after you are done ftping (source side) and done importing (destination side) This same code will work on the unix or win side. NOTE: be sure DB_File has less than 1024 bytes per entry, or it wont fit into a SDBM_File (unless you recompile the SDBM_File to support bigger buckets. =head1 Runs on the following OSs: Windows and Unix =head1 Author Po-Han Lin, pohanl@hotmail.com =head1 Copyright This program is free. Donations accepted Send Cashiers Check to... P.O. Box 1266 Alhambra, CA 91802 USA =cut =head1 CPAN Scripts Miscellanea: =head1 SCRIPT CATEGORIES Win32/Utilities UNIX/System_administration Networking =head1 PREREQUISITES This script requires the following modules: DB_File =head1 OSNAMES C C C C =head1 Changes 01.1 Documentation (POD) 01.0 Initial Release =cut __END__