]> lifelog.hopto.org Git - LifeLog.git/commitdiff
dev.
authorWill Budic <redacted>
Wed, 20 Sep 2023 00:20:11 +0000 (10:20 +1000)
committerWill Budic <redacted>
Wed, 20 Sep 2023 00:20:11 +0000 (10:20 +1000)
.gitignore
htdocs/cgi-bin/CNFServices.cgi
htdocs/cgi-bin/images/Wedges-9.1s-64px.png [new file with mode: 0644]
htdocs/cgi-bin/login_ctr.cgi
htdocs/cgi-bin/system/modules/CNFDateTime.pm
htdocs/cgi-bin/system/modules/CNFNode.pm
htdocs/cgi-bin/system/modules/CNFParser.pm
htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm
htdocs/cgi-bin/wsrc/feeds.js [new file with mode: 0644]
lighttpd.conf

index bbd220e9b06ef49b7019c17de875a448f0779b19..eafc9f98b72af39bd5e5902499dbc6b23fe3daee 100644 (file)
@@ -26,3 +26,4 @@ dbLifeLog/current_theme
 lighttpd.conf
 dump_*
 *.rdf
+tree_*.cnf
index 9a83aa47aa8c6f3b82559d5a537ce5bd38510050..b76e8fde747083e9ddb4e316e37e01a364656fac 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env perl
-#
+# CNF Services operator. The plugins and services themselve should return html.
+# Idea is that this CGI file contains the actuall CNF to interact in realtime with a web page.
 #
 use v5.30;
 use strict;
@@ -8,6 +9,7 @@ use Exception::Class ('CNFHTMLServiceError');
 use Syntax::Keyword::Try;
 use CGI;
 use CGI::Session '-ip_match';
+no warnings qw(experimental::signatures);
 use feature qw(signatures);
 ##
 # We use dynamic perl compilations. The following ONLY HERE required to carp to browser on
@@ -33,15 +35,12 @@ our $script_path = $0; $script_path =~ s/\w+.cgi$//;
 exit &CNFHTMLService;
 
 sub CNFHTMLService {
-    my ($cgi,$ptr)   = (CGI -> new(),undef); $cgi->param('service', 'feeds');
+    my ($cgi,$ptr)   = (CGI -> new(),undef);
     my  $cnf  = CNFParser -> new (undef,{ DO_ENABLED => 1, HAS_EXTENSIONS=>1, ANONS_ARE_PUBLIC => 1, CGI=>$cgi });
         $cnf->parse(undef,_getServiceScript($cgi));
         $ptr = $cnf->data();
         $ptr = $ptr->{'PAGE'};
     say $$ptr if $ptr;
-    # open my $fh, ">dump_of_output_to_browser.html";
-    # print $fh $$ptr;
-    # close $fh;
     return 0
 }
 
