2023-07-21 04:23:03 +00:00
|
|
|
/*
|
|
|
|
Guichet provides a user-management system around an LDAP Directory
|
|
|
|
|
|
|
|
Oriniated with deuxfleurs.fr and advanced by resdigita.com
|
|
|
|
*/
|
2020-02-09 13:46:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-02-09 14:01:20 +00:00
|
|
|
"crypto/rand"
|
2023-07-21 04:37:18 +00:00
|
|
|
// "crypto/tls"
|
2023-07-21 04:23:03 +00:00
|
|
|
|
|
|
|
// "encoding/json"
|
2020-02-09 15:46:26 +00:00
|
|
|
"flag"
|
2023-07-21 04:23:03 +00:00
|
|
|
// "fmt"
|
2020-02-09 14:44:18 +00:00
|
|
|
"html/template"
|
2023-07-21 04:23:03 +00:00
|
|
|
// "io/ioutil"
|
2020-02-09 15:46:26 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-07-21 04:23:03 +00:00
|
|
|
|
|
|
|
// "os"
|
2020-02-09 15:46:26 +00:00
|
|
|
"strings"
|
2020-02-09 13:46:52 +00:00
|
|
|
|
2020-02-09 21:06:33 +00:00
|
|
|
"github.com/gorilla/mux"
|
2020-02-09 22:04:37 +00:00
|
|
|
"github.com/gorilla/sessions"
|
2020-02-09 13:46:52 +00:00
|
|
|
)
|
|
|
|
|
2020-02-09 14:44:18 +00:00
|
|
|
const SESSION_NAME = "guichet_session"
|
|
|
|
|
2022-12-01 22:05:59 +00:00
|
|
|
var staticPath = "./static"
|
|
|
|
var templatePath = "./templates"
|
|
|
|
|
2020-02-09 15:46:26 +00:00
|
|
|
var store sessions.Store = nil
|
|
|
|
|
2022-12-01 22:05:59 +00:00
|
|
|
func getTemplate(name string) *template.Template {
|
2023-04-19 13:07:46 +00:00
|
|
|
return template.Must(template.New("layout.html").Funcs(template.FuncMap{
|
|
|
|
"contains": strings.Contains,
|
|
|
|
}).ParseFiles(
|
|
|
|
templatePath+"/layout.html",
|
|
|
|
templatePath+"/"+name,
|
|
|
|
))
|
2022-12-01 22:05:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 13:46:52 +00:00
|
|
|
func main() {
|
2020-02-09 14:01:20 +00:00
|
|
|
flag.Parse()
|
2020-02-09 13:46:52 +00:00
|
|
|
|
2020-02-09 14:44:18 +00:00
|
|
|
config_file := readConfig()
|
|
|
|
config = &config_file
|
2020-02-10 14:26:02 +00:00
|
|
|
|
|
|
|
session_key := make([]byte, 32)
|
|
|
|
n, err := rand.Read(session_key)
|
|
|
|
if err != nil || n != 32 {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
store = sessions.NewCookieStore(session_key)
|
2020-02-09 14:01:20 +00:00
|
|
|
|
2020-02-09 21:06:33 +00:00
|
|
|
r := mux.NewRouter()
|
|
|
|
r.HandleFunc("/", handleHome)
|
|
|
|
r.HandleFunc("/logout", handleLogout)
|
2021-08-16 13:30:14 +00:00
|
|
|
|
2020-02-09 21:06:33 +00:00
|
|
|
r.HandleFunc("/profile", handleProfile)
|
|
|
|
r.HandleFunc("/passwd", handlePasswd)
|
2021-08-16 13:30:14 +00:00
|
|
|
r.HandleFunc("/picture/{name}", handleDownloadPicture)
|
2021-07-29 22:04:17 +00:00
|
|
|
|
2023-07-21 04:51:56 +00:00
|
|
|
r.HandleFunc("/admin/activate", handleAdminActivateUsers)
|
2023-07-21 05:40:24 +00:00
|
|
|
r.HandleFunc("/admin/unactivate/{cn}", handleAdminUnactivateUser)
|
2023-07-21 05:24:42 +00:00
|
|
|
r.HandleFunc("/admin/activate/{cn}", handleAdminActivateUser)
|
2023-07-21 04:51:56 +00:00
|
|
|
|
2021-08-16 14:27:20 +00:00
|
|
|
r.HandleFunc("/directory/search", handleDirectorySearch)
|
2021-07-21 19:21:46 +00:00
|
|
|
r.HandleFunc("/directory", handleDirectory)
|
|
|
|
|
2023-04-19 13:07:46 +00:00
|
|
|
r.HandleFunc("/garage/key", handleGarageKey)
|
|
|
|
r.HandleFunc("/garage/website", handleGarageWebsiteList)
|
|
|
|
r.HandleFunc("/garage/website/new", handleGarageWebsiteNew)
|
|
|
|
r.HandleFunc("/garage/website/b/{bucket}", handleGarageWebsiteInspect)
|
2023-04-18 17:37:51 +00:00
|
|
|
|
2020-02-14 17:57:25 +00:00
|
|
|
r.HandleFunc("/invite/new_account", handleInviteNewAccount)
|
|
|
|
r.HandleFunc("/invite/send_code", handleInviteSendCode)
|
2020-02-14 20:58:34 +00:00
|
|
|
r.HandleFunc("/invitation/{code}", handleInvitationCode)
|
2020-02-14 17:57:25 +00:00
|
|
|
|
2020-02-09 21:06:33 +00:00
|
|
|
r.HandleFunc("/admin/users", handleAdminUsers)
|
|
|
|
r.HandleFunc("/admin/groups", handleAdminGroups)
|
2023-02-08 12:11:43 +00:00
|
|
|
r.HandleFunc("/admin/mailing", handleAdminMailing)
|
|
|
|
r.HandleFunc("/admin/mailing/{id}", handleAdminMailingList)
|
2020-02-09 21:06:33 +00:00
|
|
|
r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP)
|
2020-02-09 22:04:27 +00:00
|
|
|
r.HandleFunc("/admin/create/{template}/{super_dn}", handleAdminCreate)
|
2020-02-09 17:28:42 +00:00
|
|
|
|
2022-12-01 22:05:59 +00:00
|
|
|
staticfiles := http.FileServer(http.Dir(staticPath))
|
2020-02-09 21:06:33 +00:00
|
|
|
r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles))
|
2020-02-09 14:44:18 +00:00
|
|
|
|
2023-07-20 08:21:51 +00:00
|
|
|
// log.Printf("Starting HTTP server on %s", config.HttpBindAddr)
|
2020-02-10 14:26:02 +00:00
|
|
|
err = http.ListenAndServe(config.HttpBindAddr, logRequest(r))
|
2020-02-09 13:46:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Cannot start http server: ", err)
|
|
|
|
}
|
|
|
|
}
|