NavidShokoufeh / sstp_flutter

BSD 3-Clause "New" or "Revised" License
5 stars 5 forks source link

SstpFlutter

SstpFlutter is a Flutter plugin for SSTP VPN connections. It provides a convenient way to manage SSTP VPN connections, monitor connection status, and configure various settings.

Features

Getting Started

To use this plugin, add sstp_flutter as a dependency in your pubspec.yaml file.

dependencies:
  sstp_flutter: ^version

Then, run flutter pub get to install the dependency.

Example

import 'package:sstp_flutter/sstp_flutter.dart';

void main() async {
  SstpFlutter sstpFlutter = SstpFlutter();
  var cert_dir = "";

  // Take VPN permission
  await sstpFlutter.takePermission();

  // Save server data
  await sstpFlutter.saveServerData(server: SSTPServer(host: 'example.com',port:443 , username: 'user', password: 'password',verifyHostName : false, useTrustedCert: false, sslVersion: SSLVersions.DEFAULT, showDisconnectOnNotification: true, notificationText: "Notification Text Holder"));

  // Opens files and then returns selected directory path
  cert_dir = await sstpFlutterPlugin.addCertificate();

  // Connect to SSTP VPN
  await sstpFlutter.connectVpn();

  // Monitor connection status
  sstpFlutter.onResult(
    onConnectedResult: (ConnectionTraffic traffic) {
      print('Connected - Download Traffic: ${traffic.downloadTraffic}, Upload Traffic: ${traffic.uploadTraffic}');
    },
    onConnectingResult: () {
      print('Connecting...');
    },
    onDisconnectedResult: () {
      print('Disconnected');
    },
    onError: () {
      print('Error occurred');
    },
  );

  // Monitor connection Duration
  StreamBuilder(
  initialData: const Duration(),
  stream: sstpFlutterPlugin.timer,
  builder: (context, timer) {
    return timer.hasData
        ? Text("connection time : ${timer.data}")
        : const Text("connection time :no Data");
   })

  // Disconnect from SSTP VPN
  await sstpFlutter.disconnect();

  // Get installed apps
  List<InstalledAppInfo> installedApps = await sstpFlutter.getInstalledApps();
  print('Installed Apps: $installedApps');

  // Get allowed apps
  List<String> allowedApps = await sstpFlutter.getAllowedApps();
  print('Allowed Apps: $allowedApps');

  // Add apps to allowed apps
  await sstpFlutter.addToAllowedApps(packages: ['com.example.app']);

  // Enable DNS
  await sstpFlutter.enableDns(DNS: '8.8.8.8');

  // Disable DNS
  await sstpFlutter.disableDNS();

  // Enable proxy
  await sstpFlutter.enableProxy(proxy: SSTPProxy(host: 'proxy.example.com', port: 8080));

  // Disable proxy
  await sstpFlutter.disableProxy();

  // Check last connection status
  UtilKeys status = await sstpFlutter.checkLastConnectionStatus();
  print('Last Connection Status: $status');
}

Please note that the plugin methods may throw exceptions (PlatformException). Handle them appropriately in your application.

Contributions and Issues

Feel free to contribute to this project by submitting pull requests or reporting issues on the GitHub repository.

This addition emphasizes that the purpose of the plugin is to provide a secure means for web surfing using SSTP VPN connections. Adjustments can be made based on your specific requirements.

Support this Project

If you find this project helpful, consider supporting it by making a donation. Major of Your contribution will spend on charity every month.

"Buy Me A Coffee"

"زرین پال"

Thank you for your support! 🚀//zarinp.al/navid_shokoufeh