This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 265
/
list.go
176 lines (161 loc) · 4.3 KB
/
list.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package plugins
import (
"fmt"
"strings"
"github.com/crackcomm/go-clitable"
"github.com/maliceio/malice/utils"
)
// ListEnabledPlugins lists enabled plugins
func ListEnabledPlugins(detail bool) {
// TODO: Create a template for this kind of output : http://stackoverflow.com/questions/10747054/special-case-treatment-for-the-last-element-of-a-range-in-google-gos-text-templ
enabled := getEnabled(Plugs.Plugins)
if detail {
ToMarkDownTable(enabled)
} else {
for _, plugin := range enabled {
fmt.Println(plugin.Name)
}
}
}
// ListAllPlugins lists all plugins
func ListAllPlugins(detail bool) {
plugins := Plugs.Plugins
if detail {
ToMarkDownTable(plugins)
} else {
for _, plugin := range plugins {
fmt.Println(plugin.Name)
}
}
}
// ToMarkDownTable prints plugins out as Markdown table
func ToMarkDownTable(plugins []Plugin) {
table := clitable.New([]string{"Name", "Description", "Enabled", "Image", "Category", "Mime"})
for _, plugin := range plugins {
table.AddRow(map[string]interface{}{
"Name": plugin.Name,
"Description": plugin.Description,
"Enabled": plugin.Enabled,
"Image": plugin.Image,
"Category": plugin.Category,
"Mime": plugin.Mime,
})
}
table.Markdown = true
table.Print()
}
// GetPluginByName will return plugin for the given name
func GetPluginByName(name string) Plugin {
for _, plugin := range Plugs.Plugins {
if strings.EqualFold(plugin.Name, name) {
return plugin
}
}
return Plugin{}
}
// GetIntelPlugins will return all Intel plugins
func GetIntelPlugins(hashType string, enabled bool) []Plugin {
var intelPlugs []Plugin
if enabled {
intelPlugs = getIntel(getEnabled(getInstalled()))
} else {
intelPlugs = getIntel(getInstalled())
}
// filter down to intel plugins with apikey's set in ENV
// var allSet bool
// var hasEnvPlugs []Plugin
// for _, plugin := range intelPlugs {
// allSet = true
// for _, pluginEnv := range plugin.Env {
// if os.Getenv(pluginEnv) == "" {
// allSet = false
// }
// }
// if allSet {
// if utils.StringInSlice(hashType, plugin.HashTypes) {
// hasEnvPlugs = append(hasEnvPlugs, plugin)
// }
// }
// }
return intelPlugs
}
// GetPluginsForMime will return all plugins that can consume the mime type file
func GetPluginsForMime(mime string, enabled bool) []Plugin {
if enabled {
return getMime(mime, getEnabled(getInstalled()))
}
return getMime(mime, getInstalled())
}
func getIntel(plugins []Plugin) []Plugin {
intel := []Plugin{}
if plugins == nil {
plugins = Plugs.Plugins
}
for _, plugin := range plugins {
if strings.Contains(plugin.Category, "intel") {
intel = append(intel, plugin)
}
}
return intel
}
// getInstalled returns a map[string]plugin of installed plugins
func getInstalled() []Plugin {
installed := []Plugin{}
for _, plugin := range Plugs.Plugins {
if plugin.Installed {
installed = append(installed, plugin)
}
}
return installed
}
// GetCategories returns all categories
func GetCategories() []string {
categories := []string{}
for _, plugin := range Plugs.Plugins {
if !utils.StringInSlice(plugin.Category, categories) {
categories = append(categories, plugin.Category)
}
}
return categories
}
// GetAllPluginsInCategory returns all plugins in a give category
func GetAllPluginsInCategory(category string) []Plugin {
inCategory := []Plugin{}
for _, plugin := range Plugs.Plugins {
if strings.EqualFold(plugin.Category, category) {
inCategory = append(inCategory, plugin)
}
}
return inCategory
}
// GetEnabledPlugins will return all enabled plugins
func GetEnabledPlugins() []Plugin {
return getEnabled(Plugs.Plugins)
}
// filterPluginsByEnabled returns a map[string]plugin of plugins
// that work on the given mime type
func getMime(mime string, plugins []Plugin) []Plugin {
mimeMatch := []Plugin{}
if plugins == nil {
plugins = Plugs.Plugins
}
for _, plugin := range plugins {
if strings.Contains(plugin.Mime, mime) || strings.Contains(plugin.Mime, "*") {
mimeMatch = append(mimeMatch, plugin)
}
}
return mimeMatch
}
// getEnabled returns a map[string]plugin of enabled plugins
func getEnabled(plugins []Plugin) []Plugin {
enabled := []Plugin{}
if plugins == nil {
return Plugs.Plugins
}
for _, plugin := range Plugs.Plugins {
if plugin.Enabled {
enabled = append(enabled, plugin)
}
}
return enabled
}