Skip to content

Commit 9ca7867

Browse files
committed
2 parents 63f2559 + b93124c commit 9ca7867

File tree

6 files changed

+45
-17
lines changed

6 files changed

+45
-17
lines changed

config/server.conf

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
server
22
{
3-
listen 8001;
3+
listen 80;
44

55
host 127.0.0.1;
66
client_max_body_size 100;
7-
7+
server_name hhjdsghj dsfsdfda dfdsfsdf;
88

99
error_page 404 www/html/error_pages/404.html;
1010
error_page 403 www/html/error_pages/403.html;
@@ -24,11 +24,12 @@ server
2424
{
2525
root ./www/html/cgi_bin;
2626
allow_Methods GET;
27+
allow_Methods POST;
2728
index hello.html;
28-
# path_info .py /usr/bin/python3;
29-
# path_info .php /php-cgi;
30-
# #listen 8001;
31-
autoindex off;
29+
path_info .py /usr/bin/python3;
30+
path_info .php /php-cgi;
31+
# listen 8001;
32+
#autoindex on;
3233
}
3334

3435
location /red
@@ -123,7 +124,7 @@ server
123124

124125
# server
125126
# {
126-
# listen 8001;
127+
# listen 8002;
127128

128129
# host 127.0.0.1;
129130
# client_max_body_size 10000000;
@@ -205,8 +206,4 @@ server
205206

206207
# }
207208

208-
209-
210-
211-
212209
# }

include/sockets.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: yismaili <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/03/27 15:29:15 by yismaili #+# #+# */
9-
/* Updated: 2023/05/22 22:13:50 by yismaili ### ########.fr */
9+
/* Updated: 2023/05/24 14:46:10 by yismaili ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

respond/method_handling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: aoumad <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/09 17:52:50 by aoumad #+# #+# */
9-
/* Updated: 2023/05/24 16:04:10 by aoumad ### ########.fr */
9+
/* Updated: 2023/05/24 16:07:00 by aoumad ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

server/http_server.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: aoumad <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/04 18:41:23 by yismaili #+# #+# */
9-
/* Updated: 2023/05/24 15:59:43 by aoumad ### ########.fr */
9+
/* Updated: 2023/05/24 16:07:27 by aoumad ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -137,7 +137,6 @@ namespace http{
137137
clients.push_back(server_pollfd);
138138
it++;
139139
}
140-
141140
while (true)
142141
{
143142
i = 0;

server/sockets.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: yismaili <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/04 18:41:42 by yismaili #+# #+# */
9-
/* Updated: 2023/05/22 22:48:44 by yismaili ### ########.fr */
9+
/* Updated: 2023/05/24 14:56:46 by yismaili ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -96,6 +96,7 @@ namespace http{
9696
bool sockets::start_server()
9797
{
9898
int optval;
99+
static int check_port = 0;
99100

100101
optval = 1; //enabling the SO_REUSEADDR socket option.
101102
// Creates a TCP socket
@@ -118,11 +119,16 @@ namespace http{
118119
fcntl(sockfd, F_SETFL, O_NONBLOCK);
119120

120121
//bind a socket with a specific address and port number
121-
if (bind(sockfd, result->ai_addr, result->ai_addrlen) == 0)
122+
int ret_bind = bind(sockfd, result->ai_addr, result->ai_addrlen);
123+
if (ret_bind == 0)
122124
{
123125
// F_SETFL: This flag indicates that we want to set the file status flags.
126+
check_port++;
124127
std::cout << "\n\033[32mLISTENING ON ["<<port<<"]...\033[0m\n";
125128
}
129+
else if (ret_bind == -1 && check_port == 0){
130+
std::cout << "\033[31mthis ["<<port<<"] port is used\033[0m\n";
131+
}
126132
// Set socket to listen
127133
if (listen(sockfd, SOMAXCONN) < 0){
128134
// The backlog argument defines the maximum length to which the queue of pending connections for sockfd may grow

www/html/upload/getfile.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
$dir = "uploads/";
3+
$allowed_exts = array("pdf", "mp4", "png", "jpg");
4+
5+
// Loop through the directory and find files with allowed extensions
6+
$files = array();
7+
if (is_dir($dir)) {
8+
if ($dh = opendir($dir)) {
9+
while (($file = readdir($dh)) !== false) {
10+
$ext = pathinfo($file, PATHINFO_EXTENSION);
11+
if (in_array($ext, $allowed_exts)) {
12+
$files[] = $file;
13+
}
14+
}
15+
closedir($dh);
16+
}
17+
}
18+
// Display the files in a table
19+
echo "<table>";
20+
foreach ($files as $file) {
21+
echo "<tr>";
22+
echo "<td><a href='$dir$file' target='_blank'>$file</a></td>";
23+
echo "</tr>";
24+
}
25+
echo "</table>";
26+
?>

0 commit comments

Comments
 (0)