mirror of
https://github.com/CyberL1/holesail-proxy.git
synced 2025-04-01 13:38:35 -04:00
Compare commits
15 Commits
334b9aacc6
...
2cf1234534
Author | SHA1 | Date | |
---|---|---|---|
2cf1234534 | |||
d2a8181804 | |||
2762665529 | |||
|
3566169f14 | ||
c0c1d3cb42 | |||
2b11bb9d55 | |||
692aafd6c8 | |||
8fc9c8a017 | |||
14ff2efa3d | |||
f33ccec5c4 | |||
5c958b2b2d | |||
afb5f05e8d | |||
f372032b21 | |||
495d423f2e | |||
c0ac782dcb |
45
.github/workflows/release.yml
vendored
Normal file
45
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Release
|
||||
permissions: write-all
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- windows
|
||||
- linux
|
||||
- darwin
|
||||
arch:
|
||||
- amd64
|
||||
- arm64
|
||||
exclude:
|
||||
- os: windows
|
||||
arch: arm64
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.23'
|
||||
- name: Set env
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Build binary
|
||||
run: |
|
||||
export GOOS=${{ matrix.os }}
|
||||
export GOARCH=${{ matrix.arch }}
|
||||
go build -ldflags "-X holesail-proxy/utils.Version=${{ env.RELEASE_VERSION }}"
|
||||
- name: Pack binary
|
||||
run: zip holesail-proxy-${{ matrix.os }}-${{ matrix.arch }}.zip holesail-proxy${{ matrix.os == 'windows' && '.exe' || '' }}
|
||||
- name: Create release
|
||||
uses: ncipollo/release-action@v1.15.0
|
||||
with:
|
||||
tag: ${{ env.RELEASE_VERSION }}
|
||||
artifacts: holesail-proxy-${{ matrix.os }}-${{ matrix.arch }}.zip
|
||||
allowUpdates: true
|
22
README.md
Normal file
22
README.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Holesail reverse proxy
|
||||
A CLI for running holesail as a reverse proxy
|
||||
|
||||
# Instalation
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Make sure you have holesail installed on your system
|
||||
|
||||
Windows:
|
||||
```
|
||||
irm https://raw.githubusercontent.com/CyberL1/holesail-proxy/main/scripts/get.ps1 | iex
|
||||
```
|
||||
|
||||
Linux:
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/CyberL1/holesail-proxy/main/scripts/get.sh | sh
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
1. Do `holesail-proxy up`
|
||||
2. Go to `<hash>.localhost` and you'll be connected to the holesail connector after a moment
|
53
cmd/down.go
Normal file
53
cmd/down.go
Normal file
@ -0,0 +1,53 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/shirou/gopsutil/process"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(downCmd)
|
||||
}
|
||||
|
||||
var downCmd = &cobra.Command{
|
||||
Use: "down",
|
||||
Short: "Stop running holesail processes",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if _, err := exec.LookPath("holesail"); err != nil {
|
||||
fmt.Println("holesail command not found")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
processes, err := process.Processes()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
var stoppedProcesses int
|
||||
|
||||
for _, process := range processes {
|
||||
processName, _ := process.Name()
|
||||
cmdLine, _ := process.Cmdline()
|
||||
|
||||
if processName == "node" {
|
||||
cmdLineSplitted := strings.Split(cmdLine, "/")
|
||||
cmdLineWithoutBloat := strings.Join(cmdLineSplitted[len(cmdLineSplitted)-3:], "/")
|
||||
|
||||
if strings.HasPrefix(cmdLineWithoutBloat, "node_modules/holesail/index.js") {
|
||||
process.SendSignal(syscall.SIGINT)
|
||||
stoppedProcesses++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Stopped %v holesail processes\n", stoppedProcesses)
|
||||
},
|
||||
}
|
10
cmd/up.go
10
cmd/up.go
@ -24,6 +24,11 @@ var upCmd = &cobra.Command{
|
||||
Short: "Start holesail proxy",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if _, err := exec.LookPath("holesail"); err != nil {
|
||||
fmt.Println("holesail command not found")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cmd.Println("Starting proxy")
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -84,7 +89,10 @@ var upCmd = &cobra.Command{
|
||||
httputil.NewSingleHostReverseProxy(appUrl).ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
http.ListenAndServe(":80", nil)
|
||||
err := http.ListenAndServe(":80", nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
60
cmd/version.go
Normal file
60
cmd/version.go
Normal file
@ -0,0 +1,60 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"holesail-proxy/utils"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Displays your CLI version",
|
||||
Run: version,
|
||||
}
|
||||
|
||||
var upgradeCmd = &cobra.Command{
|
||||
Use: "upgrade",
|
||||
Short: "Upgrades your CLI version",
|
||||
Run: upgrade,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
versionCmd.AddCommand(upgradeCmd)
|
||||
}
|
||||
|
||||
func version(cmd *cobra.Command, args []string) {
|
||||
latestRelease, _ := utils.GetLatestCliVersion()
|
||||
|
||||
if utils.Version < latestRelease.TagName {
|
||||
fmt.Println("A new update is avaliable")
|
||||
fmt.Println("Run 'holesail-proxy version upgrade' to upgrade")
|
||||
}
|
||||
fmt.Println("Your CLI Version:", utils.Version)
|
||||
fmt.Println("Latest CLI version:", latestRelease.TagName)
|
||||
}
|
||||
|
||||
func upgrade(cmd *cobra.Command, args []string) {
|
||||
var command string
|
||||
var cmdArgs []string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "linux", "darwin":
|
||||
command = "sh"
|
||||
cmdArgs = []string{"-c", "curl -fsSL https://raw.githubusercontent.com/CyberL1/holesail-proxy/main/scripts/get.sh | sh"}
|
||||
|
||||
case "windows":
|
||||
command = "powershell"
|
||||
cmdArgs = []string{"irm https://raw.githubusercontent.com/CyberL1/holesail-proxy/main/scripts/get.ps1 | iex"}
|
||||
}
|
||||
|
||||
execCmd := exec.Command(command, cmdArgs...)
|
||||
execCmd.Stderr = os.Stderr
|
||||
execCmd.Stdin = os.Stdin
|
||||
execCmd.Stdout = os.Stdout
|
||||
execCmd.Run()
|
||||
}
|
6
go.mod
6
go.mod
@ -5,6 +5,12 @@ go 1.23.5
|
||||
require github.com/spf13/cobra v1.8.1
|
||||
|
||||
require (
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.14 // indirect
|
||||
github.com/tklauser/numcpus v0.8.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
)
|
||||
|
13
go.sum
13
go.sum
@ -1,10 +1,23 @@
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
|
||||
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
|
||||
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
|
||||
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
36
scripts/get.ps1
Normal file
36
scripts/get.ps1
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$BinPath = "${Home}\.holesail-proxy\bin"
|
||||
$Zip = "$RuntimerPath\holesail-proxy.zip"
|
||||
$Exe = "$RuntimerPath\holesail-proxy.exe"
|
||||
$OldExe = "$env:Temp\holesail-proxy-old.exe"
|
||||
|
||||
$Target = "windows-amd64"
|
||||
|
||||
$DownloadUrl = "https://github.com/CyberL1/holesail-proxy/releases/latest/download/holesal-proxy-${Target}.zip"
|
||||
|
||||
if (!(Test-Path $BinPath)) {
|
||||
New-Item $BinPath -ItemType Directory | Out-Null
|
||||
}
|
||||
|
||||
curl.exe -Lo $Zip $DownloadUrl
|
||||
|
||||
if (Test-Path $Exe) {
|
||||
Move-Item -Path $Exe -Destination $OldExe -Force
|
||||
}
|
||||
|
||||
Expand-Archive -LiteralPath $Zip -DestinationPath $BinPath -Force
|
||||
Remove-Item $Zip
|
||||
|
||||
$User = [System.EnvironmentVariableTarget]::User
|
||||
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User)
|
||||
|
||||
if (!(";${Path};".ToLower() -like "*;${BinPath};*".ToLower())) {
|
||||
[System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinPath}", $User)
|
||||
$Env:Path += ";${BinPath}"
|
||||
}
|
||||
|
||||
Write-Output "Holesail proxy was installed to $Exe"
|
||||
Write-Output "Run 'holesail-proxy up' to get started"
|
45
scripts/get.sh
Normal file
45
scripts/get.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if ! command -v unzip > /dev/null; then
|
||||
echo "Error: Unzip is required to install Holesail proxy"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dir="$HOME/.holesail-proxy/bin"
|
||||
zip="$dir/holesail-proxy.zip"
|
||||
exe="$dir/holesail-proxy"
|
||||
|
||||
if [ "$OS" = "Windows_NT" ]; then
|
||||
target="windows"
|
||||
else
|
||||
case $(uname -sm) in
|
||||
"Darwin x86_64") target="darwin-amd64" ;;
|
||||
"Darwin arm64") target="dawin-arm64" ;;
|
||||
"Linux aarch64") target="linux-arm64" ;;
|
||||
*) target="linux-amd64"
|
||||
esac
|
||||
fi
|
||||
|
||||
download_url="https://github.com/CyberL1/holesail-proxy/releases/latest/download/holesail-proxy-${target}.zip"
|
||||
|
||||
if [ ! -d $dir ]; then
|
||||
mkdir -p $dir
|
||||
fi
|
||||
|
||||
curl --fail --location --progress-bar --output $zip $download_url
|
||||
unzip -d $dir -o $zip
|
||||
chmod +x $exe
|
||||
rm $zip
|
||||
|
||||
echo "Holesail proxy was installed to $exe"
|
||||
if command -v holesail-proxy > /dev/null; then
|
||||
echo "Run 'holesail-proxy up' to get started"
|
||||
else
|
||||
case $SHELL in
|
||||
/bin/zsh) shell_profile=".zshrc" ;;
|
||||
*) shell_profile=".bashrc" ;;
|
||||
esac
|
||||
echo "export PATH=\"$dir:\$PATH\"" >> $HOME/$shell_profile
|
||||
fi
|
6
utils/constants.go
Normal file
6
utils/constants.go
Normal file
@ -0,0 +1,6 @@
|
||||
package utils
|
||||
|
||||
var (
|
||||
Version string
|
||||
GithubReleaseUrl = "https://api.github.com/repos/CyberL1/holesail-proxy/releases/latest"
|
||||
)
|
12
utils/types.go
Normal file
12
utils/types.go
Normal file
@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
type GithubRelease struct {
|
||||
TagName string `json:"tag_name"`
|
||||
Prerelease bool
|
||||
}
|
||||
|
||||
type GithubFile struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
DownloadUrl string `json:"download_url"`
|
||||
}
|
24
utils/version.go
Normal file
24
utils/version.go
Normal file
@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetLatestCliVersion() (*GithubRelease, error) {
|
||||
resp, err := http.Get(GithubReleaseUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
release := &GithubRelease{}
|
||||
err = json.Unmarshal(body, release)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return release, nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user