Skip to content

Commit c739d7b

Browse files
committed
Fixed cURL error 7 on proxied server
1 parent 3381efa commit c739d7b

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

resources/views/layouts/sidebar.blade.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,26 @@ function has_sslsb( $domain ) {
7474
$actual_linksb = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
7575
}
7676
77+
function getUrlSatusCodesb($urlsb, $timeoutsb = 3)
78+
{
79+
$chsb = curl_init();
80+
$optssb = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
81+
CURLOPT_URL => $urlsb,
82+
CURLOPT_NOBODY => true, // do a HEAD request only
83+
CURLOPT_TIMEOUT => $timeoutsb);
84+
curl_setopt_array($chsb, $optssb);
85+
curl_exec($chsb);
86+
$status = curl_getinfo($chsb, CURLINFO_HTTP_CODE);
87+
curl_close($chsb);
88+
return $status;
89+
}
90+
7791
// Files or directories to test if accessible externally
78-
$url1sb = Http::get($actual_linksb . '/../../.env');
79-
$url2sb = Http::get($actual_linksb . '/../../database/database.sqlite');
92+
$url1sb = getUrlSatusCodesb($actual_linksb . '/../../.env');
93+
$url2sb = getUrlSatusCodesb($actual_linksb . '/../../database/database.sqlite');
8094
8195
// sets compromised to true if config files got compromised
82-
if ($url1sb->successful() or $url2sb->successful()) {
96+
if($url1sb == '200' or $url2sb == '200') {
8397
$compromised = "true";
8498
} else {
8599
$compromised = "false";
@@ -223,9 +237,9 @@ function has_sslsb( $domain ) {
223237
@elseif(env('NOTIFY_UPDATES') == 'true' or env('NOTIFY_UPDATES') === 'major' or env('NOTIFY_UPDATES') === 'all')
224238
<?php // Checks if URL exists
225239
try {
226-
function URL_exists(string $url): bool
240+
function URL_exists(string $urlsb): bool
227241
{
228-
return str_contains(get_headers($url)[0], "200 OK");
242+
return str_contains(get_headers($urlsb)[0], "200 OK");
229243
}
230244
// Sets $ServerExists to true if URL exists
231245
if (URL_exists("https://julianprieber.github.io/littlelink-custom/version.json")){
@@ -283,9 +297,9 @@ function URL_exists(string $url): bool
283297
<! –– #### begin event detection #### ––>
284298
<?php
285299
try {
286-
function URL_event_exists(string $url): bool
300+
function URL_event_exists(string $urlsb): bool
287301
{
288-
return str_contains(get_headers($url)[0], "200 OK");
302+
return str_contains(get_headers($urlsb)[0], "200 OK");
289303
}
290304
if (URL_event_exists("https://julianprieber.github.io/littlelink-custom-events/event.json")){
291305
$EventServerExists = "true";

resources/views/panel/diagnose.blade.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
1111
$utrue = "<td style=\"text-align: center; cursor: help;\" title=\"Your security is at risk. This file can be accessed by everyone. Immediate action is required!\">❗</td>";
1212
$ufalse = "<td style=\"text-align: center; cursor: help;\" title=\"Everything is working as expected!\">✔️</td>";
13+
$unull = "<td style=\"text-align: center; cursor: help;\" title=\"Something went wrong. This might be normal if you're running behind a proxy or docker container.\">➖</td>";
14+
1315
1416
$server = $_SERVER['SERVER_NAME'];
1517
$uri = $_SERVER['REQUEST_URI'];
@@ -29,21 +31,33 @@ function has_ssl( $domain ) {
2931
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
3032
}
3133
34+
function getUrlSatusCode($url, $timeout = 3)
35+
{
36+
$ch = curl_init();
37+
$opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
38+
CURLOPT_URL => $url,
39+
CURLOPT_NOBODY => true, // do a HEAD request only
40+
CURLOPT_TIMEOUT => $timeout);
41+
curl_setopt_array($ch, $opts);
42+
curl_exec($ch);
43+
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
44+
curl_close($ch);
45+
return $status;
46+
}
3247
3348
//Files or directories to test if writable
3449
$wrt1 = is_writable('.env');
3550
$wrt2 = is_writable('database/database.sqlite');
3651
3752
//Files or directories to test if accessible externally
38-
$url1 = Http::get($actual_link . '/../../.env');
39-
$url2 = Http::get($actual_link . '/../../database/database.sqlite');
40-
53+
$url1 = getUrlSatusCode($actual_link . '/../../.env');
54+
$url2 = getUrlSatusCode($actual_link . '/../../database/database.sqlite');
4155
4256
?>
4357

4458
<h2 class="mb-4"><i class="bi bi-braces-asterisk"> Debugging information</i></h2>
4559

46-
@if($url1->successful() or $url2->successful())
60+
@if($url1 == '200' or $url2 == '200')
4761
<a href="https://docs.littlelink-custom.com/d/installation-requirements/" target="_blank"><h4 style="color:tomato;">Your security is at risk. Some files can be accessed by everyone. Immediate action is required! <br> Click this message to learn more.</h4></a>
4862
@endif
4963

@@ -83,11 +97,11 @@ function has_ssl( $domain ) {
8397
<tbody>
8498
<tr>
8599
<td title="">{{ url('/.env') }}</td>
86-
<?php if ($url1->successful()) {echo "$utrue";} else {echo "$ufalse";} ?>
100+
<?php if($url1 == '200'){echo "$utrue";} elseif($url1 == '0'){echo "$unull";} else{echo "$ufalse";} ?>
87101
</tr>
88102
<tr>
89103
<td title="">{{ url('/database/database.sqlite') }}</td>
90-
<?php if ($url2->successful()) {echo "$utrue";} else {echo "$ufalse";} ?>
104+
<?php if($url2 == '200'){echo "$utrue";} elseif($url2 == '0'){echo "$unull";} else{echo "$ufalse";} ?>
91105
</tr>
92106
</tbody>
93107
</table>

0 commit comments

Comments
 (0)