Skip to content

Commit

Permalink
Update "SET SERVERPREFS" command to set blocking new users setting fo…
Browse files Browse the repository at this point in the history
…r Claris FileMaker Server 2024 (#39)
  • Loading branch information
matsuo committed Jun 23, 2024
1 parent d00c207 commit 6a02455
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
51 changes: 50 additions & 1 deletion fmcsadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ type parallelBackupConfigInfo struct {
ParallelBackupEnabled bool `json:"parallelBackupEnabled"`
}

type blockNewUsersConfigInfo struct {
BlockNewUsersEnabled bool `json:"blockNewUsers"`
}

type phpConfigInfo struct {
Enabled bool `json:"enabled"`
CharacterEncoding string `json:"characterEncoding"`
Expand Down Expand Up @@ -156,6 +160,7 @@ type params struct {
requiresecuredb string
authenticatedstream int
parallelbackupenabled string
blocknewusersenabled string
characterencoding string
errormessagelanguage string
dataprevalidation bool
Expand Down Expand Up @@ -1989,6 +1994,7 @@ func (c *cli) Run(args []string) int {
switch strings.ToLower(option) {
case "cachesize", "maxfiles", "maxguests", "allowpsos", "startuprestorationenabled", "requiresecuredb":
case "authenticatedstream", "parallelbackupenabled":
case "blocknewusersenabled":
default:
exitStatus = 10001
}
Expand Down Expand Up @@ -2077,8 +2083,9 @@ func (c *cli) Run(args []string) int {
secureFilesOnlyFlag := results[5]
authenticatedStream, _ := strconv.Atoi(results[6])
parallelBackupEnabled := results[7]
blockNewUsersEnabled := results[8]

if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || startupRestorationEnabled != "" || secureFilesOnlyFlag != "" || results[6] != "" || parallelBackupEnabled != "" {
if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || startupRestorationEnabled != "" || secureFilesOnlyFlag != "" || results[6] != "" || parallelBackupEnabled != "" || blockNewUsersEnabled != "" {
if results[0] == "" {
cacheSize = settings[0]
} else {
Expand Down Expand Up @@ -2171,6 +2178,12 @@ func (c *cli) Run(args []string) int {
} else {
exitStatus = 3
}
case "blocknewusersenabled":
if version >= 21.0 {
printOptions = append(printOptions, "blocknewusersenabled")
} else {
exitStatus = 3
}
default:
exitStatus = 3
}
Expand All @@ -2194,6 +2207,9 @@ func (c *cli) Run(args []string) int {
if version >= 19.5 {
printOptions = append(printOptions, "parallelbackupenabled")
}
if version >= 21.0 {
printOptions = append(printOptions, "blocknewusersenabled")
}
}
if exitStatus == 0 {
if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || results[4] != "" {
Expand Down Expand Up @@ -2241,6 +2257,19 @@ func (c *cli) Run(args []string) int {
}
}

if results[8] != "" {
// for Claris FileMaker Server 21.0.1 or later
if version >= 21.0 {
u.Path = path.Join(getAPIBasePath(baseURI), "server", "config", "blocknewusers")
exitStatus, _, _ = sendRequest("PATCH", u.String(), token, params{command: "set", blocknewusersenabled: blockNewUsersEnabled})
if exitStatus != 0 {
exitStatus = 10001
}
} else {
exitStatus = 3
}
}

u.Path = path.Join(getAPIBasePath(baseURI), "server", "config", "general")
settingResults, exitStatus = getServerGeneralConfigurations(u.String(), token, printOptions)
if startupRestorationBuiltin && settings[4] != settingResults[4] {
Expand Down Expand Up @@ -2582,6 +2611,7 @@ func parseServerConfigurationSettings(c *cli, str []string) ([]string, int) {
secureFilesOnlyFlag := ""
authenticatedStream := ""
parallelBackupEnabled := ""
blockNewUsersEnabled := ""

for i := 0; i < len(str); i++ {
val := strings.ToLower(str[i])
Expand Down Expand Up @@ -2641,6 +2671,14 @@ func parseServerConfigurationSettings(c *cli, str []string) ([]string, int) {
} else {
parallelBackupEnabled = "false"
}
} else if regexp.MustCompile(`blocknewusersenabled=(.*)`).Match([]byte(val)) {
if strings.ToLower(str[i]) == "blocknewusersenabled=" {
exitStatus = 10001
} else if strings.ToLower(str[i]) == "blocknewusersenabled=true" || (regexp.MustCompile(`blocknewusersenabled=([+|-])?(\d)+`).Match([]byte(str[i])) && str[i] != "blocknewusersenabled=0" && str[i] != "blocknewusersenabled=+0" && str[i] != "blocknewusersenabled=-0") {
blockNewUsersEnabled = "true"
} else {
blockNewUsersEnabled = "false"
}
} else {
exitStatus = 10001
}
Expand All @@ -2654,6 +2692,7 @@ func parseServerConfigurationSettings(c *cli, str []string) ([]string, int) {
results = append(results, secureFilesOnlyFlag)
results = append(results, authenticatedStream)
results = append(results, parallelBackupEnabled)
results = append(results, blockNewUsersEnabled)

return results, exitStatus
}
Expand Down Expand Up @@ -4454,6 +4493,16 @@ func sendRequest(method string, urlString string, token string, p params) (int,
parallelbackupenabled,
}
jsonStr, _ = json.Marshal(d)
} else if strings.HasSuffix(urlString, "/server/config/blocknewusers") {
// for Claris FileMaker Server 21.0.1 or later
blocknewusersenabled := false
if p.blocknewusersenabled == "true" {
blocknewusersenabled = true
}
d := blockNewUsersConfigInfo{
blocknewusersenabled,
}
jsonStr, _ = json.Marshal(d)
} else if strings.HasSuffix(urlString, "/server/config/general") && p.startuprestorationbuiltin {
d := generalOldConfigInfo{
p.cachesize,
Expand Down
3 changes: 3 additions & 0 deletions fmcsadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ func TestGetFlags(t *testing.T) {
* fmcsadmin get serverprefs ParallelBackupEnabled
* fmcsadmin get serverprefs PersistCacheEnabled
* fmcsadmin get serverprefs SyncPersistCache
* fmcsadmin get serverprefs BlockNewUsersEnabled
* fmcsadmin --fqdn example.jp get backuptime
* fmcsadmin --fqdn example.jp -u USERNAME get backuptime
* fmcsadmin --fqdn example.jp -u USERNAME -p PASSWORD get backuptime
Expand Down Expand Up @@ -1628,6 +1629,8 @@ func TestGetFlags(t *testing.T) {
* fmcsadmin set serverprefs AuthenticatedStream=2
* fmcsadmin set serverprefs ParallelBackupEnabled=false
* fmcsadmin set serverprefs ParallelBackupEnabled=true
* fmcsadmin set serverprefs BlockNewUsersEnabled=false
* fmcsadmin set serverprefs BlockNewUsersEnabled=true
* fmcsadmin --fqdn example.jp set serverconfig hostedfiles=125 scriptsessions=100
* fmcsadmin --fqdn example.jp -u USERNAME set serverconfig hostedfiles=125 scriptsessions=100
* fmcsadmin --fqdn example.jp -u USERNAME -p PASSWORD set serverconfig hostedfiles=125 scriptsessions=100
Expand Down
1 change: 1 addition & 0 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Version: 2.2.0 (in development)
- Add support for Ubuntu 22.04 LTS (on amd64 architecture).
- Add support for Ubuntu 22.04 LTS on arm64 architecture.
- Update "GET SERVERPREFS" command to get blocking new users setting for Claris FileMaker Server 2024 (21.0). (Usage: "fmcsadmin get serverprefs BlockNewUsersEnabled")
- Update "SET SERVERPREFS" command to set blocking new users setting for Claris FileMaker Server 2024 (21.0). (Usage: "fmcsadmin set serverprefs BlockNewUsersEnabled=true")
- Update "GET SERVERPREFS" command to get persistent cache setting for Claris FileMaker Server 2023 (20.1). (Usage: "fmcsadmin get serverprefs PersistCacheEnabled")
- Update "GET SERVERPREFS" command to get persistent cache sync setting for Claris FileMaker Server 2023 (20.1). (Usage: "fmcsadmin get serverprefs SyncPersistCache")
- Update "GET SERVERCONFIG" command and "GET SERVERPREFS" command due to increasing the maximum number of hosted database files per FileMaker Server instance.
Expand Down

0 comments on commit 6a02455

Please sign in to comment.