58 lines
1.2 KiB
Dart
58 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
class HostAndPort {
|
|
String host;
|
|
int port;
|
|
|
|
HostAndPort({this.host, this.port});
|
|
}
|
|
|
|
class ManageConfig {
|
|
String listen;
|
|
}
|
|
|
|
class ProxyItemConfig {
|
|
String listen;
|
|
String backend;
|
|
List<String> allowIps;
|
|
}
|
|
|
|
class ProxyConfig {
|
|
ManageConfig managementConfig;
|
|
List<ProxyItemConfig> tcpListens;
|
|
}
|
|
|
|
ProxyConfig parseProxyConfig(String config) {
|
|
final jsonConfig = json.decode(config);
|
|
|
|
final managementConfig = jsonConfig['managementConfig'];
|
|
print(managementConfig);
|
|
|
|
// print(jsonConfig);
|
|
return null;
|
|
}
|
|
|
|
HostAndPort parseHostAndPort(String hnp) {
|
|
final indexOfC = hnp.indexOf(":");
|
|
if (indexOfC < 0) {
|
|
throw 'Missing port: ' + hnp;
|
|
}
|
|
var host = hnp.substring(0, indexOfC);
|
|
final port = int.parse(hnp.substring(indexOfC + 1));
|
|
if (host.isEmpty) {
|
|
host = "0.0.0.0";
|
|
}
|
|
return HostAndPort(host: host, port: port);
|
|
}
|
|
|
|
Future<ProxyConfig> loadProxyConfig(String configFile
|
|
/*, {List<String> files} ?? */) async {
|
|
final configFn = File(configFile);
|
|
if (!await configFn.exists()) {
|
|
throw 'Config file not found: ' + configFile;
|
|
}
|
|
return parseProxyConfig(await configFn.readAsString());
|
|
}
|