allow disabling file detections for paths
This commit is contained in:
parent
c746c1931d
commit
f26b977783
@ -261,9 +261,13 @@ func (i *FileInfo) readListing(checker rules.Checker) error {
|
||||
} else {
|
||||
listing.NumFiles++
|
||||
|
||||
err := file.detectType(true, false)
|
||||
if err != nil {
|
||||
return err
|
||||
if checker.IsTypeDetectDisabled(file.Path) {
|
||||
file.Type = "blob"
|
||||
} else {
|
||||
err := file.detectType(true, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
56
frontend/src/components/settings/DisableTypeDetections.vue
Normal file
56
frontend/src/components/settings/DisableTypeDetections.vue
Normal file
@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<form class="rules small">
|
||||
<div v-for="(disableTypeDetection, index) in disableTypeDetections" :key="index">
|
||||
<input type="checkbox" v-model="disableTypeDetection.regex"><label>Regex</label>
|
||||
|
||||
<input
|
||||
@keypress.enter.prevent
|
||||
type="text"
|
||||
v-if="disableTypeDetection.regex"
|
||||
v-model="disableTypeDetection.regexp.raw"
|
||||
:placeholder="$t('settings.insertRegex')" />
|
||||
<input
|
||||
@keypress.enter.prevent
|
||||
type="text"
|
||||
v-else
|
||||
v-model="disableTypeDetection.path"
|
||||
:placeholder="$t('settings.insertPath')" />
|
||||
|
||||
<button class="button button--red" @click="remove($event, index)">-</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button class="button" @click="create" default="false">{{ $t('buttons.new') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'disableTypeDetections-textarea',
|
||||
props: ['disableTypeDetections'],
|
||||
methods: {
|
||||
remove (event, index) {
|
||||
event.preventDefault()
|
||||
let disableTypeDetections = [ ...this.disableTypeDetections ]
|
||||
disableTypeDetections.splice(index, 1)
|
||||
this.$emit('update:disableTypeDetections', [ ...disableTypeDetections ])
|
||||
},
|
||||
create (event) {
|
||||
event.preventDefault()
|
||||
|
||||
this.$emit('update:disableTypeDetections', [
|
||||
...this.disableTypeDetections,
|
||||
{
|
||||
allow: true,
|
||||
path: '',
|
||||
regex: false,
|
||||
regexp: {
|
||||
raw: ''
|
||||
}
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -36,12 +36,19 @@
|
||||
<p class="small">{{ $t('settings.rulesHelp') }}</p>
|
||||
<rules :rules.sync="user.rules" />
|
||||
</div>
|
||||
|
||||
<div v-if="!isDefault">
|
||||
<h3>{{ $t('settings.disableTypeDetections') }}</h3>
|
||||
<p class="small">{{ $t('settings.disableTypeDetectionsHelp') }}</p>
|
||||
<disableTypeDetections :disableTypeDetections.sync="user.disableTypeDetections" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Languages from './Languages'
|
||||
import Rules from './Rules'
|
||||
import DisableTypeDetections from './DisableTypeDetections'
|
||||
import Permissions from './Permissions'
|
||||
import Commands from './Commands'
|
||||
import { enableExec } from '@/utils/constants'
|
||||
@ -52,6 +59,7 @@ export default {
|
||||
Permissions,
|
||||
Languages,
|
||||
Rules,
|
||||
DisableTypeDetections,
|
||||
Commands
|
||||
},
|
||||
props: [ 'user', 'isNew', 'isDefault' ],
|
||||
|
||||
@ -161,6 +161,8 @@
|
||||
"ruleExample2": "blocks the access to the file named Caddyfile on the root of the scope.",
|
||||
"rules": "Rules",
|
||||
"rulesHelp": "Here you can define a set of allow and disallow rules for this specific user. The blocked files won't show up in the listings and they wont be accessible to the user. We support regex and paths relative to the users scope.\n",
|
||||
"disableTypeDetections": "Disable File Type Detections",
|
||||
"disableTypeDetectionsHelp": "Here you can define a set of paths to disable file type detections for this specific user. Useful when the path is a network drive or has a lot of files. We support regex and paths relative to the users scope.\n",
|
||||
"scope": "Scope",
|
||||
"settingsUpdated": "Settings updated!",
|
||||
"user": "User",
|
||||
|
||||
@ -160,6 +160,8 @@
|
||||
"ruleExample2": "阻止用户访问其目录范围的根目录下名为 Caddyfile 的文件。",
|
||||
"rules": "规则",
|
||||
"rulesHelp": "您可以为该用户制定一组黑名单或白名单式的规则,被屏蔽的文件将不会显示在列表中,用户也无权限访问,支持相对于目录范围的路径。",
|
||||
"disableTypeDetections": "关闭文件类型检测",
|
||||
"disableTypeDetectionsHelp": "您可以为该用户制定一组不会检测文件类型的路径,当路径是挂载的网络磁盘或者文件较多时能加快反应速度,支持相对于目录范围的路径。",
|
||||
"scope": "目录范围",
|
||||
"settingsUpdated": "设置已更新!",
|
||||
"user": "用户",
|
||||
@ -244,4 +246,4 @@
|
||||
"downloadFile": "下载文件",
|
||||
"downloadFolder": "下载文件夹"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
http/data.go
12
http/data.go
@ -47,6 +47,18 @@ func (d *data) Check(path string) bool {
|
||||
return allow
|
||||
}
|
||||
|
||||
func (d *data) IsTypeDetectDisabled(path string) bool {
|
||||
if d.Check(path) {
|
||||
for _, rule := range d.user.DisableTypeDetections {
|
||||
if rule.Matches(path) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func handle(fn handleFunc, prefix string, store *storage.Storage, server *settings.Server) http.Handler {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
settings, err := store.Settings.Get()
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
// Checker is a Rules checker.
|
||||
type Checker interface {
|
||||
Check(path string) bool
|
||||
IsTypeDetectDisabled(path string) bool
|
||||
}
|
||||
|
||||
// Rule is a allow/disallow rule.
|
||||
|
||||
@ -21,20 +21,21 @@ const (
|
||||
|
||||
// User describes a user.
|
||||
type User struct {
|
||||
ID uint `storm:"id,increment" json:"id"`
|
||||
Username string `storm:"unique" json:"username"`
|
||||
Password string `json:"password"`
|
||||
Scope string `json:"scope"`
|
||||
Locale string `json:"locale"`
|
||||
LockPassword bool `json:"lockPassword"`
|
||||
ViewMode ViewMode `json:"viewMode"`
|
||||
SingleClick bool `json:"singleClick"`
|
||||
Perm Permissions `json:"perm"`
|
||||
Commands []string `json:"commands"`
|
||||
Sorting files.Sorting `json:"sorting"`
|
||||
Fs afero.Fs `json:"-" yaml:"-"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
HideDotfiles bool `json:"hideDotfiles"`
|
||||
ID uint `storm:"id,increment" json:"id"`
|
||||
Username string `storm:"unique" json:"username"`
|
||||
Password string `json:"password"`
|
||||
Scope string `json:"scope"`
|
||||
Locale string `json:"locale"`
|
||||
LockPassword bool `json:"lockPassword"`
|
||||
ViewMode ViewMode `json:"viewMode"`
|
||||
SingleClick bool `json:"singleClick"`
|
||||
Perm Permissions `json:"perm"`
|
||||
Commands []string `json:"commands"`
|
||||
Sorting files.Sorting `json:"sorting"`
|
||||
Fs afero.Fs `json:"-" yaml:"-"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
HideDotfiles bool `json:"hideDotfiles"`
|
||||
DisableTypeDetections []rules.Rule `json:"disableTypeDetections"`
|
||||
}
|
||||
|
||||
// GetRules implements rules.Provider.
|
||||
@ -50,6 +51,7 @@ var checkableFields = []string{
|
||||
"Commands",
|
||||
"Sorting",
|
||||
"Rules",
|
||||
"DisableTypeDetections",
|
||||
}
|
||||
|
||||
// Clean cleans up a user and verifies if all its fields
|
||||
@ -86,6 +88,10 @@ func (u *User) Clean(baseScope string, fields ...string) error {
|
||||
if u.Rules == nil {
|
||||
u.Rules = []rules.Rule{}
|
||||
}
|
||||
case "DisableTypeDetections":
|
||||
if u.DisableTypeDetections == nil {
|
||||
u.DisableTypeDetections = []rules.Rule{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user