@@ -55,6 +54,15 @@ sub _getServiceScript($cgi) {
 
 sub _CNF_Script_For_Feeds {
 <<__CNF_IS_COOL__;
+<<@<%LOG>
+            file      = web_server.log
+            # Should it mirror to console too?
+            console   = 0
+            # Disable/enable output to file at all?
+            enabled   = 0
+            # Tail size cut, set to 0 if no tail cutting is desired.
+            tail      = 1000
+>>
 <<PROCESS_RSS_FEEDS<PLUGIN>
 
     RUN_FEEDS = yes
@@ -78,8 +86,15 @@ sub _CNF_Script_For_Feeds {
 || The more rows have here the longer it takes to fetch them, what is it, once a day, week, month?
 <<    RSS_FEEDS     <DATA>
 ID`Name`URL`Description~
-01`CPAN`http://search.cpan.org/uploads.rdf`CPAN modules news and agenda.~
+#`CPAN`http://search.cpan.org/uploads.rdf`CPAN modules news and agenda.~
+#`The Perl Foundation RSS Feed`https://news.perlfoundation.org/rss.xml`The Perl Foundation is dedicated to the advancement
+of the Perl programming language through open discussion, collaboration, design, and code.
+ The Perl Foundation is a non-profit organization* based in Holland, Michigan~
+#`Perl Weekly`https://perlweekly.com/perlweekly.rss`A free, once a week e-mail round-up of hand-picked news and articles about Perl.
+The Perl Weekly ( http://perlweekly.com/ ) is a newsletter including links to blog posts and other news items
+ related to the Perl programming language.~
 >>
+
 __CNF_IS_COOL__
 }
 
diff --git a/htdocs/cgi-bin/images/Wedges-9.1s-64px.png b/htdocs/cgi-bin/images/Wedges-9.1s-64px.png
new file mode 100644 (file)
index 0000000..7dc4f9a
Binary files /dev/null and b/htdocs/cgi-bin/images/Wedges-9.1s-64px.png differ
index bb42c4e9c5effc37f87b7d672dd6a22dad74e53c..adb7735c3e8cac82f7d45981442d927a05b3c24c 100755 (executable)
@@ -59,7 +59,8 @@ try{
         print $cgi->start_html(
                     -title   => "Personal Log Login",
                    # -BGCOLOR => $colBG,
-                    -script=> [{-type  => 'text/javascript', -src => 'wsrc/main.js'},
+                    -script=> [ {-type  => 'text/javascript', -src => 'wsrc/main.js'},
+                                {-type  => 'text/javascript', -src => 'wsrc/feeds.js'},
                                 {-type => 'text/javascript', -src => 'wsrc/jquery.js'},
                                 {-type => 'text/javascript', -src => 'wsrc/jquery-ui.js'}],
                     -style => [ {-type  => 'text/css', -src => $css},
@@ -117,25 +118,6 @@ HTML
                 <br>
             </div>
             <div id="feeds" class="rz" style="width:60% !important;visibility:hidden">RSS</div>
-            <script>
-            function fetchFeeds(){
-                var pnl = \$('#feeds');
-                pnl.html(
-                '<div><span style="border:1px solid Crimson;padding:5px;"><font color="Crimson"><b>P l e a s e &nbsp;&nbsp;    W a i t  &nbsp;&nbsp;   D a r l i n g !</b></font></span><br><img src="images/WelloffHighlevelAlpinegoat.webp" witdht="85" height="85"></div>'
-                );
-                pnl.show();
-                pnl.css('visibility','visible');
-                \$.post('CNFServices.cgi', {service:'feeds',action:'default'}, displayFeeds).fail(
-                    function(response) {pnl.html("Service Error: "+response.status,response.responseText);pnl.fadeOut(10000);}
-                );
-                //
-            }
-            function displayFeeds(content){
-                var pnl = \$('#feeds');
-                pnl.html(content);
-                pnl.show();
-            }
-            </script>
           );
 
     Settings::printDebugHTML($DBG) if Settings::debug();
index 966cb77f0e787943b87f1fa6f9d0b103408b9d58..fbc49a5fd09b8a6678490b77dd6ee3ba947e662f 100644 (file)
@@ -5,6 +5,7 @@
 package CNFDateTime;
 use strict;
 use warnings;
+no warnings qw(experimental::signatures);
 use DateTime;
 use DateTime::Format::DateParse;
 use Time::HiRes qw(time usleep);
@@ -21,9 +22,7 @@ use constant{
 sub new {
     my $class = shift;
     my %settings;
-    if(ref($_[0]) eq ''){
-        %settings = @_;
-    }else{
+    if(ref($_[0]) ne ''){
         %settings = %{$_[0]}
     }
     $settings{epoch} = time if !$settings{epoch};
index f1fc23807454214e0527a531f49a229f7f03a63d..28bb4fa0fb89f80fe9ddb5c056a9c660c4ca95de 100644 (file)
@@ -15,6 +15,7 @@ sub new {
 }
 
 use constant PRIVATE_FIELDS => qr/@\$|[@#_~^&]/o;
+use constant EMPTY => new CNFNode;
 
 ###
 # CNFNode uses symbol offcodes for all its own field values, foe efficiancy.
@@ -259,7 +260,7 @@ sub node {
                 }
             }
        }
-      return
+      return EMPTY
     }
     foreach my $name(split(/\//, $path)){
         $ret = $self->{'@$'};
@@ -269,9 +270,11 @@ sub node {
                     $ret = $_; last
                 }
             }
-        }
+        }else{
+         $ret = EMPTY;
+       }
     }
-    return $ret;
+    return $ret
 }
 ###
 # Outreached subs list of collected node links found in a property.
index 9d69dd4888c6c38b00c9b9b26728fcbbe556b9ae..a304072194581494a6c4de43c4827a58a68e6c3a 100644 (file)
@@ -7,6 +7,7 @@ use strict;use warnings;#use warnings::unused;
 use Exception::Class ('CNFParserException');
 use Syntax::Keyword::Try;
 use Hash::Util qw(lock_hash unlock_hash);
+use File::ReadBackwards;
 
 require CNFMeta; CNFMeta::import();
 require CNFNode;
@@ -279,9 +280,7 @@ sub anon {  my ($self, $n, $args)=@_;
 # Validates and returns a constant named value as part of this configs instance.
 # Returns undef if it doesn't exist, and exception if constance required is set;
 sub const { my ($self,$c)=@_;
-    if(exists $self->{$c}){
-       return  $self->{$c}
-    }
+    return  $self->{$c} if exists $self->{$c};
     CNFParserException->throw("Required constants variable ' $c ' not defined in config!") if $CONSTREQ;
     return;
 }
@@ -1256,22 +1255,24 @@ sub log {
     elsif(%log && $log{console}){
         print $time . " " .$message ."\n"
     }
-    if(%log && $log{enabled} && $message){
+    if(%log && _isTrue($log{enabled}) && $message){
         my $logfile  = $log{file};
         my $tail_cnt = $log{tail};
-        if($log{tail} && $tail_cnt && int(`tail -n $tail_cnt $logfile | wc -l`)>$tail_cnt-1){
-use File::ReadBackwards;
-            my $pos = do {
-               my $fh = File::ReadBackwards->new($logfile) or die $!;
-               $fh->readline() for 1..$tail_cnt;
-               $fh->tell()
-            };
-            truncate($logfile, $pos) or die $!;
-
+        if($logfile){
+                        open (my $fh, ">>", $logfile) or die $!;
+                        print $fh $time . " - " . $message ."\n";
+                        close $fh;
+                        if(_isTrue($log{tail}) && $tail_cnt){
+                            my $fh = File::ReadBackwards->new($logfile) or die $!;
+                            if($fh->{lines}>$tail_cnt){
+                                my $pos = do {
+                                    $fh->readline() for 1..$tail_cnt;
+                                    $fh->tell()
+                                };
+                                truncate($logfile, $pos) or die $!;
+                            }
+                        }
         }
-        open (my $fh, ">>", $logfile) or die ("$!");
-        print $fh $time . " - " . $message ."\n";
-        close $fh;
     }
     return $time . " " .$message;
 }
index 76866b820f91a7f14db71feca3068302b2939cb0..754ba0ade30d2abf10fa83eb82e84cdf537dc480 100644 (file)
@@ -2,7 +2,7 @@ package RSSFeedsPlugin;
 
 use strict;
 use warnings;
-
+no warnings qw(experimental::signatures);
 use feature qw(signatures);
 use Scalar::Util qw(looks_like_number);
 use Syntax::Keyword::Try;
@@ -36,6 +36,7 @@ sub new ($class, $plugin){
 ###
 sub process ($self, $parser, $property) {
     my @data = @{$parser->data()->{$property}};
+    my $cgi  = $parser->const('CGI');
     $self->{date} = now();
     for my $idx (0 .. $#data){
         my @col = @{$data[$idx]};
@@ -47,24 +48,39 @@ sub process ($self, $parser, $property) {
         }
         $data[$idx]=\@col;
     }
-    $parser->addPostParseProcessor($self,'collectFeeds');
-    $parser->data()->{$property} =\@data;
+    if($cgi&&$cgi->param('action') eq 'list'){
+       my $page = '<div class="feed"><h2>List Of Feeds</h2><ol>';
+       for my $idx (1 .. $#data){
+           my @col = @{$data[$idx]};
+           $page .= qq|<li><span style="border: 1px solid black; padding: 5px; padding-bottom: 0px;"><a onclick="return fetchFeed('$col[1]')" style="cursor: pointer;"> <b>$col[1]</b> </a></span> &nbsp;&nbsp;[ $col[4] ]<dt style="padding:5px;">$col[3]</dt></li>\n|;
+       }
+       $page .= '</ol></feed>';
+       $parser->data()->{PAGE} = \$page
+    }else{
+       $parser->addPostParseProcessor($self,'collectFeeds');
+    }
+    $parser->data()->{$property} = \@data
 }
 
-sub collectFeeds($self,$parser) {
+sub collectFeeds($self, $parser) {
   my $property = $self->{property};
   my %hdr;
   my @data = @{$parser->data()->{$property}};
+  my $cgi  = $parser->const('CGI');
   my $page;
+  my $feed = $cgi->param('feed') if $cgi;
+  $parser->log("Feed request:$feed");
   for my $idx (0 .. $#data){
       my @col = @{$data[$idx]};
       if($idx==0){
         for my $i(0..$#col){ # Get the matching table column index names as scripted.
-         $hdr{$col[$i]}=$i
+               $hdr{$col[$i]} = $i
         }
       }else{
-         my $name = $col[$hdr{Name}]; # Now use the column names as coded, if names in script are changed, you must change.
+         my $name = $col[$hdr{Name}]; #<- Now use the column names as coded, if names in script are changed, you must change here.
+         next if($feed && $feed ne $name);
          my $tree =  fetchFeed($self, $name, $col[$hdr{URL}], $col[$hdr{Description}]);
+         $parser->log("Fetched feed:".$name);
          if($tree && ref($$tree) eq 'CNFNode'){
             if(not isCNFTrue($self->{CNF_TREE_LOADED}) && isCNFTrue($self->{CNF_TREE_STORE})){
                my $output_local = getOutputDir($self);
@@ -106,7 +122,7 @@ sub _treeToHTML($tree){
         my $item(@{$brew->items()}){
         next if $item->name() ne 'Item';
         my ($Title,$Link,$Date) = $item -> array('Title','Link','Date');
-        my $Description         = $item -> node('Description') -> val();
+        my $Description         = $item -> node('Description')-> val();
         $bf.= qq(
             <div class="feed">
             <div class="feeds_item_$alt">
diff --git a/htdocs/cgi-bin/wsrc/feeds.js b/htdocs/cgi-bin/wsrc/feeds.js
new file mode 100644 (file)
index 0000000..0c6bde6
--- /dev/null
@@ -0,0 +1,28 @@
+
+function fetchFeeds(){
+    var pnl = $('#feeds');
+    pnl.html(
+    '<div><span style="border:1px solid Crimson;padding:5px;"><font color="Crimson"><b>P l e a s e &nbsp;&nbsp;    W a i t  &nbsp;&nbsp;!</b></font></span><br><img src="images/Wedges-9.1s-64px.png"></div>'
+    );
+    pnl.show();
+    pnl.css('visibility','visible');
+    $.post('CNFServices.cgi', {service:'feeds',action:'list'}, displayFeeds).fail(
+        function(response) {pnl.html("Service Error: "+response.status,response.responseText);pnl.fadeOut(10000);}
+    );
+}
+function fetchFeed(feed){
+    var pnl = $('#feeds');
+    pnl.html(
+    '<div><span style="border:1px solid Crimson;padding:5px;"><font color="Crimson"><b>P l e a s e &nbsp;&nbsp;    W a i t  '+feed+' loading...</b></font></span><br><img src="images/Wedges-9.1s-64px.png"></div>'
+    );
+    pnl.show();
+    pnl.css('visibility','visible');
+    $.post('CNFServices.cgi', {service:'feeds', action:'read', feed:feed}, displayFeeds).fail(
+        function(response) {pnl.html("Service Error: "+response.status,response.responseText);pnl.fadeOut(10000);}
+    );
+}
+function displayFeeds(content){
+    var pnl = $('#feeds');
+    pnl.html(content);
+    pnl.show();
+}
index 1ecdd2acf121c4a39ff090fd84b1e5daf4cad4e9..6af6f1ed0f4437bf479be30eb8fbeebeca45ada7 100644 (file)
@@ -1,9 +1,9 @@
-server.document-root = "/home/will/dev/LifeLog/htdocs/cgi-bin" 
+server.document-root = "/home/will/dev/LifeLog/htdocs/cgi-bin"
 dir-listing.activate = "enable"
 server.port = 80
 
 mimetype.assign = (
-  ".html" => "text/html",  
+  ".html" => "text/html",
   ".md"   => "text/plain",
   ".txt" => "text/plain",
   ".jpg" => "image/jpeg",
@@ -31,7 +31,7 @@ server.modules = (
 
 
 index-file.names = ( "index.html" )
-server.breakagelog = "/home/will/dev/LifeLog/lighttpd_server.log"
+server.breakagelog = "lighttpd_server.log"
 cgi.assign = ( ".pl"  => "/usr/bin/perl", ".cgi" => "/usr/bin/perl" )
 cgi.x-sendfile = "disable"