added SystemSSHEnabled
This commit is contained in:
parent
e795fe0158
commit
1ea1259aad
10
system.go
10
system.go
@ -33,6 +33,16 @@ func SystemSetRootPassword(password string) error {
|
|||||||
return ioutil.WriteFile(systemShadow, []byte(line), os.ModePerm)
|
return ioutil.WriteFile(systemShadow, []byte(line), os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SystemSSHEnabled returns true if server is enabled
|
||||||
|
func SystemSSHEnabled() (bool, error) {
|
||||||
|
data, err := ioutil.ReadFile(systemDropbearConfig)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to read ssh config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Contains(string(data), "127.0.0.1:22"), nil
|
||||||
|
}
|
||||||
|
|
||||||
// SystemEnableSSH server
|
// SystemEnableSSH server
|
||||||
func SystemEnableSSH() error {
|
func SystemEnableSSH() error {
|
||||||
err := ioutil.WriteFile(systemDropbearConfig, []byte("DROPBEAR_OPTS=\"\""), os.ModePerm)
|
err := ioutil.WriteFile(systemDropbearConfig, []byte("DROPBEAR_OPTS=\"\""), os.ModePerm)
|
||||||
|
@ -34,6 +34,25 @@ func TestSystemSetRootPassword(t *testing.T) {
|
|||||||
_ = os.Remove(systemShadow)
|
_ = os.Remove(systemShadow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSystemSSHEnabled(t *testing.T) {
|
||||||
|
ass := assert.New(t)
|
||||||
|
|
||||||
|
_, err := SystemSSHEnabled()
|
||||||
|
ass.EqualError(err, "failed to read ssh config: open test_dropbear: no such file or directory")
|
||||||
|
|
||||||
|
ass.NoError(ioutil.WriteFile(systemDropbearConfig, []byte("test"), os.ModePerm))
|
||||||
|
value, err := SystemSSHEnabled()
|
||||||
|
ass.NoError(err)
|
||||||
|
ass.False(value)
|
||||||
|
|
||||||
|
ass.NoError(ioutil.WriteFile(systemDropbearConfig, []byte("DROPBEAR_OPTS=\"-p 127.0.0.1:22\""), os.ModePerm))
|
||||||
|
value, err = SystemSSHEnabled()
|
||||||
|
ass.NoError(err)
|
||||||
|
ass.True(value)
|
||||||
|
|
||||||
|
_ = os.Remove(systemDropbearConfig)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSystemEnableSSH(t *testing.T) {
|
func TestSystemEnableSSH(t *testing.T) {
|
||||||
ass := assert.New(t)
|
ass := assert.New(t)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user