10 import Control.Monad.Trans
12 import Database.HaskellDB
13 import qualified DDNS.DB.Zones as Zones
14 import Network.DNS.Message
15 import System.Console.Haskeline
18 listZones :: Database -> IO [DomainName]
20 = do rows <- query db $ do t <- table Zones.zones
21 project (Zones.zone << t!Zones.zone)
22 return $ map (read . (!Zones.zone)) rows
24 completeZoneName :: MonadIO m => Database -> CompletionFunc m
26 = completeWord Nothing "" $ \ prefix ->
27 do zones <- liftM (map show) $ liftIO $ listZones db
28 return $ produceCands zones prefix
30 produceCands :: [String] -> String -> [Completion]
31 produceCands zones prefix
32 = let cands = filter (prefix `isPrefixOf`) zones
33 comps = map mkComp cands
37 mkComp :: String -> Completion
45 getZone :: Database -> DomainName -> IO (Maybe SOAFields)
47 = do rows <- query db $
48 do t <- table Zones.zones
49 restrict (t!Zones.zone .==. constant (show name))
52 [r] -> return $ Just SOAFields {
53 soaMasterNameServer = read $ r!Zones.ns
54 , soaResponsibleMailbox = read $ r!Zones.owner
55 , soaSerialNumber = fromIntegral $ r!Zones.serial
56 , soaRefreshInterval = fromIntegral $ r!Zones.refresh
57 , soaRetryInterval = fromIntegral $ r!Zones.retry
58 , soaExpirationLimit = fromIntegral $ r!Zones.expire
59 , soaMinimumTTL = fromIntegral $ r!Zones.minTTL