Skip to content

Commit 7cf5a51

Browse files
committed
qr, https, etc
1 parent dbe3494 commit 7cf5a51

File tree

8 files changed

+44
-30
lines changed

8 files changed

+44
-30
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:edge
22

33
# Set the timezone and install CA certificates
4-
RUN apk --no-cache add ca-certificates tzdata libqrencode
4+
RUN apk --no-cache add ca-certificates tzdata
55

66
COPY lantern-server-manager /app/server
77
COPY --from=ghcr.io/sagernet/sing-box /usr/local/bin/sing-box /usr/local/bin/sing-box

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ lantern-server-manager:
22
CGO_ENABLED=0 go build -ldflags="-extldflags=-static" -o lantern-server-manager ./cmd/...
33

44
packer:
5-
@cd cloud/packer
65
@if [ -z "$(PKR_VAR_aws_secret_key)" ]; then \
76
echo "Error: PKR_VAR_aws_secret_key is not set"; \
87
exit 1; \
@@ -17,4 +16,4 @@ packer:
1716
exit 1; \
1817
fi
1918

20-
@packer build .
19+
cd cloud/packer && packer build .

cloud/lantern-server-manager.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ After=syslog.target network.target remote-fs.target nss-lookup.target
55

66
[Service]
77
User=root
8-
ExecStart=/opt/lantern/lantern-server-manager serve
8+
ExecStart=/opt/lantern/lantern-server-manager serve -d /opt/lantern/data
99
ExecStop=/bin/kill -s QUIT $MAINPID
1010
PrivateTmp=true
1111
StandardOutput=journal+console

