Exemple #1
0
    def __init__(self,
                 filePath=False,
                 CaptainstreasureChest=False,
                 disableLog=False):
        self.translate = QCoreApplication.translate
        self.JSONData = False
        if (disableLog):
            logbook.setisOpenJSONFile(False)
        else:
            logbook.setisOpenJSONFile(True)
        if (filePath):
            self.JSONData = self.openJSONData(filePath)

        self.treasureChest = CaptainstreasureChest
        if (not self.treasureChest):
            self.treasureChest = treasureChest.treasureChest()
        self.msgBox = QMessageBox()
        self.fly = QApplication.desktop().screen().rect().center(
        ) - self.msgBox.rect().center()
Exemple #2
0
 def settingv2rayshellPanelFromJSONFile(self, openFromJSONFile=False):
     logbook.setisOpenJSONFile(openFromJSONFile)
     if (openFromJSONFile):
         self.inbound.refreshInboundPaneltableWidget()
         self.outbound.refreshOutboundPaneltableWidget()
         self.routingTAB.settingRoutingTABFromJSONFile(
             routingJSONFile=self.treasureChest.getRouting(), openFromJSONFile=True)
         self.logTAB.settingLogTabFromJSONFile(
             logJSONFile=self.treasureChest.getLog(), openFromJSONFile=True)
         tansportJSONData = self.treasureChest.getTransport()
         if (tansportJSONData):
             self.transportTAB.settingtransportPanelFromJSONFile(
                 transportJSONFile=tansportJSONData, openFromJSONFile=True)
             self.transportTAB.groupTransportPanel.setChecked(True)
         else:
             pass
         self.dnsTAB.settingDnsTabFromJSONFile(
             dnsJSONFile=self.treasureChest.getDns(), openFromJSONFile=True)
         self.policyTAB.settingPolicyTabFromJSONFile(
             policyJSONFile=self.treasureChest.getPolicy())
         self.apiTAB.settingAPITabFromJSONFile(self.treasureChest.getApi())
