-
Notifications
You must be signed in to change notification settings - Fork 0
/
1128backup.go
133 lines (107 loc) · 3.11 KB
/
1128backup.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"html/template"
"net/http"
"strings"
"fmt"
"log"
"io/ioutil"
"encoding/json"
"net"
"time"
"errors"
"bytes"
"io"
"github.com/qiniu/api/rs"
. "github.com/qiniu/api/conf"
)
const (
BUCKET = "avivaxrq"
DOMAIN = "7u2o6v.com2.z0.glb.qiniucdn.com"
AKEY = "3GjLFqbAzSuZ8cwwP05fBj-RQHaFymC8FWStn0vd"
SKEY = "Htj0FvLqylb9QKA5KUxwdDf0wM3vNsEbncbva2EF"
)
func init() {
ACCESS_KEY = AKEY
SECRET_KEY = SKEY
}
type UploadRet struct {
Key string `json:"key"`
}
var getInfoTmpl = template.Must(template.New("getinfo").ParseFiles("getinfo.html"))
func getInfo(w http.ResponseWriter, r *http.Request) {
userInfo :=make(map[string]string)
policy := rs.PutPolicy{
Scope: BUCKET,
EndUser: "userId",
SaveKey: "$(sha1)",
}
token := policy.Token(nil)
fmt.Println(token)
fmt.Printf("%T", token)
userInfo["token"] = token
s := strings.Split(r.RemoteAddr, ":")
s[0] = "58.20.0.17"
userInfo["ip"] = s[0]
resp,_ := http.Get("http://ip.taobao.com/service/getIpInfo.php?ip="+s[0])
defer resp.Body.Close()
by,_ := ioutil.ReadAll(resp.Body)
var ret map[string]interface{}
json.Unmarshal(by,&ret)
var data = ret["data"];
dataMap, ok := data.(map[string]interface{})
if(ok){
var country = dataMap["country"]
countryInfo, ok :=country.(string)
if(ok){
userInfo["country"] = countryInfo
}
var region = dataMap["region"]
regionInfo, ok :=region.(string)
if(ok){
userInfo["region"] = regionInfo
}
var city = dataMap["city"]
cityInfo, ok :=city.(string)
if(ok){
userInfo["city"] = cityInfo
}
var isp = dataMap["isp"]
ispInfo, ok :=isp.(string)
if(ok){
userInfo["isp"] = ispInfo
}
}
for _, v := range r.Header["User-Agent"]{
userInfo["useragent"] = v
}
if r.Method !="GET" {
r.ParseForm()
email := r.Form["email"][0]
phone := r.Form["phone"][0]
description := r.Form["description"][0]
userInfo["email"] = email
userInfo["phone"] = phone
userInfo["description"] = description
// postsupportvalue := new {
// "Title": {"PiliWebTest"},
// "Type": {"Pili"},
// "Content": {userInfo["ip"] + userInfo["country"] + userInfo["region"] + userInfo["isp"] + userInfo["useragent"] + userInfo["phone"] + userInfo["description"]},
// "Email": {userInfo["email"]},
// "Source": {"Pili"},
// "Service":{"none"},
// "Attachment": {["none"]},
// "TitlePrefix": {"Pili"}
// }
// resp, err := http.PostForm("https://portal.qiniu.com/support/new",postsupportvalue)
}
getInfoTmpl.ExecuteTemplate(w, "getinfo", userInfo)
}
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", getInfo) //设置访问的路由
err := http.ListenAndServe(":9090", nil) //设置监听的端口
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}