A Swift client for the FileMaker Server Admin API (v2), which lists connected clients and force-disconnects them. On top of it sits a policy layer, the CWP Session Janitor, that periodically finds stale or excess Custom Web Publishing sessions and disconnects them to keep FileMaker Server under its licensed concurrent-connection cap.
The Janitor has been run against a live FileMaker Server, where stuck CWP sessions would otherwise use up the server's connection cap (200 on the server it was tested against).
- Swift 6.2 or later (
swift-tools-version: 6.2, Swift 6 language mode). - macOS 12 or later, or Linux. CI covers Swift 6.2 and 6.4 on Ubuntu 24.04 and Xcode 26.0.1 and 26.6 on macOS, in debug and release, with warnings as errors.
FMAdminInsecureTLSDelegate(see below) is Darwin-only, since it depends on Security-framework primitives (SecTrust/SecIdentity) thatswift-corelibs-foundationdoesn't implement on Linux. The supported production path on Linux is still to install the server's certificate into the system CA trust store. For local dev/test against a self-signed FileMaker Server,FMAdminInsecureLinuxTransport(see below) provides a Linux equivalent — pinned to one certificate you supply, rather than trusting any certificate the way the Darwin delegate does.
None on Darwin. Package.swift's dependencies: array lists
async-http-client, swift-nio, and swift-nio-ssl, but they're wired into
the target only via condition: .when(platforms: [.linux]) — they back
FMAdminInsecureLinuxTransport and are never compiled into macOS builds.
Everything else uses Foundation / FoundationNetworking and URLSession
directly, with no third-party HTTP or JSON layer.
It is also deliberately independent of, and has zero dependency on, Perfect-FileMaker (the classic XML CWP client) or Perfect-FileMaker-DataAPI. A consumer that only needs FileMaker Server session management can pull in just this package.
.package(url: "https://github.com/PerfectlySoft/Perfect-FileMaker-AdminAPI.git", from: "1.0.0"),.product(name: "PerfectFileMakerAdminAPI", package: "Perfect-FileMaker-AdminAPI"),FMAdminClient—public struct ... Sendablewrapping the FileMaker Server Admin API v2 overURLSession.listClients()anddisconnectClient(clientID:messageText:graceTime:), bothasync throws.disconnectClientperforms a real disconnect — there is no built-in dry-run; "would I disconnect this" is a policy decision left to the layer above (see the Janitor below).FMAdminSession(internalactor) — caches the Admin API's 15-minute bearer token. Re-authenticating on every call is a known anti-pattern that can exhaust the session cap on its own, so token caching here is safety-relevant, not just an optimization.FMAdminModels—Decodable,Sendableresponse types (FMAdminClientInfo,FMAdminGuestFile).FMAdminError—Error, Sendable.FMAdminInsecureTLS— an explicit opt-inURLSessionDelegate(FMAdminInsecureTLSDelegate) for trusting self-signed certs, e.g. FileMaker Server's default dev certificate. Not markedSendableitself —URLSessionDelegateconformance has its own thread-safety contract independent of Swift'sSendablechecking. Opt-in only; never the default. Darwin-only (see Requirements above).FMAdminInsecureLinuxTransport— Linux-only, the Linux equivalent ofFMAdminInsecureTLSDelegateabove. Backed by AsyncHTTPClient/NIOSSL rather thanURLSession, since Linux has noSecTrustto build aURLSessionDelegate-based bypass on. Pins trust to one PEM certificate — passed explicitly viapinnedCertificatePath:, or read from theFMADMIN_INSECURE_CERT_PATHenvironment variable — rather than trusting any certificate; a MITM presenting a different certificate still fails. Use viaFMAdminClient.insecureLinux(host:port:username:password:pinnedCertificatePath:). Logs a warning to stderr on construction. Opt-in only; never the default.
CWPSessionSelector— pure selection logic. Being overmaxSessionsis the only disconnect trigger; adurationThresholdSecondsfilter only narrows which of the over-the-limit sessions get picked. Supports aminFloor(never disconnect below N surviving sessions) and a per-sweep disconnect cap so a large backlog drains gradually across sweeps rather than all at once.CWPSessionJanitor— runs one sweep: fetch clients → select candidates → dry-run-or-disconnect → report into a tracker. No in-loop retry on failure by design (the Admin Server has documented real-world flakiness; the caller's own poll loop retries on its next cycle).CWPSessionJanitorTracker—public actorrecording last-sweep state (lastSweepAt,considered,disconnected,dryRun,error) via async-safe accessors, and preventing two overlapping sweeps.
import PerfectFileMakerAdminAPI
let client = FMAdminClient(
host: "filemaker.example.com",
username: "admin",
password: "••••••••"
)
let tracker = CWPSessionJanitorTracker()
await CWPSessionJanitor.sweep(
client: client,
durationThresholdSeconds: 3600,
maxSessions: 150,
minFloor: 20,
maxDisconnectsPerSweep: 10,
dryRun: false,
tracker: tracker,
log: { print($0) }
)For local development against a self-signed FileMaker Server certificate on
Darwin, pass a URLSession configured with FMAdminInsecureTLSDelegate
into FMAdminClient's urlSession parameter — this should never be used
against a production server with a real certificate.
On Linux, export the dev/test server's certificate once —
openssl s_client -connect filemaker.dev.example:16000 -showcerts </dev/null \
2>/dev/null | openssl x509 -outform PEM > fm-dev-server.pem— then either pass its path explicitly or set FMADMIN_INSECURE_CERT_PATH:
let client = try FMAdminClient.insecureLinux(
host: "filemaker.dev.example",
username: "admin",
password: "••••••••",
pinnedCertificatePath: "fm-dev-server.pem"
)This pins trust to that one certificate rather than trusting any certificate — never use it against a production server either.
Apache 2.0. See LICENSE.