├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── docker.yml │ └── go.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── api └── router.go ├── app.json ├── assets ├── GeoLite2-City.mmdb ├── flags.json ├── html │ ├── 1clash-config.yaml1 │ ├── 2clash-config.yaml │ ├── clash-config.yaml │ ├── clash.html │ ├── index.html │ ├── surge.conf │ └── surge.html └── proxy.jpg ├── config ├── config.go ├── config.yaml ├── source.go └── source.yaml ├── docs ├── fast.png ├── genbindata.sh └── speedtest.png ├── go.mod ├── go.sum ├── internal ├── app │ ├── getter.go │ └── task.go ├── bindata │ ├── geoip │ │ └── geoip.go │ └── html │ │ └── html.go ├── cache │ ├── cache.go │ └── vars.go ├── cloudflare │ └── cache.go ├── cron │ └── cron.go └── database │ ├── db.go │ ├── db_test.go │ └── proxy.go ├── main.go └── pkg ├── getter ├── base.go ├── subscribe.go ├── tgchannel.go ├── web_fanqiangdang.go ├── web_free_ssr_xyz.go ├── web_fuzz.go └── web_fuzz_sub.go ├── provider ├── base.go ├── clash.go ├── ssrsub.go ├── sssub.go ├── surge.go └── vmesssub.go ├── proxy ├── base.go ├── check.go ├── convert.go ├── geoip.go ├── link_test.go ├── proxies.go ├── shadowsocks.go ├── shadowsocksr.go ├── trojan.go └── vmess.go └── tool ├── base64.go ├── check.go ├── colly.go ├── httpclient.go ├── option.go └── unicode.go /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] ['zu1k'] 4 | patreon: zu1k # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | 8 | - package-ecosystem: "docker" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | 13 | - package-ecosystem: "gomod" 14 | directory: "/" 15 | schedule: 16 | interval: "daily" 17 | 18 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: docker 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: Build 8 | if: startsWith(github.ref, 'refs/tags/') 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Check out code into the Go module directory 12 | uses: actions/checkout@v2.3.2 13 | 14 | - name: Build and push Docker images 15 | uses: docker/build-push-action@v1.1.0 16 | with: 17 | username: doudoubinga 18 | password: ${{ secrets.GITHUB_TOKEN }} 19 | registry: docker.pkg.github.com 20 | repository: doudoubinga/proxypool/proxypool 21 | tag_with_ref: true 22 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | on: [push, pull_request] 3 | jobs: 4 | 5 | build: 6 | name: Build 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Setup Go 10 | uses: actions/setup-go@v2 11 | with: 12 | go-version: 1.14.x 13 | 14 | - name: Check out code into the Go module directory 15 | uses: actions/checkout@v2.3.2 16 | 17 | - name: Cache go module 18 | uses: actions/cache@v2 19 | with: 20 | path: ~/go/pkg/mod 21 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 22 | restore-keys: | 23 | ${{ runner.os }}-go- 24 | 25 | - name: Get dependencies and run test 26 | run: | 27 | go test ./... 28 | 29 | - name: gen go-bindata 30 | if: startsWith(github.ref, 'refs/tags/') 31 | run: | 32 | go get -u github.com/go-bindata/go-bindata/... 33 | go-bindata -o internal/bindata/geoip/geoip.go -pkg bingeoip assets/GeoLite2-City.mmdb assets/flags.json 34 | 35 | - name: Build 36 | if: startsWith(github.ref, 'refs/tags/') 37 | env: 38 | NAME: proxypool 39 | BINDIR: bin 40 | run: make -j releases 41 | 42 | - name: Upload Release 43 | uses: softprops/action-gh-release@v1 44 | if: startsWith(github.ref, 'refs/tags/') 45 | env: 46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 47 | with: 48 | files: bin/* 49 | draft: true 50 | prerelease: true 51 | 52 | - uses: actions/upload-artifact@v2.1.4 53 | if: startsWith(github.ref, 'refs/tags/') 54 | with: 55 | name: build 56 | path: bin 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | bin/* 8 | 9 | # Test binary, build with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # dep 16 | vendor 17 | 18 | # GoLand 19 | .idea/* 20 | 21 | # macOS file 22 | .DS_Store 23 | 24 | assets/html/ 25 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:alpine as builder 2 | 3 | RUN apk add --no-cache make git 4 | WORKDIR /proxypool-src 5 | COPY . /proxypool-src 6 | RUN go mod download && \ 7 | make docker && \ 8 | mv ./bin/proxypool-docker /proxypool 9 | 10 | FROM alpine:latest 11 | 12 | RUN apk add --no-cache ca-certificates tzdata 13 | WORKDIR /proxypool-src 14 | COPY ./assets /proxypool-src/assets 15 | COPY --from=builder /proxypool /proxypool-src/ 16 | ENTRYPOINT ["/proxypool-src/proxypool"] 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME=proxypool 2 | BINDIR=bin 3 | VERSION=$(shell git describe --tags || echo "unknown version") 4 | GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags '-w -s' 5 | 6 | PLATFORM_LIST = \ 7 | darwin-amd64 \ 8 | linux-386 \ 9 | linux-amd64 \ 10 | linux-armv5 \ 11 | linux-armv6 \ 12 | linux-armv7 \ 13 | linux-armv8 \ 14 | linux-mips-softfloat \ 15 | linux-mips-hardfloat \ 16 | linux-mipsle-softfloat \ 17 | linux-mipsle-hardfloat \ 18 | linux-mips64 \ 19 | linux-mips64le \ 20 | freebsd-386 \ 21 | freebsd-amd64 22 | 23 | 24 | all: linux-amd64 darwin-amd64 25 | 26 | docker: 27 | $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 28 | 29 | darwin-amd64: 30 | GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 31 | 32 | linux-386: 33 | GOARCH=386 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 34 | 35 | linux-amd64: 36 | GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 37 | 38 | linux-armv5: 39 | GOARCH=arm GOOS=linux GOARM=5 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 40 | 41 | linux-armv6: 42 | GOARCH=arm GOOS=linux GOARM=6 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 43 | 44 | linux-armv7: 45 | GOARCH=arm GOOS=linux GOARM=7 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 46 | 47 | linux-armv8: 48 | GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 49 | 50 | linux-mips-softfloat: 51 | GOARCH=mips GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 52 | 53 | linux-mips-hardfloat: 54 | GOARCH=mips GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 55 | 56 | linux-mipsle-softfloat: 57 | GOARCH=mipsle GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 58 | 59 | linux-mipsle-hardfloat: 60 | GOARCH=mipsle GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 61 | 62 | linux-mips64: 63 | GOARCH=mips64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 64 | 65 | linux-mips64le: 66 | GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 67 | 68 | freebsd-386: 69 | GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 70 | 71 | freebsd-amd64: 72 | GOARCH=amd64 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ 73 | 74 | gz_releases=$(addsuffix .gz, $(PLATFORM_LIST)) 75 | 76 | $(gz_releases): %.gz : % 77 | chmod +x $(BINDIR)/$(NAME)-$(basename $@) 78 | gzip -f -S -$(VERSION).gz $(BINDIR)/$(NAME)-$(basename $@) 79 | 80 | all-arch: $(PLATFORM_LIST) 81 | 82 | releases: $(gz_releases) 83 | clean: 84 | rm $(BINDIR)/* 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 3 | 4 | This project is only for personal use. It is forbidden to use this project for profit making and other illegal activities. The project will not be responsible for all the consequences 5 | -------------------------------------------------------------------------------- /api/router.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "html/template" 5 | "net/http" 6 | "os" 7 | "strconv" 8 | "time" 9 | 10 | "github.com/gin-contrib/cache" 11 | "github.com/gin-contrib/cache/persistence" 12 | "github.com/gin-gonic/gin" 13 | _ "github.com/heroku/x/hmetrics/onload" 14 | "github.com/doudoubinga/proxypool/config" 15 | binhtml "github.com/doudoubinga/proxypool/internal/bindata/html" 16 | C "github.com/doudoubinga/proxypool/internal/cache" 17 | "github.com/doudoubinga/proxypool/pkg/provider" 18 | ) 19 | 20 | const version = "v0.3.10" 21 | 22 | var router *gin.Engine 23 | 24 | func setupRouter() { 25 | gin.SetMode(gin.ReleaseMode) 26 | router = gin.New() 27 | store := persistence.NewInMemoryStore(time.Minute) 28 | router.Use(gin.Recovery(), cache.SiteCache(store, time.Minute)) 29 | temp, err := loadTemplate() 30 | if err != nil { 31 | panic(err) 32 | } 33 | router.SetHTMLTemplate(temp) 34 | 35 | router.GET("/", func(c *gin.Context) { 36 | c.HTML(http.StatusOK, "assets/html/index.html", gin.H{ 37 | "domain": config.Config.Domain, 38 | "getters_count": C.GettersCount, 39 | "all_proxies_count": C.AllProxiesCount, 40 | "ss_proxies_count": C.SSProxiesCount, 41 | "ssr_proxies_count": C.SSRProxiesCount, 42 | "vmess_proxies_count": C.VmessProxiesCount, 43 | "trojan_proxies_count": C.TrojanProxiesCount, 44 | "useful_proxies_count": C.UsefullProxiesCount, 45 | "last_crawl_time": C.LastCrawlTime, 46 | "version": version, 47 | }) 48 | }) 49 | 50 | router.GET("/clash", func(c *gin.Context) { 51 | c.HTML(http.StatusOK, "assets/html/clash.html", gin.H{ 52 | "domain": config.Config.Domain, 53 | }) 54 | }) 55 | 56 | router.GET("/surge", func(c *gin.Context) { 57 | c.HTML(http.StatusOK, "assets/html/surge.html", gin.H{ 58 | "domain": config.Config.Domain, 59 | }) 60 | }) 61 | 62 | router.GET("/clash/config", func(c *gin.Context) { 63 | c.HTML(http.StatusOK, "assets/html/clash-config.yaml", gin.H{ 64 | "domain": config.Config.Domain, 65 | }) 66 | }) 67 | 68 | router.GET("/surge/config", func(c *gin.Context) { 69 | c.HTML(http.StatusOK, "assets/html/surge.conf", gin.H{ 70 | "domain": config.Config.Domain, 71 | }) 72 | }) 73 | 74 | router.GET("/clash/proxies", func(c *gin.Context) { 75 | proxyTypes := c.DefaultQuery("type", "") 76 | proxyCountry := c.DefaultQuery("c", "") 77 | proxyNotCountry := c.DefaultQuery("nc", "") 78 | text := "" 79 | if proxyTypes == "" && proxyCountry == "" && proxyNotCountry == "" { 80 | text = C.GetString("clashproxies") 81 | if text == "" { 82 | proxies := C.GetProxies("proxies") 83 | clash := provider.Clash{ 84 | provider.Base{ 85 | Proxies: &proxies, 86 | }, 87 | } 88 | text = clash.Provide() 89 | C.SetString("clashproxies", text) 90 | } 91 | } else if proxyTypes == "all" { 92 | proxies := C.GetProxies("allproxies") 93 | clash := provider.Clash{ 94 | provider.Base{ 95 | Proxies: &proxies, 96 | Types: proxyTypes, 97 | Country: proxyCountry, 98 | NotCountry: proxyNotCountry, 99 | }, 100 | } 101 | text = clash.Provide() 102 | } else { 103 | proxies := C.GetProxies("proxies") 104 | clash := provider.Clash{ 105 | provider.Base{ 106 | Proxies: &proxies, 107 | Types: proxyTypes, 108 | Country: proxyCountry, 109 | NotCountry: proxyNotCountry, 110 | }, 111 | } 112 | text = clash.Provide() 113 | } 114 | c.String(200, text) 115 | }) 116 | 117 | router.GET("/surge/proxies", func(c *gin.Context) { 118 | proxyTypes := c.DefaultQuery("type", "") 119 | proxyCountry := c.DefaultQuery("c", "") 120 | proxyNotCountry := c.DefaultQuery("nc", "") 121 | text := "" 122 | if proxyTypes == "" && proxyCountry == "" && proxyNotCountry == "" { 123 | text = C.GetString("surgeproxies") 124 | if text == "" { 125 | proxies := C.GetProxies("proxies") 126 | surge := provider.Surge{ 127 | provider.Base{ 128 | Proxies: &proxies, 129 | }, 130 | } 131 | text = surge.Provide() 132 | C.SetString("surgeproxies", text) 133 | } 134 | } else if proxyTypes == "all" { 135 | proxies := C.GetProxies("allproxies") 136 | surge := provider.Surge{ 137 | provider.Base{ 138 | Proxies: &proxies, 139 | Types: proxyTypes, 140 | Country: proxyCountry, 141 | NotCountry: proxyNotCountry, 142 | }, 143 | } 144 | text = surge.Provide() 145 | } else { 146 | proxies := C.GetProxies("proxies") 147 | surge := provider.Surge{ 148 | provider.Base{ 149 | Proxies: &proxies, 150 | Types: proxyTypes, 151 | Country: proxyCountry, 152 | NotCountry: proxyNotCountry, 153 | }, 154 | } 155 | text = surge.Provide() 156 | } 157 | c.String(200, text) 158 | }) 159 | 160 | router.GET("/ss/sub", func(c *gin.Context) { 161 | proxies := C.GetProxies("proxies") 162 | ssSub := provider.SSSub{ 163 | provider.Base{ 164 | Proxies: &proxies, 165 | Types: "ss", 166 | }, 167 | } 168 | c.String(200, ssSub.Provide()) 169 | }) 170 | 171 | router.GET("/ssr/sub", func(c *gin.Context) { 172 | proxies := C.GetProxies("proxies") 173 | ssrSub := provider.SSRSub{ 174 | provider.Base{ 175 | Proxies: &proxies, 176 | Types: "ssr", 177 | }, 178 | } 179 | c.String(200, ssrSub.Provide()) 180 | }) 181 | 182 | router.GET("/vmess/sub", func(c *gin.Context) { 183 | proxies := C.GetProxies("proxies") 184 | vmessSub := provider.VmessSub{ 185 | provider.Base{ 186 | Proxies: &proxies, 187 | Types: "vmess", 188 | }, 189 | } 190 | c.String(200, vmessSub.Provide()) 191 | }) 192 | 193 | router.GET("/sip002/sub", func(c *gin.Context) { 194 | proxies := C.GetProxies("proxies") 195 | sip002Sub := provider.SIP002Sub{ 196 | provider.Base{ 197 | Proxies: &proxies, 198 | Types: "ss", 199 | }, 200 | } 201 | c.String(200, sip002Sub.Provide()) 202 | }) 203 | 204 | router.GET("/link/:id", func(c *gin.Context) { 205 | idx := c.Param("id") 206 | proxies := C.GetProxies("allproxies") 207 | id, err := strconv.Atoi(idx) 208 | if err != nil { 209 | c.String(500, err.Error()) 210 | } 211 | if id >= proxies.Len() || id < 0 { 212 | c.String(500, "id out of range") 213 | } 214 | c.String(200, proxies[id].Link()) 215 | }) 216 | } 217 | 218 | func Run() { 219 | setupRouter() 220 | port := os.Getenv("PORT") 221 | if port == "" { 222 | port = "8080" 223 | } 224 | router.Run(":" + port) 225 | } 226 | 227 | func loadTemplate() (t *template.Template, err error) { 228 | _ = binhtml.RestoreAssets("", "assets/html") 229 | t = template.New("") 230 | for _, fileName := range binhtml.AssetNames() { 231 | data := binhtml.MustAsset(fileName) 232 | t, err = t.New(fileName).Parse(string(data)) 233 | if err != nil { 234 | return nil, err 235 | } 236 | } 237 | return t, nil 238 | } 239 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ceshi3332", 3 | "description": "ceshi", 4 | "website": "https://www.youtube.com/channel/UClceV39J1Z_9D4_mHkBZrMg?sub_confirmation=1", 5 | "repository": "", 6 | "success_url": "/", 7 | "logo": "", 8 | "keywords": [""], 9 | "env": { 10 | "CONFIG_FILE": { 11 | "description": "" 12 | }, 13 | "DOMAIN": { 14 | "description": "" 15 | }, 16 | "CF_API_EMAIL": { 17 | "description": "", 18 | "required": false 19 | }, 20 | "CF_API_KEY": { 21 | "description": "", 22 | "required": false 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /assets/GeoLite2-City.mmdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doudoubinga/proxypool/b7ed82d783149ac2704ec9ed965c374682c4c47c/assets/GeoLite2-City.mmdb -------------------------------------------------------------------------------- /assets/html/2clash-config.yaml: -------------------------------------------------------------------------------- 1 | 2 | # port of HTTP 3 | port: 7890 4 | 5 | # port of SOCKS5 6 | socks-port: 7891 7 | 8 | # (HTTP and SOCKS5 in one port) 9 | # mixed-port: 7890 10 | 11 | # redir port for Linux and macOS 12 | # redir-port: 7892 13 | 14 | allow-lan: false 15 | mode: rule 16 | log-level: info 17 | external-controller: 127.0.0.1:9090 18 | 19 | proxies: 20 | 21 | 22 | 23 | proxy-groups: 24 | - name: 全局选择 25 | type: select 26 | proxies: 27 | - 负载均衡 28 | - 延迟最低 29 | - 手选本地 30 | - 手选延迟 31 | - 手选云1 32 | - 手选云2 33 | - 手选云3 34 | - 手选云4 35 | - 手选云5 36 | - 手选云6 37 | - 手选云7 38 | - 手选云8 39 | - 手选云9 40 | - 手选云10 41 | - 手选云11 42 | - 手选云12 43 | 44 | 45 | - name: 负载均衡 46 | type: load-balance 47 | url: 'http://www.gstatic.com/generate_204' 48 | interval: 300 49 | proxies: 50 | - 筛选1 51 | - 筛选2 52 | - 筛选3 53 | - 筛选4 54 | - 筛选5 55 | - 筛选6 56 | - 筛选7 57 | - 筛选8 58 | - 筛选9 59 | - 筛选10 60 | - 筛选11 61 | - 筛选13 62 | - 本地 63 | 64 | - name: 延迟最低 65 | type: url-test 66 | url: 'http://www.gstatic.com/generate_204' 67 | interval: 300 68 | proxies: 69 | - 筛选1 70 | - 筛选2 71 | - 筛选3 72 | - 筛选4 73 | - 筛选5 74 | - 筛选6 75 | - 筛选7 76 | - 筛选8 77 | - 筛选9 78 | - 筛选10 79 | - 筛选11 80 | - 筛选13 81 | - 本地 82 | - name: 手选本地 83 | type: select 84 | use: 85 | - test 86 | - name: 手选延迟 87 | type: select 88 | proxies: 89 | - 筛选1 90 | - 筛选2 91 | - 筛选3 92 | - 筛选4 93 | - 筛选5 94 | - 筛选6 95 | - 筛选7 96 | - 筛选8 97 | - 筛选9 98 | - 筛选10 99 | - 筛选11 100 | - 筛选13 101 | - 本地 102 | 103 | - name: 手选云1 104 | type: select 105 | use: 106 | - websub1 107 | - name: 手选云2 108 | type: select 109 | use: 110 | - websub2 111 | - name: 手选云3 112 | type: select 113 | use: 114 | - websub3 115 | - name: 手选云4 116 | type: select 117 | use: 118 | - websub4 119 | - name: 手选云5 120 | type: select 121 | use: 122 | - websub5 123 | - name: 手选云6 124 | type: select 125 | use: 126 | - websub6 127 | - name: 手选云7 128 | type: select 129 | use: 130 | - websub7 131 | - name: 手选云8 132 | type: select 133 | use: 134 | - websub8 135 | - name: 手选云9 136 | type: select 137 | use: 138 | - websub9 139 | - name: 手选云10 140 | type: select 141 | use: 142 | - websub10 143 | - name: 手选云11 144 | type: select 145 | use: 146 | - websub11 147 | - name: 手选云12 148 | type: select 149 | use: 150 | - websub13 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | - name: 筛选1 161 | type: url-test 162 | url: 'http://www.gstatic.com/generate_204' 163 | interval: 120 164 | use: 165 | - websub1 166 | 167 | - name: 筛选2 168 | type: url-test 169 | url: 'http://www.gstatic.com/generate_204' 170 | interval: 120 171 | use: 172 | - websub2 173 | - name: 筛选3 174 | type: url-test 175 | url: 'http://www.gstatic.com/generate_204' 176 | interval: 120 177 | use: 178 | - websub3 179 | - name: 筛选4 180 | type: url-test 181 | url: 'http://www.gstatic.com/generate_204' 182 | interval: 120 183 | use: 184 | - websub4 185 | - name: 筛选5 186 | type: url-test 187 | url: 'http://www.gstatic.com/generate_204' 188 | interval: 120 189 | use: 190 | - websub5 191 | - name: 筛选6 192 | type: url-test 193 | url: 'http://www.gstatic.com/generate_204' 194 | interval: 120 195 | use: 196 | - websub6 197 | - name: 筛选7 198 | type: url-test 199 | url: 'http://www.gstatic.com/generate_204' 200 | interval: 120 201 | use: 202 | - websub7 203 | - name: 筛选8 204 | type: url-test 205 | url: 'http://www.gstatic.com/generate_204' 206 | interval: 120 207 | use: 208 | - websub8 209 | - name: 筛选9 210 | type: url-test 211 | url: 'http://www.gstatic.com/generate_204' 212 | interval: 120 213 | use: 214 | - websub9 215 | - name: 筛选10 216 | type: url-test 217 | url: 'http://www.gstatic.com/generate_204' 218 | interval: 120 219 | use: 220 | - websub10 221 | - name: 筛选11 222 | type: url-test 223 | url: 'http://www.gstatic.com/generate_204' 224 | interval: 120 225 | use: 226 | - websub11 227 | 228 | - name: 筛选13 229 | type: url-test 230 | url: 'http://www.gstatic.com/generate_204' 231 | interval: 120 232 | use: 233 | - websub13 234 | - name: 本地 235 | type: url-test 236 | url: 'http://www.gstatic.com/generate_204' 237 | interval: 120 238 | use: 239 | - test 240 | 241 | 242 | proxy-providers: 243 | websub: 244 | type: http 245 | url: "https://{{ .domain }}/clash/proxies" 246 | interval: 86400 247 | path: ./websub.yaml 248 | health-check: 249 | enable: true 250 | interval: 60 251 | url: http://www.gstatic.com/generate_204 252 | 253 | websub1: 254 | type: http 255 | url: "https://{{ .domain }}/clash/proxies?c=AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,BA,BB,BC,BD,BE,BF,BG,BH,BI,BJ,BK,BL,BM,BN,BO,BP,BQ,BR,BS,BT,BU,BV,BW,BX,BY,BZ" 256 | interval: 86400 257 | path: ./websub1.yaml 258 | health-check: 259 | enable: true 260 | interval: 60 261 | url: http://www.gstatic.com/generate_204 262 | 263 | websub2: 264 | type: http 265 | url: "https://{{ .domain }}/clash/proxies?c=CA,CB,CC,CD,CE,CF,CG,CH,CI,CJ,CK,CL,CM,CN,CO,CP,CQ,CR,CS,CT,CU,CV,CW,CX,CY,CZ,DA,DB,DC,DD,DE,DF,DG,DH,DI,DJ,DK,DL,DM,DN,DO,DP,DQ,DR,DS,DT,DU,DV,DW,DX,DY,DZ" 266 | interval: 86400 267 | path: ./websub2.yaml 268 | health-check: 269 | enable: true 270 | interval: 60 271 | url: http://www.gstatic.com/generate_204 272 | 273 | websub3: 274 | type: http 275 | url: "https://{{ .domain }}/clash/proxies?c=EA,EB,EC,ED,EE,EF,EG,EH,EI,EJ,EK,EL,EM,EN,EO,EP,EQ,ER,ES,ET,EU,EV,EW,EX,EY,EZ,FA,FB,FC,FD,FE,FF,FG,FH,FI,FJ,FK,FL,FM,FN,FO,FP,FQ,FR,FS,FT,FU,FV,FW,FX,FY,FZ" 276 | interval: 86400 277 | path: ./websub3.yaml 278 | health-check: 279 | enable: true 280 | interval: 60 281 | url: http://www.gstatic.com/generate_204 282 | 283 | websub4: 284 | type: http 285 | url: "https://{{ .domain }}/clash/proxies?c=GA,GB,GC,GD,GE,GF,GG,GH,GI,GJ,GK,GL,GM,GN,GO,GP,GQ,GR,GS,GT,GU,GV,GW,GX,GY,GZ,HA,HB,HC,HD,HE,HF,HG,HH,HI,HJ,HK,HL,HM,HN,HO,HP,HQ,HR,HS,HT,HU,HV,HW,HX,HY,HZ" 286 | interval: 86400 287 | path: ./websub4.yaml 288 | health-check: 289 | enable: true 290 | interval: 60 291 | url: http://www.gstatic.com/generate_204 292 | 293 | websub5: 294 | type: http 295 | url: "https://{{ .domain }}/clash/proxies?c=IA,IB,IC,ID,IE,IF,IG,IH,II,IJ,IK,IL,IM,IN,IO,IP,IQ,IR,IS,IT,IU,IV,IW,IX,IY,IZ,JA,JB,JC,JD,JE,JF,JG,JH,JI,JJ,JK,JL,JM,JN,JO,JP,JQ,JR,JS,JT,JU,JV,JW,JX,JY,JZ" 296 | interval: 86400 297 | path: ./websub5.yaml 298 | health-check: 299 | enable: true 300 | interval: 60 301 | url: http://www.gstatic.com/generate_204 302 | 303 | websub6: 304 | type: http 305 | url: "https://{{ .domain }}/clash/proxies?c=KA,KB,KC,KD,KE,KF,KG,KH,KI,KJ,KK,KL,KM,KN,KO,KP,KQ,KR,KS,KT,KU,KV,KW,KX,KY,KZ,LA,LB,LC,LD,LE,LF,LG,LH,LI,LJ,LK,LL,LM,LN,LO,LP,LQ,LR,LS,LT,LU,LV,LW,LX,LY,LZ" 306 | interval: 86400 307 | path: ./websub6.yaml 308 | health-check: 309 | enable: true 310 | interval: 60 311 | url: http://www.gstatic.com/generate_204 312 | 313 | websub7: 314 | type: http 315 | url: "https://{{ .domain }}/clash/proxies?c=MA,MB,MC,MD,ME,MF,MG,MH,MI,MJ,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NB,NC,ND,NE,NF,NG,NH,NI,NJ,NK,NL,NM,NN,NO,NP,NQ,NR,NS,NT,NU,NV,NW,NX,NY,NZ" 316 | interval: 86400 317 | path: ./websub7.yaml 318 | health-check: 319 | enable: true 320 | interval: 60 321 | url: http://www.gstatic.com/generate_204 322 | 323 | websub8: 324 | type: http 325 | url: "https://{{ .domain }}/clash/proxies?c=OA,OB,OC,OD,OE,OF,OG,OH,OI,OJ,OK,OL,OM,ON,OO,OP,OQ,OR,OS,OT,OU,OV,OW,OX,OY,OZ,PA,PB,PC,PD,PE,PF,PG,PH,PI,PJ,PK,PL,PM,PN,PO,PP,PQ,PR,PS,PT,PU,PV,PW,PX,PY,PZ" 326 | interval: 86400 327 | path: ./websub8.yaml 328 | health-check: 329 | enable: true 330 | interval: 60 331 | url: http://www.gstatic.com/generate_204 332 | 333 | websub9: 334 | type: http 335 | url: "https://{{ .domain }}/clash/proxies?c=QA,QB,QC,QD,QE,QF,QG,QH,QI,QJ,QK,QL,QM,QN,QO,QP,QQ,QR,QS,QT,QU,QV,QW,QX,QY,QZ,RA,RB,RC,RD,RE,RF,RG,RH,RI,RJ,RK,RL,RM,RN,RO,RP,RQ,RR,RS,RT,RU,RV,RW,RX,RY,RZ" 336 | interval: 86400 337 | path: ./websub9.yaml 338 | health-check: 339 | enable: true 340 | interval: 60 341 | url: http://www.gstatic.com/generate_204 342 | 343 | websub10: 344 | type: http 345 | url: "https://{{ .domain }}/clash/proxies?c=SA,SB,SC,SD,SE,SF,SG,SH,SI,SJ,SK,SL,SM,SN,SO,SP,SQ,SR,SS,ST,SU,SV,SW,SX,SY,SZ,TA,TB,TC,TD,TE,TF,TG,TH,TI,TJ,TK,TL,TM,TN,TO,TP,TQ,TR,TS,TT,TU,TV,TW,TX,TY,TZ" 346 | interval: 86400 347 | path: ./websub10.yaml 348 | health-check: 349 | enable: true 350 | interval: 60 351 | url: http://www.gstatic.com/generate_204 352 | 353 | websub11: 354 | type: http 355 | url: "https://{{ .domain }}/clash/proxies?c=UA,UB,UC,UD,UE,UF,UG,UH,UI,UJ,UK,UL,UM,UN,UO,UP,UQ,UR,US,UT,UU,UV,UW,UX,UY,UZ,VA,VB,VC,VD,VE,VF,VG,VH,VI,VJ,VK,VL,VM,VN,VO,VP,VQ,VR,VS,VT,VU,VV,VW,VX,VY,VZ" 356 | interval: 86400 357 | path: ./websub11.yaml 358 | health-check: 359 | enable: true 360 | interval: 60 361 | url: http://www.gstatic.com/generate_204 362 | 363 | 364 | 365 | websub13: 366 | type: http 367 | url: "https://{{ .domain }}/clash/proxies?c=YA,YB,YC,YD,YE,YF,YG,YH,YI,YJ,YK,YL,YM,YN,YO,YP,YQ,YR,YS,YT,YU,YV,YW,YX,YY,YZ,ZA,ZB,ZC,ZD,ZE,ZF,ZG,ZH,ZI,ZJ,ZK,ZL,ZM,ZN,ZO,ZP,ZQ,ZR,ZS,ZT,ZU,ZV,ZW,ZX,ZY,ZZ" 368 | interval: 86400 369 | path: ./websub13.yaml 370 | health-check: 371 | enable: true 372 | interval: 60 373 | url: http://www.gstatic.com/generate_204 374 | test: 375 | type: file 376 | path: ./test.yaml 377 | health-check: 378 | enable: true 379 | interval: 60 380 | url: http://www.gstatic.com/generate_204 381 | rules: 382 | - DOMAIN-SUFFIX,smtp,DIRECT 383 | - DOMAIN-KEYWORD,aria2,DIRECT 384 | 385 | - GEOIP,CN,DIRECT 386 | 387 | - MATCH,全局选择 388 | 389 | -------------------------------------------------------------------------------- /assets/html/clash-config.yaml: -------------------------------------------------------------------------------- 1 | # port of HTTP 2 | port: 7890 3 | 4 | # port of SOCKS5 5 | socks-port: 7891 6 | 7 | # (HTTP and SOCKS5 in one port) 8 | # mixed-port: 7890 9 | 10 | # redir port for Linux and macOS 11 | # redir-port: 7892 12 | 13 | allow-lan: false 14 | mode: rule 15 | log-level: info 16 | external-controller: 127.0.0.1:9090 17 | 18 | proxies: 19 | 20 | proxy-groups: 21 | - name: 全局选择 22 | type: select 23 | proxies: 24 | - 手动选择2 25 | - 失败切换 26 | - 手动选择1 27 | - 负载均衡 28 | - name: 手动选择1 29 | type: select 30 | use: 31 | - websubvmess 32 | - test 33 | 34 | - name: 手动选择2 35 | type: select 36 | proxies: 37 | - 分类测试vmess 38 | - 分类测试本地 39 | - 分类测试全部 40 | - 分类测试ss 41 | - 分类测试ssr 42 | 43 | - name: 负载均衡 44 | type: load-balance 45 | url: 'http://www.gstatic.com/generate_204' 46 | interval: 900 47 | proxies: 48 | - 分类测试vmess 49 | - 分类测试本地 50 | - 分类测试全部 51 | - 分类测试ss 52 | - 分类测试ssr 53 | 54 | 55 | - name: 失败切换 56 | type: fallback 57 | url: 'http://www.gstatic.com/generate_204' 58 | interval: 900 59 | proxies: 60 | - 分类测试本地 61 | - 分类测试vmess 62 | - 分类测试ss 63 | - 分类测试ssr 64 | 65 | 66 | 67 | - name: 分类测试全部 68 | type: url-test 69 | url: 'https://www.bilibili.com/' 70 | interval: 1200 71 | use: 72 | - websub 73 | - name: 分类测试本地 74 | type: url-test 75 | url: 'https://www.bilibili.com/' 76 | interval: 1200 77 | use: 78 | - test 79 | - name: 分类测试vmess 80 | type: url-test 81 | url: 'https://www.bilibili.com/' 82 | interval: 1200 83 | use: 84 | - websubvmess 85 | - name: 分类测试ssr 86 | type: url-test 87 | url: 'https://www.bilibili.com/' 88 | interval: 1200 89 | use: 90 | - websubssr 91 | - name: 分类测试ss 92 | type: url-test 93 | url: 'https://www.bilibili.com/' 94 | interval: 1200 95 | use: 96 | - websubss 97 | 98 | proxy-providers: 99 | websub: 100 | type: http 101 | url: "https://{{ .domain }}/clash/proxies" 102 | interval: 86400 103 | path: ./websub.yaml 104 | health-check: 105 | enable: true 106 | interval: 900 107 | url: http://www.gstatic.com/generate_204 108 | 109 | websubss: 110 | type: http 111 | url: "https://{{ .domain }}/clash/proxies?type=ss" 112 | interval: 86400 113 | path: ./websubss.yaml 114 | health-check: 115 | enable: true 116 | interval: 900 117 | url: http://www.gstatic.com/generate_204 118 | 119 | websubssr: 120 | type: http 121 | url: "https://{{ .domain }}/clash/proxies?type=ssr" 122 | interval: 86400 123 | path: ./websubssr.yaml 124 | health-check: 125 | enable: true 126 | interval: 900 127 | url: http://www.gstatic.com/generate_204 128 | 129 | websubvmess: 130 | type: http 131 | url: "https://{{ .domain }}/clash/proxies?type=vmess" 132 | interval: 86400 133 | path: ./websubvmess.yaml 134 | health-check: 135 | enable: true 136 | interval: 900 137 | url: http://www.gstatic.com/generate_204 138 | 139 | test: 140 | type: file 141 | path: ./test.yaml 142 | health-check: 143 | enable: true 144 | interval: 900 145 | url: http://www.gstatic.com/generate_204 146 | rules: 147 | - DOMAIN-SUFFIX,smtp,DIRECT 148 | - DOMAIN-KEYWORD,aria2,DIRECT 149 | 150 | - GEOIP,CN,DIRECT 151 | 152 | - MATCH,全局选择 153 | -------------------------------------------------------------------------------- /assets/html/clash.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 豆豆兵频道的空头补给箱 8 | 100 | 101 | 102 |
103 |
104 |

