forked from infobyte/faraday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfplugin_utils.py
80 lines (57 loc) · 2.5 KB
/
fplugin_utils.py
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
71
72
73
74
75
76
77
78
79
80
import imp
import os
import sys
from colorama import Fore
from config.configuration import getInstanceConfiguration
CONF = getInstanceConfiguration()
def get_available_plugins():
faraday_directory = os.path.dirname(os.path.realpath(os.path.join(__file__, "../")))
scan_path = os.path.join(faraday_directory, "bin/")
plugin_list = os.listdir(scan_path)
if 'fplugin' in plugin_list:
plugin_list.remove('fplugin')
plugin_list = filter(lambda p: p[-3:] == '.py', plugin_list)
plugins_dic = {}
for plugin in plugin_list:
plugin_path = os.path.join(scan_path, plugin)
try:
plugin_name = os.path.splitext(plugin)[0]
module = imp.load_source('module_fplugin_%s' % plugin_name, plugin_path)
try:
description = getattr(module, '__description__')
except AttributeError:
description = 'Empty'
sys.stderr.write(Fore.YELLOW +
"WARNING: Plugin missing a description. Please update it! [%s]\n" % plugin +
Fore.RESET)
try:
prettyname = getattr(module, '__prettyname__')
except AttributeError:
prettyname = plugin_name
sys.stderr.write(Fore.YELLOW +
"WARNING: Plugin missing a pretty name. Please update it! [%s]\n" % plugin +
Fore.RESET)
try:
main = getattr(module, 'main')
except AttributeError:
main = None
sys.stderr.write(Fore.YELLOW +
"WARNING: Plugin missing a main function. Please fix it! [%s]\n" % plugin +
Fore.RESET)
plugins_dic[plugin[:-3]] = {
'description': description,
'prettyname': prettyname,
'main': main
}
except Exception:
sys.stderr.write("Unable to import module %s\n" % plugin_path)
return plugins_dic
def build_faraday_plugin_command(plugin, workspace_name, absolute_path=False):
faraday_directory = os.path.dirname(os.path.realpath(os.path.join(__file__, "../")))
path = os.path.join(faraday_directory, "bin/")
return '{path}fplugin {command} -u {url} -w {workspace} '.format(
path='"%s"' % path if absolute_path else '',
command=plugin,
url=CONF.getCouchURI(),
workspace=workspace_name
)