Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: "setup go"
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.22'
- name: Get the version
id: get_version
run: echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: "setup go"
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.22'
- name: "go mod download"
run: "go mod download"
- name: "go test ./..."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: "setup go"
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.22'
- name: "build binary and print --help"
run: |
go build -o ntgrrc .
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.iml
.idea
.DS_Store
ntgrrc
/ntgrrc
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

# ntgrrc (Netgear Remote Control) CHANGELOG

## v0.10.2

* change using Go '1.22'

----

## v0.10.1

* added outputs to standard output by @oalfreda in #64
Expand Down
12 changes: 12 additions & 0 deletions cmd/ntgrrc/cli_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import "github.com/nitram509/ntgrrc/pkg/ntgrrc"

type CliOptions struct {
Verbose bool
Quiet bool
OutputFormat ntgrrc.PrintFormat
TokenDir string
model ntgrrc.NetgearModel
token string
}
13 changes: 13 additions & 0 deletions cmd/ntgrrc/debug_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"github.com/nitram509/ntgrrc/pkg/ntgrrc"
)

type DebugReportCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
}

func (drc *DebugReportCommand) Run(args *CliOptions) error {
return ntgrrc.PrintDebugReport(drc.Address)
}
File renamed without changes.
45 changes: 45 additions & 0 deletions cmd/ntgrrc/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"errors"
"fmt"
"github.com/nitram509/ntgrrc/pkg/ntgrrc"
"golang.org/x/term"
"syscall"
)

type LoginCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
Password string `optional:"" help:"the admin console's password; if omitted, it will be prompted for" short:"p"`
}

func (login *LoginCommand) Run(args CliOptions) error {
if len(login.Password) < 1 {
pwd, err := promptForPassword(login.Address)
if err != nil {
return err
}
login.Password = pwd
}

if len(login.Password) < 1 {
return errors.New("no password given")
}

session := ntgrrc.NtgrrcSession{
PrintVerbose: args.Verbose,
TokenDir: args.TokenDir,
}

err := session.DoLogin(login.Address, login.Password)

return err
}

func promptForPassword(serverName string) (string, error) {
fmt.Printf("Please enter password for '%s' (input hidden) :> ", serverName)
// the int conversion is required for the windows build to succeed
password, err := term.ReadPassword(int(syscall.Stdin))
println()
return string(password), err
}
23 changes: 8 additions & 15 deletions main.go → cmd/ntgrrc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ package main
import (
"fmt"
"github.com/alecthomas/kong"
"github.com/nitram509/ntgrrc/pkg/ntgrrc"
"os"
)

type GlobalOptions struct {
Verbose bool
Quiet bool
OutputFormat OutputFormat
TokenDir string
model NetgearModel
token string
}

var cli struct {
HelpAll HelpAllFlag `help:"advanced/full help"`
Verbose bool `help:"verbose log messages" short:"v"`
Quiet bool `help:"no log messages" short:"q"`
OutputFormat OutputFormat `help:"what output format to use [md, json]" enum:"md,json" default:"md" short:"f"`
TokenDir string `help:"directory to store login tokens" default:"" short:"d"`
HelpAll HelpAllFlag `help:"advanced/full help"`
Verbose bool `help:"verbose log messages" short:"v"`
// FIXME: this seems to not being used ... so remove
Quiet bool `help:"no log messages" short:"q"`
OutputFormat ntgrrc.PrintFormat `help:"what output format to use [md, json]" enum:"md,json" default:"md" short:"f"`
TokenDir string `help:"directory to store login tokens" default:"" short:"d"`

Version VersionCommand `cmd:"" name:"version" help:"show version"`
Login LoginCommand `cmd:"" name:"login" help:"create a session for further commands (requires admin console password)"`
Expand All @@ -43,7 +36,7 @@ func main() {
}),
)

