Esempio n. 1
0
    def on_btnSshReadRpcConfig_clicked(self):
        if self.lstConns.currentRow() >= 0:
            cfg = self.local_config.dash_net_configs[
                self.lstConns.currentRow()]
            host = cfg.ssh_conn_cfg.host
            port = cfg.ssh_conn_cfg.port
            username = cfg.ssh_conn_cfg.username
            if not host:
                self.errorMsg('Host address is required')
                self.ssh_tunnel_widget.edtSshHost.setFocus()
            if not port:
                self.errorMsg('Host TCP port number is required')
                self.ssh_tunnel_widget.edtSshHost.setFocus()

            ok = True
            if not username:
                username, ok = QInputDialog.getText(
                    self, 'Username Dialog',
                    'Enter username for SSH connection:')
            if not ok or not username:
                return
            from dashd_intf import DashdSSH
            ssh = DashdSSH(host, int(port), username)
            try:
                ssh.connect()
                dashd_conf = ssh.find_dashd_config()
                self.disable_cfg_update = True
                if isinstance(dashd_conf, tuple) and len(dashd_conf) >= 3:
                    if not dashd_conf[0]:
                        self.infoMsg(
                            'Remore Dash daemon seems to be shut down')
                    elif not dashd_conf[1]:
                        self.infoMsg('Could not find remote dashd.conf file')
                    else:
                        file = dashd_conf[2]
                        rpcuser = file.get('rpcuser', '')
                        rpcpassword = file.get('rpcpassword', '')
                        rpcport = file.get('rpcport', '9998')
                        modified = False
                        if rpcuser:
                            modified = modified or (cfg.username != rpcuser)
                            cfg.username = rpcuser
                        if rpcpassword:
                            modified = modified or (cfg.password !=
                                                    rpcpassword)
                            cfg.password = rpcpassword
                        if rpcport:
                            modified = modified or (cfg.port != rpcport)
                            cfg.port = rpcport
                        rpcbind = file.get('rpcbind', '')
                        if not rpcbind:  # listen on all interfaces if not set
                            rpcbind = '127.0.0.1'
                        modified = modified or (cfg.host != rpcbind)
                        cfg.host = rpcbind
                        if modified:
                            self.is_modified = modified

                        if file.get('server', '1') == '0':
                            self.warnMsg(
                                "Remote dash.conf parameter 'server' is set to '0', so RPC interface will "
                                "not work.")
                        if not rpcuser:
                            self.warnMsg(
                                "Remote dash.conf parameter 'rpcuser' is not set, so RPC interface will  "
                                "not work.")
                        if not rpcpassword:
                            self.warnMsg(
                                "Remote dash.conf parameter 'rpcpassword' is not set, so RPC interface will  "
                                "not work.")
                    self.updateUi()
                elif isinstance(dashd_conf, str):
                    self.warnMsg(
                        "Couldn't read remote dashd configuration file due the following error: "
                        + dashd_conf)
                ssh.disconnect()
            except Exception as e:
                self.errorMsg(str(e))
                return
            finally:
                self.disable_cfg_update = False
Esempio n. 2
0
    def on_btnSshReadRpcConfig_clicked(self):
        """Read the configuration of a remote RPC node from the node's dash.conf file."""
        if self.current_network_cfg:
            host = self.current_network_cfg.ssh_conn_cfg.host
            port = self.current_network_cfg.ssh_conn_cfg.port
            username = self.current_network_cfg.ssh_conn_cfg.username
            auth_method = self.current_network_cfg.ssh_conn_cfg.auth_method
            private_key_path = self.current_network_cfg.ssh_conn_cfg.private_key_path

            if not host:
                self.errorMsg('Host address is required')
                self.ssh_tunnel_widget.edtSshHost.setFocus()
                return

            if not port:
                self.errorMsg('Host TCP port number is required')
                self.ssh_tunnel_widget.edtSshHost.setFocus()
                return

            ok = True
            if not username:
                username, ok = QInputDialog.getText(self, 'Username Dialog', 'Enter username for SSH connection:')
            if not ok or not username:
                return
            from dashd_intf import DashdSSH
            ssh = DashdSSH(host, int(port), username, auth_method=auth_method, private_key_path=private_key_path)
            try:
                if ssh.connect():
                    dashd_conf = ssh.find_dashd_config()
                    self.disable_cfg_update = True
                    if isinstance(dashd_conf, tuple) and len(dashd_conf) >= 3:
                        if not dashd_conf[0]:
                            self.infoMsg('Remore Firo daemon seems to be shut down')
                        elif not dashd_conf[1]:
                            self.infoMsg('Could not find remote dashd.conf file')
                        else:
                            file = dashd_conf[2]
                            rpcuser = file.get('rpcuser', '')
                            rpcpassword = file.get('rpcpassword', '')
                            rpcport = file.get('rpcport', '9998')
                            modified = False
                            if rpcuser:
                                modified = modified or (self.current_network_cfg.username != rpcuser)
                                self.current_network_cfg.username = rpcuser
                            if rpcpassword:
                                modified = modified or (self.current_network_cfg.password != rpcpassword)
                                self.current_network_cfg.password = rpcpassword
                            if rpcport:
                                modified = modified or (self.current_network_cfg.port != rpcport)
                                self.current_network_cfg.port = rpcport
                            rpcbind = file.get('rpcbind', '')
                            if not rpcbind:  # listen on all interfaces if not set
                                rpcbind = '127.0.0.1'
                            modified = modified or (self.current_network_cfg.host != rpcbind)
                            self.current_network_cfg.host = rpcbind
                            if modified:
                                self.is_modified = modified

                            if file.get('server', '1') == '0':
                                self.warnMsg("Remote firo.conf parameter 'server' is set to '0', so RPC interface will "
                                             "not work.")
                            if not rpcuser:
                                self.warnMsg("Remote firo.conf parameter 'rpcuser' is not set, so RPC interface will  "
                                             "not work.")
                            if not rpcpassword:
                                self.warnMsg("Remote firo.conf parameter 'rpcpassword' is not set, so RPC interface will  "
                                             "not work.")
                        self.update_connection_details_ui()
                    elif isinstance(dashd_conf, str):
                        self.warnMsg("Couldn't read remote firod configuration file due the following error: " +
                                     dashd_conf)
                    ssh.disconnect()
            except Exception as e:
                self.errorMsg(str(e))
                return
            finally:
                self.disable_cfg_update = False