Skip to content

Commit

Permalink
Set a default expiration date
Browse files Browse the repository at this point in the history
  • Loading branch information
yayayayaka committed Nov 8, 2023
1 parent 1599889 commit 302e1cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/httpd/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ type Binding struct {
// Enabling web client integrations you can render or modify the files with the specified
// extensions using an external tool.
WebClientIntegrations []WebClientIntegration `json:"web_client_integrations" mapstructure:"web_client_integrations"`
// Amount of days for created shares to expire per default. Set to 0 for no expiration.
ShareExpirationDays int `json:"share_expiration_days" mapstructure:"share_expiration_days"`
// Defining an OIDC configuration the web admin and web client UI will use OpenID to authenticate users.
OIDC OIDC `json:"oidc" mapstructure:"oidc"`
// Security defines security headers to add to HTTP responses and allows to restrict allowed hosts
Expand Down
9 changes: 9 additions & 0 deletions internal/httpd/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,15 @@ func (s *httpdServer) renderAddUpdateSharePage(w http.ResponseWriter, r *http.Re
currentURL = fmt.Sprintf("%v/%v", webClientSharePath, url.PathEscape(share.ShareID))
title = "Update share"
}

if share.ExpiresAt != 0 && s.binding.ShareExpirationDays > 0 {
if expiration_days, error := time.ParseDuration(fmt.Sprintf("%vh", s.binding.ShareExpirationDays * 24)); error != nil {
logger.Error(logSender, "", fmt.Sprintf("Failed to parse expiration days: %v", error))
} else {
share.ExpiresAt = util.GetTimeAsMsSinceEpoch(time.Now().Add(expiration_days))
}
}

data := clientSharePage{
baseClientPage: s.getBaseClientPageData(title, currentURL, r),
Share: share,
Expand Down
3 changes: 2 additions & 1 deletion sftpgo.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"hide_login_url": 0,
"render_openapi": true,
"web_client_integrations": [],
"share_expiration_days": 0,
"oidc": {
"client_id": "",
"client_secret": "",
Expand Down Expand Up @@ -417,4 +418,4 @@
}
},
"plugins": []
}
}

0 comments on commit 302e1cc

Please sign in to comment.