コード例 #1
0
ファイル: JAP.py プロジェクト: web883/jap
    def action_JAP_UPDATE(self, request):
        data = request.args["data"][0]

        decoder = JAP_LOCAL.JSONDecoder()
        configuration = decoder.decode(data)

        JAP_LOCAL.setConfiguration("./JAP.json", configuration,
                                   getDefaultConfiguration)

        logger = logging.getLogger("JAP")

        if configuration["LOGGER"]["LEVEL"] == "DEBUG":
            logger.setLevel(logging.DEBUG)
        elif configuration["LOGGER"]["LEVEL"] == "INFO":
            logger.setLevel(logging.INFO)
        elif configuration["LOGGER"]["LEVEL"] == "WARNING":
            logger.setLevel(logging.WARNING)
        elif configuration["LOGGER"]["LEVEL"] == "ERROR":
            logger.setLevel(logging.ERROR)
        elif configuration["LOGGER"]["LEVEL"] == "CRITICAL":
            logger.setLevel(logging.CRITICAL)
        else:
            logger.setLevel(logging.NOTSET)

        resolver = JAP_LOCAL.createResolver(configuration)
        reactor.installResolver(resolver)

        return ""
コード例 #2
0
ファイル: JAP.py プロジェクト: blockme9527/jap
 def action_JAP_UPDATE(self, request):
     data = request.args["data"][0]
     
     decoder = JAP_LOCAL.JSONDecoder()
     configuration = decoder.decode(data)
     
     JAP_LOCAL.setConfiguration("./JAP.json", configuration, getDefaultConfiguration)
     
     logger = logging.getLogger("JAP")
     
     if configuration["LOGGER"]["LEVEL"] == "DEBUG":
         logger.setLevel(logging.DEBUG)
     elif configuration["LOGGER"]["LEVEL"] == "INFO":
         logger.setLevel(logging.INFO)
     elif configuration["LOGGER"]["LEVEL"] == "WARNING":
         logger.setLevel(logging.WARNING)
     elif configuration["LOGGER"]["LEVEL"] == "ERROR":
         logger.setLevel(logging.ERROR)
     elif configuration["LOGGER"]["LEVEL"] == "CRITICAL":
         logger.setLevel(logging.CRITICAL)
     else:
         logger.setLevel(logging.NOTSET)
     
     resolver = JAP_LOCAL.createResolver(configuration)
     reactor.installResolver(resolver)
     
     return ""
コード例 #3
0
ファイル: JAP.py プロジェクト: web883/jap
    def action_JAP_REMOTE_WS(self, request):
        configuration = JAP_LOCAL.getConfiguration(
            "./JAP_REMOTE_WS.json", JAP_REMOTE_WS.getDefaultConfiguration)

        encoder = JAP_LOCAL.JSONEncoder()
        data = encoder.encode(configuration)

        return data
コード例 #4
0
ファイル: JAP.py プロジェクト: blockme9527/jap
 def action_JAP_REMOTE_WS_UPDATE(self, request):
     data = request.args["data"][0]
     
     decoder = JAP_LOCAL.JSONDecoder()
     configuration = decoder.decode(data)
     
     JAP_LOCAL.setConfiguration("./JAP_REMOTE_WS.json", configuration, JAP_REMOTE_WS.getDefaultConfiguration)
     
     return ""
コード例 #5
0
ファイル: JAP.py プロジェクト: web883/jap
    def action_JAP_REMOTE_WS_UPDATE(self, request):
        data = request.args["data"][0]

        decoder = JAP_LOCAL.JSONDecoder()
        configuration = decoder.decode(data)

        JAP_LOCAL.setConfiguration("./JAP_REMOTE_WS.json", configuration,
                                   JAP_REMOTE_WS.getDefaultConfiguration)

        return ""
