models

package
v2.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LocalNode = &Node{
	ID:          0,
	Name:        "LocalNode",
	PublicHost:  "127.0.0.1",
	PrivateHost: "127.0.0.1",
	PublicPort:  8080,
	PrivatePort: 8080,
	SFTPPort:    5657,
	Secret:      strings.Replace(uuid.NewV4().String(), "-", "", -1),
}

Functions

This section is empty.

Types

type ChangeSetting added in v2.3.0

type ChangeSetting struct {
	Value interface{} `json:"value"`
}

type ChangeUserSetting added in v2.3.0

type ChangeUserSetting struct {
	Value string `json:"value"`
}

type Client

type Client struct {
	ID                 uint   `gorm:"PRIMARY_KEY,AUTO_INCREMEMT" json:"-"`
	ClientId           string `gorm:"NOT NULL" json:"client_id"`
	HashedClientSecret string `gorm:"column:client_secret;NOT NULL" json:"-"`

	UserId uint  `gorm:"NOT NULL" json:"-"`
	User   *User `json:"-"`

	ServerId sql.NullString `gorm:"" json:"-"`
	Server   *Server        `json:"-"`

	Scopes    []pufferpanel.Scope `gorm:"-" json:"-"`
	RawScopes string              `gorm:"column:scopes;NOT NULL;size:4000" json:"-"`

	Name        string `gorm:"column:name;NOT NULL;size:100;default\"\"" json:"name"`
	Description string `gorm:"column:description;NOT NULL;size:4000;default:\"\"" json:"description"`
}

func (*Client) AfterFind

func (c *Client) AfterFind(*gorm.DB) (err error)

func (*Client) BeforeSave

func (c *Client) BeforeSave(*gorm.DB) (err error)

func (*Client) IsValid

func (c *Client) IsValid() (err error)

func (*Client) SetClientSecret

func (c *Client) SetClientSecret(secret string) error

func (*Client) ValidateSecret

func (c *Client) ValidateSecret(secret string) bool

type Clients

type Clients []*Client

type CreateServerResponse

type CreateServerResponse struct {
	Id string `json:"id"`
}

type CreatedClient added in v2.4.0

type CreatedClient struct {
	ClientId     string `json:"id"`
	ClientSecret string `json:"secret"`
}

type Deployment

type Deployment struct {
	ClientId     string `json:"clientId"`
	ClientSecret string `json:"clientSecret"`
	PublicKey    string `json:"publicKey"`
}

type GetServerResponse

type GetServerResponse struct {
	Server *ServerView     `json:"server"`
	Perms  *PermissionView `json:"permissions"`
}

type MultiplePermissions

type MultiplePermissions []*Permissions

type Node

