Permalink
Browse files

Merge pull request #526 from anders/q-nocloakdefault

Q module: Store default NVs and better default host cloak behavior, web page
  • Loading branch information...
2 parents 8ccd95b + 5a7796f commit 6bf48c2c6c51101144782cbdf49738191cd8b500 @DarthGandalf DarthGandalf committed Apr 12, 2014
Showing with 124 additions and 3 deletions.
  1. +45 −0 modules/data/q/tmpl/index.tmpl
  2. +79 −3 modules/q.cpp
@@ -0,0 +1,45 @@
+<? INC Header.tmpl ?>
+
+<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>" method="post">
+ <? INC _csrf_check.tmpl ?>
+ <div class="section">
+ <h3>Q</h3>
+ <div class="sectionbg">
+ <div class="sectionbody">
+ <div class="subsection">
+ <div class="inputlabel">Username:</div>
+ <input type="text" name="user" value="<? VAR Username ?>" class="half" maxlength="128"
+ title="Please enter a username." />
+ </div>
+ <div class="subsection">
+ <div class="inputlabel">Password:</div>
+ <input type="password" name="password" class="half"
+ title="Please enter a password." autocomplete="off" />
+ </div>
+ <div style="clear: both;"></div>
+ </div>
+ </div>
+ </div>
+
+ <div class="section">
+ <h3>Options</h3>
+ <div class="sectionbg">
+ <div class="sectionbody lotsofcheckboxes">
+ <? LOOP OptionLoop ?>
+ <span class="checkboxandlabel" title="<? VAR Tooltip ?>">
+ <input type="checkbox" name="<? VAR Name ?>" id="opt_<? VAR Name ?>" value="1"<? IF Checked ?> checked="checked"<? ENDIF ?><? IF Disabled ?> disabled="disabled"<? ENDIF ?> />
+ <label for="opt_<? VAR Name ?>"><? VAR DisplayName ?></label>
+ </span>
+ <? ENDLOOP ?>
+ <div style="clear:both;"></div>
+ </div>
+ </div>
+ </div>
+
+ <div class="submitline">
+ <input type="hidden" name="submitted" value="1" />
+ <input type="submit" value="Save" />
+ </div>
+</form>
+
+<? INC Footer.tmpl ?>
View
@@ -45,6 +45,11 @@ class CQModule : public CModule {
m_bRequestPerms = GetNV("RequestPerms").ToBool();
m_bJoinOnInvite = (sTmp = GetNV("JoinOnInvite")).empty() ? true : sTmp.ToBool();
+ // Make sure NVs are stored in config. Note: SetUseCloakedHost() is called further down.
+ SetUseChallenge(m_bUseChallenge);
+ SetRequestPerms(m_bRequestPerms);
+ SetJoinOnInvite(m_bJoinOnInvite);
+
OnIRCDisconnected(); // reset module's state
if (IsIRCConnected()) {
@@ -53,7 +58,21 @@ class CQModule : public CModule {
if (scUserModes.find('x') != scUserModes.end())
m_bCloaked = true;
- OnIRCConnected();
+ // This will only happen once, and only if the user loads the module after connecting to IRC.
+ // Also don't notify the user in case he already had mode +x set.
+ if (GetNV("UseCloakedHost").empty()) {
+ if (!m_bCloaked)
+ PutModule("Notice: Your host will be cloaked the next time you reconnect to IRC. "
+ "If you want to cloak your host now, /msg *q Cloak. You can set your preference "
+ "with /msg *q Set UseCloakedHost true/false.");
+ m_bUseCloakedHost = true;
+ SetUseCloakedHost(m_bUseCloakedHost);
+ } else if (m_bUseChallenge) {
+ Cloak();
+ }
+ WhoAmI();
+ } else {
+ SetUseCloakedHost(m_bUseCloakedHost);
}
return true;
@@ -149,8 +168,6 @@ class CQModule : public CModule {
} else if (sSetting == "usecloakedhost") {
SetUseCloakedHost(sValue.ToBool());
PutModule("UseCloakedHost set");
- if (m_bUseCloakedHost && IsIRCConnected())
- Cloak();
} else if (sSetting == "usechallenge") {
SetUseChallenge(sValue.ToBool());
PutModule("UseChallenge set");
@@ -261,6 +278,62 @@ class CQModule : public CModule {
return CONTINUE;
}
+ virtual CString GetWebMenuTitle() { return "Q"; }
+
+ virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
+ 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());
+ }
+
+ 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);
+
+ if (bSubmitted) {
+ WebSock.GetSession()->AddSuccess("Changes have been saved!");
+ }
+
+ return true;
+ }
+
+ return false;
+ }
private:
bool m_bCloaked;
@@ -499,6 +572,9 @@ class CQModule : public CModule {
void SetUseCloakedHost(const bool bUseCloakedHost) {
m_bUseCloakedHost = bUseCloakedHost;
SetNV("UseCloakedHost", CString(bUseCloakedHost));
+
+ if (!m_bCloaked && m_bUseCloakedHost && IsIRCConnected())
+ Cloak();
}
void SetUseChallenge(const bool bUseChallenge) {

0 comments on commit 6bf48c2

Please sign in to comment.