コード例 #6
0
ファイル: JAP_LOCAL_WS.py プロジェクト: web883/jap
    def onOpen(self):
        logger.debug("WSOutputProtocol.onOpen")

        self.connectionState = 1

        request = collections.OrderedDict()
        request["REMOTE_PROXY_SERVER"] = collections.OrderedDict()
        request["REMOTE_PROXY_SERVER"][
            "AUTHENTICATION"] = collections.OrderedDict()
        request["REMOTE_PROXY_SERVER"]["AUTHENTICATION"]["USERNAME"] = str(
            self.inputProtocol.configuration["REMOTE_PROXY_SERVERS"][
                self.inputProtocol.i]["AUTHENTICATION"]["USERNAME"])
        request["REMOTE_PROXY_SERVER"]["AUTHENTICATION"]["PASSWORD"] = str(
            self.inputProtocol.configuration["REMOTE_PROXY_SERVERS"][
                self.inputProtocol.i]["AUTHENTICATION"]["PASSWORD"])
        request["REMOTE_ADDRESS"] = str(self.inputProtocol.remoteAddress)
        request["REMOTE_PORT"] = self.inputProtocol.remotePort

        encoder = JAP_LOCAL.JSONEncoder()
        message = encoder.encode(request)

        self.sendMessage(message, False)

        self.message = ""
        self.messageState = 0
コード例 #7
0
ファイル: JAP_WS_LOCAL.py プロジェクト: gkmuse/jap
def setDefaultConfiguration(configuration):
    JAP_LOCAL.setDefaultConfiguration(configuration)
    
    configuration.setdefault("REMOTE_PROXY_SERVERS", [])
    i = 0
    while i < len(configuration["REMOTE_PROXY_SERVERS"]):
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("TYPE", "")
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("ADDRESS", "")
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("PORT", 0)
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("AUTHENTICATION", {})
        configuration["REMOTE_PROXY_SERVERS"][i]["AUTHENTICATION"].setdefault("USERNAME", "")
        configuration["REMOTE_PROXY_SERVERS"][i]["AUTHENTICATION"].setdefault("PASSWORD", "")
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("CERTIFICATE", {})
        configuration["REMOTE_PROXY_SERVERS"][i]["CERTIFICATE"].setdefault("AUTHENTICATION", {})
        configuration["REMOTE_PROXY_SERVERS"][i]["CERTIFICATE"]["AUTHENTICATION"].setdefault("FILE", "")
        i = i + 1
コード例 #8
0
ファイル: JAP.py プロジェクト: blockme9527/jap
 def action_JAP(self, request):
     configuration = JAP_LOCAL.getConfiguration("./JAP.json", getDefaultConfiguration)
     
     encoder = JAP_LOCAL.JSONEncoder()
     data = encoder.encode(configuration)
     
     return data
コード例 #9
0
ファイル: JAP.py プロジェクト: blockme9527/jap
 def action_JAP_REMOTE_WS_START(self, request):
     port = self.port_JAP_REMOTE_WS
     
     if port == None:
         configuration = JAP_LOCAL.getConfiguration("./JAP_REMOTE_WS.json", JAP_REMOTE_WS.getDefaultConfiguration)
         
         if configuration["REMOTE_PROXY_SERVER"]["TYPE"] == "HTTPS":
             factory = JAP_REMOTE_WS.WSInputProtocolFactory(configuration, "wss://" + str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) + ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"]), debug = False)
             factory.protocol = JAP_REMOTE_WS.WSInputProtocol
             
             contextFactory = ssl.DefaultOpenSSLContextFactory(configuration["REMOTE_PROXY_SERVER"]["CERTIFICATE"]["KEY"]["FILE"], configuration["REMOTE_PROXY_SERVER"]["CERTIFICATE"]["FILE"])
             
             port = ssl.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, contextFactory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
             port.startListening()
             
             self.port_JAP_REMOTE_WS = port
         else:
             factory = JAP_REMOTE_WS.WSInputProtocolFactory(configuration, "ws://" + str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) + ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"]), debug = False)
             factory.protocol = JAP_REMOTE_WS.WSInputProtocol
             
             port = tcp.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
             port.startListening()
             
             self.port_JAP_REMOTE_WS = port
         
         return ""
コード例 #10
0
    def connect(self):
        logger.debug("SSHClientTransportFactory.connect")

        tunnel = JAP_LOCAL.Tunnel(self.configuration)
        tunnel.connect(
            self.configuration["REMOTE_PROXY_SERVERS"][self.i]["ADDRESS"],
            self.configuration["REMOTE_PROXY_SERVERS"][self.i]["PORT"], self)
