示例#1
0
 void HandleMessage(CNick& Nick, const CString& sMessage) {
     CString sNickServName = (!GetNV("NickServName").empty())
                                 ? GetNV("NickServName")
                                 : "NickServ";
     if (!GetNV("Password").empty() && Nick.NickEquals(sNickServName) &&
         (sMessage.find("msg") != CString::npos ||
          sMessage.find("authenticate") != CString::npos ||
          sMessage.find("choose a different nickname") != CString::npos ||
          sMessage.find("please choose a different nick") != CString::npos ||
          sMessage.find("If this is your nick, identify yourself with") !=
              CString::npos ||
          sMessage.find("If this is your nick, type") != CString::npos ||
          sMessage.find("This is a registered nickname, please identify") !=
              CString::npos ||
          sMessage.StripControls_n().find(
              "type /NickServ IDENTIFY password") != CString::npos ||
          sMessage.StripControls_n().find(
              "type /msg NickServ IDENTIFY password") != CString::npos) &&
         sMessage.AsUpper().find("IDENTIFY") != CString::npos &&
         sMessage.find("help") == CString::npos) {
         MCString msValues;
         msValues["password"] = GetNV("Password");
         PutIRC(CString::NamedFormat(GetNV("IdentifyCmd"), msValues));
     }
 }
示例#2
0
文件: log.cpp 项目: Adam-/znc
void CLogMod::PutLog(const CString& sLine,
                     const CString& sWindow /*= "Status"*/) {
    if (!TestRules(sWindow)) {
        return;
    }

    CString sPath;
    time_t curtime;

    time(&curtime);
    // Generate file name
    sPath = CUtils::FormatTime(curtime, m_sLogPath, GetUser()->GetTimezone());
    if (sPath.empty()) {
        DEBUG("Could not format log path [" << sPath << "]");
        return;
    }

    // TODO: Properly handle IRC case mapping
    // $WINDOW has to be handled last, since it can contain %
    sPath.Replace("$USER",
                  CString((GetUser() ? GetUser()->GetUserName() : "UNKNOWN")));
    sPath.Replace("$NETWORK",
                  CString((GetNetwork() ? GetNetwork()->GetName() : "znc")));
    sPath.Replace("$WINDOW", CString(sWindow.Replace_n("/", "-")
                                         .Replace_n("\\", "-")).AsLower());

    // Check if it's allowed to write in this specific path
    sPath = CDir::CheckPathPrefix(GetSavePath(), sPath);
    if (sPath.empty()) {
        DEBUG("Invalid log path [" << m_sLogPath << "].");
        return;
    }

    CFile LogFile(sPath);
    CString sLogDir = LogFile.GetDir();
    struct stat ModDirInfo;
    CFile::GetInfo(GetSavePath(), ModDirInfo);
    if (!CFile::Exists(sLogDir)) CDir::MakeDir(sLogDir, ModDirInfo.st_mode);
    if (LogFile.Open(O_WRONLY | O_APPEND | O_CREAT)) {
        LogFile.Write(CUtils::FormatTime(curtime, m_sTimestamp,
                                         GetUser()->GetTimezone()) +
                      " " + (m_bSanitize ? sLine.StripControls_n() : sLine) +
                      "\n");
    } else
        DEBUG("Could not open log file [" << sPath << "]: " << strerror(errno));
}