免费Clash节点

105 |
106 |

自动抓取tg频道、订阅地址、公开互联网上的ss、ssr、vmess、trojan节点信息,聚合去重后提供clash配置,每15分钟更新

107 |
108 |

Clash配置文件:https://{{ .domain }}/clash/config 一键导入

109 |

Clash proxy-provider(Shadowrocket添加订阅方式可用):https://{{ .domain }}/clash/proxies

110 |
111 |

筛选代理类型(此种方式你只能自己维护配置文件):https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess

112 |

筛选国家(此种方式你只能自己维护配置文件):https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess&c=HK,TW,US

113 |

所有节点的Provider(不是都可以用):https://{{ .domain }}/clash/proxies?type=all

114 |
115 |

项目fork与zu1k:zu1k

116 |

欢迎关注tg频道:@doudoubinggo

117 |

订阅youtube:订阅 {{ .version }}

118 |
119 |
120 |
121 | 122 | 123 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /assets/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 豆豆兵频道的空投补给箱 8 | 9 | 10 | 11 | 103 | 104 | 105 |
106 |
107 |

豆豆兵频道的空投补给箱

108 |
109 |

clash配置优化,规则需要自己添加,节点每15分钟更新,目前共有{{.getters_count}}个抓取源

110 |

总节点数量:{{ .all_proxies_count }}

111 |

ss节点数量:{{ .ss_proxies_count }}

112 |

ssr节点数量:{{ .ssr_proxies_count }}

113 |

vmess节点数量:{{ .vmess_proxies_count }}

114 |

trojan节点数量:{{ .trojan_proxies_count }}

115 |

可用节点数量:{{ .useful_proxies_count }}

116 |

最后更新时间:{{ .last_crawl_time }}

117 |
118 |

Clash

119 |

Clash配置文件:https://{{ .domain }}/clash/config 一键导入

121 |

Clash proxy-provider(Shadowrocket添加订阅方式可用):https://{{ .domain }}/clash/proxies 122 |

123 |

筛选代理类型:https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess,trojan

124 |

筛选国家:https://{{ .domain }}/clash/proxies?c=HK,TW,US

125 |
126 |

Surge

127 |

Surge配置文件:https://{{ .domain }}/surge/config 一键导入

129 |

Surge proxy list:https://{{ .domain }}/surge/proxies 130 |

131 |
132 |

订阅链接

133 |

ss的json链接:https://{{ .domain }}/ss/sub

134 |

ss的sip002链接:https://{{ .domain }}/sip002/sub

135 |

ssr订阅链接:https://{{ .domain }}/ssr/sub

136 |

vmess订阅链接:https://{{ .domain }}/vmess/sub

137 |
138 | {{- /* 所有使用本代码提供服务的禁止删除该行*/}} 139 |

项目fork与zu1k:zu1k

140 |

欢迎关注tg频道:@doudoubinggo

141 |

订阅youtube:订阅 {{ .version }}

142 |
143 |
144 |
145 | 146 | 147 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /assets/html/surge.conf: -------------------------------------------------------------------------------- 1 | [Proxy] 2 | Direct = direct 3 | 4 | [Proxy Group] 5 | Proxy = select, 延迟最低, 失败切换, 手动选择 6 | 延迟最低 = url-test, policy-path=https://{{ .domain }}/surge/proxies, url=http://www.qualcomm.cn/generate_204, update-interval=3600, interval = 600s, tolerance = 100ms, timeout = 5s, evaluate-before-use = true 7 | 失败切换 = fallback, policy-path=https://{{ .domain }}/surge/proxies, url=http://www.qualcomm.cn/generate_204, update-interval=3600, interval = 600s, tolerance = 100ms, timeout = 5s, evaluate-before-use = true 8 | 手动选择 = select, policy-path=https://{{ .domain }}/surge/proxies, url=http://www.qualcomm.cn/generate_204, update-interval=3600, interval = 600s, tolerance = 100ms, timeout = 5s, evaluate-before-use = true 9 | Apple = select, Direct, Proxy 10 | Adblock = select, Direct, REJECT, REJECT-TINYGIF 11 | 12 | [Rule] 13 | # RULESET 14 | RULE-SET,SYSTEM,Direct 15 | # 16 | # Unbreak 后续规则修正 17 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Unbreak.list,Adblock 18 | # Advertising 广告 19 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Guard/Advertising.list,Adblock 20 | # Privacy 隐私 21 | # RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Guard/Privacy.list,Adblock 22 | # Hijacking 运营商劫持或恶意网站 23 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Guard/Hijacking.list,Adblock 24 | # 25 | # Apple 26 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Extra/Apple/Apple.list,Apple 27 | # 28 | # 代理 29 | # Streaming 国际流媒体服务 30 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/StreamingMedia/Streaming.list,Proxy 31 | # StreamingSE 中国流媒体服务(面向海外版本) 32 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/StreamingMedia/StreamingSE.list,Proxy 33 | # Global 全球加速 34 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Global.list,Proxy 35 | # 36 | RULE-SET,https://github.com/Hackl0us/SS-Rule-Snippet/raw/master/Rulesets/App/social/Telegram.list,Proxy 37 | RULE-SET,https://github.com/Hackl0us/SS-Rule-Snippet/raw/master/Rulesets/App/social/WhatsApp.list,Proxy 38 | RULE-SET,https://github.com/Hackl0us/SS-Rule-Snippet/raw/master/Rulesets/App/social/LINE.list,Proxy 39 | # 40 | # Direct 41 | RULE-SET,https://github.com/DivineEngine/Profiles/raw/master/Surge/Ruleset/Extra/ChinaIP.list,Direct 42 | # 43 | RULE-SET,LAN,Direct 44 | # GEOIP,CN,Direct 45 | FINAL,Proxy,dns-failed 46 | -------------------------------------------------------------------------------- /assets/html/surge.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 豆豆兵频道的空投补给箱 8 | 70 | 71 | 72 |
73 |
74 |

