-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
134 lines (114 loc) · 3.14 KB
/
utils.go
File metadata and controls
134 lines (114 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"encoding/json"
"fmt"
"io/fs"
"log"
"net/http"
"path/filepath"
"plugin"
"strings"
country "github.com/mikekonan/go-countries"
"github.com/techgarage-ir/IP-Hub/config"
"github.com/techgarage-ir/IP-Hub/models"
"github.com/techgarage-ir/IP-Hub/pluginBase"
)
func lookup(countryCode string) pluginBase.Lookup {
url := fmt.Sprintf("%s%v", config.LookupEndpoint, countryCode)
fmt.Println(url)
res, err := http.Get(url)
if err != nil {
fmt.Println(err)
}
defer res.Body.Close()
var response models.RipeResult
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
fmt.Println(err)
}
countryName, ok := country.ByAlpha2Code(country.Alpha2Code(countryCode))
result := pluginBase.Lookup{
UpdatedAt: response.Data.QueryTime,
CountryCode: countryCode,
ASN: response.Data.Resources.Asn,
IPv4: response.Data.Resources.Ipv4,
IPv6: response.Data.Resources.Ipv6,
}
if ok {
result.CountryName = countryName.NameStr()
} else {
result.CountryName = countryCode
}
return result
}
func arrayToString(array []string) string {
return strings.Join(array, " ")
}
func WalkDir(root string, ext string) ([]string, error) {
var files []string
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
}
if strings.HasSuffix(path, "."+ext) {
files = append(files, path)
return nil
}
return nil
})
return files, err
}
func loadPlugins() {
pluginFiles, err := WalkDir("./plugins", "so")
if err != nil {
fmt.Printf("Error walking plugin directory: %v\n", err)
return
}
for _, mod := range pluginFiles {
fmt.Printf("Loading plugin: %s\n", mod)
plug, err := plugin.Open(mod)
if err != nil {
fmt.Printf("Error opening plugin %s: %v\n", mod, err)
continue
}
symPlugin, err := plug.Lookup("Plugin")
if err != nil {
fmt.Printf("Error looking up 'Plugin' symbol in %s: %v\n", mod, err)
continue
}
// Type assert to Plugin interface instead of PluginBase struct
if p, ok := symPlugin.(*pluginBase.Plugin); ok {
plugins = append(plugins, *p)
} else {
fmt.Printf("Plugin %s does not implement the Plugin interface. Got type: %T\n", mod, symPlugin)
}
}
if len(plugins) == 0 {
fmt.Println("No plugins were loaded successfully")
} else {
fmt.Printf("Successfully loaded %d plugins\n", len(plugins))
}
}
func ValidateCaptcha(turnstile string) bool {
client := &http.Client{}
var data = strings.NewReader(`secret=0x4AAAAAABcvDFZIP0YMm9YRGQJC8wct55Q&response=` + turnstile)
req, err := http.NewRequest("POST", "https://challenges.cloudflare.com/turnstile/v0/siteverify", data)
if err != nil {
log.Fatal(err)
return false
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
return false
}
defer resp.Body.Close()
var response models.TurnstileResponse
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
fmt.Println(err)
return false
}
return response.Success
}