diff --git a/Assistant/Threads/WebApp.hs b/Assistant/Threads/WebApp.hs index 58e7de1f69..5ac36f6989 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 - [ "" - , "" - , "Starting webapp..." - , "" - , "" - , "

" - , "Starting webapp..." - , "

" - , "" - , "" - ] - myUrl :: WebApp -> PortNumber -> Url myUrl webapp port = unpack $ yesodRender webapp urlbase HomeR [] where diff --git a/Assistant/WebApp/Control.hs b/Assistant/WebApp/Control.hs index f87b22941f..e6846be47d 100644 --- a/Assistant/WebApp/Control.hs +++ b/Assistant/WebApp/Control.hs @@ -10,6 +10,7 @@ module Assistant.WebApp.Control where import Assistant.WebApp.Common +import Locations.UserConfig import Control.Concurrent import System.Posix (getProcessID, signalProcess, sigTERM) @@ -26,3 +27,16 @@ getShutdownConfirmedR = page "Shutdown" Nothing $ do threadDelay 2000000 signalProcess sigTERM =<< getProcessID $(widgetFile "control/shutdownconfirmed") + +{- Quite a hack, and doesn't redirect the browser window. -} +getRestartR :: Handler RepHtml +getRestartR = page "Restarting" Nothing $ do + void $ liftIO $ forkIO $ do + threadDelay 2000000 + program <- readProgramFile + unlessM (boolSystem "sh" [Param "-c", Param $ restartcommand program]) $ + error "restart failed" + $(widgetFile "control/restarting") + where + restartcommand program = program ++ " assistant --stop; " ++ + program ++ " webapp" diff --git a/Assistant/WebApp/DashBoard.hs b/Assistant/WebApp/DashBoard.hs index 3f37acc4d4..a9666c8796 100644 --- a/Assistant/WebApp/DashBoard.hs +++ b/Assistant/WebApp/DashBoard.hs @@ -125,9 +125,7 @@ openFileBrowser = do boolSystem cmd [Param path] return True , do - clearUltDest - setUltDest $ "file://" ++ path - void $ redirectUltDest HomeR + void $ redirect $ "file://" ++ path return False ) where diff --git a/Assistant/WebApp/routes b/Assistant/WebApp/routes index f50365b7c7..22ffbb5a53 100644 --- a/Assistant/WebApp/routes +++ b/Assistant/WebApp/routes @@ -7,6 +7,7 @@ /shutdown ShutdownR GET /shutdown/confirm ShutdownConfirmedR GET +/restart RestartR GET /config ConfigurationR GET /config/repository RepositoriesR GET diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index ddb89b2aab..0f70463339 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 6f64b2bdff..d3bd523a82 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 + [ "" + , "" + , ""++ title ++ "" + , "" + , "" + , "

" + , "" ++ title ++ "" + , "

" + , "" + , "" + ] diff --git a/debian/changelog b/debian/changelog index 39707c6c27..8979d29df5 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 Thu, 03 Jan 2013 14:58:45 -0400 diff --git a/templates/control/restarting.hamlet b/templates/control/restarting.hamlet new file mode 100644 index 0000000000..fdddc8dc13 --- /dev/null +++ b/templates/control/restarting.hamlet @@ -0,0 +1,2 @@ +
+ Restarting... diff --git a/templates/controlmenu.hamlet b/templates/controlmenu.hamlet index 3b9b827b4e..815d84b8c2 100644 --- a/templates/controlmenu.hamlet +++ b/templates/controlmenu.hamlet @@ -4,5 +4,7 @@ Add another local repository Switch repository + + Restart daemon - Shut down + Shutdown daemon