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

Commit 384a6da

Browse files
authored
Merge pull request #46 from seknox/dev
2 parents 3516def + 5872724 commit 384a6da

File tree

6 files changed

+18254
-25
lines changed

6 files changed

+18254
-25
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ Distributed under the Mozilla Public License v2 License. See `LICENSE` for more
8181
<!-- CONTACT -->
8282

8383
## Contact
84+
85+
React out to Seknox team at secure at seknox dot com

cli/cmd/root.go

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/seknox/fireser/utils"
6-
"github.com/seknox/trasa/cli/config"
75
"os"
6+
"os/user"
7+
"path/filepath"
88
"runtime"
9+
"strconv"
10+
11+
"github.com/seknox/trasa/cli/config"
912

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

2629
if *logToFile {
2730

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

4548
var err error
4649

47-
utils.Context.OS_TYPE = runtime.GOOS
50+
context.OS_TYPE = runtime.GOOS
4851

49-
utils.Context.HOME_DIR, utils.Context.U_ID, utils.Context.G_ID, err = utils.GetHomeDirAndUID()
52+
context.HOME_DIR, context.U_ID, context.G_ID, err = getHomeDirAndUID()
5053
if err != nil {
5154
fmt.Println(`Could not find home dir`)
5255
}
@@ -78,3 +81,51 @@ func Execute() {
7881
os.Exit(1)
7982
}
8083
}
84+
85+
func getLogLocation() string {
86+
switch runtime.GOOS {
87+
case "darwin":
88+
return "/var/log/fireser.log"
89+
case "linux":
90+
return "/var/log/fireser.log"
91+
case "windows":
92+
return filepath.Join(context.HOME_DIR, "fireser.log")
93+
default:
94+
return "fireser.log"
95+
}
96+
}
97+
98+
var context struct {
99+
OS_TYPE string
100+
SSH_CLIENT_NAME string
101+
HOME_DIR string
102+
KEYS_DIR_PATH string
103+
SSH_USERNAME string
104+
OS_USERNAME string
105+
U_ID int
106+
G_ID int
107+
}
108+
109+
func getHomeDirAndUID() (string, int, int, error) {
110+
111+
userc, err := user.Current()
112+
// fmt.Println(err)
113+
// fmt.Println(userc.HomeDir)
114+
115+
if err != nil {
116+
return "", -1, -1, err
117+
}
118+
119+
Context.OS_USERNAME = userc.Username
120+
uid, err := strconv.Atoi(userc.Uid)
121+
if err != nil {
122+
return userc.HomeDir, -1, -1, nil
123+
}
124+
gid, err := strconv.Atoi(userc.Gid)
125+
if err != nil {
126+
return userc.HomeDir, -1, -1, nil
127+
}
128+
129+
return userc.HomeDir, uid, gid, nil
130+
131+
}

0 commit comments

Comments
 (0)