guichet/utils.go
2023-07-26 10:35:11 +02:00

60 lines
1.5 KiB
Go

package main
import (
"bytes"
"crypto/tls"
"log"
"net"
"math/rand"
"html/template"
"github.com/go-ldap/ldap/v3"
// "golang.org/x/text/encoding/unicode"
)
func openLdap(config *ConfigFile) (*ldap.Conn, error) {
var ldapConn *ldap.Conn
var err error
if config.LdapTLS {
tlsConf := &tls.Config{
ServerName: config.LdapServerAddr,
InsecureSkipVerify: true,
}
ldapConn, err = ldap.DialTLS("tcp", net.JoinHostPort(config.LdapServerAddr, "636"), tlsConf)
} else {
ldapConn, err = ldap.DialURL("ldap://" + config.LdapServerAddr)
}
if err != nil {
log.Printf("openLDAP %v", err)
log.Printf("openLDAP %v", config.LdapServerAddr)
}
return ldapConn, err
// l, err := ldap.DialURL(config.LdapServerAddr)
// if err != nil {
// log.Printf(fmt.Sprint("Erreur connect LDAP %v", err))
// log.Printf(fmt.Sprint("Erreur connect LDAP %v", config.LdapServerAddr))
// return nil
// } else {
// return l
// }
}
func suggestPassword() string {
password := ""
chars := "abcdfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*+_-="
for i := 0; i < 12; i++ {
password += string([]rune(chars)[rand.Intn(len(chars))])
}
return password
}
// Sends an email according to the enclosed information
func sendMail(sendMailTplData SendMailTplData) error {
templateMail := template.Must(template.ParseFiles(templatePath + "/" + sendMailTplData.RelTemplatePath))
buf := bytes.NewBuffer([]byte{})
err := templateMail.Execute(buf, sendMailTplData)
return err
}