Exemplo n.º 1
0
  @ScriptUsage(
      description = "create a module instance",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type "),
        @ScriptArgument(name = "factory name", type = "string", description = "factory name"),
        @ScriptArgument(name = "instance name", type = "string", description = "instance name")
      })
  public void createInstance(String[] args) {
    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    String factoryName = args[1];
    String instanceName = args[2];

    RadiusModule module = server.getModule(type);
    RadiusFactory<?> factory = module.getFactory(factoryName);
    if (factory == null) {
      context.println("factory not found");
      return;
    }

    try {
      Map<String, Object> configs = config(factory.getConfigMetadatas());
      RadiusInstance instance = module.createInstance(instanceName, factoryName, configs);
      context.println("created " + instance);
    } catch (InterruptedException e) {
      context.println("");
      context.println("interrupted");
    } catch (Throwable t) {
      context.println(t.getMessage());
    }
  }
Exemplo n.º 2
0
  @ScriptUsage(
      description = "create profile",
      arguments = {
        @ScriptArgument(name = "name", type = "string", description = "name of the profile"),
        @ScriptArgument(name = "secret", type = "string", description = "shared secret")
      })
  public void createProfile(String[] args) {
    try {
      RadiusProfile profile = new RadiusProfile();
      profile.setName(args[0]);
      profile.setSharedSecret(args[1]);

      context.println("---------------------------");
      context.println("Select Authenticators");
      context.println("---------------------------");
      List<String> selectedAuths = select(RadiusModuleType.Authenticator);

      context.println("---------------------------");
      context.println("Select User Databases");
      context.println("---------------------------");
      List<String> selectedUdbs = select(RadiusModuleType.UserDatabase);

      profile.setAuthenticators(selectedAuths);
      profile.setUserDatabases(selectedUdbs);

      server.createProfile(profile);
      context.println("created");
    } catch (InterruptedException e) {
      context.println("");
      context.println("interrupted");
    } catch (Exception e) {
      context.println(e.getMessage());
    }
  }
Exemplo n.º 3
0
  @ScriptUsage(
      description = "create virtual server",
      arguments = {
        @ScriptArgument(name = "name", type = "string", description = "name of the virtual server"),
        @ScriptArgument(name = "profile name", type = "string", description = "profile name"),
        @ScriptArgument(
            name = "port type",
            type = "string",
            description = "type 'auth' for authentication, or 'acct' for accounting",
            optional = true)
      })
  public void createVirtualServer(String[] args) {
    try {
      String name = args[0];
      String profileName = args[1];
      RadiusPortType portType = RadiusPortType.Authentication;
      if (args.length >= 3) portType = RadiusPortType.parse(args[2]);

      RadiusVirtualServer vs = server.createVirtualServer(name, portType, profileName);
      vs.open();

      context.println("opened " + vs.getBindAddress());
    } catch (Exception e) {
      context.println(e.getMessage());
      logger.error("kraken radius: cannot create virtual server", e);
    }
  }
Exemplo n.º 4
0
 public void virtualServers(String[] args) {
   context.println("Virtual Servers");
   context.println("-----------------");
   for (RadiusVirtualServer vs : server.getVirtualServers()) {
     context.println(vs);
   }
 }
Exemplo n.º 5
0
 public void profiles(String[] args) {
   context.println("Profiles");
   context.println("-------------");
   for (RadiusProfile profile : server.getProfiles()) {
     context.println(profile);
   }
 }
Exemplo n.º 6
0
 @ScriptUsage(
     description = "remove profile",
     arguments = {
       @ScriptArgument(name = "name", type = "string", description = "name of the profile")
     })
 public void removeProfile(String[] args) {
   server.removeProfile(args[0]);
   context.println("removed");
 }
Exemplo n.º 7
0
 @ScriptUsage(
     description = "remove virtual server",
     arguments = {
       @ScriptArgument(name = "name", type = "string", description = "name of the virtual server")
     })
 public void removeVirtualServer(String[] args) {
   try {
     String name = args[0];
     server.removeVirtualServer(name);
     context.println("removed");
   } catch (Exception e) {
     context.println(e.getMessage());
     logger.error("kraken radius: cannot remove virtual server", e);
   }
 }
Exemplo n.º 8
0
  private List<String> select(RadiusModuleType type) throws InterruptedException {
    // get instance names
    List<String> names = new ArrayList<String>();
    RadiusModule module = server.getModule(type);
    for (RadiusInstance instance : module.getInstances()) {
      names.add(instance.getName());
    }

    // print instance list
    List<String> selected = new ArrayList<String>();

    int i = 1;
    for (String name : names) {
      context.println("[" + (i++) + "] " + name);
    }
    context.println("---------------------------");

    while (true) {
      try {
        context.print("select index (0 for end): ");
        int index = Integer.valueOf(context.readLine());
        if (index == 0) break;

        if (index < 0 || index > names.size()) {
          context.println("no item corresponds to selected index");
          continue;
        }

        // add to select bucket
        String name = names.get(index - 1);
        if (!selected.contains(name)) {
          selected.add(name);
          context.println(name + " added");
        }

      } catch (NumberFormatException e) {
        context.println("");
        throw new RuntimeException("invalid number format");
      }
    }

    return selected;
  }
Exemplo n.º 9
0
  @ScriptUsage(
      description = "list all module instances",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type ")
      })
  public void instances(String[] args) {
    context.println("Instances");
    context.println("------------");

    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    RadiusModule module = server.getModule(type);

    for (RadiusInstance instance : module.getInstances()) {
      context.println("[" + instance.getName() + "] " + instance);
    }
  }
Exemplo n.º 10
0
  @ScriptUsage(
      description = "remove module instance",
      arguments = {
        @ScriptArgument(name = "module type", type = "string", description = "module type"),
        @ScriptArgument(name = "instance name", type = "string", description = "instance name")
      })
  public void removeInstance(String[] args) {
    RadiusModuleType type = RadiusModuleType.parse(args[0]);
    if (type == null) {
      context.println("unknown module type");
      return;
    }

    String instanceName = args[1];

    try {
      RadiusModule module = server.getModule(type);
      module.removeInstance(instanceName);
      context.println("removed");
    } catch (Exception e) {
      context.println(e.getMessage());
    }
  }