GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 035e8c...04862d )
by Joram van den
02:15
created

index.php ➔ statusHtml()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 6
rs 9.4285
1
<?php
2
require '../vendor/autoload.php';
3
\Nabble\SemaltBlocker\Blocker::protect();
4
5
const STATUS_GREEN = 2;
6
const STATUS_ORANGE = 3;
7
const STATUS_RED = 4;
8
9
?>
10
<html>
11
<head>
12
    <title>semalt-blocker debug console</title>
13
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
14
    <style>
15
        section {
16
            margin: 100px 0;
17
        }
18
19
        form {
20
            margin: 0 0 50px;
21
        }
22
23
        input, button {
24
            padding: 10px;
25
            font-size: 18px;
26
            max-width: 100%;
27
        }
28
29
        input[name=url] {
30
            width: 30em;
31
        }
32
33
        .progress {
34
            width: 50%;
35
            display: inline-block;
36
        }
37
38
        .table {
39
            width: auto;
40
            margin: 0 auto;
41
        }
42
43
        .table span.success {
44
            color: green;
45
        }
46
47
        .table span.warning {
48
            color: orange;
49
        }
50
51
        .table span.danger {
52
            color: red;
53
        }
54
55
        span {
56
            font-weight: bold;
57
        }
58
59
        footer > div {
60
            padding-top: 50px;
61
            margin-bottom: 50px;
62
        }
63
    </style>
64
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
65
    <script>
66
        $(function () {
67
            var addhttp = function (e) {
68
                var $input = $('input[name=url]');
69
                if ($input.val() && !$input.val().match(/^https?:/)) {
70
                    $input.val('http://' + $input.val());
71
                }
72
            };
73
            $('input[name=url]').on('blur', addhttp);
74
            $('form').on('submit', addhttp);
75
        });
76
        var progress = function () {
77
            var total = $('table').data('total');
78
            var list = ['warning', 'danger', 'success'];
79
            for (var i in list) {
80
                var cat = list[i];
81
                var count = $('table span.' + cat).length;
82
                var perc = parseInt(count / total * 100);
83
                $('.progress-bar-' + cat).css('width', perc + '%').text(perc + '%');
84
            }
85
        };
86
    </script>
87
</head>
88
89
<body>
90
<section class="container">
91
    <div class="col-md-8 col-md-offset-2 text-center">
92
93
        <h1><a href="https://github.com/nabble/semalt-blocker">semalt-blocker</a> debug console</h1>
94
95
        <form method="get">
96
            <?php
97
            $url = isset($_GET['url']) ?
98
                $_GET['url'] :
99
                '';
100
            //                        "http://" . $_SERVER['HTTP_HOST'] . str_replace('index.php', '', $_SERVER['REQUEST_URI']) . 'target.php';
101
102
            $url = filter_var($url, FILTER_VALIDATE_URL);
103
104
            ?>
105
            <input type="text" name="url" placeholder="your website url" value="<?php echo htmlspecialchars($url); ?>"/>
106
            <button type="submit">debug url</button>
107
        </form>
108
109
    </div>
110
    <div class="col-md-12 text-center">
