-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add sh ports entity for listing listening ports #49
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -148,6 +148,30 @@ _u7_show() { | |||||||||||||||||||||
| esac | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ports) | ||||||||||||||||||||||
| case "$1" in | ||||||||||||||||||||||
| match) | ||||||||||||||||||||||
| if [[ -z "$2" ]]; then | ||||||||||||||||||||||
| echo "Usage: u7 sh ports match <pattern>" | ||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| if command -v ss &>/dev/null; then | ||||||||||||||||||||||
| ss -tlnp | grep -i "$2" | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| netstat -tlnp 2>/dev/null | grep -i "$2" | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
Comment on lines
+158
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: lib/show.sh
Line: 158-162
Comment:
**`grep` pattern not protected from flag injection**
`grep -i "$2"` will interpret any pattern beginning with `-` as a grep flag (e.g. `u7 sh ports match -v` would invert the match silently). The `log match` handler added in the same PR correctly uses `grep -- "$3"` to terminate flag parsing. Apply the same protection here:
```suggestion
if command -v ss &>/dev/null; then
ss -tlnp | grep -i -- "$2"
else
netstat -tlnp 2>/dev/null | grep -i -- "$2"
fi
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| "") | ||||||||||||||||||||||
| if command -v ss &>/dev/null; then | ||||||||||||||||||||||
| ss -tlnp | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| netstat -tlnp 2>/dev/null | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| *) echo "Usage: u7 sh ports [match <pattern>]" ; return 1 ;; | ||||||||||||||||||||||
| esac | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
|
Comment on lines
+151
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for choosing between ports)
_list_ports() {
if command -v ss &>/dev/null; then
ss -tlnp
else
netstat -tlnp 2>/dev/null
fi
}
case "$1" in
match)
if [[ -z "$2" ]]; then
echo "Usage: u7 sh ports match <pattern>"
return 1
fi
_list_ports | grep -i -- "$2"
;;
"")
_list_ports
;;
*) echo "Usage: u7 sh ports [match <pattern>]" ; return 1 ;;
esac
;;
Comment on lines
+151
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for choosing between ports)
local list_cmd
if command -v ss &>/dev/null; then
list_cmd="ss -tlnp"
else
list_cmd="netstat -tlnp 2>/dev/null"
fi
case "$1" in
match)
if [[ -z "$2" ]]; then
echo "Usage: u7 sh ports match <pattern>"
return 1
fi
eval "$list_cmd" | grep -i -- "$2"
;;
"")
eval "$list_cmd"
;;
*) echo "Usage: u7 sh ports [match <pattern>]" ; return 1 ;;
esac
;; |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| port) | ||||||||||||||||||||||
| lsof -i tcp:"$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.
logsubcommand completion missingportsgot argument completion, butlog(also added in this PR) has no completion case for its subcommands (limit,match,follow). Add alogcase alongside the newportscase:Prompt To Fix With AI