IDEMPIERE-391 Scheduler improvements / Evaluate IP address and hostname in all network interfaces / thanks to Juliana

This commit is contained in:
Carlos Ruiz 2012-12-04 17:05:47 -05:00
parent 23d6953cc8
commit 570d61b7aa
1 changed files with 29 additions and 26 deletions

View File

@ -21,7 +21,9 @@ import it.sauronsoftware.cron4j.Predictor;
import it.sauronsoftware.cron4j.SchedulingPattern; import it.sauronsoftware.cron4j.SchedulingPattern;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
@ -31,6 +33,7 @@ import java.util.regex.PatternSyntaxException;
import org.compiere.util.CCache; import org.compiere.util.CCache;
public class MSchedule extends X_AD_Schedule public class MSchedule extends X_AD_Schedule
{ {
/** /**
@ -107,36 +110,36 @@ public class MSchedule extends X_AD_Schedule
* @param ipOnly * @param ipOnly
* @return true if IP is correct * @return true if IP is correct
*/ */
private boolean checkIP(String ipOnly) private boolean checkIP(String ipOnly) {
{ try {
try for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
{ {
InetAddress box = InetAddress.getLocalHost(); NetworkInterface intf = en.nextElement();
String ip = box.getHostAddress(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
if (chekIPFormat(ipOnly)) { {
if (ipOnly.indexOf(ip) == -1) { InetAddress inetAddress = enumIpAddr.nextElement();
if ( !inetAddress.isLoopbackAddress()
log.fine("Not allowed here - IP=" + ip + " does not match "+ ipOnly); && !inetAddress.isLinkLocalAddress()
return false; && inetAddress.isSiteLocalAddress())
{
String retVal = inetAddress.getHostAddress().toString();
if (chekIPFormat(ipOnly)) {
retVal = inetAddress.getHostAddress().toString();
} else {
retVal = inetAddress.getHostName();
}
if (ipOnly.equals(retVal)) {
log.fine("Allowed here - IP=" + retVal+ " match");
return true;
}
}
} }
log.fine("Allowed here - IP=" + ip + " matches " + ipOnly);
} }
else{ } catch (Exception e) {
String hostname=box.getHostName();
if(! ipOnly.equals(hostname)){
log.fine("Not Allowed here -hostname " + hostname + " does not match "+ipOnly);
return false;
}
log.fine("Allowed here - hostname=" + hostname + " matches " + ipOnly);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e); log.log(Level.SEVERE, "", e);
return false;
} }
return true; return false;
} // checkIP } // checkIP
public static MSchedule get(Properties ctx, int AD_Schedule_ID) public static MSchedule get(Properties ctx, int AD_Schedule_ID)
{ {