예제 #1
0
    def settingHttpPanelFromJSONFile(self,
                                     httpJSONFile,
                                     openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)

        if (not httpJSONFile):
            self.lineEditHost.clear()
            self.lineEditPath.clear()
            self.groupBoxhttp.setChecked(False)
            del httpJSONFile
            return False

        try:
            httpJSONFile["host"]
        except Exception:
            httpJSONFile["host"] = []

        try:
            httpJSONFile["path"]
        except Exception:
            httpJSONFile["path"] = ""

        if (httpJSONFile["host"]):
            self.lineEditHost.setText(", ".join(
                [str(x) for x in httpJSONFile["host"]]))

        if (httpJSONFile["path"]):
            self.lineEditPath.setText(httpJSONFile["path"])
예제 #2
0
    def settingmuxPanelFromJSONFile(self, muxJSONFile, openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)
        
        if (not muxJSONFile): 
            muxJSONFile = {}
            self.groupBoxmuxSetting.setChecked(False)
            return
        
        try:
            muxJSONFile["enabled"]
        except KeyError as e:
            logbook.writeLog("mux", "KeyError", e)
            muxJSONFile["enabled"] = False
        
        try:
            muxJSONFile["concurrency"]
        except KeyError as e:
            logbook.writeLog("mux", "KeyError", e)
            muxJSONFile["concurrency"] = 8
        
        try:
            self.spinBoxConcurrency.setValue(int(muxJSONFile["concurrency"]))
        except ValueError as e:
            logbook.writeLog("mux", "ValueError", e)
            muxJSONFile["concurrency"] = 8

        self.groupBoxmuxSetting.setChecked(bool(muxJSONFile["enabled"]))
예제 #3
0
    def settingtcpPanelFromJSONFile(self, tcpJSONFile, openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)

        if (tcpJSONFile == None):
            tcpJSONFile = {}
            self.groupBoxTCPSetting.setChecked(False)
            self.textHttpHeaderType.clear()
            self.comboxHttpHeaderType.setCurrentText("none")
            return

        try:
            tcpJSONFile["header"]
        except KeyError as e:
            logbook.writeLog("transport TCP", "KeyError", e)
            tcpJSONFile["header"] = {}

        try:
            tcpJSONFile["header"]["type"]
        except KeyError as e:
            logbook.writeLog("transport TCP", "KeyError", e)
            tcpJSONFile["header"]["type"] = "none"

        if (tcpJSONFile["header"]["type"] == "http"):
            self.textHttpHeaderType.setText(
                json.dumps(tcpJSONFile["header"], indent=4, sort_keys=False))
            self.comboxHttpHeaderType.setCurrentText("http")
        elif (tcpJSONFile["header"]["type"] == "none"):
            self.textHttpHeaderType.clear()
        else:
            ### TODO pop a error message
            pass
예제 #4
0
    def settingwsPanelFromJSONFile(self, wsJSONFile, openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)

        if (wsJSONFile == None):
            wsJSONFile = {}
            self.groupBoxwsSetting.setChecked(False)
            self.lineEditwebsocksHost.clear()
            self.lineEditwebsocksPath.clear()
            return False
        try:
            wsJSONFile["path"]
        except KeyError as e:
            logbook.writeLog("transport ws", "KeyError", e)
            wsJSONFile["path"] = ""

        try:
            wsJSONFile["headers"]
        except KeyError as e:
            logbook.writeLog("transport ws", "KeyError", e)
            wsJSONFile["headers"] = {}

        try:
            wsJSONFile["headers"]["Host"]
        except KeyError as e:
            logbook.writeLog("transport ws", "KeyError", e)
            wsJSONFile["headers"]["Host"] = ""

        self.lineEditwebsocksPath.setText(str(wsJSONFile["path"]))
        self.lineEditwebsocksHost.setText(str(wsJSONFile["headers"]["Host"]))
