]> git.ipfire.org Git - ddns.git/blame - ddns.in
chore: add provider and sample configuration for infomaniak.ch
[ddns.git] / ddns.in
CommitLineData
91aead36 1#!/usr/bin/python3
3fdcb9d1
MT
2###############################################################################
3# #
4# ddns - A dynamic DNS client for IPFire #
5# Copyright (C) 2012 IPFire development team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
f22ab085 21
1b8c6925
MT
22import argparse
23
f22ab085
MT
24import ddns
25
1b8c6925
MT
26from ddns.i18n import _
27
28CONFIGURATION_FILE = "@configsdir@/ddns.conf"
29
30def main():
31 # Parse command line
32 p = argparse.ArgumentParser(description=_("Dynamic DNS Updater"))
33
34 p.add_argument("-d", "--debug", action="store_true",
35 help=_("Enable debugging output"))
36
37 p.add_argument("-c", "--config", default=CONFIGURATION_FILE,
38 help=_("Load configuration file (Default: %s)") % CONFIGURATION_FILE)
39
40 # Create subparsers for commands.
41 subparsers = p.add_subparsers(help=_("Sub-command help"),
42 dest="subparsers_name")
43
9e3a3d3f
MT
44 # guess-ip-addresses
45 p_guess_ip_addresses = subparsers.add_parser("guess-ip-addresses",
46 help=_("Guess the external IP addresses"))
47
2dae4713
MT
48 # list-providers
49 p_list_providers = subparsers.add_parser("list-providers",
50 help=_("List all available providers"))
51
5e075681
SS
52 # list-token-providers
53 p_list_token_provider = subparsers.add_parser("list-token-providers",
287b2bfe
SS
54 help=_("List all providers which supports authentication via token"))
55
1b8c6925
MT
56 # update
57 p_update = subparsers.add_parser("update", help=_("Update DNS record"))
58 p_update.add_argument("hostname")
59 p_update.add_argument("--force", action="store_true",
60 help=_("Execute update even if the record is already up to date"))
61
62 # update-all
63 p_update_all = subparsers.add_parser("update-all", help=_("Update all DNS records"))
64 p_update_all.add_argument("--force", action="store_true",
65 help=_("Execute update even if the record is already up to date"))
66
67 args = p.parse_args()
68
69 # Initialise the DDNSCore module.
70 d = ddns.DDNSCore(debug=args.debug)
71
72 # Load configuration.
73 if args.config:
74 d.load_configuration(args.config)
75
76 # Handle commands...
9e3a3d3f
MT
77 if args.subparsers_name == "guess-ip-addresses":
78 # IPv6
022003bc 79 ipv6_address = d.system.guess_external_ip_address("ipv6")
9e3a3d3f 80 if ipv6_address:
91aead36 81 print("IPv6 Address: %s" % ipv6_address)
9e3a3d3f
MT
82
83 # IPv4
022003bc 84 ipv4_address = d.system.guess_external_ip_address("ipv4")
9e3a3d3f 85 if ipv4_address:
91aead36 86 print("IPv4 Address: %s" % ipv4_address)
9e3a3d3f
MT
87
88 elif args.subparsers_name == "list-providers":
2dae4713 89 provider_names = d.get_provider_names()
91aead36 90 print("\n".join(provider_names))
2dae4713 91
287b2bfe
SS
92 elif args.subparsers_name == "list-token-providers":
93 token_provider = d.get_provider_with_token_support()
94 print("\n".join(token_provider))
95
2dae4713 96 elif args.subparsers_name == "update":
1b8c6925
MT
97 d.updateone(hostname=args.hostname, force=args.force)
98
99 elif args.subparsers_name == "update-all":
100 d.updateall(force=args.force)
101
102 else:
103 raise RuntimeError("Unhandled command: %s" % args.subparsers_name)
f22ab085 104
1b8c6925 105main()