commit 9915ef341388bea772f0f0825df73e67e44b6a26 Author: L. Bradley LaBoon Date: Fri Jan 10 00:24:59 2020 -0500 Initial commit. Implemented OAuth, Linodes, volumes, and images diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db97ce3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +clientID.js diff --git a/404.css b/404.css new file mode 100644 index 0000000..f72e727 --- /dev/null +++ b/404.css @@ -0,0 +1,37 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +body { + background-color: #F8F8F8; + text-align: center; +} + +fieldset { + background-color: #FFF; + border: 6px solid #999; + margin: 120px auto 10px; + padding: 15px; + width: 500px; +} + +h1 { + font-size: 60px; + font-weight: bold; + margin: 0; +} diff --git a/404.html b/404.html new file mode 100644 index 0000000..1d6b3f9 --- /dev/null +++ b/404.html @@ -0,0 +1,35 @@ + + + + + + LMC - 404 + + + + +
+

Whoops!

+

We couldn't find that page :(

+

+ It's possible this page hasn't been implemented yet.
+ You can check the development status here. +

+
+ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..33f4324 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +Full disclosure: I am an employee of Linode, however this project is being developed independently in my own free time and is not associated in any way with Linode, LLC. Only publicly-available documentation and information is being used in the development of this project. + +# Linode Manager Classic +LMC is a modern recreation of Linode's original manager interface that many people know and love. It is implemented as a client-side browser app using just vanilla HTML5, CSS3, and JavaScript (no 3rd-party libraries or other external dependencies). It uses Linode's OAuth provider for authentication and interfaces with APIv4. + +This app aims to be as faithful a recreation of the original manager as possible, making only minor adjustments to account for discrepancies between APIv4 and the original manager, to fix things which were blatantly broken in the original manager, or to add new functionality that was never present in the original manager. As an example, the original manager uses display groups for grouping Linodes together on the main page, however display groups are currently deprecated and will eventually be removed from APIv4, so instead LMC uses tags for this purpose (but this has the added advantage that you can apply multiple tags to a single Linode). + +The canonical deployment of this app can be found at https://lmc.laboon.io, however it is also possible (and easy) to self-host your own copy (see instructions below). + +## Development Progress +This project is currently a work in progress. The following list provides a high-level overview which features have been implemented and which features are planned for the future: + + - [x] OAuth Authentication/Login/Logout + - [x] Gravatar + - [x] Linodes (including the dashboard and all related subpages, but not including graphs) + - [x] Block Storage (Volumes) + - [x] Images + - [ ] Graphs + - [ ] StackScripts + - [ ] NodeBalancers + - [ ] Longview + - [ ] DNS + - [ ] Account Details + - [ ] User Profile Settings + - [ ] Support Tickets + +Eventually I plan to also implement features which were never available in the original manager, including Object Storage, One-Click Apps, and LKE. + +## Reporting Issues +Before reporting an issue, please search the issue tracker to see if the issue has already reported. The canonical source of this repository is located at https://git.bradleylaboon.com/lb.laboon/lmc. Any forks on any other websites (including GitHub) are unofficial. The issue tracker located at that address should be used for all bug reports. In some cases, the root cause of an issue might be due to features which are currently missing from Linode's APIv4 (for example, APIv4 does not expose which physical host a given Linode instance is running on, so it is not possible to display this information like the original manager did). In these cases I may close the issue and redirect you upstream to Linode. + +## Contributing +The best way to contribute is by opening issues on the issue tracker. For simple fixes or adjustments I might accept a PR, but for the time being I would prefer to maintain this project as a solo effort. I may change my mind in the future. + +## Self-hosting +In order to self-host this application, you must first create your own OAuth client using your existing Linode account (instructions for doing this in Linode's new manager can be found [here](https://github.com/linode/manager/blob/develop/CREATE_CLIENT.md)). When creating the OAuth client, use the URL where you will be hosting the app as the Callback URL. Then you can clone this repository into your webroot and copy the `clientID.js.example` file to `clientID.js` and fill in the empty string with your Client ID. You must ensure that Server Side Includes (SSI) is enabled in your web server. Optionally, you can configure your web server to use the `404.html` file as a custom error document. diff --git a/clientID.js.example b/clientID.js.example new file mode 100644 index 0000000..1033126 --- /dev/null +++ b/clientID.js.example @@ -0,0 +1,20 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +// Copy this file to clientID.js and fill in clientID with the OAuth client ID for this deployment +var clientID = ""; +export { clientID }; diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..c7eccdf Binary files /dev/null and b/favicon.ico differ diff --git a/global.css b/global.css new file mode 100644 index 0000000..724d015 --- /dev/null +++ b/global.css @@ -0,0 +1,239 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +a { + color: #0000CC; + text-decoration: none; +} + +#banner-buttons { + color: #0C0; + float: right; + font-size: 13px; + margin-top: 10px; +} + +#banner-buttons a:hover { + color: #FFF; +} + +#banner-buttons p { + display: inline; + margin: 0; + vertical-align: super; +} + +#banner-title { + font-size: 44px; + font-weight: bold; + letter-spacing: -.06em; + line-height: 70px; + text-shadow: 1px 1px 1px #57D66B; +} + +body { + background-color: #ECECEC; + font-family: Arial, Helvetica, sans-serif; + font-size: 15px; + margin: 0; +} + +button { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 14px; +} + +header { + background-color: #32AE4D; +} + +.info { + color: #777; +} + +#linode-tag { + display: none; +} + +#loading { + font-weight: bold; +} + +.lmc-table { + background-color: #CECECE; + width: 100%; +} + +.lmc-table tbody:not(.lmc-tbody-head) { + font-size: 13.3px; +} + +.lmc-table tbody.lmc-tbody-head tr:first-of-type { + font-weight: bold; +} + +.lmc-table tbody.lmc-tbody-head tr:nth-of-type(2) { + background-color: #EEE; + font-size: 14px; +} + +.lmc-table td { + padding: 0.4em; +} + +.lmc-table thead tr:first-of-type { + font-weight: bold; +} + +.lmc-table thead tr:nth-of-type(2) { + background-color: #EEE; + font-size: 14px; +} + +.lmc-tr1 { + background-color: #FFF; +} + +.lmc-tr2 { + background-color: #F4F4FF; +} + +.lmc-tr3 { + background-color: #FFF; + border-bottom: 1px solid #E8E8E8; +} + +#logout-link { + color: #6F6; +} + +#main-content { + background-color: #FFF; + box-shadow: 2px 2px 3px #BBB; + margin: 20px auto; +} + +#main-nav { + background-color: #222; + background-image: linear-gradient(#505050, #111); +} + +#nav-left { + display: inline-block; +} + +#nav-right { + display: inline-block; + float: right; +} + +.navlink { + color: #DDD; + display: inline-block; + line-height: 31px; + padding: 0px 15px; +} + +.navlink:hover { + color: #FFF; +} + +.navlink-active { + background-color: #ECECEC; + color: #000; + display: inline-block; + line-height: 31px; + padding: 0px 15px; +} + +.noshow { + display: none; +} + +.notification { + background: #FFDE4C; + margin: 0 0 20px; + padding: 5px; + text-align: center; +} + +.notification h1 { + font-size: 25px; +} + +#profile-link { + color: #DDD; +} + +#profile-pic { + border: 1px solid #FFF; + display: none; + height: 18px; + width: 18px; +} + +.sub-links { + font-size: 13.3px; + margin-bottom: 30px; + text-align: right; +} + +#subnav { + position: relative; + top: 20px; +} + +.subnav-link { + display: inline-block; + padding: 7px 10px; +} + +.subnav-link-active { + background-color: #FFF; + box-shadow: 2px -1px 1px #DDD; + color: #000; +} + +table { + border-collapse: collapse; +} + +#top-links { + padding: 15px; +} + +.top-links-title { + font-weight: bold; +} + +#username { + color: #000; + font-weight: bold; +} + +.warning { + background: #FFDE4C; + font-size: 16px; + margin-top: 0; + padding: 7px; + text-align: center; +} + +.wrapper { + margin: 0 auto; + width: 990px; +} diff --git a/global.js b/global.js new file mode 100644 index 0000000..b130a86 --- /dev/null +++ b/global.js @@ -0,0 +1,709 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +// Global default settings +var settings = { + "apiURL": "https://api.linode.com/v4", + "loginURL": "https://login.linode.com", + "oauthURL": "https://login.linode.com/oauth", + "preferredDistro": "linode/debian10", + "preferredKernel": "linode/grub2", + "refreshRate": 2000 +}; + +// Strings containing the names of various elements and CSS selectors +var elements = { + "navlink": "navlink", + "navlinkActive": "navlink-active", + "profilePic": "profile-pic", + "subnavLink": "subnav-link", + "subnavLinkActive": "subnav-link-active", + "username": "username" +}; + +// Regions (Linode doesn't provide "friendly" names via the API) +var regionNames = { + "us-central": "Dallas, TX, USA", + "us-west": "Fremont, CA, USA", + "us-southeast": "Atlanta, GA, USA", + "us-east": "Newark, NJ, USA", + "us-east-1b": "Newark 2, NJ, USA", + "eu-west": "London, England, UK", + "ap-south": "Singapore, SG", + "eu-central": "Frankfurt, DE", + "ap-northeast": "Tokyo, JP", + "ap-northeast-1a": "Tokyo 2, JP", + "ca-central": "Toronto, ON, CA", + "ap-west": "Mumbai, IN", + "ap-southeast": "Sydney, AU", + "philadelphia": "Philadelphia, PA, USA" +}; + +// Human-readable event titles +var eventTitles = { + "account_update": "Update Account", + "account_settings_update": "Update Account Settings", + "backups_enable": "Backups Enabled", + "backups_cancel": "Backups Cancelled", + "backups_restore": "Restore From Backup", + "community_question_reply": "Community Question Reply", + "community_like": "Community Like", + "credit_card_updated": "Update Credit Card", + "disk_create": "Create Disk", + "disk_delete": "Delete Disk", + "disk_update": "Update Disk", + "disk_duplicate": "Clone Disk", + "disk_imagize": "Create Image From Disk", + "disk_resize": "Resize Disk", + "dns_record_create": "Create DNS Record", + "dns_record_delete": "Delete DNS Record", + "dns_record_update": "Update DNS Record", + "dns_zone_create": "Create DNS Zone", + "dns_zone_delete": "Delete DNS Zone", + "dns_zone_import": "Import DNS Zone", + "dns_zone_update": "Update DNS Zone", + "host_reboot": "Host Initiated Restart", + "image_delete": "Delete Image", + "image_update": "Update Image", + "ipaddress_update": "Update IP Address", + "lassie_reboot": "Lassie Initiated Boot", + "lish_boot": "LISH Initiated Boot", + "linode_addip": "Add IP Address", + "linode_boot": "System Boot", + "linode_clone": "Clone Linode", + "linode_create": "Linode Initial Configuration", + "linode_delete": "Inactivate Linode", + "linode_update": "Update Linode", + "linode_deleteip": "Remove IP Address", + "linode_migrate": "Migrate Linode", + "linode_migrate_datacenter": "Migrate Linode", + "linode_migrate_datacenter_create": "Migrate Linode", + "linode_mutate": "Upgrade Linode", + "linode_mutate_create": "Upgrade Linode", + "linode_reboot": "System Reboot", + "linode_rebuild": "Rebuild Linode", + "linode_resize": "Resize Linode", + "linode_resize_create": "Resize Linode", + "linode_shutdown": "System Shutdown", + "linode_snapshot": "Linode Snapshot", + "linode_config_create": "Create Configuration Profile", + "linode_config_delete": "Delete Configuration Profile", + "linode_config_update": "Update Configuration Profile", + "managed_disabled": "Managed Service Disabled", + "managed_enabled": "Managed Service Enabled", + "managed_service_create": "Create Managed Service", + "managed_service_delete": "Delete Managed Service", + "nodebalancer_create": "NodeBalancer Initial Configuration", + "nodebalancer_delete": "Inactivate NodeBalancer", + "nodebalancer_update": "Update NodeBalancer", + "nodebalancer_config_create": "Create NodeBalancer Configuration", + "nodebalancer_config_delete": "Delete NodeBalancer Configuration", + "nodebalancer_config_update": "Update NodeBalancer Configuration", + "nodebalancer_node_create": "Create NodeBalancer Node", + "nodebalancer_node_delete": "Delete NodeBalancer Node", + "nodebalancer_node_update": "Update NodeBalancer Node", + "password_reset": "Change Root Password", + "payment_submitted": "Payment Submitted", + "profile_update": "Update Profile", + "stackscript_create": "Create StackScript", + "stackscript_delete": "Delete StackScript", + "stackscript_update": "Update StackScript", + "stackscript_publicize": "Publish StackScript", + "stackscript_revise": "Revise StackScript", + "tfa_disabled": "2FA Disabled", + "tfs_enabled": "2FA Enabled", + "ticket_attachment_upload": "Uploaded Ticket Attachment", + "ticket_create": "Create Ticket", + "ticket_update": "Update Ticket", + "user_ssh_key_add": "Add SSH Key", + "user_ssh_key_update": "Update SSH Key", + "vlan_attach": "Attach VLAN", + "vlan_detach": "Detach VLAN", + "volume_attach": "Attach Volume", + "volume_clone": "Clone Volume", + "volume_create": "Create Volume", + "volume_delete": "Delete Volume", + "volume_update": "Update Volume", + "volume_detach": "Detach Volume", + "volume_resize": "Resize Volume" +}; + +// Make an HTTP DELETE request to the Linode API +function apiDelete(endpoint, callback) +{ + // Redirect to login if there is no API key or it's expired + if (localStorage.apiKey && localStorage.apiExpire) { + var now = new Date(); + var expires = new Date(parseInt(localStorage.apiExpire)); + if (expires <= now) { + alert("Your session has expired."); + localStorage.removeItem("apiKey"); + localStorage.removeItem("apiExpire"); + location.href = "/?skip=1&redirectTo=" + encodeURIComponent(location.href); + return; + } + } else { + location.href = "/"; + return; + } + + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("DELETE", settings.apiURL + endpoint, true); + xmlhttp.setRequestHeader("Authorization", "Bearer " + localStorage.apiKey); + + xmlhttp.onreadystatechange = function() + { + if (xmlhttp.readyState != 4) + return; + + var response = JSON.parse(xmlhttp.responseText); + if (xmlhttp.status >= 400) { + console.log("Error " + xmlhttp.status); + console.log("DELETE " + settings.apiURL + endpoint); + if (response.errors) { + for (var i = 0; i < response.errors.length; i++) { + if (response.errors[i].field) + alert(response.errors[i].field + " " + response.errors[i].reason); + else + alert(response.errors[i].reason); + } + } + + // Redirect to login if invalid API key + if (xmlhttp.status == 401) { + localStorage.removeItem("apiKey"); + location.href = "/"; + } + + return; + } + + response['_endpoint'] = endpoint; + callback(response); + }; + + xmlhttp.send(); +} + +// Make an HTTP GET request to the Linode API +function apiGet(endpoint, callback, filters) +{ + // Redirect to login if there is no API key or it's expired + if (localStorage.apiKey && localStorage.apiExpire) { + var now = new Date(); + var expires = new Date(parseInt(localStorage.apiExpire)); + if (expires <= now) { + alert("Your session has expired."); + localStorage.removeItem("apiKey"); + localStorage.removeItem("apiExpire"); + location.href = "/?skip=1&redirectTo=" + encodeURIComponent(location.href); + return; + } + } else { + location.href = "/"; + return; + } + + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("GET", settings.apiURL + endpoint, true); + xmlhttp.setRequestHeader("Authorization", "Bearer " + localStorage.apiKey); + if (filters) + xmlhttp.setRequestHeader("X-Filter", JSON.stringify(filters)); + + xmlhttp.onreadystatechange = function() + { + if (xmlhttp.readyState != 4) + return; + + var response = JSON.parse(xmlhttp.responseText); + if (xmlhttp.status >= 400) { + console.log("Error " + xmlhttp.status); + console.log("GET " + settings.apiURL + endpoint); + if (response.errors) { + for (var i = 0; i < response.errors.length; i++) { + if (response.errors[i].field) + alert(response.errors[i].field + " " + response.errors[i].reason); + else + alert(response.errors[i].reason); + } + } + + // Redirect to login if invalid API key + if (xmlhttp.status == 401) { + localStorage.removeItem("apiKey"); + location.href = "/"; + } + + return; + } + + response['_endpoint'] = endpoint; + callback(response); + }; + + xmlhttp.send(); +} + +// Make an HTTP POST request to the Linode API +function apiPost(endpoint, data, callback) +{ + // Redirect to login if there is no API key or it's expired + if (localStorage.apiKey && localStorage.apiExpire) { + var now = new Date(); + var expires = new Date(parseInt(localStorage.apiExpire)); + if (expires <= now) { + alert("Your session has expired."); + localStorage.removeItem("apiKey"); + localStorage.removeItem("apiExpire"); + location.href = "/?skip=1&redirectTo=" + encodeURIComponent(location.href); + return; + } + } else { + location.href = "/"; + return; + } + + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("POST", settings.apiURL + endpoint, true); + xmlhttp.setRequestHeader("Authorization", "Bearer " + localStorage.apiKey); + xmlhttp.setRequestHeader("Content-Type", "application/json"); + + xmlhttp.onreadystatechange = function() + { + if (xmlhttp.readyState != 4) + return; + + var response = JSON.parse(xmlhttp.responseText); + if (xmlhttp.status >= 400) { + console.log("Error " + xmlhttp.status); + console.log("POST " + settings.apiURL + endpoint); + if (response.errors) { + for (var i = 0; i < response.errors.length; i++) { + if (response.errors[i].field) + alert(response.errors[i].field + " " + response.errors[i].reason); + else + alert(response.errors[i].reason); + } + } + + // Redirect to login if invalid token + if (xmlhttp.status == 401) { + localStorage.removeItem("apiKey"); + location.href = "/"; + } + + return; + } + + response['_endpoint'] = endpoint; + callback(response); + }; + + xmlhttp.send(JSON.stringify(data)); +} + +// Make an HTTP PUT request to the Linode API +function apiPut(endpoint, data, callback) +{ + // Redirect to login if there is no API key or it's expired + if (localStorage.apiKey && localStorage.apiExpire) { + var now = new Date(); + var expires = new Date(parseInt(localStorage.apiExpire)); + if (expires <= now) { + alert("Your session has expired."); + localStorage.removeItem("apiKey"); + localStorage.removeItem("apiExpire"); + location.href = "/?skip=1&redirectTo=" + encodeURIComponent(location.href); + return; + } + } else { + location.href = "/"; + return; + } + + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("PUT", settings.apiURL + endpoint, true); + xmlhttp.setRequestHeader("Authorization", "Bearer " + localStorage.apiKey); + xmlhttp.setRequestHeader("Content-Type", "application/json"); + + xmlhttp.onreadystatechange = function() + { + if (xmlhttp.readyState != 4) + return; + + var response = JSON.parse(xmlhttp.responseText); + if (xmlhttp.status >= 400) { + console.log("Error " + xmlhttp.status); + console.log("PUT " + settings.apiURL + endpoint); + if (response.errors) { + for (var i = 0; i < response.errors.length; i++) { + if (response.errors[i].field) + alert(response.errors[i].field + " " + response.errors[i].reason); + else + alert(response.errors[i].reason); + } + } + + // Redirect to login if invalid token + if (xmlhttp.status == 401) { + localStorage.removeItem("apiKey"); + location.href = "/"; + } + + return; + } + + response['_endpoint'] = endpoint; + callback(response); + }; + + xmlhttp.send(JSON.stringify(data)); +} + +// Callback for user info API call +function displayUser(response) +{ + if (!response) { + console.log("Error getting profile data"); + return; + } + + // Display username + var usernameTag = document.getElementById(elements.username); + usernameTag.innerHTML = response.username; + + // Display profile pic + var profilePic = document.getElementById(elements.profilePic); + profilePic.src = "https://www.gravatar.com/avatar/" + md5(response.email); + profilePic.style = "display: initial;"; +} + +// Return an MD5 hash of the given string +function md5(str) +{ + // Convert string to bytes + var data = new TextEncoder("utf-8").encode(str); + + // Constants + var s = new Uint32Array([ + 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, + 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, + 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, + 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 + ]); + + var K = new Uint32Array([ + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 + ]); + + // Initialize hash + var hash = new Uint32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]); + + // Apply padding + var padLength = data.length + 1; + while (padLength % 64 != 56) + padLength++; + padLength += 8; + + var padData = new Uint8Array(padLength); + for (var i = 0; i < data.length; i++) + padData[i] = data[i]; + for (var i = data.length; i < padLength; i++) + padData[i] = 0x0; + + // Append 1 bit + padData[data.length] = 0x80; + + // Append original length + var bits = data.length * 8; + var upperLen = parseInt(bits.toString(16).slice(0, -8), 16); + if (isNaN(upperLen)) + upperLen = 0; + padData[padLength-8] = bits; + padData[padLength-7] = bits >>> 8; + padData[padLength-6] = bits >>> 16; + padData[padLength-5] = bits >>> 24; + padData[padLength-4] = upperLen; + padData[padLength-3] = upperLen >>> 8; + padData[padLength-2] = upperLen >>> 16; + padData[padLength-1] = upperLen >>> 24; + + // Process the data in 64-byte chunks + for (var i = 0; i < padLength; i += 64) { + var M = new Uint32Array(16); + for (var j = 0, offset = i; j < 16; j++, offset += 4) + M[j] = padData[offset] + (padData[offset+1] << 8) + (padData[offset+2] << 16) + (padData[offset+3] << 24); + + // Main loop + var chunk = new Uint32Array(hash); + for (var j = 0; j < 64; j++) { + var locals = new Uint32Array(2); + if (j <= 15) { + locals[0] = (chunk[1] & chunk[2]) | ((~chunk[1]) & chunk[3]); + locals[1] = j; + } else if (j <= 31) { + locals[0] = (chunk[3] & chunk[1]) | ((~chunk[3]) & chunk[2]); + locals[1] = (5 * j + 1) % 16; + } else if (j <= 47) { + locals[0] = chunk[1] ^ chunk[2] ^ chunk[3]; + locals[1] = (3 * j + 5) % 16; + } else { + locals[0] = chunk[2] ^ (chunk[1] | (~chunk[3])); + locals[1] = (7 * j) % 16; + } + + locals[0] += chunk[0] + K[j] + M[locals[1]]; + chunk[0] = chunk[3]; + chunk[3] = chunk[2]; + chunk[2] = chunk[1]; + chunk[1] += rotl(locals[0], s[j]); + } + + // Add this chunk's hash to the main hash + hash[0] += chunk[0]; + hash[1] += chunk[1]; + hash[2] += chunk[2]; + hash[3] += chunk[3]; + } + + // Convert to string + var md5Str = ""; + for (var i = 0; i < 4; i++) { + var bytes = new Uint8Array([hash[i], hash[i] >> 8, hash[i] >> 16, hash[i] >> 24]); + for (var j = 0; j < 4; j++) { + if (bytes[j] < 0x10) + md5Str += "0"; + md5Str += bytes[j].toString(16); + } + } + + return md5Str; +} + +// Returns the ETA for a migration given the disk size (MB) and destination +function migrateETA(size, local) +{ + var str = ""; + + // Calculate minutes + var minutes = 0; + if (local) + minutes = (0.75 * size / 1024).toFixed(0); + else + minutes = (10 * size / 1024).toFixed(0); + + // Divide into hours + if (minutes >= 60) { + var hours = Math.floor(minutes / 60); + minutes = minutes % 60; + if (hours == 1) + hours = hours + " hour and "; + else + hours = hours + " hours and "; + str += hours; + } + + if (minutes == 1) + minutes = minutes + " minute"; + else + minutes = minutes + " minutes"; + + str += minutes; + return str; +} + +// Make an OAuth HTTP POST request +function oauthPost(endpoint, data, callback) +{ + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("POST", settings.oauthURL + endpoint, true); + xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + + xmlhttp.onreadystatechange = function() + { + if (xmlhttp.readyState != 4) + return; + + var response = JSON.parse(xmlhttp.responseText); + if (xmlhttp.status >= 400) { + console.log("Error " + xmlhttp.status); + console.log("POST " + settings.oauthURL + endpoint); + if (response.errors) { + for (var i = 0; i < response.errors.length; i++) { + if (response.errors[i].field) + alert(response.errors[i].field + " " + response.errors[i].reason); + else + alert(response.errors[i].reason); + } + } + + return; + } + + response['_endpoint'] = endpoint; + callback(response); + }; + + xmlhttp.send(data.toString()); +} + +// Parse URL parameters +function parseParams() +{ + var parsed = {}; + if (location.search.length > 1) + var params = new URLSearchParams(location.search.slice(1)); + else + var params = new URLSearchParams(location.hash.slice(1)); + + for (var pair of params.entries()) + parsed[pair[0]] = pair[1]; + + return parsed; +} + +// Bitwise left-rotate +function rotl(val, sft) +{ + return (val << sft) | (val >>> (32 - sft)); +} + +// Setup the page header +function setupHeader() +{ + // Highlight the current page in the navbar + var navlinks = document.getElementsByClassName(elements.navlink); + for (var i = 0; i < navlinks.length; i++) { + if ((location.origin + location.pathname).startsWith(navlinks[i].href)) + navlinks[i].className = navlinks[i].className.replace(elements.navlink, elements.navlinkActive); + } + + // Highlight the current page in the subnav + var subnavLinks = document.getElementsByClassName(elements.subnavLink); + for (var i = 0; i < subnavLinks.length; i++) { + if ((location.origin + location.pathname).startsWith(subnavLinks[i].href.split("?")[0])) + subnavLinks[i].className += " " + elements.subnavLinkActive; + } + + // Get user info + apiGet("/profile", displayUser, null); +} + +// Convert a millisecond count into a "friendly" time string +function timeString(ms, includeSuffix) +{ + // Future or past? + var suffix = ""; + if (includeSuffix) { + if (ms < 0) { + suffix = "from now"; + ms = -ms; + } else { + suffix = "ago"; + } + } + + // Break into units + var years = 0, days = 0, hours = 0, minutes = 0, seconds = 0; + while (ms >= 31536000000) { + ms -= 31536000000; + years++; + } + while (ms >= 86400000) { + ms -= 86400000; + days++; + } + while (ms >= 3600000) { + ms -= 3600000; + hours++; + } + while (ms >= 60000) { + ms -= 60000; + minutes++; + } + while (ms >= 1000) { + ms -= 1000; + seconds++; + } + + // Stringify + if (years == 1) + years = years + " year"; + else + years = years + " years"; + if (days == 1) + days = days + " day"; + else + days = days + " days"; + if (hours == 1) + hours = hours + " hour"; + else + hours = hours + " hours"; + if (minutes == 1) + minutes = minutes + " minute"; + else + minutes = minutes + " minutes"; + if (seconds == 1) + seconds = seconds + " second"; + else + seconds = seconds + " seconds"; + if (ms == 1) + ms = ms + " millisecond"; + else + ms = ms + " milliseconds"; + + // Return the final string + if (years[0] != "0") + return years + " " + days + " " + suffix; + if (days[0] != "0") + return days + " " + hours + " " + suffix; + if (hours[0] != "0") + return hours + " " + minutes + " " + suffix; + if (minutes[0] != "0") + return minutes + " " + seconds + " " + suffix; + if (seconds[0] != "0") + return seconds + " " + ms + " " + suffix; + return ms + " " + suffix; +} + +// Translates a kernel slug into a label and sets the contents of an element +function translateKernel(slug, element) +{ + var callback = function(response) + { + element.innerHTML = response.label; + }; + + apiGet("/linode/kernels/" + slug, callback, null); +} + +export { settings, elements, regionNames, apiDelete, apiGet, apiPost, apiPut, migrateETA, oauthPost, parseParams, setupHeader, eventTitles, timeString, translateKernel }; diff --git a/images/create/create.css b/images/create/create.css new file mode 100644 index 0000000..90808bc --- /dev/null +++ b/images/create/create.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#create { + padding: 0px 15px 15px; +} + +tbody tr:last-of-type { + border: none; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/images/create/create.js b/images/create/create.js new file mode 100644 index 0000000..a1cc525 --- /dev/null +++ b/images/create/create.js @@ -0,0 +1,155 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, apiPost, parseParams, setupHeader, timeString } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.createButton = "create-button"; + elements.description = "description"; + elements.diskLabel = "disk-label"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.nav = "navlink"; + elements.navActive = "navlink-active"; + elements.size = "size"; + elements.type = "type"; + + // Data recieved from API calls + var data = {}; + data.disk = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.createButton = {}; + ui.description = {}; + ui.diskLabel = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.size = {}; + ui.type = {}; + + // Create button handler + var handleCreate = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "disk_id": data.disk.id, + "label": ui.label.value + }; + if (ui.description.value.length) + req.description = ui.description.value; + + apiPost("/images", req, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + }; + + // Callback for image API call + var displayDisk = function(response) + { + data.disk = response; + + // Display disk label in page header + ui.diskLabel.innerHTML = data.disk.label; + + // Fill in details + ui.label.value = data.disk.label; + ui.type.innerHTML = data.disk.filesystem; + ui.size.innerHTML = data.disk.size; + ui.createButton.disabled = false; + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need an Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + // We also need a disk ID + if (!data.params.did) { + alert("No disk ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode and disk IDs + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) { + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + anchors[i].href = anchors[i].href.replace("did=0", "did=" + data.params.did); + } + + // Highlight the Linodes nav link + var navLinks = document.getElementsByClassName(elements.nav); + for (var i = 0; i < navLinks.length; i++) { + if (navLinks[i].pathname == "/linodes/") + navLinks[i].className = elements.navActive; + } + + // Get element references + ui.createButton = document.getElementById(elements.createButton); + ui.description = document.getElementById(elements.description); + ui.diskLabel = document.getElementById(elements.diskLabel); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.size = document.getElementById(elements.size); + ui.type = document.getElementById(elements.type); + + // Attach event handlers + ui.createButton.addEventListener("click", handleCreate); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/disks/" + data.params.did, displayDisk, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/images/create/index.shtml b/images/create/index.shtml new file mode 100644 index 0000000..4e4dcd0 --- /dev/null +++ b/images/create/index.shtml @@ -0,0 +1,68 @@ + + + + + + LMC - Create Image + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Image
LabelSee also: Using Linode Images
Type
Disk Size MB
Description
+
+
+ + diff --git a/images/delete/delete.css b/images/delete/delete.css new file mode 100644 index 0000000..3d81eb2 --- /dev/null +++ b/images/delete/delete.css @@ -0,0 +1,26 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#delete { + padding: 0px 15px 15px; +} + +#label { + font-weight: bold; +} diff --git a/images/delete/delete.js b/images/delete/delete.js new file mode 100644 index 0000000..73f0528 --- /dev/null +++ b/images/delete/delete.js @@ -0,0 +1,85 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, apiDelete, parseParams, setupHeader, timeString } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.deleteButton = "delete-button"; + elements.label = "label"; + elements.nav = "navlink"; + elements.navActive = "navlink-active"; + + // Data recieved from API calls + var data = {}; + + // Static references to UI elements + var ui = {}; + ui.deleteButton = {}; + ui.label = {}; + + // Callback for image API call + var displayImage = function(response) + { + ui.label.innerHTML = response.label; + }; + + // Handler for delete button + var handleDelete = function(event) + { + apiDelete("/images/" + data.params.iid, function(response) + { + location.href = "/images"; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need an image ID, so die if we don't have it + if (!data.params.iid) { + alert("No image ID supplied!"); + return; + } + + setupHeader(); + + // Highlight the Linodes nav link + var navLinks = document.getElementsByClassName(elements.nav); + for (var i = 0; i < navLinks.length; i++) { + if (navLinks[i].pathname == "/linodes/") + navLinks[i].className = elements.navActive; + } + + // Get element references + ui.deleteButton = document.getElementById(elements.deleteButton); + ui.label = document.getElementById(elements.label); + + // Attach event handlers + ui.deleteButton.addEventListener("click", handleDelete); + + // Get data from API + apiGet("/images/" + data.params.iid, displayImage, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/images/delete/index.shtml b/images/delete/index.shtml new file mode 100644 index 0000000..5892006 --- /dev/null +++ b/images/delete/index.shtml @@ -0,0 +1,36 @@ + + + + + + LMC - Delete Image + + + + + + +
+ +
+

Are you sure you want to delete the image ?

+ +
+
+ + diff --git a/images/edit/edit.css b/images/edit/edit.css new file mode 100644 index 0000000..bfb799b --- /dev/null +++ b/images/edit/edit.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#edit { + padding: 0px 15px 15px; +} + +table:first-of-type tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} + +tbody tr:last-of-type { + border: none; +} diff --git a/images/edit/edit.js b/images/edit/edit.js new file mode 100644 index 0000000..bc693e4 --- /dev/null +++ b/images/edit/edit.js @@ -0,0 +1,111 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, apiPut, parseParams, setupHeader, timeString } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.created = "created"; + elements.description = "description"; + elements.imageLabel = "image-label"; + elements.label = "label"; + elements.nav = "navlink"; + elements.navActive = "navlink-active"; + elements.saveButton = "save-button"; + elements.size = "size"; + + // Data recieved from API calls + var data = {}; + + // Static references to UI elements + var ui = {}; + ui.created = {}; + ui.description = {}; + ui.imageLabel = {}; + ui.label = {}; + ui.saveButton = {}; + ui.size = {}; + + // Callback for image API call + var displayImage = function(response) + { + ui.imageLabel.innerHTML = response.label; + ui.label.value = response.label; + var createDate = new Date(response.created + "Z"); + ui.created.innerHTML = createDate.toLocaleString(); + ui.size.innerHTML = response.size; + ui.description.value = response.description; + ui.saveButton.disabled = false; + }; + + // Handler for save button + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "label": ui.label.value, + "description": ui.description.value + }; + + apiPut("/images/" + data.params.iid, req, function(response) + { + location.href = "/images"; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need an image ID, so die if we don't have it + if (!data.params.iid) { + alert("No image ID supplied!"); + return; + } + + setupHeader(); + + // Highlight the Linodes nav link + var navLinks = document.getElementsByClassName(elements.nav); + for (var i = 0; i < navLinks.length; i++) { + if (navLinks[i].pathname == "/linodes/") + navLinks[i].className = elements.navActive; + } + + // Get element references + ui.created = document.getElementById(elements.created); + ui.description = document.getElementById(elements.description); + ui.imageLabel = document.getElementById(elements.imageLabel); + ui.label = document.getElementById(elements.label); + ui.saveButton = document.getElementById(elements.saveButton); + ui.size = document.getElementById(elements.size); + + // Attach event handlers + ui.saveButton.addEventListener("click", handleSave); + + // Get data from API + apiGet("/images/" + data.params.iid, displayImage, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/images/edit/index.shtml b/images/edit/index.shtml new file mode 100644 index 0000000..d5ea72a --- /dev/null +++ b/images/edit/index.shtml @@ -0,0 +1,68 @@ + + + + + + LMC - Edit Image + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Image
LabelSee also: Using Linode Images
Created
Size MB
Description
+
+
+ + diff --git a/images/images.css b/images/images.css new file mode 100644 index 0000000..59df3f1 --- /dev/null +++ b/images/images.css @@ -0,0 +1,26 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +table td:nth-of-type(6) { + text-align: right; +} + +#images { + padding: 0px 15px 15px; +} diff --git a/images/images.js b/images/images.js new file mode 100644 index 0000000..e4402a4 --- /dev/null +++ b/images/images.js @@ -0,0 +1,141 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, parseParams, setupHeader, timeString } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.lmcRow = "lmc-tr1"; + elements.lmcRowAlt = "lmc-tr2"; + elements.loading = "loading"; + elements.imageBody = "image-body"; + elements.nav = "navlink"; + elements.navActive = "navlink-active"; + + // Data recieved from API calls + var data = {}; + data.images = []; + + // Static references to UI elements + var ui = {}; + ui.loading = {}; + ui.imageBody = {}; + + // Generates a table row for an image + var createImageRow = function(image, alt) + { + var row = document.createElement("tr"); + if (alt) + row.className = elements.lmcRowAlt; + else + row.className = elements.lmcRow; + + var label = document.createElement("td"); + label.innerHTML = image.label; + row.appendChild(label); + + var size = document.createElement("td"); + size.innerHTML = image.size + " MB"; + row.appendChild(size); + + var type = document.createElement("td"); + type.innerHTML = image.type; + row.appendChild(type); + + var created = document.createElement("td"); + var now = new Date(); + var createDate = new Date(image.created + "Z"); + created.innerHTML = timeString(now - createDate, true); + row.appendChild(created); + + var expires = document.createElement("td"); + if (image.expiry) { + var expireDate = new Date(image.expiry + "Z"); + expires.innerHTML = timeString(now - expireDate, true); + } + row.appendChild(expires); + + var options = document.createElement("td"); + var edit = document.createElement("a"); + edit.href = "/images/edit?iid=" + image.id; + edit.innerHTML = "Edit"; + var separator = document.createElement("span"); + separator.innerHTML = " | "; + var del = document.createElement("a"); + del.href = "/images/delete?iid=" + image.id; + del.innerHTML = "Delete"; + options.appendChild(edit); + options.appendChild(separator); + options.appendChild(del); + row.appendChild(options); + + return row; + }; + + // Callback for images API call + var displayImages = function(response) + { + // Add images to array + data.images = data.images.concat(response.data); + + // Request + if (response.page != response.pages) { + var progress = (response.page / response.pages) * 100; + progress = progress.toFixed(0); + ui.loading.innerHTML = "Loading " + progress + "%..."; + var filter = { + "vendor": null + }; + apiGet("/images?page=" + (response.page + 1), displayImages, filter); + } + + // Insert images + ui.loading.remove(); + for (var i = 0; i < data.images.length; i++) + ui.imageBody.appendChild(createImageRow(data.images[i], i % 2)); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + setupHeader(); + + // Highlight the Linodes nav link + var navLinks = document.getElementsByClassName(elements.nav); + for (var i = 0; i < navLinks.length; i++) { + if (navLinks[i].pathname == "/linodes/") + navLinks[i].className = elements.navActive; + } + + // Get element references + ui.loading = document.getElementById(elements.loading); + ui.imageBody = document.getElementById(elements.imageBody); + + // Get data from API + var filter = { + "vendor": null + }; + apiGet("/images", displayImages, filter); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/images/index.shtml b/images/index.shtml new file mode 100644 index 0000000..7cbe6a2 --- /dev/null +++ b/images/index.shtml @@ -0,0 +1,51 @@ + + + + + + LMC - Linode Images + + + + + + +
+ +
+ + + + + + + + + + + + + + + + +
ImageSizeTypeCreatedExpires
Loading...
+
+
+ + diff --git a/img/disk.gif b/img/disk.gif new file mode 100644 index 0000000..23fd4b5 Binary files /dev/null and b/img/disk.gif differ diff --git a/img/spinner-trans.gif b/img/spinner-trans.gif new file mode 100644 index 0000000..82d06cc Binary files /dev/null and b/img/spinner-trans.gif differ diff --git a/include/header.html b/include/header.html new file mode 100644 index 0000000..c83d9ff --- /dev/null +++ b/include/header.html @@ -0,0 +1,27 @@ + +
+
+ + +
+
+ + diff --git a/include/linode_subnav.html b/include/linode_subnav.html new file mode 100644 index 0000000..ab72d4f --- /dev/null +++ b/include/linode_subnav.html @@ -0,0 +1,13 @@ + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..f9f5b5a --- /dev/null +++ b/index.html @@ -0,0 +1,35 @@ + + + + + + LMC - Login + + + + + +
+ Linode Manager Classic +
+ or
+ sign up +
+ Forgot username | Reset password | www.linode.com + + diff --git a/linodes/add/add.css b/linodes/add/add.css new file mode 100644 index 0000000..2e4cf63 --- /dev/null +++ b/linodes/add/add.css @@ -0,0 +1,98 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#add-button { + display: block; + font-size: 16px; + font-weight: bold; + margin: 0 auto; + padding: 5px; +} + +#datacenters { + font-size: 18px; + margin-top: 10px; +} + +h2 { + font-size: 18px; + margin: 0; +} + +h3 { + font-size: 16px; +} + +.instance-category { + padding-top: 10px; +} + +.instance-category p { + color: #808080; + font-size: 16px; +} + +.instance-type { + background-color: #F7F7F7; + border: 1px solid #DDD; + border-radius: 5px; + cursor: pointer; + display: inline-block; + margin: 10px; + padding: 10px; + text-align: center; + width: 135px; +} + +.instance-type h3 { + border-bottom: 1px solid #D4D4D4; + color: #333; + margin: 0; + padding-bottom: 2px; +} + +.instance-type p { + color: #666; + font-size: 13px; + margin: 10px 0px 0px 0px; +} + +.instance-type-active { + background-color: #5FABFF; +} + +.instance-type-active p { + color: #FFF; +} + +#instances { + padding: 15px; +} + +#location { + padding: 15px; +} + +#right-links { + float: right; +} + +#submit { + padding: 15px; +} diff --git a/linodes/add/add.js b/linodes/add/add.js new file mode 100644 index 0000000..a09b23f --- /dev/null +++ b/linodes/add/add.js @@ -0,0 +1,151 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.addButton = "add-button"; + elements.datacenters = "datacenters"; + elements.instanceType = "instance-type"; + elements.instanceTypeActive = "instance-type-active"; + + // Data recieved from API calls + var data = {}; + data.params = {}; + data.linodeTypes = []; + + // Static references to UI elements + var ui = {}; + ui.datacenters = {}; + + var createLinodeTypeButton = function(type) + { + var typeButton = document.createElement("div"); + typeButton.id = type.id; + typeButton.className = elements.instanceType; + var label = document.createElement("h3"); + label.innerHTML = type.label; + var storage = document.createElement("p"); + storage.innerHTML = (type.disk / 1024) + "GB Storage"; + var cpu = document.createElement("p"); + cpu.innerHTML = type.vcpus + " CPU Core"; + if (type.vcpus > 1) + cpu.innerHTML = cpu.innerHTML + "s"; + var transfer = document.createElement("p"); + transfer.innerHTML = type.transfer + "GB XFER"; + var cost = document.createElement("p"); + cost.innerHTML = "$" + type.price.monthly + "/mo or (" + type.price.hourly + "/hr)"; + typeButton.appendChild(label); + typeButton.appendChild(storage); + typeButton.appendChild(cpu); + typeButton.appendChild(transfer); + typeButton.appendChild(cost); + typeButton.addEventListener("click", handleTypeButtonClick); + + var list = document.getElementById(type["class"]); + list.appendChild(typeButton); + }; + + var displayRegions = function(response) + { + for (var i = 0; i < response.data.length; i++) { + var dc = document.createElement("option"); + dc.value = response.data[i].id; + if (regionNames[response.data[i].id]) + dc.innerHTML = regionNames[response.data[i].id]; + else + dc.innerHTML = response.data[i].id; + ui.datacenters.appendChild(dc); + } + + // Request the next page if there are more pages + if (response.page != response.pages) + apiGet("/regions?page=" + (response.page + 1), displayRegions, null); + }; + + var displayTypes = function(response) + { + // Add types to array + data.linodeTypes = data.linodeTypes.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/types?page=" + (response.page + 1), displayTypes, null); + return; + } + + // Insert types + for (var i = 0; i < data.linodeTypes.length; i++) + createLinodeTypeButton(data.linodeTypes[i]); + }; + + var handleAddLinode = function(event) + { + if (event.currentTarget.disabled) + return; + + var selectedPlan = document.getElementsByClassName(elements.instanceTypeActive); + if (selectedPlan.length == 0) { + alert("You must select a plan."); + return; + } + + var request = { + "type": selectedPlan[0].id, + "region": ui.datacenters.value + }; + if (data.params.tag) + request.tags = [data.params.tag]; + apiPost("/linode/instances", request, function(response) + { + location.href = "/linodes/dashboard?lid=" + response.id; + }); + }; + + var handleTypeButtonClick = function(event) + { + // Deselect any selected plans + var selected = document.getElementsByClassName(elements.instanceTypeActive); + for (var i = 0; i < selected.length; i++) + selected[i].className = selected[i].className.replace(elements.instanceTypeActive, ""); + + // Select the clicked plan + event.currentTarget.className += " " + elements.instanceTypeActive; + }; + + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + ui.datacenters = document.getElementById(elements.datacenters); + + // Register add button handler + document.getElementById(elements.addButton).addEventListener("click", handleAddLinode); + + setupHeader(); + + // Get linode types and regions + apiGet("/linode/types", displayTypes, null); + apiGet("/regions", displayRegions, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/add/index.shtml b/linodes/add/index.shtml new file mode 100644 index 0000000..26f1657 --- /dev/null +++ b/linodes/add/index.shtml @@ -0,0 +1,70 @@ + + + + + + LMC - Add a Linode + + + + + + +
+ +
+

Select an instance type

+
+

Nanode Instances

+

Nanode instances are good for low-duty workloads, where performance isn't critical.

+
+
+
+

Standard Instances

+

Standard instances are good for medium-duty workloads and are a good mix of performance, resources, and price.

+
+
+
+

Dedicated CPU Instances

+

Dedicated CPU instances are good for full-duty workloads where consistent performance is important.

+
+
+
+

High Memory Instances

+

High Memory instances favor RAM over other resources, and can be good for memory hungry use cases like caching and in-memory databases.

+
+
+
+

GPU Instances

+

Linodes with dedicated GPUs accelerate highly specialized applications such as machine learning, AI, and video transcoding.

+
+
+
+
+

Location

+ +
+
+ +
+
+ + diff --git a/linodes/backup_details/backup_details.css b/linodes/backup_details/backup_details.css new file mode 100644 index 0000000..457116c --- /dev/null +++ b/linodes/backup_details/backup_details.css @@ -0,0 +1,49 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#backup_details { + padding: 0px 15px 15px; +} + +p { + text-align: center; +} + +#restore-table td:nth-of-type(5) { + text-align: center; +} + +table:first-of-type tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} + +tbody tr:last-of-type { + border: none; +} + +td { + white-space: nowrap; +} + +ul { + display: inline; + list-style-position: inside; + padding-left: 0; +} diff --git a/linodes/backup_details/backup_details.js b/linodes/backup_details/backup_details.js new file mode 100644 index 0000000..2c8cf0f --- /dev/null +++ b/linodes/backup_details/backup_details.js @@ -0,0 +1,453 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHeader, timeString } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.backupAge = "backup-age"; + elements.backupConfigs = "backup-configs"; + elements.backupDate = "backup-date"; + elements.backupDisks = "backup-disks"; + elements.backupLabel = "backup-label"; + elements.backupLocation = "backup-location"; + elements.backupSize = "backup-size"; + elements.backupType = "backup-type"; + elements.destLabel = "dest-label"; + elements.destLinodes = "dest-linodes"; + elements.destLocation = "dest-location"; + elements.destPlan = "dest-plan"; + elements.destSpace = "dest-space"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.loading = "loading-linodes"; + elements.lmcRow = "lmc-tr3"; + elements.newLinode = "new-linode"; + elements.restorePrefix = "restore-"; + elements.selectPrefix = "select-"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + elements.unallocatedPrefix = "unallocated-"; + + // Data recieved from API calls + var data = {}; + data.backup = {}; + data.linode = {}; + data.linodes = []; + data.types = []; + + // Static references to UI elements + var ui = {}; + ui.backupAge = {}; + ui.backupConfigs = {}; + ui.backupDate = {}; + ui.backupDisks = {}; + ui.backupLabel = {}; + ui.backupLocation = {}; + ui.backupSize = {}; + ui.backupType = {}; + ui.destLabel = {}; + ui.destLinodes = {}; + ui.destLocation = {}; + ui.destPlan = {}; + ui.destSpace = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.loading = {}; + ui.newLinode = {}; + + // Temporary state + var state = {}; + state.haveTypes = false; + + // Generate a linode table row + var createLinodeRow = function(linode) + { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + var label = document.createElement("td"); + label.innerHTML = linode.label; + row.appendChild(label); + + var plan = document.createElement("td"); + if (linode.type) { + for (var i = 0; i < data.types.length; i++) { + if (data.types[i].id == linode.type) { + plan.innerHTML = data.types[i].label; + break; + } + } + } else { + plan.innerHTML = "Unknown"; + } + if (plan.innerHTML == "") + translatePlan(linode.type, plan); + row.appendChild(plan); + + var location = document.createElement("td"); + if (regionNames[linode.region]) + location.innerHTML = regionNames[linode.region]; + else + location.innerHTML = linode.region; + row.appendChild(location); + + var freeSpace = document.createElement("td"); + freeSpace.id = elements.unallocatedPrefix + linode.id; + row.appendChild(freeSpace); + + var select = document.createElement("td"); + select.id = elements.selectPrefix + linode.id; + row.appendChild(select); + + return row; + }; + + // Callback for backup details API call + var displayBackup = function(response) + { + data.backup = response; + + // Populate info table + if (data.backup.label) + ui.backupLabel.innerHTML = data.backup.label; + + var now = new Date(); + var backupStart = new Date(data.backup.created + "Z"); + ui.backupDate.innerHTML = backupStart.toLocaleString(); + ui.backupAge.innerHTML = timeString(now - backupStart, true); + + ui.backupType.innerHTML = data.backup.type; + + for (var i = 0; i < data.backup.configs.length; i++) { + var li = document.createElement("li"); + li.innerHTML = data.backup.configs[i]; + ui.backupConfigs.appendChild(li); + } + + data.backup.totalSize = 0; + for (var i = 0; i < data.backup.disks.length; i++) { + data.backup.totalSize += data.backup.disks[i].size; + var li = document.createElement("li"); + li.innerHTML = data.backup.disks[i].label + " (" + data.backup.disks[i].filesystem + ") – " + data.backup.disks[i].size + "MB"; + ui.backupDisks.appendChild(li); + } + + ui.backupSize.innerHTML = data.backup.totalSize + " MB"; + + if (state.haveTypes && data.linode.id) + insertTypes(); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Display location + if (regionNames[data.linode.region]) { + ui.backupLocation.innerHTML = regionNames[data.linode.region]; + ui.destLocation.innerHTML = regionNames[data.linode.region]; + } else { + ui.backupLocation.innerHTML = data.linode.region; + ui.destLocation.innerHTML = data.linode.region; + } + + if (state.haveTypes && data.backup.id) + insertTypes(); + }; + + // Callback for linode disks API call + var displayDisks = function(response) + { + // Find the linode this response is for + var lid = parseInt(response['_endpoint'].split("/")[3]); + var index = -1; + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == lid) { + index = i; + break; + } + } + + if (index == -1) + return; + + // Add disks to array + data.linodes[index].disks = data.linodes[index].disks.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.linodes[index].id + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + // Calculate Linode's free space + var free = data.linodes[index].specs.disk; + for (var i = 0; i < data.linodes[index].disks.length; i++) + free -= data.linodes[index].disks[i].size; + + // Update table + var freeCell = document.getElementById(elements.unallocatedPrefix + data.linodes[index].id); + var selectCell = document.getElementById(elements.selectPrefix + data.linodes[index].id); + freeCell.innerHTML = free + " MB"; + if (free >= data.backup.totalSize) { + var restoreLink = document.createElement("a"); + restoreLink.id = elements.restorePrefix + data.linodes[index].id; + restoreLink.href = "#"; + restoreLink.innerHTML = "Restore to this Linode"; + restoreLink.addEventListener("click", handleRestore); + selectCell.appendChild(restoreLink); + } else { + selectCell.innerHTML = "--- not enough free space ---"; + } + }; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to array + data.linodes = data.linodes.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + var filter = { + "region": data.linode.region + }; + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filter); + return; + } + + ui.loading.remove(); + for (var i = 0; i < data.linodes.length; i++) { + // Create row in the table + ui.destLinodes.appendChild(createLinodeRow(data.linodes[i])); + // Get the linode's disks + data.linodes[i].disks = []; + apiGet("/linode/instances/" + data.linodes[i].id + "/disks", displayDisks, null); + } + }; + + // Callback for linode types API call + var displayTypes = function(response) + { + // Add types to array + data.types = data.types.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/types?page=" + (response.page + 1), displayTypes, null); + return; + } + + state.haveTypes = true; + if (data.backup.id && data.linode.id) + insertTypes(); + }; + + // Handler for create linode button + var handleCreate = function(event) + { + if (event.currentTarget.disabled) + return; + + // Find the selected type + var index = -1; + for (var i = 0; i < data.types.length; i++) { + if (data.types[i].id == ui.destPlan.value) { + index = i; + break; + } + } + + if (index == -1) + return; + + if (!confirm("Create a new " + data.types[i].label + " from this backup? This new instance will cost $" + data.types[i].price.monthly.toFixed(2) + " per month and backups will be enabled per your global account setting.")) + return; + + var req = { + "label": ui.destLabel.value, + "type": ui.destPlan.value, + "region": data.linode.region, + "backup_id": data.backup.id + }; + var callback = function(response) + { + location.href = "/linodes/dashboard?lid=" + response.id; + }; + apiPost("/linode/instances", req, callback); + }; + + // Handler for backup restore links + var handleRestore = function(event) + { + // Find the linode associated with this link + var lid = parseInt(event.currentTarget.id.replace(elements.restorePrefix, "")); + var index = -1; + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == lid) { + index = i; + break; + } + } + + if (index == -1) + return; + if (!confirm("Restore to Linode " + data.linodes[index].label + "?")) + return; + + var req = { + "linode_id": lid, + "overwrite": false + }; + + var callback = function(response) + { + location.href = "/linodes/dashboard?lid=" + lid; + }; + apiPost("/linode/instances/" + data.params.lid + "/backups/" + data.backup.id + "/restore", req, callback); + }; + + // Insert linode types into selector + var insertTypes = function() + { + for (var i = 0; i < data.types.length; i++) { + if (data.types[i].disk < data.backup.totalSize) + continue; + + var option = document.createElement("option"); + option.value = data.types[i].id; + option.innerHTML = data.types[i].label; + ui.destPlan.appendChild(option); + } + + updatePrice(null); + ui.newLinode.disabled = false; + + var filter = { + "region": data.linode.region + }; + apiGet("/linode/instances", displayLinodes, filter); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + // We also need a backup ID + if (!data.params.bid) { + alert("No Backup ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the backups subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/backups") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.backupAge = document.getElementById(elements.backupAge); + ui.backupConfigs = document.getElementById(elements.backupConfigs); + ui.backupDate = document.getElementById(elements.backupDate); + ui.backupDisks = document.getElementById(elements.backupDisks); + ui.backupLabel = document.getElementById(elements.backupLabel); + ui.backupLocation = document.getElementById(elements.backupLocation); + ui.backupSize = document.getElementById(elements.backupSize); + ui.backupType = document.getElementById(elements.backupType); + ui.destLabel = document.getElementById(elements.destLabel); + ui.destLinodes = document.getElementById(elements.destLinodes); + ui.destLocation = document.getElementById(elements.destLocation); + ui.destPlan = document.getElementById(elements.destPlan); + ui.destSpace = document.getElementById(elements.destSpace); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.loading = document.getElementById(elements.loading); + ui.newLinode = document.getElementById(elements.newLinode); + + // Register event handlers + ui.destPlan.addEventListener("input", updatePrice); + ui.newLinode.addEventListener("click", handleCreate); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/backups/" + data.params.bid, displayBackup, null); + apiGet("/linode/types", displayTypes, null); + }; + + // Update the given element with the given type's label + var translatePlan = function(type, el) + { + var callback = function(response) + { + el.innerHTML = response.label; + }; + + apiGet("/linode/types/" + type, callback, null); + }; + + // Update the price display + var updatePrice = function(event) + { + // Find the selected type + var type = null; + for (var i = 0; i < data.types.length; i++) { + if (data.types[i].id == ui.destPlan.value) { + type = data.types[i]; + break; + } + } + + if (!type) + return; + + ui.destSpace.innerHTML = type.disk; + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/backup_details/index.shtml b/linodes/backup_details/index.shtml new file mode 100644 index 0000000..17105e5 --- /dev/null +++ b/linodes/backup_details/index.shtml @@ -0,0 +1,100 @@ + + + + + + LMC - Backups + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Backup Details
Label
Backup Date ()
Type
Location
Configuration Profiles +
    +
    Disks +
      +
      Total size required
      +

      Select a Linode to restore this backup to:

      + + + + + + + + + + + + + + + + + + + + + + +
      LinodePlanLocationUnallocated/Free SpaceSelect
      MB
      Loading Linodes...
      +
      +
      + + diff --git a/linodes/backups/backups.css b/linodes/backups/backups.css new file mode 100644 index 0000000..0ac2570 --- /dev/null +++ b/linodes/backups/backups.css @@ -0,0 +1,51 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#backups { + padding: 0px 15px 15px; +} + +#cancel-link { + text-align: center; +} + +#in-progress { + display: none; +} + +#schedule-updated { + background-color: #ADD370; + display: none; + font-size: 16px; + margin-top: 0; + padding: 7px; +} + +table { + margin-bottom: 30px; +} + +table:first-of-type tbody:not(.lmc-tbody-head) tr td:first-of-type { + font-weight: bold; + text-align: right; +} + +tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} diff --git a/linodes/backups/backups.js b/linodes/backups/backups.js new file mode 100644 index 0000000..3bcc92b --- /dev/null +++ b/linodes/backups/backups.js @@ -0,0 +1,270 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, apiPut, parseParams, setupHeader, timeString } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.backupDay = "backup-day"; + elements.backupTable = "backup-table"; + elements.backupWindow = "backup-window"; + elements.inProgress = "in-progress"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr3"; + elements.saveButton = "save-button"; + elements.scheduleUpdated = "schedule-updated"; + elements.snapshotButton = "snapshot-button"; + elements.snapshotLabel = "snapshot-label"; + elements.timezone = "timezone"; + elements.window = "window"; + + // Data recieved from API calls + var data = {}; + data.backups = {}; + data.backupsSorted = []; + data.linode = {}; + data.profile = {}; + + // Static references to UI elements + var ui = {}; + ui.backupDay = {}; + ui.backupTable = {}; + ui.backupWindow = {}; + ui.inProgress = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.saveButton = {}; + ui.scheduleUpdated = {}; + ui.snapshotButton = {}; + ui.snapshotLabel = {}; + ui.timezone = {}; + ui.windows = []; + + // Generate a backup table row + var createBackupRow = function(backup) + { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + var type = document.createElement("td"); + type.innerHTML = backup.type; + row.appendChild(type); + + var started = document.createElement("td"); + var startedDate = new Date(backup.created + "Z"); + started.innerHTML = startedDate.toLocaleString(); + row.appendChild(started); + + var finished = document.createElement("td"); + if (backup.finished) { + var finishedDate = new Date(backup.finished + "Z"); + finished.innerHTML = finishedDate.toLocaleString(); + } + row.appendChild(finished); + + var duration = document.createElement("td"); + if (backup.finished) + duration.innerHTML = timeString(finishedDate - startedDate, false); + row.appendChild(duration); + + var status = document.createElement("td"); + status.innerHTML = backup.status; + row.appendChild(status); + + var restore = document.createElement("td"); + if (backup.status == "successful") { + var restoreLink = document.createElement("a"); + restoreLink.href = "/linodes/backup_details?lid=" + data.params.lid + "&bid=" + backup.id; + restoreLink.innerHTML = "Restore to..."; + restore.appendChild(restoreLink); + } + row.appendChild(restore); + + return row; + }; + + // Callback for backups API call + var displayBackups = function(response) + { + data.backups = response; + + // Enable snapshot button if there's no snapshot in progress + if (!data.backups.snapshot.in_progress) { + ui.snapshotButton.disabled = false; + } else { + ui.snapshotButton.style.display = "none"; + ui.snapshotLabel.style.display = "none"; + ui.inProgress.style.display = "initial"; + ui.backupTable.appendChild(createBackupRow(data.backups.snapshot.in_progress)); + } + + // Sort backups by date + data.backupsSorted = data.backups.automatic; + if (data.backups.snapshot.current) + data.backupsSorted.push(data.backups.snapshot.current); + data.backupsSorted.sort(function(a, b) + { + var startA = new Date(a.created + "Z"); + var startB = new Date(b.created + "Z"); + return startB - startA; + }); + + // Add them to the table + for (var i = 0; i < data.backupsSorted.length; i++) + ui.backupTable.appendChild(createBackupRow(data.backupsSorted[i])); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Redirect to enable page if backups not enabled + if (!data.linode.backups.enabled) + location.href = "/linodes/backups_enable?lid=" + data.params.lid; + + // Set backup settings + ui.backupWindow.value = data.linode.backups.schedule.window; + ui.backupDay.value = data.linode.backups.schedule.day; + ui.saveButton.disabled = false; + }; + + // Handler for save button + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "backups": { + "schedule": { + "day": ui.backupDay.value, + "window": ui.backupWindow.value + } + } + }; + + apiPut("/linode/instances/" + data.params.lid, req, function(response) + { + ui.scheduleUpdated.style.display = "block"; + }); + }; + + // Handler for snapshot button + var handleSnapshot = function(event) + { + if (event.currentTarget.disabled) + return; + + if (!confirm("Taking a snapshot will back up your Linode in its current state, over-writing your previous snapshot. Are you sure?")) + return; + + var req = { + "label": ui.snapshotLabel.value + }; + + apiPost("/linode/instances/" + data.params.lid + "/backups", req, function(response) + { + location.reload(); + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.backupDay = document.getElementById(elements.backupDay); + ui.backupTable = document.getElementById(elements.backupTable); + ui.backupWindow = document.getElementById(elements.backupWindow); + ui.inProgress = document.getElementById(elements.inProgress); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.saveButton = document.getElementById(elements.saveButton); + ui.scheduleUpdated = document.getElementById(elements.scheduleUpdated); + ui.snapshotButton = document.getElementById(elements.snapshotButton); + ui.snapshotLabel = document.getElementById(elements.snapshotLabel); + ui.timezone = document.getElementById(elements.timezone); + ui.windows = document.getElementsByClassName(elements.window); + + // Display timezone info + var now = new Date(); + var offset = now.getTimezoneOffset() / -60; + var offsetHours = Math.floor(offset); + var offsetMins = now.getTimezoneOffset() % 60; + if (offsetMins < 10) + offsetMins = "0" + offsetMins; + ui.timezone.innerHTML = "GMT"; + if (offset >= 0) + ui.timezone.innerHTML += "+"; + ui.timezone.innerHTML += offset; + for (var i = 0; i < ui.windows.length; i++) { + var windowNum = parseInt(ui.windows[i].value.substring(1)); + var startHour = windowNum + offsetHours; + if (startHour < 0) + startHour += 24; + if (startHour < 10) + startHour = "0" + startHour; + var endHour = windowNum + offsetHours + 2; + if (endHour < 0) + endHour += 24; + if (endHour < 10) + endHour = "0" + endHour; + ui.windows[i].innerHTML = startHour + ":" + offsetMins + " - " + endHour + ":" + offsetMins; + } + + // Attach button handlers + ui.saveButton.addEventListener("click", handleSave); + ui.snapshotButton.addEventListener("click", handleSnapshot); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/backups", displayBackups, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/backups/index.shtml b/linodes/backups/index.shtml new file mode 100644 index 0000000..65c8402 --- /dev/null +++ b/linodes/backups/index.shtml @@ -0,0 +1,122 @@ + + + + + + LMC - Backups + + + + + + + +
      + +
      +

      Backup schedule updated.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Backup Settings
      Schedule
      Backup Window () + +
      Weekly Backup + +
      Manual Snapshot
      + — Snapshot In Progress —
      + + +
      + + + + + + + + + + + + + + + +
      Available Backups
      TypeStartedFinishedDurationStatusRestore
      + +
      +
      + + diff --git a/linodes/backups_cancel/backups_cancel.css b/linodes/backups_cancel/backups_cancel.css new file mode 100644 index 0000000..0c65f2f --- /dev/null +++ b/linodes/backups_cancel/backups_cancel.css @@ -0,0 +1,30 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#backups_cancel { + padding: 0px 15px 15px; +} + +#button-block { + text-align: center; +} + +h2 { + margin-top: 0; +} diff --git a/linodes/backups_cancel/backups_cancel.js b/linodes/backups_cancel/backups_cancel.js new file mode 100644 index 0000000..a65a4e5 --- /dev/null +++ b/linodes/backups_cancel/backups_cancel.js @@ -0,0 +1,107 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.cancelButton = "cancel-button"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.cancelButton = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Redirect to backups page if backups are already enabled + if (!data.linode.backups.enabled) + location.href = "/linodes/backups_enable?lid=" + data.params.lid; + }; + + // Cancel button handler + var handleCancel = function(event) + { + if (event.currentTarget.disabled) + return; + + if (!confirm("Removing Backup Service will irreversibly delete all backup data, are you sure you want to continue?")) + return; + + apiPost("/linode/instances/" + data.params.lid + "/backups/cancel", {}, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.cancelButton = document.getElementById(elements.cancelButton); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + + // Register rebuild button handler + ui.cancelButton.addEventListener("click", handleCancel); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/backups_cancel/index.shtml b/linodes/backups_cancel/index.shtml new file mode 100644 index 0000000..dcda110 --- /dev/null +++ b/linodes/backups_cancel/index.shtml @@ -0,0 +1,42 @@ + + + + + + LMC - Backups Cancel + + + + + + + +
      + +
      +

      Cancel Backups

      +

      + Warning: Please be aware that all data in your backups will be securely deleted and unrecoverable. Linode does not retain backup data after cancellation. If you would like to enable backups again, you can do so via the manager, but you will not have access to older backups as they will be purged from Linode's system.
      +
      + Would you like to continue? +

      +
      +
      +
      + + diff --git a/linodes/backups_enable/backups_enable.css b/linodes/backups_enable/backups_enable.css new file mode 100644 index 0000000..0a3f617 --- /dev/null +++ b/linodes/backups_enable/backups_enable.css @@ -0,0 +1,43 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#backups_enable { + padding: 0px 15px 15px; +} + +#button-block { + text-align: center; +} + +h2 { + margin-top: 0; +} + +#price { + font-weight: bold; +} + +#price-info { + padding-top: 15px; + text-align: center; +} + +.top-level { + font-weight: bold; +} diff --git a/linodes/backups_enable/backups_enable.js b/linodes/backups_enable/backups_enable.js new file mode 100644 index 0000000..436a9ae --- /dev/null +++ b/linodes/backups_enable/backups_enable.js @@ -0,0 +1,117 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.enableButton = "enable-button"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.price = "price"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.enableButton = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.price = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Redirect to backups page if backups are already enabled + if (data.linode.backups.enabled) + location.href = "/linodes/backups?lid=" + data.params.lid; + + // Get Linode type info for backup pricing + apiGet("/linode/types/" + data.linode.type, displayPricing, null); + }; + + // Callback for linode type API call + var displayPricing = function(response) + { + ui.price.innerHTML = "$" + response.addons.backups.price.monthly.toFixed(2) + "/mo"; + ui.enableButton.disabled = false; + }; + + // Enable button handler + var handleEnable = function(event) + { + if (event.currentTarget.disabled) + return; + + apiPost("/linode/instances/" + data.params.lid + "/backups/enable", {}, function(response) + { + location.href = "/linodes/backups?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.enableButton = document.getElementById(elements.enableButton); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.price = document.getElementById(elements.price); + + // Register rebuild button handler + ui.enableButton.addEventListener("click", handleEnable); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/backups_enable/index.shtml b/linodes/backups_enable/index.shtml new file mode 100644 index 0000000..b0ca084 --- /dev/null +++ b/linodes/backups_enable/index.shtml @@ -0,0 +1,59 @@ + + + + + + LMC - Backups Enable + + + + + + + +
      + +
      +

      Backups

      +

      The Linode Backup System is designed to be an easy to use, reliable and redundant on-site backup solution for your Linode. It performs backups without causing any interruption of your running system. It provides 4 backup slots. Three of the slots are executed and rotated automatically: a daily backup, a 2-7 day old backup, and an 8-14 day old backup. The fouth backup slot is a user-initiated snapshot and remains in place until another user-initiated snapshot is taken.

      +
        +
      • + Resiliency: +
          +
        • Linode's storage back ends tolerate hard drive failures by utilizing RAID across many drives.
        • +
        +
      • +
      • + Restoring: +
          +
        • You can restore a backup to any of the Linodes attached to this account, even if they do not have backups enabled. Currently only a full restore is possible.
        • +
        +
      • +
      • + Limitations: +
          +
        • The backup system must be able to mount your disks on the host. If you've used fdisk on your disks to create partitions, or created encrypted volumes, or done anything other than use Linode's deployment or disk creation tools, the backup system won't be able to back up the data. The backup system operates on files, not at the block level.
        • +
        +
      • +
      +

      Backups for this Linode are .

      +
      +
      +
      + + diff --git a/linodes/clone/clone.css b/linodes/clone/clone.css new file mode 100644 index 0000000..ecd40d3 --- /dev/null +++ b/linodes/clone/clone.css @@ -0,0 +1,84 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#clone { + padding: 0px 15px 15px; +} + +#clone-table tbody:last-of-type tr:last-of-type { + font-weight: bold; +} + +#clone-table tbody:last-of-type tr:last-of-type td:nth-of-type(2) { + text-align: right; +} + +#clone-table td:first-of-type { + width: 100%; +} + +#config-table { + margin-bottom: 20px; + text-align: center; +} + +#config-table td:nth-of-type(2) { + text-align: left; + width: 100%; +} + +#config-table td:nth-of-type(3) { + text-align: left; +} + +#dest-table tbody:not(.lmc-tbody-head) td:first-of-type { + font-weight: bold; + padding-left: 100px; + text-align: right; +} + +#dest-table tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} + +#dest-table td:last-of-type { + width: 100%; +} + +#disk-table { + margin-bottom: 20px; + text-align: center; +} + +#disk-table td:nth-of-type(2) { + text-align: left; + width: 100%; +} + +.lmc-table td { + white-space: nowrap; +} + +.lmc-table thead tr:first-of-type { + text-align: left; +} + +optgroup { + display: none; +} diff --git a/linodes/clone/clone.js b/linodes/clone/clone.js new file mode 100644 index 0000000..411d2a9 --- /dev/null +++ b/linodes/clone/clone.js @@ -0,0 +1,558 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, migrateETA, parseParams, regionNames, setupHeader, translateKernel } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.cloneButton = "clone-button"; + elements.configCloneTable = "config-clone-table"; + elements.configDiskRow = "config-disk-row"; + elements.configsNone = "configs-none"; + elements.configTable = "config-table-body"; + elements.destBackups = "dest-backups"; + elements.destBackupsPrice = "dest-backups-price"; + elements.destLabel = "dest-label"; + elements.destLinode = "dest-linode"; + elements.destLocation = "dest-location"; + elements.destPlan = "dest-plan"; + elements.destPlanPrice = "dest-plan-price"; + elements.diskCloneTable = "disk-clone-table"; + elements.disksNone = "disks-none"; + elements.diskTable = "disk-table-body"; + elements.etaLocal = "eta-local"; + elements.etaRemote = "eta-remote"; + elements.etaRow = "eta-row"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr1"; + elements.lmcRowAlt = "lmc-tr2"; + elements.lmcRowThree = "lmc-tr3"; + elements.loadingConfigs = "loading-configs"; + elements.loadingDisks = "loading-disks"; + elements.newLinode = "new-linode"; + elements.sourceLocation = "source-location"; + + // Data recieved from API calls + var data = {}; + data.configs = []; + data.disks = []; + data.linode = {}; + data.types = []; + + // Static references to UI elements + var ui = {}; + ui.cloneButton = {}; + ui.configCloneTable = {}; + ui.configsNone = {}; + ui.configTable = {}; + ui.destBackups = {}; + ui.destBackupsPrice = {}; + ui.destLabel = {}; + ui.destLinode = {}; + ui.destLocation = {}; + ui.destPlan = {}; + ui.destPlanPrice = {}; + ui.diskCloneTable = {}; + ui.disksNone = {}; + ui.diskTable = {}; + ui.etaLocal = {}; + ui.etaRemote = {}; + ui.etaRow = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.loadingConfigs = {}; + ui.loadingDisks = {}; + ui.newLinode = []; + ui.sourceLocation = {}; + + // Temporary state + var state = {}; + state.configs = []; + state.disks = []; + + // Generate a config profile table row for clone section + var createCloneConfigRow = function(config) + { + var row = document.createElement("tr"); + row.className = elements.lmcRowThree + " " + elements.configDiskRow; + var label = document.createElement("td"); + label.colSpan = ui.configsNone.children[0].colSpan; + label.innerHTML = config.label; + row.appendChild(label); + return row; + }; + + // Create a disk table row for clone section + var createCloneDiskRow = function(disk) + { + var row = document.createElement("tr"); + row.className = elements.lmcRowThree + " " + elements.configDiskRow; + + // Label + var label = document.createElement("td"); + label.innerHTML = disk.label; + row.appendChild(label); + + // Size + var size = document.createElement("td"); + size.innerHTML = disk.size + " MB"; + row.appendChild(size); + + // Local copy ETA + var local = document.createElement("td"); + local.innerHTML = migrateETA(disk.size, true); + row.appendChild(local); + + // Remote copy ETA + var remote = document.createElement("td"); + remote.innerHTML = migrateETA(disk.size, false); + row.appendChild(remote); + + return row; + }; + + // Generate a config profile table row + var createConfigRow = function(config, alt) + { + var row = document.createElement("tr"); + if (alt) + row.className = elements.lmcRowAlt; + else + row.className = elements.lmcRow; + + // Select checkbox + var selectCell = document.createElement("td"); + var select = document.createElement("input"); + select.id = "config-" + config.id; + select.type = "checkbox"; + select.addEventListener("input", handleSelect); + selectCell.appendChild(select); + row.appendChild(selectCell); + + // Config profile name + var nameCell = document.createElement("td"); + nameCell.innerHTML = config.label; + row.appendChild(nameCell); + + // Kernel + var kernel = document.createElement("td"); + translateKernel(config.kernel, kernel); + row.appendChild(kernel); + + // Number of disks + var disks = document.createElement("td"); + var numDisks = 0; + for (var disk in config.devices) { + if (config.devices[disk] && config.devices[disk].disk_id) + numDisks++; + } + disks.innerHTML = numDisks; + row.appendChild(disks); + + return row; + }; + + // Generate a disk table row + var createDiskRow = function(disk, alt) + { + var row = document.createElement("tr"); + if (alt) + row.className = elements.lmcRowAlt; + else + row.className = elements.lmcRow; + + // Select checkbox + var selectCell = document.createElement("td"); + var select = document.createElement("input"); + select.id = "disk-" + disk.id; + select.type = "checkbox"; + select.addEventListener("input", handleSelect); + selectCell.appendChild(select); + row.appendChild(selectCell); + + // Disk name + var nameCell = document.createElement("td"); + nameCell.innerHTML = disk.label; + row.appendChild(nameCell); + + // Disk type + var typeCell = document.createElement("td"); + typeCell.innerHTML = disk.filesystem; + row.appendChild(typeCell); + + // Disk size + var sizeCell = document.createElement("td"); + sizeCell.innerHTML = disk.size + " MB"; + row.appendChild(sizeCell); + + return row; + }; + + // Callback for config profiles API call + var displayConfigs = function(response) + { + // Add configs to array + data.configs = data.configs.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/configs?page=" + (response.page + 1), displayConfigs, null); + return; + } + + // Remove loading row + ui.loadingConfigs.remove(); + + // Insert config profile rows into table + for (var i = 0; i < data.configs.length; i++) + ui.configTable.appendChild(createConfigRow(data.configs[i], i % 2)); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Display the source location + if (regionNames[data.linode.region]) + ui.sourceLocation.innerHTML = regionNames[data.linode.region]; + else + ui.sourceLocation.innerHTML = data.linode.region; + }; + + // Callback for linode disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + // Remove loading row + ui.loadingDisks.remove(); + + // Insert disk rows into table + for (var i = 0; i < data.disks.length; i++) + ui.diskTable.appendChild(createDiskRow(data.disks[i], i % 2)); + }; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to selector + for (var i = 0; i < response.data.length; i++) { + if (response.data[i].id == data.params.lid) + continue; + var linode = document.createElement("option"); + linode.value = response.data[i].id; + linode.innerHTML = response.data[i].label; + var optgroup = document.getElementById(response.data[i].region); + optgroup.appendChild(linode); + optgroup.style.display = "initial"; + } + + // Request the next page if there are more pages + if (response.page != response.pages) + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null); + }; + + // Callback for regions API call + var displayRegions = function(response) + { + for (var i = 0; i < response.data.length; i++) { + // Add regions to selector + var dc = document.createElement("option"); + dc.value = response.data[i].id; + if (regionNames[response.data[i].id]) + dc.innerHTML = regionNames[response.data[i].id]; + else + dc.innerHTML = response.data[i].id; + ui.destLocation.appendChild(dc); + + // Add optgroups to linode selector + var optgroup = document.createElement("optgroup"); + optgroup.id = response.data[i].id; + if (regionNames[response.data[i].id]) + optgroup.label = regionNames[response.data[i].id]; + else + optgroup.label = response.data[i].label; + ui.destLinode.appendChild(optgroup); + } + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/regions?page=" + (response.page + 1), displayRegions, null); + return; + } + + apiGet("/linode/instances", displayLinodes, null); + }; + + // Callback for linode types API call + var displayTypes = function(response) + { + // Add types to array + data.types = data.types.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/types?page=" + (response.page + 1), displayTypes, null); + return; + } + + // Insert types into selector + for (var i = 0; i < data.types.length; i++) { + var type = document.createElement("option"); + type.value = data.types[i].id; + type.innerHTML = data.types[i].label; + ui.destPlan.appendChild(type); + } + + updatePrices(null); + }; + + // Clone button handler + var handleClone = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "configs": state.configs, + "disks": state.disks + }; + + var destLinode = parseInt(ui.destLinode.value); + if (destLinode == 0) { + req.region = ui.destLocation.value; + req.type = ui.destPlan.value; + if (ui.destLabel.value.length) + req.label = ui.destLabel.value; + req.backups_enabled = ui.destBackups.checked; + } else { + req.linode_id = destLinode; + } + + apiPost("/linode/instances/" + data.params.lid + "/clone", req, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Handler for checkbox selections + var handleSelect = function(event) + { + // Determine whether we're working with configs or disks + var arr = state.configs; + if (event.currentTarget.id.split("-")[0] == "disk") + arr = state.disks; + + // Get the ID of the thing + var id = parseInt(event.currentTarget.id.split("-")[1]); + var index = arr.indexOf(id); + + // If the box is checked, add the ID, otherwise remove it + if (event.currentTarget.checked && index == -1) + arr.push(id); + else if (index != -1) + arr.splice(index, 1); + + updateClone(); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.cloneButton = document.getElementById(elements.cloneButton); + ui.configCloneTable = document.getElementById(elements.configCloneTable); + ui.configsNone = document.getElementById(elements.configsNone); + ui.configTable = document.getElementById(elements.configTable); + ui.destBackups = document.getElementById(elements.destBackups); + ui.destBackupsPrice = document.getElementById(elements.destBackupsPrice); + ui.destLabel = document.getElementById(elements.destLabel); + ui.destLinode = document.getElementById(elements.destLinode); + ui.destLocation = document.getElementById(elements.destLocation); + ui.destPlan = document.getElementById(elements.destPlan); + ui.destPlanPrice = document.getElementById(elements.destPlanPrice); + ui.diskCloneTable = document.getElementById(elements.diskCloneTable); + ui.disksNone = document.getElementById(elements.disksNone); + ui.diskTable = document.getElementById(elements.diskTable); + ui.etaLocal = document.getElementById(elements.etaLocal); + ui.etaRemote = document.getElementById(elements.etaRemote); + ui.etaRow = document.getElementById(elements.etaRow); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.loadingConfigs = document.getElementById(elements.loadingConfigs); + ui.loadingDisks = document.getElementById(elements.loadingDisks); + ui.newLinode = document.getElementsByClassName(elements.newLinode); + ui.sourceLocation = document.getElementById(elements.sourceLocation); + + // Register event handlers + ui.cloneButton.addEventListener("click", handleClone); + ui.destLinode.addEventListener("input", updateDestination); + ui.destPlan.addEventListener("input", updatePrices); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/configs", displayConfigs, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + apiGet("/linode/types", displayTypes, null); + apiGet("/regions", displayRegions, null); + }; + + // Update clone config and disk info + var updateClone = function() + { + // Remove all config and disk rows + var configDiskRows = document.getElementsByClassName(elements.configDiskRow); + for (var i = configDiskRows.length - 1; i >= 0; i--) + configDiskRows[i].remove(); + + var allDisks = []; + + // Loop through configs and create rows + for (var i = 0; i < state.configs.length; i++) { + // Find config + var config = null; + for (var j = 0; j < data.configs.length; j++) { + if (state.configs[i] == data.configs[j].id) { + config = data.configs[j]; + break; + } + } + if (!config) + continue; + + // Add config to table + ui.configCloneTable.appendChild(createCloneConfigRow(config)); + + // Loop through config's disks and add them to array + for (var disk in config.devices) { + if (config.devices[disk] && config.devices[disk].disk_id && allDisks.indexOf(config.devices[disk].disk_id) == -1) + allDisks.push(config.devices[disk].disk_id); + } + } + + // Add independent disks to array + for (var i = 0; i < state.disks.length; i++) { + if (allDisks.indexOf(state.disks[i]) == -1) + allDisks.push(state.disks[i]); + } + + // Loop through disks and create rows + var totalSize = 0; + for (var i = 0; i < allDisks.length; i++) { + // Find disk + var disk = null; + for (var j = 0; j < data.disks.length; j++) { + if (allDisks[i] == data.disks[j].id) { + disk = data.disks[j]; + break; + } + } + if (!disk) + continue; + + totalSize += disk.size; + + // Add disk to table + ui.diskCloneTable.insertBefore(createCloneDiskRow(disk), ui.etaRow); + } + + // Show/hide the "none" rows + if (state.configs.length > 0) + ui.configsNone.style.display = "none"; + else + ui.configsNone.style.display = "table-row"; + if (allDisks.length > 0) + ui.disksNone.style.display = "none"; + else + ui.disksNone.style.display = "table-row"; + + // Compute total ETAs + ui.etaLocal.innerHTML = migrateETA(totalSize, true); + ui.etaRemote.innerHTML = migrateETA(totalSize, false); + }; + + // Update destination form + var updateDestination = function(event) + { + var display = "none"; + if (ui.destLinode.value == "0") + display = "table-row"; + + for (var i = 0; i < ui.newLinode.length; i++) + ui.newLinode[i].style.display = display; + }; + + // Update price labels + var updatePrices = function(event) + { + // Find the selected type + var type = null; + for (var i = 0; i < data.types.length; i++) { + if (data.types[i].id == ui.destPlan.value) { + type = data.types[i]; + break; + } + } + + if (!type) + return; + + ui.destPlanPrice.innerHTML = type.price.monthly; + ui.destBackupsPrice.innerHTML = type.addons.backups.price.monthly; + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/clone/index.shtml b/linodes/clone/index.shtml new file mode 100644 index 0000000..2ab1c05 --- /dev/null +++ b/linodes/clone/index.shtml @@ -0,0 +1,174 @@ + + + + + + LMC - Clone + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + +
      Configuration Profiles
      SelectConfiguration ProfilesKernelDisks Attached
      Loading configuration profiles...
      + + + + + + + + + + + + + + + + + + + + +
      Disks
      SelectDisksTypeSize
      Loading disks...
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Clone
      Config Profiles
      - None -
      DisksSizeTime to copy: LocalTo another Datacenter
      - None -
      TOTAL ESTIMATED TIME:0 minutes0 minutes
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Source
      Current Datacenter
      Select Destination
      Destination Linode + +
      Location
      Plan + + $ per month +
      Label
      Backups + + +
      +
      +
      + + diff --git a/linodes/config/config.css b/linodes/config/config.css new file mode 100644 index 0000000..06aecf7 --- /dev/null +++ b/linodes/config/config.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#config { + padding: 0px 15px 15px; +} + +tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} + +tbody:not(.lmc-tbody-head) tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/config/config.js b/linodes/config/config.js new file mode 100644 index 0000000..2edb9a2 --- /dev/null +++ b/linodes/config/config.js @@ -0,0 +1,535 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, apiPut, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.binbash = "binbash"; + elements.bootDeviceCustom = "boot-device-custom"; + elements.bootDeviceStandard = "boot-device-standard"; + elements.custom = "custom"; + elements["default"] = "default"; + elements.devtmpfsHelper = "devtmpfs-helper"; + elements.devtmpfsHelperNo = "devtmpfs-helper-no"; + elements.disks = "disks"; + elements.distroHelper = "distro-helper"; + elements.distroHelperNo = "distro-helper-no"; + elements.fullvirt = "fullvirt"; + elements.fullvirtHide = "fullvirt-hide"; + elements.initrd = "initrd"; + elements.kernel = "kernel"; + elements.label = "label"; + elements.limit = "limit"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.maxMem = "max-mem"; + elements.memLimit = "mem-limit"; + elements.modulesHelper = "modules-helper"; + elements.modulesHelperNo = "modules-helper-no"; + elements.networkHelper = "network-helper"; + elements.networkHelperNo = "network-helper-no"; + elements.noLimit = "no-limit"; + elements.notes = "notes"; + elements.paravirt = "paravirt"; + elements.saveButton = "save-button"; + elements.sda = "sda"; + elements.sdb = "sdb"; + elements.sdc = "sdc"; + elements.sdd = "sdd"; + elements.sde = "sde"; + elements.sdf = "sdf"; + elements.sdg = "sdg"; + elements.sdh = "sdh"; + elements.single = "single"; + elements.standard = "standard"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + elements.updatedbHelper = "updatedb-helper"; + elements.updatedbHelperNo = "updatedb-helper-no"; + elements.volumes = "volumes"; + + // Data recieved from API calls + var data = {}; + data.config = {}; + data.disks = []; + data.kernels = []; + data.linode = {}; + data.volumes = []; + + // Static references to UI elements + var ui = {}; + ui.binbash = {}; + ui.bootDeviceCustom = {}; + ui.bootDeviceStandard = {}; + ui.custom = {}; + ui["default"] = {}; + ui.devtmpfsHelper = {}; + ui.devtmpfsHelperNo = {}; + ui.disks = []; + ui.distroHelper = {}; + ui.distroHelperNo = {}; + ui.fullvirt = {}; + ui.fullvirtHide = []; + ui.initrd = {}; + ui.kernel = {}; + ui.label = {}; + ui.limit = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.maxMem = {}; + ui.memLimit = {}; + ui.modulesHelper = {}; + ui.modulesHelperNo = {}; + ui.networkHelper = {}; + ui.networkHelperNo = {}; + ui.noLimit = {}; + ui.notes = {}; + ui.paravirt = {}; + ui.saveButton = {}; + ui.sda = {}; + ui.sdb = {}; + ui.sdc = {}; + ui.sdd = {}; + ui.sde = {}; + ui.sdf = {}; + ui.sdg = {}; + ui.sdh = {}; + ui.single = {}; + ui.standard = {}; + ui.updatedbHelper = {}; + ui.updatedbHelperNo = {}; + ui.volumes = []; + + // Temporary state + var state = { + "haveDisks": false, + "haveVolumes": false + }; + + // Callback for config API call + var displayConfig = function(response) + { + data.config = response; + + // Label and notes + ui.label.value = data.config.label; + ui.notes.value = data.config.comments; + + // Virtualization mode + if (data.config.virt_mode == "paravirt") + ui.paravirt.checked = true; + else if (data.config.virt_mode == "fullvirt") + ui.fullvirt.checked = true; + showHideFullvirt(null); + + // Kernel + if (data.kernels.length) + ui.kernel.value = data.config.kernel; + + // Run level + if (data.config.run_level == "default") + ui["default"].checked = true; + else if (data.config.run_level == "single") + ui.single.checked = true; + else if (data.config.run_level == "binbash") + ui.binbash.checked = true; + + // Memory limit + if (data.config.memory_limit == 0) { + ui.noLimit.checked = true; + } else { + ui.limit.checked = true; + ui.memLimit.value = data.config.memory_limit; + } + + // Disk configuration + if (state.haveDisks && state.haveVolumes) + displayDrives(); + if (data.config.initrd) + ui.initrd.value = data.config.initrd; + if (/^\/dev\/sd[a-h]$/.test(data.config.root_device)) { + ui.standard.checked = true; + ui.bootDeviceStandard.value = data.config.root_device; + } else { + ui.custom.checked = true; + ui.bootDeviceCustom.value = data.config.root_device; + } + + // Helpers + if (data.config.helpers.distro) + ui.distroHelper.checked = true; + else + ui.distroHelperNo.checked = true; + if (data.config.helpers.updatedb_disabled) + ui.updatedbHelper.checked = true; + else + ui.updatedbHelperNo.checked = true; + if (data.config.helpers.modules_dep) + ui.modulesHelper.checked = true; + else + ui.modulesHelperNo.checked = true; + if (data.config.helpers.devtmpfs_automount) + ui.devtmpfsHelper.checked = true; + else + ui.devtmpfsHelperNo.checked = true; + if (data.config.helpers.network) + ui.networkHelper.checked = true; + else + ui.networkHelperNo.checked = true; + + ui.saveButton.disabled = false; + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Display memory limits + ui.maxMem.innerHTML = data.linode.specs.memory; + ui.memLimit.max = data.linode.specs.memory; + + // Get list of volumes + apiGet("/volumes", displayVolumes, null); + }; + + // Callback for linode disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + state.haveDisks = true; + + // Add disks to selectors + for (var i = data.disks.length - 1; i >= 0; i--) { + var disk = document.createElement("option"); + disk.value = "disk-" + data.disks[i].id; + disk.innerHTML = data.disks[i].label; + + for (var j = 0; j < ui.disks.length; j++) + ui.disks[j].prepend(disk.cloneNode(true)); + } + + if (data.config.devices && state.haveVolumes) + displayDrives(); + }; + + // Sets the values for the drive selectors + var displayDrives = function() + { + for (var drive in data.config.devices) { + if (!data.config.devices[drive]) + continue; + + if (data.config.devices[drive].disk_id) + ui[drive].value = "disk-" + data.config.devices[drive].disk_id; + else if (data.config.devices[drive].volume_id) + ui[drive].value = "volume-" + data.config.devices[drive].volume_id; + } + }; + + // Callback for linode kernels API call + var displayKernels = function(response) + { + // Add kernels to array + data.kernels = data.kernels.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/kernels?page=" + (response.page + 1), displayKernels, null); + return; + } + + // Add kernels to selector + for (var i = 0; i < data.kernels.length; i++) { + var kernel = document.createElement("option"); + kernel.value = data.kernels[i].id; + kernel.innerHTML = data.kernels[i].label; + ui.kernel.appendChild(kernel); + + if (data.params.cid == 0 && data.kernels[i].id == settings.preferredKernel) + ui.kernel.value = data.kernels[i].id; + } + + if (data.config.kernel) + ui.kernel.value = data.config.kernel; + }; + + // Callback for account settings API call + var displaySettings = function(response) + { + if (response.network_helper) + ui.networkHelper.checked = true; + else + ui.networkHelperNo.checked = true; + }; + + // Callback for volumes API call + var displayVolumes = function(response) + { + // Add volumes to array + data.volumes = data.volumes.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/volumes?page=" + (response.page + 1), displayVolumes, null); + return; + } + + state.haveVolumes = true; + + // Add volumes from this Linode's region to selectors + for (var i = 0; i < data.volumes.length; i++) { + if (data.volumes[i].region != data.linode.region) + continue; + if (data.volumes[i].linode_id && data.volumes[i].linode_id != data.params.lid) + continue; + + var volume = document.createElement("option"); + volume.value = "volume-" + data.volumes[i].id; + volume.innerHTML = data.volumes[i].label; + for (var j = 0; j < ui.volumes.length; j++) + ui.volumes[j].appendChild(volume.cloneNode(true)); + } + + if (data.config.devices && state.haveDisks) + displayDrives(); + }; + + // Save button handler + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "label": ui.label.value, + "comments": ui.notes.value, + "kernel": ui.kernel.value, + "devices": {}, + "helpers": { + "distro": ui.distroHelper.checked, + "updatedb_disabled": ui.updatedbHelper.checked, + "modules_dep": ui.modulesHelper.checked, + "devtmpfs_automount": ui.devtmpfsHelper.checked, + "network": ui.networkHelper.checked + } + }; + + if (ui.paravirt.checked) + req.virt_mode = "paravirt"; + else if (ui.fullvirt.checked) + req.virt_mode = "fullvirt"; + + if (ui["default"].checked) + req.run_level = "default"; + else if (ui.single.checked) + req.run_level = "single"; + else if (ui.binbash.checked) + req.run_level = "binbash"; + + if (ui.noLimit.checked) + req.memory_limit = 0; + else + req.memory_limit = parseInt(ui.memLimit.value); + + if (ui.sda.value.startsWith("disk-")) + req.devices.sda = { "disk_id": parseInt(ui.sda.value.substring(5)) }; + else if (ui.sda.value.startsWith("volume-")) + req.devices.sda = { "volume_id": parseInt(ui.sda.value.substring(7)) }; + if (ui.sdb.value.startsWith("disk-")) + req.devices.sdb = { "disk_id": parseInt(ui.sdb.value.substring(5)) }; + else if (ui.sdb.value.startsWith("volume-")) + req.devices.sdb = { "volume_id": parseInt(ui.sdb.value.substring(7)) }; + if (ui.sdc.value.startsWith("disk-")) + req.devices.sdc = { "disk_id": parseInt(ui.sdc.value.substring(5)) }; + else if (ui.sdc.value.startsWith("volume-")) + req.devices.sdc = { "volume_id": parseInt(ui.sdc.value.substring(7)) }; + if (ui.sdd.value.startsWith("disk-")) + req.devices.sdd = { "disk_id": parseInt(ui.sdd.value.substring(5)) }; + else if (ui.sdd.value.startsWith("volume-")) + req.devices.sdd = { "volume_id": parseInt(ui.sdd.value.substring(7)) }; + if (ui.paravirt.checked) { + if (ui.sde.value.startsWith("disk-")) + req.devices.sde = { "disk_id": parseInt(ui.sde.value.substring(5)) }; + else if (ui.sde.value.startsWith("volume-")) + req.devices.sde = { "volume_id": parseInt(ui.sde.value.substring(7)) }; + if (ui.sdf.value.startsWith("disk-")) + req.devices.sdf = { "disk_id": parseInt(ui.sdf.value.substring(5)) }; + else if (ui.sdf.value.startsWith("volume-")) + req.devices.sdf = { "volume_id": parseInt(ui.sdf.value.substring(7)) }; + if (ui.sdg.value.startsWith("disk-")) + req.devices.sdg = { "disk_id": parseInt(ui.sdg.value.substring(5)) }; + else if (ui.sdg.value.startsWith("volume-")) + req.devices.sdg = { "volume_id": parseInt(ui.sdg.value.substring(7)) }; + if (ui.sdh.value.startsWith("disk-")) + req.devices.sdh = { "disk_id": parseInt(ui.sdh.value.substring(5)) }; + else if (ui.sdh.value.startsWith("volume-")) + req.devices.sdh = { "volume_id": parseInt(ui.sdh.value.substring(7)) }; + } + + var initrd = parseInt(ui.initrd.value); + if (initrd == 0) + req.initrd = null; + else + req.initrd = initrd; + + if (ui.standard.checked) + req.root_device = ui.bootDeviceStandard.value; + else + req.root_device = ui.bootDeviceCustom.value; + + if (data.params.cid == 0) { + apiPost("/linode/instances/" + data.params.lid + "/configs", req, function(response) { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + } else { + apiPut("/linode/instances/" + data.params.lid + "/configs/" + data.params.cid, req, function(response) { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + // We also need a config ID + if (!data.params.cid) { + alert("No config ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) { + anchors[i].href = anchors[i].href.replace("lid=00", data.params.lid); + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + } + + // Highlight the dashboard subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/dashboard") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.binbash = document.getElementById(elements.binbash); + ui.bootDeviceCustom = document.getElementById(elements.bootDeviceCustom); + ui.bootDeviceStandard = document.getElementById(elements.bootDeviceStandard); + ui.custom = document.getElementById(elements.custom); + ui["default"] = document.getElementById(elements["default"]); + ui.devtmpfsHelper = document.getElementById(elements.devtmpfsHelper); + ui.devtmpfsHelperNo = document.getElementById(elements.devtmpfsHelperNo); + ui.disks = document.getElementsByClassName(elements.disks); + ui.distroHelper = document.getElementById(elements.distroHelper); + ui.distroHelperNo = document.getElementById(elements.distroHelperNo); + ui.fullvirt = document.getElementById(elements.fullvirt); + ui.fullvirtHide = document.getElementsByClassName(elements.fullvirtHide); + ui.initrd = document.getElementById(elements.initrd); + ui.kernel = document.getElementById(elements.kernel); + ui.label = document.getElementById(elements.label); + ui.limit = document.getElementById(elements.limit); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.maxMem = document.getElementById(elements.maxMem); + ui.memLimit = document.getElementById(elements.memLimit); + ui.modulesHelper = document.getElementById(elements.modulesHelper); + ui.modulesHelperNo = document.getElementById(elements.modulesHelperNo); + ui.networkHelper = document.getElementById(elements.networkHelper); + ui.networkHelperNo = document.getElementById(elements.networkHelperNo); + ui.noLimit = document.getElementById(elements.noLimit); + ui.notes = document.getElementById(elements.notes); + ui.paravirt = document.getElementById(elements.paravirt); + ui.saveButton = document.getElementById(elements.saveButton); + ui.sda = document.getElementById(elements.sda); + ui.sdb = document.getElementById(elements.sdb); + ui.sdc = document.getElementById(elements.sdc); + ui.sdd = document.getElementById(elements.sdd); + ui.sde = document.getElementById(elements.sde); + ui.sdf = document.getElementById(elements.sdf); + ui.sdg = document.getElementById(elements.sdg); + ui.sdh = document.getElementById(elements.sdh); + ui.single = document.getElementById(elements.single); + ui.standard = document.getElementById(elements.standard); + ui.updatedbHelper = document.getElementById(elements.updatedbHelper); + ui.updatedbHelperNo = document.getElementById(elements.updatedbHelperNo); + ui.volumes = document.getElementsByClassName(elements.volumes); + + // Register event handlers + ui.fullvirt.addEventListener("input", showHideFullvirt); + ui.paravirt.addEventListener("input", showHideFullvirt); + ui.saveButton.addEventListener("click", handleSave); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/kernels", displayKernels, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + if (data.params.cid == 0) { + apiGet("/account/settings", displaySettings, null); + ui.saveButton.disabled = false; + } else { + apiGet("/linode/instances/" + data.params.lid + "/configs/" + data.params.cid, displayConfig, null); + } + }; + + // Show/hide rows for fullvirt + var showHideFullvirt = function(event) + { + var display = "table-row"; + if (ui.fullvirt.checked) + display = "none"; + + for (var i = 0; i < ui.fullvirtHide.length; i++) + ui.fullvirtHide[i].style.display = display; + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/config/index.shtml b/linodes/config/index.shtml new file mode 100644 index 0000000..4321310 --- /dev/null +++ b/linodes/config/index.shtml @@ -0,0 +1,326 @@ + + + + + + LMC - Edit Configuration Profile + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Configuration Profile
      Label and Notes
      Label
      Notes
      Virtual Machine Mode
      VM Mode + +
      + + +
      + + Controls if devices inside your virtual machine are paravirtualized or fully virtualized.
      + Paravirt is what you want, unless you're doing weird things. +
      +
      Boot Settings
      Kernel + +
      Run Level + +
      + +
      + + +
      Memory Limit + + MB
      + + +
      Block Device Assignment
      /dev/sda + +
      /dev/sdb + +
      /dev/sdc + +
      /dev/sdd + +
      /dev/sde + +
      /dev/sdf + +
      /dev/sdg + +
      /dev/sdh + +
      initrd + +
      root / boot device + + +
      + + + +
      Filesystem/Boot Helpers
      Distro Helper + + + + + Helps maintain correct inittab/upstart console device
      Disable updatedb + + + + + Disables updatedb cron job to avoid disk thrashing
      modules.dep Helper + + + + + Creates a modules dependency file for the kernel you run
      Automount devtmpfs + + + + + Controls if pv_ops kernels automount devtmpfs at boot
      Auto-configure Networking + + + + + Automatically configure static networking (more info)
      +
      +
      + + diff --git a/linodes/dashboard/dashboard.css b/linodes/dashboard/dashboard.css new file mode 100644 index 0000000..de6e6d7 --- /dev/null +++ b/linodes/dashboard/dashboard.css @@ -0,0 +1,199 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +.backups-enabled { + font-weight: bold; +} + +#boot { + margin-top: 5px; +} + +.disk-icon { + height: 24px; + width: 26px; +} + +.extra-event { + display: none; +} + +h3 { + border-bottom: 1px solid #E8E8E8; + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 18px; + font-weight: lighter; + margin-bottom: 50px; +} + +.job-failed { + background-color: #C13100; + color: #FFF; + display: block; + padding: 5px; + text-align: center; +} + +.job-info { + color: #777; + font-size: 10px; +} + +.job-notice { + background-color: #3683DC; + color: #FFF; + display: block; + padding: 5px; + text-align: center; +} + +#job-progress { + background-color: #A9A9A9; + display: block; + color: #31B96E; + width: calc(100% - 2px); +} + +#job-progress::-moz-progress-bar { + background-color: #31B96E; +} + +#job-progress::-webkit-progress-bar { + background-color: #A9A9A9; +} + +#job-progress::-webkit-progress-value { + background-color: #31B96E; +} + +#job-progress-row { + display: none; +} + +#job-progress-row td { + padding: 0; +} + +.job-running { + text-align: right; +} + +.job-success { + background-color: #31B96E; + color: #FFF; + display: block; + padding: 5px; + text-align: center; +} + +.job-type { + font-weight: bold; +} + +#last-backup { + display: none; +} + +#linode-details { + display: inline-block; + padding: 0px 15px 20px; + text-overflow: ellipsis; + width: 75%; +} + +#linode-sidebar { + float: right; + margin-right: 15px; + width: calc(25% - 45px); +} + +.lmc-table td { + white-space: nowrap; +} + +.lmc-table td:nth-child(2) { + width: 100%; +} + +#moar-jobs { + font-size: 13px; + font-weight: normal; +} + +#notifications { + padding: 0px 15px; +} + +#reboot { + display: none; + margin-top: 5px; +} + +#server-status { + font-weight: bold; + font-size: 18px; +} + +#shut-down { + display: none; + font-size: 14px; + margin: 0 auto 15px; +} + +.sidebar-box { + border: 1px dotted #999; + font-size: 12px; + margin-bottom: 15px; +} + +.sidebar-box a { + font-weight: bold; +} + +.sidebar-box h4 { + background-color: #E5E5E5; + font-size: 15px; + margin: 0; + padding: 2px; +} + +.sidebar-box meter { + display: block; + margin: 0 auto 10px; + width: 90%; +} + +.sidebar-box p { + margin: 10px; + text-align: center; +} + +.sidebar-box ul { + list-style-position: inside; + padding-left: 15px; +} + +.sub-links-inline { + display: inline-block; + float: right; +} + +#uptime { + display: none; +} diff --git a/linodes/dashboard/dashboard.js b/linodes/dashboard/dashboard.js new file mode 100644 index 0000000..747a103 --- /dev/null +++ b/linodes/dashboard/dashboard.js @@ -0,0 +1,887 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiDelete, apiGet, apiPost, eventTitles, parseParams, setupHeader, timeString, translateKernel } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.backups = "backups"; + elements.backupsEnabled = "backups-enabled"; + elements.boot = "boot"; + elements.configRadioName = "config-radio"; + elements.configRemovePrefix = "config-remove-"; + elements.configTable = "config-table"; + elements.diskIcon = "disk-icon"; + elements.diskIconImg = "/img/disk.gif"; + elements.diskRemovePrefix = "disk-remove-"; + elements.diskTable = "disk-table"; + elements.diskUsage = "disk-usage"; + elements.eventRowPrefix = "event-row-"; + elements.eventTable = "event-table"; + elements.extraEvent = "extra-event"; + elements.info = "info"; + elements.jobFailed = "job-failed"; + elements.jobInfo = "job-info"; + elements.jobNotice = "job-notice"; + elements.jobProgress = "job-progress"; + elements.jobProgressRow = "job-progress-row"; + elements.jobRunning = "job-running"; + elements.jobSuccess = "job-success"; + elements.jobType = "job-type"; + elements.lastBackup = "last-backup"; + elements.lastBackupTime = "last-backup-time"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr3"; + elements.loadingConfigs = "loading-configs"; + elements.loadingDisks = "loading-disks"; + elements.loadingJobs = "loading-jobs"; + elements.loadingVolumes = "loading-volumes"; + elements.moreJobs = "moar-jobs"; + elements.netUsage = "net-usage"; + elements.notification = "notification"; + elements.notifications = "notifications"; + elements.reboot = "reboot"; + elements.serverStatus = "server-status"; + elements.shutDown = "shut-down"; + elements.spinnerImg = "/img/spinner-trans.gif"; + elements.storageFree = "storage-free"; + elements.storageTotal = "storage-total"; + elements.storageUsed = "storage-used"; + elements.transferMonthly = "transfer-monthly"; + elements.transferOverage = "transfer-overage"; + elements.transferUsed = "transfer-used"; + elements.volumeTable = "volume-table"; + + // Data recieved from API calls + var data = {}; + data.params = {}; + data.configs = []; + data.disks = []; + data.events = []; + data.linode = {}; + data.linodeTransfer = {}; + data.notifications = []; + data.volumes = []; + + // Static references to UI elements + var ui = {}; + ui.backups = {}; + ui.boot = {}; + ui.configTable = {}; + ui.diskTable = {}; + ui.diskUsage = {}; + ui.eventTable = {}; + ui.jobProgress = {}; + ui.jobProgressRow = {}; + ui.lastBackup = {}; + ui.lastBackupTime = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.loadingConfigs = {}; + ui.loadingDisks = {}; + ui.loadingJobs = {}; + ui.loadingVolumes = {}; + ui.moreJobs = {}; + ui.netUsage = {}; + ui.notifications = {}; + ui.reboot = {}; + ui.serverStatus = {}; + ui.shutDown = {}; + ui.storageFree = {}; + ui.storageTotal = {}; + ui.storageUsed = {}; + ui.transferMonthly = {}; + ui.transferOverage = {}; + ui.transferUsed = {}; + ui.volumeTable = {}; + + // Temporary state + var state = {}; + state.diskRefresh = false; + state.eventsComplete = 0; + state.linodeRefresh = false; + state.showExtraEvents = false; + + // Button handler for boot button + var bootLinode = function(event) + { + if (!confirm("Boot this Linode?")) + return; + + var config = getSelectedConfig(); + var request = {}; + if (config) + request.config_id = config; + + // Reload the page on successful API return + var callback = function() + { + location.reload(); + }; + + apiPost("/linode/instances/" + data.params.lid + "/boot", request, callback); + }; + + // Convert a byte count into a "friendly" byte string (KB, MB, GB, etc) + var byteString = function(count) + { + var prefix = "KMGTPEZY"; + var unit = ""; + + for (var i = 0; i < prefix.length; i++) { + if (count >= 1024) { + count /= 1024; + unit = prefix.charAt(i); + } else { + break; + } + } + + return count.toFixed(2) + " " + unit + "B"; + }; + + // Generate a config profile table row + var createConfigRow = function(config) + { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + // Radio button selector + var radioCell = document.createElement("td"); + var radioInput = document.createElement("input"); + radioInput.name = elements.configRadioName; + radioInput.className = elements.configRadioName; + radioInput.id = elements.configRadioName + "-" + config.id; + radioInput.type = "radio"; + radioCell.appendChild(radioInput); + row.appendChild(radioCell); + + // Config profile name and kernel + var nameCell = document.createElement("td"); + var nameLink = document.createElement("a"); + nameLink.href = "/linodes/config?cid=" + config.id + "&lid=" + data.params.lid; + if (config.label.length > 41) + nameLink.innerHTML = config.label.substring(0, 41) + "..."; + else + nameLink.innerHTML = config.label; + nameCell.appendChild(nameLink); + var prefix = document.createElement("span"); + prefix.className = elements.info; + prefix.innerHTML = " ("; + nameCell.appendChild(prefix); + var kernel = document.createElement("span"); + kernel.className = elements.info; + translateKernel(config.kernel, kernel); + nameCell.appendChild(kernel); + var suffix = document.createElement("span"); + suffix.className = elements.info; + suffix.innerHTML = ")"; + nameCell.appendChild(suffix); + row.appendChild(nameCell); + + // Option links + var options = document.createElement("td"); + var editLink = document.createElement("a"); + editLink.href = "/linodes/config?cid=" + config.id + "&lid=" + data.params.lid; + editLink.innerHTML = "Edit"; + var separator = document.createElement("span"); + separator.innerHTML = " | "; + var removeLink = document.createElement("a"); + removeLink.href = "#"; + removeLink.id = elements.configRemovePrefix + config.id; + removeLink.innerHTML = "Remove"; + removeLink.addEventListener("click", deleteConfig); + options.appendChild(editLink); + options.appendChild(separator); + options.appendChild(removeLink); + row.appendChild(options); + + return row; + }; + + // Generate a disk table row + var createDiskRow = function(disk) + { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + // Disk icon + var iconCell = document.createElement("td"); + var diskIcon = document.createElement("img"); + diskIcon.className = elements.diskIcon; + diskIcon.src = elements.diskIconImg; + iconCell.appendChild(diskIcon); + row.appendChild(iconCell); + + // Disk name and size + var nameCell = document.createElement("td"); + var nameLink = document.createElement("a"); + nameLink.href = "/linodes/disk?did=" + disk.id + "&lid=" + data.params.lid; + nameLink.innerHTML = disk.label; + var size = document.createElement("span"); + size.className = elements.info; + size.innerHTML = " (" + disk.size + " MB, " + disk.filesystem + ")"; + nameCell.appendChild(nameLink); + nameCell.appendChild(size); + row.appendChild(nameCell); + + // Options links + var options = document.createElement("td"); + var editLink = document.createElement("a"); + editLink.href = "/linodes/disk?did=" + disk.id + "&lid=" + data.params.lid; + editLink.innerHTML = "Edit"; + var separator = document.createElement("span"); + separator.innerHTML = " | "; + var removeLink = document.createElement("a"); + removeLink.href = "#"; + removeLink.id = elements.diskRemovePrefix + disk.id; + removeLink.innerHTML = "Remove"; + removeLink.addEventListener("click", deleteDisk); + options.appendChild(editLink); + options.appendChild(separator); + options.appendChild(removeLink); + row.appendChild(options); + + return row; + }; + + // Generate an event table row + var createEventRow = function(event, extra) + { + var row = document.createElement("tr"); + row.id = elements.eventRowPrefix + event.id; + row.className = elements.lmcRow; + if (extra) + row.className += " " + elements.extraEvent; + + // Status cell + var statusCell = document.createElement("td"); + if (event.status.match(/scheduled|started/)) { + statusCell.className = elements.jobRunning; + var spinner = document.createElement("img"); + spinner.src = elements.spinnerImg; + statusCell.appendChild(spinner); + } else if (event.status == "failed") { + var failed = document.createElement("span"); + failed.className = elements.jobFailed; + failed.innerHTML = "Failed"; + statusCell.appendChild(failed); + } else if (event.status == "notification") { + var notice = document.createElement("span"); + notice.className = elements.jobNotice; + notice.innerHTML = "Notice"; + statusCell.appendChild(notice); + } else if (event.status == "finished") { + var success = document.createElement("span"); + success.className = elements.jobSuccess; + success.innerHTML = "Success"; + statusCell.appendChild(success); + } + row.appendChild(statusCell); + + // Details cell + var detailsCell = document.createElement("td"); + var jobType = document.createElement("span"); + jobType.className = elements.jobType; + if (eventTitles[event.action]) + jobType.innerHTML = eventTitles[event.action]; + else + jobType.innerHTML = event.action; + var jobDetails = document.createElement("span"); + if (event.secondary_entity) + jobDetails.innerHTML = " - " + event.secondary_entity.label; + var br = document.createElement("br"); + var jobInfo = document.createElement("span"); + jobInfo.className = elements.jobInfo; + var eventDate = new Date(event.created + "Z"); + var curDate = new Date(); + jobInfo.innerHTML = "Entered: " + timeString(curDate - eventDate, true); + if (event.percent_complete && event.percent_complete != 100) + jobInfo.innerHTML += " - " + event.percent_complete + "%"; + if (event.time_remaining) { + var times = event.time_remaining.split(":"); + var ms = 0; + ms += parseInt(times[0]) * 3600000; + ms += parseInt(times[1]) * 60000; + ms += parseInt(times[2]) * 1000; + jobInfo.innerHTML += " - " + timeString(ms, false) + " Remaining"; + } + detailsCell.appendChild(jobType); + detailsCell.appendChild(jobDetails); + detailsCell.appendChild(br); + detailsCell.appendChild(jobInfo); + row.appendChild(detailsCell); + + return row; + }; + + // Generate a volume table row + var createVolumeRow = function(volume) + { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + // Disk icon + var iconCell = document.createElement("td"); + var diskIcon = document.createElement("img"); + diskIcon.className = elements.diskIcon; + diskIcon.src = elements.diskIconImg; + iconCell.appendChild(diskIcon); + row.appendChild(iconCell); + + // Volume name and size + var nameCell = document.createElement("td"); + var nameLink = document.createElement("a"); + nameLink.href = "/volumes/settings?vid=" + volume.id; + nameLink.innerHTML = volume.label; + var size = document.createElement("span"); + size.className = elements.info; + size.innerHTML = " (" + volume.size + " GiB)"; + nameCell.appendChild(nameLink); + nameCell.appendChild(size); + row.appendChild(nameCell); + + // Options links + var options = document.createElement("td"); + var editLink = document.createElement("a"); + editLink.href = "/volumes/settings?vid=" + volume.id; + editLink.innerHTML = "Edit"; + var separator = document.createElement("span"); + separator.innerHTML = " | "; + var cloneLink = document.createElement("a"); + cloneLink.href = "/volumes/clone?vid=" + volume.id; + cloneLink.innerHTML = "Clone"; + var detachLink = document.createElement("a"); + detachLink.href = "/volumes/detach?vid=" + volume.id; + detachLink.innerHTML = "Detach"; + var removeLink = document.createElement("a"); + removeLink.href = "/volumes/remove?vid=" + volume.id; + removeLink.innerHTML = "Remove"; + options.appendChild(editLink); + options.appendChild(separator); + options.appendChild(cloneLink); + options.appendChild(separator.cloneNode(true)); + options.appendChild(detachLink); + options.appendChild(separator.cloneNode(true)); + options.appendChild(removeLink); + row.appendChild(options); + + return row; + }; + + // Handler for config delete + var deleteConfig = function(event) + { + if (!confirm("Delete this Configuration Profile?")) + return; + + var cid = event.currentTarget.id.substring(elements.configRemovePrefix.length); + apiDelete("/linode/instances/" + data.params.lid + "/configs/" + cid, function() + { + location.reload(); + }); + }; + + // Handler for disk delete + var deleteDisk = function(event) + { + var did = parseInt(event.currentTarget.id.substring(elements.diskRemovePrefix.length)); + var disk = null; + for (var i = 0; i < data.disks.length; i++) { + if (data.disks[i].id == did) { + disk = data.disks[i]; + break; + } + } + + if (!disk) + return; + + if (!confirm("Delete " + disk.label + "?")) + return; + + apiDelete("/linode/instances/" + data.params.lid + "/disks/" + did, function() + { + location.reload(); + }); + }; + + // Callback for backups API call + var displayBackups = function(response) + { + // Find time of most recent backup + var mostRecent = new Date(0); + for (var i = 0; i < response.automatic.length; i++) { + if (response.automatic[i].status == "successful") { + var time = new Date(response.automatic[i].finished + "Z"); + if (time > mostRecent) + mostRecent = time; + } + } + if (response.snapshot.current && response.snapshot.current.status == "successful") { + var time = new Date(response.snapshot.current.finished + "Z"); + if (time > mostRecent) + mostRecent = time; + } + + // 1970 means no backups happened + if (mostRecent.getUTCFullYear() == 1970) + return; + + var curDate = new Date(); + ui.lastBackupTime.innerHTML = timeString(curDate - mostRecent, true); + ui.lastBackup.style.display = "block"; + }; + + // Callback for config profile API call + var displayConfigs = function(response) + { + // Add configs to array + data.configs = data.configs.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/configs?page=" + (response.page + 1), displayConfigs, null); + return; + } + + // Remove loading row + ui.loadingConfigs.remove(); + + // Insert config profile rows into table + for (var i = 0; i < data.configs.length; i++) + ui.configTable.appendChild(createConfigRow(data.configs[i])); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + if (document.title.indexOf("//") == -1) + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } else { + ui.linodeTag.style.display = "none"; + } + + // Set running status + ui.serverStatus.innerHTML = data.linode.status.charAt(0).toUpperCase() + data.linode.status.slice(1).replace(/_/g, " "); + if (data.linode.status == "running") { + ui.shutDown.disabled = false; + ui.shutDown.style.display = "block"; + } else { + ui.shutDown.style.display = "none"; + } + if (data.linode.status.match(/offline|provisioning|migrating|rebuilding|restoring|shutting_down|resizing/)) { + ui.reboot.style.display = "none"; + ui.boot.disabled = false; + ui.boot.style.display = "inline"; + } else if (data.linode.status != "cloning") { + ui.boot.style.display = "none"; + ui.reboot.disabled = false; + ui.reboot.style.display = "inline"; + } + + // Update storage info + displayStorage(); + + // Set backup status + if (data.linode.backups.enabled) { + ui.backups.innerHTML = "Enabled!"; + ui.backups.className += " " + elements.backupsEnabled; + } else { + ui.backups.innerHTML = ""; + var text = document.createElement("span"); + text.innerHTML = "No - "; + var backupLink = document.createElement("a"); + backupLink.href = "/linodes/backups_enable?lid=" + data.params.lid; + backupLink.innerHTML = "Enable"; + backups.appendChild(text); + backups.appendChild(backupLink); + } + + state.linodeRefresh = false; + }; + + // Callback for disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + // Remove loading row + ui.loadingDisks.remove(); + + // Update storage info + displayStorage(); + + // Insert disk rows into table + ui.diskTable.innerHTML = ""; + for (var i = 0; i < data.disks.length; i++) + ui.diskTable.appendChild(createDiskRow(data.disks[i])); + + state.diskRefresh = false; + }; + + // Callback for events API call + var displayEvents = function(response) + { + // Only collect a max of 8 finished jobs + for (var i = 0; i < response.data.length && state.eventsComplete < 8; i++) { + if (response.data[i].status.match(/failed|finished|notification/)) + state.eventsComplete++; + data.events.push(response.data[i]); + } + + // Request the next page if there are more + if (state.eventsComplete < 8 && response.page != response.pages) { + var filter = { + "entity.type": "linode", + "entity.id": parseInt(data.params.lid) + }; + apiGet("/account/events?page=" + (response.page + 1), displayEvents, filter); + return; + } + + // Remove loading row + ui.loadingJobs.remove(); + + // Insert events into table and compute total progress + var progress = 0; + var totalProgress = 0; + for (var i = 0; i < data.events.length; i++) { + var extra = (data.events[i].status.match(/failed|finished|notification/) && i >= 4); + ui.eventTable.appendChild(createEventRow(data.events[i], extra)); + if (!data.events[i].status.match(/failed|finished|notification/)) { + totalProgress += 100; + progress += data.events[i].percent_complete; + // Set refresh timer for event + window.setTimeout(getEvent, settings.refreshRate, data.events[i].id); + } + } + + // If there are ongoing events, show the progress bar + if (totalProgress) { + ui.jobProgress.max = totalProgress; + ui.jobProgress.value = progress; + ui.jobProgress.innerHTML = (progress / totalProgress * 100).toFixed(0) + "%"; + ui.jobProgress.title = ui.jobProgress.innerHTML; + ui.jobProgressRow.style.display = "table-row"; + } + }; + + // Callback for notifications API call + var displayNotifications = function(response) + { + // Add notifications to array + data.notifications = data.notifications.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/account/notifications?page=" + (response.page + 1), displayNotifications, null); + return; + } + + // Display notifications + for (var i = 0; i < data.notifications.length; i++) { + if (!data.notifications[i].entity || data.notifications[i].entity.type != "linode" || data.notifications[i].entity.id != data.params.lid) + continue; + + var notification = document.createElement("div"); + notification.className = elements.notification; + var header = document.createElement("h1"); + header.innerHTML = data.notifications[i].label; + notification.appendChild(header); + if (data.notifications[i].type == "migration_pending") { + var migrateButton = document.createElement("button"); + migrateButton.type = "button"; + migrateButton.innerHTML = "Migrate " + data.notifications[i].entity.label + " NOW"; + migrateButton.addEventListener("click", initiateMigration); + notification.appendChild(migrateButton); + } + var body = document.createElement("p"); + body.innerHTML = data.notifications[i].message; + notification.appendChild(body); + ui.notifications.appendChild(notification); + } + }; + + // Show storage totals + var displayStorage = function() + { + if (!data.linode.specs) + return; + + ui.storageTotal.innerHTML = data.linode.specs.disk + " MB"; + var storageUsed = 0; + for (var i = 0; i < data.disks.length; i++) + storageUsed += data.disks[i].size; + ui.storageUsed.innerHTML = storageUsed + " MB"; + ui.storageFree.innerHTML = (data.linode.specs.disk - storageUsed) + " MB"; + ui.diskUsage.value = (storageUsed / data.linode.specs.disk * 100).toFixed(0); + ui.diskUsage.innerHTML = ui.diskUsage.value + "%"; + ui.diskUsage.title = ui.diskUsage.innerHTML; + }; + + // Callback for network transfer API call + var displayTransfer = function(response) + { + data.linodeTransfer = response; + + // Display network transfer info + ui.transferMonthly.innerHTML = data.linodeTransfer.quota + " GB"; + ui.transferUsed.innerHTML = byteString(data.linodeTransfer.used); + ui.transferOverage.innerHTML = data.linodeTransfer.billable + " GB"; + ui.netUsage.value = ((data.linodeTransfer.used / 1024 / 1024 / 1024) / data.linodeTransfer.quota * 100).toFixed(0); + ui.netUsage.innerHTML = ui.netUsage.value + "%"; + ui.netUsage.title = ui.netUsage.innerHTML; + }; + + // Callback for volumes API call + var displayVolumes = function(response) + { + // Add volumes to array + data.volumes = data.volumes.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/volumes?page=" + (response.page + 1), displayVolumes, null); + return; + } + + // Remove loading row + ui.loadingVolumes.remove(); + + // Insert volume rows into table + for (var i = 0; i < data.volumes.length; i++) + ui.volumeTable.appendChild(createVolumeRow(data.volumes[i])); + }; + + // Retrieve the given event from the API + var getEvent = function(eventID) + { + apiGet("/account/events/" + eventID, updateEvent, null); + }; + + // Get selected config profile + var getSelectedConfig = function() + { + var configs = document.getElementsByClassName(elements.configRadioName); + for (var i = 0; i < configs.length; i++) { + if (configs[i].checked) + return parseInt(configs[i].id.replace(elements.configRadioName + "-", "")); + } + + return 0; + }; + + // Button handler to initiate migration + var initiateMigration = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "upgrade": false + }; + apiPost("/linode/instances/" + data.params.lid + "/migrate", req, function(response) + { + location.reload(); + }); + }; + + // Button handler for reboot button + var rebootLinode = function(event) + { + if (!confirm("Are you sure you want to issue a Reboot?")) + return; + + var config = getSelectedConfig(); + var request = {}; + if (config) + request.config_id = config; + + // Reload the page on successful API return + var callback = function() + { + location.reload(); + }; + + apiPost("/linode/instances/" + data.params.lid + "/reboot", request, callback); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.backups = document.getElementById(elements.backups); + ui.boot = document.getElementById(elements.boot); + ui.configTable = document.getElementById(elements.configTable); + ui.diskTable = document.getElementById(elements.diskTable); + ui.diskUsage = document.getElementById(elements.diskUsage); + ui.eventTable = document.getElementById(elements.eventTable); + ui.jobProgress = document.getElementById(elements.jobProgress); + ui.jobProgressRow = document.getElementById(elements.jobProgressRow); + ui.lastBackup = document.getElementById(elements.lastBackup); + ui.lastBackupTime = document.getElementById(elements.lastBackupTime); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.loadingConfigs = document.getElementById(elements.loadingConfigs); + ui.loadingDisks = document.getElementById(elements.loadingDisks); + ui.loadingJobs = document.getElementById(elements.loadingJobs); + ui.loadingVolumes = document.getElementById(elements.loadingVolumes); + ui.moreJobs = document.getElementById(elements.moreJobs); + ui.netUsage = document.getElementById(elements.netUsage); + ui.notifications = document.getElementById(elements.notifications); + ui.reboot = document.getElementById(elements.reboot); + ui.serverStatus = document.getElementById(elements.serverStatus); + ui.shutDown = document.getElementById(elements.shutDown); + ui.storageFree = document.getElementById(elements.storageFree); + ui.storageTotal = document.getElementById(elements.storageTotal); + ui.storageUsed = document.getElementById(elements.storageUsed); + ui.transferMonthly = document.getElementById(elements.transferMonthly); + ui.transferOverage = document.getElementById(elements.transferOverage); + ui.transferUsed = document.getElementById(elements.transferUsed); + ui.volumeTable = document.getElementById(elements.volumeTable); + + // Attach button handlers + ui.boot.addEventListener("click", bootLinode); + ui.moreJobs.addEventListener("click", toggleEvents); + ui.reboot.addEventListener("click", rebootLinode); + ui.shutDown.addEventListener("click", shutDownLinode); + + // Get data from the API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/configs", displayConfigs, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + apiGet("/linode/instances/" + data.params.lid + "/volumes", displayVolumes, null); + apiGet("/linode/instances/" + data.params.lid + "/transfer", displayTransfer, null); + apiGet("/linode/instances/" + data.params.lid + "/backups", displayBackups, null); + var filter = { + "entity.type": "linode", + "entity.id": parseInt(data.params.lid) + }; + apiGet("/account/events", displayEvents, filter); + apiGet("/account/notifications", displayNotifications, null); + }; + + // Button handler for shutdown button + var shutDownLinode = function(event) + { + if (!confirm("Are you sure you want to issue a Shutdown?")) + return; + + // Reload the page on successful API return + var callback = function() + { + location.reload(); + }; + + apiPost("/linode/instances/" + data.params.lid + "/shutdown", {}, callback); + }; + + // Toggle visibility of "extra" events + var toggleEvents = function(event) + { + // Flip + state.showExtraEvents = !state.showExtraEvents; + + var display = "none"; + if (state.showExtraEvents) + display = "table-row"; + + // Get extra events and show/hide them + var extras = document.getElementsByClassName(elements.extraEvent); + for (var i = 0; i < extras.length; i++) + extras[i].style.display = display; + }; + + // Update an existing event + var updateEvent = function(event) + { + // Update the local copy of the event + var progress = 0; + for (var i = 0; i < data.events.length; i++) { + if (data.events[i].id == event.id) { + progress = event.percent_complete - data.events[i].percent_complete; + // Refresh details if event status changed + if (event.status != data.events[i].status && !state.linodeRefresh && !state.diskRefresh) { + state.linodeRefresh = true; + state.diskRefresh = true; + data.linode = {}; + data.disks = []; + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + } + data.events[i] = event; + continue; + } + } + + // Generate a new event row and replace the existing one + var eventRow = document.getElementById(elements.eventRowPrefix + event.id); + var extra = (eventRow.className.indexOf(elements.extraEvent) != -1); + eventRow.replaceWith(createEventRow(event, extra)); + + // Update progress bar + ui.jobProgress.value += progress; + ui.jobProgress.innerHTML = (ui.jobProgress.value / ui.jobProgress.max * 100).toFixed(0) + "%"; + ui.jobProgress.title = ui.jobProgress.innerHTML; + if (ui.jobProgress.value == ui.jobProgress.max) + ui.jobProgressRow.style.display = "none"; + + // Refresh again if not complete + if (!event.status.match(/failed|finished|notification/)) + window.setTimeout(getEvent, settings.refreshRate, event.id); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/dashboard/index.shtml b/linodes/dashboard/index.shtml new file mode 100644 index 0000000..62102e3 --- /dev/null +++ b/linodes/dashboard/index.shtml @@ -0,0 +1,142 @@ + + + + + + LMC - Dashboard + + + + + + + +
      + +
      +
      + + + + + + + + + + + + + + + + + + +
      Dashboard
      SelectConfiguration ProfilesOptions
      Loading configuration profiles...
      + + + + + + + + + + + + + + + + +
      Disks
      Loading disks...
      + + + + + + + + + + + + + + +
      Volumes
      Loading volumes...
      + + + + + + + + + + + + + + + + +
      Host Job Queue (more)
      50%
      Loading jobs...
      +

      Graphs

      +
      +
      + + + + +
      +
      + + diff --git a/linodes/deploy/deploy.css b/linodes/deploy/deploy.css new file mode 100644 index 0000000..beb6d03 --- /dev/null +++ b/linodes/deploy/deploy.css @@ -0,0 +1,35 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#deploy { + padding: 0px 15px 15px; +} + +#size { + width: 80px; +} + +tbody tr:last-of-type { + border: none; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/deploy/deploy.js b/linodes/deploy/deploy.js new file mode 100644 index 0000000..fbef9da --- /dev/null +++ b/linodes/deploy/deploy.js @@ -0,0 +1,243 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.currentDistros = "current"; + elements.customImages = "custom"; + elements.deletedDisks = "deleted"; + elements.deployButton = "deploy-button"; + elements.deprecatedDistros = "deprecated"; + elements.image = "image"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.maxSize = "max"; + elements.minSize = "min"; + elements.rootPass = "root-pass"; + elements.size = "size"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + + // Data recieved from API calls + var data = {}; + data.disks = []; + data.images = []; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.currentDistros = {}; + ui.customImages = {}; + ui.deletedDisks = {}; + ui.deployButton = {}; + ui.deprecatedDistros = {}; + ui.image = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.rootPass = {}; + ui.maxSize = {}; + ui.minSize = {}; + ui.size = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Get linode's disks + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + }; + + // Callback for disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + // Display max size + var free = data.linode.specs.disk; + for (var i = 0; i < data.disks.length; i++) + free -= data.disks[i].size; + + ui.maxSize.innerHTML = free; + ui.size.max = free; + ui.size.value = free; + }; + + // Callback for images API call + var displayImages = function(response) + { + // Add images to array + data.images = data.images.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/images?page=" + (response.page + 1), displayImages, null); + return; + } + + // Add images to selector + for (var i = 0; i < data.images.length; i++) { + var image = document.createElement("option"); + image.value = data.images[i].id; + image.innerHTML = data.images[i].label; + if (data.images[i].deprecated) + ui.deprecatedDistros.appendChild(image); + else if (data.images[i].type == "automatic") + ui.deletedDisks.appendChild(image); + else if (!data.images[i].vendor) + ui.customImages.appendChild(image); + else + ui.currentDistros.appendChild(image); + + if (data.images[i].id == settings.preferredDistro) { + ui.image.value = data.images[i].id; + ui.minSize.innerHTML = data.images[i].size; + ui.size.min = data.images[i].size; + } + } + + if (ui.customImages.childNodes.length == 0) + ui.customImages.style.display = "none"; + if (ui.deletedDisks.childNodes.length == 0) + ui.deletedDisks.style.display = "none"; + ui.deployButton.disabled = false; + }; + + // Handler for deploy button + var handleDeploy = function(event) + { + if (event.currentTarget.disabled) + return; + + var image = null; + for (var i = 0; i < data.images.length; i++) { + if (data.images[i].id == ui.image.value) { + image = data.images[i]; + break; + } + } + + if (!image) + return; + + var req = { + "label": image.label, + "size": parseInt(ui.size.value), + "image": ui.image.value, + "root_pass": ui.rootPass.value + }; + if (image.id.startsWith("linode/")) + req.label += " Disk"; + + apiPost("/linode/instances/" + data.params.lid + "/disks", req, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the dashboard subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/dashboard") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.currentDistros = document.getElementById(elements.currentDistros); + ui.customImages = document.getElementById(elements.customImages); + ui.deletedDisks = document.getElementById(elements.deletedDisks); + ui.deployButton = document.getElementById(elements.deployButton); + ui.deprecatedDistros = document.getElementById(elements.deprecatedDistros); + ui.image = document.getElementById(elements.image); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.maxSize = document.getElementById(elements.maxSize); + ui.minSize = document.getElementById(elements.minSize); + ui.rootPass = document.getElementById(elements.rootPass); + ui.size = document.getElementById(elements.size); + + // Register event handlers + ui.deployButton.addEventListener("click", handleDeploy); + ui.image.addEventListener("input", updateMinSize); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/images", displayImages, null); + }; + + // Update the mininum image size display + var updateMinSize = function() + { + var image = null; + for (var i = 0; i < data.images.length; i++) { + if (data.images[i].id == ui.image.value) { + image = data.images[i]; + break; + } + } + + if (!image) + return; + + ui.minSize.innerHTML = image.size; + ui.size.min = image.size; + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/deploy/index.shtml b/linodes/deploy/index.shtml new file mode 100644 index 0000000..0613d70 --- /dev/null +++ b/linodes/deploy/index.shtml @@ -0,0 +1,77 @@ + + + + + + LMC - Deploy + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Deploy an Image
      Image + + See also: Deploying using StackScripts
      Deployment Disk Size + MB
      + MB min MB max +
      Swap DiskA swap disk must be created separately.
      Root Password
      +
      +
      +
      + + diff --git a/linodes/disk/disk.css b/linodes/disk/disk.css new file mode 100644 index 0000000..e59b8c3 --- /dev/null +++ b/linodes/disk/disk.css @@ -0,0 +1,63 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#disk { + padding: 0px 15px 15px; +} + +h3 { + border-bottom: 1px solid #E8E8E8; + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 18px; + font-weight: lighter; + margin-bottom: 0px; +} + +.resize { + display: none; +} + +#space-warning { + display: none; +} + +.stats-box { + border-right: 1px solid #E8E8E8; + display: inline-block; + font-size: 11px; + padding: 5px 12px 0; +} + +.stats-box:last-of-type { + border-right: none; +} + +.stats-box span { + font-size: 13.3px; + font-weight: bold; +} + +tbody tr:last-of-type { + border: none; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/disk/disk.js b/linodes/disk/disk.js new file mode 100644 index 0000000..a561a99 --- /dev/null +++ b/linodes/disk/disk.js @@ -0,0 +1,297 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, apiPut, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.currentSize = "current-size"; + elements.currentSizeRow = "current-size-row"; + elements.currentType = "current-type"; + elements.duplicateButton = "duplicate-button"; + elements.imageButton = "image-button"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.maxSize = "max-size"; + elements.resizeAddl = "resize-addl"; + elements.saveButton = "save-button"; + elements.size = "size"; + elements.spaceAllocated = "space-allocated"; + elements.spaceFree = "space-free"; + elements.spaceTotal = "space-total"; + elements.spaceWarning = "space-warning"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + elements.type = "type"; + + // Data recieved from API calls + var data = {}; + data.disks = []; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.currentSize = {}; + ui.currentSizeRow = {}; + ui.currentType = {}; + ui.duplicateButton = {}; + ui.imageButton = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.maxSize = {}; + ui.resizeAddl = {}; + ui.saveButton = {}; + ui.size = {}; + ui.spaceAllocated = {}; + ui.spaceFree = {}; + ui.spaceTotal = {}; + ui.spaceWarning = {}; + ui.type = {}; + + // Temporary state + var state = {}; + state.haveDisks = false; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + if (state.haveDisks) + displayStorage(); + }; + + // Callback for linode disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + for (var i = 0; i < data.disks.length; i++) { + if (data.disks[i].id == data.params.did) { + data.disk = data.disks[i]; + break; + } + } + + state.haveDisks = true; + if (data.linode.specs) + displayStorage(); + + if (!data.disk) + return; + + // Update form + ui.label.value = data.disk.label; + ui.currentType.innerHTML = data.disk.filesystem; + ui.currentSize.innerHTML = data.disk.size; + ui.size.value = data.disk.size; + if (data.disk.filesystem != "raw" && data.disk.filesystem != "swap") + ui.imageButton.disabled = false; + }; + + // Show storage totals + var displayStorage = function() + { + var storageUsed = 0; + for (var i = 0; i < data.disks.length; i++) + storageUsed += data.disks[i].size; + var storageFree = data.linode.specs.disk - storageUsed; + + ui.spaceAllocated.innerHTML = storageUsed; + ui.spaceFree.innerHTML = storageFree; + ui.spaceTotal.innerHTML = data.linode.specs.disk; + + if (data.params.did == 0) { + ui.size.max = storageFree; + ui.maxSize.innerHTML = storageFree; + if (storageFree <= 0) + ui.spaceWarning.style.display = "block"; + else + ui.saveButton.disabled = false; + } + + if (!data.disk) + return; + + ui.size.max = storageFree + data.disk.size; + ui.maxSize.innerHTML = storageFree + data.disk.size; + ui.saveButton.disabled = false; + if (storageFree >= data.disk.size) + ui.duplicateButton.disabled = false; + }; + + // Duplicate button handler + var handleDuplicate = function(event) + { + if (event.currentTarget.disabled) + return; + + apiPost("/linode/instances/" + data.params.lid + "/disks/" + data.params.did + "/clone", {}, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Image button handler + var handleImage = function(event) + { + if (event.currentTarget.disabled) + return; + + location.href = "/images/create?lid=" + data.params.lid + "&did=" + data.params.did; + }; + + // Save button handler + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + var diskSize = parseInt(ui.size.value); + var standardCallback = function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }; + + if (data.params.did == 0) { + var req = { + "label": ui.label.value, + "size": diskSize, + "filesystem": ui.type.value + }; + apiPost("/linode/instances/" + data.params.lid + "/disks", req, standardCallback); + } else { + var labelReq = { + "label": ui.label.value + }; + var resizeReq = { + "size": diskSize + }; + + if (data.disk.size != diskSize) { + if (data.disk.label != ui.label.value) { + apiPut("/linode/instances/" + data.params.lid + "/disks/" + data.params.did, labelReq, function(response) + { + apiPost("/linode/instances/" + data.params.lid + "/disks/" + data.params.did + "/resize", resizeReq, standardCallback); + }); + } else { + apiPost("/linode/instances/" + data.params.lid + "/disks/" + data.params.did + "/resize", resizeReq, standardCallback); + } + } else if (data.disk.label != ui.label.value) { + apiPut("/linode/instances/" + data.params.lid + "/disks/" + data.params.did, labelReq, standardCallback); + } else { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + } + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + // We also need a disk ID + if (!data.params.did) { + alert("No disk ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) { + anchors[i].href = anchors[i].href.replace("lid=00", data.params.lid); + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + } + + // Highlight the dashboard subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/dashboard") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.currentSize = document.getElementById(elements.currentSize); + ui.currentSizeRow = document.getElementById(elements.currentSizeRow); + ui.currentType = document.getElementById(elements.currentType); + ui.duplicateButton = document.getElementById(elements.duplicateButton); + ui.imageButton = document.getElementById(elements.imageButton); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.maxSize = document.getElementById(elements.maxSize); + ui.resizeAddl = document.getElementById(elements.resizeAddl); + ui.saveButton = document.getElementById(elements.saveButton); + ui.size = document.getElementById(elements.size); + ui.spaceAllocated = document.getElementById(elements.spaceAllocated); + ui.spaceFree = document.getElementById(elements.spaceFree); + ui.spaceTotal = document.getElementById(elements.spaceTotal); + ui.spaceWarning = document.getElementById(elements.spaceWarning); + ui.type = document.getElementById(elements.type); + + if (data.params.did != 0) { + ui.currentSizeRow.style.display = "table-row"; + ui.duplicateButton.style.display = "initial"; + ui.imageButton.style.display = "initial"; + ui.type.style.display = "none"; + ui.resizeAddl.style.display = "initial"; + } + + // Register event handlers + ui.duplicateButton.addEventListener("click", handleDuplicate); + ui.imageButton.addEventListener("click", handleImage); + ui.saveButton.addEventListener("click", handleSave); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/disk/index.shtml b/linodes/disk/index.shtml new file mode 100644 index 0000000..f905685 --- /dev/null +++ b/linodes/disk/index.shtml @@ -0,0 +1,92 @@ + + + + + + LMC - Edit Disk + + + + + + + +
      + +
      +

      Not enough free disk space to create any more disk images

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Edit Disk
      Label
      Type + + +
      Current Size MB
      Size MBEnter a size between 1 and to resize this disk
      + + + +
      +

      Storage Stats

      +
      + MB
      + Allocated +
      +
      + MB
      + Free +
      +
      + MB
      + Total +
      +
      +
      + + diff --git a/linodes/graphs/graphs.css b/linodes/graphs/graphs.css new file mode 100644 index 0000000..e233c8d --- /dev/null +++ b/linodes/graphs/graphs.css @@ -0,0 +1,22 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#graphs { + padding: 0px 15px 15px; +} diff --git a/linodes/graphs/graphs.js b/linodes/graphs/graphs.js new file mode 100644 index 0000000..a34706c --- /dev/null +++ b/linodes/graphs/graphs.js @@ -0,0 +1,82 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/graphs/index.shtml b/linodes/graphs/index.shtml new file mode 100644 index 0000000..83491a5 --- /dev/null +++ b/linodes/graphs/index.shtml @@ -0,0 +1,35 @@ + + + + + + LMC - Graphs + + + + + + + +
      + +
      +
      +
      + + diff --git a/linodes/index.shtml b/linodes/index.shtml new file mode 100644 index 0000000..75c32e7 --- /dev/null +++ b/linodes/index.shtml @@ -0,0 +1,43 @@ + + + + + + Linode Manager Classic + + + + + + +
      +
      +
      + Loading... +
      +
      +

      This Month's Network Transfer Pool

      +
      +
      +
      +

      Used, Remaining, Quota

      +

      Your transfer is prorated and will reset next month

      +
      +
      + + diff --git a/linodes/ip_failover/index.shtml b/linodes/ip_failover/index.shtml new file mode 100644 index 0000000..da38fee --- /dev/null +++ b/linodes/ip_failover/index.shtml @@ -0,0 +1,52 @@ + + + + + + LMC - IP Failover + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + +
      IP Failover Configuration
      Loading...
      +
      +
      + + diff --git a/linodes/ip_failover/ip_failover.css b/linodes/ip_failover/ip_failover.css new file mode 100644 index 0000000..b9afe63 --- /dev/null +++ b/linodes/ip_failover/ip_failover.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#ip-failover { + padding: 0px 15px 15px; +} + +tbody tr:last-of-type { + border: none; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/ip_failover/ip_failover.js b/linodes/ip_failover/ip_failover.js new file mode 100644 index 0000000..d734f5c --- /dev/null +++ b/linodes/ip_failover/ip_failover.js @@ -0,0 +1,225 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.failoverTable = "failover-table"; + elements.info = "info"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr3"; + elements.loading = "loading"; + elements.saveButton = "save-button"; + elements.saveRow = "save-row"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + data.linodes = []; + + // Static references to UI elements + var ui = {}; + ui.failoverTable = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.loading = {}; + ui.saveButton = {}; + ui.saveRow = {}; + + // Temporary state + var state = {}; + state.lidIndex = -1; + state.netInfoCount = 0; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Get other Linodes in the same DC + var filter = { + "region": data.linode.region + }; + apiGet("/linode/instances", displayLinodes, filter); + }; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to array + data.linodes = data.linodes.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + var filter = { + "region": data.linode.region + }; + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filter); + return; + } + + // Get net info for each linode + for (var i = 0; i < data.linodes.length; i++) + apiGet("/linode/instances/" + data.linodes[i].id + "/ips", displayNetInfo, null); + }; + + // Callback for net info API call + var displayNetInfo = function(response) + { + // Find the associated linode + var lid = parseInt(response['_endpoint'].split("/")[3]); + var index = -1; + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == lid) { + index = i; + break; + } + } + + if (i == -1) + return; + else if (lid == data.linode.id) + state.lidIndex = i; + + data.linodes[index].netInfo = response; + state.netInfoCount++; + if (state.netInfoCount < data.linodes.length) + return; + + // Populate the table + ui.loading.remove(); + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == data.linode.id) + continue; + + var ips = data.linodes[i].netInfo.ipv4["public"].concat(data.linodes[i].netInfo.ipv4["private"]); + for (var j = 0; j < ips.length; j++) { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + var nameCell = document.createElement("td"); + nameCell.innerHTML = data.linodes[i].label; + var ipCell = document.createElement("td"); + var box = document.createElement("input"); + box.id = ips[j].address; + box.type = "checkbox"; + for (var k = 0; k < data.linodes[state.lidIndex].netInfo.ipv4.shared.length; k++) { + if (data.linodes[state.lidIndex].netInfo.ipv4.shared[k].address == ips[j].address) + box.checked = true; + } + ipCell.appendChild(box); + var label = document.createElement("label"); + label.htmlFor = box.id; + label.innerHTML = " " + ips[j].address; + ipCell.appendChild(label); + if (ips[j].rdns) { + var rdns = document.createElement("span"); + rdns.className = elements.info; + rdns.innerHTML = " (" + ips[j].rdns + ")"; + ipCell.appendChild(rdns); + } + row.appendChild(nameCell); + row.appendChild(ipCell); + ui.failoverTable.insertBefore(row, ui.saveRow); + } + } + + ui.saveButton.disabled = false; + }; + + // Handler for save button + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + var ips = []; + var boxes = document.getElementsByTagName("input"); + for (var i = 0; i < boxes.length; i++) { + if (boxes[i].checked) + ips.push(boxes[i].id); + } + + var req = { + "ips": ips, + "linode_id": data.linode.id + }; + apiPost("/networking/ipv4/share", req, function(response) { + location.href = "/linodes/remote_access?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the remote access subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/remote_access") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.failoverTable = document.getElementById(elements.failoverTable); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.loading = document.getElementById(elements.loading); + ui.saveButton = document.getElementById(elements.saveButton); + ui.saveRow = document.getElementById(elements.saveRow); + + // Attach event handlers + ui.saveButton.addEventListener("click", handleSave); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/ip_remove/index.shtml b/linodes/ip_remove/index.shtml new file mode 100644 index 0000000..8880eb4 --- /dev/null +++ b/linodes/ip_remove/index.shtml @@ -0,0 +1,49 @@ + + + + + + LMC - IP Remove + + + + + + + +
      + +
      + + + + + + + + + + + +
      IP AddressRemove It
      + +

      Note: The IP address selected will be immediately removed. This is not reversible.

      +
      +
      + + diff --git a/linodes/ip_remove/ip_remove.css b/linodes/ip_remove/ip_remove.css new file mode 100644 index 0000000..929a509 --- /dev/null +++ b/linodes/ip_remove/ip_remove.css @@ -0,0 +1,40 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +button { + display: block; + margin: 10px 0 0 auto; +} + +#ip-remove { + padding: 0px 15px 15px; +} + +p { + text-align: center; +} + +td:nth-of-type(1) { + width: 100%; +} + +td:nth-of-type(2) { + text-align: center; + white-space: nowrap; +} diff --git a/linodes/ip_remove/ip_remove.js b/linodes/ip_remove/ip_remove.js new file mode 100644 index 0000000..0cc0ff4 --- /dev/null +++ b/linodes/ip_remove/ip_remove.js @@ -0,0 +1,176 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiDelete, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.info = "info"; + elements.ipBody = "ip-body"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr1"; + elements.lmcRowAlt = "lmc-tr2"; + elements.removeBox = "remove-box"; + elements.removeButton = "remove-button"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.ipBody = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.removeButton = {}; + + // Temporary state + var state = {}; + state.numReqs = 0; + state.numReturns = 0; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + ui.label.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + }; + + // Callback for linode net info API call + var displayNetInfo = function(response) + { + // Insert public IPs into table + for (var i = 0; i < response.ipv4["public"].length; i++) { + var row = document.createElement("tr"); + if (i % 2) + row.className = elements.lmcRowAlt; + else + row.className = elements.lmcRow; + + var ipCell = document.createElement("td"); + var ip = document.createElement("span"); + ip.innerHTML = response.ipv4["public"][i].address; + ipCell.appendChild(ip); + if (response.ipv4["public"][i].rdns) { + var br = document.createElement("br"); + var rdns = document.createElement("span"); + rdns.className = elements.info; + rdns.innerHTML = response.ipv4["public"][i].rdns; + ipCell.appendChild(br); + ipCell.appendChild(rdns); + } + + var removeCell = document.createElement("td"); + var removeBox = document.createElement("input"); + removeBox.id = response.ipv4["public"][i].address; + removeBox.className = elements.removeBox; + removeBox.type = "checkbox"; + removeCell.appendChild(removeBox); + + row.appendChild(ipCell); + row.appendChild(removeCell); + ui.ipBody.appendChild(row); + } + + ui.removeButton.disabled = false; + }; + + // Event handler for remove button + var handleRemove = function(event) + { + if (event.currentTarget.disabled) + return; + + var ips = document.getElementsByClassName(elements.removeBox); + state.numReqs = ips.length; + state.numReturns = 0; + + // Submit removal request for each IP + for (var i = 0; i < ips.length; i++) { + if (!ips[i].checked) + continue; + + apiDelete("/linode/instances/" + data.params.lid + "/ips/" + ips[i].id, function(response) { + state.numReturns++; + if (state.numReturns >= state.numReqs) + location.href = "/linodes/remote_access?lid=" + data.params.lid; + }); + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the remote access subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/remote_access") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.ipBody = document.getElementById(elements.ipBody); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.removeButton = document.getElementById(elements.removeButton); + + // Attach event handlers + ui.removeButton.addEventListener("click", handleRemove); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/ips", displayNetInfo, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/ip_swap/index.shtml b/linodes/ip_swap/index.shtml new file mode 100644 index 0000000..68c4f96 --- /dev/null +++ b/linodes/ip_swap/index.shtml @@ -0,0 +1,84 @@ + + + + + + LMC - IP Swap + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + +
      Swap IPs
      With Linode
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      IP AddressMove ItMove ItIP Address
      Private IP AddressMove ItMove ItPrivate IP Address
      + +

      Note: This IP Address transfer will take effect immediately however there may be a short delay before both addresses become available.

      +
      +
      + + diff --git a/linodes/ip_swap/ip_swap.css b/linodes/ip_swap/ip_swap.css new file mode 100644 index 0000000..899c4e2 --- /dev/null +++ b/linodes/ip_swap/ip_swap.css @@ -0,0 +1,91 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#ip-swap { + padding: 0px 15px 15px; +} + +p { + margin-top: 30px; + text-align: center; +} + +#select-table tbody tr td:first-of-type { + font-weight: bold; + text-align: right; + width: 200px; +} + +#swap-table tr td:nth-of-type(5) { + text-align: right; +} + +#swap-table tbody:not(.lmc-tbody-head) td:nth-of-type(2) { + text-align: center; +} + +#swap-table tbody:not(.lmc-tbody-head) td:nth-of-type(3) { + font-size: 30px; + padding: 0; + text-align: center; +} + +#swap-table tbody:not(.lmc-tbody-head) td:nth-of-type(4) { + text-align: center; +} + +#swap-table tbody.lmc-tbody-head tr:nth-of-type(1) td:nth-of-type(2) { + background-color: #FFF; +} + +#swap-table tbody.lmc-tbody-head tr:nth-of-type(2) td:nth-of-type(2) { + text-align: center; +} + +#swap-table tbody.lmc-tbody-head tr:nth-of-type(2) td:nth-of-type(3) { + background-color: #FFF; +} + +#swap-table tbody.lmc-tbody-head tr:nth-of-type(2) td:nth-of-type(4) { + text-align: center; +} + +#swap-table thead tr:nth-of-type(1) td:nth-of-type(2) { + background-color: #FFF; +} + +#swap-table thead tr:nth-of-type(2) td:nth-of-type(2) { + text-align: center; +} + +#swap-table thead tr:nth-of-type(2) td:nth-of-type(3) { + background-color: #FFF; +} + +#swap-table thead tr:nth-of-type(2) td:nth-of-type(4) { + text-align: center; +} + +table { + margin-bottom: 20px; +} + +tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} diff --git a/linodes/ip_swap/ip_swap.js b/linodes/ip_swap/ip_swap.js new file mode 100644 index 0000000..baa05fb --- /dev/null +++ b/linodes/ip_swap/ip_swap.js @@ -0,0 +1,374 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.destClass = "dest-ip"; + elements.destLinode = "dest-linode"; + elements.doIt = "do-it"; + elements.info = "info"; + elements.linodeLabel = "linode-label"; + elements.linodeSelect = "linode-select"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr3"; + elements.privateIPs = "private-ips"; + elements.publicIPs = "public-ips"; + elements.selectButton = "select-button"; + elements.srcClass = "src-ip"; + elements.srcLinode = "src-linode"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + + // Data recieved from API calls + var data = {}; + data.destNet = {}; + data.linode = {}; + data.linodes = []; + data.srcNet = {}; + + // Static references to UI elements + var ui = {}; + ui.destLinode = {}; + ui.doIt = {}; + ui.linodeLabel = {}; + ui.linodeSelect = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.privateIPs = {}; + ui.publicIPs = {}; + ui.selectButton = {}; + ui.srcLinode = {}; + + // Temporary state + var state = {}; + state.destIndex = -1; + state.haveDest = false; + state.haveSrc = false; + + // Callback for destination linode network details API call + var displayDestNet = function(response) + { + data.destNet = response; + state.haveDest = true; + if (state.haveSrc) + displayIPs(); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + ui.srcLinode.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Get other Linodes in the same DC + var filter = { + "region": data.linode.region + }; + apiGet("/linode/instances", displayLinodes, filter); + apiGet("/linode/instances/" + data.params.lid + "/ips", displaySrcNet, null); + }; + + // Populate swap table with source and dest IPs + var displayIPs = function() + { + // Add public IPs + var numIPs = Math.max(data.srcNet.ipv4["public"].length, data.destNet.ipv4["public"].length); + for (var i = 0; i < numIPs; i++) { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + var srcAddr = document.createElement("td"); + var srcMove = document.createElement("td"); + if (data.srcNet.ipv4["public"][i]) { + var ip = document.createElement("span"); + ip.innerHTML = data.srcNet.ipv4["public"][i].address; + var br = document.createElement("br"); + var rdns = document.createElement("span"); + rdns.className = elements.info; + rdns.innerHTML = data.srcNet.ipv4["public"][i].rdns; + srcAddr.appendChild(ip); + srcAddr.appendChild(br); + srcAddr.appendChild(rdns); + + var move = document.createElement("input"); + move.id = data.srcNet.ipv4["public"][i].address; + move.className = elements.srcClass; + move.type = "checkbox"; + srcMove.appendChild(move); + } + + row.appendChild(srcAddr); + row.appendChild(srcMove); + var arrow = document.createElement("td"); + arrow.innerHTML = "↔"; + row.appendChild(arrow); + + var destAddr = document.createElement("td"); + var destMove = document.createElement("td"); + if (data.destNet.ipv4["public"][i]) { + var ip = document.createElement("span"); + ip.innerHTML = data.destNet.ipv4["public"][i].address; + var br = document.createElement("br"); + var rdns = document.createElement("span"); + rdns.className = elements.info; + rdns.innerHTML = data.destNet.ipv4["public"][i].rdns; + destAddr.appendChild(ip); + destAddr.appendChild(br); + destAddr.appendChild(rdns); + + var move = document.createElement("input"); + move.id = data.destNet.ipv4["public"][i].address; + move.className = elements.destClass; + move.type = "checkbox"; + destMove.appendChild(move); + } + + row.appendChild(destMove); + row.appendChild(destAddr); + ui.publicIPs.appendChild(row); + } + + // Add private IPs + var numIPs = Math.max(data.srcNet.ipv4["private"].length, data.destNet.ipv4["private"].length); + for (var i = 0; i < numIPs; i++) { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + + var srcAddr = document.createElement("td"); + var srcMove = document.createElement("td"); + if (data.srcNet.ipv4["private"][i]) { + var ip = document.createElement("span"); + ip.innerHTML = data.srcNet.ipv4["private"][i].address; + var br = document.createElement("br"); + var rdns = document.createElement("span"); + rdns.className = elements.info; + rdns.innerHTML = data.srcNet.ipv4["private"][i].rdns; + srcAddr.appendChild(ip); + srcAddr.appendChild(br); + srcAddr.appendChild(rdns); + + var move = document.createElement("input"); + move.id = data.srcNet.ipv4["private"][i].address; + move.className = elements.srcClass; + move.type = "checkbox"; + srcMove.appendChild(move); + } + + row.appendChild(srcAddr); + row.appendChild(srcMove); + var arrow = document.createElement("td"); + arrow.innerHTML = "↔"; + row.appendChild(arrow); + + var destAddr = document.createElement("td"); + var destMove = document.createElement("td"); + if (data.destNet.ipv4["private"][i]) { + var ip = document.createElement("span"); + ip.innerHTML = data.destNet.ipv4["private"][i].address; + var br = document.createElement("br"); + var rdns = document.createElement("span"); + rdns.className = elements.info; + rdns.innerHTML = data.destNet.ipv4["private"][i].rdns; + destAddr.appendChild(ip); + destAddr.appendChild(br); + destAddr.appendChild(rdns); + + var move = document.createElement("input"); + move.id = data.destNet.ipv4["private"][i].address; + move.className = elements.destClass; + move.type = "checkbox"; + destMove.appendChild(move); + } + + row.appendChild(destMove); + row.appendChild(destAddr); + ui.privateIPs.appendChild(row); + } + + ui.doIt.disabled = false; + ui.selectButton.disabled = false; + }; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to array + data.linodes = data.linodes.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + var filter = { + "region": data.linode.region + }; + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filter); + return; + } + + // Add linodes to selector + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == data.linode.id) + continue; + + var option = document.createElement("option"); + option.value = data.linodes[i].id; + option.innerHTML = data.linodes[i].label; + ui.linodeSelect.appendChild(option); + } + ui.selectButton.disabled = false; + }; + + // Callback for source linode network details API call + var displaySrcNet = function(response) + { + data.srcNet = response; + state.haveSrc = true; + if (state.haveDest) + displayIPs(); + }; + + // Handler for select button + var handleSelect = function(event) + { + if (event.currentTarget.disabled) + return; + + state.haveDest = false; + + var lid = parseInt(ui.linodeSelect.value); + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == lid) { + state.destIndex = i; + break; + } + } + if (state.destIndex == -1) + return; + + ui.doIt.disabled = true; + ui.selectButton.disabled = true; + ui.publicIPs.innerHTML = ""; + ui.privateIPs.innerHTML = ""; + ui.destLinode.innerHTML = data.linodes[state.destIndex].label; + apiGet("/linode/instances/" + data.linodes[state.destIndex].id + "/ips", displayDestNet, null); + }; + + // Handler for "do it" button + var handleSwap = function(event) + { + if (event.currentTarget.disabled) + return; + + var assignments = []; + + // Assign all checked source IPs to the destination Linode + var srcBoxes = document.getElementsByClassName(elements.srcClass); + for (var i = 0; i < srcBoxes.length; i++) { + if (!srcBoxes[i].checked) + continue; + + assignments.push({ + "address": srcBoxes[i].id, + "linode_id": data.linodes[state.destIndex].id + }); + } + + // Assign all checked destination IPs to the source Linode + var destBoxes = document.getElementsByClassName(elements.destClass); + for (var i = 0; i < destBoxes.length; i++) { + if (!destBoxes[i].checked) + continue; + + assignments.push({ + "address": destBoxes[i].id, + "linode_id": data.linode.id + }); + } + + if (!assignments.length) + return; + + var req = { + "assignments": assignments, + "region": data.linode.region + }; + apiPost("/networking/ipv4/assign", req, function(response) { + location.href = "/linodes/remote_access?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the remote access subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/remote_access") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.destLinode = document.getElementById(elements.destLinode); + ui.doIt = document.getElementById(elements.doIt); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeSelect = document.getElementById(elements.linodeSelect); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.privateIPs = document.getElementById(elements.privateIPs); + ui.publicIPs = document.getElementById(elements.publicIPs); + ui.selectButton = document.getElementById(elements.selectButton); + ui.srcLinode = document.getElementById(elements.srcLinode); + + // Add event handlers + ui.selectButton.addEventListener("click", handleSelect); + ui.doIt.addEventListener("click", handleSwap); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/linodes.css b/linodes/linodes.css new file mode 100644 index 0000000..a744282 --- /dev/null +++ b/linodes/linodes.css @@ -0,0 +1,84 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#transfer-bar { + border: 3px solid #999; + margin: 0 auto; + width: 70%; +} + +#bar-remaining { + background-color: #EFEFEF; + border: 2px solid #EFEFEF; + display: none; + font-size: 16px; + line-height: 25px; + text-align: center; + white-space: nowrap; +} + +#bar-used { + background-color: #ADD370; + border: 2px dashed #008000; + display: none; + font-size: 16px; + line-height: 25px; + text-align: center; + white-space: nowrap; +} + +.backup-no { + font-weight: bold; +} + +.backup-yes { + color: #008000; + font-weight: bold; +} + +.center-cell { + text-align: center; +} + +.dashboard-link { + font-weight: bold; +} + +#linodes { + padding: 15px; +} + +#transfer-details { + margin: 5px 0px; + text-align: center; +} + +#transfer-header { + font-weight: bold; + margin: 50px 0px 5px; + text-align: center; +} + +#transfer-notice { + color: #777; + font-size: 12px; + margin: 10px 0px; + padding-bottom: 15px; + text-align: center; +} diff --git a/linodes/linodes.js b/linodes/linodes.js new file mode 100644 index 0000000..5c52981 --- /dev/null +++ b/linodes/linodes.js @@ -0,0 +1,386 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.backupNo = "backup-no"; + elements.backupYes = "backup-yes"; + elements.barRemaining = "bar-remaining"; + elements.barUsed = "bar-used"; + elements.centerCell = "center-cell"; + elements.dashboardLink = "dashboard-link"; + elements.info = "info"; + elements.linodes = "linodes"; + elements.linodeTagPrefix = "linode-tag-"; + elements.lmcRow = "lmc-tr1"; + elements.lmcRowAlt = "lmc-tr2"; + elements.lmcTable = "lmc-table"; + elements.loading = "loading"; + elements.notification = "notification"; + elements.notifications = "notifications"; + elements.subLinks = "sub-links"; + elements.transferQuota = "transfer-quota"; + elements.transferRemaining = "transfer-remaining"; + elements.transferUsed = "transfer-used"; + + // Data recieved from API calls + var data = {}; + data.params = {}; + data.linodes = []; + data.linodeTags = []; + data.noTag = false; + data.notifications = []; + data.plans = []; + + // Static references to UI elements + var ui = {}; + ui.linodes = {}; + ui.linodeTables = {}; + ui.loading = {}; + ui.notifications = {}; + + var createLinodeRow = function(linode, alt) + { + var row = document.createElement("tr"); + if (alt) + row.className = elements.lmcRowAlt; + else + row.className = elements.lmcRow; + var name = document.createElement("td"); + var nameLink = document.createElement("a"); + nameLink.href = "/linodes/dashboard?lid=" + linode.id; + nameLink.innerHTML = linode.label; + name.appendChild(nameLink); + var status = document.createElement("td"); + status.innerHTML = linode.status.charAt(0).toUpperCase() + linode.status.slice(1).replace(/_/g, " "); + var plan = document.createElement("td"); + if (linode.type) + plan.innerHTML = getPlanLabel(linode.type); + else + plan.innerHTML = "Unknown"; + if (plan.innerHTML == "") + translatePlan(linode.type, plan); + var ip = document.createElement("td"); + ip.innerHTML = linode.ipv4[0]; + var ipCount = 0; + for (var i = 1; i < linode.ipv4.length; i++) { + if (linode.ipv4[i].startsWith("192.168.")) + continue; + if (linode.ipv4[i].startsWith("10.")) + continue; + ipCount++; + } + if (ipCount) { + var plus = document.createElement("span"); + plus.className = elements.info; + plus.innerHTML = " (+" + ipCount + ")"; + ip.appendChild(plus); + } + var region = document.createElement("td"); + if (regionNames[linode.region]) + region.innerHTML = regionNames[linode.region]; + else + region.innerHTML = linode.region; + var backups = document.createElement("td"); + backups.className = elements.centerCell; + if (linode.backups.enabled) { + var backupStatus = document.createElement("span"); + backupStatus.className = elements.backupYes; + backupStatus.innerHTML = "Yes"; + backups.appendChild(backupStatus); + } else { + var backupStatus = document.createElement("span"); + backupStatus.className = elements.backupNo; + backupStatus.innerHTML = "No"; + var backupSeparator = document.createElement("span"); + backupSeparator.innerHTML = " - "; + var backupLink = document.createElement("a"); + backupLink.href = "/linodes/backups_enable?lid=" + linode.id; + backupLink.innerHTML = "Enable"; + backups.appendChild(backupStatus); + backups.appendChild(backupSeparator); + backups.appendChild(backupLink); + } + var options = document.createElement("td"); + options.className = elements.centerCell; + var dashboardLink = document.createElement("a"); + dashboardLink.className = elements.dashboardLink; + dashboardLink.href = "/linodes/dashboard?lid=" + linode.id; + dashboardLink.innerHTML = "Dashboard"; + var optionsSeparator = document.createElement("span"); + optionsSeparator.innerHTML = " | "; + var removeLink = document.createElement("a"); + removeLink.href = "/linodes/remove?lid=" + linode.id; + removeLink.innerHTML = "Remove"; + options.appendChild(dashboardLink); + options.appendChild(optionsSeparator); + options.appendChild(removeLink); + row.appendChild(name); + row.appendChild(status); + row.appendChild(plan); + row.appendChild(ip); + row.appendChild(region); + row.appendChild(backups); + row.appendChild(options); + + return row; + }; + + var createLinodeTable = function(tag) + { + var table = document.createElement("table"); + table.id = elements.linodeTagPrefix + tag; + table.className = elements.lmcTable; + var thead = document.createElement("thead"); + var headRow1 = document.createElement("tr"); + var title = document.createElement("td"); + if (tag.length == 0) + title.innerHTML = "Linodes"; + else + title.innerHTML = tag; + headRow1.appendChild(title); + var headRow2 = document.createElement("tr"); + var cells = ["Linode", "Status", "Plan", "IP", "Location", "Backups", "Options"]; + title.colSpan = cells.length; + for (var i = 0; i < cells.length; i++) { + var cell = document.createElement("td"); + if (cells[i] == "Backups" || cells[i] == "Options") + cell.className = elements.centerCell; + cell.innerHTML = cells[i]; + headRow2.appendChild(cell); + } + thead.appendChild(headRow1); + thead.appendChild(headRow2); + var tbody = document.createElement("tbody"); + table.appendChild(thead); + table.appendChild(tbody); + ui.linodeTables[tag] = tbody; + + var subLinks = document.createElement("p"); + subLinks.className = elements.subLinks; + var volumes = document.createElement("a"); + volumes.href = "/volumes"; + volumes.innerHTML = "Manage Volumes"; + var separator = document.createElement("span"); + separator.innerHTML = " | "; + var images = document.createElement("a"); + images.href = "/images"; + images.innerHTML = "Manage Images"; + var stackScripts = document.createElement("a"); + stackScripts.href = "/stackscripts"; + stackScripts.innerHTML = "Manage StackScripts"; + var addLinode = document.createElement("a"); + addLinode.href = "/linodes/add"; + if (tag.length > 0) + addLinode.href += "?tag=" + tag; + addLinode.innerHTML = "Add a Linode"; + subLinks.appendChild(volumes); + subLinks.appendChild(separator); + subLinks.appendChild(images); + subLinks.appendChild(separator.cloneNode(true)); + subLinks.appendChild(stackScripts); + subLinks.appendChild(separator.cloneNode(true)); + subLinks.appendChild(addLinode); + + ui.linodes.appendChild(table); + ui.linodes.appendChild(subLinks); + }; + + var displayLinodes = function(response) + { + // Add linodes to array + data.linodes = data.linodes.concat(response.data); + + // Add new tags to array + for (var i = 0; i < response.data.length; i++) { + if (response.data[i].tags.length == 0) + data.noTag = true; + + for (var j = 0; j < response.data[i].tags.length; j++) { + if (!data.linodeTags.includes(response.data[i].tags[j])) + data.linodeTags.push(response.data[i].tags[j]); + } + } + + // Request the next page if there are more pages + if (response.page != response.pages) { + var progress = (response.page / response.pages) * 100; + progress = progress.toFixed(0); + ui.loading.innerHTML = "Loading " + progress + "%..."; + var filters = null; + if (data.params.tag) + filters = { + "tags": data.params.tag + }; + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filters); + return; + } + + // Redirect to add page if there are no linodes + if (data.linodes.length == 0) + location.href = "/linodes/add"; + + // Sort + data.linodeTags.sort(); + data.linodes.sort(function(a, b) + { + return a.label.toLowerCase().localeCompare(b.label.toLowerCase()); + }); + + // Create tables + ui.loading.remove(); + if (data.noTag) + createLinodeTable(""); + for (var i = 0; i < data.linodeTags.length; i++) + createLinodeTable(data.linodeTags[i]); + + // Insert linodes + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].tags.length == 0) + ui.linodeTables[""].appendChild(createLinodeRow(data.linodes[i], ui.linodeTables[""].children.length % 2)); + + for (var j = 0; j < data.linodes[i].tags.length; j++) + ui.linodeTables[data.linodes[i].tags[j]].appendChild(createLinodeRow(data.linodes[i], ui.linodeTables[data.linodes[i].tags[j]].children.length % 2)); + } + }; + + var displayNotifications = function(response) + { + // Add notifications to array + data.notifications = data.notifications.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/account/notifications?page=" + (response.page + 1), displayNotifications, null); + return; + } + + // Display notifications + for (var i = 0; i < data.notifications.length; i++) { + if (data.notifications[i].entity && data.notifications[i].entity.type == "linode") + continue; + + var notification = document.createElement("div"); + notification.className = elements.notification; + var header = document.createElement("h1"); + header.innerHTML = data.notifications[i].label; + var body = document.createElement("p"); + body.innerHTML = data.notifications[i].message; + notification.appendChild(header); + notification.appendChild(body); + ui.notifications.appendChild(notification); + } + }; + + var displayTransfer = function(response) + { + var barRemaining = document.getElementById(elements.barRemaining); + var barUsed = document.getElementById(elements.barUsed); + var transferQuota = document.getElementById(elements.transferQuota); + var transferRemaining = document.getElementById(elements.transferRemaining); + var transferUsed = document.getElementById(elements.transferUsed); + + // Get border width of bar segments from CSS sheet + var remainingBorderWidth = 0; + var usedBorderWidth = 0; + for (var i = 0; i < document.styleSheets[0].cssRules.length; i++) { + if (document.styleSheets[0].cssRules[i].selectorText == "#" + elements.barRemaining) + remainingBorderWidth = Number.parseInt(document.styleSheets[0].cssRules[i].style.borderWidth) * 2; + else if (document.styleSheets[0].cssRules[i].selectorText == "#" + elements.barUsed) + usedBorderWidth = Number.parseInt(document.styleSheets[0].cssRules[i].style.borderWidth) * 2; + } + + var usage = (response.used / response.quota) * 100; + usage = usage.toFixed(0); + + if (usage != 0) { + barUsed.style = "display: inline-block; width: calc(" + usage + "% - " + usedBorderWidth + "px);"; + barUsed.innerHTML = usage + "% Used"; + } + if (usage != 100) { + barRemaining.style = "display: inline-block; width: calc(" + (100 - usage) + "% - " + remainingBorderWidth + "px);"; + barRemaining.innerHTML = (100 - usage) + "% Remaining"; + } + + transferUsed.innerHTML = response.used + "GB"; + transferRemaining.innerHTML = (response.quota - response.used) + "GB"; + transferQuota.innerHTML = response.quota + "GB"; + }; + + var getPlanLabel = function(id) + { + for (var i = 0; i < data.plans.length; i++) { + if (id == data.plans[i].id) + return data.plans[i].label; + } + + return ""; + }; + + var getPlans = function(response) + { + // Add plans to array + data.plans = data.plans.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/types?page=" + (response.page + 1), getPlans, null); + return; + } + + // Get linodes + var filters = null; + if (data.params.tag) + filters = { + "tags": data.params.tag + }; + apiGet("/linode/instances", displayLinodes, filters); + }; + + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + ui.linodes = document.getElementById(elements.linodes); + ui.loading = document.getElementById(elements.loading); + ui.notifications = document.getElementById(elements.notifications); + + setupHeader(); + + // Get linode and transfer info + apiGet("/linode/types", getPlans, null); + apiGet("/account/transfer", displayTransfer, null); + apiGet("/account/notifications", displayNotifications, null); + }; + + var translatePlan = function(name, cell) + { + var callback = function(response) + { + cell.innerHTML = response.label; + }; + + apiGet("/linode/types/" + name, callback, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/privateip_add/index.shtml b/linodes/privateip_add/index.shtml new file mode 100644 index 0000000..e3f1178 --- /dev/null +++ b/linodes/privateip_add/index.shtml @@ -0,0 +1,37 @@ + + + + + + LMC - Add Private IP Address + + + + + + + +
      + +
      +

      Are you sure you want to add a private IP address to the Linode ?

      + +
      +
      + + diff --git a/linodes/privateip_add/privateip_add.css b/linodes/privateip_add/privateip_add.css new file mode 100644 index 0000000..b937ce1 --- /dev/null +++ b/linodes/privateip_add/privateip_add.css @@ -0,0 +1,26 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#label { + font-weight: bold; +} + +#privateip-add { + padding: 0px 15px 15px; +} diff --git a/linodes/privateip_add/privateip_add.js b/linodes/privateip_add/privateip_add.js new file mode 100644 index 0000000..abe49b3 --- /dev/null +++ b/linodes/privateip_add/privateip_add.js @@ -0,0 +1,116 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.addButton = "add-button"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.addButton = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + ui.label.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + }; + + // Handler for add button + var handleAdd = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "public": false, + "type": "ipv4" + }; + apiPost("/linode/instances/" + data.params.lid + "/ips", req, function(response) { + location.href = "/linodes/remote_access?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the remote access subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/remote_access") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.addButton = document.getElementById(elements.addButton); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + + // Attach event handlers + ui.addButton.addEventListener("click", handleAdd); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/rdns/index.shtml b/linodes/rdns/index.shtml new file mode 100644 index 0000000..18814b7 --- /dev/null +++ b/linodes/rdns/index.shtml @@ -0,0 +1,53 @@ + + + + + + LMC - Reverse DNS + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + +
      Reverse DNS
      IP AddressTarget
      +

      Note: Forward DNS must already be set up for reverse DNS to be applied. Leaving any value blank will reset it to the default.

      +
      +
      + + diff --git a/linodes/rdns/rdns.css b/linodes/rdns/rdns.css new file mode 100644 index 0000000..c02c2fc --- /dev/null +++ b/linodes/rdns/rdns.css @@ -0,0 +1,34 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +p { + text-align: center; +} + +#rdns { + padding: 0px 15px 15px; +} + +tbody tr td:first-of-type { + font-weight: bold; +} + +tbody tr:last-of-type { + border: none; +} diff --git a/linodes/rdns/rdns.js b/linodes/rdns/rdns.js new file mode 100644 index 0000000..321057c --- /dev/null +++ b/linodes/rdns/rdns.js @@ -0,0 +1,166 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPut, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lmcRow = "lmc-tr3"; + elements.rdnsBody = "rdns-body"; + elements.rdnsTarget = "rdns-target"; + elements.saveButton = "save-button"; + elements.saveRow = "save-row"; + elements.subnav = "subnav-link"; + elements.subnavActive = "subnav-link-active"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.rdnsBody = {}; + ui.saveButton = {}; + ui.saveRow = {}; + + // Temporary state + var state = {}; + state.numReqs = 0; + state.numReturns = 0; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + }; + + // Callback for linode net info API call + var displayNetInfo = function(response) + { + var ips = response.ipv4["public"]; + ips.push(response.ipv6.slaac); + + // Add IPs to table + for (var i = 0; i < ips.length; i++) { + var row = document.createElement("tr"); + row.className = elements.lmcRow; + var addrCell = document.createElement("td"); + addrCell.innerHTML = ips[i].address; + var targetCell = document.createElement("td"); + var target = document.createElement("input"); + target.id = ips[i].address; + target.className = elements.rdnsTarget; + target.type = "text"; + target.placeholder = "host.yourdomain.com"; + target.size = "36"; + target.value = ips[i].rdns; + targetCell.appendChild(target); + row.appendChild(addrCell); + row.appendChild(targetCell); + ui.rdnsBody.insertBefore(row, ui.saveRow); + } + + ui.saveButton.disabled = false; + }; + + // Event handler for save button + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + var targets = document.getElementsByClassName(elements.rdnsTarget); + state.numReqs = targets.length; + state.numReturns = 0; + + // Submit request for each IP + for (var i = 0; i < targets.length; i++) { + var req = {}; + if (!targets[i].value.length) + req.rdns = null; + else + req.rdns = targets[i].value; + + apiPut("/linode/instances/" + data.params.lid + "/ips/" + targets[i].id, req, function(response) { + state.numReturns++; + if (state.numReturns >= state.numReqs) + location.href = "/linodes/remote_access?lid=" + data.params.lid; + }); + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Highlight the remote access subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/remote_access") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.rdnsBody = document.getElementById(elements.rdnsBody); + ui.saveButton = document.getElementById(elements.saveButton); + ui.saveRow = document.getElementById(elements.saveRow); + + // Attach event handlers + ui.saveButton.addEventListener("click", handleSave); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/ips", displayNetInfo, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/rebuild/index.shtml b/linodes/rebuild/index.shtml new file mode 100644 index 0000000..b26593e --- /dev/null +++ b/linodes/rebuild/index.shtml @@ -0,0 +1,72 @@ + + + + + + LMC - Rebuild - we have the technology + + + + + + + +
      + +
      +

      Rebuilding will destroy all data, wipe your Linode clean, and start fresh.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Deploy an Image
      Image + + See also: Deploying using StackScripts
      SwapA 512MB swap disk will be automatically created.
      Root Password
      +
      +
      + + diff --git a/linodes/rebuild/rebuild.css b/linodes/rebuild/rebuild.css new file mode 100644 index 0000000..94bc4c4 --- /dev/null +++ b/linodes/rebuild/rebuild.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#rebuild { + padding: 0px 15px 15px; +} + +tbody tr:last-of-type { + border: none; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/rebuild/rebuild.js b/linodes/rebuild/rebuild.js new file mode 100644 index 0000000..f0fa6f1 --- /dev/null +++ b/linodes/rebuild/rebuild.js @@ -0,0 +1,170 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.currentDistros = "current"; + elements.customImages = "custom"; + elements.deletedDisks = "deleted"; + elements.deprecatedDistros = "deprecated"; + elements.image = "image"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.rebuildButton = "rebuild-button"; + elements.rootPass = "root-pass"; + + // Data recieved from API calls + var data = {}; + data.images = []; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.currentDistros = {}; + ui.customImages = {}; + ui.deletedDisks = {}; + ui.deprecatedDistros = {}; + ui.image = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.rebuildButton = {}; + ui.rootPass = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + }; + + // Callback for images API call + var displayImages = function(response) + { + // Add images to array + data.images = data.images.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/images?page=" + (response.page + 1), displayImages, null); + return; + } + + // Add images to selector + for (var i = 0; i < data.images.length; i++) { + var image = document.createElement("option"); + image.value = data.images[i].id; + image.innerHTML = data.images[i].label; + if (data.images[i].deprecated) + ui.deprecatedDistros.appendChild(image); + else if (data.images[i].type == "automatic") + ui.deletedDisks.appendChild(image); + else if (!data.images[i].vendor) + ui.customImages.appendChild(image); + else + ui.currentDistros.appendChild(image); + + if (data.images[i].id == settings.preferredDistro) + ui.image.value = data.images[i].id; + } + + if (ui.customImages.childNodes.length == 0) + ui.customImages.style.display = "none"; + if (ui.deletedDisks.childNodes.length == 0) + ui.deletedDisks.style.display = "none"; + ui.rebuildButton.disabled = false; + }; + + // Rebuild button handler + var handleRebuild = function(event) + { + if (event.currentTarget.disabled) + return; + + if (ui.rootPass.value.length == 0) { + alert("You must supply a root password."); + return; + } + + if (!confirm("Delete all existing data on this Linode and redeploy?")) + return; + + var request = { + "image": ui.image.value, + "root_pass": ui.rootPass.value, + "booted": false + }; + apiPost("/linode/instances/" + data.params.lid + "/rebuild", request, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.currentDistros = document.getElementById(elements.currentDistros); + ui.customImages = document.getElementById(elements.customImages); + ui.deletedDisks = document.getElementById(elements.deletedDisks); + ui.deprecatedDistros = document.getElementById(elements.deprecatedDistros); + ui.image = document.getElementById(elements.image); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.rebuildButton = document.getElementById(elements.rebuildButton); + ui.rootPass = document.getElementById(elements.rootPass); + + // Register rebuild button handler + ui.rebuildButton.addEventListener("click", handleRebuild); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/images", displayImages, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/remote_access/index.shtml b/linodes/remote_access/index.shtml new file mode 100644 index 0000000..3e468cd --- /dev/null +++ b/linodes/remote_access/index.shtml @@ -0,0 +1,127 @@ + + + + + + LMC - Remote Access + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Network Access
      Public Network
      SSH AccessGetting Started Guide
      Public IPs + + / ( )
      + IP Add | IP Remove | IP Failover | IP Swap | Reverse DNS +
      + Static Networking Guide
      + IPv6 Networking Guide +
      Default Gateways + + +
      DNS Resolvers
      Private/LAN Network
      Private IPsNone - Add a Private IPStatic Networking Guide
      Link-Local IP
      + + + + + + + + + + + + + + + + + + + + + + + +
      Console Access
      Lish via BrowserLaunch Lish Console »
      Lish via SSHssh -t @lish-.linode.com + Lish listens on ports 22, 443, and 2200
      + (Lish Guide & Fingerprints) +
      GlishLaunch Graphical Web Console » + Equivalent to plugging a monitor and keyboard into your server.
      + (Using Glish) +
      +
      +
      + + diff --git a/linodes/remote_access/remote_access.css b/linodes/remote_access/remote_access.css new file mode 100644 index 0000000..bb2c859 --- /dev/null +++ b/linodes/remote_access/remote_access.css @@ -0,0 +1,47 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +.disabled { + text-decoration: line-through; +} + +#private-ips-guide { + visibility: hidden; +} + +#remote-access { + padding: 0px 15px 15px; +} + +#ssh-link { + font-weight: bold; +} + +table:first-of-type { + margin-bottom: 30px; +} + +tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} + +tbody:not(.lmc-tbody-head) tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/remote_access/remote_access.js b/linodes/remote_access/remote_access.js new file mode 100644 index 0000000..892d727 --- /dev/null +++ b/linodes/remote_access/remote_access.js @@ -0,0 +1,496 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.ipFailover = "ip-failover"; + elements.ipRemove = "ip-remove"; + elements.ipSwap = "ip-swap"; + elements.ipv4Addrs = "ipv4-addrs"; + elements.ipv4Gateways = "ipv4-gateways"; + elements.linkLocal = "link-local"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.lishLink = "lish-link"; + elements.privateIPGuide = "private-ips-guide"; + elements.privateIPs = "private-ips"; + elements.resolvers = "resolvers"; + elements.slaacAddr = "slaac-addr"; + elements.slaacGateway = "slaac-gateway"; + elements.slaacPrefix = "slaac-prefix"; + elements.slaacRdns = "slaac-rdns"; + elements.sshLink = "ssh-link"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + data.netInfo = {}; + + // The Linode API does not supply resolvers, so they must be hard-coded + data.resolvers = { + "us-central": [ + "173.255.199.5", + "66.228.53.5", + "96.126.122.5", + "96.126.124.5", + "96.126.127.5", + "198.58.107.5", + "198.58.111.5", + "23.239.24.5", + "2600:3c00::5", + "2600:3c00::6", + "2600:3c00::7", + "2600:3c00::8", + "2600:3c00::9", + "2600:3c00::b", + "2600:3c00::c" + ], + "us-west": [ + "173.230.145.5", + "173.230.147.5", + "173.230.155.5", + "173.255.212.5", + "173.255.219.5", + "173.255.241.5", + "173.255.243.5", + "173.255.244.5", + "2600:3c01::5", + "2600:3c01::6", + "2600:3c01::7", + "2600:3c01::8", + "2600:3c01::9", + "2600:3c01::b", + "2600:3c01::c" + ], + "us-southeast": [ + "173.230.129.5", + "173.230.136.5", + "173.230.140.5", + "66.228.59.5", + "66.228.62.5", + "50.116.35.5", + "50.116.41.5", + "23.239.18.5", + "2600:3c02::5", + "2600:3c02::6", + "2600:3c02::7", + "2600:3c02::8", + "2600:3c02::9", + "2600:3c02::b", + "2600:3c02::c" + ], + "us-east": [ + "66.228.42.5", + "96.126.106.5", + "50.116.53.5", + "50.116.58.5", + "50.116.61.5", + "50.116.62.5", + "66.175.211.5", + "2600:3c03::5", + "2600:3c03::6", + "2600:3c03::7", + "2600:3c03::8", + "2600:3c03::9", + "2600:3c03::b", + "2600:3c03::c" + ], + "us-east-1b": [ + "172.104.200.4", + "172.104.200.5", + "2400:8903::5", + "2400:8903::6", + "2400:8903::7", + "2400:8903::8", + "2400:8903::9", + "2400:8903::b", + "2400:8903::c" + ], + "eu-west": [ + "178.79.182.5", + "176.58.107.5", + "176.58.116.5", + "176.58.121.5", + "151.236.220.5", + "212.71.252.5", + "212.71.253.5", + "2a01:7e00::5", + "2a01:7e00::6", + "2a01:7e00::7", + "2a01:7e00::8", + "2a01:7e00::9", + "2a01:7e00::b", + "2a01:7e00::c" + ], + "ap-south": [ + "139.162.11.5", + "139.162.13.5", + "139.162.14.5", + "139.162.15.5", + "139.162.16.5", + "139.162.21.5", + "139.162.27.5", + "2400:8901::5", + "2400:8901::6", + "2400:8901::7", + "2400:8901::8", + "2400:8901::9", + "2400:8901::b", + "2400:8901::c" + ], + "eu-central": [ + "139.162.130.5", + "139.162.131.5", + "139.162.132.5", + "139.162.133.5", + "139.162.134.5", + "139.162.135.5", + "139.162.136.5", + "139.162.137.5", + "139.162.138.5", + "139.162.139.5", + "2a01:7e01::5", + "2a01:7e01::6", + "2a01:7e01::7", + "2a01:7e01::8", + "2a01:7e01::9", + "2a01:7e01::b", + "2a01:7e01::c" + ], + "ap-northeast": [ + "106.187.90.5", + "106.187.93.5", + "106.187.94.5", + "106.187.95.5", + "106.186.116.5", + "106.186.123.5", + "106.186.124.5", + "2400:8900::5", + "2400:8900::6", + "2400:8900::7", + "2400:8900::8", + "2400:8900::9", + "2400:8900::b", + "2400:8900::c" + ], + "ap-northeast-1a": [ + "139.162.66.5", + "139.162.67.5", + "139.162.68.5", + "139.162.69.5", + "139.162.70.5", + "139.162.71.5", + "139.162.72.5", + "139.162.73.5", + "139.162.74.5", + "139.162.75.5", + "2400:8902::5", + "2400:8902::6", + "2400:8902::7", + "2400:8902::8", + "2400:8902::9", + "2400:8902::b", + "2400:8902::c" + ], + "ca-central": [ + "172.105.0.5", + "172.105.3.5", + "172.105.4.5", + "172.105.5.5", + "172.105.6.5", + "172.105.7.5", + "172.105.8.5", + "172.105.9.5", + "172.105.10.5", + "172.105.11.5", + "2600:3C04::5", + "2600:3C04::6", + "2600:3C04::7", + "2600:3C04::8", + "2600:3C04::9", + "2600:3C04::b", + "2600:3C04::c" + ], + "ap-west": [ + "172.105.34.5", + "172.105.35.5", + "172.105.36.5", + "172.105.37.5", + "172.105.38.5", + "172.105.39.5", + "172.105.40.5", + "172.105.41.5", + "172.105.42.5", + "172.105.43.5", + "2400:8904::5", + "2400:8904::6", + "2400:8904::7", + "2400:8904::8", + "2400:8904::9", + "2400:8904::b", + "2400:8904::c" + ], + "ap-southeast": [ + "172.105.166.5", + "172.105.169.5", + "172.105.168.5", + "172.105.172.5", + "172.105.162.5", + "172.105.170.5", + "172.105.167.5", + "172.105.171.5", + "172.105.181.5", + "172.105.161.5", + "2400:8907::5", + "2400:8907::6", + "2400:8907::7", + "2400:8907::8", + "2400:8907::9", + "2400:8907::b", + "2400:8907::c" + ], + "philadelphia": [ + "100.90.80.253", + "2400:8906::5", + "2400:8906::6", + "2400:8906::7", + "2400:8906::8", + "2400:8906::9", + "2400:8906::b", + "2400:8906::c" + ] + }; + + // LISH uses different DC names than the API uses, so we need to translate them + data.lishDCs = { + "us-central": "dallas", + "us-west": "fremont", + "us-southeast": "atlanta", + "us-east": "newark", + "us-east-1b": "cjj2", + "eu-west": "london", + "ap-south": "singapore", + "eu-central": "frankfurt", + "ap-northeast": "shg1", + "ap-northeast-1a": "shg1", + "ca-central": "tor1", + "ap-west": "mum1", + "ap-southeast": "syd1", + "philadelphia": "phl1" + }; + + // Static references to UI elements + var ui = {}; + ui.ipFailover = {}; + ui.ipRemove = {}; + ui.ipSwap = {}; + ui.ipv4Addrs = {}; + ui.ipv4Gateways = {}; + ui.linkLocal = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.lishLink = {}; + ui.privateIPGuide = {}; + ui.privateIPs = {}; + ui.resolvers = {}; + ui.slaacAddr = {}; + ui.slaacGateway = {}; + ui.slaacPrefix = {}; + ui.slaacRdns = {}; + ui.sshLink = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Replace user in SSH link if we're running CoreOS Container Linux + if (data.linode.image == "linode/containerlinux") { + ui.sshLink.href = ui.sshLink.href.replace("root", "core"); + ui.sshLink.innerHTML = ui.sshLink.innerHTML.replace("root", "core"); + } + + // Get list of other instances in the same region + var filters = { + "region": data.linode.region + }; + apiGet("/linode/instances", displayIPLinks, filters); + + // Display resolvers + for (var i = 0; i < data.resolvers[data.linode.region].length; i++) { + var resolver = document.createElement("span"); + resolver.innerHTML = data.resolvers[data.linode.region][i]; + var br = document.createElement("br"); + ui.resolvers.appendChild(resolver); + ui.resolvers.appendChild(br); + } + + // Update the LISH link + ui.lishLink.href = ui.lishLink.href.replace("lish-", "lish-" + data.lishDCs[data.linode.region]); + ui.lishLink.innerHTML = ui.lishLink.innerHTML.replace("lish-", "lish-" + data.lishDCs[data.linode.region]); + ui.lishLink.innerHTML += " " + data.linode.label; + }; + + // Callback for regional instances API call + var displayIPLinks = function(response) + { + // Only enable IP failover and swap links if there are 2 or more instances in this location + if (response.data.length < 2) + return; + + var ipFailover = document.createElement("a"); + ipFailover.href = "/linodes/ip_failover?lid=" + data.params.lid; + ipFailover.innerHTML = "IP Failover"; + ui.ipFailover.replaceWith(ipFailover); + + var ipSwap = document.createElement("a"); + ipSwap.href = "/linodes/ip_swap?lid=" + data.params.lid; + ipSwap.innerHTML = "IP Swap"; + ui.ipSwap.replaceWith(ipSwap); + }; + + // Callback for user info API call + var displayLishUser = function(response) + { + // Insert username into LISH link + ui.lishLink.href = ui.lishLink.href.replace("@", response.username + "@"); + ui.lishLink.innerHTML = ui.lishLink.innerHTML.replace("@", response.username + "@"); + }; + + // Callback for network info API call + var displayNetInfo = function(response) + { + data.netInfo = response; + + // Set SSH link + // CoreOS Container Linux uses core instead of root + var user = "root"; + if (data.linode && data.linode.image == "linode/containerlinux") + user = "core"; + if (data.netInfo.ipv4["public"].length > 0) { + ui.sshLink.href = "ssh://" + user + "@" + data.netInfo.ipv4["public"][0].address; + ui.sshLink.innerHTML = "ssh " + user + "@" + data.netInfo.ipv4["public"][0].address; + } + + // Show public IPv4 info + for (var i = 0; i < data.netInfo.ipv4["public"].length; i++) { + var ipinfo = document.createElement("span"); + ipinfo.innerHTML = data.netInfo.ipv4["public"][i].address + " / " + data.netInfo.ipv4["public"][i].prefix + " ( " + data.netInfo.ipv4["public"][i].rdns + " )"; + var gateway = document.createElement("span"); + gateway.innerHTML = data.netInfo.ipv4["public"][i].gateway; + var br = document.createElement("br"); + ui.ipv4Addrs.appendChild(ipinfo); + ui.ipv4Addrs.appendChild(br); + ui.ipv4Gateways.appendChild(gateway); + ui.ipv4Gateways.appendChild(br.cloneNode(false)); + } + + // Show public IPv6 info + ui.slaacAddr.innerHTML = data.netInfo.ipv6.slaac.address; + ui.slaacGateway.innerHTML = data.netInfo.ipv6.slaac.gateway; + ui.slaacPrefix.innerHTML = data.netInfo.ipv6.slaac.prefix; + ui.slaacRdns.innerHTML = data.netInfo.ipv6.slaac.rdns; + + // Enable IP remove link if multiple IPv4s + if (data.netInfo.ipv4["public"].length > 1) { + var ipRemove = document.createElement("a"); + ipRemove.href = "/linodes/ip_remove?lid=" + data.params.lid; + ipRemove.innerHTML = "IP Remove"; + ui.ipRemove.replaceWith(ipRemove); + } + + // Display private IP info + if (data.netInfo.ipv4["private"].length > 0) { + ui.privateIPs.innerHTML = ""; + ui.privateIPGuide.style.visibility = "visible"; + } + for (var i = 0; i < data.netInfo.ipv4["private"].length; i++) { + var ip = document.createElement("span"); + ip.innerHTML = data.netInfo.ipv4["private"][i].address + " / " + data.netInfo.ipv4["private"][i].prefix; + var br = document.createElement("br"); + ui.privateIPs.appendChild(ip); + ui.privateIPs.appendChild(br); + } + + // Display link-local IPv6 address + ui.linkLocal.innerHTML = data.netInfo.ipv6.link_local.address + " / " + data.netInfo.ipv6.link_local.prefix; + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) { + anchors[i].href = anchors[i].href.replace("lid=00", data.params.lid); + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + } + + // Get element references + ui.ipFailover = document.getElementById(elements.ipFailover); + ui.ipRemove = document.getElementById(elements.ipRemove); + ui.ipSwap = document.getElementById(elements.ipSwap); + ui.ipv4Addrs = document.getElementById(elements.ipv4Addrs); + ui.ipv4Gateways = document.getElementById(elements.ipv4Gateways); + ui.linkLocal = document.getElementById(elements.linkLocal); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.lishLink = document.getElementById(elements.lishLink); + ui.privateIPGuide = document.getElementById(elements.privateIPGuide); + ui.privateIPs = document.getElementById(elements.privateIPs); + ui.resolvers = document.getElementById(elements.resolvers); + ui.slaacAddr = document.getElementById(elements.slaacAddr); + ui.slaacGateway = document.getElementById(elements.slaacGateway); + ui.slaacPrefix = document.getElementById(elements.slaacPrefix); + ui.slaacRdns = document.getElementById(elements.slaacRdns); + ui.sshLink = document.getElementById(elements.sshLink); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/ips", displayNetInfo, null); + apiGet("/profile", displayLishUser, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/remove/index.shtml b/linodes/remove/index.shtml new file mode 100644 index 0000000..977cf7a --- /dev/null +++ b/linodes/remove/index.shtml @@ -0,0 +1,38 @@ + + + + + + LMC - Remove + + + + + + +
      + +
      +

      You must confirm that you want to remove this Linode.

      +

      Are you sure you want to remove the "" Linode from your account?

      +
      + +
      +
      + + diff --git a/linodes/remove/remove.css b/linodes/remove/remove.css new file mode 100644 index 0000000..29aacb8 --- /dev/null +++ b/linodes/remove/remove.css @@ -0,0 +1,34 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +button { + margin-top: 10px; +} + +#confirm-warning { + display: none; +} + +#label { + font-weight: bold; +} + +#remove { + padding: 0px 15px 15px; +} diff --git a/linodes/remove/remove.js b/linodes/remove/remove.js new file mode 100644 index 0000000..30e60bb --- /dev/null +++ b/linodes/remove/remove.js @@ -0,0 +1,125 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiDelete, apiGet, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.confirm = "confirm"; + elements.confirmWarning = "confirm-warning"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.removeButton = "remove-button"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.confirm = {}; + ui.confirmWarning = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.removeButton = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + ui.label.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + ui.removeButton.disabled = false; + }; + + // Remove button handler + var handleRemove = function(event) + { + if (event.currentTarget.disabled) + return; + + if (!ui.confirm.checked) { + ui.confirmWarning.style.display = "block"; + return; + } + + apiDelete("/linode/instances/" + data.params.lid, function(response){ + location.href = "/linodes"; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) { + anchors[i].href = anchors[i].href.replace("lid=00", data.params.lid); + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + } + + // Highlight the dashboard subnav link + var subnavLinks = document.getElementsByClassName(elements.subnav); + for (var i = 0; i < subnavLinks.length; i++) { + if (subnavLinks[i].pathname == "/linodes/dashboard") + subnavLinks[i].className += " " + elements.subnavActive; + } + + // Get element references + ui.confirm = document.getElementById(elements.confirm); + ui.confirmWarning = document.getElementById(elements.confirmWarning); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.removeButton = document.getElementById(elements.removeButton); + + // Register event handlers + ui.removeButton.addEventListener("click", handleRemove); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/rescue/index.shtml b/linodes/rescue/index.shtml new file mode 100644 index 0000000..4c79bbd --- /dev/null +++ b/linodes/rescue/index.shtml @@ -0,0 +1,158 @@ + + + + + + LMC - Rescue + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Rescue Mode
      Boots your Linode into Rescue Mode. Access it via the console.
      /dev/sda + +
      /dev/sdb + +
      /dev/sdc + +
      /dev/sdd + +
      /dev/sde + +
      /dev/sdf + +
      /dev/sdg + +
      /dev/sdhFinnix Media
      Reset Root Password
      FilesystemLinode must be shut down
      New Password
      +
      +
      + + diff --git a/linodes/rescue/rescue.css b/linodes/rescue/rescue.css new file mode 100644 index 0000000..b9b4fc8 --- /dev/null +++ b/linodes/rescue/rescue.css @@ -0,0 +1,35 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#rescue { + padding: 0px 15px 15px; +} + +#rescue-button { + margin-bottom: 30px; +} + +tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} + +tbody:not(.lmc-tbody-head) tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/linodes/rescue/rescue.js b/linodes/rescue/rescue.js new file mode 100644 index 0000000..47eb987 --- /dev/null +++ b/linodes/rescue/rescue.js @@ -0,0 +1,268 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.disks = "disks"; + elements.drive = "drive"; + elements.filesystems = "filesystems"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.rescueButton = "rescue-button"; + elements.resetButton = "reset-button"; + elements.rootPass = "root-pass"; + elements.sda = "sda"; + elements.sdb = "sdb"; + elements.sdc = "sdc"; + elements.sdd = "sdd"; + elements.sde = "sde"; + elements.sdf = "sdf"; + elements.sdg = "sdg"; + elements.volumes = "volumes"; + + // Data received from API calls + var data = {}; + data.disks = []; + data.linode = {}; + data.volumes = []; + + // Static references to UI elements + var ui = {}; + ui.disks = []; + ui.drive = []; + ui.filesystems = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.rescueButton = {}; + ui.resetButton = {}; + ui.rootPass = {}; + ui.sda = {}; + ui.sdb = {}; + ui.sdc = {}; + ui.sdd = {}; + ui.sde = {}; + ui.sdf = {}; + ui.sdg = {}; + ui.volumes = []; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } else { + ui.linodeTag.style.display = "none"; + } + + // Get list of volumes + apiGet("/volumes", displayVolumes, null); + }; + + // Callback for linode disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + // Add disks to drive lists, and disks with filesystems to filesystems list + for (var i = 0; i < data.disks.length; i++) { + var disk = document.createElement("option"); + disk.value = "disk-" + data.disks[i].id; + disk.innerHTML = data.disks[i].label; + + for (var j = 0; j < ui.disks.length; j++) + ui.disks[j].appendChild(disk.cloneNode(true)); + + if (data.disks[i].filesystem.match(/ext3|ext4/)) + ui.filesystems.appendChild(disk.cloneNode(true)); + } + + // Preset value of drive lists + for (var i = 0; i < data.disks.length && i < ui.drive.length; i++) + ui.drive[i].value = "disk-" + data.disks[i].id; + + if (ui.filesystems.childNodes.length > 0) + ui.resetButton.disabled = false; + }; + + // Callback for volumes API call + var displayVolumes = function(response) + { + // Add volumes to array + data.volumes = data.volumes.concat(response.data); + + // Request the next page if there are more + if (response.page != response.pages) { + apiGet("/volumes?page=" + (response.page + 1), displayVolumes, null); + return; + } + + // Add volumes from this Linode's region to drive lists + for (var i = 0; i < data.volumes.length; i++) { + if (data.volumes[i].region != data.linode.region) + continue; + + var volume = document.createElement("option"); + volume.value = "volume-" + data.volumes[i].id; + volume.innerHTML = data.volumes[i].label; + for (var j = 0; j < ui.volumes.length; j++) + ui.volumes[j].appendChild(volume.cloneNode(true)); + } + + ui.rescueButton.disabled = false; + }; + + // Rescue button handler + var handleRescue = function(event) + { + if (event.currentTarget.disabled) + return; + + var request = { + "devices": {} + }; + + if (ui.sda.value.startsWith("disk-")) + request.devices.sda = { "disk_id": parseInt(ui.sda.value.split("-")[1]) }; + else if (ui.sda.value.startsWith("volume-")) + request.devices.sda = { "volume_id": parseInt(ui.sda.value.split("-")[1]) }; + + if (ui.sdb.value.startsWith("disk-")) + request.devices.sdb = { "disk_id": parseInt(ui.sdb.value.split("-")[1]) }; + else if (ui.sdb.value.startsWith("volume-")) + request.devices.sdb = { "volume_id": parseInt(ui.sdb.value.split("-")[1]) }; + + if (ui.sdc.value.startsWith("disk-")) + request.devices.sdc = { "disk_id": parseInt(ui.sdc.value.split("-")[1]) }; + else if (ui.sdc.value.startsWith("volume-")) + request.devices.sdc = { "volume_id": parseInt(ui.sdc.value.split("-")[1]) }; + + if (ui.sdd.value.startsWith("disk-")) + request.devices.sdd = { "disk_id": parseInt(ui.sdd.value.split("-")[1]) }; + else if (ui.sdd.value.startsWith("volume-")) + request.devices.sdd = { "volume_id": parseInt(ui.sdd.value.split("-")[1]) }; + + if (ui.sde.value.startsWith("disk-")) + request.devices.sde = { "disk_id": parseInt(ui.sde.value.split("-")[1]) }; + else if (ui.sde.value.startsWith("volume-")) + request.devices.sde = { "volume_id": parseInt(ui.sde.value.split("-")[1]) }; + + if (ui.sdf.value.startsWith("disk-")) + request.devices.sdf = { "disk_id": parseInt(ui.sdf.value.split("-")[1]) }; + else if (ui.sdf.value.startsWith("volume-")) + request.devices.sdf = { "volume_id": parseInt(ui.sdf.value.split("-")[1]) }; + + if (ui.sdg.value.startsWith("disk-")) + request.devices.sdg = { "disk_id": parseInt(ui.sdg.value.split("-")[1]) }; + else if (ui.sdg.value.startsWith("volume-")) + request.devices.sdg = { "volume_id": parseInt(ui.sdg.value.split("-")[1]) }; + + apiPost("/linode/instances/" + data.params.lid + "/rescue", request, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Reset button handler + var handleReset = function(event) + { + if (event.currentTarget.disabled) + return; + + if (ui.rootPass.value.length == 0) { + alert("You must supply a root password."); + return; + } + + var request = { + "password": ui.rootPass.value + }; + + apiPost("/linode/instances/" + data.params.lid + "/disks/" + ui.filesystems.value.split("-")[1] + "/password", request, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.disks = document.getElementsByClassName(elements.disks); + ui.drive = document.getElementsByClassName(elements.drive); + ui.filesystems = document.getElementById(elements.filesystems); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.rescueButton = document.getElementById(elements.rescueButton); + ui.resetButton = document.getElementById(elements.resetButton); + ui.rootPass = document.getElementById(elements.rootPass); + ui.sda = document.getElementById(elements.sda); + ui.sdb = document.getElementById(elements.sdb); + ui.sdc = document.getElementById(elements.sdc); + ui.sdd = document.getElementById(elements.sdd); + ui.sde = document.getElementById(elements.sde); + ui.sdf = document.getElementById(elements.sdf); + ui.sdg = document.getElementById(elements.sdg); + ui.volumes = document.getElementsByClassName(elements.volumes); + + // Register button handlers + ui.rescueButton.addEventListener("click", handleRescue); + ui.resetButton.addEventListener("click", handleReset); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/resize/index.shtml b/linodes/resize/index.shtml new file mode 100644 index 0000000..06b4691 --- /dev/null +++ b/linodes/resize/index.shtml @@ -0,0 +1,93 @@ + + + + + + LMC - Resize + + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + +
      Resize

      Choose your new plan

      +

      Nanode

      +
      +
      +

      Standard

      +
      + +
      +

      Dedicated CPU

      +
      +
      +

      High Memory

      +
      +
      +

      Dedicated GPU

      +
      +
      +

      How it works

      +
        +
      1. + Linode is shut down and migrated
        + You will experience downtime while your Linode is migrated. It will take about to migrate your Linode, but that may vary based on host and network load. +
      2. +
      3. + Billing
        + The resized Linode will be billed at the hourly rate of the new Linode plan going forward. +
      4. +
      5. + Enjoyment
        + After the migration completes, you can take advantage of the new resources by resizing your disks. +
      6. +
      +
      +
      + + +
      + +
      +
      +
      + + diff --git a/linodes/resize/resize.css b/linodes/resize/resize.css new file mode 100644 index 0000000..639fbc8 --- /dev/null +++ b/linodes/resize/resize.css @@ -0,0 +1,64 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#auto-resize { + display: none; + margin-bottom: 5px; +} + +.current { + text-decoration: line-through; +} + +div { + font-size: 14px; +} + +#eta { + font-weight: bold; +} + +h2 { + margin: 0px; +} + +h3 { + margin: 0px; +} + +li { + margin-bottom: 15px; +} + +.lmc-table td { + vertical-align: top; + width: 25%; +} + +.lmc-table td:last-child { + width: 50%; +} + +ol { + font-size: 14px; +} + +#resize { + padding: 0px 15px 15px; +} diff --git a/linodes/resize/resize.js b/linodes/resize/resize.js new file mode 100644 index 0000000..20b5fbd --- /dev/null +++ b/linodes/resize/resize.js @@ -0,0 +1,250 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, migrateETA, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.autoResize = "auto-resize"; + elements.autoResizeBox = "auto-resize-box"; + elements.current = "current"; + elements.dedicated = "dedicated"; + elements.diskName = "disk-name"; + elements.eta = "eta"; + elements.gpu = "gpu"; + elements.instanceType = "instance-type"; + elements.highmem = "highmem"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.nanode = "nanode"; + elements.resizeButton = "resize-button"; + elements.standard = "standard"; + + // Data received from API calls + var data = {}; + data.disks = []; + data.linode = {}; + data.types = []; + + // Static references to UI elements + var ui = {}; + ui.autoResize = {}; + ui.autoResizeBox = {}; + ui.dedicated = {}; + ui.diskName = {}; + ui.eta = {}; + ui.gpu = {}; + ui.highmem = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.nanode = {}; + ui.resizeButton = {}; + ui.standard = {}; + + // Creates a Linode type radio button and label + var createTypeButton = function(type) + { + // Radio button + var radio = document.createElement("input"); + radio.id = type.id; + radio.type = "radio"; + radio["name"] = elements.instanceType; + radio.value = type.id; + + // Label + var label = document.createElement("label"); + label.htmlFor = type.id; + label.innerHTML = type.label; + + // Text to display next to current plan + var current = document.createElement("span"); + current.innerHTML = " (current plan)"; + + var br = document.createElement("br"); + + // Insert elements + ui[type["class"]].appendChild(radio); + ui[type["class"]].appendChild(label); + + if (type.id == data.linode.type) { + radio.disabled = true; + label.className = elements.current; + ui[type["class"]].appendChild(current); + } + + ui[type["class"]].appendChild(br); + }; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } else { + ui.linodeTag.style.display = "none"; + } + + // Get linode types + apiGet("/linode/types", displayTypes, null); + }; + + // Callback for linode disks API call + var displayDisks = function(response) + { + // Add disks to array + data.disks = data.disks.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null); + return; + } + + // Compute total size and types of disks + var size = 0; + var numExt = 0; + var numSwap = 0; + for (var i = 0; i < data.disks.length; i++) { + size += data.disks[i].size; + if (data.disks[i].filesystem.match(/ext3|ext4/)) { + numExt++; + ui.diskName.innerHTML = data.disks[i].label; + } + else if (data.disks[i].filesystem == "swap") + numSwap++; + } + + // Compute estimated resize time + ui.eta.innerHTML = migrateETA(size, true); + + // Show auto-resize option if there is only a single ext disk + if ((data.disks.length == 1 && numExt == 1) || (data.disks.length == 2 && numExt == 1 && numSwap == 1)) { + ui.autoResizeBox.disabled = false; + ui.autoResizeBox.checked = true; + ui.autoResize.style.display = "block"; + } + }; + + // Callback for linode types API call + var displayTypes = function(response) + { + // Add types to array + data.types = data.types.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/linode/types?page=" + (response.page + 1), displayTypes, null); + return; + } + + // Insert types + for (var i = 0; i < data.types.length; i++) + createTypeButton(data.types[i]); + + ui.resizeButton.disabled = false; + }; + + // Resize button handler + var handleResize = function(event) + { + if (event.currentTarget.disabled) + return; + + // Find the selected type + var type = null; + var inputs = document.getElementsByTagName("input"); + for (var i = 0; i < inputs.length; i++) { + if (inputs[i]["name"] == elements.instanceType && inputs[i].checked) { + type = inputs[i]; + break; + } + } + + + if (!type) { + alert("You must choose a new plan."); + return; + } + + if (!confirm("Immediately shut down, migrate your Linode, and invoice this account for the difference?")) + return; + + var request = { + "type": type.id, + "allow_auto_disk_resize": (!ui.autoResizeBox.disabled && ui.autoResizeBox.checked) + }; + apiPost("/linode/instances/" + data.params.lid + "/resize", request, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.params.lid; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.autoResize = document.getElementById(elements.autoResize); + ui.autoResizeBox = document.getElementById(elements.autoResizeBox); + ui.dedicated = document.getElementById(elements.dedicated); + ui.diskName = document.getElementById(elements.diskName); + ui.eta = document.getElementById(elements.eta); + ui.gpu = document.getElementById(elements.gpu); + ui.highmem = document.getElementById(elements.highmem); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.nanode = document.getElementById(elements.nanode); + ui.resizeButton = document.getElementById(elements.resizeButton); + ui.standard = document.getElementById(elements.standard); + + // Register resize button handler + ui.resizeButton.addEventListener("click", handleResize); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/linodes/settings/index.shtml b/linodes/settings/index.shtml new file mode 100644 index 0000000..416c698 --- /dev/null +++ b/linodes/settings/index.shtml @@ -0,0 +1,140 @@ + + + + + + LMC - Settings + + + + + + + +
      + +
      +

      Lassie setting saved.

      +

      Alert settings saved.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Settings
      Display Settings
      Linode LabelRename your Linode
      Tags (comma-separated)Group Linodes together on the Linodes tab using tags!
      Shutdown Watchdog
      Description + Lassie is a Shutdown Watchdog that monitors your Linode and will reboot it if it powers off unexpectedly. It works by issuing a boot job when your Linode powers off without a shutdown job being responsible.
      + To prevent a boot loop, Lassie will give up if there have been more than 5 boot jobs issued within 15 minutes. +
      Lassie is currently + +
      Email Alert Thresholds
      Description + When an alert threshold is reached, an email is sent to all users that have "read" permissions on this Linode.
      + Thresholds are compared to values once per hour, 15 minutes after the hour. +
      CPU Usage | %Average CPU usage over 2 hours exceeding this value triggers this alert.
      Disk IO Rate | IO Ops/secAverage Disk IO ops/sec over 2 hours exceeding this value triggers this alert.
      Incoming Traffic | Mbit/sAverage incoming traffic over a 2 hour period exceeding this value triggers this alert.
      Outbound Traffic | Mbit/sAverage outbound traffic over a 2 hour period exceeding this value triggers this alert.
      Transfer Quota | %Percentage of network transfer quota used being greater than this value will trigger this alert.
      +
      +
      + + diff --git a/linodes/settings/settings.css b/linodes/settings/settings.css new file mode 100644 index 0000000..3adb308 --- /dev/null +++ b/linodes/settings/settings.css @@ -0,0 +1,44 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +input[type="number"] { + width: 60px; +} + +.saved-message { + background-color: #ADD370; + display: none; + font-size: 16px; + margin-top: 0; + padding: 7px; +} + +#settings { + padding: 0px 15px 15px; +} + +tbody:not(.lmc-tbody-head) tr td:first-of-type { + font-weight: bold; + text-align: right; + white-space: nowrap; +} + +tbody:not(.lmc-tbody-head) tr:last-of-type { + border: none; +} diff --git a/linodes/settings/settings.js b/linodes/settings/settings.js new file mode 100644 index 0000000..ad6ffe1 --- /dev/null +++ b/linodes/settings/settings.js @@ -0,0 +1,238 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPut, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.alertsSaved = "alerts-saved"; + elements.cpuEnabled = "cpu-enabled"; + elements.cpuValue = "cpu-value"; + elements.incomingEnabled = "incoming-enabled"; + elements.incomingValue = "incoming-value"; + elements.ioEnabled = "io-enabled"; + elements.ioValue = "io-value"; + elements.label = "label"; + elements.lassie = "lassie"; + elements.lassieSaved = "lassie-saved"; + elements.linodeLabel = "linode-label"; + elements.linodeTag = "linode-tag"; + elements.linodeTagLink = "linode-tag-link"; + elements.outboundEnabled = "outbound-enabled"; + elements.outboundValue = "outbound-value"; + elements.saveAlerts = "save-alerts"; + elements.saveDisplay = "save-display"; + elements.saveLassie = "save-lassie"; + elements.tags = "tags"; + elements.transferEnabled = "transfer-enabled"; + elements.transferValue = "transfer-value"; + + // Data recieved from API calls + var data = {}; + data.linode = {}; + + // Static references to UI elements + var ui = {}; + ui.alertsSaved = {}; + ui.cpuEnabled = {}; + ui.cpuValue = {}; + ui.incomingEnabled = {}; + ui.incomingValue = {}; + ui.ioEnabled = {}; + ui.ioValue = {}; + ui.label = {}; + ui.lassie = {}; + ui.lassieSaved = {}; + ui.linodeLabel = {}; + ui.linodeTag = {}; + ui.linodeTagLink = {}; + ui.outboundEnabled = {}; + ui.outboundValue = {}; + ui.saveAlerts = {}; + ui.saveDisplay = {}; + ui.saveLassie = {}; + ui.tags = {}; + ui.transferEnabled = {}; + ui.transferValue = {}; + + // Callback for linode details API call + var displayDetails = function(response) + { + data.linode = response; + + // Set page title and header stuff + document.title += " // " + data.linode.label; + ui.linodeLabel.innerHTML = data.linode.label; + if (data.linode.tags.length == 1) { + ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; + ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; + ui.linodeTag.style.display = "inline"; + } + + // Fill in values + ui.label.value = data.linode.label; + ui.tags.value = data.linode.tags.join(","); + ui.saveDisplay.disabled = false; + if (data.linode.watchdog_enabled) + ui.lassie.value = "enabled"; + else + ui.lassie.value = "disabled"; + ui.saveLassie.disabled = false; + ui.cpuEnabled.checked = data.linode.alerts.cpu; + ui.cpuValue.value = data.linode.alerts.cpu; + ui.ioEnabled.checked = data.linode.alerts.io; + ui.ioValue.value = data.linode.alerts.io; + ui.incomingEnabled.checked = data.linode.alerts.network_in; + ui.incomingValue.value = data.linode.alerts.network_in; + ui.outboundEnabled.checked = data.linode.alerts.network_out; + ui.outboundValue.value = data.linode.alerts.network_out; + ui.transferEnabled.checked = data.linode.alerts.transfer_quota; + ui.transferValue.value = data.linode.alerts.transfer_quota; + ui.saveAlerts.disabled = false; + }; + + // Handler for alert settings save + var handleSaveAlerts = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "alerts": { + "cpu": parseInt(ui.cpuValue.value), + "io": parseInt(ui.ioValue.value), + "network_in": parseInt(ui.incomingValue.value), + "network_out": parseInt(ui.outboundValue.value), + "transfer_quota": parseInt(ui.transferValue.value) + } + }; + + // Set values to 0 if not enabled + if (!ui.cpuEnabled.checked) + req.alerts.cpu = 0; + if (!ui.ioEnabled.checked) + req.alerts.io = 0; + if (!ui.incomingEnabled.checked) + req.alerts.network_in = 0; + if (!ui.outboundEnabled.checked) + req.alerts.network_out = 0; + if (!ui.transferEnabled.checked) + req.alerts.transfer_quota = 0; + + var callback = function(response) + { + ui.alertsSaved.style.display = "block"; + }; + + apiPut("/linode/instances/" + data.params.lid, req, callback); + }; + + // Handler for display settings save + var handleSaveDisplay = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "label": ui.label.value, + "tags": [] + }; + + if (ui.tags.value.length) + req.tags = ui.tags.value.split(","); + + var callback = function(response) + { + location.reload(); + }; + + apiPut("/linode/instances/" + data.params.lid, req, callback); + }; + + // Handler for Lassie settings save + var handleSaveLassie = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "watchdog_enabled": (ui.lassie.value == "enabled") + }; + + var callback = function(response) + { + ui.lassieSaved.style.display = "block"; + }; + + apiPut("/linode/instances/" + data.params.lid, req, callback); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a Linode ID, so die if we don't have it + if (!data.params.lid) { + alert("No Linode ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper Linode ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); + + // Get element references + ui.alertsSaved = document.getElementById(elements.alertsSaved); + ui.cpuEnabled = document.getElementById(elements.cpuEnabled); + ui.cpuValue = document.getElementById(elements.cpuValue); + ui.incomingEnabled = document.getElementById(elements.incomingEnabled); + ui.incomingValue = document.getElementById(elements.incomingValue); + ui.ioEnabled = document.getElementById(elements.ioEnabled); + ui.ioValue = document.getElementById(elements.ioValue); + ui.label = document.getElementById(elements.label); + ui.lassie = document.getElementById(elements.lassie); + ui.lassieSaved = document.getElementById(elements.lassieSaved); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.linodeTag = document.getElementById(elements.linodeTag); + ui.linodeTagLink = document.getElementById(elements.linodeTagLink); + ui.outboundEnabled = document.getElementById(elements.outboundEnabled); + ui.outboundValue = document.getElementById(elements.outboundValue); + ui.saveAlerts = document.getElementById(elements.saveAlerts); + ui.saveDisplay = document.getElementById(elements.saveDisplay); + ui.saveLassie = document.getElementById(elements.saveLassie); + ui.tags = document.getElementById(elements.tags); + ui.transferEnabled = document.getElementById(elements.transferEnabled); + ui.transferValue = document.getElementById(elements.transferValue); + + // Attach event handlers + ui.saveAlerts.addEventListener("click", handleSaveAlerts); + ui.saveDisplay.addEventListener("click", handleSaveDisplay); + ui.saveLassie.addEventListener("click", handleSaveLassie); + + // Get data from API + apiGet("/linode/instances/" + data.params.lid, displayDetails, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/login.css b/login.css new file mode 100644 index 0000000..ac5ea58 --- /dev/null +++ b/login.css @@ -0,0 +1,44 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +a { + text-decoration: underline; +} + +body { + background-color: #F8F8F8; + text-align: center; +} + +fieldset { + background-color: #FFF; + border: 6px solid #999; + margin: 120px auto 10px; + padding: 15px; + width: 500px; +} + +legend { + font-size: 36px; + font-weight: bold; +} + +#login { + font-size: 22px; +} diff --git a/login.js b/login.js new file mode 100644 index 0000000..b2c99de --- /dev/null +++ b/login.js @@ -0,0 +1,111 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, parseParams } from "/global.js"; +import { clientID } from "/clientID.js"; + +(function() +{ + // Element names specific to this page + elements.login = "login"; + + // Data recieved from API calls + var data = {}; + + // Generate a v4 UUID + var generateUUID = function() + { + var accept = "0123456789abcdef"; + var uuid = ""; + + for (var i = 0; i < 32; i++) + uuid += accept.charAt(Math.floor(Math.random() * accept.length)); + + uuid = uuid.slice(0, 8) + "-" + uuid.slice(8, 12) + "-" + uuid.slice(12, 16) + "-" + uuid.slice(16, 20) + "-" + uuid.slice(20); + return uuid; + }; + + // Login to Linode via OAuth + var login = function(event) + { + if (event && event.currentTarget.disabled) + return; + + localStorage.state = generateUUID(); + + var params = new URLSearchParams(); + params.set("client_id", clientID); + params.set("scope", "*"); + params.set("response_type", "token"); + params.set("state", localStorage.state); + + location.href = settings.oauthURL + "/authorize" + "?" + params.toString(); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // If we're being given an access token, store it and redirect + if (data.params.access_token && data.params.expires_in && data.params.state) { + if (localStorage.state && localStorage.state == data.params.state) { + localStorage.removeItem("state"); + localStorage.apiKey = data.params.access_token; + localStorage.apiExpire = Date.now() + (data.params.expires_in * 1000); + if (localStorage.redirectTo) + location.href = localStorage.redirectTo; + else + location.href = "/linodes/"; + return; + } + + // If the returned state doesn't match our local one, scrap everything and start over + alert("Something's fishy here. Let's try again."); + } + + // If we already have an unexpired token, redirect + if (localStorage.apiKey && localStorage.apiExpire) { + var now = new Date(); + var expires = new Date(parseInt(localStorage.apiExpire)); + if (expires > now) { + location.href = "/linodes/"; + return; + } + } + + // Otherwise, clear everything + localStorage.clear(); + + // Store our desired redirect + if (data.params.redirectTo) + localStorage.redirectTo = decodeURIComponent(data.params.redirectTo); + + // Don't wait for click if we were redirected from another page + if (data.params.skip && data.params.skip == "1") + login(null); + + // Register login button handler + var loginButton = document.getElementById(elements.login); + loginButton.addEventListener("click", login); + loginButton.disabled = false; + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/logout/index.html b/logout/index.html new file mode 100644 index 0000000..293ca76 --- /dev/null +++ b/logout/index.html @@ -0,0 +1,32 @@ + + + + + + LMC - Logout + + + + + +
      + Linode Manager Classic + Logging out... +
      + + diff --git a/logout/logout.css b/logout/logout.css new file mode 100644 index 0000000..3dd0be4 --- /dev/null +++ b/logout/logout.css @@ -0,0 +1,38 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +body { + background-color: #F8F8F8; + text-align: center; +} + +fieldset { + background-color: #FFF; + border: 6px solid #999; + font-size: 50px; + font-weight: bold; + margin: 120px auto 10px; + padding: 15px; + width: 500px; +} + +legend { + font-size: 36px; + font-weight: bold; +} diff --git a/logout/logout.js b/logout/logout.js new file mode 100644 index 0000000..3e34737 --- /dev/null +++ b/logout/logout.js @@ -0,0 +1,59 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, oauthPost, parseParams } from "/global.js"; +import { clientID } from "/clientID.js"; + +(function() +{ + // Data recieved from API calls + var data = {}; + + // Callback for token revoke + var redirect = function(response) + { + localStorage.clear(); + location.href = "/"; + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // Revoke only if we have an unexpired token + if (localStorage.apiKey && localStorage.apiExpire) { + var now = new Date(); + var expires = new Date(parseInt(localStorage.apiExpire)); + if (expires > now) { + var req = new URLSearchParams(); + req.set("client_id", clientID); + req.set("token", localStorage.apiKey); + oauthPost("/revoke", req, redirect); + return; + } + } + + // Otherwise clear everything and redirect to login + localStorage.clear(); + location.href = "/"; + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/add/add.css b/volumes/add/add.css new file mode 100644 index 0000000..1a489d6 --- /dev/null +++ b/volumes/add/add.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#add { + padding: 0px 15px 15px; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} + +tbody tr:last-of-type { + border: none; +} diff --git a/volumes/add/add.js b/volumes/add/add.js new file mode 100644 index 0000000..d006857 --- /dev/null +++ b/volumes/add/add.js @@ -0,0 +1,198 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.addButton = "add-button"; + elements.attachment = "attachment"; + elements.label = "label"; + elements.location = "location"; + elements.size = "size"; + + // Data recieved from API calls + var data = {}; + data.linodes = []; + data.regions = []; + + // Static references to UI elements + var ui = {}; + ui.addButton = {}; + ui.attachment = {}; + ui.label = {}; + ui.location = {}; + ui.size = {}; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to array + data.linodes = data.linodes.concat(response.data); + + // Request the next page if there are more pages + var filter = { + "+or": [] + }; + for (var i = 0; i < data.regions.length; i++) + filter["+or"].push({"region": data.regions[i].id}); + if (response.page != response.pages) { + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filter); + return; + } + + // Add linodes to selector + for (var i = 0; i < data.linodes.length; i++) { + var linode = document.createElement("option"); + linode.value = data.linodes[i].id; + linode.innerHTML = data.linodes[i].label; + ui.attachment.appendChild(linode); + if (data.params.lid && parseInt(data.params.lid) == data.linodes[i].id) { + ui.attachment.value = data.linodes[i].id; + ui.location.value = data.linodes[i].region; + } + } + + ui.addButton.disabled = false; + }; + + // Callback for regions API call + var displayRegions = function(response) + { + // Add regions that support block storage to array + for (var i = 0; i < response.data.length; i++) { + if (response.data[i].capabilities.includes("Block Storage")) + data.regions.push(response.data[i]); + } + + // Request the next page if there are more pages + if (response.page != response.pages) { + apiGet("/regions?page=" + (response.page + 1), displayRegions, null); + return; + } + + // Add regions to selector + for (var i = 0; i < data.regions.length; i++) { + var loc = document.createElement("option"); + loc.value = data.regions[i].id; + if (regionNames[data.regions[i].id]) + loc.innerHTML = regionNames[data.regions[i].id]; + else + loc.innerHTML = data.regions[i].id; + ui.location.appendChild(loc); + } + + // Request linodes in all the supported regions + var filter = { + "+or": [] + }; + for (var i = 0; i < data.regions.length; i++) + filter["+or"].push({"region": data.regions[i].id}); + apiGet("/linode/instances", displayLinodes, filter); + }; + + // Click handler for add button + var handleAdd = function(event) + { + if (event.currentTarget.disabled) + return; + + if (ui.location.value == "0") { + alert("You must select a location."); + return; + } + + var req = { + "label": ui.label.value, + "size": parseInt(ui.size.value), + "region": ui.location.value + }; + if (ui.attachment.value != "0") + req.linode_id = parseInt(ui.attachment.value); + + apiPost("/volumes", req, function(response) + { + location.href = "/volumes/settings?vid=" + response.id; + }); + }; + + // Linode select handler + var handleLinode = function(event) + { + // Set the location to the selected linode's region + var linode = null; + var lid = parseInt(ui.attachment.value); + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].id == lid) { + linode = data.linodes[i]; + break; + } + } + + if (!linode) + return; + + ui.location.value = linode.region; + }; + + // Location select handler + var handleLocation = function(event) + { + // Clear the linode selector + for (var i = ui.attachment.children.length - 1; i >= 1; i--) + ui.attachment.children[i].remove(); + + // Insert linodes in the same region + for (var i = 0; i < data.linodes.length; i++) { + if (data.linodes[i].region != ui.location.value) + continue; + + var linode = document.createElement("option"); + linode.value = data.linodes[i].id; + linode.innerHTML = data.linodes[i].label; + ui.attachment.appendChild(linode); + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + setupHeader(); + + // Get element references + ui.addButton = document.getElementById(elements.addButton); + ui.attachment = document.getElementById(elements.attachment); + ui.label = document.getElementById(elements.label); + ui.location = document.getElementById(elements.location); + ui.size = document.getElementById(elements.size); + + // Attach event handlers + ui.addButton.addEventListener("click", handleAdd); + ui.attachment.addEventListener("input", handleLinode); + ui.location.addEventListener("input", handleLocation); + + // Get data from API + apiGet("/regions", displayRegions, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/add/index.shtml b/volumes/add/index.shtml new file mode 100644 index 0000000..ccb64d7 --- /dev/null +++ b/volumes/add/index.shtml @@ -0,0 +1,76 @@ + + + + + + LMC - Add a Volume + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Add a Volume
      Label
      SizeThe size of the new volume in GiB
      Location + + The datacenter where the new volume should be created
      Attach To + + If you want to attach the new volume to a Linode, select it here
      +
      +
      + + diff --git a/volumes/attach/attach.css b/volumes/attach/attach.css new file mode 100644 index 0000000..9ccde82 --- /dev/null +++ b/volumes/attach/attach.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#attach { + padding: 0px 15px 15px; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} + +tbody tr:last-of-type { + border: none; +} diff --git a/volumes/attach/attach.js b/volumes/attach/attach.js new file mode 100644 index 0000000..dd591af --- /dev/null +++ b/volumes/attach/attach.js @@ -0,0 +1,132 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.attachButton = "attach-button"; + elements.label = "label"; + elements.linode = "linode"; + elements.volumeLabel = "volume-label"; + + // Data recieved from API calls + var data = {}; + data.volume = {}; + + // Static references to UI elements + var ui = {}; + ui.attachButton = {}; + ui.label = {}; + ui.linode = {}; + ui.volumeLabel = {}; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to selector + for (var i = 0; i < response.data.length; i++) { + var linode = document.createElement("option"); + linode.value = response.data[i].id; + linode.innerHTML = response.data[i].label; + ui.linode.appendChild(linode); + } + + // Request the next page if there are more pages + if (response.page != response.pages) { + var filter = { + "region": data.volume.region + }; + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null); + return; + } + + ui.attachButton.disabled = false; + }; + + // Callback for volume API call + var displayVolume = function(response) + { + data.volume = response; + + // Redirect to settings if already attached + if (data.volume.linode_id) + location.href = "/volumes/settings?vid=" + data.params.vid; + + // Set page title and header stuff + document.title += " // " + data.volume.label; + ui.volumeLabel.innerHTML = data.volume.label; + ui.label.innerHTML = data.volume.label; + + // Get linodes in the same DC + var filter = { + "region": data.volume.region + }; + apiGet("/linode/instances", displayLinodes, filter); + }; + + // Click handler for attach button + var handleAttach = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "linode_id": parseInt(ui.linode.value) + }; + apiPost("/volumes/" + data.params.vid + "/attach", req, function(response) + { + location.href = "/linodes/dashboard?lid=" + response.linode_id; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a volume ID, so die if we don't have it + if (!data.params.vid) { + alert("No volume ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper volume ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid); + + // Get element references + ui.attachButton = document.getElementById(elements.attachButton); + ui.label = document.getElementById(elements.label); + ui.linode = document.getElementById(elements.linode); + ui.volumeLabel = document.getElementById(elements.volumeLabel); + + // Attach event handlers + ui.attachButton.addEventListener("click", handleAttach); + + // Get data from API + apiGet("/volumes/" + data.params.vid, displayVolume, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/attach/index.shtml b/volumes/attach/index.shtml new file mode 100644 index 0000000..9597bdb --- /dev/null +++ b/volumes/attach/index.shtml @@ -0,0 +1,58 @@ + + + + + + LMC - Attach Volume + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + +
      Attach a Volume
      VolumeThe volume to attach
      Attach ToThe Linode to attach this volume to
      +
      +
      + + diff --git a/volumes/clone/clone.css b/volumes/clone/clone.css new file mode 100644 index 0000000..db6d72a --- /dev/null +++ b/volumes/clone/clone.css @@ -0,0 +1,31 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#clone { + padding: 0px 15px 15px; +} + +tbody tr td:first-of-type { + font-weight: bold; + text-align: right; +} + +tbody tr:last-of-type { + border: none; +} diff --git a/volumes/clone/clone.js b/volumes/clone/clone.js new file mode 100644 index 0000000..b85cb60 --- /dev/null +++ b/volumes/clone/clone.js @@ -0,0 +1,112 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.cloneButton = "clone-button"; + elements.label = "label"; + elements.location = "location"; + elements.newLabel = "new-label"; + elements.size = "size"; + elements.volumeLabel = "volume-label"; + + // Data recieved from API calls + var data = {}; + + // Static references to UI elements + var ui = {}; + ui.cloneButton = {}; + ui.label = {}; + ui.location = {}; + ui.newLabel = {}; + ui.size = {}; + ui.volumeLabel = {}; + + // Callback for volume API call + var displayVolume = function(response) + { + // Set page title and header stuff + document.title += " // " + response.label; + ui.volumeLabel.innerHTML = response.label; + + // Populate info table + ui.label.innerHTML = response.label; + ui.size.innerHTML = response.size; + if (regionNames[response.region]) + ui.location.innerHTML = regionNames[response.region]; + else + ui.location.innerHTML = response.region; + + ui.cloneButton.disabled = false; + }; + + // Click handler for clone button + var handleClone = function(event) + { + if (event.currentTarget.disabled) + return; + + var req = { + "label": ui.newLabel.value + }; + + apiPost("/volumes/" + data.params.vid + "/clone", req, function(response) + { + location.href = "/volumes"; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a volume ID, so die if we don't have it + if (!data.params.vid) { + alert("No volume ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper volume ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid); + + // Get element references + ui.cloneButton = document.getElementById(elements.cloneButton); + ui.label = document.getElementById(elements.label); + ui.location = document.getElementById(elements.location); + ui.newLabel = document.getElementById(elements.newLabel); + ui.size = document.getElementById(elements.size); + ui.volumeLabel = document.getElementById(elements.volumeLabel); + + // Attach event handlers + ui.cloneButton.addEventListener("click", handleClone); + + // Get data from API + apiGet("/volumes/" + data.params.vid, displayVolume, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/clone/index.shtml b/volumes/clone/index.shtml new file mode 100644 index 0000000..c39986e --- /dev/null +++ b/volumes/clone/index.shtml @@ -0,0 +1,68 @@ + + + + + + LMC - Clone a Volume + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Clone a Volume
      Volume being cloned
      Size GiBThe size of the new volume
      LocationThe datacenter where the new clone will be created
      Label for newly cloned volume
      +
      +
      + + diff --git a/volumes/detach/detach.css b/volumes/detach/detach.css new file mode 100644 index 0000000..faa5943 --- /dev/null +++ b/volumes/detach/detach.css @@ -0,0 +1,26 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#detach { + padding: 0px 15px 15px; +} + +#label { + font-weight: bold; +} diff --git a/volumes/detach/detach.js b/volumes/detach/detach.js new file mode 100644 index 0000000..74775a4 --- /dev/null +++ b/volumes/detach/detach.js @@ -0,0 +1,111 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.detachButton = "detach-button"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.volumeLabel = "volume-label"; + + // Data recieved from API calls + var data = {}; + data.volume = {}; + + // Static references to UI elements + var ui = {}; + ui.detachButton = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.volumeLabel = {}; + + // Callback for attached linode API call + var displayLinode = function(response) + { + ui.linodeLabel.innerHTML = response.label; + ui.detachButton.disabled = false; + }; + + // Callback for volume API call + var displayVolume = function(response) + { + data.volume = response; + + // Redirect to settings if unattached + if (!data.volume.linode_id) + location.href = "/volumes/settings?vid=" + data.params.vid; + + // Set page title and header stuff + document.title += " // " + data.volume.label; + ui.volumeLabel.innerHTML = data.volume.label; + ui.label.innerHTML = data.volume.label; + ui.linodeLabel.href = "/linodes/dashboard?lid=" + data.volume.linode_id; + + // Get linode info + apiGet("/linode/instances/" + data.volume.linode_id, displayLinode, null); + }; + + // Click handler for detach button + var handleDetach = function(event) + { + if (event.currentTarget.disabled) + return; + + apiPost("/volumes/" + data.params.vid + "/detach", {}, function(response) + { + location.href = "/linodes/dashboard?lid=" + data.volume.linode_id; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a volume ID, so die if we don't have it + if (!data.params.vid) { + alert("No volume ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper volume ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid); + + // Get element references + ui.detachButton = document.getElementById(elements.detachButton); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.volumeLabel = document.getElementById(elements.volumeLabel); + + // Attach event handlers + ui.detachButton.addEventListener("click", handleDetach); + + // Get data from API + apiGet("/volumes/" + data.params.vid, displayVolume, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/detach/index.shtml b/volumes/detach/index.shtml new file mode 100644 index 0000000..066eb0d --- /dev/null +++ b/volumes/detach/index.shtml @@ -0,0 +1,37 @@ + + + + + + LMC - Detach Volume + + + + + + +
      + +
      +

      The "" volume will be detached from the Linode.

      +

      It will be removed from all config profiles.

      + +
      +
      + + diff --git a/volumes/index.shtml b/volumes/index.shtml new file mode 100644 index 0000000..8abf628 --- /dev/null +++ b/volumes/index.shtml @@ -0,0 +1,52 @@ + + + + + + LMC - Volumes + + + + + + +
      + +
      + + + + + + + + + + + + + + + + +
      VolumeStatusSizeLocationAttached ToOptions
      Loading...
      + +
      +
      + + diff --git a/volumes/remove/index.shtml b/volumes/remove/index.shtml new file mode 100644 index 0000000..3aec790 --- /dev/null +++ b/volumes/remove/index.shtml @@ -0,0 +1,38 @@ + + + + + + LMC - Remove Volume + + + + + + +
      + +
      +
      You must confirm that you want to remove this Volume.
      +

      Are you sure you want to remove the "" volume from your account?

      +

      + +
      +
      + + diff --git a/volumes/remove/remove.css b/volumes/remove/remove.css new file mode 100644 index 0000000..9be09f5 --- /dev/null +++ b/volumes/remove/remove.css @@ -0,0 +1,30 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#label { + font-weight: bold; +} + +#remove { + padding: 0px 15px 15px; +} + +#warning { + display: none; +} diff --git a/volumes/remove/remove.js b/volumes/remove/remove.js new file mode 100644 index 0000000..02a2a8a --- /dev/null +++ b/volumes/remove/remove.js @@ -0,0 +1,102 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, apiDelete, apiGet, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.confirm = "confirm"; + elements.deleteButton = "delete-button"; + elements.label = "label"; + elements.volumeLabel = "volume-label"; + elements.warning = "warning"; + + // Data recieved from API calls + var data = {}; + + // Static references to UI elements + var ui = {}; + ui.confirm = {}; + ui.deleteButton = {}; + ui.label = {}; + ui.volumeLabel = {}; + ui.warning = {}; + + // Callback for volume API call + var displayVolume = function(response) + { + // Set page title and header stuff + document.title += " // " + response.label; + ui.volumeLabel.innerHTML = response.label; + ui.label.innerHTML = response.label; + ui.deleteButton.disabled = false; + }; + + // Click handler for delete button + var handleDelete = function(event) + { + if (event.currentTarget.disabled) + return; + + if (!ui.confirm.checked) { + ui.warning.style.display = "block"; + return; + } + + apiDelete("/volumes/" + data.params.vid, function(response) + { + location.href = "/volumes"; + }); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a volume ID, so die if we don't have it + if (!data.params.vid) { + alert("No volume ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper volume ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid); + + // Get element references + ui.confirm = document.getElementById(elements.confirm); + ui.deleteButton = document.getElementById(elements.deleteButton); + ui.label = document.getElementById(elements.label); + ui.volumeLabel = document.getElementById(elements.volumeLabel); + ui.warning = document.getElementById(elements.warning); + + // Attach event handlers + ui.deleteButton.addEventListener("click", handleDelete); + + // Get data from API + apiGet("/volumes/" + data.params.vid, displayVolume, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/settings/index.shtml b/volumes/settings/index.shtml new file mode 100644 index 0000000..4f2c574 --- /dev/null +++ b/volumes/settings/index.shtml @@ -0,0 +1,98 @@ + + + + + + LMC - Volumes + + + + + + +
      + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Block Storage Volume Settings
      LabelA unique name for this volume
      StatusThe current status of the volume
      Attachment + + | Detach + The Linode this volume is attached to
      SizeThe size of the volume in GiB
      LocationThe datacenter where this volume is located
      Filesystem PathThe path that this volume is accessible through when attached to a running Linode
      Instructions
      +
      +

      To get started with a new volume, you'll want to create a filesystem on it:

      + mkfs.ext4 /dev/disk/by-id/scsi-0Linode_Volume_test_volume +

      Once the volume has a filesystem, you can create a mountpoint for it:

      + mkdir /mnt/test_volume +

      Then you can mount the new volume:

      + mount /dev/disk/by-id/scsi-0Linode_Volume_test_volume /mnt/test_volume +

      If you want the volume to automatically mount every time your Linode boots, you'll want to add a line like the following to your /etc/fstab file:

      + /dev/disk/by-id/scsi-0Linode_Volume_test_volume /mnt/test_volume ext4 defaults,noatime,nofail 0 2 +
      +
      +
      + + diff --git a/volumes/settings/settings.css b/volumes/settings/settings.css new file mode 100644 index 0000000..e039d38 --- /dev/null +++ b/volumes/settings/settings.css @@ -0,0 +1,43 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +#attached { + display: none; +} + +code { + border: 1px solid #E7E6E6; + display: block; + padding: 10px; +} + +#instructions { + color: #333; + font-size: 13px; + padding: 0 60px; +} + +#settings { + padding: 0px 15px 15px; +} + +tbody:not(.lmc-tbody-head) tr td:first-of-type { + font-weight: bold; + text-align: right; +} diff --git a/volumes/settings/settings.js b/volumes/settings/settings.js new file mode 100644 index 0000000..2816787 --- /dev/null +++ b/volumes/settings/settings.js @@ -0,0 +1,209 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, apiPost, apiPut, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.attached = "attached"; + elements.attachment = "attachment"; + elements.label = "label"; + elements.linodeLabel = "linode-label"; + elements.location = "location"; + elements.path = "path"; + elements.saveButton = "save-button"; + elements.size = "size"; + elements.status = "status"; + elements.volumeLabel = "volume-label"; + + // Data recieved from API calls + var data = {}; + data.volume = {}; + + // Static references to UI elements + var ui = {}; + ui.attached = {}; + ui.attachment = {}; + ui.label = {}; + ui.linodeLabel = {}; + ui.location = {}; + ui.path = {}; + ui.saveButton = {}; + ui.size = {}; + ui.status = {}; + ui.volumeLabel = {}; + + // Temporary state + var state = {}; + state.redirect = "/volumes"; + state.requests = 0; + state.returns = 0; + + // Callback for attached linode API call + var displayLinode = function(response) + { + ui.linodeLabel.innerHTML = response.label; + }; + + // Callback for linodes API call + var displayLinodes = function(response) + { + // Add linodes to selector + for (var i = 0; i < response.data.length; i++) { + var linode = document.createElement("option"); + linode.value = response.data[i].id; + linode.innerHTML = response.data[i].label; + ui.attachment.appendChild(linode); + if (data.volume.linode_id && data.volume.linode_id == response.data[i].id) + ui.attachment.value = response.data[i].id; + } + + // Request the next page if there are more pages + if (response.page != response.pages) { + var filter = { + "region": data.volume.region + }; + apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null); + return; + } + }; + + // Callback for volume API call + var displayVolume = function(response) + { + data.volume = response; + + // Set page title and header stuff + document.title += " // " + data.volume.label; + ui.volumeLabel.innerHTML = data.volume.label; + + // Fill in details + ui.label.value = data.volume.label; + ui.status.innerHTML = data.volume.status; + ui.size.value = data.volume.size; + ui.size.min = data.volume.size; + if (regionNames[data.volume.region]) + ui.location.innerHTML = regionNames[data.volume.region]; + else + ui.location.innerHTML = data.volume.region; + ui.path.innerHTML = data.volume.filesystem_path; + + if (data.volume.linode_id) { + ui.attachment.style.display = "none"; + ui.attached.style.display = "initial"; + ui.linodeLabel.href = "/linodes/dashboard?lid=" + data.volume.linode_id; + apiGet("/linode/instances/" + data.volume.linode_id, displayLinode, null); + } else { + // Get linodes in the same DC + var filter = { + "region": data.volume.region + }; + apiGet("/linode/instances", displayLinodes, filter); + } + + ui.saveButton.disabled = false; + }; + + // Click handler for save button + var handleSave = function(event) + { + if (event.currentTarget.disabled) + return; + + state.requests = 0; + state.returns = 0; + + // Common callback + var callback = function(response) + { + state.returns++; + if (state.returns >= state.requests) + location.href = state.redirect; + }; + + // Attach request + if (!data.volume.linode_id && ui.attachment.value != "0") { + state.requests++; + state.redirect = "/linodes/dashboard?lid=" + ui.attachment.value; + var attachReq = { + "linode_id": parseInt(ui.attachment.value) + }; + apiPost("/volumes/" + data.params.vid + "/attach", attachReq, callback); + } + + // Label change request + if (ui.label.value != data.volume.label) { + state.requests++; + var labelReq = { + "label": ui.label.value + }; + apiPut("/volumes/" + data.params.vid, labelReq, callback); + } + + // Size change + var size = parseInt(ui.size.value); + if (size > data.volume.size) { + state.requests++; + var sizeReq = { + "size": size + }; + apiPost("/volumes/" + data.params.vid + "/resize", sizeReq, callback); + } + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + // We need a volume ID, so die if we don't have it + if (!data.params.vid) { + alert("No volume ID supplied!"); + return; + } + + setupHeader(); + + // Update links on page to include proper volume ID + var anchors = document.getElementsByTagName("a"); + for (var i = 0; i < anchors.length; i++) + anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid); + + // Get element references + ui.attached = document.getElementById(elements.attached); + ui.attachment = document.getElementById(elements.attachment); + ui.label = document.getElementById(elements.label); + ui.linodeLabel = document.getElementById(elements.linodeLabel); + ui.location = document.getElementById(elements.location); + ui.path = document.getElementById(elements.path); + ui.saveButton = document.getElementById(elements.saveButton); + ui.size = document.getElementById(elements.size); + ui.status = document.getElementById(elements.status); + ui.volumeLabel = document.getElementById(elements.volumeLabel); + + // Attach event handlers + ui.saveButton.addEventListener("click", handleSave); + + // Get data from API + apiGet("/volumes/" + data.params.vid, displayVolume, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})(); diff --git a/volumes/volumes.css b/volumes/volumes.css new file mode 100644 index 0000000..4f5144c --- /dev/null +++ b/volumes/volumes.css @@ -0,0 +1,42 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +@import url('/global.css'); + +table td:nth-of-type(6) { + text-align: center; +} + +tbody td:nth-of-type(5) { + font-weight: bold; +} + +tbody td:nth-of-type(6) a { + font-weight: bold; +} + +tbody td:nth-of-type(6) a:last-of-type { + font-weight: normal; +} + +tbody tr { + font-size: 14px; +} + +#volumes { + padding: 0px 15px 15px; +} diff --git a/volumes/volumes.js b/volumes/volumes.js new file mode 100644 index 0000000..e20f838 --- /dev/null +++ b/volumes/volumes.js @@ -0,0 +1,171 @@ +/* + * This file is part of Linode Manager Classic. + * + * Linode Manager Classic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Linode Manager Classic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Linode Manager Classic. If not, see . + */ + +import { settings, elements, regionNames, apiGet, parseParams, setupHeader } from "/global.js"; + +(function() +{ + // Element names specific to this page + elements.lmcRow = "lmc-tr1"; + elements.lmcRowAlt = "lmc-tr2"; + elements.loading = "loading"; + elements.volumeBody = "volume-body"; + + // Data recieved from API calls + var data = {}; + data.linodes = {}; + data.volumes = []; + + // Static references to UI elements + var ui = {}; + ui.loading = {}; + ui.volumeBody = {}; + + // Generates a table row for a volume + var createVolumeRow = function(volume, alt) + { + var row = document.createElement("tr"); + if (alt) + row.className = elements.lmcRowAlt; + else + row.className = elements.lmcRow; + + var labelCell = document.createElement("td"); + var label = document.createElement("a"); + label.href = "/volumes/settings?vid=" + volume.id; + label.innerHTML = volume.label; + labelCell.appendChild(label); + row.appendChild(labelCell); + + var status = document.createElement("td"); + status.innerHTML = volume.status; + row.appendChild(status); + + var size = document.createElement("td"); + size.innerHTML = volume.size + " GiB"; + row.appendChild(size); + + var region = document.createElement("td"); + if (regionNames[volume.region]) + region.innerHTML = regionNames[volume.region]; + else + region.innerHTML = volume.region; + row.appendChild(region); + + var attachment = document.createElement("td"); + if (volume.linode_id) { + var linode = document.createElement("a"); + linode.href = "/linodes/dashboard?lid=" + volume.linode_id; + linode.innerHTML = "linode" + volume.linode_id; + translateLinode(volume.linode_id, linode); + attachment.appendChild(linode); + } + row.appendChild(attachment); + + var options = document.createElement("td"); + var attach = document.createElement("a"); + if (volume.linode_id) { + attach.href = "/volumes/detach?vid=" + volume.id; + attach.innerHTML = "Detach"; + } else { + attach.href = "/volumes/attach?vid=" + volume.id; + attach.innerHTML = "Attach"; + } + var separator = document.createElement("span"); + separator.innerHTML = " | "; + var clone = document.createElement("a"); + clone.href = "/volumes/clone?vid=" + volume.id; + clone.innerHTML = "Clone"; + var settings = document.createElement("a"); + settings.href = "/volumes/settings?vid=" + volume.id; + settings.innerHTML = "Settings"; + var remove = document.createElement("a"); + remove.href = "/volumes/remove?vid=" + volume.id; + remove.innerHTML = "Remove"; + options.appendChild(attach); + options.appendChild(separator); + options.appendChild(clone); + options.appendChild(separator.cloneNode(true)); + options.appendChild(settings); + options.appendChild(separator.cloneNode(true)); + options.appendChild(remove); + row.appendChild(options); + + return row; + }; + + // Callback for volumes API call + var displayVolumes = function(response) + { + // Add volumes to array + data.volumes = data.volumes.concat(response.data); + + // Request the next page if there are more pages + if (response.page != response.pages) { + var progress = (response.page / response.pages) * 100; + progress = progress.toFixed(0); + ui.loading.innerHTML = "Loading " + progress + "%..."; + apiGet("/volumes?page=" + (response.page + 1), displayVolumes, null); + return; + } + + // Redirect to add page if there are no volumes + if (data.volumes.length == 0) + location.href = "/volumes/add"; + + // Insert volumes + ui.loading.remove(); + for (var i = 0; i < data.volumes.length; i++) + ui.volumeBody.appendChild(createVolumeRow(data.volumes[i], i % 2)); + }; + + // Initial setup + var setup = function() + { + // Parse URL parameters + data.params = parseParams(); + + setupHeader(); + + // Get element references + ui.loading = document.getElementById(elements.loading); + ui.volumeBody = document.getElementById(elements.volumeBody); + + // Get data from API + apiGet("/volumes", displayVolumes, null); + }; + + // Get the label of a given linode ID and update a cell's contents + var translateLinode = function(id, cell) + { + if (data.linodes[id.toString()]) { + cell.innerHTML = data.linodes[id.toString()].label; + return; + } + + var callback = function(response) + { + data.linodes[response.id.toString()] = response; + cell.innerHTML = response.label; + }; + + apiGet("/linode/instances/" + id, callback, null); + }; + + // Attach onload handler + window.addEventListener("load", setup); +})();