admin.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Björn Schießle <schiessle@owncloud.com>
  6. * @author Frank Karlitschek <frank@owncloud.org>
  7. * @author Georg Ehrke <georg@owncloud.com>
  8. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  9. * @author Joas Schilling <nickvergessen@owncloud.com>
  10. * @author Lukas Reschke <lukas@owncloud.com>
  11. * @author Martin Mattel <martin.mattel@diemattels.at>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <icewind@owncloud.com>
  14. * @author Thomas Müller <thomas.mueller@tmit.eu>
  15. * @author Vincent Petry <pvince81@owncloud.com>
  16. *
  17. * @copyright Copyright (c) 2015, ownCloud, Inc.
  18. * @license AGPL-3.0
  19. *
  20. * This code is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU Affero General Public License, version 3,
  22. * as published by the Free Software Foundation.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU Affero General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Affero General Public License, version 3,
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>
  31. *
  32. */
  33. use OC\Lock\NoopLockingProvider;
  34. OC_Util::checkAdminUser();
  35. OC_App::setActiveNavigationEntry("admin");
  36. $template = new OC_Template('settings', 'admin', 'user');
  37. $l = OC_L10N::get('settings');
  38. $showLog = (\OC::$server->getConfig()->getSystemValue('log_type', 'owncloud') === 'owncloud');
  39. $numEntriesToLoad = 3;
  40. $entries = OC_Log_Owncloud::getEntries($numEntriesToLoad + 1);
  41. $entriesRemaining = count($entries) > $numEntriesToLoad;
  42. $entries = array_slice($entries, 0, $numEntriesToLoad);
  43. $logFilePath = OC_Log_Owncloud::getLogFilePath();
  44. $doesLogFileExist = file_exists($logFilePath);
  45. $logFileSize = filesize($logFilePath);
  46. $config = \OC::$server->getConfig();
  47. $appConfig = \OC::$server->getAppConfig();
  48. $request = \OC::$server->getRequest();
  49. // Should we display sendmail as an option?
  50. $template->assign('sendmail_is_available', (bool) \OC_Helper::findBinaryPath('sendmail'));
  51. $template->assign('loglevel', $config->getSystemValue("loglevel", 2));
  52. $template->assign('mail_domain', $config->getSystemValue("mail_domain", ''));
  53. $template->assign('mail_from_address', $config->getSystemValue("mail_from_address", ''));
  54. $template->assign('mail_smtpmode', $config->getSystemValue("mail_smtpmode", ''));
  55. $template->assign('mail_smtpsecure', $config->getSystemValue("mail_smtpsecure", ''));
  56. $template->assign('mail_smtphost', $config->getSystemValue("mail_smtphost", ''));
  57. $template->assign('mail_smtpport', $config->getSystemValue("mail_smtpport", ''));
  58. $template->assign('mail_smtpauthtype', $config->getSystemValue("mail_smtpauthtype", ''));
  59. $template->assign('mail_smtpauth', $config->getSystemValue("mail_smtpauth", false));
  60. $template->assign('mail_smtpname', $config->getSystemValue("mail_smtpname", ''));
  61. $template->assign('mail_smtppassword', $config->getSystemValue("mail_smtppassword", ''));
  62. $template->assign('entries', $entries);
  63. $template->assign('entriesremain', $entriesRemaining);
  64. $template->assign('logFileSize', $logFileSize);
  65. $template->assign('doesLogFileExist', $doesLogFileExist);
  66. $template->assign('showLog', $showLog);
  67. $template->assign('readOnlyConfigEnabled', OC_Helper::isReadOnlyConfigEnabled());
  68. $template->assign('isLocaleWorking', OC_Util::isSetLocaleWorking());
  69. $template->assign('isAnnotationsWorking', OC_Util::isAnnotationsWorking());
  70. $template->assign('has_fileinfo', OC_Util::fileInfoLoaded());
  71. $template->assign('backgroundjobs_mode', $appConfig->getValue('core', 'backgroundjobs_mode', 'ajax'));
  72. $template->assign('cron_log', $config->getSystemValue('cron_log', true));
  73. $template->assign('lastcron', $appConfig->getValue('core', 'lastcron', false));
  74. $template->assign('shareAPIEnabled', $appConfig->getValue('core', 'shareapi_enabled', 'yes'));
  75. $template->assign('shareDefaultExpireDateSet', $appConfig->getValue('core', 'shareapi_default_expire_date', 'no'));
  76. $template->assign('shareExpireAfterNDays', $appConfig->getValue('core', 'shareapi_expire_after_n_days', '7'));
  77. $template->assign('shareEnforceExpireDate', $appConfig->getValue('core', 'shareapi_enforce_expire_date', 'no'));
  78. $excludeGroups = $appConfig->getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false;
  79. $template->assign('shareExcludeGroups', $excludeGroups);
  80. $excludedGroupsList = $appConfig->getValue('core', 'shareapi_exclude_groups_list', '');
  81. $excludedGroupsList = explode(',', $excludedGroupsList); // FIXME: this should be JSON!
  82. $template->assign('shareExcludedGroupsList', implode('|', $excludedGroupsList));
  83. $template->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
  84. $backends = \OC::$server->getUserManager()->getBackends();
  85. $externalBackends = (count($backends) > 1) ? true : false;
  86. $template->assign('encryptionReady', \OC::$server->getEncryptionManager()->isReady());
  87. $template->assign('externalBackendsEnabled', $externalBackends);
  88. $encryptionModules = \OC::$server->getEncryptionManager()->getEncryptionModules();
  89. $defaultEncryptionModuleId = \OC::$server->getEncryptionManager()->getDefaultEncryptionModuleId();
  90. $encModulues = array();
  91. foreach ($encryptionModules as $module) {
  92. $encModulues[$module['id']]['displayName'] = $module['displayName'];
  93. $encModulues[$module['id']]['default'] = false;
  94. if ($module['id'] === $defaultEncryptionModuleId) {
  95. $encModulues[$module['id']]['default'] = true;
  96. }
  97. }
  98. $template->assign('encryptionModules', $encModulues);
  99. // If the current web root is non-empty but the web root from the config is,
  100. // and system cron is used, the URL generator fails to build valid URLs.
  101. $shouldSuggestOverwriteCliUrl = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' &&
  102. \OC::$WEBROOT && \OC::$WEBROOT !== '/' &&
  103. !$config->getSystemValue('overwrite.cli.url', '');
  104. $suggestedOverwriteCliUrl = ($shouldSuggestOverwriteCliUrl) ? \OC::$WEBROOT : '';
  105. $template->assign('suggestedOverwriteCliUrl', $suggestedOverwriteCliUrl);
  106. $template->assign('allowLinks', $appConfig->getValue('core', 'shareapi_allow_links', 'yes'));
  107. $template->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired());
  108. $template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes'));
  109. $template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes'));
  110. $template->assign('allowPublicMailNotification', $appConfig->getValue('core', 'shareapi_allow_public_notification', 'no'));
  111. $template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no'));
  112. $template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly());
  113. $databaseOverload = (strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false);
  114. $template->assign('databaseOverload', $databaseOverload);
  115. $template->assign('cronErrors', $appConfig->getValue('core', 'cronErrors'));
  116. // warn if php is not setup properly to get system variables with getenv
  117. $path = getenv('PATH');
  118. $template->assign('getenvServerNotWorking', empty($path));
  119. // warn if Windows is used
  120. $template->assign('WindowsWarning', OC_Util::runningOnWindows());
  121. // warn if outdated version of a memcache module is used
  122. $caches = [
  123. 'apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'],
  124. 'redis' => ['name' => $l->t('Redis'), 'version' => '2.2.5'],
  125. ];
  126. $outdatedCaches = [];
  127. foreach ($caches as $php_module => $data) {
  128. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  129. if ($isOutdated) {
  130. $outdatedCaches[$php_module] = $data;
  131. }
  132. }
  133. $template->assign('OutdatedCacheWarning', $outdatedCaches);
  134. // add hardcoded forms from the template
  135. $forms = OC_App::getForms('admin');
  136. $formsAndMore = array();
  137. if ($request->getServerProtocol() !== 'https' || !OC_Util::isAnnotationsWorking() ||
  138. $suggestedOverwriteCliUrl || !OC_Util::isSetLocaleWorking() ||
  139. !OC_Util::fileInfoLoaded() || $databaseOverload
  140. ) {
  141. $formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & setup warnings'));
  142. }
  143. $formsAndMore[] = array('anchor' => 'shareAPI', 'section-name' => $l->t('Sharing'));
  144. $formsAndMore[] = ['anchor' => 'encryptionAPI', 'section-name' => $l->t('Server-side encryption')];
  145. // Prioritize fileSharingSettings and files_external and move updater to the version
  146. $fileSharingSettings = $filesExternal = $updaterAppPanel = $ocDefaultEncryptionModulePanel = '';
  147. foreach ($forms as $index => $form) {
  148. if (strpos($form, 'id="fileSharingSettings"')) {
  149. $fileSharingSettings = $form;
  150. unset($forms[$index]);
  151. continue;
  152. }
  153. if (strpos($form, 'id="files_external"')) {
  154. $filesExternal = $form;
  155. unset($forms[$index]);
  156. continue;
  157. }
  158. if (strpos($form, 'class="updater-admin"')) {
  159. $updaterAppPanel = $form;
  160. unset($forms[$index]);
  161. continue;
  162. }
  163. if (strpos($form, 'id="ocDefaultEncryptionModule"')) {
  164. $ocDefaultEncryptionModulePanel = $form;
  165. unset($forms[$index]);
  166. continue;
  167. }
  168. }
  169. if ($filesExternal) {
  170. $formsAndMore[] = array('anchor' => 'files_external', 'section-name' => $l->t('External Storage'));
  171. }
  172. $template->assign('fileSharingSettings', $fileSharingSettings);
  173. $template->assign('filesExternal', $filesExternal);
  174. $template->assign('updaterAppPanel', $updaterAppPanel);
  175. $template->assign('ocDefaultEncryptionModulePanel', $ocDefaultEncryptionModulePanel);
  176. if (\OC::$server->getLockingProvider() instanceof NoopLockingProvider) {
  177. $template->assign('fileLockingEnabled', false);
  178. } else {
  179. $template->assign('fileLockingEnabled', true);
  180. }
  181. $formsMap = array_map(function ($form) {
  182. if (preg_match('%(<h2[^>]*>.*?</h2>)%i', $form, $regs)) {
  183. $sectionName = str_replace('<h2>', '', $regs[0]);
  184. $sectionName = str_replace('</h2>', '', $sectionName);
  185. $anchor = strtolower($sectionName);
  186. $anchor = str_replace(' ', '-', $anchor);
  187. return array(
  188. 'anchor' => 'goto-' . $anchor,
  189. 'section-name' => $sectionName,
  190. 'form' => $form
  191. );
  192. }
  193. return array(
  194. 'form' => $form
  195. );
  196. }, $forms);
  197. $formsAndMore = array_merge($formsAndMore, $formsMap);
  198. // add bottom hardcoded forms from the template
  199. $formsAndMore[] = ['anchor' => 'backgroundjobs', 'section-name' => $l->t('Cron')];
  200. $formsAndMore[] = ['anchor' => 'mail_general_settings', 'section-name' => $l->t('Email server')];
  201. $formsAndMore[] = ['anchor' => 'log-section', 'section-name' => $l->t('Log')];
  202. $formsAndMore[] = ['anchor' => 'server-status', 'section-name' => $l->t('Server Status')];
  203. $formsAndMore[] = ['anchor' => 'admin-tips', 'section-name' => $l->t('Tips & tricks')];
  204. if ($updaterAppPanel) {
  205. $formsAndMore[] = ['anchor' => 'updater', 'section-name' => $l->t('Updates')];
  206. }
  207. $template->assign('forms', $formsAndMore);
  208. $template->printPage();