Example #1
0
 private static void parseGet(String[] arr, ConfigUpdater o) throws ParseException {
   if (arr.length > 1) {
     switch (arr[1]) {
       case "LIST_CLIENT":
         {
           if (arr.length == 2) {
             o.sendList(ProxyFilter.getClientsLists());
           } else {
             o.sendList(ProxyFilter.getClientList(arr[2]));
           }
         }
         break;
       case "LIST_ADDRESS":
         {
           if (arr.length == 2) {
             o.sendList(ProxyFilter.getAddressesLists());
           } else {
             o.sendList(ProxyFilter.getAddressList(arr[2]));
           }
         }
         break;
       default:
         {
           throw new ParseException("Wrong get params", 2);
         }
     }
   } else {
     throw new ParseException("Wrong get section", 1);
   }
 }
Example #2
0
 /** @return true to indicate that the parameter was processed */
 public boolean update(Config.Builder builder, QueryData data) {
   String value = data.getParam(name);
   if (value == null) {
     return false;
   }
   return configUpdater.update(value, builder);
 }
Example #3
0
 private static void parseSave(ConfigUpdater o) throws IOException {
   if (_path != null) {
     File file = new File(_path);
     if (!file.isDirectory() && file.canWrite()) {
       FileWriter fr = new FileWriter(file);
       ProxyFilter.saveConfig(fr);
       o.sendSave("Saved current config to " + _path + " successfully");
       fr.close();
     } else {
       throw new IOException("Bad config file specified");
     }
   } else {
     throw new IOException("File path not specified");
   }
 }
Example #4
0
 public static void parseConfigurator(String command, ConfigUpdater o)
     throws ParseException, IOException {
   String[] hashed = command.split(";");
   if (hashed.length > 1) {
     if (hashed[0].length() > 0 && _workers.contains(hashed[0])) {
       hashed[1] = hashed[1].replaceAll("\\r\\n", "");
       if (hashed[1].startsWith("GET")) {
         parseGet(hashed[1].split(" "), o);
       } else if (hashed[1].startsWith("REMOVE")) {
         parseRemove(hashed[1].split(" "), o);
       } else if (hashed[1].equals("SAVE")) {
         parseSave(o);
       } else {
         parseCommand(hashed[1], 0);
       }
     } else {
       String[] arr = hashed[1].split(" ");
       if (arr.length > 1) {
         arr[1] = arr[1].replaceAll("\\r\\n", "");
         if (arr.length > 1) {
           if (arr[0].equals("LOGIN") && arr[1].equals(SECRET)) {
             String uuid = UUID.randomUUID().toString();
             if (o.setHash(uuid)) _workers.add(uuid);
             else throw new ParseException("Problem with encoding", 0);
           } else {
             throw new ParseException("Wrong password", 0);
           }
         } else {
           throw new ParseException("Please login first", 0);
         }
       } else {
         throw new ParseException("Please login first", 0);
       }
     }
   }
 }
Example #5
0
 private static void parseRemove(String[] arr, ConfigUpdater o) throws ParseException {
   if (arr.length > 1) {
     switch (arr[1]) {
       case "CLIENT":
         {
           if (arr.length > 2) {
             if (arr.length > 3) {
               switch (arr[3]) {
                 case "LIST_CLIENT":
                   {
                     if (arr.length > 4) {
                       o.sendRemoval(ProxyFilter.removeClientFromClientList(arr[4], arr[2]));
                     } else {
                       throw new ParseException("Name for client list is not specified", 6);
                     }
                   }
                   break;
                 case "LIST_ADDRESS":
                   {
                     if (arr.length > 4) {
                       o.sendRemoval(ProxyFilter.removeClientFromAddressList(arr[4], arr[2]));
                     } else {
                       throw new ParseException("Name for address list is not specified", 6);
                     }
                   }
                   break;
                 default:
                   {
                     throw new ParseException("Wrong list type", 5);
                   }
               }
             } else {
               throw new ParseException("List type is not specified", 4);
             }
           } else {
             throw new ParseException("Name for client is not specified", 3);
           }
         }
         break;
       case "ADDRESS":
         {
           if (arr.length > 2) {
             if (arr.length > 3) {
               switch (arr[3]) {
                 case "LIST_ADDRESS":
                   {
                     if (arr.length > 4) {
                       o.sendRemoval(ProxyFilter.removeAddressFromAddressList(arr[4], arr[2]));
                     } else {
                       throw new ParseException("Name for address list is not specified", 6);
                     }
                   }
                   break;
                 default:
                   {
                     throw new ParseException("Wrong list type", 5);
                   }
               }
             } else {
               throw new ParseException("List type is not specified", 4);
             }
           } else {
             throw new ParseException("Address is not specified", 3);
           }
         }
         break;
       case "LIST_CLIENT":
         {
           if (arr.length > 2) {
             o.sendRemoval(ProxyFilter.removeClientList(arr[2]));
           } else {
             throw new ParseException("Name for client list is not specified", 3);
           }
         }
         break;
       case "LIST_ADDRESS":
         {
           if (arr.length > 2) {
             o.sendRemoval(ProxyFilter.removeAddressList(arr[2]));
           } else {
             throw new ParseException("Name for address list is not specified", 3);
           }
         }
         break;
       default:
         {
           throw new ParseException("Wrong remove params", 2);
         }
     }
   } else {
     throw new ParseException("Wrong remove section", 1);
   }
 }
Example #6
0
 /**
  * Reset the values associated with this option in the specified builder. This is important for
  * config inheritance to ensure that a sub-config completely overrides an option from its parent
  * config.
  *
  * @param builder
  */
 public boolean reset(Config.Builder builder) {
   return configUpdater.reset(builder);
 }
Example #7
0
 public void update(Config.Builder builder, JsonElement json) {
   if (json == null) {
     return;
   }
   configUpdater.apply(json, builder);
 }