Skip to content

Commit

Permalink
Allow customers to enable separate log-file for (sub)domains; fixes #…
Browse files Browse the repository at this point in the history
…1117

Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Jul 26, 2023
1 parent 9d113af commit d1043b4
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 6 deletions.
17 changes: 17 additions & 0 deletions customer_domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,23 @@
} else {
Response::standardError('domains_canteditdomain');
}
} elseif ($action == 'jqSpeciallogfileNote') {
$domainid = intval($_POST['id']);
$newval = intval($_POST['newval']);
try {
$json_result = SubDomains::getLocal($userinfo, [
'id' => $domainid
])->get();
} catch (Exception $e) {
Response::dynamicError($e->getMessage());
}
$result = json_decode($json_result, true)['data'];
if ($newval != $result['speciallogfile']) {
echo json_encode(['changed' => true, 'info' => lng('admin.speciallogwarning')]);
exit();
}
echo 0;
exit();
}
} elseif ($page == 'domainssleditor') {
require_once __DIR__ . '/ssl_editor.php';
Expand Down
41 changes: 38 additions & 3 deletions lib/Froxlor/Api/Commands/SubDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
* optional, php-settings-id, if empty the $domain value is used
* @param int $redirectcode
* optional, redirect-code-id from TABLE_PANEL_REDIRECTCODES
* @param int $speciallogfile
* optional, whether to create an exclusive web-logfile for this domain (1) or not (0) or inherit value from parentdomain (2, default)
* @param bool $sslenabled
* optional, whether or not SSL is enabled for this domain, regardless of the assigned ssl-ips, default
* 1 (true)
Expand Down Expand Up @@ -107,6 +109,7 @@ public function add()
$openbasedir_path = $this->getParam('openbasedir_path', true, 0);
$phpsettingid = $this->getParam('phpsettingid', true, 0);
$redirectcode = $this->getParam('redirectcode', true, Settings::Get('customredirect.default'));
$speciallogfile = intval($this->getParam('speciallogfile', true, 2));
$isemaildomain = $this->getParam('isemaildomain', true, 0);
if (Settings::Get('system.use_ssl')) {
$sslenabled = $this->getBoolParam('sslenabled', true, 1);
Expand Down Expand Up @@ -276,6 +279,11 @@ public function add()
$ssl_redirect = 2;
}

// validate speciallogfile value
if ($speciallogfile < 0 || $speciallogfile > 2) {
$speciallogfile = 2; // inherit from parent-domain
}

// get the phpsettingid from parentdomain, #107
$phpsid_stmt = Database::prepare("
SELECT `phpsettingid` FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `id` = :id
Expand Down Expand Up @@ -354,7 +362,7 @@ public function add()
"openbasedir" => $domain_check['openbasedir'],
"openbasedir_path" => $openbasedir_path,
"phpenabled" => $domain_check['phpenabled'],
"speciallogfile" => $domain_check['speciallogfile'],
"speciallogfile" => $speciallogfile == 2 ? $domain_check['speciallogfile'] : $speciallogfile,
"specialsettings" => $domain_check['specialsettings'],
"ssl_specialsettings" => $domain_check['ssl_specialsettings'],
"include_specialsettings" => $domain_check['include_specialsettings'],
Expand Down Expand Up @@ -591,6 +599,11 @@ private function validateDomainDocumentRoot($path = null, $url = null, $customer
* optional, php-settings-id, if empty the $domain value is used
* @param int $redirectcode
* optional, redirect-code-id from TABLE_PANEL_REDIRECTCODES
* @param bool $speciallogfile
* optional, whether to create an exclusive web-logfile for this domain
* @param bool $speciallogverified
* optional, when setting $speciallogfile to false, this needs to be set to true to confirm the action,
* default 0 (false)
* @param bool $sslenabled
* optional, whether or not SSL is enabled for this domain, regardless of the assigned ssl-ips, default
* 1 (true)
Expand Down Expand Up @@ -648,6 +661,8 @@ public function update()
$openbasedir_path = $this->getParam('openbasedir_path', true, $result['openbasedir_path']);
$phpsettingid = $this->getParam('phpsettingid', true, $result['phpsettingid']);
$redirectcode = $this->getParam('redirectcode', true, Domain::getDomainRedirectId($id));
$speciallogfile = $this->getBoolParam('speciallogfile', true, $result['speciallogfile']);
$speciallogverified = $this->getBoolParam('speciallogverified', true, 0);
if (Settings::Get('system.use_ssl')) {
$sslenabled = $this->getBoolParam('sslenabled', true, $result['ssl_enabled']);
$ssl_redirect = $this->getBoolParam('ssl_redirect', true, $result['ssl_redirect']);
Expand Down Expand Up @@ -757,6 +772,10 @@ public function update()
$ssl_redirect = 2;
}

if ($speciallogfile != $result['speciallogfile'] && $speciallogverified != '1') {
$speciallogfile = $result['speciallogfile'];
}

// is-email-domain flag changed - remove mail accounts and mail-addresses
if (($result['isemaildomain'] == '1') && $isemaildomain == '0') {
$params = [
Expand Down Expand Up @@ -789,7 +808,21 @@ public function update()
Domain::updateRedirectOfDomain($id, $redirectcode);
}

if ($path != $result['documentroot'] || $isemaildomain != $result['isemaildomain'] || $wwwserveralias != $result['wwwserveralias'] || $iswildcarddomain != $result['iswildcarddomain'] || $aliasdomain != (int)$result['aliasdomain'] || $openbasedir_path != $result['openbasedir_path'] || $ssl_redirect != $result['ssl_redirect'] || $letsencrypt != $result['letsencrypt'] || $hsts_maxage != $result['hsts'] || $hsts_sub != $result['hsts_sub'] || $hsts_preload != $result['hsts_preload'] || $phpsettingid != $result['phpsettingid'] || $http2 != $result['http2']) {
if ($path != $result['documentroot']
|| $isemaildomain != $result['isemaildomain']
|| $wwwserveralias != $result['wwwserveralias']
|| $iswildcarddomain != $result['iswildcarddomain']
|| $aliasdomain != (int)$result['aliasdomain']
|| $openbasedir_path != $result['openbasedir_path']
|| $ssl_redirect != $result['ssl_redirect']
|| $letsencrypt != $result['letsencrypt']
|| $hsts_maxage != $result['hsts']
|| $hsts_sub != $result['hsts_sub']
|| $hsts_preload != $result['hsts_preload']
|| $phpsettingid != $result['phpsettingid']
|| $http2 != $result['http2']
|| ($speciallogfile != $result['speciallogfile'] && $speciallogverified == '1')
) {
$stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_DOMAINS . "` SET
`documentroot` = :documentroot,
Expand All @@ -805,7 +838,8 @@ public function update()
`hsts` = :hsts,
`hsts_sub` = :hsts_sub,
`hsts_preload` = :hsts_preload,
`phpsettingid` = :phpsettingid
`phpsettingid` = :phpsettingid,
`speciallogfile` = :speciallogfile
WHERE `customerid`= :customerid AND `id`= :id
");
$params = [
Expand All @@ -823,6 +857,7 @@ public function update()
"hsts_sub" => $hsts_sub,
"hsts_preload" => $hsts_preload,
"phpsettingid" => $phpsettingid,
"speciallogfile" => $speciallogfile,
"customerid" => $customer['customerid'],
"id" => $id
];
Expand Down
13 changes: 12 additions & 1 deletion lib/formfields/customer/domains/formfield.domains_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@
'type' => 'select',
'select_var' => $phpconfigs,
'selected' => (int)Settings::Get('phpfpm.enabled') == 1 ? Settings::Get('phpfpm.defaultini') : Settings::Get('system.mod_fcgid_defaultini')
]
],
'speciallogfile' => [
'label' => lng('admin.speciallogfile.title'),
'desc' => lng('admin.speciallogfile.description'),
'type' => 'select',
'select_var' => [
0 => lng('panel.no'),
1 => lng('panel.yes'),
2 => lng('domain.inherited')
],
'selected' => 2
],
]
],
'section_bssl' => [
Expand Down
13 changes: 12 additions & 1 deletion lib/formfields/customer/domains/formfield.domains_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@
'type' => 'select',
'select_var' => $phpconfigs,
'selected' => $result['phpsettingid']
]
],
'speciallogfile' => [
'label' => lng('admin.speciallogfile.title'),
'desc' => lng('admin.speciallogfile.description'),
'type' => 'checkbox',
'value' => '1',
'checked' => $result['speciallogfile']
],
'speciallogverified' => [
'type' => 'hidden',
'value' => '0'
],
]
],
'section_bssl' => [
Expand Down
1 change: 1 addition & 0 deletions lng/de.lng.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@
],
'domain' => [
'openbasedirpath' => 'OpenBasedir-Pfad',
'inherited' => 'Gleich wie Elterndomain',
'docroot' => 'Oben angegebener Pfad',
'homedir' => 'Heimverzeichnis',
'docparent' => 'Elternverzeichnis des oben angegebenen Pfads',
Expand Down
1 change: 1 addition & 0 deletions lng/en.lng.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@
],
'domain' => [
'openbasedirpath' => 'OpenBasedir-path',
'inherited' => 'Same as parent-domain',
'docroot' => 'Path from field above',
'homedir' => 'Home directory',
'docparent' => 'Parent-directory of path from field above',
Expand Down
2 changes: 1 addition & 1 deletion templates/Froxlor/src/js/components/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $(function() {
$('#speciallogfile').removeClass('is-invalid');
$('#speciallogverified').val(0);
$.ajax({
url: "admin_domains.php?page=overview&action=jqSpeciallogfileNote",
url: window.location.pathname.substring(1) + "?page=overview&action=jqSpeciallogfileNote",
type: "POST",
data: {
id: $('input[name=id]').val(), newval: +$('#speciallogfile').is(':checked')
Expand Down

0 comments on commit d1043b4

Please sign in to comment.