diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..516f5da8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# Default severity for all analyzer diagnostics +dotnet_analyzer_diagnostic.severity = none diff --git a/.gitignore b/.gitignore index 2397d072..3739cc60 100644 --- a/.gitignore +++ b/.gitignore @@ -198,3 +198,5 @@ FakesAssemblies/ # vs code .vscode/* +/ProxySU_Core/Data/Record.json +/ProxySuper.WPF/bin diff --git a/.idea/.idea.ProxySU/.idea/codeStyles/codeStyleConfig.xml b/.idea/.idea.ProxySU/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..7ad1bf11 --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/contentModel.xml b/.idea/.idea.ProxySU/.idea/contentModel.xml new file mode 100644 index 00000000..0f66ecb4 --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/contentModel.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/encodings.xml b/.idea/.idea.ProxySU/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/indexLayout.xml b/.idea/.idea.ProxySU/.idea/indexLayout.xml new file mode 100644 index 00000000..27ba142e --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/modules.xml b/.idea/.idea.ProxySU/.idea/modules.xml new file mode 100644 index 00000000..a7c012bc --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/projectSettingsUpdater.xml b/.idea/.idea.ProxySU/.idea/projectSettingsUpdater.xml new file mode 100644 index 00000000..4bb9f4d2 --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/projectSettingsUpdater.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/vcs.xml b/.idea/.idea.ProxySU/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/.idea/workspace.xml b/.idea/.idea.ProxySU/.idea/workspace.xml new file mode 100644 index 00000000..cfb386b7 --- /dev/null +++ b/.idea/.idea.ProxySU/.idea/workspace.xml @@ -0,0 +1,121 @@ + + + + ProxySU/ProxySU.csproj + WpfApp1/WpfApp1.csproj + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1607572158648 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.ProxySU/riderModule.iml b/.idea/.idea.ProxySU/riderModule.iml new file mode 100644 index 00000000..1a4e0d95 --- /dev/null +++ b/.idea/.idea.ProxySU/riderModule.iml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/7z/7z.exe b/7z/7z.exe deleted file mode 100644 index 3a8ee478..00000000 Binary files a/7z/7z.exe and /dev/null differ diff --git a/7z/readme.md b/7z/readme.md deleted file mode 100644 index 892f5001..00000000 --- a/7z/readme.md +++ /dev/null @@ -1 +0,0 @@ -这个7z.exe文件,只是为了生成Release.zip方便。可有可无。ProxySU并不调用。 \ No newline at end of file diff --git a/FodyWeavers.xml b/FodyWeavers.xml new file mode 100644 index 00000000..5c3cf8c5 --- /dev/null +++ b/FodyWeavers.xml @@ -0,0 +1,4 @@ + + + + diff --git a/LICENSE b/LICENSE index f288702d..a535319b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,21 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +MIT License + +Copyright (c) 2025 ProxySU + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ProxySU.sln b/ProxySU.sln index 89f5ff94..a38b7001 100644 --- a/ProxySU.sln +++ b/ProxySU.sln @@ -1,9 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.1022 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31606.5 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxySU", "ProxySU\ProxySU.csproj", "{DD5505BC-E7F1-4D03-ABC7-B636E893FC09}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libs", "Libs", "{CE908112-DB46-4B91-8236-9139A19D66E9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxySuper.WPF", "ProxySuper.WPF\ProxySuper.WPF.csproj", "{B083EBFD-2925-46C9-8B00-E2C1300CEBA1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxySuper.Core", "ProxySuper.Core\ProxySuper.Core.csproj", "{15779EE6-D8CA-44BF-BFE2-941E155EEF3F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,14 +15,22 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DD5505BC-E7F1-4D03-ABC7-B636E893FC09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DD5505BC-E7F1-4D03-ABC7-B636E893FC09}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DD5505BC-E7F1-4D03-ABC7-B636E893FC09}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DD5505BC-E7F1-4D03-ABC7-B636E893FC09}.Release|Any CPU.Build.0 = Release|Any CPU + {B083EBFD-2925-46C9-8B00-E2C1300CEBA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B083EBFD-2925-46C9-8B00-E2C1300CEBA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B083EBFD-2925-46C9-8B00-E2C1300CEBA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B083EBFD-2925-46C9-8B00-E2C1300CEBA1}.Release|Any CPU.Build.0 = Release|Any CPU + {15779EE6-D8CA-44BF-BFE2-941E155EEF3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {15779EE6-D8CA-44BF-BFE2-941E155EEF3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {15779EE6-D8CA-44BF-BFE2-941E155EEF3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {15779EE6-D8CA-44BF-BFE2-941E155EEF3F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {B083EBFD-2925-46C9-8B00-E2C1300CEBA1} = {CE908112-DB46-4B91-8236-9139A19D66E9} + {15779EE6-D8CA-44BF-BFE2-941E155EEF3F} = {CE908112-DB46-4B91-8236-9139A19D66E9} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A3F3B8D6-7FED-42D9-9994-E913BD32E025} EndGlobalSection diff --git a/ProxySU/App.xaml b/ProxySU/App.xaml deleted file mode 100644 index 4a9db0e2..00000000 --- a/ProxySU/App.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - diff --git a/ProxySU/App.xaml.cs b/ProxySU/App.xaml.cs deleted file mode 100644 index 6ed51145..00000000 --- a/ProxySU/App.xaml.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Windows; - -namespace ProxySU -{ - /// - /// App.xaml 的交互逻辑 - /// - public partial class App : Application - { - } -} diff --git a/ProxySU/ClassModel.cs b/ProxySU/ClassModel.cs deleted file mode 100644 index 4bea9a7a..00000000 --- a/ProxySU/ClassModel.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; -using System.Net; -using System.ComponentModel; -using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Runtime; -using System.Globalization; -using Microsoft.Win32; -using System.Security; - -namespace ProxySU -{ - class ClassModel - { - //检测域名是否为空 - public static bool TestDomainIsEmpty(string domainStr) - { - domainStr = domainStr.Trim(); - if (string.IsNullOrEmpty(domainStr) == true) - { - //****** "域名不能为空,请检查相关参数设置!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - return false; - } - else - { - return true; - } - } - //伪装网站预处理 - public static bool PreDomainMask(string uri) - { - uri = uri.Trim(); - if (String.IsNullOrEmpty(uri) == false) - { - if (uri.Contains("/") == true) - { - //MessageBox.Show("伪装网址输入格式错误!请重新输入!"); - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_MaskSitesToolTip").ToString()); - return false; - } - } - return true; - } - //伪装网址的处理 - public static string DisguiseURLprocessing(string fakeUrl) - { - fakeUrl = fakeUrl.Trim(); - return fakeUrl; - //处理伪装网站域名中的前缀 - //if (fakeUrl.Length >= 7) - //{ - // string testDomainMask = fakeUrl.Substring(0, 7); - // if (String.Equals(testDomainMask, "https:/") || String.Equals(testDomainMask, "http://")) - // { - // var uri = new Uri(fakeUrl); - // return uri.Host; - // } - - //} - - } - } -} diff --git a/ProxySU/MainWindow.xaml b/ProxySU/MainWindow.xaml deleted file mode 100644 index 22d98954..00000000 --- a/ProxySU/MainWindow.xaml +++ /dev/null @@ -1,842 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs deleted file mode 100644 index 52bd3778..00000000 --- a/ProxySU/MainWindow.xaml.cs +++ /dev/null @@ -1,10515 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; -using System.Net; -using System.ComponentModel; -using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Runtime; -using System.Globalization; -using Microsoft.Win32; -using System.Security; - -namespace ProxySU -{ - class NatDns64 - { - private string ipaddr { set; get; } //Dns64网关地址 - private int avg { set; get; } //ping的平均值 - - public NatDns64(string IpAddr, int Avg) - { - this.ipaddr = IpAddr; - this.avg = Avg; - } - - public string IpAddr - { - get { return ipaddr; } - set { this.ipaddr = IpAddr; } - } - - public int Avg - { - get { return avg; } - set { this.avg = Avg; } - } - } - /// - /// MainWindow.xaml 的交互逻辑 - /// - public partial class MainWindow : Window - { - //多语言参数 - public class LanguageInfo - { - public string Name { get; set; } - public string Value { get; set; } - } - public static string[] ReceiveConfigurationParameters { get; set; } - - //ReceiveConfigurationParameters[0]----模板类型 - //ReceiveConfigurationParameters[1]----服务端口 - //ReceiveConfigurationParameters[2]----V2Ray uuid/(naive/Trojan-go/Trojan/SSR/SS)' Password - //ReceiveConfigurationParameters[3]----QUIC加密方式/SSR 加密方法/SS 加密方式/naive'user/VLESS ws Path/trojan-go mux concurrency - //ReceiveConfigurationParameters[4]----Domain - //ReceiveConfigurationParameters[5]----伪装类型/插件名称/trojan-go mux idle_timeout - //ReceiveConfigurationParameters[6]----V2Ray&Trojan-go&SS--Websocket'Path/http2'Path/QUIC密钥/mKCP Seed/VMESS ws Path - //ReceiveConfigurationParameters[7]----伪装网站 - //ReceiveConfigurationParameters[8]----方案名称 - //ReceiveConfigurationParameters[9]----插件参数选项/VMESS tcp Path/MTProto Parameters/trojan-go是否启用Mux(true) - //public static ConnectionInfo ConnectionInfo; - - public static string proxyType = "V2Ray"; //代理类型标识: V2Ray\TrojanGo\Trojan\NaiveProxy - public static readonly string pwdir = AppDomain.CurrentDomain.BaseDirectory; //执行文件所在目录 - public static bool mKCPvlessIsSet = false; //mKCP是否使用VLESS协议 - static bool testDomain = false; //设置标识--域名是否需要检测解析,初始化为不需要 - static string ipv4 = String.Empty; //保存获取的ipv4地址 - static string ipv6 = String.Empty; //保存获取的ipv6地址 - static bool onlyIpv6 = false; //主机是否基于纯ipv6地址 - static bool functionResult = true; //标示功能函数是否执行状态(true无错误发生/false有错误发生) - static string sshShellCommand = String.Empty; //定义保存执行的命令 - static string currentStatus = String.Empty; //定议保存要显示的状态 - static string currentShellCommandResult = String.Empty; //定义Shell命令执行结果保存变量 - static bool getApt = false; //判断系统软件管理,下同 - static bool getDnf = false; - static bool getYum = false; - static string sshCmdUpdate = String.Empty; //保存软件安装所用更新软件库命令 - static string sshCmdInstall = String.Empty; //保存软件安装所用命令格式 - static int randomCaddyListenPort = 8800; //Caddy做伪装网站所监听的端口,随机10001-60000 - static int installationDegree = 0; //安装进度条显示的百分比 - static string saveShellScriptFileName = "install.sh"; //用来保存下载的脚本名称 - - //****** ****** - // Application.Current.FindResource("").ToString() - // - // {DynamicResource } - //SetUpProgressBarProcessing(0); - public MainWindow() - { - InitializeComponent(); - - #region 多语言选择设置 初始设置为auto - List languageList = new List(); - - languageList.Add(new LanguageInfo { Name = "auto", Value = "auto" }); - languageList.Add(new LanguageInfo { Name = "English", Value = "en-US" }); - languageList.Add(new LanguageInfo { Name = "简体中文", Value = "zh-CN" }); - languageList.Add(new LanguageInfo { Name = "正體中文", Value = "zh-TW" }); - - ComboBoxLanguage.ItemsSource = languageList; - - ComboBoxLanguage.DisplayMemberPath = "Name";//显示出来的值 - ComboBoxLanguage.SelectedValuePath = "Value";//实际选中后获取的结果的值 - ComboBoxLanguage.SelectedIndex = 0; - - DataContext = this; - string Culture = System.Globalization.CultureInfo.InstalledUICulture.Name; - //Culture = "en-US"; - ResourcesLoad(Culture); - #endregion - - //初始化参数设置数组 - ReceiveConfigurationParameters = new string[10]; - - //初始化选定密码登录 - RadioButtonPasswordLogin.IsChecked = true; - //初始化选定无代理 - RadioButtonNoProxy.IsChecked = true; - //初始化代理无需登录 - RadioButtonProxyNoLogin.IsChecked = true; - //初始化隐藏Socks4代理, - RadioButtonSocks4.Visibility = Visibility.Collapsed; - - //初始化Trojan的密码 - TextBoxTrojanPassword.Text = RandomUUID(); - - //初始化NaiveProxy的用户名和密码 - TextBoxNaivePassword.Text = RandomUUID(); - TextBoxNaiveUser.Text = RandomUserName(); - - //初始化SSR的密码 - TextBoxSSRPassword.Text = RandomUUID(); - - //初始化V2Ray所选方案面板为不显示 - GridV2rayCurrentlyPlan.Visibility = Visibility.Hidden; - - //初始化Xray所选方案面板为不显示 - GridXrayCurrentlyPlan.Visibility = Visibility.Hidden; - - //自动检查ProxySU是否有新版本发布,有则显示更新提示 - Thread thread = new Thread(() => TestLatestVersionProxySU(TextBlockLastVersionProxySU, TextBlockNewVersionReminder, ButtonUpgradeProxySU)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - #region 检测新版本代码 - - //检测ProxySU新版本 - private void TestLatestVersionProxySU(TextBlock TextBlockLastVersionProxySU, TextBlock TextBlockNewVersionReminder, Button ButtonUpgradeProxySU) - { - string strJson = GetLatestJson(@"https://api.github.com/repos/proxysu/windows/releases/latest"); - if (String.IsNullOrEmpty(strJson) == false) - { - JObject lastVerJsonObj = JObject.Parse(strJson); - string lastVersion = (string)lastVerJsonObj["tag_name"];//得到远程版本信息 - - string lastVersionNoV = lastVersion.Replace("v", String.Empty); - - Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; - //MessageBox.Show(version.ToString()); - string cerversion = version.ToString().Substring(0, 6); //获取本地版本信息 - //MessageBox.Show(cerversion); - string[] lastVerComp = lastVersionNoV.Split('.'); - string[] localVerComp = cerversion.Split('.'); - - //版本信息不相同,则认为新版本发布,显示出新版本信息及更新提醒,下载按钮 - if (int.Parse(lastVerComp[0]) > int.Parse(localVerComp[0])) - { - TextBlockLastVersionProxySU.Dispatcher.BeginInvoke(updateNewVersionProxySUAction, TextBlockLastVersionProxySU, TextBlockNewVersionReminder, ButtonUpgradeProxySU, lastVersion); - return; - } - else if (int.Parse(lastVerComp[0]) == int.Parse(localVerComp[0])) - { - if (int.Parse(lastVerComp[1]) > int.Parse(localVerComp[1])) - { - TextBlockLastVersionProxySU.Dispatcher.BeginInvoke(updateNewVersionProxySUAction, TextBlockLastVersionProxySU, TextBlockNewVersionReminder, ButtonUpgradeProxySU, lastVersion); - return; - } - else if (int.Parse(lastVerComp[1]) == int.Parse(localVerComp[1])) - { - if (int.Parse(lastVerComp[2]) > int.Parse(localVerComp[2])) - { - TextBlockLastVersionProxySU.Dispatcher.BeginInvoke(updateNewVersionProxySUAction, TextBlockLastVersionProxySU, TextBlockNewVersionReminder, ButtonUpgradeProxySU, lastVersion); - return; - } - } - } - } - } - - //下载最新版ProxySU - private void ButtonUpgradeProxySU_Click(object sender, RoutedEventArgs e) - { - TextBlockNewVersionReminder.Visibility = Visibility.Hidden; - TextBlockNewVersionDown.Visibility = Visibility.Visible; - //TextBlockNewVersionReminder.Text = Application.Current.FindResource("TextBlockNewVersionDown").ToString(); - try - { - string strJson = GetLatestJson(@"https://api.github.com/repos/proxysu/windows/releases/latest"); - if (String.IsNullOrEmpty(strJson) == false) - { - JObject lastVerJsonObj = JObject.Parse(strJson); - string lastVersion = (string)lastVerJsonObj["tag_name"];//得到远程版本信息 - string latestVerDownUrl = (string)lastVerJsonObj["assets"][0]["browser_download_url"];//得到最新版文件下载地址 - string latestNewVerFileName = (string)lastVerJsonObj["assets"][0]["name"];//得到最新版文件名 - string latestNewVerExplanation = (string)lastVerJsonObj["body"];//得到更新说明 - - WebClient webClientNewVer = new WebClient(); - webClientNewVer.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); - //webClientNewVer.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); - if (CheckDir(lastVersion)) - { - Uri latestVerDownUri = new Uri(latestVerDownUrl); - webClientNewVer.DownloadFileAsync(latestVerDownUri, lastVersion + @"\" + latestNewVerFileName); - //webClientNewVer.DownloadFile(latestVerDownUrl, latestNewVerFileName); - - using (StreamWriter sw = new StreamWriter(lastVersion + @"\" + "readme.txt")) - { - sw.WriteLine(latestNewVerExplanation); - } - } - } - } - catch (Exception ex1) - { - // MessageBox.Show(ex1.ToString()); - - return; - } - } - //文件下载完处理方法 - private void Completed(object sender, AsyncCompletedEventArgs e) - { - if (e.Cancelled == true) - { - MessageBox.Show(e.Error.ToString()); - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorDownProxyFail").ToString()); - //label1.Text = "Download cancelled!"; - } - else - { - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorDownProxySuccess").ToString()); - } - } - - //获取LatestJson - private string GetLatestJson(string theLatestUrl) - { - try - { - //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)768 | SecurityProtocolType.Tls; - ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; - // ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00 | 0x30); - //string url = "https://api.github.com/repos/proxysu/windows/releases/latest"; - Uri uri = new Uri(theLatestUrl); - HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); - req.Accept = @"application/json"; - req.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0"; - HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); - Stream stream = resp.GetResponseStream(); - StreamReader sr = new StreamReader(stream); - string strJson = sr.ReadToEnd(); - return strJson; - } - catch (Exception ex1) - { - return null; - } - } - - - //更新新版本提醒显示 - Action updateNewVersionProxySUAction = new Action(UpdateNewVersionProxySU); - private static void UpdateNewVersionProxySU(TextBlock TextBlockLastVersionProxySU, TextBlock TextBlockNewVersionReminder, Button ButtonUpgradeProxySU, string theLatestVersion) - { - TextBlockLastVersionProxySU.Text = theLatestVersion; - TextBlockLastVersionProxySU.Visibility = Visibility.Visible; - TextBlockNewVersionReminder.Visibility = Visibility.Visible; - ButtonUpgradeProxySU.Visibility = Visibility.Visible; - } - - #endregion - - #region 安装过程信息显示 端口数字防错代码,密钥选择代码 - - //更新状态条显示 - Action updateAction = new Action(UpdateTextBlock); - private static void UpdateTextBlock(TextBlock textBlockName, ProgressBar progressBar, string currentStatus) - { - textBlockName.Text = currentStatus; - - //if (currentStatus.Contains("成功") == true || currentStatus.ToLower().Contains("success") == true) - //{ - // progressBar.IsIndeterminate = false; - // progressBar.Value = 100; - //} - //else - if (currentStatus.Contains("失败") == true || currentStatus.Contains("取消") == true || currentStatus.Contains("退出") == true || currentStatus.ToLower().Contains("fail") == true || currentStatus.ToLower().Contains("cancel") == true || currentStatus.ToLower().Contains("exit") == true) - { - progressBar.IsIndeterminate = false; - progressBar.Value = 0; - } - //else - //{ - // progressBar.IsIndeterminate = true; - // //progressBar.Value = 0; - //} - - - } - - //进度条更新百分比 - private void SetUpProgressBarProcessing(int max) - { - - for (int i = installationDegree; i <= max; i++) - { - Thread.Sleep(100); - Dispatcher.Invoke(new Action(ProgressBarSetUpProcessing.SetValue), System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, Convert.ToDouble(i) }); - } - installationDegree = max; - } - - - //更新监视窗内的显示 - //结尾自动添加一个换行符 - Action updateMonitorAction = new Action(UpdateTextBox); - private static void UpdateTextBox(TextBox textBoxName, string currentResult) - { - textBoxName.Text = textBoxName.Text + currentResult + Environment.NewLine; - textBoxName.ScrollToEnd(); - } - - //结尾不添加换行符 - Action updateMonitorActionNoWrap = new Action(UpdateTextBoxNoWrap); - private static void UpdateTextBoxNoWrap(TextBox textBoxName, string currentResult) - { - textBoxName.Text = textBoxName.Text + currentResult; - textBoxName.ScrollToEnd(); - } - - //退出主程序 - private void Button_canel_Click(object sender, RoutedEventArgs e) - { - Application.Current.Shutdown(); - } - - // private static readonly Regex _regex = new Regex("[^0-9]+"); - - //检测数字输入 - private void TextBoxPort_PreviewTextInput(object sender, TextCompositionEventArgs e) - { - Regex regex = new Regex("[^0-9]+"); - e.Handled = regex.IsMatch(e.Text); - } - - //检测字符串是否只由数字组成 - private bool IsOnlyNumber(string value) - { - value = value.Trim(); - Regex r = new Regex(@"^[0-9]+$"); - return r.Match(value).Success; - } - - //端口输入框是否可使用粘贴命令 - private void TextBoxPort_PreviewExecuted(object sender, ExecutedRoutedEventArgs e) - { - if (e.Command == ApplicationCommands.Paste) - { - e.Handled = false;//true为不能使用粘贴命令,false为可以使用粘贴命令 - } - } - - //打开证书浏览 - private void ButtonOpenFileDialog_Click(object sender, RoutedEventArgs e) - { - var openFileDialog = new Microsoft.Win32.OpenFileDialog() - { - Filter = "Cert Files (*.*)|*.*" - }; - var result = openFileDialog.ShowDialog(); - if (result == true) - { - TextBoxCertFilePath.Text = openFileDialog.FileName; - } - } - #endregion - - #region 主界面控件的有效无效控制代码块及界面语言 - - //加载语言资源文件 - private void ResourcesLoad(string Culture) - { - List dictionaryList = new List(); - foreach (ResourceDictionary dictionary in Application.Current.Resources.MergedDictionaries) - { - dictionaryList.Add(dictionary); - } - string requestedCulture = string.Format(@"Translations\ProxySU.{0}.xaml", Culture); - //string requestedCulture = string.Format(@"Translations\ProxySU.{0}.xaml", "default"); - ResourceDictionary resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture)); - if (resourceDictionary == null) - { - requestedCulture = @"Translations\ProxySU.en-US.xaml"; - resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedCulture)); - } - if (resourceDictionary != null) - { - Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary); - Application.Current.Resources.MergedDictionaries.Add(resourceDictionary); - } - } - - //界面语言处理 - private void ComboBoxLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - string languageCulture; - object languageSelected; - languageSelected = ComboBoxLanguage.SelectedValue; - languageCulture = languageSelected.ToString(); - if (languageCulture.Equals("auto")) - { - languageCulture = System.Globalization.CultureInfo.InstalledUICulture.Name; - ResourcesLoad(languageCulture); - } - else - { - ResourcesLoad(languageCulture); - } - //display.Text = language; - } - private void RadioButtonNoProxy_Checked(object sender, RoutedEventArgs e) - { - TextBlockProxyHost.IsEnabled = false; - TextBlockProxyHost.Visibility = Visibility.Collapsed; - TextBoxProxyHost.IsEnabled = false; - TextBoxProxyHost.Visibility = Visibility.Collapsed; - TextBlockProxyPort.IsEnabled = false; - TextBlockProxyPort.Visibility = Visibility.Collapsed; - TextBoxProxyPort.IsEnabled = false; - TextBoxProxyPort.Visibility = Visibility.Collapsed; - RadioButtonProxyNoLogin.IsEnabled = false; - RadioButtonProxyNoLogin.Visibility = Visibility.Collapsed; - RadiobuttonProxyYesLogin.IsEnabled = false; - RadiobuttonProxyYesLogin.Visibility = Visibility.Collapsed; - TextBlockProxyUser.IsEnabled = false; - TextBlockProxyUser.Visibility = Visibility.Collapsed; - TextBoxProxyUserName.IsEnabled = false; - TextBoxProxyUserName.Visibility = Visibility.Collapsed; - TextBlockProxyPassword.IsEnabled = false; - TextBlockProxyPassword.Visibility = Visibility.Collapsed; - PasswordBoxProxyPassword.IsEnabled = false; - PasswordBoxProxyPassword.Visibility = Visibility.Collapsed; - } - - private void RadioButtonNoProxy_Unchecked(object sender, RoutedEventArgs e) - { - TextBlockProxyHost.IsEnabled = true; - TextBlockProxyHost.Visibility = Visibility.Visible; - TextBoxProxyHost.IsEnabled = true; - TextBoxProxyHost.Visibility = Visibility.Visible; - TextBlockProxyPort.IsEnabled = true; - TextBlockProxyPort.Visibility = Visibility.Visible; - TextBoxProxyPort.IsEnabled = true; - TextBoxProxyPort.Visibility = Visibility.Visible; - RadioButtonProxyNoLogin.IsEnabled = true; - RadioButtonProxyNoLogin.Visibility = Visibility.Visible; - RadiobuttonProxyYesLogin.IsEnabled = true; - RadiobuttonProxyYesLogin.Visibility = Visibility.Visible; - if (RadioButtonProxyNoLogin.IsChecked == true) - { - TextBlockProxyUser.IsEnabled = false; - TextBlockProxyUser.Visibility = Visibility.Collapsed; - TextBlockProxyPassword.IsEnabled = false; - TextBlockProxyPassword.Visibility = Visibility.Collapsed; - TextBoxProxyUserName.IsEnabled = false; - TextBoxProxyUserName.Visibility = Visibility.Collapsed; - PasswordBoxProxyPassword.IsEnabled = false; - PasswordBoxProxyPassword.Visibility = Visibility.Collapsed; - } - else - { - TextBlockProxyUser.IsEnabled = true; - TextBlockProxyUser.Visibility = Visibility.Visible; - TextBoxProxyUserName.IsEnabled = true; - TextBoxProxyUserName.Visibility = Visibility.Visible; - TextBlockProxyPassword.IsEnabled = true; - TextBlockProxyPassword.Visibility = Visibility.Visible; - PasswordBoxProxyPassword.IsEnabled = true; - PasswordBoxProxyPassword.Visibility = Visibility.Visible; - } - } - - private void RadioButtonPasswordLogin_Checked(object sender, RoutedEventArgs e) - { - ButtonOpenFileDialog.IsEnabled = false; - ButtonOpenFileDialog.Visibility = Visibility.Collapsed; - TextBoxCertFilePath.IsEnabled = false; - TextBoxCertFilePath.Visibility = Visibility.Collapsed; - TextBlockCert.Visibility = Visibility.Collapsed; - TextBlockPassword.Visibility = Visibility.Visible; - PasswordBoxHostPassword.IsEnabled = true; - PasswordBoxHostPassword.Visibility = Visibility.Visible; - } - - private void RadioButtonCertLogin_Checked(object sender, RoutedEventArgs e) - { - //TextBlockPassword.Text = "密钥:"; - TextBlockCert.Visibility = Visibility.Visible; - TextBlockPassword.Visibility = Visibility.Collapsed; - PasswordBoxHostPassword.IsEnabled = false; - PasswordBoxHostPassword.Visibility = Visibility.Collapsed; - ButtonOpenFileDialog.IsEnabled = true; - ButtonOpenFileDialog.Visibility = Visibility.Visible; - TextBoxCertFilePath.IsEnabled = true; - TextBoxCertFilePath.Visibility = Visibility.Visible; - } - - private void RadioButtonProxyNoLogin_Checked(object sender, RoutedEventArgs e) - { - TextBlockProxyUser.IsEnabled = false; - TextBlockProxyUser.Visibility = Visibility.Collapsed; - TextBlockProxyPassword.IsEnabled = false; - TextBlockProxyPassword.Visibility = Visibility.Collapsed; - TextBoxProxyUserName.IsEnabled = false; - TextBoxProxyUserName.Visibility = Visibility.Collapsed; - PasswordBoxProxyPassword.IsEnabled = false; - PasswordBoxProxyPassword.Visibility = Visibility.Collapsed; - } - - private void RadiobuttonProxyYesLogin_Checked(object sender, RoutedEventArgs e) - { - TextBlockProxyUser.IsEnabled = true; - TextBlockProxyUser.Visibility = Visibility.Visible; - TextBlockProxyPassword.IsEnabled = true; - TextBlockProxyPassword.Visibility = Visibility.Visible; - TextBoxProxyUserName.IsEnabled = true; - TextBoxProxyUserName.Visibility = Visibility.Visible; - PasswordBoxProxyPassword.IsEnabled = true; - PasswordBoxProxyPassword.Visibility = Visibility.Visible; - } - #endregion - - //远程主机连接信息 - private ConnectionInfo GenerateConnectionInfo() - { - ConnectionInfo connectionInfo; - - #region 检测输入的内容是否有错,并读取内容 - if (string.IsNullOrEmpty(PreTrim(TextBoxHost.Text)) == true || string.IsNullOrEmpty(PreTrim(TextBoxPort.Text)) == true || string.IsNullOrEmpty(PreTrim(TextBoxUserName.Text)) == true) - { - //******"主机地址、主机端口、用户名为必填项,不能为空"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostPortUserNotEmpty").ToString()); - - return connectionInfo = null; - } - string sshHostName = PreTrim(TextBoxHost.Text); - int sshPort = 22; - - if (IsOnlyNumber(PreTrim(TextBoxPort.Text)) == true) - { - TextBoxPort.Text = PreTrim(TextBoxPort.Text); - sshPort = int.Parse(TextBoxPort.Text); - } - else - { - //******"连接端口含有非数字字符!"****** - MessageBox.Show("Host Port" + Application.Current.FindResource("MessageBoxShow_ErrorHostPortErr").ToString()); - return connectionInfo = null; - } - - string sshUser = PreTrim(TextBoxUserName.Text); - - if (RadioButtonPasswordLogin.IsChecked == true && string.IsNullOrEmpty(PasswordBoxHostPassword.Password) == true) - { - //****** "登录密码为必填项,不能为空!!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostPasswordNotEmpty").ToString()); - return connectionInfo = null; - } - string sshPassword = PasswordBoxHostPassword.Password.ToString(); - if (RadioButtonCertLogin.IsChecked == true && string.IsNullOrEmpty(TextBoxCertFilePath.Text) == true) - { - //****** "密钥文件为必填项,不能为空!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostKeyNotEmpty").ToString()); - return connectionInfo = null; - } - string sshPrivateKey = TextBoxCertFilePath.Text.ToString(); - ProxyTypes proxyTypes = new ProxyTypes();//默认为None - - //proxyTypes = ProxyTypes.Socks5; - if (RadioButtonHttp.IsChecked == true) - { - proxyTypes = ProxyTypes.Http; - } - else if (RadioButtonSocks4.IsChecked == true) - { - proxyTypes = ProxyTypes.Socks4; - } - else if (RadioButtonSocks5.IsChecked == true) - { - proxyTypes = ProxyTypes.Socks5; - } - else - { - proxyTypes = ProxyTypes.None; - } - - //MessageBox.Show(proxyTypes.ToString()); - if (RadioButtonNoProxy.IsChecked == false && (string.IsNullOrEmpty(PreTrim(TextBoxProxyHost.Text)) == true || string.IsNullOrEmpty(PreTrim(TextBoxProxyPort.Text)) == true)) - { - //****** "如果选择了代理,则代理地址与端口不能为空!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorProxyAddressPortNotEmpty").ToString()); - return connectionInfo = null; - } - string sshProxyHost = PreTrim(TextBoxProxyHost.Text); - - int sshProxyPort = 1080; - if (IsOnlyNumber(PreTrim(TextBoxProxyPort.Text)) == true) - { - TextBoxProxyPort.Text = PreTrim(TextBoxProxyPort.Text); - sshProxyPort = int.Parse(TextBoxProxyPort.Text); - } - else - { - //******"连接端口含有非数字字符!"****** - MessageBox.Show("Proxy Port" + Application.Current.FindResource("MessageBoxShow_ErrorHostPortErr").ToString()); - return connectionInfo = null; - } - - if (RadioButtonNoProxy.IsChecked == false && RadiobuttonProxyYesLogin.IsChecked == true && (string.IsNullOrEmpty(PreTrim(TextBoxProxyUserName.Text)) == true || string.IsNullOrEmpty(PasswordBoxProxyPassword.Password) == true)) - { - //****** "如果代理需要登录,则代理登录的用户名与密码不能为空!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorProxyUserPasswordNotEmpty").ToString()); - return connectionInfo = null; - } - string sshProxyUser = PreTrim(TextBoxProxyUserName.Text); - string sshProxyPassword = PasswordBoxProxyPassword.Password; - - #endregion - - - //var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword); - - connectionInfo = new ConnectionInfo( - sshHostName, - sshPort, - sshUser, - proxyTypes, - sshProxyHost, - sshProxyPort, - sshProxyUser, - sshProxyPassword, - new PasswordAuthenticationMethod(sshUser, sshPassword) - //new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey)) - ); - - if (RadioButtonCertLogin.IsChecked == true) - { - connectionInfo = new ConnectionInfo( - sshHostName, - sshPort, - sshUser, - proxyTypes, - sshProxyHost, - sshProxyPort, - sshProxyUser, - sshProxyPassword, - //new PasswordAuthenticationMethod(sshUser, sshPassword) - new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey)) - ); - - } - return connectionInfo; - } - - //登录主机过程中出现的异常处理 - private void ProcessException(string exceptionMessage) - { - //下面代码需要保留,以备将来启用 - //if (exceptionMessage.Contains("连接尝试失败") == true) - //{ - // //****** "请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作!" ****** - // MessageBox.Show($"{exceptionMessage}\n" + - // Application.Current.FindResource("MessageBoxShow_ErrorLoginHostOrPort").ToString()); - //} - - //else if (exceptionMessage.Contains("denied (password)") == true) - //{ - // //****** "密码错误或用户名错误" ****** - // MessageBox.Show($"{exceptionMessage}\n" + - // Application.Current.FindResource("MessageBoxShow_ErrorLoginUserOrPassword").ToString()); - //} - //else if (exceptionMessage.Contains("Invalid private key file") == true) - //{ - // //****** "所选密钥文件错误或者格式不对!" ****** - // MessageBox.Show($"{exceptionMessage}\n" + - // Application.Current.FindResource("MessageBoxShow_ErrorLoginKey").ToString()); - //} - //else if (exceptionMessage.Contains("denied (publickey)") == true) - //{ - // //****** "使用密钥登录,密钥文件错误或用户名错误" ****** - // MessageBox.Show($"{exceptionMessage}\n" + - // Application.Current.FindResource("MessageBoxShow_ErrorLoginKeyOrUser").ToString()); - //} - //else if (exceptionMessage.Contains("目标计算机积极拒绝") == true) - //{ - // //****** "主机地址错误,如果使用了代理,也可能是连接代理的端口错误" ****** - // MessageBox.Show($"{exceptionMessage}\n" + - // Application.Current.FindResource("MessageBoxShow_ErrorLoginHostOrProxyPort").ToString()); - //} - //else - //{ - //****** "发生错误" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorLoginOccurred").ToString()); - MessageBox.Show(exceptionMessage); - //} - - } - - - #region V2Ray相关 - - //打开v2ray模板设置窗口 - private void ButtonTemplateConfiguration_Click(object sender, RoutedEventArgs e) - { - //清空初始化模板参数 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - WindowTemplateConfiguration windowTemplateConfiguration = new WindowTemplateConfiguration(); - windowTemplateConfiguration.Closed += windowTemplateConfigurationClosed; - windowTemplateConfiguration.ShowDialog(); - } - - //V2Ray模板设置窗口关闭后,触发事件,将所选的方案与其参数显示在UI上 - private void windowTemplateConfigurationClosed(object sender, System.EventArgs e) - { - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //显示"未选择方案!" - TextBlockCurrentlySelectedPlan.Text = Application.Current.FindResource("TextBlockCurrentlySelectedPlanNo").ToString(); - - GridV2rayCurrentlyPlan.Visibility = Visibility.Hidden; - - return; - } - else - { - GridV2rayCurrentlyPlan.Visibility = Visibility.Visible; - } - TextBlockCurrentlySelectedPlan.Text = ReceiveConfigurationParameters[8]; //所选方案名称 - TextBlockCurrentlySelectedPlanPort.Text = ReceiveConfigurationParameters[1]; //服务器端口 - TextBlockCurrentlySelectedPlanUUID.Text = ReceiveConfigurationParameters[2]; //UUID - TextBlockCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - //MessageBox.Show(ReceiveConfigurationParameters[7]); - TextBlockCurrentlySelectedPlanFakeWebsite.Text = ReceiveConfigurationParameters[7]; //伪装网站 - - if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true - || String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true) - { - //隐藏Path/mKCP Seed/Quic Key - HideV2RayPathSeedKey(); - HideVlessVmessXtlsTcpWs(); - - //隐藏域名/Quic加密方式 - HideV2RayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideV2RayMaskSites(); - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - //隐藏Path/mKCP Seed/Quic Key - HideV2RayPathSeedKey(); - HideVlessVmessXtlsTcpWs(); - - //显示域名 - ShowV2RayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideV2RayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //显示复合方案路径 - ShowVlessVmessXtlsTcpWs(); - - //显示域名 - ShowV2RayDomainQuicEncrypt(); - - //显示伪装网站(暂时不显示) - ShowV2RayMaskSites(); - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - //隐藏Path/mKCP Seed/Quic Key - HideV2RayPathSeedKey(); - HideVlessVmessXtlsTcpWs(); - - //显示域名 - ShowV2RayDomainQuicEncrypt(); - - //显示伪装网站(暂时不显示) - ShowV2RayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "Http2") == true) - { - //显示Path - ShowV2RayPathSeedKey(); - TextBlockV2RayShowPathSeedKey.Text = "Path:"; - TextBlockCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - - //显示域名 - ShowV2RayDomainQuicEncrypt(); - - //显示伪装网站(暂时不显示) - HideV2RayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - //显示Path - ShowV2RayPathSeedKey(); - TextBlockV2RayShowPathSeedKey.Text = "Path:"; - TextBlockCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //显示域名 - ShowV2RayDomainQuicEncrypt(); - - //显示伪装网站(暂时不显示) - ShowV2RayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - //显示Path - ShowV2RayPathSeedKey(); - TextBlockV2RayShowPathSeedKey.Text = "Path:"; - TextBlockCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //隐藏域名/Quic加密方式 - HideV2RayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideV2RayMaskSites(); - } - else if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - //显示mKCP Seed - ShowV2RayPathSeedKey(); - TextBlockV2RayShowPathSeedKey.Text = "mKCP Seed:"; - TextBlockCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //隐藏域名/Quic加密方式 - HideV2RayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideV2RayMaskSites(); - } - else if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - //显示QUIC Key - ShowV2RayPathSeedKey(); - TextBlockV2RayShowPathSeedKey.Text = "QUIC Key:"; - TextBlockCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //显示Quic加密方式 - ShowV2RayDomainQuicEncrypt(); - TextBlockV2RayShowCurrentlySelectedPlanDomain.Text = Application.Current.FindResource("TextBlockQuicEncryption").ToString(); - TextBlockCurrentlySelectedPlanDomain.Text = ReceiveConfigurationParameters[3]; //Quic加密方式 - if (String.Equals(TextBlockCurrentlySelectedPlanDomain.Text, "none") == true) - { - HideV2RayPathSeedKey(); - } - - - //隐藏伪装网站 - HideV2RayMaskSites(); - } - } - - #region 当前方案界面控制 - //显示端口与UUID - private void ShowV2RayCurrentPortUUID() - { - TextBlockV2RayShowPort.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPort.Visibility = Visibility.Visible; - - TextBlockV2RayShowUUID.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanUUID.Visibility = Visibility.Visible; - } - - //显示Path/mKCP Seed/Quic Key - private void ShowV2RayPathSeedKey() - { - HideVlessVmessXtlsTcpWs(); - TextBlockV2RayShowPathSeedKey.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPathSeedKey.Visibility = Visibility.Visible; - } - - //隐藏Path/mKCP Seed/Quic Key - private void HideV2RayPathSeedKey() - { - TextBlockV2RayShowPathSeedKey.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanPathSeedKey.Visibility = Visibility.Hidden; - } - - //显示VLESS VMESS XTLS TCP WS 复合方案 - private void ShowVlessVmessXtlsTcpWs() - { - HideV2RayPathSeedKey(); - GridVlessVmessXtlsTcpWs.Visibility = Visibility.Visible; - TextBlockBoxPathVlessWS.Text = ReceiveConfigurationParameters[3]; - TextBlockBoxPathVmessTcp.Text = ReceiveConfigurationParameters[9]; - TextBlockBoxPathVmessWS.Text = ReceiveConfigurationParameters[6]; - } - - //隐藏VLESS VMESS XTLS TCP WS 复合方案 - private void HideVlessVmessXtlsTcpWs() - { - GridVlessVmessXtlsTcpWs.Visibility = Visibility.Collapsed; - } - - //显示域名/Quic加密方式 - private void ShowV2RayDomainQuicEncrypt() - { - TextBlockV2RayShowCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - TextBlockV2RayShowCurrentlySelectedPlanDomain.Text = Application.Current.FindResource("TextBlockV2RayDomain").ToString(); - TextBlockCurrentlySelectedPlanDomain.Text = ReceiveConfigurationParameters[4]; //域名 - - } - - //隐藏域名/Quic加密方式 - private void HideV2RayDomainQuicEncrypt() - { - TextBlockV2RayShowCurrentlySelectedPlanDomain.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanDomain.Visibility = Visibility.Hidden; - } - //显示伪装网站 - private void ShowV2RayMaskSites() - { - TextBlockV2RayShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Visible; - } - - //隐藏伪装网站 - private void HideV2RayMaskSites() - { - TextBlockV2RayShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - } - #endregion - - //传送V2Ray模板参数,启动V2Ray安装进程 - private void Button_Login_Click(object sender, RoutedEventArgs e) - - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - - //生成客户端配置时,连接的服务主机的IP或者域名 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[4]) == true) - { - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text); - testDomain = false; - } - //选择模板 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //******"请先选择配置模板!"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ChooseTemplate").ToString()); - return; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true - || String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true - || ReceiveConfigurationParameters[0].Contains("mKCP") == true - || ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - testDomain = false; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - testDomain = true; - - } - - - //Thread thread - //SetUpProgressBarProcessing(0); //重置安装进度 - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - //Thread thread = new Thread(() => StartSetUpV2ray(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing)); - Thread thread = new Thread(() => StartSetUpV2ray(connectionInfo)); - - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - - - } - - //登录远程主机布署V2ray程序 - private void StartSetUpV2ray(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - //Thread.Sleep(3000); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "v2ray", @"/usr/local/bin/v2ray"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测系统是否符合安装要求 11--30 - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl) - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测校对时间 31--33 - functionResult = CheckProofreadingTime(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测域名解析是否正确 34---36 - if (testDomain == true) - { - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - } - - //下载安装脚本安装 37--40 - functionResult = ProxySoftInstall(client, @"V2Ray", @"https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"); - //functionResult = ProxySoftInstallV2ray(client, @"V2Ray", @"https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"); - - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - //functionResult = V2RayInstallScript(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序是否安装成功检测 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "v2ray", @"/usr/local/bin/v2ray"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //生成服务端配置 44--46 - functionResult = GenerateServerConfigurationV2Ray(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "上传配置文件......" ****** 47--50 - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); - MainWindowsShowInfo(currentStatus); - string serverRemoteConfig = @"/usr/local/etc/v2ray/config.json"; - UploadConfig(connectionInfo, @"config.json", serverRemoteConfig); - File.Delete(@"config.json"); - SetUpProgressBarProcessing(50); - - //如果使用http2/WebSocketTLS/tcpTLS/VlessTcpTlsWeb/VLESS+TCP+XTLS+Web模式,先要安装acme.sh,申请证书 - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //安装acme.sh与申请证书 51--57 - functionResult = AcmeShInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //安装证书到V2Ray 58--60 - functionResult = CertInstallToV2ray(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - - - #region Caddy安装 61--70 - - //如果是VLESS+TCP+XTLS+Web/VLESS+TCP+TLS+Web/VLESS+WebSocket+TLS+Web/VLESS+http2+TLS+Web/WebSocket+TLS+Web/http2Web模式,需要安装Caddy - if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //安装Caddy 61--66 - functionResult = CaddyInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - #region 上传Caddy配置文件 67--70 - - //******"上传Caddy配置文件"****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - string serverConfig = ""; - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\v2ray\caddy\vlessTcpTlsWeb.caddyfile"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\v2ray\caddy\WebSocketTLSWeb.caddyfile"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\v2ray\caddy\Http2Web.caddyfile"; - } - - string upLoadPath = "/etc/caddy/Caddyfile"; - client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"); - UploadConfig(connectionInfo, serverConfig, upLoadPath); - - functionResult = FileCheckExists(client, @"/etc/caddy/Caddyfile"); - if (functionResult == false) - { - //****** "Caddy配置文件上传失败!" ******32 - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigFailed").ToString(); - MainWindowsShowInfo(currentStatus); - FunctionResultErr(); - client.Disconnect(); - return; - } - - //****** "Caddy配置文件上传成功,OK!" ******32 - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //设置Caddy配置文件 - functionResult = SetCaddyfile(client, upLoadPath); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - #endregion - - //启动Caddy服务 - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - } - #endregion - - //****** "正在启动V2ray......" ******35 - functionResult = SoftStartDetect(client, "v2ray", @"/usr/local/bin/v2ray"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //测试BBR条件,若满足提示是否启用 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - //生成客户端配置 96--98 - functionResult = GenerateClientConfigurationV2Ray(); - - //****** "V2Ray安装成功,祝你玩的愉快!!" ******40 - SetUpProgressBarProcessing(100); - currentStatus = "V2Ray" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - Thread.Sleep(1000); - - //显示服务端连接参数 - proxyType = "V2Ray"; - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - - return; - - } - } - catch (Exception ex1)//例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - } - - #region V2Ray专用调用函数 - //安装代理程序 37--40 - //functionResult = ProxySoftInstall(client,@"",@""); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool ProxySoftInstallV2ray(SshClient client, string proxyName, string downloadUrl) - { - //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - SetUpProgressBarProcessing(37); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "正在安装{proxyName}......" ****** - SetUpProgressBarProcessing(38); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + $"{proxyName}......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} {downloadUrl}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - - } - sshShellCommand = $"yes | bash {saveShellScriptFileName} --version v4.32.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(40); - return true; - } - - - //生成V2Ray服务端配置 44--46 - //functionResult = GenerateServerConfiguration(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool GenerateServerConfigurationV2Ray(SshClient client) - { - SetUpProgressBarProcessing(44); - //修改v2ray.service - - sshShellCommand = $"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/v2ray.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/v2ray.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/v2ray.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"systemctl daemon-reload"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //备用下载地址:https://raw.githubusercontent.com/proxysu/Resources/master/v2ray/v2ray.service - - //sshShellCommand = $"yes | curl -o /etc/systemd/system/v2ray.service https://raw.githubusercontent.com/proxysu/Resources/master/v2ray/v2ray.service"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //备份原来的文件 - functionResult = FileCheckExists(client, @"/usr/local/etc/v2ray/config.json"); - if (functionResult == true) - { - - sshShellCommand = @"mv /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - //读取配置文件各个模块 - string logConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\00_log\00_log.json"; - string apiConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\01_api\01_api.json"; - string dnsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\02_dns\02_dns.json"; - string routingConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\03_routing\03_routing.json"; - string policyConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\04_policy\04_policy.json"; - string inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\05_inbounds.json"; - string outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\06_outbounds\06_outbounds.json"; - string transportConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\07_transport\07_transport.json"; - string statsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\08_stats\08_stats.json"; - string reverseConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\09_reverse\09_reverse.json"; - string baseConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\base.json"; - - //配置文件模块合成 - using (StreamReader reader = File.OpenText(baseConfigJson)) - { - JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - //读取"log" - using (StreamReader readerJson = File.OpenText(logConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["log"] = jObjectJson["log"]; - } - //读取"api" - using (StreamReader readerJson = File.OpenText(apiConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["api"] = jObjectJson["api"]; - } - //读取"dns" - using (StreamReader readerJson = File.OpenText(dnsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["dns"] = jObjectJson["dns"]; - } - //读取"routing" - using (StreamReader readerJson = File.OpenText(routingConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["routing"] = jObjectJson["routing"]; - } - //读取"policy" - using (StreamReader readerJson = File.OpenText(policyConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["policy"] = jObjectJson["policy"]; - } - //读取"inbounds" - using (StreamReader readerJson = File.OpenText(inboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["inbounds"] = jObjectJson["inbounds"]; - } - //读取"outbounds" - using (StreamReader readerJson = File.OpenText(outboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["outbounds"] = jObjectJson["outbounds"]; - } - //读取"transport" - using (StreamReader readerJson = File.OpenText(transportConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["transport"] = jObjectJson["transport"]; - } - //读取"stats" - using (StreamReader readerJson = File.OpenText(statsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["stats"] = jObjectJson["stats"]; - } - //读取"reverse" - using (StreamReader readerJson = File.OpenText(reverseConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["reverse"] = jObjectJson["reverse"]; - } - - //依据安装模式读取相应模板 - if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\tcp_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\tcp_http_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\tcp_TLS_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\tcpTLSselfSigned_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\vless_tcp_xtls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\vless_tcp_tls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\vless_ws_tls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\vless_http2_tls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\vless_vmess_xtls_tcp_websocket_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\webSocket_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\WebSocket_TLS_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\WebSocketTLS_selfSigned_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\WebSocketTLSWeb_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\http2_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\Http2Web_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\Http2selfSigned_server_config.json"; - } - //else if (String.Equals(ReceiveConfigurationParameters[0], "MkcpNone")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2SRTP")||String.Equals(ReceiveConfigurationParameters[0], "mKCPuTP")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WechatVideo")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2DTLS")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - if (mKCPvlessIsSet == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\vless_mkcp_server_config.json"; - } - else - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\mkcp_server_config.json"; - } - - } - - // else if (String.Equals(ReceiveConfigurationParameters[0], "QuicNone") || String.Equals(ReceiveConfigurationParameters[0], "QuicSRTP") || String.Equals(ReceiveConfigurationParameters[0], "Quic2uTP") || String.Equals(ReceiveConfigurationParameters[0], "QuicWechatVideo") || String.Equals(ReceiveConfigurationParameters[0], "QuicDTLS") || String.Equals(ReceiveConfigurationParameters[0], "QuicWireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\quic_server_config.json"; - } - - //读取"inbounds" - using (StreamReader readerJson = File.OpenText(inboundsConfigJson)) - { - JObject jObjectJsonTmp = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - var jObjectJson = (dynamic)jObjectJsonTmp; - - //Padavan路由固件服务端设置(因为客户端分流有问题所以在服务端弥补)加上后会影响一定的速度 - - //string sniffingAddServer = $"{pwdir}" + @"TemplateConfg\v2ray\server\05_inbounds\00_padavan_router.json"; - //using (StreamReader readerSniffingJson = File.OpenText(sniffingAddServer)) - //{ - // JObject jObjectSniffingJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerSniffingJson)); - // jObjectJson["inbounds"][0]["sniffing"] = jObjectSniffingJson["sniffing"]; - //} - - //设置uuid - jObjectJson["inbounds"][0]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - - //除WebSocketTLSWeb/http2Web/VLESS+WebSocket+TLS+Web/VLESS+http2+TLS+Web模式外设置监听端口 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == false - && String.Equals(ReceiveConfigurationParameters[0], "http2Web") == false - && String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == false - && String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == false) - { - jObjectJson["inbounds"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - } - - //设置VLESS协议的回落端口,指向Caddy - if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - //设置Caddy随机监听的端口 - randomCaddyListenPort = GetRandomPort(); - - //指向Caddy监听的随机端口 - jObjectJson["inbounds"][0]["settings"]["fallbacks"][0]["dest"] = randomCaddyListenPort; - } - //设置VLESS+VMESS+Trojan+XTLS+TCP+WebSocket+Web协议 - if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //设置Caddy随机监听的端口 - randomCaddyListenPort = GetRandomPort(); - - //指向Caddy监听的随机端口 - jObjectJson["inbounds"][1]["settings"]["fallbacks"][0]["dest"] = randomCaddyListenPort; - //设置其他模式的UUID - jObjectJson["inbounds"][1]["settings"]["clients"][0]["password"] = ReceiveConfigurationParameters[2]; - jObjectJson["inbounds"][2]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["inbounds"][3]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["inbounds"][4]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - - //设置Vless回落与分流的Path - jObjectJson["inbounds"][0]["settings"]["fallbacks"][1]["path"] = ReceiveConfigurationParameters[3]; - jObjectJson["inbounds"][0]["settings"]["fallbacks"][2]["path"] = ReceiveConfigurationParameters[9]; - jObjectJson["inbounds"][0]["settings"]["fallbacks"][3]["path"] = ReceiveConfigurationParameters[6]; - - //设置Vless ws Path - jObjectJson["inbounds"][2]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[3]; - //设置Vmess tcp Path - jObjectJson["inbounds"][3]["streamSettings"]["tcpSettings"]["header"]["request"]["path"][0] = ReceiveConfigurationParameters[9]; - //设置Vmess ws Path - jObjectJson["inbounds"][4]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - - } - - //TLS自签证书/WebSocketTLS(自签证书)/http2自签证书模式下,使用v2ctl 生成自签证书 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - string selfSignedCa = client.RunCommand("/usr/local/bin/v2ctl cert --ca").Result; - JObject selfSignedCaJObject = JObject.Parse(selfSignedCa); - jObjectJson["inbounds"][0]["streamSettings"]["tlsSettings"]["certificates"][0] = selfSignedCaJObject; - } - - //如果是WebSocketTLSWeb/WebSocketTLS/WebSocketTLS(自签证书)/VLESS+WebSocket+TLS+Web模式,则设置路径 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //如果是Http2/http2Web/http2自签/VLESS+http2+TLS+Web模式下,设置路径 - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["httpSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //如果是Http2+Web/VLESS+http2+TLS+Web模式下,设置host - if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["httpSettings"]["host"][0] = ReceiveConfigurationParameters[4]; - } - - //mkcp模式下,设置伪装类型 - if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["kcpSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[6]) == false) - { - jObjectJson["inbounds"][0]["streamSettings"]["kcpSettings"]["seed"] = ReceiveConfigurationParameters[6]; - } - } - - //quic模式下设置伪装类型及密钥 - if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["quicSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - jObjectJson["inbounds"][0]["streamSettings"]["quicSettings"]["security"] = ReceiveConfigurationParameters[3]; - - if (String.Equals(ReceiveConfigurationParameters[3], "none") == true) - { - ReceiveConfigurationParameters[6] = ""; - } - jObjectJson["inbounds"][0]["streamSettings"]["quicSettings"]["key"] = ReceiveConfigurationParameters[6]; - } - - serverJson["inbounds"] = jObjectJson["inbounds"]; - } - - using (StreamWriter sw = new StreamWriter(@"config.json")) - { - sw.Write(serverJson.ToString()); - } - } - SetUpProgressBarProcessing(46); - return true; - } - - //安装证书到V2Ray 58--60 - //functionResult = CertInstallToV2ray(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool CertInstallToV2ray(SshClient client) - { - //****** "安装证书到V2ray......" ******26 - SetUpProgressBarProcessing(58); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoft").ToString() + "V2ray......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mkdir -p /usr/local/etc/v2ray/ssl"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --keypath /usr/local/etc/v2ray/ssl/v2ray_ssl.key --capath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --reloadcmd \"systemctl restart v2ray\""; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"if [ ! -f ""/usr/local/etc/v2ray/ssl/v2ray_ssl.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("1") == true) - { - //****** "证书成功安装到V2ray!" ******27 - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftOK").ToString() + "V2Ray!"; - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "证书安装到V2ray失败,原因未知,可以向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftFail").ToString() + - "V2Ray" + - Application.Current.FindResource("DisplayInstallInfo_InstallCertFailAsk").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - } - - //设置私钥权限 - sshShellCommand = @"chmod 644 /usr/local/etc/v2ray/ssl/v2ray_ssl.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - return true; - } - - //生成V2Ray客户端配置 96--98 - //functionResult = GenerateClientConfiguration(); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool GenerateClientConfigurationV2Ray() - { - //****** "生成客户端配置......" ******39 - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - string logConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\00_log\00_log.json"; - string apiConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\01_api\01_api.json"; - string dnsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\02_dns\02_dns.json"; - string routingConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\03_routing\03_routing.json"; - string policyConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\04_policy\04_policy.json"; - string inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\05_inbounds\05_inbounds.json"; - string outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\06_outbounds.json"; - string transportConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\07_transport\07_transport.json"; - string statsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\08_stats\08_stats.json"; - string reverseConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\09_reverse\09_reverse.json"; - string baseConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\base.json"; - //Thread.Sleep(1000); - if (!Directory.Exists("v2ray_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("v2ray_config");//创建该文件夹   - } - - using (StreamReader reader = File.OpenText(baseConfigJson)) - { - JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - //读取"log" - using (StreamReader readerJson = File.OpenText(logConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["log"] = jObjectJson["log"]; - } - //读取"api" - using (StreamReader readerJson = File.OpenText(apiConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["api"] = jObjectJson["api"]; - } - //读取"dns" - using (StreamReader readerJson = File.OpenText(dnsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["dns"] = jObjectJson["dns"]; - } - //读取"routing" - using (StreamReader readerJson = File.OpenText(routingConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["routing"] = jObjectJson["routing"]; - } - //读取"policy" - using (StreamReader readerJson = File.OpenText(policyConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["policy"] = jObjectJson["policy"]; - } - //读取"inbounds" - using (StreamReader readerJson = File.OpenText(inboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["inbounds"] = jObjectJson["inbounds"]; - } - //读取"outbounds" - using (StreamReader readerJson = File.OpenText(outboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["outbounds"] = jObjectJson["outbounds"]; - } - //读取"transport" - using (StreamReader readerJson = File.OpenText(transportConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["transport"] = jObjectJson["transport"]; - } - //读取"stats" - using (StreamReader readerJson = File.OpenText(statsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["stats"] = jObjectJson["stats"]; - } - //读取"reverse" - using (StreamReader readerJson = File.OpenText(reverseConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["reverse"] = jObjectJson["reverse"]; - } - - //根据不同的安装方案,选择相应的客户端模板 - if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == false) - { - #region 单模式方案 - //根据选择的不同模式,选择相应的配置文件 - if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\tcp_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\tcp_http_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\tcp_TLS_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\tcpTLSselfSigned_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_tcp_xtls_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_tcp_tls_caddy_cilent_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_ws_tls_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_http2_tls_server_config.json"; - } - - else if (String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\webSocket_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\WebSocket_TLS_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\WebSocketTLS_selfSigned_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\WebSocketTLSWeb_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\http2_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\Http2Web_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\Http2selfSigned_client_config.json"; - } - //else if (String.Equals(ReceiveConfigurationParameters[0], "MkcpNone")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2SRTP")||String.Equals(ReceiveConfigurationParameters[0], "mKCPuTP")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WechatVideo")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2DTLS")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - if (mKCPvlessIsSet == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_mkcp_client_config.json"; - } - else - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\mkcp_client_config.json"; - } - - } - // else if (String.Equals(ReceiveConfigurationParameters[0], "QuicNone") || String.Equals(ReceiveConfigurationParameters[0], "QuicSRTP") || String.Equals(ReceiveConfigurationParameters[0], "Quic2uTP") || String.Equals(ReceiveConfigurationParameters[0], "QuicWechatVideo") || String.Equals(ReceiveConfigurationParameters[0], "QuicDTLS") || String.Equals(ReceiveConfigurationParameters[0], "QuicWireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\quic_client_config.json"; - } - - - //读取"相应模板的outbounds" - using (StreamReader readerJson = File.OpenText(outboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - - - //设置WebSocket模式下的path - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //设置http2模式下的path - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["httpSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //设置http2+TLS+Web/VLESS+http2+TLS+Web模式下的host - if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["httpSettings"]["host"][0] = ReceiveConfigurationParameters[4]; - } - - //设置VLESS+TCP+XTLS+Web模式下的serverName - //if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - //{ - // jObjectJson["outbounds"][0]["streamSettings"]["xtlsSettings"]["serverName"] = ReceiveConfigurationParameters[4]; - //} - - //设置mkcp - if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["kcpSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[6]) == false) - { - jObjectJson["outbounds"][0]["streamSettings"]["kcpSettings"]["seed"] = ReceiveConfigurationParameters[6]; - } - } - - //设置QUIC - if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["quicSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - jObjectJson["outbounds"][0]["streamSettings"]["quicSettings"]["security"] = ReceiveConfigurationParameters[3]; - if (String.Equals(ReceiveConfigurationParameters[3], "none") == true) - { - ReceiveConfigurationParameters[6] = ""; - } - jObjectJson["outbounds"][0]["streamSettings"]["quicSettings"]["key"] = ReceiveConfigurationParameters[6]; - } - - clientJson["outbounds"] = jObjectJson["outbounds"]; - - } - - using (StreamWriter sw = new StreamWriter(@"v2ray_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - - #endregion - - } - else - { - //复合方案所需要的配置文件 - //VLESS over TCP with XTLS模式 - //string outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_tcp_xtls_client_config.json"; - //using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - //{ - // JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - // //设置客户端的地址/端口/id - // jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - // jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - // jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - - // clientJson["outbounds"] = jObjectJson["outbounds"]; - // if (!Directory.Exists(@"v2ray_config\vless_tcp_xtls_client_config"))//如果不存在就创建file文件夹      - // { - // Directory.CreateDirectory(@"v2ray_config\vless_tcp_xtls_client_config");//创建该文件夹   - // } - // using (StreamWriter sw = new StreamWriter(@"v2ray_config\vless_tcp_xtls_client_config\config.json")) - // { - // sw.Write(clientJson.ToString()); - // } - //} - - //VLESS over TCP with TLS模式 - string outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_tcp_tls_caddy_cilent_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"v2ray_config\vless_tcp_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"v2ray_config\vless_tcp_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"v2ray_config\vless_tcp_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VLESS over WS with TLS 模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vless_ws_tls_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[3]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"v2ray_config\vless_ws_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"v2ray_config\vless_ws_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"v2ray_config\vless_ws_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VMess over TCP with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\vmess_tcp_tls_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["tcpSettings"]["header"]["request"]["path"][0] = ReceiveConfigurationParameters[9]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"v2ray_config\vmess_tcp_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"v2ray_config\vmess_tcp_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"v2ray_config\vmess_tcp_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VMess over WS with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\WebSocketTLSWeb_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"v2ray_config\vmess_ws_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"v2ray_config\vmess_ws_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"v2ray_config\vmess_ws_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //Trojan over TCP with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\v2ray\client\06_outbounds\trojan_tcp_tls.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["servers"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["servers"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["servers"][0]["password"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["tlsSettings"]["serverName"] = ReceiveConfigurationParameters[4]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"v2ray_config\trojan_tcp_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"v2ray_config\trojan_tcp_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"v2ray_config\trojan_tcp_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - } - } - SetUpProgressBarProcessing(98); - return true; - } - - - #endregion - - //检测升级远程主机端的V2Ray版本 - private void ButtonUpdateV2ray_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => UpdateV2ray(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //升级V2ray主程序 - private void UpdateV2ray(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //******"检测系统是否已经安装V2ray......"****** - SetUpProgressBarProcessing(20); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "V2ray......"; - MainWindowsShowInfo(currentStatus); - - //Thread.Sleep(1000); - //检测是否安装V2Ray - //sshShellCommand = @"find / -name v2ray"; - //sshShellCommand = @"if [[ -f /usr/local/bin/v2ray ]];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/v2ray") == false) - //if (currentShellCommandResult.Trim().Equals("0") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/v2ray"); - if (functionResult == false) - { - //******"退出!原因:远程主机未安装V2ray"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_ErrorUpgradeSoftNotInstall").ToString() + "V2Ray!"; - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - - } - - //sshcmd = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string v2rayCurrentVersion = currentShellCommandResult;//不含字母v - - //sshcmd = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2fly/v2ray-core/releases/latest"" --connect-timeout 10| grep 'tag_name' | cut -d\"" -f4"; - sshShellCommand = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2fly/v2ray-core/releases/latest"" --connect-timeout 10 | grep 'tag_name' | cut -d\"" -f4"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string v2rayNewVersion = currentShellCommandResult;//包含字母v - - if (v2rayNewVersion.Contains(v2rayCurrentVersion) == false) - { - MessageBoxResult messageBoxResult = MessageBox.Show( - //****** "远程主机当前版本为:v" ****** - Application.Current.FindResource("DisplayInstallInfo_CurrentVersion").ToString() + - $"{v2rayCurrentVersion}\n" + - //****** "最新版本为:" ****** - Application.Current.FindResource("DisplayInstallInfo_NewVersion").ToString() + - $"{v2rayNewVersion}\n" + - //****** "是否升级为最新版本?" ****** - Application.Current.FindResource("DisplayInstallInfo_IsOrNoUpgradeNewVersion").ToString(), "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - //****** "正在升级到最新版本......" ****** - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartUpgradeNewVersion").ToString(); - MainWindowsShowInfo(currentStatus); - - //client.RunCommand(@"bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"); - sshShellCommand = $"bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(80); - //sshcmd = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - v2rayCurrentVersion = currentShellCommandResult;//不含字母v - if (v2rayNewVersion.Contains(v2rayCurrentVersion) == true) - { - //****** "升级成功!当前已是最新版本!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString()); - //****** "升级成功!当前已是最新版本!" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "升级失败,原因未知,请向开发者提问!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString()); - //****** "升级失败,原因未知,请向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString(); - MainWindowsShowInfo(currentStatus); - } - } - else - { - //****** "升级取消,退出!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeVersionCancel").ToString(); - MainWindowsShowInfo(currentStatus); - - client.Disconnect(); - return; - } - } - else - { - //****** "远程主机当前已是最新版本:" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IsNewVersion").ToString() + - $"{v2rayNewVersion}\n" + - //****** "无需升级!退出!" ****** - Application.Current.FindResource("DisplayInstallInfo_NotUpgradeVersion").ToString(); - MessageBox.Show(currentStatus); - MainWindowsShowInfo(currentStatus); - } - - client.Disconnect(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - #endregion - - #region Xray相关 - //打开Xray模板设置窗口 - private void ButtonTemplateConfigurationXray_Click(object sender, RoutedEventArgs e) - { - //清空初始化模板参数 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - XrayWindowTemplateConfiguration XraywindowTemplateConfiguration = new XrayWindowTemplateConfiguration(); - XraywindowTemplateConfiguration.Closed += XraywindowTemplateConfigurationClosed; - XraywindowTemplateConfiguration.ShowDialog(); - } - - //Xay模板设置窗口关闭后,触发事件,将所选的方案与其参数显示在UI上 - private void XraywindowTemplateConfigurationClosed(object sender, System.EventArgs e) - { - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //显示"未选择方案!" - TextBlockCurrentlySelectedPlanXray.Text = Application.Current.FindResource("TextBlockCurrentlySelectedPlanNo").ToString(); - - GridXrayCurrentlyPlan.Visibility = Visibility.Hidden; - - return; - } - else - { - GridXrayCurrentlyPlan.Visibility = Visibility.Visible; - } - TextBlockCurrentlySelectedPlanXray.Text = ReceiveConfigurationParameters[8]; //所选方案名称 - TextBlockCurrentlySelectedPlanPortXray.Text = ReceiveConfigurationParameters[1]; //服务器端口 - TextBlockCurrentlySelectedPlanUUIDXray.Text = ReceiveConfigurationParameters[2]; //UUID - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - //MessageBox.Show(ReceiveConfigurationParameters[7]); - TextBlockCurrentlySelectedPlanFakeWebsiteXray.Text = ReceiveConfigurationParameters[7]; //伪装网站 - - if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true - || String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true) - { - //隐藏Path/mKCP Seed/Quic Key - HideXayPathSeedKey(); - HideVlessVmessXtlsTcpWsXray(); - - //隐藏域名/Quic加密方式 - HideXrayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideXrayMaskSites(); - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - //隐藏Path/mKCP Seed/Quic Key - HideXayPathSeedKey(); - HideVlessVmessXtlsTcpWsXray(); - - //显示域名 - ShowXrayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideXrayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //显示复合方案路径 - ShowVlessVmessXtlsTcpWsXray(); - - //显示域名 - ShowXrayDomainQuicEncrypt(); - - //显示伪装网站 - ShowXayMaskSites(); - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - //隐藏Path/mKCP Seed/Quic Key - HideXayPathSeedKey(); - HideVlessVmessXtlsTcpWsXray(); - - //显示域名 - ShowXrayDomainQuicEncrypt(); - - //显示伪装网站 - ShowXayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "Http2") == true) - { - //显示Path - ShowXayPathSeedKey(); - TextBlockXrayShowPathSeedKey.Text = "Path:"; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - - //显示域名 - ShowXrayDomainQuicEncrypt(); - - //显示伪装网站(暂时不显示) - HideXrayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - //显示Path - ShowXayPathSeedKey(); - TextBlockXrayShowPathSeedKey.Text = "Path:"; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //显示域名 - ShowXrayDomainQuicEncrypt(); - - //显示伪装网站 - ShowXayMaskSites(); - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - //显示Path - ShowXayPathSeedKey(); - TextBlockXrayShowPathSeedKey.Text = "Path:"; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //隐藏域名/Quic加密方式 - HideXrayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideXrayMaskSites(); - } - else if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - //显示mKCP Seed - ShowXayPathSeedKey(); - TextBlockXrayShowPathSeedKey.Text = "mKCP Seed:"; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //隐藏域名/Quic加密方式 - HideXrayDomainQuicEncrypt(); - - //隐藏伪装网站 - HideXrayMaskSites(); - } - else if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - //显示QUIC Key - ShowXayPathSeedKey(); - TextBlockXrayShowPathSeedKey.Text = "QUIC Key:"; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - //显示Quic加密方式 - ShowXrayDomainQuicEncrypt(); - TextBlockXrayShowCurrentlySelectedPlanDomain.Text = Application.Current.FindResource("TextBlockQuicEncryption").ToString(); - TextBlockCurrentlySelectedPlanDomainXray.Text = ReceiveConfigurationParameters[3]; //Quic加密方式 - if (String.Equals(TextBlockCurrentlySelectedPlanDomain.Text, "none") == true) - { - HideXayPathSeedKey(); - } - - - //隐藏伪装网站 - HideXrayMaskSites(); - } - } - - #region 当前方案界面控制 - //显示端口与UUID - private void ShowXrayCurrentPortUUID() - { - TextBlockXrayShowPort.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPortXray.Visibility = Visibility.Visible; - - TextBlockXrayShowUUID.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanUUIDXray.Visibility = Visibility.Visible; - } - - //显示Path/mKCP Seed/Quic Key - private void ShowXayPathSeedKey() - { - HideVlessVmessXtlsTcpWsXray(); - TextBlockXrayShowPathSeedKey.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Visibility = Visibility.Visible; - } - - //隐藏Path/mKCP Seed/Quic Key - private void HideXayPathSeedKey() - { - TextBlockXrayShowPathSeedKey.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanPathSeedKeyXray.Visibility = Visibility.Hidden; - } - - //显示VLESS VMESS XTLS TCP WS 复合方案 - private void ShowVlessVmessXtlsTcpWsXray() - { - HideXayPathSeedKey(); - GridVlessVmessXtlsTcpWsXray.Visibility = Visibility.Visible; - TextBlockBoxPathVlessWSXray.Text = ReceiveConfigurationParameters[3]; - TextBlockBoxPathVmessTcpXray.Text = ReceiveConfigurationParameters[9]; - TextBlockBoxPathVmessWSXray.Text = ReceiveConfigurationParameters[6]; - } - - //隐藏VLESS VMESS XTLS TCP WS 复合方案 - private void HideVlessVmessXtlsTcpWsXray() - { - GridVlessVmessXtlsTcpWsXray.Visibility = Visibility.Collapsed; - } - - //显示域名/Quic加密方式 - private void ShowXrayDomainQuicEncrypt() - { - TextBlockXrayShowCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanDomainXray.Visibility = Visibility.Visible; - TextBlockXrayShowCurrentlySelectedPlanDomain.Text = Application.Current.FindResource("TextBlockV2RayDomain").ToString(); - TextBlockCurrentlySelectedPlanDomainXray.Text = ReceiveConfigurationParameters[4]; //域名 - - } - - //隐藏域名/Quic加密方式 - private void HideXrayDomainQuicEncrypt() - { - TextBlockXrayShowCurrentlySelectedPlanDomain.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanDomainXray.Visibility = Visibility.Hidden; - } - //显示伪装网站 - private void ShowXayMaskSites() - { - TextBlockXrayShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanFakeWebsiteXray.Visibility = Visibility.Visible; - } - - //隐藏伪装网站 - private void HideXrayMaskSites() - { - TextBlockXrayShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanFakeWebsiteXray.Visibility = Visibility.Hidden; - } - #endregion - - //传送Xray模板参数,启动Xray安装进程 - private void ButtonXraySetUP_Click(object sender, RoutedEventArgs e) - - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - - //生成客户端配置时,连接的服务主机的IP或者域名 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[4]) == true) - { - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text); - testDomain = false; - } - //选择模板 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //******"请先选择配置模板!"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ChooseTemplate").ToString()); - return; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true - || String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true - || ReceiveConfigurationParameters[0].Contains("mKCP") == true - || ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - testDomain = false; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - testDomain = true; - - } - - - //Thread thread - //SetUpProgressBarProcessing(0); //重置安装进度 - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - //Thread thread = new Thread(() => StartSetUpXray(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing)); - Thread thread = new Thread(() => StartSetUpXray(connectionInfo)); - - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - - - } - - //登录远程主机布署Xray程序 - private void StartSetUpXray(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - //Thread.Sleep(3000); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "xray", @"/usr/local/bin/xray"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测系统是否符合安装要求 11--30 - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl) - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测校对时间 31--33 - functionResult = CheckProofreadingTime(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测域名解析是否正确 34---36 - if (testDomain == true) - { - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - } - - //下载安装脚本安装 37--40 - //functionResult = ProxySoftInstall(client, @"Xray", @"https://raw.githubusercontent.com/v2fly/fhs-install-Xray/master/install-release.sh"); - functionResult = ProxySoftInstall(client, @"Xray", @"https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh"); - - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - //functionResult = XrayInstallScript(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序是否安装成功检测 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "xray", @"/usr/local/bin/xray"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //生成服务端配置 44--46 - functionResult = GenerateServerConfigurationXray(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "上传配置文件......" ****** 47--50 - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); - MainWindowsShowInfo(currentStatus); - string serverRemoteConfig = @"/usr/local/etc/xray/config.json"; - UploadConfig(connectionInfo, @"config.json", serverRemoteConfig); - File.Delete(@"config.json"); - SetUpProgressBarProcessing(50); - - //如果使用http2/WebSocketTLS/tcpTLS/VlessTcpTlsWeb/VLESS+TCP+XTLS+Web模式,先要安装acme.sh,申请证书 - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //安装acme.sh与申请证书 51--57 - functionResult = AcmeShInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //安装证书到Xray 58--60 - functionResult = CertInstallToXray(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - - - #region Caddy安装 61--70 - - //如果是VLESS+TCP+XTLS+Web/VLESS+TCP+TLS+Web/VLESS+WebSocket+TLS+Web/VLESS+http2+TLS+Web/WebSocket+TLS+Web/http2Web模式,需要安装Caddy - if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //安装Caddy 61--66 - functionResult = CaddyInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - #region 上传Caddy配置文件 67--70 - - //******"上传Caddy配置文件"****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - string serverConfig = ""; - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\xray\caddy\vlessTcpTlsWeb.caddyfile"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\xray\caddy\WebSocketTLSWeb.caddyfile"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\xray\caddy\Http2Web.caddyfile"; - } - - string upLoadPath = "/etc/caddy/Caddyfile"; - client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"); - UploadConfig(connectionInfo, serverConfig, upLoadPath); - - functionResult = FileCheckExists(client, @"/etc/caddy/Caddyfile"); - if (functionResult == false) - { - //****** "Caddy配置文件上传失败!" ******32 - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigFailed").ToString(); - MainWindowsShowInfo(currentStatus); - FunctionResultErr(); - client.Disconnect(); - return; - } - - //****** "Caddy配置文件上传成功,OK!" ******32 - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //设置Caddy配置文件 - functionResult = SetCaddyfile(client, upLoadPath); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - #endregion - - //启动Caddy服务 - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - } - #endregion - - //****** "正在启动Xray......" ******35 - functionResult = SoftStartDetect(client, "xray", @"/usr/local/bin/xray"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //测试BBR条件,若满足提示是否启用 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - //生成客户端配置 96--98 - functionResult = GenerateClientConfigurationXray(); - - //****** "Xray安装成功,祝你玩的愉快!!" ******40 - SetUpProgressBarProcessing(100); - currentStatus = "Xray" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - Thread.Sleep(1000); - - //显示服务端连接参数 - proxyType = "Xray"; - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - - return; - - } - } - catch (Exception ex1)//例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - } - - #region Xray专用调用函数 - //安装代理程序 37--40 - //functionResult = ProxySoftInstall(client,@"",@""); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - /* private bool ProxySoftInstallV2ray(SshClient client, string proxyName, string downloadUrl) - { - //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - SetUpProgressBarProcessing(37); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "正在安装{proxyName}......" ****** - SetUpProgressBarProcessing(38); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + $"{proxyName}......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} {downloadUrl}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - - } - sshShellCommand = $"yes | bash {saveShellScriptFileName} --version v4.32.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(40); - return true; - } */ - - - //生成Xray服务端配置 44--46 - //functionResult = GenerateServerConfiguration(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool GenerateServerConfigurationXray(SshClient client) - { - SetUpProgressBarProcessing(44); - //修改xray.service - - sshShellCommand = $"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/xray.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/xray.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/xray.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"systemctl daemon-reload"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //备用下载地址:https://raw.githubusercontent.com/proxysu/Resources/master/xray/xray.service - - //sshShellCommand = $"yes | curl -o /etc/systemd/system/xray.service https://raw.githubusercontent.com/proxysu/Resources/master/xray/xray.service"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //备份原来的文件 - functionResult = FileCheckExists(client, @"/usr/local/etc/xray/config.json"); - if (functionResult == true) - { - - sshShellCommand = @"mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - //读取配置文件各个模块 - string logConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\00_log\00_log.json"; - string apiConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\01_api\01_api.json"; - string dnsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\02_dns\02_dns.json"; - string routingConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\03_routing\03_routing.json"; - string policyConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\04_policy\04_policy.json"; - string inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\05_inbounds.json"; - string outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\06_outbounds\06_outbounds.json"; - string transportConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\07_transport\07_transport.json"; - string statsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\08_stats\08_stats.json"; - string reverseConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\09_reverse\09_reverse.json"; - string baseConfigJson = $"{pwdir}" + @"TemplateConfg\xray\base.json"; - - //配置文件模块合成 - using (StreamReader reader = File.OpenText(baseConfigJson)) - { - JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - //读取"log" - using (StreamReader readerJson = File.OpenText(logConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["log"] = jObjectJson["log"]; - } - //读取"api" - using (StreamReader readerJson = File.OpenText(apiConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["api"] = jObjectJson["api"]; - } - //读取"dns" - using (StreamReader readerJson = File.OpenText(dnsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["dns"] = jObjectJson["dns"]; - } - //读取"routing" - using (StreamReader readerJson = File.OpenText(routingConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["routing"] = jObjectJson["routing"]; - } - //读取"policy" - using (StreamReader readerJson = File.OpenText(policyConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["policy"] = jObjectJson["policy"]; - } - //读取"inbounds" - using (StreamReader readerJson = File.OpenText(inboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["inbounds"] = jObjectJson["inbounds"]; - } - //读取"outbounds" - using (StreamReader readerJson = File.OpenText(outboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["outbounds"] = jObjectJson["outbounds"]; - } - //读取"transport" - using (StreamReader readerJson = File.OpenText(transportConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["transport"] = jObjectJson["transport"]; - } - //读取"stats" - using (StreamReader readerJson = File.OpenText(statsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["stats"] = jObjectJson["stats"]; - } - //读取"reverse" - using (StreamReader readerJson = File.OpenText(reverseConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - serverJson["reverse"] = jObjectJson["reverse"]; - } - - //依据安装模式读取相应模板 - if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\tcp_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\tcp_http_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\tcp_TLS_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\tcpTLSselfSigned_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\vless_tcp_xtls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\vless_tcp_tls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\vless_ws_tls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\vless_http2_tls_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\vless_vmess_xtls_tcp_websocket_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\webSocket_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\WebSocket_TLS_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\WebSocketTLS_selfSigned_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\WebSocketTLSWeb_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\http2_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\Http2Web_server_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\Http2selfSigned_server_config.json"; - } - //else if (String.Equals(ReceiveConfigurationParameters[0], "MkcpNone")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2SRTP")||String.Equals(ReceiveConfigurationParameters[0], "mKCPuTP")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WechatVideo")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2DTLS")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - if (mKCPvlessIsSet == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\vless_mkcp_server_config.json"; - } - else - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\mkcp_server_config.json"; - } - - } - - // else if (String.Equals(ReceiveConfigurationParameters[0], "QuicNone") || String.Equals(ReceiveConfigurationParameters[0], "QuicSRTP") || String.Equals(ReceiveConfigurationParameters[0], "Quic2uTP") || String.Equals(ReceiveConfigurationParameters[0], "QuicWechatVideo") || String.Equals(ReceiveConfigurationParameters[0], "QuicDTLS") || String.Equals(ReceiveConfigurationParameters[0], "QuicWireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\quic_server_config.json"; - } - - //读取"inbounds" - using (StreamReader readerJson = File.OpenText(inboundsConfigJson)) - { - JObject jObjectJsonTmp = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - var jObjectJson = (dynamic)jObjectJsonTmp; - - //Padavan路由固件服务端设置(因为客户端分流有问题所以在服务端弥补)加上后会影响一定的速度 - - //string sniffingAddServer = $"{pwdir}" + @"TemplateConfg\xray\server\05_inbounds\00_padavan_router.json"; - //using (StreamReader readerSniffingJson = File.OpenText(sniffingAddServer)) - //{ - // JObject jObjectSniffingJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerSniffingJson)); - // jObjectJson["inbounds"][0]["sniffing"] = jObjectSniffingJson["sniffing"]; - //} - - //设置uuid - jObjectJson["inbounds"][0]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - - //除WebSocketTLSWeb/http2Web/VLESS+WebSocket+TLS+Web/VLESS+http2+TLS+Web模式外设置监听端口 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == false - && String.Equals(ReceiveConfigurationParameters[0], "http2Web") == false - && String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == false - && String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == false) - { - jObjectJson["inbounds"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - } - - //设置VLESS协议的回落端口,指向Caddy - if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - //设置Caddy随机监听的端口 - randomCaddyListenPort = GetRandomPort(); - - //指向Caddy监听的随机端口 - jObjectJson["inbounds"][0]["settings"]["fallbacks"][0]["dest"] = randomCaddyListenPort; - } - //设置VLESS+VMESS+Trojan+XTLS+TCP+WebSocket+Web协议 - if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == true) - { - //设置Caddy随机监听的端口 - randomCaddyListenPort = GetRandomPort(); - - //指向Caddy监听的随机端口 - jObjectJson["inbounds"][1]["settings"]["fallbacks"][0]["dest"] = randomCaddyListenPort; - //设置其他模式的UUID - jObjectJson["inbounds"][1]["settings"]["clients"][0]["password"] = ReceiveConfigurationParameters[2]; - jObjectJson["inbounds"][2]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["inbounds"][3]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["inbounds"][4]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - - //设置Vless回落与分流的Path - jObjectJson["inbounds"][0]["settings"]["fallbacks"][1]["path"] = ReceiveConfigurationParameters[3]; - jObjectJson["inbounds"][0]["settings"]["fallbacks"][2]["path"] = ReceiveConfigurationParameters[9]; - jObjectJson["inbounds"][0]["settings"]["fallbacks"][3]["path"] = ReceiveConfigurationParameters[6]; - - //设置Vless ws Path - jObjectJson["inbounds"][2]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[3]; - //设置Vmess tcp Path - jObjectJson["inbounds"][3]["streamSettings"]["tcpSettings"]["header"]["request"]["path"][0] = ReceiveConfigurationParameters[9]; - //设置Vmess ws Path - jObjectJson["inbounds"][4]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - - } - - //TLS自签证书/WebSocketTLS(自签证书)/http2自签证书模式下,使用v2ctl 生成自签证书 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - string selfSignedCa = client.RunCommand("/usr/local/bin/xray tls cert --ca").Result; - JObject selfSignedCaJObject = JObject.Parse(selfSignedCa); - jObjectJson["inbounds"][0]["streamSettings"]["tlsSettings"]["certificates"][0] = selfSignedCaJObject; - } - - //如果是WebSocketTLSWeb/WebSocketTLS/WebSocketTLS(自签证书)/VLESS+WebSocket+TLS+Web模式,则设置路径 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //如果是Http2/http2Web/http2自签/VLESS+http2+TLS+Web模式下,设置路径 - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["httpSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //如果是Http2+Web/VLESS+http2+TLS+Web模式下,设置host - if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["httpSettings"]["host"][0] = ReceiveConfigurationParameters[4]; - } - - //mkcp模式下,设置伪装类型 - if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["kcpSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[6]) == false) - { - jObjectJson["inbounds"][0]["streamSettings"]["kcpSettings"]["seed"] = ReceiveConfigurationParameters[6]; - } - } - - //quic模式下设置伪装类型及密钥 - if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - jObjectJson["inbounds"][0]["streamSettings"]["quicSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - jObjectJson["inbounds"][0]["streamSettings"]["quicSettings"]["security"] = ReceiveConfigurationParameters[3]; - - if (String.Equals(ReceiveConfigurationParameters[3], "none") == true) - { - ReceiveConfigurationParameters[6] = ""; - } - jObjectJson["inbounds"][0]["streamSettings"]["quicSettings"]["key"] = ReceiveConfigurationParameters[6]; - } - - serverJson["inbounds"] = jObjectJson["inbounds"]; - } - - using (StreamWriter sw = new StreamWriter(@"config.json")) - { - sw.Write(serverJson.ToString()); - } - } - SetUpProgressBarProcessing(46); - return true; - } - - //安装证书到Xray 58--60 - //functionResult = CertInstallToXray(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool CertInstallToXray(SshClient client) - { - //****** "安装证书到Xray......" ******26 - SetUpProgressBarProcessing(58); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoft").ToString() + "Xray......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mkdir -p /usr/local/etc/xray/ssl"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/xray/ssl/xray_ssl.crt --keypath /usr/local/etc/xray/ssl/xray_ssl.key --capath /usr/local/etc/xray/ssl/xray_ssl.crt --reloadcmd \"systemctl restart xray\""; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"if [ ! -f ""/usr/local/etc/xray/ssl/xray_ssl.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("1") == true) - { - //****** "证书成功安装到Xray!" ******27 - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftOK").ToString() + "Xray!"; - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "证书安装到Xray失败,原因未知,可以向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftFail").ToString() + - "Xray" + - Application.Current.FindResource("DisplayInstallInfo_InstallCertFailAsk").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - } - - //设置私钥权限 - sshShellCommand = @"chmod 644 /usr/local/etc/xray/ssl/xray_ssl.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - return true; - } - - //生成Xray客户端配置 96--98 - //functionResult = GenerateClientConfiguration(); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool GenerateClientConfigurationXray() - { - //****** "生成客户端配置......" ******39 - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - string logConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\00_log\00_log.json"; - string apiConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\01_api\01_api.json"; - string dnsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\02_dns\02_dns.json"; - string routingConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\03_routing\03_routing.json"; - string policyConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\04_policy\04_policy.json"; - string inboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\05_inbounds\05_inbounds.json"; - string outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\06_outbounds.json"; - string transportConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\07_transport\07_transport.json"; - string statsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\08_stats\08_stats.json"; - string reverseConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\09_reverse\09_reverse.json"; - string baseConfigJson = $"{pwdir}" + @"TemplateConfg\xray\base.json"; - //Thread.Sleep(1000); - if (!Directory.Exists("xray_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("xray_config");//创建该文件夹   - } - - using (StreamReader reader = File.OpenText(baseConfigJson)) - { - JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - //读取"log" - using (StreamReader readerJson = File.OpenText(logConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["log"] = jObjectJson["log"]; - } - //读取"api" - using (StreamReader readerJson = File.OpenText(apiConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["api"] = jObjectJson["api"]; - } - //读取"dns" - using (StreamReader readerJson = File.OpenText(dnsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["dns"] = jObjectJson["dns"]; - } - //读取"routing" - using (StreamReader readerJson = File.OpenText(routingConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["routing"] = jObjectJson["routing"]; - } - //读取"policy" - using (StreamReader readerJson = File.OpenText(policyConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["policy"] = jObjectJson["policy"]; - } - //读取"inbounds" - using (StreamReader readerJson = File.OpenText(inboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["inbounds"] = jObjectJson["inbounds"]; - } - //读取"outbounds" - using (StreamReader readerJson = File.OpenText(outboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["outbounds"] = jObjectJson["outbounds"]; - } - //读取"transport" - using (StreamReader readerJson = File.OpenText(transportConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["transport"] = jObjectJson["transport"]; - } - //读取"stats" - using (StreamReader readerJson = File.OpenText(statsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["stats"] = jObjectJson["stats"]; - } - //读取"reverse" - using (StreamReader readerJson = File.OpenText(reverseConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - clientJson["reverse"] = jObjectJson["reverse"]; - } - - //根据不同的安装方案,选择相应的客户端模板 - if (String.Equals(ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == false) - { - #region 单模式方案 - //根据选择的不同模式,选择相应的配置文件 - if (String.Equals(ReceiveConfigurationParameters[0], "TCP") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\tcp_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TCPhttp") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\tcp_http_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\tcp_TLS_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\tcpTLSselfSigned_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_tcp_xtls_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_tcp_tls_caddy_cilent_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_ws_tls_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_http2_tls_server_config.json"; - } - - else if (String.Equals(ReceiveConfigurationParameters[0], "webSocket") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\webSocket_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\WebSocket_TLS_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\WebSocketTLS_selfSigned_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\WebSocketTLSWeb_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\http2_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\Http2Web_client_config.json"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\Http2selfSigned_client_config.json"; - } - //else if (String.Equals(ReceiveConfigurationParameters[0], "MkcpNone")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2SRTP")||String.Equals(ReceiveConfigurationParameters[0], "mKCPuTP")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WechatVideo")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2DTLS")|| String.Equals(ReceiveConfigurationParameters[0], "mKCP2WireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - if (mKCPvlessIsSet == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_mkcp_client_config.json"; - } - else - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\mkcp_client_config.json"; - } - - } - // else if (String.Equals(ReceiveConfigurationParameters[0], "QuicNone") || String.Equals(ReceiveConfigurationParameters[0], "QuicSRTP") || String.Equals(ReceiveConfigurationParameters[0], "Quic2uTP") || String.Equals(ReceiveConfigurationParameters[0], "QuicWechatVideo") || String.Equals(ReceiveConfigurationParameters[0], "QuicDTLS") || String.Equals(ReceiveConfigurationParameters[0], "QuicWireGuard")) - else if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - outboundsConfigJson = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\quic_client_config.json"; - } - - - //读取"相应模板的outbounds" - using (StreamReader readerJson = File.OpenText(outboundsConfigJson)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - - - //设置WebSocket模式下的path - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //设置http2模式下的path - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "http2selfSigned") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["httpSettings"]["path"] = ReceiveConfigurationParameters[6]; - } - - //设置http2+TLS+Web/VLESS+http2+TLS+Web模式下的host - if (String.Equals(ReceiveConfigurationParameters[0], "http2Web") == true - || String.Equals(ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["httpSettings"]["host"][0] = ReceiveConfigurationParameters[4]; - } - - //设置VLESS+TCP+XTLS+Web模式下的serverName - //if (String.Equals(ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - //{ - // jObjectJson["outbounds"][0]["streamSettings"]["xtlsSettings"]["serverName"] = ReceiveConfigurationParameters[4]; - //} - - //设置mkcp - if (ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["kcpSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[6]) == false) - { - jObjectJson["outbounds"][0]["streamSettings"]["kcpSettings"]["seed"] = ReceiveConfigurationParameters[6]; - } - } - - //设置QUIC - if (ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - jObjectJson["outbounds"][0]["streamSettings"]["quicSettings"]["header"]["type"] = ReceiveConfigurationParameters[5]; - jObjectJson["outbounds"][0]["streamSettings"]["quicSettings"]["security"] = ReceiveConfigurationParameters[3]; - if (String.Equals(ReceiveConfigurationParameters[3], "none") == true) - { - ReceiveConfigurationParameters[6] = ""; - } - jObjectJson["outbounds"][0]["streamSettings"]["quicSettings"]["key"] = ReceiveConfigurationParameters[6]; - } - - clientJson["outbounds"] = jObjectJson["outbounds"]; - - } - - using (StreamWriter sw = new StreamWriter(@"xray_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - - #endregion - - } - else - { - //复合方案所需要的配置文件 - //VLESS over TCP with XTLS模式 - string outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_tcp_xtls_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"xray_config\vless_tcp_xtls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"xray_config\vless_tcp_xtls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"xray_config\vless_tcp_xtls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VLESS over TCP with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_tcp_tls_caddy_cilent_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"xray_config\vless_tcp_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"xray_config\vless_tcp_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"xray_config\vless_tcp_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VLESS over WS with TLS 模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vless_ws_tls_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[3]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"xray_config\vless_ws_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"xray_config\vless_ws_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"xray_config\vless_ws_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VMess over TCP with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\vmess_tcp_tls_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["tcpSettings"]["header"]["request"]["path"][0] = ReceiveConfigurationParameters[9]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"xray_config\vmess_tcp_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"xray_config\vmess_tcp_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"xray_config\vmess_tcp_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //VMess over WS with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\WebSocketTLSWeb_client_config.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[6]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"xray_config\vmess_ws_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"xray_config\vmess_ws_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"xray_config\vmess_ws_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //Trojan over TCP with TLS模式 - outboundsConfigJsons = $"{pwdir}" + @"TemplateConfg\xray\client\06_outbounds\trojan_tcp_tls.json"; - using (StreamReader readerJson = File.OpenText(outboundsConfigJsons)) - { - JObject jObjectJson = (JObject)JToken.ReadFrom(new JsonTextReader(readerJson)); - - //设置客户端的地址/端口/id - jObjectJson["outbounds"][0]["settings"]["servers"][0]["address"] = ReceiveConfigurationParameters[4]; - jObjectJson["outbounds"][0]["settings"]["servers"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); - jObjectJson["outbounds"][0]["settings"]["servers"][0]["password"] = ReceiveConfigurationParameters[2]; - jObjectJson["outbounds"][0]["streamSettings"]["tlsSettings"]["serverName"] = ReceiveConfigurationParameters[4]; - - clientJson["outbounds"] = jObjectJson["outbounds"]; - if (!Directory.Exists(@"xray_config\trojan_tcp_tls_client_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory(@"xray_config\trojan_tcp_tls_client_config");//创建该文件夹   - } - using (StreamWriter sw = new StreamWriter(@"xray_config\trojan_tcp_tls_client_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - } - } - SetUpProgressBarProcessing(98); - return true; - } - - - #endregion - - //检测升级远程主机端的Xray版本 - private void ButtonUpdateXray_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => UpdateXray(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //升级Xray主程序 - private void UpdateXray(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //******"检测系统是否已经安装Xray......"****** - SetUpProgressBarProcessing(20); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Xray......"; - MainWindowsShowInfo(currentStatus); - - //Thread.Sleep(1000); - //检测是否安装Xray - //sshShellCommand = @"find / -name xray"; - //sshShellCommand = @"if [[ -f /usr/local/bin/xray ]];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/xray") == false) - //if (currentShellCommandResult.Trim().Equals("0") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/xray"); - if (functionResult == false) - { - //******"退出!原因:远程主机未安装Xray"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_ErrorUpgradeSoftNotInstall").ToString() + "Xray!"; - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - - client.Disconnect(); - return; - - } - - //sshcmd = @"/usr/local/bin/xray -version | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"/usr/local/bin/xray -version | head -n 1 | cut -d "" "" -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string xrayCurrentVersion = currentShellCommandResult;//不含字母v - - //sshcmd = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2fly/xray-core/releases/latest"" --connect-timeout 10| grep 'tag_name' | cut -d\"" -f4"; - sshShellCommand = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -sS ""https://api.github.com/repos/XTLS/Xray-core/releases/latest"" --connect-timeout 10 | grep 'tag_name' | cut -d\"" -f4"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string xrayNewVersion = currentShellCommandResult;//包含字母v - - if (xrayNewVersion.Contains(xrayCurrentVersion) == false) - { - MessageBoxResult messageBoxResult = MessageBox.Show( - //****** "远程主机当前版本为:v" ****** - Application.Current.FindResource("DisplayInstallInfo_CurrentVersion").ToString() + - $"{xrayCurrentVersion}\n" + - //****** "最新版本为:" ****** - Application.Current.FindResource("DisplayInstallInfo_NewVersion").ToString() + - $"{xrayNewVersion}\n" + - //****** "是否升级为最新版本?" ****** - Application.Current.FindResource("DisplayInstallInfo_IsOrNoUpgradeNewVersion").ToString(), "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - //****** "正在升级到最新版本......" ****** - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartUpgradeNewVersion").ToString(); - MainWindowsShowInfo(currentStatus); - - //client.RunCommand(@"bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-xray/master/install-release.sh)"); - sshShellCommand = $"bash <(curl -L -s https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh)"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(80); - //sshcmd = @"/usr/local/bin/xray -version | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"/usr/local/bin/xray -version | head -n 1 | cut -d "" "" -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - xrayCurrentVersion = currentShellCommandResult;//不含字母v - if (xrayNewVersion.Contains(xrayCurrentVersion) == true) - { - //****** "升级成功!当前已是最新版本!" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - } - else - { - //****** "升级失败,原因未知,请向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - } - } - else - { - //****** "升级取消,退出!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeVersionCancel").ToString(); - MainWindowsShowInfo(currentStatus); - - client.Disconnect(); - return; - } - } - else - { - //****** "远程主机当前已是最新版本:" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IsNewVersion").ToString() + - $"{xrayNewVersion}\n" + - //****** "无需升级!退出!" ****** - Application.Current.FindResource("DisplayInstallInfo_NotUpgradeVersion").ToString(); - MessageBox.Show(currentStatus); - MainWindowsShowInfo(currentStatus); - } - - client.Disconnect(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - #endregion - - #region Trojan-go相关 - - //打开设置TrojanGo参数窗口 - private void ButtonTrojanGoTemplate_Click(object sender, RoutedEventArgs e) - { - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - TrojanGoTemplateWindow windowTrojanGoTemplateConfiguration = new TrojanGoTemplateWindow(); - windowTrojanGoTemplateConfiguration.Closed += windowTrojanGoTemplateConfigurationClosed; - windowTrojanGoTemplateConfiguration.ShowDialog(); - } - //TrojanGo模板设置窗口关闭后,触发事件,将所选的方案与其参数显示在UI上 - private void windowTrojanGoTemplateConfigurationClosed(object sender, System.EventArgs e) - { - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //显示"未选择方案!" - TextBlockCurrentlySelectedPlan.Text = Application.Current.FindResource("TextBlockCurrentlySelectedPlanNo").ToString(); - - TextBlockTrojanGoShowPort.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanPort.Visibility = Visibility.Hidden; - - TextBlockTrojanGoShowPassword.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanPassword.Visibility = Visibility.Hidden; - - TextBlockTrojanGoShowPath.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanPathSeedKey.Visibility = Visibility.Hidden; - - TextBlockTrojanGoShowCurrentlySelectedPlanDomain.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanDomain.Visibility = Visibility.Hidden; - - TextBlockTrojanGoShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - return; - } - TextBlockTrojanGoCurrentlySelectedPlan.Text = ReceiveConfigurationParameters[8]; //所选方案名称 - TextBlockTrojanGoCurrentlySelectedPlanPort.Text = ReceiveConfigurationParameters[1]; //服务器端口 - TextBlockTrojanGoCurrentlySelectedPlanPassword.Text = ReceiveConfigurationParameters[2]; //UUID - TextBlockTrojanGoCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - TextBlockTrojanGoCurrentlySelectedPlanDomain.Text = ReceiveConfigurationParameters[4]; //域名 - TextBlockTrojanGoCurrentlySelectedPlanFakeWebsite.Text = ReceiveConfigurationParameters[7]; //伪装网站 - - if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoTLS2Web")) - { - TextBlockTrojanGoShowPort.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanPort.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowPassword.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanPassword.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowPath.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanPathSeedKey.Visibility = Visibility.Hidden; - - TextBlockTrojanGoShowCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) - { - TextBlockTrojanGoShowPort.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanPort.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowPassword.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanPassword.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowPath.Text = "WebSocket Path:"; - TextBlockTrojanGoCurrentlySelectedPlanPathSeedKey.Text = ReceiveConfigurationParameters[6]; //mKCP Seed\Quic Key\Path - - - TextBlockTrojanGoShowPath.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanPathSeedKey.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - TextBlockTrojanGoCurrentlySelectedPlanDomain.Visibility = Visibility.Visible; - - TextBlockTrojanGoShowCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - TextBlockTrojanGoCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - } - - } - - //传递TrojanGo参数 - private void ButtonTrojanGoSetUp_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //******"请先选择配置模板!"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ChooseTemplate").ToString()); - return; - } - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[4]) == true) - { - //****** "域名不能为空,请检查相关参数设置!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - return; - } - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartSetUpTrojanGo(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //登录远程主机布署Trojan-Go程序 - private void StartSetUpTrojanGo(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "trojan-go", @"/usr/local/bin/trojan-go"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl)11--30 - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测域名是否解析到当前IP上 34---36 - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //下载脚本安装Trojan-go 37--40 - functionResult = ProxySoftInstall(client, @"Trojan-go", @"https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - //functionResult = TrojanGoInstall(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "trojan-go", @"/usr/local/bin/trojan-go"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //生成Trojan-go服务端配置 44--46 - functionResult = GenerateServerConfigurationTrojanGo(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //上传配置文件 - string upLoadPath = "/usr/local/etc/trojan-go/config.json"; - UploadConfig(connectionInfo, @"config.json", upLoadPath); - File.Delete(@"config.json"); - - //acme.sh安装与申请证书 51--57 - functionResult = AcmeShInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //****** "安装证书到Trojan-go......" ****** - SetUpProgressBarProcessing(58); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoft").ToString() + "Trojan-go......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan-go/trojan-go.crt --keypath /usr/local/etc/trojan-go/trojan-go.key --capath /usr/local/etc/trojan-go/trojan-go.crt --reloadcmd \"systemctl restart trojan-go\""; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"if [ ! -f ""/usr/local/etc/trojan-go/trojan-go.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("1") == true) - { - //****** "证书成功安装到Trojan-go!" ****** - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftOK").ToString() + "Trojan-go!"; - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "证书安装到Trojan-go失败,原因未知,可以向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftFail").ToString() + - "Trojan-go" + - Application.Current.FindResource("DisplayInstallInfo_InstallCertFailAsk").ToString(); - MainWindowsShowInfo(currentStatus); - client.Disconnect(); - return; - } - - //设置证书权限 - sshShellCommand = @"chmod 644 /usr/local/etc/trojan-go/trojan-go.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //Caddy安装与检测安装是否成功 61--66 - functionResult = CaddyInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //****** "上传Caddy配置文件......" ****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string caddyConfig = $"{pwdir}" + @"TemplateConfg\trojan-go\trojan-go.caddyfile"; - - upLoadPath = "/etc/caddy/Caddyfile"; - UploadConfig(connectionInfo, caddyConfig, upLoadPath); - - //设置Caddy配置文件 - functionResult = SetCaddyfile(client, upLoadPath); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //****** "Caddy配置文件上传成功,OK!" ****** - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //程序启动检测Caddy - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序启动检测Trojan-go - functionResult = SoftStartDetect(client, "trojan-go", @"/usr/local/bin/trojan-go"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测BBR,满足条件并启动 90--95 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - - //****** "生成客户端配置......" ****** - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - if (!Directory.Exists("trojan-go_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("trojan-go_config");//创建该文件夹   - } - - string clientConfig = $"{pwdir}" + @"TemplateConfg\trojan-go\trojan-go_all_config.json"; //生成的客户端配置文件 - - using (StreamReader reader = File.OpenText(clientConfig)) - { - JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - clientJson["run_type"] = "client"; - clientJson["local_addr"] = "127.0.0.1"; - clientJson["local_port"] = 1080; - clientJson["remote_addr"] = ReceiveConfigurationParameters[4]; - clientJson["remote_port"] = 443; - //设置密码 - clientJson["password"][0] = ReceiveConfigurationParameters[2]; - clientJson["ssl"]["sni"] = ReceiveConfigurationParameters[4]; - //如果是WebSocket协议则设置路径 - if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) - { - clientJson["websocket"]["enabled"] = true; - clientJson["websocket"]["path"] = ReceiveConfigurationParameters[6]; - clientJson["websocket"]["host"] = ReceiveConfigurationParameters[4]; - } - //如果开启了mux,设置客户端配置文件参数 - if (String.Equals(ReceiveConfigurationParameters[9], "true") == true) - { - clientJson["mux"]["enabled"] = true; - clientJson["mux"]["concurrency"] = int.Parse(ReceiveConfigurationParameters[3]); - clientJson["mux"]["idle_timeout"] = int.Parse(ReceiveConfigurationParameters[5]); - //if(int.TryParse(ReceiveConfigurationParameters[3],out int value) == true) - //{ - // clientJson["mux"]["concurrency"] = value; - //} - //if (int.TryParse(ReceiveConfigurationParameters[5], out int value2) == true) - //{ - // clientJson["mux"]["idle_timeout"] = value2; - //} - //clientJson["mux"]["idle_timeout"] = int.TryParse(ReceiveConfigurationParameters[5], out int value2); - //clientJson["mux"]["idle_timeout"] = value2; - } - - using (StreamWriter sw = new StreamWriter(@"trojan-go_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //****** "Trojan-go安装成功,祝你玩的愉快!!" ****** - SetUpProgressBarProcessing(100); - currentStatus = "Trojan-go" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示服务端连接参数 - proxyType = "TrojanGo"; - - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //下载脚本安装Trojan-go 37--40 - //functionResult = TrojanGoInstall(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - //private bool TrojanGoInstall(SshClient client) - //{ - // //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - // SetUpProgressBarProcessing(37); - // currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - // MainWindowsShowInfo(currentStatus); - - // //****** "正在安装Trojan-go......" ****** - // SetUpProgressBarProcessing(38); - // currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + "Trojan-go......"; - // MainWindowsShowInfo(currentStatus); - - // sshShellCommand = $"curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; - // currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - // functionResult = FileCheckExists(client, @"/tmp/trojan-go.sh"); - // if (functionResult == true) - // { - // sshShellCommand = @"yes | bash /tmp/trojan-go.sh -f"; - // currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - // sshShellCommand = @"rm -f /tmp/trojan-go.sh"; - // currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - // } - // else - // { - // //***安装脚本下载失败!*** - // currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - // MainWindowsShowInfo(currentStatus); - // return false; - // } - - - // SetUpProgressBarProcessing(40); - // return true; - //} - - //生成Trojan-go服务端配置 44--46 - //functionResult = GenerateServerConfigurationTrojanGo(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool GenerateServerConfigurationTrojanGo(SshClient client) - { - //备份原配置文件 - sshShellCommand = @"mv /etc/trojan-go/config.json /etc/trojan-go/config.json.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //****** "安装完毕,上传配置文件......" ****** - SetUpProgressBarProcessing(44); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - string serverConfig = $"{pwdir}" + @"TemplateConfg\trojan-go\trojan-go_all_config.json"; //服务端配置文件 - //string upLoadPath = @"/usr/local/etc/trojan-go/config.json"; //服务端文件位置 - - //生成服务端配置 - using (StreamReader reader = File.OpenText(serverConfig)) - { - //设置Caddy随机监听的端口,用于Trojan-go,Trojan,V2Ray vless TLS - //Random random = new Random(); - randomCaddyListenPort = GetRandomPort(); - - JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - serverJson["run_type"] = "server"; - serverJson["local_addr"] = "0.0.0.0"; - serverJson["local_port"] = 443; - serverJson["remote_addr"] = "127.0.0.1"; - serverJson["remote_port"] = randomCaddyListenPort; - //设置密码 - serverJson["password"][0] = ReceiveConfigurationParameters[2]; - //设置证书 - serverJson["ssl"]["cert"] = "/usr/local/etc/trojan-go/trojan-go.crt"; - serverJson["ssl"]["key"] = "/usr/local/etc/trojan-go/trojan-go.key"; - serverJson["ssl"]["sni"] = ReceiveConfigurationParameters[4]; - - if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) - { - serverJson["websocket"]["enabled"] = true; - serverJson["websocket"]["path"] = ReceiveConfigurationParameters[6]; - serverJson["websocket"]["host"] = ReceiveConfigurationParameters[4]; - } - - using (StreamWriter sw = new StreamWriter(@"config.json")) - { - sw.Write(serverJson.ToString()); - } - } - - - SetUpProgressBarProcessing(46); - return true; - } - - - //检测升级Trojan-Go版本传递参数 - private void ButtonUpdateTrojanGo_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - installationDegree = 0; - Thread thread = new Thread(() => UpdateTojanGo(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //升级Trojan-go主程序 - private void UpdateTojanGo(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //******"检测系统是否已经安装Trojan-go......"****** - SetUpProgressBarProcessing(20); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Trojan-go......"; - MainWindowsShowInfo(currentStatus); - - //string cmdTestTrojanInstalled = @"find / -name trojan-go"; - - //sshShellCommand = @"find / -name trojan-go"; - //sshShellCommand = @"if [[ -f /usr/local/bin/trojan-go ]];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/trojan-go") == false) - //if (currentShellCommandResult.Trim().Equals("0") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/trojan-go"); - if (functionResult == false) - { - //******"退出!原因:远程主机未安装Trojan-go"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_ErrorUpgradeSoftNotInstall").ToString() + "Trojan-go!"; - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - - } - SetUpProgressBarProcessing(40); - //获取当前安装的版本 - //string sshcmd = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - string trojanCurrentVersion = currentShellCommandResult;//含字母v - - //获取最新版本 - //sshcmd = @"curl -s https://api.github.com/repos/p4gefau1t/trojan-go/tags | grep 'name' | cut -d\"" -f4 | head -1"; - sshShellCommand = @"curl -s https://api.github.com/repos/p4gefau1t/trojan-go/tags | grep 'name' | cut -d\"" -f4 | head -1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - string trojanNewVersion = currentShellCommandResult;//含字母v - - if (trojanNewVersion.Equals(trojanCurrentVersion) == false) - { - MessageBoxResult messageBoxResult = MessageBox.Show( - //****** "远程主机当前版本为:v" ****** - Application.Current.FindResource("DisplayInstallInfo_CurrentVersion").ToString() + - $"{trojanCurrentVersion}\n" + - //****** "最新版本为:" ****** - Application.Current.FindResource("DisplayInstallInfo_NewVersion").ToString() + - $"{trojanNewVersion}\n" + - //****** "是否升级为最新版本?" ****** - Application.Current.FindResource("DisplayInstallInfo_IsOrNoUpgradeNewVersion").ToString(), "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - //****** "正在升级到最新版本......" ****** - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartUpgradeNewVersion").ToString(); - MainWindowsShowInfo(currentStatus); - - //备份配置文件 - //sshcmd = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; - //client.RunCommand(sshcmd); - //升级Trojan-Go主程序 - //client.RunCommand("curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"); - //client.RunCommand("yes | bash /tmp/trojan-go.sh -f"); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(80); - - //获取升级后的版本 - //sshcmd = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - trojanCurrentVersion = currentShellCommandResult;//含字母v - if (trojanNewVersion.Equals(trojanCurrentVersion) == true) - { - //恢复原来的配置文件备份 - //sshcmd = @"rm -f /usr/local/etc/trojan/config.json"; - //client.RunCommand(sshcmd); - //sshcmd = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; - //client.RunCommand(sshcmd); - - //****** "升级成功!当前已是最新版本!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString()); - //****** "升级成功!当前已是最新版本!" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "升级失败,原因未知,请向开发者提问!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString()); - //****** "升级失败,原因未知,请向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString(); - MainWindowsShowInfo(currentStatus); - - client.Disconnect(); - return; - } - } - - else - { - //****** "升级取消,退出!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeVersionCancel").ToString(); - MainWindowsShowInfo(currentStatus); - - client.Disconnect(); - return; - } - } - else - { - //****** "远程主机当前已是最新版本:" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IsNewVersion").ToString() + - $"{trojanNewVersion}\n" + - //****** "无需升级!退出!" ****** - Application.Current.FindResource("DisplayInstallInfo_NotUpgradeVersion").ToString(); - MessageBox.Show(currentStatus); - MainWindowsShowInfo(currentStatus); - } - - client.Disconnect(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - #endregion - - #region Trojan相关 - - //Trojan参数传递 - private void ButtonTrojanSetUp_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - //清空参数空间 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - bool preDomainMask = ClassModel.PreDomainMask(TextBoxTrojanSites.Text); - bool domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxTrojanHostDomain.Text); - //if (string.IsNullOrEmpty(PreTrim(TextBoxTrojanHostDomain.Text)) == true) - //{ - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return; - //} - if (domainNotEmpty == false || preDomainMask == false) - { - return; - } - //传递模板类型 - ReceiveConfigurationParameters[0] = "TrojanTLS2Web"; - - //传递域名 - ReceiveConfigurationParameters[4] = PreTrim(TextBoxTrojanHostDomain.Text); - //传递伪装网站 - ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxTrojanSites.Text)); - - //传递服务端口 - ReceiveConfigurationParameters[1] = "443"; - //传递密码(uuid) - ReceiveConfigurationParameters[2] = TextBoxTrojanPassword.Text.ToString(); - - //启动布署进程 - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartSetUpTrojan(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //登录远程主机布署Trojan程序 - private void StartSetUpTrojan(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "trojan", @"/usr/local/bin/trojan"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl)11--30 - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //检测是否为64位系统 - sshShellCommand = @"uname -m"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - string resultCmd = currentShellCommandResult; - if (resultCmd.Contains("x86_64") == false) - { - //******"请在x86_64系统中安装Trojan" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_PleaseInstallSoftAtX64").ToString() + "NaiveProxy......"); - //****** "系统环境不满足要求,安装失败!!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_MissingSystemComponents").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - //检测域名是否解析到当前IP上 34---36 - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //下载安装脚本安装 37-40 - functionResult = ProxySoftInstall(client, @"Trojan", @"https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - ////****** "正在安装Trojan......" ****** - //SetUpProgressBarProcessing(37); - //currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + "Trojan......"; - //MainWindowsShowInfo(currentStatus); - - //sshShellCommand = $"curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"yes | bash /tmp/trojan-quickstart.sh"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"rm -f /tmp/trojan-quickstart.sh"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "trojan", @"/usr/local/bin/trojan"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "安装完毕,上传配置文件......" ****** - SetUpProgressBarProcessing(44); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string serverConfig = $"{pwdir}" + @"TemplateConfg\trojan\trojan_server_config.json"; //服务端配置文件 - string upLoadPath = @"/usr/local/etc/trojan/config.json"; //服务端文件位置 - - //生成服务端配置 - using (StreamReader reader = File.OpenText(serverConfig)) - { - JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - //设置密码 - serverJson["password"][0] = ReceiveConfigurationParameters[2]; - - //设置Caddy随机监听的端口,用于Trojan-go,Trojan,V2Ray vless TLS - //Random random = new Random(); - randomCaddyListenPort = GetRandomPort(); - - //设置转发到Caddy的随机监听端口 - serverJson["remote_port"] = randomCaddyListenPort; - - using (StreamWriter sw = new StreamWriter(@"config.json")) - { - sw.Write(serverJson.ToString()); - } - } - UploadConfig(connectionInfo, @"config.json", upLoadPath); - - File.Delete(@"config.json"); - - //acme.sh安装与申请证书 51--57 - functionResult = AcmeShInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "安装证书到Trojan......" ****** - SetUpProgressBarProcessing(58); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoft").ToString() + "Trojan......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan/trojan_ssl.crt --keypath /usr/local/etc/trojan/trojan_ssl.key --capath /usr/local/etc/trojan/trojan_ssl.crt --reloadcmd \"systemctl restart trojan\""; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"if [ ! -f ""/usr/local/etc/trojan/trojan_ssl.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("1") == true) - { - //****** "证书成功安装到Trojan!" ****** - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftOK").ToString() + "Trojan!"; - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "证书安装到Trojan失败,原因未知,可以向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftFail").ToString() + - "Trojan" + - Application.Current.FindResource("DisplayInstallInfo_InstallCertFailAsk").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - //设置证书权限 - sshShellCommand = @"chmod 644 /usr/local/etc/trojan/trojan_ssl.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //Caddy安装 61--66 - functionResult = CaddyInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "上传Caddy配置文件......" ****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string caddyConfig = $"{pwdir}" + @"TemplateConfg\trojan\trojan.caddyfile"; - upLoadPath = @"/etc/caddy/Caddyfile"; - - UploadConfig(connectionInfo, caddyConfig, upLoadPath); - - //设置Caddy配置文件 - functionResult = SetCaddyfile(client, upLoadPath); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "Caddy配置文件上传成功,OK!" ****** - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //程序启动检测Caddy - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序启动检测Trojan - functionResult = SoftStartDetect(client, "trojan", @"/usr/local/bin/trojan"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测BBR,满足条件并启动 90--95 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - //****** "生成客户端配置......" ****** - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - if (!Directory.Exists("trojan_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("trojan_config");//创建该文件夹   - } - - string clientConfig = $"{pwdir}" + @"TemplateConfg\trojan\trojan_client_config.json"; //生成的客户端配置文件 - using (StreamReader reader = File.OpenText(clientConfig)) - { - JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - - clientJson["remote_addr"] = ReceiveConfigurationParameters[4]; - clientJson["remote_port"] = int.Parse(ReceiveConfigurationParameters[1]); - clientJson["password"][0] = ReceiveConfigurationParameters[2]; - - using (StreamWriter sw = new StreamWriter(@"trojan_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - //****** "Trojan安装成功,祝你玩的愉快!!" ****** - SetUpProgressBarProcessing(100); - currentStatus = "Trojan" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示服务端连接参数 - proxyType = "Trojan"; - - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //检测升级远程主机Trojan版本传递参数 - private void ButtonUpdateTrojan_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => UpdateTojan(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //升级Trojan主程序 - private void UpdateTojan(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //******"检测系统是否已经安装Trojan......"****** - SetUpProgressBarProcessing(20); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Trojan......"; - MainWindowsShowInfo(currentStatus); - - - //string cmdTestTrojanInstalled = @"find / -name trojan"; - //string resultCmdTestTrojanInstalled = client.RunCommand(cmdTestTrojanInstalled).Result; - //sshShellCommand = @"find / -name trojan"; - //sshShellCommand = @"if [[ -f /usr/local/bin/trojan ]];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/trojan") == false) - //if (currentShellCommandResult.Trim().Equals("0") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/trojan"); - if (functionResult == false) - { - //******"退出!原因:远程主机未安装Trojan"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_ErrorUpgradeSoftNotInstall").ToString() + "Trojan!"; - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - - } - - SetUpProgressBarProcessing(40); - - //获取当前安装的版本 - //string sshcmd = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; - //string trojanCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v - sshShellCommand = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string trojanCurrentVersion = currentShellCommandResult;//不含字母v - - - //sshcmd = @"curl -fsSL https://api.github.com/repos/trojan-gfw/trojan/releases/latest | grep tag_name | sed -E 's/.*""v(.*)"".*/\1/'"; - //获取最新版本 - - sshShellCommand = @"curl -fsSL https://api.github.com/repos/trojan-gfw/trojan/releases/latest | grep tag_name | sed -E 's/.*""v(.*)"".*/\1/'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string trojanNewVersion = currentShellCommandResult;//不含字母v - - if (trojanNewVersion.Equals(trojanCurrentVersion) == false) - { - MessageBoxResult messageBoxResult = MessageBox.Show( - //****** "远程主机当前版本为:v" ****** - Application.Current.FindResource("DisplayInstallInfo_CurrentVersion").ToString() + - $"{trojanCurrentVersion}\n" + - //****** "最新版本为:" ****** - Application.Current.FindResource("DisplayInstallInfo_NewVersion").ToString() + - $"{trojanNewVersion}\n" + - //****** "是否升级为最新版本?" ****** - Application.Current.FindResource("DisplayInstallInfo_IsOrNoUpgradeNewVersion").ToString(), "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - //****** "正在升级到最新版本......" ****** - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartUpgradeNewVersion").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "备份Trojan配置文件......" ****** - SetUpProgressBarProcessing(80); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BackTrojanConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - //string sshcmd = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; - //client.RunCommand(sshcmd); - sshShellCommand = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //升级Trojan主程序 - //client.RunCommand("curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); - //client.RunCommand("yes | bash /tmp/trojan-quickstart.sh"); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshcmd = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; - sshShellCommand = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - trojanCurrentVersion = currentShellCommandResult;//不含字母v - //trojanCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v - if (trojanNewVersion.Equals(trojanCurrentVersion) == true) - { - //****** "恢复Trojan配置文件......" ****** - SetUpProgressBarProcessing(90); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_RestoreTrojanConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - //sshcmd = @"rm -f /usr/local/etc/trojan/config.json"; - //client.RunCommand(sshcmd); - sshShellCommand = @"rm -f /usr/local/etc/trojan/config.json"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshcmd = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; - //client.RunCommand(sshcmd); - sshShellCommand = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //****** "升级成功!当前已是最新版本!" ****** - SetUpProgressBarProcessing(100); - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString()); - //****** "升级成功!当前已是最新版本!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionOK").ToString(); - MainWindowsShowInfo(currentStatus); - - } - else - { - //****** "升级失败,原因未知,请向开发者提问!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString()); - //****** "升级失败,原因未知,请向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNewVersionFail").ToString(); - MainWindowsShowInfo(currentStatus); - } - } - - else - { - //****** "升级取消,退出!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeVersionCancel").ToString(); - MainWindowsShowInfo(currentStatus); - - client.Disconnect(); - return; - } - } - else - { - //****** "远程主机当前已是最新版本:" ****** - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_IsNewVersion").ToString() + - $"{trojanNewVersion}\n" + - //****** "无需升级!退出!" ****** - Application.Current.FindResource("DisplayInstallInfo_NotUpgradeVersion").ToString(); - MessageBox.Show(currentStatus); - MainWindowsShowInfo(currentStatus); - } - - client.Disconnect(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //更新Trojan的密码 - private void ButtonTrojanPassword_Click(object sender, RoutedEventArgs e) - { - TextBoxTrojanPassword.Text = RandomUUID(); - } - #endregion - - #region NaiveProxy相关 - - //NaiveProxy一键安装开始传递参数 - private void ButtonNavieSetUp_Click(object sender, RoutedEventArgs e) - { - //if (string.IsNullOrEmpty(PreTrim(TextBoxNaiveHostDomain.Text)) == true) - //{ - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return; - //} - - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - //清空参数空间 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - - bool preDomainMask = ClassModel.PreDomainMask(TextBoxNaiveSites.Text); - bool domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxNaiveHostDomain.Text); - if (domainNotEmpty == false || preDomainMask == false) - { - return; - } - //传递参数 - ReceiveConfigurationParameters[4] = PreTrim(TextBoxNaiveHostDomain.Text);//传递域名 - ReceiveConfigurationParameters[1] = "443";//传递端口 - ReceiveConfigurationParameters[3] = TextBoxNaiveUser.Text;//传递用户名 - ReceiveConfigurationParameters[2] = TextBoxNaivePassword.Text;//传递密码 - ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxNaiveSites.Text));//传递伪装网站 - - //启动布署进程 - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartSetUpNaive(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //登录远程主机布署NaiveProxy程序 - private void StartSetUpNaive(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl)11--30 - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测域名是否解析到当前IP上 34---36 - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //安装代理程序 37--40 - functionResult = ProxySoftInstall(client,@"NaiveProxy", @"https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - ////****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - //SetUpProgressBarProcessing(60); - //currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - //MainWindowsShowInfo(currentStatus); - - ////Caddy安装与检测安装是否成功 61--66 - //functionResult = CaddyInstall(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - ////使用带插件的Caddy替换 - ////****** "正在为NaiveProxy升级服务端!" ****** - ////SetUpProgressBarProcessing(76); - //currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNaiveProxy").ToString(); - //MainWindowsShowInfo(currentStatus); - - //sshShellCommand = $"curl -o /tmp/caddy.zip https://raw.githubusercontent.com/proxysu/Resources/master/Caddy2/caddy2.zip"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //functionResult = FileCheckExists(client, @"/tmp/caddy.zip"); - //if (functionResult == false) - //{ - // //***文件下载失败!*** - // currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - // MainWindowsShowInfo(currentStatus); - // return; - //} - //sshShellCommand = @"yes | unzip -o /tmp/caddy.zip"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"chmod +x ./caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"systemctl stop caddy;rm -f /usr/bin/caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"cp caddy /usr/bin/"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"rm -f /tmp/caddy.zip caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - ////****** "升级完毕,OK!" ****** - ////SetUpProgressBarProcessing(79); - //currentStatus = Application.Current.FindResource("DisplayInstallInfo_UpgradeNaiveProxyOK").ToString(); - //MainWindowsShowInfo(currentStatus); - - //****** "上传Caddy配置文件......" ****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - //生成服务端配置 - string caddyConfig = $"{pwdir}" + @"TemplateConfg\naive\naive_server.caddyfile"; - string upLoadPath = @"/etc/caddy/Caddyfile"; - UploadConfig(connectionInfo, caddyConfig, upLoadPath); - //$"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}" - //$"sed -i 's/##basicauth##/basicauth {ReceiveConfigurationParameters[3]} {ReceiveConfigurationParameters[2]}/' {upLoadPath}" - - //设置Caddy配置文件 - functionResult = SetCaddyfile(client, upLoadPath); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - sshShellCommand = $"sed -i 's/##basicauth##/basic_auth {ReceiveConfigurationParameters[3]} {ReceiveConfigurationParameters[2]}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/file_server/#file_server/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //string caddyConfig = $"{pwdir}" + @"TemplateConfg\naive\naive_server_config.json"; - //using (StreamReader reader = File.OpenText(caddyConfig)) - //{ - // JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - // serverJson["apps"]["http"]["servers"]["srv0"]["routes"][0]["handle"][0]["auth_user"] = ReceiveConfigurationParameters[3];//----用户名 - // serverJson["apps"]["http"]["servers"]["srv0"]["routes"][0]["handle"][0]["auth_pass"] = ReceiveConfigurationParameters[2]; //----密码 - - // serverJson["apps"]["http"]["servers"]["srv0"]["routes"][1]["match"][0]["host"][0] = ReceiveConfigurationParameters[4]; //----域名 - - // serverJson["apps"]["http"]["servers"]["srv0"]["tls_connection_policies"][0]["match"]["sni"][0] = ReceiveConfigurationParameters[4]; //----域名 - - // serverJson["apps"]["tls"]["automation"]["policies"][0]["subjects"][0] = ReceiveConfigurationParameters[4]; //-----域名 - // serverJson["apps"]["tls"]["automation"]["policies"][0]["issuer"]["email"] = $"user@{ReceiveConfigurationParameters[4]}"; //-----邮箱 - // //保存配置文件 - // using (StreamWriter sw = new StreamWriter(@"config.json")) - // { - // sw.Write(serverJson.ToString()); - // } - //} - //string upLoadPath = @"/etc/caddy/config.json"; - //UploadConfig(connectionInfo, @"config.json", upLoadPath); - - //File.Delete(@"config.json"); - - //****** Caddy配置文件上传成功,OK! ****** - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"sed -i 's/Caddyfile/config.json/' /lib/systemd/system/caddy.service"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"systemctl daemon-reload"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序启动检测Caddy - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - ////设置伪装网站 - //if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) - //{ - // sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - // //MessageBox.Show(sshCmd); - // client.RunCommand(sshCmd); - //} - //Thread.Sleep(2000); - - //****** "正在优化网络参数......" ****** - SetUpProgressBarProcessing(80); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_OptimizeNetwork").ToString(); - MainWindowsShowInfo(currentStatus); - - //优化网络参数 - sshShellCommand = @"bash -c 'echo ""fs.file-max = 51200"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.core.rmem_max = 67108864"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.core.wmem_max = 67108864"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.core.rmem_default = 65536"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.core.wmem_default = 65536"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.core.netdev_max_backlog = 4096"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.core.somaxconn = 4096"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_syncookies = 1"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_tw_reuse = 1"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_tw_recycle = 0"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_fin_timeout = 30"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_keepalive_time = 1200"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.ip_local_port_range = 10000 65000"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_max_syn_backlog = 4096"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_max_tw_buckets = 5000"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_rmem = 4096 87380 67108864"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_wmem = 4096 65536 67108864"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_mtu_probing = 1"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sysctl -p"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //****** "优化网络参数,OK!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_OptimizeNetworkOK").ToString(); ; - MainWindowsShowInfo(currentStatus); - - //检测BBR,满足条件并启动 90--95 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - //****** "生成客户端配置......" ****** - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - if (!Directory.Exists("naive_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("naive_config");//创建该文件夹   - } - - string clientConfig = $"{pwdir}" + @"TemplateConfg\naive\naive_client_config.json"; //生成的客户端配置文件 - using (StreamReader reader = File.OpenText(clientConfig)) - { - JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - - clientJson["proxy"] = $"https://{ReceiveConfigurationParameters[3]}:{ReceiveConfigurationParameters[2]}@{ReceiveConfigurationParameters[4]}"; - using (StreamWriter sw = new StreamWriter(@"naive_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - - //****** "NaiveProxy安装成功,祝你玩的愉快!!" ****** - SetUpProgressBarProcessing(100); - currentStatus = "NaiveProxy" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示服务端连接参数 - proxyType = "NaiveProxy"; - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //更新NaiveProxy的密码 - private void ButtonNaivePassword_Click(object sender, RoutedEventArgs e) - { - TextBoxNaivePassword.Text = RandomUUID(); - } - - //生成随机UUID - private string RandomUUID() - { - Guid uuid = Guid.NewGuid(); - //TextBoxNaivePassword.Text = uuid.ToString(); - return uuid.ToString(); - } - - //NaiveProxy产生随机用户名 - private string RandomUserName() - { - Random random = new Random(); - int randomSerialNum = random.Next(0, 4); - Guid uuid = Guid.NewGuid(); - string[] pathArray = uuid.ToString().Split('-'); - string path = pathArray[randomSerialNum]; - return path; - // TextBoxPath.Text = $"/{path}"; - //MessageBox.Show(path); - } - - //NaiveProxy更改用户名,随机方式 - private void ButtonNaiveUser_Click(object sender, RoutedEventArgs e) - { - TextBoxNaiveUser.Text = RandomUserName(); - } - - #endregion - - #region SSR+TLS+Caddy相关 - - //SSR参数传递 - private void ButtonSSRSetUp_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - //清空参数空间 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - - bool domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxSSRHostDomain.Text); - bool preDomainMask = ClassModel.PreDomainMask(TextBoxSSRSites.Text); - if (domainNotEmpty == false || preDomainMask == false) - { - return; - } - //if (string.IsNullOrEmpty(PreTrim(TextBoxSSRHostDomain.Text)) == true) - //{ - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return; - //} - - //传递域名 - ReceiveConfigurationParameters[4] = PreTrim(TextBoxSSRHostDomain.Text); - //传递伪装网站 - ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxSSRSites.Text)); - - //传递服务端口 - ReceiveConfigurationParameters[1] = "443"; - //传递密码(uuid) - ReceiveConfigurationParameters[2] = TextBoxSSRPassword.Text.ToString(); - - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartSetUpSSR(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //登录远程主机布署SSR+TLS+Caddy程序 - private void StartSetUpSSR(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "server.py", @"/usr/local/shadowsocks/server.py"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl)11--30 - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测域名是否解析到当前IP上 34---36 - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //下载脚本安装SSR 37--40 - functionResult = ProxySoftInstall(client, @"SSR", @"https://raw.githubusercontent.com/proxysu/shellscript/master/ssr/ssr.sh"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - ////****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - //SetUpProgressBarProcessing(37); - //currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - //MainWindowsShowInfo(currentStatus); - - ////下载安装脚本安装 - ////****** "正在安装SSR......" ****** - //SetUpProgressBarProcessing(38); - //currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + "SSR......"; - //MainWindowsShowInfo(currentStatus); - - //sshShellCommand = $"curl -o /tmp/ssr.sh https://raw.githubusercontent.com/proxysu/shellscript/master/ssr/ssr.sh"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"yes | bash /tmp/ssr.sh"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"rm -f /tmp/ssr.sh"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "server.py", @"/usr/local/shadowsocks/server.py"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //****** "安装完毕,上传配置文件......" ****** - SetUpProgressBarProcessing(44); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - //生成服务端配置 - string upLoadPath = @"/etc/shadowsocks.json"; - - //设置指向Caddy监听的随机端口 - randomCaddyListenPort = GetRandomPort(); - string randomSSRListenPortStr = randomCaddyListenPort.ToString(); - - sshShellCommand = $"sed -i 's/8800/{randomSSRListenPortStr}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //设置密码 - sshShellCommand = $"sed -i 's/##password##/{ReceiveConfigurationParameters[2]}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //Caddy安装与检测安装是否成功 61--66 - functionResult = CaddyInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "上传Caddy配置文件......" ****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string caddyConfig = $"{pwdir}" + @"TemplateConfg\ssr\ssr_tls.caddyfile"; - upLoadPath = @"/etc/caddy/Caddyfile"; - - UploadConfig(connectionInfo, caddyConfig, upLoadPath); - - functionResult = SetCaddyfile(client, @"/etc/caddy/Caddyfile"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "Caddy配置文件上传成功,OK!" ****** - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //程序启动检测Caddy - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序启动检测SSR - functionResult = SoftStartDetect(client, "ssr", @"/usr/bin/ssr"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测BBR,满足条件并启动 90--95 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - //****** "生成客户端配置......" ****** - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - if (!Directory.Exists("ssr_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("ssr_config");//创建该文件夹   - } - - - //****** "SSR+TLS+Caddy安装成功,祝你玩的愉快!!" ****** - SetUpProgressBarProcessing(100); - currentStatus = "SSR+TLS+Caddy" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示服务端连接参数 - proxyType = "SSR"; - - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //更新SSR的密码 - private void ButtonSSRPassword_Click(object sender, RoutedEventArgs e) - { - TextBoxSSRPassword.Text = RandomUUID(); - } - - - #endregion - - #region SS相关 - - //打开SS Plugin设置窗口 - private void ButtonTemplateConfigurationSS_Click(object sender, RoutedEventArgs e) - { - //清空初始化模板参数 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - SSpluginWindow windowTemplateConfigurationSS = new SSpluginWindow(); - windowTemplateConfigurationSS.Closed += windowTemplateConfigurationSSClosed; - windowTemplateConfigurationSS.ShowDialog(); - } - //SS Plugin设置窗口关闭后,触发事件,将所选的方案与其参数显示在UI上 - private void windowTemplateConfigurationSSClosed(object sender, System.EventArgs e) - { - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //显示"未选择方案!" - TextBlockCurrentlySelectedPlanSS.Text = Application.Current.FindResource("TextBlockCurrentlySelectedPlanNo").ToString(); - - TextBlockShowPortSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanPortSS.Visibility = Visibility.Hidden; - - TextBlockShowUUIDSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanUUIDSS.Visibility = Visibility.Hidden; - - TextBlockShowMethodSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanMethodSS.Visibility = Visibility.Hidden; - - TextBlockShowDomainSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanDomainSS.Visibility = Visibility.Hidden; - - TextBlockShowPathSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanPathSS.Visibility = Visibility.Hidden; - - TextBlockShowFakeWebsiteSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanFakeWebsite.Visibility = Visibility.Hidden; - return; - } - TextBlockCurrentlySelectedPlanSS.Text = ReceiveConfigurationParameters[8]; //所选方案名称 - TextBlockCurrentlySelectedPlanPortSS.Text = ReceiveConfigurationParameters[1]; //服务器端口 - TextBlockCurrentlySelectedPlanUUIDSS.Text = ReceiveConfigurationParameters[2]; //密码 - TextBlockCurrentlySelectedPlanMethodSS.Text = ReceiveConfigurationParameters[3]; //加密方法 - TextBlockCurrentlySelectedPlanDomainSS.Text = ReceiveConfigurationParameters[4]; //域名 - TextBlockCurrentlySelectedPlanPathSS.Text = ReceiveConfigurationParameters[6]; //WebSocket Path - TextBlockCurrentlySelectedPlanFakeWebsite.Text = ReceiveConfigurationParameters[7]; //伪装网站 - - if (String.Equals(ReceiveConfigurationParameters[0], "NonePluginSS") - || String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpWebSS") - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketSS") - || String.Equals(ReceiveConfigurationParameters[0], "KcptunPluginSS") - ) - { - //显示端口 - TextBlockShowPortSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPortSS.Visibility = Visibility.Visible; - //显示密码 - TextBlockShowUUIDSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanUUIDSS.Visibility = Visibility.Visible; - //显示加密方式 - TextBlockShowMethodSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanMethodSS.Visibility = Visibility.Visible; - //隐藏域名 - TextBlockShowDomainSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanDomainSS.Visibility = Visibility.Hidden; - //隐藏WebSocket路径 - TextBlockShowPathSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanPathSS.Visibility = Visibility.Hidden; - //隐藏伪装网站 - TextBlockShowFakeWebsiteSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanFakeWebsiteSS.Visibility = Visibility.Hidden; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpsWebSS") - || String.Equals(ReceiveConfigurationParameters[0], "QuicSS") - || String.Equals(ReceiveConfigurationParameters[0], "GoQuietPluginSS") - || String.Equals(ReceiveConfigurationParameters[0], "CloakPluginSS") - ) - { - //显示端口 - TextBlockShowPortSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPortSS.Visibility = Visibility.Visible; - //显示密码 - TextBlockShowUUIDSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanUUIDSS.Visibility = Visibility.Visible; - //显示加密方式 - TextBlockShowMethodSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanMethodSS.Visibility = Visibility.Visible; - //显示域名 - TextBlockShowDomainSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanDomainSS.Visibility = Visibility.Visible; - //隐藏WebSocket路径 - TextBlockShowPathSS.Visibility = Visibility.Hidden; - TextBlockCurrentlySelectedPlanPathSS.Visibility = Visibility.Hidden; - //显示伪装网站 - TextBlockShowFakeWebsiteSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanFakeWebsiteSS.Visibility = Visibility.Visible; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSWebFrontSS")) - { - //显示端口 - TextBlockShowPortSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPortSS.Visibility = Visibility.Visible; - //显示密码 - TextBlockShowUUIDSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanUUIDSS.Visibility = Visibility.Visible; - //显示加密方式 - TextBlockShowMethodSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanMethodSS.Visibility = Visibility.Visible; - //显示域名 - TextBlockShowDomainSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanDomainSS.Visibility = Visibility.Visible; - //隐藏WebSocket路径 - TextBlockShowPathSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanPathSS.Visibility = Visibility.Visible; - //显示伪装网站 - TextBlockShowFakeWebsiteSS.Visibility = Visibility.Visible; - TextBlockCurrentlySelectedPlanFakeWebsiteSS.Visibility = Visibility.Visible; - } - - } - - //传送SS参数,启动SS安装进程 - private void Button_LoginSS_Click(object sender, RoutedEventArgs e) - - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - //读取模板配置 - - //生成客户端配置时,连接的服务主机的IP或者域名 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[4]) == true) - { - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text); - testDomain = false; - } - //选择模板 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - //******"请先选择配置模板!"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ChooseTemplate").ToString()); - return; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "NonePluginSS") - || String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpWebSS") - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketSS") - || String.Equals(ReceiveConfigurationParameters[0], "KcptunPluginSS") - ) - { - testDomain = false; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "GoQuietPluginSS") - || String.Equals(ReceiveConfigurationParameters[0], "CloakPluginSS") - || String.Equals(ReceiveConfigurationParameters[0], "QuicSS") - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSWebFrontSS") - || String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpsWebSS") - ) - { - testDomain = true; - } - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartSetUpSS(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - - } - - //登录远程主机布署SS程序 - private void StartSetUpSS(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "ss-server", @"/usr/local/bin/ss-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl)11--30 - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //如果使用是TLS模式,需要检测域名解析是否正确 - if (testDomain == true) - { - //检测域名是否解析到当前IP上 34---36 - functionResult = DomainResolutionCurrentIPDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - SetUpProgressBarProcessing(37); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - MainWindowsShowInfo(currentStatus); - - //下载安装脚本安装 - //****** "正在安装SS,使用编译方式,时间稍长,请耐心等待............" ****** - SetUpProgressBarProcessing(38); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + "SS," + Application.Current.FindResource("DisplayInstallInfo_ExplainBuildSS").ToString(); - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - - //****** "编译中,请耐心等待............" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_CompilingSS").ToString(); - MainWindowsShowInfo(currentStatus); - - Thread threadWaitSScompile = new Thread(() => MonitorCompileSSprocess()); - threadWaitSScompile.SetApartmentState(ApartmentState.STA); - threadWaitSScompile.Start(); - - //开始编译。。。 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - compileSSend = true; //中止显示"**"的线程 - threadWaitSScompile.Abort(); - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "ss-server", @"/usr/local/bin/ss-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "上传配置文件......" ****** - SetUpProgressBarProcessing(44); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mv /etc/shadowsocks-libev/config.json /etc/shadowsocks-libev/config.json.1"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //string getIpv4 = client.RunCommand(@"curl -4 ip.sb").Result; - //string getIpv6 = client.RunCommand(@"wget -qO- -t1 -T2 ipv6.icanhazip.com").Result; - - //生成服务端配置 - - string serverConfig = $"{pwdir}" + @"TemplateConfg\ss\ss_server_config.json"; - string ssPluginType = ""; - using (StreamReader reader = File.OpenText(serverConfig)) - { - JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - - //设置服务器监听地址 - //if (String.IsNullOrEmpty(getIpv6) == true) - //{ - serverJson["server"] = "0.0.0.0"; - //} - //else - //{ - // JArray serverIp = JArray.Parse(@"[""[::0]"", ""0.0.0.0""]"); - // serverJson["server"] = serverIp; - //} - - //设置密码 - serverJson["password"] = ReceiveConfigurationParameters[2]; - //设置监听端口 - serverJson["server_port"] = int.Parse(ReceiveConfigurationParameters[1]); - //设置加密方式 - serverJson["method"] = ReceiveConfigurationParameters[3]; - //产生伪装Web的监听端口 - randomCaddyListenPort = GetRandomPort(); - - string failoverPort = randomCaddyListenPort.ToString(); - //obfs http模式 - if (String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpWebSS") == true) - { - serverJson["plugin"] = @"obfs-server"; - serverJson["plugin_opts"] = $"obfs=http;failover=127.0.0.1:{failoverPort}"; - //客户端项 - ReceiveConfigurationParameters[5] = @"obfs-local"; - ReceiveConfigurationParameters[9] = "obfs=http;obfs-host=www.bing.com"; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpsWebSS") == true) - { - serverJson["plugin"] = @"obfs-server"; - serverJson["plugin_opts"] = $"obfs=tls;failover=127.0.0.1:{failoverPort}"; - //客户端项 - ReceiveConfigurationParameters[5] = @"obfs-local"; - ReceiveConfigurationParameters[9] = $"obfs=tls;obfs-host={ReceiveConfigurationParameters[4]}"; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketSS") == true) - { - serverJson["plugin"] = @"v2ray-plugin"; - serverJson["plugin_opts"] = $"server"; - //客户端项 - ReceiveConfigurationParameters[5] = @"v2ray-plugin"; - ReceiveConfigurationParameters[9] = ""; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSWebFrontSS") == true) - { - serverJson["server_port"] = 10000; - serverJson["plugin"] = @"v2ray-plugin"; - serverJson["plugin_opts"] = $"server;host={ReceiveConfigurationParameters[4]};path={ReceiveConfigurationParameters[6]}"; - - //客户端项 - ReceiveConfigurationParameters[5] = @"v2ray-plugin"; - ReceiveConfigurationParameters[9] = $"tls;host={ReceiveConfigurationParameters[4]};path={ReceiveConfigurationParameters[6]}"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "QuicSS") == true) - { - serverJson["mode"] = "tcp"; - serverJson["plugin"] = @"v2ray-plugin"; - serverJson["plugin_opts"] = $"server;mode=quic;host={ReceiveConfigurationParameters[4]}"; - //客户端项 - ReceiveConfigurationParameters[5] = @"v2ray-plugin"; - ReceiveConfigurationParameters[9] = $"mode=quic;host={ReceiveConfigurationParameters[4]}"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "KcptunPluginSS") == true) - { - serverJson["mode"] = "tcp"; - serverJson["plugin"] = @"kcptun-plugin-server"; - serverJson["plugin_opts"] = $"key={ReceiveConfigurationParameters[2]}"; - //客户端项 - ReceiveConfigurationParameters[5] = @"kcptun"; - ReceiveConfigurationParameters[9] = $"key={ReceiveConfigurationParameters[2]}"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "GoQuietPluginSS") == true) - { - serverJson["plugin"] = @"goquiet-plugin-server"; - serverJson["plugin_opts"] = $"WebServerAddr=127.0.0.1:{failoverPort};Key={ReceiveConfigurationParameters[2]}"; - //客户端项 - ReceiveConfigurationParameters[5] = @"goquiet"; - ReceiveConfigurationParameters[9] = $"ServerName={ReceiveConfigurationParameters[4]};Key={ReceiveConfigurationParameters[2]};Browser=chrome"; - - } - else if (String.Equals(ReceiveConfigurationParameters[0], "CloakPluginSS") == true) - { - //****** "正在安装 Cloak-Plugin......" ****** - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + " Cloak-Plugin......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-plugins/cloak-plugin-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "cloak-plugin-server", @"/usr/local/bin/cloak-plugin-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - string bypassUID = client.RunCommand(@"/usr/local/bin/cloak-plugin-server -u").Result.TrimEnd('\r', '\n'); - string generateKey = client.RunCommand(@"/usr/local/bin/cloak-plugin-server -k").Result.TrimEnd('\r', '\n'); - string[] keyCloak = generateKey.Split(new char[] { ',' }); - string publicKey = keyCloak[0]; - string privateKey = keyCloak[1]; - - serverJson["plugin"] = @"cloak-plugin-server"; - serverJson["plugin_opts"] = $"BypassUID={bypassUID};PrivateKey={privateKey};RedirAddr=127.0.0.1:{failoverPort};DatabasePath=/etc/shadowsocks-libev/userinfo.db;StreamTimeout=300"; - //客户端项 - ReceiveConfigurationParameters[5] = @"cloak"; - ReceiveConfigurationParameters[9] = $"UID={bypassUID};PublicKey={publicKey};Transport=direct;ServerName={ReceiveConfigurationParameters[4]};BrowserSig=chrome;NumConn=4;EncryptionMethod=plain;StreamTimeout=300"; - - } - ssPluginType = (string)serverJson["plugin"]; - using (StreamWriter sw = new StreamWriter(@"config.json")) - { - sw.Write(serverJson.ToString()); - } - } - - string upLoadPath = @"/etc/shadowsocks-libev/config.json"; - UploadConfig(connectionInfo, @"config.json", upLoadPath); - - File.Delete(@"config.json"); - - //安装所使用的插件 - if (String.Equals(ssPluginType, "obfs-server")) - { - //****** "正在安装 Simple-obfs Plugin......" ****** - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + " Simple-obfs Plugin......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-plugins/obfs-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "obfs-server", @"/usr/local/bin/obfs-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - } - else if (String.Equals(ssPluginType, "v2ray-plugin")) - { - //****** "正在安装 V2Ray-Plugin......" ****** - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + " V2Ray-Plugin......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-plugins/v2ray-plugin-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "v2ray-plugin", @"/usr/local/bin/v2ray-plugin"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - else if (String.Equals(ssPluginType, "kcptun-plugin-server")) - { - //****** "正在安装 Kcptun-Plugin......" ****** - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + " Kcptun-Plugin......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-plugins/kcptun-plugin-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "kcptun-plugin-server", @"/usr/local/bin/kcptun-plugin-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - else if (String.Equals(ssPluginType, "goquiet-plugin-server")) - { - //****** "正在安装 GoQuiet-Plugin......" ****** - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + " GoQuiet-Plugin......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-plugins/goquiet-plugin-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "goquiet-plugin-server", @"/usr/local/bin/goquiet-plugin-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - else if (String.Equals(ssPluginType, "cloak-plugin-server")) - { - - } - - - //如果使用v2ray-plugin Quic模式,先要安装acme.sh,申请证书 - if (String.Equals(ReceiveConfigurationParameters[0], "QuicSS") == true) - { - //acme.sh安装与申请证书 51--57 - functionResult = AcmeShInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - - //如果使用Web伪装网站模式,需要安装Caddy - if (String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpWebSS") == true - || String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpsWebSS") == true - || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSWebFrontSS") == true - || String.Equals(ReceiveConfigurationParameters[0], "GoQuietPluginSS") == true - || String.Equals(ReceiveConfigurationParameters[0], "CloakPluginSS") == true - ) - { - //Caddy安装 61--66 - functionResult = CaddyInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "上传Caddy配置文件......" ****** - SetUpProgressBarProcessing(67); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpWebSS") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\ss\ss_obfs_http_web_config.caddyfile"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "ObfsPluginHttpsWebSS") == true - || String.Equals(ReceiveConfigurationParameters[0], "GoQuietPluginSS") == true - || String.Equals(ReceiveConfigurationParameters[0], "CloakPluginSS") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\ss\ss_tls_caddy_config.caddyfile"; - } - else if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLSWebFrontSS") == true) - { - serverConfig = $"{pwdir}" + @"TemplateConfg\ss\WebSocketTLSWeb.caddyfile"; - } - - upLoadPath = @"/etc/caddy/Caddyfile"; - - UploadConfig(connectionInfo, serverConfig, upLoadPath); - - //设置Caddy配置文件 - functionResult = SetCaddyfile(client, @"/etc/caddy/Caddyfile"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "Caddy配置文件上传成功,OK!" ****** - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //程序启动检测Caddy - functionResult = SoftStartDetect(client, "caddy", @"/usr/bin/caddy"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - } - - //程序启动检测SS - functionResult = SoftStartDetect(client, "ss-server", @"/usr/local/bin/ss-server"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测BBR,满足条件并启动 90--95 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - client.Disconnect();//断开服务器ssh连接 - - //****** "生成客户端配置......" ****** - SetUpProgressBarProcessing(96); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "SS安装成功,祝你玩的愉快!!" ****** - SetUpProgressBarProcessing(100); - currentStatus = "SS" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示服务端连接参数 - proxyType = "SS"; - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - } - - //编译SS时,中间监视窗口显示"****"不断增长进度,直到编译结束 - private static bool compileSSend = false; - private void MonitorCompileSSprocess() - { - currentShellCommandResult = "**"; - while (compileSSend == false) - { - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorActionNoWrap, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - Thread.Sleep(1000); - } - } - - #endregion - - #region MTProto相关 - //传递参数启动安装进程 - private void ButtonMtgSetUp_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - //清空参数空间 - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - //传递服务器地址 - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text); ; - //传递服务端口 - ReceiveConfigurationParameters[1] = PreTrim(TextBoxMtgHostPort.Text); - //传递伪装域名 - if (String.IsNullOrEmpty(PreTrim(TextBoxMtgSites.Text)) == true) - { - ReceiveConfigurationParameters[7] = "azure.microsoft.com"; - } - else - { - ReceiveConfigurationParameters[7] = PreTrim(TextBoxMtgSites.Text); - } - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartSetUpMtg(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //Mtg安装进程 - private void StartSetUpMtg(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否已安装代理 8--10 - functionResult = SoftInstalledIsNoYes(client, "mtg", @"/usr/local/bin/mtg"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测关闭Selinux及系统组件是否齐全(apt-get/yum/dnf/systemctl)11--30 - //安装依赖软件,检测端口,防火墙开启端口 - functionResult = ShutDownSelinuxAndSysComponentsDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //检测是否为64位系统 - sshShellCommand = @"uname -m"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - string resultCmd = currentShellCommandResult; - if (resultCmd.Contains("x86_64") == false) - { - //******"请在x86_64系统中安装MTProto" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_PleaseInstallSoftAtX64").ToString() + "MTProto......"); - //****** "系统环境不满足要求,安装失败!!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_MissingSystemComponents").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - //下载安装脚本安装MTProto 37--40 - - functionResult = MTProtoInstall(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //程序是否安装成功检测并设置开机启动 41--43 - functionResult = SoftInstalledSuccessOrFail(client, "mtg", @"/usr/local/bin/mtg"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "正在启动MTProto......" ****** - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartSoft").ToString() + "MTProto......"; - MainWindowsShowInfo(currentStatus); - - //启动MTProto服务 - functionResult = SoftStartDetect(client, "mtg", @"/usr/local/bin/mtg"); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - //****** "生成客户端配置......" ****** - SetUpProgressBarProcessing(80); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop mtg"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - sshShellCommand = @"cat /usr/local/etc/mtg.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - sshShellCommand = currentShellCommandResult; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - Thread.Sleep(3000); - sshShellCommand = @"cat /usr/local/etc/mtg_info.json"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - ReceiveConfigurationParameters[9] = currentShellCommandResult; - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[9]) == true) - { - Thread.Sleep(3000); - sshShellCommand = @"cat /usr/local/etc/mtg_info.json"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - ReceiveConfigurationParameters[9] = currentShellCommandResult; - } - sshShellCommand = @"pkill mtg"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - sshShellCommand = @"systemctl restart mtg"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[9]) == true) - { - //***客户端配置获取失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GetClientConfigFailed").ToString(); - MainWindowsShowInfo(currentStatus); - FunctionResultErr(); - client.Disconnect(); - return; - } - - //检测BBR,满足条件并启动 90--95 - functionResult = DetectBBRandEnable(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - client.Disconnect();//断开服务器ssh连接 - - //Thread.Sleep(1000); - //if (!Directory.Exists("mtproto_config"))//如果不存在就创建file文件夹      - //{ - // Directory.CreateDirectory("mtproto_config");//创建该文件夹   - //} - //using (StreamWriter sw = new StreamWriter(@"mtproto_config\mtproto_info.json")) - //{ - // sw.Write(currentShellCommandResult.ToString()); - //} - - //****** "MTProto+TLS安装成功,祝你玩的愉快!!" ****** - SetUpProgressBarProcessing(100); - currentStatus = "MTProto+TLS" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示服务端连接参数 - proxyType = "MTProto"; - - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //下载安装脚本安装MTProto 37--40 - //functionResult = MTProtoInstall(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool MTProtoInstall(SshClient client) - { - //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - SetUpProgressBarProcessing(37); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - MainWindowsShowInfo(currentStatus); - - //下载安装脚本安装 - //****** "正在安装MTProto......" ****** - SetUpProgressBarProcessing(38); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + "MTProto......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/MTProto/mtg_install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - } - - sshShellCommand = $"yes | bash {saveShellScriptFileName} {ReceiveConfigurationParameters[1]} {ReceiveConfigurationParameters[7]}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(40); - return true; - } - #endregion - - #region 其他功能函数及系统工具相关 - //TextBox输入内容做预处理 - private string PreTrim(string preString) - { - return preString.Trim(); - } - //产生随机端口 - private int GetRandomPort() - { - Random random = new Random(); - return random.Next(10001, 60000); - } - - //产生随机字符串 - private string GenerateRandomStr(int length) - { - var rand = System.Security.Cryptography.RandomNumberGenerator.Create(); - byte[] bytes = new byte[length*2]; - rand.GetBytes(bytes); - string randStr = Convert.ToBase64String(bytes); - randStr = randStr.Replace("+", "").Replace("/", "").Replace("=", "").Substring(0,length); - //MessageBox.Show(randStr); - return randStr; - } - //生成保存的shell脚本名称 - private string GenerateRandomScriptFileName(string filename) - { - return "/tmp/tmp." + filename + ".sh"; - } - //判断目录是否存在,不存在则创建 - private static bool CheckDir(string folder) - { - try - { - if (!Directory.Exists(folder))//如果不存在就创建file文件夹 - Directory.CreateDirectory(folder);//创建该文件夹   - return true; - } - catch (Exception) - { - return false; - } - } - - //目录已存在则生成序号递增,并返回所创建的目录路径。 - private string CreateConfigSaveDir(string upperDir, string configDir) - { - try - { - //string saveFileFolderFirst = configDir; - int num = 1; - //string saveFileFolder; - //saveFileFolder = EncodeURIComponent(configDir); - string saveFileFolder = configDir.Replace(":", "_"); - CheckDir(upperDir); - while (Directory.Exists(upperDir + @"\" + saveFileFolder) == true) - { - saveFileFolder = configDir + "_copy_" + num.ToString(); - num++; - } - CheckDir(upperDir + @"\" + saveFileFolder); - return upperDir + @"\" + saveFileFolder; - } - catch (Exception) - { - //string saveFileFolder = ""; - //return upperDir + @"\" + saveFileFolder; - return upperDir; - } - - } - - - //上传配置文件 - private void UploadConfig(ConnectionInfo connectionInfo, string uploadConfig, string upLoadPath) - { - try - { - using (var sftpClient = new SftpClient(connectionInfo)) - { - sftpClient.Connect(); - FileStream openUploadConfigFile = File.OpenRead(uploadConfig); - sftpClient.UploadFile(openUploadConfigFile, upLoadPath, true); - openUploadConfigFile.Close(); - sftpClient.Disconnect(); - } - - } - catch (Exception ex2) - { - MessageBox.Show("sftp" + ex2.ToString()); - //MessageBox.Show("sftp出现未知错误,上传文件失败,请重试!"); - return; - } - } - - //下载配置文件 - private void DownloadConfig(ConnectionInfo connectionInfo, string localConfigSavePathAndFileName, string remoteConfigPathAndFileName) - { - try - { - using (var sftpClient = new SftpClient(connectionInfo)) - { - sftpClient.Connect(); - FileStream createDownloadConfig = File.Open(localConfigSavePathAndFileName, FileMode.Create); - sftpClient.DownloadFile(remoteConfigPathAndFileName, createDownloadConfig); - createDownloadConfig.Close(); - - sftpClient.Disconnect(); - } - - } - catch (Exception ex2) - { - MessageBox.Show("sftp" + ex2.ToString()); - //MessageBox.Show("sftp出现未知错误,下载文件失败,请重试!"); - return; - } - } - - //伪装网站处理 - //private string DisguiseURLprocessing(string fakeUrl) - //{ - //var uri = new Uri(fakeUrl); - //return uri.Host; - - ////处理伪装网站域名中的前缀 - //if (fakeUrl.Length >= 7) - //{ - // string testDomainMask = fakeUrl.Substring(0, 7); - // if (String.Equals(testDomainMask, "https:/") || String.Equals(testDomainMask, "http://")) - // { - // //MessageBox.Show(testDomain); - // string[] tmpUrl = fakeUrl.Split('/'); - // //MainWindow.ReceiveConfigurationParameters[7] = TextBoxMaskSites.Text.Replace("/", "\\/"); - // fakeUrl = tmpUrl[2]; - // } - - //} - //return fakeUrl; - // } - - #region 检测系统内核是否符合安装要求 - //private static bool DetectKernelVersion(string kernelVer) - //{ - // string[] linuxKernelCompared = kernelVer.Split('.'); - // if (int.Parse(linuxKernelCompared[0]) > 2) - // { - // //MessageBox.Show($"当前系统内核版本为{result.Result},符合安装要求!"); - // return true; - // } - // else if (int.Parse(linuxKernelCompared[0]) < 2) - // { - // //MessageBox.Show($"当前系统内核版本为{result.Result},V2ray要求内核为2.6.23及以上。请升级内核再安装!"); - // return false; - // } - // else if (int.Parse(linuxKernelCompared[0]) == 2) - // { - // if (int.Parse(linuxKernelCompared[1]) > 6) - // { - // //MessageBox.Show($"当前系统内核版本为{result.Result},符合安装要求!"); - // return true; - // } - // else if (int.Parse(linuxKernelCompared[1]) < 6) - // { - // //MessageBox.Show($"当前系统内核版本为{result.Result},V2ray要求内核为2.6.23及以上。请升级内核再安装!"); - // return false; - // } - // else if (int.Parse(linuxKernelCompared[1]) == 6) - // { - // if (int.Parse(linuxKernelCompared[2]) < 23) - // { - // //MessageBox.Show($"当前系统内核版本为{result.Result},V2ray要求内核为2.6.23及以上。请升级内核再安装!"); - // return false; - // } - // else - // { - // //MessageBox.Show($"当前系统内核版本为{result.Result},符合安装要求!"); - // return true; - // } - - // } - // } - // return false; - - //} - #endregion - - //打开系统工具中的校对时间窗口 - private void ButtonProofreadTime_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - ProofreadTimeWindow proofreadTimeWindow = new ProofreadTimeWindow(); - ProofreadTimeWindow.ProfreadTimeReceiveConnectionInfo = connectionInfo; - - proofreadTimeWindow.ShowDialog(); - - } - //释放80/443端口 - private void ButtonClearOccupiedPorts_Click(object sender, RoutedEventArgs e) - { - //****** "80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?" ****** - MessageBoxResult dialogResult = MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorPortUsed").ToString(), "Stop application", MessageBoxButton.YesNo); - if (dialogResult == MessageBoxResult.No) - { - return; - } - - ConnectionInfo testconnect = GenerateConnectionInfo(); - try - { - using (var client = new SshClient(testconnect)) - { - client.Connect(); - - //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; - if (testRootAuthority.Equals("0\n") == false) - { - //******"请使用具有root权限的账户登录主机!!"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorRootPermission").ToString()); - client.Disconnect(); - return; - } - string cmdTestPort; - string cmdResult; - cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; - cmdResult = client.RunCommand(cmdTestPort).Result; - - if (String.IsNullOrEmpty(cmdResult) == false) - { - - string[] cmdResultArry443 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); - client.RunCommand($"kill -9 {cmdResultArry443[3]}"); - } - - cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; - cmdResult = client.RunCommand(cmdTestPort).Result; - if (String.IsNullOrEmpty(cmdResult) == false) - { - string[] cmdResultArry80 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); - client.RunCommand($"kill -9 {cmdResultArry80[3]}"); - } - //****** "80/443端口释放完毕!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_ReleasePortOK").ToString()); - client.Disconnect(); - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - //启用BBR - private void ButtonTestAndEnableBBR_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartTestAndEnableBBR(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //启用BBR的主要进程 - private void StartTestAndEnableBBR(ConnectionInfo connectionInfo) - { - functionResult = true; - onlyIpv6 = false; - getApt = false; - getDnf = false; - getYum = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - SetUpProgressBarProcessing(30); - //****** "BBR测试......" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestBBR").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"uname -r"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string[] linuxKernelVerStrBBR = currentShellCommandResult.Split('-'); - - bool detectResultBBR = DetectKernelVersionBBR(linuxKernelVerStrBBR[0]); - - sshShellCommand = @"sysctl net.ipv4.tcp_congestion_control | grep bbr"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - string resultCmdTestBBR = currentShellCommandResult; - //如果内核满足大于等于4.9,且还未启用BBR,则启用BBR - if (detectResultBBR == true && resultCmdTestBBR.Contains("bbr") == false) - { - SetUpProgressBarProcessing(60); - //****** "正在启用BBR......" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableBBR").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sysctl -p"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - else if (resultCmdTestBBR.Contains("bbr") == true) - { - SetUpProgressBarProcessing(100); - //****** "BBR已经启用了!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRisEnabled").ToString(); - MainWindowsShowInfo(currentStatus); - - } - else - { - //****** "系统不满足启用BBR的条件,启用失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - - client.Disconnect();//断开服务器ssh连接 - - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - //检测要启用BBR主要的内核版本 - private static bool DetectKernelVersionBBR(string kernelVer) - { - string[] linuxKernelCompared = kernelVer.Split('.'); - if (int.Parse(linuxKernelCompared[0]) > 4) - { - return true; - } - else if (int.Parse(linuxKernelCompared[0]) < 4) - { - return false; - } - else if (int.Parse(linuxKernelCompared[0]) == 4) - { - if (int.Parse(linuxKernelCompared[1]) >= 9) - { - return true; - } - else if (int.Parse(linuxKernelCompared[1]) < 9) - { - return false; - } - - } - return false; - - } - - //启动卸载代理 - private void ButtonRemoveAllSoft_Click(object sender, RoutedEventArgs e) - { - //******"仅支持卸载由ProxySU安装的代理软件及相关配置,请确保重要配置已备份。不支持卸载使用其他方法或脚本安装的代理。确定要卸载远程主机上的代理软件吗?"****** - string messageShow = Application.Current.FindResource("MessageBoxShow_RemoveAllSoft").ToString(); - MessageBoxResult messageBoxResult = MessageBox.Show(messageShow, "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => StartRemoveProxySoft(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - } - //卸载代理进程 - private void StartRemoveProxySoft(ConnectionInfo connectionInfo) - { - functionResult = true; - getApt = false; - getDnf = false; - getYum = false; - onlyIpv6 = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - //Thread.Sleep(3000); - } - - - //检测root权限 5--7 - functionResult = RootAuthorityDetect(client); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - functionResult = FileCheckExists(client, @"/etc/resolv.conf.proxysu"); - if (functionResult == true) - { - sshShellCommand = @"mv /etc/resolv.conf.proxysu /etc/resolv.conf "; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - sshShellCommand = @"command -v apt-get"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - getApt = !String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v dnf"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - getDnf = !String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v yum"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - getYum = !String.IsNullOrEmpty(currentShellCommandResult); - - //设置安装软件所用的命令格式 - if (getApt == true) - { - sshCmdUpdate = @"apt-get update"; - //sshCmdInstall = @"apt-get -y install "; - } - else if (getDnf == true) - { - sshCmdUpdate = @"dnf clean all;dnf makecache"; - //sshCmdInstall = @"dnf -y install "; - } - else if (getYum == true) - { - sshCmdUpdate = @"yum clean all; yum makecache"; - //sshCmdInstall = @"yum -y install "; - } - - //检测主机是否为纯ipv6的主机 - onlyIpv6 = OnlyIpv6HostDetect(client); - - //如果未检测到有效的ip,连接就会被断开 - if (client.IsConnected == false) - { - return ; - } - if (onlyIpv6 == true) - { - functionResult = SetUpNat64(client, true); - if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return ; } - //SetUpNat64(client, true); - //sshShellCommand = $"{sshCmdUpdate}"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - - //******"开始卸载......"****** - SetUpProgressBarProcessing(10); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() + "......"; - MainWindowsShowInfo(currentStatus); - - #region 卸载V2Ray - - //******"检测系统是否已经安装V2ray......"******03 - SetUpProgressBarProcessing(11); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "V2ray......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name v2ray"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - functionResult = FileCheckExists(client, @"/usr/local/bin/v2ray"); - if (functionResult == true) - { - //******"检测到已安装V2Ray!开始卸载V2Ray......"****** - SetUpProgressBarProcessing(12); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "V2Ray!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "V2Ray......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop v2ray"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"bash {saveShellScriptFileName} --remove"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable v2ray"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/etc/v2ray /var/log/v2ray"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"find / -name v2ray"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, @"/usr/local/bin/v2ray"); - if (functionResult == true) - //if (currentShellCommandResult.Contains("/usr/local/bin/v2ray") == true) - { - //******"V2Ray卸载失败!请向开发者问询!"****** - currentStatus = "V2Ray" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"V2Ray卸载成功!"****** - SetUpProgressBarProcessing(16); - currentStatus ="V2Ray" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装V2Ray!"******04 - SetUpProgressBarProcessing(16); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "V2Ray!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - #region 卸载Trojan-go - - //******"检测系统是否已经安装Trojan-go......"******03 - SetUpProgressBarProcessing(17); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Trojan-go......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name trojan-go"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/trojan-go") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/trojan-go"); - if (functionResult == true) - { - //******"检测到已安装Trojan-go,开始卸载Trojan-go......"****** - SetUpProgressBarProcessing(18); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "Trojan-go!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "Trojan-go......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop trojan-go"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"bash {saveShellScriptFileName} --remove"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable trojan-go"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/etc/trojan-go /var/log/trojan-go"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"find / -name trojan-go"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/trojan-go") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/trojan-go"); - if (functionResult == true) - { - //******"Trojan-go卸载失败!请向开发者问询!"****** - currentStatus = "Trojan-go" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"Trojan-go卸载成功!"****** - SetUpProgressBarProcessing(22); - currentStatus = "Trojan-go" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装Trojan-go!"******04 - SetUpProgressBarProcessing(22); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "Trojan-go!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - #region 卸载Trojan - - //******"检测系统是否已经安装Trojan......"******03 - SetUpProgressBarProcessing(23); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Trojan......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name trojan"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/trojan") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/trojan"); - if (functionResult == true) - { - //******"检测到已安装Trojan,开始卸载Trojan......"****** - SetUpProgressBarProcessing(24); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "Trojan!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "Trojan......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop trojan"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable trojan"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/bin/trojan /etc/systemd/system/trojan.service /usr/local/etc/trojan"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"find / -name trojan"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/trojan") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/trojan"); - if (functionResult == true) - { - //******"Trojan卸载失败!请向开发者问询!"****** - currentStatus = "Trojan" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"Trojan卸载成功!"****** - SetUpProgressBarProcessing(30); - currentStatus = "Trojan" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装Trojan!"******04 - SetUpProgressBarProcessing(30); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "Trojan!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - #region 卸载SSR - - //******"检测系统是否已经安装SSR......"******03 - SetUpProgressBarProcessing(31); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "SSR......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"if [ -f /usr/local/shadowsocks/server.py ];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("1") == true) - functionResult = FileCheckExists(client, @"/usr/local/shadowsocks/server.py"); - if (functionResult == true) - { - //******"检测到已安装SSR,开始卸载SSR......"****** - SetUpProgressBarProcessing(32); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "SSR!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "SSR......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop ssr"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ssr/ssr.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"bash {saveShellScriptFileName} uninstall"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable ssr"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"if [ -f /usr/local/shadowsocks/server.py ];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("1") == true) - functionResult = FileCheckExists(client, @"/usr/local/shadowsocks/server.py"); - if (functionResult == true) - { - //******"SSR卸载失败!请向开发者问询!"****** - currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"SSR卸载成功!"****** - SetUpProgressBarProcessing(36); - currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装SSR!"******04 - SetUpProgressBarProcessing(36); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "SSR!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - #region 卸载SS (Shadowsoks-libev) - - //******"检测系统是否已经安装SS (Shadowsoks-libev)......"******03 - SetUpProgressBarProcessing(37); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "SS (Shadowsoks-libev)......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name ss-server"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/ss-server") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/ss-server"); - if (functionResult == true) - { - //******"检测到SS(Shadowsoks-libev),开始卸载SS(Shadowsoks-libev)......"****** - SetUpProgressBarProcessing(38); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "SS (Shadowsoks-libev)!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "SS (Shadowsoks-libev)......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop ss-server"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/ss/ss-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"bash {saveShellScriptFileName} uninstall"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable ss-server"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //卸载插件 - sshShellCommand = @"rm -f /usr/local/bin/obfs-server /usr/local/bin/obfs-local /usr/local/bin/v2ray-plugin /usr/local/bin/kcptun-plugin-server /usr/local/bin/goquiet-plugin-server /usr/local/bin/cloak-plugin-server"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"find / -name ss-server"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/ss-server") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/ss-server"); - if (functionResult == true) - { - //******"SS(Shadowsoks-libev)卸载失败!请向开发者问询!"****** - currentStatus = "SS (Shadowsoks-libev)" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"SS (Shadowsoks-libev)卸载成功!"****** - SetUpProgressBarProcessing(40); - currentStatus = "SS (Shadowsoks-libev)" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装SS(Shadowsoks-libev)!"******04 - SetUpProgressBarProcessing(40); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "SS (Shadowsoks-libev)!"; - MainWindowsShowInfo(currentStatus); - } - - - #endregion - - #region 卸载acme.sh - - //******"检测系统是否已经安装acme.sh......"******03 - SetUpProgressBarProcessing(41); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "acme.sh......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"if [[ -d ~/.acme.sh ]];then echo '1';else echo '0'; fi"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("1") == true) - { - //******"检测到acme.sh,开始卸载acme.sh......"****** - SetUpProgressBarProcessing(42); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "acme.sh!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "acme.sh......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"/root/.acme.sh/acme.sh --uninstall"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -r ~/.acme.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"if [[ -d ~/.acme.sh ]];then echo '1';else echo '0'; fi"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("1") == true) - { - //******"acme.sh卸载失败!请向开发者问询!"****** - currentStatus = "acme.sh" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - sshShellCommand = @"sed -i 's/. ""/root/.acme.sh/acme.sh.env""//g' /root/.bashrc"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //******"acme.sh卸载成功!"****** - SetUpProgressBarProcessing(46); - currentStatus = "acme.sh" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装acme.sh!"******04 - SetUpProgressBarProcessing(46); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "acme.sh!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - - #region 卸载NaiveProxy - - //******"检测系统是否已经安装NaiveProxy......"******03 - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "NaiveProxy......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/bin/caddy") == true) - functionResult = FileCheckExists(client, @"/etc/caddy/naive"); - if (functionResult == true) - { - //******"检测到NaiveProxy,开始卸载NaiveProxy......"****** - SetUpProgressBarProcessing(49); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "NaiveProxy!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "NaiveProxy......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"bash {saveShellScriptFileName} uninstall"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - - - //sshShellCommand = @"find / -name caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/caddy") == true) - functionResult = FileCheckExists(client, @"/usr/bin/naive"); - if (functionResult == true) - { - //******"Caddy/NaiveProxy卸载失败!请向开发者问询!"****** - currentStatus = "NaiveProxy" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"Caddy/NaiveProxy卸载成功!"****** - SetUpProgressBarProcessing(60); - currentStatus = "NaiveProxy" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装NaiveProxy!"******04 - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "NaiveProxy!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - - #region 卸载Caddy - - //******"检测系统是否已经安装Caddy......"******03 - SetUpProgressBarProcessing(48); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Caddy......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/bin/caddy") == true) - functionResult = FileCheckExists(client, @"/usr/bin/caddy"); - if (functionResult == true) - { - //******"检测到Caddy,开始卸载Caddy......"****** - SetUpProgressBarProcessing(49); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "Caddy!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "Caddy......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //检测系统是否支持yum 或 apt-get或zypper - //如果不存在组件,则命令结果为空,string.IsNullOrEmpty值为真, - - sshShellCommand = @"command -v apt-get"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - bool getApt = ! String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v dnf"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - bool getDnf = ! String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v yum"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - bool getYum = ! String.IsNullOrEmpty(currentShellCommandResult); - - SetUpProgressBarProcessing(55); - - sshShellCommand = @"command -v zypper"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - bool getZypper = String.IsNullOrEmpty(currentShellCommandResult); - - - string sshCmdRemove = ""; - //string sshCmdRemove2; - //设置安装软件所用的命令格式 - if (getApt == true) - { - //sshCmdUpdate = @"apt-get update"; - sshCmdRemove = @"apt-get -y autoremove --purge "; - } - else if (getDnf == true) - { - //sshCmdUpdate = @"dnf -q makecache"; - sshCmdRemove = @"dnf -y remove "; - } - else if (getYum == true) - { - //sshCmdUpdate = @"yum -q makecache"; - sshCmdRemove = @"yum -y remove "; - } - else if (getZypper == true) - { - //sshCmdUpdate = @"zypper ref"; - sshCmdRemove = @"zypper -y remove "; - } - - sshShellCommand = $"{sshCmdRemove}caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"find / -name caddy"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/caddy") == true) - functionResult = FileCheckExists(client, @"/usr/bin/caddy"); - if (functionResult == true) - { - //******"Caddy卸载失败!请向开发者问询!"****** - currentStatus = "Caddy" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"Caddy卸载成功!"****** - SetUpProgressBarProcessing(60); - currentStatus = "Caddy" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装Caddy!"******04 - SetUpProgressBarProcessing(60); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "Caddy!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - #region 卸载MtProto - //******"检测系统是否已经安装MtProto......"******03 - SetUpProgressBarProcessing(61); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "MtProto......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name mtg"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/mtg") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/mtg"); - if (functionResult == true) - { - //******"检测到MtProto,开始卸载MtProto......"****** - SetUpProgressBarProcessing(63); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "MtProto!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "MtProto......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop mtg"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable mtg"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /etc/systemd/system/mtg.service"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/bin/mtg"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/etc/mtg_info.json"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/etc/mtg.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"find / -name mtg"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //if (currentShellCommandResult.Contains("/usr/local/bin/mtg") == true) - functionResult = FileCheckExists(client, @"/usr/local/bin/mtg"); - if (functionResult == true) - { - //******"MtProto卸载失败!请向开发者问询!"****** - currentStatus = "MtProto" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"MtProto卸载成功!"****** - SetUpProgressBarProcessing(65); - currentStatus = "MtProto" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装MtProto!"******04 - SetUpProgressBarProcessing(65); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "MtProto!"; - MainWindowsShowInfo(currentStatus); - } - #endregion - - #region 卸载Xay - - //******"检测系统是否已经安装Xray......"******03 - SetUpProgressBarProcessing(66); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "Xray......"; - MainWindowsShowInfo(currentStatus); - - //sshShellCommand = @"find / -name v2ray"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - functionResult = FileCheckExists(client, @"/usr/local/bin/xray"); - if (functionResult == true) - { - //******"检测到已安装V2Ray!开始卸载Xray......"****** - SetUpProgressBarProcessing(68); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DiscoverProxySoft").ToString() - + "Xray!" - + Application.Current.FindResource("DisplayInstallInfo_StartRemoveProxy").ToString() - + "Xray......"; - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"systemctl stop xray"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return; - } - - sshShellCommand = $"bash {saveShellScriptFileName} --remove"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl disable xray"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"rm -rf /usr/local/etc/xray /var/log/xray"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, @"/usr/local/bin/xray"); - if (functionResult == true) - //if (currentShellCommandResult.Contains("/usr/local/bin/v2ray") == true) - { - //******"V2Ray卸载失败!请向开发者问询!"****** - currentStatus = "Xray" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //******"V2Ray卸载成功!"****** - SetUpProgressBarProcessing(70); - currentStatus = "Xray" + Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - - } - else - { - //******"检测结果:未安装Xray!"******04 - SetUpProgressBarProcessing(70); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "Xray!"; - MainWindowsShowInfo(currentStatus); - } - - #endregion - - //如果是纯ipv6主机,则需要删除前面设置的Nat64网关 - if (onlyIpv6 == true) - { - SetUpNat64(client, false); - //sshShellCommand = $"{sshCmdUpdate}"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - - //******"卸载成功!"******04 - SetUpProgressBarProcessing(100); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - client.Disconnect(); - - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_RemoveProxySoftSuccess").ToString()); - - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - #region 启用Root密码登录 - private void ButtonEnableRootPassWord_Click(object sender, RoutedEventArgs e) - { - //******"本功能需要当前登录的账户具有sudo权限,是否为远程主机启用root账户并设置密码?"****** - string messageShow = Application.Current.FindResource("MessageBoxShow_EnableRootPassword").ToString(); - MessageBoxResult messageBoxResult = MessageBox.Show(messageShow, "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text); ;//传递主机地址 - ReceiveConfigurationParameters[2] = PasswordBoxHostPassword.Password;//传递当前账户密码 - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => EnableRootPassWord(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - } - //启用Root密码登录进程 - private void EnableRootPassWord(ConnectionInfo connectionInfo) - { - functionResult = true; - getApt = false; - getDnf = false; - getYum = false; - onlyIpv6 = false; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - //******"检测是否运行在root权限下..."******01 - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootPermission").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"id -u"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == true) - { - //******"当前账户已经具有root权限,无需再设置!"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_AlreadyRoot").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - } - - SetUpProgressBarProcessing(10); - string hostPassword = "'" + ReceiveConfigurationParameters[2] + "'"; - //MessageBox.Show(hostPassword); - sshShellCommand = $"echo {hostPassword} | sudo -S id -u"; - //MessageBox.Show(sshShellCommand); - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == false) - { - //******"当前账户无法获取sudo权限,设置失败!"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_NoSudoToAccount").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - } - - SetUpProgressBarProcessing(20); - string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';'; - sshShellCommand = cmdPre + @"sudo sed -i 's/PermitRootLogin /#PermitRootLogin /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo sed -i 's/PasswordAuthentication /#PasswordAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(30); - sshShellCommand = cmdPre + @"sudo sed -i 's/PermitEmptyPasswords /#PermitEmptyPasswords /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(40); - sshShellCommand = cmdPre + @"echo 'PasswordAuthentication yes' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"echo 'PermitEmptyPasswords no' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(60); - sshShellCommand = cmdPre + @"sudo systemctl restart sshd"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //******"生成20位随机密码!"****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateRandomPassword").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"cat /dev/urandom | tr -dc '_A-Z#\-+=a-z(0-9%^>)]{<|' | head -c 20 ; echo ''"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(80); - string setPassword = currentShellCommandResult.TrimEnd('\r', '\n') + '\n'; - - sshShellCommand = cmdPre + $"echo -e \"{setPassword}{setPassword}\" | sudo passwd root"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - client.Disconnect(); - - //***保存密码信息*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootPasswordSavePasswordInfo").ToString(); - MainWindowsShowInfo(currentStatus); - - string filePath = ReceiveConfigurationParameters[4].Replace(':', '_'); - CheckDir(filePath); - using (StreamWriter sw = new StreamWriter($"{filePath}\\host_password_info.txt")) - { - sw.WriteLine(ReceiveConfigurationParameters[4]); - sw.WriteLine("root"); - sw.WriteLine(setPassword); - } - - SetUpProgressBarProcessing(100); - //***远程主机Root账户密码登录已启用,密码保存在随后打开的文件夹中!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootPasswordSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - System.Diagnostics.Process.Start("explorer.exe", filePath); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - #endregion - - #region 启用Root证书密钥登录 - private void ButtonEnableRootCert_Click(object sender, RoutedEventArgs e) - { - //******"本功能需要当前登录的账户具有root或者sudo权限,是否为远程主机启用root证书密钥登录?"****** - string messageShow = Application.Current.FindResource("MessageBoxShow_ButtonEnableRootCert").ToString(); - MessageBoxResult messageBoxResult = MessageBox.Show(messageShow, "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text);//传递主机地址 - ReceiveConfigurationParameters[2] = PasswordBoxHostPassword.Password; - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => EnableRootCert(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - } - - //启用Root证书密钥登录进程 - private void EnableRootCert(ConnectionInfo connectionInfo) - { - functionResult = true; - getApt = false; - getDnf = false; - getYum = false; - onlyIpv6 = false; - - string filePath = String.Empty; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - //******"检测是否运行在root权限下..."******01 - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootPermission").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"id -u"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == true) - { - SetUpProgressBarProcessing(20); - - //***正在生成密钥......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertGenerateCert").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"yes | ssh-keygen -b 2048 -t rsa -f /tmp/rootuser.key -q -N ''"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"yes | ssh-keygen -p -P '' -N '' -m PEM -f /tmp/rootuser.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"mkdir -p /root/.ssh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"cat /tmp/rootuser.key.pub | tee -a /root/.ssh/authorized_keys"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"chmod 777 /tmp/rootuser.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(30); - //***正在下载密钥......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertDownloadCert").ToString(); - MainWindowsShowInfo(currentStatus); - - filePath = CreateConfigSaveDir(@"root_cert", ReceiveConfigurationParameters[4].Replace(':', '_')); - string localConfigSavePathAndFileName = $"{filePath}\\rootuser.key"; - string remoteConfigPathAndFileName = @"/tmp/rootuser.key"; - DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName); - - localConfigSavePathAndFileName = $"{filePath}\\rootuser.key.pub"; - remoteConfigPathAndFileName = @"/tmp/rootuser.key.pub"; - DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName); - - sshShellCommand = @"rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(50); - //***远程主机启用密钥登录......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertSetCertEnable").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"sed -i 's/PermitRootLogin /#PermitRootLogin /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sed -i 's/StrictModes /#StrictModes /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(70); - sshShellCommand = @"sed -i 's/PubkeyAuthentication /#PubkeyAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sed -i 's/#AuthorizedKeysFile /AuthorizedKeysFile /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(80); - sshShellCommand = @"sed -i 's/#RSAAuthentication /RSAAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"echo 'PermitRootLogin yes' | tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(90); - sshShellCommand = @"echo 'StrictModes no' | tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"echo 'PubkeyAuthentication yes' | tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl restart sshd"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - else - { - SetUpProgressBarProcessing(10); - string hostPassword = "'" + ReceiveConfigurationParameters[2] + "'"; - //MessageBox.Show(hostPassword); - sshShellCommand = $"echo {hostPassword} | sudo -S id -u"; - //MessageBox.Show(sshShellCommand); - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - //MessageBox.Show(currentShellCommandResult); - if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == false) - { - //******"当前账户无法获取sudo权限,设置失败!"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_NoSudoToAccount").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - } - - SetUpProgressBarProcessing(20); - string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';'; - //***正在生成密钥......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertGenerateCert").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = cmdPre + @"sudo rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"yes | sudo ssh-keygen -b 2048 -t rsa -f /tmp/rootuser.key -q -N ''"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"yes | sudo ssh-keygen -p -P '' -N '' -m PEM -f /tmp/rootuser.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo mkdir -p /root/.ssh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"cat /tmp/rootuser.key.pub | sudo tee -a /root/.ssh/authorized_keys"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo chmod 777 /tmp/rootuser.key"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(30); - //***正在下载密钥......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertDownloadCert").ToString(); - MainWindowsShowInfo(currentStatus); - - filePath = CreateConfigSaveDir(@"root_cert", ReceiveConfigurationParameters[4].Replace(':', '_')); - string localConfigSavePathAndFileName = $"{filePath}\\rootuser.key"; - string remoteConfigPathAndFileName = @"/tmp/rootuser.key"; - DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName); - - localConfigSavePathAndFileName = $"{filePath}\\rootuser.key.pub"; - remoteConfigPathAndFileName = @"/tmp/rootuser.key.pub"; - DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName); - - sshShellCommand = cmdPre + @"sudo rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(50); - //***远程主机启用密钥登录......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertSetCertEnable").ToString(); - MainWindowsShowInfo(currentStatus); - - //string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';'; - sshShellCommand = cmdPre + @"sudo sed -i 's/PermitRootLogin /#PermitRootLogin /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo sed -i 's/StrictModes /#StrictModes /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(70); - sshShellCommand = cmdPre + @"sudo sed -i 's/PubkeyAuthentication /#PubkeyAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo sed -i 's/#AuthorizedKeysFile /AuthorizedKeysFile /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(80); - sshShellCommand = cmdPre + @"sudo sed -i 's/#RSAAuthentication /RSAAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(90); - sshShellCommand = cmdPre + @"echo 'StrictModes no' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"echo 'PubkeyAuthentication yes' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo systemctl restart sshd"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - client.Disconnect(); - - SetUpProgressBarProcessing(100); - //******"远程主机root账户证书密钥登录已启用,密钥文件rootuser.key保存在随后打开的文件夹中!"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_ButtonEnableRootCertSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - System.Diagnostics.Process.Start("explorer.exe", filePath); - - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - - } - - - #endregion - - #region 禁止root账户密码登录 - //root禁止密码登录 - private void ButtonRootProhibitsPasswordLogin_Click(object sender, RoutedEventArgs e) - { - //******"本功能需要远程主机已经开启了其他登录方式,如密钥方式等,否则将可能造成远程主机无法连接,是否禁止远程主机的root账户密码登录方式?"****** - string messageShow = Application.Current.FindResource("MessageBoxShow_ButtonRootProhibitsPasswordLogin").ToString(); - MessageBoxResult messageBoxResult = MessageBox.Show(messageShow, "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - //****** "远程主机连接信息有误,请检查!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - return; - } - - ReceiveConfigurationParameters[4] = PreTrim(TextBoxHost.Text);//传递主机地址 - ReceiveConfigurationParameters[2] = PasswordBoxHostPassword.Password;//传递主机密码 - - installationDegree = 0; - TextBoxMonitorCommandResults.Text = ""; - Thread thread = new Thread(() => RootProhibitsPasswordLogin(connectionInfo)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - } - - //禁止root密码登录进程 - private void RootProhibitsPasswordLogin(ConnectionInfo connectionInfo) - { - functionResult = true; - getApt = false; - getDnf = false; - getYum = false; - onlyIpv6 = false; - - string filePath = String.Empty; - - //******"正在登录远程主机......"****** - SetUpProgressBarProcessing(1); - string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); - MainWindowsShowInfo(currentStatus); - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - } - - //检测root权限 5--7 - //******"检测是否运行在root权限下..."******01 - SetUpProgressBarProcessing(5); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootPermission").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"id -u"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == true) - { - SetUpProgressBarProcessing(20); - - //***正在关闭root账户密码登录方式......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_SetRootProhibitsPasswordLogin").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"sed -i 's/PasswordAuthentication /#PasswordAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sed -i 's/PermitEmptyPasswords /#PermitEmptyPasswords /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"echo 'PasswordAuthentication no' | tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"echo 'PermitEmptyPasswords no' | tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl restart sshd"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - else - { - SetUpProgressBarProcessing(10); - string hostPassword = "'" + ReceiveConfigurationParameters[2] + "'"; - //MessageBox.Show(hostPassword); - sshShellCommand = $"echo {hostPassword} | sudo -S id -u"; - //MessageBox.Show(sshShellCommand); - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - //MessageBox.Show(currentShellCommandResult); - if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == false) - { - //******"当前账户无法获取sudo权限,设置失败!"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_NoSudoToAccount").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - client.Disconnect(); - return; - } - - SetUpProgressBarProcessing(20); - string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';'; - - //***正在关闭root账户密码登录方式......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_SetRootProhibitsPasswordLogin").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = cmdPre + @"sudo sed -i 's/PasswordAuthentication /#PasswordAuthentication /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo sed -i 's/PermitEmptyPasswords /#PermitEmptyPasswords /g' /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"echo 'PasswordAuthentication no' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"echo 'PermitEmptyPasswords no' | sudo tee -a /etc/ssh/sshd_config"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = cmdPre + @"sudo systemctl restart sshd"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - client.Disconnect(); - - SetUpProgressBarProcessing(100); - //******"远程主机root账户密码登录方式已关闭!"****** - currentStatus = Application.Current.FindResource("MessageBoxShow_RootProhibitsPasswordLoginOK").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - ProcessException(ex1.Message); - - //****** "主机登录失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); - MainWindowsShowInfo(currentStatus); - } - #endregion - } - #endregion - - //安装日志另存为... - private void ButtonSaveInstalledLog_Click(object sender, RoutedEventArgs e) - { - string logSaveName = ChooseSaveFile("Log Save as...", $"{pwdir}"); - if (String.IsNullOrEmpty(logSaveName) == false) - { - using (StreamWriter sw = new StreamWriter($"{logSaveName}")) - { - sw.WriteLine($"{TextBoxMonitorCommandResults.Text}"); - } - } - } - private string ChooseSaveFile(string title, string initFolder) - { - SaveFileDialog dlg = new SaveFileDialog(); - dlg.Title = title; - string localTime = DateTime.Now.ToLocalTime().ToString().Replace(' ', '-').Replace(':', '-').Replace('/', '-').Replace('\\', '-'); - dlg.FileName = $"{PreTrim(TextBoxHost.Text).Replace(':', '_')}_{localTime}.txt"; // Default file name - dlg.DefaultExt = ".txt"; // Default file extension - dlg.Filter = "Text documents|*.txt"; // Filter files by extension - dlg.InitialDirectory = initFolder; - - // Process save file dialog box results - if (dlg.ShowDialog() == true) - { - return dlg.FileName; - } - else - { - return null; - } - } - - #endregion - - #region 标签页控制 - - private void ButtonWebBrowserHomePage_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserResourcesAndTools.Source = new Uri("https://github.com/proxysu/windows/wiki/ResourcesAndTools"); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - private void ButtonWebBrowserBack_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserResourcesAndTools.GoBack(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void ButtonWebBrowserForward_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserResourcesAndTools.GoForward(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - - - #region 免翻网址资源标签 - private void ButtonWebBrowserHomePageFreeWallURL_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserResourcesAndToolsFreeWallURL.Source = new Uri("https://github.com/proxysu/windows/wiki/FreeWallURL"); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void ButtonWebBrowserBackFreeWallURL_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserResourcesAndToolsFreeWallURL.GoBack(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void ButtonWebBrowserForwardFreeWallURL_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserResourcesAndToolsFreeWallURL.GoForward(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - #endregion - - #region 常见问题标签 - private void ButtonWebBrowserHomePageCommonError_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserCommonError.Source = new Uri("https://github.com/proxysu/windows/wiki/CommonError"); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void ButtonWebBrowserBackCommonError_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserCommonError.GoBack(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - private void ButtonWebBrowserForwardCommonError_Click(object sender, RoutedEventArgs e) - { - try - { - WebBrowserCommonError.GoForward(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - - - #endregion - #endregion - - #region 测试用代码 - private void Button_Click(object sender, RoutedEventArgs e) - { - //string host = ClassModel.DisguiseURLprocessing("www.google.com/accout/"); - //MessageBox.Show(host); - //saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - //saveShellScriptFileName = "tmp." + saveShellScriptFileName + ".sh"; - //MessageBox.Show(saveShellScriptFileName); - //var rand = System.Security.Cryptography.RandomNumberGenerator.Create(); - //byte[] bytes = new byte[8]; - //rand.GetBytes(bytes); - //string randStr = Convert.ToBase64String(bytes); - //randStr = randStr.Replace("+","").Replace("/", "").Replace("=",""); - //MessageBox.Show(randStr); - proxyType = "V2Ray"; - ResultClientInformation resultClientInformation = new ResultClientInformation(); - resultClientInformation.ShowDialog(); - //return; - //string pwdir = AppDomain.CurrentDomain.BaseDirectory; - //MessageBox.Show(pwdir); - //ConnectionInfo connectionInfo = GenerateConnectionInfo(); - //if (connectionInfo == null) - //{ - // //****** "远程主机连接信息有误,请检查!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); - // return; - //} - //using (var client = new SshClient(connectionInfo)) - //{ - // client.Connect(); - // if (client.IsConnected == true) - // { - // //******"主机登录成功"****** - // SetUpProgressBarProcessing(3); - // currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - // MainWindowsShowInfo(currentStatus); - - // } - // string fileProxy = @"/usr/local/bin/v2ray"; - // sshShellCommand = $"if [[ -f {fileProxy} ]];then echo '1';else echo '0'; fi"; - // //sshShellCommand = @"if [[ -f /usr/local/bin/v2ray ]];then echo '1';else echo '0'; fi"; - // currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - // if (currentShellCommandResult.Trim().Equals("0") == true) - // { - // MessageBox.Show("0"); - // } - // else - // { - // MessageBox.Show("1"); - // } - // // SetUpNat64(client, true); - // //FilterFastestIP(client); - // //string cmdErr = client.RunCommand(@"aaa ee").Error; - // //MessageBox.Show(cmdErr); - // //SshCommand cmdResult = client.RunCommand(@"pwd"); - // //string result = cmdResult.Result; - // //MessageBox.Show("result:" + result); - // //string error = cmdResult.Error; - // //MessageBox.Show("err:" + error); - - // //int cmdExitStatus = cmdResult.ExitStatus; - // //MessageBox.Show("cmdExitStatus:" + cmdExitStatus.ToString()); - - // //SshCommand cmdResultCat = client.RunCommand(@"cat tt.t"); - // //string resultCat = cmdResultCat.Result; - // //MessageBox.Show("resultCat:" + resultCat); - // //string errorCat = cmdResultCat.Error; - // //MessageBox.Show("errCat:" + errorCat); - - // //cmdExitStatus = cmdResultCat.ExitStatus; - // //MessageBox.Show("cmdExitStatus:" + cmdExitStatus.ToString()); - - // //SoftInstalledSuccessOrFail(client, "v2ray", @"/usr/local/bin/v2ray"); - // //CaddyInstall(client); - // //if (client.IsConnected == true) - // //{ - // // MessageBox.Show("Connected"); - // //} - // //if (client.IsConnected == false) - // //{ - // // MessageBox.Show("disConnected"); - // //} - //} - } - - private string CaddyInstallTest(SshClient client) - { - - if (client.IsConnected == true) - { - //******"主机登录成功"****** - SetUpProgressBarProcessing(3); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"id -u"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - client.Disconnect(); - } - return ""; - } - #endregion - - #region 布署代理所用到的步骤函数 - - //检测主机是否为纯ipv6的主机 - private bool OnlyIpv6HostDetect(SshClient client) - { - //****** "正在检测是否为纯ipv6主机......." ******11 - //SetUpProgressBarProcessing(34); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_OnlyIpv6HostDetect").ToString(); - MainWindowsShowInfo(currentStatus); - - //再次初始化相关变量 - ipv4 = String.Empty; - ipv6 = String.Empty; - - //sshShellCommand = @"curl -4 ip.sb"; - sshShellCommand = @"curl -s https://api.ip.sb/ip --ipv4 --max-time 8"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - ipv4 = currentShellCommandResult.TrimEnd('\r', '\n'); - - sshShellCommand = @"curl -s https://api.ip.sb/ip --ipv6 --max-time 8"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - ipv6 = currentShellCommandResult.TrimEnd('\r', '\n'); - - if (String.IsNullOrEmpty(ipv4) == false) - { - return false; - } - else - { - if (String.IsNullOrEmpty(ipv6) == false) - { - - return true; - } - else - { - //FunctionResultErr(); - client.Disconnect(); - //****未检测到有效的IP地址......*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoIpDetect").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - return false; - } - } - - } - - //设置Nat64与删除设置Nat64 - private bool SetUpNat64(SshClient client,bool set) - { - if(set == true) - { - //****** "正在查找最快的Nat64网关......" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_FindFastestSetUpNat64").ToString(); - MainWindowsShowInfo(currentStatus); - //string[] dns64 = new string[2]; - var dns64 = FilterFastestIP(client); - - if (functionResult == false) - { - //****** "未能找到有效的Nat64网关......" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_FindFastestSetUpNat64Failed").ToString(); - MainWindowsShowInfo(currentStatus); - MessageBox.Show(currentStatus); - //FunctionResultErr(); - client.Disconnect(); - return false; - } - - //****** "正在设置Nat64网关......" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_SetUpNat64").ToString(); - MainWindowsShowInfo(currentStatus); - - functionResult = FileCheckExists(client, @"/etc/resolv.conf.proxysu"); - if (functionResult == false) - { - sshShellCommand = @"mv /etc/resolv.conf /etc/resolv.conf.proxysu"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - - foreach (string gateip in dns64) - { - sshShellCommand = $"echo \"nameserver {gateip}\" > /etc/resolv.conf"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"curl -fsSL https://api.github.com/repos/proxysu/windows/releases/latest"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - SshCommand currentShellCommand = client.RunCommand(sshShellCommand); - int cmdExitStatus = currentShellCommand.ExitStatus; - if (cmdExitStatus == 0) - { - return true; - } - - } - - } - else - { - //****** "正在删除Nat64网关......" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DeleteSetUpNat64").ToString(); - MainWindowsShowInfo(currentStatus); - sshShellCommand = @"rm /etc/resolv.conf"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - sshShellCommand = @"mv /etc/resolv.conf.proxysu /etc/resolv.conf"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - return true; - } - - //筛选最优的NAT64地址 - private string[] FilterFastestIP(SshClient client) - { - string[] gateNat64 = { - "2a01:4f9:c010:3f02::1", - "2001:67c:2b0::4", - "2001:67c:2b0::6", - "2a09:11c0:f1:bbf0::70", - "2a01:4f8:c2c:123f::1", - "2001:67c:27e4:15::6411", - "2001:67c:27e4::64", - "2001:67c:27e4:15::64", - "2001:67c:27e4::60", - "2a00:1098:2b::1", - "2a03:7900:2:0:31:3:104:161", - "2a00:1098:2c::1", - "2a09:11c0:100::53", - }; - - List NatDns64s = new List(); - foreach (string gateip in gateNat64) - { - sshShellCommand = $"ping6 -c4 {gateip} | grep avg | awk '{{print $4}}'|cut -d/ -f2"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - if (String.IsNullOrEmpty(currentShellCommandResult) != true) - { - if (float.TryParse(currentShellCommandResult, out float delay) == true) - { - - int delayInt = (int)(delay * 1000); - NatDns64 ipaddr = new NatDns64($"{gateip}", delayInt); - NatDns64s.Add(ipaddr); - } - } - - } - NatDns64s = NatDns64s.OrderBy(o => o.Avg).ToList(); - int listCount = NatDns64s.Count; - currentStatus = listCount.ToString() + " NAT64 gateways are valid"; - MainWindowsShowInfo(currentStatus); - if (listCount < 1) - { - functionResult = false; - } - else - { - functionResult = true; - } - string[] returnstr = new string[listCount]; - for(int i=0;i= 90) - { - //******"本地时间与远程主机时间相差超过限制(90秒),请先用 '系统工具-->时间校对' 校对时间后再设置"****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_TimeError").ToString()); - //"时间较对失败......" - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TimeError").ToString(); - MainWindowsShowInfo(currentStatus); - - //client.Disconnect(); - return false; - } - //******"时间差符合要求,OK!"******10 - SetUpProgressBarProcessing(33); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TimeOK").ToString(); - MainWindowsShowInfo(currentStatus); - return true; - } - - - //检测域名是否解析到当前IP上 34---36 - //functionResult = DomainResolutionCurrentIPDetect(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool DomainResolutionCurrentIPDetect(SshClient client) - { - //****** "正在检测域名是否解析到当前VPS的IP上......" ******11 - SetUpProgressBarProcessing(34); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestDomainResolve").ToString(); - MainWindowsShowInfo(currentStatus); - - //再次初始化相关变量 - //ipv4 = String.Empty; - //ipv6 = String.Empty; - //onlyIpv6 = false; - - //sshShellCommand = @"curl -4 ip.sb"; - //sshShellCommand = @"curl -s https://api.ip.sb/ip --ipv4 --max-time 8"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - //ipv4 = currentShellCommandResult.TrimEnd('\r', '\n'); - - //sshShellCommand = @"curl -s https://api.ip.sb/ip --ipv6 --max-time 8"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - //ipv6 = currentShellCommandResult.TrimEnd('\r', '\n'); - - if (onlyIpv6 == false) - { - string nativeIp = ipv4; - - sshShellCommand = "ping " + ReceiveConfigurationParameters[4] + " -c1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string resultTestDomainCmd = currentShellCommandResult.TrimEnd('\r', '\n'); - if (String.Equals(nativeIp, resultTestDomainCmd) == true) - { - //****** "解析正确!OK!" ******12 - SetUpProgressBarProcessing(36); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DomainResolveOK").ToString(); - MainWindowsShowInfo(currentStatus); - //onlyIpv6 = false; - return true; - } - - } - else - { - - string nativeIp = ipv6; - - //sshShellCommand = "ping6 " + ReceiveConfigurationParameters[4] + " -c1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - sshShellCommand = $"dig @resolver1.opendns.com AAAA {ReceiveConfigurationParameters[4]} +short -6"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string resultTestDomainCmd = currentShellCommandResult.TrimEnd('\r', '\n'); - if (String.Equals(nativeIp, resultTestDomainCmd) == true) - { - //****** "解析正确!OK!" ******12 - SetUpProgressBarProcessing(36); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DomainResolveOK").ToString(); - MainWindowsShowInfo(currentStatus); - //onlyIpv6 = true; - - return true; - } - - } - //****** "域名未能正确解析到当前VPS的IP上!安装失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorDomainResolve").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "域名未能正确解析到当前VPS的IP上,请检查!若解析设置正确,请等待生效后再重试安装。如果域名使用了CDN,请先关闭!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorDomainResolve").ToString()); - //client.Disconnect(); - return false; - - } - - - //安装代理程序 37--40 - //functionResult = ProxySoftInstall(client,@"",@""); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool ProxySoftInstall(SshClient client,string proxyName,string downloadUrl) - { - //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** - SetUpProgressBarProcessing(37); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "正在安装{proxyName}......" ****** - SetUpProgressBarProcessing(38); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + $"{proxyName}......"; - MainWindowsShowInfo(currentStatus); - - saveShellScriptFileName = GenerateRandomScriptFileName(GenerateRandomStr(10)); - - sshShellCommand = $"curl -o {saveShellScriptFileName} {downloadUrl}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - functionResult = FileCheckExists(client, $"{saveShellScriptFileName}"); - if (functionResult == false) - { - //***文件下载失败!*** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_DownloadScriptFailed").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - - } - sshShellCommand = $"yes | bash {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"rm -f {saveShellScriptFileName}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - SetUpProgressBarProcessing(40); - return true; - } - - //程序是否安装成功检测并设置开机启动 41--43 - //soft--要检测的程序 - //condition---成功安装的条件 - //functionResult = SoftInstalledSuccessOrFail(client,"v2ray",@"/usr/local/bin/v2ray"); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool SoftInstalledSuccessOrFail(SshClient client,string soft,string condition) - { - SetUpProgressBarProcessing(41); - //sshShellCommand = $"find / -name {soft}"; - //sshShellCommand = $"if [[ -f {condition} ]];then echo '1';else echo '0'; fi"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - bool functionResult = FileCheckExists(client, condition); - - //if (!currentShellCommandResult.Contains($"{condition}")) - if (functionResult == false) - { - //****** "安装失败,官方脚本运行出错!" ****** - MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorInstallSoftFail").ToString()); - //****** "安装失败,官方脚本运行出错!" ****** - currentStatus = Application.Current.FindResource("MessageBoxShow_ErrorInstallSoftFail").ToString(); - MainWindowsShowInfo(currentStatus); - - //client.Disconnect(); - return false; - } - else - { - //****** "安装成功!" ******20 - SetUpProgressBarProcessing(43); - currentStatus = $"{soft}" + Application.Current.FindResource("DisplayInstallInfo_SoftInstallSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - - //开机启动 - sshShellCommand = $"systemctl enable {soft}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - return true; - } - - - //生成服务端配置 44--46 - //functionResult = GenerateServerConfiguration(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - - - //上传服务配置 47--50 - private bool GenerateServerConfigurations(SshClient client) { return true; } - - //acme.sh安装与申请证书 51--57 - //functionResult = AcmeShInstall(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool AcmeShInstall(SshClient client) - { - - //****** "正在安装acme.sh......" ******22 - SetUpProgressBarProcessing(51); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallAcmeSh").ToString(); - MainWindowsShowInfo(currentStatus); - - //安装所依赖的软件 - sshShellCommand = $"{sshCmdUpdate}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"{sshCmdInstall}socat"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //解决搬瓦工CentOS缺少问题 - sshShellCommand = $"{sshCmdInstall}automake autoconf libtool"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("Install success") == true) - { - //****** "acme.sh安装成功!" ******23 - SetUpProgressBarProcessing(54); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_AcmeShInstallSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "acme.sh安装失败!原因未知,请向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorAcmeShInstallFail").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - } - - sshShellCommand = @"cd ~/.acme.sh/"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"alias acme.sh=~/.acme.sh/acme.sh"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //****** "申请域名证书......" ******24 - SetUpProgressBarProcessing(55); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartApplyCert").ToString(); - MainWindowsShowInfo(currentStatus); - - if (onlyIpv6 == true) - { - sshShellCommand = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {ReceiveConfigurationParameters[4]} --listen-v6"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - else - { - sshShellCommand = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {ReceiveConfigurationParameters[4]}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - if (currentShellCommandResult.Contains("Cert success") == true) - { - //****** "证书申请成功!" ******25 - SetUpProgressBarProcessing(57); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_ApplyCertSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "证书申请失败!原因未知,请向开发者提问!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_ApplyCertFail").ToString(); - MainWindowsShowInfo(currentStatus); - return false; - } - return true; - - } - - - - //安装证书到代理程序 58--60 - private bool CertInstallProxy(SshClient client) - { - return true; - } - - - //Caddy安装与检测安装是否成功 61--66 - //functionResult = CaddyInstall(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool CaddyInstall(SshClient client) - { - //****** "安装Caddy......" ******28 - SetUpProgressBarProcessing(61); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallCaddy").ToString(); - MainWindowsShowInfo(currentStatus); - - //为真则表示系统有相应的组件。 - if (getApt == true) - { - - sshShellCommand = @"echo ""deb [trusted=yes] https://apt.fury.io/caddy/ /"" | tee -a /etc/apt/sources.list.d/caddy-fury.list"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"apt-get install -y apt-transport-https"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"apt-get update"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"apt-get -y install caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - else if (getDnf == true) - { - - sshShellCommand = @"dnf install 'dnf-command(copr)' -y"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"dnf copr enable @caddy/caddy -y"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"dnf makecache"; - //currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"dnf -y install caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - else if (getYum == true) - { - - sshShellCommand = @"yum install yum-plugin-copr -y"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"yum copr enable @caddy/caddy -y"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //sshShellCommand = @"yum makecache"; - //currentShellCommandResult = MainWindowsShowCmd(client,sshShellCommand); - - sshShellCommand = @"yum -y install caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - - string caddyService = @"/lib/systemd/system/caddy.service"; - functionResult = FileCheckExists(client, $"{caddyService}"); - if (functionResult == false) - { - caddyService = @"/usr/lib/systemd/system/caddy.service"; - } - sshShellCommand = $"sed -i 's/AmbientCapabilities/#AmbientCapabilities/g' {caddyService}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/=caddy/=root/g' {caddyService}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/LimitNPROC/#LimitNPROC/g' {caddyService}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/LimitNOFILE/#LimitNOFILE/g' {caddyService}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"systemctl daemon-reload"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - - functionResult = FileCheckExists(client, @"/usr/bin/caddy"); - if (functionResult == true) - { - //****** "Caddy安装成功!" ******29 - SetUpProgressBarProcessing(66); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_InstalledCaddyOK").ToString(); - MainWindowsShowInfo(currentStatus); - - - sshShellCommand = @"systemctl enable caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - return true; - - } - functionResult = ProxySoftInstall(client, @"Caddy", @"https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return false; } - - functionResult = FileCheckExists(client, @"/usr/bin/caddy"); - if (functionResult == true) - { - //****** "Caddy安装成功!" ******29 - SetUpProgressBarProcessing(66); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_InstalledCaddyOK").ToString(); - MainWindowsShowInfo(currentStatus); - - - sshShellCommand = @"systemctl enable caddy"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - return true; - } - - //****** "安装Caddy失败!" ****** - MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_ErrorInstallCaddyFail").ToString()); - //****** "安装Caddy失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorInstallCaddyFail").ToString(); - MainWindowsShowInfo(currentStatus); - - //client.Disconnect(); - return false; - } - - - //上传Caddy配置文件67--70 - private bool UpConfigCaddy(SshClient client) - { - return true; - } - - //设置Caddy配置文件 - //functionResult = SetCaddyfile(client, @"/etc/caddy/Caddyfile"); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool SetCaddyfile(SshClient client,string upLoadPath) - { - - //设置Caddyfile文件中的tls 邮箱,在caddy2中已经不需要设置。 - - //设置Caddy监听的随机端口 - string randomCaddyListenPortStr = randomCaddyListenPort.ToString(); - - sshShellCommand = $"sed -i 's/8800/{randomCaddyListenPortStr}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //设置域名 - ReceiveConfigurationParameters[4] = ReceiveConfigurationParameters[4].TrimEnd(' '); - sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/g' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //设置Path - sshShellCommand = $"sed -i 's/##path##/\\{ReceiveConfigurationParameters[6]}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //设置伪装网站/纯ipv6主机暂不设置 - // && onlyIpv6 == false - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) - { - sshShellCommand = $"sed -i 's/##reverse_Proxy1##/reverse_proxy http:\\/\\/{ReceiveConfigurationParameters[7]} {{/ ' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/##reverse_Proxy2##/header_up Host {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = $"sed -i 's/##reverse_Proxy3##/}}/' {upLoadPath}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - } - return true; - } - - //程序启动检测 - //soft--要检测的程序 - //condition---成功启动的条件 - //functionResult = SoftStartDetect(client, "v2ray", @"/usr/local/bin/v2ray"); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool SoftStartDetect(SshClient client,string soft,string condition) - { - //****** "正在启动......" ******33 - //SetUpProgressBarProcessing(87); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartSoft").ToString() + $"{soft}......"; - MainWindowsShowInfo(currentStatus); - - //启动服务 - sshShellCommand = $"systemctl restart {soft}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - Thread.Sleep(3000); - - sshShellCommand = $"ps aux | grep {soft}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains($"{condition}") == true) - { - //****** "启动成功!" ******34 - //SetUpProgressBarProcessing(88); - currentStatus = $"{soft}" + Application.Current.FindResource("DisplayInstallInfo_StartSoftOK").ToString(); - MainWindowsShowInfo(currentStatus); - - } - else - { - //****** "启动失败!" ****** - currentStatus = $"{soft}" + Application.Current.FindResource("DisplayInstallInfo_StartSoftFail").ToString(); - MainWindowsShowInfo(currentStatus); - - Thread.Sleep(1000); - - //****** "正在启动(第二次尝试)!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartSoftSecond").ToString() + $"{soft}"; - MainWindowsShowInfo(currentStatus); - - Thread.Sleep(3000); - sshShellCommand = $"systemctl restart {soft}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - Thread.Sleep(3000); - - sshShellCommand = $"ps aux | grep {soft}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains($"{condition}") == true) - { - //****** "启动成功!" ****** - currentStatus = $"{soft}" + Application.Current.FindResource("DisplayInstallInfo_StartSoftOK").ToString(); - MainWindowsShowInfo(currentStatus); - - } - else - { - //****** "启动失败(第二次)!退出安装!" ****** - currentStatus = $"{soft}" + Application.Current.FindResource("DisplayInstallInfo_StartSoftSecondFail").ToString(); - MainWindowsShowInfo(currentStatus); - - //显示启动失败原因 - sshShellCommand = $"journalctl -n50 --no-pager --boot -u {soft}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - //****** "启动失败,原因如上!请排查原因!" ****** - currentStatus = $"{soft}" + Application.Current.FindResource("DisplayInstallInfo_StartSoftFailedExit").ToString(); - MainWindowsShowInfo(currentStatus); - - //****** "启动失败,原因如上!请排查原因!" ****** - MessageBox.Show($"{soft}" + Application.Current.FindResource("DisplayInstallInfo_StartSoftFailedExit").ToString()); - return false; - } - } - return true; - } - - //检测BBR,满足条件并启动 90--95 - //functionResult = DetectBBRandEnable(client); - //if (functionResult == false) { FunctionResultErr(); client.Disconnect(); return; } - private bool DetectBBRandEnable(SshClient client) - { - //测试BBR条件,若满足提示是否启用 - //****** "BBR测试......" ******37 - SetUpProgressBarProcessing(90); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestBBR").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"uname -r"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string[] linuxKernelVerStrBBR = currentShellCommandResult.Split('-'); - - bool detectResultBBR = DetectKernelVersionBBR(linuxKernelVerStrBBR[0]); - - sshShellCommand = @"sysctl net.ipv4.tcp_congestion_control | grep bbr"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - string resultCmdTestBBR = currentShellCommandResult; - //如果内核满足大于等于4.9,且还未启用BBR,则启用BBR - if (detectResultBBR == true && resultCmdTestBBR.Contains("bbr") == false) - { - //****** "正在启用BBR......" ******38 - SetUpProgressBarProcessing(93); - currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableBBR").ToString(); - MainWindowsShowInfo(currentStatus); - - sshShellCommand = @"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sysctl -p"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - sshShellCommand = @"sysctl net.ipv4.tcp_congestion_control | grep bbr"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - - if (currentShellCommandResult.Contains("bbr") == true) - { - //****** "BBR启用成功!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBREnabledSuccess").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "系统不满足启用BBR的条件,启用失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRFailed").ToString(); - MainWindowsShowInfo(currentStatus); - //return false; - } - } - else if (resultCmdTestBBR.Contains("bbr") == true) - { - //****** "BBR已经启用了!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRisEnabled").ToString(); - MainWindowsShowInfo(currentStatus); - } - else - { - //****** "系统不满足启用BBR的条件,启用失败!" ****** - currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRFailed").ToString(); - MainWindowsShowInfo(currentStatus); - //return false; - } - - //如果是纯ipv6主机,则需要删除前面设置的Nat64网关 - if (onlyIpv6 == true) - { - SetUpNat64(client, false); - sshShellCommand = $"{sshCmdUpdate}"; - currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand); - } - - SetUpProgressBarProcessing(95); - return true; - } - - - - - - //生成客户端配置 96--98 - - - #endregion - - - } - -} diff --git a/ProxySU/ProofreadTimeWindow.xaml b/ProxySU/ProofreadTimeWindow.xaml deleted file mode 100644 index 01d9842d..00000000 --- a/ProxySU/ProofreadTimeWindow.xaml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/ProofreadTimeWindow.xaml.cs b/ProxySU/ProofreadTimeWindow.xaml.cs deleted file mode 100644 index 04992161..00000000 --- a/ProxySU/ProofreadTimeWindow.xaml.cs +++ /dev/null @@ -1,258 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; -using System.Net; -using System.Net.Sockets; -using System.Net.NetworkInformation; -using System.Runtime.InteropServices; -using System.Runtime; -using System.Globalization; - -namespace ProxySU -{ - /// - /// ProofreadTimeWindow.xaml 的交互逻辑 - /// - public partial class ProofreadTimeWindow : Window - { - public static ConnectionInfo ProfreadTimeReceiveConnectionInfo { get; set; } - //ProfreadTimeReceiveParameters - - public ProofreadTimeWindow() - { - InitializeComponent(); - - } - - private void ButtonTestTime_Click(object sender, RoutedEventArgs e) - { - using (var client = new SshClient(ProfreadTimeReceiveConnectionInfo)) - { - client.Connect(); - client.RunCommand("rm -f /etc/localtime"); - client.RunCommand("ln -s /usr/share/zoneinfo/UTC /etc/localtime"); - //获取远程主机的时间戳 - long timeStampVPS = Convert.ToInt64(client.RunCommand("date +%s").Result.ToString()); - - //获取本地时间戳 - TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0); - long timeStampLocal = Convert.ToInt64(ts.TotalSeconds); - client.Disconnect(); - if (Math.Abs(timeStampLocal - timeStampVPS) >= 90) - { - - MessageBox.Show("本地时间与远程主机时间相差超过限制(90秒),V2ray无法建立连接"); - - return; - } - else - { - MessageBox.Show("误差为:" + Math.Abs(timeStampLocal - timeStampVPS).ToString()+" 可以连接"); - } - } - } - - private void ButtonProofreading_Click(object sender, RoutedEventArgs e) - { - if (RadioButtonUpDateLocalTime.IsChecked == true) - { - //将本机电脑与网络时间同步 - DateTime netUTCtime = NetTime.GetUTCTime(); - if (!DateTime.Equals(netUTCtime, new DateTime(1970, 1, 1, 0, 0, 0, 0))) - { - DateTime localTime = netUTCtime.ToLocalTime(); - bool setD = UpdateTime.SetDate(localTime); - if (setD == true) - { - MessageBox.Show("本机时间已经更新为网络时间(国家授时中心获取)"); - } - else - { - MessageBox.Show("更新失败,请重试。"); - } - } - return; - } - using (var client = new SshClient(ProfreadTimeReceiveConnectionInfo)) - { - client.Connect(); - //设置vps为UTC时区 - client.RunCommand("rm -f /etc/localtime"); - client.RunCommand("ln -s /usr/share/zoneinfo/UTC /etc/localtime"); - - if (RadioButtonLocalTime.IsChecked == true) - { - //以本地时间为准,校正远程主机时间 - //获取本地时间戳 - TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0); - long timeStampLocal = Convert.ToInt64(ts.TotalSeconds); - - string sshCmd = $"date --set=\"$(date \"+%Y-%m-%d %H:%M:%S\" -d @{timeStampLocal.ToString()})\""; - - client.RunCommand(sshCmd); - MessageBox.Show("同步本地时间校时完毕"); - - - } - else - { - //以网络时间为准,校正远程主机时间 - TimeSpan utcTS = NetTime.GetUTCTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0); - long timeStampVPS = Convert.ToInt64(utcTS.TotalSeconds); - if (timeStampVPS!=0) - { - - string sshCmd = $"date --set=\"$(date \"+%Y-%m-%d %H:%M:%S\" -d @{timeStampVPS.ToString()})\""; - - client.RunCommand(sshCmd); - MessageBox.Show("同步网络时间校时完毕"); - } - - } - client.Disconnect(); - } - - } - - private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e) - { - RadioButtonNetworkTime.IsChecked = true; - } - - private void TextBlock_MouseDown_1(object sender, MouseButtonEventArgs e) - { - RadioButtonLocalTime.IsChecked = true; - } - - private void TextBlock_MouseDown_2(object sender, MouseButtonEventArgs e) - { - RadioButtonUpDateLocalTime.IsChecked = true; - } - - //private void ButtonTEST_Click(object sender, RoutedEventArgs e) - //{ - // //NetTime netTime = new NetTime(); - // string netDatetime = NetTime.GetUTCTime().ToString(); - // MessageBox.Show(netDatetime); - // //NetTime netTime = new NetTime(); - // //UpdateTime updateTime = new UpdateTime(); - // //DateTime netDateTime = netTime.GetBeijingTime(); - // //MessageBox.Show(netDateTime.ToString()); - //} - - } - - /// - /// 网络时间 代码从网上复制,原网址:https://www.codeleading.com/article/23791981303/ - /// - public class NetTime - { - /// - /// 从国家授时中心获取标准GMT时间,读取https://www.tsa.cn - /// GMT时间与UTC时间没有差别,可以UTC=GMT - /// - /// 返回网络时间 - public static DateTime GetUTCTime() - { - DateTime time; - ////Thread.Sleep(5000); - try - { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.tsa.cn"); - request.Method = "HEAD"; - request.AllowAutoRedirect = false; - HttpWebResponse reponse = (HttpWebResponse)request.GetResponse(); - string cc = reponse.GetResponseHeader("date"); - reponse.Close(); - - bool s = GMTStrParse(cc, out time); - return time; - } - catch (Exception ex1) - { - if (ex1.ToString().Contains("403")) - { - MessageBox.Show("校时操作太频繁,请稍等片刻再操作!"); - } - else - { - MessageBox.Show(ex1.Message); - } - return time = new DateTime(1970, 1, 1, 0, 0, 0, 0); - } - - //return time.AddHours(8); //GMT要加8个小时才是北京时间 - } - public static bool GMTStrParse(string gmtStr, out DateTime gmtTime) //抓取的date是GMT格式的字符串,这里转成datetime - { - CultureInfo enUS = new CultureInfo("en-US"); - bool s = DateTime.TryParseExact(gmtStr, "r", enUS, DateTimeStyles.None, out gmtTime); - return s; - } - - } - - /// - /// 更新系统时间,代码从网上复制,原网址:https://www.open-open.com/code/view/1430552965599 - /// - public class UpdateTime - { - //设置系统时间的API函数 - [DllImport("kernel32.dll")] - private static extern bool SetLocalTime(ref SYSTEMTIME time); - - [StructLayout(LayoutKind.Sequential)] - private struct SYSTEMTIME - { - public short year; - public short month; - public short dayOfWeek; - public short day; - public short hour; - public short minute; - public short second; - public short milliseconds; - } - - /// - /// 设置系统时间 - /// - /// 需要设置的时间 - /// 返回系统时间设置状态,true为成功,false为失败 - public static bool SetDate(DateTime dt) - { - SYSTEMTIME st; - - st.year = (short)dt.Year; - st.month = (short)dt.Month; - st.dayOfWeek = (short)dt.DayOfWeek; - st.day = (short)dt.Day; - st.hour = (short)dt.Hour; - st.minute = (short)dt.Minute; - st.second = (short)dt.Second; - st.milliseconds = (short)dt.Millisecond; - bool rt = SetLocalTime(ref st); - return rt; - } - } - -} diff --git a/ProxySU/ProxySU.csproj b/ProxySU/ProxySU.csproj deleted file mode 100644 index 1dac41db..00000000 --- a/ProxySU/ProxySU.csproj +++ /dev/null @@ -1,202 +0,0 @@ - - - - - Debug - AnyCPU - {DD5505BC-E7F1-4D03-ABC7-B636E893FC09} - WinExe - ProxySU - ProxySU - v4.0 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - true - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - ProxySU.ico - - - - ..\json.net\net40\Newtonsoft.Json.dll - - - ..\qrcoder\net40\QRCoder.dll - - - ..\ssh.net\net40\Renci.SshNet.dll - - - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - - ProofreadTimeWindow.xaml - - - ResultClientInformation.xaml - - - SSpluginWindow.xaml - - - XayTemplateWindow.xaml - - - V2RayTemplateWindow.xaml - - - TrojanGoTemplateWindow.xaml - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - MSBuild:Compile - Designer - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - False - .NET Framework 3.5 SP1 - false - - - - - - - - - del "$(TargetDir)*.xml" -del "$(TargetDir)*.pdb" -del "$(TargetDir)*.zip" -mkdir "$(TargetDir)TemplateConfg" -xcopy /Y /E /R "$(TargetDir)..\..\..\TemplateConfg\*.*" "$(TargetDir)TemplateConfg\" -"$(TargetDir)..\..\..\7z\7z.exe" a $(TargetDir)Release.zip $(TargetDir) -xr!*config -rmdir /S /Q "$(TargetDir)..\Beta" -mkdir "$(TargetDir)..\Beta" -copy /Y "$(TargetDir)Release.zip" "$(TargetDir)..\Beta\Beta.zip" - - - rmdir /S /Q "$(TargetDir) - - \ No newline at end of file diff --git a/ProxySU/ProxySU.csproj.user b/ProxySU/ProxySU.csproj.user deleted file mode 100644 index 2c7a9c0a..00000000 --- a/ProxySU/ProxySU.csproj.user +++ /dev/null @@ -1,13 +0,0 @@ - - - - publish\ - - - - - - zh-CN - false - - \ No newline at end of file diff --git a/ProxySU/ProxySU.ico b/ProxySU/ProxySU.ico deleted file mode 100644 index 9d7a128c..00000000 Binary files a/ProxySU/ProxySU.ico and /dev/null differ diff --git a/ProxySU/ResultClientInformation.xaml b/ProxySU/ResultClientInformation.xaml deleted file mode 100644 index eede1c4c..00000000 --- a/ProxySU/ResultClientInformation.xaml +++ /dev/null @@ -1,570 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/ResultClientInformation.xaml.cs b/ProxySU/ResultClientInformation.xaml.cs deleted file mode 100644 index 719ece9c..00000000 --- a/ProxySU/ResultClientInformation.xaml.cs +++ /dev/null @@ -1,4942 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Web; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; -using System.Runtime.InteropServices; - - -namespace ProxySU -{ - /// - /// ResultClientInformation.xaml 的交互逻辑 - /// - public partial class ResultClientInformation : Window - { - private static string saveFileFolder = ""; - private static string configDomainSavePath = ""; - private static string server = MainWindow.ReceiveConfigurationParameters[4]; - - private static string TextBoxURLDefault; - private static string TextBoxURLVlessTcp; - private static string TextBoxURLVlessWs; - private static string TextBoxURLVmessTcp; - private static string TextBoxURLVmessWs; - private static string TextBoxURLTrojanTcp; - - private static BitmapSource ImageShareQRcodeDefault; - private static BitmapSource ImageShareQRcodeVlessTcp; - private static BitmapSource ImageShareQRcodeVlessWs; - private static BitmapSource ImageShareQRcodeVmessTcp; - private static BitmapSource ImageShareQRcodeVmessWs; - private static BitmapSource ImageShareQRcodeTrojanTcp; - - - [DllImport("user32.dll")] - private static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time); //引用DLL - - public ResultClientInformation() - { - InitializeComponent(); - - if (String.Equals(MainWindow.proxyType, "V2Ray")) - { - //显示V2Ray参数,隐藏其他 - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Visible; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - //主机地址 - TextBoxHostAddress.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxPort.Text = MainWindow.ReceiveConfigurationParameters[1]; - //用户ID(uuid)/Trojan密码 - TextBoxUUID.Text = MainWindow.ReceiveConfigurationParameters[2]; - //额外ID - TextBoxUUIDextra.Text = "0"; - //加密方式,一般都为auto - TextBoxEncryption.Text = "auto"; - - //传输协议 - TextBoxTransmission.Text = ""; - //伪装类型 - TextBoxCamouflageType.Text = MainWindow.ReceiveConfigurationParameters[5]; - - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = ""; - - //QUIC密钥/mKCP Seed/路径Path - TextBoxQuicKeyMkcpSeedPath.Text = MainWindow.ReceiveConfigurationParameters[6]; - - //TLS设置 - TextBoxTLS.Text = "none"; - - //初始化时,隐藏多方案客户端选择面板 - GroupBoxSelectVlessVmessXtlsTcpWs.Visibility = Visibility.Collapsed; - //显示非Trojan的所有参数 - GridNotTrojanParameters.Visibility = Visibility.Visible; - - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == false) - { - #region 单模式方案 - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCP") == true) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "none"; - ShowHostName(); - ShowPathV2ray(); - - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCPhttp") == true) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "http"; - TextBoxTLS.Text = "none"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryption.Text = "none"; - TextBoxTLS.Text = "xtls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) - { - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryption.Text = "none"; - TextBoxTLS.Text = "tls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryption.Text = "none"; - TextBoxTLS.Text = "tls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryption.Text = "none"; - TextBoxTLS.Text = "tls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "webSocket") == true) - { - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "none"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS") == true) - { - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true) - { - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Http2") == true) - { - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2Web") == true) - { - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4];//获取Host - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowHostName(); - ShowPathV2ray(); - } - else if (MainWindow.ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - if(MainWindow.mKCPvlessIsSet == true) - { - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBoxEncryption.Text = "none"; - HideAlterId(); - HideGroupBoxClientQRandURL(); - } - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPNone") == true) - { - TextBoxCamouflageType.Text = "none"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2SRTP") == true) - { - TextBoxCamouflageType.Text = "srtp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPuTP") == true) - { - TextBoxCamouflageType.Text = "utp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WechatVideo") == true) - { - TextBoxCamouflageType.Text = "wechat-video"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2DTLS") == true) - { - TextBoxCamouflageType.Text = "dtls"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WireGuard") == true) - { - TextBoxCamouflageType.Text = "wireguard"; - } - - TextBoxTransmission.Text = "kcp"; - TextBoxQuicKeyMkcpSeedPath.Text = MainWindow.ReceiveConfigurationParameters[6];//获取mkcp Seed - TextBoxTLS.Text = "none"; - ShowHostName(); - ShowMkcpSeed(); - } - else if (MainWindow.ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicNone") == true) - { - TextBoxCamouflageType.Text = "none"; - - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicSRTP") == true) - { - TextBoxCamouflageType.Text = "srtp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Quic2uTP") == true) - { - TextBoxCamouflageType.Text = "utp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWechatVideo") == true) - { - TextBoxCamouflageType.Text = "wechat-video"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicDTLS") == true) - { - TextBoxCamouflageType.Text = "dtls"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWireGuard") == true) - { - TextBoxCamouflageType.Text = "wireguard"; - } - - TextBoxTransmission.Text = "quic"; - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[3];//获取Quic加密方式 - TextBoxQuicKeyMkcpSeedPath.Text = MainWindow.ReceiveConfigurationParameters[6];//获取Quic加密密钥 - TextBoxTLS.Text = "none"; - ShowQuicEncryption(); - ShowQuicKey(); - } - - else - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "none"; - ShowHostName(); - ShowPathV2ray(); - } - CheckDir("v2ray_config"); - - GenerateV2rayShareQRcodeAndBase64Url(); - #endregion - } - else - { - //显示多方案客户端选择面板 - GroupBoxSelectVlessVmessXtlsTcpWs.Visibility = Visibility.Visible; - - string proxyfolder = CheckDir("v2ray_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxHostAddress.Text); - - V2raySetVlessTcpXtls(); - //GenerateV2rayVlessTcpXtlsShareQRcodeAndBase64Url(); - - V2raySetVlessTcpTls(); - GenerateV2rayVlessTcpTlsShareQRcodeAndBase64Url(); - - V2raySetVlessWsTls(); - GenerateV2rayVlessWsTlsShareQRcodeAndBase64Url(); - - V2raySetVmessTcpTls(); - GenerateV2rayVmessTcpTlsShareQRcodeAndBase64Url(); - - V2raySetVmessWsTls(); - GenerateV2rayVmessWsTlsShareQRcodeAndBase64Url(); - - GenerateV2rayTrojanShareQRcodeAndBase64Url(); - RadioButtonVlessTcpTls.IsChecked = true; - } - - } - else if (String.Equals(MainWindow.proxyType, "Xray")) - { - //显示Xray参数,隐藏其他 - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Visible; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - //主机地址 - TextBoxHostAddressXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxPortXray.Text = MainWindow.ReceiveConfigurationParameters[1]; - //用户ID(uuid)/Trojan密码 - TextBoxUUIDXray.Text = MainWindow.ReceiveConfigurationParameters[2]; - //额外ID - TextBoxUUIDextraXray.Text = "0"; - //加密方式,一般都为auto - TextBoxEncryptionXray.Text = "auto"; - - //传输协议 - TextBoxTransmissionXray.Text = ""; - //伪装类型 - TextBoxCamouflageTypeXray.Text = MainWindow.ReceiveConfigurationParameters[5]; - - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = ""; - - //QUIC密钥/mKCP Seed/路径Path - TextBoxQuicKeyMkcpSeedPathXray.Text = MainWindow.ReceiveConfigurationParameters[6]; - - //TLS设置 - TextBoxTLSXray.Text = "none"; - - //初始化时,隐藏多方案客户端选择面板 - GroupBoxSelectVlessVmessXtlsTcpWsXray.Visibility = Visibility.Collapsed; - //显示非Trojan的所有参数 - GridNotTrojanParametersXray.Visibility = Visibility.Visible; - - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessVmessXtlsTcpWebSocketWeb") == false) - { - #region 单模式方案 - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCP") == true) - { - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - TextBoxTLSXray.Text = "none"; - ShowHostNameXray(); - ShowPathXray(); - - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCPhttp") == true) - { - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "http"; - TextBoxTLSXray.Text = "none"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLSselfSigned") == true) - { - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessXtlsTcp") == true) - { - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryptionXray.Text = "none"; - TextBoxTLSXray.Text = "xtls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) - { - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryptionXray.Text = "none"; - TextBoxTLSXray.Text = "tls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == true) - { - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryptionXray.Text = "none"; - TextBoxTLSXray.Text = "tls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessHttp2Web") == true) - { - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - - TextBoxTransmissionXray.Text = "h2"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxEncryptionXray.Text = "none"; - TextBoxTLSXray.Text = "tls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - HideGroupBoxClientQRandURL(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "webSocket") == true) - { - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageTypeXray.Text = "none"; - TextBoxTLSXray.Text = "none"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS") == true) - { - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == true) - { - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned") == true) - { - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Http2") == true) - { - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "h2"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2Web") == true) - { - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "h2"; - TextBoxCamouflageTypeXray.Text = "none"; - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4];//获取Host - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2selfSigned") == true) - { - TextBoxTransmissionXray.Text = "h2"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowHostNameXray(); - ShowPathXray(); - } - else if (MainWindow.ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - if (MainWindow.mKCPvlessIsSet == true) - { - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBoxEncryptionXray.Text = "none"; - HideAlterIdXray(); - HideGroupBoxClientQRandURL(); - } - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPNone") == true) - { - TextBoxCamouflageTypeXray.Text = "none"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2SRTP") == true) - { - TextBoxCamouflageTypeXray.Text = "srtp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPuTP") == true) - { - TextBoxCamouflageTypeXray.Text = "utp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WechatVideo") == true) - { - TextBoxCamouflageTypeXray.Text = "wechat-video"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2DTLS") == true) - { - TextBoxCamouflageTypeXray.Text = "dtls"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WireGuard") == true) - { - TextBoxCamouflageTypeXray.Text = "wireguard"; - } - - TextBoxTransmissionXray.Text = "kcp"; - TextBoxQuicKeyMkcpSeedPathXray.Text = MainWindow.ReceiveConfigurationParameters[6];//获取mkcp Seed - TextBoxTLSXray.Text = "none"; - ShowHostNameXray(); - ShowMkcpSeedXray(); - } - else if (MainWindow.ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicNone") == true) - { - TextBoxCamouflageTypeXray.Text = "none"; - - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicSRTP") == true) - { - TextBoxCamouflageTypeXray.Text = "srtp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Quic2uTP") == true) - { - TextBoxCamouflageTypeXray.Text = "utp"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWechatVideo") == true) - { - TextBoxCamouflageTypeXray.Text = "wechat-video"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicDTLS") == true) - { - TextBoxCamouflageTypeXray.Text = "dtls"; - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWireGuard") == true) - { - TextBoxCamouflageTypeXray.Text = "wireguard"; - } - - TextBoxTransmissionXray.Text = "quic"; - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[3];//获取Quic加密方式 - TextBoxQuicKeyMkcpSeedPathXray.Text = MainWindow.ReceiveConfigurationParameters[6];//获取Quic加密密钥 - TextBoxTLSXray.Text = "none"; - ShowQuicEncryptionXray(); - ShowQuicKeyXray(); - } - - else - { - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - TextBoxTLSXray.Text = "none"; - ShowHostNameXray(); - ShowPathXray(); - } - CheckDir("xray_config"); - - GenerateXrayShareQRcodeAndBase64Url(); - #endregion - } - else - { - //显示多方案客户端选择面板 - GroupBoxSelectVlessVmessXtlsTcpWsXray.Visibility = Visibility.Visible; - - string proxyfolder = CheckDir("xray_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxHostAddressXray.Text); - - XraySetVlessTcpXtls(); - GenerateXrayVlessTcpXtlsShareQRcodeAndBase64Url(); - - XraySetVlessTcpTls(); - GenerateXrayVlessTcpTlsShareQRcodeAndBase64Url(); - - XraySetVlessWsTls(); - GenerateXrayVlessWsTlsShareQRcodeAndBase64Url(); - - XraySetVmessTcpTls(); - GenerateXrayVmessTcpTlsShareQRcodeAndBase64Url(); - - XraySetVmessWsTls(); - GenerateXrayVmessWsTlsShareQRcodeAndBase64Url(); - - GenerateXrayTrojanShareQRcodeAndBase64Url(); - RadioButtonVlessTcpXtlsXray.IsChecked = true; - } - - } - else if (String.Equals(MainWindow.proxyType, "TrojanGo")) - { - //GroupBoxTrojanClient.Header = "Trojan-go 客户端配置参数"; - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Visible; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - TextBlockTrojanGoHost.Visibility = Visibility.Hidden; - TextBoxTrojanGoHost.Visibility = Visibility.Hidden; - TextBoxTrojanGoWSPath.Visibility = Visibility.Hidden; - TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Hidden; - TextBlockTrojanGoCaption.Visibility = Visibility.Hidden; - - TextBlockMuxSelect.Visibility = Visibility.Hidden; - GridMuxSelect.Visibility = Visibility.Hidden; - TextBlockExplainCheckBoxMuxSelectResult.Visibility = Visibility.Hidden; - - //******"可用于ShadowRocket (ios)、igniter(Android)、Qv2ray (windows) 扫码和导入url。注意:有的客户端可能不支持WebSocket模式。" ****** - TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainTrojan-go").ToString(); - - //主机地址 - TextBoxTrojanGoServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxTrojanGoServerPort.Text = "443"; - //密钥(uuid) - TextBoxTrojanGoServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; - //SNI - TextBoxTrojanGoSNI.Text = MainWindow.ReceiveConfigurationParameters[4]; - //TrojanGo 使用类型 - TextBoxTrojanGoType.Text = "original"; - - //WebSocket设置 - if (MainWindow.ReceiveConfigurationParameters[0].Equals("TrojanGoWebSocketTLS2Web")) - { - TextBoxTrojanGoType.Text = "ws"; - //Host - TextBoxTrojanGoHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBlockTrojanGoHost.Visibility = Visibility.Visible; - TextBoxTrojanGoHost.Visibility = Visibility.Visible; - //Path - TextBoxTrojanGoWSPath.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTrojanGoWSPath.Visibility = Visibility.Visible; - TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Visible; - TextBlockTrojanGoCaption.Visibility = Visibility.Visible; - - } - if(String.Equals(MainWindow.ReceiveConfigurationParameters[9],"true") == true) - { - TextBoxConcurrency.Text = MainWindow.ReceiveConfigurationParameters[3]; - TextBoxIdle_timeout.Text = MainWindow.ReceiveConfigurationParameters[5]; - TextBlockMuxSelect.Visibility = Visibility.Visible; - GridMuxSelect.Visibility = Visibility.Visible; - TextBlockExplainCheckBoxMuxSelectResult.Visibility = Visibility.Visible; - } - CheckDir("trojan-go_config"); - GenerateTrojanGoShareQRcodeAndBase64Url(); - } - else if (String.Equals(MainWindow.proxyType, "Trojan")) - { - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Visible; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainTrojan").ToString(); - - //主机地址 - TextBoxTrojanServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxTrojanServerPort.Text = "443"; - //密钥(uuid) - TextBoxTrojanServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; - - CheckDir("trojan_config"); - GenerateTrojanShareQRcodeAndBase64Url(); - } - else if (String.Equals(MainWindow.proxyType, "NaiveProxy")) - { - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Visible; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainNaiveProxy").ToString(); - - TextBoxNaiveServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxNaiveUser.Text = MainWindow.ReceiveConfigurationParameters[3]; - TextBoxNaivePassword.Text = MainWindow.ReceiveConfigurationParameters[2]; - GenerateNaivePrxoyShareQRcodeAndBase64Url(); - } - else if (String.Equals(MainWindow.proxyType, "SSR")) - { - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Visible; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainSSR").ToString(); - - //主机地址 - TextBoxSSRHostAddress.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxSSRPort.Text = "443"; - //密码(uuid) - TextBoxSSRUUID.Text = MainWindow.ReceiveConfigurationParameters[2]; - //加密方式 - TextBoxSSREncryption.Text = "none"; - //传输协议 - TextBoxSSRTransmission.Text = "auth_chain_a"; - //混淆 - TextBoxSSRCamouflageType.Text = "tls1.2_ticket_auth"; - - //CheckDir("ssr_config"); - GenerateSSRShareQRcodeAndBase64Url(); - } - else if (String.Equals(MainWindow.proxyType, "SS")) - { - GroupBoxClientMTProto.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Visible; - - //主机地址 - TextBoxHostAddressSS.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxPortSS.Text = MainWindow.ReceiveConfigurationParameters[1]; - //密码(uuid) - TextBoxPasswordSS.Text = MainWindow.ReceiveConfigurationParameters[2]; - //加密方式 - TextBoxEncryptionSS.Text = MainWindow.ReceiveConfigurationParameters[3]; - //插件程序 - TextBoxPluginNameExplainSS.Text = MainWindow.ReceiveConfigurationParameters[5]; - //插件选项 - TextBoxPluginOptionExplainSS.Text = MainWindow.ReceiveConfigurationParameters[9]; - //创建ss配置文件总文件夹 - CheckDir("ss_config"); - - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == true) - { - TextBlockPluginNameExplainSS.Visibility = Visibility.Collapsed; - TextBoxPluginNameExplainSS.Visibility = Visibility.Collapsed; - - //TextBoxPluginNameExplainSSpc.Visibility = Visibility.Collapsed; - TextBlockPluginOptionExplainSS.Visibility = Visibility.Collapsed; - TextBoxPluginOptionExplainSS.Visibility = Visibility.Collapsed; - - TextBlockClientPromptSS.Visibility = Visibility.Collapsed; - RadioButtonMobile.Visibility = Visibility.Collapsed; - RadioButtonPC.Visibility = Visibility.Collapsed; - TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainSS").ToString(); - } - else - { - //显示插件程序与插件选项 - TextBlockPluginNameExplainSS.Visibility = Visibility.Visible; - TextBoxPluginNameExplainSS.Visibility = Visibility.Visible; - - TextBlockPluginOptionExplainSS.Visibility = Visibility.Visible; - TextBoxPluginOptionExplainSS.Visibility = Visibility.Visible; - - TextBlockClientPromptSS.Visibility = Visibility.Visible; - RadioButtonMobile.Visibility = Visibility.Visible; - RadioButtonPC.Visibility = Visibility.Visible; - - TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainSSmobile").ToString(); - TextBlockQrURLexplainSSpc.Text = Application.Current.FindResource("TextBlockQrURLexplainSSpc").ToString(); - - //转换成PC版plugin格式 - if (String.Equals(TextBoxPluginNameExplainSS.Text, "obfs-local")) - { - TextBoxPluginNameExplainSSpc.Text = @"plugins\obfs-local.exe"; - } - else if (String.Equals(TextBoxPluginNameExplainSS.Text, "v2ray-plugin")) - { - TextBoxPluginNameExplainSSpc.Text = @"plugins\v2ray-plugin.exe"; - } - else if (String.Equals(TextBoxPluginNameExplainSS.Text, "kcptun")) - { - TextBoxPluginNameExplainSSpc.Text = @"plugins\kcptun-client.exe"; - } - else if (String.Equals(TextBoxPluginNameExplainSS.Text, "goquiet")) - { - TextBoxPluginNameExplainSSpc.Text = @"plugins\goquiet-client.exe"; - } - else if (String.Equals(TextBoxPluginNameExplainSS.Text, "cloak")) - { - TextBoxPluginNameExplainSSpc.Text = @"plugins\cloak-client.exe"; - } - } - - GenerateShareQRcodeAndBase64UrlSS(); - //选择手机端做为默认显示 - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == false) - { - RadioButtonMobile.IsChecked = true; - if (String.Equals(TextBoxPluginNameExplainSS.Text, "goquiet")) - { - RadioButtonPC.IsChecked = true; - RadioButtonMobile.Visibility = Visibility.Collapsed; - TextBlockClientPromptSS.Visibility = Visibility.Collapsed; - //File.Delete($"ss_config\\{saveFileFolder}\\QR.bmp"); - //File.Delete($"ss_config\\{saveFileFolder}\\url.txt"); - } - else if (String.Equals(TextBoxPluginNameExplainSS.Text, "cloak")) - { - RadioButtonPC.IsChecked = true; - RadioButtonMobile.Visibility = Visibility.Collapsed; - TextBlockClientPromptSS.Visibility = Visibility.Collapsed; - //File.Delete($"ss_config\\{saveFileFolder}\\QR.bmp"); - //File.Delete($"ss_config\\{saveFileFolder}\\url.txt"); - } - - } - - } - else if (String.Equals(MainWindow.proxyType, "MTProto")) - { - //显示MTProto参数,隐藏其他 - GroupBoxClientMTProto.Visibility = Visibility.Visible; - GroupBoxClientQRandURL.Visibility = Visibility.Collapsed; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - GroupBoxV2rayClient.Visibility = Visibility.Collapsed; - GroupBoxXrayClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; - GroupBoxTrojanClient.Visibility = Visibility.Collapsed; - GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GroupBoxSSRClient.Visibility = Visibility.Collapsed; - GroupBoxClientSS.Visibility = Visibility.Collapsed; - - string proxyfolder = CheckDir("mtproto_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, MainWindow.ReceiveConfigurationParameters[4]); - string configSavePath = configDomainSavePath; - - RadioButtonMtgIpv4.IsChecked = true; - - JObject jObjectJson = JObject.Parse(MainWindow.ReceiveConfigurationParameters[9]); - - if (jObjectJson["ipv6"]["tg_url"].ToString().Contains("nil") == false) - { - RadioButtonMtgIpv6.Visibility = Visibility.Visible; - TextBoxURLMtgTgIpv6.Text = jObjectJson["ipv6"]["tg_url"].ToString(); - ImageShareQRcodeMtgTgIpv6.Source = CreateQRCode(TextBoxURLMtgTgIpv6.Text, $"{configSavePath}\\QRIpv6Tg.bmp"); - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv6Tg.txt")) - { - sw.WriteLine(TextBoxURLMtgTgIpv6.Text); - } - - TextBoxURLMtgTmeIpv6.Text = jObjectJson["ipv6"]["tme_url"].ToString(); - ImageShareQRcodeMtgTmeIpv6.Source = CreateQRCode(TextBoxURLMtgTmeIpv6.Text, $"{configSavePath}\\QRIpv6Tme.bmp"); - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv6Tme.txt")) - { - sw.WriteLine(TextBoxURLMtgTmeIpv6.Text); - } - RadioButtonMtgIpv6.IsChecked = true; - } - else - { - RadioButtonMtgIpv6.Visibility = Visibility.Collapsed; - } - - if (jObjectJson["ipv4"]["tg_url"].ToString().Contains("nil") == false) - { - RadioButtonMtgIpv4.Visibility = Visibility.Visible; - TextBoxURLMtgTgIpv4.Text = jObjectJson["ipv4"]["tg_url"].ToString(); - ImageShareQRcodeMtgTgIpv4.Source = CreateQRCode(TextBoxURLMtgTgIpv4.Text, $"{configSavePath}\\QRIpv4Tg.bmp"); - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv4Tg.txt")) - { - sw.WriteLine(TextBoxURLMtgTgIpv4.Text); - } - - TextBoxURLMtgTmeIpv4.Text = jObjectJson["ipv4"]["tme_url"].ToString(); - ImageShareQRcodeMtgTmeIpv4.Source = CreateQRCode(TextBoxURLMtgTmeIpv4.Text, $"{configSavePath}\\QRIpv4Tme.bmp"); - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\urlIpv4Tme.txt")) - { - sw.WriteLine(TextBoxURLMtgTmeIpv4.Text); - } - RadioButtonMtgIpv4.IsChecked = true; - } - else - { - RadioButtonMtgIpv4.Visibility = Visibility.Collapsed; - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\mtproto_info.json")) - { - sw.Write(MainWindow.ReceiveConfigurationParameters[9].ToString()); - } - - } - } - - #region V2Ray 相关 - - #region V2ray参数设置函数 - - //设置VLESS over TCP with XTLS - private void V2raySetVlessTcpXtls() - { - GridNotTrojanParameters.Visibility = Visibility.Visible; - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBlockVmessOrVless.Visibility = Visibility.Visible; - //隐藏下面的二维码显示 - HideGroupBoxClientQRandURL(); - //ImageShareQRcode.Source = ImageShareQRcodeDefault; - //TextBoxURL.Text = TextBoxURLDefault; - - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "xtls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - TextBoxQuicKeyMkcpSeedPath.Text = ""; - - - } - - //设置VLESS over TCP with TLS - private void V2raySetVlessTcpTls() - { - GridNotTrojanParameters.Visibility = Visibility.Visible; - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBlockVmessOrVless.Visibility = Visibility.Visible; - //隐藏下面的二维码显示 - HideGroupBoxClientQRandURL(); - //TextBoxURL.Text = TextBoxURLVlessTcp; - //ImageShareQRcode.Source = ImageShareQRcodeVlessTcp; - - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - TextBoxQuicKeyMkcpSeedPath.Text = ""; - } - - //设置VLESS over WS with TLS - private void V2raySetVlessWsTls() - { - GridNotTrojanParameters.Visibility = Visibility.Visible; - TextBlockVmessOrVless.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBlockVmessOrVless.Visibility = Visibility.Visible; - //隐藏下面的二维码显示 - HideGroupBoxClientQRandURL(); - //TextBoxURL.Text = TextBoxURLVlessWs; - //ImageShareQRcode.Source = ImageShareQRcodeVlessWs; - - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - HideAlterId(); - ShowHostName(); - ShowPathV2ray(); - TextBoxQuicKeyMkcpSeedPath.Text = MainWindow.ReceiveConfigurationParameters[3]; - - } - - //设置VMess over TCP with TLS - private void V2raySetVmessTcpTls() - { - GridNotTrojanParameters.Visibility = Visibility.Visible; - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "http"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowAlterId(); - ShowHostName(); - ShowPathV2ray(); - TextBoxQuicKeyMkcpSeedPath.Text = MainWindow.ReceiveConfigurationParameters[9]; - TextBlockVmessOrVless.Visibility = Visibility.Collapsed; - //显示下面的二维码显示。 - //HideGroupBoxClientQRandURL(); - ShowGroupBoxClientQRandURL(); - TextBoxURL.Text = TextBoxURLVmessTcp; - ImageShareQRcode.Source = ImageShareQRcodeVmessTcp; - } - - //设置VMess over WS with TLS - private void V2raySetVmessWsTls() - { - GridNotTrojanParameters.Visibility = Visibility.Visible; - TextBoxEncryption.Text = "none"; - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryption.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowAlterId(); - ShowHostName(); - ShowPathV2ray(); - TextBoxQuicKeyMkcpSeedPath.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBlockVmessOrVless.Visibility = Visibility.Collapsed; - ShowGroupBoxClientQRandURL(); - TextBoxURL.Text = TextBoxURLVmessWs; - ImageShareQRcode.Source = ImageShareQRcodeVmessWs; - } - - //设置Trojan over TCP with TLS - private void V2raySetTrojanTcpTls() - { - //隐藏所有不是Trojan的参数 - GridNotTrojanParameters.Visibility = Visibility.Collapsed; - //显示下面的二维码与分享链接 - ShowGroupBoxClientQRandURL(); - TextBoxURL.Text = TextBoxURLTrojanTcp; - ImageShareQRcode.Source = ImageShareQRcodeTrojanTcp; - } - #endregion - - #region 界面控制相关 - - //显示Quic 加密方式 - private void ShowQuicEncryption() - { - TextBlockQuicEncryption.Visibility = Visibility.Visible; - TextBlockHost.Visibility = Visibility.Collapsed; - } - - //显示Host隐藏Quic加密方式 - private void ShowHostName() - { - TextBlockHost.Visibility = Visibility.Visible; - TextBlockQuicEncryption.Visibility = Visibility.Collapsed; - } - - //显示路径Path,隐藏mKCP/Quic Key/复制按钮 - private void ShowPathV2ray() - { - TextBlockPath.Visibility = Visibility.Visible; - TextBlockMkcpSeed.Visibility = Visibility.Collapsed; - TextBlockQuicKey.Visibility = Visibility.Collapsed; - } - - //显示mKCP Seed/复制按钮,隐藏Path/Quic Key - private void ShowMkcpSeed() - { - TextBlockPath.Visibility = Visibility.Collapsed; - TextBlockMkcpSeed.Visibility = Visibility.Visible; - TextBlockQuicKey.Visibility = Visibility.Collapsed; - } - - //显示Quic Key/复制按钮 隐藏Path/mKcp Seed - private void ShowQuicKey() - { - TextBlockPath.Visibility = Visibility.Collapsed; - TextBlockMkcpSeed.Visibility = Visibility.Collapsed; - TextBlockQuicKey.Visibility = Visibility.Visible; - } - - //显示额外ID - private void ShowAlterId() - { - TextBlockUUIDextra.Visibility = Visibility.Visible; - TextBoxUUIDextra.Visibility = Visibility.Visible; - TextBlockUUIDextraExplanation.Visibility = Visibility.Visible; - - } - - //隐藏额外ID - private void HideAlterId() - { - TextBlockUUIDextra.Visibility = Visibility.Collapsed; - TextBoxUUIDextra.Visibility = Visibility.Collapsed; - TextBlockUUIDextraExplanation.Visibility = Visibility.Collapsed; - - } - - //显示加密方式 - private void ShowEncryption() - { - TextBlockEncryption.Visibility = Visibility.Visible; - TextBoxEncryption.Visibility = Visibility.Visible; - } - //隐藏加密方式 - private void HideEncryption() - { - TextBlockEncryption.Visibility = Visibility.Collapsed; - TextBoxEncryption.Visibility = Visibility.Collapsed; - } - - //显示传输协议 - private void ShowTransferProtocol() - { - TextBlockTransferProtocol.Visibility = Visibility.Visible; - TextBoxTransmission.Visibility = Visibility.Visible; - } - //隐藏传输协议 - private void HideTransferProtocol() - { - TextBlockTransferProtocol.Visibility = Visibility.Collapsed; - TextBoxTransmission.Visibility = Visibility.Collapsed; - } - //显示伪装类型 - private void ShowTextBlockCamouflageType() - { - TextBlockCamouflageType.Visibility = Visibility.Visible; - TextBoxCamouflageType.Visibility = Visibility.Visible; - } - //隐藏伪装类型 - private void HideTextBlockCamouflageType() - { - TextBlockCamouflageType.Visibility = Visibility.Collapsed; - TextBoxCamouflageType.Visibility = Visibility.Collapsed; - } - - //显示二维码与链接分享 - private void ShowGroupBoxClientQRandURL() - { - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - } - //隐藏二维码与链接分享 - private void HideGroupBoxClientQRandURL() - { - GroupBoxClientQRandURL.Visibility = Visibility.Hidden; - } - - //以下几个为对RadioButton按钮的选中后,界面变化与参数显示 - private void RadioButtonVlessTcpXtls_Checked(object sender, RoutedEventArgs e) - { - V2raySetVlessTcpXtls(); - } - - private void RadioButtonVlessTcpTls_Checked(object sender, RoutedEventArgs e) - { - V2raySetVlessTcpTls(); - } - - private void RadioButtonVlessWsTls_Checked(object sender, RoutedEventArgs e) - { - V2raySetVlessWsTls(); - } - - private void RadioButtonVmessTcpTls_Checked(object sender, RoutedEventArgs e) - { - V2raySetVmessTcpTls(); - } - - private void RadioButtonVmessWsTls_Checked(object sender, RoutedEventArgs e) - { - V2raySetVmessWsTls(); - } - - private void RadioButtonTrojanTcpTls_Checked(object sender, RoutedEventArgs e) - { - V2raySetTrojanTcpTls(); - } - #endregion - - #region 复制参数到剪贴板中 - - //复制内容到剪贴板函数 - private void CopyToClipboard(string content) - { - if (content != "") - { - Clipboard.SetDataObject(content); - //MessageBox.Show(Application.Current.FindResource("MessageBoxShow_V2RayUUIDcopyedToClip").ToString()); - string message = Application.Current.FindResource("MessageBoxShow_V2RayUUIDcopyedToClip").ToString(); - MessageBoxTimeoutA((IntPtr)0, message, "", 0, 0, 600); // 直接调用 0.6秒后自动关闭 - } - else - { - //MessageBox.Show(Application.Current.FindResource("MessageBoxShow_V2RayEmptyToClip").ToString()); - string message = Application.Current.FindResource("MessageBoxShow_V2RayEmptyToClip").ToString(); - MessageBoxTimeoutA((IntPtr)0, message, "", 0, 0, 600); // 直接调用 0.6秒后自动关闭 - } - } - - //复制服务器地址到剪贴板 - private void TextBoxHostAddress_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxHostAddress.Text); - } - - - //复制服务器端口到剪贴板 - private void TextBoxPort_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPort.Text); - } - - //复制UUID到剪贴板 - private void TextBoxUUID_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxUUID.Text); - } - - //复制额外ID到剪贴板 - private void TextBoxUUIDextra_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxUUIDextra.Text); - } - - //复制加密方式到剪贴板 - private void TextBoxEncryption_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxEncryption.Text); - } - - //复制传输协议到剪贴板 - private void TextBoxTransmission_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTransmission.Text); - } - - //复制伪装方式到剪贴板 - private void TextBoxCamouflageType_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxCamouflageType.Text); - } - - //复制Host/Quic加密方法到剪贴板 - private void TextBoxHostQuicEncryption_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxHostQuicEncryption.Text); - } - - //复制Quic Key/mKCP Seed/路径Path 到剪贴板中 - private void TextBoxQuicKeyMkcpSeedPath_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxQuicKeyMkcpSeedPath.Text); - } - - //复制TLS 到剪贴板中 - private void TextBoxTLS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTLS.Text); - } - - //复制URL链接到剪贴板中 - private void TextBoxURL_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxURL.Text); - } - - #endregion - - #region V2Ray客户端生成 - //生成单方案v2rayN客户端导入文件 - private void GenerateV2rayShareQRcodeAndBase64Url() - { - //生成v2rayN的json文件 - string v2rayNjsonFile = @" -{ - ""v"": """", - ""ps"": """", - ""add"": """", - ""port"": """", - ""id"": """", - ""aid"": """", - ""net"": """", - ""type"": """", - ""host"": """", - ""path"": """", - ""tls"": """" -}"; - //MessageBox.Show(v2rayNjsonFile); - JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - v2rayNjsonObject["v"] = "2"; - v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - if (TextBoxTransmission.Text.Contains("kcp") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - v2rayNjsonObject["host"] = "";//设置Host - } - else if (TextBoxTransmission.Text.Contains("quic")==true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - } - else - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - } - - v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - //MessageBox.Show("step1"); - string proxyfolder = CheckDir("v2ray_config"); - //MessageBox.Show("step2"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxHostAddress.Text); - //MessageBox.Show("step3"); - string configSavePath = configDomainSavePath; - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxURL.Text = vmessUrl; - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessXtlsTcp") == false - && String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false - && String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == false - && String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessHttp2Web") == false - && MainWindow.mKCPvlessIsSet == false) - { - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(vmessUrl); - } - ImageShareQRcode.Source = CreateQRCode(vmessUrl, $"{configSavePath}\\QR.bmp"); - } - - if (File.Exists(@"v2ray_config\config.json")) - { - File.Move(@"v2ray_config\config.json", $"{configSavePath}\\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - ReadmeTxtWriteGenerate(sw); - //sw.WriteLine("config.json"); - ////****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - ////****** "v2ray官方网站:https://www.v2ray.com/" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - ////****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - ////****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - ////****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - ////****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - ////****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - ////****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - ////****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - ////****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - ////****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - ////写入通用配置参数 - //TxtWriteGeneralParameters(sw); - } - } - - #region VLESS VMESS XTLS WS共存方案生成链接与说明文件 - - //生成VLESS Vmess Tcp Xtls Ws 配置保存(暂未有分享链接与二维码) - private void GenerateV2rayVlessVmessTcpXtlsWsShareQRcodeAndBase64Url(string plainSavePath) - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - //string plainSavePath = @""; - - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = vmessUrl; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - // if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false) - // { - // sw.WriteLine(vmessUrl); - // } - //} - //if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false) - //{ - // ImageShareQRcode.Source = CreateQRCode(vmessUrl, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - //} - - - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray:https://github.com/Qv2ray/Qv2ray/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数 - TxtWriteGeneralParameters(sw); - } - } - - - //生成VLESS over TCP with XTLS的配置保存(暂未有分享链接与二维码) - private void GenerateV2rayVlessTcpXtlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - string plainSavePath = @"vless_tcp_xtls_client_config"; - - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //TextBoxURLDefault = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLDefault; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - - // sw.WriteLine(TextBoxURLDefault); - - //} - - // ImageShareQRcodeDefault = CreateQRCode(TextBoxURLDefault, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - // ImageShareQRcode.Source = ImageShareQRcodeDefault; - - - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数-- - TxtWriteGeneralParameters(sw,false); - - } - } - - //生成VLESS over TCP with TLS的配置保存(暂未有分享链接与二维码) - private void GenerateV2rayVlessTcpTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - string plainSavePath = @"vless_tcp_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //TextBoxURLVlessTcp = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVlessTcp; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - - // sw.WriteLine(TextBoxURLVlessTcp); - - //} - - // ImageShareQRcodeVlessTcp = CreateQRCode(TextBoxURLVlessTcp, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - // ImageShareQRcode.Source = ImageShareQRcodeVlessTcp; - - - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数-- - TxtWriteGeneralParameters(sw,false); - - } - } - - //生成VLESS over WS with TLS的配置保存(暂未有分享链接与二维码) - private void GenerateV2rayVlessWsTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - string plainSavePath = @"vless_ws_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //TextBoxURLVlessWs = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVlessWs; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - - // sw.WriteLine(TextBoxURLVlessWs); - - //} - - // ImageShareQRcodeVlessWs = CreateQRCode(TextBoxURLVlessWs, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeVlessWs; - - - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数-- - TxtWriteGeneralParameters(sw,false); - - } - } - - //生成VMess over TCP with TLS的配置保存 - private void GenerateV2rayVmessTcpTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - //生成v2rayN的json文件 - string v2rayNjsonFile = @" -{ - ""v"": """", - ""ps"": """", - ""add"": """", - ""port"": """", - ""id"": """", - ""aid"": """", - ""net"": """", - ""type"": """", - ""host"": """", - ""path"": """", - ""tls"": """" -}"; - //MessageBox.Show(v2rayNjsonFile); - JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - v2rayNjsonObject["v"] = "2"; - v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - if (TextBoxTransmission.Text.Contains("kcp") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - v2rayNjsonObject["host"] = "";//设置Host - } - else if (TextBoxTransmission.Text.Contains("quic") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - } - else - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - } - - v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - - - #endregion - - //创建保存目录 - string plainSavePath = @"vmess_tcp_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - TextBoxURLVmessTcp = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVmessTcp; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(TextBoxURLVmessTcp); - } - - ImageShareQRcodeVmessTcp = CreateQRCode(TextBoxURLVmessTcp, $"{configSavePath}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeVmessTcp; - - - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - ReadmeTxtWriteGenerate(sw); - - } - } - - //生成VMess over WS with TLS的配置保存 - private void GenerateV2rayVmessWsTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - //生成v2rayN的json文件 - string v2rayNjsonFile = @" -{ - ""v"": """", - ""ps"": """", - ""add"": """", - ""port"": """", - ""id"": """", - ""aid"": """", - ""net"": """", - ""type"": """", - ""host"": """", - ""path"": """", - ""tls"": """" -}"; - //MessageBox.Show(v2rayNjsonFile); - JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - v2rayNjsonObject["v"] = "2"; - v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - if (TextBoxTransmission.Text.Contains("kcp") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - } - else if (TextBoxTransmission.Text.Contains("quic") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - } - else - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - } - - v2rayNjsonObject["tls"] = "tls"; //设置是否启用TLS - v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - - #endregion - - //创建保存目录 - string plainSavePath = @"vmess_ws_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - TextBoxURLVmessWs = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVmessWs; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - - sw.WriteLine(TextBoxURLVmessWs); - - } - - ImageShareQRcodeVmessWs = CreateQRCode(TextBoxURLVmessWs, $"{configSavePath}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeVmessWs; - - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - ReadmeTxtWriteGenerate(sw); - - } - } - - //生成Trojan over TCP with TLS的配置保存 - private void GenerateV2rayTrojanShareQRcodeAndBase64Url() - { - //创建保存目录 - string plainSavePath = @"trojan_tcp_tls_client_config"; - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - TextBoxURLTrojanTcp = $"trojan://{TextBoxUUID.Text}@{TextBoxHostAddress.Text}:{TextBoxPort.Text}#{TextBoxHostAddress.Text}"; - - //TextBoxURL.Text = TextBoxURLTrojanTcp; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(TextBoxURLTrojanTcp); - - } - //ImageShareQRcode.Source = CreateQRCode(TextBoxURLTrojanTcp, $"{configSavePath}\\QR.bmp"); - ImageShareQRcodeTrojanTcp = CreateQRCode(TextBoxURLTrojanTcp, $"{configSavePath}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeTrojanTcp; - //移动官方程序配置文件到相应目录 - if (File.Exists($"v2ray_config\\{plainSavePath}\\config.json")) - { - File.Move($"v2ray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"v2ray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - //ReadmeTxtWriteGenerate(sw); - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - //****** "服务器通用连接配置参数:" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine12").ToString()); - sw.WriteLine(""); - - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxHostAddress.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockServerPort"; - strParam = TextBoxPort.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockUserUUID"; - strParam = TextBoxUUID.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - } - - } - - //写入VMESS的readme.txt文件 - private void ReadmeTxtWriteGenerate(StreamWriter sw) - { - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数 - TxtWriteGeneralParameters(sw); - } - //TXT文件中写入通用配置参数--- - private void TxtWriteGeneralParameters(StreamWriter sw,bool alterId = true) - { - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - //****** "服务器通用连接配置参数:" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine12").ToString()); - sw.WriteLine(""); - - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxHostAddress.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockServerPort"; - strParam = TextBoxPort.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockUserUUID"; - strParam = TextBoxUUID.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - if (alterId == true) - { - strApplicat = "TextBlockV2RayAlterId"; - strParam = TextBoxUUIDextra.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - } - - strApplicat = "TextBlockEncryption"; - strParam = TextBoxEncryption.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockTransferProtocol"; - strParam = TextBoxTransmission.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockCamouflageType"; - strParam = TextBoxCamouflageType.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockIsOrNotTLS"; - strParam = TextBoxTLS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - if (MainWindow.ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - strParam = TextBoxHostQuicEncryption.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockQuicEncryption.Text, strLenth) + strParam); - - strParam = TextBoxQuicKeyMkcpSeedPath.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockQuicKey.Text, strLenth) + strParam); - - } - else if (MainWindow.ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - strParam = TextBoxHostQuicEncryption.Text; - sw.WriteLine(AlignmentStrFunc("host:", strLenth) + strParam); - - strParam = TextBoxQuicKeyMkcpSeedPath.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockMkcpSeed.Text, strLenth) + strParam); - - } - else - { - strParam = TextBoxHostQuicEncryption.Text; - sw.WriteLine(AlignmentStrFunc("host:", strLenth) + strParam); - - strParam = TextBoxQuicKeyMkcpSeedPath.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockPath.Text, strLenth) + strParam); - } - } - #endregion - - #endregion - - #endregion - - #region Xray 相关 - - #region Xray参数设置函数 - - //设置VLESS over TCP with XTLS - private void XraySetVlessTcpXtls() - { - GridNotTrojanParametersXray.Visibility = Visibility.Visible; - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBlockVmessOrVlessXray.Visibility = Visibility.Visible; - //隐藏下面的二维码显示 - HideGroupBoxClientQRandURL(); - - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "xtls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - TextBoxQuicKeyMkcpSeedPathXray.Text = ""; - - - } - - //设置VLESS over TCP with TLS - private void XraySetVlessTcpTls() - { - GridNotTrojanParametersXray.Visibility = Visibility.Visible; - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBlockVmessOrVlessXray.Visibility = Visibility.Visible; - //隐藏下面的二维码显示 - HideGroupBoxClientQRandURL(); - - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - TextBoxQuicKeyMkcpSeedPathXray.Text = ""; - } - - //设置VLESS over WS with TLS - private void XraySetVlessWsTls() - { - GridNotTrojanParametersXray.Visibility = Visibility.Visible; - TextBlockVmessOrVlessXray.Text = Application.Current.FindResource("TabItemHeaderV2RayVlessProtocol").ToString(); - TextBlockVmessOrVlessXray.Visibility = Visibility.Visible; - //隐藏下面的二维码显示 - HideGroupBoxClientQRandURL(); - - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - HideAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - TextBoxQuicKeyMkcpSeedPathXray.Text = MainWindow.ReceiveConfigurationParameters[3]; - - } - - //设置VMess over TCP with TLS - private void XraySetVmessTcpTls() - { - GridNotTrojanParametersXray.Visibility = Visibility.Visible; - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "tcp"; - TextBoxCamouflageTypeXray.Text = "http"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - TextBoxQuicKeyMkcpSeedPathXray.Text = MainWindow.ReceiveConfigurationParameters[9]; - TextBlockVmessOrVlessXray.Visibility = Visibility.Collapsed; - //显示下面的二维码显示。 - //HideGroupBoxClientQRandURL(); - ShowGroupBoxClientQRandURL(); - TextBoxURL.Text = TextBoxURLVmessTcp; - ImageShareQRcode.Source = ImageShareQRcodeVmessTcp; - } - - //设置VMess over WS with TLS - private void XraySetVmessWsTls() - { - GridNotTrojanParametersXray.Visibility = Visibility.Visible; - TextBoxEncryptionXray.Text = "none"; - TextBoxTransmissionXray.Text = "ws"; - TextBoxCamouflageTypeXray.Text = "none"; - //TLS的Host /Quic 加密方式 - TextBoxHostQuicEncryptionXray.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLSXray.Text = "tls"; - ShowAlterIdXray(); - ShowHostNameXray(); - ShowPathXray(); - TextBoxQuicKeyMkcpSeedPathXray.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBlockVmessOrVlessXray.Visibility = Visibility.Collapsed; - //显示下面的二维码与分享链接 - ShowGroupBoxClientQRandURL(); - TextBoxURL.Text = TextBoxURLVmessWs; - ImageShareQRcode.Source = ImageShareQRcodeVmessWs; - } - - //设置Trojan over TCP with TLS - private void XraySetTrojanTcpTls() - { - //隐藏所有不是Trojan的参数 - GridNotTrojanParametersXray.Visibility = Visibility.Collapsed; - //显示下面的二维码与分享链接 - ShowGroupBoxClientQRandURL(); - TextBoxURL.Text = TextBoxURLTrojanTcp; - ImageShareQRcode.Source = ImageShareQRcodeTrojanTcp; - } - #endregion - - #region 界面控制相关 - - //显示Quic 加密方式 - private void ShowQuicEncryptionXray() - { - TextBlockQuicEncryptionXray.Visibility = Visibility.Visible; - TextBlockHostXray.Visibility = Visibility.Collapsed; - } - - //显示Host隐藏Quic加密方式 - private void ShowHostNameXray() - { - TextBlockHostXray.Visibility = Visibility.Visible; - TextBlockQuicEncryptionXray.Visibility = Visibility.Collapsed; - } - - //显示路径Path,隐藏mKCP/Quic Key/复制按钮 - private void ShowPathXray() - { - TextBlockPathXray.Visibility = Visibility.Visible; - TextBlockMkcpSeedXray.Visibility = Visibility.Collapsed; - TextBlockQuicKeyXray.Visibility = Visibility.Collapsed; - } - - //显示mKCP Seed/复制按钮,隐藏Path/Quic Key - private void ShowMkcpSeedXray() - { - TextBlockPathXray.Visibility = Visibility.Collapsed; - TextBlockMkcpSeedXray.Visibility = Visibility.Visible; - TextBlockQuicKeyXray.Visibility = Visibility.Collapsed; - } - - //显示Quic Key/复制按钮 隐藏Path/mKcp Seed - private void ShowQuicKeyXray() - { - TextBlockPathXray.Visibility = Visibility.Collapsed; - TextBlockMkcpSeedXray.Visibility = Visibility.Collapsed; - TextBlockQuicKeyXray.Visibility = Visibility.Visible; - } - - //显示额外ID - private void ShowAlterIdXray() - { - TextBlockUUIDextraXray.Visibility = Visibility.Visible; - TextBoxUUIDextraXray.Visibility = Visibility.Visible; - TextBlockUUIDextraExplanationXray.Visibility = Visibility.Visible; - - } - - //隐藏额外ID - private void HideAlterIdXray() - { - TextBlockUUIDextraXray.Visibility = Visibility.Collapsed; - TextBoxUUIDextraXray.Visibility = Visibility.Collapsed; - TextBlockUUIDextraExplanationXray.Visibility = Visibility.Collapsed; - - } - - //显示加密方式 - private void ShowEncryptionXray() - { - TextBlockEncryptionXray.Visibility = Visibility.Visible; - TextBoxEncryptionXray.Visibility = Visibility.Visible; - } - //隐藏加密方式 - private void HideEncryptionXray() - { - TextBlockEncryptionXray.Visibility = Visibility.Collapsed; - TextBoxEncryptionXray.Visibility = Visibility.Collapsed; - } - - //显示传输协议 - private void ShowTransferProtocolXray() - { - TextBlockTransferProtocolXray.Visibility = Visibility.Visible; - TextBoxTransmissionXray.Visibility = Visibility.Visible; - } - //隐藏传输协议 - private void HideTransferProtocolXray() - { - TextBlockTransferProtocolXray.Visibility = Visibility.Collapsed; - TextBoxTransmissionXray.Visibility = Visibility.Collapsed; - } - //显示伪装类型 - private void ShowTextBlockCamouflageTypeXray() - { - TextBlockCamouflageTypeXray.Visibility = Visibility.Visible; - TextBoxCamouflageTypeXray.Visibility = Visibility.Visible; - } - //隐藏伪装类型 - private void HideTextBlockCamouflageTypeXray() - { - TextBlockCamouflageTypeXray.Visibility = Visibility.Collapsed; - TextBoxCamouflageTypeXray.Visibility = Visibility.Collapsed; - } - - - //以下几个为对RadioButton按钮的选中后,界面变化与参数显示 - private void RadioButtonVlessTcpXtlsXray_Checked(object sender, RoutedEventArgs e) - { - XraySetVlessTcpXtls(); - } - - private void RadioButtonVlessTcpTlsXray_Checked(object sender, RoutedEventArgs e) - { - XraySetVlessTcpTls(); - } - - private void RadioButtonVlessWsTlsXray_Checked(object sender, RoutedEventArgs e) - { - XraySetVlessWsTls(); - } - - private void RadioButtonVmessTcpTlsXray_Checked(object sender, RoutedEventArgs e) - { - XraySetVmessTcpTls(); - } - - private void RadioButtonVmessWsTlsXray_Checked(object sender, RoutedEventArgs e) - { - XraySetVmessWsTls(); - } - - private void RadioButtonTrojanTcpTlsXray_Checked(object sender, RoutedEventArgs e) - { - XraySetTrojanTcpTls(); - } - #endregion - - #region 复制参数到剪贴板中 - - - - //复制服务器地址到剪贴板 - private void TextBoxHostAddressXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxHostAddressXray.Text); - } - - - //复制服务器端口到剪贴板 - private void TextBoxPortXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPortXray.Text); - } - - //复制UUID到剪贴板 - private void TextBoxUUIDXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxUUIDXray.Text); - } - - //复制额外ID到剪贴板 - private void TextBoxUUIDextraXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxUUIDextraXray.Text); - } - - //复制加密方式到剪贴板 - private void TextBoxEncryptionXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxEncryptionXray.Text); - } - - //复制传输协议到剪贴板 - private void TextBoxTransmissionXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTransmissionXray.Text); - } - - //复制伪装方式到剪贴板 - private void TextBoxCamouflageTypeXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxCamouflageTypeXray.Text); - } - - //复制Host/Quic加密方法到剪贴板 - private void TextBoxHostQuicEncryptionXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxHostQuicEncryptionXray.Text); - } - - //复制Quic Key/mKCP Seed/路径Path 到剪贴板中 - private void TextBoxQuicKeyMkcpSeedPathXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxQuicKeyMkcpSeedPathXray.Text); - } - - //复制TLS 到剪贴板中 - private void TextBoxTLSXray_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTLSXray.Text); - } - - #endregion - - #region Xray客户端生成 - //生成单方案v2rayN客户端导入文件 - private void GenerateXrayShareQRcodeAndBase64Url() - { - //生成v2rayN的json文件 - string v2rayNjsonFile = @" -{ - ""v"": """", - ""ps"": """", - ""add"": """", - ""port"": """", - ""id"": """", - ""aid"": """", - ""net"": """", - ""type"": """", - ""host"": """", - ""path"": """", - ""tls"": """" -}"; - //MessageBox.Show(v2rayNjsonFile); - JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - v2rayNjsonObject["v"] = "2"; - v2rayNjsonObject["add"] = TextBoxHostAddressXray.Text; //设置域名 - v2rayNjsonObject["port"] = TextBoxPortXray.Text; //设置端口 - v2rayNjsonObject["id"] = TextBoxUUIDXray.Text; //设置uuid - v2rayNjsonObject["aid"] = TextBoxUUIDextraXray.Text; //设置额外ID - v2rayNjsonObject["net"] = TextBoxTransmissionXray.Text; //设置传输模式 - v2rayNjsonObject["type"] = TextBoxCamouflageTypeXray.Text; //设置伪装类型 - - if (TextBoxTransmissionXray.Text.Contains("kcp") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text;//设置mKCP Seed - v2rayNjsonObject["host"] = "";//设置Host - } - else if (TextBoxTransmissionXray.Text.Contains("quic") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text;//设置quic密钥 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryptionXray.Text;//Quic加密方式 - } - else - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text; //设置路径 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryptionXray.Text;//设置TLS的Host - } - - v2rayNjsonObject["tls"] = TextBoxTLSXray.Text; //设置是否启用TLS - v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - //MessageBox.Show("step1"); - string proxyfolder = CheckDir("xray_config"); - //MessageBox.Show("step2"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxHostAddressXray.Text); - //MessageBox.Show("step3"); - string configSavePath = configDomainSavePath; - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxURL.Text = vmessUrl; - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessXtlsTcp") == false - && String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false - && String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessWebSocketTlsWeb") == false - && String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessHttp2Web") == false - && MainWindow.mKCPvlessIsSet == false) - { - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(vmessUrl); - } - ImageShareQRcode.Source = CreateQRCode(vmessUrl, $"{configSavePath}\\QR.bmp"); - } - - if (File.Exists(@"xray_config\config.json")) - { - File.Move(@"xray_config\config.json", $"{configSavePath}\\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - ReadmeTxtWriteGenerateXray(sw); - - } - } - - #region VLESS VMESS XTLS WS共存方案生成链接与说明文件 - - //生成VLESS Vmess Tcp Xtls Ws 配置保存(暂未有分享链接与二维码) - private void GenerateXrayVlessVmessTcpXtlsWsShareQRcodeAndBase64Url(string plainSavePath) - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - //string plainSavePath = @""; - - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = vmessUrl; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - // if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false) - // { - // sw.WriteLine(vmessUrl); - // } - //} - //if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false) - //{ - // ImageShareQRcode.Source = CreateQRCode(vmessUrl, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - //} - - - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为v2ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine01").ToString()); - - //****** "v2ray官方网站:https://www.v2ray.com/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine02").ToString()); - - //****** "v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray:https://github.com/Qv2ray/Qv2ray/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数 - TxtWriteGeneralParametersXray(sw); - } - } - - - //生成VLESS over TCP with XTLS的配置保存(暂未有分享链接与二维码) - private void GenerateXrayVlessTcpXtlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - string plainSavePath = @"vless_tcp_xtls_client_config"; - - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //TextBoxURLDefault = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLDefault; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - - // sw.WriteLine(TextBoxURLDefault); - - //} - - // ImageShareQRcodeDefault = CreateQRCode(TextBoxURLDefault, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - // ImageShareQRcode.Source = ImageShareQRcodeDefault; - - - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为Xray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine01").ToString()); - - //****** "Xray官方网站:https://github.com/XTLS/Xray-core" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine02").ToString()); - - //****** "Xray官方程序下载地址:https://github.com/XTLS/Xray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择xray-windows-64.zip或者xray-windows-32.zip,解压后提取xray.exe。与config.json放在同一目录,运行xray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数-- - TxtWriteGeneralParametersXray(sw, false); - - } - } - - //生成VLESS over TCP with TLS的配置保存(暂未有分享链接与二维码) - private void GenerateXrayVlessTcpTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - string plainSavePath = @"vless_tcp_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //TextBoxURLVlessTcp = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVlessTcp; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - - // sw.WriteLine(TextBoxURLVlessTcp); - - //} - - // ImageShareQRcodeVlessTcp = CreateQRCode(TextBoxURLVlessTcp, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - // ImageShareQRcode.Source = ImageShareQRcodeVlessTcp; - - - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为Xray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine01").ToString()); - - //****** "Xray官方网站:https://github.com/XTLS/Xray-core" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine02").ToString()); - - //****** "Xray官方程序下载地址:https://github.com/XTLS/Xray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择xray-windows-64.zip或者xray-windows-32.zip,解压后提取v2ray.exe。与config.json放在同一目录,运行xray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数-- - TxtWriteGeneralParametersXray(sw, false); - - } - } - - //生成VLESS over WS with TLS的配置保存(暂未有分享链接与二维码) - private void GenerateXrayVlessWsTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - // //生成v2rayN的json文件 - // string v2rayNjsonFile = @" - //{ - // ""v"": """", - // ""ps"": """", - // ""add"": """", - // ""port"": """", - // ""id"": """", - // ""aid"": """", - // ""net"": """", - // ""type"": """", - // ""host"": """", - // ""path"": """", - // ""tls"": """" - //}"; - // //MessageBox.Show(v2rayNjsonFile); - // JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - // v2rayNjsonObject["v"] = "2"; - // v2rayNjsonObject["add"] = TextBoxHostAddress.Text; //设置域名 - // v2rayNjsonObject["port"] = TextBoxPort.Text; //设置端口 - // v2rayNjsonObject["id"] = TextBoxUUID.Text; //设置uuid - // v2rayNjsonObject["aid"] = TextBoxUUIDextra.Text; //设置额外ID - // v2rayNjsonObject["net"] = TextBoxTransmission.Text; //设置传输模式 - // v2rayNjsonObject["type"] = TextBoxCamouflageType.Text; //设置伪装类型 - - // if (TextBoxTransmission.Text.Contains("kcp") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置mKCP Seed - // } - // else if (TextBoxTransmission.Text.Contains("quic") == true) - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text;//设置quic密钥 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//Quic加密方式 - // } - // else - // { - // v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPath.Text; //设置路径 - // v2rayNjsonObject["host"] = TextBoxHostQuicEncryption.Text;//设置TLS的Host - // } - - // v2rayNjsonObject["tls"] = TextBoxTLS.Text; //设置是否启用TLS - // v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - // //MessageBox.Show(v2rayNjsonObject["v"].ToString()); - - //string saveFileFolderFirst = TextBoxHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir(@"v2ray_config"); - //while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"v2ray_config\" + saveFileFolder); - - #endregion - - //创建保存目录 - string plainSavePath = @"vless_ws_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - //TextBoxURLVlessWs = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVlessWs; - //using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - //{ - - // sw.WriteLine(TextBoxURLVlessWs); - - //} - - // ImageShareQRcodeVlessWs = CreateQRCode(TextBoxURLVlessWs, $"v2ray_config\\{saveFileFolder}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeVlessWs; - - - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - //****** "此文件为Xray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine01").ToString()); - - //****** "Xray官方网站:https://github.com/XTLS/Xray-core" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine02").ToString()); - - //****** "Xray官方程序下载地址:https://github.com/XTLS/Xray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择xray-windows-64.zip或者xray-windows-32.zip,解压后提取v2ray.exe。与config.json放在同一目录,运行xray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine04").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数-- - TxtWriteGeneralParametersXray(sw, false); - - } - } - - //生成VMess over TCP with TLS的配置保存 - private void GenerateXrayVmessTcpTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - //生成v2rayN的json文件 - string v2rayNjsonFile = @" -{ - ""v"": """", - ""ps"": """", - ""add"": """", - ""port"": """", - ""id"": """", - ""aid"": """", - ""net"": """", - ""type"": """", - ""host"": """", - ""path"": """", - ""tls"": """" -}"; - //MessageBox.Show(v2rayNjsonFile); - JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - v2rayNjsonObject["v"] = "2"; - v2rayNjsonObject["add"] = TextBoxHostAddressXray.Text; //设置域名 - v2rayNjsonObject["port"] = TextBoxPortXray.Text; //设置端口 - v2rayNjsonObject["id"] = TextBoxUUIDXray.Text; //设置uuid - v2rayNjsonObject["aid"] = TextBoxUUIDextraXray.Text; //设置额外ID - v2rayNjsonObject["net"] = TextBoxTransmissionXray.Text; //设置传输模式 - v2rayNjsonObject["type"] = TextBoxCamouflageTypeXray.Text; //设置伪装类型 - - if (TextBoxTransmissionXray.Text.Contains("kcp") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text;//设置mKCP Seed - v2rayNjsonObject["host"] = "";//设置Host - } - else if (TextBoxTransmissionXray.Text.Contains("quic") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text;//设置quic密钥 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryptionXray.Text;//Quic加密方式 - } - else - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text; //设置路径 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryptionXray.Text;//设置TLS的Host - } - - v2rayNjsonObject["tls"] = TextBoxTLSXray.Text; //设置是否启用TLS - v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - - - #endregion - - //创建保存目录 - string plainSavePath = @"vmess_tcp_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL,跳过VlessTcpTlsWeb暂时未有URL标准 - TextBoxURLVmessTcp = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVmessTcp; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(TextBoxURLVmessTcp); - } - - ImageShareQRcodeVmessTcp = CreateQRCode(TextBoxURLVmessTcp, $"{configSavePath}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeVmessTcp; - - - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - ReadmeTxtWriteGenerateXray(sw); - - } - } - - //生成VMess over WS with TLS的配置保存 - private void GenerateXrayVmessWsTlsShareQRcodeAndBase64Url() - { - #region 暂时不用内容 - //生成v2rayN的json文件 - string v2rayNjsonFile = @" -{ - ""v"": """", - ""ps"": """", - ""add"": """", - ""port"": """", - ""id"": """", - ""aid"": """", - ""net"": """", - ""type"": """", - ""host"": """", - ""path"": """", - ""tls"": """" -}"; - //MessageBox.Show(v2rayNjsonFile); - JObject v2rayNjsonObject = JObject.Parse(v2rayNjsonFile); - v2rayNjsonObject["v"] = "2"; - v2rayNjsonObject["add"] = TextBoxHostAddressXray.Text; //设置域名 - v2rayNjsonObject["port"] = TextBoxPortXray.Text; //设置端口 - v2rayNjsonObject["id"] = TextBoxUUIDXray.Text; //设置uuid - v2rayNjsonObject["aid"] = TextBoxUUIDextraXray.Text; //设置额外ID - v2rayNjsonObject["net"] = TextBoxTransmissionXray.Text; //设置传输模式 - v2rayNjsonObject["type"] = TextBoxCamouflageTypeXray.Text; //设置伪装类型 - - if (TextBoxTransmissionXray.Text.Contains("kcp") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text;//设置mKCP Seed - } - else if (TextBoxTransmissionXray.Text.Contains("quic") == true) - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text;//设置quic密钥 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryptionXray.Text;//Quic加密方式 - } - else - { - v2rayNjsonObject["path"] = TextBoxQuicKeyMkcpSeedPathXray.Text; //设置路径 - v2rayNjsonObject["host"] = TextBoxHostQuicEncryptionXray.Text;//设置TLS的Host - } - - v2rayNjsonObject["tls"] = "tls"; //设置是否启用TLS - v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注 - - #endregion - - //创建保存目录 - string plainSavePath = @"vmess_ws_tls_client_config"; - //v2ray_config\${域名IP} - //string configDomainSavePath = CreateConfigSaveDir(@"v2ray_config", TextBoxHostAddressSS.Text); - //v2ray_config\${域名IP}\vless_tcp_xtls_client_config - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - - //生成二维码与URL - TextBoxURLVmessWs = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - //TextBoxURL.Text = TextBoxURLVmessWs; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(TextBoxURLVmessWs); - } - - ImageShareQRcodeVmessWs = CreateQRCode(TextBoxURLVmessWs, $"{configSavePath}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeVmessWs; - - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - ReadmeTxtWriteGenerateXray(sw); - - } - } - - //生成Trojan over TCP with TLS的配置保存 - private void GenerateXrayTrojanShareQRcodeAndBase64Url() - { - //创建保存目录 - string plainSavePath = @"trojan_tcp_tls_client_config"; - string configSavePath = CheckDir($"{configDomainSavePath}\\{plainSavePath}"); - - TextBoxURLTrojanTcp = $"trojan://{TextBoxUUIDXray.Text}@{TextBoxHostAddressXray.Text}:{TextBoxPortXray.Text}#{TextBoxHostAddressXray.Text}"; - - //TextBoxURL.Text = TextBoxURLTrojanTcp; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(TextBoxURLTrojanTcp); - - } - //ImageShareQRcode.Source = CreateQRCode(TextBoxURLTrojanTcp, $"{configSavePath}\\QR.bmp"); - ImageShareQRcodeTrojanTcp = CreateQRCode(TextBoxURLTrojanTcp, $"{configSavePath}\\QR.bmp"); - //ImageShareQRcode.Source = ImageShareQRcodeTrojanTcp; - //移动官方程序配置文件到相应目录 - if (File.Exists($"xray_config\\{plainSavePath}\\config.json")) - { - File.Move($"xray_config\\{plainSavePath}\\config.json", $"{configSavePath}\\config.json"); - Directory.Delete($"xray_config\\{plainSavePath}"); - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - //ReadmeTxtWriteGenerate(sw); - sw.WriteLine("config.json"); - //****** "此文件为Xray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine01").ToString()); - - //****** "Xray官方网站:https://github.com/XTLS/Xray-core" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine02").ToString()); - - //****** "Xray官方程序下载地址:https://github.com/XTLS/Xray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择Xray-windows-64.zip或者Xray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - //****** "服务器通用连接配置参数:" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine12").ToString()); - sw.WriteLine(""); - - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxHostAddressXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockServerPort"; - strParam = TextBoxPortXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockUserUUID"; - strParam = TextBoxUUIDXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - } - - } - - //写入VMESS的readme.txt文件 - private void ReadmeTxtWriteGenerateXray(StreamWriter sw) - { - sw.WriteLine("config.json"); - //****** "此文件为Xray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine01").ToString()); - - //****** "Xray官方网站:https://github.com/XTLS/Xray-core" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine02").ToString()); - - //****** "Xray官方程序下载地址:https://github.com/XTLS/Xray-core/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine03").ToString()); - - //****** "下载相应版本,Windows选择xray-windows-64.zip或者xray-windows-32.zip,解压后提取xray.exe。与config.json放在同一目录,运行xray.exe即可。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtXrayExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("QR.bmp"); - - //****** "此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine05").ToString()); - - //****** "v2rayN下载网址:https://github.com/2dust/v2rayN/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine06").ToString()); - - //****** "Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine07").ToString()); - - //****** "v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine08").ToString()); - - //****** "v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine09").ToString()); - - //****** "Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine10").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("url.txt"); - - //****** "此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine11").ToString()); - - //写入通用配置参数 - TxtWriteGeneralParametersXray(sw); - } - //TXT文件中写入通用配置参数--- - private void TxtWriteGeneralParametersXray(StreamWriter sw, bool alterId = true) - { - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - //****** "服务器通用连接配置参数:" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtV2RayExplainLine12").ToString()); - sw.WriteLine(""); - - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxHostAddressXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockServerPort"; - strParam = TextBoxPortXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockUserUUID"; - strParam = TextBoxUUIDXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - if (alterId == true) - { - strApplicat = "TextBlockV2RayAlterId"; - strParam = TextBoxUUIDextraXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - } - - strApplicat = "TextBlockEncryption"; - strParam = TextBoxEncryptionXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockTransferProtocol"; - strParam = TextBoxTransmissionXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockCamouflageType"; - strParam = TextBoxCamouflageTypeXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - strApplicat = "TextBlockIsOrNotTLS"; - strParam = TextBoxTLSXray.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - if (MainWindow.ReceiveConfigurationParameters[0].Contains("Quic") == true) - { - strParam = TextBoxHostQuicEncryptionXray.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockQuicEncryptionXray.Text, strLenth) + strParam); - - strParam = TextBoxQuicKeyMkcpSeedPathXray.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockQuicKeyXray.Text, strLenth) + strParam); - - } - else if (MainWindow.ReceiveConfigurationParameters[0].Contains("mKCP") == true) - { - strParam = TextBoxHostQuicEncryptionXray.Text; - sw.WriteLine(AlignmentStrFunc("host:", strLenth) + strParam); - - strParam = TextBoxQuicKeyMkcpSeedPathXray.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockMkcpSeedXray.Text, strLenth) + strParam); - - } - else - { - strParam = TextBoxHostQuicEncryptionXray.Text; - sw.WriteLine(AlignmentStrFunc("host:", strLenth) + strParam); - - strParam = TextBoxQuicKeyMkcpSeedPathXray.Text; - sw.WriteLine(AlignmentStrFunc(TextBlockPathXray.Text, strLenth) + strParam); - } - } - #endregion - - #endregion - - #endregion - - #region TrojanGo 相关 - //生成TrojanGo客户端资料 - private void GenerateTrojanGoShareQRcodeAndBase64Url() - { - string proxyfolder = CheckDir("trojan-go_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxTrojanGoServerHost.Text); - string configSavePath = configDomainSavePath; - - string trojanGoUrl = GetTrojanGoUrl(); - - TextBoxURL.Text = trojanGoUrl; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(trojanGoUrl); - - } - ImageShareQRcode.Source = CreateQRCode(trojanGoUrl, $"{configSavePath}\\QR.bmp"); - - //移动Trojan官方程序配置文件到相应目录 - if (File.Exists(@"trojan-go_config\config.json")) - { - File.Move(@"trojan-go_config\config.json", $"{configSavePath}\\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - - //****** "此文件为Trojan-go官方程序所使用的客户端配置文件,配置为全局模式,http与socks5地址:127.0.0.1:1080" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine01").ToString()); - - //****** "Trojan-go官方网站:https://github.com/p4gefau1t/trojan-go" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine02").ToString()); - - //sw.WriteLine("Trojan-go官方程序下载地址:https://github.com/p4gefau1t/trojan-go/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine03").ToString()); - - //sw.WriteLine("下载相应版本,Windows选择Trojan-go-x.xx-win.zip,解压后提取trojan-go.exe。与config.json放在同一目录,运行trojan-go.exe即可。"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR.bmp"); - - //sw.WriteLine("此文件为Qv2ray (windows)、igniter(Android)扫码导入节点"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine05").ToString()); - - //sw.WriteLine("Qv2ray (windows)下载网址:https://github.com/Qv2ray/Qv2ray/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine06").ToString()); - - //sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine07").ToString()); - - //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - // sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine08").ToString()); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - - //sw.WriteLine("此文件为Qv2ray (windows)、igniter(Android)复制粘贴导入节点的网址"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine09").ToString()); - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - - //sw.WriteLine("服务器通用连接配置参数"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojan-goExplainLine10").ToString()); - sw.WriteLine(""); - - //****** 服务器地址(address): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerAddress").ToString() + $"{TextBoxTrojanGoServerHost.Text}"); - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxTrojanGoServerHost.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 端口(port): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerPort").ToString() + $"{TextBoxTrojanGoServerPort.Text}"); - strApplicat = "TextBlockServerPort"; - strParam = TextBoxTrojanGoServerPort.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 密码: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxTrojanGoServerPassword.Text}"); - strApplicat = "TextBlockTrojanGoPassword"; - strParam = TextBoxTrojanGoServerPassword.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** Type: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxTrojanGoServerPassword.Text}"); - //strApplicat = "TextBlockTrojanGoPassword"; - strParam = TextBoxTrojanGoType.Text; - sw.WriteLine(AlignmentStrFunc("Type:", strLenth) + strParam); - //sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** WebSocket路径: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); - strApplicat = "TextBlockTrojanGoWebSocketPath"; - strParam = TextBoxTrojanGoWSPath.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** Mux多路复用 ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); - strApplicat = "CheckBoxMuxSelect"; - strParam = ":"; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** concurrency: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); - strApplicat = "concurrency:"; - strParam = TextBoxConcurrency.Text; - sw.WriteLine(AlignmentStrFunc(strApplicat, strLenth) + strParam); - - //****** idle_timeout: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); - strApplicat = "idle_timeout:"; - strParam = TextBoxIdle_timeout.Text; - sw.WriteLine(AlignmentStrFunc(strApplicat, strLenth) + strParam); - - } - - } - - #region TrojanGo内容双击复制到剪贴板 - private void TextBoxTrojanGoServerHost_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoServerHost.Text); - } - - private void TextBoxTrojanGoServerPort_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoServerPort.Text); - } - - private void TextBoxTrojanGoServerPassword_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoServerPassword.Text); - } - private void TextBoxTrojanGoSNI_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoSNI.Text); - } - private void TextBoxTrojanGoType_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoType.Text); - } - private void TextBoxTrojanGoHost_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoHost.Text); - } - private void TextBoxTrojanGoWSPath_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanGoWSPath.Text); - } - private void TextBoxConcurrency_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxConcurrency.Text); - } - - private void TextBoxIdle_timeout_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxIdle_timeout.Text); - } - #endregion - - //生成TrojanGo的分享链接 - private string GetTrojanGoUrl() - { - string trojanGoPassword = EncodeURIComponent(TextBoxTrojanGoServerPassword.Text); - string trojanGoHost = TextBoxTrojanGoServerHost.Text; - string trojanGoPort = TextBoxTrojanGoServerPort.Text; - - string trojanGoSni = EncodeURIComponent(TextBoxTrojanGoSNI.Text); - string trojanGoType= EncodeURIComponent(TextBoxTrojanGoType.Text); - string trojanGohostName = EncodeURIComponent(TextBoxTrojanGoHost.Text); - - string trojanGoPath = EncodeURIComponent(TextBoxTrojanGoWSPath.Text); - string trojanGoEncryption = EncodeURIComponent(""); - string trojanGoPlugin = EncodeURIComponent(""); - - string trojanGoRemarks = EncodeURIComponent(trojanGoHost); - - //分享链接规范:https://github.com/p4gefau1t/trojan-go/issues/132 - //trojan-go://$(trojan-password)@trojan-host:port/?sni=$(update.microsoft.com)&type=$(original|ws|h2|h2+ws)&host=$(update-01.microsoft.com)&path=$(/update/whatever)&encryption=$(ss;aes-256-gcm:ss-password)&plugin=$(...)#$(descriptive-text) - //string trojanGoUrl = $"trojan-go://{trojanGoPassword}@{trojanGoHost}:{trojanGoPort}/?sni={trojanGoSni}&type={trojanGoType}&host={trojanGohostName}&path={trojanGoPath}&encryption={trojanGoEncryption}&plugin={trojanGoPlugin}#{trojanGoRemarks}"; - - //&path={trojanGoPath} - //&encryption={trojanGoEncryption} - //&plugin={trojanGoPlugin} - //#{trojanGoRemarks} - string trojanGoUrl = $"trojan-go://{trojanGoPassword}@{trojanGoHost}:{trojanGoPort}/?sni={trojanGoSni}&type={trojanGoType}"; - - if (String.IsNullOrEmpty(trojanGohostName) == false) - { - trojanGoUrl += $"&host={trojanGohostName}"; - } - if (String.IsNullOrEmpty(trojanGoPath) == false) - { - trojanGoUrl += $"&path={trojanGoPath}"; - } - if (String.IsNullOrEmpty(trojanGoEncryption) == false) - { - trojanGoUrl += $"&encryption={trojanGoEncryption}"; - } - if (String.IsNullOrEmpty(trojanGoPlugin) == false) - { - trojanGoUrl += $"&plugin={trojanGoPlugin}"; - } - - trojanGoUrl += $"#{trojanGoRemarks}"; - return trojanGoUrl; - } - private string EncodeURIComponent(string initialUri) - { - return Uri.EscapeDataString(initialUri); - } - - //生成Trojan客户端资料 - private void GenerateTrojanShareQRcodeAndBase64Url() - { - string proxyfolder = CheckDir("trojan_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxTrojanServerHost.Text); - string configSavePath = configDomainSavePath; - - //string saveFileFolderFirst = TextBoxTrojanServerHost.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir("trojan_config"); - //while (Directory.Exists(@"trojan_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"trojan_config\" + saveFileFolder); - string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}#{TextBoxTrojanServerHost.Text}"; - //MessageBox.Show(v2rayNjsonObject.ToString()); - //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxURL.Text = trojanUrl; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(trojanUrl); - - } - ImageShareQRcode.Source = CreateQRCode(trojanUrl, $"{configSavePath}\\QR.bmp"); - - //移动Trojan官方程序配置文件到相应目录 - if (File.Exists(@"trojan_config\config.json")) - { - File.Move(@"trojan_config\config.json", $"{configSavePath}\\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - - //****** "此文件为Trojan官方程序所使用的客户端配置文件,配置为全局模式,http与socks5地址:127.0.0.1:1080" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine01").ToString()); - - //****** "Trojan官方网站:https://trojan-gfw.github.io/trojan/" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine02").ToString()); - - //sw.WriteLine("Trojan官方程序下载地址:https://github.com/trojan-gfw/trojan/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine03").ToString()); - - //sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR.bmp"); - - //sw.WriteLine("此文件为Qv2ray (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine05").ToString()); - - //sw.WriteLine("Qv2ray (windows)下载网址:https://github.com/Qv2ray/Qv2ray/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine06").ToString()); - - //sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine07").ToString()); - - //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine08").ToString()); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - - //sw.WriteLine("此文件为Qv2ray (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine09").ToString()); - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - - //sw.WriteLine("服务器通用连接配置参数"); - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine10").ToString()); - sw.WriteLine(""); - - //****** 服务器地址(address): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerAddress").ToString() + $"{TextBoxTrojanGoServerHost.Text}"); - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxTrojanServerHost.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 端口(port): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerPort").ToString() + $"{TextBoxTrojanGoServerPort.Text}"); - strApplicat = "TextBlockServerPort"; - strParam = TextBoxTrojanServerPort.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 密码: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxTrojanGoServerPassword.Text}"); - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); - strApplicat = "TextBlockTrojanGoPassword"; - strParam = TextBoxTrojanServerPassword.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - - } - - } - - #region Trojan内容双击复制到剪贴板 - - private void TextBoxTrojanServerHost_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanServerHost.Text); - } - - private void TextBoxTrojanServerPort_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanServerPort.Text); - } - - private void TextBoxTrojanServerPassword_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxTrojanServerPassword.Text); - } - - #endregion - - #endregion - - #region NaiveProxy 相关 - //生成NaiveProxy客户端资料 - private void GenerateNaivePrxoyShareQRcodeAndBase64Url() - { - string proxyfolder = CheckDir("naive_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxNaiveServerHost.Text); - string configSavePath = configDomainSavePath; - - string naiveUrl = $"naive+https://{TextBoxNaiveUser.Text}:{TextBoxNaivePassword.Text}@{TextBoxNaiveServerHost.Text}:443?padding=true#{TextBoxNaiveServerHost.Text}"; - - TextBoxURL.Text = naiveUrl; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(naiveUrl); - - } - ImageShareQRcode.Source = CreateQRCode(naiveUrl, $"{configSavePath}\\QR.bmp"); - - //移动NaiveProxy官方程序配置文件到相应目录 - if (File.Exists(@"naive_config\config.json")) - { - File.Move(@"naive_config\config.json", $"{configSavePath}\\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - sw.WriteLine("config.json"); - - //****** "此文件为NaiveProxy官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine01").ToString()); - - //****** "NaiveProxy官方网站:https://github.com/klzgrad/naiveproxy" ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine02").ToString()); - - //sw.WriteLine("NaiveProxy官方程序下载地址:https://github.com/klzgrad/naiveproxy/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine03").ToString()); - - //sw.WriteLine("下载相应版本,Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录,运行naive.exe即可。"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine04").ToString()); - - sw.WriteLine("-----------------------------------------"); - sw.WriteLine("QR.bmp"); - - //sw.WriteLine("此文件为NaiveSharp(windows)复制粘贴导入节点的网址"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine05").ToString()); - - //sw.WriteLine("NaiveSharp(windows)下载网址:https://github.com/KevinZonda/NaiveSharp/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine06").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - - sw.WriteLine("url.txt"); - - //sw.WriteLine("此文件为NaiveSharp(windows)复制粘贴导入节点的网址"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine05").ToString()); - - //sw.WriteLine("NaiveSharp(windows)下载网址:https://github.com/KevinZonda/NaiveSharp/releases"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine06").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - - //sw.WriteLine("服务器通用连接配置参数"); - sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine07").ToString()); - sw.WriteLine(""); - - //****** 服务器地址(address): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerAddress").ToString() + $"{TextBoxNaiveServerHost.Text}"); - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxNaiveServerHost.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 用户名:****** - //sw.WriteLine(Application.Current.FindResource("TextBlockHostUser").ToString() + $"{TextBoxNaiveUser.Text}"); - strApplicat = "TextBlockHostUser"; - strParam = TextBoxNaiveUser.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 密码: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxNaivePassword.Text}"); - strApplicat = "TextBlockTrojanGoPassword"; - strParam = TextBoxNaivePassword.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - } - - } - - #region NaiveProxy内容双击复制到剪贴板 - private void TextBoxNaiveServerHost_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxNaiveServerHost.Text); - } - - private void TextBoxNaivePort_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxNaivePort.Text); - } - - private void TextBoxNaiveUser_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxNaiveUser.Text); - } - - private void TextBoxNaivePassword_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxNaivePassword.Text); - } - - - - #endregion - - #endregion - - #region SSR 相关 - //生成SSR客户端资料 - private void GenerateSSRShareQRcodeAndBase64Url() - { - string proxyfolder = CheckDir("ssr_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxSSRHostAddress.Text); - string configSavePath = configDomainSavePath; - //string saveFileFolderFirst = TextBoxSSRHostAddress.Text; - //int num = 1; - //saveFileFolder = saveFileFolderFirst; - //CheckDir("ssr_config"); - //while (Directory.Exists(@"ssr_config\" + saveFileFolder)) - //{ - // saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - // num++; - //} - //CheckDir(@"ssr_config\" + saveFileFolder); - - string ssrUrl = GetSSRLinkForServer(); - TextBoxURL.Text = ssrUrl; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(ssrUrl); - } - ImageShareQRcode.Source = CreateQRCode(ssrUrl, $"{configSavePath}\\QR.bmp"); - - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - //sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR.bmp"); - - //***"此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)扫码导入节点"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine05").ToString()); - - //***"ShadowsocksR (windows)下载网址:https://github.com/shadowsocksrr/shadowsocksr-csharp/releases"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine06").ToString()); - - //***"SSRR(Android)下载网址:https://github.com/shadowsocksrr/shadowsocksr-android/releases"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine07").ToString()); - - //***"Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine08").ToString()); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - - //***"此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine09").ToString()); - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - - //***"服务器通用连接配置参数"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine10").ToString()); - sw.WriteLine(""); - - //****** 服务器地址(address): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerAddress").ToString() + $"{ TextBoxSSRHostAddress.Text}"); - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxSSRHostAddress.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 端口(port): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerPort").ToString() + $"{TextBoxSSRPort.Text}"); - strApplicat = "TextBlockServerPort"; - strParam = TextBoxSSRPort.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 密码: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxSSRUUID.Text}"); - strApplicat = "TextBlockTrojanGoPassword"; - strParam = TextBoxSSRUUID.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 加密方式: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockEncryption").ToString() + $"{TextBoxSSREncryption.Text}"); - strApplicat = "TextBlockEncryption"; - strParam = TextBoxSSREncryption.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 传输协议: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTransferProtocol").ToString() + $"{TextBoxSSRTransmission.Text}"); - strApplicat = "TextBlockTransferProtocol"; - strParam = TextBoxSSRTransmission.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 混淆: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockCamouflageType").ToString() + $"{TextBoxSSRCamouflageType.Text}"); - strApplicat = "TextBlockCamouflageType"; - strParam = TextBoxSSRCamouflageType.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - } - } - - #region SSR内容双击复制到剪贴板 - - private void TextBoxSSRHostAddress_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxSSRHostAddress.Text); - } - - private void TextBoxSSRPort_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxSSRPort.Text); - } - - private void TextBoxSSRUUID_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxSSRUUID.Text); - } - - private void TextBoxSSREncryption_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxSSREncryption.Text); - } - - private void TextBoxSSRTransmission_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxSSRTransmission.Text); - } - - private void TextBoxSSRCamouflageType_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxSSRCamouflageType.Text); - } - #endregion - - //生成SS客户端资料 - private void GenerateShareQRcodeAndBase64UrlSS() - { - //创建保存目录 - string proxyfolder = CheckDir("ss_config"); - configDomainSavePath = CreateConfigSaveDir(proxyfolder, TextBoxHostAddressSS.Text); - string configSavePath = configDomainSavePath; - //string configSavePath = CreateConfigSaveDir(@"ss_config", TextBoxHostAddressSS.Text); - string ssUrl; - - //生成手机端的URL(无插件时,为电脑手机通用) - if (String.Equals(TextBoxPluginNameExplainSS.Text, "goquiet")==false && String.Equals(TextBoxPluginNameExplainSS.Text, "cloak") == false) - { - ssUrl = GetSStoURL(TextBoxPluginNameExplainSS.Text); - TextBoxURL.Text = ssUrl; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url.txt")) - { - sw.WriteLine(ssUrl); - } - ImageShareQRcode.Source = CreateQRCode(ssUrl, $"{configSavePath}\\QR.bmp"); - } - - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == false) - { - //生成电脑端 - ssUrl = GetSStoURL(TextBoxPluginNameExplainSSpc.Text); - TextBoxURLpcSS.Text = ssUrl; - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\url_pc.txt")) - { - sw.WriteLine(ssUrl); - } - ImageShareQRcodeSSpc.Source = CreateQRCode(ssUrl, $"{configSavePath}\\QR_pc.bmp"); - } - using (StreamWriter sw = new StreamWriter($"{configSavePath}\\readme.txt")) - { - if (String.Equals(TextBoxPluginNameExplainSS.Text, "goquiet") == false && String.Equals(TextBoxPluginNameExplainSS.Text, "cloak") == false) - { - //sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR.bmp"); - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == true) - { - //***"此文件为Shadowsocks (windows)、shadowsocks(Android)、Shadowrocket(ios)扫码导入节点"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS05").ToString()); - - } - else - { - //***"此文件为shadowsocks(Android)、Shadowrocket(ios)扫码导入节点"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS05").ToString()); - } - - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == true) - { - //***"此文件为Shadowsocks (windows)、shadowsocks(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS09").ToString()); - } - else - { - //***"此文件为shadowsocks(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS09").ToString()); - } - sw.WriteLine(""); - //***"shadowsocks(Android)下载网址:https://github.com/shadowsocks/shadowsocks-android/releases"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS07").ToString()); - - //***"Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS08").ToString()); - } - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == false) - { - sw.WriteLine(""); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR_pc.bmp"); - - //***"此文件为Shadowsocks (windows)扫码导入节点"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS01").ToString()); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url_pc.txt"); - - //***"此文件为Shadowsocks (windows)复制粘贴导入节点的网址"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS02").ToString()); - sw.WriteLine(""); - - } - //***"Shadowsocks(windows)下载网址:https://github.com/shadowsocks/shadowsocks-windows/releases"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtExplainLineSS06").ToString()); - sw.WriteLine("-----------------------------------------\n"); - - string strApplicat = ""; - string strParam = ""; - int strLenth = 20; - - //***"服务器通用连接配置参数"*** - sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine10").ToString()); - sw.WriteLine(""); - - //****** 服务器地址(address): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerAddress").ToString() + $"{TextBoxHostAddressSS.Text}"); - strApplicat = "TextBlockServerAddress"; - strParam = TextBoxHostAddressSS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 端口(port): ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockServerPort").ToString() + $"{TextBoxPortSS.Text}"); - strApplicat = "TextBlockServerPort"; - strParam = TextBoxPortSS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 密码: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxPasswordSS.Text}"); - strApplicat = "TextBlockTrojanGoPassword"; - strParam = TextBoxPasswordSS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 加密方式: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockEncryption").ToString() + $"{TextBoxEncryptionSS.Text}"); - strApplicat = "TextBlockEncryption"; - strParam = TextBoxEncryptionSS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - - if (String.IsNullOrEmpty(TextBoxPluginNameExplainSS.Text) == false) - { - //****** 插件程序:: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockPluginNameExplainSS").ToString() + $"{TextBoxPluginNameExplainSS.Text}"); - strApplicat = "TextBlockPluginNameExplainSS"; - strParam = TextBoxPluginNameExplainSS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - //****** 插件选项: ****** - //sw.WriteLine(Application.Current.FindResource("TextBlockPluginOptionExplainSS").ToString() + $"{TextBoxPluginOptionExplainSS.Text}"); - strApplicat = "TextBlockPluginOptionExplainSS"; - strParam = TextBoxPluginOptionExplainSS.Text; - sw.WriteLine(AlignmentStrFunc(Application.Current.FindResource($"{strApplicat}").ToString(), strLenth) + strParam); - - sw.WriteLine("-----------------------------------------\n"); - //****** 插件使用说明 ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS").ToString()); - - //****** ProxySU默认所有插件,在Shadowsocks (windows)运行文件所在文件夹的子文件夹plugins下。 ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS01").ToString()); - - //****** 电脑端手动安装插件说明 ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS02").ToString()); - - //****** 先下载插件,各个插件Windows客户端下载地址为: ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS03").ToString()); - - //****** Simple-obfs: https://github.com/shadowsocks/simple-obfs/releases 只下载 obfs-local.zip ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS04").ToString()); - - //****** V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin/releases 64位系统选择:v2ray-plugin-windows-amd64-vx.x.x.tar.gz,32位系统选择:v2ray-plugin-windows-386-vx.x.x.tar.gz (x为数字,是版本号)****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS05").ToString()); - - //****** Kcptun-plugin: https://github.com/shadowsocks/kcptun/releases 64位系统选择:kcptun-windows-amd64-xxxxxx.tar.gz,32位系统选择:kcptun-plugin-windows-386-xxxxxx.tar.gz (x为数字,是版本号)****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS06").ToString()); - - ////****** GoQuiet-plugin: https://github.com/cbeuw/GoQuiet/releases 64位系统选择:gq-client-windows-amd64-x.x.x.exe,32位系统选择:gq-client-windows-386-x.x.x.exe(x为数字,是版本号)****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS07").ToString()); - - ////****** Cloak-plugin: https://github.com/cbeuw/Cloak/releases 64位系统选择:ck-client-windows-amd64-x.x.x.exe,32位系统选择:ck-client-windows-386-x.x.x.exe(x为数字,是版本号) ****** - //sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS08").ToString()); - - //****** 在Shadowsocks (windows)运行文件所在文件夹中,新建文件夹plugins,将obfs-local.zip解压出的文件(两个)全部复到plugins中, - //v2ray -plugin下载得到的文件,解压出的文件,复制到plugins中,并重命名为:v2ray-plugin.exe。 - //Kcptun -plugin下载得到的文件,解压出两个文件,将其中的client_windows开头的文件,复制到plugins中,并重命名为:kcptun-client.exe。 - //GoQuiet-plugin下载得到的文件,直接复制到plugin中,并重命名为:goquiet-client.exe。 - //Cloak-plugin下载得到的文件,直接复制到plugin中,并重命名为:cloak-client.exe - //****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS09").ToString()); - //******安装完毕 ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSS10").ToString()); - - sw.WriteLine("-----------------------------------------\n"); - - //******手机安卓客户端插件安装说明 ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSSandroid02").ToString()); - - //****** 先下载插件,各个插件安卓客户端下载地址为: ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSSandroid03").ToString()); - - //****** Simple-obfs: https://github.com/shadowsocks/simple-obfs-android/releases 只下载 obfs-local-nightly-x.x.x.apk(x为数字,是版本号) ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSSandroid04").ToString()); - - //****** V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin-android/releases 一般选择v2ray--universal-x.x.x.apk(x为数字,是版本号)****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSSandroid05").ToString()); - - //****** Kcptun-plugin: https://github.com/shadowsocks/kcptun-android/releases 一般选择kcptun--universal-x.x.x.apk(x为数字,是版本号)****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSSandroid06").ToString()); - //******将上述apk文件传到手机,安装即可! ****** - sw.WriteLine(Application.Current.FindResource("readmeTxtPluginExplainSSandroid07").ToString()); - - } - - } - - } - - #region SS内容双击复制到剪贴板 - private void TextBoxHostAddressSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxHostAddressSS.Text); - } - - private void TextBoxPortSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPortSS.Text); - } - - private void TextBoxPasswordSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPasswordSS.Text); - } - - private void TextBoxEncryptionSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxEncryptionSS.Text); - } - - private void TextBoxPluginNameExplainSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPluginNameExplainSS.Text); - } - private void TextBoxPluginNameExplainSSpc_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPluginNameExplainSSpc.Text); - } - - private void TextBoxPluginOptionExplainSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxPluginOptionExplainSS.Text); - } - - private void TextBoxURLpcSS_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxURLpcSS.Text); - } - - #endregion - - #endregion - - #region MTProto 界面控制 - private void RadioButtonMtgIpv4_Checked(object sender, RoutedEventArgs e) - { - GridMtgIpv4.Visibility = Visibility.Visible; - GridMtgIpv6.Visibility = Visibility.Collapsed; - } - - private void RadioButtonMtgIpv6_Checked(object sender, RoutedEventArgs e) - { - GridMtgIpv4.Visibility = Visibility.Collapsed; - GridMtgIpv6.Visibility = Visibility.Visible; - } - private void TextBoxURLMtgTgIpv4_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxURLMtgTgIpv4.Text); - } - - private void TextBoxURLMtgTmeIpv4_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxURLMtgTmeIpv4.Text); - } - - private void TextBoxURLMtgTgIpv6_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxURLMtgTgIpv6.Text); - } - - private void TextBoxURLMtgTmeIpv6_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - CopyToClipboard(TextBoxURLMtgTmeIpv6.Text); - } - - #endregion - - //生成base64 - private string ToBase64Encode(string text) - { - if (String.IsNullOrEmpty(text)) - { - return text; - } - - byte[] textBytes = Encoding.UTF8.GetBytes(text); - return Convert.ToBase64String(textBytes); - } - - //生成QRcoder图片,并按给出的路径与名称保存,返回窗口显示的图片源 - private BitmapSource CreateQRCode(string varBase64,string configPath) - { - QRCodeGenerator qrGenerator = new QRCodeGenerator(); - QRCodeData qrCodeData = qrGenerator.CreateQrCode(varBase64, QRCodeGenerator.ECCLevel.Q); - QRCode qrCode = new QRCode(qrCodeData); - Bitmap qrCodeImage = qrCode.GetGraphic(20); - IntPtr myImagePtr = qrCodeImage.GetHbitmap(); - BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); - //ImageShareQRcode.Source = imgsource; - //DeleteObject(myImagePtr); - qrCodeImage.Save(configPath); - return imgsource; - - } - - //判断目录是否存在,不存在则创建 - private string CheckDir(string folder) - { - try - { - if (!Directory.Exists(folder))//如果不存在就创建file文件夹 - Directory.CreateDirectory(folder);//创建该文件夹   - return folder; - } - catch (Exception) - { - return ""; - } - } - - //目录已存在则生成序号递增,并返回所创建的目录路径。 - private string CreateConfigSaveDir(string upperDir,string configDir) - { - try - { - //string saveFileFolderFirst = configDir; - int num = 1; - //saveFileFolder = EncodeURIComponent(configDir); - saveFileFolder = configDir.Replace(":","_"); - CheckDir(upperDir); - while (Directory.Exists(upperDir + @"\" + saveFileFolder) == true) - { - saveFileFolder = configDir + "_copy_" + num.ToString(); - num++; - } - CheckDir(upperDir + @"\" + saveFileFolder); - return upperDir + @"\" + saveFileFolder; - } - catch (Exception) - { - saveFileFolder = ""; - return upperDir + @"\" + saveFileFolder; - } - - } - - //打开文件夹 - private void ButtonOpenSaveDir_Click(object sender, RoutedEventArgs e) - { - string openFolderPath = configDomainSavePath; - System.Diagnostics.Process.Start("explorer.exe", openFolderPath); - this.Close(); - - } - - //SSR生成URL链接 - private string GetSSRLinkForServer() - { - string server = TextBoxSSRHostAddress.Text; - string server_port = TextBoxSSRPort.Text; - string password = TextBoxSSRUUID.Text; - string protocol = TextBoxSSRTransmission.Text; - string method = TextBoxSSREncryption.Text; - string obfs = TextBoxSSRCamouflageType.Text; - - string obfsparam=""; - string protocolparam = ""; - string remarks = TextBoxSSRHostAddress.Text; - string group = TextBoxSSRHostAddress.Text; - bool udp_over_tcp = true; - int server_udp_port = 0; - - string main_part = server + ":" + server_port + ":" + protocol + ":" + method + ":" + obfs + ":" + EncodeUrlSafeBase64(password); - string param_str = "obfsparam=" + EncodeUrlSafeBase64(obfsparam ?? ""); - if (!string.IsNullOrEmpty(protocolparam)) - { - param_str += "&protoparam=" + EncodeUrlSafeBase64(protocolparam); - } - if (!string.IsNullOrEmpty(remarks)) - { - param_str += "&remarks=" + EncodeUrlSafeBase64(remarks); - } - if (!string.IsNullOrEmpty(group)) - { - param_str += "&group=" + EncodeUrlSafeBase64(group); - } - if (udp_over_tcp) - { - param_str += "&uot=" + "1"; - } - if (server_udp_port > 0) - { - param_str += "&udpport=" + server_udp_port.ToString(); - } - string base64 = EncodeUrlSafeBase64(main_part + "/?" + param_str); - return "ssr://" + base64; - } - - //SS生成URL链接,需要给出plugin的内容,用于生成手机端或电脑端的URL - public string GetSStoURL(string plugin,bool legacyUrl = true) - { - string tag = string.Empty; - string url = string.Empty; - - server = TextBoxHostAddressSS.Text; - string server_port = TextBoxPortSS.Text; - - string password = TextBoxPasswordSS.Text; - string method = TextBoxEncryptionSS.Text; - - // plugin = TextBoxPluginNameExplainSS.Text; - string plugin_opts = TextBoxPluginOptionExplainSS.Text; - - string remarks = server; - - if (legacyUrl && string.IsNullOrWhiteSpace(plugin)) - { - // For backwards compatiblity, if no plugin, use old url format - string parts = $"{method}:{password}@{server}:{server_port}"; - string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); - url = base64; - } - else - { - // SIP002 - string parts = $"{method}:{password}"; - string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); - string websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('='); - - url = string.Format( - "{0}@{1}:{2}/", - websafeBase64, - FormalHostName, - server_port - ); - - if (!String.IsNullOrWhiteSpace(plugin)) - { - - string pluginPart = plugin; - if (!String.IsNullOrWhiteSpace(plugin_opts)) - { - pluginPart += ";" + plugin_opts; - } - string pluginQuery = "?plugin=" + HttpUtility.UrlEncode(pluginPart, Encoding.UTF8); - url += pluginQuery; - } - } - - if (!String.IsNullOrEmpty(remarks)) - { - tag = $"#{HttpUtility.UrlEncode(remarks, Encoding.UTF8)}"; - } - return $"ss://{url}{tag}"; - } - - //格式化主机名称 - private string FormalHostName - { - get - { - // CheckHostName() won't do a real DNS lookup - switch (Uri.CheckHostName(server)) - { - case UriHostNameType.IPv6: // Add square bracket when IPv6 (RFC3986) - return $"[{server}]"; - default: // IPv4 or domain name - return server; - } - } - } - //编码安全Base64 - private string EncodeUrlSafeBase64(byte[] val, bool trim) - { - if (trim) - return Convert.ToBase64String(val).Replace('+', '-').Replace('/', '_').TrimEnd('='); - else - return Convert.ToBase64String(val).Replace('+', '-').Replace('/', '_'); - } - //编码安全Base64重载 - private string EncodeUrlSafeBase64(string val, bool trim = true) - { - return EncodeUrlSafeBase64(Encoding.UTF8.GetBytes(val), trim); - } - - private void RadioButtonMobile_Checked(object sender, RoutedEventArgs e) - { - TextBoxPluginNameExplainSS.Visibility = Visibility.Visible; - GroupBoxClientQRandURL.Visibility = Visibility.Visible; - - TextBoxPluginNameExplainSSpc.Visibility = Visibility.Collapsed; - GroupBoxClientSSpc.Visibility = Visibility.Collapsed; - - } - - private void RadioButtonPC_Checked(object sender, RoutedEventArgs e) - { - TextBoxPluginNameExplainSS.Visibility = Visibility.Collapsed; - GroupBoxClientQRandURL.Visibility = Visibility.Collapsed; - - TextBoxPluginNameExplainSSpc.Visibility = Visibility.Visible; - GroupBoxClientSSpc.Visibility = Visibility.Visible; - } - - /// - ///生成固定长度的空格字符串 - /// - /// - /// - - private string SpaceStrFunc(int length) - { - string strReturn = string.Empty; - if (length > 0) - { - for (int i = 0; i < length; i++) - { - strReturn += " "; - } - } - return strReturn; - } - - /// - ///将字符串生转化为固定长度左对齐,右补空格 - /// - ///需要补齐的字符串 - ///补齐后的长度 - /// - - private string AlignmentStrFunc(string strTemp, int length) - { - byte[] byteStr = System.Text.Encoding.Default.GetBytes(strTemp.Trim()); - int iLength = byteStr.Length; - int iNeed = length - iLength; - - byte[] spaceLen = Encoding.Default.GetBytes(" "); //一个空格的长度 - iNeed = iNeed / spaceLen.Length; - - string spaceString = SpaceStrFunc(iNeed); - //return strTemp + spaceString; - return spaceString + strTemp; - } - - - } - - -} diff --git a/ProxySU/SSpluginWindow.xaml b/ProxySU/SSpluginWindow.xaml deleted file mode 100644 index a3af977a..00000000 --- a/ProxySU/SSpluginWindow.xaml +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/SSpluginWindow.xaml.cs b/ProxySU/SSpluginWindow.xaml.cs deleted file mode 100644 index f1f508b3..00000000 --- a/ProxySU/SSpluginWindow.xaml.cs +++ /dev/null @@ -1,394 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace ProxySU -{ - /// - /// SSpluginWindow.xaml 的交互逻辑 - /// - public partial class SSpluginWindow : Window - { - //SS加密方法设定 - public class EncryptionMethodInfo - { - public string Name { get; set; } - public string Value { get; set; } - } - public SSpluginWindow() - { - InitializeComponent(); - - #region 加密方法选择 初始设置为chacha20-ietf-poly1305 - List methodList = new List(); - - methodList.Add(new EncryptionMethodInfo { Name = "chacha20-ietf-poly1305", Value = "chacha20-ietf-poly1305" }); - methodList.Add(new EncryptionMethodInfo { Name = "xchacha20-ietf-poly1305", Value = "xchacha20-ietf-poly1305" }); - methodList.Add(new EncryptionMethodInfo { Name = "aes-256-gcm", Value = "aes-256-gcm" }); - methodList.Add(new EncryptionMethodInfo { Name = "aes-192-gcm", Value = "aes-192-gcm" }); - methodList.Add(new EncryptionMethodInfo { Name = "aes-128-gcm", Value = "aes-128-gcm" }); - - ComboBoxEncryptionMethodInfo.ItemsSource = methodList; - - ComboBoxEncryptionMethodInfo.DisplayMemberPath = "Name";//显示出来的值 - ComboBoxEncryptionMethodInfo.SelectedValuePath = "Value";//实际选中后获取的结果的值 - ComboBoxEncryptionMethodInfo.SelectedIndex = 0; - - DataContext = this; - #endregion - } - - - - //取消不在当前活动选项卡中的其他所有选项卡中的所有RadioBuuton的选中状态 - //代码参考网址:https://blog.csdn.net/weixin_42583999/article/details/103468857 - //调用:UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - private void UncheckLayouts(TabItem activePage) - { - foreach (TabItem tabPage in TabControlTemplate.Items) - { - if (tabPage == activePage) continue; - Grid grid = (Grid)tabPage.Content; - foreach (UIElement element in grid.Children) - { - if (element is RadioButton) - { - RadioButton radiobutton = (element as RadioButton); - radiobutton.IsChecked = false; - } - - } - } - } - - - //伪装网站处理 - //private string DisguiseURLprocessing(string fakeUrl) - //{ - //var uri = new Uri(fakeUrl); - //return uri.Host; - //处理伪装网站域名中的前缀 - //if (fakeUrl.Length >= 7) - //{ - // string testDomainMask = fakeUrl.Substring(0, 7); - // if (String.Equals(testDomainMask, "https:/") || String.Equals(testDomainMask, "http://")) - // { - // string[] tmpUrl = fakeUrl.Split('/'); - // fakeUrl = tmpUrl[2]; - // } - - //} - //return fakeUrl; - // } - - private void ButtondDecide_Click(object sender, RoutedEventArgs e) - { - bool preDomainMask = ClassModel.PreDomainMask(TextBoxMaskSites.Text); - bool domainNotEmpty = true; - //UncheckLayouts(TabControlTemplate); - //SS 经典模式被选中 - if (RadioButtonNonePluginSS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "NonePluginSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonNonePluginSS.Content.ToString(); - - } - //SS+obfs+http+web伪装模式被选中 - else if (RadioButtonObfsPluginHttpWebSS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "ObfsPluginHttpWebSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonObfsPluginHttpWebSS.Content.ToString(); - - } - //SS+obfs+TLS+web模式被选中 - else if (RadioButtonObfsPluginHttpsWebSS.IsChecked == true) - { - - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomainSS.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "ObfsPluginHttpsWebSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonObfsPluginHttpsWebSS.Content.ToString(); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomainSS.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //V2Ray-Plugin SS+WebSocket 无TLS模式被选中 - else if (RadioButtonWebSocketSS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketSS.Content.ToString(); - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxWebSocketPathSS.Text); - } - - //V2Ray-Plugin SS+WebSocket+TLS+Web模式被选中 - else if (RadioButtonWebSocketTLSWebFrontSS.IsChecked == true || RadioButtonWebSocketTLSWebFrontSSHot.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomainSS.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLSWebFrontSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLSWebFrontSS.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxWebSocketPathSS.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomainSS.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - //V2Ray-Plugin SS+QUIC模式被选中 - else if (RadioButtonQuicSS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomainSS.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicSS.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomainSS.Text); - - } - //SS+kcptun-plugin模式被选中 - else if (RadioButtonKcptunPluginSS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "KcptunPluginSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonKcptunPluginSS.Content.ToString(); - - } - //SS+GoQuiet-Plugin模式被选中 - else if (RadioButtonGoQuietPluginSS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomainSS.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "GoQuietPluginSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonGoQuietPluginSS.Content.ToString(); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomainSS.Text); - - } - //SS+Cloak-Plugin模式被选中 - else if (RadioButtonCloakPluginSS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomainSS.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "CloakPluginSS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonCloakPluginSS.Content.ToString(); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomainSS.Text); - - } - - //传递服务端口 - MainWindow.ReceiveConfigurationParameters[1] = PreTrim(TextBoxServerListenPortSS.Text); - //传递uuid密码 - MainWindow.ReceiveConfigurationParameters[2] = PreTrim(TextBoxNewUUIDSS.Text); - //传递加密方式 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - - if (domainNotEmpty == true && preDomainMask == true) - { - this.Close(); - } - - } - - private void ButtondCancel_Click(object sender, RoutedEventArgs e) => Close(); - - - #region 其他设置中的界面控制 - - //无插件的界面 - private void RadioButtonNonePluginSS_Checked(object sender, RoutedEventArgs e) - { - //隐藏Websocket Path - TextBlockWebSocketPathSS.Visibility = Visibility.Collapsed; - TextBoxWebSocketPathSS.Visibility = Visibility.Collapsed; - ButtonWebSocketPathSS.Visibility = Visibility.Collapsed; - - //隐藏域名 - TextBlockDomainSS.Visibility = Visibility.Collapsed; - TextBoxDomainSS.Visibility = Visibility.Collapsed; - //检测域名按钮 - ButtonDomain.Visibility = Visibility.Collapsed; - //隐藏伪装网站 - TextBlockMaskSites.Visibility = Visibility.Collapsed; - TextBoxMaskSites.Visibility = Visibility.Collapsed; - - //初始化密码 - TextBoxNewUUIDSS.Text = GenerateRandomUUID(); - //初始化端口 - - TextBoxServerListenPortSS.Text = GenerateRandomPort().ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - //使用域名,启用TLS 无Websocket的界面 - private void RadioButtonUseDomainTls_Checked(object sender, RoutedEventArgs e) - { - - TextBoxServerListenPortSS.Text = "443"; - //隐藏Websocket Path - TextBlockWebSocketPathSS.Visibility = Visibility.Collapsed; - TextBoxWebSocketPathSS.Visibility = Visibility.Collapsed; - ButtonWebSocketPathSS.Visibility = Visibility.Collapsed; - - //显示域名 - TextBlockDomainSS.Visibility = Visibility.Visible; - TextBoxDomainSS.Visibility = Visibility.Visible; - //检测域名按钮 - ButtonDomain.Visibility = Visibility.Collapsed; - //显示伪装网站 - TextBlockMaskSites.Visibility = Visibility.Visible; - TextBoxMaskSites.Visibility = Visibility.Visible; - - //初始化密码 - TextBoxNewUUIDSS.Text = GenerateRandomUUID(); - //初始化端口 - //TextBoxServerListenPortSS.Text = GenerateRandomPort().ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - //使用V2ray-plugin 的Websocket over https (TLS) - private void RadioButtonUseDomainWebsocketTls_Checked(object sender, RoutedEventArgs e) - { - - TextBoxServerListenPortSS.Text = "443"; - //显示Websocket Path - TextBlockWebSocketPathSS.Visibility = Visibility.Visible; - TextBoxWebSocketPathSS.Visibility = Visibility.Visible; - ButtonWebSocketPathSS.Visibility = Visibility.Visible; - - //显示域名 - TextBlockDomainSS.Visibility = Visibility.Visible; - TextBoxDomainSS.Visibility = Visibility.Visible; - //检测域名按钮 - ButtonDomain.Visibility = Visibility.Collapsed; - //显示伪装网站 - TextBlockMaskSites.Visibility = Visibility.Visible; - TextBoxMaskSites.Visibility = Visibility.Visible; - - //初始化密码 - TextBoxNewUUIDSS.Text = GenerateRandomUUID(); - - //初始化端口 - - //TextBoxServerListenPortSS.Text = GenerateRandomPort().ToString(); - - //初始化Websocket Path - TextBoxWebSocketPathSS.Text = GenerateRandomPath(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - #endregion - - //加密方法更改后的动作 - private void ComboBoxEncryptionMethodInfo_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - //传递加密方式 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - - } - - //产生随机的uuid - private void ButtonNewUUID_Click(object sender, RoutedEventArgs e) - { - TextBoxNewUUIDSS.Text = GenerateRandomUUID(); - } - - //产生随机服务端口 - private void ButtonServerListenPort_Click(object sender, RoutedEventArgs e) - { - TextBoxServerListenPortSS.Text = GenerateRandomPort().ToString(); - } - //产生随机的Path - private void ButtonPath_Click(object sender, RoutedEventArgs e) - { - TextBoxWebSocketPathSS.Text = GenerateRandomPath(); - } - - #region 相关参数生成函数 - //产生随机的UUID - private string GenerateRandomUUID() - { - Guid uuid = Guid.NewGuid(); - return uuid.ToString(); - } - //产生随机端口 - private int GenerateRandomPort() - { - Random random = new Random(); - return random.Next(30001, 50000); - } - //读取加密方式 - private string GetEncryptionMethodSS() - { - //string methodName; - //object methodSelected; - //methodSelected = ComboBoxEncryptionMethodInfo.SelectedValue; - //methodName = methodSelected.ToString(); - //return methodName; - return ComboBoxEncryptionMethodInfo.SelectedValue.ToString(); - } - //产生随机的Path - private string GenerateRandomPath() - { - Random random = new Random(); - int randomSerialNum = random.Next(0, 4); - Guid uuid = Guid.NewGuid(); - string[] pathArray = uuid.ToString().Split('-'); - string path = pathArray[randomSerialNum]; - return $"/{path}"; - } - - #endregion - - //TextBox输入内容做预处理 - private string PreTrim(string preString) - { - return preString.Trim(); - } - - //域名检测是否为空 - //private bool TestDomainIsEmpty() - //{ - // if (string.IsNullOrEmpty(PreTrim(TextBoxDomainSS.Text)) == true) - // { - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return false; - // } - // else - // { - // return true; - // } - //} - } -} diff --git a/ProxySU/Translations/ProxySU.en-US.xaml b/ProxySU/Translations/ProxySU.en-US.xaml deleted file mode 100644 index 4007373d..00000000 --- a/ProxySU/Translations/ProxySU.en-US.xaml +++ /dev/null @@ -1,617 +0,0 @@ - - - The new version has been released! - Downloading...Wait Prompt... - The download of the latest version failed, please try again later! - Download the latest version successfully, the file has been saved in the same directory of the current ProxySU.exe - Update - 界面語言: - Deployment - Resources - Free Wall URL - Common Error - Host: - IP or Domain (Not empty) - Port: - User: - Password: - Key: - Key file Path (Not Empty) - Open... - Password Login - Key Login - No Proxy - Not Login - Requires Login - Proxy Addr: - Save Installation Log... - Waiting for installation and deployment - System Tools - - Xray template library - Xray one-click installation - Upgrade Xay - - V2Ray Templates - V2ray install - Upgrade V2Ray - Cancel - Trojan-Go Templates - Trojan-Go install - Upgrade Trojan-Go - Cancel - Currently selected plan: - No plan selected - - Parameter settings - Mode: Trojan+TLS+Caddy - Domain: - Port: 443 - Domain Not Empty - Password: - Change - Trojan install - Upgrade Trojan - Cancel - - Mode: NaiveProxy+TLS+Caddy - Random - NaiveProxy install - Cancel - - Mode: SSR+TLS+Caddy - SSR install - - - Mode: MTProto+TLS - MTProto install - Making domain name: - Recommended https ports 443, 2053, 2083, 2087, 2096, 8443 - The secret key will be randomly generated by the server. - - - SS install - SS plug-in library - Classic mode - Tip: This mode, long time, large traffic use, easy to be blocked and interfered, is not recommended! - SS Classic - SS classic use mode, no domain name is required, data is encrypted with high strength, and the data is recognized as unknown data. At present, the traffic is easy to be identified, and it is easy to be interfered and blocked. Use it with caution! Putting here is just a feeling and tribute! - Simple-obfs plug-in - Tip: This is a traffic obfuscation scheme used in the early days of SS. The plug-in has not been updated for a long time and is not recommended! - SS+obfs+http+Web - Does not require a domain name, the data is highly encrypted, the traffic is confused as http (not the real http), and the use of Web site camouflage can enhance the anti-recognition to a certain extent! CDN is not supported. - SS+obfs+TLS(https)+Web - requires a domain name, the use of a domain name will greatly enhance the anti-identification, high-strength data encryption, traffic confusion as https (not real https), the use of Web site camouflage, further enhance the anti-identification! CDN is not supported. - V2Ray plug-in - Reminder: ShadowRocket(ios) does not support SS+Quic mode - SS+WebSocket+TLS+Caddy (Web post) - SS+WebSocket+TLS+Caddy (Web front) - Tip: In the above scheme, there is no difference in the use effect between Web front and Web post. In the Web post scheme, the TLS certificate is applied for by acme.sh. After the certificate expires, acme.sh will automatically renew, but you need to manually restart SS to load the new certificate. The certificate in the web front-end solution is automatically applied for and loaded by Caddy without restarting SS. - SS+QUIC - V2Ray-Plugin uses QUIC protocol for transmission, and TLS encryption is mandatory. Encrypted data transmission, identified as udp traffic, was originally initiated by Google, advantages: reduced delay, multiplexing, connection migration, domain name is required, - - kcptun Plugin - Reminder: Shadowrocket(ios) does not support GoQuiet-plugin. shadowsocks (Android) does not support GoQuiet-plugin and Cloak-plugin plug-ins - KCP is a fast and reliable protocol. It can waste 10%-20% of bandwidth than TCP in exchange for a 30%-40% reduction in average latency and a three-fold reduction in maximum latency The transmission effect. Use UDP protocol for transmission, high-strength data encryption, transmission of the same content, kcp generally consumes more traffic than TCP, and will greatly increase the network speed under lines with high packet loss rates, and may be restricted by QOS at individual operators . - The basic principle is to simulate TLS traffic while disguising the server as a normal web server. This confusion is not the first: simple-obfs and ShadowsocksR’s tls1.2_ticket_auth mode proves this. It works. This plug-in improves the existing methods, and its goal is to make large-scale blockade of HTTPS servers (even IP segments) the only effective way to block SS - Use encryption to confuse proxy traffic into legitimate HTTPS traffic, and disguise the proxy server as a normal Web server to avoid Internet censorship. It can be seen as an upgraded version of GoQuiet above, optimizing the network connection speed, and not confusing https but real https traffic. - Plugin program: - Plugin options: - Use the compilation method, it will take a little longer, please be patient... - - - Proofreading Time - Release 80/443 - Enable BBR - Uninstall Proxy - Enable root password login - root prohibits password login - Enable root certificate key login - Only the proxy software installed by ProxySU and related configurations are supported. Please make sure that important configurations have been backed up. Uninstalling agents installed using other methods or scripts is not supported. Are you sure you want to uninstall the agent software on the remote host? - This function requires that the currently logged-in account has sudo permissions. Is the root account enabled and password set for the remote host? - This function requires that the currently logged-in account has root or sudo authority. Is root certificate key login enabled for the remote host? - This function requires that the remote host has enabled other login methods, such as key mode, etc., otherwise the remote host may not be able to connect. Is the root account password login method of the remote host prohibited? - is closing the root account password login method..... - The remote host root account password login method is closed! - The root account certificate key login of the remote host has been enabled, and the key file rootuser.key is saved in the subsequent opened folder! - The current account already has root privileges, no need to set it up! - The current account cannot obtain sudo permission, the setting failed! - Generate a 20-digit random password! - Save password information! - Generating a key... - The key is being downloaded... - The remote host enables key login....... - The remote host Root account password login is enabled, and the password is saved in the folder opened afterwards! - Start uninstall...... - Detected installed - Uninstallation failed! Please ask the developer! - Uninstall successfully! - - Home - Forward - Back - Due to well-known reasons, loading is slow at certain times, please be patient - - Trojan-go template library - http/2 transmission, Caddy2 camouflage website, anti-recognition, CDN of CloudFlare is not currently supported - Use WebSocket transmission, Caddy2 camouflage website, anti-identification, support CloudFlare CDN - Parameter settings - Domain name: - Port: 443 - Password: - Use the existing password and paste it directly into the box - WebSocket Path: - Mux multiplexing - The settings here are only valid for the official client configuration file config.json, other clients need to be set manually, and the server automatically adapts. - This field does not appear in the QR code and sharing URL. The client needs to set it by itself, and the server enables automatic adaptation by default. - OK - Cancel - - V2Ray Templates - Recommend - EarlyPlan - VLESS - VLESS is a lightweight transmission protocol. Unlike VMess, VLESS don't depend on the system time. The authentication method is also UUID, but alterId is not required. Currently VLESS does not have its own encryption, please use it for reliable channels, such as TLS. Advantages: It can effectively reduce host resource consumption. Currently VLESS does not support sharing. Please ensure that both the client and server v2ray-core are the latest version. - XTLS works well on devices with low performance or without AES hard-decoding. For example, XTLS is used on hard routers, and the network speed can be doubled when the CPU is full, or the same The CPU occupancy rate is halved at Internet speed, and for mobile devices, the reduction in the amount of calculation means power saving.Version requires 4.29+ (Domain required) Not support CDN. - Lightweight protocol VLESS, occupies less host resources, data TLS encrypted transmission, and Caddy2 is used as a disguised website on the node. Suitable for VPS with low configuration, or shared nodes by multiple people, the server client version requires 4.27+ (Domain required) Notsupport CDN. - VLESS protocol, this type of solution with VMESS is more lightweight. Stability is strong, Caddy2 is front-facing, hidden proxy features, it is recognized as https traffic visiting the website, the strongest anti-blocking recognition, (Domain required) CDN is supported - VLESS protocol, this type of solution with VMESS is more lightweight. Based on HTTP/2 transmission. Completely implemented in accordance with the HTTP/2 standard, with Caddy2 as the front, hidden proxy features, H2C protocol forwarding to V2Ray, (Domain required) CloudFlare CDN is not supported - TCP - WebSocket - Http/2 - mKCP - QUIC - Parameter settings - Server port: - Random - If TLS encryption is used, please keep the default port 443 - Use the existing UUID and paste it directly into the box - QUIC Key: - mKCP Seed: - Enable the mKCP Seed key to enhance anti-recognition, leave it blank to disable it. Version 4.24.2+ - Path: - VLESS ws path: - VMESS tcp path: - VMESS ws path: - QUIC Encryption: - Domain name: - Trojan password is the same as V2ray UUID. - Mask a website: - Set this option to increase proxy concealment (can be empty) - Enter only the domain name, excluding "http" and "/" etc. - Only forbid root account to log in with password, please make sure that other login methods of root account have taken effect - The root account will be enabled and set to password login - will enable or set the root account as the key certificate login - The input format of the fake URL is wrong! please enter again! - Strong stability, Caddy2 as the front, hidden proxy feature, recognized as https traffic to the website, the strongest anti-blocking recognition, domain name is required, CDN support - based on HTTP/2 transmission. Completely implemented in accordance with the HTTP/2 standard, with Caddy2 as the front, hidden proxy features, H2C protocol forwarding to V2Ray, domain name is required, and CloudFlare CDN is not currently supported - Currently Xray is a superset of V2Ray, and it will have a different development direction from V2Ray in the future. - VLESS over TCP with XTLS + fallback and shunt to WHATEVER (ultimate configuration), configured and recommended by rprx boss (author of xtls), configure the following six solutions at the same time on the server side, sharing the same domain name and port 443, WS can pass through CDN. - VLESS over TCP with XTLS + fallback and shunt to WHATEVER (ultimate configuration), configured and recommended by rprx boss (author of xtls), configure the following five solutions at the same time on the server side, sharing the same domain name and port 443, WS can pass through CDN.(If you want to add XTLS scheme, please use Xray configuration) - Encrypted data transmission will be recognized as unknown tcp traffic - TCP+Http camouflage - Encrypted data transmission and HTTP disguise will be recognized as http traffic, but not real http access - Data encrypted transmission, the transmission protocol uses TLS, it will be recognized as TLS traffic, not equivalent to https traffic characteristics (domain name required) - TCP+TLS (self-signed certificate) - Data encrypted transmission, the transmission protocol uses TLS, it will be recognized as TLS traffic, not equivalent to https traffic characteristics (no domain name required) - Shadowrocket (ios) needs to manually open the "Allow Unsafe" option - Data encrypted transmission, the transmission protocol uses WebSocket, if TLS is not enabled, it will be recognized as WebSocket traffic. - Data encrypted transmission, the transmission protocol uses WebSocket, and TLS is enabled, it will be recognized as TLS traffic. (Domain name required),Support CDN. - WebSocket+TLS (self-signed certificate) - Data encrypted transmission, the transmission protocol uses WebSocket, and TLS is enabled, and it will be recognized as TLS traffic. (No domain name required) - The transmission method based on HTTP/2. It is fully implemented in accordance with the HTTP/2 standard and requires a domain name - HTTP2 (self-signed certificate) - The transmission method based on HTTP/2. It is fully implemented in accordance with the HTTP/2 standard, uses a self-signed certificate, and does not require a domain name - mKCP (no camouflage) - Encrypted data transmission to increase bandwidth usage and reduce delay, udp protocol, no camouflage, will be recognized as udp traffic - Same as mKCP (without camouflage), add disguised as SRTP packet, it will be recognized as video call data (such as FaceTime) - Same as mKCP (without camouflage), adding a uTP packet disguised as a uTP data packet will be recognized as BT download data - Same as mKCP (no camouflage), adding data packets disguised as WeChat video calls - Same as mKCP (without camouflage), add disguised as DTLS 1.2 data packet - Same as mKCP (without camouflage), with the addition of disguised as WireGuard packets. (Not the real WireGuard protocol) - Reminder: Shadowrocket currently does not support QUIC transmission mode. - QUIC (no camouflage) - Encrypted data transmission, no pretense will be recognized as udp traffic, originally created by Google, advantages: reduced delay, multiplexing, connection migration - Same as QUIC (no camouflage), adding a packet disguised as SRTP, it will be recognized as video call data (such as FaceTime) - Same as QUIC (without camouflage), add disguised as uTP data packet, it will be recognized as BT download data - Same as QUIC (no camouflage), adding data packets disguised as WeChat video calls - Same as QUIC (without camouflage), add disguised as DTLS 1.2 packet - Same as QUIC (without camouflage), adding a pretend to be a WireGuard packet. (Not the real WireGuard protocol) - - Sync Network Time - Correct the remote host time to the network time. Note: The time of the local computer must also be synchronized with the network time, otherwise the local computer V2ray may have a connection error Recommendation: First use this method to proofread time - Sync local time - Synchronize the remote host’s time to the local time. Note: The local computer’s time must be accurate and synchronized with the network time, otherwise there may be connection errors in other clients Use this method when you can’t check the time when using the network - Update the local time - Synchronize the local computer time with the network time. Note: To use this function, you must run this program as an administrator - Detection Time - Proofread - - Client configuration parameters - Server address: - Port: - User ID(uuid)/Password: - Copy - Copied to the clipboard! - Empty content! - alterId: - The default is 16, and you can fill in a value not exceeding 64. If the client does not have this option, leave it blank - Encryption method: - Transfer Protocol: - Camouflage type(Confuse): - TLS Set: - Tip: Double-click the above content window to copy it to the clipboard. - Path: - mKCP Seed/QUIC key: - default auto - QR/URL - The above parameters can be entered into the client manually or by scanning. The configuration and related files used for the official client have been stored in the directory. Click the OK button to open - QR code and URL link can be used v2rayN(windows) Qv2ray(windows) Qv2ray(windows) Shadowrocket(ios) v2rayNG(Android) Import v2ray node Note: The Vless protocol requires manual input of configuration parameters, and the QR code and URL are invalid - " can be used for ShadowRocket (ios), ignore (Android), Qv2ray (windows) to scan codes and import URLs. Note: some clients may not support WebSocket mode ." - "Can be used for ShadowRocket (ios), ignore (Android), Qv2ray (windows) to scan codes and import URLs. Note: Some clients may not support WebSocket mode." - URL import link for NaiveSharp (windows) - Used to scan codes and import URL import links for ShadowsocksR (windows), SSRR (android), Shadowrocket (ios) - For mobile phone client shadowsocks(android), Shadowrocket(ios) scan code and URL import link - For the computer client Shadowsocks (windows) scan code and URL import link - Scan code and URL import link for Shadowsocks (windows), shadowsocks(android), Shadowrocket(ios) - Reminder: The import format of the computer client Shadowsocks (windows) and the mobile client shadowsocks (android) and Shadowrocket (ios) are not compatible. Please select the corresponding format. - Mobile phone - Computer side - TG format QR - TG format URL (double-click to copy to the clipboard) - T.ME format QR - T.ME format URL (double-click to copy to the clipboard) - - Host address, host port, and user name are required and cannot be empty!! - The connection port contains non-numeric characters! - The login password is required and cannot be empty!! - The key file is required and cannot be empty!! - If a proxy is selected, the proxy address and port cannot be empty! - If the proxy needs to log in, the user name and password for proxy login cannot be empty! - The remote host connection information is wrong, please check! - Please select a configuration template first! - An error occurred, the installation was interrupted... - Logging in to the remote host... - The host login is successful! - Detect whether it is running under root permissions... - Please use an account with root permissions to log in to the host! ! - Detection result: OK! - Check whether the system has been installed - The remote host has been installed - , it is recommended to uninstall first, or reinstall the system, if the forced installation may fail. Do you force a reinstallation? - installation canceled, exit - Selected mandatory installation - Test result: not installed - Check whether the system meets the installation requirements... - The current system kernel version is - , V2ray requires the kernel to be 2.6.23 and above. Please upgrade the kernel and install again! - The system kernel version does not meet the requirements, and the installation failed! ! - The system lacks necessary installation components such as: apt||dnf||yum||zypper||Syetemd, the host system is recommended to use: CentOS 7/8, Debian 8/9/10 ,Ubuntu 16.04 and above - The system environment does not meet the requirements, and the installation fails! ! - Test result: OK! - It is detected that the system has SELinux enabled and it is working in strict mode. It needs to be changed to relaxed mode! Modifying... - The modification is complete! - Proofreading time... - The difference between the local time and the remote host’s time exceeds the limit (90 seconds), please use'System Tools-->Time Correction' to verify the time before setting - Time comparison failed... - The time difference meets the requirements, OK! - is checking whether the domain name is resolved to the IP of the current VPS... - is detecting whether it is a pure ipv6 host... - A valid IP address was not detected... - Finding the fastest Nat64 gateway... - Failed to find a valid Nat64 gateway... - The fastest Nat64 gateway of the current host is: - Nat64 gateway is being set up...... - Nat64 gateway is being deleted... - The resolution is correct! OK! - detects that the current host is a pure ipv6 host, it is not currently supported! - The domain name could not be correctly resolved to the IP of the current VPS! Installation failed! - The domain name cannot be correctly resolved to the IP of the current VPS, please check! If the resolution setting is correct, please wait for it to take effect before retrying the installation. If the domain name uses CDN, please close it first! - Detect port occupancy... - If one or all of the 80/443 ports are occupied, will the program occupying 80/443 ports be forcibly stopped? - The port is occupied and the installation failed... - is releasing port 80/443... - The release of port 80/443 is complete! - The port is occupied, will the program occupying this port be forcibly stopped? - Release the port... - The port is released! - Test result: Not occupied! - The system environment has been tested and the installation requirements are met, and the deployment begins... - Open the corresponding port of the firewall... - Installing - File download failed! - Compiling, please wait patiently............. - The installation failed, the script runs incorrectly! - The installation is successful! - After installation, upload the configuration file...... - Installing acme.sh...... - acme.sh is installed successfully! - acme.sh installation failed! The reason is unknown, please ask the developer! - Apply for domain name certificate... - The certificate application is successful! - Certificate application failed! The reason is unknown, please ask the developer! - Install the certificate to - The certificate is successfully installed to - The certificate is installed to - failed, the reason is unknown, you can ask the developer! - Install Caddy... - Test result: Caddy is not installed! - The installation of Caddy failed! - Caddy installed successfully! - is upgrading the Caddy v2.2.0 beta version for Http2Web mode! - Upload Caddy configuration file... - Caddy configuration file upload failed! - The Caddy configuration file is uploaded successfully, OK! - Starting Caddy... - Caddy started successfully! - Caddy failed to start! - Starting Caddy (second attempt)! - Caddy failed to start (second time)! Exit the installation! - Caddy failed to start, the reason is unknown! Please ask the developer! - Starting - Startup is successful! - Startup failed! - is trying to start the second time - failed to start (second time)! Exit the installation! - Startup failed, the reason is as above! Please troubleshoot the reason! - BBR test... - Enable BBR... - BBR has been enabled! - The system does not meet the conditions for enabling BBR, and the enabling failed! - BBR is successfully activated! - Generate client configuration... - Failed to obtain client configuration! - The installation is successful, Enjoy it!! - Installation Failed! - An error occurred! - Wrong password or wrong username! - Please check whether the host address and port are correct, if it passes the proxy, please check whether the proxy is working properly - The selected key file is wrong or the format is wrong! - Login using the key, the key file is wrong or the user name is wrong! - The host address is wrong. If a proxy is used, it may also be the wrong port to connect to the proxy! - Exit! Reason: The remote host is not installed - V2Ray using the old installation script is detected... - The V2Ray using the old installation script is detected. Do you want to uninstall the old version and reinstall it with the new installation script? - Uninstalling the old version... - Uninstall the old version, OK! - Install the new version... - Migrate the original configuration file. - has been updated to the latest version. - The current version of the remote host is: v - The latest version is: - Is it upgraded to the latest version? - Upgrading to the latest version - The upgrade is successful! It is currently the latest version! - The upgrade failed. The reason is unknown. Please ask the developer! - Upgrade is cancelled, exit! - The remote host is currently the latest version: - No need to upgrade! drop out! - The domain name cannot be empty, please check the relevant parameter settings! - Please install in x86_64 system - Back up the Trojan configuration file... - Restore the Trojan configuration file... - "Caddy has been installed on the remote host, but I’m not sure whether it supports forward proxy. Do I force a reinstallation?" - Please uninstall Caddy or reinstall the VPS system first! - Installing dependent software...... - The installation is complete! OK! - Installing Caddy..... - The server is being upgraded for NaiveProxy - The upgrade is complete, OK! - Optimizing network parameters... - Optimize network parameters, OK! - - This file is the client configuration file used by the official Xay program. It is configured in global mode, socks5 address: 127.0.0.1:1080, http proxy address: 127.0.0.1:1081 - Xray official website: https://github.com/XTLS/Xray-core - Xray official program download address: https://github.com/XTLS/Xray-core/releases - Download the corresponding version, select xray-windows-64.zip or xray-windows-32.zip for Windows, extract xray.exe after decompression. Put it in the same directory as config.json, just run xray.exe. - - This file is the client configuration file used by the official V2Ray program. It is configured in global mode, socks5 address: 127.0.0.1:1080, http proxy address: 127.0.0.1:1081 - v2ray official website: https://www.v2ray.com/ - v2ray official program download address: https://github.com/v2ray/v2ray-core/releases - download the corresponding version, Windows select v2ray-windows-64.zip or v2ray-windows-32.zip, extract v2ctl.exe and v2ray.exe after decompression. Put it in the same directory as config.json, just run v2ray.exe. - This file is v2rayN, Qv2ray, v2rayNG(Android), Shadowrocket(ios) scan code import node - v2rayN download URL: https://github.com/2dust/v2rayN/releases - Qv2ray download URL: https://github.com/Qv2ray/Qv2ray/releases - v2rayNG(Android) download URL: https://github.com/2dust/v2rayNG/releases - v2rayNG (Android) download URL on Google Play: https://play.google.com/store/apps/details?id=com.v2ray.ang - Shadowrocket(ios) download, you need to use the AppleID of the foreign region. Please Google method yourself. - This file is v2rayN, Qv2ray, v2rayNG(Android), Shadowrocket(ios) copy and paste the vmess URL of the imported node - Server general connection configuration parameters - - This file is the client configuration file used by the official Trojan-go program, configured in global mode, http and socks5 address: 127.0.0.1:1080 - Trojan-go official website: https://github.com/p4gefau1t/trojan-go - Trojan-go official program download address: https://github.com/p4gefau1t/trojan-go/releases - Download the corresponding version, select Trojan-go-x.xx-win.zip for Windows, extract trojan-go.exe after decompression. Put it in the same directory as config.json, just run trojan-go.exe. - This file is for Qv2ray (windows), ignore (Android) scan code import node - Qv2ray (windows) download URL: https://github.com/Qv2ray/Qv2ray/releases - igniter (Android) download URL: https://github.com/trojan-gfw/igniter/releases - Shadowrocket(ios) download, you need to use the AppleID of the foreign region. Please Google method yourself. - This file is Qv2ray (windows), ignore (Android)copy and paste the URL of the imported node - Server general connection configuration parameters - - This file is the client configuration file used by the official Trojan program. It is configured in global mode, http and socks5 address: 127.0.0.1:1080 - Trojan official website: https://trojan-gfw.github.io/trojan/ - Trojan official program download address: https://github.com/trojan-gfw/trojan/releases - Download the corresponding version, select Trojan-x.xx-win.zip for Windows, extract trojan.exe after decompression. Put it in the same directory as config.json, just run trojan.exe. - This file is Qv2ray (windows), ignore (Android), Shadowrocket (ios) scan code import node - Qv2ray (windows) download URL: https://github.com/Qv2ray/Qv2ray/releases - igniter (Android) download URL: https://github.com/trojan-gfw/igniter/releases - Shadowrocket(ios) download, you need to use the AppleID of the foreign region. Please Google method yourself. - This file is Qv2ray (windows), ignore (Android), Shadowrocket (ios) copy and paste the URL of the imported node - Server general connection configuration parameters - - This file is the client configuration file used by the official NaiveProxy program, configured in global mode, socks5 address: 127.0.0.1:1080 - NaiveProxy official website: https://github.com/klzgrad/naiveproxy - NaiveProxy official program download address: https://github.com/klzgrad/naiveproxy/releases - download the corresponding version, select naiveproxy-x.xx-win.zip for Windows, extract naive.exe after decompression. Put it in the same directory as config.json, just run naive.exe. - This file is NaiveSharp (windows) copy and paste the URL of the imported node - NaiveSharp(windows) download URL: https://github.com/KevinZonda/NaiveSharp/releases - Server general connection configuration parameters - - This file is for ShadowsocksR (windows), SSRR (Android), Shadowrocket (ios) scan code import node - ShadowsocksR (windows) download URL: https://github.com/shadowsocksrr/shadowsocksr-csharp/releases - SSRR (Android) download URL: https://github.com/shadowsocksrr/shadowsocksr-android/releases - Shadowrocket(ios) download, you need to use the AppleID of the foreign region. Please Google method yourself. - This file is ShadowsocksR (windows), SSRR (Android), Shadowrocket (ios) copy and paste the URL of the imported node - Server general connection configuration parameters - - This file is a Shadowsocks (windows) scan code import node - This file is Shadowsocks (windows) copy and paste the URL of the imported node - This file is for shadowsocks (Android), Shadowrocket (ios) scan code to import nodes - Shadowsocks (windows) download URL: https://github.com/shadowsocks/shadowsocks-windows/releases - shadowsocks (Android) download URL: https://github.com/shadowsocks/shadowsocks-android/releases - Shadowrocket(ios) download, you need to use the AppleID of the foreign region. Please Google method yourself. - This file is shadowsocks (Android), Shadowrocket (ios) copy and paste the URL of the imported node - Server general connection configuration parameters - plug-in instructions - ProxySU defaults all plug-ins, under the subfolder plugins of the folder where the Shadowsocks (windows) run file is located. - Instructions for manually installing the plug-in on the computer - First download the plug-in, the download address of each plug-in Windows client is: - Simple-obfs: https://github.com/shadowsocks/simple-obfs/releases only download obfs-local.zip - V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin/releases 64-bit system selection: v2ray-plugin-windows-amd64-vx.xxtar.gz , 32-bit system selection: v2ray-plugin-windows-386-vx.xxtar.gz (x is a number, is the version number) - Kcptun-plugin: https://github.com/shadowsocks/kcptun/releases 64-bit system selection: kcptun-windows-amd64-xxxxxx.tar.gz, 32-bit system selection :Kcptun-plugin-windows-386-xxxxxx.tar.gz (x is a number, is the version number) - GoQuiet-plugin: https://github.com/cbeuw/GoQuiet/releases 64-bit system selection: gq-client-windows-amd64-xxxexe, 32-bit system selection: gq-client-windows-386-xxxexe (x is a number, is the version number) - Cloak-plugin: https://github.com/cbeuw/Cloak/releases 64-bit system selection: ck-client-windows-amd64-xxxexe, 32-bit system selection: ck-client-windows-386-xxxexe (x is a number, is the version number) - In the folder where the Shadowsocks (windows) run file is located, create a new folder plugins, and copy all the files (two) extracted from obfs-local.zip to plugins, v2ray -plugin download the file, unzip the file, copy it to plugins, and rename it to: v2ray-plugin.exe. Kcptun-plugin downloads the file, unzip the two files, copy the file starting with client_windows into the plugins, and rename it to: kcptun-client.exe. The file downloaded by GoQuiet-plugin is directly copied to the plugin and renamed to: goquiet-client.exe. The file downloaded by Cloak-plugin is directly copied to the plugin and renamed to: cloak-client.exe - installation completed - Mobile Android client plug-in installation instructions - first download the plug-in, the download address of each plug-in Android client is: - Simple-obfs: https://github.com/shadowsocks/simple-obfs-android/releases only download obfs-local-nightly-xxxapk (x is a number, is the version Number) - V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin-android/releases Generally choose v2ray--universal-xxxapk (x is a number, is the version number ) - Kcptun-plugin: https://github.com/shadowsocks/kcptun-android/releases Generally choose kcptun--universal-xxxapk (x is a number, is the version number) - Transfer the above apk file to the phone and install it! - - - - - - \ No newline at end of file diff --git a/ProxySU/Translations/ProxySU.zh-CN.xaml b/ProxySU/Translations/ProxySU.zh-CN.xaml deleted file mode 100644 index 825341a5..00000000 --- a/ProxySU/Translations/ProxySU.zh-CN.xaml +++ /dev/null @@ -1,505 +0,0 @@ - - - 最新版本已发布了,快去更新一下吧! - 正在下载最新版,请等待完成提示.... - 最新版下载失败,请稍后重试! - 下载最新版成功,文件已存入当前ProxySU.exe同一目录 - 下载更新 - Languages: - 应用布署 - 资源工具 - 免翻网址资源 - 常见问题 - 主机: - IP或域名(不可为空) - 端口: - 用户: - 密码: - 密钥: - 密钥文件存放路径(不可为空) - 浏览... - 密码登录 - 密钥登录 - 无代理 - 不需登录 - 需要登录 - 代理地址: - 安装日志另存为... - 等待安装布署 - 系统工具 - - Xray模板库 - Xray一键安装 - 升级Xay - - V2Ray模板库 - V2ray一键安装 - 升级V2ray - 取消 - - Trojan-Go参数设置 - Trojan-Go一键安装 - 升级Trojan-Go - 取消 - 当前所选方案: - 未选择方案 - - 参数设置 - 模式:Trojan+TLS+Caddy - 服务器地址(域名): - 端口:443 - 域名不可为空 - 密码: - 更新 - Trojan一键安装 - 升级Trojan - 取消 - - 模式:NaiveProxy+TLS+Caddy - 随机 - NaiveProxy一键安装 - 取消 - - 模式:SSR+TLS+Caddy - SSR一键安装 - - - 模式:MTProto+TLS - MTProto一键安装 - 伪装域名: - 推荐用常见https端口443、2053、2083、2087、2096、8443 - 密钥将由服务端随机生成,这里无需设置。 - - - SS 一键安装 - SS 插件库 - 经典模式 - 提示:这种模式,长时间,大流量使用,容易被阻断和干扰,不推荐使用! - SS 经典 - SS经典使用模式,无需域名,数据高强度加密,数据被识别为未知数据。目前流量容易被识别,极易被干扰与阻断,慎重使用!放在这里仅仅只是一种情怀与致敬! - Simple-obfs 插件 - 提示:这是SS早期使用的流量混淆方案,插件已经长时间不再更新,不推荐使用! - SS+obfs+http+Web - 无需域名,数据高强度加密,流量混淆为http(并非真正的http),使用Web网站伪装,可在一定程度上增强抗识别!不支持CDN。 - SS+obfs+TLS(https)+Web - 需要域名,使用域名将很大增强抗识别,数据高强度加密,流量混淆为https(并非真正的https),使用Web网站伪装,进一步增强抗识别!不支持CDN。 - V2Ray 插件 - 提醒:ShadowRocket(ios)不支持SS+Quic模式 - SS+WebSocket+TLS+Caddy(Web后置) - SS+WebSocket+TLS+Caddy(Web前置) - 提示:上面方案中的Web前置与Web后置,使用效果上没有差别,Web后置方案,TLS证书由acme.sh申请,证书到期后,acme.sh会自动续期,但是需要手动重启SS加载新证书。而Web前置方案中的证书由Caddy自动申请并加载,不需要重启SS。 - SS+QUIC - 通过V2Ray-Plugin使用QUIC协议传输,强制使用TLS加密。数据加密传输,被识别为udp流量,最初由谷歌创始,优点:减少延迟、多路复用、连接迁移,需要域名, - - kcptun 插件 - 提醒:Shadowrocket(ios)不支持GoQuiet-plugin插件。shadowsocks(Android)不支持GoQuiet-plugin与Cloak-plugin插件 - KCP是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价,换取平均延迟降低 30%-40%,且最大延迟降低三倍的传输效果。使用UDP协议传输,数据高强度加密,传输同样的内容,kcp 一般比 TCP 消耗更多的流量,在丢包率高的线路下将极大提高网速,在个别运营商处可能会被QOS限制。 - 基本原理为模拟TLS的流量同时将服务器伪装成一个正常的网站服务器,这个混淆思路并非首创:simple-obfs和ShadowsocksR的tls1.2_ticket_auth模式证明这条道是行得通的。此插件对现有的方法进行了改善,其目标为让大规模封锁HTTPS服务器(甚至IP段)成为封锁SS的唯一有效手段 - 通过加密方式将代理流量混淆为合法的HTTPS流量,并将代理服务器伪装成普通的Web服务器以规避互联网审查。可以看成是上面GoQuiet升级版,优化网络连接速度,并且不是混淆https而是真正的https流量。 - 插件程序: - 插件选项: - 使用编译方式,时间稍长,请耐心等待...... - - - 校对时间 - 释放80/443端口 - 启用BBR - 卸载代理 - 启用root密码登录 - 启用root证书密钥登录 - root禁止密码登录 - 仅支持卸载由ProxySU安装的代理软件及相关配置,请确保重要配置已备份。不支持卸载使用其他方法或脚本安装的代理。确定要卸载远程主机上的代理软件吗? - 本功能需要当前登录的账户具有sudo权限,是否为远程主机启用root账户并设置密码? - 本功能需要当前登录的账户具有root或者sudo权限,是否为远程主机启用root证书密钥登录? - 本功能需要远程主机已经开启了其他登录方式,如密钥方式等,否则将可能造成远程主机无法连接,是否禁止远程主机的root账户密码登录方式? - 正在关闭root账户密码登录方式..... - 远程主机root账户密码登录方式已关闭! - 远程主机root账户证书密钥登录已启用,密钥文件rootuser.key保存在随后打开的文件夹中! - 当前账户已经具有root权限,无需再设置! - 当前账户无法获取sudo权限,设置失败! - 生成20位随机密码! - 保存密码信息! - 正在生成密钥...... - 正在下载密钥...... - 远程主机启用密钥登录....... - 远程主机Root账户密码登录已启用,密码保存在随后打开的文件夹中! - 开始卸载 - 检测到已安装 - 卸载失败!请向开发者问询! - 卸载成功! - - - 主页 - 前进 - 后退 - 由于众所周知的原因,在某些时候,加载缓慢,请耐心等待一下 - - Trojan-go 模板库 - http/2传输,Caddy2伪装网站,抗识别,暂不支持CloudFlare的CDN - 使用WebSocket传输,Caddy2伪装网站,抗识别,支持CloudFlare的CDN - 参数设置 - 域名: - 端口: 443 - 密码: - 使用已有密码,直接粘贴到框中 - WebSocket路径: - Mux多路复用 - 此处设置只对官方客户端配置文件config.json有效,其他客户端需手动设置,服务端自动适配。 - 此字段不出现在QR码及分享URL中,客户端需自行设置,服务端默认启用自动适配。 - 确定 - 取消 - - V2Ray 模板库 - 推荐方案 - 尝鲜方案 - VLESS协议 - VLESS 是一个无状态的轻量传输协议,与 VMess 不同,VLESS 不依赖于系统时间,认证方式同样为 UUID,但不需要 alterId。目前 VLESS 没有自带加密,请用于可靠信道,如 TLS。优点:可以有效的降低主机资源消耗。目前 VLESS 不支持分享。VLESS 处于公测阶段,测试期间请确保客户端与服务端的 v2ray-core 均为最新版本。 - XTLS 在低性能或没有 AES 硬解的设备上效果出众,如在硬路由上换用 XTLS,同样跑满 CPU 时实现网速 翻倍,或是相同网速时 CPU 占用率减半,而对于移动设备,计算量减少意味着省电。服务端客户端版本要求4.29+ (需域名)不支持CDN。 - 轻量协议VLESS,占用更少主机资源,数据TLS加密传输,用Caddy2在节点上做伪装网站。适合配置低的VPS,或多人共用节点,服务端客户端版本要求4.27+ (需域名)不支持CDN。 - 使用VLESS协议,与VMESS的此类型方案,更轻量。稳定性强,Caddy2做前置,隐藏代理特征,被识别为访问网站的https流量,抗封锁识别最强,需要域名,支持CDN - 使用VLESS协议,与VMESS的此类型方案,更轻量。基于 HTTP/2 传输。完整按 HTTP/2 标准实现,Caddy2做前置,隐藏代理特征,H2C协议转发到V2Ray,需要域名,暂不支持CloudFlare的CDN - - TCP传输协议 - WebSocket传输协议 - Http/2传输协议 - mKCP传输协议 - QUIC传输协议 - 参数设置 - 服务器端口: - 随机选择 - 若使用TLS加密,请保持默认的443端口 - 使用已有UUID,直接粘贴到框中 - QUIC密钥: - mKCP Seed: - 启用mKCP Seed密钥,可增强抗识别,留空则禁用,要求版本4.24.2+ - 路径: - VLESS ws路径: - VMESS tcp路径: - VMESS ws路径: - - QUIC加密方式: - 域名: - Trojan密码与UUID相同。 - 伪装网站: - 设置此项可增加代理的隐蔽(可为空) - 仅仅输入域名,不包括"http"及"/"等 - 仅仅禁止root账户使用密码登录,请确保root账户其他登录方式已生效 - 将启用root账户,并设置为密码登录 - 将启用或设置root账户为密钥证书登录 - 伪装网址输入格式错误!请重新输入! - 稳定性强,Caddy2做前置,隐藏代理特征,被识别为访问网站的https流量,抗封锁识别最强,需要域名,支持CDN - 基于 HTTP/2 传输。完整按 HTTP/2 标准实现,Caddy2做前置,隐藏代理特征,H2C协议转发到V2Ray,需要域名,暂不支持CloudFlare的CDN - 当前Xray是V2Ray的超集,未来与V2Ray会有不同的发展方向。 - VLESS over TCP with XTLS + 回落 and 分流 to WHATEVER(终极配置),由rprx大佬 (xtls作者) 配置并推荐,在服务端同时配置以下六种方案,共用同一域名与443端口,其中 WS 都可以通过 CDN。 - VLESS over TCP with XTLS + 回落 and 分流 to WHATEVER(终极配置),由rprx大佬 (xtls作者) 配置并推荐,在服务端同时配置以下五种方案,共用同一域名与443端口,其中 WS 都可以通过 CDN。(想增加XTLS方案请使用Xray配置) - TCP+Http伪装 - 数据加密传输,会被识别为未知的tcp流量 - 数据加密传输,并做http伪装,会被识别为http流量,但并不是真正的http访问 - 数据加密传输,传输协议使用TLS,会被识别为TLS流量,不等同于https流量特征 (需域名) - TCP+TLS(自签证书) - 数据加密传输,传输协议使用TLS,会被识别为TLS流量,不等同于https流量特征 (无需域名) - Shadowrocket (ios)需要手动打开“允许不安全”选项 - 数据加密传输,传输协议使用WebSocket,未启用TLS,将被识别为WebSocket流量。 - 数据加密传输,传输协议使用WebSocket,启用TLS,将被识别为TLS流量。(需要域名)支持CDN。 - WebSocket+TLS(自签证书) - 数据加密传输,传输协议使用WebSocket,启用TLS,将被识别为TLS流量。(无需域名) - 基于 HTTP/2 的传输方式。它完整按照 HTTP/2 标准实现,需要域名 - HTTP2(自签证书) - 基于 HTTP/2 的传输方式。它完整按照 HTTP/2 标准实现,使用自签名证书,不需要域名 - mKCP(无伪装) - 数据加密传输,以增加带宽占用,减少延迟,udp协议,无伪装,会被识别为udp流量 - 同mKCP(无伪装),增加伪装成 SRTP 数据包,会被识别为视频通话数据(如 FaceTime) - 同mKCP(无伪装),增加伪装成 uTP 数据包,会被识别为 BT 下载数据 - 同mKCP(无伪装),增加伪装成微信视频通话的数据包 - 同mKCP(无伪装),增加伪装成 DTLS 1.2 数据包 - 同mKCP(无伪装),增加伪装成 WireGuard 数据包。(并不是真正的 WireGuard 协议) - 提醒:Shadowrocket目前暂不支持QUIC的传输模式。 - QUIC(无伪装) - 数据加密传输,无伪装会被识别为udp流量,最初由谷歌创始,优点:减少延迟、多路复用、连接迁移 - 同QUIC(无伪装),增加伪装成 SRTP 数据包,会被识别为视频通话数据(如 FaceTime) - 同QUIC(无伪装),增加伪装成 uTP 数据包,会被识别为 BT 下载数据 - 同QUIC(无伪装),增加伪装成微信视频通话的数据包 - 同QUIC(无伪装),增加伪装成 DTLS 1.2 数据包 - 同QUIC(无伪装),增加伪装成 WireGuard 数据包。(并不是真正的 WireGuard 协议) - - 同步网络时间 - 将远程主机时间校正为网络时间,注意:本机电脑的时间必须也是与网络时间同步的,否则本机电脑V2ray有可能连接出错 推荐:优先使用此方法校对时间 - 同步本机时间 - 将远程主机时间同步为本地时间,注意:本机电脑的时间必须是准确的,与网络时间同步的,否则其他客户端中,有可能连接出错 使用网络校时无法校对时间时,使用此种方法 - 更新本机时间 - 将本机电脑时间与网络时间同步。 注意:使用此项功能,必须以管理员身份运行本程序 - 检测时间误差 - 校对时间 - - 客户端配置参数 - 服务器地址(address): - 端口(port): - 用户ID(uuid)/密码: - 复制 - 已复制到剪贴板中! - 空内容! - 额外ID: - 不超过64,客户端没此项可不填 - 加密方式: - 传输协议: - 伪装类型(混淆): - TLS设置: - 提示:双击以上内容窗,即可复制到剪贴板中。 - 路径(Path): - QUIC密钥: - mKCP Seed: - 默认auto - 二维码/URL - 以上参数可以手动或扫描输入客户端,用于官方客户端的配置和相关文件已经存放入目录下,点击 确定 按扭可打开 - 二维码和URL链接可用于 v2rayN(windows) Qv2ray(windows) Qv2ray(windows) Shadowrocket(ios) v2rayNG(Android) 导入v2ray节点 注意:Vless协议需要手动输入配置参数,二维码和URL无效 - "可用于ShadowRocket (ios)、igniter(Android)、Qv2ray (windows) 扫码和导入url。注意:有的客户端可能不支持WebSocket模式。" - "可用于ShadowRocket (ios)、igniter(Android)、Qv2ray (windows) 扫码和导入url。注意:有的客户端可能不支持WebSocket模式。" - 用于NaiveSharp(windows)的URL导入链接 - 用于ShadowsocksR(windows)、SSRR(android)、Shadowrocket(ios)的扫码和URL导入链接 - 用于手机客户端shadowsocks(android)、Shadowrocket(ios)的扫码和URL导入链接 - 用于电脑客户端Shadowsocks (windows)的扫码和URL导入链接 - 用于Shadowsocks (windows)、shadowsocks(android)、Shadowrocket(ios)的扫码和URL导入链接 - 提醒: 电脑客户端Shadowsocks (windows)与手机客户端shadowsocks(android)、Shadowrocket(ios)的导入格式不兼容,请选择相应格式。 - 手机端 - 电脑端 - TG格式QR - TG格式URL(双击复制到剪切板中) - T.ME格式QR - T.ME格式URL(双击复制到剪切板中) - - - 主机地址、主机端口、用户名为必填项,不能为空!! - 连接端口含有非数字字符! - 登录密码为必填项,不能为空!! - 密钥文件为必填项,不能为空!! - 如果选择了代理,则代理地址与端口不能为空! - 如果代理需要登录,则代理登录的用户名与密码不能为空! - 远程主机连接信息有误,请检查! - 请先选择配置模板! - 发生错误,安装中断...... - 正在登录远程主机...... - 主机登录成功! - 检测是否运行在root权限下... - 请使用具有root权限的账户登录主机!! - 检测结果:OK! - 检测系统是否已经安装 - 远程主机已安装 - ,建议先执行卸载,或者重装系统,若强制安装有一定机率失败。是否强制重新安装? - 安装取消,退出 - 已选择强制安装 - 检测结果:未安装 - 检测系统是否符合安装要求...... - 当前系统内核版本为 - ,V2ray要求内核为2.6.23及以上。请升级内核再安装! - 系统内核版本不符合要求,安装失败!! - 系统缺乏必要的安装组件如:apt||dnf||yum||zypper||Syetemd,主机系统推荐使用:CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本 - 系统环境不满足要求,安装失败!! - 检测结果:OK! - 检测到系统启用SELinux,且工作在严格模式下,需改为宽松模式!修改中...... - 修改完毕! - 校对时间...... - 本地时间与远程主机时间相差超过限制(90秒),请先用 '系统工具-->时间校对' 校对时间后再设置 - 时间较对失败...... - 时间差符合要求,OK! - 正在检测域名是否解析到当前VPS的IP上...... - 正在检测是否为纯ipv6主机...... - 未检测到有效的IP地址...... - 正在查找最快的Nat64网关...... - 未能找到有效的Nat64网关...... - 当前主机最快的Nat64网关为: - 正在设置Nat64网关...... - 正在删除Nat64网关...... - 解析正确!OK! - 检测当前主机为纯ipv6主机,目前暂不支持! - 域名未能正确解析到当前VPS的IP上!安装失败! - 域名未能正确解析到当前VPS的IP上,请检查!若解析设置正确,请等待生效后再重试安装。如果域名使用了CDN,请先关闭! - 检测端口占用情况...... - 80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序? - 端口被占用,安装失败...... - 正在释放80/443端口...... - 80/443端口释放完毕! - 端口被占用,将强制停止占用此端口的程序? - 正在释放端口...... - 端口释放完毕! - 检测结果:未被占用! - 系统环境检测完毕,符合安装要求,开始布署...... - 开启防火墙相应端口...... - 正在安装 - 文件下载失败! - 编译中,请耐心等待............. - 安装失败,脚本运行出错! - 安装成功! - 安装完毕,上传配置文件...... - 正在安装acme.sh...... - acme.sh安装成功! - acme.sh安装失败!原因未知,请向开发者提问! - 申请域名证书...... - 证书申请成功! - 证书申请失败!原因未知,请向开发者提问! - 安装证书到 - 证书成功安装到 - 证书安装到 - 失败,原因未知,可以向开发者提问! - 安装Caddy...... - 检测结果:未安装Caddy! - 安装Caddy失败! - Caddy安装成功! - 正在为Http2Web模式升级Caddy v2.2.0测试版! - 上传Caddy配置文件...... - Caddy配置文件上传失败! - Caddy配置文件上传成功,OK! - 正在启动Caddy...... - Caddy启动成功! - Caddy启动失败! - 正在启动Caddy(第二次尝试)! - Caddy启动失败(第二次)!退出安装! - Caddy启动失败,原因未知!请向开发者问询! - 正在启动 - 启动成功! - 启动失败! - 正在第二次尝试启动 - 启动失败(第二次)!退出安装! - 启动失败,原因如上!请排查原因! - BBR测试...... - 正在启用BBR...... - BBR已经启用了! - 系统不满足启用BBR的条件,启用失败! - BBR 启用成功! - 生成客户端配置...... - 客户端配置获取失败! - 安装成功,祝你玩的愉快!! - 安装失败! - 发生错误! - 密码错误或用户名错误! - 请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作 - 所选密钥文件错误或者格式不对! - 使用密钥登录,密钥文件错误或用户名错误! - 主机地址错误,如果使用了代理,也可能是连接代理的端口错误! - 退出!原因:远程主机未安装 - 检测到使用旧安装脚本的V2Ray...... - 检测到使用旧安装脚本的V2Ray,是否卸载旧版本并使用新安装脚本重新安装? - 正在卸载旧版本...... - 卸载旧版本,OK! - 安装新版本...... - 迁移原配置文件。 - 已更新到最新版本。 - 远程主机当前版本为:v - 最新版本为: - 是否升级为最新版本? - 正在升级到最新版本 - 升级成功!当前已是最新版本! - 升级失败,原因未知,请向开发者提问! - 升级取消,退出! - 远程主机当前已是最新版本: - 无需升级!退出! - 域名不能为空,请检查相关参数设置! - 请在x86_64系统中安装 - 备份Trojan配置文件...... - 恢复Trojan配置文件...... - "远程主机已安装Caddy,但不确定是否支持forward proxy,是否强制重新安装?" - 请先行卸载Caddy或重装VPS系统! - 正在安装依赖的软件...... - 安装完毕!OK! - 正在安装Caddy..... - 正在为NaiveProxy升级服务端 - 升级完毕,OK! - 正在优化网络参数...... - 优化网络参数,OK! - - 此文件为Xay官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081 - Xray官方网站:https://github.com/XTLS/Xray-core - Xray官方程序下载地址:https://github.com/XTLS/Xray-core/releases - 下载相应版本,Windows选择xray-windows-64.zip或者xray-windows-32.zip,解压后提取xray.exe。与config.json放在同一目录,运行xray.exe即可。 - - - 此文件为V2Ray官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081 - v2ray官方网站:https://www.v2ray.com/ - v2ray官方程序下载地址:https://github.com/v2ray/v2ray-core/releases - 下载相应版本,Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip,解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录,运行v2ray.exe即可。 - - 此文件为v2rayN(windows)、Qv2ray(windows)、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点 - v2rayN下载网址:https://github.com/2dust/v2rayN/releases - Qv2ray下载网址:https://github.com/Qv2ray/Qv2ray/releases - v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases - v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang - Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。 - 此文件为v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址 - 服务器通用连接配置参数: - - 此文件为Trojan-go官方程序所使用的客户端配置文件,配置为全局模式,http与socks5地址:127.0.0.1:1080 - Trojan-go官方网站:https://github.com/p4gefau1t/trojan-go - Trojan-go官方程序下载地址:https://github.com/p4gefau1t/trojan-go/releases - 下载相应版本,Windows选择Trojan-go-x.xx-win.zip,解压后提取trojan-go.exe。与config.json放在同一目录,运行trojan-go.exe即可。 - 此文件为Qv2ray (windows)、igniter(Android)扫码导入节点 - Qv2ray (windows)下载网址:https://github.com/Qv2ray/Qv2ray/releases - igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases - Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。 - 此文件为Qv2ray (windows)、igniter(Android)复制粘贴导入节点的网址 - 服务器通用连接配置参数 - - 此文件为Trojan官方程序所使用的客户端配置文件,配置为全局模式,http与socks5地址:127.0.0.1:1080 - Trojan官方网站:https://trojan-gfw.github.io/trojan/ - Trojan官方程序下载地址:https://github.com/trojan-gfw/trojan/releases - 下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。 - 此文件为Qv2ray (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点 - Qv2ray (windows)下载网址:https://github.com/Qv2ray/Qv2ray/releases - igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases - Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。 - 此文件为Qv2ray (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址 - 服务器通用连接配置参数 - - 此文件为NaiveProxy官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080 - NaiveProxy官方网站:https://github.com/klzgrad/naiveproxy - NaiveProxy官方程序下载地址:https://github.com/klzgrad/naiveproxy/releases - 下载相应版本,Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录,运行naive.exe即可。 - 此文件为NaiveSharp(windows)复制粘贴导入节点的网址 - NaiveSharp(windows)下载网址:https://github.com/KevinZonda/NaiveSharp/releases - 服务器通用连接配置参数 - - 此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)扫码导入节点 - ShadowsocksR (windows)下载网址:https://github.com/shadowsocksrr/shadowsocksr-csharp/releases - SSRR(Android)下载网址:https://github.com/shadowsocksrr/shadowsocksr-android/releases - Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。 - 此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)复制粘贴导入节点的网址 - 服务器通用连接配置参数 - - 此文件为Shadowsocks (windows)扫码导入节点 - 此文件为Shadowsocks (windows)复制粘贴导入节点的网址 - 此文件为shadowsocks(Android)、Shadowrocket(ios)扫码导入节点 - Shadowsocks (windows)下载网址:https://github.com/shadowsocks/shadowsocks-windows/releases - shadowsocks(Android)下载网址:https://github.com/shadowsocks/shadowsocks-android/releases - Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。 - 此文件为shadowsocks(Android)、Shadowrocket(ios)复制粘贴导入节点的网址 - 服务器通用连接配置参数 - 插件使用说明 - ProxySU默认所有插件,在Shadowsocks (windows)运行文件所在文件夹的子文件夹plugins下。 - 电脑端手动安装插件说明 - 先下载插件,各个插件Windows客户端下载地址为: - Simple-obfs: https://github.com/shadowsocks/simple-obfs/releases 只下载 obfs-local.zip - V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin/releases 64位系统选择:v2ray-plugin-windows-amd64-vx.x.x.tar.gz,32位系统选择:v2ray-plugin-windows-386-vx.x.x.tar.gz (x为数字,是版本号) - Kcptun-plugin: https://github.com/shadowsocks/kcptun/releases 64位系统选择:kcptun-windows-amd64-xxxxxx.tar.gz,32位系统选择:kcptun-plugin-windows-386-xxxxxx.tar.gz (x为数字,是版本号) - GoQuiet-plugin: https://github.com/cbeuw/GoQuiet/releases 64位系统选择:gq-client-windows-amd64-x.x.x.exe,32位系统选择:gq-client-windows-386-x.x.x.exe(x为数字,是版本号) - Cloak-plugin: https://github.com/cbeuw/Cloak/releases 64位系统选择:ck-client-windows-amd64-x.x.x.exe,32位系统选择:ck-client-windows-386-x.x.x.exe(x为数字,是版本号) - 在Shadowsocks (windows)运行文件所在文件夹中,新建文件夹plugins,将obfs-local.zip解压出的文件(两个)全部复制到plugins中,v2ray -plugin下载得到的文件,解压出的文件,复制到plugins中,并重命名为:v2ray-plugin.exe。Kcptun -plugin下载得到的文件,解压出两个文件,将其中的client_windows开头的文件,复制到plugins中,并重命名为:kcptun-client.exe。GoQuiet-plugin下载得到的文件,直接复制到plugin中,并重命名为:goquiet-client.exe。Cloak-plugin下载得到的文件,直接复制到plugin中,并重命名为:cloak-client.exe - 安装完毕 - 手机安卓客户端插件安装说明 - 先下载插件,各个插件安卓客户端下载地址为: - Simple-obfs: https://github.com/shadowsocks/simple-obfs-android/releases 只下载 obfs-local-nightly-x.x.x.apk(x为数字,是版本号) - V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin-android/releases 一般选择v2ray--universal-x.x.x.apk(x为数字,是版本号) - Kcptun-plugin: https://github.com/shadowsocks/kcptun-android/releases 一般选择kcptun--universal-x.x.x.apk(x为数字,是版本号) - 将上述apk文件传到手机,安装即可! - - - - \ No newline at end of file diff --git a/ProxySU/Translations/ProxySU.zh-TW.xaml b/ProxySU/Translations/ProxySU.zh-TW.xaml deleted file mode 100644 index d6c233eb..00000000 --- a/ProxySU/Translations/ProxySU.zh-TW.xaml +++ /dev/null @@ -1,486 +0,0 @@ - - - 最新版本已發布了,快去更新一下吧! - 正在下載最新版,請等待完成提示.... - 最新版下載失敗,請稍後重試! - 下載最新版成功,文件已存入當前ProxySU.exe同一目錄 - 下載更新 - Languages: - 應用佈署 - 資源工具 - 免翻網址資源 - 常見問題 - 主機: - IP或域名(不可為空) - 端口: - 用戶: - 密碼: - 密鑰:: - 密鑰文件存放路徑(不可為空) - 瀏覽... - 密碼登錄 - 密鑰登錄 - 無代理 - 不需登錄 - 需要登錄 - 代理地址: - 安裝日誌另存為... - 等待安裝佈署 - 系統工具 - - Xray模板庫 - Xray一鍵安裝 - 升級Xay - - V2Ray模板庫 - V2ray一鍵安裝 - 升級V2Ray - 取消 - Trojan-Go參數設置 - Trojan-Go一鍵安裝 - 升級Trojan-Go - 取消 - 當前所選方案: - 未選擇方案 - - 參數設置 - 模式:Trojan+TLS+Caddy - 服務器地址(域名): - 端口:443 - 域名不可為空 - 密碼: - 更新 - Trojan一鍵安裝 - 升級Trojan - 取消 - - 模式:NaiveProxy+TLS+Caddy - 隨機 - NaiveProxy一鍵安裝 - 取消 - - 模式:SSR+TLS+Caddy - SSR一鍵安裝 - - - 模式:MTProto+TLS - MTProto一鍵安裝 - 偽裝域名: - 推薦用常見https端口443、2053、2083、2087、2096、8443 - 密鑰將由服務端隨機生成,這裡無需設置。 - - - SS 一鍵安裝 - SS 插件庫 - 經典模式 - 提示:這種模式,長時間,大流量使用,容易被阻斷和乾擾,不推薦使用! - SS 經典 - SS經典使用模式,無需域名,數據高強度加密,數據被識別為未知數據。目前流量容易被識別,極易被干擾與阻斷,慎重使用!放在這裡僅僅只是一種情懷與致敬! - Simple-obfs 插件 - 提示:這是SS早期使用的流量混淆方案,插件已經長時間不再更新,不推薦使用! - SS+obfs+http+Web - 無需域名,數據高強度加密,流量混淆為http(並非真正的http),使用Web網站偽裝,可在一定程度上增強抗識別!不支持CDN。 - SS+obfs+TLS(https)+Web - 需要域名,使用域名將很大增強抗識別,數據高強度加密,流量混淆為https(並非真正的https),​​使用Web網站偽裝,進一步增強抗識別!不支持CDN。 - V2Ray 插件 - 提醒:ShadowRocket(ios)不支持SS+Quic模式 - SS+WebSocket+TLS+Caddy(Web後置) - SS+WebSocket+TLS+Caddy(Web前置) - 提示:上面方案中的Web前置與Web後置,使用效果上沒有差別,Web後置方案,TLS證書由acme.sh申請,證書到期後, acme.sh會自動續期,但是需要手動重啟SS加載新證書。而Web前置方案中的證書由Caddy自動申請並加載,不需要重啟SS。 - SS+QUIC - 通過V2Ray-Plugin使用QUIC協議傳輸,強制使用TLS加密。數據加密傳輸,被識別為udp流量,最初由谷歌創始,優點:減少延遲、多路復用、連接遷移,需要域名, - - kcptun 插件 - 提醒:Shadowrocket(ios)不支持GoQuiet-plugin插件。 shadowsocks(Android)不支持GoQuiet-plugin與Cloak-plugin插件 - KCP是一個快速可靠協議,能以比TCP浪費10%-20%的帶寬的代價,換取平均延遲降低30%-40%,且最大延遲降低三倍的傳輸效果。使用UDP協議傳輸,數據高強度加密,傳輸同樣的內容,kcp 一般比TCP 消耗更多的流量,在丟包率高的線路下將極大提高網速,在個別運營商處可能會被QOS限制。 - 基本原理為模擬TLS的流量同時將服務器偽裝成一個正常的網站服務器,這個混淆思路並非首創:simple-obfs和ShadowsocksR的tls1.2_ticket_auth模式證明這條道是行得通的。此插件對現有的方法進行了改善,其目標為讓大規模封鎖HTTPS服務器(甚至IP段)成為封鎖SS的唯一有效手段 - 通過加密方式將代理流量混淆為合法的HTTPS流量,並將代理服務器偽裝成普通的Web服務器以規避互聯網審查。可以看成是上面GoQuiet升級版,優化網絡連接速度,並且不是混淆https而是真正的https流量。 - 插件程序: - 插件選項: - 使用編譯方式,時間稍長,請耐心等待...... - - - 校對時間 - 釋放80/443端口 - 啟用BBR - 卸載代理 - 啟用root密碼登錄 - root禁止密碼登錄 - 啟用root證書密鑰登錄 - 僅支持卸載由ProxySU安裝的代理軟件及相關配置,請確保重要配置已備份。不支持卸載使用其他方法或腳本安裝的代理。確定要卸載遠程主機上的代理軟件嗎? - 本功能需要當前登錄的賬戶具有sudo權限,是否為遠程主機啟用root賬戶並設置密碼? - 本功能需要當前登錄的賬戶具有root或者sudo權限,是否為遠程主機啟用root證書密鑰登錄? - 本功能需要遠程主機已經開啟了其他登錄方式,如密鑰方式等,否則將可能造成遠程主機無法連接,是否禁止遠程主機的root賬戶密碼登錄方式? - 正在關閉root賬戶密碼登錄方式..... - 遠程主機root賬戶密碼登錄方式已關閉! - 遠程主機root賬戶證書密鑰登錄已啟用,密鑰文件rootuser.key保存在隨後打開的文件夾中! - 當前賬戶已經具有root權限,無需再設置! - 當前賬戶無法獲取sudo權限,設置失敗! - 生成20位隨機密碼! - 保存密碼信息! - 正在生成密鑰...... - 正在下載密鑰...... - 遠程主機啟用密鑰登錄....... - 遠程主機Root賬戶密碼登錄已啟用,密碼保存在隨後打開的文件夾中! - 開始卸載...... - 檢測到已安裝 - 卸載失敗!請向開發者問詢! - 卸載成功! - - 主頁 - 前進 - 後退 - 由於眾所周知的原因,在某些時候,加載緩慢,請耐心等待一下 - - Trojan-go 模板庫 - http/2傳輸,Caddy2偽裝網站,抗識別,暫不支持CloudFlare的CDN - 使用WebSocket傳輸,Caddy2偽裝網站,抗識別,支持CloudFlare的CDN - 參數設置 - 域名: - 端口: 443 - 密碼: - 使用已有密碼,直接粘貼到框中 - WebSocket路徑: - Mux多路復用 - 此處設置只對官方客戶端配置文件config.json有效,其他客戶端需手動設置,服務端自動適配。 - 此字段不出現在QR碼及分享URL中,客戶端需自行設置,服務端默認啟用自動適配。 - 確定 - 取消 - - V2Ray 模板庫 - 推薦方案 - 嚐鮮方案 - VLESS協議 - VLESS 是一個無狀態的輕量傳輸協議,與 VMess 不同,VLESS 不依賴於系統時間,認證方式同樣為 UUID,但不需要 alterId。目前 VLESS 沒有自帶加密,請用於可靠信道,如 TLS。優點:可以有效的降低主機資源消耗。目前 VLESS 不支持分享。 VLESS 處於公測階段,測試期間請確保客戶端與服務端的 v2ray-core 均為最新版本。 - XTLS 在低性能或沒有AES 硬解的設備上效果出眾,如在硬路由上換用XTLS,同樣跑滿CPU 時實現網速翻倍,或是相同網速時CPU 佔用率減半,而對於移動設備,計算量減少意味著省電。服務端客戶端版本要求4.29+ (需域名)不支持CDN。 - 輕量協議VLESS,佔用更少主機資源,數據TLS加密傳輸,用Caddy2在節點上做偽裝網站。適合配置低的VPS,或多人共用節點,服務端客戶端版本要求4.27+ (需域名)不支持CDN。 - 使用VLESS協議,與VMESS的此類型方案,更輕量。穩定性強,Caddy2做前置,隱藏代理特徵,被識別為訪問網站的https流量,抗封鎖識別最強,需要域名,支持CDN - 使用VLESS協議,與VMESS的此類型方案,更輕量。基於 HTTP/2 傳輸。完整按 HTTP/2 標準實現,Caddy2做前置,隱藏代理特徵,H2C協議轉發到V2Ray,需要域名,暫不支持CloudFlare的CDN - TCP傳輸協議 - WebSocket傳輸協議 - Http/2傳輸協議 - mKCP傳輸協議 - QUIC傳輸協議 - 參數設置 - 服務器端口: - 隨機選擇 - 若使用TLS加密,請保持默認的443端口 - 使用已有UUID,直接粘貼到框中 - QUIC密鑰: - mKCP Seed: - 啟用mKCP Seed密鑰,可增強抗識別,留空則禁用,要求版本4.24.2+ - 路徑: - VLESS ws路徑: - VMESS tcp路徑: - VMESS ws路徑: - QUIC加密方式: - 域名: - Trojan密碼與V2ray的UUID相同。 - 偽裝網站: - 設置此項可增加代理的隱蔽(可為空) - 僅僅輸入域名,不包括"http"及"/"等 - 僅僅禁止root賬戶使用密碼登錄,請確保root賬戶其他登錄方式已生效 - 將啟用root賬戶,並設置為密碼登錄 - 將啟用或設置root賬戶為密鑰證書登錄 - 偽裝網址輸入格式錯誤!請重新輸入! - 穩定性強,Caddy2做前置,隱藏代理特徵,被識別為訪問網站的https流量,抗封鎖識別最強,需要域名,支持CDN - 基於 HTTP/2 傳輸。完整按 HTTP/2 標準實現,Caddy2做前置,隱藏代理特徵,H2C協議轉發到V2Ray,需要域名,暫不支持CloudFlare的CDN - 當前Xray是V2Ray的超集,未來與V2Ray會有不同的發展方向。 - VLESS over TCP with XTLS + 回落and 分流to WHATEVER(終極配置),由rprx大佬(xtls作者)配置並推薦,在服務端同時配置以下六種方案,共用同一域名與443端口,其中 WS 都可以通過 CDN。 - VLESS over TCP with XTLS + 回落and 分流to WHATEVER(終極配置),由rprx大佬(xtls作者)配置並推薦,在服務端同時配置以下五種方案,共用同一域名與443端口,其中 WS 都可以通過 CDN。(想增加XTLS方案請使用Xray配置) - 數據加密傳輸,會被識別為未知的tcp流量 - TCP+Http偽裝 - 數據加密傳輸,並做http偽裝,會被識別為http流量,但並不是真正的http訪問 - 數據加密傳輸,傳輸協議使用TLS,會被識別為TLS流量,不等同於https流量特徵 (需域名) - TCP+TLS(自簽證書) - 數據加密傳輸,傳輸協議使用TLS,會被識別為TLS流量,不等同於https流量特徵 (無需域名) - Shadowrocket (ios)需要手動打開“允許不安全”選項 - 數據加密傳輸,傳輸協議使用WebSocket,未啟用TLS,將被識別為WebSocket流量。 - 數據加密傳輸,傳輸協議使用WebSocket,啟用TLS,將被識別為TLS流量。 (需要域名)支持CDN。 - WebSocket+TLS(自簽證書) - 數據加密傳輸,傳輸協議使用WebSocket,啟用TLS,將被識別為TLS流量。 (無需域名) - 基於 HTTP/2 的傳輸方式。它完整​​按照 HTTP/2 標準實現,需要域名 - HTTP2(自簽證書) - 基於 HTTP/2 的傳輸方式。它完整​​按照 HTTP/2 標準實現,使用自簽名證書,不需要域名 - mKCP(無偽裝) - 數據加密傳輸,以增加帶寬佔用,減少延遲,udp協議,無偽裝,會被識別為udp流量 - 同mKCP(無偽裝),增加偽裝成 SRTP 數據包,會被識別為視頻通話數據(如 FaceTime) - 同mKCP(無偽裝),增加偽裝成 uTP 數據包,會被識別為 BT 下載數據 - 同mKCP(無偽裝),增加偽裝成微信視頻通話的數據包 - 同mKCP(無偽裝),增加偽裝成 DTLS 1.2 數據包 - 同mKCP(無偽裝),增加偽裝成 WireGuard 數據包。 (並不是真正的 WireGuard 協議) - 提醒:Shadowrocket目前暫不支持QUIC的傳輸模式。 - QUIC(無偽裝) - 數據加密傳輸,無偽裝會被識別為udp流量,最初由谷歌創始,優點:減少延遲、多路復用、連接遷移 - 同QUIC(無偽裝),增加偽裝成 SRTP 數據包,會被識別為視頻通話數據(如 FaceTime) - 同QUIC(無偽裝),增加偽裝成 uTP 數據包,會被識別為 BT 下載數據 - 同QUIC(無偽裝),增加偽裝成微信視頻通話的數據包 - 同QUIC(無偽裝),增加偽裝成 DTLS 1.2 數據包 - 同QUIC(無偽裝),增加偽裝成 WireGuard 數據包。 (並不是真正的 WireGuard 協議) - - 同步網絡時間 - 將遠程主機時間校正為網絡時間,注意:本機電腦的時間必須也是與網絡時間同步的,否則本機電腦V2ray有可能連接出錯 推薦:優先使用此方法校對時間 - 同步本機時間 - 將遠程主機時間同步為本地時間,注意:本機電腦的時間必須是準確的,與網絡時間同步的,否則其他客戶端中,有可能連接出錯 使用網絡校時無法校對時間時,使用此種方法 - 更新本機時間 - 將本機電腦時間與網絡時間同步。 注意:使用此項功能,必須以管理員身份運行本程序 - 檢測時間誤差 - 校對時間 - - 客戶端配置參數 - 服務器地址(address): - 端口(port): - 用戶ID(uuid)/密碼: - 複製 - 已復製到剪貼板中! - 空內容! - 額外ID: - 不超過64,客戶端沒此項可不填 - 加密方式: - 傳輸協議: - 偽裝類型(混淆): - TLS設置: - 提示:雙擊以上內容窗,即可複製到剪貼板中。 - 路徑(Path): - mKCP Seed/QUIC密鑰: - 默認auto - 二維碼/URL - 以上參數可以手動或掃描輸入客戶端,用於官方客戶端的配置和相關文件已經存放入目錄下,點擊 確定 按扭可打開 - 二維碼和URL鏈接可用於 v2rayN(windows) Qv2ray(windows) Qv2ray(windows) Shadowrocket(ios) v2rayNG(Android) 導入v2ray節點 注意:Vless協議需要手動輸入配置參數,二維碼和URL無效 - "可用於ShadowRocket (ios)、igniter(Android)、Qv2ray (windows) 掃碼和導入url。注意:有的客戶端可能不支持WebSocket模式。" - "可用於ShadowRocket (ios)、igniter(Android)、Qv2ray (windows) 掃碼和導入url。注意:有的客戶端可能不支持WebSocket模式。" - 用於NaiveSharp(windows)的URL導入鏈接 - 用於ShadowsocksR(windows)、SSRR(android)、Shadowrocket(ios)的掃碼和導入URL導入鏈接 - 用於手機客戶端shadowsocks(android)、Shadowrocket(ios)的掃碼和URL導入鏈接 - 用於電腦客戶端Shadowsocks (windows)的掃碼和URL導入鏈接 - 用於Shadowsocks (windows)、shadowsocks(android)、Shadowrocket(ios)的掃碼和URL導入鏈接 - 提醒: 電腦客戶端Shadowsocks (windows)與手機客戶端shadowsocks(android)、Shadowrocket(ios)的導入格式不兼容,請選擇相應格式。 - 手機端 - 電腦端 - TG格式QR - TG格式URL(雙擊複製到剪切板中) - T.ME格式QR - T.ME格式URL(雙擊複製到剪切板中) - - 主機地址、主機端口、用戶名為必填項,不能為空!! - 連接端口含有非數字字符! - 登錄密碼為必填項,不能為空!! - 密鑰文件為必填項,不能為空!! - 如果選擇了代理,則代理地址與端口不能為空! - 如果代理需要登錄,則代理登錄的用戶名與密碼不能為空! - 遠程主機連接信息有誤,請檢查! - 請先選擇配置模板! - 發生錯誤,安裝中斷...... - 正在登錄遠程主機...... - 主機登錄成功! - 檢測是否運行在root權限下... - 請使用具有root權限的賬戶登錄主機! ! - 檢測結果:OK! - 檢測系統是否已經安裝 - 遠程主機已安裝 - ,建議先執行卸載,或者重裝系統,若強制安裝有一定機率失敗。是否強制重新安裝? - 安裝取消,退出 - 已選擇強制安裝 - 檢測結果:未安裝 - 檢測系統是否符合安裝要求...... - 當前系統內核版本為 - ,V2ray要求內核為2.6.23及以上。請升級內核再安裝! - 系統內核版本不符合要求,安裝失敗! ! - 系統缺乏必要的安裝組件如:apt||dnf||yum||zypper||Syetemd,主機系統推薦使用:CentOS 7/8,Debian 8/9/10 ,Ubuntu 16.04及以上版本 - 系統環境不滿足要求,安裝失敗! ! - 檢測結果:OK! - 檢測到系統啟用SELinux,且工作在嚴格模式下,需改為寬鬆模式!修改中...... - 修改完畢! - 校對時間...... - 本地時間與遠程主機時間相差超過限制(90秒),請先用 '系統工具-->時間校對' 校對時間後再設置 - 時間較對失敗...... - 時間差符合要求,OK! - 正在檢測域名是否解析到當前VPS的IP上...... - 正在檢測是否為純ipv6主機...... - 未檢測到有效的IP地址...... - 正在查找最快的Nat64網關...... - 未能找到有效的Nat64網關...... - 當前主機最快的Nat64網關為: - 正在設置Nat64網關...... - 正在刪除Nat64網關...... - 解析正確! OK! - 檢測當前主機為純ipv6主機,目前暫不支持! - 域名未能正確解析到當前VPS的IP上!安裝失敗! - 域名未能正確解析到當前VPS的IP上,請檢查!若解析設置正確,請等待生效後再重試安裝。如果域名使用了CDN,請先關閉! - 檢測端口占用情況...... - 80/443端口之一,或全部被佔用,將強制停止佔用80/443端口的程序? - 端口被佔用,安裝失敗...... - 正在釋放80/443端口...... - 80/443端口釋放完畢! - 端口被佔用,將強制停止佔用此端口的程序? - 正在釋放端口...... - 端口釋放完畢! - 檢測結果:未被佔用! - 系統環境檢測完畢,符合安裝要求,開始佈署...... - 開啟防火牆相應端口...... - 正在安裝 - 文件下載失敗! - 編譯中,請耐心等待............. - 安裝失敗,腳本運行出錯! - 安裝成功! - 安裝完畢,上傳配置文件...... - 正在安裝acme.sh...... - acme.sh安裝成功! - acme.sh安裝失敗!原因未知,請向開發者提問! - 申請域名證書...... - 證書申請成功! - 證書申請失敗!原因未知,請向開發者提問! - 安裝證書到 - 證書成功安裝到 - 證書安裝到 - 失敗,原因未知,可以向開發者提問! - 安裝Caddy...... - 檢測結果:未安裝Caddy! - 安裝Caddy失敗! - Caddy安裝成功! - 正在為Http2Web模式升級Caddy v2.2.0測試版! - 上傳Caddy配置文件...... - Caddy配置文件上傳失敗! - Caddy配置文件上傳成功,OK! - 正在啟動Caddy...... - Caddy啟動成功! - Caddy啟動失敗! - 正在啟動Caddy(第二次嘗試)! - Caddy啟動失敗(第二次)!退出安裝! - Caddy啟動失敗,原因未知!請向開發者問詢! - 正在啟動 - 啟動成功! - 啟動失敗! - 正在第二次嘗試啟動 - 啟動失敗(第二次)!退出安裝! - 啟動失敗,原因如上!請排查原因! - BBR測試...... - 正在啟用BBR...... - BBR已經啟用了! - 系統不滿足啟用BBR的條件,啟用失敗! - BBR 啟用成功! - 生成客戶端配置...... - 客戶端配置獲取失敗! - 安裝成功,祝你玩的愉快! ! - 安裝失敗! - 發生錯誤! - 密碼錯誤或用戶名錯誤! - 請檢查主機地址及端口是否正確,如果通過代理,請檢查代理是否正常工作 - 所選密鑰文件錯誤或者格式不對! - 使用密鑰登錄,密鑰文件錯誤或用戶名錯誤! - 主機地址錯誤,如果使用了代理,也可能是連接代理的端口錯誤! - 退出!原因:遠程主機未安裝 - 檢測到使用舊安裝腳本的V2Ray...... - 檢測到使用舊安裝腳本的V2Ray,是否卸載舊版本並使用新安裝腳本重新安裝? - 正在卸載舊版本...... - 卸載舊版本,OK! - 安裝新版本...... - 遷移原配置文件。 - 已更新到最新版本。 - 遠程主機當前版本為:v - 最新版本為: - 是否升級為最新版本? - 正在升級到最新版本 - 升級成功!當前已是最新版本! - 升級失敗,原因未知,請向開發者提問! - 升級取消,退出! - 遠程主機當前已是最新版本: - 無需升級!退出! - 域名不能為空,請檢查相關參數設置! - 請在x86_64系統中安裝 - 備份Trojan配置文件...... - 恢復Trojan配置文件...... - "遠程主機已安裝Caddy,但不確定是否支持forward proxy,是否強制重新安裝?" - 請先行卸載Caddy或重裝VPS系統! - 正在安裝依賴的軟件...... - 安裝完畢! OK! - 正在安裝Caddy..... - 正在為NaiveProxy升級服務端 - 升級完畢,OK! - 正在優化網絡參數...... - 優化網絡參數,OK! - - 此文件為Xay官方程序所使用的客戶端配置文件,配置為全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081 - Xray官方網站:https://github.com/XTLS/Xray-core - Xray官方程序下載地址:https://github.com/XTLS/Xray-core/releases - 下載相應版本,Windows選擇xray-windows-64.zip或者xray-windows-32.zip,解壓後提取xray.exe。與config.json放在同一目錄,運行xray.exe即可。 - - 此文件為V2Ray官方程序所使用的客戶端配置文件,配置為全局模式,socks5地址:127.0.0.1:1080,http代理地址:127.0.0.1:1081 - v2ray官方網站:https://www.v2ray.com/ - v2ray官方程序下載地址:https://github.com/v2ray/v2ray-core/releases - 下載相應版本,Windows選擇v2ray-windows-64.zip或者v2ray-windows-32.zip,解壓後提取v2ctl.exe和v2ray.exe。與config.json放在同一目錄,運行v2ray.exe即可。 - 此文件為v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)掃碼導入節點 - v2rayN下載網址:https://github.com/2dust/v2rayN/releases - Qv2ray下載網址:https://github.com/Qv2ray/Qv2ray/releases - v2rayNG(Android)下載網址:https://github.com/2dust/v2rayNG/releases - v2rayNG(Android)在Google Play下載網址:https://play.google.com/store/apps/details?id=com.v2ray.ang - Shadowrocket(ios)下載,需要使用國外區的AppleID。請自行谷歌方法。 - 此文件為v2rayN、Qv2ray、v2rayNG(Android)、Shadowrocket(ios)複製粘貼導入節點的vmess網址 - 服務器通用連接配置參數 - - 此文件為Trojan-go官方程序所使用的客戶端配置文件,配置為全局模式,http與socks5地址:127.0.0.1:1080 - Trojan-go官方網站:https://github.com/p4gefau1t/trojan-go - Trojan-go官方程序下載地址:https://github.com/p4gefau1t/trojan-go/releases - 下載相應版本,Windows選擇Trojan-go-x.xx-win.zip,解壓後提取trojan-go.exe。與config.json放在同一目錄,運行trojan-go.exe即可。 - 此文件為Qv2ray (windows)、igniter(Android)掃碼導入節點 - Qv2ray (windows)下載網址:https://github.com/Qv2ray/Qv2ray/releases - igniter(Android)下載網址:https://github.com/trojan-gfw/igniter/releases - Shadowrocket(ios)下載,需要使用國外區的AppleID。請自行谷歌方法。 - 此文件為Qv2ray (windows)、igniter(Android)複製粘貼導入節點的網址 - 服務器通用連接配置參數 - - 此文件為Trojan官方程序所使用的客戶端配置文件,配置為全局模式,http與socks5地址:127.0.0.1:1080 - Trojan官方網站:https://trojan-gfw.github.io/trojan/ - Trojan官方程序下載地址:https://github.com/trojan-gfw/trojan/releases - 下載相應版本,Windows選擇Trojan-x.xx-win.zip,解壓後提取trojan.exe。與config.json放在同一目錄,運行trojan.exe即可。 - 此文件為Qv2ray (windows)、igniter(Android)、Shadowrocket(ios)掃碼導入節點 - Qv2ray (windows)下載網址:https://github.com/Qv2ray/Qv2ray/releases - igniter(Android)下載網址:https://github.com/trojan-gfw/igniter/releases - Shadowrocket(ios)下載,需要使用國外區的AppleID。請自行谷歌方法。 - 此文件為Qv2ray (windows)、igniter(Android)、Shadowrocket(ios)複製粘貼導入節點的網址 - 服務器通用連接配置參數 - - 此文件為NaiveProxy官方程序所使用的客戶端配置文件,配置為全局模式,socks5地址:127.0.0.1:1080 - NaiveProxy官方網站:https://github.com/klzgrad/naiveproxy - NaiveProxy官方程序下載地址:https://github.com/klzgrad/naiveproxy/releases - 下載相應版本,Windows選擇naiveproxy-x.xx-win.zip,解壓後提取naive.exe。與config.json放在同一目錄,運行naive.exe即可。 - 此文件為NaiveSharp(windows)複製粘貼導入節點的網址 - NaiveSharp(windows)下載網址:https://github.com/KevinZonda/NaiveSharp/releases - 服務器通用連接配置參數 - - 此文件為ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)掃碼導入節點 - ShadowsocksR (windows)下載網址:https://github.com/shadowsocksrr/shadowsocksr-csharp/releases - SSRR(Android)下載網址:https://github.com/shadowsocksrr/shadowsocksr-android/releases - Shadowrocket(ios)下載,需要使用國外區的AppleID。請自行谷歌方法。 - 此文件為ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)複製粘貼導入節點的網址 - 服務器通用連接配置參數 - - 此文件為Shadowsocks (windows)掃碼導入節點 - 此文件為Shadowsocks (windows)複製粘貼導入節點的網址 - 此文件為shadowsocks(Android)、Shadowrocket(ios)掃碼導入節點 - Shadowsocks (windows)下載網址:https://github.com/shadowsocks/shadowsocks-windows/releases - shadowsocks(Android)下載網址:https://github.com/shadowsocks/shadowsocks-android/releases - Shadowrocket(ios)下載,需要使用國外區的AppleID。請自行谷歌方法。 - 此文件為shadowsocks(Android)、Shadowrocket(ios)複製粘貼導入節點的網址 - 服務器通用連接配置參數 - 插件使用說明 - ProxySU默認所有插件,在Shadowsocks (windows)運行文件所在文件夾的子文件夾plugins下。 - 電腦端手動安裝插件說明 - 先下載插件,各個插件Windows客戶端下載地址為: - Simple-obfs: https://github.com/shadowsocks/simple-obfs/releases 只下載 obfs-local.zip - V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin/releases 64位系統選擇:v2ray-plugin-windows-amd64-vx.xxtar.gz ,32位系統選擇:v2ray-plugin-windows-386-vx.xxtar.gz (x為數字,是版本號) - Kcptun-plugin: https://github.com/shadowsocks/kcptun/releases 64位系統選擇:kcptun-windows-amd64-xxxxxx.tar.gz,32位系統選擇:kcptun-plugin-windows-386-xxxxxx.tar.gz (x為數字,是版本號) - GoQuiet-plugin: https://github.com/cbeuw/GoQuiet/releases 64位系統選擇:gq-client-windows-amd64-xxxexe,32位系統選擇: gq-client-windows-386-xxxexe(x為數字,是版本號) - Cloak-plugin: https://github.com/cbeuw/Cloak/releases 64位系統選擇:ck-client-windows-amd64-xxxexe,32位系統選擇: ck-client-windows-386-xxxexe(x為數字,是版本號) - 在Shadowsocks (windows)運行文件所在文件夾中,新建文件夾plugins,將obfs-local.zip解壓出的文件(兩個)全部複製到plugins中,v2ray -plugin下載得到的文件,解壓出的文件,複製到plugins中,並重命名為:v2ray-plugin.exe。 Kcptun -plugin下載得到的文件,解壓出兩個文件,將其中的client_windows開頭的文件,複製到plugins中,並重命名為:kcptun-client.exe。 GoQuiet-plugin下載得到的文件,直接複製到plugin中,並重命名為:goquiet-client.exe。 Cloak-plugin下載得到的文件,直接複製到plugin中,並重命名為:cloak-client.exe - 安裝完畢 - 手機安卓客戶端插件安裝說明 - 先下載插件,各個插件安卓客戶端下載地址為: - Simple-obfs: https://github.com/shadowsocks/simple-obfs-android/releases 只下載obfs-local-nightly-xxxapk(x為數字,是版本號) - V2ray-plugin: https://github.com/shadowsocks/v2ray-plugin-android/releases 一般選擇v2ray--universal-xxxapk(x為數字,是版本號) - Kcptun-plugin: https://github.com/shadowsocks/kcptun-android/releases 一般選擇kcptun--universal-xxxapk(x為數字,是版本號) - 將上述apk文件傳到手機,安裝即可! - \ No newline at end of file diff --git a/ProxySU/TrojanGoTemplateWindow.xaml b/ProxySU/TrojanGoTemplateWindow.xaml deleted file mode 100644 index 1c59fa48..00000000 --- a/ProxySU/TrojanGoTemplateWindow.xaml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/TrojanGoTemplateWindow.xaml.cs b/ProxySU/TrojanGoTemplateWindow.xaml.cs deleted file mode 100644 index 59816c7b..00000000 --- a/ProxySU/TrojanGoTemplateWindow.xaml.cs +++ /dev/null @@ -1,194 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace ProxySU -{ - /// - /// TrojanGoTemplateWindow.xaml 的交互逻辑 - /// - public partial class TrojanGoTemplateWindow : Window - { - public TrojanGoTemplateWindow() - { - InitializeComponent(); - RadioButtonTrojanGoTLS2Web.IsChecked = true; - CheckBoxMuxSelect.IsChecked = false; - GridTrojanGoMuxSelected.Visibility = Visibility.Collapsed; - TextBlockExplainCheckBoxMuxSelect.Visibility = Visibility.Collapsed; - } - private void ButtondDecide_Click(object sender, RoutedEventArgs e) - { - bool preDomainMask = ClassModel.PreDomainMask(TextBoxMaskSites.Text); - bool domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //if (string.IsNullOrEmpty(PreTrim(TextBoxDomain.Text)) == true) - //{ - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return; - //} - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - //传递服务端口 - MainWindow.ReceiveConfigurationParameters[1] = "443"; - //传递密码(uuid) - MainWindow.ReceiveConfigurationParameters[2] = PreTrim(TextBoxNewUUID.Text); - if (RadioButtonTrojanGoTLS2Web.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "TrojanGoTLS2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTrojanGoTLS2Web.Content.ToString(); - - } - else if (RadioButtonTrojanGoWebSocketTLS2Web.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "TrojanGoWebSocketTLS2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTrojanGoWebSocketTLS2Web.Content.ToString(); - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - } - //传递Mux的concurrency与idle_timeout - if (CheckBoxMuxSelect.IsChecked == true) - { - MainWindow.ReceiveConfigurationParameters[9] = "true"; - MainWindow.ReceiveConfigurationParameters[3] = PreTrim(TextBoxConcurrency.Text); - MainWindow.ReceiveConfigurationParameters[5] = PreTrim(TextBoxIdle_timeout.Text); - } - if (domainNotEmpty == true && preDomainMask == true) - { - this.Close(); - } - - } - //更新密码 - private void ButtonNewUUID_Click(object sender, RoutedEventArgs e) - { - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - } - //更新路径 - private void ButtonPath_Click(object sender, RoutedEventArgs e) - { - string path = GenerateRandomPath(); - TextBoxPath.Text = $"/{path}"; - //MessageBox.Show(path); - } - //private void ButtonServerListenPort_Click(object sender, RoutedEventArgs e) - //{ - // TextBoxServerListenPort.Text = GetRandomPort(); - //} - private void ButtondCancel_Click(object sender, RoutedEventArgs e) => Close(); - - private void RadioButtonTrojanTLS2Web_Checked(object sender, RoutedEventArgs e) - { - Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = uuid.ToString(); - TextBlockPath.Visibility = Visibility.Collapsed; - TextBoxPath.Visibility = Visibility.Collapsed; - ButtonPath.Visibility = Visibility.Collapsed; - //Random random = new Random(); - //int randomServerPort = random.Next(10000, 50000); - //TextBoxServerListenPort.Text = "443"; - } - private void RadioButtonTrojanGoWebSocketTLS2Web_Checked(object sender, RoutedEventArgs e) - { - Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = uuid.ToString(); - TextBlockPath.Visibility = Visibility.Visible; - TextBoxPath.Visibility = Visibility.Visible; - ButtonPath.Visibility = Visibility.Visible; - TextBoxPath.Text = "/trojan"; - } - - //生成随机UUID - private string GenerateRandomUUID() - { - Guid uuid = Guid.NewGuid(); - return uuid.ToString(); - } - - //生成随机端口 - private int GetRandomPort() - { - Random random = new Random(); - return random.Next(10001, 60000); - } - //生成随机Path - private string GenerateRandomPath() - { - Random random = new Random(); - int randomSerialNum = random.Next(0, 4); - //Guid uuid = Guid.NewGuid(); - string uuid = GenerateRandomUUID(); - string[] pathArray = uuid.Split('-'); - string path = pathArray[randomSerialNum]; - return path; - } - //域名检测是否为空 - //private bool TestDomainIsEmpty() - //{ - // if (string.IsNullOrEmpty(PreTrim(TextBoxDomain.Text)) == true) - // { - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return false; - // } - // else - // { - // return true; - // } - //} - - private void CheckBoxMuxSelect_Checked(object sender, RoutedEventArgs e) - { - GridTrojanGoMuxSelected.Visibility = Visibility.Visible; - TextBlockExplainCheckBoxMuxSelect.Visibility = Visibility.Visible; - } - - private void CheckBoxMuxSelect_Unchecked(object sender, RoutedEventArgs e) - { - GridTrojanGoMuxSelected.Visibility = Visibility.Collapsed; - TextBlockExplainCheckBoxMuxSelect.Visibility = Visibility.Collapsed; - } - - //TextBox输入内容做预处理 - private string PreTrim(string preString) - { - return preString.Trim(); - } - - //处理伪装网站域名中的前缀 - //private string DisguiseURLprocessing(string fakeUrl) - //{ - //var uri = new Uri(fakeUrl); - //return uri.Host; - //if (fakeUrl.Length >= 7) - //{ - // string testDomainMask = fakeUrl.Substring(0, 7); - // if (String.Equals(testDomainMask, "https:/") || String.Equals(testDomainMask, "http://")) - // { - // string[] tmpUrl = fakeUrl.Split('/'); - // fakeUrl = tmpUrl[2]; - // } - - //} - //return fakeUrl; - // } - } -} diff --git a/ProxySU/V2RayTemplateWindow.xaml b/ProxySU/V2RayTemplateWindow.xaml deleted file mode 100644 index a3e05779..00000000 --- a/ProxySU/V2RayTemplateWindow.xaml +++ /dev/null @@ -1,390 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/V2RayTemplateWindow.xaml.cs b/ProxySU/V2RayTemplateWindow.xaml.cs deleted file mode 100644 index 0b171a6e..00000000 --- a/ProxySU/V2RayTemplateWindow.xaml.cs +++ /dev/null @@ -1,1146 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -//using System.Windows.Forms; - -namespace ProxySU -{ - /// - /// WindowTemplateConfiguration.xaml 的交互逻辑 - /// - public partial class WindowTemplateConfiguration : Window - { - //QUIC 加密方法 - public class EncryptionMethodInfo - { - public string Name { get; set; } - public string Value { get; set; } - } - - public WindowTemplateConfiguration() - { - InitializeComponent(); - - #region 加密方法选择 初始设置为chacha20-poly1305 - List methodList = new List(); - - methodList.Add(new EncryptionMethodInfo { Name = "chacha20-poly1305", Value = "chacha20-poly1305" }); - methodList.Add(new EncryptionMethodInfo { Name = "aes-128-gcm", Value = "aes-128-gcm" }); - methodList.Add(new EncryptionMethodInfo { Name = "none", Value = "none" }); - - ComboBoxEncryptionMethodInfo.ItemsSource = methodList; - - ComboBoxEncryptionMethodInfo.DisplayMemberPath = "Name";//显示出来的值 - ComboBoxEncryptionMethodInfo.SelectedValuePath = "Value";//实际选中后获取的结果的值 - ComboBoxEncryptionMethodInfo.SelectedIndex = 0; - - DataContext = this; - #endregion - - //隐藏QUIC密钥 - FirstQuicHideEncryption(); - RadioButtonVMESSmKCP.IsChecked = true; - } - //取消不在当前活动选项卡中的其他所有选项卡中的所有RadioBuuton的选中状态 - //代码参考网址:https://blog.csdn.net/weixin_42583999/article/details/103468857 - //调用:UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - private void UncheckLayouts(TabItem activePage) - { - foreach (TabItem tabPage in TabControlTemplate.Items) - { - if (tabPage == activePage) continue; - Grid grid = (Grid)tabPage.Content; - foreach (UIElement element in grid.Children) - { - if (element is RadioButton) - { - RadioButton radiobutton = (element as RadioButton); - radiobutton.IsChecked = false; - } - - } - } - } - - //传递所选择的参数与模板方案 - private void ButtondDecide_Click(object sender, RoutedEventArgs e) - { - bool preDomainMask = ClassModel.PreDomainMask(TextBoxMaskSites.Text); - bool domainNotEmpty = true; - - #region TCP 传输协议(VMESS) - - //TCP模式被选中 - if (RadioButtonTCP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "TCP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTCP.Content.ToString(); - - } - - //TCP+http伪装模式被选中 - else if (RadioButtonTCPhttp.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "TCPhttp"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTCPhttp.Content.ToString(); - //伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "http"; - - } - - //TCP+TLS模式被选中 - else if (RadioButtonTCP2TLS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "tcpTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTCP2TLS.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - //tcp+TLS(自签证书)模式被选中 - else if (RadioButtonTcpTLS2SelfSigned.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "tcpTLSselfSigned"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTcpTLS2SelfSigned.Content.ToString(); - - //传递域名 - // MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - #endregion - - #region VLESS协议 - - //VLESS+TCP+XTLS+Web模式选中 - else if (RadioButtonVlessXtlsTcp.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessXtlsTcp"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessXtlsTcp.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //VLESS+TCP+TLS+Web模式选中 - else if (RadioButtonVlessTcpTlsWeb.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessTcpTlsWeb"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessTcpTlsWeb.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //VLESS+WebSocket+TLS+Web模式选中 - else if (RadioButtonVlessWebSocketTlsWeb.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessWebSocketTlsWeb"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessWebSocketTlsWeb.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - } - - //VLESS+http2+TLS+Web模式选中 - else if (RadioButtonVlessHttp2Web.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessHttp2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessHttp2Web.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - } - - //VLESS+VMESS+Trojan+XTLS+TCP+WebSocket+Web模式被选中 - else if (RadioButtonVlessVmessXtlsTcpWebSocketHot.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessVmessXtlsTcpWebSocketWeb"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessVmessXtlsTcpWebSocketHot.Content.ToString(); - //传递路径 - MainWindow.ReceiveConfigurationParameters[3] = PreTrim(TextBoxPathVlessWS.Text);//VLESS ws Path - MainWindow.ReceiveConfigurationParameters[9] = PreTrim(TextBoxPathVmessTcp.Text);//VMESS tcp Path - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPathVmessWS.Text);//VMESS ws Path - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递混淆方式(VMESS TCP Path方式所用) - MainWindow.ReceiveConfigurationParameters[5] = "http"; - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - #endregion - - #region WebSocket传输协议(VMESS) - - //webSocket模式被选中 - else if (RadioButtonWebSocket.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "webSocket"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocket.Content.ToString(); - - } - - //WebSocket+TLS模式被选中 - else if (RadioButtonWebSocketTLS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLS.Content.ToString(); - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - //WebSocket+TLS+Web模式被选中 - else if (RadioButtonWebSocketTLS2Web.IsChecked == true|| RadioButtonWebSocketTLS2WebHot.IsChecked==true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLS2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLS2Web.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //WebSocket+TLS(自签证书)模式被选中 - else if (RadioButtonWebSocketTLSselfSigned.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLSselfSigned"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLSselfSigned.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - //MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - #endregion - - #region http2传输协议(VMESS) - - //http2模式被选中 - else if (RadioButtonHTTP2.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "Http2"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonHTTP2.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - //http2+TLS+Web模式被选中 - else if (RadioButtonHTTP2Web.IsChecked == true || RadioButtonHTTP2WebHot.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "http2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonHTTP2Web.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //http2(自签证书)模式被选中 - else if (RadioButtonHTTP2selfSigned.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "http2selfSigned"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonHTTP2selfSigned.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - //MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - #endregion - - #region mKCP 传输协议 (VMESS) - - //mKCP无伪装模式被选中 - else if (RadioButtonMkcpNone.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCPNone"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonMkcpNone.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "none"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) ==false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+srtp伪装模式被选中 - else if (RadioButton2mKCP2SRTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2SRTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2SRTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "srtp"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+utp伪装模式被选中 - else if (RadioButton2mKCPuTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCPuTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCPuTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "utp"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+wechat-video伪装模式被选中 - else if (RadioButton2mKCP2WechatVideo.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2WechatVideo"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2WechatVideo.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wechat-video"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+dtls伪装模式被选中 - else if (RadioButton2mKCP2DTLS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2DTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2DTLS.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "dtls"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+wireguard伪装模式被选中 - else if (RadioButton2mKCP2WireGuard.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2WireGuard"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2WireGuard.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wireguard"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - #endregion - - #region QUIC传输协议(VMESS) - - //QUIC无伪装模式被选中 - else if (RadioButtonQuicNone.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicNone"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicNone.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "none"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+srtp伪装模式被选中 - else if (RadioButtonQuicSRTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicSRTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicSRTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "srtp"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+utp伪装模式被选中 - else if (RadioButtonQuic2uTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "Quic2uTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuic2uTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "utp"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+wechat-video伪装模式被选中 - else if (RadioButtonQuicWechatVideo.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicWechatVideo"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicWechatVideo.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wechat-video"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+dtls伪装模式被选中 - else if (RadioButtonQuicDTLS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicDTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicDTLS.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "dtls"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+wireguard伪装模式被选中 - else if (RadioButtonQuicWireGuard.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicWireGuard"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicWireGuard.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wireguard"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - #endregion - - //传递服务端口 - MainWindow.ReceiveConfigurationParameters[1] = PreTrim(TextBoxServerListenPort.Text); - //传递uuid - MainWindow.ReceiveConfigurationParameters[2] = PreTrim(TextBoxNewUUID.Text); - - if (RadioButtonVLESSmKCP.IsChecked == true) - { - MainWindow.mKCPvlessIsSet = true; - } - else - { - MainWindow.mKCPvlessIsSet = false; - } - - if (domainNotEmpty == true && preDomainMask == true) - { - this.Close(); - } - - } - - //取消选择返回主窗口 - private void ButtondCancel_Click(object sender, RoutedEventArgs e) => Close(); - - - //伪装网站处理 - //DisguiseURLprocessing(string fakeUrl); - // private string DisguiseURLprocessing(string fakeUrl) - //{ - //var uri = new Uri(fakeUrl); - //return uri.Host; - //Console.WriteLine(uri.Host); - - ////处理伪装网站域名中的前缀 - //if (fakeUrl.Length >= 7) - //{ - // string testDomainMask = fakeUrl.Substring(0, 7); - // if (String.Equals(testDomainMask, "https:/") || String.Equals(testDomainMask, "http://")) - // { - // string[] tmpUrl = fakeUrl.Split('/'); - // fakeUrl = tmpUrl[2]; - // } - - //} - - //} - - #region 其他设置中的界面控制 - - private void RadioButtonTCP_Checked(object sender, RoutedEventArgs e) - { - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //Random random = new Random(); - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonTCPhttp_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "80"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonTCP2TLS_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //显示域名 - ShowDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonVlessTcpTlsWeb_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //显示域名 - ShowDomain(); - - //显示伪装网站 - ShowMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonVlessVmessXtlsTcpWebSocketHot_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示复合路径 - ShowVlessVmessMultiplePath(); - - //显示域名 - ShowDomain(); - - //显示伪装网站 - ShowMaskSites(); - - //生成UUID - TextBoxNewUUID.Text = GenerateRandomUUID(); - - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - //单击TextBlockVlessVmessXtlsTcpWebSocket标签则选中RadioButtonVlessVmessXtlsTcpWebSocketHot - private void TextBlockVlessVmessXtlsTcpWebSocket_MouseDown(object sender, MouseButtonEventArgs e) - { - RadioButtonVlessVmessXtlsTcpWebSocketHot.IsChecked = true; - } - private void RadioButtonTCP2TLSnoDomain_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonWebSocketTLS2Web_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示Path - ShowPath(); - - //显示域名 - ShowDomain(); - - //显示伪装网站 - ShowMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonWebSocketTLSselfSigned_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示Path - ShowPath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonHTTP2_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示Path - ShowPath(); - - //显示域名 - ShowDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - //mKCP显示界面 - private void RadioButtonMkcp_Checked(object sender, RoutedEventArgs e) - { - //隐藏QUIC密钥 - HideQuic(); - - //显示mKCP Seed - ShowMkcpSeed(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - - //uuid = Guid.NewGuid(); - TextBoxQuicAndMkcpSeedUUID.Text = GenerateRandomUUID(); - - //Random random = new Random(); - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - //QUIC显示界面 - private void RadioButtonQuicNone_Checked(object sender, RoutedEventArgs e) - { - //隐藏mKCP项 - HideMkcpSeed(); - - //显示QUIC密钥 - ShowQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - - //uuid = Guid.NewGuid(); - TextBoxQuicAndMkcpSeedUUID.Text = GenerateRandomUUID(); - - //Random random = new Random(); - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - - //隐藏QUIC相关项 - private void HideQuic() - { - TextBlockQuicUUID.Visibility = Visibility.Collapsed; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Collapsed; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Collapsed; - TextBlockQuicEncryption.Visibility = Visibility.Collapsed; - ComboBoxEncryptionMethodInfo.Visibility = Visibility.Collapsed; - //TextBlockMkcpUUID.Visibility = Visibility.Collapsed; - } - //如果加密方法选择none,则隐藏只QUIC密钥 - private void NoneEncryptionHideQuicKey() - { - TextBlockQuicUUID.Visibility = Visibility.Collapsed; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Collapsed; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Collapsed; - } - //窗口初始化时,需要做一次隐藏QUIC加密方法 - private void FirstQuicHideEncryption() - { - TextBlockQuicEncryption.Visibility = Visibility.Collapsed; - ComboBoxEncryptionMethodInfo.Visibility = Visibility.Collapsed; - } - //显示QUIC相关项 - private void ShowQuic() - { - TextBlockQuicUUID.Visibility = Visibility.Visible; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Visible; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Visible; - TextBlockQuicEncryption.Visibility = Visibility.Visible; - ComboBoxEncryptionMethodInfo.Visibility = Visibility.Visible; - - //隐藏mKCP相关项 - TextBlockMkcpSeedUUID.Visibility = Visibility.Collapsed; - TextBlockMkcpUUID.Visibility = Visibility.Collapsed; - } - //隐藏mKCP Seed相关项 - private void HideMkcpSeed() - { - TextBlockMkcpSeedUUID.Visibility = Visibility.Collapsed; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Collapsed; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Collapsed; - TextBlockMkcpUUID.Visibility = Visibility.Collapsed; - - } - //显示mKCP Seed相关项 - private void ShowMkcpSeed() - { - TextBlockMkcpSeedUUID.Visibility = Visibility.Visible; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Visible; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Visible; - TextBlockMkcpUUID.Visibility = Visibility.Visible; - //隐藏QUIC标示 - TextBlockQuicUUID.Visibility = Visibility.Collapsed; - } - //隐藏路径相关项 - private void HidePath() - { - //隐藏Path - TextBlockPath.Visibility = Visibility.Collapsed; - TextBoxPath.Visibility = Visibility.Collapsed; - ButtonPath.Visibility = Visibility.Collapsed; - } - //显示路径相关项 - private void ShowPath() - { - HideVlessVmessMultiplePath();//隐藏VLESS VMESS多种方案的路径Path - //显示Path - TextBlockPath.Visibility = Visibility.Visible; - TextBoxPath.Visibility = Visibility.Visible; - TextBoxPath.Text = "/ray"; - ButtonPath.Visibility = Visibility.Visible; - } - //隐藏VLESS VMESS复合方案路径 - private void HideVlessVmessMultiplePath() - { - TextBlockPathVlessWs.Visibility = Visibility.Collapsed; - TextBoxPathVlessWS.Visibility = Visibility.Collapsed; - TextBlockPathVmessTcp.Visibility = Visibility.Collapsed; - TextBoxPathVmessTcp.Visibility = Visibility.Collapsed; - TextBlockPathVmessWs.Visibility = Visibility.Collapsed; - TextBoxPathVmessWS.Visibility = Visibility.Collapsed; - ButtonVlessVmessPath.Visibility = Visibility.Collapsed; - TextBlockTrojanPassword.Visibility = Visibility.Collapsed; - - } - //显示VLESS VMESS复合方案路径 - private void ShowVlessVmessMultiplePath() - { - HidePath();//隐藏普通路径Path - TextBlockPathVlessWs.Visibility = Visibility.Visible; - TextBoxPathVlessWS.Visibility = Visibility.Visible; - TextBoxPathVlessWS.Text = "/vlessws"; - - TextBlockPathVmessTcp.Visibility = Visibility.Visible; - TextBoxPathVmessTcp.Visibility = Visibility.Visible; - TextBoxPathVmessTcp.Text = "/vmesstcp"; - - TextBlockPathVmessWs.Visibility = Visibility.Visible; - TextBoxPathVmessWS.Visibility = Visibility.Visible; - TextBoxPathVmessWS.Text = "/vmessws"; - - ButtonVlessVmessPath.Visibility = Visibility.Visible; - TextBlockTrojanPassword.Visibility = Visibility.Visible; - } - //隐藏域名相关项 - private void HideDomain() - { - //隐藏域名 - TextBlockDomain.Visibility = Visibility.Collapsed; - TextBoxDomain.Visibility = Visibility.Collapsed; - ButtonDomain.Visibility = Visibility.Collapsed; - } - //显示域名相关项 - private void ShowDomain() - { - //显示域名 - TextBlockDomain.Visibility = Visibility.Visible; - TextBoxDomain.Visibility = Visibility.Visible; - //ButtonDomain.Visibility = Visibility.Visible; - } - //隐藏伪装网站 - private void HideMaskSites() - { - TextBlockMaskSites.Visibility = Visibility.Collapsed; - TextBoxMaskSites.Visibility = Visibility.Collapsed; - } - //显示伪装网站 - private void ShowMaskSites() - { - TextBlockMaskSites.Visibility = Visibility.Visible; - TextBoxMaskSites.Visibility = Visibility.Visible; - } - #endregion - - //产生随机的uuid - private void ButtonNewUUID_Click(object sender, RoutedEventArgs e) - { - TextBoxNewUUID.Text = GenerateRandomUUID(); - } - - //产生QUIC密钥/mKCP Seed所用的UUID - private void ButtonQuicAndMkcpSeedUUID_Click(object sender, RoutedEventArgs e) - { - TextBoxQuicAndMkcpSeedUUID.Text = GenerateRandomUUID(); - } - - //更新随机服务端口 - private void ButtonServerListenPort_Click(object sender, RoutedEventArgs e) - { - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - } - - //更新单方案随机的Path - private void ButtonPath_Click(object sender, RoutedEventArgs e) - { - string path = GenerateRandomPath(); - TextBoxPath.Text = $"/{path}"; - } - - //更新多方案共存的Path - private void ButtonVlessVmessPath_Click(object sender, RoutedEventArgs e) - { - string path = GenerateRandomPath(); - TextBoxPathVlessWS.Text = $"/{path}"; - - path = GenerateRandomPath(); - TextBoxPathVmessTcp.Text = $"/{path}"; - - path = GenerateRandomPath(); - TextBoxPathVmessWS.Text = $"/{path}"; - } - //TextBox输入内容做预处理 - private string PreTrim(string preString) - { - return preString.Trim(); - } - //生成随机端口 - private int GetRandomPort() - { - Random random = new Random(); - return random.Next(10001, 60000); - } - - //生成随机UUID - private string GenerateRandomUUID() - { - Guid uuid = Guid.NewGuid(); - return uuid.ToString(); - } - - //生成随机Path - private string GenerateRandomPath() - { - Random random = new Random(); - int randomSerialNum = random.Next(0, 4); - //Guid uuid = Guid.NewGuid(); - string uuid = GenerateRandomUUID(); - string[] pathArray = uuid.Split('-'); - string path = pathArray[randomSerialNum]; - return path; - } - //域名检测是否为空 - //private bool TestDomainIsEmpty() - //{ - // if (string.IsNullOrEmpty(PreTrim(TextBoxDomain.Text)) == true) - // { - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return false; - // } - // else - // { - // return true; - // } - //} - - //加密方法更改后的动作 - private void ComboBoxEncryptionMethodInfo_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - string getMethond = GetEncryptionMethodSS(); - //传递加密方式 - MainWindow.ReceiveConfigurationParameters[3] = getMethond; - if (String.Equals(getMethond,"none")) - { - NoneEncryptionHideQuicKey(); - } - else - { - ShowQuic(); - } - - } - - //读取加密方式 - private string GetEncryptionMethodSS() - { - return ComboBoxEncryptionMethodInfo.SelectedValue.ToString(); - } - private void ButtonDomain_Click(object sender, RoutedEventArgs e) - { - - } - - - - - - - - - - //private void ButtonTestChecked_Click(object sender, RoutedEventArgs e) - //{ - // UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - - //} - } -} diff --git a/ProxySU/XayTemplateWindow.xaml b/ProxySU/XayTemplateWindow.xaml deleted file mode 100644 index 0daad4e6..00000000 --- a/ProxySU/XayTemplateWindow.xaml +++ /dev/null @@ -1,390 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/XayTemplateWindow.xaml.cs b/ProxySU/XayTemplateWindow.xaml.cs deleted file mode 100644 index 10799667..00000000 --- a/ProxySU/XayTemplateWindow.xaml.cs +++ /dev/null @@ -1,1146 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -//using System.Windows.Forms; - -namespace ProxySU -{ - /// - /// WindowTemplateConfiguration.xaml 的交互逻辑 - /// - public partial class XrayWindowTemplateConfiguration : Window - { - //QUIC 加密方法 - public class EncryptionMethodInfo - { - public string Name { get; set; } - public string Value { get; set; } - } - - public XrayWindowTemplateConfiguration() - { - InitializeComponent(); - - #region 加密方法选择 初始设置为chacha20-poly1305 - List methodList = new List(); - - methodList.Add(new EncryptionMethodInfo { Name = "chacha20-poly1305", Value = "chacha20-poly1305" }); - methodList.Add(new EncryptionMethodInfo { Name = "aes-128-gcm", Value = "aes-128-gcm" }); - methodList.Add(new EncryptionMethodInfo { Name = "none", Value = "none" }); - - ComboBoxEncryptionMethodInfo.ItemsSource = methodList; - - ComboBoxEncryptionMethodInfo.DisplayMemberPath = "Name";//显示出来的值 - ComboBoxEncryptionMethodInfo.SelectedValuePath = "Value";//实际选中后获取的结果的值 - ComboBoxEncryptionMethodInfo.SelectedIndex = 0; - - DataContext = this; - #endregion - - //隐藏QUIC密钥 - FirstQuicHideEncryption(); - RadioButtonVMESSmKCP.IsChecked = true; - } - //取消不在当前活动选项卡中的其他所有选项卡中的所有RadioBuuton的选中状态 - //代码参考网址:https://blog.csdn.net/weixin_42583999/article/details/103468857 - //调用:UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - private void UncheckLayouts(TabItem activePage) - { - foreach (TabItem tabPage in TabControlTemplate.Items) - { - if (tabPage == activePage) continue; - Grid grid = (Grid)tabPage.Content; - foreach (UIElement element in grid.Children) - { - if (element is RadioButton) - { - RadioButton radiobutton = (element as RadioButton); - radiobutton.IsChecked = false; - } - - } - } - } - - //传递所选择的参数与模板方案 - private void ButtondDecide_Click(object sender, RoutedEventArgs e) - { - bool preDomainMask = ClassModel.PreDomainMask(TextBoxMaskSites.Text); - bool domainNotEmpty = true; - - #region TCP 传输协议(VMESS) - - //TCP模式被选中 - if (RadioButtonTCP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "TCP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTCP.Content.ToString(); - - } - - //TCP+http伪装模式被选中 - else if (RadioButtonTCPhttp.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "TCPhttp"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTCPhttp.Content.ToString(); - //伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "http"; - - } - - //TCP+TLS模式被选中 - else if (RadioButtonTCP2TLS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "tcpTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTCP2TLS.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - //tcp+TLS(自签证书)模式被选中 - else if (RadioButtonTcpTLS2SelfSigned.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "tcpTLSselfSigned"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonTcpTLS2SelfSigned.Content.ToString(); - - //传递域名 - // MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - #endregion - - #region VLESS协议 - - //VLESS+TCP+XTLS+Web模式选中 - else if (RadioButtonVlessXtlsTcp.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessXtlsTcp"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessXtlsTcp.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //VLESS+TCP+TLS+Web模式选中 - else if (RadioButtonVlessTcpTlsWeb.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessTcpTlsWeb"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessTcpTlsWeb.Content.ToString(); - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //VLESS+WebSocket+TLS+Web模式选中 - else if (RadioButtonVlessWebSocketTlsWeb.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessWebSocketTlsWeb"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessWebSocketTlsWeb.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - } - - //VLESS+http2+TLS+Web模式选中 - else if (RadioButtonVlessHttp2Web.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessHttp2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessHttp2Web.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - } - - //VLESS+VMESS+Trojan+XTLS+TCP+WebSocket+Web模式被选中 - else if (RadioButtonVlessVmessXtlsTcpWebSocketHot.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "VlessVmessXtlsTcpWebSocketWeb"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonVlessVmessXtlsTcpWebSocketHot.Content.ToString(); - //传递路径 - MainWindow.ReceiveConfigurationParameters[3] = PreTrim(TextBoxPathVlessWS.Text);//VLESS ws Path - MainWindow.ReceiveConfigurationParameters[9] = PreTrim(TextBoxPathVmessTcp.Text);//VMESS tcp Path - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPathVmessWS.Text);//VMESS ws Path - - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递混淆方式(VMESS TCP Path方式所用) - MainWindow.ReceiveConfigurationParameters[5] = "http"; - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - #endregion - - #region WebSocket传输协议(VMESS) - - //webSocket模式被选中 - else if (RadioButtonWebSocket.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "webSocket"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocket.Content.ToString(); - - } - - //WebSocket+TLS模式被选中 - else if (RadioButtonWebSocketTLS.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLS.Content.ToString(); - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - //WebSocket+TLS+Web模式被选中 - else if (RadioButtonWebSocketTLS2Web.IsChecked == true|| RadioButtonWebSocketTLS2WebHot.IsChecked==true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLS2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLS2Web.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //WebSocket+TLS(自签证书)模式被选中 - else if (RadioButtonWebSocketTLSselfSigned.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLSselfSigned"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonWebSocketTLSselfSigned.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - //MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - #endregion - - #region http2传输协议(VMESS) - - //http2模式被选中 - else if (RadioButtonHTTP2.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "Http2"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonHTTP2.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - //http2+TLS+Web模式被选中 - else if (RadioButtonHTTP2Web.IsChecked == true || RadioButtonHTTP2WebHot.IsChecked == true) - { - domainNotEmpty = ClassModel.TestDomainIsEmpty(TextBoxDomain.Text); - - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "http2Web"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonHTTP2Web.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - //传递伪装网站 - MainWindow.ReceiveConfigurationParameters[7] = ClassModel.DisguiseURLprocessing(PreTrim(TextBoxMaskSites.Text)); - - } - - //http2(自签证书)模式被选中 - else if (RadioButtonHTTP2selfSigned.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "http2selfSigned"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonHTTP2selfSigned.Content.ToString(); - - //传递路径 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxPath.Text); - //传递域名 - //MainWindow.ReceiveConfigurationParameters[4] = PreTrim(TextBoxDomain.Text); - - } - - #endregion - - #region mKCP 传输协议 (VMESS) - - //mKCP无伪装模式被选中 - else if (RadioButtonMkcpNone.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCPNone"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonMkcpNone.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "none"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) ==false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+srtp伪装模式被选中 - else if (RadioButton2mKCP2SRTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2SRTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2SRTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "srtp"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+utp伪装模式被选中 - else if (RadioButton2mKCPuTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCPuTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCPuTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "utp"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+wechat-video伪装模式被选中 - else if (RadioButton2mKCP2WechatVideo.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2WechatVideo"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2WechatVideo.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wechat-video"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+dtls伪装模式被选中 - else if (RadioButton2mKCP2DTLS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2DTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2DTLS.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "dtls"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - //mKCP+wireguard伪装模式被选中 - else if (RadioButton2mKCP2WireGuard.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "mKCP2WireGuard"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButton2mKCP2WireGuard.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wireguard"; - //传递mKCP Seed - if (String.IsNullOrEmpty(PreTrim(TextBoxQuicAndMkcpSeedUUID.Text)) == false) - { - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - } - } - - #endregion - - #region QUIC传输协议(VMESS) - - //QUIC无伪装模式被选中 - else if (RadioButtonQuicNone.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicNone"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicNone.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "none"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+srtp伪装模式被选中 - else if (RadioButtonQuicSRTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicSRTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicSRTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "srtp"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+utp伪装模式被选中 - else if (RadioButtonQuic2uTP.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "Quic2uTP"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuic2uTP.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "utp"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+wechat-video伪装模式被选中 - else if (RadioButtonQuicWechatVideo.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicWechatVideo"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicWechatVideo.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wechat-video"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+dtls伪装模式被选中 - else if (RadioButtonQuicDTLS.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicDTLS"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicDTLS.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "dtls"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - //QUIC+wireguard伪装模式被选中 - else if (RadioButtonQuicWireGuard.IsChecked == true) - { - //传递模板类型 - MainWindow.ReceiveConfigurationParameters[0] = "QuicWireGuard"; - //传递方案名称 - MainWindow.ReceiveConfigurationParameters[8] = RadioButtonQuicWireGuard.Content.ToString(); - //传递伪装类型 - MainWindow.ReceiveConfigurationParameters[5] = "wireguard"; - //QUIC 密钥 - MainWindow.ReceiveConfigurationParameters[6] = PreTrim(TextBoxQuicAndMkcpSeedUUID.Text); - //QUIC加密方法 - MainWindow.ReceiveConfigurationParameters[3] = GetEncryptionMethodSS(); - } - - #endregion - - //传递服务端口 - MainWindow.ReceiveConfigurationParameters[1] = PreTrim(TextBoxServerListenPort.Text); - //传递uuid - MainWindow.ReceiveConfigurationParameters[2] = PreTrim(TextBoxNewUUID.Text); - - if (RadioButtonVLESSmKCP.IsChecked == true) - { - MainWindow.mKCPvlessIsSet = true; - } - else - { - MainWindow.mKCPvlessIsSet = false; - } - - if (domainNotEmpty == true && preDomainMask == true) - { - this.Close(); - } - - } - - //取消选择返回主窗口 - private void ButtondCancel_Click(object sender, RoutedEventArgs e) => Close(); - - - //伪装网站处理 - //DisguiseURLprocessing(string fakeUrl); - // private string DisguiseURLprocessing(string fakeUrl) - //{ - //var uri = new Uri(fakeUrl); - //return uri.Host; - //Console.WriteLine(uri.Host); - - ////处理伪装网站域名中的前缀 - //if (fakeUrl.Length >= 7) - //{ - // string testDomainMask = fakeUrl.Substring(0, 7); - // if (String.Equals(testDomainMask, "https:/") || String.Equals(testDomainMask, "http://")) - // { - // string[] tmpUrl = fakeUrl.Split('/'); - // fakeUrl = tmpUrl[2]; - // } - - //} - - //} - - #region 其他设置中的界面控制 - - private void RadioButtonTCP_Checked(object sender, RoutedEventArgs e) - { - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //Random random = new Random(); - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonTCPhttp_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "80"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonTCP2TLS_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //显示域名 - ShowDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonVlessTcpTlsWeb_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //显示域名 - ShowDomain(); - - //显示伪装网站 - ShowMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonVlessVmessXtlsTcpWebSocketHot_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示复合路径 - ShowVlessVmessMultiplePath(); - - //显示域名 - ShowDomain(); - - //显示伪装网站 - ShowMaskSites(); - - //生成UUID - TextBoxNewUUID.Text = GenerateRandomUUID(); - - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - //单击TextBlockVlessVmessXtlsTcpWebSocket标签则选中RadioButtonVlessVmessXtlsTcpWebSocketHot - private void TextBlockVlessVmessXtlsTcpWebSocket_MouseDown(object sender, MouseButtonEventArgs e) - { - RadioButtonVlessVmessXtlsTcpWebSocketHot.IsChecked = true; - } - private void RadioButtonTCP2TLSnoDomain_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonWebSocketTLS2Web_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示Path - ShowPath(); - - //显示域名 - ShowDomain(); - - //显示伪装网站 - ShowMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonWebSocketTLSselfSigned_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示Path - ShowPath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - private void RadioButtonHTTP2_Checked(object sender, RoutedEventArgs e) - { - TextBoxServerListenPort.Text = "443"; - - //隐藏mKCP项 - HideMkcpSeed(); - - //隐藏QUIC密钥 - HideQuic(); - - //显示Path - ShowPath(); - - //显示域名 - ShowDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - //mKCP显示界面 - private void RadioButtonMkcp_Checked(object sender, RoutedEventArgs e) - { - //隐藏QUIC密钥 - HideQuic(); - - //显示mKCP Seed - ShowMkcpSeed(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - - //uuid = Guid.NewGuid(); - TextBoxQuicAndMkcpSeedUUID.Text = GenerateRandomUUID(); - - //Random random = new Random(); - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - //QUIC显示界面 - private void RadioButtonQuicNone_Checked(object sender, RoutedEventArgs e) - { - //隐藏mKCP项 - HideMkcpSeed(); - - //显示QUIC密钥 - ShowQuic(); - - //隐藏Path - HidePath(); - HideVlessVmessMultiplePath(); - - //隐藏域名 - HideDomain(); - - //隐藏伪装网站 - HideMaskSites(); - - //Guid uuid = Guid.NewGuid(); - TextBoxNewUUID.Text = GenerateRandomUUID(); - - //uuid = Guid.NewGuid(); - TextBoxQuicAndMkcpSeedUUID.Text = GenerateRandomUUID(); - - //Random random = new Random(); - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - //清除其他选项卡中的选项 - UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - } - - - //隐藏QUIC相关项 - private void HideQuic() - { - TextBlockQuicUUID.Visibility = Visibility.Collapsed; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Collapsed; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Collapsed; - TextBlockQuicEncryption.Visibility = Visibility.Collapsed; - ComboBoxEncryptionMethodInfo.Visibility = Visibility.Collapsed; - //TextBlockMkcpUUID.Visibility = Visibility.Collapsed; - } - //如果加密方法选择none,则隐藏只QUIC密钥 - private void NoneEncryptionHideQuicKey() - { - TextBlockQuicUUID.Visibility = Visibility.Collapsed; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Collapsed; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Collapsed; - } - //窗口初始化时,需要做一次隐藏QUIC加密方法 - private void FirstQuicHideEncryption() - { - TextBlockQuicEncryption.Visibility = Visibility.Collapsed; - ComboBoxEncryptionMethodInfo.Visibility = Visibility.Collapsed; - } - //显示QUIC相关项 - private void ShowQuic() - { - TextBlockQuicUUID.Visibility = Visibility.Visible; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Visible; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Visible; - TextBlockQuicEncryption.Visibility = Visibility.Visible; - ComboBoxEncryptionMethodInfo.Visibility = Visibility.Visible; - - //隐藏mKCP相关项 - TextBlockMkcpSeedUUID.Visibility = Visibility.Collapsed; - TextBlockMkcpUUID.Visibility = Visibility.Collapsed; - } - //隐藏mKCP Seed相关项 - private void HideMkcpSeed() - { - TextBlockMkcpSeedUUID.Visibility = Visibility.Collapsed; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Collapsed; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Collapsed; - TextBlockMkcpUUID.Visibility = Visibility.Collapsed; - - } - //显示mKCP Seed相关项 - private void ShowMkcpSeed() - { - TextBlockMkcpSeedUUID.Visibility = Visibility.Visible; - TextBoxQuicAndMkcpSeedUUID.Visibility = Visibility.Visible; - ButtonQuicAndmKcpSeedUUID.Visibility = Visibility.Visible; - TextBlockMkcpUUID.Visibility = Visibility.Visible; - //隐藏QUIC标示 - TextBlockQuicUUID.Visibility = Visibility.Collapsed; - } - //隐藏路径相关项 - private void HidePath() - { - //隐藏Path - TextBlockPath.Visibility = Visibility.Collapsed; - TextBoxPath.Visibility = Visibility.Collapsed; - ButtonPath.Visibility = Visibility.Collapsed; - } - //显示路径相关项 - private void ShowPath() - { - HideVlessVmessMultiplePath();//隐藏VLESS VMESS多种方案的路径Path - //显示Path - TextBlockPath.Visibility = Visibility.Visible; - TextBoxPath.Visibility = Visibility.Visible; - TextBoxPath.Text = "/ray"; - ButtonPath.Visibility = Visibility.Visible; - } - //隐藏VLESS VMESS复合方案路径 - private void HideVlessVmessMultiplePath() - { - TextBlockPathVlessWs.Visibility = Visibility.Collapsed; - TextBoxPathVlessWS.Visibility = Visibility.Collapsed; - TextBlockPathVmessTcp.Visibility = Visibility.Collapsed; - TextBoxPathVmessTcp.Visibility = Visibility.Collapsed; - TextBlockPathVmessWs.Visibility = Visibility.Collapsed; - TextBoxPathVmessWS.Visibility = Visibility.Collapsed; - ButtonVlessVmessPath.Visibility = Visibility.Collapsed; - TextBlockTrojanPassword.Visibility = Visibility.Collapsed; - - } - //显示VLESS VMESS复合方案路径 - private void ShowVlessVmessMultiplePath() - { - HidePath();//隐藏普通路径Path - TextBlockPathVlessWs.Visibility = Visibility.Visible; - TextBoxPathVlessWS.Visibility = Visibility.Visible; - TextBoxPathVlessWS.Text = "/vlessws"; - - TextBlockPathVmessTcp.Visibility = Visibility.Visible; - TextBoxPathVmessTcp.Visibility = Visibility.Visible; - TextBoxPathVmessTcp.Text = "/vmesstcp"; - - TextBlockPathVmessWs.Visibility = Visibility.Visible; - TextBoxPathVmessWS.Visibility = Visibility.Visible; - TextBoxPathVmessWS.Text = "/vmessws"; - - ButtonVlessVmessPath.Visibility = Visibility.Visible; - TextBlockTrojanPassword.Visibility = Visibility.Visible; - } - //隐藏域名相关项 - private void HideDomain() - { - //隐藏域名 - TextBlockDomain.Visibility = Visibility.Collapsed; - TextBoxDomain.Visibility = Visibility.Collapsed; - ButtonDomain.Visibility = Visibility.Collapsed; - } - //显示域名相关项 - private void ShowDomain() - { - //显示域名 - TextBlockDomain.Visibility = Visibility.Visible; - TextBoxDomain.Visibility = Visibility.Visible; - //ButtonDomain.Visibility = Visibility.Visible; - } - //隐藏伪装网站 - private void HideMaskSites() - { - TextBlockMaskSites.Visibility = Visibility.Collapsed; - TextBoxMaskSites.Visibility = Visibility.Collapsed; - } - //显示伪装网站 - private void ShowMaskSites() - { - TextBlockMaskSites.Visibility = Visibility.Visible; - TextBoxMaskSites.Visibility = Visibility.Visible; - } - #endregion - - //产生随机的uuid - private void ButtonNewUUID_Click(object sender, RoutedEventArgs e) - { - TextBoxNewUUID.Text = GenerateRandomUUID(); - } - - //产生QUIC密钥/mKCP Seed所用的UUID - private void ButtonQuicAndMkcpSeedUUID_Click(object sender, RoutedEventArgs e) - { - TextBoxQuicAndMkcpSeedUUID.Text = GenerateRandomUUID(); - } - - //更新随机服务端口 - private void ButtonServerListenPort_Click(object sender, RoutedEventArgs e) - { - int randomServerPort = GetRandomPort(); - TextBoxServerListenPort.Text = randomServerPort.ToString(); - } - - //更新单方案随机的Path - private void ButtonPath_Click(object sender, RoutedEventArgs e) - { - string path = GenerateRandomPath(); - TextBoxPath.Text = $"/{path}"; - } - - //更新多方案共存的Path - private void ButtonVlessVmessPath_Click(object sender, RoutedEventArgs e) - { - string path = GenerateRandomPath(); - TextBoxPathVlessWS.Text = $"/{path}"; - - path = GenerateRandomPath(); - TextBoxPathVmessTcp.Text = $"/{path}"; - - path = GenerateRandomPath(); - TextBoxPathVmessWS.Text = $"/{path}"; - } - //TextBox输入内容做预处理 - private string PreTrim(string preString) - { - return preString.Trim(); - } - //生成随机端口 - private int GetRandomPort() - { - Random random = new Random(); - return random.Next(10001, 60000); - } - - //生成随机UUID - private string GenerateRandomUUID() - { - Guid uuid = Guid.NewGuid(); - return uuid.ToString(); - } - - //生成随机Path - private string GenerateRandomPath() - { - Random random = new Random(); - int randomSerialNum = random.Next(0, 4); - //Guid uuid = Guid.NewGuid(); - string uuid = GenerateRandomUUID(); - string[] pathArray = uuid.Split('-'); - string path = pathArray[randomSerialNum]; - return path; - } - //域名检测是否为空 - //private bool TestDomainIsEmpty() - //{ - // if (string.IsNullOrEmpty(PreTrim(TextBoxDomain.Text)) == true) - // { - // //****** "域名不能为空,请检查相关参数设置!" ****** - // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); - // return false; - // } - // else - // { - // return true; - // } - //} - - //加密方法更改后的动作 - private void ComboBoxEncryptionMethodInfo_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - string getMethond = GetEncryptionMethodSS(); - //传递加密方式 - MainWindow.ReceiveConfigurationParameters[3] = getMethond; - if (String.Equals(getMethond,"none")) - { - NoneEncryptionHideQuicKey(); - } - else - { - ShowQuic(); - } - - } - - //读取加密方式 - private string GetEncryptionMethodSS() - { - return ComboBoxEncryptionMethodInfo.SelectedValue.ToString(); - } - private void ButtonDomain_Click(object sender, RoutedEventArgs e) - { - - } - - - - - - - - - - //private void ButtonTestChecked_Click(object sender, RoutedEventArgs e) - //{ - // UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); - - //} - } -} diff --git a/ProxySU/bin/Beta/Beta.zip b/ProxySU/bin/Beta/Beta.zip deleted file mode 100644 index 500116a7..00000000 Binary files a/ProxySU/bin/Beta/Beta.zip and /dev/null differ diff --git a/ProxySuper.Core/App.cs b/ProxySuper.Core/App.cs new file mode 100644 index 00000000..919fd052 --- /dev/null +++ b/ProxySuper.Core/App.cs @@ -0,0 +1,13 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.ViewModels; + +namespace ProxySuper.Core +{ + public class App : MvxApplication + { + public override void Initialize() + { + RegisterAppStart(); + } + } +} diff --git a/ProxySuper.Core/Converters/LoginSecretTypeConverter.cs b/ProxySuper.Core/Converters/LoginSecretTypeConverter.cs new file mode 100644 index 00000000..56cd8752 --- /dev/null +++ b/ProxySuper.Core/Converters/LoginSecretTypeConverter.cs @@ -0,0 +1,22 @@ +using ProxySuper.Core.Models.Hosts; +using System; +using System.Globalization; +using System.Windows.Data; + +namespace ProxySuper.Core.Converters +{ + public class LoginSecretTypeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value.Equals(parameter); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (parameter == null) return LoginSecretType.Password; + return parameter; + } + + } +} diff --git a/ProxySuper.Core/Converters/ProxyTypeConverter.cs b/ProxySuper.Core/Converters/ProxyTypeConverter.cs new file mode 100644 index 00000000..92ba31ed --- /dev/null +++ b/ProxySuper.Core/Converters/ProxyTypeConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Windows; +using System.Windows.Data; + +namespace ProxySuper.Core.Converters +{ + public class ProxyTypeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value != null && value.Equals(parameter); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + { + return Binding.DoNothing; + } + + if (!value.Equals(true)) + { + return Binding.DoNothing; + } + + return parameter; + } + } + + public class BooleanOrConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + return values.OfType().Any(v => v); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + +} diff --git a/ProxySuper.Core/Converters/VisibleConverter.cs b/ProxySuper.Core/Converters/VisibleConverter.cs new file mode 100644 index 00000000..1379bb46 --- /dev/null +++ b/ProxySuper.Core/Converters/VisibleConverter.cs @@ -0,0 +1,66 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace ProxySuper.Core.Converters +{ + public class VisibleConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value.Equals(true) ? Visibility.Visible : Visibility.Collapsed;//Hidden;//Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + { + return false; + } + + if (value.Equals(Visibility.Visible)) + { + return true; + } + + return false; + } + } + + public class VisibleConverter2 : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + bool isMatch = (value != null && value.Equals(parameter)); + // 如果匹配则显示,否则隐藏(Collapsed) + return isMatch ? Visibility.Visible : Visibility.Collapsed;//Hidden;//Collapsed; + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + public class BooleanOrToVisibilityConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + // 如果任一条件为 true,则返回 Visible,否则返回 Hidden/Collapsed + foreach (var value in values) + { + if (value is bool boolVal && boolVal) + { + return Visibility.Visible; + } + } + return Visibility.Collapsed;//Hidden;//Collapsed + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/ProxySuper.Core/Converters/YamlJsonConverter.cs b/ProxySuper.Core/Converters/YamlJsonConverter.cs new file mode 100644 index 00000000..ca56c156 --- /dev/null +++ b/ProxySuper.Core/Converters/YamlJsonConverter.cs @@ -0,0 +1,205 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.IO; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace ProxySuper.Core.Converters +{ + public class YamlJsonConverter + { + private readonly IDeserializer _yamlDeserializer; + private readonly ISerializer _yamlSerializer; + + public YamlJsonConverter() + { + _yamlDeserializer = new DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + + _yamlSerializer = new SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .DisableAliases() + .WithIndentedSequences() + .Build(); + } + + /// + /// YAML 字符串转 JSON 字符串 + /// + public string YamlToJson(string yaml, bool indentJson = true) + { + var obj = _yamlDeserializer.Deserialize(yaml); + var formatting = indentJson ? Formatting.Indented : Formatting.None; + return JsonConvert.SerializeObject(obj, formatting); + } + + /// + /// JSON 字符串转 YAML 字符串 + /// + public string JsonToYaml(string json) + { + var obj = JsonConvert.DeserializeObject(json); + return _yamlSerializer.Serialize(obj); + } + } + + public class JsonYamlConverters + { + /// + /// 将JSON字符串转换为YAML字符串。 + /// + /// 要转换的JSON字符串。 + /// 转换后的YAML字符串。 + /// 如果jsonString为空或null。 + /// 如果JSON字符串无效。 + public static string JsonToYaml(string jsonString) + { + if (string.IsNullOrWhiteSpace(jsonString)) + { + throw new ArgumentNullException(nameof(jsonString), "JSON字符串不能为空或null。"); + } + + // 使用自定义转换器将JSON反序列化为ExpandoObject + // ExpandoObject 实现了 IDictionary,这通常更受 YamlDotNet 欢迎 + var settings = new JsonSerializerSettings + { + Converters = { new ExpandoObjectConverter() } + }; + ExpandoObject expandoObject = JsonConvert.DeserializeObject(jsonString, settings); + + + // 创建一个序列化器将对象转换为YAML + var serializer = new SerializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) // 可选:设置命名约定 + .Build(); + + // 将对象序列化为YAML字符串 + return serializer.Serialize(expandoObject); + } + + /// + /// 将YAML字符串转换为JSON字符串。 + /// + /// 要转换的YAML字符串。 + /// 转换后的JSON字符串。 + /// 如果yamlString为空或null。 + /// 如果YAML字符串无效。 + public static string YamlToJson(string yamlString) + { + if (string.IsNullOrWhiteSpace(yamlString)) + { + throw new ArgumentNullException(nameof(yamlString), "YAML字符串不能为空或null。"); + } + + // 创建一个反序列化器将YAML转换为对象 + var deserializer = new DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) // 可选:设置命名约定 + .Build(); + + // 将YAML字符串反序列化为动态对象或JObject + // 使用object可以适应各种YAML结构 + object yamlObject = deserializer.Deserialize(new StringReader(yamlString)); + + // 将对象序列化为美化(格式化)的JSON字符串 + return JsonConvert.SerializeObject(yamlObject, Formatting.Indented); + } + } + + public class ExpandoObjectConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(ExpandoObject); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return ReadValue(reader); + } + + private object ReadValue(JsonReader reader) + { + switch (reader.TokenType) + { + case JsonToken.StartObject: + var expando = new ExpandoObject() as IDictionary; + while (reader.Read()) + { + switch (reader.TokenType) + { + case JsonToken.PropertyName: + var propertyName = reader.Value.ToString(); + reader.Read(); + expando[propertyName] = ReadValue(reader); + break; + case JsonToken.EndObject: + return expando; + } + } + break; + case JsonToken.StartArray: + var list = new List(); + while (reader.Read()) + { + switch (reader.TokenType) + { + case JsonToken.EndArray: + return list; + case JsonToken.Comment: // Skip comments + break; + default: + list.Add(ReadValue(reader)); + break; + } + } + break; + case JsonToken.Integer: + case JsonToken.Float: + case JsonToken.String: + case JsonToken.Boolean: + case JsonToken.Date: + case JsonToken.Bytes: + return reader.Value; + case JsonToken.Null: + return null; + } + return null; // Should not happen with valid JSON + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + // ExpandoObject 实际上会由 JsonSerializer 自行处理, + // 但为了完整性,我们也可以在此处实现更严格的转换 + if (value is IDictionary dictionary) + { + writer.WriteStartObject(); + foreach (var kvp in dictionary) + { + writer.WritePropertyName(kvp.Key); + serializer.Serialize(writer, kvp.Value); + } + writer.WriteEndObject(); + } + else if (value is IEnumerable enumerable) + { + writer.WriteStartArray(); + foreach (var item in enumerable) + { + serializer.Serialize(writer, item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteValue(value); + } + } + } + + + +} diff --git a/ProxySuper.Core/Helpers/DateTimeUtils.cs b/ProxySuper.Core/Helpers/DateTimeUtils.cs new file mode 100644 index 00000000..4625b81a --- /dev/null +++ b/ProxySuper.Core/Helpers/DateTimeUtils.cs @@ -0,0 +1,82 @@ + +using System; +using System.Globalization; +using System.Net; +using System.Runtime.InteropServices; + +namespace ProxySuper.Core.Helpers +{ + public static class DateTimeUtils + { + /// + /// 从国家授时中心获取标准GMT时间,读取https://www.tsa.cn + /// GMT时间与UTC时间没有差别,可以UTC=GMT + /// + /// 返回网络时间 + public static DateTime GetUTCTime() + { + DateTime time; + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.tsa.cn"); + request.Method = "HEAD"; + request.AllowAutoRedirect = false; + HttpWebResponse reponse = (HttpWebResponse)request.GetResponse(); + string cc = reponse.GetResponseHeader("date"); + reponse.Close(); + + bool s = GMTStrParse(cc, out time); + return time; + } + catch + { + return new DateTime(1970, 1, 1, 0, 0, 0, 0); + } + } + + public static bool GMTStrParse(string gmtStr, out DateTime gmtTime) //抓取的date是GMT格式的字符串,这里转成datetime + { + CultureInfo enUS = new CultureInfo("en-US"); + bool s = DateTime.TryParseExact(gmtStr, "r", enUS, DateTimeStyles.None, out gmtTime); + return s; + } + + //设置系统时间的API函数 + [DllImport("kernel32.dll")] + private static extern bool SetLocalTime(ref SYSTEMTIME time); + + [StructLayout(LayoutKind.Sequential)] + private struct SYSTEMTIME + { + public short year; + public short month; + public short dayOfWeek; + public short day; + public short hour; + public short minute; + public short second; + public short milliseconds; + } + + /// + /// 设置系统时间 + /// + /// 需要设置的时间 + /// 返回系统时间设置状态,true为成功,false为失败 + public static bool SetDate(DateTime dt) + { + SYSTEMTIME st; + + st.year = (short)dt.Year; + st.month = (short)dt.Month; + st.dayOfWeek = (short)dt.DayOfWeek; + st.day = (short)dt.Day; + st.hour = (short)dt.Hour; + st.minute = (short)dt.Minute; + st.second = (short)dt.Second; + st.milliseconds = (short)dt.Millisecond; + bool rt = SetLocalTime(ref st); + return rt; + } + } +} diff --git a/ProxySuper.Core/Helpers/Utils.cs b/ProxySuper.Core/Helpers/Utils.cs new file mode 100644 index 00000000..76e41b19 --- /dev/null +++ b/ProxySuper.Core/Helpers/Utils.cs @@ -0,0 +1,40 @@ +using Newtonsoft.Json; +using System; +using System.Linq; + +namespace ProxySuper.Core.Services +{ + public class Utils + { + public static string Base64Encode(string plainText) + { + var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); + return System.Convert.ToBase64String(plainTextBytes); + } + + public static string Base64Decode(string base64EncodedData) + { + var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); + return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); + } + + public static T DeepClone(T obj) where T : class + { + var serialized = JsonConvert.SerializeObject(obj); + return JsonConvert.DeserializeObject(serialized); + } + + public static string GetTickID() + { + return DateTime.Now.Ticks.ToString(); + } + + private static Random random = new Random(); + public static string RandomString(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + return new string(Enumerable.Repeat(chars, length) + .Select(s => s[random.Next(s.Length)]).ToArray()); + } + } +} diff --git a/ProxySuper.Core/Helpers/X25519KeyPair.cs b/ProxySuper.Core/Helpers/X25519KeyPair.cs new file mode 100644 index 00000000..590e2f8b --- /dev/null +++ b/ProxySuper.Core/Helpers/X25519KeyPair.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Security.Cryptography; +using Chaos.NaCl; + +namespace ProxySuper.Core.Helpers +{ + public class X25519KeyPair + { + public byte[] _PrivateKey { get; private set; } // 32 bytes + public byte[] _PublicKey { get; private set; } // 32 bytes + + public X25519KeyPair() + { + _PrivateKey = new byte[32]; + using (var rng = RandomNumberGenerator.Create()) + { + rng.GetBytes(_PrivateKey); + } + _PublicKey = MontgomeryCurve25519.GetPublicKey(_PrivateKey); + } + + public X25519KeyPair(byte[] privateKey) + { + if (privateKey == null || privateKey.Length != 32) + throw new ArgumentException("Private key must be 32 bytes."); + + _PrivateKey = privateKey; + _PublicKey = MontgomeryCurve25519.GetPublicKey(_PrivateKey); + } + + public static string Base64UrlEncode(byte[] data) + { + string base64 = Convert.ToBase64String(data); // 标准Base64 + base64 = base64.TrimEnd('='); // 去掉末尾的 '=' + base64 = base64.Replace('+', '-'); // '+' 替换成 '-' + base64 = base64.Replace('/', '_'); // '/' 替换成 '_' + return base64; + } + + public string PrivateKey + { + get { return Base64UrlEncode(_PrivateKey); } + } + + public string PublicKey + { + get { return Base64UrlEncode(_PublicKey); } + } + + } +} diff --git a/ProxySuper.Core/Helpers/YamlConfigMerger.cs b/ProxySuper.Core/Helpers/YamlConfigMerger.cs new file mode 100644 index 00000000..34c5a65c --- /dev/null +++ b/ProxySuper.Core/Helpers/YamlConfigMerger.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace ProxySuper.Core.Helpers +{ + /// + /// 提供静态方法来合并两个 YAML 字符串。 + /// 它将第二个 YAML 字符串的内容合并到第一个 YAML 字符串中, + /// 遵循深度合并字典和追加列表的策略。 + /// + public static class YamlConfigMerger + { + /// + /// 合并两个 YAML 字符串。 + /// 当键冲突时,第二个 YAML 字符串的值会覆盖第一个字符串的值。 + /// 对于列表,它会尝试进行追加合并。 + /// + /// 第一个 YAML 字符串(作为基础配置)。 + /// 第二个 YAML 字符串(其内容将合并到第一个字符串中)。 + /// 用于 YAML 序列化/反序列化的命名约定。默认为 CamelCaseNamingConvention。 + /// 合并后的 YAML 字符串。 + public static string MergeYamlStrings(string yamlString1, string yamlString2, INamingConvention namingConvention = null) + { + // 默认使用 CamelCaseNamingConvention + namingConvention = namingConvention ?? CamelCaseNamingConvention.Instance; + + var deserializer = new DeserializerBuilder() + .WithNamingConvention(namingConvention) + .Build(); + + var serializer = new SerializerBuilder() + .WithNamingConvention(namingConvention) + .Build(); + + // 1. 反序列化两个 YAML 字符串为内部字典表示 + IDictionary data1 = DeserializeYaml(yamlString1, deserializer); + IDictionary data2 = DeserializeYaml(yamlString2, deserializer); + + // 2. 合并两个字典 + IDictionary mergedData = MergeDictionaries(data1, data2); + + // 3. 序列化合并后的数据回 YAML 字符串 + return serializer.Serialize(mergedData); + } + + /// + /// 私有方法:将 YAML 字符串反序列化为 IDictionary。 + /// + /// 要反序列化的 YAML 字符串。 + /// 用于反序列化的 YamlDotNet Deserializer 实例。 + /// 表示 YAML 数据的字典。 + private static IDictionary DeserializeYaml(string yamlString, IDeserializer deserializer) + { + if (string.IsNullOrWhiteSpace(yamlString)) + { + return new Dictionary(); + } + try + { + var data = deserializer.Deserialize>(yamlString); + return data ?? new Dictionary(); // 如果反序列化结果为 null,则返回空字典 + } + catch (YamlDotNet.Core.YamlException ex) + { + // 可以在此处添加更详细的日志记录 + throw new ArgumentException($"Invalid YAML string provided: {ex.Message}", nameof(yamlString), ex); + } + } + + /// + /// 内部递归合并字典的方法。 + /// sourceDict 将会被 targetDict 中的内容更新或覆盖。 + /// 对于列表,它会尝试进行追加。 + /// + private static IDictionary MergeDictionaries(IDictionary sourceDict, IDictionary targetDict) + { + if (sourceDict == null && targetDict == null) + { + return new Dictionary(); + } + if (sourceDict == null) + { + return new Dictionary(targetDict); + } + if (targetDict == null) + { + return new Dictionary(sourceDict); + } + + var result = new Dictionary(sourceDict); // 创建 sourceDict 的一个副本 + + foreach (var kvp in targetDict) + { + var key = kvp.Key; + var targetValue = kvp.Value; + + if (result.ContainsKey(key)) + { + var sourceValue = result[key]; + + if (sourceValue is IDictionary sourceSubDict && + targetValue is IDictionary targetSubDict) + { + // 递归合并嵌套的字典 + result[key] = MergeDictionaries(sourceSubDict, targetSubDict); + } + else if (sourceValue is IList sourceList && + targetValue is IList targetList) + { + // 对于列表,简单地追加。 + // 实际应用中,你可能需要更复杂的列表合并逻辑(例如按 ID 更新、去重等)。 + var mergedList = new List(sourceList); + mergedList.AddRange(targetList); + result[key] = mergedList; + } + else + { + // 覆盖非字典/非列表的值 + result[key] = targetValue; + } + } + else + { + // targetDict 中有而 sourceDict 中没有的键,直接添加 + result[key] = targetValue; + } + } + return result; + } + } +} diff --git a/ProxySuper.Core/Models/Caddy.cs b/ProxySuper.Core/Models/Caddy.cs new file mode 100644 index 00000000..93e3c22c --- /dev/null +++ b/ProxySuper.Core/Models/Caddy.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Models +{ + public static class Caddy + { + public static string Service = @" +[Unit] +Description=Caddy +Documentation=https://caddyserver.com/docs/ +After=network.target network-online.target +Requires=network-online.target + +[Service] +#User=caddy +#Group=caddy +User=root +Group=root +ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile +ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile +TimeoutStopSec=5s +#LimitNOFILE=1048576 +#LimitNPROC=512 +PrivateTmp=true +ProtectSystem=full +#AmbientCapabilities=CAP_NET_BIND_SERVICE + +[Install] +WantedBy=multi-user.target +"; + + public static string DefaultCaddyFile = @" +:80 { + respond ""Hello world!""; +} +"; + } +} diff --git a/ProxySuper.Core/Models/Hosts/Host.cs b/ProxySuper.Core/Models/Hosts/Host.cs new file mode 100644 index 00000000..f6fb043b --- /dev/null +++ b/ProxySuper.Core/Models/Hosts/Host.cs @@ -0,0 +1,80 @@ +using Microsoft.Win32; +using MvvmCross.Commands; +using Newtonsoft.Json; +using System.ComponentModel; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Models.Hosts +{ + public class Host + { + + public Host() + { + Proxy = new LocalProxy(); + } + + + public string Tag { get; set; } + + public string Address { get; set; } + + public int Port { get; set; } = 22; + + public string UserName { get; set; } + + public string Password { get; set; } + + public string PrivateKeyPath { get; set; } + + public string PrivateKeyPassPhrase { get; set; } + + public LocalProxy Proxy { get; set; } + + public LoginSecretType SecretType { get; set; } + + //public IMvxCommand UploadPrivateKeyCommand => new MvxCommand(UploadPrivateKey); + + private readonly IMvxCommand _uploadPrivateKeyCommand; + public IMvxCommand UploadPrivateKeyCommand => _uploadPrivateKeyCommand ?? new MvxCommand(UploadPrivateKey); + + private void UploadPrivateKey() + { + var fileDialog = new OpenFileDialog() + { + Filter = "Private Key (*.pem;*.key)|*.pem;*.key|All File (*.*)|*.*", + Title = "Select the private key file" + }; + fileDialog.FileOk += OnFileOk; + fileDialog.ShowDialog(); + } + + private async void OnFileOk(object sender, CancelEventArgs e) + { + var file = sender as OpenFileDialog; + if (file != null) + { + PrivateKeyPath = file.FileName; + + //Task.Delay(300).ContinueWith((t) => + //{ + // MessageBox.Show("OK:" + PrivateKeyPath, "Tips"); + //}); + + await Task.Delay(300); + MessageBox.Show("OK:" + PrivateKeyPath, "Tips"); + } + else + { + //Task.Delay(300).ContinueWith((t) => + //{ + // MessageBox.Show("Error:Unable to get file!", "Tips"); + //}); + + await Task.Delay(300); + MessageBox.Show("Error:Unable to get file!", "Tips"); + } + } + } +} diff --git a/ProxySuper.Core/Models/Hosts/LocalProxy.cs b/ProxySuper.Core/Models/Hosts/LocalProxy.cs new file mode 100644 index 00000000..c382bbe2 --- /dev/null +++ b/ProxySuper.Core/Models/Hosts/LocalProxy.cs @@ -0,0 +1,20 @@ +using Renci.SshNet; + +namespace ProxySuper.Core.Models.Hosts +{ + public class LocalProxy + { + public string Address { get; set; } = "127.0.0.1"; + + public int Port { get; set; } = 1080; + + public ProxyTypes Type { get; set; } + + public string UserName { get; set; } + + public string Password { get; set; } + + } + + +} diff --git a/ProxySuper.Core/Models/Hosts/LoginSecretType.cs b/ProxySuper.Core/Models/Hosts/LoginSecretType.cs new file mode 100644 index 00000000..8ba540a1 --- /dev/null +++ b/ProxySuper.Core/Models/Hosts/LoginSecretType.cs @@ -0,0 +1,8 @@ +namespace ProxySuper.Core.Models.Hosts +{ + public enum LoginSecretType + { + Password = 0, + PrivateKey = 1 + } +} diff --git a/ProxySuper.Core/Models/ProjectProgress.cs b/ProxySuper.Core/Models/ProjectProgress.cs new file mode 100644 index 00000000..dad33a35 --- /dev/null +++ b/ProxySuper.Core/Models/ProjectProgress.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Models +{ + public class ProjectProgress + { + private string _step; + + private string _desc; + + private int _percentage; + + private string _logs; + + public ProjectProgress() + { + _step = "步骤"; + + _desc = "步骤描述"; + + _percentage = 0; + + _logs = string.Empty; + + StepUpdate = () => { }; + } + + + public Action StepUpdate { get; set; } + + public Action LogsUpdate { get; set; } + + public string Desc + { + get { return _desc; } + set + { + _desc = value; + StepUpdate(); + + _logs += _desc + "\n"; + LogsUpdate(); + } + } + + public string Step + { + get { return _step; } + set + { + _step = value; + StepUpdate(); + + _logs += Step + "\n"; + LogsUpdate(); + } + } + + public int Percentage + { + get { return _percentage; } + set + { + _percentage = value; + StepUpdate(); + } + } + + public string Logs + { + get { return _logs; } + set + { + _logs = value; + LogsUpdate(); + } + } + } +} \ No newline at end of file diff --git a/ProxySuper.Core/Models/Projects/BrookSettings.cs b/ProxySuper.Core/Models/Projects/BrookSettings.cs new file mode 100644 index 00000000..7bf1adb5 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/BrookSettings.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace ProxySuper.Core.Models.Projects +{ + public class BrookSettings : IProjectSettings + { + public string Domain { get; set; } + + public string IP { get; set; } + + public string Password { get; set; } + + public BrookType BrookType { get; set; } + + public int Port { get; set; } = 443; + + public List FreePorts + { + get + { + if (Port == 443) + { + return new List { 80, 443 }; + } + return new List { Port }; + } + } + + public string Email => "server@brook.com"; + + public ProjectType Type { get; set; } = ProjectType.Brook; + + } +} diff --git a/ProxySuper.Core/Models/Projects/BrookType.cs b/ProxySuper.Core/Models/Projects/BrookType.cs new file mode 100644 index 00000000..6f5fc1d7 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/BrookType.cs @@ -0,0 +1,10 @@ +namespace ProxySuper.Core.Models.Projects +{ + public enum BrookType + { + server, + wsserver, + wssserver, + socks5 + } +} diff --git a/ProxySuper.Core/Models/Projects/HysteriaSettings.cs b/ProxySuper.Core/Models/Projects/HysteriaSettings.cs new file mode 100644 index 00000000..bca8d310 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/HysteriaSettings.cs @@ -0,0 +1,75 @@ +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static QRCoder.PayloadGenerator; + +namespace ProxySuper.Core.Models.Projects +{ + public class HysteriaSettings : IProjectSettings + { + public HysteriaSettings() + { + Password = Guid.NewGuid().ToString(); + + Email = GetEmailRandom(); + + ObfsPassword = Guid.NewGuid().ToString(); + } + public string Domain { get; set; } = ""; + + public int Port { get; set; } = 443; + + public string Password { get; set; } = ""; + + public bool AutoACME { get; set; } = true; + + public string Email { get; set; } = ""; + + public bool EnableObfs { get; set; } = false; + public string ObfsPassword { get; set; } = ""; + + public int UpMbps { get; set; } = 0; + + public int DownMbps { get; set; } = 0; + + public bool BBRenable { get; set; } = false; + + public string MaskDomain { get; set; } = ""; + + public bool EnableUpDisguisedWeb { get; set; } = false; + + public string HysteriaShareLink + { + get + { + return ShareLink.BuildHysteria(this); + } + } + public List FreePorts + { + get + { + return new List { Port, 80 }; + } + } + + public string GetEmailRandom() + { + if (!string.IsNullOrEmpty(Domain)) + { + var arr = Domain.Split('.'); + if (arr.Length == 3) + { + return $"{arr[0]}@{arr[1]}.{arr[2]}"; + } + } + + return $"{Guid.NewGuid().ToString().Substring(2, 6)}@gmail.com"; + } + + public string ClientHysteria2Config { get; set; } + } +} diff --git a/ProxySuper.Core/Models/Projects/IProjectSettings.cs b/ProxySuper.Core/Models/Projects/IProjectSettings.cs new file mode 100644 index 00000000..aa5eb9d3 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/IProjectSettings.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace ProxySuper.Core.Models.Projects +{ + public interface IProjectSettings + { + /// + /// 端口 + /// + int Port { get; set; } + + /// + /// 域名 + /// + string Domain { get; set; } + + /// + /// 额外需要开放的端口 + /// + List FreePorts { get; } + + /// + /// 类型 + /// + //ProjectType Type { get; set; } + + /// + /// 邮箱 + /// + string Email { get; } + } +} diff --git a/ProxySuper.Core/Models/Projects/MTProtoGoSettings.cs b/ProxySuper.Core/Models/Projects/MTProtoGoSettings.cs new file mode 100644 index 00000000..26cfabd4 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/MTProtoGoSettings.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Models.Projects +{ + public class MTProtoGoSettings : IProjectSettings + { + public MTProtoGoSettings() + { + Port = 443; + + Domain = string.Empty; + + Cleartext = "bing.com"; + + SecretText = string.Empty; + } + + public int Port { get; set; } + + public string Domain { get; set; } + + public List FreePorts => new List { Port }; + + public string Email => ""; + + public string Cleartext { get; set; } + + public string SecretText { get; set; } + } +} diff --git a/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs b/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs new file mode 100644 index 00000000..f6c457f2 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; + +namespace ProxySuper.Core.Models.Projects +{ + public class NaiveProxySettings : IProjectSettings + { + public NaiveProxySettings() + { + Port = 443; + } + + public List FreePorts + { + get + { + return new List { 80, 443, Port }.Distinct().ToList(); + } + } + + public ProjectType Type { get; set; } = ProjectType.NaiveProxy; + + public int Port { get; set; } + + public string Domain { get; set; } + + public string UserName { get; set; } + + public string Password { get; set; } + + public string MaskDomain { get; set; } + + [JsonIgnore] + public string Email + { + get + { + if (!string.IsNullOrEmpty(Domain)) + { + var arr = Domain.Split('.'); + if (arr.Length == 3) + { + return $"{arr[0]}@{arr[1]}.{arr[2]}"; + } + } + + + return $"{UserName + Port.ToString()}@gmail.com"; + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/ProjectType.cs b/ProxySuper.Core/Models/Projects/ProjectType.cs new file mode 100644 index 00000000..93767fac --- /dev/null +++ b/ProxySuper.Core/Models/Projects/ProjectType.cs @@ -0,0 +1,13 @@ +namespace ProxySuper.Core.Models.Projects +{ + public enum ProjectType + { + Xray = 0, + TrojanGo = 1, + NaiveProxy = 2, + Brook = 3, + V2ray = 4, + MTProtoGo = 5, + Hysteria2 = 6, + } +} diff --git a/ProxySuper.Core/Models/Projects/RayType.cs b/ProxySuper.Core/Models/Projects/RayType.cs new file mode 100644 index 00000000..ce2d0989 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/RayType.cs @@ -0,0 +1,50 @@ +namespace ProxySuper.Core.Models.Projects +{ + public enum V2RayType + { + // 入口 + //VLESS_RAW_XTLS = 100, + + // VLESS 101开头 + VLESS_TCP = 101, + VLESS_WS = 102, + VLESS_H2 = 103, + VLESS_KCP = 104, + VLESS_QUIC = 105, + //VLESS_RAW = 106, + VLESS_gRPC = 110, + + // VMESS 201开头 + VMESS_TCP = 201, + VMESS_WS = 202, + VMESS_H2 = 203, + VMESS_KCP = 204, + VMESS_QUIC = 205, + + // Trojan 301开头 + Trojan_TCP = 301, + Trojan_WS = 302, + + // SS + ShadowsocksAEAD = 401 + } + + public enum XrayType + { + // VLESS 协议 + VLESS_RAW_XTLS = 100, + VLESS_XTLS_RAW_REALITY = 101, + VLESS_WS = 102, + VLESS_XHTTP = 103, + VLESS_gRPC = 104, + + // VMESS 201开头 + VMESS_KCP = 204, + + // Trojan 301开头 + Trojan_TCP = 301, + + // SS + ShadowsocksAEAD = 401 + } +} diff --git a/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs b/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs new file mode 100644 index 00000000..4462cf8d --- /dev/null +++ b/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs @@ -0,0 +1,91 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ProxySuper.Core.Models.Projects +{ + public class TrojanGoSettings : IProjectSettings + { + public TrojanGoSettings() + { + WithTLS = true; + Port = 443; + WebSocketPath = "/ws"; + Password = Guid.NewGuid().ToString(); + } + + public List FreePorts + { + get + { + return new List { 80, 443, Port }.Distinct().ToList(); + } + } + + public ProjectType Type { get; set; } = ProjectType.TrojanGo; + + /// + /// 是否安装TLS证书 + /// + public bool WithTLS { get; set; } + + /// + /// 域名 + /// + public string Domain { get; set; } + + /// + /// 端口 + /// + public int Port { get; set; } + + /// + /// 密码 + /// + public string Password { get; set; } + + /// + /// 伪装域名 + /// + public string MaskDomain { get; set; } + + /// + /// 是否开启WebSocket + /// + [JsonIgnore] + public bool EnableWebSocket + { + get + { + return !string.IsNullOrEmpty(WebSocketPath); + } + } + + /// + /// websocket路径 + /// + public string WebSocketPath { get; set; } + + + [JsonIgnore] + public string Email + { + get + { + if (!string.IsNullOrEmpty(Domain)) + { + var arr = Domain.Split('.'); + if (arr.Length == 3) + { + return $"{arr[0]}@{arr[1]}.{arr[2]}"; + } + } + + var prefix = Password.Length > 7 ? Password.Substring(0, 7) : Password; + return $"{prefix}@gmail.com"; + } + } + + } +} diff --git a/ProxySuper.Core/Models/Projects/V2raySettings.cs b/ProxySuper.Core/Models/Projects/V2raySettings.cs new file mode 100644 index 00000000..87b46531 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/V2raySettings.cs @@ -0,0 +1,187 @@ +using Newtonsoft.Json; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class V2raySettings : IProjectSettings + { + public static List DisguiseTypes = new List { + "none", + "srtp", + "utp", + "wechat-video", + "dtls", + "wireguard", + }; + + public V2raySettings() + { + WithTLS = true; + + var guid = Guid.NewGuid().ToString(); + Port = 443; + VLESS_KCP_Port = 2001; + VLESS_QUIC_Port = 2002; + VLESS_gRPC_Port = 2003; + + VMESS_KCP_Port = 3001; + VMESS_QUIC_Port = 3002; + ShadowSocksPort = 4001; + + UUID = guid; + Types = new List(); + + VLESS_WS_Path = "/" + Utils.RandomString(6); + VLESS_KCP_Type = "none"; + VLESS_KCP_Seed = guid; + VLESS_QUIC_Key = ""; + VLESS_QUIC_Type = "none"; + VLESS_QUIC_Security = "none"; + VLESS_QUIC_Type = "none"; + VLESS_gRPC_ServiceName = Utils.RandomString(7); + + VMESS_WS_Path = "/" + Utils.RandomString(8); + VMESS_TCP_Path = "/" + Utils.RandomString(9); + VMESS_KCP_Seed = guid; + VMESS_QUIC_Key = ""; + VMESS_KCP_Type = "none"; + VMESS_QUIC_Security = "none"; + VMESS_QUIC_Type = "none"; + + TrojanPassword = guid; + + ShadowSocksPassword = guid; + ShadowSocksMethod = "aes-128-gcm"; + } + + [JsonIgnore] + public bool IsIPAddress + { + get + { + return IPAddress.TryParse(Domain, out _); + } + } + + [JsonIgnore] + public List FreePorts + { + get + { + var list = new List(); + list.Add(80); + list.Add(Port); + + if (Types.Contains(V2RayType.VLESS_KCP)) + { + list.Add(VLESS_KCP_Port); + } + + if (Types.Contains(V2RayType.VLESS_QUIC)) + { + list.Add(VLESS_QUIC_Port); + } + + if (Types.Contains(V2RayType.VMESS_KCP)) + { + list.Add(VMESS_KCP_Port); + } + + if (Types.Contains(V2RayType.VMESS_QUIC)) + { + list.Add(VMESS_QUIC_Port); + } + + if (Types.Contains(V2RayType.ShadowsocksAEAD)) + { + list.Add(ShadowSocksPort); + } + + if (Types.Contains(V2RayType.VLESS_gRPC)) + { + list.Add(VLESS_gRPC_Port); + } + + return list.Distinct().ToList(); + } + } + + /// + /// 是否安装证书, + /// 上传自有证书时选False,则不会自动安装证书。 + /// + public bool WithTLS { get; set; } + + /// + /// 端口 + /// + public int Port { get; set; } + + /// + /// 域名 + /// + public string Domain { get; set; } + + /// + /// UUID + /// + public string UUID { get; set; } + + /// + /// 多用户 + /// + public List MulitUUID { get; set; } = new List(); + + /// + /// 伪装域名 + /// + public string MaskDomain { get; set; } + + [JsonIgnore] + public string Email + { + get + { + if (!string.IsNullOrEmpty(Domain)) + { + var arr = Domain.Split('.'); + if (arr.Length == 3) + { + return $"{arr[0]}@{arr[1]}.{arr[2]}"; + } + } + + return $"{UUID.Substring(2, 6)}@gmail.com"; + } + } + + /// + /// 安装类型 + /// + public List Types { get; set; } = new List(); + + /// + /// 根据xray类型获取路径 + /// + /// + /// + public string GetPath(V2RayType type) + { + switch (type) + { + case V2RayType.VLESS_WS: + return VLESS_WS_Path; + case V2RayType.VMESS_TCP: + return VMESS_TCP_Path; + case V2RayType.VMESS_WS: + return VMESS_WS_Path; + default: + return string.Empty; + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/V2raySettings_SS.cs b/ProxySuper.Core/Models/Projects/V2raySettings_SS.cs new file mode 100644 index 00000000..9fa4afd0 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/V2raySettings_SS.cs @@ -0,0 +1,33 @@ +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class V2raySettings + { + /// + /// ss password + /// + public string ShadowSocksPassword { get; set; } + + /// + /// ss method + /// + public string ShadowSocksMethod { get; set; } + + /// + /// ss port + /// + public int ShadowSocksPort { get; set; } + + /// + /// share link + /// + public string ShadowSocksShareLink + { + get + { + return ShareLink.Build(V2RayType.ShadowsocksAEAD, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/V2raySettings_Trojan.cs b/ProxySuper.Core/Models/Projects/V2raySettings_Trojan.cs new file mode 100644 index 00000000..bc5ac882 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/V2raySettings_Trojan.cs @@ -0,0 +1,17 @@ +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class V2raySettings + { + public string TrojanPassword { get; set; } + + public string Trojan_TCP_ShareLink + { + get + { + return ShareLink.Build(V2RayType.Trojan_TCP, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/V2raySettings_VLESS.cs b/ProxySuper.Core/Models/Projects/V2raySettings_VLESS.cs new file mode 100644 index 00000000..14b7372b --- /dev/null +++ b/ProxySuper.Core/Models/Projects/V2raySettings_VLESS.cs @@ -0,0 +1,115 @@ +using ProxySuper.Core.Services; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Documents; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class V2raySettings + { + /// + /// vless tcp shareLink + /// + public string VLESS_TCP_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VLESS_TCP, this); + } + } + + /// + /// websocket path + /// + public string VLESS_WS_Path { get; set; } + + /// + /// VLESS WS ShareLink + /// + public string VLESS_WS_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VLESS_WS, this); + } + } + + /// + /// kcp seed + /// + public string VLESS_KCP_Seed { get; set; } + + /// + /// kcp type + /// + public string VLESS_KCP_Type { get; set; } + + /// + /// kcp port + /// + public int VLESS_KCP_Port { get; set; } + + /// + /// VLESS KCP ShareLink + /// + public string VLESS_KCP_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VLESS_KCP, this); + } + } + + /// + /// vless quic security + /// + public string VLESS_QUIC_Security { get; set; } + + /// + /// vless quic type + /// + public string VLESS_QUIC_Type { get; set; } + + /// + /// vless quic port + /// + public int VLESS_QUIC_Port { get; set; } + + /// + /// vless quic key + /// + public string VLESS_QUIC_Key { get; set; } + + /// + /// vless quic ShareLink + /// + public string VLESS_QUIC_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VLESS_QUIC, this); + } + } + + /// + /// grpc port + /// + public int VLESS_gRPC_Port { get; set; } + + /// + /// grpc service name + /// + public string VLESS_gRPC_ServiceName { get; set; } + + /// + /// vless grpc share link + /// + public string VLESS_gRPC_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VLESS_gRPC, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/V2raySettings_VMESS.cs b/ProxySuper.Core/Models/Projects/V2raySettings_VMESS.cs new file mode 100644 index 00000000..5bc359bc --- /dev/null +++ b/ProxySuper.Core/Models/Projects/V2raySettings_VMESS.cs @@ -0,0 +1,96 @@ +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class V2raySettings + { + /// + /// vmess websocket path + /// + public string VMESS_WS_Path { get; set; } + + /// + /// vmess ws sharelink + /// + public string VMESS_WS_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VMESS_WS, this); + } + } + + /// + /// mvess tcp path + /// + public string VMESS_TCP_Path { get; set; } + + /// + /// vmess tcp ShareLink + /// + public string VMESS_TCP_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VMESS_TCP, this); + } + } + + /// + /// vmess kcp seed + /// + public string VMESS_KCP_Seed { get; set; } + + /// + /// vmess kcp type + /// + public string VMESS_KCP_Type { get; set; } + + /// + /// vmess kcp port + /// + public int VMESS_KCP_Port { get; set; } + + /// + /// vmess kcp ShareLink + /// + public string VMESS_KCP_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VMESS_KCP, this); + } + } + + /// + /// vmess quic security + /// + public string VMESS_QUIC_Security { get; set; } + + /// + /// vmess quic type + /// + public string VMESS_QUIC_Type { get; set; } + + /// + /// vmess quic port + /// + public int VMESS_QUIC_Port { get; set; } + + /// + /// vmess quic key + /// + public string VMESS_QUIC_Key { get; set; } + + /// + /// vmess quic ShareLink + /// + public string VMESS_QUIC_ShareLink + { + get + { + return ShareLink.Build(V2RayType.VMESS_QUIC, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/XraySettings.cs b/ProxySuper.Core/Models/Projects/XraySettings.cs new file mode 100644 index 00000000..d039a25f --- /dev/null +++ b/ProxySuper.Core/Models/Projects/XraySettings.cs @@ -0,0 +1,179 @@ +using Newtonsoft.Json; +using ProxySuper.Core.Services; +using ProxySuper.Core.Helpers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class XraySettings : IProjectSettings + { + + public XraySettings() + { + WithTLS = true; + + var guid = Guid.NewGuid().ToString(); + Port = 443; + VLESS_gRPC_Port = 8443; + VMESS_KCP_Port = 3001; + ShadowSocksPort = 4001; + + UUID = guid; + Types = new List(); + + VLESS_XHTTP_Path = "/" + Utils.RandomString(6); + VLESS_WS_Path = "/" + Utils.RandomString(6); + VLESS_gRPC_ServiceName = Utils.RandomString(7); + + VMESS_KCP_Seed = guid; + VMESS_KCP_Type = "none"; + + TrojanPassword = guid; + + ShadowSocksPassword = guid; + ShadowSocksMethod = "aes-128-gcm"; + + var x25519Key = new X25519KeyPair(); + REALITY_privateKey = x25519Key.PrivateKey; + REALITY_publicKey = x25519Key.PublicKey; + } + + /// + /// Xray 使用浏览器的 TLS Client Hello 指纹可选列表 + /// + [JsonIgnore] + public static List UTLSList = new List { "", "chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random", "randomized" }; + + /// + /// Xray 使用浏览器的 TLS Client Hello 指纹参数 + /// + public string UTLS { get; set; } = UTLSList[1]; + + [JsonIgnore] + public bool IsIPAddress + { + get + { + return IPAddress.TryParse(Domain, out _); + } + } + + [JsonIgnore] + public List FreePorts + { + get + { + var list = new List(); + list.Add(80); + list.Add(Port); + + + if (Types.Contains(XrayType.VMESS_KCP)) + { + list.Add(VMESS_KCP_Port); + } + + + if (Types.Contains(XrayType.ShadowsocksAEAD)) + { + list.Add(ShadowSocksPort); + } + + if (Types.Contains(XrayType.VLESS_gRPC)) + { + list.Add(VLESS_gRPC_Port); + } + + return list.Distinct().ToList(); + } + } + + /// + /// 使用REALITY模式时,客户端爬虫初始路径与参数 + /// + public string REALITY_spiderX { get; set; } = "/"; + + /// + /// 使用REALITY模式时,私钥 + /// + public string REALITY_privateKey { get; set; } = string.Empty; + + /// + /// 使用REALITY模式时,公钥 + /// + public string REALITY_publicKey { get; set; } = string.Empty; + + /// + /// 是否安装证书, + /// 上传自有证书时选False,则不会自动安装证书。 + /// + public bool WithTLS { get; set; } + + /// + /// 端口 + /// + public int Port { get; set; } + + /// + /// 域名 + /// + public string Domain { get; set; } + + /// + /// UUID + /// + public string UUID { get; set; } + + /// + /// 多用户 + /// + public List MulitUUID { get; set; } = new List(); + + /// + /// 伪装域名 + /// + public string MaskDomain { get; set; } + + [JsonIgnore] + public string Email + { + get + { + if (!string.IsNullOrEmpty(Domain)) + { + var arr = Domain.Split('.'); + if (arr.Length == 3) + { + return $"{arr[0]}@{arr[1]}.{arr[2]}"; + } + } + + return $"{UUID.Substring(2, 6)}@gmail.com"; + } + } + + /// + /// 安装类型 + /// + public List Types { get; set; } = new List(); + + /// + /// 根据xray类型获取路径 + /// + /// + /// + public string GetPath(XrayType type) + { + switch (type) + { + case XrayType.VLESS_WS: + return VLESS_WS_Path; + default: + return string.Empty; + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/XraySettings_SS.cs b/ProxySuper.Core/Models/Projects/XraySettings_SS.cs new file mode 100644 index 00000000..b392f541 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/XraySettings_SS.cs @@ -0,0 +1,33 @@ +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class XraySettings + { + /// + /// ss password + /// + public string ShadowSocksPassword { get; set; } + + /// + /// ss method + /// + public string ShadowSocksMethod { get; set; } + + /// + /// ss port + /// + public int ShadowSocksPort { get; set; } + + /// + /// share link + /// + public string ShadowSocksShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.ShadowsocksAEAD, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/XraySettings_Trojan.cs b/ProxySuper.Core/Models/Projects/XraySettings_Trojan.cs new file mode 100644 index 00000000..62e8ead1 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/XraySettings_Trojan.cs @@ -0,0 +1,17 @@ +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class XraySettings + { + public string TrojanPassword { get; set; } + + public string Trojan_TCP_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.Trojan_TCP, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/XraySettings_VLESS.cs b/ProxySuper.Core/Models/Projects/XraySettings_VLESS.cs new file mode 100644 index 00000000..aa7d8551 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/XraySettings_VLESS.cs @@ -0,0 +1,103 @@ +using ProxySuper.Core.Services; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Documents; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class XraySettings + { + + /// + /// vless xtls 流控参数可选列表 + /// + + //流控参数在服务端只有两种 ""/null, "xtls-rprx-vision",客户端可以选择三种:""/null, "xtls-rprx-vision", "xtls-rprx-vision-udp443". + //但是选择了XTLS模式就是默认服务端flow不是""/null,所以这里不再填加""/null这一项。 + //如果服务端开启了流控,客户端也必须开启流控,否则会报错。 + //同样如果服务端没有开启流控,客户端也不能开启流控,否则会报错。 + public static List FlowList = new List { "xtls-rprx-vision", "xtls-rprx-vision-udp443" }; + + /// + /// vless xtls 流控参数 + /// + public string Flow { get; set; } = FlowList[0]; + + /// + /// vless xtls reality shareLink + /// + public string VLESS_RAW_XTLS_REALITY_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.VLESS_XTLS_RAW_REALITY, this); + } + } + + + /// + /// vless xtls shareLink + /// + public string VLESS_RAW_XTLS_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.VLESS_RAW_XTLS, this); + } + } + + + /// + /// vless xhttp path + /// + public string VLESS_XHTTP_Path { get; set; } + + /// + /// VLESS XHTTP ShareLink + /// + public string VLESS_XHTTP_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.VLESS_XHTTP, this); + } + } + + /// + /// websocket path + /// + public string VLESS_WS_Path { get; set; } + + /// + /// VLESS WS ShareLink + /// + public string VLESS_WS_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.VLESS_WS, this); + } + } + + /// + /// grpc port + /// + public int VLESS_gRPC_Port { get; set; } + + /// + /// grpc service name + /// + public string VLESS_gRPC_ServiceName { get; set; } + + /// + /// vless grpc share link + /// + public string VLESS_gRPC_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.VLESS_gRPC, this); + } + } + } +} diff --git a/ProxySuper.Core/Models/Projects/XraySettings_VMESS.cs b/ProxySuper.Core/Models/Projects/XraySettings_VMESS.cs new file mode 100644 index 00000000..0e6bd472 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/XraySettings_VMESS.cs @@ -0,0 +1,48 @@ +using ProxySuper.Core.Services; +using System.Collections.Generic; + +namespace ProxySuper.Core.Models.Projects +{ + public partial class XraySettings + { + /// + /// vmess kcp 数据包头部伪装类型 + /// + public static List DisguiseTypes = new List { + "none", + "srtp", + "utp", + "wechat-video", + "dtls", + "wireguard", + "dns", + }; + + /// + /// vmess kcp seed 混淆密码 + /// + public string VMESS_KCP_Seed { get; set; } + + /// + /// vmess kcp type + /// + public string VMESS_KCP_Type { get; set; } + + /// + /// vmess kcp port + /// + public int VMESS_KCP_Port { get; set; } + + /// + /// vmess kcp ShareLink + /// + public string VMESS_KCP_ShareLink + { + get + { + return ShareLink.XrayBuild(XrayType.VMESS_KCP, this); + } + } + + } +} diff --git a/ProxySuper.Core/Models/Record.cs b/ProxySuper.Core/Models/Record.cs new file mode 100644 index 00000000..aa80c6cb --- /dev/null +++ b/ProxySuper.Core/Models/Record.cs @@ -0,0 +1,134 @@ +using MvvmCross.ViewModels; +using Newtonsoft.Json; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Text; + +namespace ProxySuper.Core.Models +{ + [JsonObject] + public class Record : MvxViewModel + { + public Record() + { + _isChecked = false; + } + + private Host _host; + private bool _isChecked; + + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("host")] + public Host Host + { + get { return _host; } + set + { + _host = value; + RaisePropertyChanged("Host"); + } + } + + [JsonProperty("v2raySettings")] + public V2raySettings V2raySettings { get; set; } + + [JsonProperty("xraySettings")] + public XraySettings XraySettings { get; set; } + + [JsonProperty("trojanGoSettings")] + public TrojanGoSettings TrojanGoSettings { get; set; } + + [JsonProperty("naiveProxySettings")] + public NaiveProxySettings NaiveProxySettings { get; set; } + + [JsonProperty("brook")] + public BrookSettings BrookSettings { get; set; } + + [JsonProperty("mtProtoGoSettings")] + public MTProtoGoSettings MTProtoGoSettings { get; set; } + + [JsonProperty] + public HysteriaSettings HysteriaSettings { get; set; } + + + [JsonIgnore] + public ProjectType Type + { + get + { + if (XraySettings != null) return ProjectType.Xray; + + if (V2raySettings != null) return ProjectType.V2ray; + + if (TrojanGoSettings != null) return ProjectType.TrojanGo; + + if (NaiveProxySettings != null) return ProjectType.NaiveProxy; + + if (MTProtoGoSettings != null) return ProjectType.MTProtoGo; + + if (HysteriaSettings != null) return ProjectType.Hysteria2; + + return ProjectType.Brook; + } + } + + [JsonIgnore] + public bool IsChecked + { + get + { + return _isChecked; + } + set + { + _isChecked = value; + RaisePropertyChanged("IsChecked"); + } + } + + [JsonIgnore] + public Action OnSave { get; set; } = () => { }; + + public string GetShareLink() + { + if (Type == ProjectType.V2ray) + { + StringBuilder strBuilder = new StringBuilder(); + V2raySettings.Types.ForEach(type => + { + var link = ShareLink.Build(type, V2raySettings); + strBuilder.AppendLine(link); + }); + return strBuilder.ToString(); + } + + if (Type == ProjectType.Xray) + { + StringBuilder strBuilder = new StringBuilder(); + XraySettings.Types.ForEach(type => + { + var link = ShareLink.XrayBuild(type, XraySettings); + strBuilder.AppendLine(link); + }); + return strBuilder.ToString(); + } + + if (Type == ProjectType.TrojanGo) + { + return ShareLink.BuildTrojanGo(TrojanGoSettings); + } + + if (Type == ProjectType.NaiveProxy) + { + return ShareLink.BuildNaiveProxy(NaiveProxySettings); + } + + return string.Empty; + } + + } +} diff --git a/ProxySuper.Core/Properties/AssemblyInfo.cs b/ProxySuper.Core/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b26cc8e3 --- /dev/null +++ b/ProxySuper.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("ProxySuper.Core")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ProxySuper.Core")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("15779ee6-d8ca-44bf-bfe2-941e155eef3f")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ProxySuper.Core/ProxySU.ico b/ProxySuper.Core/ProxySU.ico new file mode 100644 index 00000000..955b1e26 Binary files /dev/null and b/ProxySuper.Core/ProxySU.ico differ diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj new file mode 100644 index 00000000..51a3453d --- /dev/null +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -0,0 +1,178 @@ + + + + + Debug + AnyCPU + {15779EE6-D8CA-44BF-BFE2-941E155EEF3F} + Library + Properties + ProxySuper.Core + ProxySuper.Core + v4.7.2 + latest + 512 + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + ProxySU.ico + + + + ..\packages\Chaos.NaCl.Standard.1.0.0\lib\netstandard2.0\Chaos.NaCl.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\packages\MvvmCross.8.0.2\lib\net461\MvvmCross.dll + + + False + ..\json.net\net40\Newtonsoft.Json.dll + + + + + ..\packages\QRCoder.1.4.3\lib\net40\QRCoder.dll + + + ..\packages\SSH.NET.2023.0.0\lib\net462\Renci.SshNet.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Console.4.3.1\lib\net46\System.Console.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + + + + + + + + + ..\packages\YamlDotNet.16.3.0\lib\net47\YamlDotNet.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProxySuper.Core/Services/BrookService.cs b/ProxySuper.Core/Services/BrookService.cs new file mode 100644 index 00000000..d5904ff6 --- /dev/null +++ b/ProxySuper.Core/Services/BrookService.cs @@ -0,0 +1,171 @@ +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class BrookService : ServiceBase + { + private string brookServiceTemp = @" + [Unit] + Description=brook service + After=network.target syslog.target + Wants=network.target + + [Service] + Type=simple + ExecStart=##run_cmd## + + [Install] + WantedBy=multi-user.target"; + + + public BrookService(Host host, BrookSettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "安装Brook"; + Progress.Percentage = 0; + + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 40; + + Progress.Desc = "配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 50; + + + Progress.Step = "检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 60; + if (Settings.BrookType == BrookType.wssserver) + { + Progress.Desc = "检测域名是否绑定本机IP"; + ValidateDomain(); + Progress.Percentage = 80; + } + + Progress.Step = "安装Brook服务"; + InstallBrook(); + + Progress.Percentage = 100; + Progress.Step = "安装Brook成功"; + Progress.Desc = "安装Brook成功"; + + AppendCommand("分享连接:"); + AppendCommand(ShareLink.BuildBrook(Settings)); + + NavigationService.Navigate(Settings); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void InstallBrook() + { + Progress.Desc = "执行Brook安装文件"; + string url = "https://github.com/txthinking/brook/releases/latest/download/brook_linux_amd64"; + if (ArchType == ArchType.arm) + { + url = url.Replace("brook_linux_amd64", "brook_linux_arm7"); + } + + RunCmd($"curl -L {url} -o /usr/bin/brook"); + RunCmd("chmod +x /usr/bin/brook"); + + Progress.Desc = "设置Brook服务"; + var brookService = brookServiceTemp.Replace("##run_cmd##", GetRunBrookCommand()); + + RunCmd("rm -rf /etc/systemd/system/brook.service"); + RunCmd("touch /etc/systemd/system/brook.service"); + RunCmd($"echo \"{brookService}\" > /etc/systemd/system/brook.service"); + RunCmd("sudo chmod 777 /etc/systemd/system/brook.service"); + + Progress.Desc = "启动Brook服务"; + RunCmd("systemctl enable brook"); + RunCmd("systemctl restart brook"); + } + + private string GetRunBrookCommand() + { + var runBrookCmd = string.Empty; + + if (Settings.BrookType == BrookType.server) + { + return $"/usr/bin/brook server --listen :{Settings.Port} --password {Settings.Password}"; + } + + if (Settings.BrookType == BrookType.wsserver) + { + return $"/usr/bin/brook wsserver --listen :{Settings.Port} --password {Settings.Password}"; + } + + if (Settings.BrookType == BrookType.wssserver) + { + return $"/usr/bin/brook wssserver --domain {Settings.Domain} --password {Settings.Password}"; + } + + if (Settings.BrookType == BrookType.socks5) + { + var ip = IsOnlyIPv6 ? IPv6 : IPv4; + return $"/usr/bin/brook socks5 --socks5 {ip}:{Settings.Port}"; + } + + return runBrookCmd; + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "卸载Brook"; + Progress.Percentage = 0; + + Progress.Desc = "停止Brook服务"; + RunCmd("systemctl stop brook"); + RunCmd("systemctl disable brook"); + Progress.Percentage = 30; + + Progress.Desc = "删除Brook相关文件"; + RunCmd("rm -rf /etc/systemd/system/brook.service"); + RunCmd("rm -rf /usr/bin/brook"); + Progress.Percentage = 80; + + Progress.Desc = "重置防火墙设置"; + ResetFirewalld(); + + Progress.Percentage = 100; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + } +} diff --git a/ProxySuper.Core/Services/HysteriaService.cs b/ProxySuper.Core/Services/HysteriaService.cs new file mode 100644 index 00000000..02f50850 --- /dev/null +++ b/ProxySuper.Core/Services/HysteriaService.cs @@ -0,0 +1,398 @@ +using Microsoft.Win32; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using ProxySuper.Core.Converters; +using ProxySuper.Core.Helpers; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Templates; +using Renci.SshNet.Messages; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Dynamic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Windows; +using YamlDotNet.Core; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace ProxySuper.Core.Services +{ + public class HysteriaService : ServiceBase + { + public HysteriaService(Host host, HysteriaSettings settings) : base(host, settings) + { + } + + + public void Install() + { + try + { + Task.Factory.StartNew(() => + { + Progress.Step = "安装Hysteria"; + Progress.Percentage = 0; + + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 40; + + Progress.Desc = "配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 50; + + Progress.Step = "检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 60; + + + Progress.Desc = "检测域名是否绑定本机IP"; + ValidateDomain(); + Progress.Percentage = 80; + + Progress.Step = "上传Hysteria配置文件"; + string yamlConfig = BuildYamlConfig(); + UploadConfigFile(yamlConfig); + Progress.Step = "安装Hysteria服务"; + InstallHysteria(); + + Progress.Percentage = 100; + Progress.Step = "安装Hysteria成功"; + Progress.Desc = "安装Hysteria成功"; + + if (Settings.AutoACME == false) + { + Progress.Step = "请手动上传SSL证书"; + Progress.Desc = "请手动上传SSL证书"; + } + + if (Settings.EnableUpDisguisedWeb == true) + { + Progress.Step = "请手动上传伪装网站内容"; + Progress.Desc = "请手动上传伪装网站内容"; + } + }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "卸载Hysteria"; + Progress.Percentage = 0; + + Progress.Desc = "停止Hysteria服务"; + RunCmd("systemctl stop hysteria-server.service"); + RunCmd("systemctl disable hysteria-server.service"); + Progress.Percentage = 30; + + Progress.Desc = "删除Hysteria相关文件"; + RunCmd("bash <(curl -fsSL https://get.hy2.sh/) --remove"); + //RunCmd("rm -rf /etc/systemd/system/Hysteria.service"); + //RunCmd("rm -rf /usr/bin/Hysteria"); + Progress.Percentage = 80; + + Progress.Desc = "重置防火墙设置"; + ResetFirewalld(); + + Progress.Percentage = 100; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + /* + private string HysteriaServiceTemp = @" + [Unit] + Description=hysteria service + After=network.target syslog.target + Wants=network.target + + [Service] + Type=simple + ExecStart=##run_cmd## + + [Install] + WantedBy=multi-user.target"; + */ + private void InstallHysteria() + { + Progress.Desc = "执行Hysteria安装文件,及设置Hysteria服务"; + RunCmd($"bash <(curl -fsSL https://get.hy2.sh/)"); + + /* + string url = "https://github.com/apernet/hysteria/releases/download/v1.3.4/hysteria-linux-386"; + string targetPath = "/usr/bin/hysteria/hysteria-linux-386"; + + if (ArchType == ArchType.arm) + { + url = url.Replace("hysteria-linux-386", "hysteria-linux-arm"); + targetPath = targetPath.Replace("hysteria-linux-386", "hysteria-linux-arm"); + } + + RunCmd($"curl -L {url} -o {targetPath}"); + RunCmd($"chmod +x {targetPath}"); + + Progress.Desc = "设置Hysteria服务"; + var cmd = targetPath + " -c /usr/bin/hysteria/config.json server"; + var hysteriaService = HysteriaServiceTemp.Replace("##run_cmd##", cmd); + + RunCmd("rm -rf /etc/systemd/system/hysteria.service"); + RunCmd("touch /etc/systemd/system/hysteria.service"); + + RunCmd($"echo \"{hysteriaService}\" > /etc/systemd/system/hysteria.service"); + RunCmd("sudo chmod 777 /etc/systemd/system/hysteria.service"); + + */ + + + Progress.Desc = "启动Hysteria服务"; + RunCmd("systemctl enable hysteria-server.service"); + RunCmd("systemctl restart hysteria-server.service"); + } + + private static string ConfigFile_base = HysteriaConfigTemplates.ServerHysteria2Config_base; + private static string ConfigFile_acme = HysteriaConfigTemplates.ServerHysteria2Config_acme; + private static string ConfigFile_tls = HysteriaConfigTemplates.ServerHysteria2Config_tls; + private static string ConfigFile_masquerade_proxy = HysteriaConfigTemplates.ServerHysteria2Config_masquerade_proxy; + private static string ConfigFile_masquerade_file = HysteriaConfigTemplates.ServerHysteria2Config_masquerade_file; + private static string ConfigFile_bbr = HysteriaConfigTemplates.ServerHysteria2Config_bbr; + private static string ConfigFile_obfs = HysteriaConfigTemplates.ServerAndClientHysteria2Config_obfs; + private static string ConfigFile_bandwidth = HysteriaConfigTemplates.ServerAndClientHysteria2Config_bandwidth; + + private static string ClientConfigFile_base = HysteriaConfigTemplates.ClientHysteria2Config_base; + + + public void UploadCert() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadCert; + fileDialog.ShowDialog(); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + + #region 私有方法 + + private string BuildYamlConfig() + { + dynamic yamlConfigBase = LoadYamlConfigToJsonObject(ConfigFile_base); + yamlConfigBase.listen = ":" + Settings.Port; + yamlConfigBase.auth.password = Settings.Password; + string yamlConfig = JsonObjectToYamlConfig(yamlConfigBase); + + dynamic yamlClientConfigBase = LoadYamlConfigToJsonObject(ClientConfigFile_base); + yamlClientConfigBase.server = $"{Settings.Domain}:{Settings.Port}"; + yamlClientConfigBase.auth = Settings.Password; + string yamlClientConfig = JsonObjectToYamlConfig(yamlClientConfigBase); + + if (Settings.AutoACME == true) + { + dynamic yamlConfigAcme = LoadYamlConfigToJsonObject(ConfigFile_acme); + yamlConfigAcme.acme.domains[0] = Settings.Domain; + yamlConfigAcme.acme.email = Settings.Email; + string _yamlConfigAcme = JsonObjectToYamlConfig(yamlConfigAcme); + yamlConfig = YamlConfigMerger.MergeYamlStrings(yamlConfig, _yamlConfigAcme, CamelCaseNamingConvention.Instance); + } + else + { + yamlConfig = YamlConfigMerger.MergeYamlStrings(yamlConfig, ConfigFile_tls, CamelCaseNamingConvention.Instance); + } + + if (Settings.EnableObfs == true) + { + dynamic yamlConfigObfs = LoadYamlConfigToJsonObject(ConfigFile_obfs); + yamlConfigObfs.obfs.salamander.password = Settings.ObfsPassword; + string _yamlConfigObfs = JsonObjectToYamlConfig(yamlConfigObfs); + yamlConfig = YamlConfigMerger.MergeYamlStrings(yamlConfig, _yamlConfigObfs, CamelCaseNamingConvention.Instance); + + dynamic yamlClientConfigObfs = LoadYamlConfigToJsonObject(ConfigFile_obfs); + yamlClientConfigObfs.obfs.salamander.password = Settings.ObfsPassword; + string _yamlClientConfigObfs = JsonObjectToYamlConfig(yamlClientConfigObfs); + yamlClientConfig = YamlConfigMerger.MergeYamlStrings(yamlClientConfig, _yamlClientConfigObfs, CamelCaseNamingConvention.Instance); + + } + + if (Settings.EnableUpDisguisedWeb == true) + { + yamlConfig = YamlConfigMerger.MergeYamlStrings(yamlConfig, ConfigFile_masquerade_file, CamelCaseNamingConvention.Instance); + } + else if (string.IsNullOrEmpty(Settings.MaskDomain) == false) + { + dynamic yamlConfigMasquerade_proxy = LoadYamlConfigToJsonObject(ConfigFile_masquerade_proxy); + + var prefix = "https://"; + if (Settings.MaskDomain.StartsWith("http://")) + { + prefix = "http://"; + } + var domain = Settings.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()); + + yamlConfigMasquerade_proxy.masquerade.proxy.url = $"{prefix}{domain}";// Settings.MaskDomain; + string _yamlConfigMasquerade_proxy = JsonObjectToYamlConfig(yamlConfigMasquerade_proxy); + yamlConfig = YamlConfigMerger.MergeYamlStrings(yamlConfig, _yamlConfigMasquerade_proxy, CamelCaseNamingConvention.Instance); + } + + Settings.ClientHysteria2Config = yamlClientConfig; + return yamlConfig; + } + + private void UploadConfigFile(string yamlConfig) + { + RunCmd("mkdir -p /etc/hysteria"); + WriteToFile(yamlConfig, "/etc/hysteria/config.yaml"); + } + + private dynamic LoadYamlConfigToJsonObject(string yamlConfigString) + { + var JsonStr = JsonYamlConverters.YamlToJson(yamlConfigString); + + return JToken.Parse(JsonStr); + } + + private string JsonObjectToYamlConfig(dynamic jsonObj) + { + var jsonStr = JsonConvert.SerializeObject(jsonObj, Formatting.Indented); + return JsonYamlConverters.JsonToYaml(jsonStr); + } + + private void DoUploadCert(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Percentage = 0; + Progress.Step = "上传自有证书"; + Progress.Desc = "检测系统环境"; + + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + var oldFileName = $"ssl_{DateTime.Now.Ticks}"; + RunCmd($"mv /etc/hysteria/ssl /etc/hysteria/{oldFileName}"); + + RunCmd("mkdir -p /etc/hysteria/ssl"); + UploadFile(stream, "/etc/hysteria/ssl/ssl.zip"); + RunCmd("unzip /etc/hysteria/ssl/ssl.zip -d /etc/hysteria/ssl"); + } + + var crtFiles = RunCmd("find /etc/hysteria/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + var keyFiles = RunCmd("find /etc/hysteria/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (crtFiles.Length > 0 && keyFiles.Length > 0) + { + RunCmd($"mv {crtFiles[0]} /etc/hysteria/ssl/hysteria_ssl.crt"); + RunCmd($"mv {keyFiles[0]} /etc/hysteria/ssl/hysteria_ssl.key"); + } + else + { + Progress.Step = "上传失败"; + Progress.Desc = "上传证书失败,缺少 .crt 和 .key 文件"; + return; + } + + Progress.Desc = "重启Hysteria服务"; + RunCmd("systemctl restart hysteria"); + + Progress.Percentage = 100; + Progress.Desc = "上传证书完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Desc = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/var/www/hymasq")) + { + RunCmd("mkdir -p /var/www/hymasq"); + } + RunCmd("rm -rf /var/www/hymasq/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/var/www/hymasq/webfile.zip"); + RunCmd("unzip /var/www/hymasq/webfile.zip -d /var/www/hymasq"); + } + RunCmd("chmod -R 777 /var/www/hymasq"); + Progress.Percentage = 80; + + + Progress.Percentage = 90; + + Progress.Desc = "重启Hysteria服务"; + RunCmd("systemctl restart hysteria"); + Progress.Percentage = 100; + + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + #endregion + } +} diff --git a/ProxySuper.Core/Services/MTProtoGoService.cs b/ProxySuper.Core/Services/MTProtoGoService.cs new file mode 100644 index 00000000..ce67bc24 --- /dev/null +++ b/ProxySuper.Core/Services/MTProtoGoService.cs @@ -0,0 +1,160 @@ +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class MTProtoGoService : ServiceBase + { + public MTProtoGoService(Host host, MTProtoGoSettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "1. 检测系统环境"; + Progress.Percentage = 0; + + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 15; + + Progress.Step = "2. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 25; + + Progress.Step = "3. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 35; + + Progress.Step = "4. 安装docker"; + InstallDocker(); + Progress.Percentage = 50; + + Progress.Step = "5. 生成密钥"; + //RunCmd("docker pull nineseconds/mtg:2"); //拉取v2版本命令,但是似乎不用也可以。 + //下面的命令是v1版本的命令格式。可以保留。将来如启用v1,可用。 + //Settings.SecretText = RunCmd($"docker run nineseconds/mtg:1 generate-secret -c {Settings.Cleartext} tls").TrimEnd('\n'); + Settings.SecretText = RunCmd($"docker run nineseconds/mtg:2 generate-secret {Settings.Cleartext}").TrimEnd('\n'); + Progress.Percentage = 65; + + Progress.Step = "6. 生成配置文件"; + Progress.Desc = "创建配置"; + RunCmd("touch /etc/mtg.toml"); + + Progress.Desc = "写入配置内容"; + RunCmd($"echo \"secret=\\\"{Settings.SecretText}\\\"\" > /etc/mtg.toml"); + RunCmd($"echo \"bind-to=\\\"0.0.0.0:{Settings.Port}\\\"\" >> /etc/mtg.toml"); + Progress.Percentage = 80; + + Progress.Step = "7. 启动MTProto服务"; + RunCmd($"docker run -d -v /etc/mtg.toml:/config.toml --name=mtg --restart=always -p {Settings.Port + ":" + Settings.Port} nineseconds/mtg:2"); + Progress.Desc = "设置自启动MTProto服务"; + + Progress.Step = "安装完成"; + Progress.Percentage = 100; + + AppendCommand("Host: " + Settings.Domain); + AppendCommand("Port: " + Settings.Port); + AppendCommand("Secret: " + Settings.SecretText); + + NavigationService.Navigate(Settings); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "卸载MTProto"; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + Progress.Percentage = 30; + + Progress.Desc = "删除docker容器"; + var cid = RunCmd("docker ps -q --filter name=mtg"); + RunCmd($"docker stop {cid}"); + RunCmd($"docker rm {cid}"); + Progress.Percentage = 100; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "更新MTProto配置"; + + Progress.Desc = "暂停MTProto服务"; + var cid = RunCmd("docker ps -q --filter name=mtg"); + RunCmd($"docker stop {cid}"); + Progress.Percentage = 50; + + Progress.Desc = "生成密钥"; + //Settings.SecretText = RunCmd($"docker run nineseconds/mtg:1 generate-secret -c {Settings.Cleartext} tls").TrimEnd('\n'); //v1版本 + Settings.SecretText = RunCmd($"docker run nineseconds/mtg:2 generate-secret {Settings.Cleartext}").TrimEnd('\n'); + Progress.Percentage = 65; + + Progress.Desc = "修改配置文件"; + RunCmd($"echo \"secret=\\\"{Settings.SecretText}\\\"\" > /etc/mtg.toml"); + RunCmd($"echo \"bind-to=\\\"0.0.0.0:{Settings.Port}\\\"\" >> /etc/mtg.toml"); + Progress.Percentage = 80; + + Progress.Desc = "重启MTProto服务"; + RunCmd($"docker restart {cid}"); + + Progress.Percentage = 100; + Progress.Desc = "更新配置成功"; + + AppendCommand("Host: " + Settings.Domain); + AppendCommand("Port: " + Settings.Port); + AppendCommand("Secret: " + Settings.SecretText); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallDocker() + { + Progress.Desc = "执行docker安装脚本"; + RunCmd("yes | curl https://get.docker.com | sh"); + + if (!FileExists("/usr/bin/docker")) + { + Progress.Desc = "docker安装失败"; + throw new Exception("docker安装失败"); + } + } + } +} diff --git a/ProxySuper.Core/Services/NaiveProxyService.cs b/ProxySuper.Core/Services/NaiveProxyService.cs new file mode 100644 index 00000000..b483f9d4 --- /dev/null +++ b/ProxySuper.Core/Services/NaiveProxyService.cs @@ -0,0 +1,283 @@ +using Microsoft.Win32; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.ViewModels; +using ProxySuper.Core.Templates; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class NaiveProxyService : ServiceBase + { + public NaiveProxyService(Host host, NaiveProxySettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + var index = 1; + + Progress.Step = $"{index++}. 检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 安装系统必要工具"; + InstallSystemTools(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 检测域名是否绑定到本机"; + ValidateDomain(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 安装NaiveProxy"; + InstallNaiveProxy(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 优化网络参数"; + ConfigNetwork(); + Progress.Percentage = 90; + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Desc = "重启Caddy服务"; + RunCmd("systemctl restart caddy"); + + Progress.Percentage = 100; + Progress.Step = "NaiveProxy安装成功"; + Progress.Desc = string.Empty; + + AppendCommand("分享连接:"); + AppendCommand(ShareLink.BuildNaiveProxy(Settings)); + + NavigationService.Navigate(Settings); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "卸载NaiveProxy"; + Progress.Percentage = 0; + + Progress.Desc = "正在卸载..."; + RunCmd("rm -rf caddy_install.sh"); + Progress.Percentage = 10; + + RunCmd("curl -o caddy_install.sh https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); + Progress.Percentage = 20; + + RunCmd("yes | bash caddy_install.sh uninstall"); + Progress.Percentage = 80; + + RunCmd("rm -rf caddy_install.sh"); + Progress.Percentage = 100; + Progress.Step = "卸载NaiveProxy成功"; + Progress.Desc = "卸载NaiveProxy成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新配置"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 30; + + UploadCaddySettings(); + Progress.Desc = "重启Caddy服务"; + RunCmd("systemctl restart caddy"); + Progress.Percentage = 100; + + Progress.Step = "更新配置成功"; + Progress.Desc = string.Empty; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + + #region 私有方法 + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir -p /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 700; + } + + Progress.Desc = "上传Caddy配置文件"; + UploadCaddySettings(useCustomWeb: true); + Progress.Percentage = 90; + + Progress.Desc = "重启caddy服务"; + RunCmd("systemctl restart caddy"); + Progress.Percentage = 100; + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallNaiveProxy() + { + Progress.Desc = "下载NaiveProxy安装文件"; + RunCmd(@"curl https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh yes | bash"); + + Progress.Desc = "设置NaiveProxy开机启动"; + RunCmd("systemctl enable caddy"); + + Progress.Desc = "上传配置文件"; + UploadCaddySettings(false); + } + + private void ConfigNetwork() + { + RunCmd(@"bash -c 'echo ""fs.file-max = 51200"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.rmem_max = 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.wmem_max = 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.rmem_default = 65536"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.wmem_default = 65536"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.netdev_max_backlog = 4096"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.somaxconn = 4096"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_syncookies = 1"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_tw_reuse = 1"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_tw_recycle = 0"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_fin_timeout = 30"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_keepalive_time = 1200"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.ip_local_port_range = 10000 65000"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_max_syn_backlog = 4096"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_max_tw_buckets = 5000"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_rmem = 4096 87380 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_wmem = 4096 65536 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_mtu_probing = 1"" >> /etc/sysctl.conf'"); + RunCmd(@"sysctl -p"); + } + + private void UploadCaddySettings(bool useCustomWeb = false) + { + Progress.Desc = "生成配置文件"; + var caddyStr = BuildConfig(useCustomWeb); + + if (FileExists("/etc/caddy/Caddyfile")) + { + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + } + + Progress.Desc = "上传配置文件"; + WriteToFile(caddyStr, "/etc/caddy/Caddyfile"); + } + + private string BuildConfig(bool useCustomWeb = false) + { + var jsonStr = NaiveServerCaddyfile.BaseCaddyFile;//File.ReadAllText("Templates/NaiveProxy/naive_server.caddyfile"); + jsonStr = jsonStr.Replace("##port##", Settings.Port.ToString()); + jsonStr = jsonStr.Replace("##domain##", Settings.Domain); + jsonStr = jsonStr.Replace("##basicauth##", $"basic_auth {Settings.UserName} {Settings.Password}"); + + if (!useCustomWeb && !string.IsNullOrEmpty(Settings.MaskDomain)) + { + var prefix = "http://"; + if (Settings.MaskDomain.StartsWith("https://")) + { + prefix = "https://"; + } + var domain = Settings.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()); + + jsonStr = jsonStr.Replace("##reverse_proxy##", $"reverse_proxy {prefix}{domain} {{ \n header_up Host {domain} \n }}"); + } + else + { + jsonStr = jsonStr.Replace("##reverse_proxy##", ""); + jsonStr = jsonStr.Replace("#file_server", "file_server"); + } + return jsonStr; + } + + #endregion + } +} diff --git a/ProxySuper.Core/Services/ServiceBase.cs b/ProxySuper.Core/Services/ServiceBase.cs new file mode 100644 index 00000000..7a8c8e1e --- /dev/null +++ b/ProxySuper.Core/Services/ServiceBase.cs @@ -0,0 +1,846 @@ +using MvvmCross; +using MvvmCross.Navigation; +using ProxySuper.Core.Helpers; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using Renci.SshNet; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Navigation; + +namespace ProxySuper.Core.Services +{ + public enum ArchType + { + x86, + arm + } + + public enum CmdType + { + None, + Yum, + Apt, + Dnf + } + + public abstract class ServiceBase where TSettings : IProjectSettings + { + private Host _host; + + private SshClient _sshClient; + + private ProjectProgress _progress; + + public ServiceBase(Host host, TSettings settings) + { + _host = host; + + Settings = settings; + + var connection = CreateConnectionInfo(); + if (connection != null) + { + _sshClient = new SshClient(connection); + } + + _progress = new ProjectProgress(); + + ArchType = ArchType.x86; + + CmdType = CmdType.None; + + IPv4 = string.Empty; + + IPv6 = string.Empty; + + IsOnlyIPv6 = false; + + NavigationService = Mvx.IoCProvider.Resolve(); + } + + public string RunCmd(string command) + { + AppendCommand(command); + + string result; + if (_sshClient.IsConnected) + { + result = _sshClient.CreateCommand(command).Execute(); + } + else + { + result = "连接已断开"; + } + + AppendCommand(result); + + return result; + } + + public ProjectProgress Progress => _progress; + + public TSettings Settings { get; set; } + + public ArchType ArchType { get; set; } + + public CmdType CmdType { get; set; } + + public string IPv4 { get; set; } + + public string IPv6 { get; set; } + + public bool IsOnlyIPv6 { get; set; } + + public IMvxNavigationService NavigationService { get; set; } + + + #region 公用方法 + public void Connect() + { + Task.Run(() => + { + if (_sshClient == null) + { + MessageBox.Show("无法建立连接,连接参数有误!"); + return; + } + + if (_sshClient.IsConnected == false) + { + Progress.Desc = ("正在与服务器建立连接"); + try + { + _sshClient.Connect(); + Progress.Desc = ("建立连接成功"); + } + catch (Exception e) + { + Progress.Desc = ("连接失败," + e.Message); + } + } + }); + } + + public void Disconnect() + { + Task.Run(() => + { + _sshClient?.Disconnect(); + }); + } + + protected void WriteToFile(string text, string path) + { + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text))) + { + using (var sftp = new SftpClient(_sshClient.ConnectionInfo)) + { + try + { + sftp.Connect(); + sftp.UploadFile(stream, path, true); + } + catch (Exception ex) + { + throw ex; + } + finally + { + sftp.Disconnect(); + } + } + } + } + + protected bool FileExists(string path) + { + var cmdStr = $"if [[ -f {path} ]];then echo '1';else echo '0'; fi"; + var cmd = RunCmd(cmdStr); + return cmd.Trim() == "1"; + } + + protected void SyncTimeDiff() + { + RunCmd("rm -f /etc/localtime"); + RunCmd("ln -s /usr/share/zoneinfo/UTC /etc/localtime"); + + var result = RunCmd("date +%s"); + var vpsSeconds = Convert.ToInt64(result); + var localSeconds = (int)(DateTime.Now.ToUniversalTime() - DateTime.Parse("1970-01-01")).TotalSeconds; + + if (Math.Abs(vpsSeconds - localSeconds) >= 90) + { + // 同步本地时间 + var netUtcTime = DateTimeUtils.GetUTCTime(); + DateTimeUtils.SetDate(netUtcTime.ToLocalTime()); + + // 同步VPS时间 + var utcTS = DateTimeUtils.GetUTCTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0); + long timeStampVPS = Convert.ToInt64(utcTS.TotalSeconds); + RunCmd($"date --set=\"$(date \"+%Y-%m-%d %H:%M:%S\" -d @{timeStampVPS.ToString()})\""); + } + } + + protected void ValidateDomain() + { + var domainIP = RunCmd($"ping \"{Settings.Domain}\" -c 1" + @" | sed '1{s/[^(]*(//;s/).*//;q}'") + .Trim('\r', '\n'); + + if (IsOnlyIPv6) + { + Progress.Desc = ($"本机IP({IPv6})"); + if (IPv6 != domainIP) + { + //throw new Exception("域名解析地址与服务器IP不匹配!"); + } + } + else + { + Progress.Desc = ($"本机IP({IPv4})"); + Progress.Desc = ($"域名IP({domainIP})"); + if (IPv4 != domainIP) + { + //throw new Exception("域名解析地址与服务器IP不匹配!"); + } + } + } + + protected void EnableBBR() + { + Progress.Desc = ("检查系统是否满足启动BBR条件"); + var osVersion = RunCmd("uname -r"); + var canInstallBBR = CheckKernelVersionBBR(osVersion.Split('-')[0]); + + var bbrInfo = RunCmd("sysctl net.ipv4.tcp_congestion_control | grep bbr"); + var installed = bbrInfo.Contains("bbr"); + if (canInstallBBR && !installed) + { + RunCmd(@"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"); + RunCmd(@"sysctl -p"); + + if (IsOnlyIPv6) + { + RemoveNat64(); + } + Progress.Desc = ("启动BBR成功"); + } + + if (!canInstallBBR) + { + Progress.Desc = ("系统不满足启用BBR条件,启动失败。"); + } + + } + + /// + /// 安装证书 + /// + /// + /// + protected void InstallCert(string dirPath, string certName, string keyName) + { + string certPath = dirPath + "/" + certName; + string keyPath = dirPath + "/" + keyName; + + Progress.Desc = ("安装Acme软件"); + #region 安装Acme + // 安装依赖 + RunCmd(GetInstallCmd("socat")); + + // 解决搬瓦工CentOS缺少问题 + RunCmd(GetInstallCmd("automake autoconf libtool")); + + // 安装Acme + var result = RunCmd($"curl https://get.acme.sh yes | sh"); + if (!result.Contains("nstall success")) + { + throw new Exception("安装 Acme 失败,请联系开发者!"); + } + + RunCmd("alias acme.sh=~/.acme.sh/acme.sh"); + + #endregion + + + #region 申请证书 + Progress.Desc = ("正在申请证书"); + // 申请证书 + var cmd = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {Settings.Domain} {(IsOnlyIPv6 ? "--listen-v6" : "")} --pre-hook \"systemctl stop caddy\" --post-hook \"systemctl start caddy\" --server letsencrypt"; + result = RunCmd(cmd); + + + if (result.Contains("success")) + { + Progress.Desc = ("申请证书成功"); + } + else + { + Progress.Desc = ("申请证书失败,如果申请次数过多请更换二级域名,或联系开发者!"); + throw new Exception("申请证书失败,如果申请次数过多请更换二级域名,或联系开发者!"); + } + #endregion + + // 安装证书 + Progress.Desc = ("安装TLS证书"); + RunCmd($"mkdir -p {dirPath}"); + RunCmd($"/root/.acme.sh/acme.sh --installcert -d {Settings.Domain} --certpath {certPath} --keypath {keyPath} --capath {certPath}"); + + result = RunCmd($@"if [ ! -f ""{keyPath}"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"); + + if (result.Contains("1")) + { + Progress.Desc = ("安装证书成功"); + } + else + { + Progress.Desc = ("安装证书失败,请联系开发者!"); + throw new Exception("安装证书失败,请联系开发者!"); + } + + RunCmd($"chmod 755 {dirPath}"); + } + + protected void UploadFile(Stream stream, string path) + { + using (var sftp = new SftpClient(_sshClient.ConnectionInfo)) + { + sftp.Connect(); + sftp.UploadFile(stream, path, true); + sftp.Disconnect(); + } + } + + public void EnsureRootUser() + { + // 禁止一些可能产生的干扰信息 + RunCmd(@"sed -i 's/echo/#echo/g' ~/.bashrc"); + RunCmd(@"sed -i 's/echo/#echo/g' ~/.profile"); + + var result = RunCmd("id -u"); + if (!result.Equals("0\n")) + { + throw new Exception("请使用Root权限账户登录!"); + } + } + + public void UninstallCaddy() + { + Progress.Desc = "关闭Caddy服务"; + RunCmd("systemctl stop caddy"); + RunCmd("systemctl disable caddy"); + + Progress.Desc = "彻底删除Caddy文件"; + RunCmd("rm -rf /etc/systemd/system/caddy.service"); + RunCmd("rm -rf /usr/bin/caddy"); + RunCmd("rm -rf /usr/share/caddy"); + RunCmd("rm -rf /etc/caddy"); + } + + public void EnsureSystemEnv() + { + // cpu架构 + Progress.Desc = ("检测CPU架构"); + EnsureCPU(); + + // 安装命令类型 + Progress.Desc = ("检测系统安装命令"); + EnsureCmdType(); + + // systemctl + Progress.Desc = ("检测Systemctl"); + EnsureSystemctl(); + + // SELinux + Progress.Desc = ("检测SELinux"); + ConfigSELinux(); + } + + public void InstallSystemTools() + { + Progress.Desc = ("更新安装包"); + RunUpdateCmd(); + + Progress.Desc = ("安装sudo工具"); + InstallSoftware("sudo"); + + Progress.Desc = ("安装curl工具"); + InstallSoftware("curl"); + + Progress.Desc = ("安装wget工具"); + InstallSoftware("wget"); + + Progress.Desc = ("安装ping工具"); + InstallSoftware("ping"); + + Progress.Desc = ("安装unzip工具"); + InstallSoftware("unzip"); + + Progress.Desc = ("安装cron工具"); + InstallSoftware("cron"); + + Progress.Desc = ("安装lsof工具"); + InstallSoftware("lsof"); + + Progress.Desc = ("安装systemd工具"); + InstallSoftware("systemd"); + } + + public void ConfigFirewalld() + { + Progress.Desc = ("释放被占用的端口"); + Settings.FreePorts.ForEach(port => SetPortFree(port)); + + Progress.Desc = ("开放需要的端口"); + OpenPort(Settings.FreePorts.ToArray()); + } + + public void ResetFirewalld() + { + ClosePort(Settings.FreePorts.ToArray()); + } + + public void EnsureNetwork() + { + string cmd; + + Progress.Desc = ("检测IPv4"); + cmd = RunCmd(@"curl -4 ip.sb"); + IPv4 = cmd.TrimEnd('\r', '\n'); + + Progress.Desc = ($"IPv4地址为{IPv4}"); + if (!string.IsNullOrEmpty(IPv4)) + { + IsOnlyIPv6 = false; + } + else + { + Progress.Desc = ("检测IPv6"); + cmd = RunCmd(@"curl -6 ip.sb"); + IPv6 = cmd.TrimEnd('\r', '\n'); + Progress.Desc = ($"IPv6地址为{IPv6}"); + + IsOnlyIPv6 = true; + SetNat64(); + } + + if (string.IsNullOrEmpty(IPv4) && string.IsNullOrEmpty(IPv6)) + { + throw new Exception("未检测到服务器公网IP,请检查网络或重试。"); + } + } + + public void InstallCaddy() + { + RunCmd("rm -rf caddy.tar.gz"); + RunCmd("rm -rf /etc/caddy"); + RunCmd("rm -rf /usr/share/caddy"); + + var url = "https://github.com/caddyserver/caddy/releases/download/v2.4.3/caddy_2.4.3_linux_amd64.tar.gz"; + if (ArchType == ArchType.arm) + { + url = "https://github.com/caddyserver/caddy/releases/download/v2.4.3/caddy_2.4.3_linux_armv7.tar.gz"; + } + + RunCmd($"wget -O caddy.tar.gz {url}"); + RunCmd("mkdir -p /etc/caddy"); + RunCmd("tar -zxvf caddy.tar.gz -C /etc/caddy"); + RunCmd("cp -rf /etc/caddy/caddy /usr/bin"); + WriteToFile(Caddy.DefaultCaddyFile, "/etc/caddy/Caddyfile"); + WriteToFile(Caddy.Service, "/etc/systemd/system/caddy.service"); + RunCmd("systemctl daemon-reload"); + RunCmd("systemctl enable caddy"); + + RunCmd("mkdir -p /usr/share/caddy"); + RunCmd("chmod 775 /usr/share/caddy"); + + if (!FileExists("/usr/bin/caddy")) + { + throw new Exception("Caddy服务器安装失败,请联系开发者!"); + } + } + #endregion + + + #region 检测System环境 + private void EnsureCPU() + { + var result = RunCmd("uname -m"); + if (result.Contains("x86")) + { + ArchType = ArchType.x86; + } + else if (result.Contains("arm") || result.Contains("arch")) + { + ArchType = ArchType.arm; + } + } + + private void EnsureCmdType() + { + var result = string.Empty; + + if (CmdType == CmdType.None) + { + result = RunCmd("command -v apt"); + if (!string.IsNullOrEmpty(result)) + { + CmdType = CmdType.Apt; + } + } + + if (CmdType == CmdType.None) + { + result = RunCmd("command -v dnf"); + if (!string.IsNullOrEmpty(result)) + { + CmdType = CmdType.Dnf; + } + } + + if (CmdType == CmdType.None) + { + result = RunCmd("command -v yum"); + if (!string.IsNullOrEmpty(result)) + { + CmdType = CmdType.Yum; + } + } + + if (CmdType == CmdType.None) + { + throw new Exception("未检测到正确的系统安装命令,请尝试使用ProxySU推荐的系统版本安装!"); + } + } + + private void EnsureSystemctl() + { + var result = RunCmd("command -v systemctl"); + if (string.IsNullOrEmpty(result)) + { + throw new Exception("系统缺少 systemctl 组件,请尝试使用ProxySU推荐的系统版本安装!"); + } + } + + private void ConfigSELinux() + { + // SELinux + var result = RunCmd("command -v getenforce"); + var isSELinux = !string.IsNullOrEmpty(result); + + // 判断是否启用了SELinux,如果启用了,并且工作在Enforcing模式下,则改为Permissive模式 + if (isSELinux) + { + result = RunCmd("getenforce"); + + // 检测到系统启用SELinux,且工作在严格模式下,需改为宽松模式 + if (result.Contains("Enforcing")) + { + RunCmd("setenforce 0"); + RunCmd(@"sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config"); + } + } + } + #endregion + + + #region 私有方法 + + protected void SetNat64() + { + var dns64List = FilterFastestIP(); + if (dns64List.Count == 0) + { + throw new Exception("未找到有效的Nat64网关"); + } + + var exists = FileExists("/etc/resolv.conf.proxysu"); + if (!exists) + { + var cmdStr = @"mv /etc/resolv.conf /etc/resolv.conf.proxysu"; + RunCmd(cmdStr); + } + + foreach (var gateip in dns64List) + { + RunCmd($"echo \"nameserver {gateip}\" > /etc/resolv.conf"); + } + } + + protected void RemoveNat64() + { + RunCmd("rm /etc/resolv.conf"); + RunCmd("mv /etc/resolv.conf.proxysu /etc/resolv.conf"); + } + + protected void AppendCommand(string command) + { + if (!command.EndsWith("\n")) + { + command += "\n"; + } + Progress.Logs += command; + } + + private List FilterFastestIP() + { + string[] gateNat64 = { + "2a01:4f9:c010:3f02::1", + "2001:67c:2b0::4", + "2001:67c:2b0::6", + "2a09:11c0:f1:bbf0::70", + "2a01:4f8:c2c:123f::1", + "2001:67c:27e4:15::6411", + "2001:67c:27e4::64", + "2001:67c:27e4:15::64", + "2001:67c:27e4::60", + "2a00:1098:2b::1", + "2a03:7900:2:0:31:3:104:161", + "2a00:1098:2c::1", + "2a09:11c0:100::53", + }; + + Dictionary dns64List = new Dictionary(); + foreach (var gateip in gateNat64) + { + var cmdStr = $"ping6 -c4 {gateip} | grep avg | awk '{{print $4}}'|cut -d/ -f2"; + var cmd = RunCmd(cmdStr); + if (!string.IsNullOrEmpty(cmd)) + { + if (float.TryParse(cmd, out float delay)) + { + dns64List.Add(gateip, delay); + } + } + } + + //return dns64List.Keys.ToList(); + return dns64List.OrderBy(kv => kv.Value).Select(kv => kv.Key).ToList(); + + } + + private bool CheckKernelVersionBBR(string kernelVer) + { + string[] linuxKernelCompared = kernelVer.Split('.'); + if (int.Parse(linuxKernelCompared[0]) > 4) + { + return true; + } + else if (int.Parse(linuxKernelCompared[0]) < 4) + { + return false; + } + else if (int.Parse(linuxKernelCompared[0]) == 4) + { + if (int.Parse(linuxKernelCompared[1]) >= 9) + { + return true; + } + else if (int.Parse(linuxKernelCompared[1]) < 9) + { + return false; + } + + } + return false; + + } + + private void SetPortFree(int port) + { + string result = RunCmd($"lsof -n -P -i :{port} | grep LISTEN"); + + if (!string.IsNullOrEmpty(result)) + { + string[] process = result.Split(' '); + RunCmd($"systemctl stop {process[0]}"); + RunCmd($"systemctl disable {process[0]}"); + RunCmd($"pkill {process[0]}"); + } + } + + private void OpenPort(params int[] portList) + { + string cmd; + + cmd = RunCmd("command -v firewall-cmd"); + if (!string.IsNullOrEmpty(cmd)) + { + //有很奇怪的vps主机,在firewalld未运行时,端口是关闭的,无法访问。所以要先启动firewalld + //用于保证acme.sh申请证书成功 + cmd = RunCmd("firewall-cmd --state"); + if (cmd.Trim() != "running") + { + RunCmd("systemctl restart firewalld"); + } + + // 保持 ssh 端口开放 + RunCmd($"firewall-cmd --add-port={_host.Port}/tcp --permanent"); + foreach (var port in portList) + { + RunCmd($"firewall-cmd --add-port={port}/tcp --permanent"); + RunCmd($"firewall-cmd --add-port={port}/udp --permanent"); + } + + RunCmd("yes | firewall-cmd --reload"); + } + else + { + cmd = RunCmd("command -v ufw"); + if (string.IsNullOrEmpty(cmd)) + { + RunCmd(GetInstallCmd("ufw")); + RunCmd("echo y | ufw enable"); + } + + // 保持 ssh 端口开放 + RunCmd($"ufw allow {_host.Port}/tcp"); + foreach (var port in portList) + { + RunCmd($"ufw allow {port}/tcp"); + RunCmd($"ufw allow {port}/udp"); + } + RunCmd("yes | ufw reload"); + } + } + + private void ClosePort(params int[] portList) + { + string cmd; + + cmd = RunCmd("command -v firewall-cmd"); + if (!string.IsNullOrEmpty(cmd)) + { + //有很奇怪的vps主机,在firewalld未运行时,端口是关闭的,无法访问。所以要先启动firewalld + //用于保证acme.sh申请证书成功 + cmd = RunCmd("firewall-cmd --state"); + if (cmd.Trim() != "running") + { + RunCmd("systemctl restart firewalld"); + } + + foreach (var port in portList) + { + RunCmd($"firewall-cmd --remove-port={port}/tcp --permanent"); + RunCmd($"firewall-cmd --remove-port={port}/udp --permanent"); + } + RunCmd("yes | firewall-cmd --reload"); + } + else + { + cmd = RunCmd("command -v ufw"); + if (!string.IsNullOrEmpty(cmd)) + { + foreach (var port in portList) + { + RunCmd($"ufw delete allow {port}/tcp"); + RunCmd($"ufw delete allow {port}/udp"); + } + RunCmd("yes | ufw reload"); + } + } + } + + private void InstallSoftware(string software) + { + var result = RunCmd($"command -v {software}"); + if (string.IsNullOrEmpty(result)) + { + RunCmd(GetInstallCmd(software)); + } + } + + private string GetInstallCmd(string soft) + { + if (CmdType == CmdType.Apt) + { + return $"apt install -y {soft}"; + } + else if (CmdType == CmdType.Yum) + { + return $"yum install -y {soft}"; + } + else + { + return $"dnf install -y {soft}"; + } + } + + private void RunUpdateCmd() + { + if (CmdType == CmdType.Apt) + { + RunCmd($"apt update -y"); + } + else if (CmdType == CmdType.Yum) + { + RunCmd($"yum update -y"); + } + else + { + RunCmd($"dnf update -y"); + } + } + + + private ConnectionInfo CreateConnectionInfo() + { + try + { + var authMethods = new List(); + + if (_host.SecretType == LoginSecretType.Password) + { + authMethods.Add(new PasswordAuthenticationMethod(_host.UserName, _host.Password)); + } + + if (_host.SecretType == LoginSecretType.PrivateKey) + { + PrivateKeyFile keyFile; + if (string.IsNullOrEmpty(_host.PrivateKeyPassPhrase)) + { + keyFile = new PrivateKeyFile(_host.PrivateKeyPath); + } + else + { + keyFile = new PrivateKeyFile(_host.PrivateKeyPath, _host.PrivateKeyPassPhrase); + } + authMethods.Add(new PrivateKeyAuthenticationMethod(_host.UserName, keyFile)); + } + + if (_host.Proxy.Type == ProxyTypes.None) + { + return new ConnectionInfo( + host: _host.Address, + username: _host.UserName, + port: _host.Port, + authenticationMethods: authMethods.ToArray()); + } + + return new ConnectionInfo( + host: _host.Address, + port: _host.Port, + username: _host.UserName, + proxyType: _host.Proxy.Type, + proxyHost: _host.Proxy.Address, + proxyPort: _host.Proxy.Port, + proxyUsername: _host.Proxy.UserName, + proxyPassword: _host.Proxy.Password, + authenticationMethods: authMethods.ToArray()); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return null; + } + } + #endregion + } +} diff --git a/ProxySuper.Core/Services/ShareLink.cs b/ProxySuper.Core/Services/ShareLink.cs new file mode 100644 index 00000000..deecf28e --- /dev/null +++ b/ProxySuper.Core/Services/ShareLink.cs @@ -0,0 +1,488 @@ + +using Newtonsoft.Json; +using ProxySuper.Core.Models.Projects; +using System; +using System.Net; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Web; + +namespace ProxySuper.Core.Services +{ + public class ShareLink + { + public static string BuildHysteria(HysteriaSettings settings) + { + //hysteria2://[auth@]hostname[:port]/?[key=value]&[key=value]... + //hysteria2://letmein@example.com:123,5000-6000/?insecure=1&obfs=salamander&obfs-password=gawrgura&pinSHA256=deadbeef&sni=real.example.com + var auth = HttpUtility.UrlEncode(settings.Password); + + if (settings.EnableObfs == true) + { + //var _obfsPassword = settings.ObfsPassword; + return $"hysteria2://{auth}@{settings.Domain}:{settings.Port}/?obfs=salamander&obfs-password={settings.ObfsPassword}"; + } + return $"hysteria2://{auth}@{settings.Domain}:{settings.Port}"; + + } + public static string BuildBrook(BrookSettings settings) + { + var password = HttpUtility.UrlEncode(settings.Password); + + if (settings.BrookType == BrookType.server) + { + var address = HttpUtility.UrlEncode($"{settings.IP}:{settings.Port}"); + return $"brook://server?password={password}&server={address}"; + } + + if (settings.BrookType == BrookType.wsserver) + { + var address = HttpUtility.UrlEncode($"ws://{settings.IP}:{settings.Port}"); + return $"brook://wsserver?password={password}&wsserver={address}"; + } + + if (settings.BrookType == BrookType.wssserver) + { + var address = HttpUtility.UrlEncode($"wss://{settings.Domain}:{settings.Port}"); + return $"brook://wssserver?password={password}&wssserver={address}"; + } + + if (settings.BrookType == BrookType.socks5) + { + var address = HttpUtility.UrlEncode($"socks5://{settings.IP}:{settings.Port}"); + return $"brook://socks5?password={password}&socks5={address}"; + } + + return string.Empty; + } + + public static string BuildNaiveProxy(NaiveProxySettings settings) + { + StringBuilder strBuilder = new StringBuilder(); + strBuilder.Append("naive+https://"); + strBuilder.Append($"{settings.UserName}:{settings.Password}"); + strBuilder.Append($"@{settings.Domain}:{settings.Port}"); + strBuilder.Append("?padding=true#naive_proxy"); + + return strBuilder.ToString(); + } + + public static string BuildTrojanGo(TrojanGoSettings settings) + { + StringBuilder strBuilder = new StringBuilder(); + strBuilder.Append("trojan-go://"); + + strBuilder.Append($"{HttpUtility.UrlEncode(settings.Password)}@{settings.Domain}:{settings.Port}/?"); + if (settings.EnableWebSocket) + { + strBuilder.Append($"type=ws&path={HttpUtility.UrlEncode(settings.WebSocketPath)}&"); + } + else + { + strBuilder.Append("type=original&"); + } + strBuilder.Append($"#{HttpUtility.UrlEncode("trojan-go")}"); + + return strBuilder.ToString(); + } + + #region V2Ray ShareLink + public static string Build(V2RayType v2rayType, V2raySettings settings) + { + + switch (v2rayType) + { + case V2RayType.VLESS_TCP: + //case RayType.VLESS_RAW_XTLS: + case V2RayType.VLESS_WS: + case V2RayType.VLESS_KCP: + case V2RayType.VLESS_QUIC: + case V2RayType.VLESS_gRPC: + case V2RayType.Trojan_TCP: + return BuildVlessShareLink(v2rayType, settings); + case V2RayType.VMESS_TCP: + case V2RayType.VMESS_WS: + case V2RayType.VMESS_KCP: + case V2RayType.VMESS_QUIC: + return BuildVmessShareLink(v2rayType, settings); + case V2RayType.ShadowsocksAEAD: + return BuildShadowSocksShareLink(settings); + default: + return string.Empty; + } + } + + private static string BuildShadowSocksShareLink(V2raySettings settings) + { + var _method = settings.ShadowSocksMethod; + var _password = settings.ShadowSocksPassword; + var _server = settings.Domain; + var _port = settings.ShadowSocksPort; + + var base64URL = Utils.Base64Encode($"{_method}:{_password}@{_server}:{_port}"); + return "ss://" + base64URL + "#ShadowSocks"; + } + + private static string BuildVmessShareLink(V2RayType v2rayType, V2raySettings settings) + { + var vmess = new Vmess + { + v = "2", + add = settings.Domain, + port = settings.Port.ToString(), + id = settings.UUID, + aid = "0", + net = "", + type = "none", + host = "", + path = "", + tls = "tls", + ps = "", + }; + + switch (v2rayType) + { + case V2RayType.VMESS_TCP: + vmess.ps = "vmess-tcp-tls"; + vmess.net = "tcp"; + vmess.type = "http"; + vmess.path = settings.VMESS_TCP_Path; + break; + case V2RayType.VMESS_WS: + vmess.ps = "vmess-ws-tls"; + vmess.net = "ws"; + vmess.type = "none"; + vmess.path = settings.VMESS_WS_Path; + break; + case V2RayType.VMESS_KCP: + vmess.ps = "vmess-mKCP"; + vmess.port = settings.VMESS_KCP_Port.ToString(); + vmess.net = "kcp"; + vmess.type = settings.VMESS_KCP_Type; + vmess.path = settings.VMESS_KCP_Seed; + vmess.tls = ""; + break; + case V2RayType.VMESS_QUIC: + vmess.ps = "vmess-quic"; + vmess.port = settings.VMESS_QUIC_Port.ToString(); + vmess.net = "quic"; + vmess.type = settings.VMESS_QUIC_Type; + vmess.path = settings.VMESS_QUIC_Key; + vmess.host = settings.VMESS_QUIC_Security; + vmess.tls = "tls"; + break; + default: + return string.Empty; + } + + var base64Url = Utils.Base64Encode(JsonConvert.SerializeObject(vmess)); + return $"vmess://" + base64Url; + } + + private static string BuildVlessShareLink(V2RayType v2rayType, V2raySettings settings) + { + var _protocol = string.Empty; + var _uuid = settings.UUID; + var _domain = settings.Domain; + var _port = settings.Port; + var _type = string.Empty; + var _encryption = "none"; + var _security = "tls"; + var _path = "/"; + var _host = settings.Domain; + var _descriptiveText = string.Empty; + + switch (v2rayType) + { + case V2RayType.VLESS_TCP: + _protocol = "vless"; + _type = "tcp"; + _descriptiveText = "vless-tcp-tls"; + break; + //case RayType.VLESS_RAW_XTLS: + // _protocol = "vless"; + // _type = "tcp"; + // _security = "tls"; + // _descriptiveText = "vless-tcp-xtls"; + // break; + case V2RayType.VLESS_WS: + _protocol = "vless"; + _type = "ws"; + _path = settings.VLESS_WS_Path; + _descriptiveText = "vless-ws-tls"; + break; + case V2RayType.VLESS_KCP: + _protocol = "vless"; + _type = "kcp"; + _port = settings.VLESS_KCP_Port; + _security = "none"; + _descriptiveText = "vless-mKCP"; + break; + case V2RayType.VLESS_QUIC: + _protocol = "vless"; + _port = settings.VLESS_QUIC_Port; + _type = "quic"; + _security = "tls"; + _descriptiveText = "vless-quic"; + break; + case V2RayType.VLESS_gRPC: + _protocol = "vless"; + _type = "grpc"; + _port = settings.VLESS_gRPC_Port; + _descriptiveText = "vless-gRPC"; + break; + case V2RayType.Trojan_TCP: + _protocol = "trojan"; + _uuid = settings.TrojanPassword; + _descriptiveText = "trojan-tcp"; + break; + default: + throw new Exception("暂未实现的协议"); + } + + + string parametersURL = string.Empty; + if (v2rayType != V2RayType.Trojan_TCP) + { + // 4.3 传输层相关段 + parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&path={HttpUtility.UrlEncode(_path)}"; + + // kcp + if (v2rayType == V2RayType.VLESS_KCP) + { + parametersURL += $"&seed={settings.VLESS_KCP_Seed}&headerType={settings.VLESS_KCP_Type}"; + } + + if (v2rayType == V2RayType.VLESS_QUIC) + { + parametersURL += $"&quicSecurity={settings.VLESS_QUIC_Security}"; + if (settings.VLESS_QUIC_Security != "none") + { + parametersURL += $"&key={HttpUtility.UrlEncode(settings.VLESS_QUIC_Key)}"; + } + parametersURL += $"&headerType={settings.VLESS_QUIC_Type}"; + } + /* + // 4.4 TLS 相关段 + if (settings is XraySettings) + { + if (v2rayType == RayType.VLESS_RAW_XTLS) + { + var xraySettings = settings as XraySettings; + parametersURL += $"&flow={xraySettings.Flow}"; + } + } + */ + + if (v2rayType == V2RayType.VLESS_gRPC) + { + parametersURL += $"&serviceName={settings.VLESS_gRPC_ServiceName}&mode=gun"; + } + } + + + return $"{_protocol}://{HttpUtility.UrlEncode(_uuid)}@{_domain}:{_port}{parametersURL}#{HttpUtility.UrlEncode(_descriptiveText)}"; + } + + #endregion + + #region Xray ShareLink + public static string XrayBuild(XrayType xrayType, XraySettings settings) + { + + switch (xrayType) + { + case XrayType.VLESS_RAW_XTLS: + case XrayType.VLESS_XTLS_RAW_REALITY: + case XrayType.VLESS_XHTTP: + case XrayType.VLESS_WS: + case XrayType.VLESS_gRPC: + case XrayType.Trojan_TCP: + return XrayBuildVlessShareLink(xrayType, settings); + + case XrayType.VMESS_KCP: + return XrayBuildVmessShareLink(xrayType, settings); + case XrayType.ShadowsocksAEAD: + return XrayBuildShadowSocksShareLink(settings); + default: + return string.Empty; + } + } + + private static string XrayBuildShadowSocksShareLink(XraySettings settings) + { + var _method = settings.ShadowSocksMethod; + var _password = settings.ShadowSocksPassword; + var _server = settings.Domain; + var _port = settings.ShadowSocksPort; + + var base64URL = Utils.Base64Encode($"{_method}:{_password}@{_server}:{_port}"); + return "ss://" + base64URL + "#ShadowSocks"; + } + + private static string XrayBuildVmessShareLink(XrayType xrayType, XraySettings settings) + { + var vmess = new Vmess + { + v = "2", + add = settings.Domain, + port = settings.Port.ToString(), + id = settings.UUID, + aid = "0", + net = "", + type = "none", + host = "", + path = "", + tls = "tls", + ps = "", + }; + + switch (xrayType) + { + case XrayType.VMESS_KCP: + vmess.ps = "vmess-mKCP"; + vmess.port = settings.VMESS_KCP_Port.ToString(); + vmess.net = "kcp"; + vmess.type = settings.VMESS_KCP_Type; + vmess.path = settings.VMESS_KCP_Seed; + vmess.tls = ""; + break; + + default: + return string.Empty; + } + + var base64Url = Utils.Base64Encode(JsonConvert.SerializeObject(vmess)); + return $"vmess://" + base64Url; + } + + private static string XrayBuildVlessShareLink(XrayType xrayType, XraySettings settings) + { + var _protocol = string.Empty; + var _uuid = settings.UUID; + var _domain = settings.Domain; + var _port = settings.Port; + var _type = string.Empty; + var _encryption = "none"; + var _security = "tls"; + var _path = "/"; + var _host = settings.Domain; + var _descriptiveText = string.Empty; + + var _flow = settings.Flow; + var _sni = settings.MaskDomain; + var _fingerprint = settings.UTLS; + var _publicKey = settings.REALITY_publicKey; + var _spiderX = settings.REALITY_spiderX; + var _headerType = "none"; + + var _alpn = string.Empty; + var _mode = string.Empty; + + switch (xrayType) + { + case XrayType.VLESS_XTLS_RAW_REALITY: + _protocol = "vless"; + _type = "tcp"; + _security = "reality"; + _flow = settings.Flow; + _sni = settings.MaskDomain; + _fingerprint = settings.UTLS; + _publicKey = settings.REALITY_publicKey; + _spiderX = settings.REALITY_spiderX; + _headerType = "none"; + _host = settings.MaskDomain; + _descriptiveText = "vless-xtls-reality"; + break; + case XrayType.VLESS_RAW_XTLS: + _protocol = "vless"; + _type = "tcp"; + _security = "tls"; + _descriptiveText = "vless-tcp-xtls"; + break; + case XrayType.VLESS_XHTTP: + _protocol = "vless"; + _type = "xhttp"; + _path = settings.VLESS_XHTTP_Path; + _alpn = "h3,h2,http/1.1"; + _mode = "packet-up"; + _descriptiveText = "vless-xhttp"; + break; + case XrayType.VLESS_WS: + _protocol = "vless"; + _type = "ws"; + _path = settings.VLESS_WS_Path; + _descriptiveText = "vless-ws-tls"; + break; + case XrayType.VLESS_gRPC: + _protocol = "vless"; + _type = "grpc"; + _port = settings.VLESS_gRPC_Port; + _descriptiveText = "vless-gRPC"; + break; + case XrayType.Trojan_TCP: + _protocol = "trojan"; + _uuid = settings.TrojanPassword; + _descriptiveText = "trojan-tcp"; + break; + default: + throw new Exception("暂未实现的协议"); + } + + + string parametersURL = string.Empty; + if (xrayType != XrayType.Trojan_TCP && xrayType != XrayType.VLESS_XTLS_RAW_REALITY) + { + // 4.3 传输层相关段 + parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&path={HttpUtility.UrlEncode(_path)}"; + + // xhttp + if (xrayType == XrayType.VLESS_XHTTP) + { + parametersURL += $"&alpn={HttpUtility.UrlEncode(_alpn)}&mode={_mode}"; + } + + + // 4.4 TLS 相关段 + + if (xrayType == XrayType.VLESS_RAW_XTLS) + { + + parametersURL += $"&flow={settings.Flow}"; + } + + if (xrayType == XrayType.VLESS_gRPC) + { + parametersURL += $"&serviceName={settings.VLESS_gRPC_ServiceName}&mode=gun"; + } + } + + if (xrayType == XrayType.VLESS_XTLS_RAW_REALITY) + { + parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&flow={_flow}&sni={_sni}&fp={_fingerprint}&pbk={_publicKey}&spx={HttpUtility.UrlEncode(_spiderX)}&headerType={_headerType}&host={_host}"; + + } + + return $"{_protocol}://{HttpUtility.UrlEncode(_uuid)}@{_domain}:{_port}{parametersURL}#{HttpUtility.UrlEncode(_descriptiveText)}"; + } + #endregion + + } + + + + class Vmess + { + public string v { get; set; } + public string ps { get; set; } + public string add { get; set; } + public string port { get; set; } + public string id { get; set; } + public string aid { get; set; } + public string net { get; set; } + public string type { get; set; } + public string host { get; set; } + public string path { get; set; } + public string tls { get; set; } + } +} diff --git a/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs b/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs new file mode 100644 index 00000000..4aab35e8 --- /dev/null +++ b/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs @@ -0,0 +1,67 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Templates; +using System.IO; + +namespace ProxySuper.Core.Services +{ + public class TrojanGoConfigBuilder + { + public static readonly int WebPort = 8088; + + public static readonly string TrojanGoSettingPath = TrojanGoTemplates.TrojanGoJson; + + public static readonly string CaddyFilePath = TrojanGoTemplates.BaseCaddyfile; + + public static string BuildTrojanGoConfig(TrojanGoSettings parameters) + { + var jsonStr = TrojanGoSettingPath; + var settings = JToken.FromObject(JsonConvert.DeserializeObject(jsonStr)); + + settings["remote_port"] = WebPort; + settings["password"][0] = parameters.Password; + settings["ssl"]["sni"] = parameters.Domain; + + if (parameters.EnableWebSocket) + { + settings["websocket"]["enabled"] = true; + settings["websocket"]["path"] = parameters.WebSocketPath; + settings["websocket"]["host"] = parameters.Domain; + } + + return JsonConvert.SerializeObject(settings, Formatting.Indented, new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }); + } + + public static string BuildCaddyConfig(TrojanGoSettings parameters, bool useCustomWeb = false) + { + var caddyStr = CaddyFilePath; + caddyStr = caddyStr.Replace("##domain##", parameters.Domain); + caddyStr = caddyStr.Replace("##port##", WebPort.ToString()); + + if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) + { + var prefix = "http://"; + if (parameters.MaskDomain.StartsWith("https://")) + { + prefix = "https://"; + } + var domain = parameters.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()); + + caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {prefix}{domain} {{ \n header_up Host {domain} \n }}"); + } + else + { + caddyStr = caddyStr.Replace("##reverse_proxy##", ""); + } + + return caddyStr; + } + } + +} diff --git a/ProxySuper.Core/Services/TrojanGoService.cs b/ProxySuper.Core/Services/TrojanGoService.cs new file mode 100644 index 00000000..5a37d2e8 --- /dev/null +++ b/ProxySuper.Core/Services/TrojanGoService.cs @@ -0,0 +1,401 @@ +using Microsoft.Win32; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class TrojanGoService : ServiceBase + { + public TrojanGoService(Host host, TrojanGoSettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "安装TrojanGo"; + Progress.Desc = "安装TrojanGo"; + EnsureRootUser(); + + if (FileExists("/usr/local/bin/trojan-go")) + { + var btnResult = MessageBox.Show("已经安装Trojan-Go,是否需要重装?", "提示", MessageBoxButton.YesNo); + if (btnResult == MessageBoxResult.No) + { + MessageBox.Show("安装终止", "提示"); + return; + } + } + + var index = 1; + Progress.Step = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 10; + + Progress.Step = $"{index++}. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 检测域名是否解析到本机"; + ValidateDomain(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 安装Caddy服务"; + InstallCaddy(); + Progress.Percentage = 70; + + Progress.Step = $"{index++}. 安装TrojanGo"; + InstallTrojanGo(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 上传Caddy配置文件"; + UploadCaddySettings(); + Progress.Percentage = 90; + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Step = $"{index++}. 重启caddy服务"; + RunCmd("systemctl restart caddy"); + + Progress.Desc = "启用Trojan-Go开机启动"; + RunCmd("systemctl enable trojan-go"); + RunCmd("systemctl restart trojan-go"); + + AppendCommand("分享连接:"); + AppendCommand(ShareLink.BuildTrojanGo(Settings)); + + Progress.Percentage = 100; + Progress.Step = "安装成功"; + Progress.Desc = string.Empty; + + if (!Settings.WithTLS) + { + Progress.Step = "安装成功,请上传您的 TLS 证书。"; + } + else + { + NavigationService.Navigate(Settings); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "卸载Trojgan-Go"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "停止Trojan—Go服务"; + RunCmd("systemctl stop trojan-go"); + Progress.Percentage = 40; + + + Progress.Desc = "卸载Caddy"; + UninstallCaddy(); + Progress.Percentage = 60; + + Progress.Desc = "卸载Trojan-Go"; + RunCmd("rm -rf /usr/local/bin/trojan-go"); + RunCmd("rm -rf /usr/local/etc/trojan-go"); + Progress.Percentage = 90; + + Progress.Desc = "删除 acme.sh"; + RunCmd("acme.sh --uninstall"); + RunCmd("rm -r ~/.acme.sh"); + + Progress.Percentage = 100; + Progress.Step = "卸载Trojan-Go成功"; + Progress.Desc = string.Empty; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新配置文件"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 30; + + Progress.Desc = "更新配置文件"; + UploadTrojanGoSettings(); + Progress.Percentage = 70; + + Progress.Desc = "重启caddy服务"; + RunCmd("systemctl restart caddy"); + Progress.Percentage = 80; + + Progress.Desc = "重启Trojan-Go服务器"; + RunCmd("systemctl restart trojan-go"); + + Progress.Percentage = 100; + Progress.Desc = "更新配置成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + public void UploadCert() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadCert; + fileDialog.ShowDialog(); + } + + public void ApplyForCert() + { + Task.Factory.StartNew(() => + { + try + { + + Progress.Step = "续签证书"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "安装TLS证书"; + InstallCert( + dirPath: "/usr/local/etc/trojan-go", + certName: "trojan-go.crt", + keyName: "trojan-go.key"); + Progress.Percentage = 90; + + Progress.Desc = "重启Trojan-go服务"; + RunCmd("systemctl restart trojan-go"); + + Progress.Percentage = 100; + Progress.Step = "续签证书成功"; + Progress.Desc = "续签证书成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + #region 私有方法 + + + private void DoUploadCert(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Percentage = 0; + Progress.Step = "上传自有证书"; + Progress.Desc = "检测系统环境"; + + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + var oldFileName = $"ssl_{DateTime.Now.Ticks}"; + RunCmd($"mv /usr/local/etc/trojan-go/ssl /usr/local/etc/trojan-go/{oldFileName}"); + + RunCmd("mkdir -p /usr/local/etc/trojan-go/ssl"); + UploadFile(stream, "/usr/local/etc/trojan-go/ssl/ssl.zip"); + RunCmd("unzip /usr/local/etc/trojan-go/ssl/ssl.zip -d /usr/local/etc/trojan-go/ssl"); + } + + var crtFiles = RunCmd("find /usr/local/etc/trojan-go/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + var keyFiles = RunCmd("find /usr/local/etc/trojan-go/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (crtFiles.Length > 0 && keyFiles.Length > 0) + { + RunCmd($"mv {crtFiles[0]} /usr/local/etc/trojan-go/ssl/trojan-go.crt"); + RunCmd($"mv {keyFiles[0]} /usr/local/etc/trojan-go/ssl/trojan-go.key"); + } + else + { + Progress.Step = "上传失败"; + Progress.Desc = "上传证书失败,缺少 .crt 和 .key 文件"; + return; + } + + Progress.Desc = "重启trojan-go服务"; + RunCmd("systemctl restart trojan-go"); + + Progress.Percentage = 100; + Progress.Desc = "上传证书完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir -p /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 700; + } + + Progress.Desc = "上传Caddy配置文件"; + UploadCaddySettings(useCustomWeb: true); + Progress.Percentage = 90; + + Progress.Desc = "重启caddy服务"; + RunCmd("systemctl restart caddy"); + Progress.Percentage = 100; + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void UploadCaddySettings(bool useCustomWeb = false) + { + var config = TrojanGoConfigBuilder.BuildCaddyConfig(Settings, useCustomWeb); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(config)); + if (FileExists("/etc/caddy/Caddyfile")) + { + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + } + UploadFile(stream, "/etc/caddy/Caddyfile"); + } + + private void InstallTrojanGo() + { + RunCmd(@"curl https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh yes | bash"); + var success = FileExists("/usr/local/bin/trojan-go"); + if (success == false) + { + throw new Exception("trojan-go 安装失败,请联系开发者!"); + } + + Progress.Desc = "设置Trojan-Go权限"; + RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"systemctl daemon-reload"); + + if (Settings.WithTLS) + { + Progress.Desc = "安装TLS证书"; + InstallCert( + dirPath: "/usr/local/etc/trojan-go/ssl", + certName: "trojan-go.crt", + keyName: "trojan-go.key"); + } + + Progress.Desc = "上传Trojan-Go配置文件"; + UploadTrojanGoSettings(); + } + + private void UploadTrojanGoSettings() + { + // 上传配置 + Progress.Desc = "生成配置文件"; + var settings = TrojanGoConfigBuilder.BuildTrojanGoConfig(Settings); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(settings)); + + Progress.Desc = "正在上传配置文件"; + UploadFile(stream, "/usr/local/etc/trojan-go/config.json"); + + } + + #endregion + + + } +} diff --git a/ProxySuper.Core/Services/V2rayConfigBuilder.cs b/ProxySuper.Core/Services/V2rayConfigBuilder.cs new file mode 100644 index 00000000..11885fd0 --- /dev/null +++ b/ProxySuper.Core/Services/V2rayConfigBuilder.cs @@ -0,0 +1,264 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Templates; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Services +{ + public class V2rayConfigBuilder + { + private static string ServerLog = V2rayConfigTemplates.ServerGeneralConfig_log; + private static string ServerDns = V2rayConfigTemplates.ServerGeneralConfig_dns; + private static string ServerRouting = V2rayConfigTemplates.ServerGeneralConfig_routing_BlockPrivateIP; + private static string ServerInbounds = V2rayConfigTemplates.ServerGeneralConfig_inbounds; + private static string ServerOutbounds = V2rayConfigTemplates.ServerGeneralConfig_outbounds; + private static string CaddyFile = CaddyFiles.BaseCaddyFile; + + public static int VLESS_TCP_Port = 1110; + public static int VLESS_WS_Port = 1111; + public static int VLESS_H2_Port = 1112; + + public static int VMESS_TCP_Port = 1210; + public static int VMESS_WS_Port = 1211; + public static int VMESS_H2_Port = 1212; + + public static int Trojan_TCP_Port = 1310; + public static int Trojan_WS_Port = 1311; + + public static int FullbackPort = 8080; + + + + public static dynamic LoadV2rayConfig() + { + + dynamic logObj = LoadJsonObj(ServerLog); + dynamic dnsObj = LoadJsonObj(ServerDns); + dynamic routingObj = LoadJsonObj(ServerRouting); + dynamic inboundsObj = LoadJsonObj(ServerInbounds); + dynamic outboundsObj = LoadJsonObj(ServerOutbounds); + + return new + { + log = logObj["log"], + dns = dnsObj["dns"], + routing = routingObj["routing"], + inbounds = inboundsObj["inbounds"], + outbounds = outboundsObj["outbounds"] + }; + } + + public static string BuildCaddyConfig(V2raySettings parameters, bool useCustomWeb = false) + { + var caddyStr = CaddyFile;// File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile")); + caddyStr = caddyStr.Replace("##domain##", parameters.IsIPAddress ? "" : parameters.Domain); + caddyStr = caddyStr.Replace("##port##", FullbackPort.ToString()); + + if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) + { + var prefix = "http://"; + if (parameters.MaskDomain.StartsWith("https://")) + { + prefix = "https://"; + } + var domain = parameters.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()); + + caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {prefix}{domain} {{ \n header_up Host {domain} \n }}"); + } + else + { + caddyStr = caddyStr.Replace("##reverse_proxy##", ""); + } + + return caddyStr; + } + + private static void SetClients(dynamic bound, List uuidList) + { + bound.settings.clients.Clear(); + uuidList.ForEach(id => + { + object obj; + + obj = new { id = id }; + + bound.settings.clients.Add(JToken.FromObject(obj)); + }); + } + + + public static string BuildV2rayConfig(V2raySettings parameters) + { + var uuidList = new List(); + uuidList.Add(parameters.UUID); + uuidList.AddRange(parameters.MulitUUID); + + var xrayConfig = LoadV2rayConfig(); + + var baseBound = LoadJsonObj(V2rayConfigTemplates.VLESS_TCP_TLS_ServerConfig);//GetBound("VLESS_TCP_TLS.json"); + baseBound.port = parameters.Port; + baseBound.settings.fallbacks.Add(JToken.FromObject(new + { + dest = FullbackPort + })); + xrayConfig.inbounds.Add(baseBound); + SetClients(baseBound, uuidList); + + #region Fullbacks + + if (parameters.Types.Contains(V2RayType.VLESS_WS)) + { + var wsInbound = LoadJsonObj(V2rayConfigTemplates.VLESS_WS_ServerConfig); //GetBound("VLESS_WS.json"); + wsInbound.port = VLESS_WS_Port; + SetClients(wsInbound, uuidList); + wsInbound.streamSettings.wsSettings.path = parameters.VLESS_WS_Path; + baseBound.settings.fallbacks.Add(JToken.FromObject(new + { + dest = VLESS_WS_Port, + path = parameters.VLESS_WS_Path, + xver = 1, + })); + xrayConfig.inbounds.Add(JToken.FromObject(wsInbound)); + } + + if (parameters.Types.Contains(V2RayType.VMESS_TCP)) + { + var mtcpBound = LoadJsonObj(V2rayConfigTemplates.VMESS_TCP_ServerConfig); //GetBound("VMESS_TCP.json"); + mtcpBound.port = VMESS_TCP_Port; + SetClients(mtcpBound, uuidList); + mtcpBound.streamSettings.tcpSettings.header.request.path = parameters.VMESS_TCP_Path; + baseBound.settings.fallbacks.Add(JToken.FromObject(new + { + dest = VMESS_TCP_Port, + path = parameters.VMESS_TCP_Path, + xver = 1, + })); + xrayConfig.inbounds.Add(JToken.FromObject(mtcpBound)); + } + + if (parameters.Types.Contains(V2RayType.VMESS_WS)) + { + var mwsBound = LoadJsonObj(V2rayConfigTemplates.VMESS_WS_ServerConfig); //GetBound("VMESS_WS.json"); + mwsBound.port = VMESS_WS_Port; + SetClients(mwsBound, uuidList); + mwsBound.streamSettings.wsSettings.path = parameters.VMESS_WS_Path; + baseBound.settings.fallbacks.Add(JToken.FromObject(new + { + dest = VMESS_WS_Port, + path = parameters.VMESS_WS_Path, + xver = 1, + })); + xrayConfig.inbounds.Add(JToken.FromObject(mwsBound)); + } + + if (parameters.Types.Contains(V2RayType.Trojan_TCP)) + { + var trojanTcpBound = LoadJsonObj(V2rayConfigTemplates.Trojan_ServerConfig); //GetBound("Trojan_TCP.json"); + trojanTcpBound.port = Trojan_TCP_Port; + trojanTcpBound.settings.clients[0].password = parameters.TrojanPassword; + trojanTcpBound.settings.fallbacks[0].dest = FullbackPort; + baseBound.settings.fallbacks[0] = JToken.FromObject(new + { + dest = Trojan_TCP_Port, + xver = 1, + }); + xrayConfig.inbounds.Add(JToken.FromObject(trojanTcpBound)); + } + #endregion + + #region VLESS GRPC + if (parameters.Types.Contains(V2RayType.VLESS_gRPC)) + { + var gRPCInBound = LoadJsonObj(V2rayConfigTemplates.VLESS_gRPC_ServerConfig); //GetBound("VLESS_gRPC.json"); + gRPCInBound.port = parameters.VLESS_gRPC_Port; + SetClients(gRPCInBound, uuidList); + gRPCInBound.streamSettings.grpcSettings.serviceName = parameters.VLESS_gRPC_ServiceName; + gRPCInBound.streamSettings.tlsSettings.serverName = parameters.Domain; + xrayConfig.inbounds.Add(JToken.FromObject(gRPCInBound)); + } + #endregion + + #region VLESS KCP + if (parameters.Types.Contains(V2RayType.VLESS_KCP)) + { + var kcpBound = LoadJsonObj(V2rayConfigTemplates.VLESS_KCP_ServerConfig); //GetBound("VLESS_KCP.json"); + kcpBound.port = parameters.VLESS_KCP_Port; + SetClients(kcpBound, uuidList); + kcpBound.streamSettings.kcpSettings.header.type = parameters.VLESS_KCP_Type; + kcpBound.streamSettings.kcpSettings.seed = parameters.VLESS_KCP_Seed; + xrayConfig.inbounds.Add(JToken.FromObject(kcpBound)); + } + #endregion + + #region VLESS QUIC + if (parameters.Types.Contains(V2RayType.VLESS_QUIC)) + { + var quicBound = LoadJsonObj(V2rayConfigTemplates.VLESS_QUIC_ServerConfig); //GetBound("VLESS_QUIC.json"); + quicBound.port = parameters.VLESS_QUIC_Port; + SetClients(quicBound, uuidList); + quicBound.streamSettings.quicSettings.security = parameters.VLESS_QUIC_Security; + quicBound.streamSettings.quicSettings.key = parameters.VLESS_QUIC_Key; + quicBound.streamSettings.quicSettings.header.type = parameters.VLESS_QUIC_Type; + xrayConfig.inbounds.Add(JToken.FromObject(quicBound)); + } + #endregion + + #region VMESS KCP + if (parameters.Types.Contains(V2RayType.VMESS_KCP)) + { + var kcpBound = LoadJsonObj(V2rayConfigTemplates.VMESS_KCP_ServerConfig); //GetBound("VMESS_KCP.json"); + kcpBound.port = parameters.VMESS_KCP_Port; + SetClients(kcpBound, uuidList); + kcpBound.streamSettings.kcpSettings.header.type = parameters.VMESS_KCP_Type; + kcpBound.streamSettings.kcpSettings.seed = parameters.VMESS_KCP_Seed; + xrayConfig.inbounds.Add(JToken.FromObject(kcpBound)); + } + #endregion + + #region VMESS QUIC + if (parameters.Types.Contains(V2RayType.VMESS_QUIC)) + { + var quicBound = LoadJsonObj(V2rayConfigTemplates.VMESS_QUIC_ServerConfig); //GetBound("VMESS_QUIC.json"); + quicBound.port = parameters.VMESS_QUIC_Port; + SetClients(quicBound, uuidList); + quicBound.streamSettings.quicSettings.security = parameters.VMESS_QUIC_Security; + quicBound.streamSettings.quicSettings.key = parameters.VMESS_QUIC_Key; + quicBound.streamSettings.quicSettings.header.type = parameters.VMESS_QUIC_Type; + xrayConfig.inbounds.Add(JToken.FromObject(quicBound)); + } + #endregion + + #region Shadowsocks + if (parameters.Types.Contains(V2RayType.ShadowsocksAEAD)) + { + var ssBound = LoadJsonObj(V2rayConfigTemplates.Shadowsocks_ServerConfig); //GetBound("Shadowsocks-AEAD.json"); + ssBound.port = parameters.ShadowSocksPort; + ssBound.settings.password = parameters.ShadowSocksPassword; + ssBound.settings.method = parameters.ShadowSocksMethod; + xrayConfig.inbounds.Add(JToken.FromObject(ssBound)); + } + #endregion + + return JsonConvert.SerializeObject( + xrayConfig, + Formatting.Indented, + new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }); + } + + private static dynamic LoadJsonObj(string jsonStr) + { + return JToken.Parse(jsonStr); + } + } +} diff --git a/ProxySuper.Core/Services/V2rayService.cs b/ProxySuper.Core/Services/V2rayService.cs new file mode 100644 index 00000000..73479d8b --- /dev/null +++ b/ProxySuper.Core/Services/V2rayService.cs @@ -0,0 +1,449 @@ +using Microsoft.Win32; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class V2rayService : ServiceBase + { + public V2rayService(Host host, V2raySettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + int index = 1; + EnsureRootUser(); + + if (FileExists("/usr/local/bin/v2ray")) + { + var btnResult = MessageBox.Show("已经安装v2ray,是否需要重装?", "提示", MessageBoxButton.YesNo); + if (btnResult == MessageBoxResult.No) + { + MessageBox.Show("安装终止", "提示"); + return; + } + } + + Progress.Step = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 5; + + Progress.Step = $"{index++}. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 15; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + if (Settings.IsIPAddress) + { + Progress.Desc = ("检查域名是否解析正确"); + ValidateDomain(); + } + Progress.Percentage = 25; + + Progress.Step = $"{index}. 同步系统和本地时间"; + SyncTimeDiff(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 安装Caddy服务器"; + InstallCaddy(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 安装V2ray-Core"; + InstallV2ray(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 上传Web服务器配置"; + UploadCaddyFile(); + Progress.Percentage = 90; + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Desc = "重启V2ray服务"; + + RunCmd("systemctl restart caddy"); + RunCmd("systemctl restart v2ray"); + + Progress.Percentage = 100; + Progress.Step = "安装成功"; + Progress.Desc = string.Empty; + + if (!Settings.WithTLS) + { + Progress.Step = "安装成功,请上传您的 TLS 证书。"; + } + else + { + NavigationService.Navigate(Settings); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新V2ray配置"; + Progress.Percentage = 0; + EnsureRootUser(); + var index = 0; + + Progress.Desc = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = $"{index++}. 配置防火墙"; + RunCmd("systemctl stop v2ray"); + RunCmd("systemctl stop caddy"); + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Desc = $"{index++}. 上传V2ray配置文件"; + var configJson = V2rayConfigBuilder.BuildV2rayConfig(Settings); + WriteToFile(configJson, "/usr/local/etc/v2ray/config.json"); + Progress.Percentage = 70; + + Progress.Desc = $"{index++}. 上传Caddy配置文件"; + UploadCaddyFile(); + Progress.Percentage = 90; + + Progress.Desc = $"{index++}. 重启v2ray服务"; + RunCmd("systemctl restart caddy"); + RunCmd("systemctl restart v2ray"); + Progress.Percentage = 100; + + Progress.Desc = ("更新配置成功"); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateV2rayCore() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新V2ray-Core"; + Progress.Percentage = 0; + + EnsureRootUser(); + Progress.Percentage = 20; + + Progress.Desc = "下载最新版本V2ray-Core"; + EnsureSystemEnv(); + Progress.Percentage = 40; + + RunCmd("bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"); + RunCmd("systemctl restart v2ray"); + Progress.Percentage = 100; + + Progress.Desc = "更新V2ray-Core成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + var index = 1; + Progress.Percentage = 0; + + Progress.Step = $"{index++}. 检测系统环境"; + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 卸载Caddy服务"; + UninstallCaddy(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 卸载V2ray服务"; + UninstallV2ray(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 卸载Acme证书申请服务"; + UninstallAcme(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 重置防火墙端口"; + ResetFirewalld(); + Progress.Percentage = 100; + + Progress.Step = "卸载完成"; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UploadCert() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadCert; + fileDialog.ShowDialog(); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + public void ApplyForCert() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "续签证书"; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + + Progress.Desc = "安装证书"; + InstallCert( + dirPath: "/usr/local/etc/v2ray/ssl", + certName: "v2ray_ssl.crt", + keyName: "v2ray_ssl.key"); + + Progress.Percentage = 90; + Progress.Desc = "重启服务"; + RunCmd("systemctl restart v2ray"); + + Progress.Percentage = 100; + Progress.Desc = "续签证书成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + + #region 似有方法 + + private void DoUploadCert(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Percentage = 0; + Progress.Step = "上传自有证书"; + Progress.Desc = "检测系统环境"; + + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + var oldFileName = $"ssl_{DateTime.Now.Ticks}"; + RunCmd($"mv /usr/local/etc/v2ray/ssl /usr/local/etc/v2ray/{oldFileName}"); + + RunCmd("mkdir -p /usr/local/etc/v2ray/ssl"); + UploadFile(stream, "/usr/local/etc/v2ray/ssl/ssl.zip"); + RunCmd("unzip /usr/local/etc/v2ray/ssl/ssl.zip -d /usr/local/etc/v2ray/ssl"); + } + + var crtFiles = RunCmd("find /usr/local/etc/v2ray/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + var keyFiles = RunCmd("find /usr/local/etc/v2ray/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (crtFiles.Length > 0 && keyFiles.Length > 0) + { + RunCmd($"mv {crtFiles[0]} /usr/local/etc/v2ray/ssl/v2ray_ssl.crt"); + RunCmd($"mv {keyFiles[0]} /usr/local/etc/v2ray/ssl/v2ray_ssl.key"); + } + else + { + Progress.Step = "上传失败"; + Progress.Desc = "上传证书失败,缺少 .crt 和 .key 文件"; + return; + } + + Progress.Desc = "重启V2ray服务"; + RunCmd("systemctl restart v2ray"); + + Progress.Percentage = 100; + Progress.Desc = "上传证书完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Desc = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir -p /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + } + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 80; + + Progress.Desc = "上传Web配置文件"; + UploadCaddyFile(useCustomWeb: true); + Progress.Percentage = 90; + + Progress.Desc = "重启caddy服务"; + RunCmd("systemctl restart caddy"); + Progress.Percentage = 100; + + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallV2ray() + { + Progress.Desc = ("开始安装V2ray-Core"); + RunCmd("bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"); + + if (!FileExists("/usr/local/bin/v2ray")) + { + Progress.Desc = ("V2ray-Core安装失败,请联系开发者"); + throw new Exception("V2ray-Core安装失败,请联系开发者"); + } + + Progress.Desc = ("设置V2ray-Core权限"); + RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/v2ray.service"); + RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/v2ray.service"); + RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/v2ray.service"); + RunCmd($"systemctl daemon-reload"); + RunCmd("systemctl enable v2ray"); + + if (FileExists("/usr/local/etc/v2ray/config.json")) + { + RunCmd(@"mv /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.1"); + } + Progress.Percentage = 60; + + if (Settings.WithTLS && !Settings.IsIPAddress) + { + Progress.Desc = ("安装TLS证书"); + InstallCert( + dirPath: "/usr/local/etc/v2ray/ssl", + certName: "v2ray_ssl.crt", + keyName: "v2ray_ssl.key"); + Progress.Percentage = 75; + } + + Progress.Desc = ("生成v2ray服务器配置文件"); + var configJson = V2rayConfigBuilder.BuildV2rayConfig(Settings); + WriteToFile(configJson, "/usr/local/etc/v2ray/config.json"); + } + + private void UploadCaddyFile(bool useCustomWeb = false) + { + var configJson = V2rayConfigBuilder.BuildCaddyConfig(Settings, useCustomWeb); + + if (FileExists("/etc/caddy/Caddyfile")) + { + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + } + WriteToFile(configJson, "/etc/caddy/Caddyfile"); + } + + + private void UninstallV2ray() + { + Progress.Desc = "关闭V2ray服务"; + RunCmd("systemctl stop v2ray"); + RunCmd("systemctl disable v2ray"); + + Progress.Desc = "卸载V2ray"; + RunCmd("bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove"); + } + + private void UninstallAcme() + { + Progress.Desc = "卸载 acme.sh"; + RunCmd("acme.sh --uninstall"); + + Progress.Desc = "删除 acme.sh 相关文件"; + RunCmd("rm -rf ~/.acme.sh"); + } + + #endregion + } +} diff --git a/ProxySuper.Core/Services/XrayConfigBuilder.cs b/ProxySuper.Core/Services/XrayConfigBuilder.cs new file mode 100644 index 00000000..c766c321 --- /dev/null +++ b/ProxySuper.Core/Services/XrayConfigBuilder.cs @@ -0,0 +1,245 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Templates; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace ProxySuper.Core.Services +{ + public class XrayConfigBuilder + { + private static string ServerLog = XrayConfigTemplates.ServerGeneralConfig_log; + private static string ServerDns = XrayConfigTemplates.ServerGeneralConfig_dns; + private static string ServerRouting = XrayConfigTemplates.ServerGeneralConfig_routing_BlockPrivateIP; + private static string ServerInbounds = XrayConfigTemplates.ServerGeneralConfig_inbounds; + private static string ServerOutbounds = XrayConfigTemplates.ServerGeneralConfig_outbounds; + private static string CaddyFile = CaddyFiles.BaseCaddyFile; + + public static int VLESS_WS_Port = 1111; + //public static int VLESS_XHTTP_Port ; + + public static int Trojan_TCP_Port = 1310; + public static int Trojan_WS_Port = 1311; + + public static int FullbackPort = 8080; + + + + public static dynamic LoadXrayConfig() + { + dynamic logObj = LoadJsonObj(ServerLog); + dynamic dnsObj = LoadJsonObj(ServerDns); + dynamic routingObj = LoadJsonObj(ServerRouting); + dynamic inboundsObj = LoadJsonObj(ServerInbounds); + dynamic outboundsObj = LoadJsonObj(ServerOutbounds); + + return new + { + log = logObj["log"], + dns = dnsObj["dns"], + routing = routingObj["routing"], + inbounds = inboundsObj["inbounds"], + outbounds = outboundsObj["outbounds"] + }; + } + + public static string BuildCaddyConfig(XraySettings parameters, bool useCustomWeb = false) + { + var caddyStr = CaddyFile; + caddyStr = caddyStr.Replace("##domain##", parameters.IsIPAddress ? "" : parameters.Domain); + caddyStr = caddyStr.Replace("##port##", FullbackPort.ToString()); + + if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) + { + var prefix = "http://"; + if (parameters.MaskDomain.StartsWith("https://")) + { + prefix = "https://"; + } + var domain = parameters.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()) + .TrimEnd('/'); + + caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {prefix}{domain} {{ \n header_up Host {domain} \n }}"); + } + else + { + caddyStr = caddyStr.Replace("##reverse_proxy##", ""); + } + + return caddyStr; + } + + private static void SetClients(dynamic bound, List uuidList, bool withXtls = false, string flow = "") + { + bound.settings.clients.Clear(); + uuidList.ForEach(id => + { + object obj; + if (!withXtls) + { + obj = new { id = id }; + } + else + { + flow = "xtls-rprx-vision";//Xray不再同时兼容普通tls与xtls。服务端与客户端必须一致。 + obj = new { id = id, flow = flow }; + } + + bound.settings.clients.Add(JToken.FromObject(obj)); + }); + } + + public static string BuildXrayConfig(XraySettings parameters) + { + var uuidList = new List(); + uuidList.Add(parameters.UUID); + uuidList.AddRange(parameters.MulitUUID); + + var xrayConfig = LoadXrayConfig(); + + #region VLESS_XTLS_REALITY + + if (parameters.Types.Contains(XrayType.VLESS_XTLS_RAW_REALITY)) + { + var xtlsRealityBound = LoadJsonObj(XrayConfigTemplates.VLESS_XTLS_RAW_REALITY_ServerConfig); + xtlsRealityBound.inbounds[0].port = parameters.Port; + xtlsRealityBound.inbounds[0].settings.port = 4431;//parameters.Port; + xtlsRealityBound.inbounds[1].port = 4431;//parameters.Port; + xtlsRealityBound.inbounds[1].settings.clients[0].id = parameters.UUID; + xtlsRealityBound.inbounds[1].streamSettings.realitySettings.target = parameters.MaskDomain + ":443"; + xtlsRealityBound.inbounds[1].streamSettings.realitySettings.serverNames[0] = parameters.MaskDomain; + xtlsRealityBound.inbounds[1].streamSettings.realitySettings.privateKey = parameters.REALITY_privateKey; + xtlsRealityBound.routing.rules[0].domain[0] = parameters.MaskDomain; + xtlsRealityBound.Merge(JToken.Parse(XrayConfigTemplates.ServerGeneralConfig_log)); + xtlsRealityBound.Merge(JToken.Parse(XrayConfigTemplates.ServerGeneralConfig_outbounds)); + SetClients(xtlsRealityBound.inbounds[1], uuidList, withXtls: true, flow: parameters.Flow); + xrayConfig = xtlsRealityBound; + } + + #endregion + + #region VLESS_XHTTP + + if (parameters.Types.Contains(XrayType.VLESS_XHTTP)) + { + var xhttpInbound = LoadJsonObj(XrayConfigTemplates.VLESS_XHTTP_ServerConfig); + xhttpInbound.port = parameters.Port; + xhttpInbound.settings.fallbacks.Add(JToken.FromObject(new + { + dest = FullbackPort + })); + SetClients(xhttpInbound, uuidList); + xhttpInbound.streamSettings.xhttpSettings.path = parameters.VLESS_XHTTP_Path; + xrayConfig.inbounds.Add(JToken.FromObject(xhttpInbound)); + } + + #endregion + + #region VLESS_XTLS + if (parameters.Types.Contains(XrayType.VLESS_RAW_XTLS) || parameters.Types.Contains(XrayType.VLESS_WS) || parameters.Types.Contains(XrayType.Trojan_TCP)) + { + var xtlsBound = LoadJsonObj(XrayConfigTemplates.VLESS_XTLS_ServerConfig); + xtlsBound.port = parameters.Port; + xtlsBound.settings.fallbacks.Add(JToken.FromObject(new + { + dest = FullbackPort + })); + SetClients(xtlsBound, uuidList, withXtls: true, flow: parameters.Flow); + xrayConfig.inbounds.Add(xtlsBound); + } + #endregion + + #region VLESS_WS + + if (parameters.Types.Contains(XrayType.VLESS_WS)) + { + var wsInbound = LoadJsonObj(XrayConfigTemplates.VLESS_WS_ServerConfig); + wsInbound.port = VLESS_WS_Port; + SetClients(wsInbound, uuidList); + wsInbound.streamSettings.wsSettings.path = parameters.VLESS_WS_Path; + xrayConfig.inbounds[0].settings.fallbacks.Add(JToken.FromObject(new + { + dest = VLESS_WS_Port, + path = parameters.VLESS_WS_Path, + xver = 1, + })); + xrayConfig.inbounds.Add(JToken.FromObject(wsInbound)); + } + + #endregion + + #region Trojan_TCP + + if (parameters.Types.Contains(XrayType.Trojan_TCP)) + { + var trojanTcpBound = LoadJsonObj(XrayConfigTemplates.Trojan_ServerConfig); + trojanTcpBound.port = Trojan_TCP_Port; + trojanTcpBound.settings.clients[0].password = parameters.TrojanPassword; + trojanTcpBound.settings.fallbacks[0].dest = FullbackPort; + xrayConfig.inbounds[0].settings.fallbacks[0] = JToken.FromObject(new + { + dest = Trojan_TCP_Port, + xver = 1, + }); + xrayConfig.inbounds.Add(JToken.FromObject(trojanTcpBound)); + } + #endregion + + #region VLESS GRPC + if (parameters.Types.Contains(XrayType.VLESS_gRPC)) + { + var gRPCInBound = LoadJsonObj(XrayConfigTemplates.VLESS_gRPC_ServerConfig); + gRPCInBound.port = parameters.VLESS_gRPC_Port; + SetClients(gRPCInBound, uuidList); + gRPCInBound.streamSettings.grpcSettings.serviceName = parameters.VLESS_gRPC_ServiceName; + gRPCInBound.streamSettings.tlsSettings.serverName = parameters.Domain; + xrayConfig.inbounds.Add(JToken.FromObject(gRPCInBound)); + } + #endregion + + #region VMESS KCP + if (parameters.Types.Contains(XrayType.VMESS_KCP)) + { + var kcpBound = LoadJsonObj(XrayConfigTemplates.VMESS_KCP_ServerConfig); + kcpBound.port = parameters.VMESS_KCP_Port; + SetClients(kcpBound, uuidList); + kcpBound.streamSettings.kcpSettings.header.type = parameters.VMESS_KCP_Type; + kcpBound.streamSettings.kcpSettings.seed = parameters.VMESS_KCP_Seed; + xrayConfig.inbounds.Add(JToken.FromObject(kcpBound)); + } + #endregion + + #region Shadowsocks + if (parameters.Types.Contains(XrayType.ShadowsocksAEAD)) + { + var ssBound = LoadJsonObj(XrayConfigTemplates.Shadowsocks_ServerConfig); + ssBound.port = parameters.ShadowSocksPort; + ssBound.settings.password = parameters.ShadowSocksPassword; + ssBound.settings.method = parameters.ShadowSocksMethod; + xrayConfig.inbounds.Add(JToken.FromObject(ssBound)); + } + #endregion + + return JsonConvert.SerializeObject( + xrayConfig, + Formatting.Indented, + new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }); + } + + + private static dynamic LoadJsonObj(string jsonStr) + { + return JToken.Parse(jsonStr); + } + + } + +} diff --git a/ProxySuper.Core/Services/XrayService.cs b/ProxySuper.Core/Services/XrayService.cs new file mode 100644 index 00000000..5933cf5b --- /dev/null +++ b/ProxySuper.Core/Services/XrayService.cs @@ -0,0 +1,453 @@ +using Microsoft.Win32; +using ProxySuper.Core.Helpers; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class XrayService : ServiceBase + { + + public XrayService(Host host, XraySettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + int index = 1; + EnsureRootUser(); + + if (FileExists("/usr/local/bin/xray")) + { + var btnResult = MessageBox.Show("已经安装Xray,是否需要重装?", "提示", MessageBoxButton.YesNo); + if (btnResult == MessageBoxResult.No) + { + MessageBox.Show("安装终止", "提示"); + return; + } + } + + Progress.Step = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 5; + + Progress.Step = $"{index++}. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 15; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + if (Settings.IsIPAddress) + { + Progress.Desc = ("检查域名是否解析正确"); + ValidateDomain(); + } + Progress.Percentage = 25; + + Progress.Step = $"{index}. 同步系统和本地时间"; + SyncTimeDiff(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 安装Caddy服务器"; + InstallCaddy(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 安装Xray-Core"; + InstallXray(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 上传Web服务器配置"; + UploadCaddyFile(); + Progress.Percentage = 90; + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Desc = "重启Xray服务"; + RunCmd("systemctl restart caddy"); + RunCmd("systemctl restart xray"); + + Progress.Percentage = 100; + Progress.Step = "安装成功"; + Progress.Desc = string.Empty; + + if (!Settings.WithTLS && (Settings.Types.Contains(XrayType.VLESS_RAW_XTLS) + || Settings.Types.Contains(XrayType.VLESS_WS) + || Settings.Types.Contains(XrayType.VLESS_gRPC) + || Settings.Types.Contains(XrayType.Trojan_TCP) + ) + ) + { + Progress.Step = "安装成功,请上传您的 TLS 证书。"; + } + else + { + NavigationService.Navigate(Settings); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新Xray配置"; + Progress.Percentage = 0; + EnsureRootUser(); + var index = 0; + + Progress.Desc = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = $"{index++}. 配置防火墙"; + RunCmd("systemctl stop xray"); + RunCmd("systemctl stop caddy"); + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Desc = $"{index++}. 上传Xray配置文件"; + var configJson = XrayConfigBuilder.BuildXrayConfig(Settings); + WriteToFile(configJson, "/usr/local/etc/xray/config.json"); + Progress.Percentage = 70; + + Progress.Desc = $"{index++}. 上传Caddy配置文件"; + UploadCaddyFile(); + Progress.Percentage = 90; + + Progress.Desc = $"{index++}. 重启xray服务"; + RunCmd("systemctl restart caddy"); + RunCmd("systemctl restart xray"); + Progress.Percentage = 100; + + Progress.Desc = ("更新配置成功"); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateXrayCore() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新Xray-Core"; + Progress.Percentage = 0; + + EnsureRootUser(); + Progress.Percentage = 20; + + Progress.Desc = "下载最新版本Xray-Core"; + EnsureSystemEnv(); + Progress.Percentage = 40; + + RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); + RunCmd("systemctl restart xray"); + Progress.Percentage = 100; + + Progress.Desc = "更新Xray-Core成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + var index = 1; + Progress.Percentage = 0; + + Progress.Step = $"{index++}. 检测系统环境"; + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 卸载Caddy服务"; + UninstallCaddy(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 卸载Xray服务"; + UninstallXray(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 卸载Acme证书申请服务"; + UninstallAcme(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 重置防火墙端口"; + ResetFirewalld(); + Progress.Percentage = 100; + + Progress.Step = "卸载完成"; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UploadCert() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadCert; + fileDialog.ShowDialog(); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + public void ApplyForCert() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "续签证书"; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + + Progress.Desc = "安装证书"; + InstallCert( + dirPath: "/usr/local/etc/xray/ssl", + certName: "xray_ssl.crt", + keyName: "xray_ssl.key"); + + Progress.Percentage = 90; + Progress.Desc = "重启服务"; + RunCmd("systemctl restart xray"); + + Progress.Percentage = 100; + Progress.Desc = "续签证书成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + + #region 私有方法 + + private void DoUploadCert(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Percentage = 0; + Progress.Step = "上传自有证书"; + Progress.Desc = "检测系统环境"; + + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + var oldFileName = $"ssl_{DateTime.Now.Ticks}"; + RunCmd($"mv /usr/local/etc/xray/ssl /usr/local/etc/xray/{oldFileName}"); + + RunCmd("mkdir -p /usr/local/etc/xray/ssl"); + UploadFile(stream, "/usr/local/etc/xray/ssl/ssl.zip"); + RunCmd("unzip /usr/local/etc/xray/ssl/ssl.zip -d /usr/local/etc/xray/ssl"); + } + + var crtFiles = RunCmd("find /usr/local/etc/xray/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + var keyFiles = RunCmd("find /usr/local/etc/xray/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (crtFiles.Length > 0 && keyFiles.Length > 0) + { + RunCmd($"mv {crtFiles[0]} /usr/local/etc/xray/ssl/xray_ssl.crt"); + RunCmd($"mv {keyFiles[0]} /usr/local/etc/xray/ssl/xray_ssl.key"); + } + else + { + Progress.Step = "上传失败"; + Progress.Desc = "上传证书失败,缺少 .crt 和 .key 文件"; + return; + } + + Progress.Desc = "重启Xray服务"; + RunCmd("systemctl restart xray"); + + Progress.Percentage = 100; + Progress.Desc = "上传证书完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Desc = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir -p /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + } + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 80; + + Progress.Desc = "上传Web配置文件"; + UploadCaddyFile(useCustomWeb: true); + Progress.Percentage = 90; + + Progress.Desc = "重启caddy服务"; + RunCmd("systemctl restart caddy"); + Progress.Percentage = 100; + + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallXray() + { + Progress.Desc = ("开始安装Xray-Core"); + RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); + + if (!FileExists("/usr/local/bin/xray")) + { + Progress.Desc = ("Xray-Core安装失败,请联系开发者"); + throw new Exception("Xray-Core安装失败,请联系开发者"); + } + + Progress.Desc = ("设置Xray-core权限"); + RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/xray.service"); + RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/xray.service"); + RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/xray.service"); + RunCmd($"systemctl daemon-reload"); + + if (FileExists("/usr/local/etc/xray/config.json")) + { + RunCmd(@"mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.1"); + } + Progress.Percentage = 60; + + if (Settings.WithTLS && !Settings.IsIPAddress) + { + Progress.Desc = ("安装TLS证书"); + InstallCert( + dirPath: "/usr/local/etc/xray/ssl", + certName: "xray_ssl.crt", + keyName: "xray_ssl.key"); + Progress.Percentage = 75; + } + + Progress.Desc = ("生成Xray服务器配置文件"); + var configJson = XrayConfigBuilder.BuildXrayConfig(Settings); + WriteToFile(configJson, "/usr/local/etc/xray/config.json"); + } + + private void UploadCaddyFile(bool useCustomWeb = false) + { + var configJson = XrayConfigBuilder.BuildCaddyConfig(Settings, useCustomWeb); + + if (FileExists("/etc/caddy/Caddyfile")) + { + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + } + WriteToFile(configJson, "/etc/caddy/Caddyfile"); + } + + private void UninstallXray() + { + Progress.Desc = "关闭Xray服务"; + RunCmd("systemctl stop xray"); + RunCmd("systemctl disable xray"); + + Progress.Desc = "卸载Xray"; + RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ remove"); + } + + private void UninstallAcme() + { + Progress.Desc = "卸载 acme.sh"; + RunCmd("acme.sh --uninstall"); + + Progress.Desc = "删除 acme.sh 相关文件"; + RunCmd("rm -rf ~/.acme.sh"); + } + + #endregion + } +} diff --git a/ProxySuper.Core/Templates/CaddyFiles.cs b/ProxySuper.Core/Templates/CaddyFiles.cs new file mode 100644 index 00000000..fd8c6855 --- /dev/null +++ b/ProxySuper.Core/Templates/CaddyFiles.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Templates +{ + public static class CaddyFiles + { + public static string BaseCaddyFile = """ + :##port## { + root * /usr/share/caddy + file_server + ##reverse_proxy## + } + + ##domain##:80 { + redir https://##domain##{uri} + } + """; + } +} diff --git a/ProxySuper.Core/Templates/HysteriaConfigTemplates.cs b/ProxySuper.Core/Templates/HysteriaConfigTemplates.cs new file mode 100644 index 00000000..9d3a1f78 --- /dev/null +++ b/ProxySuper.Core/Templates/HysteriaConfigTemplates.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Templates +{ + public static class HysteriaConfigTemplates + { + + #region ServerHysteria2Config + public static string ServerHysteria2Config_base = """ + listen: :443 + + auth: + type: password + password: your_password + + sniff: + enable: true + timeout: 2s + rewriteDomain: false + tcpPorts: 80,443,8000-9000 + udpPorts: all + """; + + public static string ServerHysteria2Config_acme = """ + acme: + domains: + - domain1.com + email: your@email.net + ca: letsencrypt + """; + + public static string ServerHysteria2Config_tls = """ + tls: + cert: /etc/hysteria/ssl/hysteria_ssl.crt + key: /etc/hysteria/ssl/hysteria_ssl.key + sniGuard: dns-san + """; + + public static string ServerHysteria2Config_masquerade_proxy = """ + masquerade: + type: proxy + proxy: + url: https://some.site.net + rewriteHost: true + insecure: false + listenHTTP: :80 + listenHTTPS: :443 + forceHTTPS: true + """; + + public static string ServerHysteria2Config_masquerade_file = """ + masquerade: + type: file + file: + dir: /var/www/hymasq + listenHTTP: :80 + listenHTTPS: :443 + forceHTTPS: true + """; + + + public static string ServerHysteria2Config_bbr = """ + ignoreClientBandwidth: true + """; + + public static string ServerHysteria1ConfigTemplateOld = """ + { + "listen": ":36712", + "acme": { + "domains": [ + "your.domain.com" + ], + "email": "your@email.com" + }, + "obfs": "8ZuA2Zpqhuk8yakXvMjDqEXBwY" + } + """; + #endregion + + #region ServerAndClientHysteria2Config + public static string ServerAndClientHysteria2Config_obfs = """ + obfs: + type: salamander + salamander: + password: cry_me_a_r1ver + """; + + public static string ServerAndClientHysteria2Config_bandwidth = """ + bandwidth: + up: 0 gbps + down: 0 gbps + """; + #endregion + + #region ClientHysteria2Config + public static string ClientHysteria2Config_base = """ + server: example.com + auth: some_password + bandwidth: + up: 20 mbps + down: 100 mbps + socks5: + listen: 127.0.0.1:1080 + http: + listen: 127.0.0.1:8080 + """; + + public static string ClientHysteria2Config_url = """ + server: hysteria2://user:pass@example.com/ + """; + + #endregion + } +} diff --git a/ProxySuper.Core/Templates/NaiveServerCaddyfile.cs b/ProxySuper.Core/Templates/NaiveServerCaddyfile.cs new file mode 100644 index 00000000..1b2d9ef8 --- /dev/null +++ b/ProxySuper.Core/Templates/NaiveServerCaddyfile.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Templates +{ + public static class NaiveServerCaddyfile + { + public static string BaseCaddyFile = """ + :##port##, ##domain## + route { + forward_proxy { + ##basicauth## + hide_ip + hide_via + probe_resistance + } + #file_server { root /usr/share/caddy } + } + ##reverse_proxy## + """; + } +} diff --git a/ProxySuper.Core/Templates/TrojanGoTemplates.cs b/ProxySuper.Core/Templates/TrojanGoTemplates.cs new file mode 100644 index 00000000..c94411f2 --- /dev/null +++ b/ProxySuper.Core/Templates/TrojanGoTemplates.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Templates +{ + public static class TrojanGoTemplates + { + public static string BaseCaddyfile = """ + :##port## { + root * /usr/share/caddy + file_server + ##reverse_proxy## + } + + ##domain##:80 { + redir https://##domain##{uri} + } + """; + + public static string TrojanGoJson = """ + { + "log_level": 5, + "run_type": "server", + "local_addr": "0.0.0.0", + "local_port": 443, + "remote_addr": "127.0.0.1", + "remote_port": 80, + "password": [ + "" + ], + "ssl": { + "cert": "/usr/local/etc/trojan-go/ssl/trojan-go.crt", + "key": "/usr/local/etc/trojan-go/ssl/trojan-go.key", + "sni": "example.com" + }, + "websocket": { + "enabled": false, + "path": "/ws", + "host": "example.com" + } + } + + """; + } +} diff --git a/ProxySuper.Core/Templates/V2rayConfigTemplates.cs b/ProxySuper.Core/Templates/V2rayConfigTemplates.cs new file mode 100644 index 00000000..a191525b --- /dev/null +++ b/ProxySuper.Core/Templates/V2rayConfigTemplates.cs @@ -0,0 +1,667 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Templates +{ + public static class V2rayConfigTemplates + { + #region VLESS_TCP_TLS_ServerConfig + public static string VLESS_TCP_TLS_ServerConfig = """ + { + "port": 443, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "", + "level": 0 + } + ], + "decryption": "none", + "fallbacks": [] + }, + "streamSettings": { + "network": "tcp", + "security": "tls", + "tlsSettings": { + "alpn": [ + "http/1.1" + ], + "certificates": [ + { + "certificateFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.crt", + "keyFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.key" + } + ] + } + } + } + """; + public static string VLESS_TCP_TLS_ClientConfig = """ + + """; + #endregion + + #region VLESS_WS_ServerConfig + public static string VLESS_WS_ServerConfig = """ + { + "port": 1234, + "listen": "127.0.0.1", + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/websocket" + } + } + } + + """; + public static string VLESS_WS_ClientConfig = """ + + """; + #endregion + + #region VLESS_QUIC_ServerConfig + public static string VLESS_QUIC_ServerConfig = """ + { + "port": 2000, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "quic", + "quicSettings": { + "security": "none", + "key": "", + "header": { + "type": "none" + } + }, + "security": "tls", + "tlsSettings": { + "certificates": [ + { + "certificateFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.crt", + "keyFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.key" + } + ] + } + } + } + """; + public static string VLESS_QUIC_ClientConfig = """ + + """; + #endregion + + #region VLESS_KCP_ServerConfig + public static string VLESS_KCP_ServerConfig = """ + { + "port": 3456, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "mkcp", + "kcpSettings": { + "uplinkCapacity": 100, + "downlinkCapacity": 100, + "congestion": true, + "header": { + "type": "none" + }, + "seed": null + } + } + } + + """; + public static string VLESS_KCP_ClientConfig = """ + + """; + #endregion + + #region VLESS_HTTP2_ServerConfig + public static string VLESS_HTTP2_ServerConfig = """ + { + "port": 1234, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "decryption": "none", + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "h2", + "httpSettings": { + "path": "" + } + } + } + """; + public static string VLESS_HTTP2_ClientConfig = """ + + """; + #endregion + + #region VLESS_gRPC_ServerConfig + public static string VLESS_gRPC_ServerConfig = """ + { + "port": 2002, + "listen": "0.0.0.0", + "protocol": "vless", + "settings": { + "decryption": "none", + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "grpc", + "security": "tls", + "tlsSettings": { + "serverName": "domain", + "alpn": [ + "h2" + ], + "certificates": [ + { + "certificateFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.crt", + "keyFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.key" + } + ] + }, + "grpcSettings": { + "serviceName": "service_name" + } + } + } + + """; + public static string VLESS_gRPC_ClientConfig = """ + + """; + #endregion + + #region VMESS_WS_ServerConfig + public static string VMESS_WS_ServerConfig = """ + { + "port": 3456, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/vmessws" + } + } + } + + """; + public static string VMESS_WS_ClientConfig = """ + + """; + #endregion + + #region VMESS_TCP_ServerConfig + public static string VMESS_TCP_ServerConfig = """ + { + "port": 443, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "tcp", + "security": "none", + "tcpSettings": { + "acceptProxyProtocol": true, + "header": { + "type": "http", + "request": { + "path": [ + "/vmesstcp" + ] + } + } + } + } + } + + """; + public static string VMESS_TCP_ClientConfig = """ + + """; + #endregion + + #region VMESS_QUIC_ServerConfig + public static string VMESS_QUIC_ServerConfig = """ + { + "port": 3000, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "quic", + "quicSettings": { + "security": "none", + "key": "", + "header": { + "type": "none" + } + }, + "security": "tls", + "tlsSettings": { + "certificates": [ + { + "certificateFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.crt", + "keyFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.key" + } + ] + } + } + } + """; + public static string VMESS_QUIC_ClientConfig = """ + + """; + #endregion + + + #region VMESS KCP Configs + public static string VMESS_KCP_ServerConfig = """ + { + "port": 3456, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "mkcp", + "kcpSettings": { + "uplinkCapacity": 100, + "downlinkCapacity": 100, + "congestion": true, + "header": { + "type": "none" + }, + "seed": null + } + } + } + + """; + public static string VMESS_KCP_ClientConfig = """ + + """; + #endregion + + + #region VMESS_HTTP2_ServerConfig + public static string VMESS_HTTP2_ServerConfig = """ + { + "port": 1234, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "h2", + "httpSettings": { + "path": "" + } + } + } + """; + public static string VMESS_HTTP2_ClientConfig = """ + + """; + #endregion + + #region VMESS_gRPC_ServerConfig + public static string VMESS_gRPC_ServerConfig = """ + { + "port": 2002, + "listen": "0.0.0.0", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "grpc", + "security": "tls", + "tlsSettings": { + "serverName": "domain", + "alpn": [ + "h2" + ], + "certificates": [ + { + "certificateFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.crt", + "keyFile": "/usr/local/etc/v2ray/ssl/v2ray_ssl.key" + } + ] + }, + "grpcSettings": { + "serviceName": "service_name" + } + } + } + + """; + public static string VMESS_gRPC_ClientConfig = """ + + """; + #endregion + + #region Trojan Configs + public static string Trojan_ServerConfig = """ + { + "port": 1310, + "listen": "127.0.0.1", + "protocol": "trojan", + "settings": { + "clients": [ + { + "password": "" + } + ], + "fallbacks": [ + { + "dest": 8080 + } + ] + }, + "streamSettings": { + "network": "tcp", + "security": "none", + "tcpSettings": { + "acceptProxyProtocol": true + } + } + } + + """; + public static string Trojan_ClientConfig = """ + + """; + #endregion + + #region Shadowsocks Configs + public static string Shadowsocks_ServerConfig = """ + { + "port": 12345, + "protocol": "shadowsocks", + "settings": { + "password": "", + "method": "aes-128-gcm", + "network": "tcp,udp" + } + } + """; + public static string Shadowsocks_ClientConfig = """ + + """; + #endregion + + + #region ServerGeneralConfig + public static string ServerGeneralConfig_log = """ + { + "log": { + "access": "none", + "loglevel": "none" + } + } + """; + + public static string ServerGeneralConfig_outbounds = """ + { + "outbounds": [ + { + "protocol": "freedom", + "tag": "direct" + }, + { + "protocol": "blackhole", + "tag": "block" + } + ] + } + """; + + public static string ServerGeneralConfig_inbounds = """ + { + "inbounds": [] + } + + """; + + public static string ServerGeneralConfig_dns = """ + { + "dns": {} + } + """; + + public static string ServerGeneralConfig_routing_BlockPrivateIPAndCN = """ + { + "routing": { + "rules": [ + { + "ip": [ + "geoip:private", + "geoip:cn" + ], + "outboundTag": "block" + } + ] + } + } + """; + + public static string ServerGeneralConfig_routing_BlockPrivateIP = """ + { + "routing": { + "rules": [ + { + "ip": [ + "geoip:private" + ], + "outboundTag": "block" + } + ] + } + } + """; + + #endregion + + + #region ClientGeneralConfig + public static string ClientGeneralConfig_log = """ + { + "log": { + "loglevel": "warning" + } + } + """; + + public static string ClientGeneralConfig_inbounds = """ + { + "inbounds": [ + { + "port": 10808, + "protocol": "socks", + "settings": { + "udp": true, + "auth": "noauth" + } + } + ] + } + """; + + + public static string ClientGeneralConfig_outbounds = """ + { + "outbounds": [] + } + """; + + public static string ClientGeneralConfig_dns = """ + { + "dns": {} + } + """; + + public static string ClientGeneralConfig_routing = """ + { + "routing": {} + } + """; + + public static string ClientGeneralConfig_WhiteList = """ + { + "outbounds": [ + { + "tag": "direct", + "protocol": "freedom" + }, + { + "tag": "block", + "protocol": "blackhole" + } + ], + "dns": { + "servers": [ + "1.1.1.1", + "8.8.8.8", + "8.8.4.4", + "2001:4860:4860::8888", + "2001:4860:4860::8844", + "https://1.1.1.1/dns-query", + "https://dns.google/dns-query", + { + "address": "223.5.5.5", + "domains": [ + "geosite:cn" + ], + "expectIPs": [ + "geoip:cn" + ] + } + { + "address": "2400:3200::1", + "domains": [ + "geosite:cn" + ], + "expectIPs": [ + "geoip:cn" + ] + } + ] + }, + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "network": "udp", + "port": "443", + "outboundTag": "blocked" + }, + { + "ip": [ + "223.5.5.5", + "2400:3200::1", + "geoip:private", + "geoip:cn" + ], + "outboundTag": "direct" + }, + { + "domain": ["geosite:cn"], + "outboundTag": "direct" + } + ] + } + } + """; + + #endregion + + public static string BaseConfig = """ + { + "log": {}, + "dns": {}, + "routing": {}, + "inbounds": [], + "outbounds": [] + } + """; + } +} diff --git a/ProxySuper.Core/Templates/XrayConfigTemplates.cs b/ProxySuper.Core/Templates/XrayConfigTemplates.cs new file mode 100644 index 00000000..c78b5a69 --- /dev/null +++ b/ProxySuper.Core/Templates/XrayConfigTemplates.cs @@ -0,0 +1,641 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Templates +{ + public static class XrayConfigTemplates + { + #region VLESS_XTLS_RAW_REALITY Configs + //参考自https://github.com/XTLS/Xray-examples/tree/main/VLESS-TCP-REALITY%20(without%20being%20stolen) + //添加 xtls-rprx-vision + public static string VLESS_XTLS_RAW_REALITY_ServerConfig = """ + { + "inbounds": [ + { + "tag": "dokodemo-in", + "port": 443, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1", + "port": 4431, + "network": "tcp" + }, + "sniffing": { + "enabled": true, + "destOverride": [ + "tls" + ], + "routeOnly": true + } + }, + { + "listen": "127.0.0.1", + "port": 4431, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "", + "flow": "xtls-rprx-vision" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "raw", + "security": "reality", + "realitySettings": { + "target": "speed.cloudflare.com:443", + "serverNames": [ + "speed.cloudflare.com" + ], + "privateKey": "", + "shortIds": [ "" ] + } + }, + "sniffing": { + "enabled": true, + "destOverride": [ + "http", + "tls", + "quic" + ], + "routeOnly": true + } + } + ], + "routing": { + "rules": [ + { + "inboundTag": [ + "dokodemo-in" + ], + "domain": [ + "speed.cloudflare.com" + ], + "outboundTag": "direct" + }, + { + "inboundTag": [ + "dokodemo-in" + ], + "outboundTag": "block" + } + ] + } + } + """; + + public static string VLESS_XTLS_REALITY_ClientConfig = """ + { + "outbounds": [ + { + "protocol": "vless", + "settings": { + "vnext": [ + { + "address": "127.0.0.1", + "port": 443, + "users": [ + { + "id": "", + "flow": "xtls-rprx-vision", + "encryption": "none" + } + ] + } + ] + }, + "streamSettings": { + "network": "raw", + "security": "reality", + "realitySettings": { + "fingerprint": "chrome", + "serverName": "speed.cloudflare.com", + "publicKey": "", + "spiderX": "/", + "shortId": "" + } + }, + "tag": "proxy" + } + ] + } + """; + #endregion + + #region VLESS XHTTP Configs + + public static string VLESS_XHTTP_ServerConfig = """ + { + "port": 443, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none", + "fallbacks": [] + }, + "streamSettings": { + "network": "xhttp", + "xhttpSettings": { + "path": "" + }, + "security": "tls", + "tlsSettings": { + "rejectUnknownSni": true, + "minVersion": "1.2", + "certificates": [ + { + "ocspStapling": 3600, + "certificateFile": "/usr/local/etc/xray/ssl/xray_ssl.crt", + "keyFile": "/usr/local/etc/xray/ssl/xray_ssl.key" + } + ] + } + + } + } + """; + + public static string VLESS_XHTTP_ClientConfig = """ + { + "outbounds": [ + { + "tag": "proxy", + "protocol": "vless", + "settings": { + "vnext": [ + { + "address": "", + "port": 443, + "users": [ + { + "id": "", + "encryption": "none" + } + ] + } + ] + }, + "streamSettings": { + "network": "xhttp", + "security": "tls", + "tlsSettings": { + "allowInsecure": false, + "alpn": [ + "h3", + "h2", + "http/1.1" + ] + }, + "xhttpSettings": { + "path": "", + "mode": "packet-up" + } + } + } + ] + } + + """; + #endregion + + #region VLESS XTLS Configs + public static string VLESS_XTLS_ServerConfig = """ + { + "port": 443, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "", + "flow": "xtls-rprx-vision" + } + ], + "decryption": "none", + "fallbacks": [] + }, + "streamSettings": { + "network": "raw", + "security": "tls", + "tlsSettings": { + "rejectUnknownSni": true, + "minVersion": "1.2", + "certificates": [ + { + "ocspStapling": 3600, + "certificateFile": "/usr/local/etc/xray/ssl/xray_ssl.crt", + "keyFile": "/usr/local/etc/xray/ssl/xray_ssl.key" + } + ] + } + } + } + """; + public static string VLESS_XTLS_ClientConfig = """ + + """; + + #endregion + + #region VLESS WS Configs + public static string VLESS_WS_ServerConfig = """ + { + "port": 1234, + "listen": "127.0.0.1", + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/websocket" + } + } + } + + """; + public static string VLESS_WS_ClientConfig = """ + { + "outbounds": [ + { + "protocol": "vless", + "settings": { + "vnext": [ + { + "address": "", + "port": 443, + "users": [ + { + "id": "", + "encryption": "none", + "level": 0 + } + ] + } + ] + }, + "streamSettings": { + "network": "ws", + "security": "tls", + "tlsSettings": { + "serverName": "" + }, + "wsSettings": { + "path": "" + } + } + } + ] + } + + """; + #endregion + + #region VLESS gRPC Configs + public static string VLESS_gRPC_ServerConfig = """ + { + "port": 2002, + "listen": "0.0.0.0", + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "grpc", + "security": "tls", + "tlsSettings": { + "serverName": "domain", + "alpn": [ + "h2" + ], + "certificates": [ + { + "certificateFile": "/usr/local/etc/xray/ssl/xray_ssl.crt", + "keyFile": "/usr/local/etc/xray/ssl/xray_ssl.key" + } + ] + }, + "grpcSettings": { + "serviceName": "service_name" + } + } + } + + """; + public static string VLESS_gRPC_ClientConfig = """ + + """; + #endregion + + #region Trojan Configs + public static string Trojan_ServerConfig = """ + { + "port": 1310, + "listen": "127.0.0.1", + "protocol": "trojan", + "settings": { + "clients": [ + { + "password": "" + } + ], + "fallbacks": [ + { + "dest": 8080 + } + ] + }, + "streamSettings": { + "network": "raw", + "security": "none", + "tcpSettings": { + "acceptProxyProtocol": true + } + } + } + + """; + public static string Trojan_ClientConfig = """ + + """; + #endregion + + #region Shadowsocks Configs + public static string Shadowsocks_ServerConfig = """ + { + "port": 12345, + "protocol": "shadowsocks", + "settings": { + "password": "", + "method": "aes-128-gcm", + "network": "tcp,udp" + } + } + """; + public static string Shadowsocks_ClientConfig = """ + + """; + #endregion + + #region VMESS KCP Configs + public static string VMESS_KCP_ServerConfig = """ + { + "port": 3456, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "" + } + ] + }, + "streamSettings": { + "network": "mkcp", + "kcpSettings": { + "uplinkCapacity": 100, + "downlinkCapacity": 100, + "congestion": true, + "header": { + "type": "none" + }, + "seed": null + } + } + } + + """; + public static string VMESS_KCP_ClientConfig = """ + + """; + #endregion + + + + + #region ServerGeneralConfig + public static string ServerGeneralConfig_log = """ + { + "log": { + "access": "none", + "loglevel": "none" + } + } + """; + + public static string ServerGeneralConfig_outbounds = """ + { + "outbounds": [ + { + "protocol": "freedom", + "tag": "direct" + }, + { + "protocol": "blackhole", + "tag": "block" + } + ] + } + """; + + public static string ServerGeneralConfig_inbounds = """ + { + "inbounds": [] + } + + """; + + public static string ServerGeneralConfig_dns = """ + { + "dns": {} + } + """; + + public static string ServerGeneralConfig_routing_BlockPrivateIPAndCN = """ + { + "routing": { + "rules": [ + { + "ip": [ + "geoip:private", + "geoip:cn" + ], + "outboundTag": "block" + } + ] + } + } + """; + + public static string ServerGeneralConfig_routing_BlockPrivateIP = """ + { + "routing": { + "rules": [ + { + "ip": [ + "geoip:private" + ], + "outboundTag": "block" + } + ] + } + } + """; + + #endregion + + + #region ClientGeneralConfig + public static string ClientGeneralConfig_log = """ + { + "log": { + "loglevel": "warning" + } + } + """; + + public static string ClientGeneralConfig_inbounds = """ + { + "inbounds": [ + { + "port": 10808, + "protocol": "socks", + "settings": { + "udp": true, + "auth": "noauth" + } + } + ] + } + """; + + + public static string ClientGeneralConfig_outbounds = """ + { + "outbounds": [] + } + """; + + public static string ClientGeneralConfig_dns = """ + { + "dns": {} + } + """; + + public static string ClientGeneralConfig_routing = """ + { + "routing": {} + } + """; + + public static string ClientGeneralConfig_WhiteList = """ + { + "outbounds": [ + { + "tag": "direct", + "protocol": "freedom" + }, + { + "tag": "block", + "protocol": "blackhole" + } + ], + "dns": { + "servers": [ + "1.1.1.1", + "8.8.8.8", + "8.8.4.4", + "2001:4860:4860::8888", + "2001:4860:4860::8844", + "https://1.1.1.1/dns-query", + "https://dns.google/dns-query", + { + "address": "223.5.5.5", + "domains": [ + "geosite:cn" + ], + "expectIPs": [ + "geoip:cn" + ] + } + { + "address": "2400:3200::1", + "domains": [ + "geosite:cn" + ], + "expectIPs": [ + "geoip:cn" + ] + } + ] + }, + "routing": { + "domainMatcher": "mph", + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "network": "udp", + "port": "443", + "outboundTag": "blocked" + }, + { + "ip": [ + "223.5.5.5", + "2400:3200::1", + "geoip:private", + "geoip:cn" + ], + "outboundTag": "direct" + }, + { + "domain": ["geosite:cn"], + "outboundTag": "direct" + } + ] + } + } + """; + + #endregion + + public static string BaseConfig = """ + { + "log": {}, + "dns": {}, + "routing": {}, + "inbounds": [], + "outbounds": [] + } + """; + + + + + + + + + + } +} diff --git a/ProxySuper.Core/ViewModels/BrookConfigViewModel.cs b/ProxySuper.Core/ViewModels/BrookConfigViewModel.cs new file mode 100644 index 00000000..99d9421c --- /dev/null +++ b/ProxySuper.Core/ViewModels/BrookConfigViewModel.cs @@ -0,0 +1,24 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.ViewModels +{ + public class BrookConfigViewModel : MvxViewModel + { + public BrookSettings Settings { get; set; } + + public override void Prepare(BrookSettings parameter) + { + Settings = parameter; + } + + public string Link + { + get + { + return ShareLink.BuildBrook(Settings); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs b/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs new file mode 100644 index 00000000..29ef9e5d --- /dev/null +++ b/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs @@ -0,0 +1,102 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; + +namespace ProxySuper.Core.ViewModels +{ + public class BrookEditorViewModel : MvxViewModel + { + public BrookEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public IMvxNavigationService NavigationService { get; } + + public string Id { get; set; } + + public Host Host { get; set; } + + public BrookSettings Settings { get; set; } + + public List BrookTypes + { + get + { + return new List { + BrookType.server.ToString(), + BrookType.wsserver.ToString(), + BrookType.wssserver.ToString(), + BrookType.socks5.ToString(), + }; + } + } + + public string CheckedBrookType + { + get + { + return Settings.BrookType.ToString(); + } + set + { + Settings.BrookType = (BrookType)Enum.Parse(typeof(BrookType), value); + + if (Settings.BrookType == BrookType.wssserver) + { + Settings.Port = 443; + RaisePropertyChanged("Settings"); + } + RaisePropertyChanged("EnablePort"); + RaisePropertyChanged("EnableDomain"); + RaisePropertyChanged("EnableIP"); + } + } + + public bool EnablePort => Settings.BrookType != BrookType.wssserver; + + public bool EnableDomain => Settings.BrookType == BrookType.wssserver; + + public bool EnableIP => Settings.BrookType != BrookType.wssserver; + + public IMvxCommand SaveCommand => new MvxCommand(() => Save()); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + Id = record.Id; + Host = record.Host; + Settings = record.BrookSettings; + } + + public void Save() + { + NavigationService.Close(this, new Record() + { + Id = Id, + Host = Host, + BrookSettings = Settings, + }); + } + + private void SaveAndInstall() + { + var record = new Record + { + Id = this.Id, + Host = this.Host, + BrookSettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } +} diff --git a/ProxySuper.Core/ViewModels/BrookInstallViewModel.cs b/ProxySuper.Core/ViewModels/BrookInstallViewModel.cs new file mode 100644 index 00000000..c3bc429b --- /dev/null +++ b/ProxySuper.Core/ViewModels/BrookInstallViewModel.cs @@ -0,0 +1,65 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class BrookInstallViewModel : MvxViewModel + { + Host _host; + + BrookSettings _settings; + + BrookService _service; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.BrookSettings; + } + + public override Task Initialize() + { + _service = new BrookService(_host, _settings); + _service.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _service.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _service.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress => _service.Progress; + + public string Logs => _service.Progress.Logs; + + public IMvxCommand InstallCommand => new MvxCommand(_service.Install); + + public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall); + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".brook.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/EnableRootViewModel.cs b/ProxySuper.Core/ViewModels/EnableRootViewModel.cs new file mode 100644 index 00000000..3ae228c5 --- /dev/null +++ b/ProxySuper.Core/ViewModels/EnableRootViewModel.cs @@ -0,0 +1,168 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models.Hosts; +using Renci.SshNet; +using System; +using System.IO; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.ViewModels +{ + public class EnableRootViewModel : MvxViewModel + { + private SshClient _sshClient; + + public EnableRootViewModel() + { + Host = new Host(); + } + + public Host Host { get; set; } + + public string RootUserName { get; set; } + + public string RootPassword { get; set; } + + public string OutputText { get; set; } + + public IMvxCommand ExecuteCommand => new MvxCommand(Execute); + + public override void ViewDisappearing() + { + base.ViewDisappearing(); + if (_sshClient != null) + { + _sshClient.Disconnect(); + _sshClient.Dispose(); + } + } + + public void Execute() + { + Task.Factory.StartNew(() => + { + OpenConnect(); + if (!_sshClient.IsConnected) + { + MessageBox.Show("连接失败,请重试!"); + return; + } + + string result = string.Empty; + result = RunCmd("id -u"); + + if (result.TrimEnd('\r', '\n') == "0") + { + MessageBox.Show("当前账户已经具有root权限,无需再设置!"); + return; + } + + result = RunCmd($"echo {Host.Password} | sudo -S id -u"); + if (result.TrimEnd('\r', '\n') != "0") + { + MessageBox.Show("当前账户无法获取sudo权限,设置失败!"); + return; + } + + string cmdPre = $"echo {Host.Password} | sudo -S id -u" + ';'; + RunCmd(cmdPre + "sudo sed -i 's/PermitRootLogin /#PermitRootLogin /g' /etc/ssh/sshd_config"); + RunCmd(cmdPre + "sudo sed -i 's/PasswordAuthentication /#PasswordAuthentication /g' /etc/ssh/sshd_config"); + RunCmd(cmdPre + "sudo sed -i 's/PermitEmptyPasswords /#PermitEmptyPasswords /g' /etc/ssh/sshd_config"); + RunCmd(cmdPre + "echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config"); + RunCmd(cmdPre + "echo 'PasswordAuthentication yes' | sudo tee -a /etc/ssh/sshd_config"); + RunCmd(cmdPre + "echo 'PermitEmptyPasswords no' | sudo tee -a /etc/ssh/sshd_config"); + RunCmd(cmdPre + "sudo systemctl restart sshd"); + + result = RunCmd(@"cat /dev/urandom | tr -dc '_A-Z#\-+=a-z(0-9%^>)]{<|' | head -c 20 ; echo ''"); + string setPassword = result.TrimEnd('\r', '\n') + '\n'; + RunCmd(cmdPre + $"echo \"{setPassword}{setPassword}\" | sudo passwd root"); + RunCmd("sudo systemctl restart sshd"); + + RootUserName = "root"; + RootPassword = setPassword.Trim('\n'); + RaisePropertyChanged("RootUserName"); + RaisePropertyChanged("RootPassword"); + + + var filePath = Host.Address.Replace(':', '_'); + using (StreamWriter sw = new StreamWriter("Logs\\host_password_info.txt")) + { + sw.WriteLine(Host.Address); + sw.WriteLine("root"); + sw.WriteLine(setPassword); + } + WriteOutput("设置成功,账号信息保存在Logs/host_password_info.txt"); + WriteOutput("账号:\nroot"); + WriteOutput($"密码:\n{setPassword}"); + }); + } + + protected string RunCmd(string cmdStr) + { + var cmd = _sshClient.CreateCommand(cmdStr); + WriteOutput(cmdStr); + + var result = cmd.Execute(); + WriteOutput(result); + return result; + } + + private void WriteOutput(string text) + { + OutputText += text + '\n'; + RaisePropertyChanged("OutputText"); + } + + + private void OpenConnect() + { + WriteOutput("正在建立连接..."); + var conneInfo = CreateConnectionInfo(Host); + _sshClient = new SshClient(conneInfo); + try + { + _sshClient.Connect(); + WriteOutput("Connected..."); + } + catch (Exception ex) + { + WriteOutput(ex.Message); + MessageBox.Show(ex.Message); + } + } + + private ConnectionInfo CreateConnectionInfo(Host host) + { + AuthenticationMethod auth = null; + + if (host.SecretType == LoginSecretType.Password) + { + auth = new PasswordAuthenticationMethod(host.UserName, host.Password); + } + else if (host.SecretType == LoginSecretType.PrivateKey) + { + auth = new PrivateKeyAuthenticationMethod(host.UserName, new PrivateKeyFile(host.PrivateKeyPath)); + } + + if (host.Proxy.Type == ProxyTypes.None) + { + return new ConnectionInfo(host.Address, host.Port, host.UserName, auth); + } + else + { + return new ConnectionInfo( + host: host.Address, + port: host.Port, + username: host.UserName, + proxyType: host.Proxy.Type, + proxyHost: host.Proxy.Address, + proxyPort: host.Proxy.Port, + proxyUsername: host.Proxy.UserName, + proxyPassword: host.Proxy.Password, + authenticationMethods: auth); + } + + } + } +} diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs new file mode 100644 index 00000000..13c8bc28 --- /dev/null +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -0,0 +1,380 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.ViewModels +{ + public class HomeViewModel : MvxViewModel + { + private readonly IMvxNavigationService _navigationService; + + public HomeViewModel(IMvxNavigationService navigationService) + { + _navigationService = navigationService; + ReadRecords(); + } + + public void ReadRecords() + { + List records = new List(); + if (File.Exists("Data/Record.json")) + { + var json = File.ReadAllText("Data/Record.json"); + records = JsonConvert.DeserializeObject>(json); + } + + this.Records = new MvxObservableCollection(); + + records.ForEach(item => + { + if (string.IsNullOrEmpty(item.Id)) + { + item.Id = Guid.NewGuid().ToString(); + } + this.Records.Add(item); + }); + } + + public void SaveToJson() + { + var json = JsonConvert.SerializeObject(Records, Formatting.Indented, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }); + if (!Directory.Exists("Data")) + { + Directory.CreateDirectory("Data"); + } + File.WriteAllText("Data/Record.json", json); + } + + public void SortDone(string id) + { + var item = Records.Where(x => x.Id == id).FirstOrDefault(); + if (item == null) return; + + var index = Records.IndexOf(item); + if (index >= Records.Count - 1) return; + + Records.Remove(item); + Records.Insert(index + 1, item); + + RaisePropertyChanged("Records"); + SaveToJson(); + } + + public void SortUp(string id) + { + var item = Records.Where(x => x.Id == id).FirstOrDefault(); + if (item == null) return; + + var index = Records.IndexOf(item); + if (index <= 0) return; + + Records.Remove(item); + Records.Insert(index - 1, item); + + RaisePropertyChanged("Records"); + SaveToJson(); + } + + public MvxObservableCollection Records { get; set; } + + public IMvxCommand SortUpCommand => new MvxCommand(SortUp); + + public IMvxCommand SortDoneCommand => new MvxCommand(SortDone); + + public IMvxCommand AddV2rayCommand => new MvxAsyncCommand(AddV2rayRecord); + + public IMvxCommand AddXrayCommand => new MvxAsyncCommand(AddXrayRecord); + + public IMvxCommand AddTrojanGoCommand => new MvxAsyncCommand(AddTrojanGoRecord); + + public IMvxCommand AddNaiveProxyCommand => new MvxAsyncCommand(AddNaiveProxyRecord); + + public IMvxCommand AddMTProtoGoCommand => new MvxAsyncCommand(AddMTProtoGoRecord); + + public IMvxCommand AddBrookCommand => new MvxAsyncCommand(AddBrookRecord); + + public IMvxCommand AddHysteria2Command => new MvxAsyncCommand(AddHysteria2Record); + + public IMvxCommand RemoveCommand => new MvxAsyncCommand(DeleteRecord); + + public IMvxCommand EditCommand => new MvxAsyncCommand(EditRecord); + + public IMvxCommand ViewConfigCommand => new MvxAsyncCommand(ViewConfig); + + public IMvxCommand InstallCommand => new MvxAsyncCommand(GoToInstall); + + public async Task AddV2rayRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.V2raySettings = new V2raySettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + SaveToJson(); + } + + public async Task AddXrayRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.XraySettings = new XraySettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + SaveToJson(); + } + + public async Task AddTrojanGoRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.TrojanGoSettings = new TrojanGoSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + + public async Task AddMTProtoGoRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.MTProtoGoSettings = new MTProtoGoSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + + public async Task AddNaiveProxyRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.NaiveProxySettings = new NaiveProxySettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + + public async Task AddBrookRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.BrookSettings = new BrookSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + + public async Task AddHysteria2Record() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.HysteriaSettings = new HysteriaSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + + + public async Task EditRecord(string id) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record == null) return; + + Record result = null; + if (record.Type == ProjectType.V2ray) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.V2raySettings = result.V2raySettings; + } + if (record.Type == ProjectType.Xray) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.XraySettings = result.XraySettings; + } + if (record.Type == ProjectType.TrojanGo) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.TrojanGoSettings = result.TrojanGoSettings; + } + if (record.Type == ProjectType.NaiveProxy) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.NaiveProxySettings = result.NaiveProxySettings; + } + if (record.Type == ProjectType.Brook) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.BrookSettings = result.BrookSettings; + } + if (record.Type == ProjectType.MTProtoGo) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.MTProtoGoSettings = result.MTProtoGoSettings; + } + if (record.Type == ProjectType.Hysteria2) + { + result = await _navigationService.Navigate(record); + if (result == null) return; + + record.Host = result.Host; + record.HysteriaSettings = result.HysteriaSettings; + } + + SaveToJson(); + } + + public async Task DeleteRecord(string id) + { + var result = MessageBox.Show($"您确认删除主机吗?", "提示", MessageBoxButton.OKCancel); + if (result == MessageBoxResult.OK) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record != null) + { + Records.Remove(record); + SaveToJson(); + } + } + await Task.CompletedTask; + } + + public async Task ViewConfig(string id) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record == null) return; + + if (record.Type == ProjectType.V2ray) + { + await _navigationService.Navigate(record.V2raySettings); + } + if (record.Type == ProjectType.Xray) + { + await _navigationService.Navigate(record.XraySettings); + } + if (record.Type == ProjectType.TrojanGo) + { + await _navigationService.Navigate(record.TrojanGoSettings); + } + if (record.Type == ProjectType.NaiveProxy) + { + await _navigationService.Navigate(record.NaiveProxySettings); + } + if (record.Type == ProjectType.Brook) + { + await _navigationService.Navigate(record.BrookSettings); + } + if (record.Type == ProjectType.MTProtoGo) + { + await _navigationService.Navigate(record.MTProtoGoSettings); + } + if (record.Type == ProjectType.Hysteria2) + { + await _navigationService.Navigate(record.HysteriaSettings); + } + } + + public async Task GoToInstall(string id) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record == null) return; + record.OnSave = SaveToJson; + + if (record.Type == ProjectType.V2ray) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.Xray) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.TrojanGo) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.NaiveProxy) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.Brook) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.MTProtoGo) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.Hysteria2) + { + await _navigationService.Navigate(record); + } + + SaveToJson(); + } + + } +} diff --git a/ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs b/ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs new file mode 100644 index 00000000..68cbe6f2 --- /dev/null +++ b/ProxySuper.Core/ViewModels/HysteriaConfigViewModel.cs @@ -0,0 +1,100 @@ +using MvvmCross.ViewModels; +using Newtonsoft.Json; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class HysteriaConfigViewModel : MvxViewModel + { + public HysteriaSettings Settings { get; set; } + + public override void Prepare(HysteriaSettings parameter) + { + Settings = parameter; + } + + public string Domain + { + get => Settings.Domain; + set + { + Settings.Domain = value; + RaisePropertyChanged("Domain"); + } + } + + public int Port + { + get => Settings.Port; + set + { + Settings.Port = value; + RaisePropertyChanged("Port"); + } + } + + public string Password + { + get => Settings.Password; + set + { + Settings.Password = value; + RaisePropertyChanged("Password"); + } + } + + public string ObfsPassword + { + get + { + if(Settings.EnableObfs == true) + { + return Settings.ObfsPassword; + } + return ""; + }//=> Settings.ObfsPassword; + set + { + Settings.ObfsPassword = value; + RaisePropertyChanged("ObfsPassword"); + } + } + + public string HysteriaShareLink + { + get => Settings.HysteriaShareLink; + + } + + + public string ClientYamlConfig { + + get + { + /* + var jsonData = new + { + server = $"{Settings.Domain}:{Settings.Port}", + obfs = Settings.ObfsPassword, + up_mbps = 10, + down_mbps = 50, + socks5 = new + { + listen = "127.0.0.1:1080" + }, + http = new + { + listen = "127.0.0.1:1081" + } + }; + */ + return Settings.ClientHysteria2Config;//JsonConvert.SerializeObject(jsonData, Formatting.Indented); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/HysteriaEditorViewModel.cs b/ProxySuper.Core/ViewModels/HysteriaEditorViewModel.cs new file mode 100644 index 00000000..7bd40c46 --- /dev/null +++ b/ProxySuper.Core/ViewModels/HysteriaEditorViewModel.cs @@ -0,0 +1,68 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Navigation; + +namespace ProxySuper.Core.ViewModels +{ + public class HysteriaEditorViewModel : MvxViewModel + { + public string Id { get; set; } + + public Host Host { get; set; } + + public HysteriaSettings Settings { get; set; } + + public IMvxNavigationService NavigationService { get; } + + public IMvxCommand SaveCommand => new MvxCommand(() => Save()); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public HysteriaEditorViewModel(IMvxNavigationService mvxNavigationService) + { + NavigationService = mvxNavigationService; + } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + + Id = record.Id; + Host = record.Host; + Settings = record.HysteriaSettings; + } + + public void Save() + { + NavigationService.Close(this, new Record + { + Id = Id, + Host = Host, + HysteriaSettings = Settings, + }); + } + + public void SaveAndInstall() + { + var record = new Record + { + Id = Id, + Host = Host, + HysteriaSettings = Settings, + }; + + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } +} diff --git a/ProxySuper.Core/ViewModels/HysteriaInstallViewModel.cs b/ProxySuper.Core/ViewModels/HysteriaInstallViewModel.cs new file mode 100644 index 00000000..0125eec2 --- /dev/null +++ b/ProxySuper.Core/ViewModels/HysteriaInstallViewModel.cs @@ -0,0 +1,69 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class HysteriaInstallViewModel : MvxViewModel + { + public Host _host { get; set; } + + public HysteriaSettings _settings { get; set; } + + public HysteriaService _service { get; set; } + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.HysteriaSettings; + } + + public override Task Initialize() + { + _service = new HysteriaService(_host, _settings); + _service.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _service.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _service.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress => _service.Progress; + + public string Logs => _service.Progress.Logs; + + public IMvxCommand InstallCommand => new MvxCommand(_service.Install); + + public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall); + + public IMvxCommand UploadCertCommand => new MvxCommand(_service.UploadCert); + + public IMvxCommand UploadWebCommand => new MvxCommand(_service.UploadWeb); + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".hysteria.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/MTProtoGoConfigViewModel.cs b/ProxySuper.Core/ViewModels/MTProtoGoConfigViewModel.cs new file mode 100644 index 00000000..a6058ca5 --- /dev/null +++ b/ProxySuper.Core/ViewModels/MTProtoGoConfigViewModel.cs @@ -0,0 +1,21 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class MTProtoGoConfigViewModel : MvxViewModel + { + public MTProtoGoSettings Settings { get; set; } + + public override void Prepare(MTProtoGoSettings parameter) + { + Settings = parameter; + } + } +} diff --git a/ProxySuper.Core/ViewModels/MTProtoGoEditorViewModel.cs b/ProxySuper.Core/ViewModels/MTProtoGoEditorViewModel.cs new file mode 100644 index 00000000..fa983bfa --- /dev/null +++ b/ProxySuper.Core/ViewModels/MTProtoGoEditorViewModel.cs @@ -0,0 +1,66 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class MTProtoGoEditorViewModel : MvxViewModel + { + public MTProtoGoEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public IMvxNavigationService NavigationService { get; } + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public string Id { get; set; } + + public Host Host { get; set; } + + public MTProtoGoSettings Settings { get; set; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + + Id = record.Id; + Host = record.Host; + Settings = record.MTProtoGoSettings; + } + + private void Save() + { + NavigationService.Close(this, new Record + { + Id = this.Id, + Host = this.Host, + MTProtoGoSettings = Settings, + }); + } + + private void SaveAndInstall() + { + var record = new Record + { + Id = this.Id, + Host = this.Host, + MTProtoGoSettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } +} diff --git a/ProxySuper.Core/ViewModels/MTProtoGoInstallViewModel.cs b/ProxySuper.Core/ViewModels/MTProtoGoInstallViewModel.cs new file mode 100644 index 00000000..794d4f18 --- /dev/null +++ b/ProxySuper.Core/ViewModels/MTProtoGoInstallViewModel.cs @@ -0,0 +1,94 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class MTProtoGoInstallViewModel : MvxViewModel + { + Host _host; + + MTProtoGoSettings _settings; + + MTProtoGoService _mtproxyService; + + Action _onSave; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.MTProtoGoSettings; + _onSave = parameter.OnSave; + } + + public override Task Initialize() + { + _mtproxyService = new MTProtoGoService(_host, _settings); + _mtproxyService.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _mtproxyService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _mtproxyService.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _mtproxyService.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress + { + get => _mtproxyService.Progress; + } + + public string Logs + { + get => _mtproxyService.Progress.Logs; + } + + + #region Command + + public IMvxCommand InstallCommand => new MvxCommand(() => + { + _mtproxyService.Install(); + + // 安装时生成的Secret需要保存 + _onSave(); + }); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(() => + { + _mtproxyService.UpdateSettings(); + + // 安装时生成的Secret需要保存 + _onSave(); + }); + + public IMvxCommand UninstallCommand => new MvxCommand(_mtproxyService.Uninstall); + + #endregion + + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".mtproxy-go.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/NaiveProxyConfigViewModel.cs b/ProxySuper.Core/ViewModels/NaiveProxyConfigViewModel.cs new file mode 100644 index 00000000..8e59f65f --- /dev/null +++ b/ProxySuper.Core/ViewModels/NaiveProxyConfigViewModel.cs @@ -0,0 +1,24 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.ViewModels +{ + public class NaiveProxyConfigViewModel : MvxViewModel + { + public NaiveProxySettings Settings { get; set; } + + public override void Prepare(NaiveProxySettings parameter) + { + Settings = parameter; + } + + public string Link + { + get + { + return ShareLink.BuildNaiveProxy(Settings); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/NaiveProxyEditorViewModel.cs b/ProxySuper.Core/ViewModels/NaiveProxyEditorViewModel.cs new file mode 100644 index 00000000..cb131e41 --- /dev/null +++ b/ProxySuper.Core/ViewModels/NaiveProxyEditorViewModel.cs @@ -0,0 +1,63 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.ViewModels +{ + public class NaiveProxyEditorViewModel : MvxViewModel + { + public NaiveProxyEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public IMvxNavigationService NavigationService { get; } + + public string Id { get; set; } + + public Host Host { get; set; } + + public NaiveProxySettings Settings { get; set; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + + Id = record.Id; + Host = record.Host; + Settings = record.NaiveProxySettings; + } + + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + private void Save() + { + NavigationService.Close(this, new Record + { + Id = Id, + Host = Host, + NaiveProxySettings = Settings + }); + } + + + private void SaveAndInstall() + { + var record = new Record + { + Id = this.Id, + Host = this.Host, + NaiveProxySettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } +} diff --git a/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs b/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs new file mode 100644 index 00000000..29870767 --- /dev/null +++ b/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs @@ -0,0 +1,75 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class NaiveProxyInstallViewModel : MvxViewModel + { + Host _host; + + NaiveProxySettings _settings; + + NaiveProxyService _service; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.NaiveProxySettings; + } + + public override Task Initialize() + { + _service = new NaiveProxyService(_host, _settings); + _service.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _service.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _service.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + + public ProjectProgress Progress => _service.Progress; + + public string Logs => _service.Progress.Logs; + + + #region Commands + + public IMvxCommand InstallCommand => new MvxCommand(_service.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_service.UpdateSettings); + + public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall); + + public IMvxCommand UploadWebCommand => new MvxCommand(_service.UploadWeb); + + #endregion + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".naiveproxy.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/ShareLinkViewModel.cs b/ProxySuper.Core/ViewModels/ShareLinkViewModel.cs new file mode 100644 index 00000000..749d86bf --- /dev/null +++ b/ProxySuper.Core/ViewModels/ShareLinkViewModel.cs @@ -0,0 +1,31 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using System.Collections.Generic; +using System.Text; + +namespace ProxySuper.Core.ViewModels +{ + public class ShareLinkViewModel : MvxViewModel> + { + public List Records { get; set; } + + public override void Prepare(List parameter) + { + Records = parameter; + } + + public string ShareLinks + { + get + { + StringBuilder sb = new StringBuilder(); + Records.ForEach(record => + { + var link = record.GetShareLink(); + sb.AppendLine(link); + }); + return sb.ToString(); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs b/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs new file mode 100644 index 00000000..ff469e22 --- /dev/null +++ b/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs @@ -0,0 +1,24 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.ViewModels +{ + public class TrojanGoConfigViewModel : MvxViewModel + { + public TrojanGoSettings Settings { get; set; } + + public override void Prepare(TrojanGoSettings parameter) + { + Settings = parameter; + } + + public string Link + { + get + { + return ShareLink.BuildTrojanGo(Settings); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs b/ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs new file mode 100644 index 00000000..737e9b03 --- /dev/null +++ b/ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs @@ -0,0 +1,63 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; + +namespace ProxySuper.Core.ViewModels +{ + public class TrojanGoEditorViewModel : MvxViewModel + { + public TrojanGoEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public IMvxNavigationService NavigationService { get; } + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public string Id { get; set; } + + public Host Host { get; set; } + + public TrojanGoSettings Settings { get; set; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + + Id = record.Id; + Host = record.Host; + Settings = record.TrojanGoSettings; + } + + private void Save() + { + NavigationService.Close(this, new Record + { + Id = this.Id, + Host = this.Host, + TrojanGoSettings = Settings, + }); + } + + private void SaveAndInstall() + { + var record = new Record + { + Id = this.Id, + Host = this.Host, + TrojanGoSettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } + + +} diff --git a/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs b/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs new file mode 100644 index 00000000..e4582958 --- /dev/null +++ b/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs @@ -0,0 +1,85 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class TrojanGoInstallViewModel : MvxViewModel + { + Host _host; + + TrojanGoSettings _settings; + + TrojanGoService _trojanGoService; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.TrojanGoSettings; + } + + public override Task Initialize() + { + _trojanGoService = new TrojanGoService(_host, _settings); + _trojanGoService.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _trojanGoService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _trojanGoService.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _trojanGoService.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress + { + get => _trojanGoService.Progress; + } + + public string Logs + { + get => _trojanGoService.Progress.Logs; + } + + + #region Command + + public IMvxCommand InstallCommand => new MvxCommand(_trojanGoService.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_trojanGoService.UpdateSettings); + + public IMvxCommand UninstallCommand => new MvxCommand(_trojanGoService.Uninstall); + + public IMvxCommand UploadCertCommand => new MvxCommand(_trojanGoService.UploadCert); + + public IMvxCommand UploadWebCommand => new MvxCommand(_trojanGoService.UploadWeb); + + public IMvxCommand ApplyForCertCommand => new MvxCommand(_trojanGoService.ApplyForCert); + + #endregion + + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".trojan-go.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/V2rayConfigViewModel.cs b/ProxySuper.Core/ViewModels/V2rayConfigViewModel.cs new file mode 100644 index 00000000..51fc185d --- /dev/null +++ b/ProxySuper.Core/ViewModels/V2rayConfigViewModel.cs @@ -0,0 +1,109 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class V2rayConfigViewModel : MvxViewModel + { + public V2raySettings Settings { get; set; } + + public override void Prepare(V2raySettings parameter) + { + Settings = parameter; + } + + + public bool Checked_VLESS_TCP + { + get + { + return Settings.Types.Contains(V2RayType.VLESS_TCP); + } + } + + public bool Checked_VLESS_WS + { + get + { + return Settings.Types.Contains(V2RayType.VLESS_WS); + } + } + + public bool Checked_VLESS_KCP + { + get + { + return Settings.Types.Contains(V2RayType.VLESS_KCP); + } + } + + public bool Checked_VLESS_QUIC + { + get + { + return Settings.Types.Contains(V2RayType.VLESS_QUIC); + } + } + + public bool Checked_VLESS_gRPC + { + get + { + return Settings.Types.Contains(V2RayType.VLESS_gRPC); + } + } + + public bool Checked_VMESS_TCP + { + get + { + return Settings.Types.Contains(V2RayType.VMESS_TCP); + } + } + + public bool Checked_VMESS_WS + { + get + { + return Settings.Types.Contains(V2RayType.VMESS_WS); + } + } + + public bool Checked_VMESS_KCP + { + get + { + return Settings.Types.Contains(V2RayType.VMESS_KCP); + } + } + + public bool Checked_VMESS_QUIC + { + get + { + return Settings.Types.Contains(V2RayType.VMESS_QUIC); + } + } + + public bool Checked_Trojan_TCP + { + get + { + return Settings.Types.Contains(V2RayType.Trojan_TCP); + } + } + + public bool CheckedShadowSocks + { + get + { + return Settings.Types.Contains(V2RayType.ShadowsocksAEAD); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/V2rayEditorViewModel.cs b/ProxySuper.Core/ViewModels/V2rayEditorViewModel.cs new file mode 100644 index 00000000..b8ac26bf --- /dev/null +++ b/ProxySuper.Core/ViewModels/V2rayEditorViewModel.cs @@ -0,0 +1,572 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace ProxySuper.Core.ViewModels +{ + public partial class V2rayEditorViewModel : MvxViewModel + { + public V2rayEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public string Id { get; set; } + + public Host Host { get; set; } + + public V2raySettings Settings { get; set; } + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public IMvxNavigationService NavigationService { get; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + Id = record.Id; + Host = record.Host; + Settings = record.V2raySettings; + } + + public void Save() + { + NavigationService.Close(this, new Record() + { + Id = Id, + Host = Host, + V2raySettings = Settings, + }); + } + + public void SaveAndInstall() + { + var record = new Record() + { + Id = Id, + Host = Host, + V2raySettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } + + public partial class V2rayEditorViewModel + { + public List KcpTypes => V2raySettings.DisguiseTypes; + + public List QuicTypes => V2raySettings.DisguiseTypes; + + /// + /// https://www.v2ray.com/chapter_02/transport/quic.html + /// + public List QuicSecurities => new List { + "none", + "aes-128-gcm", + "chacha20-poly1305" + }; + + /// + /// https://www.v2ray.com/chapter_02/protocols/shadowsocks.html + /// + public List ShadowSocksMethods => new List { + "aes-256-cfb", + "aes-128-cfb", + "chacha20", + "chacha20-ietf", + "aes-256-gcm", + "aes-128-gcm", + "chacha20-poly1305" + }; + + public IMvxCommand RandomUuid => new MvxCommand(() => GetUuid()); + + public bool WithTLS + { + get => Settings.WithTLS; + set + { + Settings.WithTLS = value; + RaisePropertyChanged("Port"); + } + } + + public int Port + { + get => Settings.Port; + set + { + Settings.Port = value; + RaisePropertyChanged("Port"); + } + } + + public int VLESS_KCP_Port + { + get => Settings.VLESS_KCP_Port; + set + { + Settings.VLESS_KCP_Port = value; + RaisePropertyChanged("VLESS_KCP_Port"); + } + } + + public int VMESS_KCP_Port + { + get => Settings.VMESS_KCP_Port; + set + { + Settings.VMESS_KCP_Port = value; + RaisePropertyChanged("VMESS_KCP_Port"); + } + } + + public string UUID + { + get => Settings.UUID; + set + { + Settings.UUID = value; + RaisePropertyChanged("UUID"); + } + } + + public string MultiUUID + { + get => string.Join(",", Settings.MulitUUID); + set + { + var input = value.Replace(',', ','); + var arr = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); + arr.RemoveAll(x => x == this.UUID); + Settings.MulitUUID = arr; + RaisePropertyChanged("MultiUUID"); + } + } + + public string Domain + { + get => Settings.Domain; + set + { + Settings.Domain = value; + RaisePropertyChanged("Domain"); + } + } + + public string MaskDomain + { + get => Settings.MaskDomain; + set + { + Settings.MaskDomain = value; + RaisePropertyChanged("MaskDomain"); + } + } + + #region Torjan + public string TrojanPassword + { + get => Settings.TrojanPassword; + set => Settings.TrojanPassword = value; + } + public bool Checked_Trojan_TCP + { + get + { + return Settings.Types.Contains(V2RayType.Trojan_TCP); + } + set + { + if (value == true) + { + if (!Settings.Types.Contains(V2RayType.Trojan_TCP)) + Settings.Types.Add(V2RayType.Trojan_TCP); + } + else + { + Settings.Types.Remove(V2RayType.Trojan_TCP); + } + RaisePropertyChanged("Checked_Trojan_TCP"); + } + } + public string Trojan_TCP_ShareLink + { + get => ShareLink.Build(V2RayType.Trojan_TCP, Settings); + } + #endregion + + #region ShadowSocks + public int ShadowSocksPort + { + get => Settings.ShadowSocksPort; + set + { + Settings.ShadowSocksPort = value; + RaisePropertyChanged("ShadowSocksPort"); + } + } + public bool CheckedShadowSocks + { + + get => Settings.Types.Contains(V2RayType.ShadowsocksAEAD); + set + { + CheckBoxChanged(value, V2RayType.ShadowsocksAEAD); + RaisePropertyChanged("CheckedShadowSocks"); + } + } + + public string ShadowSocksPassword + { + get => Settings.ShadowSocksPassword; + set => Settings.ShadowSocksPassword = value; + } + public string ShadowSocksMethod + { + get => Settings.ShadowSocksMethod; + set + { + var namespaceStr = typeof(ComboBoxItem).FullName + ":"; + var trimValue = value.Replace(namespaceStr, ""); + trimValue = trimValue.Trim(); + Settings.ShadowSocksMethod = trimValue; + RaisePropertyChanged("ShadowSocksMethod"); + } + } + public string ShadowSocksShareLink + { + get => ShareLink.Build(V2RayType.ShadowsocksAEAD, Settings); + } + #endregion + + + private void CheckBoxChanged(bool value, V2RayType type) + { + if (value == true) + { + if (!Settings.Types.Contains(type)) + { + Settings.Types.Add(type); + } + } + else + { + Settings.Types.RemoveAll(x => x == type); + } + } + + + + private void GetUuid() + { + UUID = Guid.NewGuid().ToString(); + RaisePropertyChanged("UUID"); + } + + } + + /// + /// VMESS SETTINGS + /// + public partial class V2rayEditorViewModel + { + #region VMESS TCP + public bool Checked_VMESS_TCP + { + get => Settings.Types.Contains(V2RayType.VMESS_TCP); + set + { + CheckBoxChanged(value, V2RayType.VMESS_TCP); + RaisePropertyChanged("Checked_VMESS_TCP"); + } + } + public string VMESS_TCP_Path + { + get => Settings.VMESS_TCP_Path; + set => Settings.VMESS_TCP_Path = value; + } + public string VMESS_TCP_ShareLink + { + get => ShareLink.Build(V2RayType.VMESS_TCP, Settings); + } + #endregion + + #region VMESS WS + public bool Checked_VMESS_WS + { + get => Settings.Types.Contains(V2RayType.VMESS_WS); + set + { + CheckBoxChanged(value, V2RayType.VMESS_WS); + RaisePropertyChanged("Checked_VMESS_WS"); + } + } + public string VMESS_WS_Path + { + get => Settings.VMESS_WS_Path; + set => Settings.VMESS_WS_Path = value; + } + public string VMESS_WS_ShareLink + { + get => ShareLink.Build(V2RayType.VMESS_WS, Settings); + } + #endregion + + #region VMESS KCP + public string VMESS_KCP_Seed + { + get => Settings.VMESS_KCP_Seed; + set => Settings.VMESS_KCP_Seed = value; + } + public string VMESS_KCP_Type + { + get => Settings.VMESS_KCP_Type; + set + { + var namespaceStr = typeof(ComboBoxItem).FullName + ":"; + var trimValue = value.Replace(namespaceStr, ""); + trimValue = trimValue.Trim(); + Settings.VMESS_KCP_Type = trimValue; + RaisePropertyChanged("VMESS_KCP_Type"); + } + } + public bool Checked_VMESS_KCP + { + get => Settings.Types.Contains(V2RayType.VMESS_KCP); + set + { + CheckBoxChanged(value, V2RayType.VMESS_KCP); + RaisePropertyChanged("Checked_VMESS_KCP"); + } + } + public string VMESS_KCP_ShareLink + { + get => ShareLink.Build(V2RayType.VMESS_KCP, Settings); + } + #endregion + + #region VMESS QUIC + public bool Checked_VMESS_QUIC + { + get => Settings.Types.Contains(V2RayType.VMESS_QUIC); + set + { + CheckBoxChanged(value, V2RayType.VMESS_QUIC); + RaisePropertyChanged(nameof(Checked_VMESS_QUIC)); + } + } + public string VMESS_QUIC_Key + { + get => Settings.VMESS_QUIC_Key; + set + { + Settings.VMESS_QUIC_Key = value; + RaisePropertyChanged(nameof(VMESS_QUIC_Key)); + } + } + public string VMESS_QUIC_Security + { + get => Settings.VMESS_QUIC_Security; + set + { + Settings.VMESS_QUIC_Security = value; + RaisePropertyChanged(nameof(VMESS_QUIC_Security)); + } + } + public string VMESS_QUIC_Type + { + get => Settings.VMESS_QUIC_Type; + set + { + Settings.VMESS_QUIC_Type = value; + RaisePropertyChanged(nameof(VMESS_QUIC_Type)); + } + } + public int VMESS_QUIC_Port + { + get => Settings.VMESS_QUIC_Port; + set + { + Settings.VMESS_QUIC_Port = value; + RaisePropertyChanged(nameof(VMESS_QUIC_Port)); + } + } + public string VMESS_QUIC_ShareLink + { + get => ShareLink.Build(V2RayType.VMESS_QUIC, Settings); + } + #endregion + + } + + + /// + /// VLESS SETTINGS + /// + public partial class V2rayEditorViewModel + { + #region VLESS TCP + public bool Checked_VLESS_TCP + { + get => Settings.Types.Contains(V2RayType.VLESS_TCP); + set + { + CheckBoxChanged(value, V2RayType.VLESS_TCP); + RaisePropertyChanged("Checked_VLESS_TCP"); + } + } + public string VLESS_TCP_ShareLink + { + get => ShareLink.Build(V2RayType.VLESS_TCP, Settings); + } + #endregion + + #region VLESS WS + public string VLESS_WS_Path + { + get => Settings.VLESS_WS_Path; + set => Settings.VLESS_WS_Path = value; + } + public bool Checked_VLESS_WS + { + get + { + return Settings.Types.Contains(V2RayType.VLESS_WS); + } + set + { + CheckBoxChanged(value, V2RayType.VLESS_WS); + RaisePropertyChanged("Checked_VLESS_WS"); + } + } + public string VLESS_WS_ShareLink + { + get => ShareLink.Build(V2RayType.VLESS_WS, Settings); + } + #endregion + + #region VLESS KCP + public string VLESS_KCP_Seed + { + get => Settings.VLESS_KCP_Seed; + set => Settings.VLESS_KCP_Seed = value; + } + public string VLESS_KCP_Type + { + get => Settings.VLESS_KCP_Type; + set + { + var namespaceStr = typeof(ComboBoxItem).FullName + ":"; + var trimValue = value.Replace(namespaceStr, ""); + trimValue = trimValue.Trim(); + Settings.VLESS_KCP_Type = trimValue; + RaisePropertyChanged("VLESS_KCP_Type"); + } + } + public bool Checked_VLESS_KCP + { + get => Settings.Types.Contains(V2RayType.VLESS_KCP); + set + { + CheckBoxChanged(value, V2RayType.VLESS_KCP); + RaisePropertyChanged("Checked_VLESS_KCP"); + } + } + public string VLESS_KCP_ShareLink + { + get => ShareLink.Build(V2RayType.VLESS_KCP, Settings); + } + #endregion + + #region VLESS QUIC + public bool Checked_VLESS_QUIC + { + get => Settings.Types.Contains(V2RayType.VLESS_QUIC); + set + { + CheckBoxChanged(value, V2RayType.VLESS_QUIC); + RaisePropertyChanged(nameof(Checked_VLESS_QUIC)); + } + } + public string VLESS_QUIC_Key + { + get => Settings.VLESS_QUIC_Key; set + { + Settings.VLESS_QUIC_Key = value; + RaisePropertyChanged(nameof(VLESS_QUIC_Key)); + } + } + public string VLESS_QUIC_Security + { + get => Settings.VLESS_QUIC_Security; + set + { + Settings.VLESS_QUIC_Security = value; + RaisePropertyChanged(nameof(VLESS_QUIC_Security)); + } + } + public string VLESS_QUIC_Type + { + get => Settings.VLESS_QUIC_Type; + set + { + Settings.VLESS_QUIC_Type = value; + RaisePropertyChanged(nameof(VLESS_QUIC_Type)); + } + } + public int VLESS_QUIC_Port + { + get => Settings.VLESS_QUIC_Port; + set + { + Settings.VLESS_QUIC_Port = value; + RaisePropertyChanged(nameof(VLESS_QUIC_Port)); + } + } + public string VLESS_QUIC_ShareLink + { + get => ShareLink.Build(V2RayType.VLESS_QUIC, Settings); + } + #endregion + + #region VLESS gRPC + public string VLESS_gRPC_ServiceName + { + get => Settings.VLESS_gRPC_ServiceName; + set => Settings.VLESS_gRPC_ServiceName = value; + } + public int VLESS_gRPC_Port + { + get => Settings.VLESS_gRPC_Port; + set => Settings.VLESS_gRPC_Port = value; + } + public bool Checked_VLESS_gRPC + { + get => Settings.Types.Contains(V2RayType.VLESS_gRPC); + set + { + CheckBoxChanged(value, V2RayType.VLESS_gRPC); + RaisePropertyChanged("Checked_VLESS_gRPC"); + } + } + public string VLESS_gRPC_ShareLink + { + get => ShareLink.Build(V2RayType.VLESS_gRPC, Settings); + } + #endregion + } +} diff --git a/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs b/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs new file mode 100644 index 00000000..0bfa7aa8 --- /dev/null +++ b/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs @@ -0,0 +1,88 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class V2rayInstallViewModel : MvxViewModel + { + Host _host; + + V2raySettings _settings; + + V2rayService _service; + + public override void ViewDestroy(bool viewFinishing = true) + { + _service.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public override void Prepare(Record parameter) + { + this._host = parameter.Host; + this._settings = parameter.V2raySettings; + } + + public override Task Initialize() + { + _service = new V2rayService(_host, _settings); + _service.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _service.Connect(); + + return base.Initialize(); + } + + public ProjectProgress Progress + { + get => _service.Progress; + } + + public string Logs + { + get => _service.Progress.Logs; + } + + + + #region Command + + public IMvxCommand InstallCommand => new MvxCommand(_service.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_service.UpdateSettings); + + public IMvxCommand UpdateV2rayCoreCommand => new MvxCommand(_service.UpdateV2rayCore); + + public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall); + + public IMvxCommand UploadCertCommand => new MvxCommand(_service.UploadCert); + + public IMvxCommand UploadWebCommand => new MvxCommand(_service.UploadWeb); + + public IMvxCommand ApplyForCertCommand => new MvxCommand(_service.ApplyForCert); + + #endregion + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".v2ray.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/XrayConfigViewModel.cs b/ProxySuper.Core/ViewModels/XrayConfigViewModel.cs new file mode 100644 index 00000000..1b6851d3 --- /dev/null +++ b/ProxySuper.Core/ViewModels/XrayConfigViewModel.cs @@ -0,0 +1,92 @@ +using MvvmCross.ViewModels; +using ProxySuper.Core.Models.Projects; + +namespace ProxySuper.Core.ViewModels +{ + public class XrayConfigViewModel : MvxViewModel + { + + public XraySettings Settings { get; set; } + + public override void Prepare(XraySettings parameter) + { + Settings = parameter; + } + + public string Flow + { + get { return Settings.Flow; } + } + + public string UTLS + { + get { return Settings.UTLS; } + } + + public bool Checked_VLESS_XTLS_RAW_REALITY + { + get + { + return Settings.Types.Contains(XrayType.VLESS_XTLS_RAW_REALITY); + } + } + + + public bool Checked_VLESS_RAW_XTLS + { + get + { + return Settings.Types.Contains(XrayType.VLESS_RAW_XTLS); + } + } + + + public bool Checked_VLESS_XHTTP + { + get + { + return Settings.Types.Contains(XrayType.VLESS_XHTTP); + } + } + + public bool Checked_VLESS_WS + { + get + { + return Settings.Types.Contains(XrayType.VLESS_WS); + } + } + + public bool Checked_VLESS_gRPC + { + get + { + return Settings.Types.Contains(XrayType.VLESS_gRPC); + } + } + + public bool Checked_VMESS_KCP + { + get + { + return Settings.Types.Contains(XrayType.VMESS_KCP); + } + } + + public bool Checked_Trojan_TCP + { + get + { + return Settings.Types.Contains(XrayType.Trojan_TCP); + } + } + + public bool CheckedShadowSocks + { + get + { + return Settings.Types.Contains(XrayType.ShadowsocksAEAD); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs new file mode 100644 index 00000000..42043675 --- /dev/null +++ b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs @@ -0,0 +1,507 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using Newtonsoft.Json.Linq; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using System.Windows.Controls; + +namespace ProxySuper.Core.ViewModels +{ + public partial class XrayEditorViewModel : MvxViewModel + { + public XrayEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + + public string Id { get; set; } + + public Host Host { get; set; } + + public XraySettings Settings { get; set; } + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public IMvxNavigationService NavigationService { get; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + Id = record.Id; + Host = record.Host; + Settings = record.XraySettings; + } + + public void Save() + { + if (Settings.Types.Count > 0) + { + NavigationService.Close(this, new Record() + { + Id = Id, + Host = Host, + XraySettings = Settings, + }); + } + else + { + MessageBox.Show("Error:No configuration was selected!", "Tips"); + } + + } + + public void SaveAndInstall() + { + if (Settings.Types.Count > 0) + { + var record = new Record() + { + Id = Id, + Host = Host, + XraySettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + else + { + MessageBox.Show("Error:No configuration was selected!", "Tips"); + } + + } + } + + public partial class XrayEditorViewModel + { + public List UTLSList { get => XraySettings.UTLSList; } + + /* + public List QuicTypes => XraySettings.DisguiseTypes; + + public List QuicSecurities => new List + { + "none", + "aes-128-gcm", + "chacha20-poly1305" + }; + */ + + public IMvxCommand RandomUuid => new MvxCommand(() => GetUuid()); + + public bool WithTLS + { + get => Settings.WithTLS; + set + { + Settings.WithTLS = value; + RaisePropertyChanged("WithTLS"); + } + } + + public int Port + { + get => Settings.Port; + set + { + Settings.Port = value; + RaisePropertyChanged("Port"); + } + } + + + public string UTLS + { + get => Settings.UTLS; + set + { + Settings.UTLS = value; + RaisePropertyChanged(nameof(UTLS)); + } + } + + + public int VMESS_KCP_Port + { + get => Settings.VMESS_KCP_Port; + set + { + Settings.VMESS_KCP_Port = value; + RaisePropertyChanged("VMESS_KCP_Port"); + } + } + + public string UUID + { + get => Settings.UUID; + set + { + Settings.UUID = value; + RaisePropertyChanged("UUID"); + } + } + + public string MultiUUID + { + get => string.Join(",", Settings.MulitUUID); + set + { + var input = value.Replace(',', ','); + var arr = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); + arr.RemoveAll(x => x == this.UUID); + Settings.MulitUUID = arr; + RaisePropertyChanged("MultiUUID"); + } + } + + public string Domain + { + get => Settings.Domain; + set + { + Settings.Domain = value; + RaisePropertyChanged("Domain"); + } + } + + public string MaskDomain + { + get => Settings.MaskDomain; + set + { + Settings.MaskDomain = value; + RaisePropertyChanged("MaskDomain"); + } + } + + #region Trojan + public string TrojanPassword + { + get => Settings.TrojanPassword; + set => Settings.TrojanPassword = value; + } + + public bool Checked_Trojan_TCP + { + get + { + return Settings.Types.Contains(XrayType.Trojan_TCP); + } + set + { + if (value == true) + { + if (!Settings.Types.Contains(XrayType.Trojan_TCP)) + Settings.Types.Add(XrayType.Trojan_TCP); + } + else + { + Settings.Types.Remove(XrayType.Trojan_TCP); + } + RaisePropertyChanged("Checked_Trojan_TCP"); + } + } + public string Trojan_TCP_ShareLink + { + get => ShareLink.XrayBuild(XrayType.Trojan_TCP, Settings); + } + #endregion + + #region ShadowSocks + public int ShadowSocksPort + { + get => Settings.ShadowSocksPort; + set + { + Settings.ShadowSocksPort = value; + RaisePropertyChanged("ShadowSocksPort"); + } + } + public bool CheckedShadowSocks + { + + get => Settings.Types.Contains(XrayType.ShadowsocksAEAD); + set + { + CheckBoxChanged(value, XrayType.ShadowsocksAEAD); + RaisePropertyChanged("CheckedShadowSocks"); + } + } + public string ShadowSocksPassword + { + get => Settings.ShadowSocksPassword; + set => Settings.ShadowSocksPassword = value; + } + public List ShadowSocksMethods => new List + { + "2022-blake3-aes-128-gcm", + "2022-blake3-aes-256-gcm", + "2022-blake3-chacha20-poly1305", + "aes-256-gcm", + "aes-128-gcm", + "chacha20-poly1305", + "none" + }; + public string ShadowSocksMethod + { + get => Settings.ShadowSocksMethod; + set + { + var namespaceStr = typeof(ComboBoxItem).FullName + ":"; + var trimValue = value.Replace(namespaceStr, ""); + trimValue = trimValue.Trim(); + Settings.ShadowSocksMethod = trimValue; + RaisePropertyChanged("ShadowSocksMethod"); + } + } + public string ShadowSocksShareLink + { + get => ShareLink.XrayBuild(XrayType.ShadowsocksAEAD, Settings); + } + #endregion + + private void CheckBoxChanged(bool value, XrayType type) + { + if (value == true) + { + if (!Settings.Types.Contains(type)) + { + Settings.Types.Add(type); + } + } + else + { + Settings.Types.RemoveAll(x => x == type); + } + } + + private void GetUuid() + { + UUID = Guid.NewGuid().ToString(); + RaisePropertyChanged("UUID"); + } + + } + + /// + /// VMESS + /// + public partial class XrayEditorViewModel + { + + #region VMESS KCP + public List KcpTypes => XraySettings.DisguiseTypes; + public string VMESS_KCP_Seed + { + get => Settings.VMESS_KCP_Seed; + set => Settings.VMESS_KCP_Seed = value; + } + public string VMESS_KCP_Type + { + get => Settings.VMESS_KCP_Type; + set + { + var namespaceStr = typeof(ComboBoxItem).FullName + ":"; + var trimValue = value.Replace(namespaceStr, ""); + trimValue = trimValue.Trim(); + Settings.VMESS_KCP_Type = trimValue; + RaisePropertyChanged("VMESS_KCP_Type"); + } + } + public bool Checked_VMESS_KCP + { + get => Settings.Types.Contains(XrayType.VMESS_KCP); + set + { + CheckBoxChanged(value, XrayType.VMESS_KCP); + RaisePropertyChanged("Checked_VMESS_KCP"); + if(value && !Checked_VLESS_RAW_XTLS +  && !Checked_VLESS_WS +  && !Checked_VLESS_gRPC +  && !Checked_Trojan_TCP) + { + WithTLS = false; + } + else + { + WithTLS = true; + } + } + } + public string VMESS_KCP_ShareLink + { + get => ShareLink.XrayBuild(XrayType.VMESS_KCP, Settings); + } + #endregion + + } + + /// + /// VLESS + /// + public partial class XrayEditorViewModel + { + + public List FlowList { get => XraySettings.FlowList; } + + public string Flow + { + get => Settings.Flow; + set + { + Settings.Flow = value; + RaisePropertyChanged(nameof(Flow)); + } + } + + public string REALITY_spiderX + { + get => Settings.REALITY_spiderX; + set => Settings.REALITY_spiderX = value; + } + + + #region VLESS XTLS(RAW) REALITY + + public bool Checked_VLESS_XTLS_RAW_REALITY + { + get => Settings.Types.Contains(XrayType.VLESS_XTLS_RAW_REALITY); + set + { + CheckBoxChanged(value, XrayType.VLESS_XTLS_RAW_REALITY); + RaisePropertyChanged("Checked_VLESS_XTLS_RAW_REALITY"); + if (value) + { + WithTLS = false; + } + else + { + WithTLS = true; + } + } + } + public string VLESS_XTLS_RAW_REALITY_ShareLink + { + get => ShareLink.XrayBuild(XrayType.VLESS_XTLS_RAW_REALITY, Settings); + } + + #endregion + + #region VLESS XTLS(RAW) + + public bool Checked_VLESS_RAW_XTLS + { + get => Settings.Types.Contains(XrayType.VLESS_RAW_XTLS); + set + { + CheckBoxChanged(value, XrayType.VLESS_RAW_XTLS); + RaisePropertyChanged("Checked_VLESS_RAW_XTLS"); + if (value) + { + WithTLS = true; + } + } + } + public string VLESS_RAW_XTLS_ShareLink + { + get => ShareLink.XrayBuild(XrayType.VLESS_RAW_XTLS, Settings); + } + #endregion + + #region VLESS XHTTP + public string VLESS_XHTTP_Path + { + get => Settings.VLESS_XHTTP_Path; + set => Settings.VLESS_XHTTP_Path = value; + } + public bool Checked_VLESS_XHTTP + { + get + { + return Settings.Types.Contains(XrayType.VLESS_XHTTP); + } + set + { + CheckBoxChanged(value, XrayType.VLESS_XHTTP); + RaisePropertyChanged("Checked_VLESS_XHTTP"); + if (value) + { + WithTLS = true; + } + } + } + public string VLESS_XHTTP_ShareLink + { + get => ShareLink.XrayBuild(XrayType.VLESS_XHTTP, Settings); + } + #endregion + + #region VLESS WS + public string VLESS_WS_Path + { + get => Settings.VLESS_WS_Path; + set => Settings.VLESS_WS_Path = value; + } + public bool Checked_VLESS_WS + { + get + { + return Settings.Types.Contains(XrayType.VLESS_WS); + } + set + { + CheckBoxChanged(value, XrayType.VLESS_WS); + RaisePropertyChanged("Checked_VLESS_WS"); + if (value) + { + WithTLS = true; + } + } + } + public string VLESS_WS_ShareLink + { + get => ShareLink.XrayBuild(XrayType.VLESS_WS, Settings); + } + #endregion + + #region VLESS gRPC + public string VLESS_gRPC_ServiceName + { + get => Settings.VLESS_gRPC_ServiceName; + set => Settings.VLESS_gRPC_ServiceName = value; + } + public int VLESS_gRPC_Port + { + get => Settings.VLESS_gRPC_Port; + set => Settings.VLESS_gRPC_Port = value; + } + public bool Checked_VLESS_gRPC + { + get => Settings.Types.Contains(XrayType.VLESS_gRPC); + set + { + CheckBoxChanged(value, XrayType.VLESS_gRPC); + RaisePropertyChanged("Checked_VLESS_gRPC"); + if (value) + { + WithTLS = true; + } + } + } + public string VLESS_gRPC_ShareLink + { + get => ShareLink.XrayBuild(XrayType.VLESS_gRPC, Settings); + } + #endregion + } + +} diff --git a/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs b/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs new file mode 100644 index 00000000..f7d483e3 --- /dev/null +++ b/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs @@ -0,0 +1,88 @@ +using MvvmCross.Commands; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class XrayInstallViewModel : MvxViewModel + { + Host _host; + + XraySettings _settings; + + XrayService _xrayService; + + public override void ViewDestroy(bool viewFinishing = true) + { + _xrayService.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public override void Prepare(Record parameter) + { + this._host = parameter.Host; + this._settings = parameter.XraySettings; + } + + public override Task Initialize() + { + _xrayService = new XrayService(_host, _settings); + _xrayService.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _xrayService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _xrayService.Connect(); + + return base.Initialize(); + } + + public ProjectProgress Progress + { + get => _xrayService.Progress; + } + + public string Logs + { + get => _xrayService.Progress.Logs; + } + + + + #region Command + + public IMvxCommand InstallCommand => new MvxCommand(_xrayService.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_xrayService.UpdateSettings); + + public IMvxCommand UpdateXrayCoreCommand => new MvxCommand(_xrayService.UpdateXrayCore); + + public IMvxCommand UninstallCommand => new MvxCommand(_xrayService.Uninstall); + + public IMvxCommand UploadCertCommand => new MvxCommand(_xrayService.UploadCert); + + public IMvxCommand UploadWebCommand => new MvxCommand(_xrayService.UploadWeb); + + public IMvxCommand ApplyForCertCommand => new MvxCommand(_xrayService.ApplyForCert); + + #endregion + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".xary.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/app.config b/ProxySuper.Core/app.config new file mode 100644 index 00000000..0703d682 --- /dev/null +++ b/ProxySuper.Core/app.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProxySuper.Core/packages.config b/ProxySuper.Core/packages.config new file mode 100644 index 00000000..a3cfb0cd --- /dev/null +++ b/ProxySuper.Core/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProxySuper.WPF/App.config b/ProxySuper.WPF/App.config new file mode 100644 index 00000000..66da88ef --- /dev/null +++ b/ProxySuper.WPF/App.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/ProxySuper.WPF/App.xaml b/ProxySuper.WPF/App.xaml new file mode 100644 index 00000000..daea7fd7 --- /dev/null +++ b/ProxySuper.WPF/App.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/ProxySuper.WPF/App.xaml.cs b/ProxySuper.WPF/App.xaml.cs new file mode 100644 index 00000000..1eb4bc6e --- /dev/null +++ b/ProxySuper.WPF/App.xaml.cs @@ -0,0 +1,17 @@ +using MvvmCross.Core; +using MvvmCross.Platforms.Wpf.Core; +using MvvmCross.Platforms.Wpf.Views; + +namespace ProxySuper.WPF +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : MvxApplication + { + protected override void RegisterSetup() + { + this.RegisterSetupType(); + } + } +} diff --git a/ProxySuper.WPF/Controls/AdCarouselControl.xaml b/ProxySuper.WPF/Controls/AdCarouselControl.xaml new file mode 100644 index 00000000..eb77e541 --- /dev/null +++ b/ProxySuper.WPF/Controls/AdCarouselControl.xaml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +