de.blinkt.openvpn.core.ProfileManager Java Examples

The following examples show how to use de.blinkt.openvpn.core.ProfileManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenVpnApi.java    From Cake-VPN with GNU General Public License v2.0 7 votes vote down vote up
static void startVpnInternal(Context context, String inlineConfig, String userName, String pw) throws RemoteException {
    ConfigParser cp = new ConfigParser();
    try {
        cp.parseConfig(new StringReader(inlineConfig));
        VpnProfile vp = cp.convertProfile();// Analysis.ovpn
        Log.d(TAG, "startVpnInternal: =============="+cp+"\n" +
                vp);
        vp.mName = "VPN";
        if (vp.checkProfile(context) != de.blinkt.openvpn.R.string.no_error_found){
            throw new RemoteException(context.getString(vp.checkProfile(context)));
        }
        vp.mProfileCreator = context.getPackageName();
        vp.mUsername = userName;
        vp.mPassword = pw;
        ProfileManager.setTemporaryProfile(vp);
        VPNLaunchHelper.startOpenVpn(vp, context);
    } catch (IOException | ConfigParser.ConfigParseError e) {
        throw new RemoteException(e.getMessage());
    }
}
 
Example #2
Source File: VPNActivity.java    From SimpleOpenVpn-Android with Apache License 2.0 6 votes vote down vote up
public boolean loadVpnProfile(byte[] data) {
    ConfigParser cp = new ConfigParser();
    InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(data));
    try {
        cp.parseConfig(isr);
        mVpnProfile = cp.convertProfile();
        if (filterAds) {
            mVpnProfile.mOverrideDNS = true;
            mVpnProfile.mDNS1 = "101.132.183.99";
            mVpnProfile.mDNS2 = "193.112.15.186";
        }

        ProfileManager.getInstance(this).addProfile(mVpnProfile);
        return true;
    } catch (IOException | ConfigParser.ConfigParseError e) {
        e.printStackTrace();
        return false;
    }
}
 
Example #3
Source File: OpenVpnApi.java    From Cybernet-VPN with GNU General Public License v3.0 6 votes vote down vote up
static void startVpnInternal(Context context, String inlineConfig, String userName, String pw) throws RemoteException {
    ConfigParser cp = new ConfigParser();
    try {
        cp.parseConfig(new StringReader(inlineConfig));
        VpnProfile vp = cp.convertProfile();
        vp.mName = Build.MODEL;
        if (vp.checkProfile(context) != R.string.no_error_found){
            throw new RemoteException(context.getString(vp.checkProfile(context)));
        }
        vp.mProfileCreator = context.getPackageName();
        vp.mUsername = "password";
        vp.mPassword = "password";
        ProfileManager.setTemporaryProfile(vp);
        VPNLaunchHelper.startOpenVpn(vp, context);
    } catch (IOException | ConfigParser.ConfigParseError e) {
        throw new RemoteException(e.getMessage());
    }
}
 
Example #4
Source File: OnBootReceiver.java    From android with GNU General Public License v3.0 6 votes vote down vote up
void launchVPN(Context context) {
       ConfigParser configParser = new ConfigParser();
       try {
           Server server = new Server();
           server.hostname = PrefUtils.get(context, Preferences.LAST_CONNECTED_HOSTNAME, "hub.vpn.ht");
           server.country =  PrefUtils.get(context, Preferences.LAST_CONNECTED_COUNTRY, "Nearest");
           configParser.parseConfig(new StringReader(VPNHTConfig.generate(PrefUtils.getPrefs(context), server, PrefUtils.get(context, Preferences.LAST_CONNECTED_FIREWALL, false))));
           VpnProfile profile = configParser.convertProfile();
           profile.mName = server.country;
           ProfileManager.setTemporaryProfile(profile);

           Intent intent = new Intent(context, LaunchVPN.class);
           intent.setAction(Intent.ACTION_MAIN);
           intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString());
           intent.putExtra(LaunchVPN.EXTRA_HIDELOG, true);
           intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(intent);
       } catch (IOException e) {
           e.printStackTrace();
       } catch (ConfigParser.ConfigParseError configParseError) {
           configParseError.printStackTrace();
       }
}
 
Example #5
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 6 votes vote down vote up
public void startVPN(String name, String inlineConfig) throws RemoteException {
    checkOpenVPNPermission();

    ConfigParser cp = new ConfigParser();
    try {
        cp.parseConfig(new StringReader(inlineConfig));
        VpnProfile vp = cp.convertProfile();
        vp.mName = name;
        if (vp.checkProfile(getApplicationContext()) != R.string.no_error_found)
            throw new RemoteException(getString(vp.checkProfile(getApplicationContext())));

        /*int needpw = vp.needUserPWInput(false);
        if(needpw !=0)
            throw new RemoteException("The inline file would require user input: " + getString(needpw));
            */

        ProfileManager.setTemporaryProfile(vp);
        startProfile(vp);
    } catch (IOException | ConfigParseError e) {
        throw new RemoteException(e.getMessage());
    }
}
 
