Commit 23c74aeb authored by zdc's avatar zdc

added input validation

parent 6ef30ef0
<html>
<head>
<title>Looking Glass</title>
</head>
<body>
<p><strong>Bad input!</strong></p>
<pre></pre>
</body>
</html>
\ No newline at end of file
......@@ -4,6 +4,7 @@ import (
"fmt"
"html/template"
"log"
"net"
"net/http"
)
......@@ -17,21 +18,26 @@ func doit (w http.ResponseWriter, r *http.Request) {
Command string
Items string
}
output := data{Command: r.PostFormValue("action"), Items: "Generated output for "+r.PostFormValue("argument")}
fmt.Println("router:", r.PostFormValue("router"))
fmt.Println("action:", r.PostFormValue("action"))
fmt.Println("argument:", r.PostFormValue("argument"))
fmt.Println(output)
t, _ := template.ParseFiles("page02.gtpl")
t.Execute(w, output)
if net.ParseIP(r.PostFormValue("router")) != nil && net.ParseIP(r.PostFormValue("argument")) != nil && ( r.PostFormValue("action") == "ping" || r.PostFormValue("action") == "traceroute" || r.PostFormValue("action") == "showroute") {
fmt.Println(net.ParseIP(r.PostFormValue("router")))
fmt.Println(net.ParseIP(r.PostFormValue("argument")))
//router := r.PostFormValue("router")
action := r.PostFormValue("action")
argument := r.PostFormValue("argument")
output := data{Command: action, Items: "Generated output for "+argument}
t, _ := template.ParseFiles("page02.gtpl")
t.Execute(w, output)
} else {
t, _ := template.ParseFiles("badinput.gtpl")
t.Execute(w, nil)
}
}
func main() {
http.HandleFunc("/", page01) // setting router rule
http.HandleFunc("/do", doit) // setting router rule
//http.HandleFunc("/login", login)
http.HandleFunc("/", page01)
http.HandleFunc("/do", doit)
fmt.Println("started")
err := http.ListenAndServe(":80", nil) // setting listening port
err := http.ListenAndServe(":40080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
......
......@@ -18,7 +18,7 @@
<td style="width: 50px;">&nbsp;</td>
<td>
<select name="router">
<option value="router01">router01</option>
<option value="127.0.0.1">router01</option>
<option value="router02">router02</option>
<option value="router03">router03</option>
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment