Compare commits

...

8 commits
v1 ... latest

Author SHA1 Message Date
Jostein Fossheim
4caf6694f9 Small fix on v6-handeling 2025-03-11 20:57:16 +01:00
Jostein Fossheim
e4cdf8df96 Re-adding lost code
Human error while rebasing the project.
2025-03-11 20:30:27 +01:00
Ruben
18c1f1a37d fix: add mikrotik details 2025-03-06 10:51:51 +01:00
Ruben
de1b5e58ca Merge remote-tracking branch 'odin/latest' 2025-03-06 10:46:03 +01:00
Ruben
3dca45e790 fix: add license 2025-03-06 10:43:30 +01:00
Ruben
f8daf710f7 fix: add license 2025-03-06 10:41:55 +01:00
Ruben
94942a1ad8 Add version check and auto-update 2025-03-05 11:15:22 +01:00
Ruben
49a4d16951 Simplify load_env 2025-03-04 18:26:36 +01:00
4 changed files with 873 additions and 233 deletions

236
LICENSE Normal file
View file

@ -0,0 +1,236 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are 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.
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.
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
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 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 work with which it is combined will remain governed by version 3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU Affero 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 Affero 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 Affero 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 Affero 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.
certman
Copyright (C) 2025 Skyfritt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
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 AGPL, see <http://www.gnu.org/licenses/>.

122
README.md
View file

