mirror of https://github.com/statping/statping
Merge pull request #252 from tufanbarisyildirim/fix/sni-from-header-in-tls-handshake
Fix/sni from header in tls handshakepull/242/head
commit
d9cf4c769a
|
@ -241,7 +241,7 @@ func HelpEcho() {
|
||||||
func checkGithubUpdates() (githubResponse, error) {
|
func checkGithubUpdates() (githubResponse, error) {
|
||||||
var gitResp githubResponse
|
var gitResp githubResponse
|
||||||
url := "https://api.github.com/repos/hunterlong/statping/releases/latest"
|
url := "https://api.github.com/repos/hunterlong/statping/releases/latest"
|
||||||
contents, _, err := utils.HttpRequest(url, "GET", nil, nil, nil, time.Duration(10*time.Second))
|
contents, _, err := utils.HttpRequest(url, "GET", nil, nil, nil, time.Duration(10*time.Second), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return githubResponse{}, err
|
return githubResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,9 +211,9 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Method == "POST" {
|
if s.Method == "POST" {
|
||||||
content, res, err = utils.HttpRequest(s.Domain, s.Method, "application/json", headers, bytes.NewBuffer([]byte(s.PostData.String)), timeout)
|
content, res, err = utils.HttpRequest(s.Domain, s.Method, "application/json", headers, bytes.NewBuffer([]byte(s.PostData.String)), timeout, s.VerifySSL.Bool)
|
||||||
} else {
|
} else {
|
||||||
content, res, err = utils.HttpRequest(s.Domain, s.Method, nil, headers, nil, timeout)
|
content, res, err = utils.HttpRequest(s.Domain, s.Method, nil, headers, nil, timeout, s.VerifySSL.Bool)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if record {
|
if record {
|
||||||
|
|
|
@ -59,7 +59,7 @@ func init() {
|
||||||
// Send will send a HTTP Post to the discord API. It accepts type: []byte
|
// Send will send a HTTP Post to the discord API. It accepts type: []byte
|
||||||
func (u *discord) Send(msg interface{}) error {
|
func (u *discord) Send(msg interface{}) error {
|
||||||
message := msg.(string)
|
message := msg.(string)
|
||||||
_, _, err := utils.HttpRequest(discorder.GetValue("host"), "POST", "application/json", nil, strings.NewReader(message), time.Duration(10*time.Second))
|
_, _, err := utils.HttpRequest(discorder.GetValue("host"), "POST", "application/json", nil, strings.NewReader(message), time.Duration(10*time.Second), true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ func (u *discord) OnSave() error {
|
||||||
func (u *discord) OnTest() error {
|
func (u *discord) OnTest() error {
|
||||||
outError := errors.New("Incorrect discord URL, please confirm URL is correct")
|
outError := errors.New("Incorrect discord URL, please confirm URL is correct")
|
||||||
message := `{"content": "Testing the discord notifier"}`
|
message := `{"content": "Testing the discord notifier"}`
|
||||||
contents, _, err := utils.HttpRequest(discorder.Host, "POST", "application/json", nil, bytes.NewBuffer([]byte(message)), time.Duration(10*time.Second))
|
contents, _, err := utils.HttpRequest(discorder.Host, "POST", "application/json", nil, bytes.NewBuffer([]byte(message)), time.Duration(10*time.Second), true)
|
||||||
if string(contents) == "" {
|
if string(contents) == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (u *lineNotifier) Send(msg interface{}) error {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("message", message)
|
v.Set("message", message)
|
||||||
headers := []string{fmt.Sprintf("Authorization=Bearer %v", u.ApiSecret)}
|
headers := []string{fmt.Sprintf("Authorization=Bearer %v", u.ApiSecret)}
|
||||||
_, _, err := utils.HttpRequest("https://notify-api.line.me/api/notify", "POST", "application/x-www-form-urlencoded", headers, strings.NewReader(v.Encode()), time.Duration(10*time.Second))
|
_, _, err := utils.HttpRequest("https://notify-api.line.me/api/notify", "POST", "application/x-www-form-urlencoded", headers, strings.NewReader(v.Encode()), time.Duration(10*time.Second), true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ func pushRequest(msg *pushArray) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
url := "https://push.statping.com/api/push"
|
url := "https://push.statping.com/api/push"
|
||||||
body, _, err = utils.HttpRequest(url, "POST", "application/json", nil, bytes.NewBuffer(body), time.Duration(20*time.Second))
|
body, _, err = utils.HttpRequest(url, "POST", "application/json", nil, bytes.NewBuffer(body), time.Duration(20*time.Second), true)
|
||||||
return body, err
|
return body, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
slackMethod = "slack"
|
slackMethod = "slack"
|
||||||
failingTemplate = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is currently failing", "text": "Your Statping service <{{.Service.Domain}}|{{.Service.Name}}> has just received a Failure notification based on your expected results. {{.Service.Name}} responded with a HTTP Status code of {{.Service.LastStatusCode}}.", "fields": [ { "title": "Expected Status Code", "value": "{{.Service.ExpectedStatus}}", "short": true }, { "title": "Received Status Code", "value": "{{.Service.LastStatusCode}}", "short": true } ], "color": "#FF0000", "thumb_url": "https://statping.com", "footer": "Statping", "footer_icon": "https://img.cjx.io/statuplogo32.png" } ] }`
|
failingTemplate = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is currently failing", "text": "Your Statping service <{{.Service.Domain}}|{{.Service.Name}}> has just received a Failure notification based on your expected results. {{.Service.Name}} responded with a HTTP Status code of {{.Service.LastStatusCode}}.", "fields": [ { "title": "Expected Status Code", "value": "{{.Service.ExpectedStatus}}", "short": true }, { "title": "Received Status Code", "value": "{{.Service.LastStatusCode}}", "short": true } ,{ "title": "Error Message", "value": "{{.Issue}}", "short": false } ], "color": "#FF0000", "thumb_url": "https://statping.com", "footer": "Statping", "footer_icon": "https://img.cjx.io/statuplogo32.png" } ] }`
|
||||||
successTemplate = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is now back online", "text": "Your Statping service <{{.Service.Domain}}|{{.Service.Name}}> is now back online and meets your expected responses.", "color": "#00FF00", "thumb_url": "https://statping.com", "footer": "Statping", "footer_icon": "https://img.cjx.io/statuplogo32.png" } ] }`
|
successTemplate = `{ "attachments": [ { "fallback": "Service {{.Service.Name}} - is now back online", "text": "Your Statping service <{{.Service.Domain}}|{{.Service.Name}}> is now back online and meets your expected responses.", "color": "#00FF00", "thumb_url": "https://statping.com", "footer": "Statping", "footer_icon": "https://img.cjx.io/statuplogo32.png" } ] }`
|
||||||
slackText = `{"text":"{{.}}"}`
|
slackText = `{"text":"{{.}}"}`
|
||||||
)
|
)
|
||||||
|
@ -79,12 +79,13 @@ type slackMessage struct {
|
||||||
Service *types.Service
|
Service *types.Service
|
||||||
Template string
|
Template string
|
||||||
Time int64
|
Time int64
|
||||||
|
Issue string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send will send a HTTP Post to the slack webhooker API. It accepts type: string
|
// Send will send a HTTP Post to the slack webhooker API. It accepts type: string
|
||||||
func (u *slack) Send(msg interface{}) error {
|
func (u *slack) Send(msg interface{}) error {
|
||||||
message := msg.(string)
|
message := msg.(string)
|
||||||
_, _, err := utils.HttpRequest(u.Host, "POST", "application/json", nil, strings.NewReader(message), time.Duration(10*time.Second))
|
_, _, err := utils.HttpRequest(u.Host, "POST", "application/json", nil, strings.NewReader(message), time.Duration(10*time.Second), true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ func (u *slack) Select() *notifier.Notification {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *slack) OnTest() error {
|
func (u *slack) OnTest() error {
|
||||||
contents, _, err := utils.HttpRequest(u.Host, "POST", "application/json", nil, bytes.NewBuffer([]byte(`{"text":"testing message"}`)), time.Duration(10*time.Second))
|
contents, _, err := utils.HttpRequest(u.Host, "POST", "application/json", nil, bytes.NewBuffer([]byte(`{"text":"testing message"}`)), time.Duration(10*time.Second), true)
|
||||||
if string(contents) != "ok" {
|
if string(contents) != "ok" {
|
||||||
return errors.New("The slack response was incorrect, check the URL")
|
return errors.New("The slack response was incorrect, check the URL")
|
||||||
}
|
}
|
||||||
|
@ -106,6 +107,7 @@ func (u *slack) OnFailure(s *types.Service, f *types.Failure) {
|
||||||
Service: s,
|
Service: s,
|
||||||
Template: failingTemplate,
|
Template: failingTemplate,
|
||||||
Time: time.Now().Unix(),
|
Time: time.Now().Unix(),
|
||||||
|
Issue: f.Issue,
|
||||||
}
|
}
|
||||||
parseSlackMessage(s.Id, failingTemplate, message)
|
parseSlackMessage(s.Id, failingTemplate, message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (u *telegram) Send(msg interface{}) error {
|
||||||
v.Set("text", message)
|
v.Set("text", message)
|
||||||
rb := *strings.NewReader(v.Encode())
|
rb := *strings.NewReader(v.Encode())
|
||||||
|
|
||||||
contents, _, err := utils.HttpRequest(apiEndpoint, "GET", "application/x-www-form-urlencoded", nil, &rb, time.Duration(10*time.Second))
|
contents, _, err := utils.HttpRequest(apiEndpoint, "GET", "application/x-www-form-urlencoded", nil, &rb, time.Duration(10*time.Second), true)
|
||||||
|
|
||||||
success, _ := telegramSuccess(contents)
|
success, _ := telegramSuccess(contents)
|
||||||
if !success {
|
if !success {
|
||||||
|
|
|
@ -89,7 +89,7 @@ func (u *twilio) Send(msg interface{}) error {
|
||||||
v.Set("Body", message)
|
v.Set("Body", message)
|
||||||
rb := *strings.NewReader(v.Encode())
|
rb := *strings.NewReader(v.Encode())
|
||||||
|
|
||||||
contents, _, err := utils.HttpRequest(twilioUrl, "POST", "application/x-www-form-urlencoded", nil, &rb, time.Duration(10*time.Second))
|
contents, _, err := utils.HttpRequest(twilioUrl, "POST", "application/x-www-form-urlencoded", nil, &rb, time.Duration(10*time.Second), true)
|
||||||
success, _ := twilioSuccess(contents)
|
success, _ := twilioSuccess(contents)
|
||||||
if !success {
|
if !success {
|
||||||
errorOut := twilioError(contents)
|
errorOut := twilioError(contents)
|
||||||
|
|
|
@ -108,6 +108,16 @@
|
||||||
<small class="form-text text-muted">You can also drag and drop services to reorder on the Services tab.</small>
|
<small class="form-text text-muted">You can also drag and drop services to reorder on the Services tab.</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="order" class="col-sm-4 col-form-label">Verify SSL</label>
|
||||||
|
<div class="col-8 mt-1">
|
||||||
|
<span class="switch float-left">
|
||||||
|
<input type="checkbox" name="verify_ssl-option" class="switch" id="switch-verify-ssl" {{if eq .Id 0}}checked{{end}}{{if .VerifySSL.Bool}}checked{{end}}>
|
||||||
|
<label for="switch-verify-ssl">Verify SSL Certificate for this service</label>
|
||||||
|
<input type="hidden" name="verify_ssl" id="switch-verify-ssl-value" value="{{if eq .Id 0}}true{{else}}{{if .VerifySSL.Bool}}true{{else}}false{{end}}{{end}}">
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label for="order" class="col-sm-4 col-form-label">Notifications</label>
|
<label for="order" class="col-sm-4 col-form-label">Notifications</label>
|
||||||
<div class="col-8 mt-1">
|
<div class="col-8 mt-1">
|
||||||
|
|
|
@ -34,6 +34,7 @@ type Service struct {
|
||||||
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
||||||
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
||||||
AllowNotifications NullBool `gorm:"default:true;column:allow_notifications" json:"allow_notifications"`
|
AllowNotifications NullBool `gorm:"default:true;column:allow_notifications" json:"allow_notifications"`
|
||||||
|
VerifySSL NullBool `gorm:"default:false;column:verify_ssl" json:"verify_ssl"`
|
||||||
Public NullBool `gorm:"default:true;column:public" json:"public"`
|
Public NullBool `gorm:"default:true;column:public" json:"public"`
|
||||||
GroupId int `gorm:"default:0;column:group_id" json:"group_id"`
|
GroupId int `gorm:"default:0;column:group_id" json:"group_id"`
|
||||||
Headers NullString `gorm:"column:headers" json:"headers"`
|
Headers NullString `gorm:"column:headers" json:"headers"`
|
||||||
|
|
|
@ -274,21 +274,8 @@ func SaveFile(filename string, data []byte) error {
|
||||||
// // body - The body or form data to send with HTTP request
|
// // body - The body or form data to send with HTTP request
|
||||||
// // timeout - Specific duration to timeout on. time.Duration(30 * time.Seconds)
|
// // timeout - Specific duration to timeout on. time.Duration(30 * time.Seconds)
|
||||||
// // You can use a HTTP Proxy if you HTTP_PROXY environment variable
|
// // You can use a HTTP Proxy if you HTTP_PROXY environment variable
|
||||||
func HttpRequest(url, method string, content interface{}, headers []string, body io.Reader, timeout time.Duration) ([]byte, *http.Response, error) {
|
func HttpRequest(url, method string, content interface{}, headers []string, body io.Reader, timeout time.Duration, verifySSL bool) ([]byte, *http.Response, error) {
|
||||||
var err error
|
var err error
|
||||||
transport := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
InsecureSkipVerify: true,
|
|
||||||
},
|
|
||||||
DisableKeepAlives: true,
|
|
||||||
ResponseHeaderTimeout: timeout,
|
|
||||||
TLSHandshakeTimeout: timeout,
|
|
||||||
Proxy: http.ProxyFromEnvironment,
|
|
||||||
}
|
|
||||||
client := &http.Client{
|
|
||||||
Transport: transport,
|
|
||||||
Timeout: timeout,
|
|
||||||
}
|
|
||||||
var req *http.Request
|
var req *http.Request
|
||||||
if req, err = http.NewRequest(method, url, body); err != nil {
|
if req, err = http.NewRequest(method, url, body); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -310,6 +297,22 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
|
||||||
|
transport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: !verifySSL,
|
||||||
|
ServerName: req.Host,
|
||||||
|
},
|
||||||
|
DisableKeepAlives: true,
|
||||||
|
ResponseHeaderTimeout: timeout,
|
||||||
|
TLSHandshakeTimeout: timeout,
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
}
|
||||||
|
client := &http.Client{
|
||||||
|
Transport: transport,
|
||||||
|
Timeout: timeout,
|
||||||
|
}
|
||||||
|
|
||||||
if resp, err = client.Do(req); err != nil {
|
if resp, err = client.Do(req); err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue