From cff4938223c41448571f5e1ae695734ea7ecad88 Mon Sep 17 00:00:00 2001 From: sandeep <8293321+ehsandeep@users.noreply.github.com> Date: Mon, 20 Mar 2023 19:45:54 +0530 Subject: [PATCH 1/3] workflow update --- .github/workflows/build-test.yml | 7 +++++-- .github/workflows/codeql-analysis.yml | 3 +++ .github/workflows/dockerhub-push.yml | 6 ++++-- .github/workflows/lint-test.yml | 7 +++++-- .github/workflows/release-binary.yml | 8 ++++++-- .goreleaser.yml | 28 ++++++++++++++++++++------- go.mod | 2 +- internal/runner/banner.go | 7 ++----- 8 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 69a6eea..c9baa4e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,7 +1,10 @@ name: 🔨 Build Test + on: - push: pull_request: + paths: + - '**.go' + - '**.mod' workflow_dispatch: @@ -13,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.18 + go-version: 1.19 - name: Check out code uses: actions/checkout@v3 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9f533f8..2863865 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -3,6 +3,9 @@ name: 🚨 CodeQL Analysis on: workflow_dispatch: pull_request: + paths: + - '**.go' + - '**.mod' branches: - dev diff --git a/.github/workflows/dockerhub-push.yml b/.github/workflows/dockerhub-push.yml index 829fefb..d141bff 100644 --- a/.github/workflows/dockerhub-push.yml +++ b/.github/workflows/dockerhub-push.yml @@ -1,8 +1,10 @@ name: 🌥 Docker Push on: - release: - types: [published] + workflow_run: + workflows: ["🎉 Release Binary"] + types: + - completed workflow_dispatch: jobs: diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 2a22228..7f4c078 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -1,7 +1,10 @@ name: 🙏🏻 Lint Test + on: - push: pull_request: + paths: + - '**.go' + - '**.mod' workflow_dispatch: jobs: @@ -12,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.18 + go-version: 1.19 - name: Checkout code uses: actions/checkout@v3 - name: Run golangci-lint diff --git a/.github/workflows/release-binary.yml b/.github/workflows/release-binary.yml index 602f907..8581b0b 100644 --- a/.github/workflows/release-binary.yml +++ b/.github/workflows/release-binary.yml @@ -1,6 +1,7 @@ name: 🎉 Release Binary + on: - create: + push: tags: - v* workflow_dispatch: @@ -12,7 +13,7 @@ jobs: - name: "Set up Go" uses: actions/setup-go@v4 with: - go-version: 1.18 + go-version: 1.19 - name: "Check out code" uses: actions/checkout@v3 with: @@ -21,6 +22,9 @@ jobs: uses: goreleaser/goreleaser-action@v4 env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + SLACK_WEBHOOK: "${{ secrets.RELEASE_SLACK_WEBHOOK }}" + DISCORD_WEBHOOK_ID: "${{ secrets.DISCORD_WEBHOOK_ID }}" + DISCORD_WEBHOOK_TOKEN: "${{ secrets.DISCORD_WEBHOOK_TOKEN }}" with: args: "release --rm-dist" version: latest diff --git a/.goreleaser.yml b/.goreleaser.yml index f6cb1e2..e0a4795 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,7 @@ +before: + hooks: + - go mod tidy + builds: - binary: simplehttpserver main: cmd/simplehttpserver/simplehttpserver.go @@ -12,10 +16,20 @@ builds: - arm64 archives: - - id: tgz - format: tar.gz - replacements: - darwin: macOS - format_overrides: - - goos: windows - format: zip \ No newline at end of file +- format: zip + replacements: + darwin: macOS + +checksum: + algorithm: sha256 + +announce: + slack: + enabled: true + channel: '#release' + username: GoReleaser + message_template: 'New Release: {{ .ProjectName }} {{ .Tag }} is published! Check it out at {{ .ReleaseURL }}' + + discord: + enabled: true + message_template: '**New Release: {{ .ProjectName }} {{.Tag}}** is published! Check it out at {{ .ReleaseURL }}' \ No newline at end of file diff --git a/go.mod b/go.mod index fd4d53b..01a2ea1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/projectdiscovery/simplehttpserver -go 1.17 +go 1.19 require ( github.com/fsnotify/fsnotify v1.6.0 diff --git a/internal/runner/banner.go b/internal/runner/banner.go index 24febe0..ed4193f 100644 --- a/internal/runner/banner.go +++ b/internal/runner/banner.go @@ -8,17 +8,14 @@ const banner = ` \__ \/ / __ -__ \/ __ \/ / _ \/ /_/ / / / / / / /_/ / ___/ _ \/ ___/ | / / _ \/ ___/ ___/ / / / / / / / /_/ / / __/ __ / / / / / / ____(__ ) __/ / | |/ / __/ / /____/_/_/ /_/ /_/ .___/_/\___/_/ /_/ /_/ /_/ /_/ /____/\___/_/ |___/\___/_/ - /_/ - v0.0.5 + /_/ - v0.0.6 ` // Version is the current version -const Version = `0.0.5` +const Version = `0.0.6` // showBanner is used to show the banner to the user func showBanner() { gologger.Print().Msgf("%s\n", banner) gologger.Print().Msgf("\t\tprojectdiscovery.io\n\n") - - gologger.Print().Msgf("Use with caution. You are responsible for your actions\n") - gologger.Print().Msgf("Developers assume no liability and are not responsible for any misuse or damage.\n") } From 9ba0eb97fd757b5de37c2317d4739d7417e19179 Mon Sep 17 00:00:00 2001 From: sandeep <8293321+ehsandeep@users.noreply.github.com> Date: Mon, 20 Mar 2023 19:49:28 +0530 Subject: [PATCH 2/3] readme update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 769daa9..709e1ac 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ This will display help for the tool. Here are all the switches it supports. | `-cert` | HTTPS/TLS certificate (self generated if not specified) | `simplehttpserver -cert cert.pem` | | `-key` | HTTPS/TLS certificate private key | `simplehttpserver -key cert.key` | | `-domain` | Domain name to use for the self-generated certificate | `simplehttpserver -domain projectdiscovery.io` | +| `-cors` | Enable cross-origin resource sharing (CORS) | `simplehttpserver -cors` | | `-basic-auth` | Basic auth (username:password) | `simplehttpserver -basic-auth user:password` | | `-realm` | Basic auth message | `simplehttpserver -realm "insert the credentials"` | | `-version` | Show version | `simplehttpserver -version` | From a58e3a50663fe32441e86c823661dc7996f7b76a Mon Sep 17 00:00:00 2001 From: Ramana Reddy Date: Mon, 20 Mar 2023 20:20:27 +0530 Subject: [PATCH 3/3] use os and io pkg to read/write file --- pkg/httpserver/uploadlayer.go | 6 +++--- pkg/tcpserver/tcpserver.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/httpserver/uploadlayer.go b/pkg/httpserver/uploadlayer.go index 4064714..571d3c1 100644 --- a/pkg/httpserver/uploadlayer.go +++ b/pkg/httpserver/uploadlayer.go @@ -2,7 +2,7 @@ package httpserver import ( "errors" - "io/ioutil" + "io" "net/http" "os" "path" @@ -55,7 +55,7 @@ func (t *HTTPServer) uploadlayer(handler http.Handler) http.Handler { r.Body = http.MaxBytesReader(w, r.Body, maxFileSize) } - data, err = ioutil.ReadAll(r.Body) + data, err = io.ReadAll(r.Body) if err != nil { gologger.Print().Msgf("%s\n", err) w.WriteHeader(http.StatusInternalServerError) @@ -95,5 +95,5 @@ func handleUpload(base, file string, data []byte) error { return errors.New("invalid path") } - return ioutil.WriteFile(trustedPath, data, 0655) + return os.WriteFile(trustedPath, data, 0655) } diff --git a/pkg/tcpserver/tcpserver.go b/pkg/tcpserver/tcpserver.go index cbdd407..3b996f5 100644 --- a/pkg/tcpserver/tcpserver.go +++ b/pkg/tcpserver/tcpserver.go @@ -4,7 +4,7 @@ import ( "context" "crypto/tls" "errors" - "io/ioutil" + "os" "net" "sync" "time" @@ -146,7 +146,7 @@ func (t *TCPServer) Close() error { // LoadTemplate from yaml func (t *TCPServer) LoadTemplate(templatePath string) error { var config RulesConfiguration - yamlFile, err := ioutil.ReadFile(templatePath) + yamlFile, err := os.ReadFile(templatePath) if err != nil { return err }