head	1.2;
access;
symbols;
locks
	root:1.2; strict;
comment	@# @;


1.2
date	2026.09.29.10.38.20;	author root;	state Exp;
branches;
next	1.1;

1.1
date	2025.12.27.10.05.06;	author root;	state Exp;
branches;
next	;


desc
@mix of original and new. about to delete the old sub routines that handled renderiing the list of articles. use a recursing method of discovering directories and going into them and listing files.
-bert
@


1.2
log
@as i found it.
-bert
@
text
@#!/usr/bin/perl

### index.cgi
### This is the index.cgi which is found at /var/www/www.rcflightpath.com/articles all others should link to it.

use lib qw (/var/www/www.rcflightpath.com/lib);
use POSIX qw(strftime);
use CGI qw(:standard :html3 :all *table *Tr *td unescape);
use CGI::Cookie;
use Templates::Navbar;
use Templates::Header;
use Templates::Footer;

$mode       = param('mode');
$file       = param('file');
$user_agent = user_agent();
$basedir    = '/var/www/www.rcflightpath.com';
$filepath   = $basedir.'/articles/index.cgi';
$keywords   = 'KEYWORDS HERE';
$page_desc  = 'PAGE DESCRIPTION HERE';
$domain     = 'www.rcflightpath.com';

if ($file =~ /\,v$/) {
  ($o_file) = split/\,/,$file;
  print "requested: $file\n";
  $o_file =~ s/\/RCS//;
  print "likely: $o_file\n";
  $o_file =~ s/^\///;
  print "url: http://$domain/$o_file\n";
  @@rpath = split/\//,$o_file;
  $filename = pop(@@rpath);
# print "file: $filename\n";
  chomp (@@search = `/usr/bin/find $basedir/articles | grep $filename`);
# print "search: @@search\n";
  foreach (@@search) {
    next if ($_ =~ /\/old|\,v$/);
    $possible++;
    $elected = $_;
  }
  $basedir =~ s/\//\\\//g;
  $elected =~ s/$basedir//;
  if ($possible) {
#   print "possible($possible): $elected\n";
#   print "final url: https://$domain/$elected\n";
    $redirect = "https://$domain/$elected";
  } else {
    $final_path =  join ('/',@@rpath);
#   print "possible($possible): https://$domain/$final_path\n";
    $redirect = "https://$domain/$final_path";
  }
  Header::print_redirect2($title,'0',$redirect);
  exit;
} elsif ($file) {
  @@path = split/\//,$file;
  $filename = pop(@@path);
  @@filename = split/\./,$filename;
  $filename = shift(@@filename);
  $filename =~ s/\_/ /g;
  $title    = $filename;
  if (-e "$basedir$file") {
    open (FILE,"$basedir$file");
    while (<FILE>) {
      $standalone++ if ($_ =~ /DOCTYPE\s+html/);
      last if (! $standalone);
      print;
    }
    close FILE;
    exit if ($standalone);
  }
} else {
  $cwd_path = `pwd`;
  @@path = split/\//,$cwd_path;
  $last = pop(@@path);
  $last =~ s/\b(\w)/\U$1/g;
  $title    = $last;
}
chomp $title;

charset('UTF-8');

$|=1;

if (-e 'style.css') {
  $style = 'style.css';
} elsif (-e '../style.css') {
  $style = '../style.css';
} else {
  $style = '/style.css';
}

Header::print_header($title,$style,$page_desc,$keywords);

print '   ',start_table({-border=>0,-margin=>0,-topmargin=>0,-cellpadding=>0,-cellspacing=>0,-width=>900}),"\n    ",
       start_Tr,"\n     ",
        start_td({-colspan=>2}),"   ";
Header::print_titlebar($title,$filepath,'FFFFFF');
print  "\n    ",end_td,"\n   ",
       end_Tr,"\n   ",
       start_Tr,"\n    ",
        start_td({-valign=>'top',-width=>'150',-rowspan=>2});
Navbar::default2('sections','webapps','info','resources');
print   "\n   ",end_td,"\n   ",
        start_td({-valign=>'top'}),
        "\n    ",div({-id=>'main'}),
        "\n<!-- START CONTENT -->\n     ";

if ($mode eq 'open') {
  &open;
} else {
  &print_content;
}

print   end_td,"\n ",
       end_Tr,"<!-- END CONTENT -->\n ",
      end_table,"<!-- END MAIN TABLE -->\n";
Footer::print_footer;
print end_html;

