keypair err mgt + shorturl random improve
This commit is contained in:
@@ -18,38 +18,46 @@ import (
|
||||
// - Server remote management if ManagerKp is available for that server
|
||||
type Server struct {
|
||||
//ServerCard meowlib.ServerCard `json:"server_data,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PublicKey string `json:"public_key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Login string `json:"login,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Presence bool `json:"presence,omitempty"`
|
||||
LastCheck time.Time `json:"last_check,omitempty"`
|
||||
Uptime time.Duration `json:"uptime,omitempty"`
|
||||
UserKp meowlib.KeyPair `json:"user_kp,omitempty"`
|
||||
ManagerKp meowlib.KeyPair `json:"manager_kp,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
AllowedDelay int `json:"allowed_delay,omitempty"`
|
||||
Backup bool `json:"backup,omitempty"`
|
||||
WebRTC bool `json:"webrtc,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PublicKey string `json:"public_key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Login string `json:"login,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Presence bool `json:"presence,omitempty"`
|
||||
LastCheck time.Time `json:"last_check,omitempty"`
|
||||
Uptime time.Duration `json:"uptime,omitempty"`
|
||||
UserKp *meowlib.KeyPair `json:"user_kp,omitempty"`
|
||||
ManagerKp *meowlib.KeyPair `json:"manager_kp,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
AllowedDelay int `json:"allowed_delay,omitempty"`
|
||||
Backup bool `json:"backup,omitempty"`
|
||||
WebRTC bool `json:"webrtc,omitempty"`
|
||||
}
|
||||
|
||||
// CreateServerFromUrl creates a server from a basic url, ex : https://my.meowserver.example:8443/meow/
|
||||
func CreateServerFromUrl(url string) *Server {
|
||||
func CreateServerFromUrl(url string) (*Server, error) {
|
||||
var is Server
|
||||
var err error
|
||||
is.Name = url
|
||||
is.Url = url
|
||||
is.UserKp = meowlib.NewKeyPair()
|
||||
return &is
|
||||
is.UserKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &is, nil
|
||||
}
|
||||
|
||||
// CreateServerFromUid creates a server from a uid string, ex : mylogin:mypassword@https://my.meowserver.example:8443/meow/
|
||||
func CreateServerFromUid(uid string) *Server {
|
||||
func CreateServerFromUid(uid string) (*Server, error) {
|
||||
var is Server
|
||||
var err error
|
||||
uidTable := strings.Split(uid, "@") //! Weak test, use regexp
|
||||
is.Name = uid
|
||||
is.UserKp = meowlib.NewKeyPair()
|
||||
is.UserKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(uidTable) == 2 {
|
||||
loginpw := strings.Split(uidTable[0], ":")
|
||||
is.Url = uidTable[1]
|
||||
@@ -58,17 +66,17 @@ func CreateServerFromUid(uid string) *Server {
|
||||
} else {
|
||||
is.Url = uidTable[0]
|
||||
}
|
||||
return &is
|
||||
return &is, nil
|
||||
}
|
||||
|
||||
// CreateServerFromMeowUrl creates a server from a meow url, ex : meow://mylogin:mypassword@https://my.meowserver.example:8443/meow/
|
||||
func CreateServerFromMeowUrl(meowurl string) *Server {
|
||||
func CreateServerFromMeowUrl(meowurl string) (*Server, error) {
|
||||
uid := strings.Replace(meowurl[7:], "//", "://", 1)
|
||||
return CreateServerFromUid(uid)
|
||||
}
|
||||
|
||||
// CreateServerFromInvitationLink creates a server from a meow url, ex : meow://mylogin:mypassword@https://my.meowserver.example:8443/meow?invitationCode
|
||||
func CreateServerFromInvitationLink(meowurl string) *Server {
|
||||
func CreateServerFromInvitationLink(meowurl string) (*Server, error) {
|
||||
// remove the invitation code, last token after a /
|
||||
meowurlTable := strings.Split(meowurl, "?")
|
||||
// join all elements with / except the last one
|
||||
@@ -103,16 +111,20 @@ func (sc *Server) GetMeowUrl() string {
|
||||
}
|
||||
|
||||
// Create a server from a server card
|
||||
func CreateServerFromServerCard(server *meowlib.ServerCard) *Server {
|
||||
func CreateServerFromServerCard(server *meowlib.ServerCard) (*Server, error) {
|
||||
var is Server
|
||||
var err error
|
||||
is.Name = server.Name
|
||||
is.PublicKey = server.PublicKey
|
||||
is.Description = server.Description
|
||||
is.Url = server.Url
|
||||
is.Login = server.Login
|
||||
is.Password = server.Password
|
||||
is.UserKp = meowlib.NewKeyPair()
|
||||
return &is
|
||||
is.UserKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &is, nil
|
||||
}
|
||||
|
||||
// AsymEncryptMessage prepares a message to send to a specific internal server
|
||||
|
||||
Reference in New Issue
Block a user