-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25d5b8a
commit 5fa2822
Showing
28 changed files
with
352 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package admin_service | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hiddify/libcore/global" | ||
"github.com/kardianos/service" | ||
) | ||
|
||
var logger service.Logger | ||
|
||
type hiddifyNext struct{} | ||
|
||
var port int = 18020 | ||
|
||
func (m *hiddifyNext) Start(s service.Service) error { | ||
go m.run() | ||
return nil | ||
} | ||
func (m *hiddifyNext) Stop(s service.Service) error { | ||
err := global.StopService() | ||
if err != nil { | ||
return err | ||
} | ||
// Stop should not block. Return with a few seconds. | ||
// <-time.After(time.Second * 1) | ||
return nil | ||
} | ||
func (m *hiddifyNext) run() { | ||
StartWebServer(port, false) | ||
} | ||
|
||
func StartService(goArg string) { | ||
svcConfig := &service.Config{ | ||
Name: "Hiddify Tunnel Service", | ||
DisplayName: "Hiddify Tunnel Service", | ||
Description: "This is a bridge for tunnel", | ||
} | ||
|
||
prg := &hiddifyNext{} | ||
s, err := service.New(prg, svcConfig) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if len(goArg) > 0 { | ||
if goArg == "uninstall" { | ||
err = s.Stop() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
err = service.Control(s, goArg) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if goArg == "install" { | ||
err = s.Start() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
logger, err = s.Logger(nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = s.Run() | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> | ||
<!-- <assemblyIdentity | ||
version="1.0.0.0" | ||
processorArchitecture="*" | ||
name="hiddify-service.exe" | ||
type="win32" | ||
/> --> | ||
<description>Hiddify Tunnel Service</description> | ||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> | ||
<security> | ||
<requestedPrivileges> | ||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> | ||
</requestedPrivileges> | ||
</security> | ||
</trustInfo> | ||
</assembly> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
/* | ||
#cgo LDFLAGS: bin/libcore.dll | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
// Import the function from the DLL | ||
extern void AdminServiceStart(char *arg); | ||
*/ | ||
import "C" | ||
import ( | ||
"os" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
// Check if there is at least one command-line argument | ||
if len(args) < 2 { | ||
println("Usage: hiddify-service.exe empty/start/stop/uninstall/install") | ||
// os.Exit(1) | ||
args = append(args, "") | ||
} | ||
// fmt.Printf("os.Args: %+v", args) | ||
os.Chdir(os.Args[0]) | ||
// Convert the Go string to a C string | ||
arg := C.CString(args[1]) | ||
// defer C.free(unsafe.Pointer(arg)) | ||
|
||
// Call AdminServiceStart with the C string | ||
C.AdminServiceStart(arg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hiddify/libcore/admin_service" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var commandService = &cobra.Command{ | ||
Use: "admin-service", | ||
Short: "Sign box service start/stop/install/uninstall", | ||
Args: cobra.MaximumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) < 2 { | ||
admin_service.StartService("") | ||
} | ||
admin_service.StartService(args[1]) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.