mirror of
https://github.com/Luzifer/ots.git
synced 2025-07-20 13:18:54 -04:00
add cfg option DefaultSecretExpire
This commit is contained in:
parent
a3554d3551
commit
4042cd065f
4 changed files with 30 additions and 19 deletions
7
api.go
7
api.go
|
@ -63,12 +63,15 @@ func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
expiry = cfg.MaxSecretExpiry
|
expiry = cfg.DefaultSecretExpiry
|
||||||
secret string
|
secret string
|
||||||
)
|
)
|
||||||
|
|
||||||
if !cust.DisableExpiryOverride {
|
if !cust.DisableExpiryOverride {
|
||||||
if ev, err := strconv.ParseInt(r.URL.Query().Get("expire"), 10, 64); err == nil && (ev < expiry || cfg.MaxSecretExpiry == 0) {
|
if cfg.DefaultSecretExpiry == 0 && cfg.MaxSecretExpiry > 0 {
|
||||||
|
cfg.DefaultSecretExpiry = cfg.MaxSecretExpiry
|
||||||
|
}
|
||||||
|
if ev, err := strconv.ParseInt(r.URL.Query().Get("expire"), 10, 64); err == nil && (ev <= cfg.MaxSecretExpiry || cfg.MaxSecretExpiry == 0) {
|
||||||
expiry = ev
|
expiry = ev
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
|
|
||||||
// Template variable from Golang process
|
// Template variable from Golang process
|
||||||
const maxSecretExpire = {{ .MaxSecretExpiry }}
|
const maxSecretExpire = {{ .MaxSecretExpiry }}
|
||||||
|
const defaultSecretExpire = {{ .DefaultSecretExpiry }}
|
||||||
|
|
||||||
const version = "{{ .Version }}"
|
const version = "{{ .Version }}"
|
||||||
window.OTSCustomize = JSON.parse('{{ .Customize.ToJSON }}')
|
window.OTSCustomize = JSON.parse('{{ .Customize.ToJSON }}')
|
||||||
window.useFormalLanguage = {{ .Customize.UseFormalLanguage | mustToJson }}
|
window.useFormalLanguage = {{ .Customize.UseFormalLanguage | mustToJson }}
|
||||||
|
|
4
main.go
4
main.go
|
@ -31,6 +31,7 @@ var (
|
||||||
Listen string `flag:"listen" default:":3000" description:"IP/Port to listen on"`
|
Listen string `flag:"listen" default:":3000" description:"IP/Port to listen on"`
|
||||||
LogLevel string `flag:"log-level" default:"info" description:"Set log level (debug, info, warning, error)"`
|
LogLevel string `flag:"log-level" default:"info" description:"Set log level (debug, info, warning, error)"`
|
||||||
MaxSecretExpiry int64 `flag:"max-secret-expiry" default:"0" description:"Maximum expiry of the stored secrets in seconds"`
|
MaxSecretExpiry int64 `flag:"max-secret-expiry" default:"0" description:"Maximum expiry of the stored secrets in seconds"`
|
||||||
|
DefaultSecretExpiry int64 `flag:"default-secret-expiry" default:"0" description:"Default expiry of the stored secrets in seconds"`
|
||||||
StorageType string `flag:"storage-type" default:"mem" description:"Storage to use for putting secrets to" validate:"nonzero"`
|
StorageType string `flag:"storage-type" default:"mem" description:"Storage to use for putting secrets to" validate:"nonzero"`
|
||||||
VersionAndExit bool `flag:"version" default:"false" description:"Print version information and exit"`
|
VersionAndExit bool `flag:"version" default:"false" description:"Print version information and exit"`
|
||||||
}
|
}
|
||||||
|
@ -155,6 +156,7 @@ func main() {
|
||||||
// Start server
|
// Start server
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"max_secret_expiry": time.Duration(cfg.MaxSecretExpiry) * time.Second,
|
"max_secret_expiry": time.Duration(cfg.MaxSecretExpiry) * time.Second,
|
||||||
|
"default_secret_expiry": time.Duration(cfg.DefaultSecretExpiry) * time.Second,
|
||||||
"version": version,
|
"version": version,
|
||||||
}).Info("ots started")
|
}).Info("ots started")
|
||||||
|
|
||||||
|
@ -212,11 +214,13 @@ func handleIndex(w http.ResponseWriter, _ *http.Request) {
|
||||||
Customize customization.Customize
|
Customize customization.Customize
|
||||||
InlineContentNonce string
|
InlineContentNonce string
|
||||||
MaxSecretExpiry int64
|
MaxSecretExpiry int64
|
||||||
|
DefaultSecretExpiry int64
|
||||||
Version string
|
Version string
|
||||||
}{
|
}{
|
||||||
Customize: cust,
|
Customize: cust,
|
||||||
InlineContentNonce: inlineContentNonceStr,
|
InlineContentNonce: inlineContentNonceStr,
|
||||||
MaxSecretExpiry: cfg.MaxSecretExpiry,
|
MaxSecretExpiry: cfg.MaxSecretExpiry,
|
||||||
|
DefaultSecretExpiry: cfg.DefaultSecretExpiry,
|
||||||
Version: version,
|
Version: version,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
http.Error(w, errors.Wrap(err, "executing template").Error(), http.StatusInternalServerError)
|
http.Error(w, errors.Wrap(err, "executing template").Error(), http.StatusInternalServerError)
|
||||||
|
|
|
@ -114,6 +114,8 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
/* global maxSecretExpire */
|
/* global maxSecretExpire */
|
||||||
|
/* global defaultSecretExpire */
|
||||||
|
|
||||||
|
|
||||||
import appCrypto from '../crypto.js'
|
import appCrypto from '../crypto.js'
|
||||||
import { bytesToHuman } from '../helpers'
|
import { bytesToHuman } from '../helpers'
|
||||||
|
@ -220,7 +222,7 @@ export default {
|
||||||
fileSize: 0,
|
fileSize: 0,
|
||||||
secret: '',
|
secret: '',
|
||||||
securePassword: null,
|
securePassword: null,
|
||||||
selectedExpiry: null,
|
selectedExpiry: defaultSecretExpire,
|
||||||
selectedFileMeta: [],
|
selectedFileMeta: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue