| 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 |  |  | 	// Inactive is a inactive status in WPPackage struct | 
            
                                                        
            
                                    
            
            
                | 72 |  |  | 	Inactive = "inactive" | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | ) | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 75 |  |  | // WpPackage has a details of plugin and theme | 
            
                                                        
            
                                    
            
            
                | 76 |  |  | type WpPackage struct { | 
            
                                                        
            
                                    
            
            
                | 77 |  |  | 	Name    string `json:"name,omitempty"` | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | 	Status  string `json:"status,omitempty"` // active, inactive or must-use | 
            
                                                        
            
                                    
            
            
                | 79 |  |  | 	Update  string `json:"update,omitempty"` // available or none | 
            
                                                        
            
                                    
            
            
                | 80 |  |  | 	Version string `json:"version,omitempty"` | 
            
                                                        
            
                                    
            
            
                | 81 |  |  | 	Type    string `json:"type,omitempty"` // core, plugin, theme | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | // WpPackageFixStatus is used in Vulninfo.WordPress | 
            
                                                        
            
                                    
            
            
                | 85 |  |  | type WpPackageFixStatus struct { | 
            
                                                        
            
                                    
            
            
                | 86 |  |  | 	Name    string `json:"name,omitempty"` | 
            
                                                        
            
                                    
            
            
                | 87 |  |  | 	FixedIn string `json:"fixedIn,omitempty"` | 
            
                                                        
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  |