Format + documentation
This commit is contained in:
parent
a84ac778ad
commit
158eda06de
6 changed files with 31 additions and 27 deletions
|
@ -30,6 +30,15 @@ Guichet requires go 1.13 or later.
|
||||||
To build Guichet, clone this repository outside of your `$GOPATH`.
|
To build Guichet, clone this repository outside of your `$GOPATH`.
|
||||||
Then, run `make` in the root of the repo.
|
Then, run `make` in the root of the repo.
|
||||||
|
|
||||||
|
## Releasing Guichet
|
||||||
|
|
||||||
|
To build Guichet in a controlled environment, because you plan to release it for example, please use Nix.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix-build -A bin # build only the Go binary
|
||||||
|
nix-build -A pkg # build the binary and add the ressources
|
||||||
|
nix-build -A docker # build a docker container
|
||||||
|
```
|
||||||
|
|
||||||
## Configuration of Guichet
|
## Configuration of Guichet
|
||||||
|
|
||||||
|
|
22
default.nix
22
default.nix
|
@ -11,7 +11,8 @@ let
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
bin = pkgs.gomod.buildGoApplication {
|
in rec {
|
||||||
|
bin = pkgs.gomod.buildGoApplication {
|
||||||
pname = "guichet-bin";
|
pname = "guichet-bin";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
@ -26,23 +27,18 @@ let
|
||||||
platforms = platforms.linux;
|
platforms = platforms.linux;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
pkg = pkgs.stdenv.mkDerivation {
|
||||||
pkgs.stdenv.mkDerivation {
|
|
||||||
pname = "guichet";
|
pname = "guichet";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/
|
mkdir -p $out/
|
||||||
|
cp ${bin}/bin/guichet $out/guichet
|
||||||
cat > guichet <<EOF
|
|
||||||
#!${pkgs.bash}/bin/bash
|
|
||||||
cd $out
|
|
||||||
${bin}/bin/guichet \$@
|
|
||||||
EOF
|
|
||||||
chmod +x guichet
|
|
||||||
|
|
||||||
cp guichet $out/guichet
|
|
||||||
cp -r templates static $out/
|
cp -r templates static $out/
|
||||||
'';
|
'';
|
||||||
}
|
};
|
||||||
|
/*docker = pkgs.xxx {
|
||||||
|
|
||||||
|
};*/
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ type SearchResults struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleDirectorySearch(w http.ResponseWriter, r *http.Request) {
|
func handleDirectorySearch(w http.ResponseWriter, r *http.Request) {
|
||||||
templateDirectoryResults := template.Must(template.ParseFiles(config.Resources[0]+"/templates/directory_results.html"))
|
templateDirectoryResults := template.Must(template.ParseFiles(config.Resources[0] + "/templates/directory_results.html"))
|
||||||
|
|
||||||
//Get input value by user
|
//Get input value by user
|
||||||
r.ParseMultipartForm(1024)
|
r.ParseMultipartForm(1024)
|
||||||
|
|
|
@ -298,7 +298,7 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
templateMail := template.Must(template.ParseFiles(config.Resources[0]+"/templates/invite_mail.txt"))
|
templateMail := template.Must(template.ParseFiles(config.Resources[0] + "/templates/invite_mail.txt"))
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
templateMail.Execute(buf, &CodeMailFields{
|
templateMail.Execute(buf, &CodeMailFields{
|
||||||
To: sendto,
|
To: sendto,
|
||||||
|
|
19
main.go
19
main.go
|
@ -21,9 +21,9 @@ import (
|
||||||
|
|
||||||
type ConfigFile struct {
|
type ConfigFile struct {
|
||||||
Resources []string `json:"resources"`
|
Resources []string `json:"resources"`
|
||||||
HttpBindAddr string `json:"http_bind_addr"`
|
HttpBindAddr string `json:"http_bind_addr"`
|
||||||
LdapServerAddr string `json:"ldap_server_addr"`
|
LdapServerAddr string `json:"ldap_server_addr"`
|
||||||
LdapTLS bool `json:"ldap_tls"`
|
LdapTLS bool `json:"ldap_tls"`
|
||||||
|
|
||||||
BaseDN string `json:"base_dn"`
|
BaseDN string `json:"base_dn"`
|
||||||
UserBaseDN string `json:"user_base_dn"`
|
UserBaseDN string `json:"user_base_dn"`
|
||||||
|
@ -64,7 +64,7 @@ var store sessions.Store = nil
|
||||||
func readConfig() ConfigFile {
|
func readConfig() ConfigFile {
|
||||||
// Default configuration values for certain fields
|
// Default configuration values for certain fields
|
||||||
config_file := ConfigFile{
|
config_file := ConfigFile{
|
||||||
Resources: []string{},
|
Resources: []string{},
|
||||||
HttpBindAddr: ":9991",
|
HttpBindAddr: ":9991",
|
||||||
LdapServerAddr: "ldap://127.0.0.1:389",
|
LdapServerAddr: "ldap://127.0.0.1:389",
|
||||||
|
|
||||||
|
@ -97,17 +97,16 @@ func readConfig() ConfigFile {
|
||||||
// Enrich the Resource entry with default values
|
// Enrich the Resource entry with default values
|
||||||
config_file.Resources = append(config_file.Resources, ".")
|
config_file.Resources = append(config_file.Resources, ".")
|
||||||
ex, err := os.Executable()
|
ex, err := os.Executable()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
exPath := filepath.Dir(ex)
|
exPath := filepath.Dir(ex)
|
||||||
config_file.Resources = append(config_file.Resources, exPath)
|
config_file.Resources = append(config_file.Resources, exPath)
|
||||||
}
|
}
|
||||||
fmt.Println(config_file.Resources)
|
|
||||||
|
|
||||||
return config_file
|
return config_file
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectResource(conf *ConfigFile) {
|
func selectResource(conf *ConfigFile) {
|
||||||
ResourceLoop:
|
ResourceLoop:
|
||||||
for _, p := range conf.Resources {
|
for _, p := range conf.Resources {
|
||||||
for _, suffix := range []string{"", "/templates", "/static"} {
|
for _, suffix := range []string{"", "/templates", "/static"} {
|
||||||
_, err := os.Stat(p + suffix)
|
_, err := os.Stat(p + suffix)
|
||||||
|
@ -157,7 +156,7 @@ func main() {
|
||||||
r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP)
|
r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP)
|
||||||
r.HandleFunc("/admin/create/{template}/{super_dn}", handleAdminCreate)
|
r.HandleFunc("/admin/create/{template}/{super_dn}", handleAdminCreate)
|
||||||
|
|
||||||
staticfiles := http.FileServer(http.Dir(config.Resources[0]+"/static"))
|
staticfiles := http.FileServer(http.Dir(config.Resources[0] + "/static"))
|
||||||
r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles))
|
r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles))
|
||||||
|
|
||||||
log.Printf("Starting HTTP server on %s", config.HttpBindAddr)
|
log.Printf("Starting HTTP server on %s", config.HttpBindAddr)
|
||||||
|
|
|
@ -122,7 +122,7 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
||||||
data.NoMatchError = true
|
data.NoMatchError = true
|
||||||
} else {
|
} else {
|
||||||
modify_request := ldap.NewModifyRequest(login.Info.DN, nil)
|
modify_request := ldap.NewModifyRequest(login.Info.DN, nil)
|
||||||
pw, err := SSHAEncode(password);
|
pw, err := SSHAEncode(password)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
modify_request.Replace("userpassword", []string{pw})
|
modify_request.Replace("userpassword", []string{pw})
|
||||||
err := login.conn.Modify(modify_request)
|
err := login.conn.Modify(modify_request)
|
||||||
|
|
Loading…
Reference in a new issue