guard

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileInfoEqual

func FileInfoEqual(old, current *GuardFileInfo) bool

func FileInfoToHash

func FileInfoToHash(c *GuardFileInfo) string

Types

type ApacheDetail

type ApacheDetail struct {
	Process *PsProcess
	MainPid int `json:"main_pid"`

	ExecutableFile string `json:"executable_file"`
	Version        string `json:"version"`
	HttpdRoot      string `json:"httpd_root"`
	ConfigPath     string `json:"config_path"`

	Timestamp int64 `json:"timestamp"`
	// contains filtered or unexported fields
}

func GetApacheDetail

func GetApacheDetail(c context.Context) []*ApacheDetail

func (*ApacheDetail) CalcHash

func (n *ApacheDetail) CalcHash() string

func (*ApacheDetail) IsServing

func (n *ApacheDetail) IsServing() bool

type ApacheGuardCallback

type ApacheGuardCallback func(detail ApacheDetail)

type ApacheGuardTarget

type ApacheGuardTarget struct {
	// contains filtered or unexported fields
}

func NewApacheGuardTarget

func NewApacheGuardTarget(
	interval int, cbs ...ApacheGuardCallback,
) *ApacheGuardTarget

func (*ApacheGuardTarget) Do

func (g *ApacheGuardTarget) Do()

func (*ApacheGuardTarget) Next

func (g *ApacheGuardTarget) Next()

type Guard

type Guard struct {
	// contains filtered or unexported fields
}

func NewGuard

func NewGuard() *Guard

func (*Guard) AddApacheGuard

func (g *Guard) AddApacheGuard(id string, intervalSeconds int, cbs ...ApacheGuardCallback)

func (*Guard) AddNetConnGuard

func (g *Guard) AddNetConnGuard(id string, intervalSeconds int, options ...NetConnGuardOption) error

func (*Guard) AddNginxGuard

func (g *Guard) AddNginxGuard(id string, intervalSeconds int, cbs ...NginxGuardCallback)

func (*Guard) AddPathGuard

func (g *Guard) AddPathGuard(id, path string, recursive bool, intervalSeconds int, options ...PathGuardTargetOption) error

func (*Guard) AddPathGuardWithRecover

func (g *Guard) AddPathGuardWithRecover(
	id, path string, recursive bool, intervalSeconds int,
	options ...PathGuardTargetOption,
) error

func (*Guard) AddProcessGuard

func (g *Guard) AddProcessGuard(id string, intervalSeconds int, options ...PsAuxProcessGuardOption) error

func (*Guard) GetAllFilesUnderRecovered

func (g *Guard) GetAllFilesUnderRecovered() []string

func (*Guard) GetOriginFileContent

func (g *Guard) GetOriginFileContent(p string) ([]byte, error)

func (*Guard) RecoverFile

func (g *Guard) RecoverFile(p string) error

func (*Guard) RemoveApacheGuard

func (g *Guard) RemoveApacheGuard(id string)

func (*Guard) RemoveNetConnGuard

func (g *Guard) RemoveNetConnGuard(id string)

func (*Guard) RemoveNginxGuard

func (g *Guard) RemoveNginxGuard(id string)

func (*Guard) RemovePathGuard

func (g *Guard) RemovePathGuard(id string)

func (*Guard) RemoveProcessGuard

func (g *Guard) RemoveProcessGuard(id string)

func (*Guard) Run

func (g *Guard) Run(ctx context.Context)

func (*Guard) TriggerNetConnectionGuardActionById

func (g *Guard) TriggerNetConnectionGuardActionById(id string) error

func (*Guard) TriggerPathMonitorGuardActionById

func (g *Guard) TriggerPathMonitorGuardActionById(id string) error

func (*Guard) TriggerProcessGuardActionById

func (g *Guard) TriggerProcessGuardActionById(id string) error

type GuardFileInfo

type GuardFileInfo struct {
	os.FileInfo

	Path    string
	Content []byte
}

type MySQLServerDetail

type MySQLServerDetail struct {
	Process *PsProcess
	MainPid int `json:"main_pid"`

	// language.*?PATH
	BaseDir        string `json:"base_dir"`
	DefaultRootDir string `json:"default_root_dir"`

	// mysql.*?Ver[\s]+%{DATA:full}[\s]+
	VersionFull string `json:"version_full"`
	// mysql.*?Ver[\s]+%{COMMONVERSION:full}[\s]+
	VersionShort string `json:"version_short"`

	// from process
	BinaryFile string `json:"binary_file"`

	// --default-files=PATH
	ConfigPath string `json:"config_path"`
	DataDir    string `json:"data_dir"`
}

func GetMySQLServerDetails

func GetMySQLServerDetails(c context.Context) []*MySQLServerDetail

type NetConn

type NetConn struct {
	Fd         uint32
	Family     string
	Type       string
	LocalAddr  string
	RemoteAddr string
	Status     string
	Uids       []int32
	Pid        int
}

func GetAllConns

func GetAllConns(ctx context.Context) ([]*NetConn, error)

func (*NetConn) String

func (s *NetConn) String() string

type NetConnCallback

type NetConnCallback func([]*NetConn)

type NetConnEventCallback

type NetConnEventCallback func(eventType NetConnEventType, conn *NetConn)

