func static(w http.ResponseWriter, r *http.Request) { jsn := dirReader("etc/config.json") var cfig Config err := json.Unmarshal(jsn, &cfig) if err != nil { log.Printf("error: %v\n", err) } check := strings.Contains(r.URL.Path, cfig["dir"]) if check == false { http.Redirect(w, r, "/home", http.StatusFound) return } path := r.URL.Path[1:] data := dirReader(path) cont := contype.FileType(r.URL.Path) w.Header().Set("Content-Type", cont) w.Write(data) }
// Login page func login(w http.ResponseWriter, r *http.Request) { log.Printf("%s: %s \n", r.Method, r.URL.Path) var page WebPage page.Title = "Login" cont := contype.FileType(r.URL.Path) w.Header().Set("Content-Type", cont) w.Header().Set("Server", "Syamp") switch r.Method { case "GET": reVtmp(w, page, "reVres/tmp/login-body.html") case "POST": xusr := r.FormValue("syamp_name") xpas := r.FormValue("syamp_pass") var check bool acc, err := queryUser() if err != nil { log.Fatal(err) } if xusr == string(acc[0]) && xpas == string(acc[2]) { check = true } if check == true { expiration := time.Now().Add(360 * 24 * time.Hour) snack := string(acc[3]) cookie := http.Cookie{Name: "syamp", Value: snack, Expires: expiration} http.SetCookie(w, &cookie) http.Redirect(w, r, "/home", http.StatusFound) return } else { page.Message = "syam{p} thinks the information was wrong" reVtmp(w, page, "reVres/tmp/login-body.html") } } }
// The home page of syamp func home(w http.ResponseWriter, r *http.Request) { log.Printf("%s: %s \n", r.Method, r.URL.Path) cookie, err := r.Cookie("syamp") if err != nil { http.Redirect(w, r, "/login", http.StatusFound) return } // Checks for cookie injections cook, err := rootCoo(cookie.Value) if err != nil { log.Fatal(err) } if cookie.Value != cook { http.Redirect(w, r, "/login", http.StatusFound) return } // Use the contype to get the write media type from // Url cont := contype.FileType(r.URL.Path) var page WebPage page.Title = "Home" // Add the name of root user to Webpage struct yugi, err := rootUsr(cookie.Value) if err != nil { log.Fatal(err) } page.First_Name = yugi[0] // Metal returns s reciver Channel of type []slice with value to add to // the webpage struct metalOut := ubusuma.Metal() metalVal := <-metalOut page.Distributor = metalVal[0] page.Description = metalVal[1] page.Release = metalVal[2] page.Codename = metalVal[3] switch r.Method { case "GET": query := r.FormValue("stdout") if query == "std" { // RunningUser returns s reciver Channel of type string. running := ubusuma.RunningUser() fmt.Fprintf(w, <-running) return } // RunningUser returns s reciver Channel of type string. pid := r.FormValue("term") if pid != "" { ter_msg := ubusuma.Kill(pid) fmt.Fprintf(w, <-ter_msg) return } // RunningUser returns s reciver Channel of type string. con_cmd := r.FormValue("cmd") if con_cmd != "" { console := ubusuma.Term(con_cmd) fmt.Fprintf(w, <-console) return } w.Header().Set("Content-Type", cont) slice := []string{ "home-window-material", "home-body", } Build(w, page, slice) case "POST": // This does nothing fmt.Fprintf(w, "post home") } }