diff --git a/assets/images/green-mark.png b/assets/images/green-mark.png new file mode 100644 index 0000000..546b535 Binary files /dev/null and b/assets/images/green-mark.png differ diff --git a/assets/images/red-mark.png b/assets/images/red-mark.png new file mode 100644 index 0000000..ac6c122 Binary files /dev/null and b/assets/images/red-mark.png differ diff --git a/common/constants/view/pec/pec.py b/common/constants/view/pec/pec.py index 001e97f..7dd41dd 100644 --- a/common/constants/view/pec/pec.py +++ b/common/constants/view/pec/pec.py @@ -27,5 +27,9 @@ DOWNLOAD_EML_SUCCESS="EML file has been successfully downloaded." RETRIES_NUMBER="Retries EML download" SERVER_CONFIGURATION="Server configuration" +VERIFY_IMAP="Verify IMAP server" +VERIFY_SMTP="Verify SMTP server" + + diff --git a/view/configurations/tabs/pec/pec.py b/view/configurations/tabs/pec/pec.py index ab61b1b..43282c6 100644 --- a/view/configurations/tabs/pec/pec.py +++ b/view/configurations/tabs/pec/pec.py @@ -5,10 +5,17 @@ # Copyright (c) 2023 FIT-Project # SPDX-License-Identifier: GPL-3.0-only # ----- -###### +###### +import imaplib +import smtplib from PyQt5 import QtCore, QtWidgets +from PyQt5.QtGui import QPixmap +from PyQt5.QtWidgets import QMessageBox, QLabel, QSizePolicy + +from common.constants import error from controller.configurations.tabs.pec.pec import Pec as PecController +from view.error import Error as ErrorView from common.constants.view.pec import pec __is_tab__ = True @@ -82,7 +89,7 @@ def initUI(self): self.group_box_server.setObjectName("group_box_server") self.form_layout_widget_IMAP = QtWidgets.QWidget(self.group_box_server) - self.form_layout_widget_IMAP.setGeometry(QtCore.QRect(10, 20, 511, 24)) + self.form_layout_widget_IMAP.setGeometry(QtCore.QRect(10, 20, 600, 24)) self.form_layout_widget_IMAP.setObjectName("form_layout_widget_server_IMAP") self.horizontal_layout_IMAP = QtWidgets.QHBoxLayout(self.form_layout_widget_IMAP) self.horizontal_layout_IMAP.setContentsMargins(0, 0, 0, 0) @@ -110,8 +117,23 @@ def initUI(self): self.horizontal_layout_IMAP.addWidget(self.imap_port) + self.verification_imap_button = QtWidgets.QPushButton(self.form_layout_widget_IMAP) + self.verification_imap_button.clicked.connect(self.__verify_imap) + self.verification_imap_button.setObjectName("verification_imap_button") + self.verification_imap_button.setEnabled(True) + self.horizontal_layout_IMAP.addWidget(self.verification_imap_button) + + self.info_imap_img = QLabel(self) + self.info_imap_img.setEnabled(True) + self.info_imap_img.setPixmap(QPixmap("assets/images/red-mark.png").scaled(20, 20)) + self.info_imap_img.setScaledContents(True) + self.info_imap_img.setGeometry(QtCore.QRect(630, 192, 20, 20)) + self.info_imap_img.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + self.info_imap_img.setVisible(False) + + self.form_layout_widget_SMTP = QtWidgets.QWidget(self.group_box_server) - self.form_layout_widget_SMTP.setGeometry(QtCore.QRect(10, 50, 511, 24)) + self.form_layout_widget_SMTP.setGeometry(QtCore.QRect(10, 50, 600, 24)) self.form_layout_widget_SMTP.setObjectName("form_layout_widget_SMTP") self.horizontal_layout_SMTP = QtWidgets.QHBoxLayout(self.form_layout_widget_SMTP) @@ -143,11 +165,26 @@ def initUI(self): self.smtp_port.setSizePolicy(sizePolicy) self.smtp_port.setObjectName("smtp_port") self.horizontal_layout_SMTP.addWidget(self.smtp_port) - + + self.verification_smtp_button = QtWidgets.QPushButton(self.form_layout_widget_SMTP) + self.verification_smtp_button.clicked.connect(self.__verify_smtp) + self.verification_smtp_button.setObjectName("verification_smtp_button") + self.verification_smtp_button.setEnabled(True) + self.horizontal_layout_SMTP.addWidget(self.verification_smtp_button) + + self.info_smtp_img = QLabel(self) + self.info_smtp_img.setEnabled(True) + self.info_smtp_img.setPixmap(QPixmap("assets/images/red-mark.png").scaled(20, 20)) + self.info_smtp_img.setScaledContents(True) + self.info_smtp_img.setGeometry(QtCore.QRect(630, 222, 20, 20)) + self.info_smtp_img.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + self.info_smtp_img.setVisible(False) + + def retranslateUi(self): self.setWindowTitle(pec.WINDOW_TITLE) - self.enabled_checkbox.setText(pec.ENABLE) + self.enabled_checkbox.setText(pec.ENABLE) self.group_box_credential.setTitle(pec.CREDENTIAL_CONFIGURATION) self.label_pec_email.setText(pec.LABEL_EMAIL) self.label_password.setText(pec.LABEL_PASSWORD) @@ -157,7 +194,9 @@ def retranslateUi(self): self.label_imap_port.setText(pec.LABEL_IMAP_PORT) self.label_smtp_server.setText(pec.LABEL_SMPT_SERVER) self.label_smtp_port.setText(pec.LABEL_SMPT_PORT) - + self.verification_imap_button.setText(pec.VERIFY_IMAP) + self.verification_smtp_button.setText(pec.VERIFY_SMTP) + def __is_enabled_pec(self): self.group_box_credential.setEnabled(self.enabled_checkbox.isChecked()) self.group_box_retries.setEnabled(self.enabled_checkbox.isChecked()) @@ -190,7 +229,50 @@ def __get_current_values(self): self.options[keyword] = value + def __verify_imap(self): + try: + self.info_imap_img.setVisible(False) + server = imaplib.IMAP4_SSL(self.imap_server.text(), int(self.imap_port.text())) + server.login(self.pec_email.text(), self.password.text()) + server.logout() + self.info_imap_img.setPixmap(QPixmap("assets/images/green-mark.png").scaled(20, 20)) + self.info_imap_img.setVisible(True) + + except Exception as e: + self.info_imap_img.setPixmap(QPixmap("assets/images/red-mark.png").scaled(20, 20)) + self.info_imap_img.setVisible(True) + error_dlg = ErrorView(QMessageBox.Critical, + pec.LOGIN_FAILED, + error.LOGIN_ERROR, + str(e) + ) + error_dlg.exec_() + + + def __verify_smtp(self): + try: + self.info_smtp_img.setVisible(False) + server = smtplib.SMTP_SSL(self.smtp_server.text(), int(self.smtp_port.text())) + server.login(self.pec_email.text(), self.password.text()) + server.quit() + self.info_smtp_img.setPixmap(QPixmap("assets/images/green-mark.png").scaled(20, 20)) + self.info_smtp_img.setVisible(True) + + + except Exception as e: + + self.info_smtp_img.setPixmap(QPixmap("assets/images/red-mark.png").scaled(20, 20)) + self.info_smtp_img.setVisible(True) + + error_dlg = ErrorView(QMessageBox.Critical, + pec.LOGIN_FAILED, + error.LOGIN_ERROR, + str(e) + ) + error_dlg.exec_() + def accept(self) -> None: + self.__get_current_values() self.controller.options = self.options diff --git a/view/instagram.py b/view/instagram.py index 31770cf..2e3f0b9 100644 --- a/view/instagram.py +++ b/view/instagram.py @@ -121,11 +121,6 @@ def init(self, case_info, wizard, options=None): self.case_action.triggered.connect(self.__case) self.menuBar().addAction(self.case_action) - # BACK TO WIZARD - back_action = QtWidgets.QAction("Back to wizard", self) - back_action.setStatusTip("Go back to the main menu") - back_action.triggered.connect(self.__back_to_wizard) - self.menuBar().addAction(back_action) self.configuration_general = self.configuration_view.get_tab_from_name("configuration_general") @@ -507,6 +502,5 @@ def __back_to_wizard(self): self.wizard.show() def closeEvent(self, event): - print("CLOSE") event.ignore() self.__back_to_wizard() diff --git a/view/mail.py b/view/mail.py index 45a6778..2c28678 100644 --- a/view/mail.py +++ b/view/mail.py @@ -367,12 +367,6 @@ def init(self, case_info, wizard, options=None): self.case_action.triggered.connect(self.__case) self.menuBar().addAction(self.case_action) - # BACK ACTION - back_action = QtWidgets.QAction("Back to wizard", self) - back_action.setStatusTip("Go back to the main menu") - back_action.triggered.connect(self.__back_to_wizard) - self.menuBar().addAction(back_action) - self.configuration_general = self.configuration_view.get_tab_from_name("configuration_general") @@ -702,6 +696,11 @@ def __configuration(self): self.configuration_view.exec_() def __back_to_wizard(self): - self.deleteLater() - self.wizard.reload_case_info() - self.wizard.show() + if self.is_acquisition_running is False: + self.deleteLater() + self.wizard.reload_case_info() + self.wizard.show() + + def closeEvent(self, event): + event.ignore() + self.__back_to_wizard() diff --git a/view/post_acquisition/post.py b/view/post_acquisition/post.py index 64a1c00..16e0031 100644 --- a/view/post_acquisition/post.py +++ b/view/post_acquisition/post.py @@ -35,8 +35,8 @@ def __init__(self, parent: None): def execute(self, folder, case_info, type): self.calculate_acquisition_file_hash(folder) self.generate_pdf_report(folder, case_info, type) - self.generate_timestamp_report(folder) - self.send_report_from_pec(folder, case_info, type) + self.generate_timestamp_report(folder, case_info, type) + def calculate_acquisition_file_hash(self, folder): @@ -66,7 +66,7 @@ def generate_pdf_report(self, folder, case_info,type): report.generate_pdf(type, self.parent().get_time()) self.parent().upadate_progress_bar() - def generate_timestamp_report(self, folder): + def generate_timestamp_report(self, folder, case_info, type): self.parent().set_message_on_the_statusbar(tasks.TIMESTAMP) options = TimestampController().options if options['enabled']: @@ -79,11 +79,14 @@ def generate_timestamp_report(self, folder): timestamp.finished.connect(timestamp.deleteLater) timestamp.finished.connect(self.thread_timestamp.quit) - self.thread_timestamp.finished.connect(self.__thread_timestamp_is_finished) + self.thread_timestamp.finished.connect(lambda:self.__thread_timestamp_is_finished(folder, case_info, type)) self.thread_timestamp.start() - def __thread_timestamp_is_finished(self): + def __thread_timestamp_is_finished(self,folder, case_info, type): + options = PecController().options + if options['enabled']: + self.send_report_from_pec(folder, case_info, type) self.parent().upadate_progress_bar() self.is_finished_timestamp = True self.__async_task_are_finished() @@ -92,15 +95,14 @@ def send_report_from_pec(self, folder, case_info, type): self.parent().set_message_on_the_statusbar(tasks.PEC) - options = PecController().options - if options['enabled']: - self.pec = PecView(self) - self.pec.sentpec.connect(lambda status: self.__is_pec_sent(status)) - self.pec.downloadedeml.connect(lambda status: self.__is_eml_downloaded(status)) - view_form=True - self.pec.init(case_info, type, folder, view_form) - if view_form is False: - self.pec.send() + self.pec = PecView(self) + self.pec.sentpec.connect(lambda status: self.__is_pec_sent(status)) + self.pec.downloadedeml.connect(lambda status: self.__is_eml_downloaded(status)) + view_form = False + self.pec.init(case_info, type, folder, view_form) + if view_form is False: + self.pec.send() + def __is_pec_sent(self, status): if status == Status.SUCCESS: diff --git a/view/verify_pdf_timestamp.py b/view/verify_pdf_timestamp.py index d464673..ad8e34a 100644 --- a/view/verify_pdf_timestamp.py +++ b/view/verify_pdf_timestamp.py @@ -77,12 +77,6 @@ def init(self, case_info, wizard, options=None): self.case_action.triggered.connect(self.case) self.menuBar().addAction(self.case_action) - # BACK ACTION - back_action = QtWidgets.QAction("Back to wizard", self) - back_action.setStatusTip("Go back to the main menu") - back_action.triggered.connect(self.__back_to_wizard) - self.menuBar().addAction(back_action) - # set font font = QtGui.QFont() font.setPointSize(10) @@ -322,3 +316,7 @@ def __back_to_wizard(self): self.deleteLater() self.wizard.reload_case_info() self.wizard.show() + + def closeEvent(self, event): + event.ignore() + self.__back_to_wizard() diff --git a/view/verify_pec.py b/view/verify_pec.py index 00db520..12e0f45 100644 --- a/view/verify_pec.py +++ b/view/verify_pec.py @@ -64,12 +64,6 @@ def init(self, case_info, wizard, options=None): self.case_action.triggered.connect(self.__case) self.menuBar().addAction(self.case_action) - # BACK ACTION - back_action = QtWidgets.QAction("Back to wizard", self) - back_action.setStatusTip("Go back to the main menu") - back_action.triggered.connect(self.__back_to_wizard) - self.menuBar().addAction(back_action) - self.eml_group_box = QtWidgets.QGroupBox(self.centralwidget) self.eml_group_box.setEnabled(True) self.eml_group_box.setGeometry(QtCore.QRect(50, 20, 500, 180)) @@ -172,3 +166,7 @@ def __back_to_wizard(self): self.deleteLater() self.wizard.reload_case_info() self.wizard.show() + + def closeEvent(self, event): + event.ignore() + self.__back_to_wizard() diff --git a/view/web/web.py b/view/web/web.py index de5b3af..a715983 100644 --- a/view/web/web.py +++ b/view/web/web.py @@ -79,7 +79,7 @@ def __init__(self, *args, **kwargs): self.case_info = None self.__tasks = [] - self.setWindowFlag(QtCore.Qt.WindowMinMaxButtonsHint, False) + self.setWindowFlag(QtCore.Qt.WindowMinMaxButtonsHint, True) self.setObjectName('FITWeb') def init(self, case_info, wizard, options=None): @@ -150,11 +150,6 @@ def init(self, case_info, wizard, options=None): case_action.triggered.connect(self.case) self.menuBar().addAction(case_action) - # BACK ACTION - back_action = QtWidgets.QAction("Back to wizard", self) - back_action.setStatusTip("Go back to the main menu") - back_action.triggered.connect(self.__back_to_wizard) - self.menuBar().addAction(back_action) self.configuration_general = self.configuration_view.get_tab_from_name("configuration_general") @@ -509,16 +504,16 @@ def add_new_tab(self, qurl=None, label="Blank"): self.browser.loadFinished.connect(lambda _, i=i, browser=self.browser: self.__page_on_loaded(i, browser)) + + if i == 0: self.showMaximized() + def __page_on_loaded(self, tab_index, browser): self.tabs.setTabText(tab_index, browser.page().title()) - self.current_page_load_is_finished = True - self.navtb.enable_screenshot_buttons() - def tab_open_doubleclick(self, i): if i == -1 and self.isEnabled(): # No tab under the click self.add_new_tab() @@ -553,11 +548,13 @@ def navigate_to_url(self): # Does not receive the Url self.tabs.currentWidget().setUrl(q) - def load_progress(self, prog): - pass + def load_progress(self, progress): + if progress == 100: + self.current_page_load_is_finished = True + self.navtb.enable_screenshot_buttons() - def __update_urlbar(self, q, browser=None): + def __update_urlbar(self, q, browser=None): self.current_page_load_is_finished = False self.navtb.enable_screenshot_buttons()