From: Will Budic Date: Wed, 20 Sep 2023 00:20:11 +0000 (+1000) Subject: dev. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=25e40ed59aca0315294cd8ab40aa17ff1e632a23;p=LifeLog.git dev. --- diff --git a/.gitignore b/.gitignore index bbd220e..eafc9f9 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ dbLifeLog/current_theme lighttpd.conf dump_* *.rdf +tree_*.cnf diff --git a/htdocs/cgi-bin/CNFServices.cgi b/htdocs/cgi-bin/CNFServices.cgi index 9a83aa4..b76e8fd 100755 --- a/htdocs/cgi-bin/CNFServices.cgi +++ b/htdocs/cgi-bin/CNFServices.cgi @@ -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 +>> < 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 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 index 0000000..7dc4f9a Binary files /dev/null and b/htdocs/cgi-bin/images/Wedges-9.1s-64px.png differ diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index bb42c4e..adb7735 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -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
- ); Settings::printDebugHTML($DBG) if Settings::debug(); diff --git a/htdocs/cgi-bin/system/modules/CNFDateTime.pm b/htdocs/cgi-bin/system/modules/CNFDateTime.pm index 966cb77..fbc49a5 100644 --- a/htdocs/cgi-bin/system/modules/CNFDateTime.pm +++ b/htdocs/cgi-bin/system/modules/CNFDateTime.pm @@ -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}; diff --git a/htdocs/cgi-bin/system/modules/CNFNode.pm b/htdocs/cgi-bin/system/modules/CNFNode.pm index f1fc238..28bb4fa 100644 --- a/htdocs/cgi-bin/system/modules/CNFNode.pm +++ b/htdocs/cgi-bin/system/modules/CNFNode.pm @@ -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. diff --git a/htdocs/cgi-bin/system/modules/CNFParser.pm b/htdocs/cgi-bin/system/modules/CNFParser.pm index 9d69dd4..a304072 100644 --- a/htdocs/cgi-bin/system/modules/CNFParser.pm +++ b/htdocs/cgi-bin/system/modules/CNFParser.pm @@ -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; } diff --git a/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm b/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm index 76866b8..754ba0a 100644 --- a/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm +++ b/htdocs/cgi-bin/system/modules/RSSFeedsPlugin.pm @@ -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 = '

List Of Feeds

    '; + for my $idx (1 .. $#data){ + my @col = @{$data[$idx]}; + $page .= qq|
  1. $col[1]   [ $col[4] ]
    $col[3]
  2. \n|; + } + $page .= '
'; + $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(
diff --git a/htdocs/cgi-bin/wsrc/feeds.js b/htdocs/cgi-bin/wsrc/feeds.js new file mode 100644 index 0000000..0c6bde6 --- /dev/null +++ b/htdocs/cgi-bin/wsrc/feeds.js @@ -0,0 +1,28 @@ + +function fetchFeeds(){ + var pnl = $('#feeds'); + pnl.html( + '
P l e a s e    W a i t   !
' + ); + 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( + '
P l e a s e    W a i t '+feed+' loading...
' + ); + 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(); +} diff --git a/lighttpd.conf b/lighttpd.conf index 1ecdd2a..6af6f1e 100644 --- a/lighttpd.conf +++ b/lighttpd.conf @@ -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"