Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce3b5193ac | ||
|
|
76d2da9199 |
@@ -2,11 +2,12 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Proxy(wr http.ResponseWriter, req *http.Request, rawUrl string) error {
|
||||
@@ -20,7 +21,7 @@ func Proxy(wr http.ResponseWriter, req *http.Request, rawUrl string) error {
|
||||
u, err := url.Parse(rawUrl)
|
||||
if err != nil {
|
||||
http.Error(wr, "Server Error", http.StatusInternalServerError)
|
||||
log.Println("ServeHTTP:", err)
|
||||
log.Warnln("ServeHTTP:", err)
|
||||
return err
|
||||
}
|
||||
req.URL.Host = u.Host
|
||||
@@ -29,7 +30,7 @@ func Proxy(wr http.ResponseWriter, req *http.Request, rawUrl string) error {
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
http.Error(wr, "Server Error", http.StatusInternalServerError)
|
||||
log.Println("ServeHTTP:", err)
|
||||
log.Warnln("ServeHTTP:", err)
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -25,28 +25,30 @@ func (w LndHub) Handle(writer http.ResponseWriter, request *http.Request) {
|
||||
|
||||
// check if the user is banned
|
||||
if auth != "" {
|
||||
username, password, ok := parseBearerAuth(auth)
|
||||
_, password, ok := parseBearerAuth(auth)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
log.Debugf("[LNDHUB] %s, %s", username, password)
|
||||
// first we make sure that the password is not already "banned_"
|
||||
if strings.Contains(password, "_") || strings.HasPrefix(password, "banned_") {
|
||||
log.Warnf("[LNDHUB] Banned user. Not forwarding request")
|
||||
log.Warnf("[LNDHUB] Banned user %s. Not forwarding request", password)
|
||||
return
|
||||
}
|
||||
// then we check whether the "normal" password provided is in the database (it should be not if the user is banned)
|
||||
user := &lnbits.User{}
|
||||
tx := w.database.Where("wallet_adminkey = ? COLLATE NOCASE", password).First(user)
|
||||
if tx.Error != nil {
|
||||
log.Warnf("[LNDHUB] wallet admin key (%s) not found: %v", password, tx.Error)
|
||||
log.Warnf("[LNDHUB] Could not get wallet admin key %s: %v", password, tx.Error)
|
||||
return
|
||||
}
|
||||
log.Debugf("[LNDHUB] User: %s", telegram.GetUserStr(user.Telegram))
|
||||
}
|
||||
// if not, proxy the request
|
||||
api.Proxy(writer, request, internal.Configuration.Lnbits.Url)
|
||||
}
|
||||
|
||||
// parseBasicAuth parses an HTTP Basic Authentication string.
|
||||
// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true).
|
||||
// parseBearerAuth parses an HTTP Basic Authentication string.
|
||||
// "Bearer QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true).
|
||||
func parseBearerAuth(auth string) (username, password string, ok bool) {
|
||||
const prefix = "Bearer "
|
||||
// Case insensitive prefix match. See Issue 22736.
|
||||
|
||||
@@ -101,7 +101,7 @@ func (bot *TipBot) invoiceHandler(ctx context.Context, m *tb.Message) {
|
||||
}
|
||||
|
||||
creatingMsg := bot.trySendMessage(m.Sender, Translate(ctx, "lnurlGettingUserMessage"))
|
||||
log.Infof("[/invoice] Creating invoice for %s of %d sat.", userStr, amount)
|
||||
log.Debugf("[/invoice] Creating invoice for %s of %d sat.", userStr, amount)
|
||||
invoice, err := bot.createInvoiceWithEvent(ctx, user, amount, memo, InvoiceCallbackGeneric, "")
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("[/invoice] Could not create an invoice: %s", err.Error())
|
||||
|
||||
@@ -118,7 +118,7 @@ func (bot *TipBot) UserGetAnonLightningAddress(user *lnbits.User) (string, error
|
||||
}
|
||||
|
||||
func UserGetLNURL(user *lnbits.User) (string, error) {
|
||||
name := fmt.Sprint(user.AnonID)
|
||||
name := fmt.Sprint(user.AnonIDSha256)
|
||||
callback := fmt.Sprintf("%s/.well-known/lnurlp/%s", internal.Configuration.Bot.LNURLHostName, name)
|
||||
log.Debugf("[lnurlReceiveHandler] %s's LNURL: %s", GetUserStr(user.Telegram), callback)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user