Skip to content

Commit

Permalink
disable every browser except firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
Mast3rwaf1z committed Nov 11, 2024
1 parent 24f8c83 commit 527a195
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import Text.Blaze.Html (Html)
import Text.Blaze.Html.Renderer.String (renderHtml)

import Data.List (find, intercalate)
import Data.Text (unpack)
import Data.Text (unpack, isInfixOf, pack)

import System.Directory (doesFileExist)

import Blaze.ByteString.Builder (copyByteString)
import Data.ByteString.UTF8 (ByteString, fromString)
import Network.HTTP.Types (HeaderName, Query, Status, status200, status404, statusCode)
import Network.Wai (Request (queryString), responseBuilder, responseFile, responseLBS)
import Network.Wai (Request (queryString, requestHeaderUserAgent), responseBuilder, responseFile, responseLBS)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Internal (Request, Response (ResponseBuilder, ResponseFile), pathInfo, requestMethod)

Expand Down Expand Up @@ -77,32 +77,35 @@ app request respond = do
let args = "/" ++ intercalate "/" xs
print $ getStates request
print $ getCookies request
response <- if x == "static" then do
-- If the requested content is a file
serveFile $ intercalate "/" xs
else if x == "favicon.ico" then do
-- If the requested file is the icon file
serveFile "static/favicon.ico"
else if x == "api" then do
-- If the request is to the API
(status, value, headers) <- api request
return $ responseBuilder status headers $ copyByteString (fromString value)
else do
-- If the content is to the HTML Frontend
let (settings, page) = findPage args
result <- page request
let image = if embedImage settings /= "" then [hsx|
<meta content={embedImage settings} property="og:image">
|] else [hsx||]
let text = if embedText settings /= "" then [hsx|
<meta content={embedText settings} property="og:title">
|] else [hsx||]
let desc = if description settings /= "" then [hsx|
<meta content={description settings} property="og:description">
|] else [hsx||]

footer' <- footer request
return $ serve (mconcat [result, image, text, desc, footer'])
response <- case isInfixOf "Firefox" . pack . unpackBS <$> requestHeaderUserAgent request of
(Just True) -> do
if x == "static" then do
-- If the requested content is a file
serveFile $ intercalate "/" xs
else if x == "favicon.ico" then do
-- If the requested file is the icon file
serveFile "static/favicon.ico"
else if x == "api" then do
-- If the request is to the API
(status, value, headers) <- api request
return $ responseBuilder status headers $ copyByteString (fromString value)
else do
-- If the content is to the HTML Frontend
let (settings, page) = findPage args
result <- page request
let image = if embedImage settings /= "" then [hsx|
<meta content={embedImage settings} property="og:image">
|] else [hsx||]
let text = if embedText settings /= "" then [hsx|
<meta content={embedText settings} property="og:title">
|] else [hsx||]
let desc = if description settings /= "" then [hsx|
<meta content={description settings} property="og:description">
|] else [hsx||]

footer' <- footer request
return $ serve (mconcat [result, image, text, desc, footer'])
_ -> return $ serve [hsx|Error, only firefox is currently supported!|]

logger request response
respond response
Expand Down

0 comments on commit 527a195

Please sign in to comment.