2020-09-13 01:28:27 +02:00
|
|
|
/*
|
2021-05-14 17:20:52 +02:00
|
|
|
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
2020-09-13 01:28:27 +02:00
|
|
|
*
|
|
|
|
* This file is part of StatoolInfos, simple service statistics tool.
|
|
|
|
*
|
|
|
|
* StatoolInfos is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* StatoolInfos is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package fr.devinsy.statoolinfos.cli;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2021-12-15 13:02:00 +01:00
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
2020-09-13 01:28:27 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2021-12-08 00:39:48 +01:00
|
|
|
import fr.devinsy.statoolinfos.core.BotFilter;
|
2020-09-13 01:28:27 +02:00
|
|
|
import fr.devinsy.statoolinfos.core.StatoolInfos;
|
2020-09-19 02:37:52 +02:00
|
|
|
import fr.devinsy.statoolinfos.util.BuildInformation;
|
2021-05-29 02:23:15 +02:00
|
|
|
import fr.devinsy.statoolinfos.util.Chrono;
|
2020-09-19 02:37:52 +02:00
|
|
|
import fr.devinsy.statoolinfos.util.Files;
|
2021-05-15 16:59:04 +02:00
|
|
|
import fr.devinsy.statoolinfos.util.FilesUtils;
|
2020-09-13 01:28:27 +02:00
|
|
|
import fr.devinsy.strings.StringList;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class <code>StatoolInfosCLI</code> manages a Command Line Interface for
|
|
|
|
* StatoolInfos.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public final class StatoolInfosCLI
|
|
|
|
{
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(StatoolInfosCLI.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new statool infos CLI.
|
|
|
|
*/
|
|
|
|
private StatoolInfosCLI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert path.
|
|
|
|
*
|
|
|
|
* @param path
|
|
|
|
* the path
|
|
|
|
* @return the files
|
|
|
|
*/
|
|
|
|
public static Files convertPath(final String path)
|
|
|
|
{
|
|
|
|
Files result;
|
|
|
|
|
|
|
|
result = new Files();
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(path))
|
|
|
|
{
|
|
|
|
File input = new File(path);
|
|
|
|
|
|
|
|
if (input.exists())
|
|
|
|
{
|
|
|
|
if (input.isFile())
|
|
|
|
{
|
|
|
|
result.add(input);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (File file : input.listFiles())
|
|
|
|
{
|
2020-10-18 00:14:39 +02:00
|
|
|
if ((file.isFile()) && (file.getName().endsWith(".conf")))
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
|
|
|
result.add(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.add(input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display help.
|
|
|
|
*/
|
|
|
|
public static void displayHelp()
|
|
|
|
{
|
|
|
|
StringList message = new StringList();
|
|
|
|
|
|
|
|
message.append("StatoolInfos CLI version ").appendln(BuildInformation.instance().version());
|
|
|
|
message.appendln("Usage:");
|
|
|
|
message.appendln(" statoolinfos [ -h | -help | --help ]");
|
|
|
|
message.appendln(" statoolinfos [ -v | -version | --version ]");
|
2021-12-08 00:39:48 +01:00
|
|
|
message.appendln();
|
|
|
|
message.appendln(" statoolinfos build <configurationfile> build property files from conf and input");
|
|
|
|
message.appendln(" statoolinfos clear <configurationfile> remove property files from conf");
|
|
|
|
message.appendln(" statoolinfos crawl <configurationfile> crawl all file from conf and input");
|
2021-12-18 12:10:29 +01:00
|
|
|
message.appendln(" statoolinfos format <fileordirectory> format property files in tiny way");
|
2021-12-08 00:39:48 +01:00
|
|
|
message.appendln(" statoolinfos htmlize <configurationfile> generate web pages from conf");
|
2021-12-15 13:02:00 +01:00
|
|
|
message.appendln(" statoolinfos probe OPTION [<directory>|<configurationfile>] generate metrics files from conf");
|
|
|
|
message.appendln(" OPTION = [-full|-today|-previousday|-NN] with NN a day count");
|
2021-12-18 12:10:29 +01:00
|
|
|
message.appendln(" statoolinfos tagdate <fileordirectory> update the file.datetime file");
|
2021-12-08 00:39:48 +01:00
|
|
|
message.appendln(" statoolinfos uptime <configurationfile> update uptime journal");
|
|
|
|
message.appendln();
|
2021-12-18 12:10:29 +01:00
|
|
|
message.appendln(" statoolinfos list ip [-bot|-nobot] <fileordirectory> generate ip list from http log file");
|
|
|
|
message.appendln(" statoolinfos list ua [-bot|-nobot] <fileordirectory> generate user agent list from http log file");
|
|
|
|
message.appendln(" statoolinfos list visitors [-bot|-nobot] <fileordirectory> generate visitors (ip+ua) list from http log file");
|
|
|
|
message.appendln(" statoolinfos stat ip [-bot|-nobot] <fileordirectory> generate stats about ip from http log file");
|
|
|
|
message.appendln(" statoolinfos stat ua [-bot|-nobot] <fileordirectory> generate stats about user agent from http log file");
|
|
|
|
message.appendln(" statoolinfos stat visitors [-bot|-nobot] <fileordirectory> generate stats about visitors (ip+ua) from http log file");
|
2020-09-13 01:28:27 +02:00
|
|
|
|
2021-12-09 12:25:19 +01:00
|
|
|
System.out.print(message.toString());
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display version.
|
|
|
|
*/
|
|
|
|
public static void displayVersion()
|
|
|
|
{
|
|
|
|
StringList message = new StringList();
|
|
|
|
|
|
|
|
message.appendln(BuildInformation.instance().version());
|
|
|
|
|
2021-12-09 12:46:37 +01:00
|
|
|
System.out.print(message.toString());
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is matching.
|
|
|
|
*
|
|
|
|
* @param args
|
|
|
|
* the args
|
|
|
|
* @param regexps
|
|
|
|
* the regexps
|
|
|
|
* @return true, if is matching
|
|
|
|
*/
|
|
|
|
public static boolean isMatching(final String[] args, final String... regexps)
|
|
|
|
{
|
|
|
|
boolean result;
|
|
|
|
|
|
|
|
if ((args.length == 0) && (regexps == null))
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else if ((args.length != 0) && (regexps == null))
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
else if (args.length != regexps.length)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boolean ended = false;
|
|
|
|
int index = 0;
|
|
|
|
result = false;
|
|
|
|
while (!ended)
|
|
|
|
{
|
|
|
|
if (index < args.length)
|
|
|
|
{
|
|
|
|
String arg = args[index];
|
|
|
|
String regexp = regexps[index];
|
|
|
|
|
|
|
|
if (arg.matches(regexp))
|
|
|
|
{
|
|
|
|
index += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ended = true;
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ended = true;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-05 17:56:07 +02:00
|
|
|
/**
|
|
|
|
* Parses the log filter option.
|
|
|
|
*
|
|
|
|
* @param source
|
|
|
|
* the source
|
|
|
|
* @return the log filter
|
|
|
|
*/
|
2021-12-08 00:39:48 +01:00
|
|
|
private static BotFilter parseLogFilterOption(final String source)
|
2021-06-05 17:56:07 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter result;
|
2021-06-05 17:56:07 +02:00
|
|
|
|
|
|
|
if (StringUtils.equals(source, "-all"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
result = BotFilter.ALL;
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (StringUtils.equals(source, "-bot"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
result = BotFilter.BOT;
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (StringUtils.equals(source, "-nobot"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
result = BotFilter.NOBOT;
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-09-13 01:28:27 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* This method launch CLI.
|
|
|
|
*
|
|
|
|
* @param args
|
|
|
|
* necessary arguments
|
|
|
|
*/
|
|
|
|
public static void run(final String[] args)
|
|
|
|
{
|
|
|
|
// Set default catch.
|
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void uncaughtException(final Thread thread, final Throwable exception)
|
|
|
|
{
|
|
|
|
String message;
|
|
|
|
if (exception instanceof OutOfMemoryError)
|
|
|
|
{
|
|
|
|
message = "Java ran out of memory!\n\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message = String.format("An error occured: %1s(%2s)", exception.getClass(), exception.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error("uncaughtException ", exception);
|
|
|
|
logger.error(message);
|
|
|
|
logger.info("Oups, an unexpected error occured. Please try again.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-15 03:55:18 +02:00
|
|
|
logger.debug("{} StatoolInfos call: {}", LocalDateTime.now(), new StringList(args).toStringSeparatedBy(" "));
|
2020-09-13 01:28:27 +02:00
|
|
|
|
|
|
|
if (isMatching(args))
|
|
|
|
{
|
|
|
|
logger.info("No parameter.");
|
|
|
|
displayHelp();
|
|
|
|
}
|
|
|
|
else if (isMatching(args, "(-h|--h|--help)"))
|
|
|
|
{
|
|
|
|
displayHelp();
|
|
|
|
}
|
|
|
|
else if (isMatching(args, "(-v|-version|--version)"))
|
|
|
|
{
|
|
|
|
displayVersion();
|
|
|
|
}
|
2021-12-08 00:39:48 +01:00
|
|
|
else if (isMatching(args, "build", "\\s*.+\\.conf\\s*"))
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
|
|
|
try
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.build(configurationFile);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 00:39:48 +01:00
|
|
|
else if (isMatching(args, "clear", "\\s*.+\\.conf\\s*"))
|
2020-10-15 01:47:48 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
|
|
|
try
|
2020-10-15 01:47:48 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.clear(configurationFile);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
2020-10-15 01:47:48 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 00:39:48 +01:00
|
|
|
else if (isMatching(args, "crawl", "\\s*.+\\.conf\\s*"))
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-05-29 02:23:15 +02:00
|
|
|
Chrono chrono = new Chrono().start();
|
2021-12-08 00:39:48 +01:00
|
|
|
|
|
|
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
|
|
|
try
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.crawl(configurationFile);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
2021-05-29 02:23:15 +02:00
|
|
|
System.out.println(chrono.format());
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
2021-05-15 16:59:04 +02:00
|
|
|
else if (isMatching(args, "format", "\\s*.+\\s*"))
|
|
|
|
{
|
|
|
|
Files inputs = FilesUtils.searchEndingWith(new File(args[1]), ".properties");
|
|
|
|
for (File input : inputs)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
StatoolInfos.format(input);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", input.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-08 00:39:48 +01:00
|
|
|
else if (isMatching(args, "htmlize", "\\s*.+\\.conf\\s*"))
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-05-29 02:23:15 +02:00
|
|
|
Chrono chrono = new Chrono().start();
|
2021-12-08 00:39:48 +01:00
|
|
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
|
|
|
try
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.htmlize(configurationFile);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
2021-05-29 02:23:15 +02:00
|
|
|
System.out.println(chrono.format());
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
2021-06-05 17:56:07 +02:00
|
|
|
else if (isMatching(args, "list", "ip", "\\s*\\S+\\s*"))
|
|
|
|
{
|
|
|
|
File source = new File(args[2]);
|
|
|
|
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.listIps(source, BotFilter.ALL);
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (isMatching(args, "list", "ip", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter filter = parseLogFilterOption(args[2]);
|
2021-06-05 17:56:07 +02:00
|
|
|
File source = new File(args[3]);
|
|
|
|
|
|
|
|
StatoolInfos.listIps(source, filter);
|
|
|
|
}
|
|
|
|
else if (isMatching(args, "list", "(useragent|ua)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
|
|
|
File source = new File(args[2]);
|
|
|
|
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.listUserAgents(source, BotFilter.ALL);
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (isMatching(args, "list", "(useragent|ua)", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter filter = parseLogFilterOption(args[2]);
|
2021-06-05 17:56:07 +02:00
|
|
|
File source = new File(args[3]);
|
|
|
|
|
|
|
|
StatoolInfos.listUserAgents(source, filter);
|
|
|
|
}
|
|
|
|
else if (isMatching(args, "list", "visitors", "\\s*\\S+\\s*"))
|
|
|
|
{
|
|
|
|
File source = new File(args[2]);
|
|
|
|
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.listVisitors(source, BotFilter.ALL);
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (isMatching(args, "list", "visitors", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter filter = parseLogFilterOption(args[2]);
|
2021-06-05 17:56:07 +02:00
|
|
|
File source = new File(args[3]);
|
|
|
|
|
|
|
|
StatoolInfos.listVisitors(source, filter);
|
|
|
|
}
|
2021-12-15 13:02:00 +01:00
|
|
|
else if (isMatching(args, "probe", "\\S*(-full|-today|-previousday|-\\d+)\\s*", "\\s*.+\\s*"))
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-12-15 13:02:00 +01:00
|
|
|
File configurationFile = new File(StringUtils.trim(args[2]));
|
2021-12-09 11:53:17 +01:00
|
|
|
|
2021-12-15 13:02:00 +01:00
|
|
|
String filter = StringUtils.trim(args[1]);
|
|
|
|
int dayCountFilter;
|
|
|
|
if (filter.equals("-full"))
|
2021-12-09 12:46:37 +01:00
|
|
|
{
|
2021-12-15 13:02:00 +01:00
|
|
|
dayCountFilter = -1;
|
2021-12-09 12:46:37 +01:00
|
|
|
}
|
2021-12-15 13:02:00 +01:00
|
|
|
else if (filter.equals("-today"))
|
2021-12-09 12:46:37 +01:00
|
|
|
{
|
2021-12-15 13:02:00 +01:00
|
|
|
dayCountFilter = 0;
|
|
|
|
}
|
|
|
|
else if (filter.equals("-previousday"))
|
|
|
|
{
|
|
|
|
dayCountFilter = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dayCountFilter = -1 * NumberUtils.toInt(filter);
|
2021-12-09 12:46:37 +01:00
|
|
|
}
|
|
|
|
|
2021-12-15 13:02:00 +01:00
|
|
|
try
|
2020-09-13 01:28:27 +02:00
|
|
|
{
|
2021-12-09 11:53:17 +01:00
|
|
|
Files inputs = FilesUtils.searchEndingWith(configurationFile, ".conf");
|
2021-12-15 13:02:00 +01:00
|
|
|
if (inputs.isEmpty())
|
2021-12-09 11:53:17 +01:00
|
|
|
{
|
2021-12-15 13:02:00 +01:00
|
|
|
System.out.println("No configuration file found.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (File input : inputs)
|
2021-12-09 11:53:17 +01:00
|
|
|
{
|
2021-12-15 13:02:00 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
System.out.println("Probing [" + input + "] with day count filter " + dayCountFilter);
|
|
|
|
StatoolInfos.probe(input, dayCountFilter);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", input.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
2021-12-09 11:53:17 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 00:39:48 +01:00
|
|
|
}
|
2021-12-15 13:02:00 +01:00
|
|
|
catch (Exception exception)
|
2021-12-08 00:39:48 +01:00
|
|
|
{
|
2021-12-15 13:02:00 +01:00
|
|
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
2020-09-13 01:28:27 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-05 17:56:07 +02:00
|
|
|
else if (isMatching(args, "stat", "ip", "\\s*\\S+\\s*"))
|
|
|
|
{
|
|
|
|
File source = new File(args[2]);
|
|
|
|
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.statIps(source, BotFilter.ALL);
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (isMatching(args, "stat", "ip", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter filter = parseLogFilterOption(args[2]);
|
2021-06-05 17:56:07 +02:00
|
|
|
File source = new File(args[3]);
|
|
|
|
|
|
|
|
StatoolInfos.statIps(source, filter);
|
|
|
|
}
|
|
|
|
else if (isMatching(args, "stat", "(useragent|ua)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
|
|
|
File source = new File(args[2]);
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.statUserAgents(source, BotFilter.ALL);
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (isMatching(args, "stat", "(useragent|ua)", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter filter = parseLogFilterOption(args[2]);
|
2021-06-05 17:56:07 +02:00
|
|
|
File source = new File(args[3]);
|
|
|
|
|
|
|
|
StatoolInfos.statUserAgents(source, filter);
|
|
|
|
}
|
|
|
|
else if (isMatching(args, "stat", "visitors", "\\s*\\S+\\s*"))
|
|
|
|
{
|
|
|
|
File source = new File(args[2]);
|
|
|
|
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.statVisitors(source, BotFilter.ALL);
|
2021-06-05 17:56:07 +02:00
|
|
|
}
|
|
|
|
else if (isMatching(args, "stat", "visitors", "(-all|-bot|-nobot)", "\\s*\\S+\\s*"))
|
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
BotFilter filter = parseLogFilterOption(args[2]);
|
2021-06-05 17:56:07 +02:00
|
|
|
File source = new File(args[3]);
|
|
|
|
|
|
|
|
StatoolInfos.statVisitors(source, filter);
|
|
|
|
}
|
2021-05-15 16:59:04 +02:00
|
|
|
else if (isMatching(args, "tagdate", "\\s*.+\\s*"))
|
|
|
|
{
|
|
|
|
Files inputs = FilesUtils.searchEndingWith(new File(args[1]), ".properties");
|
|
|
|
for (File input : inputs)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
StatoolInfos.tagDate(input);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", input.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-08 00:39:48 +01:00
|
|
|
else if (isMatching(args, "uptime", "\\s*.+\\.conf\\s*"))
|
2021-06-10 03:54:39 +02:00
|
|
|
{
|
|
|
|
Chrono chrono = new Chrono().start();
|
2021-12-08 00:39:48 +01:00
|
|
|
|
|
|
|
File configurationFile = new File(StringUtils.trim(args[1]));
|
|
|
|
try
|
2021-06-10 03:54:39 +02:00
|
|
|
{
|
2021-12-08 00:39:48 +01:00
|
|
|
StatoolInfos.uptime(configurationFile);
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
2021-06-10 03:54:39 +02:00
|
|
|
}
|
|
|
|
System.out.println(chrono.format());
|
|
|
|
}
|
2020-09-13 01:28:27 +02:00
|
|
|
else
|
|
|
|
{
|
2021-05-14 17:20:52 +02:00
|
|
|
System.out.println("Bad usage.");
|
2020-09-13 01:28:27 +02:00
|
|
|
displayHelp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|