コード例 #11
0
ファイル: JAP_REMOTE_WS.py プロジェクト: web883/jap
    def processMessageState0(self):
        logger.debug("WSInputProtocol.processMessageState0")

        decoder = JAP_LOCAL.JSONDecoder()
        request = decoder.decode(self.message)

        authorized = False

        if len(self.configuration["REMOTE_PROXY_SERVER"]
               ["AUTHENTICATION"]) == 0:
            authorized = True

        if authorized == False:
            i = 0
            while i < len(self.configuration["REMOTE_PROXY_SERVER"]
                          ["AUTHENTICATION"]):
                if self.configuration["REMOTE_PROXY_SERVER"]["AUTHENTICATION"][
                        i]["USERNAME"] == request["REMOTE_PROXY_SERVER"][
                            "AUTHENTICATION"][
                                "USERNAME"] and self.configuration[
                                    "REMOTE_PROXY_SERVER"]["AUTHENTICATION"][
                                        i]["PASSWORD"] == request[
                                            "REMOTE_PROXY_SERVER"][
                                                "AUTHENTICATION"]["PASSWORD"]:
                    authorized = True
                    break

                i = i + 1

        if authorized == False:
            self.sendClose()

            return

        self.remoteAddress = request["REMOTE_ADDRESS"]
        self.remotePort = request["REMOTE_PORT"]

        logger.debug("WSInputProtocol.remoteAddress: " + self.remoteAddress)
        logger.debug("WSInputProtocol.remotePort: " + str(self.remotePort))

        outputProtocolFactory = WSOutputProtocolFactory(self)
        outputProtocolFactory.protocol = WSOutputProtocol

        tunnel = JAP_LOCAL.Tunnel(self.configuration)
        tunnel.connect(self.remoteAddress, self.remotePort,
                       outputProtocolFactory)
コード例 #12
0
ファイル: JAP_LOCAL_WS.py プロジェクト: web883/jap
    def connect(self):
        logger.debug("WSInputProtocol.connect")

        self.i = random.randrange(
            0, len(self.configuration["REMOTE_PROXY_SERVERS"]))

        if self.configuration["REMOTE_PROXY_SERVERS"][
                self.i]["TYPE"] == "HTTPS":
            factory = WSOutputProtocolFactory(
                self,
                "wss://" + str(self.configuration["REMOTE_PROXY_SERVERS"][
                    self.i]["ADDRESS"]) + ":" +
                str(self.configuration["REMOTE_PROXY_SERVERS"][self.i]
                    ["PORT"]),
                debug=False)
            factory.protocol = WSOutputProtocol

            if self.configuration["REMOTE_PROXY_SERVERS"][
                    self.i]["CERTIFICATE"]["AUTHENTICATION"]["FILE"] != "":
                contextFactory = ClientContextFactory(
                    self.configuration["REMOTE_PROXY_SERVERS"][
                        self.i]["CERTIFICATE"]["AUTHENTICATION"]["FILE"])
            else:
                contextFactory = ssl.ClientContextFactory()

            tunnel = JAP_LOCAL.Tunnel(self.configuration)
            tunnel.connect(
                self.configuration["REMOTE_PROXY_SERVERS"][self.i]["ADDRESS"],
                self.configuration["REMOTE_PROXY_SERVERS"][self.i]["PORT"],
                factory, contextFactory)
        else:
            factory = WSOutputProtocolFactory(
                self,
                "ws://" + str(self.configuration["REMOTE_PROXY_SERVERS"][
                    self.i]["ADDRESS"]) + ":" +
                str(self.configuration["REMOTE_PROXY_SERVERS"][self.i]
                    ["PORT"]),
                debug=False)
            factory.protocol = WSOutputProtocol

            tunnel = JAP_LOCAL.Tunnel(self.configuration)
            tunnel.connect(
                self.configuration["REMOTE_PROXY_SERVERS"][self.i]["ADDRESS"],
                self.configuration["REMOTE_PROXY_SERVERS"][self.i]["PORT"],
                factory)
