Issues (4)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

source/ClassElectronicInvoiceUserInterface.php (3 issues)

1
<?php
2
3
/*
4
 * Copyright (c) 2024 - 2025 Daniel Popiniuc.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Daniel Popiniuc
12
 */
13
14
namespace danielgp\efactura;
15
16
class ClassElectronicInvoiceUserInterface
17
{
18
    use \danielgp\efactura\TraitUserInterfaceLogic;
0 ignored issues
show
The trait danielgp\efactura\TraitUserInterfaceLogic requires the property $numFiles which is not provided by danielgp\efactura\ClassE...nicInvoiceUserInterface.
Loading history...
19
    use \danielgp\efactura\TraitBackEndRomania;
20
21
    private \SebastianBergmann\Timer\Timer $classTimer;
22
23
    public function __construct()
24
    {
25
        $this->classTimer = new \SebastianBergmann\Timer\Timer();
26
        $this->classTimer->start();
27
        $this->getConfiguration();
28
        $this->setLocalization();
29
    }
30
31
    private function getButtonForLocalisation(string $strLanguageCountry): string
32
    {
33
        $arrayMapFlags  = [
34
            'ro_RO' => 'ro',
35
            'it_IT' => 'it',
36
            'en_US' => 'us',
37
        ];
38
        $arrayFlagSizes = ['20px', '15px'];
39
        if ($strLanguageCountry === filter_input(INPUT_GET, 'language_COUNTRY', FILTER_VALIDATE_REGEXP, [
40
                'options' => [
41
                    'regexp' => '/^(en_US|it_IT|ro_RO)$/'
42
                ]
43
            ])) {
44
            $arrayFlagSizes = ['40px', '30px'];
45
        }
46
        return vsprintf('<a href="?language_COUNTRY=%s" style="float:left;margin-left:10px;">'
47
            . '<span class="fi fi-%s" style="%s">&nbsp;</span>'
48
            . '</a>', [
49
            $strLanguageCountry . (array_key_exists('action', $_GET) ? '&action='
50
            . filter_input(INPUT_GET, 'action', FILTER_FLAG_ENCODE_LOW | FILTER_FLAG_ENCODE_HIGH) : ''),
51
            $arrayMapFlags[$strLanguageCountry],
52
            vsprintf('width:%s;height:%s;', $arrayFlagSizes),
53
        ]);
54
    }
55
56
    private function getButtonToActionSomething(array $arrayButtonFeatures): string
57
    {
58
        $arrayButtonStyle = [
59
            'font:bold 14pt Arial',
60
            'margin:2px',
61
            'padding:4px 10px',
62
        ];
63
        $arrayStylePieces = $arrayButtonStyle;
64
        if (array_key_exists('AdditionalStyle', $arrayButtonFeatures)) {
65
            $arrayStylePieces = array_merge($arrayButtonStyle, $arrayButtonFeatures['AdditionalStyle']);
66
        }
67
        return vsprintf('<a href="%s" class="btn btn-outline-primary" style="%s">%s</a>', [
68
            $arrayButtonFeatures['URL']
69
            . (array_key_exists('language_COUNTRY', $_GET) ? '&language_COUNTRY='
70
            . filter_input(INPUT_GET, 'language_COUNTRY', FILTER_VALIDATE_REGEXP, [
71
                'options' => [
72
                    'regexp' => '/^(en_US|it_IT|ro_RO)$/'
73
                ]
74
            ]) : ''),
75
            implode(';', $arrayStylePieces),
76
            $arrayButtonFeatures['Text'],
77
        ]);
78
    }
79
80
    private function getHeaderColumnMapping(array $arrayColumns): array
81
    {
82
        $arrayMap = [];
83
        foreach ($arrayColumns as $strColumnName) {
84
            $arrayMap[$strColumnName] = $strColumnName;
85
            $strRelevant              = $this->translation->find(null, 'i18n_Clmn_' . $strColumnName);
86
            if (!is_null($strRelevant)) {
87
                $arrayMap[$strColumnName] = $strRelevant->getTranslation();
88
            }
89
        }
90
        return $arrayMap;
91
    }
92
93
    public function setActionToDo(): void
94
    {
95
        echo '<main>';
96
        if (is_array($_GET) && array_key_exists('action', $_GET)) {
97
            $arrayOptions = [
98
                'action' => FILTER_SANITIZE_SPECIAL_CHARS,
99
            ];
100
            $arrayInputs  = filter_input_array(INPUT_GET, $arrayOptions, true);
101
            switch($arrayInputs['action']) {
102
                case 'AnalyzeZIPfromANAFfromLocalFolder':
103
                    echo '<div class="tabber" id="tabStandard">'
104
                    . '<div class="tabbertab" id="tab1" title="Filters">';
105
                    echo '</div><!-- tab1 -->';
106
                    echo '<div class="tabbertab" id="tab2" title="Lista">';
107
                    $strRelevantFolder = 'P:/e-Factura/ZIPs_from_ANAF/';
108
                    if (!file_exists($strRelevantFolder)) {
109
                        $strRelevantFolder = realpath('../../');
110
                    }
111
                    $arrayInvoices = $this->actionAnalyzeZIPfromANAFfromLocalFolder($strRelevantFolder);
112
                    if (count($arrayInvoices) === 0) {
113
                        echo sprintf('<p style="color:red;">'
114
                            . $this->translation->find(null, 'i18n_Msg_NoZip')->getTranslation()
115
                            . '</p>', $strRelevantFolder);
116
                    } else {
117
                        echo $this->setHtmlTable($arrayInvoices);
118
                    }
119
                    echo '</div><!-- tab2 -->'
120
                    . '</div><!-- tabStandard -->';
121
                    break;
122
                case 'checkAllMessages':
123
                    if (!array_key_exists('NumberOfDays', $_GET)) {
124
                        $_GET['NumberOfDays'] = 2;
125
                    }
126
                    $this->getElectronicInvoiceMessages('ListAll', [
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
127
                        'Days' => filter_input(INPUT_GET, 'NumberOfDays', FILTER_SANITIZE_NUMBER_INT),
128
                    ]);
129
                case 'checkSingleMessage':
130
                    if (!array_key_exists('NumberOfDays', $_GET)) {
131
                        $_GET['LoadingId'] = 0; // this is not real ID...
132
                    }
133
                    $this->getElectronicInvoiceMessages('Single', [
134
                        'LoadingId' => filter_input(INPUT_GET, 'LoadingId', FILTER_SANITIZE_NUMBER_INT),
135
                    ]);
136
                case 'uploadElectronicInvoicesFromFolderToRomanianAuthority':
137
                    $this->uploadElectronicInvoicesFromFolder();
138
                    break;
139
            }
140
        }
141
        echo '</main>';
142
    }
143
144
    public function setHtmlFooter(): void
145
    {
146
        $strHtmlContent = implode('', $this->getFileEntireContent(implode(DIRECTORY_SEPARATOR, [
147
                __DIR__,
148
                'HTML',
149
                'footer.html',
150
        ])));
151
        echo vsprintf($strHtmlContent, [
152
            (new \SebastianBergmann\Timer\ResourceUsageFormatter())->resourceUsage($this->classTimer->stop()),
0 ignored issues
show
The type SebastianBergmann\Timer\ResourceUsageFormatter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
153
            date('Y'),
154
            $this->arrayConfiguration['Application']['Developer'],
155
        ]);
156
    }
157
158
    public function setHtmlHeader(): void
159
    {
160
        $strHtmlContent = implode('', $this->getFileEntireContent(implode(DIRECTORY_SEPARATOR, [
161
                __DIR__,
162
                'HTML',
163
                'header.html',
164
        ])));
165
        echo vsprintf($strHtmlContent, [
166
            $this->arrayConfiguration['Application']['Name'],
167
            $this->arrayConfiguration['Application']['Developer'],
168
        ]);
169
    }
170
171
    public function setHtmlTable(array $arrayData): string
172
    {
173
        $strReturn = '<table style="margin-left:auto;margin-right:auto;">';
174
        foreach ($arrayData as $intLineNo => $arrayContent) {
175
            ksort($arrayContent);
176
            if ($intLineNo === 0) {
177
                $strReturn .= $this->setHtmlTableHeader(array_keys($arrayContent))
178
                    . '<tbody>';
179
            }
180
            $strReturn .= $this->setHtmlTableLine(($intLineNo + 1), $arrayContent);
181
        }
182
        return ($strReturn . '</tbody>' . '</table>');
183
    }
184
185
    private function setHtmlTableHeader(array $arrayData): string
186
    {
187
        $arrayMap    = $this->getHeaderColumnMapping(array_values($arrayData));
188
        $strToReturn = '<th>#</th>';
189
        foreach ($arrayData as $key) {
190
            $strToReturn .= sprintf('<th>%s</th>', (array_key_exists($key, $arrayMap) ? $arrayMap[$key] : $key));
191
        }
192
        return '<thead><tr>' . $strToReturn . '</tr></thead>';
193
    }
194
195
    private function setHtmlTableLine(int $intLineNo, array $arrayLine): string
196
    {
197
        $arrayContent = [];
198
        foreach ($arrayLine as $strColumn => $strValue) {
199
            if (str_starts_with($strColumn, 'Amount_')) {
200
                $arrayContent[] = sprintf('<td style="text-align:right;">%s</td>', $this->setNumbers($strValue, 2, 2));
201
            } elseif (in_array($strColumn, ['No_of_Lines', 'Response_Size', 'Size'])) {
202
                $arrayContent[] = sprintf('<td style="text-align:right;">%s</td>', $this->setNumbers($strValue, 0, 0));
203
            } else {
204
                $arrayContent[] = sprintf('<td>%s</td>', $strValue);
205
            }
206
        }
207
        return '<tr' . ($arrayLine['Error'] === '' ? '' : ' style="color:red;"') . '>'
208
            . '<td>' . $intLineNo . '</td>'
209
            . implode('', $arrayContent)
210
            . '</tr>';
211
    }
212
213
    private function setNumbers(float $floatNumber, int $intMinDigits, int $intMaxDigits): string
214
    {
215
        $classFormat = new \NumberFormatter($_GET['language_COUNTRY'], \NumberFormatter::DECIMAL);
216
        $classFormat->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $intMinDigits);
217
        $classFormat->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $intMaxDigits);
218
        return $classFormat->format($floatNumber);
219
    }
220
221
    public function setUserInterface(): void
222
    {
223
        echo '<header class="border-bottom">'
224
        . $this->getButtonForLocalisation('en_US')
225
        . $this->getButtonForLocalisation('it_IT')
226
        . $this->getButtonForLocalisation('ro_RO')
227
        . $this->getButtonToActionSomething([
228
            'Text' => $this->translation->find(null, 'i18n_Btn_AnalyzeZIP')->getTranslation(),
229
            'URL'  => '?action=AnalyzeZIPfromANAFfromLocalFolder',
230
        ])
231
        . ' </header>';
232
    }
233
}
234