Issues (663)

Security Analysis    not enabled

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

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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.

zip/unzip.php (31 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
//验证密码
4
$password = "pwd";
5
6
?>
7
<html>
8
<head>
9
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
10
    <title>在线ZIP解压程序</title>
11
    <style type="text/css">
12
        <!--
13
        body, td {
14
            font-size: 14px;
15
            color: #000000;
16
        }
17
18
        a {
19
            color: #000066;
20
            text-decoration: none;
21
        }
22
23
        a:hover {
24
            color: #FF6600;
25
            text-decoration: underline;
26
        }
27
28
        -->
29
    </style>
30
</head>
31
32
<body>
33
<form name="myform" method="post" action="<?= $_SERVER[PHP_SELF]; ?>" enctype="multipart/form-data" onSubmit="return check_uploadObject(this);">
34
    <?
0 ignored issues
show
Security Best Practice introduced by
It is not recommend to use PHP's short opening tag <?, better use <?php, or <?= in case of outputting.

Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.

As a precaution to avoid these problems better use the long opening tag <?php.

Loading history...
35
    if (!$_REQUEST["myaction"]):
36
        ?>
37
38
        <script language="javascript">
39
            function check_uploadObject(form) {
40
                if (form.password.value == '') {
41
                    alert('请输入密码.');
42
                    return false;
43
                }
44
                return true;
45
            }
46
        </script>
47
48
        <table width="100%" border="0" cellspacing="0" cellpadding="4">
49
            <tr>
50
                <td height="40" colspan="2" style="color:#FF9900"><p><font color="#FF0000">在线解压ZIP文件程序</font></p>
51
                    <p>使用方法:把zip文件通过FTP上传到本文件相同的目录下,选择zip文件;或直接点击“浏览...”上传zip文件。</p>
52
                    <p>解压的结果保留原来的目录结构。</p>
53
                    <p>&nbsp;</p></td>
54
            </tr>
55
            <tr>
56
                <td width="11%">选择ZIP文件:</td>
57
                <td width="89%"><select name="zipfile">
58
                        <option value="" selected>- 请选择 -</option>
59
                        <?
60
                        $fdir = opendir('./');
61
                        while ($file = readdir($fdir)) {
62
                            if (!is_file($file)) {
63
                                continue;
64
                            }
65
                            if (preg_match('/\.zip$/mis', $file)) {
66
                                echo "<option value='$file'>$file</option>\r\n";
67
                            }
68
                        }
69
                        ?>
70
                    </select></td>
71
            </tr>
72
            <tr>
73
                <td width="11%" nowrap>或上传文件:</td>
74
                <td width="89%"><input name="upfile" type="file" id="upfile" size="20"></td>
75
            </tr>
76
            <tr>
77
                <td>解压到目录:</td>
78
                <td><input name="todir" type="text" id="todir" value="__unzipfiles__" size="15">
79
                    (留空为本目录,必须有写入权限)
80
                </td>
81
            </tr>
82
            <tr>
83
                <td>验证密码:</td>
84
                <td><input name="password" type="password" id="password" size="15">
85
                    (源文件中设定的密码)
86
                </td>
87
            </tr>
88
            <tr>
89
                <td><input name="myaction" type="hidden" id="myaction" value="dounzip"></td>
90
                <td><input type="submit" name="Submit" value=" 解 压 "></td>
91
            </tr>
92
        </table>
93
94
    <?
95
96
    elseif ($_REQUEST["myaction"] === "dounzip"):
97
98
    /**
99
     * Class zip
100
     */
101
    class zip
102
    {
103
104
        var $total_files   = 0;
105
        var $total_folders = 0;
106
107
        /**
108
         * @param       $zn
109
         * @param       $to
110
         * @param array $index
111
         * @return int
0 ignored issues
show
Should the return type not be integer|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
112
         */
113
        function Extract($zn, $to, $index = Array(-1))
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
114
        {
115
            $ok  = 0;
0 ignored issues
show
$ok is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
116
            $zip = @fopen($zn, 'rb');
117
            if (!$zip) {
118
                return (-1);
119
            }
120
            $cdir      = $this->ReadCentralDir($zip, $zn);
121
            $pos_entry = $cdir['offset'];
122
123
            if (!is_array($index)) {
124
                $index = array($index);
125
            }
126
            for ($i = 0; $index[$i]; $i++) {
127
                if ((int)($index[$i]) != $index[$i] || $index[$i] > $cdir['entries']) {
128
                    return (-1);
129
                }
130
            }
131
            for ($i = 0; $i < $cdir['entries']; $i++) {
132
                @fseek($zip, $pos_entry);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
133
                $header          = $this->ReadCentralFileHeaders($zip);
134
                $header['index'] = $i;
135
                $pos_entry       = ftell($zip);
136
                @rewind($zip);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
137
                fseek($zip, $header['offset']);
138
                if (in_array("-1", $index) || in_array($i, $index)) {
139
                    $stat[$header['filename']] = $this->ExtractFile($header, $to, $zip);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$stat was never initialized. Although not strictly required by PHP, it is generally a good practice to add $stat = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
140
                }
141
            }
142
            fclose($zip);
143
144
            return $stat;
0 ignored issues
show
The variable $stat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
145
        }
146
147
        /**
148
         * @param $zip
149
         * @return mixed
150
         */
151
        function ReadFileHeader($zip)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
152
        {
153
            $binary_data = fread($zip, 30);
154
            $data        = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
155
156
            $header['filename'] = fread($zip, $data['filename_len']);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$header was never initialized. Although not strictly required by PHP, it is generally a good practice to add $header = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
157 View Code Duplication
            if ($data['extra_len'] != 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
                $header['extra'] = fread($zip, $data['extra_len']);
159
            } else {
160
                $header['extra'] = '';
161
            }
162
163
            $header['compression']     = $data['compression'];
164
            $header['size']            = $data['size'];
165
            $header['compressed_size'] = $data['compressed_size'];
166
            $header['crc']             = $data['crc'];
167
            $header['flag']            = $data['flag'];
168
            $header['mdate']           = $data['mdate'];
169
            $header['mtime']           = $data['mtime'];
170
171 View Code Duplication
            if ($header['mdate'] && $header['mtime']) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
172
                $hour            = ($header['mtime'] & 0xF800) >> 11;
173
                $minute          = ($header['mtime'] & 0x07E0) >> 5;
174
                $seconde         = ($header['mtime'] & 0x001F) * 2;
175
                $year            = (($header['mdate'] & 0xFE00) >> 9) + 1980;
176
                $month           = ($header['mdate'] & 0x01E0) >> 5;
177
                $day             = $header['mdate'] & 0x001F;
178
                $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
179
            } else {
180
                $header['mtime'] = time();
181
            }
182
183
            $header['stored_filename'] = $header['filename'];
184
            $header['status']          = "ok";
185
186
            return $header;
187
        }
188
189
        /**
190
         * @param $zip
191
         * @return array
192
         */
193
        function ReadCentralFileHeaders($zip)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
194
        {
195
            $binary_data = fread($zip, 46);
196
            $header      = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
197
198
            if ($header['filename_len'] != 0) {
199
                $header['filename'] = fread($zip, $header['filename_len']);
200
            } else {
201
                $header['filename'] = '';
202
            }
203
204 View Code Duplication
            if ($header['extra_len'] != 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
205
                $header['extra'] = fread($zip, $header['extra_len']);
206
            } else {
207
                $header['extra'] = '';
208
            }
209
210
            if ($header['comment_len'] != 0) {
211
                $header['comment'] = fread($zip, $header['comment_len']);
212
            } else {
213
                $header['comment'] = '';
214
            }
215
216 View Code Duplication
            if ($header['mdate'] && $header['mtime']) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
217
                $hour            = ($header['mtime'] & 0xF800) >> 11;
218
                $minute          = ($header['mtime'] & 0x07E0) >> 5;
219
                $seconde         = ($header['mtime'] & 0x001F) * 2;
220
                $year            = (($header['mdate'] & 0xFE00) >> 9) + 1980;
221
                $month           = ($header['mdate'] & 0x01E0) >> 5;
222
                $day             = $header['mdate'] & 0x001F;
223
                $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
224
            } else {
225
                $header['mtime'] = time();
226
            }
227
            $header['stored_filename'] = $header['filename'];
228
            $header['status']          = 'ok';
229
            if (substr($header['filename'], -1) === '/') {
230
                $header['external'] = 0x41FF0010;
231
            }
232
233
            return $header;
234
        }
