-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
340 lines (275 loc) · 11.3 KB
/
functions.php
File metadata and controls
340 lines (275 loc) · 11.3 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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
// functions
// include "db.php";
function _http_res($time, $dir){
echo "<meta http-equiv='refresh' content='{$time};url={$dir}'>";
}
function _innerjs($msg){
echo "<script>alert('$msg')</script>";
}
function _document_js($id, $style){
echo "<script>let {$id} = document.getElementById('{$id}');{$id}.style.{$style};</script>";
}
function _innerhtml($msg, $redirect){
echo "
<p>
$msg
<br><br>
<button id='backbtn'>Go Back</button>
</p>
<style>
p {width:100%;max-width:400px;margin:0 auto;margin-top:50px;font-family:sans-serif;text-align:;text-transform:;}
button {text-align:center;width: 150px;padding: 1rem;display:block;background: var(--secondary-color);color: white;border: none;border-radius: 5px;font-size: 1rem;font-weight: 600;cursor: pointer;transition: var(--transition);background: #c0392b;}
button:hover {background: #c0392b;transform: translateY(-2px);transition:0.5s;}
button:not(:hover) {transition:0.5s;}
</style>
<script>
const bkbtn = document.querySelector('#backbtn');
bkbtn.addEventListener('click', function() {
window.location.href='{$redirect}'
})
</script>
";
}
function _pictureHundler($connect, $table, $cssid, $style, $SqlPicture, $SqlPhone){
$picturesql = "select current_profile from {$table} where phone = ?";
$picturesqlq = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($picturesqlq, $picturesql)) {
echo "sql error";
} else {
mysqli_stmt_bind_param($picturesqlq,"s",$SqlPhone);
mysqli_stmt_execute($picturesqlq);
$picturesqlq_result = mysqli_stmt_get_result($picturesqlq);
$picturesqlF = mysqli_fetch_assoc($picturesqlq_result);
}
$pictureVar = $picturesqlF["current_profile"];
$customDesign = "<style>.$cssid{ $style }</style>";
if ($picturesqlF["current_profile"] == "") {
echo "{$customDesign} <img src='assets/img/def.jpg' class='$cssid' alt='defaultprofile'/>";
} else {
echo "{$customDesign} <img src='assets/img/$pictureVar' class='$cssid' alt='$pictureVar'/>";
}
}
function _antiRoot_($connect,$sesPhone){
// anti root
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, "select * from users where phone = ?")) {
session_destroy();
exit();
} else {
mysqli_stmt_bind_param($stmt,"s",$sesPhone);
mysqli_stmt_execute($stmt);
$usercheck_R = mysqli_stmt_get_result($stmt);
}
$usercheck = mysqli_fetch_assoc($usercheck_R);
if (empty($usercheck["phone"])) {
//session_destroy();
_http_res(0,"../login/");
_innerjs("Account deleted");
exit();
}
}
function _fetch_record_number_($connect, $sql_code, $column, $phone){
$stmt = mysqli_stmt_init($connect);
$sql = "select * from ".$sql_code." where {$column} = ?";
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "sql error";
} else {
mysqli_stmt_bind_param($stmt, "s", $phone);
mysqli_stmt_execute($stmt);
$stmt_RES = mysqli_stmt_get_result($stmt);
$stmt_ROWS = mysqli_num_rows($stmt_RES);
return $stmt_ROWS;
}
}
function _fetch_read_file_($connect, $phone, $table, $column_name, $size, $dir){
$stmt_f = mysqli_stmt_init($connect);
$stmt_f_sql = "select {$column_name} from {$table} where phone = ?";
if (!mysqli_stmt_prepare($stmt_f, $stmt_f_sql)) {
echo "something went wrong from [ _fetch_read_file_(); ] function";
} else {
mysqli_stmt_bind_param($stmt_f, "s", $phone);
mysqli_stmt_execute($stmt_f);
$stmt_f_Res = mysqli_stmt_get_result($stmt_f);
$stmt_f_Row = mysqli_num_rows($stmt_f_Res);
$destination = $dir;
for ($i = 1; $i <= $stmt_f_Row; $i++) {
$stmt_f_Fetch = mysqli_fetch_assoc($stmt_f_Res);
$file = $stmt_f_Fetch["{$column_name}"];
if (file_exists("{$destination}{$file}")) {
// echo "{$destination}{$file} available ". $file_size ."mb<br>";
if ($size == "byte"){
if ($stmt_f_Row == 0) {
return $stmt_f_Row;
} else {
$byte_file_size = filesize("{$destination}{$file}");
return $byte_file_size * $stmt_f_Row;
}
} else if ($size=="megabyte") {
if ($stmt_f_Row == 0) {
return $stmt_f_Row;
} else {
$file_size = round(filesize("{$destination}{$file}") / 1024 / 1024, 2);
return $file_size * $stmt_f_Row;
}
}
}
}
}
}
// this function will only work if the _fetch_read_file_(); is mentioned
/*
These two function are there to help count the number of
fetches from the server through the database, and reduce the dublicates of
[ _fetch_read_file_() ] function.
_fetch_total_size_MB_
This function fetches the file allocated in the server using the database
query made and customized by the user and looks for the directory path then
outputs the size of the file or files in megabytes(MB) size
_fetch_total_size_B_
This function fetches the file allocated in the server using the database
query made and customized by the user and looks for the directory path then
outputs the size of the file or files in bytes(B) size
*/
function _fetch_total_size_MB_($connect, $phone, $songTable, $imgTable){
return _fetch_read_file_($connect, $phone, $songTable, "songs", "megabyte","../main/xbin/mp3/users/") +
_fetch_read_file_($connect, $phone, $songTable, "picture", "megabyte","../main/xbin/img/users/") +
_fetch_read_file_($connect, $phone, "businesstable", "pictures", "megabyte","../main/xbin/img/users/business/") +
_fetch_read_file_($connect, $phone, "imagesdump", "image", "megabyte","../main/xbin/img/users/") +
_fetch_read_file_($connect, $phone, "musicdump", "songs", "megabyte","../main/xbin/mp3/users/") +
_fetch_read_file_($connect, $phone, "musicdump", "picture", "megabyte","../main/xbin/img/users/") +
_fetch_read_file_($connect, $phone, $imgTable, "image", "megabyte","../main/xbin/img/users/");
}
function _fetch_total_size_B_($connect, $phone, $songTable, $imgTable){
return _fetch_read_file_($connect, $phone, $songTable, "songs", "byte","../main/xbin/mp3/users/") +
_fetch_read_file_($connect, $phone, $songTable, "picture", "byte","../main/xbin/img/users/") +
_fetch_read_file_($connect, $phone, "businesstable", "pictures", "byte","../main/xbin/img/users/business/") +
_fetch_read_file_($connect, $phone, "imagesdump", "image", "byte","../main/xbin/img/users/") +
_fetch_read_file_($connect, $phone, "musicdump", "songs", "byte","../main/xbin/mp3/users/") +
_fetch_read_file_($connect, $phone, "musicdump", "picture", "byte","../main/xbin/img/users/") +
_fetch_read_file_($connect, $phone, $imgTable, "image", "byte","../main/xbin/img/users/");
}
function ai_delete_folder_($dir){
if (!file_exists($dir)) {
echo "";
}
if (!is_dir($dir)) {
return unlink($dir);
}
foreach ( scandir($dir) as $item ) {
if ($item == '.' || $item == '..') {
continue;
}
if (!ai_delete_folder_($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
return rmdir($dir);
}
function _ajax_($version){
$link = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js";
if (empty($version)) {
echo $link;
} else {
$link = "https://ajax.googleapis.com/ajax/libs/jquery/{$version}/jquery.min.js";
echo $link;
}
}
function _print_($msg){
echo "{$msg}";
}
function _report($connect,$msg){
$time = date("y");
mysqli_query($connect, "insert into tbordinary_reports () values ()");
}
function getClientIP() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
// IP from shared internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// IP passed from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
// Direct IP from remote address
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
// advanced
function _adv_getRealClientIP() {
$ipKeys = [
'HTTP_CF_CONNECTING_IP', // Cloudflare
'HTTP_X_REAL_IP', // Nginx proxy or load balancer
'HTTP_X_FORWARDED_FOR', // Can contain multiple IPs
'HTTP_CLIENT_IP', // Shared internet
'REMOTE_ADDR' // Direct connection
];
foreach ($ipKeys as $key) {
if (!empty($_SERVER[$key])) {
$ipList = explode(',', $_SERVER[$key]); // In case of multiple IPs
$ip = trim($ipList[0]);
// Validate IP format (both IPv4 and IPv6)
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
return $ip;
}
}
}
return 'UNKNOWN';
}
function _error($msg) {
echo "
<script>
let error = document.getElementById('error');
error.innerHTML = '$msg';
error.style.color='white'
error.style.backgroundColor='red'
error.style.padding='10px'
error.style.fontWeight='bold'
error.style.fontSize='15px'
</script>
";
}
function _session_ip_blocker_($connect){
if (isset($_COOKIE["PHPSESSID"])) {
$session_id = $_COOKIE["PHPSESSID"];
$assigned_id = uniqid("",false);
$ip = getClientIP();
$status = "yes";
$check_record_stmt = mysqli_stmt_init($connect);
$check_record_sql = "select visitor_ipaddress from tbvisitors where visitor_ipaddress = ?";
if (mysqli_stmt_prepare($check_record_stmt,$check_record_sql)) {
if (mysqli_stmt_bind_param($check_record_stmt,"s",$ip)) {
if (mysqli_stmt_execute($check_record_stmt)) {
$check_record_result = mysqli_stmt_get_result($check_record_stmt);
if (mysqli_num_rows($check_record_result) < VISITOR_SESSIONAL_ALLOWED) {
$visit_stmt = mysqli_stmt_init($connect);
$visit_sql = "insert into tbvisitors (`assigned_id`,`visitor_session`,`visitor_ipaddress`,`status`) values (?,?,?,?)";
mysqli_stmt_prepare($visit_stmt,$visit_sql);
mysqli_stmt_bind_param($visit_stmt, "ssss", $assigned_id, $session_id, $ip, $status);
mysqli_stmt_execute($visit_stmt);
mysqli_stmt_close($visit_stmt);
} else {
_http_res(0,"block.php?blockedIpAddress=$ip");
exit();
}
}
}
}
// manuel ip block
$checkip_allowed = mysqli_query($connect, "select status, visitor_ipaddress from tbvisitors where status = 'no'"); // == no
$checkip_fetch = mysqli_fetch_assoc($checkip_allowed);
if (mysqli_num_rows($checkip_allowed) > 0) {
if ($ip == $checkip_fetch["visitor_ipaddress"]) {
_http_res(0, "block.php?blockedIpAddress=$ip");
}
}
// automatic ip block
$autoip_q = mysqli_query($connect, "select visitor_ipaddress from tbvisitors where visitor_ipaddress = '$ip'");
if (mysqli_num_rows($autoip_q) > 19) {
mysqli_query($connect, "update tbvisitors set status = 'no' where visitor_ipaddress = '$ip'");
_http_res(0,"block.php?blockedIpAddress=$ip");
}
} else {
echo "reload this page.";
}
}