Skip to content

Commit

Permalink
Create cgi-bin folder add better comments to config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepulven committed May 22, 2024
1 parent 7abdbfb commit ef17894
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 13 deletions.
Binary file removed a.txt
Binary file not shown.
File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# The first server block will be the default server, it will answer all requests
# that dont belong to another server.

## * Main server block;
server:
# * Webserver specifications;
listen: # mandatory
host: localhost
port: 8080
server_name: example.com
max_cbsize: 2000m # to do: conversion and mapping
max_conn: 10
# * Root definition
root: /
dir_listing: on
http_methods: GET POST
# * Error pages map;
error_pages:
403: error/403.html
400: error/400.html
# * CGI extension exec. path map;
cgi:
.py: /usr/bin/python3
.php: /usr/bin/php
max_cbsize: 2000m # to do: conversion and mapping
max_conn: 10
# * Server routing;
route /main: # to do: HTTP redirect.
root: /pages
index: index.html # default file to open if the request is the dir
Expand All @@ -31,12 +37,16 @@ server:
root: /uploads
dir_listing: on
http_methods: GET POST DELETE

# * CGI routing;
route /python:
root: /cgi-bin/py
index: index.py
http_methods: GET POST DELETE
route /php:
root: /cgi-bin/php
index: index.php
http_methods: GET POST DELETE

server:
listen:
Expand Down
2 changes: 0 additions & 2 deletions post_request_test.txt

This file was deleted.

8 changes: 3 additions & 5 deletions srcs/conn/Res.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/*
* We must have this map globally;
! Performance issue with error handling issue;
*/
Res::Res(ConnStream *_stream) : stream(_stream)
{
Expand Down Expand Up @@ -48,9 +47,6 @@ int Res::build_http_response(void)
ss << content;

this->data = ss.str();
// std::cout << "********************************" << std::endl;
// std::cout << data;
// std::cout << "********************************" << std::endl;
return (write(stream->fd, this->data.c_str(), this->data.length()));
}

Expand Down Expand Up @@ -132,6 +128,8 @@ int Res::exec_CGI(void)
if (pid == 0)
{
std::vector<std::string> request;
int dev_null;

request.push_back("request=" + data);
request.push_back("path=" + req->file_path);
request.push_back("method=" + req->method);
Expand All @@ -153,7 +151,7 @@ int Res::exec_CGI(void)
close(pipe_fd_aux[1]); // Close write end
dup2(pipe_fd_aux[0], STDIN_FILENO); // Redirect stdin to the read end

int dev_null = open("/dev/null", O_WRONLY);
dev_null = open("/dev/null", O_WRONLY);
dup2(dev_null, STDERR_FILENO); // redirecting stderr to /dev/null
close(dev_null);

Expand Down
7 changes: 3 additions & 4 deletions srcs/utils/__file_manager_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,19 @@ std::string FileManager::read_file(const std::string path)
*/
std::string FileManager::directory_listing(const std::string path, std::string route_path, int port)
{
std::cout << "path directory: " << path << std::endl;
DIR* dir = opendir(path.c_str());
std::stringstream ss;
std::string entry_path;

if (!dir)
throw HttpError("500", "Internal Server Error");
ss << "<meta name=\"referrer\" content=\"no-referrer\">";
ss << "<h1>Directory Listing</h1>";
ss << "<ul>";
if (route_path[route_path.size() - 1] != '/')
route_path += "/";
if (route_path[0] == '/')
route_path.erase(0, 1);
ss << "<meta name=\"referrer\" content=\"no-referrer\">";
ss << "<h1>Directory Listing</h1>";
ss << "<ul>";
for (struct dirent* entry = readdir(dir); entry; entry = readdir(dir))
{
entry_path = std::string(entry->d_name);
Expand Down
Empty file removed uploads/1716393220035_
Empty file.
Binary file not shown.
Binary file not shown.
Binary file removed uploads/1716393295561_Screenshotfrom.png
Binary file not shown.
Empty file removed uploads/1716418561372_
Empty file.
Empty file removed uploads/1716418565372_
Empty file.

0 comments on commit ef17894

Please sign in to comment.