Esempio n. 1
0
	virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
		if (sPageName.empty() || sPageName == "index") {
			CModules& GModules = CZNC::Get().GetModules();
			Tmpl["WebAdminLoaded"] = CString(GModules.FindModule("webadmin") != NULL);

			MTimeMulti mmSorted;
			const MUsers& mUsers = CZNC::Get().GetUserMap();

			for (MUsers::const_iterator uit = mUsers.begin(); uit != mUsers.end(); ++uit) {
				mmSorted.insert(pair<time_t, CUser*>(GetTime(uit->second), uit->second));
			}

			for (MTimeMulti::const_iterator it = mmSorted.begin(); it != mmSorted.end(); ++it) {
				CUser *pUser = it->second;
				CTemplate& Row = Tmpl.AddRow("UserLoop");

				Row["Username"] = pUser->GetUserName();
				Row["IsSelf"] = CString(pUser == WebSock.GetSession()->GetUser());
				Row["LastSeen"] = FormatLastSeen(pUser, "never");

				Row["Info"] = CString(pUser->GetClients().size()) +
					" client" + CString(pUser->GetClients().size() == 1 ? "" : "s");
				if(!pUser->GetCurrentServer()) {
					Row["Info"] += ", not connected to IRC";
				} else {
					unsigned int uChans = 0;
					const vector<CChan*>& vChans = pUser->GetChans();
					for (unsigned int a = 0; a < vChans.size(); ++a) {
						if (vChans[a]->IsOn()) ++uChans;
					}
					unsigned int n = uChans;
					Row["Info"] += ", joined to " + CString(uChans);
					if(uChans != vChans.size()) {
						Row["Info"] += " out of " + CString(vChans.size()) + " configured";
						n = vChans.size();
					}
					Row["Info"] += " channel" + CString(n == 1 ? "" : "s");
				}
			}

			return true;
		}

		return false;
	}
Esempio n. 2
0
	virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
		if (sPageName == "index") {
			for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
				CTemplate& Row = Tmpl.AddRow("NotesLoop");

				Row["Key"] = it->first;
				Row["Note"] = it->second;
			}

			return true;
		} else if (sPageName == "delnote") {
			DelNote(WebSock.GetParam("key", false));
			WebSock.Redirect("/mods/notes/");
			return true;
		} else if (sPageName == "addnote") {
			AddNote(WebSock.GetParam("key"), WebSock.GetParam("note"));
			WebSock.Redirect("/mods/notes/");
			return true;
		}

		return false;
	}
Esempio n. 3
0
	virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
		CUser *pUser = WebSock.GetSession()->GetUser();

		if (sPageName == "index") {
			MSCString::iterator it = m_PubKeys.find(pUser->GetUserName());
			if (it != m_PubKeys.end()) {
				SCString::iterator it2;

				for (it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
					CTemplate& row = Tmpl.AddRow("KeyLoop");
					row["Key"] = *it2;
				}
			}

			return true;
		} else if (sPageName == "add") {
			AddKey(pUser, WebSock.GetParam("key"));
			WebSock.Redirect(GetWebPath());
			return true;
		} else if (sPageName == "delete") {
			MSCString::iterator it = m_PubKeys.find(pUser->GetUserName());
			if (it != m_PubKeys.end()) {
				if (it->second.erase(WebSock.GetParam("key", false))) {
					if (it->second.size() == 0) {
						m_PubKeys.erase(it);
					}

					Save();
				}
			}

			WebSock.Redirect(GetWebPath());
			return true;
		}

		return false;
	}
Esempio n. 4
0
bool CLogMod::OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
	CFile LogFile(m_sLogPath);
  CDir  LogDir (LogFile.GetDir());
  for(std::vector<CFile*>::iterator it = LogDir.begin(); it != LogDir.end(); ++it) {
    CTemplate& Row = Tmpl.AddRow("LogsLoop");
    Row["File"] = (**it).GetShortName();
  }
  if (WebSock.HasParam("file", false)) {
    CString path = CDir::CheckPathPrefix(GetSavePath(), LogFile.GetDir() + WebSock.GetParam("file", false));
    if (path.empty()) {
      WebSock.PrintErrorPage("Invalid Path");
      return true;
    }

    CFile DisplayFile(path);
    CString content;

    DisplayFile.Open();

    int PageSize = 1024 * 1024;
    int Page = 0;
    if (WebSock.HasParam("page", false)) {
      Page = WebSock.GetParam("page", false).ToInt();
      DisplayFile.Seek(Page * PageSize);
    }
    Tmpl["Prev"] = CString(Page - 1);
    Tmpl["Next"] = CString(Page + 1);
    Tmpl["Curr"] = WebSock.GetParam("file", false);

    DisplayFile.ReadFile(content, PageSize);
    DisplayFile.Close();
    
    Tmpl["Log"] = content;
  }
  return true;
}
Esempio n. 5
0
	bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) override {
		if (sPageName != "index") {
			// only accept requests to index
			return false;
		}

		if (WebSock.IsPost()) {
			VCString vsPerf;
			WebSock.GetRawParam("perform", true).Split("\n", vsPerf, false);
			m_vPerform.clear();

			for (const CString& sPerf : vsPerf)
				m_vPerform.push_back(ParsePerform(sPerf));

			Save();
		}

		for (const CString& sPerf : m_vPerform) {
			CTemplate& Row = Tmpl.AddRow("PerformLoop");
			Row["Perform"] = sPerf;
		}

		return true;
	}
