admin.php 9.4 KB

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