[jetrix-cvs] SF.net SVN: jetrix:[823] monitor/trunk/src/main/webapp/server-add.jsp
Brought to you by:
smanux
From: <sm...@us...> - 2010-02-22 16:17:35
|
Revision: 823 http://jetrix.svn.sourceforge.net/jetrix/?rev=823&view=rev Author: smanux Date: 2010-02-22 16:17:29 +0000 (Mon, 22 Feb 2010) Log Message: ----------- Accept only global unicast addresses Modified Paths: -------------- monitor/trunk/src/main/webapp/server-add.jsp Modified: monitor/trunk/src/main/webapp/server-add.jsp =================================================================== --- monitor/trunk/src/main/webapp/server-add.jsp 2010-02-22 15:16:11 UTC (rev 822) +++ monitor/trunk/src/main/webapp/server-add.jsp 2010-02-22 16:17:29 UTC (rev 823) @@ -3,50 +3,58 @@ <%@ page import="java.net.InetSocketAddress" %> <%@ page import="java.net.Socket" %> <%@ page import="java.util.Date" %> -<%@ page import="org.springframework.web.context.ContextLoader" %> -<%@ page import="org.springframework.web.context.WebApplicationContext" %> <%@ page import="net.jetrix.monitor.ServerInfo" %> <%@ page import="net.jetrix.monitor.dao.IpToCountryDao" %> <%@ page import="net.jetrix.monitor.dao.ServerInfoDao" %> +<%@ page import="org.springframework.web.context.ContextLoader" %> +<%@ page import="org.springframework.web.context.WebApplicationContext" %> <% String hostname = request.getParameter("hostname"); - + try { // lookup the IP InetAddress address = InetAddress.getByName(hostname); - + + if (address.isLoopbackAddress() + || address.isLinkLocalAddress() + || address.isSiteLocalAddress() + || address.isMulticastAddress()) { + // multicast and non routable addresses are ignored + return; + } + WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); ServerInfoDao dao = (ServerInfoDao) context.getBean("serverInfoDao"); IpToCountryDao countryDao = (IpToCountryDao) context.getBean("ipToCountryDao"); - + ServerInfo server = new ServerInfo(); server.setHostname(hostname); server.setIP(address.getHostAddress()); server.setDateAdded(new Date()); server.setCountry(countryDao.getCountry(address)); - + // lookup the hostname if the IP was specified if (address.getHostAddress().equals(hostname)) { server.setHostname(address.getCanonicalHostName()); } - + // check if the tetrinet port is opened long t0 = System.currentTimeMillis(); Socket socket = new Socket(); socket.connect(new InetSocketAddress(address, 31457), 15000); long t1 = System.currentTimeMillis(); socket.close(); - + server.getStats().setPing((int) (t1 - t0)); - - if (!dao.exists(server) && !address.isLoopbackAddress()) + + if (!dao.exists(server)) { dao.save(server); out.println("server added " + address); } - + // todo register the alias if the server is already registered } catch (IOException e) @@ -54,6 +62,8 @@ out.println(e.getMessage()); // server ignored } - - response.sendRedirect("index.jsp"); + finally + { + response.sendRedirect("index.jsp"); + } %> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |