Skip to content

Commit

Permalink
新增https协议支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lmb1113 committed Oct 17, 2024
1 parent 63bc8d5 commit 844ded3
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 60 deletions.
70 changes: 41 additions & 29 deletions frontend/src/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,52 @@
<span>内网地址</span>
</t-row>
<t-row>
<t-row>
<t-col :span="24">
<div>
<t-input size="large" @input="handleInput" v-model="localhost"
placeholder="请输入需要穿透的本地服务地址,例如(127.0.0.1:8081)"></t-input>
</div>
</t-col>
</t-row>
<t-row v-if="remoteAddr != ''" style="margin-top: 20px;">
<span>外网地址</span>
</t-row>
<t-row v-if="remoteAddr != ''">
<t-input size="large" status="success" v-model="remoteAddr">
<template #suffixIcon>
<copy-icon @click="copy(remoteAddr)" />
</template>
</t-input>
</t-row>
<t-row>
<div class="start-div" v-if="recording">
<t-button size="large" theme="danger" style="width: 100%;margin-top: 20px;"
@click="close()">停止穿透</t-button>
<t-col :span="24">
<div>
<t-input size="large" @input="handleInput" v-model="localhost"
placeholder="请输入需要穿透的本地服务地址,例如(127.0.0.1:8081)"></t-input>
</div>
<div class="start-div" v-else>
<t-button size="large" theme="primary" style="width: 100%;margin-top: 20px;"
@click="startRecording">开始穿透</t-button>
</t-col>
</t-row>
<t-row style="margin-top: 10px;">
<span>映射协议</span>
</t-row>
<t-row>
<t-col :span="24">
<div>
<t-radio-group variant="default-filled" default-value="4" v-model="proxyType">
<t-radio-button v-for="item in proxyTypeList" :value="item">{{ item }}</t-radio-button>
</t-radio-group>
</div>
</t-row>
</t-col>
</t-row>
<t-row v-if="remoteAddr != ''" style="margin-top: 20px;">
<span>外网地址</span>
</t-row>
<t-row v-if="remoteAddr != ''">
<t-input size="large" status="success" v-model="remoteAddr">
<template #suffixIcon>
<copy-icon @click="copy(remoteAddr)" />
</template>
</t-input>
</t-row>
<t-row>
<div class="start-div" v-if="recording">
<t-button size="large" theme="danger" style="width: 100%;margin-top: 20px;"
@click="close()">停止穿透</t-button>
</div>
<div class="start-div" v-else>
<t-button size="large" theme="primary" style="width: 100%;margin-top: 20px;"
@click="startRecording">开始穿透</t-button>
</div>
</t-row>
<t-row style=" position: absolute;bottom: 2%; left: 0;right: 0;">
<div class="copyright-div">
<div>
<t-link style="margin: 5px;" theme="primary" @click="dialogVisible = true"
hover="color">使用指南</t-link>
<t-link style="margin: 5px;" theme="primary"
hover="color" @click="gotoBrowser('http://c.0a0a.cn')">软件官网</t-link>
<t-link style="margin: 5px;" theme="primary" hover="color"
@click="gotoBrowser('http://c.0a0a.cn')">软件官网</t-link>
<t-link style="margin: 5px;" theme="primary" target="_blank"
@click="gotoBrowser('https://qm.qq.com/q/lhm1yvQQN4')" hover="color">交流Q群</t-link>
</div>
Expand Down Expand Up @@ -81,6 +91,8 @@ import useClipboard from 'vue-clipboard3'
import { setBodyBg } from '@/utils/utils';
const localhost = ref("127.0.0.1:8080")
const remoteAddr = ref("")
const proxyType = ref("http")
const proxyTypeList = ref(["http", "https"])
const recording = ref(false)
const dialogVisible = ref(false)
import {
Expand All @@ -93,7 +105,7 @@ const handleInput = (value) => {
}
const startRecording = () => {
recording.value = true
const response = Run(localhost.value);
const response = Run(localhost.value, proxyType.value);
response.then((res) => {
console.log(res)
remoteAddr.value = res; // 设置返回值
Expand Down
2 changes: 1 addition & 1 deletion frontend/wailsjs/go/proxy/Options.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function Run(arg1:string):Promise<string>;
export function Run(arg1:string,arg2:string):Promise<string>;

export function Stop():Promise<void>;
4 changes: 2 additions & 2 deletions frontend/wailsjs/go/proxy/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function Run(arg1) {
return window['go']['proxy']['Options']['Run'](arg1);
export function Run(arg1, arg2) {
return window['go']['proxy']['Options']['Run'](arg1, arg2);
}

export function Stop() {
Expand Down
35 changes: 22 additions & 13 deletions global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,45 @@ import (
"cyj/utils"
"fmt"
"sync"
"time"
)

const remotePort = 7777
const Version = 3

type Config struct {
LocalAddr string
LocalPort int
RemotePort int
RemoteAddr string
ServicePort int
ServiceAddr string
Token string
Name string
LocalAddr string
LocalPort int
RemotePort int
RemoteAddr string
ServicePort int
ServiceAddr string
Token string
Name string
ProxyType string
SubDomain string
CustomDomains []string
}

func (c *Config) GetProxyUrl() string {
if c.ProxyType == "https" {
return fmt.Sprintf("https://%s:%d", c.CustomDomains[0], 1443)
}
return fmt.Sprintf("http://%s:%d", c.RemoteAddr, c.RemotePort)
}

var once sync.Once

func NewDefaultConfig() *Config {
subDomain := utils.RandomString(8, time.Now().UnixMicro())
once.Do(func() {
gConfig = &Config{
ServicePort: remotePort,
ServiceAddr: "c.0a0a.cn",
Token: "12345",
RemoteAddr: "c.0a0a.cn",
Name: utils.GenerateName(),
ServicePort: remotePort,
ServiceAddr: "c.0a0a.cn",
Token: "12345",
RemoteAddr: "c.0a0a.cn",
Name: utils.GenerateName(),
CustomDomains: []string{subDomain + ".c.0a0a.cn"},
}
})
return gConfig
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module cyj

go 1.20
go 1.23

require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/reedsolomon v1.9.15 h1:g2erWKD2M6rgnPf89fCji6jNlhMKMdXcuNHMW1SYCIo=
github.com/klauspost/reedsolomon v1.9.15/go.mod h1:eqPAcE7xar5CIzcdfwydOEdcmchAKAP/qs14y4GCBOk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M=
Expand Down Expand Up @@ -120,6 +121,7 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
Expand Down Expand Up @@ -201,6 +203,7 @@ github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4X
github.com/wailsapp/wails/v2 v2.9.1 h1:irsXnoQrCpeKzKTYZ2SUVlRRyeMR6I0vCO9Q1cvlEdc=
github.com/wailsapp/wails/v2 v2.9.1/go.mod h1:7maJV2h+Egl11Ak8QZN/jlGLj2wg05bsQS+ywJPT0gI=
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 h1:EWU6Pktpas0n8lLQwDsRyZfmkPeRbdgPtW609es+/9E=
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37/go.mod h1:HpMP7DB2CyokmAh4lp0EQnnWhmycP/TvwBGzvuie+H0=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -327,6 +330,7 @@ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/frp/cmd/frpc/sub/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func startService(
defer log.Info("frpc service for config file [%s] stopped", cfgFile)
}

fmt.Printf("%d\n", pxyCfgs[0].(*v1.TCPProxyConfig).RemotePort)
//fmt.Printf("%d\n", pxyCfgs[0].(*v1.TCPProxyConfig).RemotePort)
svr, err := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
if err != nil {
return nil, err
Expand Down
42 changes: 31 additions & 11 deletions pkg/frp/pkg/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"html/template"
"os"
"path/filepath"
"strconv"
"strings"

toml "github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -214,21 +215,40 @@ func LoadClientConfig(path string) (
legacyCommon.ServerPort = config.ServicePort
legacyCommon.ServerAddr = config.ServiceAddr
legacyCommon.Token = config.Token
legacyCommon.TLSEnable = true
legacyCommon.TCPMux = true
var loclConfig = legacy.LocalSvrConf{
var localConfig = legacy.LocalSvrConf{
LocalIP: config.LocalAddr,
LocalPort: config.LocalPort,
}
var xx = legacy.BaseProxyConf{
ProxyType: "tcp",
ProxyName: config.Name,
LocalSvrConf: loclConfig,
}
legacyPxyCfgs["tcp"] = &legacy.TCPProxyConf{
BaseProxyConf: xx,
RemotePort: config.RemotePort,
fmt.Println(config.LocalPort, "=========")
switch config.ProxyType {
case "https":
localConfig.Plugin = "https2http"
localConfig.PluginParams = map[string]string{
"plugin_local_addr": config.LocalAddr + ":" + strconv.Itoa(config.LocalPort),
}
var xx = legacy.BaseProxyConf{
ProxyType: "https",
ProxyName: config.Name,
LocalSvrConf: localConfig,
}
legacyPxyCfgs["https"] = &legacy.HTTPSProxyConf{
BaseProxyConf: xx,
DomainConf: legacy.DomainConf{
CustomDomains: config.CustomDomains,
},
}
default:
var xx = legacy.BaseProxyConf{
ProxyType: "tcp",
ProxyName: config.Name,
LocalSvrConf: localConfig,
}
legacyPxyCfgs["tcp"] = &legacy.TCPProxyConf{
BaseProxyConf: xx,
RemotePort: config.RemotePort,
}
}

cliCfg = legacy.Convert_ClientCommonConf_To_v1(&legacyCommon)
for _, c := range legacyPxyCfgs {
pxyCfgs = append(pxyCfgs, legacy.Convert_ProxyConf_To_v1(c))
Expand Down
6 changes: 4 additions & 2 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewProxy() *Options {
return o
}

func (o *Options) Run(addr string) (string, error) {
func (o *Options) Run(addr string, proxyType string) (string, error) {
if !utils.ValidateIPPortFormat(addr) {
return "", errors.New("本地地址错误 [ip:端口]")
}
Expand All @@ -34,11 +34,13 @@ func (o *Options) Run(addr string) (string, error) {
return "", errors.New("本地地址错误 [ip:端口]")
}

config.ProxyType = proxyType
config.LocalAddr = info[0]
config.LocalPort, _ = strconv.Atoi(info[1])
config.RemotePort = utils.GenerateRemotePort()
global.SetConfig(config)
fmt.Println(addr)
fmt.Printf("%+v", config)

service, err := sub.RunClient("")
if err != nil {
fmt.Println(err.Error())
Expand Down
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ func GenerateRemotePort() int {
func GenerateName() string {
return uuid.New().String()
}

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz0123456789")

// RandomString 生成随机字符串
func RandomString(n int, seed int64) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}

0 comments on commit 844ded3

Please sign in to comment.