webapp: check that tor and magic wormhole are installed
authorJoey Hess <joeyh@joeyh.name>
Sat, 24 Dec 2016 21:08:03 +0000 (17:08 -0400)
committerJoey Hess <joeyh@joeyh.name>
Sat, 24 Dec 2016 21:08:03 +0000 (17:08 -0400)
Assistant/WebApp/Configurators/Pairing.hs
Utility/Tor.hs
git-annex.cabal
templates/configurators/needmagicwormhole.hamlet [new file with mode: 0644]
templates/configurators/needtor.hamlet [new file with mode: 0644]

index 60a8ee7138ddbf4be6176ea3c116557e86637399..3381b4f6475c21fe28a6c98ff750a8b65d190a98 100644 (file)
@@ -22,6 +22,7 @@ import Assistant.DaemonStatus
 import Utility.Verifiable
 #endif
 import Utility.UserInfo
+import Utility.Tor
 import qualified Utility.MagicWormhole as Wormhole
 import Git
 
@@ -49,14 +50,15 @@ postStartTorPairSelfR :: Handler Html
 postStartTorPairSelfR = postStartTorPairR PairingWithSelf
 
 postStartTorPairR :: PairingWith -> Handler Html
-postStartTorPairR pairingwith = pairPage $ do
-       let Just ourcode = Wormhole.mkCode "11-bannana-bananna" -- XXX tmp
-       ((result, form), enctype) <- liftH $
-               runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $
-                       areq wormholeCodeField (bfs codeprompt) Nothing
-       case result of
-               FormSuccess v -> error "TODO"
-               _ -> showform form enctype ourcode
+postStartTorPairR pairingwith = whenTorInstalled $ whenWormholeInstalled $
+       pairPage $ do
+               let Just ourcode = Wormhole.mkCode "11-bannana-bananna" -- XXX tmp
+               ((result, form), enctype) <- liftH $
+                       runFormPostNoToken $ renderBootstrap3 bootstrapFormLayout $
+                               areq wormholeCodeField (bfs codeprompt) Nothing
+               case result of
+                       FormSuccess v -> error "TODO"
+                       _ -> showform form enctype ourcode
   where
        showform form enctype ourcode = $(widgetFile "configurators/pairing/tor/prompt")
        codeprompt = case pairingwith of
@@ -66,6 +68,20 @@ postStartTorPairR pairingwith = pairPage $ do
                ("That does not look like a valid pairing code. Try again..." :: T.Text)
                textField
 
+whenTorInstalled :: Handler Html -> Handler Html
+whenTorInstalled a = ifM (liftIO torIsInstalled)
+       ( a
+       , page "Need Tor" (Just Configuration) $
+               $(widgetFile "configurators/needtor")
+       )
+
+whenWormholeInstalled :: Handler Html -> Handler Html
+whenWormholeInstalled a = ifM (liftIO Wormhole.isInstalled)
+       ( a
+       , page "Need Magic Wormhole" (Just Configuration) $
+               $(widgetFile "configurators/needmagicwormhole")
+       )
+
 {- Starts local pairing. -}
 getStartLocalPairR :: Handler Html
 getStartLocalPairR = postStartLocalPairR
index 4e7c0ef43fc171913a87589ec2b5d2b7f7ebd0b5..37fbabd402d44ee942d73edbf1d54d03332660c5 100644 (file)
@@ -161,3 +161,6 @@ torLibDir = "/var/lib/tor"
 
 varLibDir :: FilePath
 varLibDir = "/var/lib"
+
+torIsInstalled :: IO Bool
+torIsInstalled = inPath "tor"
index f6a4e1660613f21a9392aaf76eb76c31b39543ef..f2ba8897932fdcbf031c951d08d133d30984838d 100644 (file)
@@ -227,6 +227,8 @@ Extra-Source-Files:
   templates/configurators/rsync.net/encrypt.hamlet
   templates/configurators/gitlab.com/add.hamlet
   templates/configurators/needgcrypt.hamlet
+  templates/configurators/needtor.hamlet
+  templates/configurators/needmagicwormhole.hamlet
   templates/configurators/enabledirectory.hamlet
   templates/configurators/fsck/status.hamlet
   templates/configurators/fsck/form.hamlet
diff --git a/templates/configurators/needmagicwormhole.hamlet b/templates/configurators/needmagicwormhole.hamlet
new file mode 100644 (file)
index 0000000..c10d3a1
--- /dev/null
@@ -0,0 +1,11 @@
+<div .col-sm-9>
+  <div .content-box>
+    <h2>
+      Need Magic Wormhole
+    <p>
+      You need to install #
+      <a href="https://github.com/warner/magic-wormhole">
+        Magic Wormhole
+    <p>
+      <a .btn .btn-primary .btn-lg href="">
+        Retry
diff --git a/templates/configurators/needtor.hamlet b/templates/configurators/needtor.hamlet
new file mode 100644 (file)
index 0000000..808cbe9
--- /dev/null
@@ -0,0 +1,11 @@
+<div .col-sm-9>
+  <div .content-box>
+    <h2>
+      Need Tor
+    <p>
+      You need to install #
+      <a href="https://torproject.org/">
+        Tor
+    <p>
+      <a .btn .btn-primary .btn-lg href="">
+        Retry