From e9192b3d42660a5781101df4357d276318151e8a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:14:41 -0500 Subject: cgi-bin & lib --- cgi-bin/services_f | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 cgi-bin/services_f (limited to 'cgi-bin/services_f') diff --git a/cgi-bin/services_f b/cgi-bin/services_f new file mode 100755 index 0000000..ba51e4d --- /dev/null +++ b/cgi-bin/services_f @@ -0,0 +1,83 @@ +#!/usr/bin/perl +######################################### +# services_f +# feeds bPod the file list for a valid thread +######################################### + +use localbucky; + +$dbh = DBI->connect ($dsn); + +our $KWAREZ = $BUCKY_CONFIG->{BPOD_SERVICES_WAREZ_DIR}; + +our ($USER, $lastlog) = checkin(); + +our $logged_in = ($USER != -1); + +# this start/end shit is all broken anyway +#my $start = $input->{s}; +#my $end = $input->{e}; +my $pid = $input->{pid}; + +print "Content-type: text/html\r\n\r\n"; + +my $thread = get_thread( $pid ); +my $keyword = get_keyword( $thread->{keyword} ); +exit unless check_privacy( $thread, $keyword ); + +my $files = get_files( $pid ); + +my $numItems = @$files; + +my $returnString = " &numItems=" . ($numItems ); + +@$files = sort{ lc($a->{filename}) cmp lc($b->{filename}) } @$files; + +my $fileCount = 0; +foreach my $file_row (@$files) + { + $returnString .= "&filetype$fileCount=" . fileEXT($file_row->{filename}); + $returnString .= "&filename$fileCount=" . lc($file_row->{filename}); + $returnString .= "&username$fileCount=" . $file_row->{username}; + $returnString .= "&date$fileCount=" . $file_row->{date}; + $returnString .= "&url$fileCount=" . $KWAREZ . $file_row->{thread} ."/". spaceReplace($file_row->{filename}); + $returnString .= "&size$fileCount=" . sizeinK($file_row->{size}); + $fileCount++; + } +print $returnString ; + +exit; + +sub fileEXT + { + my $filename = shift; + $filename =~ s/.+\.//; + return uc($filename); + } +sub spaceReplace + { + my $filename = shift; + $filename =~ s/\ /\%20/g; + return $filename; + } +sub sizeinK + { + my $bytes = shift; + my $size = $bytes / 1024; + if ( $size < 1024 ) + { + $size = sprintf "%2.2f", $size; + $size .= "k"; + } + elsif ( $size / 1024 < 1024 ) + { + $size = sprintf "%2.2f", $size / 1024; + $size .= "mb"; + } + elsif ( $size / 1024 / 1024 < 1024 ) + { + $size = sprintf "%2.2f", $size / 1024 / 1024; + $size .= " GB"; + } + return $size; + } -- cgit v1.2.3-70-g09d2