From 7489d8e141f5f9a7b7175285b0d78fd1a2efd9b7 Mon Sep 17 00:00:00 2001 From: b Date: Fri, 12 May 2023 22:10:21 +0000 Subject: [PATCH] Preparing of the post default values mirror URL --- botm-common | 2 +- sendpost.1.pl | 185 +++++++++++++++++++++++++++++++++++++------ settings-debug.txt | 7 ++ settings-release.txt | 6 ++ settings.txt | 15 +++- 5 files changed, 187 insertions(+), 28 deletions(-) diff --git a/botm-common b/botm-common index 341e2e9..29f4a0d 160000 --- a/botm-common +++ b/botm-common @@ -1 +1 @@ -Subproject commit 341e2e9846e2f68a53b336eb5e741346e82b039e +Subproject commit 29f4a0d68bcb31fb4032b61f191b0b88a1be922f diff --git a/sendpost.1.pl b/sendpost.1.pl index e5cb857..58d8353 100644 --- a/sendpost.1.pl +++ b/sendpost.1.pl @@ -21,21 +21,22 @@ use Getopt::Long; use Encode qw(encode decode); ###PERL_LIB: use lib '/botm/lib/post'; -use botm_common qw(readdatafile); +use botm_common qw(readdatafile writedatafile join_path); -###PERL_ENCODING_FILE_IN: use constant ENCODING_FILE_IN => 'UTF-8' -###PERL_ENCODING_FILE_OUT: use constant ENCODING_FILE_OUT => 'utf8' -###PERL_ENCODING_STD_IN: use constant ENCODING_STD_IN => 'UTF-8' -###PERL_ENCODING_STD_OUT: use constant ENCODING_STD_OUT => 'utf8' +###PERL_ENCODING_FILE_IN: use constant ENCODING_FILE_IN => 'UTF-8'; +###PERL_ENCODING_FILE_OUT: use constant ENCODING_FILE_OUT => 'utf8'; +###PERL_ENCODING_STD_IN: use constant ENCODING_STD_IN => 'UTF-8'; +###PERL_ENCODING_STD_OUT: use constant ENCODING_STD_OUT => 'utf8'; -binmode STDIN, ':encoding('.ENCODING_STD_IN.')'; -# binmode ARGV, ':encoding('.ENCODING_STD_IN.')'; # not working -binmode STDOUT, ':encoding('.ENCODING_STD_OUT.')'; -binmode STDERR, ':encoding('.ENCODING_STD_OUT.')'; +###PERL_DEFAULT_PASSWORD: use constant DEFAULT_PASSWORD => 'password'; +###PERL_DEFAULT_SUBJECT: use constant DEFAULT_SUBJECT => 'Re: 1190: "Time"'; +###PERL_DEFAULT_USERNAME: use constant DEFAULT_USERNAME => 'username'; -my $helptext = +###PERL_MIRROR_URL: use constant MIRROR_URL => 'https://1190.bicyclesonthemoon.info/ott'; + +use constant HELP_TEXT => "sendpost [options] [file(s)]\n". - " -s, --username=USERNAME\n". + " -l, --username=USERNAME\n". " -p, --password=PASSWORD\n". " -t, --subject=POST_SUBJECT\n". " -c, --content=POST_CONTENT\n". @@ -55,9 +56,15 @@ my $helptext = "\n". " -M, --mirror\n". " -m, --no-mirror\n". + " -R, --mirror-url=MIRROR_URL\n", "\n". " -h, --help\n"; +binmode STDIN, ':encoding('.ENCODING_STD_IN.')'; +# binmode ARGV, ':encoding('.ENCODING_STD_IN.')'; # not working +binmode STDOUT, ':encoding('.ENCODING_STD_OUT.')'; +binmode STDERR, ':encoding('.ENCODING_STD_OUT.')'; + my %options = {}; foreach my $arg (@ARGV) { @@ -86,19 +93,26 @@ GetOptions ( 'mirror|M' => \$options{ 'mirror'}, 'no-mirror|m' => \$options{'no-mirror'}, + 'mirror-url|R=s' => \$options{ 'mirror-url'}, + 'help|h' => \$options{ 'help'} ); if ($options{'help'} ne '') { - print $helptext; + print HELP_TEXT; exit 0; } - -print "options\n"; -foreach my $ind (keys %options) { - print $ind.'='.$options{$ind}."\n"; +if ($options{'mirror-url'} eq '') { + $options{'mirror-url'} = MIRROR_URL; } -print; + +print "options:\n"; +my $a = writedatafile(\*STDOUT, ENCODING_STD_OUT, 0, \%options); +print "$a\n"; +# foreach my $ind (keys %options) { + # print $ind.'='.$options{$ind}."\n"; +# } +# print; foreach my $arg (@ARGV) { print "\nFILE $arg\n"; my %data = readdatafile($arg, 'utf8', 1); @@ -106,12 +120,137 @@ foreach my $arg (@ARGV) { print $ind.'='.$data{$ind}."\n"; } } -if ((scalar @ARGV) == 0) { - print "\nSTDIN\n"; - my $fh; - my %data = readdatafile(\*STDIN, 'utf8', 1); - foreach my $ind (keys %data) { - print $ind.'='.$data{$ind}."\n"; +# if ((scalar @ARGV) == 0) { + # print "\nSTDIN\n"; + # my $fh; + # my %data = readdatafile(\*STDIN, 'utf8', 1); + # foreach my $ind (keys %data) { + # print $ind.'='.$data{$ind}."\n"; + # } +# } + + +sub prepare_post { + (my $cmd_options, my $file_data) = @_; + my %post; + + if ($cmd_options->{'subject'}) ne '') { + $post{'subject'} = $cmd_options->{'subject'}; + } + elsif ($file_data->{'subject'}) ne '') { + $post{'subject'} = $file_data->{'subject'}; + } + else { + $post{'subject'} = DEFAULT_SUBJECT; + } + + if ($cmd_options->{'username'}) ne '') { + $post{'username'} = $cmd_options->{'username'}; + } + elsif ($file_data->{'username'}) ne '') { + $post{'username'} = $file_data->{'username'}; + } + else { + $post{'username'} = DEFAULT_USERNAME; + } + + if ($cmd_options->{'password'}) ne '') { + $post{'password'} = $cmd_options->{'password'}; + } + elsif ($file_data->{'password'}) ne '') { + $post{'password'} = $file_data->{'password'}; + } + else { + $post{'password'} = DEFAULT_PASSWORD; + } + + if ($cmd_options->{'content'}) ne '') { + $post{'content'} = $cmd_options->{'content'}; + } + elsif ($file_data->{'content'}) ne '') { + $post{'content'} = $file_data->{'content'}; + } + else { + $post{'content'} = ''; } + + if ($cmd_options->{'no-bbcode'}) ne '') { + $post{'bbcode'} = 0; + } + elsif ($cmd_options->{'bbcode'}) ne '') { + $post{'bbcode'} = 1; + } + elsif ($file_data->{'bbcode'}) ne '') { + $post{'bbcode'} = $file_data->{'bbcode'}+0; + } + else { + $post{'bbcode'} = 1; + } + + if ($cmd_options->{'no-smilies'}) ne '') { + $post{'smilies'} = 0; + } + elsif ($cmd_options->{'smilies'}) ne '') { + $post{'smilies'} = 1; + } + elsif ($file_data->{'smilies'}) ne '') { + $post{'smilies'} = $file_data->{'smilies'}+0; + } + else { + $post{'smilies'} = 1; + } + + if ($cmd_options->{'no-urls'}) ne '') { + $post{'urls'} = 0; + } + elsif ($cmd_options->{'urls'}) ne '') { + $post{'urls'} = 1; + } + elsif ($file_data->{'urls'}) ne '') { + $post{'urls'} = $file_data->{'urls'}+0; + } + else { + $post{'urls'} = 1; + } + + if ($cmd_options->{'no-signature'}) ne '') { + $post{'signature'} = 0; + } + elsif ($cmd_options->{'signature'}) ne '') { + $post{'signature'} = 1; + } + elsif ($file_data->{'signature'}) ne '') { + $post{'signature'} = $file_data->{'signature'}+0; + } + else { + $post{'signature'} = 1; + } + + if ($cmd_options->{'no-notify'}) ne '') { + $post{'notify'} = 0; + } + elsif ($cmd_options->{'notify'}) ne '') { + $post{'notify'} = 1; + } + elsif ($file_data->{'notify'}) ne '') { + $post{'notify'} = $file_data->{'notify'}+0; + } + else { + $post{'notify'} = 0; + } + + if ($file_data->{'time'}) ne '') { + $post{'time'} = $file_data->{'time'}+0; + } + else { + $post{'time'} = 0; + } + + return %post; } +sub post_to_mirror { + (my $cmd_options, my $post) = @_; + my $post_url = join_path('/', $cmd_options->{'mirror-url'}, 'post'); + +} diff --git a/settings-debug.txt b/settings-debug.txt index df2ea3d..38f43eb 100644 --- a/settings-debug.txt +++ b/settings-debug.txt @@ -10,11 +10,18 @@ configure: /botm/bin/config/configure.pl bin_path: /botm/bin/test-post lib_path: /botm/lib/test-post +mirror_url: http://1190.botcastle1b/ott + encoding_file_in: UTF-8 encoding_file_out: utf8 encoding_std_in: UTF-8 encoding_std_out: utf8 +default_subject: Re: 1190: "Time" +default_username: _ +default_password: _ + + cp: /usr/bin/cp chmod: /usr/bin/chmod mkdir: /usr/bin/mkdir diff --git a/settings-release.txt b/settings-release.txt index f4c4783..456017b 100644 --- a/settings-release.txt +++ b/settings-release.txt @@ -10,11 +10,17 @@ configure: /botm/bin/config/configure.pl bin_path: /botm/bin/post lib_path: /botm/lib/post +mirror_url: https://1190.bicyclesonthemoon.info/ott + encoding_file_in: UTF-8 encoding_file_out: utf8 encoding_std_in: UTF-8 encoding_std_out: utf8 +default_subject: Re: 1190: "Time" +default_username: _ +default_password: _ + cp: /usr/bin/cp chmod: /usr/bin/chmod mkdir: /usr/bin/mkdir diff --git a/settings.txt b/settings.txt index 7f34c9a..df9c303 100644 --- a/settings.txt +++ b/settings.txt @@ -16,9 +16,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +_PERL_STR: '@_ESCAPE($0,')' _SHEBANG: #!$0 _PERL_USE_2: use $0 $1; _PERL_CONSTANT: use constant $0 => $1; +_PERL_CONSTANT_STR: @_PERL_CONSTANT($0,@_PERL_STR($1)) MAKE_CONFIGURE = CONFIGURE = $configure MAKE_TARGET = TARGET = $target @@ -32,10 +34,15 @@ MAKE_BIN_PATH = BIN_PATH = $bin_path MAKE_LIB_PATH = LIB_PATH = $lib_path -PERL_ENCODING_FILE_IN = @_PERL_CONSTANT(ENCODING_FILE_IN , '$encoding_file_in') -PERL_ENCODING_FILE_OUT = @_PERL_CONSTANT(ENCODING_FILE_OUT, '$encoding_file_out') -PERL_ENCODING_STD_IN = @_PERL_CONSTANT(ENCODING_STD_IN , '$encoding_std_in') -PERL_ENCODING_STD_OUT = @_PERL_CONSTANT(ENCODING_STD_OUT , '$encoding_std_out') +PERL_DEFAULT_PASSWORD = @_PERL_CONSTANT_STR( DEFAULT_PASSWORD , $default_password) +PERL_DEFAULT_SUBJECT = @_PERL_CONSTANT_STR( DEFAULT_SUBJECT , $default_subject) +PERL_DEFAULT_USERNAME = @_PERL_CONSTANT_STR( DEFAULT_USERNAME , $default_username) +PERL_ENCODING_FILE_IN = @_PERL_CONSTANT_STR( ENCODING_FILE_IN , $encoding_file_in) +PERL_ENCODING_FILE_OUT = @_PERL_CONSTANT_STR( ENCODING_FILE_OUT, $encoding_file_out) +PERL_ENCODING_STD_IN = @_PERL_CONSTANT_STR( ENCODING_STD_IN , $encoding_std_in) +PERL_ENCODING_STD_OUT = @_PERL_CONSTANT_STR( ENCODING_STD_OUT , $encoding_std_out) +PERL_MIRROR_URL = @_PERL_CONSTANT_STR( MIRROR_URL , $mirror_url); + PERL_LIB = @_PERL_USE_2(lib, '$lib_path') -- 2.30.2