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