admin.php 6.46 KB
Newer Older
1
2
3
4
5
6
7
<?php
/**
 * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */

8
OC_Util::checkAdminUser();
9
OC_App::setActiveNavigationEntry("admin");
10

11
12
13
14
15
$template = new OC_Template('settings', 'admin', 'user');
$htAccessWorking = OC_Util::isHtaccessWorking();

$entries = OC_Log_Owncloud::getEntries(3);
$entriesRemaining = count(OC_Log_Owncloud::getEntries(4)) > 3;
16
$config = \OC::$server->getConfig();
17
$appConfig = \OC::$server->getAppConfig();
18

19
// Should we display sendmail as an option?
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$template->assign('sendmail_is_available', (bool)findBinaryPath('sendmail'));

$template->assign('loglevel', $config->getSystemValue("loglevel", 2));
$template->assign('mail_domain', $config->getSystemValue("mail_domain", ''));
$template->assign('mail_from_address', $config->getSystemValue("mail_from_address", ''));
$template->assign('mail_smtpmode', $config->getSystemValue("mail_smtpmode", ''));
$template->assign('mail_smtpsecure', $config->getSystemValue("mail_smtpsecure", ''));
$template->assign('mail_smtphost', $config->getSystemValue("mail_smtphost", ''));
$template->assign('mail_smtpport', $config->getSystemValue("mail_smtpport", ''));
$template->assign('mail_smtpauthtype', $config->getSystemValue("mail_smtpauthtype", ''));
$template->assign('mail_smtpauth', $config->getSystemValue("mail_smtpauth", false));
$template->assign('mail_smtpname', $config->getSystemValue("mail_smtpname", ''));
$template->assign('mail_smtppassword', $config->getSystemValue("mail_smtppassword", ''));
$template->assign('entries', $entries);
$template->assign('entriesremain', $entriesRemaining);
$template->assign('htaccessworking', $htAccessWorking);
$template->assign('isLocaleWorking', OC_Util::isSetLocaleWorking());
$template->assign('isPhpCharSetUtf8', OC_Util::isPhpCharSetUtf8());
$template->assign('isAnnotationsWorking', OC_Util::isAnnotationsWorking());
$template->assign('has_fileinfo', OC_Util::fileInfoLoaded());
$template->assign('old_php', OC_Util::isPHPoutdated());
$template->assign('backgroundjobs_mode', $appConfig->getValue('core', 'backgroundjobs_mode', 'ajax'));
$template->assign('cron_log', $config->getSystemValue('cron_log', true));
$template->assign('lastcron', $appConfig->getValue('core', 'lastcron', false));
$template->assign('shareAPIEnabled', $appConfig->getValue('core', 'shareapi_enabled', 'yes'));
$template->assign('shareDefaultExpireDateSet', $appConfig->getValue('core', 'shareapi_default_expire_date', 'no'));
$template->assign('shareExpireAfterNDays', $appConfig->getValue('core', 'shareapi_expire_after_n_days', '7'));
$template->assign('shareEnforceExpireDate', $appConfig->getValue('core', 'shareapi_enforce_expire_date', 'no'));
$excludeGroups = $appConfig->getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false;
$template->assign('shareExcludeGroups', $excludeGroups);
$excludedGroupsList = $appConfig->getValue('core', 'shareapi_exclude_groups_list', '');
51
$excludedGroupsList = explode(',', $excludedGroupsList); // FIXME: this should be JSON!
52
$template->assign('shareExcludedGroupsList', implode('|', $excludedGroupsList));
53
54

// Check if connected using HTTPS
55
56
$template->assign('isConnectedViaHTTPS', OC_Request::serverProtocol() === 'https');
$template->assign('enforceHTTPSEnabled', $config->getSystemValue("forcessl", false));
57

58
// If the current web root is non-empty but the web root from the config is,
59
// and system cron is used, the URL generator fails to build valid URLs.
60
$shouldSuggestOverwriteWebRoot = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' &&
61
62
	\OC::$WEBROOT && \OC::$WEBROOT !== '/' &&
	!$config->getSystemValue('overwritewebroot', '');
63
64
$suggestedOverwriteWebRoot = ($shouldSuggestOverwriteWebRoot) ? \OC::$WEBROOT : '';
$template->assign('suggestedOverwriteWebroot', $suggestedOverwriteWebRoot);
Morris Jobke's avatar
Morris Jobke committed
65

66
67
68
69
70
71
$template->assign('allowLinks', $appConfig->getValue('core', 'shareapi_allow_links', 'yes'));
$template->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired());
$template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes'));
$template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes'));
$template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no'));
$template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly());
Morris Jobke's avatar
Morris Jobke committed
72
$databaseOverload = (strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false);
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
$template->assign('databaseOverload', $databaseOverload);


// add hardcoded forms from the template
$forms = OC_App::getForms('admin');
$l = OC_L10N::get('settings');
$formsAndMore = array();
if (OC_Request::serverProtocol() !== 'https' || !$htAccessWorking || !OC_Util::isAnnotationsWorking() ||
	$suggestedOverwriteWebRoot || !OC_Util::isSetLocaleWorking() || !OC_Util::isPhpCharSetUtf8() ||
	OC_Util::isPHPoutdated() || !OC_Util::fileInfoLoaded() || $databaseOverload
) {
	$formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & Setup Warnings'));
}

$formsMap = array_map(function ($form) {
	if (preg_match('%(<h2[^>]*>.*?</h2>)%i', $form, $regs)) {
		$sectionName = str_replace('<h2>', '', $regs[0]);
		$sectionName = str_replace('</h2>', '', $sectionName);
		$anchor = strtolower($sectionName);
		$anchor = str_replace(' ', '-', $anchor);

		return array(
			'anchor' => $anchor,
			'section-name' => $sectionName,
			'form' => $form
		);
	}
	return array(
		'form' => $form
	);
}, $forms);

$formsAndMore = array_merge($formsAndMore, $formsMap);

// add bottom hardcoded forms from the template
$formsAndMore[] = array('anchor' => 'backgroundjobs', 'section-name' => $l->t('Cron'));
$formsAndMore[] = array('anchor' => 'shareAPI', 'section-name' => $l->t('Sharing'));
$formsAndMore[] = array('anchor' => 'security', 'section-name' => $l->t('Security'));
$formsAndMore[] = array('anchor' => 'mail_general_settings', 'section-name' => $l->t('Email Server'));
$formsAndMore[] = array('anchor' => 'log', 'section-name' => $l->t('Log'));

$template->assign('forms', $formsAndMore);
Morris Jobke's avatar
Morris Jobke committed
115

116
$template->printPage();
117
118

/**
119
 * Try to find a program
120
121
122
123
124
 *
 * @param string $program
 * @return null|string
 */
function findBinaryPath($program) {
125
126
127
128
129
	if (OC_Helper::is_function_enabled('exec')) {
		exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode);
		if ($returnCode === 0 && count($output) > 0) {
			return escapeshellcmd($output[0]);
		}
130
131
132
	}
	return null;
}