Add peer management routes and server configuration services
This commit is contained in:
29
lib/core/utils.dart
Normal file
29
lib/core/utils.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
/// Get the current WAN IP address of the device.
|
||||
Future<String> getWanIp() async {
|
||||
// Get the IP address of the server. https://api.ipify.org?format=json
|
||||
var ipResponse = await http.get(Uri.parse('https://api.ipify.org?format=json'));
|
||||
if (ipResponse.statusCode == 200) {
|
||||
var ipData = jsonDecode(ipResponse.body);
|
||||
return ipData['ip'] as String;
|
||||
} else {
|
||||
throw Exception('Failed to get server IP address');
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if Wireguard is installed on the system.
|
||||
Future<bool> isWireguardInstalled() async {
|
||||
try {
|
||||
var result = await Process.run('wg', ['--version']);
|
||||
return result.exitCode == 0;
|
||||
} catch (e) {
|
||||
print('Error checking WireGuard installation: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool get kIsRunningInDocker => File('/.dockerenv').existsSync();
|
||||
Reference in New Issue
Block a user