-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkurl.cgi
61 lines (44 loc) · 1.35 KB
/
mkurl.cgi
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
#!/usr/bin/perl
use strict;
use CGI qw(param);
use WebService::Bitly;
my $bitly_user = "-----put your bitly username here------";
my $bitly_api = "---------------put your bitly key here---------";
my $page_tile = "My link shortener";
my $domain_url = "http://mydomain.com";
my $cgi_location = "/cgi-bin/mkurl.cgi";
my $query = new CGI;
print $query->header;
print $query->start_html($page_tile);
my $url=$query->param('URLValue');
print '<form method="post" action="'.$cgi_location.'" name="URLForm">';
print '<input tabindex="2" id="mkbutton" value="Make URL" type="submit">';
print '<input tabindex="1" maxlength="4096" size="80" id="URLValue" name="URLValue">';
print '</form>';
if ($url)
{
my $bitly = WebService::Bitly->new(
user_name => $bitly_user,
user_api_key => $bitly_api,
);
my $shorten = $bitly->shorten($url);
if (!$shorten->is_error)
{
$url = $shorten->short_url;
}
else
{
undef $url;
}
if ($url)
{
$url =~ m/http\:\/\/bit\.ly\/(.*)/;
my $extracted_url = $1;
print '<script language="javascript" type="text/javascript">';
print 'document.URLForm.URLValue.value = "'.$domain_url.$cgi_location.'?'.$extracted_url.'";';
print 'document.getElementById( "URLValue" ).select();';
print "</script>";
}
}
print $query->end_html;
exit;