Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 0 additions & 7 deletions config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Configuration interface {
LoadConfig()
SaveConfig() error
Config() *models.Config
IsWindows() bool
ConfigDir() string
}

Expand All @@ -23,7 +22,6 @@ type configuration struct {
cfgFile string
cfgFilePath string
config *models.Config
isWindows bool
}

func (cfg *configuration) Config() *models.Config {
Expand All @@ -50,10 +48,6 @@ func (cfg *configuration) isConfigExists() {
}
}

func (cfg *configuration) IsWindows() bool {
return cfg.IsWindows()
}

func (cfg *configuration) ConfigDir() string {
return cfg.cfgDir
}
Expand Down Expand Up @@ -99,7 +93,6 @@ func InitConfig() Configuration {
Credientials: make(map[string]models.Crediential),
Tunnels: make(map[string]models.Tunnel),
},
isWindows: IsWindows(),
}
cfg.isConfigExists()
cfg.LoadConfig()
Expand Down
7 changes: 0 additions & 7 deletions config/darwin.go

This file was deleted.

7 changes: 0 additions & 7 deletions config/linux.go

This file was deleted.

7 changes: 0 additions & 7 deletions config/windows.go

This file was deleted.

24 changes: 14 additions & 10 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
"log"
"net"
"os"
"os/exec"
"strconv"
"strings"
"syscall"

"github.com/tech-thinker/telepath/config"
"github.com/tech-thinker/telepath/constants"
"github.com/tech-thinker/telepath/handler"
"github.com/tech-thinker/telepath/models"
Expand Down Expand Up @@ -49,6 +47,11 @@ func (ps *daemonMgr) IsDaemonRunning(ctx context.Context) bool {
return false
}

// For windows, no need to check process signal
if utils.IsWindows() {
return true
}

// Check if the process is alive
err = process.Signal(syscall.Signal(0))
return err == nil
Expand All @@ -61,12 +64,13 @@ func (ps *daemonMgr) RunAsDaemon(ctx context.Context) error {
return fmt.Errorf("daemon is already running")
}

// Fork the process
cmd := exec.Command(os.Args[0], "daemon", "start", "--daemon-child")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Start()
fmt.Printf("Daemon started with PID: %d\n", cmd.Process.Pid)
pid, err := utils.FrokProcess(os.Args[0], "daemon", "start", "--daemon-child")
if err != nil {
// fmt.Println("Failed to start daemon process: ", err)
return fmt.Errorf("failed to start daemon process: %v", err.Error())
}

fmt.Printf("Daemon started with PID: %d\n", pid)
return nil
}

Expand All @@ -83,7 +87,7 @@ func (ps *daemonMgr) RunDaemonChild(ctx context.Context) (err error) {
// Set up the UNIX socket
var listener net.Listener

if !config.IsWindows() {
if !utils.IsWindows() {
if _, err := os.Stat(ps.socketPath); err == nil {
os.Remove(ps.socketPath)
}
Expand Down Expand Up @@ -189,7 +193,7 @@ func (ps *daemonMgr) SendCommandToDaemon(ctx context.Context, packet models.Pack
var conn net.Conn
var err error

if !config.IsWindows() {
if !utils.IsWindows() {
conn, err = net.Dial("unix", ps.socketPath)
if err != nil {
return fmt.Errorf("failed to connect to daemon: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion man/telepath.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH TELEPATH 1 "BUILDDATE" "Version VERSION" "User Commands"
.TH TELEPATH 1 "2025-01-23" "Version v0.0.0" "User Commands"
.SH NAME
telepath \- is a powerful CLI tool for secure port forwarding with support for multiple jump hosts and flexible authentication.
.SH SYNOPSIS
Expand Down
24 changes: 24 additions & 0 deletions utils/darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build darwin

package utils

import (
"os"
"os/exec"
)

func IsWindows() bool {
return false
}

func FrokProcess(name string, arg ...string) (int, error) {
// Fork the process
cmd := exec.Command(name, arg...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
return 0, err
}
return cmd.Process.Pid, nil
}
24 changes: 24 additions & 0 deletions utils/linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build linux

package utils

import (
"os"
"os/exec"
)

func IsWindows() bool {
return false
}

func FrokProcess(name string, arg ...string) (int, error) {
// Fork the process
cmd := exec.Command(name, arg...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
return 0, err
}
return cmd.Process.Pid, nil
}
29 changes: 29 additions & 0 deletions utils/windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build windows

package utils

import (
"os"
"os/exec"
"syscall"
)

func IsWindows() bool {
return true
}

func FrokProcess(name string, arg ...string) (int, error) {
// Fork the process
cmd := exec.Command(name, arg...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
err := cmd.Start()
if err != nil {
return 0, err
}
return cmd.Process.Pid, nil
}
Loading