/usr/share/perl5/EBox/DHCP/Model/DynamicDNS.pm is in zentyal-dhcp 2.3.8+quantal1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | # Copyright (C) 2009-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Class: EBox::DHCP::Model::DynamicDNS
#
# This class is the model to configurate dynamic DNS options for DHCP
# server and DNS server on a static interface. The fields are the following:
#
# - enabled
# - dynamic domain
# - static domain
#
package EBox::DHCP::Model::DynamicDNS;
use base 'EBox::Model::DataForm';
use strict;
use warnings;
use EBox::Exceptions::External;
use EBox::Gettext;
use EBox::Global;
use EBox::Types::Select;
use EBox::Types::Union;
use EBox::Types::Union::Text;
use EBox::View::Customizer;
# Dependencies
# Group: Public methods
# Constructor: new
#
# Create the dynamic DNS options to the dhcp server
#
# Overrides:
#
# <EBox::Model::DataForm::new>
#
# Returns:
#
# <EBox::DHCP::Model::DynamicDNS>
#
# Exceptions:
#
# <EBox::Exceptions::MissingArgument> - thrown if any compulsory
# argument is missing
#
sub new
{
my $class = shift;
my %opts = @_;
my $self = $class->SUPER::new(@_);
bless ($self, $class);
return $self;
}
# Method: formSubmitted
#
# When the form is submitted, do something
#
# Overrides:
#
# <EBox::Model::DataForm::formSubmitted>
#
sub formSubmitted
{
my ($self, $oldRow) = @_;
# We assume the DNS module exists and is configured
my $newRow = $self->row();
my $dnsMod = EBox::Global->modInstance('dns');
my $msg = '';
if ($newRow->valueByName('enabled')) {
# Manage dynamic domain
$msg .= $self->_manageZone(newDomain => $newRow->valueByName('dynamic_domain'),
oldDomain => $oldRow->valueByName('dynamic_domain'),
dns => $dnsMod);
# Manage static domain
my ($newDomain, $oldDomain) = ($newRow->valueByName('static_domain'),
$oldRow->valueByName('static_domain'));
if ( $newRow->elementByName('static_domain')->selectedType() eq 'same' ) {
$newDomain = undef;
}
if ( $oldRow->elementByName('static_domain')->selectedType() eq 'same' ) {
$oldDomain = undef;
}
if ( $msg ) {
$msg .= '. ';
}
$msg .= $self->_manageZone(newDomain => $newDomain, oldDomain => $oldDomain,
dns => $dnsMod);
# Enable again if necessary for notifying other models using
# the same previous domain
my $currentRow = $self->row();
$currentRow->elementByName('enabled')->setValue(1);
$currentRow->store();
} elsif ( $oldRow->valueByName('enabled') ) {
# If it was enabled, remove old domains
$msg .= $self->_manageZone(newDomain => undef,
oldDomain => $oldRow->valueByName('dynamic_domain'),
dns => $dnsMod);
# Delete the static if it is different than dynamic
if ( $oldRow->elementByName('static_domain')->selectedType() eq 'custom' ) {
if ( $msg ) {
$msg .= '. ';
}
$msg .= $self->_manageZone(newDomain => undef,
oldDomain => $oldRow->valueByName('static_domain'),
dns => $dnsMod);
}
}
EBox::debug("message: $msg");
$self->setMessage($msg) if ( $msg );
}
# Method: precondition
#
# Overrides:
#
# <EBox::Model::Component::precondition>
#
sub precondition
{
my $gl = EBox::Global->getInstance();
if ( $gl->modExists('dns') ) {
my $dns = $gl->modInstance('dns');
return $dns->configured();
}
return 0;
}
# Method: preconditionFailMsg
#
# Overrides:
#
# <EBox::Model::Component::preconditionFailMsg>
#
sub preconditionFailMsg
{
my $gl = EBox::Global->getInstance();
if ( $gl->modExists('dns') ) {
my $dns = $gl->modInstance('dns');
unless ( $dns->configured() ) {
return __('DNS module must be configured to work with this feature');
}
} else {
return __x('{pkg} must be installed to use this feature', pkg => 'zentyal-dns');
}
}
# Method: viewCustomizer
#
# Overrides this to warn the user about the usage of this feature
# depends on ebox-dns module to work and it has to be enabled to work.
#
# Overrides:
#
# <EBox::Model::DataTable::viewCustomizer>
#
sub viewCustomizer
{
my ($self) = @_;
my $customizer = new EBox::View::Customizer();
$customizer->setModel($self);
my $gl = EBox::Global->getInstance();
if ( $gl->modExists('dns') ) {
my $dns = $gl->modInstance('dns');
unless ( $dns->isEnabled() ) {
my $msg = __('DNS module must be enabled to make this feature work.');
$customizer->setPermanentMessage($msg);
}
}
$customizer->setHTMLTitle([]);
return $customizer;
}
# Method: notifyForeignModelAction
#
# Disable DynamicDNS configuration for this model if the domain is
# deleted from the interface or from another interface in DHCP
# configuration
#
# Overrides:
#
# <EBox::Model::DataTable::notifyForeignModelAction>
#
sub notifyForeignModelAction
{
my ($self, $model, $action, $row) = @_;
# TODO: update action is not yet supported, since we do not have
# the old row to check the usage of the domain, currently, it is
# not possible to edit a dynamic domain
if ($action eq 'del') {
if ( $row->id() eq $self->row()->valueByName('dynamic_domain')
or $row->id() eq $self->row()->valueByName('static_domain') ) {
# Disable the dynamic DNS feature, in formSubmitted we
# have to enable again (:-S)
my $row = $self->row();
if ( $row->valueByName('enabled') ) {
$row->elementByName('enabled')->setValue(0);
$row->store();
return __x('Dynamic DNS feature has been disabled in DHCP module '
. 'in {iface} interface.', iface => $self->index());
}
}
}
return '';
}
# Group: Protected methods
# Method: _table
#
# Overrides:
#
# <EBox::Model::DataForm::_table>
#
sub _table
{
my ($self) = @_;
my @tableDesc =
(
new EBox::Types::Select(
fieldName => 'dynamic_domain',
printableName => __('Dynamic domain'),
editable => 1,
help => __('Domain name appended to the hostname from those clients '
. 'whose leased IP address comes from a range'),
foreignModel => \&_domainModel,
foreignField => 'domain',
),
new EBox::Types::Union(
fieldName => 'static_domain',
printableName => __('Static domain'),
editable => 1,
help => __('Domain name appended to the hostname from those clients '
. 'with a fixed address mapping'),
subtypes => [
new EBox::Types::Union::Text(
fieldName => 'same',
printableName => __('Same as Dynamic Domain'),
),
new EBox::Types::Select(
fieldName => 'custom',
printableName => __('Custom'),
editable => 1,
foreignModel => \&_domainModel,
foreignField => 'domain',
),
]),
);
my $dataForm = {
tableName => 'DynamicDNS',
printableTableName => __('Dynamic DNS Options'),
modelDomain => 'DHCP',
defaultActions => [ 'editField', 'changeView' ],
tableDescription => \@tableDesc,
class => 'dataForm',
help => __('The domains will be added automatically to '
. 'DNS module in read-only mode'),
# The support may be enabled or not
enableProperty => 1,
# Notify when changes in DomainTable
notifyActions => [ 'DomainTable' ],
};
return $dataForm;
}
# Group: Private methods
# Add/remove the zone/domain from DNS
# Returns a message to inform the user
sub _manageZone
{
my ($self, %args) = @_;
my $msg = "";
if ( defined($args{newDomain}) ) {
my $domainRow = $args{dns}->model('DomainTable')->row($args{newDomain});
if ( defined($domainRow) ) {
$domainRow->elementByName('dynamic')->setValue(1);
$domainRow->store();
$msg = __x('Domain "{domain}" set as dynamic in DNS section',
domain => $domainRow->printableValueByName('domain'));
} else {
throw EBox::Exceptions::Internal('Trying to modify a not valid domain from dhcp module');
}
}
if (defined($args{oldDomain}) and ($args{oldDomain} ne $args{newDomain})) {
my $domainRow = $args{dns}->model('DomainTable')->row($args{oldDomain});
if ( defined($domainRow) ) {
$domainRow->elementByName('dynamic')->setValue(0);
$domainRow->store();
if ( $msg ) {
$msg .= '. ';
}
$msg .= __x('Domain "{domain}" set as static in DNS section',
domain => $domainRow->printableValueByName('domain'));
} # else already remove by previous caller (delete a domain from DNS)
}
return $msg;
}
# Get the domain model
sub _domainModel
{
if ( EBox::Global->modExists('dns') ) {
return EBox::Global->modInstance('dns')->model('DomainTable');
} else {
return undef;
}
}
1;
|