Browse Source

validate user's empty config

rufengsuixing 5 years ago
parent
commit
a6e6d5cbe3
1 changed files with 6 additions and 0 deletions
  1. 6 0
      luasrc/model/cbi/AdGuardHome/base.lua

+ 6 - 0
luasrc/model/cbi/AdGuardHome/base.lua

@@ -70,7 +70,9 @@ o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin
 o.default     = "/usr/bin/AdGuardHome/AdGuardHome"
 o.default     = "/usr/bin/AdGuardHome/AdGuardHome"
 o.datatype    = "string"
 o.datatype    = "string"
 o.optional = false
 o.optional = false
+o.rmempty=false
 o.validate=function(self, value)
 o.validate=function(self, value)
+if value=="" then return nil end
 if fs.stat(value,"type")=="dir" then
 if fs.stat(value,"type")=="dir" then
 	fs.rmdir(value)
 	fs.rmdir(value)
 end
 end
@@ -100,7 +102,9 @@ o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHo
 o.default     = "/etc/AdGuardHome.yaml"
 o.default     = "/etc/AdGuardHome.yaml"
 o.datatype    = "string"
 o.datatype    = "string"
 o.optional = false
 o.optional = false
+o.rmempty=false
 o.validate=function(self, value)
 o.validate=function(self, value)
+if value==nil then return nil end
 if fs.stat(value,"type")=="dir" then
 if fs.stat(value,"type")=="dir" then
 	fs.rmdir(value)
 	fs.rmdir(value)
 end
 end
@@ -119,7 +123,9 @@ o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome wor
 o.default     = "/usr/bin/AdGuardHome"
 o.default     = "/usr/bin/AdGuardHome"
 o.datatype    = "string"
 o.datatype    = "string"
 o.optional = false
 o.optional = false
+o.rmempty=false
 o.validate=function(self, value)
 o.validate=function(self, value)
+if value=="" then return nil end
 if fs.stat(value,"type")=="reg" then
 if fs.stat(value,"type")=="reg" then
 	if m.message then
 	if m.message then
 	m.message =m.message.."\nerror!work dir is a file"
 	m.message =m.message.."\nerror!work dir is a file"