#!/usr/local/bin/perl
#This was my futile attempt to write a small program
#to .htaccess protect some files
#Anyone is welcome to experiment and play with it.
#If you get it working let me know at bsd@pobox.com

unshift=(@INC,'./library');
if ($#ARGV == -1){
 print "What is the name of the board you want to protect? (????.defs) =>";
 $board=<STDIN>;
 chop($board);
}
else{$board=$ARGV[0];}
require "$board.defs";
print "Enter a path for the password file (should be www user accessible)=>";
$PASSPATH=<STDIN>;
chop($PASSPATH);
if(!-d $PASSPATH){die "Can't find $PASSPATH";}
$htaccess=<<END;
AuthUserFile /$PASSPATH/.htpasswd
AuthGroupFile /dev/null
AuthName ByPassword
AuthType Basic

<Limit GET>
require user $ADMINNAME
</Limit>
END
$passfile="$ADMINNAME:$MASTERPASSWORD";
print "Protect: $HSCRIPTP (y/n)=>";
$ph=<STDIN>;chop($ph);
print "Protect $SSCRIPTP (y/n)=>";
$ps=<STDIN>;chop($ps);
print "Protect $TSCRIPTP (y/n)=>";
$pt=<STDIN>;chop($pt);
if($ph eq "y" || $ph eq "Y"){
 open(DOC,">$HSCRIPTP/.htaccess")||die "Can't open $HSCRIPTP/.htaccess";
 print DOC "$htaccess";
 close(DOC);
 system("cp arhead.cgi $HSCRIPTP");
}
if($ps eq "y" || $ps eq "Y"){
 open(DOC,">$SSCRIPTP/.htaccess")||die "Can't open $SSCRIPTP/.htaccess";
 print DOC "$htaccess";
 close(DOC);
 system("cp arsubhead.cgi $SSCRIPTP");
}
if($pt eq "y" || $pt eq "Y"){
 open(DOC,">$TSCRIPTP/.htaccess")||die "Can't open $TSCRIPTP/.htaccess";
 print DOC "$htaccess";
 close(DOC);
 system("cp artitle.cgi $TSCRIPTP");
}
open(DOC, ">$PASSPATH/.htpasswd") ||die "Can't open $PASSPATH/.htpasswd";
print DOC "$passfile";
close(DOC);
exit;
 
