admin: Remove hardcoded strings
This commit is contained in:
parent
239e8ae88d
commit
df08e1ec72
@ -8,7 +8,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/admin/pki"
|
"srs.epita.fr/fic-server/admin/pki"
|
||||||
"srs.epita.fr/fic-server/libfic"
|
"srs.epita.fr/fic-server/libfic"
|
||||||
@ -135,7 +137,7 @@ web:
|
|||||||
http: 0.0.0.0:5556
|
http: 0.0.0.0:5556
|
||||||
frontend:
|
frontend:
|
||||||
issuer: Challenge forensic
|
issuer: Challenge forensic
|
||||||
logoURL: files/logo/ec2.png
|
logoURL: {{ .LogoPath }}
|
||||||
dir: /srv/dex/web/
|
dir: /srv/dex/web/
|
||||||
oauth2:
|
oauth2:
|
||||||
skipApprovalScreen: true
|
skipApprovalScreen: true
|
||||||
@ -158,7 +160,7 @@ const dexpasswdtpl = `{{ "{{" }} template "header.html" . {{ "}}" }}
|
|||||||
|
|
||||||
<div class="theme-panel">
|
<div class="theme-panel">
|
||||||
<h2 class="theme-heading">
|
<h2 class="theme-heading">
|
||||||
Bienvenue au challenge Forensic !
|
Bienvenue au {{ .Name }} !
|
||||||
</h2>
|
</h2>
|
||||||
<form method="post" action="{{ "{{" }} .PostURL {{ "}}" }}">
|
<form method="post" action="{{ "{{" }} .PostURL {{ "}}" }}">
|
||||||
<div class="theme-form-row">
|
<div class="theme-form-row">
|
||||||
@ -203,24 +205,48 @@ type dexConfigClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type dexConfig struct {
|
type dexConfig struct {
|
||||||
|
Name string
|
||||||
Issuer string
|
Issuer string
|
||||||
Clients []dexConfigClient
|
Clients []dexConfigClient
|
||||||
Teams []*fic.Team
|
Teams []*fic.Team
|
||||||
|
LogoPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func genDexConfig() ([]byte, error) {
|
func genDexConfig() ([]byte, error) {
|
||||||
if teams, err := fic.GetTeams(); err != nil {
|
if OidcSecret == "" {
|
||||||
return nil, err
|
|
||||||
} else if OidcSecret == "" {
|
|
||||||
return nil, fmt.Errorf("Unable to generate dex configuration: OIDC Secret not defined. Please define FICOIDC_SECRET in your environment.")
|
return nil, fmt.Errorf("Unable to generate dex configuration: OIDC Secret not defined. Please define FICOIDC_SECRET in your environment.")
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
teams, err := fic.GetTeams()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
b := bytes.NewBufferString("")
|
b := bytes.NewBufferString("")
|
||||||
|
|
||||||
if challengeInfo, err := GetChallengeInfo(); err != nil {
|
challengeInfo, err := GetChallengeInfo()
|
||||||
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Cannot create template: %w", err)
|
return nil, fmt.Errorf("Cannot create template: %w", err)
|
||||||
} else if dexTmpl, err := template.New("dexcfg").Parse(dexcfgtpl); err != nil {
|
}
|
||||||
|
|
||||||
|
// Lower the first letter to be included in a sentence.
|
||||||
|
name := []rune(challengeInfo.Title)
|
||||||
|
if len(name) > 0 {
|
||||||
|
name[0] = unicode.ToLower(name[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
logoPath := ""
|
||||||
|
if len(challengeInfo.MainLogo) > 0 {
|
||||||
|
logoPath = strings.Replace(challengeInfo.MainLogo[len(challengeInfo.MainLogo)-1], "$FILES$", fic.FilesDir, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
dexTmpl, err := template.New("dexcfg").Parse(dexcfgtpl)
|
||||||
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Cannot create template: %w", err)
|
return nil, fmt.Errorf("Cannot create template: %w", err)
|
||||||
} else if err = dexTmpl.Execute(b, dexConfig{
|
}
|
||||||
|
|
||||||
|
err = dexTmpl.Execute(b, dexConfig{
|
||||||
|
Name: string(name),
|
||||||
Issuer: "https://" + OidcIssuer,
|
Issuer: "https://" + OidcIssuer,
|
||||||
Clients: []dexConfigClient{
|
Clients: []dexConfigClient{
|
||||||
dexConfigClient{
|
dexConfigClient{
|
||||||
@ -231,9 +257,12 @@ func genDexConfig() ([]byte, error) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Teams: teams,
|
Teams: teams,
|
||||||
}); err != nil {
|
LogoPath: logoPath,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
return nil, fmt.Errorf("An error occurs during template execution: %w", err)
|
return nil, fmt.Errorf("An error occurs during template execution: %w", err)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Also generate team associations
|
// Also generate team associations
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
if _, err := os.Stat(path.Join(TeamsDir, fmt.Sprintf("team%02d", team.Id))); err == nil {
|
if _, err := os.Stat(path.Join(TeamsDir, fmt.Sprintf("team%02d", team.Id))); err == nil {
|
||||||
@ -250,8 +279,6 @@ func genDexConfig() ([]byte, error) {
|
|||||||
|
|
||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func genDexPasswordTpl() ([]byte, error) {
|
func genDexPasswordTpl() ([]byte, error) {
|
||||||
if teams, err := fic.GetTeams(); err != nil {
|
if teams, err := fic.GetTeams(); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user