Hi all,
I am having problems getting a perl script to run from the primary (or any other) ibay. I have included the whole program below. For now; the program is a perl script to automatically compress images an create a gallery. (uses Image Magick & nagg)
The problem is this: The program works when run from the command line -perfectly.
When run from the cgi-bin of an ibay, I get this error in the logs:
[Mon Jan 29 22:40:48 2007] [error] [client 192.168.1.194] /usr/bin/convert: error while loading shared libraries: libdpstk.so.1: cannot open shared object file: No such file or directory
OK, so it's just an ENV thing like the PATH, or something similar right?
Also, when I use a suid "C wrapper" that I wrote around it:
like this: "c-wrapper?make_gallery_and_compress.pl", I get this:
[Mon Jan 29 22:42:00 2007] [error] [client 192.168.1.194] make_gallery_and_compress.pl: line 3: use: command not found
There are a few lines for this error in the logs, but it exactly like the error you get when the "path to perl" at the top is wrong, the line quoted that generates the error is "use strict;" - bummer.
So, I should mention that running similar perl scripts, and also using the "C wrapper" in this way, works perfectly on many other Straight CentOS 4.3 boxes that I have installed. So proof of concept there.
What the hell is going wrong here, it almost seems as though the script gets put in a chrooted jail, without the corresponding libs...
Anyway, any help is greatly appreciated. TIA
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my @gallery_base_dir = ( "/home/e-smith/files/ibays/web/files/dev/GALLERY_MAKER" );
my @gallery_dir_list = @gallery_base_dir;
header();
print "\nSearching directories and compressing images:\n\n";
find ( \&wanted, @gallery_base_dir );
my $nagg_result;
my $base_gallery_dir = pop @gallery_dir_list;
print "\nNow creating Galleries\n";
print "Base gallery directory is: $base_gallery_dir\n\n";
foreach my $dir ( @gallery_dir_list ) {
if ( defined($dir) && $dir ne $gallery_base_dir[0] ) {
print "Working on: $dir";
$nagg_result = qx#nagg -d "$dir"#;
if ( $? == 0 ) {
print " -> gallery complete\n"
}
else {
print "$nagg_result\n";
footer_and_exit(172)
}
}
}
print "\nAll processes complete!\n\n";
footer_and_exit();
#=========================================================================================#
sub wanted {
my $convert_result;
my $current_dir = $File::Find::dir;
my $current_file = $_;
my $path_to_file = $current_dir . "/" . $current_file;
my $path_to_new_file = $path_to_file;
unshift @gallery_dir_list, $current_dir unless ( $current_dir eq $gallery_dir_list[0] );
if ( /jp.?g/i ) {
$path_to_new_file =~ s/$/.mod/;
$convert_result = qx#/usr/bin/convert -compress JPEG -quality 30 $path_to_file $path_to_new_file#;
if ( $? != 0 ) {
print "$convert_result\n\n";
footer_and_exit(172)
}
else {
unlink $path_to_file or die "Couldn't delete $path_to_file: $!\n";
rename $path_to_new_file, $path_to_file or die "Couldn't rename $path_to_new_file: $!\n";
print "$path_to_file -> compressed\n";
}
}
}
sub header {
print <<'END_HTML';
Content-Type: text/html
<html>
<body>
<blockquote>
END_HTML
}
sub footer_and_exit {
my $exit_code = shift;
$exit_code = 0 unless defined($exit_code);
print <<'END_HTML';
</blockquote>
</pre> </em>
</body> </HTML>
END_HTML
exit $exit_code;
}