openvpn_flutter_update 1.2.1 openvpn_flutter_update: ^1.2.1 copied to clipboard
A plugin that allow you to connect OpenVPN service with Flutter
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:openvpn_flutter/openvpn_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late OpenVPN engine;
VpnStatus? status;
VPNStage? stage;
bool _granted = false;
@override
void initState() {
engine = OpenVPN(
onVpnStatusChanged: (data) {
setState(() {
status = data;
});
},
onVpnStageChanged: (data, raw) {
setState(() {
stage = data;
});
},
);
engine.initialize(
groupIdentifier: "group.com.laskarmedia.vpn",
providerBundleIdentifier: "id.laskarmedia.openvpnFlutterExample.VPNExtension",
localizedDescription: "VPN by Nizwar",
lastStage: (stage) {
setState(() {
this.stage = stage;
});
},
lastStatus: (status) {
setState(() {
this.status = status;
});
},
);
super.initState();
}
Future<void> initPlatformState() async {
// print("defaultVpnUsername $defaultVpnUsername");
// print("defaultVpnUsername $defaultVpnPassword");
// print("defaultVpnUsername $config");
engine.connect(config, "USA",
username: defaultVpnUsername, password: defaultVpnPassword, certIsRequired: false);
if (!mounted) return;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(stage?.toString() ?? VPNStage.disconnected.toString()),
Text(status?.toJson().toString() ?? ""),
TextButton(
child: const Text("Start"),
onPressed: () {
initPlatformState();
},
),
TextButton(
child: const Text("STOP"),
onPressed: () {
engine.disconnect();
},
),
if (Platform.isAndroid)
TextButton(
child: Text(_granted ? "Granted" : "Request Permission"),
onPressed: () {
engine.requestPermissionAndroid().then((value) {
setState(() {
_granted = value;
});
});
},
),
],
),
),
),
);
}
}
const String defaultVpnUsername = "SubUser-JRUEUOCGJAZVIKB4_57_167@HUB_MOB811";
const String defaultVpnPassword = "OVYUWY2WNA5HURTPMI2VGOZULYZUI4JJ";
String config = '''dev tun
proto tcp
#topology subnet
remote 18.185.248.12 1194
cipher AES-128-CBC
auth SHA1
resolv-retry infinite
nobind
persist-key
persist-tun
client
verb 3
#remote-cert-tls server
<auth-user-pass>
SubUser-JRUEUOCGJAZVIKB4_57_167@HUB_MOB811
OVYUWY2WNA5HURTPMI2VGOZULYZUI4JJ
</auth-user-pass>
<ca>
-----BEGIN CERTIFICATE-----
MIIDxDCCAqygAwIBAgIBADANBgkqhkiG9w0BAQsFADBhMRowGAYDVQQDDBFzZS1j
bHVzdGVybWFuYWdlcjEaMBgGA1UECgwRc2UtY2x1c3Rlcm1hbmFnZXIxGjAYBgNV
BAsMEXNlLWNsdXN0ZXJtYW5hZ2VyMQswCQYDVQQGEwJVUzAeFw0xOTA2MTUxNTE3
MjRaFw0zNzEyMzExNTE3MjRaMGExGjAYBgNVBAMMEXNlLWNsdXN0ZXJtYW5hZ2Vy
MRowGAYDVQQKDBFzZS1jbHVzdGVybWFuYWdlcjEaMBgGA1UECwwRc2UtY2x1c3Rl
cm1hbmFnZXIxCzAJBgNVBAYTAlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAo8Q40oop1dVxXZpNtjEzrLSOPX81ZQEe5Ys3fMawci3oGEaQ0xCEu4yh
WCLkxsAiYXTVV6ZdyfoLSMFG2ojGIWAZWqXFTJeJO/dLBIPDZw6JXg7uwsHzGt3s
z3NFvc0IYgLXzBKm2QzpoRFYincgbbygAT93mZcuqjVixPnAc4vVlVZr635mnRPH
7MvSeBRNUbjMBsevDOhCnFNBG7BJSXAIWPgNudrJlrt9uwjSJLWKniefJTXCrIA3
/1Yh5rVGg26s7SU6LVC1KSOUY9Dfz1iW1uy7/38+fZqxsEAOHfXbjp31t35JaPwy
Q6ItgFDMmjc8Is9FGWGpqcQuL8bLxQIDAQABo4GGMIGDMA8GA1UdEwEB/wQFMAMB
Af8wC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