Skip to content

Instantly share code, notes, and snippets.

@naz013
Created August 3, 2018 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naz013/0678430273750e7a313e43996d109195 to your computer and use it in GitHub Desktop.
Save naz013/0678430273750e7a313e43996d109195 to your computer and use it in GitHub Desktop.
public String getConfigFile(Context context, boolean configForOvpn3) {
boolean isDebug = BuildConfig.DEBUG && PrefUtils.getBoolean(context, PrefUtils.USE_CUSTOM, false);
File cacheDir = context.getCacheDir();
String cfg = "";
// Enable management interface
cfg += "# Enables connection to GUI\n";
cfg += "management ";
cfg += cacheDir.getAbsolutePath() + "/" + "mgmtsocket";
cfg += " unix\n";
cfg += "management-client\n";
// Not needed, see updated man page in 2.3
//cfg += "management-signal\n";
cfg += "management-query-passwords\n";
cfg += "management-hold\n\n";
if (!configForOvpn3) {
cfg += String.format("setenv IV_GUI_VER %s \n", openVpnEscape(getVersionEnvString(context)));
}
cfg += "machine-readable-output\n";
// Users are confused by warnings that are misleading...
cfg += "ifconfig-nowarn\n";
boolean useTLSClient = (mAuthenticationType != TYPE_STATICKEYS);
if (useTLSClient && mUsePull) {
cfg += "client\n";
} else if (mUsePull) {
cfg += "pull\n";
} else if (useTLSClient) {
cfg += "tls-client\n";
}
//cfg += "verb " + mVerb + "\n";
cfg += "verb " + MAXLOGLEVEL + "\n";
if (mConnectRetryMax == null) {
mConnectRetryMax = "0";
}
if (isDebug) {
cfg += "connect-retry-max " + PrefUtils.getString(context, PrefUtils.CONNECT_RETRY_MAX, "0") + "\n";
} else {
if (!mConnectRetryMax.equals("-1")) {
cfg += "connect-retry-max " + mConnectRetryMax + "\n";
}
}
if (mConnectRetry == null) {
mConnectRetry = "60";
}
if (isDebug) {
cfg += "connect-retry " + PrefUtils.getString(context, PrefUtils.CONNECT_RETRY, "60") + "\n";
cfg += "resolv-retry " + PrefUtils.getString(context, PrefUtils.RESOLVE_RETRY, "infinite") + "\n";
if (PrefUtils.getBoolean(context, PrefUtils.TLS_EXIT, true)) {
cfg += "tls-exit\n";
}
cfg += "route-delay " + PrefUtils.getString(context, PrefUtils.ROUTE_DELAY, "2") + "\n";
if (PrefUtils.getBoolean(context, PrefUtils.REDIRECT_GATEWAY, true)) {
cfg += "redirect-gateway\n";
}
} else {
cfg += "connect-retry " + mConnectRetry + "\n";
cfg += "resolv-retry infinite\n";
cfg += "tls-exit\n";
cfg += "route-delay 2\n";
cfg += "redirect-gateway\n";
}
// We cannot use anything else than tun
if (isDebug) cfg += "dev " + PrefUtils.getString(context, PrefUtils.DEV, "tun") + "\n\n";
else cfg += "dev tun\n";
if (PrefUtils.isUseSmoke(App.getInstance().getApplicationContext())) {
if (isDebug) cfg += "proto " + PrefUtils.getString(context, PrefUtils.PROTO, "udp") + "\n\n";
else cfg += "proto udp\n";
}
// TODO
// Server Address
if (isDebug) {
cfg += "remote " + PrefUtils.getString(context, PrefUtils.REMOTE_IP, "127.0.0.1")
+ " " + PrefUtils.getString(context, PrefUtils.REMOTE_PORT, "4987");
} else {
cfg += "remote ";
cfg += mServerName;
cfg += " ";
cfg += mServerPort;
}
if (mUseUdp && !PrefUtils.isUseSmoke(App.getInstance().getApplicationContext())) {
cfg += " udp\n";
} else if (PrefUtils.isUseSmoke(App.getInstance().getApplicationContext())) {
cfg += "\n";
if (isDebug) {
if (PrefUtils.getBoolean(context, PrefUtils.NOBIND, true)) {
cfg += "nobind\n";
}
if (PrefUtils.getBoolean(context, PrefUtils.PERSIST_KEY, true)) {
cfg += "persist-key\n";
}
} else {
cfg += "nobind\n";
cfg += "persist-key\n";
}
cfg += "persist-tun\n";
} else {
cfg += " tcp-client\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment