-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimapsync-web.go
53 lines (43 loc) · 1.36 KB
/
imapsync-web.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"net/http"
"os/exec"
"strings"
)
func hello(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.Error(w, "404 not found.", http.StatusNotFound)
return
}
switch r.Method {
case "GET":
http.ServeFile(w, r, "form.html")
case "POST":
// Call ParseForm() to parse the raw query and update r.PostForm and r.Form.
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
fmt.Fprintf(w, "Process should began, Please wait for 10 minutes")
name := r.FormValue("email")
oldpass := r.FormValue("oldpass")
newpass := r.FormValue("newpass")
host1 := r.FormValue("host1")
host2 := r.FormValue("host2")
cmdName := ("sudo /usr/bin/imapsync --host1 " + host1 + "--user1 " + name + " --password1 " + oldpass + " --host2 " + host2 + " --user2 " + name + " --password2 " + newpass)
cmdArgs := strings.Fields(cmdName)
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
cmd.Start()
default:
fmt.Fprintf(w, "Sorry, only GET and POST methods are supported.")
}
}
func main() {
http.HandleFunc("/", hello)
fmt.Printf("Starting server for testing HTTP POST...\n")
if err := http.ListenAndServe(":666", nil); err != nil {
log.Fatal(err)
}
}