Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTP passive mode enhancement #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: ftp passive mode enhancement
Allow specifying public IP and port range for FTP passive mode.
  • Loading branch information
shprota committed Jan 3, 2023
commit 1655923936ac308eef93f3d27e35308b953a4b1a
18 changes: 12 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ Alarm Server will accept any username as FTP login username and use it as camera

```yaml
ftp:
enabled: true # if not enabled, it won't accept connections
port: 21 # has to match settings in the cameras
password: "root" # FTP password that will be accepted
allowFiles: true # if false, no files will be stored (but transfers will still happen)
rootPath: "./ftp" # folder where to save cameras' uploads
enabled: true # if not enabled, it won't accept connections
port: 21 # has to match settings in the cameras
password: "root" # FTP password that will be accepted
allowFiles: true # if false, no files will be stored (but transfers will still happen)
rootPath: "./ftp" # folder where to save cameras' uploads
publicIp: "192.168.0.2" # Optional - specify FTP server real public IP
passivePorts: "21000-21010" # Optional - specify passive mode port range

```

_Q_: Isn't FTP, like, slow??
Expand Down Expand Up @@ -111,7 +114,7 @@ If your camera works with Alarm Server - create an issue with some details about

There is a pre-built image `toxuin/alarmserver`. It is a multi-architecture image and will work both on Intel/AMD machines, and your Raspberry PI too.

Usage: `docker run -d -v $PWD/config.yml:/config.yml -v $PWD/ftp:/ftp -p 21:21 -p 15002:15002 toxuin/alarmserver`
Usage: `docker run -d -v $PWD/config.yaml:/config.yaml -v $PWD/ftp:/ftp -p 21:21 -p 15002:15002 -p 21000-21010 toxuin/alarmserver`

Explanation:

Expand All @@ -125,6 +128,9 @@ Explanation:

- `-p 15002:15002` same as above, but for port 15002 that's used by HiSilicon alarms server. Not needed if you don't need HiSilicon server.

- `-p 21000-21010` Optional. Allow pass through FTP passive mode ports specified in the config.


## Feedback

This project was created for author's personal use and while it will probably work for you too, author has no idea if you use it the same way as author. To fit everyone's usage scenario better, it would be beneficial if you could describe how YOU use the Alarm Server.
Expand Down
16 changes: 11 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ type DahuaConfig struct {
}

type FtpConfig struct {
Enabled bool `json:"enabled"`
Port int `json:"port"`
AllowFiles bool `json:"allowFiles"`
Password string `json:"password"`
RootPath string `json:"rootPath"`
Enabled bool `json:"enabled"`
Port int `json:"port"`
AllowFiles bool `json:"allowFiles"`
Password string `json:"password"`
RootPath string `json:"rootPath"`
PublicIP string `json:"publicIP"`
PassivePorts string `json:"passivePorts"` // Port range notation. Example: "21000-21010"
}

func (c *Config) SetDefaults() {
Expand Down Expand Up @@ -279,6 +281,8 @@ func (c *Config) Printout() {
" files allowed: %t\n"+
" password set: %t\n"+
" root path: %s\n"+
" public IP: %s\n"+
" passive ports: %s\n"+
" BUS: MQTT - enabled: %t\n"+
" port: %s\n"+
" topicRoot: %s\n"+
Expand All @@ -298,6 +302,8 @@ func (c *Config) Printout() {
c.Ftp.AllowFiles,
c.Ftp.Password != "",
c.Ftp.RootPath,
c.Ftp.PublicIP,
c.Ftp.PassivePorts,
c.Mqtt.Enabled,
c.Mqtt.Port,
c.Mqtt.TopicRoot,
Expand Down
5 changes: 5 additions & 0 deletions docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ ftp:
password: "root"
allowFiles: true
rootPath: "./ftp"
# THE FOLLOWING SETTINGS ARE OPTIONAL. Mainly intended for proper connectivity when running in Docker container
publicIp: "192.168.0.2"
# Export these ports in the container config "-p 21000-21010:21000-21010"
passivePorts: "21000-21010"


mqtt:
enabled: true
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func main() {
AllowFiles: config.Ftp.AllowFiles,
RootPath: config.Ftp.RootPath,
Password: config.Ftp.Password,
PublicIP: config.Ftp.PublicIP,
PassivePorts: config.Ftp.PassivePorts,
MessageHandler: messageHandler,
}
ftpServer.Start()
Expand Down
17 changes: 11 additions & 6 deletions servers/ftp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
)

type Server struct {
Debug bool
WaitGroup *sync.WaitGroup
Port int
AllowFiles bool
RootPath string
Password string
Debug bool
WaitGroup *sync.WaitGroup
Port int
AllowFiles bool
RootPath string
Password string
PublicIP string
PassivePorts string

MessageHandler func(cameraName string, eventType string, extra string)
}

Expand Down Expand Up @@ -60,6 +63,8 @@ func (serv *Server) Start() {
Port: serv.Port,
Perm: server.NewSimplePerm("root", "root"),
Auth: &DumbAuth{Debug: serv.Debug, Password: serv.Password},
PublicIP: serv.PublicIP,
PassivePorts: serv.PassivePorts,
}

if !serv.Debug {
Expand Down