-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Implements PostUp and PostDown commands using /bin/sh
#25
Conversation
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.
Very cool!
util.go
Outdated
@@ -35,6 +36,16 @@ func ExitFail(format string, a ...interface{}) { | |||
os.Exit(1) | |||
} | |||
|
|||
func ShellOut(command *string, name string) { | |||
if command != nil { | |||
shell := exec.Command("/bin/sh", "-c", *command) |
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.
Should it emit a message before running so we are aware what it just did?
I.e:
fmt.Printf("Running %s commands:\n %s", name, command)
Thanks @fs111 looks good. I think @botto is right, it should probably log the command it's running to stdout so I'll add that before releasing unless you beat me to it. Regarding using pointers to strings as they're optional fields -- I assume that will serialise as |
This introduces PostUp and PostDown in dsnet. PostUp and PostDown allow the user to run arbitrary commands after the device is up or down. These are typically used to change the firewall rules via iptables. A working example would be ... "PostUp" : "iptables -A FORWARD -i dsnet -j ACCEPT; iptables -A FORWARD -o dsnet -j ACCEPT; iptables -t nat -A POSTROUTING -o ens2 -j MASQUERADE ", "PostDown" : "iptables -D FORWARD -i dsnet -j ACCEPT; iptables -D FORWARD -o dsnet -j ACCEPT; iptables -t nat -D POSTROUTING -o ens2 -j MASQUERADE ", ... All commands are executed by `/bin/sh` and no filtering or sandboxing is applied. Users of this should know what they are doing. Fixes naggie#16
I have updated the PR with the comments addressed. I am personally more a fan of the "Rule of silence" and would not have added the print, but it is fine either way. |
I'll have a think about the rule of silence, but for now I'll release. Thanks @fs111 ! |
I thought about it and decided against the extra print command. Sorry @botto :) |
This introduces PostUp and PostDown in dsnet. PostUp and PostDown allow
the user to run arbitrary commands after the device is up or down. These
are typically used to change the firewall rules via iptables. A working
example would be
...
"PostUp" : "iptables -A FORWARD -i dsnet -j ACCEPT; iptables -A FORWARD -o dsnet -j ACCEPT; iptables -t nat -A POSTROUTING -o ens2 -j MASQUERADE ",
"PostDown" : "iptables -D FORWARD -i dsnet -j ACCEPT; iptables -D FORWARD -o dsnet -j ACCEPT; iptables -t nat -D POSTROUTING -o ens2 -j MASQUERADE ",
...
All commands are executed by
/bin/sh
and no filtering or sandboxing isapplied. Users of this should know what they are doing.
Fixes #16