This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
238 lines (204 loc) · 8.21 KB
/
index.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
// ======================================
//
// Fried Fame VPN Engine
// Created by Eithan
//
// https://github.com/eithan1231/fried-fame
// https://eithan.me/
//
// \index.php
//
// ======================================
date_default_timezone_set('UTC');
header_remove('x-powered-by');
ini_set('display_errors', 0);
// Main includes.
require_once __DIR__ .'/constants.php';
require_once FF_LIB_DIR .'/autoloader.php';
autoloader::load('functions');
handlers_exception::register();
handlers_error::register();
$ff_config = new config(FF_WORK_DIR .'/config.php');
$ff_request = new request();
$ff_response = new response();
$ff_sql = new sql(
$ff_config->get('mysql.username'),
$ff_config->get('mysql.password'),
$ff_config->get('mysql.hostname'),
$ff_config->get('mysql.database')
);
$ff_router = new router($ff_config->get('work-url'));
// Registering all routes.
$ff_router->registerSpecial('404', new routes_special_404());
$ff_router->registerSpecial('db', new routes_special_db());
$ff_router->register(new routes_asset());
$ff_router->register(new routes_landing());
$ff_router->register(new routes_manifest());
$ff_router->register(new routes_tos());
$ff_router->register(new routes_pp());
$ff_router->register(new routes_login());
$ff_router->register(new routes_register());
$ff_router->register(new routes_recovery());
$ff_router->register(new routes_post());
$ff_router->register(new routes_emailverif());
$ff_router->register(new routes_mlt());// Mailing List Terms
$ff_router->register(new routes_redirect());
$ff_router->register(new routes_containers_landing());
$ff_router->register(new routes_robots());
$ff_router->register(new routes_contact());
$ff_router->register(new routes_badpages());
$ff_router->register(new routes_credits());
$ff_router->register(new routes_ping());// Used for status page
$ff_router->register(new routes_status());
$ff_router->register(new routes_sitemap());
$ff_router->register(new routes_faq());
// internal api endpoints
$ff_router->register(new routes_internalapi_ffrpc_new());
$ff_router->register(new routes_internalapi_ffrpc_list());
// Documentation / Knowledge Base
$ff_router->register(new routes_knowbase_landing());
$ff_router->register(new routes_knowbase_category());
$ff_router->register(new routes_knowbase_article());
// User CP pages
$ff_router->register(new routes_cp_landing());
$ff_router->register(new routes_cp_additionalauth());
$ff_router->register(new routes_cp_reauth());
$ff_router->register(new routes_cp_settings());
$ff_router->register(new routes_cp_settings_email());
$ff_router->register(new routes_cp_settings_password());
$ff_router->register(new routes_cp_history_email());
$ff_router->register(new routes_cp_history_password());
$ff_router->register(new routes_cp_support_new());
$ff_router->register(new routes_cp_support_view());
$ff_router->register(new routes_cp_support_landing());
$ff_router->register(new routes_cp_payments_method());
$ff_router->register(new routes_cp_payments_view());
$ff_router->register(new routes_cp_payments_list());
$ff_router->register(new routes_cp_payments_plans());
$ff_router->register(new routes_cp_giftcard());
$ff_router->register(new routes_cp_announcements());
$ff_router->register(new routes_cp_package_download());
$ff_router->register(new routes_cp_review());
// CP Installation Guides
$ff_router->register(new routes_cp_install_landing());
$ff_router->register(new routes_cp_install_ios());
$ff_router->register(new routes_cp_install_android());
$ff_router->register(new routes_cp_install_windows());
$ff_router->register(new routes_cp_install_osx());
$ff_router->register(new routes_cp_install_linux());
// Control panel payment processing
$ff_router->register(new routes_cp_payments_paypal_cancel());
$ff_router->register(new routes_cp_payments_paypal_success());
// Mod items within CP page..
$ff_router->register(new routes_cp_mod_audit());
$ff_router->register(new routes_cp_mod_feedback());
$ff_router->register(new routes_cp_mod_language_edit());
$ff_router->register(new routes_cp_mod_language_list());
$ff_router->register(new routes_cp_mod_language_new());
$ff_router->register(new routes_cp_mod_language_outdated());
$ff_router->register(new routes_cp_mod_language_unfound());
$ff_router->register(new routes_cp_mod_user_landing());
$ff_router->register(new routes_cp_mod_user_find());
$ff_router->register(new routes_cp_mod_user_manage());
$ff_router->register(new routes_cp_mod_group_landing());
$ff_router->register(new routes_cp_mod_support_list());
$ff_router->register(new routes_cp_mod_support_view());
$ff_router->register(new routes_cp_mod_giftcard());
$ff_router->register(new routes_cp_mod_ffrpc_landing());
$ff_router->register(new routes_cp_mod_ffrpc_new());
$ff_router->register(new routes_cp_mod_announcement());
$ff_router->register(new routes_cp_mod_package_new());
$ff_router->register(new routes_cp_mod_package_landing());
$ff_router->register(new routes_cp_mod_nodes_landing());
$ff_router->register(new routes_cp_mod_nodes_manage());
$ff_router->register(new routes_cp_mod_nodes_new());
$ff_router->register(new routes_cp_mod_review());
$ff_router->register(new routes_cp_mod_internalapi_new());
$ff_router->register(new routes_cp_mod_internalapi_list());
$ff_router->register(new routes_cp_mod_internalapi_edit());
// WinNative
$ff_router->register(new routes_containers_winnative_api_list());
$ff_router->register(new routes_containers_winnative_api_context());
$ff_router->register(new routes_containers_winnative_api_connect());
$ff_router->register(new routes_containers_winnative_api_authenticate());
$ff_router->register(new routes_containers_winnative_api_openvpnconfig());
// NixNative
$ff_router->register(new routes_containers_nixnative_api_list());
$ff_router->register(new routes_containers_nixnative_api_context());
$ff_router->register(new routes_containers_nixnative_api_connect());
$ff_router->register(new routes_containers_nixnative_api_authenticate());
$ff_router->register(new routes_containers_nixnative_api_openvpnconfig());
// Payments
$ff_router->register(new routes_payments_gateways_paypal_ipn());
$ff_router->register(new routes_payments_gateways_paypal_redirect());
if($ff_sql->connect()) {
// Creating FF context (requires MySQL)
$ff_context = new context();
// At the end of this block of code, we may not want to run the router, as
// we may be printing output without it.
$runRouter = true;
// Check errors
$errors = $ff_request->check();
if(count($errors) > 0) {
$runRouter = false;
$ff_response->setHttpStatus(400);
$ff_response->setHttpHeader('Content-type', 'text/plain');
$ff_response->appendBody('Errors Experienced:');
foreach ($errors as $error) {
$ff_response->appendBody("\n$error");
// Log error to log file
$ff_context->getLogger()->error("Error: $error", $error);
}
}
// HTTP Upgrade
if(
$ff_config->get('secure-server') &&
$ff_request->getHeader('upgrade-insecure-requests') == '1' &&
!$ff_request->isSecure()
) {
$runRouter = false;
$redirectPath = "https://{$ff_request->getHeader('host')}{$ff_request->getPath()}";
if(strlen($ff_request->getQuery()) > 0) {
$redirectPath .= '?'. $ff_request->getQuery();
}
$ff_response->redirect($redirectPath);
}
// Hostname redirect
$hostnameRedirects = $ff_config->get('hostname-redirects');
$httpHostHeader = $ff_request->getHeader('host');
if(isset($hostnameRedirects[$httpHostHeader])) {
$runRouter = false;
$redirectPath = "//{$hostnameRedirects[$httpHostHeader]}{$ff_request->getPath()}";
if($ff_request->getQuery()) {
$redirectPath .= '?'. $ff_request->getQuery();
}
$ff_response->redirect($redirectPath);
}
// run routes.
if ($runRouter) {
$ff_router->run();
}
}
// Finishing off the response.
$ff_response->setHttpHeader(
'X-Memory-Usage',
ff_getSizeAsVisual(memory_get_peak_usage())
);
$ff_response->setHttpHeader(
'X-Duration',
strval(round((microtime(true) - FF_MICROTIME) * 1000, 2)) .'ms'
);
$ff_response->setHttpHeader(
'X-Powered-By',
'github:eithan1231/fried-fame'
);
$ff_response->setHttpHeader('X-Query-Count', $ff_sql->queryCount());
$ff_response->setHttpHeader('X-UA-Compatible', 'IE=edge');
$ff_response->setHttpHeader('X-Frame-Options', 'sameorigin');
$ff_response->setHttpHeader('X-Request-Id', FF_REQUEST_ID);
$ff_response->flush();
// Saving log
if(isset($ff_context)) {
$ff_context->getLogger()->commit();
}