model

package
v5.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: AGPL-3.0 Imports: 28 Imported by: 11

Documentation

Overview

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	// type
	CloudBackupTypeFull   = `full`
	CloudBackupTypeChange = `change`

	// status
	CloudBackupStatusSuccess = `success`
	CloudBackupStatusFailure = `failure`

	// operation
	CloudBackupOperationCreate = `create`
	CloudBackupOperationUpdate = `update`
	CloudBackupOperationDelete = `delete`
	CloudBackupOperationNone   = `none`
)
View Source
const (
	// log type
	CloudBackupLogTypeAll   = `all`
	CloudBackupLogTypeError = `error`

	// storage engine
	StorageEngineS3     = `s3`
	StorageEngineSFTP   = `sftp`
	StorageEngineFTP    = `ftp`
	StorageEngineWebDAV = `webdav`
	StorageEngineSMB    = `smb`
)
View Source
const (
	KvRootType        = `root`
	AutoCreatedType   = `autoCreated`
	KvDefaultDataType = `text`
)
View Source
const (
	AuthTypePassword = `password`
)
View Source
const StorageAccountIDKey = `storerID`

Variables

View Source
var (
	// SMSWaitingSeconds 短信发送后等待秒数
	SMSWaitingSeconds int64 = 60
	// SMSMaxPerDay 短信每人每天发送上限
	SMSMaxPerDay int64 = 10
)
View Source
var CloudBackupLogTypes = echo.NewKVData().Add(CloudBackupLogTypeAll, `全部`).Add(CloudBackupLogTypeError, `报错`)
View Source
var CloudBackupOperations = echo.NewKVData().Add(CloudBackupOperationCreate, `创建`).
	Add(CloudBackupOperationUpdate, `更新`).
	Add(CloudBackupOperationDelete, `删除`).
	Add(CloudBackupOperationNone, `未知`)
View Source
var CloudBackupStatuses = echo.NewKVData().Add(CloudBackupStatusSuccess, `成功`).Add(CloudBackupStatusFailure, `失败`)
View Source
var CloudBackupStorageEngines = echo.NewKVData()
View Source
var CloudBackupTypes = echo.NewKVData().Add(CloudBackupTypeFull, `全量`).Add(CloudBackupTypeChange, `监控`)
View Source
var KvDataTypes = echo.NewKVData().Add(`number`, `数字`).Add(`text`, `文本`).Add(`json`, `JSON`)
View Source
var SafeItems = echo.NewKVData().
	Add(`google`, `两步验证`, echo.KVOptX(SafeItemInfo{
		Step: 2, ConfigTitle: `两步验证`, ConfigRoute: `gauth_bind`,
	})).
	Add(`password`, `密码登录`, echo.KVOptX(SafeItemInfo{
		Step: 1, ConfigTitle: `修改密码`, ConfigRoute: `password`,
	}))

Functions

func GetU2FStepCondValue

func GetU2FStepCondValue(step uint) interface{}

func ListSafeItemsByStep added in v5.1.1

func ListSafeItemsByStep(step uint, exclude ...string) []echo.KV

func RegisterSafeItem added in v5.1.1

func RegisterSafeItem(itemType, itemTitle string, info SafeItemInfo, extra ...echo.H)

Types

type AlertRecipient

type AlertRecipient struct {
	*dbschema.NgingAlertRecipient
}

func NewAlertRecipient

func NewAlertRecipient(ctx echo.Context) *AlertRecipient

func (*AlertRecipient) Add

func (s *AlertRecipient) Add() (pk interface{}, err error)

func (*AlertRecipient) Delete

func (s *AlertRecipient) Delete(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*AlertRecipient) Edit

func (s *AlertRecipient) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

type AlertTopic

type AlertTopic struct {
	*dbschema.NgingAlertTopic
}

func NewAlertTopic

func NewAlertTopic(ctx echo.Context) *AlertTopic

func (*AlertTopic) Add

func (s *AlertTopic) Add(rows ...*dbschema.NgingAlertTopic) (pk interface{}, err error)

func (*AlertTopic) Edit

func (s *AlertTopic) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*AlertTopic) Exists

func (s *AlertTopic) Exists(topic string, recipientId uint) (bool, error)

func (*AlertTopic) ExistsOther

func (s *AlertTopic) ExistsOther(topic string, recipientId uint, excludeID uint) (bool, error)

func (*AlertTopic) Send

func (s *AlertTopic) Send(topic string, alertData *alert.AlertData) (err error)

