diff options
Diffstat (limited to 'modules/webcpanel/template_fileserver.cpp')
-rw-r--r-- | modules/webcpanel/template_fileserver.cpp | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/modules/webcpanel/template_fileserver.cpp b/modules/webcpanel/template_fileserver.cpp index 3a8f96725..1ecbfae4b 100644 --- a/modules/webcpanel/template_fileserver.cpp +++ b/modules/webcpanel/template_fileserver.cpp @@ -1,8 +1,20 @@ /* - * (C) 2003-2017 Anope Team - * Contact us at team@anope.org + * Anope IRC Services * - * Please read COPYING and README for further details. + * Copyright (C) 2012-2017 Anope Team <team@anope.org> + * + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "webcpanel.h" @@ -79,7 +91,7 @@ static Anope::string FindReplacement(const TemplateFileServer::Replacements &r, } } } - + TemplateFileServer::Replacements::const_iterator it = r.find(key); if (it != r.end()) return it->second; @@ -95,7 +107,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n int fd = open((template_base + "/" + this->file_name).c_str(), O_RDONLY); if (fd < 0) { - Log(LOG_NORMAL, "httpd") << "Error serving file " << page_name << " (" << (template_base + "/" + this->file_name) << "): " << strerror(errno); + Anope::Logger.Category("webcpanel").Log("Error serving file {0} ({1}/{2}): {3}", page_name, template_base, this->file_name, strerror(errno)); client->SendError(HTTP_PAGE_NOT_FOUND, "Page not found"); return; @@ -110,7 +122,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n buffer[i] = 0; buf += buffer; } - + close(fd); Anope::string finished; @@ -149,12 +161,16 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n IfStack.push(stackok && r.count(tokens[2]) > 0); } else - Log() << "Invalid IF in web template " << this->file_name; + { + Anope::Logger.Log("Invalid IF in web template {0}", this->file_name); + } } else if (content == "ELSE") { if (IfStack.empty()) - Log() << "Invalid ELSE with no stack in web template" << this->file_name; + { + Anope::Logger.Log("Invalid ELSE with no stack in web template {0}", this->file_name); + } else { bool old = IfStack.top(); @@ -166,7 +182,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n else if (content == "END IF") { if (IfStack.empty()) - Log() << "END IF with empty stack?"; + Anope::Logger.Log("END IF with empty stack?"); else IfStack.pop(); } @@ -176,7 +192,9 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n spacesepstream(content).GetTokens(tokens); if (tokens.size() != 4 || tokens[2] != "IN") - Log() << "Invalid FOR in web template " << this->file_name; + { + Anope::Logger.Log("Invalid FOR in web template {0}", this->file_name); + } else { std::vector<Anope::string> temp_variables, real_variables; @@ -184,7 +202,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n commasepstream(tokens[3]).GetTokens(real_variables); if (temp_variables.size() != real_variables.size()) - Log() << "Invalid FOR in web template " << this->file_name << " variable mismatch"; + Anope::Logger.Log("Invalid FOR in web template {0} variable mismatch", this->file_name); else ForLoop::Stack.push_back(ForLoop(j + f, r, temp_variables, real_variables)); } @@ -192,7 +210,9 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n else if (content == "END FOR") { if (ForLoop::Stack.empty()) - Log() << "END FOR with empty stack?"; + { + Anope::Logger.Log("END FOR with empty stack?"); + } else { ForLoop &fl = ForLoop::Stack.back(); @@ -217,7 +237,9 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n spacesepstream(content).GetTokens(tokens); if (tokens.size() != 2) - Log() << "Invalid INCLUDE in web template " << this->file_name; + { + Anope::Logger.Log("Invalid INCLUDE in web template {0}", this->file_name); + } else { if (!finished.empty()) @@ -235,7 +257,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n // If the if stack is empty or we are in a true statement bool ifok = IfStack.empty() || IfStack.top(); bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r); - + if (ifok && forok) { const Anope::string &replacement = FindReplacement(r, content.substr(0, f - 1)); @@ -252,7 +274,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n // If the if stack is empty or we are in a true statement bool ifok = IfStack.empty() || IfStack.top(); bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r); - + if (ifok && forok) finished += buf[j]; } |