Skip to content

Commit bae547a

Browse files
author
Younes Ismaili
committed
webserv is finished
1 parent 26336af commit bae547a

18 files changed

+366
-153
lines changed

CGI/cgi.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::string run_cgi(request &r, Respond &res, std::vector<server> server)
109109
free_all(file, path,envp, env.size());
110110
return res.get_response_status(res.get_status_code());
111111
}
112-
alarm(1);
112+
alarm(2);
113113
execve(cmd[0], cmd, envp);
114114
exit(1);
115115
}
@@ -123,12 +123,11 @@ std::string run_cgi(request &r, Respond &res, std::vector<server> server)
123123
return res.get_response_status(res.get_status_code());
124124
}
125125
char buf[1];
126-
std::string content;
127126
int byt;
127+
std::string content;
128128
std::rewind(temp);
129-
while ((byt = read(fdtemp, buf, 1)) > 0){
129+
while ((byt = read(fdtemp, buf, 1)) > 0)
130130
content.append(buf, 1);
131-
}
132131
if (byt == -1)
133132
{
134133
res.set_status_code(500);

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NAME = webserv
22
CC = c++
3-
CFLAGS = -Wall -Wextra -Werror -std=c++98 #-g -fsanitize=address
3+
CFLAGS = -Wall -Wextra -Werror -std=c++98 -g -fsanitize=address
44
SRCS = prs_rsc/main.cpp prs_rsc/server.cpp prs_rsc/location.cpp prs_rsc/server_utils.cpp \
55
request/request.cpp request/request_utils.cpp respond/respond.cpp respond/respond_root.cpp respond/pairs_def.cpp respond/method_utils.cpp \
66
respond/method_handling.cpp CGI/cgi.cpp server/sockets.cpp server/http_server.cpp

config/server.conf

+91-69
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
server
1+
server
22
{
3-
listen 8001;
3+
listen 8002;
44

55
host 127.0.0.1;
6-
client_max_body_size 10000000;
7-
root ./www/html;
8-
server_name localhost;
9-
server_name listen;
10-
6+
client_max_body_size 100;
7+
server_name hhjdsghj dsfsdfda dfdsfsdf;
8+
119
error_page 404 www/html/error_pages/404.html;
1210
error_page 403 www/html/error_pages/403.html;
1311
error_page 409 www/html/error_pages/409.html;
@@ -19,24 +17,24 @@ server
1917
index index.html;
2018

2119
location / {
22-
autoindex on;
20+
autoindex off;
2321
}
2422

2523
location /cgi_bin
2624
{
27-
2825
root ./www/html/cgi_bin;
29-
allow_Methods GET POST;
26+
allow_Methods GET;
27+
allow_Methods POST;
3028
index hello.html;
3129
path_info .py /usr/bin/python3;
3230
path_info .php /php-cgi;
33-
#listen 8001;
34-
autoindex on;
31+
# listen 8001;
32+
#autoindex on;
3533
}
3634

3735
location /red
3836
{
39-
return 400 https://www.youtube.com/watch?v=fhdX3Wcxwas&t=2768s&ab_channel=BGMGhibliStudio;
37+
return 301 http://localhost:8002/;
4038
}
4139

4240
location /delete {
@@ -52,78 +50,77 @@ server
5250
allow_methods POST GET;
5351
upload on;
5452
upload_store ./www/html/upload;
53+
#autoindex on;
5554
}
5655

5756
location /getto {
5857
root ./www/html/upload;
59-
index video.mp4;
58+
# index video.mp4;
6059
allow_methods GET;
61-
autoindex off;
60+
autoindex on;
6261
}
6362
}
63+
# server
64+
# {
65+
# listen 8002;
6466

65-
server
66-
{
67-
listen 8001;
68-
69-
host 127.0.0.1;
70-
client_max_body_size 10000000;
71-
root ./www/html;
72-
server_name localhostp;
73-
error_page 404 www/html/error_pages/404.html;
74-
error_page 403 www/html/error_pages/403.html;
75-
error_page 409 www/html/error_pages/409.html;
76-
error_page 400 www/html/error_pages/400.html;
77-
error_page 405 www/html/error_pages/405.html;
78-
error_page 413 www/html/error_pages/413.html;
79-
error_page 500 www/html/error_pages/500.html;
67+
# host 127.0.0.1;
68+
# client_max_body_size 10000000;
69+
# root ./www/html;
70+
# server_name localhostp;
71+
# error_page 404 www/html/error_pages/404.html;
72+
# error_page 403 www/html/error_pages/403.html;
73+
# error_page 409 www/html/error_pages/409.html;
74+
# error_page 400 www/html/error_pages/400.html;
75+
# error_page 405 www/html/error_pages/405.html;
76+
# error_page 413 www/html/error_pages/413.html;
77+
# error_page 500 www/html/error_pages/500.html;
8078

81-
index index.html;
79+
# index index.html;
8280

83-
location / {
84-
autoindex on;
85-
}
81+
# location / {
82+
# autoindex on;
83+
# }
8684

87-
location /cgi_bin
88-
{
85+
# location /cgi_bin
86+
# {
8987

90-
root ./www/html;
91-
allow_Methods GET POST;
92-
index hello.html;
93-
path_info .py /usr/bin/python3;
94-
path_info .php /php-cgi;
95-
#listen 8001;
96-
#autoindex on;
97-
}
98-
99-
location /red
100-
{
101-
return 301 https://www.youtube.com/watch?v=_Nbm2yn8WA8&t=30s;
102-
}
88+
# root ./www/html;
89+
# allow_Methods GET POST;
90+
# index hello.html;
91+
# path_info .py /usr/bin/python3;
92+
# path_info .php /php-cgi;
93+
# #listen 8001;
94+
# #autoindex on;
95+
# }
10396

104-
location /delete {
105-
root ./www/html/delete;
106-
allow_methods DELETE;
107-
index todelete;
108-
path_info .py /usr/bin/python3;
109-
}
97+
# location /red
98+
# {
99+
# return 301 https://www.youtube.com/watch?v=_Nbm2yn8WA8&t=30s;
100+
# }
110101

111-
location /upload{
112-
root ./www/html/upload;
113-
index upload.html;
114-
allow_methods POST GET;
115-
upload on;
116-
upload_store /upload;
117-
}
102+
# location /delete {
103+
# root ./www/html/delete;
104+
# allow_methods DELETE;
105+
# index todelete;
106+
# path_info .py /usr/bin/python3;
107+
# }
118108

119-
location /getto {
120-
root ./www/html/upload;
121-
index vid.mp4;
122-
allow_methods GET;
123-
autoindex off;
124-
}
125-
}
109+
# location /upload{
110+
# root ./www/html/upload;
111+
# index upload.html;
112+
# allow_methods POST GET;
113+
# upload on;
114+
# upload_store /upload;
115+
# }
126116

117+
# location /getto {
118+
# root ./www/html/upload;
119+
# index vid.mp4;
120+
# allow_methods GET;
121+
# autoindex off;
122+
# }
123+
# }
127124

128125
# server
129126
# {
@@ -188,4 +185,29 @@ server
188185
# allow_methods GET;
189186
# autoindex off;
190187
# }
188+
# }
189+
190+
191+
192+
# server
193+
# {
194+
# listen 8001 8001 5000 5000;
195+
196+
# client_max_body_size 100;
197+
198+
199+
# server_name localhost;
200+
201+
202+
203+
# index index.html;
204+
# location / {
205+
206+
207+
# }
208+
209+
210+
211+
212+
191213
# }

index.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Your Website Title</title>
5+
<style>
6+
body {
7+
font-family: Arial, sans-serif;
8+
margin: 0;
9+
padding: 0;
10+
background-color: #f1f1f1;
11+
}
12+
.container {
13+
max-width: 800px;
14+
margin: 0 auto;
15+
padding: 20px;
16+
background-color: #ffffff;
17+
border-radius: 10px;
18+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
19+
}
20+
h1 {
21+
text-align: center;
22+
color: #333333;
23+
}
24+
p {
25+
color: #555555;
26+
line-height: 1.5;
27+
}
28+
.cta-button {
29+
display: inline-block;
30+
padding: 12px 24px;
31+
background-color: #007bff;
32+
color: #ffffff;
33+
font-size: 16px;
34+
text-decoration: none;
35+
border-radius: 5px;
36+
transition: background-color 0.3s ease;
37+
}
38+
.cta-button:hover {
39+
background-color: #0056b3;
40+
}
41+
</style>
42+
</head>
43+
<body>
44+
<div class="container">
45+
<h1>Welcome to our WEBSERVER!</h1>
46+
<p>This is the main page of our web server.</p>
47+
<p class="message">This is the default page for my website. Start exploring by clicking the button below.</p>
48+
<a class="cta-button" href="/start.html">Get Started</a>
49+
</div>
50+
51+
</body>
52+
</html>
53+

prs_rsc/location.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ std::string extract_path(std::string location_name)
66
{
77
if (!isspace(location_name[i]))
88
break;
9-
pos++;
9+
pos++;
1010
}
1111
int start = pos;
1212
size_t i;
@@ -55,8 +55,8 @@ location::~location()
5555

5656
void location::fill_rest(server &s)
5757
{
58-
// if (_index.empty())
59-
// _index = s.get_index();
58+
if (!_client_max_body_size)
59+
_client_max_body_size = s.get_client_max_body_size();
6060
if (_root.empty())
6161
_root = s.get_root();
6262
if(_error_page.empty())

0 commit comments

Comments
 (0)