Skip to content

Commit df81c65

Browse files
mwfarbjuagargi
authored andcommitted
fixed: bad paths, bad IA search, bad dir check order, removed .webapp
fix runtime dir fix runtime dir remove .webapp remove error when loading settings found missing IA issue, better check order, format
1 parent cf44b57 commit df81c65

File tree

4 files changed

+32
-67
lines changed

4 files changed

+32
-67
lines changed

webapp/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ To run the Go Web UI at a specific address `-a` and port `-p` like 0.0.0.0:8000
1515
webapp \
1616
-a 0.0.0.0 \
1717
-p 8000 \
18-
-r /var/www/webapp/web/data \
19-
-srvroot /var/www/webapp/web \
18+
-r /var/lib/scion/webapp/web/data \
19+
-srvroot /var/lib/scion/webapp/web \
2020
-sabin /usr/bin \
2121
-sroot /etc/scion \
2222
-sbin /usr/bin \
@@ -68,31 +68,31 @@ webapp
6868
```
6969

7070
## Dependancies
71-
A list of dependencies for `webapp` can be found at [dependencies.md](./dependencies.md).
71+
A list of dependencies for `webapp` can be found at [dependencies.md](./dependencies.md).
7272

7373
## Help
7474
```shell
7575
Usage of webapp:
7676
-a string
77-
Address of server host. (default "127.0.0.1")
77+
Address of server host. (default "127.0.0.1")
7878
-p int
79-
Port of server host. (default 8000)
79+
Port of server host. (default 8000)
8080
-r string
81-
Root path to read/browse from, CAUTION: read-access granted from -a and -p. (default ".")
81+
Root path to read/browse from, CAUTION: read-access granted from -a and -p. (default ".")
8282
-sabin string
83-
Path to execute the installed scionlab apps binaries (default "/home/ubuntu/go/bin")
83+
Path to execute the installed scionlab apps binaries (default "/home/ubuntu/go/bin")
8484
-sbin string
85-
Path to execute SCION bin directory of infrastructure tools (default "/home/ubuntu/go/src/github.com/scionproto/scion/bin")
85+
Path to execute SCION bin directory of infrastructure tools (default "/home/ubuntu/go/src/github.com/scionproto/scion/bin")
8686
-sgen string
87-
Path to read SCION gen directory of infrastructure config (default "/home/ubuntu/go/src/github.com/scionproto/scion/gen")
87+
Path to read SCION gen directory of infrastructure config (default "/home/ubuntu/go/src/github.com/scionproto/scion/gen")
8888
-sgenc string
89-
Path to read SCION gen-cache directory of infrastructure run-time config (default "/home/ubuntu/go/src/github.com/scionproto/scion/gen-cache")
89+
Path to read SCION gen-cache directory of infrastructure run-time config (default "/home/ubuntu/go/src/github.com/scionproto/scion/gen-cache")
9090
-slogs string
91-
Path to read SCION logs directory of infrastructure logging (default "/home/ubuntu/go/src/github.com/scionproto/scion/logs")
91+
Path to read SCION logs directory of infrastructure logging (default "/home/ubuntu/go/src/github.com/scionproto/scion/logs")
9292
-sroot string
93-
Path to read SCION root directory of infrastructure (default "/home/ubuntu/go/src/github.com/scionproto/scion")
93+
Path to read SCION root directory of infrastructure (default "/home/ubuntu/go/src/github.com/scionproto/scion")
9494
-srvroot string
95-
Path to read/write web server files. (default "/home/ubuntu/go/src/github.com/netsec-ethz/scion-apps/webapp/web")
95+
Path to read/write web server files. (default "/home/ubuntu/go/src/github.com/netsec-ethz/scion-apps/webapp/web")
9696
```
9797

9898
## Related Links

webapp/dependencies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
webapp \
66
-a 0.0.0.0 \
77
-p 8000 \
8-
-r /var/www/webapp/web/data \
9-
-srvroot /var/www/webapp/web \
8+
-r /var/lib/scion/webapp/web/data \
9+
-srvroot /var/lib/scion/webapp/web \
1010
-sabin /usr/bin \
1111
-sroot /etc/scion \
1212
-sbin /usr/bin \

webapp/lib/config.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ func ReadUserSetting(options *CmdOptions) UserSetting {
6868
cliUserFp := path.Join(options.StaticRoot, cfgFileCliUser)
6969

7070
// no problem when user settings not set yet
71-
raw, err := ioutil.ReadFile(cliUserFp)
72-
log.Debug("ReadClientsUser", "settings", string(raw))
73-
if !CheckError(err) {
74-
json.Unmarshal([]byte(raw), &settings)
75-
}
71+
raw, _ := ioutil.ReadFile(cliUserFp)
72+
log.Debug("ReadUserSetting from saved", "settings", string(raw))
73+
json.Unmarshal([]byte(raw), &settings)
74+
7675
return settings
7776
}
7877

@@ -81,7 +80,7 @@ func ScanLocalIAs(options *CmdOptions) []string {
8180
var localIAs []string
8281
var reIaFilePathCap = `\/ISD([0-9]+)\/AS(\w+)`
8382
re := regexp.MustCompile(reIaFilePathCap)
84-
var searchPath = path.Join(options.ScionRoot, "gen")
83+
var searchPath = options.ScionGen
8584
filepath.Walk(searchPath, func(path string, f os.FileInfo, _ error) error {
8685
if f != nil && f.IsDir() {
8786
capture := re.FindStringSubmatch(path)

webapp/webapp.go

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"fmt"
2525
"html/template"
2626
"io"
27-
"io/ioutil"
2827
"net/http"
2928
"os"
3029
"os/exec"
@@ -73,7 +72,6 @@ var addr = flag.String("a", "127.0.0.1", "Address of server host.")
7372
var port = flag.Int("p", 8000, "Port of server host.")
7473
var cmdBufLen = 1024
7574
var browserAddr = "127.0.0.1"
76-
var rootmarker = ".webapp"
7775
var settings lib.UserSetting
7876
var id = "webapp"
7977

@@ -134,13 +132,15 @@ func main() {
134132
options = lib.CmdOptions{*staticRoot, *browseRoot, *appsRoot, *scionRoot, *scionBin, *scionGen, *scionGenCache, *scionLogs}
135133
// correct static files are required for the app to serve them, else fail
136134
if _, err := os.Stat(path.Join(options.StaticRoot, "static")); os.IsNotExist(err) {
137-
log.Error("-s flag must be set with local repo: scion-apps/webapp")
135+
log.Error("-s flag must be set with local repo: scion-apps/webapp/web")
138136
CheckFatal(err)
139137
return
140138
}
139+
checkPath(options.StaticRoot)
141140

142141
// logging
143142
logDirPath := ensurePath(options.StaticRoot, "logs")
143+
checkPath(options.ScionLogs)
144144
log.Root().SetHandler(log.MultiHandler(
145145
log.LvlFilterHandler(log.LvlDebug,
146146
log.StreamHandler(os.Stderr, fmt15.Fmt15Format(fmt15.ColorMap))),
@@ -149,15 +149,6 @@ func main() {
149149
fmt15.Fmt15Format(nil)))))
150150
log.Info("======================> Webapp started")
151151

152-
checkPath(options.StaticRoot)
153-
checkPath(options.BrowseRoot)
154-
checkPath(options.AppsRoot)
155-
checkPath(options.ScionRoot)
156-
checkPath(options.ScionBin)
157-
checkPath(options.ScionGen)
158-
checkPath(options.ScionGenCache)
159-
checkPath(options.ScionLogs)
160-
161152
// prepare templates
162153
templates = prepareTemplates(options.StaticRoot)
163154
// open and manage database
@@ -175,14 +166,18 @@ func main() {
175166
ensurePath(options.StaticRoot, "data")
176167
ensurePath(options.StaticRoot, "data/images")
177168

169+
checkPath(options.ScionRoot)
170+
checkPath(options.ScionGen)
171+
checkPath(options.ScionGenCache)
178172
initLocalIaOptions()
179173
log.Info("IA loaded:", "myIa", settings.MyIA)
180174

181175
// generate client/server default
182176
lib.GenClientNodeDefaults(&options, settings.MyIA)
183177
lib.GenServerNodeDefaults(&options, localIAs)
184178

185-
refreshRootDirectory()
179+
checkPath(options.AppsRoot)
180+
checkPath(options.ScionBin)
186181
appsBuildCheck("bwtester")
187182
appsBuildCheck("camerapp")
188183
appsBuildCheck("sensorapp")
@@ -191,6 +186,7 @@ func main() {
191186

192187
initServeHandlers()
193188
log.Info(fmt.Sprintf("Browser access: at http://%s:%d.", browserAddr, *port))
189+
checkPath(options.BrowseRoot)
194190
log.Info("File browser root:", "root", options.BrowseRoot)
195191
log.Info(fmt.Sprintf("Listening on %s:%d...", *addr, *port))
196192
err = http.ListenAndServe(fmt.Sprintf("%s:%d", *addr, *port), logRequestHandler(http.DefaultServeMux))
@@ -581,13 +577,13 @@ func getClientCwd(app string) string {
581577
var cwd string
582578
switch app {
583579
case "sensorapp":
584-
cwd = path.Join(options.StaticRoot, ".")
580+
cwd = path.Join(options.StaticRoot, "data")
585581
case "camerapp":
586582
cwd = path.Join(options.StaticRoot, "data/images")
587583
case "bwtester":
588-
cwd = path.Join(options.StaticRoot, ".")
584+
cwd = path.Join(options.StaticRoot, "data")
589585
case "echo", "traceroute":
590-
cwd = path.Join(options.ScionRoot, "bin")
586+
cwd = path.Join(options.ScionBin, ".")
591587
}
592588
return cwd
593589
}
@@ -788,33 +784,3 @@ func setUserOptionsHandler(w http.ResponseWriter, r *http.Request) {
788784
lib.GenClientNodeDefaults(&options, settings.MyIA)
789785
log.Info("IA set:", "myIa", settings.MyIA)
790786
}
791-
792-
// Used to workaround cache-control issues by ensuring root specified by user
793-
// has updated last modified date by writing a .webapp file
794-
func refreshRootDirectory() {
795-
cliFp := path.Join(options.StaticRoot, options.BrowseRoot, rootmarker)
796-
err := ioutil.WriteFile(cliFp, []byte(``), 0644)
797-
CheckError(err)
798-
}
799-
800-
// FileBrowseResponseWriter holds modified response headers
801-
type FileBrowseResponseWriter struct {
802-
http.ResponseWriter
803-
}
804-
805-
// WriteHeader prevents caching directory listings based on directory last modified date.
806-
// This is especially a problem in Chrome, and can serve the browser stale listings.
807-
func (w FileBrowseResponseWriter) WriteHeader(code int) {
808-
if code == 200 {
809-
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate, proxy-revalidate")
810-
}
811-
w.ResponseWriter.WriteHeader(code)
812-
}
813-
814-
// Handles custom filtering of file browsing content
815-
func fileBrowseHandler(h http.Handler) http.Handler {
816-
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
817-
rw := FileBrowseResponseWriter{w}
818-
h.ServeHTTP(rw, r)
819-
})
820-
}

0 commit comments

Comments
 (0)