cloud/packer/main.pkr.hcl

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source "amazon-ebs" "amazon-linux" {
1313
region = var.aws_region
1414
source_ami_filter {
1515
filters = {
16-
name = "*amzn3-ami-hvm-*"
16+
name = "al2023-ami*x86_64"
1717
root-device-type = "ebs"
1818
virtualization-type = "hvm"
1919
}
@@ -30,19 +30,24 @@ build {
3030
source = "../lantern-server-manager.service"
3131
destination = "/tmp/lantern-server-manager.service"
3232
}
33+
provisioner "file" {
34+
source = "../sing-box.service"
35+
destination = "/tmp/sing-box.service"
36+
}
3337

3438
provisioner "shell" {
3539
inline = [
36-
"yum install -y qrencode",
3740
"curl -L https://github.com/SagerNet/sing-box/releases/download/v${var.sing_box_version}/sing-box-${var.sing_box_version}-linux-amd64.tar.gz -o /tmp/sing-box.tar.gz",
3841
"curl -L https://github.com/getlantern/lantern-server-manager/releases/download/v${var.version}/lantern-server-manager_${var.version}_linux_amd64.tar.gz -o /tmp/lantern-server-manager.tar.gz",
3942
"tar -xzf /tmp/lantern-server-manager.tar.gz -C /tmp",
4043
"tar -xzf /tmp/sing-box.tar.gz -C /tmp",
4144
"sudo mkdir -p /opt/lantern",
4245
"sudo mv /tmp/sing-box-${var.sing_box_version}-linux-amd64/sing-box /usr/local/bin/sing-box",
4346
"sudo mv /tmp/lantern-server-manager.service /opt/lantern/lantern-server-manager.service",
47+
"sudo mv /tmp/sing-box.service /opt/lantern/sing-box.service",
4448
"sudo mv /tmp/lantern-server-manager /opt/lantern/lantern-server-manager",
4549
"sudo systemctl enable /opt/lantern/lantern-server-manager.service",
50+
"sudo systemctl enable /opt/lantern/sing-box.service",
4651
"rm /home/ec2-user/.ssh/authorized_keys",
4752
"sudo rm /root/.ssh/authorized_keys"
4853
]

cloud/packer/vars.pkr.hcl

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ variable "aws_access_key" {
1414

1515
variable "version" {
1616
type = string
17-
default = "0.0.2"
1817
}
1918

2019
variable "sing_box_version" {

cloud/sing-box.service

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=SingBox
3+
Documentation=https://github.com/getlantern/sing-box
4+
After=lantern-server-manager.service
5+
Requires=lantern-server-manager.service
6+
7+
[Service]
8+
User=root
9+
ExecStart=/usr/local/bin/sing-box run --config /opt/lantern/data/sing-box-config.json
10+
ExecStop=/bin/kill -s QUIT $MAINPID
11+
PrivateTmp=true
12+
StandardOutput=journal+console
13+
StandardError=journal+console
14+
[Install]
15+
WantedBy=multi-user.target

common/server.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"github.com/mdp/qrterminal/v3"
89
"math/rand/v2"
910
"os"
10-
"os/exec"
1111
"path"
1212
"time"
1313

@@ -29,20 +29,8 @@ func (c *ServerConfig) GetNewServerURL() string {
2929
}
3030

3131
func (c *ServerConfig) GetQR() string {
32-
qrCodeOptions := []string{"ANSI", "ANSI256", "ASCII", "ASCIIi", "UTF8", "UTF8i", "ANSIUTF8", "ANSIUTF8i", "ANSI256UTF8"}
33-
text := "https://google.com/" // TODO: c.GetNewServerURL()
3432
qrCode := bytes.NewBufferString("")
35-
for _, qrCodeOption := range qrCodeOptions {
36-
cmd := exec.Command("qrencode", "-t", qrCodeOption, text+qrCodeOption)
37-
// collect output
38-
cmd.Stdout = qrCode
39-
cmd.Stderr = os.Stderr
40-
if err := cmd.Run(); err != nil {
41-
log.Errorf("Error generating QR code: %v", err)
42-
continue
43-
}
44-
}
45-
//qrterminal.GenerateHalfBlock(c.GetNewServerURL(), qrterminal.L, qrCode)
33+
qrterminal.GenerateHalfBlock(c.GetNewServerURL(), qrterminal.L, qrCode)
4634

4735
return qrCode.String()
4836
}

common/singbox.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func GenerateSingBoxConnectConfig(dataDir, publicIP, username string) ([]byte, e
122122
Server: publicIP,
123123
ServerPort: inboundOptions.ListenPort,
124124
},
125-
Method: "2022-blake3-aes-128-gcm",
125+
Method: "chacha20-ietf-poly1305",
126126
Password: pw,
127127
},
128128
},
@@ -140,8 +140,8 @@ func WriteSingBoxServerConfig(dataDir string, opt *option.Options) error {
140140
}
141141

142142
func makeShadowsocksPassword() string {
143-
// generate a password. we are using 2022-blake3-aes-128-gcm so length must be 16
144-
passwordStr := password.MustGenerate(16, 10, 6, false, false)
143+
// generate a password. we are using chacha20-ietf-poly1305 so length can be anything
144+
passwordStr := password.MustGenerate(32, 10, 6, false, false)
145145

146146
return base64.StdEncoding.EncodeToString([]byte(passwordStr))
147147
}
@@ -163,7 +163,7 @@ func GenerateBasicSingBoxServerConfig(dataDir string) (*option.Options, error) {
163163
Tag: "ss-inbound",
164164

165165
Options: &option.ShadowsocksInboundOptions{
166-
Method: "2022-blake3-aes-128-gcm",
166+
Method: "chacha20-ietf-poly1305",
167167
ListenOptions: option.ListenOptions{
168168
ListenPort: uint16(port),
169169
Listen: common.Ptr(badoption.Addr(netip.AddrFrom4([4]byte{0, 0, 0, 0}))),
@@ -194,10 +194,18 @@ func ValidateSingBoxConfig(dataDir string) error {
194194
return nil
195195
}
196196

197+
// RestartSingBox restarts the sing-box service. If NO_SYSTEMD is set, it will use pkill and run the command directly.
198+
// this is useful for local testing without install of the service
199+
var noSystemd = os.Getenv("NO_SYSTEMD") != ""
200+
197201
func RestartSingBox(dataDir string) error {
198-
singBoxPath, _ := exec.LookPath("sing-box")
199-
// kill process
200-
_ = exec.Command("pkill", "-9", "sing-box").Run()
201-
// start process
202-
return exec.Command(singBoxPath, "run", "--config", path.Join(dataDir, "sing-box-config.json")).Start()
202+
if noSystemd {
203+
singBoxPath, _ := exec.LookPath("sing-box")
204+
// kill process
205+
_ = exec.Command("pkill", "-9", "sing-box").Run()
206+
// start process
207+
return exec.Command(singBoxPath, "run", "--config", path.Join(dataDir, "sing-box-config.json")).Start()
208+
} else {
209+
return exec.Command("systemctl", "restart", "sing-box").Run()
210+
}
203211
}

0 commit comments

Comments
 (0)