Completed
Pull Request — master (#769)
by kota
14:05
created

models.WordPressPackages.Themes   A

Complexity

Conditions 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
nop 0
1
/* Vuls - Vulnerability Scanner
2
Copyright (C) 2016  Future Corporation , Japan.
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
package models
19
20
// WordPressPackages has Core version, plugins and themes.
21
type WordPressPackages []WpPackage
22
23
// CoreVersion returns the core version of the installed WordPress
24
func (w WordPressPackages) CoreVersion() string {
25
	for _, p := range w {
26
		if p.Type == WPCore {
27
			return p.Version
28
		}
29
	}
30
	return ""
31
}
32
33
// Plugins returns a slice of plugins of the installed WordPress
34
func (w WordPressPackages) Plugins() (ps []WpPackage) {
35
	for _, p := range w {
36
		if p.Type == WPPlugin {
37
			ps = append(ps, p)
38
		}
39
	}
40
	return
41
}
42
43
// Themes returns a slice of themes of the installed WordPress
44
func (w WordPressPackages) Themes() (ps []WpPackage) {
45
	for _, p := range w {
46
		if p.Type == WPTheme {
47
			ps = append(ps, p)
48
		}
49
	}
50
	return
51
}
52
53
// Find searches by specified name
54
func (w WordPressPackages) Find(name string) (ps *WpPackage, found bool) {
55
	for _, p := range w {
56
		if p.Name == name {
57
			return &p, true
58
		}
59
	}
60
	return nil, false
61
}
62
63
const (
64
	// WPCore is a type `core` in WPPackage struct
65
	WPCore = "core"
66
	// WPPlugin is a type `plugin` in WPPackage struct
67
	WPPlugin = "plugin"
68
	// WPTheme is a type `theme` in WPPackage struct
69
	WPTheme = "theme"
70
)
71
72
// WpPackage has a details of plugin and theme
73
type WpPackage struct {
74
	Name    string `json:"name,omitempty"`
75
	Status  string `json:"status,omitempty"` // activfe, inactive or must-use
76
	Update  string `json:"update,omitempty"` // avaliable or none
77
	Version string `json:"version,omitempty"`
78
	Type    string `json:"type,omitempty"` // core, plugin, theme
79
}
80
81
// WpPackageFixStatus is used in Vulninfo.WordPress
82
type WpPackageFixStatus struct {
83
	Name    string `json:"name,omitempty"`
84
	FixedIn string `json:"fixedIn,omitempty"`
85
}
86