sub open {
  #my $ref = $ENV{'HTTP_REFERER'};
  my $ref = '.';
  print a({-href=>$ref},'<< Back'),br;
  my $filepath = $basedir.'/'.$file;


  if ($file =~ /\/RCS\//) {
    print 'here';
  } elsif ($file =~ /\.pdf/) {

    $filepath =~ s/\/var\/www\/www.rcflightpath.com\///;
    print "<p><embed src=\"$filepath\" type=\"application/pdf\" width=700 height=650>";

  } elsif ($file =~ /\.yt/) {

    open (YT,"$basedir$file");
    chomp ($data = <YT>);
    close YT;
    if ($data =~ /\&/) {
      ($yt_id,$all_opts) = split/\&/,$data;
      $all_opts =~ m/(t\=\d+s)/;
      $time = $1;
      $time =~ s/^t\=//;
      $time =~ s/s$//;
      print "<iframe border=0 width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$yt_id?&autoplay=0&mute=0&start=$time\" title=\"YouTube video player\" frameborder=\"2\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen></iframe>";
    } else { 
      $yt_id = $data;
      print "<iframe border=0 width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$yt_id?&autoplay=0&mute=0\" title=\"YouTube video player\" frameborder=\"2\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen></iframe>";
    }

  } else {
    print '<pre>' if ($file =~ /\.txt/);
    if (-d $filepath) {
      chdir "$basedir$file";
      @@ls = <*>;
      print h3("$file Directory Contents:");
      print '<ul>';
      foreach $ls(@@ls) {
        next if (($ls eq 'RCS')||($ls eq 'DB')||($ls eq 'recycle_bin')||($ls eq 'lib')||($ls eq 'test')||($ls eq 'tmp')||($ls eq 'static')||($ls eq 'uploads')||($ls eq 'templates')||($ls eq 'invoices')||($ls eq 'clients')||($ls eq 'downloads')||($ls eq 'analytics')||($ls eq 'bkp')||($ls eq 'db'));
        next if ($ls =~ /\.(pl|php|xml|css|ico|js|inv|pay|cfg|cgi|gz|tar|tbz|disabled|rating|gtag)$/);
        print "<li><a href=/articles/new.cgi?mode=open&file=$file/$ls>$ls</a></li>\n";
      }
      print '</ul>';
    } elsif (-e $filepath) {
      if ($filepath =~ /(\.html|\.txt)/) {
        open (CONTENT,$filepath);
        my $flag;
        while (<CONTENT>) {
          print if ($flag);
          $flag = 1 if ($_ =~ /\<body\>/);
          push (@@backup,$_);
        }
        close CONTENT;
        if (!$flag) {
          foreach (@@backup) {
            print;
          }
        }
      } else {
        $filepath =~ s/$basedir(\/)?//;
        print (img{-src=>$filepath});
      }
    } else {
      print h1("Sorry, no such file: $filepath");
    }
    print '</pre>' if ($file =~ /\.txt/);
  }
}

sub print_content {
  my $pwd = `/usr/bin/pwd`; chomp $pwd;
  my $cwd = '/var/www/www.rcflightpath.com';
  $pwd =~ s/$cwd//;
  if ($pwd eq '/articles') {
    print h2('RC FlightPath Article Repository (Root Directory)'),p;
  } else {
    print a({-href=>'..'},"<< Back"),br,"\n     ";
    print h2("$pwd Contents:"),p;
  }
  &recurse($pwd,$pwd);
  print "<br><font color=FFCC00>$count total files/dirs</font>";
}

sub recurse {
  my $tgt = shift;
  my $prv = shift;
  my $cwd = `/usr/bin/pwd`; chomp $cwd;
  my $rwd = $cwd;
     $rwd =~ s/\/var\/www\/www\.rcflightpath\.com//;
  $nest++;
  print "\n<!-- Nest=$nest -->\n";
  chdir $tgt;
  print "<ul>";
  foreach $file(<*>) {
    $count++;
    chomp;
    next if (($file eq 'admin')||($file eq 'backups')||($file eq 'index.cgi')||($file eq 'RCS')||($file eq 'images'));
    next if (($file =~ /^(old|style|prev)/)||($file =~ /(disabled|private)/)||($file =~ /(\.(db|tgz|pl))$/));
    if (-d $file) {
      if ($rwd eq $prv) {
        print li("<font color=#F5BB27>Topic:</font> <a href=$rwd/$file>$file articles</a>:");
      } else {
        print li("<font color=#F5BB27>Topic:</font> <a href=$rwd/$prv/$file>$file articles</a>:");
      }
      &recurse($file,$file);
    } else {
      ($name,$ext) = split/\./,$file;
      $name =~ s/\_/ /g;
      if ($file =~ /\.(recording|cgi)$/) {
        print li(a({-href=>"$rwd/$file"},$name)); #ZZZzzz
      } elsif ($rwd eq $prv) {
        print li(a({-href=>"$prv/$file"},$name));
      } else {
        print li(a({-href=>"$rwd/$prv/$file"},$name));
      }
    }
  }
  $nest--;
  print "</ul>";
  chdir '..';
}
@


