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


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

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


desc
@original and works. as I found it.
-bert
@


1.2
log
@about to check in this version and update with a whole new version.
-bert
@
text
@#!/usr/bin/perl

use POSIX qw(strftime);
use CGI qw(:standard :html3 :all *table *Tr *td);

$user_agent = user_agent();
my $mode = param('mode');
my $all = param('all');
my $profiles = param('profiles');
my $rates = param('rates');
$logo_font2 = 'FFB400';
$page_desc = 'RotorFlight configuration checker';
$auc = $ftc = $bsc = '5D5C61';
$debug = 1;
$basedir = '/var/www/www.rcflightpath.com/heli/configs';
$cgipath = "$basedir/index.cgi";

charset('UTF-8');

print header;

if (-e 'style.css') {
  $style = "$basedir/style.css";
} else {
  #$style = '/var/www/www.rcflightpath.com/style.css';
  $style = '/style.css';
}

print  start_html(
          -title => "$title",
          -style => {'src' => $style},
          -meta=> {'viewport'=>'width=device-width, initial-scale=1.0','description'=>$page_desc}
        );

print "<!-- Google tag (gtag.js) -->
      <script async src='https://www.googletagmanager.com/gtag/js?id=G-3D6XXHE4VQ'></script>
      <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'G-3D6XXHE4VQ');
      </script>";

# TOP TITLE AREA

  my $mod_time = (stat($cgipath))[9];
  my ($sec, $min, $hour, $mday, $mon, $year) = localtime($mod_time);

  @@months = qw /null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
  $mon++;  # Adjust month (0-based index)
  $year += 1900;  # Adjust year (start from 1900)
  $ampm = 'a.m.';
  $ampm = 'p.m.' if ($hour > 11);
  $hour = "0$hour" if ($hour < 11);
  $min  = "0$min"if ($min < 11);

  print start_table({-border=>0,-cellpadding=>0,-cellspacing=>0,-topmargin=>0,-width=>800}), # MAIN TABLE
          start_Tr,
            start_td({-colspan=>2,-bgcolor=>'#5D5C61'}),
              div({-id=>'title'},
                center(
                  table({-border=>0,-width=>'100%',-background=>'/images/bg.png'}, # TITLE TABLE
                    Tr(
                      td({-align=>'center',-width=>300},
                        img({-border=>0,-height=>143,-width=>300,src=>'/images/logo6.png'})),
                      td({-align=>'center'},
                        h1("<b><font color=white>RC</font> <font color=$logo_font2>FlightPath</font></b>"),
                        h2($title),
                        font({-color=>'white'},"Last updated: $months[$mon] $mday, $year @@ $hour:$min $ampm"),
                      ),
                    )
                  )
                ),
              ),
            end_td, 
          end_Tr;

# LEFT SIDE NAVIGATION

  print   start_Tr,
            start_td({-valign=>'top',-bgcolor=>'#B1A296'}), # NAVBAR HERE
              "<div id='navigation'>\n",
              "<ul>",
              "    <li><a href='/articles/pid-tuning/rotorflight'><font color=$auc><b>RotorFlight Blackbox Tuning</b></font></a></li>",p,"\n",
              "  </ul>","\n",
              "</div>\n\n";
            end_td,




# MAIN PAGE SECTION

  print start_td({-bgcolor=>'#EEE2DC',-valign=>'top'}),
        "<div id='main'>\n";

  &print_content;

  print "</div>\n",
        end_td,"\n",
        end_Tr,"\n",
        end_table,"\n";

  &print_footer;

  print end_html;

sub print_footer {
  print br,br,'<footer>',
    start_table({-border=>0}),
      start_Tr,
        start_td,
          font({-size=>'-1'},"DBUG: mode=$all $rates $profiles"),
        end_td,
      end_Tr,
      start_Tr,
        '&nbsp;',
      end_Tr,
      start_Tr,
        start_td({-align=>'center'}),
          font({-size=>'-1'},'&copy; 2024 RC FlightPath RC Flight Training & Build Services | San Fernando Valley, CA'),
        end_td,
      end_Tr,
    end_table,
  '</footer>';
}

