Skip to content

Commit 026b2c3

Browse files
author
Younes Ismaili
committed
create error page
2 parents 07c255c + 5b72478 commit 026b2c3

21 files changed

+405
-110
lines changed

CGI/cgi.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void set_headers_cgi(std::string output, Respond &res) {
9494

9595
put_cookie(output, res);
9696
while (std::getline(ss, line)) {
97-
if (line.empty()) {
97+
if (line == "\r") {
9898
headers_finished = true;
9999
continue;
100100
}
@@ -105,10 +105,12 @@ void set_headers_cgi(std::string output, Respond &res) {
105105
std::string value = line.substr(pos + 2);
106106
if(key != "Set-Cookie")
107107
res.set_header(key, value);
108-
//puts("heeeeere");
109108
}
110-
} else {
111-
body += line;
109+
}
110+
else
111+
{
112+
std::cout << line << "\n";
113+
body += line + "\n";
112114
}
113115
}
114116
res.set_response_body(body);
@@ -117,11 +119,11 @@ void set_headers_cgi(std::string output, Respond &res) {
117119

118120
std::string run_cgi(request &r, Respond &res)
119121
{
120-
// puts("heeeeeeeeerererere");
122+
puts("heeeeeeeeerererere");
121123
char *file, *path;
122124
file = strdup(res.get_file_cgi().c_str());
123125
path = strdup(res.get_path_info_founded().c_str());
124-
//std::cout << path << " " << file << std::endl;
126+
std::cout << path << " " << file << std::endl;
125127
char *cmd[3] = {path, file, NULL};
126128

127129
std::string cgi_str;
@@ -202,7 +204,9 @@ std::string run_cgi(request &r, Respond &res)
202204
close(fdtemp1);
203205

204206
//put_cookie(content, res);
207+
std::cout << "Content :::::::::::\n" << content << std::endl;
205208
set_headers_cgi(content, res);
209+
std::cout << "body :: \n" << res.get_response_body() << std::endl;
206210
//std::cout << content << std::endl;
207211
return (content);
208212
}

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
4+
CFLAGS = -Wall -Wextra -Werror -std=c++98
45
SRCS = prs_rsc/main.cpp prs_rsc/server.cpp prs_rsc/location.cpp prs_rsc/server_utils.cpp \
56
request/request.cpp request/request_utils.cpp respond/respond.cpp respond/respond_root.cpp respond/pairs_def.cpp respond/method_utils.cpp \
67
respond/method_handling.cpp CGI/cgi.cpp server/sockets.cpp server/http_server.cpp

errorPage/403.html

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>403 Forbidden</title>
5+
<style>
6+
body {
7+
font-family: Arial, sans-serif;
8+
margin: 0;
9+
padding: 0;
10+
background-color: hwb(201 90% 5%);
11+
}
12+
.container {
13+
max-width: 800px;
14+
margin: 0 auto;
15+
text-align: center;
16+
padding: 100px 20px;
17+
}
18+
h1 {
19+
font-size: 48px;
20+
margin-bottom: 20px;
21+
color: #333;
22+
}
23+
p {
24+
font-size: 24px;
25+
color: #777;
26+
margin-bottom: 40px;
27+
}
28+
a {
29+
font-size: 18px;
30+
color: #777;
31+
text-decoration: none;
32+
border-bottom: 1px solid #ccc;
33+
padding-bottom: 2px;
34+
}
35+
a:hover {
36+
color: #333;
37+
border-bottom: 1px solid #333;
38+
}
39+
</style>
40+
</head>
41+
<body>
42+
<div class="container">
43+
<h1>403 Forbidden</h1>
44+
<p>You do not have permission to access this resource.</p>
45+
<a href="#">Go back to homepage</a>
46+
</div>
47+
</body>
48+
</html>
49+

errorPage/404.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>404 Error - Page Not Found</title>
5+
<style>
6+
body {
7+
background-color: hwb(201 90% 5%);
8+
color: rgb(0, 0, 0);
9+
font-family: Arial, sans-serif;
10+
text-align: center;
11+
padding: 50px;
12+
}
13+
14+
h1 {
15+
font-size: 50px;
16+
margin-top: 0;
17+
}
18+
19+
p {
20+
font-size: 20px;
21+
}
22+
</style>
23+
</head>
24+
<body>
25+
<h1>404 Error</h1>
26+
<p>Sorry, the page you are looking for could not be found.</p>
27+
</body>
28+
</html>

errorPage/500.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>500 Internal Server Error</title>
5+
<style>
6+
body {
7+
background-color: #f2f2f2;
8+
font-family: Arial, sans-serif;
9+
font-size: 16px;
10+
line-height: 1.6;
11+
color: #333;
12+
}
13+
.container {
14+
max-width: 600px;
15+
margin: 0 auto;
16+
padding: 30px;
17+
background-color: #fff;
18+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
19+
}
20+
h1 {
21+
font-size: 28px;
22+
margin-top: 0;
23+
margin-bottom: 10px;
24+
}
25+
p {
26+
margin-top: 0;
27+
margin-bottom: 20px;
28+
}
29+
button {
30+
display: inline-block;
31+
margin-top: 20px;
32+
padding: 10px 20px;
33+
font-size: 16px;
34+
font-weight: bold;
35+
color: #fff;
36+
background-color: #337ab7;
37+
border: none;
38+
border-radius: 3px;
39+
cursor: pointer;
40+
}
41+
button:hover {
42+
background-color: #286090;
43+
}
44+
</style>
45+
</head>
46+
<body>
47+
<div class="container">
48+
<h1>500 Internal Server Error</h1>
49+
<p>Sorry, something went wrong on our server. We're working to fix the problem. Please try again later.</p>
50+
<button onclick="window.history.back();">Go Back</button>
51+
</div>
52+
</body>
53+
</html>

errorPage/indix.html

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>My Page</title>
5+
<link rel="stylesheet" type="text/css" href="style.css">
6+
</head>
7+
<body>
8+
<header>
9+
<h1>Welcome to my page</h1>
10+
<nav>
11+
<ul>
12+
<li><a href="#">Home</a></li>
13+
<li><a href="#">About</a></li>
14+
<li><a href="#">Contact</a></li>
15+
</ul>
16+
</nav>
17+
</header>
18+
19+
<dev>
20+
<img src="https://cdn.intra.42.fr/users/080cb88649236ca06ede61155d2bf3cb/aoumad.jpg" alt="yismaili">
21+
<h2>aoumad</h2>
22+
<p>Abderazzak Oumad, a diligent and aspiring student of 1337 School for computer science. With a passion for coding and a thirst
23+
for knowledge, Abderazzak has been honing his programming skills and expanding his understanding of computer science concepts.
24+
He is an individual with a strong work ethic and always strives to improve himself in every way possible.
25+
Abderazzak is a quick learner and has shown excellent problem-solving skills in various programming projects.
26+
With his dedication and commitment to learning, Abderazzak is set to make a significant contribution to the world of computer science.</p>
27+
</dev>
28+
<dev>
29+
<img src="https://cdn.intra.42.fr/users/b627a0f207cc5e0d352a4f7fb7410813/yismaili.jpg" alt="yismaili">
30+
<h2>yismaili</h2>
31+
<p>Younes Ismaili, a diligent and aspiring student of 1337 School for computer science. With a passion for coding and a thirst
32+
for knowledge, Younes has been honing his programming skills and expanding his understanding of computer science concepts.
33+
He is an individual with a strong work ethic and always strives to improve himself in every way possible.
34+
Younes is a quick learner and has shown excellent problem-solving skills in various programming projects.
35+
With his dedication and commitment to learning, Younes is set to make a significant contribution to the world of computer science.</p>
36+
</dev>
37+
38+
<dev>
39+
<img src="https://cdn.intra.42.fr/users/c06c0753f8262f275a233097381d0190/snouae.jpg" alt="yismaili">
40+
<h2>snouae</h2>
41+
<p>Soufiane Nouae, a diligent and aspiring student of 1337 School for computer science. With a passion for coding and a thirst
42+
for knowledge, Soufiane has been honing his programming skills and expanding his understanding of computer science concepts.
43+
He is an individual with a strong work ethic and always strives to improve himself in every way possible.
44+
Soufiane is a quick learner and has shown excellent problem-solving skills in various programming projects.
45+
With his dedication and commitment to learning, Soufiane is set to make a significant contribution to the world of computer science.</p>
46+
</dev>
47+
48+
<footer>
49+
<p>&copy; 2023 My Page. All rights reserved.</p>
50+
</footer>
51+
</body>
52+
</html>

errorPage/style.css

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
body {
2+
background-color: #eee;
3+
font-family: Arial, sans-serif;
4+
}
5+
6+
header {
7+
background-color: #333;
8+
color: #fff;
9+
padding: 20px;
10+
}
11+
12+
h1 {
13+
margin: 0;
14+
}
15+
16+
nav ul {
17+
margin: 0;
18+
padding: 0;
19+
list-style: none;
20+
}
21+
22+
nav li {
23+
display: inline-block;
24+
margin-right: 20px;
25+
}
26+
27+
nav a {
28+
color: #fff;
29+
text-decoration: none;
30+
}
31+
32+
main {
33+
padding: 20px;
34+
}
35+
36+
h2 {
37+
margin-top: 0;
38+
}
39+
40+
img {
41+
max-width: 10%;
42+
height: auto;
43+
}
44+
45+
footer {
46+
background-color: #333;
47+
color: #fff;
48+
padding: 10px;
49+
text-align: center;
50+
}

prs_rsc/server.conf

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ server {
1313
index index.html;
1414

1515

16-
location /favicon.ico {
17-
allow_methods GET POST DELETE;
18-
root ./www/html/favicon.ico;
19-
}
16+
2017

2118
location / {
2219
allow_methods GET POST DELETE;
23-
root ./www/html/favicon.ico;
2420
}
2521

2622
location /cgi_bin
@@ -29,7 +25,7 @@ server {
2925
allow_methods GET POST;
3026
index hello.html;
3127
path_info .py /usr/bin/python3;
32-
path_info .php ./php-cgi;
28+
path_info .php /php-cgi;
3329
}
3430

3531
location /red
@@ -49,6 +45,7 @@ server {
4945
index upload.html;
5046
allow_methods POST GET;
5147
upload on;
48+
upload_store /upload;
5249
}
5350
}
5451

prs_rsc/server.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,11 @@ server& server::operator=(const server& o)
596596
return (*this);
597597
}
598598

599+
bool server::get_upload() const
600+
{
601+
return(_upload);
602+
}
603+
599604
server::server(const server& o)
600605
{
601606
*this = o;

prs_rsc/server.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class server
4949
std::map<int, std::string> get_error_page() const;
5050
std::vector<std::string> get_allow_methods() const;
5151
bool get_autoindex () const;
52+
bool get_upload() const;
5253
std::pair <int , std::string> get_redirection() const;
5354
std::string get_upload_store() const;
5455
std::map<std::string ,std::string> get_path_info() const;

request/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ SRC = request.cpp main.cpp request_utils.cpp
44

55
CC = c++
66

7-
FLAGS = -std=c++98 -Wall -Wextra -Werror -g -fsanitize=address
8-
# FLAGS = -std=c++98 -Wall -Wextra -Werror
7+
# FLAGS = -std=c++98 -Wall -Wextra -Werror -g -fsanitize=address
8+
FLAGS = -std=c++98 -Wall -Wextra -Werror
99

1010
OBJS = $(SRC:.c=.o)
1111

0 commit comments

Comments
 (0)