235
236
        /**
237
         * @param $zip
238
         * @param $zip_name
239
         * @return mixed
240
         */
241
        function ReadCentralDir($zip, $zip_name)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
242
        {
243
            $size = filesize($zip_name);
244
245
            if ($size < 277) {
246
                $maximum_size = $size;
247
            } else {
248
                $maximum_size = 277;
249
            }
250
251
            @fseek($zip, $size - $maximum_size);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
252
            $pos   = ftell($zip);
253
            $bytes = 0x00000000;
254
255
            while ($pos < $size) {
256
                $byte  = @fread($zip, 1);
257
                $bytes = ($bytes << 8) | ord($byte);
258
                if ($bytes == 0x504b0506 or $bytes == 0x2e706870504b0506) {
259
                    $pos++;
260
                    break;
261
                }
262
                $pos++;
263
            }
264
265
            $fdata = fread($zip, 18);
266
267
            $data = @unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $fdata);
268
269
            if ($data['comment_size'] != 0) {
270
                $centd['comment'] = fread($zip, $data['comment_size']);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$centd was never initialized. Although not strictly required by PHP, it is generally a good practice to add $centd = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
271
            } else {
272
                $centd['comment'] = '';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$centd was never initialized. Although not strictly required by PHP, it is generally a good practice to add $centd = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
273
            }
274
            $centd['entries']      = $data['entries'];
275
            $centd['disk_entries'] = $data['disk_entries'];
276
            $centd['offset']       = $data['offset'];
277
            $centd['disk_start']   = $data['disk_start'];
278
            $centd['size']         = $data['size'];
279
            $centd['disk']         = $data['disk'];
280
281
            return $centd;
282
        }
283
284
        /**
285
         * @param $header
286
         * @param $to
287
         * @param $zip
288
         * @return bool|void
0 ignored issues
show
Should the return type not be null|integer|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
289
         */
290
        function ExtractFile($header, $to, $zip)
0 ignored issues
show
The parameter $header is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
291
        {
292
            $header = $this->readfileheader($zip);
293
294
            if (substr($to, -1) !== "/") {
295
                $to .= "/";
296
            }
297
            if ($to === './') {
298
                $to = '';
299
            }
300
            $pth   = explode("/", $to . $header['filename']);
301
            $mydir = '';
302
            for ($i = 0; $i < count($pth) - 1; $i++) {
303
                if (!$pth[$i]) {
304
                    continue;
305
                }
306
                $mydir .= $pth[$i] . "/";
307
                if ((!is_dir($mydir) && @mkdir($mydir, 0777)) || (($mydir == $to . $header['filename'] || ($mydir == $to && $this->total_folders == 0)) && is_dir($mydir))) {
308
                    @chmod($mydir, 0777);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
309
                    $this->total_folders++;
310
                    echo "<input name='dfile[]' type='checkbox' value='$mydir' checked> <a href='$mydir' target='_blank'>目录: $mydir</a><br>";
311
                }
312
            }
313
314
            if (strrchr($header['filename'], '/') === '/') {
315
                return;
316
            }
317
318
            if (!($header['external'] == 0x41FF0010) && !($header['external'] == 16)) {
319
                if ($header['compression'] == 0) {
320
                    $fp = @fopen($to . $header['filename'], 'wb');
321
                    if (!$fp) {
322
                        return (-1);
323
                    }
324
                    $size = $header['compressed_size'];
325
326 View Code Duplication
                    while ($size != 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
327
                        $read_size   = ($size < 2048 ? $size : 2048);
328
                        $buffer      = fread($zip, $read_size);
329
                        $binary_data = pack('a' . $read_size, $buffer);
330
                        @fwrite($fp, $binary_data, $read_size);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
331
                        $size -= $read_size;
332
                    }
333
                    fclose($fp);
334
                    touch($to . $header['filename'], $header['mtime']);
335
                } else {
336
                    $fp = @fopen($to . $header['filename'] . '.gz', 'wb');
337
                    if (!$fp) {
338
                        return (-1);
339
                    }
340
                    $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
341
342
                    fwrite($fp, $binary_data, 10);
343
                    $size = $header['compressed_size'];
344
345 View Code Duplication
                    while ($size != 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
346
                        $read_size   = ($size < 1024 ? $size : 1024);
347
                        $buffer      = fread($zip, $read_size);
348
                        $binary_data = pack('a' . $read_size, $buffer);
349
                        @fwrite($fp, $binary_data, $read_size);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
350
                        $size -= $read_size;
351
                    }
352
353
                    $binary_data = pack('VV', $header['crc'], $header['size']);
354
                    fwrite($fp, $binary_data, 8);
355
                    fclose($fp);
356
357
                    $gzp = @gzopen($to . $header['filename'] . '.gz', 'rb') or die("Cette archive est compress閑");
358
                    if (!$gzp) {
359
                        return (-2);
360
                    }
361
                    $fp = @fopen($to . $header['filename'], 'wb');
362
                    if (!$fp) {
363
                        return (-1);
364
                    }
365
                    $size = $header['size'];
366
367 View Code Duplication
                    while ($size != 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
368
                        $read_size   = ($size < 2048 ? $size : 2048);
369
                        $buffer      = gzread($gzp, $read_size);
370
                        $binary_data = pack('a' . $read_size, $buffer);
371
                        @fwrite($fp, $binary_data, $read_size);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
372
                        $size -= $read_size;
373
                    }
374
                    fclose($fp);
375
                    gzclose($gzp);
376
377
                    touch($to . $header['filename'], $header['mtime']);
378
                    @unlink($to . $header['filename'] . '.gz');
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
379
380
                }
381
            }
382
383
            $this->total_files++;
384
            echo "<input name='dfile[]' type='checkbox' value='$to$header[filename]' checked> <a href='$to$header[filename]' target='_blank'>文件: $to$header[filename]</a><br>";
385
386
            return true;
387
        }
