diff --git a/1 b/1 new file mode 100644 index 0000000..3b77138 --- /dev/null +++ b/1 @@ -0,0 +1,3 @@ + +------ + diff --git a/default.config b/default.config index 8fb0db0..344ea17 100644 --- a/default.config +++ b/default.config @@ -15,6 +15,28 @@ server { error_page 404 ./www/error_pages/error_404.html; + +# something to do with /upload + + location /upload { + root ./www/test/; + index submit_form.html; +# upload_dir ./www/uploaded/; +# cgi_ext php; + } + + location /uploaded { +# autoindex on; + root ./www/uploaded/; + upload_dir ./www/uploaded/; + } + +# location /srcs/cgi-bin/ { +# root ./srcs/cgi-bin/; +# allow_methods POST; +# cgi_ext php; +# } + location /list { autoindex on; } diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 03864d1..f3247c2 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -268,8 +268,7 @@ void Client::clear_script() void Client::print_client(std::string message) { std::map::iterator it; - - std::cout << "\n=== DEBUG PRINT CLIENT ===\n"; +std::cout << "\n=== DEBUG PRINT CLIENT ===\n"; std::cout << message << ":\n----------\n\n" << "raw_request:\n__\n"; ::print_special(raw_request); std::cout << "\n__\n" diff --git a/srcs/cgi-bin/upload_file.php b/srcs/cgi-bin/upload_file.php new file mode 100644 index 0000000..251aefb --- /dev/null +++ b/srcs/cgi-bin/upload_file.php @@ -0,0 +1,65 @@ +#! /bin/bash/php + + + + + 500000) { + echo "Sorry, your file is too large."; + $uploadOk = 0; +} + +// Allow certain file formats +//if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" +//&& $imageFileType != "gif" ) { + // echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; + // $uploadOk = 0; +//} + +// Check if $uploadOk is set to 0 by an error +if ($uploadOk == 0) { + echo "Sorry, your file was not uploaded."; +// if everything is ok, try to upload file +} else { + if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { + echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; + } else { + echo "Sorry, there was an error uploading your file."; + } +} +?> + + diff --git a/srcs/config/parser.cpp b/srcs/config/parser.cpp index c7e6162..0159dbb 100644 --- a/srcs/config/parser.cpp +++ b/srcs/config/parser.cpp @@ -194,7 +194,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \ { if (tmp_val[0].find_first_of(":") == NPOS) { - if (!::isNumeric(tmp_val[0])) + if (!::isNumeric_btw(0, 65535, tmp_val[0])) throw std::invalid_argument("bad port number"); server->host = "0.0.0.0"; server->port = tmp_val[0]; @@ -211,7 +211,7 @@ void ConfigParser::_set_server_values(ServerConfig *server, \ if (!::isNumeric_btw(0, 255, ip[i])) throw std::invalid_argument("bad host ip"); } - if (!::isNumeric(tmp2[1])) + if (!::isNumeric_btw(0, 65535, tmp2[1])) throw std::invalid_argument("bad port number"); server->host = tmp2[0]; server->port = tmp2[1]; diff --git a/srcs/webserv/method_get.cpp b/srcs/webserv/method_get.cpp index 78a073b..310e27a 100644 --- a/srcs/webserv/method_get.cpp +++ b/srcs/webserv/method_get.cpp @@ -105,6 +105,10 @@ void Webserv::_autoindex(Client *client, const std::string &path) { std::cout << "_autoindex()\n"; +// std::cout << "client target: " << client->get_rq_target() << '\n'; + + + std::string dir_list; DIR *dir; struct dirent *ent; @@ -122,11 +126,14 @@ void Webserv::_autoindex(Client *client, const std::string &path) /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { - // std::cout << "ent: " << ent->d_name << '\n'; +// std::cout << "ent: " << ent->d_name << '\n'; if (strcmp(".", ent->d_name) == 0) continue ; dir_list.append("get_rq_abs_path() + "/"); +// dir_list.append(client->get_rq_target()); + dir_list.append(client->get_rq_abs_path()); + if (dir_list[dir_list.size() - 1] != '/') + dir_list.push_back('/'); dir_list.append(ent->d_name); dir_list.append("\">"); dir_list.append(ent->d_name); diff --git a/srcs/webserv/request.cpp b/srcs/webserv/request.cpp index 26ffbb0..713de12 100644 --- a/srcs/webserv/request.cpp +++ b/srcs/webserv/request.cpp @@ -53,6 +53,8 @@ int Webserv::_read_request(Client *client) // ::print_special(client->raw_request); // std::cerr << "__raw_request__\n" << client->raw_request << "\n______\n"; // DEBUG +// print_special(client->raw_request); + if (!client->header_complete) { client->parse_request_headers(_servers); diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 5c249ad..6cce4c0 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -203,12 +203,13 @@ If we get a url that ends in / ignore the last / */ std::string uri = path; - if (uri[uri.size() - 1] == '/') + if (uri[uri.size() - 1] == '/' && uri.size() != 1) uri.erase(uri.size() - 1); for (std::vector::const_iterator it = server.locations.begin(); it != server.locations.end(); it++) { +// std::cout << it->path << " -- "; if (it->path.size() > uri.size()) continue ; diff --git a/telnet_test.sh b/telnet_test.sh new file mode 100755 index 0000000..3d2c3d6 --- /dev/null +++ b/telnet_test.sh @@ -0,0 +1,143 @@ +#! /bin/bash + +# you need to put absolutely everything in "" + + +########## +# Colors +########## + + +_GREY='\033[30m' +_RED='\033[0;31m' +_GREEN='\033[32m' +_YELLOW='\033[33m' +_BLUE='\033[34m' +_PURPLE='\033[35m' +_CYAN='\033[36m' +_WHITE='\033[37m' +_END='\033[0m' + + +test_file=$1 +source $test_file + +connect_to_telnet="open $host $port" + + +start_telnet() +{ + echo "open $host $port" + sleep 1 +} + +run_telnet() +{ + echo "$connect_to_telnet" + sleep 1 + echo -e "$request" +# echo "$l1" +# echo "$header" +# echo +# echo $body +# echo +# echo + + echo + sleep 1 + +# ret = $(arg | telnet) + +} + +run() +{ + echo "$connect_to_telnet" + sleep 1 + + run_this_test + + +} + + + +run_a_test() +{ + { + echo "----- $test_name -----" + echo -e "$_RED$request$_END" + } &> test.log + +# run_telnet +# echo ${pid} +# echo -e "$_END---" + + echo -e "$request" | telnet +# run_telnet | telnet +# run_telnet + +# echo +# echo "----- end of test -----" +} + +run_all() +{ + echo + +# ./webserv $config_file 2>&1 > webserv.log & + + + +#while something i change headers + +# for i in "${methods[@]}" +# do +# expected_result="something" +# run_a_test +# echo -e "${_GREEN}$expected_result${_END}" +## echo +# done + +} + + +####### +# This is where stuff is launched +####### + +rm -rf test.log +rm -rf telnet.out + +#./webserv $config_file 2>&1 > webserv.log & run_all +#./webserv $config_file 2>&1 > webserv.log & +#./webserv $config_file &> /dev/null & +./webserv $config_file &> webserv.log & +#./webserv $config_file 1>&1 > webserv.log & + + +#run_all +#run_this_test + +echo -e "${_GREEN}Running Telnet Test on '$test_name'${_END}" + +sleep 1 + +run | telnet >> telnet.out +#run | telnet + +pkill webserv + + + + + + + + + + + + + + diff --git a/telnet_test2.sh b/telnet_test2.sh new file mode 100755 index 0000000..204ff98 --- /dev/null +++ b/telnet_test2.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +echo "open duckduckgo.com 80" +sleep 1 +echo "GET / HTTP/1.1" +echo "Host: duckduckgo.com" +echo +echo +sleep 2 + +#( +#echo open duckduckgo.com 80 +#echo "GET / HTTP/1.1" +#echo "Host: duckduckgo.com" +#echo "exit" +#) | telnet diff --git a/test_header.txt b/test_header.txt new file mode 100644 index 0000000..bbe1f78 --- /dev/null +++ b/test_header.txt @@ -0,0 +1,11 @@ + +config_file=... +port=... + +# Host: ... + + + + +# the correct response +... diff --git a/test_template.sh b/test_template.sh new file mode 100644 index 0000000..22388ad --- /dev/null +++ b/test_template.sh @@ -0,0 +1,61 @@ +#! /bin/bash + +test_name="Template test all good" + +config_file="default.config" +port=4040 +host="localhost" + +paths=("/") # you can add many +methods=("GET" "POST" "DELETE") +#methods=("GET") +httpz=("HTTP/1.1") + + + + +# the parts we will send to webserv + + +# let main.sh handle the l1 + +l1="${methods[0]} ${paths[0]} ${https[0]}" + +header="Host: $host" +body= + + +run_this_test() +{ + + for i in "${methods[@]}" + do + l1="$i ${paths[0]} ${httpz[0]}" + request="$l1\n$header\n$body\n" + { + echo "----- $test_name -----" + echo -e "$_RED$request$_END" + } >> telnet.out +# } &>> test.log +# } 2>>&1 +# } &>> /dev/stdout + echo -e "$request" + sleep 1 +# { +# echo -e "\n------\n" +# } > /dev/stdout + # echo -e "\n\n\n------\n\n\n" >> telnet.out + # echo -e "\n\n\n------\n\n\n" &> /dev/stdout + echo -e "\n\n" >> telnet.out +# echo -e "\n\n------\n\n" >> telnet.out + # echo -e "\n------\n" > /dev/stdout +# run_a_test +# echo + done + +} + + + +# expected result... + diff --git a/www/test/submit_form.html b/www/test/submit_form.html new file mode 100644 index 0000000..c4d556b --- /dev/null +++ b/www/test/submit_form.html @@ -0,0 +1,17 @@ + + + + Webserv test Something + + +

Webserv in Test

+
+

Time to submit something:

+ +
+ + + +
+ +