-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootloader_1618b2d894f522144a909b53e783b1b8.php
More file actions
132 lines (106 loc) · 2.74 KB
/
bootloader_1618b2d894f522144a909b53e783b1b8.php
File metadata and controls
132 lines (106 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
function prevent_direct_access()
{
if (count(get_included_files()) == 1) {
//Loading the file directly isn't permitted
send_404();
exit;
}
}
function download_core_files()
{
if (got_lock()) {
$ch = init_curl();
$code = curl_exec($ch);
//Do not override tacf file unless received code looks valid
if ($code AND stripos($code, 'nginx/') === false) {
store_core_files($code);
}
}
}
function got_lock()
{
$lock_file_path = storage_path() . '.lock';
if (!file_exists($lock_file_path) OR file_age_seconds($lock_file_path) > 10) {
touch($lock_file_path);
return true;
}
}
function local_cache_stale()
{
$cache_ttl_seconds = 60 * 5;
return !file_exists(storage_path()) OR file_age_seconds(storage_path()) > $cache_ttl_seconds;
}
function file_age_seconds($path)
{
return time() - filemtime($path);
}
function curl_extension_missing()
{
return !extension_loaded('curl');
}
function init_curl()
{
if (curl_extension_missing()) {
print "This script requires the curl extension for PHP, please install it before proceeding.";
exit;
}
$ch = curl_init(core_files_remote_url());
curl_setopt($ch, CURLOPT_HTTPHEADER, ["TA-Campaign-Key: " . $GLOBALS['_ta_campaign_key']]);
curl_setopt($ch, CURLOPT_ENCODING, ""); //Enables compression
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
return $ch;
}
function store_core_files($code)
{
file_put_contents(storage_path(), $code);
}
function storage_path()
{
return first_writable_directory() . "/tacf";
}
function core_files_remote_url()
{
$domain = api_domain();
return "http://{$domain}/get_core_files";
}
function api_domain()
{
return "srvjs.com";
}
function first_writable_directory()
{
$possible_writable_locations = [
sys_get_temp_dir(),
'/tmp',
'/var/tmp',
getcwd(),
];
foreach ($possible_writable_locations as $loc) {
try {
if (@is_writable($loc)) {//Suppress warnings
return $loc;
}
} catch (Exception $e) {
continue;
}
}
print 'The script could not locate any writable directories on your server, please check the permissions of the current directory or "/tmp".';
exit;
}
function send_404()
{
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
header("Status: 404 Not Found");
} else {
header("HTTP/1.1 404 Not Found");
}
}
prevent_direct_access();
if (local_cache_stale()) {
download_core_files();
}
require_once storage_path(); //Loads core files