| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
 1000
 1001
 1002
 1003
 1004
 1005
 1006
 1007
 1008
 1009
 1010
 1011
 1012
 1013
 1014
 1015
 1016
 1017
 1018
 1019
 1020
 1021
 1022
 1023
 1024
 1025
 1026
 1027
 1028
 1029
 1030
 1031
 1032
 1033
 1034
 1035
 1036
 1037
 1038
 1039
 1040
 1041
 1042
 1043
 1044
 1045
 1046
 1047
 1048
 1049
 1050
 1051
 1052
 1053
 1054
 1055
 1056
 1057
 1058
 1059
 1060
 1061
 1062
 1063
 1064
 1065
 1066
 1067
 1068
 1069
 1070
 1071
 1072
 1073
 1074
 1075
 1076
 1077
 1078
 1079
 1080
 1081
 1082
 1083
 1084
 1085
 1086
 1087
 1088
 1089
 1090
 1091
 1092
 1093
 1094
 1095
 1096
 1097
 1098
 1099
 1100
 1101
 1102
 1103
 1104
 1105
 1106
 1107
 1108
 1109
 1110
 1111
 1112
 1113
 1114
 1115
 1116
 1117
 1118
 1119
 1120
 1121
 1122
 1123
 1124
 1125
 1126
 1127
 1128
 1129
 1130
 1131
 1132
 1133
 1134
 1135
 1136
 1137
 1138
 1139
 1140
 1141
 1142
 1143
 1144
 1145
 1146
 1147
 1148
 1149
 1150
 1151
 1152
 1153
 1154
 1155
 1156
 1157
 1158
 1159
 1160
 1161
 1162
 1163
 1164
 1165
 1166
 1167
 1168
 1169
 1170
 1171
 1172
 1173
 1174
 1175
 1176
 1177
 1178
 1179
 1180
 1181
 1182
 1183
 1184
 1185
 1186
 1187
 1188
 1189
 1190
 1191
 1192
 1193
 1194
 1195
 1196
 1197
 1198
 1199
 1200
 1201
 1202
 1203
 1204
 1205
 1206
 1207
 1208
 1209
 1210
 1211
 1212
 1213
 1214
 1215
 1216
 1217
 1218
 1219
 1220
 1221
 1222
 1223
 1224
 1225
 1226
 1227
 1228
 1229
 1230
 1231
 1232
 1233
 1234
 1235
 1236
 1237
 1238
 1239
 1240
 1241
 1242
 1243
 1244
 1245
 1246
 1247
 1248
 1249
 1250
 1251
 1252
 1253
 1254
 1255
 1256
 1257
 1258
 1259
 1260
 1261
 1262
 1263
 1264
 1265
 1266
 1267
 1268
 1269
 1270
 1271
 1272
 1273
 1274
 1275
 1276
 1277
 1278
 1279
 1280
 1281
 1282
 1283
 1284
 1285
 1286
 1287
 1288
 1289
 1290
 1291
 1292
 1293
 1294
 1295
 1296
 1297
 1298
 1299
 1300
 1301
 1302
 1303
 1304
 1305
 1306
 1307
 1308
 1309
 1310
 1311
 1312
 1313
 1314
 1315
 1316
 1317
 1318
 1319
 1320
 1321
 1322
 1323
 1324
 1325
 1326
 1327
 1328
 1329
 1330
 1331
 1332
 1333
 1334
 1335
 1336
 1337
 1338
 1339
 1340
 1341
 1342
 1343
 1344
 1345
 1346
 1347
 1348
 1349
 1350
 1351
 1352
 1353
 1354
 1355
 1356
 1357
 1358
 1359
 1360
 1361
 1362
 1363
 1364
 1365
 1366
 1367
 1368
 1369
 1370
 1371
 1372
 1373
 1374
 1375
 1376
 1377
 1378
 1379
 1380
 1381
 1382
 1383
 1384
 1385
 1386
 1387
 1388
 1389
 1390
 1391
 1392
 1393
 1394
 1395
 1396
 1397
 1398
 1399
 1400
 1401
 1402
 1403
 1404
 1405
 1406
 1407
 1408
 1409
 1410
 1411
 1412
 1413
 1414
 1415
 1416
 1417
 1418
 1419
 1420
 1421
 1422
 1423
 1424
 1425
 1426
 1427
 1428
 1429
 1430
 1431
 1432
 1433
 1434
 1435
 1436
 1437
 1438
 1439
 1440
 1441
 1442
 1443
 1444
 1445
 1446
 1447
 1448
 1449
 1450
 1451
 1452
 1453
 1454
 1455
 1456
 1457
 1458
 1459
 1460
 1461
 1462
 1463
 1464
 1465
 1466
 1467
 1468
 1469
 1470
 1471
 1472
 1473
 1474
 1475
 1476
 1477
 1478
 1479
 1480
 1481
 1482
 1483
 1484
 1485
 1486
 1487
 1488
 1489
 1490
 1491
 1492
 1493
 1494
 1495
 1496
 1497
 1498
 1499
 1500
 1501
 1502
 1503
 1504
 1505
 1506
 1507
 1508
 1509
 1510
 1511
 1512
 1513
 1514
 1515
 1516
 1517
 1518
 1519
 1520
 1521
 1522
 1523
 1524
 1525
 1526
 1527
 1528
 1529
 1530
 1531
 1532
 1533
 1534
 1535
 1536
 1537
 1538
 1539
 1540
 1541
 1542
 1543
 1544
 1545
 1546
 1547
 1548
 1549
 1550
 1551
 1552
 1553
 1554
 1555
 1556
 1557
 1558
 1559
 1560
 1561
 1562
 1563
 1564
 1565
 1566
 1567
 1568
 1569
 1570
 1571
 1572
 1573
 1574
 1575
 1576
 1577
 1578
 1579
 1580
 1581
 1582
 1583
 1584
 1585
 1586
 1587
 1588
 1589
 1590
 1591
 1592
 1593
 1594
 1595
 1596
 1597
 1598
 1599
 1600
 1601
 1602
 1603
 1604
 1605
 1606
 1607
 1608
 1609
 1610
 1611
 1612
 1613
 1614
 1615
 1616
 1617
 1618
 1619
 1620
 1621
 1622
 1623
 1624
 1625
 1626
 1627
 1628
 1629
 1630
 1631
 1632
 1633
 1634
 1635
 1636
 1637
 1638
 1639
 1640
 1641
 1642
 1643
 1644
 1645
 1646
 1647
 1648
 1649
 1650
 1651
 1652
 1653
 1654
 1655
 1656
 1657
 1658
 1659
 1660
 1661
 1662
 1663
 1664
 1665
 1666
 1667
 1668
 1669
 1670
 1671
 1672
 1673
 1674
 1675
 1676
 1677
 1678
 1679
 1680
 1681
 1682
 1683
 1684
 1685
 1686
 1687
 1688
 1689
 1690
 1691
 1692
 1693
 1694
 1695
 1696
 1697
 1698
 1699
 1700
 1701
 1702
 1703
 1704
 1705
 1706
 1707
 1708
 1709
 1710
 1711
 1712
 1713
 1714
 1715
 1716
 1717
 1718
 1719
 1720
 1721
 1722
 1723
 1724
 1725
 1726
 1727
 1728
 1729
 1730
 1731
 1732
 1733
 1734
 1735
 1736
 1737
 1738
 1739
 1740
 1741
 1742
 1743
 1744
 1745
 1746
 1747
 1748
 1749
 1750
 1751
 1752
 1753
 1754
 1755
 1756
 1757
 1758
 1759
 1760
 1761
 1762
 1763
 1764
 1765
 1766
 1767
 1768
 1769
 1770
 1771
 1772
 1773
 1774
 1775
 1776
 1777
 1778
 1779
 1780
 1781
 1782
 1783
 1784
 1785
 1786
 1787
 1788
 1789
 1790
 1791
 1792
 1793
 1794
 1795
 1796
 1797
 1798
 1799
 1800
 1801
 1802
 1803
 1804
 1805
 1806
 1807
 1808
 1809
 1810
 1811
 1812
 1813
 1814
 1815
 1816
 1817
 1818
 1819
 1820
 1821
 1822
 1823
 1824
 1825
 1826
 1827
 1828
 1829
 1830
 1831
 1832
 1833
 1834
 1835
 1836
 1837
 1838
 1839
 1840
 1841
 1842
 1843
 1844
 1845
 1846
 1847
 1848
 1849
 1850
 1851
 1852
 1853
 1854
 1855
 1856
 1857
 1858
 1859
 1860
 1861
 1862
 1863
 1864
 1865
 1866
 1867
 1868
 1869
 1870
 1871
 1872
 1873
 1874
 1875
 1876
 1877
 1878
 1879
 1880
 1881
 1882
 1883
 1884
 1885
 1886
 1887
 1888
 1889
 1890
 1891
 1892
 1893
 1894
 1895
 1896
 1897
 1898
 1899
 1900
 1901
 1902
 1903
 1904
 1905
 1906
 1907
 1908
 1909
 1910
 1911
 1912
 1913
 1914
 1915
 1916
 1917
 1918
 1919
 1920
 1921
 1922
 1923
 1924
 1925
 1926
 1927
 1928
 1929
 1930
 1931
 1932
 1933
 1934
 1935
 1936
 1937
 1938
 1939
 1940
 1941
 1942
 1943
 1944
 1945
 1946
 1947
 1948
 1949
 1950
 1951
 1952
 1953
 1954
 1955
 1956
 1957
 1958
 1959
 1960
 1961
 1962
 1963
 1964
 1965
 1966
 1967
 1968
 1969
 1970
 1971
 1972
 1973
 1974
 1975
 1976
 1977
 1978
 1979
 1980
 1981
 1982
 1983
 1984
 1985
 1986
 1987
 1988
 1989
 1990
 1991
 1992
 1993
 1994
 1995
 1996
 1997
 1998
 1999
 2000
 2001
 2002
 2003
 2004
 2005
 2006
 2007
 2008
 2009
 2010
 2011
 2012
 2013
 2014
 2015
 2016
 2017
 2018
 2019
 2020
 2021
 2022
 2023
 2024
 2025
 2026
 2027
 2028
 2029
 2030
 2031
 2032
 2033
 2034
 2035
 2036
 2037
 2038
 2039
 2040
 2041
 2042
 2043
 2044
 2045
 2046
 2047
 2048
 2049
 2050
 2051
 2052
 2053
 2054
 2055
 2056
 2057
 2058
 2059
 2060
 2061
 2062
 2063
 2064
 2065
 2066
 2067
 2068
 2069
 2070
 2071
 2072
 2073
 2074
 2075
 2076
 2077
 2078
 2079
 2080
 2081
 2082
 2083
 2084
 2085
 2086
 2087
 2088
 2089
 2090
 2091
 2092
 2093
 2094
 2095
 2096
 2097
 2098
 2099
 2100
 2101
 2102
 2103
 2104
 2105
 2106
 2107
 2108
 2109
 2110
 2111
 2112
 2113
 2114
 2115
 2116
 2117
 2118
 2119
 2120
 2121
 2122
 2123
 2124
 2125
 2126
 2127
 2128
 2129
 2130
 2131
 2132
 2133
 2134
 2135
 2136
 2137
 2138
 2139
 2140
 2141
 2142
 2143
 2144
 2145
 2146
 2147
 2148
 2149
 2150
 2151
 2152
 2153
 2154
 2155
 2156
 2157
 2158
 2159
 2160
 2161
 2162
 2163
 2164
 2165
 2166
 2167
 2168
 2169
 2170
 2171
 2172
 2173
 2174
 2175
 2176
 2177
 2178
 2179
 2180
 2181
 2182
 2183
 2184
 2185
 2186
 2187
 2188
 2189
 2190
 2191
 2192
 2193
 2194
 2195
 2196
 2197
 2198
 2199
 2200
 2201
 2202
 2203
 2204
 2205
 2206
 2207
 2208
 2209
 2210
 2211
 2212
 2213
 2214
 2215
 2216
 2217
 2218
 2219
 2220
 2221
 2222
 2223
 2224
 2225
 2226
 2227
 2228
 2229
 2230
 2231
 2232
 2233
 2234
 2235
 2236
 2237
 2238
 2239
 2240
 2241
 2242
 2243
 2244
 2245
 2246
 2247
 2248
 2249
 2250
 2251
 2252
 2253
 2254
 2255
 2256
 2257
 2258
 2259
 2260
 2261
 2262
 2263
 2264
 2265
 2266
 2267
 2268
 2269
 2270
 2271
 2272
 2273
 2274
 2275
 2276
 2277
 2278
 2279
 2280
 2281
 2282
 2283
 2284
 2285
 2286
 2287
 2288
 2289
 2290
 2291
 2292
 2293
 2294
 2295
 2296
 2297
 2298
 2299
 2300
 2301
 2302
 2303
 2304
 2305
 2306
 2307
 2308
 2309
 2310
 2311
 2312
 2313
 2314
 2315
 2316
 2317
 2318
 2319
 2320
 2321
 2322
 2323
 2324
 2325
 2326
 2327
 2328
 2329
 2330
 2331
 2332
 2333
 2334
 2335
 2336
 2337
 2338
 2339
 2340
 2341
 2342
 2343
 2344
 2345
 2346
 2347
 2348
 2349
 2350
 2351
 2352
 2353
 2354
 2355
 2356
 2357
 2358
 2359
 2360
 2361
 2362
 2363
 2364
 2365
 2366
 2367
 2368
 2369
 2370
 2371
 2372
 2373
 2374
 2375
 2376
 2377
 2378
 2379
 2380
 2381
 2382
 2383
 2384
 2385
 2386
 2387
 2388
 2389
 2390
 2391
 2392
 2393
 2394
 2395
 2396
 2397
 2398
 2399
 2400
 2401
 2402
 2403
 2404
 2405
 2406
 2407
 2408
 2409
 2410
 2411
 2412
 2413
 2414
 2415
 2416
 2417
 2418
 2419
 2420
 2421
 2422
 2423
 2424
 2425
 2426
 2427
 2428
 2429
 2430
 2431
 2432
 2433
 2434
 2435
 2436
 2437
 2438
 2439
 2440
 2441
 2442
 2443
 2444
 2445
 2446
 2447
 2448
 2449
 2450
 2451
 2452
 2453
 2454
 2455
 2456
 2457
 2458
 2459
 2460
 2461
 2462
 2463
 2464
 2465
 2466
 2467
 2468
 2469
 2470
 2471
 2472
 2473
 2474
 2475
 2476
 2477
 2478
 2479
 2480
 2481
 2482
 2483
 2484
 2485
 2486
 2487
 2488
 2489
 2490
 2491
 2492
 2493
 2494
 2495
 2496
 2497
 2498
 2499
 2500
 2501
 2502
 2503
 2504
 2505
 2506
 2507
 2508
 2509
 2510
 2511
 2512
 2513
 2514
 2515
 2516
 2517
 2518
 2519
 2520
 2521
 2522
 2523
 2524
 2525
 2526
 2527
 2528
 2529
 2530
 2531
 2532
 2533
 2534
 2535
 2536
 2537
 2538
 2539
 2540
 2541
 2542
 2543
 2544
 2545
 2546
 2547
 2548
 2549
 2550
 2551
 2552
 2553
 2554
 2555
 2556
 2557
 2558
 2559
 2560
 2561
 2562
 2563
 2564
 2565
 2566
 2567
 2568
 2569
 2570
 2571
 2572
 2573
 2574
 2575
 2576
 2577
 2578
 2579
 2580
 2581
 2582
 2583
 2584
 2585
 2586
 2587
 2588
 2589
 2590
 2591
 2592
 2593
 2594
 2595
 2596
 2597
 2598
 2599
 2600
 2601
 2602
 2603
 2604
 2605
 2606
 2607
 2608
 2609
 2610
 2611
 2612
 2613
 2614
 2615
 2616
 2617
 2618
 2619
 2620
 2621
 2622
 2623
 2624
 2625
 2626
 2627
 2628
 2629
 2630
 2631
 2632
 2633
 2634
 2635
 2636
 2637
 2638
 2639
 2640
 2641
 2642
 2643
 2644
 2645
 2646
 2647
 2648
 2649
 2650
 2651
 2652
 2653
 2654
 2655
 2656
 2657
 2658
 2659
 2660
 2661
 2662
 2663
 2664
 2665
 2666
 2667
 2668
 2669
 2670
 2671
 2672
 2673
 2674
 2675
 2676
 2677
 2678
 2679
 2680
 2681
 2682
 2683
 2684
 2685
 2686
 2687
 2688
 2689
 2690
 2691
 2692
 2693
 2694
 2695
 2696
 2697
 2698
 2699
 2700
 2701
 2702
 2703
 2704
 2705
 2706
 2707
 2708
 2709
 2710
 2711
 2712
 2713
 2714
 2715
 2716
 2717
 2718
 2719
 2720
 2721
 2722
 2723
 2724
 2725
 2726
 2727
 2728
 2729
 2730
 2731
 2732
 2733
 2734
 2735
 2736
 2737
 2738
 2739
 2740
 2741
 2742
 2743
 2744
 2745
 2746
 2747
 2748
 2749
 2750
 2751
 2752
 2753
 2754
 2755
 2756
 2757
 2758
 2759
 2760
 2761
 2762
 2763
 2764
 2765
 2766
 2767
 2768
 2769
 2770
 2771
 2772
 2773
 2774
 2775
 2776
 2777
 2778
 2779
 2780
 2781
 2782
 2783
 2784
 2785
 2786
 2787
 2788
 2789
 2790
 2791
 2792
 2793
 2794
 2795
 2796
 2797
 2798
 2799
 2800
 2801
 2802
 2803
 2804
 2805
 2806
 2807
 2808
 2809
 2810
 2811
 2812
 2813
 2814
 2815
 2816
 2817
 2818
 2819
 2820
 2821
 2822
 2823
 2824
 2825
 2826
 2827
 2828
 2829
 2830
 2831
 2832
 2833
 2834
 2835
 2836
 2837
 2838
 2839
 2840
 2841
 2842
 2843
 2844
 2845
 2846
 2847
 2848
 2849
 2850
 2851
 2852
 2853
 2854
 2855
 2856
 2857
 2858
 2859
 2860
 2861
 2862
 2863
 2864
 2865
 2866
 2867
 2868
 2869
 2870
 2871
 2872
 2873
 2874
 2875
 2876
 2877
 2878
 2879
 2880
 2881
 2882
 2883
 2884
 2885
 2886
 2887
 2888
 2889
 2890
 2891
 2892
 2893
 2894
 2895
 2896
 2897
 2898
 2899
 2900
 2901
 2902
 2903
 2904
 2905
 2906
 2907
 2908
 2909
 2910
 2911
 2912
 2913
 2914
 2915
 2916
 2917
 2918
 2919
 2920
 2921
 2922
 2923
 2924
 2925
 2926
 2927
 2928
 2929
 2930
 2931
 2932
 2933
 2934
 2935
 2936
 2937
 2938
 2939
 2940
 2941
 2942
 2943
 2944
 2945
 2946
 2947
 2948
 2949
 2950
 2951
 2952
 2953
 2954
 2955
 2956
 2957
 2958
 2959
 2960
 2961
 2962
 2963
 2964
 2965
 2966
 2967
 2968
 2969
 2970
 2971
 2972
 2973
 2974
 2975
 2976
 2977
 2978
 2979
 2980
 2981
 2982
 2983
 2984
 2985
 2986
 2987
 2988
 2989
 2990
 2991
 2992
 2993
 2994
 2995
 2996
 2997
 2998
 2999
 3000
 3001
 3002
 3003
 3004
 3005
 3006
 3007
 3008
 3009
 3010
 3011
 3012
 3013
 3014
 3015
 3016
 3017
 3018
 3019
 3020
 3021
 3022
 3023
 3024
 3025
 3026
 3027
 3028
 3029
 3030
 3031
 3032
 3033
 3034
 3035
 3036
 3037
 3038
 3039
 3040
 3041
 3042
 3043
 3044
 3045
 3046
 3047
 3048
 3049
 3050
 3051
 3052
 3053
 3054
 3055
 3056
 3057
 3058
 3059
 3060
 3061
 3062
 3063
 3064
 3065
 3066
 3067
 3068
 3069
 3070
 3071
 3072
 3073
 3074
 3075
 3076
 3077
 3078
 3079
 3080
 3081
 3082
 3083
 3084
 3085
 3086
 3087
 3088
 3089
 3090
 3091
 3092
 3093
 3094
 3095
 3096
 3097
 3098
 3099
 3100
 3101
 3102
 3103
 3104
 3105
 3106
 3107
 3108
 3109
 3110
 3111
 3112
 3113
 3114
 3115
 3116
 3117
 3118
 3119
 3120
 3121
 3122
 3123
 3124
 3125
 3126
 3127
 3128
 3129
 3130
 3131
 3132
 3133
 3134
 3135
 3136
 3137
 3138
 3139
 3140
 3141
 3142
 3143
 3144
 3145
 3146
 3147
 3148
 3149
 3150
 3151
 3152
 3153
 3154
 3155
 3156
 3157
 3158
 3159
 3160
 3161
 3162
 3163
 3164
 3165
 3166
 3167
 3168
 3169
 3170
 3171
 3172
 3173
 3174
 3175
 3176
 3177
 3178
 3179
 3180
 3181
 3182
 3183
 3184
 3185
 3186
 3187
 3188
 3189
 3190
 3191
 3192
 3193
 3194
 3195
 3196
 3197
 3198
 3199
 3200
 3201
 3202
 3203
 3204
 3205
 3206
 3207
 3208
 3209
 3210
 3211
 3212
 3213
 3214
 3215
 3216
 3217
 3218
 3219
 3220
 3221
 3222
 3223
 3224
 3225
 3226
 3227
 3228
 3229
 3230
 3231
 3232
 3233
 3234
 3235
 3236
 3237
 3238
 3239
 3240
 3241
 3242
 3243
 3244
 3245
 3246
 3247
 3248
 3249
 3250
 3251
 3252
 3253
 3254
 3255
 3256
 3257
 3258
 3259
 3260
 3261
 3262
 3263
 3264
 3265
 3266
 3267
 3268
 3269
 3270
 3271
 3272
 3273
 3274
 3275
 3276
 3277
 3278
 3279
 3280
 3281
 3282
 3283
 3284
 3285
 3286
 3287
 3288
 3289
 3290
 3291
 3292
 3293
 3294
 3295
 3296
 3297
 3298
 3299
 3300
 3301
 3302
 3303
 3304
 3305
 3306
 3307
 3308
 3309
 3310
 3311
 3312
 3313
 3314
 3315
 3316
 3317
 3318
 3319
 3320
 3321
 3322
 3323
 3324
 3325
 3326
 3327
 3328
 3329
 3330
 3331
 3332
 3333
 3334
 3335
 3336
 3337
 3338
 3339
 3340
 3341
 3342
 3343
 3344
 3345
 3346
 3347
 3348
 3349
 3350
 3351
 3352
 3353
 3354
 3355
 3356
 3357
 3358
 3359
 3360
 3361
 3362
 3363
 3364
 3365
 3366
 3367
 3368
 3369
 3370
 3371
 3372
 3373
 3374
 3375
 3376
 3377
 3378
 3379
 3380
 3381
 3382
 3383
 3384
 3385
 3386
 3387
 3388
 3389
 3390
 3391
 3392
 3393
 3394
 3395
 3396
 3397
 3398
 3399
 3400
 3401
 3402
 3403
 3404
 3405
 3406
 3407
 3408
 3409
 3410
 3411
 3412
 3413
 3414
 3415
 3416
 3417
 3418
 3419
 3420
 3421
 3422
 3423
 3424
 3425
 3426
 3427
 3428
 3429
 3430
 3431
 3432
 3433
 3434
 3435
 3436
 3437
 3438
 3439
 3440
 3441
 3442
 3443
 3444
 3445
 3446
 3447
 3448
 3449
 3450
 3451
 3452
 3453
 3454
 3455
 3456
 3457
 3458
 3459
 3460
 3461
 3462
 3463
 3464
 3465
 3466
 3467
 3468
 3469
 3470
 3471
 3472
 3473
 3474
 3475
 3476
 3477
 3478
 3479
 3480
 3481
 3482
 3483
 3484
 3485
 3486
 3487
 3488
 3489
 3490
 3491
 3492
 3493
 3494
 3495
 3496
 3497
 3498
 3499
 3500
 3501
 3502
 3503
 3504
 3505
 3506
 3507
 3508
 3509
 3510
 3511
 3512
 3513
 3514
 3515
 3516
 3517
 3518
 3519
 3520
 3521
 3522
 3523
 3524
 3525
 3526
 3527
 3528
 3529
 3530
 3531
 3532
 3533
 3534
 3535
 3536
 3537
 3538
 3539
 3540
 3541
 3542
 3543
 3544
 3545
 3546
 3547
 3548
 3549
 3550
 3551
 3552
 3553
 3554
 3555
 3556
 3557
 3558
 3559
 3560
 3561
 3562
 3563
 3564
 3565
 3566
 3567
 3568
 3569
 3570
 3571
 3572
 3573
 3574
 3575
 3576
 3577
 3578
 3579
 3580
 3581
 3582
 3583
 3584
 3585
 3586
 3587
 3588
 3589
 3590
 3591
 3592
 3593
 3594
 3595
 3596
 3597
 3598
 3599
 3600
 3601
 3602
 3603
 3604
 3605
 3606
 3607
 3608
 3609
 3610
 3611
 3612
 3613
 3614
 3615
 3616
 3617
 3618
 3619
 3620
 3621
 3622
 3623
 3624
 3625
 3626
 3627
 3628
 3629
 3630
 3631
 3632
 3633
 3634
 3635
 3636
 3637
 3638
 3639
 3640
 3641
 3642
 3643
 3644
 3645
 3646
 3647
 3648
 3649
 3650
 3651
 3652
 3653
 3654
 3655
 3656
 3657
 3658
 3659
 3660
 3661
 3662
 3663
 3664
 3665
 3666
 3667
 
 | import { connect } from 'cloudflare:sockets';
 
 
 let userID = '';
 
 let proxyIP = '';
 
 let sub = '';
 
 let subConverter = 'SUBAPI.fxxk.dedyn.io';
 
 let subConfig = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini";
 
 let subProtocol = 'https';
 
 let subEmoji = 'true';
 
 let socks5Address = '';
 
 let parsedSocks5Address = {};
 
 let enableSocks = false;
 
 
 
 let fakeUserID ;
 
 let fakeHostName ;
 
 let noTLS = 'false';
 
 const expire = 4102329600;//2099-12-31
 
 let proxyIPs;
 
 let socks5s;
 
 let go2Socks5s = [
 
 '*ttvnw.net',
 
 '*tapecontent.net',
 
 '*cloudatacdn.com',
 
 '*.loadshare.org',
 
 ];
 
 let addresses = [];
 
 let addressesapi = [];
 
 let addressesnotls = [];
 
 let addressesnotlsapi = [];
 
 let addressescsv = [];
 
 let DLS = 8;
 
 let remarkIndex = 1;//CSV备注所在列偏移量
 
 let FileName = atob('ZWRnZXR1bm5lbA==');
 
 let BotToken;
 
 let ChatID;
 
 let proxyhosts = [];
 
 let proxyhostsURL = '';
 
 let RproxyIP = 'false';
 
 let httpsPorts = ["2053","2083","2087","2096","8443"];
 
 let 有效时间 = 7;
 
 let 更新时间 = 3;
 
 let userIDLow;
 
 let userIDTime = "";
 
 let proxyIPPool = [];
 
 let path = '/?ed=2560';
 
 let 动态UUID;
 
 export default {
 
 async fetch(request, env, ctx) {
 
 try {
 
 const UA = request.headers.get('User-Agent') || 'null';
 
 const userAgent = UA.toLowerCase();
 
 userID = env.UUID || env.uuid || env.PASSWORD || env.pswd || userID;
 
 if (env.KEY || env.TOKEN || (userID && !isValidUUID(userID))) {
 
 动态UUID = env.KEY || env.TOKEN || userID;
 
 有效时间 = Number(env.TIME) || 有效时间;
 
 更新时间 = Number(env.UPTIME) || 更新时间;
 
 const userIDs = await 生成动态UUID(动态UUID);
 
 userID = userIDs[0];
 
 userIDLow = userIDs[1];
 
 }
 
 
 
 if (!userID) {
 
 return new Response('请设置你的UUID变量,或尝试重试部署,检查变量是否生效?', {
 
 status: 404,
 
 headers: {
 
 "Content-Type": "text/plain;charset=utf-8",
 
 }
 
 });
 
 }
 
 const currentDate = new Date();
 
 currentDate.setHours(0, 0, 0, 0);
 
 const timestamp = Math.ceil(currentDate.getTime() / 1000);
 
 const fakeUserIDMD5 = await 双重哈希(`${userID}${timestamp}`);
 
 fakeUserID = [
 
 fakeUserIDMD5.slice(0, 8),
 
 fakeUserIDMD5.slice(8, 12),
 
 fakeUserIDMD5.slice(12, 16),
 
 fakeUserIDMD5.slice(16, 20),
 
 fakeUserIDMD5.slice(20)
 
 ].join('-');
 
 
 
 fakeHostName = `${fakeUserIDMD5.slice(6, 9)}.${fakeUserIDMD5.slice(13, 19)}`;
 
 
 
 proxyIP = env.PROXYIP || env.proxyip || proxyIP;
 
 proxyIPs = await 整理(proxyIP);
 
 proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)];
 
 
 
 socks5Address = env.SOCKS5 || socks5Address;
 
 socks5s = await 整理(socks5Address);
 
 socks5Address = socks5s[Math.floor(Math.random() * socks5s.length)];
 
 socks5Address = socks5Address.split('//')[1] || socks5Address;
 
 if (env.GO2SOCKS5) go2Socks5s = await 整理(env.GO2SOCKS5);
 
 if (env.CFPORTS) httpsPorts = await 整理(env.CFPORTS);
 
 
 
 if (socks5Address) {
 
 try {
 
 parsedSocks5Address = socks5AddressParser(socks5Address);
 
 RproxyIP = env.RPROXYIP || 'false';
 
 enableSocks = true;
 
 } catch (err) {
 
 let e = err;
 
 console.log(e.toString());
 
 RproxyIP = env.RPROXYIP || !proxyIP ? 'true' : 'false';
 
 enableSocks = false;
 
 }
 
 } else {
 
 RproxyIP = env.RPROXYIP || !proxyIP ? 'true' : 'false';
 
 }
 
 
 
 const upgradeHeader = request.headers.get('Upgrade');
 
 const url = new URL(request.url);
 
 if (!upgradeHeader || upgradeHeader !== 'websocket') {
 
 if (env.ADD) addresses = await 整理(env.ADD);
 
 if (env.ADDAPI) addressesapi = await 整理(env.ADDAPI);
 
 if (env.ADDNOTLS) addressesnotls = await 整理(env.ADDNOTLS);
 
 if (env.ADDNOTLSAPI) addressesnotlsapi = await 整理(env.ADDNOTLSAPI);
 
 if (env.ADDCSV) addressescsv = await 整理(env.ADDCSV);
 
 DLS = Number(env.DLS) || DLS;
 
 remarkIndex = Number(env.CSVREMARK) || remarkIndex;
 
 BotToken = env.TGTOKEN || BotToken;
 
 ChatID = env.TGID || ChatID;
 
 FileName = env.SUBNAME || FileName;
 
 subEmoji = env.SUBEMOJI || env.EMOJI || subEmoji;
 
 if (subEmoji == '0') subEmoji = 'false';
 
 
 
 sub = env.SUB || sub;
 
 subConverter = env.SUBAPI || subConverter;
 
 if (subConverter.includes("http://") ){
 
 subConverter = subConverter.split("//")[1];
 
 subProtocol = 'http';
 
 } else {
 
 subConverter = subConverter.split("//")[1] || subConverter;
 
 }
 
 subConfig = env.SUBCONFIG || subConfig;
 
 if (url.searchParams.has('sub') && url.searchParams.get('sub') !== '') sub = url.searchParams.get('sub');
 
 if (url.searchParams.has('notls')) noTLS = 'true';
 
 
 
 if (url.searchParams.has('proxyip')) {
 
 path = `/?ed=2560&proxyip=${url.searchParams.get('proxyip')}`;
 
 RproxyIP = 'false';
 
 } else if (url.searchParams.has('socks5')) {
 
 path = `/?ed=2560&socks5=${url.searchParams.get('socks5')}`;
 
 RproxyIP = 'false';
 
 } else if (url.searchParams.has('socks')) {
 
 path = `/?ed=2560&socks5=${url.searchParams.get('socks')}`;
 
 RproxyIP = 'false';
 
 }
 
 
 
 const 路径 = url.pathname.toLowerCase();
 
 if (路径 == '/') {
 
 if (env.URL302) return Response.redirect(env.URL302, 302);
 
 else if (env.URL) return await 代理URL(env.URL, url);
 
 else return new Response(JSON.stringify(request.cf, null, 4), {
 
 status: 200,
 
 headers: {
 
 'content-type': 'application/json',
 
 },
 
 });
 
 } else if (路径 == `/${fakeUserID}`) {
 
 const fakeConfig = await 生成配置信息(userID, request.headers.get('Host'), sub, 'CF-Workers-SUB', RproxyIP, url, env);
 
 return new Response(`${fakeConfig}`, { status: 200 });
 
 } else if (路径 == `/${动态UUID}` || 路径 == `/${userID}`) {
 
 await sendMessage(`#获取订阅 ${FileName}`, request.headers.get('CF-Connecting-IP'), `UA: ${UA}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
 
 const 维列斯Config = await 生成配置信息(userID, request.headers.get('Host'), sub, UA, RproxyIP, url, env);
 
 const now = Date.now();
 
 //const timestamp = Math.floor(now / 1000);
 
 const today = new Date(now);
 
 today.setHours(0, 0, 0, 0);
 
 const UD = Math.floor(((now - today.getTime())/86400000) * 24 * 1099511627776 / 2);
 
 let pagesSum = UD;
 
 let workersSum = UD;
 
 let total = 24 * 1099511627776 ;
 
 
 
 if (userAgent && userAgent.includes('mozilla')){
 
 return new Response(`${维列斯Config}`, {
 
 status: 200,
 
 headers: {
 
 "Content-Type": "text/plain;charset=utf-8",
 
 "Profile-Update-Interval": "6",
 
 "Subscription-Userinfo": `upload=${pagesSum}; download=${workersSum}; total=${total}; expire=${expire}`,
 
 }
 
 });
 
 } else {
 
 return new Response(`${维列斯Config}`, {
 
 status: 200,
 
 headers: {
 
 "Content-Disposition": `attachment; filename=${FileName}; filename*=utf-8''${encodeURIComponent(FileName)}`,
 
 "Content-Type": "text/plain;charset=utf-8",
 
 "Profile-Update-Interval": "6",
 
 "Subscription-Userinfo": `upload=${pagesSum}; download=${workersSum}; total=${total}; expire=${expire}`,
 
 }
 
 });
 
 }
 
 } else {
 
 if (env.URL302) return Response.redirect(env.URL302, 302);
 
 else if (env.URL) return await 代理URL(env.URL, url);
 
 else return new Response(``, { status: 404 });
 
 }
 
 } else {
 
 socks5Address = url.searchParams.get('socks5') || socks5Address;
 
 if (new RegExp('/socks5=', 'i').test(url.pathname)) socks5Address = url.pathname.split('5=')[1];
 
 else if (new RegExp('/socks://', 'i').test(url.pathname) || new RegExp('/socks5://', 'i').test(url.pathname)) {
 
 socks5Address = url.pathname.split('://')[1].split('#')[0];
 
 if (socks5Address.includes('@')){
 
 let userPassword = socks5Address.split('@')[0];
 
 const base64Regex = /^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=)?$/i;
 
 if (base64Regex.test(userPassword) && !userPassword.includes(':')) userPassword = atob(userPassword);
 
 socks5Address = `${userPassword}@${socks5Address.split('@')[1]}`;
 
 }
 
 }
 
 
 
 if (socks5Address) {
 
 try {
 
 parsedSocks5Address = socks5AddressParser(socks5Address);
 
 enableSocks = true;
 
 } catch (err) {
 
 let e = err;
 
 console.log(e.toString());
 
 enableSocks = false;
 
 }
 
 } else {
 
 enableSocks = false;
 
 }
 
 
 
 if (url.searchParams.has('proxyip')){
 
 proxyIP = url.searchParams.get('proxyip');
 
 enableSocks = false;
 
 } else if (new RegExp('/proxyip=', 'i').test(url.pathname)) {
 
 proxyIP = url.pathname.toLowerCase().split('/proxyip=')[1];
 
 enableSocks = false;
 
 } else if (new RegExp('/proxyip.', 'i').test(url.pathname)) {
 
 proxyIP = `proxyip.${url.pathname.toLowerCase().split("/proxyip.")[1]}`;
 
 enableSocks = false;
 
 }
 
 
 
 return await 维列斯OverWSHandler(request);
 
 }
 
 } catch (err) {
 
 let e = err;
 
 return new Response(e.toString());
 
 }
 
 },
 
 };
 
 
 
 async function 维列斯OverWSHandler(request) {
 
 
 
 // @ts-ignore
 
 const webSocketPair = new WebSocketPair();
 
 const [client, webSocket] = Object.values(webSocketPair);
 
 
 
 // 接受 WebSocket 连接
 
 webSocket.accept();
 
 
 
 let address = '';
 
 let portWithRandomLog = '';
 
 // 日志函数,用于记录连接信息
 
 const log = (/** @type {string} */ info, /** @type {string | undefined} */ event) => {
 
 console.log(`[${address}:${portWithRandomLog}] ${info}`, event || '');
 
 };
 
 // 获取早期数据头部,可能包含了一些初始化数据
 
 const earlyDataHeader = request.headers.get('sec-websocket-protocol') || '';
 
 
 
 // 创建一个可读的 WebSocket 流,用于接收客户端数据
 
 const readableWebSocketStream = makeReadableWebSocketStream(webSocket, earlyDataHeader, log);
 
 
 
 // 用于存储远程 Socket 的包装器
 
 let remoteSocketWapper = {
 
 value: null,
 
 };
 
 // 标记是否为 DNS 查询
 
 let isDns = false;
 
 
 
 // WebSocket 数据流向远程服务器的管道
 
 readableWebSocketStream.pipeTo(new WritableStream({
 
 async write(chunk, controller) {
 
 if (isDns) {
 
 // 如果是 DNS 查询,调用 DNS 处理函数
 
 return await handleDNSQuery(chunk, webSocket, null, log);
 
 }
 
 if (remoteSocketWapper.value) {
 
 // 如果已有远程 Socket,直接写入数据
 
 const writer = remoteSocketWapper.value.writable.getWriter()
 
 await writer.write(chunk);
 
 writer.releaseLock();
 
 return;
 
 }
 
 
 
 // 处理 维列斯 协议头部
 
 const {
 
 hasError,
 
 message,
 
 addressType,
 
 portRemote = 443,
 
 addressRemote = '',
 
 rawDataIndex,
 
 维列斯Version = new Uint8Array([0, 0]),
 
 isUDP,
 
 } = process维列斯Header(chunk, userID);
 
 // 设置地址和端口信息,用于日志
 
 address = addressRemote;
 
 portWithRandomLog = `${portRemote}--${Math.random()} ${isUDP ? 'udp ' : 'tcp '} `;
 
 if (hasError) {
 
 // 如果有错误,抛出异常
 
 throw new Error(message);
 
 return;
 
 }
 
 // 如果是 UDP 且端口不是 DNS 端口(53),则关闭连接
 
 if (isUDP) {
 
 if (portRemote === 53) {
 
 isDns = true;
 
 } else {
 
 throw new Error('UDP 代理仅对 DNS(53 端口)启用');
 
 return;
 
 }
 
 }
 
 // 构建 维列斯 响应头部
 
 const 维列斯ResponseHeader = new Uint8Array([维列斯Version[0], 0]);
 
 // 获取实际的客户端数据
 
 const rawClientData = chunk.slice(rawDataIndex);
 
 
 
 if (isDns) {
 
 // 如果是 DNS 查询,调用 DNS 处理函数
 
 return handleDNSQuery(rawClientData, webSocket, 维列斯ResponseHeader, log);
 
 }
 
 // 处理 TCP 出站连接
 
 log(`处理 TCP 出站连接 ${addressRemote}:${portRemote}`);
 
 handleTCPOutBound(remoteSocketWapper, addressType, addressRemote, portRemote, rawClientData, webSocket, 维列斯ResponseHeader, log);
 
 },
 
 close() {
 
 log(`readableWebSocketStream 已关闭`);
 
 },
 
 abort(reason) {
 
 log(`readableWebSocketStream 已中止`, JSON.stringify(reason));
 
 },
 
 })).catch((err) => {
 
 log('readableWebSocketStream 管道错误', err);
 
 });
 
 
 
 // 返回一个 WebSocket 升级的响应
 
 return new Response(null, {
 
 status: 101,
 
 // @ts-ignore
 
 webSocket: client,
 
 });
 
 }
 
 
 
 async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portRemote, rawClientData, webSocket, 维列斯ResponseHeader, log,) {
 
 async function useSocks5Pattern(address) {
 
 if ( go2Socks5s.includes(atob('YWxsIGlu')) || go2Socks5s.includes(atob('Kg==')) ) return true;
 
 return go2Socks5s.some(pattern => {
 
 let regexPattern = pattern.replace(/\*/g, '.*');
 
 let regex = new RegExp(`^${regexPattern}$`, 'i');
 
 return regex.test(address);
 
 });
 
 }
 
 
 
 async function connectAndWrite(address, port, socks = false) {
 
 log(`connected to ${address}:${port}`);
 
 //if (/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(address)) address = `${atob('d3d3Lg==')}${address}${atob('LmlwLjA5MDIyNy54eXo=')}`;
 
 // 如果指定使用 SOCKS5 代理,则通过 SOCKS5 协议连接;否则直接连接
 
 const tcpSocket = socks ? await socks5Connect(addressType, address, port, log)
 
 : connect({
 
 hostname: address,
 
 port: port,
 
 });
 
 remoteSocket.value = tcpSocket;
 
 //log(`connected to ${address}:${port}`);
 
 const writer = tcpSocket.writable.getWriter();
 
 // 首次写入,通常是 TLS 客户端 Hello 消息
 
 await writer.write(rawClientData);
 
 writer.releaseLock();
 
 return tcpSocket;
 
 }
 
 
 
 /**
 
 * 重试函数:当 Cloudflare 的 TCP Socket 没有传入数据时,我们尝试重定向 IP
 
 * 这可能是因为某些网络问题导致的连接失败
 
 */
 
 async function retry() {
 
 if (enableSocks) {
 
 // 如果启用了 SOCKS5,通过 SOCKS5 代理重试连接
 
 tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
 
 } else {
 
 // 否则,尝试使用预设的代理 IP(如果有)或原始地址重试连接
 
 if (!proxyIP || proxyIP == '') {
 
 proxyIP = atob(`UFJPWFlJUC50cDEuZnh4ay5kZWR5bi5pbw==`);
 
 } else if (proxyIP.includes(']:')) {
 
 portRemote = proxyIP.split(']:')[1] || portRemote;
 
 proxyIP = proxyIP.split(']:')[0] || proxyIP;
 
 } else if (proxyIP.split(':').length === 2) {
 
 portRemote = proxyIP.split(':')[1] || portRemote;
 
 proxyIP = proxyIP.split(':')[0] || proxyIP;
 
 }
 
 if (proxyIP.includes('.tp')) portRemote = proxyIP.split('.tp')[1].split('.')[0] || portRemote;
 
 tcpSocket = await connectAndWrite(proxyIP || addressRemote, portRemote);
 
 }
 
 // 无论重试是否成功,都要关闭 WebSocket(可能是为了重新建立连接)
 
 tcpSocket.closed.catch(error => {
 
 console.log('retry tcpSocket closed error', error);
 
 }).finally(() => {
 
 safeCloseWebSocket(webSocket);
 
 })
 
 // 建立从远程 Socket 到 WebSocket 的数据流
 
 remoteSocketToWS(tcpSocket, webSocket, 维列斯ResponseHeader, null, log);
 
 }
 
 
 
 let useSocks = false;
 
 if (go2Socks5s.length > 0 && enableSocks ) useSocks = await useSocks5Pattern(addressRemote);
 
 // 首次尝试连接远程服务器
 
 let tcpSocket = await connectAndWrite(addressRemote, portRemote, useSocks);
 
 
 
 // 当远程 Socket 就绪时,将其传递给 WebSocket
 
 // 建立从远程服务器到 WebSocket 的数据流,用于将远程服务器的响应发送回客户端
 
 // 如果连接失败或无数据,retry 函数将被调用进行重试
 
 remoteSocketToWS(tcpSocket, webSocket, 维列斯ResponseHeader, retry, log);
 
 }
 
 
 
 function makeReadableWebSocketStream(webSocketServer, earlyDataHeader, log) {
 
 // 标记可读流是否已被取消
 
 let readableStreamCancel = false;
 
 
 
 // 创建一个新的可读流
 
 const stream = new ReadableStream({
 
 // 当流开始时的初始化函数
 
 start(controller) {
 
 // 监听 WebSocket 的消息事件
 
 webSocketServer.addEventListener('message', (event) => {
 
 // 如果流已被取消,不再处理新消息
 
 if (readableStreamCancel) {
 
 return;
 
 }
 
 const message = event.data;
 
 // 将消息加入流的队列中
 
 controller.enqueue(message);
 
 });
 
 
 
 // 监听 WebSocket 的关闭事件
 
 // 注意:这个事件意味着客户端关闭了客户端 -> 服务器的流
 
 // 但是,服务器 -> 客户端的流仍然打开,直到在服务器端调用 close()
 
 // WebSocket 协议要求在每个方向上都要发送单独的关闭消息,以完全关闭 Socket
 
 webSocketServer.addEventListener('close', () => {
 
 // 客户端发送了关闭信号,需要关闭服务器端
 
 safeCloseWebSocket(webSocketServer);
 
 // 如果流未被取消,则关闭控制器
 
 if (readableStreamCancel) {
 
 return;
 
 }
 
 controller.close();
 
 });
 
 
 
 // 监听 WebSocket 的错误事件
 
 webSocketServer.addEventListener('error', (err) => {
 
 log('WebSocket 服务器发生错误');
 
 // 将错误传递给控制器
 
 controller.error(err);
 
 });
 
 
 
 // 处理 WebSocket 0-RTT(零往返时间)的早期数据
 
 // 0-RTT 允许在完全建立连接之前发送数据,提高了效率
 
 const { earlyData, error } = base64ToArrayBuffer(earlyDataHeader);
 
 if (error) {
 
 // 如果解码早期数据时出错,将错误传递给控制器
 
 controller.error(error);
 
 } else if (earlyData) {
 
 // 如果有早期数据,将其加入流的队列中
 
 controller.enqueue(earlyData);
 
 }
 
 },
 
 
 
 // 当使用者从流中拉取数据时调用
 
 pull(controller) {
 
 // 这里可以实现反压机制
 
 // 如果 WebSocket 可以在流满时停止读取,我们就可以实现反压
 
 // 参考:https://streams.spec.whatwg.org/#example-rs-push-backpressure
 
 },
 
 
 
 // 当流被取消时调用
 
 cancel(reason) {
 
 // 流被取消的几种情况:
 
 // 1. 当管道的 WritableStream 有错误时,这个取消函数会被调用,所以在这里处理 WebSocket 服务器的关闭
 
 // 2. 如果 ReadableStream 被取消,所有 controller.close/enqueue 都需要跳过
 
 // 3. 但是经过测试,即使 ReadableStream 被取消,controller.error 仍然有效
 
 if (readableStreamCancel) {
 
 return;
 
 }
 
 log(`可读流被取消,原因是 ${reason}`);
 
 readableStreamCancel = true;
 
 // 安全地关闭 WebSocket
 
 safeCloseWebSocket(webSocketServer);
 
 }
 
 });
 
 
 
 return stream;
 
 }
 
 
 
 // https://xtls.github.io/development/protocols/维列斯.html
 
 // https://github.com/zizifn/excalidraw-backup/blob/main/v2ray-protocol.excalidraw
 
 
 
 /**
 
 * 解析 维列斯 协议的头部数据
 
 * @param { ArrayBuffer} 维列斯Buffer 维列斯 协议的原始头部数据
 
 * @param {string} userID 用于验证的用户 ID
 
 * @returns {Object} 解析结果,包括是否有错误、错误信息、远程地址信息等
 
 */
 
 function process维列斯Header(维列斯Buffer, userID) {
 
 // 检查数据长度是否足够(至少需要 24 字节)
 
 if (维列斯Buffer.byteLength < 24) {
 
 return {
 
 hasError: true,
 
 message: 'invalid data',
 
 };
 
 }
 
 
 
 // 解析 维列斯 协议版本(第一个字节)
 
 const version = new Uint8Array(维列斯Buffer.slice(0, 1));
 
 
 
 let isValidUser = false;
 
 let isUDP = false;
 
 
 
 // 验证用户 ID(接下来的 16 个字节)
 
 function isUserIDValid(userID, userIDLow, buffer) {
 
 const userIDArray = new Uint8Array(buffer.slice(1, 17));
 
 const userIDString = stringify(userIDArray);
 
 return userIDString === userID || userIDString === userIDLow;
 
 }
 
 
 
 // 使用函数验证
 
 isValidUser = isUserIDValid(userID, userIDLow, 维列斯Buffer);
 
 
 
 // 如果用户 ID 无效,返回错误
 
 if (!isValidUser) {
 
 return {
 
 hasError: true,
 
 message: `invalid user ${(new Uint8Array(维列斯Buffer.slice(1, 17)))}`,
 
 };
 
 }
 
 
 
 // 获取附加选项的长度(第 17 个字节)
 
 const optLength = new Uint8Array(维列斯Buffer.slice(17, 18))[0];
 
 // 暂时跳过附加选项
 
 
 
 // 解析命令(紧跟在选项之后的 1 个字节)
 
 // 0x01: TCP, 0x02: UDP, 0x03: MUX(多路复用)
 
 const command = new Uint8Array(
 
 维列斯Buffer.slice(18 + optLength, 18 + optLength + 1)
 
 )[0];
 
 
 
 // 0x01 TCP
 
 // 0x02 UDP
 
 // 0x03 MUX
 
 if (command === 1) {
 
 // TCP 命令,不需特殊处理
 
 } else if (command === 2) {
 
 // UDP 命令
 
 isUDP = true;
 
 } else {
 
 // 不支持的命令
 
 return {
 
 hasError: true,
 
 message: `command ${command} is not support, command 01-tcp,02-udp,03-mux`,
 
 };
 
 }
 
 
 
 // 解析远程端口(大端序,2 字节)
 
 const portIndex = 18 + optLength + 1;
 
 const portBuffer = 维列斯Buffer.slice(portIndex, portIndex + 2);
 
 // port is big-Endian in raw data etc 80 == 0x005d
 
 const portRemote = new DataView(portBuffer).getUint16(0);
 
 
 
 // 解析地址类型和地址
 
 let addressIndex = portIndex + 2;
 
 const addressBuffer = new Uint8Array(
 
 维列斯Buffer.slice(addressIndex, addressIndex + 1)
 
 );
 
 
 
 // 地址类型:1-IPv4(4字节), 2-域名(可变长), 3-IPv6(16字节)
 
 const addressType = addressBuffer[0];
 
 let addressLength = 0;
 
 let addressValueIndex = addressIndex + 1;
 
 let addressValue = '';
 
 
 
 switch (addressType) {
 
 case 1:
 
 // IPv4 地址
 
 addressLength = 4;
 
 // 将 4 个字节转为点分十进制格式
 
 addressValue = new Uint8Array(
 
 维列斯Buffer.slice(addressValueIndex, addressValueIndex + addressLength)
 
 ).join('.');
 
 break;
 
 case 2:
 
 // 域名
 
 // 第一个字节是域名长度
 
 addressLength = new Uint8Array(
 
 维列斯Buffer.slice(addressValueIndex, addressValueIndex + 1)
 
 )[0];
 
 addressValueIndex += 1;
 
 // 解码域名
 
 addressValue = new TextDecoder().decode(
 
 维列斯Buffer.slice(addressValueIndex, addressValueIndex + addressLength)
 
 );
 
 break;
 
 case 3:
 
 // IPv6 地址
 
 addressLength = 16;
 
 const dataView = new DataView(
 
 维列斯Buffer.slice(addressValueIndex, addressValueIndex + addressLength)
 
 );
 
 // 每 2 字节构成 IPv6 地址的一部分
 
 const ipv6 = [];
 
 for (let i = 0; i < 8; i++) {
 
 ipv6.push(dataView.getUint16(i * 2).toString(16));
 
 }
 
 addressValue = ipv6.join(':');
 
 // seems no need add [] for ipv6
 
 break;
 
 default:
 
 // 无效的地址类型
 
 return {
 
 hasError: true,
 
 message: `invild addressType is ${addressType}`,
 
 };
 
 }
 
 
 
 // 确保地址不为空
 
 if (!addressValue) {
 
 return {
 
 hasError: true,
 
 message: `addressValue is empty, addressType is ${addressType}`,
 
 };
 
 }
 
 
 
 // 返回解析结果
 
 return {
 
 hasError: false,
 
 addressRemote: addressValue,  // 解析后的远程地址
 
 addressType,         // 地址类型
 
 portRemote,         // 远程端口
 
 rawDataIndex: addressValueIndex + addressLength,  // 原始数据的实际起始位置
 
 维列斯Version: version,    // 维列斯 协议版本
 
 isUDP,           // 是否是 UDP 请求
 
 };
 
 }
 
 
 
 async function remoteSocketToWS(remoteSocket, webSocket, 维列斯ResponseHeader, retry, log) {
 
 // 将数据从远程服务器转发到 WebSocket
 
 let remoteChunkCount = 0;
 
 let chunks = [];
 
 /** @type {ArrayBuffer | null} */
 
 let 维列斯Header = 维列斯ResponseHeader;
 
 let hasIncomingData = false; // 检查远程 Socket 是否有传入数据
 
 
 
 // 使用管道将远程 Socket 的可读流连接到一个可写流
 
 await remoteSocket.readable
 
 .pipeTo(
 
 new WritableStream({
 
 start() {
 
 // 初始化时不需要任何操作
 
 },
 
 /**
 
 * 处理每个数据块
 
 * @param {Uint8Array} chunk 数据块
 
 * @param {*} controller 控制器
 
 */
 
 async write(chunk, controller) {
 
 hasIncomingData = true; // 标记已收到数据
 
 // remoteChunkCount++; // 用于流量控制,现在似乎不需要了
 
 
 
 // 检查 WebSocket 是否处于开放状态
 
 if (webSocket.readyState !== WS_READY_STATE_OPEN) {
 
 controller.error(
 
 'webSocket.readyState is not open, maybe close'
 
 );
 
 }
 
 
 
 if (维列斯Header) {
 
 // 如果有 维列斯 响应头部,将其与第一个数据块一起发送
 
 webSocket.send(await new Blob([维列斯Header, chunk]).arrayBuffer());
 
 维列斯Header = null; // 清空头部,之后不再发送
 
 } else {
 
 // 直接发送数据块
 
 // 以前这里有流量控制代码,限制大量数据的发送速率
 
 // 但现在 Cloudflare 似乎已经修复了这个问题
 
 // if (remoteChunkCount > 20000) {
 
 //   // cf one package is 4096 byte(4kb),  4096 * 20000 = 80M
 
 //   await delay(1);
 
 // }
 
 webSocket.send(chunk);
 
 }
 
 },
 
 close() {
 
 // 当远程连接的可读流关闭时
 
 log(`remoteConnection!.readable is close with hasIncomingData is ${hasIncomingData}`);
 
 // 不需要主动关闭 WebSocket,因为这可能导致 HTTP ERR_CONTENT_LENGTH_MISMATCH 问题
 
 // 客户端无论如何都会发送关闭事件
 
 // safeCloseWebSocket(webSocket);
 
 },
 
 abort(reason) {
 
 // 当远程连接的可读流中断时
 
 console.error(`remoteConnection!.readable abort`, reason);
 
 },
 
 })
 
 )
 
 .catch((error) => {
 
 // 捕获并记录任何异常
 
 console.error(
 
 `remoteSocketToWS has exception `,
 
 error.stack || error
 
 );
 
 // 发生错误时安全地关闭 WebSocket
 
 safeCloseWebSocket(webSocket);
 
 });
 
 
 
 // 处理 Cloudflare 连接 Socket 的特殊错误情况
 
 // 1. Socket.closed 将有错误
 
 // 2. Socket.readable 将关闭,但没有任何数据
 
 if (hasIncomingData === false && retry) {
 
 log(`retry`);
 
 retry(); // 调用重试函数,尝试重新建立连接
 
 }
 
 }
 
 
 
 /**
 
 * 将 Base64 编码的字符串转换为 ArrayBuffer
 
 *
 
 * @param {string} base64Str Base64 编码的输入字符串
 
 * @returns {{ earlyData: ArrayBuffer | undefined, error: Error | null }} 返回解码后的 ArrayBuffer 或错误
 
 */
 
 function base64ToArrayBuffer(base64Str) {
 
 // 如果输入为空,直接返回空结果
 
 if (!base64Str) {
 
 return { error: null };
 
 }
 
 try {
 
 // Go 语言使用了 URL 安全的 Base64 变体(RFC 4648)
 
 // 这种变体使用 '-' 和 '_' 来代替标准 Base64 中的 '+' 和 '/'
 
 // JavaScript 的 atob 函数不直接支持这种变体,所以我们需要先转换
 
 base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
 
 
 
 // 使用 atob 函数解码 Base64 字符串
 
 // atob 将 Base64 编码的 ASCII 字符串转换为原始的二进制字符串
 
 const decode = atob(base64Str);
 
 
 
 // 将二进制字符串转换为 Uint8Array
 
 // 这是通过遍历字符串中的每个字符并获取其 Unicode 编码值(0-255)来完成的
 
 const arryBuffer = Uint8Array.from(decode, (c) => c.charCodeAt(0));
 
 
 
 // 返回 Uint8Array 的底层 ArrayBuffer
 
 // 这是实际的二进制数据,可以用于网络传输或其他二进制操作
 
 return { earlyData: arryBuffer.buffer, error: null };
 
 } catch (error) {
 
 // 如果在任何步骤中出现错误(如非法 Base64 字符),则返回错误
 
 return { error };
 
 }
 
 }
 
 
 
 /**
 
 * 这不是真正的 UUID 验证,而是一个简化的版本
 
 * @param {string} uuid 要验证的 UUID 字符串
 
 * @returns {boolean} 如果字符串匹配 UUID 格式则返回 true,否则返回 false
 
 */
 
 function isValidUUID(uuid) {
 
 // 定义一个正则表达式来匹配 UUID 格式
 
 const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
 
 
 
 // 使用正则表达式测试 UUID 字符串
 
 return uuidRegex.test(uuid);
 
 }
 
 
 
 // WebSocket 的两个重要状态常量
 
 const WS_READY_STATE_OPEN = 1;   // WebSocket 处于开放状态,可以发送和接收消息
 
 const WS_READY_STATE_CLOSING = 2;  // WebSocket 正在关闭过程中
 
 
 
 function safeCloseWebSocket(socket) {
 
 try {
 
 // 只有在 WebSocket 处于开放或正在关闭状态时才调用 close()
 
 // 这避免了在已关闭或连接中的 WebSocket 上调用 close()
 
 if (socket.readyState === WS_READY_STATE_OPEN || socket.readyState === WS_READY_STATE_CLOSING) {
 
 socket.close();
 
 }
 
 } catch (error) {
 
 // 记录任何可能发生的错误,虽然按照规范不应该有错误
 
 console.error('safeCloseWebSocket error', error);
 
 }
 
 }
 
 
 
 // 预计算 0-255 每个字节的十六进制表示
 
 const byteToHex = [];
 
 for (let i = 0; i < 256; ++i) {
 
 // (i + 256).toString(16) 确保总是得到两位数的十六进制
 
 // .slice(1) 删除前导的 "1",只保留两位十六进制数
 
 byteToHex.push((i + 256).toString(16).slice(1));
 
 }
 
 
 
 /**
 
 * 快速地将字节数组转换为 UUID 字符串,不进行有效性检查
 
 * 这是一个底层函数,直接操作字节,不做任何验证
 
 * @param {Uint8Array} arr 包含 UUID 字节的数组
 
 * @param {number} offset 数组中 UUID 开始的位置,默认为 0
 
 * @returns {string} UUID 字符串
 
 */
 
 function unsafeStringify(arr, offset = 0) {
 
 // 直接从查找表中获取每个字节的十六进制表示,并拼接成 UUID 格式
 
 // 8-4-4-4-12 的分组是通过精心放置的连字符 "-" 实现的
 
 // toLowerCase() 确保整个 UUID 是小写的
 
 return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" +
 
 byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" +
 
 byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" +
 
 byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" +
 
 byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] +
 
 byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
 
 }
 
 
 
 /**
 
 * 将字节数组转换为 UUID 字符串,并验证其有效性
 
 * 这是一个安全的函数,它确保返回的 UUID 格式正确
 
 * @param {Uint8Array} arr 包含 UUID 字节的数组
 
 * @param {number} offset 数组中 UUID 开始的位置,默认为 0
 
 * @returns {string} 有效的 UUID 字符串
 
 * @throws {TypeError} 如果生成的 UUID 字符串无效
 
 */
 
 function stringify(arr, offset = 0) {
 
 // 使用不安全的函数快速生成 UUID 字符串
 
 const uuid = unsafeStringify(arr, offset);
 
 // 验证生成的 UUID 是否有效
 
 if (!isValidUUID(uuid)) {
 
 // 原:throw TypeError("Stringified UUID is invalid");
 
 throw TypeError(`生成的 UUID 不符合规范 ${uuid}`);
 
 //uuid = userID;
 
 }
 
 return uuid;
 
 }
 
 
 
 /**
 
 * 处理 DNS 查询的函数
 
 * @param {ArrayBuffer} udpChunk - 客户端发送的 DNS 查询数据
 
 * @param {ArrayBuffer} 维列斯ResponseHeader - 维列斯 协议的响应头部数据
 
 * @param {(string)=> void} log - 日志记录函数
 
 */
 
 async function handleDNSQuery(udpChunk, webSocket, 维列斯ResponseHeader, log) {
 
 // 无论客户端发送到哪个 DNS 服务器,我们总是使用硬编码的服务器
 
 // 因为有些 DNS 服务器不支持 DNS over TCP
 
 try {
 
 // 选用 Google 的 DNS 服务器(注:后续可能会改为 Cloudflare 的 1.1.1.1)
 
 const dnsServer = '8.8.4.4'; // 在 Cloudflare 修复连接自身 IP 的 bug 后,将改为 1.1.1.1
 
 const dnsPort = 53; // DNS 服务的标准端口
 
 
 
 let 维列斯Header = 维列斯ResponseHeader; // 保存 维列斯 响应头部,用于后续发送
 
 
 
 // 与指定的 DNS 服务器建立 TCP 连接
 
 const tcpSocket = connect({
 
 hostname: dnsServer,
 
 port: dnsPort,
 
 });
 
 
 
 log(`连接到 ${dnsServer}:${dnsPort}`); // 记录连接信息
 
 const writer = tcpSocket.writable.getWriter();
 
 await writer.write(udpChunk); // 将客户端的 DNS 查询数据发送给 DNS 服务器
 
 writer.releaseLock(); // 释放写入器,允许其他部分使用
 
 
 
 // 将从 DNS 服务器接收到的响应数据通过 WebSocket 发送回客户端
 
 await tcpSocket.readable.pipeTo(new WritableStream({
 
 async write(chunk) {
 
 if (webSocket.readyState === WS_READY_STATE_OPEN) {
 
 if (维列斯Header) {
 
 // 如果有 维列斯 头部,则将其与 DNS 响应数据合并后发送
 
 webSocket.send(await new Blob([维列斯Header, chunk]).arrayBuffer());
 
 维列斯Header = null; // 头部只发送一次,之后置为 null
 
 } else {
 
 // 否则直接发送 DNS 响应数据
 
 webSocket.send(chunk);
 
 }
 
 }
 
 },
 
 close() {
 
 log(`DNS 服务器(${dnsServer}) TCP 连接已关闭`); // 记录连接关闭信息
 
 },
 
 abort(reason) {
 
 console.error(`DNS 服务器(${dnsServer}) TCP 连接异常中断`, reason); // 记录异常中断原因
 
 },
 
 }));
 
 } catch (error) {
 
 // 捕获并记录任何可能发生的错误
 
 console.error(
 
 `handleDNSQuery 函数发生异常,错误信息: ${error.message}`
 
 );
 
 }
 
 }
 
 
 
 /**
 
 * 建立 SOCKS5 代理连接
 
 * @param {number} addressType 目标地址类型(1: IPv4, 2: 域名, 3: IPv6)
 
 * @param {string} addressRemote 目标地址(可以是 IP 或域名)
 
 * @param {number} portRemote 目标端口
 
 * @param {function} log 日志记录函数
 
 */
 
 async function socks5Connect(addressType, addressRemote, portRemote, log) {
 
 const { username, password, hostname, port } = parsedSocks5Address;
 
 // 连接到 SOCKS5 代理服务器
 
 const socket = connect({
 
 hostname, // SOCKS5 服务器的主机名
 
 port,  // SOCKS5 服务器的端口
 
 });
 
 
 
 // 请求头格式(Worker -> SOCKS5 服务器):
 
 // +----+----------+----------+
 
 // |VER | NMETHODS | METHODS  |
 
 // +----+----------+----------+
 
 // | 1  |  1   | 1 to 255 |
 
 // +----+----------+----------+
 
 
 
 // https://en.wikipedia.org/wiki/SOCKS#SOCKS5
 
 // METHODS 字段的含义:
 
 // 0x00 不需要认证
 
 // 0x02 用户名/密码认证 https://datatracker.ietf.org/doc/html/rfc1929
 
 const socksGreeting = new Uint8Array([5, 2, 0, 2]);
 
 // 5: SOCKS5 版本号, 2: 支持的认证方法数, 0和2: 两种认证方法(无认证和用户名/密码)
 
 
 
 const writer = socket.writable.getWriter();
 
 
 
 await writer.write(socksGreeting);
 
 log('已发送 SOCKS5 问候消息');
 
 
 
 const reader = socket.readable.getReader();
 
 const encoder = new TextEncoder();
 
 let res = (await reader.read()).value;
 
 // 响应格式(SOCKS5 服务器 -> Worker):
 
 // +----+--------+
 
 // |VER | METHOD |
 
 // +----+--------+
 
 // | 1  |   1  |
 
 // +----+--------+
 
 if (res[0] !== 0x05) {
 
 log(`SOCKS5 服务器版本错误: 收到 ${res[0]},期望是 5`);
 
 return;
 
 }
 
 if (res[1] === 0xff) {
 
 log("服务器不接受任何认证方法");
 
 return;
 
 }
 
 
 
 // 如果返回 0x0502,表示需要用户名/密码认证
 
 if (res[1] === 0x02) {
 
 log("SOCKS5 服务器需要认证");
 
 if (!username || !password) {
 
 log("请提供用户名和密码");
 
 return;
 
 }
 
 // 认证请求格式:
 
 // +----+------+----------+------+----------+
 
 // |VER | ULEN |  UNAME   | PLEN |  PASSWD  |
 
 // +----+------+----------+------+----------+
 
 // | 1  |  1   | 1 to 255 |  1   | 1 to 255 |
 
 // +----+------+----------+------+----------+
 
 const authRequest = new Uint8Array([
 
 1,           // 认证子协议版本
 
 username.length,  // 用户名长度
 
 ...encoder.encode(username), // 用户名
 
 password.length,  // 密码长度
 
 ...encoder.encode(password)  // 密码
 
 ]);
 
 await writer.write(authRequest);
 
 res = (await reader.read()).value;
 
 // 期望返回 0x0100 表示认证成功
 
 if (res[0] !== 0x01 || res[1] !== 0x00) {
 
 log("SOCKS5 服务器认证失败");
 
 return;
 
 }
 
 }
 
 
 
 // 请求数据格式(Worker -> SOCKS5 服务器):
 
 // +----+-----+-------+------+----------+----------+
 
 // |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
 
 // +----+-----+-------+------+----------+----------+
 
 // | 1  |  1  | X'00' |  1   | Variable |  2   |
 
 // +----+-----+-------+------+----------+----------+
 
 // ATYP: 地址类型
 
 // 0x01: IPv4 地址
 
 // 0x03: 域名
 
 // 0x04: IPv6 地址
 
 // DST.ADDR: 目标地址
 
 // DST.PORT: 目标端口(网络字节序)
 
 
 
 // addressType
 
 // 1 --> IPv4  地址长度 = 4
 
 // 2 --> 域名
 
 // 3 --> IPv6  地址长度 = 16
 
 let DSTADDR;  // DSTADDR = ATYP + DST.ADDR
 
 switch (addressType) {
 
 case 1: // IPv4
 
 DSTADDR = new Uint8Array(
 
 [1, ...addressRemote.split('.').map(Number)]
 
 );
 
 break;
 
 case 2: // 域名
 
 DSTADDR = new Uint8Array(
 
 [3, addressRemote.length, ...encoder.encode(addressRemote)]
 
 );
 
 break;
 
 case 3: // IPv6
 
 DSTADDR = new Uint8Array(
 
 [4, ...addressRemote.split(':').flatMap(x => [parseInt(x.slice(0, 2), 16), parseInt(x.slice(2), 16)])]
 
 );
 
 break;
 
 default:
 
 log(`无效的地址类型: ${addressType}`);
 
 return;
 
 }
 
 const socksRequest = new Uint8Array([5, 1, 0, ...DSTADDR, portRemote >> 8, portRemote & 0xff]);
 
 // 5: SOCKS5版本, 1: 表示CONNECT请求, 0: 保留字段
 
 // ...DSTADDR: 目标地址, portRemote >> 8 和 & 0xff: 将端口转为网络字节序
 
 await writer.write(socksRequest);
 
 log('已发送 SOCKS5 请求');
 
 
 
 res = (await reader.read()).value;
 
 // 响应格式(SOCKS5 服务器 -> Worker):
 
 //  +----+-----+-------+------+----------+----------+
 
 // |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
 
 // +----+-----+-------+------+----------+----------+
 
 // | 1  |  1  | X'00' |  1   | Variable |  2   |
 
 // +----+-----+-------+------+----------+----------+
 
 if (res[1] === 0x00) {
 
 log("SOCKS5 连接已建立");
 
 } else {
 
 log("SOCKS5 连接建立失败");
 
 return;
 
 }
 
 writer.releaseLock();
 
 reader.releaseLock();
 
 return socket;
 
 }
 
 
 
 /**
 
 * SOCKS5 代理地址解析器
 
 * 此函数用于解析 SOCKS5 代理地址字符串,提取出用户名、密码、主机名和端口号
 
 *
 
 * @param {string} address SOCKS5 代理地址,格式可以是:
 
 *   - "username:password@hostname:port" (带认证)
 
 *   - "hostname:port" (不需认证)
 
 *   - "username:password@[ipv6]:port" (IPv6 地址需要用方括号括起来)
 
 */
 
 function socks5AddressParser(address) {
 
 // 使用 "@" 分割地址,分为认证部分和服务器地址部分
 
 // reverse() 是为了处理没有认证信息的情况,确保 latter 总是包含服务器地址
 
 let [latter, former] = address.split("@").reverse();
 
 let username, password, hostname, port;
 
 
 
 // 如果存在 former 部分,说明提供了认证信息
 
 if (former) {
 
 const formers = former.split(":");
 
 if (formers.length !== 2) {
 
 throw new Error('无效的 SOCKS 地址格式:认证部分必须是 "username:password" 的形式');
 
 }
 
 [username, password] = formers;
 
 }
 
 
 
 // 解析服务器地址部分
 
 const latters = latter.split(":");
 
 // 从末尾提取端口号(因为 IPv6 地址中也包含冒号)
 
 port = Number(latters.pop());
 
 if (isNaN(port)) {
 
 throw new Error('无效的 SOCKS 地址格式:端口号必须是数字');
 
 }
 
 
 
 // 剩余部分就是主机名(可能是域名、IPv4 或 IPv6 地址)
 
 hostname = latters.join(":");
 
 
 
 // 处理 IPv6 地址的特殊情况
 
 // IPv6 地址包含多个冒号,所以必须用方括号括起来,如 [2001:db8::1]
 
 const regex = /^\[.*\]$/;
 
 if (hostname.includes(":") && !regex.test(hostname)) {
 
 throw new Error('无效的 SOCKS 地址格式:IPv6 地址必须用方括号括起来,如 [2001:db8::1]');
 
 }
 
 
 
 //if (/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(hostname)) hostname = `${atob('d3d3Lg==')}${hostname}${atob('LmlwLjA5MDIyNy54eXo=')}`;
 
 // 返回解析后的结果
 
 return {
 
 username,  // 用户名,如果没有则为 undefined
 
 password,  // 密码,如果没有则为 undefined
 
 hostname,  // 主机名,可以是域名、IPv4 或 IPv6 地址
 
 port,   // 端口号,已转换为数字类型
 
 }
 
 }
 
 
 
 /**
 
 * 恢复被伪装的信息
 
 * 这个函数用于将内容中的假用户ID和假主机名替换回真实的值
 
 *
 
 * @param {string} content 需要处理的内容
 
 * @param {string} userID 真实的用户ID
 
 * @param {string} hostName 真实的主机名
 
 * @param {boolean} isBase64 内容是否是Base64编码的
 
 * @returns {string} 恢复真实信息后的内容
 
 */
 
 function 恢复伪装信息(content, userID, hostName, isBase64) {
 
 if (isBase64) content = atob(content);  // 如果内容是Base64编码的,先解码
 
 
 
 // 使用正则表达式全局替换('g'标志)
 
 // 将所有出现的假用户ID和假主机名替换为真实的值
 
 content = content.replace(new RegExp(fakeUserID, 'g'), userID)
 
 .replace(new RegExp(fakeHostName, 'g'), hostName);
 
 
 
 if (isBase64) content = btoa(content);  // 如果原内容是Base64编码的,处理完后再次编码
 
 
 
 return content;
 
 }
 
 
 
 /**
 
 * 双重MD5哈希函数
 
 * 这个函数对输入文本进行两次MD5哈希,增强安全性
 
 * 第二次哈希使用第一次哈希结果的一部分作为输入
 
 *
 
 * @param {string} 文本 要哈希的文本
 
 * @returns {Promise<string>} 双重哈希后的小写十六进制字符串
 
 */
 
 async function 双重哈希(文本) {
 
 const 编码器 = new TextEncoder();
 
 
 
 const 第一次哈希 = await crypto.subtle.digest('MD5', 编码器.encode(文本));
 
 const 第一次哈希数组 = Array.from(new Uint8Array(第一次哈希));
 
 const 第一次十六进制 = 第一次哈希数组.map(字节 => 字节.toString(16).padStart(2, '0')).join('');
 
 
 
 const 第二次哈希 = await crypto.subtle.digest('MD5', 编码器.encode(第一次十六进制.slice(7, 27)));
 
 const 第二次哈希数组 = Array.from(new Uint8Array(第二次哈希));
 
 const 第二次十六进制 = 第二次哈希数组.map(字节 => 字节.toString(16).padStart(2, '0')).join('');
 
 
 
 return 第二次十六进制.toLowerCase();
 
 }
 
 
 
 async function 代理URL(代理网址, 目标网址) {
 
 const 网址列表 = await 整理(代理网址);
 
 const 完整网址 = 网址列表[Math.floor(Math.random() * 网址列表.length)];
 
 
 
 // 解析目标 URL
 
 let 解析后的网址 = new URL(完整网址);
 
 console.log(解析后的网址);
 
 // 提取并可能修改 URL 组件
 
 let 协议 = 解析后的网址.protocol.slice(0, -1) || 'https';
 
 let 主机名 = 解析后的网址.hostname;
 
 let 路径名 = 解析后的网址.pathname;
 
 let 查询参数 = 解析后的网址.search;
 
 
 
 // 处理路径名
 
 if (路径名.charAt(路径名.length - 1) == '/') {
 
 路径名 = 路径名.slice(0, -1);
 
 }
 
 路径名 += 目标网址.pathname;
 
 
 
 // 构建新的 URL
 
 let 新网址 = `${协议}://${主机名}${路径名}${查询参数}`;
 
 
 
 // 反向代理请求
 
 let 响应 = await fetch(新网址);
 
 
 
 // 创建新的响应
 
 let 新响应 = new Response(响应.body, {
 
 status: 响应.status,
 
 statusText: 响应.statusText,
 
 headers: 响应.headers
 
 });
 
 
 
 // 添加自定义头部,包含 URL 信息
 
 //新响应.headers.set('X-Proxied-By', 'Cloudflare Worker');
 
 //新响应.headers.set('X-Original-URL', 完整网址);
 
 新响应.headers.set('X-New-URL', 新网址);
 
 
 
 return 新响应;
 
 }
 
 
 
 const 啥啥啥_写的这是啥啊 = atob('ZG14bGMzTT0=');
 
 function 配置信息(UUID, 域名地址) {
 
 const 协议类型 = atob(啥啥啥_写的这是啥啊);
 
 
 
 const 别名 = FileName;
 
 let 地址 = 域名地址;
 
 let 端口 = 443;
 
 
 
 const 用户ID = UUID;
 
 const 加密方式 = 'none';
 
 
 
 const 传输层协议 = 'ws';
 
 const 伪装域名 = 域名地址;
 
 const 路径 = path;
 
 
 
 let 传输层安全 = ['tls',true];
 
 const SNI = 域名地址;
 
 const 指纹 = 'randomized';
 
 
 
 if (域名地址.includes('.workers.dev')){
 
 地址 = atob('dmlzYS5jbg==');
 
 端口 = 80 ;
 
 传输层安全 = ['',false];
 
 }
 
 
 
 const 威图瑞 = `${协议类型}://${用户ID}@${地址}:${端口}\u003f\u0065\u006e\u0063\u0072\u0079`+'p'+`${atob('dGlvbj0=') + 加密方式}\u0026\u0073\u0065\u0063\u0075\u0072\u0069\u0074\u0079\u003d${传输层安全[0]}&sni=${SNI}&fp=${指纹}&type=${传输层协议}&host=${伪装域名}&path=${encodeURIComponent(路径)}#${encodeURIComponent(别名)}`;
 
 const 猫猫猫 = `- type: ${协议类型}
 
 name: ${FileName}
 
 server: ${地址}
 
 port: ${端口}
 
 uuid: ${用户ID}
 
 network: ${传输层协议}
 
 tls: ${传输层安全[1]}
 
 udp: false
 
 sni: ${SNI}
 
 client-fingerprint: ${指纹}
 
 ws-opts:
 
 path: "${路径}"
 
 headers:
 
 host: ${伪装域名}`;
 
 return [威图瑞,猫猫猫];
 
 }
 
 
 
 let subParams = ['sub','base64','b64','clash','singbox','sb'];
 
 
 
 /**
 
 * @param {string} userID
 
 * @param {string | null} hostName
 
 * @param {string} sub
 
 * @param {string} UA
 
 * @returns {Promise<string>}
 
 */
 
 async function 生成配置信息(userID, hostName, sub, UA, RproxyIP, _url, env) {
 
 if (sub) {
 
 const match = sub.match(/^(?:https?:\/\/)?([^\/]+)/);
 
 if (match) {
 
 sub = match[1];
 
 }
 
 const subs = await 整理(sub);
 
 if (subs.length > 1) sub = subs[0];
 
 
 
 } else if ((addresses.length + addressesapi.length + addressesnotls.length + addressesnotlsapi.length + addressescsv.length) == 0){
 
 // 定义 Cloudflare IP 范围的 CIDR 列表
 
 let cfips = [
 
 '103.21.244.0/23',
 
 '104.16.0.0/13',
 
 '104.24.0.0/14',
 
 '172.64.0.0/14',
 
 '103.21.244.0/23',
 
 '104.16.0.0/14',
 
 '104.24.0.0/15',
 
 '141.101.64.0/19',
 
 '172.64.0.0/14',
 
 '188.114.96.0/21',
 
 '190.93.240.0/21',
 
 ];
 
 
 
 // 生成符合给定 CIDR 范围的随机 IP 地址
 
 function generateRandomIPFromCIDR(cidr) {
 
 const [base, mask] = cidr.split('/');
 
 const baseIP = base.split('.').map(Number);
 
 const subnetMask = 32 - parseInt(mask, 10);
 
 const maxHosts = Math.pow(2, subnetMask) - 1;
 
 const randomHost = Math.floor(Math.random() * maxHosts);
 
 
 
 const randomIP = baseIP.map((octet, index) => {
 
 if (index < 2) return octet;
 
 if (index === 2) return (octet & (255 << (subnetMask - 8))) + ((randomHost >> 8) & 255);
 
 return (octet & (255 << subnetMask)) + (randomHost & 255);
 
 });
 
 
 
 return randomIP.join('.');
 
 }
 
 addresses = addresses.concat('127.0.0.1:1234#CFnat');
 
 if (hostName.includes(".workers.dev")) {
 
 addressesnotls = addressesnotls.concat(cfips.map(cidr => generateRandomIPFromCIDR(cidr) + '#CF随机节点'));
 
 } else {
 
 addresses = addresses.concat(cfips.map(cidr => generateRandomIPFromCIDR(cidr) + '#CF随机节点'));
 
 }
 
 }
 
 const uuid = (_url.pathname == `/${动态UUID}`) ? 动态UUID : userID;
 
 const userAgent = UA.toLowerCase();
 
 const Config = 配置信息(userID , hostName);
 
 const v2ray = Config[0];
 
 const clash = Config[1];
 
 let proxyhost = "";
 
 if(hostName.includes(".workers.dev")){
 
 if ( proxyhostsURL && (!proxyhosts || proxyhosts.length == 0)) {
 
 try {
 
 const response = await fetch(proxyhostsURL);
 
 
 
 if (!response.ok) {
 
 console.error('获取地址时出错:', response.status, response.statusText);
 
 return; // 如果有错误,直接返回
 
 }
 
 
 
 const text = await response.text();
 
 const lines = text.split('\n');
 
 // 过滤掉空行或只包含空白字符的行
 
 const nonEmptyLines = lines.filter(line => line.trim() !== '');
 
 
 
 proxyhosts = proxyhosts.concat(nonEmptyLines);
 
 } catch (error) {
 
 //console.error('获取地址时出错:', error);
 
 }
 
 }
 
 if (proxyhosts.length != 0) proxyhost = proxyhosts[Math.floor(Math.random() * proxyhosts.length)] + "/";
 
 }
 
 
 
 if (userAgent.includes('mozilla') && !subParams.some(_searchParams => _url.searchParams.has(_searchParams))) {
 
 const newSocks5s = socks5s.map(socks5Address => {
 
 if (socks5Address.includes('@')) return socks5Address.split('@')[1];
 
 else if (socks5Address.includes('//')) return socks5Address.split('//')[1];
 
 else return socks5Address;
 
 });
 
 
 
 let socks5List = '';
 
 if (go2Socks5s.length > 0 && enableSocks ) {
 
 socks5List = `${decodeURIComponent('SOCKS5%EF%BC%88%E7%99%BD%E5%90%8D%E5%8D%95%EF%BC%89%3A%20')}`;
 
 if (go2Socks5s.includes(atob('YWxsIGlu'))||go2Socks5s.includes(atob('Kg=='))) socks5List += `${decodeURIComponent('%E6%89%80%E6%9C%89%E6%B5%81%E9%87%8F')}\n`;
 
 else socks5List += `\n  ${go2Socks5s.join('\n  ')}\n`;
 
 }
 
 
 
 let 订阅器 = '\n';
 
 if (sub) {
 
 if (enableSocks) 订阅器 += `CFCDN(访问方式): Socks5\n  ${newSocks5s.join('\n  ')}\n${socks5List}`;
 
 else if (proxyIP && proxyIP != '') 订阅器 += `CFCDN(访问方式): ProxyIP\n  ${proxyIPs.join('\n  ')}\n`;
 
 else if (RproxyIP == 'true') 订阅器 += `CFCDN(访问方式): 自动获取ProxyIP\n`;
 
 else 订阅器 += `CFCDN(访问方式): 无法访问, 需要您设置 proxyIP/PROXYIP !!!\n`
 
 订阅器 += `\nSUB(优选订阅生成器): ${sub}`;
 
 } else {
 
 if (enableSocks) 订阅器 += `CFCDN(访问方式): Socks5\n  ${newSocks5s.join('\n  ')}\n${socks5List}`;
 
 else if (proxyIP && proxyIP != '') 订阅器 += `CFCDN(访问方式): ProxyIP\n  ${proxyIPs.join('\n  ')}\n`;
 
 else 订阅器 += `CFCDN(访问方式): 无法访问, 需要您设置 proxyIP/PROXYIP !!!\n`;
 
 订阅器 += `\n您的订阅内容由 内置 addresses/ADD* 参数变量提供\n`;
 
 if (addresses.length > 0) 订阅器 += `ADD(TLS优选域名&IP): \n  ${addresses.join('\n  ')}\n`;
 
 if (addressesnotls.length > 0) 订阅器 += `ADDNOTLS(noTLS优选域名&IP): \n  ${addressesnotls.join('\n  ')}\n`;
 
 if (addressesapi.length > 0) 订阅器 += `ADDAPI(TLS优选域名&IP 的 API): \n  ${addressesapi.join('\n  ')}\n`;
 
 if (addressesnotlsapi.length > 0) 订阅器 += `ADDNOTLSAPI(noTLS优选域名&IP 的 API): \n  ${addressesnotlsapi.join('\n  ')}\n`;
 
 if (addressescsv.length > 0) 订阅器 += `ADDCSV(IPTest测速csv文件 限速 ${DLS} ): \n  ${addressescsv.join('\n  ')}\n`;
 
 }
 
 
 
 if (动态UUID && _url.pathname !== `/${动态UUID}`) 订阅器 = '';
 
 else 订阅器 += `\nSUBAPI(订阅转换后端): ${subProtocol}://${subConverter}\nSUBCONFIG(订阅转换配置文件): ${subConfig}`;
 
 const 动态UUID信息 = (uuid != userID) ? `TOKEN: ${uuid}\nUUIDNow: ${userID}\nUUIDLow: ${userIDLow}\n${userIDTime}TIME(动态UUID有效时间): ${有效时间} 天\nUPTIME(动态UUID更新时间): ${更新时间} 时(北京时间)\n\n` : `${userIDTime}`;
 
 return `
 
 ################################################################
 
 Subscribe / sub 订阅地址, 支持 Base64、clash-meta、sing-box 订阅格式
 
 ---------------------------------------------------------------
 
 快速自适应订阅地址:
 
 https://${proxyhost}${hostName}/${uuid}
 
 https://${proxyhost}${hostName}/${uuid}?sub
 
 
 
 Base64订阅地址:
 
 https://${proxyhost}${hostName}/${uuid}?b64
 
 https://${proxyhost}${hostName}/${uuid}?base64
 
 
 
 clash订阅地址:
 
 https://${proxyhost}${hostName}/${uuid}?clash
 
 
 
 singbox订阅地址:
 
 https://${proxyhost}${hostName}/${uuid}?sb
 
 https://${proxyhost}${hostName}/${uuid}?singbox
 
 ---------------------------------------------------------------
 
 ################################################################
 
 ${FileName} 配置信息
 
 ---------------------------------------------------------------
 
 ${动态UUID信息}HOST: ${hostName}
 
 UUID: ${userID}
 
 FKID: ${fakeUserID}
 
 UA: ${UA}
 
 ${订阅器}
 
 ---------------------------------------------------------------
 
 ################################################################
 
 v2ray
 
 ---------------------------------------------------------------
 
 ${v2ray}
 
 ---------------------------------------------------------------
 
 ################################################################
 
 clash-meta
 
 ---------------------------------------------------------------
 
 ${clash}
 
 ---------------------------------------------------------------
 
 ################################################################
 
 ${decodeURIComponent(atob('dGVsZWdyYW0lMjAlRTQlQkElQTQlRTYlQjUlODElRTclQkUlQTQlMjAlRTYlOEElODAlRTYlOUMlQUYlRTUlQTQlQTclRTQlQkQlQUMlN0UlRTUlOUMlQTglRTclQkElQkYlRTUlOEYlOTElRTclODklOEMhCmh0dHBzJTNBJTJGJTJGdC5tZSUyRkNNTGl1c3NzcwotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KZ2l0aHViJTIwJUU5JUExJUI5JUU3JTlCJUFFJUU1JTlDJUIwJUU1JTlEJTgwJTIwU3RhciFTdGFyIVN0YXIhISEKaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGY21saXUlMkZlZGdldHVubmVsCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQolMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjMlMjM='))}
 
 `;
 
 } else {
 
 if (typeof fetch != 'function') {
 
 return 'Error: fetch is not available in this environment.';
 
 }
 
 
 
 let newAddressesapi = [];
 
 let newAddressescsv = [];
 
 let newAddressesnotlsapi = [];
 
 let newAddressesnotlscsv = [];
 
 
 
 // 如果是使用默认域名,则改成一个workers的域名,订阅器会加上代理
 
 if (hostName.includes(".workers.dev")){
 
 noTLS = 'true';
 
 fakeHostName = `${fakeHostName}.workers.dev`;
 
 newAddressesnotlsapi = await 整理优选列表(addressesnotlsapi);
 
 newAddressesnotlscsv = await 整理测速结果('FALSE');
 
 } else if (hostName.includes(".pages.dev")){
 
 fakeHostName = `${fakeHostName}.pages.dev`;
 
 } else if (hostName.includes("worker") || hostName.includes("notls") || noTLS == 'true'){
 
 noTLS = 'true';
 
 fakeHostName = `notls${fakeHostName}.net`;
 
 newAddressesnotlsapi = await 整理优选列表(addressesnotlsapi);
 
 newAddressesnotlscsv = await 整理测速结果('FALSE');
 
 } else {
 
 fakeHostName = `${fakeHostName}.xyz`
 
 }
 
 console.log(`虚假HOST: ${fakeHostName}`);
 
 let url = `${subProtocol}://${sub}/sub?host=${fakeHostName}&uuid=${fakeUserID + atob('JmVkZ2V0dW5uZWw9Y21saXUmcHJveHlpcD0=') + RproxyIP}&path=${encodeURIComponent(path)}`;
 
 let isBase64 = true;
 
 
 
 if (!sub || sub == ""){
 
 if(hostName.includes('workers.dev')) {
 
 if (proxyhostsURL && (!proxyhosts || proxyhosts.length == 0)) {
 
 try {
 
 const response = await fetch(proxyhostsURL);
 
 
 
 if (!response.ok) {
 
 console.error('获取地址时出错:', response.status, response.statusText);
 
 return; // 如果有错误,直接返回
 
 }
 
 
 
 const text = await response.text();
 
 const lines = text.split('\n');
 
 // 过滤掉空行或只包含空白字符的行
 
 const nonEmptyLines = lines.filter(line => line.trim() !== '');
 
 
 
 proxyhosts = proxyhosts.concat(nonEmptyLines);
 
 } catch (error) {
 
 console.error('获取地址时出错:', error);
 
 }
 
 }
 
 // 使用Set对象去重
 
 proxyhosts = [...new Set(proxyhosts)];
 
 }
 
 
 
 newAddressesapi = await 整理优选列表(addressesapi);
 
 newAddressescsv = await 整理测速结果('TRUE');
 
 url = `https://${hostName}/${fakeUserID + _url.search}`;
 
 if (hostName.includes("worker") || hostName.includes("notls") || noTLS == 'true') {
 
 if (_url.search) url += '¬ls';
 
 else url += '?notls';
 
 }
 
 console.log(`虚假订阅: ${url}`);
 
 }
 
 
 
 if (!userAgent.includes(('CF-Workers-SUB').toLowerCase())){
 
 if ((userAgent.includes('clash') && !userAgent.includes('nekobox')) || ( _url.searchParams.has('clash') && !userAgent.includes('subconverter'))) {
 
 url = `${subProtocol}://${subConverter}/sub?target=clash&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subConfig)}&emoji=${subEmoji}&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
 
 isBase64 = false;
 
 } else if (userAgent.includes('sing-box') || userAgent.includes('singbox') || (( _url.searchParams.has('singbox') || _url.searchParams.has('sb')) && !userAgent.includes('subconverter'))) {
 
 url = `${subProtocol}://${subConverter}/sub?target=singbox&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subConfig)}&emoji=${subEmoji}&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
 
 isBase64 = false;
 
 }
 
 }
 
 
 
 try {
 
 let content;
 
 if ((!sub || sub == "") && isBase64 == true) {
 
 content = await 生成本地订阅(fakeHostName,fakeUserID,noTLS,newAddressesapi,newAddressescsv,newAddressesnotlsapi,newAddressesnotlscsv);
 
 } else {
 
 const response = await fetch(url ,{
 
 headers: {
 
 'User-Agent': UA + atob('IENGLVdvcmtlcnMtZWRnZXR1bm5lbC9jbWxpdQ==')
 
 }});
 
 content = await response.text();
 
 }
 
 
 
 if (_url.pathname == `/${fakeUserID}`) return content;
 
 
 
 return 恢复伪装信息(content, userID, hostName, isBase64);
 
 
 
 } catch (error) {
 
 console.error('Error fetching content:', error);
 
 return `Error fetching content: ${error.message}`;
 
 }
 
 }
 
 }
 
 
 
 async function 整理优选列表(api) {
 
 if (!api || api.length === 0) return [];
 
 
 
 let newapi = "";
 
 
 
 // 创建一个AbortController对象,用于控制fetch请求的取消
 
 const controller = new AbortController();
 
 
 
 const timeout = setTimeout(() => {
 
 controller.abort(); // 取消所有请求
 
 }, 2000); // 2秒后触发
 
 
 
 try {
 
 // 使用Promise.allSettled等待所有API请求完成,无论成功或失败
 
 // 对api数组进行遍历,对每个API地址发起fetch请求
 
 const responses = await Promise.allSettled(api.map(apiUrl => fetch(apiUrl, {
 
 method: 'get',
 
 headers: {
 
 'Accept': 'text/html,application/xhtml+xml,application/xml;',
 
 'User-Agent': atob('Q0YtV29ya2Vycy1lZGdldHVubmVsL2NtbGl1')
 
 },
 
 signal: controller.signal // 将AbortController的信号量添加到fetch请求中,以便于需要时可以取消请求
 
 }).then(response => response.ok ? response.text() : Promise.reject())));
 
 
 
 // 遍历所有响应
 
 for (const [index, response] of responses.entries()) {
 
 // 检查响应状态是否为'fulfilled',即请求成功完成
 
 if (response.status === 'fulfilled') {
 
 // 获取响应的内容
 
 const content = await response.value;
 
 
 
 const lines = content.split(/\r?\n/);
 
 let 节点备注 = '';
 
 let 测速端口 = '443';
 
 
 
 if (lines[0].split(',').length > 3){
 
 const idMatch = api[index].match(/id=([^&]*)/);
 
 if (idMatch) 节点备注 = idMatch[1];
 
 
 
 const portMatch = api[index].match(/port=([^&]*)/);
 
 if (portMatch) 测速端口 = portMatch[1];
 
 
 
 for (let i = 1; i < lines.length; i++) {
 
 const columns = lines[i].split(',')[0];
 
 if(columns){
 
 newapi += `${columns}:${测速端口}${节点备注 ? `#${节点备注}` : ''}\n`;
 
 if (api[index].includes('proxyip=true')) proxyIPPool.push(`${columns}:${测速端口}`);
 
 }
 
 }
 
 } else {
 
 // 验证当前apiUrl是否带有'proxyip=true'
 
 if (api[index].includes('proxyip=true')) {
 
 // 如果URL带有'proxyip=true',则将内容添加到proxyIPPool
 
 proxyIPPool = proxyIPPool.concat((await 整理(content)).map(item => {
 
 const baseItem = item.split('#')[0] || item;
 
 if (baseItem.includes(':')) {
 
 const port = baseItem.split(':')[1];
 
 if (!httpsPorts.includes(port)) {
 
 return baseItem;
 
 }
 
 } else {
 
 return `${baseItem}:443`;
 
 }
 
 return null; // 不符合条件时返回 null
 
 }).filter(Boolean)); // 过滤掉 null 值
 
 }
 
 // 将内容添加到newapi中
 
 newapi += content + '\n';
 
 }
 
 }
 
 }
 
 } catch (error) {
 
 console.error(error);
 
 } finally {
 
 // 无论成功或失败,最后都清除设置的超时定时器
 
 clearTimeout(timeout);
 
 }
 
 
 
 const newAddressesapi = await 整理(newapi);
 
 
 
 // 返回处理后的结果
 
 return newAddressesapi;
 
 }
 
 
 
 async function 整理测速结果(tls) {
 
 if (!addressescsv || addressescsv.length === 0) {
 
 return [];
 
 }
 
 
 
 let newAddressescsv = [];
 
 
 
 for (const csvUrl of addressescsv) {
 
 try {
 
 const response = await fetch(csvUrl);
 
 
 
 if (!response.ok) {
 
 console.error('获取CSV地址时出错:', response.status, response.statusText);
 
 continue;
 
 }
 
 
 
 const text = await response.text();// 使用正确的字符编码解析文本内容
 
 let lines;
 
 if (text.includes('\r\n')){
 
 lines = text.split('\r\n');
 
 } else {
 
 lines = text.split('\n');
 
 }
 
 
 
 // 检查CSV头部是否包含必需字段
 
 const header = lines[0].split(',');
 
 const tlsIndex = header.indexOf('TLS');
 
 
 
 const ipAddressIndex = 0;// IP地址在 CSV 头部的位置
 
 const portIndex = 1;// 端口在 CSV 头部的位置
 
 const dataCenterIndex = tlsIndex + remarkIndex; // 数据中心是 TLS 的后一个字段
 
 
 
 if (tlsIndex === -1) {
 
 console.error('CSV文件缺少必需的字段');
 
 continue;
 
 }
 
 
 
 // 从第二行开始遍历CSV行
 
 for (let i = 1; i < lines.length; i++) {
 
 const columns = lines[i].split(',');
 
 const speedIndex = columns.length - 1; // 最后一个字段
 
 // 检查TLS是否为"TRUE"且速度大于DLS
 
 if (columns[tlsIndex].toUpperCase() === tls && parseFloat(columns[speedIndex]) > DLS) {
 
 const ipAddress = columns[ipAddressIndex];
 
 const port = columns[portIndex];
 
 const dataCenter = columns[dataCenterIndex];
 
 
 
 const formattedAddress = `${ipAddress}:${port}#${dataCenter}`;
 
 newAddressescsv.push(formattedAddress);
 
 if (csvUrl.includes('proxyip=true') && columns[tlsIndex].toUpperCase() == 'true' && !httpsPorts.includes(port)) {
 
 // 如果URL带有'proxyip=true',则将内容添加到proxyIPPool
 
 proxyIPPool.push(`${ipAddress}:${port}`);
 
 }
 
 }
 
 }
 
 } catch (error) {
 
 console.error('获取CSV地址时出错:', error);
 
 continue;
 
 }
 
 }
 
 
 
 return newAddressescsv;
 
 }
 
 
 
 function 生成本地订阅(host,UUID,noTLS,newAddressesapi,newAddressescsv,newAddressesnotlsapi,newAddressesnotlscsv) {
 
 const regex = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[.*\]):?(\d+)?#?(.*)?$/;
 
 addresses = addresses.concat(newAddressesapi);
 
 addresses = addresses.concat(newAddressescsv);
 
 let notlsresponseBody ;
 
 if (noTLS == 'true'){
 
 addressesnotls = addressesnotls.concat(newAddressesnotlsapi);
 
 addressesnotls = addressesnotls.concat(newAddressesnotlscsv);
 
 const uniqueAddressesnotls = [...new Set(addressesnotls)];
 
 
 
 notlsresponseBody = uniqueAddressesnotls.map(address => {
 
 let port = "-1";
 
 let addressid = address;
 
 
 
 const match = addressid.match(regex);
 
 if (!match) {
 
 if (address.includes(':') && address.includes('#')) {
 
 const parts = address.split(':');
 
 address = parts[0];
 
 const subParts = parts[1].split('#');
 
 port = subParts[0];
 
 addressid = subParts[1];
 
 } else if (address.includes(':')) {
 
 const parts = address.split(':');
 
 address = parts[0];
 
 port = parts[1];
 
 } else if (address.includes('#')) {
 
 const parts = address.split('#');
 
 address = parts[0];
 
 addressid = parts[1];
 
 }
 
 
 
 if (addressid.includes(':')) {
 
 addressid = addressid.split(':')[0];
 
 }
 
 } else {
 
 address = match[1];
 
 port = match[2] || port;
 
 addressid = match[3] || address;
 
 }
 
 
 
 const httpPorts = ["8080","8880","2052","2082","2086","2095"];
 
 if (!isValidIPv4(address) && port == "-1") {
 
 for (let httpPort of httpPorts) {
 
 if (address.includes(httpPort)) {
 
 port = httpPort;
 
 break;
 
 }
 
 }
 
 }
 
 if (port == "-1") port = "80";
 
 
 
 let 伪装域名 = host ;
 
 let 最终路径 = path ;
 
 let 节点备注 = '';
 
 const 协议类型 = atob(啥啥啥_写的这是啥啊);
 
 
 
 const 维列斯Link = `${协议类型}://${UUID}@${address}:${port + atob('P2VuY3J5cHRpb249bm9uZSZzZWN1cml0eT0mdHlwZT13cyZob3N0PQ==') + 伪装域名}&path=${encodeURIComponent(最终路径)}#${encodeURIComponent(addressid + 节点备注)}`;
 
 
 
 return 维列斯Link;
 
 
 
 }).join('\n');
 
 
 
 }
 
 
 
 // 使用Set对象去重
 
 const uniqueAddresses = [...new Set(addresses)];
 
 
 
 const responseBody = uniqueAddresses.map(address => {
 
 let port = "-1";
 
 let addressid = address;
 
 
 
 const match = addressid.match(regex);
 
 if (!match) {
 
 if (address.includes(':') && address.includes('#')) {
 
 const parts = address.split(':');
 
 address = parts[0];
 
 const subParts = parts[1].split('#');
 
 port = subParts[0];
 
 addressid = subParts[1];
 
 } else if (address.includes(':')) {
 
 const parts = address.split(':');
 
 address = parts[0];
 
 port = parts[1];
 
 } else if (address.includes('#')) {
 
 const parts = address.split('#');
 
 address = parts[0];
 
 addressid = parts[1];
 
 }
 
 
 
 if (addressid.includes(':')) {
 
 addressid = addressid.split(':')[0];
 
 }
 
 } else {
 
 address = match[1];
 
 port = match[2] || port;
 
 addressid = match[3] || address;
 
 }
 
 
 
 if (!isValidIPv4(address) && port == "-1") {
 
 for (let httpsPort of httpsPorts) {
 
 if (address.includes(httpsPort)) {
 
 port = httpsPort;
 
 break;
 
 }
 
 }
 
 }
 
 if (port == "-1") port = "443";
 
 
 
 let 伪装域名 = host ;
 
 let 最终路径 = path ;
 
 let 节点备注 = '';
 
 const matchingProxyIP = proxyIPPool.find(proxyIP => proxyIP.includes(address));
 
 if (matchingProxyIP) 最终路径 += `&proxyip=${matchingProxyIP}`;
 
 
 
 if(proxyhosts.length > 0 && (伪装域名.includes('.workers.dev'))) {
 
 最终路径 = `/${伪装域名}${最终路径}`;
 
 伪装域名 = proxyhosts[Math.floor(Math.random() * proxyhosts.length)];
 
 节点备注 = ` 已启用临时域名中转服务,请尽快绑定自定义域!`;
 
 }
 
 
 
 const 协议类型 = atob(啥啥啥_写的这是啥啊);
 
 const 维列斯Link = `${协议类型}://${UUID}@${address}:${port + atob('P2VuY3J5cHRpb249bm9uZSZzZWN1cml0eT10bHMmc25pPQ==') + 伪装域名}&fp=random&type=ws&host=${伪装域名}&path=${encodeURIComponent(最终路径)}#${encodeURIComponent(addressid + 节点备注)}`;
 
 
 
 return 维列斯Link;
 
 }).join('\n');
 
 
 
 let base64Response = responseBody; // 重新进行 Base64 编码
 
 if(noTLS == 'true') base64Response += `\n${notlsresponseBody}`;
 
 return btoa(base64Response);
 
 }
 
 
 
 async function 整理(内容) {
 
 // 将制表符、双引号、单引号和换行符都替换为逗号
 
 // 然后将连续的多个逗号替换为单个逗号
 
 var 替换后的内容 = 内容.replace(/[  |"'\r\n]+/g, ',').replace(/,+/g, ',');
 
 
 
 // 删除开头和结尾的逗号(如果有的话)
 
 if (替换后的内容.charAt(0) == ',') 替换后的内容 = 替换后的内容.slice(1);
 
 if (替换后的内容.charAt(替换后的内容.length - 1) == ',') 替换后的内容 = 替换后的内容.slice(0, 替换后的内容.length - 1);
 
 
 
 // 使用逗号分割字符串,得到地址数组
 
 const 地址数组 = 替换后的内容.split(',');
 
 
 
 return 地址数组;
 
 }
 
 
 
 async function sendMessage(type, ip, add_data = "") {
 
 if (!BotToken || !ChatID) return;
 
 
 
 try {
 
 let msg = "";
 
 const response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`);
 
 if (response.ok) {
 
 const ipInfo = await response.json();
 
 msg = `${type}\nIP: ${ip}\n国家: ${ipInfo.country}\n<tg-spoiler>城市: ${ipInfo.city}\n组织: ${ipInfo.org}\nASN: ${ipInfo.as}\n${add_data}`;
 
 } else {
 
 msg = `${type}\nIP: ${ip}\n<tg-spoiler>${add_data}`;
 
 }
 
 
 
 const url = `https://api.telegram.org/bot${BotToken}/sendMessage?chat_id=${ChatID}&parse_mode=HTML&text=${encodeURIComponent(msg)}`;
 
 return fetch(url, {
 
 method: 'GET',
 
 headers: {
 
 'Accept': 'text/html,application/xhtml+xml,application/xml;',
 
 'Accept-Encoding': 'gzip, deflate, br',
 
 'User-Agent': 'Mozilla/5.0 Chrome/90.0.4430.72'
 
 }
 
 });
 
 } catch (error) {
 
 console.error('Error sending message:', error);
 
 }
 
 }
 
 
 
 function isValidIPv4(address) {
 
 const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
 
 return ipv4Regex.test(address);
 
 }
 
 
 
 function 生成动态UUID(密钥) {
 
 const 时区偏移 = 8; // 北京时间相对于UTC的时区偏移+8小时
 
 const 起始日期 = new Date(2007, 6, 7, 更新时间, 0, 0); // 固定起始日期为2007年7月7日的凌晨3点
 
 const 一周的毫秒数 = 1000 * 60 * 60 * 24 * 有效时间;
 
 
 
 function 获取当前周数() {
 
 const 现在 = new Date();
 
 const 调整后的现在 = new Date(现在.getTime() + 时区偏移 * 60 * 60 * 1000);
 
 const 时间差 = Number(调整后的现在) - Number(起始日期);
 
 return Math.ceil(时间差 / 一周的毫秒数);
 
 }
 
 
 
 function 生成UUID(基础字符串) {
 
 const 哈希缓冲区 = new TextEncoder().encode(基础字符串);
 
 return crypto.subtle.digest('SHA-256', 哈希缓冲区).then((哈希) => {
 
 const 哈希数组 = Array.from(new Uint8Array(哈希));
 
 const 十六进制哈希 = 哈希数组.map(b => b.toString(16).padStart(2, '0')).join('');
 
 return `${十六进制哈希.substr(0, 8)}-${十六进制哈希.substr(8, 4)}-4${十六进制哈希.substr(13, 3)}-${(parseInt(十六进制哈希.substr(16, 2), 16) & 0x3f | 0x80).toString(16)}${十六进制哈希.substr(18, 2)}-${十六进制哈希.substr(20, 12)}`;
 
 });
 
 }
 
 
 
 const 当前周数 = 获取当前周数(); // 获取当前周数
 
 const 结束时间 = new Date(起始日期.getTime() + 当前周数 * 一周的毫秒数);
 
 
 
 // 生成两个 UUID
 
 const 当前UUIDPromise = 生成UUID(密钥 + 当前周数);
 
 const 上一个UUIDPromise = 生成UUID(密钥 + (当前周数 - 1));
 
 
 
 // 格式化到期时间
 
 const 到期时间UTC = new Date(结束时间.getTime() - 时区偏移 * 60 * 60 * 1000); // UTC时间
 
 const 到期时间字符串 = `到期时间(UTC): ${到期时间UTC.toISOString().slice(0, 19).replace('T', ' ')} (UTC+8): ${结束时间.toISOString().slice(0, 19).replace('T', ' ')}\n`;
 
 
 
 return Promise.all([当前UUIDPromise, 上一个UUIDPromise, 到期时间字符串]);
 
 }
 
 |