📄 sort.lua.svn-base
字号:
#!/usr/bin/lua-- Copyright (C) 2008 OpenRB.comrequire('fslib')data = datajson() or {}if (data.id ~= nil and data.extra ~= nil) then fw = uci.get_array('firewall') moveid = data.id moveto = data.extra found = false -- scan through fw config, found id of next and previous rules for i, params in ipairs(fw) do type = params['.type'] id = params['.name'] if (type == 'rule' or type == 'redirect') then if (found) then nextid = id nextnum = i break elseif (id == moveid) then found = true movenum = i else previd = id prevnum = i end end end -- make sure we are not moving first rule up and last one down if (moveto == 'up' and previd ~= nil) then switchid = previd switchnum = prevnum elseif (moveto == 'down' and nextid ~= nil) then switchid = nextid switchnum = nextnum end -- found id to switch values, delete all previous values and set new if (switchid ~= nil) then uci.set('firewall', moveid, fw[ switchnum ]['.type']) uci.set('firewall', switchid, fw[ movenum ]['.type']) for param, value in pairs(fw[ movenum ]) do first = param:sub(1,1) if (first == '.') then fw[ movenum ][ param ] = nil else uci.delete('firewall', moveid, param) end end for param, value in pairs(fw[ switchnum ]) do first = param:sub(1,1) if (first == '.') then fw[ switchnum ][ param ] = nil else uci.delete('firewall', switchid, param) end end for param, value in pairs(fw[ movenum ]) do uci.set('firewall', switchid, param, value) end for param, value in pairs(fw[ switchnum ]) do uci.set('firewall', moveid, param, value) end uci.commit('firewall') endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -