SuperSakeChecker::hasWebConfigProtection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
4
class SuperSakeChecker
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    /**
7
     * Checks if the supersake file in webroot is protected with htaccess or web.config.
8
     *
9
     * From the command line we don't know on what server software we are running,
10
     * so we just checking if a .htaccess or web.config exists and has the protection lines in it.
11
     *
12
     * If one of the files has access to the file denied, we consider this protected
13
     *
14
     * @return bool|string
15
     */
16
    public function superSakeIsNotProtected()
17
    {
18
        $htaccess = $this->hasHtAccessProtection(BASE_PATH.'/.htaccess');
19
        $webConfig = $this->hasWebConfigProtection(BASE_PATH.'/web.config');
20
21
        // nothing is done, add the instructions
22
        return !$htaccess && !$webConfig;
23
    }
24
25
    /**
26
     * @param string $file
27
     *
28
     * @return bool|string
29
     */
30
    protected function hasHtAccessProtection($file)
31
    {
32
        return is_file($file) &&
33
               strpos(file_get_contents($file), '<Files supersake>') !== false;
34
    }
35
36
    /**
37
     * @param string $file
38
     *
39
     * @return bool|string
40
     */
41
    protected function hasWebConfigProtection($file)
42
    {
43
        return is_file($file) &&
44
               strpos(file_get_contents($file), '<add fileExtension="supersake" allowed="false"/>') !== false;
45
    }
46
47
    public function htaccessContent()
48
    {
49
        $content = <<<'EOF'
50
51
# Deny access to supersake
52
<Files supersake>
53
    Order allow,deny
54
    Deny from all
55
</Files>
56
57
EOF;
58
59
        return $content;
60
    }
61
62
    public function webconfigContent()
63
    {
64
        $content = <<<'EOF'
65
<add fileExtension="supersake" allowed="false"/>
66
EOF;
67
68
        return $content;
69
    }
70
}
71