model

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var DB *gorm.DB

Functions

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 CreateTag

func CreateTag(tagQuery *apis.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 *apis.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 DeleteTagWithID

func DeleteTagWithID(id uint64) error

func DeleteTemplateWithID

func DeleteTemplateWithID(id uint64) error

func DeleteTokenWithID

func DeleteTokenWithID(id uint64) error

func EncryptPassword

func EncryptPassword(p string) string

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 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 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 Migration

func Migration(driver string) error

func MySQL

func MySQL() (*gorm.DB, error)

func SQLite

func SQLite() (*gorm.DB, error)

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 *apis.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 UpdateTagWithID

func UpdateTagWithID(query *apis.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)

Types

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:smaillintt;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      *apis.Source      `form:"source" json:"source,omitempty" gorm:"json"`
	Destination *apis.Destination `form:"destination" json:"destination,omitempty" gorm:"json"`
	Port        []*apis.Port      `form:"port" json:"port,omitempty" gorm:"json"`
	Protocol    *apis.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      *apis.Source      `form:"source" json:"source,omitempty" gorm:"json"`
	Destination *apis.Destination `form:"destination" json:"destination,omitempty" gorm:"json"`
	Port        []*apis.Port      `form:"port" json:"port,omitempty" gorm:"json"`
	Protocol    *apis.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 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)"`
}

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)"`
	LoginIP  int    `json:"login_ip" gorm:"type:int"`
}

func QueryUserWithUID

func QueryUserWithUID(uid int64) (User, error)

func QueryUserWithUsername

func QueryUserWithUsername(username string) (User, error)

Jump to

Keyboard shortcuts

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