You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin.php 12KB

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