123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- // 代理类
- class Proxy {
- final String name;
- final String type;
- final String server;
- final int port;
- final String uuid;
- final int udp;
- final String? flow;
- final String? servername;
- final bool? tls;
- Proxy({
- required this.name,
- required this.type,
- required this.server,
- required this.port,
- required this.uuid,
- required this.udp,
- this.flow,
- this.servername,
- this.tls,
- });
- String toYamlString() {
- var lines = [
- 'name: $name',
- 'type: $type',
- 'server: $server',
- 'port: $port',
- 'uuid: $uuid',
- 'udp: $udp',
- ];
- if (flow != null) lines.add('flow: $flow');
- if (servername != null) lines.add('servername: $servername');
- if (tls != null) lines.add('tls: $tls');
- return lines.map((line) => ' - $line').join('\n');
- }
- }
- // 代理组类
- class ProxyGroup {
- final String name;
- final String type;
- final List<String> proxies;
- ProxyGroup({
- required this.name,
- required this.type,
- required this.proxies,
- });
- String toYamlString() {
- return ' - name: $name\n type: $type\n proxies: [${proxies.join(', ')}]';
- }
- }
- // 主配置类
- class YamlConfig {
- final int mixedPort;
- final bool allowLan;
- final String bindAddress;
- final String mode;
- final String logLevel;
- final String externalController;
- final List<Proxy> proxies;
- final List<ProxyGroup> proxyGroups;
- final List<String> rules;
- YamlConfig({
- required this.mixedPort,
- required this.allowLan,
- required this.bindAddress,
- required this.mode,
- required this.logLevel,
- required this.externalController,
- required this.proxies,
- required this.proxyGroups,
- required this.rules,
- });
- String toYamlString() {
- return '''mixed-port: $mixedPort
- allow-lan: $allowLan
- bind-address: '$bindAddress'
- mode: $mode
- log-level: $logLevel
- external-controller: '$externalController'
- proxies:
- ${proxies.map((proxy) => proxy.toYamlString()).join('\n')}
- proxy-groups:
- ${proxyGroups.map((group) => group.toYamlString()).join('\n')}
- rules:
- - ${rules.join('\n- ')}''';
- }
- }
- // void main() {
- // // 为示例,这里仅添加了一些代理和代理组。
- // var exampleProxies = [
- // Proxy(
- // name: '香港22-vless',
- // type: 'vless',
- // server: 'sz.ip2000.top',
- // port: 27399,
- // uuid: '459b4a80-bd61-4ecd-a26b-e9c1809d9e45',
- // udp: 1,
- // flow: 'xtls-rprx-vision',
- // servername: 'www.amazon.com',
- // tls: true,
- // ),
- // // ... 可以根据需要添加更多代理
- // ];
- //
- // var exampleProxyGroup = ProxyGroup(
- // name: 'proxy',
- // type: 'select',
- // proxies: ['香港22-vless', '香港原生61D'],
- // );
- //
- // var config = YamlConfig(
- // mixedPort: 7890,
- // allowLan: true,
- // bindAddress: '*',
- // mode: 'rule',
- // logLevel: 'info',
- // externalController: '127.0.0.1:9090',
- // proxies: exampleProxies,
- // proxyGroups: [exampleProxyGroup],
- // rules: ['MATCH,用户中心'],
- // );
- //
- // // var fileName = 'config_output.yaml';
- // // File(fileName).writeAsStringSync(config.toYamlString());
- // // print('YAML config saved to $fileName');
- // }
|