model

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const Secret = "com.github.cylonchau"

Variables

View Source
var DB *gorm.DB

Functions

func AllocateRole2User added in v0.0.6

func AllocateRole2User(userID uint64, roles_id []int) (enconterError error)

func AppendAuditLog added in v0.0.6

func AppendAuditLog(auditLog map[string]interface{})

func CheckPortIsExistWithName

func CheckPortIsExistWithName(name string) bool

func CheckTagIsExistWithName

func CheckTagIsExistWithName(name string) bool

func CheckTemplateIsExistWithName

func CheckTemplateIsExistWithName(name string) bool

func CreateHost

func CreateHost(hostIP, host string, tagID int) (enconterError error)

func CreateHostWithHost

func CreateHostWithHost(host *Host) (enconterError error)

func CreatePort

func CreatePort(port uint16, protocol string, template_id int) (enconterError error)

func CreateRich

func CreateRich(query *queryapi.RichEditQuery) (enconterError error)

func CreateRole added in v0.0.6

func CreateRole(query *query2.RoleEditQuery, routers []Router) (enconterError error)

Create role

func CreateTag

func CreateTag(tagQuery *query.TagEditQuery) (enconterError error)

func CreateTemplate

func CreateTemplate(name, description, target string) (enconterError error)

func CreateToken

func CreateToken(SignedTo, description string) (enconterError error)

func CreateUser

func CreateUser(userQuery *query.UserQuery) (enconterError error)

func DeleteHostWithID

func DeleteHostWithID(id uint64) error

func DeletePortWithID

func DeletePortWithID(id uint64) error

func DeleteRichWithID

func DeleteRichWithID(id uint64) error

func DeleteRoleWithID added in v0.0.6

func DeleteRoleWithID(id uint64) error

func DeleteTagWithID

func DeleteTagWithID(id uint64) error

func DeleteTemplateWithID

func DeleteTemplateWithID(id uint64) error

func DeleteTokenWithID

func DeleteTokenWithID(id uint64) error

func DeleteUserWithID added in v0.0.6

func DeleteUserWithID(id uint64) error

func EncryptPassword

func EncryptPassword(p string) string

func GetAuditLogs added in v0.0.6

func GetAuditLogs(offset, limit int, sort string) (map[string]interface{}, error)

func GetHosts

func GetHosts(offset, limit int, sort string) (map[string]interface{}, error)

func GetPorts

func GetPorts(offset, limit int, sort string) (map[string]interface{}, error)

func GetRequestIP

func GetRequestIP(r *http.Request) (uint32, error)

func GetRich

func GetRich(offset, limit int, sort string) (map[string]interface{}, error)

func GetRoles added in v0.0.6

func GetRoles(offset, limit int, sort string) (map[string]interface{}, error)

Get all roles

func GetRouters added in v0.0.6

func GetRouters(offset, limit int, sort string) (map[string]interface{}, error)

Get all roles

func GetSimpleTemplates

func GetSimpleTemplates(offset, limit int, sort string) (map[string]interface{}, error)

func GetTags

func GetTags(offset, limit int, sort string) (map[string]interface{}, error)

func GetTemplates

func GetTemplates(offset, limit int, sort string) (map[string]interface{}, error)

func GetTokens

func GetTokens(offset, limit int, sort string) (map[string]interface{}, error)

func GetUsers added in v0.0.6

func GetUsers(offset, limit int, sort string) (map[string]interface{}, error)

func HostCounter added in v0.0.5

func HostCounter() int64

func InitDB

func InitDB(driver string) error

func LastLogin

func LastLogin(uid int64, ip uint32) bool

func TagCounter added in v0.0.5

func TagCounter() int64

func TemplateCounter added in v0.0.5

func TemplateCounter() int64

func TokenIsDestoryed added in v0.0.4

func TokenIsDestoryed(tokenStr string) bool

func UpdateHostWithID

