Skip to content

Commit

Permalink
Update "SET SERVERPREFS" command to open only the databases that were…
Browse files Browse the repository at this point in the history
… opened when the database server was last shut down (#45)
  • Loading branch information
matsuo committed Nov 10, 2024
1 parent b8ce1af commit dbec9ae
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
130 changes: 89 additions & 41 deletions fmcsadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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:
}
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions fmcsadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dbec9ae

Please sign in to comment.