1package models
2
3// WordPressPackages has Core version, plugins and themes.
4type WordPressPackages []WpPackage
5
6// CoreVersion returns the core version of the installed WordPress
7func (w WordPressPackages) CoreVersion() string {
8	for _, p := range w {
9		if p.Type == WPCore {
10			return p.Version
11		}
12	}
13	return ""
14}
15
16// Plugins returns a slice of plugins of the installed WordPress
17func (w WordPressPackages) Plugins() (ps []WpPackage) {
18	for _, p := range w {
19		if p.Type == WPPlugin {
20			ps = append(ps, p)
21		}
22	}
23	return
24}
25
26// Themes returns a slice of themes of the installed WordPress
27func (w WordPressPackages) Themes() (ps []WpPackage) {
28	for _, p := range w {
29		if p.Type == WPTheme {
30			ps = append(ps, p)
31		}
32	}
33	return
34}
35
36// Find searches by specified name
37func (w WordPressPackages) Find(name string) (ps *WpPackage, found bool) {
38	for _, p := range w {
39		if p.Name == name {
40			return &p, true
41		}
42	}
43	return nil, false
44}
45
46const (
47	// WPCore is a type `core` in WPPackage struct
48	WPCore = "core"
49	// WPPlugin is a type `plugin` in WPPackage struct
50	WPPlugin = "plugin"
51	// WPTheme is a type `theme` in WPPackage struct
52	WPTheme = "theme"
53
54	// Inactive is a inactive status in WPPackage struct
55	Inactive = "inactive"
56)
57
58// WpPackage has a details of plugin and theme
59type WpPackage struct {
60	Name    string `json:"name,omitempty"`
61	Status  string `json:"status,omitempty"` // active, inactive or must-use
62	Update  string `json:"update,omitempty"` // available or none
63	Version string `json:"version,omitempty"`
64	Type    string `json:"type,omitempty"` // core, plugin, theme
65}
66
67// WpPackageFixStatus is used in Vulninfo.WordPress
68type WpPackageFixStatus struct {
69	Name    string `json:"name,omitempty"`
70	FixedIn string `json:"fixedIn,omitempty"`
71}
72