|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +nessus file analyzer (NFA) by LimberDuck (pronounced *ˈlɪm.bɚ dʌk*) is a GUI |
| 4 | +tool which enables you to parse multiple nessus files containing the results |
| 5 | +of scans performed by using Nessus by (C) Tenable, Inc. and exports parsed |
| 6 | +data to a Microsoft Excel Workbook for effortless analysis. |
| 7 | +Copyright (C) 2019 Damian Krawczyk |
| 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 3 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, see <https://www.gnu.org/licenses/>. |
| 21 | +""" |
| 22 | + |
| 23 | +import requests |
| 24 | +from packaging import version |
| 25 | + |
| 26 | +from PyQt5.QtCore import Qt |
| 27 | +from PyQt5.QtWidgets import QMessageBox |
| 28 | + |
| 29 | +from nessus_file_analyzer import __about__ |
| 30 | + |
| 31 | +PACKAGE_NAME = __about__.__package_name__ |
| 32 | + |
| 33 | + |
| 34 | +class UpdateCheck(QMessageBox): |
| 35 | + def __init__(self, parent=None): |
| 36 | + super(UpdateCheck, self).__init__(parent) |
| 37 | + |
| 38 | + self.appName = __about__.__title__ |
| 39 | + self.current_version = __about__.__version__ |
| 40 | + self.release_date = __about__.__release_date__ |
| 41 | + |
| 42 | + self.setWindowTitle(self.tr(f"Update Check - {self.appName}")) |
| 43 | + self.setTextFormat(Qt.RichText) |
| 44 | + self.setStandardButtons(QMessageBox.Ok) |
| 45 | + |
| 46 | + latest_version, message = self.check_for_update() |
| 47 | + |
| 48 | + self.setText(message) |
| 49 | + self.exec_() |
| 50 | + |
| 51 | + def check_for_update(self): |
| 52 | + try: |
| 53 | + response = requests.get( |
| 54 | + f"https://pypi.org/pypi/{PACKAGE_NAME}/json", timeout=1.5 |
| 55 | + ) |
| 56 | + response.raise_for_status() |
| 57 | + latest = response.json()["info"]["version"] |
| 58 | + read_more = ( |
| 59 | + f"Read more:<br>" |
| 60 | + f"<a href='https://limberduck.org/en/latest/tools/{PACKAGE_NAME}'>Documentation</a><br>" |
| 61 | + f"<a href='https://github.com/LimberDuck/{PACKAGE_NAME}'>GitHub</a><br>" |
| 62 | + f"<a href='https://github.com/LimberDuck/{PACKAGE_NAME}/releases'>Releases</a>" |
| 63 | + ) |
| 64 | + if version.parse(latest) > version.parse(self.current_version): |
| 65 | + message = ( |
| 66 | + f"<b> A new version of {self.appName} is available!</b><br><br>" |
| 67 | + f"Latest: <b>{latest}</b><br>" |
| 68 | + f"You have: <b>{self.current_version}</b><br><br>" |
| 69 | + f"Update with:<br>" |
| 70 | + f"<code>pip install -U {PACKAGE_NAME}</code><br><br>" |
| 71 | + f"{read_more}" |
| 72 | + ) |
| 73 | + elif version.parse(latest) == version.parse(self.current_version): |
| 74 | + message = ( |
| 75 | + f"You are using the latest version of {self.appName}: <b>{self.current_version}</b><br><br>" |
| 76 | + f"{read_more}" |
| 77 | + ) |
| 78 | + |
| 79 | + else: |
| 80 | + message = ( |
| 81 | + f"You are using a <b>pre-release</b> version of {self.appName}: {self.current_version}<br><br>" |
| 82 | + f"Latest released version: {latest}<br><br>" |
| 83 | + f"{read_more}" |
| 84 | + ) |
| 85 | + return latest, message |
| 86 | + |
| 87 | + except requests.exceptions.ConnectionError as e: |
| 88 | + return ( |
| 89 | + None, |
| 90 | + f"Could not check for updates: <br><br><i>Connection error</i><br><br>{e}", |
| 91 | + ) |
| 92 | + except Exception as e: |
| 93 | + return None, f"Could not check for updates:<br><br>{e}" |
0 commit comments