mirror of
https://codeberg.org/crimeflare/cloudflare-tor
synced 2024-11-09 19:02:40 +00:00
Update 'tool/irssi_cf_alturl.pl'
This commit is contained in:
parent
2afd5db528
commit
804ce3ceb8
@ -13,6 +13,9 @@
|
|||||||
#
|
#
|
||||||
# /set cflarealt_localdbpath <"string to path"> -- () '/path/database/split/'
|
# /set cflarealt_localdbpath <"string to path"> -- () '/path/database/split/'
|
||||||
# /set cflarealt_uselocaldb <on|off> -- (off) if 'on', please set path to local database (or the script will die)
|
# /set cflarealt_uselocaldb <on|off> -- (off) if 'on', please set path to local database (or the script will die)
|
||||||
|
#
|
||||||
|
# /set cflarealt_printurl <on|off> -- (off) if 'on' print converted URL
|
||||||
|
# /set cflarealt_donotsend <on|off> -- (off) if 'on' do not send converted URL
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
|
|
||||||
##use strict;
|
##use strict;
|
||||||
@ -21,6 +24,7 @@ use vars qw($VERSION %IRSSI);
|
|||||||
|
|
||||||
$VERSION = "20190506";
|
$VERSION = "20190506";
|
||||||
%IRSSI = (
|
%IRSSI = (
|
||||||
|
|
||||||
# Special thanks to: "eo, tsaavik"
|
# Special thanks to: "eo, tsaavik"
|
||||||
authors => "Anonymous",
|
authors => "Anonymous",
|
||||||
contact => 'anonymous@cloudflare-tor.nab',
|
contact => 'anonymous@cloudflare-tor.nab',
|
||||||
@ -35,7 +39,11 @@ use Irssi::Irc;
|
|||||||
use LWP::Simple;
|
use LWP::Simple;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
|
|
||||||
my ( $cfg_minurllen, $cfg_send2chan, $cfg_useshort, $cfg_isdebug, $cfg_uselocaldb, $cfg_localdbpath, $cfg_chanlist );
|
my (
|
||||||
|
$cfg_minurllen, $cfg_send2chan, $cfg_useshort, $cfg_isdebug,
|
||||||
|
$cfg_uselocaldb, $cfg_localdbpath, $cfg_chanlist
|
||||||
|
);
|
||||||
|
my ( $cfg_printurl, $cfg_donotsendurl );
|
||||||
my @cached = ();
|
my @cached = ();
|
||||||
|
|
||||||
sub setuphandler {
|
sub setuphandler {
|
||||||
@ -90,6 +98,18 @@ sub setuphandler {
|
|||||||
print "cflarealt: DB path set to $cfg_localdbpath";
|
print "cflarealt: DB path set to $cfg_localdbpath";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Irssi::settings_add_bool( "cflarealt", "cflarealt_printurl", 0 );
|
||||||
|
if ( Irssi::settings_get_bool("cflarealt_printurl") ) {
|
||||||
|
print "cflarealt: print URL enabled";
|
||||||
|
$cfg_printurl = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Irssi::settings_add_bool( "cflarealt", "cflarealt_donotsend", 0 );
|
||||||
|
if ( Irssi::settings_get_bool("cflarealt_donotsend") ) {
|
||||||
|
print "cflarealt: dont-send enabled";
|
||||||
|
$cfg_donotsendurl = 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GotUrl {
|
sub GotUrl {
|
||||||
@ -102,8 +122,9 @@ sub GotUrl {
|
|||||||
$data =~ s/^\s+//;
|
$data =~ s/^\s+//;
|
||||||
$data =~ s/\s+$//;
|
$data =~ s/\s+$//;
|
||||||
my @urls = ();
|
my @urls = ();
|
||||||
|
my @knownShortFQDN = ( 'tinyurl.com', 'bit.ly' );
|
||||||
my ( $url, $a, $return, $char, $ch ) = "";
|
my ( $url, $a, $return, $char, $ch ) = "";
|
||||||
my $same = 0;
|
my $same = 0;
|
||||||
|
|
||||||
return unless ( ( $data =~ /\bhttp\:/ ) || ( $data =~ /\bhttps\:/ ) );
|
return unless ( ( $data =~ /\bhttp\:/ ) || ( $data =~ /\bhttps\:/ ) );
|
||||||
deb("$target triggered GotUrl() with url: $data");
|
deb("$target triggered GotUrl() with url: $data");
|
||||||
@ -128,9 +149,9 @@ sub GotUrl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my ( $myurl, $fqdn, $junk, $mytype );
|
my ( $myurl, $fqdn, $junk, $mytype );
|
||||||
my ( $url, $browser, $response, $answer );
|
my ( $url, $browser, $response, $answer );
|
||||||
my ( $line, $ifoundit );
|
my ( $line, $ifoundit );
|
||||||
|
|
||||||
foreach (@urls) {
|
foreach (@urls) {
|
||||||
$myurl = $_;
|
$myurl = $_;
|
||||||
@ -140,16 +161,43 @@ sub GotUrl {
|
|||||||
|
|
||||||
if ( length($fqdn) >= 4 ) {
|
if ( length($fqdn) >= 4 ) {
|
||||||
## Start of Act
|
## Start of Act
|
||||||
|
|
||||||
|
## ACT0. If ShortURL, expand it. (knownShortFQDN)
|
||||||
|
if ( grep( /^$fqdn$/, @knownShortFQDN ) ) {
|
||||||
|
deb("$target Expand $fqdn");
|
||||||
|
$browser = LWP::UserAgent->new;
|
||||||
|
$answer = HTTP::Request->new( GET => $myurl );
|
||||||
|
$response = $browser->request($answer);
|
||||||
|
|
||||||
|
if ( $response->is_success and $response->previous ) {
|
||||||
|
if ( $myurl ne $response->request->uri ) {
|
||||||
|
$junk = $response->request->uri;
|
||||||
|
if ( index( $junk, 'http' ) == 0 ) {
|
||||||
|
deb("$target Expanded $fqdn");
|
||||||
|
$myurl = $junk;
|
||||||
|
( $junk, $fqdn ) = split( /\/\//, $myurl, 2 );
|
||||||
|
( $fqdn, $junk ) = split( /\//, $fqdn, 2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
## ACT1: Update URL if Cloudflared
|
## ACT1: Update URL if Cloudflared
|
||||||
if ( grep( /^$fqdn$/, @cached ) ) {
|
if ( grep( /^$fqdn$/, @cached ) ) {
|
||||||
deb("$target Found in Cache $fqdn");
|
deb("$target Found in Cache $fqdn");
|
||||||
$mytype = '^B^C3[Archive]^O ';
|
$mytype = '^B^C3[Archive]^O ';
|
||||||
$myurl = 'https://web.archive.org/web/' . $myurl;
|
$myurl = 'https://web.archive.org/web/' . $myurl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( $cfg_uselocaldb == 1 ) {
|
if ( $cfg_uselocaldb == 1 ) {
|
||||||
deb("$target Lookup local DB about $fqdn");
|
deb("$target Lookup local DB about $fqdn");
|
||||||
open( CFSFILE,$cfg_localdbpath. "cloudflare_". substr( $fqdn, 0, 1 ). ".txt" ) or die "file not found for $fqdn";
|
open( CFSFILE,
|
||||||
|
$cfg_localdbpath
|
||||||
|
. "cloudflare_"
|
||||||
|
. substr( $fqdn, 0, 1 )
|
||||||
|
. ".txt" )
|
||||||
|
or die "file not found for $fqdn";
|
||||||
$ifoundit = 0;
|
$ifoundit = 0;
|
||||||
while (<CFSFILE>) {
|
while (<CFSFILE>) {
|
||||||
$line = $_;
|
$line = $_;
|
||||||
@ -164,7 +212,7 @@ sub GotUrl {
|
|||||||
if ( $ifoundit == 1 ) {
|
if ( $ifoundit == 1 ) {
|
||||||
push( @cached, $fqdn );
|
push( @cached, $fqdn );
|
||||||
$mytype = '^B^C3[Archive]^O ';
|
$mytype = '^B^C3[Archive]^O ';
|
||||||
$myurl = 'https://web.archive.org/web/' . $myurl;
|
$myurl = 'https://web.archive.org/web/' . $myurl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -178,7 +226,7 @@ sub GotUrl {
|
|||||||
if ( $answer eq '[true,true]' ) {
|
if ( $answer eq '[true,true]' ) {
|
||||||
push( @cached, $fqdn );
|
push( @cached, $fqdn );
|
||||||
$mytype = '^B^C3[Archive]^O ';
|
$mytype = '^B^C3[Archive]^O ';
|
||||||
$myurl = 'https://web.archive.org/web/' . $myurl;
|
$myurl = 'https://web.archive.org/web/' . $myurl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,23 +241,32 @@ sub GotUrl {
|
|||||||
$response = $browser->get($url);
|
$response = $browser->get($url);
|
||||||
$answer = $response->content;
|
$answer = $response->content;
|
||||||
if ( index( $answer, 'https://ux.nu/' ) == 0 ) {
|
if ( index( $answer, 'https://ux.nu/' ) == 0 ) {
|
||||||
if ($mytype eq ''){
|
if ( $mytype eq '' ) {
|
||||||
$mytype = '^B^C7[Short]^O ';
|
$mytype = '^B^C7[Short]^O ';
|
||||||
}else{
|
}
|
||||||
$mytype = '^B^C2[Short,Archive]^O ';
|
else {
|
||||||
|
$mytype = '^B^C2[Short,Archive]^O ';
|
||||||
}
|
}
|
||||||
$myurl = $answer;
|
$myurl = $answer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
##ACT3: Shout Result
|
##ACT3: Result
|
||||||
if ( $cfg_send2chan == 1 ) {
|
if ( $cfg_printurl == 1 ) {
|
||||||
$server->command("msg $target $myurl");
|
Irssi::print("URL: $mytype$myurl");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$server->print( "$target", "$mytype$myurl", MSGLEVEL_CLIENTCRAP );
|
if ( $cfg_donotsendurl != 1 ) {
|
||||||
|
if ( $cfg_send2chan == 1 ) {
|
||||||
|
$server->command("msg $target $myurl");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$server->print( "$target", "$mytype$myurl",
|
||||||
|
MSGLEVEL_CLIENTCRAP );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
## End of Act
|
## End of Act
|
||||||
}
|
}
|
||||||
deb("$target process done for input $myurl");
|
deb("$target process done for input $myurl");
|
||||||
|
Loading…
Reference in New Issue
Block a user