From 696c406940e8946d30c6d024ec7613d4f7efae41 Mon Sep 17 00:00:00 2001 From: b Date: Wed, 5 Jul 2023 22:53:26 +0000 Subject: [PATCH] develop wget --- botm-common | 2 +- sendpost.1.pl | 58 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/botm-common b/botm-common index f59a33c..e44d4fc 160000 --- a/botm-common +++ b/botm-common @@ -1 +1 @@ -Subproject commit f59a33c43337111906246e3c26df2445886255bb +Subproject commit e44d4fc88013f9ad09186ce3cfc73d93829103d2 diff --git a/sendpost.1.pl b/sendpost.1.pl index 5a5cb10..c2a6451 100644 --- a/sendpost.1.pl +++ b/sendpost.1.pl @@ -23,7 +23,8 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib '/botm/lib/post'; use botm_common ( - 'read_data_file', 'write_data_file', + 'read_data_file', 'write_data_file', 'write_postdata_file', + 'read_header_file', 'merge_url', 'make_temp_path', 'system_encoded' @@ -272,18 +273,65 @@ sub post_to_mirror { my $cookie_path = make_temp_path(TMP_PATH, 'sendpost.cookie.txt'); my $postdata_path = make_temp_path(TMP_PATH, 'sendpost.postdata.txt'); - wget($post_url, $tmp_path); - + my %wget_options = ( + 'with_header', 1, + 'cookie_path', $cookie_path, + 'postdata_path', $postdata_path + ); + my %post_data = ( + 'uvwxyz', 'eół', + 'lel', 'lol' + ); + + wget($post_url, $tmp_path, \%wget_options, \%post_data); + + # unlink($tmp_path, $cookie_path, $postdata_path); } sub wget { - (my $url, my $path, my $postdata) = @_; + (my $url, my $path, my $options, my $postdata) = @_; + + my @arg = ( + WGET, + '-q' + ); + + if ($options->{'with_header'}) { + push(@arg, '--save-headers'); + } + + if ($options->{'cookie_path'} ne '') { + if (-f $options->{'cookie_path'}) { + push(@arg, '--load-cookies='.$options->{'cookie_path'}); + } + push(@arg, '--save-cookies='.$options->{'cookie_path'}); + } + else { + push(@arg, '--no-cookies'); + } + + if ($options->{'postdata_path'} ne '') { + if (defined $postdata) { + write_postdata_file( + $options->{'postdata_path'}, + ENCODING_FILE, '', + $postdata + ); + push(@arg, '--post-file='.$options->{'postdata_path'}); + } + } + + push(@arg, ( + $url, + '-O', $path + )); + - my @arg = (WGET, '-q', $url, '-O', $path); system_encoded(WGET, @arg); return 1; } + -- 2.30.2