type Node struct {
	ID          uint   `json:"-"`
	Name        string `gorm:"size:100;UNIQUE;NOT NULL" json:"-" validate:"required,printascii"`
	PublicHost  string `gorm:"size:100;NOT NULL" json:"-"`
	PrivateHost string `gorm:"size:100;NOT NULL" json:"-"`
	PublicPort  uint16 `gorm:"DEFAULT:8080;NOT NULL" json:"-" validate:"required,min=1,max=65535,nefield=SFTPPort"`
	PrivatePort uint16 `gorm:"DEFAULT:8080;NOT NULL" json:"-" validate:"required,min=1,max=65535,nefield=SFTPPort"`
	SFTPPort    uint16 `gorm:"DEFAULT:5657;NOT NULL" json:"-" validate:"required,min=1,max=65535,nefield=PublicPort,nefield=PrivatePort"`

	Secret string `gorm:"size=36;NOT NULL" json:"-" validate:"required"`

	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

func (*Node) BeforeSave

func (n *Node) BeforeSave(*gorm.DB) (err error)

func (*Node) IsLocal

func (n *Node) IsLocal() bool

func (*Node) IsValid

func (n *Node) IsValid() (err error)

type NodeView

type NodeView struct {
	Id          uint   `json:"id"`
	Name        string `json:"name,omitempty"`
	PublicHost  string `json:"publicHost,omitempty"`
	PrivateHost string `json:"privateHost,omitempty"`
	PublicPort  uint16 `json:"publicPort,omitempty"`
	PrivatePort uint16 `json:"privatePort,omitempty"`
	SFTPPort    uint16 `json:"sftpPort,omitempty"`
	Local       bool   `json:"isLocal"`
}

func FromNode

func FromNode(n *Node) *NodeView

func (*NodeView) CopyToModel

func (n *NodeView) CopyToModel(newModel *Node)

func (*NodeView) Valid

func (n *NodeView) Valid(allowEmpty bool) error

type NodesView

type NodesView []*NodeView

func FromNodes

func FromNodes(n []*Node) *NodesView

type PermissionView

type PermissionView struct {
	Username         string `json:"username,omitempty"`
	Email            string `json:"email,omitempty"`
	ServerIdentifier string `json:"serverIdentifier,omitempty"`

	EditServerData    bool `json:"editServerData,omitempty"`
	EditServerUsers   bool `json:"editServerUsers,omitempty"`
	InstallServer     bool `json:"installServer,omitempty"`
	UpdateServer      bool `json:"-"` //this is unused currently
	ViewServerConsole bool `json:"viewServerConsole,omitempty"`
	SendServerConsole bool `json:"sendServerConsole,omitempty"`
	StopServer        bool `json:"stopServer,omitempty"`
	StartServer       bool `json:"startServer,omitempty"`
	ViewServerStats   bool `json:"viewServerStats,omitempty"`
	ViewServerFiles   bool `json:"viewServerFiles,omitempty"`
	SFTPServer        bool `json:"sftpServer,omitempty"`
	PutServerFiles    bool `json:"putServerFiles,omitempty"`

	Admin           bool `json:"admin,omitempty"`
	ViewServer      bool `json:"viewServers,omitempty"`
	CreateServer    bool `json:"createServers,omitempty"`
	ViewNodes       bool `json:"viewNodes,omitempty"`
	EditNodes       bool `json:"editNodes,omitempty"`
	DeployNodes     bool `json:"deployNodes,omitempty"`
	ViewTemplates   bool `json:"viewTemplates,omitempty"`
	EditTemplates   bool `json:"editTemplates,omitempty"`
	EditUsers       bool `json:"editUsers,omitempty"`
	ViewUsers       bool `json:"viewUsers,omitempty"`
	EditServerAdmin bool `json:"editServerAdmin,omitempty"`
	DeleteServer    bool `json:"deleteServers,omitempty"`
	PanelSettings   bool `json:"panelSettings,omitempty"`
}

func FromPermission

func FromPermission(p *Permissions) *PermissionView

func (*PermissionView) CopyTo

func (p *PermissionView) CopyTo(model *Permissions, copyAdminFlags bool)

Copies perms from the view to the model This will only copy what it knows about the server

type Permissions

type Permissions struct {
	ID uint `gorm:"primaryKey,autoIncrement" json:"-"`

	//owners of this permission set
	UserId *uint `json:"-"`
	User   User  `gorm:"ASSOCIATION_SAVE_REFERENCE:false" json:"-" validate:"-"`

	ClientId *uint  `json:"-"`
	Client   Client `gorm:"ASSOCIATION_SAVE_REFERENCE:false" json:"-" validate:"-"`

	//if this set is for a server, what server
	ServerIdentifier *string `json:"-"`
	Server           Server  `gorm:"ASSOCIATION_SAVE_REFERENCE:false" json:"-" validate:"-"`

	//and here are all the perms we support
	Admin           bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	ViewServer      bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	CreateServer    bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	ViewNodes       bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	EditNodes       bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	DeployNodes     bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	ViewTemplates   bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	EditTemplates   bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	EditUsers       bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	ViewUsers       bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	EditServerAdmin bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	DeleteServer    bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	PanelSettings   bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`

	//these only will exist if tied to a server, and for a user
	EditServerData    bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	EditServerUsers   bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	InstallServer     bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	UpdateServer      bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""` //this is unused currently
	ViewServerConsole bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	SendServerConsole bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	StopServer        bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	StartServer       bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	ViewServerStats   bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	ViewServerFiles   bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	SFTPServer        bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
	PutServerFiles    bool `gorm:"NOT NULL;DEFAULT:0" json:"-" oneOf:""`
}

func (*Permissions) BeforeSave

func (p *Permissions) BeforeSave(*gorm.DB) error

func (*Permissions) SetDefaults

func (p *Permissions) SetDefaults()

func (*Permissions) ShouldDelete

func (p *Permissions) ShouldDelete() bool

func (*Permissions) ToScopes

func (p *Permissions) ToScopes() []pufferpanel.Scope

type Server

type Server struct {
	Name       string `gorm:"size:40;NOT NULL" json:"-" validate:"required,printascii"`
	Identifier string `gorm:"UNIQUE;NOT NULL;primaryKey;size:8" json:"-" validate:"required,printascii"`

	RawNodeID *uint `gorm:"column:node_id" json:"-"`
	NodeID    uint  `gorm:"-" json:"-" validate:"-"`
	Node      Node  `gorm:"ASSOCIATION_SAVE_REFERENCE:false;foreignKey:RawNodeID" json:"-" validate:"-"`

	IP   string `gorm:"" json:"-" validate:"omitempty,ip|fqdn"`
	Port uint16 `gorm:"" json:"-" validate:"omitempty"`

	Type string `gorm:"NOT NULL;default='generic'" json:"-" validate:"required,printascii"`

	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

func (*Server) AfterFind added in v2.6.0

func (s *Server) AfterFind(*gorm.DB) (err error)

func (*Server) BeforeSave

func (s *Server) BeforeSave(*gorm.DB) (err error)

func (*Server) IsValid

func (s *Server) IsValid() (err error)

type ServerCreation

type ServerCreation struct {
	pufferpanel.Server

	NodeId uint     `json:"node"`
	Users  []string `json:"users"`
	Name   string   `json:"name"`
}

type ServerSearchResponse

type ServerSearchResponse struct {
	Servers []*ServerView `json:"servers"`
	*response.Metadata
}

type ServerUserView

type ServerUserView struct {
	Username string   `json:"username"`
	Scopes   []string `json:"scopes"`
}

type ServerView

type ServerView struct {
	Identifier string           `json:"id,omitempty"`
	Name       string           `json:"name,omitempty"`
	NodeId     uint             `json:"nodeId,omitempty"`
	Node       *NodeView        `json:"node,omitempty"`
	Data       interface{}      `json:"data,omitempty"`
	Users      []ServerUserView `json:"users,omitempty"`
	IP         string           `json:"ip,omitempty"`
	Port       uint16           `json:"port,omitempty"`
	Type       string           `json:"type"`
}

func FromServer

func FromServer(server *Server) *ServerView

func FromServers

func FromServers(servers []*Server) []*ServerView

func RemoveServerPrivateInfo

func RemoveServerPrivateInfo(server *ServerView) *ServerView

func RemoveServerPrivateInfoFromAll

func RemoveServerPrivateInfoFromAll(servers []*ServerView) []*ServerView

func (*ServerView) Valid

func (s *ServerView) Valid(allowEmpty bool) error

type SettingResponse added in v2.3.0

type SettingResponse struct {
	Value interface{} `json:"value"`
}

type Template

type Template struct {
	pufferpanel.Server `gorm:"-"`

	Name     string `gorm:"type:varchar(100);primaryKey" json:"name"`
	RawValue string `gorm:"type:text" json:"-"`

	Readme string `gorm:"type:text" json:"readme,omitempty"`
}

func (*Template) AfterFind

func (t *Template) AfterFind(*gorm.DB) error

func (*Template) BeforeSave

func (t *Template) BeforeSave(*gorm.DB) error

type Templates

type Templates []*Template

type User

type User struct {
	ID             uint   `json:"-"`
	Username       string `gorm:"UNIQUE;NOT NULL;size:100" json:"-" validate:"required,printascii,max=100,min=5"`
	Email          string `gorm:"UNIQUE;NOT NULL;size:255" json:"-" validate:"required,email,max=255"`
	HashedPassword string `gorm:"column:password;NOT NULL;size:200" json:"-" validate:"required,max=200"`
	OtpSecret      string `gorm:"size:32" json:"-"`
	OtpActive      bool   `gorm:"NOT NULL;DEFAULT:0" json"-"`

	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

func (*User) BeforeSave

func (u *User) BeforeSave(*gorm.DB) (err error)

func (*User) IsValid

func (u *User) IsValid() (err error)

func (*User) SetPassword

func (u *User) SetPassword(pw string) error

type UserSearch

type UserSearch struct {
	Username  string `form:"username"`
	Email     string `form:"email"`
	PageLimit uint   `form:"limit"`
	Page      uint   `form:"page"`
}

type UserSearchResponse

type UserSearchResponse struct {
	Users []*UserView `json:"users"`
	*response.Metadata
}

type UserSetting added in v2.3.0

type UserSetting struct {
	Key    string `gorm:"NOT NULL;size:100;primaryKey"`
	UserID uint   `gorm:"NOT NULL;primaryKey;AUTO_INCREMENT:false"`
	Value  string `gorm:"NOT NULL;type:text"`
}

type UserSettingView added in v2.3.0

type UserSettingView struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

func FromUserSetting added in v2.3.0

func FromUserSetting(setting *UserSetting) *UserSettingView

type UserSettings added in v2.3.0

type UserSettings []*UserSetting

type UserSettingsView added in v2.3.0

type UserSettingsView []*UserSettingView

func FromUserSettings added in v2.3.0

func FromUserSettings(settings *UserSettings) UserSettingsView

type UserView

type UserView struct {
	Id       uint   `json:"id,omitempty"`
	Username string `json:"username,omitempty"`
	Email    string `json:"email,omitempty"`
	//ONLY SHOW WHEN COPYING
	Password    string `json:"password,omitempty"`
	NewPassword string `json:"newPassword,omitempty"`
}

func FromUser

func FromUser(model *User) *UserView

func FromUsers

func FromUsers(users *Users) []*UserView

func (*UserView) CopyToModel

func (model *UserView) CopyToModel(newModel *User)

func (*UserView) EmailValid added in v2.1.3

func (model *UserView) EmailValid(allowEmpty bool) error

func (*UserView) UserNameValid added in v2.1.3

func (model *UserView) UserNameValid(allowEmpty bool) error

func (*UserView) Valid

func (model *UserView) Valid(allowEmpty bool) error

type Users

type Users []*User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL