Some code reorg
This commit is contained in:
parent
43f26d099f
commit
e4fc9c3a6c
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/net/route"
|
"golang.org/x/net/route"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultRoute4 = [4]byte{0, 0, 0, 0}
|
var defaultRoute4 = [4]byte{0, 0, 0, 0}
|
||||||
@ -103,3 +105,22 @@ func (jh *JailHost) GetDefaultGateway6() string {
|
|||||||
}
|
}
|
||||||
return jh.default_gateway6
|
return jh.default_gateway6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHostInUseIPv4() ([]string, error) {
|
||||||
|
var ips []string
|
||||||
|
|
||||||
|
re := regexp.MustCompile(ifconfigipv4re)
|
||||||
|
|
||||||
|
out, err := executeCommand("/sbin/ifconfig")
|
||||||
|
if err != nil {
|
||||||
|
return ips, fmt.Errorf("ERROR executing \"/sbin/ifconfig\": %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(out, "\n") {
|
||||||
|
if re.MatchString(line) {
|
||||||
|
ips = append(ips, re.FindStringSubmatch(line)[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ips, nil
|
||||||
|
}
|
||||||
|
43
cmd/start.go
43
cmd/start.go
@ -229,12 +229,6 @@ func prepareJailedZfsDatasets(jail *Jail) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type NatDesc struct {
|
|
||||||
Proto string
|
|
||||||
JailPort string
|
|
||||||
HostPort string
|
|
||||||
}
|
|
||||||
|
|
||||||
// tcp(80:8080),tcp(3300-3310:33060-33070)
|
// tcp(80:8080),tcp(3300-3310:33060-33070)
|
||||||
func getNatForwardsArray(nat_forwards string, decompose_range bool) ([]NatDesc, error) {
|
func getNatForwardsArray(nat_forwards string, decompose_range bool) ([]NatDesc, error) {
|
||||||
var res []NatDesc
|
var res []NatDesc
|
||||||
@ -282,24 +276,6 @@ func getNatForwardsArray(nat_forwards string, decompose_range bool) ([]NatDesc,
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func enableRcKeyValue(rcconfpath string, key string, value string) error {
|
|
||||||
cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s %s=%s", rcconfpath, key, value)
|
|
||||||
_, err := executeCommand(cmd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func disableRcKey(rcconfpath string, key string) error {
|
|
||||||
cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s -x %s", rcconfpath, key)
|
|
||||||
_, err := executeCommand(cmd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Enable or disables DHCP or accept_rtadv for interfaces declared with this
|
* Enable or disables DHCP or accept_rtadv for interfaces declared with this
|
||||||
* option
|
* option
|
||||||
@ -433,25 +409,6 @@ func getJailsInUseIPv4() ([]string, error) {
|
|||||||
return ips, nil
|
return ips, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHostInUseIPv4() ([]string, error) {
|
|
||||||
var ips []string
|
|
||||||
|
|
||||||
re := regexp.MustCompile(ifconfigipv4re)
|
|
||||||
|
|
||||||
out, err := executeCommand("/sbin/ifconfig")
|
|
||||||
if err != nil {
|
|
||||||
return ips, fmt.Errorf("ERROR executing \"/sbin/ifconfig\": %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range strings.Split(out, "\n") {
|
|
||||||
if re.MatchString(line) {
|
|
||||||
ips = append(ips, re.FindStringSubmatch(line)[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ips, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func genNatIpv4(jail *Jail) ([]string, error) {
|
func genNatIpv4(jail *Jail) ([]string, error) {
|
||||||
var ippair []string
|
var ippair []string
|
||||||
|
|
||||||
|
@ -9,6 +9,12 @@ const (
|
|||||||
IPv6 = 1
|
IPv6 = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type NatDesc struct {
|
||||||
|
Proto string
|
||||||
|
JailPort string
|
||||||
|
HostPort string
|
||||||
|
}
|
||||||
|
|
||||||
// To allow sorting, just duplicate fields in JailSort below
|
// To allow sorting, just duplicate fields in JailSort below
|
||||||
type Jail struct {
|
type Jail struct {
|
||||||
Name string
|
Name string
|
||||||
|
23
cmd/utils.go
23
cmd/utils.go
@ -214,6 +214,29 @@ func executeCommandInJail(jail *Jail, cmdline string) (string, error) {
|
|||||||
return string(out), err
|
return string(out), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* rc.conf management
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
func enableRcKeyValue(rcconfpath string, key string, value string) error {
|
||||||
|
cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s %s=%s", rcconfpath, key, value)
|
||||||
|
_, err := executeCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func disableRcKey(rcconfpath string, key string) error {
|
||||||
|
cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s -x %s", rcconfpath, key)
|
||||||
|
_, err := executeCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Parse an fstab file, returning an array of Mount
|
* Parse an fstab file, returning an array of Mount
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user