import domain HTTP setups

This commit is contained in:
Michael Hoennig 2024-08-05 15:03:26 +02:00
parent ec0e9a5c9e
commit 2875af483d
3 changed files with 49 additions and 13 deletions

View File

@ -13,7 +13,7 @@ import static net.hostsharing.hsadminng.hs.validation.StringProperty.stringPrope
class HsDomainHttpSetupHostingAssetValidator extends HostingAssetEntityValidator { class HsDomainHttpSetupHostingAssetValidator extends HostingAssetEntityValidator {
public static final String IDENTIFIER_SUFFIX = "|HTTP"; public static final String IDENTIFIER_SUFFIX = "|HTTP";
public static final String FILESYSTEM_PATH = "^/"; public static final String FILESYSTEM_PATH = "^/.*";
public static final String PARTIAL_DOMAIN_NAME_REGEX = "(?!-)[A-Za-z0-9-]{1,63}(?<!-)"; public static final String PARTIAL_DOMAIN_NAME_REGEX = "(?!-)[A-Za-z0-9-]{1,63}(?<!-)";
HsDomainHttpSetupHostingAssetValidator() { HsDomainHttpSetupHostingAssetValidator() {

View File

@ -31,6 +31,7 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest {
.identifier("example.org|HTTP") .identifier("example.org|HTTP")
.config(Map.ofEntries( .config(Map.ofEntries(
entry("passenger-errorpage", true), entry("passenger-errorpage", true),
entry("fcgi-php-bin", "/usr/bin/whatsoever"),
entry("subdomains", Array.of("www", "test") entry("subdomains", Array.of("www", "test")
) )
)); ));
@ -54,10 +55,10 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest {
"{type=boolean, propertyName=includes, defaultValue=true}", "{type=boolean, propertyName=includes, defaultValue=true}",
"{type=boolean, propertyName=letsencrypt, defaultValue=true}", "{type=boolean, propertyName=letsencrypt, defaultValue=true}",
"{type=boolean, propertyName=multiviews, defaultValue=true}", "{type=boolean, propertyName=multiviews, defaultValue=true}",
"{type=string, propertyName=fcgi-php-bin, matchesRegEx=[^/], provided=[/usr/lib/cgi-bin/php], defaultValue=/usr/lib/cgi-bin/php}", "{type=string, propertyName=fcgi-php-bin, matchesRegEx=[^/.*], provided=[/usr/lib/cgi-bin/php], defaultValue=/usr/lib/cgi-bin/php}",
"{type=string, propertyName=passenger-nodejs, matchesRegEx=[^/], provided=[/usr/bin/node], defaultValue=/usr/bin/node}", "{type=string, propertyName=passenger-nodejs, matchesRegEx=[^/.*], provided=[/usr/bin/node], defaultValue=/usr/bin/node}",
"{type=string, propertyName=passenger-python, matchesRegEx=[^/], provided=[/usr/bin/python3], defaultValue=/usr/bin/python3}", "{type=string, propertyName=passenger-python, matchesRegEx=[^/.*], provided=[/usr/bin/python3], defaultValue=/usr/bin/python3}",
"{type=string, propertyName=passenger-ruby, matchesRegEx=[^/], provided=[/usr/bin/ruby], defaultValue=/usr/bin/ruby}", "{type=string, propertyName=passenger-ruby, matchesRegEx=[^/.*], provided=[/usr/bin/ruby], defaultValue=/usr/bin/ruby}",
"{type=string[], propertyName=subdomains, elementsOf={type=string, propertyName=subdomains, matchesRegEx=[(?!-)[A-Za-z0-9-]{1,63}(?<!-)], required=true}}" "{type=string[], propertyName=subdomains, elementsOf={type=string, propertyName=subdomains, matchesRegEx=[(?!-)[A-Za-z0-9-]{1,63}(?<!-)], required=true}}"
); );
} }
@ -155,7 +156,7 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest {
// then // then
assertThat(result).containsExactlyInAnyOrder( assertThat(result).containsExactlyInAnyOrder(
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.htdocsfallback' is expected to be of type Boolean, but is of type String", "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.htdocsfallback' is expected to be of type Boolean, but is of type String",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.fcgi-php-bin' is expected to match any of [^/] but 'false' does not match", "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.fcgi-php-bin' is expected to match any of [^/.*] but 'false' does not match",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but '' does not match", "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but '' does not match",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but '@' does not match", "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but '@' does not match",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but 'example.com' does not match"); "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but 'example.com' does not match");

View File

@ -472,11 +472,16 @@ public class ImportHostingAssets extends ImportOfficeData {
10004532=HsHostingAssetRealEntity(DOMAIN_SETUP, linuxfanboysngirls.de, linuxfanboysngirls.de), 10004532=HsHostingAssetRealEntity(DOMAIN_SETUP, linuxfanboysngirls.de, linuxfanboysngirls.de),
10004534=HsHostingAssetRealEntity(DOMAIN_SETUP, lug-mars.de, lug-mars.de), 10004534=HsHostingAssetRealEntity(DOMAIN_SETUP, lug-mars.de, lug-mars.de),
10004581=HsHostingAssetRealEntity(DOMAIN_SETUP, 1981.ist-im-netz.de, 1981.ist-im-netz.de), 10004581=HsHostingAssetRealEntity(DOMAIN_SETUP, 1981.ist-im-netz.de, 1981.ist-im-netz.de),
11004530=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, l-u-g.de|DNS, DNS für l-u-g.de, DOMAIN_SETUP:l-u-g.de, MANAGED_WEBSPACE:lug00), 11004530=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, l-u-g.de|DNS, DNS-Setup für l-u-g.de, DOMAIN_SETUP:l-u-g.de, MANAGED_WEBSPACE:lug00),
11004531=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, l-u-g.org|DNS, DNS für l-u-g.org, DOMAIN_SETUP:l-u-g.org, MANAGED_WEBSPACE:lug00), 11004531=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, l-u-g.org|DNS, DNS-Setup für l-u-g.org, DOMAIN_SETUP:l-u-g.org, MANAGED_WEBSPACE:lug00),
11004532=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, linuxfanboysngirls.de|DNS, DNS für linuxfanboysngirls.de, DOMAIN_SETUP:linuxfanboysngirls.de, MANAGED_WEBSPACE:lug00), 11004532=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, linuxfanboysngirls.de|DNS, DNS-Setup für linuxfanboysngirls.de, DOMAIN_SETUP:linuxfanboysngirls.de, MANAGED_WEBSPACE:lug00),
11004534=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, lug-mars.de|DNS, DNS für lug-mars.de, DOMAIN_SETUP:lug-mars.de, MANAGED_WEBSPACE:lug00), 11004534=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, lug-mars.de|DNS, DNS-Setup für lug-mars.de, DOMAIN_SETUP:lug-mars.de, MANAGED_WEBSPACE:lug00),
11004581=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, 1981.ist-im-netz.de|DNS, DNS für 1981.ist-im-netz.de, DOMAIN_SETUP:1981.ist-im-netz.de, MANAGED_WEBSPACE:mim00) 11004581=HsHostingAssetRealEntity(DOMAIN_DNS_SETUP, 1981.ist-im-netz.de|DNS, DNS-Setup für 1981.ist-im-netz.de, DOMAIN_SETUP:1981.ist-im-netz.de, MANAGED_WEBSPACE:mim00),
12004530=HsHostingAssetRealEntity(DOMAIN_HTTP_SETUP, l-u-g.de|HTTP, HTTP-Setup für l-u-g.de, DOMAIN_SETUP:l-u-g.de, UNIX_USER:lug00, { "autoconfig": false, "cgi": true, "fastcgi": true, "fcgi-php-bin": "/usr/lib/cgi-bin/php", "greylisting": true, "htdocsfallback": true, "includes": true, "indexes": true, "letsencrypt": false, "multiviews": true, "passenger": true, "passenger-errorpage": false, "passenger-nodejs": "/usr/bin/node", "passenger-python": "/usr/bin/python3", "passenger-ruby": "/usr/bin/ruby"}),
12004531=HsHostingAssetRealEntity(DOMAIN_HTTP_SETUP, l-u-g.org|HTTP, HTTP-Setup für l-u-g.org, DOMAIN_SETUP:l-u-g.org, UNIX_USER:lug00, { "autoconfig": false, "cgi": true, "fastcgi": true, "fcgi-php-bin": "/usr/lib/cgi-bin/php", "greylisting": true, "htdocsfallback": true, "includes": true, "indexes": true, "letsencrypt": false, "multiviews": true, "passenger": true, "passenger-errorpage": false, "passenger-nodejs": "/usr/bin/node", "passenger-python": "/usr/bin/python3", "passenger-ruby": "/usr/bin/ruby"}),
12004532=HsHostingAssetRealEntity(DOMAIN_HTTP_SETUP, linuxfanboysngirls.de|HTTP, HTTP-Setup für linuxfanboysngirls.de, DOMAIN_SETUP:linuxfanboysngirls.de, UNIX_USER:lug00-wla.2, { "autoconfig": false, "cgi": true, "fastcgi": true, "fcgi-php-bin": "/usr/lib/cgi-bin/php", "greylisting": true, "htdocsfallback": true, "includes": true, "indexes": true, "letsencrypt": false, "multiviews": true, "passenger": true, "passenger-errorpage": false, "passenger-nodejs": "/usr/bin/node", "passenger-python": "/usr/bin/python3", "passenger-ruby": "/usr/bin/ruby"}),
12004534=HsHostingAssetRealEntity(DOMAIN_HTTP_SETUP, lug-mars.de|HTTP, HTTP-Setup für lug-mars.de, DOMAIN_SETUP:lug-mars.de, UNIX_USER:lug00-wla.2, { "autoconfig": false, "cgi": true, "fastcgi": true, "fcgi-php-bin": "/usr/lib/cgi-bin/php", "greylisting": true, "htdocsfallback": true, "includes": true, "indexes": true, "letsencrypt": true, "multiviews": true, "passenger": true, "passenger-errorpage": false, "passenger-nodejs": "/usr/bin/node", "passenger-python": "/usr/bin/python3", "passenger-ruby": "/usr/bin/ruby"}),
12004581=HsHostingAssetRealEntity(DOMAIN_HTTP_SETUP, 1981.ist-im-netz.de|HTTP, HTTP-Setup für 1981.ist-im-netz.de, DOMAIN_SETUP:1981.ist-im-netz.de, UNIX_USER:mim00, { "autoconfig": false, "cgi": true, "fastcgi": true, "fcgi-php-bin": "/usr/lib/cgi-bin/php", "greylisting": true, "htdocsfallback": true, "includes": true, "indexes": true, "letsencrypt": false, "multiviews": true, "passenger": true, "passenger-errorpage": false, "passenger-nodejs": "/usr/bin/node", "passenger-python": "/usr/bin/python3", "passenger-ruby": "/usr/bin/ruby"})
} }
"""); """);
} }
@ -1109,6 +1114,7 @@ public class ImportHostingAssets extends ImportOfficeData {
final var fcgi_php_bin = rec.getString("fcgi_php_bin"); final var fcgi_php_bin = rec.getString("fcgi_php_bin");
final var domainoptions = rec.getString("domainoptions"); final var domainoptions = rec.getString("domainoptions");
// Domain Setup
final var domainSetupAsset = HsHostingAssetRealEntity.builder() final var domainSetupAsset = HsHostingAssetRealEntity.builder()
.type(DOMAIN_SETUP) .type(DOMAIN_SETUP)
// .parentAsset(parentDomainSetupAsset) are set once we've collected all of them // .parentAsset(parentDomainSetupAsset) are set once we've collected all of them
@ -1121,6 +1127,7 @@ public class ImportHostingAssets extends ImportOfficeData {
domainSetupsByName.put(domain_name, domainSetupAsset); domainSetupsByName.put(domain_name, domainSetupAsset);
hostingAssets.put(DOMAIN_SETUP_OFFSET + domain_id, domainSetupAsset); hostingAssets.put(DOMAIN_SETUP_OFFSET + domain_id, domainSetupAsset);
// Domain DNS Setup
final var ownerAsset = hostingAssets.get(UNIXUSER_ID_OFFSET + owner_id); final var ownerAsset = hostingAssets.get(UNIXUSER_ID_OFFSET + owner_id);
final var webspaceAsset = ownerAsset.getParentAsset(); final var webspaceAsset = ownerAsset.getParentAsset();
assertThat(webspaceAsset.getType()).isEqualTo(MANAGED_WEBSPACE); assertThat(webspaceAsset.getType()).isEqualTo(MANAGED_WEBSPACE);
@ -1129,12 +1136,40 @@ public class ImportHostingAssets extends ImportOfficeData {
.parentAsset(domainSetupAsset) .parentAsset(domainSetupAsset)
.assignedToAsset(webspaceAsset) .assignedToAsset(webspaceAsset)
.identifier(domain_name + "|DNS") .identifier(domain_name + "|DNS")
.caption("DNS für " + domain_name) .caption("DNS-Setup für " + domain_name)
.config(ofEntries( .config(ofEntries(
// FIXME: read from separate files // FIXME: read from separate files
)) ))
.build(); .build();
hostingAssets.put(DOMAIN_DNS_SETUP_OFFSET + domain_id, domainDnsSetupAsset); hostingAssets.put(DOMAIN_DNS_SETUP_OFFSET + domain_id, domainDnsSetupAsset);
// Domain HTTP Setup
final var options = stream(domainoptions.split(",")).collect(toSet());
final var domainHttpSetupAsset = HsHostingAssetRealEntity.builder()
.type(DOMAIN_HTTP_SETUP)
.parentAsset(domainSetupAsset)
.assignedToAsset(ownerAsset)
.identifier(domain_name + "|HTTP")
.caption("HTTP-Setup für " + domain_name)
.config(ofEntries(
entry("htdocsfallback", options.contains("htdocsfallback")),
entry("indexes", options.contains("indexes")),
entry("cgi", options.contains("cgi")),
entry("passenger", options.contains("passenger")),
entry("passenger-errorpage", options.contains("passenger-errorpage")),
entry("fastcgi", options.contains("fastcgi")),
entry("autoconfig", options.contains("autoconfig")),
entry("greylisting", options.contains("greylisting")),
entry("includes", options.contains("includes")),
entry("letsencrypt", options.contains("letsencrypt")),
entry("multiviews", options.contains("multiviews")),
entry("fcgi-php-bin", rec.getString("fcgi_php_bin")),
entry("passenger-nodejs", rec.getString("passenger_nodejs")),
entry("passenger-python", rec.getString("passenger_python")),
entry("passenger-ruby", rec.getString("passenger_ruby"))
))
.build();
hostingAssets.put(DOMAIN_HTTP_SETUP_OFFSET + domain_id, domainHttpSetupAsset);
}); });
domainSetupsByName.values().forEach(domainSetup -> { domainSetupsByName.values().forEach(domainSetup -> {