Remove use of isCustomDomain
Use adminFqdn instead as needed
This commit is contained in:
+4
-1
@@ -7,8 +7,9 @@ json="${source_dir}/../node_modules/.bin/json"
|
||||
arg_api_server_origin=""
|
||||
arg_fqdn=""
|
||||
arg_admin_location=""
|
||||
arg_admin_fqdn=""
|
||||
arg_zone_name=""
|
||||
arg_is_custom_domain="false"
|
||||
arg_is_custom_domain="false" # can be removed after 1.9
|
||||
arg_retire_reason=""
|
||||
arg_retire_info=""
|
||||
arg_token=""
|
||||
@@ -33,9 +34,11 @@ while true; do
|
||||
--data)
|
||||
# these params must be valid in all cases
|
||||
arg_fqdn=$(echo "$2" | $json fqdn)
|
||||
arg_admin_fqdn=$(echo "$2" | $json adminFqdn)
|
||||
arg_zone_name=$(echo "$2" | $json zoneName)
|
||||
[[ "${arg_zone_name}" == "" ]] && arg_zone_name="${arg_fqdn}"
|
||||
|
||||
# can be removed after 1.9
|
||||
arg_is_custom_domain=$(echo "$2" | $json isCustomDomain)
|
||||
[[ "${arg_is_custom_domain}" == "" ]] && arg_is_custom_domain="true"
|
||||
|
||||
|
||||
+2
-3
@@ -18,8 +18,7 @@ fi
|
||||
source "${script_dir}/argparser.sh" "$@" # this injects the arg_* variables used below
|
||||
|
||||
# keep this is sync with config.js appFqdn()
|
||||
admin_fqdn=$([[ "${arg_is_custom_domain}" == "true" ]] && echo "${arg_admin_location}.${arg_fqdn}" || echo "${arg_admin_location}-${arg_fqdn}")
|
||||
admin_origin="https://${admin_fqdn}"
|
||||
admin_origin="https://${arg_admin_fqdn}"
|
||||
|
||||
# copy the website
|
||||
rm -rf "${SETUP_WEBSITE_DIR}" && mkdir -p "${SETUP_WEBSITE_DIR}"
|
||||
@@ -37,7 +36,7 @@ if [[ "${arg_retire_reason}" != "" || "${existing_infra}" != "${current_infra}"
|
||||
else
|
||||
echo "Show progress bar only on admin domain for normal update"
|
||||
${box_src_dir}/node_modules/.bin/ejs-cli -f "${script_dir}/start/nginx/appconfig.ejs" \
|
||||
-O "{ \"vhost\": \"${admin_fqdn}\", \"adminOrigin\": \"${admin_origin}\", \"endpoint\": \"splash\", \"sourceDir\": \"${SETUP_WEBSITE_DIR}\", \"certFilePath\": \"cert/host.cert\", \"keyFilePath\": \"cert/host.key\", \"xFrameOptions\": \"SAMEORIGIN\", \"robotsTxtQuoted\": null, \"hasIPv6\": false }" > "${PLATFORM_DATA_DIR}/nginx/applications/admin.conf"
|
||||
-O "{ \"vhost\": \"${arg_admin_fqdn}\", \"adminOrigin\": \"${admin_origin}\", \"endpoint\": \"splash\", \"sourceDir\": \"${SETUP_WEBSITE_DIR}\", \"certFilePath\": \"cert/host.cert\", \"keyFilePath\": \"cert/host.key\", \"xFrameOptions\": \"SAMEORIGIN\", \"robotsTxtQuoted\": null, \"hasIPv6\": false }" > "${PLATFORM_DATA_DIR}/nginx/applications/admin.conf"
|
||||
fi
|
||||
|
||||
if [[ "${arg_retire_reason}" == "migrate" ]]; then
|
||||
|
||||
+8
-1
@@ -206,6 +206,13 @@ cd "${BOX_SRC_DIR}"
|
||||
BOX_ENV=cloudron DATABASE_URL=mysql://root:${mysql_root_password}@127.0.0.1/box "${BOX_SRC_DIR}/node_modules/.bin/db-migrate" up
|
||||
EOF
|
||||
|
||||
if [[ -z "${arg_admin_fqdn:-}" ]]; then
|
||||
# can be removed after 1.9
|
||||
admin_fqdn=$([[ "${arg_is_custom_domain}" == "true" ]] && echo "${arg_admin_location}.${arg_fqdn}" || echo "${arg_admin_location}-${arg_fqdn}")
|
||||
else
|
||||
admin_fqdn="${arg_admin_fqdn}"
|
||||
fi
|
||||
|
||||
echo "==> Creating cloudron.conf"
|
||||
cat > "${CONFIG_DIR}/cloudron.conf" <<CONF_END
|
||||
{
|
||||
@@ -214,9 +221,9 @@ cat > "${CONFIG_DIR}/cloudron.conf" <<CONF_END
|
||||
"apiServerOrigin": "${arg_api_server_origin}",
|
||||
"webServerOrigin": "${arg_web_server_origin}",
|
||||
"fqdn": "${arg_fqdn}",
|
||||
"adminFqdn": "${admin_fqdn}",
|
||||
"adminLocation": "${arg_admin_location}",
|
||||
"zoneName": "${arg_zone_name}",
|
||||
"isCustomDomain": ${arg_is_custom_domain},
|
||||
"provider": "${arg_provider}",
|
||||
"isDemo": ${arg_is_demo}
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ function retire(reason, info, callback) {
|
||||
|
||||
var data = {
|
||||
apiServerOrigin: config.apiServerOrigin(),
|
||||
isCustomDomain: config.isCustomDomain(),
|
||||
adminFqdn: config.adminFqdn(),
|
||||
fqdn: config.fqdn()
|
||||
};
|
||||
shell.sudo('retire', [ RETIRE_CMD, reason, JSON.stringify(info), JSON.stringify(data) ], callback);
|
||||
|
||||
+4
-3
@@ -194,7 +194,8 @@ function autoprovision(callback) {
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function dnsSetup(domain, zoneName, provider, dnsConfig, callback) {
|
||||
function dnsSetup(adminFqdn, domain, zoneName, provider, dnsConfig, callback) {
|
||||
assert.strictEqual(typeof adminFqdn, 'string');
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof zoneName, 'string');
|
||||
assert.strictEqual(typeof provider, 'string');
|
||||
@@ -215,6 +216,8 @@ function dnsSetup(domain, zoneName, provider, dnsConfig, callback) {
|
||||
if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error));
|
||||
|
||||
config.setFqdn(domain); // set fqdn only after dns config is valid, otherwise cannot re-setup if we failed
|
||||
config.setAdminFqdn(adminFqdn);
|
||||
config.setAdminLocation('my');
|
||||
config.setZoneName(zoneName);
|
||||
|
||||
callback();
|
||||
@@ -452,7 +455,6 @@ function getConfig(callback) {
|
||||
version: config.version(),
|
||||
update: updateChecker.getUpdateInfo(),
|
||||
progress: progress.getAll(),
|
||||
isCustomDomain: config.isCustomDomain(),
|
||||
isDemo: config.isDemo(),
|
||||
region: result.box.region,
|
||||
size: result.box.size,
|
||||
@@ -722,7 +724,6 @@ function doUpdate(boxUpdateInfo, callback) {
|
||||
webServerOrigin: config.webServerOrigin(),
|
||||
fqdn: config.fqdn(),
|
||||
adminLocation: config.adminLocation(),
|
||||
isCustomDomain: config.isCustomDomain(),
|
||||
isDemo: config.isDemo(),
|
||||
zoneName: config.zoneName(),
|
||||
|
||||
|
||||
+16
-22
@@ -19,10 +19,11 @@ exports = module.exports = {
|
||||
fqdn: fqdn,
|
||||
zoneName: zoneName,
|
||||
setFqdn: setFqdn,
|
||||
setAdminFqdn: setAdminFqdn,
|
||||
setAdminLocation: setAdminLocation,
|
||||
token: token,
|
||||
version: version,
|
||||
setVersion: setVersion,
|
||||
isCustomDomain: isCustomDomain,
|
||||
database: database,
|
||||
|
||||
// these values are derived
|
||||
@@ -76,9 +77,9 @@ function saveSync() {
|
||||
apiServerOrigin: data.apiServerOrigin,
|
||||
webServerOrigin: data.webServerOrigin,
|
||||
fqdn: data.fqdn,
|
||||
adminFqdn: data.adminFqdn,
|
||||
zoneName: data.zoneName,
|
||||
adminLocation: data.adminLocation,
|
||||
isCustomDomain: data.isCustomDomain,
|
||||
provider: data.provider,
|
||||
isDemo: data.isDemo
|
||||
};
|
||||
@@ -97,12 +98,12 @@ function _reset(callback) {
|
||||
function initConfig() {
|
||||
// setup defaults
|
||||
data.fqdn = '';
|
||||
data.adminFqdn = '';
|
||||
data.zoneName = '';
|
||||
data.adminLocation = 'my';
|
||||
data.port = 3000;
|
||||
data.token = null;
|
||||
data.version = null;
|
||||
data.isCustomDomain = true;
|
||||
data.apiServerOrigin = null;
|
||||
data.webServerOrigin = null;
|
||||
data.provider = 'caas';
|
||||
@@ -184,32 +185,29 @@ function zoneName() {
|
||||
return tld.getDomain(fqdn()) || '';
|
||||
}
|
||||
|
||||
// keep this in sync with start.sh admin.conf generation code
|
||||
function appFqdn(app) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof app.location, 'string');
|
||||
assert.strictEqual(typeof app.domain, 'string');
|
||||
|
||||
if (app.location === '') return app.domain;
|
||||
|
||||
// caas still has subdomains with a dash
|
||||
return app.location + (isCustomDomain() ? '.' : '-') + app.domain;
|
||||
}
|
||||
|
||||
function mailLocation() {
|
||||
return get('adminLocation'); // not a typo! should be same as admin location until we figure out certificates
|
||||
}
|
||||
|
||||
function mailFqdn() {
|
||||
return appFqdn({ domain: fqdn(), location: mailLocation() });
|
||||
function setAdminLocation(location) {
|
||||
set('adminLocation', location);
|
||||
}
|
||||
|
||||
|
||||
function adminLocation() {
|
||||
return get('adminLocation');
|
||||
}
|
||||
|
||||
function setAdminFqdn(adminFqdn) {
|
||||
set('adminFqdn', adminFqdn);
|
||||
}
|
||||
|
||||
function adminFqdn() {
|
||||
return appFqdn({ domain: fqdn(), location: adminLocation() });
|
||||
return get('adminFqdn');
|
||||
}
|
||||
|
||||
function mailFqdn() {
|
||||
return adminFqdn();
|
||||
}
|
||||
|
||||
function adminOrigin() {
|
||||
@@ -236,10 +234,6 @@ function setVersion(version) {
|
||||
set('version', version);
|
||||
}
|
||||
|
||||
function isCustomDomain() {
|
||||
return get('isCustomDomain');
|
||||
}
|
||||
|
||||
function database() {
|
||||
return get('database');
|
||||
}
|
||||
|
||||
+2
-1
@@ -318,8 +318,9 @@ function setAdmin(domain, callback) {
|
||||
if (error) return callback(new DomainError(DomainError.EXTERNAL_ERROR, 'Error setting PTR record:' + error.message));
|
||||
|
||||
config.setFqdn(result.domain);
|
||||
config.setAdminLocation('my');
|
||||
config.setAdminFqdn('my.' + result.domain);
|
||||
config.setZoneName(result.zoneName);
|
||||
config.set('isCustomDomain', true);
|
||||
|
||||
callback();
|
||||
|
||||
|
||||
@@ -108,11 +108,12 @@ function dnsSetup(req, res, next) {
|
||||
|
||||
if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
||||
if (typeof req.body.domain !== 'string' || !req.body.domain) return next(new HttpError(400, 'domain is required'));
|
||||
if (typeof req.body.adminFqdn !== 'string' || !req.body.domain) return next(new HttpError(400, 'adminFqdn is required'));
|
||||
|
||||
if ('zoneName' in req.body && typeof req.body.zoneName !== 'string') return next(new HttpError(400, 'zoneName must be a string'));
|
||||
if (!config || typeof req.body.config !== 'object') return next(new HttpError(400, 'config must be an object'));
|
||||
|
||||
cloudron.dnsSetup(req.body.domain.toLowerCase(), req.body.zoneName || '', req.body.provider, req.body.config, function (error) {
|
||||
cloudron.dnsSetup(req.body.adminFqdn.toLowerCase(), req.body.domain.toLowerCase(), req.body.zoneName || '', req.body.provider, req.body.config, function (error) {
|
||||
if (error && error.reason === CloudronError.ALREADY_SETUP) return next(new HttpError(409, error.message));
|
||||
if (error && error.reason === CloudronError.BAD_FIELD) return next(new HttpError(400, error.message));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
@@ -185,7 +186,7 @@ function getConfig(req, res, next) {
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
if (!req.user.admin) {
|
||||
cloudronConfig = _.pick(cloudronConfig, 'apiServerOrigin', 'webServerOrigin', 'fqdn', 'version', 'progress', 'isCustomDomain', 'isDemo', 'cloudronName', 'provider');
|
||||
cloudronConfig = _.pick(cloudronConfig, 'apiServerOrigin', 'webServerOrigin', 'fqdn', 'adminFqdn', 'version', 'progress', 'isDemo', 'cloudronName', 'provider');
|
||||
}
|
||||
|
||||
next(new HttpSuccess(200, cloudronConfig));
|
||||
|
||||
@@ -29,6 +29,7 @@ function setup(done) {
|
||||
nock.cleanAll();
|
||||
config._reset();
|
||||
config.setFqdn('example-cloudron-test.com');
|
||||
config.setAdminFqdn('my.example-cloudron-test.com');
|
||||
|
||||
async.series([
|
||||
server.start.bind(server),
|
||||
@@ -240,7 +241,7 @@ describe('Cloudron', function () {
|
||||
expect(result.body.apiServerOrigin).to.eql('http://localhost:6060');
|
||||
expect(result.body.webServerOrigin).to.eql(null);
|
||||
expect(result.body.fqdn).to.eql(config.fqdn());
|
||||
expect(result.body.isCustomDomain).to.eql(true);
|
||||
expect(result.body.adminFqdn).to.eql(config.adminFqdn());
|
||||
expect(result.body.progress).to.be.an('object');
|
||||
expect(result.body.update).to.be.an('object');
|
||||
expect(result.body.version).to.eql(config.version());
|
||||
@@ -265,7 +266,7 @@ describe('Cloudron', function () {
|
||||
expect(result.body.apiServerOrigin).to.eql('http://localhost:6060');
|
||||
expect(result.body.webServerOrigin).to.eql(null);
|
||||
expect(result.body.fqdn).to.eql(config.fqdn());
|
||||
expect(result.body.isCustomDomain).to.eql(true);
|
||||
expect(result.body.adminFqdn).to.eql(config.adminFqdn());
|
||||
expect(result.body.progress).to.be.an('object');
|
||||
expect(result.body.update).to.be.an('object');
|
||||
expect(result.body.version).to.eql(config.version());
|
||||
@@ -290,7 +291,7 @@ describe('Cloudron', function () {
|
||||
expect(result.body.apiServerOrigin).to.eql('http://localhost:6060');
|
||||
expect(result.body.webServerOrigin).to.eql(null);
|
||||
expect(result.body.fqdn).to.eql(config.fqdn());
|
||||
expect(result.body.isCustomDomain).to.eql(true);
|
||||
expect(result.body.adminFqdn).to.eql(config.adminFqdn());
|
||||
expect(result.body.progress).to.be.an('object');
|
||||
expect(result.body.version).to.eql(config.version());
|
||||
expect(result.body.cloudronName).to.be.a('string');
|
||||
|
||||
@@ -296,6 +296,7 @@ describe('OAuth2', function () {
|
||||
function setup(done) {
|
||||
config._reset();
|
||||
config.setFqdn(APP_0.domain);
|
||||
config.setAdminFqdn('my.' + APP_0.domain);
|
||||
|
||||
async.series([
|
||||
server.start,
|
||||
|
||||
@@ -29,6 +29,7 @@ var token = null;
|
||||
function setup(done) {
|
||||
config._reset();
|
||||
config.setFqdn('example-settings-test.com');
|
||||
config.setAdminFqdn('my.example-settings-test.com');
|
||||
config.set('provider', 'caas');
|
||||
|
||||
async.series([
|
||||
|
||||
@@ -132,6 +132,7 @@ describe('Apps', function () {
|
||||
config._reset();
|
||||
|
||||
config.setFqdn(DOMAIN_0.domain);
|
||||
config.setAdminFqdn('my.' + DOMAIN_0.domain);
|
||||
|
||||
async.series([
|
||||
database.initialize,
|
||||
@@ -161,7 +162,7 @@ describe('Apps', function () {
|
||||
|
||||
describe('validateHostname', function () {
|
||||
it('does not allow admin subdomain', function () {
|
||||
expect(apps._validateHostname('my', 'example.com', 'my.example.com')).to.be.an(Error);
|
||||
expect(apps._validateHostname('my', DOMAIN_0.domain, 'my.' + DOMAIN_0.domain)).to.be.an(Error);
|
||||
});
|
||||
|
||||
it('cannot have >63 length subdomains', function () {
|
||||
|
||||
@@ -31,8 +31,8 @@ describe('config', function () {
|
||||
});
|
||||
|
||||
it('did set default values', function () {
|
||||
expect(config.isCustomDomain()).to.equal(true);
|
||||
expect(config.fqdn()).to.equal('');
|
||||
expect(config.adminFqdn()).to.equal('');
|
||||
expect(config.zoneName()).to.equal('');
|
||||
expect(config.adminLocation()).to.equal('my');
|
||||
});
|
||||
@@ -63,20 +63,20 @@ describe('config', function () {
|
||||
|
||||
it('uses dotted locations with custom domain', function () {
|
||||
config.setFqdn('example.com');
|
||||
config.set('isCustomDomain', true);
|
||||
config.setAdminFqdn('my.example.com');
|
||||
|
||||
expect(config.isCustomDomain()).to.equal(true);
|
||||
expect(config.fqdn()).to.equal('example.com');
|
||||
expect(config.adminFqdn()).to.equal('my.example.com');
|
||||
expect(config.adminOrigin()).to.equal('https://my.example.com');
|
||||
expect(config.zoneName()).to.equal('example.com');
|
||||
});
|
||||
|
||||
it('uses hyphen locations with non-custom domain', function () {
|
||||
config.setFqdn('test.example.com');
|
||||
config.set('isCustomDomain', false);
|
||||
config.setAdminFqdn('my-test.example.com');
|
||||
|
||||
expect(config.isCustomDomain()).to.equal(false);
|
||||
expect(config.fqdn()).to.equal('test.example.com');
|
||||
expect(config.adminLocation()).to.equal('my');
|
||||
expect(config.adminOrigin()).to.equal('https://my-test.example.com');
|
||||
expect(config.zoneName()).to.equal('example.com');
|
||||
});
|
||||
|
||||
@@ -737,6 +737,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
|
||||
Client.prototype.setupDnsConfig = function (domain, zoneName, provider, dnsConfig, callback) {
|
||||
var data = {
|
||||
domain: domain,
|
||||
adminFqdn: 'my.' + domain,
|
||||
zoneName: zoneName,
|
||||
provider: provider,
|
||||
config: dnsConfig
|
||||
|
||||
Reference in New Issue
Block a user