err := options.Run(&GlobalOptions{
err := options.Run(&CliOptions{
Verbose: cli.Verbose,
Quiet: cli.Quiet,
OutputFormat: cli.OutputFormat,
Expand Down
8 changes: 8 additions & 0 deletions cmd/ntgrrc/poe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

type PoeCommand struct {
PoeStatusCommand PoeStatusCommand `cmd:"" name:"status" help:"show current PoE status for all ports" default:"1"`
PoeShowSettingsCommand PoeShowSettingsCommand `cmd:"" name:"settings" help:"show current PoE settings for all ports"`
PoeSetPowerCommand PoeSetPowerCommand `cmd:"" name:"set" help:"set new PoE settings per each PORT number"`
PoeCyclePowerCommand PoeCyclePowerCommand `cmd:"" name:"cycle" help:"power cycle one or more PoE ports"`
}
21 changes: 21 additions & 0 deletions cmd/ntgrrc/poe_cycle_power.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import "github.com/nitram509/ntgrrc/pkg/ntgrrc"

type PoeCyclePowerCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
Ports []int `required:"" help:"port number (starting with 1), use multiple times for cycling multiple ports at once" short:"p" name:"port"`
}

func (pcp *PoeCyclePowerCommand) Run(args *CliOptions) error {
session := ntgrrc.NtgrrcSession{
PrintVerbose: args.Verbose,
TokenDir: args.TokenDir,
}
changedPorts, err := session.PoeCyclePower(pcp.Ports)
if err != nil {
return err
}
ntgrrc.PrettyPrintPoePortSettings(args.OutputFormat, changedPorts)
return nil
}
38 changes: 38 additions & 0 deletions cmd/ntgrrc/poe_set_power.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import "github.com/nitram509/ntgrrc/pkg/ntgrrc"

type PoeSetPowerCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
Ports []int `required:"" help:"port number (starting with 1), use multiple times for setting multiple ports at once" short:"p" name:"port"`
PortPwr string `optional:"" help:"power state for port [enable, disable]" short:"s" name:"power"`
PwrMode string `optional:"" help:"power mode [802.3af, legacy, pre-802.3at, 802.3at]" short:"m" name:"mode"`
PortPrio string `optional:"" help:"priority [low, high, critical]" short:"r" name:"priority"`
LimitType string `optional:"" help:"power limit type [none, class, user]" short:"t" name:"limit-type"`
PwrLimit string `optional:"" help:"power limit (W)" short:"l" name:"pwr-limit"`
DetecType string `optional:"" help:"detection type [IEEE 802, legacy, 4pt 802.3af + Legacy]" short:"e" name:"detect-type"`
LongerDetect string `optional:"" help:"longer detection time [enable, disable]" name:"longer-detection-time"`
}

func (psp *PoeSetPowerCommand) Run(args *CliOptions) error {
session := ntgrrc.NtgrrcSession{
PrintVerbose: args.Verbose,
TokenDir: args.TokenDir,
}
poeSetPower := ntgrrc.SetPoePowerRequest{
Ports: psp.Ports,
PortPwr: psp.PortPwr,
PwrMode: psp.PwrMode,
PortPrio: psp.PortPrio,
LimitType: psp.LimitType,
PwrLimit: psp.PwrLimit,
DetecType: psp.DetecType,
LongerDetect: psp.LongerDetect,
}
changedPorts, err := session.SetPoePower(poeSetPower)
if err != nil {
return err
}
ntgrrc.PrettyPrintPoePortSettings(args.OutputFormat, changedPorts)
return err
}
19 changes: 19 additions & 0 deletions cmd/ntgrrc/poe_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"github.com/nitram509/ntgrrc/pkg/ntgrrc"
)

type PoeShowSettingsCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
}

func (poe *PoeShowSettingsCommand) Run(args *CliOptions) error {
session := ntgrrc.NtgrrcSession{}
settings, err := session.GetPoeSettings()
if err != nil {
return err
}
ntgrrc.PrettyPrintPoePortSettings(args.OutputFormat, settings)
return nil
}
20 changes: 20 additions & 0 deletions cmd/ntgrrc/poe_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/nitram509/ntgrrc/pkg/ntgrrc"
)

type PoeStatusCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
}

func (poe *PoeStatusCommand) Run(args *CliOptions) error {
session := ntgrrc.NtgrrcSession{
PrintVerbose: args.Verbose,
TokenDir: args.TokenDir,
}

status, err := session.GetPoePortStatus()
ntgrrc.PrettyPrintPoePortStatus(args.OutputFormat, status)
return err
}
6 changes: 6 additions & 0 deletions cmd/ntgrrc/port.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

type PortCommand struct {
PortSettingsCommand PortSettingsCommand `cmd:"" name:"settings" help:"show switch port settings" default:"1"`
PortSetCommand PortSetCommand `cmd:"" name:"set" help:"set new settings/properties for each port"`
}
34 changes: 34 additions & 0 deletions cmd/ntgrrc/port_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import "github.com/nitram509/ntgrrc/pkg/ntgrrc"

type PortSetCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
Ports []int `required:"" help:"port number (starting with 1), use multiple times for setting multiple ports at once" short:"p" name:"port"`
Name *string `optional:"" help:"sets the name of a port, 1-16 character limit" short:"n"`
Speed string `optional:"" help:"set the speed and duplex of the port ['100M full', '100M half', '10M full', '10M half', 'Auto', 'Disable']" short:"s"`
IngressRateLimit string `optional:"" help:"set an incoming rate limit for the port ['1 Mbit/s', '128 Mbit/s', '16 Mbit/s', '2 Mbit/s', '256 Mbit/s', '32 Mbit/s', '4 Mbit/s', '512 Kbit/s', '512 Mbit/s', '64 Mbit/s', '8 Mbit/s', 'No Limit']" short:"i"`
EgressRateLimit string `optional:"" help:"set an outgoing rate limit for the port ['1 Mbit/s', '128 Mbit/s', '16 Mbit/s', '2 Mbit/s', '256 Mbit/s', '32 Mbit/s', '4 Mbit/s', '512 Kbit/s', '512 Mbit/s', '64 Mbit/s', '8 Mbit/s', 'No Limit']" short:"o"`
FlowControl string `optional:"" help:"enable/disable flow control on port ['Off', 'On']"`
}

func (ps *PortSetCommand) Run(args *CliOptions) error {
session := ntgrrc.NtgrrcSession{
PrintVerbose: args.Verbose,
TokenDir: args.TokenDir,
}
req := ntgrrc.SetPortSettingsRequest{
Ports: ps.Ports,
Name: ps.Name,
Speed: ps.Speed,
IngressRateLimit: ps.IngressRateLimit,
EgressRateLimit: ps.EgressRateLimit,
FlowControl: ps.FlowControl,
}
changed, err := session.SetPortSettings(req)
if err != nil {
return err
}
ntgrrc.PrettyPrintPortSettings(args.OutputFormat, changed)
return nil
}
22 changes: 22 additions & 0 deletions cmd/ntgrrc/port_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"github.com/nitram509/ntgrrc/pkg/ntgrrc"
)

type PortSettingsCommand struct {
Address string `required:"" help:"the Netgear switch's IP address or host name to connect to" short:"a"`
}

func (ps *PortSettingsCommand) Run(args *CliOptions) error {
session := ntgrrc.NtgrrcSession{
PrintVerbose: args.Verbose,
TokenDir: args.TokenDir,
}
settings, err := session.GetPortSettings()
if err != nil {
return err
}
ntgrrc.PrettyPrintPortSettings(args.OutputFormat, settings)
return nil
}
13 changes: 13 additions & 0 deletions cmd/ntgrrc/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"strings"
)

func suffixToLength(s string, length int) string {
if len(s) < length {
diff := length - len(s)
return s + strings.Repeat(" ", diff)
}
return s
}
File renamed without changes.
2 changes: 1 addition & 1 deletion version.go → cmd/ntgrrc/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var VERSION = "dev"
type VersionCommand struct {
}

func (version *VersionCommand) Run(args *GlobalOptions) error {
func (version *VersionCommand) Run(args *CliOptions) error {
println(VERSION)
return nil
}
8 changes: 0 additions & 8 deletions formatter.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ntgrrc
module github.com/nitram509/ntgrrc

go 1.20
go 1.22

require (
github.com/PuerkitoBio/goquery v1.9.2
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk=
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/corbym/gocrest v1.1.1 h1:lry77EvxdkHVL9XaPf0uHTcRPZi9jOXvUbdxhV7djYc=
github.com/corbym/gocrest v1.1.1/go.mod h1:vhNebfdBGx5l0Nh0OM/CvIVqGAnR9AAbI5qA9OxRUOU=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down
Loading