type NetConnEventType

type NetConnEventType string
const (
	NetConnEvent_New       NetConnEventType = "new"
	NetConnEvent_Disappear NetConnEventType = "disappear"
)

type NetConnGuardOption

type NetConnGuardOption func(t *NetConnGuardTarget) error

func SetNetConnEventCallback

func SetNetConnEventCallback(f NetConnEventCallback) NetConnGuardOption

func SetNetConnsCallback

func SetNetConnsCallback(f NetConnCallback) NetConnGuardOption

type NetConnGuardTarget

type NetConnGuardTarget struct {
	// contains filtered or unexported fields
}

func NewNetConnGuardTarget

func NewNetConnGuardTarget(intervalSeconds int, options ...NetConnGuardOption) (*NetConnGuardTarget, error)

func (*NetConnGuardTarget) Do

func (g *NetConnGuardTarget) Do()

func (*NetConnGuardTarget) Next

func (g *NetConnGuardTarget) Next()

type NginxDetail

type NginxDetail struct {
	Process            *PsProcess
	MainPid            int    `json:"main_pid"`
	Prefix             string `json:"prefix"`
	ConfigPath         string `json:"config_path"`
	Version            string `json:"version"`
	OpensslVersionFull string `json:"openssl_version_full"`
	OpensslVersion     string `json:"openssl_version"`

	Timestamp int64 `json:"timestamp"`
	// contains filtered or unexported fields
}

func GetNginxDetail

func GetNginxDetail(c context.Context) []*NginxDetail

func (*NginxDetail) CalcHash

func (n *NginxDetail) CalcHash() string

func (*NginxDetail) IsServing

func (n *NginxDetail) IsServing() bool

type NginxGuardCallback

type NginxGuardCallback func(NginxDetail)

type NginxGuardTarget

type NginxGuardTarget struct {
	// contains filtered or unexported fields
}

func NewNginxGuardTarget

func NewNginxGuardTarget(
	interval int, cbs ...NginxGuardCallback,
) *NginxGuardTarget

func (*NginxGuardTarget) Do

func (g *NginxGuardTarget) Do()

func (*NginxGuardTarget) Next

func (g *NginxGuardTarget) Next()

type PathGuardTarget

type PathGuardTarget struct {
	Path      string
	Recursive bool
	// contains filtered or unexported fields
}

func (*PathGuardTarget) Do

func (g *PathGuardTarget) Do()

func (*PathGuardTarget) Next

func (g *PathGuardTarget) Next()

type PathGuardTargetOption

type PathGuardTargetOption func(p *PathGuardTarget) error

func SetDisallowNewFile

func SetDisallowNewFile(s ...string) PathGuardTargetOption

func SetPathGuardCacheFileSize

func SetPathGuardCacheFileSize(byteSize int) PathGuardTargetOption

func SetPathGuardCallback

func SetPathGuardCallback(f pathGuardCallback) PathGuardTargetOption

func SetPathGuardContentChangeCallback

func SetPathGuardContentChangeCallback(f pathGuardCallback) PathGuardTargetOption

func SetPathGuardFileCountLimit

func SetPathGuardFileCountLimit(i int) PathGuardTargetOption

func SetPathGuardFirstToNotify

func SetPathGuardFirstToNotify() PathGuardTargetOption

func SetPathNameExcludes

func SetPathNameExcludes(s ...string) PathGuardTargetOption

func SetPathNameIncludes

func SetPathNameIncludes(s ...string) PathGuardTargetOption

func SetPathUnserRecovered

func SetPathUnserRecovered(r bool) PathGuardTargetOption

type PsAuxProcessCallback

type PsAuxProcessCallback func([]*PsProcess)

type PsAuxProcessEventCallback

type PsAuxProcessEventCallback func(name PsAuxProcessEventType, proc *PsProcess)

type PsAuxProcessEventType

type PsAuxProcessEventType string
const (
	PsAuxProcessEvent_New       PsAuxProcessEventType = "new"
	PsAuxProcessEvent_Disappear PsAuxProcessEventType = "disappear"
)

type PsAuxProcessGuardOption

type PsAuxProcessGuardOption func(t *PsAuxProcessGuardTarget) error

type PsAuxProcessGuardTarget

type PsAuxProcessGuardTarget struct {
	// contains filtered or unexported fields
}

func NewPsAuxProcessGuardTarget

func NewPsAuxProcessGuardTarget(intervalSeconds int, options ...PsAuxProcessGuardOption) (*PsAuxProcessGuardTarget, error)

func (*PsAuxProcessGuardTarget) Do

func (g *PsAuxProcessGuardTarget) Do()

func (*PsAuxProcessGuardTarget) Next

func (g *PsAuxProcessGuardTarget) Next()

type PsProcess

type PsProcess struct {
	Raw             []byte
	User            string
	Pid             int
	CPUPercent      float64
	MEMPercent      float64
	Vsz             int64
	Rss             int64
	Tty             string
	Stat            string
	Started         string
	DurationTimeRaw string
	Command         string
	ProcessName     string
	ParentPid       int32
	ChildrenPid     []int32
}

func CallPsAux

func CallPsAux(ctx context.Context) ([]*PsProcess, error)

Jump to

Keyboard shortcuts

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