388
389
        // end class
390
    }
391
392
    set_time_limit(0);
393
394
    if ($_POST['password'] != $password) {
395
        die("输入的密码不正确,请重新输入。");
396
    }
397
    if (!$_POST["todir"]) {
398
        $_POST["todir"] = ".";
399
    }
400
    $z             = new Zip;
401
    $have_zip_file = 0;
402
    /**
403
     * @param $tmp_name
404
     * @param $new_name
405
     * @param $checked
406
     */
407
    function start_unzip($tmp_name, $new_name, $checked)
408
    {
409
        global $_POST, $z, $have_zip_file;
410
        $upfile = array("tmp_name" => $tmp_name, "name" => $new_name);
411
        if (is_file($upfile[tmp_name])) {
412
            $have_zip_file = 1;
413
            echo "<br>正在解压: <input name='dfile[]' type='checkbox' value='$upfile[name]' " . ($checked ? "checked" : "") . "> $upfile[name]<br><br>";
414
            if (preg_match('/\.zip$/mis', $upfile[name])) {
415
                $result = $z->Extract($upfile[tmp_name], $_POST["todir"]);
416
                if ($result == -1) {
417
                    echo "<br>文件 $upfile[name] 错误.<br>";
418
                }
419
                echo "<br>完成,共建立 $z->total_folders 个目录,$z->total_files 个文件.<br><br><br>";
420
            } else {
421
                echo "<br>$upfile[name] 不是 zip 文件.<br><br>";
422
            }
423
            if (realpath($upfile[name]) != realpath($upfile[tmp_name])) {
424
                @unlink($upfile[name]);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
425
                rename($upfile[tmp_name], $upfile[name]);
426
            }
427
        }
428
    }
429
430
    clearstatcache();
431
432
    start_unzip($_POST["zipfile"], $_POST["zipfile"], 0);
433
    start_unzip($_FILES["upfile"][tmp_name], $_FILES["upfile"][name], 1);
434
435
    if (!$have_zip_file) {
436
        echo "<br>请选择或上传文件.<br>";
437
    }
438
    ?>
439
    <input name="password" type="hidden" id="password" value="<?= $_POST['password']; ?>">
440
    <input name="myaction" type="hidden" id="myaction" value="dodelete">
441
    <input name="按钮" type="button" value="返回" onClick="window.location='<?= $_SERVER[PHP_SELF]; ?>';">
442
443
    <input type='button' value='反选' onclick='selrev();'> <input type='submit' onclick='return confirm("删除选定文件?");' value='删除选定'>
444
445
        <script language='javascript'>
446
            function selrev() {
447
                with (document.myform) {
448
                    for (i = 0; i < elements.length; i++) {
449
                        thiselm = elements[i];
450
                        if (thiselm.name.match(/dfile\[]/))    thiselm.checked = !thiselm.checked;
451
                    }
452
                }
453
            }
454
            alert('完成.');
455
        </script>
456
        <?
457
458
    elseif ($_REQUEST["myaction"] === "dodelete"):
459
        set_time_limit(0);
460
        if ($_POST['password'] != $password) {
461
            die("输入的密码不正确,请重新输入。");
462
        }
463
464
        $dfile = $_POST["dfile"];
465
        echo "正在删除文件...<br><br>";
466
        if (is_array($dfile)) {
467
            for ($i = count($dfile) - 1; $i >= 0; $i--) {
468
                if (is_file($dfile[$i])) {
469
                    if (@unlink($dfile[$i])) {
470
                        echo "已删除文件: $dfile[$i]<br>";
471
                    } else {
472
                        echo "删除文件失败: $dfile[$i]<br>";
473
                    }
474
                } else {
475
                    if (@rmdir($dfile[$i])) {
476
                        echo "已删除目录: $dfile[$i]<br>";
477
                    } else {
478
                        echo "删除目录失败: $dfile[$i]<br>";
479
                    }
480
                }
481
482
            }
483
        }
484
        echo "<br>完成.<br><br><input type='button' value='返回' onclick=\"window.location='$_SERVER[PHP_SELF]';\"><br><br>
485
		 <script language='javascript'>('完成.');</script>";
486
487
    endif;
488
489
    ?>
490
</form>
491
</body>
492
</html>
493