-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: [A] Added instructions for GeoIP2 settings (commit b2fd881b75) [U] Mitigated CVE-2023-45288 by updating golang.org/x/net. (commit 2cbef54263) [U] Use GeoIP2 instead of qqWry (commit daee499a4c)
- Loading branch information
1 parent
ef77fe0
commit 1ea3aee
Showing
28 changed files
with
168 additions
and
332 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ | |
/db-data/* | ||
|
||
# Go statik | ||
/statik/statik.go | ||
/fs/statik.go |
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
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 |
---|---|---|
@@ -1,61 +1,17 @@ | ||
package ip2location | ||
|
||
import ( | ||
"bytes" | ||
"compress/zlib" | ||
"encoding/binary" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
// @ref https://zhangzifan.com/update-qqwry-dat.html | ||
|
||
func getKey() (uint32, error) { | ||
resp, err := http.Get("http://update.cz88.net/ip/copywrite.rar") | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer func(Body io.ReadCloser) { | ||
_ = Body.Close() | ||
}(resp.Body) | ||
|
||
if body, err := io.ReadAll(resp.Body); err != nil { | ||
return 0, err | ||
} else { | ||
// @see https://stackoverflow.com/questions/34078427/how-to-read-packed-binary-data-in-go | ||
return binary.LittleEndian.Uint32(body[5*4:]), nil | ||
} | ||
} | ||
|
||
func GetOnline() ([]byte, error) { | ||
resp, err := http.Get("http://update.cz88.net/ip/qqwry.rar") | ||
resp, err := http.Get("https://git.io/GeoLite2-City.mmdb") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func(Body io.ReadCloser) { | ||
_ = Body.Close() | ||
}(resp.Body) | ||
|
||
if body, err := io.ReadAll(resp.Body); err != nil { | ||
return nil, err | ||
} else { | ||
if key, err := getKey(); err != nil { | ||
return nil, err | ||
} else { | ||
for i := 0; i < 0x200; i++ { | ||
key = key * 0x805 | ||
key++ | ||
key = key & 0xff | ||
|
||
body[i] = byte(uint32(body[i]) ^ key) | ||
} | ||
|
||
reader, err := zlib.NewReader(bytes.NewReader(body)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return io.ReadAll(reader) | ||
} | ||
} | ||
return io.ReadAll(resp.Body) | ||
} |
Oops, something went wrong.