xray.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. const Protocols = {
  2. VMESS: 'vmess',
  3. VLESS: 'vless',
  4. TROJAN: 'trojan',
  5. SHADOWSOCKS: 'shadowsocks',
  6. DOKODEMO: 'dokodemo-door',
  7. MTPROTO: 'mtproto',
  8. SOCKS: 'socks',
  9. HTTP: 'http',
  10. };
  11. const VmessMethods = {
  12. AES_128_GCM: 'aes-128-gcm',
  13. CHACHA20_POLY1305: 'chacha20-poly1305',
  14. AUTO: 'auto',
  15. NONE: 'none',
  16. };
  17. const SSMethods = {
  18. // AES_256_CFB: 'aes-256-cfb',
  19. // AES_128_CFB: 'aes-128-cfb',
  20. // CHACHA20: 'chacha20',
  21. // CHACHA20_IETF: 'chacha20-ietf',
  22. CHACHA20_POLY1305: 'chacha20-poly1305',
  23. AES_256_GCM: 'aes-256-gcm',
  24. AES_128_GCM: 'aes-128-gcm',
  25. };
  26. const RULE_IP = {
  27. PRIVATE: 'geoip:private',
  28. CN: 'geoip:cn',
  29. };
  30. const RULE_DOMAIN = {
  31. ADS: 'geosite:category-ads',
  32. ADS_ALL: 'geosite:category-ads-all',
  33. CN: 'geosite:cn',
  34. GOOGLE: 'geosite:google',
  35. FACEBOOK: 'geosite:facebook',
  36. SPEEDTEST: 'geosite:speedtest',
  37. };
  38. const FLOW_CONTROL = {
  39. ORIGIN: "xtls-rprx-origin",
  40. DIRECT: "xtls-rprx-direct",
  41. };
  42. Object.freeze(Protocols);
  43. Object.freeze(VmessMethods);
  44. Object.freeze(SSMethods);
  45. Object.freeze(RULE_IP);
  46. Object.freeze(RULE_DOMAIN);
  47. Object.freeze(FLOW_CONTROL);
  48. class XrayCommonClass {
  49. static toJsonArray(arr) {
  50. return arr.map(obj => obj.toJson());
  51. }
  52. static fromJson() {
  53. return new XrayCommonClass();
  54. }
  55. toJson() {
  56. return this;
  57. }
  58. toString(format=true) {
  59. return format ? JSON.stringify(this.toJson(), null, 2) : JSON.stringify(this.toJson());
  60. }
  61. static toHeaders(v2Headers) {
  62. let newHeaders = [];
  63. if (v2Headers) {
  64. Object.keys(v2Headers).forEach(key => {
  65. let values = v2Headers[key];
  66. if (typeof(values) === 'string') {
  67. newHeaders.push({ name: key, value: values });
  68. } else {
  69. for (let i = 0; i < values.length; ++i) {
  70. newHeaders.push({ name: key, value: values[i] });
  71. }
  72. }
  73. });
  74. }
  75. return newHeaders;
  76. }
  77. static toV2Headers(headers, arr=true) {
  78. let v2Headers = {};
  79. for (let i = 0; i < headers.length; ++i) {
  80. let name = headers[i].name;
  81. let value = headers[i].value;
  82. if (ObjectUtil.isEmpty(name) || ObjectUtil.isEmpty(value)) {
  83. continue;
  84. }
  85. if (!(name in v2Headers)) {
  86. v2Headers[name] = arr ? [value] : value;
  87. } else {
  88. if (arr) {
  89. v2Headers[name].push(value);
  90. } else {
  91. v2Headers[name] = value;
  92. }
  93. }
  94. }
  95. return v2Headers;
  96. }
  97. }
  98. class TcpStreamSettings extends XrayCommonClass {
  99. constructor(acceptProxyProtocol=false,
  100. type='none',
  101. request=new TcpStreamSettings.TcpRequest(),
  102. response=new TcpStreamSettings.TcpResponse(),
  103. ) {
  104. super();
  105. this.acceptProxyProtocol = acceptProxyProtocol;
  106. this.type = type;
  107. this.request = request;
  108. this.response = response;
  109. }
  110. static fromJson(json={}) {
  111. let header = json.header;
  112. if (!header) {
  113. header = {};
  114. }
  115. return new TcpStreamSettings(json.acceptProxyProtocol,
  116. header.type,
  117. TcpStreamSettings.TcpRequest.fromJson(header.request),
  118. TcpStreamSettings.TcpResponse.fromJson(header.response),
  119. );
  120. }
  121. toJson() {
  122. return {
  123. acceptProxyProtocol: this.acceptProxyProtocol,
  124. header: {
  125. type: this.type,
  126. request: this.type === 'http' ? this.request.toJson() : undefined,
  127. response: this.type === 'http' ? this.response.toJson() : undefined,
  128. },
  129. };
  130. }
  131. }
  132. TcpStreamSettings.TcpRequest = class extends XrayCommonClass {
  133. constructor(version='1.1',
  134. method='GET',
  135. path=['/'],
  136. headers=[],
  137. ) {
  138. super();
  139. this.version = version;
  140. this.method = method;
  141. this.path = path.length === 0 ? ['/'] : path;
  142. this.headers = headers;
  143. }
  144. addPath(path) {
  145. this.path.push(path);
  146. }
  147. removePath(index) {
  148. this.path.splice(index, 1);
  149. }
  150. addHeader(name, value) {
  151. this.headers.push({ name: name, value: value });
  152. }
  153. getHeader(name) {
  154. for (const header of this.headers) {
  155. if (header.name.toLowerCase() === name.toLowerCase()) {
  156. return header.value;
  157. }
  158. }
  159. return null;
  160. }
  161. removeHeader(index) {
  162. this.headers.splice(index, 1);
  163. }
  164. static fromJson(json={}) {
  165. return new TcpStreamSettings.TcpRequest(
  166. json.version,
  167. json.method,
  168. json.path,
  169. XrayCommonClass.toHeaders(json.headers),
  170. );
  171. }
  172. toJson() {
  173. return {
  174. method: this.method,
  175. path: ObjectUtil.clone(this.path),
  176. headers: XrayCommonClass.toV2Headers(this.headers),
  177. };
  178. }
  179. };
  180. TcpStreamSettings.TcpResponse = class extends XrayCommonClass {
  181. constructor(version='1.1',
  182. status='200',
  183. reason='OK',
  184. headers=[],
  185. ) {
  186. super();
  187. this.version = version;
  188. this.status = status;
  189. this.reason = reason;
  190. this.headers = headers;
  191. }
  192. addHeader(name, value) {
  193. this.headers.push({ name: name, value: value });
  194. }
  195. removeHeader(index) {
  196. this.headers.splice(index, 1);
  197. }
  198. static fromJson(json={}) {
  199. return new TcpStreamSettings.TcpResponse(
  200. json.version,
  201. json.status,
  202. json.reason,
  203. XrayCommonClass.toHeaders(json.headers),
  204. );
  205. }
  206. toJson() {
  207. return {
  208. version: this.version,
  209. status: this.status,
  210. reason: this.reason,
  211. headers: XrayCommonClass.toV2Headers(this.headers),
  212. };
  213. }
  214. };
  215. class KcpStreamSettings extends XrayCommonClass {
  216. constructor(mtu=1350, tti=20,
  217. uplinkCapacity=5,
  218. downlinkCapacity=20,
  219. congestion=false,
  220. readBufferSize=2,
  221. writeBufferSize=2,
  222. type='none',
  223. seed=RandomUtil.randomSeq(10),
  224. ) {
  225. super();
  226. this.mtu = mtu;
  227. this.tti = tti;
  228. this.upCap = uplinkCapacity;
  229. this.downCap = downlinkCapacity;
  230. this.congestion = congestion;
  231. this.readBuffer = readBufferSize;
  232. this.writeBuffer = writeBufferSize;
  233. this.type = type;
  234. this.seed = seed;
  235. }
  236. static fromJson(json={}) {
  237. return new KcpStreamSettings(
  238. json.mtu,
  239. json.tti,
  240. json.uplinkCapacity,
  241. json.downlinkCapacity,
  242. json.congestion,
  243. json.readBufferSize,
  244. json.writeBufferSize,
  245. ObjectUtil.isEmpty(json.header) ? 'none' : json.header.type,
  246. json.seed,
  247. );
  248. }
  249. toJson() {
  250. return {
  251. mtu: this.mtu,
  252. tti: this.tti,
  253. uplinkCapacity: this.upCap,
  254. downlinkCapacity: this.downCap,
  255. congestion: this.congestion,
  256. readBufferSize: this.readBuffer,
  257. writeBufferSize: this.writeBuffer,
  258. header: {
  259. type: this.type,
  260. },
  261. seed: this.seed,
  262. };
  263. }
  264. }
  265. class WsStreamSettings extends XrayCommonClass {
  266. constructor(acceptProxyProtocol=false, path='/', headers=[]) {
  267. super();
  268. this.acceptProxyProtocol = acceptProxyProtocol;
  269. this.path = path;
  270. this.headers = headers;
  271. }
  272. addHeader(name, value) {
  273. this.headers.push({ name: name, value: value });
  274. }
  275. getHeader(name) {
  276. for (const header of this.headers) {
  277. if (header.name.toLowerCase() === name.toLowerCase()) {
  278. return header.value;
  279. }
  280. }
  281. return null;
  282. }
  283. removeHeader(index) {
  284. this.headers.splice(index, 1);
  285. }
  286. static fromJson(json={}) {
  287. return new WsStreamSettings(
  288. json.acceptProxyProtocol,
  289. json.path,
  290. XrayCommonClass.toHeaders(json.headers),
  291. );
  292. }
  293. toJson() {
  294. return {
  295. acceptProxyProtocol: this.acceptProxyProtocol,
  296. path: this.path,
  297. headers: XrayCommonClass.toV2Headers(this.headers, false),
  298. };
  299. }
  300. }
  301. class HttpStreamSettings extends XrayCommonClass {
  302. constructor(path='/', host=['']) {
  303. super();
  304. this.path = path;
  305. this.host = host.length === 0 ? [''] : host;
  306. }
  307. addHost(host) {
  308. this.host.push(host);
  309. }
  310. removeHost(index) {
  311. this.host.splice(index, 1);
  312. }
  313. static fromJson(json={}) {
  314. return new HttpStreamSettings(json.path, json.host);
  315. }
  316. toJson() {
  317. let host = [];
  318. for (let i = 0; i < this.host.length; ++i) {
  319. if (!ObjectUtil.isEmpty(this.host[i])) {
  320. host.push(this.host[i]);
  321. }
  322. }
  323. return {
  324. path: this.path,
  325. host: host,
  326. }
  327. }
  328. }
  329. class QuicStreamSettings extends XrayCommonClass {
  330. constructor(security=VmessMethods.NONE,
  331. key='', type='none') {
  332. super();
  333. this.security = security;
  334. this.key = key;
  335. this.type = type;
  336. }
  337. static fromJson(json={}) {
  338. return new QuicStreamSettings(
  339. json.security,
  340. json.key,
  341. json.header ? json.header.type : 'none',
  342. );
  343. }
  344. toJson() {
  345. return {
  346. security: this.security,
  347. key: this.key,
  348. header: {
  349. type: this.type,
  350. }
  351. }
  352. }
  353. }
  354. class GrpcStreamSettings extends XrayCommonClass {
  355. constructor(serviceName="") {
  356. super();
  357. this.serviceName = serviceName;
  358. }
  359. static fromJson(json={}) {
  360. return new GrpcStreamSettings(json.serviceName);
  361. }
  362. toJson() {
  363. return {
  364. serviceName: this.serviceName,
  365. }
  366. }
  367. }
  368. class TlsStreamSettings extends XrayCommonClass {
  369. constructor(serverName='',
  370. certificates=[new TlsStreamSettings.Cert()], alpn=[]) {
  371. super();
  372. this.server = serverName;
  373. this.certs = certificates;
  374. this.alpn = alpn;
  375. }
  376. addCert(cert) {
  377. this.certs.push(cert);
  378. }
  379. removeCert(index) {
  380. this.certs.splice(index, 1);
  381. }
  382. static fromJson(json={}) {
  383. let certs;
  384. if (!ObjectUtil.isEmpty(json.certificates)) {
  385. certs = json.certificates.map(cert => TlsStreamSettings.Cert.fromJson(cert));
  386. }
  387. return new TlsStreamSettings(
  388. json.serverName,
  389. certs,
  390. json.alpn
  391. );
  392. }
  393. toJson() {
  394. return {
  395. serverName: this.server,
  396. certificates: TlsStreamSettings.toJsonArray(this.certs),
  397. alpn: this.alpn
  398. };
  399. }
  400. }
  401. TlsStreamSettings.Cert = class extends XrayCommonClass {
  402. constructor(useFile=true, certificateFile='', keyFile='', certificate='', key='') {
  403. super();
  404. this.useFile = useFile;
  405. this.certFile = certificateFile;
  406. this.keyFile = keyFile;
  407. this.cert = certificate instanceof Array ? certificate.join('\n') : certificate;
  408. this.key = key instanceof Array ? key.join('\n') : key;
  409. }
  410. static fromJson(json={}) {
  411. if ('certificateFile' in json && 'keyFile' in json) {
  412. return new TlsStreamSettings.Cert(
  413. true,
  414. json.certificateFile,
  415. json.keyFile,
  416. );
  417. } else {
  418. return new TlsStreamSettings.Cert(
  419. false, '', '',
  420. json.certificate.join('\n'),
  421. json.key.join('\n'),
  422. );
  423. }
  424. }
  425. toJson() {
  426. if (this.useFile) {
  427. return {
  428. certificateFile: this.certFile,
  429. keyFile: this.keyFile,
  430. };
  431. } else {
  432. return {
  433. certificate: this.cert.split('\n'),
  434. key: this.key.split('\n'),
  435. };
  436. }
  437. }
  438. };
  439. class StreamSettings extends XrayCommonClass {
  440. constructor(network='tcp',
  441. security='none',
  442. tlsSettings=new TlsStreamSettings(),
  443. tcpSettings=new TcpStreamSettings(),
  444. kcpSettings=new KcpStreamSettings(),
  445. wsSettings=new WsStreamSettings(),
  446. httpSettings=new HttpStreamSettings(),
  447. quicSettings=new QuicStreamSettings(),
  448. grpcSettings=new GrpcStreamSettings(),
  449. ) {
  450. super();
  451. this.network = network;
  452. this.security = security;
  453. this.tls = tlsSettings;
  454. this.tcp = tcpSettings;
  455. this.kcp = kcpSettings;
  456. this.ws = wsSettings;
  457. this.http = httpSettings;
  458. this.quic = quicSettings;
  459. this.grpc = grpcSettings;
  460. }
  461. get isTls() {
  462. return this.security === 'tls';
  463. }
  464. set isTls(isTls) {
  465. if (isTls) {
  466. this.security = 'tls';
  467. } else {
  468. this.security = 'none';
  469. }
  470. }
  471. get isXTls() {
  472. return this.security === "xtls";
  473. }
  474. set isXTls(isXTls) {
  475. if (isXTls) {
  476. this.security = 'xtls';
  477. } else {
  478. this.security = 'none';
  479. }
  480. }
  481. static fromJson(json={}) {
  482. let tls;
  483. if (json.security === "xtls") {
  484. tls = TlsStreamSettings.fromJson(json.xtlsSettings);
  485. } else {
  486. tls = TlsStreamSettings.fromJson(json.tlsSettings);
  487. }
  488. return new StreamSettings(
  489. json.network,
  490. json.security,
  491. tls,
  492. TcpStreamSettings.fromJson(json.tcpSettings),
  493. KcpStreamSettings.fromJson(json.kcpSettings),
  494. WsStreamSettings.fromJson(json.wsSettings),
  495. HttpStreamSettings.fromJson(json.httpSettings),
  496. QuicStreamSettings.fromJson(json.quicSettings),
  497. GrpcStreamSettings.fromJson(json.grpcSettings),
  498. );
  499. }
  500. toJson() {
  501. const network = this.network;
  502. return {
  503. network: network,
  504. security: this.security,
  505. tlsSettings: this.isTls ? this.tls.toJson() : undefined,
  506. xtlsSettings: this.isXTls ? this.tls.toJson() : undefined,
  507. tcpSettings: network === 'tcp' ? this.tcp.toJson() : undefined,
  508. kcpSettings: network === 'kcp' ? this.kcp.toJson() : undefined,
  509. wsSettings: network === 'ws' ? this.ws.toJson() : undefined,
  510. httpSettings: network === 'http' ? this.http.toJson() : undefined,
  511. quicSettings: network === 'quic' ? this.quic.toJson() : undefined,
  512. grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
  513. };
  514. }
  515. }
  516. class Sniffing extends XrayCommonClass {
  517. constructor(enabled=true, destOverride=['http', 'tls']) {
  518. super();
  519. this.enabled = enabled;
  520. this.destOverride = destOverride;
  521. }
  522. static fromJson(json={}) {
  523. let destOverride = ObjectUtil.clone(json.destOverride);
  524. if (!ObjectUtil.isEmpty(destOverride) && !ObjectUtil.isArrEmpty(destOverride)) {
  525. if (ObjectUtil.isEmpty(destOverride[0])) {
  526. destOverride = ['http', 'tls'];
  527. }
  528. }
  529. return new Sniffing(
  530. !!json.enabled,
  531. destOverride,
  532. );
  533. }
  534. }
  535. class Inbound extends XrayCommonClass {
  536. constructor(port=RandomUtil.randomIntRange(10000, 60000),
  537. listen='',
  538. protocol=Protocols.VMESS,
  539. settings=null,
  540. streamSettings=new StreamSettings(),
  541. tag='',
  542. sniffing=new Sniffing(),
  543. ) {
  544. super();
  545. this.port = port;
  546. this.listen = listen;
  547. this._protocol = protocol;
  548. this.settings = ObjectUtil.isEmpty(settings) ? Inbound.Settings.getSettings(protocol) : settings;
  549. this.stream = streamSettings;
  550. this.tag = tag;
  551. this.sniffing = sniffing;
  552. }
  553. get protocol() {
  554. return this._protocol;
  555. }
  556. set protocol(protocol) {
  557. this._protocol = protocol;
  558. this.settings = Inbound.Settings.getSettings(protocol);
  559. if (protocol === Protocols.TROJAN) {
  560. this.tls = true;
  561. }
  562. }
  563. get tls() {
  564. return this.stream.security === 'tls';
  565. }
  566. set tls(isTls) {
  567. if (isTls) {
  568. this.stream.security = 'tls';
  569. } else {
  570. this.stream.security = 'none';
  571. }
  572. }
  573. get xtls() {
  574. return this.stream.security === 'xtls';
  575. }
  576. set xtls(isXTls) {
  577. if (isXTls) {
  578. this.stream.security = 'xtls';
  579. } else {
  580. this.stream.security = 'none';
  581. }
  582. }
  583. get network() {
  584. return this.stream.network;
  585. }
  586. set network(network) {
  587. this.stream.network = network;
  588. }
  589. get isTcp() {
  590. return this.network === "tcp";
  591. }
  592. get isWs() {
  593. return this.network === "ws";
  594. }
  595. get isKcp() {
  596. return this.network === "kcp";
  597. }
  598. get isQuic() {
  599. return this.network === "quic"
  600. }
  601. get isGrpc() {
  602. return this.network === "grpc";
  603. }
  604. get isH2() {
  605. return this.network === "http";
  606. }
  607. // VMess & VLess
  608. get uuid() {
  609. switch (this.protocol) {
  610. case Protocols.VMESS:
  611. return this.settings.vmesses[0].id;
  612. case Protocols.VLESS:
  613. return this.settings.vlesses[0].id;
  614. default:
  615. return "";
  616. }
  617. }
  618. // VLess & Trojan
  619. get flow() {
  620. switch (this.protocol) {
  621. case Protocols.VLESS:
  622. return this.settings.vlesses[0].flow;
  623. case Protocols.TROJAN:
  624. return this.settings.clients[0].flow;
  625. default:
  626. return "";
  627. }
  628. }
  629. // VMess
  630. get alterId() {
  631. switch (this.protocol) {
  632. case Protocols.VMESS:
  633. return this.settings.vmesses[0].alterId;
  634. default:
  635. return "";
  636. }
  637. }
  638. // Socks & HTTP
  639. get username() {
  640. switch (this.protocol) {
  641. case Protocols.SOCKS:
  642. case Protocols.HTTP:
  643. return this.settings.accounts[0].user;
  644. default:
  645. return "";
  646. }
  647. }
  648. // Trojan & Shadowsocks & Socks & HTTP
  649. get password() {
  650. switch (this.protocol) {
  651. case Protocols.TROJAN:
  652. return this.settings.clients[0].password;
  653. case Protocols.SHADOWSOCKS:
  654. return this.settings.password;
  655. case Protocols.SOCKS:
  656. case Protocols.HTTP:
  657. return this.settings.accounts[0].pass;
  658. default:
  659. return "";
  660. }
  661. }
  662. // Shadowsocks
  663. get method() {
  664. switch (this.protocol) {
  665. case Protocols.SHADOWSOCKS:
  666. return this.settings.method;
  667. default:
  668. return "";
  669. }
  670. }
  671. get serverName() {
  672. if (this.stream.isTls || this.stream.isXTls) {
  673. return this.stream.tls.server;
  674. }
  675. return "";
  676. }
  677. get host() {
  678. if (this.isTcp) {
  679. return this.stream.tcp.request.getHeader("Host");
  680. } else if (this.isWs) {
  681. return this.stream.ws.getHeader("Host");
  682. } else if (this.isH2) {
  683. return this.stream.http.host[0];
  684. }
  685. return null;
  686. }
  687. get path() {
  688. if (this.isTcp) {
  689. return this.stream.tcp.request.path[0];
  690. } else if (this.isWs) {
  691. return this.stream.ws.path;
  692. } else if (this.isH2) {
  693. return this.stream.http.path[0];
  694. }
  695. return null;
  696. }
  697. get quicSecurity() {
  698. return this.stream.quic.security;
  699. }
  700. get quicKey() {
  701. return this.stream.quic.key;
  702. }
  703. get quicType() {
  704. return this.stream.quic.type;
  705. }
  706. get kcpType() {
  707. return this.stream.kcp.type;
  708. }
  709. get kcpSeed() {
  710. return this.stream.kcp.seed;
  711. }
  712. get serviceName() {
  713. return this.stream.grpc.serviceName;
  714. }
  715. canEnableTls() {
  716. switch (this.protocol) {
  717. case Protocols.VMESS:
  718. case Protocols.VLESS:
  719. case Protocols.TROJAN:
  720. case Protocols.SHADOWSOCKS:
  721. break;
  722. default:
  723. return false;
  724. }
  725. switch (this.network) {
  726. case "tcp":
  727. case "ws":
  728. case "http":
  729. case "quic":
  730. case "grpc":
  731. return true;
  732. default:
  733. return false;
  734. }
  735. }
  736. canSetTls() {
  737. return this.canEnableTls();
  738. }
  739. canEnableXTls() {
  740. switch (this.protocol) {
  741. case Protocols.VLESS:
  742. case Protocols.TROJAN:
  743. break;
  744. default:
  745. return false;
  746. }
  747. return this.network === "tcp";
  748. }
  749. canEnableStream() {
  750. switch (this.protocol) {
  751. case Protocols.VMESS:
  752. case Protocols.VLESS:
  753. case Protocols.SHADOWSOCKS:
  754. return true;
  755. default:
  756. return false;
  757. }
  758. }
  759. canSniffing() {
  760. switch (this.protocol) {
  761. case Protocols.VMESS:
  762. case Protocols.VLESS:
  763. case Protocols.TROJAN:
  764. case Protocols.SHADOWSOCKS:
  765. return true;
  766. default:
  767. return false;
  768. }
  769. }
  770. reset() {
  771. this.port = RandomUtil.randomIntRange(10000, 60000);
  772. this.listen = '';
  773. this.protocol = Protocols.VMESS;
  774. this.settings = Inbound.Settings.getSettings(Protocols.VMESS);
  775. this.stream = new StreamSettings();
  776. this.tag = '';
  777. this.sniffing = new Sniffing();
  778. }
  779. genVmessLink(address='', remark='') {
  780. if (this.protocol !== Protocols.VMESS) {
  781. return '';
  782. }
  783. let network = this.stream.network;
  784. let type = 'none';
  785. let host = '';
  786. let path = '';
  787. if (network === 'tcp') {
  788. let tcp = this.stream.tcp;
  789. type = tcp.type;
  790. if (type === 'http') {
  791. let request = tcp.request;
  792. path = request.path.join(',');
  793. let index = request.headers.findIndex(header => header.name.toLowerCase() === 'host');
  794. if (index >= 0) {
  795. host = request.headers[index].value;
  796. }
  797. }
  798. } else if (network === 'kcp') {
  799. let kcp = this.stream.kcp;
  800. type = kcp.type;
  801. path = kcp.seed;
  802. } else if (network === 'ws') {
  803. let ws = this.stream.ws;
  804. path = ws.path;
  805. let index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
  806. if (index >= 0) {
  807. host = ws.headers[index].value;
  808. }
  809. } else if (network === 'http') {
  810. network = 'h2';
  811. path = this.stream.http.path;
  812. host = this.stream.http.host.join(',');
  813. } else if (network === 'quic') {
  814. type = this.stream.quic.type;
  815. host = this.stream.quic.security;
  816. path = this.stream.quic.key;
  817. } else if (network === 'grpc') {
  818. path = this.stream.grpc.serviceName;
  819. }
  820. if (this.stream.security === 'tls') {
  821. if (!ObjectUtil.isEmpty(this.stream.tls.server)) {
  822. address = this.stream.tls.server;
  823. }
  824. }
  825. let obj = {
  826. v: '2',
  827. ps: remark,
  828. add: address,
  829. port: this.port,
  830. id: this.settings.vmesses[0].id,
  831. aid: this.settings.vmesses[0].alterId,
  832. net: network,
  833. type: type,
  834. host: host,
  835. path: path,
  836. tls: this.stream.security,
  837. };
  838. return 'vmess://' + base64(JSON.stringify(obj, null, 2));
  839. }
  840. genVLESSLink(address = '', remark='') {
  841. const settings = this.settings;
  842. const uuid = settings.vlesses[0].id;
  843. const port = this.port;
  844. const type = this.stream.network;
  845. const params = new Map();
  846. params.set("type", this.stream.network);
  847. if (this.xtls) {
  848. params.set("security", "xtls");
  849. } else {
  850. params.set("security", this.stream.security);
  851. }
  852. switch (type) {
  853. case "tcp":
  854. const tcp = this.stream.tcp;
  855. if (tcp.type === 'http') {
  856. const request = tcp.request;
  857. params.set("path", request.path.join(','));
  858. const index = request.headers.findIndex(header => header.name.toLowerCase() === 'host');
  859. if (index >= 0) {
  860. const host = request.headers[index].value;
  861. params.set("host", host);
  862. }
  863. }
  864. break;
  865. case "kcp":
  866. const kcp = this.stream.kcp;
  867. params.set("headerType", kcp.type);
  868. params.set("seed", kcp.seed);
  869. break;
  870. case "ws":
  871. const ws = this.stream.ws;
  872. params.set("path", ws.path);
  873. const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
  874. if (index >= 0) {
  875. const host = ws.headers[index].value;
  876. params.set("host", host);
  877. }
  878. break;
  879. case "http":
  880. const http = this.stream.http;
  881. params.set("path", http.path);
  882. params.set("host", http.host);
  883. break;
  884. case "quic":
  885. const quic = this.stream.quic;
  886. params.set("quicSecurity", quic.security);
  887. params.set("key", quic.key);
  888. params.set("headerType", quic.type);
  889. break;
  890. case "grpc":
  891. const grpc = this.stream.grpc;
  892. params.set("serviceName", grpc.serviceName);
  893. break;
  894. }
  895. if (this.stream.security === 'tls') {
  896. if (!ObjectUtil.isEmpty(this.stream.tls.server)) {
  897. address = this.stream.tls.server;
  898. params.set("sni", address);
  899. }
  900. }
  901. if (this.xtls) {
  902. params.set("flow", this.settings.vlesses[0].flow);
  903. }
  904. const link = `vless://${uuid}@${address}:${port}`;
  905. const url = new URL(link);
  906. for (const [key, value] of params) {
  907. url.searchParams.set(key, value)
  908. }
  909. url.hash = encodeURIComponent(remark);
  910. return url.toString();
  911. }
  912. genSSLink(address='', remark='') {
  913. let settings = this.settings;
  914. const server = this.stream.tls.server;
  915. if (!ObjectUtil.isEmpty(server)) {
  916. address = server;
  917. }
  918. return 'ss://' + safeBase64(settings.method + ':' + settings.password + '@' + address + ':' + this.port)
  919. + '#' + encodeURIComponent(remark);
  920. }
  921. genTrojanLink(address='', remark='') {
  922. let settings = this.settings;
  923. return `trojan://${settings.clients[0].password}@${address}:${this.port}#${encodeURIComponent(remark)}`;
  924. }
  925. genLink(address='', remark='') {
  926. switch (this.protocol) {
  927. case Protocols.VMESS: return this.genVmessLink(address, remark);
  928. case Protocols.VLESS: return this.genVLESSLink(address, remark);
  929. case Protocols.SHADOWSOCKS: return this.genSSLink(address, remark);
  930. case Protocols.TROJAN: return this.genTrojanLink(address, remark);
  931. default: return '';
  932. }
  933. }
  934. static fromJson(json={}) {
  935. return new Inbound(
  936. json.port,
  937. json.listen,
  938. json.protocol,
  939. Inbound.Settings.fromJson(json.protocol, json.settings),
  940. StreamSettings.fromJson(json.streamSettings),
  941. json.tag,
  942. Sniffing.fromJson(json.sniffing),
  943. )
  944. }
  945. toJson() {
  946. let streamSettings;
  947. if (this.canEnableStream() || this.protocol === Protocols.TROJAN) {
  948. streamSettings = this.stream.toJson();
  949. }
  950. return {
  951. port: this.port,
  952. listen: this.listen,
  953. protocol: this.protocol,
  954. settings: this.settings instanceof XrayCommonClass ? this.settings.toJson() : this.settings,
  955. streamSettings: streamSettings,
  956. tag: this.tag,
  957. sniffing: this.sniffing.toJson(),
  958. };
  959. }
  960. }
  961. Inbound.Settings = class extends XrayCommonClass {
  962. constructor(protocol) {
  963. super();
  964. this.protocol = protocol;
  965. }
  966. static getSettings(protocol) {
  967. switch (protocol) {
  968. case Protocols.VMESS: return new Inbound.VmessSettings(protocol);
  969. case Protocols.VLESS: return new Inbound.VLESSSettings(protocol);
  970. case Protocols.TROJAN: return new Inbound.TrojanSettings(protocol);
  971. case Protocols.SHADOWSOCKS: return new Inbound.ShadowsocksSettings(protocol);
  972. case Protocols.DOKODEMO: return new Inbound.DokodemoSettings(protocol);
  973. case Protocols.MTPROTO: return new Inbound.MtprotoSettings(protocol);
  974. case Protocols.SOCKS: return new Inbound.SocksSettings(protocol);
  975. case Protocols.HTTP: return new Inbound.HttpSettings(protocol);
  976. default: return null;
  977. }
  978. }
  979. static fromJson(protocol, json) {
  980. switch (protocol) {
  981. case Protocols.VMESS: return Inbound.VmessSettings.fromJson(json);
  982. case Protocols.VLESS: return Inbound.VLESSSettings.fromJson(json);
  983. case Protocols.TROJAN: return Inbound.TrojanSettings.fromJson(json);
  984. case Protocols.SHADOWSOCKS: return Inbound.ShadowsocksSettings.fromJson(json);
  985. case Protocols.DOKODEMO: return Inbound.DokodemoSettings.fromJson(json);
  986. case Protocols.MTPROTO: return Inbound.MtprotoSettings.fromJson(json);
  987. case Protocols.SOCKS: return Inbound.SocksSettings.fromJson(json);
  988. case Protocols.HTTP: return Inbound.HttpSettings.fromJson(json);
  989. default: return null;
  990. }
  991. }
  992. toJson() {
  993. return {};
  994. }
  995. };
  996. Inbound.VmessSettings = class extends Inbound.Settings {
  997. constructor(protocol,
  998. vmesses=[new Inbound.VmessSettings.Vmess()],
  999. disableInsecureEncryption=false) {
  1000. super(protocol);
  1001. this.vmesses = vmesses;
  1002. this.disableInsecure = disableInsecureEncryption;
  1003. }
  1004. indexOfVmessById(id) {
  1005. return this.vmesses.findIndex(vmess => vmess.id === id);
  1006. }
  1007. addVmess(vmess) {
  1008. if (this.indexOfVmessById(vmess.id) >= 0) {
  1009. return false;
  1010. }
  1011. this.vmesses.push(vmess);
  1012. }
  1013. delVmess(vmess) {
  1014. const i = this.indexOfVmessById(vmess.id);
  1015. if (i >= 0) {
  1016. this.vmesses.splice(i, 1);
  1017. }
  1018. }
  1019. static fromJson(json={}) {
  1020. return new Inbound.VmessSettings(
  1021. Protocols.VMESS,
  1022. json.clients.map(client => Inbound.VmessSettings.Vmess.fromJson(client)),
  1023. ObjectUtil.isEmpty(json.disableInsecureEncryption) ? false : json.disableInsecureEncryption,
  1024. );
  1025. }
  1026. toJson() {
  1027. return {
  1028. clients: Inbound.VmessSettings.toJsonArray(this.vmesses),
  1029. disableInsecureEncryption: this.disableInsecure,
  1030. };
  1031. }
  1032. };
  1033. Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
  1034. constructor(id=RandomUtil.randomUUID(), alterId=0) {
  1035. super();
  1036. this.id = id;
  1037. this.alterId = alterId;
  1038. }
  1039. static fromJson(json={}) {
  1040. return new Inbound.VmessSettings.Vmess(
  1041. json.id,
  1042. json.alterId,
  1043. );
  1044. }
  1045. };
  1046. Inbound.VLESSSettings = class extends Inbound.Settings {
  1047. constructor(protocol,
  1048. vlesses=[new Inbound.VLESSSettings.VLESS()],
  1049. decryption='none',
  1050. fallbacks=[],) {
  1051. super(protocol);
  1052. this.vlesses = vlesses;
  1053. this.decryption = decryption;
  1054. this.fallbacks = fallbacks;
  1055. }
  1056. addFallback() {
  1057. this.fallbacks.push(new Inbound.VLESSSettings.Fallback());
  1058. }
  1059. delFallback(index) {
  1060. this.fallbacks.splice(index, 1);
  1061. }
  1062. static fromJson(json={}) {
  1063. return new Inbound.VLESSSettings(
  1064. Protocols.VLESS,
  1065. json.clients.map(client => Inbound.VLESSSettings.VLESS.fromJson(client)),
  1066. json.decryption,
  1067. Inbound.VLESSSettings.Fallback.fromJson(json.fallbacks),
  1068. );
  1069. }
  1070. toJson() {
  1071. return {
  1072. clients: Inbound.VLESSSettings.toJsonArray(this.vlesses),
  1073. decryption: this.decryption,
  1074. fallbacks: Inbound.VLESSSettings.toJsonArray(this.fallbacks),
  1075. };
  1076. }
  1077. };
  1078. Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
  1079. constructor(id=RandomUtil.randomUUID(), flow=FLOW_CONTROL.DIRECT) {
  1080. super();
  1081. this.id = id;
  1082. this.flow = flow;
  1083. }
  1084. static fromJson(json={}) {
  1085. return new Inbound.VLESSSettings.VLESS(
  1086. json.id,
  1087. json.flow,
  1088. );
  1089. }
  1090. };
  1091. Inbound.VLESSSettings.Fallback = class extends XrayCommonClass {
  1092. constructor(name="", alpn='', path='', dest='', xver=0) {
  1093. super();
  1094. this.name = name;
  1095. this.alpn = alpn;
  1096. this.path = path;
  1097. this.dest = dest;
  1098. this.xver = xver;
  1099. }
  1100. toJson() {
  1101. let xver = this.xver;
  1102. if (!Number.isInteger(xver)) {
  1103. xver = 0;
  1104. }
  1105. return {
  1106. name: this.name,
  1107. alpn: this.alpn,
  1108. path: this.path,
  1109. dest: this.dest,
  1110. xver: xver,
  1111. }
  1112. }
  1113. static fromJson(json=[]) {
  1114. const fallbacks = [];
  1115. for (let fallback of json) {
  1116. fallbacks.push(new Inbound.VLESSSettings.Fallback(
  1117. fallback.name,
  1118. fallback.alpn,
  1119. fallback.path,
  1120. fallback.dest,
  1121. fallback.xver,
  1122. ))
  1123. }
  1124. return fallbacks;
  1125. }
  1126. };
  1127. Inbound.TrojanSettings = class extends Inbound.Settings {
  1128. constructor(protocol,
  1129. clients=[new Inbound.TrojanSettings.Client()],
  1130. fallbacks=[],) {
  1131. super(protocol);
  1132. this.clients = clients;
  1133. this.fallbacks = fallbacks;
  1134. }
  1135. addTrojanFallback() {
  1136. this.fallbacks.push(new Inbound.TrojanSettings.Fallback());
  1137. }
  1138. delTrojanFallback(index) {
  1139. this.fallbacks.splice(index, 1);
  1140. }
  1141. toJson() {
  1142. return {
  1143. clients: Inbound.TrojanSettings.toJsonArray(this.clients),
  1144. fallbacks: Inbound.TrojanSettings.toJsonArray(this.fallbacks),
  1145. };
  1146. }
  1147. static fromJson(json={}) {
  1148. const clients = [];
  1149. for (const c of json.clients) {
  1150. clients.push(Inbound.TrojanSettings.Client.fromJson(c));
  1151. }
  1152. return new Inbound.TrojanSettings(
  1153. Protocols.TROJAN,
  1154. clients,
  1155. Inbound.TrojanSettings.Fallback.fromJson(json.fallbacks),);
  1156. }
  1157. };
  1158. Inbound.TrojanSettings.Client = class extends XrayCommonClass {
  1159. constructor(password=RandomUtil.randomSeq(10), flow=FLOW_CONTROL.DIRECT) {
  1160. super();
  1161. this.password = password;
  1162. this.flow = flow;
  1163. }
  1164. toJson() {
  1165. return {
  1166. password: this.password,
  1167. flow: this.flow,
  1168. };
  1169. }
  1170. static fromJson(json={}) {
  1171. return new Inbound.TrojanSettings.Client(
  1172. json.password,
  1173. json.flow,
  1174. );
  1175. }
  1176. };
  1177. Inbound.TrojanSettings.Fallback = class extends XrayCommonClass {
  1178. constructor(name="", alpn='', path='', dest='', xver=0) {
  1179. super();
  1180. this.name = name;
  1181. this.alpn = alpn;
  1182. this.path = path;
  1183. this.dest = dest;
  1184. this.xver = xver;
  1185. }
  1186. toJson() {
  1187. let xver = this.xver;
  1188. if (!Number.isInteger(xver)) {
  1189. xver = 0;
  1190. }
  1191. return {
  1192. name: this.name,
  1193. alpn: this.alpn,
  1194. path: this.path,
  1195. dest: this.dest,
  1196. xver: xver,
  1197. }
  1198. }
  1199. static fromJson(json=[]) {
  1200. const fallbacks = [];
  1201. for (let fallback of json) {
  1202. fallbacks.push(new Inbound.TrojanSettings.Fallback(
  1203. fallback.name,
  1204. fallback.alpn,
  1205. fallback.path,
  1206. fallback.dest,
  1207. fallback.xver,
  1208. ))
  1209. }
  1210. return fallbacks;
  1211. }
  1212. };
  1213. Inbound.ShadowsocksSettings = class extends Inbound.Settings {
  1214. constructor(protocol,
  1215. method=SSMethods.AES_256_GCM,
  1216. password=RandomUtil.randomSeq(10),
  1217. network='tcp,udp'
  1218. ) {
  1219. super(protocol);
  1220. this.method = method;
  1221. this.password = password;
  1222. this.network = network;
  1223. }
  1224. static fromJson(json={}) {
  1225. return new Inbound.ShadowsocksSettings(
  1226. Protocols.SHADOWSOCKS,
  1227. json.method,
  1228. json.password,
  1229. json.network,
  1230. );
  1231. }
  1232. toJson() {
  1233. return {
  1234. method: this.method,
  1235. password: this.password,
  1236. network: this.network,
  1237. };
  1238. }
  1239. };
  1240. Inbound.DokodemoSettings = class extends Inbound.Settings {
  1241. constructor(protocol, address, port, network='tcp,udp') {
  1242. super(protocol);
  1243. this.address = address;
  1244. this.port = port;
  1245. this.network = network;
  1246. }
  1247. static fromJson(json={}) {
  1248. return new Inbound.DokodemoSettings(
  1249. Protocols.DOKODEMO,
  1250. json.address,
  1251. json.port,
  1252. json.network,
  1253. );
  1254. }
  1255. toJson() {
  1256. return {
  1257. address: this.address,
  1258. port: this.port,
  1259. network: this.network,
  1260. };
  1261. }
  1262. };
  1263. Inbound.MtprotoSettings = class extends Inbound.Settings {
  1264. constructor(protocol, users=[new Inbound.MtprotoSettings.MtUser()]) {
  1265. super(protocol);
  1266. this.users = users;
  1267. }
  1268. static fromJson(json={}) {
  1269. return new Inbound.MtprotoSettings(
  1270. Protocols.MTPROTO,
  1271. json.users.map(user => Inbound.MtprotoSettings.MtUser.fromJson(user)),
  1272. );
  1273. }
  1274. toJson() {
  1275. return {
  1276. users: XrayCommonClass.toJsonArray(this.users),
  1277. };
  1278. }
  1279. };
  1280. Inbound.MtprotoSettings.MtUser = class extends XrayCommonClass {
  1281. constructor(secret=RandomUtil.randomMTSecret()) {
  1282. super();
  1283. this.secret = secret;
  1284. }
  1285. static fromJson(json={}) {
  1286. return new Inbound.MtprotoSettings.MtUser(json.secret);
  1287. }
  1288. };
  1289. Inbound.SocksSettings = class extends Inbound.Settings {
  1290. constructor(protocol, auth='password', accounts=[new Inbound.SocksSettings.SocksAccount()], udp=false, ip='127.0.0.1') {
  1291. super(protocol);
  1292. this.auth = auth;
  1293. this.accounts = accounts;
  1294. this.udp = udp;
  1295. this.ip = ip;
  1296. }
  1297. addAccount(account) {
  1298. this.accounts.push(account);
  1299. }
  1300. delAccount(index) {
  1301. this.accounts.splice(index, 1);
  1302. }
  1303. static fromJson(json={}) {
  1304. let accounts;
  1305. if (json.auth === 'password') {
  1306. accounts = json.accounts.map(
  1307. account => Inbound.SocksSettings.SocksAccount.fromJson(account)
  1308. )
  1309. }
  1310. return new Inbound.SocksSettings(
  1311. Protocols.SOCKS,
  1312. json.auth,
  1313. accounts,
  1314. json.udp,
  1315. json.ip,
  1316. );
  1317. }
  1318. toJson() {
  1319. return {
  1320. auth: this.auth,
  1321. accounts: this.auth === 'password' ? this.accounts.map(account => account.toJson()) : undefined,
  1322. udp: this.udp,
  1323. ip: this.ip,
  1324. };
  1325. }
  1326. };
  1327. Inbound.SocksSettings.SocksAccount = class extends XrayCommonClass {
  1328. constructor(user=RandomUtil.randomSeq(10), pass=RandomUtil.randomSeq(10)) {
  1329. super();
  1330. this.user = user;
  1331. this.pass = pass;
  1332. }
  1333. static fromJson(json={}) {
  1334. return new Inbound.SocksSettings.SocksAccount(json.user, json.pass);
  1335. }
  1336. };
  1337. Inbound.HttpSettings = class extends Inbound.Settings {
  1338. constructor(protocol, accounts=[new Inbound.HttpSettings.HttpAccount()]) {
  1339. super(protocol);
  1340. this.accounts = accounts;
  1341. }
  1342. addAccount(account) {
  1343. this.accounts.push(account);
  1344. }
  1345. delAccount(index) {
  1346. this.accounts.splice(index, 1);
  1347. }
  1348. static fromJson(json={}) {
  1349. return new Inbound.HttpSettings(
  1350. Protocols.HTTP,
  1351. json.accounts.map(account => Inbound.HttpSettings.HttpAccount.fromJson(account)),
  1352. );
  1353. }
  1354. toJson() {
  1355. return {
  1356. accounts: Inbound.HttpSettings.toJsonArray(this.accounts),
  1357. };
  1358. }
  1359. };
  1360. Inbound.HttpSettings.HttpAccount = class extends XrayCommonClass {
  1361. constructor(user=RandomUtil.randomSeq(10), pass=RandomUtil.randomSeq(10)) {
  1362. super();
  1363. this.user = user;
  1364. this.pass = pass;
  1365. }
  1366. static fromJson(json={}) {
  1367. return new Inbound.HttpSettings.HttpAccount(json.user, json.pass);
  1368. }
  1369. };