Commit a785931e authored by Tails developers's avatar Tails developers

Import newer custom htpdate (at commit 042cc8e3).

This will allow us to use a custom SocksPort for htpdate.

042cc8e3 Use curl instead of wget, and add a --proxy option passed through to curl.
5f213676 Remove the --fullrequest option, we don't need it anymore.
bfe6ffb7 Remove --dns-timeout option, we don't need it anymore.
parent 03a86a5a
......@@ -10,17 +10,6 @@
# of the License, or (at your option) any later version.
# http://www.gnu.org/copyleft/gpl.html
# Proxy setting are read from environment
# e.g. in bash for setting environment variables:
#
# export HTTP_PROXY='http://wwwproxy.xs4all.nl:8080'
#
# or set the proxy value here
#
# $ENV{HTTP_PROXY} = 'http://wwwproxy.xs4all.nl:8080';
#
# If proxy authentication is required, specify your userid and password below.
use strict;
use warnings;
......@@ -46,13 +35,10 @@ my $datecommand = '/bin/date'; # "date" command to set time
my $dateparam = '-s'; # "date" parameter to set time
my $maxadjust = 0; # maximum time step in seconds (0 means no max.)
my $minadjust = 1; # minimum time step in seconds
my $ssl_protocol = 'TLSv1'; # will be passed to wget's --secure-protocol
my $userid = ''; # userid for proxy servers
my $password = ''; # password for proxy server
my (
$debug, $useragent, $fullrequest, $log, $quiet, $set_date,
$dns_timeout, $done_file, $res_file, $usage, $opt, $runas,
$allowed_per_pool_failure_ratio, @pools,
$debug, $useragent, $log, $quiet, $set_date,
$done_file, $res_file, $usage, $opt, $runas,
$allowed_per_pool_failure_ratio, $proxy, @pools,
);
sub done {
......@@ -105,15 +91,14 @@ sub parseCommandLine () {
[ 'user|u:s', "userid to run as" ],
[ 'dont_set_date|x', "do not set the time (only show)", { default => 0 } ],
[ 'user_agent|a:s', "http user agent to use", { default => "htpdate/$VERSION" } ],
[ 'fullrequest|f', "request the full page and referenced resources rather than only its header", { default => 0 } ],
[ 'log_file|l:s', "log to this file rather than to STDOUT" ],
[ 'dns_timeout|t:i', "DNS timeout for wget" ],
[ 'done_file|D:s', "create this file after quitting in any way" ],
[ 'success_file|T:s', "create this file after setting time successfully" ],
[ 'pal_pool=s@', "distrusted hostnames" ],
[ 'neutral_pool=s@', "neutral hostnames" ],
[ 'foe_pool=s@', "distrusted hostnames" ],
[ 'allowed_per_pool_failure_ratio:f', "ratio (0.0-1.0) of allowed per-pool failure", { default => 1.0 } ],
[ 'proxy|p:s', "what to pass to curl's --proxy" ],
);
usage() if $opt->help;
......@@ -123,14 +108,13 @@ sub parseCommandLine () {
$> = getpwnam($runas) if $runas;
$useragent = $opt->user_agent;
$debug = $opt->debug;
$fullrequest = $opt->fullrequest;
$log = $opt->log_file if $opt->log_file;
$quiet = $opt->quiet;
$set_date = ! $opt->dont_set_date;
$dns_timeout = $opt->dns_timeout;
$done_file = $opt->done_file if $opt->done_file;
$res_file = $opt->success_file if $opt->success_file;
$allowed_per_pool_failure_ratio = $opt->allowed_per_pool_failure_ratio;
$proxy = $opt->proxy if $opt->proxy;
@pools = map {
[
map {
......@@ -217,13 +201,11 @@ sub random_first_with_allowed_failure_ratio {
sub getPoolDateDiff {
my $args = shift;
my $fullrequest = defined $args->{fullrequest} ? $args->{fullrequest} : 0;
random_first_with_allowed_failure_ratio({
list => $args->{urls},
code => \&getUrlDateDiff,
is_success => sub { defined shift },
args => { fullrequest => $fullrequest },
allowed_failure_ratio => $allowed_per_pool_failure_ratio,
});
}
......@@ -231,34 +213,20 @@ sub getPoolDateDiff {
sub getUrlDateDiff {
my $url = shift;
my $args = shift;
my $fullrequest = $args->{fullrequest};
defined $url or error "getUrlDateDiff must be passed an URL";
debug("getUrlDateDiff: $url");
my $tmpdir = tempdir("XXXXXXXXXX", TMPDIR => 1);
my @wget_options = (
'-U', $useragent, '--quiet', '--no-cache',
'-e', 'robots=off',
'--secure-protocol', $ssl_protocol,
'--directory-prefix', $tmpdir,
my @curl_options = (
'--user-agent', $useragent, '--silent',
'--proto', '=https', '--tlsv1',
'--head', '--output', catfile($tmpdir, 'headers'),
);
push @wget_options, ('--dns-timeout', $dns_timeout) if defined $dns_timeout;
if ($fullrequest) {
push @wget_options, (
'--no-directories', '--page-requisites', '--span-hosts',
'--save-headers',
);
}
else {
push @wget_options, (
'--spider', '--server-response',
'--output-file', catfile($tmpdir, 'headers'),
);
}
push @curl_options, ('--proxy', $proxy) if defined $proxy;
my @cmdline = ('wget', @wget_options, $url);
my @cmdline = ('curl', @curl_options, $url);
# fetch (the page and) referenced resources:
# images, stylesheets, scripts, etc.
......@@ -316,11 +284,13 @@ sub adjustDate {
$> = getpwnam($runas) if $runas;
}
}
$> = 0 if $runas;
open my $res_h, '>>', $res_file or die "Cannot open res file $res_file: $!";
print $res_h "$diff\n";
close $res_h;
$> = getpwnam($runas) if $runas;
if (defined $res_file) {
$> = 0 if $runas;
open my $res_h, '>>', $res_file or die "Cannot open res file $res_file: $!";
print $res_h "$diff\n";
close $res_h;
$> = getpwnam($runas) if $runas;
}
}
parseCommandLine();
......@@ -334,10 +304,7 @@ my @diffs = grep {
}
$diff;
} map {
threads->create(\&getPoolDateDiff, {
urls => $_,
fullrequest => $fullrequest,
})
threads->create(\&getPoolDateDiff, { urls => $_ })
} @pools
or error "No Date header could be received.";
my @sorted_diffs = sort @diffs;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment