def onbtnSave(self): text = self.textEditor.toPlainText() if (not text): self.statusBar.showMessage("There have nothing to svae...") return JSONData = openV2rayJSONFile().jsonDataValitor(copy.deepcopy(text)) if (JSONData[0] == -1): logbook.writeLog("", "Parse json File Error", JSONData[1]) self.statusBar.showMessage(JSONData[1]) return else: JSONData = copy.deepcopy( json.dumps(JSONData[1], indent=4, sort_keys=False)) options = QFileDialog.Options() fileName, _ = QFileDialog.getSaveFileName( self, "Save V2ray config.json file", "", """ json file (*.json);; All file (*) """, options=options) if (fileName and JSONData): openV2rayJSONFile().saveTextdata(filePath=fileName, data=JSONData)
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 initboundJSONData(self): """ save config.json file's data to class boundJSONData. ########################## boundJSONData.py self.__log = {} self.__dns = {} self.__api = {} self.__routing = {} self.__policy = {} self.__inbound = {} self.__outbound = {} self.__inboundDetour = {} self.__outboundDetour = {} self.__transport = {} self.__stats = {} ########################## """ JSONData = False if (self.JSONData): JSONData = copy.deepcopy(self.JSONData) else: return False try: JSONData["log"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["log"] = {} try: JSONData["dns"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["dns"] = {} try: JSONData["api"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["api"] = {} try: JSONData["routing"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["routing"] = {} try: JSONData["policy"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["policy"] = {} JSONData["policy"]["levels"] = {} try: JSONData["inbound"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["inbound"] = {} try: JSONData["outbound"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["outbound"] = {} try: JSONData["inboundDetour"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["inboundDetour"] = {} try: JSONData["outboundDetour"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["outboundDetour"] = {} try: JSONData["transport"] except KeyError as e: logbook.writeLog("", "Parse json File Error", e) JSONData["transport"] = {} try: JSONData["stats"] except KeyError: JSONData["stats"] = {} self.treasureChest.clear() self.treasureChest.setLog(JSONData["log"]) self.treasureChest.setDns(JSONData["dns"]) if JSONData["api"]: self.treasureChest.setApi(JSONData["api"]) if JSONData["stats"]: self.treasureChest.setStats(JSONData["stats"]) self.treasureChest.setPolicy(JSONData["policy"]["levels"]) self.treasureChest.setRouting(JSONData["routing"]) self.treasureChest.setInbound(JSONData["inbound"], openFromJSONFile=True) self.treasureChest.setOutbound(JSONData["outbound"], openFromJSONFile=True) self.treasureChest.setInboundDetour(None, JSONData["inboundDetour"], openFromJSONFile=True) self.treasureChest.setOutboundDetour(None, JSONData["outboundDetour"], openFromJSONFile=True) self.treasureChest.setTransport(JSONData["transport"]) return JSONData
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)