免费Surge节点

75 |
76 |

自动抓取tg频道、订阅地址、公开互联网上的ss、vmess节点信息,聚合去重后提供Surge节点列表,每15分钟更新

77 |
78 |

Surge配置文件:https://{{ .domain }}/surge/config 一键导入

79 |

Surge proxy list:https://{{ .domain }}/surge/proxies

80 |
81 |

项目fork与zu1k:zu1k

82 |

欢迎关注tg频道:@doudoubinggo

83 |

订阅youtube:订阅 {{ .version }}

84 |
85 |
86 |
87 | 88 | 89 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /assets/proxy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doudoubinga/proxypool/b7ed82d783149ac2704ec9ed965c374682c4c47c/assets/proxy.jpg -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "errors" 5 | "io/ioutil" 6 | "os" 7 | "strings" 8 | 9 | "github.com/ghodss/yaml" 10 | "github.com/doudoubinga/proxypool/pkg/tool" 11 | ) 12 | 13 | var configFilePath = "config.yaml" 14 | 15 | type ConfigOptions struct { 16 | Domain string `json:"domain" yaml:"domain"` 17 | DatabaseUrl string `json:"database_url" yaml:"database_url"` 18 | CFEmail string `json:"cf_email" yaml:"cf_email"` 19 | CFKey string `json:"cf_key" yaml:"cf_key"` 20 | SourceFiles []string `json:"source-files" yaml:"source-files"` 21 | } 22 | 23 | // Config 配置 24 | var Config ConfigOptions 25 | 26 | // Parse 解析配置文件,支持本地文件系统和网络链接 27 | func Parse(path string) error { 28 | if path == "" { 29 | path = configFilePath 30 | } else { 31 | configFilePath = path 32 | } 33 | fileData, err := ReadFile(path) 34 | if err != nil { 35 | return err 36 | } 37 | Config = ConfigOptions{} 38 | err = yaml.Unmarshal(fileData, &Config) 39 | if err != nil { 40 | return err 41 | } 42 | 43 | // 部分配置环境变量优先 44 | if domain := os.Getenv("DOMAIN"); domain != "" { 45 | Config.Domain = domain 46 | } 47 | if cfEmail := os.Getenv("CF_API_EMAIL"); cfEmail != "" { 48 | Config.CFEmail = cfEmail 49 | } 50 | if cfKey := os.Getenv("CF_API_KEY"); cfKey != "" { 51 | Config.CFKey = cfKey 52 | } 53 | 54 | return nil 55 | } 56 | 57 | // 从本地文件或者http链接读取配置文件内容 58 | func ReadFile(path string) ([]byte, error) { 59 | if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { 60 | resp, err := tool.GetHttpClient().Get(path) 61 | if err != nil { 62 | return nil, errors.New("config file http get fail") 63 | } 64 | defer resp.Body.Close() 65 | return ioutil.ReadAll(resp.Body) 66 | } else { 67 | if _, err := os.Stat(path); os.IsNotExist(err) { 68 | return nil, err 69 | } 70 | return ioutil.ReadFile(path) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /config/config.yaml: -------------------------------------------------------------------------------- 1 | # your domain 2 | domain: doudoubing3332.herokuapp.com 3 | 4 | # database url 5 | database_url: "" 6 | 7 | # cloudflare api 8 | cf_email: "" 9 | cf_key: "" 10 | 11 | # source definition file 12 | source-files: 13 | # use local file 14 | - ./config/source.yaml 15 | # use web file 16 | - https://doudoubing3332.herokuapp.com/source.yaml 17 | -------------------------------------------------------------------------------- /config/source.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "github.com/doudoubinga/proxypool/pkg/tool" 4 | 5 | type Source struct { 6 | Type string `json:"type" yaml:"type"` 7 | Options tool.Options `json:"options" yaml:"options"` 8 | } 9 | -------------------------------------------------------------------------------- /config/source.yaml: -------------------------------------------------------------------------------- 1 | # 爬订阅链接 2 | 3 | - type: webfuzzsub 4 | options: 5 | url: https://raw.githubusercontent.com/oouxx/fqsub/master/sub.list 6 | - type: webfuzzsub 7 | options: 8 | url: https://github.com/JACKUSR2089/v2ray-subscribed 9 | - type: webfuzzsub 10 | options: 11 | url: https://github.com/pojiezhiyuanjun/freev2 12 | 13 | 14 | 15 | 16 | 17 | 18 | # 爬节点 19 | - type: webfuzz 20 | options: 21 | url: https://telegra.ph/2020-10-3-10-02 22 | - type: webfuzz 23 | options: 24 | url: https://lisondawang.tk/jiedianfenxiang.html 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | # tg订阅+节点 35 | 36 | - type: tgchannel 37 | options: 38 | channel: NetfreexSrV 39 | num: 200 40 | - type: tgchannel 41 | options: 42 | channel: V2List 43 | num: 200 44 | - type: tgchannel 45 | options: 46 | channel: ssrList 47 | num: 200 48 | - type: tgchannel 49 | options: 50 | channel: SSRSUB 51 | num: 200 52 | - type: tgchannel 53 | options: 54 | channel: FreeSSRNode 55 | num: 200 56 | - type: tgchannel 57 | options: 58 | channel: V2List 59 | num: 200 60 | - type: tgchannel 61 | options: 62 | channel: ssrtool 63 | num: 200 64 | - type: tgchannel 65 | options: 66 | channel: freeshadowsock 67 | num: 200 68 | - type: tgchannel 69 | options: 70 | channel: jiedianfenxiang 71 | num: 200 72 | - type: tgchannel 73 | options: 74 | channel: fanqiang666 75 | num: 200 76 | - type: tgchannel 77 | options: 78 | channel: ssrtool_crack 79 | num: 200 80 | - type: tgchannel 81 | options: 82 | channel: ssrshares 83 | num: 200 84 | - type: tgchannel 85 | options: 86 | channel: gongyijichangfenxiang 87 | num: 200 88 | - type: tgchannel 89 | options: 90 | channel: fanqiang666 91 | num: 200 92 | - type: tgchannel 93 | options: 94 | channel: ssrtool_crack 95 | num: 200 96 | - type: tgchannel 97 | options: 98 | channel: moneyfly01 99 | num: 200 100 | - type: tgchannel 101 | options: 102 | channel: ssrv2taytgshare 103 | num: 200 104 | 105 | - type: tgchannel 106 | options: 107 | channel: freeshadowsock 108 | num: 200 109 | - type: tgchannel 110 | options: 111 | channel: gyjclub 112 | num: 200 113 | - type: tgchannel 114 | options: 115 | channel: TgProxies 116 | num: 200 117 | - type: tgchannel 118 | options: 119 | channel: VPNFolder 120 | num: 200 121 | - type: tgchannel 122 | options: 123 | channel: vmesssr 124 | num: 200 125 | - type: tgchannel 126 | options: 127 | channel: youmtp 128 | num: 200 129 | - type: tgchannel 130 | options: 131 | channel: ssrkn 132 | num: 200 133 | - type: tgchannel 134 | options: 135 | channel: abchz 136 | num: 200 137 | - type: tgchannel 138 | options: 139 | channel: yg251153 140 | num: 200 141 | - type: tgchannel 142 | options: 143 | channel: woyaofq 144 | num: 200 145 | - type: tgchannel 146 | options: 147 | channel: wwx_com 148 | num: 200 149 | - type: tgchannel 150 | options: 151 | channel: freessr4k 152 | num: 200 153 | - type: tgchannel 154 | options: 155 | channel: ultrafreevpn 156 | num: 200 157 | - type: tgchannel 158 | options: 159 | channel: VSshit 160 | num: 200 161 | - type: tgchannel 162 | options: 163 | channel: InternetSSR 164 | num: 200 165 | - type: tgchannel 166 | options: 167 | channel: baipiaodadui 168 | num: 200 169 | - type: tgchannel 170 | options: 171 | channel: mtproxy666 172 | num: 200 173 | - type: tgchannel 174 | options: 175 | channel: v2ray666 176 | num: 200 177 | - type: tgchannel 178 | options: 179 | channel: freeVPNserv 180 | num: 200 181 | 182 | 183 | # 论坛 184 | #- type: web-fanqiangdang 185 | # options: 186 | # url: https://fanqiangdang.com/forum-48-1.html 187 | 188 | # 网站抓取 189 | - type: web-freessrxyz 190 | options: 191 | 192 | # 爬订阅 193 | 194 | #- type: subscribe 195 | # options: 196 | # url: https://gooii.ml/v2ray/sub/vmess.html 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /docs/fast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doudoubinga/proxypool/b7ed82d783149ac2704ec9ed965c374682c4c47c/docs/fast.png -------------------------------------------------------------------------------- /docs/genbindata.sh: -------------------------------------------------------------------------------- 1 | go-bindata -o internal/bindata/html/html.go -pkg binhtml assets/html/ 2 | go-bindata -o internal/bindata/geoip/geoip.go -pkg bingeoip assets/GeoLite2-City.mmdb assets/flags.json 3 | -------------------------------------------------------------------------------- /docs/speedtest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doudoubinga/proxypool/b7ed82d783149ac2704ec9ed965c374682c4c47c/docs/speedtest.png -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | // +heroku goVersion go1.14 2 | 3 | module github.com/doudoubinga/proxypool 4 | 5 | go 1.14 6 | 7 | require ( 8 | github.com/Dreamacro/clash v1.0.1-0.20200812125056-8b7c731fd629 9 | github.com/PuerkitoBio/goquery v1.5.1 // indirect 10 | github.com/andybalholm/cascadia v1.2.0 // indirect 11 | github.com/antchfx/htmlquery v1.2.3 // indirect 12 | github.com/antchfx/xmlquery v1.2.4 // indirect 13 | github.com/antchfx/xpath v1.1.8 // indirect 14 | github.com/cloudflare/cloudflare-go v0.13.2 15 | github.com/ghodss/yaml v1.0.0 16 | github.com/gin-contrib/cache v1.1.0 // indirect 17 | github.com/gin-gonic/gin v1.6.3 18 | github.com/go-playground/validator/v10 v10.3.0 // indirect 19 | github.com/gobwas/glob v0.2.3 // indirect 20 | github.com/gocolly/colly v1.2.0 21 | github.com/golang/protobuf v1.4.2 // indirect 22 | github.com/heroku/x v0.0.25 23 | github.com/ivpusic/grpool v1.0.0 24 | github.com/jackc/pgproto3/v2 v2.0.4 // indirect 25 | github.com/jasonlvhit/gocron v0.0.1 26 | github.com/json-iterator/go v1.1.10 // indirect 27 | github.com/kennygrant/sanitize v1.2.4 // indirect 28 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 29 | github.com/modern-go/reflect2 v1.0.1 // indirect 30 | github.com/oschwald/geoip2-golang v1.4.0 31 | github.com/oschwald/maxminddb-golang v1.7.0 // indirect 32 | github.com/patrickmn/go-cache v2.1.0+incompatible 33 | github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect 34 | github.com/temoto/robotstxt v1.1.1 // indirect 35 | golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect 36 | golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect 37 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect 38 | google.golang.org/appengine v1.6.6 // indirect 39 | google.golang.org/protobuf v1.25.0 // indirect 40 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect 41 | gorm.io/driver/postgres v1.0.0 42 | gorm.io/gorm v1.20.0 43 | ) 44 | -------------------------------------------------------------------------------- /internal/app/getter.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | 7 | "github.com/doudoubinga/proxypool/internal/cache" 8 | 9 | "github.com/ghodss/yaml" 10 | 11 | "github.com/doudoubinga/proxypool/config" 12 | "github.com/doudoubinga/proxypool/pkg/getter" 13 | ) 14 | 15 | var Getters = make([]getter.Getter, 0) 16 | 17 | func InitConfigAndGetters(path string) (err error) { 18 | err = config.Parse(path) 19 | if err != nil { 20 | return 21 | } 22 | if s := config.Config.SourceFiles; len(s) == 0 { 23 | return errors.New("no sources") 24 | } else { 25 | initGetters(s) 26 | } 27 | return 28 | } 29 | 30 | func initGetters(sourceFiles []string) { 31 | Getters = make([]getter.Getter, 0) 32 | for _, path := range sourceFiles { 33 | data, err := config.ReadFile(path) 34 | if err != nil { 35 | fmt.Errorf("Init SourceFile Error: %s\n", err.Error()) 36 | continue 37 | } 38 | sourceList := make([]config.Source, 0) 39 | err = yaml.Unmarshal(data, &sourceList) 40 | if err != nil { 41 | fmt.Errorf("Init SourceFile Error: %s\n", err.Error()) 42 | continue 43 | } 44 | for _, source := range sourceList { 45 | g, err := getter.NewGetter(source.Type, source.Options) 46 | if err == nil && g != nil { 47 | Getters = append(Getters, g) 48 | fmt.Println("init getter:", source.Type, source.Options) 49 | } 50 | } 51 | } 52 | fmt.Println("Getter count:", len(Getters)) 53 | cache.GettersCount = len(Getters) 54 | } 55 | -------------------------------------------------------------------------------- /internal/app/task.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | "time" 7 | 8 | "github.com/doudoubinga/proxypool/internal/cache" 9 | "github.com/doudoubinga/proxypool/internal/database" 10 | "github.com/doudoubinga/proxypool/pkg/provider" 11 | "github.com/doudoubinga/proxypool/pkg/proxy" 12 | ) 13 | 14 | var location, _ = time.LoadLocation("PRC") 15 | 16 | func CrawlGo() { 17 | wg := &sync.WaitGroup{} 18 | var pc = make(chan proxy.Proxy) 19 | for _, g := range Getters { 20 | wg.Add(1) 21 | go g.Get2Chan(pc, wg) 22 | } 23 | proxies := cache.GetProxies("allproxies") 24 | proxies = append(proxies, database.GetAllProxies()...) 25 | go func() { 26 | wg.Wait() 27 | close(pc) 28 | }() 29 | for node := range pc { 30 | if node != nil { 31 | proxies = append(proxies, node) 32 | } 33 | } 34 | // 节点衍生并去重 35 | proxies = proxies.Deduplication().Derive() 36 | log.Println("CrawlGo node count:", len(proxies)) 37 | proxies = provider.Clash{ 38 | provider.Base{ 39 | Proxies: &proxies, 40 | }, 41 | }.CleanProxies() 42 | log.Println("CrawlGo cleaned node count:", len(proxies)) 43 | proxies.NameSetCounrty().Sort().NameAddIndex().NameAddTG() 44 | log.Println("Proxy rename DONE!") 45 | 46 | // 全节点存储到数据库 47 | database.SaveProxyList(proxies) 48 | 49 | cache.SetProxies("allproxies", proxies) 50 | cache.AllProxiesCount = proxies.Len() 51 | log.Println("AllProxiesCount:", cache.AllProxiesCount) 52 | cache.SSProxiesCount = proxies.TypeLen("ss") 53 | log.Println("SSProxiesCount:", cache.SSProxiesCount) 54 | cache.SSRProxiesCount = proxies.TypeLen("ssr") 55 | log.Println("SSRProxiesCount:", cache.SSRProxiesCount) 56 | cache.VmessProxiesCount = proxies.TypeLen("vmess") 57 | log.Println("VmessProxiesCount:", cache.VmessProxiesCount) 58 | cache.TrojanProxiesCount = proxies.TypeLen("trojan") 59 | log.Println("TrojanProxiesCount:", cache.TrojanProxiesCount) 60 | cache.LastCrawlTime = time.Now().In(location).Format("2006-01-02 15:04:05") 61 | 62 | // 可用性检测 63 | log.Println("Now proceed proxy health check...") 64 | proxies = proxy.CleanBadProxiesWithGrpool(proxies) 65 | log.Println("CrawlGo clash usable node count:", len(proxies)) 66 | proxies.NameReIndex().NameAddTG() 67 | cache.SetProxies("proxies", proxies) 68 | cache.UsefullProxiesCount = proxies.Len() 69 | 70 | cache.SetString("clashproxies", provider.Clash{ 71 | provider.Base{ 72 | Proxies: &proxies, 73 | }, 74 | }.Provide()) 75 | cache.SetString("surgeproxies", provider.Surge{ 76 | provider.Base{ 77 | Proxies: &proxies, 78 | }, 79 | }.Provide()) 80 | } 81 | -------------------------------------------------------------------------------- /internal/bindata/geoip/geoip.go: -------------------------------------------------------------------------------- 1 | // Code generated for package bingeoip by go-bindata DO NOT EDIT. (@generated) 2 | // sources: 3 | // assets/GeoLite2-City.mmdb 4 | // assets/flags.json 5 | package bingeoip 6 | 7 | import ( 8 | "fmt" 9 | "io/ioutil" 10 | "os" 11 | "path/filepath" 12 | "strings" 13 | ) 14 | 15 | // bindataRead reads the given file from disk. It returns an error on failure. 16 | func bindataRead(path, name string) ([]byte, error) { 17 | buf, err := ioutil.ReadFile(path) 18 | if err != nil { 19 | err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err) 20 | } 21 | return buf, err 22 | } 23 | 24 | type asset struct { 25 | bytes []byte 26 | info os.FileInfo 27 | } 28 | 29 | // assetsGeolite2CityMmdb reads file data from disk. It returns an error on failure. 30 | func assetsGeolite2CityMmdb() (*asset, error) { 31 | path := "assets/GeoLite2-City.mmdb" 32 | name := "assets/GeoLite2-City.mmdb" 33 | bytes, err := bindataRead(path, name) 34 | if err != nil { 35 | return nil, err 36 | } 37 | 38 | fi, err := os.Stat(path) 39 | if err != nil { 40 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 41 | } 42 | 43 | a := &asset{bytes: bytes, info: fi} 44 | return a, err 45 | } 46 | 47 | // assetsFlagsJson reads file data from disk. It returns an error on failure. 48 | func assetsFlagsJson() (*asset, error) { 49 | path := "assets/flags.json" 50 | name := "assets/flags.json" 51 | bytes, err := bindataRead(path, name) 52 | if err != nil { 53 | return nil, err 54 | } 55 | 56 | fi, err := os.Stat(path) 57 | if err != nil { 58 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 59 | } 60 | 61 | a := &asset{bytes: bytes, info: fi} 62 | return a, err 63 | } 64 | 65 | // Asset loads and returns the asset for the given name. 66 | // It returns an error if the asset could not be found or 67 | // could not be loaded. 68 | func Asset(name string) ([]byte, error) { 69 | cannonicalName := strings.Replace(name, "\\", "/", -1) 70 | if f, ok := _bindata[cannonicalName]; ok { 71 | a, err := f() 72 | if err != nil { 73 | return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) 74 | } 75 | return a.bytes, nil 76 | } 77 | return nil, fmt.Errorf("Asset %s not found", name) 78 | } 79 | 80 | // MustAsset is like Asset but panics when Asset would return an error. 81 | // It simplifies safe initialization of global variables. 82 | func MustAsset(name string) []byte { 83 | a, err := Asset(name) 84 | if err != nil { 85 | panic("asset: Asset(" + name + "): " + err.Error()) 86 | } 87 | 88 | return a 89 | } 90 | 91 | // AssetInfo loads and returns the asset info for the given name. 92 | // It returns an error if the asset could not be found or 93 | // could not be loaded. 94 | func AssetInfo(name string) (os.FileInfo, error) { 95 | cannonicalName := strings.Replace(name, "\\", "/", -1) 96 | if f, ok := _bindata[cannonicalName]; ok { 97 | a, err := f() 98 | if err != nil { 99 | return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) 100 | } 101 | return a.info, nil 102 | } 103 | return nil, fmt.Errorf("AssetInfo %s not found", name) 104 | } 105 | 106 | // AssetNames returns the names of the assets. 107 | func AssetNames() []string { 108 | names := make([]string, 0, len(_bindata)) 109 | for name := range _bindata { 110 | names = append(names, name) 111 | } 112 | return names 113 | } 114 | 115 | // _bindata is a table, holding each asset generator, mapped to its name. 116 | var _bindata = map[string]func() (*asset, error){ 117 | "assets/GeoLite2-City.mmdb": assetsGeolite2CityMmdb, 118 | "assets/flags.json": assetsFlagsJson, 119 | } 120 | 121 | // AssetDir returns the file names below a certain 122 | // directory embedded in the file by go-bindata. 123 | // For example if you run go-bindata on data/... and data contains the 124 | // following hierarchy: 125 | // data/ 126 | // foo.txt 127 | // img/ 128 | // a.png 129 | // b.png 130 | // then AssetDir("data") would return []string{"foo.txt", "img"} 131 | // AssetDir("data/img") would return []string{"a.png", "b.png"} 132 | // AssetDir("foo.txt") and AssetDir("notexist") would return an error 133 | // AssetDir("") will return []string{"data"}. 134 | func AssetDir(name string) ([]string, error) { 135 | node := _bintree 136 | if len(name) != 0 { 137 | cannonicalName := strings.Replace(name, "\\", "/", -1) 138 | pathList := strings.Split(cannonicalName, "/") 139 | for _, p := range pathList { 140 | node = node.Children[p] 141 | if node == nil { 142 | return nil, fmt.Errorf("Asset %s not found", name) 143 | } 144 | } 145 | } 146 | if node.Func != nil { 147 | return nil, fmt.Errorf("Asset %s not found", name) 148 | } 149 | rv := make([]string, 0, len(node.Children)) 150 | for childName := range node.Children { 151 | rv = append(rv, childName) 152 | } 153 | return rv, nil 154 | } 155 | 156 | type bintree struct { 157 | Func func() (*asset, error) 158 | Children map[string]*bintree 159 | } 160 | 161 | var _bintree = &bintree{nil, map[string]*bintree{ 162 | "assets": &bintree{nil, map[string]*bintree{ 163 | "GeoLite2-City.mmdb": &bintree{assetsGeolite2CityMmdb, map[string]*bintree{}}, 164 | "flags.json": &bintree{assetsFlagsJson, map[string]*bintree{}}, 165 | }}, 166 | }} 167 | 168 | // RestoreAsset restores an asset under the given directory 169 | func RestoreAsset(dir, name string) error { 170 | data, err := Asset(name) 171 | if err != nil { 172 | return err 173 | } 174 | info, err := AssetInfo(name) 175 | if err != nil { 176 | return err 177 | } 178 | err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) 179 | if err != nil { 180 | return err 181 | } 182 | err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) 183 | if err != nil { 184 | return err 185 | } 186 | err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) 187 | if err != nil { 188 | return err 189 | } 190 | return nil 191 | } 192 | 193 | // RestoreAssets restores an asset under the given directory recursively 194 | func RestoreAssets(dir, name string) error { 195 | children, err := AssetDir(name) 196 | // File 197 | if err != nil { 198 | return RestoreAsset(dir, name) 199 | } 200 | // Dir 201 | for _, child := range children { 202 | err = RestoreAssets(dir, filepath.Join(name, child)) 203 | if err != nil { 204 | return err 205 | } 206 | } 207 | return nil 208 | } 209 | 210 | func _filePath(dir, name string) string { 211 | cannonicalName := strings.Replace(name, "\\", "/", -1) 212 | return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) 213 | } 214 | -------------------------------------------------------------------------------- /internal/bindata/html/html.go: -------------------------------------------------------------------------------- 1 | // Code generated for package binhtml by go-bindata DO NOT EDIT. (@generated) 2 | // sources: 3 | // assets/html/clash-config.yaml 4 | // assets/html/clash.html 5 | // assets/html/index.html 6 | // assets/html/surge.conf 7 | // assets/html/surge.html 8 | package binhtml 9 | 10 | import ( 11 | "fmt" 12 | "io/ioutil" 13 | "os" 14 | "path/filepath" 15 | "strings" 16 | ) 17 | 18 | // bindataRead reads the given file from disk. It returns an error on failure. 19 | func bindataRead(path, name string) ([]byte, error) { 20 | buf, err := ioutil.ReadFile(path) 21 | if err != nil { 22 | err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err) 23 | } 24 | return buf, err 25 | } 26 | 27 | type asset struct { 28 | bytes []byte 29 | info os.FileInfo 30 | } 31 | 32 | // assetsHtmlClashConfigYaml reads file data from disk. It returns an error on failure. 33 | func assetsHtmlClashConfigYaml() (*asset, error) { 34 | path := "assets/html/clash-config.yaml" 35 | name := "assets/html/clash-config.yaml" 36 | bytes, err := bindataRead(path, name) 37 | if err != nil { 38 | return nil, err 39 | } 40 | 41 | fi, err := os.Stat(path) 42 | if err != nil { 43 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 44 | } 45 | 46 | a := &asset{bytes: bytes, info: fi} 47 | return a, err 48 | } 49 | 50 | // assetsHtmlClashHtml reads file data from disk. It returns an error on failure. 51 | func assetsHtmlClashHtml() (*asset, error) { 52 | path := "assets/html/clash.html" 53 | name := "assets/html/clash.html" 54 | bytes, err := bindataRead(path, name) 55 | if err != nil { 56 | return nil, err 57 | } 58 | 59 | fi, err := os.Stat(path) 60 | if err != nil { 61 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 62 | } 63 | 64 | a := &asset{bytes: bytes, info: fi} 65 | return a, err 66 | } 67 | 68 | // assetsHtmlIndexHtml reads file data from disk. It returns an error on failure. 69 | func assetsHtmlIndexHtml() (*asset, error) { 70 | path := "assets/html/index.html" 71 | name := "assets/html/index.html" 72 | bytes, err := bindataRead(path, name) 73 | if err != nil { 74 | return nil, err 75 | } 76 | 77 | fi, err := os.Stat(path) 78 | if err != nil { 79 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 80 | } 81 | 82 | a := &asset{bytes: bytes, info: fi} 83 | return a, err 84 | } 85 | 86 | // assetsHtmlSurgeConf reads file data from disk. It returns an error on failure. 87 | func assetsHtmlSurgeConf() (*asset, error) { 88 | path := "assets/html/surge.conf" 89 | name := "assets/html/surge.conf" 90 | bytes, err := bindataRead(path, name) 91 | if err != nil { 92 | return nil, err 93 | } 94 | 95 | fi, err := os.Stat(path) 96 | if err != nil { 97 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 98 | } 99 | 100 | a := &asset{bytes: bytes, info: fi} 101 | return a, err 102 | } 103 | 104 | // assetsHtmlSurgeHtml reads file data from disk. It returns an error on failure. 105 | func assetsHtmlSurgeHtml() (*asset, error) { 106 | path := "assets/html/surge.html" 107 | name := "assets/html/surge.html" 108 | bytes, err := bindataRead(path, name) 109 | if err != nil { 110 | return nil, err 111 | } 112 | 113 | fi, err := os.Stat(path) 114 | if err != nil { 115 | err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 116 | } 117 | 118 | a := &asset{bytes: bytes, info: fi} 119 | return a, err 120 | } 121 | 122 | // Asset loads and returns the asset for the given name. 123 | // It returns an error if the asset could not be found or 124 | // could not be loaded. 125 | func Asset(name string) ([]byte, error) { 126 | cannonicalName := strings.Replace(name, "\\", "/", -1) 127 | if f, ok := _bindata[cannonicalName]; ok { 128 | a, err := f() 129 | if err != nil { 130 | return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) 131 | } 132 | return a.bytes, nil 133 | } 134 | return nil, fmt.Errorf("Asset %s not found", name) 135 | } 136 | 137 | // MustAsset is like Asset but panics when Asset would return an error. 138 | // It simplifies safe initialization of global variables. 139 | func MustAsset(name string) []byte { 140 | a, err := Asset(name) 141 | if err != nil { 142 | panic("asset: Asset(" + name + "): " + err.Error()) 143 | } 144 | 145 | return a 146 | } 147 | 148 | // AssetInfo loads and returns the asset info for the given name. 149 | // It returns an error if the asset could not be found or 150 | // could not be loaded. 151 | func AssetInfo(name string) (os.FileInfo, error) { 152 | cannonicalName := strings.Replace(name, "\\", "/", -1) 153 | if f, ok := _bindata[cannonicalName]; ok { 154 | a, err := f() 155 | if err != nil { 156 | return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) 157 | } 158 | return a.info, nil 159 | } 160 | return nil, fmt.Errorf("AssetInfo %s not found", name) 161 | } 162 | 163 | // AssetNames returns the names of the assets. 164 | func AssetNames() []string { 165 | names := make([]string, 0, len(_bindata)) 166 | for name := range _bindata { 167 | names = append(names, name) 168 | } 169 | return names 170 | } 171 | 172 | // _bindata is a table, holding each asset generator, mapped to its name. 173 | var _bindata = map[string]func() (*asset, error){ 174 | "assets/html/clash-config.yaml": assetsHtmlClashConfigYaml, 175 | "assets/html/clash.html": assetsHtmlClashHtml, 176 | "assets/html/index.html": assetsHtmlIndexHtml, 177 | "assets/html/surge.conf": assetsHtmlSurgeConf, 178 | "assets/html/surge.html": assetsHtmlSurgeHtml, 179 | } 180 | 181 | // AssetDir returns the file names below a certain 182 | // directory embedded in the file by go-bindata. 183 | // For example if you run go-bindata on data/... and data contains the 184 | // following hierarchy: 185 | // data/ 186 | // foo.txt 187 | // img/ 188 | // a.png 189 | // b.png 190 | // then AssetDir("data") would return []string{"foo.txt", "img"} 191 | // AssetDir("data/img") would return []string{"a.png", "b.png"} 192 | // AssetDir("foo.txt") and AssetDir("notexist") would return an error 193 | // AssetDir("") will return []string{"data"}. 194 | func AssetDir(name string) ([]string, error) { 195 | node := _bintree 196 | if len(name) != 0 { 197 | cannonicalName := strings.Replace(name, "\\", "/", -1) 198 | pathList := strings.Split(cannonicalName, "/") 199 | for _, p := range pathList { 200 | node = node.Children[p] 201 | if node == nil { 202 | return nil, fmt.Errorf("Asset %s not found", name) 203 | } 204 | } 205 | } 206 | if node.Func != nil { 207 | return nil, fmt.Errorf("Asset %s not found", name) 208 | } 209 | rv := make([]string, 0, len(node.Children)) 210 | for childName := range node.Children { 211 | rv = append(rv, childName) 212 | } 213 | return rv, nil 214 | } 215 | 216 | type bintree struct { 217 | Func func() (*asset, error) 218 | Children map[string]*bintree 219 | } 220 | 221 | var _bintree = &bintree{nil, map[string]*bintree{ 222 | "assets": &bintree{nil, map[string]*bintree{ 223 | "html": &bintree{nil, map[string]*bintree{ 224 | "clash-config.yaml": &bintree{assetsHtmlClashConfigYaml, map[string]*bintree{}}, 225 | "clash.html": &bintree{assetsHtmlClashHtml, map[string]*bintree{}}, 226 | "index.html": &bintree{assetsHtmlIndexHtml, map[string]*bintree{}}, 227 | "surge.conf": &bintree{assetsHtmlSurgeConf, map[string]*bintree{}}, 228 | "surge.html": &bintree{assetsHtmlSurgeHtml, map[string]*bintree{}}, 229 | }}, 230 | }}, 231 | }} 232 | 233 | // RestoreAsset restores an asset under the given directory 234 | func RestoreAsset(dir, name string) error { 235 | data, err := Asset(name) 236 | if err != nil { 237 | return err 238 | } 239 | info, err := AssetInfo(name) 240 | if err != nil { 241 | return err 242 | } 243 | err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) 244 | if err != nil { 245 | return err 246 | } 247 | err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) 248 | if err != nil { 249 | return err 250 | } 251 | err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) 252 | if err != nil { 253 | return err 254 | } 255 | return nil 256 | } 257 | 258 | // RestoreAssets restores an asset under the given directory recursively 259 | func RestoreAssets(dir, name string) error { 260 | children, err := AssetDir(name) 261 | // File 262 | if err != nil { 263 | return RestoreAsset(dir, name) 264 | } 265 | // Dir 266 | for _, child := range children { 267 | err = RestoreAssets(dir, filepath.Join(name, child)) 268 | if err != nil { 269 | return err 270 | } 271 | } 272 | return nil 273 | } 274 | 275 | func _filePath(dir, name string) string { 276 | cannonicalName := strings.Replace(name, "\\", "/", -1) 277 | return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) 278 | } 279 | -------------------------------------------------------------------------------- /internal/cache/cache.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/patrickmn/go-cache" 7 | "github.com/doudoubinga/proxypool/pkg/proxy" 8 | ) 9 | 10 | var c = cache.New(cache.NoExpiration, 10*time.Minute) 11 | 12 | func GetProxies(key string) proxy.ProxyList { 13 | result, found := c.Get(key) 14 | if found { 15 | return result.(proxy.ProxyList) 16 | } 17 | return nil 18 | } 19 | 20 | func SetProxies(key string, proxies proxy.ProxyList) { 21 | c.Set(key, proxies, cache.NoExpiration) 22 | } 23 | 24 | func SetString(key, value string) { 25 | c.Set(key, value, cache.NoExpiration) 26 | } 27 | 28 | func GetString(key string) string { 29 | result, found := c.Get(key) 30 | if found { 31 | return result.(string) 32 | } 33 | return "" 34 | } 35 | -------------------------------------------------------------------------------- /internal/cache/vars.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | var ( 4 | GettersCount = 0 5 | 6 | AllProxiesCount = 0 7 | SSRProxiesCount = 0 8 | SSProxiesCount = 0 9 | VmessProxiesCount = 0 10 | TrojanProxiesCount = 0 11 | 12 | UsefullProxiesCount = 0 13 | 14 | LastCrawlTime = "程序刚升级完成,正在爬取中..." 15 | ) 16 | -------------------------------------------------------------------------------- /internal/cloudflare/cache.go: -------------------------------------------------------------------------------- 1 | package cloudflare 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | "github.com/cloudflare/cloudflare-go" 8 | "github.com/doudoubinga/proxypool/config" 9 | ) 10 | 11 | func test() { 12 | api, err := cloudflare.New(config.Config.CFKey, config.Config.CFKey) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | 17 | // Fetch the zone ID 18 | id, err := api.ZoneIDByName(config.Config.Domain) 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | // Fetch zone details 24 | zone, err := api.ZoneDetails(id) 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | // Print zone details 29 | fmt.Println(zone) 30 | } 31 | -------------------------------------------------------------------------------- /internal/cron/cron.go: -------------------------------------------------------------------------------- 1 | package cron 2 | 3 | import ( 4 | "runtime" 5 | 6 | "github.com/jasonlvhit/gocron" 7 | "github.com/doudoubinga/proxypool/internal/app" 8 | ) 9 | 10 | func Cron() { 11 | _ = gocron.Every(15).Minutes().Do(crawlTask) 12 | <-gocron.Start() 13 | } 14 | 15 | func crawlTask() { 16 | _ = app.InitConfigAndGetters("") 17 | app.CrawlGo() 18 | app.Getters = nil 19 | runtime.GC() 20 | } 21 | -------------------------------------------------------------------------------- /internal/database/db.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/doudoubinga/proxypool/config" 8 | 9 | "gorm.io/driver/postgres" 10 | "gorm.io/gorm" 11 | "gorm.io/gorm/logger" 12 | ) 13 | 14 | var DB *gorm.DB 15 | 16 | func connect() (err error) { 17 | dsn := "user=proxypool password=proxypool dbname=proxypool port=5432 sslmode=disable TimeZone=Asia/Shanghai" 18 | if url := config.Config.DatabaseUrl; url != "" { 19 | dsn = url 20 | } 21 | if url := os.Getenv("DATABASE_URL"); url != "" { 22 | dsn = url 23 | } 24 | DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{ 25 | Logger: logger.Default.LogMode(logger.Silent), 26 | }) 27 | if err == nil { 28 | fmt.Println("DB connect success: ", DB.Name()) 29 | } 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /internal/database/db_test.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import "testing" 4 | 5 | func TestConnect(t *testing.T) { 6 | t.SkipNow() 7 | //connect() 8 | InitTables() 9 | } 10 | -------------------------------------------------------------------------------- /internal/database/proxy.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "github.com/doudoubinga/proxypool/pkg/proxy" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | type Proxy struct { 9 | gorm.Model 10 | proxy.Base 11 | Link string 12 | Identifier string `gorm:"unique"` 13 | } 14 | 15 | func InitTables() { 16 | if DB == nil { 17 | err := connect() 18 | if err != nil { 19 | return 20 | } 21 | } 22 | err := DB.AutoMigrate(&Proxy{}) 23 | if err != nil { 24 | panic(err) 25 | } 26 | } 27 | 28 | const roundSize = 100 29 | 30 | func SaveProxyList(pl proxy.ProxyList) { 31 | if DB == nil { 32 | return 33 | } 34 | 35 | // TODO 批量插入因为是生成一个sql,如果插入失败(重复)就全都没了 36 | //size := pl.Len() 37 | //round := (size + roundSize - 1) / roundSize 38 | // 39 | //for r := 0; r < round; r++ { 40 | // proxies := make([]Proxy, 0, roundSize) 41 | // for i, j := r*roundSize, (r+1)*roundSize-1; i < j && i < size; i++ { 42 | // p := pl[i] 43 | // proxies = append(proxies, Proxy{ 44 | // Base: *p.BaseInfo(), 45 | // Link: p.Link(), 46 | // Identifier: p.Identifier(), 47 | // }) 48 | // } 49 | // DB.Create(&proxies) 50 | //} 51 | 52 | for _, p := range pl { 53 | DB.Create(&Proxy{ 54 | Base: *p.BaseInfo(), 55 | Link: p.Link(), 56 | Identifier: p.Identifier(), 57 | }) 58 | } 59 | } 60 | 61 | func GetAllProxies() (proxies proxy.ProxyList) { 62 | proxies = make(proxy.ProxyList, 0) 63 | if DB == nil { 64 | return 65 | } 66 | 67 | proxiesDB := make([]Proxy, 0) 68 | DB.Select("link").Find(&proxiesDB) 69 | 70 | for _, proxyDB := range proxiesDB { 71 | if proxiesDB != nil { 72 | p, err := proxy.ParseProxyFromLink(proxyDB.Link) 73 | if err == nil && p != nil { 74 | proxies = append(proxies, p) 75 | } 76 | } 77 | } 78 | return 79 | } 80 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "net/http" 7 | _ "net/http/pprof" 8 | "os" 9 | 10 | "github.com/doudoubinga/proxypool/api" 11 | "github.com/doudoubinga/proxypool/internal/app" 12 | "github.com/doudoubinga/proxypool/internal/cron" 13 | "github.com/doudoubinga/proxypool/internal/database" 14 | "github.com/doudoubinga/proxypool/pkg/proxy" 15 | ) 16 | 17 | var configFilePath = "" 18 | 19 | func main() { 20 | go func() { 21 | http.ListenAndServe("0.0.0.0:6060", nil) 22 | }() 23 | 24 | flag.StringVar(&configFilePath, "c", "", "path to config file: config.yaml") 25 | flag.Parse() 26 | 27 | if configFilePath == "" { 28 | configFilePath = os.Getenv("CONFIG_FILE") 29 | } 30 | if configFilePath == "" { 31 | configFilePath = "config.yaml" 32 | } 33 | err := app.InitConfigAndGetters(configFilePath) 34 | if err != nil { 35 | panic(err) 36 | } 37 | 38 | database.InitTables() 39 | proxy.InitGeoIpDB() 40 | fmt.Println("Do the first crawl...") 41 | go app.CrawlGo() 42 | go cron.Cron() 43 | api.Run() 44 | } 45 | -------------------------------------------------------------------------------- /pkg/getter/base.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "errors" 5 | "sync" 6 | 7 | "github.com/doudoubinga/proxypool/pkg/proxy" 8 | "github.com/doudoubinga/proxypool/pkg/tool" 9 | ) 10 | 11 | type Getter interface { 12 | Get() proxy.ProxyList 13 | Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) 14 | } 15 | 16 | type creator func(options tool.Options) (getter Getter, err error) 17 | 18 | var creatorMap = make(map[string]creator) 19 | 20 | func Register(sourceType string, c creator) { 21 | creatorMap[sourceType] = c 22 | } 23 | 24 | func NewGetter(sourceType string, options tool.Options) (getter Getter, err error) { 25 | c, ok := creatorMap[sourceType] 26 | if ok { 27 | return c(options) 28 | } 29 | return nil, ErrorCreaterNotSupported 30 | } 31 | 32 | func StringArray2ProxyArray(origin []string) proxy.ProxyList { 33 | results := make(proxy.ProxyList, 0) 34 | for _, link := range origin { 35 | p, err := proxy.ParseProxyFromLink(link) 36 | if err == nil && p != nil { 37 | results = append(results, p) 38 | } 39 | } 40 | return results 41 | } 42 | 43 | func GrepLinksFromString(text string) []string { 44 | results := proxy.GrepSSRLinkFromString(text) 45 | results = append(results, proxy.GrepVmessLinkFromString(text)...) 46 | results = append(results, proxy.GrepSSLinkFromString(text)...) 47 | results = append(results, proxy.GrepTrojanLinkFromString(text)...) 48 | return results 49 | } 50 | 51 | func FuzzParseProxyFromString(text string) proxy.ProxyList { 52 | return StringArray2ProxyArray(GrepLinksFromString(text)) 53 | } 54 | 55 | var ( 56 | ErrorUrlNotFound = errors.New("url should be specified") 57 | ErrorCreaterNotSupported = errors.New("type not supported") 58 | ) 59 | 60 | func AssertTypeStringNotNull(i interface{}) (str string, err error) { 61 | switch i.(type) { 62 | case string: 63 | str = i.(string) 64 | if str == "" { 65 | return "", errors.New("string is null") 66 | } 67 | return str, nil 68 | default: 69 | return "", errors.New("type is not string") 70 | } 71 | return "", nil 72 | } 73 | -------------------------------------------------------------------------------- /pkg/getter/subscribe.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | "strings" 7 | "sync" 8 | 9 | "github.com/doudoubinga/proxypool/pkg/proxy" 10 | "github.com/doudoubinga/proxypool/pkg/tool" 11 | ) 12 | 13 | func init() { 14 | Register("subscribe", NewSubscribe) 15 | } 16 | 17 | type Subscribe struct { 18 | Url string 19 | } 20 | 21 | func (s *Subscribe) Get() proxy.ProxyList { 22 | resp, err := tool.GetHttpClient().Get(s.Url) 23 | if err != nil { 24 | return nil 25 | } 26 | defer resp.Body.Close() 27 | body, err := ioutil.ReadAll(resp.Body) 28 | if err != nil { 29 | return nil 30 | } 31 | 32 | nodesString, err := tool.Base64DecodeString(string(body)) 33 | if err != nil { 34 | return nil 35 | } 36 | nodesString = strings.ReplaceAll(nodesString, "\t", "") 37 | 38 | nodes := strings.Split(nodesString, "\n") 39 | return StringArray2ProxyArray(nodes) 40 | } 41 | 42 | func (s *Subscribe) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) { 43 | defer wg.Done() 44 | nodes := s.Get() 45 | log.Printf("STATISTIC: Subscribe\tcount=%d\turl=%s\n", len(nodes), s.Url) 46 | for _, node := range nodes { 47 | pc <- node 48 | } 49 | } 50 | 51 | func NewSubscribe(options tool.Options) (getter Getter, err error) { 52 | urlInterface, found := options["url"] 53 | if found { 54 | url, err := AssertTypeStringNotNull(urlInterface) 55 | if err != nil { 56 | return nil, err 57 | } 58 | return &Subscribe{ 59 | Url: url, 60 | }, nil 61 | } 62 | return nil, ErrorUrlNotFound 63 | } 64 | -------------------------------------------------------------------------------- /pkg/getter/tgchannel.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "sync" 7 | 8 | "github.com/gocolly/colly" 9 | "github.com/doudoubinga/proxypool/pkg/proxy" 10 | "github.com/doudoubinga/proxypool/pkg/tool" 11 | ) 12 | 13 | func init() { 14 | Register("tgchannel", NewTGChannelGetter) 15 | } 16 | 17 | type TGChannelGetter struct { 18 | c *colly.Collector 19 | NumNeeded int 20 | results []string 21 | Url string 22 | } 23 | 24 | func NewTGChannelGetter(options tool.Options) (getter Getter, err error) { 25 | num, found := options["num"] 26 | t := 200 27 | switch num.(type) { 28 | case int: 29 | t = num.(int) 30 | case float64: 31 | t = int(num.(float64)) 32 | } 33 | 34 | if !found || t <= 0 { 35 | t = 200 36 | } 37 | urlInterface, found := options["channel"] 38 | if found { 39 | url, err := AssertTypeStringNotNull(urlInterface) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return &TGChannelGetter{ 44 | c: tool.GetColly(), 45 | NumNeeded: t, 46 | Url: "https://t.me/s/" + url, 47 | }, nil 48 | } 49 | return nil, ErrorUrlNotFound 50 | } 51 | 52 | func (g *TGChannelGetter) Get() proxy.ProxyList { 53 | result := make(proxy.ProxyList, 0) 54 | g.results = make([]string, 0) 55 | // 找到所有的文字消息 56 | g.c.OnHTML("div.tgme_widget_message_text", func(e *colly.HTMLElement) { 57 | g.results = append(g.results, GrepLinksFromString(e.Text)...) 58 | // 抓取到http链接,有可能是订阅链接或其他链接,无论如何试一下 59 | subUrls := urlRe.FindAllString(e.Text, -1) 60 | for _, url := range subUrls { 61 | result = append(result, (&Subscribe{Url: url}).Get()...) 62 | } 63 | }) 64 | 65 | // 找到之前消息页面的链接,加入访问队列 66 | g.c.OnHTML("link[rel=prev]", func(e *colly.HTMLElement) { 67 | if len(g.results) < g.NumNeeded { 68 | _ = e.Request.Visit(e.Attr("href")) 69 | } 70 | }) 71 | 72 | g.results = make([]string, 0) 73 | err := g.c.Visit(g.Url) 74 | if err != nil { 75 | _ = fmt.Errorf("%s", err.Error()) 76 | } 77 | return append(result, StringArray2ProxyArray(g.results)...) 78 | } 79 | 80 | func (g *TGChannelGetter) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) { 81 | defer wg.Done() 82 | nodes := g.Get() 83 | log.Printf("STATISTIC: TGChannel\tcount=%d\turl=%s\n", len(nodes), g.Url) 84 | for _, node := range nodes { 85 | pc <- node 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /pkg/getter/web_fanqiangdang.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "strings" 7 | "sync" 8 | 9 | "github.com/gocolly/colly" 10 | "github.com/doudoubinga/proxypool/pkg/proxy" 11 | "github.com/doudoubinga/proxypool/pkg/tool" 12 | ) 13 | 14 | func init() { 15 | Register("web-fanqiangdang", NewWebFanqiangdangGetter) 16 | } 17 | 18 | type WebFanqiangdang struct { 19 | c *colly.Collector 20 | Url string 21 | results proxy.ProxyList 22 | } 23 | 24 | func NewWebFanqiangdangGetter(options tool.Options) (getter Getter, err error) { 25 | urlInterface, found := options["url"] 26 | if found { 27 | url, err := AssertTypeStringNotNull(urlInterface) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return &WebFanqiangdang{ 32 | c: colly.NewCollector(), 33 | Url: url, 34 | }, nil 35 | } 36 | return nil, ErrorUrlNotFound 37 | } 38 | 39 | func (w *WebFanqiangdang) Get() proxy.ProxyList { 40 | w.results = make(proxy.ProxyList, 0) 41 | w.c.OnHTML("td.t_f", func(e *colly.HTMLElement) { 42 | w.results = append(w.results, FuzzParseProxyFromString(e.Text)...) 43 | subUrls := urlRe.FindAllString(e.Text, -1) 44 | for _, url := range subUrls { 45 | w.results = append(w.results, (&Subscribe{Url: url}).Get()...) 46 | } 47 | }) 48 | 49 | w.c.OnHTML("th.new>a[href]", func(e *colly.HTMLElement) { 50 | url := e.Attr("href") 51 | if strings.HasPrefix(url, "https://fanqiangdang.com/thread") { 52 | _ = e.Request.Visit(url) 53 | } 54 | }) 55 | 56 | w.results = make(proxy.ProxyList, 0) 57 | err := w.c.Visit(w.Url) 58 | if err != nil { 59 | _ = fmt.Errorf("%s", err.Error()) 60 | } 61 | 62 | return w.results 63 | } 64 | 65 | func (w *WebFanqiangdang) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) { 66 | defer wg.Done() 67 | nodes := w.Get() 68 | log.Printf("STATISTIC: Fanqiangdang\tcount=%d\turl=%s\n", len(nodes), w.Url) 69 | for _, node := range nodes { 70 | pc <- node 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /pkg/getter/web_free_ssr_xyz.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "encoding/json" 5 | "io/ioutil" 6 | "log" 7 | "sync" 8 | 9 | "github.com/doudoubinga/proxypool/pkg/proxy" 10 | "github.com/doudoubinga/proxypool/pkg/tool" 11 | ) 12 | 13 | func init() { 14 | Register("web-freessrxyz", NewWebFreessrxyzGetter) 15 | } 16 | 17 | const ( 18 | freessrxyzSsrLink = "https://api.free-ssr.xyz/ssr" 19 | freessrxyzV2rayLink = "https://api.free-ssr.xyz/v2ray" 20 | ) 21 | 22 | type WebFreessrXyz struct { 23 | } 24 | 25 | func NewWebFreessrxyzGetter(options tool.Options) (getter Getter, err error) { 26 | return &WebFreessrXyz{}, nil 27 | } 28 | 29 | func (w *WebFreessrXyz) Get() proxy.ProxyList { 30 | results := freessrxyzFetch(freessrxyzSsrLink) 31 | results = append(results, freessrxyzFetch(freessrxyzV2rayLink)...) 32 | return results 33 | } 34 | 35 | func (w *WebFreessrXyz) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) { 36 | defer wg.Done() 37 | nodes := w.Get() 38 | log.Printf("STATISTIC: FreeSSRxyz\tcount=%d\turl=%s\n", len(nodes), "api.free-ssr.xyz") 39 | for _, node := range nodes { 40 | pc <- node 41 | } 42 | } 43 | 44 | func freessrxyzFetch(link string) proxy.ProxyList { 45 | resp, err := tool.GetHttpClient().Get(link) 46 | if err != nil { 47 | return nil 48 | } 49 | defer resp.Body.Close() 50 | body, err := ioutil.ReadAll(resp.Body) 51 | if err != nil { 52 | return nil 53 | } 54 | 55 | type node struct { 56 | Url string `json:"url"` 57 | } 58 | ssrs := make([]node, 0) 59 | err = json.Unmarshal(body, &ssrs) 60 | if err != nil { 61 | return nil 62 | } 63 | 64 | result := make([]string, 0) 65 | for _, node := range ssrs { 66 | result = append(result, node.Url) 67 | } 68 | 69 | return StringArray2ProxyArray(result) 70 | } 71 | -------------------------------------------------------------------------------- /pkg/getter/web_fuzz.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | "sync" 7 | 8 | "github.com/doudoubinga/proxypool/pkg/proxy" 9 | "github.com/doudoubinga/proxypool/pkg/tool" 10 | ) 11 | 12 | func init() { 13 | Register("webfuzz", NewWebFuzzGetter) 14 | } 15 | 16 | type WebFuzz struct { 17 | Url string 18 | } 19 | 20 | func (w *WebFuzz) Get() proxy.ProxyList { 21 | resp, err := tool.GetHttpClient().Get(w.Url) 22 | if err != nil { 23 | return nil 24 | } 25 | defer resp.Body.Close() 26 | body, err := ioutil.ReadAll(resp.Body) 27 | if err != nil { 28 | return nil 29 | } 30 | 31 | return FuzzParseProxyFromString(string(body)) 32 | } 33 | 34 | func (w *WebFuzz) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) { 35 | defer wg.Done() 36 | nodes := w.Get() 37 | log.Printf("STATISTIC: WebFuzz\tcount=%d\turl=%s\n", len(nodes), w.Url) 38 | for _, node := range nodes { 39 | pc <- node 40 | } 41 | } 42 | 43 | func NewWebFuzzGetter(options tool.Options) (getter Getter, err error) { 44 | urlInterface, found := options["url"] 45 | if found { 46 | url, err := AssertTypeStringNotNull(urlInterface) 47 | if err != nil { 48 | return nil, err 49 | } 50 | return &WebFuzz{Url: url}, nil 51 | } 52 | return nil, ErrorUrlNotFound 53 | } 54 | -------------------------------------------------------------------------------- /pkg/getter/web_fuzz_sub.go: -------------------------------------------------------------------------------- 1 | package getter 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | "regexp" 7 | "sync" 8 | 9 | "github.com/doudoubinga/proxypool/pkg/proxy" 10 | "github.com/doudoubinga/proxypool/pkg/tool" 11 | ) 12 | 13 | func init() { 14 | Register("webfuzzsub", NewWebFuzzSubGetter) 15 | } 16 | 17 | type WebFuzzSub struct { 18 | Url string 19 | } 20 | 21 | func (w *WebFuzzSub) Get() proxy.ProxyList { 22 | resp, err := tool.GetHttpClient().Get(w.Url) 23 | if err != nil { 24 | return nil 25 | } 26 | defer resp.Body.Close() 27 | body, err := ioutil.ReadAll(resp.Body) 28 | if err != nil { 29 | return nil 30 | } 31 | text := string(body) 32 | subUrls := urlRe.FindAllString(text, -1) 33 | result := make(proxy.ProxyList, 0) 34 | for _, url := range subUrls { 35 | result = append(result, (&Subscribe{Url: url}).Get()...) 36 | } 37 | return result 38 | } 39 | 40 | func (w *WebFuzzSub) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) { 41 | defer wg.Done() 42 | nodes := w.Get() 43 | log.Printf("STATISTIC: WebFuzzSub\tcount=%d\turl=%s\n", len(nodes), w.Url) 44 | for _, node := range nodes { 45 | pc <- node 46 | } 47 | } 48 | 49 | func NewWebFuzzSubGetter(options tool.Options) (getter Getter, err error) { 50 | urlInterface, found := options["url"] 51 | if found { 52 | url, err := AssertTypeStringNotNull(urlInterface) 53 | if err != nil { 54 | return nil, err 55 | } 56 | return &WebFuzzSub{Url: url}, nil 57 | } 58 | return nil, ErrorUrlNotFound 59 | } 60 | 61 | var urlRe = regexp.MustCompile(urlPattern) 62 | 63 | const ( 64 | // 匹配 IP4 65 | ip4Pattern = `((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)` 66 | 67 | // 匹配 IP6,参考以下网页内容: 68 | // http://blog.csdn.net/jiangfeng08/article/details/7642018 69 | ip6Pattern = `(([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|` + 70 | `(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|` + 71 | `(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|` + 72 | `(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|` + 73 | `(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|` + 74 | `(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|` + 75 | `(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|` + 76 | `(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))` 77 | 78 | // 同时匹配 IP4 和 IP6 79 | ipPattern = "(" + ip4Pattern + ")|(" + ip6Pattern + ")" 80 | 81 | // 匹配域名 82 | domainPattern = `[a-zA-Z0-9][a-zA-Z0-9_-]{0,62}(\.[a-zA-Z0-9][a-zA-Z0-9_-]{0,62})*(\.[a-zA-Z][a-zA-Z0-9]{0,10}){1}` 83 | 84 | // 匹配 URL 85 | urlPattern = `((https|http)?://)?` + // 协议 86 | `(([0-9a-zA-Z]+:)?[0-9a-zA-Z_-]+@)?` + // pwd:user@ 87 | "(" + ipPattern + "|(" + domainPattern + "))" + // IP 或域名 88 | `(:\d{1,5})?` + // 端口 89 | `(/+[a-zA-Z0-9][a-zA-Z0-9_.-]*)*/*` + // path 90 | `(\?([a-zA-Z0-9_-]+(=.*&?)*)*)*` // query 91 | ) 92 | -------------------------------------------------------------------------------- /pkg/provider/base.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/doudoubinga/proxypool/pkg/proxy" 7 | ) 8 | 9 | type Provider interface { 10 | Provide() string 11 | } 12 | 13 | type Base struct { 14 | Proxies *proxy.ProxyList `yaml:"proxies"` 15 | Types string `yaml:"type"` 16 | Country string `yaml:"country"` 17 | NotCountry string `yaml:"not_country"` 18 | } 19 | 20 | func (b *Base) preFilter() { 21 | proxies := make(proxy.ProxyList, 0) 22 | 23 | needFilterType := true 24 | needFilterCountry := true 25 | needFilterNotCountry := true 26 | if b.Types == "" || b.Types == "all" { 27 | needFilterType = false 28 | } 29 | if b.Country == "" || b.Country == "all" { 30 | needFilterCountry = false 31 | } 32 | if b.NotCountry == "" { 33 | needFilterNotCountry = false 34 | } 35 | types := strings.Split(b.Types, ",") 36 | countries := strings.Split(b.Country, ",") 37 | notCountries := strings.Split(b.NotCountry, ",") 38 | 39 | bProxies := *b.Proxies 40 | for _, p := range bProxies { 41 | if needFilterType { 42 | typeOk := false 43 | for _, t := range types { 44 | if p.TypeName() == t { 45 | typeOk = true 46 | break 47 | } 48 | } 49 | if !typeOk { 50 | goto exclude 51 | } 52 | } 53 | 54 | if needFilterNotCountry { 55 | for _, c := range notCountries { 56 | if strings.Contains(p.BaseInfo().Name, c) { 57 | goto exclude 58 | } 59 | } 60 | } 61 | 62 | if needFilterCountry { 63 | countryOk := false 64 | for _, c := range countries { 65 | if strings.Contains(p.BaseInfo().Name, c) { 66 | countryOk = true 67 | break 68 | } 69 | } 70 | if !countryOk { 71 | goto exclude 72 | } 73 | } 74 | 75 | proxies = append(proxies, p) 76 | exclude: 77 | } 78 | 79 | b.Proxies = &proxies 80 | } 81 | -------------------------------------------------------------------------------- /pkg/provider/clash.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/doudoubinga/proxypool/pkg/tool" 7 | 8 | "github.com/doudoubinga/proxypool/pkg/proxy" 9 | ) 10 | 11 | type Clash struct { 12 | Base 13 | } 14 | 15 | func (c Clash) CleanProxies() (proxies proxy.ProxyList) { 16 | proxies = make(proxy.ProxyList, 0) 17 | for _, p := range *c.Proxies { 18 | if checkClashSupport(p) { 19 | proxies = append(proxies, p) 20 | } 21 | } 22 | return 23 | } 24 | 25 | func (c Clash) Provide() string { 26 | c.preFilter() 27 | 28 | var resultBuilder strings.Builder 29 | resultBuilder.WriteString("proxies:\n") 30 | for _, p := range *c.Proxies { 31 | if checkClashSupport(p) { 32 | resultBuilder.WriteString(p.ToClash() + "\n") 33 | } 34 | } 35 | return resultBuilder.String() 36 | } 37 | 38 | func checkClashSupport(p proxy.Proxy) bool { 39 | switch p.TypeName() { 40 | case "ssr": 41 | ssr := p.(*proxy.ShadowsocksR) 42 | if tool.CheckInList(proxy.SSRCipherList, ssr.Cipher) && tool.CheckInList(ssrProtocolList, ssr.Protocol) && tool.CheckInList(ssrObfsList, ssr.Obfs) { 43 | return true 44 | } 45 | case "vmess": 46 | vmess := p.(*proxy.Vmess) 47 | if tool.CheckInList(vmessCipherList, vmess.Cipher) { 48 | return true 49 | } 50 | case "ss": 51 | ss := p.(*proxy.Shadowsocks) 52 | if tool.CheckInList(proxy.SSCipherList, ss.Cipher) { 53 | return true 54 | } 55 | case "trojan": 56 | return true 57 | default: 58 | return false 59 | } 60 | return false 61 | } 62 | 63 | var ssrObfsList = []string{ 64 | "plain", 65 | "http_simple", 66 | "http_post", 67 | "random_head", 68 | "tls1.2_ticket_auth", 69 | "tls1.2_ticket_fastauth", 70 | } 71 | 72 | var ssrProtocolList = []string{ 73 | "origin", 74 | "verify_deflate", 75 | "verify_sha1", 76 | "auth_sha1", 77 | "auth_sha1_v2", 78 | "auth_sha1_v4", 79 | "auth_aes128_md5", 80 | "auth_aes128_sha1", 81 | "auth_chain_a", 82 | "auth_chain_b", 83 | } 84 | 85 | var vmessCipherList = []string{ 86 | "auto", 87 | "aes-128-gcm", 88 | "chacha20-poly1305", 89 | "none", 90 | } 91 | -------------------------------------------------------------------------------- /pkg/provider/ssrsub.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/doudoubinga/proxypool/pkg/tool" 7 | ) 8 | 9 | type SSRSub struct { 10 | Base 11 | } 12 | 13 | func (sub SSRSub) Provide() string { 14 | sub.Types = "ssr" 15 | sub.preFilter() 16 | var resultBuilder strings.Builder 17 | for _, p := range *sub.Proxies { 18 | resultBuilder.WriteString(p.Link() + "\n") 19 | } 20 | return tool.Base64EncodeString(resultBuilder.String(), false) 21 | } 22 | -------------------------------------------------------------------------------- /pkg/provider/sssub.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "encoding/json" 5 | "strconv" 6 | "strings" 7 | 8 | "github.com/doudoubinga/proxypool/pkg/tool" 9 | 10 | "github.com/doudoubinga/proxypool/pkg/proxy" 11 | ) 12 | 13 | type SSSub struct { 14 | Base 15 | } 16 | 17 | type ssJson struct { 18 | Remarks string `json:"remarks"` 19 | Server string `json:"server"` 20 | ServerPort string `json:"server_port"` 21 | Method string `json:"method"` 22 | Password string `json:"password"` 23 | Plugin string `json:"plugin"` 24 | PluginOpts map[string]interface{} `json:"plugin_opts"` 25 | } 26 | 27 | func (sub SSSub) Provide() string { 28 | sub.Types = "ss" 29 | sub.preFilter() 30 | proxies := make([]ssJson, 0, sub.Proxies.Len()) 31 | for _, p := range *sub.Proxies { 32 | pp := p.(*proxy.Shadowsocks) 33 | proxies = append(proxies, ssJson{ 34 | Remarks: pp.Name, 35 | Server: pp.Server, 36 | ServerPort: strconv.Itoa(pp.Port), 37 | Method: pp.Cipher, 38 | Password: pp.Password, 39 | Plugin: pp.Plugin, 40 | PluginOpts: pp.PluginOpts, 41 | }) 42 | } 43 | text, err := json.Marshal(proxies) 44 | if err != nil { 45 | return "" 46 | } 47 | return string(text) 48 | } 49 | 50 | type SIP002Sub struct { 51 | Base 52 | } 53 | 54 | func (sub SIP002Sub) Provide() string { 55 | sub.Types = "ss" 56 | sub.preFilter() 57 | var resultBuilder strings.Builder 58 | for _, p := range *sub.Proxies { 59 | resultBuilder.WriteString(p.Link() + "\n") 60 | } 61 | return tool.Base64EncodeString(resultBuilder.String(), false) 62 | } 63 | -------------------------------------------------------------------------------- /pkg/provider/surge.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/doudoubinga/proxypool/pkg/tool" 7 | 8 | "github.com/doudoubinga/proxypool/pkg/proxy" 9 | ) 10 | 11 | type Surge struct { 12 | Base 13 | } 14 | 15 | func (s Surge) Provide() string { 16 | s.preFilter() 17 | 18 | var resultBuilder strings.Builder 19 | for _, p := range *s.Proxies { 20 | if checkSurgeSupport(p) { 21 | resultBuilder.WriteString(p.ToSurge() + "\n") 22 | } 23 | } 24 | return resultBuilder.String() 25 | } 26 | 27 | func checkSurgeSupport(p proxy.Proxy) bool { 28 | switch p.(type) { 29 | case *proxy.ShadowsocksR: 30 | return false 31 | case *proxy.Vmess: 32 | return true 33 | case *proxy.Shadowsocks: 34 | ss := p.(*proxy.Shadowsocks) 35 | if tool.CheckInList(proxy.SSCipherList, ss.Cipher) { 36 | return true 37 | } 38 | default: 39 | return false 40 | } 41 | return false 42 | } 43 | -------------------------------------------------------------------------------- /pkg/provider/vmesssub.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/doudoubinga/proxypool/pkg/tool" 7 | ) 8 | 9 | type VmessSub struct { 10 | Base 11 | } 12 | 13 | func (sub VmessSub) Provide() string { 14 | sub.Types = "vmess" 15 | sub.preFilter() 16 | var resultBuilder strings.Builder 17 | for _, p := range *sub.Proxies { 18 | resultBuilder.WriteString(p.Link() + "\n") 19 | } 20 | return tool.Base64EncodeString(resultBuilder.String(), false) 21 | } 22 | -------------------------------------------------------------------------------- /pkg/proxy/base.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | ) 7 | 8 | type Base struct { 9 | Name string `yaml:"name" json:"name" gorm:"index"` 10 | Server string `yaml:"server" json:"server" gorm:"index"` 11 | Port int `yaml:"port" json:"port" gorm:"index"` 12 | Type string `yaml:"type" json:"type" gorm:"index"` 13 | UDP bool `yaml:"udp,omitempty" json:"udp,omitempty"` 14 | Country string `yaml:"country,omitempty" json:"country,omitempty" gorm:"index"` 15 | Useable bool `yaml:"useable,omitempty" json:"useable,omitempty" gorm:"index"` 16 | } 17 | 18 | func (b *Base) TypeName() string { 19 | if b.Type == "" { 20 | return "unknown" 21 | } 22 | return b.Type 23 | } 24 | 25 | func (b *Base) SetName(name string) { 26 | b.Name = name 27 | } 28 | 29 | func (b *Base) SetIP(ip string) { 30 | b.Server = ip 31 | } 32 | 33 | func (b *Base) BaseInfo() *Base { 34 | return b 35 | } 36 | 37 | func (b *Base) Clone() Base { 38 | c := *b 39 | return c 40 | } 41 | 42 | func (b *Base) SetUseable(useable bool) { 43 | b.Useable = useable 44 | } 45 | 46 | func (b *Base) SetCountry(country string) { 47 | b.Country = country 48 | } 49 | 50 | type Proxy interface { 51 | String() string 52 | ToClash() string 53 | ToSurge() string 54 | Link() string 55 | Identifier() string 56 | SetName(name string) 57 | SetIP(ip string) 58 | TypeName() string 59 | BaseInfo() *Base 60 | Clone() Proxy 61 | SetUseable(useable bool) 62 | SetCountry(country string) 63 | } 64 | 65 | func ParseProxyFromLink(link string) (p Proxy, err error) { 66 | if strings.HasPrefix(link, "ssr://") { 67 | p, err = ParseSSRLink(link) 68 | } else if strings.HasPrefix(link, "vmess://") { 69 | p, err = ParseVmessLink(link) 70 | } else if strings.HasPrefix(link, "ss://") { 71 | p, err = ParseSSLink(link) 72 | } else if strings.HasPrefix(link, "trojan://") { 73 | p, err = ParseTrojanLink(link) 74 | } 75 | if err != nil || p == nil { 76 | return nil, errors.New("link parse failed") 77 | } 78 | ip, country, err := geoIp.Find(p.BaseInfo().Server) 79 | if err != nil { 80 | country = "🏁 ZZ" 81 | } 82 | p.SetCountry(country) 83 | // trojan依赖域名? 84 | if p.TypeName() != "trojan" { 85 | p.SetIP(ip) 86 | } 87 | return 88 | } 89 | -------------------------------------------------------------------------------- /pkg/proxy/check.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "sync" 8 | "time" 9 | 10 | "github.com/ivpusic/grpool" 11 | 12 | "github.com/Dreamacro/clash/adapters/outbound" 13 | ) 14 | 15 | const defaultURLTestTimeout = time.Second * 5 16 | 17 | func testDelay(p Proxy) (delay uint16, err error) { 18 | pmap := make(map[string]interface{}) 19 | err = json.Unmarshal([]byte(p.String()), &pmap) 20 | if err != nil { 21 | return 22 | } 23 | 24 | pmap["port"] = int(pmap["port"].(float64)) 25 | if p.TypeName() == "vmess" { 26 | pmap["alterId"] = int(pmap["alterId"].(float64)) 27 | } 28 | 29 | clashProxy, err := outbound.ParseProxy(pmap) 30 | if err != nil { 31 | fmt.Println(err.Error()) 32 | return 33 | } 34 | 35 | ctx, cancel := context.WithTimeout(context.Background(), defaultURLTestTimeout) 36 | delay, err = clashProxy.URLTest(ctx, "http://www.gstatic.com/generate_204") 37 | cancel() 38 | return delay, err 39 | } 40 | 41 | func CleanBadProxiesWithGrpool(proxies []Proxy) (cproxies []Proxy) { 42 | pool := grpool.NewPool(500, 200) 43 | 44 | c := make(chan checkResult) 45 | defer close(c) 46 | 47 | pool.WaitCount(len(proxies)) 48 | go func() { 49 | for _, p := range proxies { 50 | pp := p 51 | pool.JobQueue <- func() { 52 | defer pool.JobDone() 53 | delay, err := testDelay(pp) 54 | if err == nil { 55 | c <- checkResult{ 56 | name: pp.Identifier(), 57 | delay: delay, 58 | } 59 | } 60 | } 61 | } 62 | }() 63 | done := make(chan struct{}) 64 | defer close(done) 65 | 66 | go func() { 67 | pool.WaitAll() 68 | pool.Release() 69 | done <- struct{}{} 70 | }() 71 | 72 | okMap := make(map[string]struct{}) 73 | for { 74 | select { 75 | case r := <-c: 76 | if r.delay > 0 { 77 | okMap[r.name] = struct{}{} 78 | } 79 | case <-done: 80 | cproxies = make(ProxyList, 0, 500) 81 | for _, p := range proxies { 82 | if _, ok := okMap[p.Identifier()]; ok { 83 | cproxies = append(cproxies, p.Clone()) 84 | } 85 | } 86 | return 87 | } 88 | } 89 | } 90 | 91 | func CleanBadProxies(proxies []Proxy) (cproxies []Proxy) { 92 | c := make(chan checkResult, 40) 93 | wg := &sync.WaitGroup{} 94 | wg.Add(len(proxies)) 95 | for _, p := range proxies { 96 | go testProxyDelayToChan(p, c, wg) 97 | } 98 | go func() { 99 | wg.Wait() 100 | close(c) 101 | }() 102 | 103 | okMap := make(map[string]struct{}) 104 | for r := range c { 105 | if r.delay > 0 { 106 | okMap[r.name] = struct{}{} 107 | } 108 | } 109 | cproxies = make(ProxyList, 0, 500) 110 | for _, p := range proxies { 111 | if _, ok := okMap[p.Identifier()]; ok { 112 | p.SetUseable(true) 113 | cproxies = append(cproxies, p.Clone()) 114 | } else { 115 | p.SetUseable(false) 116 | } 117 | } 118 | return 119 | } 120 | 121 | type checkResult struct { 122 | name string 123 | delay uint16 124 | } 125 | 126 | func testProxyDelayToChan(p Proxy, c chan checkResult, wg *sync.WaitGroup) { 127 | defer wg.Done() 128 | delay, err := testDelay(p) 129 | if err == nil { 130 | c <- checkResult{ 131 | name: p.Identifier(), 132 | delay: delay, 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /pkg/proxy/convert.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/doudoubinga/proxypool/pkg/tool" 7 | ) 8 | 9 | var ErrorTypeCanNotConvert = errors.New("type not support") 10 | 11 | // Convert2SS convert proxy to ShadowsocksR if possible 12 | func Convert2SSR(p Proxy) (ssr *ShadowsocksR, err error) { 13 | if p.TypeName() == "ss" { 14 | ss := p.(*Shadowsocks) 15 | if ss == nil { 16 | return nil, errors.New("ss is nil") 17 | } 18 | if !tool.CheckInList(SSRCipherList, ss.Cipher) { 19 | return nil, errors.New("cipher not support") 20 | } 21 | base := ss.Base 22 | base.Type = "ssr" 23 | return &ShadowsocksR{ 24 | Base: base, 25 | Password: ss.Password, 26 | Cipher: ss.Cipher, 27 | Protocol: "origin", 28 | Obfs: "plain", 29 | Group: "proxy.tgbot.co", 30 | }, nil 31 | } 32 | return nil, ErrorTypeCanNotConvert 33 | } 34 | 35 | // Convert2SS convert proxy to Shadowsocks if possible 36 | func Convert2SS(p Proxy) (ss *Shadowsocks, err error) { 37 | if p.TypeName() == "ss" { 38 | ssr := p.(*ShadowsocksR) 39 | if ssr == nil { 40 | return nil, errors.New("ssr is nil") 41 | } 42 | if !tool.CheckInList(SSCipherList, ssr.Cipher) { 43 | return nil, errors.New("cipher not support") 44 | } 45 | if ssr.Protocol != "origin" || ssr.Obfs != "plain" { 46 | return nil, errors.New("protocol or obfs not allowed") 47 | } 48 | base := ssr.Base 49 | base.Type = "ss" 50 | return &Shadowsocks{ 51 | Base: base, 52 | Password: ssr.Password, 53 | Cipher: ssr.Cipher, 54 | Plugin: "", 55 | PluginOpts: nil, 56 | }, nil 57 | } 58 | return nil, ErrorTypeCanNotConvert 59 | } 60 | 61 | var SSRCipherList = []string{ 62 | "aes-128-cfb", 63 | "aes-192-cfb", 64 | "aes-256-cfb", 65 | "aes-128-ctr", 66 | "aes-192-ctr", 67 | "aes-256-ctr", 68 | "aes-128-ofb", 69 | "aes-192-ofb", 70 | "aes-256-ofb", 71 | "des-cfb", 72 | "bf-cfb", 73 | "cast5-cfb", 74 | "rc4-md5", 75 | "chacha20-ietf", 76 | "salsa20", 77 | "camellia-128-cfb", 78 | "camellia-192-cfb", 79 | "camellia-256-cfb", 80 | "idea-cfb", 81 | "rc2-cfb", 82 | "seed-cfb", 83 | } 84 | 85 | var SSCipherList = []string{ 86 | "aes-128-gcm", 87 | "aes-192-gcm", 88 | "aes-256-gcm", 89 | "aes-128-cfb", 90 | "aes-192-cfb", 91 | "aes-256-cfb", 92 | "aes-128-ctr", 93 | "aes-192-ctr", 94 | "aes-256-ctr", 95 | "rc4-md5", 96 | "chacha20-ietf", 97 | "xchacha20", 98 | "chacha20-ietf-poly1305", 99 | "xchacha20-ietf-poly1305", 100 | } 101 | -------------------------------------------------------------------------------- /pkg/proxy/geoip.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "net" 9 | "os" 10 | 11 | "github.com/oschwald/geoip2-golang" 12 | bingeoip "github.com/doudoubinga/proxypool/internal/bindata/geoip" 13 | ) 14 | 15 | var geoIp GeoIP 16 | 17 | func InitGeoIpDB() { 18 | err := bingeoip.RestoreAsset("", "assets/GeoLite2-City.mmdb") 19 | if err != nil { 20 | panic(err) 21 | } 22 | err = bingeoip.RestoreAsset("", "assets/flags.json") 23 | if err != nil { 24 | panic(err) 25 | } 26 | geoIp = NewGeoIP("assets/GeoLite2-City.mmdb", "assets/flags.json") 27 | } 28 | 29 | // GeoIP2 30 | type GeoIP struct { 31 | db *geoip2.Reader 32 | emojiMap map[string]string 33 | } 34 | 35 | type CountryEmoji struct { 36 | Code string `json:"code"` 37 | Emoji string `json:"emoji"` 38 | } 39 | 40 | // new geoip from db file 41 | func NewGeoIP(geodb, flags string) (geoip GeoIP) { 42 | // 判断文件是否存在 43 | _, err := os.Stat(geodb) 44 | if err != nil && os.IsNotExist(err) { 45 | log.Println("文件不存在,请自行下载 Geoip2 City库,并保存在", geodb) 46 | os.Exit(1) 47 | } else { 48 | db, err := geoip2.Open(geodb) 49 | if err != nil { 50 | log.Fatal(err) 51 | } 52 | geoip.db = db 53 | } 54 | 55 | _, err = os.Stat(flags) 56 | if err != nil && os.IsNotExist(err) { 57 | log.Println("flags 文件不存在,请自行下载 flags.json,并保存在", flags) 58 | os.Exit(1) 59 | } else { 60 | data, err := ioutil.ReadFile(flags) 61 | if err != nil { 62 | log.Fatal(err) 63 | return 64 | } 65 | var countryEmojiList = make([]CountryEmoji, 0) 66 | err = json.Unmarshal(data, &countryEmojiList) 67 | if err != nil { 68 | log.Fatalln(err.Error()) 69 | return 70 | } 71 | 72 | emojiMap := make(map[string]string) 73 | for _, i := range countryEmojiList { 74 | emojiMap[i.Code] = i.Emoji 75 | } 76 | geoip.emojiMap = emojiMap 77 | } 78 | return 79 | } 80 | 81 | // find ip info 82 | func (g GeoIP) Find(ipORdomain string) (ip, country string, err error) { 83 | ips, err := net.LookupIP(ipORdomain) 84 | if err != nil { 85 | return "", "", err 86 | } 87 | ip = ips[0].String() 88 | 89 | var record *geoip2.City 90 | record, err = g.db.City(ips[0]) 91 | if err != nil { 92 | return 93 | } 94 | countryIsoCode := record.Country.IsoCode 95 | if countryIsoCode == "" { 96 | country = fmt.Sprintf("🏁 ZZ") 97 | } 98 | emoji, found := g.emojiMap[countryIsoCode] 99 | if found { 100 | country = fmt.Sprintf("%v %v", emoji, countryIsoCode) 101 | } else { 102 | country = fmt.Sprintf("🏁 ZZ") 103 | } 104 | return 105 | } 106 | -------------------------------------------------------------------------------- /pkg/proxy/link_test.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestSSLink(t *testing.T) { 9 | ss, err := ParseSSLink("ss://YWVzLTI1Ni1jZmI6ZUlXMERuazY5NDU0ZTZuU3d1c3B2OURtUzIwMXRRMERAMTcyLjEwNC4xNjEuNTQ6ODA5OQ==#翻墙党223.13新加坡") 10 | if err != nil { 11 | t.Error(err) 12 | } 13 | fmt.Println(ss) 14 | fmt.Println(ss.Link()) 15 | ss, err = ParseSSLink(ss.Link()) 16 | if err != nil { 17 | t.Error(err) 18 | } 19 | fmt.Println(ss) 20 | } 21 | 22 | func TestSSRLink(t *testing.T) { 23 | ssr, err := ParseSSRLink("ssr://MTcyLjEwNC4xNjEuNTQ6ODA5OTpvcmlnaW46YWVzLTI1Ni1jZmI6cGxhaW46WlVsWE1FUnVhelk1TkRVMFpUWnVVM2QxYzNCMk9VUnRVekl3TVhSUk1FUT0vP29iZnNwYXJhbT0mcHJvdG9wYXJhbT0mcmVtYXJrcz01Ny03NWFLWjVZV2FNakl6TGpFejVwYXc1WXFnNVoyaCZncm91cD01cGF3NVlxZzVaMmg=") 24 | if err != nil { 25 | t.Error(err) 26 | } 27 | fmt.Println(ssr) 28 | fmt.Println(ssr.Link()) 29 | ssr, err = ParseSSRLink(ssr.Link()) 30 | if err != nil { 31 | t.Error(err) 32 | } 33 | fmt.Println(ssr) 34 | } 35 | 36 | func TestTrojanLink(t *testing.T) { 37 | trojan, err := ParseTrojanLink("trojan://65474277@sqcu.hostmsu.ru:55551?allowinsecure=0&peer=mza.hkfq.xyz&mux=1&ws=0&wspath=&wshost=&ss=0&ssmethod=aes-128-gcm&sspasswd=&group=#%E9%A6%99%E6%B8%AFCN2-MZA%E8%8A%82%E7%82%B9-%E5%AE%BF%E8%BF%81%E8%81%94%E9%80%9A%E4%B8%AD%E8%BD%AC") 38 | if err != nil { 39 | t.Error(err) 40 | } 41 | fmt.Println(trojan) 42 | fmt.Println(trojan.Link()) 43 | trojan, err = ParseTrojanLink(trojan.Link()) 44 | if err != nil { 45 | t.Error(err) 46 | } 47 | fmt.Println(trojan) 48 | } 49 | 50 | func TestVmessLink(t *testing.T) { 51 | v, err := ParseVmessLink("vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogIuW+ruS/oeWFrOS8l+WPtyDlpJrlvannmoTlpKfljYPkuJbnlYwiLA0KICAiYWRkIjogInMyNzEuc25vZGUueHl6IiwNCiAgInBvcnQiOiAiNDQzIiwNCiAgImlkIjogIjZhOTAwZDYzLWNiOTItMzVhMC1hZWYwLTNhMGMxMWFhODUyMyIsDQogICJhaWQiOiAiMSIsDQogICJuZXQiOiAid3MiLA0KICAidHlwZSI6ICJub25lIiwNCiAgImhvc3QiOiAiczI3MS5zbm9kZS54eXoiLA0KICAicGF0aCI6ICIvcGFuZWwiLA0KICAidGxzIjogInRscyINCn0=") 52 | if err != nil { 53 | t.Error(err) 54 | } 55 | fmt.Println(v) 56 | fmt.Println(v.Link()) 57 | v, err = ParseVmessLink(v.Link()) 58 | if err != nil { 59 | t.Error(err) 60 | } 61 | fmt.Println(v) 62 | } 63 | -------------------------------------------------------------------------------- /pkg/proxy/proxies.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | "strings" 7 | ) 8 | 9 | type ProxyList []Proxy 10 | 11 | func (ps ProxyList) Len() int { 12 | return len(ps) 13 | } 14 | 15 | func (ps ProxyList) TypeLen(t string) int { 16 | l := 0 17 | for _, p := range ps { 18 | if p.TypeName() == t { 19 | l++ 20 | } 21 | } 22 | return l 23 | } 24 | 25 | var sortType = make(map[string]int) 26 | 27 | func init() { 28 | sortType["ss"] = 1 29 | sortType["ssr"] = 2 30 | sortType["vmess"] = 3 31 | sortType["trojan"] = 4 32 | } 33 | 34 | func (ps ProxyList) Less(i, j int) bool { 35 | if ps[i].BaseInfo().Name == ps[j].BaseInfo().Name { 36 | return sortType[ps[i].BaseInfo().Type] < sortType[ps[j].BaseInfo().Type] 37 | } else { 38 | return ps[i].BaseInfo().Name < ps[j].BaseInfo().Name 39 | } 40 | } 41 | 42 | func (ps ProxyList) Swap(i, j int) { 43 | ps[i], ps[j] = ps[j], ps[i] 44 | } 45 | 46 | func (ps ProxyList) Deduplication() ProxyList { 47 | result := make(ProxyList, 0, len(ps)) 48 | temp := map[string]struct{}{} 49 | for _, item := range ps { 50 | if item != nil { 51 | if _, ok := temp[item.Identifier()]; !ok { 52 | temp[item.Identifier()] = struct{}{} 53 | result = append(result, item) 54 | } 55 | } 56 | } 57 | return result 58 | } 59 | 60 | func (ps ProxyList) Sort() ProxyList { 61 | sort.Sort(ps) 62 | return ps 63 | } 64 | 65 | func (ps ProxyList) NameSetCounrty() ProxyList { 66 | num := len(ps) 67 | for i := 0; i < num; i++ { 68 | ps[i].SetName(ps[i].BaseInfo().Country) 69 | } 70 | return ps 71 | } 72 | 73 | func (ps ProxyList) NameAddIndex() ProxyList { 74 | num := len(ps) 75 | for i := 0; i < num; i++ { 76 | ps[i].SetName(fmt.Sprintf("%s_%+02v", ps[i].BaseInfo().Name, i+1)) 77 | } 78 | return ps 79 | } 80 | 81 | func (ps ProxyList) NameReIndex() ProxyList { 82 | num := len(ps) 83 | for i := 0; i < num; i++ { 84 | originName := ps[i].BaseInfo().Name 85 | country := strings.SplitN(originName, "_", 2)[0] 86 | ps[i].SetName(fmt.Sprintf("%s_%+02v", country, i+1)) 87 | } 88 | return ps 89 | } 90 | 91 | func (ps ProxyList) NameAddTG() ProxyList { 92 | num := len(ps) 93 | for i := 0; i < num; i++ { 94 | ps[i].SetName(fmt.Sprintf("%s %s", ps[i].BaseInfo().Name, "TG@doudoubinggo")) 95 | } 96 | return ps 97 | } 98 | 99 | func (ps ProxyList) Clone() ProxyList { 100 | result := make(ProxyList, 0, len(ps)) 101 | for _, pp := range ps { 102 | if pp != nil { 103 | result = append(result, pp.Clone()) 104 | } 105 | } 106 | return result 107 | } 108 | 109 | // Derive 将原有节点中的ss和ssr互相转换进行衍生 110 | func (ps ProxyList) Derive() ProxyList { 111 | proxies := ps 112 | for _, p := range ps { 113 | if p == nil { 114 | continue 115 | } 116 | if p.TypeName() == "ss" { 117 | ssr, err := Convert2SSR(p) 118 | if err == nil { 119 | proxies = append(proxies, ssr) 120 | } 121 | } else if p.TypeName() == "ssr" { 122 | ss, err := Convert2SS(p) 123 | if err == nil { 124 | proxies = append(proxies, ss) 125 | } 126 | } 127 | } 128 | return proxies.Deduplication() 129 | } 130 | -------------------------------------------------------------------------------- /pkg/proxy/shadowsocks.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "math/rand" 8 | "net" 9 | "net/url" 10 | "regexp" 11 | "strconv" 12 | "strings" 13 | 14 | "github.com/doudoubinga/proxypool/pkg/tool" 15 | ) 16 | 17 | var ( 18 | ErrorNotSSLink = errors.New("not a correct ss link") 19 | ) 20 | 21 | type Shadowsocks struct { 22 | Base 23 | Password string `yaml:"password" json:"password"` 24 | Cipher string `yaml:"cipher" json:"cipher"` 25 | Plugin string `yaml:"plugin,omitempty" json:"plugin,omitempty"` 26 | PluginOpts map[string]interface{} `yaml:"plugin-opts,omitempty" json:"plugin-opts,omitempty"` 27 | } 28 | 29 | func (ss Shadowsocks) Identifier() string { 30 | return net.JoinHostPort(ss.Server, strconv.Itoa(ss.Port)) + ss.Password 31 | } 32 | 33 | func (ss Shadowsocks) String() string { 34 | data, err := json.Marshal(ss) 35 | if err != nil { 36 | return "" 37 | } 38 | return string(data) 39 | } 40 | 41 | func (ss Shadowsocks) ToClash() string { 42 | data, err := json.Marshal(ss) 43 | if err != nil { 44 | return "" 45 | } 46 | return "- " + string(data) 47 | } 48 | 49 | func (ss Shadowsocks) ToSurge() string { 50 | // node1 = ss, server, port, encrypt-method=, password=, obfs=, obfs-host=, udp-relay=false 51 | if ss.Plugin == "obfs" { 52 | text := fmt.Sprintf("%s = ss, %s, %d, encrypt-method=%s, password=%s, obfs=%s, udp-relay=false", 53 | ss.Name, ss.Server, ss.Port, ss.Cipher, ss.Password, ss.PluginOpts["mode"]) 54 | if ss.PluginOpts["host"].(string) != "" { 55 | text += ", obfs-host=" + ss.PluginOpts["host"].(string) 56 | } 57 | return text 58 | } else { 59 | return fmt.Sprintf("%s = ss, %s, %d, encrypt-method=%s, password=%s, udp-relay=false", 60 | ss.Name, ss.Server, ss.Port, ss.Cipher, ss.Password) 61 | } 62 | } 63 | 64 | func (ss Shadowsocks) Clone() Proxy { 65 | return &ss 66 | } 67 | 68 | // https://shadowsocks.org/en/config/quick-guide.html 69 | func (ss Shadowsocks) Link() (link string) { 70 | payload := fmt.Sprintf("%s:%s@%s:%d", ss.Cipher, ss.Password, ss.Server, ss.Port) 71 | payload = tool.Base64EncodeString(payload, false) 72 | return fmt.Sprintf("ss://%s#%s", payload, ss.Name) 73 | } 74 | 75 | func ParseSSLink(link string) (*Shadowsocks, error) { 76 | if !strings.HasPrefix(link, "ss://") { 77 | return nil, ErrorNotSSRLink 78 | } 79 | 80 | uri, err := url.Parse(link) 81 | if err != nil { 82 | return nil, ErrorNotSSLink 83 | } 84 | 85 | cipher := "" 86 | password := "" 87 | if uri.User.String() == "" { 88 | // base64的情况 89 | infos, err := tool.Base64DecodeString(uri.Hostname()) 90 | if err != nil { 91 | return nil, err 92 | } 93 | uri, err = url.Parse("ss://" + infos) 94 | if err != nil { 95 | return nil, err 96 | } 97 | cipher = uri.User.Username() 98 | password, _ = uri.User.Password() 99 | } else { 100 | cipherInfoString, err := tool.Base64DecodeString(uri.User.Username()) 101 | if err != nil { 102 | return nil, ErrorPasswordParseFail 103 | } 104 | cipherInfo := strings.SplitN(cipherInfoString, ":", 2) 105 | if len(cipherInfo) < 2 { 106 | return nil, ErrorPasswordParseFail 107 | } 108 | cipher = strings.ToLower(cipherInfo[0]) 109 | password = cipherInfo[1] 110 | } 111 | server := uri.Hostname() 112 | port, _ := strconv.Atoi(uri.Port()) 113 | 114 | moreInfos := uri.Query() 115 | pluginString := moreInfos.Get("plugin") 116 | plugin := "" 117 | pluginOpts := make(map[string]interface{}) 118 | if strings.Contains(pluginString, ";") { 119 | pluginInfos, err := url.ParseQuery(pluginString) 120 | if err == nil { 121 | if strings.Contains(pluginString, "obfs") { 122 | plugin = "obfs" 123 | pluginOpts["mode"] = pluginInfos.Get("obfs") 124 | pluginOpts["host"] = pluginInfos.Get("obfs-host") 125 | } else if strings.Contains(pluginString, "v2ray") { 126 | plugin = "v2ray-plugin" 127 | pluginOpts["mode"] = pluginInfos.Get("mode") 128 | pluginOpts["host"] = pluginInfos.Get("host") 129 | pluginOpts["tls"] = strings.Contains(pluginString, "tls") 130 | } 131 | } 132 | } 133 | if port == 0 || cipher == "" { 134 | return nil, ErrorNotSSLink 135 | } 136 | 137 | return &Shadowsocks{ 138 | Base: Base{ 139 | Name: strconv.Itoa(rand.Int()), 140 | Server: server, 141 | Port: port, 142 | Type: "ss", 143 | }, 144 | Password: password, 145 | Cipher: cipher, 146 | Plugin: plugin, 147 | PluginOpts: pluginOpts, 148 | }, nil 149 | } 150 | 151 | var ( 152 | ssPlainRe = regexp.MustCompile("ss://([A-Za-z0-9+/_&?=@:%.-])+") 153 | ) 154 | 155 | func GrepSSLinkFromString(text string) []string { 156 | results := make([]string, 0) 157 | texts := strings.Split(text, "ss://") 158 | for _, text := range texts { 159 | results = append(results, ssPlainRe.FindAllString("ss://"+text, -1)...) 160 | } 161 | return results 162 | } 163 | -------------------------------------------------------------------------------- /pkg/proxy/shadowsocksr.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "math/rand" 8 | "net" 9 | "net/url" 10 | "regexp" 11 | "strconv" 12 | "strings" 13 | 14 | "github.com/doudoubinga/proxypool/pkg/tool" 15 | ) 16 | 17 | var ( 18 | ErrorNotSSRLink = errors.New("not a correct ssr link") 19 | ErrorPasswordParseFail = errors.New("password parse failed") 20 | ErrorPathNotComplete = errors.New("path not complete") 21 | ErrorMissingQuery = errors.New("link missing query") 22 | ErrorProtocolParamParseFail = errors.New("protocol param parse failed") 23 | ErrorObfsParamParseFail = errors.New("obfs param parse failed") 24 | ) 25 | 26 | type ShadowsocksR struct { 27 | Base 28 | Password string `yaml:"password" json:"password"` 29 | Cipher string `yaml:"cipher" json:"cipher"` 30 | Protocol string `yaml:"protocol" json:"protocol"` 31 | ProtocolParam string `yaml:"protocol-param,omitempty" json:"protocol_param,omitempty"` 32 | Obfs string `yaml:"obfs" json:"obfs"` 33 | ObfsParam string `yaml:"obfs-param,omitempty" json:"obfs_param,omitempty"` 34 | Group string `yaml:"group,omitempty" json:"group,omitempty"` 35 | } 36 | 37 | func (ssr ShadowsocksR) Identifier() string { 38 | return net.JoinHostPort(ssr.Server, strconv.Itoa(ssr.Port)) + ssr.Password + ssr.ProtocolParam 39 | } 40 | 41 | func (ssr ShadowsocksR) String() string { 42 | data, err := json.Marshal(ssr) 43 | if err != nil { 44 | return "" 45 | } 46 | return string(data) 47 | } 48 | 49 | func (ssr ShadowsocksR) ToClash() string { 50 | data, err := json.Marshal(ssr) 51 | if err != nil { 52 | return "" 53 | } 54 | return "- " + string(data) 55 | } 56 | 57 | func (ssr ShadowsocksR) ToSurge() string { 58 | return "" 59 | } 60 | 61 | func (ssr ShadowsocksR) Clone() Proxy { 62 | return &ssr 63 | } 64 | 65 | // https://github.com/HMBSbige/ShadowsocksR-Windows/wiki/SSR-QRcode-scheme 66 | func (ssr ShadowsocksR) Link() (link string) { 67 | payload := fmt.Sprintf("%s:%d:%s:%s:%s:%s", 68 | ssr.Server, ssr.Port, ssr.Protocol, ssr.Cipher, ssr.Obfs, tool.Base64EncodeString(ssr.Password, true)) 69 | query := url.Values{} 70 | query.Add("obfsparam", tool.Base64EncodeString(ssr.ObfsParam, true)) 71 | query.Add("protoparam", tool.Base64EncodeString(ssr.ProtocolParam, true)) 72 | query.Add("remarks", tool.Base64EncodeString(ssr.Name, true)) 73 | query.Add("group", tool.Base64EncodeString("proxy.tgbot.co", true)) 74 | payload = tool.Base64EncodeString(fmt.Sprintf("%s/?%s", payload, query.Encode()), true) 75 | return fmt.Sprintf("ssr://%s", payload) 76 | } 77 | 78 | func ParseSSRLink(link string) (*ShadowsocksR, error) { 79 | if !strings.HasPrefix(link, "ssr") { 80 | return nil, ErrorNotSSRLink 81 | } 82 | 83 | ssrmix := strings.SplitN(link, "://", 2) 84 | if len(ssrmix) < 2 { 85 | return nil, ErrorNotSSRLink 86 | } 87 | linkPayloadBase64 := ssrmix[1] 88 | payload, err := tool.Base64DecodeString(linkPayloadBase64) 89 | if err != nil { 90 | return nil, ErrorMissingQuery 91 | } 92 | 93 | infoPayload := strings.SplitN(payload, "/?", 2) 94 | if len(infoPayload) < 2 { 95 | return nil, ErrorNotSSRLink 96 | } 97 | ssrpath := strings.Split(infoPayload[0], ":") 98 | if len(ssrpath) < 6 { 99 | return nil, ErrorPathNotComplete 100 | } 101 | // base info 102 | server := strings.ToLower(ssrpath[0]) 103 | port, _ := strconv.Atoi(ssrpath[1]) 104 | protocol := strings.ToLower(ssrpath[2]) 105 | cipher := strings.ToLower(ssrpath[3]) 106 | obfs := strings.ToLower(ssrpath[4]) 107 | password, err := tool.Base64DecodeString(ssrpath[5]) 108 | if err != nil { 109 | return nil, ErrorPasswordParseFail 110 | } 111 | 112 | moreInfo, _ := url.ParseQuery(infoPayload[1]) 113 | 114 | // remarks 115 | remarks := moreInfo.Get("remarks") 116 | remarks, err = tool.Base64DecodeString(remarks) 117 | if err != nil { 118 | remarks = "" 119 | err = nil 120 | } 121 | if strings.ContainsAny(remarks, "\t\r\n ") { 122 | remarks = strings.ReplaceAll(remarks, "\t", "") 123 | remarks = strings.ReplaceAll(remarks, "\r", "") 124 | remarks = strings.ReplaceAll(remarks, "\n", "") 125 | remarks = strings.ReplaceAll(remarks, " ", "") 126 | } 127 | 128 | // protocol param 129 | protocolParam, err := tool.Base64DecodeString(moreInfo.Get("protoparam")) 130 | if err != nil { 131 | return nil, ErrorProtocolParamParseFail 132 | } 133 | if tool.ContainChineseChar(protocolParam) { 134 | protocolParam = "" 135 | } 136 | if strings.HasSuffix(protocol, "_compatible") { 137 | protocol = strings.ReplaceAll(protocol, "_compatible", "") 138 | } 139 | 140 | // obfs param 141 | obfsParam, err := tool.Base64DecodeString(moreInfo.Get("obfsparam")) 142 | if err != nil { 143 | return nil, ErrorObfsParamParseFail 144 | } 145 | if tool.ContainChineseChar(obfsParam) { 146 | obfsParam = "" 147 | } 148 | if strings.HasSuffix(obfs, "_compatible") { 149 | obfs = strings.ReplaceAll(obfs, "_compatible", "") 150 | } 151 | 152 | //group, err := tool.Base64DecodeString(moreInfo.Get("group")) 153 | //if err != nil { 154 | // group = "" 155 | //} 156 | group := "" 157 | 158 | return &ShadowsocksR{ 159 | Base: Base{ 160 | Name: remarks + "_" + strconv.Itoa(rand.Int()), 161 | Server: server, 162 | Port: port, 163 | Type: "ssr", 164 | }, 165 | Password: password, 166 | Cipher: cipher, 167 | Protocol: protocol, 168 | ProtocolParam: protocolParam, 169 | Obfs: obfs, 170 | ObfsParam: obfsParam, 171 | Group: group, 172 | }, nil 173 | } 174 | 175 | var ( 176 | ssrPlainRe = regexp.MustCompile("ssr://([A-Za-z0-9+/_-])+") 177 | ) 178 | 179 | func GrepSSRLinkFromString(text string) []string { 180 | results := make([]string, 0) 181 | texts := strings.Split(text, "ssr://") 182 | for _, text := range texts { 183 | results = append(results, ssrPlainRe.FindAllString("ssr://"+text, -1)...) 184 | } 185 | return results 186 | } 187 | -------------------------------------------------------------------------------- /pkg/proxy/trojan.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "math/rand" 7 | "net" 8 | "net/url" 9 | "regexp" 10 | "strconv" 11 | "strings" 12 | ) 13 | 14 | var ( 15 | ErrorNotTrojanink = errors.New("not a correct trojan link") 16 | ) 17 | 18 | type Trojan struct { 19 | Base 20 | Password string `yaml:"password" json:"password"` 21 | ALPN []string `yaml:"alpn,omitempty" json:"alpn,omitempty"` 22 | SNI string `yaml:"sni,omitempty" json:"sni,omitempty"` 23 | SkipCertVerify bool `yaml:"skip-cert-verify,omitempty" json:"skip-cert-verify,omitempty"` 24 | UDP bool `yaml:"udp,omitempty" json:"udp,omitempty"` 25 | } 26 | 27 | /** 28 | - name: "trojan" 29 | type: trojan 30 | server: server 31 | port: 443 32 | password: yourpsk 33 | # udp: true 34 | # sni: example.com # aka server name 35 | # alpn: 36 | # - h2 37 | # - http/1.1 38 | # skip-cert-verify: true 39 | */ 40 | 41 | func (t Trojan) Identifier() string { 42 | return net.JoinHostPort(t.Server, strconv.Itoa(t.Port)) + t.Password 43 | } 44 | 45 | func (t Trojan) String() string { 46 | data, err := json.Marshal(t) 47 | if err != nil { 48 | return "" 49 | } 50 | return string(data) 51 | } 52 | 53 | func (t Trojan) ToClash() string { 54 | data, err := json.Marshal(t) 55 | if err != nil { 56 | return "" 57 | } 58 | return "- " + string(data) 59 | } 60 | 61 | func (t Trojan) ToSurge() string { 62 | return "" 63 | } 64 | 65 | func (t Trojan) Clone() Proxy { 66 | return &t 67 | } 68 | 69 | // https://p4gefau1t.github.io/trojan-go/developer/url/ 70 | func (t Trojan) Link() (link string) { 71 | query := url.Values{} 72 | if t.SNI != "" { 73 | query.Set("sni", url.QueryEscape(t.SNI)) 74 | } 75 | 76 | uri := url.URL{ 77 | Scheme: "trojan", 78 | User: url.User(url.QueryEscape(t.Password)), 79 | Host: net.JoinHostPort(t.Server, strconv.Itoa(t.Port)), 80 | RawQuery: query.Encode(), 81 | Fragment: t.Name, 82 | } 83 | 84 | return uri.String() 85 | } 86 | 87 | func ParseTrojanLink(link string) (*Trojan, error) { 88 | if !strings.HasPrefix(link, "trojan://") && !strings.HasPrefix(link, "trojan-go://") { 89 | return nil, ErrorNotTrojanink 90 | } 91 | 92 | /** 93 | trojan-go:// 94 | $(trojan-password) 95 | @ 96 | trojan-host 97 | : 98 | port 99 | /? 100 | sni=$(tls-sni.com)& 101 | type=$(original|ws|h2|h2+ws)& 102 | host=$(websocket-host.com)& 103 | path=$(/websocket/path)& 104 | encryption=$(ss;aes-256-gcm;ss-password)& 105 | plugin=$(...) 106 | #$(descriptive-text) 107 | */ 108 | 109 | uri, err := url.Parse(link) 110 | if err != nil { 111 | return nil, ErrorNotSSLink 112 | } 113 | 114 | password := uri.User.Username() 115 | password, _ = url.QueryUnescape(password) 116 | 117 | server := uri.Hostname() 118 | port, _ := strconv.Atoi(uri.Port()) 119 | 120 | moreInfos := uri.Query() 121 | sni := moreInfos.Get("sni") 122 | sni, _ = url.QueryUnescape(sni) 123 | transformType := moreInfos.Get("type") 124 | transformType, _ = url.QueryUnescape(transformType) 125 | host := moreInfos.Get("host") 126 | host, _ = url.QueryUnescape(host) 127 | path := moreInfos.Get("path") 128 | path, _ = url.QueryUnescape(path) 129 | 130 | alpn := make([]string, 0) 131 | if transformType == "h2" { 132 | alpn = append(alpn, "h2") 133 | } 134 | 135 | if port == 0 { 136 | return nil, ErrorNotTrojanink 137 | } 138 | 139 | return &Trojan{ 140 | Base: Base{ 141 | Name: strconv.Itoa(rand.Int()), 142 | Server: server, 143 | Port: port, 144 | Type: "trojan", 145 | }, 146 | Password: password, 147 | ALPN: alpn, 148 | UDP: true, 149 | SNI: host, 150 | SkipCertVerify: true, 151 | }, nil 152 | } 153 | 154 | var ( 155 | trojanPlainRe = regexp.MustCompile("trojan(-go)?://([A-Za-z0-9+/_&?=@:%.-])+") 156 | ) 157 | 158 | func GrepTrojanLinkFromString(text string) []string { 159 | results := make([]string, 0) 160 | texts := strings.Split(text, "trojan://") 161 | for _, text := range texts { 162 | results = append(results, trojanPlainRe.FindAllString("trojan://"+text, -1)...) 163 | } 164 | return results 165 | } 166 | -------------------------------------------------------------------------------- /pkg/proxy/vmess.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "math/rand" 8 | "net" 9 | "net/url" 10 | "regexp" 11 | "strconv" 12 | "strings" 13 | 14 | "github.com/doudoubinga/proxypool/pkg/tool" 15 | ) 16 | 17 | var ( 18 | ErrorNotVmessLink = errors.New("not a correct vmess link") 19 | ErrorVmessPayloadParseFail = errors.New("vmess link payload parse failed") 20 | ) 21 | 22 | type Vmess struct { 23 | Base 24 | UUID string `yaml:"uuid" json:"uuid"` 25 | AlterID int `yaml:"alterId" json:"alterId"` 26 | Cipher string `yaml:"cipher" json:"cipher"` 27 | TLS bool `yaml:"tls,omitempty" json:"tls,omitempty"` 28 | Network string `yaml:"network,omitempty" json:"network,omitempty"` 29 | HTTPOpts HTTPOptions `yaml:"http-opts,omitempty" json:"http-opts,omitempty"` 30 | WSPath string `yaml:"ws-path,omitempty" json:"ws-path,omitempty"` 31 | WSHeaders map[string]string `yaml:"ws-headers,omitempty" json:"ws-headers,omitempty"` 32 | SkipCertVerify bool `yaml:"skip-cert-verify,omitempty" json:"skip-cert-verify,omitempty"` 33 | ServerName string `yaml:"servername,omitempty" json:"servername,omitempty"` 34 | } 35 | 36 | type HTTPOptions struct { 37 | Method string `yaml:"method,omitempty" json:"method,omitempty"` 38 | Path []string `yaml:"path,omitempty" json:"path,omitempty"` 39 | Headers map[string][]string `yaml:"headers,omitempty" json:"headers,omitempty"` 40 | } 41 | 42 | func (v Vmess) Identifier() string { 43 | return net.JoinHostPort(v.Server, strconv.Itoa(v.Port)) + v.Cipher + v.UUID 44 | } 45 | 46 | func (v Vmess) String() string { 47 | data, err := json.Marshal(v) 48 | if err != nil { 49 | return "" 50 | } 51 | return string(data) 52 | } 53 | 54 | func (v Vmess) ToClash() string { 55 | data, err := json.Marshal(v) 56 | if err != nil { 57 | return "" 58 | } 59 | return "- " + string(data) 60 | } 61 | 62 | func (v Vmess) ToSurge() string { 63 | // node2 = vmess, server, port, username=, ws=true, ws-path=, ws-headers= 64 | if v.Network == "ws" { 65 | wsHeasers := "" 66 | for k, v := range v.WSHeaders { 67 | if wsHeasers == "" { 68 | wsHeasers = k + ":" + v 69 | } else { 70 | wsHeasers += "|" + k + ":" + v 71 | } 72 | } 73 | text := fmt.Sprintf("%s = vmess, %s, %d, username=%s, ws=true, tls=%t, ws-path=%s", 74 | v.Name, v.Server, v.Port, v.UUID, v.TLS, v.WSPath) 75 | if wsHeasers != "" { 76 | text += ", ws-headers=" + wsHeasers 77 | } 78 | return text 79 | } else { 80 | return fmt.Sprintf("%s = vmess, %s, %d, username=%s, tls=%t", 81 | v.Name, v.Server, v.Port, v.UUID, v.TLS) 82 | } 83 | } 84 | 85 | func (v Vmess) Clone() Proxy { 86 | return &v 87 | } 88 | 89 | func (v Vmess) Link() (link string) { 90 | vjv, err := json.Marshal(v.toLinkJson()) 91 | if err != nil { 92 | return 93 | } 94 | return fmt.Sprintf("vmess://%s", tool.Base64EncodeBytes(vjv)) 95 | } 96 | 97 | type vmessLinkJson struct { 98 | Add string `json:"add"` 99 | V string `json:"v"` 100 | Ps string `json:"ps"` 101 | Port interface{} `json:"port"` 102 | Id string `json:"id"` 103 | Aid string `json:"aid"` 104 | Net string `json:"net"` 105 | Type string `json:"type"` 106 | Host string `json:"host"` 107 | Path string `json:"path"` 108 | Tls string `json:"tls"` 109 | } 110 | 111 | func (v Vmess) toLinkJson() vmessLinkJson { 112 | vj := vmessLinkJson{ 113 | Add: v.Server, 114 | Ps: v.Name, 115 | Port: v.Port, 116 | Id: v.UUID, 117 | Aid: strconv.Itoa(v.AlterID), 118 | Net: v.Network, 119 | Path: v.WSPath, 120 | Host: v.ServerName, 121 | V: "2", 122 | } 123 | if v.TLS { 124 | vj.Tls = "tls" 125 | } 126 | if host, ok := v.WSHeaders["HOST"]; ok && host != "" { 127 | vj.Host = host 128 | } 129 | return vj 130 | } 131 | 132 | func ParseVmessLink(link string) (*Vmess, error) { 133 | if !strings.HasPrefix(link, "vmess") { 134 | return nil, ErrorNotVmessLink 135 | } 136 | 137 | vmessmix := strings.SplitN(link, "://", 2) 138 | if len(vmessmix) < 2 { 139 | return nil, ErrorNotVmessLink 140 | } 141 | linkPayload := vmessmix[1] 142 | if strings.Contains(linkPayload, "?") { 143 | // 使用第二种解析方法 144 | var infoPayloads []string 145 | if strings.Contains(linkPayload, "/?") { 146 | infoPayloads = strings.SplitN(linkPayload, "/?", 2) 147 | } else { 148 | infoPayloads = strings.SplitN(linkPayload, "?", 2) 149 | } 150 | if len(infoPayloads) < 2 { 151 | return nil, ErrorNotVmessLink 152 | } 153 | 154 | baseInfo, err := tool.Base64DecodeString(infoPayloads[0]) 155 | if err != nil { 156 | return nil, ErrorVmessPayloadParseFail 157 | } 158 | baseInfoPath := strings.Split(baseInfo, ":") 159 | if len(baseInfoPath) < 3 { 160 | return nil, ErrorPathNotComplete 161 | } 162 | // base info 163 | cipher := baseInfoPath[0] 164 | mixInfo := strings.SplitN(baseInfoPath[1], "@", 2) 165 | if len(mixInfo) < 2 { 166 | return nil, ErrorVmessPayloadParseFail 167 | } 168 | uuid := mixInfo[0] 169 | server := mixInfo[1] 170 | portStr := baseInfoPath[2] 171 | port, err := strconv.Atoi(portStr) 172 | if err != nil { 173 | return nil, ErrorVmessPayloadParseFail 174 | } 175 | 176 | moreInfo, _ := url.ParseQuery(infoPayloads[1]) 177 | remarks := moreInfo.Get("remarks") 178 | obfs := moreInfo.Get("obfs") 179 | network := "tcp" 180 | if obfs == "websocket" { 181 | network = "ws" 182 | } 183 | //obfsParam := moreInfo.Get("obfsParam") 184 | path := moreInfo.Get("path") 185 | if path == "" { 186 | path = "/" 187 | } 188 | tls := moreInfo.Get("tls") == "1" 189 | 190 | wsHeaders := make(map[string]string) 191 | return &Vmess{ 192 | Base: Base{ 193 | Name: remarks + "_" + strconv.Itoa(rand.Int()), 194 | Server: server, 195 | Port: port, 196 | Type: "vmess", 197 | UDP: false, 198 | }, 199 | UUID: uuid, 200 | AlterID: 0, 201 | Cipher: cipher, 202 | TLS: tls, 203 | Network: network, 204 | HTTPOpts: HTTPOptions{}, 205 | WSPath: path, 206 | WSHeaders: wsHeaders, 207 | SkipCertVerify: true, 208 | ServerName: server, 209 | }, nil 210 | } else { 211 | payload, err := tool.Base64DecodeString(linkPayload) 212 | if err != nil { 213 | return nil, ErrorVmessPayloadParseFail 214 | } 215 | vmessJson := vmessLinkJson{} 216 | err = json.Unmarshal([]byte(payload), &vmessJson) 217 | if err != nil { 218 | return nil, err 219 | } 220 | port := 443 221 | portInterface := vmessJson.Port 222 | switch portInterface.(type) { 223 | case int: 224 | port = portInterface.(int) 225 | case string: 226 | port, _ = strconv.Atoi(portInterface.(string)) 227 | } 228 | 229 | alterId, err := strconv.Atoi(vmessJson.Aid) 230 | if err != nil { 231 | alterId = 0 232 | } 233 | tls := vmessJson.Tls == "tls" 234 | 235 | wsHeaders := make(map[string]string) 236 | if vmessJson.Host != "" { 237 | wsHeaders["HOST"] = vmessJson.Host 238 | } 239 | 240 | if vmessJson.Path == "" { 241 | vmessJson.Path = "/" 242 | } 243 | return &Vmess{ 244 | Base: Base{ 245 | Name: vmessJson.Ps + "_" + strconv.Itoa(rand.Int()), 246 | Server: vmessJson.Add, 247 | Port: port, 248 | Type: "vmess", 249 | UDP: false, 250 | }, 251 | UUID: vmessJson.Id, 252 | AlterID: alterId, 253 | Cipher: "auto", 254 | TLS: tls, 255 | Network: vmessJson.Net, 256 | HTTPOpts: HTTPOptions{}, 257 | WSPath: vmessJson.Path, 258 | WSHeaders: wsHeaders, 259 | SkipCertVerify: true, 260 | ServerName: vmessJson.Host, 261 | }, nil 262 | } 263 | } 264 | 265 | var ( 266 | vmessPlainRe = regexp.MustCompile("vmess://([A-Za-z0-9+/_?&=-])+") 267 | ) 268 | 269 | func GrepVmessLinkFromString(text string) []string { 270 | results := make([]string, 0) 271 | texts := strings.Split(text, "vmess://") 272 | for _, text := range texts { 273 | results = append(results, vmessPlainRe.FindAllString("vmess://"+text, -1)...) 274 | } 275 | return results 276 | } 277 | -------------------------------------------------------------------------------- /pkg/tool/base64.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "encoding/base64" 5 | ) 6 | 7 | func Base64DecodeString(src string) (dst string, err error) { 8 | if src == "" { 9 | return "", nil 10 | } 11 | var dstbytes []byte 12 | dstbytes, err = base64.RawURLEncoding.DecodeString(src) 13 | 14 | if err != nil { 15 | dstbytes, err = base64.RawStdEncoding.DecodeString(src) 16 | } 17 | if err != nil { 18 | dstbytes, err = base64.StdEncoding.DecodeString(src) 19 | } 20 | if err != nil { 21 | dstbytes, err = base64.URLEncoding.DecodeString(src) 22 | } 23 | if err != nil { 24 | return "", err 25 | } 26 | dst = string(dstbytes) 27 | return 28 | } 29 | 30 | func Base64EncodeString(origin string, urlsafe bool) (result string) { 31 | if urlsafe { 32 | return base64.URLEncoding.EncodeToString([]byte(origin)) 33 | } 34 | return base64.StdEncoding.EncodeToString([]byte(origin)) 35 | } 36 | 37 | func Base64EncodeBytes(origin []byte) (result string) { 38 | return base64.StdEncoding.EncodeToString([]byte(origin)) 39 | } 40 | -------------------------------------------------------------------------------- /pkg/tool/check.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | func CheckInList(list []string, item string) bool { 4 | for _, i := range list { 5 | if item == i { 6 | return true 7 | } 8 | } 9 | return false 10 | } 11 | -------------------------------------------------------------------------------- /pkg/tool/colly.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "time" 7 | 8 | "github.com/gocolly/colly" 9 | ) 10 | 11 | func GetColly() *colly.Collector { 12 | c := colly.NewCollector( 13 | colly.UserAgent(UserAgent), 14 | ) 15 | c.WithTransport(&http.Transport{ 16 | Proxy: http.ProxyFromEnvironment, 17 | DialContext: (&net.Dialer{ 18 | Timeout: 10 * time.Second, // 超时时间 19 | KeepAlive: 10 * time.Second, // keepAlive 超时时间 20 | }).DialContext, 21 | MaxIdleConns: 100, // 最大空闲连接数 22 | IdleConnTimeout: 20 * time.Second, // 空闲连接超时 23 | TLSHandshakeTimeout: 10 * time.Second, // TLS 握手超时 24 | ExpectContinueTimeout: 10 * time.Second, 25 | }) 26 | return c 27 | } 28 | -------------------------------------------------------------------------------- /pkg/tool/httpclient.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36" 10 | 11 | type HttpClient struct { 12 | *http.Client 13 | } 14 | 15 | var httpClient *HttpClient 16 | 17 | func init() { 18 | httpClient = &HttpClient{http.DefaultClient} 19 | httpClient.Timeout = time.Second * 10 20 | } 21 | 22 | func GetHttpClient() *HttpClient { 23 | c := *httpClient 24 | return &c 25 | } 26 | 27 | func (c *HttpClient) Get(url string) (resp *http.Response, err error) { 28 | req, err := http.NewRequest(http.MethodGet, url, nil) 29 | if err != nil { 30 | return nil, err 31 | } 32 | req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8") 33 | req.Header.Set("User-Agent", UserAgent) 34 | return c.Do(req) 35 | } 36 | 37 | func (c *HttpClient) Post(url string, body io.Reader) (resp *http.Response, err error) { 38 | req, err := http.NewRequest(http.MethodPost, url, body) 39 | if err != nil { 40 | return nil, err 41 | } 42 | req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8") 43 | req.Header.Set("User-Agent", UserAgent) 44 | return c.Do(req) 45 | } 46 | -------------------------------------------------------------------------------- /pkg/tool/option.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | type Options map[string]interface{} 4 | -------------------------------------------------------------------------------- /pkg/tool/unicode.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "regexp" 5 | "unicode" 6 | ) 7 | 8 | var hanRe = regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]") 9 | 10 | func ContainChineseChar(str string) bool { 11 | for _, r := range str { 12 | if unicode.Is(unicode.Scripts["Han"], r) || (hanRe.MatchString(string(r))) { 13 | return true 14 | } 15 | } 16 | return false 17 | } 18 | --------------------------------------------------------------------------------