pi-hoole-0.1.0.0: app/shell/Main.hs
-- pi-hoole: lightweight access-control for pijul
-- Copyright (C) 2018 Thomas Letan <contact@thomasletan.fr>
--
-- This program 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.
--
-- This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M (fromList)
import Data.Set (Set)
import qualified Data.Set as S (fromList)
import Data.Text (Text, append, pack, unpack)
import qualified Data.Text.IO as T (getLine)
import Data.Void (Void)
import Data.Yaml (decodeFile)
import PiHoole
import System.Directory (XdgDirectory (..), getXdgDirectory)
import System.Environment (getArgs)
import Text.Megaparsec (parseTest)
-------------------------------------------------------------------------------
main :: IO ()
main = getArgs >>= \case
[ "--license" ] ->
putStrLn license
[ user, "" ] ->
putStrLn $ "connected as " ++ user
[ user, cmd ] ->
getConfiguration >>= \case
Just cfg ->
case (parseUserName (pack user), parsePijul (pack cmd)) of
(Just user, Just cmd) ->
pijulProxy cfg user cmd
(Nothing, _) ->
putStrLn $ user ++ " is not a valid role"
(_, Nothing) ->
putStrLn $ cmd ++ " is not a valid pijul command"
Nothing ->
putStrLn "could not parse the configuration file"
_ ->
putStrLn "incorrect shell command"
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
getConfiguration :: IO (Maybe Configuration)
getConfiguration = getXdgDirectory XdgConfig "pi-hoole/config.yaml" >>= decodeFile
decodeLimes :: FilePath -> IO (Maybe Configuration)
decodeLimes = decodeFile
pijulProxy :: Configuration -> UserName -> Pijul -> IO ()
pijulProxy cfg user cmd
| checkPrivilege user cmd cfg = callPijul cmd
| otherwise = putStrLn "nah"
license :: String
license =
unlines [ "Copyright (C) 2018 Thomas Letan <contact@thomasletan.fr>"
, ""
, "This program 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."
, ""
, "This program 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 this program. If not, see <http://www.gnu.org/licenses/>."
]
-------------------------------------------------------------------------------