| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | # Copyright (C) 2005 Insecure.Com LLC. |
|---|
| 5 | # |
|---|
| 6 | # Author: Adriano Monteiro Marques <py.adriano@gmail.com> |
|---|
| 7 | # Cleber Rodrigues <cleber.gnu@gmail.com> |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License as published by |
|---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | # (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program; if not, write to the Free Software |
|---|
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 22 | |
|---|
| 23 | import gtk |
|---|
| 24 | import gobject |
|---|
| 25 | import re |
|---|
| 26 | import sys |
|---|
| 27 | import os.path |
|---|
| 28 | |
|---|
| 29 | from umitCore.Paths import Path |
|---|
| 30 | from umitCore.UmitConf import is_maemo |
|---|
| 31 | from umitCore.UmitLogging import log |
|---|
| 32 | |
|---|
| 33 | icon_names = ( |
|---|
| 34 | # Operating Systems |
|---|
| 35 | 'default', |
|---|
| 36 | 'freebsd', |
|---|
| 37 | 'irix', |
|---|
| 38 | 'linux', |
|---|
| 39 | 'macosx', |
|---|
| 40 | 'openbsd', |
|---|
| 41 | 'redhat', |
|---|
| 42 | 'shadow_man', |
|---|
| 43 | 'solaris', |
|---|
| 44 | 'ubuntu', |
|---|
| 45 | 'unknown', |
|---|
| 46 | 'win', |
|---|
| 47 | # Vulnerability Levels |
|---|
| 48 | 'vl_1', |
|---|
| 49 | 'vl_2', |
|---|
| 50 | 'vl_3', |
|---|
| 51 | 'vl_4', |
|---|
| 52 | 'vl_5') |
|---|
| 53 | |
|---|
| 54 | pixmap_path = Path.pixmaps_dir |
|---|
| 55 | if pixmap_path: |
|---|
| 56 | # This is a generator that returns file names for pixmaps in the order they |
|---|
| 57 | # should be tried. |
|---|
| 58 | def get_pixmap_file_names(icon_name, size): |
|---|
| 59 | yield '%s.svg' % icon_name |
|---|
| 60 | yield '%s_%s.png' % (icon_name, size) |
|---|
| 61 | |
|---|
| 62 | iconfactory = gtk.IconFactory() |
|---|
| 63 | for icon_name in icon_names: |
|---|
| 64 | for type, size in (('icon', '32'), ('logo', '75')): |
|---|
| 65 | key = '%s_%s' % (icon_name, type) |
|---|
| 66 | # Look for a usable image file. |
|---|
| 67 | for file_name in get_pixmap_file_names(icon_name, size): |
|---|
| 68 | file_path = os.path.join(pixmap_path, file_name) |
|---|
| 69 | try: |
|---|
| 70 | pixbuf = gtk.gdk.pixbuf_new_from_file(file_path) |
|---|
| 71 | break |
|---|
| 72 | except gobject.GError: |
|---|
| 73 | # Try again. |
|---|
| 74 | pass |
|---|
| 75 | else: |
|---|
| 76 | log.warn('Could not find the icon for %s at any of (%s) in %s' % (icon_name, ', '.join(get_pixmap_file_names(icon_name, size)), pixmap_path)) |
|---|
| 77 | continue |
|---|
| 78 | iconset = gtk.IconSet(pixbuf) |
|---|
| 79 | iconfactory.add(key, iconset) |
|---|
| 80 | log.debug('Register %s icon name for file %s' % (key, file_path)) |
|---|
| 81 | iconfactory.add_default() |
|---|
| 82 | |
|---|
| 83 | def get_os_icon(os_match): |
|---|
| 84 | return get_os(os_match, 'icon') |
|---|
| 85 | |
|---|
| 86 | def get_os_logo(os_match): |
|---|
| 87 | return get_os(os_match, 'logo') |
|---|
| 88 | |
|---|
| 89 | def get_os(os_match, type): |
|---|
| 90 | if os_match: |
|---|
| 91 | if re.findall('[rR][eE][dD][ ]+[hH][aA][tT]', os_match): |
|---|
| 92 | # Linux icon |
|---|
| 93 | return 'redhat_%s'%type |
|---|
| 94 | elif re.findall('[uU][bB][uU][nN][tT][uU]', os_match): |
|---|
| 95 | # Linux icon |
|---|
| 96 | return 'ubuntu_%s'%type |
|---|
| 97 | elif re.findall('[lL][iI][nN][uU][xX]', os_match): |
|---|
| 98 | # Linux icon |
|---|
| 99 | return 'linux_%s'%type |
|---|
| 100 | elif re.findall('[wW][iI][nN][dD][oO][wW][sS]', os_match): |
|---|
| 101 | #print '>>> Match windows!' |
|---|
| 102 | # Windows icon |
|---|
| 103 | return 'win_%s'%type |
|---|
| 104 | elif re.findall('[oO][pP][eE][nN][bB][sS][dD]', os_match): |
|---|
| 105 | # OpenBSD icon |
|---|
| 106 | return 'openbsd_%s'%type |
|---|
| 107 | elif re.findall('[fF][rR][eE][eE][bB][sS][dD]', os_match): |
|---|
| 108 | # FreeBSD icon |
|---|
| 109 | return 'freebsd_%s'%type |
|---|
| 110 | elif re.findall('[nN][eE][tT][bB][sS][dD]', os_match): |
|---|
| 111 | # NetBSD icon |
|---|
| 112 | return 'default_%s'%type |
|---|
| 113 | elif re.findall('[sS][oO][lL][aA][rR][iI][sS]',os_match): |
|---|
| 114 | # Solaris icon |
|---|
| 115 | return 'solaris_%s'%type |
|---|
| 116 | elif re.findall('[oO][pP][eE][nN].*[sS][oO][lL][aA][rR][iI][sS]',\ |
|---|
| 117 | os_match): |
|---|
| 118 | # OpenSolaris icon |
|---|
| 119 | return 'solaris_%s'%type |
|---|
| 120 | elif re.findall('[iI][rR][iI][xX]',os_match): |
|---|
| 121 | # Irix icon |
|---|
| 122 | return 'irix_%s'%type |
|---|
| 123 | elif re.findall('[mM][aA][cC].*[oO][sS].*[xX]',os_match): |
|---|
| 124 | # Mac OS X icon |
|---|
| 125 | return 'macosx_%s'%type |
|---|
| 126 | elif re.findall('[mM][aA][cC].*[oO][sS]',os_match): |
|---|
| 127 | # Mac OS icon |
|---|
| 128 | return 'macosx_%s'%type |
|---|
| 129 | else: |
|---|
| 130 | # Default OS icon |
|---|
| 131 | return 'default_%s'%type |
|---|
| 132 | else: |
|---|
| 133 | # This is the icon for unkown OS |
|---|
| 134 | # Can't be a scary icon, like stop, cancel, etc. |
|---|
| 135 | return 'unknown_%s'%type |
|---|
| 136 | |
|---|
| 137 | def get_vulnerability_logo(open_ports): |
|---|
| 138 | open_ports = int(open_ports) |
|---|
| 139 | if open_ports < 3: |
|---|
| 140 | return 'vl_1_logo' |
|---|
| 141 | elif open_ports < 5: |
|---|
| 142 | return 'vl_2_logo' |
|---|
| 143 | elif open_ports < 7: |
|---|
| 144 | return 'vl_3_logo' |
|---|
| 145 | elif open_ports < 9: |
|---|
| 146 | return 'vl_4_logo' |
|---|
| 147 | else: |
|---|
| 148 | return 'vl_5_logo' |
|---|