anope

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

modes.cpp (3275B)

      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 #include "utils.h"
     10 
     11 WebCPanel::ChanServ::Modes::Modes(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
     12 {
     13 }
     14 
     15 bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
     16 {
     17 	const Anope::string &chname = message.get_data["channel"];
     18 	const Anope::string &mode = message.get_data["m"];
     19 	TemplateFileServer Page("chanserv/modes.html");
     20 
     21 	BuildChanList(na, replacements);
     22 
     23 	if (chname.empty())
     24 	{
     25 		Page.Serve(server, page_name, client, message, reply, replacements);
     26 		return true;
     27 	}
     28 
     29 	replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname);
     30 	ChannelInfo *ci = ChannelInfo::Find(chname);
     31 
     32 	if (!ci)
     33 	{
     34 		Page.Serve(server, page_name, client, message, reply, replacements);
     35 		return true;
     36 	}
     37 
     38 	Channel *c = Channel::Find(chname);
     39 
     40 	if (!c)
     41 	{
     42 		replacements["MESSAGES"] = Anope::printf(CHAN_X_NOT_IN_USE, chname.c_str());
     43 		Page.Serve(server, page_name, client, message, reply, replacements);
     44 		return true;
     45 	}
     46 
     47 	AccessGroup u_access = ci->AccessFor(na->nc);
     48 	bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/administration");
     49 
     50 	if (!u_access.HasPriv("MODE") && !has_priv)
     51 	{
     52 		replacements["MESSAGES"] = "Access denied.";
     53 		Page.Serve(server, page_name, client, message, reply, replacements);
     54 		return true;
     55 	}
     56 
     57 	replacements["MODE"] = "YES";
     58 
     59 	/* build a list with the names of all listmodes */
     60 	for (unsigned i = 0; i < ModeManager::GetChannelModes().size(); ++i)
     61 	{
     62 		ChannelMode *cm = ModeManager::GetChannelModes()[i];
     63 
     64 		if (cm->type == MODE_LIST && cm->mchar)
     65 			replacements["LISTMODES"] = cm->mchar;
     66 	}
     67 
     68 	if (mode.empty())
     69 	{
     70 		Page.Serve(server, page_name, client, message, reply, replacements);
     71 		return true;
     72 	}
     73 	replacements["ESCAPED_MODE"] = HTTPUtils::URLEncode(mode);
     74 
     75 	ChannelMode *cm = ModeManager::FindChannelModeByChar(mode[0]);
     76 	if (cm)
     77 	{
     78 		if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
     79 		{
     80 			std::vector<Anope::string> params;
     81 			params.push_back(ci->name);
     82 			params.push_back("SET");
     83 			params.push_back("-" + Anope::string(cm->mchar));
     84 			params.push_back(message.get_data["mask"]);
     85 			WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements);
     86 		}
     87 		else if (message.post_data["mask"].empty() == false)
     88 		{
     89 			std::vector<Anope::string> params;
     90 			params.push_back(ci->name);
     91 			params.push_back("SET");
     92 			params.push_back("+" + Anope::string(cm->mchar));
     93 			params.push_back(message.post_data["mask"]);
     94 			WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements);
     95 		}
     96 
     97 		std::vector<Anope::string> v = c->GetModeList(cm->name);
     98 		for (unsigned int i = 0; i < v.size(); ++i)
     99 			replacements["MASKS"] = v[i];
    100 	}
    101 
    102 	Page.Serve(server, page_name, client, message, reply, replacements);
    103 	return true;
    104 }
    105 
    106 std::set<Anope::string> WebCPanel::ChanServ::Modes::GetData()
    107 {
    108 	std::set<Anope::string> v;
    109 	v.insert("channel");
    110 	return v;
    111 }