-- vim:set ft=lua: dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua') ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE) ct:Append(DOCTYPE_HTML4_STRICT..[=[ 設定/ネットワーク設定 - EDCB

設定/ネットワーク設定

]=]) appIni='EpgDataCap_Bon.ini' function GetItemList(tcp) local count=tonumber(edcb.GetPrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','Count',0,appIni)) or 0 local ret={} for i=1,count do local ip=edcb.GetPrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','IP'..(i-1),2130706433,appIni) if ip:find('^%[.') then ip=ip:match('^%[(.*).$') else --IPv4 ip=tonumber(ip) or 0 ip=(ip<0 and 0x100000000 or 0)+ip ip=(math.floor(ip/256/256/256)%256)..'.'..(math.floor(ip/256/256)%256)..'.'..(math.floor(ip/256)%256)..'.'..(ip%256) end ret[i]={ ip=ip, port=tonumber(edcb.GetPrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','Port'..(i-1),not tcp and 1234 or ip~='0.0.0.1' and 2230 or 0,appIni)) or 0, broadcast=not tcp and edcb.GetPrivateProfile('SET_UDP','BroadCast'..(i-1),0,appIni)~='0' } end return ret end post=AssertPost() if post and not ALLOW_SETTING then post=nil ct:Append('
変更は許可されていません
\n') end if post then tcp=not not mg.get_var(post,'tcp') itemList=GetItemList(tcp) if mg.get_var(post,'add') then ip=(mg.get_var(post,'specip') or ''):match('^.+$') or mg.get_var(post,'ip') port=GetVarInt(post,'port',0) --IPアドレスっぽくないものを弾く if ip and port and ip:find('^[0-9A-Za-z%%.:]+$') and ip:find('[^%%.:]') and ip:find('[.:]') then if ip=='0.0.0.1' then --SrvPipeのPortは常に0 port=0 elseif ip=='0.0.0.2' and port>=100 then --PipeのPortは基本的に0 port=0 end broadcast=not tcp and GetVarInt(post,'broadcast')==1 for i,v in ipairs(itemList) do if v.ip==ip and v.port%65536==port%65536 and v.broadcast==broadcast then --既にある ip=nil break end end if ip then itemList[#itemList+1]={ip=ip,port=port,broadcast=broadcast} ct:Append('
追加しました
\n') end end elseif mg.get_var(post,'del') then index=GetVarInt(post,'index',1) if index and index<=#itemList then table.remove(itemList,index) ct:Append('
削除しました
\n') end end for i,v in ipairs(itemList) do ipA,ipB,ipC,ipD=v.ip:match('^([0-2]?[0-9]?[0-9])%.([0-2]?[0-9]?[0-9])%.([0-2]?[0-9]?[0-9])%.([0-2]?[0-9]?[0-9])$') if ipA then --IPv4。非負の整数に変換 ip=(tonumber(ipA) or 0)*256*256*256+(tonumber(ipB) or 0)*256*256+(tonumber(ipC) or 0)*256+(tonumber(ipD) or 0) ip=math.floor(ip<0x100000000 and (ip>=0x80000000 and ip-0x100000000 or ip>0 and ip) or 0) else ip='['..v.ip..']' end edcb.WritePrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','IP'..(i-1),ip,appIni) edcb.WritePrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','Port'..(i-1),v.port,appIni) if not tcp then edcb.WritePrivateProfile('SET_UDP','BroadCast'..(i-1),v.broadcast,appIni) end end edcb.WritePrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','Count',#itemList,appIni) for i=#itemList+1,999 do --掃除 if edcb.GetPrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','IP'..(i-1),'',appIni)=='' then break end edcb.WritePrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','IP'..(i-1),nil,appIni) edcb.WritePrivateProfile(tcp and 'SET_TCP' or 'SET_UDP','Port'..(i-1),nil,appIni) if not tcp then edcb.WritePrivateProfile('SET_UDP','BroadCast'..(i-1),nil,appIni) end end end edcb.htmlEscape=15 ct:Append([=[ UDP送信先
]=]) for i,v in ipairs(GetItemList(false)) do ct:Append([=[
]=]..v.ip..' Port '..v.port..('-')..(v.port+29)..(v.broadcast and ' (Broadcast)' or '')..[=[
]=]) end ct:Append([=[ ※複数の起動があった場合、自動的にPortが+1されます。
※ブロードキャストとして送信する場合は、ブロードキャストアドレスを指定してください。
※仕様によりドロップすることがあるので、とくに理由がなければTCP送信の利用をお勧めします。
Port
TCP送信先
]=]) for i,v in ipairs(GetItemList(true)) do ct:Append([=[
]=]..v.ip..' Port '..v.port..('-')..(v.port+29)..(v.ip=='0.0.0.1' and ' (SrvPipe)' or v.ip=='0.0.0.2' and ' (Pipe)' or '')..[=[
]=]) end ct:Append([=[ ※複数の起動があった場合、自動的にPortが+1されます。
Port
]=]) ct:Finish() mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)..'\r\n'))