diff --git a/second/index.html b/second/index.html new file mode 100644 index 0000000..8e63e83 --- /dev/null +++ b/second/index.html @@ -0,0 +1,164 @@ + + + + +Название сайта + + + + + + + + + +
+ + + + + + + + + + +
+ +

Название сайта (организации)

+

Описание сайта

+ +
+ + + + + + + + + + + + + + + + + + + + + +
+

Страница

+ +

+Здравствуйте уважаемые будущие веб-мастера! +Мне 55 лет и я рад приветствовать Вас на своём сайте. +Этот сайт первый, который я разработал самостоятельно, +а до этого умел только входить в интернет.

+ +

Почему я решил его сделать? +За те 3 месяца, пока разбирался в +сайтостроении и создавал этот ресурс обнаружилось, +что авторы руководств по созданию +сайтов считают многие нюансы само собой разумеющимися +и не обращают на них внимание +А мне, учитывая возраст и «опыт», было не просто +понять как раз эти нюансы, они отнимали больше всего +времени.

+ +
+

Меню

+ +

+ + + + + +Страница + +

+

+ + +Страница 1 +

+

+ + +Страница 2 +

+ +
+

Общая информация

+

Текст общей информации или реклама

+ +
+ + + + + + + + + + +
+

Подвал

+ +
+ +
+ + \ No newline at end of file diff --git a/src/Server/ServerConfig.cpp b/src/Server/ServerConfig.cpp index d0efac0..0fcc7bc 100644 --- a/src/Server/ServerConfig.cpp +++ b/src/Server/ServerConfig.cpp @@ -316,33 +316,59 @@ void ServerConfig::fillFields(void) checkConfig(); } +int ServerConfig::isFile(std::string path) +{ + struct stat s; + + if (stat(path.c_str(), &s) == 0) + { + if (s.st_mode & S_IFDIR) + return (-1); + else if (s.st_mode & S_IFREG) + return (0); + } + else + return (-1); + return (-1); +} + +int ServerConfig::isDir(std::string path) +{ + struct stat s; + + if (stat(path.c_str(), &s) == 0) + { + if (s.st_mode & S_IFDIR) + return (0); + else if (s.st_mode & S_IFREG) + return (-1); + } + else + return (-1); + return (-1); +} + bool ServerConfig::checkFileAndDir(location *loc) { std::string root = loc->root; std::string upload_dir = loc->uploadDir; std::string directory_file = loc->directoryFile; - DIR *dir; + if (!root.empty()) { - dir = opendir(root.c_str()); - if (dir == NULL) - throw ConfigException("Directory " + root + " " + strerror(errno) + "!"); - closedir(dir); + if (isDir(root) != 0) + throw ConfigException("Directory " + root + " not found!"); } if (!upload_dir.empty()) { - dir = opendir(upload_dir.c_str()); - if (dir == NULL) - throw ConfigException("Directory " + upload_dir + " " + strerror(errno) + "!"); - closedir(dir); + if (isDir(upload_dir) != 0) + throw ConfigException("Directory " + upload_dir + " not found!"); } if (!directory_file.empty()) { directory_file = root + "/" + directory_file; - std::ofstream file(directory_file.c_str(), std::ios::out | std::ios::binary); - if (!file.is_open()) - throw ConfigException("File " + directory_file + " " + strerror(errno) + "!"); - file.close(); + if (isFile(directory_file) != 0) + throw ConfigException("File " + directory_file + " not found!"); } return (true); } diff --git a/src/Server/ServerConfig.hpp b/src/Server/ServerConfig.hpp index a11e386..a91c255 100644 --- a/src/Server/ServerConfig.hpp +++ b/src/Server/ServerConfig.hpp @@ -72,6 +72,9 @@ private: std::string getTypestr(toml_node::e_type); std::string getWrongTypeErrorMSG(std::string field, toml_node::e_type expected, toml_node::e_type received); bool checkFileAndDir(location *); + int isFile(std::string path); + int isDir(std::string path); + public: void fillFields(void);