root/branch/PreferencesWindow/umitExport/HTML/Parse.py @ 3650

Revision 3650, 5.2 kB (checked in by luis, 5 years ago)

Changed locate of style and fix table style

Line 
1# Copyright (C) 2008 Adriano Monteiro Marques.
2#
3# Author: Luis A. Bastiao Silva <luis.kop@gmail.com>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19
20from umitExport.Parse import Export
21from umitExport.HTML.Codes import Node, STYLE
22
23BR = Node(None, None, "<br />")
24
25class ExportHTML(Export):
26    def __init__(self, parse, filename):
27        Export.__init__(self, parse, filename)
28       
29        # Head Structure
30        self.head = Node('html')
31        head = Node('head')
32        self.head.add_child(head)
33        self.add_style(STYLE)
34    def add_style(self, style_t):
35        headtag = self.head.get_childs()[0]
36        style = Node('style', [{'name':'type', 'value':'text/css'}])
37        style.add_child(Node(None, None ,style_t))
38        headtag.add_child(style)
39    def get(self):
40        return self.generate_html()
41    def get_name(self):
42        np = self.parse
43        if np.scan_name == "":
44            name = "Unnamed"
45        else:
46            name = np.scan_name
47        return name
48    def generate_html(self):
49       
50        # Header / Title
51        np = self.parse
52        head = self.head.get_childs()[0]
53
54        head.add_child(Node('title',text = self.get_name()\
55                            + " - "  + np.profile_name ))
56        body = self.get_body(head)
57        self.head.add_child(body)
58        hosts = self.get_hosts()
59       
60       
61        # Packing Body
62        body.add_child(Node(None, text="<h1><b>"+self.get_name()+" - "+\
63                            np.profile_name+\
64                            "</b></h1>"+"</br></br>" ))
65        body.add_child(self.get_nmap_command())
66       
67        title = Node(None, None, '<b><h2>Available hosts:</h2></b> <br />')
68        body.add_child(title)
69        body.add_child(hosts)
70       
71        # Services
72       
73        title = Node(None, None, '<b><h2>Services:</h2></b> <br />')
74        body.add_child(title)
75        services = self.get_port_services()
76        body.add_child(services)
77        body.add_child(self.get_nmap_output())
78        return self.head.get_html()
79    def get_body(self, head):
80        # Customize Page
81        body = Node('body')
82        return body
83   
84    def get_nmap_command(self):
85        nmap = Node(None,None, "Nmap command: <b>" + self.parse.nmap_command + \
86                    "</b><br /><br />")
87        return nmap
88   
89    def get_hosts(self):
90       
91       
92       
93        table = Node('table', [{'name':'border', 'value':'1'}])
94       
95        res = self.get_list_host()
96       
97        for i in res:
98            tr = Node('tr')
99            # Ip
100            td = Node('td')
101            td.add_child(Node(None, None, i['_ip']['addr']))
102            tr.add_child(td)
103           
104            #FIXME <- Verify ALL
105           
106            # OS Classes Values
107            for j in i['_osclasses']:
108                for key in j:
109                    value =  j[key]
110                    td = Node('td')
111                    td.add_child(Node(None, None, value))
112                    tr.add_child(td)
113               
114                       
115            # OS Matches Values
116            for key in i['_osmatch']:
117                value =  i['_osmatch'][key]
118                td = Node('td')
119                td.add_child(Node(None, None, value))
120                tr.add_child(td)
121            table.add_child(tr)
122           
123        return table
124   
125    def get_port_services(self):
126        """
127        Returns port and services
128        """
129       
130       
131        group = Node('div', [{'name':'width', 'value':'60%'}])
132       
133        res = self.get_list_host()
134       
135        for host in res:
136            table = Node('table', [{'name':'border', 'value':'1'}, \
137                                   {'name':'width', 'value':'60%'}])
138            for portlist in host['_ports'][0]['port']:
139                tr = Node('tr')
140                for port in portlist:
141                   
142                    td = Node('td')
143                    td.add_child(Node(None, None, \
144                                      portlist[port]))
145                    tr.add_child(td)
146                table.add_child(tr)
147               
148            group.add_child(table)
149            group.add_child(BR)
150        return group
151    def get_nmap_output(self):
152        """ Return Node with nmap output """
153       
154        div = Node('div',[{'name':'width', 'value':'60%'}])
155        title = Node(None, None, '<b><h2>Nmap outpuut:</h2></b> <br />')
156        div.add_child(title)
157       
158        pre = Node('pre' , [{'name':'width', 'value':'60%'}])
159        output = Node(None, None, self.parse.nmap_output)
160        pre.add_child(output)
161        div.add_child(pre)
162       
163        return div
Note: See TracBrowser for help on using the browser.