Skip to content

Commit ee1140f

Browse files
mwfarbjuagargi
authored andcommitted
Packaging for Scionlab Next Version
1 parent 645ee64 commit ee1140f

File tree

5 files changed

+63
-50
lines changed

5 files changed

+63
-50
lines changed

webapp/lib/config.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ import (
1717
. "github.com/netsec-ethz/scion-apps/webapp/util"
1818
)
1919

20-
// SCIONROOT is the root location of the scion infrastructure.
21-
var SCIONROOT = "src/github.com/scionproto/scion"
22-
23-
// LABROOT is the root location of scionlab apps.
24-
var LABROOT = "src/github.com/netsec-ethz/scion-apps"
25-
26-
// GOPATH is the root of the GOPATH environment.
27-
var GOPATH = os.Getenv("GOPATH")
28-
2920
// default params for localhost testing
3021
var serIaDef = "1-ff00:0:112"
3122
var cliPortDef = "30001"
@@ -68,11 +59,11 @@ func ReadUserSetting(srcpath string) UserSetting {
6859
}
6960

7061
// ScanLocalIAs will load list of locally available IAs
71-
func ScanLocalIAs() []string {
62+
func ScanLocalIAs(scionRoot string) []string {
7263
var localIAs []string
7364
var reIaFilePathCap = `\/ISD([0-9]+)\/AS(\w+)`
7465
re := regexp.MustCompile(reIaFilePathCap)
75-
var searchPath = path.Join(GOPATH, SCIONROOT, "gen")
66+
var searchPath = path.Join(scionRoot, "gen")
7667
filepath.Walk(searchPath, func(path string, f os.FileInfo, _ error) error {
7768
if f != nil && f.IsDir() {
7869
capture := re.FindStringSubmatch(path)

webapp/lib/image.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func findNewestFileExt(dir, extRegEx string) (imgFilename string, imgTimestamp i
7272
}
7373

7474
// FindImageInfoHandler locating most recent image and writing text info data about it.
75-
func FindImageInfoHandler(w http.ResponseWriter, r *http.Request) {
76-
filesDir := path.Join(GOPATH, LABROOT, "webapp/data/images")
75+
func FindImageInfoHandler(w http.ResponseWriter, r *http.Request, staticRoot string) {
76+
filesDir := path.Join(staticRoot, "data/images")
7777
imgFilename, _ := findNewestFileExt(filesDir, regexImageFiles)
7878
if imgFilename == "" {
7979
return
@@ -83,8 +83,8 @@ func FindImageInfoHandler(w http.ResponseWriter, r *http.Request) {
8383
}
8484

8585
// FindImageHandler locating most recent image formatting it for graphic display in response.
86-
func FindImageHandler(w http.ResponseWriter, r *http.Request, browserAddr string, port int) {
87-
filesDir := path.Join(GOPATH, LABROOT, "webapp/data/images")
86+
func FindImageHandler(w http.ResponseWriter, r *http.Request, staticRoot string, browserAddr string, port int) {
87+
filesDir := path.Join(staticRoot, "data/images")
8888
imgFilename, _ := findNewestFileExt(filesDir, regexImageFiles)
8989
if imgFilename == "" {
9090
fmt.Fprint(w, "Error: Unable to find image file locally.")

webapp/lib/sciond.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func getNetworkByIA(iaCli string) (*snet.SCIONNetwork, error) {
8282
// sciond data sources and calls
8383

8484
// PathTopoHandler handles requests for paths, returning results from sciond.
85-
func PathTopoHandler(w http.ResponseWriter, r *http.Request) {
85+
func PathTopoHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
8686
r.ParseForm()
8787
SIa := r.PostFormValue("ia_ser")
8888
CIa := r.PostFormValue("ia_cli")
@@ -116,7 +116,7 @@ func PathTopoHandler(w http.ResponseWriter, r *http.Request) {
116116

117117
// Since segments data is supplimentary to paths data, if segments data
118118
// fails, provide the error, but we must still allow paths data to return.
119-
segments, err := getSegmentsJSON(*clientCCAddr)
119+
segments, err := getSegmentsJSON(*clientCCAddr, scionRoot)
120120
if CheckError(err) {
121121
returnPathHandler(w, paths, nil, err)
122122
return
@@ -126,9 +126,9 @@ func PathTopoHandler(w http.ResponseWriter, r *http.Request) {
126126
returnPathHandler(w, paths, segments, err)
127127
}
128128

129-
func getSegmentsJSON(local snet.Addr) ([]byte, error) {
129+
func getSegmentsJSON(local snet.Addr, scionRoot string) ([]byte, error) {
130130
// load segments from paths database
131-
var dbSrcFile = findDBFilename(local.IA)
131+
var dbSrcFile = findDBFilename(local.IA, scionRoot)
132132
dbTmpFile, err := copyDBToTemp(dbSrcFile)
133133
if err != nil {
134134
return nil, err
@@ -168,15 +168,14 @@ func getSegmentsJSON(local snet.Addr) ([]byte, error) {
168168
return jsonSegsInfo, nil
169169
}
170170

171-
func findDBFilename(ia addr.IA) string {
172-
filenames, err := filepath.Glob(filepath.Join(
173-
GOPATH, SCIONROOT, "gen-cache", "ps*path.db"))
171+
func findDBFilename(ia addr.IA, scionRoot string) string {
172+
filenames, err := filepath.Glob(filepath.Join(scionRoot, "gen-cache", "ps*path.db"))
174173
CheckError(err)
175174
if len(filenames) == 1 {
176175
return filenames[0]
177176
}
178177
pathDBFileName := fmt.Sprintf("ps%s-1.path.db", ia.FileFmt(false))
179-
return filepath.Join(GOPATH, SCIONROOT, "gen-cache", pathDBFileName)
178+
return filepath.Join(scionRoot, "gen-cache", pathDBFileName)
180179
}
181180

182181
// returns the name of the created file
@@ -289,10 +288,10 @@ func AsTopoHandler(w http.ResponseWriter, r *http.Request) {
289288
}
290289

291290
// TrcHandler handles requests for all local trust root data.
292-
func TrcHandler(w http.ResponseWriter, r *http.Request) {
291+
func TrcHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
293292
r.ParseForm()
294293
CIa := r.PostFormValue("src")
295-
raw, err := loadJSONCerts(CIa, "*.trc")
294+
raw, err := loadJSONCerts(CIa, "*.trc", scionRoot)
296295
if CheckError(err) {
297296
returnError(w, err)
298297
return
@@ -302,10 +301,10 @@ func TrcHandler(w http.ResponseWriter, r *http.Request) {
302301
}
303302

304303
// CrtHandler handles requests for all local certificate data.
305-
func CrtHandler(w http.ResponseWriter, r *http.Request) {
304+
func CrtHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
306305
r.ParseForm()
307306
CIa := r.PostFormValue("src")
308-
raw, err := loadJSONCerts(CIa, "*.crt")
307+
raw, err := loadJSONCerts(CIa, "*.crt", scionRoot)
309308
if CheckError(err) {
310309
returnError(w, err)
311310
return
@@ -314,14 +313,13 @@ func CrtHandler(w http.ResponseWriter, r *http.Request) {
314313
fmt.Fprintf(w, string(raw))
315314
}
316315

317-
func loadJSONCerts(src, pattern string) ([]byte, error) {
316+
func loadJSONCerts(src, pattern string, scionRoot string) ([]byte, error) {
318317
ia, err := addr.IAFromString(src)
319318
if err != nil {
320319
return nil, err
321320
}
322-
certDir := path.Join(GOPATH, SCIONROOT,
323-
fmt.Sprintf("gen/ISD%d/AS%s/endhost/certs", ia.I, ia.A.FileFmt()))
324-
cacheDir := path.Join(GOPATH, SCIONROOT, "gen-cache")
321+
certDir := path.Join(scionRoot, fmt.Sprintf("gen/ISD%d/AS%s/endhost/certs", ia.I, ia.A.FileFmt()))
322+
cacheDir := path.Join(scionRoot, "gen-cache")
325323
files, err := filepath.Glob(fmt.Sprintf("%s/%s", certDir, pattern))
326324
if err != nil {
327325
return nil, err

webapp/tests/health/beaconstest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ iaFile=$(echo $1 | sed "s/:/_/g")
1212
echo "IA found: $iaFile"
1313

1414
# format log file and beacons grep string
15-
logfile=~/go/src/github.com/scionproto/scion/logs/bs${iaFile}-1.DEBUG
15+
logfile=$SC/logs/bs${iaFile}-1.DEBUG
1616
echo "Log: $logfile"
1717

1818
# seek last log entry for verified PCBs

webapp/webapp.go

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ import (
3030
. "github.com/netsec-ethz/scion-apps/webapp/util"
3131
)
3232

33+
// GOPATH is the root of the GOPATH environment.
34+
var GOPATH = os.Getenv("GOPATH")
35+
3336
// browseRoot is browse-only, consider security (def: cwd)
3437
var browseRoot = flag.String("r", ".",
3538
"Root path to browse from, CAUTION: read-access granted from -a and -p.")
3639

37-
// staticRoot for serving/writing static data (def: cwd)
38-
var staticRoot = flag.String("s", ".",
40+
// staticRoot for serving/writing static data
41+
var staticRoot = flag.String("s", path.Join(GOPATH, "src/github.com/netsec-ethz/scion-apps/webapp"),
3942
"Static path of web server files (local repo scion-apps/webapp).")
4043

41-
// cwdPath - this is where images are going, this is runtime (record, no settings)
42-
var cwdPath = "."
44+
// scionRoot is the root location of the scion infrastructure.
45+
var scionRoot = flag.String("i", path.Join(GOPATH, "src/github.com/scionproto/scion"),
46+
"the root location of the scion infrastructure.")
47+
48+
// appsRoot is the root location of scionlab apps.
49+
var appsRoot = flag.String("l", path.Join(GOPATH, "bin"),
50+
"the root location of scionlab apps.")
4351

4452
var addr = flag.String("a", "127.0.0.1", "Address of server host.")
4553
var port = flag.Int("p", 8000, "Port of server host.")
@@ -154,7 +162,7 @@ func main() {
154162

155163
// load list of locally available IAs and determine user choices
156164
func initLocalIaOptions() {
157-
localIAs = lib.ScanLocalIAs()
165+
localIAs = lib.ScanLocalIAs(*scionRoot)
158166
settings = lib.ReadUserSetting(*staticRoot)
159167

160168
// if read myia not in list, pick default
@@ -188,7 +196,7 @@ func initServeHandlers() {
188196

189197
http.HandleFunc("/command", commandHandler)
190198
http.HandleFunc("/imglast", findImageHandler)
191-
http.HandleFunc("/txtlast", lib.FindImageInfoHandler)
199+
http.HandleFunc("/txtlast", findImageInfoHandler)
192200
http.HandleFunc("/getnodes", getNodesHandler)
193201
http.HandleFunc("/getbwbytime", getBwByTimeHandler)
194202
http.HandleFunc("/healthcheck", healthCheckHandler)
@@ -203,10 +211,10 @@ func initServeHandlers() {
203211
http.HandleFunc("/labels", lib.LabelsHandler)
204212
http.HandleFunc("/locations", lib.LocationsHandler)
205213
http.HandleFunc("/geolocate", lib.GeolocateHandler)
206-
http.HandleFunc("/getpathtopo", lib.PathTopoHandler)
214+
http.HandleFunc("/getpathtopo", getPathInfoHandler)
207215
http.HandleFunc("/getastopo", lib.AsTopoHandler)
208-
http.HandleFunc("/getcrt", lib.CrtHandler)
209-
http.HandleFunc("/gettrc", lib.TrcHandler)
216+
http.HandleFunc("/getcrt", getCrtInfoHandler)
217+
http.HandleFunc("/gettrc", getTrcInfoHandler)
210218
}
211219

212220
func logRequestHandler(handler http.Handler) http.Handler {
@@ -536,13 +544,13 @@ func getClientCwd(app string) string {
536544
var cwd string
537545
switch app {
538546
case "sensorapp":
539-
cwd = path.Join(lib.GOPATH, lib.LABROOT, ".")
547+
cwd = path.Join(*staticRoot, ".")
540548
case "camerapp":
541-
cwd = path.Join(lib.GOPATH, lib.LABROOT, "webapp/data/images")
549+
cwd = path.Join(*staticRoot, "data/images")
542550
case "bwtester":
543-
cwd = path.Join(lib.GOPATH, lib.LABROOT, ".")
551+
cwd = path.Join(*staticRoot, ".")
544552
case "echo", "traceroute":
545-
cwd = path.Join(lib.GOPATH, lib.SCIONROOT, "bin")
553+
cwd = path.Join(*scionRoot, "bin")
546554
}
547555
return cwd
548556
}
@@ -552,13 +560,13 @@ func getClientLocationBin(app string) string {
552560
var binname string
553561
switch app {
554562
case "sensorapp":
555-
binname = path.Join(lib.GOPATH, "bin/sensorfetcher")
563+
binname = path.Join(*appsRoot, "sensorfetcher")
556564
case "camerapp":
557-
binname = path.Join(lib.GOPATH, "bin/imagefetcher")
565+
binname = path.Join(*appsRoot, "imagefetcher")
558566
case "bwtester":
559-
binname = path.Join(lib.GOPATH, "bin/bwtestclient")
567+
binname = path.Join(*appsRoot, "bwtestclient")
560568
case "echo", "traceroute":
561-
binname = path.Join(lib.GOPATH, lib.SCIONROOT, "bin/scmp")
569+
binname = path.Join(*scionRoot, "bin/scmp")
562570
}
563571
return binname
564572
}
@@ -703,7 +711,23 @@ func getTracerouteByTimeHandler(w http.ResponseWriter, r *http.Request) {
703711

704712
// Handles locating most recent image formatting it for graphic display in response.
705713
func findImageHandler(w http.ResponseWriter, r *http.Request) {
706-
lib.FindImageHandler(w, r, browserAddr, *port)
714+
lib.FindImageHandler(w, r, *staticRoot, browserAddr, *port)
715+
}
716+
717+
func findImageInfoHandler(w http.ResponseWriter, r *http.Request) {
718+
lib.FindImageInfoHandler(w, r, *staticRoot)
719+
}
720+
721+
func getTrcInfoHandler(w http.ResponseWriter, r *http.Request) {
722+
lib.TrcHandler(w, r, *scionRoot)
723+
}
724+
725+
func getCrtInfoHandler(w http.ResponseWriter, r *http.Request) {
726+
lib.CrtHandler(w, r, *scionRoot)
727+
}
728+
729+
func getPathInfoHandler(w http.ResponseWriter, r *http.Request) {
730+
lib.PathTopoHandler(w, r, *scionRoot)
707731
}
708732

709733
func getNodesHandler(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)