mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-05-03 11:31:35 -05:00
Add log for limited users
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/common"
|
||||
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
flagMode = flag.String("mode", "", "encrypt | decrypt")
|
||||
envFileFlag = flag.String("env", "", "Path to .env file, 'stdin' or empty")
|
||||
idFlag = flag.String("id", "", "Actual ID")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
env, err := common.NewEnvMap(*envFileFlag)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
}
|
||||
cfg := config.NewEnvConfig(env.Get)
|
||||
|
||||
hasher := common.NewIDHasher(cfg.Get(common.IDHasherSaltKey))
|
||||
|
||||
switch *flagMode {
|
||||
case "encrypt":
|
||||
id, err := strconv.Atoi(*idFlag)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error deserializing ID: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
value := hasher.Encrypt(id)
|
||||
fmt.Print(value)
|
||||
case "decrypt":
|
||||
id, err := hasher.Decrypt(*idFlag)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error decrypting ID: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Print(id)
|
||||
}
|
||||
}
|
||||
@@ -369,6 +369,7 @@ func (am *AuthMiddleware) APIKey(keyFunc func(r *http.Request) string) func(http
|
||||
|
||||
// if user is not an active subscriber, their properties and orgs might still exist but should not allow API
|
||||
if softRestriction, err := am.Limiter.Evaluate(ctx, apiKey.UserID.Int32); (err == nil) && !softRestriction {
|
||||
slog.WarnContext(ctx, "User is limited", "userID", apiKey.UserID.Int32)
|
||||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user