Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PasswordSender;
- import java.util.*;
- import java.util.logging.Logger;
- public class Main {
- public static final int zipPasswordLength = 6;
- private static Properties prop;
- private static final Logger logger = PasswordLogger.init("test.log");
- private static final String zipPassword = String.valueOf((int)(Math.random() * Math.pow(10, zipPasswordLength)));
- private static final String messageID = String.valueOf((int)(Math.random() * Math.pow(10, zipPasswordLength)));
- public static void main(String[] args) {
- parseArguments(args);
- EncryptedZip zip = new EncryptedZip(zipPassword, "EncryptedArchive.txt", prop.getProperty("body"),
- logger);
- SendEmail email = new SendEmail(prop, zip.getZipFile(), messageID ,logger);
- email.sendEmail();
- zip.removeCreatedFiles();
- SendSMS.send(prop.getProperty("phone"), zipPassword, messageID, logger);
- }
- private static void parseArguments(String[] args){
- List<String> requiredArguments = new ArrayList<>(Arrays.asList("phone", "recipient",
- "body", "smtp", "from"));
- /* All arguments except smtp and from required, that's why we are checking args length.
- If all arguments provided as cmd parametes, then we will return true, otherwise false.
- */
- if(args.length < (requiredArguments.size() * 2 - 4)){
- printHelp();
- }
- // If all arguments provided as parameters then no need to load config.
- if(args.length < requiredArguments.size() * 2){
- prop = new LoadPropertyFile(logger).loadConfig();
- } else {
- prop = GenerateProperties.initFromArgs(args);
- }
- for(int i=0; i<args.length; i+=2){
- if(!args[i].startsWith("-") || !requiredArguments.contains(args[i].replace("-", ""))
- || args[i+1].startsWith("-")){
- printHelp();
- }else{
- prop.setProperty(args[i].replace("-", ""), args[i+1]);
- }
- }
- }
- private static void printHelp(){
- logger.warning("Program trying to run without required arguments.");
- System.out.println("Usage: passwordHelper.jar --Phone +994502000000 --recipient mt@domain.com" +
- " --Body 'Username: MTokarev, Password: P@ssw0rd1\n" +
- "Optional parameters: --smtp\n" +
- " --from\n" +
- "if optional parameters won't be provided, this script will ask you to initialize +\n" +
- "it from your input and will store to the future usage.");
- System.exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement