From a5d134dbfd55fe73cf798f052057ad5e3e0b547c Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 23 Nov 2022 11:26:03 +1100 Subject: updated a bit for compliance run --- README.org | 29 +++++++++++++++++++++++++++++ app/Main.hs | 45 ++++++++++++++++++++++++++++++++++++++++----- build.sh | 1 + librejserver.cabal | 1 + 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 README.org diff --git a/README.org b/README.org new file mode 100644 index 0000000..61be26b --- /dev/null +++ b/README.org @@ -0,0 +1,29 @@ +* librejserver: a server program serving librejs compliance info + +*WIP - it does not work yet*. + +The program should return librejs report for a given page. It should +return JSON for a given url: + +http://localhost:5678/https://fsf.org + +returns a JSON report of the compliance of https://fsf.org + +A more advanced version of this program should take user input url +(url to a webpage, not a javascript file), run librejs compliance, and +return the report to user. If the user is ok for the report to be +shared, it will also be added to a database. The server can then +serve a filtered / sorted list of urls by compliance, popularity etc. +This can help users discover sites that are librejs-compliant. + +An even more advanced version of this program should list reasons for +non-compliance of free javascript, and librejs devs can use this data +and statistics to determine how to update the compliance check to +cover more free javascript. A more advanced librejs can download a +database, and add javascript to whitelist depending on some threshold +from the data. + +Problem: + +1. This is an SaaSS +2. Without moderation or approval, user will submit nonfree javascript diff --git a/app/Main.hs b/app/Main.hs index fa816ae..8dd0f47 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,3 +1,23 @@ +{- +Copyright (C) 2022 Yuchen Pei. + +This file is part of librejserver. + +librejserver is free software: you can redistribute it and/or modify it under +the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +librejserver is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +Public License for more details. + +You should have received a copy of the GNU Affero General Public +License along with librejserver. If not, see . + +-} + {-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeOperators #-} @@ -7,6 +27,7 @@ import Data.Proxy ( Proxy(..) ) import Data.Text ( Text ) import qualified Data.Text as T import Network.Wai.Handler.Warp ( run ) +import Paths_librejserver import Servant ( (:>) , Application , CaptureAll @@ -16,7 +37,13 @@ import Servant ( (:>) , Server , serve ) -import System.Process ( readProcess ) +import System.IO ( hGetContents ) +import System.Process ( CreateProcess(..) + , createProcess + , proc + , readCreateProcess + , readProcess + ) type API = GetPageCompliance @@ -25,17 +52,25 @@ type GetPageCompliance = CaptureAll "url" Text :> Get '[JSON] Text server :: Server API server = getPageCompliance +-- TODO: use runCompliance once that function is fixed. getPageCompliance :: [Text] -> Handler Text getPageCompliance urlPieces = return $ "You have requested librejs-compliance info for " <> T.intercalate "/" urlPieces +-- FIXME: not working: selenium webdriver says +-- Error: Server terminated early with status 127 runCompliance :: Text -> IO Text -runCompliance url = T.pack <$> readProcess - "bin/node" - ["~/source/librejserver/librejs/utilities/compliance.js", T.unpack url] - "" +runCompliance url = do + dataDir <- getDataDir + T.pack + <$> readCreateProcess + (proc "node" ["./utilities/compliance.js", T.unpack url]) + { cwd = Just (dataDir ++ "/librejs") + , env = Just [("PATH", "$PATH:./node_modules/.bin")] + } + [] app :: Application app = serve api server diff --git a/build.sh b/build.sh index ff62f95..bfa4b0d 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ set -eux +cabal build git clone https://git.savannah.gnu.org/git/librejs.git cd librejs npm install acorn@"<=8.7.1" jssha browserify selenium-webdriver geckodriver diff --git a/librejserver.cabal b/librejserver.cabal index 3048390..a84ec3a 100644 --- a/librejserver.cabal +++ b/librejserver.cabal @@ -12,5 +12,6 @@ extra-source-files: CHANGELOG.md executable librejserver main-is: Main.hs build-depends: base, servant-server, text, warp, process + other-modules: Paths_librejserver hs-source-dirs: app default-language: Haskell2010 -- cgit v1.2.3