diff --git a/README.md b/README.md
index 27a5ffc..9d62782 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
# [cowyo.com](http://cowyo.com/)
-[![Version 0.94](https://img.shields.io/badge/version-0.94-brightgreen.svg)]() [![Go Report Card](https://goreportcard.com/badge/github.com/schollz/cowyo)](https://goreportcard.com/report/github.com/schollz/cowyo) [![Join the chat at https://gitter.im/schollz/cowyo](https://badges.gitter.im/schollz/cowyo.svg)](https://gitter.im/schollz/cowyo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+[![Version 0.95](https://img.shields.io/badge/version-0.94-brightgreen.svg)]() [![Go Report Card](https://goreportcard.com/badge/github.com/schollz/cowyo)](https://goreportcard.com/report/github.com/schollz/cowyo) [![Join the chat at https://gitter.im/schollz/cowyo](https://badges.gitter.im/schollz/cowyo.svg)](https://gitter.im/schollz/cowyo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This is a self-contained notepad webserver that makes sharing easy and _fast_. The most important feature here is *simplicity*. There are many other features as well including versioning, page locking, self-destructing messages, encryption, math support, and listifying. Read on to learn more about the features.
@@ -44,6 +44,23 @@ This is a self-contained notepad webserver that makes sharing easy and _fast_. T
+**CLI support**. Want to upload/download from a server? Its super easy. Upload/download files like this:
+```bash
+$ echo "Hello, world!" > hi.txt
+$ curl --upload-file hi.txt cowyo.com
+ File uploaded to http://cowyo.com/hi.txt
+$ curl cowyo.com/test.txt
+ Hello, world!
+```
+or just skip the file-creation step,
+```bash
+$ echo "Wow, so easy" | curl --upload-file "-" cowyo.com
+ File uploaded to http://cowyo.com/CautiousCommonLoon
+$ curl cowyo.com/CautiousCommonLoon
+ Wow, so easy
+```
+
+
**Keyboard Shortcuts**. Quickly transition between Edit/View/List by using `Ctl+Shift+E` to Edit, `Ctl+Shift+Z` to View, and `Ctl+Shift+L` to Listify.
diff --git a/main.go b/main.go
index cdcebb3..6663546 100644
--- a/main.go
+++ b/main.go
@@ -35,10 +35,8 @@ var RuntimeArgs struct {
}
var VersionNum string
-const _24K = (1 << 20) * 24
-
func main() {
- VersionNum = "0.94"
+ VersionNum = "0.95"
// _, executableFile, _, _ := runtime.Caller(0) // get full path of this file
cwd, _ := os.Getwd()
databaseFile := path.Join(cwd, "data.db")
@@ -105,6 +103,7 @@ Options:`)
r.HEAD("/", func(c *gin.Context) { c.Status(200) })
r.GET("/:title", editNote)
r.PUT("/:title", putFile)
+ r.PUT("/", putFile)
r.GET("/:title/*option", everythingElse)
r.POST("/:title/*option", encryptionRoute)
r.DELETE("/listitem", deleteListItem)
diff --git a/ratelimiter.go b/ratelimiter.go
new file mode 100755
index 0000000..a01e268
--- /dev/null
+++ b/ratelimiter.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "fmt"
+ "time"
+)
+
+var bannedIPs []string
+
+func init() {
+ go clearBannedIPs()
+}
+
+func clearBannedIPs() {
+ for {
+ fmt.Println("CLEARING IPS!!")
+ bannedIPs = []string{}
+ time.Sleep(3 * time.Minute)
+ }
+}
+
+func isIPBanned(ip string) bool {
+ if stringInSlice(ip, bannedIPs) {
+ return true
+ } else {
+ bannedIPs = append(bannedIPs, ip)
+ return false
+ }
+}
diff --git a/routes.go b/routes.go
index 71153fd..6b44aa3 100644
--- a/routes.go
+++ b/routes.go
@@ -21,8 +21,17 @@ import (
"github.com/russross/blackfriday"
)
+const _24K = (1 << 20) * 24
+
func putFile(c *gin.Context) {
+ if isIPBanned(c.ClientIP()) {
+ c.Data(200, "text/plain", []byte("You are rate limited to 20 requests/hour."))
+ return
+ }
filename := c.Param("title")
+ if len(filename) == 0 {
+ filename = randomAlliterateCombo()
+ }
contentLength := c.Request.ContentLength
var reader io.Reader
reader = c.Request.Body
@@ -68,7 +77,6 @@ func putFile(c *gin.Context) {
var p WikiData
p.load(strings.ToLower(filename))
p.save(buf.String())
- fmt.Println(c.ClientIP())
c.Data(200, "text/plain", []byte("File uploaded to http://"+RuntimeArgs.ExternalIP+"/"+filename))
}