From 6f21f362c3f7e6c0f2458d8a74400611dd811229 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Thu, 23 May 2024 13:12:34 -0600 Subject: [PATCH] bins/ix: move to "script" and switch to using okturing --- .gitignore | 1 + bins/ix.nix | 38 +++----------------------------------- bins/ix/ix.pl | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 bins/ix/ix.pl diff --git a/.gitignore b/.gitignore index 597edfe..b38f654 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ result .DS_Store tags +*.bak \ No newline at end of file diff --git a/bins/ix.nix b/bins/ix.nix index 5f06790..897bfb2 100644 --- a/bins/ix.nix +++ b/bins/ix.nix @@ -1,36 +1,4 @@ { perl }: '' - #!${perl}/bin/perl - - use strict; - use warnings; - - use HTTP::Tiny; - if ($^O eq "openbsd") { - require OpenBSD::Pledge; - require OpenBSD::Unveil; - - OpenBSD::Unveil::unveil("/", "") or die; - OpenBSD::Pledge::pledge(qw( stdio dns inet rpath )) or die; - } - - my $http = HTTP::Tiny->new(); - - sub slurp { - my ($fh) = @_; - local $/; - <$fh>; - } - - sub ix { - my ($input) = @_; - my $url = "http://sprunge.us"; - my $form = [ sprunge => $input ]; - my $resp = $http->post_form($url, $form) - or die "could not POST: $!"; - $resp->{content}; - } - - my $input = slurp('STDIN'); - my $url = ix($input); - print $url; -'' +#!${perl}/bin/perl +${builtins.readFile ./ix/ix.pl} +'' diff --git a/bins/ix/ix.pl b/bins/ix/ix.pl new file mode 100644 index 0000000..5190619 --- /dev/null +++ b/bins/ix/ix.pl @@ -0,0 +1,42 @@ +use strict; +use warnings; + +use HTTP::Tiny; +if ( $^O eq "openbsd" ) { + require OpenBSD::Pledge; + require OpenBSD::Unveil; + + OpenBSD::Unveil::unveil( "/", "" ) or die; + OpenBSD::Pledge::pledge(qw( stdio dns inet rpath )) or die; +} + +my $http = HTTP::Tiny->new(); + +sub slurp { + my ($fh) = @_; + local $/; + <$fh>; +} + +sub ix { + my ($input) = @_; + my $url = "http://okturing.com"; + my $form = [ + a_body => $input, + submit => "submit", + fake => "fake", + a_func => "add_post" + ]; + my $resp = $http->post_form( $url, $form ) + or die "could not POST: $!"; + $resp->{content}; +} + +my $input = slurp('STDIN'); +my $out = ix($input); +foreach my $line ($out) { + if ( $line =~ m/href="(.+okturing\.com\/src.+\/body)\"/ ) { + print $1, "\n"; + last; + } +}