Merge 0.9->trunk
authorKim Alvefur <zash@zash.se>
Sat, 18 May 2013 11:20:46 +0000 (13:20 +0200)
committerKim Alvefur <zash@zash.se>
Sat, 18 May 2013 11:20:46 +0000 (13:20 +0200)
1  2 
plugins/mod_admin_telnet.lua
util/ip.lua

Simple merge
diff --cc util/ip.lua
index 6ebc023bae92fca058691f060c3ca316644ac04f,856bf03498261860db5796afccac66258c33beae..20ea3dd70594e4914116e15e1e8424b5bbd7a96d
@@@ -12,17 -12,16 +12,24 @@@ local ip_mt = { __index = function (ip
  local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111" };
  
  local function new_ip(ipStr, proto)
 -      if proto ~= "IPv4" and proto ~= "IPv6" then
 +      if not proto then
 +              local sep = ipStr:match("^%x+(.)");
 +              if sep == ":" then proto = "IPv6"
 +              elseif sep == "." then proto = "IPv4"
 +              end
 +              if not proto then
 +                      return nil, "invalid address";
 +              end
 +      elseif proto ~= "IPv4" and proto ~= "IPv6" then
                return nil, "invalid protocol";
        end
+       if proto == "IPv6" and ipStr:find('.', 1, true) then
+               local changed;
+               ipStr, changed = ipStr:gsub(":(%d+)%.(%d+)%.(%d+)%.(%d+)$", function(a,b,c,d)
+                       return (":%04X:%04X"):format(a*256+b,c*256+d);
+               end);
+               if changed ~= 1 then return nil, "invalid-address"; end
+       end
  
        return setmetatable({ addr = ipStr, proto = proto }, ip_mt);
  end