├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── luasrc ├── controller │ └── xray.lua ├── model │ └── cbi │ │ └── xray │ │ ├── access-control.lua │ │ ├── general.lua │ │ ├── gfwlist-custom.lua │ │ ├── servers-details.lua │ │ └── servers.lua └── view │ └── xray │ ├── general.htm │ ├── plain.htm │ └── servers-details.htm ├── po ├── zh-cn │ └── xray.zh-cn.po └── zh_Hans └── root ├── etc ├── config │ └── xray ├── init.d │ └── xray └── uci-defaults │ └── luci-xray └── usr ├── bin └── xray-rules └── share └── rpcd └── acl.d └── luci-app-xray.json /.gitignore: -------------------------------------------------------------------------------- 1 | dist/* 2 | *.lmo 3 | *.o 4 | tools/po2lmo/src/po2lmo 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020-2025 honwen https://github.com/honwen 3 | # 4 | # This is free software, licensed under the GNU General Public License v3. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=luci-app-xray 11 | PKG_VERSION:=0.7.3 12 | PKG_RELEASE:=2 13 | PKG_MAINTAINER:=honwen 14 | 15 | LUCI_TITLE:=LuCI Support for Xray 16 | LUCI_DEPENDS:=+iptables +ipset +curl +ip +iptables-mod-tproxy 17 | LUCI_PKGARCH:=all 18 | 19 | define Package/$(PKG_NAME)/conffiles 20 | /etc/config/xray 21 | endef 22 | 23 | include $(TOPDIR)/feeds/luci/luci.mk 24 | 25 | define Package/$(PKG_NAME)/postinst 26 | #!/bin/sh 27 | if [ -z "$${IPKG_INSTROOT}" ]; then 28 | if [ -f /etc/uci-defaults/luci-xray ]; then 29 | ( . /etc/uci-defaults/luci-xray ) && \ 30 | rm -f /etc/uci-defaults/luci-xray 31 | fi 32 | rm -rf /tmp/luci-indexcache /tmp/luci-modulecache 33 | fi 34 | exit 0 35 | endef 36 | 37 | # call BuildPackage - OpenWrt buildroot signature 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenWrt LuCI for Xray 2 | 3 | [![Latest release][release_badge]][release_url] 4 | 5 | ## 简介 6 | 7 | 本软件包是 [xray][openwrt-xray] 的 LuCI 控制界面, 兼容[SagerNet/v2ray-core][openwrt-xray] 8 | 方便用户控制和使用「透明代理」「SOCKS5 代理」「端口转发」功能. 9 | 10 | 软件包文件结构: 11 | 12 | ``` 13 | / 14 | ├── etc/ 15 | │   ├── config/ 16 | │   │   └── xray // UCI 配置文件 17 | │   │── init.d/ 18 | │   │   └── xray // init 脚本 19 | │   └── uci-defaults/ 20 | │      └── luci-xray // uci-defaults 脚本 21 | └── usr/ 22 | ├── bin/ 23 | │   └── xray-rules // 生成代理转发规则的脚本 24 | └── lib/ 25 | └── lua/ 26 | └── luci/ // LuCI 部分 27 | ├── controller/ 28 | │   └── xray.lua // LuCI 菜单配置 29 | ├── i18n/ // LuCI 语言文件目录 30 | │   └── xray.zh-cn.lmo 31 | └── model/ 32 | └── cbi/ 33 | └── xray/ 34 | ├── general.lua // LuCI 基本设置 35 | ├── servers.lua // LuCI 服务器列表 36 | ├── servers-details.lua // LuCI 服务器编辑 37 | └── access-control.lua // LuCI 访问控制 38 | ``` 39 | 40 | ## 依赖 41 | 42 | 软件包的正常使用需要依赖 `iptables` 和 `ipset`. 43 | 软件包不显式依赖 `xray`, 会根据用户添加的可执行文件启用相应的功能. 44 | **GFW-List 模式 正常使用需要依赖 [dnsmasq-extra][openwrt-dnsmasq-extra], 其中包括`DNS防污染`和`GFW-List`** 45 | 可执行文件可通过安装 [openwrt-xray][openwrt-xray] 中提供的 `xray` 获得. 46 | 只有当文件存在时, 相应的功能才可被使用, 并显示相应的 LuCI 设置界面. 47 | 48 | | 可执行文件 | 可选 | 功能 | TCP 协议 | UDP 协议 | 49 | | ---------- | ---- | -------- | -------- | ---------------------------------- | 50 | | `xray` | 是 | 透明代理 | 支持 | 需安装 `iptables-mod-tproxy`, `ip` | 51 | 52 | 注: 可执行文件在 `$PATH` 环境变量所表示的搜索路径中, 都可被正确调用. 53 | 54 | ## 配置 55 | 56 | 软件包的配置文件路径: `/etc/config/xray` 57 | 此文件为 UCI 配置文件, 配置方式可参考 [Wiki -> Use-UCI-system][use-uci-system] 和 [OpenWrt Wiki][uci] 58 | 透明代理的访问控制功能设置可参考 [Wiki -> LuCI-Access-Control][luci-access-control] 59 | 60 | ## 编译 61 | 62 | 从 OpenWrt 的 [SDK][openwrt-sdk] 编译 63 | 64 | ```bash 65 | # 解压下载好的 SDK 66 | tar xjf OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 67 | cd OpenWrt-SDK-ar71xx-* 68 | # Clone 项目 69 | git clone https://github.com/honwen/luci-app-xray.git package/luci-app-xray 70 | # 编译 po2lmo (如果有po2lmo可跳过) 71 | pushd package/luci-app-xray/tools/po2lmo 72 | make && sudo make install 73 | popd 74 | # 选择要编译的包 LuCI -> 3. Applications 75 | make menuconfig 76 | # 开始编译 77 | make package/luci-app-xray/compile V=99 78 | ``` 79 | 80 | [release_badge]: https://img.shields.io/github/release/honwen/luci-app-xray.svg 81 | [release_url]: https://github.com/honwen/luci-app-xray/releases 82 | [openwrt-xray]: https://github.com/honwen/openwrt-precompiled-feeds 83 | [openwrt-sdk]: https://wiki.openwrt.org/doc/howto/obtain.firmware.sdk 84 | [xray-rules]: https://github.com/xray/luci-app-xray/wiki/Instruction-of-xray-rules 85 | [use-uci-system]: https://github.com/xray/luci-app-xray/wiki/Use-UCI-system 86 | [uci]: https://wiki.openwrt.org/doc/uci 87 | [luci-access-control]: https://github.com/xray/luci-app-xray/wiki/LuCI-Access-Control 88 | [openwrt-dnsmasq-extra]: https://github.com/honwen/openwrt-dnsmasq-extra 89 | -------------------------------------------------------------------------------- /luasrc/controller/xray.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2014-2017 Jian Chang 2 | -- Copyright (C) 2020-2023 honwen 3 | -- Licensed to the public under the GNU General Public License v3. 4 | 5 | module("luci.controller.xray", package.seeall) 6 | 7 | function index() 8 | if not nixio.fs.access("/etc/config/xray") then 9 | return 10 | end 11 | 12 | page = entry({"admin", "services", "xray"}, 13 | alias("admin", "services", "xray", "general"), 14 | _("Xray"), 10) 15 | page.dependent = true 16 | page.acl_depends = { "luci-app-xray" } 17 | 18 | page = entry({"admin", "services", "xray", "general"}, 19 | cbi("xray/general"), 20 | _("General Settings"), 10) 21 | page.leaf = true 22 | page.acl_depends = { "luci-app-xray" } 23 | 24 | page = entry({"admin", "services", "xray", "status"}, 25 | call("action_status")) 26 | page.leaf = true 27 | page.acl_depends = { "luci-app-xray" } 28 | 29 | page = entry({"admin", "services", "xray", "servers"}, 30 | arcombine(cbi("xray/servers"), cbi("xray/servers-details")), 31 | _("Servers Manage"), 20) 32 | page.leaf = true 33 | page.acl_depends = { "luci-app-xray" } 34 | 35 | if luci.sys.call("command -v xray >/dev/null") ~= 0 then 36 | return 37 | end 38 | 39 | page = entry({"admin", "services", "xray", "access-control"}, 40 | cbi("xray/access-control"), 41 | _("Access Control"), 30) 42 | page.leaf = true 43 | page.acl_depends = { "luci-app-xray" } 44 | 45 | page = entry({"admin", "services", "xray", "log"}, 46 | call("action_log"), 47 | _("System Log"), 90) 48 | page.leaf = true 49 | page.acl_depends = { "luci-app-xray" } 50 | 51 | if luci.sys.call("command -v /etc/init.d/dnsmasq-extra >/dev/null") ~= 0 then 52 | return 53 | end 54 | 55 | page = entry({"admin", "services", "xray", "gfwlist"}, 56 | call("action_gfw"), 57 | _("GFW-List"), 60) 58 | page.leaf = true 59 | page.acl_depends = { "luci-app-xray" } 60 | 61 | page = entry({"admin", "services", "xray", "custom"}, 62 | cbi("xray/gfwlist-custom"), 63 | _("Custom-List"), 50) 64 | page.leaf = true 65 | page.acl_depends = { "luci-app-xray" } 66 | 67 | end 68 | 69 | local function is_running(name) 70 | return luci.sys.call("pgrep -f '%s' >/dev/null" %{name}) == 0 71 | end 72 | 73 | function action_status() 74 | luci.http.prepare_content("application/json") 75 | luci.http.write_json({ 76 | xray_status = is_running("bin/xray"), 77 | }) 78 | end 79 | 80 | function action_log() 81 | local conffile = "/var/log/xray_watchdog.log" 82 | local watchdog = nixio.fs.readfile(conffile) or "" 83 | luci.template.render("xray/plain", {content=watchdog}) 84 | end 85 | 86 | function action_gfw() 87 | local conffile = "/etc/dnsmasq-extra.d/gfwlist" 88 | local gfwlist = nixio.fs.readfile(conffile) or luci.sys.exec("cat %s.gz | gunzip -c" %{conffile}) or "" 89 | luci.template.render("xray/plain", {content=gfwlist}) 90 | end 91 | -------------------------------------------------------------------------------- /luasrc/model/cbi/xray/access-control.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2016-2017 Jian Chang 2 | -- Copyright (C) 2020-2023 honwen 3 | -- Licensed to the public under the GNU General Public License v3. 4 | 5 | local m, s, o 6 | local xray = "xray" 7 | local uci = luci.model.uci.cursor() 8 | local nwm = require("luci.model.network").init() 9 | local gfwroute = luci.sys.call("command -v /etc/init.d/dnsmasq-extra >/dev/null") == 0 10 | local chnroute = gfwroute and "/etc/chinadns_chnroute.txt" or uci:get_first("chinadns", "chinadns", "chnroute") 11 | local lan_ifaces = {} 12 | local io = require "io" 13 | 14 | local function ipv4_hints(callback) 15 | local hosts = {} 16 | uci:foreach("dhcp", "dnsmasq", function(s) 17 | if s.leasefile and nixio.fs.access(s.leasefile) then 18 | for e in io.lines(s.leasefile) do 19 | mac, ip, name = e:match("^%d+ (%S+) (%S+) (%S+)") 20 | if mac and ip then 21 | hosts[ip] = name ~= "*" and name or mac:upper() 22 | end 23 | end 24 | end 25 | end) 26 | uci:foreach("dhcp", "host", function(s) 27 | for mac in luci.util.imatch(s.mac) do 28 | hosts[s.ip] = s.name or mac:upper() 29 | end 30 | end) 31 | for ip, name in pairs(hosts) do 32 | callback(ip, name) 33 | end 34 | end 35 | 36 | for _, net in ipairs(nwm:get_networks()) do 37 | if net:name() ~= "loopback" and string.find(net:name(), "wan") ~= 1 then 38 | net = nwm:get_network(net:name()) 39 | local device = net and net:get_interface() 40 | if device then 41 | lan_ifaces[device:name()] = device:get_i18n() 42 | end 43 | end 44 | end 45 | 46 | m = Map(xray, "%s - %s" %{translate("Xray"), translate("Access Control")}) 47 | 48 | -- [[ Zone WAN ]]-- 49 | s = m:section(TypedSection, "access_control", translate("Zone WAN")) 50 | s.anonymous = true 51 | 52 | o = s:option(Value, "wan_bp_list", translate("Bypassed IP List")) 53 | o:value("/dev/null", translate("NULL - As Global Proxy")) 54 | if gfwroute then o:value("/dev/flag_gfwlist", translate("Only Proxy GFW-List")) end 55 | if chnroute then o:value(chnroute, translate("ChinaDNS CHNRoute")) end 56 | -- o.datatype = "or(file, '/dev/null')" 57 | o.default = "/dev/null" 58 | o.rmempty = false 59 | 60 | o = s:option(DynamicList, "wan_bp_ips", translate("Bypassed IP")) 61 | o.datatype = "ip4addr" 62 | o.rmempty = true 63 | 64 | o = s:option(Value, "wan_fw_list", translate("Forwarded IP List")) 65 | o.datatype = "or(file, '/dev/null')" 66 | o.rmempty = true 67 | 68 | o = s:option(DynamicList, "wan_fw_ips", translate("Forwarded IP")) 69 | o.datatype = "ip4addr" 70 | o.rmempty = true 71 | 72 | -- [[ Zone LAN ]]-- 73 | s = m:section(TypedSection, "access_control", translate("Zone LAN")) 74 | s.anonymous = true 75 | 76 | o = s:option(MultiValue, "lan_ifaces", translate("Interface")) 77 | function o.cfgvalue(...) 78 | local v = MultiValue.cfgvalue(...) 79 | if v then 80 | return v 81 | else 82 | local names = {} 83 | for name, _ in pairs(lan_ifaces) do 84 | names[#names+1] = name 85 | end 86 | return table.concat(names, " ") 87 | end 88 | end 89 | for name, i18n in pairs(lan_ifaces) do 90 | o:value(name, i18n) 91 | end 92 | 93 | o = s:option(ListValue, "lan_target", translate("Proxy Type")) 94 | o:value("XRAY_SPEC_WAN_AC", translate("Normal")) 95 | o:value("RETURN", translate("Direct")) 96 | o:value("XRAY_SPEC_WAN_FW", translate("Global")) 97 | o.rmempty = false 98 | 99 | o = s:option(ListValue, "self_proxy", translate("Self Proxy")) 100 | o:value("1", translate("Normal")) 101 | o:value("0", translate("Direct")) 102 | o:value("2", translate("Global")) 103 | o.rmempty = false 104 | 105 | o = s:option(Value, "ipt_ext", translate("Extra arguments"), 106 | translate("Passes additional arguments to iptables. Use with care!")) 107 | o:value("", translate("None")) 108 | o:value("--dport 22:1023", translatef("Proxy port numbers %s only", "22~1023")) 109 | o:value("-m multiport --dport 22:1023,8000:8443", translatef("Proxy port numbers %s only", "22~1023,8000~8443")) 110 | o:value("-m multiport --dports 53,80,443,853", translatef("Proxy port numbers %s only", "53,80,443,853")) 111 | 112 | -- [[ LAN Hosts ]]-- 113 | s = m:section(TypedSection, "lan_hosts", translate("LAN Hosts")) 114 | s.template = "cbi/tblsection" 115 | s.addremove = true 116 | s.anonymous = true 117 | 118 | o = s:option(Value, "host", translate("Host")) 119 | ipv4_hints(function(ip, name) 120 | o:value(ip, "%s (%s)" %{ip, name}) 121 | end) 122 | o.datatype = "ip4addr" 123 | o.rmempty = false 124 | 125 | o = s:option(ListValue, "type", translate("Proxy Type")) 126 | o:value("b", translate("Direct")) 127 | o:value("g", translate("Global")) 128 | o:value("n", translate("Normal")) 129 | o.rmempty = false 130 | 131 | o = s:option(Flag, "enable", translate("Enable")) 132 | o.default = "1" 133 | o.rmempty = false 134 | 135 | return m 136 | -------------------------------------------------------------------------------- /luasrc/model/cbi/xray/general.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2014-2018 Jian Chang 2 | -- Copyright (C) 2020-2023 honwen 3 | -- Licensed to the public under the GNU General Public License v3. 4 | 5 | local m, s, o 6 | local xray = "xray" 7 | local uci = luci.model.uci.cursor() 8 | local servers = {} 9 | local strategy = { 10 | "random", 11 | "leastPing", 12 | "leastLoad", 13 | } 14 | 15 | local function has_bin(name) 16 | return luci.sys.call("command -v %s >/dev/null" %{name}) == 0 17 | end 18 | 19 | local function has_udp_relay() 20 | return luci.sys.call("lsmod | grep -q TPROXY && command -v ip >/dev/null") == 0 21 | end 22 | 23 | if not has_bin("xray") then 24 | return Map(xray, "%s - %s" %{translate("Xray"), 25 | translate("General Settings")}, 'xray binary file not found.') 26 | end 27 | 28 | local function is_running(name) 29 | return luci.sys.call("pgrep -f '%s' >/dev/null" %{name}) == 0 30 | end 31 | 32 | local function get_status(name) 33 | return is_running(name) and translate("RUNNING") or translate("NOT RUNNING") 34 | end 35 | 36 | uci:foreach(xray, "servers", function(s) 37 | if s.server and s.server_port then 38 | servers[#servers+1] = {name = s[".name"], alias = s.alias or "%s:%s" %{s.server, s.server_port}} 39 | end 40 | end) 41 | 42 | m = Map(xray, "%s - %s" %{translate("Xray"), translate("General Settings")}) 43 | m.template = "xray/general" 44 | 45 | -- [[ Running Status ]]-- 46 | s = m:section(TypedSection, "general", translate("Running Status")) 47 | s.anonymous = true 48 | 49 | o = s:option(DummyValue, "_xray_status", translate("Xray")) 50 | o.value = "%s" %{get_status("bin/xray")} 51 | o.rawhtml = true 52 | 53 | -- [[ General Config ]]-- 54 | s = m:section(TypedSection, "general", translate("Global Settings")) 55 | s.anonymous = true 56 | 57 | o = s:option(Value, "startup_delay", translate("Startup Delay")) 58 | o:value(0, translate("Not enabled")) 59 | for _, v in ipairs({3, 5, 10, 15, 25, 40}) do 60 | o:value(v, translatef("%u seconds", v)) 61 | end 62 | o.datatype = "uinteger" 63 | o.default = 0 64 | o.rmempty = false 65 | 66 | o = s:option(DynamicList, "server", translate("Server")) 67 | o:value("nil", translate("Disable")) 68 | for _, s in ipairs(servers) do o:value(s.name, s.alias) end 69 | o.default = "nil" 70 | o.rmempty = false 71 | 72 | o = s:option(Value, "strategy", translate("Balancer Strategy")) 73 | for _, v in ipairs(strategy) do o:value(v, v:upper()) end 74 | o.default = 'leastPing' 75 | o.rmempty = false 76 | 77 | o = s:option(Flag, "no_dns_injection", translate("Disable DNS Auto-Injection")) 78 | o.rmempty = false 79 | 80 | -- [[ Transparent Proxy ]]-- 81 | s = m:section(TypedSection, "transparent_proxy", translate("Transparent Proxy")) 82 | s.anonymous = true 83 | 84 | o = s:option(Flag, "enable", translate("Enable")) 85 | o.rmempty = false 86 | 87 | o = s:option(Flag, "enable_udp", "%s %s" %{translate("Enable"), "UDP"}) 88 | o.default = '1' 89 | o.rmempty = false 90 | o:depends('enable', '1') 91 | 92 | o = s:option(Flag, "disable_http3", "%s %s" %{translate("Disable"), "HTTP3"}) 93 | o.default = '1' 94 | o.rmempty = false 95 | o:depends('enable_udp', '1') 96 | 97 | o = s:option(Value, "local_port", translate("Local Port")) 98 | o.datatype = "port" 99 | o.default = 1234 100 | o:depends('enable', '1') 101 | 102 | o = s:option(Flag, "no_healthcheck", translate("Disable HealthCheck")) 103 | o.rmempty = false 104 | o:depends('enable', '1') 105 | 106 | -- [[ HTTP Proxy ]]-- 107 | s = m:section(TypedSection, "http_proxy", translate("HTTP Proxy")) 108 | s.anonymous = true 109 | 110 | o = s:option(Flag, "enable", translate("Enable")) 111 | o.rmempty = false 112 | 113 | o = s:option(Value, "local_port", translate("Local Port")) 114 | o.datatype = "port" 115 | o.default = 1080 116 | o:depends('enable', '1') 117 | 118 | -- [[ SOCKS5 Proxy ]]-- 119 | s = m:section(TypedSection, "socks5_proxy", translate("SOCKS5 Proxy")) 120 | s.anonymous = true 121 | 122 | o = s:option(Flag, "enable", translate("Enable")) 123 | o.rmempty = false 124 | 125 | o = s:option(Value, "local_port", translate("Local Port")) 126 | o.datatype = "port" 127 | o.default = 1080 128 | o:depends('enable', '1') 129 | 130 | -- [[ Port Forward ]]-- 131 | s = m:section(TypedSection, "port_forward", translate("Port Forward")) 132 | s.anonymous = true 133 | 134 | o = s:option(Flag, "enable", translate("Enable")) 135 | o.rmempty = false 136 | 137 | o = s:option(Value, "local_port", translate("Local Port")) 138 | o.datatype = "port" 139 | o.default = 5300 140 | o:depends('enable', '1') 141 | 142 | o = s:option(Value, "destination", translate("Destination")) 143 | o.default = "8.8.4.4:53" 144 | o:depends('enable', '1') 145 | 146 | return m 147 | -------------------------------------------------------------------------------- /luasrc/model/cbi/xray/gfwlist-custom.lua: -------------------------------------------------------------------------------- 1 | local fs = require "nixio.fs" 2 | local conffile = "/etc/dnsmasq-extra.d/custom.conf" 3 | 4 | f = SimpleForm("custom", translate("Be Careful!"), translate("Dnsmasq Config for xray. This may CRASH DNSMASQ!")) 5 | 6 | t = f:field(TextValue, "conf") 7 | t.rmempty = true 8 | t.rows = 30 9 | function t.cfgvalue() 10 | return fs.readfile(conffile) or "" 11 | end 12 | 13 | function f.handle(self, state, data) 14 | if state == FORM_VALID then 15 | if data.conf then 16 | fs.writefile(conffile, data.conf:gsub("\r\n", "\n")) 17 | luci.sys.call("/etc/init.d/dnsmasq-extra restart") 18 | end 19 | end 20 | return true 21 | end 22 | 23 | return f 24 | -------------------------------------------------------------------------------- /luasrc/model/cbi/xray/servers-details.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2016-2017 Jian Chang 2 | -- Copyright (C) 2020-2023 honwen 3 | -- Licensed to the public under the GNU General Public License v3. 4 | 5 | local m, s, o 6 | local xray = "xray" 7 | local sid = arg[1] 8 | local protocols = { 9 | "socks", 10 | "vless", 11 | "trojan", 12 | "shadowsocks", 13 | } 14 | local securitys = { 15 | "h2@reality", 16 | "xtls-vision@reality", 17 | "xtls-splice", 18 | "xtls-direct", 19 | "xtls-vision", 20 | "tls", 21 | "wss", 22 | "quic", 23 | } 24 | local encrypts = { 25 | "aes-256-gcm", 26 | "aes-128-gcm", 27 | "chacha20-ietf-poly1305", 28 | "2022-blake3-aes-128-gcm", 29 | "2022-blake3-aes-256-gcm", 30 | "2022-blake3-chacha20-poly1305", 31 | "rc4-md5", 32 | "aes-128-cfb", 33 | "aes-192-cfb", 34 | "aes-256-cfb", 35 | "aes-128-ctr", 36 | "aes-192-ctr", 37 | "aes-256-ctr", 38 | "camellia-128-cfb", 39 | "camellia-192-cfb", 40 | "camellia-256-cfb", 41 | "chacha20-ietf", 42 | "none", 43 | } 44 | 45 | m = Map(xray, "%s - %s" %{translate("Xray"), translate("Edit Server")}) 46 | m.redirect = luci.dispatcher.build_url("admin/services/xray/servers") 47 | m.sid = sid 48 | m.template = "xray/servers-details" 49 | 50 | if m.uci:get(xray, sid) ~= "servers" then 51 | luci.http.redirect(m.redirect) 52 | return 53 | end 54 | 55 | -- [[ Edit Server ]]-- 56 | s = m:section(NamedSection, sid, "servers") 57 | s.anonymous = true 58 | s.addremove = false 59 | 60 | o = s:option(Value, "alias", translate("Alias(optional)")) 61 | o.rmempty = true 62 | 63 | o = s:option(ListValue, "protocol", translate("Protocol")) 64 | for _, v in ipairs(protocols) do o:value(v, v:upper()) end 65 | o.default = 'vless' 66 | o.rmempty = false 67 | 68 | o = s:option(Value, "server", translate("Server Address")) 69 | o.datatype = "host" 70 | o.rmempty = false 71 | 72 | o = s:option(Value, "server_port", translate("Server Port")) 73 | o.datatype = "port" 74 | o.rmempty = false 75 | 76 | o = s:option(Value, "server_name", translate("Server Name")) 77 | o:depends('protocol', 'vless') 78 | o:depends('protocol', 'trojan') 79 | o.datatype = "host" 80 | o.rmempty = true 81 | 82 | o = s:option(Value, "id", translate("ID/AUTH")) 83 | o:depends('protocol', 'vless') 84 | o:depends('protocol', 'trojan') 85 | o:depends('protocol', 'shadowsocks') 86 | o.password = true 87 | 88 | -- [[ vless/trojan ]]-- 89 | o = s:option(ListValue, "security", translate("Security")) 90 | for _, v in ipairs(securitys) do o:value(v, v:upper()) end 91 | o:depends('protocol', 'vless') 92 | o:depends('protocol', 'trojan') 93 | o.default = 'xtls-vision@reality' 94 | o.rmempty = false 95 | 96 | o = s:option(Value, "ws_path", translate("Websocket Path")) 97 | o:depends('security', 'wss') 98 | o.placeholder = "/" 99 | o.rmempty = false 100 | -- [[ vless/trojan ]]-- 101 | 102 | -- [[ vless@reality ]]-- 103 | o = s:option(Value, "public_key", translate("Public Key")) 104 | o:depends('security', 'xtls-vision@reality') 105 | o:depends('security', 'h2@reality') 106 | o.rmempty = false 107 | 108 | o = s:option(Value, "short_id", translate("Short ID")) 109 | o:depends('security', 'xtls-vision@reality') 110 | o:depends('security', 'h2@reality') 111 | o.rmempty = true 112 | -- [[ vless@reality ]]-- 113 | 114 | -- [[ shadowsocks ]]-- 115 | o = s:option(ListValue, "method", translate("Encrypt Method")) 116 | for _, v in ipairs(encrypts) do o:value(v, v:upper()) end 117 | o:depends('protocol', 'shadowsocks') 118 | o.rmempty = false 119 | 120 | o = s:option(Value, "plugin", translate("Plugin Name")) 121 | o:depends('protocol', 'socks') 122 | o:depends('protocol', 'shadowsocks') 123 | -- o.placeholder = "eg: v2ray-plugin" 124 | o.rmempty = true 125 | 126 | o = s:option(Value, "plugin_opts", translate("Plugin Arguments")) 127 | o:depends('protocol', 'socks') 128 | o:depends('protocol', 'shadowsocks') 129 | -- o.placeholder = "eg: tls;host=www.bing.com;path=/websocket" 130 | o.rmempty = true 131 | 132 | o = s:option(Flag, "uot", translate("UDP over TCP")) 133 | o.rmempty = true 134 | -- [[ shadowsocks ]]-- 135 | 136 | return m 137 | -------------------------------------------------------------------------------- /luasrc/model/cbi/xray/servers.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2016-2017 Jian Chang 2 | -- Copyright (C) 2020-2023 honwen 3 | -- Licensed to the public under the GNU General Public License v3. 4 | 5 | local m, s, o 6 | local xray = "xray" 7 | 8 | m = Map(xray, "%s - %s" %{translate("Xray"), translate("Servers Manage")}) 9 | 10 | -- [[ Servers Manage ]]-- 11 | s = m:section(TypedSection, "servers") 12 | s.anonymous = true 13 | s.addremove = true 14 | s.sortable = true 15 | s.template = "cbi/tblsection" 16 | s.extedit = luci.dispatcher.build_url("admin/services/xray/servers/%s") 17 | function s.create(...) 18 | local sid = TypedSection.create(...) 19 | if sid then 20 | luci.http.redirect(s.extedit % sid) 21 | return 22 | end 23 | end 24 | 25 | o = s:option(DummyValue, "alias", translate("Alias")) 26 | function o.cfgvalue(...) 27 | return Value.cfgvalue(...) or translate("None") 28 | end 29 | 30 | o = s:option(DummyValue, "server", translate("Server Address")) 31 | function o.cfgvalue(...) 32 | return Value.cfgvalue(...) or "?" 33 | end 34 | 35 | o = s:option(DummyValue, "server_port", translate("Server Port")) 36 | function o.cfgvalue(...) 37 | return Value.cfgvalue(...) or "?" 38 | end 39 | 40 | o = s:option(DummyValue, "protocol", translate("Protocol")) 41 | function o.cfgvalue(...) 42 | local v = Value.cfgvalue(...) 43 | return v and v:upper() or "?" 44 | end 45 | 46 | o = s:option(DummyValue, "security", translate("Security")) 47 | function o.cfgvalue(...) 48 | local v = Value.cfgvalue(...) 49 | return v and v:upper() or "-" 50 | end 51 | 52 | return m 53 | -------------------------------------------------------------------------------- /luasrc/view/xray/general.htm: -------------------------------------------------------------------------------- 1 | <%# 2 | Copyright (C) 2017-2018 Jian Chang 3 | Copyright (C) 2020-2023 honwen 4 | Licensed to the public under the GNU General Public License v3. 5 | -%> 6 | 7 | <% include("cbi/map") %> 8 | 9 | 90 | -------------------------------------------------------------------------------- /luasrc/view/xray/plain.htm: -------------------------------------------------------------------------------- 1 | <%+header%> 2 | 9 | <%+footer%> 10 | -------------------------------------------------------------------------------- /luasrc/view/xray/servers-details.htm: -------------------------------------------------------------------------------- 1 | <%# 2 | Copyright (C) 2017-2018 Jian Chang 3 | Licensed to the public under the GNU General Public License v3. 4 | -%> 5 | 6 | <% include("cbi/map") %> 7 | 8 | 36 | -------------------------------------------------------------------------------- /po/zh-cn/xray.zh-cn.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "Content-Type: text/plain; charset=UTF-8\n" 3 | 4 | msgid "%u seconds" 5 | msgstr "%u 秒" 6 | 7 | msgid "Access Control" 8 | msgstr "访问控制" 9 | 10 | msgid "Alias" 11 | msgstr "别名" 12 | 13 | msgid "Alias(optional)" 14 | msgstr "别名(可选)" 15 | 16 | msgid "Balancer Strategy" 17 | msgstr "均衡器策略" 18 | 19 | msgid "Bypassed IP List" 20 | msgstr "被忽略IP列表" 21 | 22 | msgid "Bypassed IP" 23 | msgstr "额外被忽略IP" 24 | 25 | msgid "ChinaDNS CHNRoute" 26 | msgstr "ChinaDNS路由表" 27 | 28 | msgid "Connection Timeout" 29 | msgstr "连接超时" 30 | 31 | msgid "Destination" 32 | msgstr "目标地址" 33 | 34 | msgid "Direct" 35 | msgstr "直接连接" 36 | 37 | msgid "Directly Key" 38 | msgstr "直接密钥" 39 | 40 | msgid "Disable" 41 | msgstr "停用" 42 | 43 | msgid "Disable DNS Auto-Injection" 44 | msgstr "停用DNS自动注入" 45 | 46 | msgid "Disable HealthCheck" 47 | msgstr "停用健康检查" 48 | 49 | msgid "Edit Server" 50 | msgstr "编辑服务器" 51 | 52 | msgid "Enable" 53 | msgstr "启用" 54 | 55 | msgid "Encrypt Method" 56 | msgstr "加密方式" 57 | 58 | msgid "Extra arguments" 59 | msgstr "附加参数" 60 | 61 | msgid "Forwarded IP List" 62 | msgstr "走代理IP列表" 63 | 64 | msgid "Forwarded IP" 65 | msgstr "强制走代理IP" 66 | 67 | msgid "Global" 68 | msgstr "全局代理" 69 | 70 | msgid "Global Settings" 71 | msgstr "全局设置" 72 | 73 | msgid "Host" 74 | msgstr "主机" 75 | 76 | msgid "HTTP Proxy" 77 | msgstr "HTTP代理" 78 | 79 | msgid "LAN Hosts" 80 | msgstr "内网主机" 81 | 82 | msgid "Local Port" 83 | msgstr "本地端口" 84 | 85 | msgid "Main Server" 86 | msgstr "主服务器" 87 | 88 | msgid "Maximum UDP Associations" 89 | msgstr "UDP协商数上限" 90 | 91 | msgid "None" 92 | msgstr "无" 93 | 94 | msgid "Normal" 95 | msgstr "正常代理" 96 | 97 | msgid "Not enabled" 98 | msgstr "未启用" 99 | 100 | msgid "NOT RUNNING" 101 | msgstr "未运行" 102 | 103 | msgid "NULL - As Global Proxy" 104 | msgstr "留空 - 作为全局代理" 105 | 106 | msgid "Passes additional arguments to iptables. Use with care!" 107 | msgstr "传递到iptables的额外参数。小心使用!" 108 | 109 | msgid "Password" 110 | msgstr "密码" 111 | 112 | msgid "Plugin" 113 | msgstr "插件" 114 | 115 | msgid "Plugin Arguments" 116 | msgstr "插件参数" 117 | 118 | msgid "Plugin Name" 119 | msgstr "插件名称" 120 | 121 | msgid "Port Forward" 122 | msgstr "端口转发" 123 | 124 | msgid "Proxy port numbers %s only" 125 | msgstr "仅代理 %s 端口" 126 | 127 | msgid "RUNNING" 128 | msgstr "运行中" 129 | 130 | msgid "Running Status" 131 | msgstr "运行状态" 132 | 133 | msgid "Same as Main Server" 134 | msgstr "与主服务器相同" 135 | 136 | msgid "Security" 137 | msgstr "安全策略" 138 | 139 | msgid "Self Proxy" 140 | msgstr "代理自身" 141 | 142 | msgid "Server" 143 | msgstr "服务器" 144 | 145 | msgid "Server Address" 146 | msgstr "服务器地址" 147 | 148 | msgid "Servers Manage" 149 | msgstr "服务器管理" 150 | 151 | msgid "Server Name" 152 | msgstr "服务器名(SNI)" 153 | 154 | msgid "Server Port" 155 | msgstr "服务器端口" 156 | 157 | msgid "SOCKS5 Proxy" 158 | msgstr "SOCKS5代理" 159 | 160 | msgid "Startup Delay" 161 | msgstr "自启动延时" 162 | 163 | msgid "TCP Connection Timeout" 164 | msgstr "TCP 连接超时" 165 | 166 | msgid "TCP Fast Open" 167 | msgstr "TCP快速打开" 168 | 169 | msgid "TCP no-delay" 170 | msgstr "TCP无延时" 171 | 172 | msgid "Transparent Proxy" 173 | msgstr "透明代理" 174 | 175 | msgid "Timeout for UDP Associations" 176 | msgstr "UDP协商超时" 177 | 178 | msgid "Proxy Type" 179 | msgstr "代理类型" 180 | 181 | msgid "UDP-Relay Server" 182 | msgstr "UDP服务器" 183 | 184 | msgid "Unlimited" 185 | msgstr "无限制" 186 | 187 | msgid "Unusable - Missing iptables-mod-tproxy or ip" 188 | msgstr "不可用 - iptables-mod-tproxy 或 ip 缺失" 189 | 190 | msgid "Zone LAN" 191 | msgstr "内网区域" 192 | 193 | msgid "Zone WAN" 194 | msgstr "外网区域" 195 | 196 | msgid "GFW-List" 197 | msgstr "GFW 列表" 198 | 199 | msgid "Custom-List" 200 | msgstr "自定义列表" 201 | 202 | msgid "Be Careful!" 203 | msgstr "注意" 204 | 205 | msgid "Dnsmasq Config for xray. This may CRASH DNSMASQ!" 206 | msgstr "自定义 DNSMASQ 的 xray 列表, 这可能让DNSMASQ崩溃, 请参考以下的格式" 207 | -------------------------------------------------------------------------------- /po/zh_Hans: -------------------------------------------------------------------------------- 1 | zh-cn -------------------------------------------------------------------------------- /root/etc/config/xray: -------------------------------------------------------------------------------- 1 | 2 | config general 3 | option startup_delay '0' 4 | list server 'nil' 5 | 6 | config transparent_proxy 7 | option enable '1' 8 | option local_port '1234' 9 | 10 | config http_proxy 11 | option enable '0' 12 | 13 | config socks5_proxy 14 | option enable '0' 15 | 16 | config port_forward 17 | option enable '0' 18 | 19 | config servers 20 | option alias 'sample-xtls' 21 | option server '127.0.0.1' 22 | option server_port '443' 23 | option server_name 'xray.example.com' 24 | 25 | config access_control 26 | option self_proxy '1' 27 | -------------------------------------------------------------------------------- /root/etc/init.d/xray: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # 3 | # Copyright (C) 2020-2023 honwen 4 | # 5 | # This is free software, licensed under the GNU General Public License v3. 6 | # See /LICENSE for more information. 7 | # 8 | 9 | START=90 10 | STOP=15 11 | 12 | NAME=xray 13 | EXTRA_COMMANDS="rules healthcheck" 14 | EXTRA_HELP=" rules Start IPTABLES inject\n healthcheck Check if service health" 15 | CRON_FILE=/etc/crontabs/root 16 | PLUGIN_FILE=/var/run/xray-plugin 17 | WATCHDOG_ENDPOINT='one.one.one.one' 18 | WATCHDOG_ENDPOINT_IP0='1.0.0.1' 19 | WATCHDOG_ENDPOINT_IP1='1.1.1.1' 20 | PROBE_ENDPOINT='detectportal.firefox.com' 21 | # PROBE_ENDPOINT='accounts.gstatic.com' 22 | # PROBE_ENDPOINT='cp.cloudflare.com' 23 | 24 | DNSMASQDIR=$(sed -n 's+conf-dir=++p' /var/etc/dnsmasq.conf.* 2>/dev/null) 25 | [ "V$DNSMASQDIR" = "V" ] && DNSMASQDIR=/var/dnsmasq.d 26 | 27 | uci_get_by_name() { 28 | local ret=$(uci get $NAME.$1.$2 2>/dev/null) 29 | echo ${ret:=$3} 30 | } 31 | 32 | uci_get_by_type() { 33 | local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null) 34 | echo ${ret:=$3} 35 | } 36 | 37 | uci_bool_by_name() { 38 | case "$(uci_get_by_name $1 $2)" in 39 | 1 | on | true | yes | enabled) return 0 ;; 40 | esac 41 | return 1 42 | } 43 | 44 | uci_bool_by_type() { 45 | case "$(uci_get_by_type $1 $2)" in 46 | 1 | on | true | yes | enabled) return 0 ;; 47 | esac 48 | return 1 49 | } 50 | 51 | xray_xudp_basekey() { 52 | cache=/var/run/xray-xdup-basekey 53 | if [ ! -f $cache ]; then 54 | xray x25519 | tail -n 1 | sed 's+.* ++g' >$cache 55 | fi 56 | cat $cache 57 | } 58 | 59 | xray_bin() { 60 | if grep -q 'v2ray-sing' ${PLUGIN_FILE} 2>/dev/null; then 61 | which v2ray-sing 62 | else 63 | which xray 64 | fi 65 | } 66 | 67 | random_id() { 68 | $(xray_bin) uuid | cut -c1-4 69 | } 70 | 71 | random_port() { 72 | offset=$($(xray_bin) uuid | tr -d '[a-zA-Z-]' | cut -c1-3 | sed 's+^0*++g') 73 | echo $((offset + 12000)) 2>/dev/null || random_port 74 | } 75 | 76 | validate_server() { 77 | [ "$(uci get $NAME.$1 2>/dev/null)" = "servers" ] 78 | } 79 | 80 | has_valid_server() { 81 | for server in $@; do 82 | validate_server $server && return 0 83 | done 84 | return 1 85 | } 86 | 87 | get_arg_udp() { 88 | uci_bool_by_type transparent_proxy enable_udp && echo "-u" 89 | } 90 | 91 | get_arg_out() { 92 | case "$(uci_get_by_type access_control self_proxy 1)" in 93 | 1) echo "-o" ;; 94 | 2) echo "-O" ;; 95 | esac 96 | } 97 | 98 | get_arg_tnd() { 99 | uci_bool_by_type $1 no_delay && echo "--no-delay" 100 | } 101 | 102 | get_server_ips() { 103 | echo $(uci_get_by_name $1 server) 104 | local alias=$(uci_get_by_name $1 alias) 105 | if echo $alias | grep -q '@'; then 106 | echo $alias | sed 's+.*@++g' 107 | fi 108 | } 109 | 110 | get_lan_hosts() { 111 | uci_bool_by_name $1 enable && 112 | echo "$(uci_get_by_name $1 type),$(uci_get_by_name $1 host)" 113 | } 114 | 115 | xray_cleandns() { 116 | uci_bool_by_type general no_dns_injection && return 0 117 | 118 | rm -f $DNSMASQDIR/xray.conf $DNSMASQDIR/xray-servers.conf 2>/dev/null 119 | ([ -x /etc/init.d/dnsmasq-extra ] && /etc/init.d/dnsmasq reload || /etc/init.d/dnsmasq restart) >/dev/null 2>&1 120 | } 121 | 122 | xray_injectdns() { 123 | uci_bool_by_type general no_dns_injection && return 0 124 | 125 | echo >&2 "# Info: $NAME dnsmasq injecting..." 126 | 127 | DNSconf=$DNSMASQDIR/xray-servers.conf 128 | tmpDNSconf=$DNSMASQDIR/xray.conf 129 | echo "all-servers" >$tmpDNSconf 130 | config_load $NAME 131 | for server in $(config_foreach get_server_ips servers | sort -u | grep -v '[0-9]$'); do 132 | cat <<-EOF >>$tmpDNSconf 133 | ipset=/${server}/xray_spec_dst_bp 134 | server=/${server}/# 135 | server=/${server}/223.5.5.5 136 | server=/${server}/119.29.29.29 137 | server=/${server}/114.114.114.114 138 | server=/${server}/80.80.80.80 139 | server=/${server}/208.67.222.222#443 140 | server=/${server}/208.67.220.220#5353 141 | EOF 142 | done 143 | 144 | (grep -q 'no-resolv' /etc/dnsmasq.conf /etc/dnsmasq.d/* /var/dnsmasq.d/* /var/etc/dnsmasq.conf.* 2 >/dev/null) && 145 | sed "/\/#$/d" -i $tmpDNSconf 146 | sort -u $tmpDNSconf | sed '/\/\//d; /\/127.0.0.1\//d' >$DNSconf 147 | rm -f $tmpDNSconf 148 | 149 | echo "server=/${WATCHDOG_ENDPOINT}/127.0.0.1#$(uci_get_by_type port_forward local_port 5300)" >>$DNSconf 150 | [ -x /etc/init.d/dnsmasq-extra ] || { 151 | echo "server=/${WATCHDOG_ENDPOINT}/208.67.222.222#443" >>$DNSconf 152 | echo "server=/${WATCHDOG_ENDPOINT}/114.114.115.115" >>$DNSconf 153 | echo "server=/${WATCHDOG_ENDPOINT}/80.80.80.80" >>$DNSconf 154 | } 155 | 156 | DNSPROBE_DOMAIN='0.alidns.com' 157 | cat <<-EOF >>$DNSconf 158 | server=/$DNSPROBE_DOMAIN/223.5.5.5 159 | server=/$DNSPROBE_DOMAIN/119.29.29.29 160 | server=/$DNSPROBE_DOMAIN/114.114.114.114 161 | EOF 162 | 163 | ([ -x /etc/init.d/dnsmasq-extra ] && /etc/init.d/dnsmasq reload || /etc/init.d/dnsmasq restart) >/dev/null 2>&1 164 | # wait-for-dns, timeout 10s 165 | if which wait4x >/dev/null 2>&1; then # use [wait4x] 166 | wait4x http http://$DNSPROBE_DOMAIN --no-redirect -q 167 | elif which wait-for >/dev/null 2>&1; then # use [wait-for] 168 | wait-for -t=10s http --url=http://$DNSPROBE_DOMAIN >/dev/null 2>&1 169 | else # use [ping] 170 | for _ in $(seq 10); do if ping -4 -q -c 1 -s 0 -W 1 -w 1 $DNSPROBE_DOMAIN >/dev/null 2>&1; then break; fi; done 171 | fi 172 | echo >&2 "# Info: $NAME dnsmasq injected." 173 | } 174 | 175 | start_rules() { 176 | config_load $NAME 177 | /usr/bin/${NAME}-rules \ 178 | -s "$(for it in $(uci_get_by_type general server); do get_server_ips $it; done | sort -u)" \ 179 | -l "$(uci_get_by_type transparent_proxy local_port 1234)" \ 180 | -B "$(uci_get_by_type access_control wan_bp_list)" \ 181 | -b "$(uci_get_by_type access_control wan_bp_ips)" \ 182 | -W "$(uci_get_by_type access_control wan_fw_list)" \ 183 | -w "$(uci_get_by_type access_control wan_fw_ips) $WATCHDOG_ENDPOINT_IP0 $WATCHDOG_ENDPOINT_IP1" \ 184 | -I "$(uci_get_by_type access_control lan_ifaces)" \ 185 | -d "$(uci_get_by_type access_control lan_target)" \ 186 | -a "$(config_foreach get_lan_hosts lan_hosts)" \ 187 | -e "$(uci_get_by_type access_control ipt_ext)" \ 188 | $(get_arg_out) $(get_arg_udp) 189 | } 190 | 191 | rules() { 192 | pgrep -f $(xray_bin) >/dev/null || return 0 193 | start_rules || /usr/bin/${NAME}-rules -f 194 | } 195 | 196 | gen_config_inbound_redir() { 197 | command -v $(xray_bin) >/dev/null 2>&1 || return 0 198 | uci_bool_by_type 'transparent_proxy' 'enable' && cat <<-EOF 199 | { 200 | "protocol": "dokodemo-door", 201 | "port": $(uci_get_by_type transparent_proxy local_port), 202 | "address": "0.0.0.0", 203 | "settings": { 204 | "network": "tcp,udp", 205 | "followRedirect": true 206 | }, 207 | "sniffing": { 208 | "enabled": true, 209 | "destOverride": ["http", "tls"] 210 | }, 211 | "streamSettings": { 212 | "sockopt": { 213 | "tproxy": "redirect" 214 | } 215 | } 216 | }, 217 | EOF 218 | } 219 | 220 | gen_config_inbound_http() { 221 | command -v $(xray_bin) >/dev/null 2>&1 || return 0 222 | uci_bool_by_type 'http_proxy' 'enable' && cat <<-EOF 223 | { 224 | "protocol": "http", 225 | "port": $(uci_get_by_type http_proxy local_port), 226 | "address": "0.0.0.0", 227 | "sniffing": { 228 | "enabled": true, 229 | "destOverride": ["http", "tls"] 230 | }, 231 | }, 232 | EOF 233 | } 234 | 235 | gen_config_inbound_socks5() { 236 | command -v $(xray_bin) >/dev/null 2>&1 || return 0 237 | uci_bool_by_type 'socks5_proxy' 'enable' && cat <<-EOF 238 | { 239 | "protocol": "socks", 240 | "port": $(uci_get_by_type socks5_proxy local_port), 241 | "address": "0.0.0.0", 242 | "sniffing": { 243 | "enabled": true, 244 | "destOverride": ["http", "tls"] 245 | }, 246 | "settings": { 247 | "udp": true 248 | } 249 | }, 250 | EOF 251 | } 252 | 253 | gen_config_inbound_tunnel() { 254 | command -v $(xray_bin) >/dev/null 2>&1 || return 0 255 | uci_bool_by_type 'port_forward' 'enable' && cat <<-EOF 256 | { 257 | "protocol": "dokodemo-door", 258 | "port": $(uci_get_by_type port_forward local_port), 259 | "address": "0.0.0.0", 260 | "settings": { 261 | "address": "$(uci_get_by_type port_forward destination | sed 's+:.*++g')", 262 | "port": $(uci_get_by_type port_forward destination | sed 's+.*:++g'), 263 | "network": "tcp,udp" 264 | } 265 | }, 266 | EOF 267 | } 268 | 269 | gen_config_inbounds() { 270 | cat <<-EOF | sed 's+, +,\n +g;s+},__$+}+g' 271 | "inbounds": [ 272 | $(gen_config_inbound_redir)$(gen_config_inbound_http)$(gen_config_inbound_socks5)$(gen_config_inbound_tunnel)__ 273 | ], 274 | EOF 275 | } 276 | 277 | gen_stream_setting_key() { 278 | network=$1 279 | security=$2 280 | ws_path=$3 281 | if [ "V${ws_path}" != "V" ]; then 282 | echo -en "\"wsSettings\": { \"path\": \"${ws_path}\" },\n " 283 | fi 284 | if [ "V${network}" = "Vquic" ]; then 285 | echo -e "\"quicSettings\": {},\n \"${security}Settings\"" 286 | else 287 | echo "\"${security}Settings\"" 288 | fi 289 | } 290 | 291 | gen_reality_settings() { 292 | uci_get_by_name $1 security | grep -q 'reality' || return 293 | echo >&2 "# Info: vless@reality[utls@chrome]" 294 | cat <<-EOF 295 | , 296 | "fingerprint": "chrome", 297 | "publicKey": "$(uci_get_by_name $1 public_key)", 298 | "shortId": "$(uci_get_by_name $1 short_id '')", 299 | "spiderX": "/$(random_id)" 300 | EOF 301 | } 302 | 303 | gen_xtls_flow() { 304 | local security=$(uci_get_by_name $1 security | sed 's+@.*$++g' | sed 's+-.*++g') 305 | local flow=$(uci_get_by_name $1 security | sed 's+@.*$++g' | sed 's+.*-++g') 306 | [ "V${security}" == 'Vh2' ] && return 307 | [ "V${flow}" == 'Vxtls' ] && flow='splice' 308 | if [ "V${security}" == 'Vxtls' ]; then 309 | echo -e "\n \"flow\": \"xtls-rprx-${flow}\"," 310 | fi 311 | } 312 | 313 | gen_server_vless_config() { 314 | local network='tcp' 315 | local security=$(uci_get_by_name $1 security 'tls') 316 | if echo $security | grep -q 'reality'; then 317 | if echo ${security} | grep -q '^h2'; then 318 | network='h2' 319 | fi 320 | security='reality' 321 | elif echo $security | grep -q 'vision'; then 322 | security='tls' 323 | else 324 | security=$(echo $security | sed 's+-.*++g') 325 | fi 326 | [ "V${security}" = "Vquic" ] && { 327 | sysctl -w net.core.rmem_max=250000 >/dev/null 328 | network='quic' 329 | security='tls' 330 | } 331 | [ "V${security}" = "Vwss" ] && { 332 | sysctl -w net.core.rmem_max=250000 >/dev/null 333 | network='ws' 334 | security='tls' 335 | ws_path=$(uci_get_by_name $1 ws_path '/') 336 | } 337 | validate_server $1 && { 338 | local serverName=$(uci_get_by_name $1 server_name) 339 | [ "V$serverName" = "V" ] && serverName=$(uci_get_by_name $1 server) 340 | local alias=$(uci_get_by_name $1 alias) 341 | if [ "V$plugin" != "V" ]; then 342 | tag="[$alias]-$(random_id)" 343 | else 344 | tag="[${serverName}-${network}-${security}]-$(random_id)" 345 | fi 346 | echo >&2 "# Debug: OutB-vless-${tag}" 347 | cat <<-EOF 348 | { 349 | "tag": "OutB-vless-${tag}", 350 | "protocol": "$(uci_get_by_name $1 protocol)", 351 | "settings": { 352 | "vnext": [ 353 | { 354 | "address": "$(uci_get_by_name $1 server)", 355 | "port": $(uci_get_by_name $1 server_port), 356 | "users": [ 357 | { 358 | "id": "$(uci_get_by_name $1 id)",$(gen_xtls_flow $1) 359 | "encryption": "none", 360 | "level": 0 361 | } 362 | ] 363 | } 364 | ] 365 | }, 366 | "streamSettings": { 367 | "sockopt": { "mark": 255 }, 368 | "network": "${network}", 369 | "security": "${security}", 370 | $(gen_stream_setting_key ${network} ${security} $(uci_get_by_name $1 ws_path)): { 371 | "serverName": "${serverName}"$(gen_reality_settings $1) 372 | } 373 | } 374 | }, 375 | EOF 376 | } 377 | } 378 | 379 | gen_server_trojan_config() { 380 | local network='tcp' 381 | local security=$(uci_get_by_name $1 security 'tls' | sed 's+-.*++g') 382 | [ "V${security}" = "Vquic" ] && { 383 | sysctl -w net.core.rmem_max=250000 >/dev/null 384 | network='quic' 385 | security='tls' 386 | } 387 | validate_server $1 && { 388 | local serverName=$(uci_get_by_name $1 server_name) 389 | [ "V$serverName" = "V" ] && serverName=$(uci_get_by_name $1 server) 390 | local alias=$(uci_get_by_name $1 alias) 391 | if [ "V$plugin" != "V" ]; then 392 | tag="[$alias]-$(random_id)" 393 | else 394 | tag="[${serverName}]-$(random_id)" 395 | fi 396 | echo >&2 "# Debug: OutB-trojan-${tag}" 397 | cat <<-EOF 398 | { 399 | "tag": "OutB-trojan-${tag}", 400 | "protocol": "$(uci_get_by_name $1 protocol)", 401 | "settings": { 402 | "servers": [ 403 | { 404 | "address": "$(uci_get_by_name $1 server)", 405 | "port": $(uci_get_by_name $1 server_port), 406 | "password": "$(uci_get_by_name $1 id)", 407 | "level": 0 408 | } 409 | ] 410 | }, 411 | "streamSettings": { 412 | "sockopt": { "mark": 255 }, 413 | "network": "${network}", 414 | "security": "${security}", 415 | $(gen_stream_setting_key ${network} ${security}): { 416 | "serverName": "${serverName}" 417 | } 418 | } 419 | }, 420 | EOF 421 | } 422 | } 423 | 424 | gen_server_shadowsocks_config() { 425 | validate_server $1 && { 426 | local alias=$(uci_get_by_name $1 alias) 427 | if [ "V$plugin" != "V" ]; then 428 | tag="[$alias]-$(random_id)" 429 | else 430 | tag="[$(uci_get_by_name $1 server)]-$(random_id)" 431 | fi 432 | echo >&2 "# Debug: OutB-ss-${tag}" 433 | cat <<-EOF 434 | { 435 | "tag": "OutB-ss-${tag}", 436 | "protocol": "$(uci_get_by_name $1 protocol)", 437 | "settings": {$(get_shadowsocks_plugin_config $1) 438 | "servers": [ 439 | { 440 | "address": "$(uci_get_by_name $1 server)", 441 | "port": $(uci_get_by_name $1 server_port), 442 | "password": "$(uci_get_by_name $1 id)", 443 | "method": "$(uci_get_by_name $1 method)", 444 | "uot": $(uci_bool_by_name $1 uot && echo true || echo false) 445 | } 446 | ] 447 | }, 448 | "streamSettings": { "sockopt": { "mark": 255 } } 449 | }, 450 | EOF 451 | } 452 | } 453 | 454 | gen_server_socks_config() { 455 | validate_server $1 && { 456 | local alias=$(uci_get_by_name $1 alias) 457 | local plugin=$(uci_get_by_name $1 plugin) 458 | local plugin_opts=$(uci_get_by_name $1 plugin_opts) 459 | local server_port=$(uci_get_by_name $1 server_port) 460 | if [ "V$server_port" = "V_RANDDOM_" ]; then 461 | server_port=$(random_port) 462 | [ "V$server_port" = "V" ] && server_port=12000 463 | fi 464 | if [ "V$plugin" != "V" ]; then 465 | tag="[$(basename ${plugin})]-$(random_id)" 466 | plugin=$(which $plugin) 467 | echo >&2 "# Info: socks(:$server_port)-extra-plugin[$plugin]" 468 | echo $plugin >>${PLUGIN_FILE} 469 | echo "${plugin} ${plugin_opts} >/var/log/xray.$1.log 2>&1 &" | 470 | sed "s+_RANDDOM_+${server_port}+g" >>${PLUGIN_FILE}.daemon.sh 471 | else 472 | tag="[$alias]-$(random_id)" 473 | fi 474 | echo >&2 "# Debug: OutB-socks-${tag}" 475 | cat <<-EOF 476 | { 477 | "tag": "OutB-socks-${tag}", 478 | "protocol": "$(uci_get_by_name $1 protocol)", 479 | "settings": { 480 | "servers": [ 481 | { 482 | "address": "$(uci_get_by_name $1 server)", 483 | "port": ${server_port} 484 | } 485 | ] 486 | }, 487 | "streamSettings": { "sockopt": { "mark": 255 } } 488 | }, 489 | EOF 490 | } 491 | } 492 | 493 | get_shadowsocks_plugin_config() { 494 | local plugin=$(uci_get_by_name $1 plugin) 495 | local plugin_opts=$(uci_get_by_name $1 plugin_opts) 496 | if [ "V$plugin" != "V" ]; then 497 | if which v2ray-sing >/dev/null 2>&1; then 498 | echo '# v2ray-sing' >>${PLUGIN_FILE} 499 | else 500 | echo >&2 "# Err: [https://github.com/SagerNet/v2ray-core] is needed to support SIP003" 501 | exit 1 502 | fi 503 | if [ "V$plugin" = "Vv2ray-plugin" -o "V$plugin" = "Vxray-plugin" ]; then 504 | plugin="v2ray-plugin" 505 | else 506 | plugin=$(which $plugin) 507 | echo $plugin >>${PLUGIN_FILE} 508 | fi 509 | echo >&2 "# Info: SIP003[$plugin]" 510 | echo -e "\n \"plugin\": \"$plugin\"," 511 | if [ -n "$plugin_opts" ]; then 512 | echo " \"pluginOpts\": \"$plugin_opts\"," 513 | fi 514 | fi 515 | } 516 | 517 | gen_server_config() { 518 | local protocol=$(uci_get_by_name $1 protocol) 519 | echo >&2 "# Info: config@protocol[$protocol]" 520 | if [ "V${protocol}" = "Vsocks" ]; then 521 | gen_server_socks_config $1 522 | elif [ "V${protocol}" = "Vvless" ]; then 523 | gen_server_vless_config $1 524 | elif [ "V${protocol}" = "Vtrojan" ]; then 525 | gen_server_trojan_config $1 526 | elif [ "V${protocol}" = "Vshadowsocks" ]; then 527 | gen_server_shadowsocks_config $1 528 | else 529 | echo >&2 "# Err: protocol[$protocol] not supported!" 530 | exit 1 531 | fi 532 | } 533 | 534 | gen_config_outbounds() { 535 | cat <<-EOF | sed 's+, +,\n +g' 536 | "outbounds": [ 537 | $(for server in $(uci_get_by_type general server); do gen_server_config $server; done) 538 | { 539 | "protocol": "blackhole", 540 | "settings": {}, 541 | "tag": "blackhole" 542 | } 543 | ], 544 | EOF 545 | } 546 | 547 | get_rules_http3() { 548 | uci_bool_by_type transparent_proxy disable_http3 || return 549 | echo >&2 "# Info: disable[http3]" 550 | cat <<-EOF 551 | 552 | { 553 | "type": "field", 554 | "network": "udp", 555 | "port": 443, 556 | "outboundTag": "blackhole" 557 | }, 558 | EOF 559 | } 560 | 561 | gen_config_file() { 562 | local config_file=/var/etc/$NAME.json 563 | local balancer_name="balancer-$(random_id)" 564 | local strategy="$(uci_get_by_type general strategy leastLoad)" 565 | [ "V${strategy}" = "VleastLoad" ] && $(xray_bin) version | grep -q 'Xray' && { 566 | strategy="leastPing" 567 | } 568 | cat <<-EOF >$config_file 569 | { 570 | $(gen_config_inbounds) 571 | $(gen_config_outbounds) 572 | "routing": { 573 | "rules": [$(get_rules_http3) 574 | { 575 | "type": "field", 576 | "network": "tcp,udp", 577 | "balancerTag": "${balancer_name}" 578 | } 579 | ], 580 | "balancers": [{ 581 | "tag": "${balancer_name}", 582 | "selector": ["OutB"], 583 | "strategy": { 584 | "type": "${strategy}" 585 | } 586 | }] 587 | }, 588 | "observatory": { 589 | "subjectSelector": [ "OutB" ], 590 | "probeURL": "https://${PROBE_ENDPOINT}/success.txt", 591 | "probeInterval": "9s" 592 | }, 593 | "log": { 594 | "loglevel": "warning" 595 | } 596 | } 597 | EOF 598 | echo $config_file 599 | } 600 | 601 | xray_plugin_daemon() { 602 | [ -e ${PLUGIN_FILE} ] && kill_all $(sort -u ${PLUGIN_FILE} | grep -v '^#') 603 | [ -e ${PLUGIN_FILE}.daemon.sh ] && { 604 | chmod a+x ${PLUGIN_FILE}.daemon.sh 605 | ${PLUGIN_FILE}.daemon.sh 606 | } 607 | echo >&2 "# Info: xray-plugin daemon init." 608 | } 609 | 610 | xray_daemon() { 611 | command -v $(xray_bin) >/dev/null 2>&1 || return 0 612 | if [ -e /proc/sys/fs/nr_open ] && [ -e /proc/sys/fs/file-max ]; then 613 | [ $(cat /proc/sys/fs/nr_open) -lt 1048576 ] && echo 1048576 >/proc/sys/fs/nr_open # 1048576=2^31 614 | [ $(cat /proc/sys/fs/file-max) -lt 2097152 ] && echo 2097152 >/proc/sys/fs/file-max # 2097152=2^32 615 | limit=$(cat /proc/sys/fs/nr_open) 616 | else 617 | limit=65535 618 | fi 619 | while (! ulimit -SHn $limit) && [ $limit -gt 1024 ]; do limit=$((limit / 2)); done 620 | ulimit -SHn $limit 621 | config_file=$(gen_config_file) 622 | cd /var/run/xrayservice 623 | xray_plugin_daemon 2>/dev/null 624 | (XRAY_XUDP_BASEKEY=$(xray_xudp_basekey) $(xray_bin) run -c ${config_file} >/var/log/xray.log 2>&1) & 625 | cd - >/dev/null 626 | # wait-for-dns, timeout 10s 627 | if which wait4x >/dev/null 2>&1; then # use [wait4x] 628 | wait4x tcp 127.0.0.1:$(sed -n 's/.*"port".*: *\(.*\),/\1/p' ${config_file} | head -n1) --connection-timeout=300ms -q 629 | elif which wait-for >/dev/null 2>&1; then # use [wait-for] 630 | wait-for -t=10s net --address 127.0.0.1:$(sed -n 's/.*"port".*: *\(.*\),/\1/p' ${config_file} | head -n1) >/dev/null 2>&1 631 | else # use [pgrep] 632 | for _ in $(seq 10); do if pgrep -f $(xray_bin) >/dev/null; then break; else sleep 1; fi; done 633 | fi 634 | pgrep -f $(xray_bin) >/dev/null 635 | } 636 | 637 | start() { 638 | local t0=$(date '+%s') 639 | echo >&2 "# Info: starting..." 640 | pgrep -f $(xray_bin) >/dev/null && return 0 641 | uci_bool_by_type 'transparent_proxy' 'enable' || 642 | uci_bool_by_type 'port_forward' 'enable' || 643 | uci_bool_by_type 'http_proxy' 'enable' || 644 | uci_bool_by_type 'socks5_proxy' 'enable' || 645 | return 0 646 | 647 | mkdir -p /var/run/xrayservice /var/etc $DNSMASQDIR 648 | has_valid_server $(uci_get_by_type general server) && { 649 | xray_injectdns 650 | xray_daemon 651 | echo >&2 "# Info: xray daemon init." 652 | 653 | uci_bool_by_type 'transparent_proxy' 'enable' && { 654 | rules 655 | add_cron 656 | echo >&2 "# Info: transparent proxy init." 657 | } 658 | } 659 | echo >&2 "# Info: started. CostTime: $(($(date '+%s') - $t0))s" 660 | } 661 | 662 | boot() { 663 | echo 'exit 0' >/var/etc/$NAME.include 664 | local delay=$(uci_get_by_type general startup_delay 0) 665 | (sleep $delay && start >/dev/null 2>&1) & 666 | return 0 667 | } 668 | 669 | kill_all() { 670 | for it in $@; do 671 | kill -9 $(pgrep -f $it) >/dev/null 2>&1 672 | done 673 | } 674 | 675 | stop() { 676 | local t0=$(date '+%s') 677 | echo >&2 "# Info: stopping..." 678 | kill_all $(xray_bin) 679 | /usr/bin/${NAME}-rules -f 680 | if [ -f ${PLUGIN_FILE} ]; then 681 | kill_all $(sort -u ${PLUGIN_FILE}) 682 | rm -f ${PLUGIN_FILE}* 683 | fi 684 | rm -rf /var/log/xray*.log 685 | rm -rf /var/run/xrayservice 686 | xray_cleandns 687 | del_cron 688 | kill_all $(xray_bin) 689 | echo >&2 "# Info: stopped. CostTime: $(($(date '+%s') - $t0))s" 690 | } 691 | 692 | add_cron() { 693 | [ -f $CRON_FILE ] || return 0 694 | uci_bool_by_type transparent_proxy no_healthcheck && return 0 695 | 696 | sed -i '/xray_healthcheck/d' $CRON_FILE 697 | echo '0 */3 * * * rm -f /var/log/xray_healthcheck.log 2>&1' >>$CRON_FILE 698 | echo '* * * * * /etc/init.d/xray healthcheck >> /var/log/xray_healthcheck.log 2>&1' >>$CRON_FILE 699 | /etc/init.d/cron restart 700 | } 701 | 702 | del_cron() { 703 | [ -f $CRON_FILE ] || return 0 704 | uci_bool_by_type transparent_proxy no_healthcheck && return 0 705 | 706 | sed -i '/xray_healthcheck/d' $CRON_FILE 707 | /etc/init.d/cron restart 708 | } 709 | 710 | healthcheck() { 711 | command -v $(xray_bin) >/dev/null 2>&1 || return 1 712 | has_valid_server $(uci_get_by_type general server) && uci_bool_by_type 'transparent_proxy' 'enable' || return 1 713 | uci_bool_by_type transparent_proxy no_healthcheck && return 0 714 | 715 | LOGTIME=$(date "+%Y-%m-%d %H:%M:%S") 716 | pgrep -f "/var/etc/$NAME.json" >/dev/null 2>&1 || { 717 | echo "[${LOGTIME}] Problem decteted, restarting ${NAME}..." 718 | stop >/dev/null 2>&1 719 | start >/dev/null 2>&1 720 | return 0 721 | } 722 | iptables -n -t nat -L PREROUTING | grep -q '_SPEC_LAN_DG' || { 723 | echo "[${LOGTIME}] Problem decteted, restarting ${NAME}..." 724 | stop >/dev/null 2>&1 725 | start >/dev/null 2>&1 726 | return 0 727 | } 728 | 729 | cat_connect() { 730 | target="$1" 731 | retry=${2:-1} 732 | timeout=5 733 | [ $retry -lt 1 ] && return 1 734 | if which wait4x >/dev/null 2>&1; then # use [wait4x] 735 | wait4x -i300ms -t5s http $target 736 | elif which wait-for >/dev/null 2>&1; then # use [wait-for] 737 | wait-for -t=5s http --url=$target >/dev/null 2>&1 738 | else # use [curl] 739 | ret_code=$(curl -s --connect-timeout $timeout "$target" -w %{http_code} -o /dev/null | tail -n1) 740 | # echo -n "[ $retry $ret_code ] " 741 | [ "x$ret_code" = "x200" -o "x$ret_code" = "x204" ] && return 0 || sleep 1 && cat_connect $target $((retry - 1)) 742 | fi 743 | } 744 | 745 | TRPORT=$(uci_get_by_type transparent_proxy local_port 1234) 746 | DNSPOD=119.29.29.98 #DNSPOD HTTPDNS (Inside GFW) 747 | 748 | # DNSCHECK 749 | if [ "Z$(ping -4 -q -c 1 -s 0 -W 1 -w 1 ${WATCHDOG_ENDPOINT} 2>/dev/null | sed '1{s/[^(]*(//;s/).*//;q}')" = "Z" ]; then 750 | iptables -t nat -I OUTPUT -p tcp -d $DNSPOD -j RETURN 751 | cat_connect "http://${DNSPOD}/d" 752 | if [ "Z$?" = "Z0" ]; then 753 | echo "[${LOGTIME}] Problem-DNS decteted, restarting ${NAME}..." 754 | [ -x /etc/init.d/dnsmasq-extra ] && /etc/init.d/dnsmasq-extra restart || /etc/init.d/dnsmasq restart 755 | stop >/dev/null 2>&1 756 | start >/dev/null 2>&1 757 | else 758 | echo '['$LOGTIME'] Network Problem. Do nothing.' 759 | fi 760 | while iptables -t nat -D OUTPUT -p tcp -d $DNSPOD -j RETURN 2>/dev/null; do :; done 761 | return 0 762 | fi 763 | 764 | # iptables -t nat -I OUTPUT -p tcp -d $WATCHDOG_ENDPOINT_IP0 -j REDIRECT --to-port $TRPORT 765 | # iptables -t nat -I OUTPUT -p tcp -d $WATCHDOG_ENDPOINT_IP1 -j REDIRECT --to-port $TRPORT 766 | iptables -t nat -I OUTPUT -p tcp -d $DNSPOD -j RETURN 767 | cat_connect "https://${WATCHDOG_ENDPOINT}/cdn-cgi/trace" 3 768 | if [ "Z$?" = "Z0" ]; then 769 | echo "[${LOGTIME}] ${NAME} No Problem." 770 | else 771 | # cat_connect "http://wifi.vivo.com/generate_204" 772 | # cat_connect "http://wifi.vivo.com.cn/generate_204" 773 | # cat_connect "http://www.qualcomm.cn/generate_204" 774 | # cat_connect "http://connectivitycheck.platform.hicloud.com/generate_204" 775 | cat_connect "http://${DNSPOD}/d" 776 | if [ "Z$?" = "Z0" ]; then 777 | echo "[${LOGTIME}] Problem decteted, restarting ${NAME}..." 778 | [ -x /etc/init.d/haproxy-tcp ] && /etc/init.d/haproxy-tcp restart >/dev/null 2>&1 779 | stop >/dev/null 2>&1 780 | start >/dev/null 2>&1 781 | else 782 | echo '['$LOGTIME'] Network Problem. Do nothing.' 783 | fi 784 | fi 785 | 786 | # while iptables -t nat -D OUTPUT -p tcp -d $WATCHDOG_ENDPOINT_IP0 -j REDIRECT --to-port $TRPORT 2>/dev/null; do :; done 787 | # while iptables -t nat -D OUTPUT -p tcp -d $WATCHDOG_ENDPOINT_IP1 -j REDIRECT --to-port $TRPORT 2>/dev/null; do :; done 788 | while iptables -t nat -D OUTPUT -p tcp -d $DNSPOD -j RETURN 2>/dev/null; do :; done 789 | return 0 790 | } 791 | -------------------------------------------------------------------------------- /root/etc/uci-defaults/luci-xray: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | uci get xray.@general[-1] >/dev/null 2>&1 || \ 3 | uci add xray general >/dev/null 2>&1 4 | uci get xray.@transparent_proxy[-1] >/dev/null 2>&1 || \ 5 | uci add xray transparent_proxy >/dev/null 2>&1 6 | uci get xray.@http_proxy[-1] >/dev/null 2>&1 || \ 7 | uci add xray http_proxy >/dev/null 2>&1 8 | uci get xray.@socks5_proxy[-1] >/dev/null 2>&1 || \ 9 | uci add xray socks5_proxy >/dev/null 2>&1 10 | uci get xray.@port_forward[-1] >/dev/null 2>&1 || \ 11 | uci add xray port_forward >/dev/null 2>&1 12 | uci get xray.@access_control[-1] >/dev/null 2>&1 || \ 13 | uci add xray access_control >/dev/null 2>&1 14 | uci commit xray 15 | uci -q batch <<-EOF >/dev/null 16 | delete ucitrack.@xray[-1] 17 | add ucitrack xray 18 | set ucitrack.@xray[-1].init=xray 19 | commit ucitrack 20 | delete firewall.xray 21 | set firewall.xray=include 22 | set firewall.xray.type=script 23 | set firewall.xray.path=/var/etc/xray.include 24 | set firewall.xray.reload=1 25 | commit firewall 26 | EOF 27 | exit 0 28 | -------------------------------------------------------------------------------- /root/usr/bin/xray-rules: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014-2017 Jian Chang 4 | # 2017-2023 honwen https://github.com/honwen 5 | # 6 | # This is free software, licensed under the GNU General Public License v3. 7 | # See /LICENSE for more information. 8 | # 9 | 10 | usage() { 11 | cat <<-EOF 12 | Usage: xray-rules [options] 13 | 14 | Valid options are: 15 | 16 | -s ip address of xray remote server 17 | -l port number of xray local server 18 | -S ip address of xray remote UDP server 19 | -L port number of xray local UDP server 20 | -B a file whose content is bypassed ip list 21 | -b wan ip of will be bypassed 22 | -W a file whose content is forwarded ip list 23 | -w wan ip of will be forwarded 24 | -I proxy only for the given interface 25 | -d the default target of lan access control 26 | -a lan ip of access control, need a prefix to 27 | define proxy type 28 | -e extra arguments for iptables 29 | -o apply the rules to the OUTPUT chain 30 | -O apply the global rules to the OUTPUT chain 31 | -u enable udprelay mode, TPROXY is required 32 | -U enable udprelay mode, using different IP 33 | and ports for TCP and UDP 34 | -f flush the rules 35 | -h show this help message and exit 36 | EOF 37 | exit $1 38 | } 39 | 40 | loger() { 41 | # 1.alert 2.crit 3.err 4.warn 5.notice 6.info 7.debug 42 | logger -st xray-rules[$$] -p$1 $2 43 | } 44 | 45 | fw_reinit() { 46 | uci -q show firewall | sed -n 's/.*path=//p' | sed -n '/adbyby\|koolproxy\|dnsmasq/p' | tr -d \' | while read init; do 47 | sh $init restart >/dev/null 2>&1 48 | done 49 | return 0 50 | } 51 | 52 | flush_rules() { 53 | iptables-save -c | grep -v "XRAY_SPEC" | sed '/[^ ]--/d' | uniq | iptables-restore -w -c 54 | uci -q show firewall | sed -n 's/.*path=//p' | sed -n '/gargoyle/p' | tr -d \' | while read init; do 55 | sh $init restart >/dev/null 2>&1 56 | done 57 | 58 | if command -v ip >/dev/null 2>&1; then 59 | ip rule del fwmark 1 lookup 100 2>/dev/null 60 | ip route del local default dev lo table 100 2>/dev/null 61 | fi 62 | for setname in $(ipset -n list | grep "xray_spec"); do 63 | ipset destroy $setname 2>/dev/null 64 | done 65 | FWI=$(uci get firewall.xray.path 2>/dev/null) 66 | [ -n "$FWI" ] && echo '# firewall include file' >$FWI 67 | return 0 68 | } 69 | 70 | ipset_init() { 71 | ipset -! restore <<-EOF || return 1 72 | create xray_spec_src_ac hash:ip hashsize 64 73 | create xray_spec_src_bp hash:ip hashsize 64 74 | create xray_spec_src_fw hash:ip hashsize 64 75 | create xray_spec_dst_sp hash:net hashsize 64 76 | create xray_spec_dst_bp hash:net hashsize 64 77 | create xray_spec_dst_fw hash:net hashsize 64 78 | $(gen_lan_host_ipset_entry) 79 | $(gen_special_purpose_ip | sed -e "s/^/add xray_spec_dst_sp /") 80 | $(sed -e "s/^/add xray_spec_dst_bp /" ${WAN_BP_LIST:=/dev/null} 2>/dev/null) 81 | $(for ip in $WAN_BP_IP; do echo "add xray_spec_dst_bp $ip"; done) 82 | $(sed -e "s/^/add xray_spec_dst_fw /" ${WAN_FW_LIST:=/dev/null} 2>/dev/null) 83 | $(for ip in $WAN_FW_IP; do echo "add xray_spec_dst_fw $ip"; done) 84 | EOF 85 | return 0 86 | } 87 | 88 | ipt_nat() { 89 | include_ac_rules nat 90 | ipt="iptables -w -t nat" 91 | $ipt -A XRAY_SPEC_WAN_FW -p tcp \ 92 | -j REDIRECT --to-ports $local_port || return 1 93 | if [ -n "$OUTPUT" ]; then 94 | $ipt -N XRAY_SPEC_WAN_DG 95 | $ipt -A XRAY_SPEC_WAN_DG -m mark --mark 0xff -j RETURN 96 | $ipt -A XRAY_SPEC_WAN_DG -m set --match-set xray_spec_dst_sp dst -j RETURN 97 | $ipt -A XRAY_SPEC_WAN_DG -p tcp $EXT_ARGS -j $OUTPUT 98 | $ipt -I OUTPUT 1 -p tcp -j XRAY_SPEC_WAN_DG 99 | fi 100 | return $? 101 | } 102 | 103 | ipt_mangle() { 104 | [ -n "$TPROXY" ] || return 0 105 | if !(lsmod | grep -q TPROXY && command -v ip >/dev/null); then 106 | loger 4 "TPROXY or ip not found." 107 | return 0 108 | fi 109 | ip rule add fwmark 1 lookup 100 110 | ip route add local default dev lo table 100 111 | include_ac_rules mangle 112 | iptables -w -t mangle -A XRAY_SPEC_WAN_FW -p udp \ 113 | -j TPROXY --on-port $LOCAL_PORT --tproxy-mark 0x01/0x01 114 | return $? 115 | } 116 | 117 | export_ipt_rules() { 118 | [ -n "$FWI" ] || return 0 119 | cat <<-CAT >>$FWI 120 | iptables-save -c | grep -v "XRAY_SPEC" | sed '/[^ ]--/d' | uniq | iptables-restore -w -c 121 | 122 | iptables-restore -w -n <<-EOF 123 | $(iptables-save | grep -E "XRAY_SPEC|^\*|^COMMIT" |\ 124 | sed -e "s/^-A \(OUTPUT\|PREROUTING\)/-I \1 1/") 125 | EOF 126 | 127 | uci -q show firewall | sed -n 's/.*path=//p' | sed -n '/gargoyle\|adbyby\|koolproxy\|dnsmasq/p' | tr -d \' | while read init; do 128 | sh \$init restart >/dev/null 2>&1 129 | done 130 | return 0 131 | CAT 132 | return $? 133 | } 134 | 135 | gen_lan_host_ipset_entry() { 136 | for host in $LAN_HOSTS; do 137 | case "${host:0:1}" in 138 | b|B) 139 | echo add xray_spec_src_bp ${host:2} 140 | ;; 141 | g|G) 142 | echo add xray_spec_src_fw ${host:2} 143 | ;; 144 | n|N) 145 | echo add xray_spec_src_ac ${host:2} 146 | ;; 147 | esac 148 | done 149 | } 150 | 151 | gen_special_purpose_ip() { 152 | cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" 153 | 0.0.0.0/8 154 | 10.0.0.0/8 155 | 100.64.0.0/10 156 | 127.0.0.0/8 157 | 169.254.0.0/16 158 | 172.16.0.0/12 159 | 192.0.0.0/24 160 | 192.0.2.0/24 161 | 192.31.196.0/24 162 | 192.52.193.0/24 163 | 192.88.99.0/24 164 | 192.168.0.0/16 165 | 192.175.48.0/24 166 | 198.18.0.0/15 167 | 198.51.100.0/24 168 | 203.0.113.0/24 169 | 224.0.0.0/4 170 | 240.0.0.0/4 171 | 255.255.255.255 172 | $server 173 | $SERVER 174 | EOF 175 | } 176 | 177 | include_ac_rules() { 178 | ipt_chain=$1 179 | local protocol=$([ "$1" = "mangle" ] && echo udp || echo tcp) 180 | iptables-restore -w -n <<-EOF 181 | *$1 182 | :XRAY_SPEC_LAN_DG - [0:0] 183 | :XRAY_SPEC_LAN_AC - [0:0] 184 | :XRAY_SPEC_WAN_AC - [0:0] 185 | :XRAY_SPEC_WAN_FW - [0:0] 186 | -A XRAY_SPEC_LAN_DG -m set --match-set xray_spec_dst_sp dst -j RETURN 187 | -A XRAY_SPEC_LAN_DG -p $protocol $EXT_ARGS -j XRAY_SPEC_LAN_AC 188 | -A XRAY_SPEC_LAN_AC -m set --match-set xray_spec_src_bp src -j RETURN 189 | -A XRAY_SPEC_LAN_AC -m set --match-set xray_spec_src_fw src -j XRAY_SPEC_WAN_FW 190 | -A XRAY_SPEC_LAN_AC -m set --match-set xray_spec_src_ac src -j XRAY_SPEC_WAN_AC 191 | -A XRAY_SPEC_LAN_AC -j ${LAN_TARGET:=XRAY_SPEC_WAN_AC} 192 | -A XRAY_SPEC_WAN_AC -m set --match-set xray_spec_dst_fw dst -j XRAY_SPEC_WAN_FW 193 | -A XRAY_SPEC_WAN_AC -m set --match-set xray_spec_dst_bp dst -j RETURN 194 | -A XRAY_SPEC_WAN_AC -j XRAY_SPEC_WAN_FW 195 | $(gen_prerouting_rules $protocol) 196 | COMMIT 197 | EOF 198 | if [ "Z${WAN_BP_LIST}" = "Z/dev/flag_gfwlist" ]; then 199 | [ $(ipset list -n | grep -c gfwlist) -lt 1 ] && /etc/init.d/dnsmasq-extra restart 200 | idx=$(($(iptables -w -t $ipt_chain -L XRAY_SPEC_WAN_AC | grep all | sed -n -e '/xray_spec_dst_bp/=') +1)) 201 | iptables -w -t $ipt_chain -I XRAY_SPEC_WAN_AC $idx -m set ! --match-set gfwlist dst -j RETURN 202 | fi 203 | } 204 | 205 | gen_prerouting_rules() { 206 | [ -z "$IFNAMES" ] && echo -I PREROUTING 1 -p $1 -j XRAY_SPEC_LAN_DG 207 | for ifname in $IFNAMES; do 208 | echo -I PREROUTING 1 -i $ifname -p $1 -j XRAY_SPEC_LAN_DG 209 | done 210 | } 211 | 212 | resolveip() { 213 | if echo $1 | grep -q '[0-9]$'; then 214 | echo $1 215 | else 216 | ping -q -c 1 -s 0 -W 1 -w 1 $1 2>/dev/null | sed '1{s/[^(]*(//; s/).*//;q}' | sed 's/[^(]*(//; s/).*//' 217 | fi 218 | } 219 | 220 | while getopts ":s:l:S:L:B:b:W:w:I:d:a:e:oOuUfh" arg; do 221 | case "$arg" in 222 | s) 223 | server=$(for it in $(echo -n $OPTARG | tr ' ' '\n' | sort -u); do resolveip $it; done) 224 | ;; 225 | l) 226 | local_port=$OPTARG 227 | ;; 228 | S) 229 | SERVER=$(for it in $(echo -n $OPTARG | tr ' ' '\n' | sort -u); do resolveip $it; done) 230 | ;; 231 | L) 232 | LOCAL_PORT=$OPTARG 233 | ;; 234 | B) 235 | WAN_BP_LIST=$OPTARG 236 | ;; 237 | b) 238 | WAN_BP_IP=$OPTARG 239 | ;; 240 | W) 241 | WAN_FW_LIST=$OPTARG 242 | ;; 243 | w) 244 | WAN_FW_IP=$OPTARG 245 | ;; 246 | I) 247 | IFNAMES=$OPTARG 248 | ;; 249 | d) 250 | LAN_TARGET=$OPTARG 251 | ;; 252 | a) 253 | LAN_HOSTS=$OPTARG 254 | ;; 255 | e) 256 | EXT_ARGS=$OPTARG 257 | ;; 258 | o) 259 | OUTPUT=XRAY_SPEC_WAN_AC 260 | ;; 261 | O) 262 | OUTPUT=XRAY_SPEC_WAN_FW 263 | ;; 264 | u) 265 | TPROXY=1 266 | ;; 267 | U) 268 | TPROXY=2 269 | ;; 270 | f) 271 | flush_rules 272 | exit 0 273 | ;; 274 | h) 275 | usage 0 276 | ;; 277 | esac 278 | done 279 | 280 | [ -z "$server" -o -z "$local_port" ] && usage 2 281 | 282 | if [ "$TPROXY" = 1 ]; then 283 | unset SERVER 284 | LOCAL_PORT=$local_port 285 | elif [ "$TPROXY" = 2 ]; then 286 | : ${SERVER:?"You must assign an ip for the udp relay server."} 287 | : ${LOCAL_PORT:?"You must assign a port for the udp relay server."} 288 | fi 289 | 290 | flush_rules && ipset_init && ipt_nat && ipt_mangle && fw_reinit && export_ipt_rules 291 | RET=$? 292 | [ "$RET" = 0 ] || loger 3 "Start failed!" 293 | exit $RET 294 | -------------------------------------------------------------------------------- /root/usr/share/rpcd/acl.d/luci-app-xray.json: -------------------------------------------------------------------------------- 1 | { 2 | "luci-app-xray": { 3 | "description": "Grant UCI access for luci-app-xray", 4 | "read": { 5 | "uci": [ "xray" ] 6 | }, 7 | "write": { 8 | "uci": [ "xray" ] 9 | } 10 | } 11 | } 12 | --------------------------------------------------------------------------------