makeReq
= do fqdn <- runInputT defaultSettings $
do defaultFqdn <- liftM uNodeName $ liftIO uname
- fqdn <- getInputLine ("What's your FQDN? (default: " ++ defaultFqdn ++ "): ")
- case trim fqdn of
- Just s -> return s
- _ -> return defaultFqdn
+ getInputLineWithDefault
+ ("What's your FQDN? (default: " ++ defaultFqdn ++ "): ")
+ defaultFqdn
putStrLn "Generating RSA keypair..."
key <- generateRSAKey 1024 3 Nothing
else
do fqdn <- runInputT defaultSettings $
do defaultFqdn <- liftM uNodeName $ liftIO uname
- fqdn <- getInputLine ("What's your FQDN? (default: " ++ defaultFqdn ++ "): ")
- case trim fqdn of
- Just s -> return s
- _ -> return defaultFqdn
+ getInputLineWithDefault
+ ("What's your FQDN? (default: " ++ defaultFqdn ++ "): ")
+ defaultFqdn
putStrLn "Generating RSA keypair..."
key <- generateRSAKey 1024 3 Nothing
where
import Control.Monad
-import Control.Monad.Trans
import DDNS.Utils
import DDNS.Zone
import Database.HaskellDB
editZone :: Database -> IO ()
editZone db
- = runInputT (setComplete (completeZoneName db) defaultSettings) $
- do zoneNameStr <- getInputLine "Which zone do you want to edit (or create?): "
- case trim zoneNameStr of
- Just zoneNameStr'
- -> liftIO $
- do --let zone = read zoneNameStr'
- fail zoneNameStr'
- _ -> return ()
+ = do zone <- runInputT (setComplete (completeZoneName db) defaultSettings) $
+ do name <- getInputLine' "Which zone do you want to edit (or create?): "
+ return $ read name
+ soa <- getZone db zone
+ print soa
signReq :: KeyPair k => k -> X509 -> IO ()
signReq sKey sCert
= runInputT (setComplete completeFilename defaultSettings) $
- do file <- getInputLine "Which X.509 request do you want to sign?: "
- case trim file of
- Just file'
- -> liftIO $
- do req <- readX509Req =<< readFile file'
+ do file <- getInputLine' "Which X.509 request do you want to sign?: "
+ liftIO $ do req <- readX509Req =<< readFile file
key <- Req.getPublicKey req
vst <- verifyX509Req req key
unless (vst == VerifySuccess)
setNotAfter cert =<< liftM (addUTCTime (20 * 365 * 24 * 60 * 60)) getCurrentTime
signX509 cert sKey Nothing
- let certFile = file' `replaceExtension` ".cert"
+ let certFile = file `replaceExtension` ".cert"
withFile certFile WriteMode $ \ h ->
writeX509 cert >>= hPutStr h
putStrLn ("Wrote " ++ certFile)
Just (_, fqdn) <- liftM (find ((== "CN") . fst)) $ X509.getSubjectName cert False
putStrLn ("Now send " ++ certFile ++ " back to " ++ fqdn ++ ".")
- _ -> return ()
module DDNS.Utils
( trim
+ , getInputLine'
+ , getInputLineWithDefault
)
where
+import System.Console.Haskeline
+
+
trim :: Maybe String -> Maybe String
trim Nothing = Nothing
trim (Just xs) = case trimTail $ trimHead xs of
trimHead ys = ys
trimTail = reverse . trimHead . reverse
+
+getInputLine' :: MonadException m => String -> InputT m String
+getInputLine' prompt
+ = do ret <- getInputLine prompt
+ case trim ret of
+ Just ret' -> return ret'
+ Nothing -> fail "No input"
+
+getInputLineWithDefault :: MonadException m => String -> String -> InputT m String
+getInputLineWithDefault prompt defaultStr
+ = do ret <- getInputLine prompt
+ case trim ret of
+ Just ret' -> return ret'
+ Nothing -> return defaultStr
module DDNS.Zone
( listZones
, completeZoneName
+
+ , getZone
)
where
, display = zn
, isFinished = True
}
+
+getZone :: Database -> DomainName -> IO (Maybe SOAFields)
+getZone db name
+ = do rows <- query db $
+ do t <- table Zones.zones
+ restrict (t!Zones.zone .==. constant (show name))
+ return t
+ case rows of
+ [r] -> return $ Just SOAFields {
+ soaMasterNameServer = read $ r!Zones.ns
+ , soaResponsibleMailbox = read $ r!Zones.owner
+ , soaSerialNumber = fromIntegral $ r!Zones.serial
+ , soaRefreshInterval = fromIntegral $ r!Zones.refresh
+ , soaRetryInterval = fromIntegral $ r!Zones.retry
+ , soaExpirationLimit = fromIntegral $ r!Zones.expire
+ , soaMinimumTTL = fromIntegral $ r!Zones.minTTL
+ }
+ _ -> return Nothing
\ No newline at end of file