1
0

admin.php 13 KB

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