anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

info.cpp (3836B)

      1 /*
      2  * (C) 2003-2022 Anope Team
      3  * Contact us at team@anope.org
      4  *
      5  * Please read COPYING and README for further details.
      6  */
      7 
      8 #include "../../webcpanel.h"
      9 
     10 WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
     11 {
     12 }
     13 
     14 bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
     15 {
     16 	if (message.post_data.empty() == false)
     17 	{
     18 		if (message.post_data.count("email") > 0)
     19 		{
     20 			if (message.post_data["email"] != na->nc->email)
     21 			{
     22 				if (!message.post_data["email"].empty() && !Mail::Validate(message.post_data["email"]))
     23 					replacements["ERRORS"] = "Invalid email";
     24 				else
     25 				{
     26 					na->nc->email = message.post_data["email"];
     27 					replacements["MESSAGES"] = "Email updated";
     28 				}
     29 			}
     30 		}
     31 		if (message.post_data.count("greet") > 0)
     32 		{
     33 			Anope::string *greet = na->nc->GetExt<Anope::string>("greet");
     34 			const Anope::string &post_greet = HTTPUtils::URLDecode(message.post_data["greet"].replace_all_cs("+", " "));
     35 
     36 			if (post_greet.empty())
     37 				na->nc->Shrink<Anope::string>("greet");
     38 			else if (!greet || post_greet != *greet)
     39 				na->nc->Extend<Anope::string>("greet", post_greet);
     40 
     41 			replacements["MESSAGES"] = "Greet updated";
     42 		}
     43 		if (na->nc->HasExt("AUTOOP") != message.post_data.count("autoop"))
     44 		{
     45 			if (!na->nc->HasExt("AUTOOP"))
     46 				na->nc->Extend<bool>("AUTOOP");
     47 			else
     48 				na->nc->Shrink<bool>("AUTOOP");
     49 			replacements["MESSAGES"] = "Autoop updated";
     50 		}
     51 		if (na->nc->HasExt("NS_PRIVATE") != message.post_data.count("private"))
     52 		{
     53 			if (!na->nc->HasExt("NS_PRIVATE"))
     54 				na->nc->Extend<bool>("NS_PRIVATE");
     55 			else
     56 				na->nc->Shrink<bool>("NS_PRIVATE");
     57 			replacements["MESSAGES"] = "Private updated";
     58 		}
     59 		if (na->nc->HasExt("NS_SECURE") != message.post_data.count("secure"))
     60 		{
     61 			if (!na->nc->HasExt("NS_SECURE"))
     62 				na->nc->Extend<bool>("NS_SECURE");
     63 			else
     64 				na->nc->Shrink<bool>("NS_SECURE");
     65 			replacements["MESSAGES"] = "Secure updated";
     66 		}
     67 		if (message.post_data["kill"] == "on" && !na->nc->HasExt("KILLPROTECT"))
     68 		{
     69 			na->nc->Extend<bool>("KILLPROTECT");
     70 			na->nc->Shrink<bool>("KILL_QUICK");
     71 			replacements["MESSAGES"] = "Kill updated";
     72 		}
     73 		else if (message.post_data["kill"] == "quick" && !na->nc->HasExt("KILL_QUICK"))
     74 		{
     75 			na->nc->Extend<bool>("KILLPROTECT");
     76 			na->nc->Extend<bool>("KILL_QUICK");
     77 			replacements["MESSAGES"] = "Kill updated";
     78 		}
     79 		else if (message.post_data["kill"] == "off" && (na->nc->HasExt("KILLPROTECT") || na->nc->HasExt("KILL_QUICK")))
     80 		{
     81 			na->nc->Shrink<bool>("KILLPROTECT");
     82 			na->nc->Shrink<bool>("KILL_QUICK");
     83 			replacements["MESSAGES"] = "Kill updated";
     84 		}
     85 	}
     86 
     87 	replacements["DISPLAY"] = na->nc->display;
     88 	if (na->nc->email.empty() == false)
     89 		replacements["EMAIL"] = na->nc->email;
     90 	replacements["TIME_REGISTERED"] = Anope::strftime(na->time_registered, na->nc);
     91 	if (na->HasVhost())
     92 	{
     93 		if (na->GetVhostIdent().empty() == false)
     94 			replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
     95 		else
     96 			replacements["VHOST"] = na->GetVhostHost();
     97 	}
     98 	Anope::string *greet = na->nc->GetExt<Anope::string>("greet");
     99 	if (greet)
    100 		replacements["GREET"] = *greet;
    101 	if (na->nc->HasExt("AUTOOP"))
    102 		replacements["AUTOOP"];
    103 	if (na->nc->HasExt("NS_PRIVATE"))
    104 		replacements["PRIVATE"];
    105 	if (na->nc->HasExt("NS_SECURE"))
    106 		replacements["SECURE"];
    107 	if (na->nc->HasExt("KILLPROTECT"))
    108 		replacements["KILL_ON"];
    109 	if (na->nc->HasExt("KILL_QUICK"))
    110 		replacements["KILL_QUICK"];
    111 	if (!na->nc->HasExt("KILLPROTECT") && !na->nc->HasExt("KILL_QUICK"))
    112 		replacements["KILL_OFF"];
    113 
    114 	TemplateFileServer page("nickserv/info.html");
    115 	page.Serve(server, page_name, client, message, reply, replacements);
    116 	return true;
    117 }