mirror of
https://codeberg.org/crimeflare/cloudflare-tor
synced 2024-11-09 02:42:42 +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_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;
|
||||
@ -21,6 +24,7 @@ use vars qw($VERSION %IRSSI);
|
||||
|
||||
$VERSION = "20190506";
|
||||
%IRSSI = (
|
||||
|
||||
# Special thanks to: "eo, tsaavik"
|
||||
authors => "Anonymous",
|
||||
contact => 'anonymous@cloudflare-tor.nab',
|
||||
@ -35,7 +39,11 @@ use Irssi::Irc;
|
||||
use LWP::Simple;
|
||||
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 = ();
|
||||
|
||||
sub setuphandler {
|
||||
@ -90,6 +98,18 @@ sub setuphandler {
|
||||
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 {
|
||||
@ -102,6 +122,7 @@ sub GotUrl {
|
||||
$data =~ s/^\s+//;
|
||||
$data =~ s/\s+$//;
|
||||
my @urls = ();
|
||||
my @knownShortFQDN = ( 'tinyurl.com', 'bit.ly' );
|
||||
my ( $url, $a, $return, $char, $ch ) = "";
|
||||
my $same = 0;
|
||||
|
||||
@ -140,6 +161,28 @@ sub GotUrl {
|
||||
|
||||
if ( length($fqdn) >= 4 ) {
|
||||
## 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
|
||||
if ( grep( /^$fqdn$/, @cached ) ) {
|
||||
deb("$target Found in Cache $fqdn");
|
||||
@ -149,7 +192,12 @@ sub GotUrl {
|
||||
else {
|
||||
if ( $cfg_uselocaldb == 1 ) {
|
||||
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;
|
||||
while (<CFSFILE>) {
|
||||
$line = $_;
|
||||
@ -193,9 +241,10 @@ sub GotUrl {
|
||||
$response = $browser->get($url);
|
||||
$answer = $response->content;
|
||||
if ( index( $answer, 'https://ux.nu/' ) == 0 ) {
|
||||
if ($mytype eq ''){
|
||||
if ( $mytype eq '' ) {
|
||||
$mytype = '^B^C7[Short]^O ';
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
$mytype = '^B^C2[Short,Archive]^O ';
|
||||
}
|
||||
$myurl = $answer;
|
||||
@ -203,13 +252,21 @@ sub GotUrl {
|
||||
}
|
||||
}
|
||||
|
||||
##ACT3: Shout Result
|
||||
##ACT3: Result
|
||||
if ( $cfg_printurl == 1 ) {
|
||||
Irssi::print("URL: $mytype$myurl");
|
||||
}
|
||||
|
||||
if ( $cfg_donotsendurl != 1 ) {
|
||||
if ( $cfg_send2chan == 1 ) {
|
||||
$server->command("msg $target $myurl");
|
||||
}
|
||||
else {
|
||||
$server->print( "$target", "$mytype$myurl", MSGLEVEL_CLIENTCRAP );
|
||||
$server->print( "$target", "$mytype$myurl",
|
||||
MSGLEVEL_CLIENTCRAP );
|
||||
}
|
||||
}
|
||||
|
||||
## End of Act
|
||||
}
|
||||
deb("$target process done for input $myurl");
|
||||
|
Loading…
Reference in New Issue
Block a user