fixed sonar bugs
This commit is contained in:
@ -1,7 +1,3 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import static java.lang.Long.valueOf;
|
||||
@ -47,7 +43,7 @@ public class CidrTool {
|
||||
}
|
||||
|
||||
|
||||
public static final int[] CIDR2MASK = new int[]{0x00000000, 0x80000000,
|
||||
protected static final int[] CIDR2MASK = new int[]{0x00000000, 0x80000000,
|
||||
0xC0000000, 0xE0000000, 0xF0000000, 0xF8000000, 0xFC000000,
|
||||
0xFE000000, 0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
|
||||
0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
|
||||
|
||||
@ -4,12 +4,15 @@ import de.muehlencord.shared.network.whois.NetworkInformation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class NetworkScanner {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(NetworkScanner.class);
|
||||
|
||||
private String networkString;
|
||||
private NetworkInformation networkInformation = null; // TODO add scan for information
|
||||
@ -25,15 +28,15 @@ public class NetworkScanner {
|
||||
|
||||
PortScanner portScanner = new PortScanner(20,1,1024);
|
||||
for (String currentAddress : addresses) {
|
||||
System.out.print ("Scanning "+currentAddress+"....");
|
||||
LOGGER.info("Scanning "+currentAddress+"....");
|
||||
List<PortInformation> portInformation = portScanner.scan(currentAddress);
|
||||
if (atLeastOnePortOpen(portInformation)) {
|
||||
IpInformation ipInformation = new IpInformation(currentAddress);
|
||||
ipInformation.setPortInformation(portInformation);
|
||||
ipinformationList.add (ipInformation);
|
||||
System.out.println ("open ports found");
|
||||
LOGGER.info ("open ports found");
|
||||
} else {
|
||||
System.out.println ("not found");
|
||||
LOGGER.info ("not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,13 +5,16 @@ import java.net.Socket;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class PortScan {
|
||||
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(PortScan.class);
|
||||
|
||||
private PortScan() {
|
||||
// hide constructor
|
||||
}
|
||||
@ -25,16 +28,13 @@ public class PortScan {
|
||||
Socket socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(ip, port), timeout);
|
||||
socket.close();
|
||||
return new PortInformation (port, true);
|
||||
return new PortInformation(port, true);
|
||||
} catch (Exception ex) {
|
||||
return new PortInformation (port, false);
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
return new PortInformation(port, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -7,12 +7,15 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class PortScanner {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(PortScanner.class);
|
||||
|
||||
private final int startPort;
|
||||
private final int endPort;
|
||||
@ -42,9 +45,8 @@ public class PortScanner {
|
||||
for (final Future<PortInformation> f : futures) {
|
||||
resultList.add(f.get());
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace(); // FIXME add error handling
|
||||
} catch (ExecutionException ex) {
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
LOGGER.error(ex.toString(), ex);
|
||||
}
|
||||
|
||||
return resultList;
|
||||
|
||||
@ -5,15 +5,12 @@ import com.enterprisedt.net.ftp.FTPConnectMode;
|
||||
import com.enterprisedt.net.ftp.FTPException;
|
||||
import com.enterprisedt.net.ftp.FTPFile;
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import static java.util.Locale.getDefault;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -24,7 +21,7 @@ public class FTPConnection {
|
||||
/** the default timeout in ms */
|
||||
public static final int DEFAULTTIMEOUT = 30000;
|
||||
/** the logger object */
|
||||
private final Logger logger = getLogger(FTPConnection.class);
|
||||
private final Logger LOGGER = Logger.getLogger(FTPConnection.class);
|
||||
/** the username to connect with */
|
||||
private String userName;
|
||||
/** the password to connect with */
|
||||
@ -44,7 +41,7 @@ public class FTPConnection {
|
||||
* @param password the password to connect with
|
||||
*/
|
||||
public FTPConnection(String remoteHost, String userName, String password) {
|
||||
this(remoteHost, userName, password, getDefault());
|
||||
this(remoteHost, userName, password, Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,8 +83,8 @@ public class FTPConnection {
|
||||
try {
|
||||
client.quit();
|
||||
} catch (IOException | FTPException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,8 +104,8 @@ public class FTPConnection {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
@ -133,8 +130,8 @@ public class FTPConnection {
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -160,8 +157,8 @@ public class FTPConnection {
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -187,8 +184,8 @@ public class FTPConnection {
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -215,8 +212,8 @@ public class FTPConnection {
|
||||
client.put(localFilename, remoteName, false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -233,8 +230,8 @@ public class FTPConnection {
|
||||
try {
|
||||
client.rename(remoteOldName, remoteNewName);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while renaming file. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,11 +193,13 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
*/
|
||||
@Override
|
||||
public String getFolder(String folderPath) throws MailReaderException {
|
||||
String returnValue = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<Folder> folderList = getFolderPath(folderPath);
|
||||
for (Folder folder : folderList) {
|
||||
returnValue += folder.getName() + "/";
|
||||
sb.append (folder.getName());
|
||||
sb.append ("/");
|
||||
}
|
||||
String returnValue = sb.toString();
|
||||
if (returnValue.endsWith("/")) {
|
||||
returnValue = returnValue.substring(0, returnValue.length() - 1);
|
||||
}
|
||||
@ -407,7 +409,8 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
message.setFlag(Flags.Flag.DELETED, true);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (MessagingException | MailReaderException ex) {
|
||||
LOGGER.debug(ex.getMessage(), ex);
|
||||
} finally {
|
||||
if ((df != null) && (df.isOpen())) {
|
||||
try {
|
||||
@ -458,7 +461,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
cmsg.getContentType();
|
||||
return cmsg;
|
||||
} catch (MessagingException ex) {
|
||||
LOGGER.debug("Access via copy constructor failed, trying byte array constructor");
|
||||
LOGGER.debug("Access via copy constructor failed, trying byte array constructor. "+ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -476,7 +479,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
|
||||
return cmsg;
|
||||
} catch (Exception ex) {
|
||||
LOGGER.debug("Also fallback solution did not work");
|
||||
LOGGER.debug("Also fallback solution did not work. "+ex.getMessage(), ex);
|
||||
throw initialException;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public class MailMessage {
|
||||
/** the html content of the message if avaialble, null else */
|
||||
private List<String> htmlContent;
|
||||
/** true, if content is html message body */
|
||||
private boolean isHtmlMessage;
|
||||
private boolean htmlMessage;
|
||||
/** the message id if available, null otherwise */
|
||||
private String messageId;
|
||||
/** the size of the message in bytes */
|
||||
@ -53,7 +53,7 @@ public class MailMessage {
|
||||
content.add(contentString);
|
||||
}
|
||||
this.htmlContent = new LinkedList<>();
|
||||
this.isHtmlMessage = false;
|
||||
this.htmlMessage = false;
|
||||
this.messageId = null;
|
||||
this.sender = null;
|
||||
this.receiver = new LinkedList<>();
|
||||
@ -88,12 +88,13 @@ public class MailMessage {
|
||||
}
|
||||
|
||||
private String getContent(List<String> contentList) {
|
||||
String returnValue = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String contentSeparator = "--------";
|
||||
for (String currentContent : contentList) {
|
||||
returnValue += currentContent;
|
||||
returnValue += contentSeparator; // FIXME make configurable
|
||||
sb.append (currentContent);
|
||||
sb.append (contentSeparator); // FIXME make configurable
|
||||
}
|
||||
String returnValue = sb.toString();
|
||||
if (returnValue.endsWith(contentSeparator)) {
|
||||
returnValue = returnValue.substring(0, returnValue.length() - contentSeparator.length());
|
||||
}
|
||||
@ -111,7 +112,7 @@ public class MailMessage {
|
||||
public void setContent(String c, boolean isHtmlContent) {
|
||||
if (c != null) {
|
||||
content.add(c);
|
||||
this.isHtmlMessage = isHtmlContent;
|
||||
this.htmlMessage = isHtmlContent;
|
||||
if (isHtmlContent) {
|
||||
this.htmlContent.add(c);
|
||||
}
|
||||
@ -140,7 +141,7 @@ public class MailMessage {
|
||||
* @return the isHtmlMessage
|
||||
*/
|
||||
public boolean isHtmlMessage() {
|
||||
return isHtmlMessage;
|
||||
return htmlMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Locale;
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
@ -18,7 +18,6 @@ import javax.mail.Multipart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
* Util class to convert between javax.mail.Message and MailMessage objects
|
||||
@ -28,7 +27,7 @@ import static org.apache.log4j.Logger.getLogger;
|
||||
public abstract class MailMessageUtils {
|
||||
|
||||
/** the logging object */
|
||||
private static final Logger logger = getLogger(MailMessageUtils.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(MailMessageUtils.class.getName());
|
||||
|
||||
/** content type of mutipart messages - e.g. multipart_alternative or _mixed */
|
||||
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
||||
@ -70,16 +69,16 @@ public abstract class MailMessageUtils {
|
||||
try {
|
||||
contentType = getContentType(mm.getContentType());
|
||||
subject = mm.getSubject();
|
||||
logger.debug("message subject = " + subject);
|
||||
LOGGER.debug("message subject = " + subject);
|
||||
messageId = getMessageId(message);
|
||||
logger.debug("messageid = " + messageId);
|
||||
logger.debug(mm.getSentDate());
|
||||
LOGGER.debug("messageid = " + messageId);
|
||||
LOGGER.debug(mm.getSentDate());
|
||||
|
||||
} catch (MessagingException ex) {
|
||||
throw new MailMessageException("Error while converting mime message. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
logger.debug("messageContentType = " + contentType);
|
||||
LOGGER.debug("messageContentType = " + contentType);
|
||||
|
||||
// handling multipart messages
|
||||
if (contentType.contains(CONTENTTYPE_MULTIPART)) {
|
||||
@ -88,23 +87,23 @@ public abstract class MailMessageUtils {
|
||||
try {
|
||||
Multipart mp = (Multipart) mm.getContent();
|
||||
int partsFound = mp.getCount();
|
||||
logger.debug(partsFound + " parts found");
|
||||
LOGGER.debug(partsFound + " parts found");
|
||||
for (int i = 0; i < partsFound; i++) {
|
||||
logger.debug("Working on multiPart " + (i + 1));
|
||||
LOGGER.debug("Working on multiPart " + (i + 1));
|
||||
BodyPart bp = mp.getBodyPart(i);
|
||||
String bodyContentType = getContentType(bp.getContentType());
|
||||
logger.debug("contentType = " + bodyContentType);
|
||||
LOGGER.debug("contentType = " + bodyContentType);
|
||||
|
||||
if (bodyContentType.contains(CONTENTTYPE_MULTIPART)) {
|
||||
MimeMultipart bodyMultiPart = (MimeMultipart) bp.getContent();
|
||||
int bodyPartCount = bodyMultiPart.getCount();
|
||||
logger.debug(bodyPartCount + " bodyMultiParts found");
|
||||
LOGGER.debug(bodyPartCount + " bodyMultiParts found");
|
||||
for (int currentBodyPart = 0; currentBodyPart < bodyPartCount; currentBodyPart++) {
|
||||
|
||||
logger.debug("Working on bodypart " + (currentBodyPart + 1));
|
||||
LOGGER.debug("Working on bodypart " + (currentBodyPart + 1));
|
||||
BodyPart bodyPart = bodyMultiPart.getBodyPart(currentBodyPart);
|
||||
String bodyPartContentType = getContentType(bodyPart.getContentType());
|
||||
logger.debug("bodyPart contentType = " + bodyPartContentType);
|
||||
LOGGER.debug("bodyPart contentType = " + bodyPartContentType);
|
||||
|
||||
if (bodyPartContentType.contains(CONTENTTYPE_TEXT_PLAIN)) {
|
||||
returnMessage.setContent(getContent(bodyPart), false);
|
||||
@ -117,21 +116,19 @@ public abstract class MailMessageUtils {
|
||||
if (bp.getFileName() == null) {
|
||||
returnMessage.setContent(getContent(bp), false);
|
||||
} else {
|
||||
logger.debug("Found base64 coded attachment - not yet supported, skipping");
|
||||
LOGGER.debug("Found base64 coded attachment - not yet supported, skipping");
|
||||
}
|
||||
|
||||
} else if (bodyContentType.equals(CONTENTTYPE_TEXT_HTML)) {
|
||||
returnMessage.setHtmlContent(getContent(bp));
|
||||
|
||||
} else if (bodyContentType.equals(CONTENTTYPE_APPLICATION_PGPSIGNATURE)) {
|
||||
logger.debug("Found pgp signature - not yet supported, skipping");
|
||||
LOGGER.debug("Found pgp signature - not yet supported, skipping");
|
||||
// TODO add pgp/signature support
|
||||
|
||||
} else if ((bodyContentType.contains(CONTENTTYPE_APPLICATION) || (bodyContentType.contains(CONTENTTYPE_MESSAGE))
|
||||
|| (bodyContentType.contains(CONTENTTYPE_TEXT)) || (bodyContentType.contains(CONTENTTYPE_IMAGE))
|
||||
|| (bodyContentType.contains(CONTENTTYPE_VIDEO)) || (bodyContentType.contains(CONTENTTYPE_AUDIO)))) {
|
||||
logger.debug("Found attachment - not yet supported, skipping");
|
||||
// TODO add attachment support
|
||||
} else if (isSupportedAttachmentType(bodyContentType)) {
|
||||
LOGGER.debug("Found attachment - not yet supported, skipping");
|
||||
// TODO add attachment support
|
||||
} else {
|
||||
throw new MailMessageException("Reading bodyContentType " + bodyContentType + " not yet implemented");
|
||||
}
|
||||
@ -177,19 +174,20 @@ public abstract class MailMessageUtils {
|
||||
} else if (contentType.contains(CONTENTTYPE_APPLICATION)) {
|
||||
// message with only attachment
|
||||
returnMessage = new MailMessage(subject, "", messageId);
|
||||
logger.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
||||
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
||||
} else if (contentType.contains(CONTENTTYPE_TEXT)) {
|
||||
returnMessage = new MailMessage(subject, "", messageId);
|
||||
logger.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
||||
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
|
||||
} else {
|
||||
String hint = "Unkonwn message format Converting MimeMessage of contentType " + contentType + " not yet implemented.";
|
||||
|
||||
try {
|
||||
logger.debug(mm.getContent().getClass());
|
||||
logger.debug(mm.getContent());
|
||||
logger.error(hint);
|
||||
LOGGER.debug(mm.getContent().getClass());
|
||||
LOGGER.debug(mm.getContent());
|
||||
LOGGER.error(hint);
|
||||
} catch (IOException | MessagingException ex) {
|
||||
logger.error(hint);
|
||||
LOGGER.debug (ex.toString(), ex);
|
||||
LOGGER.error(hint);
|
||||
}
|
||||
throw new MailMessageException(hint);
|
||||
}
|
||||
@ -233,7 +231,7 @@ public abstract class MailMessageUtils {
|
||||
if (contentType.contains(";")) {
|
||||
returnValue = contentType.substring(0, contentType.indexOf(';'));
|
||||
}
|
||||
returnValue = returnValue.toLowerCase();
|
||||
returnValue = returnValue.toLowerCase(Locale.US);
|
||||
returnValue = returnValue.trim();
|
||||
return returnValue;
|
||||
}
|
||||
@ -254,7 +252,7 @@ public abstract class MailMessageUtils {
|
||||
try {
|
||||
returnValue = bp.getContent().toString();
|
||||
} catch (java.io.UnsupportedEncodingException ex) {
|
||||
logger.debug(ex.getMessage());
|
||||
throw new MessagingException("Cannot read content from bodypart. "+ex.getMessage(), ex);
|
||||
} catch (java.io.IOException ioex) {
|
||||
throw new IOException("Cannot read content from bodypart.", ioex);
|
||||
} catch (MessagingException mex) {
|
||||
@ -300,16 +298,16 @@ public abstract class MailMessageUtils {
|
||||
output.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
logger.debug(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.debug(ex.getMessage());
|
||||
LOGGER.debug(getStackTraceString(ex));
|
||||
}
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
logger.debug(ex.getMessage());
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.debug(ex.getMessage());
|
||||
LOGGER.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
@ -331,4 +329,28 @@ public abstract class MailMessageUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true, if the contentType string is one of the known attachment types.
|
||||
*
|
||||
* @param contentType the contentType to check
|
||||
* @return true, if the contentType string is one of the known attachment types. False otherwise.
|
||||
*/
|
||||
private static boolean isSupportedAttachmentType(String contentType) {
|
||||
if (contentType.contains(CONTENTTYPE_APPLICATION)) {
|
||||
return true;
|
||||
} else if (contentType.contains(CONTENTTYPE_MESSAGE)) {
|
||||
return true;
|
||||
} else if (contentType.contains(CONTENTTYPE_TEXT)) {
|
||||
return true;
|
||||
} else if (contentType.contains(CONTENTTYPE_IMAGE)) {
|
||||
return true;
|
||||
} else if (contentType.contains(CONTENTTYPE_VIDEO)) {
|
||||
return true;
|
||||
} else if (contentType.contains(CONTENTTYPE_AUDIO)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,7 +14,7 @@ import static org.apache.log4j.Logger.getLogger;
|
||||
public abstract class MailReaderConfigurationFactory {
|
||||
|
||||
/** the logging object */
|
||||
private final static Logger logger = getLogger(MailReaderConfigurationFactory.class.getName());
|
||||
private final static Logger LOGGER = Logger.getLogger(MailReaderConfigurationFactory.class);
|
||||
|
||||
/**
|
||||
* reads the config file and creates a configured mailreader configuration
|
||||
@ -43,8 +41,8 @@ public abstract class MailReaderConfigurationFactory {
|
||||
try {
|
||||
is.close();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error while reading input file.");
|
||||
logger.debug(getStackTraceString(ex));
|
||||
LOGGER.error("Error while reading input file.");
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,15 +51,15 @@ public abstract class MailReaderConfigurationFactory {
|
||||
throw new MailReaderConfigurationException("property smtp.server not specified. Please check config");
|
||||
}
|
||||
String host = p.getProperty("imap.server");
|
||||
if ((smtpServer == null) || (smtpServer.isEmpty())) {
|
||||
if ((host == null) || (host.isEmpty())) {
|
||||
throw new MailReaderConfigurationException("property imap.server not specified. Please check config");
|
||||
}
|
||||
String userName = p.getProperty("imap.username");
|
||||
if ((smtpServer == null) || (smtpServer.isEmpty())) {
|
||||
if ((userName == null) || (userName.isEmpty())) {
|
||||
throw new MailReaderConfigurationException("property imap.username not specified. Please check config");
|
||||
}
|
||||
String password = p.getProperty("imap.password");
|
||||
if ((smtpServer == null) || (smtpServer.isEmpty())) {
|
||||
if ((password == null) || (password.isEmpty())) {
|
||||
throw new MailReaderConfigurationException("property imap.password not specified. Please check config");
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import de.muehlencord.shared.network.mail.MailReaderConfiguration;
|
||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||
import javax.mail.Session;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
* Implementation of MaiLReader to connect to an IMAP server
|
||||
@ -15,7 +14,7 @@ import static org.apache.log4j.Logger.getLogger;
|
||||
public class ImapMailReader extends DefaultMailReader {
|
||||
|
||||
/** the logger object */
|
||||
private final static Logger logger = getLogger(ImapMailReader.class);
|
||||
private final static Logger LOGGER = Logger.getLogger(ImapMailReader.class);
|
||||
|
||||
/**
|
||||
* creates a new instance to connect to an IMAP (or MS Exchange) server
|
||||
@ -41,7 +40,7 @@ public class ImapMailReader extends DefaultMailReader {
|
||||
hint += ". Reason: " + ex.getMessage();
|
||||
throw new MailReaderConnectionException(hint, ex);
|
||||
}
|
||||
logger.info("Connected to " + getConnectionShortCut());
|
||||
LOGGER.info("Connected to " + getConnectionShortCut());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,20 +1,11 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network.whois;
|
||||
|
||||
import de.muehlencord.shared.network.whois.DefaultWhoisParser;
|
||||
import de.muehlencord.shared.network.whois.WhoisInformation;
|
||||
import de.muehlencord.shared.network.whois.WhoisException;
|
||||
import de.muehlencord.shared.network.whois.WhoisParser;
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@ -23,7 +14,7 @@ import static org.apache.log4j.Logger.getLogger;
|
||||
public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger logger = getLogger(DefaultWhoisParser.class);
|
||||
private final static Logger LOGGER = Logger.getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
@ -69,11 +60,11 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
|
||||
}
|
||||
|
||||
private void analyseBlock(String block) throws WhoisException {
|
||||
logger.debug("Start analysing block");
|
||||
logger.debug("\n---\n" + block + "\n---\n");
|
||||
LOGGER.debug("Start analysing block");
|
||||
LOGGER.debug("\n---\n" + block + "\n---\n");
|
||||
|
||||
if ((block == null) || (block.equals("")) || (!block.contains(" "))) {
|
||||
logger.debug("Skippig empty block");
|
||||
LOGGER.debug("Skippig empty block");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -96,7 +87,7 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
whoisInformation.getNetwork().addAll(rangeToCidrList(startIpAddress, endIPAddress));
|
||||
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
LOGGER.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
} else {
|
||||
throw new WhoisException("Cannot identify netrange value");
|
||||
}
|
||||
@ -114,24 +105,24 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
|
||||
orgId = orgName;
|
||||
}
|
||||
whoisInformation.setNetworkInformation(new NetworkInformation(orgName, orgId, country));
|
||||
logger.info("Networkinformation:" + whoisInformation.getNetworkInformation().toString());
|
||||
LOGGER.info("Networkinformation:" + whoisInformation.getNetworkInformation().toString());
|
||||
break;
|
||||
|
||||
|
||||
case "OrgAbuseHandle:":
|
||||
// TODO add abuse handler
|
||||
logger.info("Skipping OrgAbuseHandle block");
|
||||
LOGGER.info("Skipping OrgAbuseHandle block");
|
||||
break;
|
||||
case "OrgTechHandle:":
|
||||
// admin person of network server belongs to
|
||||
logger.info("Skipping OrgTechHandle block");
|
||||
LOGGER.info("Skipping OrgTechHandle block");
|
||||
break;
|
||||
|
||||
case "#":
|
||||
logger.info("Skipping comment block");
|
||||
LOGGER.info("Skipping comment block");
|
||||
break;
|
||||
default:
|
||||
logger.info("Unknown block found");
|
||||
LOGGER.info("Unknown block found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ package de.muehlencord.shared.network.whois;
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -12,7 +11,7 @@ import static org.apache.log4j.Logger.getLogger;
|
||||
public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger logger = getLogger(DefaultWhoisParser.class);
|
||||
private final static Logger LOGGER = Logger.getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
@ -36,11 +35,11 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
}
|
||||
|
||||
private void analyseBlock(String block) throws WhoisException {
|
||||
logger.debug("Start analysing block");
|
||||
logger.debug("\n---\n" + block + "\n---\n");
|
||||
LOGGER.debug("Start analysing block");
|
||||
LOGGER.debug("\n---\n" + block + "\n---\n");
|
||||
|
||||
if ((block == null) || (block.equals("")) || (!block.contains(" "))) {
|
||||
logger.debug("Skippig empty block");
|
||||
LOGGER.debug("Skippig empty block");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,7 +74,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
whoisInformation.getNetwork().add(inetnum);
|
||||
}
|
||||
|
||||
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
LOGGER.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
whoisInformation.setNetworkInformation(new NetworkInformation(netname, descr, country));
|
||||
|
||||
break;
|
||||
@ -90,26 +89,26 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
}
|
||||
*/
|
||||
whoisInformation.getRootNetwork().add(route);
|
||||
logger.info("Root network " + whoisInformation.getRootNetwork().toString());
|
||||
LOGGER.info("Root network " + whoisInformation.getRootNetwork().toString());
|
||||
break;
|
||||
|
||||
|
||||
case "role:":
|
||||
// admin company of network server belongs to
|
||||
logger.info("Skipping role block");
|
||||
LOGGER.info("Skipping role block");
|
||||
break;
|
||||
case "person:":
|
||||
// admin person of network server belongs to
|
||||
logger.info("Skipping person block");
|
||||
LOGGER.info("Skipping person block");
|
||||
break;
|
||||
case "% Information":
|
||||
case "% Note:":
|
||||
case "% This":
|
||||
case "%":
|
||||
logger.info("Skipping comment block");
|
||||
LOGGER.info("Skipping comment block");
|
||||
break;
|
||||
default:
|
||||
logger.info("Unknown block found");
|
||||
LOGGER.info("Unknown block found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package de.muehlencord.shared.network.whois;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.net.whois.WhoisClient;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -11,25 +11,25 @@ import static org.apache.log4j.Logger.getLogger;
|
||||
public class Whois {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger logger = getLogger(Whois.class);
|
||||
/** whois client from commons-net package to execute commands with */
|
||||
WhoisClient whois;
|
||||
private final static Logger LOGGER = Logger.getLogger(Whois.class);
|
||||
/** whoisClient client from commons-net package to execute commands with */
|
||||
WhoisClient whoisClient;
|
||||
/** the complete output */
|
||||
String whoisString = null;
|
||||
|
||||
/**
|
||||
* creates a new instance of the whois client
|
||||
* creates a new instance of the whoisClient client
|
||||
*/
|
||||
public Whois() {
|
||||
whois = new WhoisClient();
|
||||
whois.setDefaultTimeout(60000);
|
||||
whoisClient = new WhoisClient();
|
||||
whoisClient.setDefaultTimeout(60000);
|
||||
}
|
||||
|
||||
/**
|
||||
* reads and parses the inforomation for the given ip address from the given whoisserver
|
||||
* @param whoIsServer the whois server to use
|
||||
* @param ip the ip to query whois data for
|
||||
* @return whoisInformation parsed from whois string
|
||||
* @param whoIsServer the whoisClient server to use
|
||||
* @param ip the ip to query whoisClient data for
|
||||
* @return whoisInformation parsed from whoisClient string
|
||||
* @throws WhoisException if the parsing fails
|
||||
*/
|
||||
public WhoisInformation execute(String whoIsServer, String ip) throws WhoisException {
|
||||
@ -39,18 +39,18 @@ public class Whois {
|
||||
parameter = "n + ";
|
||||
}
|
||||
|
||||
// get whois information
|
||||
// get whoisClient information
|
||||
try {
|
||||
whois.connect(whoIsServer);
|
||||
whoisString = whois.query(parameter + ip);
|
||||
whois.disconnect();
|
||||
whoisClient.connect(whoIsServer);
|
||||
whoisString = whoisClient.query(parameter + ip);
|
||||
whoisClient.disconnect();
|
||||
} catch (Exception ex) {
|
||||
throw new WhoisException("Error while reading whois data from " + whoIsServer + ". Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
// identify RIR and select correct parser
|
||||
WhoisParser parser;
|
||||
if (whoisString.toLowerCase().contains("arin.net")) {
|
||||
if (whoisString.toLowerCase(Locale.US).contains("arin.net")) {
|
||||
parser = new ArinWhoisParser();
|
||||
} else {
|
||||
parser = new DefaultWhoisParser();
|
||||
|
||||
Reference in New Issue
Block a user