#!/usr/bin/perl

use strict;

my $script = "img_inst.pl";
my $version = "$script v. 20051125";

require("img_magick.conf");
my ($galrep,$password,$back_txt,$back_url2,$galerie_txt,$multirep,$monorep,$SIGNATURE,$ADMIN,$HEADER,$FOOTER,$CSS,$diapowait) = &init1();
my $instrep = "$galrep";

#########################################################################
#### parametres utilisateur :

my $chmod = "/bin/chmod";
my $magick = "lynx -dump http://resoo.com/cgi-bin/img_magick.pl";

## fin parametres utilisateur
#########################################################################


#########################################################################
#### parametrage programme

my $ARGS = @ARGV[0];
# nettoyage de la requete
$ARGS =~ s/%([0-9A-F][0-9A-F])/pack("C",oct("0x$1"))/ge;
$ARGS =~ tr/+/ /;
$ARGS =~ s/\///g;
$ARGS =~ s/\.\.//g;
$ARGS =~ s/^\.$//g;
my @ARGS = split(/@@/, $ARGS);
my ($request)=@ARGS;
$request=$password;
#########################################################################
#### main prog


if(($galrep) and ($multirep) and ($password) and ($request==$password)){
    my @rep_work = glob("$instrep/*");
# recuperation des repertoires
    foreach my $rep(@rep_work){
	if (-d $rep){
print "$rep\n";
	    my $command = "$chmod 0777 $rep";
print "  >>> exec: $command\n";
	    system $command;
	    my $line = $rep;
	    $line =~ s/$galrep\///;
	    my $command2 = "echo \"$magick?$line\@\@new\@\@$password\" >> img_inst.sh";
	    system $command2;
	}
	my @file_work = glob("$rep/*");
# recuperation des fichier
	foreach my $file(@file_work){
	    if (-f $file){
print "    $file\n";
	   	 my $command = "$chmod 0666 $file";
print "  >>> exec: $command\n";
	    	 system $command;
	    }
	}
    }
}

print "\n\n [done]\n";
