#!/usr/bin/luaweb
json = require("json")
omg = require("omg")

dofile("/data/config.lua")

if config~=nil and config.struct_Box~=nil and config.struct_Box.bool_SnmpRawConfig==true and config.struct_Box.string_SnmpRawConfigContent~=nil then
      local f
      f = io.open("/etc/snmp/snmpd.conf", "w")
      if f then
      	 local s = "#LOCKED\n#RAWSNMP\n\n"
         s = s .. string.gsub(config.struct_Box.string_SnmpRawConfigContent,"(.-)\n","%1\n")
      	 f:write(s)
      	 f:close()
      end
elseif config~=nil and config.struct_Box~=nil and config.struct_Box.bool_SnmpRawConfig~=true then
    os.execute("if grep -q '^#RAWSNMP$' /etc/snmp/snmpd.conf;then rm -f /etc/snmp/snmpd.conf; fi")
end
os.execute("switchsnmp.sh")
