Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72b12132d4 | ||
|
|
da5d1f38b0 | ||
|
|
4fdbb1e0eb | ||
|
|
b45ed52a2a |
23
42.config
Normal file
23
42.config
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
server {
|
||||||
|
|
||||||
|
|
||||||
|
server_name server1;
|
||||||
|
listen 0.0.0.0:4040;
|
||||||
|
client_body_limit 1000;
|
||||||
|
|
||||||
|
index youpi.bla; # this is another comment
|
||||||
|
|
||||||
|
root ./YoupiBanane/;
|
||||||
|
|
||||||
|
error_page 404 ./www/error_pages/error_404.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
allow_methods GET;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /directory {
|
||||||
|
index youpi.bad_extention;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ server {
|
|||||||
|
|
||||||
server_name server1;
|
server_name server1;
|
||||||
|
|
||||||
listen 0.0.0.0:4040;
|
listen 0.0.0.0:8080;
|
||||||
|
|
||||||
client_body_limit 1;
|
client_body_limit 1;
|
||||||
# Max == 18446744073709551615 / 1024 == 18014398509481984
|
# Max == 18446744073709551615 / 1024 == 18014398509481984
|
||||||
|
|||||||
98
Tester/test3.config
Normal file
98
Tester/test3.config
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
|
||||||
|
server {
|
||||||
|
|
||||||
|
# this is a comment
|
||||||
|
|
||||||
|
server_name server1;
|
||||||
|
|
||||||
|
listen 8080;
|
||||||
|
# listen 70000;
|
||||||
|
|
||||||
|
# client_body_limit asdfa;
|
||||||
|
client_body_limit 1000;
|
||||||
|
# Max == 18446744073709551615 / 1024 == 18014398509481984
|
||||||
|
|
||||||
|
index index.html; # this is another comment
|
||||||
|
#index mdr.html; # this is another comment
|
||||||
|
|
||||||
|
root ./Tester/www/;
|
||||||
|
|
||||||
|
error_page 404 ./Tester/www/error_pages/error_404.html;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
location / {
|
||||||
|
allow_methods GET;
|
||||||
|
root ./Tester/www/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /srcs/cgi-bin/ {
|
||||||
|
root ./srcs/cgi-bin/;
|
||||||
|
allow_methods POST;
|
||||||
|
cgi_ext php;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /list {
|
||||||
|
autoindex on;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /cgi-bin {
|
||||||
|
root ./srcs/cgi-bin/;
|
||||||
|
cgi_ext out php sh;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /upload {
|
||||||
|
allow_methods POST;
|
||||||
|
autoindex on;
|
||||||
|
upload_dir ./Tester/www/user_files/;
|
||||||
|
# root doesn’t matter if used only with POST and no CGI
|
||||||
|
}
|
||||||
|
|
||||||
|
location /the_dump {
|
||||||
|
allow_methods GET DELETE;
|
||||||
|
root ./Tester/www/user_files;
|
||||||
|
autoindex on;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /redirect {
|
||||||
|
redirect 307 https://fr.wikipedia.org/wiki/Ketchup;
|
||||||
|
# redirect 307 https://www.youtube.com/watch?v=rG6b8gjMEkw;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /test {
|
||||||
|
index index1.html subdex.html;
|
||||||
|
root ./Tester/www/test/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /stylesheet {
|
||||||
|
root ./stylesheet/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /test/index1.html {
|
||||||
|
root ./Tester/www/test/index1.html;
|
||||||
|
index index1.html subdex.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /hilarious_404/ {
|
||||||
|
redirect 301 https://berniesanders.com/404/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /test/something.html {
|
||||||
|
# allow_methods DELETE;
|
||||||
|
root ./Tester/www/test/something.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /test/test_deeper/ {
|
||||||
|
# allow_methods
|
||||||
|
root ./Tester/www/test/test_deeper/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /test/test_deeper/super_deep {
|
||||||
|
root ./Tester/www/test/test_deeper/super_deep/;
|
||||||
|
}
|
||||||
|
|
||||||
|
# location /test/test_deeper/something.html {
|
||||||
|
# allow_methods DELETE;
|
||||||
|
# }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
test_name="Body Test"
|
test_name="Body Test"
|
||||||
|
|
||||||
config_file="./Tester/test2.config"
|
config_file="./Tester/test2.config"
|
||||||
port=4040
|
port=8080
|
||||||
host="localhost"
|
host="localhost"
|
||||||
|
|
||||||
#paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many
|
#paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many
|
||||||
@@ -17,17 +17,19 @@ httpz=("HTTP/1.1")
|
|||||||
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
|
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
|
||||||
|
|
||||||
header="Host: $host\n"
|
header="Host: $host\n"
|
||||||
body="this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message \n"
|
body="this is a message \n"
|
||||||
|
body+="this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message \n"
|
||||||
|
|
||||||
# turns out this does nothing...
|
# turns out this does nothing...
|
||||||
#header_cycle=("Content-Length: 17" "Content-Length: 14" "Content-Length: 25")
|
#header_cycle=("Content-Length: 17\n" "Content-Length: 14" "Content-Length: 25")
|
||||||
#header_cycle=("Content-Length: 17" "")
|
#header_cycle=("Content-Length: 17\n" "\n")
|
||||||
#header_cycle=("Content-Length: 17")
|
#header_cycle=("Content-Length: 17\n")
|
||||||
#header_cycle=()
|
#header_cycle=()
|
||||||
header+="Content-Length: 15"
|
#header+="Content-Length: 8\n"
|
||||||
|
|
||||||
run_this_test()
|
run_this_test()
|
||||||
{
|
{
|
||||||
|
echo size is ${#body} >> telnet.log
|
||||||
|
|
||||||
# for i in "${header_cycle[@]}"
|
# for i in "${header_cycle[@]}"
|
||||||
for i in "${paths[@]}"
|
for i in "${paths[@]}"
|
||||||
@@ -36,7 +38,9 @@ run_this_test()
|
|||||||
l1="${methods[0]} $i ${httpz[0]}"
|
l1="${methods[0]} $i ${httpz[0]}"
|
||||||
# header_send="$header$i"
|
# header_send="$header$i"
|
||||||
header_send="$header"
|
header_send="$header"
|
||||||
request="$l1\n$header_send\n\n$body\n"
|
## if you add an extra \n after header send you get a status code 200 OK and 400 bad request, but like both
|
||||||
|
# request="$l1\n$header_send\n$body\n"
|
||||||
|
request="$l1\n$header_send\n$body"
|
||||||
{
|
{
|
||||||
echo "----- $test_name -----"
|
echo "----- $test_name -----"
|
||||||
echo -e "$_RED$request$_END"
|
echo -e "$_RED$request$_END"
|
||||||
|
|||||||
74
Tester/test_port.sh
Normal file
74
Tester/test_port.sh
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
test_name="Port Test"
|
||||||
|
|
||||||
|
config_file="./Tester/test3.config"
|
||||||
|
port=8080
|
||||||
|
host="localhost"
|
||||||
|
|
||||||
|
#paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many
|
||||||
|
paths=("/") # you can add many
|
||||||
|
#methods=("GET" "POST" "DELETE")
|
||||||
|
methods=("GET")
|
||||||
|
httpz=("HTTP/1.1")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
|
||||||
|
|
||||||
|
header="Host: $host"
|
||||||
|
body=
|
||||||
|
|
||||||
|
|
||||||
|
run_this_test()
|
||||||
|
{
|
||||||
|
|
||||||
|
for i in "${paths[@]}"
|
||||||
|
do
|
||||||
|
l1="${methods[0]} $i ${httpz[0]}"
|
||||||
|
request="$l1\n$header\n$body\n"
|
||||||
|
{
|
||||||
|
echo "----- $test_name -----"
|
||||||
|
echo -e "$_RED$request$_END"
|
||||||
|
} >> telnet.log
|
||||||
|
echo -e "$request"
|
||||||
|
sleep 1
|
||||||
|
echo -e "\n" >> telnet.log
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# expected result...
|
||||||
|
|
||||||
|
|
||||||
|
files=()
|
||||||
|
|
||||||
|
file="expected_path_test.txt"
|
||||||
|
files+=("expected_path_test.txt")
|
||||||
|
#files+=("expected_path_root_test.txt")
|
||||||
|
#files+=("expected_path_testnoslash_test.txt")
|
||||||
|
#files+=("expected_path_testslash_test.txt")
|
||||||
|
#files+=("expected_path_list_test.txt")
|
||||||
|
#files+=("expected_path_badlist_test.txt")
|
||||||
|
#files+=("expected_path_wrong_test.txt")
|
||||||
|
|
||||||
|
|
||||||
|
#local_expected_test_file=$file
|
||||||
|
local_expected_test_files=()
|
||||||
|
test_path=""
|
||||||
|
|
||||||
|
add_path()
|
||||||
|
{
|
||||||
|
for i in "${files[@]}"
|
||||||
|
do
|
||||||
|
local_expected_test_files+=("$test_path$i")
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
#add_path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
12
compare.txt
12
compare.txt
@@ -1,10 +1,4 @@
|
|||||||
telnet> Trying 127.0.0.1...
|
telnet> Trying 127.0.0.1...
|
||||||
Connected to localhost.
|
telnet> ?Invalid command
|
||||||
Escape character is '^]'.
|
telnet> ?Invalid command
|
||||||
HTTP/1.1 413 Content Too Large
|
telnet> telnet> telnet>
|
||||||
Server: Webserv/0.1
|
|
||||||
Connection: close
|
|
||||||
Content-Type: text/html; charset=UTF-8
|
|
||||||
Content-Length: 197
|
|
||||||
|
|
||||||
<!DOCTYPE html><html><head><title>413 Content Too Large</title></head><body><h1 style="text-align:center">413 Content Too Large</h1><hr><p style="text-align:center">Le Webserv/0.1</p></body></html>
|
|
||||||
@@ -42,8 +42,19 @@ server {
|
|||||||
|
|
||||||
location /upload {
|
location /upload {
|
||||||
allow_methods POST;
|
allow_methods POST;
|
||||||
|
# autoindex on;
|
||||||
|
# root ./www/;
|
||||||
|
# index upload_form_single.html;
|
||||||
|
|
||||||
|
# upload_dir ./www/user_files/;
|
||||||
|
# root doesn’t matter if used only with POST and no CGI
|
||||||
|
}
|
||||||
|
|
||||||
|
location /uploaded {
|
||||||
|
allow_methods GET;
|
||||||
autoindex on;
|
autoindex on;
|
||||||
upload_dir ./www/user_files/;
|
# upload_dir ./www/user_files/;
|
||||||
|
root ./www/user_files;
|
||||||
# root doesn’t matter if used only with POST and no CGI
|
# root doesn’t matter if used only with POST and no CGI
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +95,12 @@ server {
|
|||||||
location /test/test_deeper/ {
|
location /test/test_deeper/ {
|
||||||
# allow_methods
|
# allow_methods
|
||||||
root ./www/test/test_deeper/;
|
root ./www/test/test_deeper/;
|
||||||
|
index index1.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /test/test_deeper/super_deep {
|
location /test/test_deeper/super_deep {
|
||||||
root ./www/test/test_deeper/super_deep/;
|
root ./www/test/test_deeper/super_deep/;
|
||||||
|
index something.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# location /test/test_deeper/something.html {
|
# location /test/test_deeper/something.html {
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ _END='\033[0m'
|
|||||||
|
|
||||||
#test_file_names=("test_template.sh" "test_header.sh" "test_path.sh")
|
#test_file_names=("test_template.sh" "test_header.sh" "test_path.sh")
|
||||||
#test_file_names=("test_method.sh" "test_header.sh" "test_path.sh")
|
#test_file_names=("test_method.sh" "test_header.sh" "test_path.sh")
|
||||||
test_file_names=("test_body.sh")
|
test_file_names=("test_port.sh")
|
||||||
|
#test_file_names=("test_body.sh")
|
||||||
#test_file_names=("test_valid_uri.sh")
|
#test_file_names=("test_valid_uri.sh")
|
||||||
#test_file_names=("test_path.sh")
|
#test_file_names=("test_path.sh")
|
||||||
|
|
||||||
|
|||||||
@@ -137,16 +137,18 @@ void Client::parse_request_body()
|
|||||||
}
|
}
|
||||||
else if (raw_request.size() - pos >= std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10))
|
else if (raw_request.size() - pos >= std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10))
|
||||||
{
|
{
|
||||||
|
std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
||||||
if (get_rq_headers("Content-Type").find("multipart/form-data") != NPOS)
|
if (get_rq_headers("Content-Type").find("multipart/form-data") != NPOS)
|
||||||
_parse_multipart_body(pos);
|
_parse_multipart_body(pos);
|
||||||
else
|
else
|
||||||
_request.body = raw_request.substr(pos + CRLF_SIZE*2);
|
_request.body = raw_request.substr(pos + CRLF_SIZE*2);
|
||||||
body_complete = true;
|
body_complete = true;
|
||||||
}
|
}
|
||||||
// std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
|
||||||
// std::cerr << "raw_request.size() - pos = " << raw_request.size() - pos << "\n";
|
std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
||||||
// _request.body = raw_request.substr(pos);
|
std::cerr << "raw_request.size() - pos = " << raw_request.size() - pos << "\n";
|
||||||
// std::cerr << "_request.body.size() = " << _request.body.size() << "\n";
|
_request.body = raw_request.substr(pos);
|
||||||
|
std::cerr << "_request.body.size() = " << _request.body.size() << "\n";
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Body checks
|
// Body checks
|
||||||
@@ -339,6 +341,7 @@ void Client::_parse_request_line()
|
|||||||
{
|
{
|
||||||
std::cerr << "err _parse_first_line(): wrong number of elements (" << line.size() << " instead of 3)\n";
|
std::cerr << "err _parse_first_line(): wrong number of elements (" << line.size() << " instead of 3)\n";
|
||||||
status = 400; // "bad request"
|
status = 400; // "bad request"
|
||||||
|
// if the header is fucked up, then this will be triggered, but for some reason in test_body.sh case another response 200 OK is sent first?
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -413,9 +416,9 @@ void Client::_parse_port_hostname(std::string host)
|
|||||||
|
|
||||||
void Client::_check_request_errors()
|
void Client::_check_request_errors()
|
||||||
{
|
{
|
||||||
// /* Debug */ std::cerr << "Content-Length=" << get_rq_headers("Content-Length") << "\n";
|
/* Debug */ std::cerr << "Content-Length=" << get_rq_headers("Content-Length") << "\n";
|
||||||
// /* Debug */ std::cerr << "strtoul=" << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
/* Debug */ std::cerr << "strtoul=" << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
||||||
// /* Debug */ std::cerr << "client_body_limit=" << assigned_server->client_body_limit << "\n";
|
/* Debug */ std::cerr << "client_body_limit=" << assigned_server->client_body_limit << "\n";
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// Request line checks
|
// Request line checks
|
||||||
if (_request.method == UNKNOWN)
|
if (_request.method == UNKNOWN)
|
||||||
@@ -507,6 +510,7 @@ If we get a url that ends in / ignore the last /
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: technically i think this is useless...
|
||||||
std::string uri = path;
|
std::string uri = path;
|
||||||
if (uri[uri.size() - 1] == '/' && uri.size() != 1)
|
if (uri[uri.size() - 1] == '/' && uri.size() != 1)
|
||||||
uri.erase(uri.size() - 1);
|
uri.erase(uri.size() - 1);
|
||||||
|
|||||||
4
srcs/cgi-bin/cgi
Executable file
4
srcs/cgi-bin/cgi
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
echo "status: 100\r\n"
|
||||||
|
echo "\r\n\r\n"
|
||||||
|
echo "hiii"
|
||||||
10
srcs/cgi-bin/tmp.php
Executable file
10
srcs/cgi-bin/tmp.php
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#! /usr/bin/php
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if(isset($_FILE["fileToUpload"]))
|
||||||
|
echo "there is a file";
|
||||||
|
else
|
||||||
|
echo "\n\nHeader: something\r\n\r\nno file\r\n";
|
||||||
|
|
||||||
|
?>
|
||||||
49
srcs/cgi-bin/upload_file.php
Normal file → Executable file
49
srcs/cgi-bin/upload_file.php
Normal file → Executable file
@@ -1,34 +1,26 @@
|
|||||||
#! /bin/bash/php
|
#! /usr/bin/php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// $FileName=$_FILES['myFile']['filename'];
|
|
||||||
# $TmpName=$_FILES['myFile']['tmp_name'];
|
|
||||||
# move_uploaded_file($TmpName, $FileName);
|
|
||||||
# echo("File was uploaded successfully!");
|
|
||||||
|
|
||||||
// this part needs to be grabed from POST uri
|
|
||||||
$target_dir = "./www/uploaded/";
|
|
||||||
//$target_dir = $_POST["upload_dir"];
|
$target_dir = "user_files/";
|
||||||
//$target_dir = $_GET["upload_dir"];
|
|
||||||
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
||||||
$uploadOk = 1;
|
$uploadOk = 1;
|
||||||
$fileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
||||||
//$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
|
||||||
|
|
||||||
// Check if image file is a actual image or fake image
|
// Check if image file is a actual image or fake image
|
||||||
//if(isset($_POST["submit"])) {
|
if(isset($_POST["submit"])) {
|
||||||
// $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
|
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
|
||||||
// if($check !== false) {
|
if($check !== false) {
|
||||||
// echo "File is an image - " . $check["mime"] . ".";
|
echo "File is an image - " . $check["mime"] . ".";
|
||||||
// $uploadOk = 1;
|
$uploadOk = 1;
|
||||||
// } else {
|
} else {
|
||||||
// echo "File is not an image.";
|
echo "File is not an image.";
|
||||||
// $uploadOk = 0;
|
$uploadOk = 0;
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
// Check if file already exists
|
// Check if file already exists
|
||||||
if (file_exists($target_file)) {
|
if (file_exists($target_file)) {
|
||||||
@@ -43,11 +35,11 @@ if ($_FILES["fileToUpload"]["size"] > 500000) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allow certain file formats
|
// Allow certain file formats
|
||||||
//if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
|
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
|
||||||
//&& $imageFileType != "gif" ) {
|
&& $imageFileType != "gif" ) {
|
||||||
// echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
|
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
|
||||||
// $uploadOk = 0;
|
$uploadOk = 0;
|
||||||
//}
|
}
|
||||||
|
|
||||||
// Check if $uploadOk is set to 0 by an error
|
// Check if $uploadOk is set to 0 by an error
|
||||||
if ($uploadOk == 0) {
|
if ($uploadOk == 0) {
|
||||||
@@ -62,4 +54,3 @@ if ($uploadOk == 0) {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
67
srcs/cgi-bin/upload_file1.php
Executable file
67
srcs/cgi-bin/upload_file1.php
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#! /usr/bin/php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// $FileName=$_FILES['myFile']['filename'];
|
||||||
|
# $TmpName=$_FILES['myFile']['tmp_name'];
|
||||||
|
# move_uploaded_file($TmpName, $FileName);
|
||||||
|
# echo("File was uploaded successfully!");
|
||||||
|
|
||||||
|
// this part needs to be grabed from POST uri
|
||||||
|
$target_dir = "./www/user_files/";
|
||||||
|
//$target_dir = $_POST["upload_dir"];
|
||||||
|
//$target_dir = $_GET["upload_dir"];
|
||||||
|
//$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
||||||
|
$target_file = $target_dir . basename($_FILES["myFile"]["name"]);
|
||||||
|
|
||||||
|
$uploadOk = 1;
|
||||||
|
$fileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
||||||
|
//$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
// Check if image file is a actual image or fake image
|
||||||
|
//if(isset($_POST["submit"])) {
|
||||||
|
// $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
|
||||||
|
// if($check !== false) {
|
||||||
|
// echo "File is an image - " . $check["mime"] . ".";
|
||||||
|
// $uploadOk = 1;
|
||||||
|
// } else {
|
||||||
|
// echo "File is not an image.";
|
||||||
|
// $uploadOk = 0;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Check if file already exists
|
||||||
|
if (file_exists($target_file)) {
|
||||||
|
echo "Sorry, file already exists.";
|
||||||
|
$uploadOk = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check file size
|
||||||
|
if ($_FILES["fileToUpload"]["size"] > 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.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
@@ -53,10 +53,13 @@ int Webserv::_read_request(Client *client)
|
|||||||
// ::print_special(client->raw_request);
|
// ::print_special(client->raw_request);
|
||||||
// std::cerr << "__raw_request__\n" << client->raw_request << "\n______\n"; // DEBUG
|
// std::cerr << "__raw_request__\n" << client->raw_request << "\n______\n"; // DEBUG
|
||||||
|
|
||||||
// print_special(client->raw_request);
|
print_special(client->raw_request);
|
||||||
|
|
||||||
|
std::cerr << "client header complete: " << client->header_complete << "\n"; // DEBUG
|
||||||
|
|
||||||
if (!client->header_complete)
|
if (!client->header_complete)
|
||||||
{
|
{
|
||||||
|
std::cout << "Header not complete\n"; // debug
|
||||||
client->parse_request_headers(_servers);
|
client->parse_request_headers(_servers);
|
||||||
if (client->status)
|
if (client->status)
|
||||||
return READ_COMPLETE;
|
return READ_COMPLETE;
|
||||||
@@ -75,6 +78,7 @@ int Webserv::_read_request(Client *client)
|
|||||||
}
|
}
|
||||||
if (client->header_complete)
|
if (client->header_complete)
|
||||||
{
|
{
|
||||||
|
std::cerr << "Client header Complete\n";
|
||||||
// client->read_body_size += ret; // Not accurate, part of body could have been read with headers, unused for now
|
// client->read_body_size += ret; // Not accurate, part of body could have been read with headers, unused for now
|
||||||
client->parse_request_body();
|
client->parse_request_body();
|
||||||
if (client->status || client->body_complete)
|
if (client->status || client->body_complete)
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ void Webserv::_read_cgi_output(Client *client)
|
|||||||
else if (ret == 0)
|
else if (ret == 0)
|
||||||
std::cerr << "Madame s'il vous plait, du Ketchup pour mon hamburger" << " (AKA:ret=0)" << "\n";
|
std::cerr << "Madame s'il vous plait, du Ketchup pour mon hamburger" << " (AKA:ret=0)" << "\n";
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "NORMAL BEHAVIOR I THINK!\n"; // debug
|
||||||
client->cgi_output.append(buf, ret);
|
client->cgi_output.append(buf, ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Webserv::_handle_epoll_error_cgi_fd(uint32_t events, Client *client)
|
void Webserv::_handle_epoll_error_cgi_fd(uint32_t events, Client *client)
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
<title>Webserv test Something</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<h1 style="text-align:center">Webserv in Test</h1>
|
|
||||||
<hr>
|
<!--- <form action="/cgi-bin/tmp.php" method="post" enctype="multipart/form-data"> -->
|
||||||
<p style="text-align:center">Time to submit something:</p>
|
<form action="/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data">
|
||||||
<!-- <form action="./srcs/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data"> -->
|
Select image to upload:
|
||||||
<form action="/uploaded" method="post" enctype="multipart/form-data">
|
<input type="file" name="fileToUpload" id="fileToUpload">
|
||||||
<!-- <input type="hidden" name="upload_dir" value="./www/uploaded/"> -->
|
<input type="submit" value="Upload Image" name="submit">
|
||||||
<input type="file" id="fileToUpload" name="myFile">
|
</form>
|
||||||
<input type="submit" value="Upload File">
|
|
||||||
</form>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
17
www/test/submit_form_old.html
Normal file
17
www/test/submit_form_old.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Webserv test Something</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 style="text-align:center">Webserv in Test</h1>
|
||||||
|
<hr>
|
||||||
|
<p style="text-align:center">Time to submit something:</p>
|
||||||
|
<!-- <form action="./srcs/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data"> -->
|
||||||
|
<form action="/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data">
|
||||||
|
<!-- <input type="hidden" name="upload_dir" value="./www/uploaded/"> -->
|
||||||
|
<input type="file" id="fileToUpload" name="fileToUpload">
|
||||||
|
<input type="submit" value="Upload File">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
https://www.rfc-editor.org/rfc/rfc9110#name-multipart-types
|
https://www.rfc-editor.org/rfc/rfc9110#name-multipart-types
|
||||||
https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
|
https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
|
||||||
-->
|
-->
|
||||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
<form action="/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data">
|
||||||
<input type="file" name="upload_file1">
|
<input type="file" name="upload_file1">
|
||||||
<input type="submit">
|
<input type="submit">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user