Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Apr 6, 2020
2 parents a2e1637 + 0175c20 commit 4c004d9
Show file tree
Hide file tree
Showing 33 changed files with 579 additions and 393 deletions.
5 changes: 3 additions & 2 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ done

cp ../data/*.dat ./
cp ../data/*.json ./
cp ../data/*.service ./

for name in *.zip;do
zip -ur $name ./*.dat ./*.json
zip -ur $name ./*.dat ./*.json ./*.service
sha1sum $name > $name.sha1
done

rm ./*.dat
rm ./*.json

rm ./*.service
40 changes: 20 additions & 20 deletions cert/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func askForConfirmation() bool {
var response string
_, err := fmt.Scanln(&response)
if err != nil {
log.DefaultLogger.Fatal(err)
log.Fatal(err)
}
okayResponses := []string{"y", "Y", "yes", "Yes", "YES"}
nokayResponses := []string{"n", "N", "no", "No", "NO"}
Expand All @@ -47,11 +47,11 @@ func askForConfirmation() bool {
}

func RequestCertGuide() {
log.DefaultLogger.Info("Guide mode: request cert")
log.Info("Guide mode: request cert")

log.DefaultLogger.Warn("To perform a ACME challenge, trojan-go need the ROOT PRIVILEGE to bind port 80 and 443")
log.DefaultLogger.Warn("Please make sure you HAVE sudo this program, and port 80/443 is NOT used by other process at this moment")
log.DefaultLogger.Info("Continue? (y/n)")
log.Warn("To perform a ACME challenge, trojan-go need the ROOT PRIVILEGE to bind port 80 and 443")
log.Warn("Please make sure you HAVE sudo this program, and port 80/443 is NOT used by other process at this moment")
log.Info("Continue? (y/n)")

if !askForConfirmation() {
return
Expand All @@ -66,9 +66,9 @@ func RequestCertGuide() {
fmt.Println("Your email:")
fmt.Scanf("%s", &info.Email)
} else {
log.DefaultLogger.Info("domain_info.json found")
log.Info("domain_info.json found")
if err := json.Unmarshal(data, info); err != nil {
log.DefaultLogger.Error(common.NewError("failed to parse domain_info.json").Base(err))
log.Error(common.NewError("failed to parse domain_info.json").Base(err))
return
}
}
Expand All @@ -85,36 +85,36 @@ func RequestCertGuide() {
ioutil.WriteFile("domain_info.json", data, os.ModePerm)

if err := RequestCert(info.Domain, info.Email); err != nil {
log.DefaultLogger.Error(common.NewError("Failed to create cert").Base(err))
log.Error(common.NewError("Failed to create cert").Base(err))
return
}

log.DefaultLogger.Info("All done. Certificates has been saved to server.crt and server.key")
log.DefaultLogger.Warn("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
log.DefaultLogger.Warn("BACKUP DOMAIN_INFO.JSON, SERVER.KEY, SERVER.CRT AND USER.KEY TO A SAFE PLACE")
log.DefaultLogger.Warn("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
log.Info("All done. Certificates has been saved to server.crt and server.key")
log.Warn("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
log.Warn("BACKUP DOMAIN_INFO.JSON, SERVER.KEY, SERVER.CRT AND USER.KEY TO A SAFE PLACE")
log.Warn("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
}

func RenewCertGuide() {
log.DefaultLogger.Info("Guide mode: renew cert")
log.Info("Guide mode: renew cert")

log.DefaultLogger.Warn("To perform a ACME challenge, trojan-go need the ROOT PRIVILEGE to bind port 80 and 443")
log.DefaultLogger.Warn("Please make sure you HAVE sudo this program, and port 80/443 is NOT used by other process at this moment")
log.DefaultLogger.Info("Continue? (y/n)")
log.Warn("To perform a ACME challenge, trojan-go need the ROOT PRIVILEGE to bind port 80 and 443")
log.Warn("Please make sure you HAVE sudo this program, and port 80/443 is NOT used by other process at this moment")
log.Info("Continue? (y/n)")

if !askForConfirmation() {
return
}

data, err := ioutil.ReadFile("domain_info.json")
if err != nil {
log.DefaultLogger.Error(err)
log.Error(err)
return
}

info := &domainInfo{}
if err := json.Unmarshal(data, info); err != nil {
log.DefaultLogger.Error(err)
log.Error(err)
}

fmt.Printf("Domain: %s, Email: %s\n", info.Domain, info.Email)
Expand All @@ -125,8 +125,8 @@ func RenewCertGuide() {
}

if err := RenewCert(info.Domain, info.Email); err != nil {
log.DefaultLogger.Error(common.NewError("Failed to renew cert").Base(err))
log.Error(common.NewError("Failed to renew cert").Base(err))
return
}
log.DefaultLogger.Info("All done")
log.Info("All done")
}
2 changes: 1 addition & 1 deletion cert/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *certOption) Handle() error {
return common.NewError("not specified")
default:
err := common.NewError("invalid args " + *c.args)
log.DefaultLogger.Error(err)
log.Error(err)
return common.NewError("invalid args")
}
}
Expand Down
13 changes: 12 additions & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"crypto/sha256"
"fmt"
"io"
"log"
"os"
"path/filepath"
)

const (
Version = "v0.0.17"
Version = "v0.1.0"
)

type Runnable interface {
Expand Down Expand Up @@ -49,3 +52,11 @@ func HumanFriendlyTraffic(bytes int) string {
}
return fmt.Sprintf("%.2f GiB", float32(bytes)/GiB)
}

func GetProgramDir() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
return dir
}
2 changes: 2 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type RouterConfig struct {
DefaultPolicy string `json:"default_policy"`
RouteByIP bool `json:"route_by_ip"`
RouteByIPOnNonmatch bool `json:"route_by_ip_on_nonmatch"`
GeoIPFilename string `json:"geoip"`
GeoSiteFilename string `json:"geosite"`

BypassList []byte
ProxyList []byte
Expand Down
Loading

0 comments on commit 4c004d9

Please sign in to comment.