2020-02-09 17:03:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-ldap/ldap/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ProfileTplData struct {
|
|
|
|
Status *LoginStatus
|
|
|
|
ErrorMessage string
|
|
|
|
Success bool
|
|
|
|
Mail string
|
|
|
|
DisplayName string
|
|
|
|
GivenName string
|
|
|
|
Surname string
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleProfile(w http.ResponseWriter, r *http.Request) {
|
|
|
|
templateProfile := template.Must(template.ParseFiles("templates/layout.html", "templates/profile.html"))
|
|
|
|
|
|
|
|
login := checkLogin(w, r)
|
|
|
|
if login == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data := &ProfileTplData{
|
|
|
|
Status: login,
|
|
|
|
ErrorMessage: "",
|
|
|
|
Success: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Method == "POST" {
|
|
|
|
r.ParseForm()
|
|
|
|
|
2020-02-10 14:26:02 +00:00
|
|
|
data.Mail = strings.TrimSpace(strings.Join(r.Form["mail"], ""))
|
|
|
|
data.DisplayName = strings.TrimSpace(strings.Join(r.Form["display_name"], ""))
|
|
|
|
data.GivenName = strings.TrimSpace(strings.Join(r.Form["given_name"], ""))
|
|
|
|
data.Surname = strings.TrimSpace(strings.Join(r.Form["surname"], ""))
|
2020-02-09 17:03:10 +00:00
|
|
|
|
|
|
|
modify_request := ldap.NewModifyRequest(login.Info.DN, nil)
|
|
|
|
modify_request.Replace("mail", []string{data.Mail})
|
|
|
|
modify_request.Replace("displayname", []string{data.DisplayName})
|
|
|
|
modify_request.Replace("givenname", []string{data.GivenName})
|
|
|
|
modify_request.Replace("sn", []string{data.Surname})
|
|
|
|
|
|
|
|
err := login.conn.Modify(modify_request)
|
|
|
|
if err != nil {
|
|
|
|
data.ErrorMessage = err.Error()
|
|
|
|
} else {
|
|
|
|
data.Success = true
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data.Mail = login.UserEntry.GetAttributeValue("mail")
|
|
|
|
data.DisplayName = login.UserEntry.GetAttributeValue("displayname")
|
|
|
|
data.GivenName = login.UserEntry.GetAttributeValue("givenname")
|
|
|
|
data.Surname = login.UserEntry.GetAttributeValue("sn")
|
|
|
|
}
|
|
|
|
|
|
|
|
templateProfile.Execute(w, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
type PasswdTplData struct {
|
2020-02-09 18:56:01 +00:00
|
|
|
Status *LoginStatus
|
|
|
|
ErrorMessage string
|
|
|
|
TooShortError bool
|
|
|
|
NoMatchError bool
|
|
|
|
Success bool
|
2020-02-09 17:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
|
|
|
templatePasswd := template.Must(template.ParseFiles("templates/layout.html", "templates/passwd.html"))
|
|
|
|
|
|
|
|
login := checkLogin(w, r)
|
|
|
|
if login == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data := &PasswdTplData{
|
|
|
|
Status: login,
|
|
|
|
ErrorMessage: "",
|
|
|
|
Success: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Method == "POST" {
|
|
|
|
r.ParseForm()
|
|
|
|
|
|
|
|
password := strings.Join(r.Form["password"], "")
|
|
|
|
password2 := strings.Join(r.Form["password2"], "")
|
|
|
|
|
2020-02-09 18:56:01 +00:00
|
|
|
if len(password) < 8 {
|
|
|
|
data.TooShortError = true
|
|
|
|
} else if password2 != password {
|
2020-02-09 17:03:10 +00:00
|
|
|
data.NoMatchError = true
|
|
|
|
} else {
|
|
|
|
modify_request := ldap.NewModifyRequest(login.Info.DN, nil)
|
|
|
|
modify_request.Replace("userpassword", []string{SSHAEncode([]byte(password))})
|
|
|
|
err := login.conn.Modify(modify_request)
|
|
|
|
if err != nil {
|
|
|
|
data.ErrorMessage = err.Error()
|
|
|
|
} else {
|
|
|
|
data.Success = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
templatePasswd.Execute(w, data)
|
|
|
|
}
|