Code cleanups

This commit is contained in:
Jamie Cameron
2017-05-31 18:52:38 -07:00
parent 08a1f3db74
commit 2ee32e71cf

View File

@@ -10,41 +10,44 @@ get_paths();
$archive_type = mimetype($cwd.'/'.$in{'file'});
if ($archive_type =~ /x-bzip/) {
$cmd = "tar xvjfp ".quotemeta("$cwd/$in{'file'}").
" -C ".quotemeta($cwd);
}
elsif ($archive_type =~ /x-tar|\/gzip|x-xz|x-compressed-tar/) {
$cmd = "tar xfp ".quotemeta("$cwd/$in{'file'}").
" -C ".quotemeta($cwd);
}
elsif ($archive_type =~ /x-7z/) {
$cmd = "7z x ".quotemeta("$cwd/$in{'file'}")." -o" .quotemeta($cwd);
}
elsif ($archive_type =~ /\/zip/) {
$cmd = "unzip ".quotemeta("$cwd/$in{'file'}")." -d ".quotemeta($cwd);
}
elsif ($archive_type =~ /\/x-rar/) {
$cmd = "unrar x -r -y ".quotemeta("$cwd/$in{'file'}").
" ".quotemeta($cwd);
}
elsif ($archive_type =~ /(\/x-rpm|\/x-deb)/) {
my $dir = fileparse( "$cwd/$name", qr/\.[^.]*/ );
my $path = quotemeta("$cwd/$dir");
&make_dir($path, 0755);
if ($archive_type =~ /\/x-rpm/) {
$cmd = "(rpm2cpio ".quotemeta("$cwd/$name").
" | (cd ".quotemeta($path)."; cpio -idmv))";
}
else {
$cmd = "dpkg -x ".quotemeta("$cwd/$name")." ".quotemeta($path);
}
}
else {
&error($text{'extract_etype'});
}
if ( index( $archive_type, "x-bzip" ) != -1 ) {
&backquote_logged( "tar xvjfp " . quotemeta("$cwd/$in{'file'}") . " -C " . quotemeta($cwd) );
&redirect("index.cgi?path=".&urlize($path));
}
elsif (index( $archive_type, "x-tar" ) != -1
|| index( $archive_type, "/gzip" ) != -1
|| index( $archive_type, "x-xz" ) != -1
|| index( $archive_type, "x-compressed-tar" ) != -1 )
{
&backquote_logged( "tar xfp " . quotemeta("$cwd/$in{'file'}") . " -C " . quotemeta($cwd) );
&redirect("index.cgi?path=".&urlize($path));
}
elsif ( index( $archive_type, "x-7z" ) != -1 ) {
&backquote_logged( "7z x " . quotemeta("$cwd/$in{'file'}") . " -o" . quotemeta($cwd) );
&redirect("index.cgi?path=".&urlize($path));
}
elsif ( index( $archive_type, "/zip" ) != -1 ) {
&backquote_logged( "unzip " . quotemeta("$cwd/$in{'file'}") . " -d " . quotemeta($cwd) );
&redirect("index.cgi?path=".&urlize($path));
}
elsif ( index( $archive_type, "/x-rar" ) != -1 ) {
&backquote_logged( "unrar x -r -y " . quotemeta("$cwd/$in{'file'}") . " " . quotemeta($cwd) );
&redirect("index.cgi?path=".&urlize($path));
}
elsif ( index( $archive_type, "/x-rpm" ) != -1 || index( $archive_type, "/x-deb" ) != -1 ) {
my $dir = fileparse( "$cwd/$name", qr/\.[^.]*/ );
my $path = quotemeta("$cwd/$dir");
&backquote_logged("mkdir $path");
if ( index( $archive_type, "/x-rpm" ) != -1 ) {
&backquote_logged(
"(rpm2cpio " . quotemeta("$cwd/$name") . " | (cd " . $path . "; cpio -idmv))" );
}
else {
&backquote_logged( "dpkg -x " . quotemeta("$cwd/$name") . " " . $path );
}
}
# Run the extraction command
$out = &backquote_logged("$cmd 2>&1 >/dev/null </dev/null");
if ($?) {
&error(&html_escape($out));
}
&redirect("index.cgi?path=".&urlize($path));