Skip to content

hostname validation added #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions phpipam-hosts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ def listSubnets():
sys.exit(0)


# check if hostname is a valid DNS hostname (DNS names requirements RFC952+RFC1123)
def is_valid_hostname(hostname):
if len(hostname) > 255:
return False
if hostname[-1] == ".":
hostname = hostname[:-1] # strip exactly one dot from the right, if present
allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in hostname.split("."))


# ---- Main script starts here ----

# If --restart-trigger is enabled, check if trigger file exists. If it does,
Expand Down Expand Up @@ -354,8 +364,8 @@ try:

#entry = ''

# Check the hostname. If it's not specified, generate one.
if hostname:
# Check the hostname. If it was not specified or invalid then generate one.
if hostname and is_valid_hostname(hostname):
host = hostname
else:
if state != '4':
Expand Down