mirror of
				https://github.com/h44z/wg-portal.git
				synced 2025-11-03 23:56:18 +00:00 
			
		
		
		
	peer expiry feature: database model, frontend updates
This commit is contained in:
		@@ -108,11 +108,15 @@ type Peer struct {
 | 
			
		||||
	// Global Device Settings (can be ignored, only make sense if device is in server mode)
 | 
			
		||||
	Mtu int `form:"mtu" binding:"gte=0,lte=1500"`
 | 
			
		||||
 | 
			
		||||
	DeactivatedAt *time.Time `json:",omitempty"`
 | 
			
		||||
	CreatedBy     string
 | 
			
		||||
	UpdatedBy     string
 | 
			
		||||
	CreatedAt     time.Time
 | 
			
		||||
	UpdatedAt     time.Time
 | 
			
		||||
	DeactivatedAt     *time.Time `json:",omitempty"`
 | 
			
		||||
	DeactivatedReason string     `json:",omitempty"`
 | 
			
		||||
 | 
			
		||||
	ExpiresAt *time.Time `json:",omitempty" form:"expires_at" binding:"omitempty" time_format:"2006-01-02"`
 | 
			
		||||
 | 
			
		||||
	CreatedBy string
 | 
			
		||||
	UpdatedBy string
 | 
			
		||||
	CreatedAt time.Time
 | 
			
		||||
	UpdatedAt time.Time
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *Peer) SetIPAddresses(addresses ...string) {
 | 
			
		||||
@@ -238,6 +242,19 @@ func (p Peer) IsValid() bool {
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p Peer) WillExpire() bool {
 | 
			
		||||
	if p.ExpiresAt == nil {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	if p.DeactivatedAt != nil {
 | 
			
		||||
		return false // already deactivated...
 | 
			
		||||
	}
 | 
			
		||||
	if p.ExpiresAt.After(time.Now()) {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p Peer) GetConfigFileName() string {
 | 
			
		||||
	reg := regexp.MustCompile("[^a-zA-Z0-9_-]+")
 | 
			
		||||
	return reg.ReplaceAllString(strings.ReplaceAll(p.Identifier, " ", "-"), "") + ".conf"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user