lighttpd.conf
dump_*
*.rdf
+tree_*.cnf
#!/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;
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
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
}
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
|| 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__
}
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},
<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 W a i t 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();
package CNFDateTime;
use strict;
use warnings;
+no warnings qw(experimental::signatures);
use DateTime;
use DateTime::Format::DateParse;
use Time::HiRes qw(time usleep);
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};
}
use constant PRIVATE_FIELDS => qr/@\$|[@#_~^&]/o;
+use constant EMPTY => new CNFNode;
###
# CNFNode uses symbol offcodes for all its own field values, foe efficiancy.
}
}
}
- return
+ return EMPTY
}
foreach my $name(split(/\//, $path)){
$ret = $self->{'@$'};
$ret = $_; last
}
}
- }
+ }else{
+ $ret = EMPTY;
+ }
}
- return $ret;
+ return $ret
}
###
# Outreached subs list of collected node links found in a property.
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;
# 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;
}
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;
}
use strict;
use warnings;
-
+no warnings qw(experimental::signatures);
use feature qw(signatures);
use Scalar::Util qw(looks_like_number);
use Syntax::Keyword::Try;
###
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]};
}
$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> [ $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);
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">
--- /dev/null
+
+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 W a i t !</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 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();
+}
-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",
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"