Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

[Feature] Possible IPv6-Support through built in shell-commands #17

Open
Hedrauta opened this issue May 10, 2021 · 4 comments
Open

[Feature] Possible IPv6-Support through built in shell-commands #17

Hedrauta opened this issue May 10, 2021 · 4 comments

Comments

@Hedrauta
Copy link
Contributor

Hedrauta commented May 10, 2021

Since I read alot of Issues about Synology is not transmitting the IPv6 to the script, I thought about fetching the IPv6 on my own....

I tried a lot.... but it looks like, that i "may" broke the script....

My Idea was fetching the Inet6-adresses from "ip -6 addr show eth0" ( which do contain 2 kinds of adresses ) filter the first adress, and copy all relevant commands.
Well.... it "should" work...... but it doesn't...

Maybe as a feature, to try fetching the IPv6 and sent it to Cloudflare..... I'm going to revert my changes for today.... I'm done -.-

What I tried so far:

removed
@Hedrauta
Copy link
Contributor Author

Hedrauta commented May 11, 2021

#!/bin/bash
set -e;

ipv4Regex="((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"

proxy="true"

# DSM Config
username="$1"
password="$2"
hostname="$3"
ipAddr="$4"
ip6fetch=$(ip -6 addr show eth0 | grep -oP '(?<=inet6\s)[\da-f:]+')
ip6Addr=${ip6fetch:0:$((${#ip6fetch})) - 25}
rec6type="AAAA"

if [[ $ipAddr =~ $ipv4Regex ]]; then
    recordType="A";
else
    recordType="AAAA";
fi

listDnsApi="https://api.cloudflare.com/client/v4/zones/${username}/dns_records?type=${recordType}&name=${hostname}"
list6DnsApi="https://api.cloudflare.com/client/v4/zones/${username}/dns_records?type=${rec6type}&name=${hostname}"
createDnsApi="https://api.cloudflare.com/client/v4/zones/${username}/dns_records"

res6=$(curl -s -X GET "$list6DnsApi" -H "Authorization: Bearer $password" -H "Content-Type:application/json")
res=$(curl -s -X GET "$listDnsApi" -H "Authorization: Bearer $password" -H "Content-Type:application/json")

resSuccess=$(echo "$res" | jq -r ".success")
res6Success=$(echo "$res" | jq -r ".success")

if [ $resSuccess != "true" ] || [ $res6Success != "true" ]; then
    echo "badauth";
    exit 1;
fi

recordId=$(echo "$res" | jq -r ".result[0].id")
recordIp=$(echo "$res" | jq -r ".result[0].content")
recordId6=$(echo "$res6" | jq -r ".result[0].id")
recordIp6=$(echo "$res6" | jq -r ".result[0].content")

if [ $recordIp = "$ipAddr" ] && [ $recordIp6 = "$ip6Addr" ]; then
    echo "nochg";
    exit 0;
fi

if [ $recordId = "null" ]; then
    # Record not exists
        res=$(curl -s -X POST "$createDnsApi" -H "Authorization: Bearer $password" -H "Content-Type:application/json" --data "{\"type\":\"$recordType\",\"name\":\"$hostname\",\"content\":\"$ipAddr\",\"proxied\":$proxy}");
elif [ $recordId6 = "null" ]; then
        res6=$(curl -s -X POST "$createDnsApi" -H "Authorization: Bearer $password" -H "Content-Type:application/json" --data "{\"type\":\"$rec6type\",\"name\":\"$hostname\",\"content\":\"$ip6Addr\",\"proxied\":$proxy}");
elif [ $recordIp != "$ipAddr" ]; then
    updateDnsApi="https://api.cloudflare.com/client/v4/zones/${username}/dns_records/${recordId}";
    res=$(curl -s -X PUT "$updateDnsApi" -H "Authorization: Bearer $password" -H "Content-Type:application/json" --data "{\"type\":\"$recordType\",\"name\":\"$hostname\",\"content\":\"$ipAddr\",\"proxied\":$proxy}");
elif [ $recordIp6 != "$ip6Addr" ]; then
        update6DnsApi="https://api.cloudflare.com/client/v4/zones/${username}/dns_records/${recordId6}";
        res6=$(curl -s -X PUT "$update6DnsApi" -H "Authorization: Bearer $password" -H "Content-Type:application/json" --data "{\"type\":\"$rec6type\",\"name\":\"$hostname\",\"content\":\"$ip6Addr\",\"proxied\":$proxy}");
fi

resSuccess=$(echo "$res" | jq -r ".success")
res6Success=$(echo "$res6" | jq -r ".success")

if [ $resSuccess = "true" ] || [ $res6Success = "true" ]; then
    echo "good";
else
    echo "badauth";
fi

Possible workaround for fetching IPv6 and send it to cloudflare.... will work on a check if IPv6 exists and so on.... maybe rewrite it a bit more... i'll comment if there are any updates ;)

@captainhook
Copy link

Please use a pull request…

@Hedrauta
Copy link
Contributor Author

i will ;) just.... let me fix my mess ..... also found a typo on line 51 😆 will let it "look better" then it is actually 😉

Hedrauta added a commit to Hedrauta/SynologyCloudflareDDNS that referenced this issue May 11, 2021
- Support for creating or updating IPv6 Records, ( please report any issues.... )
- Proxy will stay it's state
joshuaavalon#17 is done.....
@Hedrauta
Copy link
Contributor Author

#18
!!!! I'm done for now..... had to get some food and then some sleep....
Took me a while to get am almost clean design.
It may still look worse on some lines, but it's working. Using it right now on the DS218+ 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants