Swift library for Synology DiskStation and use DSM APIs
Tools :
- Resolve NAS host/ip base on QuickConnectId
- List available APIs
- Login with encryption
With Cocoapods:
pod 'SynologySwift'
With Carthage:
github "Thomaslegravier/SynologySwift"
import SynologySwift
Resolve DS reachable interface for a specific QuickConnectId :
SynologySwift.resolveURL(quickConnectId: "your-quick-id") { (result) in
switch result {
case .success(let data):
let dsPort = data.port
let dsHost = data.host
case .failure(let error): break
}
}
List available APIs on your DS :
SynologySwift.resolveAvailableAPIs { (result) in
switch result {
case .success(let data):
for service in data.apiList! {
let serviceName = service.key // Example : SYNO.API.Auth
let servicePath = service.value.path // Example : auth.cgi
}
case .failure(let error): break
}
}
Auth connection with encryption :
SynologySwift.login(quickConnectid: "your-quick-id", sessionType: "DownloadStation", login: "login", password: "password", useDefaultCacheApis: false) { (result) in
switch result {
case .success(let data):
let accountName = data.account // Account name
let sessionId = data.sid // Sid param for futher connected calls
case .failure(let error): break
}
}
/* NB : Set 'useDefaultCacheApis' for faster login. If true, we use default auth and encryption APIs paths, instead fetch all available APIs on your DS. Use at your own risk. */
Get info for a specific service
let dlService = SynologySwift.serviceInfos(serviceName: "SYNO.DownloadStation.Info")
let path = dlService.path
Logout :
let dsAuthInfos = SynologySwiftAuth.DSAuthInfos(sid: "XXXXXXXXX", account: "account-name", dsInfos: SynologySwiftURLResolver.DSInfos(quickId: "your-quick-id", host: "XXXXXXX", port: 5000))
SynologySwift.logout(dsAuthInfos: dsAuthInfos, sessionType: "DownloadStation") { (result) in
switch result {
case .success(_): print("Success logout")
case .failure(let error): print(error)
}
}
/* NB : Use auth infos from your last login session to perform logout. */
Login helper:
- Resolve automatically your DS host base on the quickConnectId
- List available APIs on your DS
- Fetch encryption details
- Login with your account informations.
- Get specific service info path
- Logout from a specific session
Your login and password are encrypted and not stored.
- Thanks to @Frizlab fro RSA/AES encryption part.
- Thanks to @soyersoyer for SwCrypt implementation RSA part