@ -1,30 +1,45 @@
# DNSDrone
DNSDrone is a Bash script that automatically updates DNS records (A, AAAA, and PTR) in FreeIPA or standard DNS servers using nsupdate. It detects your current public IPv4 and IPv6 addresses and updates the configured DNS records when changes are detected.
DNSDrone is a collection of scripts for automatically updating DNS records (A, AAAA, PTR, and TXT) in FreeIPA or standard DNS servers. It supports both Bash environments and Mikrotik routers.
## Features
- Supports both IPv4 (A) and IPv6 (AAAA) records
- Optional PTR record management for both IPv4 and IPv6
- Optional TXT record management for IPv6 prefix tracking
- Supports authentication via FreeIPA user/password or TSIG keys
- Configurable through environment variables
- Debug mode for troubleshooting
- Dry run mode for testing
- Flexible .env file location detection
- Multiple IP address providers for redundancy
- Support for updating zone apex (root domain)
### Common Features
- Full DNS record management (A, AAAA, PTR, and TXT records)
- IPv6 prefix tracking and updates
- Support for zone apex (root domain) updates
- FreeIPA API integration
### Bash Script Features
- Dual authentication support (FreeIPA user/password or TSIG keys)
- Flexible configuration with environment variables and multiple .env file locations
- Advanced operational modes (debug, dry-run, auto-update)
- Multiple IP provider fallback for reliable address detection
- Automatic updates with version checking
### Mikrotik Script Features
- Native RouterOS integration
- DHCP client-based IP detection
- DoH (DNS over HTTPS) support for TXT record queries
- Cookie-based FreeIPA authentication
## Prerequisites
### For Bash Script
- curl
- jq
- dig
- nsupdate
- [ipcalc or ipcalc-ng](https://gitlab.com/ipcalc/ipcalc) ("ng" for Debian-based distros)
### For Mikrotik Script
- RouterOS with SSH capability
- DHCP client configuration
- Internet connectivity for API access
## Configuration
### Bash Script Configuration
The script looks for a `.env` file in the following locations (in order):
1. Current working directory (`.env`)
2. Script's real path directory (`.env`)
@ -32,67 +47,56 @@ The script looks for a `.env` file in the following locations (in order):
4. Script's symlink path directory (`.env.<symlink_name>`)
5. `/opt/skyfritt-tools-env/.env.<symlink_name>`
### Required Variables
#### Required Variables
| Variable | Description |
|----------|-------------|
| `SERVER` | DNS server hostname or IP address |
| `ZONE_NAME` | DNS zone name (e.g., "example.com") |
| `RECORD_NAME` | Hostname to update (without domain). Skip to update zone apex |
### Authentication Variables
Either USER/PASSWORD or TSIG authentication must be configured:
[Rest of the existing configuration documentation remains the same...]
#### FreeIPA Authentication
| Variable | Description |
|----------|-------------|
| `USER` | FreeIPA username |
| `PASSWORD` | FreeIPA password |
### Mikrotik Script Configuration
Configure the script by modifying the CONFIG dictionary:
**IMPORTANT!** When using FreeIPA's API, the records has to exist *before* the script can be used. It can only modify, not add, records.
```rsc
:local CONFIG {
"wanInterface"="VLAN666_Altibox";
"IpaServer"="ipa.demo1.freeipa.org";
"dnsZone"="demo1.freeipa.org";
"IpaUser"="admin";
"IpaPassword"="Secret123";
"apiVersion"="2.253";
"recordTTL"="300";
# [Additional configuration options...]
}
```
#### TSIG Authentication
| Variable | Description |
|----------|-------------|
| `TSIG_KEYNAME` | Name of the TSIG key |
| `TSIG_KEY_TYPE` | Type of TSIG key (e.g., "hmac-sha256") |
| `TSIG_KEY` | The TSIG key value |
## Usage
### Optional Variables
### Bash Script
```bash
# Basic usage
./dnsdrone.sh
| Variable | Description | Default |
|----------|-------------|---------|
| `RECORD_TTL` | Time-to-live value for DNS records in seconds | 60 |
| `RECORD_A` | Enable IPv4 (A) record updates | false |
| `RECORD_AAAA` | Enable IPv6 (AAAA) record updates | false |
| `RECORD_PTR4` | Enable IPv4 PTR record updates | false |
| `RECORD_PTR6` | Enable IPv6 PTR record updates | false |
| `RECORD_TXT_PREFIX` | Enable TXT record updates for IPv6 prefix | false |
| `ISP_PREFIX_LENGHT` | IPv6 prefix length for TXT record updates | Required if RECORD_TXT_PREFIX is true |
| `API_VERSION` | FreeIPA API version | 2.253 |
# Debug mode
./dnsdrone.sh -d
### Example Configuration
# Dry run
./dnsdrone.sh -n
```env
# Server Configuration
SERVER=dns.example.com
ZONE_NAME=example.com
RECORD_NAME=myhost
RECORD_TTL=300
# Check for updates
./dnsdrone.sh -c
# FreeIPA Authentication
USER=dnsuser
PASSWORD=secretpassword
# Auto-update
./dnsdrone.sh -a
```
# Alternative: TSIG Authentication
# TSIG_KEYNAME=mykey
# TSIG_KEY_TYPE=hmac-sha256
# TSIG_KEY="base64encodedkey=="
### Mikrotik Script
1. Upload the script to your Mikrotik router
2. Configure the CONFIG dictionary
3. Run manually or schedule via RouterOS scheduler
# Record Configuration
RECORD_A=true
RECORD_AAAA=true
RECORD_PTR4=false
RECORD_PTR6=false
RECORD_TXT_PREFIX=true
ISP_PREFIX_LENGHT=56
## License
Licensed under GNU Affero General Public License v3 (AGPL-3.0)

View file

@ -1,25 +1,10 @@
#!rsc by RouterOS
# DNSDrone for Mikrotik - DNS Record Updater for FreeIPA
# This script:
# 1. Consolidates all configuration into a single CONFIG dictionary
# 2. Includes a function for making FreeIPA API calls
# 3. Gets current IP addresses from DHCP clients
# 4. Compares with existing DNS records
# 5. Updates records only when they differ
# 6. Handles both IPv4 and IPv6 records
# 7. Updates the prefix TXT record
#
# To use this:
# 1. Replace the configuration values in the CONFIG dictionary
# 2. Save it as a script in your Mikrotik router
# 3. Schedule it to run periodically or trigger it manually
#
# Note: You might need to adjust the HTTP headers and API calls based on your specific FreeIPA version and requirements. Also, ensure your Mikrotik router has proper SSL/TLS # certificates installed for HTTPS communication with the FreeIPA server.
# Configuration Variables
:local CONFIG {
"wanInterface"="VLAN666_Altibox";
"wanInterface"="VLAN666_WAN_Telenor";
"IpaServer"="ipa.demo1.freeipa.org";
"dnsZone"="demo1.freeipa.org";
"IpaUser"="admin";
@ -43,7 +28,7 @@
"DoHserver"="one.one.one.one";
# Script options (true/false)
"debug"="true"
"Debug"="true"
}
@ -54,9 +39,39 @@
# Import config
:local CONFIG $1;
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "";
:put "* RouterOS-multiline authentication-command (what we want):";
:put "";
:put "/tool fetch url=\"https://$($CONFIG->"IpaServer")/ipa/session/login_password\" \\";
:put " http-method=post \\";
:put " http-header-field=\"Accept: text/plain, \\";
:put " Content-Type: application/x-www-form-urlencoded, \\";
:put " Referer: https://$($CONFIG->"IpaServer")/ipa,\\";
:put " X-IPA-API-Version: $($CONFIG->"apiVersion")\" \\";
:put " http-data=\"user=$($CONFIG->"IpaUser")&password=$($CONFIG->"IpaPassword")\" \\";
:put " output=user-with-headers";
:put "";
:put "* Reverting to ugly curl+ssh workaround instead via the following command:";
:put "";
:put "/system ssh-exec \"$($CONFIG->"curlproxyserver")\" user=\"$($CONFIG->"curlproxyuser")\" \\";
:put " command=\"curl -s -k -i -H 'Accept: text/plain' \\";
:put " -H 'Content-Type: application/x-www-form-urlencoded' \\";
:put " -H 'Referer: https://$($CONFIG->"IpaServer")/ipa' \\";
:put " -H 'X-IPA-API-Version: $($CONFIG->"apiVersion")' \\";
:put " --data-urlencode 'user=$($CONFIG->"IpaUser")' \\";
:put " --data-urlencode 'password=$($CONFIG->"IpaPassword")' \\";
:put " 'https://$($CONFIG->"IpaServer")/ipa/session/login_password'\" \\";
:put " output-to-file=\"$($CONFIG->"cookiefile")\"";
:put "";
}
# Save Cookie-information in tempoary local file via ugly ssh hack
/system ssh "$($CONFIG->"curlproxyserver")" user="$($CONFIG->"curlproxyuser")" \
/system ssh-exec "$($CONFIG->"curlproxyserver")" user="$($CONFIG->"curlproxyuser")" \
command="curl -s -k -i -H 'Accept: text/plain' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Referer: https://$($CONFIG->"IpaServer")/ipa' \
@ -80,7 +95,7 @@
:if ($startIndex != -1) do={
:set startIndex ($startIndex + 12)
:local endIndex [:find $fileContents "\n" $startIndex]
:local endIndex [:find $fileContents "\r\n" $startIndex]
:if ($endIndex = -1) do={
:set endIndex [:len $fileContents]
}
@ -91,8 +106,8 @@
# Cleaning up the cookiefile
/file remove "$($CONFIG->"cookiefile")"
:put "DEBUG (function: GetIPACookie):;
:put Ipakjeks: $cookie";
# :put "DEBUG (function: GetIPACookie):;
# :put Ipakjeks: $cookie";
# Output
:return "$cookie";
@ -113,42 +128,70 @@
:local resultClean;
:if ($ConfigType = "ipv4address" ) do={
# Retrieve information with error handling
:local dhcpError;
:onerror dhcpError in={
:set resultRAW [/ip dhcp-client get [/ip dhcp-client find interface="$($CONFIG->"wanInterface")"] address];
} do={
:put "* Warning: Failed to get DHCPv4 address for interface $($CONFIG->"wanInterface"): $dhcpError";
# Set default value on error
:set resultRAW "";
}
# Clean information only if resultRAW was set successfully
:if ([:len "$resultRAW"] != 0) do={
:set resultClean [:pick "$resultRAW" 0 [:find "$resultRAW" "/"]];
} else={
:set resultClean "NA";
}
# Retrive information
:set resultRAW [/ip dhcp-client get [/ip dhcp-client find interface="$($CONFIG->"wanInterface")"] address];
}
# Clean information
:set resultClean [:pick "$resultRAW" 0 [:find "$resultRAW" "/"]];
# :put "DEBUG: resultClean: $resultClean";
:if ($ConfigType = "ipv6address" ) do={
# Retrieve information with error handling
:local dhcpError;
:onerror dhcpError in={
:set resultRAW [/ipv6 dhcp-client get [/ipv6 dhcp-client find interface="$($CONFIG->"wanInterface")"] address];
} do={
:put "* Warning: Failed to get DHCPv6 address for interface $($CONFIG->"wanInterface"): $dhcpError";
# Set default value on error
:set resultRAW "";
}
# Clean information only if resultRAW was set successfully
:if ([:len "$resultRAW"] != 0) do={
:set resultClean [:pick "$resultRAW" 0 [:find "$resultRAW" ","]];
} else={
:set resultClean "NA";
}
}
:if ($ConfigType = "ipv6address") do={
# Retrive information
:set resultRAW [/ipv6 dhcp-client get [/ipv6 dhcp-client find interface="$($CONFIG->"wanInterface")"] address];
# Clean information
:set resultClean [:pick "$resultRAW" 0 [:find "$resultRAW" ","]];
# :put "DEBUG: resultClean: $resultClean";
:if ($ConfigType = "ipv6prefix" ) do={
# Retrieve information with error handling
:local dhcpError;
:onerror dhcpError in={
:set resultRAW [/ipv6 dhcp-client get [/ipv6 dhcp-client find interface="$($CONFIG->"wanInterface")"] prefix];
} do={
:put "* Warning: Failed to get DHCPv6 prefix for interface $($CONFIG->"wanInterface"): $dhcpError";
# Set default value on error
:set resultRAW "";
}
# Clean information only if resultRAW was set successfully
:if ([:len "$resultRAW"] != 0) do={
:set resultClean [:pick "$resultRAW" 0 [:find "$resultRAW" ","]];
} else={
:set resultClean "NA";
}
}
:if ($ConfigType = "ipv6prefix") do={
# Retrive information
:set resultRAW [/ipv6 dhcp-client get [/ipv6 dhcp-client find interface="$($CONFIG->"wanInterface")"] prefix];
# Clean information
:set resultClean [:pick "$resultRAW" 0 [:find "$resultRAW" ","]];
# :put "DEBUG: resultClean: $resultClean";
}
# Output
:return "$resultClean";
@ -171,35 +214,56 @@
:local resultRAW;
:local resultClean;
:if ($ConfigType = "ipv4address" ) do={
# Retrive information
:set resultRAW [/resolve "$RecordName" server="$($CONFIG->"DNSserver")" type=ipv4]
# Clean information
:set resultClean "$resultRAW";
# :put "DEBUG: resultClean: $resultClean";
# Retrive information with error handling
:local resolveError;
:onerror resolveError in={
:set resultRAW [/resolve "$RecordName" server="$($CONFIG->"DNSserver")" type=ipv4];
} do={
:put "* Warning: Failed to resolve IPv4 address for $RecordName: $resolveError";
# You can set a default value or take alternative action
:set resultRAW "";
}
# Clean information (only if resultRAW was set successfully)
:if ([:len "$resultRAW"] != 0) do={
:set resultClean "$resultRAW";
} else={
:set resultClean "NA";
}
}
:if ($ConfigType = "ipv6address" ) do={
# Retrive information
:set resultRAW [/resolve "$RecordName" server="$($CONFIG->"DNSserver")" type=ipv6]
# Clean information
:set resultClean "$resultRAW";
# :put "DEBUG: resultClean: $resultClean";
# Retrive information with error handling
:local resolveError;
:onerror resolveError in={
:set resultRAW [/resolve "$RecordName" server="$($CONFIG->"DNSserver")" type=ipv6];
} do={
:put "* Warning: Failed to resolve IPv6 address for $RecordName: $resolveError";
# You can set a default value or take alternative action
:set resultRAW "";
}
# Clean information (only if resultRAW was set successfully)
:if ([:len "$resultRAW"] != 0) do={
:set resultClean "$resultRAW";
} else={
:set resultClean "NA";
}
}
:if ($ConfigType = "ipv6prefix") do={
# Fetch prefix TXT-record via DoH server:
:set resultRAW [/tool fetch url="https://$($CONFIG->"DoHserver")/dns-query?name=$RecordName&type=TXT" http-method=get output=user http-header-field="accept: application/dns-json" as-value];
:set resultRAW [/tool fetch \
url="https://$($CONFIG->"DoHserver")/dns-query?name=$RecordName&type=TXT" \
http-method=get http-header-field="accept: application/dns-json" \
output=user as-value];
# :put "DEBUG: resultRAW: $resultRAW";
@ -252,39 +316,108 @@
:local resultRAW;
:local resultClean;
put "DEBUG: IPACookie: $IPACookie";
put "DEBUG: ConfigType: $ConfigType";
put "DEBUG: RecordName: $RecordName";
put "DEBUG: RecordContent: $RecordContent";
:if ($ConfigType = "ipv4address" ) do={
# Construct valid json-data:
# :local httpheader "\"Accept: application/json,Content-Type: application/json, Referer: https://$($CONFIG->"IpaServer")/ipa, X-IPA-API-Version: $($CONFIG->"apiVersion"), Cookie: $IPACookie \"\"";
:local httpdata "{\"method\":\"dnsrecord_mod\",\"params\":[[\"$($CONFIG->"dnsZone")\",\"$RecordName.\"],{\"arecord\":\"$RecordContent\",\"dnsttl\":$($CONFIG->"recordTTL")}]}";
:local IPACookieData "$IPACookie";
:local IPACookieData "$cookie";
# :local IPACookieData "ipa_session=MagBearerToken=4ZTumSEI1zR%2fcPkbvlzM2lkT7CR9ojGOsvOzji0MO8ee61xUjZqXX3Ecs9n1FCHl0Vyn1U0EEooAAQk2DZ9GWT1Wt43Zx06sqDjDd5Ku8OJMa0W5SzkQuIQs%2f2hqkFoREevjwefgXurIlSxvDyVofXzJM726ZUAZsGICL9UawnWmo%2f7IVIqPRnNkb5g2NeMJKgThT0xuJ1G4nRY8w0CuIJV%2fJnVk9%2fjK%2bg%2bEjxhE3Lo%3d;path=/ipa;httponly;secure;";
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* RouterOS-multiline update-command:";
:put "";
:put "/tool fetch url=\"https://$($CONFIG->"IpaServer")/ipa/session/json\" \\";
:put " http-method=post \\";
:put " http-header-field=\"Accept: application/json, \\";
:put " Content-Type: application/json,\\";
:put " Referer: https://$($CONFIG->"IpaServer")/ipa,\\";
:put " X-IPA-API-Version: $($CONFIG->"apiVersion"),\\";
:put " Cookie: $IPACookieData\" \\";
:put " http-data=\"{\\\"method\\\":\\\"dnsrecord_mod\\\",\\\"params\\\":[[\\\"$($CONFIG->"dnsZone")\\\",\\\"$RecordName.\\\"],{\\\"arecord\\\":\\\"$RecordContent\\\",\\\"dnsttl\\\":$($CONFIG->"recordTTL")}]}\" \\";
:put " keep-result=no";
:put "";
}
put "DEBUG: (NEW)IPACookie = $IPACookie";
put "DEBUG: IPACookieData = $IPACookieData";
put "DEBUG: http-data=$httpdata";
/tool fetch url="https://$($CONFIG->"IpaServer")/ipa/session/json" \
http-method=post \
http-header-field="Accept: application/json,Content-Type: application/json,\
http-header-field="Accept: application/json, \
Content-Type: application/json,\
Referer: https://$($CONFIG->"IpaServer")/ipa,\
X-IPA-API-Version: $($CONFIG->"apiVersion"),\
Cookie: $IPACookieData" \
http-data="$httpdata" \
http-data="{\"method\":\"dnsrecord_mod\",\"params\":[[\"$($CONFIG->"dnsZone")\",\"$RecordName.\"],{\"arecord\":\"$RecordContent\",\"dnsttl\":$($CONFIG->"recordTTL")}]}" \
keep-result=no
# http-data="{\"method\":\"dnsrecord_mod\",\"params\":[[\"$($CONFIG->"dnsZone")\",\"$RecordName.\"],{\"arecord\":\"$RecordContent\",\"dnsttl\":$($CONFIG->"recordTTL")}]}" \
# Cookie: $IPACookie" \
}
:if ($ConfigType = "ipv6address" ) do={
:local IPACookieData "$IPACookie";
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* RouterOS-multiline update-command:";
:put "";
:put "/tool fetch url=\"https://$($CONFIG->"IpaServer")/ipa/session/json\" \\";
:put " http-method=post \\";
:put " http-header-field=\"Accept: application/json, \\";
:put " Content-Type: application/json,\\";
:put " Referer: https://$($CONFIG->"IpaServer")/ipa,\\";
:put " X-IPA-API-Version: $($CONFIG->"apiVersion"),\\";
:put " Cookie: $IPACookieData\" \\";
:put " http-data=\"{\\\"method\\\":\\\"dnsrecord_mod\\\",\\\"params\\\":[[\\\"$($CONFIG->"dnsZone")\\\",\\\"$RecordName.\\\"],{\\\"aaaarecord\\\":\\\"$RecordContent\\\",\\\"dnsttl\\\":$($CONFIG->"recordTTL")}]}\" \\";
:put " keep-result=no";
:put "";
}
/tool fetch url="https://$($CONFIG->"IpaServer")/ipa/session/json" \
http-method=post \
http-header-field="Accept: application/json, \
Content-Type: application/json,\
Referer: https://$($CONFIG->"IpaServer")/ipa,\
X-IPA-API-Version: $($CONFIG->"apiVersion"),\
Cookie: $IPACookieData" \
http-data="{\"method\":\"dnsrecord_mod\",\"params\":[[\"$($CONFIG->"dnsZone")\",\"$RecordName.\"],{\"aaaarecord\":\"$RecordContent\",\"dnsttl\":$($CONFIG->"recordTTL")}]}" \
keep-result=no
}
:if ($ConfigType = "ipv6prefix" ) do={
:local IPACookieData "$IPACookie";
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* RouterOS-multiline update-command:";
:put "";
:put "/tool fetch url=\"https://$($CONFIG->"IpaServer")/ipa/session/json\" \\";
:put " http-method=post \\";
:put " http-header-field=\"Accept: application/json, \\";
:put " Content-Type: application/json,\\";
:put " Referer: https://$($CONFIG->"IpaServer")/ipa,\\";
:put " X-IPA-API-Version: $($CONFIG->"apiVersion"),\\";
:put " Cookie: $IPACookieData\" \\";
:put " http-data=\"{\\\"method\\\":\\\"dnsrecord_mod\\\",\\\"params\\\":[[\\\"$($CONFIG->"dnsZone")\\\",\\\"$RecordName.\\\"],{\\\"txtrecord\\\":\\\"\\\\\\\"$RecordContent\\\\\\\"\\\",\\\"dnsttl\\\":$($CONFIG->"recordTTL")}]}\" \\";
:put " keep-result=no";
:put "";
}
/tool fetch url="https://$($CONFIG->"IpaServer")/ipa/session/json" \
http-method=post \
http-header-field="Accept: application/json, \
Content-Type: application/json,\
Referer: https://$($CONFIG->"IpaServer")/ipa,\
X-IPA-API-Version: $($CONFIG->"apiVersion"),\
Cookie: $IPACookieData" \
http-data="{\"method\":\"dnsrecord_mod\",\"params\":[[\"$($CONFIG->"dnsZone")\",\"$RecordName.\"],{\"txtrecord\":\"\\\"$RecordContent\\\"\",\"dnsttl\":$($CONFIG->"recordTTL")}]}" \
keep-result=no
}
:if ( "$($CONFIG->"Debug")" = "true") do={
:put ""
}
# Output
:return "$resultClean";
@ -301,24 +434,29 @@
# Main Runtime
:local UpdateDNS;
:local UpdateCurrentDualStackRecordv4;
:local UpdateCurrentDualStackRecordv6;
:local UpdateCurrentSingleStackRecordv4;
:local UpdateCurrentSingleStackRecordv6;
:local UpdateCurrentTXTRecordIPv6Prefix;
#:local IPACookie "drytest";
:local IPACookie [$GetIPACookie $CONFIG];
:put "DEBUG: IPACookie: $IPACookie";
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "";
:put "Debug: Collecting information";
:put "#############################";
:put "";
}
:local CurrentIPv4address [$GetLocalDynamicConfig $CONFIG ipv4address];
:put "DEBUG CurrentIPv4address: $CurrentIPv4address";
:local CurrentIPv6address [$GetLocalDynamicConfig $CONFIG ipv6address];
:put "DEBUG: CurrentIPV6address: $CurrentIPv6address";
:local CurrentIPv6prefix [$GetLocalDynamicConfig $CONFIG ipv6prefix];
:put "DEBUG: CurrentIPv6prefix: $CurrentIPv6prefix";
# "$($CONFIG->"dualStackName").$($CONFIG->"dnsZone")"
:local CurrentDualStackRecordName "$($CONFIG->"dualStackName").$($CONFIG->"dnsZone")";
:local CurrentSingleStackIPv4RecordName "$($CONFIG->"ipv4OnlyName").$($CONFIG->"dnsZone")";
@ -326,20 +464,204 @@
:local CurrentTXTRecordIPv6PrefixName "$($CONFIG->"prefixTxtName").$($CONFIG->"dnsZone")";
:local CurrentDualStackRecordv4 [$GetDynamicDNSRecords $CONFIG ipv4address $CurrentDualStackRecordName ];
:put "DEBUG: Dual-stack: $CurrentDualStackRecordName ipv4-resolves as $CurrentDualStackRecordv4";
:local CurrentDualStackRecordv6 [$GetDynamicDNSRecords $CONFIG ipv6address $CurrentDualStackRecordName ];
:put "DEBUG: Dual-stack: $CurrentDualStackRecordName ipv6-resolves as $CurrentDualStackRecordv6";
:local CurrentSingleStackRecordv4 [$GetDynamicDNSRecords $CONFIG ipv4address $CurrentSingleStackIPv4RecordName ];
:put "DEBUG: Single-stack-IPv4: $CurrentSingleStackIPv4RecordName ipv4-resolves as $CurrentSingleStackRecordv4";
:local CurrentSingleStackRecordv6 [$GetDynamicDNSRecords $CONFIG ipv6address $CurrentSingleStackIPv6RecordName ];
:put "DEBUG: Single-stack-IPv6: $CurrentSingleStackIPv6RecordName ipv6-resolves as $CurrentSingleStackRecordv6";
:local CurrentTXTRecordIPv6Prefix [$GetDynamicDNSRecords $CONFIG ipv6prefix $CurrentTXTRecordIPv6PrefixName ];
:put "DEBUG: $CurrentTXTRecordIPv6PrefixName resolves as $CurrentTXTRecordIPv6Prefix";
:local DebugUpdate [$UpdateDynamicDNSRecord $CONFIG $IPACookie ipv4address $CurrentSingleStackIPv4RecordName $CurrentIPv4address ];
:put "DEBUG: $DebugUpdate";
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* CurrentIPv4address via DHCPv4 on '$($CONFIG->"wanInterface")' is '$CurrentIPv4address'";
:put "* CurrentIPv6address via DHCPv6 on '$($CONFIG->"wanInterface")' is '$CurrentIPv6address'";
:put "* CurrentIPv6prefix via DHCPv6 on '$($CONFIG->"wanInterface")' is '$CurrentIPv6prefix'";
:put "";
:put "* '$CurrentDualStackRecordName' has the following IPv4-(A)-record '$CurrentDualStackRecordv4'";
:put "* '$CurrentDualStackRecordName' has the following IPv6-(AAAA)-record '$CurrentDualStackRecordv6';"
:put "* '$CurrentSingleStackIPv4RecordName' has the following IPv4-(A)-record '$CurrentSingleStackRecordv4'";
:put "* '$CurrentSingleStackIPv6RecordName' has the following IPv6-(AAAA)-record '$CurrentSingleStackRecordv6';"
:put "* '$CurrentTXTRecordIPv6PrefixName' has the following prefix-(TXT)-record '$CurrentTXTRecordIPv6Prefix'";
}
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "";
:put "Debug: Evaluating information";
:put "#############################";
:put "";
}
if (("$CurrentDualStackRecordv4" != "$CurrentIPv4address" ) and \
([:typeof [:toip "$CurrentIPv4address"]] = "ip")) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* '$CurrentDualStackRecordName' needs to update the IPv4-(A)-record";
}
:set $UpdateDNS "true";
:set $UpdateCurrentDualStackRecordv4 "true";
}
if (("$CurrentDualStackRecordv6" != "$CurrentIPv6address" ) && \
([:typeof [:toip6 "$CurrentIPv6address"]] = "ip6")) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* '$CurrentDualStackRecordName' needs to update the IPv6-(AAAA)-record";
}
:set $UpdateDNS "true";
:set $UpdateCurrentDualStackRecordv6 "true";
}
if (("$CurrentSingleStackRecordv4" != "$CurrentIPv4address" ) && \
([:typeof [:toip "$CurrentIPv4address"]] = "ip")) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* '$CurrentSingleStackIPv4RecordName' needs to update the IPv4-(A)-record";
}
:set $UpdateDNS "true";
:set $UpdateCurrentSingleStackRecordv4 "true";
}
if (("$CurrentSingleStackRecordv6" != "$CurrentIPv6address" ) && \
([:typeof [:toip6 "$CurrentIPv6address"]] = "ip6")) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* '$CurrentSingleStackIPv6RecordName' needs to update the IPv6-(AAAA)-record";
}
:set $UpdateDNS "true";
:set $UpdateCurrentSingleStackRecordv6 "true";
}
if (("$CurrentTXTRecordIPv6Prefix" != "$CurrentIPv6prefix" ) && \
# The following trick/workaround for the check was recomended by forum-sources:
([:typeof ([[:parse "return $CurrentIPv6prefix"]])] = "ip6-prefix")) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* '$CurrentTXTRecordIPv6PrefixName' needs to update the prefix-(TXT)-record";
}
:set $UpdateDNS "true";
:set $UpdateCurrentTXTRecordIPv6Prefix "true";
}
:put "";
# UPDATE INFORMATION
if ("$UpdateDNS" != "true" ) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "No DNS-updates-nescessary... everything is aye-ok!"
:put "";
}
} else {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "";
:put "Debug: Updating DNS-information";
:put "###############################";
:put "";
}
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* Attempting to authenticate against '$($CONFIG->"IpaServer")' as user '$($CONFIG->"IpaUser")'";
}
:local IPACookie [$GetIPACookie $CONFIG];
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "";
:put "* The following cookie was recived:";
:put "- '$IPACookie'";
:put "";
}
if ("$UpdateCurrentDualStackRecordv4" = "true" ) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* Attempting to update '$CurrentDualStackRecordName' IPv4-(A)-record with '$CurrentIPv4address' ";
:put ""
}
$UpdateDynamicDNSRecord $CONFIG $IPACookie ipv4address $CurrentDualStackRecordName $CurrentIPv4address;
}
if ("$UpdateCurrentDualStackRecordv6" = "true" ) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* Attempting to update '$CurrentDualStackRecordName' IPv6-(AAAA)-record with '$CurrentIPv6address' ";
:put ""
}
$UpdateDynamicDNSRecord $CONFIG $IPACookie ipv6address $CurrentDualStackRecordName $CurrentIPv6address;
}
if ("$UpdateCurrentSingleStackRecordv4" = "true" ) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* Attempting to update '$CurrentSingleStackIPv4RecordName' IPv4-(A)-record with '$CurrentIPv4address' ";
:put ""
}
$UpdateDynamicDNSRecord $CONFIG $IPACookie ipv4address $CurrentSingleStackIPv4RecordName $CurrentIPv4address;
}
if ("$UpdateCurrentSingleStackRecordv6" = "true" ) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* Attempting to update '$CurrentSingleStackIPv6RecordName' IPv4-(A)-record with '$CurrentIPv6address' ";
:put ""
}
$UpdateDynamicDNSRecord $CONFIG $IPACookie ipv6address $CurrentSingleStackIPv6RecordName $CurrentIPv6address;
}
if ("$UpdateCurrentTXTRecordIPv6Prefix" = "true" ) do {
:if ( "$($CONFIG->"Debug")" = "true") do={
:put "* Attempting to update '$CurrentTXTRecordIPv6PrefixName' prefix-(TXT)-record with '$CurrentIPv6prefix' ";
:put ""
}
$UpdateDynamicDNSRecord $CONFIG $IPACookie ipv6prefix $CurrentTXTRecordIPv6PrefixName $CurrentIPv6prefix;
}
}

View file

@ -1,40 +1,35 @@
#!/usr/bin/env bash
# TODO: Make hierarchy of where to check for .env.* files.
#
# Exit on any error
# set -e
set -u # Exit on undefined variable
set -o pipefail # Exit on pipe failures
# Debug flag
DEBUG=0
DRY_RUN=0
CURRENT_VERSION="v1.1"
FORGEJO_API_URL=${FORGEJO_API_URL:-"https://forge.dmz.skyfritt.net"}
FORGEJO_ORG=${FORGEJO_ORG:-"Skyfritt"}
FORGEJO_REPO=${FORGEJO_REPO:-"dnsdrone"}
AUTO_UPDATE=${AUTO_UPDATE:-0}
CHECK_UPDATE=${CHECK_UPDATE:-0}
# Default values
RECORD_A=${RECORD_A:-false}
RECORD_AAAA=${RECORD_AAAA:-false}
RECORD_PTR4=${RECORD_PTR4:-false}
RECORD_PTR6=${RECORD_PTR6:-false}
ISP_PREFIX_LENGHT="${ISP_PREFIX_LENGHT:-false}"
# TXT_PREFIX_NAME="${TXT_PREFIX_NAME:-false}"
API_VERSION=${API_VERSION:-2.253}
IPCALC_CMD=${IPCALC_CMD:-false}
RECORD_NAME=${RECORD_NAME:-false}
# Error handling function
error() {
echo "[ERROR] $1" >&2
exit 1
}
# Function to handle debug output
debug() {
[[ $DEBUG -eq 1 ]] && echo "[DEBUG] $1"
}
# Function to check dependencies
check_dependencies() {
local missing=0
for cmd in curl jq dig nsupdate; do
@ -44,7 +39,6 @@ check_dependencies() {
fi
done
# Check for ipcalc-ng first, fall back to ipcalc
if command -v ipcalc-ng >/dev/null 2>&1; then
debug "Using ipcalc-ng"
IPCALC_CMD="ipcalc-ng"
@ -60,50 +54,69 @@ check_dependencies() {
}
load_env() {
local fullRealPath fullLinkPath realPath linkPath realName linkName callDir
linkName="$(basename $0)"
fullLinkPath="$(readlink "$0")"
fullRealPath="$(realpath "$0")"
realName="$(basename "$fullRealPath")"
realPath="$(dirname "$fullRealPath")"
linkPath="$(dirname "$fullLinkPath")"
callDir="$(pwd)"
local skyfrittEnvPath="/opt/skyfritt-tools-env"
local envFile=""
local linkName realName envFile=""
linkName="$(basename "$0")"
realName="$(basename "$(realpath "$0")")"
local -r skyfrittEnvPath="/opt/skyfritt-tools-env"
local -a searchPaths=(
"$(pwd)/.env"
"$(dirname "$(realpath "$0")")/.env"
"$(dirname "$(realpath "$0")")/.env.${realName}"
"$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")/.env.${linkName}"
"${skyfrittEnvPath}/.env.${linkName}"
)
debug "Checking for .env file in multiple locations"
if [[ -f "${callDir}/.env" ]]; then # Check in call directory
envFile="${callDir}/.env"
debug "Found .env in call directory: ${envFile}"
elif [[ -f "${realPath}/.env" ]]; then # Check in real path directory
envFile="${realPath}/.env"
debug "Found .env in real path directory: ${envFile}"
elif [[ -f "${realPath}/.env.${realName}" ]]; then # Check for .env.realName in real path
envFile="${realPath}/.env.${realName}"
debug "Found .env.${realName} in real path: ${envFile}"
elif [[ -f "${linkPath}/.env.${linkName}" ]]; then # Check for .env.linkName in link path
envFile="${linkPath}/.env.${linkName}"
debug "Found .env.${linkName} in link path: ${envFile}"
elif [[ -f "${skyfrittEnvPath}/.env.${linkName}" ]]; then # Check in skyfritt env path
envFile="${skyfrittEnvPath}/.env.${linkName}"
debug "Found .env.${linkName} in skyfritt path: ${envFile}"
fi
for path in "${searchPaths[@]}"; do
if [[ -f "$path" ]]; then
envFile="$path"
debug "Found .env file: ${envFile}"
break
fi
done
[[ -z "$envFile" ]] && error ".env file not found in any location"
[[ -z "$envFile" ]] && error "No .env file found in search paths"
[[ ! -r "$envFile" ]] && error "Found .env file at ${envFile} but it's not readable"
# shellcheck source=/dev/null
source "$envFile" || error "Failed to source .env file"
if ! source "$envFile"; then
error "Failed to source .env file: ${envFile}"
fi
# Validate required environment variables
[[ -z "${SERVER:-}" ]] && error "SERVER not set in .env"
[[ -z "${ZONE_NAME:-}" ]] && error "ZONE_NAME not set in .env"
# [[ -z "${RECORD_NAME:-}" ]] && error "RECORD_NAME not set in .env"
local -a required_vars=("SERVER" "ZONE_NAME")
local missing_vars=()
for var in "${required_vars[@]}"; do
if [[ -z "${!var:-}" ]]; then
missing_vars+=("$var")
fi
done
# Check for missing required variables
if [[ ${#missing_vars[@]} -gt 0 ]]; then
error "Missing required variables in .env file: ${missing_vars[*]}"
fi
# Validate authentication method
if [[ -z "${USER:-}" || -z "${PASSWORD:-}" ]] && [[ -z "${TSIG_KEYNAME:-}" || -z "${TSIG_KEY:-}" ]]; then
error "Either USER/PASSWORD or TSIG_KEYNAME/TSIG_KEY must be set"
error "Either USER/PASSWORD or TSIG_KEYNAME/TSIG_KEY must be set in .env file"
fi
# Validate values if present
[[ -n "${RECORD_TTL:-}" ]] && [[ ! "${RECORD_TTL}" =~ ^[0-9]+$ ]] && \
error "RECORD_TTL must be a positive integer"
# Additional validation for specific record types
if [[ "${RECORD_TXT_PREFIX:-false}" == "true" ]]; then
[[ -z "${ISP_PREFIX_LENGHT:-}" ]] && \
error "ISP_PREFIX_LENGHT must be set when RECORD_TXT_PREFIX is true"
[[ ! "${ISP_PREFIX_LENGHT}" =~ ^[0-9]+$ ]] && \
error "ISP_PREFIX_LENGHT must be a positive integer"
fi
debug "Environment loaded successfully"
}
# Function to get current IPs
@ -123,7 +136,6 @@ get_current_ips() {
"v6.ident.me"
)
# Try IPv4 providers
for provider in "${ipv4_providers[@]}"; do
local temp_ipv4
temp_ipv4=$(curl -s4 --connect-timeout 5 "$provider" 2>/dev/null)
@ -133,7 +145,6 @@ get_current_ips() {
fi
done
# Try IPv6 providers
for provider in "${ipv6_providers[@]}"; do
local temp_ipv6
temp_ipv6=$(curl -s6 --connect-timeout 5 "$provider" 2>/dev/null)
@ -143,7 +154,6 @@ get_current_ips() {
fi
done
# Only error if both stacks are unavailable
if [[ -z "$ipv4" && -z "$ipv6" ]]; then
error "Failed to get any IP addresses from providers"
fi
@ -151,7 +161,6 @@ get_current_ips() {
echo "$ipv4:$ipv6"
}
# Function to get DNS records
get_dns_records() {
local record_type=$1
local result
@ -159,7 +168,6 @@ get_dns_records() {
echo "$result"
}
# Function to get PTR record
get_ptr_record() {
local ip=$1
local result
@ -167,8 +175,6 @@ get_ptr_record() {
echo "$result"
}
# Function to update FreeIPA DNS record
# IMPORTANT! The records have to exists, since we are using the api call dnsrecord_mod.
update_freeipa_record() {
local record_type=$1
local ip=$2
@ -184,7 +190,6 @@ update_freeipa_record() {
return
fi
# Validate inputs
[[ -z "$record_type" ]] && error "Record type cannot be empty"
[[ -z "$ip" ]] && error "IP address cannot be empty"
@ -229,7 +234,7 @@ update_freeipa_record() {
ip="\\\"${ip}\\\""
fi
# Now make the API call with the cookie
# Make the API call with the cookie
curl_output=$(curl -s -k \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
@ -241,7 +246,6 @@ update_freeipa_record() {
"https://${SERVER}/ipa/session/json" 2>&1)
curl_exit_code=$?
# Cleanup cookie file
rm -f "${cookie_file}"
# Parse HTTP status code from last line
@ -252,12 +256,10 @@ update_freeipa_record() {
debug "Curl exit code: $curl_exit_code"
debug "HTTP status code: $http_code"
# Check curl execution
if [[ $curl_exit_code -ne 0 ]]; then
error "Curl command failed with exit code $curl_exit_code: $data"
fi
# Check HTTP status
if [[ $http_code -ne 200 ]]; then
error "HTTP request failed with status $http_code: $data"
fi
@ -273,7 +275,6 @@ update_freeipa_record() {
debug "DNS record update completed successfully"
}
# Function to update nsupdate record
update_nsupdate_record() {
local record_type=$1
local ip=$2
@ -306,7 +307,6 @@ send
EOF
}
# Main update function
update_record() {
local record_type=$1
local current_ip=$2
@ -329,47 +329,126 @@ update_record() {
fi
}
# Main execution
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
check_for_updates() {
local latest_version
local api_endpoint="${FORGEJO_API_URL}/api/v1/repos/${FORGEJO_ORG}/${FORGEJO_REPO}/releases/latest"
debug "Checking for updates from: $api_endpoint"
latest_version=$(curl -s "$api_endpoint" | jq -r '.tag_name' 2>/dev/null)
if [[ -z "$latest_version" ]]; then
error "Failed to fetch latest version information"
fi
debug "Current version: $CURRENT_VERSION"
debug "Latest version: $latest_version"
if version_gt "$latest_version" "$CURRENT_VERSION"; then
echo "Update available: $CURRENT_VERSION$latest_version"
return 0
else
echo "You are running the latest version ($CURRENT_VERSION)"
return 1
fi
}
perform_update() {
local latest_version
local api_endpoint="${FORGEJO_API_URL}/api/v1/repos/${FORGEJO_ORG}/${FORGEJO_REPO}/releases/latest"
local raw_download_url
local current_script_path
local temp_file
latest_version=$(curl -s "$api_endpoint" | jq -r '.tag_name' 2>/dev/null)
if [[ -z "$latest_version" ]]; then
error "Failed to get latest version information. Is the repo public?"
fi
raw_download_url="${FORGEJO_API_URL}/${FORGEJO_ORG}/${FORGEJO_REPO}/raw/tag/${latest_version}/dnsdrone.sh"
debug "Downloading from: $raw_download_url"
temp_file=$(mktemp)
current_script_path=$(realpath "$0")
echo "Downloading update..."
if ! curl -s -L "$raw_download_url" -o "$temp_file"; then
rm -f "$temp_file"
error "Failed to download update"
fi
if ! bash -n "$temp_file"; then
rm -f "$temp_file"
error "Downloaded file appears to be invalid"
fi
cp "$current_script_path" "${current_script_path}.backup"
if ! mv "$temp_file" "$current_script_path"; then
cp "${current_script_path}.backup" "$current_script_path"
rm -f "$temp_file"
error "Failed to install update"
fi
chmod +x "$current_script_path"
echo "Successfully updated to version $latest_version"
echo "Previous version backed up to ${current_script_path}.backup"
exit 0
}
main() {
# Process flags
while getopts "dn" opt; do
while getopts "dnac" opt; do
case $opt in
d) DEBUG=1 ;;
n) DRY_RUN=1 ;;
a) AUTO_UPDATE=1 ;;
c) CHECK_UPDATE=1 ;;
*) error "Invalid option: -$OPTARG" ;;
esac
done
if [[ $CHECK_UPDATE -eq 1 ]]; then
check_for_updates
exit $?
fi
if [[ $AUTO_UPDATE -eq 1 ]]; then
if check_for_updates; then
perform_update
fi
fi
trap 'error "Script interrupted"' INT TERM
check_dependencies
load_env
# Construct the full domain name
if [[ $RECORD_NAME = false ]]; then
local FQDN="${ZONE_NAME}."
else
local FQDN="${RECORD_NAME}.${ZONE_NAME}."
fi
# Get current IPs
IFS=':' read -r current_ipv4 current_ipv6 <<< "$(get_current_ips)" || true
# Update A record if IPv4 is available
if [[ -n "$current_ipv4" && "${RECORD_A:-false}" == "true" ]]; then
update_record "A" "$current_ipv4"
elif [[ "${RECORD_A:-false}" == "true" ]]; then
debug "Skipping A record update - no IPv4 address available"
fi
# Update AAAA record if IPv6 is available
if [[ -n "$current_ipv6" && "${RECORD_AAAA:-false}" == "true" ]]; then
update_record "AAAA" "$current_ipv6"
elif [[ "${RECORD_AAAA:-false}" == "true" ]]; then
debug "Skipping AAAA record update - no IPv6 address available"
fi
# Check and update PTR records if configured and IP is available
if [[ "${RECORD_PTR4:-false}" == "true" ]]; then
if [[ -n "$current_ipv4" ]]; then
debug "Processing PTR record for IPv4"
@ -400,7 +479,6 @@ main() {
fi
fi
# Check for, and update TXT record with IPv6 prefix if IPv6 is available
if [[ "${RECORD_TXT_PREFIX:-false}" == true ]]; then
if [[ -n "$current_ipv6" ]]; then
local expected_network_address expected_network_address_without_prefix current_network_address current_network_address_quotes