SOURCES: znc-cnu-log.cpp (NEW), znc-crox-svn-statupdate.cpp (NEW), ...
glen
glen at pld-linux.org
Sat Apr 12 23:19:00 CEST 2008
Author: glen Date: Sat Apr 12 21:19:00 2008 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- from http://home.ircnet.de/cru/znc/sources/znc-0.052-4.cru.src.rpm
---- Files affected:
SOURCES:
znc-cnu-log.cpp (NONE -> 1.1) (NEW), znc-crox-svn-statupdate.cpp (NONE -> 1.1) (NEW), znc-crox-svn-fish.cpp (NONE -> 1.1) (NEW), znc-crox-svn-antiidle.cpp (NONE -> 1.1) (NEW), znc-crox-svn-admin.cpp (NONE -> 1.1) (NEW), znc-0.052-add_denysetvhost2.diff (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/znc-cnu-log.cpp
diff -u /dev/null SOURCES/znc-cnu-log.cpp:1.1
--- /dev/null Sat Apr 12 23:19:00 2008
+++ SOURCES/znc-cnu-log.cpp Sat Apr 12 23:18:55 2008
@@ -0,0 +1,213 @@
+/*
+ * CNU's Logging Module
+ * Copyright (C) 2006-2007, CNU <bshalm at broadpark.no> (http://cnu.dieplz.net/znc)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <iomanip>
+#include <fstream>
+#include <sstream>
+#include <ctime>
+#include "main.h"
+#include "User.h"
+#include "Nick.h"
+#include "Modules.h"
+#include "Chan.h"
+#include "Server.h"
+
+class CLogMod: public CModule {
+public:
+ MODCONSTRUCTOR(CLogMod) {}
+
+ void PutLog(const CString& sLine, const CString& sWindow = "Status");
+ CString GetServer();
+
+ virtual void OnIRCConnected();
+ virtual void OnIRCDisconnected();
+ virtual EModRet OnBroadcast(CString& sMessage);
+
+ virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
+ virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
+ virtual void OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans);
+ virtual void OnJoin(const CNick& Nick, CChan& Channel);
+ virtual void OnPart(const CNick& Nick, CChan& Channel);
+ virtual void OnNick(const CNick& OldNick, const CString& sNewNick, const vector<CChan*>& vChans);
+
+ /* notices */
+ virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage);
+ virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage);
+ virtual EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage);
+
+ /* actions */
+ virtual EModRet OnUserAction(CString& sTarget, CString& sMessage);
+ virtual EModRet OnPrivAction(CNick& Nick, CString& sMessage);
+ virtual EModRet OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage);
+
+ /* msgs */
+ virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage);
+ virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage);
+ virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage);
+};
+
+void CLogMod::PutLog(const CString& sLine, const CString& sWindow /*= "Status"*/)
+{
+ std::ofstream ofLog;
+ std::stringstream ssPath;
+ time_t curtime;
+ tm* timeinfo;
+
+ time(&curtime);
+ timeinfo = localtime(&curtime);
+
+ /* Generate file name: ~/.znc/users/USER/WINDOW_YYYYMMDD.log */
+ ssPath.fill('0');
+ ssPath << GetSavePath() << "/" << sWindow << "_"
+ << std::setw(4) << (timeinfo->tm_year + 1900)
+ << std::setw(2) << (timeinfo->tm_mon + 1)
+ << std::setw(2) << (timeinfo->tm_mday)
+ << ".log";
+
+ ofLog.open(ssPath.str().c_str(), std::ofstream::app);
+
+ if (ofLog.good())
+ {
+ /* Write line: [HH:MM:SS] MSG */
+ ofLog.fill('0');
+ ofLog << "[" << std::setw(2) << timeinfo->tm_hour
+ << ":" << std::setw(2) << timeinfo->tm_min
+ << ":" << std::setw(2) << timeinfo->tm_sec
+ << "] " << sLine << endl;
+ }
+}
+
+CString CLogMod::GetServer()
+{
+ CServer* pServer = m_pUser->GetCurrentServer();
+
+ if (!pServer)
+ return "(no server)";
+
+ //! @todo pServer->IsSSL()
+ return pServer->GetName() + ":" + CString(pServer->GetPort());
+}
+
+void CLogMod::OnIRCConnected()
+{
+ PutLog("Connected to IRC (" + GetServer() + ")");
+}
+
+void CLogMod::OnIRCDisconnected()
+{
+ PutLog("Disconnected from IRC (" + GetServer() + ")");
+}
+
+CModule::EModRet CLogMod::OnBroadcast(CString& sMessage)
+{
+ PutLog("Broadcast: " + sMessage);
+ return CONTINUE;
+}
+
+void CLogMod::OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
+{
+ PutLog("* " + OpNick.GetNick() + " sets mode: " + sModes + " " + sArgs, Channel.GetName());
+}
+
+void CLogMod::OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage)
+{
+ PutLog("* " + sKickedNick + " was kicked by " + OpNick.GetNick() + " (" + sMessage + ")", Channel.GetName());
+}
+
+void CLogMod::OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans)
+{
+ for (std::vector<CChan*>::const_iterator pChan = vChans.begin(); pChan != vChans.end(); ++pChan)
+ PutLog("* Quits: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ") (" + sMessage + ")", (*pChan)->GetName());
+}
+
+void CLogMod::OnJoin(const CNick& Nick, CChan& Channel)
+{
+ PutLog("* Joins: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ")", Channel.GetName());
+}
+
+void CLogMod::OnPart(const CNick& Nick, CChan& Channel)
+{
+ PutLog("* Parts: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ")", Channel.GetName());
+}
+
+void CLogMod::OnNick(const CNick& OldNick, const CString& sNewNick, const vector<CChan*>& vChans)
+{
+ for (std::vector<CChan*>::const_iterator pChan = vChans.begin(); pChan != vChans.end(); ++pChan)
+ PutLog("* " + OldNick.GetNick() + " is now known as " + sNewNick, (*pChan)->GetName());
+}
+
+/* notices */
+CModule::EModRet CLogMod::OnUserNotice(CString& sTarget, CString& sMessage)
+{
+ PutLog("-" + GetUser()->GetCurNick() + "- " + sMessage, sTarget);
+ return CONTINUE;
+}
+
+CModule::EModRet CLogMod::OnPrivNotice(CNick& Nick, CString& sMessage)
+{
+ PutLog("-" + Nick.GetNick() + "- " + sMessage, Nick.GetNick());
+ return CONTINUE;
+}
+
+CModule::EModRet CLogMod::OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage)
+{
+ PutLog("-" + Nick.GetNick() + "- " + sMessage, Channel.GetName());
+ return CONTINUE;
+}
+
+/* actions */
+CModule::EModRet CLogMod::OnUserAction(CString& sTarget, CString& sMessage)
+{
+ PutLog("* " + GetUser()->GetCurNick() + " " + sMessage, sTarget);
+ return CONTINUE;
+}
+
+CModule::EModRet CLogMod::OnPrivAction(CNick& Nick, CString& sMessage)
+{
+ PutLog("* " + Nick.GetNick() + " " + sMessage, Nick.GetNick());
+ return CONTINUE;
+}
+
+CModule::EModRet CLogMod::OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage)
+{
+ PutLog("* " + Nick.GetNick() + " " + sMessage, Channel.GetName());
+ return CONTINUE;
+}
+
+/* msgs */
+CModule::EModRet CLogMod::OnUserMsg(CString& sTarget, CString& sMessage)
+{
+ PutLog("<" + GetUser()->GetCurNick() + "> " + sMessage, sTarget);
+ return CONTINUE;
+}
+
+CModule::EModRet CLogMod::OnPrivMsg(CNick& Nick, CString& sMessage)
+{
+ PutLog("<" + Nick.GetNick() + "> " + sMessage, Nick.GetNick());
+ return CONTINUE;
+}
+
+CModule::EModRet CLogMod::OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage)
+{
+ PutLog("<" + Nick.GetNick() + "> " + sMessage, Channel.GetName());
+ return CONTINUE;
+}
+
+MODULEDEFS(CLogMod, "CNU's IRC Logging Module")
================================================================
Index: SOURCES/znc-crox-svn-statupdate.cpp
diff -u /dev/null SOURCES/znc-crox-svn-statupdate.cpp:1.1
--- /dev/null Sat Apr 12 23:19:00 2008
+++ SOURCES/znc-crox-svn-statupdate.cpp Sat Apr 12 23:18:55 2008
@@ -0,0 +1,103 @@
+#include "main.h"
+#include "User.h"
+#include "Nick.h"
+#include "Modules.h"
+#include "Chan.h"
+#include "znc.h"
+#include "Server.h"
+
+class CStatUpdateMod : public CGlobalModule {
+private:
+ CString m_sPath;
+ char epoch_str[64];
+
+public:
+ GLOBALMODCONSTRUCTOR(CStatUpdateMod) { }
+
+ virtual ~CStatUpdateMod () {}
+
+ virtual void UpdateStatFile ()
+ {
+ // Create filestream
+ FILE *file = fopen (m_sPath.c_str(), "w+");
+
+ if (file == NULL)
+ return;
+
+ sprintf(epoch_str, "%i", (int)time(NULL));
+
+ // Setup time
+ fputs ("STATUPDATE_TIME;", file);
+ fputs (epoch_str, file);
+ fputs ("\n", file);
+
+ const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();
+ for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++)
+ {
+ CUser& User = *it->second;
+ const CString& sNick = User.GetUserName();
+
+ fputs (sNick.c_str(), file);
+ fputs (";", file);
+
+ if (User.IsUserAttached())
+ {
+ fputs ("online\n", file);
+ }
+ else
+ {
+ fputs ("offline\n", file);
+ }
+ }
+
+ // close filestream
+ fclose (file);
+ }
+
+ virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
+ m_sPath = sArgs;
+ PutModule("StatUpdate module successfully loaded with args: [" + sArgs + "]");
+ return true;
+ }
+
+ virtual bool OnBoot() {
+ return true;
+ }
+
+ virtual void OnUserAttached ()
+ {
+ UpdateStatFile();
+ }
+
+ virtual void OnUserDetached ()
+ {
+ UpdateStatFile();
+ }
+
+ virtual void OnModCommand(const CString& sCommand) {
+ if (sCommand.CaseCmp("DEBUG") == 0) {
+ PutModule("Current path is: " + m_sPath);
+ }
+
+ if ((sCommand.CaseCmp("UPDATE") == 0 || sCommand.CaseCmp("REFRESH") == 0) && m_pUser->IsAdmin()) {
+ UpdateStatFile();
+ PutModule("StatUpdate file successfully updated.");
+ }
+
+ if (sCommand.CaseCmp("VERSION") == 0) {
+ PutModule("StatUpdate - v0.2b");
+ PutModule("Autor: Daniel 'd4n13L' Schmitz (daniel at danielschmitz.de)");
+ }
+ }
+
+ virtual EModRet OnStatusCommand(const CString& sCommand) {
+ if (sCommand.CaseCmp("STATUPDATE") == 0) {
+ PutModule("Hello! I am here ;-)");
+ return HALT;
+ }
+
+ return CONTINUE;
+ }
+};
+
+GLOBALMODULEDEFS(CStatUpdateMod, "StatUpdate writes users online status into a text file.")
================================================================
Index: SOURCES/znc-crox-svn-fish.cpp
diff -u /dev/null SOURCES/znc-crox-svn-fish.cpp:1.1
--- /dev/null Sat Apr 12 23:19:00 2008
+++ SOURCES/znc-crox-svn-fish.cpp Sat Apr 12 23:18:55 2008
@@ -0,0 +1,572 @@
+#include "main.h"
+#include "User.h"
+#include "Nick.h"
+#include "Modules.h"
+#include "Chan.h"
+#include "String.h"
+
+#include <string.h>
+
+#include <netinet/in.h>
+
+#include <openssl/opensslv.h>
+#include <openssl/blowfish.h>
+
+#define REQUIRESSL 1
+
+#if (OPENSSL_VERSION_NUMBER < 0x0090800f)
+#error "We require openssl >= 0.9.8"
+#endif
+
+/*
+ Public Base64 conversion tables
+*/
+unsigned char B64ABC[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+unsigned char b64buf[256];
+
+
+/*
+ void initb64();
+ Initializes the base64->base16 conversion tab.
+ Call this function once when your program starts.
+ and always after your B64 table has been changed.
+*/
+void initb64(){
+ unsigned int i;
+ for (i=0; i<256; i++) b64buf[i]=0x00;
+ for (i=0; i<64; i++) b64buf[(B64ABC[i])]=i;
+}
+
+/*
+ int b64toh(lpBase64String, lpDestinationBuffer);
+ Converts base64 string b to hexnumber d.
+ Returns size of hexnumber in bytes.
+*/
+int b64toh(char *b, char *d){
+ unsigned int i,k,l;
+
+ l=strlen(b);
+ if (l<2) return 0;
+ for (i=l-1;i>-1;i--){
+ if (b64buf[(b[i])]==0) l--;
+ else break;
+ }
+
+ if (l<2) return 0;
+ i=0, k=0;
+ while (1) {
+ i++;
+ if (k+1<l) d[i-1]=((b64buf[(b[k])])<<2);
+ else break;
+ k++;
+ if (k<l) d[i-1]|=((b64buf[(b[k])])>>4);
+ else break;
+ i++;
+ if (k+1<l) d[i-1]=((b64buf[(b[k])])<<4);
+ else break;
+ k++;
+ if (k<l) d[i-1]|=((b64buf[(b[k])])>>2);
+ else break;
+ i++;
+ if (k+1<l) d[i-1]=((b64buf[(b[k])])<<6);
+ else break;
+ k++;
+ if (k<l) d[i-1]|=(b64buf[(b[k])]);
+ else break;
+ k++;
+ }
+ return i-1;
+}
+
+/*
+ int htob64(lpHexNumber, lpDestinationBuffer);
+ Converts hexnumber h (with length l bytes) to base64 string d.
+ Returns length of base64 string.
+*/
+int htob64(char *h, char *d, unsigned int l){
+ unsigned int i,j,k;
+ unsigned char m,t;
+
+ if (!l) return 0;
+ l<<=3; // no. bits
+ m=0x80;
+ for (i=0,j=0,k=0,t=0; i<l; i++){
+ if (h[(i>>3)]&m) t|=1;
+ j++;
+ if (!(m>>=1)) m=0x80;
+ if (!(j%6)) {
+ d[k]=B64ABC[t];
+ t&=0;
+ k++;
+ }
+ t<<=1;
+ }
+ m=5-(j%6);
+ t<<=m;
+ if (m) {
+ d[k]=B64ABC[t];
+ k++;
+ }
+ d[k]&=0;
+ return strlen(d);
+}
+
+unsigned char B64[]="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+char *prime1080="FBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B";
+
+int base64dec(char c)
+{
+ int i;
+
+ for (i = 0; i < 64; i++)
+ if (B64[i] == c) return i;
+
+ return 0;
+}
+
+char *encrypts(char *key,char *str) {
+ char *result;
+ unsigned int length;
+ unsigned int left,right;
+ char *s,*d;
+ unsigned char *p;
+ BF_KEY bfkey;
+ int i;
+
+ if(key==NULL||str==NULL) return NULL;
+
+ length=strlen(str);
+ BF_set_key(&bfkey, strlen(key), (const unsigned char *)key);
+
+ s=(char *)malloc(length+9);
+
+ strncpy(s,str,length);
+ memset(s+length,0,9);
+
+ result=(char *)malloc(((length%8==0) ? length/8*12 : 12+length/8*12)+1);
+
+ p=(unsigned char *)s;
+ d=result;
+
+ while(*p) {
+ BF_ecb_encrypt((const unsigned char *)p, (unsigned char *)p, &bfkey, BF_ENCRYPT);
+ left = ((*p++) << 24);
+ left += ((*p++) << 16);
+ left += ((*p++) << 8);
+ left += (*p++);
+ right = ((*p++) << 24);
+ right += ((*p++) << 16);
+ right += ((*p++) << 8);
+ right += (*p++);
+ for (i = 0; i < 6; i++) {
+ *d++=B64[right & 0x3f];
+ right = (right >> 6);
+ }
+
+ for (i = 0; i < 6; i++) {
+ *d++=B64[left & 0x3f];
+ left = (left >> 6);
+ }
+ }
+ *d = '\0';
+
+ memset(s,0,length+9);
+ free(s);
+ return result;
+}
+
+char *decrypts(char *key, char *str) {
+ char *result;
+ unsigned int length;
+ unsigned int left,right;
+ int i;
+ char *d;
+ unsigned char *c;
+ BF_KEY bfkey;
+
+ if(key==NULL||str==NULL) return NULL;
+
+ length=strlen(str);
+ BF_set_key(&bfkey,strlen(key),(const unsigned char *)key);
+
+ result=(char *)malloc(length/12*8);
+ c=(unsigned char *)result;
+ d=str;
+ while(*d) {
+ right=0;
+ left=0;
+ for (i = 0; i < 6; i++) right |= (base64dec(*d++)) << (i * 6);
+ for (i = 0; i < 6; i++) left |= (base64dec(*d++)) << (i * 6);
+ right=htonl(right);
+ left=htonl(left);
+ memcpy(c,&left,4);
+ memcpy(c+4,&right,4);
+ BF_ecb_encrypt(c,c,&bfkey,BF_DECRYPT);
+ c+=8;
+ }
+ *c='\0';
+ return result;
+}
+
+class CKeyExchangeTimer : public CTimer {
+public:
+ CKeyExchangeTimer(CModule* pModule)
+ : CTimer(pModule, 5, 0, "KeyExchangeTimer", "Key exchange timer removes stale exchanges") {}
+
+protected:
+ virtual void RunJob();
+};
+
+class CFishMod : public CModule {
+public:
+ MODCONSTRUCTOR(CFishMod) {}
+ virtual ~CFishMod() {
+ }
+
+ virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) {
+ CString command = sMessage.Token(0);
+
+ if (command.CaseCmp("DH1080_INIT") == 0) {
+ CString sPriv_Key;
+ CString sPub_Key;
+ CString sOtherPub_Key;
+ CString sSecretKey;
+
+ PutModule("Received DH1080 public key from " + Nick.GetNick() + ", sending mine...");
+ DH1080_gen(sPriv_Key, sPub_Key);
+ sOtherPub_Key = sMessage.Token(1);
+ PutIRC("NOTICE " + Nick.GetNick() + " :DH1080_FINISH " + sPub_Key);
+ DH1080_comp(sPriv_Key, sOtherPub_Key, sSecretKey);
+ SetNV(Nick.GetNick().AsLower(), sSecretKey);
+ PutModule("Key for " + Nick.GetNick() + " successfully set.");
+ return HALT;
+ } else if (command.CaseCmp("DH1080_FINISH") == 0) {
+ CString sPriv_Key;
+ CString sOtherPub_Key;
+ CString sSecretKey;
+
+ sOtherPub_Key = sMessage.Token(1);
+ map<CString, pair<time_t, CString> >::iterator it = m_msKeyExchange.find(Nick.GetNick().AsLower());
+ if (it == m_msKeyExchange.end()) {
+ PutModule("Received unexpected DH1080_FINISH from " + Nick.GetNick() + ".");
+ } else {
+ sPriv_Key = it->second.second;
+ DH1080_comp(sPriv_Key, sOtherPub_Key, sSecretKey);
+ SetNV(Nick.GetNick().AsLower(), sSecretKey);
+ PutModule("Key for " + Nick.GetNick() + " successfully set.");
+ m_msKeyExchange.erase(Nick.GetNick().AsLower());
+ }
+ return HALT;
+ } else {
+ FilterIncoming(Nick.GetNick(), Nick, sMessage);
+ }
<<Diff was trimmed, longer than 597 lines>>
More information about the pld-cvs-commit
mailing list