[
  {
    "path": ".github/workflows/release.yml",
    "content": "name: Main\n\non: push\n\npermissions:\n  contents: write\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: checkout\n        uses: actions/checkout@v3\n        with:\n          fetch-depth: 0\n      - name: get ver\n        run: |\n          echo \"$(cat v2ray.sh | grep ver=)\" >> $GITHUB_ENV\n          echo \"old=$(git tag | tail -n1)\" >> $GITHUB_ENV\n      # - name: test\n      #   if: env.is_sh_ver == env.old \n      #   run: |\n      #     echo not found new version.\n      #     exit 1\n      - name: zip\n        run: zip -9vr code.zip . -x .\\*\n      - name: release\n        uses: softprops/action-gh-release@v1\n        with:\n          files: code.zip\n          tag_name: ${{ env.is_sh_ver }}\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# 介绍\n\n最好用的 V2Ray 一键安装脚本 &amp; 管理脚本\n\n# 特点\n\n- 快速安装\n- 超级好用\n- 零学习成本\n- 自动化 TLS\n- 简化所有流程\n- 屏蔽 BT\n- 屏蔽中国 IP\n- 使用 API 操作\n- 兼容 V2Ray 命令\n- 强大的快捷参数\n- 支持所有常用协议\n- 一键添加 Shadowsocks\n- 一键添加 VMess-(TCP/mKCP/QUIC)\n- 一键添加 VMess-(WS/H2/gRPC)-TLS\n- 一键添加 VLESS-(WS/H2/gRPC)-TLS\n- 一键添加 Trojan-(WS/H2/gRPC)-TLS\n- 一键添加 VMess-(TCP/mKCP/QUIC) 动态端口\n- 一键启用 BBR\n- 一键更改伪装网站\n- 一键更改 (端口/UUID/密码/域名/路径/加密方式/SNI/动态端口/等...)\n- 还有更多...\n\n# 设计理念\n\n设计理念为：**高效率，超快速，极易用**\n\n脚本基于作者的自身使用需求，以 **多配置同时运行** 为核心设计\n\n并且专门优化了，添加、更改、查看、删除、这四项常用功能\n\n你只需要一条命令即可完成 添加、更改、查看、删除、等操作\n\n例如，添加一个配置仅需不到 1 秒！瞬间完成添加！其他操作亦是如此！\n\n脚本的参数非常高效率并且超级易用，请掌握参数的使用\n\n# 脚本说明\n\n[V2Ray 一键安装脚本](https://github.com/233boy/v2ray/wiki/V2Ray%E4%B8%80%E9%94%AE%E5%AE%89%E8%A3%85%E8%84%9A%E6%9C%AC)\n\n# 搭建教程\n\n[V2Ray搭建详细图文教程](https://github.com/233boy/v2ray/wiki/V2Ray%E6%90%AD%E5%BB%BA%E8%AF%A6%E7%BB%86%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B)\n\n# 帮助\n\n使用: `v2ray help`\n\n```\nV2Ray script v4.21 by 233boy\nUsage: v2ray [options]... [args]...\n\n基本:\n   v, version                                      显示当前版本\n   ip                                              返回当前主机的 IP\n   get-port                                        返回一个可用的端口\n\n一般:\n   a, add [protocol] [args... | auto]              添加配置\n   c, change [name] [option] [args... | auto]      更改配置\n   d, del [name]                                   删除配置**\n   i, info [name]                                  查看配置\n   qr [name]                                       二维码信息\n   url [name]                                      URL 信息\n   log                                             查看日志\n   logerr                                          查看错误日志\n\n更改:\n   dp, dynamicport [name] [start | auto] [end]     更改动态端口\n   full [name] [...]                               更改多个参数\n   id [name] [uuid | auto]                         更改 UUID\n   host [name] [domain]                            更改域名\n   port [name] [port | auto]                       更改端口\n   path [name] [path | auto]                       更改路径\n   passwd [name] [password | auto]                 更改密码\n   type [name] [type | auto]                       更改伪装类型\n   method [name] [method | auto]                   更改加密方式\n   seed [name] [seed | auto]                       更改 mKCP seed\n   new [name] [...]                                更改协议\n   web [name] [domain]                             更改伪装网站\n\n进阶:\n   dns [...]                                       设置 DNS\n   dd, ddel [name...]                              删除多个配置**\n   fix [name]                                      修复一个配置\n   fix-all                                         修复全部配置\n   fix-caddyfile                                   修复 Caddyfile\n   fix-config.json                                 修复 config.json\n\n管理:\n   un, uninstall                                   卸载\n   u, update [core | sh | dat | caddy] [ver]       更新\n   U, update.sh                                    更新脚本\n   s, status                                       运行状态\n   start, stop, restart [caddy]                    启动, 停止, 重启\n   t, test                                         测试运行\n   reinstall                                       重装脚本\n\n测试:\n   client [name]                                   显示用于客户端 JSON, 仅供参考\n   debug [name]                                    显示一些 debug 信息, 仅供参考\n   gen [...]                                       同等于 add, 但只显示 JSON 内容, 不创建文件, 测试使用\n   genc [name]                                     显示用于客户端部分 JSON, 仅供参考\n   no-auto-tls [...]                               同等于 add, 但禁止自动配置 TLS, 可用于 *TLS 相关协议\n   xapi [...]                                      同等于 v2ray api, 但 API 后端使用当前运行的 V2Ray 服务\n\n其他:\n   bbr                                             启用 BBR, 如果支持\n   bin [...]                                       运行 V2Ray 命令, 例如: v2ray bin help\n   api, convert, tls, run, uuid  [...]             兼容 V2Ray 命令\n   h, help                                         显示此帮助界面\n\n谨慎使用 del, ddel, 此选项会直接删除配置; 无需确认\n反馈问题) https://github.com/233boy/v2ray/issues\n文档(doc) https://233boy.com/v2ray/v2ray-script/\n```\n"
  },
  {
    "path": "install.sh",
    "content": "#!/bin/bash\n\nauthor=233boy\n# github=https://github.com/233boy/v2ray\n\n# bash fonts colors\nred='\\e[31m'\nyellow='\\e[33m'\ngray='\\e[90m'\ngreen='\\e[92m'\nblue='\\e[94m'\nmagenta='\\e[95m'\ncyan='\\e[96m'\nnone='\\e[0m'\n_red() { echo -e ${red}$@${none}; }\n_blue() { echo -e ${blue}$@${none}; }\n_cyan() { echo -e ${cyan}$@${none}; }\n_green() { echo -e ${green}$@${none}; }\n_yellow() { echo -e ${yellow}$@${none}; }\n_magenta() { echo -e ${magenta}$@${none}; }\n_red_bg() { echo -e \"\\e[41m$@${none}\"; }\n\nis_err=$(_red_bg 错误!)\nis_warn=$(_red_bg 警告!)\n\nerr() {\n    echo -e \"\\n$is_err $@\\n\" && exit 1\n}\n\nwarn() {\n    echo -e \"\\n$is_warn $@\\n\"\n}\n\n# root\n[[ $EUID != 0 ]] && err \"当前非 ${yellow}ROOT用户.${none}\"\n\n# yum or apt-get, ubuntu/debian/centos\ncmd=$(type -P apt-get || type -P yum)\n[[ ! $cmd ]] && err \"此脚本仅支持 ${yellow}(Ubuntu or Debian or CentOS)${none}.\"\n\n# systemd\n[[ ! $(type -P systemctl) ]] && {\n    err \"此系统缺少 ${yellow}(systemctl)${none}, 请尝试执行:${yellow} ${cmd} update -y;${cmd} install systemd -y ${none}来修复此错误.\"\n}\n\n# wget installed or none\nis_wget=$(type -P wget)\n\n# x64\ncase $(uname -m) in\namd64 | x86_64)\n    is_jq_arch=amd64\n    is_core_arch=\"64\"\n    ;;\n*aarch64* | *armv8*)\n    is_jq_arch=arm64\n    is_core_arch=\"arm64-v8a\"\n    ;;\n*)\n    err \"此脚本仅支持 64 位系统...\"\n    ;;\nesac\n\nis_core=v2ray\nis_core_name=V2Ray\nis_core_dir=/etc/$is_core\nis_core_bin=$is_core_dir/bin/$is_core\nis_core_repo=v2fly/$is_core-core\nis_conf_dir=$is_core_dir/conf\nis_log_dir=/var/log/$is_core\nis_sh_bin=/usr/local/bin/$is_core\nis_sh_dir=$is_core_dir/sh\nis_sh_repo=$author/$is_core\nis_pkg=\"wget unzip\"\nis_config_json=$is_core_dir/config.json\ntmp_var_lists=(\n    tmpcore\n    tmpsh\n    tmpjq\n    is_core_ok\n    is_sh_ok\n    is_jq_ok\n    is_pkg_ok\n)\n\n# tmp dir\ntmpdir=$(mktemp -u)\n[[ ! $tmpdir ]] && {\n    tmpdir=/tmp/tmp-$RANDOM\n}\n\n# set up var\nfor i in ${tmp_var_lists[*]}; do\n    export $i=$tmpdir/$i\ndone\n\n# load bash script.\nload() {\n    . $is_sh_dir/src/$1\n}\n\n# wget add --no-check-certificate\n_wget() {\n    [[ $proxy ]] && export https_proxy=$proxy\n    wget --no-check-certificate $*\n}\n\n# print a mesage\nmsg() {\n    case $1 in\n    warn)\n        local color=$yellow\n        ;;\n    err)\n        local color=$red\n        ;;\n    ok)\n        local color=$green\n        ;;\n    esac\n\n    echo -e \"${color}$(date +'%T')${none}) ${2}\"\n}\n\n# show help msg\nshow_help() {\n    echo -e \"Usage: $0 [-f xxx | -l | -p xxx | -v xxx | -h]\"\n    echo -e \"  -f, --core-file <path>          自定义 $is_core_name 文件路径, e.g., -f /root/${is_core}-linux-64.zip\"\n    echo -e \"  -l, --local-install             本地获取安装脚本, 使用当前目录\"\n    echo -e \"  -p, --proxy <addr>              使用代理下载, e.g., -p http://127.0.0.1:2333\"\n    echo -e \"  -v, --core-version <ver>        自定义 $is_core_name 版本, e.g., -v v5.4.1\"\n    echo -e \"  -h, --help                      显示此帮助界面\\n\"\n\n    exit 0\n}\n\n# install dependent pkg\ninstall_pkg() {\n    cmd_not_found=\n    for i in $*; do\n        [[ ! $(type -P $i) ]] && cmd_not_found=\"$cmd_not_found,$i\"\n    done\n    if [[ $cmd_not_found ]]; then\n        pkg=$(echo $cmd_not_found | sed 's/,/ /g')\n        msg warn \"安装依赖包 >${pkg}\"\n        $cmd install -y $pkg &>/dev/null\n        if [[ $? != 0 ]]; then\n            [[ $cmd =~ yum ]] && yum install epel-release -y &>/dev/null\n            $cmd update -y &>/dev/null\n            $cmd install -y $pkg &>/dev/null\n            [[ $? == 0 ]] && >$is_pkg_ok\n        else\n            >$is_pkg_ok\n        fi\n    else\n        >$is_pkg_ok\n    fi\n}\n\n# download file\ndownload() {\n    case $1 in\n    core)\n        link=https://github.com/${is_core_repo}/releases/latest/download/${is_core}-linux-${is_core_arch}.zip\n        [[ $is_core_ver ]] && link=\"https://github.com/${is_core_repo}/releases/download/${is_core_ver}/${is_core}-linux-${is_core_arch}.zip\"\n        name=$is_core_name\n        tmpfile=$tmpcore\n        is_ok=$is_core_ok\n        ;;\n    sh)\n        link=https://github.com/${is_sh_repo}/releases/latest/download/code.zip\n        name=\"$is_core_name 脚本\"\n        tmpfile=$tmpsh\n        is_ok=$is_sh_ok\n        ;;\n    jq)\n        link=https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-$is_jq_arch\n        name=\"jq\"\n        tmpfile=$tmpjq\n        is_ok=$is_jq_ok\n        ;;\n    esac\n\n    msg warn \"下载 ${name} > ${link}\"\n    if _wget -t 3 -q -c $link -O $tmpfile; then\n        mv -f $tmpfile $is_ok\n    fi\n}\n\n# get server ip\nget_ip() {\n    export \"$(_wget -4 -qO- https://one.one.one.one/cdn-cgi/trace | grep ip=)\" &>/dev/null\n    [[ -z $ip ]] && export \"$(_wget -6 -qO- https://one.one.one.one/cdn-cgi/trace | grep ip=)\" &>/dev/null\n}\n\n# check background tasks status\ncheck_status() {\n    # dependent pkg install fail\n    [[ ! -f $is_pkg_ok ]] && {\n        msg err \"安装依赖包失败\"\n        msg err \"请尝试手动安装依赖包: $cmd update -y; $cmd install -y $is_pkg\"\n        is_fail=1\n    }\n\n    # download file status\n    if [[ $is_wget ]]; then\n        [[ ! -f $is_core_ok ]] && {\n            msg err \"下载 ${is_core_name} 失败\"\n            is_fail=1\n        }\n        [[ ! -f $is_sh_ok ]] && {\n            msg err \"下载 ${is_core_name} 脚本失败\"\n            is_fail=1\n        }\n        [[ ! -f $is_jq_ok ]] && {\n            msg err \"下载 jq 失败\"\n            is_fail=1\n        }\n    else\n        [[ ! $is_fail ]] && {\n            is_wget=1\n            [[ ! $is_core_file ]] && download core &\n            [[ ! $local_install ]] && download sh &\n            [[ $jq_not_found ]] && download jq &\n            get_ip\n            wait\n            check_status\n        }\n    fi\n\n    # found fail status, remove tmp dir and exit.\n    [[ $is_fail ]] && {\n        exit_and_del_tmpdir\n    }\n}\n\n# parameters check\npass_args() {\n    while [[ $# -gt 0 ]]; do\n        case $1 in\n        online)\n            err \"如果想要安装旧版本, 请转到: https://github.com/233boy/v2ray/tree/old\"\n            ;;\n        -f | --core-file)\n            [[ -z $2 ]] && {\n                err \"($1) 缺少必需参数, 正确使用示例: [$1 /root/$is_core-linux-64.zip]\"\n            } || [[ ! -f $2 ]] && {\n                err \"($2) 不是一个常规的文件.\"\n            }\n            is_core_file=$2\n            shift 2\n            ;;\n        -l | --local-install)\n            [[ ! -f ${PWD}/src/core.sh || ! -f ${PWD}/$is_core.sh ]] && {\n                err \"当前目录 (${PWD}) 非完整的脚本目录.\"\n            }\n            local_install=1\n            shift 1\n            ;;\n        -p | --proxy)\n            [[ -z $2 ]] && {\n                err \"($1) 缺少必需参数, 正确使用示例: [$1 http://127.0.0.1:2333 or -p socks5://127.0.0.1:2333]\"\n            }\n            proxy=$2\n            shift 2\n            ;;\n        -v | --core-version)\n            [[ -z $2 ]] && {\n                err \"($1) 缺少必需参数, 正确使用示例: [$1 v1.8.1]\"\n            }\n            is_core_ver=v${2#v}\n            shift 2\n            ;;\n        -h | --help)\n            show_help\n            ;;\n        *)\n            echo -e \"\\n${is_err} ($@) 为未知参数...\\n\"\n            show_help\n            ;;\n        esac\n    done\n    [[ $is_core_ver && $is_core_file ]] && {\n        err \"无法同时自定义 ${is_core_name} 版本和 ${is_core_name} 文件.\"\n    }\n}\n\n# exit and remove tmpdir\nexit_and_del_tmpdir() {\n    rm -rf $tmpdir\n    [[ ! $1 ]] && {\n        msg err \"哦豁..\"\n        msg err \"安装过程出现错误...\"\n        echo -e \"反馈问题) https://github.com/${is_sh_repo}/issues\"\n        echo\n        exit 1\n    }\n    exit\n}\n\n# main\nmain() {\n\n    # check old version\n    [[ -f $is_sh_bin && -d $is_core_dir/bin && -d $is_sh_dir && -d $is_conf_dir ]] && {\n        err \"检测到脚本已安装, 如需重装请使用${green} ${is_core} reinstall ${none}命令.\"\n    }\n\n    # check parameters\n    [[ $# -gt 0 ]] && pass_args $@\n\n    # show welcome msg\n    clear\n    echo\n    echo \"........... $is_core_name script by $author ..........\"\n    echo\n\n    # start installing...\n    msg warn \"开始安装...\"\n    [[ $is_core_ver ]] && msg warn \"${is_core_name} 版本: ${yellow}$is_core_ver${none}\"\n    [[ $proxy ]] && msg warn \"使用代理: ${yellow}$proxy${none}\"\n    # create tmpdir\n    mkdir -p $tmpdir\n    # if is_core_file, copy file\n    [[ $is_core_file ]] && {\n        cp -f $is_core_file $is_core_ok\n        msg warn \"${yellow}${is_core_name} 文件使用 > $is_core_file${none}\"\n    }\n    # local dir install sh script\n    [[ $local_install ]] && {\n        >$is_sh_ok\n        msg warn \"${yellow}本地获取安装脚本 > $PWD ${none}\"\n    }\n\n    timedatectl set-ntp true &>/dev/null\n    [[ $? != 0 ]] && {\n        msg warn \"${yellow}\\e[4m提醒!!! 无法设置自动同步时间, 可能会影响使用 VMess 协议.${none}\"\n    }\n\n    # install dependent pkg\n    install_pkg $is_pkg &\n\n    # jq\n    if [[ $(type -P jq) ]]; then\n        >$is_jq_ok\n    else\n        jq_not_found=1\n    fi\n    # if wget installed. download core, sh, jq, get ip\n    [[ $is_wget ]] && {\n        [[ ! $is_core_file ]] && download core &\n        [[ ! $local_install ]] && download sh &\n        [[ $jq_not_found ]] && download jq &\n        get_ip\n    }\n\n    # waiting for background tasks is done\n    wait\n\n    # check background tasks status\n    check_status\n\n    # test $is_core_file\n    if [[ $is_core_file ]]; then\n        unzip -qo $is_core_ok -d $tmpdir/testzip &>/dev/null\n        [[ $? != 0 ]] && {\n            msg err \"${is_core_name} 文件无法通过测试.\"\n            exit_and_del_tmpdir\n        }\n        for i in ${is_core} geoip.dat geosite.dat; do\n            [[ ! -f $tmpdir/testzip/$i ]] && is_file_err=1 && break\n        done\n        [[ $is_file_err ]] && {\n            msg err \"${is_core_name} 文件无法通过测试.\"\n            exit_and_del_tmpdir\n        }\n    fi\n\n    # get server ip.\n    [[ ! $ip ]] && {\n        msg err \"获取服务器 IP 失败.\"\n        exit_and_del_tmpdir\n    }\n\n    # create sh dir...\n    mkdir -p $is_sh_dir\n\n    # copy sh file or unzip sh zip file.\n    if [[ $local_install ]]; then\n        cp -rf $PWD/* $is_sh_dir\n    else\n        unzip -qo $is_sh_ok -d $is_sh_dir\n    fi\n\n    # create core bin dir\n    mkdir -p $is_core_dir/bin\n    # copy core file or unzip core zip file\n    if [[ $is_core_file ]]; then\n        cp -rf $tmpdir/testzip/* $is_core_dir/bin\n    else\n        unzip -qo $is_core_ok -d $is_core_dir/bin\n    fi\n\n    # add alias\n    echo \"alias $is_core=$is_sh_bin\" >>/root/.bashrc\n\n    # core command\n    ln -sf $is_sh_dir/$is_core.sh $is_sh_bin\n\n    # jq\n    [[ $jq_not_found ]] && mv -f $is_jq_ok /usr/bin/jq\n\n    # chmod\n    chmod +x $is_core_bin $is_sh_bin /usr/bin/jq\n\n    # create log dir\n    mkdir -p $is_log_dir\n\n    # show a tips msg\n    msg ok \"生成配置文件...\"\n\n    # create systemd service\n    load systemd.sh\n    is_new_install=1\n    install_service $is_core &>/dev/null\n\n    # create condf dir\n    mkdir -p $is_conf_dir\n\n    load core.sh\n    # create a tcp config\n    add tcp\n    # remove tmp dir and exit.\n    exit_and_del_tmpdir ok\n}\n\n# start.\nmain $@\n"
  },
  {
    "path": "src/bbr.sh",
    "content": "_open_bbr() {\n\tsed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf\n\tsed -i '/net.core.default_qdisc/d' /etc/sysctl.conf\n\techo \"net.ipv4.tcp_congestion_control = bbr\" >>/etc/sysctl.conf\n\techo \"net.core.default_qdisc = fq\" >>/etc/sysctl.conf\n\tsysctl -p &>/dev/null\n\techo\n\t_green \"..已经启用 BBR 优化....\"\n\techo\n}\n\n_try_enable_bbr() {\n\tlocal _test1=$(uname -r | cut -d\\. -f1)\n\tlocal _test2=$(uname -r | cut -d\\. -f2)\n\tif [[ $_test1 -eq 4 && $_test2 -ge 9 ]] || [[ $_test1 -ge 5 ]]; then\n\t\t_open_bbr\n\telse\n\t\terr \"不支持启用 BBR 优化.\"\n\tfi\n}\n"
  },
  {
    "path": "src/caddy.sh",
    "content": "caddy_config() {\n    is_caddy_site_file=$is_caddy_conf/${host}.conf\n    case $1 in\n    new)\n        mkdir -p $is_caddy_dir $is_caddy_dir/sites $is_caddy_conf\n        cat >$is_caddyfile <<-EOF\n# don't edit this file #\n# for more info, see https://233boy.com/$is_core/caddy-auto-tls/\n# 不要编辑这个文件 #\n# 更多相关请阅读此文章: https://233boy.com/$is_core/caddy-auto-tls/\n# https://caddyserver.com/docs/caddyfile/options\n{\n  admin off\n  http_port $is_http_port\n  https_port $is_https_port\n}\nimport $is_caddy_conf/*.conf\nimport $is_caddy_dir/sites/*.conf\nEOF\n        ;;\n    *ws*)\n        cat >${is_caddy_site_file} <<<\"\n${host}:${is_https_port} {\n    reverse_proxy ${path} 127.0.0.1:${port}\n    import ${is_caddy_site_file}.add\n}\"\n        ;;\n    *h2*)\n        cat >${is_caddy_site_file} <<<\"\n${host}:${is_https_port} {\n    reverse_proxy ${path} h2c://127.0.0.1:${port}\n    import ${is_caddy_site_file}.add\n}\"\n        ;;\n    *grpc*)\n        cat >${is_caddy_site_file} <<<\"\n${host}:${is_https_port} {\n    reverse_proxy /${path}/* h2c://127.0.0.1:${port}\n    import ${is_caddy_site_file}.add\n}\"\n        ;;\n    proxy)\n        \n        cat >${is_caddy_site_file}.add <<<\"\nreverse_proxy https://$proxy_site {\n        header_up Host {upstream_hostport}\n}\"\n        ;;\n    esac\n    [[ $1 != \"new\" && $1 != 'proxy' ]] && {\n        [[ ! -f ${is_caddy_site_file}.add ]] && echo \"# see https://233boy.com/$is_core/caddy-auto-tls/\" >${is_caddy_site_file}.add\n    }\n}\n"
  },
  {
    "path": "src/core.sh",
    "content": "#!/bin/bash\n\nprotocol_list=(\n    VMess-TCP\n    VMess-mKCP\n    VMess-QUIC\n    VMess-H2-TLS\n    VMess-WS-TLS\n    VMess-gRPC-TLS\n    VLESS-H2-TLS\n    VLESS-WS-TLS\n    VLESS-gRPC-TLS\n    # VLESS-XTLS-uTLS-REALITY\n    Trojan-H2-TLS\n    Trojan-WS-TLS\n    Trojan-gRPC-TLS\n    Shadowsocks\n    # Dokodemo-Door\n    VMess-TCP-dynamic-port\n    VMess-mKCP-dynamic-port\n    VMess-QUIC-dynamic-port\n    Socks\n)\nss_method_list=(\n    aes-128-gcm\n    aes-256-gcm\n    chacha20-ietf-poly1305\n    # xchacha20-ietf-poly1305\n    # 2022-blake3-aes-128-gcm\n    # 2022-blake3-aes-256-gcm\n    # 2022-blake3-chacha20-poly1305\n)\nheader_type_list=(\n    none\n    srtp\n    utp\n    wechat-video\n    dtls\n    wireguard\n)\nmainmenu=(\n    \"添加配置\"\n    \"更改配置\"\n    \"查看配置\"\n    \"删除配置\"\n    \"运行管理\"\n    \"更新\"\n    \"卸载\"\n    \"帮助\"\n    \"其他\"\n    \"关于\"\n)\ninfo_list=(\n    \"协议 (protocol)\"\n    \"地址 (address)\"\n    \"端口 (port)\"\n    \"用户ID (id)\"\n    \"传输协议 (network)\"\n    \"伪装类型 (type)\"\n    \"伪装域名 (host)\"\n    \"路径 (path)\"\n    \"传输层安全 (TLS)\"\n    \"mKCP seed\"\n    \"密码 (password)\"\n    \"加密方式 (encryption)\"\n    \"链接 (URL)\"\n    \"目标地址 (remote addr)\"\n    \"目标端口 (remote port)\"\n    \"流控 (flow)\"\n    \"SNI (serverName)\"\n    \"指纹 (Fingerprint)\"\n    \"公钥 (Public key)\"\n    \"用户名 (Username)\"\n)\nchange_list=(\n    \"更改协议\"\n    \"更改端口\"\n    \"更改域名\"\n    \"更改路径\"\n    \"更改密码\"\n    \"更改 UUID\"\n    \"更改加密方式\"\n    \"更改伪装类型\"\n    \"更改目标地址\"\n    \"更改目标端口\"\n    \"更改密钥\"\n    \"更改 SNI (serverName)\"\n    \"更改动态端口\"\n    \"更改伪装网站\"\n    \"更改 mKCP seed\"\n    \"更改用户名 (Username)\"\n)\nservername_list=(\n    www.amazon.com\n    www.microsoft.com\n    www.apple.com\n    dash.cloudflare.com\n    dl.google.com\n    aws.amazon.com\n)\n\nis_random_ss_method=${ss_method_list[$(shuf -i 0-${#ss_method_list[@]} -n1) - 1]}\nis_random_header_type=${header_type_list[$(shuf -i 1-5 -n1)]} # random dont use none\nis_random_servername=${servername_list[$(shuf -i 0-${#servername_list[@]} -n1) - 1]}\n\nmsg() {\n    echo -e \"$@\"\n}\n\nmsg_ul() {\n    echo -e \"\\e[4m$@\\e[0m\"\n}\n\n# pause\npause() {\n    echo\n    echo -ne \"按 $(_green Enter 回车键) 继续, 或按 $(_red Ctrl + C) 取消.\"\n    read -rs -d $'\\n'\n    echo\n}\n\nget_uuid() {\n    tmp_uuid=$(cat /proc/sys/kernel/random/uuid)\n}\n\nget_ip() {\n    [[ $ip || $is_no_auto_tls || $is_gen || $is_dont_get_ip ]] && return\n    export \"$(_wget -4 -qO- https://one.one.one.one/cdn-cgi/trace | grep ip=)\" &>/dev/null\n    [[ ! $ip ]] && export \"$(_wget -6 -qO- https://one.one.one.one/cdn-cgi/trace | grep ip=)\" &>/dev/null\n    [[ ! $ip ]] && {\n        err \"获取服务器 IP 失败..\"\n    }\n}\n\nget_port() {\n    is_count=0\n    while :; do\n        ((is_count++))\n        if [[ $is_count -ge 233 ]]; then\n            err \"自动获取可用端口失败次数达到 233 次, 请检查端口占用情况.\"\n        fi\n        tmp_port=$(shuf -i 445-65535 -n 1)\n        [[ ! $(is_test port_used $tmp_port) && $tmp_port != $port ]] && break\n    done\n}\n\nget_pbk() {\n    is_tmp_pbk=($($is_core_bin x25519 | sed 's/.*://'))\n    is_private_key=${is_tmp_pbk[0]}\n    is_public_key=${is_tmp_pbk[1]}\n}\n\nshow_list() {\n    PS3=''\n    COLUMNS=1\n    select i in \"$@\"; do echo; done &\n    wait\n    # i=0\n    # for v in \"$@\"; do\n    #     ((i++))\n    #     echo \"$i) $v\"\n    # done\n    # echo\n\n}\n\nis_test() {\n    case $1 in\n    number)\n        echo $2 | grep -E '^[1-9][0-9]?+$'\n        ;;\n    port)\n        if [[ $(is_test number $2) ]]; then\n            [[ $2 -le 65535 ]] && echo ok\n        fi\n        ;;\n    port_used)\n        [[ $(is_port_used $2) && ! $is_cant_test_port ]] && echo ok\n        ;;\n    domain)\n        echo $2 | grep -E -i '^\\w(\\w|\\-|\\.)?+\\.\\w+$'\n        ;;\n    path)\n        echo $2 | grep -E -i '^\\/\\w(\\w|\\-|\\/)?+\\w$'\n        ;;\n    uuid)\n        echo $2 | grep -E -i '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'\n        ;;\n    esac\n\n}\n\nis_port_used() {\n    if [[ $(type -P netstat) ]]; then\n        [[ ! $is_used_port ]] && is_used_port=\"$(netstat -tunlp | sed -n 's/.*:\\([0-9]\\+\\).*/\\1/p' | sort -nu)\"\n        echo $is_used_port | sed 's/ /\\n/g' | grep ^${1}$\n        return\n    fi\n    if [[ $(type -P ss) ]]; then\n        [[ ! $is_used_port ]] && is_used_port=\"$(ss -tunlp | sed -n 's/.*:\\([0-9]\\+\\).*/\\1/p' | sort -nu)\"\n        echo $is_used_port | sed 's/ /\\n/g' | grep ^${1}$\n        return\n    fi\n    is_cant_test_port=1\n    msg \"$is_warn 无法检测端口是否可用.\"\n    msg \"请执行: $(_yellow \"${cmd} update -y; ${cmd} install net-tools -y\") 来修复此问题.\"\n}\n\n# ask input a string or pick a option for list.\nask() {\n    case $1 in\n    set_ss_method)\n        is_tmp_list=(${ss_method_list[@]})\n        is_default_arg=$is_random_ss_method\n        is_opt_msg=\"\\n请选择加密方式:\\n\"\n        is_opt_input_msg=\"(默认\\e[92m $is_default_arg\\e[0m):\"\n        is_ask_set=ss_method\n        ;;\n    set_header_type)\n        is_tmp_list=(${header_type_list[@]})\n        is_default_arg=$is_random_header_type\n        [[ $(grep -i tcp <<<\"$is_new_protocol-$net\") ]] && {\n            is_tmp_list=(none http)\n            is_default_arg=none\n        }\n        is_opt_msg=\"\\n请选择伪装类型:\\n\"\n        is_opt_input_msg=\"(默认\\e[92m $is_default_arg\\e[0m):\"\n        is_ask_set=header_type\n        [[ $is_use_header_type ]] && return\n        ;;\n    set_protocol)\n        is_tmp_list=(${protocol_list[@]})\n        [[ $is_no_auto_tls ]] && {\n            unset is_tmp_list\n            for v in ${protocol_list[@]}; do\n                [[ $(grep -i tls$ <<<$v) ]] && is_tmp_list=(${is_tmp_list[@]} $v)\n            done\n        }\n        is_opt_msg=\"\\n请选择协议:\\n\"\n        is_ask_set=is_new_protocol\n        ;;\n    set_change_list)\n        is_tmp_list=()\n        for v in ${is_can_change[@]}; do\n            is_tmp_list+=(\"${change_list[$v]}\")\n        done\n        is_opt_msg=\"\\n请选择更改:\\n\"\n        is_ask_set=is_change_str\n        is_opt_input_msg=$3\n        ;;\n    string)\n        is_ask_set=$2\n        is_opt_input_msg=$3\n        ;;\n    list)\n        is_ask_set=$2\n        [[ ! $is_tmp_list ]] && is_tmp_list=($3)\n        is_opt_msg=$4\n        is_opt_input_msg=$5\n        ;;\n    get_config_file)\n        is_tmp_list=(\"${is_all_json[@]}\")\n        is_opt_msg=\"\\n请选择配置:\\n\"\n        is_ask_set=is_config_file\n        ;;\n    mainmenu)\n        is_tmp_list=(\"${mainmenu[@]}\")\n        is_ask_set=is_main_pick\n        is_emtpy_exit=1\n        ;;\n    esac\n    msg $is_opt_msg\n    [[ ! $is_opt_input_msg ]] && is_opt_input_msg=\"请选择 [\\e[91m1-${#is_tmp_list[@]}\\e[0m]:\"\n    [[ $is_tmp_list ]] && show_list \"${is_tmp_list[@]}\"\n    while :; do\n        echo -ne $is_opt_input_msg\n        read REPLY\n        [[ ! $REPLY && $is_emtpy_exit ]] && exit\n        [[ ! $REPLY && $is_default_arg ]] && export $is_ask_set=$is_default_arg && break\n        [[ \"$REPLY\" == \"${is_str}2${is_get}3${is_opt}3\" && $is_ask_set == 'is_main_pick' ]] && {\n            msg \"\\n${is_get}2${is_str}3${is_msg}3b${is_tmp}o${is_opt}y\\n\" && exit\n        }\n        if [[ ! $is_tmp_list ]]; then\n            [[ $(grep port <<<$is_ask_set) ]] && {\n                [[ ! $(is_test port \"$REPLY\") ]] && {\n                    msg \"$is_err 请输入正确的端口, 可选(1-65535)\"\n                    continue\n                }\n                if [[ $(is_test port_used $REPLY) && $is_ask_set != 'door_port' ]]; then\n                    msg \"$is_err 无法使用 ($REPLY) 端口.\"\n                    continue\n                fi\n            }\n            [[ $(grep path <<<$is_ask_set) && ! $(is_test path \"$REPLY\") ]] && {\n                [[ ! $tmp_uuid ]] && get_uuid\n                msg \"$is_err 请输入正确的路径, 例如: /$tmp_uuid\"\n                continue\n            }\n            [[ $(grep uuid <<<$is_ask_set) && ! $(is_test uuid \"$REPLY\") ]] && {\n                [[ ! $tmp_uuid ]] && get_uuid\n                msg \"$is_err 请输入正确的 UUID, 例如: $tmp_uuid\"\n                continue\n            }\n            [[ $(grep ^y$ <<<$is_ask_set) ]] && {\n                [[ $(grep -i ^y$ <<<\"$REPLY\") ]] && break\n                msg \"请输入 (y)\"\n                continue\n            }\n            [[ $REPLY ]] && export $is_ask_set=$REPLY && msg \"使用: ${!is_ask_set}\" && break\n        else\n            [[ $(is_test number \"$REPLY\") ]] && is_ask_result=${is_tmp_list[$REPLY - 1]}\n            [[ $is_ask_result ]] && export $is_ask_set=\"$is_ask_result\" && msg \"选择: ${!is_ask_set}\" && break\n        fi\n\n        msg \"输入${is_err}\"\n    done\n    unset is_opt_msg is_opt_input_msg is_tmp_list is_ask_result is_default_arg is_emtpy_exit\n}\n\n# create file\ncreate() {\n    case $1 in\n    server)\n        is_tls=none\n        get new\n\n        # file name\n        if [[ $host ]]; then\n            is_config_name=$2-${host}.json\n        else\n            is_config_name=$2-${port}.json\n        fi\n        is_json_file=$is_conf_dir/$is_config_name\n        # get json\n        [[ $is_change || ! $json_str ]] && get protocol $2\n        case $net in\n        ws | h2 | grpc | http)\n            is_listen='\"listen\": \"127.0.0.1\"'\n            ;;\n        *)\n            is_listen='\"listen\": \"0.0.0.0\"'\n            ;;\n        esac\n        is_sniffing='sniffing:{enabled:true,destOverride:[\"http\",\"tls\"]}'\n        is_new_json=$(jq '{inbounds:[{tag:'\\\"$is_config_name\\\"',port:'\"$port\"','\"$is_listen\"',protocol:'\\\"$is_protocol\\\"','\"$json_str\"','\"$is_sniffing\"'}]}' <<<{})\n        if [[ $is_dynamic_port ]]; then\n            [[ ! $is_dynamic_port_range ]] && get dynamic-port\n            is_new_dynamic_port_json=$(jq '{inbounds:[{tag:'\\\"$is_config_name-link.json\\\"',port:'\\\"$is_dynamic_port_range\\\"','\"$is_listen\"',protocol:\"vmess\",'\"$is_stream\"','\"$is_sniffing\"',allocate:{strategy:\"random\"}}]}' <<<{})\n        fi\n        [[ $is_test_json ]] && return # tmp test\n        # only show json, dont save to file.\n        [[ $is_gen ]] && {\n            msg\n            jq <<<$is_new_json\n            msg\n            [[ $is_new_dynamic_port_json ]] && jq <<<$is_new_dynamic_port_json && msg\n            return\n        }\n        # del old file\n        [[ $is_config_file ]] && is_no_del_msg=1 && del $is_config_file\n        # save json to file\n        cat <<<$is_new_json >$is_json_file\n        [[ $is_new_dynamic_port_json ]] && {\n            is_dynamic_port_link_file=$is_json_file-link.json\n            cat <<<$is_new_dynamic_port_json >$is_dynamic_port_link_file\n        }\n        if [[ $is_new_install ]]; then\n            # config.json\n            create config.json\n        else\n            # use api add config\n            api add $is_json_file $is_dynamic_port_link_file &>/dev/null\n        fi\n        # caddy auto tls\n        [[ $is_caddy && $host && ! $is_no_auto_tls ]] && {\n            create caddy $net\n        }\n        # restart core\n        [[ $is_api_fail ]] && manage restart &\n        ;;\n    client)\n        is_tls=tls\n        is_client=1\n        get info $2\n        [[ ! $is_client_id_json ]] && err \"($is_config_name) 不支持生成客户端配置.\"\n        is_new_json=$(jq '{outbounds:[{tag:'\\\"$is_config_name\\\"',protocol:'\\\"$is_protocol\\\"','\"$is_client_id_json\"','\"$is_stream\"'}]}' <<<{})\n        if [[ $is_full_client ]]; then\n            is_dns='dns:{servers:[{address:\"223.5.5.5\",domain:[\"geosite:cn\",\"geosite:geolocation-cn\"],expectIPs:[\"geoip:cn\"]},\"1.1.1.1\",\"8.8.8.8\"]}'\n            is_route='routing:{rules:[{type:\"field\",outboundTag:\"direct\",ip:[\"geoip:cn\",\"geoip:private\"]},{type:\"field\",outboundTag:\"direct\",domain:[\"geosite:cn\",\"geosite:geolocation-cn\"]}]}'\n            is_inbounds='inbounds:[{port:2333,listen:\"127.0.0.1\",protocol:\"socks\",settings:{udp:true},sniffing:{enabled:true,destOverride:[\"http\",\"tls\"]}}]'\n            is_outbounds='outbounds:[{tag:'\\\"$is_config_name\\\"',protocol:'\\\"$is_protocol\\\"','\"$is_client_id_json\"','\"$is_stream\"'},{tag:\"direct\",protocol:\"freedom\"}]'\n            is_new_json=$(jq '{'$is_dns,$is_route,$is_inbounds,$is_outbounds'}' <<<{})\n        fi\n        msg\n        jq <<<$is_new_json\n        msg\n        ;;\n    caddy)\n        load caddy.sh\n        [[ $is_install_caddy ]] && caddy_config new\n        [[ ! $(grep \"$is_caddy_conf\" $is_caddyfile) ]] && {\n            msg \"import $is_caddy_conf/*.conf\" >>$is_caddyfile\n        }\n        [[ ! -d $is_caddy_conf ]] && mkdir -p $is_caddy_conf\n        caddy_config $2\n        manage restart caddy &\n        ;;\n    config.json)\n        get_port\n        is_log='log:{access:\"/var/log/'\"$is_core\"'/access.log\",error:\"/var/log/'\"$is_core\"'/error.log\",loglevel:\"warning\"}'\n        is_dns='dns:{}'\n        is_api='api:{tag:\"api\",services:[\"HandlerService\",\"LoggerService\",\"StatsService\"]}'\n        is_stats='stats:{}'\n        is_policy_system='system:{statsInboundUplink:true,statsInboundDownlink:true,statsOutboundUplink:true,statsOutboundDownlink:true}'\n        is_policy='policy:{levels:{\"0\":{handshake:'\"$((${tmp_port:0:1} + 1))\"',connIdle:'\"${tmp_port:0:3}\"',uplinkOnly:'\"$((${tmp_port:2:1} + 1))\"',downlinkOnly:'\"$((${tmp_port:3:1} + 3))\"',statsUserUplink:true,statsUserDownlink:true}},'\"$is_policy_system\"'}'\n        is_ban_ad='{type:\"field\",domain:[\"geosite:category-ads-all\"],marktag:\"ban_ad\",outboundTag:\"block\"}'\n        is_ban_bt='{type:\"field\",protocol:[\"bittorrent\"],marktag:\"ban_bt\",outboundTag:\"block\"}'\n        is_ban_cn='{type:\"field\",ip:[\"geoip:cn\"],marktag:\"ban_geoip_cn\",outboundTag:\"block\"}'\n        is_openai='{type:\"field\",domain:[\"domain:openai.com\"],marktag:\"fix_openai\",outboundTag:\"direct\"}'\n        is_routing='routing:{domainStrategy:\"IPIfNonMatch\",rules:[{type:\"field\",inboundTag:[\"api\"],outboundTag:\"api\"},'\"$is_ban_bt\"','\"$is_ban_cn\"','\"$is_openai\"',{type:\"field\",ip:[\"geoip:private\"],outboundTag:\"block\"}]}'\n        is_inbounds='inbounds:[{tag:\"api\",port:'\"$tmp_port\"',listen:\"127.0.0.1\",protocol:\"dokodemo-door\",settings:{address:\"127.0.0.1\"}}]'\n        is_outbounds='outbounds:[{tag:\"direct\",protocol:\"freedom\"},{tag:\"block\",protocol:\"blackhole\"}]'\n        is_server_config_json=$(jq '{'\"$is_log\"','\"$is_dns\"','\"$is_api\"','\"$is_stats\"','\"$is_policy\"','\"$is_routing\"','\"$is_inbounds\"','\"$is_outbounds\"'}' <<<{})\n        cat <<<$is_server_config_json >$is_config_json\n        manage restart &\n        ;;\n    esac\n}\n\n# change config file\nchange() {\n    is_change=1\n    is_dont_show_info=1\n    if [[ $2 ]]; then\n        case ${2,,} in\n        full)\n            is_change_id=full\n            ;;\n        new)\n            is_change_id=0\n            ;;\n        port)\n            is_change_id=1\n            ;;\n        host)\n            is_change_id=2\n            ;;\n        path)\n            is_change_id=3\n            ;;\n        pass | passwd | password)\n            is_change_id=4\n            ;;\n        id | uuid)\n            is_change_id=5\n            ;;\n        ssm | method | ss-method | ss_method)\n            is_change_id=6\n            ;;\n        type | header | header-type | header_type)\n            is_change_id=7\n            ;;\n        dda | door-addr | door_addr)\n            is_change_id=8\n            ;;\n        ddp | door-port | door_port)\n            is_change_id=9\n            ;;\n        key | publickey | privatekey)\n            is_change_id=10\n            ;;\n        sni | servername | servernames)\n            is_change_id=11\n            ;;\n        dp | dyp | dynamic | dynamicport | dynamic-port)\n            is_change_id=12\n            ;;\n        web | proxy-site)\n            is_change_id=13\n            ;;\n        seed | kcpseed | kcp-seed | kcp_seed)\n            is_change_id=14\n            ;;\n        *)\n            [[ $is_try_change ]] && return\n            err \"无法识别 ($2) 更改类型.\"\n            ;;\n        esac\n    fi\n    [[ $is_try_change ]] && return\n    [[ $is_dont_auto_exit ]] && {\n        get info $1\n    } || {\n        [[ $is_change_id ]] && {\n            is_change_msg=${change_list[$is_change_id]}\n            [[ $is_change_id == 'full' ]] && {\n                [[ $3 ]] && is_change_msg=\"更改多个参数\" || is_change_msg=\n            }\n            [[ $is_change_msg ]] && _green \"\\n快速执行: $is_change_msg\"\n        }\n        info $1\n        [[ $is_auto_get_config ]] && msg \"\\n自动选择: $is_config_file\"\n    }\n    is_old_net=$net\n    [[ $is_protocol == 'vless' && ! $is_reality ]] && net=v$net\n    [[ $is_protocol == 'trojan' ]] && net=t$net\n    [[ $is_dynamic_port ]] && net=${net}d\n    [[ $3 == 'auto' ]] && is_auto=1\n    # if is_dont_show_info exist, cant show info.\n    is_dont_show_info=\n    # if not prefer args, show change list and then get change id.\n    [[ ! $is_change_id ]] && {\n        ask set_change_list\n        is_change_id=${is_can_change[$REPLY - 1]}\n    }\n    case $is_change_id in\n    full)\n        add $net ${@:3}\n        ;;\n    0)\n        # new protocol\n        is_set_new_protocol=1\n        add ${@:3}\n        ;;\n    1)\n        # new port\n        is_new_port=$3\n        [[ $host && ! $is_caddy || $is_no_auto_tls ]] && err \"($is_config_file) 不支持更改端口, 因为没啥意义.\"\n        if [[ $is_new_port && ! $is_auto ]]; then\n            [[ ! $(is_test port $is_new_port) ]] && err \"请输入正确的端口, 可选(1-65535)\"\n            [[ $is_new_port != 443 && $(is_test port_used $is_new_port) ]] && err \"无法使用 ($is_new_port) 端口\"\n        fi\n        [[ $is_auto ]] && get_port && is_new_port=$tmp_port\n        [[ ! $is_new_port ]] && ask string is_new_port \"请输入新端口:\"\n        if [[ $is_caddy && $host ]]; then\n            net=$is_old_net\n            is_https_port=$is_new_port\n            load caddy.sh\n            caddy_config $net\n            manage restart caddy &\n            info\n        else\n            add $net $is_new_port\n        fi\n        ;;\n    2)\n        # new host\n        is_new_host=$3\n        [[ ! $host ]] && err \"($is_config_file) 不支持更改域名.\"\n        [[ ! $is_new_host ]] && ask string is_new_host \"请输入新域名:\"\n        old_host=$host # del old host\n        add $net $is_new_host\n        ;;\n    3)\n        # new path\n        is_new_path=$3\n        [[ ! $path ]] && err \"($is_config_file) 不支持更改路径.\"\n        [[ $is_auto ]] && get_uuid && is_new_path=/$tmp_uuid\n        [[ ! $is_new_path ]] && ask string is_new_path \"请输入新路径:\"\n        add $net auto auto $is_new_path\n        ;;\n    4)\n        # new password\n        is_new_pass=$3\n        if [[ $net == 'ss' || $is_trojan || $is_socks_pass ]]; then\n            [[ $is_auto ]] && get_uuid && is_new_pass=$tmp_uuid\n        else\n            err \"($is_config_file) 不支持更改密码.\"\n        fi\n        [[ ! $is_new_pass ]] && ask string is_new_pass \"请输入新密码:\"\n        trojan_password=$is_new_pass\n        ss_password=$is_new_pass\n        is_socks_pass=$is_new_pass\n        add $net\n        ;;\n    5)\n        # new uuid\n        is_new_uuid=$3\n        [[ ! $uuid ]] && err \"($is_config_file) 不支持更改 UUID.\"\n        [[ $is_auto ]] && get_uuid && is_new_uuid=$tmp_uuid\n        [[ ! $is_new_uuid ]] && ask string is_new_uuid \"请输入新 UUID:\"\n        add $net auto $is_new_uuid\n        ;;\n    6)\n        # new method\n        is_new_method=$3\n        [[ $net != 'ss' ]] && err \"($is_config_file) 不支持更改加密方式.\"\n        [[ $is_auto ]] && is_new_method=$is_random_ss_method\n        [[ ! $is_new_method ]] && {\n            ask set_ss_method\n            is_new_method=$ss_method\n        }\n        add $net auto auto $is_new_method\n        ;;\n    7)\n        # new header type\n        is_new_header_type=$3\n        [[ ! $header_type ]] && err \"($is_config_file) 不支持更改伪装类型.\"\n        [[ $is_auto ]] && {\n            is_new_header_type=$is_random_header_type\n            if [[ $net == 'tcp' ]]; then\n                is_tmp_header_type=(none http)\n                is_new_header_type=${is_tmp_header_type[$(shuf -i 0-1 -n1)]}\n            fi\n        }\n        [[ ! $is_new_header_type ]] && {\n            ask set_header_type\n            is_new_header_type=$header_type\n        }\n        add $net auto auto $is_new_header_type\n        ;;\n    8)\n        # new remote addr\n        is_new_door_addr=$3\n        [[ $net != 'door' ]] && err \"($is_config_file) 不支持更改目标地址.\"\n        [[ ! $is_new_door_addr ]] && ask string is_new_door_addr \"请输入新的目标地址:\"\n        door_addr=$is_new_door_addr\n        add $net\n        ;;\n    9)\n        # new remote port\n        is_new_door_port=$3\n        [[ $net != 'door' ]] && err \"($is_config_file) 不支持更改目标端口.\"\n        [[ ! $is_new_door_port ]] && {\n            ask string door_port \"请输入新的目标端口:\"\n            is_new_door_port=$door_port\n        }\n        add $net auto auto $is_new_door_port\n        ;;\n    10)\n        # new is_private_key is_public_key\n        is_new_private_key=$3\n        is_new_public_key=$4\n        [[ ! $is_reality ]] && err \"($is_config_file) 不支持更改密钥.\"\n        if [[ $is_auto ]]; then\n            get_pbk\n            add $net\n        else\n            [[ $is_new_private_key && ! $is_new_public_key ]] && {\n                err \"无法找到 Public key.\"\n            }\n            [[ ! $is_new_private_key ]] && ask string is_new_private_key \"请输入新 Private key:\"\n            [[ ! $is_new_public_key ]] && ask string is_new_public_key \"请输入新 Public key:\"\n            if [[ $is_new_private_key == $is_new_public_key ]]; then\n                err \"Private key 和 Public key 不能一样.\"\n            fi\n            is_private_key=$is_new_private_key\n            is_test_json=1\n            # create server $is_protocol-$net | $is_core_bin -test &>/dev/null\n            create server $is_protocol-$net\n            $is_core_bin -test <<<\"$is_new_json\" &>/dev/null\n            if [[ $? != 0 ]]; then\n                err \"Private key 无法通过测试.\"\n            fi\n            is_private_key=$is_new_public_key\n            # create server $is_protocol-$net | $is_core_bin -test &>/dev/null\n            create server $is_protocol-$net\n            $is_core_bin -test <<<\"$is_new_json\" &>/dev/null\n            if [[ $? != 0 ]]; then\n                err \"Public key 无法通过测试.\"\n            fi\n            is_private_key=$is_new_private_key\n            is_public_key=$is_new_public_key\n            is_test_json=\n            add $net\n        fi\n        ;;\n    11)\n        # new serverName\n        is_new_servername=$3\n        [[ ! $is_reality ]] && err \"($is_config_file) 不支持更改 serverName.\"\n        [[ $is_auto ]] && is_new_servername=$is_random_servername\n        [[ ! $is_new_servername ]] && ask string is_new_servername \"请输入新的 serverName:\"\n        is_servername=$is_new_servername\n        [[ $(grep -i \"^233boy.com$\" <<<$is_servername) ]] && {\n            err \"你干嘛～哎呦～\"\n        }\n        add $net\n        ;;\n    12)\n        # new dynamic-port\n        is_new_dynamic_port_start=$3\n        is_new_dynamic_port_end=$4\n        [[ ! $is_dynamic_port ]] && err \"($is_config_file) 不支持更改动态端口.\"\n        if [[ $is_auto ]]; then\n            get dynamic-port\n            add $net\n        else\n            [[ $is_new_dynamic_port_start && ! $is_new_dynamic_port_end ]] && {\n                err \"无法找到动态结束端口.\"\n            }\n            [[ ! $is_new_dynamic_port_start ]] && ask string is_new_dynamic_port_start \"请输入新的动态开始端口:\"\n            [[ ! $is_new_dynamic_port_end ]] && ask string is_new_dynamic_port_end \"请输入新的动态结束端口:\"\n            add $net auto auto auto $is_new_dynamic_port_start $is_new_dynamic_port_end\n        fi\n        ;;\n    13)\n        # new proxy site\n        is_new_proxy_site=$3\n        [[ ! $is_caddy && ! $host ]] && {\n            err \"($is_config_file) 不支持更改伪装网站.\"\n        }\n        [[ ! -f $is_caddy_conf/${host}.conf.add ]] && err \"无法配置伪装网站.\"\n        [[ ! $is_new_proxy_site ]] && ask string is_new_proxy_site \"请输入新的伪装网站 (例如 example.com):\"\n        proxy_site=$(sed 's#^.*//##;s#/$##' <<<$is_new_proxy_site)\n        [[ $(grep -i \"^233boy.com$\" <<<$proxy_site) ]] && {\n            err \"你干嘛～哎呦～\"\n        } || {\n            load caddy.sh\n            caddy_config proxy\n            manage restart caddy &\n        }\n        msg \"\\n已更新伪装网站为: $(_green $proxy_site) \\n\"\n        ;;\n    14)\n        # new kcp seed\n        is_new_kcp_seed=$3\n        [[ ! $kcp_seed ]] && err \"($is_config_file) 不支持更改 mKCP seed.\"\n        [[ $is_auto ]] && get_uuid && is_new_kcp_seed=$tmp_uuid\n        [[ ! $is_new_kcp_seed ]] && ask string is_new_kcp_seed \"请输入新 mKCP seed:\"\n        kcp_seed=$is_new_kcp_seed\n        add $net\n        ;;\n    15)\n        # new socks user\n        [[ ! $is_socks_user ]] && err \"($is_config_file) 不支持更改用户名 (Username).\"\n        ask string is_socks_user \"请输入新用户名 (Username):\"\n        add $net\n        ;;\n    esac\n}\n\n# delete config.\ndel() {\n    # dont get ip\n    is_dont_get_ip=1\n    [[ $is_conf_dir_empty ]] && return # not found any json file.\n    # get a config file\n    [[ ! $is_config_file ]] && get info $1\n    if [[ $is_config_file ]]; then\n        if [[ $is_main_start && ! $is_no_del_msg ]]; then\n            msg \"\\n是否删除配置文件?: $is_config_file\"\n            pause\n        fi\n        api del $is_conf_dir/\"$is_config_file\" $is_dynamic_port_file &>/dev/null\n        rm -rf $is_conf_dir/\"$is_config_file\" $is_dynamic_port_file\n        [[ $is_api_fail && ! $is_new_json ]] && manage restart &\n        [[ ! $is_no_del_msg ]] && _green \"\\n已删除: $is_config_file\\n\"\n\n        [[ $is_caddy ]] && {\n            is_del_host=$host\n            [[ $is_change ]] && {\n                [[ ! $old_host ]] && return # no host exist or not set new host;\n                is_del_host=$old_host\n            }\n            [[ $is_del_host && $host != $old_host && ! $is_no_auto_tls ]] && {\n                rm -rf $is_caddy_conf/$is_del_host.conf $is_caddy_conf/$is_del_host.conf.add\n                [[ ! $is_new_json ]] && manage restart caddy &\n            }\n        }\n    fi\n    if [[ ! $(ls $is_conf_dir | grep .json) && ! $is_change ]]; then\n        warn \"当前配置目录为空! 因为你刚刚删除了最后一个配置文件.\"\n        is_conf_dir_empty=1\n    fi\n    unset is_dont_get_ip\n    [[ $is_dont_auto_exit ]] && unset is_config_file\n}\n\n# uninstall\nuninstall() {\n    if [[ $is_caddy ]]; then\n        is_tmp_list=(\"卸载 $is_core_name\" \"卸载 ${is_core_name} & Caddy\")\n        ask list is_do_uninstall\n    else\n        ask string y \"是否卸载 ${is_core_name}? [y]:\"\n    fi\n    manage stop &>/dev/null\n    manage disable &>/dev/null\n    rm -rf $is_core_dir $is_log_dir $is_sh_bin /lib/systemd/system/$is_core.service\n    sed -i \"/$is_core/d\" /root/.bashrc\n    # uninstall caddy; 2 is ask result\n    if [[ $REPLY == '2' ]]; then\n        manage stop caddy &>/dev/null\n        manage disable caddy &>/dev/null\n        rm -rf $is_caddy_dir $is_caddy_bin /lib/systemd/system/caddy.service\n    fi\n    [[ $is_install_sh ]] && return # reinstall\n    _green \"\\n卸载完成!\"\n    msg \"脚本哪里需要完善? 请反馈\"\n    msg \"反馈问题) $(msg_ul https://github.com/${is_sh_repo}/issues)\\n\"\n}\n\n# manage run status\nmanage() {\n    [[ $is_dont_auto_exit ]] && return\n    case $1 in\n    1 | start)\n        is_do=start\n        is_do_msg=启动\n        is_test_run=1\n        ;;\n    2 | stop)\n        is_do=stop\n        is_do_msg=停止\n        ;;\n    3 | r | restart)\n        is_do=restart\n        is_do_msg=重启\n        is_test_run=1\n        ;;\n    *)\n        is_do=$1\n        is_do_msg=$1\n        ;;\n    esac\n    case $2 in\n    caddy)\n        is_do_name=$2\n        is_run_bin=$is_caddy_bin\n        is_do_name_msg=Caddy\n        ;;\n    *)\n        is_do_name=$is_core\n        is_run_bin=$is_core_bin\n        is_do_name_msg=$is_core_name\n        ;;\n    esac\n    systemctl $is_do $is_do_name\n    [[ $is_test_run && ! $is_new_install ]] && {\n        sleep 2\n        if [[ ! $(pgrep -f $is_run_bin) ]]; then\n            is_run_fail=${is_do_name_msg,,}\n            [[ ! $is_no_manage_msg ]] && {\n                msg\n                warn \"($is_do_msg) $is_do_name_msg 失败\"\n                _yellow \"检测到运行失败, 自动执行测试运行.\"\n                get test-run\n                _yellow \"测试结束, 请按 Enter 退出.\"\n            }\n        fi\n    }\n}\n\n# use api add or del inbounds\napi() {\n    [[ $is_core_ver_lt_5 ]] && {\n        warn \"$is_core_ver 版本不支持使用 API 操作. 请升级内核版本: $is_core update core\"\n        is_api_fail=1\n        return\n    }\n    [[ ! $1 ]] && err \"无法识别 API 的参数.\"\n    [[ $is_core_stop ]] && {\n        warn \"$is_core_name 当前处于停止状态.\"\n        is_api_fail=1\n        return\n    }\n    case $1 in\n    add)\n        is_api_do=adi\n        ;;\n    del)\n        is_api_do=rmi\n        ;;\n    s)\n        is_api_do=stats\n        ;;\n    t | sq)\n        is_api_do=statsquery\n        ;;\n    esac\n    [[ ! $is_api_do ]] && is_api_do=$1\n    [[ ! $is_api_port ]] && {\n        is_api_port=$(jq '.inbounds[] | select(.tag == \"api\") | .port' $is_config_json)\n        [[ $? != 0 ]] && {\n            warn \"读取 API 端口失败, 无法使用 API 操作.\"\n            return\n        }\n    }\n    $is_core_bin api $is_api_do --server=127.0.0.1:$is_api_port ${@:2}\n    [[ $? != 0 ]] && {\n        is_api_fail=1\n    }\n}\n\n# add a config\nadd() {\n    is_lower=${1,,}\n    if [[ $is_lower ]]; then\n        case $is_lower in\n        tcp | kcp | quic | tcpd | kcpd | quicd)\n            is_new_protocol=VMess-$(sed 's/^K/mK/;s/D$/-dynamic-port/' <<<${is_lower^^})\n            ;;\n        ws | h2 | grpc | vws | vh2 | vgrpc | tws | th2 | tgrpc)\n            is_new_protocol=$(sed -E \"s/^V/VLESS-/;s/^T/Trojan-/;/^(W|H|G)/{s/^/VMess-/};s/G/g/\" <<<${is_lower^^})-TLS\n            ;;\n        # r | reality)\n        #     is_new_protocol=VLESS-XTLS-uTLS-REALITY\n        #     ;;\n        ss)\n            is_new_protocol=Shadowsocks\n            ;;\n        door)\n            is_new_protocol=Dokodemo-Door\n            ;;\n        socks)\n            is_new_protocol=Socks\n            ;;\n        http)\n            is_new_protocol=local-$is_lower\n            ;;\n        *)\n            for v in ${protocol_list[@]}; do\n                [[ $(grep -E -i \"^$is_lower$\" <<<$v) ]] && is_new_protocol=$v && break\n            done\n\n            [[ ! $is_new_protocol ]] && err \"无法识别 ($1), 请使用: $is_core add [protocol] [args... | auto]\"\n            ;;\n        esac\n    fi\n\n    # no prefer protocol\n    [[ ! $is_new_protocol ]] && ask set_protocol\n\n    case ${is_new_protocol,,} in\n    *-tls)\n        is_use_tls=1\n        is_use_host=$2\n        is_use_uuid=$3\n        is_use_path=$4\n        is_add_opts=\"[host] [uuid] [/path]\"\n        ;;\n    vmess*)\n        is_use_port=$2\n        is_use_uuid=$3\n        is_use_header_type=$4\n        is_use_dynamic_port_start=$5\n        is_use_dynamic_port_end=$6\n        [[ $(grep dynamic-port <<<$is_new_protocol) ]] && is_dynamic_port=1\n        if [[ $is_dynamic_port ]]; then\n            is_add_opts=\"[port] [uuid] [type] [start_port] [end_port]\"\n        else\n            is_add_opts=\"[port] [uuid] [type]\"\n        fi\n        ;;\n    # *reality*)\n    #     is_reality=1\n    #     is_use_port=$2\n    #     is_use_uuid=$3\n    #     is_use_servername=$4\n    #     ;;\n    shadowsocks)\n        is_use_port=$2\n        is_use_pass=$3\n        is_use_method=$4\n        is_add_opts=\"[port] [password] [method]\"\n        ;;\n    *door)\n        is_use_port=$2\n        is_use_door_addr=$3\n        is_use_door_port=$4\n        is_add_opts=\"[port] [remote_addr] [remote_port]\"\n        ;;\n    socks)\n        is_socks=1\n        is_use_port=$2\n        is_use_socks_user=$3\n        is_use_socks_pass=$4\n        is_add_opts=\"[port] [username] [password]\"\n        ;;\n    *http)\n        is_use_port=$2\n        is_add_opts=\"[port]\"\n        ;;\n    esac\n\n    [[ $1 && ! $is_change ]] && {\n        msg \"\\n使用协议: $is_new_protocol\"\n        # err msg tips\n        is_err_tips=\"\\n\\n请使用: $(_green $is_core add $1 $is_add_opts) 来添加 $is_new_protocol 配置\"\n    }\n\n    # remove old protocol args\n    if [[ $is_set_new_protocol ]]; then\n        case $is_old_net in\n        tcp)\n            unset header_type net\n            ;;\n        kcp | quic)\n            kcp_seed=\n            [[ $(grep -i tcp <<<$is_new_protocol) ]] && header_type=\n            ;;\n        h2 | ws | grpc)\n            old_host=$host\n            if [[ ! $is_use_tls ]]; then\n                unset host is_no_auto_tls\n            else\n                [[ $is_old_net == 'grpc' ]] && {\n                    path=/$path\n                }\n            fi\n            [[ ! $(grep -i trojan <<<$is_new_protocol) ]] && is_trojan=\n            ;;\n        reality)\n            [[ ! $(grep -i reality <<<$is_new_protocol) ]] && is_reality=\n            ;;\n        ss)\n            [[ $(is_test uuid $ss_password) ]] && uuid=$ss_password\n            ;;\n        esac\n        [[ $is_dynamic_port && ! $(grep dynamic-port <<<$is_new_protocol) ]] && {\n            is_dynamic_port=\n        }\n\n        [[ ! $(is_test uuid $uuid) ]] && uuid=\n    fi\n\n    # no-auto-tls only use h2,ws,grpc\n    if [[ $is_no_auto_tls && ! $is_use_tls ]]; then\n        err \"$is_new_protocol 不支持手动配置 tls.\"\n    fi\n\n    # prefer args.\n    if [[ $2 ]]; then\n        for v in is_use_port is_use_uuid is_use_header_type is_use_host is_use_path is_use_pass is_use_method is_use_door_addr is_use_door_port is_use_dynamic_port_start is_use_dynamic_port_end; do\n            [[ ${!v} == 'auto' ]] && unset $v\n        done\n\n        if [[ $is_use_port ]]; then\n            [[ ! $(is_test port ${is_use_port}) ]] && {\n                err \"($is_use_port) 不是一个有效的端口. $is_err_tips\"\n            }\n            [[ $(is_test port_used $is_use_port) ]] && {\n                err \"无法使用 ($is_use_port) 端口. $is_err_tips\"\n            }\n            port=$is_use_port\n        fi\n        if [[ $is_use_door_port ]]; then\n            [[ ! $(is_test port ${is_use_door_port}) ]] && {\n                err \"(${is_use_door_port}) 不是一个有效的目标端口. $is_err_tips\"\n            }\n            door_port=$is_use_door_port\n        fi\n        if [[ $is_use_uuid ]]; then\n            [[ ! $(is_test uuid $is_use_uuid) ]] && {\n                err \"($is_use_uuid) 不是一个有效的 UUID. $is_err_tips\"\n            }\n            uuid=$is_use_uuid\n        fi\n        if [[ $is_use_path ]]; then\n            [[ ! $(is_test path $is_use_path) ]] && {\n                err \"($is_use_path) 不是有效的路径. $is_err_tips\"\n            }\n            path=$is_use_path\n        fi\n        if [[ $is_use_header_type || $is_use_method ]]; then\n            is_tmp_use_name=加密方式\n            is_tmp_list=${ss_method_list[@]}\n            [[ ! $is_use_method ]] && {\n                is_tmp_use_name=伪装类型\n                ask set_header_type\n            }\n            for v in ${is_tmp_list[@]}; do\n                [[ $(grep -E -i \"^${is_use_header_type}${is_use_method}$\" <<<$v) ]] && is_tmp_use_type=$v && break\n            done\n            [[ ! ${is_tmp_use_type} ]] && {\n                warn \"(${is_use_header_type}${is_use_method}) 不是一个可用的${is_tmp_use_name}.\"\n                msg \"${is_tmp_use_name}可用如下: \"\n                for v in ${is_tmp_list[@]}; do\n                    msg \"\\t\\t$v\"\n                done\n                msg \"$is_err_tips\\n\"\n                exit 1\n            }\n            ss_method=$is_tmp_use_type\n            header_type=$is_tmp_use_type\n        fi\n        if [[ $is_dynamic_port && $is_use_dynamic_port_start ]]; then\n            get dynamic-port-test\n        fi\n        [[ $is_use_pass ]] && ss_password=$is_use_pass\n        [[ $is_use_host ]] && host=$is_use_host\n        [[ $is_use_door_addr ]] && door_addr=$is_use_door_addr\n        [[ $is_use_servername ]] && is_servername=$is_use_servername\n        [[ $is_use_socks_user ]] && is_socks_user=$is_use_socks_user\n        [[ $is_use_socks_pass ]] && is_socks_pass=$is_use_socks_pass\n    fi\n\n    if [[ $is_use_tls ]]; then\n        if [[ ! $is_no_auto_tls && ! $is_caddy && ! $is_gen ]]; then\n            # test auto tls\n            [[ $(is_test port_used 80) || $(is_test port_used 443) ]] && {\n                get_port\n                is_http_port=$tmp_port\n                get_port\n                is_https_port=$tmp_port\n                warn \"端口 (80 或 443) 已经被占用, 你也可以考虑使用 no-auto-tls\"\n                msg \"\\e[41m no-auto-tls 帮助(help)\\e[0m: $(msg_ul https://233boy.com/$is_core/no-auto-tls/)\\n\"\n                msg \"\\n Caddy 将使用非标准端口实现自动配置 TLS, HTTP:$is_http_port HTTPS:$is_https_port\\n\"\n                msg \"请确定是否继续???\"\n                pause\n            }\n            is_install_caddy=1\n        fi\n        # set host\n        [[ ! $host ]] && ask string host \"请输入域名:\"\n        # test host dns\n        get host-test\n    else\n        # for main menu start, dont auto create args\n        if [[ $is_main_start ]]; then\n\n            # set port\n            [[ ! $port ]] && ask string port \"请输入端口:\"\n\n            case ${is_new_protocol,,} in\n            *tcp* | *kcp* | *quic*)\n                [[ ! $header_type ]] && ask set_header_type\n                ;;\n            socks)\n                # set user\n                [[ ! $is_socks_user ]] && ask string is_socks_user \"请设置用户名:\"\n                # set password\n                [[ ! $is_socks_pass ]] && ask string is_socks_pass \"请设置密码:\"\n                ;;\n            shadowsocks)\n                # set method\n                [[ ! $ss_method ]] && ask set_ss_method\n                # set password\n                [[ ! $ss_password ]] && ask string ss_password \"请设置密码:\"\n                ;;\n            esac\n            # set dynamic port\n            [[ $is_dynamic_port && ! $is_dynamic_port_range ]] && {\n                ask string is_use_dynamic_port_start \"请输入动态开始端口:\"\n                ask string is_use_dynamic_port_end \"请输入动态结束端口:\"\n                get dynamic-port-test\n            }\n        fi\n    fi\n\n    # Dokodemo-Door\n    if [[ $is_new_protocol == 'Dokodemo-Door' ]]; then\n        # set remote addr\n        [[ ! $door_addr ]] && ask string door_addr \"请输入目标地址:\"\n        # set remote port\n        [[ ! $door_port ]] && ask string door_port \"请输入目标端口:\"\n    fi\n\n    # Shadowsocks 2022\n    if [[ $(grep 2022 <<<$ss_method) ]]; then\n        # test ss2022 password\n        [[ $ss_password ]] && {\n            is_test_json=1\n            # create server Shadowsocks | $is_core_bin -test &>/dev/null\n            create server Shadowsocks\n            $is_core_bin -test <<<\"$is_new_json\" &>/dev/null\n            if [[ $? != 0 ]]; then\n                warn \"Shadowsocks 协议 ($ss_method) 不支持使用密码 ($(_red_bg $ss_password))\\n\\n你可以使用命令: $(_green $is_core ss2022) 生成支持的密码.\\n\\n脚本将自动创建可用密码:)\"\n                ss_password=\n                # create new json.\n                json_str=\n            fi\n            is_test_json=\n        }\n\n    fi\n\n    # install caddy\n    if [[ $is_install_caddy ]]; then\n        get install-caddy\n    fi\n\n    # create json\n    create server $is_new_protocol\n\n    # show config info.\n    info\n}\n\n# get config info\n# or somes required args\nget() {\n    case $1 in\n    addr)\n        is_addr=$host\n        [[ ! $is_addr ]] && {\n            get_ip\n            is_addr=$ip\n            [[ $(grep \":\" <<<$ip) ]] && is_addr=\"[$ip]\"\n        }\n        ;;\n    new)\n        [[ ! $host ]] && get_ip\n        [[ ! $port ]] && get_port && port=$tmp_port\n        [[ ! $uuid ]] && get_uuid && uuid=$tmp_uuid\n        ;;\n    file)\n        is_file_str=$2\n        [[ ! $is_file_str ]] && is_file_str='.json$'\n        # is_all_json=(\"$(ls $is_conf_dir | grep -E $is_file_str)\")\n        readarray -t is_all_json <<<\"$(ls $is_conf_dir | grep -E -i \"$is_file_str\" | sed '/dynamic-port-.*-link/d' | head -233)\" # limit max 233 lines for show.\n        [[ ! $is_all_json ]] && err \"无法找到相关的配置文件: $2\"\n        [[ ${#is_all_json[@]} -eq 1 ]] && is_config_file=$is_all_json && is_auto_get_config=1\n        [[ ! $is_config_file ]] && {\n            [[ $is_dont_auto_exit ]] && return\n            ask get_config_file\n        }\n        ;;\n    info)\n        get file $2\n        if [[ $is_config_file ]]; then\n            is_json_str=$(cat $is_conf_dir/\"$is_config_file\")\n            is_json_data_base=$(jq '.inbounds[0]|.protocol,.port,.settings.clients[0].id,.settings.clients[0].password,.settings.method,.settings.password,.settings.address,.settings.port,.settings.detour.to,.settings.accounts[0].user,.settings.accounts[0].pass' <<<$is_json_str)\n            [[ $? != 0 ]] && err \"无法读取此文件: $is_config_file\"\n            is_json_data_more=$(jq '.inbounds[0]|.streamSettings|.network,.security,.tcpSettings.header.type,.kcpSettings.seed,.kcpSettings.header.type,.quicSettings.header.type,.wsSettings.path,.httpSettings.path,.grpcSettings.serviceName' <<<$is_json_str)\n            is_json_data_host=$(jq '.inbounds[0]|.streamSettings|.grpc_host,.wsSettings.headers.Host,.httpSettings.host[0]' <<<$is_json_str)\n            is_json_data_reality=$(jq '.inbounds[0]|.streamSettings|.realitySettings.serverNames[0],.realitySettings.publicKey,.realitySettings.privateKey' <<<$is_json_str)\n            is_up_var_set=(null is_protocol port uuid trojan_password ss_method ss_password door_addr door_port is_dynamic_port is_socks_user is_socks_pass net is_reality tcp_type kcp_seed kcp_type quic_type ws_path h2_path grpc_path grpc_host ws_host h2_host is_servername is_public_key is_private_key)\n            [[ $is_debug ]] && msg \"\\n------------- debug: $is_config_file -------------\"\n            i=0\n            for v in $(sed 's/\"\"/null/g;s/\"//g' <<<\"$is_json_data_base $is_json_data_more $is_json_data_host $is_json_data_reality\"); do\n                ((i++))\n                [[ $is_debug ]] && msg \"$i-${is_up_var_set[$i]}: $v\"\n                export ${is_up_var_set[$i]}=\"${v}\"\n            done\n            for v in ${is_up_var_set[@]}; do\n                [[ ${!v} == 'null' ]] && unset $v\n            done\n\n            path=\"${ws_path}${h2_path}${grpc_path}\"\n            host=\"${ws_host}${h2_host}${grpc_host}\"\n            header_type=\"${tcp_type}${kcp_type}${quic_type}\"\n            if [[ $is_reality == 'reality' ]]; then\n                net=reality\n            else\n                is_reality=\n            fi\n            [[ ! $kcp_seed ]] && is_no_kcp_seed=1\n            is_config_name=$is_config_file\n            if [[ $is_dynamic_port ]]; then\n                is_dynamic_port_file=$is_conf_dir/$is_dynamic_port\n                is_dynamic_port_range=$(jq -r '.inbounds[0].port' $is_dynamic_port_file)\n                [[ $? != 0 ]] && err \"无法读取动态端口文件: $is_dynamic_port\"\n            fi\n            if [[ $is_caddy && $host && -f $is_caddy_conf/$host.conf ]]; then\n                is_tmp_https_port=$(grep -E -o \"$host:[1-9][0-9]?+\" $is_caddy_conf/$host.conf | sed s/.*://)\n            fi\n            if [[ $host && ! -f $is_caddy_conf/$host.conf ]]; then\n                is_no_auto_tls=1\n            fi\n            [[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port\n            [[ $is_client && $host ]] && port=$is_https_port\n            get protocol $is_protocol-$net\n        fi\n        ;;\n    protocol)\n        get addr # get host or server ip\n        is_lower=${2,,}\n        net=\n        case $is_lower in\n        vmess*)\n            is_protocol=vmess\n            if [[ $is_dynamic_port ]]; then\n                is_server_id_json='settings:{clients:[{id:'\\\"$uuid\\\"'}],detour:{to:'\\\"$is_config_name-link.json\\\"'}}'\n            else\n                is_server_id_json='settings:{clients:[{id:'\\\"$uuid\\\"'}]}'\n            fi\n            is_client_id_json='settings:{vnext:[{address:'\\\"$is_addr\\\"',port:'\"$port\"',users:[{id:'\\\"$uuid\\\"'}]}]}'\n            ;;\n        vless*)\n            is_protocol=vless\n            is_server_id_json='settings:{clients:[{id:'\\\"$uuid\\\"'}],decryption:\"none\"}'\n            is_client_id_json='settings:{vnext:[{address:'\\\"$is_addr\\\"',port:'\"$port\"',users:[{id:'\\\"$uuid\\\"',encryption:\"none\"}]}]}'\n            if [[ $is_reality ]]; then\n                is_server_id_json='settings:{clients:[{id:'\\\"$uuid\\\"',flow:\"xtls-rprx-vision\"}],decryption:\"none\"}'\n                is_client_id_json='settings:{vnext:[{address:'\\\"$is_addr\\\"',port:'\"$port\"',users:[{id:'\\\"$uuid\\\"',encryption:\"none\",flow:\"xtls-rprx-vision\"}]}]}'\n            fi\n            ;;\n        trojan*)\n            is_protocol=trojan\n            [[ ! $trojan_password ]] && trojan_password=$uuid\n            is_server_id_json='settings:{clients:[{password:'\\\"$trojan_password\\\"'}]}'\n            is_client_id_json='settings:{servers:[{address:'\\\"$is_addr\\\"',port:'\"$port\"',password:'\\\"$trojan_password\\\"'}]}'\n            is_trojan=1\n            ;;\n        shadowsocks*)\n            is_protocol=shadowsocks\n            net=ss\n            [[ ! $ss_method ]] && ss_method=$is_random_ss_method\n            [[ ! $ss_password ]] && {\n                ss_password=$uuid\n                [[ $(grep 2022 <<<$ss_method) ]] && ss_password=$(get ss2022)\n            }\n            is_client_id_json='settings:{servers:[{address:'\\\"$is_addr\\\"',port:'\"$port\"',method:'\\\"$ss_method\\\"',password:'\\\"$ss_password\\\"',}]}'\n            json_str='settings:{method:'\\\"$ss_method\\\"',password:'\\\"$ss_password\\\"',network:\"tcp,udp\"}'\n            ;;\n        dokodemo-door*)\n            is_protocol=dokodemo-door\n            net=door\n            json_str='settings:{port:'\"$door_port\"',address:'\\\"$door_addr\\\"',network:\"tcp,udp\"}'\n            ;;\n        *http*)\n            is_protocol=http\n            net=http\n            json_str='settings:{\"timeout\": 233}'\n            ;;\n        *socks*)\n            is_protocol=socks\n            net=socks\n            [[ ! $is_socks_user ]] && is_socks_user=233boy\n            [[ ! $is_socks_pass ]] && is_socks_pass=$uuid\n            json_str='settings:{auth:\"password\",accounts:[{user:'\\\"$is_socks_user\\\"',pass:'\\\"$is_socks_pass\\\"'}],udp:true,ip:\"0.0.0.0\"}'\n            ;;\n        *)\n            err \"无法识别协议: $is_config_file\"\n            ;;\n        esac\n        [[ $net ]] && return # if net exist, dont need more json args\n        case $is_lower in\n        *tcp*)\n            net=tcp\n            [[ ! $header_type ]] && header_type=none\n            is_stream='streamSettings:{network:\"tcp\",tcpSettings:{header:{type:'\\\"$header_type\\\"'}}}'\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *kcp* | *mkcp)\n            net=kcp\n            [[ ! $header_type ]] && header_type=$is_random_header_type\n            [[ ! $is_no_kcp_seed && ! $kcp_seed ]] && kcp_seed=$uuid\n            is_stream='streamSettings:{network:\"kcp\",kcpSettings:{seed:'\\\"$kcp_seed\\\"',header:{type:'\\\"$header_type\\\"'}}}'\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *quic*)\n            net=quic\n            [[ ! $header_type ]] && header_type=$is_random_header_type\n            is_stream='streamSettings:{network:\"quic\",quicSettings:{header:{type:'\\\"$header_type\\\"'}}}'\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *ws* | *websocket)\n            net=ws\n            [[ ! $path ]] && path=\"/$uuid\"\n            is_stream='streamSettings:{network:\"ws\",security:'\\\"$is_tls\\\"',wsSettings:{path:'\\\"$path\\\"',headers:{Host:'\\\"$host\\\"'}}}'\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *grpc* | *gun)\n            net=grpc\n            [[ ! $path ]] && path=\"$uuid\"\n            [[ $path ]] && path=$(sed 's#/##g' <<<$path)\n            is_stream='streamSettings:{network:\"grpc\",grpc_host:'\\\"$host\\\"',security:'\\\"$is_tls\\\"',grpcSettings:{serviceName:'\\\"$path\\\"'}}'\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *h2* | *http*)\n            net=h2\n            [[ ! $path ]] && path=\"/$uuid\"\n            is_stream='streamSettings:{network:\"h2\",security:'\\\"$is_tls\\\"',httpSettings:{path:'\\\"$path\\\"',host:['\\\"$host\\\"']}}'\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *reality*)\n            net=reality\n            [[ ! $is_servername ]] && is_servername=$is_random_servername\n            [[ ! $is_private_key ]] && get_pbk\n            is_stream='streamSettings:{network:\"tcp\",security:\"reality\",realitySettings:{dest:'\\\"${is_servername}\\:443\\\"',serverNames:['\\\"${is_servername}\\\"',\"\"],publicKey:'\\\"$is_public_key\\\"',privateKey:'\\\"$is_private_key\\\"',shortIds:[\"\"]}}'\n            if [[ $is_client ]]; then\n                is_stream='streamSettings:{network:\"tcp\",security:\"reality\",realitySettings:{serverName:'\\\"${is_servername}\\\"',\"fingerprint\": \"ios\",publicKey:'\\\"$is_public_key\\\"',\"shortId\": \"\",\"spiderX\": \"/\"}}'\n            fi\n            json_str=''\"$is_server_id_json\"','\"$is_stream\"''\n            ;;\n        *)\n            err \"无法识别传输协议: $is_config_file\"\n            ;;\n        esac\n        ;;\n    dynamic-port) # create random dynamic port\n        if [[ $port -ge 60000 ]]; then\n            is_dynamic_port_end=$(shuf -i $(($port - 2333))-$port -n1)\n            is_dynamic_port_start=$(shuf -i $(($is_dynamic_port_end - 2333))-$is_dynamic_port_end -n1)\n        else\n            is_dynamic_port_start=$(shuf -i $port-$(($port + 2333)) -n1)\n            is_dynamic_port_end=$(shuf -i $is_dynamic_port_start-$(($is_dynamic_port_start + 2333)) -n1)\n        fi\n        is_dynamic_port_range=\"$is_dynamic_port_start-$is_dynamic_port_end\"\n        ;;\n    dynamic-port-test) # test dynamic port\n        [[ ! $(is_test port ${is_use_dynamic_port_start}) || ! $(is_test port ${is_use_dynamic_port_end}) ]] && {\n            err \"无法正确处理动态端口 ($is_use_dynamic_port_start-$is_use_dynamic_port_end) 范围.\"\n        }\n        [[ $(is_test port_used $is_use_dynamic_port_start) ]] && {\n            err \"动态端口 ($is_use_dynamic_port_start-$is_use_dynamic_port_end), 但 ($is_use_dynamic_port_start) 端口无法使用.\"\n        }\n        [[ $(is_test port_used $is_use_dynamic_port_end) ]] && {\n            err \"动态端口 ($is_use_dynamic_port_start-$is_use_dynamic_port_end), 但 ($is_use_dynamic_port_end) 端口无法使用.\"\n        }\n        [[ $is_use_dynamic_port_end -le $is_use_dynamic_port_start ]] && {\n            err \"无法正确处理动态端口 ($is_use_dynamic_port_start-$is_use_dynamic_port_end) 范围.\"\n        }\n        [[ $is_use_dynamic_port_start == $port || $is_use_dynamic_port_end == $port ]] && {\n            err \"动态端口 ($is_use_dynamic_port_start-$is_use_dynamic_port_end) 范围和主端口 ($port) 冲突.\"\n        }\n        is_dynamic_port_range=\"$is_use_dynamic_port_start-$is_use_dynamic_port_end\"\n        ;;\n    host-test) # test host dns record; for auto *tls required.\n        [[ $is_no_auto_tls || $is_gen ]] && return\n        get_ip\n        get ping\n        if [[ ! $(grep $ip <<<$is_host_dns) ]]; then\n            msg \"\\n请将 ($(_red_bg $host)) 解析到 ($(_red_bg $ip))\"\n            msg \"\\n如果使用 Cloudflare, 在 DNS 那; 关闭 (Proxy status / 代理状态), 即是 (DNS only / 仅限 DNS)\"\n            ask string y \"我已经确定解析 [y]:\"\n            get ping\n            if [[ ! $(grep $ip <<<$is_host_dns) ]]; then\n                _cyan \"\\n测试结果: $is_host_dns\"\n                err \"域名 ($host) 没有解析到 ($ip)\"\n            fi\n        fi\n        ;;\n    ssss | ss2022)\n        openssl rand -base64 32\n        [[ $? != 0 ]] && err \"无法生成 Shadowsocks 2022 密码, 请安装 openssl.\"\n        ;;\n    ping)\n        # is_ip_type=\"-4\"\n        # [[ $(grep \":\" <<<$ip) ]] && is_ip_type=\"-6\"\n        # is_host_dns=$(ping $host $is_ip_type -c 1 -W 2 | head -1)\n        is_dns_type=\"a\"\n        [[ $(grep \":\" <<<$ip) ]] && is_dns_type=\"aaaa\"\n        is_host_dns=$(_wget -qO- --header=\"accept: application/dns-json\" \"https://one.one.one.one/dns-query?name=$host&type=$is_dns_type\")\n        ;;\n    log | logerr)\n        msg \"\\n 提醒: 按 $(_green Ctrl + C) 退出\\n\"\n        [[ $1 == 'log' ]] && tail -f $is_log_dir/access.log\n        [[ $1 == 'logerr' ]] && tail -f $is_log_dir/error.log\n        ;;\n    install-caddy)\n        _green \"\\n安装 Caddy 实现自动配置 TLS.\\n\"\n        load download.sh\n        download caddy\n        load systemd.sh\n        install_service caddy &>/dev/null\n        is_caddy=1\n        _green \"安装 Caddy 成功.\\n\"\n        ;;\n    reinstall)\n        is_install_sh=$(cat $is_sh_dir/install.sh)\n        uninstall\n        bash <<<$is_install_sh\n        ;;\n    test-run)\n        systemctl list-units --full -all &>/dev/null\n        [[ $? != 0 ]] && {\n            _yellow \"\\n无法执行测试, 请检查 systemctl 状态.\\n\"\n            return\n        }\n        is_no_manage_msg=1\n        if [[ ! $(pgrep -f $is_core_bin) ]]; then\n            _yellow \"\\n测试运行 $is_core_name ..\\n\"\n            manage start &>/dev/null\n            if [[ $is_run_fail == $is_core ]]; then\n                _red \"$is_core_name 运行失败信息:\"\n                $is_core_bin $is_with_run_arg -c $is_config_json -confdir $is_conf_dir\n            else\n                _green \"\\n测试通过, 已启动 $is_core_name ..\\n\"\n            fi\n        else\n            _green \"\\n$is_core_name 正在运行, 跳过测试\\n\"\n        fi\n        if [[ $is_caddy ]]; then\n            if [[ ! $(pgrep -f $is_caddy_bin) ]]; then\n                _yellow \"\\n测试运行 Caddy ..\\n\"\n                manage start caddy &>/dev/null\n                if [[ $is_run_fail == 'caddy' ]]; then\n                    _red \"Caddy 运行失败信息:\"\n                    $is_caddy_bin run --config $is_caddyfile\n                else\n                    _green \"\\n测试通过, 已启动 Caddy ..\\n\"\n                fi\n            else\n                _green \"\\nCaddy 正在运行, 跳过测试\\n\"\n            fi\n        fi\n        ;;\n    esac\n}\n\n# show info\ninfo() {\n    if [[ ! $is_protocol ]]; then\n        get info $1\n    fi\n    # is_color=$(shuf -i 41-45 -n1)\n    is_color=44\n    case $net in\n    tcp | kcp | quic)\n        is_can_change=(0 1 5 7)\n        is_info_show=(0 1 2 3 4 5)\n        is_vmess_url=$(jq -c '{v:2,ps:'\\\"233boy-${net}-$is_addr\\\"',add:'\\\"$is_addr\\\"',port:'\\\"$port\\\"',id:'\\\"$uuid\\\"',aid:\"0\",net:'\\\"$net\\\"',type:'\\\"$header_type\\\"',path:'\\\"$kcp_seed\\\"'}' <<<{})\n        is_url=vmess://$(echo -n $is_vmess_url | base64 -w 0)\n        is_tmp_port=$port\n        [[ $is_dynamic_port ]] && {\n            is_can_change+=(12)\n            is_tmp_port=\"$port & 动态端口: $is_dynamic_port_range\"\n        }\n        [[ $kcp_seed ]] && {\n            is_info_show+=(9)\n            is_can_change+=(14)\n        }\n        is_info_str=($is_protocol $is_addr \"$is_tmp_port\" $uuid $net $header_type $kcp_seed)\n        ;;\n    ss)\n        is_can_change=(0 1 4 6)\n        is_info_show=(0 1 2 10 11)\n        is_url=\"ss://$(echo -n ${ss_method}:${ss_password} | base64 -w 0)@${is_addr}:${port}#233boy-$net-${is_addr}\"\n        is_info_str=($is_protocol $is_addr $port $ss_password $ss_method)\n        ;;\n    ws | h2 | grpc)\n        is_color=45\n        is_can_change=(0 1 2 3 5)\n        is_info_show=(0 1 2 3 4 6 7 8)\n        is_url_path=path\n        [[ $net == 'grpc' ]] && {\n            path=$(sed 's#/##g' <<<$path)\n            is_url_path=serviceName\n        }\n        [[ $is_protocol == 'vmess' ]] && {\n            is_vmess_url=$(jq -c '{v:2,ps:'\\\"233boy-$net-$host\\\"',add:'\\\"$is_addr\\\"',port:'\\\"$is_https_port\\\"',id:'\\\"$uuid\\\"',aid:\"0\",net:'\\\"$net\\\"',host:'\\\"$host\\\"',path:'\\\"$path\\\"',tls:'\\\"tls\\\"'}' <<<{})\n            is_url=vmess://$(echo -n $is_vmess_url | base64 -w 0)\n        } || {\n            [[ $is_trojan ]] && {\n                uuid=$trojan_password\n                is_can_change=(0 1 2 3 4)\n                is_info_show=(0 1 2 10 4 6 7 8)\n            }\n            is_url=\"$is_protocol://$uuid@$host:$is_https_port?encryption=none&security=tls&type=$net&host=$host&${is_url_path}=$(sed 's#/#%2F#g' <<<$path)#233boy-$net-$host\"\n        }\n        [[ $is_caddy ]] && is_can_change+=(13)\n        is_info_str=($is_protocol $is_addr $is_https_port $uuid $net $host $path 'tls')\n        ;;\n    reality)\n        is_color=41\n        is_can_change=(0 1 5 10 11)\n        is_info_show=(0 1 2 3 15 8 16 17 18)\n        is_info_str=($is_protocol $is_addr $port $uuid xtls-rprx-vision reality $is_servername \"ios\" $is_public_key)\n        is_url=\"$is_protocol://$uuid@$is_addr:$port?encryption=none&security=reality&flow=xtls-rprx-vision&type=tcp&sni=$is_servername&pbk=$is_public_key&fp=ios#233boy-$net-$is_addr\"\n        ;;\n    door)\n        is_can_change=(0 1 8 9)\n        is_info_show=(0 1 2 13 14)\n        is_info_str=($is_protocol $is_addr $port $door_addr $door_port)\n        ;;\n    socks)\n        is_can_change=(0 1 15 4)\n        is_info_show=(0 1 2 19 10)\n        is_info_str=($is_protocol $is_addr $port $is_socks_user $is_socks_pass)\n        is_url=\"socks://$(echo -n ${is_socks_user}:${is_socks_pass} | base64 -w 0)@${is_addr}:${port}#233boy-$net-${is_addr}\"\n        ;;\n    http)\n        is_can_change=(0 1)\n        is_info_show=(0 1 2)\n        is_info_str=($is_protocol 127.0.0.1 $port)\n        ;;\n    esac\n    [[ $is_dont_show_info || $is_gen || $is_dont_auto_exit ]] && return # dont show info\n    msg \"-------------- $is_config_name -------------\"\n    for ((i = 0; i < ${#is_info_show[@]}; i++)); do\n        a=${info_list[${is_info_show[$i]}]}\n        if [[ ${#a} -eq 11 || ${#a} -ge 13 ]]; then\n            tt='\\t'\n        else\n            tt='\\t\\t'\n        fi\n        msg \"$a $tt= \\e[${is_color}m${is_info_str[$i]}\\e[0m\"\n    done\n    if [[ $is_new_install ]]; then\n        warn \"首次安装请查看脚本帮助文档: $(msg_ul https://233boy.com/$is_core/$is_core-script/)\"\n    fi\n    if [[ $is_url ]]; then\n        msg \"------------- ${info_list[12]} -------------\"\n        msg \"\\e[4;${is_color}m${is_url}\\e[0m\"\n    fi\n    if [[ $is_no_auto_tls ]]; then\n        is_tmp_path=$path\n        [[ $net == 'grpc' ]] && is_tmp_path=\"/$path/*\"\n        msg \"------------- no-auto-tls INFO -------------\"\n        msg \"端口(port): $port\"\n        msg \"路径(path): $is_tmp_path\"\n        msg \"\\e[41m帮助(help)\\e[0m: $(msg_ul https://233boy.com/$is_core/no-auto-tls/)\"\n    fi\n    footer_msg\n}\n\n# footer msg\nfooter_msg() {\n    [[ $is_core_stop && ! $is_new_json ]] && warn \"$is_core_name 当前处于停止状态.\"\n    [[ $is_caddy_stop && $host ]] && warn \"Caddy 当前处于停止状态.\"\n    ####### 要点13脸吗只会改我链接的小人 #######\n    unset c n m s b\n    msg \"------------- END -------------\"\n    msg \"关注(tg): $(msg_ul https://t.me/tg2333)\"\n    msg \"文档(doc): $(msg_ul https://233boy.com/$is_core/$is_core-script/)\"\n    msg \"推广(ads): 机场推荐($is_core_name services): $(msg_ul https://g${c}e${n}t${m}j${s}m${b}s.com/)\\n\"\n    ####### 要点13脸吗只会改我链接的小人 #######\n}\n\n# URL or qrcode\nurl_qr() {\n    is_dont_show_info=1\n    info $2\n    if [[ $is_url ]]; then\n        [[ $1 == 'url' ]] && {\n            msg \"\\n------------- $is_config_name & URL 链接 -------------\"\n            msg \"\\n\\e[${is_color}m${is_url}\\e[0m\\n\"\n            footer_msg\n        } || {\n            link=\"https://233boy.github.io/tools/qr.html#${is_url}\"\n            msg \"\\n------------- $is_config_name & QR code 二维码 -------------\"\n            msg\n            if [[ $(type -P qrencode) ]]; then\n                qrencode -t ANSI \"${is_url}\"\n            else\n                msg \"请安装 qrencode: $(_green \"$cmd update -y; $cmd install qrencode -y\")\"\n            fi\n            msg\n            msg \"如果无法正常显示或识别, 请使用下面的链接来生成二维码:\"\n            msg \"\\n\\e[4;${is_color}m${link}\\e[0m\\n\"\n            footer_msg\n        }\n    else\n        [[ $1 == 'url' ]] && {\n            err \"($is_config_name) 无法生成 URL 链接.\"\n        } || {\n            err \"($is_config_name) 无法生成 QR code 二维码.\"\n        }\n    fi\n}\n\n# update core, sh, caddy\nupdate() {\n    case $1 in\n    1 | core | $is_core)\n        is_update_name=core\n        is_show_name=$is_core_name\n        is_run_ver=v${is_core_ver##* }\n        is_update_repo=$is_core_repo\n        ;;\n    2 | sh)\n        is_update_name=sh\n        is_show_name=\"$is_core_name 脚本\"\n        is_run_ver=$is_sh_ver\n        is_update_repo=$is_sh_repo\n        ;;\n    3 | caddy)\n        [[ ! $is_caddy ]] && err \"不支持更新 Caddy.\"\n        is_update_name=caddy\n        is_show_name=\"Caddy\"\n        is_run_ver=$is_caddy_ver\n        is_update_repo=$is_caddy_repo\n        ;;\n    *)\n        err \"无法识别 ($1), 请使用: $is_core update [core | sh | caddy] [ver]\"\n        ;;\n    esac\n    [[ $2 ]] && is_new_ver=v${2#v}\n    [[ $is_run_ver == $is_new_ver ]] && {\n        msg \"\\n自定义版本和当前 $is_show_name 版本一样, 无需更新.\\n\"\n        exit\n    }\n    load download.sh\n    if [[ $is_new_ver ]]; then\n        msg \"\\n使用自定义版本更新 $is_show_name: $(_green $is_new_ver)\\n\"\n    else\n        get_latest_version $is_update_name\n        [[ $is_run_ver == $latest_ver ]] && {\n            msg \"\\n$is_show_name 当前已经是最新版本了.\\n\"\n            exit\n        }\n        msg \"\\n发现 $is_show_name 新版本: $(_green $latest_ver)\\n\"\n        is_new_ver=$latest_ver\n    fi\n    download $is_update_name $is_new_ver\n    msg \"更新成功, 当前 $is_show_name 版本: $(_green $is_new_ver)\\n\"\n    msg \"$(_green 请查看更新说明: https://github.com/$is_update_repo/releases/tag/$is_new_ver)\\n\"\n    [[ $is_update_name == 'core' ]] && $is_core restart\n    [[ $is_update_name == 'caddy' ]] && manage restart $is_update_name &\n}\n\n# main menu; if no prefer args.\nis_main_menu() {\n    msg \"\\n------------- $is_core_name script $is_sh_ver by $author -------------\"\n    msg \"$is_core_ver: $is_core_status\"\n    msg \"群组 (Chat): $(msg_ul https://t.me/tg233boy)\"\n    is_main_start=1\n    ask mainmenu\n    case $REPLY in\n    1)\n        add\n        ;;\n    2)\n        change\n        ;;\n    3)\n        info\n        ;;\n    4)\n        del\n        ;;\n    5)\n        ask list is_do_manage \"启动 停止 重启\"\n        manage $REPLY &\n        msg \"\\n管理状态执行: $(_green $is_do_manage)\\n\"\n        ;;\n    6)\n        is_tmp_list=(\"更新$is_core_name\" \"更新脚本\")\n        [[ $is_caddy ]] && is_tmp_list+=(\"更新Caddy\")\n        ask list is_do_update null \"\\n请选择更新:\\n\"\n        update $REPLY\n        ;;\n    7)\n        uninstall\n        ;;\n    8)\n        msg\n        load help.sh\n        show_help\n        ;;\n    9)\n        ask list is_do_other \"启用BBR 查看日志 查看错误日志 测试运行 重装脚本 设置DNS\"\n        case $REPLY in\n        1)\n            load bbr.sh\n            _try_enable_bbr\n            ;;\n        2)\n            get log\n            ;;\n        3)\n            get logerr\n            ;;\n        4)\n            get test-run\n            ;;\n        5)\n            get reinstall\n            ;;\n        6)\n            load dns.sh\n            dns_set\n            ;;\n        esac\n        ;;\n    10)\n        load help.sh\n        about\n        ;;\n    esac\n}\n\n# check prefer args, if not exist prefer args and show main menu\nmain() {\n    case $1 in\n    a | add | gen | no-auto-tls)\n        [[ $1 == 'gen' ]] && is_gen=1\n        [[ $1 == 'no-auto-tls' ]] && is_no_auto_tls=1\n        add ${@:2}\n        ;;\n    api | bin | convert | tls | run | uuid)\n        [[ $is_core_ver_lt_5 ]] && {\n            warn \"$is_core_ver 版本不支持使用命令. 请升级内核版本: $is_core update core\"\n            return\n        }\n        is_run_command=$1\n        if [[ $1 == 'bin' ]]; then\n            $is_core_bin ${@:2}\n        else\n            # [[ $is_run_command == 'pbk' ]] && is_run_command=x25519\n            $is_core_bin $is_run_command ${@:2}\n        fi\n        ;;\n    bbr)\n        load bbr.sh\n        _try_enable_bbr\n        ;;\n    c | config | change)\n        change ${@:2}\n        ;;\n    client | genc)\n        [[ $1 == 'client' ]] && is_full_client=1\n        create client $2\n        ;;\n    d | del | rm)\n        del $2\n        ;;\n    dd | ddel | fix | fix-all)\n        case $1 in\n        fix)\n            [[ $2 ]] && {\n                change $2 full\n            } || {\n                is_change_id=full && change\n            }\n            return\n            ;;\n        fix-all)\n            is_dont_auto_exit=1\n            msg\n            for v in $(ls $is_conf_dir | grep .json$ | sed '/dynamic-port-.*-link/d'); do\n                msg \"fix: $v\"\n                change $v full\n            done\n            _green \"\\nfix 完成.\\n\"\n            ;;\n        *)\n            is_dont_auto_exit=1\n            [[ ! $2 ]] && {\n                err \"无法找到需要删除的参数\"\n            } || {\n                for v in ${@:2}; do\n                    del $v\n                done\n            }\n            ;;\n        esac\n        is_dont_auto_exit=\n        [[ $is_api_fail ]] && manage restart &\n        [[ $is_del_host ]] && manage restart caddy &\n        ;;\n    dns)\n        load dns.sh\n        dns_set ${@:2}\n        ;;\n    debug)\n        is_debug=1\n        get info $2\n        warn \"如果需要复制; 请把 *uuid, *password, *host, *key 的值改写, 以避免泄露.\"\n        ;;\n    fix-config.json)\n        create config.json\n        ;;\n    fix-caddyfile)\n        if [[ $is_caddy ]]; then\n            load caddy.sh\n            caddy_config new\n            manage restart caddy &\n            _green \"\\nfix 完成.\\n\"\n        else\n            err \"无法执行此操作\"\n        fi\n        ;;\n    i | info)\n        info $2\n        ;;\n    ip)\n        get_ip\n        msg $ip\n        ;;\n    log | logerr | errlog)\n        load log.sh\n        log_set $@\n        ;;\n    url | qr)\n        url_qr $@\n        ;;\n    un | uninstall)\n        uninstall\n        ;;\n    u | up | update | U | update.sh)\n        is_update_name=$2\n        is_update_ver=$3\n        [[ ! $is_update_name ]] && is_update_name=core\n        [[ $1 == 'U' || $1 == 'update.sh' ]] && {\n            is_update_name=sh\n            is_update_ver=\n        }\n        if [[ $2 == 'dat' ]]; then\n            load download.sh\n            download dat\n            msg \"$(_green 更新 geoip.dat geosite.dat 成功.)\\n\"\n            manage restart &\n        else\n            update $is_update_name $is_update_ver\n        fi\n        ;;\n    ssss | ss2022)\n        get $@\n        ;;\n    s | status)\n        msg \"\\n$is_core_ver: $is_core_status\\n\"\n        [[ $is_caddy ]] && msg \"Caddy $is_caddy_ver: $is_caddy_status\\n\"\n        ;;\n    start | stop | r | restart)\n        [[ $2 && $2 != 'caddy' ]] && err \"无法识别 ($2), 请使用: $is_core $1 [caddy]\"\n        manage $1 $2 &\n        ;;\n    t | test)\n        get test-run\n        ;;\n    reinstall)\n        get $1\n        ;;\n    get-port)\n        get_port\n        msg $tmp_port\n        ;;\n    main)\n        is_main_menu\n        ;;\n    v | ver | version)\n        [[ $is_caddy_ver ]] && is_caddy_ver=\"/ $(_blue Caddy $is_caddy_ver)\"\n        msg \"\\n$(_green $is_core_ver) / $(_cyan $is_core_name script $is_sh_ver) $is_caddy_ver\\n\"\n        ;;\n    xapi)\n        api ${@:2}\n        ;;\n    h | help | --help)\n        load help.sh\n        show_help ${@:2}\n        ;;\n    *)\n        is_try_change=1\n        change test $1\n        if [[ $is_change_id ]]; then\n            unset is_try_change\n            [[ $2 ]] && {\n                change $2 $1 ${@:3}\n            } || {\n                change\n            }\n        else\n            err \"无法识别 ($1), 获取帮助请使用: $is_core help\"\n        fi\n        ;;\n    esac\n}\n"
  },
  {
    "path": "src/dns.sh",
    "content": "is_dns_list=(\n    1.1.1.1\n    8.8.8.8\n    https://dns.google/dns-query\n    https://cloudflare-dns.com/dns-query\n    https://family.cloudflare-dns.com/dns-query\n    set\n    none\n)\ndns_set() {\n    if [[ $1 ]]; then\n        case ${1,,} in\n        11 | 1111)\n            is_dns_use=${is_dns_list[0]}\n            ;;\n        88 | 8888)\n            is_dns_use=${is_dns_list[1]}\n            ;;\n        gg | google)\n            is_dns_use=${is_dns_list[2]}\n            ;;\n        cf | cloudflare)\n            is_dns_use=${is_dns_list[3]}\n            ;;\n        nosex | family)\n            is_dns_use=${is_dns_list[4]}\n            ;;\n        set)\n            if [[ $2 ]]; then\n                is_dns_use=${2,,}\n            else\n                ask string is_dns_use \"请输入 DNS: \"\n            fi\n            ;;\n        none)\n            is_dns_use=none\n            ;;\n        *)\n            err \"无法识别 DNS 参数: $@\"\n            ;;\n        esac\n    else\n        is_tmp_list=(${is_dns_list[@]})\n        ask list is_dns_use null \"\\n请选择 DNS:\\n\"\n        if [[ $is_dns_use == \"set\" ]]; then\n            ask string is_dns_use \"请输入 DNS: \"\n        fi\n    fi\n    if [[ $is_dns_use == \"none\" ]]; then\n        cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json\n    else\n        cat <<<$(jq '.dns.servers=[\"'${is_dns_use/https/https+local}'\"]' $is_config_json) >$is_config_json\n    fi\n    manage restart &\n    msg \"\\n已更新 DNS 为: $(_green $is_dns_use)\\n\"\n}"
  },
  {
    "path": "src/download.sh",
    "content": "get_latest_version() {\n    case $1 in\n    core)\n        name=$is_core_name\n        url=\"https://api.github.com/repos/${is_core_repo}/releases/latest?v=$RANDOM\"\n        ;;\n    sh)\n        name=\"$is_core_name 脚本\"\n        url=\"https://api.github.com/repos/$is_sh_repo/releases/latest?v=$RANDOM\"\n        ;;\n    caddy)\n        name=\"Caddy\"\n        url=\"https://api.github.com/repos/$is_caddy_repo/releases/latest?v=$RANDOM\"\n        ;;\n    esac\n    latest_ver=$(_wget -qO- $url | grep tag_name | grep -E -o 'v([0-9.]+)')\n    [[ ! $latest_ver ]] && {\n        err \"获取 ${name} 最新版本失败.\"\n    }\n    unset name url\n}\ndownload() {\n    latest_ver=$2\n    [[ ! $latest_ver && $1 != 'dat' ]] && get_latest_version $1\n    # tmp dir\n    tmpdir=$(mktemp -u)\n    [[ ! $tmpdir ]] && {\n        tmpdir=/tmp/tmp-$RANDOM\n    }\n    mkdir -p $tmpdir\n    case $1 in\n    core)\n        name=$is_core_name\n        tmpfile=$tmpdir/$is_core.zip\n        link=\"https://github.com/${is_core_repo}/releases/download/${latest_ver}/${is_core}-linux-${is_core_arch}.zip\"\n        download_file\n        unzip -qo $tmpfile -d $is_core_dir/bin\n        chmod +x $is_core_bin\n        ;;\n    sh)\n        name=\"$is_core_name 脚本\"\n        tmpfile=$tmpdir/sh.zip\n        link=\"https://github.com/${is_sh_repo}/releases/download/${latest_ver}/code.zip\"\n        download_file\n        unzip -qo $tmpfile -d $is_sh_dir\n        chmod +x $is_sh_bin\n        ;;\n    dat)\n        name=\"geoip.dat\"\n        tmpfile=$tmpdir/geoip.dat\n        link=\"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat\"\n        download_file\n        name=\"geosite.dat\"\n        tmpfile=$tmpdir/geosite.dat\n        link=\"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat\"\n        download_file\n        cp -f $tmpdir/*.dat $is_core_dir/bin/\n        ;;\n    caddy)\n        name=\"Caddy\"\n        tmpfile=$tmpdir/caddy.tar.gz\n        # https://github.com/caddyserver/caddy/releases/download/v2.6.4/caddy_2.6.4_linux_amd64.tar.gz\n        link=\"https://github.com/${is_caddy_repo}/releases/download/${latest_ver}/caddy_${latest_ver:1}_linux_${caddy_arch}.tar.gz\"\n        download_file\n        [[ ! $(type -P tar) ]] && {\n            rm -rf $tmpdir\n            err \"请安装 tar\"\n        }\n        tar zxf $tmpfile -C $tmpdir\n        cp -f $tmpdir/caddy $is_caddy_bin\n        chmod +x $is_caddy_bin\n        ;;\n    esac\n    rm -rf $tmpdir\n    unset latest_ver\n}\ndownload_file() {\n    if ! _wget -t 5 -c $link -O $tmpfile; then\n        rm -rf $tmpdir\n        err \"\\n下载 ${name} 失败.\\n\"\n    fi\n}\n"
  },
  {
    "path": "src/help.sh",
    "content": "show_help() {\n    case $1 in\n    api | convert | tls | run | uuid | version)\n        $is_core_bin help $1 ${@:2}\n        ;;\n    *)\n        [[ $1 ]] && warn \"未知选项 '$1'\"\n        msg \"$is_core_name script $is_sh_ver by $author\"\n        msg \"Usage: $is_core [options]... [args]... \"\n        msg\n        help_info=(\n            \"基本:\"\n            \"   v, version                                      显示当前版本\"\n            \"   ip                                              返回当前主机的 IP\"\n            # \"   pbk                                             同等于 $is_core x25519\"\n            \"   get-port                                        返回一个可用的端口\\n\"\n            # \"   ss2022                                          返回一个可用于 Shadowsocks 2022 的密码\\n\"\n            \"一般:\"\n            \"   a, add [protocol] [args... | auto]              添加配置\"\n            \"   c, change [name] [option] [args... | auto]      更改配置\"\n            \"   d, del [name]                                   删除配置**\"\n            \"   i, info [name]                                  查看配置\"\n            \"   qr [name]                                       二维码信息\"\n            \"   url [name]                                      URL 信息\"\n            \"   log                                             查看日志\"\n            \"   logerr                                          查看错误日志\\n\"\n            \"更改:\"\n            \"   dp, dynamicport [name] [start | auto] [end]     更改动态端口\"\n            \"   full [name] [...]                               更改多个参数\"\n            \"   id [name] [uuid | auto]                         更改 UUID\"\n            \"   host [name] [domain]                            更改域名\"\n            \"   port [name] [port | auto]                       更改端口\"\n            \"   path [name] [path | auto]                       更改路径\"\n            \"   passwd [name] [password | auto]                 更改密码\"\n            # \"   key [name] [Private key | atuo] [Public key]    更改密钥\"\n            \"   type [name] [type | auto]                       更改伪装类型\"\n            \"   method [name] [method | auto]                   更改加密方式\"\n            # \"   sni [name] [ ip | domain]                       更改 serverName\"\n            \"   seed [name] [seed | auto]                       更改 mKCP seed\"\n            \"   new [name] [...]                                更改协议\"\n            \"   web [name] [domain]                             更改伪装网站\\n\"\n            \"进阶:\"\n            \"   dns [...]                                       设置 DNS\"\n            \"   dd, ddel [name...]                              删除多个配置**\"\n            \"   fix [name]                                      修复一个配置\"\n            \"   fix-all                                         修复全部配置\"\n            \"   fix-caddyfile                                   修复 Caddyfile\"\n            \"   fix-config.json                                 修复 config.json\\n\"\n            \"管理:\"\n            \"   un, uninstall                                   卸载\"\n            \"   u, update [core | sh | dat | caddy] [ver]       更新\"\n            \"   U, update.sh                                    更新脚本\"\n            \"   s, status                                       运行状态\"\n            \"   start, stop, restart [caddy]                    启动, 停止, 重启\"\n            \"   t, test                                         测试运行\"\n            \"   reinstall                                       重装脚本\\n\"\n            \"测试:\"\n            \"   client [name]                                   显示用于客户端 JSON, 仅供参考\"\n            \"   debug [name]                                    显示一些 debug 信息, 仅供参考\"\n            \"   gen [...]                                       同等于 add, 但只显示 JSON 内容, 不创建文件, 测试使用\"\n            \"   genc [name]                                     显示用于客户端部分 JSON, 仅供参考\"\n            \"   no-auto-tls [...]                               同等于 add, 但禁止自动配置 TLS, 可用于 *TLS 相关协议\"\n            \"   xapi [...]                                      同等于 $is_core api, 但 API 后端使用当前运行的 $is_core_name 服务\\n\"\n            \"其他:\"\n            \"   bbr                                             启用 BBR, 如果支持\"\n            \"   bin [...]                                       运行 $is_core_name 命令, 例如: $is_core bin help\"\n            \"   api, convert, tls, run, uuid  [...]             兼容 $is_core_name 命令\"\n            \"   h, help                                         显示此帮助界面\\n\"\n        )\n        for v in \"${help_info[@]}\"; do\n            msg \"$v\"\n        done\n        msg \"谨慎使用 del, ddel, 此选项会直接删除配置; 无需确认\"\n        msg \"反馈问题) $(msg_ul https://github.com/${is_sh_repo}/issues) \"\n        msg \"文档(doc) $(msg_ul https://233boy.com/$is_core/$is_core-script/)\"\n        ;;\n\n    esac\n}\n\nabout() {\n    ####### 要点13脸吗只会改我链接的小人 #######\n    unset c n m s b\n    msg\n    msg \"网站: $(msg_ul https://233boy.com)\"\n    msg \"频道: $(msg_ul https://t.me/tg2333)\"\n    msg \"群组: $(msg_ul https://t.me/tg233boy)\"\n    msg \"Github: $(msg_ul https://github.com/${is_sh_repo})\"\n    msg \"Twitter: $(msg_ul https://twitter.com/ai233boy)\"\n    msg \"$is_core_name site: $(msg_ul https://www.v2fly.org)\"\n    msg \"$is_core_name core: $(msg_ul https://github.com/${is_core_repo})\"\n    msg\n    ####### 要点13脸吗只会改我链接的小人 #######\n}\n"
  },
  {
    "path": "src/init.sh",
    "content": "#!/bin/bash\n\nauthor=233boy\n# github=https://github.com/233boy/v2ray\n\n# bash fonts colors\nred='\\e[31m'\nyellow='\\e[33m'\ngray='\\e[90m'\ngreen='\\e[92m'\nblue='\\e[94m'\nmagenta='\\e[95m'\ncyan='\\e[96m'\nnone='\\e[0m'\n\n_red() { echo -e ${red}$@${none}; }\n_blue() { echo -e ${blue}$@${none}; }\n_cyan() { echo -e ${cyan}$@${none}; }\n_green() { echo -e ${green}$@${none}; }\n_yellow() { echo -e ${yellow}$@${none}; }\n_magenta() { echo -e ${magenta}$@${none}; }\n_red_bg() { echo -e \"\\e[41m$@${none}\"; }\n\n_rm() {\n    rm -rf \"$@\"\n}\n_cp() {\n    cp -rf \"$@\"\n}\n_sed() {\n    sed -i \"$@\"\n}\n_mkdir() {\n    mkdir -p \"$@\"\n}\n\nis_err=$(_red_bg 错误!)\nis_warn=$(_red_bg 警告!)\n\nerr() {\n    echo -e \"\\n$is_err $@\\n\"\n    [[ $is_dont_auto_exit ]] && return\n    exit 1\n}\n\nwarn() {\n    echo -e \"\\n$is_warn $@\\n\"\n}\n\n# load bash script.\nload() {\n    . $is_sh_dir/src/$1\n}\n\n# wget add --no-check-certificate\n_wget() {\n    # [[ $proxy ]] && export https_proxy=$proxy\n    wget --no-check-certificate \"$@\"\n}\n\n# yum or apt-get\ncmd=$(type -P apt-get || type -P yum)\n\n# x64\ncase $(arch) in\namd64 | x86_64)\n    is_core_arch=\"64\"\n    caddy_arch=\"amd64\"\n    ;;\n*aarch64* | *armv8*)\n    is_core_arch=\"arm64-v8a\"\n    caddy_arch=\"arm64\"\n    ;;\n*)\n    err \"此脚本仅支持 64 位系统...\"\n    ;;\nesac\n\nis_core=v2ray\nis_core_name=V2Ray\nis_core_dir=/etc/$is_core\nis_core_bin=$is_core_dir/bin/$is_core\nis_core_repo=v2fly/$is_core-core\nis_conf_dir=$is_core_dir/conf\nis_log_dir=/var/log/$is_core\nis_sh_bin=/usr/local/bin/$is_core\nis_sh_dir=$is_core_dir/sh\nis_sh_repo=$author/$is_core\nis_pkg=\"wget unzip jq qrencode\"\nis_config_json=$is_core_dir/config.json\nis_caddy_bin=/usr/local/bin/caddy\nis_caddy_dir=/etc/caddy\nis_caddy_repo=caddyserver/caddy\nis_caddyfile=$is_caddy_dir/Caddyfile\nis_caddy_conf=$is_caddy_dir/$author\nis_caddy_service=$(systemctl list-units --full -all | grep caddy.service)\nis_http_port=80\nis_https_port=443\n\n# core ver\nis_core_ver=$($is_core_bin version | head -n1 | cut -d \" \" -f1-2)\n\nif [[ $(grep -o ^[0-9] <<<${is_core_ver#* }) -lt 5 ]]; then\n    # core version less than 5, e.g, v4.45.2\n    is_core_ver_lt_5=1\n    if [[ $(grep 'run -config' /lib/systemd/system/v2ray.service) ]]; then\n        sed -i 's/run //' /lib/systemd/system/v2ray.service\n        systemctl daemon-reload\n    fi\nelse\n    is_with_run_arg=run\n    if [[ ! $(grep 'run -config' /lib/systemd/system/v2ray.service) ]]; then\n        sed -i 's/-config/run -config/' /lib/systemd/system/v2ray.service\n        systemctl daemon-reload\n    fi\nfi\n\nif [[ $(pgrep -f $is_core_bin) ]]; then\n    is_core_status=$(_green running)\nelse\n    is_core_status=$(_red_bg stopped)\n    is_core_stop=1\nfi\nif [[ -f $is_caddy_bin && -d $is_caddy_dir && $is_caddy_service ]]; then\n    is_caddy=1\n    # fix caddy run; ver >= 2.8.2\n    [[ ! $(grep '\\-\\-adapter caddyfile' /lib/systemd/system/caddy.service) ]] && {\n        load systemd.sh\n        install_service caddy\n        systemctl restart caddy &\n    }\n    is_caddy_ver=$($is_caddy_bin version | head -n1 | cut -d \" \" -f1)\n    is_tmp_http_port=$(grep -E '^ {2,}http_port|^http_port' $is_caddyfile | grep -E -o [0-9]+)\n    is_tmp_https_port=$(grep -E '^ {2,}https_port|^https_port' $is_caddyfile | grep -E -o [0-9]+)\n    [[ $is_tmp_http_port ]] && is_http_port=$is_tmp_http_port\n    [[ $is_tmp_https_port ]] && is_https_port=$is_tmp_https_port\n    if [[ $(pgrep -f $is_caddy_bin) ]]; then\n        is_caddy_status=$(_green running)\n    else\n        is_caddy_status=$(_red_bg stopped)\n        is_caddy_stop=1\n    fi\nfi\n\nload core.sh\n# old sh ver\nis_old_dir=/etc/v2ray/233boy\nis_old_conf=/etc/v2ray/233blog_v2ray_backup.conf\nif [[ -f $is_old_conf && -d $is_old_dir ]]; then\n    load old.sh\nfi\n[[ ! $args ]] && args=main\nmain $args\n"
  },
  {
    "path": "src/log.sh",
    "content": "is_log_level_list=(\n    debug\n    info\n    warning\n    error\n    none\n    del\n)\nlog_set() {\n    if [[ $2 ]]; then\n        for v in ${is_log_level_list[@]}; do\n            [[ $(grep -E -i \"^${2,,}$\" <<<$v) ]] && is_log_level_use=$v && break\n        done\n        [[ ! $is_log_level_use ]] && {\n            err \"无法识别 log 参数: $@ \\n请使用 $is_core log [${is_log_level_list[@]}] 进行相关设定.\\n备注: del 参数仅临时删除 log 文件; none 参数将不会生成 log 文件.\"\n        }\n        case $is_log_level_use in\n        del)\n            rm -rf $is_log_dir/*.log\n            msg \"\\n $(_green 已临时删除 log 文件, 如果你想要完全禁止生成 log 文件请使用: $is_core log none)\\n\"\n            ;;\n        none)\n            rm -rf $is_log_dir/*.log\n            cat <<<$(jq '.log={\"loglevel\":\"none\"}' $is_config_json) >$is_config_json\n            ;;\n        *)\n            cat <<<$(jq '.log={access:\"/var/log/'$is_core'/access.log\",error:\"/var/log/'$is_core'/error.log\",loglevel:\"'$is_log_level_use'\"}' $is_config_json) >$is_config_json\n            ;;\n        esac\n\n        manage restart &\n        [[ $2 != 'del' ]] && msg \"\\n已更新 Log 设定为: $(_green $is_log_level_use)\\n\"\n    else\n        case $1 in\n        log)\n            if [[ -f $is_log_dir/access.log ]]; then\n                msg \"\\n 提醒: 按 $(_green Ctrl + C) 退出\\n\"\n                tail -f $is_log_dir/access.log\n            else\n                err \"无法找到 log 文件.\"\n            fi\n            ;;\n        *)\n            if [[ -f $is_log_dir/error.log ]]; then\n                msg \"\\n 提醒: 按 $(_green Ctrl + C) 退出\\n\"\n                tail -f $is_log_dir/error.log\n            else\n                err \"无法找到 log 文件.\"\n            fi\n            ;;\n        esac\n\n    fi\n}"
  },
  {
    "path": "src/old.sh",
    "content": "is_old_list=(\n\tTCP\n\tTCP_HTTP\n\tWebSocket\n\t\"WebSocket + TLS\"\n\tHTTP/2\n\tmKCP\n\tmKCP_utp\n\tmKCP_srtp\n\tmKCP_wechat-video\n\tmKCP_dtls\n\tmKCP_wireguard\n\tQUIC\n\tQUIC_utp\n\tQUIC_srtp\n\tQUIC_wechat-video\n\tQUIC_dtls\n\tQUIC_wireguard\n\tTCP_dynamicPort\n\tTCP_HTTP_dynamicPort\n\tWebSocket_dynamicPort\n\tmKCP_dynamicPort\n\tmKCP_utp_dynamicPort\n\tmKCP_srtp_dynamicPort\n\tmKCP_wechat-video_dynamicPort\n\tmKCP_dtls_dynamicPort\n\tmKCP_wireguard_dynamicPort\n\tQUIC_dynamicPort\n\tQUIC_utp_dynamicPort\n\tQUIC_srtp_dynamicPort\n\tQUIC_wechat-video_dynamicPort\n\tQUIC_dtls_dynamicPort\n\tQUIC_wireguard_dynamicPort\n\tVLESS_WebSocket_TLS\n)\n\n# del old file\ndel_old_file() {\n\t# old sh bin\n\t_v2ray_sh=\"/usr/local/sbin/v2ray\"\n\trm -rf $_v2ray_sh $is_old_conf $is_old_dir $is_core_dir/233blog_v2ray_config.json /usr/bin/v2ray\n\t# del alias\n\tsed -i \"#$_v2ray_sh#d\" /root/.bashrc\n\texit\n}\n\n# read old config\n. $is_old_conf\nis_old=${is_old_list[$v2ray_transport - 1]}\ncase $v2ray_transport in\n3 | 20)\n\tis_old_use=\n\t;;\n4)\n\tis_old_use=ws\n\t;;\n5)\n\tis_old_use=h2\n\t;;\n33)\n\tis_old_use=vws\n\t;;\n*)\n\tis_test_old_use=($(sed 's/_dynamicPort//;s/_/ /' <<<$is_old))\n\tis_old_use=${is_test_old_use[0]#m}\n\tis_old_header_type=${is_test_old_use[1]}\n\t[[ ! $is_old_header_type ]] && is_old_header_type=none\n\t;;\nesac\n\nif [[ $is_old_use && ! $is_old_header_type ]]; then\n\t# not use caddy auto tls\n\t[[ ! $caddy ]] && is_old_use=\nfi\n\n# add old config\nif [[ $is_old_use ]]; then\n\tis_tmp_list=(\"删除旧配置\" \"恢复: $is_old\")\n\n\task list is_do_upgrade null \"\\n是否恢复旧配置:\\n\"\n\n\t[[ $REPLY == '1' ]] && {\n\t\t_green \"\\n删除完成!\\n\"\n\t\tdel_old_file\n\t}\n\n\t_green \"\\n开始恢复...\\n\"\n\n\t# upgrade caddy\n\tif [[ $caddy ]]; then\n\t\tget install-caddy\n\t\t# bak caddy files\n\t\tmv -f $is_caddyfile $is_caddyfile.233.bak\n\t\tmv -f $is_caddy_dir/sites $is_caddy_dir/sites.233.bak\n\t\tload caddy.sh\n\t\tcaddy_config new\n\tfi\n\tis_change=1\n\tis_dont_auto_exit=1\n\tis_dont_show_info=1\n\tif [[ $shadowsocks ]]; then\n\t\tfor v in ${ss_method_list[@]}; do\n\t\t\t[[ $(grep -E -i \"^${ssciphers}$\" <<<$v) ]] && ss_method=$v && break\n\t\tdone\n\t\tif [[ $ss_method ]]; then\n\t\t\tadd ss $ssport $sspass $ss_method\n\t\tfi\n\tfi\n\tif [[ $socks ]]; then\n\t\tadd socks $socks_port $socks_username $socks_userpass\n\tfi\n\tport=$v2ray_port\n\tuuid=$v2ray_id\n\tis_no_kcp_seed=1\n\theader_type=$is_old_header_type\n\t[[ $caddy ]] && host=$domain\n\tpath=/$path\n\t[[ ! $path_status ]] && path=\n\tif [[ $(grep dynamic <<<$is_old) ]]; then\n\t\tis_dynamic_port=1\n\t\tis_dynamic_port_range=\"$v2ray_dynamicPort_start-$v2ray_dynamicPort_end\"\n\t\tadd ${is_old_use}d\n\telse\n\t\tadd $is_old_use\n\tfi\n\n\tif [[ $path_status ]]; then\n\t\tchange $is_config_name web $proxy_site\n\tfi\n\tis_dont_auto_exit=\n\tis_dont_show_info=\n\t[[ $is_api_fail ]] && manage restart &\n\t[[ $caddy ]] && manage restart caddy\n\tinfo $is_config_name\nelse\n\task string y \"是否删除旧配置? [y]:\"\n\t_green \"\\n删除完成!\\n\"\nfi\n\ndel_old_file"
  },
  {
    "path": "src/systemd.sh",
    "content": "install_service() {\n    case $1 in\n    xray | v2ray)\n        is_doc_site=https://xtls.github.io/\n        [[ $1 == 'v2ray' ]] && is_doc_site=https://www.v2fly.org/\n        cat >/lib/systemd/system/$is_core.service <<<\"\n[Unit]\nDescription=$is_core_name Service\nDocumentation=$is_doc_site\nAfter=network.target nss-lookup.target\n\n[Service]\n#User=nobody\nUser=root\nNoNewPrivileges=true\nExecStart=$is_core_bin run -config $is_config_json -confdir $is_conf_dir\nRestart=on-failure\nRestartPreventExitStatus=23\nLimitNPROC=10000\nLimitNOFILE=1048576\nPrivateTmp=true\nProtectSystem=full\n#CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE\n#AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE\n\n[Install]\nWantedBy=multi-user.target\"\n        ;;\n    caddy)\n        cat >/lib/systemd/system/caddy.service <<<\"\n#https://github.com/caddyserver/dist/blob/master/init/caddy.service\n[Unit]\nDescription=Caddy\nDocumentation=https://caddyserver.com/docs/\nAfter=network.target network-online.target\nRequires=network-online.target\n\n[Service]\nType=notify\nUser=root\nGroup=root\nExecStart=$is_caddy_bin run --environ --config $is_caddyfile --adapter caddyfile\nExecReload=$is_caddy_bin reload --config $is_caddyfile --adapter caddyfile\nTimeoutStopSec=5s\nLimitNPROC=10000\nLimitNOFILE=1048576\nPrivateTmp=true\nProtectSystem=full\n#AmbientCapabilities=CAP_NET_BIND_SERVICE\n\n[Install]\nWantedBy=multi-user.target\"\n        ;;\n    esac\n\n    # enable, reload\n    systemctl enable $1\n    systemctl daemon-reload\n}\n"
  },
  {
    "path": "v2ray.sh",
    "content": "#!/bin/bash\n\nargs=$@\nis_sh_ver=v4.27\n\n. /etc/v2ray/sh/src/init.sh\n"
  }
]