diff --git a/src/HttpProxy.hs b/src/HttpProxy.hs index 224f208..ada3ebf 100644 --- a/src/HttpProxy.hs +++ b/src/HttpProxy.hs @@ -58,7 +58,7 @@ httpProxyConnection HttpProxySettings{..} (host, port) app = onError $ do sendConnectRequest :: Connection -> IO () sendConnectRequest h = write h $ "CONNECT " <> fromString host <> ":" <> fromString (show port) <> " HTTP/1.0\r\n" - <> "Host: " <> fromString host <> ":" <> (fromString $ show port) <> "\r\n" + <> "Host: " <> fromString host <> ":" <> fromString (show port) <> "\r\n" <> maybe mempty credentialsToHeader credentials <> "\r\n" @@ -75,6 +75,6 @@ httpProxyConnection HttpProxySettings{..} (host, port) app = onError $ do isAuthorized response = " 200 " `isInfixOf` response onError f = catch f $ \(e :: SomeException) -> return $ - if (take 10 (show e) == "user error") + if take 10 (show e) == "user error" then throwError $ ProxyConnectionError (show e) else throwError $ ProxyConnectionError ("Unknown Error :: " <> show e) diff --git a/src/Socks5.hs b/src/Socks5.hs index 933ff22..df67352 100644 --- a/src/Socks5.hs +++ b/src/Socks5.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} @@ -73,7 +72,7 @@ instance Binary RequestAuth where put RequestAuth{..} = do putWord8 (fromIntegral version) putWord8 (fromIntegral $ length methods) - sequence_ (put <$> methods) + mapM_ put methods -- Check length <= 255 get = do @@ -134,8 +133,7 @@ instance Binary Request where host <- if opCode == 0x03 then do length <- fromIntegral <$> getWord8 - host <- either (const T.empty) id . E.decodeUtf8' <$> replicateM length getWord8 - return host + fromRight T.empty . E.decodeUtf8' <$> replicateM length getWord8 else do ipv4 <- replicateM 4 getWord8 :: Get [Word8] let ipv4Str = T.intercalate "." $ fmap (tshow . fromEnum) ipv4 @@ -200,7 +198,7 @@ instance Binary Response where opCode <- fromIntegral <$> getWord8 -- Type guard(opCode == 0x03) length <- fromIntegral <$> getWord8 - host <- either (const T.empty) id . E.decodeUtf8' <$> replicateM length getWord8 + host <- fromRight T.empty . E.decodeUtf8' <$> replicateM length getWord8 guard (not $ null host) port <- getWord16be @@ -219,12 +217,4 @@ data ServerSettings = ServerSettings , bindOn :: HostName -- , onAuthentification :: (MonadIO m, MonadError IOException m) => RequestAuth -> m ResponseAuth -- , onRequest :: (MonadIO m, MonadError IOException m) => Request -> m Response - } deriving (Show) - - - - - - - - -- + } deriving (Show) \ No newline at end of file diff --git a/src/Tunnel.hs b/src/Tunnel.hs index 778b0ec..26ee1e5 100644 --- a/src/Tunnel.hs +++ b/src/Tunnel.hs @@ -64,9 +64,9 @@ tunnelingClientP cfg@TunnelSettings{..} app conn = onError $ do debug "Opening Websocket stream" stream <- connectionToStream conn - let authorization = if not (null upgradeCredentials) then [("Authorization", "Basic " <> B64.encode upgradeCredentials)] else [] + let authorization = ([("Authorization", "Basic " <> B64.encode upgradeCredentials) | not (null upgradeCredentials)]) let headers = authorization <> customHeaders - let hostname = if not (null hostHeader) then (BC.unpack hostHeader) else serverHost + let hostname = if not (null hostHeader) then BC.unpack hostHeader else serverHost ret <- WS.runClientWithStream stream hostname (toPath cfg) WS.defaultConnectionOptions headers run @@ -240,6 +240,8 @@ serverEventLoop sClient isAllowed pendingConn = do case proto of UDP -> runUDPClient (BC.unpack rhost, fromIntegral rport) (\cnx -> void $ toConnection conn <==> toConnection cnx) TCP -> runTCPClient (BC.unpack rhost, fromIntegral rport) (\cnx -> void $ toConnection conn <==> toConnection cnx) + STDIO -> mempty + SOCKS5 -> mempty runServer :: Bool -> (HostName, PortNumber) -> ((ByteString, Int) -> Bool) -> IO ()