diff --git a/config/config.sample.php b/config/config.sample.php index 66c77af40d35..17f95afe5489 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -99,6 +99,12 @@ */ 'show_server_hostname' => false, +/** + * Optionally, use the short hostname in the status.php. + * Defaults to use the gethostname() return value. + */ +'use_relative_domain_name' => false, + /** * Identifies the database used with this installation. See also config option * `supportedDatabases` diff --git a/lib/public/Util.php b/lib/public/Util.php index e233ea195454..2235110c31df 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -733,7 +733,7 @@ public static function needUpgrade() { * @return array * @since 10.0 */ - public static function getStatusInfo($includeVersion = false, $serverHide = false) { + public static function getStatusInfo($includeVersion = false, $serverHide = false, $hostnameShort = false) { $systemConfig = \OC::$server->getSystemConfig(); $installed = (bool) $systemConfig->getValue('installed', false); @@ -759,7 +759,13 @@ public static function getStatusInfo($includeVersion = false, $serverHide = fals $values['productname'] = $defaults->getName(); // expose the servername only if allowed via version, but never when called via status.php if ($serverHide === false) { - $values['hostname'] = \gethostname(); + $hostname = \gethostname(); + if (($hostnameShort) && + (\is_string($hostname))) { + $splitted = \explode('.', $hostname); + $hostname = $splitted[0]; + } + $values['hostname'] = $hostname; } } diff --git a/status.php b/status.php index 6165752d43b4..e836fd0660f1 100644 --- a/status.php +++ b/status.php @@ -37,7 +37,9 @@ # but do not expose the servername in the public via url $values = \OCP\Util::getStatusInfo( null, - \OC::$server->getConfig()->getSystemValue('show_server_hostname', false) !== true); + \OC::$server->getConfig()->getSystemValue('show_server_hostname', false) !== true, + \OC::$server->getConfig()->getSystemValue('use_relative_domain_name', false) === true + ); if (OC::$CLI) { \print_r($values); diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index f083f0124a46..a8bb8fec28e3 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -523,6 +523,12 @@ public function testGetStatusInfo() { $statusInfo = \OCP\Util::getStatusInfo(); $this->assertArrayHasKey('productname', $statusInfo); $this->assertEquals($statusInfo['productname'], 'ownCloud'); + $statusInfoShortHostname = \OCP\Util::getStatusInfo(false, false, true); + if (\strpos($statusInfo['hostname'], '.') === false) { + $this->assertEquals($statusInfo['hostname'], $statusInfoShortHostname['hostname']); + } else { + $this->assertNotEquals($statusInfo['hostname'], $statusInfoShortHostname['hostname']); + } } public function fullDomainDataProvider() {