2012-11-17 19:30:11 +00:00
|
|
|
{- git-annex assistant webapp configurators for WebDAV remotes
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012, 2013 Joey Hess <id@joeyh.name>
|
2012-11-17 19:30:11 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2020-09-08 16:42:59 +00:00
|
|
|
{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
|
2012-11-17 19:30:11 +00:00
|
|
|
|
|
|
|
module Assistant.WebApp.Configurators.WebDAV where
|
|
|
|
|
2012-11-25 04:26:46 +00:00
|
|
|
import Assistant.WebApp.Common
|
2013-04-20 23:25:50 +00:00
|
|
|
import Creds
|
2012-11-17 19:30:11 +00:00
|
|
|
import qualified Remote.WebDAV as WebDAV
|
2013-10-28 15:33:14 +00:00
|
|
|
import Assistant.WebApp.MakeRemote
|
2012-11-17 19:30:11 +00:00
|
|
|
import qualified Remote
|
2020-03-20 16:48:43 +00:00
|
|
|
import Types.Remote (RemoteConfig, config)
|
2012-11-17 19:30:11 +00:00
|
|
|
import Types.StandardGroups
|
2012-11-17 19:58:27 +00:00
|
|
|
import Logs.Remote
|
2013-11-07 22:02:00 +00:00
|
|
|
import Git.Types (RemoteName)
|
2017-08-17 16:26:14 +00:00
|
|
|
import Assistant.Gpg
|
|
|
|
import Types.GitConfig
|
2019-10-10 17:08:17 +00:00
|
|
|
import Annex.SpecialRemote.Config
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2023-03-27 17:38:02 +00:00
|
|
|
import Utility.Url
|
2012-11-17 19:30:11 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2013-04-20 23:25:50 +00:00
|
|
|
import qualified Data.Text as T
|
2013-04-27 19:16:06 +00:00
|
|
|
import Network.URI
|
2012-11-17 19:30:11 +00:00
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
webDAVConfigurator :: Widget -> Handler Html
|
2012-12-30 03:10:18 +00:00
|
|
|
webDAVConfigurator = page "Add a WebDAV repository" (Just Configuration)
|
2012-11-17 19:58:27 +00:00
|
|
|
|
2012-11-17 19:30:11 +00:00
|
|
|
data WebDAVInput = WebDAVInput
|
|
|
|
{ user :: Text
|
|
|
|
, password :: Text
|
2012-11-28 17:31:49 +00:00
|
|
|
, embedCreds :: Bool
|
2012-11-17 19:30:11 +00:00
|
|
|
, directory :: Text
|
2012-12-04 17:28:22 +00:00
|
|
|
, enableEncryption :: EnableEncryption
|
2012-11-17 19:30:11 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 17:31:49 +00:00
|
|
|
toCredPair :: WebDAVInput -> CredPair
|
|
|
|
toCredPair input = (T.unpack $ user input, T.unpack $ password input)
|
|
|
|
|
2013-06-03 20:33:05 +00:00
|
|
|
webDAVCredsAForm :: Maybe CredPair -> MkAForm WebDAVInput
|
2013-04-27 19:16:06 +00:00
|
|
|
webDAVCredsAForm defcreds = WebDAVInput
|
2014-04-18 00:07:09 +00:00
|
|
|
<$> areq textField (bfs "Username or Email") (T.pack . fst <$> defcreds)
|
|
|
|
<*> areq passwordField (bfs "Password") (T.pack . snd <$> defcreds)
|
2012-11-28 17:31:49 +00:00
|
|
|
<*> pure False
|
|
|
|
<*> pure T.empty
|
2012-12-04 17:28:22 +00:00
|
|
|
<*> pure NoEncryption -- not used!
|
2012-11-17 19:58:27 +00:00
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
getEnableWebDAVR :: UUID -> Handler Html
|
2013-03-16 22:48:23 +00:00
|
|
|
getEnableWebDAVR = postEnableWebDAVR
|
2013-06-27 05:15:28 +00:00
|
|
|
postEnableWebDAVR :: UUID -> Handler Html
|
2013-03-16 22:48:23 +00:00
|
|
|
postEnableWebDAVR uuid = do
|
2020-09-22 17:52:26 +00:00
|
|
|
m <- liftAnnex remoteConfigMap
|
2012-11-17 19:58:27 +00:00
|
|
|
let c = fromJust $ M.lookup uuid m
|
2019-10-10 17:08:17 +00:00
|
|
|
let name = fromJust $ lookupName c
|
2020-01-10 18:10:20 +00:00
|
|
|
let url = fromProposedAccepted $ fromJust $ M.lookup (Accepted "url") c
|
2017-08-17 16:26:14 +00:00
|
|
|
mcreds <- liftAnnex $ do
|
|
|
|
dummycfg <- liftIO dummyRemoteGitConfig
|
fix encryption of content to gcrypt and git-lfs
Fix serious regression in gcrypt and encrypted git-lfs remotes.
Since version 7.20200202.7, git-annex incorrectly stored content
on those remotes without encrypting it.
Problem was, Remote.Git enumerates all git remotes, including git-lfs
and gcrypt. It then dispatches to those. So, Remote.List used the
RemoteConfigParser from Remote.Git, instead of from git-lfs or gcrypt,
and that parser does not know about encryption fields, so did not
include them in the ParsedRemoteConfig. (Also didn't include other
fields specific to those remotes, perhaps chunking etc also didn't
get through.)
To fix, had to move RemoteConfig parsing down into the generate methods
of each remote, rather than doing it in Remote.List.
And a consequence of that was that ParsedRemoteConfig had to change to
include the RemoteConfig that got parsed, so that testremote can
generate a new remote based on an existing remote.
(I would have rather fixed this just inside Remote.Git, but that was not
practical, at least not w/o re-doing work that Remote.List already did.
Big ugly mostly mechanical patch seemed preferable to making git-annex
slower.)
2020-02-26 21:20:56 +00:00
|
|
|
pc <- parsedRemoteConfig WebDAV.remote c
|
2020-01-15 17:47:31 +00:00
|
|
|
getRemoteCredPairFor "webdav" pc dummycfg (WebDAV.davCreds uuid)
|
2012-11-28 17:31:49 +00:00
|
|
|
case mcreds of
|
2013-06-03 17:51:54 +00:00
|
|
|
Just creds -> webDAVConfigurator $ liftH $
|
2013-09-27 04:15:50 +00:00
|
|
|
makeWebDavRemote enableSpecialRemote name creds M.empty
|
2019-01-22 15:48:35 +00:00
|
|
|
Nothing -> webDAVConfigurator $ showform name url
|
2012-11-17 19:58:27 +00:00
|
|
|
where
|
2012-11-28 17:31:49 +00:00
|
|
|
showform name url = do
|
2013-04-27 19:16:06 +00:00
|
|
|
defcreds <- liftAnnex $
|
|
|
|
maybe (pure Nothing) previouslyUsedWebDAVCreds $
|
|
|
|
urlHost url
|
2013-06-03 17:51:54 +00:00
|
|
|
((result, form), enctype) <- liftH $
|
2014-04-18 00:07:09 +00:00
|
|
|
runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $
|
|
|
|
webDAVCredsAForm defcreds
|
2012-11-17 19:58:27 +00:00
|
|
|
case result of
|
2013-06-03 17:51:54 +00:00
|
|
|
FormSuccess input -> liftH $
|
2013-09-27 04:15:50 +00:00
|
|
|
makeWebDavRemote enableSpecialRemote name (toCredPair input) M.empty
|
2012-11-17 19:58:27 +00:00
|
|
|
_ -> do
|
2013-03-16 04:12:28 +00:00
|
|
|
description <- liftAnnex $
|
2013-04-03 21:01:40 +00:00
|
|
|
T.pack <$> Remote.prettyUUID uuid
|
2012-11-17 19:58:27 +00:00
|
|
|
$(widgetFile "configurators/enablewebdav")
|
|
|
|
|
2013-09-27 04:15:50 +00:00
|
|
|
makeWebDavRemote :: SpecialRemoteMaker -> RemoteName -> CredPair -> RemoteConfig -> Handler ()
|
2020-03-20 16:48:43 +00:00
|
|
|
makeWebDavRemote maker name creds c =
|
2013-09-29 18:39:10 +00:00
|
|
|
setupCloudRemote TransferGroup Nothing $
|
2020-03-20 16:48:43 +00:00
|
|
|
maker name WebDAV.remote (Just creds) c
|
2013-04-27 19:16:06 +00:00
|
|
|
|
|
|
|
{- Only returns creds previously used for the same hostname. -}
|
|
|
|
previouslyUsedWebDAVCreds :: String -> Annex (Maybe CredPair)
|
|
|
|
previouslyUsedWebDAVCreds hostname =
|
|
|
|
previouslyUsedCredPair WebDAV.davCreds WebDAV.remote samehost
|
|
|
|
where
|
2020-03-20 16:48:43 +00:00
|
|
|
samehost r = case urlHost =<< WebDAV.configUrl (config r) of
|
2013-04-27 19:16:06 +00:00
|
|
|
Nothing -> False
|
|
|
|
Just h -> h == hostname
|
|
|
|
|
|
|
|
urlHost :: String -> Maybe String
|
2023-03-27 17:38:02 +00:00
|
|
|
urlHost url = uriRegName <$> (uriAuthority =<< parseURIPortable url)
|