├── .github └── workflows │ └── build.yml ├── LICENSE ├── README.md ├── aws ├── aga.go ├── aws.go ├── ec2.go ├── lightsail.go ├── quota.go └── wavelength.go ├── build.sh ├── cache └── cache.go ├── conf ├── conf.go └── conf_test.go ├── controller ├── aga.go ├── config.go ├── controller.go ├── ec2.go ├── error.go ├── lightsail.go ├── quota.go ├── secret.go ├── session.go └── user.go ├── data ├── data.go ├── secret.go └── user.go ├── example └── config.json ├── go.mod ├── go.sum ├── mail ├── mail.go └── mail_test.go ├── main.go ├── middleware ├── admin.go └── user.go ├── request ├── ec2.go ├── lightsail.go ├── secret.go └── user.go ├── router ├── route.go └── router.go ├── utils ├── doubleclick.go ├── doubleclick_win.go ├── file.go ├── password.go ├── password_test.go └── random.go └── web ├── .idea ├── .gitignore ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── web.iml ├── babel.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ ├── aws.png │ ├── jb_beam.svg │ └── logo.png ├── components │ └── lightsail.vue ├── main.js ├── plugins │ └── vuetify.js ├── router │ └── index.js ├── utils │ ├── api.js │ └── sleep.js └── views │ ├── Home.vue │ ├── Instance.vue │ ├── Login.vue │ ├── Manger.vue │ ├── Register.vue │ └── User.vue └── vue.config.js /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - main 8 | paths: 9 | - "**/*.go" 10 | - "go.mod" 11 | - "go.sum" 12 | - ".github/workflows/*.yml" 13 | pull_request: 14 | types: [ opened, synchronize, reopened ] 15 | paths: 16 | - "**/*.go" 17 | - "go.mod" 18 | - "go.sum" 19 | - ".github/workflows/*.yml" 20 | release: 21 | types: [ published ] 22 | 23 | jobs: 24 | build: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - uses: actions/checkout@v2 28 | - name: Use Node.js ${{ matrix.node-version }} 29 | uses: actions/setup-node@v2 30 | with: 31 | node-version: 17 32 | cache: 'npm' 33 | cache-dependency-path: 'web/package-lock.json' 34 | - name: Build web 35 | run: | 36 | export NODE_OPTIONS=--openssl-legacy-provider 37 | mkdir tmp/ 38 | cd web/ 39 | npm ci 40 | npm run build 41 | mv dist/ ../tmp/web 42 | cd .. 43 | - name: Build with xgo 44 | uses: crazy-max/ghaction-xgo@v1 45 | with: 46 | xgo_version: latest 47 | go_version: latest 48 | dest: build 49 | prefix: AWS-Panel 50 | targets: windows/386,windows/amd64,linux/386,linux/amd64 51 | v: true 52 | x: false 53 | race: false 54 | ldflags: -s -w --extldflags "-fpic" 55 | buildmode: default 56 | - name: Zip 57 | run: | 58 | mkdir output/ 59 | cd tmp/ 60 | for i in `ls ../build`; do mv ../build/$i ./; zip -r $i.zip *; mv $i.zip ../output/; rm -rf $i; done 61 | cd .. 62 | - name: Upload artifact 63 | uses: actions/upload-artifact@v2 64 | if: ${{ !github.head_ref }} 65 | with: 66 | name: AWS-Panel_ALL 67 | path: output/ 68 | - name: Upload binaries to release 69 | uses: svenstaro/upload-release-action@v2 70 | if: github.event_name == 'release' 71 | with: 72 | repo_token: ${{ secrets.GITHUB_TOKEN }} 73 | file: output/* 74 | tag: ${{ github.ref }} 75 | file_glob: true 76 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Aws-Panel 2 | [](https://t.me/YuzukiProjects) 3 | 4 | 一个可以管理AWS资源的Web面板 5 | 6 | [](https://www.gnu.org/licenses/gpl-3.0.html) 7 | 8 | 暂时未实现用户权限及用户管理,为避免风险,建议仅在本地使用 9 | 10 | # 已实现的功能 11 | 12 | - [x] 分用户多密钥 13 | - [x] EC2管理 14 | - [x] Lightsail管理 15 | - [ ] AGA管理 16 | - [ ] Wavelength管理 17 | - [ ] 配额相关操作 18 | - [x] 用户管理 19 | 20 | 21 | # TODO 22 | 23 | - 开机脚本 24 | - 显示实例创建时间 25 | - 自选实例类型 26 | - 自选系统镜像 27 | - 分离ssh密钥操作逻辑 28 | 29 | # 使用 30 | 31 | 从Releases里下载可执行文件并运行,然后访问http://127.0.0.1:8011 32 | 初始管理员帐号密码为admin admin123456 33 | 34 | # 构建 35 | 36 | ``` bash 37 | git clone https://github.com/Yuzuki616/AWS-Panel.git 38 | cd AWS-Panel 39 | bash build.sh 40 | ``` 41 | 42 | # Thanks 43 | 44 | - [Gin](https://github.com/gin-gonic/gin) 45 | - [Aws-Sdk-Go](https://github.com/aws/aws-sdk-go) 46 | - [Vue.js](https://vuejs.org/) 47 | - [Vuetify](https://vuetifyjs.com/) 48 | - [Axios](https://github.com/axios/axios) 49 | -------------------------------------------------------------------------------- /aws/aga.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/aws" 5 | aga "github.com/aws/aws-sdk-go/service/globalaccelerator" 6 | "time" 7 | ) 8 | 9 | type AgaInfo struct { 10 | Name *string 11 | Status *string 12 | Arn string 13 | Ip []*aga.IpSet 14 | Protocol *string 15 | Port []*aga.PortOverride 16 | } 17 | 18 | func (a *Aws) CreateAga(Name string, Region string, InstanceId string) (*AgaInfo, error) { 19 | svc := aga.New(a.Sess) 20 | IdempotencyToken := time.Unix(time.Now().Unix(), 0).Format("2006-01-02_15:04:05") 21 | createAccRt, createAccErr := svc.CreateAccelerator(&aga.CreateAcceleratorInput{ 22 | Name: aws.String(Name), 23 | Enabled: aws.Bool(false), 24 | IdempotencyToken: aws.String(IdempotencyToken), 25 | }) 26 | if createAccErr != nil { 27 | return nil, createAccErr 28 | } 29 | createLiRt, createLiErr := svc.CreateListener(&aga.CreateListenerInput{ 30 | AcceleratorArn: createAccRt.Accelerator.AcceleratorArn, 31 | PortRanges: []*aga.PortRange{ 32 | { 33 | FromPort: aws.Int64(1), 34 | ToPort: aws.Int64(65535), 35 | }, 36 | }, 37 | Protocol: aws.String("TCP"), 38 | }) 39 | if createLiErr != nil { 40 | return nil, createLiErr 41 | } 42 | createEndRt, createEndErr := svc.CreateEndpointGroup(&aga.CreateEndpointGroupInput{ 43 | EndpointGroupRegion: aws.String(Region), 44 | IdempotencyToken: aws.String(IdempotencyToken), 45 | ListenerArn: createLiRt.Listener.ListenerArn, 46 | HealthCheckPort: aws.Int64(22), 47 | EndpointConfigurations: []*aga.EndpointConfiguration{ 48 | { 49 | EndpointId: aws.String(InstanceId), 50 | }, 51 | }, 52 | }) 53 | if createEndErr != nil { 54 | return nil, createEndErr 55 | } 56 | return &AgaInfo{ 57 | Name: createAccRt.Accelerator.Name, 58 | Status: createAccRt.Accelerator.Status, 59 | Arn: *createAccRt.Accelerator.AcceleratorArn, 60 | Ip: createAccRt.Accelerator.IpSets, 61 | Protocol: createLiRt.Listener.Protocol, 62 | Port: createEndRt.EndpointGroup.PortOverrides, 63 | }, nil 64 | } 65 | 66 | func (a *Aws) ListAga() ([]*aga.Accelerator, error) { 67 | svc := aga.New(a.Sess) 68 | rt, err := svc.ListAccelerators(&aga.ListAcceleratorsInput{}) 69 | if err != nil { 70 | return nil, err 71 | } 72 | return rt.Accelerators, err 73 | } 74 | 75 | /* func (p *Aws) GetAgaInfo(AcceleratorArn string) (*AgaInfo, error) { 76 | svc := aga.New(p.Sess) 77 | accRt, accErr := svc.DescribeAccelerator(&aga.DescribeAcceleratorInput{AcceleratorArn: aws.String(AcceleratorArn)}) 78 | if accErr != nil { 79 | return nil, accErr 80 | } 81 | liRt, liErr := svc.ListListeners(&aga.ListListenersInput{AcceleratorArn: accRt.Accelerator.AcceleratorArn}) 82 | if liErr != nil { 83 | return nil, liErr 84 | } 85 | endRt, endErr := svc.ListEndpointGroups(&aga.ListEndpointGroupsInput{ListenerArn: liRt.Listeners[0].ListenerArn}) 86 | if endErr != nil { 87 | return nil, endErr 88 | } 89 | return &AgaInfo{ 90 | Username: accRt.Accelerator.Username, 91 | Status: accRt.Accelerator.Status, 92 | Arn: AcceleratorArn + "_" + 93 | *liRt.Listeners[0].ListenerArn + "_" + *endRt.EndpointGroups[0].EndpointGroupArn, 94 | Ip: accRt.Accelerator.IpSets, 95 | Protocol: liRt.Listeners[0].Protocol, 96 | Port: endRt.EndpointGroups[0].PortOverrides, 97 | }, nil 98 | }*/ 99 | 100 | func (a *Aws) DeleteAga(AcceleratorArn string) error { 101 | svc := aga.New(a.Sess) 102 | _, updateErr := svc.UpdateAccelerator(&aga.UpdateAcceleratorInput{ 103 | AcceleratorArn: aws.String(AcceleratorArn), 104 | Enabled: aws.Bool(false), 105 | }) 106 | if updateErr != nil { 107 | return updateErr 108 | } 109 | _, deleteErr := svc.DeleteAccelerator(&aga.DeleteAcceleratorInput{AcceleratorArn: aws.String(AcceleratorArn)}) 110 | if deleteErr != nil { 111 | return deleteErr 112 | } 113 | return nil 114 | } 115 | -------------------------------------------------------------------------------- /aws/aws.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "crypto/tls" 5 | "github.com/aws/aws-sdk-go/aws" 6 | "github.com/aws/aws-sdk-go/aws/credentials" 7 | "github.com/aws/aws-sdk-go/aws/session" 8 | "net/http" 9 | "net/url" 10 | ) 11 | 12 | type Aws struct { 13 | Sess *session.Session 14 | } 15 | 16 | func New(Region string, Id string, Secret string, Proxy string) (*Aws, error) { 17 | config := &aws.Config{ 18 | Region: aws.String(Region), 19 | Credentials: credentials.NewStaticCredentials(Id, Secret, ""), 20 | } 21 | if Proxy != "" { 22 | config.HTTPClient = &http.Client{ 23 | Transport: &http.Transport{ 24 | Proxy: func(*http.Request) (*url.URL, error) { 25 | return url.Parse(Proxy) 26 | }, 27 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 28 | }, 29 | } 30 | } 31 | sess, err := session.NewSession(config) 32 | if err != nil { 33 | return nil, err 34 | } 35 | c := &Aws{ 36 | Sess: sess, 37 | } 38 | return c, nil 39 | } 40 | -------------------------------------------------------------------------------- /aws/ec2.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "fmt" 5 | "github.com/aws/aws-sdk-go/aws" 6 | "github.com/aws/aws-sdk-go/service/ec2" 7 | "reflect" 8 | "time" 9 | ) 10 | 11 | type Ec2Info struct { 12 | Name string 13 | InstanceId string 14 | Status string 15 | Type string 16 | Ip string 17 | Key string 18 | } 19 | 20 | func (a *Aws) CreateEc2(Ami, Ec2Type, Name, userdata string, DiskSize int64) (*Ec2Info, error) { 21 | svc := ec2.New(a.Sess) 22 | dateName := Name + time.Unix(time.Now().Unix(), 0).Format("_2006-01-02_15:04:05") 23 | key, keyErr := a.CreateEc2SshKey(dateName + "_key") 24 | if keyErr != nil { 25 | return nil, fmt.Errorf("create key error: %v", keyErr) 26 | } //创建ssh密钥 27 | secRt, secErr := svc.CreateSecurityGroup(&ec2.CreateSecurityGroupInput{ 28 | GroupName: aws.String(dateName + "_security"), 29 | Description: aws.String("A security group for aws manger bot"), 30 | }) //创建安全组 31 | if secErr != nil { 32 | return nil, fmt.Errorf("create security group error: %v", secErr) 33 | } 34 | _, authSecInErr := svc.AuthorizeSecurityGroupIngress(&ec2.AuthorizeSecurityGroupIngressInput{ 35 | GroupId: secRt.GroupId, 36 | IpPermissions: []*ec2.IpPermission{ 37 | { 38 | IpProtocol: aws.String("-1"), 39 | IpRanges: []*ec2.IpRange{ 40 | { 41 | CidrIp: aws.String("0.0.0.0/0"), 42 | }, 43 | }, 44 | FromPort: aws.Int64(-1), 45 | ToPort: aws.Int64(-1), 46 | }, 47 | }, 48 | }) //添加入站规则 49 | if authSecInErr != nil { 50 | return nil, fmt.Errorf( 51 | "authorize security group ingress error: %v", authSecInErr) 52 | } 53 | ebs, ebsErr := a.getAmiEbsMap(Ami) 54 | if ebsErr != nil { 55 | return nil, ebsErr 56 | } 57 | ebs[0].Ebs.VolumeSize = &DiskSize 58 | runRt, runErr := svc.RunInstances(&ec2.RunInstancesInput{ 59 | ImageId: &Ami, 60 | InstanceType: &Ec2Type, 61 | MinCount: aws.Int64(1), 62 | MaxCount: aws.Int64(1), 63 | KeyName: &dateName, 64 | BlockDeviceMappings: ebs, 65 | SecurityGroupIds: []*string{secRt.GroupId}, 66 | UserData: &userdata, 67 | }) //创建ec2实例 68 | if runErr != nil { 69 | return nil, fmt.Errorf("run instances error: %v", runErr) 70 | } 71 | _, tagErr := svc.CreateTags(&ec2.CreateTagsInput{ 72 | Resources: []*string{runRt.Instances[0].InstanceId}, 73 | Tags: []*ec2.Tag{ 74 | { 75 | Key: aws.String("Name"), 76 | Value: &Name, 77 | }, 78 | }, 79 | }) //创建标签 80 | if tagErr != nil { 81 | return nil, fmt.Errorf("create tag error: %v", tagErr) 82 | } 83 | return &Ec2Info{ 84 | Name: Name, 85 | InstanceId: *runRt.Instances[0].InstanceId, 86 | Status: *runRt.Instances[0].State.Name, 87 | Key: key, 88 | }, nil 89 | } 90 | 91 | func (a *Aws) ChangeEc2Ip(InstanceId string) (*string, error) { 92 | svc := ec2.New(a.Sess) 93 | desRt, desErr := svc.DescribeAddresses(&ec2.DescribeAddressesInput{ 94 | Filters: []*ec2.Filter{ 95 | { 96 | Name: aws.String("instance-id"), 97 | Values: []*string{&InstanceId}, 98 | }, 99 | }, 100 | }) 101 | if desErr != nil { 102 | return nil, fmt.Errorf("describe addresses error: %v", desErr) 103 | } 104 | if len(desRt.Addresses) != 0 { 105 | _, relErr := svc.ReleaseAddress(&ec2.ReleaseAddressInput{AllocationId: desRt.Addresses[0].AllocationId}) 106 | if relErr != nil { 107 | return nil, fmt.Errorf("release ip error: %s", relErr) 108 | } 109 | } 110 | allRt, allErr := svc.AllocateAddress(&ec2.AllocateAddressInput{}) 111 | if allErr != nil { 112 | return nil, fmt.Errorf("allocate address error: %v", allErr) 113 | } 114 | _, assErr := svc.AssociateAddress(&ec2.AssociateAddressInput{ 115 | AllocationId: allRt.AllocationId, 116 | InstanceId: &InstanceId, 117 | }) 118 | if assErr != nil { 119 | return nil, fmt.Errorf("associate address error: %v", assErr) 120 | } 121 | return allRt.PublicIp, nil 122 | } 123 | 124 | func getNameFromTags(v []*ec2.Tag) string { 125 | if reflect.ValueOf(v).IsNil() { 126 | return "" 127 | } 128 | return *v[0].Value 129 | } 130 | 131 | func (a *Aws) GetEc2Info(InstanceId string) (*Ec2Info, error) { 132 | svc := ec2.New(a.Sess) 133 | rt, err := svc.DescribeInstances(&ec2.DescribeInstancesInput{InstanceIds: []*string{aws.String(InstanceId)}}) 134 | if err != nil { 135 | return nil, err 136 | } 137 | return &Ec2Info{ 138 | Name: getNameFromTags(rt.Reservations[0].Instances[0].Tags), 139 | InstanceId: *rt.Reservations[0].Instances[0].InstanceId, 140 | Status: *rt.Reservations[0].Instances[0].State.Name, 141 | Ip: *rt.Reservations[0].Instances[0].PublicIpAddress, 142 | }, nil 143 | } 144 | 145 | func (a *Aws) ListEc2() ([]Ec2Info, error) { 146 | svc := ec2.New(a.Sess) 147 | rt, err := svc.DescribeInstances(&ec2.DescribeInstancesInput{MaxResults: aws.Int64(100)}) 148 | if err != nil { 149 | return nil, err 150 | } 151 | ec2Instances := make([]Ec2Info, 0, len(rt.Reservations)) 152 | for _, v := range rt.Reservations { 153 | ec2Instances = append(ec2Instances, Ec2Info{ 154 | Name: getNameFromTags(v.Instances[0].Tags), 155 | Status: *v.Instances[0].State.Name, 156 | Type: *v.Instances[0].InstanceType, 157 | InstanceId: *v.Instances[0].InstanceId, 158 | Ip: *v.Instances[0].PublicIpAddress, 159 | }) 160 | } 161 | return ec2Instances, nil 162 | } 163 | 164 | func (a *Aws) StartEc2(InstanceId string) error { 165 | svc := ec2.New(a.Sess) 166 | _, err := svc.StartInstances(&ec2.StartInstancesInput{ 167 | InstanceIds: []*string{&InstanceId}}) 168 | if err != nil { 169 | return err 170 | } 171 | return nil 172 | } 173 | 174 | func (a *Aws) StopEc2(InstanceId string) error { 175 | svc := ec2.New(a.Sess) 176 | _, err := svc.StopInstances(&ec2.StopInstancesInput{ 177 | InstanceIds: []*string{&InstanceId}}) 178 | if err != nil { 179 | return err 180 | } 181 | return nil 182 | } 183 | 184 | func (a *Aws) RebootEc2(InstanceId string) error { 185 | svc := ec2.New(a.Sess) 186 | _, err := svc.RebootInstances(&ec2.RebootInstancesInput{ 187 | InstanceIds: []*string{&InstanceId}}) 188 | if err != nil { 189 | return err 190 | } 191 | return nil 192 | } 193 | 194 | func (a *Aws) DeleteEc2(InstanceId string) error { 195 | svc := ec2.New(a.Sess) 196 | ip, ipErr := svc.DescribeAddresses(&ec2.DescribeAddressesInput{ 197 | Filters: []*ec2.Filter{ 198 | { 199 | Name: aws.String("instance-id"), 200 | Values: []*string{aws.String(InstanceId)}, 201 | }, 202 | }, 203 | }) 204 | if ipErr != nil { 205 | return fmt.Errorf("get ip error: %v", ipErr) 206 | } 207 | if len(ip.Addresses) != 0 { 208 | _, relErr := svc.ReleaseAddress(&ec2.ReleaseAddressInput{ 209 | AllocationId: ip.Addresses[0].AssociationId}) 210 | if relErr != nil { 211 | return fmt.Errorf("release ip error: %v", relErr) 212 | } 213 | } 214 | _, err := svc.TerminateInstances(&ec2.TerminateInstancesInput{ 215 | InstanceIds: []*string{aws.String(InstanceId)}}) 216 | if err != nil { 217 | return fmt.Errorf("terminate instance error: %v", err) 218 | } 219 | return nil 220 | } 221 | 222 | func (a *Aws) GetAmiId(AmiName string) (string, error) { 223 | svc := ec2.New(a.Sess) 224 | ami, err := svc.DescribeImages(&ec2.DescribeImagesInput{ 225 | Filters: []*ec2.Filter{ 226 | { 227 | Name: aws.String("name"), 228 | Values: []*string{aws.String(AmiName)}, 229 | }, 230 | { 231 | Name: aws.String("architecture"), 232 | Values: []*string{aws.String("x86_64")}, 233 | }, 234 | }}) 235 | if err != nil { 236 | return "", err 237 | } 238 | return *ami.Images[0].ImageId, nil 239 | } 240 | 241 | func (a *Aws) getAmiEbsMap(AmiId string) ([]*ec2.BlockDeviceMapping, error) { 242 | svc := ec2.New(a.Sess) 243 | ami, err := svc.DescribeImages(&ec2.DescribeImagesInput{ 244 | Filters: []*ec2.Filter{ 245 | { 246 | Name: aws.String("image-id"), 247 | Values: []*string{aws.String(AmiId)}, 248 | }, 249 | { 250 | Name: aws.String("architecture"), 251 | Values: []*string{aws.String("x86_64")}, 252 | }, 253 | }}) 254 | if err != nil { 255 | return nil, err 256 | } 257 | return ami.Images[0].BlockDeviceMappings, nil 258 | } 259 | 260 | func (a *Aws) GetEc2WindowsPassword(InstanceId string) (*ec2.GetPasswordDataOutput, error) { 261 | svc := ec2.New(a.Sess) 262 | rt, err := svc.GetPasswordData(&ec2.GetPasswordDataInput{ 263 | InstanceId: &InstanceId}) 264 | if err != nil { 265 | return nil, err 266 | } 267 | return rt, nil 268 | } 269 | 270 | func (a *Aws) CreateEc2SshKey(name string) (string, error) { 271 | svc := ec2.New(a.Sess) 272 | rt, err := svc.CreateKeyPair(&ec2.CreateKeyPairInput{KeyName: &name}) 273 | if err != nil { 274 | return "", err 275 | } 276 | return *rt.KeyMaterial, nil 277 | } 278 | 279 | func (a *Aws) ListEc2SshKey() ([]*ec2.KeyPairInfo, error) { 280 | svc := ec2.New(a.Sess) 281 | rt, err := svc.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{}) 282 | if err != nil { 283 | return nil, err 284 | } 285 | return rt.KeyPairs, nil 286 | } 287 | 288 | func (a *Aws) DeleteEc2SshKey(name string) error { 289 | svc := ec2.New(a.Sess) 290 | _, err := svc.DeleteKeyPair(&ec2.DeleteKeyPairInput{KeyName: &name}) 291 | if err != nil { 292 | return err 293 | } 294 | return nil 295 | } 296 | -------------------------------------------------------------------------------- /aws/lightsail.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "strconv" 7 | "time" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | "github.com/aws/aws-sdk-go/service/lightsail" 11 | ) 12 | 13 | type LsInfo struct { 14 | Name string 15 | Ip string 16 | ResourceName string 17 | Type string 18 | Status string 19 | Key string 20 | } 21 | 22 | func (a *Aws) GetBlueprintId() (*lightsail.GetBlueprintsOutput, error) { 23 | svc := lightsail.New(a.Sess) 24 | blueID, blueErr := svc.GetBlueprints(&lightsail.GetBlueprintsInput{}) 25 | if blueErr != nil { 26 | return nil, blueErr 27 | } 28 | return blueID, nil 29 | } 30 | 31 | func (a *Aws) GetRegions() ([]*lightsail.Region, error) { 32 | svc := lightsail.New(a.Sess) 33 | regions, regErr := svc.GetRegions(&lightsail.GetRegionsInput{ 34 | IncludeAvailabilityZones: aws.Bool(true), 35 | }) 36 | if regErr != nil { 37 | return nil, regErr 38 | } 39 | return regions.Regions, nil 40 | } 41 | 42 | func (a *Aws) CreateLs(Name string, AvailabilityZone string, BlueprintId string, BundleId string) (*LsInfo, error) { 43 | svc := lightsail.New(a.Sess) 44 | dateName := Name + time.Unix(time.Now().Unix(), 0). 45 | Format(AvailabilityZone+"2006_01_02_15_04_05_"+strconv.Itoa(rand.Intn(1000))) 46 | key, keyErr := svc.CreateKeyPair(&lightsail.CreateKeyPairInput{ 47 | KeyPairName: aws.String(dateName)}) 48 | if keyErr != nil { 49 | return nil, fmt.Errorf("create key error: %v", keyErr) 50 | } 51 | lsRt, lsErr := svc.CreateInstances(&lightsail.CreateInstancesInput{ 52 | AvailabilityZone: aws.String(AvailabilityZone), 53 | BlueprintId: aws.String(BlueprintId), 54 | BundleId: aws.String(BundleId), 55 | InstanceNames: []*string{aws.String(Name)}, 56 | KeyPairName: aws.String(dateName), 57 | Tags: []*lightsail.Tag{ 58 | { 59 | Key: aws.String("ResourceName"), 60 | Value: aws.String(dateName), 61 | }, 62 | }, 63 | }) 64 | if lsErr != nil { 65 | return nil, fmt.Errorf("create ls error: %v", lsErr) 66 | } 67 | /*_, allErr := svc.AllocateStaticIp(&lightsail.AllocateStaticIpInput{ 68 | StaticIpName: aws.String(dateName + "_ip")}) 69 | if allErr != nil { 70 | return nil, fmt.Errorf("allocate ip error: %v", allErr) 71 | } 72 | _, attErr := svc.AttachStaticIp(&lightsail.AttachStaticIpInput{ 73 | StaticIpName: aws.String(dateName + "_ip"), 74 | InstanceName: aws.String(Name), 75 | }) 76 | if attErr != nil { 77 | return nil, fmt.Errorf("attach ip error: %v", attErr) 78 | }*/ 79 | return &LsInfo{ 80 | Name: Name, 81 | Status: *lsRt.Operations[0].Status, 82 | Key: *key.PrivateKeyBase64, 83 | }, nil 84 | } 85 | 86 | func (a *Aws) OpenLsPorts(Name string) error { 87 | svc := lightsail.New(a.Sess) 88 | _, err := svc.OpenInstancePublicPorts(&lightsail.OpenInstancePublicPortsInput{ 89 | InstanceName: aws.String(Name), 90 | PortInfo: &lightsail.PortInfo{ 91 | Protocol: aws.String("all"), 92 | FromPort: aws.Int64(0), 93 | ToPort: aws.Int64(65535), 94 | }, 95 | }) 96 | if err != nil { 97 | return err 98 | } 99 | return nil 100 | } 101 | 102 | func getResourceNameFromTags(tags []*lightsail.Tag) string { 103 | for _, tag := range tags { 104 | if *tag.Key == "ResourceName" { 105 | return *tag.Value 106 | } 107 | } 108 | return "" 109 | } 110 | 111 | func (a *Aws) GetLsInfo(Name string) (*LsInfo, error) { 112 | svc := lightsail.New(a.Sess) 113 | rt, err := svc.GetInstance(&lightsail.GetInstanceInput{ 114 | InstanceName: aws.String(Name)}) 115 | if err != nil { 116 | return nil, err 117 | } 118 | return &LsInfo{ 119 | Name: *rt.Instance.Name, 120 | Ip: *rt.Instance.PublicIpAddress, 121 | ResourceName: getResourceNameFromTags(rt.Instance.Tags), 122 | Status: *rt.Instance.State.Name, 123 | }, nil 124 | } 125 | 126 | func (a *Aws) ListLs() ([]*lightsail.Instance, error) { 127 | svc := lightsail.New(a.Sess) 128 | rt, err := svc.GetInstances(&lightsail.GetInstancesInput{}) 129 | if err != nil { 130 | return nil, err 131 | } 132 | info := make([]LsInfo, 0, len(rt.Instances)) 133 | for _, v := range rt.Instances { 134 | info = append(info, LsInfo{ 135 | Name: *v.Name, 136 | Type: *v.BundleId, 137 | Ip: *v.PublicIpAddress, 138 | ResourceName: getResourceNameFromTags(v.Tags), 139 | Status: *v.State.Name, 140 | }) 141 | } 142 | return rt.Instances, nil 143 | } 144 | 145 | func (a *Aws) getAndDeleteIpName(svc *lightsail.Lightsail, Name string) (string, error) { 146 | info, getErr := a.GetLsInfo(Name) 147 | if getErr != nil { 148 | return "", fmt.Errorf("get ls info error: %v", getErr) 149 | } 150 | haveStaticIp := false 151 | if info.ResourceName == "" { 152 | ip, err := svc.GetStaticIps(&lightsail.GetStaticIpsInput{}) 153 | if err != nil { 154 | return "", fmt.Errorf("list ip error: %v", err) 155 | } 156 | for _, v := range ip.StaticIps { 157 | if *v.IpAddress == info.Ip { 158 | info.ResourceName = *v.Name 159 | haveStaticIp = true 160 | break 161 | } 162 | } 163 | info.ResourceName = info.Name + time.Unix(time.Now().Unix(), 0). 164 | Format("_2006_01_02_15_04_05_"+strconv.Itoa(rand.Intn(1000))) 165 | } else { 166 | info.ResourceName = info.Name + "_ip" 167 | _, err := svc.GetStaticIp(&lightsail.GetStaticIpInput{ 168 | StaticIpName: aws.String(info.ResourceName), 169 | }) 170 | if err != nil { 171 | if err.Error() != lightsail.ErrCodeNotFoundException { 172 | return "", fmt.Errorf("get ip error: %v", err) 173 | } 174 | } else { 175 | haveStaticIp = true 176 | } 177 | } 178 | if haveStaticIp { 179 | _, detErr := svc.DetachStaticIp(&lightsail.DetachStaticIpInput{ 180 | StaticIpName: &info.ResourceName}) 181 | if detErr != nil { 182 | return "", fmt.Errorf("detach ip error: %v", detErr) 183 | } 184 | _, relErr := svc.ReleaseStaticIp(&lightsail.ReleaseStaticIpInput{ 185 | StaticIpName: &info.ResourceName}) 186 | if relErr != nil { 187 | return "", fmt.Errorf("release ip error: %v", relErr) 188 | } 189 | return info.ResourceName, nil 190 | } 191 | return "", nil 192 | } 193 | 194 | func (a *Aws) ChangeLsIp(Name string) error { 195 | svc := lightsail.New(a.Sess) 196 | ipName, err := a.getAndDeleteIpName(svc, Name) 197 | if err != nil { 198 | return err 199 | } 200 | _, allErr := svc.AllocateStaticIp(&lightsail.AllocateStaticIpInput{ 201 | StaticIpName: &ipName}) 202 | if allErr != nil { 203 | return fmt.Errorf("allocate ip error: %v", allErr) 204 | } 205 | _, attErr := svc.AttachStaticIp(&lightsail.AttachStaticIpInput{ 206 | StaticIpName: &ipName, 207 | InstanceName: &Name, 208 | }) 209 | if attErr != nil { 210 | return fmt.Errorf("attach ip error: %v", attErr) 211 | } 212 | return nil 213 | } 214 | 215 | func (a *Aws) StopLs(Name string) error { 216 | svc := lightsail.New(a.Sess) 217 | _, err := svc.StopInstance(&lightsail.StopInstanceInput{ 218 | InstanceName: aws.String(Name)}) 219 | if err != nil { 220 | return err 221 | } 222 | return nil 223 | } 224 | 225 | func (a *Aws) StartLs(Name string) error { 226 | svc := lightsail.New(a.Sess) 227 | _, err := svc.StartInstance(&lightsail.StartInstanceInput{ 228 | InstanceName: &Name}) 229 | if err != nil { 230 | return err 231 | } 232 | return nil 233 | } 234 | 235 | func (a *Aws) RebootLs(Name string) error { 236 | svc := lightsail.New(a.Sess) 237 | _, err := svc.RebootInstance(&lightsail.RebootInstanceInput{ 238 | InstanceName: &Name}) 239 | if err != nil { 240 | return err 241 | } 242 | return nil 243 | } 244 | 245 | func (a *Aws) DeleteLs(Name string, ResourceName string) error { 246 | svc := lightsail.New(a.Sess) 247 | _, err := a.getAndDeleteIpName(svc, Name) 248 | if err != nil { 249 | return err 250 | } 251 | if ResourceName != "" { 252 | _, delErr := svc.DeleteKeyPair(&lightsail.DeleteKeyPairInput{ 253 | KeyPairName: &ResourceName}) 254 | if delErr != nil { 255 | return fmt.Errorf("delete key error: %v", delErr) 256 | } 257 | } 258 | _, delInstance := svc.DeleteInstance(&lightsail.DeleteInstanceInput{ 259 | InstanceName: &Name}) 260 | if delInstance != nil { 261 | return fmt.Errorf("delete instance error: %v", delInstance) 262 | } 263 | return nil 264 | } 265 | -------------------------------------------------------------------------------- /aws/quota.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/aws" 5 | quota "github.com/aws/aws-sdk-go/service/servicequotas" 6 | ) 7 | 8 | func (a *Aws) GetQuota(ServiceCode string, QuotaCode string) (*quota.ServiceQuota, error) { 9 | svc := quota.New(a.Sess) 10 | rt, err := svc.GetServiceQuota("a.GetServiceQuotaInput{ 11 | ServiceCode: aws.String(ServiceCode), 12 | QuotaCode: aws.String(QuotaCode), 13 | }) 14 | if err != nil { 15 | return nil, err 16 | } 17 | return rt.Quota, nil 18 | } 19 | func (a *Aws) ChangeQuota(ServiceCode string, QuotaCode string, DesiredValue float64) error { 20 | svc := quota.New(a.Sess) 21 | _, err := svc.RequestServiceQuotaIncrease("a.RequestServiceQuotaIncreaseInput{ 22 | ServiceCode: aws.String(ServiceCode), 23 | QuotaCode: aws.String(QuotaCode), 24 | DesiredValue: aws.Float64(DesiredValue), 25 | }) 26 | if err != nil { 27 | return err 28 | } 29 | return nil 30 | } 31 | 32 | func (a *Aws) ListChangeQuotaRequest(ServiceCode string, QuotaCode string) ([]*quota.RequestedServiceQuotaChange, error) { 33 | svc := quota.New(a.Sess) 34 | rt, err := svc.ListRequestedServiceQuotaChangeHistoryByQuota("a.ListRequestedServiceQuotaChangeHistoryByQuotaInput{ 35 | ServiceCode: aws.String(ServiceCode), 36 | QuotaCode: aws.String(QuotaCode), 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | return rt.RequestedQuotas, nil 42 | } 43 | -------------------------------------------------------------------------------- /aws/wavelength.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go/aws" 5 | "github.com/aws/aws-sdk-go/service/ec2" 6 | "time" 7 | ) 8 | 9 | func (a *Aws) getVpcId() (string, error) { 10 | svc := ec2.New(a.Sess) 11 | vpc, err := svc.DescribeVpcs(&ec2.DescribeVpcsInput{}) 12 | if err != nil { 13 | return "", err 14 | } 15 | return *vpc.Vpcs[0].VpcId, nil 16 | } 17 | 18 | func (a *Aws) CreateWl(Zone string) (string, error) { 19 | svc := ec2.New(a.Sess) 20 | vpcId, vpcErr := a.getVpcId() 21 | if vpcErr != nil { 22 | return "", vpcErr 23 | } 24 | sub, subErr := svc.CreateSubnet(&ec2.CreateSubnetInput{ 25 | AvailabilityZone: aws.String(Zone), 26 | CidrBlock: aws.String("172.31.128.0/20"), 27 | VpcId: aws.String(vpcId), 28 | TagSpecifications: []*ec2.TagSpecification{ 29 | { 30 | ResourceType: aws.String("subnet"), 31 | Tags: []*ec2.Tag{ 32 | { 33 | Key: aws.String("Username"), 34 | Value: aws.String("aws_manger_subnet"), 35 | }, 36 | }, 37 | }, 38 | }, 39 | }) 40 | if subErr != nil { 41 | return "", subErr 42 | } 43 | ca, caErr := svc.CreateCarrierGateway(&ec2.CreateCarrierGatewayInput{ 44 | VpcId: aws.String(vpcId), 45 | TagSpecifications: []*ec2.TagSpecification{ 46 | { 47 | ResourceType: aws.String("carrier-gateway"), 48 | Tags: []*ec2.Tag{ 49 | { 50 | Key: aws.String("Username"), 51 | Value: aws.String("aws_manger_gateway"), 52 | }, 53 | }, 54 | }, 55 | }, 56 | }) 57 | if caErr != nil { 58 | return "", caErr 59 | } 60 | route, routeErr := svc.CreateRouteTable(&ec2.CreateRouteTableInput{ 61 | VpcId: aws.String(vpcId), 62 | TagSpecifications: []*ec2.TagSpecification{ 63 | { 64 | ResourceType: aws.String("route-table"), 65 | Tags: []*ec2.Tag{ 66 | { 67 | Key: aws.String("Username"), 68 | Value: aws.String("aws_manger_route"), 69 | }, 70 | }, 71 | }, 72 | }, 73 | }) 74 | if routeErr != nil { 75 | return "", routeErr 76 | } 77 | _, assErr := svc.AssociateRouteTable(&ec2.AssociateRouteTableInput{ 78 | RouteTableId: route.RouteTable.RouteTableId, 79 | GatewayId: ca.CarrierGateway.CarrierGatewayId, 80 | }) 81 | if assErr != nil { 82 | return "", assErr 83 | } 84 | return *sub.Subnet.SubnetId, nil 85 | } 86 | 87 | func (a *Aws) GetSubnetInfo() (*ec2.DescribeSubnetsOutput, error) { 88 | svc := ec2.New(a.Sess) 89 | sub, err := svc.DescribeSubnets(&ec2.DescribeSubnetsInput{ 90 | Filters: []*ec2.Filter{ 91 | { 92 | Name: aws.String("tag:Username"), 93 | Values: []*string{aws.String("kddi")}, 94 | }, 95 | }, 96 | }) 97 | if err != nil { 98 | return nil, err 99 | } 100 | return sub, nil 101 | } 102 | 103 | func (a *Aws) CreateEc2Wl(SubId string, Ami string, Name string, DiskSize int64) (*Ec2Info, error) { 104 | svc := ec2.New(a.Sess) 105 | dateName := Name + time.Unix(time.Now().Unix(), 0).Format("_2006-01-02_15:04:05") 106 | keyRt, keyErr := svc.CreateKeyPair(&ec2.CreateKeyPairInput{KeyName: &dateName}) 107 | if keyErr != nil { 108 | return nil, keyErr 109 | } //创建ssh密钥 110 | secRt, secErr := svc.CreateSecurityGroup(&ec2.CreateSecurityGroupInput{ 111 | GroupName: aws.String(dateName + "security"), 112 | Description: aws.String("A security group for aws manger bot"), 113 | }) //创建安全组 114 | if secErr != nil { 115 | return nil, secErr 116 | } 117 | _, authSecInErr := svc.AuthorizeSecurityGroupIngress(&ec2.AuthorizeSecurityGroupIngressInput{ 118 | GroupId: secRt.GroupId, 119 | IpPermissions: []*ec2.IpPermission{ 120 | { 121 | IpProtocol: aws.String("-1"), 122 | IpRanges: []*ec2.IpRange{ 123 | { 124 | CidrIp: aws.String("0.0.0.0/0"), 125 | }, 126 | }, 127 | FromPort: aws.Int64(-1), 128 | ToPort: aws.Int64(-1), 129 | }, 130 | }, 131 | }) //添加入站规则 132 | if authSecInErr != nil { 133 | return nil, authSecInErr 134 | } 135 | runRt, runErr := svc.RunInstances(&ec2.RunInstancesInput{ 136 | ImageId: aws.String(Ami), 137 | InstanceType: aws.String("t3.medium"), 138 | MinCount: aws.Int64(1), 139 | MaxCount: aws.Int64(1), 140 | KeyName: &dateName, 141 | NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{{ 142 | DeviceIndex: aws.Int64(0), 143 | SubnetId: aws.String(SubId), 144 | AssociateCarrierIpAddress: aws.Bool(true), 145 | Groups: []*string{secRt.GroupId}, 146 | }}, 147 | BlockDeviceMappings: []*ec2.BlockDeviceMapping{{DeviceName: aws.String("/dev/sda1"), 148 | Ebs: &ec2.EbsBlockDevice{VolumeSize: aws.Int64(DiskSize)}}}, 149 | }) //创建ec2实例 150 | if runErr != nil { 151 | return nil, runErr 152 | } 153 | _, tagErr := svc.CreateTags(&ec2.CreateTagsInput{ 154 | Resources: []*string{runRt.Instances[0].InstanceId}, 155 | Tags: []*ec2.Tag{ 156 | { 157 | Key: aws.String("Email"), 158 | Value: aws.String(Name), 159 | }, 160 | }, 161 | }) //创建标签 162 | if tagErr != nil { 163 | return nil, tagErr 164 | } 165 | return &Ec2Info{ 166 | Name: Name, 167 | Ip: *runRt.Instances[0].PrivateIpAddress, 168 | InstanceId: *runRt.Instances[0].InstanceId, 169 | Status: *runRt.Instances[0].State.Name, 170 | Key: *keyRt.KeyMaterial, 171 | }, nil 172 | } 173 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | mkdir tmp 2 | CGO_ENABLED=1 go build || exit 1 3 | mv Aws-Panel tmp/ 4 | cp ./example/config.json tmp/ 5 | cp LICENSE tmp/ 6 | cd ./web/ || exit 1 7 | npm install || exit 1 8 | npm run build || exit 1 9 | mv dist/ ../tmp/web 10 | cd ../tmp/ || exit 1 11 | zip -r Aws-Panel.zip ./* 12 | mv Aws-Panel.zip ../ 13 | cd ../ 14 | rm -rf tmp 15 | -------------------------------------------------------------------------------- /cache/cache.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "github.com/patrickmn/go-cache" 5 | "time" 6 | ) 7 | 8 | var client = cache.New(6*time.Hour, 2*time.Hour) 9 | 10 | func Get(key string) (interface{}, bool) { 11 | return client.Get(key) 12 | } 13 | 14 | func Set(key string, value interface{}, expiration time.Duration) { 15 | client.Set(key, value, expiration) 16 | } 17 | 18 | func Delete(key string) { 19 | client.Delete(key) 20 | } 21 | 22 | func DeleteExpired() { 23 | client.DeleteExpired() 24 | } 25 | 26 | func DeleteAll() { 27 | client.Flush() 28 | } 29 | -------------------------------------------------------------------------------- /conf/conf.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | var Config *Conf 10 | 11 | type Conf struct { 12 | path string 13 | LogLevel string `json:"LogLevel"` 14 | Addr string `json:"Addr"` 15 | DbPath string `json:"DbPath"` 16 | EnableLoadStatic bool `json:"LoadStatic"` 17 | StaticPath string `json:"StaticPath"` 18 | EnableMailVerify bool `json:"EnableMailVerify"` 19 | MailConfig *Mail `json:"MailConfig"` 20 | } 21 | type Mail struct { 22 | Host string `json:"Host"` 23 | Port int `json:"Port"` 24 | Email string `json:"Email"` 25 | Password string `json:"Password"` 26 | } 27 | 28 | func New(path string) *Conf { 29 | return &Conf{ 30 | path: path, 31 | LogLevel: "error", 32 | Addr: ":8011", 33 | DbPath: "./data.db", 34 | EnableLoadStatic: true, 35 | StaticPath: "./web", 36 | EnableMailVerify: false, 37 | MailConfig: &Mail{ 38 | Host: "smtp.qq.com", 39 | Port: 465, 40 | Email: "a@qq.com", 41 | Password: "12321", 42 | }, 43 | } 44 | } 45 | 46 | func Init(path string) error { 47 | Config = New(path) 48 | err := Config.LoadConfig() 49 | if err != nil { 50 | return err 51 | } 52 | return nil 53 | } 54 | 55 | func (c *Conf) LoadConfig() error { 56 | r, err := os.Open(c.path) 57 | if err != nil { 58 | return fmt.Errorf("read config file error: %s", err) 59 | } 60 | err = json.NewDecoder(r).Decode(c) 61 | if err != nil { 62 | return fmt.Errorf("unmarshal config file error: %w", err) 63 | } 64 | return nil 65 | } 66 | 67 | func (c *Conf) SaveConfig() error { 68 | f, err := os.OpenFile(c.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) 69 | if err != nil { 70 | return fmt.Errorf("open file error: %s", err) 71 | } 72 | err = json.NewEncoder(f).Encode(c) 73 | if err != nil { 74 | return fmt.Errorf("unmarshal config file error: %s", err) 75 | } 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /conf/conf_test.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import "testing" 4 | 5 | func TestConf_SaveConfig(t *testing.T) { 6 | c := New("./config.json") 7 | err := c.SaveConfig() 8 | if err != nil { 9 | t.Errorf("save config error: %s", err) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /controller/aga.go: -------------------------------------------------------------------------------- 1 | package controller 2 | -------------------------------------------------------------------------------- /controller/config.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/conf" 5 | "github.com/gin-gonic/gin" 6 | ) 7 | 8 | func IsEnableEmailVerify(c *gin.Context) { 9 | c.JSON(200, gin.H{ 10 | "code": 200, 11 | "data": conf.Config.EnableMailVerify, 12 | }) 13 | } 14 | -------------------------------------------------------------------------------- /controller/controller.go: -------------------------------------------------------------------------------- 1 | package controller 2 | -------------------------------------------------------------------------------- /controller/ec2.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "errors" 5 | "github.com/Yuzuki616/Aws-Panel/aws" 6 | "github.com/Yuzuki616/Aws-Panel/data" 7 | "github.com/Yuzuki616/Aws-Panel/request" 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | func CreateEc2(c *gin.Context) error { 12 | email := c.GetString("email") 13 | p := request.CreateEc2{} 14 | if err := c.ShouldBind(&p); err != nil { 15 | return err 16 | } 17 | secret, _ := data.GetSecret(email, p.SecretName) 18 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 19 | if newErr != nil { 20 | return newErr 21 | } 22 | amiTmp, amiErr := client.GetAmiId(p.Ami) 23 | if amiErr != nil { 24 | return amiErr 25 | } 26 | if amiTmp == "" { 27 | return errors.New("get ami ID error: not found ami") 28 | } 29 | creRt, creErr := client.CreateEc2(amiTmp, p.Ec2Type, p.Ec2Name, p.Userdata, p.Disk) 30 | if creErr != nil { 31 | return creErr 32 | } 33 | c.JSON(200, gin.H{ 34 | "code": 200, 35 | "msg": "创建成功", 36 | "data": creRt.Key, 37 | }) 38 | return nil 39 | } 40 | 41 | func ListEc2(c *gin.Context) error { 42 | email := c.GetString("email") 43 | p := request.ListEc2{} 44 | if err := c.ShouldBind(&p); err != nil { 45 | return err 46 | } 47 | secret, _ := data.GetSecret(email, p.SecretName) 48 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 49 | if newErr != nil { 50 | return newErr 51 | } 52 | ec2Info, listErr := client.ListEc2() 53 | if listErr != nil { 54 | return listErr 55 | } 56 | 57 | c.JSON(200, gin.H{ 58 | "code": 200, 59 | "data": ec2Info, 60 | }) 61 | return nil 62 | } 63 | 64 | func GetEc2Info(c *gin.Context) error { 65 | email := c.GetString("email") 66 | p := request.Ec2Action{} 67 | if err := c.ShouldBind(&p); err != nil { 68 | return err 69 | } 70 | secret, _ := data.GetSecret(email, p.SecretName) 71 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 72 | if newErr != nil { 73 | return newErr 74 | } 75 | ec2Info, getErr := client.GetEc2Info(p.Ec2Id) 76 | if getErr != nil { 77 | return getErr 78 | } 79 | c.JSON(200, gin.H{ 80 | "code": 200, 81 | "data": ec2Info, 82 | }) 83 | return nil 84 | } 85 | 86 | func ChangeEc2Ip(c *gin.Context) error { 87 | email := c.GetString("email") 88 | p := request.Ec2Action{} 89 | if err := c.ShouldBind(&p); err != nil { 90 | return err 91 | } 92 | secret, _ := data.GetSecret(email, p.SecretName) 93 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 94 | if newErr != nil { 95 | return newErr 96 | } 97 | newIp, changeErr := client.ChangeEc2Ip(p.Ec2Id) 98 | if changeErr != nil { 99 | return changeErr 100 | } 101 | c.JSON(200, gin.H{ 102 | "code": 200, 103 | "msg": "更换IP成功", 104 | "data": newIp, 105 | }) 106 | return nil 107 | } 108 | 109 | func StopEc2(c *gin.Context) error { 110 | email := c.GetString("email") 111 | p := request.Ec2Action{} 112 | if err := c.ShouldBind(&p); err != nil { 113 | return err 114 | } 115 | secret, _ := data.GetSecret(email, p.SecretName) 116 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 117 | if newErr != nil { 118 | return newErr 119 | } 120 | stopErr := client.StopEc2(p.Ec2Id) 121 | if stopErr != nil { 122 | return stopErr 123 | } 124 | c.JSON(200, gin.H{ 125 | "code": 200, 126 | "msg": "启动失败", 127 | }) 128 | return nil 129 | } 130 | 131 | func StartEc2(c *gin.Context) error { 132 | email := c.GetString("email") 133 | p := request.Ec2Action{} 134 | if err := c.ShouldBind(&p); err != nil { 135 | return err 136 | } 137 | secret, _ := data.GetSecret(email, p.SecretName) 138 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 139 | if newErr != nil { 140 | return newErr 141 | } 142 | startErr := client.StartEc2(p.Ec2Id) 143 | if startErr != nil { 144 | return startErr 145 | } 146 | c.JSON(200, gin.H{ 147 | "code": 200, 148 | "msg": "启动成功", 149 | }) 150 | return nil 151 | } 152 | 153 | func RebootEc2(c *gin.Context) error { 154 | email := c.GetString("email") 155 | p := request.Ec2Action{} 156 | if err := c.ShouldBind(&p); err != nil { 157 | return err 158 | } 159 | secret, _ := data.GetSecret(email, p.SecretName) 160 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 161 | if newErr != nil { 162 | return newErr 163 | } 164 | rebootErr := client.RebootEc2(p.Ec2Id) 165 | if rebootErr != nil { 166 | return rebootErr 167 | } 168 | c.JSON(200, gin.H{ 169 | "code": 200, 170 | "msg": "重启成功", 171 | }) 172 | return nil 173 | } 174 | 175 | func DeleteEc2(c *gin.Context) error { 176 | email := c.GetString("email") 177 | p := request.Ec2Action{} 178 | if err := c.ShouldBind(&p); err != nil { 179 | return err 180 | } 181 | secret, _ := data.GetSecret(email, p.SecretName) 182 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 183 | if newErr != nil { 184 | return newErr 185 | } 186 | delErr := client.DeleteEc2(p.Ec2Id) 187 | if delErr != nil { 188 | return delErr 189 | } 190 | c.JSON(200, gin.H{ 191 | "code": 200, 192 | "msg": "删除成功", 193 | }) 194 | return nil 195 | } 196 | 197 | func CreateEc2SshKey(c *gin.Context) error { 198 | email := c.GetString("email") 199 | p := request.CreateEc2SshKey{} 200 | if err := c.ShouldBind(&p); err != nil { 201 | return err 202 | } 203 | secret, _ := data.GetSecret(email, p.SecretName) 204 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 205 | if newErr != nil { 206 | return newErr 207 | } 208 | key, err := client.CreateEc2SshKey(p.KeyName) 209 | if err != nil { 210 | return err 211 | } 212 | c.JSON(200, gin.H{ 213 | "code": 200, 214 | "msg": "创建成功", 215 | "data": key, 216 | }) 217 | return nil 218 | } 219 | 220 | func ListEc2SshKey(c *gin.Context) error { 221 | email := c.GetString("email") 222 | p := request.ListEc2SshKey{} 223 | if err := c.ShouldBind(&p); err != nil { 224 | return err 225 | } 226 | secret, _ := data.GetSecret(email, p.SecretName) 227 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 228 | if newErr != nil { 229 | return newErr 230 | } 231 | keys, err := client.ListEc2SshKey() 232 | if err != nil { 233 | return err 234 | } 235 | c.JSON(200, gin.H{ 236 | "code": 200, 237 | "msg": "获取成功", 238 | "data": keys, 239 | }) 240 | return nil 241 | } 242 | 243 | func DeleteEc2SshKey(c *gin.Context) error { 244 | email := c.GetString("email") 245 | p := request.DeleteEc2SshKey{} 246 | if err := c.ShouldBind(&p); err != nil { 247 | return err 248 | } 249 | secret, _ := data.GetSecret(email, p.SecretName) 250 | client, newErr := aws.New(p.Region, secret.SecretId, secret.Secret, "") 251 | if newErr != nil { 252 | return newErr 253 | } 254 | err := client.DeleteEc2SshKey(p.KeyName) 255 | if err != nil { 256 | return err 257 | } 258 | c.JSON(200, gin.H{ 259 | "code": 200, 260 | "msg": "删除成功", 261 | }) 262 | return nil 263 | } 264 | -------------------------------------------------------------------------------- /controller/error.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import "github.com/gin-gonic/gin" 4 | 5 | func ErrorHandle(handle func(c *gin.Context) error) gin.HandlerFunc { 6 | return func(context *gin.Context) { 7 | err := handle(context) 8 | if err != nil { 9 | context.JSON(400, gin.H{ 10 | "code": 400, 11 | "msg": err.Error(), 12 | }) 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /controller/lightsail.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/aws" 5 | "github.com/Yuzuki616/Aws-Panel/data" 6 | "github.com/Yuzuki616/Aws-Panel/request" 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | func GetRegions(c *gin.Context) error { 11 | email := c.GetString("email") 12 | params := request.GetRegions{} 13 | if err := c.ShouldBind(¶ms); err != nil { 14 | return err 15 | } 16 | secret, _ := data.GetSecret(email, params.SecretName) 17 | client, newErr := aws.New("ap-northeast-1", secret.SecretId, secret.Secret, "") 18 | if newErr != nil { 19 | return newErr 20 | } 21 | regions, getRegionsErr := client.GetRegions() 22 | if getRegionsErr != nil { 23 | return getRegionsErr 24 | } 25 | c.JSON(200, gin.H{ 26 | "code": 200, 27 | "msg": "查询成功", 28 | "data": regions, 29 | }) 30 | return nil 31 | } 32 | 33 | func CreateLightsail(c *gin.Context) error { 34 | email := c.GetString("email") 35 | params := request.CreateLightsail{} 36 | if err := c.ShouldBind(¶ms); err != nil { 37 | return err 38 | } 39 | secret, _ := data.GetSecret(email, params.SecretName) 40 | client, newErr := aws.New(params.Zone, secret.SecretId, secret.Secret, "") 41 | if newErr != nil { 42 | return newErr 43 | } 44 | createRt, createErr := client.CreateLs(params.Name, 45 | params.AvailabilityZone, params.BlueprintId, params.BundleId) 46 | if createErr != nil { 47 | return createErr 48 | } 49 | c.JSON(200, gin.H{ 50 | "code": 200, 51 | "msg": "创建成功", 52 | "data": createRt.Key, 53 | }) 54 | return nil 55 | } 56 | 57 | func OpenLightsailPorts(c *gin.Context) error { 58 | email := c.GetString("email") 59 | p := request.OpenLightsailPorts{} 60 | if err := c.ShouldBind(&p); err != nil { 61 | return err 62 | } 63 | secret, _ := data.GetSecret(email, p.SecretName) 64 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 65 | if newErr != nil { 66 | return newErr 67 | } 68 | openErr := client.OpenLsPorts(p.Name) 69 | if openErr != nil { 70 | return openErr 71 | } 72 | c.JSON(200, gin.H{ 73 | "code": 200, 74 | "msg": "开放成功", 75 | }) 76 | return nil 77 | } 78 | 79 | func ListLightsail(c *gin.Context) error { 80 | email := c.GetString("email") 81 | p := request.LightsailAction{} 82 | if err := c.ShouldBind(&p); err != nil { 83 | return err 84 | } 85 | secret, _ := data.GetSecret(email, p.SecretName) 86 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 87 | if newErr != nil { 88 | return newErr 89 | } 90 | listRt, listErr := client.ListLs() 91 | if listErr != nil { 92 | return listErr 93 | } 94 | var instances []*aws.LsInfo 95 | if listRt == nil { 96 | instances = append(instances, &aws.LsInfo{}) 97 | } 98 | c.JSON(200, gin.H{ 99 | "code": 200, 100 | "msg": "查询成功", 101 | "data": instances, 102 | }) 103 | return nil 104 | } 105 | 106 | func GetLightsailInfo(c *gin.Context) error { 107 | email := c.GetString("email") 108 | p := request.LightsailAction{} 109 | name := c.PostForm("name") 110 | secret, _ := data.GetSecret(email, p.SecretName) 111 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 112 | if newErr != nil { 113 | return newErr 114 | } 115 | info, getInfoErr := client.GetLsInfo(name) 116 | if getInfoErr != nil { 117 | return getInfoErr 118 | } 119 | c.JSON(200, gin.H{ 120 | "code": 200, 121 | "msg": "删除成功", 122 | "data": info, 123 | }) 124 | return nil 125 | } 126 | 127 | func StartLightsail(c *gin.Context) error { 128 | email := c.GetString("email") 129 | p := request.LightsailAction{} 130 | if err := c.ShouldBind(&p); err != nil { 131 | return err 132 | } 133 | secret, _ := data.GetSecret(email, p.SecretName) 134 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 135 | if newErr != nil { 136 | return newErr 137 | } 138 | startErr := client.StartLs(p.Name) 139 | if startErr != nil { 140 | return startErr 141 | } 142 | c.JSON(200, gin.H{ 143 | "code": 200, 144 | "msg": "启动成功", 145 | }) 146 | return nil 147 | } 148 | 149 | func StopLightsail(c *gin.Context) error { 150 | email := c.GetString("email") 151 | p := request.LightsailAction{} 152 | if err := c.ShouldBind(&p); err != nil { 153 | return err 154 | } 155 | secret, _ := data.GetSecret(email, p.SecretName) 156 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 157 | if newErr != nil { 158 | return newErr 159 | } 160 | stopErr := client.StopLs(p.Name) 161 | if stopErr != nil { 162 | return stopErr 163 | } 164 | c.JSON(200, gin.H{ 165 | "code": 200, 166 | "msg": "停止成功", 167 | }) 168 | return nil 169 | } 170 | 171 | func RebootLightsail(c *gin.Context) error { 172 | email := c.GetString("email") 173 | p := request.LightsailAction{} 174 | if err := c.ShouldBind(&p); err != nil { 175 | return err 176 | } 177 | secret, _ := data.GetSecret(email, p.SecretName) 178 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 179 | if newErr != nil { 180 | return newErr 181 | } 182 | stopErr := client.RebootLs(p.Name) 183 | if stopErr != nil { 184 | return stopErr 185 | } 186 | c.JSON(200, gin.H{ 187 | "code": 200, 188 | "msg": "停止成功", 189 | }) 190 | return nil 191 | } 192 | 193 | func ChangeLightsailIp(c *gin.Context) error { 194 | email := c.GetString("email") 195 | p := request.LightsailAction{} 196 | if err := c.ShouldBind(&p); err != nil { 197 | return err 198 | } 199 | secret, _ := data.GetSecret(email, p.SecretName) 200 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 201 | if newErr != nil { 202 | return newErr 203 | } 204 | changeIpErr := client.ChangeLsIp(p.Name) 205 | if changeIpErr != nil { 206 | return changeIpErr 207 | } 208 | c.JSON(200, gin.H{ 209 | "code": 200, 210 | "msg": "更换IP成功", 211 | }) 212 | return nil 213 | } 214 | 215 | func DeleteLightsail(c *gin.Context) error { 216 | email := c.GetString("email") 217 | p := request.DeleteLightsail{} 218 | if err := c.ShouldBind(&p); err != nil { 219 | return err 220 | } 221 | secret, _ := data.GetSecret(email, p.SecretName) 222 | client, newErr := aws.New(p.Zone, secret.SecretId, secret.Secret, "") 223 | if newErr != nil { 224 | return newErr 225 | } 226 | startErr := client.DeleteLs(p.Name, p.ResourceName) 227 | if startErr != nil { 228 | return startErr 229 | } 230 | c.JSON(200, gin.H{ 231 | "code": 200, 232 | "msg": "删除成功", 233 | }) 234 | return nil 235 | } 236 | -------------------------------------------------------------------------------- /controller/quota.go: -------------------------------------------------------------------------------- 1 | package controller 2 | -------------------------------------------------------------------------------- /controller/secret.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/data" 5 | "github.com/Yuzuki616/Aws-Panel/request" 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | func AddSecret(c *gin.Context) error { 10 | email := c.GetString("email") 11 | params := &request.AddSecret{} 12 | if err := c.ShouldBind(params); err != nil { 13 | return err 14 | } 15 | addErr := data.AddSecret(email, params.Name, params.Id, params.Secret) 16 | if addErr != nil { 17 | return addErr 18 | } 19 | c.JSON(200, gin.H{ 20 | "code": 200, 21 | "msg": "添加成功", 22 | }) 23 | return nil 24 | } 25 | 26 | func ListSecret(c *gin.Context) error { 27 | email := c.GetString("email") 28 | secret, listErr := data.ListSecret(email) 29 | if listErr != nil { 30 | return listErr 31 | } 32 | var tmp []map[string]string 33 | for _, v := range secret { 34 | tmp = append(tmp, map[string]string{ 35 | "name": v.Name, 36 | "id": v.SecretId, 37 | "secret": v.Secret, 38 | }) 39 | } 40 | c.JSON(200, gin.H{ 41 | "code": 200, 42 | "msg": "查询成功", 43 | "data": tmp, 44 | }) 45 | return nil 46 | } 47 | 48 | func GetSecret(c *gin.Context) error { 49 | email := c.GetString("email") 50 | params := &request.GetSecret{} 51 | secret, getErr := data.GetSecret(email, params.Name) 52 | if getErr != nil { 53 | return getErr 54 | } 55 | c.JSON(200, gin.H{ 56 | "code": 200, 57 | "msg": "查询成功", 58 | "data": secret, 59 | }) 60 | return nil 61 | } 62 | 63 | func DelSecret(c *gin.Context) error { 64 | email := c.GetString("email") 65 | params := &request.DelSecret{} 66 | if err := c.ShouldBind(params); err != nil { 67 | return err 68 | } 69 | delErr := data.DelSecret(email, params.Name) 70 | if delErr != nil { 71 | return delErr 72 | } 73 | c.JSON(200, gin.H{ 74 | "code": 200, 75 | "msg": "删除成功", 76 | }) 77 | return nil 78 | } 79 | -------------------------------------------------------------------------------- /controller/session.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/cache" 5 | "github.com/Yuzuki616/Aws-Panel/utils" 6 | "github.com/gin-contrib/sessions" 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | func addLoginSession(c *gin.Context, email string) error { 11 | sessionId := utils.GenRandomString(16) 12 | if _, e := cache.Get(sessionId); e { 13 | return addLoginSession(c, email) 14 | } 15 | cache.Set(sessionId, email, 0) 16 | s := sessions.Default(c) 17 | s.Set("loginSession", sessionId) 18 | saveErr := s.Save() 19 | if saveErr != nil { 20 | return saveErr 21 | } 22 | return nil 23 | } 24 | 25 | func delLoginSession(c *gin.Context) error { 26 | s := sessions.Default(c) 27 | id := s.Get("loginSession") 28 | cache.Delete(id.(string)) 29 | s.Delete("loginSession") 30 | err := s.Save() 31 | if err != nil { 32 | return err 33 | } 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /controller/user.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "errors" 5 | "github.com/Yuzuki616/Aws-Panel/cache" 6 | "github.com/Yuzuki616/Aws-Panel/conf" 7 | "github.com/Yuzuki616/Aws-Panel/data" 8 | "github.com/Yuzuki616/Aws-Panel/mail" 9 | "github.com/Yuzuki616/Aws-Panel/request" 10 | "github.com/Yuzuki616/Aws-Panel/utils" 11 | "github.com/gin-gonic/gin" 12 | "time" 13 | ) 14 | 15 | func Login(c *gin.Context) error { 16 | params := &request.Login{} 17 | if err := c.ShouldBind(params); err != nil { 18 | return err 19 | } 20 | err := data.VerifyUser(params.Email, params.Password) 21 | if err != nil { 22 | return err 23 | } 24 | err = addLoginSession(c, params.Email) 25 | if err != nil { 26 | return err 27 | } 28 | c.JSON(200, gin.H{ 29 | "code": 200, 30 | "isAdmin": data.IsAdmin(params.Email), 31 | "msg": "登录成功", 32 | }) 33 | return nil 34 | } 35 | 36 | func SendMailVerify(c *gin.Context) error { 37 | p := request.SendMailVerify{} 38 | if err := c.ShouldBind(&p); err != nil { 39 | return err 40 | } 41 | if !conf.Config.EnableMailVerify { 42 | return errors.New("未开启邮箱验证") 43 | } 44 | if _, e := cache.Get(p.Email + "|codeLimit"); e { 45 | return errors.New("发送间隔太短,请稍后再试") 46 | } 47 | code := utils.GenRandomString(6) 48 | cache.Set(p.Email+"|code", code, time.Minute*5) 49 | cache.Set(p.Email+"|codeLimit", nil, time.Second*60) 50 | sendErr := mail.SendMail(p.Email, code) 51 | if sendErr != nil { 52 | return sendErr 53 | } 54 | c.JSON(200, gin.H{ 55 | "code": 200, 56 | "msg": "发送成功", 57 | }) 58 | return nil 59 | } 60 | 61 | func Register(c *gin.Context) error { 62 | params := &request.Register{} 63 | if err := c.ShouldBind(params); err != nil { 64 | return err 65 | } 66 | if conf.Config.EnableMailVerify { 67 | code := c.PostForm("code") 68 | if savedCode, e := cache.Get(code + "|code"); !e || savedCode.(string) != code { 69 | return errors.New("验证码不正确或已失效") 70 | } 71 | } 72 | registerErr := data.CreateUser(params.Email, params.Email, params.Password, 0) 73 | if registerErr != nil { 74 | return registerErr 75 | } 76 | c.JSON(200, gin.H{ 77 | "code": 200, 78 | "msg": "注册成功", 79 | }) 80 | return nil 81 | } 82 | 83 | func ChangeEmail(c *gin.Context) error { 84 | params := &request.ChangeUsername{} 85 | if err := c.ShouldBind(params); err != nil { 86 | return err 87 | } 88 | err := data.ChangeEmail(params.OldEmail, params.NewEmail, params.Password) 89 | if err != nil { 90 | return err 91 | } 92 | Logout(c) 93 | if c.IsAborted() { 94 | return nil 95 | } 96 | c.JSON(200, gin.H{ 97 | "code": 200, 98 | "msg": "修改成功", 99 | }) 100 | return nil 101 | } 102 | 103 | func ChangePassword(c *gin.Context) error { 104 | username := c.GetString("email") 105 | params := &request.ChangePassword{} 106 | if err := c.ShouldBind(params); err != nil { 107 | return err 108 | } 109 | changeErr := data.ChangeUserPassword(username, params.OldPassword, params.NewPassword) 110 | if changeErr != nil { 111 | c.JSON(400, gin.H{ 112 | "code": 400, 113 | "msg": changeErr.Error(), 114 | }) 115 | } 116 | err := Logout(c) 117 | if err != nil { 118 | return err 119 | } 120 | c.JSON(200, gin.H{ 121 | "code": 200, 122 | "msg": "修改成功", 123 | }) 124 | return nil 125 | } 126 | 127 | func GetUserInfo(c *gin.Context) { 128 | email := c.GetString("email") 129 | c.JSON(200, gin.H{ 130 | "code": 200, 131 | "msg": "获取成功", 132 | "data": email, 133 | }) 134 | } 135 | 136 | func Logout(c *gin.Context) error { 137 | err := delLoginSession(c) 138 | if err != nil { 139 | return err 140 | } 141 | c.JSON(200, gin.H{ 142 | "code": 200, 143 | "msg": "退出成功", 144 | }) 145 | return nil 146 | } 147 | 148 | func IsAdmin(c *gin.Context) { 149 | email := c.GetString("email") 150 | if data.IsAdmin(email) { 151 | c.JSON(200, gin.H{ 152 | "code": 200, 153 | "msg": true, 154 | }) 155 | } 156 | c.JSON(200, gin.H{ 157 | "code": 200, 158 | "msg": false, 159 | }) 160 | } 161 | 162 | func DeleteUser(c *gin.Context) error { 163 | params := &request.DeleteUser{} 164 | if err := c.ShouldBind(params); err != nil { 165 | return err 166 | } 167 | err := data.DeleteUser(params.Email) 168 | if err != nil { 169 | return err 170 | } 171 | c.JSON(200, gin.H{ 172 | "code": 200, 173 | "msg": "删除成功", 174 | }) 175 | return nil 176 | } 177 | 178 | func BanUser(c *gin.Context) error { 179 | params := &request.BanUser{} 180 | if err := c.ShouldBind(params); err != nil { 181 | return err 182 | } 183 | err := data.BanUser(params.Email) 184 | if err != nil { 185 | return err 186 | } 187 | c.JSON(200, gin.H{ 188 | "code": 200, 189 | "msg": "封禁成功", 190 | }) 191 | return nil 192 | } 193 | 194 | func UnBanUser(c *gin.Context) error { 195 | params := &request.BanUser{} 196 | if err := c.ShouldBind(params); err != nil { 197 | return err 198 | } 199 | err := data.UnBanUser(params.Email) 200 | if err != nil { 201 | return err 202 | } 203 | c.JSON(200, gin.H{ 204 | "code": 200, 205 | "msg": "解封成功", 206 | }) 207 | return nil 208 | } 209 | 210 | func GetUserList(c *gin.Context) error { 211 | list, listErr := data.GetUserList() 212 | if listErr != nil { 213 | return listErr 214 | } 215 | c.JSON(200, gin.H{ 216 | "code": 200, 217 | "data": list, 218 | }) 219 | return nil 220 | } 221 | -------------------------------------------------------------------------------- /data/data.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "fmt" 5 | "github.com/Yuzuki616/Aws-Panel/utils" 6 | log "github.com/sirupsen/logrus" 7 | "gorm.io/driver/sqlite" 8 | "gorm.io/gorm" 9 | "gorm.io/gorm/logger" 10 | ) 11 | 12 | var client *gorm.DB 13 | 14 | func Init(path string) error { 15 | if utils.IsNotFound(path) { 16 | defer func() { 17 | log.Info("Create default admin") 18 | err := CreateUser("admin", "admin@admin.com", "admin", 1) 19 | if err != nil { 20 | log.Error("Create user error: ", err) 21 | return 22 | } 23 | log.Info("Done. account: admin password: admin123456") 24 | }() 25 | } 26 | db, openErr := gorm.Open(sqlite.Open(path), 27 | &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)}) 28 | if openErr != nil { 29 | return fmt.Errorf("open db error: %v", openErr) 30 | } 31 | err := db.AutoMigrate(UserData{}, AwsSecret{}) 32 | if err != nil { 33 | return fmt.Errorf("AutoMigrate error: %v", err) 34 | } 35 | client = db 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /data/secret.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "errors" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | type AwsSecret struct { 9 | gorm.Model 10 | UserId uint `gorm:"column:UserId"` 11 | Name string `gorm:"column:Name"` 12 | SecretId string `gorm:"column:SecretId"` 13 | Secret string `gorm:"column:Secret"` 14 | } 15 | 16 | func AddSecret(email string, name, Id, Secret string) error { 17 | user := UserData{} 18 | secret := AwsSecret{} 19 | client.Where("Email = ?", email).First(&user) 20 | if user.ID == 0 { 21 | return errors.New("用户不存在") 22 | } 23 | client.Where("UserId = ? and Name = ?", user.ID, name).First(&secret) 24 | if secret.ID != 0 { 25 | return errors.New("密钥已存在") 26 | } 27 | client.Create(&AwsSecret{ 28 | Name: name, 29 | SecretId: Id, 30 | Secret: Secret, 31 | UserId: user.ID, 32 | }) 33 | return nil 34 | } 35 | 36 | func ListSecret(email string) ([]AwsSecret, error) { 37 | var user UserData 38 | var secrets []AwsSecret 39 | client.Where("Email = ?", email).First(&user) 40 | if user.ID == 0 { 41 | return nil, errors.New("用户不存在") 42 | } 43 | client.Where("UserId = ?", user.ID).Find(&secrets) 44 | return secrets, nil 45 | } 46 | 47 | func DelSecret(email string, name string) error { 48 | var user UserData 49 | var secret AwsSecret 50 | client.Where("Email = ?", email).First(&user) 51 | if user.ID == 0 { 52 | return errors.New("用户不存在") 53 | } 54 | client.Where("UserId = ? and Name = ?", user.ID, name).First(&secret) 55 | if secret.ID == 0 { 56 | return errors.New("密钥不存在") 57 | } 58 | client.Delete(&secret) 59 | return nil 60 | } 61 | 62 | func GetSecret(email string, name string) (*AwsSecret, error) { 63 | var user UserData 64 | var secret AwsSecret 65 | client.Where("Email = ?", email).First(&user) 66 | if user.ID == 0 { 67 | return nil, errors.New("用户不存在") 68 | } 69 | client.Where("UserId = ? and Name = ?", user.ID, name).First(&secret) 70 | if secret.ID == 0 { 71 | return nil, errors.New("密钥不存在") 72 | } 73 | return &secret, nil 74 | } 75 | -------------------------------------------------------------------------------- /data/user.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "errors" 5 | "github.com/Yuzuki616/Aws-Panel/utils" 6 | _ "github.com/mattn/go-sqlite3" 7 | "gorm.io/gorm" 8 | ) 9 | 10 | type UserData struct { 11 | gorm.Model 12 | Status int `gorm:"column:Status"` //0 正常,1 封禁 13 | Email string `gorm:"column:Email"` 14 | Password string `gorm:"column:Password"` 15 | IsAdmin int `gorm:"column:IsAdmin"` //0 否,1 是 16 | } 17 | 18 | func VerifyUser(email string, Password string) error { 19 | var user UserData 20 | client.Where("Email = ?", email).First(&user) 21 | if user.ID == 0 || !utils.VerifyPasswordHash(Password, user.Password) { 22 | return errors.New("用户名或密码错误") 23 | } 24 | if user.Status == 1 { 25 | return errors.New("用户已封禁") 26 | } 27 | return nil 28 | } 29 | 30 | func CreateUser(email, Email, Password string, IsAdmin int) error { 31 | var user UserData 32 | client.Where("Email = ?", email).First(&user) 33 | if user.ID != 0 { 34 | return errors.New("用户已存在") 35 | } 36 | user.Email = email 37 | user.Email = Email 38 | Password, err := utils.GenPasswordHash(Password) 39 | if err != nil { 40 | return err 41 | } 42 | user.Password = Password 43 | user.Status = 0 44 | user.IsAdmin = IsAdmin 45 | client.Create(&user) 46 | return nil 47 | } 48 | 49 | func ChangeEmail(oldEmail, newEmail, Password string) error { 50 | var user UserData 51 | client.Where("Email = ?", oldEmail).First(&user) 52 | if user.ID == 0 || !utils.VerifyPasswordHash(Password, user.Password) { 53 | return errors.New("用户名或密码错误") 54 | } 55 | user.Email = newEmail 56 | client.Save(&user) 57 | return nil 58 | } 59 | 60 | func ChangeUserPassword(email string, oldPassword, newPassword string) error { 61 | var user UserData 62 | client.Where("Email = ?", email).First(&user) 63 | if user.ID == 0 { 64 | return errors.New("用户不存在或密码错误") 65 | } 66 | if !utils.VerifyPasswordHash(oldPassword, user.Password) { 67 | return errors.New("用户不存在或密码错误") 68 | } 69 | hash, _ := utils.GenPasswordHash(newPassword) 70 | user.Password = hash 71 | client.Save(&user) 72 | return nil 73 | } 74 | 75 | func IsAdmin(email string) bool { 76 | var user UserData 77 | client.Where("Email = ?", email).First(&user) 78 | if user.ID == 0 { 79 | return false 80 | } 81 | if user.IsAdmin == 1 { 82 | return true 83 | } 84 | return false 85 | } 86 | 87 | func DeleteUser(email string) error { 88 | var user UserData 89 | client.Where("Email = ?", email).First(&user) 90 | if user.ID == 0 { 91 | return errors.New("用户不存在") 92 | } 93 | if user.IsAdmin == 1 { 94 | return errors.New("不能删除管理员账户") 95 | } 96 | client.Delete(&user) 97 | return nil 98 | } 99 | 100 | func BanUser(email string) error { 101 | var user UserData 102 | client.Where("Email = ?", email).First(&user) 103 | if user.ID == 0 { 104 | return errors.New("用户不存在") 105 | } 106 | if user.IsAdmin == 1 { 107 | return errors.New("不能封禁管理员账户") 108 | } 109 | if user.Status == 0 { 110 | user.Status = 1 111 | client.Save(&user) 112 | } else { 113 | return errors.New("该用户已被封禁") 114 | } 115 | return nil 116 | } 117 | 118 | func UnBanUser(email string) error { 119 | var user UserData 120 | client.Where("Email = ?", email).First(&user) 121 | if user.ID == 0 { 122 | return errors.New("用户不存在") 123 | } 124 | if user.IsAdmin == 1 { 125 | return errors.New("不能解封管理员账户") 126 | } 127 | if user.Status == 1 { 128 | user.Status = 0 129 | client.Save(&user) 130 | } else { 131 | return errors.New("该用户未被封禁") 132 | } 133 | return nil 134 | } 135 | 136 | type UserInfo struct { 137 | Email string 138 | Status int 139 | IsAdmin int 140 | } 141 | 142 | func GetUserList() ([]UserInfo, error) { 143 | var u []UserData 144 | client.Find(&u) 145 | if len(u) == 0 { 146 | return nil, errors.New("未找到任何用户") 147 | } 148 | var users []UserInfo 149 | for i := range u { 150 | users = append(users, UserInfo{ 151 | Email: u[i].Email, 152 | Status: u[i].Status, 153 | IsAdmin: u[i].IsAdmin, 154 | }) 155 | } 156 | return users, nil 157 | } 158 | -------------------------------------------------------------------------------- /example/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "LogLevel": "error", 3 | "Addr": ":8011", 4 | "DbPath": "./data.db", 5 | "LoadStatic": true, 6 | "StaticPath": "./web", 7 | "EnableMailVerify": false, 8 | "MailConfig": { 9 | "Host": "smtp.qq.com", 10 | "Port": 465, 11 | "Email": "a@qq.com", 12 | "Password": "12321" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Yuzuki616/Aws-Panel 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.43.17 7 | github.com/gin-contrib/cors v1.3.1 8 | github.com/gin-contrib/sessions v0.0.4 9 | github.com/gin-gonic/gin v1.7.7 10 | github.com/mattn/go-sqlite3 v1.14.12 11 | github.com/patrickmn/go-cache v2.1.0+incompatible 12 | github.com/sirupsen/logrus v1.8.1 13 | github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 14 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 15 | gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df 16 | gorm.io/driver/sqlite v1.3.1 17 | gorm.io/gorm v1.23.2 18 | ) 19 | 20 | require ( 21 | github.com/gin-contrib/sse v0.1.0 // indirect 22 | github.com/go-playground/locales v0.13.0 // indirect 23 | github.com/go-playground/universal-translator v0.17.0 // indirect 24 | github.com/go-playground/validator/v10 v10.4.1 // indirect 25 | github.com/golang/protobuf v1.3.3 // indirect 26 | github.com/gorilla/context v1.1.1 // indirect 27 | github.com/gorilla/securecookie v1.1.1 // indirect 28 | github.com/gorilla/sessions v1.2.0 // indirect 29 | github.com/jinzhu/inflection v1.0.0 // indirect 30 | github.com/jinzhu/now v1.1.4 // indirect 31 | github.com/jmespath/go-jmespath v0.4.0 // indirect 32 | github.com/json-iterator/go v1.1.9 // indirect 33 | github.com/leodido/go-urn v1.2.0 // indirect 34 | github.com/mattn/go-isatty v0.0.12 // indirect 35 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect 36 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect 37 | github.com/ugorji/go/codec v1.1.7 // indirect 38 | golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect 39 | gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect 40 | gopkg.in/yaml.v2 v2.2.8 // indirect 41 | ) 42 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw= 2 | github.com/aws/aws-sdk-go v1.43.17 h1:jDPBz1UuTxmyRo0eLgaRiro0fiI1zL7lkscqYxoEDLM= 3 | github.com/aws/aws-sdk-go v1.43.17/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= 4 | github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw= 5 | github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= 6 | github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1/go.mod h1:dkChI7Tbtx7H1Tj7TqGSZMOeGpMP5gLHtjroHd4agiI= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 9 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA= 11 | github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= 12 | github.com/gin-contrib/sessions v0.0.4 h1:gq4fNa1Zmp564iHP5G6EBuktilEos8VKhe2sza1KMgo= 13 | github.com/gin-contrib/sessions v0.0.4/go.mod h1:pQ3sIyviBBGcxgyR8mkeJuXbeV3h3NYmhJADQTq5+Vo= 14 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 15 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 16 | github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= 17 | github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= 18 | github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= 19 | github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= 20 | github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= 21 | github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= 22 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 23 | github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= 24 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 25 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 26 | github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= 27 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 28 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 29 | github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= 30 | github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= 31 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 32 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 33 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 34 | github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= 35 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 36 | github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= 37 | github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= 38 | github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= 39 | github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= 40 | github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= 41 | github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= 42 | github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= 43 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 44 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 45 | github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= 46 | github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 47 | github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= 48 | github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= 49 | github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= 50 | github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= 51 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 52 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= 53 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 54 | github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b/go.mod h1:g2nVr8KZVXJSS97Jo8pJ0jgq29P6H7dG0oplUA86MQw= 55 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 56 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 57 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 58 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 59 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 60 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 61 | github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= 62 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 63 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 64 | github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= 65 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 66 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 67 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 68 | github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= 69 | github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0= 70 | github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= 71 | github.com/memcachier/mc v2.0.1+incompatible/go.mod h1:7bkvFE61leUBvXz+yxsOnGBQSZpBSPIMUQSmmSHvuXc= 72 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= 73 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 74 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= 75 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 76 | github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= 77 | github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= 78 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 79 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 80 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 81 | github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b/go.mod h1:wTPjTepVu7uJBYgZ0SdWHQlIas582j6cn2jgk4DDdlg= 82 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 83 | github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= 84 | github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= 85 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 86 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 87 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 88 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 89 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 90 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 91 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 92 | github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= 93 | github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA= 94 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 95 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 96 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 97 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 98 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= 99 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 100 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 101 | golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 102 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 103 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 104 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 105 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 106 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 107 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 108 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 109 | golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= 110 | golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 111 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 112 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 113 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 114 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 115 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 116 | gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk= 117 | gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= 118 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 119 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 120 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 121 | gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= 122 | gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= 123 | gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE= 124 | gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= 125 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 126 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 127 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 128 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 129 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 130 | gorm.io/driver/sqlite v1.3.1 h1:bwfE+zTEWklBYoEodIOIBwuWHpnx52Z9zJFW5F33WLk= 131 | gorm.io/driver/sqlite v1.3.1/go.mod h1:wJx0hJspfycZ6myN38x1O/AqLtNS6c5o9TndewFbELg= 132 | gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= 133 | gorm.io/gorm v1.23.2 h1:xmq9QRMWL8HTJyhAUBXy8FqIIQCYESeKfJL4DoGKiWQ= 134 | gorm.io/gorm v1.23.2/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= 135 | -------------------------------------------------------------------------------- /mail/mail.go: -------------------------------------------------------------------------------- 1 | package mail 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/conf" 5 | "gopkg.in/gomail.v2" 6 | "strings" 7 | ) 8 | 9 | const tmpl = "\n \n \n \n \n \n \n \n \n {{$name}}\n \n \n \n \n 邮箱验证码\n \n \n \n 尊敬的用户您好!\n \n \n 您的验证码是:{{$code}},请在 5 分钟内进行验证。如果该验证码不为您本人申请,请无视。\n \n \n \n \n \n \n \n \n \n \n \n AWS-Panel\n \n \n \n \n \n \n \n" 10 | 11 | var mail *gomail.Dialer 12 | 13 | func Init() { 14 | if !conf.Config.EnableMailVerify { 15 | return 16 | } 17 | c := conf.Config.MailConfig 18 | mail = gomail.NewDialer(c.Host, c.Port, c.Email, c.Password) 19 | } 20 | 21 | func SendMail(to, code string) error { 22 | m := gomail.NewMessage() 23 | m.SetHeader("From", conf.Config.MailConfig.Email) 24 | m.SetHeader("To", to) 25 | m.SetHeader("Subject", "邮件验证码") 26 | m.SetBody("text/html", strings.ReplaceAll(tmpl, 27 | "{{$code}}", code)) 28 | err := mail.DialAndSend(m) 29 | if err != nil { 30 | return err 31 | } 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /mail/mail_test.go: -------------------------------------------------------------------------------- 1 | package mail 2 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/Yuzuki616/Aws-Panel/conf" 6 | "github.com/Yuzuki616/Aws-Panel/data" 7 | "github.com/Yuzuki616/Aws-Panel/mail" 8 | "github.com/Yuzuki616/Aws-Panel/router" 9 | "github.com/Yuzuki616/Aws-Panel/utils" 10 | log "github.com/sirupsen/logrus" 11 | easy "github.com/t-tomalak/logrus-easy-formatter" 12 | "time" 13 | ) 14 | 15 | var config = flag.String("config", ".config.json", "config file path") 16 | var ver = flag.Bool("version", false, "print version message") 17 | 18 | var ( 19 | // use ld flags replace 20 | version = "master" 21 | commit = "none" 22 | buildDate = "none" 23 | ) 24 | 25 | func printVersion() { 26 | log.Info("Aws Panel") 27 | log.Info("Version: ", version) 28 | log.Info("Commit: ", commit) 29 | log.Info("Build Date: ", buildDate) 30 | log.Info("Github: https://github.com/Yuzuki616/AWS-Panel") 31 | } 32 | 33 | func main() { 34 | log.SetFormatter(&easy.Formatter{ 35 | TimestampFormat: "01-02 15:04:05", 36 | LogFormat: "Aws-Panel | %time% | %lvl% >> %msg% \n", 37 | }) 38 | printVersion() 39 | if *ver { 40 | return 41 | } 42 | err := conf.Init("./config.json") 43 | if err != nil { 44 | log.Error("Init config error: ", err) 45 | } 46 | switch conf.Config.LogLevel { 47 | case "debug": 48 | log.SetLevel(log.DebugLevel) 49 | case "info": 50 | log.SetLevel(log.InfoLevel) 51 | case "warn": 52 | log.SetLevel(log.WarnLevel) 53 | case "error": 54 | log.SetLevel(log.ErrorLevel) 55 | } 56 | if utils.RunningByDoubleClick() { 57 | log.Warning("不建议直接双击运行本程序,这将导致一些非可预料后果,请通过控制台启动本程序") 58 | log.Warning("将等待10秒后启动") 59 | time.Sleep(time.Second * 10) 60 | } 61 | err = data.Init(conf.Config.DbPath) 62 | if err != nil { 63 | log.Error("Database init error: ", err) 64 | } 65 | mail.Init() 66 | router.Init() 67 | err = router.Start() 68 | if err != nil { 69 | log.Error(err) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /middleware/admin.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/data" 5 | "github.com/gin-gonic/gin" 6 | ) 7 | 8 | func AdminCheck(c *gin.Context) { 9 | username := c.GetString("email") 10 | if !data.IsAdmin(username) { 11 | c.JSON(403, gin.H{ 12 | "code": 403, 13 | "msg": "没有权限", 14 | }) 15 | c.Abort() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /middleware/user.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/cache" 5 | "github.com/gin-contrib/sessions" 6 | "github.com/gin-gonic/gin" 7 | "github.com/modern-go/reflect2" 8 | ) 9 | 10 | func UserCheck(c *gin.Context) { 11 | s := sessions.Default(c) 12 | id := s.Get("loginSession") 13 | if reflect2.IsNil(id) { 14 | c.JSON(401, gin.H{ 15 | "code": 401, 16 | "msg": "用户未登录", 17 | }) 18 | c.Abort() 19 | return 20 | } 21 | email, ok := cache.Get(id.(string)) 22 | if !ok { 23 | c.JSON(401, gin.H{ 24 | "code": 401, 25 | "msg": "用户未登录", 26 | }) 27 | c.Abort() 28 | return 29 | } 30 | c.Set("email", email) 31 | } 32 | -------------------------------------------------------------------------------- /request/ec2.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | type CreateEc2 struct { 4 | SecretName string `form:"secretName" binding:"required"` 5 | Region string `form:"region" binding:"required"` 6 | Ami string `form:"ami" binding:"required"` 7 | Ec2Type string `form:"ec2Type" binding:"required"` 8 | Ec2Name string `form:"ec2Name" binding:"required"` 9 | Disk int64 `form:"Disk" binding:"required"` 10 | Userdata string `form:"userdata" binding:"required"` 11 | } 12 | 13 | type ListEc2 struct { 14 | SecretName string `form:"secretName" binding:"required"` 15 | Region string `form:"region" binding:"required"` 16 | } 17 | 18 | type Ec2Action struct { 19 | SecretName string `form:"secretName" binding:"required"` 20 | Region string `form:"region" binding:"required"` 21 | Ec2Id string `form:"ec2Id" binding:"required"` 22 | } 23 | 24 | type CreateEc2SshKey struct { 25 | SecretName string `form:"secretName" binding:"required"` 26 | Region string `form:"region" binding:"required"` 27 | KeyName string `form:"keyName" binding:"required"` 28 | } 29 | 30 | type ListEc2SshKey struct { 31 | SecretName string `form:"secretName" binding:"required"` 32 | Region string `form:"region" binding:"required"` 33 | } 34 | type DeleteEc2SshKey struct { 35 | SecretName string `form:"secretName" binding:"required"` 36 | Region string `form:"region" binding:"required"` 37 | KeyName string `form:"keyName" binding:"required"` 38 | } 39 | -------------------------------------------------------------------------------- /request/lightsail.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | type GetRegions struct { 4 | SecretName string `form:"secretName" binding:"required"` 5 | } 6 | 7 | type CreateLightsail struct { 8 | Name string `form:"name" binding:"required"` 9 | Zone string `form:"zone" binding:"required"` 10 | AvailabilityZone string `form:"availabilityZone" binding:"required"` 11 | BlueprintId string `form:"blueprintId" binding:"required"` 12 | BundleId string `form:"bundleId" binding:"required"` 13 | SecretName string `form:"secretName" binding:"required"` 14 | } 15 | 16 | type OpenLightsailPorts struct { 17 | Zone string `form:"zone" binding:"required"` 18 | SecretName string `form:"secretName" binding:"required"` 19 | Name string `form:"name" binding:"required"` 20 | } 21 | 22 | type LightsailAction struct { 23 | Zone string `form:"zone" binding:"required"` 24 | SecretName string `form:"secretName" binding:"required"` 25 | Name string `form:"name" binding:"required"` 26 | } 27 | 28 | type DeleteLightsail struct { 29 | Zone string `form:"zone" binding:"required"` 30 | SecretName string `form:"secretName" binding:"required"` 31 | Name string `form:"name" binding:"required"` 32 | ResourceName string `form:"resourceName" binding:"required"` 33 | } 34 | -------------------------------------------------------------------------------- /request/secret.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | type AddSecret struct { 4 | Name string `form:"name" binding:"required"` 5 | Id string `form:"id" binding:"required"` 6 | Secret string `form:"secret" binding:"required"` 7 | } 8 | 9 | type GetSecret struct { 10 | Name string `form:"name" binding:"required"` 11 | } 12 | 13 | type DelSecret struct { 14 | Name string `form:"name" binding:"required"` 15 | } 16 | -------------------------------------------------------------------------------- /request/user.go: -------------------------------------------------------------------------------- 1 | package request 2 | 3 | type Login struct { 4 | Email string `form:"username" binding:"required"` 5 | Password string `form:"password" binding:"required"` 6 | } 7 | 8 | type Register struct { 9 | Email string `form:"username" binding:"required"` 10 | Password string `form:"password" binding:"required"` 11 | Code string `form:"code"` 12 | } 13 | 14 | type SendMailVerify struct { 15 | Email string `form:"email" binding:"required"` 16 | } 17 | 18 | type ChangeUsername struct { 19 | OldEmail string `form:"oldEmail" binding:"required"` 20 | NewEmail string `form:"newEmail" binding:"required"` 21 | Password string `form:"password" binding:"required"` 22 | } 23 | 24 | type ChangePassword struct { 25 | OldPassword string `form:"oldPassword" binding:"required"` 26 | NewPassword string `form:"newPassword" binding:"required"` 27 | } 28 | 29 | type BanUser struct { 30 | Email string `form:"username" binding:"required"` 31 | } 32 | 33 | type DeleteUser struct { 34 | Email string `form:"username" binding:"required"` 35 | } 36 | -------------------------------------------------------------------------------- /router/route.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/conf" 5 | "github.com/Yuzuki616/Aws-Panel/controller" 6 | "github.com/Yuzuki616/Aws-Panel/middleware" 7 | "github.com/gin-gonic/gin" 8 | "path" 9 | ) 10 | 11 | func LoadNormalRoute() { 12 | if conf.Config.EnableLoadStatic { 13 | //Page 14 | engine.Static("/js", path.Join(conf.Config.StaticPath, "js")) 15 | engine.Static("/css", path.Join(conf.Config.StaticPath, "css")) 16 | engine.Static("/img", path.Join(conf.Config.StaticPath, "img")) 17 | //engine.StaticFile("/","./web/index.html") 18 | engine.StaticFile("/favicon.ico", path.Join(conf.Config.StaticPath, "favicon.ico")) 19 | engine.NoRoute(func(c *gin.Context) { 20 | c.File(path.Join(conf.Config.StaticPath, "index.html")) 21 | }) 22 | } 23 | engine.GET("/api/v1/Config/IsEnableEmailVerify", controller.IsEnableEmailVerify) 24 | engine.POST("/api/v1/User/SendMailVerify", controller.ErrorHandle(controller.SendMailVerify)) 25 | engine.POST("/api/v1/User/Login", controller.ErrorHandle(controller.Login)) 26 | engine.POST("/api/v1/User/Register", controller.ErrorHandle(controller.Register)) 27 | } 28 | 29 | func LoadUserRoute() { 30 | user := engine.Group("/api/v1/") 31 | user.Use(middleware.UserCheck) 32 | user.POST("User/ChangeEmail", controller.ErrorHandle(controller.ChangeEmail)) 33 | user.POST("User/ChangePassword", controller.ErrorHandle(controller.ChangePassword)) 34 | user.GET("User/Info", controller.GetUserInfo) 35 | user.GET("User/Logout", controller.ErrorHandle(controller.Logout)) 36 | user.GET("User/IsAdmin", controller.IsAdmin) 37 | //Secret 38 | user.POST("Secret/Add", controller.ErrorHandle(controller.AddSecret)) 39 | user.GET("Secret/List", controller.ErrorHandle(controller.ListSecret)) 40 | user.POST("Secret/Delete", controller.ErrorHandle(controller.DelSecret)) 41 | user.POST("Secret/Info", controller.ErrorHandle(controller.GetSecret)) 42 | //Ec2 43 | user.POST("Ec2/Create", controller.ErrorHandle(controller.CreateEc2)) 44 | user.POST("Ec2/List", controller.ErrorHandle(controller.ListEc2)) 45 | user.POST("Ec2/Info", controller.ErrorHandle(controller.GetEc2Info)) 46 | user.POST("Ec2/ChangeIp", controller.ErrorHandle(controller.ChangeEc2Ip)) 47 | user.POST("Ec2/Stop", controller.ErrorHandle(controller.StopEc2)) 48 | user.POST("Ec2/Start", controller.ErrorHandle(controller.StartEc2)) 49 | user.POST("Ec2/Reboot", controller.ErrorHandle(controller.RebootEc2)) 50 | user.POST("Ec2/Delete", controller.ErrorHandle(controller.DeleteEc2)) 51 | user.POST("Ec2/CreateSshKey", controller.ErrorHandle(controller.CreateEc2SshKey)) 52 | user.POST("Ec2/ListSshKey", controller.ErrorHandle(controller.ListEc2SshKey)) 53 | user.POST("Ec2/DeleteSshKey", controller.ErrorHandle(controller.DeleteEc2SshKey)) 54 | //Lightsail 55 | user.POST("LightSail/GetRegions", controller.ErrorHandle(controller.GetRegions)) 56 | user.POST("LightSail/Create", controller.ErrorHandle(controller.CreateLightsail)) 57 | user.POST("LightSail/OpenPorts", controller.ErrorHandle(controller.OpenLightsailPorts)) 58 | user.POST("LightSail/GetBlueprintId") 59 | user.POST("LightSail/Info", controller.ErrorHandle(controller.GetLightsailInfo)) 60 | user.POST("LightSail/List", controller.ErrorHandle(controller.ListLightsail)) 61 | user.POST("LightSail/ChangeIp", controller.ErrorHandle(controller.ChangeLightsailIp)) 62 | user.POST("LightSail/Stop", controller.ErrorHandle(controller.StopLightsail)) 63 | user.POST("LightSail/Start", controller.ErrorHandle(controller.StartLightsail)) 64 | user.POST("LightSail/Reboot", controller.ErrorHandle(controller.RebootLightsail)) 65 | user.POST("LightSail/Delete", controller.ErrorHandle(controller.DeleteLightsail)) 66 | //Quota 67 | user.POST("Quota/Get") 68 | user.GET("Quota/ListChangeRequest") 69 | user.POST("Quota/ChangeQuota") 70 | } 71 | 72 | func LoadAdminRoute() { 73 | admin := engine.Group("/api/v1/") 74 | admin.Use(middleware.UserCheck, middleware.AdminCheck) 75 | //Admin Only 76 | admin.GET("User/List", controller.ErrorHandle(controller.GetUserList)) 77 | admin.POST("User/Delete", controller.ErrorHandle(controller.DeleteUser)) 78 | admin.POST("User/Ban", controller.ErrorHandle(controller.BanUser)) 79 | admin.POST("User/UnBan", controller.ErrorHandle(controller.UnBanUser)) 80 | } 81 | -------------------------------------------------------------------------------- /router/router.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/Yuzuki616/Aws-Panel/conf" 5 | "github.com/gin-contrib/cors" 6 | "github.com/gin-contrib/sessions" 7 | "github.com/gin-contrib/sessions/cookie" 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | var engine *gin.Engine 12 | 13 | func Init() { 14 | gin.SetMode(gin.ReleaseMode) 15 | engine = gin.Default() 16 | } 17 | 18 | func LoadRoute() { 19 | store := cookie.NewStore([]byte("loginSession")) 20 | /*store, err := redis.NewStore(10, "tcp", "127.0.0.1:6379", "", []byte("loginuser")) 21 | if err != nil { 22 | log.Error("Create session error: ", err) 23 | }*/ 24 | engine.Use(sessions.Sessions("loginSession", store)) 25 | config := cors.DefaultConfig() 26 | config.AllowOrigins = []string{"http://127.0.0.1:8080"} 27 | config.AllowCredentials = true 28 | engine.Use(cors.New(config)) 29 | LoadNormalRoute() 30 | LoadUserRoute() 31 | LoadAdminRoute() 32 | } 33 | 34 | func Start() error { 35 | LoadRoute() 36 | runErr := engine.Run(conf.Config.Addr) 37 | if runErr != nil { 38 | return runErr 39 | } 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /utils/doubleclick.go: -------------------------------------------------------------------------------- 1 | //go:build !windows 2 | 3 | package utils 4 | 5 | func RunningByDoubleClick() bool { 6 | return false 7 | } 8 | -------------------------------------------------------------------------------- /utils/doubleclick_win.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | 3 | package utils 4 | 5 | import ( 6 | "syscall" 7 | "unsafe" 8 | ) 9 | 10 | func RunningByDoubleClick() bool { 11 | kernel32 := syscall.NewLazyDLL("kernel32.dll") 12 | lp := kernel32.NewProc("GetConsoleProcessList") 13 | if lp != nil { 14 | var ids [2]uint32 15 | var maxCount uint32 = 2 16 | ret, _, _ := lp.Call(uintptr(unsafe.Pointer(&ids)), uintptr(maxCount)) 17 | if ret > 1 { 18 | return false 19 | } 20 | } 21 | return true 22 | } 23 | -------------------------------------------------------------------------------- /utils/file.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "os" 4 | 5 | func IsNotFound(path string) bool { 6 | _, err := os.Stat(path) 7 | if os.IsNotExist(err) { 8 | return true 9 | } else { 10 | return false 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /utils/password.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "golang.org/x/crypto/bcrypt" 5 | ) 6 | 7 | func GenPasswordHash(password string) (string, error) { 8 | bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10) 9 | return string(bytes), err 10 | } 11 | 12 | func VerifyPasswordHash(password, hash string) bool { 13 | err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) 14 | return err == nil 15 | } 16 | -------------------------------------------------------------------------------- /utils/password_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "testing" 4 | 5 | func TestGenPasswordHash(t *testing.T) { 6 | password := "test123" 7 | hash, err := GenPasswordHash(password) 8 | if err != nil { 9 | t.Error(err) 10 | } 11 | t.Log(hash) 12 | } 13 | 14 | func TestVerifyPasswordHash(t *testing.T) { 15 | password := "test123" 16 | hash := "$2a$10$BADuTsY.rYTQvp73yut7LuinBULy8.2TJdntEBv77wZNH5FU372J6" 17 | if VerifyPasswordHash(password, hash) { 18 | t.Log("ok") 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /utils/random.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "encoding/hex" 5 | "math/rand" 6 | ) 7 | 8 | func GenRandomString(size int) string { 9 | tmp := make([]byte, size) 10 | rand.Read(tmp) 11 | return hex.EncodeToString(tmp) 12 | } 13 | -------------------------------------------------------------------------------- /web/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | -------------------------------------------------------------------------------- /web/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /web/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /web/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /web/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /web/.idea/web.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /web/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aws-panel", 3 | "version": "0.3.6", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "core-js": "^3.6.5", 12 | "cors": "^2.8.5", 13 | "vue": "^2.6.11", 14 | "vue-cookie": "^1.1.4", 15 | "vue-meta": "^2.4.0", 16 | "vue-router": "^3.5.3", 17 | "vuetify": "^2.4.0" 18 | }, 19 | "devDependencies": { 20 | "@vue/cli-plugin-babel": "~4.5.0", 21 | "@vue/cli-plugin-eslint": "~4.5.0", 22 | "@vue/cli-service": "~4.5.0", 23 | "axios": "^0.18.1", 24 | "babel-eslint": "^10.1.0", 25 | "eslint": "^6.7.2", 26 | "eslint-plugin-vue": "^6.2.2", 27 | "sass": "~1.32.0", 28 | "sass-loader": "^10.0.0", 29 | "vue-cli-plugin-axios": "~0.0.4", 30 | "vue-cli-plugin-vuetify": "~2.4.5", 31 | "vue-template-compiler": "^2.6.11", 32 | "vuetify-loader": "^1.7.0" 33 | }, 34 | "eslintConfig": { 35 | "root": true, 36 | "env": { 37 | "node": true 38 | }, 39 | "extends": [ 40 | "plugin:vue/essential", 41 | "eslint:recommended" 42 | ], 43 | "parserOptions": { 44 | "parser": "babel-eslint" 45 | }, 46 | "rules": {} 47 | }, 48 | "browserslist": [ 49 | "> 1%", 50 | "last 2 versions", 51 | "not dead" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /web/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yuzuki616/AWS-Panel/f4f689e86cc7d0b57297203460fba29204fd697c/web/public/favicon.ico -------------------------------------------------------------------------------- /web/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | AWS Panel 9 | 10 | 11 | 12 | 13 | 14 | We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. 15 | Please enable it to continue. 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /web/src/App.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | mdi-home 13 | 14 | 主页|Home 15 | 16 | 17 | 18 | 19 | mdi-server 20 | 21 | 实例|Instances 22 | 23 | 24 | 30 | 31 | 32 | 33 | mdi-account-details 34 | 35 | 用户|User 36 | 37 | 38 | 39 | mdi-information-outline 40 | 41 | 管理 | Manger 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | mdi-aws 52 | AWS Panel 53 | 54 | 55 | 56 | 57 | 58 | 注册 59 | mdi-account-plus 60 | 61 | 62 | 用户 63 | mdi-account-details 64 | 65 | 66 | 67 | 登陆 68 | mdi-account-key 69 | 70 | 71 | 注销 72 | mdi-logout 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 130 | 131 | -------------------------------------------------------------------------------- /web/src/assets/aws.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yuzuki616/AWS-Panel/f4f689e86cc7d0b57297203460fba29204fd697c/web/src/assets/aws.png -------------------------------------------------------------------------------- /web/src/assets/jb_beam.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 25 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /web/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yuzuki616/AWS-Panel/f4f689e86cc7d0b57297203460fba29204fd697c/web/src/assets/logo.png -------------------------------------------------------------------------------- /web/src/components/lightsail.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lightsail实例 4 | Lightsail Instance 5 | 6 | 7 | 10 | 21 | 22 | 23 | 27 | 创建 28 | 29 | 33 | 34 | 35 | 创建Lightsail 36 | 37 | 38 | 39 | 40 | 41 | 44 | 50 | 51 | 52 | 58 | 59 | 62 | 69 | 70 | 73 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 92 | 取消 93 | 94 | 99 | 创建 100 | 101 | 102 | 103 | 104 | 108 | 109 | 110 | SSH密钥 111 | 112 | 113 | 114 | 115 | 116 | 117 | 122 | 复制 123 | 124 | 125 | 126 | 127 | 128 | 129 | 刷新 130 | 131 | 132 | 133 | 145 | 146 | 无任何实例 147 | 148 | 149 | 150 | 151 | 158 | mdi-shield-lock-open 159 | 160 | 161 | 开放端口 162 | 163 | 164 | 165 | 172 | mdi-play 173 | 174 | 175 | 启动 176 | 177 | 178 | 179 | 186 | mdi-stop 187 | 188 | 189 | 停止 190 | 191 | 192 | 193 | 194 | 201 | mdi-restart 202 | 203 | 204 | 重启 205 | 206 | 207 | 208 | 209 | 216 | mdi-delete 217 | 218 | 219 | 删除 220 | 221 | 222 | 223 | 224 | 225 | 226 | 229 | {{ messageText }} 230 | 231 | 232 | 238 | Close 239 | 240 | 241 | 242 | 243 | 247 | 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /web/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import router from './router' 4 | import vuetify from "./plugins/vuetify"; 5 | import vueMeta from 'vue-meta' 6 | import VueCookie from 'vue-cookie' 7 | 8 | //const VueCookie = require('') 9 | Vue.use(VueCookie,vueMeta) 10 | Vue.config.productionTip = false 11 | new Vue({ 12 | vuetify, 13 | router, 14 | render: h => h(App) 15 | }).$mount('#app') -------------------------------------------------------------------------------- /web/src/plugins/vuetify.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuetify from 'vuetify/lib/framework'; 3 | 4 | Vue.use(Vuetify); 5 | 6 | export default new Vuetify({ 7 | breakpoint: { 8 | mobileBreakpoint: 'sm' 9 | } 10 | }); -------------------------------------------------------------------------------- /web/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | import Home from '../views/Home.vue' 4 | import Login from '../views/Login' 5 | import Register from "../views/Register" 6 | import Instance from '../views/Instance' 7 | import User from '../views/User' 8 | import Manger from '../views/Manger' 9 | 10 | Vue.use(VueRouter) 11 | 12 | const routes = [ 13 | { 14 | path: '/', 15 | name: 'Home', 16 | component: Home 17 | }, 18 | { 19 | path: '/Login', 20 | name: 'Login', 21 | component: Login 22 | }, 23 | { 24 | path: '/Register', 25 | name: 'Register', 26 | component: Register 27 | }, 28 | { 29 | path: '/Instance', 30 | name: 'Instance', 31 | component: Instance, 32 | meta: { 33 | needLogin: true 34 | } 35 | }, 36 | { 37 | path: '/User', 38 | name: 'User', 39 | component: User, 40 | meta: { 41 | needLogin: true 42 | } 43 | }, 44 | { 45 | path: '/Manger', 46 | name: 'Manger', 47 | component: Manger, 48 | meta: { 49 | needLogin: true 50 | } 51 | } 52 | ] 53 | 54 | const router = new VueRouter({ 55 | mode: 'history', 56 | base: process.env.BASE_URL, 57 | routes 58 | }) 59 | 60 | function CheckCookie(name) { 61 | let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); 62 | return arr != null; 63 | } 64 | 65 | router.beforeEach((to, from, next) => { 66 | if (to.meta.needLogin) { 67 | if (CheckCookie("loginSession")) { 68 | next() 69 | } else { 70 | next({ 71 | path: '/login', 72 | }) 73 | } 74 | } else { 75 | next() 76 | } 77 | }); 78 | 79 | export default router -------------------------------------------------------------------------------- /web/src/utils/api.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export default axios.create({ 4 | baseURL: ``, 5 | withCredentials: true, 6 | validateStatus: function (status) { 7 | return status < 500; 8 | } 9 | }); -------------------------------------------------------------------------------- /web/src/utils/sleep.js: -------------------------------------------------------------------------------- 1 | function sleep (time) { 2 | return new Promise((resolve) => setTimeout(resolve, time)); 3 | } 4 | 5 | export default { 6 | sleep 7 | }; -------------------------------------------------------------------------------- /web/src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 欢迎使用AWS Panel 16 | 17 | 18 | 19 | 使用AWS Panel可以方便的管理AWS资源,比如EC2、Lightsail等。 20 | 21 | 22 | 23 | 27 | 28 | Thanks 29 | 30 | 31 | 32 | 39 | {{ link.text }} 40 | 41 | 42 | 43 | 感谢 JetBrains 为本项目提供的 WebStorm 和 Goland IDE的免费使用授权 46 | 47 | 48 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /web/src/views/Instance.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | Ec2实例 20 | 21 | 22 | Ec2 Instances 23 | 24 | 25 | 26 | 27 | 36 | 37 | 38 | 42 | 创建 43 | 44 | 48 | 49 | 50 | 创建Ec2 51 | 52 | 53 | 54 | 55 | 56 | 59 | 65 | 66 | 69 | 76 | 77 | 80 | 87 | 88 | 91 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 110 | 取消 111 | 112 | 117 | 创建 118 | 119 | 120 | 121 | 122 | 126 | 127 | 128 | SSH密钥 129 | 130 | 131 | 132 | 133 | 134 | 135 | 140 | 复制 141 | 142 | 143 | 144 | 145 | 146 | 147 | 刷新 148 | 149 | 150 | 151 | 163 | 164 | 无任何实例 165 | 166 | 167 | 168 | 169 | 176 | mdi-play 177 | 178 | 179 | 启动 180 | 181 | 182 | 183 | 184 | 191 | mdi-stop 192 | 193 | 194 | 停止 195 | 196 | 197 | 198 | 199 | 206 | mdi-restart 207 | 208 | 209 | 重启 210 | 211 | 212 | 213 | 220 | mdi-delete 221 | 222 | 223 | 删除 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 239 | 240 | 241 | 242 | 246 | 247 | 250 | {{ messageText }} 251 | 252 | 253 | 259 | Close 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | -------------------------------------------------------------------------------- /web/src/views/Login.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登陆 6 | Login 7 | 8 | 9 | 10 | 11 | 20 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 登陆 38 | 39 | 40 | 41 | 42 | 45 | {{ text }} 46 | 47 | 48 | 54 | Close 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /web/src/views/Manger.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 用户列表 7 | 8 | 9 | User List 10 | 11 | 12 | 13 | 14 | 83 | 84 | 刷新 85 | 86 | 87 | 88 | 99 | 100 | 无任何用户 101 | 102 | 103 | 104 | 105 | 112 | mdi-delete 113 | 114 | 115 | 删除 116 | 117 | 118 | 119 | 126 | mdi-lock 127 | 128 | 129 | 封禁 130 | 131 | 132 | 133 | 140 | mdi-lock-open 141 | 142 | 143 | 解封 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 157 | 158 | 161 | {{ messageText }} 162 | 163 | 169 | Close 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /web/src/views/Register.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 注册 6 | Register 7 | 8 | 9 | 10 | 11 | 12 | 21 | 22 | 23 | 24 | 33 | 34 | 35 | 40 | {{ codeBtnText }} 41 | 42 | 43 | 44 | 54 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 注册 71 | 72 | 73 | 74 | 75 | 76 | 79 | {{ text }} 80 | 81 | 87 | Close 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /web/src/views/User.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 用户中心 10 | 11 | 12 | User Center 13 | 14 | 15 | 欢迎回来,{{ email }} 16 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 修改密码 25 | 26 | 27 | Change Password 28 | 29 | 30 | 31 | 32 | 33 | 40 | 41 | 42 | 49 | 50 | 51 | 58 | 59 | 60 | 修改 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 70 | 71 | 72 | 密钥管理 73 | 74 | 75 | Secret Manger 76 | 77 | 78 | 79 | 80 | 81 | 82 | 86 | 添加 87 | 88 | 92 | 93 | 94 | 添加密钥 95 | 96 | 97 | 98 | 99 | 100 | 103 | 109 | 110 | 111 | 117 | 118 | 119 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 136 | 取消 137 | 138 | 144 | 添加 145 | 146 | 147 | 148 | 149 | 150 | 151 | 155 | 刷新 156 | 157 | 158 | 159 | 160 | 161 | 162 | 173 | 174 | 无任何密钥 175 | 176 | 177 | 178 | 179 | 186 | mdi-delete 187 | 188 | 189 | 删除 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 204 | 205 | 208 | {{ messageText }} 209 | 210 | 216 | Close 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | -------------------------------------------------------------------------------- /web/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transpileDependencies: [ 3 | 'vuetify' 4 | ] 5 | } --------------------------------------------------------------------------------
19 | 使用AWS Panel可以方便的管理AWS资源,比如EC2、Lightsail等。 20 |
感谢 JetBrains 为本项目提供的 WebStorm 和 Goland IDE的免费使用授权