This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @see http://www.yiiframework.com/ |
||
4 | * |
||
5 | * @copyright Copyright (c) 2008 Yii Software LLC |
||
6 | * @license http://www.yiiframework.com/license/ |
||
7 | */ |
||
8 | |||
9 | namespace yiicod\cron\commands; |
||
10 | |||
11 | use yii\base\InvalidConfigException; |
||
12 | |||
13 | /** |
||
14 | * FileOutput records log messages in a file. |
||
15 | */ |
||
16 | class FileOutput |
||
17 | { |
||
18 | /** |
||
19 | * @var string log file path or path alias. If not set, it will use the "@runtime/logs/app.log" file. |
||
20 | * The directory containing the log files will be automatically created if not existing. |
||
21 | */ |
||
22 | public $logFile; |
||
23 | |||
24 | /** |
||
25 | * @var int maximum log file size, in kilo-bytes. Defaults to 10240, meaning 10MB. |
||
26 | */ |
||
27 | public $maxFileSize = 10240; // in KB |
||
28 | /** |
||
29 | * @var int number of log files used for rotation. Defaults to 5. |
||
30 | */ |
||
31 | public $maxLogFiles = 5; |
||
32 | |||
33 | /** |
||
34 | * @var bool Whether to rotate log files by copy and truncate in contrast to rotation by |
||
35 | * renaming files. Defaults to `true` to be more compatible with log tailers and is windows |
||
36 | * systems which do not play well with rename on open files. Rotation by renaming however is |
||
37 | * a bit faster. |
||
38 | * |
||
39 | * The problem with windows systems where the [rename()](http://www.php.net/manual/en/function.rename.php) |
||
40 | * function does not work with files that are opened by some process is described in a |
||
41 | * [comment by Martin Pelletier](http://www.php.net/manual/en/function.rename.php#102274) in |
||
42 | * the PHP documentation. By setting rotateByCopy to `true` you can work |
||
43 | * around this problem. |
||
44 | */ |
||
45 | public $rotateByCopy = true; |
||
46 | |||
47 | /** |
||
48 | * Initializes the route. |
||
49 | * This method is invoked after the route is created by the route manager. |
||
50 | */ |
||
51 | public function __construct($logFile) |
||
52 | { |
||
53 | $this->logFile = $logFile; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Writes log messages to a file. |
||
58 | * |
||
59 | * @throws InvalidConfigException if unable to open the log file for writing |
||
60 | */ |
||
61 | public function stdout($text) |
||
62 | { |
||
63 | /* Disable empty output */ |
||
64 | if (empty($text)) { |
||
65 | return; |
||
66 | } |
||
67 | $text = sprintf("\n---------------------------------\n%s Stack output:\n---------------------------------\n%s", date('Y-m-d H:i:s'), $text); |
||
68 | if (false === ($fp = @fopen($this->logFile, 'a'))) { |
||
69 | throw new InvalidConfigException("Unable to append to log file: {$this->logFile}"); |
||
70 | } |
||
71 | @flock($fp, LOCK_EX); |
||
0 ignored issues
–
show
|
|||
72 | |||
73 | // clear stat cache to ensure getting the real current file size and not a cached one |
||
74 | // this may result in rotating twice when cached file size is used on subsequent calls |
||
75 | clearstatcache(); |
||
76 | |||
77 | if (@filesize($this->logFile) > $this->maxFileSize * 1024) { |
||
78 | $this->rotateFiles(); |
||
79 | @flock($fp, LOCK_UN); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
80 | @fclose($fp); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
81 | @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
82 | } else { |
||
83 | @fwrite($fp, $text); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
84 | @flock($fp, LOCK_UN); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
85 | @fclose($fp); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
86 | } |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Rotates log files. |
||
91 | */ |
||
92 | protected function rotateFiles() |
||
93 | { |
||
94 | $file = $this->logFile; |
||
95 | for ($i = $this->maxLogFiles; $i >= 0; --$i) { |
||
96 | // $i == 0 is the original log file |
||
97 | $rotateFile = $file . (0 === $i ? '' : '.' . $i); |
||
98 | if (is_file($rotateFile)) { |
||
99 | // suppress errors because it's possible multiple processes enter into this section |
||
100 | if ($i === $this->maxLogFiles) { |
||
101 | @unlink($rotateFile); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
102 | } else { |
||
103 | if ($this->rotateByCopy) { |
||
104 | @copy($rotateFile, $file . '.' . ($i + 1)); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
105 | if ($fp = @fopen($rotateFile, 'a')) { |
||
106 | @ftruncate($fp, 0); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
107 | @fclose($fp); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
108 | } |
||
109 | } else { |
||
110 | @rename($rotateFile, $file . '.' . ($i + 1)); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
111 | } |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 |
If you suppress an error, we recommend checking for the error condition explicitly: