Bug #2344
open
Disallow dots in vm names
Description
I had a user create a host with dots in the name, which appeared to auto-create the sub-domain in Foreman.
The problem is that the domain was not added to the location or organization after it was created, so every time he tried to edit the host he got a 'Host Not Found' error after a long delay.
The logs showed:
not found: Couldn't find Domain with ID=351 [WHERE (domains.id in (SELECT taxable_id from taxable_taxonomies WHERE taxable_type = 'Domain' AND taxonomy_id in (1) ) ) AND (domains.id in (SELECT taxable_id from taxable_taxonomies WHERE taxable_type = 'Domain' AND taxonomy_id in (81) ) )]
Rendered home/_topbar.rhtml (3.3ms)
Rendered common/404.rhtml within layouts/application (8.7ms)
Completed 404 Not Found in 15969ms (Views: 9.5ms | ActiveRecord: 23.7ms)
There is also the issue that if I add the domains and the proper delegations in named I now have to worry about deleting the existing A records and adding them to the new zones I create in named, where they would belong.
It seems it would be better, for the sake of not causing odd problems, to (at least optionally) disable auto creation of new domains, and disallow dots in names, unless it can be made to work more seemlessly, without opening it up to the possibility of abuse (user specifying a hostname in a domain that already exists, but not in the location or organization, and therefore getting it pulled over for use where it was not intended).
Updated by Anonymous almost 12 years ago
Until this functionality works fully it might be good to add a regex check like this on line 187 of app/models/host.rb.
validates_format_of :name, :with => /^([-\w\d]+)$/, :message => "can't be blank, contain white spaces, or contain dots."
Updated by Anonymous almost 12 years ago
After a bit more testing I realized the above won't work since it is checking on the fqdn.
So I created this to work like the downcase check:
def does_name_have_dots?
return unless name.present?
errors.add(:name, "must not contain dots") if shortname.match(/\./)
end
It seems to work as I want, not allowing dots to be entered for the name, while still allowing for a fqdn/hostname with dots, and preventing the creation of new domains.