/usr/share/irssi/scripts/tinyurl.pl is in irssi-scripts 20131030.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #!/usr/bin/perl
#
# Maintained by Stuart Powers
# stuart.powers@gmail.com
# http://sente.cc/misc/tinyurl.pl
use strict;
use IO::Socket;
use LWP::UserAgent;
use vars qw($VERSION %IRSSI);
use Irssi qw(command_bind active_win);
$VERSION = '1.1';
%IRSSI = (
authors => 'Stuart Powers, previously Atoms',
contact => 'stuart.powers@gmail.com',
name => 'tinyurl',
description => 'create a tinyurl from a long one',
license => 'GPL',
);
command_bind(
tinyurl => sub {
my ($msg, $server, $witem) = @_;
my $answer = tinyurl($msg);
if ($answer) {
print CLIENTCRAP "$answer";
if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')) {
$witem->command("MSG " . $witem->{name} ." ". $answer);
}
}
}
);
sub tinyurl {
my $url = shift;
#added to fix URLs containing a '&'
$url=url_encode($url);
my $ua = LWP::UserAgent->new;
$ua->agent("tinyurl for irssi/1.0 ");
my $req = HTTP::Request->new(POST => 'http://tinyurl.com/create.php');
$req->content_type('application/x-www-form-urlencoded');
$req->content("url=$url");
my $res = $ua->request($req);
if ($res->is_success){
return get_tiny_url($res->content);
}
else{
print CLIENTCRAP "ERROR: tinyurl: tinyurl is down or not pingable";
return "";
}
}
#added because the URL was not being url_encoded. This would cause URLS
#which contained &'s and other characters to not be properly sent
sub url_encode {
my $url = shift;
$url =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
return $url;
}
#added because tinyurl.com changed their HTML output
sub get_tiny_url($) {
my $tiny_url_body = shift;
$tiny_url_body =~ />(\w*?:\/\/)preview.(tinyurl.com\/.*?)</;
return "$1$2";
}
|