-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
332 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
################################## | ||
# STEP 1 build executable binary # | ||
################################## | ||
FROM golang:alpine AS builder | ||
|
||
# Install git. | ||
# Git is required for fetching the dependencies. | ||
RUN apk update && apk add --no-cache git | ||
COPY . $GOPATH/src/github.com/scotow/burgoking | ||
|
||
# Move to command directory. | ||
WORKDIR $GOPATH/src/github.com/scotow/burgoking/cmd/web_original | ||
|
||
# Fetch dependencies. | ||
# Using go get. | ||
RUN go get -d -v | ||
|
||
# Build the binary. | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/burgoking | ||
|
||
############################## | ||
# STEP 2 build a small image # | ||
############################## | ||
FROM scratch | ||
|
||
# Copy our static executable and static files. | ||
COPY --from=builder /go/bin/burgoking /burgoking | ||
COPY cmd/web_original/static /static | ||
|
||
# Copy SSL certificates for HTTPS connections. | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
# Copy locale data. | ||
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip / | ||
ENV ZONEINFO=/zoneinfo.zip | ||
|
||
# Run the hello binary. | ||
ENTRYPOINT ["/burgoking"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/scotow/burgoking" | ||
"github.com/sirupsen/logrus" | ||
"github.com/tomasen/realip" | ||
) | ||
|
||
var ( | ||
publicPool *burgoking.Pool | ||
privatePool *burgoking.Pool | ||
) | ||
|
||
var ( | ||
port = flag.Int("p", 8080, "listening port") | ||
contact = flag.String("c", "", "contact address on error") | ||
|
||
publicSize = flag.Int("n", 3, "public code pool size") | ||
publicExpiration = flag.Duration("d", 24*time.Hour, "public code expiration") | ||
publicRetry = flag.Duration("r", 30*time.Second, "public code regeneration interval") | ||
|
||
privateDirectKey = flag.String("k", "", "authorization token for private and direct code (disable if empty)") | ||
privateSize = flag.Int("N", 1, "private code pool size") | ||
privateExpiration = flag.Duration("D", 24*time.Hour, "private code expiration") | ||
privateRetry = flag.Duration("R", 30*time.Second, "private code regeneration interval") | ||
) | ||
|
||
func handleCodeRequest(p *burgoking.Pool, t string, w http.ResponseWriter, r *http.Request) { | ||
codeC, cancelC := make(chan string), make(chan struct{}) | ||
go p.GetCode(codeC, cancelC) | ||
|
||
select { | ||
case code := <-codeC: | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "text/plain") | ||
_, _ = w.Write([]byte(code)) | ||
logrus.WithFields(logrus.Fields{"code": code, "ip": realip.FromRequest(r), "type": t}).Info("Code used by user.") | ||
case <-r.Context().Done(): | ||
cancelC <- struct{}{} | ||
} | ||
} | ||
|
||
func handlePublic(w http.ResponseWriter, r *http.Request) { | ||
handleCodeRequest(publicPool, "public", w, r) | ||
} | ||
|
||
func handlePrivate(w http.ResponseWriter, r *http.Request) { | ||
if r.Header.Get("Authorization") != *privateDirectKey { | ||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden) | ||
return | ||
} | ||
|
||
handleCodeRequest(privatePool, "private", w, r) | ||
} | ||
|
||
func handleDirect(w http.ResponseWriter, r *http.Request) { | ||
if r.Header.Get("Authorization") != *privateDirectKey { | ||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden) | ||
return | ||
} | ||
|
||
code, err := burgoking.GenerateCode(nil) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
_, _ = w.Write([]byte(code)) | ||
logrus.WithFields(logrus.Fields{"code": code, "ip": r.RemoteAddr, "type": "direct"}).Info("Code used by user.") | ||
} | ||
|
||
func handleContact(w http.ResponseWriter, _ *http.Request) { | ||
_, _ = w.Write([]byte(*contact)) | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
// Static files. | ||
http.Handle("/", http.FileServer(http.Dir("static"))) | ||
|
||
// Public pool. | ||
pool, err := burgoking.NewPool(*publicSize, *publicExpiration, *publicRetry) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
return | ||
} | ||
publicPool = pool | ||
|
||
http.HandleFunc("/code", handlePublic) | ||
|
||
// Private pool. | ||
if *privateDirectKey != "" { | ||
pool, err = burgoking.NewPool(*privateSize, *privateExpiration, *privateRetry) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
return | ||
} | ||
privatePool = pool | ||
|
||
http.HandleFunc("/private", handlePrivate) | ||
http.HandleFunc("/direct", handleDirect) | ||
|
||
logrus.Info("Private and direct code generation activated.") | ||
} | ||
|
||
// Contact address. | ||
if *contact != "" { | ||
http.HandleFunc("/contact", handleContact) | ||
} | ||
|
||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<browserconfig> | ||
<msapplication> | ||
<tile> | ||
<square150x150logo src="/icons/mstile-150x150.png"/> | ||
<TileColor>#da532c</TileColor> | ||
</tile> | ||
</msapplication> | ||
</browserconfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
@import url(https://fonts.googleapis.com/css?family=Lobster); | ||
|
||
html, body { | ||
height: 100%; | ||
} | ||
|
||
html { | ||
font-size: 0; | ||
font-family: 'Lobster', sans-serif; | ||
color: #fff; | ||
background: #131313; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
padding: 0; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
body::after { | ||
content: ''; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 4px; | ||
background: #15b154; | ||
} | ||
|
||
.video { | ||
flex: 0; | ||
width: 80vw; | ||
max-width: 300px; | ||
border-radius: 35%; | ||
} | ||
|
||
.label { | ||
margin-top: 20px; | ||
text-align: center; | ||
color: white; | ||
font-size: 36px; | ||
font-family: 'Lobster', sans-serif; | ||
} | ||
|
||
.label.done { | ||
margin-top: 18px; | ||
font-size: 44px; | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.