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

Commit

Permalink
Merge pull request #7 from parkervcp/feature/use-config
Browse files Browse the repository at this point in the history
Feature/use config
  • Loading branch information
DaneEveritt authored Mar 17, 2019
2 parents 15ee5a7 + eb9fba3 commit a463aaf
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 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,27 @@ func main() {
return
}

// default to config port if the sftp was not passed.
if !isFlagPassed("port") {
// get port form config
confPort, err := jsonparser.GetInt(config, "sftp", "port")
if err != nil {
// default to the bindPort default from the flag section
logger.Get().Debugw("could not find sftp port, falling back to \"2022\"", zap.Error(err))
} else {
// set bindPort to the confPort value
logger.Get().Infow("using config daemon port", zap.String("port", zap.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 +116,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
}

0 comments on commit a463aaf

Please sign in to comment.