Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.updateconf);

    File sdcardDir = Environment.getExternalStorageDirectory();
    conf_file = new File(sdcardDir, confFile);
    log_file = sdcardDir.getAbsolutePath() + "/oor.log";

    iface_list = ConfigTools.get_ifaces_list();

    // Spinner spinner = (Spinner) findViewById(R.id.IfaceNameSpinner);
    MultiSelectionSpinner spinner = (MultiSelectionSpinner) findViewById(R.id.IfaceNameSpinner);
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, iface_list);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    // spinner.setAdapter(adapter);
    spinner.setItems(iface_list);

    Spinner logSpinner = (Spinner) findViewById(R.id.LogSpinner);
    ArrayAdapter<CharSequence> logAdapter =
        ArrayAdapter.createFromResource(
            this, R.array.LogLevelArray, android.R.layout.simple_spinner_item);
    logSpinner.setAdapter(logAdapter);

    if (!conf_file.exists()) {
      createConfFile();
    }

    readConfFileAndFillParameters();
  }
Пример #2
0
  public boolean get_and_validate_parameters() {
    EditText e;
    CheckBox c;
    MultiSelectionSpinner multi_spinner;
    Spinner spinner;
    String eidv4 = "";
    String eidv6 = "";
    String mapResolver = "";
    String mapServer = "";
    String mapServerKey = "password";
    String pETR = "";
    String DNS_1 = "";
    String DNS_2 = "";
    boolean overrideDNS_bool = false;
    boolean nat_aware_bool = false;

    String message = "ERROR: The following fields are not valid: \n";
    String error = "";

    e = (EditText) findViewById(R.id.updateConfeid4Text);
    eidv4 = e.getText().toString();

    e = (EditText) findViewById(R.id.updateConfeid6Text);
    eidv6 = e.getText().toString();

    c = (CheckBox) findViewById(R.id.updateConf_NAT_aware);
    nat_aware_bool = c.isChecked();

    e = (EditText) findViewById(R.id.updateConfMRText);
    mapResolver = e.getText().toString();

    e = (EditText) findViewById(R.id.updateConfMSText);
    mapServer = e.getText().toString();

    e = (EditText) findViewById(R.id.updateConfMSKeyText);
    mapServerKey = e.getText().toString();

    e = (EditText) findViewById(R.id.updateConf_proxy_etr);
    pETR = e.getText().toString();

    c = (CheckBox) findViewById(R.id.updateConfDNSCheck);
    overrideDNS_bool = c.isChecked();

    e = (EditText) findViewById(R.id.updateConfDNS1Text);
    DNS_1 = e.getText().toString();

    e = (EditText) findViewById(R.id.updateConfDNS2Text);
    DNS_2 = e.getText().toString();

    multi_spinner = (MultiSelectionSpinner) findViewById(R.id.IfaceNameSpinner);
    ifaces = multi_spinner.getSelectedStrings();

    spinner = (Spinner) findViewById(R.id.LogSpinner);
    logLevel = spinner.getSelectedItem().toString();

    if (!eidv4.equals("") && !ConfigTools.validate_IP_Address(eidv4)) {
      error = error.concat("  - EID-IPv4\n");
    }
    if (!eidv6.equals("") && !ConfigTools.validate_IP_Address(eidv6)) {
      error = error.concat("  - EID-IPv6\n");
    }
    if (!ConfigTools.validate_IP_Address(mapResolver)) {
      error = error.concat("  - Map-Resolver\n");
    }
    if (!ConfigTools.validate_IP_Address(mapServer)) {
      error = error.concat("  - Map-Server\n");
    }
    if (!ConfigTools.validate_IP_Address(pETR)) {
      error = error.concat("  - Proxy ETR\n");
    }
    if (overrideDNS_bool && (DNS_1.equals("") || !ConfigTools.validate_IP_Address(DNS_1))) {
      error = error.concat("  - Primary DNS\n");
    }
    if ((overrideDNS_bool && !DNS_2.equals("") && !ConfigTools.validate_IP_Address(DNS_2))) {
      error = error.concat("  - Secondary DNS\n");
    }
    if (nat_aware_bool == true && !eidv4.equals("") && !eidv6.equals("")) {
      error = error.concat("  - Only one EID is supported\n");
    }

    if (!error.equals("")) {
      displayMessage(message + error, false, null);
      return (false);
    }
    if (eidv4.equals("") && eidv6.equals("")) {
      displayMessage("ERROR: At least one EID should be supplied", false, null);
      return (false);
    }

    eidIPv4 = eidv4;
    eidIPv6 = eidv6;
    MR = mapResolver;
    MS = mapServer;
    MSKey = mapServerKey;
    proxyETR = pETR;
    DNS1 = DNS_1;
    DNS2 = DNS_2;
    overrideDNS = overrideDNS_bool;
    nat_aware = nat_aware_bool;

    return (true);
  }
