Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Switch to shorten hostname in status.php #34469

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 8 additions & 2 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,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() {
Expand Down