func UpdateHostWithID(query *query.HostQuery) (enconterError error)

func UpdatePortWithID

func UpdatePortWithID(id uint64, port uint16, protocol string, template_id int) (enconterError error)

func UpdateRichWithID

func UpdateRichWithID(query *queryapi.RichEditQuery) (enconterError error)

func UpdateRoleWithID added in v0.0.6

func UpdateRoleWithID(query *query2.RoleEditQuery) (enconterError error)

func UpdateTagWithID

func UpdateTagWithID(query *query.TagEditQuery) (enconterError error)

func UpdateTemplateWithID

func UpdateTemplateWithID(id uint64, name, description, target string) (enconterError error)

func UpdateTokenWithID

func UpdateTokenWithID(id uint64, signedTo, description string, isUpdate bool) (enconterError error)

func UpdateUserWithID added in v0.0.6

func UpdateUserWithID(query *query.UserEditQuery) (enconterError error)

Types

type Audit added in v0.0.6

type Audit struct {
	gorm.Model
	UserID  uint64 `json:"user_id" gorm:"index;type:int"`
	IP      uint32 `json:"ip" gorm:"index;type:int"`
	Method  string `json:"method" gorm:"type:char(5)"`
	Path    string `json:"path" gorm:"varchar(50)"`
	Browser string `json:"browser" gorm:"varchar(50)"`
	System  string `json:"system" gorm:"varchar(50)"`
}

func (*Audit) TableName added in v0.0.6

func (*Audit) TableName() string

type AuditList added in v0.0.6

type AuditList struct {
	Username string `json:"username" gorm:"index;type:varchar(20)"`
	IP       uint32 `json:"ip" gorm:"index;type:int"`
	Method   string `json:"method" gorm:"type:char(5)"`
	Path     string `json:"path" gorm:"varchar(50)"`
	Browser  string `json:"browser" gorm:"varchar(50)"`
	System   string `json:"system" gorm:"varchar(50)"`
}

func (*AuditList) TableName added in v0.0.6

func (*AuditList) TableName() string

type Classify added in v0.0.5

type Classify struct {
	Name  string `json:"name"`
	Count int    `json:"value"`
}

func HostClassify added in v0.0.5

func HostClassify() ([]*Classify, error)

func (*Classify) TableName added in v0.0.5

func (*Classify) TableName() string

type Host

type Host struct {
	gorm.Model
	Hostname string `json:"hostname" gorm:"index;type:varchar(255)"`
	IP       uint32 `json:"ip" gorm:"index;type:int"`
	TagId    int    `json:"tag_id" gorm:"index;type:int"`
}

func QueryHostWithID

func QueryHostWithID(uid int) (*Host, error)

func QueryHostWithName

func QueryHostWithName(hostname string) (*Host, error)

type HostList

type HostList struct {
	ID       int    `json:"id"`
	Hostname string `json:"hostname"`
	Ip       uint32 `json:"ip"`
	Tag      string `json:"tag"`
	TagId    int    `json:"tag_id"`
}

func (*HostList) TableName

func (*HostList) TableName() string

type Port

type Port struct {
	gorm.Model
	Port       uint16 `json:"port" gorm:"index;type:smallint;unsigned"`
	Protocol   string `json:"protocol" gorm:"type:varchar(255)"`
	TemplateId int    `json:"template_id" gorm:"type:int"`
}

type PortList

type PortList struct {
	ID         int    `json:"id"`
	Port       uint16 `json:"port"`
	Protocol   string `json:"protocol"`
	Template   string `json:"template"`
	TemplateID int    `json:"template_id"`
}

func (*PortList) TableName

func (*PortList) TableName() string

type Rich

