summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-01-03 18:50:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-01-03 18:50:30 -0400
commitfbaf52d7b852d02ec0b5bfe639715a29024b1a9b (patch)
treec6f5db7ac6fc3d9f15210ab10b3bb61c9f8ea93f
parent1c880e8692e9722967a30d4c4f59107e15360d92 (diff)
restart UI
Browser behavior is not ideal; a new tab is opened on restart. Browsers won't let me redirect to a file:// so I cannot use the old tab.
-rw-r--r--Assistant/Threads/WebApp.hs32
-rw-r--r--Utility/FileMode.hs9
-rw-r--r--Utility/WebApp.hs22
-rw-r--r--debian/changelog2
4 files changed, 35 insertions, 30 deletions
diff --git a/Assistant/Threads/WebApp.hs b/Assistant/Threads/WebApp.hs
index 58e7de1f6..5ac36f698 100644
--- a/Assistant/Threads/WebApp.hs
+++ b/Assistant/Threads/WebApp.hs
@@ -29,8 +29,8 @@ import Assistant.WebApp.Control
import Assistant.WebApp.OtherRepos
import Assistant.Types.ThreadedMonad
import Utility.WebApp
-import Utility.FileMode
import Utility.TempFile
+import Utility.FileMode
import Git
import Yesod
@@ -84,36 +84,10 @@ webAppThread assistantdata urlrenderer noannex postfirstrun onstartup = thread $
=<< runThreadState (threadState assistantdata) (fromRepo repoPath))
go port webapp htmlshim urlfile = do
let url = myUrl webapp port
- maybe noop (`writeFile` url) urlfile
- writeHtmlShim url htmlshim
+ maybe noop (`writeFileProtected` url) urlfile
+ writeHtmlShim "Starting webapp..." url htmlshim
maybe noop (\a -> a url htmlshim) onstartup
-{- Creates a html shim file that's used to redirect into the webapp,
- - to avoid exposing the secretToken when launching the web browser. -}
-writeHtmlShim :: String -> FilePath -> IO ()
-writeHtmlShim url file = viaTmp go file $ genHtmlShim url
- where
- go tmpfile content = do
- h <- openFile tmpfile WriteMode
- modifyFileMode tmpfile $ removeModes [groupReadMode, otherReadMode]
- hPutStr h content
- hClose h
-
-{- TODO: generate this static file using Yesod. -}
-genHtmlShim :: String -> String
-genHtmlShim url = unlines
- [ "<html>"
- , "<head>"
- , "<title>Starting webapp...</title>"
- , "<meta http-equiv=\"refresh\" content=\"0; URL="++url++"\">"
- , "<body>"
- , "<p>"
- , "<a href=\"" ++ url ++ "\">Starting webapp...</a>"
- , "</p>"
- , "</body>"
- , "</html>"
- ]
-
myUrl :: WebApp -> PortNumber -> Url
myUrl webapp port = unpack $ yesodRender webapp urlbase HomeR []
where
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs
index ddb89b2aa..0f7046333 100644
--- a/Utility/FileMode.hs
+++ b/Utility/FileMode.hs
@@ -101,3 +101,12 @@ isSticky = checkMode stickyMode
setSticky :: FilePath -> IO ()
setSticky f = modifyFileMode f $ addModes [stickyMode]
+
+{- Writes a file, ensuring that its modes do not allow it to be read
+ - by anyone other than the current user, before any content is written. -}
+writeFileProtected :: FilePath -> String -> IO ()
+writeFileProtected file content = do
+ h <- openFile file WriteMode
+ modifyFileMode file $ removeModes [groupReadMode, otherReadMode]
+ hPutStr h content
+ hClose h
diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs
index 6f64b2bdf..d3bd523a8 100644
--- a/Utility/WebApp.hs
+++ b/Utility/WebApp.hs
@@ -10,6 +10,8 @@
module Utility.WebApp where
import Common
+import Utility.TempFile
+import Utility.FileMode
import qualified Yesod
import qualified Network.Wai as Wai
@@ -188,3 +190,23 @@ insertAuthToken extractToken predicate webapp root pathbits params =
params'
| predicate pathbits = authparam:params
| otherwise = params
+
+{- Creates a html shim file that's used to redirect into the webapp,
+ - to avoid exposing the secret token when launching the web browser. -}
+writeHtmlShim :: String -> String -> FilePath -> IO ()
+writeHtmlShim title url file = viaTmp writeFileProtected file $ genHtmlShim title url
+
+{- TODO: generate this static file using Yesod. -}
+genHtmlShim :: String -> String -> String
+genHtmlShim title url = unlines
+ [ "<html>"
+ , "<head>"
+ , "<title>"++ title ++ "</title>"
+ , "<meta http-equiv=\"refresh\" content=\"1; URL="++url++"\">"
+ , "<body>"
+ , "<p>"
+ , "<a href=\"" ++ url ++ "\">" ++ title ++ "</a>"
+ , "</p>"
+ , "</body>"
+ , "</html>"
+ ]
diff --git a/debian/changelog b/debian/changelog
index 39707c6c2..8979d29df 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,6 @@
git-annex (3.20130103) UNRELEASED; urgency=low
- * webapp: Add UI to stop assistant.
+ * webapp: Add UI to stop and restart assistant.
-- Joey Hess <joeyh@debian.org> Thu, 03 Jan 2013 14:58:45 -0400