Skip to content

Commit

Permalink
- Now supporting go mod (Yeay)
Browse files Browse the repository at this point in the history
- Pastedb is now Paste.me
- Added new API changes
- Small improvements
  • Loading branch information
0x111 committed Jan 3, 2020
1 parent abd8ac1 commit b840e55
Show file tree
Hide file tree
Showing 31 changed files with 115 additions and 5,647 deletions.
39 changes: 0 additions & 39 deletions Gopkg.lock

This file was deleted.

38 changes: 0 additions & 38 deletions Gopkg.toml

This file was deleted.

34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
binary_name = pasteme-cli

.PHONY: all
all: linux_amd64 darwin_amd64 windows_amd64 checksums

.PHONY: linux_amd64
linux_amd64:
GOOS=linux GOARCH=amd64 go build -v -a -gcflags=-trimpath=$$PWD -asmflags=-trimpath=$$PWD -o build/$(binary_name)-linux-amd64

.PHONY: linux_i386
linux_i386:
GOOS=linux GOARCH=386 go build -v -a -gcflags=-trimpath=$$PWD -asmflags=-trimpath=$$PWD -o build/$(binary_name)-linux-i386

.PHONY: darwin_amd64
darwin_amd64:
GOOS=darwin GOARCH=amd64 go build -v -a -gcflags=-trimpath=$$PWD -asmflags=-trimpath=$$PWD -o build/$(binary_name)-darwin-amd64

.PHONY: darwin_i386
darwin_i386:
GOOS=darwin GOARCH=386 go build -v -a -gcflags=-trimpath=$$PWD -asmflags=-trimpath=$$PWD -o build/$(binary_name)-darwin-i386

.PHONY: windows_amd64
windows_amd64:
CC=/usr/local/bin/x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -v -a -gcflags=-trimpath=$$PWD -asmflags=-trimpath=$$PWD -o build/$(binary_name)-windows-amd64.exe

.PHONY: windows_i386
windows_i386:
CC=/usr/local/bin/x86_64-w64-mingw32-gcc GOOS=windows GOARCH=386 go build -v -a -gcflags=-trimpath=$$PWD -asmflags=-trimpath=$$PWD -o build/$(binary_name)-windows-i386.exe

.PHONY: checksums
checksums:
shasum -a 256 build/* > build/checksum.txt

test:
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/0x111/pastedb-cli

go 1.12

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/stretchr/testify v1.2.1
github.com/urfave/cli v1.20.0
github.com/urfave/cli/v2 v2.1.1
golang.org/x/crypto v0.0.0-20180127211104-1875d0a70c90
)
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/crypto v0.0.0-20180127211104-1875d0a70c90 h1:DNyuYmiOz3AH2rGH1n4YsZUvxVhkeMvSs8s31jiWpm0=
golang.org/x/crypto v0.0.0-20180127211104-1875d0a70c90/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
71 changes: 49 additions & 22 deletions pastedb_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/pbkdf2"
)

Expand All @@ -33,48 +34,67 @@ type Paste struct {
Salt string `json:"salt"`
} `json:"body"`
} `json:"paste"`
SourceCode bool `json:"sourceCode"`
SelfDestruct bool `json:"selfDestruct"`
ExpiresMinutes int64 `json:"expiresMinutes"`
Files []Files `bson:"files" json:"files"`
SourceCode bool `json:"sourceCode"`
SelfDestruct bool `json:"selfDestruct"`
ExpiresMinutes int64 `json:"expiresMinutes"`
}

type Files struct {
Name struct {
Data string `bson:"data" json:"data"`
Vector string `bson:"iv" json:"iv"`
Salt string `bson:"salt" json:"salt"`
} `json:"name"`
Content struct {
Data string `bson:"data" json:"data"`
Vector string `bson:"iv" json:"iv"`
Salt string `bson:"salt" json:"salt"`
} `json:"content"`
}

type PasteSuccess struct {
Msg string `json:"msg"`
Uuid string `json:"uuid"`
Msg string `json:"msg"`
Paste struct {
Uuid string `json:"uuid"`
} `json:"paste"`
}

func main() {
app := cli.NewApp()
app.Name = "Paste.me"
app.Version = "v0.0.1"
app.Version = "v0.0.2"
app.Usage = "Share your pastes securely"

app.Flags = []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "name",
Usage: "Insert the name of the paste here.",
},
cli.StringFlag{
&cli.StringFlag{
Name: "body",
Usage: "Here you can insert the paste body or send it through cli.",
},
cli.Int64Flag{
&cli.Int64Flag{
Name: "expire",
Usage: "Here you will be able to set an expiration time for your pastes. The expiration time should be defined in minutes. Allowed values for the time being: 5,10,60,1440,10080,43800.",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "destroy",
Usage: "With this flag, you are posting the paste with a 'Self Destruct' flag. The link will work only once.",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "source",
Usage: "With this flag, you are posting a paste which is some kind of source code. Syntax highlighting will be applied.",
},
}

app.Action = Action

app.Run(os.Args)
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}

func Action(c *cli.Context) error {
Expand All @@ -91,11 +111,9 @@ func Action(c *cli.Context) error {
return errors.New("paste_name_error")
}

//var r io.Reader
var terminalText string
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
//r = strings.NewReader(string(os.Stdin))
terminalText, err = ReadDataFromTerminal(os.Stdin)
if err != nil {
return err
Expand All @@ -108,7 +126,6 @@ func Action(c *cli.Context) error {
}
}


if len(terminalText) > 0 {
pasteText = terminalText
} else {
Expand Down Expand Up @@ -145,31 +162,41 @@ func Action(c *cli.Context) error {
paste.Paste.Body.Salt = splittedEncryptData[0]
paste.SourceCode = sourceCode
paste.SelfDestruct = destroy
// Note: The cli client does not support sending files yet!
paste.Files = []Files{}

if !destroy {
paste.ExpiresMinutes = minutes
}

jsonValue, _ := json.Marshal(paste)
//fmt.Println(string(jsonValue))
resp, err := http.Post("https://api.paste.me/api/paste/new", "application/json", bytes.NewBuffer(jsonValue))
//resp.Body.Read(res)

req, err := http.NewRequest("POST", "https://api.paste.me/api/paste/new", bytes.NewBuffer(jsonValue))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)

if err != nil {
log.Fatal(err)
}

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)
resp.Body.Close()

if err != nil {
return cli.NewExitError("There was some problem while sending the paste data. Please try again later or contact the site administrator.", 15)
}

if resp.StatusCode == 200 {
res := PasteSuccess{}
err = json.Unmarshal([]byte(bodyString), &res)
err = json.Unmarshal(bodyBytes, &res)

if err != nil {
return cli.NewExitError("We received an invalid response from the server. Please contact the site administrator.", 16)
}

msg := `Paste added successfully!
Share this url to your friends: https://paste.me/paste/` + res.Uuid + `#` + passPhrase
Share this url to your friends: https://paste.me/paste/` + res.Paste.Uuid + `#` + passPhrase
fmt.Println(msg)
return nil
} else {
Expand Down
2 changes: 0 additions & 2 deletions vendor/github.com/urfave/cli/.flake8

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/urfave/cli/.gitignore

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/github.com/urfave/cli/.travis.yml

This file was deleted.

Loading

0 comments on commit b840e55

Please sign in to comment.