]> bicyclesonthemoon.info Git - ott/post/commitdiff
adapt to new spambot filter v1.0.6
authorb <rowerynaksiezycu@gmail.com>
Sat, 9 Mar 2024 21:30:44 +0000 (21:30 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sat, 9 Mar 2024 21:30:44 +0000 (21:30 +0000)
botm-common
sendpost.1.pl
settings-debug.txt
settings.txt

index 2b44cff4fd1df24df3fc9d354e0848e3f0516ef3..d14fbf1044eb55f7c2f4d77f3117623a5dc3a92d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 2b44cff4fd1df24df3fc9d354e0848e3f0516ef3
+Subproject commit d14fbf1044eb55f7c2f4d77f3117623a5dc3a92d
index e07cfdc4beb7a1855afbed5a2a1717c6a6907261..be46d4c24f7efa853109cf69bb21710fdfeacda0 100644 (file)
@@ -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 =~ /^<!--/) {
+                               $comment = 1;
+                               $line = $';
+                               next;
+                       }
+                       
+                       if ($line =~ /^(<[^>]*>)/s) {
                                $tag = lc($1);
-                               $line = $2;
+                               $line = $';
                        }
                        else { # oh no tag doesn't end on this line - whatever, I don't care.
                                $tag = $line;
@@ -574,9 +605,15 @@ sub get_mirror_previous_post {
                        }
                        
                        # SKIP!: form_token creation_time attachment (from post.awk)
-                       if ($tag =~ /name="subject"/) {
-                               $tag =~ /value="([^"]*)"/;
-                               $post{'subject'} = html_entity_decode($1);
+                       if ($tag =~ /^<input (.* )?name="([^"]*)"/) {
+                               $input_name = html_entity_decode($2);
+                               if ($tag =~ /value="([^"]*)"/) {
+                                       $input_value = html_entity_decode($1);
+                               }
+                               else {
+                                       $input_value = '';
+                               }
+                               $post{$input_name} = $input_value;
                        }
                }
        }
index d283d789fb49ae2ed73810a23be4cc79cf865614..ab59bc0c5ba42d338434a0407e525b8bed6a57b2 100644 (file)
@@ -8,7 +8,8 @@ lib_path : /botm/lib/test-post
 tmp_path : /botm/tmp/test-post
 data_path: /botm/data/test-post
 
-mirror_url: http://1190.botcastle1b/ott
+# mirror_url: http://1190.botcastle1b/ott
+mirror_url: http://1190.bicyclesonthemoon.info/ottest
 
 encoding_file  : UTF-8
 encoding_ott   : UTF-8
index a980017f8c47e11b23c6610e6090d7871ef8efae..c4587b8d95aae2774262e752faa171effe0864ac 100644 (file)
@@ -15,7 +15,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-_version: 1.0.5
+_version: 1.0.6
 
 _PERL_STR: '@_ESCAPE($0,')'
 _SHEBANG: #!$0