OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 Serves a webpage for easy management of Skia bugs. | 6 Serves a webpage for easy management of Skia bugs. |
7 | 7 |
8 WARNING: This server is NOT secure and should not be made publicly | 8 WARNING: This server is NOT secure and should not be made publicly |
9 accessible. | 9 accessible. |
10 */ | 10 */ |
11 | 11 |
12 package main | 12 package main |
13 | 13 |
14 import ( | 14 import ( |
15 "encoding/json" | 15 "encoding/json" |
16 "flag" | 16 "flag" |
17 "fmt" | 17 "fmt" |
18 "html/template" | 18 "html/template" |
19 "issue_tracker" | 19 "issue_tracker" |
20 "log" | 20 "log" |
21 "net/http" | 21 "net/http" |
22 "net/url" | 22 "net/url" |
23 » "path" | 23 » "os" |
24 "path/filepath" | 24 "path/filepath" |
25 "runtime" | |
25 "strconv" | 26 "strconv" |
26 "strings" | 27 "strings" |
27 "time" | 28 "time" |
28 ) | 29 ) |
29 | 30 |
30 import "github.com/gorilla/securecookie" | 31 import "github.com/gorilla/securecookie" |
31 | 32 |
32 const ( | 33 const ( |
33 certFile = "certs/cert.pem" | 34 certFile = "certs/cert.pem" |
34 keyFile = "certs/key.pem" | 35 keyFile = "certs/key.pem" |
35 issueComment = "Edited by BugChomper" | 36 issueComment = "Edited by BugChomper" |
36 oauthCallbackPath = "/oauth2callback" | 37 oauthCallbackPath = "/oauth2callback" |
37 oauthConfigFile = "oauth_client_secret.json" | 38 oauthConfigFile = "oauth_client_secret.json" |
38 localHost = "127.0.0.1" | 39 localHost = "127.0.0.1" |
39 maxSessionLen = time.Duration(3600 * time.Second) | 40 maxSessionLen = time.Duration(3600 * time.Second) |
40 priorityPrefix = "Priority-" | 41 priorityPrefix = "Priority-" |
41 project = "skia" | 42 project = "skia" |
42 cookieName = "BugChomperCookie" | 43 cookieName = "BugChomperCookie" |
43 ) | 44 ) |
44 | 45 |
45 // Flags: | 46 // Flags: |
46 var ( | 47 var ( |
47 port = flag.String("port", ":8000", "HTTP service address (e.g., ':800 0')") | 48 port = flag.String("port", ":8000", "HTTP service address (e.g., ':800 0')") |
48 public = flag.Bool("public", false, "Make this server publicly accessibl e.") | 49 public = flag.Bool("public", false, "Make this server publicly accessibl e.") |
49 ) | 50 ) |
50 | 51 |
51 var ( | 52 var ( |
52 » scheme = "http" | 53 » // templates is the list of html templates used by bug_chomper. |
54 » templates *template.Template = nil | |
53 | 55 |
54 » curdir, _ = filepath.Abs(".") | 56 » scheme = "http" |
55 » templatePath, _ = filepath.Abs("templates") | |
56 » templates = template.Must(template.ParseFiles( | |
57 » » path.Join(templatePath, "bug_chomper.html"), | |
58 » » path.Join(templatePath, "submitted.html"), | |
59 » » path.Join(templatePath, "error.html"))) | |
60 | |
61 hashKey = securecookie.GenerateRandomKey(32) | 57 hashKey = securecookie.GenerateRandomKey(32) |
62 blockKey = securecookie.GenerateRandomKey(32) | 58 blockKey = securecookie.GenerateRandomKey(32) |
63 secureCookie = securecookie.New(hashKey, blockKey) | 59 secureCookie = securecookie.New(hashKey, blockKey) |
64 ) | 60 ) |
65 | 61 |
62 func init() { | |
63 // Change the current working directory to two directories up from this | |
64 // source file so that we can read templates. | |
65 _, filename, _, _ := runtime.Caller(0) | |
66 cwd := filepath.Join(filepath.Dir(filename), "../..") | |
67 if err := os.Chdir(cwd); err != nil { | |
68 log.Fatal(err) | |
69 } | |
70 | |
71 templates = template.Must(template.ParseFiles( | |
72 filepath.Join(cwd, "templates/bug_chomper.html"), | |
tfarina
2014/10/15 22:18:14
cwd results in the abs path where running ./run_se
| |
73 filepath.Join(cwd, "templates/submitted.html"), | |
74 filepath.Join(cwd, "templates/error.html"), | |
75 )) | |
76 } | |
77 | |
66 // SessionState contains data for a given session. | 78 // SessionState contains data for a given session. |
67 type SessionState struct { | 79 type SessionState struct { |
68 IssueTracker *issue_tracker.IssueTracker | 80 IssueTracker *issue_tracker.IssueTracker |
69 OrigRequestURL string | 81 OrigRequestURL string |
70 SessionStart time.Time | 82 SessionStart time.Time |
71 } | 83 } |
72 | 84 |
73 // getAbsoluteURL returns the absolute URL of the given Request. | 85 // getAbsoluteURL returns the absolute URL of the given Request. |
74 func getAbsoluteURL(r *http.Request) string { | 86 func getAbsoluteURL(r *http.Request) string { |
75 return scheme + "://" + r.Host + r.URL.Path | 87 return scheme + "://" + r.Host + r.URL.Path |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 } | 368 } |
357 http.NotFound(w, r) | 369 http.NotFound(w, r) |
358 } | 370 } |
359 | 371 |
360 // Run the BugChomper server. | 372 // Run the BugChomper server. |
361 func main() { | 373 func main() { |
362 flag.Parse() | 374 flag.Parse() |
363 | 375 |
364 http.HandleFunc("/", handleRoot) | 376 http.HandleFunc("/", handleRoot) |
365 http.HandleFunc(oauthCallbackPath, handleOAuth2Callback) | 377 http.HandleFunc(oauthCallbackPath, handleOAuth2Callback) |
366 » http.Handle("/res/", http.FileServer(http.Dir(curdir))) | 378 » http.Handle("/res/", http.FileServer(http.Dir("./"))) |
367 log.Println("Server is running at " + scheme + "://" + localHost + *port ) | 379 log.Println("Server is running at " + scheme + "://" + localHost + *port ) |
368 var err error | 380 var err error |
369 if *public { | 381 if *public { |
370 log.Println("WARNING: This server is not secure and should not b e made " + | 382 log.Println("WARNING: This server is not secure and should not b e made " + |
371 "publicly accessible.") | 383 "publicly accessible.") |
372 scheme = "https" | 384 scheme = "https" |
373 err = http.ListenAndServeTLS(*port, certFile, keyFile, nil) | 385 err = http.ListenAndServeTLS(*port, certFile, keyFile, nil) |
374 } else { | 386 } else { |
375 scheme = "http" | 387 scheme = "http" |
376 err = http.ListenAndServe(localHost+*port, nil) | 388 err = http.ListenAndServe(localHost+*port, nil) |
377 } | 389 } |
378 if err != nil { | 390 if err != nil { |
379 log.Println(err.Error()) | 391 log.Println(err.Error()) |
380 } | 392 } |
381 } | 393 } |
OLD | NEW |