mirror of
https://github.com/moul/sshportal.git
synced 2025-01-11 09:59:39 +08:00
Merge pull request #135 from jle64/accept_ip_as_hostname
Allow to create a host using an ip as name
This commit is contained in:
commit
4b9e881ad0
2 changed files with 12 additions and 2 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -685,7 +686,16 @@ GLOBAL OPTIONS:
|
||||||
if c.String("password") != "" {
|
if c.String("password") != "" {
|
||||||
host.Password = c.String("password")
|
host.Password = c.String("password")
|
||||||
}
|
}
|
||||||
|
matched, err := regexp.MatchString(`^([0-9]{1,3}.){3}.([0-9]{1,3})$`, host.Hostname())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if matched {
|
||||||
|
host.Name = host.Hostname()
|
||||||
|
} else {
|
||||||
host.Name = strings.Split(host.Hostname(), ".")[0]
|
host.Name = strings.Split(host.Hostname(), ".")[0]
|
||||||
|
}
|
||||||
|
|
||||||
if c.String("hop") != "" {
|
if c.String("hop") != "" {
|
||||||
hop, err := dbmodels.HostByName(db, c.String("hop"))
|
hop, err := dbmodels.HostByName(db, c.String("hop"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -53,7 +53,7 @@ type SSHKey struct {
|
||||||
type Host struct {
|
type Host struct {
|
||||||
// FIXME: use uuid for ID
|
// FIXME: use uuid for ID
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string `gorm:"size:32" valid:"required,length(1|32),unix_user"`
|
Name string `gorm:"size:32" valid:"required,length(1|32)"`
|
||||||
Addr string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
|
Addr string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
|
||||||
User string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
|
User string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
|
||||||
Password string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
|
Password string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
|
||||||
|
|
Loading…
Reference in a new issue