diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-04-11 20:08:13 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-04-11 20:10:14 +0300 |
commit | e2cd2b783b44e09da4368bb361dd75e7026b1444 (patch) | |
tree | 7531b2b8aaf544e8292d37b1100ce60c1c5f68c7 /lualib/rspamadm | |
parent | 36590c124e4f134bc4d048fff89a9b0309198663 (diff) | |
download | rspamd-e2cd2b783b44e09da4368bb361dd75e7026b1444.tar.gz rspamd-e2cd2b783b44e09da4368bb361dd75e7026b1444.zip |
[Minor] Validate expire value in configwizard
Diffstat (limited to 'lualib/rspamadm')
-rw-r--r-- | lualib/rspamadm/configwizard.lua | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lualib/rspamadm/configwizard.lua b/lualib/rspamadm/configwizard.lua index 941590156..95febf719 100644 --- a/lualib/rspamadm/configwizard.lua +++ b/lualib/rspamadm/configwizard.lua @@ -74,6 +74,30 @@ local function readline_default(greet, def_value) return reply end +local function readline_expire() + local expire = '100d' + repeat + expire = readline_default("Expire time for new tokens [" .. expire .. "]: ", + expire) + expire = lua_util.parse_time_interval(expire) + + if not expire then + expire = '100d' + elseif expire > 2147483647 then + printf("The maximum possible value is 2147483647 (about 68y)") + expire = '68y' + elseif expire < -1 then + printf("The value must be a non-negative integer or -1") + expire = -1 + elseif expire ~= math.floor(expire) then + printf("The value must be an integer") + expire = math.floor(expire) + else + return expire + end + until false +end + local function print_changes(changes) local function print_change(k, c, where) printf('File: %s, changes list:', highlight(local_conf .. '/' @@ -337,10 +361,7 @@ local function check_redis_classifier(cls, changes) local function try_convert(update_config) if ask_yes_no("Do you wish to convert data to the new schema?", true) then - local expire = readline_default("Expire time for new tokens [default: 100d]: ", - '100d') - expire = lua_util.parse_time_interval(expire) - + local expire = readline_expire() if not lua_stat_tools.convert_bayes_schema(parsed_redis, symbol_spam, symbol_ham, expire) then printf("Conversion failed") @@ -460,10 +481,7 @@ local function setup_statistic(cfg, changes) local parsed_redis = {} if lua_redis.try_load_redis_servers(redis_params, nil, parsed_redis) then printf('You have %d sqlite classifiers', #sqlite_configs) - local expire = readline_default("Expire time for new tokens [default: 100d]: ", - '100d') - expire = lua_util.parse_time_interval(expire) - + local expire = readline_expire() local reset_previous = ask_yes_no("Reset previous data?") if ask_yes_no('Do you wish to convert them to Redis?', true) then |