Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #46 from seknox/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghermit authored Sep 17, 2020
2 parents 3516def + 5872724 commit 384a6da
Show file tree
Hide file tree
Showing 6 changed files with 18,254 additions and 25 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ Distributed under the Mozilla Public License v2 License. See `LICENSE` for more
<!-- CONTACT -->

## Contact

React out to Seknox team at secure at seknox dot com
61 changes: 56 additions & 5 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package cmd

import (
"fmt"
"github.com/seknox/fireser/utils"
"github.com/seknox/trasa/cli/config"
"os"
"os/user"
"path/filepath"
"runtime"
"strconv"

"github.com/seknox/trasa/cli/config"

logger "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -25,7 +28,7 @@ func init() {

if *logToFile {

f, err := os.OpenFile(utils.GetLogLocation(), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
f, err := os.OpenFile(getLogLocation(), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
logger.Fatal(err)
}
Expand All @@ -44,9 +47,9 @@ func init() {

var err error

utils.Context.OS_TYPE = runtime.GOOS
context.OS_TYPE = runtime.GOOS

utils.Context.HOME_DIR, utils.Context.U_ID, utils.Context.G_ID, err = utils.GetHomeDirAndUID()
context.HOME_DIR, context.U_ID, context.G_ID, err = getHomeDirAndUID()
if err != nil {
fmt.Println(`Could not find home dir`)
}
Expand Down Expand Up @@ -78,3 +81,51 @@ func Execute() {
os.Exit(1)
}
}

func getLogLocation() string {
switch runtime.GOOS {
case "darwin":
return "/var/log/fireser.log"
case "linux":
return "/var/log/fireser.log"
case "windows":
return filepath.Join(context.HOME_DIR, "fireser.log")
default:
return "fireser.log"
}
}

var context struct {
OS_TYPE string
SSH_CLIENT_NAME string
HOME_DIR string
KEYS_DIR_PATH string
SSH_USERNAME string
OS_USERNAME string
U_ID int
G_ID int
}

func getHomeDirAndUID() (string, int, int, error) {

userc, err := user.Current()
// fmt.Println(err)
// fmt.Println(userc.HomeDir)

if err != nil {
return "", -1, -1, err
}

Context.OS_USERNAME = userc.Username
uid, err := strconv.Atoi(userc.Uid)
if err != nil {
return userc.HomeDir, -1, -1, nil
}
gid, err := strconv.Atoi(userc.Gid)
if err != nil {
return userc.HomeDir, -1, -1, nil
}

return userc.HomeDir, uid, gid, nil

}
Loading

0 comments on commit 384a6da

Please sign in to comment.