Skip to content
Snippets Groups Projects
Unverified Commit 21055d60 authored by CTFang@WireLab's avatar CTFang@WireLab
Browse files

feat: use config file in billing server

parent 8553d72c
No related branches found
No related tags found
No related merge requests found
...@@ -4,10 +4,12 @@ package billing ...@@ -4,10 +4,12 @@ package billing
import ( import (
"encoding/json" "encoding/json"
"os" "os"
"path"
"strconv" "strconv"
"sync" "sync"
"github.com/fclairamb/ftpserver/config" "github.com/fclairamb/ftpserver/config"
ftpconf "github.com/fclairamb/ftpserver/config/confpar"
"github.com/fclairamb/ftpserver/server" "github.com/fclairamb/ftpserver/server"
ftpserver "github.com/fclairamb/ftpserverlib" ftpserver "github.com/fclairamb/ftpserverlib"
...@@ -21,55 +23,40 @@ type BillingDomain struct { ...@@ -21,55 +23,40 @@ type BillingDomain struct {
wg *sync.WaitGroup wg *sync.WaitGroup
} }
type Access struct {
User string `json:"user"`
Pass string `json:"pass"`
Fs string `json:"fs"`
Params map[string]string `json:"params"`
}
type PortRange struct {
Start int `json:"start"`
End int `json:"end"`
}
type FtpConfig struct {
Version int `json:"version"`
Accesses []Access `json:"accesses"`
Listen_address string `json:"listen_address"`
Passive_transfer_port_range PortRange `json:"passive_transfer_port_range"`
}
// The ftp server is for CDR Push method, that is the CHF will send the CDR file to the FTP server // The ftp server is for CDR Push method, that is the CHF will send the CDR file to the FTP server
func OpenServer(wg *sync.WaitGroup) *BillingDomain { func OpenServer(wg *sync.WaitGroup) *BillingDomain {
// Arguments vars
confFile := "/tmp/webconsole/ftpserver.json"
b := &BillingDomain{ b := &BillingDomain{
wg: wg, wg: wg,
} }
if _, err := os.Stat("/tmp/webconsole"); err != nil {
if err_mk := os.Mkdir("/tmp/webconsole", os.ModePerm); err_mk != nil { billingConfig := factory.WebuiConfig.Configuration.BillingServer
basePath := billingConfig.BastPath
confFile := path.Join(basePath, "ftpserver.json")
if _, err := os.Stat(basePath); err != nil {
if err_mk := os.Mkdir(basePath, os.ModePerm); err_mk != nil {
logger.BillingLog.Error(err_mk) logger.BillingLog.Error(err_mk)
} }
} }
billingConfig := factory.WebuiConfig.Configuration.BillingServer
addr := billingConfig.HostIPv4 + ":" + strconv.Itoa(billingConfig.ListenPort) addr := billingConfig.HostIPv4 + ":" + strconv.Itoa(billingConfig.ListenPort)
params := map[string]string{ params := map[string]string{
"basePath": "/tmp/webconsole", "basePath": basePath,
} }
if billingConfig.Tls != nil { logger.BillingLog.Infof("Open BillingServer on %+v", basePath)
params["cert"] = billingConfig.Tls.Pem
params["key"] = billingConfig.Tls.Key if billingConfig.Cert != nil {
params["cert"] = billingConfig.Cert.Pem
params["key"] = billingConfig.Cert.Key
logger.BillingLog.Infof("Use tls: %+v, %+v", params["cert"], params["key"])
} }
ftpConfig := FtpConfig{ ftpConfig := ftpconf.Content{
Version: 1, Version: 1,
Accesses: []Access{ Accesses: []*ftpconf.Access{
{ {
User: "admin", User: "admin",
Pass: "free5gc", Pass: "free5gc",
...@@ -77,11 +64,11 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { ...@@ -77,11 +64,11 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {
Params: params, Params: params,
}, },
}, },
Passive_transfer_port_range: PortRange{ PassiveTransferPortRange: &ftpconf.PortRange{
Start: 2123, Start: billingConfig.PortRange.Start,
End: 2130, End: billingConfig.PortRange.End,
}, },
Listen_address: addr, ListenAddress: addr,
} }
file, err := json.MarshalIndent(ftpConfig, "", " ") file, err := json.MarshalIndent(ftpConfig, "", " ")
...@@ -100,7 +87,7 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { ...@@ -100,7 +87,7 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {
logger.BillingLog.Error("Can't load conf", "Err", errConfig) logger.BillingLog.Error("Can't load conf", "Err", errConfig)
return nil return nil
} }
logger.BillingLog.Warnf("conf %+v", conf.Content.Accesses[0].Params)
// Loading the driver // Loading the driver
var errNewServer error var errNewServer error
b.driver, errNewServer = server.NewServer(conf, logger.FtpServerLog) b.driver, errNewServer = server.NewServer(conf, logger.FtpServerLog)
...@@ -118,7 +105,7 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { ...@@ -118,7 +105,7 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {
b.ftpServer.Logger = logger.FtpServerLog b.ftpServer.Logger = logger.FtpServerLog
go b.Serve() go b.Serve()
logger.BillingLog.Info("Billing server Start") logger.BillingLog.Info("Billing server started")
return b return b
} }
......
...@@ -35,7 +35,7 @@ func (c *Config) Validate() (bool, error) { ...@@ -35,7 +35,7 @@ func (c *Config) Validate() (bool, error) {
} }
type Info struct { type Info struct {
Version string `yaml:"version,omitempty" valid:"required,in(1.0.2)"` Version string `yaml:"version,omitempty" valid:"required,in(1.0.3)"`
Description string `yaml:"description,omitempty" valid:"type(string)"` Description string `yaml:"description,omitempty" valid:"type(string)"`
} }
...@@ -58,17 +58,24 @@ type WebServer struct { ...@@ -58,17 +58,24 @@ type WebServer struct {
PORT string `yaml:"port" valid:"required"` PORT string `yaml:"port" valid:"required"`
} }
type Tls struct { type Cert struct {
Pem string `yaml:"pem,omitempty" valid:"type(string),minstringlength(1),required"` Pem string `yaml:"pem,omitempty" valid:"type(string),minstringlength(1),required"`
Key string `yaml:"key,omitempty" valid:"type(string),minstringlength(1),required"` Key string `yaml:"key,omitempty" valid:"type(string),minstringlength(1),required"`
} }
type PortRange struct {
Start int `yaml:"start,omitempty" valid:"required" json:"start"`
End int `yaml:"end,omitempty" valid:"required" json:"end"`
}
type BillingServer struct { type BillingServer struct {
Enable bool `yaml:"enable,omitempty" valid:"required,type(bool)"` Enable bool `yaml:"enable,omitempty" valid:"required,type(bool)"`
HostIPv4 string `yaml:"hostIPv4,omitempty" valid:"required,host"` HostIPv4 string `yaml:"hostIPv4,omitempty" valid:"required,host"`
Port int `yaml:"port,omitempty" valid:"optional,port"`
ListenPort int `yaml:"listenPort,omitempty" valid:"required,port"` ListenPort int `yaml:"listenPort,omitempty" valid:"required,port"`
Tls *Tls `yaml:"tls,omitempty" valid:"optional"` PortRange PortRange `yaml:"portRange,omitempty" valid:"required"`
BastPath string `yaml:"basePath,omitempty" valid:"type(string),required"`
Cert *Cert `yaml:"cert,omitempty" valid:"optional"`
Port int `yaml:"port,omitempty" valid:"optional,port"`
} }
type Mongodb struct { type Mongodb struct {
......
info: info:
version: 1.0.2 version: 1.0.3
description: WebUI initial local configuration description: WebUI initial local configuration
configuration: configuration:
...@@ -15,11 +15,16 @@ configuration: ...@@ -15,11 +15,16 @@ configuration:
enable: true enable: true
hostIPv4: 127.0.0.1 hostIPv4: 127.0.0.1
listenPort: 2121 listenPort: 2121
port: 2122 portRange: # passive port range
tls: start: 2123
end: 2130
basePath: /tmp/webconsole
port: 2122 # CGF's FTP server port (not used for now)
cert:
pem: cert/chf.pem pem: cert/chf.pem
key: cert/chf.key key: cert/chf.key
logger: # log output setting logger: # log output setting
enable: true # true or false enable: true # true or false
level: info # how detailed to output, value: trace, debug, info, warn, error, fatal, panic level: info # how detailed to output, value: trace, debug, info, warn, error, fatal, panic
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment