Skip to content

Commit f5fac02

Browse files
committed
Code cleanup
1 parent a95445d commit f5fac02

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

modules/os2forms_digital_signature/os2forms_digital_signature.module

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,14 @@ function os2forms_digital_signature_file_download($uri) {
6363
$allowedIpsArr = array_filter($allowedIpsArr);
6464
$remoteIp = \Drupal::request()->getClientIp();
6565

66-
// IP list is empty, allow access.
67-
if (empty($allowedIpsArr)) {
66+
// Check if remote IP matches any allowed IP or CIDR range.
67+
if (empty($allowedIpsArr) || IpUtils::checkIp($remoteIp, $allowedIpsArr)) {
6868
$basename = basename($uri);
6969
return [
7070
'Content-disposition' => 'attachment; filename="' . $basename . '"',
7171
];
7272
}
7373

74-
// Check if remote IP matches any allowed IP or CIDR range.
75-
foreach ($allowedIpsArr as $allowedIp) {
76-
if ($remoteIp === $allowedIp || os2forms_digital_signature_ip_in_cidr($remoteIp, $allowedIp)) {
77-
$basename = basename($uri);
78-
return [
79-
'Content-disposition' => 'attachment; filename="' . $basename . '"',
80-
];
81-
}
82-
}
83-
8474
// Deny access and log warning.
8575
\Drupal::logger('os2forms_digital_signature')->warning('File download denied for IP @ip on URI @uri. Allowed IPs: @allowed', [
8676
'@ip' => $remoteIp,
@@ -94,18 +84,3 @@ function os2forms_digital_signature_file_download($uri) {
9484
// Not submission file, allow normal access.
9585
return NULL;
9686
}
97-
98-
/**
99-
* Check if an IP address is within a CIDR range.
100-
*
101-
* @param string $ip
102-
* The IP address to check.
103-
* @param string $cidr
104-
* The CIDR range (e.g. "172.16.0.0/16").
105-
*
106-
* @return bool
107-
* TRUE if the IP is within the CIDR range, FALSE otherwise.
108-
*/
109-
function os2forms_digital_signature_ip_in_cidr(string $ip, string $cidr): bool {
110-
return IpUtils::checkIp($ip, $cidr);
111-
}

modules/os2forms_digital_signature/os2forms_digital_signature.services.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,3 @@ services:
1111
- '@config.factory'
1212
- '@entity_type.manager'
1313
- '@logger.channel.os2forms_digital_signature'
14-
services:
15-
logger.channel.os2forms_digital_signature:
16-
parent: logger.channel_base
17-
arguments: [ 'os2forms_digital_signature' ]
18-
19-
os2forms_digital_signature.signing_service:
20-
class: Drupal\os2forms_digital_signature\Service\SigningService
21-
arguments:
22-
- '@http_client'
23-
- '@datetime.time'
24-
- '@config.factory'
25-
- '@entity_type.manager'
26-
- '@logger.channel.os2forms_digital_signature'

0 commit comments

Comments
 (0)