sub print_content {
  if ($mode eq 'submit') {

    $dump = param('dump');

    if ($dump !~ /(\.(txt|dmp))$/) {
      print font({-color=>'red'},'Error: You accidentally selected an invalid file. Please hit your "Back" button and try again');
    } elsif ($dump) {
        $upload_dir = '/var/www/www.rcflightpath.com/heli/configs/RotorFlight/tmp';
        $query = new CGI;
        $upload_filehandle = $query->upload("dump");
        $info = $dump;
        $info =~ s/^RTFL_cli_//;
        $info =~ s/(\d+_\d+\.txt$)//;
        $timestamp = $1; $timestamp =~ s/\.txt$//;
        $model = $info;
        $model =~ s/_$//;
        ($date,$time) = split/\_/,$timestamp;
        $time =~ /(\d{2})(\d{2})(\d{2})$/;
        $hour = $1;
        $min = $2;
        $sec = $3;
        $date =~ /(\d{4})(\d{2})(\d{2})$/;
        $year = $1;
        $month = $2;
        $day = $3;
        print b("Model: $model",br,"Date: $month/$day/$year",br,"Time: $hour:$min"),p;
        open UPLOADDUMP, ">$upload_dir/$dump";
        while ( <$upload_filehandle> ) {
          if ($_ =~ /^\#/) {
            (undef,$index,$arg) = split /\s+/;
          }
          $c = length($_);
            if ($all) {
              if ($c > 2) {
                print "($index $arg) $_",br
              } else {
                print $_,br
              }
            } elsif ($profiles) {
              if (($index =~ /^profile/)&&($_ =~ /gain/)) {
                $_ =~ s/^set\s+//;
                ($key,$val) = split/\=/;
                $profile_index = $index.$arg;
#               if ($profile_index ne $profile_index_prev) {
#                 print b($profile_index),br;
#               }
                $$profile_index{$key} = $val;
                #print "storing $key = $val into $profile_index",br;
                $profile_index_prev = $profile_index;
              }
            } elsif ($rates) {
              if ($index =~ /^rateprofile/) {
                $_ =~ s/^set\s+//;
                ($key,$val) = split/\=/;
                $rateprofile_index = $index.$arg;
#               if ($rateprofile_index ne $rateprofile_index_prev) {
#                 print b($rateprofile_index),br;
#               }
                $$rateprofile_index{$key} = $val;
                #print "storing $key = $val into $rateprofile_index",br;
                $rateprofile_index_prev = $rateprofile_index;
              }
            } else {
            }
          print UPLOADDUMP;
        }
        close UPLOADDUMP;

        if ($all) {
        } elsif ($profiles) {
          @@profiles = qw /profile0 profile1 profile2 profile3 profile4 profile5/;
          print start_table({-border=>1,-cellpadding=>15});
          print start_Tr;
          print th({-bgcolor=>'9d9ef3'},'Profile');
          for $db(@@profiles) {
            $pname = $db;
            $pname =~ s/(\d+)//;
            $pnum = $1;
            $pnum++;
            print th({-bgcolor=>'9d9ef3'},$pnum);
          }
          print end_Tr;
          print start_Tr;
          foreach (sort keys %profile0) {
            print start_Tr;
            print td({-bgcolor=>'cdf39d'},$_);
            for $db(@@profiles) {
              if (($$db{$_} ne $val_prev)&&($val_prev)) {
                print td({-bgcolor=>'d4af7d'},$$db{$_});
              } else {
                print td($$db{$_});
              }
              $val_prev = $$db{$_};
            }
            undef $val_prev;
            print end_Tr;
          }
          print end_table;
        } elsif ($rates) {
          @@rateprofiles = qw /rateprofile0 rateprofile1 rateprofile2 rateprofile3 rateprofile4 rateprofile5/;
          print start_table({-border=>1});
          print start_Tr;
          print th({-bgcolor=>'9d9ef3'},'Rate Profile');
          for $db(@@rateprofiles) {
            $pname = $db;
            $pname =~ s/(\d+)//;
            $pnum = $1;
            $pnum++;
            print th({-bgcolor=>'9d9ef3'},$pnum);
          }
          print end_Tr;
          print start_Tr;
          foreach (sort keys %rateprofile0) {
            print start_Tr;
            next if ($_ =~ /^\#/);
            print td($_);
            for $db(@@rateprofiles) {
              if (($$db{$_} ne $val_prev)&&($val_prev)) {
                print td({-bgcolor=>'d4af7d'},$$db{$_});
              } else {
                print td($$db{$_});
              }
              $val_prev = $$db{$_};
            }
            undef $val_prev;
            print end_Tr;
          }
          print end_table;
        } elsif ($rates) {
        } else {
        }


    } else {
      print font({-color=>'red'},'Error: You need to choose a file to use this program. Please hit your "Back" button and try again');
    }


  } else {
    print h3('RotorFlight Config Profile Comparison'),p,
          strong('Instructions:'),br,
          'Use this tool for quickly finding a difference between the <b>Profiles</b> or <b>Rates</b> in your RotorFlight config files:',
          hr,
          start_form({-action=>'index.cgi',-method=>'post',-enctype=>'multipart/form-data'}),
          start_table({-border=>1}),
           start_Tr,
            start_td({-colspan=>2}),
             '1. Choose your RotorFlight Config (Dump file): ',
            end_td,
            start_td({-colspan=>3}),
             input({-type=>'file',-name=>'dump'}),br,
            end_td,
           end_Tr,
           start_Tr,
            start_td({-colspan=>2}),
             '2. Choose the Display Type: ----->>>',
            end_td,
            start_td({-colspan=>2}),
             hidden({-value=>'submit',-name=>'mode'}),
              table({-border=>1},
               Tr(td(input({-type=>'submit',-name=>'all',-value=>'Show All'}))),
               Tr(td(input({-type=>'submit',-name=>'profiles',-value=>'Profiles Only'}))),
               Tr(td(input({-type=>'submit',-name=>'rates',-value=>'Rates Only'}))),
              ),
             end_form,
            end_td,
           end_Tr,
          end_table;
  }
}
@


1.1
log
@Initial revision
@
text
@d108 20
d139 16
a154 2

        print b($dump),p;
a297 22
}

sub print_footer {

  print br,br,'<footer>',
    start_table({-border=>0}),
      start_Tr,
        start_td,
          font({-size=>'-1'},"DBUG: mode=$all $rates $profiles"),
        end_td,
      end_Tr,
      start_Tr,
        '&nbsp;',
      end_Tr,
      start_Tr,
        start_td({-align=>'center'}),
          font({-size=>'-1'},'&copy; 2024 RC FlightPath RC Flight Training & Build Services | San Fernando Valley, CA'),
        end_td,
      end_Tr,
    end_table,
  '</footer>';

@