Exemple #3
0
    def settingOutboundPanelFromJSONFile(self,
                                         outboundJSONFile,
                                         openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)
        transport = True
        mux = True
        detourPorxy = True
        tag = True

        if (not outboundJSONFile): outboundJSONFile = {}

        try:
            outboundJSONFile["sendThrough"]
        except KeyError as e:
            logbook.writeLog("Outbound", "KeyError", e)
            outboundJSONFile["sendThrough"] = ""

        try:
            outboundJSONFile["protocol"]
        except KeyError as e:
            logbook.writeLog("Outbound", "KeyError", e)
            outboundJSONFile["protocol"] = "vmess"

        try:
            outboundJSONFile["tag"]
        except KeyError as e:
            logbook.writeLog("Outbound", "KeyError", e)
            outboundJSONFile["tag"] = ""
            tag = False

        try:
            outboundJSONFile["settings"]
        except KeyError as e:
            logbook.writeLog("Outbound", "KeyError", e)
            outboundJSONFile["settings"] = {}

        try:
            outboundJSONFile["streamSettings"]
        except KeyError as e:
            outboundJSONFile["streamSettings"] = {}
            logbook.writeLog("Outbound", "KeyError", e)
            transport = False

        try:
            outboundJSONFile["proxySettings"]
        except KeyError as e:
            logbook.writeLog("Outbound", "KeyError", e)
            outboundJSONFile["proxySettings"] = {}

        try:
            outboundJSONFile["proxySettings"]["tag"]
        except KeyError as e:
            outboundJSONFile["proxySettings"]["tag"] = ""
            logbook.writeLog("Outbound", "KeyError", e)
            detourPorxy = False

        try:
            outboundJSONFile["mux"]
        except KeyError as e:
            outboundJSONFile["mux"] = {}
            mux = False

        if (tag):
            self.lineEditOutboundSettingTAG.setText(
                str(outboundJSONFile["tag"]))

        self.lineEditOutboundSettingSendThrough.setText(
            str(outboundJSONFile["sendThrough"]))

        if (detourPorxy and outboundJSONFile["proxySettings"]["tag"]):
            # TODO if JSONFile open from user conf, need get all outbound tags
            self.comboBoxOutboundDetour.addItem(
                outboundJSONFile["proxySettings"]["tag"])
            self.comboBoxOutboundDetour.setCurrentText(
                outboundJSONFile["proxySettings"]["tag"])
        else:
            self.comboBoxOutboundDetour.addItem("")
            self.comboBoxOutboundDetour.setCurrentText("")

        outboundProtocol = outboundJSONFile["protocol"]
        if (outboundJSONFile["settings"]):
            settings = copy.deepcopy(outboundJSONFile["settings"])
            if (outboundProtocol == "vmess"):
                self.settingOutboundVmessPanelFromJSONFile(
                    settings, openFromJSONFile)
            if (outboundProtocol == "socks"):
                self.settingOutboundSocksPanelFromJSONFile(
                    settings, openFromJSONFile)
            if (outboundProtocol == "shadowsocks"):
                self.settingOutboundShadowsocksPanelFromJSONFile(
                    settings, openFromJSONFile)
            if (outboundProtocol == "blackhole"):
                self.settingblackholePanelFromJSONFile(settings,
                                                       openFromJSONFile)
            if (outboundProtocol == "freedom"):
                self.settingfreedomPanelFromJSONFile(settings,
                                                     openFromJSONFile)

        if (outboundProtocol in self.listComboxProtocol):
            self.comboBoxoutboundProtocol.setCurrentText(outboundProtocol)

        if (not transport or not outboundJSONFile["streamSettings"]):
            self.checkBoxTransportSetting.setChecked(False)
            self.groupTransportPanel.hide()
        else:
            self.settingtransportPanelFromJSONFile(
                copy.deepcopy(outboundJSONFile["streamSettings"]),
                openFromJSONFile)
            self.checkBoxTransportSetting.setChecked(True)
            self.groupTransportPanel.show()

        if (not mux and not outboundJSONFile["mux"]):
            self.groupBoxmuxSetting.setChecked(False)
        else:
            self.settingmuxPanelFromJSONFile(
                copy.deepcopy(outboundJSONFile["mux"]), openFromJSONFile)
            self.groupBoxmuxSetting.setChecked(True)
    def settingInboundPanelFromJSONFile(self,
                                        inboundJSONFile={},
                                        openFromJSONFile=False):
        logbook.setisOpenJSONFile(openFromJSONFile)
        allocate = True
        tranport = True
        domainOveride = True
        tag = True

        if (not inboundJSONFile): inboundJSONFile = {}

        try:
            inboundJSONFile["protocol"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["protocol"] = "socks"

        try:
            inboundJSONFile["port"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["port"] = 1080

        try:
            inboundJSONFile["listen"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["listen"] = "127.0.0.1"

        try:
            inboundJSONFile["settings"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["settings"] = {}

        try:
            inboundJSONFile["tag"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["tag"] = ""
            tag = False

        try:
            inboundJSONFile["domainOverride"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["domainOverride"] = [""]
            domainOveride = False

        try:
            inboundJSONFile["streamSettings"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["streamSettings"] = {}
            tranport = False

        try:
            inboundJSONFile["allocate"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["allocate"] = {}
            allocate = False

        try:
            inboundJSONFile["allocate"]["concurrency"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["allocate"]["concurrency"] = 3

        try:
            inboundJSONFile["allocate"]["refresh"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["allocate"]["refresh"] = 5

        try:
            inboundJSONFile["allocate"]["strategy"]
        except KeyError as e:
            logbook.writeLog("Inbound", "KeyError", e)
            inboundJSONFile["allocate"]["strategy"] = "random"

        self.comboBoxInboundProtocol.setCurrentText(
            str(inboundJSONFile["protocol"]))

        # checking Multiple Ports
        port = str(inboundJSONFile["port"])
        if ("-" in port):
            self.groupBoxAllocate.setChecked(True)
            self.spinBoxInboundSettingPort.setValue(int(min(port.split("-"))))
            self.spinBoxMultiplePort.setValue(int(max(port.split("-"))))
            self.spinBoxMultiplePort.setEnabled(True)
            if (allocate):
                try:
                    self.spinBoxInboundSettingConcurrency.setValue(
                        int(inboundJSONFile["allocate"]["concurrency"]))
                except KeyError as e:
                    logbook.writeLog("Inbound", "KeyError", e)
                except (TypeError, ValueError) as e:
                    logbook.writeLog("Inbound", "TypeError or ValueError", e)

                try:
                    self.spinBoxInboundSettingRefresh.setValue(
                        int(inboundJSONFile["allocate"]["refresh"]))
                except KeyError as e:
                    logbook.writeLog("Inbound", "KeyError", e)
                except (TypeError, ValueError) as e:
                    logbook.writeLog("Inbound", "TypeError or ValueError", e)

                strategy = inboundJSONFile["allocate"]["strategy"]
                if (strategy == "always"):
                    self.radioBoxInboundSettingStrategyAlways.setChecked(True)
                if (strategy == "random"):
                    self.radioBoxInboundSettingStrategyRandom.setChecked(True)
                    if (self.groupBoxAllocate.isChecked()):
                        self.spinBoxInboundSettingRefresh.setEnabled(True)
                else:
                    # strategy may be some wrong with value, pass it
                    pass
        else:
            self.spinBoxInboundSettingPort.setValue(int(port))
            self.groupBoxAllocate.setChecked(False)
            self.spinBoxMultiplePort.setDisabled(True)

        if (tag):
            self.lineEditInboundSettingTAG.setText(str(inboundJSONFile["tag"]))

        self.lineEditInboundSettingListen.setText(
            str(inboundJSONFile["listen"]))

        protocol = str(inboundJSONFile["protocol"])
        if (inboundJSONFile["settings"]):
            settings = copy.deepcopy(inboundJSONFile["settings"])
            if (protocol == "vmess"):
                self.settingInboundVmessPanelFromJSONFile(
                    settings, openFromJSONFile)
                self.comboBoxInboundProtocol.setCurrentText("vmess")
            if (protocol == "socks"):
                self.settingInboundSocksPanelFromJSONFile(
                    settings, openFromJSONFile)
                self.comboBoxInboundProtocol.setCurrentText("socks")
            if (protocol == "shadowsocks"):
                self.settingInboundShadowsocksPanelFromJSONFile(
                    settings, openFromJSONFile)
                self.comboBoxInboundProtocol.setCurrentText("shadowsocks")
            if (protocol == "http"):
                self.settinghttpPanelFromJSONFile(settings, openFromJSONFile)
                self.comboBoxInboundProtocol.setCurrentText("http")
            if (protocol == "dokodemo-door"):
                self.settingdokodemodoorPanelFromJSONFile(
                    settings, openFromJSONFile)
                self.comboBoxInboundProtocol.setCurrentText("dokodemo-door")

        if (not tranport or not inboundJSONFile["streamSettings"]):
            self.checkBoxTransportSetting.setChecked(False)
            self.groupTransportPanel.hide()
        else:
            self.settingtransportPanelFromJSONFile(
                copy.deepcopy(inboundJSONFile["streamSettings"]),
                openFromJSONFile)
            self.checkBoxTransportSetting.setChecked(True)
            self.groupTransportPanel.show()

        if (domainOveride and ("http" in inboundJSONFile["domainOverride"])):
            self.checkBoxDomainOverrideHTTP.setChecked(True)

        if (domainOveride and ("tls" in inboundJSONFile["domainOverride"])):
            self.checkBoxDomainOverrideTLS.setChecked(True)