Skip to content

Commit

Permalink
Merge pull request #488 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 13.1.0
  • Loading branch information
andyone authored Jul 18, 2024
2 parents 2157401 + 2d6cefa commit 264d6d7
Show file tree
Hide file tree
Showing 19 changed files with 767 additions and 856 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

### [13.1.0](https://kaos.sh/ek/13.1.0)

- `[env]` Fixed compatibility with Windows
- `[support]` Add basic support of collecting info on Windows
- `[support/apps]` Added Windows support
- `[support/network]` Added Windows support

### [13.0.0](https://kaos.sh/ek/13.0.0)

> [!CAUTION]
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "13.0.0"
const VERSION = "13.1.0"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
17 changes: 0 additions & 17 deletions env/env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows
// +build !windows

// Package env provides methods for working with environment variables
package env

Expand All @@ -15,7 +12,6 @@ import (
"os"
"strconv"
"strings"
"syscall"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -51,19 +47,6 @@ func Get() Env {
return env
}

// 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 ""
}

// ////////////////////////////////////////////////////////////////////////////////// //

// Get returns environment variable value
Expand Down
29 changes: 29 additions & 0 deletions env/env_unix.go
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 ""
}
64 changes: 0 additions & 64 deletions env/env_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,9 @@ package env
// //
// ////////////////////////////////////////////////////////////////////////////////// //

// ❗ Env is map with environment values
type Env map[string]string

// ❗ Variable is environment variable for lazy reading
type Variable struct {
key string
value string
isRead bool
}

// ////////////////////////////////////////////////////////////////////////////////// //

// ❗ Var creates new environment variable struct
func Var(name string) *Variable {
panic("UNSUPPORTED")
}

// ❗ Get return key-value map with environment values
func Get() Env {
panic("UNSUPPORTED")
}

// ❗ Which find full path to some app
func Which(name string) string {
panic("UNSUPPORTED")
}

// ////////////////////////////////////////////////////////////////////////////////// //

// ❗ Get returns environment variable value
func (v *Variable) Get() string {
panic("UNSUPPORTED")
}

// ❗ Is returns true if environment variable value is equal to given one
func (v *Variable) Is(value string) bool {
panic("UNSUPPORTED")
}

// ❗ String returns environment variable value as string
func (v *Variable) String() string {
panic("UNSUPPORTED")
}

// ❗ Reset resets reading state of variable
func (v *Variable) Reset() *Variable {
panic("UNSUPPORTED")
}

// ////////////////////////////////////////////////////////////////////////////////// //

// ❗ Path return path as string slice
func (e Env) Path() []string {
panic("UNSUPPORTED")
}

// ❗ GetS return environment variable value as string
func (e Env) GetS(name string) string {
panic("UNSUPPORTED")
}

// ❗ GetI return environment variable value as int
func (e Env) GetI(name string) int {
panic("UNSUPPORTED")
}

// ❗ GetF return environment variable value as float
func (e Env) GetF(name string) float64 {
panic("UNSUPPORTED")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/depsy v1.3.0
github.com/essentialkaos/go-linenoise/v3 v3.6.0
golang.org/x/crypto v0.24.0
golang.org/x/crypto v0.25.0
golang.org/x/sys v0.22.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3 changes: 0 additions & 3 deletions support/apps/apps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows
// +build !windows

// Package apps provides methods for obtaining version information about various tools
package apps

Expand Down
85 changes: 0 additions & 85 deletions support/apps/apps_windows.go

This file was deleted.

4 changes: 2 additions & 2 deletions support/fs/fs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// ////////////////////////////////////////////////////////////////////////////////// //

// Collect collects info about filesystem
// Collect collects info about filesystem
func Collect() []support.FSInfo {
panic("UNSUPPORTED")
return nil
}
72 changes: 72 additions & 0 deletions support/network/ip-resolver.go
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
}
Loading

0 comments on commit 264d6d7

Please sign in to comment.