kopia lustrzana https://github.com/tmsmr/xmpp-webhook
Minor refactoring
rodzic
7e236f4973
commit
2cc450badc
13
main.go
13
main.go
|
@ -28,14 +28,14 @@ type MessageBody struct {
|
||||||
Body string `xml:"body"`
|
Body string `xml:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func initXMPP(address jid.JID, pass string, skipTLSVerify bool, legacyTLS bool, forceStartTLS bool) (*xmpp.Session, error) {
|
func initXMPP(address jid.JID, pass string, skipTLSVerify bool, useXMPPS bool) (*xmpp.Session, error) {
|
||||||
tlsConfig := tls.Config{InsecureSkipVerify: skipTLSVerify}
|
tlsConfig := tls.Config{InsecureSkipVerify: skipTLSVerify}
|
||||||
var dialer dial.Dialer
|
var dialer dial.Dialer
|
||||||
// only use the tls config for the dialer if necessary
|
// only use the tls config for the dialer if necessary
|
||||||
if skipTLSVerify {
|
if skipTLSVerify {
|
||||||
dialer = dial.Dialer{NoTLS: !legacyTLS, TLSConfig: &tlsConfig}
|
dialer = dial.Dialer{NoTLS: !useXMPPS, TLSConfig: &tlsConfig}
|
||||||
} else {
|
} else {
|
||||||
dialer = dial.Dialer{NoTLS: !legacyTLS}
|
dialer = dial.Dialer{NoTLS: !useXMPPS}
|
||||||
}
|
}
|
||||||
conn, err := dialer.Dial(context.TODO(), "tcp", address)
|
conn, err := dialer.Dial(context.TODO(), "tcp", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -53,7 +53,7 @@ func initXMPP(address jid.JID, pass string, skipTLSVerify bool, legacyTLS bool,
|
||||||
false,
|
false,
|
||||||
xmpp.NewNegotiator(xmpp.StreamConfig{Features: []xmpp.StreamFeature{
|
xmpp.NewNegotiator(xmpp.StreamConfig{Features: []xmpp.StreamFeature{
|
||||||
xmpp.BindResource(),
|
xmpp.BindResource(),
|
||||||
xmpp.StartTLS(forceStartTLS, &tlsConfig),
|
xmpp.StartTLS(false, &tlsConfig),
|
||||||
xmpp.SASL("", pass, sasl.ScramSha1Plus, sasl.ScramSha1, sasl.Plain),
|
xmpp.SASL("", pass, sasl.ScramSha1Plus, sasl.ScramSha1, sasl.Plain),
|
||||||
}}),
|
}}),
|
||||||
)
|
)
|
||||||
|
@ -72,8 +72,7 @@ func main() {
|
||||||
|
|
||||||
// get tls settings from env
|
// get tls settings from env
|
||||||
_, skipTLSVerify := os.LookupEnv("XMPP_SKIP_VERIFY")
|
_, skipTLSVerify := os.LookupEnv("XMPP_SKIP_VERIFY")
|
||||||
_, legacyTLS := os.LookupEnv("XMPP_OVER_TLS")
|
_, useXMPPS := os.LookupEnv("XMPP_OVER_TLS")
|
||||||
_, forceStartTLS := os.LookupEnv("XMPP_FORCE_STARTTLS")
|
|
||||||
|
|
||||||
// check if xmpp credentials and receiver list are supplied
|
// check if xmpp credentials and receiver list are supplied
|
||||||
if xi == "" || xp == "" || xr == "" {
|
if xi == "" || xp == "" || xr == "" {
|
||||||
|
@ -84,7 +83,7 @@ func main() {
|
||||||
panicOnErr(err)
|
panicOnErr(err)
|
||||||
|
|
||||||
// connect to xmpp server
|
// connect to xmpp server
|
||||||
xmppSession, err := initXMPP(address, xp, skipTLSVerify, legacyTLS, forceStartTLS)
|
xmppSession, err := initXMPP(address, xp, skipTLSVerify, useXMPPS)
|
||||||
panicOnErr(err)
|
panicOnErr(err)
|
||||||
defer closeXMPP(xmppSession)
|
defer closeXMPP(xmppSession)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue