cli/internal/cmd/unifi/cmd_networks.go
Snider 76332b0f02
Add User Documentation (User Guide, FAQ, Troubleshooting) (#307)
* docs: add user guide, faq, and enhance troubleshooting

- Created docs/user-guide.md with key concepts and workflows.
- Created docs/faq.md with common questions and answers.
- Enhanced docs/troubleshooting.md with AI/Agentic issues.
- Updated README.md with CLI Quick Start and Getting Help sections.
- Refactored mkdocs.yml to reflect actual file structure and include new docs.

* docs: add user documentation and fix mkdocs navigation

- Created docs/user-guide.md and docs/faq.md.
- Enhanced docs/troubleshooting.md with AI/Agentic issues.
- Updated README.md with CLI Quick Start and Help links.
- Restored original mkdocs.yml navigation and added new user documentation sections.
- Fixed formatting in pkg/io/local/client.go to ensure CI passes.

* docs: add user documentation and fix auto-merge workflow

- Created docs/user-guide.md and docs/faq.md with user-focused content.
- Enhanced docs/troubleshooting.md with AI/Agentic issue solutions.
- Updated README.md with CLI Quick Start and organized help links.
- Refactored mkdocs.yml to include new documentation while preserving technical sections.
- Fixed .github/workflows/auto-merge.yml by inlining the logic and adding git repository context (checkout and -R flag) to resolve CI failures.
- Verified that docs/workflows.md is present in the repository.

* docs: add user documentation and resolve merge conflict

- Created docs/user-guide.md and docs/faq.md.
- Enhanced docs/troubleshooting.md with AI/Agentic issue solutions.
- Updated README.md with CLI Quick Start and Help sections.
- Merged latest base branch changes and resolved conflict in .github/workflows/auto-merge.yml.
- Verified and organized mkdocs.yml navigation.

* docs: add user documentation and fix UniFi security issue

- Created docs/user-guide.md and docs/faq.md.
- Enhanced docs/troubleshooting.md.
- Updated README.md with CLI Quick Start.
- Fixed UniFi security vulnerability (CodeQL alert) by making TLS verification configurable.
- Added --insecure flag to UniFi CLI commands.
- Verified all documentation links and navigation.

* docs: add user documentation and fix formatting/security

- Created docs/user-guide.md and docs/faq.md.
- Enhanced docs/troubleshooting.md.
- Updated README.md with CLI Quick Start.
- Fixed UniFi security vulnerability by making TLS verification configurable.
- Added --insecure flag to UniFi CLI commands.
- Fixed formatting in internal/cmd/unifi/cmd_config.go.
- Verified all documentation links and navigation.

---------

Co-authored-by: Claude <developers@lethean.io>
2026-02-05 06:55:52 +00:00

145 lines
3.2 KiB
Go

package unifi
import (
"fmt"
"github.com/host-uk/core/pkg/cli"
"github.com/host-uk/core/pkg/log"
uf "github.com/host-uk/core/pkg/unifi"
)
// Networks command flags.
var (
networksSite string
)
// addNetworksCommand adds the 'networks' subcommand for listing network segments.
func addNetworksCommand(parent *cli.Command) {
cmd := &cli.Command{
Use: "networks",
Short: "List network segments",
Long: "List all network segments configured on the UniFi controller, showing VLANs, subnets, isolation, and DHCP.",
RunE: func(cmd *cli.Command, args []string) error {
return runNetworks()
},
}
cmd.Flags().StringVar(&networksSite, "site", "", "Site name (default: \"default\")")
parent.AddCommand(cmd)
}
func runNetworks() error {
client, err := uf.NewFromConfig("", "", "", "", nil)
if err != nil {
return log.E("unifi.networks", "failed to initialise client", err)
}
networks, err := client.GetNetworks(networksSite)
if err != nil {
return log.E("unifi.networks", "failed to fetch networks", err)
}
if len(networks) == 0 {
cli.Text("No networks found.")
return nil
}
// Separate WANs, LANs, and VPNs
var wans, lans, vpns []uf.NetworkConf
for _, n := range networks {
switch n.Purpose {
case "wan":
wans = append(wans, n)
case "remote-user-vpn":
vpns = append(vpns, n)
default:
lans = append(lans, n)
}
}
cli.Blank()
// WANs
if len(wans) > 0 {
cli.Print(" %s\n\n", infoStyle.Render("WAN Interfaces"))
wanTable := cli.NewTable("Name", "Type", "Group", "Status")
for _, w := range wans {
status := successStyle.Render("enabled")
if !w.Enabled {
status = errorStyle.Render("disabled")
}
wanTable.AddRow(
valueStyle.Render(w.Name),
dimStyle.Render(w.WANType),
dimStyle.Render(w.WANNetworkGroup),
status,
)
}
wanTable.Render()
cli.Blank()
}
// LANs
if len(lans) > 0 {
cli.Print(" %s\n\n", infoStyle.Render("LAN Networks"))
lanTable := cli.NewTable("Name", "Subnet", "VLAN", "Isolated", "Internet", "DHCP", "mDNS")
for _, n := range lans {
vlan := dimStyle.Render("-")
if n.VLANEnabled {
vlan = numberStyle.Render(fmt.Sprintf("%d", n.VLAN))
}
isolated := successStyle.Render("no")
if n.NetworkIsolationEnabled {
isolated = warningStyle.Render("yes")
}
internet := successStyle.Render("yes")
if !n.InternetAccessEnabled {
internet = errorStyle.Render("no")
}
dhcp := dimStyle.Render("off")
if n.DHCPEnabled {
dhcp = fmt.Sprintf("%s - %s", n.DHCPStart, n.DHCPStop)
}
mdns := dimStyle.Render("off")
if n.MDNSEnabled {
mdns = successStyle.Render("on")
}
lanTable.AddRow(
valueStyle.Render(n.Name),
n.IPSubnet,
vlan,
isolated,
internet,
dhcp,
mdns,
)
}
lanTable.Render()
cli.Blank()
}
// VPNs
if len(vpns) > 0 {
cli.Print(" %s\n\n", infoStyle.Render("VPN Networks"))
vpnTable := cli.NewTable("Name", "Subnet", "Type")
for _, v := range vpns {
vpnTable.AddRow(
valueStyle.Render(v.Name),
v.IPSubnet,
dimStyle.Render(v.VPNType),
)
}
vpnTable.Render()
cli.Blank()
}
cli.Print(" %s\n\n", dimStyle.Render(fmt.Sprintf("%d networks total", len(networks))))
return nil
}