Completed
Push — master ( 88de30...a4b642 )
by Martijn van
02:12
created

SuperSakeChecker::webconfigContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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