Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Feature/use config #7

Merged
merged 4 commits into from
Mar 17, 2019
Merged
Changes from 2 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
33 changes: 27 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"errors"
"flag"
"fmt"
"github.com/buger/jsonparser"
"github.com/patrickmn/go-cache"
"github.com/pterodactyl/sftp-server/src/logger"
"github.com/pterodactyl/sftp-server/src/server"
"go.uber.org/zap"
"io/ioutil"
"os"
"os/user"
"path"
"runtime"
"strconv"
"time"

"github.com/buger/jsonparser"
"github.com/patrickmn/go-cache"
"github.com/pterodactyl/sftp-server/src/logger"
"github.com/pterodactyl/sftp-server/src/server"
"go.uber.org/zap"
)

func main() {
Expand Down Expand Up @@ -64,13 +65,23 @@ func main() {
return
}

// default to config port if the sftp was not passed.
if !isFlagPassed("port") {
confPort, err := jsonparser.GetInt(config, "sftp", "port")
if err != nil {
logger.Get().Debugw("could not find sftp port, falling back to \"2022\"", zap.Error(err))
}
logger.Get().Infow("using config daemon port", zap.String("port", strconv.Itoa(int(confPort))))
bindPort = int(confPort)
}

uid, _ := strconv.Atoi(u.Uid)
gid, _ := strconv.Atoi(u.Gid)

var s = server.Configuration{
Data: config,
Cache: cache.New(5*time.Minute, 10*time.Minute),
User: server.SftpUser{
User: server.SftpUser{
Uid: uid,
Gid: gid,
},
Expand Down Expand Up @@ -101,3 +112,13 @@ func readConfiguration(path string) ([]byte, error) {

return data, nil
}

func isFlagPassed(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}