gclayburg / synology-diskstation-scripts

Update Synology DNS records from DHCP IP address reservation
169 stars 41 forks source link

Read network interfaces from system and remove invalid characters from hostnames #17

Closed WolfspiritM closed 7 years ago

WolfspiritM commented 8 years ago

On Systems with a bond the interface for example is called "ovs_bond0" which breaks the current behaviour of hardcoded interfaces. This PR changes the way adapters are handled by reading out all the interfaces from the system instead of keeping a hardcoded list.

Also this PR removes all invalid characters from the hostname as I had trouble with a host that had an underscore like "host_name". Underscores are not allowed to be in hostnames and bind won't load the zone if that hostname is used. (See: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames )

gsub(/([^a-zA-Z0-9-]*|^[-]*|[-]*$)/,"",NAME)

Means: Replace every character sequence that is not a alphanumeric or a hyphen OR sequence of hyphens at the begining OR at the end of NAME with an empty string.

gclayburg commented 7 years ago

Sorry @WolfspiritM I guess I missed this PR. I'll try it out on my DSM 5.1 system before merging it. Maybe in the next few days or so I should have some time.