Skip to content

Commit

Permalink
v20240606
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed May 10, 2024
1 parent a8ff76e commit c5416fb
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 488 deletions.
302 changes: 186 additions & 116 deletions README.md

Large diffs are not rendered by default.

34 changes: 11 additions & 23 deletions cli/brook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func main() {
},
&cli.StringFlag{
Name: "pid",
Usage: "A file path used to store pid",
Usage: "A file path used to store pid. Send SIGUSR1 to me to reset the --serverLog file on unix system",
},
}
app.Before = func(c *cli.Context) error {
Expand Down Expand Up @@ -1192,16 +1192,6 @@ func main() {
}
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "quicserver",
Aliases: []string{"s"},
Usage: "Brook quicserver address, like: quic://google.com:443. Do not omit the port under any circumstances",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "Brook quicserver password",
},
&cli.StringFlag{
Name: "link",
Usage: "brook link, you can get it via $ brook link. The wssserver and password parameters will be ignored",
Expand Down Expand Up @@ -1236,21 +1226,13 @@ func main() {
},
Action: func(c *cli.Context) error {
if c.Bool("example") {
fmt.Println("brook quicclient --quicserver quic://domain.com:9999 --password hello --socks5 127.0.0.1:1080")
fmt.Println("brook quicclient --link 'brook://...' --socks5 127.0.0.1:1080")
return nil
}
if c.String("quicserver") == "" && c.String("link") == "" {
if c.String("link") == "" {
return cli.ShowSubcommandHelp(c)
}
var link = ""
if c.String("quicserver") != "" {
v := url.Values{}
v.Set("password", c.String("password"))
link = brook.Link("quicserver", c.String("quicserver"), v)
}
if c.String("link") != "" {
link = c.String("link")
}
link := c.String("link")
h, p, err := net.SplitHostPort(c.String("socks5"))
if err != nil {
return err
Expand Down Expand Up @@ -1376,6 +1358,9 @@ func main() {
if strings.HasPrefix(c.String("server"), "quic://") {
kind = "quicserver"
}
if kind == "quicserver" {
return errors.New("It is recommended to use brook link and specify --udpoverstream")
}
v := url.Values{}
v.Set("password", c.String("password"))
link = brook.Link(kind, c.String("server"), v)
Expand Down Expand Up @@ -1514,6 +1499,9 @@ func main() {
if strings.HasPrefix(c.String("server"), "quic://") {
kind = "quicserver"
}
if kind == "quicserver" {
return errors.New("It is recommended to use brook link and specify --udpoverstream")
}
v := url.Values{}
v.Set("password", c.String("password"))
link = brook.Link(kind, c.String("server"), v)
Expand Down Expand Up @@ -1585,7 +1573,7 @@ func main() {
},
&cli.BoolFlag{
Name: "udpoverstream",
Usage: "When server is brook quicserver, UDP over Stream. Note: only brook CLI and tun2brook suppport for now",
Usage: "When server is brook quicserver, UDP over Stream. Under normal circumstances, you need this parameter because the max datagram size for QUIC is very small. Note: only brook CLI and tun2brook suppport for now",
},
&cli.StringFlag{
Name: "address",
Expand Down
6 changes: 1 addition & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,4 @@ brook server -l :9999 -p hello
| [![](https://brook.app/images/appstore.png)](https://apps.apple.com/us/app/brook-network-tool/id1216002642) | [![](https://brook.app/images/android.png)](https://github.com/txthinking/brook/releases/latest/download/Brook.apk) | [![](https://brook.app/images/mac.png)](https://apps.apple.com/us/app/brook-network-tool/id1216002642) | [![Windows](https://brook.app/images/windows.png)](https://github.com/txthinking/brook/releases/latest/download/Brook.msix) | [![](https://brook.app/images/linux.png)](https://github.com/txthinking/brook/releases/latest/download/Brook.bin) | [![OpenWrt](https://brook.app/images/openwrt.png)](https://github.com/txthinking/brook/releases) |
| / | / | [App Mode](https://www.txthinking.com/talks/articles/macos-app-mode-en.article) | [How](https://www.txthinking.com/talks/articles/msix-brook-en.article) | [How](https://www.txthinking.com/talks/articles/linux-app-brook-en.article) | [How](https://www.txthinking.com/talks/articles/brook-openwrt-en.article) |

## CLI Client

```
brook client -s 1.2.3.4:9999 -p hello --socks5 127.0.0.1:1080
```
> You may want to use `brook link` to customize some parameters
61 changes: 54 additions & 7 deletions docs/gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

## Programmable

```
Brook GUI will pass different global variables to the script at different times, and the script only needs to assign the processing result to the global variable out
```
Brook GUI will pass different _global variables_ to the script at different times, and the script only needs to assign the processing result to the global variable `out`

- address: We call it address which includes both host and port. For example, an ip address contains an ip and a port; a domain address contains a domain and a port.
- Fake DNS: Fake DNS can allow you to obtain domain address on `in_address` step. [How Fake DNS works](https://www.txthinking.com/talks/articles/brook-fakedns-en.article)

### Introduction to incoming variables
### Variables

| variable | type | condition | timing | description | out type |
| ------------------------------ | ---- | ----------- | --------------------------------- | ------------------------------------------------- | -------- |
Expand Down Expand Up @@ -104,7 +105,53 @@ Brook GUI will pass different global variables to the script at different times,

`out`, must be set to a response

## Write script
## Module

There are already some modules: https://github.com/txthinking/brook/blob/master/programmable/modules/

### Brook GUI

In Brook GUI, scripts are abstracted into modules, and it will automatically combine [_header.tengo](https://github.com/txthinking/brook/blob/master/programmable/modules/_header.tengo) and [_footer.tengo](https://github.com/txthinking/brook/blob/master/programmable/modules/_footer.tengo), so you only need to write the module itself.

```
modules = append(modules, {
// If you want to predefine multiple brook links, and then programmatically specify which one to connect to, then define `brooklinks` key a function
brooklinks: func(m) {
// Please refer to the example in `brooklinks.tengo`
},
// If you want to intercept and handle a DNS query, then define `dnsquery` key a function, `m` is the `in_dnsquery`
dnsquery: func(m) {
// Please refer to the example in `block_aaaa.tengo`
},
// If you want to intercept and handle an address, then define `address` key a function, `m` is the `in_address`
address: func(m) {
// Please refer to the example in `block_google_secure_dns.tengo`
},
// If you want to intercept and handle a http request, then define `httprequest` key a function, `request` is the `in_httprequest`
httprequest: func(request) {
// Please refer to the example in `ios_app_downgrade.tengo` or `redirect_google_cn.tengo`
},
// If you want to intercept and handle a http response, then define `httpresponse` key a function, `request` is the `in_httprequest`, `response` is the `in_httpresponse`
httpresponse: func(request, response) {
// Please refer to the example in `response_sample.tengo`
}
})
```

### tun2brook

If you are using tun2brook, you can combine multiple modules into a complete script in the following way. For example:

```
cat _header.tengo > my.tengo
cat block_google_secure_dns.tengo >> my.tengo
cat block_aaaa.tengo >> my.tengo
cat _footer.tengo >> my.tengo
```

## Syntax

[Tengo Language Syntax](https://github.com/d5/tengo/blob/master/docs/tutorial.md)

Expand Down Expand Up @@ -151,9 +198,9 @@ Library
* hexencode(s string) => string/error: returns the hexadecimal encoding of src
```

## Debug script
## Debug

It is recommended to use [tun2brook](https://github.com/txthinking/tun2brook) on desktop to debug with `fmt.println`
If you are writing complex scripts, the GUI may not be convenient for debugging. It is recommended to use [tun2brook](https://github.com/txthinking/tun2brook) on desktop to debug with `fmt.println`

## Install CA

Expand Down
Loading

0 comments on commit c5416fb

Please sign in to comment.