From c0292c263c497806f4922ca5fa894f5fa2b14e08 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Mon, 18 Feb 2013 15:53:04 -0500 Subject: [PATCH] Move the static assets to the "m" subdirectory --- .../css/bootstrap-responsive.css | 0 .../css/bootstrap-responsive.min.css | 0 .../{static => m}/css/bootstrap.css | 0 .../{static => m}/css/bootstrap.min.css | 0 .../{static => m}/css/custom.css | 0 .../img/glyphicons-halflings-white.png | Bin .../img/glyphicons-halflings.png | Bin .../{static => m}/img/web_background_3.jpg | Bin .../{static => m}/js/bootstrap.js | 0 .../{static => m}/js/bootstrap.min.js | 0 .../xs_interceptor/templates/landing.html | 8 +- xonstat/util/xs_interceptor/xs_interceptor.go | 78 +++++++++--------- 12 files changed, 43 insertions(+), 43 deletions(-) rename xonstat/util/xs_interceptor/{static => m}/css/bootstrap-responsive.css (100%) rename xonstat/util/xs_interceptor/{static => m}/css/bootstrap-responsive.min.css (100%) rename xonstat/util/xs_interceptor/{static => m}/css/bootstrap.css (100%) rename xonstat/util/xs_interceptor/{static => m}/css/bootstrap.min.css (100%) rename xonstat/util/xs_interceptor/{static => m}/css/custom.css (100%) rename xonstat/util/xs_interceptor/{static => m}/img/glyphicons-halflings-white.png (100%) rename xonstat/util/xs_interceptor/{static => m}/img/glyphicons-halflings.png (100%) rename xonstat/util/xs_interceptor/{static => m}/img/web_background_3.jpg (100%) rename xonstat/util/xs_interceptor/{static => m}/js/bootstrap.js (100%) rename xonstat/util/xs_interceptor/{static => m}/js/bootstrap.min.js (100%) diff --git a/xonstat/util/xs_interceptor/static/css/bootstrap-responsive.css b/xonstat/util/xs_interceptor/m/css/bootstrap-responsive.css similarity index 100% rename from xonstat/util/xs_interceptor/static/css/bootstrap-responsive.css rename to xonstat/util/xs_interceptor/m/css/bootstrap-responsive.css diff --git a/xonstat/util/xs_interceptor/static/css/bootstrap-responsive.min.css b/xonstat/util/xs_interceptor/m/css/bootstrap-responsive.min.css similarity index 100% rename from xonstat/util/xs_interceptor/static/css/bootstrap-responsive.min.css rename to xonstat/util/xs_interceptor/m/css/bootstrap-responsive.min.css diff --git a/xonstat/util/xs_interceptor/static/css/bootstrap.css b/xonstat/util/xs_interceptor/m/css/bootstrap.css similarity index 100% rename from xonstat/util/xs_interceptor/static/css/bootstrap.css rename to xonstat/util/xs_interceptor/m/css/bootstrap.css diff --git a/xonstat/util/xs_interceptor/static/css/bootstrap.min.css b/xonstat/util/xs_interceptor/m/css/bootstrap.min.css similarity index 100% rename from xonstat/util/xs_interceptor/static/css/bootstrap.min.css rename to xonstat/util/xs_interceptor/m/css/bootstrap.min.css diff --git a/xonstat/util/xs_interceptor/static/css/custom.css b/xonstat/util/xs_interceptor/m/css/custom.css similarity index 100% rename from xonstat/util/xs_interceptor/static/css/custom.css rename to xonstat/util/xs_interceptor/m/css/custom.css diff --git a/xonstat/util/xs_interceptor/static/img/glyphicons-halflings-white.png b/xonstat/util/xs_interceptor/m/img/glyphicons-halflings-white.png similarity index 100% rename from xonstat/util/xs_interceptor/static/img/glyphicons-halflings-white.png rename to xonstat/util/xs_interceptor/m/img/glyphicons-halflings-white.png diff --git a/xonstat/util/xs_interceptor/static/img/glyphicons-halflings.png b/xonstat/util/xs_interceptor/m/img/glyphicons-halflings.png similarity index 100% rename from xonstat/util/xs_interceptor/static/img/glyphicons-halflings.png rename to xonstat/util/xs_interceptor/m/img/glyphicons-halflings.png diff --git a/xonstat/util/xs_interceptor/static/img/web_background_3.jpg b/xonstat/util/xs_interceptor/m/img/web_background_3.jpg similarity index 100% rename from xonstat/util/xs_interceptor/static/img/web_background_3.jpg rename to xonstat/util/xs_interceptor/m/img/web_background_3.jpg diff --git a/xonstat/util/xs_interceptor/static/js/bootstrap.js b/xonstat/util/xs_interceptor/m/js/bootstrap.js similarity index 100% rename from xonstat/util/xs_interceptor/static/js/bootstrap.js rename to xonstat/util/xs_interceptor/m/js/bootstrap.js diff --git a/xonstat/util/xs_interceptor/static/js/bootstrap.min.js b/xonstat/util/xs_interceptor/m/js/bootstrap.min.js similarity index 100% rename from xonstat/util/xs_interceptor/static/js/bootstrap.min.js rename to xonstat/util/xs_interceptor/m/js/bootstrap.min.js diff --git a/xonstat/util/xs_interceptor/templates/landing.html b/xonstat/util/xs_interceptor/templates/landing.html index 0c36894..25f0685 100644 --- a/xonstat/util/xs_interceptor/templates/landing.html +++ b/xonstat/util/xs_interceptor/templates/landing.html @@ -8,15 +8,15 @@ - - + + - + - + diff --git a/xonstat/util/xs_interceptor/xs_interceptor.go b/xonstat/util/xs_interceptor/xs_interceptor.go index 50f3772..88eda74 100644 --- a/xonstat/util/xs_interceptor/xs_interceptor.go +++ b/xonstat/util/xs_interceptor/xs_interceptor.go @@ -15,7 +15,7 @@ var templates = template.Must(template.ParseFiles("templates/landing.html")) func main() { port := flag.Int("port", 6543, "Default port on which to accept requests") url := flag.String("url", "http://localhost:6543/stats/submit", "URL to send POST requests against") - flag.Usage = usage + flag.Usage = usage flag.Parse() if len(flag.Args()) < 1 { @@ -44,17 +44,17 @@ func main() { // override the default Usage function to show the different "commands" // that are in the switch statement in main() func usage() { - fmt.Fprintf(os.Stderr, "Usage of xs_interceptor:\n") - fmt.Fprintf(os.Stderr, " xs_interceptor [options] \n\n") - fmt.Fprintf(os.Stderr, "Where is one of the following:\n") - fmt.Fprintf(os.Stderr, " create - create the requests db (sqlite3 db file)\n") - fmt.Fprintf(os.Stderr, " drop - remove the requests db\n") - fmt.Fprintf(os.Stderr, " list - lists the requests in the db\n") - fmt.Fprintf(os.Stderr, " serve - listens for stats requests, storing them if found\n") - fmt.Fprintf(os.Stderr, " resubmit - resubmits the requests to another URL\n\n") - fmt.Fprintf(os.Stderr, "Where [options] is one or more of the following:\n") - fmt.Fprintf(os.Stderr, " -port - port number (int) to listen on for 'serve' command\n") - fmt.Fprintf(os.Stderr, " -url - url (string) to submit requests\n\n") + fmt.Fprintf(os.Stderr, "Usage of xs_interceptor:\n") + fmt.Fprintf(os.Stderr, " xs_interceptor [options] \n\n") + fmt.Fprintf(os.Stderr, "Where is one of the following:\n") + fmt.Fprintf(os.Stderr, " create - create the requests db (sqlite3 db file)\n") + fmt.Fprintf(os.Stderr, " drop - remove the requests db\n") + fmt.Fprintf(os.Stderr, " list - lists the requests in the db\n") + fmt.Fprintf(os.Stderr, " serve - listens for stats requests, storing them if found\n") + fmt.Fprintf(os.Stderr, " resubmit - resubmits the requests to another URL\n\n") + fmt.Fprintf(os.Stderr, "Where [options] is one or more of the following:\n") + fmt.Fprintf(os.Stderr, " -port - port number (int) to listen on for 'serve' command\n") + fmt.Fprintf(os.Stderr, " -url - url (string) to submit requests\n\n") } // removes the requests database. it is just a file, so this is really easy. @@ -110,7 +110,7 @@ func serve(port int) { // routing http.HandleFunc("/", defaultHandler) http.HandleFunc("/stats/submit", makeSubmitHandler(requests)) - http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + http.Handle("/m/", http.StripPrefix("/m/", http.FileServer(http.Dir("m")))) // serving fmt.Printf("Serving on port %d...\n", port) @@ -153,10 +153,10 @@ func makeSubmitHandler(requests int) http.HandlerFunc { body := make([]byte, r.ContentLength) r.Body.Read(body) - db := getDBConn() - defer db.Close() + db := getDBConn() + defer db.Close() - _, err := db.Exec("INSERT INTO requests(blind_id_header, ip_addr, body, bodylength) VALUES(?, ?, ?, ?)", blind_id_header, remoteAddr, string(body), r.ContentLength) + _, err := db.Exec("INSERT INTO requests(blind_id_header, ip_addr, body, bodylength) VALUES(?, ?, ?, ?)", blind_id_header, remoteAddr, string(body), r.ContentLength) if err != nil { fmt.Println("Unable to insert request.") fmt.Println(err) @@ -186,7 +186,7 @@ func getRemoteAddr(r *http.Request) (remoteAddr string) { // resubmits stats request to a particular URL. this is intended to be used when // you want to write back to the "real" XonStat func resubmit(url string) { - db := getDBConn() + db := getDBConn() defer db.Close() rows, err := db.Query("SELECT request_id, ip_addr, blind_id_header, body, bodylength FROM requests ORDER BY request_id") @@ -196,7 +196,7 @@ func resubmit(url string) { } defer rows.Close() - successfulRequests := make([]int, 0, 10) + successfulRequests := make([]int, 0, 10) for rows.Next() { // could use a struct here, but isntead just a bunch of vars var request_id int @@ -220,31 +220,31 @@ func resubmit(url string) { req.Header = header res, err := http.DefaultClient.Do(req) - if err != nil { - fmt.Printf("Error submitting request #%d. Continuing...\n", request_id) - continue - } + if err != nil { + fmt.Printf("Error submitting request #%d. Continuing...\n", request_id) + continue + } defer res.Body.Close() fmt.Printf("Request #%d: %s\n", request_id, res.Status) - if res.StatusCode < 500 { - successfulRequests = append(successfulRequests, request_id) - } + if res.StatusCode < 500 { + successfulRequests = append(successfulRequests, request_id) + } } - // now that we're done resubmitting, let's clean up the successful requests - // by deleting them outright from the database - for _, val := range(successfulRequests) { - deleteRequest(db, val) - } + // now that we're done resubmitting, let's clean up the successful requests + // by deleting them outright from the database + for _, val := range successfulRequests { + deleteRequest(db, val) + } } // lists all the requests and their information *in the XonStat log format* in // order to 1) show what's in the db and 2) to be able to save/parse it (with // xs_parse) for later use. func list() { - db := getDBConn() + db := getDBConn() defer db.Close() rows, err := db.Query("SELECT request_id, ip_addr, blind_id_header, body FROM requests ORDER BY request_id") @@ -280,22 +280,22 @@ func list() { // hard-coded sqlite database connection retriever to keep it simple func getDBConn() *sql.DB { - conn, err := sql.Open("sqlite3", "./middleman.db") + conn, err := sql.Open("sqlite3", "./middleman.db") if err != nil { fmt.Println("Error opening middleman.db. Did you create it?") os.Exit(1) } - return conn + return conn } // removes reqeusts from the database by request_id func deleteRequest(db *sql.DB, request_id int) { - _, err := db.Exec("delete from requests where request_id = ?", request_id) - if err != nil { - fmt.Printf("Could not remove request_id %d from the database. Reason: %v\n", request_id, err) - } else { - fmt.Printf("Request #%d removed from the database.\n", request_id) - } + _, err := db.Exec("delete from requests where request_id = ?", request_id) + if err != nil { + fmt.Printf("Could not remove request_id %d from the database. Reason: %v\n", request_id, err) + } else { + fmt.Printf("Request #%d removed from the database.\n", request_id) + } } -- 2.39.2