Skip to content

Commit

Permalink
First bitly plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-k committed Sep 26, 2017
1 parent 2636c8c commit c030c9c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
38 changes: 34 additions & 4 deletions harpoon/commands/bitly.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
#! /usr/bin/env python
import sys
from harpoon.commands.base import Command
from harpoon.lib.bitly import Bitly
from harpoon.lib.bitly import Bitly, Link

class CommandBitly(Command):
name = "bitly"

def run(self):
print('Bitly')

def add_arguments(self, parser):
parser.add_argument('--hash', '-H', help='HASH of a link')
parser.add_argument('--file', '-f', help='File containing list of hashes')

def run(self, conf, args):
if 'Bitly' not in conf and 'token' not in conf['Bitly']:
print('Invalid configuration file, quitting...')
sys.exit(1)
bitly = Bitly(access_token=conf['Bitly']["token"])
if args.hash:
link = Link(bitly, args.hash)
link.pprint()
elif args.file:
f = open(args.file, 'r')
data = f.read().split()
print("Date;Short URL;Long URL;Analytics;Aggregate;Aggregate Hash;User;Short URL Clicks;Long URL Clicks")
for d in data:
if d.strip() != "":
link = Link(bitly, d)
print("%s;%s;%s;%s;%s;%s;%s;%i;%i" % (
link.timestamp.strftime("%m/%d/%Y %H:%M:%S"),
link.short_url,
link.long_url,
link.short_url + "+",
link.hash if link.is_aggregate else link.aggregate.hash,
"Yes" if link.is_aggregate else "No",
link.user_hash,
link.clicks,
link.clicks if link.is_aggregate else link.aggregate.clicks
)
)
else:
print("Please provide a hash or a file")


11 changes: 10 additions & 1 deletion harpoon/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import os
import sys
import argparse
import configparser
from harpoon.commands.base import Command

def load_config():
config = configparser.ConfigParser()
if os.path.isfile(os.path.join(os.path.expanduser("~"), ".harpoon")):
config.read(os.path.join(os.path.expanduser("~"), ".harpoon"))
return config

def init_plugins():
plugin_dir = os.path.dirname(os.path.realpath(__file__)) + '/commands'
plugin_files = [x[:-3] for x in os.listdir(plugin_dir) if x.endswith(".py")]
Expand All @@ -27,6 +34,8 @@ def main():
sp.set_defaults(command=p)

args = parser.parse_args()
print(args)
config = load_config()

print(args)
print(plugins)
plugins[args.command].run(config, args)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
author='Tek',
author_email='[email protected]',
keywords='osint',
install_requires=['requests', 'click'],
install_requires=['requests', 'configparser'],
license='GPLv3',
packages=['harpoon', 'harpoon.commands'],
entry_points= {
Expand Down

0 comments on commit c030c9c

Please sign in to comment.