eval 'use Net::INET6Glue::INET_is_INET6';
-our $version = 20150826;
+our $version = 20160328;
+our $DEBUG = $ENV{DEBUG};
my %SSL = (SSL_version => 'TLSv1');
my $sigpipe;
}
} elsif ($0 eq 'sexget' or $0 eq 'fuckme') {
+
+ $opt_g = 0;
getopts('hgvVdu:') or die $usage;
die $usage if $opt_h;
} else { # sexsend
- $opt_g = 1;
+ $opt_g = 0;
getopts('hguvqVTt:') or die $usage;
die $usage if $opt_h;
}
request("POST /sex?BS=$bs&user=$user$mode$type$timeout$stream HTTP/1.0");
-print STDERR "==> (streaming ...)\n" if $opt_v;
+print STDERR "--> (streaming ...)\n" if $opt_v;
transfer(STDIN,$SH);
sub request {
my $req = shift;
- print STDERR "==> $req\n" if $opt_v;
- syswrite $SH,"$req\r\n\r\n";
+ print STDERR "--> $req\n" if $opt_v;
+ syswrite $SH,"$req\r\n";
+ syswrite $SH,"User-Agent: sexsend\r\n";
+ syswrite $SH,"\r\n";
for (;;) {
unless (defined($_ = &getline)) {
die "$0: server has closed the connection\n";
}
if (/^HTTP\/[\d\.]+ 200/) {
- print STDERR "<== $_" if $opt_v;
+ print STDERR "<-- $_" if $opt_v;
last;
} elsif (/^HTTP\/[\d\.]+ 199/) {
- print STDERR "<== $_" if $opt_v;
+ print STDERR "<-- $_" if $opt_v;
} else {
if ($opt_v) {
- print STDERR "<== $_";
+ print STDERR "<-- $_";
exit 3;
} else {
s:^HTTP/[ \d\.]+::;
while (defined($_ = &getline)) {
last if /^\s*$/;
$H{uc($1)} = $2 if /(.+):\s*(.+)/;
- print STDERR "<== $_" if $opt_v;
+ print STDERR "<-- $_" if $opt_v;
}
}
local $_;
$req = "GET SID HTTP/1.1";
- print STDERR "==> $req\n" if $opt_v;
+ print STDERR "--> $req\n" if $opt_v;
syswrite $SH,"$req\r\n\r\n";
$_ = &getline;
unless (defined $_ and /\w/) {
}
s/\r//;
if (/^HTTP.* 201 (.+)/) {
- print STDERR "<== $_" if $opt_v;
+ print STDERR "<-- $_" if $opt_v;
$id = 'MD5H:'.md5_hex($id.$1);
while (defined($_ = &getline)) {
s/\r//;
last if /^\n/;
- print STDERR "<== $_" if $opt_v;
+ print STDERR "<-- $_" if $opt_v;
}
} else {
die "$0: $server does not support session ID\n";
my $connect = "CONNECT $server:$port HTTP/1.1";
local $_;
- if ($opt_v and $port == 443 and %SSL) {
- foreach my $v (keys %SSL) {
- printf "%s => %s\n",$v,$SSL{$v};
- }
- }
-
if ($proxy) {
tcpconnect(split(':',$proxy));
- if ($port == 443) {
+ if ($https) {
printf "--> %s\n",$connect if $opt_v;
nvtsend($connect,"");
$_ = <$SH>;
unless (/^HTTP.1.. 200/) {
die "$0: proxy error : $_";
}
- eval "use IO::Socket::SSL";
- die "$0: cannot load IO::Socket::SSL\n" if $@;
+ &enable_ssl;
$SH = IO::Socket::SSL->start_SSL($SH,%SSL);
}
} else {
tcpconnect($server,$port);
}
-# if ($port == 443 and $opt_v) {
+# if ($https and $opt_v) {
# printf "%s\n",$SH->get_cipher();
# }
}
undef $SH;
}
- if ($port == 443) {
+ if ($https) {
# eval "use IO::Socket::SSL qw(debug3)";
- eval "use IO::Socket::SSL";
- die "$0: cannot load IO::Socket::SSL\n" if $@;
+ &enable_ssl;
$SH = IO::Socket::SSL->new(
PeerAddr => $server,
PeerPort => $port,
if ($SH) {
autoflush $SH 1;
+ binmode $SH;
} else {
die "$0: cannot connect $server:$port - $@\n";
}
}
+sub enable_ssl {
+ eval "use IO::Socket::SSL";
+ die "$0: cannot load IO::Socket::SSL\n" if $@;
+ eval '$SSL{SSL_verify_mode} = 0 if Net::SSLeay::SSLeay() <= 9470143';
+ if ($opt_v) {
+ foreach my $v (keys %SSL) {
+ printf "%s => %s\n",$v,$SSL{$v};
+ }
+ }
+}
+
+
sub sendheader {
my $sp = shift;
my @head = @_;
}
+sub quote {
+ local $_ = shift;
+ s/([^\w\@\/%^,.=+_:+-])/\\$1/g;
+ return $_;
+}
+
+
+sub debug {
+ print "## DEBUG: @_\n" if $DEBUG;
+}
+
+
# from MIME::Base64::Perl
sub encode_b64 {
my $res = "";