From 4f1e9c520d411374d6708a5d6f9e67c9a0195222 Mon Sep 17 00:00:00 2001 From: b Date: Sat, 9 Mar 2024 21:30:44 +0000 Subject: [PATCH] adapt to new spambot filter --- botm-common | 2 +- sendpost.1.pl | 103 ++++++++++++++++++++++++++++++--------------- settings-debug.txt | 3 +- settings.txt | 2 +- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/botm-common b/botm-common index 2b44cff..d14fbf1 160000 --- a/botm-common +++ b/botm-common @@ -1 +1 @@ -Subproject commit 2b44cff4fd1df24df3fc9d354e0848e3f0516ef3 +Subproject commit d14fbf1044eb55f7c2f4d77f3117623a5dc3a92d diff --git a/sendpost.1.pl b/sendpost.1.pl index e07cfdc..be46d4c 100644 --- a/sendpost.1.pl +++ b/sendpost.1.pl @@ -1,6 +1,6 @@ ###RUN_PERL: -# Copyright (C) 2023 Balthasar Szczepański +# Copyright (C) 2023, 2024 Balthasar Szczepański # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -27,7 +27,8 @@ use botm_common ( 'read_header_file', 'merge_url', 'html_entity_decode', 'url_query_encode', - 'make_temp_path' + 'make_temp_path', + 'open_encoded' ); use post_common ( 'prepare_post', @@ -177,7 +178,7 @@ foreach my $arg (@ARGV) { my %data = (); unless (($arg == \*STDIN) and ($options{'content'} ne '') and ($options{'data-only'} ne '')) { - %data = read_data_file($arg, ENCODING_FILE, $options{'data-only'}); + %data = read_data_file($arg, ENCODING_FILE(), $options{'data-only'}); unless (keys %data) { unless ($options{'quiet'} ne '') { print "NO DATA\n"; @@ -305,7 +306,7 @@ sub post_to_mirror { return CODE->{'POST_FAILED'}; } - unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) { + unless (open_encoded($fh, '<:encoding('.ENCODING_MIRROR.')', $tmp_path)) { unless ($cmd_options->{'quiet'} ne '') { print "FAIL open $tmp_path\n"; } @@ -331,32 +332,34 @@ sub post_to_mirror { return CODE->{'POST_FAILED'}; } - if (($cmd_options->{'edit'} ne '') and ($cmd_options->{'append'} ne '')) { - %previous_post = get_mirror_previous_post($fh); - if ($previous_post{'error'} ne '') { - unless ($cmd_options->{'quiet'} ne '') { - print "FAIL previous post\n"; - } - print STDERR 'Failed getting previous post content: '.$previous_post{'error'}."\n"; - return CODE->{'POST_FAILED'}; - } - if ($cmd_options->{'verbose'} ne '') { - print "PREVIOUS POST\n"; - write_data_file( - \*STDOUT, \%previous_post, 'console_out', - 0, 0, 0, - '>>', 1 - ); - print "\n"; + %previous_post = get_mirror_previous_post($fh); + if ($cmd_options->{'verbose'} ne '') { + print "PREVIOUS POST\n"; + write_data_file( + \*STDOUT, \%previous_post, 'console_out', + 0, 0, 0, + '>>', 1 + ); + print "\n"; + } + if ($previous_post{'error'} ne '') { + unless ($cmd_options->{'quiet'} ne '') { + print "FAIL previous post\n"; } + print STDERR 'Failed getting previous post content: '.$previous_post{'error'}."\n"; + return CODE->{'POST_FAILED'}; } - + close ($fh); $wget_options{'referer'} = $edit_url; $wget_options{'postdata_path'} = $postdata_path; - if ($previous_post{'content'} ne '') { + if ( + ($cmd_options->{'edit'} ne '') and + ($cmd_options->{'append'} ne '') and + ($previous_post{'content'} ne '') + ) { $post_data{'subject'} = $previous_post{'subject'}; $post_data{'message'} = $previous_post{'content'}. @@ -388,6 +391,10 @@ sub post_to_mirror { if ($cmd_options->{'edit'} ne '') { $post_data{'forceID'} = $cmd_options->{'edit'}; } + if ($previous_post{'st'} ne '') { + $post_data{'st'} = $previous_post{'st'}; + } + $post_data{'post'} = 'Submit'; unless ($cmd_options->{'quiet'} ne '') { @@ -398,7 +405,9 @@ sub post_to_mirror { 0, 0, 0, '>>', 1 ); + print "WAIT 5s\n"; } + sleep(5); # TODO: selectable wait time print "SUBMIT post"; if ($cmd_options->{'verbose'} ne '') { print ": $post_url SAVE $tmp_path\n"; @@ -423,7 +432,7 @@ sub post_to_mirror { return CODE->{'POST_FAILED'}; } - unless (open($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $tmp_path))) { + unless (open_encoded($fh, '<:encoding('.ENCODING_MIRROR.')', $tmp_path)) { unless ($cmd_options->{'quiet'} ne '') { print "FAIL open $tmp_path\n"; } @@ -452,6 +461,8 @@ sub post_to_mirror { ($r, $s) = get_mirror_post_status($fh); close ($fh); + # TODO: wait & retry + unless ($r) { unless ($cmd_options->{'quiet'} ne '') { print "FAIL $s\n"; @@ -488,7 +499,7 @@ sub get_mirror_post_status { $fh=$file; } else { - unless (open ($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $file))) { + unless (open_encoded ($fh, '<:encoding('.ENCODING_MIRROR.')', $file)) { return (0, "Failed to open $file"); } } @@ -528,13 +539,16 @@ sub get_mirror_previous_post { my %post; my $text; my $tag; + my $input_name; + my $input_value; my $textarea = 0; + my $comment = 0; if(ref($file)) { $fh=$file; } else { - unless (open ($fh, '<:encoding('.ENCODING_MIRROR.')', encode('locale_fs', $file))) { + unless (open_encoded ($fh, '<:encoding('.ENCODING_MIRROR.')', $file)) { $post{'error'} = "Failed to open $file"; return %post; } @@ -542,9 +556,20 @@ sub get_mirror_previous_post { while (defined(my $line = <$fh>)) { while ($line ne '') { - if ($line =~ /^([^<]*)(<.*)$/s) { + if ($comment) { + if ($line =~ /-->/) { + $comment = 0; + $line = $'; + next; + } + else { + last; + } + } + + if ($line =~ /^([^<]*)(<)/s) { $text = $1; - $line = $2; + $line = $2.$'; } else { $text = $line; @@ -557,9 +582,15 @@ sub get_mirror_previous_post { last; } - if ($line =~ /^(<[^>]*>)(.*)$/s) { + if ($line =~ /^