Skip to content
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
3 changes: 2 additions & 1 deletion apps/files_trashbin/tests/ExpirationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private function getMockedConfig($returnValue){
'deleteUserValue',
'deleteAllUserValues',
'deleteAppFromAllUsers',
'getUsersForUserValue'
'getUsersForUserValue',
'isSystemConfigReadOnly'
]
)
->getMock()
Expand Down
3 changes: 2 additions & 1 deletion apps/files_versions/tests/ExpirationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private function getMockedConfig($returnValue){
'deleteUserValue',
'deleteAllUserValues',
'deleteAppFromAllUsers',
'getUsersForUserValue'
'getUsersForUserValue',
'isSystemConfigReadOnly'
]
)
->getMock()
Expand Down
2 changes: 1 addition & 1 deletion lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static function checkConfig() {

// Check if config is writable
$configFileWritable = is_writable($configFilePath);
if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled()
if (!$configFileWritable && !\OC::$server->getConfig()->isSystemConfigReadOnly()
|| !$configFileWritable && self::checkUpgrade(false)) {

$urlGenerator = \OC::$server->getURLGenerator();
Expand Down
12 changes: 11 additions & 1 deletion lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use Doctrine\DBAL\Platforms\OraclePlatform;
use OC\Cache\CappedMemoryCache;
use OCP\IDBConnection;
use OCP\PreConditionNotMetException;

/**
* Class to combine all the configuration options ownCloud offers
Expand Down Expand Up @@ -445,4 +444,15 @@ public function getUsersForUserValue($appName, $key, $value) {

return $userIDs;
}

/**
* In some environments the system config file is readonly. Find out if this
* is the case.
*
* @return boolean
* @since 10.0.3
*/
public function isSystemConfigReadOnly() {
return $this->systemConfig->isReadOnly();
}
}
16 changes: 16 additions & 0 deletions lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public function getValue($key, $default = null) {
* If value is null, the config key will be deleted
*/
public function setValues(array $configs) {
if ($this->isReadOnly()) {
throw new \Exception('Config file is read only.');
}
$needsUpdate = false;
foreach ($configs as $key => $value) {
if ($value !== null) {
Expand All @@ -127,6 +130,9 @@ public function setValues(array $configs) {
* @param mixed $value value
*/
public function setValue($key, $value) {
if ($this->isReadOnly()) {
throw new \Exception('Config file is read only.');
}
if ($this->set($key, $value)) {
// Write changes
$this->writeData();
Expand Down Expand Up @@ -155,6 +161,9 @@ protected function set($key, $value) {
* @param string $key
*/
public function deleteKey($key) {
if ($this->isReadOnly()) {
throw new \Exception('Config file is read only.');
}
if ($this->delete($key)) {
// Write changes
$this->writeData();
Expand Down Expand Up @@ -272,5 +281,12 @@ private function writeData() {
\OC_Util::clearOpcodeCache();
}
}

public function isReadOnly() {
if (!$this->getValue('installed', false)) {
return false;
}
return $this->getValue('config_is_read_only', false);
}
}

4 changes: 4 additions & 0 deletions lib/private/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ protected function removeSensitiveValue($keysToRemove, $value) {

return $value;
}

public function isReadOnly() {
return $this->config->isReadOnly();
}
}
8 changes: 0 additions & 8 deletions lib/private/legacy/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,4 @@ private static function getGlobalStorageInfo() {
return ['free' => $free, 'used' => $used, 'total' => $total, 'relative' => $relative];

}

/**
* Returns whether the config file is set manually to read-only
* @return bool
*/
public static function isReadOnlyConfigEnabled() {
return \OC::$server->getConfig()->getSystemValue('config_is_read_only', false);
}
}
17 changes: 1 addition & 16 deletions lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public static function checkServer(\OCP\IConfig $config) {
}

// Check if config folder is writable.
if(!OC_Helper::isReadOnlyConfigEnabled()) {
if(!\OC::$server->getConfig()->isSystemConfigReadOnly()) {
if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
$errors[] = [
'error' => $l->t('Cannot write into "config" directory'),
Expand All @@ -726,21 +726,6 @@ public static function checkServer(\OCP\IConfig $config) {
}
}

// Check if there is a writable install folder.
if ($config->getSystemValue('appstoreenabled', true)) {
if (OC_App::getInstallPath() === null
|| !is_writable(OC_App::getInstallPath())
|| !is_readable(OC_App::getInstallPath())
) {
$errors[] = [
'error' => $l->t('Cannot write into "apps" directory'),
'hint' => $l->t('This can usually be fixed by '
. '%sgiving the webserver write access to the apps directory%s'
. ' or disabling the appstore in the config file.',
['<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>'])
];
}
}
// Create root dir.
if ($config->getSystemValue('installed', false)) {
if (!is_dir($CONFIG_DATADIRECTORY)) {
Expand Down
9 changes: 9 additions & 0 deletions lib/public/IConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,13 @@ public function deleteAppFromAllUsers($appName);
* @since 8.0.0
*/
public function getUsersForUserValue($appName, $key, $value);

/**
* In some environments the system config file is readonly. Find out if this
* is the case.
*
* @return boolean
* @since 10.0.3
*/
public function isSystemConfigReadOnly();
}
1 change: 1 addition & 0 deletions settings/Panels/Admin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getPriority() {
public function getPanel() {
$template = new Template('settings', 'panels/admin/mail');
// Should we display sendmail as an option?
$template->assign('read-only', $this->config->isSystemConfigReadOnly());
$template->assign('sendmail_is_available', $this->helper->findBinaryPath('sendmail'));
$template->assign('loglevel', $this->config->getSystemValue("loglevel", 2));
$template->assign('mail_domain', $this->config->getSystemValue("mail_domain", ''));
Expand Down
2 changes: 1 addition & 1 deletion settings/Panels/Admin/SecurityWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getPanel() {
// warn if php is not setup properly to get system variables with getenv
$path = getenv('PATH');
$template->assign('getenvServerNotWorking', empty($path));
$template->assign('readOnlyConfigEnabled', $this->helper->isReadOnlyConfigEnabled());
$template->assign('readOnlyConfigEnabled', $this->config->isSystemConfigReadOnly());
$template->assign('isAnnotationsWorking', $this->helper->isAnnotationsWorking());
try {
if ($this->dbconnection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
Expand Down
4 changes: 0 additions & 4 deletions settings/Panels/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public function findBinaryPath($path) {
return (bool) \OC_Helper::findBinaryPath($path);
}

public function isReadOnlyConfigEnabled() {
return \OC_Helper::isReadOnlyConfigEnabled();
}

public function isAnnotationsWorking() {
return \OC_Util::isAnnotationsWorking();
}
Expand Down
155 changes: 81 additions & 74 deletions settings/templates/panels/admin/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,87 +22,94 @@
$mail_smtpmode[] = 'qmail';
}
?><div class="section">
<form id="mail_general_settings_form" class="mail_settings">
<h2 class="app-name has-documentation"><?php p($l->t('Email server'));?></h2>
<a target="_blank" rel="noreferrer" class="icon-info"
title="<?php p($l->t('Open documentation'));?>"
href="<?php p(link_to_docs('admin-email')); ?>"></a>

<p><?php p($l->t('This is used for sending out notifications.')); ?> <span id="mail_settings_msg" class="msg"></span></p>

<h2 class="app-name has-documentation"><?php p($l->t('Email server'));?></h2>
<a target="_blank" rel="noreferrer" class="icon-info"
title="<?php p($l->t('Open documentation'));?>"
href="<?php p(link_to_docs('admin-email')); ?>"></a>
<?php if ($_['read-only']) : ?>
<p>
<label for="mail_smtpmode"><?php p($l->t( 'Send mode' )); ?></label>
<select name='mail_smtpmode' id='mail_smtpmode'>
<?php foreach ($mail_smtpmode as $smtpmode):
$selected = '';
if ($smtpmode == $_['mail_smtpmode']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($smtpmode)?>' <?php p($selected) ?>><?php p($smtpmode) ?></option>
<?php endforeach;?>
</select>

<label id="mail_smtpsecure_label" for="mail_smtpsecure"
<?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<?php p($l->t( 'Encryption' )); ?>
</label>
<select name="mail_smtpsecure" id="mail_smtpsecure"
<?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<?php foreach ($mail_smtpsecure as $secure => $name):
$selected = '';
if ($secure == $_['mail_smtpsecure']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($secure)?>' <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>
<?php p($l->t('The config file is read only. Please adjust your setup by editing the config file manually.')); ?>
<br>
<?php p($l->t('In a clustered setup please make sure to sync the config.php file across all nodes.')); ?>
</p>
<?php else :?>
<form id="mail_general_settings_form" class="mail_settings">

<p>
<label for="mail_from_address"><?php p($l->t( 'From address' )); ?></label>
<input type="text" name='mail_from_address' id="mail_from_address" placeholder="<?php p($l->t('mail'))?>"
value='<?php p($_['mail_from_address']) ?>' />@
<input type="text" name='mail_domain' id="mail_domain" placeholder="example.com"
value='<?php p($_['mail_domain']) ?>' />
</p>
<p><?php p($l->t('This is used for sending out notifications.')); ?> <span id="mail_settings_msg" class="msg"></span></p>

<p id="setting_smtpauth" <?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtpauthtype"><?php p($l->t( 'Authentication method' )); ?></label>
<select name='mail_smtpauthtype' id='mail_smtpauthtype'>
<?php foreach ($mail_smtpauthtype as $authtype => $name):
$selected = '';
if ($authtype == $_['mail_smtpauthtype']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($authtype)?>' <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>
<p>
<label for="mail_smtpmode"><?php p($l->t( 'Send mode' )); ?></label>
<select name='mail_smtpmode' id='mail_smtpmode'>
<?php foreach ($mail_smtpmode as $smtpmode):
$selected = '';
if ($smtpmode == $_['mail_smtpmode']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($smtpmode)?>' <?php p($selected) ?>><?php p($smtpmode) ?></option>
<?php endforeach;?>
</select>

<input type="checkbox" name="mail_smtpauth" id="mail_smtpauth" class="checkbox" value="1"
<?php if ($_['mail_smtpauth']) print_unescaped('checked="checked"'); ?> />
<label for="mail_smtpauth"><?php p($l->t( 'Authentication required' )); ?></label>
</p>
<label id="mail_smtpsecure_label" for="mail_smtpsecure"
<?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<?php p($l->t( 'Encryption' )); ?>
</label>
<select name="mail_smtpsecure" id="mail_smtpsecure"
<?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<?php foreach ($mail_smtpsecure as $secure => $name):
$selected = '';
if ($secure == $_['mail_smtpsecure']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($secure)?>' <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>
</p>

<p id="setting_smtphost" <?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtphost"><?php p($l->t( 'Server address' )); ?></label>
<input type="text" name='mail_smtphost' id="mail_smtphost" placeholder="smtp.example.com"
value='<?php p($_['mail_smtphost']) ?>' />
:
<input type="text" name='mail_smtpport' id="mail_smtpport" placeholder="<?php p($l->t('Port'))?>"
value='<?php p($_['mail_smtpport']) ?>' />
</p>
</form>
<form class="mail_settings" id="mail_credentials_settings">
<p id="mail_credentials" <?php if (!$_['mail_smtpauth'] || $_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtpname"><?php p($l->t( 'Credentials' )); ?></label>
<input type="text" name='mail_smtpname' id="mail_smtpname" placeholder="<?php p($l->t('SMTP Username'))?>"
value='<?php p($_['mail_smtpname']) ?>' />
<input type="password" name='mail_smtppassword' id="mail_smtppassword" autocomplete="off"
placeholder="<?php p($l->t('SMTP Password'))?>" value='<?php p($_['mail_smtppassword']) ?>' />
<input id="mail_credentials_settings_submit" type="button" value="<?php p($l->t('Store credentials')) ?>">
</p>
</form>
<p>
<label for="mail_from_address"><?php p($l->t( 'From address' )); ?></label>
<input type="text" name='mail_from_address' id="mail_from_address" placeholder="<?php p($l->t('mail'))?>"
value='<?php p($_['mail_from_address']) ?>' />@
<input type="text" name='mail_domain' id="mail_domain" placeholder="example.com"
value='<?php p($_['mail_domain']) ?>' />
</p>

<p id="setting_smtpauth" <?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtpauthtype"><?php p($l->t( 'Authentication method' )); ?></label>
<select name='mail_smtpauthtype' id='mail_smtpauthtype'>
<?php foreach ($mail_smtpauthtype as $authtype => $name):
$selected = '';
if ($authtype == $_['mail_smtpauthtype']):
$selected = 'selected="selected"';
endif; ?>
<option value='<?php p($authtype)?>' <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>

<input type="checkbox" name="mail_smtpauth" id="mail_smtpauth" class="checkbox" value="1"
<?php if ($_['mail_smtpauth']) print_unescaped('checked="checked"'); ?> />
<label for="mail_smtpauth"><?php p($l->t( 'Authentication required' )); ?></label>
</p>

<p id="setting_smtphost" <?php if ($_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtphost"><?php p($l->t( 'Server address' )); ?></label>
<input type="text" name='mail_smtphost' id="mail_smtphost" placeholder="smtp.example.com"
value='<?php p($_['mail_smtphost']) ?>' />
:
<input type="text" name='mail_smtpport' id="mail_smtpport" placeholder="<?php p($l->t('Port'))?>"
value='<?php p($_['mail_smtpport']) ?>' />
</p>
</form>
<form class="mail_settings" id="mail_credentials_settings">
<p id="mail_credentials" <?php if (!$_['mail_smtpauth'] || $_['mail_smtpmode'] != 'smtp') print_unescaped(' class="hidden"'); ?>>
<label for="mail_smtpname"><?php p($l->t( 'Credentials' )); ?></label>
<input type="text" name='mail_smtpname' id="mail_smtpname" placeholder="<?php p($l->t('SMTP Username'))?>"
value='<?php p($_['mail_smtpname']) ?>' />
<input type="password" name='mail_smtppassword' id="mail_smtppassword" autocomplete="off"
placeholder="<?php p($l->t('SMTP Password'))?>" value='<?php p($_['mail_smtppassword']) ?>' />
<input id="mail_credentials_settings_submit" type="button" value="<?php p($l->t('Store credentials')) ?>">
</p>
</form>
<?php endif; ?>
<br />
<em><?php p($l->t( 'Test email settings' )); ?></em>
<input type="submit" name="sendtestemail" id="sendtestemail" value="<?php p($l->t( 'Send email' )); ?>"/>
Expand Down