コード例 #13
0
ファイル: JAP.py プロジェクト: web883/jap
    def action_JAP_LOCAL_START(self, request):
        port = self.port_JAP_LOCAL

        if port == None:
            configuration = JAP_LOCAL.getConfiguration(
                "./JAP_LOCAL.json", JAP_LOCAL.getDefaultConfiguration)

            factory = JAP_LOCAL.InputProtocolFactory(configuration)
            factory.protocol = JAP_LOCAL.InputProtocol

            port = tcp.Port(configuration["LOCAL_PROXY_SERVER"]["PORT"],
                            factory, 50,
                            configuration["LOCAL_PROXY_SERVER"]["ADDRESS"],
                            reactor)
            port.startListening()

            self.port_JAP_LOCAL = port

            return ""
コード例 #14
0
ファイル: JAP_LOCAL_WS.py プロジェクト: web883/jap
    def processMessageState0(self):
        logger.debug("WSOutputProtocol.processMessageState0")

        decoder = JAP_LOCAL.JSONDecoder()
        response = decoder.decode(self.message)

        self.inputProtocol.outputProtocol_connectionMade()

        self.message = ""
        self.messageState = 1
コード例 #15
0
 def channelOpen(self, specificData):
     logger.debug("SSHChannel.channelOpen")
     
     self.connectionState = 1
     
     outputProtocolFactory = SSHOutputProtocolFactory(self)
     outputProtocolFactory.protocol = SSHOutputProtocol
     
     tunnel = JAP_LOCAL.Tunnel(self.avatar.configuration)
     tunnel.connect(self.remoteAddress, self.remotePort, outputProtocolFactory)
コード例 #16
0
ファイル: JAP.py プロジェクト: blockme9527/jap
 def action_JAP_REMOTE_SSH_START(self, request):
     port = self.port_JAP_REMOTE_SSH
     
     if port == None:
         configuration = JAP_LOCAL.getConfiguration("./JAP_REMOTE_SSH.json", JAP_REMOTE_SSH.getDefaultConfiguration)
         
         factory = JAP_REMOTE_SSH.SSHFactory(configuration)
         
         port = tcp.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
         port.startListening()
         
         self.port_JAP_REMOTE_SSH = port
         
         return ""
コード例 #17
0
ファイル: JAP.py プロジェクト: blockme9527/jap
 def action_JAP_LOCAL_WS_START(self, request):
     port = self.port_JAP_LOCAL_WS
     
     if port == None:
         configuration = JAP_LOCAL.getConfiguration("./JAP_LOCAL_WS.json", JAP_LOCAL_WS.getDefaultConfiguration)
         
         factory = JAP_LOCAL_WS.WSInputProtocolFactory(configuration)
         factory.protocol = JAP_LOCAL_WS.WSInputProtocol
         
         port = tcp.Port(configuration["LOCAL_PROXY_SERVER"]["PORT"], factory, 50, configuration["LOCAL_PROXY_SERVER"]["ADDRESS"], reactor)
         port.startListening()
         
         self.port_JAP_LOCAL_WS = port
         
         return ""
