WebBrowser/VirusTotal/VirusTotalApi.py

Wed, 07 Feb 2018 20:14:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 07 Feb 2018 20:14:09 +0100
changeset 6121
d3d64f3128b3
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
permissions
-rw-r--r--

Continued removing the use of QObject.sender().

978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
3 # Copyright (c) 2011 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
7 Module implementing the <a href="http://www.virustotal.com">VirusTotal</a>
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
8 API class.
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
11 from __future__ import unicode_literals
2599
2373006616da Fixes for the webbrowser.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
12 try:
5624
cdd346d8858b Removed a bunch of __IGNORE_WARNING_M131__ markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
13 str = unicode # __IGNORE_EXCEPTION__
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
14 except NameError:
2599
2373006616da Fixes for the webbrowser.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
15 pass
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
16
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import json
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
19 from PyQt5.QtCore import pyqtSignal, QObject, QUrl, QUrlQuery, QByteArray
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
20 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
21
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
22 from E5Gui import E5MessageBox
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 import Preferences
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
992
566e87428fc8 Fixed a few PEP-8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 979
diff changeset
26
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class VirusTotalAPI(QObject):
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
29 Class implementing the <a href="http://www.virustotal.com">VirusTotal</a>
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
30 API.
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
31
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
32 @signal checkServiceKeyFinished(bool, str) emitted after the service key
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
33 check has been performed. It gives a flag indicating validity
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
34 (boolean) and an error message in case of a network error (string).
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
35 @signal submitUrlError(str) emitted with the error string, if the URL scan
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
36 submission returned an error.
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
37 @signal urlScanReport(str) emitted with the URL of the URL scan report page
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
38 @signal fileScanReport(str) emitted with the URL of the file scan report
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
39 page
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
41 checkServiceKeyFinished = pyqtSignal(bool, str)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
42 submitUrlError = pyqtSignal(str)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
43 urlScanReport = pyqtSignal(str)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
44 fileScanReport = pyqtSignal(str)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
45
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 TestServiceKeyScanID = \
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 "4feed2c2e352f105f6188efd1d5a558f24aee6971bdf96d5fdb19c197d6d3fad"
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
49 ServiceResult_ItemQueued = -2
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 ServiceResult_ItemNotPresent = 0
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 ServiceResult_ItemPresent = 1
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
53 # HTTP Status Codes
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
54 ServiceCode_InvalidKey = 202
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
55 ServiceCode_RateLimitExceeded = 204
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
56 ServiceCode_InvalidPrivilege = 403
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
58 GetFileReportPattern = "{0}://www.virustotal.com/vtapi/v2/file/report"
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
59 ScanUrlPattern = "{0}://www.virustotal.com/vtapi/v2/url/scan"
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
60 GetUrlReportPattern = "{0}://www.virustotal.com/vtapi/v2/url/report"
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
61 GetIpAddressReportPattern = \
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
62 "{0}://www.virustotal.com/vtapi/v2/ip-address/report"
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
63 GetDomainReportPattern = "{0}://www.virustotal.com/vtapi/v2/domain/report"
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def __init__(self, parent=None):
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Constructor
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param parent reference to the parent object (QObject)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
71 super(VirusTotalAPI, self).__init__(parent)
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
73 self.__replies = []
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
74
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__loadSettings()
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
76
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
77 self.__lastIP = ""
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
78 self.__lastDomain = ""
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
79 self.__ipReportDlg = None
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
80 self.__domainReportDlg = None
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 def __loadSettings(self):
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 Private method to load the settings.
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
86 if Preferences.getWebBrowser("VirusTotalSecure"):
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 protocol = "https"
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 else:
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 protocol = "http"
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.GetFileReportUrl = self.GetFileReportPattern.format(protocol)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.ScanUrlUrl = self.ScanUrlPattern.format(protocol)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.GetUrlReportUrl = self.GetUrlReportPattern.format(protocol)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
93 self.GetIpAddressReportUrl = self.GetIpAddressReportPattern.format(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
94 protocol)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
95 self.GetDomainReportUrl = self.GetDomainReportPattern.format(protocol)
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.errorMessages = {
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
98 204: self.tr("Request limit has been reached."),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
99 0: self.tr("Requested item is not present."),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
100 -2: self.tr("Requested item is still queued."),
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 }
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
103 def preferencesChanged(self):
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
104 """
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
105 Public slot to handle a change of preferences.
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
106 """
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
107 self.__loadSettings()
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
108
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def checkServiceKeyValidity(self, key, protocol=""):
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 Public method to check the validity of the given service key.
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @param key service key (string)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @param protocol protocol used to access VirusTotal (string)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 if protocol == "":
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 urlStr = self.GetFileReportUrl
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 else:
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 urlStr = self.GetFileReportPattern.format(protocol)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 request = QNetworkRequest(QUrl(urlStr))
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 request.setHeader(QNetworkRequest.ContentTypeHeader,
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 "application/x-www-form-urlencoded")
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
123 params = QByteArray("apikey={0}&resource={1}".format(
4331
711e7c35a49b Changed code to make eric compatible to PyQt 5.5 (QByteArry issue).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4326
diff changeset
124 key, self.TestServiceKeyScanID).encode("utf-8"))
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
126 import WebBrowser.WebBrowserWindow
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 .networkManager()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 reply = nam.post(request, params)
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
130 reply.finished.connect(
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
131 lambda: self.__checkServiceKeyValidityFinished(reply))
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
132 self.__replies.append(reply)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
133
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
134 def __checkServiceKeyValidityFinished(self, reply):
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
135 """
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
136 Private slot to determine the result of the service key validity check.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
137
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
138 @param reply reference to the network reply
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
139 @type QNetworkReply
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
140 """
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
141 res = False
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
142 msg = ""
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
143
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 if reply.error() == QNetworkReply.NoError:
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
145 res = True
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
146 elif reply.error() == self.ServiceCode_InvalidKey:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
147 res = False
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
148 else:
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
149 msg = reply.errorString()
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
150 self.__replies.remove(reply)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
151 reply.deleteLater()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
153 self.checkServiceKeyFinished.emit(res, msg)
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 def submitUrl(self, url):
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 Public method to submit an URL to be scanned.
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 @param url url to be scanned (QUrl)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 request = QNetworkRequest(QUrl(self.ScanUrlUrl))
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 request.setHeader(QNetworkRequest.ContentTypeHeader,
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 "application/x-www-form-urlencoded")
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
164 params = QByteArray("apikey={0}&url=".format(
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
165 Preferences.getWebBrowser("VirusTotalServiceKey"))
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
166 .encode("utf-8")).append(QUrl.toPercentEncoding(url.toString()))
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
168 import WebBrowser.WebBrowserWindow
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
169 nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
170 .networkManager()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 reply = nam.post(request, params)
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
172 reply.finished.connect(self.__submitUrlFinished)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
173 self.__replies.append(reply)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
174
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
175 def __submitUrlFinished(self, reply):
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
176 """
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
177 Private slot to determine the result of the URL scan submission.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 @param reply reference to the network reply
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
180 @type QNetworkReply
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
181 """
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if reply.error() == QNetworkReply.NoError:
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 result = json.loads(str(reply.readAll(), "utf-8"))
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
184 if result["response_code"] == self.ServiceResult_ItemPresent:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
185 self.urlScanReport.emit(result["permalink"])
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
186 self.__getUrlScanReportUrl(result["scan_id"])
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 else:
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
188 if result["response_code"] in self.errorMessages:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
189 msg = self.errorMessages[result["response_code"]]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
190 else:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
191 msg = result["verbose_msg"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
192 self.submitUrlError.emit(msg)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
193 elif reply.error() == self.ServiceCode_RateLimitExceeded:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
194 self.submitUrlError.emit(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
195 self.errorMessages[result[self.ServiceCode_RateLimitExceeded]])
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
196 else:
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
197 self.submitUrlError.emit(reply.errorString())
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
198 self.__replies.remove(reply)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
199 reply.deleteLater()
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
200
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
201 def __getUrlScanReportUrl(self, scanId):
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
202 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
203 Private method to get the report URL for a URL scan.
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
204
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
205 @param scanId ID of the scan to get the report URL for (string)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
206 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
207 request = QNetworkRequest(QUrl(self.GetUrlReportUrl))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
208 request.setHeader(QNetworkRequest.ContentTypeHeader,
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
209 "application/x-www-form-urlencoded")
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
210 params = QByteArray("apikey={0}&resource={1}".format(
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
211 Preferences.getWebBrowser("VirusTotalServiceKey"), scanId)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
212 .encode("utf-8"))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
213
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
214 import WebBrowser.WebBrowserWindow
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
215 nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
216 .networkManager()
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
217 reply = nam.post(request, params)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
218 reply.finished.connect(self.__getUrlScanReportUrlFinished)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
219 self.__replies.append(reply)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
220
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
221 def __getUrlScanReportUrlFinished(self, reply):
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
222 """
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
223 Private slot to determine the result of the URL scan report URL.
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
224
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
225 @param reply reference to the network reply
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
226 @type QNetworkReply
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
227 request.
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
228 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
229 if reply.error() == QNetworkReply.NoError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
230 result = json.loads(str(reply.readAll(), "utf-8"))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
231 if "filescan_id" in result and result["filescan_id"] is not None:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
232 self.__getFileScanReportUrl(result["filescan_id"])
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
233 self.__replies.remove(reply)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
234 reply.deleteLater()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
236 def __getFileScanReportUrl(self, scanId):
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 """
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
238 Private method to get the report URL for a file scan.
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 @param scanId ID of the scan to get the report URL for (string)
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
242 request = QNetworkRequest(QUrl(self.GetFileReportUrl))
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 request.setHeader(QNetworkRequest.ContentTypeHeader,
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 "application/x-www-form-urlencoded")
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
245 params = QByteArray("apikey={0}&resource={1}".format(
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
246 Preferences.getWebBrowser("VirusTotalServiceKey"), scanId)
4332
64034d85c709 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4331
diff changeset
247 .encode("utf-8"))
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
249 import WebBrowser.WebBrowserWindow
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
250 nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
251 .networkManager()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 reply = nam.post(request, params)
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
253 reply.finished.connect(self.__getFileScanReportUrlFinished)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
254 self.__replies.append(reply)
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
255
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
256 def __getFileScanReportUrlFinished(self, reply):
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
257 """
2999
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
258 Private slot to determine the result of the file scan report URL
28c75409a78f Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
259 request.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
260
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
261 @param reply reference to the network reply
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
262 @type QNetworkReply
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
263 """
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 if reply.error() == QNetworkReply.NoError:
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 result = json.loads(str(reply.readAll(), "utf-8"))
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
266 self.fileScanReport.emit(result["permalink"])
979
0ae0c8852d31 Refined the VirusTotal code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 978
diff changeset
267 self.__replies.remove(reply)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
268 reply.deleteLater()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
270 def getIpAddressReport(self, ipAddress):
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
271 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
272 Public method to retrieve a report for an IP address.
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
273
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
274 @param ipAddress valid IPv4 address in dotted quad notation
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
275 @type str
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
276 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
277 self.__lastIP = ipAddress
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
278
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
279 queryItems = [
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
280 ("apikey", Preferences.getWebBrowser("VirusTotalServiceKey")),
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
281 ("ip", ipAddress),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
282 ]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
283 url = QUrl(self.GetIpAddressReportUrl)
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
284 query = QUrlQuery()
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
285 query.setQueryItems(queryItems)
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
286 url.setQuery(query)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
287 request = QNetworkRequest(url)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
288
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
289 import WebBrowser.WebBrowserWindow
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
290 nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
291 .networkManager()
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
292 reply = nam.get(request)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
293 reply.finished.connect(self.__getIpAddressReportFinished)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
294 self.__replies.append(reply)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
295
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
296 def __getIpAddressReportFinished(self, reply):
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
297 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
298 Private slot to process the IP address report data.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
299
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
300 @param reply reference to the network reply
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
301 @type QNetworkReply
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 """
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
303 if reply.error() == QNetworkReply.NoError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
304 result = json.loads(str(reply.readAll(), "utf-8"))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
305 if result["response_code"] == 0:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
306 E5MessageBox.information(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
307 None,
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
308 self.tr("VirusTotal IP Address Report"),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
309 self.tr("""VirusTotal does not have any information for"""
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
310 """ the given IP address."""))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
311 elif result["response_code"] == -1:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
312 E5MessageBox.information(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
313 None,
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
314 self.tr("VirusTotal IP Address Report"),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
315 self.tr("""The submitted IP address is invalid."""))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
316 else:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
317 owner = result["as_owner"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
318 resolutions = result["resolutions"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
319 try:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
320 urls = result["detected_urls"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
321 except KeyError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
322 urls = []
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
323
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
324 from .VirusTotalIpReportDialog import VirusTotalIpReportDialog
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
325 self.__ipReportDlg = VirusTotalIpReportDialog(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
326 self.__lastIP, owner, resolutions, urls)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
327 self.__ipReportDlg.show()
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
328 self.__replies.remove(reply)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
329 reply.deleteLater()
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
330
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
331 def getDomainReport(self, domain):
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
332 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
333 Public method to retrieve a report for a domain.
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
334
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
335 @param domain domain name
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
336 @type str
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
337 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
338 self.__lastDomain = domain
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
340 queryItems = [
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4753
diff changeset
341 ("apikey", Preferences.getWebBrowser("VirusTotalServiceKey")),
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
342 ("domain", domain),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
343 ]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
344 url = QUrl(self.GetDomainReportUrl)
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
345 query = QUrlQuery()
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
346 query.setQueryItems(queryItems)
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
347 url.setQuery(query)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
348 request = QNetworkRequest(url)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
349
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
350 import WebBrowser.WebBrowserWindow
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
351 nam = WebBrowser.WebBrowserWindow.WebBrowserWindow\
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
352 .networkManager()
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
353 reply = nam.get(request)
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
354 reply.finished.connect(lambda: self.__getDomainReportFinished(reply))
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
355 self.__replies.append(reply)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
356
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
357 def __getDomainReportFinished(self, reply):
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
358 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
359 Private slot to process the IP address report data.
6121
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
360
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
361 @param reply reference to the network reply
d3d64f3128b3 Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
362 @type QNetworkReply
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 """
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
364 if reply.error() == QNetworkReply.NoError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
365 result = json.loads(str(reply.readAll(), "utf-8"))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
366 if result["response_code"] == 0:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
367 E5MessageBox.information(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
368 None,
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
369 self.tr("VirusTotal Domain Report"),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
370 self.tr("""VirusTotal does not have any information for"""
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
371 """ the given domain."""))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
372 elif result["response_code"] == -1:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
373 E5MessageBox.information(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
374 None,
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
375 self.tr("VirusTotal Domain Report"),
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
376 self.tr("""The submitted domain address is invalid."""))
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
377 else:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
378 resolutions = result["resolutions"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
379 try:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
380 urls = result["detected_urls"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
381 except KeyError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
382 urls = []
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
383 try:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
384 subdomains = result["subdomains"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
385 except KeyError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
386 subdomains = []
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
387 try:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
388 bdCategory = result["BitDefender category"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
389 except KeyError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
390 bdCategory = self.tr("not available")
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
391 try:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
392 tmCategory = result["TrendMicro category"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
393 except KeyError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
394 tmCategory = self.tr("not available")
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
395 try:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
396 wtsCategory = result["Websense ThreatSeeker category"]
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
397 except KeyError:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
398 wtsCategory = self.tr("not available")
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
399 try:
4336
473bf2a8676f Finished implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4335
diff changeset
400 whois = result["whois"]
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
401 except KeyError:
4336
473bf2a8676f Finished implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4335
diff changeset
402 whois = ""
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
403
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
404 from .VirusTotalDomainReportDialog import \
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
405 VirusTotalDomainReportDialog
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
406 self.__domainReportDlg = VirusTotalDomainReportDialog(
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
407 self.__lastDomain, resolutions, urls, subdomains,
4336
473bf2a8676f Finished implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4335
diff changeset
408 bdCategory, tmCategory, wtsCategory, whois)
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
409 self.__domainReportDlg.show()
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
410 self.__replies.remove(reply)
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
411 reply.deleteLater()
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
412
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
413 def close(self):
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
414 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
415 Public slot to close the API.
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
416 """
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
417 for reply in self.__replies:
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
418 reply.abort()
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419
4335
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
420 self.__ipReportDlg and self.__ipReportDlg.close()
a25c157625c4 Started implementing the VirusTotal APIv2 interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4332
diff changeset
421 self.__domainReportDlg and self.__domainReportDlg.close()

eric ide

mercurial