From dbec9ae664a902018681c11ba0cd16025369789a Mon Sep 17 00:00:00 2001 From: Atsushi Matsuo Date: Sun, 10 Nov 2024 16:45:55 +0900 Subject: [PATCH] Update "SET SERVERPREFS" command to open only the databases that were opened when the database server was last shut down (#45) --- README.md | 2 +- fmcsadmin.go | 130 +++++++++++++++++++++++++++++++--------------- fmcsadmin_test.go | 3 ++ release-notes.txt | 3 +- 4 files changed, 95 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 3ef66c7..631c2b0 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Features - FileMaker Admin API PKI Authentication - View and change the settings for the persistent cache (for FileMaker Server 2024) - View and change the setting for blocking new users (for FileMaker Server 2024) -- View the setting for opening the databases that were opened when the database server was last shut down (for FileMaker Server 2024 (21.1)) +- View and change the "Only open last opened databases" setting (for FileMaker Server 2024 (21.1)) Supported Servers ----- diff --git a/fmcsadmin.go b/fmcsadmin.go index 65336c8..e97f9d8 100644 --- a/fmcsadmin.go +++ b/fmcsadmin.go @@ -79,6 +79,14 @@ type generalConfigInfo struct { MaxPSOS int `json:"maxPSOS"` } +type general211ConfigInfo struct { + CacheSize int `json:"cacheSize"` + MaxFiles int `json:"maxFiles"` + MaxProConnections int `json:"maxProConnections"` + MaxPSOS int `json:"maxPSOS"` + OnlyOpenLastOpenedDatabases bool `json:"onlyOpenLastOpenedDatabases"` +} + type securityConfigInfo struct { RequireSecureDB bool `json:"requireSecureDB"` } @@ -150,38 +158,39 @@ type importingCertificateInfo struct { } type params struct { - command string - key string - messageText string - force bool - retry int - status string - enabled string - cachesize int - maxfiles int - maxproconnections int - maxpsos int - startuprestorationenabled bool - startuprestorationbuiltin bool - requiresecuredb string - authenticatedstream int - parallelbackupenabled string - persistcacheenabled string - syncpersistcache string - databaseserverautorestart string - blocknewusersenabled string - characterencoding string - errormessagelanguage string - dataprevalidation bool - usefilemakerphp bool - saveKey bool - subject string - password string - certificate string - privateKey string - intermediateCertificates string - printRefreshToken bool - identityFile string + command string + key string + messageText string + force bool + retry int + status string + enabled string + cachesize int + maxfiles int + maxproconnections int + maxpsos int + startuprestorationenabled bool + startuprestorationbuiltin bool + requiresecuredb string + authenticatedstream int + parallelbackupenabled string + persistcacheenabled string + syncpersistcache string + databaseserverautorestart string + blocknewusersenabled string + onlyopenlastopeneddatabases string + characterencoding string + errormessagelanguage string + dataprevalidation bool + usefilemakerphp bool + saveKey bool + subject string + password string + certificate string + privateKey string + intermediateCertificates string + printRefreshToken bool + identityFile string } type commandOptions struct { @@ -2026,6 +2035,7 @@ func (c *cli) Run(args []string) int { case "authenticatedstream", "parallelbackupenabled": case "persistcacheenabled", "syncpersistcache", "databaseserverautorestart": case "blocknewusersenabled": + case "onlyopenlastopeneddatabases": default: exitStatus = 10001 } @@ -2119,8 +2129,9 @@ func (c *cli) Run(args []string) int { syncPersistCache := results[9] databaseServerAutoRestart := results[10] blockNewUsersEnabled := results[11] + onlyOpenLastOpenedDatabases := results[12] - if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || startupRestorationEnabled != "" || secureFilesOnlyFlag != "" || results[6] != "" || parallelBackupEnabled != "" || persistCacheEnabled != "" || syncPersistCache != "" || databaseServerAutoRestart != "" || blockNewUsersEnabled != "" { + if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || startupRestorationEnabled != "" || secureFilesOnlyFlag != "" || results[6] != "" || parallelBackupEnabled != "" || persistCacheEnabled != "" || syncPersistCache != "" || databaseServerAutoRestart != "" || blockNewUsersEnabled != "" || results[12] != "" { if results[0] == "" { cacheSize = settings[0] } else { @@ -2237,6 +2248,12 @@ func (c *cli) Run(args []string) int { } else { exitStatus = 3 } + case "onlyopenlastopeneddatabases": + if version >= 21.1 { + printOptions = append(printOptions, "onlyopenlastopeneddatabases") + } else { + exitStatus = 3 + } default: exitStatus = 3 } @@ -2266,18 +2283,22 @@ func (c *cli) Run(args []string) int { printOptions = append(printOptions, "databaseserverautorestart") printOptions = append(printOptions, "blocknewusersenabled") } + if version >= 21.1 { + printOptions = append(printOptions, "onlyopenlastopeneddatabases") + } } if exitStatus == 0 { - if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || results[4] != "" { + if results[0] != "" || results[1] != "" || results[2] != "" || results[3] != "" || results[4] != "" || results[12] != "" { u.Path = path.Join(getAPIBasePath(), "server", "config", "general") exitStatus, _, _ = sendRequest("PATCH", u.String(), token, params{ - command: "set", - cachesize: cacheSize, - maxfiles: maxFiles, - maxproconnections: maxProConnections, - maxpsos: maxPSOS, - startuprestorationenabled: startupRestoration, - startuprestorationbuiltin: startupRestorationBuiltin, + command: "set", + cachesize: cacheSize, + maxfiles: maxFiles, + maxproconnections: maxProConnections, + maxpsos: maxPSOS, + startuprestorationenabled: startupRestoration, + startuprestorationbuiltin: startupRestorationBuiltin, + onlyopenlastopeneddatabases: onlyOpenLastOpenedDatabases, }) } @@ -2725,6 +2746,7 @@ func parseServerConfigurationSettings(str []string) ([]string, int) { syncPersistCache := "" databaseServerAutoRestart := "" blockNewUsersEnabled := "" + onlyOpenLastOpenedDatabases := "" for i := 0; i < len(str); i++ { val := strings.ToLower(str[i]) @@ -2816,6 +2838,14 @@ func parseServerConfigurationSettings(str []string) ([]string, int) { } else { blockNewUsersEnabled = "false" } + } else if regexp.MustCompile(`onlyopenlastopeneddatabases=(.*)`).Match([]byte(val)) { + if strings.ToLower(str[i]) == "onlyopenlastopeneddatabases=" { + exitStatus = 10001 + } else if strings.ToLower(str[i]) == "onlyopenlastopeneddatabases=true" || (regexp.MustCompile(`onlyopenlastopeneddatabases=([+|-])?(\d)+`).Match([]byte(str[i])) && str[i] != "onlyopenlastopeneddatabases=0" && str[i] != "onlyopenlastopeneddatabases=+0" && str[i] != "onlyopenlastopeneddatabases=-0") { + onlyOpenLastOpenedDatabases = "true" + } else { + onlyOpenLastOpenedDatabases = "false" + } } else { exitStatus = 10001 } @@ -2833,6 +2863,7 @@ func parseServerConfigurationSettings(str []string) ([]string, int) { results = append(results, syncPersistCache) results = append(results, databaseServerAutoRestart) results = append(results, blockNewUsersEnabled) + results = append(results, onlyOpenLastOpenedDatabases) return results, exitStatus } @@ -4183,6 +4214,8 @@ func getServerSettingAsBool(urlString string, token string, printOptions []strin fmt.Println("ParallelBackupEnabled = " + enabledStr + " [default: false] ") case "blocknewusersenabled": fmt.Println("BlockNewUsersEnabled = " + enabledStr + " [default: false] ") + case "onlyopenlastopeneddatabases": + fmt.Println("OnlyOpenLastOpenedDatabases = " + enabledStr + " [default: false] ") default: } } @@ -4743,7 +4776,22 @@ func sendRequest(method string, urlString string, token string, p params) (int, blocknewusersenabled, } jsonStr, _ = json.Marshal(d) + } else if strings.HasSuffix(urlString, "/server/config/general") && p.onlyopenlastopeneddatabases != "" { + // for Claris FileMaker Server 21.1.1 or later + onlyopenlastopeneddatabases := false + if p.onlyopenlastopeneddatabases == "true" { + onlyopenlastopeneddatabases = true + } + d := general211ConfigInfo{ + p.cachesize, + p.maxfiles, + p.maxproconnections, + p.maxpsos, + onlyopenlastopeneddatabases, + } + jsonStr, _ = json.Marshal(d) } else if strings.HasSuffix(urlString, "/server/config/general") && p.startuprestorationbuiltin { + // for Claris FileMaker Server 19.1.1 or previous d := generalOldConfigInfo{ p.cachesize, p.maxfiles, diff --git a/fmcsadmin_test.go b/fmcsadmin_test.go index c0c6398..70ec4fb 100644 --- a/fmcsadmin_test.go +++ b/fmcsadmin_test.go @@ -1164,6 +1164,7 @@ func TestGetFlags(t *testing.T) { * fmcsadmin get serverprefs SyncPersistCache * fmcsadmin get serverprefs DatabaseServerAutoRestart * fmcsadmin get serverprefs BlockNewUsersEnabled + * fmcsadmin get serverprefs OnlyOpenLastOpenedDatabases * fmcsadmin --fqdn example.jp get backuptime * fmcsadmin --fqdn example.jp -u USERNAME get backuptime * fmcsadmin --fqdn example.jp -u USERNAME -p PASSWORD get backuptime @@ -1638,6 +1639,8 @@ func TestGetFlags(t *testing.T) { * fmcsadmin set serverprefs DatabaseServerAutoRestart=true * fmcsadmin set serverprefs BlockNewUsersEnabled=false * fmcsadmin set serverprefs BlockNewUsersEnabled=true + * fmcsadmin set serverprefs OnlyOpenLastOpenedDatabases=false + * fmcsadmin set serverprefs OnlyOpenLastOpenedDatabases=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 6e19918..53de8b7 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -5,7 +5,8 @@ This software is distributed under the Apache License, Version 2.0, see LICENSE. Version: 2.3.0-dev (in development) - Add support for Claris FileMaker Server 2024 (21.1). - Add support for macOS Sequoia 15. -- Update "GET SERVERPREFS" command to open the databases that were opened when the database server was last shut down for Claris FileMaker Server 2024 (21.1). (Usage: "fmcsadmin get serverprefs OnlyOpenLastOpenedDatabases") +- Update "GET SERVERPREFS" command to view the "Only open last opened databases" setting for Claris FileMaker Server 2024 (21.1). (Usage: "fmcsadmin get serverprefs OnlyOpenLastOpenedDatabases") +- Update "SET SERVERPREFS" command to open only the databases that were opened when the database server was last shut down for Claris FileMaker Server 2024 (21.1). (Usage: "fmcsadmin set serverprefs OnlyOpenLastOpenedDatabases=true") - Built with Go 1.23. - [INFO] Drop support for Claris FileMaker Server 19.6. - [INFO] Drop support for macOS Monterey 12.