111
112
        <?php if (isset($_GET['url']) && empty($_GET['url'])) {
113
114
            echo 'No URL provided';
115
116
        } else if (isset($_GET['url']) && $_GET['url']) {
117
118
        function status($code)
119
        {
120
            if (substr($code, 0, 1) == '2') return STATUS_RED;
121
            if (substr($code, 0, 1) == '3') return STATUS_ORANGE;
122
            return STATUS_GREEN;
123
        }
124
125
        function statusHtml($status, $redirect = null)
126
        {
127
            if ($status == STATUS_RED) return '<span class="danger">Not blocked</span>';
128
            if ($status == STATUS_ORANGE) return '<span class="warning">Redirect </span> &rarr; <a href="?url=' . urlencode($redirect) . '">' . $redirect . '</a>';
129
            return '<span class="success">Blocked</span>';
130
        }
131
132
        ob_implicit_flush(true);
133
        ob_end_flush();
134
135
        $list = [];
136
137
        if ($url) {
138
139
            $list = \Nabble\SemaltBlocker\Blocker::getBlocklist();
140
            $client = new \Guzzle\Http\Client(null, array('redirect.disable' => true));
141
142
        }
143
144
        ?>
145
146
        <p><a href=".">recent scores</a></p>
147
        <div class="progress">
148
            <div class="progress-bar progress-bar-success" style="width: 0%"></div>
149
            <div class="progress-bar progress-bar-warning" style="width: 0%"></div>
150
            <div class="progress-bar progress-bar-danger" style="width: 0%"></div>
151
        </div>
152
        <table class='table table-bordered table-condensed table-hover' data-total='<?php echo count($list); ?>'>
153
154
            <?php
155
            $greens = 0;
156
            foreach ($list as $k => $referral) {
157
158
                $request = $client->get($url, [
159
                    'Referer' => 'http://' . $referral
160
                ]);
161
162
                $redirect = false;
163
                try {
164
                    $response = $request->send();
165
                    if ($response->getStatusCode() == 302 || $response->getStatusCode() == 301) {
166
                        $redirect = (string)$response->getHeader('Location');
167
                    }
168
                } catch (Guzzle\Http\Exception\BadResponseException $e) {
169
                    $response = $e->getResponse();
170
                } catch (Exception $e) {
171
                    $response = false;
172
                }
173
174
                $status = STATUS_RED;
175
                if ($response) {
176
                    $status = status($response->getStatusCode());
177
                    echo "<tr><th>" . $referral . '</th><td>' . statusHtml($status, $redirect) . '</td></tr>';
178
                }
179
180
                if ($status == STATUS_GREEN)
181
                    $greens++;
182
183
                echo "<script>progress();</script>";
184
            }
185
186
            if (count($list)) {
187
                $perc = str_pad((int)($greens / count($list) * 100), 3, "0", STR_PAD_LEFT);
188
                file_put_contents('stats/' . base64_encode($url), $url . PHP_EOL . $perc . PHP_EOL . time() . PHP_EOL);
189
            }
190
191
            echo "</table>";
192
193
            } else {
194
195
                $files = glob('stats/*');
196
                usort($files, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
197
                ?>
198
199
                <h3>Recent scores</h3>
200
                <table class="table">
201
                    <thead>
202
                        <tr>
203
                            <th>Date</th>
204
                            <th>URL</th>
205
                            <th>Blocked</th>
206
                        </tr>
207
                    </thead>
208
209
                <?php
210
                $i = 0;
211
                foreach ($files as $file) {
212
                    $i++;
213
                    $results = explode(PHP_EOL, file_get_contents($file));
214
                    ?>
215
                    <tr>
216
                        <td><?php echo date('c', $results[2]); ?></td>
217
                        <td><?php echo htmlentities($results[0]); ?></td>
218
                        <td><?php echo (int) $results[1]; ?>%</td>
219
                    </tr>
220
                    <?php
221
                    if ($i > 10) break;
222
                }
223
                ?>
224
225
                </table>
226
227
                <?php
228
            } ?>
229
230
    </div>
231
</section>
232
233
<footer class="container text-center">
234
    <hr/>
235
    <div class="col-sm-6 col-sm-offset-3">
236
        a service by <a href="http://nabble.nl">Nabble</a><br/>
237
        source available on <a href="https://github.com/nabble/semalt-blocker">GitHub</a>
238
    </div>
239
</footer>
240
241
<script>
242
    (function (i, s, o, g, r, a, m) {
243
        i['GoogleAnalyticsObject'] = r;
244
        i[r] = i[r] || function () {
245
                (i[r].q = i[r].q || []).push(arguments)
246
            }, i[r].l = 1 * new Date();
247
        a = s.createElement(o),
248
            m = s.getElementsByTagName(o)[0];
249
        a.async = 1;
250
        a.src = g;
251
        m.parentNode.insertBefore(a, m)
252
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
253
254
    ga('create', 'UA-27015911-4', 'auto');
255
    ga('send', 'pageview');
256
</script>
257
258
</body>
259
</html>