예제 #5
0
    def settingmKcpPanelFromJSONFile(self,
                                     mKcpJSONFile,
                                     openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)

        if (not mKcpJSONFile):
            mKcpJSONFile = {}
            self.groupBoxmKCPSetting.setChecked(False)
            return False

        try:
            mKcpJSONFile["mtu"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["mtu"] = 1355

        try:
            mKcpJSONFile["tti"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["tti"] = 50

        try:
            mKcpJSONFile["uplinkCapacity"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["uplinkCapacity"] = 5

        try:
            mKcpJSONFile["downlinkCapacity"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["downlinkCapacity"] = 20

        try:
            mKcpJSONFile["congestion"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["congestion"] = False

        try:
            mKcpJSONFile["readBufferSize"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["readBufferSize"] = 2

        try:
            mKcpJSONFile["writeBufferSize"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["writeBufferSize"] = 2

        try:
            mKcpJSONFile["header"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["header"] = {}

        try:
            mKcpJSONFile["header"]["type"]
        except KeyError as e:
            logbook.writeLog("mKcp", "KeyError", e)
            mKcpJSONFile["header"]["type"] = "none"

        try:
            self.spinBoxmKcpMTU.setValue(int(mKcpJSONFile["mtu"]))
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["mtu"] = 1355

        try:
            self.spinBoxmKcpTTI.setValue(int(mKcpJSONFile["tti"]))
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["tti"] = 50

        try:
            self.spinBoxUpCapacity.setValue(int(
                mKcpJSONFile["uplinkCapacity"]))
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["uplinkCapacity"] = 5

        try:
            self.spinBoxDownCapacity.setValue(
                int(mKcpJSONFile["downlinkCapacity"]))
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["downlinkCapacity"] = 20

        try:
            self.checkBoxCongestion.setChecked(mKcpJSONFile["congestion"])
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["congestion"] = False

        try:
            self.spinBoxRdBufferSize.setValue(
                int(mKcpJSONFile["readBufferSize"]))
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["readBufferSize"] = 2

        try:
            self.spinBoxWrBufferSize.setValue(
                int(mKcpJSONFile["writeBufferSize"]))
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
            mKcpJSONFile["writeBufferSize"] = 2

        try:
            self.comboBoxHeader.setCurrentText(mKcpJSONFile["header"]["type"])
        except ValueError as e:
            logbook.writeLog("mKcp", "ValueError", e)
        except TypeError as e:
            logbook.writeLog("mKcp", "TypeError", e)
        except:
            logbook.writeLog("mKcp", "unkonw Error")
예제 #6
0
    def settingtransportPanelFromJSONFile(self,
                                          transportJSONFile=None,
                                          openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)
        certificatesFilesNumber = 0

        if (not transportJSONFile):
            transportJSONFile = {}
            self.checkBoxTransportSetting.setChecked(False)
            return False

        try:
            transportJSONFile["network"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["network"] = "tcp"

        try:
            transportJSONFile["security"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["security"] = "none"

        try:
            transportJSONFile["tlsSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["tlsSettings"] = None

        try:
            transportJSONFile["tcpSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["tcpSettings"] = None

        try:
            transportJSONFile["kcpSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["kcpSettings"] = None

        try:
            transportJSONFile["wsSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["wsSettings"] = None

        try:
            transportJSONFile["httpSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["httpSettings"] = None

        def hideSettingsandDisableRadioButton():
            self.tcpPanel.hide()
            self.wsPanel.hide()
            self.mkcpPanel.hide()
            self.http2Panel.hide()
            self.ws.groupBoxwsSetting.setChecked(False)
            self.mkcp.groupBoxmKCPSetting.setChecked(False)
            self.tcp.groupBoxTCPSetting.setChecked(False)
            self.http2.groupBoxhttp.setChecked(False)

        def setTransport(protocol=transportJSONFile["network"]):
            if (protocol == "tcp"):
                hideSettingsandDisableRadioButton()
                self.radioButtonTransportTCP.setChecked(True)
                self.tcpPanel.show()
                if (transportJSONFile["tcpSettings"]):
                    self.tcp.settingtcpPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["tcpSettings"]),
                        openFromJSONFile)
                    self.tcp.groupBoxTCPSetting.setChecked(True)

            elif (protocol == "kcp"):
                hideSettingsandDisableRadioButton()
                self.radioButtonmTransportKCP.setChecked(True)
                self.mkcpPanel.show()
                if (transportJSONFile["kcpSettings"]):
                    self.mkcp.settingmKcpPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["kcpSettings"]),
                        openFromJSONFile)
                    self.mkcp.groupBoxmKCPSetting.setChecked(True)

            elif (protocol == "ws"):
                hideSettingsandDisableRadioButton()
                self.radioButtonTransportWS.setChecked(True)
                self.wsPanel.show()
                if (transportJSONFile["wsSettings"]):
                    self.ws.settingwsPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["wsSettings"]),
                        openFromJSONFile)
                    self.ws.groupBoxwsSetting.setChecked(True)

            elif (protocol == "http"):
                hideSettingsandDisableRadioButton()
                self.radioButtonTransportHTTP.setChecked(True)
                self.http2Panel.show()
                if (transportJSONFile["httpSettings"]):
                    self.http2.groupBoxhttp.setChecked(True)
                    self.http2.settingHttpPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["httpSettings"]),
                        openFromJSONFile)

        setTransport()

        def cleartlsSettings():
            self.groupBoxTLSSetting.setChecked(False)
            self.checkBoxCertificateAllowInsecure.setChecked(False)
            self.tableWidgetUserCertificates.setRowCount(0)
            self.lineEditCertificateServerName.clear()

        if (transportJSONFile["security"] == "tls"):
            self.groupBoxTLSSetting.setChecked(True)
            if (not transportJSONFile["tlsSettings"]):
                cleartlsSettings()
                certificatesFilesNumber = 0
            else:
                try:
                    certificatesFilesNumber = len(
                        transportJSONFile["tlsSettings"]["certificates"])
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                try:
                    certificateFiles = transportJSONFile["tlsSettings"][
                        "certificates"]
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                except:
                    logbook.writeLog("transport tlsSettings certificates",
                                     "unkonw")
                try:
                    self.lineEditCertificateServerName.setText(
                        str(transportJSONFile["tlsSettings"]["serverName"]))
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                try:
                    self.checkBoxCertificateAllowInsecure.setChecked(
                        bool(
                            transportJSONFile["tlsSettings"]["allowInsecure"]))
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                try:
                    self.lineEditCertificatealpn.setText(", ".join([
                        str(x)
                        for x in transportJSONFile["tlsSettings"]["alpn"]
                    ]))
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
        else:
            cleartlsSettings()
            certificatesFilesNumber = 0

        if (certificatesFilesNumber):
            try:
                for i in range(certificatesFilesNumber):
                    self.onbtnCertificatesaddNewRow()
                    combox = self.tableWidgetUserCertificates.cellWidget(i, 0)
                    try:
                        combox.setCurrentText(
                            str(certificateFiles[i]["useage"]))
                    except Exception:
                        pass
                    self.tableWidgetUserCertificates.setItem(
                        i, 1,
                        QTableWidgetItem(
                            str(certificateFiles[i]["certificateFile"])))
                    self.tableWidgetUserCertificates.setItem(
                        i, 2,
                        QTableWidgetItem(str(certificateFiles[i]["keyFile"])))
                    self.tableWidgetUserCertificates.setItem(
                        i, 3,
                        QTableWidgetItem(",".join(
                            certificateFiles[i]["certificate"])))
                    self.tableWidgetUserCertificates.setItem(
                        i, 4,
                        QTableWidgetItem(",".join(certificateFiles[i]["key"])))
            except KeyError as e:
                logbook.writeLog("transport", "KeyError", e)
        else:
            self.tableWidgetUserCertificates.setRowCount(0)
예제 #7
0
    def settingtransportPanelFromJSONFile(self,
                                          transportJSONFile={},
                                          openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)
        certificatesFilesNumber = 0

        if (transportJSONFile == None):
            transportJSONFile = {}
            self.checkBoxTransportSetting.setChecked(False)
            return False

        try:
            transportJSONFile["network"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["network"] = "tcp"

        try:
            transportJSONFile["security"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["security"] = "none"

        try:
            transportJSONFile["tlsSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["tlsSettings"] = {}

        try:
            transportJSONFile["tcpSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["tcpSettings"] = {}

        try:
            transportJSONFile["kcpSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["kcpSettings"] = {}

        try:
            transportJSONFile["wsSettings"]
        except KeyError as e:
            logbook.writeLog("transport", "KeyError", e)
            transportJSONFile["wsSettings"] = {}

        def hideSettingsandDisableRadioButton():
            self.tcpPanel.hide()
            self.wsPanel.hide()
            self.mkcpPanel.hide()
            self.ws.groupBoxwsSetting.setChecked(False)
            self.mkcp.groupBoxmKCPSetting.setChecked(False)
            self.tcp.groupBoxTCPSetting.setChecked(False)

        def setTransport(protocol=transportJSONFile["network"]):
            if (protocol == "tcp"):
                hideSettingsandDisableRadioButton()
                self.radioButtonTransportTCP.setChecked(True)
                self.tcpPanel.show()
                if (transportJSONFile["tcpSettings"] == {}
                        or transportJSONFile["tcpSettings"] == None):
                    pass
                else:
                    self.tcp.settingtcpPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["tcpSettings"]),
                        openFromJSONFile)
                    self.tcp.groupBoxTCPSetting.setChecked(True)

            elif (protocol == "kcp"):
                hideSettingsandDisableRadioButton()
                self.radioButtonmTransportKCP.setChecked(True)
                self.mkcpPanel.show()
                if (transportJSONFile["kcpSettings"] == {}
                        or transportJSONFile["kcpSettings"] == None):
                    pass
                else:
                    self.mkcp.settingmKcpPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["kcpSettings"]),
                        openFromJSONFile)
                    self.mkcp.groupBoxmKCPSetting.setChecked(True)

            elif (protocol == "ws"):
                hideSettingsandDisableRadioButton()
                self.radioButtonTransportWS.setChecked(True)
                self.wsPanel.show()
                if (transportJSONFile["wsSettings"] == {}
                        or transportJSONFile["wsSettings"] == None):
                    pass
                else:
                    self.ws.settingwsPanelFromJSONFile(
                        copy.deepcopy(transportJSONFile["wsSettings"]),
                        openFromJSONFile)
                    self.ws.groupBoxwsSetting.setChecked(True)

        setTransport()

        def cleartlsSettings():
            self.groupBoxTLSSetting.setChecked(False)
            self.checkBoxCertificateAllowInsecure.setChecked(False)
            self.tableWidgetUserCertificates.setRowCount(0)
            self.lineEditCertificateServerName.clear()

        if (transportJSONFile["security"] == "tls"):
            self.groupBoxTLSSetting.setChecked(True)
            if (transportJSONFile["tlsSettings"] == {}
                    or transportJSONFile["tlsSettings"] == None):
                cleartlsSettings()
                certificatesFilesNumber = 0
            else:
                try:
                    certificatesFilesNumber = len(
                        transportJSONFile["tlsSettings"]["certificates"])
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                try:
                    certificateFiles = transportJSONFile["tlsSettings"][
                        "certificates"]
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                except:
                    logbook.writeLog("transport tlsSettings certificates",
                                     "unkonw")
                try:
                    self.lineEditCertificateServerName.setText(
                        str(transportJSONFile["tlsSettings"]["serverName"]))
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
                try:
                    self.checkBoxCertificateAllowInsecure.setChecked(
                        bool(
                            transportJSONFile["tlsSettings"]["allowInsecure"]))
                except KeyError as e:
                    logbook.writeLog("transport", "KeyError", e)
        else:
            cleartlsSettings()
            certificatesFilesNumber = 0

        if (certificatesFilesNumber > 0):
            self.tableWidgetUserCertificates.setRowCount(
                certificatesFilesNumber)
            try:
                for i in range(certificatesFilesNumber):
                    self.tableWidgetUserCertificates.setItem(
                        i, 0,
                        QTableWidgetItem(
                            str(certificateFiles[i]["certificateFile"])))
                    self.tableWidgetUserCertificates.setItem(
                        i, 1,
                        QTableWidgetItem(str(certificateFiles[i]["keyFile"])))
                    self.tableWidgetUserCertificates.resizeColumnsToContents()
            except KeyError as e:
                logbook.writeLog("transport", "KeyError", e)
        else:
            self.tableWidgetUserCertificates.setRowCount(0)