type Rich struct {
	gorm.Model
	Family      string           `form:"family" json:"family,omitempty" gorm:"type:char(4)"`
	Source      *api.Source      `form:"source" json:"source,omitempty" gorm:"json"`
	Destination *api.Destination `form:"destination" json:"destination,omitempty" gorm:"json"`
	Port        []*api.Port      `form:"port" json:"port,omitempty" gorm:"json"`
	Protocol    *api.Protocol    `form:"protocol" json:"protocol,omitempty" gorm:"json"`
	Action      string           `form:"action" json:"action,omitempty" gorm:"type:varchar(30)"`
	Limit       uint16           `form:"limit" json:"limit,omitempty" gorm:"type:varchar(255)"`
	LimitUnit   string           `form:"limit_unit" json:"limit_unit,omitempty" gorm:"type:char(1)"`
	TemplateID  int              `form:"template_id" json:"template_id,omitempty" gorm:"type:int"`
}

func (*Rich) Scan

func (r *Rich) Scan(value interface{}) error

func (*Rich) Value

func (r *Rich) Value() (value driver.Value, err error)

type RichList

type RichList struct {
	ID          int              `json:"id"`
	Family      string           `form:"family" json:"family,omitempty"`
	Source      *api.Source      `form:"source" json:"source,omitempty" gorm:"json"`
	Destination *api.Destination `form:"destination" json:"destination,omitempty" gorm:"json"`
	Port        []*api.Port      `form:"port" json:"port,omitempty" gorm:"json"`
	Protocol    *api.Protocol    `form:"protocol" json:"protocol,omitempty" gorm:"json"`
	Action      string           `form:"action" json:"action,omitempty"`
	Limit       uint16           `form:"limit" json:"limit,omitempty"`
	LimitUnit   string           `form:"limit_unit" json:"limit_unit,omitempty"`
	TemplateID  int              `form:"template_id" json:"template_id,omitempty"`
	Template    string           `json:"template"`
}

func (*RichList) Scan

func (r *RichList) Scan(value interface{}) error

func (*RichList) TableName

func (*RichList) TableName() string

func (*RichList) Value

func (r *RichList) Value() (value driver.Value, err error)

type Role added in v0.0.6