Esempio n. 6
0
	virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
		if (sPageName != "index") {
			// only accept requests to /mods/perform/
			return false;
		}

		if (WebSock.IsPost()) {
			VCString vsPerf;
			WebSock.GetRawParam("perform", true).Split("\n", vsPerf, false);
			m_vPerform.clear();

			for (VCString::const_iterator it = vsPerf.begin(); it != vsPerf.end(); ++it)
				m_vPerform.push_back(ParsePerform(*it));

			Save();
		}

		for (VCString::const_iterator it = m_vPerform.begin(); it != m_vPerform.end(); ++it) {
			CTemplate& Row = Tmpl.AddRow("PerformLoop");
			Row["Perform"] = *it;
		}

		return true;
	}
Esempio n. 7
0
File: q.cpp Progetto: Adam-/znc
    bool OnWebRequest(CWebSock& WebSock, const CString& sPageName,
                      CTemplate& Tmpl) override {
        if (sPageName == "index") {
            bool bSubmitted = (WebSock.GetParam("submitted").ToInt() != 0);

            if (bSubmitted) {
                CString FormUsername = WebSock.GetParam("user");
                if (!FormUsername.empty()) SetUsername(FormUsername);

                CString FormPassword = WebSock.GetParam("password");
                if (!FormPassword.empty()) SetPassword(FormPassword);

                SetUseCloakedHost(WebSock.GetParam("usecloakedhost").ToBool());
                SetUseChallenge(WebSock.GetParam("usechallenge").ToBool());
                SetRequestPerms(WebSock.GetParam("requestperms").ToBool());
                SetJoinOnInvite(WebSock.GetParam("joinoninvite").ToBool());
                SetJoinAfterCloaked(
                    WebSock.GetParam("joinaftercloaked").ToBool());
            }

            Tmpl["Username"] = m_sUsername;

            CTemplate& o1 = Tmpl.AddRow("OptionLoop");
            o1["Name"] = "usecloakedhost";
            o1["DisplayName"] = "UseCloakedHost";
            o1["Tooltip"] =
                "Whether to cloak your hostname (+x) automatically on connect.";
            o1["Checked"] = CString(m_bUseCloakedHost);

            CTemplate& o2 = Tmpl.AddRow("OptionLoop");
            o2["Name"] = "usechallenge";
            o2["DisplayName"] = "UseChallenge";
            o2["Tooltip"] =
                "Whether to use the CHALLENGEAUTH mechanism to avoid sending "
                "passwords in cleartext.";
            o2["Checked"] = CString(m_bUseChallenge);

            CTemplate& o3 = Tmpl.AddRow("OptionLoop");
            o3["Name"] = "requestperms";
            o3["DisplayName"] = "RequestPerms";
            o3["Tooltip"] =
                "Whether to request voice/op from Q on join/devoice/deop.";
            o3["Checked"] = CString(m_bRequestPerms);

            CTemplate& o4 = Tmpl.AddRow("OptionLoop");
            o4["Name"] = "joinoninvite";
            o4["DisplayName"] = "JoinOnInvite";
            o4["Tooltip"] = "Whether to join channels when Q invites you.";
            o4["Checked"] = CString(m_bJoinOnInvite);

            CTemplate& o5 = Tmpl.AddRow("OptionLoop");
            o5["Name"] = "joinaftercloaked";
            o5["DisplayName"] = "JoinAfterCloaked";
            o5["Tooltip"] =
                "Whether to delay joining channels until after you are "
                "cloaked.";
            o5["Checked"] = CString(m_bJoinAfterCloaked);

            if (bSubmitted) {
                WebSock.GetSession()->AddSuccess("Changes have been saved!");
            }

            return true;
        }

        return false;
    }