Skip to content

Commit

Permalink
增加新版本提示,debug 模式默认脱敏
Browse files Browse the repository at this point in the history
  • Loading branch information
Becivells committed Dec 28, 2021
1 parent 01a946c commit 7fb12ab
Show file tree
Hide file tree
Showing 102 changed files with 30,486 additions and 6 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require (
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211221011931-643d94fcab96
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08
github.com/fatih/color v1.13.0
github.com/google/go-github v17.0.0+incompatible
github.com/hashicorp/go-version v1.3.0
github.com/jweny/xhttp v0.0.0-20211209064339-2c93342bd421
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pkg/errors v0.9.1
Expand All @@ -16,7 +18,9 @@ require (
)

require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211221011931-643d94fcab96 h1:2P/dm3KbCLnRHQN/Ma50elhMx1Si9loEZe5hOrsuvuE=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211221011931-643d94fcab96/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdknSRMDrAr8mfxPCfSZolH+/qQnyQ=
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/jweny/xhttp v0.0.0-20211209064339-2c93342bd421 h1:DSMeSqAjFp6S0LGEeSUm96w853M4vTb3cKC0aM26HZc=
github.com/jweny/xhttp v0.0.0-20211209064339-2c93342bd421/go.mod h1:HjZqoChO6HBA4HcxMHJg3ifbEQuuzzzfsMdJInGtHzQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand Down Expand Up @@ -55,6 +64,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
44 changes: 39 additions & 5 deletions internal/cli/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fofax/internal/fxparser"
"fofax/internal/printer"
"fofax/internal/utils"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -81,10 +82,12 @@ type config struct {
FoFaEmail string
FoFaKey string
// 脱敏密码
FoFaKeyFake string
Proxy string
Debug bool
ConfigFile string
FoFaKeyFake string
Proxy string
Debug bool
ShowPrivacy bool
ConfigFile string
DisableUpdate bool
}
type fxconfig struct {
FxSearch string
Expand Down Expand Up @@ -131,6 +134,8 @@ func init() {
flags.StringVarP(&args.Proxy, "proxy", "p", "", "proxy for http like http://127.0.0.1:8080"),
flags.StringVar(&args.FoFaURL, "fofa-url", args.FoFaURL, "Fofa url"),
flags.BoolVar(&args.Debug, "debug", false, "Debug mode"),
flags.BoolVarP(&args.ShowPrivacy, "show-privacy", "sp", false, "Debug mode Show Privacy"),
flags.BoolVarP(&args.DisableUpdate, "disable-update", "du", false, "Close update alerts"),
)
createGroup(
flags, "filters", "FILTERS",
Expand Down Expand Up @@ -237,7 +242,10 @@ func ParseOptions() *Options {
ShowUsage()
os.Exit(0)
}

// 检查更新
if !args.DisableUpdate {
checkUpdateInfo()
}
// 检查基本信息
checkFoFaInfo()

Expand Down Expand Up @@ -308,3 +316,29 @@ func checkFoFaInfo() {
os.Exit(1)
}
}

func checkUpdateInfo() {
lastfile := filepath.Join(filepath.Dir(utils.GetDefaultConf()), ".fofax-last")
if !utils.FileExist(lastfile) {
_ = os.MkdirAll(filepath.Dir(lastfile), os.ModePerm)
ioutil.WriteFile(lastfile, []byte(strings.TrimSpace(Date)), os.ModePerm)
}
lasttime, err := ioutil.ReadFile(lastfile)
if err != nil {
printer.Error(err)
return
}
lastime, err := time.Parse("2006-01-02T15:04:05Z", strings.TrimSpace(string(lasttime)))
if err != nil {
printer.Error(err)
return
}
if -time.Until(lastime) > 24*time.Hour {
err := UpdateTips(FoFaXVersion)
if err != nil {
printer.Infof(err.Error())
}
ioutil.WriteFile(lastfile, []byte(time.Now().Format("2006-01-02T15:04:05Z")), os.ModePerm)
}

}
63 changes: 63 additions & 0 deletions internal/cli/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cli

import (
"context"
"fmt"
"fofax/internal/printer"
"github.com/google/go-github/github"
"github.com/hashicorp/go-version"
"strings"
)

func UpdateTips(tagName string) error {
if !strings.HasPrefix(tagName, "v") {
return fmt.Errorf("%s", "this file does not have a version number")
}

if strings.HasSuffix(tagName, "-next") {
printer.Debug("Self-compiled versions do not check for updates")
return nil
}

bVersion, err := version.NewVersion(tagName)
if err != nil {
return err
}

gtag, ginfo, err := getGithubVersionInfo("xiecat", "fofax")
if err != nil {
return err
}

gVersion, err := version.NewVersion(gtag)
if err != nil {
return err
}

if gVersion.GreaterThan(bVersion) {
bannerSite(fmt.Sprintf("New:\n\nVersion:%s\n\n%s\n", gtag, ginfo))
bannerSite("Please go to https://github.com/xiecat/fofax/releases to download\n\n")
}
return nil
}

func getGithubVersionInfo(owner, repo string) (tag, info string, err error) {
client := github.NewClient(nil)
opt := &github.ListOptions{Page: 1, PerPage: 1}
ctx := context.Background()

releases, rsp, err := client.Repositories.ListReleases(ctx, owner, repo, opt)

if err != nil {
fmt.Println(err)
}
if rsp.StatusCode != 200 {
printer.Infof("update status code err :%d", rsp.StatusCode)
return "", "", fmt.Errorf("update status code err :%d", rsp.StatusCode)
}
if len(releases) != 1 {
printer.Infof("releases err")
return "", "", fmt.Errorf("releases err")
}
return *releases[0].TagName, *releases[0].Body, nil
}
16 changes: 15 additions & 1 deletion internal/fofa/fofa_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"fofax/internal/cli"
"fofax/internal/printer"
"fofax/internal/utils"
"github.com/jweny/xhttp"
"math"
"net/http"
Expand Down Expand Up @@ -86,7 +87,20 @@ func (f *FoFa) fetchByFields(fields string, queryStr string) bool {

fullURL := f.buildQueryUrl(uri)
if f.option.Debug {
printer.Debug(fullURL)
if f.option.ShowPrivacy {
printer.Debug(fullURL)
} else {
hiddenUri := fmt.Sprintf(
"/api/v1/search/all?email=%s&key=%s&qbase64=%s&size=%d&page=%d&fields=%s",
"*****@*******", utils.GetHidePasswd(f.option.FoFaKey),
base64.StdEncoding.EncodeToString([]byte(queryStr)),
perPage,
f.page,
fields,
)
printer.Debug(f.buildQueryUrl(hiddenUri))
}

}
hr, _ := http.NewRequest("GET", fullURL, nil)
req := &xhttp.Request{RawRequest: hr}
Expand Down
1 change: 1 addition & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var ConfDefaultPath = []string{
"fofax.yaml",
filepath.Join(getHomedir(), "fofax.yaml"),
"/etc/fofax/fofax.yaml",
"/etc/fofax.yaml",
}

Expand Down
Loading

0 comments on commit 7fb12ab

Please sign in to comment.