1
0

admin.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 Windows is used
  142. $template->assign('WindowsWarning', OC_Util::runningOnWindows());
  143. // warn if outdated version of a memcache module is used
  144. $caches = [
  145. 'apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'],
  146. 'redis' => ['name' => $l->t('Redis'), 'version' => '2.2.5'],
  147. ];
  148. $outdatedCaches = [];
  149. foreach ($caches as $php_module => $data) {
  150. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  151. if ($isOutdated) {
  152. $outdatedCaches[$php_module] = $data;
  153. }
  154. }
  155. $template->assign('OutdatedCacheWarning', $outdatedCaches);
  156. // add hardcoded forms from the template
  157. $forms = OC_App::getForms('admin');
  158. if ($config->getSystemValue('enable_certificate_management', false)) {
  159. $certificatesTemplate = new OC_Template('settings', 'certificates');
  160. $certificatesTemplate->assign('type', 'admin');
  161. $certificatesTemplate->assign('uploadRoute', 'settings.Certificate.addSystemRootCertificate');
  162. $certificatesTemplate->assign('certs', $certificateManager->listCertificates());
  163. $certificatesTemplate->assign('urlGenerator', $urlGenerator);
  164. $forms[] = $certificatesTemplate->fetchPage();
  165. }
  166. $formsAndMore = array();
  167. if ($request->getServerProtocol() !== 'https' || !OC_Util::isAnnotationsWorking() ||
  168. $suggestedOverwriteCliUrl || !OC_Util::isSetLocaleWorking() ||
  169. !OC_Util::fileInfoLoaded() || $databaseOverload
  170. ) {
  171. $formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & setup warnings'));
  172. }
  173. $formsAndMore[] = array('anchor' => 'shareAPI', 'section-name' => $l->t('Sharing'));
  174. $formsAndMore[] = ['anchor' => 'encryptionAPI', 'section-name' => $l->t('Server-side encryption')];
  175. // Prioritize fileSharingSettings and files_external and move updater to the version
  176. $fileSharingSettings = $filesExternal = $updaterAppPanel = $ocDefaultEncryptionModulePanel = '';
  177. foreach ($forms as $index => $form) {
  178. if (strpos($form, 'id="fileSharingSettings"')) {
  179. $fileSharingSettings = $form;
  180. unset($forms[$index]);
  181. continue;
  182. }
  183. if (strpos($form, 'id="files_external"')) {
  184. $filesExternal = $form;
  185. unset($forms[$index]);
  186. continue;
  187. }
  188. if (strpos($form, 'class="updater-admin"')) {
  189. $updaterAppPanel = $form;
  190. unset($forms[$index]);
  191. continue;
  192. }
  193. if (strpos($form, 'id="ocDefaultEncryptionModule"')) {
  194. $ocDefaultEncryptionModulePanel = $form;
  195. unset($forms[$index]);
  196. continue;
  197. }
  198. }
  199. if ($filesExternal) {
  200. $formsAndMore[] = array('anchor' => 'files_external', 'section-name' => $l->t('External Storage'));
  201. }
  202. $template->assign('fileSharingSettings', $fileSharingSettings);
  203. $template->assign('filesExternal', $filesExternal);
  204. $template->assign('updaterAppPanel', $updaterAppPanel);
  205. $template->assign('ocDefaultEncryptionModulePanel', $ocDefaultEncryptionModulePanel);
  206. $lockingProvider = \OC::$server->getLockingProvider();
  207. if ($lockingProvider instanceof NoopLockingProvider) {
  208. $template->assign('fileLockingType', 'none');
  209. } else if ($lockingProvider instanceof \OC\Lock\DBLockingProvider) {
  210. $template->assign('fileLockingType', 'db');
  211. } else {
  212. $template->assign('fileLockingType', 'cache');
  213. }
  214. $formsMap = array_map(function ($form) {
  215. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  216. $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
  217. $sectionName = str_replace('</h2>', '', $sectionName);
  218. $anchor = strtolower($sectionName);
  219. $anchor = str_replace(' ', '-', $anchor);
  220. return array(
  221. 'anchor' => $anchor,
  222. 'section-name' => $sectionName,
  223. 'form' => $form
  224. );
  225. }
  226. return array(
  227. 'form' => $form
  228. );
  229. }, $forms);
  230. $formsAndMore = array_merge($formsAndMore, $formsMap);
  231. // add bottom hardcoded forms from the template
  232. $formsAndMore[] = ['anchor' => 'backgroundjobs', 'section-name' => $l->t('Cron')];
  233. $formsAndMore[] = ['anchor' => 'mail_general_settings', 'section-name' => $l->t('Email server')];
  234. $formsAndMore[] = ['anchor' => 'log-section', 'section-name' => $l->t('Log')];
  235. $formsAndMore[] = ['anchor' => 'admin-tips', 'section-name' => $l->t('Tips & tricks')];
  236. if ($updaterAppPanel) {
  237. $formsAndMore[] = ['anchor' => 'updater', 'section-name' => $l->t('Updates')];
  238. }
  239. $template->assign('forms', $formsAndMore);
  240. $template->printPage();
  241. $util = new \OC_Util();
  242. $util->createHtaccessTestFile(\OC::$server->getConfig());