type Role struct {
	gorm.Model
	Name        string   `gorm:"size:50;not null;unique" json:"name"`
	Routers     []Router `gorm:"many2many:role_routers;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
	Users       []User   `gorm:"many2many:user_roles;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
	Tokens      []Token  `gorm:"many2many:token_roles;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
	Description string   `gorm:"size:255;not null" json:"description"`
}

Role model

func GenerateRoleWithID added in v0.0.6

func GenerateRoleWithID(ids []int) []Role

func (*Role) TableName added in v0.0.6

func (*Role) TableName() string

type RoleInfo added in v0.0.6

type RoleInfo struct {
	ID   int    `json:"id" gorm:"column:id"`
	Name string `json:"name" gorm:"column:name"`
}

func (*RoleInfo) TableName added in v0.0.6

func (*RoleInfo) TableName() string

type RoleList added in v0.0.6

type RoleList struct {
	ID          int    `json:"id"`
	Name        string `gorm:"size:50;not null;unique" json:"name"`
	Description string `gorm:"size:255;not null" json:"description"`
}

func (*RoleList) TableName added in v0.0.6

func (*RoleList) TableName() string

type Router added in v0.0.6

type Router struct {
	gorm.Model
	Path   string `json:"path" gorm:"type:varchar(255);not null;"`
	Method string `json:"method" gorm:"type:char(4);not null;"`
	Roles  []Role `gorm:"many2many:role_routers;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}

Router model

func GenerateRouterWithID added in v0.0.6

func GenerateRouterWithID(ids []int) []Router

func (*Router) TableName added in v0.0.6

func (*Router) TableName() string

type RouterList added in v0.0.6

type RouterList struct {
	ID        int       `json:"id" gorm:"primarykey;column:id"`
	Path      string    `json:"path" gorm:"type:varchar(255);not null;column:path"`
	Method    string    `json:"method" gorm:"type:char(4);not null;column:method"`
	CreatedAt time.Time `json:"created_at" gorm:"column:created_at"`
}

func GetRoutersWithRID added in v0.0.6

func GetRoutersWithRID(roleIDs []string) (routers []*RouterList, encounterError error)

func (*RouterList) TableName added in v0.0.6

func (*RouterList) TableName() string

type Tag

type Tag struct {
	gorm.Model
	Name        string `json:"name" gorm:"index;type:varchar(255)"`
	Description string `json:"description" gorm:"type:varchar(255)"`
	Hosts       []Host `json:"hosts" gorm:"foreignKey:TagId;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}

func CheckTagIsExistWithID

func CheckTagIsExistWithID(id int64) (Tag, error)

func (*Tag) TableName

func (*Tag) TableName() string

type TagInfo

type TagInfo struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (*TagInfo) TableName

func (*TagInfo) TableName() string

type Template

type Template struct {
	gorm.Model
	Name        string `json:"name" gorm:"index;type:varchar(255)"`
	Description string `json:"description" gorm:"type:varchar(255)"`
	Target      string `json:"target" gorm:"type:varchar(100)"`
}

type TemplateList

type TemplateList struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Target      string `json:"target,omitempty"`
	Description string `json:"description,omitempty"`
}

func (*TemplateList) TableName

func (*TemplateList) TableName() string

type Token

type Token struct {
	gorm.Model
	Token       string `form:"token" json:"token" gorm:"index,type:text"`
	SignedTo    string `form:"signed_to" json:"signed_to" gorm:"type:varchar(255)"`
	SignedBy    string `form:"signed_by" json:"signed_by" gorm:"type:varchar(255)"`
	Description string `json:"description" gorm:"type:varchar(255)"`
	Roles       []Role `gorm:"many2many:token_roles;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}

type TokenList

type TokenList struct {
	ID          int    `json:"id"`
	Token       string `form:"token" json:"token" gorm:"type:text"`
	SignedTo    string `form:"signed_to" json:"signed_to" gorm:"type:varchar(255)"`
	SignedBy    string `form:"signed_by" json:"signed_by" gorm:"type:varchar(255)"`
	Description string `json:"description" gorm:"type:varchar(255)"`
}

func (*TokenList) TableName

func (*TokenList) TableName() string

type User

type User struct {
	gorm.Model
	Username string `gorm:"index;type:varchar(20)"`
	Password string `gorm:"type:varchar(32)"`
	Roles    []Role `gorm:"many2many:user_roles;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
	LoginIP  int    `json:"login_ip" gorm:"index;type:int"`
}

func QueryUserWithUID

func QueryUserWithUID(uid int64) (User, error)

func QueryUserWithUsername

func QueryUserWithUsername(username string) (User, error)

func (*User) TableName added in v0.0.6

func (*User) TableName() string

type UserInfo added in v0.0.6

type UserInfo struct {
	ID       uint       `gorm:"primarykey;column:id" json:"id"`
	Username string     `gorm:"index;type:varchar(20);column:username" json:"username"`
	Roles    []RoleInfo `` /* 171-byte string literal not displayed */
}

func GetRolesWithUID added in v0.0.6

func GetRolesWithUID(uid int) (user *UserInfo, encounterError error)

func (*UserInfo) TableName added in v0.0.6

func (*UserInfo) TableName() string

type UserList added in v0.0.6

type UserList struct {
	ID        uint           `json:"id" gorm:"primarykey"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"update_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
	Username  string         `json:"username" gorm:"index;type:varchar(20)"`
	Roles     []Role         `json:"roles" gorm:"many2many:user_roles;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
	LoginIP   int            `json:"login_ip" gorm:"index;type:int"`
}

func (*UserList) TableName added in v0.0.6

func (*UserList) TableName() string

type UserRoles added in v0.0.6

type UserRoles struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func (*UserRoles) TableName added in v0.0.6

func (*UserRoles) TableName() string

Jump to

Keyboard shortcuts

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