Skip to content

Commit 67bff06

Browse files
committed
NEW REALLY BIG UPDATE
1 parent c8e913f commit 67bff06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2966
-110
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,26 @@ Main | Attachments
9494
- черный/белый список ников? (опционально, пыха, жс)
9595
- черный/белый список адресов? (опционально, пыха, жс)
9696
- скрипт для калибровки бд (бд почистить напрочь, в скрипте будут тестовые данные)
97-
- crud htaccess basic-based система регистрации и логина
97+
98+
- crud htaccess basic-based система регистрации и логина +
9899
- сброс вывода при ошибках базы (если сообщений стало меньше, сделать после реорганизации)
100+
- сделать проверку на пустоту полей, чтобы не выпадала форма
101+
- сделать анимации полей через js (это + к верхней таске)
102+
- сначала бахнуть все проверки на серверные исключения а потом переводить??? <-- после самой разработки всего, сначала сделать рабочий минимум, а эту задачу скинуть в туду +
103+
- жопа с фреймами при авторизации +
104+
- жопа при неудачных попытках авторизации +
105+
- продумать кей-адреса при наличии авторизации +
106+
- на хроме жопа с прокруткой и кнопкой вниз
107+
- оттестировать на 4 пыхе
108+
- доделать вместо алертов на клиенте кастомные формы
109+
- доделать dry run на регистрации?
110+
- доделать алгоритм сообщение дисконнекта, т.к. есть косяк внесения через логаут - нужно будет сделать проверку на наличие юзера в базе (ну и мб другие стандартные и пароль) (+ часто просто не срабатывает) (ВОЗМОЖНО ДЫРА)
111+
- везде проставить таргеты, что возможно поможет избавиться от фреймов +
112+
- сделать потом полный рефакторинг кода, всё раздробить на функции
113+
- исключение при попытке загрузки файла бОльшего размера +
114+
- кодировать все запросы, ответы и креды в base64
115+
- попробовать сделать проверку на фрейм (для хромов по крайней мере) и если в фрейме делать бланк
116+
- проверить возможность регистрации если она выключена, т.к. есть вероятность спама (ВОЗМОЖНО ДЫРА)
99117

100118
<br/>
101119

attachments/index.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
include("../functions/presets.php");
3+
require_once("../functions/presets.php");
44

5-
include("../functions/attachments.php");
5+
require_once("../functions/authentication.php");
66

7-
?>
7+
require_once("../functions/attachments.php");
8+
9+
?>

databases/users.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WwogICAgewogICAgICAgICJsb2dpbiI6ICJiRzluYjNWMCIsCiAgICAgICAgInBhc3N3b3JkIjogIk5URXlNRFJqTkRObU9UUTVNalZsWkRreU56Y3lOak15WVRBNU4ySmtNbVEyTW1NNU9HUXhObU01TWpNNE1XWXlNalpsTlRabVkyTTNNV014TlRaallqRTBNV1poWldJeE5URmpOR1EyWlRCbFptWXlPVFJrTVRRMVlqRm1NRE16WXprMk9HVmpNRGhpWm1FMk9XTmlPVGt4WVRFME1HVTJaVEZpWVRRd05EUT0iCiAgICB9Cl0=

functions/attachments.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ function readableBytes($bytes)
1212

1313
};
1414

15-
include("../functions/presets.php");
15+
require_once("../functions/presets.php");
16+
17+
require_once("../functions/authentication.php");
1618

1719
if ($use_databases_encryption != "true")
1820

@@ -36,7 +38,7 @@ function readableBytes($bytes)
3638

3739
$readable_max_file_size = ini_get("upload_max_filesize");
3840

39-
include("../templates/attachments.html");
41+
require_once("../templates/attachments.html");
4042

4143
for ($i = $total_files-1; $i >= 0; $i--)
4244

@@ -88,7 +90,7 @@ function readableBytes($bytes)
8890

8991
$link = "../functions/download.php?id=$i";
9092

91-
include("../templates/attachments_list.html");
93+
require("../templates/attachments_list.html");
9294

9395
};
9496