1.1
log
@Initial revision
@
text
@d3 3
a16 1
$filepath   = '/var/www/www.rcflightpath.com/articles/flight_training/index.cgi';
d18 1
d21 1
d23 31
a53 1
if ($file) {
d60 10
d101 1
a101 1
Navbar::default2('sections','webapps','info','resources','checklist');
d126 3
a128 1
  if ($file =~ /\.pdf/) {
d133 1
a133 1
  } else {
d135 14
d150 11
a160 9
  print '<pre>' if ($file =~ /\.txt/);
  if (-e $filepath) {
    if ($filepath =~ /(\.html|\.txt)/) {
      open (CONTENT,$filepath);
      my $flag;
      while (<CONTENT>) {
        print if ($flag);
        $flag = 1 if ($_ =~ /\<body\>/);
        push (@@backup,$_);
d162 9
a170 4
      close CONTENT;
      if (!$flag) {
        foreach (@@backup) {
          print;
d172 9
d183 1
a183 2
      $filepath =~ s/$basedir(\/)?//;
      print (img{-src=>$filepath});
d185 1
a185 2
  } else {
    print h1("Sorry, no such file: $filepath");
a186 4
  print '</pre>' if ($file =~ /\.txt/);

  }

d193 6
a198 1
  print a({-href=>'..'},"<< Back"),br,"\n     ";
a202 9
sub print_content2 {
  my $pwd = `/usr/bin/pwd`; chomp $pwd;
  my $cwd = '/var/www/www.rcflightpath.com';
  $pwd =~ s/$cwd//;
  print a({-href=>'..'},"<< Back"),br,"\n     ";
  print br,li(b("\"$pwd\" directory contents:")),p,"\n   ";
  &recurse(0,$pwd);
}

d207 4
a210 3
  #print "pwd=$pwd",br;
  #print "cwd=$cwd",br;
  #print "<font color=green>Going to $tgt</font>";
d212 1
a212 1
  print '<ul>';
d217 1
a217 1
    next if (($file =~ /(\.db)$/)||($file =~ /disabled/));
d219 5
a223 1
      print li("<font color=#F5BB27>Topic:</font> $file articles:"),br;
d228 7
a234 4
      $rwd = $cwd;
      $rwd =~ s/\/var\/www\/www\.rcflightpath\.com//;
      #print li(a({-href=>"?mode=open&file=$rwd/$prv/$file"},"$name ($rwd/$prv/$file)")),"\n   ";
      print li(a({-href=>"?mode=open&file=$rwd/$prv/$file"},$name)),"\n   ";
d237 2
a238 1
  print "<br></ul>\n";
a239 31
}

sub recurse2 {
  my $gen = shift; $gen++;
  my $path = shift;
  my @@ls = <*>;
  my $pwd = `/usr/bin/pwd`;
  my $length = scalar(@@ls);
  my $cnt;
  my $space = '&nbsp;';
  print "<UL>\n";
  foreach (@@ls) {
    $cnt++;
    next if (($_ eq 'index.cgi')||($_ eq 'images')||($_ eq 'admin')||($_ =~ /old|\.css|RCS|mkr|backup|bert|disabl|\.prev/i));
    if (-d) {
      print $space x $gen;
      print li(a({-href=>"$path/$_"},"$path/$_")),"\n   ";
      chdir $_ || print "unable to access $obj\n   ";
      &recurse($gen,"$path/$_");
      chdir '..';
    } elsif ($_ =~ /\.cgi/) {
      print p,li(a({-href=>"$path/$_"},"$_ (PERL CGI)")),"\n   ";
    } elsif ($_ =~ /\.recording/) {
      print li(a({-href=>"$path/$_"},"$_ (RealFlight Recording)")),"\n   ";
    } else {
      print "&nbsp;" x $gen;
      print li(a({-href=>"?mode=open&file=$path/$_"},$_)),"\n   ";
    }
#   print "</ul>\n   " if ($cnt == $length);
  }
  print "</UL>\n";
@
