X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=pdns-pipe-nmc.hs;h=5fc64fa1c940c96bff85b47f80ec7bc65943b307;hp=e62a1e7d438f3d145da076b748856aa4fc2d527b;hb=0288e756cf28a0229c03a946e54cda94252526c1;hpb=1ee46aba2ad401d2b9b11fe57eef1fb5697c905c diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index e62a1e7..5fc64fa 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -4,6 +4,7 @@ module Main where import Prelude hiding (lookup, readFile) import System.Environment +import System.Console.GetOpt import System.IO hiding (readFile) import System.IO.Error import Data.Time.Clock.POSIX @@ -20,7 +21,9 @@ import Data.Map.Lazy (Map, empty, lookup, insert, delete, size) import Data.Aeson (encode, decode, Value(..)) import Network.HTTP.Types import Network.HTTP.Client -import Data.Default (def) +import Data.Default.Class (def) +-- if you have data-default-0.5.1 import this instead of Data.Default.Class: +-- import Data.Default (def) import JsonRpcClient import Config @@ -78,7 +81,7 @@ queryDom queryOp fqdn = -- Yet another - to use (const - expires_in) from the lookup. nmcAge = fmap (\x -> floor ((x - 1303070400) / 600)) getPOSIXTime --- Main entries +-- run a PowerDNS coprocess. Negotiate ABI version and execute requests. mainPdnsNmc = do @@ -156,7 +159,7 @@ pdnsOut gen key qt dom = "AXFR" -> pdnsOutXfr 1 (-1) gen key dom _ -> pdnsOutQ 1 (-1) gen key (rrType qt) dom --- query by key from Namecoin +-- run one query by key from Namecoin, print domain object and answer mainOne gen key qt = do cfg <- readConfig confFile @@ -165,7 +168,7 @@ mainOne gen key qt = do putStrLn $ ppShow dom putStr $ pdnsOut gen key qt dom --- using file backend for testing json domain data +-- get data from the file, print domain object and answer mainFile gen key qt = do dom <- queryDom queryOpFile key @@ -177,8 +180,12 @@ mainFile gen key qt = do main = do args <- getArgs gen <- nmcAge + let + with f xs = case xs of + [qfqdn, qtype] -> f gen qfqdn qtype + _ -> error $ "usage: empty args, or \"[-f] {|ANY|AXFR}\"" + ++ " (type in caps)" case args of - [] -> mainPdnsNmc - [key, qtype] -> mainOne gen key qtype - ["-f" ,key, qtype] -> mainFile gen key qtype - _ -> error $ "usage: empty args, or \"[-f] {|ANY|AXFR}\" (type in caps)" + [] -> mainPdnsNmc + "-f":xs -> with mainFile xs + _ -> with mainOne args