functions/authentication.php

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
<?php
2+
3+
require_once("../functions/presets.php");
4+
5+
function throwMessage($throw_code, $throw_message, $json_output, $check_output)
6+
7+
{
8+
9+
require("../functions/presets.php");
10+
11+
if ($check_output == true)
12+
13+
{
14+
15+
if ($json_output == true)
16+
17+
{
18+
19+
$throw_json_message["response"]["error"] = $throw_code;
20+
21+
$throw_json_message["response"]["message"] = $throw_message;
22+
23+
$throw_json_message_encoded = json_encode($throw_json_message, JSON_PRETTY_PRINT);
24+
25+
print($throw_json_message_encoded);
26+
27+
exit();
28+
29+
}
30+
31+
else
32+
33+
{
34+
35+
require_once("../templates/throw.html");
36+
37+
header("refresh:3; url=../login/");
38+
39+
exit();
40+
41+
};
42+
43+
}
44+
45+
else
46+
47+
{
48+
49+
if ($throw_code != 200)
50+
51+
{
52+
53+
require_once("../templates/throw.html");
54+
55+
header("refresh:3; url=../login/");
56+
57+
exit();
58+
59+
};
60+
61+
};
62+
63+
};
64+
65+
if ($use_php_basic_authentication == "true")
66+
67+
{
68+
69+
if ($use_databases_encryption != "true")
70+
71+
{
72+
73+
$users_database = json_decode(base64_decode(file_get_contents($databases_users_path), true), true);
74+
75+
}
76+
77+
else
78+
79+
{
80+
81+
$users_database = json_decode(base64_decode(openssl_decrypt(file_get_contents($databases_users_path), $encryption_cipher, $salt_global.$databases_password.$salt_users, $encryption_options, $encryption_iv), true), true);
82+
83+
};
84+
85+
$total_users = count($users_database);
86+
87+
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
88+
89+
{
90+
91+
header('WWW-Authenticate: Basic realm="Webchat Restricted Area"');
92+
93+
header('${protocol} 401 Unauthorized');
94+
95+
$throw_code = 401;
96+
97+
$throw_message = "You need to be authorized!";
98+
99+
throwMessage($throw_code, $throw_message, $json_output, $check_output);
100+
101+
}
102+
103+
else
104+
105+
{
106+
107+
$login = $_SERVER['PHP_AUTH_USER'];
108+
109+
$password = $_SERVER['PHP_AUTH_PW'];
110+
111+
$json_output = $_GET['json_output'];
112+
113+
$check_output = $_GET['check_output'];
114+
115+
$founded_users_count = 0;
116+
117+
if ($login != null && $login != "" && $password != null && $password != "")
118+
119+
{
120+
121+
if ($login != "logout")
122+
123+
{
124+
125+
for ($i = 0; $i < $total_users; $i++)
126+
127+
{
128+
129+
$decoded_login = base64_decode($users_database[$i][login]);
130+
131+
if ($decoded_login != $login)
132+
133+
{
134+
135+
continue;
136+
137+
}
138+
139+
else
140+
141+
{
142+
143+
$founded_users_count++;
144+
145+
$founded_user_id = $i;
146+
147+
break;
148+
149+
};
150+
151+
};
152+
153+
if ($founded_users_count == 0 || !isset($founded_user_id))
154+
155+
{
156+
157+
$throw_code = 401;
158+
159+
$throw_message = "This user doesn't exists!";
160+
161+
throwMessage($throw_code, $throw_message, $json_output, $check_output);
162+
163+
}
164+
165+
else
166+
167+
{
168+
169+
$hashed_password_input = hash($user_password_hashing_algorithm, $salt_global.$password.$salt_password);
170+
171+
$hashed_password_etalon = base64_decode($users_database[$founded_user_id][password]);
172+
173+
if ($hashed_password_input != $hashed_password_etalon)
174+
175+
{
176+
177+
$throw_code = 401;
178+
179+
$throw_message = "Wrong password!";
180+
181+
throwMessage($throw_code, $throw_message, $json_output, $check_output);
182+
183+
}
184+
185+
else
186+
187+
{
188+
189+
$throw_code = 200;
190+
191+
$throw_message = "Successful login!";
192+
193+
throwMessage($throw_code, $throw_message, $json_output, $check_output);
194+
195+
};
196+
197+
};
198+
199+
}
200+
201+
else
202+
203+
{
204+
205+
$throw_code = 401;
206+
207+
$throw_message = "Logging out!";
208+
209+
throwMessage($throw_code, $throw_message, $json_output, $check_output);
210+
211+
};
212+
213+
}
214+
215+
else
216+
217+
{
218+
219+
$throw_code = 401;
220+
221+
$throw_message = "Fill all forms!";
222+
223+
throwMessage($throw_code, $throw_message, $json_output, $check_output);
224+
225+
};
226+
227+
};
228+
229+
};
230+
231+
?>

functions/download.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
include("../functions/presets.php");
3+
require_once("../functions/presets.php");
4+
5+
require_once("../functions/authentication.php");
46

57
$GETFILEID = $_GET["id"];
68

@@ -50,4 +52,4 @@
5052

5153
header("Location: ../attachments/");
5254

53-
?>
55+
?>

0 commit comments

Comments
 (0)