def finished( self, result ): # Pull all messages into the main thread so we can see them. logger = LoggingMessageHandler(bool(), self._log_viewer) logger.status_message(result) self.openfile.setEnabled(True) self._backup_config.setEnabled(True) # turn the buttons on again. self.load.setEnabled(True) self.zero.setEnabled(True)
def _open(self, _): """ Invoked when the user clicks the open button. """ logger = LoggingMessageHandler(bool(), self._log_viewer) fltr = "Text or Config (*.txt *.cfg)" obj = QFileDialog.getOpenFileName(self, 'Config to Load', '', fltr) if obj[0] == '': return with open(obj[0], 'r') as file: config = file.read() logger.clear() logger.status_message('>======= Configuration Preview ======<\n') logger.status_message(config) logger.status_message( '>============= Reminder =============<\n' 'Remove extra lines from the text file, such as:\n ' ' enable \n config t \n building \n etc...') self.load_thread.config = config
def _traceroute(self, _): """ Invoked when the user clicks the traceroute button. """ logger = LoggingMessageHandler(bool(), self._log_viewer) if self.ip.text() == '': logger.clear() logger.status_message("No IP to traceroute.") return else: command = f'traceroute {self.ip.text()}' self.command_thread.command = command logger.status_message("Running....") self.command_thread.start()
class AboutTab(QWidget): label = "RouterInfo" def __init__(self, parent=None): """ Initialise the page. """ super().__init__(parent) '''sets up a grid layout for the tab''' layout = QGridLayout() # Page will use a grid layout. self._log_viewer = QPlainTextEdit(readOnly=True) self._log_viewer.setStyleSheet("background-color: #1E1E1E") layout.addWidget(self._log_viewer, 0, 0, 5, 1) self.logger = LoggingMessageHandler(bool(), self._log_viewer) self.logger.clear() self.logger.title( 'SNAP' ) # Description of the application the different message types create different colors. self.logger.user_exception('Version: 1.0') self.logger.message('Author: Jason Hernandez') self.logger.user_exception( '\nMIT License: Copyright (c) 2018 Jason Hernandez\n' 'Permission is hereby granted, free of charge, to any person obtaining a copy\n' 'of this software and associated documentation files (the "Software"), to deal\n' 'in the Software without restriction, including without limitation the rights\n' 'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n' 'copies of the Software, and to permit persons to whom the Software is\n' 'furnished to do so, subject to the following conditions:\n\n' 'The above copyright notice and this permission notice shall be included in all\n' 'copies or substantial portions of the Software.\n\n' 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \n' 'EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \n' 'OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \n' 'NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \n' 'HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \n' 'WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \n' 'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \n' 'DEALINGS IN THE SOFTWARE.\n') self.setLayout(layout) # Displays the layout
def _load(self): # load button triggers the backup thread to start logger = LoggingMessageHandler(bool(), self._log_viewer) logger.clear() logger.status_message('Loading Configuration....') self.openfile.setEnabled(False) self._backup_config.setEnabled( False) # turn off the buttons so accidents don't happen. self.load.setEnabled(False) self.zero.setEnabled(False) self.load_thread.start()
def _backup(self, state): # backup button triggers the backup thread to start logger = LoggingMessageHandler(bool(), self._log_viewer) logger.clear() logger.status_message('Connecting....') self.openfile.setEnabled(False) self._backup_config.setEnabled( False) # turn off the buttons so accidents don't happen. self.load.setEnabled(False) self.zero.setEnabled(False) self.backup_thread.start()
def finished(self, result): # Pull all messages into the main thread so we can see them. logger = LoggingMessageHandler(bool(), self._log_viewer) self.ping.setEnabled(True) self.traceroute.setEnabled(True) self.ip.setEnabled(True) self.routes.setEnabled(True) self.interfaces.setEnabled(True) self.dmvpn.setEnabled(True) self.ospf.setEnabled(True) self.eigrp.setEnabled(True) if result == '': logger.status_message('Process not running.') else: logger.status_message(result)
def _eigrp(self, _): """ Invoked when the user clicks the eigrp button. """ logger = LoggingMessageHandler(bool(), self._log_viewer) command = 'show ip eigrp neigh' self.command_thread.command = command logger.clear() logger.status_message("Running....") self.ping.setEnabled(False) self.traceroute.setEnabled(False) self.ip.setEnabled(False) self.routes.setEnabled(False) self.interfaces.setEnabled(False) self.dmvpn.setEnabled(False) self.ospf.setEnabled(False) self.eigrp.setEnabled(False) self.command_thread.start()
def _zero(self, ): zero_msg = "Are you sure you want Zero the router?" reply = QMessageBox.question(self, 'Zero?', zero_msg, QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: logger = LoggingMessageHandler(bool(), self._log_viewer) logger.clear() logger.status_message('Zeroizing router...') self.openfile.setEnabled(False) self._backup_config.setEnabled( False) # turn off the buttons so accidents don't happen. self.load.setEnabled(False) self.zero.setEnabled(False) self.zero_thread.start() else: return
def finished(self, result): logger = LoggingMessageHandler(bool(), self._log_viewer) logger.status_message(result) self.verify_button.setEnabled(True) # Enable the pushButton
def _verify( self ): # We want to verify the information in a new thread so we don't freeze up the entire app. logger = LoggingMessageHandler(bool(), self._log_viewer) if self.ip.text() == '' or self.username.text( ) == '' or self.password.text() == '': logger.clear() logger.status_message("All Fields must be Completed.") return if self.con_method == 'cisco_ios_serial': if 'COM' not in self.ip.text().upper(): logger.clear() logger.status_message( "Com Port field requires COM1 or COM2 or COM3 etc...") return device = { 'device_type': self.con_method, 'global_delay_factor': 2, 'username': self.username.text(), 'password': self.password.text(), 'serial_settings': { 'port': self.ip.text() } } Settings.device = device self.verify_thread.device = device elif self.con_method == 'cisco_ios_telnet': device = { 'device_type': self.con_method, 'ip': self.ip.text(), 'username': self.username.text(), 'password': self.password.text() } Settings.device = device self.verify_thread.device = device elif self.con_method == 'cisco_ios': device = { 'device_type': self.con_method, 'ip': self.ip.text(), 'username': self.username.text(), 'password': self.password.text() } Settings.device = device self.verify_thread.device = device else: logger.clear() logger.status_message("Please select a connection method.") return self.verify_button.setEnabled(False) # Disables the pushButton logger.status_message( "Verifying... (This may take a while on Console)") self.verify_thread.start()