type CloudBackup

type CloudBackup struct {
	*dbschema.NgingCloudBackup
}

func NewCloudBackup

func NewCloudBackup(ctx echo.Context) *CloudBackup

func (*CloudBackup) Add

func (s *CloudBackup) Add() (pk interface{}, err error)

func (*CloudBackup) Edit

func (s *CloudBackup) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*CloudBackup) ListPage

func (s *CloudBackup) ListPage(cond *db.Compounds, sorts ...interface{}) ([]*CloudBackupExt, error)

type CloudBackupExt

type CloudBackupExt struct {
	*dbschema.NgingCloudBackup
	Storage       *dbschema.NgingCloudStorage `db:"-,relation=id:dest_storage|gtZero|eq(storage_engine:s3),columns=id&name&type"`
	Watching      bool
	FullBackuping bool
}

type CloudBackupLog added in v5.2.1

type CloudBackupLog struct {
	*dbschema.NgingCloudBackupLog
}

func NewCloudBackupLog added in v5.2.1

func NewCloudBackupLog(ctx echo.Context) *CloudBackupLog

func (*CloudBackupLog) Add added in v5.2.1

func (s *CloudBackupLog) Add() (pk interface{}, err error)

func (*CloudBackupLog) Edit added in v5.2.1

func (s *CloudBackupLog) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

type CloudStorage

type CloudStorage struct {
	*dbschema.NgingCloudStorage
}

func GetCloudStorage

func GetCloudStorage(ctx context.Context) (*CloudStorage, error)

func NewCloudStorage

func NewCloudStorage(ctx echo.Context) *CloudStorage

func (*CloudStorage) Add

func (s *CloudStorage) Add() (pk interface{}, err error)

func (*CloudStorage) BaseURL

func (s *CloudStorage) BaseURL() string

func (*CloudStorage) CachedList

func (s *CloudStorage) CachedList() map[string]*dbschema.NgingCloudStorage

func (*CloudStorage) Edit

func (s *CloudStorage) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*CloudStorage) Get

func (s *CloudStorage) Get(mw func(db.Result) db.Result, args ...interface{}) error

func (*CloudStorage) RawSecret

func (s *CloudStorage) RawSecret() string

type Code

type Code struct {
	Verification *dbschema.NgingCodeVerification
	Invitation   *dbschema.NgingCodeInvitation
	*base.Base
}

func NewCode

func NewCode(ctx echo.Context) *Code

func (*Code) AddVerificationCode

func (c *Code) AddVerificationCode() (interface{}, error)

func (*Code) CheckFrequency

func (c *Code) CheckFrequency(ownerID uint64, ownerType string, sendMethod string, frequencyCfg echo.H) error

func (*Code) CheckVerificationCode

func (c *Code) CheckVerificationCode(code string, purpose string, ownerID uint64, ownerType string, sendMethod string, sendTo string) (err error)

func (*Code) CountTodayVerificationCode

func (c *Code) CountTodayVerificationCode(ownerID uint64, ownerType string, sendMethod string) (int64, error)

func (*Code) LastVerificationCode

func (c *Code) LastVerificationCode(ownerID uint64, ownerType string, sendMethod string) (err error)

func (*Code) UseInvitationCode

func (c *Code) UseInvitationCode(m *dbschema.NgingCodeInvitation, usedUid uint) (err error)

func (*Code) UseVerificationCode

func (c *Code) UseVerificationCode(m *dbschema.NgingCodeVerification) (err error)

func (*Code) VerfyInvitationCode

func (c *Code) VerfyInvitationCode(code string) (err error)

type Config

type Config struct {
	*dbschema.NgingConfig
}

func NewConfig

func NewConfig(ctx echo.Context) *Config

func (*Config) Add

func (f *Config) Add() (pk interface{}, err error)

func (*Config) Edit

func (f *Config) Edit(mw func(db.Result) db.Result, args ...interface{}) error

func (*Config) EditByPK

func (f *Config) EditByPK(mw func(db.Result) db.Result, group string, key string) error

func (*Config) ListAllMapByGroup

func (f *Config) ListAllMapByGroup() (echo.H, error)

func (*Config) ListByGroup

func (f *Config) ListByGroup(group string) (func() int64, error)

func (*Config) ListMapByGroup

func (f *Config) ListMapByGroup(group string) (echo.H, error)

func (*Config) Upsert

func (f *Config) Upsert() (pk interface{}, err error)

