synoapi

package
v0.0.0-...-d459dd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2022 License: MIT, GPL-3.0 Imports: 6 Imported by: 0

README

syno-cli

Provides a command-line interface for a Synology DiskStation allowing to list shares and lock/unlock encrypted volumes.

It allows to unlock several volumes at once by providing JSON with a list of shares and their corresponding passwords. If you have a lot of shares and install the frequent security updates (which you should), this might make your life easier.

Example

$ export SYNO_BASE_URL='https://myds.example.net:5001'
$ export SYNO_USER='api'
$ export SYNO_PASSWORD='password'
$ syno-cli list
[ debug messages... ]
backup          Encrypted, locked
homes           Not encrypted        user home
public          Not encrypted
sync            Encrypted, locked
$ cat shares.json
[
    {"name": "backup", "password": "secret"},
    {"name": "sync", "password": "secret2"}
]
$ cat shares.json | syno-cli unlock --batch
[ debug messages ...]

Installation

You'll need Go. Once you have Go and set a GOPATH, you can install syno-cli:

go get frister.net/go/syno-cli

Usage

syno-cli reads configuration from the following environment variables.

  • SYNO_BASE_URL - your DiskStation's URL with protocol and port, e.g. https://myds.example.net:5001
  • SYNO_USER - the user to log in as
  • SYNO_PASSWORD - the user's password
usage: syno-cli <command> [<flags>] [<args> ...]

Flags:
  --help  Show help.

Commands:
  help [<command>]
    Show help for a command.

  list
    List shares

  lock <share name>
    Lock an encrypted volume

  unlock [<flags>] [<share name>]
    Unlock an encrypted volume
JSON format for batch unlock

It's just an array of objects with a name and a password attribute:

[
    {"name": "backup", "password": "secret"},
    {"name": "sync", "password": "secret2"}
]

Limitations

  • syno-cli logs the user in, but not out, so the session id is still valid after it quits.
  • The API sometimes returns error 119. No idea why, a retry helps.
  • There's still a lot of debug output, including all HTTP requests including credentials.

Synology API documentation

I couldn't find any documentation for the part of the API this tool uses, but there's documentation for another part of the DiskStation API (FileStation).

Fortunately, the web interface uses the same API, so opening the network tab of a browser's developer tools and doing the actions in the UI gives you the requests.

Contributions

Feel free to create a pull request, being able to do more with this CLI would be nice :)

License

syno-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

syno-cli is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with syno-cli. If not, see <http://www.gnu.org/licenses/>.

Documentation

Index

Constants

View Source
const (
	NOT_ENCRYPTED      = 0
	ENCRYPTED_LOCKED   = 1
	ENCRYPTED_UNLOCKED = 2
)

Variables

View Source
var SYNO_ERR_CODES = map[int]string{
	402: "This shared folder doesn't exist.",
	400: "The password is invalid.",

	3308: "The password is invalid.",
}

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(base_url string) *Client

func (*Client) ListShares

func (c *Client) ListShares() ([]Share, error)

func (*Client) LockShare

func (c *Client) LockShare(name string) error

func (*Client) Login

func (c *Client) Login(user string, password string) error

func (*Client) UnlockShare

func (c *Client) UnlockShare(name string, password string) error

type ClientError

type ClientError interface {
	error
	UnderlyingError() error
}

func NewClientError

func NewClientError(context string, err error) ClientError

type EncryptionStatus

type EncryptionStatus int8

func (EncryptionStatus) String

func (e EncryptionStatus) String() string

type ListSharesResponse

type ListSharesResponse struct {
	Data struct {
		Shares []Share
	}
	// contains filtered or unexported fields
}

func (*ListSharesResponse) ErrorCode

func (s *ListSharesResponse) ErrorCode() int

func (*ListSharesResponse) Successful

func (s *ListSharesResponse) Successful() bool

type LoginResponse

type LoginResponse struct {
	Data struct {
		Sid string
	}
	// contains filtered or unexported fields
}

func (*LoginResponse) ErrorCode

func (s *LoginResponse) ErrorCode() int

func (*LoginResponse) Successful

func (s *LoginResponse) Successful() bool

type Share

type Share struct {
	Description string `json:"desc"`
	Encryption  EncryptionStatus
	Name        string
	// contains filtered or unexported fields
}

type SynoBaseResponse

type SynoBaseResponse interface {
	ErrorCode() int
	Successful() bool
}

type SynoError

type SynoError interface {
	ClientError
	Code() int
	Description() string
}

func NewSynoError

func NewSynoError(code int) SynoError

type SynoResponse

type SynoResponse struct {
	Data map[string]interface{}
	// contains filtered or unexported fields
}

func (*SynoResponse) ErrorCode

func (s *SynoResponse) ErrorCode() int

func (*SynoResponse) Successful

func (s *SynoResponse) Successful() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL