From 6a02455e353c0150729d7912a66093aec84804f4 Mon Sep 17 00:00:00 2001 From: Atsushi Matsuo Date: Sun, 23 Jun 2024 11:26:50 +0900 Subject: [PATCH] Update "SET SERVERPREFS" command to set blocking new users setting for Claris FileMaker Server 2024 (#39) --- fmcsadmin.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++- fmcsadmin_test.go | 3 +++ release-notes.txt | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/fmcsadmin.go b/fmcsadmin.go index 2ef064b..1a5595c 100644 --- a/fmcsadmin.go +++ b/fmcsadmin.go @@ -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"` @@ -156,6 +160,7 @@ type params struct { requiresecuredb string authenticatedstream int parallelbackupenabled string + blocknewusersenabled string characterencoding string errormessagelanguage string dataprevalidation bool @@ -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 } @@ -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 { @@ -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 } @@ -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] != "" { @@ -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] { @@ -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]) @@ -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 } @@ -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 } @@ -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, diff --git a/fmcsadmin_test.go b/fmcsadmin_test.go index c6bc446..490b31f 100644 --- a/fmcsadmin_test.go +++ b/fmcsadmin_test.go @@ -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 @@ -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 diff --git a/release-notes.txt b/release-notes.txt index b781e5e..41c6399 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -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.