mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 05:17:59 +03:00
update: Autoindex class
This commit is contained in:
@@ -4,7 +4,7 @@ Autoindex::Autoindex()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Autoindex::getPage(std::string path, std::string allpath, std::string host)
|
std::string Autoindex::getPage(std::string path, std::string allpath, std::string host, int port)
|
||||||
{
|
{
|
||||||
DIR *dir = opendir(allpath.c_str());
|
DIR *dir = opendir(allpath.c_str());
|
||||||
struct dirent *dirEnt;
|
struct dirent *dirEnt;
|
||||||
@@ -31,17 +31,17 @@ std::string Autoindex::getPage(std::string path, std::string allpath, std::strin
|
|||||||
{
|
{
|
||||||
tmp = dirEnt->d_name;
|
tmp = dirEnt->d_name;
|
||||||
if (tmp != ".." && tmp != ".")
|
if (tmp != ".." && tmp != ".")
|
||||||
page = page + getReference(tmp, path, host);
|
page = page + getReference(tmp, path, host, port);
|
||||||
}
|
}
|
||||||
page += "</p>\n</body>\n</html>\n";
|
page += "</p>\n</body>\n</html>\n";
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return (page);
|
return (page);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Autoindex::getReference(std::string file, std::string dir, std::string host)
|
std::string Autoindex::getReference(std::string file, std::string dir, std::string host, int port)
|
||||||
{
|
{
|
||||||
std::stringstream link;
|
std::stringstream link;
|
||||||
link << "\t\t<p><a href=\"http://" << host
|
link << "\t\t<p><a href=\"http://" << host << ":" << port
|
||||||
<< dir;
|
<< dir;
|
||||||
if (dir[dir.length() - 1] != '/')
|
if (dir[dir.length() - 1] != '/')
|
||||||
link << "/";
|
link << "/";
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Autoindex();
|
Autoindex();
|
||||||
static std::string getPage(std::string path, std::string allpath, std::string host);
|
static std::string getPage(std::string path, std::string allpath, std::string host, int port);
|
||||||
static std::string getReference(std::string file, std::string dir, std::string host);
|
static std::string getReference(std::string file, std::string dir, std::string host, int port);
|
||||||
~Autoindex();
|
~Autoindex();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user