admin.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. *
  16. * @copyright Copyright (c) 2015, 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. $showLog = (\OC::$server->getConfig()->getSystemValue('log_type', 'owncloud') === 'owncloud');
  38. $numEntriesToLoad = 3;
  39. $entries = OC_Log_Owncloud::getEntries($numEntriesToLoad + 1);
  40. $entriesRemaining = count($entries) > $numEntriesToLoad;
  41. $entries = array_slice($entries, 0, $numEntriesToLoad);
  42. $logFilePath = OC_Log_Owncloud::getLogFilePath();
  43. $doesLogFileExist = file_exists($logFilePath);
  44. $logFileSize = 0;
  45. if($doesLogFileExist) {
  46. $logFileSize = filesize($logFilePath);
  47. }
  48. $config = \OC::$server->getConfig();
  49. $appConfig = \OC::$server->getAppConfig();
  50. $request = \OC::$server->getRequest();
  51. // Should we display sendmail as an option?
  52. $template->assign('sendmail_is_available', (bool) \OC_Helper::findBinaryPath('sendmail'));
  53. $template->assign('loglevel', $config->getSystemValue("loglevel", 2));
  54. $template->assign('mail_domain', $config->getSystemValue("mail_domain", ''));
  55. $template->assign('mail_from_address', $config->getSystemValue("mail_from_address", ''));
  56. $template->assign('mail_smtpmode', $config->getSystemValue("mail_smtpmode", ''));
  57. $template->assign('mail_smtpsecure', $config->getSystemValue("mail_smtpsecure", ''));
  58. $template->assign('mail_smtphost', $config->getSystemValue("mail_smtphost", ''));
  59. $template->assign('mail_smtpport', $config->getSystemValue("mail_smtpport", ''));
  60. $template->assign('mail_smtpauthtype', $config->getSystemValue("mail_smtpauthtype", ''));
  61. $template->assign('mail_smtpauth', $config->getSystemValue("mail_smtpauth", false));
  62. $template->assign('mail_smtpname', $config->getSystemValue("mail_smtpname", ''));
  63. $template->assign('mail_smtppassword', $config->getSystemValue("mail_smtppassword", ''));
  64. $template->assign('entries', $entries);
  65. $template->assign('entriesremain', $entriesRemaining);
  66. $template->assign('logFileSize', $logFileSize);
  67. $template->assign('doesLogFileExist', $doesLogFileExist);
  68. $template->assign('showLog', $showLog);
  69. $template->assign('readOnlyConfigEnabled', OC_Helper::isReadOnlyConfigEnabled());
  70. $template->assign('isLocaleWorking', OC_Util::isSetLocaleWorking());
  71. $template->assign('isAnnotationsWorking', OC_Util::isAnnotationsWorking());
  72. $template->assign('has_fileinfo', OC_Util::fileInfoLoaded());
  73. $template->assign('backgroundjobs_mode', $appConfig->getValue('core', 'backgroundjobs_mode', 'ajax'));
  74. $template->assign('cron_log', $config->getSystemValue('cron_log', true));
  75. $template->assign('lastcron', $appConfig->getValue('core', 'lastcron', false));
  76. $template->assign('shareAPIEnabled', $appConfig->getValue('core', 'shareapi_enabled', 'yes'));
  77. $template->assign('shareDefaultExpireDateSet', $appConfig->getValue('core', 'shareapi_default_expire_date', 'no'));
  78. $template->assign('shareExpireAfterNDays', $appConfig->getValue('core', 'shareapi_expire_after_n_days', '7'));
  79. $template->assign('shareEnforceExpireDate', $appConfig->getValue('core', 'shareapi_enforce_expire_date', 'no'));
  80. $excludeGroups = $appConfig->getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false;
  81. $template->assign('shareExcludeGroups', $excludeGroups);
  82. $excludedGroupsList = $appConfig->getValue('core', 'shareapi_exclude_groups_list', '');
  83. $excludedGroupsList = json_decode($excludedGroupsList);
  84. $template->assign('shareExcludedGroupsList', !is_null($excludedGroupsList) ? implode('|', $excludedGroupsList) : '');
  85. $template->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
  86. $backends = \OC::$server->getUserManager()->getBackends();
  87. $externalBackends = (count($backends) > 1) ? true : false;
  88. $template->assign('encryptionReady', \OC::$server->getEncryptionManager()->isReady());
  89. $template->assign('externalBackendsEnabled', $externalBackends);
  90. $encryptionModules = \OC::$server->getEncryptionManager()->getEncryptionModules();
  91. $defaultEncryptionModuleId = \OC::$server->getEncryptionManager()->getDefaultEncryptionModuleId();
  92. $encModulues = array();
  93. foreach ($encryptionModules as $module) {
  94. $encModulues[$module['id']]['displayName'] = $module['displayName'];
  95. $encModulues[$module['id']]['default'] = false;
  96. if ($module['id'] === $defaultEncryptionModuleId) {
  97. $encModulues[$module['id']]['default'] = true;
  98. }
  99. }
  100. $template->assign('encryptionModules', $encModulues);
  101. // If the current web root is non-empty but the web root from the config is,
  102. // and system cron is used, the URL generator fails to build valid URLs.
  103. $shouldSuggestOverwriteCliUrl = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' &&
  104. \OC::$WEBROOT && \OC::$WEBROOT !== '/' &&
  105. !$config->getSystemValue('overwrite.cli.url', '');
  106. $suggestedOverwriteCliUrl = ($shouldSuggestOverwriteCliUrl) ? \OC::$WEBROOT : '';
  107. $template->assign('suggestedOverwriteCliUrl', $suggestedOverwriteCliUrl);
  108. $template->assign('allowLinks', $appConfig->getValue('core', 'shareapi_allow_links', 'yes'));
  109. $template->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired());
  110. $template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes'));
  111. $template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes'));
  112. $template->assign('allowPublicMailNotification', $appConfig->getValue('core', 'shareapi_allow_public_notification', 'no'));
  113. $template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no'));
  114. $template->assign('allowShareDialogUserEnumeration', $appConfig->getValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'));
  115. $template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly());
  116. $databaseOverload = (strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false);
  117. $template->assign('databaseOverload', $databaseOverload);
  118. $template->assign('cronErrors', $appConfig->getValue('core', 'cronErrors'));
  119. // warn if php is not setup properly to get system variables with getenv
  120. $path = getenv('PATH');
  121. $template->assign('getenvServerNotWorking', empty($path));
  122. // warn if Windows is used
  123. $template->assign('WindowsWarning', OC_Util::runningOnWindows());
  124. // warn if outdated version of a memcache module is used
  125. $caches = [
  126. 'apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'],
  127. 'redis' => ['name' => $l->t('Redis'), 'version' => '2.2.5'],
  128. ];
  129. $outdatedCaches = [];
  130. foreach ($caches as $php_module => $data) {
  131. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  132. if ($isOutdated) {
  133. $outdatedCaches[$php_module] = $data;
  134. }
  135. }
  136. $template->assign('OutdatedCacheWarning', $outdatedCaches);
  137. // add hardcoded forms from the template
  138. $forms = OC_App::getForms('admin');
  139. $formsAndMore = array();
  140. if ($request->getServerProtocol() !== 'https' || !OC_Util::isAnnotationsWorking() ||
  141. $suggestedOverwriteCliUrl || !OC_Util::isSetLocaleWorking() ||
  142. !OC_Util::fileInfoLoaded() || $databaseOverload
  143. ) {
  144. $formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & setup warnings'));
  145. }
  146. $formsAndMore[] = array('anchor' => 'shareAPI', 'section-name' => $l->t('Sharing'));
  147. $formsAndMore[] = ['anchor' => 'encryptionAPI', 'section-name' => $l->t('Server-side encryption')];
  148. // Prioritize fileSharingSettings and files_external and move updater to the version
  149. $fileSharingSettings = $filesExternal = $updaterAppPanel = $ocDefaultEncryptionModulePanel = '';
  150. foreach ($forms as $index => $form) {
  151. if (strpos($form, 'id="fileSharingSettings"')) {
  152. $fileSharingSettings = $form;
  153. unset($forms[$index]);
  154. continue;
  155. }
  156. if (strpos($form, 'id="files_external"')) {
  157. $filesExternal = $form;
  158. unset($forms[$index]);
  159. continue;
  160. }
  161. if (strpos($form, 'class="updater-admin"')) {
  162. $updaterAppPanel = $form;
  163. unset($forms[$index]);
  164. continue;
  165. }
  166. if (strpos($form, 'id="ocDefaultEncryptionModule"')) {
  167. $ocDefaultEncryptionModulePanel = $form;
  168. unset($forms[$index]);
  169. continue;
  170. }
  171. }
  172. if ($filesExternal) {
  173. $formsAndMore[] = array('anchor' => 'files_external', 'section-name' => $l->t('External Storage'));
  174. }
  175. $template->assign('fileSharingSettings', $fileSharingSettings);
  176. $template->assign('filesExternal', $filesExternal);
  177. $template->assign('updaterAppPanel', $updaterAppPanel);
  178. $template->assign('ocDefaultEncryptionModulePanel', $ocDefaultEncryptionModulePanel);
  179. $lockingProvider = \OC::$server->getLockingProvider();
  180. if ($lockingProvider instanceof NoopLockingProvider) {
  181. $template->assign('fileLockingType', 'none');
  182. } else if ($lockingProvider instanceof \OC\Lock\DBLockingProvider) {
  183. $template->assign('fileLockingType', 'db');
  184. } else {
  185. $template->assign('fileLockingType', 'cache');
  186. }
  187. $formsMap = array_map(function ($form) {
  188. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  189. $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
  190. $sectionName = str_replace('</h2>', '', $sectionName);
  191. $anchor = strtolower($sectionName);
  192. $anchor = str_replace(' ', '-', $anchor);
  193. return array(
  194. 'anchor' => 'goto-' . $anchor,
  195. 'section-name' => $sectionName,
  196. 'form' => $form
  197. );
  198. }
  199. return array(
  200. 'form' => $form
  201. );
  202. }, $forms);
  203. $formsAndMore = array_merge($formsAndMore, $formsMap);
  204. // add bottom hardcoded forms from the template
  205. $formsAndMore[] = ['anchor' => 'backgroundjobs', 'section-name' => $l->t('Cron')];
  206. $formsAndMore[] = ['anchor' => 'mail_general_settings', 'section-name' => $l->t('Email server')];
  207. $formsAndMore[] = ['anchor' => 'log-section', 'section-name' => $l->t('Log')];
  208. $formsAndMore[] = ['anchor' => 'admin-tips', 'section-name' => $l->t('Tips & tricks')];
  209. if ($updaterAppPanel) {
  210. $formsAndMore[] = ['anchor' => 'updater', 'section-name' => $l->t('Updates')];
  211. }
  212. $template->assign('forms', $formsAndMore);
  213. $template->printPage();