From 1822704b7cb39eb890b81b270143e7d9eb319f2b Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 1 May 2016 22:51:52 +0000 Subject: Handle ipsec.secret --- cokiki.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'cokiki.hs') diff --git a/cokiki.hs b/cokiki.hs index f8eed0a..2638677 100644 --- a/cokiki.hs +++ b/cokiki.hs @@ -132,17 +132,29 @@ sshServer uid root cmn = whenRoot uid root cmn $ do Kiki.importAndRefresh root cmn strongswan uid root cmn = whenRoot uid root cmn $ do + -- (1) /etc/ipsec.conf <-- 'include /var/cache/kiki/config/ipsec.conf' -- Parsing as if ssh config, that's not right, but good enough for now. ipsecconf <- parseSshConfig . fromMaybe "" <$> maybeReadFile (root "/etc/ipsec.conf") let p:gs = groupBy (\_ d -> not $ sshIsDirective "include" d) $ ["#"]:ipsecconf got = filter (\(d:ds) -> elem "/var/cache/kiki/config/ipsec.conf" d) gs case got of - _:_ -> do hPutStrLn stderr "ipsec already configured." + _:_ -> do hPutStrLn stderr "ipsec.conf already configured." [] -> do let ipsecconf' = drop 1 $ ipsecconf ++ [stmt] stmt = ["include", " ", "/var/cache/kiki/config/ipsec.conf"] hPutStrLn stderr "adding include directive" myWriteFile (root "/etc/ipsec.conf") $ unparseSshConfig ipsecconf' - -- etc/ipsec.conf <-- 'include /var/cache/kiki/ipsec.conf' + + -- (2) /etc/ipsec.secrets/ <- include /var/cache/kiki/config/ipsec.secrets + -- Parsing as if ssh config, that's not right, but good enough for now. + ipsecconf <- parseSshConfig . fromMaybe "" <$> maybeReadFile (root "/etc/ipsec.secrets") + let p:gs = groupBy (\_ d -> not $ sshIsDirective "include" d) $ ["#"]:ipsecconf + got = filter (\(d:ds) -> elem "/var/cache/kiki/config/ipsec.secrets" d) gs + case got of + _:_ -> do hPutStrLn stderr "ipsec.secrets already configured." + [] -> do let ipsecconf' = drop 1 $ ipsecconf ++ [stmt] + stmt = ["include", " ", "/var/cache/kiki/config/ipsec.secrets"] + hPutStrLn stderr "adding include directive" + myWriteFile (root "/etc/ipsec.secrets") $ unparseSshConfig ipsecconf' Kiki.importAndRefresh root cmn configureTor uid root cmn = whenRoot uid root cmn $ do -- cgit v1.2.3 From 246a78be5da87cb48144c12b512a84d3999191b5 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 1 May 2016 23:18:35 +0000 Subject: Correction to cokiki docs. --- cokiki.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cokiki.hs') diff --git a/cokiki.hs b/cokiki.hs index 2638677..292b0b7 100644 --- a/cokiki.hs +++ b/cokiki.hs @@ -41,14 +41,14 @@ usage = unlines , "COMMANDS" , "" , " ssh-client Modify system ssh configuration to respect" - , " /var/cache/kiki/ssh_known_hosts." + , " /var/cache/kiki/config/ssh_known_hosts." , "" , " ssh-server Modify system ssh configuration to use the" , " kiki-managed host key at" - , " /var/cache/kiki/ssh_host_rsa_key." + , " /var/cache/kiki/config/ssh_host_rsa_key." , "" , " strongswan Modify /etc/ipsec.conf to include settings from" - , " /var/cache/kiki/ipsec.conf." + , " /var/cache/kiki/config/ipsec.conf." , "" , " tor Modify /etc/tor/torrc to configure a tor hidden" , " service for email (smtp), ssh, and http ports." -- cgit v1.2.3 From b04dd1bba833852e22844696ecad365a11248e98 Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 2 May 2016 00:21:02 +0000 Subject: implemented cokiki hosts command to merge cache hosts with etc hosts. --- cokiki.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'cokiki.hs') diff --git a/cokiki.hs b/cokiki.hs index 292b0b7..8e6ec35 100644 --- a/cokiki.hs +++ b/cokiki.hs @@ -19,6 +19,7 @@ import System.Exit import System.IO import System.Posix.User import CommandLine +import qualified Hosts usage = unlines [ "cokiki [--chroot=ROOTDIR]" @@ -52,6 +53,9 @@ usage = unlines , "" , " tor Modify /etc/tor/torrc to configure a tor hidden" , " service for email (smtp), ssh, and http ports." + , "" + , " hosts Merge hostnames from /var/cache/kiki/config/hosts" + , " into system file /etc/hosts." ] main = do @@ -62,6 +66,7 @@ main = do ["ssh-server"] -> Just $ sshServer uid <$> Kiki.ㄧchroot <*> Kiki.ㄧhomedir ["strongswan"] -> Just $ strongswan uid <$> Kiki.ㄧchroot <*> Kiki.ㄧhomedir ["tor"] -> Just $ configureTor uid <$> Kiki.ㄧchroot <*> Kiki.ㄧhomedir + ["hosts"] -> Just $ configureHosts uid <$> Kiki.ㄧchroot <*> Kiki.ㄧhomedir _ -> Nothing spec = uncurry fancy Kiki.kikiOptions "" errorQuit msg = do @@ -77,6 +82,7 @@ main = do maybeReadFile :: FilePath -> IO (Maybe L.ByteString) maybeReadFile path = do doesFileExist path >>= bool (return Nothing) (Just <$> L.readFile path) + myWriteFile f bs = do createDirectoryIfMissing True (takeDirectory f) hPutStrLn stderr $ "Writing "++f @@ -212,6 +218,14 @@ configureTor uid root cmn = whenRoot uid root cmn $ do Kiki.importAndRefresh root cmn return () +configureHosts uid root cmn = whenRoot uid root cmn $ do + Kiki.importAndRefresh root cmn + hosts <- Hosts.decode . fromMaybe "" <$> maybeReadFile (root "/etc/hosts") + kikihosts <- Hosts.decode . fromMaybe "" <$> maybeReadFile (root "/var/cache/kiki/config/hosts") + let hosts' = hosts `Hosts.plus` kikihosts + case Hosts.diff hosts hosts' of + [] -> hPutStrLn stderr "kiki hosts are already merged." + _ -> myWriteFile (root "/etc/hosts") $ Hosts.encode hosts' parseSshConfig :: L.ByteString -> [[L.ByteString]] parseSshConfig bs = map tokenize $ L8.lines bs -- cgit v1.2.3