commit 2f6ea3da66906333528502103d6ed824af1b5c6a Author: Moony Date: Wed Jun 28 22:12:59 2023 -0400 Initial commit of v0.0.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..69bd279 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +openai_keys.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..19f42e1 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Skeleton Key + +Verifies a list of OpenAI keys for validity. + + + + +## Authors + +- [@deltreed](https://www.git.tcp.direct/moony) + + +## Installation + +Install my-project with npm + +```bash + go install https://git.tcp.direct/moony/skeletonkey.git + go mod tidy + go build . +``` + +## Usage/Examples + +```bash +./skeletonkey input_file.txt +``` + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..01c7d98 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module main + +go 1.20 + +require github.com/daviddengcn/go-colortext v1.0.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..861c058 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE= +github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c= +github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho= +github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A= +github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE= +github.com/golangplus/testing v1.0.0 h1:+ZeeiKZENNOMkTTELoSySazi+XaEhVO0mb+eanrSEUQ= +github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..dd91085 --- /dev/null +++ b/main.go @@ -0,0 +1,65 @@ +// Package main provides a simple tool to check if a list of OpenAI keys are valid. +package main + +import ( + "bufio" + "fmt" + "net/http" + "os" + "sync" + "time" + + ct "github.com/daviddengcn/go-colortext" +) + +const openaiEndpoint = "https://api.openai.com/v1/engines/davinci-codex/completions" + +var ( + valid = 0 + invalid = 0 + total = 0 + date string +) + +// main is the entrypoint for the program. +func main() { + keysFile, err := os.Open(os.Args[1]) + if err != nil { + fmt.Println("Error opening keys file:", err) + return + } + defer keysFile.Close() + + var wg sync.WaitGroup + scanner := bufio.NewScanner(keysFile) + for scanner.Scan() { + date = time.Now().Format("15:04:05") + total++ + key := scanner.Text() + wg.Add(1) + go func(k string) { + defer wg.Done() + client := &http.Client{} + req, err := http.NewRequest("POST", openaiEndpoint, nil) + if err != nil { + fmt.Println("Error creating request:", err) + return + } + req.Header.Set("Authorization", "Bearer "+k) + res, err := client.Do(req) + if err != nil || res.StatusCode == 401 { + invalid++ + ct.ChangeColor(ct.Red, false, ct.None, false) + fmt.Printf("[%d] [%s] [%d] [BAD]: %s\n", total, date, valid, k) + return + } + valid++ + ct.ChangeColor(ct.Green, false, ct.None, false) + fmt.Printf("[%d] [%s] [%d] [GOOD]: %s\n", total, date, valid, k) + }(key) + } + wg.Wait() + + ct.ChangeColor(ct.Blue, false, ct.None, false) + fmt.Printf("[%d] [%s] [COMPLETE]: Valid: (%d) - Invalid: (%d)\n", total, date, valid, invalid) +}