die "value '$domain' does not look like a valid domain name!\n";
});
+PVE::JSONSchema::register_format('pve-acme-alias', sub {
+ my ($alias, $noerr) = @_;
+
+ my $label = qr/[a-z0-9_][a-z0-9_-]*/i;
+
+ return $alias if $alias =~ /^$label(?:\.$label)+$/;
+ return undef if $noerr;
+ die "value '$alias' does not look like a valid alias name!\n";
+});
+
sub config_file {
my ($node) = @_;
my $raw = eval { PVE::Tools::file_get_contents($filename); };
return {} if !$raw;
- return parse_node_config($raw);
+ return parse_node_config($raw, $filename);
}
sub write_config {
my $confdesc = {
description => {
type => 'string',
- description => 'Node description/comment.',
+ description => "Description for the Node. Shown in the web-interface node notes panel."
+ ." This is saved as comment inside the configuration file.",
+ maxLength => 64 * 1024,
optional => 1,
},
wakeonlan => {
},
alias => {
type => 'string',
- format => 'pve-acme-domain',
+ format => 'pve-acme-alias',
format_description => 'domain',
description => 'Alias for the Domain to verify ACME Challenge over DNS',
optional => 1,
};
};
-sub check_type {
- my ($key, $value) = @_;
-
- die "unknown setting '$key'\n" if !$confdesc->{$key};
-
- my $type = $confdesc->{$key}->{type};
-
- if (!defined($value)) {
- die "got undefined value\n";
- }
-
- if ($value =~ m/[\n\r]/) {
- die "property contains a line feed\n";
- }
-
- if ($type eq 'boolean') {
- return 1 if ($value eq '1') || ($value =~ m/^(on|yes|true)$/i);
- return 0 if ($value eq '0') || ($value =~ m/^(off|no|false)$/i);
- die "type check ('boolean') failed - got '$value'\n";
- } elsif ($type eq 'integer') {
- return int($1) if $value =~ m/^(\d+)$/;
- die "type check ('integer') failed - got '$value'\n";
- } elsif ($type eq 'number') {
- return $value if $value =~ m/^(\d+)(\.\d+)?$/;
- die "type check ('number') failed - got '$value'\n";
- } elsif ($type eq 'string') {
- if (my $fmt = $confdesc->{$key}->{format}) {
- PVE::JSONSchema::check_format($fmt, $value);
- return $value;
- } elsif (my $pattern = $confdesc->{$key}->{pattern}) {
- if ($value !~ m/^$pattern$/) {
- die "value does not match the regex pattern\n";
- }
- }
- return $value;
- } else {
- die "internal error"
- }
-}
+my $conf_schema = {
+ type => 'object',
+ properties => $confdesc,
+};
-sub parse_node_config {
- my ($content) = @_;
+sub parse_node_config : prototype($$) {
+ my ($content, $filename) = @_;
return undef if !defined($content);
+ my $digest = Digest::SHA::sha1_hex($content);
- my $conf = {
- digest => Digest::SHA::sha1_hex($content),
- };
- my $descr = '';
-
- my @lines = split(/\n/, $content);
- foreach my $line (@lines) {
- if ($line =~ /^\#(.*)\s*$/ || $line =~ /^description:\s*(.*\S)\s*$/) {
- $descr .= PVE::Tools::decode_text($1) . "\n";
- next;
- }
- if ($line =~ /^([a-z][a-z-_]*\d*):\s*(\S.*)\s*$/) {
- my $key = $1;
- my $value = $2;
- $value = eval { check_type($key, $value) };
- die "cannot parse value of '$key' in node config: $@" if $@;
- $conf->{$key} = $value;
- } else {
- warn "cannot parse line '$line' in node config\n";
- }
- }
-
- $conf->{description} = $descr if $descr;
+ my $conf = PVE::JSONSchema::parse_config($conf_schema, $filename, $content, 'description');
+ $conf->{digest} = $digest;
return $conf;
}
return $raw;
}
+# we always convert domain values to lower case, since DNS entries are not case
+# sensitive and ACME implementations might convert the ordered identifiers
+# to lower case
sub get_acme_conf {
my ($node_conf, $noerr) = @_;
die $err;
}
my $standalone_domains = delete($res->{domains}) // '';
+ $res->{domains} = {};
for my $domain (split(";", $standalone_domains)) {
+ $domain = lc($domain);
+ die "duplicate domain '$domain' in ACME config properties\n"
+ if defined($res->{domains}->{$domain});
+
$res->{domains}->{$domain}->{plugin} = 'standalone';
$res->{domains}->{$domain}->{_configkey} = 'acme';
}
return undef if $noerr;
die $err;
}
- my $domain = delete $parsed->{domain};
+ my $domain = lc(delete $parsed->{domain});
if (my $exists = $res->{domains}->{$domain}) {
return undef if $noerr;
die "duplicate domain '$domain' in ACME config properties"