-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from essentialkaos/develop
Version 13.1.0
- Loading branch information
Showing
19 changed files
with
767 additions
and
856 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
// Package env provides methods for working with environment variables | ||
package env | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import "syscall" | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// Which find full path to some app | ||
func Which(name string) string { | ||
paths := Get().Path() | ||
|
||
for _, path := range paths { | ||
if syscall.Access(path+"/"+name, syscall.F_OK) == nil { | ||
return path + "/" + name | ||
} | ||
} | ||
|
||
return "" | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Package network provides methods for collecting information about machine network | ||
package network | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import ( | ||
"net" | ||
"strings" | ||
|
||
"github.com/essentialkaos/ek/v13/req" | ||
"github.com/essentialkaos/ek/v13/strutil" | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// resolvePublicIP resolves public IP using IP resolver | ||
func resolvePublicIP(resolverURL string) string { | ||
resp, err := req.Request{ | ||
URL: resolverURL, | ||
AutoDiscard: true, | ||
}.Get() | ||
|
||
if err != nil { | ||
return "" | ||
} | ||
|
||
var ip string | ||
|
||
if strings.HasSuffix(resolverURL, "/cdn-cgi/trace") { | ||
ip = extractIPFromCloudflareTrace(resp.String()) | ||
} else { | ||
ip = resp.String() | ||
} | ||
|
||
if isValidIP(ip) { | ||
return ip | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// extractIPFromCloudflareTrace extracts public IP from Cloudflare trace | ||
// response | ||
func extractIPFromCloudflareTrace(data string) string { | ||
for i := 0; i < 16; i++ { | ||
f := strutil.ReadField(data, i, false, '\n') | ||
|
||
if f == "" { | ||
break | ||
} | ||
|
||
n := strutil.ReadField(f, 0, false, '=') | ||
|
||
if n != "ip" { | ||
continue | ||
} | ||
|
||
return strutil.ReadField(f, 1, false, '=') | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// isValidIP returns if given IP is valid | ||
func isValidIP(ip string) bool { | ||
return ip != "" && net.ParseIP(ip) != nil | ||
} |
Oops, something went wrong.