func (*Config) ValueByKey

func (f *Config) ValueByKey(group, key string) string

type Invitation

type Invitation struct {
	*dbschema.NgingCodeInvitation
}

func NewInvitation

func NewInvitation(ctx echo.Context) *Invitation

func (*Invitation) Exists

func (u *Invitation) Exists(code string) (bool, error)

func (*Invitation) Exists2

func (u *Invitation) Exists2(code string, excludeID uint) (bool, error)

type Kv

type Kv struct {
	*dbschema.NgingKv
}

func NewKv

func NewKv(ctx echo.Context) *Kv

func (*Kv) Add

func (s *Kv) Add() (pk interface{}, err error)

func (*Kv) AutoCreateKey

func (s *Kv) AutoCreateKey(key string, value ...string) error

AutoCreateKey 自动创建 key value: 0. 值; 1. 说明; 2. 帮助说明

func (*Kv) Delete

func (s *Kv) Delete(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*Kv) Edit

func (s *Kv) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*Kv) Get

func (s *Kv) Get(mw func(db.Result) db.Result, args ...interface{}) error

func (*Kv) GetFromTypeList

func (s *Kv) GetFromTypeList(typeList []*dbschema.NgingKv, key string) string

func (*Kv) GetTypeValues

func (s *Kv) GetTypeValues(typ string, defaultValue ...string) ([]string, error)

func (*Kv) GetValue

func (s *Kv) GetValue(key string, defaultValue ...string) (string, error)

GetValue 获取 key 的值 defaultValue: 0. 默认值; 1. 说明; 2. 帮助说明 (1 和 2 仅在自动创建时有用)

func (*Kv) IsRootType

func (s *Kv) IsRootType(typ string) bool

func (*Kv) KvTypeList

func (s *Kv) KvTypeList(excludeIDs ...uint) []*dbschema.NgingKv

func (*Kv) ListByType

func (s *Kv) ListByType(typ string, excludeIDs ...uint) []*dbschema.NgingKv

func (*Kv) ListToMap

func (s *Kv) ListToMap(typeList []*dbschema.NgingKv) map[string]*dbschema.NgingKv

func (*Kv) SetSingleField

func (s *Kv) SetSingleField(id int, field string, value string) error

type LoginLog

type LoginLog struct {
	*dbschema.NgingLoginLog
}

func NewLoginLog

func NewLoginLog(ctx echo.Context) *LoginLog

func (*LoginLog) Add

func (s *LoginLog) Add() (pk interface{}, err error)

func (*LoginLog) AddAndSaveSession

func (s *LoginLog) AddAndSaveSession() (pk interface{}, err error)

func (*LoginLog) Edit

func (s *LoginLog) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error)

func (*LoginLog) GetLastFailure

func (s *LoginLog) GetLastFailure(ownerType string, ownerId uint64) (err error)

func (*LoginLog) GetLastSuccess

func (s *LoginLog) GetLastSuccess(ownerType string, ownerId uint64, sessionId string) (err error)

func (*LoginLog) InitLocation

func (s *LoginLog) InitLocation() (ipInfo ip2regionparser.IpInfo, err error)

func (*LoginLog) ListPage

func (s *LoginLog) ListPage(cond *db.Compounds, sorts ...interface{}) ([]*dbschema.NgingLoginLog, error)

type SafeItemInfo added in v5.1.1

type SafeItemInfo struct {
	Step        uint
	ConfigTitle string
	ConfigRoute string
}

func GetSafeItem added in v5.1.1

func GetSafeItem(itemType string) SafeItemInfo

func (SafeItemInfo) IsZero added in v5.1.1

func (s SafeItemInfo) IsZero() bool

type SendingLog

type SendingLog struct {
	*dbschema.NgingSendingLog
}

func NewSendingLog

func NewSendingLog(ctx echo.Context) *SendingLog

func (*SendingLog) Add

func (c *SendingLog) Add() (interface{}, error)

type Task

type Task struct {
	*dbschema.NgingTask
}

func NewTask

func NewTask(ctx echo.Context) *Task

type TaskAndGroup

type TaskAndGroup struct {
	*dbschema.NgingTask
	Group *dbschema.NgingTaskGroup `db:"-,relation=id:group_id|gtZero"`
}

type TaskGroup

type TaskGroup struct {
	*dbschema.NgingTaskGroup
}

func NewTaskGroup

func NewTaskGroup(ctx echo.Context) *TaskGroup

type TaskLog

