Skip to content

Commit

Permalink
add update function
Browse files Browse the repository at this point in the history
  • Loading branch information
BapiGso committed Oct 31, 2024
1 parent e917def commit 6792536
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
3 changes: 3 additions & 0 deletions core/frps/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func Index(c echo.Context) error {
}
if c.QueryParam("status") == "enable" {
viper.Set("enable.frps", !viper.Get("enable.frps").(bool))
if err := viper.WriteConfig(); err != nil {
return err // 处理错误
}
}
return c.JSON(200, "success")

Expand Down
2 changes: 1 addition & 1 deletion core/mymiddleware/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func showPanelAddr() {
fmt.Printf("gopanel started on https://%v%v/%v\n", ipNet.IP, viper.GetString("panel.port"), viper.GetString("panel.path"))
} else if ipNet.IP.To16() != nil && ipNet.IP.IsGlobalUnicast() {
// Check for IPv6 unicast addresses
fmt.Printf("gopanel started on https://%v%v/%v\n", ipNet.IP, viper.GetString("panel.port"), viper.GetString("panel.path"))
fmt.Printf("gopanel started on https://[%v]%v/%v\n", ipNet.IP, viper.GetString("panel.port"), viper.GetString("panel.path"))
}
}
}
11 changes: 8 additions & 3 deletions core/security/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ func Index(c echo.Context) error {
if err := c.Bind(req); err != nil {
return err
}
viper.Set("panel.port", req.Port)

viper.Set("panel,port", req.Port)
viper.Set("panel.path", req.Path)
viper.Set("panel.username", req.Username)
viper.Set("panel.password", req.Password)
if err := viper.WriteConfig(); err != nil {
return err // 处理错误
}
c.Response().After(restart())
if err := restart(); err != nil {
return err
}
return c.JSON(200, "gopanel will take a little time to reboot")
case "PUT":
if err := updateBinaryIfNeeded(); err != nil {
return err
}
c.Response().After(restart())
if err := restart(); err != nil {
return err
}
return c.JSON(200, "success")
}
return echo.ErrMethodNotAllowed
Expand Down
28 changes: 16 additions & 12 deletions core/security/restart_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@

package security

func restart() func() {
return func() {
executable, err := os.Executable()
if err != nil {
return
}
import (
"os"
"syscall"
)

// 使用 syscall.Exec 替换当前进程
err = syscall.Exec(executable, os.Args, os.Environ())
if err != nil {
fmt.Println("Error restarting process:", err)
os.Exit(1)
}
func restart() error {

executable, err := os.Executable()
if err != nil {
return err
}

// 使用 syscall.Exec 替换当前进程
err = syscall.Exec(executable, os.Args, os.Environ())
if err != nil {
return err
}

return nil
}
6 changes: 2 additions & 4 deletions core/security/restart_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package security

import "fmt"

func restart() func() {
return func() {
fmt.Println(123)
}
func restart() error {
return fmt.Errorf("Your operating system need manually reboot")
}
2 changes: 1 addition & 1 deletion core/security/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func updateBinaryIfNeeded() error {

fmt.Println("Binary updated successfully.")
} else {
return fmt.Errorf("local binary is up-to-date")
return fmt.Errorf("latest release date is %s. Local binary is up-to-date", latestReleaseDate.Format("2006-01-02"))
}

return nil
Expand Down

0 comments on commit 6792536

Please sign in to comment.