| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.io.File; |
|---|
| 4 | 4 | import java.net.URISyntaxException; |
|---|
| 5 | | -import java.util.Date; |
|---|
| 6 | 5 | |
|---|
| 7 | 6 | import net.curisit.securis.utils.Params; |
|---|
| 8 | 7 | |
|---|
| .. | .. |
|---|
| 16 | 15 | import org.apache.logging.log4j.LogManager; |
|---|
| 17 | 16 | import org.apache.logging.log4j.Logger; |
|---|
| 18 | 17 | |
|---|
| 18 | +/** |
|---|
| 19 | + * Main class when SeCuris client is used from command line. |
|---|
| 20 | + * |
|---|
| 21 | + * <pre> |
|---|
| 22 | + * usage: securis-client [-c] [-g] [-h] [-l <lic_file>] [-r <lic_file>] [-s |
|---|
| 23 | + * <url_license_server>] [-t] |
|---|
| 24 | + * -c,--create Request a license file from server. |
|---|
| 25 | + * --rfile and --server parameters are |
|---|
| 26 | + * mandatory. |
|---|
| 27 | + * -g,--gen_request Generate request file. If --rfile |
|---|
| 28 | + * parameter is missing then It is |
|---|
| 29 | + * generated in current directory. |
|---|
| 30 | + * -h,--help Show help. |
|---|
| 31 | + * -l,--validate <lic_file> Validate lic file. |
|---|
| 32 | + * -r,--renew <lic_file> Synchronize/renew the current license |
|---|
| 33 | + * file. --server parameter is mandatory. |
|---|
| 34 | + * -s,--server <url_license_server> License server url. |
|---|
| 35 | + * -t,--test_lc Test if License Server (LC) is |
|---|
| 36 | + * available. --server parameter is |
|---|
| 37 | + * mandatory. |
|---|
| 38 | + * </pre> |
|---|
| 39 | + * |
|---|
| 40 | + * @author roberto <roberto.sanchez@curisit.net> |
|---|
| 41 | + * |
|---|
| 42 | + */ |
|---|
| 19 | 43 | public class License { |
|---|
| 20 | 44 | |
|---|
| 21 | | - static { |
|---|
| 22 | | - // BasicConfigurator.configure(new ConsoleAppender()); |
|---|
| 23 | | - // PropertyConfigurator.configure("/log4j.xml"); |
|---|
| 24 | | - // LogManager.getRootLogger(). |
|---|
| 25 | | - } |
|---|
| 26 | | - |
|---|
| 27 | | - // private static final Logger log = LoggerFactory.getLogger(License.class); |
|---|
| 28 | 45 | private static final Logger log = LogManager.getLogger(License.class); |
|---|
| 29 | 46 | |
|---|
| 47 | + /** |
|---|
| 48 | + * Aplication entry point when it used as CLI |
|---|
| 49 | + * |
|---|
| 50 | + * @param args |
|---|
| 51 | + * @throws URISyntaxException |
|---|
| 52 | + */ |
|---|
| 30 | 53 | public static void main(String[] args) throws URISyntaxException { |
|---|
| 31 | 54 | // Configuration conf = XMLConfigurationFactory.getInstance().getConfiguration("config", License.class.getResource("/log4j.xml").toURI()); |
|---|
| 32 | 55 | |
|---|
| 33 | | - log.info("Tool init {}", new Date()); |
|---|
| 56 | + log.debug("SeCuris client tool init "); |
|---|
| 34 | 57 | |
|---|
| 35 | 58 | checkConfigFile(); |
|---|
| 36 | 59 | CommandLine cmd = getCommandLine(args); |
|---|
| .. | .. |
|---|
| 61 | 84 | System.exit(0); |
|---|
| 62 | 85 | } |
|---|
| 63 | 86 | |
|---|
| 87 | + if (cmd.hasOption('c')) { |
|---|
| 88 | + String reqFilename = cmd.getOptionValue("rfile"); |
|---|
| 89 | + checkMandatoryParameter(reqFilename, "rfile"); |
|---|
| 90 | + String server = cmd.getOptionValue("server"); |
|---|
| 91 | + checkMandatoryParameter(server, "server"); |
|---|
| 92 | + |
|---|
| 93 | + log.warn("This command is not yet implemented"); |
|---|
| 94 | + System.exit(0); |
|---|
| 95 | + } |
|---|
| 96 | + |
|---|
| 97 | + if (cmd.hasOption('t')) { |
|---|
| 98 | + String server = cmd.getOptionValue("server"); |
|---|
| 99 | + checkMandatoryParameter(server, "server"); |
|---|
| 100 | + |
|---|
| 101 | + log.warn("This command is not yet implemented"); |
|---|
| 102 | + System.exit(0); |
|---|
| 103 | + } |
|---|
| 104 | + |
|---|
| 105 | + if (cmd.hasOption('r')) { |
|---|
| 106 | + String licFilename = cmd.getOptionValue("sync"); |
|---|
| 107 | + checkMandatoryParameter(licFilename, "sync"); |
|---|
| 108 | + String server = cmd.getOptionValue("server"); |
|---|
| 109 | + checkMandatoryParameter(server, "server"); |
|---|
| 110 | + |
|---|
| 111 | + log.warn("This command is not yet implemented"); |
|---|
| 112 | + System.exit(0); |
|---|
| 113 | + } |
|---|
| 114 | + |
|---|
| 64 | 115 | } catch (SeCurisException e) { |
|---|
| 65 | 116 | log.error("The command generated an error: {}", e.toString()); |
|---|
| 117 | + } |
|---|
| 118 | + } |
|---|
| 119 | + |
|---|
| 120 | + private static void checkMandatoryParameter(String value, String param) { |
|---|
| 121 | + if (value == null) { |
|---|
| 122 | + log.error("Parameter {} is mandatory. Use --help to get information about parameters", param); |
|---|
| 123 | + System.exit(-5); |
|---|
| 66 | 124 | } |
|---|
| 67 | 125 | } |
|---|
| 68 | 126 | |
|---|
| .. | .. |
|---|
| 120 | 178 | options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory."); |
|---|
| 121 | 179 | options.addOption("c", "create", false, "Request a license file from server. --rfile and --server parameters are mandatory."); |
|---|
| 122 | 180 | options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. --server parameter is mandatory."); |
|---|
| 123 | | - options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("sync").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('y')); |
|---|
| 181 | + options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('r')); |
|---|
| 124 | 182 | |
|---|
| 125 | 183 | return options; |
|---|
| 126 | 184 | } |
|---|