0byt3m1n1
Path:
/
data
/
11
/
0
/
19
/
129
/
997781
/
user
/
1027887
/
cgi-bin
/
[
Home
]
File: pack.cgi
#! /usr/bin/perl -- #print "Content-Type: text/html \n\n"; use Net::FTP; if ($ARGV[0] !~ /\w/) { print "Content-Type: text/html \n\n"; } use CGI qw(:cgi-lib);&ReadParse; $exclude_file="./pack-excludefiles"; $exclude_dir="./pack-excludedir"; $cust_file="./pack-tmp.files"; open (exclude_file,">$exclude_file");print exclude_file "XXXX\n";close (exclude_file); open (exclude_file,">$exclude_dir");print exclude_file "pack-\n";close (exclude_file); $pfile=$in{'pfile'}; $pmode=$in{'pmode'}; $pdir=$in{'pdir'}; $ptrans=$in{'ptrans'}; $pftphost=$in{'pftphost'}; $pftpuser=$in{'pftpuser'}; $pftppass=$in{'pftppass'}; $pcgipath=$in{'pcgipath'}; ## FORCE SET pcgipath to local dir #$pcgipath=`pwd`;chomp($pcgipath); $pcgipath=$0; $pcgipath=~s/pack.cgi//; $pcgipath=~s/pack-gunzip.cgi//; $pcgipath.="/"; $pcgipath=~s/\/\/$/\//; if ($ARGV[0] =~ /\w/) { $pmode=$ARGV[0]; $pfile=$ARGV[1]; $pdir=$ARGV[2]; $ptrans=$ARGV[3]; $pftphost=$ARGV[4]; $pftpuser=$ARGV[5]; $pftppass=$ARGV[6]; $pcgipath=$ARGV[7]; } $perlmakedir=1; $ftpdebug=0; #$cmd=`pwd`; #print "direct command would be<br><b>perl pack.cgi $pmode $pfile $pdir $ptrans $pftphost $pftpuser $pftppass</b><br>\n"; #print "dir - $pdir<hr>"; #print "curr dir - $cmd<hr>"; if ($pmode eq "unpackftp") { $ftp = Net::FTP->new($pftphost, Debug => $ftpdebug); $ftp->login($pftpuser,$pftppass); print "Created Object!\n"; #exit; } ## TEST FOR PERMISSIONS if ($pmode eq "unpackftp") { $extrapermissions=0; $testdir=$pdir."smctmp"; $testfile="./smctmp/test"; #my $ftp = Net::FTP->new($pftphost, Debug => $ftpdebug); #$ftp->login($pftpuser,$pftppass); print "Creating $testdir and $testfile\n"; #exit; #$ftp->rmdir($testdir,1); $ftp->mkdir($testdir); $ftp->site("chmod 755 $testdir"); open(testfile,">$testfile"); print testfile "1"; close (testfile); if (!(-e $testfile)) {$extrapermissions=1} if (-e $testfile) { unlink($testfile); } if ($extrapermissions) {$ftp->site("CHMOD 777 $testdir");print "\n\n\n Setting 777 to $testdir\n\n\n";} #$ftp->rmdir($testdir); #$ftp->close; #exit; print "Need extra permissions?? - $extrapermissions<hr>"; } ## MAKE A GUNZIP REQUIRE FILE IF NEEDED ## NONE FOR THIS FILE if (($ARGV[0] !~ /\w/) and ($pfile !~ /\w/)) { print "Usage:\n\nperl pack.cgi MODE FILE DIR\nperl pack.cgi pack packfile.pck .\n\nBe sure to use ./ for directory if packing current directory!!!"; } if ($pmode =~ /unpack/) { print "Running UNPACK mode\n\n<br>"; open (pfile,"<$pfile"); binmode(pfile); while (<pfile>) { $alllines[$index]=$_; $index++; $maxlines++; } close(pfile); print "Opening file - $pfile\n"; ## UNPACK foreach ($readline=0;$readline<=$#alllines;$readline++) { $thisline=$alllines[$readline]; if ($thisline =~ /^\#\#COMMAND/) { $readline++; $realcommand=$alllines[$readline]; &Trun(*realcommand); #print "comm - $realcommand\n"; if (($realcommand eq "mkdir")) { $readline++; $realdir=$alllines[$readline]; &Trun(*realdir); $readline++; $dump=$alllines[$readline]; if ($ptrans =~ /\w/) {$realdir=~s/9800/$ptrans/g;} if ($perlmakedir eq "1") { $done=0; if ((($extrapermissions) and ($realdir =~ /data|inventory|wizard|udat|log|lock|session|backup|smc_launch/)) or (($realdir =~ /inventory|wizard/))) { #my $ftp = Net::FTP->new($pftphost, Debug => $ftpdebug); #$ftp->login($pftpuser,$pftppass); $fulldir="$pdir$realdir"; $ftp->mkdir($fulldir); $ftp->site("CHMOD 777 $fulldir"); #$ftp->logout; print "Making dir with 777 - $fulldir\n<br>"; $done=1; } if (((!($extrapermissions)) or (($realdir !~ /data|inventory|wizard|udat|log|lock|session|backup|smc_launch/))) and ($done eq "0")) { $fulldir="$pdir$realdir"; $ftp->mkdir($fulldir); $ftp->site("CHMOD 755 $fulldir"); #$ftp->close; print "Making dir - $fulldir\n<br>"; } } #exit; } if (($realcommand eq "mkfile") and ($pmode eq "unpack")) { $readline++; $realfile=$alllines[$readline]; &Trun(*realfile); $readline++; $realfilemode=$alllines[$readline]; &Trun(*realfilemode); $readline++; $dump=$alllines[$readline];; $binary=""; if ($ptrans =~ /\w/) {$realfile=~s/9800/$ptrans/g;} #print "real: $realfile\n"; $completedir="$pdir$realfile"; @allparts=split(/\//,$completedir); $changedir=""; for ($part=0;$part<$#allparts;$part++) { if ($part>0) {$changedir.="/".$allparts[$part]} } $actualfile=$allparts[$#allparts]; chdir($changedir); if ($changedir =~ /\w/) { open (newfile,">$actualfile"); if ($realfilemode eq "binary") {$binary="binary ";binmode(newfile)} print "Change to directory - $changedir Creating $binary $actualfile\n<br>"; for ($makefile=$readline;$makefile<=$#alllines;$makefile++) { $readline++; if ($alllines[$readline] =~ /^\#\#EOL/) {close (newfile);goto EXIT;} $alllines[$readline]=~s/\#\#EOL//g; print newfile $alllines[$readline]; } } } if (($realcommand eq "mkfile") and ($pmode eq "unpackftp")) { $readline++; $realfile=$alllines[$readline]; &Trun(*realfile); $readline++; $realfilemode=$alllines[$readline]; &Trun(*realfilemode); $readline++; $dump=$alllines[$readline];; $binary=""; if (($ptrans =~ /\w/)) {$realfile=~s/9800/$ptrans/;} #print "real: $realfile\n"; $completedir="$pdir$realfile"; @allparts=split(/\//,$completedir); $changedir=""; for ($part=0;$part<$#allparts;$part++) { if ($part>0) {$changedir.="/".$allparts[$part]} } $actualfile=$allparts[$#allparts]; $actualfile=~s/ /_/g; $completedir=~s/ /_/g; $localfile=$pcgipath."smctmp/$actualfile"; $remotefile="$completedir"; $remotefile=~s/\/\//\//g; #$debug=1; open (newfile,">$localfile"); if ($realfilemode eq "binary") {$binary="binary ";binmode(newfile)} if ($ftpdebug) {print "Prep ftp file dir - local: $localfile remote: $remotefile<br>Creating $binary $actualfile\n<br>";} else {print "$remotefile\n"} for ($makefile=$readline;$makefile<=$#alllines;$makefile++) { $readline++; if (($alllines[$readline] =~ /^\#\#EOL/)) { close (newfile); if (($remotefile !~ /Thumbs|db|txt/) and ($actualfile =~ /^[a-z]/i)) { #print "Setup $binary<br>"; if ($ftpdebug) {print "Uploading file - $localfile - $binary -> $remotefile\n<br>";} #my $ftp = Net::FTP->new($pftphost, Debug => $ftpdebug); #$ftp->login($pftpuser,$pftppass); if ($binary =~ /binary/) {$ftp->binary;} else {$ftp->ascii;} $ftpres=$ftp->put($localfile,$remotefile); if ($ftpdebug) {print "Local file - $localfile - $remotefile<br>";} if ($debug) { open (debugfile,">>file.log"); print debugfile "$remotefile\n"; close (debugfile); } #print "extra permisionns -- $extrapermissions -- $remotefile<br>"; $nochmod=1; if (($extrapermissions) and ($remotefile !~ /\.cgi|\.jpg|\.gif|kioss/)) {$ftp->site("CHMOD 777 $remotefile");;$nochmod=0} if (($remotefile =~ /inventory|wizard/)) {$ftp->site("CHMOD 777 $remotefile");;$nochmod=0} if ($remotefile =~ /kioss/) {$ftp->delete($remotefile)} if (($remotefile =~ /sessions/) and ($remotefile =~ /\.dat/)) {$ftp->delete($remotefile)} if ($remotefile =~ /\.cgi/) {$ftp->site("CHMOD 755 $remotefile");$nochmod=0} if (($extrapermissions) and ($remotefile =~ /smc-setup/)) {$ftp->site("CHMOD 777 $remotefile");;$nochmod=0} if ($nochmod) {$ftp->site("CHMOD 644 $remotefile");} #$ftp->close; } unlink($localfile); #print "Uploaded - $ftpres - $localfile\n"; goto EXIT; } #if (($alllines[$readline] !~ /\w/) and ($readline eq $#alllines)) {print "Exiting..\n";goto EXIT} $alllines[$readline]=~s/\#\#EOL//g; print newfile $alllines[$readline]; #print "Writing line $alllines[$readline]<br>\n"; if ($readline>$maxlines) {goto FULLSTOP} } } EXIT: } } FULLSTOP: #my $ftp = Net::FTP->new($pftphost, Debug => 1); #$ftp->login($pftpuser,$pftppass); $ftp->rmdir($testdir); $ftp->quit; print "Done unpacking..\n"; } ########## SUBS ########## DO NOT MODIFY BELOW THIS LINE - SMC TECHNOLOGIES ALL RIGHTS RESERVED 2004 sub Trun { local (*in_data)=@_; $one=chr(10);$two=chr(13);$in_data=~s/$one//;$in_data=~s/$two//; return(*in_data); } unlink($exclude_file); unlink($exclude_dir); unlink($cust_file); #unlink("./pack-gz.cgi"); exit;