コード例 #18
0
ファイル: JAP_SSH_LOCAL.py プロジェクト: gkmuse/jap
def setDefaultConfiguration(configuration):
    JAP_LOCAL.setDefaultConfiguration(configuration)
    
    configuration["LOCAL_PROXY_SERVER"].setdefault("KEYS", [])
    i = 0
    while i < len(configuration["LOCAL_PROXY_SERVER"]["KEYS"]):
        configuration["LOCAL_PROXY_SERVER"]["KEYS"][i].setdefault("PUBLIC", {})
        configuration["LOCAL_PROXY_SERVER"]["KEYS"][i]["PUBLIC"].setdefault("FILE", "")
        configuration["LOCAL_PROXY_SERVER"]["KEYS"][i].setdefault("PRIVATE", {})
        configuration["LOCAL_PROXY_SERVER"]["KEYS"][i]["PRIVATE"].setdefault("FILE", "")
        configuration["LOCAL_PROXY_SERVER"]["KEYS"][i]["PRIVATE"].setdefault("PASSPHRASE", "")
        i = i + 1
    configuration.setdefault("REMOTE_PROXY_SERVERS", [])
    i = 0
    while i < len(configuration["REMOTE_PROXY_SERVERS"]):
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("ADDRESS", "")
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("PORT", 0)
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("AUTHENTICATION", {})
        configuration["REMOTE_PROXY_SERVERS"][i]["AUTHENTICATION"].setdefault("USERNAME", "")
        configuration["REMOTE_PROXY_SERVERS"][i]["AUTHENTICATION"].setdefault("PASSWORD", "")
        configuration["REMOTE_PROXY_SERVERS"][i].setdefault("KEYS", {})
        configuration["REMOTE_PROXY_SERVERS"][i]["KEY"].setdefault("AUTHENTICATION", {})
        configuration["REMOTE_PROXY_SERVERS"][i]["KEY"]["AUTHENTICATION"].setdefault("FINGERPRINT", "")
        i = i + 1
コード例 #19
0
ファイル: JAP.py プロジェクト: web883/jap
    def action_JAP_REMOTE_WS_START(self, request):
        port = self.port_JAP_REMOTE_WS

        if port == None:
            configuration = JAP_LOCAL.getConfiguration(
                "./JAP_REMOTE_WS.json", JAP_REMOTE_WS.getDefaultConfiguration)

            if configuration["REMOTE_PROXY_SERVER"]["TYPE"] == "HTTPS":
                factory = JAP_REMOTE_WS.WSInputProtocolFactory(
                    configuration,
                    "wss://" +
                    str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) +
                    ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"]),
                    debug=False)
                factory.protocol = JAP_REMOTE_WS.WSInputProtocol

                contextFactory = ssl.DefaultOpenSSLContextFactory(
                    configuration["REMOTE_PROXY_SERVER"]["CERTIFICATE"]["KEY"]
                    ["FILE"], configuration["REMOTE_PROXY_SERVER"]
                    ["CERTIFICATE"]["FILE"])

                port = ssl.Port(
                    configuration["REMOTE_PROXY_SERVER"]["PORT"], factory,
                    contextFactory, 50,
                    configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
                port.startListening()

                self.port_JAP_REMOTE_WS = port
            else:
                factory = JAP_REMOTE_WS.WSInputProtocolFactory(
                    configuration,
                    "ws://" +
                    str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) +
                    ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"]),
                    debug=False)
                factory.protocol = JAP_REMOTE_WS.WSInputProtocol

                port = tcp.Port(
                    configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50,
                    configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
                port.startListening()

                self.port_JAP_REMOTE_WS = port

            return ""
コード例 #20
0
ファイル: JAP.py プロジェクト: web883/jap
    def action_JAP_REMOTE_SSH_START(self, request):
        port = self.port_JAP_REMOTE_SSH

        if port == None:
            configuration = JAP_LOCAL.getConfiguration(
                "./JAP_REMOTE_SSH.json",
                JAP_REMOTE_SSH.getDefaultConfiguration)

            factory = JAP_REMOTE_SSH.SSHFactory(configuration)

            port = tcp.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"],
                            factory, 50,
                            configuration["REMOTE_PROXY_SERVER"]["ADDRESS"],
                            reactor)
            port.startListening()

            self.port_JAP_REMOTE_SSH = port

            return ""
コード例 #21
0
ファイル: JAP_REMOTE_WS.py プロジェクト: web883/jap
    def outputProtocol_connectionMade(self):
        logger.debug("WSInputProtocol.outputProtocol_connectionMade")

        if self.connectionState == 1:
            response = collections.OrderedDict()
            response["REMOTE_ADDRESS"] = self.remoteAddress
            response["REMOTE_PORT"] = self.remotePort

            encoder = JAP_LOCAL.JSONEncoder()
            message = encoder.encode(response)

            self.sendMessage(message, False)

            self.outputProtocol.inputProtocol_connectionMade()

            self.message = ""
            self.messageState = 1
        else:
            if self.connectionState == 2:
                self.outputProtocol.inputProtocol_connectionLost(None)