From: bert hubert Date: Sat, 9 Dec 2017 15:37:07 +0000 (+0100) Subject: LOC fun X-Git-Tag: dnsdist-1.3.1~136^2~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0540d223cfae15d060c8ca5016ebd67b3daa3eca;p=thirdparty%2Fpdns.git LOC fun --- diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 282f181bd5..4b22e1930c 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -7,6 +7,20 @@ #include "ueberbackend.hh" #include #include "../../modules/geoipbackend/geoipbackend.hh" + +/* to do: + global allow-lua-record setting + zone metadata setting + fix compilation/linking with/without geoipbackend + use weak symbol? + unify ifupurl/ifupport + add attribute for query source + add attribute for certificate chedk + add list of current monitors + expire them too? + + */ + class IsUpOracle { private: @@ -236,6 +250,57 @@ static bool getLatLon(const std::string& ip, double& lat, double& lon) return true; } +static bool getLatLon(const std::string& ip, string& loc) +{ + int latdeg, latmin, londeg, lonmin; + double latsec, lonsec; + char lathem='X', lonhem='X'; + + double lat, lon; + if(!getLatLon(ip, lat, lon)) + return false; + + if(lat > 0) { + lathem='N'; + } + else { + lat = -lat; + lathem='S'; + } + + if(lon > 0) { + lonhem='E'; + } + else { + lon = -lon; + lonhem='W'; + } + + /* + >>> deg = int(R) + >>> min = int((R - int(R)) * 60.0) + >>> sec = (((R - int(R)) * 60.0) - min) * 60.0 + >>> print("{}º {}' {}\"".format(deg, min, sec)) + */ + + + latdeg = lat; + latmin = (lat - latdeg)*60.0; + latsec = (((lat - latdeg)*60.0) - latmin)*60.0; + + londeg = lon; + lonmin = (lon - londeg)*60.0; + lonsec = (((lon - londeg)*60.0) - lonmin)*60.0; + + // 51 59 00.000 N 5 55 00.000 E 4.00m 1.00m 10000.00m 10.00m + + boost::format fmt("%d %d %d %c %d %d %d %c 0.00m 1.00m 10000.00m 10.00m"); + + loc= (fmt % latdeg % latmin % latsec % lathem % londeg % lonmin % lonsec % lonhem ).str(); + return true; +} + + static ComboAddress closest(const ComboAddress& bestwho, vector& wips) { @@ -273,28 +338,32 @@ std::vector> luaSynth(const std::string& code, cons lua.writeVariable("who", dnsp.getRemote()); ComboAddress bestwho; if(dnsp.hasEDNSSubnet()) { - lua.writeVariable("ecs-who", dnsp.getRealRemote()); + lua.writeVariable("ecswho", dnsp.getRealRemote()); bestwho=dnsp.getRealRemote().getNetwork(); - lua.writeVariable("best-who", dnsp.getRealRemote().getNetwork()); + lua.writeVariable("bestwho", dnsp.getRealRemote().getNetwork()); } else { - lua.writeVariable("ecs-who", dnsp.getRemote()); bestwho=dnsp.getRemote(); } lua.writeFunction("latlon", [&bestwho]() { - double lat, lon; - getLatLon(bestwho.toString(), lat, lon); - return std::to_string(lat)+" "+std::to_string(lon); + double lat, lon; + getLatLon(bestwho.toString(), lat, lon); + return std::to_string(lat)+" "+std::to_string(lon); + }); + + lua.writeFunction("latlonloc", [&bestwho]() { + string loc; + getLatLon(bestwho.toString(), loc); + cout<<"loc: "< candidates; for(auto l : query.getRawLabels()) { boost::replace_all(l, "-", "."); - cout<> luaSynth(const std::string& code, cons } } - return closest(bestwho, candidates); + return closest(bestwho, candidates).toString(); });