Пример #3
0
  public void readConfFileAndFillParameters() {

    try {

      BufferedReader br = new BufferedReader(new FileReader(conf_file));
      String line = br.readLine();
      String sub_line = null;
      String sub_line_1 = null;
      ifaces = new ArrayList<String>();

      while (line != null) {
        if (line.startsWith("#")) {
          line = br.readLine();
          continue;
        }
        line = line.toLowerCase();
        line = line.replaceAll("\\s", "");

        if (line.contains("database-mapping")) {
          do {
            sub_line = br.readLine();
            if (sub_line.startsWith("#")) {
              sub_line = br.readLine();
              continue;
            }
            sub_line = sub_line.toLowerCase();
            sub_line = sub_line.replaceAll("\\s", "");

            if (sub_line.contains("eid-prefix")) {
              String[] tmp = sub_line.split("=");
              if (tmp.length < 2) continue;
              String[] tmp_1 = tmp[1].split("/");
              if (tmp_1.length < 2) continue;
              if (tmp_1[0].contains(":")) {
                eidIPv6 = tmp_1[0];
                EditText e = (EditText) findViewById(R.id.updateConfeid6Text);
                e.setText(eidIPv6);
              } else if (tmp_1[0].contains(".")) {
                eidIPv4 = tmp_1[0];
                EditText e = (EditText) findViewById(R.id.updateConfeid4Text);
                e.setText(eidIPv4);
              }
            }
            if (sub_line.contains("rloc-iface")) {
              sub_line = br.readLine();
              if (sub_line.startsWith("#")) {
                sub_line = br.readLine();
                continue;
              }
              sub_line = sub_line.toLowerCase();
              sub_line = sub_line.replaceAll("\\s", "");

              if (sub_line.contains("interface")) {
                String[] tmp = sub_line.split("=");
                if (tmp.length < 2) continue;
                String iface_name = tmp[1];

                Iterator<String> iface_it = iface_list.iterator();
                while (iface_it.hasNext()) {
                  if (iface_it.next().equals(iface_name)) {
                    if (!ifaces.contains(iface_name)) {
                      ifaces.add(iface_name);
                    }
                    break;
                  }
                }
              }
            }
          } while (!sub_line.contains("}"));
        } else if (line.contains("map-resolver")) {
          sub_line = br.readLine();
          if (sub_line.startsWith("#")) {
            sub_line = br.readLine();
            continue;
          }
          sub_line = sub_line.replaceAll("\\s", "");

          if (sub_line.contains(",")) {
            String[] tmp = sub_line.split(",");
            if (tmp.length != 0) {
              MR = tmp[0];
            }
          } else {
            MR = sub_line;
          }

          EditText e = (EditText) findViewById(R.id.updateConfMRText);
          e.setText(MR);
        } else if (line.contains("nat-traversal") && !line.startsWith("#")) {
          do {
            sub_line = br.readLine();
            if (sub_line.startsWith("#")) {
              sub_line = br.readLine();
              continue;
            }
            sub_line = sub_line.toLowerCase();
            sub_line = sub_line.replaceAll("\\s", "");

            if (sub_line.contains("nat_aware")) {
              String[] tmp = sub_line.split("=");
              if (tmp.length < 2) continue;
              String nat_aware_aux = tmp[1];
              if (nat_aware_aux.equals("on") || nat_aware_aux.equals("true")) {
                nat_aware = true;
              } else {
                nat_aware = false;
              }
            }
          } while (!sub_line.contains("}"));
          CheckBox c = (CheckBox) findViewById(R.id.updateConf_NAT_aware);
          c.setChecked(nat_aware);
        } else if (line.contains("map-server")) {
          do {
            sub_line = br.readLine();
            if (sub_line.startsWith("#")) {
              sub_line = br.readLine();
              continue;
            }
            sub_line_1 = sub_line; // Not lose uppercase in password
            sub_line = sub_line.toLowerCase();
            sub_line = sub_line.replaceAll("\\s", "");

            if (sub_line.contains("address")) {
              String[] tmp = sub_line.split("=");
              if (tmp.length > 1) {
                MS = tmp[1];
              }
            } else if (sub_line.contains("key")) {
              String[] tmp = sub_line_1.split("=");
              if (tmp.length > 1) {
                MSKey = tmp[1];
              }
            }
          } while (!sub_line.contains("}"));

          EditText e = (EditText) findViewById(R.id.updateConfMSText);
          e.setText(MS);

          EditText et = (EditText) findViewById(R.id.updateConfMSKeyText);
          et.setText(MSKey);
        } else if (line.contains("proxy-etr")) {
          do {
            sub_line = br.readLine();
            if (sub_line.startsWith("#")) {
              sub_line = br.readLine();
              continue;
            }
            sub_line = sub_line.toLowerCase();
            sub_line = sub_line.replaceAll("\\s", "");

            if (sub_line.contains("address")) {
              String[] tmp = sub_line.split("=");
              if (tmp.length > 1) {
                proxyETR = tmp[1];
              }
            }
          } while (!sub_line.contains("}"));

          EditText e = (EditText) findViewById(R.id.updateConf_proxy_etr);
          e.setText(proxyETR);

        } else if (line.contains("override-dns=")) {
          String[] tmp = line.split("=");
          if (tmp.length > 1) {
            String overrideDNS_aux = tmp[1];
            if (overrideDNS_aux.equals("on") || overrideDNS_aux.equals("true")) {
              overrideDNS = true;
            } else {
              overrideDNS = false;
            }
          }

          CheckBox c = (CheckBox) findViewById(R.id.updateConfDNSCheck);
          c.setChecked(overrideDNS);
        } else if (line.contains("override-dns-primary=")) {
          String[] tmp = line.split("=");
          if (tmp.length > 1) {
            if (ConfigTools.validate_IP_Address(tmp[1])) {
              DNS1 = tmp[1];
            }
          }
          EditText e = (EditText) findViewById(R.id.updateConfDNS1Text);
          e.setText(DNS1);
        } else if (line.contains("override-dns-secondary=")) {
          String[] tmp = line.split("=");
          if (tmp.length > 1) {
            if (ConfigTools.validate_IP_Address(tmp[1])) {
              DNS2 = tmp[1];
            }
          }
          EditText e = (EditText) findViewById(R.id.updateConfDNS2Text);
          e.setText(DNS2);
        } else if (line.contains("debug=")) {
          String[] tmp = line.split("=");
          if (tmp.length > 1) {
            logLevel = tmp[1];
          }
          Spinner log_spinner = (Spinner) findViewById(R.id.LogSpinner);
          log_spinner.setSelection(new Integer(logLevel).intValue());
        }

        line = br.readLine();
      }
      MultiSelectionSpinner spinner = (MultiSelectionSpinner) findViewById(R.id.IfaceNameSpinner);
      spinner.setSelection(ifaces);

      EditText e = (EditText) findViewById(R.id.updateConfDNS1Text);
      e.setEnabled(overrideDNS);
      e = (EditText) findViewById(R.id.updateConfDNS2Text);
      e.setEnabled(overrideDNS);

    } catch (IOException e) {;
    }
  }