type TaskLog struct {
	*dbschema.NgingTaskLog
}

func NewTaskLog

func NewTaskLog(ctx echo.Context) *TaskLog

type User

type User struct {
	*dbschema.NgingUser
}

func NewUser

func NewUser(ctx echo.Context) *User

func (*User) Add

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

func (*User) CheckPasswd

func (u *User) CheckPasswd(username string, password string) (exists bool, err error)

func (*User) ClearPasswordData

func (u *User) ClearPasswordData(users ...*dbschema.NgingUser) dbschema.NgingUser

func (*User) Exists

func (u *User) Exists(username string) (bool, error)

func (*User) Exists2

func (u *User) Exists2(username string, excludeUID uint) (bool, error)

func (*User) FireLoginFailure

func (u *User) FireLoginFailure(authType string, pass string, err error) error

func (*User) FireLoginSuccess

func (u *User) FireLoginSuccess(authType string) error

func (*User) GetUserAllU2F

func (u *User) GetUserAllU2F(uid uint) ([]*dbschema.NgingUserU2f, error)

func (*User) IncrLoginFails

func (u *User) IncrLoginFails() error

func (*User) NeedCheckU2F

func (u *User) NeedCheckU2F(authType string, uid uint, step uint) (need bool, err error)

func (*User) NewLoginLog

func (u *User) NewLoginLog(username string, authType string) *LoginLog

func (*User) Register

func (u *User) Register(user, pass, email, roleIds string) error

func (*User) ResetLoginFails

func (u *User) ResetLoginFails() error

func (*User) SetSession

func (u *User) SetSession(users ...*dbschema.NgingUser)

func (*User) U2F

func (u *User) U2F(uid uint, typ string, step uint) (u2f *dbschema.NgingUserU2f, err error)

func (*User) UnsetSession

func (u *User) UnsetSession()

func (*User) UpdateField

func (u *User) UpdateField(uid uint, set map[string]interface{}) (err error)

func (*User) VerifySession

func (u *User) VerifySession(users ...*dbschema.NgingUser) error

type UserRole

type UserRole struct {
	*dbschema.NgingUserRole
	// contains filtered or unexported fields
}

func NewUserRole

func NewUserRole(ctx echo.Context) *UserRole

func (*UserRole) Add

func (u *UserRole) Add() (interface{}, error)

func (*UserRole) Edit

func (u *UserRole) Edit(mw func(db.Result) db.Result, args ...interface{}) error

func (*UserRole) Exists

func (u *UserRole) Exists(name string) (bool, error)

func (*UserRole) Exists2

func (u *UserRole) Exists2(name string, excludeID uint) (bool, error)

func (*UserRole) ListByUser

func (u *UserRole) ListByUser(user *dbschema.NgingUser) (roleList []*dbschema.NgingUserRole)

type UserRolePermission

type UserRolePermission struct {
	*dbschema.NgingUserRolePermission
}

func NewUserRolePermission

func NewUserRolePermission(ctx echo.Context) *UserRolePermission

func (*UserRolePermission) Add

func (u *UserRolePermission) Add() (interface{}, error)

func (*UserRolePermission) Edit

func (u *UserRolePermission) Edit(mw func(db.Result) db.Result, args ...interface{}) error

func (*UserRolePermission) Exists

func (u *UserRolePermission) Exists(roleID uint, typ string) (bool, error)

type UserU2F

type UserU2F struct {
	*dbschema.NgingUserU2f
}

func NewUserU2F

func NewUserU2F(ctx echo.Context) *UserU2F

func (*UserU2F) Add

func (u *UserU2F) Add() (interface{}, error)

func (*UserU2F) HasType

func (u *UserU2F) HasType(uid uint, authType string, step uint) (bool, error)

func (*UserU2F) ListPageByType

func (u *UserU2F) ListPageByType(uid uint, typ string, step uint, sorts ...interface{}) error

func (*UserU2F) Unbind

func (u *UserU2F) Unbind(uid uint, typ string, step uint) error

func (*UserU2F) UnbindByToken

func (u *UserU2F) UnbindByToken(uid uint, typ string, step uint, token string) error

func (*UserU2F) UpdatePrecondition added in v5.1.1

func (u *UserU2F) UpdatePrecondition(uid uint, typ string, step uint, precondition string) error

type Verification

type Verification struct {
	*dbschema.NgingCodeVerification
}

func NewVerification

func NewVerification(ctx echo.Context) *Verification

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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