2020 endpoint = flag .String ("e" , "/var/run/docker.sock" , "Dockerd endpoint" )
2121 addr = flag .String ("p" , ":9000" , "Address and port to serve UI For Docker" )
2222 assets = flag .String ("a" , "." , "Path to the assets" )
23+ data = flag .String ("d" , "." , "Path to the data" )
2324 authKey []byte
2425 authKeyFile = "authKey.dat"
2526)
@@ -72,7 +73,7 @@ func createUnixHandler(e string) http.Handler {
7273 return & UnixHandler {e }
7374}
7475
75- func createHandler (dir string , e string ) http.Handler {
76+ func createHandler (dir string , d string , e string ) http.Handler {
7677 var (
7778 mux = http .NewServeMux ()
7879 fileHandler = http .FileServer (http .Dir (dir ))
@@ -92,11 +93,12 @@ func createHandler(dir string, e string) http.Handler {
9293 }
9394
9495 // Use existing csrf authKey if present or generate a new one.
95- dat , err := ioutil .ReadFile (authKeyFile )
96+ var authKeyPath = d + "/" + authKeyFile
97+ dat , err := ioutil .ReadFile (authKeyPath )
9698 if err != nil {
9799 fmt .Println (err )
98100 authKey = securecookie .GenerateRandomKey (32 )
99- err := ioutil .WriteFile (authKeyFile , authKey , 0644 )
101+ err := ioutil .WriteFile (authKeyPath , authKey , 0644 )
100102 if err != nil {
101103 fmt .Println ("unable to persist auth key" , err )
102104 }
@@ -125,7 +127,7 @@ func csrfWrapper(h http.Handler) http.Handler {
125127func main () {
126128 flag .Parse ()
127129
128- handler := createHandler (* assets , * endpoint )
130+ handler := createHandler (* assets , * data , * endpoint )
129131 if err := http .ListenAndServe (* addr , handler ); err != nil {
130132 log .Fatal (err )
131133 }
0 commit comments