ZNC-Extra no more.

Few the most useless modules are just removed, the others are moved to
standard modules.
This commit is contained in:
Alexey Sokolov
2012-02-21 19:34:36 +07:00
parent fc8e789b08
commit 7ac61474ed
25 changed files with 27 additions and 444 deletions
+21 -30
View File
@@ -92,10 +92,6 @@ esac
AC_ARG_WITH( [openssl],
AS_HELP_STRING([--with-openssl=DIR], [openssl installation prefix]),
[OPENSSL=$withval],)
AC_ARG_ENABLE( [extra],
AS_HELP_STRING([--enable-extra], [enable some extra modules]),
[EXTRA="$enableval"],
[EXTRA="no"])
AC_ARG_ENABLE( [debug],
AS_HELP_STRING([--enable-debug], [enable debugging]),
[DEBUG="$enableval"],
@@ -456,31 +452,28 @@ then
LIBS="$my_saved_LIBS"
fi
if test x"$EXTRA" = "xyes"
AC_CHECK_FUNC( iconv, CHARSET=1 )
AC_CHECK_LIB( iconv, iconv_open, LIBICONV=-liconv ; CHARSET=1 )
if test "x$CHARSET" = "x1"
then
AC_CHECK_FUNC( iconv, CHARSET=1 )
AC_CHECK_LIB( iconv, iconv_open, LIBICONV=-liconv ; CHARSET=1 )
if test "x$CHARSET" = "x1"
then
AC_MSG_CHECKING([whether iconv expects a const second argument])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#include <iconv.h>
]], [[
const char input[] = "X"; const char *inptr = input; size_t inbytes = 1;
char buf[1]; char *outptr = buf; size_t outbytes = 1;
iconv_t ic = iconv_open("ISO8859-1", "UTF8");
iconv(ic, (char**)&inptr, &inbytes, &outptr, &outbytes);
]])], [
AC_MSG_RESULT([no])
appendMod -DICONV_CONST=
], [
AC_MSG_RESULT([yes])
appendMod -DICONV_CONST=const
])
else
AC_MSG_WARN([libiconv was not found, disabling the charset module])
fi
AC_MSG_CHECKING([whether iconv expects a const second argument])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#include <iconv.h>
]], [[
const char input[] = "X"; const char *inptr = input; size_t inbytes = 1;
char buf[1]; char *outptr = buf; size_t outbytes = 1;
iconv_t ic = iconv_open("ISO8859-1", "UTF8");
iconv(ic, (char**)&inptr, &inbytes, &outptr, &outbytes);
]])], [
AC_MSG_RESULT([no])
appendMod -DICONV_CONST=
], [
AC_MSG_RESULT([yes])
appendMod -DICONV_CONST=const
])
else
AC_MSG_WARN([libiconv was not found, disabling the charset module])
fi
AC_CACHE_CHECK([for GNU make], [ac_cv_path_GNUMAKE], [
@@ -504,7 +497,6 @@ AC_SUBST([LIBZNC])
AC_SUBST([LIBZNCDIR])
AC_SUBST([MODLINK])
AC_SUBST([NOSSL])
AC_SUBST([EXTRA])
AC_SUBST([TCL_FLAGS])
AC_SUBST([SASL])
AC_SUBST([CHARSET])
@@ -542,7 +534,6 @@ if test x"$SASL" = "x" ; then
else
echo "sasl: yes"
fi
echo "extra: $EXTRA"
if test x"$TCL_FLAGS" = "x" ; then
echo "tcl: no"
else
+6 -13
View File
@@ -59,10 +59,6 @@ endif
CLEAN :=
FILES := $(notdir $(wildcard $(srcdir)/*.cpp))
# If extra is enabled
ifeq "@EXTRA@" "yes"
FILES += $(addprefix extra/, $(notdir $(wildcard $(srcdir)/extra/*.cpp)))
endif
include $(srcdir)/modperl/Makefile.inc
include $(srcdir)/modpython/Makefile.inc
@@ -79,18 +75,18 @@ FILES := $(foreach file, $(FILES), \
endif
ifeq "@SASL@" ""
FILES := $(shell echo $(FILES) | sed -e "s:extra/saslauth::")
FILES := $(shell echo $(FILES) | sed -e "s:saslauth::")
endif
saslauthLDFLAGS := -lsasl2
ifeq "@CHARSET@" ""
FILES := $(shell echo $(FILES) | sed -e "s:extra/charset::")
FILES := $(shell echo $(FILES) | sed -e "s:charset::")
endif
charsetLDFLAGS := @LIBICONV@
TARGETS := $(addsuffix .so, $(FILES))
CLEAN += *.so extra/*.so *.o extra/*.o
CLEAN += *.so *.o
.PHONY: all clean install install_datadir uninstall
.SECONDARY:
@@ -106,9 +102,6 @@ install_datadir:
test -d $(DESTDIR)$(DATADIR)/modules || $(INSTALL) -d $(DESTDIR)$(DATADIR)/modules
rm -rf $(DESTDIR)$(MODDIR)/*.so
cp -R $(srcdir)/data/* $(DESTDIR)$(DATADIR)/modules
if test "@EXTRA@" = "yes" ; then \
cp -R $(srcdir)/extra/data/* $(DESTDIR)$(DATADIR)/modules ; \
fi
find $(DESTDIR)$(DATADIR)/modules -type d -exec chmod 0755 '{}' \;
find $(DESTDIR)$(DATADIR)/modules -type f -exec chmod 0644 '{}' \;
@@ -116,12 +109,12 @@ clean:
rm -rf $(CLEAN)
%.o: %.cpp Makefile
@mkdir -p .depend extra
$(E) Building $(if $(filter %extra/,$(dir $<)),extra )module $(notdir $(basename $@))...
@mkdir -p .depend
$(E) Building module $(notdir $(basename $@))...
$(Q)$(CXX) $(MODFLAGS) -c -o $@ $< $($(notdir $(basename $@))CXXFLAGS) -MD -MF .depend/$(notdir $@).dep
%.so: %.o Makefile
$(E) Linking $(if $(filter %extra/,$(dir $<)),extra )module $(notdir $(basename $@))...
$(E) Linking module $(notdir $(basename $@))...
$(Q)$(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -o $@ $< $($(notdir $(basename $@))LDFLAGS)
uninstall:
-144
View File
@@ -1,144 +0,0 @@
/*
* droproot.cpp
*
* Copyright (c) 2009 Vadtec (vadtec@vadtec.net)
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* Copyright (C) 2004-2012 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#include <znc/znc.h>
#include <znc/User.h>
#include <pwd.h>
#include <grp.h>
class CDroproot : public CModule {
public:
MODCONSTRUCTOR(CDroproot) {
}
virtual ~CDroproot() {
}
uid_t GetUser(const CString& sUser, CString& sMessage) {
uid_t ret = sUser.ToUInt();
if (ret != 0)
return ret;
struct passwd *pUser = getpwnam(sUser.c_str());
if (!pUser) {
sMessage = "User [" + sUser + "] not found!";
return 0;
}
return pUser->pw_uid;
}
gid_t GetGroup(const CString& sGroup, CString& sMessage) {
gid_t ret = sGroup.ToUInt();
if (ret != 0)
return ret;
struct group *pGroup = getgrnam(sGroup.c_str());
if (!pGroup) {
sMessage = "Group [" + sGroup + "] not found!";
return 0;
}
return pGroup->gr_gid;
}
virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
CString sUser = sArgs.Token(0);
CString sGroup = sArgs.Token(1, true);
if (sUser.empty() || sGroup.empty()) {
sMessage = "Usage: LoadModule = Droproot <uid> <gid>";
return false;
}
m_user = GetUser(sUser, sMessage);
if (m_user == 0) {
sMessage
= "Error: Cannot run as root, check your config file | Useage: LoadModule = Droproot <uid> <gid>";
return false;
}
m_group = GetGroup(sGroup, sMessage);
if (m_group == 0) {
sMessage
= "Error: Cannot run as root, check your config file | Useage: LoadModule = Droproot <uid> <gid>";
return false;
}
return true;
}
virtual bool OnBoot() {
int u, eu, g, eg, sg;
if ((geteuid() == 0) || (getuid() == 0) || (getegid() == 0) || (getgid()
== 0)) {
CUtils::PrintAction("Dropping root permissions");
// Clear all the supplementary groups
sg = setgroups(0, NULL);
if (sg < 0) {
CUtils::PrintStatus(false,
"Could not remove supplementary groups! ["
+ CString(strerror(errno)) + "]");
return false;
}
// Set the group (if we are root, this sets all three group IDs)
g = setgid(m_group);
eg = setegid(m_group);
if ((g < 0) || (eg < 0)) {
CUtils::PrintStatus(false, "Could not switch group id! ["
+ CString(strerror(errno)) + "]");
return false;
}
// and set the user (if we are root, this sets all three user IDs)
u = setuid(m_user);
eu = seteuid(m_user);
if ((u < 0) || (eu < 0)) {
CUtils::PrintStatus(false, "Could not switch user id! ["
+ CString(strerror(errno)) + "]");
return false;
}
CUtils::PrintStatus(true);
return true;
}
return true;
}
protected:
uid_t m_user;
gid_t m_group;
};
GLOBALMODULEDEFS(CDroproot, "Allows ZNC to drop root privileges and run as an un-privileged user.")
-253
View File
@@ -1,253 +0,0 @@
/*
* Copyright (C) 2004-2012 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* Email Monitor / Retrieval
* Author: imaginos <imaginos@imaginos.net>
*/
#include <znc/FileUtils.h>
#include <znc/MD5.h>
#include <znc/User.h>
#include <znc/znc.h>
#include <sstream>
using std::stringstream;
struct EmailST
{
CString sFrom;
CString sSubject;
CString sUidl;
u_int iSize;
};
class CEmailJob : public CTimer
{
public:
CEmailJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription)
: CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {}
virtual ~CEmailJob() {}
protected:
virtual void RunJob();
};
class CEmail : public CModule
{
public:
MODCONSTRUCTOR(CEmail)
{
m_iLastCheck = 0;
m_bInitialized = false;
}
virtual ~CEmail() {}
virtual bool OnLoad(const CString & sArgs, CString& sMessage) {
#ifndef MOD_EMAIL_ALLOW_EVERYONE
if (!m_pUser->IsAdmin()) {
sMessage = "You must be admin to use the email module";
return false;
}
#endif
m_sMailPath = sArgs;
StartParser();
if (m_pUser->IsUserAttached())
StartTimer();
return true;
}
virtual void OnClientLogin()
{
stringstream s;
s << "You have " << m_ssUidls.size() << " emails.";
PutModule(s.str());
StartTimer();
}
virtual void OnClientDisconnect()
{
RemTimer("EMAIL::" + m_pUser->GetUserName());
}
void StartTimer()
{
if (!FindTimer("EMAIL::" + m_pUser->GetUserName()))
{
CEmailJob *p = new CEmailJob(this, 60, 0, "EmailMonitor", "Monitors email activity");
AddTimer(p);
}
}
virtual void OnModCommand(const CString& sCommand);
void StartParser();
void ParseEmails(const vector<EmailST> & vEmails)
{
if (!m_bInitialized)
{
m_bInitialized = true;
for (u_int a = 0; a < vEmails.size(); a++)
m_ssUidls.insert(vEmails[a].sUidl);
stringstream s;
s << "You have " << vEmails.size() << " emails.";
PutModule(s.str());
} else
{
set<CString> ssUidls;
CTable Table;
Table.AddColumn("From");
Table.AddColumn("Size");
Table.AddColumn("Subject");
for (u_int a = 0; a < vEmails.size(); a++)
{
if (m_ssUidls.find(vEmails[a].sUidl) == m_ssUidls.end())
{
//PutModule("------------------- New Email -------------------");
Table.AddRow();
Table.SetCell("From", vEmails[a].sFrom.Ellipsize(32));
Table.SetCell("Size", CString(vEmails[a].iSize));
Table.SetCell("Subject", vEmails[a].sSubject.Ellipsize(64));
}
ssUidls.insert(vEmails[a].sUidl);
}
m_ssUidls = ssUidls; // keep the list in synch
if (Table.size()) {
PutModule(Table);
stringstream s;
s << "You have " << vEmails.size() << " emails.";
PutModule(s.str());
}
}
}
private:
CString m_sMailPath;
time_t m_iLastCheck;
set<CString> m_ssUidls;
bool m_bInitialized;
};
class CEmailFolder : public CSocket
{
public:
CEmailFolder(CEmail *pModule, const CString & sMailbox) : CSocket(pModule)
{
m_pModule = pModule;
m_sMailbox = sMailbox;
EnableReadLine();
}
virtual ~CEmailFolder()
{
if (!m_sMailBuffer.empty())
ProcessMail(); // get the last one
if (!m_vEmails.empty())
m_pModule->ParseEmails(m_vEmails);
}
virtual void ReadLine(const CS_STRING & sLine)
{
if (sLine.Left(5) == "From ")
{
if (!m_sMailBuffer.empty())
{
ProcessMail();
m_sMailBuffer.clear();
}
}
m_sMailBuffer += sLine;
}
void ProcessMail()
{
EmailST tmp;
tmp.sUidl = (char *)CMD5(m_sMailBuffer.Left(255));
VCString vsLines;
VCString::iterator it;
m_sMailBuffer.Split("\n", vsLines);
for (it = vsLines.begin(); it != vsLines.end(); it++) {
CString sLine(*it);
sLine.Trim();
if (sLine.empty())
break; // out of the headers
if (sLine.Equals("From: ", false, 6))
tmp.sFrom = sLine.substr(6, CString::npos);
else if (sLine.Equals("Subject: ", false, 9))
tmp.sSubject = sLine.substr(9, CString::npos);
if ((!tmp.sFrom.empty()) && (!tmp.sSubject.empty()))
break;
}
tmp.iSize = m_sMailBuffer.length();
m_vEmails.push_back(tmp);
}
private:
CEmail *m_pModule;
CString m_sMailbox;
CString m_sMailBuffer;
vector<EmailST> m_vEmails;
};
void CEmail::OnModCommand(const CString& sCommand)
{
CString sCom = sCommand.Token(0);
if (sCom == "timers")
{
ListTimers();
} else
PutModule("Error, no such command [" + sCom + "]");
}
void CEmail::StartParser()
{
CString sParserName = "EMAIL::" + m_pUser->GetUserName();
if (m_pManager->FindSockByName(sParserName))
return; // one at a time sucker
CFile cFile(m_sMailPath);
if ((!cFile.Exists()) || (cFile.GetSize() == 0))
{
m_bInitialized = true;
return; // der
}
if (cFile.GetMTime() <= m_iLastCheck)
return; // only check if modified
int iFD = open(m_sMailPath.c_str(), O_RDONLY);
if (iFD >= 0)
{
m_iLastCheck = time(NULL);
CEmailFolder *p = new CEmailFolder(this, m_sMailPath);
p->SetRSock(iFD);
p->SetWSock(iFD);
m_pManager->AddSock(p, "EMAIL::" + m_pUser->GetUserName());
}
}
void CEmailJob::RunJob()
{
CEmail *p = (CEmail *)m_pModule;
p->StartParser();
}
USERMODULEDEFS(CEmail, "Monitors Email activity on local disk /var/mail/user")
-4
View File
@@ -1092,10 +1092,6 @@ CModules::ModDirList CModules::GetModDirs() {
// ./modules
sDir = CZNC::Get().GetCurPath() + "/modules/";
ret.push(std::make_pair(sDir, sDir + "data/"));
// ./modules/extra
sDir = CZNC::Get().GetCurPath() + "/modules/extra/";
ret.push(std::make_pair(sDir, sDir + "data/"));
#endif
// ~/.znc/modules