]> git.treefish.org Git - fex.git/blobdiff - htdocs/download/sexsend
Original release 20160919
[fex.git] / htdocs / download / sexsend
index ff3f1ed5d367d8cd5e12c3bb12f82dc7e203f212..8b9e1d1e94c981225b266e4a4f74256ada87ce0e 100755 (executable)
@@ -19,7 +19,8 @@ use constant M => 2**20;
 
 eval 'use Net::INET6Glue::INET_is_INET6';
 
-our $version = 20150826;
+our $version = 20160919;
+our $DEBUG = $ENV{DEBUG};
 
 my %SSL = (SSL_version => 'TLSv1');
 my $sigpipe;
@@ -142,6 +143,8 @@ if ($0 eq 'sexxx') {
   }
 
 } elsif ($0 eq 'sexget' or $0 eq 'fuckme') {
+
+  $opt_g = 0;
   getopts('hgvVdu:') or die $usage;
   die $usage if $opt_h;
 
@@ -175,7 +178,7 @@ if ($0 eq 'sexxx') {
 
 } else { # sexsend
 
-  $opt_g = 1;
+  $opt_g = 0;
   getopts('hguvqVTt:') or die $usage;
   die $usage if $opt_h;
 
@@ -328,7 +331,7 @@ if ($mode eq 'anonymous') {
 }
 
 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);
 
@@ -392,20 +395,22 @@ sub transfer {
 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\.]+::;
@@ -417,7 +422,7 @@ sub request {
   while (defined($_ = &getline)) {
     last if /^\s*$/;
     $H{uc($1)} = $2 if /(.+):\s*(.+)/;
-    print STDERR "<== $_" if $opt_v;
+    print STDERR "<-- $_" if $opt_v;
   }
 }
 
@@ -458,7 +463,7 @@ sub query_sid {
   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/) {
@@ -467,12 +472,12 @@ sub query_sid {
   }
   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";
@@ -605,15 +610,9 @@ sub serverconnect {
   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>;
@@ -622,14 +621,13 @@ sub serverconnect {
       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();
 #  }
 }
@@ -644,10 +642,9 @@ sub tcpconnect {
     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,
@@ -664,6 +661,7 @@ sub tcpconnect {
 
   if ($SH) {
     autoflush $SH 1;
+    binmode $SH;
   } else {
     die "$0: cannot connect $server:$port - $@\n";
   }
@@ -672,6 +670,18 @@ sub tcpconnect {
 }
 
 
+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 = @_;
@@ -708,6 +718,18 @@ sub nvtsend {
 }
 
 
+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 = "";