Example #6
Source File: DisconnectVPNActivity.java    From Cybernet-VPN with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == DialogInterface.BUTTON_POSITIVE) {
        ProfileManager.setConntectedVpnProfileDisconnected(this);
        if (mService != null && mService.getManagement() != null) {
            mService.getManagement().stopVPN(false);
        }
    }
    finish();
}
 
Example #7
Source File: ServerActivity.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
private void stopVpn() {
    //prepareStopVPN();
    ProfileManager.setConntectedVpnProfileDisconnected(this);
    if (mVPNService != null && mVPNService.getManagement() != null)
        mVPNService.getManagement().stopVPN(false);

}
 
Example #8
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<APIVpnProfile> getProfiles() throws RemoteException {
    checkOpenVPNPermission();

    ProfileManager pm = ProfileManager.getInstance(getBaseContext());

    List<APIVpnProfile> profiles = new LinkedList<>();

    for (VpnProfile vp : pm.getProfiles()) {
        if (!vp.profileDeleted)
            profiles.add(new APIVpnProfile(vp.getUUIDString(), vp.mName, vp.mUserEditable, vp.mProfileCreator));
    }

    return profiles;
}
 
Example #9
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void startProfile(String profileUUID) throws RemoteException {
    checkOpenVPNPermission();

    VpnProfile vp = ProfileManager.get(getBaseContext(), profileUUID);
    if (vp.checkProfile(getApplicationContext()) != R.string.no_error_found)
        throw new RemoteException(getString(vp.checkProfile(getApplicationContext())));

    startProfile(vp);
}
 
Example #10
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeProfile(String profileUUID) throws RemoteException {
    checkOpenVPNPermission();
    ProfileManager pm = ProfileManager.getInstance(getBaseContext());
    VpnProfile vp = ProfileManager.get(getBaseContext(), profileUUID);
    pm.removeProfile(ExternalOpenVPNService.this, vp);
}
 
Example #11
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateState(String state, String logmessage, int resid, ConnectionStatus level) {
    mMostRecentState = new UpdateMessage(state, logmessage, level);
    if (ProfileManager.getLastConnectedVpn() != null)
        mMostRecentState.vpnUUID = ProfileManager.getLastConnectedVpn().getUUIDString();

    Message msg = mHandler.obtainMessage(SEND_TOALL, mMostRecentState);
    msg.sendToTarget();

}
 
Example #12
Source File: DisconnectVPN.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == DialogInterface.BUTTON_POSITIVE) {
        ProfileManager.setConntectedVpnProfileDisconnected(this);
        if (mService != null && mService.getManagement() != null)
            mService.getManagement().stopVPN();
    }
    finish();
}
 
Example #13
Source File: LaunchVPN.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    // Resolve the intent

    final Intent intent = getIntent();
    final String action = intent.getAction();

    // If the intent is a request to create a shortcut, we'll do that and exit


    if (Intent.ACTION_MAIN.equals(action)) {
        // we got called to be the starting point, most likely a shortcut
        String shortcutUUID = intent.getStringExtra(EXTRA_KEY);
        String shortcutName = intent.getStringExtra(EXTRA_NAME);
        mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false);

        VpnProfile profileToConnect = ProfileManager.get(this, shortcutUUID);
        if (shortcutName != null && profileToConnect == null)
            profileToConnect = ProfileManager.getInstance(this).getProfileByName(shortcutName);

        if (profileToConnect == null) {
            VpnStatus.logError(R.string.shortcut_profile_notfound);
            // show Log window to display error
            finish();
            return;
        }

        mSelectedProfile = profileToConnect;
        launchVPN();

    }
}
 
Example #14
Source File: DisconnectVPNActivity.java    From Cake-VPN with GNU General Public License v2.0 4 votes vote down vote up
public void stopVpn(){
    ProfileManager.setConntectedVpnProfileDisconnected(this);
    if (mService != null && mService.getManagement() != null) {
        mService.getManagement().stopVPN(false);
    }
}
 
Example #15
Source File: VPNActivity.java    From SimpleOpenVpn-Android with Apache License 2.0 4 votes vote down vote up
/**
 * 停止VPN
 */
public void stopVpn() {
    ProfileManager.setConntectedVpnProfileDisconnected(this);
    if (mVPNService != null && mVPNService.getManagement() != null)
        mVPNService.getManagement().stopVPN(false);
}
 
Example #16
Source File: LaunchVPN.java    From android with GNU General Public License v3.0 3 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mPM = ProfileManager.getInstance(this);

}