-
Notifications
You must be signed in to change notification settings - Fork 33
Add networkwizard.sh: a TUI for network configuration #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit introduces `networkwizard.sh`, a shell script that provides a text-based user interface (TUI) for managing common network configurations on FreeBSD. It utilizes the `bsddialog` utility. Features: - View detailed status of all network interfaces, including IP addresses, MAC addresses, and Wi-Fi connection details (SSID, signal). - Manage wired Ethernet connections: - List available wired interfaces. - Activate interfaces using DHCP. - Deactivate interfaces. - Manage Wi-Fi connections: - Create `wlan` (cloned) interfaces from physical Wi-Fi devices. - Scan for available Wi-Fi networks. - Connect to Open and WPA-PSK secured Wi-Fi networks. - Disconnect from Wi-Fi networks. - Destroy `wlan` interfaces. The utility is designed to simplify common networking tasks for you if you may prefer a menu-driven interface over manual command-line operations. It sources `bsdconfig`'s `common.subr` and `dialog.subr` for helper functions. A README.md file is included, detailing the script's purpose, requirements, usage, and limitations (e.g., changes are non-persistent).
Can one of the admins verify this patch? |
Reviewer's GuideThis PR adds a new shell-based TUI utility, networkwizard.sh, that leverages bsddialog and helper subr scripts to interactively view network status and manage both wired and Wi-Fi interfaces on FreeBSD, accompanied by a README.md with usage instructions and caveats. Sequence Diagram for Viewing Network StatussequenceDiagram
actor User
participant NW as networkwizard.sh
participant IFCONF as ifconfig
participant WPA as wpa_cli
participant NETS as netstat
participant BSDD as bsddialog
User->>NW: Selects "View Network Status"
NW->>IFCONF: Executes `ifconfig -l` (get interfaces)
IFCONF-->>NW: List of interfaces
loop For each relevant interface
NW->>IFCONF: Executes `ifconfig <iface>` (get details)
IFCONF-->>NW: Interface details (MAC, IP, status)
alt Interface is Wi-Fi
NW->>WPA: Executes `wpa_cli -i <iface> status`
WPA-->>NW: Wi-Fi status (SSID, etc.)
NW->>WPA: Executes `wpa_cli -i <iface> signal_poll`
WPA-->>NW: Signal strength
end
end
NW->>NETS: Executes `netstat -rn -f inet` (IPv4 route)
NETS-->>NW: IPv4 default gateway
NW->>NETS: Executes `netstat -rn -f inet6` (IPv6 route)
NETS-->>NW: IPv6 default gateway
NW->>BSDD: Formats and displays all info via `bsddialog --textbox`
BSDD-->>User: Shows network status
Sequence Diagram for Activating a Wired InterfacesequenceDiagram
actor User
participant NW as networkwizard.sh
participant DHC as dhclient
participant IFCONF as ifconfig
participant BSDD as bsddialog
User->>NW: Selects "Manage Wired", Interface, "ACTIVATE"
NW->>DHC: Executes `dhclient <iface>` (background)
DHC-->>NW: (process starts)
NW->>IFCONF: Executes `ifconfig <iface> up`
IFCONF-->>NW: (command status)
alt Activation initiated
NW->>BSDD: `bsddialog --msgbox "Interface activating..."`
BSDD-->>User: Shows status message
else Activation command failed
NW->>BSDD: `bsddialog --msgbox "Failed to bring up..."`
BSDD-->>User: Shows error message
end
Sequence Diagram for Connecting to a Wi-Fi NetworksequenceDiagram
actor User
participant NW as networkwizard.sh
participant BSDD as bsddialog
participant WPA as wpa_cli
participant IFCONF as ifconfig
participant DHC as dhclient
User->>NW: Selects "Manage Wi-Fi", <wlan_iface>, "CONNECT"
NW->>BSDD: `bsddialog --inputbox "Enter SSID:"`
BSDD-->>User: Prompts for SSID
User->>BSDD: Enters SSID
BSDD-->>NW: SSID
NW->>BSDD: `bsddialog --yesno "Is network open?"`
BSDD-->>User: Prompts for network type
User->>BSDD: Selects Yes/No
BSDD-->>NW: Network type
alt Network requires password
NW->>BSDD: `bsddialog --passwordbox "Password for SSID:"`
BSDD-->>User: Prompts for password
User->>BSDD: Enters password
BSDD-->>NW: Password
end
NW->>WPA: `add_network`, `set_network ssid`, `set_network key_mgmt/psk`
WPA-->>NW: Network ID, command status
NW->>WPA: `enable_network`, `select_network`
WPA-->>NW: Command status
NW->>IFCONF: Executes `ifconfig <wlan_iface> up`
IFCONF-->>NW: Command status
NW->>DHC: Executes `dhclient <wlan_iface>` (background)
DHC-->>NW: (process starts)
NW->>BSDD: `bsddialog --infobox "Attempting to connect..."`
BSDD-->>User: Shows connecting message
NW->>WPA: `status` (to verify)
WPA-->>NW: Connection status
NW->>IFCONF: `ifconfig <wlan_iface>` (to verify IP)
IFCONF-->>NW: Interface status with IP
alt Connection successful
NW->>BSDD: `bsddialog --msgbox "Connected to SSID, IP: X.X.X.X"`
BSDD-->>User: Shows success message
else Connection failed/partial
NW->>BSDD: `bsddialog --msgbox "Failed to connect or get IP..."`
BSDD-->>User: Shows failure/status message
end
Sequence Diagram for Creating a wlan InterfacesequenceDiagram
actor User
participant NW as networkwizard.sh
participant IFCONF as ifconfig
participant BSDD as bsddialog
User->>NW: Selects "Manage Wi-Fi", "CREATE wlan for <phys_dev>"
NW->>NW: Determine next available wlan number (e.g., wlanX)
NW->>IFCONF: Executes `ifconfig wlanX create wlandev <phys_dev> up`
IFCONF-->>NW: Command status
alt Creation successful
NW->>BSDD: `bsddialog --msgbox "Interface wlanX created..."`
BSDD-->>User: Shows success message
else Creation failed
NW->>BSDD: `bsddialog --msgbox "Failed to create wlanX..."`
BSDD-->>User: Shows error message
end
Class Diagram for networkwizard.sh Structure and DependenciesclassDiagram
class networkwizard_sh {
<<Shell Script>>
+COMMON_SUBR : String
+DIALOG_SUBR : String
+view_status() void
+manage_one_wired_interface(iface_name: String) void
+manage_wired() void
+_get_wifi_interfaces() String list
+manage_one_wifi_interface(wlan_iface: String) int
+manage_wifi() void
+_populate_wifi_interface_lists() void
+main_menu() String
# Main script execution / loop implicitly uses these functions
}
class bsdconfig_libraries {
<<External Shell Libraries>>
+f_dialog_title(title: String) void
+f_dialog_backtitle(backtitle: String) void
+f_dialog_buttonbox_size(...)
+...other common and dialog helper functions...
}
networkwizard_sh ..> bsdconfig_libraries : sources and uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
sourcery-ai review
12 Haz 2025 Per 10:56 tarihinde sourcery-ai[bot] ***@***.***>
şunu yazdı:
… *sourcery-ai[bot]* left a comment (ghostbsd/ghostbsd-src#363)
<#363 (comment)>
🧙 Sourcery is reviewing your pull request!
------------------------------
Tips and commands Interacting with Sourcery
- *Trigger a new review:* Comment @sourcery-ai review on the pull
request.
- *Continue discussions:* Reply directly to Sourcery's review comments.
- *Generate a GitHub issue from a review comment:* Ask Sourcery to
create an
issue from a review comment by replying to it. You can also reply to a
review comment with @sourcery-ai issue to create an issue from it.
- *Generate a pull request title:* Write @sourcery-ai anywhere in the
pull
request title to generate a title at any time. You can also comment
@sourcery-ai title on the pull request to (re-)generate the title at
any time.
- *Generate a pull request summary:* Write @sourcery-ai summary
anywhere in
the pull request body to generate a PR summary at any time exactly
where you
want it. You can also comment @sourcery-ai summary on the pull request
to
(re-)generate the summary at any time.
- *Generate reviewer's guide:* Comment @sourcery-ai guide on the pull
request to (re-)generate the reviewer's guide at any time.
- *Resolve all Sourcery comments:* Comment @sourcery-ai resolve on the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore.
- *Dismiss all Sourcery reviews:* Comment @sourcery-ai dismiss on the
pull
request to dismiss all existing Sourcery reviews. Especially useful if
you
want to start fresh with a new review - don't forget to comment
@sourcery-ai review to trigger a new review!
Customizing Your Experience
Access your dashboard <https://app.sourcery.ai> to:
- Enable or disable review features such as the Sourcery-generated
pull request
summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team ***@***.***> for questions or
feedback.
- Visit our documentation <https://docs.sourcery.ai> for detailed
guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter
<https://x.com/SourceryAI>, LinkedIn
<https://www.linkedin.com/company/sourcery-ai/> or GitHub
<https://github.com/sourcery-ai>.
—
Reply to this email directly, view it on GitHub
<#363 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BOMX7Z6LTOXAB5VXNEST27T3DEXCJAVCNFSM6AAAAAB7EUHINKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNRVGUZTMOBTGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rkarahan80 - I've reviewed your changes - here's some feedback:
- There’s duplicated wireless interface detection logic (
_get_wifi_interfaces
vs_populate_wifi_interface_lists
); consolidate into a single function and remove the unused implementation. - Functions like
view_status
andmanage_wifi
are very large and complex—consider breaking them into smaller helper functions or modules to improve readability and maintainability. - Add explicit checks at startup for required external commands (e.g.,
wpa_cli
,dhclient
,netstat
) so the script can fail fast if a dependency is missing.
Here's what I looked at during the review
- 🟡 General issues: 8 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
# Get all interfaces | ||
interfaces=$(ifconfig -l) | ||
|
||
status_info="Network Interface Status:\n\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Literal \n sequences aren’t converted to newlines in the string
To display multiline text correctly, use printf, a here-document, or embed actual newlines in the variable instead of literal \n sequences.
|
||
# Display the collected information | ||
# Use --textbox which is better for scrollable text | ||
bsddialog --title "Network Status" --textbox "$status_info" 22 78 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): --textbox requires a filename, not a content string
--textbox expects a file path, not the content itself. Write status_info to a temporary file and pass its path, or use an option that accepts piped input.
scan_menu_items="" | ||
item_count=0 | ||
# Skip header line and parse results | ||
echo "$scan_results_raw" | awk 'NR>1 {printf "%s \"%s %s %s\"\n", $5, $5, $3, $4}' | while IFS= read -r line; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Variables set inside piped while loop run in a subshell
Assignments to scan_menu_items and item_count inside the piped while loop won't persist after the loop. Consider using process substitution or input redirection to ensure variable changes are retained.
done | ||
} | ||
|
||
# Helper to identify Wi-Fi interfaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: The _get_wifi_interfaces stub is unused and can be removed
Since _get_wifi_interfaces
is not used, please remove it to avoid dead code and potential confusion.
|
||
status_info="Network Interface Status:\n\n" | ||
|
||
for iface in $interfaces; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Unquoted variable expansion can lead to word splitting or globbing
Quote "$interfaces" or use an array to prevent unintended word splitting or glob expansion during iteration.
status_info="$status_info--------------------------------------------------\n\n" | ||
|
||
# Get IPv4 default route | ||
ipv4_route=$(netstat -rn -f inet | grep '^default' | awk '{print "Default Gateway (IPv4): " $2 " via " $4}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Label 'via' might misrepresent the interface field
In netstat, $4 is the interface name. Use 'Gateway:
on ' for accuracy.# dhclient -r "$iface_name" >/dev/null 2>&1 | ||
# Start new dhclient | ||
# Need to run dhclient in background otherwise it might block the script | ||
dhclient "$iface_name" >/dev/null 2>&1 & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Starting dhclient before bringing the interface up
Bring the interface up with ifconfig up
before starting dhclient to ensure it can bind to the active link.
- **View Detailed Status:** Show the full `ifconfig` output for the interface. | ||
|
||
3. **Manage Wi-Fi Connections:** | ||
- Lists existing `wlan` (virtual Wi-Fi) interfaces and physical Wi-Fi capable devices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (typo): Suggest hyphenating "Wi-Fi capable" to "Wi-Fi-capable".
Hyphenating compound modifiers before nouns improves clarity, so use "Wi-Fi-capable devices."
- Lists existing `wlan` (virtual Wi-Fi) interfaces and physical Wi-Fi capable devices. | |
- Lists existing `wlan` (virtual Wi-Fi) interfaces and physical Wi-Fi-capable devices. |
This commit introduces
networkwizard.sh
, a shell script that provides a text-based user interface (TUI) for managing common network configurations on FreeBSD. It utilizes thebsddialog
utility.Features:
wlan
(cloned) interfaces from physical Wi-Fi devices.wlan
interfaces.The utility is designed to simplify common networking tasks for you if you may prefer a menu-driven interface over manual command-line operations. It sources
bsdconfig
'scommon.subr
anddialog.subr
for helper functions.A README.md file is included, detailing the script's purpose, requirements, usage, and limitations (e.g., changes are non-persistent).
Summary by Sourcery
Add networkwizard.sh, a bsddialog-based TUI utility that simplifies network configuration tasks on FreeBSD.
New Features:
Documentation: