2023-09-02 20:03:44 +01:00
// Linsk - A utility to access Linux-native file systems on non-Linux operating systems.
// Copyright (c) 2023 The Linsk Authors.
//
// This program 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.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
2023-08-31 16:19:03 +01:00
package share
import (
"fmt"
"net"
"log/slog"
)
type UserConfiguration struct {
listenIP net . IP
ftpExtIP net . IP
smbExtMode bool
}
type RawUserConfiguration struct {
ListenIP string
// Backend-specific
FTPExtIP string
SMBExtMode bool
}
func ( rc RawUserConfiguration ) Process ( backend string , warnLogger * slog . Logger ) ( * UserConfiguration , error ) {
listenIP := net . ParseIP ( rc . ListenIP )
if listenIP == nil {
return nil , fmt . Errorf ( "invalid listen ip '%v'" , rc . ListenIP )
}
ftpExtIP := net . ParseIP ( rc . FTPExtIP )
if ftpExtIP == nil {
return nil , fmt . Errorf ( "invalid ftp ext ip '%v'" , rc . FTPExtIP )
}
if backend == "ftp" {
if ! listenIP . Equal ( defaultListenIP ) && ftpExtIP . Equal ( defaultListenIP ) {
2023-10-13 09:07:37 +02:00
warnLogger . Warn ( "No external FTP IP address via --ftp-extip was configured. This is a requirement in almost all scenarios if you want to connect remotely." )
2023-08-31 16:19:03 +01:00
}
} else {
if ! ftpExtIP . Equal ( defaultListenIP ) {
2023-10-13 09:07:37 +02:00
warnLogger . Warn ( "FTP external IP address specification is ineffective with non-FTP backends" , "selected" , backend )
2023-08-31 16:19:03 +01:00
}
}
2023-08-31 20:17:55 +01:00
if rc . SMBExtMode && backend != "smb" && ! IsSMBExtModeDefault ( ) {
2023-10-13 09:07:37 +02:00
warnLogger . Warn ( "SMB external mode specification is ineffective with non-SMB backends" )
2023-08-31 20:17:55 +01:00
}
2023-08-31 16:19:03 +01:00
return & UserConfiguration {
listenIP : listenIP ,
ftpExtIP : ftpExtIP ,
smbExtMode : rc . SMBExtMode ,
} , nil
}