]> gitweb @ CieloNegro.org - blackboard-dns.git/blob - DDNS/Server/EditZone.hs
editzone
[blackboard-dns.git] / DDNS / Server / EditZone.hs
1 module DDNS.Server.EditZone
2     ( editZone
3     )
4     where
5
6 import           DDNS.Utils
7 import           DDNS.Zone
8 import           Database.HaskellDB
9 import           Data.Maybe
10 import           Network.DNS.Message
11 import           System.Console.Haskeline
12
13 editZone :: Database -> IO ()
14 editZone db
15     = do zone <- runInputT (setComplete (completeZoneName db) defaultSettings) $
16                  readInputLine' "Which zone do you want to edit (or create?): "
17          soa  <- getZone db zone
18          ns   <- let d = fromMaybe (read $ "ns." ++ show zone) $ fmap soaMasterNameServer soa
19                  in runInputT defaultSettings $
20                     readInputLineWithDefault
21                         ("Which host is the master name server? (default: " ++ show d ++ "): ")
22                         d
23          mail <- let d = fromMaybe (read $ "root." ++ show ns) $ fmap soaResponsibleMailbox soa
24                  in runInputT defaultSettings $
25                     readInputLineWithDefault
26                         ("Which is the mailbox of responsibility? (default: " ++ show d ++ "): ")
27                         d
28          refr <- let d = fromIntegral $ fromMaybe 3600 $ fmap soaRefreshInterval soa
29                  in runInputT defaultSettings $
30                     readInputLineWithDefault
31                         ("How many seconds should refresh interval be? (default: " ++ show d ++ "): ")
32                         d
33          retr <- let d = fromIntegral $ fromMaybe 900 $ fmap soaRetryInterval soa
34                  in runInputT defaultSettings $
35                     readInputLineWithDefault
36                         ("How many seconds should retry interval be? (default: " ++ show d ++ "): ")
37                         d
38          expi <- let d = fromIntegral $ fromMaybe 604800 $ fmap soaExpirationLimit soa
39                  in runInputT defaultSettings $
40                     readInputLineWithDefault
41                         ("How many seconds should expiration limit be? (default: " ++ show d ++ "): ")
42                         d
43          mint <- let d = fromIntegral $ fromMaybe 3600 $ fmap soaExpirationLimit soa
44                  in runInputT defaultSettings $
45                     readInputLineWithDefault
46                         ("How many seconds should minimum TTL be? (default: " ++ show d ++ "): ")
47                         d
48          let soa' = SOAFields {
49                       soaMasterNameServer   = ns
50                     , soaResponsibleMailbox = mail
51                     , soaSerialNumber       = fromMaybe 0 $ fmap ((+1) . soaSerialNumber) soa
52                     , soaRefreshInterval    = refr
53                     , soaRetryInterval      = retr
54                     , soaExpirationLimit    = expi
55                     , soaMinimumTTL         = mint
56                     }
57          putZone db zone soa'