42 lines
1.3 KiB
Dart
42 lines
1.3 KiB
Dart
import 'dart:io';
|
|
import 'package:waylume_server/config/supabase_config.dart';
|
|
import 'package:waylume_server/core/utils.dart';
|
|
|
|
class ServerService {
|
|
static Future<void> registerServer() async {
|
|
|
|
GeolocationData geolocationData = await getGeolocationData();
|
|
|
|
String ip = "${geolocationData.ip}:${fromEnivronment("EXTERNAL_PORT") ?? "3000"}";
|
|
|
|
var existsCheck = await SUPABASE_CLIENT
|
|
.from("waylume_servers")
|
|
.select()
|
|
.eq("id", fromEnivronment('SERVER_ID'))
|
|
.eq("host_ip", ip);
|
|
|
|
if (existsCheck.isEmpty) {
|
|
await SUPABASE_CLIENT
|
|
.from("waylume_servers")
|
|
.insert({
|
|
"id": fromEnivronment('SERVER_ID')!,
|
|
"last_heartbeat": DateTime.now().toUtc().toIso8601String(),
|
|
"host_ip": ip,
|
|
"geolocation": {
|
|
"country": geolocationData.countryName,
|
|
"country_code": geolocationData.countryCode,
|
|
"city": geolocationData.city,
|
|
"coords": [
|
|
geolocationData.latitude,
|
|
geolocationData.longitude
|
|
],
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
static Future<void> isolatePeers() async {
|
|
await Process.run('iptables', ['-I', 'FORWARD', '-i', 'wg0', '-o', 'wg0', '-j', 'DROP']);
|
|
await Process.run('iptables', ['-I', 'FORWARD', '-i', 'wg0', '-o', 'wg0', '-m', 'state', '--state', 'ESTABLISHED,RELATED', '-j', 'ACCEPT']);
|
|
}
|
|
} |