Skip to content

Commit

Permalink
Merge pull request #40 from ErnestoAvedillo/Change-cgi-in-all-Location
Browse files Browse the repository at this point in the history
Change cgi in all location, cookies, norma and cgi environments
  • Loading branch information
josephcheel authored Jun 30, 2024
2 parents 18de093 + 79c739c commit 6c1588a
Show file tree
Hide file tree
Showing 46 changed files with 1,084 additions and 828 deletions.
File renamed without changes.
File renamed without changes.
87 changes: 56 additions & 31 deletions conf/eval.conf
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
/* format type of the configutation file # This is a comment part /*
server:{
port:8001; # listening port, mandatory parameter. Can be multiple ex: 8000:8100, 8060, 8020
host:127.0.0.1; # host or 127.0.0.1 by default
server_name:test; # specify server_name, need to be added into /etc/hosts to work
error_page:/error/; # default error page
client_max_body_size:1024; # max request body size in bytes
root:docs/fusion_web/; # root folder of site directory, full or relative path, mandatory parameter
index:index.html; # default page when requesting a directory, index.html by default
}
*/
server:{

port:8080; # listening port, mandatory parameter
host:0.0.0.0; # host or 127.0.0.1 by default
server_name:example.com; # specify server_name, need to be added into /etc/hosts to work
error_page:./www/errors; # default error page
client_max_body_size:120MB; # max request body size in bytes
root:./www/web1; # root folder of site directory, full or relative path, mandatory parameter
index:index.html; # default page when requesting a directory, index.html by default
port:8080, 8081;
host:127.0.0.1;
server_name:example.com;
error_page:./www/errors;
client_max_body_size:120MB;
root:./www/web1;
index:index.html;
autoindex: on;
# location:{
# name:/;
# root:./www/web1; # root folder of site directory, full or relative path, mandatory parameter
# index:index.html; # default page when requesting a directory, index.html by default
# }
location:{
name:/redirect;
return:https://www.42barcelona.com/; # redirection
return:https://www.42barcelona.com/;
}
location:{
name:/redirect2;
return:/uploads; # redirection
return:/uploads;
}
location:{
name:/post;
allow_methods: GET; #allowed methods in location, GET only by default
index:index5.html; # default page when requesting a directory, copies root index by default
alias: ./www/web3; # replaces location part of URI.
name:/post/;
allow_methods: GET;
index:index6.html;
alias: ./www/web3;
}
location:{
name:/uploads;
Expand All @@ -46,12 +30,13 @@ server:{
}
location:{
name:/cgi-bin;
cgi_enabled: true;
alias:./www/web6;
allow_methods: GET, POST, DELETE;
autoindex:on;
cgi_path:/usr/bin/python3, /bin/sh;
cgi_extension:.py, .sh;
cgi_extension:cgi, py, sh;
}

location:{
name:/cgi-no-bin;
alias:./www/web6;
Expand All @@ -64,4 +49,44 @@ server:{
allow_methods: GET;
autoindex:on;
}
location:{
name:/set-cookie/;
alias:./www/web7;
index:set-cookie3.html;
allow_methods: GET, POST;
autoindex:on;
}
location:{
name:/get-cookie/;
set-cookie:id, name, lastname, theme;
set-id: true;
alias:./www/web7;
index:welcome.html;
allow_methods: GET, POST;
}
location:{
name:/cookie/;
alias:./www/web7;
allow_methods: GET, POST;
autoindex:on;
}
location:{
name: /cgi-crash/;
alias:./www/web4;
index:index.html;
allow_methods: GET, POST;
cgi_enabled: true;
cgi_extension: cgi;
}
};

server:{
port:8082:8090;
host:0.0.0.0;
server_name:example.com;
error_page:./www/errors;
client_max_body_size:120MB;
root:./www/web1;
index:index.html;
autoindex: on;
};
2 changes: 1 addition & 1 deletion conf/simple.conf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ server:{
alias:./www/web4;
allow_methods: GET, POST, DELETE;
autoindex:on;
cgi_path:/bin/sh;
cgi_enabled: true;
cgi_extension:cgi;
}
};
Expand Down
8 changes: 4 additions & 4 deletions mandatory/inc/Attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: eavedill <eavedill@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/07 18:22:35 by eavedill #+# #+# */
/* Updated: 2024/06/15 14:34:07 by eavedill ### ########.fr */
/* Updated: 2024/06/30 14:29:47 by eavedill ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,10 +31,10 @@ class Attributes
Attributes();
Attributes(const std::string& filename);
~Attributes();
void setAttributesFromFile(const std::string& filename);


void setAttributesFromFile(const std::string& filename);
std::string getName() ;
bool getIsDir() ;
bool getIsDir() ;
std::string getSize() ;
std::string getDevice() ;
std::string getCreated() ;
Expand Down
65 changes: 36 additions & 29 deletions mandatory/inc/CGI.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CGI.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eavedill <eavedill@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 13:47:27 by eavedill #+# #+# */
/* Updated: 2024/06/30 15:00:16 by eavedill ### ########.fr */
/* */
/* ************************************************************************** */

#pragma once
#include <iostream>
#include <string>
Expand All @@ -12,43 +24,38 @@
#include "StatusCodesDefinition.hpp"
#include <signal.h>
#include "ExtendedString.hpp"
#include "Environment.hpp"

class CGI
class CGI : public Environment
{
private:
std::string CGIFolder;
std::string fileName;
std::string fileArgs;
bool isCGI;
std::vector <ExtendedString> args;
std::map<std::string, std::string> CGIExtensions;
std::string CGIFolder;
std::string fileName;
std::string fileArgs;
bool isCGI;
std::vector <ExtendedString> args;
std::map<std::string, std::string> CGIExtensions;

public:
CGI();
CGI(const std::string &, const std::string &);
CGI(const CGI &);
~CGI();
//------ Setters and Getters ------//
//setters
void setCGIFolder(const std::string &);
void setFileName(const std::string&, const std::string&);
void setIsCGI(bool);
bool setIdentifyCGIFromFileName(const std::string &str);
bool getIsCGI();
//bool setIsCGI(const std::string &str);
void setArgs(const std::string &);
void setCGIMapExtensions(std::string const &cgi_extension);
//getters
std::string getFileName();
std::string getCGIFolder();
std::vector <ExtendedString> getArgs();
std::string getCGIExtension(const std::string &);
std::string getFileExtension();
void setCGIFolder(const std::string &);
void setFileName(const std::string&, const std::string&);
void setIsCGI(bool);
bool setIdentifyCGIFromFileName(const std::string &str);
bool getIsCGI();
void setArgs(const std::string &);
void setCGIMapExtensions(std::string const &cgi_extension);
std::string getFileName();
std::string getCGIFolder();
std::vector <ExtendedString> getArgs();
std::string getCGIExtension(const std::string &);
std::string getFileExtension();
std::string execute();
CGI *clone();
static int ChildPID;
static void alarm_handler(int);
std::map<std::string, std::string>::iterator findCGIExtension(const std::string &);
//------ OTHER Methods ------//
std::string execute();
CGI *clone();

static int ChildPID;
static void alarm_handler(int);
};
56 changes: 56 additions & 0 deletions mandatory/inc/Environment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Environment.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eavedill <eavedill@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 13:47:48 by eavedill #+# #+# */
/* Updated: 2024/06/30 14:57:33 by eavedill ### ########.fr */
/* */
/* ************************************************************************** */

#pragma once
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include "ExtendedString.hpp"

#define SCRIPT_FILENAME_KEY "SCRIPT_FILENAME"
#define QUERY_STRING_KEY "QUERY_STRING"
#define REQUEST_METHOD_KEY "REQUEST_METHOD"
#define CONTENT_TYPE_KEY "CONTENT_TYPE"
#define CONTENT_LENGTH_KEY "CONTENT_LENGTH"
#define GATEWAY_INTERFACE_KEY "GATEWAY_INTERFACE"
#define SERVER_SOFTWARE_KEY "SERVER_SOFTWARE"
#define REMOTE_ADDR_KEY "REMOTE_ADDR"
#define REMOTE_PORT_KEY "REMOTE_PORT"
#define SERVER_ADDR_KEY "SERVER_ADDR"
#define SERVER_PORT_KEY "SERVER_PORT"
#define CONTENT_LENGTH_KEY "CONTENT_LENGTH"
#define CONTENT_TYPE_KEY "CONTENT_TYPE"
#define SERVER_NAME_KEY "SERVER_NAME"
#define HTTP_HOST_KEY "HTTP_HOST"
#define HTTP_USER_AGENT_KEY "HTTP_USER_AGENT"
#define HTTP_ACCEPT_KEY "HTTP_ACCEPT"
#define HTTP_ACCEPT_LANGUAGE_KEY "HTTP_ACCEPT_LANGUAGE"
#define HTTP_ACCEPT_ENCODING_KEY "HTTP_ACCEPT_ENCODING"
#define HTTP_COOKIE_KEY "HTTP_COOKIE"
#define HTTP_CONNECTION_KEY "HTTP_CONNECTION"
#define HTTP_UPGRADE_INSECURE_REQUESTS_KEY "HTTP_UPGRADE_INSECURE_REQUESTS"
#define PATH_INFO_KEY "PATH_INFO"


class Environment
{
private:
std::map<std::string, std::string> _env;
std::vector<char*> _envArray;
public:
Environment();
~Environment();
void setEnv(const std::string $key, const std::string $value);
std::vector<char*> getEnv();
std::string getEnv(std::string key);
};
52 changes: 30 additions & 22 deletions mandatory/inc/ExtendedString.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ExtendedString.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eavedill <eavedill@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 13:47:57 by eavedill #+# #+# */
/* Updated: 2024/06/30 14:56:55 by eavedill ### ########.fr */
/* */
/* ************************************************************************** */

#pragma once
#include <sstream>
#include <string>
#include <unistd.h>
#include <vector>
#include "utils.hpp"

class ExtendedString : public std::string {
public:
//using std::string::string; // Inherit constructors from std::string
ExtendedString();
ExtendedString(const std::string &str);
~ExtendedString();
ExtendedString &operator=(const std::string &str);

bool isNumber() const;
bool firstCharIsSign() const;
void replaceString(const std::string& , const std::string& );
bool validIPAddress();
size_t stringToSizeT();
std::vector<ExtendedString> splitString(char );
//***To be used in case do not want to modify the original string
//ExtendedString removeCharFromString(char);
void removeCharFromString(char);
//***To be used in case do not want to modify the original string
// ExtendedString removeBlanksAndTabs() ;
void removeBlanksAndTabs() ;
int count_chars(char c);
void replaceFirstString(const std::string& searchString, const std::string& replaceString);
class ExtendedString : public std::string
{
public:
ExtendedString();
ExtendedString(const std::string &str);
~ExtendedString();
ExtendedString &operator=(const std::string &str);

bool isNumber() const;
bool firstCharIsSign() const;
void replaceString(const std::string& , const std::string& );
bool validIPAddress();
size_t stringToSizeT();
std::vector<ExtendedString> splitString(char );
void removeCharFromString(char);
void removeBlanksAndTabs() ;
int count_chars(char c);
void replaceFirstString(const std::string& searchString, const std::string& replaceString);

};
Loading

0 comments on commit 6c1588a

Please sign in to comment.