77use LWP::UserAgent;
88use Storable qw/ store_fd fd_retrieve/ ;
99use File::Glob qw/ :bsd_glob/ ;
10+ use Digest::MD5 qw/ md5_hex/ ;
1011
11- $VERSION = ' 0.04 ' ;
12+ $VERSION = ' 0.05 ' ;
1213%IRSSI = (
1314 authors => ' bw1' ,
14151516 name => ' 0x0st' ,
1617 description => ' upload file to https://0x0.st/' ,
1718 license => ' ISC' ,
1819 url => ' https://scripts.irssi.org/' ,
19- changed => ' 2021-01-13 ' ,
20- modules => ' POSIX HTTP::Request::Common LWP::UserAgent Storable File::Glob' ,
20+ changed => ' 2025-10-12 ' ,
21+ modules => ' POSIX HTTP::Request::Common LWP::UserAgent Storable File::Glob Digest::MD5 ' ,
2122 commands => ' 0x0st' ,
2223 selfcheckcmd => ' 0x0st -c' ,
2324);
3334%9Description%9
3435 $IRSSI {description}
3536 -p past url to channel
36- -s shorten url
37+ -s shorten url (disabled by 0x0st)
3738 -u file from url
3839 -c self check
3940%9See also%9
4546
4647my $base_uri ;
4748
49+ my $user_agent =' curl/123.123' ;
50+
4851my %bg_process = ();
4952my $self_check_timer ;
5053
@@ -84,8 +87,8 @@ sub sig_pidwait {
8487
8588sub upload {
8689 my ($filename ) = @_ ;
87- my $ua = LWP::UserAgent-> new(agent => ' wget ' );
88- my $filename = bsd_glob $filename ;
90+ my $ua = LWP::UserAgent-> new(agent => $user_agent );
91+ $filename = bsd_glob $filename ;
8992 if (-e $filename ) {
9093 my $re = $ua -> request(POST $base_uri ,
9194 Content_Type => ' form-data' ,
@@ -96,12 +99,14 @@ sub upload {
9699 my $code = $re -> code();
97100 chomp $res ;
98101 return $res , $code ;
102+ } else {
103+ return ' file not found' , 404;
99104 }
100105}
101106
102107sub url {
103108 my ($url ) = @_ ;
104- my $ua = LWP::UserAgent-> new(agent => ' wget ' );
109+ my $ua = LWP::UserAgent-> new(agent => $user_agent );
105110 my $re = $ua -> request(POST $base_uri ,
106111 {url => $url }
107112 );
@@ -113,7 +118,7 @@ sub url {
113118
114119sub shorten {
115120 my ($url ) = @_ ;
116- my $ua = LWP::UserAgent-> new(agent => ' wget ' );
121+ my $ua = LWP::UserAgent-> new(agent => $user_agent );
117122 my $re = $ua -> request(POST $base_uri ,
118123 {shorten => $url }
119124 );
@@ -123,6 +128,14 @@ sub shorten {
123128 return $res , $code ;
124129}
125130
131+ sub getwebsite {
132+ my $ua = LWP::UserAgent-> new(agent => $user_agent );
133+ my $re = $ua -> request(GET $base_uri );
134+ my $res = $re -> content;
135+ my $code = $re -> code();
136+ return length ($res ), $code , md5_hex($res );
137+ }
138+
126139sub past2channel {
127140 my ($cmd ) = @_ ;
128141 my $witem = $cmd -> {witem };
@@ -152,10 +165,9 @@ sub cmd {
152165 $cmd -> {args }=[$arg ];
153166 background( $cmd );
154167 } elsif (exists $opt -> {c }) {
155- $cmd -> {cmd }=\&shorten;
156- $cmd -> {args }=[' https://scripts.irssi.org/' ];
168+ $cmd -> {cmd }=\&getwebsite;
157169 $cmd -> {last }=[\&self_check];
158- $self_check_timer = Irssi::timeout_add_once(2000 , \&self_check, ' ' );
170+ $self_check_timer = Irssi::timeout_add_once(20000 , \&self_check, ' ' );
159171 background( $cmd );
160172 } else {
161173 $cmd -> {cmd }=\&upload;
@@ -176,18 +188,20 @@ sub self_check {
176188 } else {
177189 @res = @{$arg -> {res }};
178190 Irssi::timeout_remove($self_check_timer );
179- Irssi::print (" 0x0st: surl: $res [0] stat: $res [1]" , MSGLEVEL_CLIENTCRAP);
180- if ( 2 != scalar (@res ) ) {
191+ Irssi::print (" 0x0st: surl: $res [0] stat: $res [1], digest: $res [2] " , MSGLEVEL_CLIENTCRAP);
192+ if ( 3 != scalar (@res ) ) {
181193 $s = ' Error: arg count' ;
182194 } elsif ( $res [1] != 200 ) {
183195 $s = " Error: HTTP status code ($res [1])" ;
184- } elsif ( $res [0] !~ m / ^http/ ) {
185- $s = " Error: result ($res [0])" ;
196+ } elsif ( $res [0] < 2900 ) {
197+ $s = " Error: result length ($res [0])" ;
198+ } elsif ( $res [2] ne ' 6c6c0ea80554f86b41596d2ecdac3482' ) {
199+ $s = " Warning: website changed" ;
186200 }
187201 }
188- Irssi::print (" 0x0st: selfcheck $s " , MSGLEVEL_CLIENTCRAP);
189- my $schs_version = $Irssi::Script::selfcheckhelperscript::VERSION ;
190- Irssi::command(" selfcheckhelperscript $s " ) if (defined $schs_version );
202+ Irssi::print (" 0x0st: selfckeck $s " , MSGLEVEL_CLIENTCRAP);
203+ my $schs = exists $Irssi::Script ::{ ' selfcheckhelperscript::' } ;
204+ Irssi::command(" selfcheckhelperscript $s " ) if ( $schs );
191205}
192206
193207sub cmd_help {
0 commit comments