Fixed package path.
This commit is contained in:
parent
2ff492fc83
commit
90dc98fbc5
9 changed files with 85 additions and 26 deletions
|
@ -39,7 +39,7 @@ import org.april.logar.util.LineIterator;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import anonymizer.Anonymizer;
|
||||
import fr.devinsy.logar.app.anonymizer.Anonymizer;
|
||||
import fr.devinsy.logar.app.log.LogUtils;
|
||||
|
||||
/**
|
||||
|
@ -102,7 +102,7 @@ public final class Logar
|
|||
{
|
||||
if (file.getName().contains("access"))
|
||||
{
|
||||
anonymizer.anonymize(file);
|
||||
anonymizer.anonymizeAccessFile(file);
|
||||
}
|
||||
else if (file.getName().contains("error"))
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Logar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package anonymizer;
|
||||
package fr.devinsy.logar.app.anonymizer;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Logar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package anonymizer;
|
||||
package fr.devinsy.logar.app.anonymizer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
|
@ -16,16 +16,18 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Logar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package anonymizer;
|
||||
package fr.devinsy.logar.app.anonymizer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.april.logar.util.LineIterator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -36,10 +38,17 @@ import fr.devinsy.logar.app.log.LogUtils;
|
|||
/**
|
||||
* The Class Anonymizer.
|
||||
*/
|
||||
/**
|
||||
* @author cpm
|
||||
*
|
||||
*/
|
||||
public final class Anonymizer
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(Anonymizer.class);
|
||||
|
||||
public static final Pattern IPV4_PATTERN = Pattern.compile("\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}");
|
||||
public static final Pattern IPV6_PATTERN = Pattern.compile("([0-9a-f]{1,4}:{1,2}){4,7}([0-9a-f]){1,4}", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private AnonMap map;
|
||||
|
||||
/**
|
||||
|
@ -50,6 +59,32 @@ public final class Anonymizer
|
|||
this.map = new AnonMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize.
|
||||
*
|
||||
* @param log
|
||||
* the log
|
||||
* @return the log
|
||||
*/
|
||||
public Log anonymizeAccess(final Log log)
|
||||
{
|
||||
Log result;
|
||||
|
||||
String anonIp = this.map.anonymizeIp(log.getIp());
|
||||
String anonUser = this.map.anonymizeUser(log.getUser());
|
||||
|
||||
String line = log.getLine().replace(log.getIp(), anonIp);
|
||||
if (!log.getUser().equals("-"))
|
||||
{
|
||||
line = line.replace(log.getUser(), anonUser);
|
||||
}
|
||||
|
||||
result = new Log(line, log.getDatetime(), anonIp, anonUser);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize.
|
||||
*
|
||||
|
@ -58,7 +93,7 @@ public final class Anonymizer
|
|||
* @param target
|
||||
* the target
|
||||
*/
|
||||
public void anonymize(final File source)
|
||||
public void anonymizeAccessFile(final File source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
|
@ -68,10 +103,24 @@ public final class Anonymizer
|
|||
{
|
||||
throw new IllegalArgumentException("Parameter is not a file.");
|
||||
}
|
||||
else if (!StringUtils.containsAny(source.getName(), "access", "error"))
|
||||
{
|
||||
throw new IllegalArgumentException("File name does not contain 'access' or 'error'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("== Anonymize log for [" + source.getName() + "]");
|
||||
|
||||
boolean isAccessFile;
|
||||
if (source.getName().contains("access"))
|
||||
{
|
||||
isAccessFile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isAccessFile = false;
|
||||
}
|
||||
|
||||
File target;
|
||||
if (source.getName().endsWith(".log.gz"))
|
||||
{
|
||||
|
@ -93,15 +142,25 @@ public final class Anonymizer
|
|||
|
||||
try
|
||||
{
|
||||
Log log = LogUtils.parseAccessLog(line);
|
||||
// logger.info("line={}", line);
|
||||
// logger.info("log =[{}][{}][{}]", log.getIp(),
|
||||
// log.getUser(), log.getDatetime());
|
||||
Log anon;
|
||||
if (isAccessFile)
|
||||
{
|
||||
Log log = LogUtils.parseAccessLog(line);
|
||||
// logger.info("line={}", line);
|
||||
// logger.info("log =[{}][{}][{}]", log.getIp(),
|
||||
// log.getUser(), log.getDatetime());
|
||||
|
||||
Log anon = anonymize(log);
|
||||
// logger.info("anon=[{}][{}][{}]", anon.getIp(),
|
||||
// anon.getUser(), anon.getDatetime());
|
||||
// logger.info("anon={}", anon);
|
||||
anon = anonymizeAccess(log);
|
||||
// logger.info("anon=[{}][{}][{}]", anon.getIp(),
|
||||
// anon.getUser(), anon.getDatetime());
|
||||
// logger.info("anon={}", anon);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log log = LogUtils.parseErrorLog(line);
|
||||
|
||||
anon = anonymizeError(log);
|
||||
}
|
||||
|
||||
out.println(anon);
|
||||
}
|
||||
|
@ -129,13 +188,13 @@ public final class Anonymizer
|
|||
}
|
||||
|
||||
/**
|
||||
* Anonymize.
|
||||
* Anonymize error.
|
||||
*
|
||||
* @param log
|
||||
* the log
|
||||
* @return the log
|
||||
*/
|
||||
public Log anonymize(final Log log)
|
||||
public Log anonymizeError(final Log log)
|
||||
{
|
||||
Log result;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Logar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package anonymizer;
|
||||
package fr.devinsy.logar.app.anonymizer;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.slf4j.Logger;
|
|
@ -16,7 +16,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Logar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package anonymizer;
|
||||
package fr.devinsy.logar.app.anonymizer;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
|
@ -16,7 +16,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Logar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package anonymizer;
|
||||
package fr.devinsy.logar.app.anonymizer;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
|
@ -54,12 +54,12 @@ public final class LogarCLI
|
|||
message.appendln("Usage:");
|
||||
message.appendln(" logar [ -h | -help | --help ]");
|
||||
message.appendln(" logar [ -v | -version | --version ]");
|
||||
message.appendln(" logar anonymize source target anonymize ip and login");
|
||||
message.appendln(" logar archive source target archive previous month");
|
||||
message.appendln(" logar checksort fileordirectory check sort of an access log file");
|
||||
message.appendln(" logar check fileordirectory census bad format line in log files");
|
||||
message.appendln(" logar sort fileordirectory sort log files by datetime");
|
||||
message.appendln(" logar testarchive source test archive");
|
||||
message.appendln(" logar anonymize fileordirectory [maptable] anonymize ip and login");
|
||||
message.appendln(" logar archive source target archive previous month");
|
||||
message.appendln(" logar checksort fileordirectory check sort of an access log file");
|
||||
message.appendln(" logar check fileordirectory census bad format line in log files");
|
||||
message.appendln(" logar sort fileordirectory sort log files by datetime");
|
||||
message.appendln(" logar testarchive source test archive");
|
||||
|
||||
logger.info(message.toString());
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.junit.Assert;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import anonymizer.Ipv4Generator;
|
||||
import fr.devinsy.logar.app.LogarException;
|
||||
import fr.devinsy.logar.app.anonymizer.Ipv4Generator;
|
||||
|
||||
/**
|
||||
* The Class VisitCountersTest.
|
||||
|
|
Loading…
Reference in a new issue