Dyndns Update bei OVH über API
Robin (Diskussion | Beiträge) |
Robin (Diskussion | Beiträge) (→Zugriff über Perl) |
||
Zeile 67: | Zeile 67: | ||
timeout => 10, |
timeout => 10, |
||
); |
); |
||
− | |||
− | if (not $ApiOvh->{consumerKey}) |
||
− | { |
||
− | my $validation = $ApiOvh->requestCredentials( |
||
− | accessRules => [ |
||
− | { |
||
− | method => "ALL", |
||
− | path => "/hosting/web*", |
||
− | }, |
||
− | { |
||
− | method => "GET", |
||
− | path => "/me", |
||
− | }, |
||
− | ] |
||
− | ); |
||
− | if (not $validation) |
||
− | { |
||
− | printf("Failed to request new credentials: %s\n", $validation); |
||
− | return 0; |
||
− | } |
||
− | |||
− | $validation = $validation->content(); |
||
− | printf("Please visit %s to authenticate,\nand press Enter to continue...", $validation->{'validationUrl'}); |
||
− | <STDIN> // die "Abort.\n"; |
||
− | $ApiOvh->{consumerKey} = $validation->{'consumerKey'}; |
||
− | printf("Your 'consumerKey' is '%s', you can save it to use it next time you want to use this script!\n", $ApiOvh->{'consumerKey'}); |
||
− | } |
||
my $rcDynDNSupd; |
my $rcDynDNSupd; |
Version vom 16. November 2022, 21:03 Uhr
Dyndns Update bei OVH über API
Bei einer bei OVH gehosteten Domain kann man auch dyndns für dynamische IP-Adressen nutzen. Leider ist das Update über das dyndns2 Protokoll nur für IPv4 Adressen möglich. Dokumentation:
https://docs.ovh.com/de/domains/verwendung-dynhost/
Problembeschreibung:
https://github.com/ovh/manager/issues/3919
Lösungsvorschlag (Update über das OVH API):
https://github.com/ovh/manager/issues/3919#issuecomment-1287119549
Zugriff über Shell Skript
Zugriff über Shell Skripte (Beispiel):
https://gist.github.com/trnsnt/8ec73cc1a0c1c6d696d5dbfdf506b671#file-ovh_api-sh
#!/bin/bash OVH_CONSUMER_KEY="***" OVH_APP_KEY="***" OVH_APP_SECRET="***" HTTP_METHOD="GET" HTTP_QUERY="https://api.ovh.com/1.0/domain" HTTP_BODY="" TIME=$(curl -s https://api.ovh.com/1.0/auth/time) CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME" SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //') curl -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
Beispiel:
https://gandrille.github.io/linux-notes/Web_API/OVH_API/OVH_API_Keys_management.html
Zugriff über Perl
Ein Update das DNS records über Shell ist mir nicht gelungen, Abfragen schon.
Ein erster Versuch mit Perl gelang. Folgende Perl-Modul ist nötig:
https://github.com/ovh/perl-ovh
Quick and dirty Perl-Skript:
Die Zugangsdaten müssen in der Datei ovh.conf abgelegt werden. Die DNS Record-ID muß vorher abgefragt werden, dies sollte idealerweise im Skript erledigt werden.
#!/usr/bin/env perl use strict; use warnings; use 5.010; use OvhApi; sub main { my $ApiOvh = OvhApi->new( timeout => 10, ); my $rcDynDNSupd; $rcDynDNSupd = $ApiOvh->put( path => '/domain/zone/<domain>/record/<record-id>', body => { subDomain => 'raccoon', target => '2003:..:...:....:....:....:....:affe', ttl => '300', }, );
}
main();