From 4fdbb1e0eb861f70f2a2ce784cbd50a43fdfef34 Mon Sep 17 00:00:00 2001 From: Eric LAZO Date: Wed, 17 Aug 2022 17:59:53 +0200 Subject: [PATCH] conclusion, no real php cgi --- srcs/cgi-bin/cgi | 4 +++ srcs/cgi-bin/tmp.php | 10 ++++++ srcs/cgi-bin/upload_file.php | 49 +++++++++++-------------- srcs/cgi-bin/upload_file1.php | 67 +++++++++++++++++++++++++++++++++++ srcs/webserv/request.cpp | 2 +- srcs/webserv/run_loop.cpp | 3 ++ www/test/submit_form.html | 20 +++++------ www/test/submit_form_old.html | 17 +++++++++ 8 files changed, 130 insertions(+), 42 deletions(-) create mode 100755 srcs/cgi-bin/cgi create mode 100755 srcs/cgi-bin/tmp.php create mode 100755 srcs/cgi-bin/upload_file1.php create mode 100644 www/test/submit_form_old.html diff --git a/srcs/cgi-bin/cgi b/srcs/cgi-bin/cgi new file mode 100755 index 0000000..14e0d29 --- /dev/null +++ b/srcs/cgi-bin/cgi @@ -0,0 +1,4 @@ +#! /bin/bash +echo "status: 100\r\n" +echo "\r\n\r\n" +echo "hiii" diff --git a/srcs/cgi-bin/tmp.php b/srcs/cgi-bin/tmp.php new file mode 100755 index 0000000..c962a8d --- /dev/null +++ b/srcs/cgi-bin/tmp.php @@ -0,0 +1,10 @@ +#! /usr/bin/php + + diff --git a/srcs/cgi-bin/upload_file.php b/srcs/cgi-bin/upload_file.php index 572f5be..f3622d6 100755 --- a/srcs/cgi-bin/upload_file.php +++ b/srcs/cgi-bin/upload_file.php @@ -1,34 +1,26 @@ -#! /bin/bash/php - - +#! /usr/bin/php 500000) { } // 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; -//} +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) { @@ -62,4 +54,3 @@ if ($uploadOk == 0) { } ?> - diff --git a/srcs/cgi-bin/upload_file1.php b/srcs/cgi-bin/upload_file1.php new file mode 100755 index 0000000..b536577 --- /dev/null +++ b/srcs/cgi-bin/upload_file1.php @@ -0,0 +1,67 @@ +#! /usr/bin/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/webserv/request.cpp b/srcs/webserv/request.cpp index 54e90a6..2940d4c 100644 --- a/srcs/webserv/request.cpp +++ b/srcs/webserv/request.cpp @@ -53,7 +53,7 @@ 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); + print_special(client->raw_request); std::cerr << "client header complete: " << client->header_complete << "\n"; // DEBUG diff --git a/srcs/webserv/run_loop.cpp b/srcs/webserv/run_loop.cpp index 1b1e644..dea6a8e 100644 --- a/srcs/webserv/run_loop.cpp +++ b/srcs/webserv/run_loop.cpp @@ -26,7 +26,10 @@ void Webserv::_read_cgi_output(Client *client) else if (ret == 0) std::cerr << "Madame s'il vous plait, du Ketchup pour mon hamburger" << " (AKA:ret=0)" << "\n"; else + { + std::cerr << "NORMAL BEHAVIOR I THINK!\n"; // debug client->cgi_output.append(buf, ret); + } } void Webserv::_handle_epoll_error_cgi_fd(uint32_t events, Client *client) diff --git a/www/test/submit_form.html b/www/test/submit_form.html index 7922e67..ec753c0 100644 --- a/www/test/submit_form.html +++ b/www/test/submit_form.html @@ -1,17 +1,13 @@ - - Webserv test Something - -

Webserv in Test

-
-

Time to submit something:

- -
- - - -
+ + +
+ Select image to upload: + + +
+ diff --git a/www/test/submit_form_old.html b/www/test/submit_form_old.html new file mode 100644 index 0000000..28c8b0c --- /dev/null +++ b/www/test/submit_form_old.html @@ -0,0 +1,17 @@ + + + + Webserv test Something + + +

Webserv in Test

+
+

Time to submit something:

+ +
+ + + +
+ +