1// Package sftpd implements the SSH File Transfer Protocol as described in https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02.
2// It uses pkg/sftp library:
3// https://github.com/pkg/sftp
4package sftpd
5
6import (
7	"strings"
8	"time"
9)
10
11const (
12	logSender        = "sftpd"
13	handshakeTimeout = 2 * time.Minute
14)
15
16var (
17	supportedSSHCommands = []string{"scp", "md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum", "cd", "pwd",
18		"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync", "sftpgo-copy", "sftpgo-remove"}
19	defaultSSHCommands = []string{"md5sum", "sha1sum", "cd", "pwd", "scp"}
20	sshHashCommands    = []string{"md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum"}
21	systemCommands     = []string{"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync"}
22	serviceStatus      ServiceStatus
23)
24
25type sshSubsystemExitStatus struct {
26	Status uint32
27}
28
29type sshSubsystemExecMsg struct {
30	Command string
31}
32
33// HostKey defines the details for a used host key
34type HostKey struct {
35	Path        string `json:"path"`
36	Fingerprint string `json:"fingerprint"`
37}
38
39// ServiceStatus defines the service status
40type ServiceStatus struct {
41	IsActive    bool      `json:"is_active"`
42	Bindings    []Binding `json:"bindings"`
43	SSHCommands []string  `json:"ssh_commands"`
44	HostKeys    []HostKey `json:"host_keys"`
45}
46
47// GetSSHCommandsAsString returns enabled SSH commands as comma separated string
48func (s ServiceStatus) GetSSHCommandsAsString() string {
49	return strings.Join(s.SSHCommands, ", ")
50}
51
52// GetStatus returns the server status
53func GetStatus() ServiceStatus {
54	return serviceStatus
55}
56
57// GetDefaultSSHCommands returns the SSH commands enabled as default
58func GetDefaultSSHCommands() []string {
59	result := make([]string, len(defaultSSHCommands))
60	copy(result, defaultSSHCommands)
61	return result
62}
63
64// GetSupportedSSHCommands returns the supported SSH commands
65func GetSupportedSSHCommands() []string {
66	result := make([]string, len(supportedSSHCommands))
67	copy(result, supportedSSHCommands)
68	return result
69}
70