Commit initial: GNUWorld servicii IRC cu README.md complet in limba romana - Analiza arhitecturala completa a proiectului - Documentatie ierarhie clase, bucla de evenimente, protocol P10 - Identificare probleme memorie si recomandari modernizare
This commit is contained in:
commit
fcb24f6de9
870 files changed
+311128
No files matched your search
@@ -0,0 +1,6 @@
|
||||
.deps
|
||||
.libs
|
||||
*.la
|
||||
*.lo
|
||||
Makefile
|
||||
.arch-ids
|
||||
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* ACCEPTCommand.cc
|
||||
*
|
||||
* 27/04/2012 - Gergo Focze <gergo_f@yahoo.com>
|
||||
* Initial Version.
|
||||
*
|
||||
* Channel accept command from IRC
|
||||
*
|
||||
* 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 <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "dbHandle.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char ACCEPTCommand_cc_rcsId[] = "$Id: ACCEPTCommand.cc,v 1.0 2012/04/27 20:48:00 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::pair ;
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool ACCEPTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.ACCEPT");
|
||||
string decision;
|
||||
string mngrUserName;
|
||||
unsigned int chanId;
|
||||
int level = 0;
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (theUser) level = bot->getAdminAccessLevel(theUser);
|
||||
if (level == 0) return true; //don't show anything to normal users ;)
|
||||
StringTokenizer st( Message ) ;
|
||||
if ( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
if (!theUser) return false;
|
||||
|
||||
/* First, check the channel is registered/real. */
|
||||
|
||||
if ( (st[1][0] != '#') )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_chan_name,
|
||||
string("Invalid channel name.")));
|
||||
return false;
|
||||
}
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_already_reg,
|
||||
string("%s is already registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
/* Check the user has sufficient access for this command.. */
|
||||
if (level < level::accept)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
decision = st.assemble(2);
|
||||
if (decision.size() > 300)
|
||||
{
|
||||
bot->Notice(theClient,"Decision cannot exceed 300 charcters.");
|
||||
return false;
|
||||
}
|
||||
unsigned int lastdays = (unsigned int)bot->currentTime() - ((unsigned int)bot->daySeconds*5);
|
||||
stringstream theQuery;
|
||||
/********** Channel ID query ***********/
|
||||
theQuery << "SELECT id,status FROM channels,pending WHERE "
|
||||
<< "channels.registered_ts = 0 AND lower(channels.name) = '"
|
||||
<< escapeSQLChars(string_lower(st[1]))
|
||||
<< "'"
|
||||
<< " AND channels.id = pending.channel_id AND (pending.decision_ts=0 OR (pending.decision_ts>0 AND pending.decision_ts>="
|
||||
<< lastdays
|
||||
<< "))"
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{ bot->logDebugMessage("Error on ACCEPT: channel is not UnClaimed");
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "ACCEPT.pending.status query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
} else if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
chanId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
unsigned short status = atoi(bot->SQLDb->GetValue(0,1));
|
||||
if (status == 3) //if we're here, the channel was previously Rejected
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
/* Quick query to set registered_ts back for this chan. */
|
||||
stringstream reclaimQuery;
|
||||
reclaimQuery << "UPDATE channels SET registered_ts = date_part('epoch', CURRENT_TIMESTAMP)::int,"
|
||||
<< " last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int, "
|
||||
<< " flags = 0, description = '', url = '', comment = '', keywords = '', channel_mode = '+tn' "
|
||||
//<< " WHERE lower(name) = '"
|
||||
//<< escapeSQLChars(string_lower(st[1]))
|
||||
//<< "'"
|
||||
<< " WHERE id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
if (!bot->SQLDb->Exec(reclaimQuery))
|
||||
{
|
||||
bot->logDebugMessage("Error on ACCEPT.UpdateReclaim query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> " << reclaimQuery.str().c_str() << endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
/********** Update pending status ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "UPDATE pending SET status=3,last_updated=date_part('epoch', CURRENT_TIMESTAMP)::int,decision_ts=date_part('epoch', CURRENT_TIMESTAMP)::int,reviewed='Y',decision='"
|
||||
<< decision
|
||||
<< "',reviewed_by_id="
|
||||
<< theUser->getID()
|
||||
<<" WHERE channel_id="
|
||||
<< chanId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on ACCEPT.UpdatePending query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "ACCEPT.UpdatePending query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
/********** Manager ID query ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT manager_id FROM pending WHERE channel_id="
|
||||
<< chanId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on ACCEPT.Manager_ID query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "ACCEPT.Manager_ID query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->logDebugMessage("Result NOT Found ACCEPT.Manager_ID query");
|
||||
return false;
|
||||
}
|
||||
unsigned int mngrId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
/********** Update users LastSeen last_updated ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "UPDATE users_lastseen SET last_updated=date_part('epoch', CURRENT_TIMESTAMP)::int,last_seen=date_part('epoch', CURRENT_TIMESTAMP)::int WHERE user_id="
|
||||
<< mngrId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on ACCEPT.UsersLastseen last_updated");
|
||||
#ifdef LOG_SQL
|
||||
elog << "ACCEPT.UsersLastseen last_updated> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
/********** Manager username query ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT user_name FROM users WHERE id="
|
||||
<< mngrId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on ACCEPT.Manager UserName Query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "ACCEPT.Manager UserName Query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
mngrUserName = bot->SQLDb->GetValue(0,0);
|
||||
//sqlUser* tmpUser = bot->getUserRecord(mngrUserName);
|
||||
/*
|
||||
* Create the new channel and insert it into the cache.
|
||||
* If the channel exists on IRC, grab the creation timestamp
|
||||
* and use this as the channel_ts in the Db.
|
||||
*/
|
||||
unsigned int channel_ts = 0;
|
||||
Channel* tmpChan = Network->findChannel(st[1]);
|
||||
channel_ts = tmpChan ? tmpChan->getCreationTime() : ::time(NULL);
|
||||
|
||||
sqlChannel* newChan = new (std::nothrow) sqlChannel(bot->SQLDb);
|
||||
newChan->setName(st[1]);
|
||||
newChan->setID(chanId);
|
||||
newChan->setChannelTS(channel_ts);
|
||||
newChan->setRegisteredTS(bot->currentTime());
|
||||
newChan->setChannelMode("+tn");
|
||||
newChan->setLastUsed(bot->currentTime());
|
||||
|
||||
bot->sqlChannelCache.insert(cservice::sqlChannelHashType::value_type(newChan->getName(), newChan));
|
||||
bot->sqlChannelIDCache.insert(cservice::sqlChannelIDHashType::value_type(newChan->getID(), newChan));
|
||||
|
||||
/*
|
||||
* Finally, commit a channellog entry.
|
||||
*/
|
||||
|
||||
bot->writeChannelLog(newChan, theClient, sqlChannel::EV_REGISTER, " (*** REGPROC ***) to " + mngrUserName);
|
||||
|
||||
/*
|
||||
* Create the new manager.
|
||||
*/
|
||||
|
||||
sqlLevel* newManager = new (std::nothrow) sqlLevel(bot->SQLDb);
|
||||
newManager->setChannelId(newChan->getID());
|
||||
newManager->setUserId(mngrId);
|
||||
newManager->setAccess(500);
|
||||
newManager->setAdded(bot->currentTime());
|
||||
newManager->setAddedBy("*** REGPROC ***");
|
||||
newManager->setLastModif(bot->currentTime());
|
||||
newManager->setLastModifBy("*** REGPROC ***");
|
||||
|
||||
if (!newManager->insertRecord())
|
||||
{
|
||||
bot->Notice(theClient, "Couldn't automatically add the level 500 Manager, check it doesn't already exist.");
|
||||
delete(newManager);
|
||||
return (false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert this new 500 into the level cache.
|
||||
*/
|
||||
|
||||
pair<int, int> thePair( newManager->getUserId(), newManager->getChannelId());
|
||||
bot->sqlLevelCache.insert(cservice::sqlLevelHashType::value_type(thePair, newManager));
|
||||
|
||||
bot->logAdminMessage("%s (%s) has accepted %s to %s", theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(), st[1].c_str(), mngrUserName.c_str());
|
||||
bot->Notice(theClient,"Accepted channel %s",st[1].c_str());
|
||||
|
||||
/* set channel mode R - tmpChan is created further above */
|
||||
stringstream tmpTS;
|
||||
tmpTS << channel_ts;
|
||||
string channelTS = tmpTS.str();
|
||||
|
||||
if (tmpChan)
|
||||
bot->getUplink()->Mode(NULL, tmpChan, string("+R"), channelTS );
|
||||
bot->getUplink()->RegisterChannelEvent(st[1],bot);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,443 @@
|
||||
/**
|
||||
* ACCESSCommand.cc
|
||||
*
|
||||
* 24/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
* 15/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Added -op/-voice/-none support
|
||||
*
|
||||
* 01/03/01 - Daniel Simard <svr@undernet.org>
|
||||
* Fixed Language module stuff.
|
||||
*
|
||||
* Displays all "Level" records for a specified channel.
|
||||
* Can optionally narrow down selection using a number of switches.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: ACCESSCommand.cc,v 1.50 2009/06/09 15:40:29 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "dbHandle.h"
|
||||
#include "match.h"
|
||||
#include "responses.h"
|
||||
#include "cservice_config.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char ACCESSCommand_cc_rcsId[] = "$Id: ACCESSCommand.cc,v 1.50 2009/06/09 15:40:29 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
using std::string ;
|
||||
|
||||
static const char* queryHeader = "SELECT channels.name,users.user_name,levels.access,levels.flags,users_lastseen.last_seen,levels.suspend_expires,levels.last_modif,levels.last_modif_by,levels.suspend_level,levels.suspend_reason FROM levels,channels,users,users_lastseen ";
|
||||
static const char* queryCondition = "WHERE levels.channel_id=channels.id AND levels.user_id=users.id AND users.id=users_lastseen.user_id ";
|
||||
static const char* queryFooter = "ORDER BY levels.access DESC;";
|
||||
|
||||
bool ACCESSCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.ACCESS");
|
||||
|
||||
/*
|
||||
* This command will build up a custom SQL query and execute it on
|
||||
* the 'levels' table.
|
||||
*/
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg).c_str(),
|
||||
st[1].c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Don't let ordinary people view * accesses */
|
||||
if (theChan->getName() == "*")
|
||||
{
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if (!theUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg).c_str(),
|
||||
st[1].c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (theUser && !bot->getAdminAccessLevel(theUser))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg).c_str(),
|
||||
st[1].c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Figure out the switches and append to the SQL statement accordingly.
|
||||
*/
|
||||
|
||||
/* 0 = None, 1 = min, 2 = max, 3 = modif, 4 = op, 5 = voice, 6 = none. */
|
||||
unsigned short currentType = 0;
|
||||
|
||||
unsigned int minAmount = 0;
|
||||
unsigned int maxAmount = 0;
|
||||
bool modif = false;
|
||||
bool showAll = false;
|
||||
bool aOp = false;
|
||||
bool aHalfOp = false;
|
||||
bool aVoice = false;
|
||||
bool aNone = false;
|
||||
|
||||
string modifMask;
|
||||
|
||||
for( StringTokenizer::const_iterator ptr = st.begin() ; ptr != st.end() ;
|
||||
++ptr )
|
||||
{
|
||||
if (string_lower(*ptr) == "-min")
|
||||
{
|
||||
currentType = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_lower(*ptr) == "-max")
|
||||
{
|
||||
currentType = 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_lower(*ptr) == "-modif")
|
||||
{
|
||||
currentType = 3;
|
||||
modif = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_lower(*ptr) == "-op")
|
||||
{
|
||||
currentType = 4;
|
||||
aOp = true;
|
||||
continue;
|
||||
}
|
||||
if (string_lower(*ptr) == "-halfop")
|
||||
{
|
||||
currentType = 5;
|
||||
aHalfOp = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_lower(*ptr) == "-voice")
|
||||
{
|
||||
currentType = 6;
|
||||
aVoice = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_lower(*ptr) == "-none")
|
||||
{
|
||||
currentType = 7;
|
||||
aNone = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string_lower(*ptr) == "-all")
|
||||
{
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient, false);
|
||||
if( tmpUser && bot->getAdminAccessLevel(tmpUser) )
|
||||
{
|
||||
showAll = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(currentType)
|
||||
{
|
||||
case 1: /* Min */
|
||||
{
|
||||
minAmount = atoi( (*ptr).c_str() );
|
||||
if ((minAmount > 1000) /* || (minAmount < 0) */)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_min_lvl).c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
currentType = 0;
|
||||
break;
|
||||
}
|
||||
case 2: /* Max */
|
||||
{
|
||||
maxAmount = atoi( (*ptr).c_str() );
|
||||
if ((maxAmount > 1000) /* || (maxAmount < 0) */)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_max_lvl).c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
currentType = 0;
|
||||
break;
|
||||
}
|
||||
case 3: /* Modif */
|
||||
{
|
||||
// [22:13] <DrCkTaiL> backburner
|
||||
break;
|
||||
}
|
||||
case 4: /* Automode Op */
|
||||
{
|
||||
break;
|
||||
}
|
||||
case 5: /* Automode HalfOp */
|
||||
{
|
||||
break;
|
||||
}
|
||||
case 6: /* Automode Voice */
|
||||
{
|
||||
break;
|
||||
}
|
||||
case 7: /* Automode None */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort out the additional conditions */
|
||||
|
||||
stringstream extraCond;
|
||||
if (minAmount)
|
||||
{
|
||||
extraCond << "AND levels.access >= " << minAmount << " ";
|
||||
}
|
||||
if (maxAmount)
|
||||
{
|
||||
extraCond << "AND levels.access <= " << maxAmount << " ";
|
||||
}
|
||||
extraCond << ends;
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << queryHeader
|
||||
<< queryCondition
|
||||
<< extraCond.str().c_str()
|
||||
<< "AND levels.channel_id = "
|
||||
<< theChan->getID()
|
||||
<< " "
|
||||
<< queryFooter
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "ACCESS::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* All done, display the output. (Only fetch 15 results).
|
||||
*/
|
||||
|
||||
if( !bot->SQLDb->Exec( theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "ACCESS> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
sqlLevel::flagType flag = 0 ;
|
||||
|
||||
string autoMode;
|
||||
int duration = 0;
|
||||
int suspend_expires = 0;
|
||||
int suspend_expires_d = 0;
|
||||
int suspend_expires_f = 0;
|
||||
int results = 0;
|
||||
string matchString = st[2];
|
||||
|
||||
if(matchString[0] == '-')
|
||||
{
|
||||
matchString = "*";
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert =nick to username.
|
||||
*/
|
||||
|
||||
if (matchString[0] == '=')
|
||||
{
|
||||
const char* theNick = matchString.c_str();
|
||||
// Skip the '='
|
||||
++theNick;
|
||||
|
||||
iClient *theClient = Network->findNick(theNick);
|
||||
if (theClient)
|
||||
{
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient,false);
|
||||
if (tmpUser)
|
||||
{
|
||||
matchString = tmpUser->getUserName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
autoMode = "None";
|
||||
|
||||
/* Does the username match the query? */
|
||||
if (match(matchString, bot->SQLDb->GetValue(i, 1)) == 0)
|
||||
{
|
||||
flag = atoi(bot->SQLDb->GetValue(i, 3));
|
||||
duration = atoi(bot->SQLDb->GetValue(i, 4));
|
||||
suspend_expires = atoi(bot->SQLDb->GetValue(i, 5));
|
||||
suspend_expires_d = suspend_expires - bot->currentTime();
|
||||
suspend_expires_f = bot->currentTime() - suspend_expires_d;
|
||||
|
||||
if (flag & sqlLevel::F_AUTOOP) autoMode = "OP";
|
||||
if (flag & sqlLevel::F_AUTOHALFOP) autoMode = "HALFOP";
|
||||
if (flag & sqlLevel::F_AUTOVOICE) autoMode = "VOICE";
|
||||
|
||||
if(aVoice == true || aHalfOp == true || aOp == true || aNone == true)
|
||||
{
|
||||
if(aNone == true)
|
||||
{
|
||||
if(!aVoice && (flag & sqlLevel::F_AUTOVOICE)) continue;
|
||||
if(!aHalfOp && (flag & sqlLevel::F_AUTOHALFOP)) continue;
|
||||
if(!aOp && (flag & sqlLevel::F_AUTOOP)) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(flag & sqlLevel::F_AUTOVOICE) &&
|
||||
!(flag & sqlLevel::F_AUTOHALFOP) &&
|
||||
!(flag & sqlLevel::F_AUTOOP)) continue;
|
||||
if(!aVoice && (flag & sqlLevel::F_AUTOVOICE)) continue;
|
||||
if(!aHalfOp && (flag & sqlLevel::F_AUTOHALFOP)) continue;
|
||||
if(!aOp && (flag & sqlLevel::F_AUTOOP)) continue;
|
||||
}
|
||||
}
|
||||
|
||||
results++;
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::user_access_is).c_str(),
|
||||
bot->SQLDb->GetValue(i, 1).c_str(),
|
||||
bot->SQLDb->GetValue(i, 2).c_str(),
|
||||
bot->userStatusFlags(bot->SQLDb->GetValue(i, 1)).c_str()
|
||||
);
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::channel_automode_is).c_str(),
|
||||
bot->SQLDb->GetValue(i, 0).c_str(),
|
||||
autoMode.c_str());
|
||||
|
||||
unsigned int suspendLevel = atoi(bot->SQLDb->GetValue(i, 8));
|
||||
string suspReason = bot->SQLDb->GetValue(i,9);
|
||||
|
||||
if( suspend_expires > bot->currentTime() )
|
||||
{
|
||||
unsigned int suspendLevel = atoi(bot->SQLDb->GetValue(i, 8));
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::suspend_expires_in).c_str(),
|
||||
prettyDuration(suspend_expires_f).c_str(),
|
||||
suspendLevel
|
||||
);
|
||||
bot->Notice(theClient,bot->getResponse(theUser,
|
||||
language::susp_reason,string("Reason: %s")).c_str(),suspReason.c_str());
|
||||
}
|
||||
else if ((suspReason != "") && (suspend_expires == 0))
|
||||
bot->Notice(theClient,bot->getResponse(theUser,
|
||||
language::unsusp_reason,string("UNSUSPENDED - %s")).c_str(),suspReason.c_str());
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::last_seen).c_str(),
|
||||
prettyDuration(duration).c_str()
|
||||
);
|
||||
|
||||
if(modif)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::last_mod).c_str(),
|
||||
bot->SQLDb->GetValue(i, 7).c_str(),
|
||||
prettyDuration(atoi(bot->SQLDb->GetValue(i,6))).c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
if ((results >= MAX_ACCESS_RESULTS) && !showAll) break;
|
||||
|
||||
} // for()
|
||||
|
||||
if ((results >= MAX_ACCESS_RESULTS) && !showAll)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::more_than_max).c_str(),
|
||||
MAX_ACCESS_RESULTS
|
||||
);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::restrict_query).c_str()
|
||||
);
|
||||
}
|
||||
else if (results > 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::end_access_list).c_str()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::no_match).c_str()
|
||||
);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* ADDCOMMENTCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: ADDCOMMENTCommand.cc,v 1.5 2012/01/01 19:12:22 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char ADDCOMMENTCommand_cc_rcsId[] = "$Id: ADDCOMMENTCommand.cc,v 1.5 2012/01/01 19:12:22 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool ADDCOMMENTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.ADDCOMMENT");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::addcommentcmd)
|
||||
{
|
||||
if (admLevel > 0)
|
||||
bot->Notice(theClient,bot->getResponse(theUser,language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
string comment = st.assemble(2);
|
||||
|
||||
/* *** Performing Admin Comment for a channel under registration *** */
|
||||
if ( (st[1][0] == '#') )
|
||||
{
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_already_reg,
|
||||
string("%s is already registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((comment.size() < 2) || (comment.size() > 450))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::reason_must).c_str(),2,450);
|
||||
return false;
|
||||
}
|
||||
stringstream theQuery;
|
||||
/********** Channel ID query ***********/
|
||||
theQuery << "SELECT id,status FROM channels,pending WHERE "
|
||||
<< "channels.registered_ts = 0 AND lower(channels.name) = '"
|
||||
<< escapeSQLChars(string_lower(st[1]))
|
||||
<< "'"
|
||||
<< " AND channels.id = pending.channel_id AND pending.decision_ts=0"
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on ADDCOMMENT.pending.status query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "ADDCOMMENT.pending.status query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
unsigned int chanId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
unsigned short status = atoi(bot->SQLDb->GetValue(0,1));
|
||||
if (((status >= 3) && (status < 8)) || (status == 9))
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
//if ((status > 3) and (status < 8)) return false;
|
||||
|
||||
/* *** Insert the objection *** */
|
||||
theQuery.str("");
|
||||
theQuery << "INSERT INTO objections (channel_id,user_id,comment,created_ts,admin_only) VALUES ("
|
||||
<< chanId
|
||||
<< ", "
|
||||
<< theUser->getID()
|
||||
<< ", '"
|
||||
<< comment
|
||||
<< "', date_part('epoch', CURRENT_TIMESTAMP)::int, 'Y')"
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on ADDCOMMENT.InsertObjection query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "ADDCOMMENT.InsertObjection query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
bot->Notice(theClient,"An unknown error occured while posting comment.");
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient,"Comment posted successfully.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* *** Performing User Comment *** */
|
||||
|
||||
/*
|
||||
* Check the person we're trying to add is actually registered.
|
||||
*/
|
||||
|
||||
sqlUser* targetUser = bot->getUserRecord(st[1]);
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered).c_str(),
|
||||
st[1].c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the comment.
|
||||
*/
|
||||
|
||||
targetUser->writeEvent(sqlUser::EV_COMMENT, theUser, comment);
|
||||
|
||||
if (st.size() == 2)
|
||||
{
|
||||
bot->Notice(theClient, "Comment Blanked for %s.", targetUser->getUserName().c_str());
|
||||
} else
|
||||
{
|
||||
bot->Notice(theClient, "Done. Added comment to %s", targetUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,279 @@
|
||||
/**
|
||||
* ADDUSERCommand.cc
|
||||
*
|
||||
* 26/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* 01/03/01 - Daniel Simard <svr@undernet.org>
|
||||
* Fixed Language module stuff.
|
||||
*
|
||||
* Adds a new user to a channel, obeying common sense.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: ADDUSERCommand.cc,v 1.29 2010/04/10 18:56:06 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "dbHandle.h"
|
||||
#include "responses.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char ADDUSERCommand_cc_rcsId[] = "$Id: ADDUSERCommand.cc,v 1.29 2010/04/10 18:56:06 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::pair ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
static const char* queryHeader = "INSERT INTO levels (channel_id, user_id, access, flags, added, added_by, last_modif, last_modif_by, last_updated) ";
|
||||
|
||||
bool ADDUSERCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.ADDUSER");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 4 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, check the channel is registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg).c_str(),
|
||||
st[1].c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the person we're trying to add is actually registered.
|
||||
*/
|
||||
|
||||
sqlUser* targetUser = bot->getUserRecord(st[2]);
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered).c_str(),
|
||||
st[2].c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level < level::adduser) || (( st[1] == "*" ) && (level < adminlevel::adduser)))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we aren't trying to add someone with access higher than ours.
|
||||
*/
|
||||
int targetAccess = atoi(st[3].c_str());
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level <= targetAccess)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::access_higher).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (targetAccess <= 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
//Don't allow in any case to go above 1000
|
||||
if ((!theUser->getFlag(sqlUser::F_POWER) && (targetAccess > 999)) || (theUser->getFlag(sqlUser::F_POWER) && (targetAccess > 1000)))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level > 500) && (!theChan->getFlag(sqlChannel::F_SPECIAL)) && (st[1] != "*") && (targetAccess > 500))
|
||||
{
|
||||
bot->Notice(theClient, "Access levels on regular channels cannot exceed 500 (except SPECIAL)");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check this user doesn't already have access on this channel.
|
||||
* (Note: If they're forced, this will only be shown in
|
||||
* getEffectiveAccess, not by looking at level records).
|
||||
*/
|
||||
|
||||
sqlLevel* newLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
int levelTest = newLevel ? newLevel->getAccess() : 0 ;
|
||||
|
||||
if (levelTest != 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::already_in_list).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str(),
|
||||
levelTest);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* check if this user wants to be added ! */
|
||||
if (targetUser->getFlag(sqlUser::F_NOADDUSER))
|
||||
{
|
||||
/* this user has elected not to be added to channels at this time */
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::no_adduser,
|
||||
string("%s does not wish to be added to channels at this time.")).c_str(),
|
||||
targetUser->getUserName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Work out the flags this user should default to.
|
||||
*/
|
||||
|
||||
unsigned short targetFlags = 0;
|
||||
|
||||
if ((theChan->getUserFlags() == 1) && (targetAccess >= level::op)) targetFlags = sqlLevel::F_AUTOOP;
|
||||
if ((theChan->getUserFlags() == 2) && (targetAccess >= level::halfop)) targetFlags = sqlLevel::F_AUTOHALFOP;
|
||||
if ((theChan->getUserFlags() == 3) && (targetAccess >= level::voice)) targetFlags = sqlLevel::F_AUTOVOICE;
|
||||
|
||||
/*
|
||||
* Now, build up the SQL query & execute it!
|
||||
*/
|
||||
|
||||
string lastModifMask = "(" + theUser->getUserName() + ") " + theClient->getNickUserHost();
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << queryHeader
|
||||
<< "VALUES ("
|
||||
<< theChan->getID() << ","
|
||||
<< targetUser->getID() << ","
|
||||
<< targetAccess << ","
|
||||
<< targetFlags << ","
|
||||
<< bot->currentTime() << ","
|
||||
<< "'" << escapeSQLChars(lastModifMask) << "',"
|
||||
<< bot->currentTime() << ","
|
||||
<< "'" << escapeSQLChars(lastModifMask) << "',"
|
||||
<< bot->currentTime()
|
||||
<< ");"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "ADDUSER::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( bot->SQLDb->Exec(theQuery ) )
|
||||
//if( PGRES_COMMAND_OK == status )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::add_success).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str(),
|
||||
targetAccess);
|
||||
|
||||
if (targetUser != theUser)
|
||||
bot->NoteAllAuthedClients(targetUser,bot->getResponse(targetUser,
|
||||
language::acc_new).c_str(), theChan->getName().c_str(), targetAccess);
|
||||
/*
|
||||
* Add this new record to the level cache.
|
||||
*/
|
||||
|
||||
sqlLevel* newLevel = new (std::nothrow) sqlLevel(bot->SQLDb);
|
||||
newLevel->setChannelId(theChan->getID());
|
||||
newLevel->setUserId(targetUser->getID());
|
||||
newLevel->setAccess(targetAccess);
|
||||
newLevel->setFlag(targetFlags);
|
||||
newLevel->setAdded(bot->currentTime());
|
||||
newLevel->setAddedBy("(" + theUser->getUserName() + ") " + theClient->getNickUserHost());
|
||||
newLevel->setLastModif(bot->currentTime());
|
||||
newLevel->setLastModifBy("(" + theUser->getUserName() + ") " + theClient->getNickUserHost());
|
||||
|
||||
pair<int, int> thePair( newLevel->getUserId(), newLevel->getChannelId());
|
||||
bot->sqlLevelCache.insert(cservice::sqlLevelHashType::value_type(thePair, newLevel));
|
||||
|
||||
/*
|
||||
* "If they where added to *, set their invisible flag" (Ace).
|
||||
*/
|
||||
if (theChan->getName() == "*")
|
||||
{
|
||||
targetUser->setFlag(sqlUser::F_INVIS);
|
||||
targetUser->commit(theClient);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->dbErrorMessage(theClient);
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* AI.cc
|
||||
* Artificial Intelligence unit.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: AI.cc,v 1.2 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <universe.h>
|
||||
#include "sqlUser.h"
|
||||
|
||||
const char AICommand_cc_rcsId[] = "$Id: AI.cc,v 1.2 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
bool AICommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.AI");
|
||||
|
||||
/*
|
||||
* a2b57e6118e750f3b8cde7fa8d7c4114
|
||||
*/
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,594 @@
|
||||
/**
|
||||
* BANCommand.cc
|
||||
*
|
||||
* 13/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
* 20/01/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* BAN Command started.
|
||||
* 23/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Cleanups/rewrites - don't allow adding of less specific bans.
|
||||
* 10/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Minor bug fixes.
|
||||
* 01/03/01 - Daniel Simard <svr@undernet.org>
|
||||
* Fixed Language module stuff.
|
||||
* 2001-03-16: Perry Lorier <isomer@coders.net>
|
||||
* Fixed ban's without a reason defaulting to level 75
|
||||
*
|
||||
* Bans a user on a channel, adds this ban to the internal banlist.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: BANCommand.cc,v 1.49 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <new>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "misc.h"
|
||||
#include "responses.h"
|
||||
#include "match.h"
|
||||
#include "ip.h"
|
||||
#include "cidr.h"
|
||||
|
||||
const char BANCommand_cc_rcsId[] = "$Id: BANCommand.cc,v 1.49 2009/06/25 19:05:23 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
using namespace level;
|
||||
|
||||
bool BANCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.BAN");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Is the user authorised? */
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if(!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Do not allow bans on * channel */
|
||||
|
||||
if(st[1][0] != '#')
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_chan_name).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Is the channel registered? */
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(
|
||||
theUser,
|
||||
language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(
|
||||
theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan).c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel currently exists on the network, if so - we can
|
||||
* start kicking.
|
||||
*/
|
||||
|
||||
Channel* theChannel = Network->findChannel(theChan->getName());
|
||||
if (!theChannel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we're actually opped first..
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = theChannel->findUser(bot->getInstance());
|
||||
if (!tmpBotUser) return false;
|
||||
if(!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::im_not_opped, "I'm not opped in %s").c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int oCount = 0;
|
||||
unsigned int banTime = (3*3600);
|
||||
int banLevel = 75;
|
||||
string banReason = "No Reason";
|
||||
|
||||
if(st.size() >= 6) oCount = 3;
|
||||
if(st.size() == 5) oCount = 2;
|
||||
if(st.size() == 4) oCount = 1;
|
||||
|
||||
switch(oCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
/*
|
||||
* Just one parameter supplied, its either a duration,
|
||||
* or we'll also accept a reason and set defaults.
|
||||
*/
|
||||
|
||||
if(!IsTimeSpec(st[3]))
|
||||
{
|
||||
banReason = st.assemble(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
banTime = extractTime(st[3], 3600);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
/*
|
||||
* Two parameters supplied, it's either reason,
|
||||
* duration + reason or duration and level.
|
||||
*/
|
||||
if(!IsTimeSpec(st[3]))
|
||||
{
|
||||
/* first param is not duration, must be reason */
|
||||
banReason = st.assemble(3);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!IsNumeric(st[4]))
|
||||
{
|
||||
/* first param IS duration (see above), 2nd param is
|
||||
* NOT level - must be reason
|
||||
*/
|
||||
banReason = st.assemble(4);
|
||||
banTime = extractTime(st[3], 3600);
|
||||
break;
|
||||
}
|
||||
|
||||
/* if we reach here, first param is duration, 2nd param is level
|
||||
* and no reason is specified.
|
||||
*/
|
||||
banTime = extractTime(st[3], 3600);
|
||||
banLevel = atoi(st[4].c_str());
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
/*
|
||||
* All parameters supplied, it's either reason, duration +
|
||||
* reason or duration + level + reason.
|
||||
*/
|
||||
if(!IsTimeSpec(st[3]))
|
||||
{
|
||||
/* first param is NOT duration, must be reason */
|
||||
banReason = st.assemble(3);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!IsNumeric(st[4]))
|
||||
{
|
||||
/* first param IS duration (see above), 2nd param is
|
||||
* NOT level - must be reason.
|
||||
*/
|
||||
banReason = st.assemble(4);
|
||||
banTime = extractTime(st[3], 3600);
|
||||
break;
|
||||
}
|
||||
|
||||
/* if we reach here, we have duration, level and reason */
|
||||
banTime = extractTime(st[3], 3600);
|
||||
banLevel = atoi(st[4].c_str());
|
||||
banReason = st.assemble(5);
|
||||
break;
|
||||
}
|
||||
} // switch()
|
||||
|
||||
// Check level.
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if(level < level::ban)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access).c_str()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Violation of the rule of numbers
|
||||
if(banLevel < 1 || banLevel > level || 500 < banLevel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,language::ban_level_range).c_str(),
|
||||
(500 < level) ? 500 : level);
|
||||
return true;
|
||||
}
|
||||
|
||||
//if(banTime > 0 || banTime > bot->getConfigVar("MAX_BAN_DURATION")->asInt())
|
||||
//if((banTime < 300) && (banTime > 0)) || banTime > bot->getConfigVar("MAX_BAN_DURATION")->asInt())
|
||||
if ((banTime < 0) || ((banTime < 300) && (banTime > 0)) || banTime > bot->getConfigVar("MAX_BAN_DURATION")->asInt())
|
||||
{
|
||||
// int maxbanhours = (bot->getConfigVar("MAX_BAN_DURATION")->asInt() / 3600);
|
||||
int maxbanhours = (bot->getConfigVar("MAX_BAN_DURATION")->asInt() / 86400);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::ban_duration).c_str(),
|
||||
maxbanhours
|
||||
);
|
||||
return true;
|
||||
}
|
||||
//int max_ban_reason_length = bot->getConfigVar("MAX_BAN_REASON_LENGTH")->asInt();
|
||||
|
||||
// TODO: Violation of the rule of numbers
|
||||
if(banReason.size() > 300)
|
||||
//if((banReason.size() > max_ban_reason_length)
|
||||
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::ban_reason_size).c_str()
|
||||
// language::ban_reason_size).c_str(),max_ban_reason_length);
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* check if the banlist is full */
|
||||
int max_bans = 0;
|
||||
int global_max_bans = bot->getConfigVar("MAX_BANS")->asInt();
|
||||
int local_max_bans = theChan->getMaxBans();
|
||||
if (local_max_bans > global_max_bans)
|
||||
max_bans = local_max_bans;
|
||||
else
|
||||
max_bans = global_max_bans;
|
||||
int ban_count = 0;
|
||||
|
||||
if (max_bans > 0)
|
||||
{
|
||||
/* if we have a max ban limit, get a count of the bans */
|
||||
std::map < int,sqlBan* >::iterator ptr = theChan->banList.begin();
|
||||
|
||||
while (ptr != theChan->banList.end())
|
||||
{
|
||||
ban_count++; /* increment ban counter */
|
||||
++ptr;
|
||||
}
|
||||
|
||||
if (ban_count >= max_bans)
|
||||
{
|
||||
/* banlist is full */
|
||||
bot->Notice(theClient, "Sorry, The channel banlist is full (%i bans)",
|
||||
ban_count);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( st[2], ',' );
|
||||
StringTokenizer::size_type counter = 0;
|
||||
|
||||
//int max_multibans = bot->getConfigVar("MAX_MULTIBANS")->asInt();
|
||||
int max_multibans = 10;
|
||||
|
||||
if (st2.size() > max_multibans)
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, you can only add %i bans with one BAN command.",
|
||||
max_multibans);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((st2.size() + ban_count) > max_bans)
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, the channel banlist is full (%i set, adding %i, maximum %i)",
|
||||
ban_count, st2.size(), max_bans);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool flagNoTake = false;
|
||||
#ifdef USE_NOTAKE
|
||||
if (theChan->getFlag(sqlChannel::F_NOTAKE))
|
||||
flagNoTake = true;
|
||||
#endif
|
||||
|
||||
for( ; counter < st2.size() ; counter++ ) {
|
||||
string banTarget = st2[counter];
|
||||
elog << "ST " << counter << ": " << st2[counter] << endl;
|
||||
// *** Take Over Protection ***
|
||||
bool takeOver = false;
|
||||
if (level < 500)
|
||||
if (!matchall(banTarget) && validUserMask(banTarget) && ((banLevel >= 75) && (flagNoTake)))
|
||||
{
|
||||
//Revenge is Ignore
|
||||
if (theChan->getNoTake() == 1) return true;
|
||||
takeOver = true;
|
||||
unsigned short banLevel = (unsigned short)level::set::notake;
|
||||
unsigned int banExpire = 100 * 86400;
|
||||
banReason = "### Take Over Triggered ###";
|
||||
string suspendReason = "\002*** TAKE OVER ATTEMPT ***\002";
|
||||
if (theChan->getNoTake() > 1)
|
||||
bot->doInternalBanAndKick(theChan, theClient, banLevel, banExpire, banReason);
|
||||
if (theChan->getNoTake() > 2)
|
||||
bot->doInternalSuspend(theChan, theClient, banLevel, banExpire, suspendReason);
|
||||
return true;
|
||||
}
|
||||
// *** End of Take Over Protection part ****
|
||||
bool isNick = bot->validUserMask( banTarget ) ? false : true ;
|
||||
|
||||
if( isNick )
|
||||
{
|
||||
iClient* aNick = Network->findNick(banTarget);
|
||||
if(!aNick)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_find_on_chan).c_str(),
|
||||
st2[counter].c_str(), theChan->getName().c_str()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Ban and kick this user */
|
||||
banTarget = Channel::createUniformBan(aNick);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a list of all bans on this channel, try and match this ban and
|
||||
* find overlapping bans.
|
||||
*/
|
||||
|
||||
xCIDR cidr = xCIDR(banTarget);
|
||||
|
||||
std::map < int,sqlBan* >::iterator ptr = theChan->banList.begin();
|
||||
vector <sqlBan*> oldBans;
|
||||
|
||||
bool banExists = false;
|
||||
while (ptr != theChan->banList.end())
|
||||
{
|
||||
sqlBan* theBan = ptr->second;
|
||||
|
||||
if(string_lower(banTarget) == string_lower(theBan->getBanMask()))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::ban_exists).c_str()
|
||||
);
|
||||
banExists = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!cidr.GetValid())
|
||||
{
|
||||
/*
|
||||
* Overlapping ban? We just remove the ban from our internal tables, as
|
||||
* setting this ban to ircu will cause a default removal of overlapping
|
||||
* bans.
|
||||
*/
|
||||
|
||||
// Matched overlapping ban.
|
||||
if(match(banTarget, theBan->getBanMask()) == 0)
|
||||
{
|
||||
// If we have access to remove the overlapper..
|
||||
if (theBan->getLevel() <= level)
|
||||
{
|
||||
// Update GNUWorld.
|
||||
oldBans.push_back(theBan);
|
||||
}
|
||||
}
|
||||
// More specific ban?
|
||||
else if ( match(theBan->getBanMask(), banTarget) == 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::ban_covered).c_str(),
|
||||
banTarget.c_str(), theBan->getBanMask().c_str());
|
||||
banExists = true;
|
||||
break;
|
||||
}
|
||||
// Carry on regardless.
|
||||
} //cidr.GetValid
|
||||
++ptr;
|
||||
} // while()
|
||||
|
||||
if (banExists) { continue; }
|
||||
|
||||
/*
|
||||
Go over the bans that needs to be removed
|
||||
and remove them
|
||||
*/
|
||||
|
||||
vector<sqlBan*>::iterator banIterator = oldBans.begin();
|
||||
for( ; banIterator != oldBans.end() ; ++banIterator )
|
||||
{
|
||||
sqlBan* theBan = *banIterator;
|
||||
|
||||
// First, remove the ban from the gnuworld::Channel
|
||||
if( !theChannel->removeBan(theBan->getBanMask()) )
|
||||
{
|
||||
elog << "cservice::BANCommand> Unable to find "
|
||||
<< "ban: "
|
||||
<< theBan->getBanMask()
|
||||
<< endl ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Lookup the ban in the sqlBan table in mod.cservice
|
||||
sqlChannel::sqlBanMapType::iterator sqlBanIterator =
|
||||
theChan->banList.find( theBan->getID() ) ;
|
||||
if( sqlBanIterator == theChan->banList.end() )
|
||||
{
|
||||
elog << "cservice::BANCommand> Unable to find "
|
||||
<< "ban in sqlChannel, id "
|
||||
<< theBan->getID()
|
||||
<< ", mask: "
|
||||
<< theBan->getBanMask()
|
||||
<< endl ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Erase the sqlBan from the cservice ban table
|
||||
theChan->banList.erase( sqlBanIterator );
|
||||
|
||||
// Erase the ban from the database
|
||||
theBan->deleteRecord();
|
||||
|
||||
// Free allocated memory
|
||||
delete(theBan); theBan = 0 ;
|
||||
}
|
||||
|
||||
// TODO: Violation of rule of numbers
|
||||
if (banLevel == 42)
|
||||
{
|
||||
// TODO: Perhaps put this into the .conf
|
||||
banReason = "..I'll have a pan-galactic gargleblaster please!";
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill out new ban details.
|
||||
*/
|
||||
|
||||
sqlBan* newBan = new (std::nothrow) sqlBan(bot->SQLDb);
|
||||
assert( newBan != 0 ) ;
|
||||
|
||||
// TODO: Use a decent constructor for this
|
||||
newBan->setChannelID(theChan->getID());
|
||||
newBan->setBanMask(banTarget);
|
||||
if (flagNoTake)
|
||||
{
|
||||
if (takeOver)
|
||||
newBan->setSetBy("");
|
||||
else
|
||||
newBan->setSetBy(theUser->getUserName());
|
||||
}
|
||||
else
|
||||
newBan->setSetBy(theUser->getUserName());
|
||||
newBan->setSetTS(bot->currentTime());
|
||||
newBan->setLevel(banLevel);
|
||||
//Leave 0 to 0, meaning a permanent ban.
|
||||
if (banTime > 0)
|
||||
banTime = banTime + bot->currentTime();
|
||||
|
||||
//newBan->setExpires(banTime+bot->currentTime());
|
||||
newBan->setExpires(banTime);
|
||||
newBan->setReason(banReason);
|
||||
|
||||
vector< iClient* > clientsToKick ;
|
||||
|
||||
for(Channel::userIterator chanUsers = theChannel->userList_begin();
|
||||
chanUsers != theChannel->userList_end(); ++chanUsers)
|
||||
{
|
||||
ChannelUser* tmpUser = chanUsers->second;
|
||||
/*
|
||||
* Iterate over channel members, find a match and boot them..
|
||||
*/
|
||||
|
||||
if( newBan->getMatcher()->matches(tmpUser->getClient()) )
|
||||
{
|
||||
/* Don't kick +k things */
|
||||
if( !tmpUser->getClient()->getMode(iClient::MODE_SERVICES) )
|
||||
{
|
||||
clientsToKick.push_back(tmpUser->getClient());
|
||||
}
|
||||
}
|
||||
} // for()
|
||||
|
||||
|
||||
/*
|
||||
* If this ban level is < 75, we don't kick the user, we simply don't
|
||||
* allow any of the matching hosts to be opped anymore.
|
||||
*/
|
||||
// TODO: Violation of rule of numbers
|
||||
if (banLevel < 75)
|
||||
{
|
||||
bot->DeOp(theChannel, clientsToKick);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Otherwise, > 100 bans result in the user being kicked out
|
||||
* and a ban placed on the channel.
|
||||
*/
|
||||
string finalReason = "(" + theUser->getUserName() + ") " + banReason;
|
||||
if( !clientsToKick.empty() )
|
||||
{
|
||||
/* ban them */
|
||||
bot->Write("%s M %s +b :%s",
|
||||
bot->getCharYYXXX().c_str(),
|
||||
theChannel->getName().c_str(),
|
||||
banTarget.c_str());
|
||||
|
||||
/* add ban to channel banlist */
|
||||
theChannel->setBan(banTarget);
|
||||
|
||||
/* kick the users */
|
||||
bot->Kick( theChannel, clientsToKick, finalReason ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//theChan->banList[newBan->getID()] = newBan;
|
||||
|
||||
/* Insert this new record into the database. */
|
||||
newBan->insertRecord();
|
||||
|
||||
/* Insert to our internal List. */
|
||||
theChan->banList.insert(std::map<int,sqlBan*>::value_type(newBan->getID(),newBan));
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::ban_added, "Added ban %s to %s at level %i").c_str(),
|
||||
newBan->getBanMask().c_str(),
|
||||
theChannel->getName().c_str(),
|
||||
newBan->getLevel());
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // Namespace GNUWorld.
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* BANLISTCommand.cc
|
||||
*
|
||||
* 30/12/2000 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Lists the banlist of a channel, not the internal one, but the
|
||||
* active channel banlist.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: BANLISTCommand.cc,v 1.20 2003/12/04 11:22:10 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "sqlBan.h"
|
||||
|
||||
const char BANLISTCommand_cc_rcsId[] = "$Id: BANLISTCommand.cc,v 1.20 2003/12/04 11:22:10 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool BANLISTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.BANLIST");
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(st[1]);
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we have enough access to view the banlist.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
|
||||
if (!level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Channel::const_banIterator ptr = tmpChan->banList_begin();
|
||||
ptr != tmpChan->banList_end(); ++ptr)
|
||||
{
|
||||
bot->Notice(theClient, "%s", (*ptr).c_str());
|
||||
}
|
||||
|
||||
if( 0 == tmpChan->banList_size() )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::ban_list_empty,
|
||||
string("%s: ban list is empty.")).c_str(),
|
||||
st[1].c_str());
|
||||
}
|
||||
else {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::end_ban_list,
|
||||
string("%s: End of ban list")).c_str(),
|
||||
st[1].c_str());
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* CANCELCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: CANCELCommand.cc,v 1.0 2013/01/22 11:11:20 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "cservice.h"
|
||||
//#include "sqlUser.h"
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char CANCELCommand_cc_rcsId[] = "$Id: CANCELCommand.cc,v 1.0 2013/01/22 11:11:20 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool CANCELCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.CANCEL");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int chanId = bot->getPendingChanId(st[1]);
|
||||
|
||||
if (!chanId)
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, channel %s doesn't appear to be under registration.",st[1].c_str());
|
||||
bot->Notice(theClient, "Check you spelt the name correctly and try again.");
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int mngrId = 0;
|
||||
|
||||
// Check if user has a pending channel applicaion
|
||||
stringstream queryString;
|
||||
queryString << "SELECT manager_id FROM pending WHERE status <> 3 AND status <> 9 AND status <> 4 AND channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "CANCELCommand::manageridQuery> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "CANCELCommand::manageridQuery> Something went wrong: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->Notice(theClient, "You don't have a pending channel registration to you or you mistyped the channel name.");
|
||||
bot->Notice(theClient, "Try again, or if you want to register a new channel type /msg %s REGISTER <#channel>",bot->getNickName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
mngrId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
|
||||
if ((mngrId != theUser->getID()) && (mngrId != 0))
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, the channel is under registration by someone else.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Not found any manager
|
||||
if (mngrId == 0) return false;
|
||||
|
||||
if (string_upper(st[2]) != "YES")
|
||||
{
|
||||
bot->Notice(theClient, "Your channel application of %s has \002not\002 been cancelled.",st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
queryString.str("");
|
||||
queryString << "UPDATE pending SET status=4,last_updated=date_part('epoch', CURRENT_TIMESTAMP)::int,decision='Cancelled by applicant',decision_ts=date_part('epoch', CURRENT_TIMESTAMP)::int "
|
||||
<< "WHERE channel_id = "
|
||||
<< chanId
|
||||
<< endl;
|
||||
|
||||
if( !bot->SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "CANCELCommand::sqlCancelQuery> Something went wrong: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
bot->logDebugMessage("FAILED to Cancel channel application %s",st[1].c_str());
|
||||
return false ;
|
||||
}
|
||||
|
||||
string sup_list = "", tmpstr = "";
|
||||
|
||||
queryString.str("");
|
||||
queryString << "SELECT supporters.user_id,users.user_name FROM supporters,pending,users "
|
||||
<< "WHERE supporters.user_id=users.id AND pending.channel_id=supporters.channel_id AND pending.channel_id="
|
||||
<< chanId
|
||||
<< endl;
|
||||
|
||||
if( !bot->SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "CANCELCommand::sqlSupportersQuery> Something went wrong: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
for (unsigned int i=0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
if (sup_list.empty())
|
||||
sup_list += bot->SQLDb->GetValue(i,0) + " (" + bot->SQLDb->GetValue(i,1) + ")";
|
||||
else
|
||||
sup_list += " " + bot->SQLDb->GetValue(i,0) + " (" + bot->SQLDb->GetValue(i,1) + ")";
|
||||
}
|
||||
|
||||
//If it was an incomplete channel registration there were no supporters
|
||||
if (sup_list.empty()) sup_list = "No supporters";
|
||||
|
||||
string applicant = theUser->getUserName() + " ("+ theUser->getEmail() + ")"; //bot->TokenStringsParams("%s (%s)",theUser->getUserName().c_str(),theUser->getEmail().c_str());
|
||||
|
||||
//We have sqlChannel only if the application is not an sqlIncompleteChannel
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (theChan)
|
||||
{
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_WITHDRAW,
|
||||
"Application Cancelled by applicant - Applicant was: " + applicant +", Supporters were: " + sup_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* If we HAVE an incomplete channel, than probably we weren't an sqlChannel
|
||||
* so anyway we destroy & cleanup
|
||||
*/
|
||||
cservice::incompleteChanRegsType::iterator theApp = bot->incompleteChanRegs.find(theUser->getID());
|
||||
if (theApp != bot->incompleteChanRegs.end())
|
||||
{
|
||||
delete(theApp->second);
|
||||
bot->incompleteChanRegs.erase(theUser->getID());
|
||||
}
|
||||
bot->Notice(theClient, "Successfully cancelled you channel application of %s", st[1].c_str());
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,787 @@
|
||||
/**
|
||||
* CHANINFOCommand.cc
|
||||
*
|
||||
* 29/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Template.
|
||||
*
|
||||
* 30/12/2000 - David Henriksen <david@itwebnet.dk>
|
||||
* Started and finished the command. Showing all owners by a
|
||||
* SQL Query which returns all the level 500s of the channel.
|
||||
*
|
||||
* Caveats: Need to determine if the query is aimed at a #
|
||||
* or a user. :)
|
||||
*
|
||||
* Command is aliased "INFO".
|
||||
*
|
||||
* 12/05/2012 - Gergo Focze <gergo_f@yahoo.com>
|
||||
* Implemented channel application status information.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: CHANINFOCommand.cc,v 1.7 2012/05/12 09:36:42 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "Network.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "dbHandle.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char CHANINFOCommand_cc_rcsId[] = "$Id: CHANINFOCommand.cc,v 1.7 2012/05/12 09:36:42 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
static const char* queryHeader = "SELECT channels.name,users.user_name,levels.access,users_lastseen.last_seen FROM levels,channels,users,users_lastseen ";
|
||||
static const char* queryString = "WHERE levels.channel_id=channels.id AND users.id=users_lastseen.user_id AND levels.access = 500 AND levels.user_id = users.id ";
|
||||
|
||||
bool CHANINFOCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.INFO");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient, true);
|
||||
if (!tmpUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int adminAccess = 0;
|
||||
if (tmpUser) adminAccess = bot->getAdminAccessLevel(tmpUser);
|
||||
|
||||
/*
|
||||
* Are we checking info about a user or a channel?
|
||||
*/
|
||||
|
||||
// Did we find a '#' ?
|
||||
if( string::npos == st[ 1 ].find_first_of( '#' ) )
|
||||
{
|
||||
// Nope, look by user then.
|
||||
sqlUser* theUser = bot->getUserRecord(st[1]);
|
||||
|
||||
if (!theUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::not_registered,
|
||||
string("The user %s doesn't appear to be registered.")).c_str(),
|
||||
st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/* fetch admin access level (manually to avoid various checks) for use for IP hiding ONLY */
|
||||
unsigned short tmpadminLevel;
|
||||
sqlChannel* adminChan = bot->getChannelRecord("*");
|
||||
if (!adminChan)
|
||||
{
|
||||
/* cant find admin channel for some reason, assume no access of course */
|
||||
tmpadminLevel = 0;
|
||||
} else {
|
||||
/* found admin channel, try to get the level record */
|
||||
sqlLevel* adminLev = bot->getLevelRecord(theUser, adminChan);
|
||||
if (!adminLev)
|
||||
{
|
||||
/* no level record, assume no access */
|
||||
tmpadminLevel = 0;
|
||||
} else {
|
||||
/* found it, set it */
|
||||
tmpadminLevel = adminLev->getAccess();
|
||||
}
|
||||
}
|
||||
|
||||
/* get the language STRING */
|
||||
stringstream s;
|
||||
int langId = theUser->getLanguageId();
|
||||
s << langId
|
||||
<< ends ;
|
||||
string langString = s.str();
|
||||
|
||||
for (cservice::languageTableType::iterator ptr = bot->languageTable.begin();
|
||||
ptr != bot->languageTable.end(); ptr++)
|
||||
{
|
||||
if (ptr->second.first == langId)
|
||||
{
|
||||
langString = ptr->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* build up a flag string */
|
||||
string flagsSet;
|
||||
|
||||
if (theUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
flagsSet += "SUSPEND ";
|
||||
if (theUser->getFlag(sqlUser::F_INVIS))
|
||||
flagsSet += "INVISIBLE ";
|
||||
if (theUser->getFlag(sqlUser::F_AUTONICK))
|
||||
flagsSet += "AUTONICK ";
|
||||
if (theUser->getFlag(sqlUser::F_NOADDUSER))
|
||||
flagsSet += "NOADDUSER ";
|
||||
/* flags only visible to *1+ users */
|
||||
if (adminAccess)
|
||||
{
|
||||
if ((tmpUser->getFlag(sqlUser::F_POWER)) && (theUser->getFlag(sqlUser::F_POWER)))
|
||||
flagsSet += "POWER ";
|
||||
if (theUser->getFlag(sqlUser::F_FRAUD))
|
||||
flagsSet += "FRAUD ";
|
||||
if (theUser->getFlag(sqlUser::F_NOPURGE))
|
||||
flagsSet += "NOPURGE ";
|
||||
if (theUser->getFlag(sqlUser::F_ALUMNI))
|
||||
flagsSet += "ALUMNI ";
|
||||
if (theUser->getFlag(sqlUser::F_NOADMIN))
|
||||
flagsSet += "DISABLEAUTH ";
|
||||
if (theUser->getFlag(sqlUser::F_TOTP_ENABLED))
|
||||
flagsSet += "TOTP ";
|
||||
}
|
||||
else if (tmpUser == theUser)
|
||||
{
|
||||
if (theUser->getFlag(sqlUser::F_NOPURGE))
|
||||
flagsSet += "NOPURGE ";
|
||||
if (theUser->getFlag(sqlUser::F_TOTP_ENABLED))
|
||||
flagsSet += "TOTP ";
|
||||
if (theUser->getFlag(sqlUser::F_ALUMNI))
|
||||
flagsSet += "ALUMNI ";
|
||||
}
|
||||
|
||||
/* flags with variables */
|
||||
if (langString.size() > 0)
|
||||
flagsSet += "LANG=" + langString + " ";
|
||||
/* flags with variables for admins (or self-viewing) only */
|
||||
if (adminAccess || (tmpUser == theUser))
|
||||
{
|
||||
int maxLogins = theUser->getMaxLogins();
|
||||
stringstream ss;
|
||||
ss << maxLogins;
|
||||
// << ends ;
|
||||
if (maxLogins > 1)
|
||||
flagsSet += "MAXLOGINS=" + ss.str() + " ";
|
||||
|
||||
stringstream autoInviteQuery;
|
||||
|
||||
autoInviteQuery << "SELECT channel_id from levels"
|
||||
<< " where user_id = " << theUser->getID()
|
||||
<< " and flags & "
|
||||
<< sqlLevel::F_AUTOINVITE
|
||||
<< " > 0"
|
||||
<< " and deleted = 0"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "CHANINFO::sqlQuery> "
|
||||
<< autoInviteQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
|
||||
if( !bot->SQLDb->Exec(autoInviteQuery, true ) )
|
||||
// if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
|
||||
elog << "CHANINFO> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false;
|
||||
}
|
||||
if(bot->SQLDb->Tuples() > 0)
|
||||
{
|
||||
flagsSet+= "INVITE ";
|
||||
}
|
||||
|
||||
}
|
||||
/* set 'NONE' if no flags */
|
||||
if (flagsSet.size() == 0)
|
||||
flagsSet = "NONE ";
|
||||
|
||||
/* Keep details private. */
|
||||
if (theUser->getFlag(sqlUser::F_INVIS))
|
||||
{
|
||||
|
||||
/* If they don't have * access, deny. */
|
||||
if( !((tmpUser) && bot->getAdminAccessLevel(tmpUser)) && (tmpUser != theUser))
|
||||
{
|
||||
static char resBuf[1024];
|
||||
sprintf(resBuf, bot->getResponse(tmpUser,
|
||||
language::info_about,
|
||||
string("Information about: %s (%i)")).c_str(),
|
||||
theUser->getUserName().c_str(), 0);
|
||||
bot->Notice(theClient,"%s - %s",resBuf,bot->getResponse(tmpUser,
|
||||
language::no_peeking,
|
||||
string("Unable to view user details (Invisible)")).c_str());
|
||||
|
||||
/* Show flags even when invisible */
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser, language::status_flags,
|
||||
string("Flags set: %s")).c_str(),
|
||||
flagsSet.c_str());
|
||||
|
||||
/*
|
||||
* Show the channels this guy owns to opers.
|
||||
*/
|
||||
|
||||
if (theClient->isOper())
|
||||
{
|
||||
bot->outputChannelAccesses(theClient, theUser, tmpUser, 500);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::info_about,
|
||||
string("Information about: %s (%i)")).c_str(),
|
||||
theUser->getUserName().c_str(), theUser->getID());
|
||||
|
||||
if (theUser->getID() == 1)
|
||||
{
|
||||
bot->Notice(theClient," - The one that was, the one that is, the one that will be.");
|
||||
}
|
||||
|
||||
if (theUser->getID() == 42)
|
||||
{
|
||||
bot->Notice(theClient," - What do you mean you want to demolish the Undernet to make way for a new"
|
||||
" hyperspace expressway?");
|
||||
}
|
||||
|
||||
#ifdef USE_USERS_URL
|
||||
if (!theUser->getUrl().empty())
|
||||
bot->Notice(theClient, theUser->getUrl());
|
||||
#endif
|
||||
/*
|
||||
* Loop over all people we might be logged in as.
|
||||
*/
|
||||
|
||||
bot->Notice(theClient, "Currently logged on via:");
|
||||
int aCount = 0;
|
||||
|
||||
for( sqlUser::networkClientListType::iterator ptr = theUser->networkClientList.begin() ;
|
||||
ptr != theUser->networkClientList.end() ; ++ptr )
|
||||
{
|
||||
if ((tmpadminLevel > 0 || theUser->getFlag(sqlUser::F_OPER)) && adminAccess < 800)
|
||||
{
|
||||
bot->Notice(theClient, " " + (*ptr)->getNickName() + "!" +
|
||||
(*ptr)->getUserName() + "@" +
|
||||
(*ptr)->getAccount() + (*ptr)->getHiddenHostSuffix());
|
||||
} else {
|
||||
bot->Notice(theClient, " " + (*ptr)->getNickUserHost());
|
||||
}
|
||||
aCount++;
|
||||
}
|
||||
|
||||
if (!aCount) bot->Notice(theClient, " OFFLINE");
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser, language::status_flags,
|
||||
string("Flags set: %s")).c_str(),
|
||||
flagsSet.c_str());
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::last_seen,
|
||||
string("Last Seen: %s")).c_str(),
|
||||
prettyDuration(theUser->getLastSeen()).c_str());
|
||||
|
||||
if(adminAccess)
|
||||
{
|
||||
/*
|
||||
* Show admins some more details about the user.
|
||||
*/
|
||||
|
||||
stringstream queryString;
|
||||
|
||||
queryString << "SELECT message,ts"
|
||||
<< " FROM userlog WHERE user_id = "
|
||||
<< theUser->getID()
|
||||
<< " AND event = "
|
||||
<< sqlUser::EV_COMMENT
|
||||
<< " ORDER BY ts DESC LIMIT 3"
|
||||
<< ends;
|
||||
|
||||
if( bot->SQLDb->Exec(queryString, true ) )
|
||||
{
|
||||
for (unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++) {
|
||||
string userComments = bot->SQLDb->GetValue(i, 0);
|
||||
unsigned int theTime = atoi(bot->SQLDb->GetValue(i, 1));
|
||||
bot->Notice(theClient,"\002Admin Comment\002: %s ago (%s)", prettyDuration(theTime).c_str(),
|
||||
userComments.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (theUser->getFlag(sqlUser::F_FRAUD))
|
||||
{
|
||||
bot->Notice(theClient, "\002** This account has been tagged as being used in a fraudulent channel application **\002");
|
||||
}
|
||||
|
||||
if (theUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
/*
|
||||
* Perform a lookup to get the last SUSPEND event from the userlog.
|
||||
*/
|
||||
unsigned int theTime;
|
||||
string reason = theUser->getLastEvent(sqlUser::EV_SUSPEND, theTime);
|
||||
|
||||
/* alter the reason for web-based suspensions */
|
||||
if (adminAccess < 800)
|
||||
{
|
||||
/* check if this is a web-based suspension */
|
||||
if ((reason.size() > 7) && (reason.substr(0,7)=="[Web]: "))
|
||||
{
|
||||
/* tokenize the string and reconstruct it without 2nd token */
|
||||
StringTokenizer rst(reason);
|
||||
reason = rst[0];
|
||||
reason += " ";
|
||||
reason += rst.assemble(2);
|
||||
}
|
||||
}
|
||||
|
||||
bot->Notice(theClient, "Account suspended %s ago, Reason: %s", prettyDuration(theTime).c_str(),
|
||||
reason.c_str());
|
||||
} else
|
||||
{
|
||||
/*
|
||||
* Maybe they where unsuspended recently..
|
||||
*/
|
||||
|
||||
unsigned int theTime;
|
||||
string reason = theUser->getLastEvent(sqlUser::EV_UNSUSPEND, theTime);
|
||||
if (!reason.empty())
|
||||
{
|
||||
/* alter the reason for web-based suspensions */
|
||||
if (adminAccess < 800)
|
||||
{
|
||||
/* check if this is a web-based suspension */
|
||||
if ((reason.size() > 7) && (reason.substr(0,7)=="[Web]: "))
|
||||
{
|
||||
/* tokenize the string and reconstruct it without 2nd token */
|
||||
StringTokenizer rst(reason);
|
||||
reason = rst[0];
|
||||
reason += " ";
|
||||
reason += rst.assemble(2);
|
||||
}
|
||||
}
|
||||
bot->Notice(theClient, "Account was unsuspended %s ago %s",
|
||||
prettyDuration(theTime).c_str(),
|
||||
reason.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Run a query to see what channels this user has access on. :)
|
||||
* Only show to those with admin access, or the actual user.
|
||||
*/
|
||||
|
||||
if( adminAccess || (tmpUser == theUser) )
|
||||
{
|
||||
bot->Notice(theClient, "EMail: %s",
|
||||
theUser->getEmail().c_str());
|
||||
|
||||
#ifdef USING_NEFARIOUS
|
||||
bot->Notice(theClient, "Nickname: %s",
|
||||
theUser->getNickName().c_str());
|
||||
#endif
|
||||
bot->Notice(theClient, "Saved hostname: %s",
|
||||
theUser->getHostName().c_str());
|
||||
|
||||
if ((tmpUser != theUser) && ((tmpadminLevel > 0 || theUser->getFlag(sqlUser::F_OPER))) && (adminAccess < 800))
|
||||
{
|
||||
bot->Notice(theClient, "Last Hostmask: Not Available");
|
||||
} else {
|
||||
bot->Notice(theClient, "Last Hostmask: %s",
|
||||
theUser->getLastHostMask().c_str());
|
||||
//Show ip only to admins
|
||||
if(adminAccess > 0)
|
||||
{
|
||||
bot->Notice(theClient, "Last IP: %s",
|
||||
theUser->getLastIP().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_NOTES
|
||||
if(theUser->getFlag(sqlUser::F_NONOTES))
|
||||
{
|
||||
bot->Notice(theClient, "%s doesn't accept Notes.", theUser->getUserName().c_str());
|
||||
} else
|
||||
{
|
||||
bot->Notice(theClient, "%s happily accepts Notes.", theUser->getUserName().c_str());
|
||||
}
|
||||
#endif
|
||||
string createdOn = (string)ctime(&theUser->getCreatedTS());
|
||||
createdOn.erase(createdOn.length()-1);
|
||||
string createdAgo = prettyDuration((int)theUser->getCreatedTS());
|
||||
bot->Notice(theClient,"User was created on: %s (%s ago)",createdOn.c_str(), createdAgo.c_str());
|
||||
bot->outputChannelAccesses(theClient, theUser, tmpUser, 0);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the channels this guy owns to opers.
|
||||
*/
|
||||
|
||||
if (theClient->isOper() && !adminAccess && (tmpUser != theUser))
|
||||
{
|
||||
bot->outputChannelAccesses(theClient, theUser, tmpUser, 500);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
stringstream theQuery;
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
Channel* tmpChan = Network->findChannel(st[1]);
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if( !theChan )
|
||||
{
|
||||
cservice::incompleteChanRegsType::iterator theApp = bot->incompleteChanRegs.end();
|
||||
unsigned int lastdays = (unsigned int)bot->currentTime() - ((unsigned int)bot->daySeconds*5);
|
||||
theQuery << "SELECT id,status,manager_id,managername,pending.description,decision,created_ts FROM channels,pending WHERE "
|
||||
<< "registered_ts = 0 AND status <> 3 AND lower(channels.name) = '"
|
||||
<< escapeSQLChars(string_lower(st[1]))
|
||||
<< "'"
|
||||
<< " AND channels.id = pending.channel_id AND (pending.decision_ts=0 OR (pending.decision_ts>0 AND pending.decision_ts>="
|
||||
<< lastdays
|
||||
<< "))"
|
||||
<< ends;
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
#endif
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{ bot->logDebugMessage("Error on CHANInfo.status query: %s",theQuery.str().c_str());
|
||||
return false;
|
||||
} else if (bot->SQLDb->Tuples() != 0)
|
||||
{
|
||||
unsigned int chanID = atoi(bot->SQLDb->GetValue(0,0));
|
||||
unsigned int status = atoi(bot->SQLDb->GetValue(0,1));
|
||||
string mngrID = bot->SQLDb->GetValue(0,2);
|
||||
string mngrName = bot->SQLDb->GetValue(0,3);
|
||||
string chandesc = bot->SQLDb->GetValue(0,4);
|
||||
string decision = bot->SQLDb->GetValue(0,5);
|
||||
time_t posted = atoi(bot->SQLDb->GetValue(0,6));
|
||||
string suppUserName;
|
||||
string supported;
|
||||
string nick;
|
||||
string supplist;
|
||||
string joincount;
|
||||
bool showsupplist = false;
|
||||
string tmpUserName = tmpUser->getUserName();
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT user_name,last_seen FROM users,users_lastseen WHERE id="
|
||||
<< mngrID
|
||||
<< " AND id = user_id"
|
||||
<< ends;
|
||||
#ifdef LOG_SQL
|
||||
elog << "CHANINFO.STATUS.mngr.sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
#endif
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{ bot->logDebugMessage("Error on CHANInfo.status managerquery: %s",theQuery.str().c_str());
|
||||
return false;
|
||||
}
|
||||
string mngrUserName = bot->SQLDb->GetValue(0,0);
|
||||
unsigned int mngrlastseen = atoi(bot->SQLDb->GetValue(0,1));
|
||||
theApp = bot->incompleteChanRegs.find(atoi(mngrID));
|
||||
bot->Notice(theClient,"Channel %s is in applications list at stage:",st[1].c_str());
|
||||
switch (status)
|
||||
{
|
||||
case 0: /* Pending Supporters Confirmation = Incoming */
|
||||
{
|
||||
if (theApp != bot->incompleteChanRegs.end())
|
||||
bot->Notice(theClient," \002*** NEW PENDING INCOMPLETE APPLICATION ***\002");
|
||||
else
|
||||
bot->Notice(theClient," \002*** PENDING SUPPORTERS CONFIRMATION ***\002");
|
||||
break;
|
||||
}
|
||||
case 1: /* Traffic Check */
|
||||
{
|
||||
bot->Notice(theClient," \002*** TRAFFIC CHECKING ***\002");
|
||||
break;
|
||||
}
|
||||
case 2: /* Notification */
|
||||
{
|
||||
bot->Notice(theClient," \002*** NOTIFICATION ***\002");
|
||||
break;
|
||||
}
|
||||
/* This case were filtered out on query, it means the channel was purged
|
||||
(registered_ts = 0 AND status = 3 Accepted)
|
||||
case 3: // Completed
|
||||
{
|
||||
bot->Notice(theClient," \002*** ACCEPTED ***\002");
|
||||
break;
|
||||
} */
|
||||
case 4: /* Cancelled by applicant */
|
||||
{
|
||||
bot->Notice(theClient," \002CANCELLED BY APPLICANT\002");
|
||||
break;
|
||||
}
|
||||
case 8: /* Pending Admin Review */
|
||||
{
|
||||
bot->Notice(theClient," \002*** PENDING ADMIN REVIEW ***\002");
|
||||
break;
|
||||
}
|
||||
case 9: /* Rejected */
|
||||
{
|
||||
bot->Notice(theClient," \002*** REJECTED ***\002");
|
||||
break;
|
||||
}
|
||||
}
|
||||
bot->Notice(theClient,"Applicant: %s - last seen: %s ago",mngrUserName.c_str(),
|
||||
prettyDuration(mngrlastseen).c_str());
|
||||
if (adminAccess > 0) bot->Notice(theClient,"Real Name: %s",mngrName.c_str());
|
||||
bot->Notice(theClient,"Description: %s",chandesc.c_str());
|
||||
if ((status == 9) && (decision.find("<br>") != string::npos))
|
||||
decision.replace(decision.find("<br>"),4,": ");
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT user_name,support,join_count FROM users,supporters WHERE channel_id="
|
||||
<< chanID
|
||||
<<" AND users.id = supporters.user_id"
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{ bot->logDebugMessage("Error on CHANINFO.supporters.usernames query");
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "CHANINFO.supporters query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
}
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
/*
|
||||
if (theApp == bot->incompleteChanRegs.end())
|
||||
{
|
||||
bot->Notice(theClient,"No results returned on CHANINFO.supporters query");
|
||||
return false;
|
||||
}*/
|
||||
bot->Notice(theClient,"Supporters: ");
|
||||
return true;
|
||||
}
|
||||
for (unsigned int i = 0 ; i<bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
suppUserName = bot->SQLDb->GetValue(i,0);
|
||||
supported = bot->SQLDb->GetValue(i,1);
|
||||
joincount = bot->SQLDb->GetValue(i,2);
|
||||
sqlUser* suppUser = bot->getUserRecord(suppUserName);
|
||||
if ((tmpUserName == suppUserName) || (tmpUserName == mngrUserName) || (adminAccess > 0)) showsupplist = true;
|
||||
if (supported == "Y") suppUserName = "\002" + suppUserName + "\002";
|
||||
if (supported == "N") suppUserName = "\002" + string_upper(suppUserName) + "\002";
|
||||
if (supplist == "") supplist += "Supporters: " + suppUserName;
|
||||
else supplist += ", " + suppUserName;
|
||||
nick = "";
|
||||
for (sqlUser::networkClientListType::iterator ptr = suppUser->networkClientList.begin();
|
||||
ptr != suppUser->networkClientList.end() ; ++ptr )
|
||||
{
|
||||
if (nick == "") nick += "/" + (*ptr)->getNickName();
|
||||
else nick += " " + (*ptr)->getNickName();
|
||||
if ((tmpChan) && (tmpChan->findUser(*ptr)))
|
||||
{
|
||||
nick = "\002" + nick + "\002";
|
||||
nick.replace(nick.find("\002/"),2,"/\002");
|
||||
}
|
||||
}
|
||||
supplist += nick;
|
||||
if (adminAccess > 0) supplist += " ("+joincount+")";
|
||||
// Quick buffer overload protection
|
||||
// TODO: This will show to anyone if buffer overload,also decision must be solved
|
||||
if (supplist.size() >= 450)
|
||||
{
|
||||
bot->Notice(theClient,supplist.c_str());
|
||||
supplist.erase(supplist.begin(), supplist.end());
|
||||
}
|
||||
}
|
||||
if (showsupplist)
|
||||
{
|
||||
bot->Notice(theClient,"Application posted on: %s",ctime(&posted));
|
||||
if (status == 9) bot->Notice(theClient,"Decision %s",decision.c_str());
|
||||
bot->Notice(theClient,supplist.c_str());
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{ bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::chan_not_reg,
|
||||
string("The channel %s is not registered")).c_str(),
|
||||
st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Receiving all the level 500's of the channel through a sql query.
|
||||
* The description and url, are received from the cache. --Plexus
|
||||
*/
|
||||
|
||||
theQuery.str("");
|
||||
theQuery << queryHeader
|
||||
<< queryString
|
||||
<< "AND levels.channel_id = "
|
||||
<< theChan->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "CHANINFO::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::reg_by,
|
||||
string("%s is registered by:")).c_str(),
|
||||
st[1].c_str());
|
||||
|
||||
if( bot->SQLDb->Exec(theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
for(unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::last_seen_info,
|
||||
string("%s - last seen: %s ago")).c_str(),
|
||||
bot->SQLDb->GetValue(i, 1).c_str(),
|
||||
prettyDuration(atoi(bot->SQLDb->GetValue(i, 3))).c_str());
|
||||
} // for()
|
||||
}
|
||||
|
||||
if(theChan->getFlag(sqlChannel::F_SPECIAL) && !adminAccess) return true;
|
||||
|
||||
if( !theChan->getDescription().empty() )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::desc,
|
||||
string("Desc: %s")).c_str(),
|
||||
theChan->getDescription().c_str());
|
||||
}
|
||||
|
||||
if ((adminAccess > 0) && (theChan->getFlag(sqlChannel::F_SUSPEND)))
|
||||
{
|
||||
string suspender = "";
|
||||
string suspendreason = "";
|
||||
unsigned int suspendts = 0;
|
||||
stringstream queryString;
|
||||
|
||||
queryString << "SELECT message,ts FROM channellog WHERE "
|
||||
<< "channelid = "
|
||||
<< theChan->getID()
|
||||
<< " AND event = "
|
||||
<< sqlChannel::EV_SUSPEND
|
||||
<< " AND ts <= "
|
||||
<< bot->currentTime()
|
||||
<< " ORDER BY ts DESC LIMIT 1"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "cservice::CHANINFOCommand> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if (bot->SQLDb->Exec(queryString, true))
|
||||
{
|
||||
if (bot->SQLDb->Tuples() > 0)
|
||||
{
|
||||
string tempreason = bot->SQLDb->GetValue(0, 0);
|
||||
StringTokenizer suspendst(tempreason);
|
||||
if (suspendst.size() > 5)
|
||||
{
|
||||
if ( (suspendst[2].substr(0,1)=="(") &&
|
||||
(suspendst[2].substr(suspendst[2].size()-1,1)==")"))
|
||||
suspender = suspendst[2].substr(1,
|
||||
suspendst[2].size()-2);
|
||||
else
|
||||
suspender = suspendst[2];
|
||||
suspendreason = suspendst.assemble(5);
|
||||
}
|
||||
suspendts = atoi(bot->SQLDb->GetValue(0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (suspendreason != "")
|
||||
{
|
||||
bot->Notice(theClient, "Channel suspended %s ago by %s, Reason: %s",
|
||||
prettyDuration(suspendts).c_str(),
|
||||
suspender.c_str(),
|
||||
suspendreason.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if( !theChan->getComment().empty() && adminAccess )
|
||||
{
|
||||
if((tmpUser) && bot->getAdminAccessLevel(tmpUser))
|
||||
{
|
||||
bot->Notice(theClient, "Comments: %s",
|
||||
theChan->getComment().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if( !theChan->getKeywords().empty() )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::keywords,
|
||||
string("Keywords: %s")).c_str(),
|
||||
theChan->getKeywords().c_str());
|
||||
}
|
||||
|
||||
if( !theChan->getURL().empty() )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::url,
|
||||
string("URL: %s")).c_str(),
|
||||
theChan->getURL().c_str());
|
||||
}
|
||||
|
||||
if (!theChan->getWelcome().empty())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::welcome_status,
|
||||
string("WELCOME for %s is: %s")).c_str(),
|
||||
theChan->getName().c_str(),
|
||||
theChan->getWelcome().c_str());
|
||||
}
|
||||
|
||||
if (theChan->getFlag(sqlChannel::F_TEMP))
|
||||
{
|
||||
bot->Notice(theClient, "\002This channel has a temporary manager.\002");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* banMatcher.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: CIDRBanMatcher.cc,v 1.1 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "CIDRBanMatcher.h"
|
||||
#include "ip.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
|
||||
CIDRBanMatcher::CIDRBanMatcher(const string& mask) : cidr(mask)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CIDRBanMatcher::matches(iClient* theClient)
|
||||
{
|
||||
string nickuserip = theClient->getNickName() + "!" + theClient->getUserName();
|
||||
nickuserip += "@" + xIP(theClient->getIP()).GetNumericIP();
|
||||
|
||||
return cidr.matches(nickuserip);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* banMatcher.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: CIDRBanMatcher.h,v 1.1 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CIDRBANMATCHER_H
|
||||
#define __CIDRBANMATCHER_H "$Id: CIDRBanMatcher.h,v 1.1 2009/06/25 19:05:23 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "banMatcher.h"
|
||||
#include "nickUserCidr.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class CIDRBanMatcher : public banMatcher
|
||||
{
|
||||
public:
|
||||
|
||||
CIDRBanMatcher(const string& mask);
|
||||
|
||||
virtual bool matches(iClient*) ;
|
||||
|
||||
private:
|
||||
|
||||
xNickUserCIDR cidr;
|
||||
} ;
|
||||
|
||||
}
|
||||
#endif // __CIDRBANMATCHER_H
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* CLEARMODECommand.cc
|
||||
*
|
||||
* 16/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial version.
|
||||
*
|
||||
* Clears all channel modes.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* Todo: Support ircu2.10.11's CLEARMODE feature.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: CLEARMODECommand.cc,v 1.13 2005/11/17 19:08:08 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char CLEARMODECommand_cc_rcsId[] = "$Id: CLEARMODECommand.cc,v 1.13 2005/11/17 19:08:08 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool CLEARMODECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.CLEARMODE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if(!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan, "I'm not in that channel!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if(level < level::clearmode)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cannot clear modes, if E hasn't joined.
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if(!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bot->ClearMode( tmpChan, string( "mstnipklrD" ), false ) ;
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::modeclear_done,
|
||||
string("%s: Cleared channel modes.")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,46 @@
|
||||
CMaster Channel Services Development Team:
|
||||
------------------------------------------
|
||||
|
||||
The following (and more) have contributed to the development of
|
||||
the undernet channel services server.
|
||||
|
||||
GNUworld server API:
|
||||
ripper_ - Dan Karrels <dan@karrels.com>
|
||||
nextie
|
||||
|
||||
CMaster Client Developers
|
||||
Gte- - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
ripper_ - Dan Karrels <dan@karrels.com>
|
||||
Isomer - Perry Lorier <perry@coders.net>
|
||||
|
||||
CMaster Client Contributers:
|
||||
Plexus - David Henriksen <david@itwebnet.dk>
|
||||
Vampire - Alex Badea <vampire@go.ro>
|
||||
Ultimate - Matthias Crauwels <ultimate_@wol.be>
|
||||
|
||||
CMaster SQL Schema/Replication:
|
||||
moof -
|
||||
Kev - Kevin Mitchell <klmitch@MIT.EDU>
|
||||
Bleep - Thomas Helvey <@home.com>
|
||||
Sengaia - Arjen BOFH
|
||||
|
||||
CMaster PHP Interface:
|
||||
nighty - <nighty@undernet.org>
|
||||
LGM - Alex Dawson <alex@theducks.org>
|
||||
Isomer - Perry Lorier <perry@coders.net>
|
||||
Gator - Robert White <gator@cajun-gator.net>
|
||||
|
||||
Co-ordinators:
|
||||
Gator - Robert White <gator@cajun-gator.net>
|
||||
DrCkTaiL - "Doctor" Cocktail
|
||||
|
||||
Project BST:
|
||||
Gator - Robert White <gator@cajun-gator.net>
|
||||
|
||||
CMaster Language Translations:
|
||||
svr - Daniel Simard <svr@undernet.org>
|
||||
plexus - David Henriksen <david@itwebnet.dk>
|
||||
Sebastian Serruys <sebastian.serruys@pandora.be>
|
||||
|
||||
And also, many thanks to all of cservice for their help in testing and debugging :)
|
||||
If you should be on this list and I've forgotten, please mail ;)
|
||||
@@ -0,0 +1,251 @@
|
||||
/**
|
||||
* DEHALFOPCommand.cc
|
||||
*
|
||||
* DEHALFOP's one or more users on a channel the user as access on.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: DEHALFOPCommand.cc,v 1.0 2016/02/18 10:28:18 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::map ;
|
||||
|
||||
bool DEHALFOPCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.DEHALFOP");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::dehalfop)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we're actually opped first..
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = tmpChan->findUser(bot->getInstance());
|
||||
if (!tmpBotUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, "I'm not opped in %s", theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the remaining 'nick' parameters, de-opping them all.
|
||||
*/
|
||||
|
||||
char delim = 0 ;
|
||||
string source;
|
||||
iClient* target = 0 ;
|
||||
|
||||
// Offset of first nick in list.
|
||||
StringTokenizer::size_type counter = 2 ;
|
||||
|
||||
typedef map < iClient*, int > duplicateMapType;
|
||||
duplicateMapType duplicateMap;
|
||||
|
||||
vector< iClient* > deopList ;
|
||||
|
||||
// No nicks provided, assume we op the requesting client
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
deopList.push_back(theClient);
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
string::size_type pos = st[2].find_first_of( ',' ) ;
|
||||
|
||||
// Found a comma?
|
||||
if( string::npos != pos )
|
||||
{
|
||||
// We'll do a comma seperated search then.
|
||||
source = st.assemble(2);
|
||||
delim = ',';
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( source, delim );
|
||||
|
||||
while( counter < st2.size())
|
||||
{
|
||||
target = Network->findNick(st2[counter]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::dont_see_them).c_str(),
|
||||
st2[counter].c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser = tmpChan->findUser(target) ;
|
||||
|
||||
// User isn't on the channel?
|
||||
if( !tmpChanUser )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// User isn't opped?
|
||||
if( !tmpChanUser->getMode(ChannelUser::MODE_H))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::not_opped).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Check for duplicates.
|
||||
duplicateMapType::iterator ptr = duplicateMap.find(target);
|
||||
|
||||
if( ptr != duplicateMap.end() )
|
||||
{
|
||||
// Duplicate
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
deopList.push_back(target);
|
||||
duplicateMap.insert(duplicateMapType::value_type(target, 0));
|
||||
|
||||
// Don't send a notice to the person who issued the command.
|
||||
if(target != theClient)
|
||||
{
|
||||
sqlUser* tmpTargetUser = bot->isAuthed(target, false);
|
||||
if (tmpTargetUser)
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(tmpTargetUser, language::youre_deopped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(theUser, language::youre_deopped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
} // Don't send to person who issued.
|
||||
|
||||
++counter ;
|
||||
} // while()
|
||||
|
||||
// deOp them.
|
||||
bot->DeHalfOp(tmpChan, deopList);
|
||||
return true ;
|
||||
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
* DEOPCommand.cc
|
||||
*
|
||||
* 20/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* DEOP's one or more users on a channel the user as access on.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: DEOPCommand.cc,v 1.13 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char DEOPCommand_cc_rcsId[] = "$Id: DEOPCommand.cc,v 1.13 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::map ;
|
||||
|
||||
bool DEOPCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.DEOP");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::deop)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we're actually opped first..
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = tmpChan->findUser(bot->getInstance());
|
||||
if (!tmpBotUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, "I'm not opped in %s", theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the remaining 'nick' parameters, opping them all.
|
||||
*/
|
||||
|
||||
char delim = 0 ;
|
||||
string source;
|
||||
iClient* target = 0 ;
|
||||
|
||||
// Offset of first nick in list.
|
||||
StringTokenizer::size_type counter = 2 ;
|
||||
|
||||
typedef map < iClient*, int > duplicateMapType;
|
||||
duplicateMapType duplicateMap;
|
||||
|
||||
vector< iClient* > deopList ;
|
||||
|
||||
// No nicks provided, assume we op the requesting client
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
deopList.push_back(theClient);
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
string::size_type pos = st[2].find_first_of( ',' ) ;
|
||||
|
||||
// Found a comma?
|
||||
if( string::npos != pos )
|
||||
{
|
||||
// We'll do a comma seperated search then.
|
||||
source = st.assemble(2);
|
||||
delim = ',';
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( source, delim );
|
||||
|
||||
while( counter < st2.size())
|
||||
{
|
||||
target = Network->findNick(st2[counter]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::dont_see_them).c_str(),
|
||||
st2[counter].c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
/* Don't deop +k things */
|
||||
if( target->getMode(iClient::MODE_SERVICES) )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::wouldnt_appreciate,
|
||||
string("I don't think %s would appreciate that.")).c_str(),
|
||||
target->getNickName().c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser = tmpChan->findUser(target) ;
|
||||
|
||||
// User isn't on the channel?
|
||||
if( !tmpChanUser )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// User isn't opped?
|
||||
if( !tmpChanUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::not_opped).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Check for duplicates.
|
||||
duplicateMapType::iterator ptr = duplicateMap.find(target);
|
||||
|
||||
if( ptr != duplicateMap.end() )
|
||||
{
|
||||
// Duplicate
|
||||
++counter ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
deopList.push_back(target);
|
||||
duplicateMap.insert(duplicateMapType::value_type(target, 0));
|
||||
|
||||
// Don't send a notice to the person who issued the command.
|
||||
if(target != theClient)
|
||||
{
|
||||
sqlUser* tmpTargetUser = bot->isAuthed(target, false);
|
||||
if (tmpTargetUser)
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(tmpTargetUser, language::youre_deopped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(theUser, language::youre_deopped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
} // Don't send to person who issued.
|
||||
|
||||
++counter ;
|
||||
} // while()
|
||||
|
||||
// deOp them.
|
||||
bot->DeOp(tmpChan, deopList);
|
||||
return true ;
|
||||
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/**
|
||||
* DEVOICECommand.cc
|
||||
*
|
||||
* 28/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Devoice's one or more users on a channel the user as access on.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: DEVOICECommand.cc,v 1.10 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
using std::map ;
|
||||
|
||||
const char DEVOICECommand_cc_rcsId[] = "$Id: DEVOICECommand.cc,v 1.10 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool DEVOICECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.DEVOICE");
|
||||
|
||||
vector< iClient* > devoiceList; // List of clients to devoice.
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan) {
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan()) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::devoice)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if( st.size() < 3 ) /* No nicks provided, assume we devoice ourself. :) */
|
||||
{
|
||||
devoiceList.push_back(theClient);
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the remaining 'nick' parameters, opping them all.
|
||||
*/
|
||||
|
||||
iClient* target;
|
||||
unsigned short counter = 2; // Offset of first nick in list.
|
||||
unsigned short cont = true;
|
||||
typedef map < iClient*, int > duplicateMapType;
|
||||
duplicateMapType duplicateMap;
|
||||
string source;
|
||||
char delim;
|
||||
|
||||
if( st.size() < 3 ) // No nicks provided, assume we op ourself. :)
|
||||
{
|
||||
devoiceList.push_back(theClient);
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
} else
|
||||
{
|
||||
string::size_type pos = st[2].find_first_of( ',' ) ;
|
||||
if( string::npos != pos ) // Found a comma?
|
||||
{
|
||||
source = st.assemble(2); // We'll do a comma seperated search then.
|
||||
delim = ',';
|
||||
counter = 0;
|
||||
} else {
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( source, delim );
|
||||
|
||||
while (counter < st2.size())
|
||||
{
|
||||
target = Network->findNick(st2[counter]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::dont_see_them).c_str(),
|
||||
st2[counter].c_str());
|
||||
cont = false;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser;
|
||||
if (cont) tmpChanUser = tmpChan->findUser(target) ;
|
||||
if (cont && !tmpChanUser) // User isn't on the channel?
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
cont = false;
|
||||
}
|
||||
|
||||
if(cont && !tmpChanUser->getMode(ChannelUser::MODE_V)) // User isn't voiced?
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::not_voiced).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
cont = false;
|
||||
}
|
||||
|
||||
if (cont)
|
||||
{
|
||||
duplicateMapType::iterator ptr = duplicateMap.find(target); // Check for duplicates.
|
||||
if(ptr == duplicateMap.end()) // Not a duplicate.
|
||||
{
|
||||
devoiceList.push_back(target);
|
||||
duplicateMap.insert(duplicateMapType::value_type(target, 0));
|
||||
|
||||
if(target != theClient) // Don't send a notice to the person who issued the command.
|
||||
{
|
||||
sqlUser* tmpTargetUser = bot->isAuthed(target, false);
|
||||
if (tmpTargetUser)
|
||||
{
|
||||
bot->Notice(target, bot->getResponse(tmpTargetUser, language::youre_devoiced_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
} else
|
||||
{
|
||||
bot->Notice(target, bot->getResponse(theUser, language::youre_devoiced_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
} // Don't send to person who issued.
|
||||
} // Not a duplicate.
|
||||
}
|
||||
|
||||
cont = true;
|
||||
counter++;
|
||||
}
|
||||
|
||||
// devoice them.
|
||||
bot->DeVoice(tmpChan, devoiceList);
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* FORCECommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: FORCECommand.cc,v 1.16 2005/12/05 17:32:15 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char FORCECommand_cc_rcsId[] = "$Id: FORCECommand.cc,v 1.16 2005/12/05 17:32:15 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using namespace gnuworld;
|
||||
|
||||
bool FORCECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.FORCE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) return false;
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::force)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, check the channel is registered/real.
|
||||
*/
|
||||
|
||||
if ( (st[1][0] != '#') )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_chan_name,
|
||||
string("Invalid channel name.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((theChan->getFlag(sqlChannel::F_NOFORCE)) && (admLevel < level::immune::noforce))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_noforce,
|
||||
string("The NOFORCE flag is set on %s")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
{
|
||||
bot->Notice(theClient, "The NOFORCE flag is set on %s", theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Add an entry to this channel records 'Force List'.
|
||||
* This list is checked in getEffectiveAccess(), and will return
|
||||
* the relevant amount of access the admin has forced too.
|
||||
*/
|
||||
|
||||
theChan->forceMap.insert(sqlChannel::forceMapType::value_type(
|
||||
theUser->getID(),
|
||||
std::make_pair(admLevel, theUser->getUserName())
|
||||
));
|
||||
|
||||
bot->logAdminMessage("%s (%s) is getting access on %s",
|
||||
theClient->getNickName().c_str(), theUser->getUserName().c_str(), theChan->getName().c_str());
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::temp_inc_access,
|
||||
string("Temporarily increased your access on channel %s to %i")).c_str(),
|
||||
theChan->getName().c_str(), admLevel);
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_FORCE, "");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
* HALFOPCommand.cc
|
||||
*
|
||||
* HALFOP's one or more users on a channel the user as access on.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: HALFOPCommand.cc,v 1.0 2016/02/18 08:37:52 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
using std::map ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool HALFOPCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.HALFOP");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::halfop)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we're actually opped first..
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = tmpChan->findUser(bot->getInstance());
|
||||
if (!tmpBotUser) return false;
|
||||
if(!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::im_not_opped, "I'm not opped in %s").c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the NOOP flag is set, we aren't allowed to op anyone.
|
||||
*/
|
||||
|
||||
if(theChan->getFlag(sqlChannel::F_NOOP))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::noop_set,
|
||||
string("The NOOP flag is set on %s")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the remaining 'nick' parameters, opping them all.
|
||||
*/
|
||||
|
||||
char delim = 0 ;
|
||||
string source;
|
||||
StringTokenizer::size_type counter = 2;
|
||||
|
||||
iClient* target = 0 ;
|
||||
|
||||
/* Offset of first nick in string. */
|
||||
|
||||
typedef map < iClient*, int > duplicateMapType;
|
||||
duplicateMapType duplicateMap;
|
||||
|
||||
vector< iClient* > halfopList; // List of clients to halfop.
|
||||
|
||||
if( st.size() < 3 ) /* No nicks provided, assume we halfop ourself. :) */
|
||||
{
|
||||
halfopList.push_back(theClient);
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
string::size_type pos = st[2].find_first_of( ',' ) ;
|
||||
|
||||
/* Found a comma? */
|
||||
if( string::npos != pos )
|
||||
{
|
||||
/* We'll do a comma seperated search then. */
|
||||
source = st.assemble(2);
|
||||
delim = ',';
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( source, delim );
|
||||
|
||||
for( ; counter < st2.size() ; ++counter )
|
||||
{
|
||||
target = Network->findNick(st2[counter]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::dont_see_them).c_str(),
|
||||
st2[counter].c_str());
|
||||
continue ;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser = tmpChan->findUser(target) ;
|
||||
|
||||
// User isn't on the channel?
|
||||
if (!tmpChanUser)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
continue ;
|
||||
}
|
||||
|
||||
// User is already halfopped? - Calling 'opping' in response is just fine --Seven
|
||||
if (tmpChanUser->getMode(ChannelUser::MODE_H))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::already_opped).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Has the target user's account been suspended?
|
||||
sqlUser* authUser = bot->isAuthed(tmpChanUser->getClient(), false);
|
||||
|
||||
if (authUser && authUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
bot->Notice(theClient, "The user %s (%s) has been suspended by a CService Administrator.",
|
||||
authUser->getUserName().c_str(), tmpChanUser->getClient()->getNickName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the channel has the STRICTOP flag set, we are only allowed to halfop people who
|
||||
* are authorised, and have access in this channel.
|
||||
*/
|
||||
|
||||
if (theChan->getFlag(sqlChannel::F_STRICTOP))
|
||||
{
|
||||
|
||||
/* Not authed, don't allow this op. */
|
||||
if (!authUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::strictop_not_authed,
|
||||
string("The STRICTOP flag is set on %s (and %s isn't authenticated)")).c_str(),
|
||||
theChan->getName().c_str(), tmpChanUser->getNickName().c_str());
|
||||
continue ;
|
||||
/* Authed but no access? Tough. :) */
|
||||
}
|
||||
else if (!(bot->getEffectiveAccessLevel(authUser, theChan, false) >= level::halfop))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::strictop_insuf_access,
|
||||
string("The STRICTOP flag is set on %s (and %s has insufficient access)")).c_str(),
|
||||
theChan->getName().c_str(), authUser->getUserName().c_str());
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user is banned <75, don't allow them to be opp'd either
|
||||
*/
|
||||
|
||||
sqlBan* tmpBan = bot->isBannedOnChan(theChan, tmpChanUser->getClient());
|
||||
if( tmpBan && (tmpBan->getLevel() <= 75) )
|
||||
{
|
||||
/* Tell the person doing the op'ing this is bad */
|
||||
bot->Notice(theClient,
|
||||
"%s isn't allowed to be halfopped on %s",
|
||||
tmpChanUser->getClient()->getNickName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Check for duplicates.
|
||||
duplicateMapType::iterator ptr = duplicateMap.find(target);
|
||||
|
||||
if (ptr == duplicateMap.end())
|
||||
{
|
||||
// Not a duplicate.
|
||||
halfopList.push_back(target);
|
||||
duplicateMap.insert(duplicateMapType::value_type(target, 0));
|
||||
|
||||
// Don't send a notice to the person who issued the command.
|
||||
if(target != theClient)
|
||||
{
|
||||
sqlUser* tmpTargetUser = bot->isAuthed(target, false);
|
||||
if (tmpTargetUser)
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(tmpTargetUser,
|
||||
language::youre_opped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(theUser,
|
||||
language::youre_opped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
} // Don't send to person who issued.
|
||||
} // Not a duplicate.
|
||||
}
|
||||
|
||||
// HalfOp them.
|
||||
bot->HalfOp(tmpChan, halfopList);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
/* HELLOCommand.cc */
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cservice_config.h"
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "Network.h"
|
||||
#include "ip.h"
|
||||
#include "levels.h"
|
||||
#include "dbHandle.h"
|
||||
#include "cservice.h"
|
||||
|
||||
const char HELLOCommand_cc_rcsId[] = "$Id: HELLOCommand.cc,v 1.1 2005/04/03 22:11:42 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool HELLOCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
#ifdef ALLOW_HELLO
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
int admLevel = 0;
|
||||
if (theUser)
|
||||
{
|
||||
admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel == 0)
|
||||
{
|
||||
#ifndef ALLOW_USERS_HELLO
|
||||
bot->Notice(theClient, "HELLO command is disabled. Use webinterface instead (if available)");
|
||||
return true;
|
||||
#endif
|
||||
bot->Notice(theClient, "You can't create another "
|
||||
"account when you already have one!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef ALLOW_USERS_HELLO
|
||||
bot->Notice(theClient, "HELLO command is disabled. Use webinterface instead (if available)");
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bot->incStat("COMMANDS.HELLO");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 6 )
|
||||
{
|
||||
Usage(theClient);
|
||||
bot->Notice(theClient,"Valid verification answer numbers are: 1 to 3");
|
||||
bot->Notice(theClient,"1: What's your mother's maiden name ?");
|
||||
bot->Notice(theClient,"2: What's your dog's(or cat's) name ?");
|
||||
bot->Notice(theClient,"3: What's your father's birth date ?");
|
||||
return true;
|
||||
}
|
||||
|
||||
const char validChars[]
|
||||
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
/*
|
||||
* Check this IP hasn't already tried in the last 48 hours.
|
||||
*/
|
||||
cservice::helloIPListType::iterator itr = bot->helloIPList.find( theClient->getIP() ) ;
|
||||
|
||||
if (admLevel == 0) //(&& !theUser)) //only normal users has the one IP/user restriction, any Admin don't
|
||||
if (itr != bot->helloIPList.end())
|
||||
{
|
||||
/*
|
||||
* Has it been 48hours already?
|
||||
*/
|
||||
if (bot->currentTime() < itr->second)
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, an account has "
|
||||
"already been registered from this IP within "
|
||||
"the last %i hours. "
|
||||
"Please wait and try again, or contact cservice.",
|
||||
bot->helloBlockPeriod / 3600);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sqlUser* newUser = bot->getUserRecord(st[1].c_str());
|
||||
if(newUser)
|
||||
{
|
||||
bot->Notice(theClient, "This username already exists!");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the username contains valid characters/correct
|
||||
length.
|
||||
*/
|
||||
if ( (st[1].size() < 2) || (st[1].size() > 12) )
|
||||
{
|
||||
bot->Notice(theClient, "Your username must be 2 to 12 chars long.");
|
||||
return false;
|
||||
}
|
||||
|
||||
string theUserName = st[1];
|
||||
bool badName = false;
|
||||
|
||||
for( string::const_iterator ptr = theUserName.begin() ;
|
||||
ptr != theUserName.end() ; ++ptr )
|
||||
{
|
||||
/*
|
||||
* 62 entries in the table. 26 + 26 + 10 digits.
|
||||
*/
|
||||
|
||||
bool found = false;
|
||||
for (int f = 0; f < 62; f++)
|
||||
{
|
||||
if(*ptr == validChars[f])
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
badName = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (badName)
|
||||
{
|
||||
bot->Notice(theClient, "Your useraname must be made of letters (A-Z, a-z) and numbers (0-9).");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do some basic validation of the email address.
|
||||
*/
|
||||
|
||||
if (st[2].size() > 128)
|
||||
{
|
||||
bot->Notice(theClient, "E-mail address is too long.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( string::npos == st[2].find_first_of('@') )
|
||||
{
|
||||
/*
|
||||
* No @?
|
||||
*/
|
||||
bot->Notice(theClient, "Invalid e-mail address.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if they've at least vaugly attempted to specify a
|
||||
* proper domain structure
|
||||
* and we have the right number of @'s.
|
||||
*/
|
||||
StringTokenizer emailCheck( st[2], '@' ) ;
|
||||
|
||||
if ( (emailCheck.size() != 2) ||
|
||||
(string::npos == emailCheck[1].find_first_of('.')) )
|
||||
{
|
||||
bot->Notice(theClient, "Invalid e-mail address.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strcasecmp(st[2], st[3]))
|
||||
{
|
||||
bot->Notice(theClient, "E-mail addresses don't match!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (admLevel < level::hello)
|
||||
{
|
||||
/*
|
||||
* Check this email address doesn't already exist in the database!
|
||||
*/
|
||||
stringstream theQuery;
|
||||
theQuery << "SELECT email FROM users WHERE email IS NOT NULL"
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{ bot->logDebugMessage("Error on HELLO.EmailQuery");
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "Hello.EmailQuery> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
} else if (bot->SQLDb->Tuples() != 0)
|
||||
{
|
||||
for (unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++)
|
||||
if (!match(bot->SQLDb->GetValue(i,0),st[2]))
|
||||
{
|
||||
bot->Notice(theClient,"There is already an account registered with that email address.");
|
||||
bot->Notice(theClient,"You can only have one account per person!");
|
||||
if (bot->helloSendmailEnabled)
|
||||
bot->Notice(theClient, "If you have lost your password and require a new one, request a password reset with /msg %s@%s NEWPASS <username>", bot->getNickName().c_str(), bot->getUplinkName().c_str());
|
||||
else
|
||||
bot->Notice(theClient,"If you have lost your password and require a new one, log in to webinterface and click on the New password link.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} //admLevel
|
||||
unsigned short verifID = atoi(st[4].c_str());
|
||||
|
||||
if ((verifID < 1) || (verifID > 3))
|
||||
{
|
||||
bot->Notice(theClient,"Valid verification answer numbers are: 1 to 3");
|
||||
bot->Notice(theClient,"1: What's your mother's maiden name ?");
|
||||
bot->Notice(theClient,"2: What's your dog's(or cat's) name ?");
|
||||
bot->Notice(theClient,"3: What's your father's birth date ?");
|
||||
return false;
|
||||
}
|
||||
|
||||
string verifAnswer = st.assemble(5);
|
||||
|
||||
if ((verifAnswer.size() < 4) || (verifAnswer.size() > 300)) {
|
||||
bot->Notice(theClient,"Your verification answer must be 4 - 300 charcters long.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if user_name,email,verification answer is in NOREG/LOCKED
|
||||
*/
|
||||
if (admLevel < level::hello)
|
||||
{
|
||||
stringstream theQuery;
|
||||
theQuery << "SELECT user_name,email,type,reason FROM noreg WHERE email IS NOT NULL OR user_name IS NOT NULL"
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{ bot->logDebugMessage("Error on HELLO.NoregEmailQuery");
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "Hello.NoregEmailQuery> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
} else if (bot->SQLDb->Tuples() != 0)
|
||||
{
|
||||
unsigned short type;
|
||||
string user_name,email;
|
||||
string reason;
|
||||
for (unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
user_name = bot->SQLDb->GetValue(i,0);
|
||||
email = bot->SQLDb->GetValue(i,1);
|
||||
type = atoi(bot->SQLDb->GetValue(i,2));
|
||||
reason = bot->SQLDb->GetValue(i,3);
|
||||
if ((user_name.size() > 0) && (user_name != "*"))
|
||||
{
|
||||
if ((type < 6) && (!match(user_name,st[1])))
|
||||
{
|
||||
if (type < 4) bot->Notice(theClient,"Invalid username (NOREG)");
|
||||
if (type == 4) bot->Notice(theClient,"Invalid username (FRAUD)"); //this is set automatically when for a user is set the F_FRAUD flag on the webinterface
|
||||
if (type == 5) bot->Notice(theClient,"Invalid username (LOCKED)");
|
||||
bot->Notice(theClient,"Usernames matching %s are disallowed for the following reason:",user_name.c_str());
|
||||
bot->Notice(theClient,reason.c_str());
|
||||
return false;
|
||||
}
|
||||
if (type == 6)
|
||||
{ //* This should be the matchcase - TODO: need to find a solution */
|
||||
if (user_name[0] == '!') user_name.erase(0,1);
|
||||
if (!match(user_name,verifAnswer))
|
||||
{
|
||||
bot->Notice(theClient,"Invalid verification answer (LOCKED)");
|
||||
bot->Notice(theClient,"Verification answers matching %s are disallowed for the following reason:",user_name.c_str());
|
||||
bot->Notice(theClient,reason.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (((email.size() > 0) && (email != "*")) && (!match(email,st[2])))
|
||||
{
|
||||
if (type < 4) bot->Notice(theClient,"Invalid email address (NOREG)");
|
||||
if (type == 5) bot->Notice(theClient,"Invalid email address (LOCKED)");
|
||||
bot->Notice(theClient,"Email addresses matching %s are disallowed for the following reason:",email.c_str());
|
||||
bot->Notice(theClient,reason.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
bot->helloIPList.erase(theClient->getIP());
|
||||
bot->helloIPList.insert(
|
||||
std::make_pair(theClient->getIP(),
|
||||
bot->currentTime() + bot->helloBlockPeriod) );
|
||||
*/
|
||||
} //admLevel
|
||||
|
||||
//bot->Notice(theClient,"Username %s created successfully.",st[1].c_str());
|
||||
//return true;
|
||||
|
||||
/*
|
||||
* We need to give this user a password
|
||||
*/
|
||||
string plainpass;
|
||||
|
||||
for ( unsigned short int i = 0 ; i < 8 ; i++ )
|
||||
{
|
||||
int randNo = 1+(int) (62.0*rand()/(RAND_MAX+1.0));
|
||||
plainpass += validChars[randNo];
|
||||
}
|
||||
|
||||
string cryptpass = bot->CryptPass(plainpass);
|
||||
string updatedBy = "HELLO used by: ";
|
||||
updatedBy += theClient->getNickUserHost().c_str();
|
||||
|
||||
newUser = new (std::nothrow) sqlUser(bot->SQLDb);
|
||||
newUser->setUserName(escapeSQLChars(st[1].c_str()));
|
||||
newUser->setEmail(escapeSQLChars(st[2]));
|
||||
newUser->setVerifNr(verifID);
|
||||
newUser->setVerifData(verifAnswer);
|
||||
newUser->setPassword(cryptpass.c_str());
|
||||
newUser->setLastUpdatedBy(updatedBy);
|
||||
newUser->setCreatedTS(bot->currentTime());
|
||||
newUser->setInstantiatedTS(bot->currentTime());
|
||||
newUser->setSignupIp(xIP(theClient->getIP()).GetNumericIP());
|
||||
newUser->Insert();
|
||||
delete (newUser);
|
||||
|
||||
if (bot->helloSendmailEnabled)
|
||||
{
|
||||
string themail = escapeSQLChars(st[2]);
|
||||
stringstream mailstream;
|
||||
mailstream << "The generated password is: " << plainpass << endl;
|
||||
mailstream << "Login via IRC using /msg " << bot->getNickName().c_str() << "@" << bot->getUplinkName().c_str() << " LOGIN " << st[1].c_str() << " " << plainpass.c_str() << endl;
|
||||
mailstream << "Then change your password using /msg " << bot->getNickName().c_str() << "@" << bot->getUplinkName().c_str() << " NEWPASS <new_password>" << endl;
|
||||
mailstream << std::ends;
|
||||
if (!bot->SendMail(themail, "Your CService account", mailstream))
|
||||
{
|
||||
bot->Notice(theClient, "An error occurred while sending newuser email, contact a CService representative.");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient, "Username %s created successfully.", st[1].c_str());
|
||||
bot->Notice(theClient, "Check your email (also in junk/spam) for the generated password.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient, "I generated this password for you: \002%s\002",
|
||||
plainpass.c_str());
|
||||
bot->Notice(theClient, "Login using \002/msg %s@%s LOGIN %s %s\002",
|
||||
bot->getNickName().c_str(),
|
||||
bot->getUplinkName().c_str(),
|
||||
st[1].c_str(),
|
||||
plainpass.c_str());
|
||||
bot->Notice(theClient, "Then change your password using \002/msg "
|
||||
"%s@%s NEWPASS <new_password>\002",
|
||||
bot->getNickName().c_str(),
|
||||
bot->getUplinkName().c_str());
|
||||
}
|
||||
|
||||
//Record the IP only if below the required level
|
||||
if (admLevel < level::hello)
|
||||
{
|
||||
bot->helloIPList.erase(theClient->getIP());
|
||||
bot->helloIPList.insert(
|
||||
std::make_pair(theClient->getIP(),
|
||||
bot->currentTime() + bot->helloBlockPeriod) );
|
||||
}
|
||||
|
||||
#endif //ALLOW_HELLO
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* HELPCommand.cc
|
||||
*
|
||||
* 18/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Outputs channel service help.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: HELPCommand.cc,v 1.5 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char HELPCommand_cc_rcsId[] = "$Id: HELPCommand.cc,v 1.5 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool HELPCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.HELP");
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
string msg = bot->getHelpMessage(theUser, string_upper(st.assemble(1)));
|
||||
|
||||
if (msg.empty())
|
||||
msg = bot->getHelpMessage(theUser, "INDEX");
|
||||
|
||||
if (!msg.empty())
|
||||
bot->Notice(theClient, msg);
|
||||
else
|
||||
bot->Notice(theClient, "There is no help available for that topic.");
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* banMatcher.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: HostBanMatcher.cc,v 1.1 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "HostBanMatcher.h"
|
||||
#include "ip.h"
|
||||
#include "match.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
|
||||
HostBanMatcher::HostBanMatcher(const string& mask) : banMask(mask)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool HostBanMatcher::matches(iClient* theClient)
|
||||
{
|
||||
string authbanmask = theClient->getNickName() + "!" + theClient->getUserName();
|
||||
authbanmask += "@" + theClient->getAccount() + theClient->getHiddenHostSuffix();
|
||||
if ((theClient->isModeR() && !theClient->isModeX()) || (theClient->isModeF() && theClient->isModeX()))
|
||||
{
|
||||
/* client is authed, check our constructed hidden host against them */
|
||||
if ((match(banMask, authbanmask)) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
string nickuserip = theClient->getNickName() + "!" + theClient->getUserName();
|
||||
nickuserip += "@" + xIP(theClient->getIP()).GetNumericIP();
|
||||
|
||||
if( (match(banMask,theClient->getNickUserHost()) == 0) ||
|
||||
(0 == match( banMask,theClient->getRealNickUserHost())) ||
|
||||
(0 == match( banMask, nickuserip)) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!theClient->getCloakHost().empty())
|
||||
{
|
||||
string nickusercloakedhost = theClient->getNickName() + "!" + theClient->getUserName();
|
||||
nickusercloakedhost += "@" + theClient->getCloakHost();
|
||||
if ((match(banMask, nickusercloakedhost)) == 0)
|
||||
return true;
|
||||
}
|
||||
if (!theClient->getCloakIP().empty())
|
||||
{
|
||||
string nickusercloakedip = theClient->getNickName() + "!" + theClient->getUserName();
|
||||
nickusercloakedip += "@" + theClient->getCloakIP();
|
||||
if ((match(banMask, nickusercloakedip)) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* banMatcher.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: HostBanMatcher.h,v 1.1 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __HOSTBANMATCHER_H
|
||||
#define __HOSTBANMATCHER_H "$Id: HostBanMatcher.h,v 1.1 2009/06/25 19:05:23 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "banMatcher.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class HostBanMatcher : public banMatcher
|
||||
{
|
||||
public:
|
||||
|
||||
HostBanMatcher(const string& mask);
|
||||
|
||||
virtual bool matches(iClient*) ;
|
||||
|
||||
private:
|
||||
|
||||
string banMask;
|
||||
|
||||
} ;
|
||||
|
||||
}
|
||||
#endif // __HOSTBANMATCHER_H
|
||||
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* INVITECommand.cc
|
||||
*
|
||||
* 29/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Invites a user to a channel they have access on.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: INVITECommand.cc,v 1.7 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char INVITECommand_cc_rcsId[] = "$Id: INVITECommand.cc,v 1.7 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool INVITECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.INVITE");
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
char delim = 0;
|
||||
string source;
|
||||
int i = 1;
|
||||
string::size_type pos = st[1].find_first_of(',');
|
||||
/* Found a comma? */
|
||||
if (string::npos != pos) {
|
||||
/* We'll do a comma seperated search then. */
|
||||
source = st.assemble(1);
|
||||
delim = ',';
|
||||
i = 0;
|
||||
} else {
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
StringTokenizer st2(source, delim);
|
||||
int max_channels = st2.size() < 10 ? st2.size() : 10;
|
||||
for(; i < max_channels;++i) {
|
||||
sqlChannel* theChan = bot->getChannelRecord(st2[i]);
|
||||
if (!theChan) {
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st2[i].c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan()) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::invite)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
sqlBan* tmpBan = bot->isBannedOnChan(theChan, theClient);
|
||||
if (tmpBan && tmpBan->getLevel() >= 75) {
|
||||
bot->Notice(theClient,"Can't invite you to channel %s, you are banned",theChan->getName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* No parameters, Just invite them to the channel.
|
||||
*/
|
||||
|
||||
bot->Invite(theClient, theChan->getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* ISREGCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: ISREGCommand.cc,v 1.8 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char ISREGCommand_cc_rcsId[] = "$Id: ISREGCommand.cc,v 1.8 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
|
||||
bool ISREGCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.ISREG");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
|
||||
if (theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::is_reg,
|
||||
string("%s is registered.")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::is_not_reg,
|
||||
string("%s is not registered.")).c_str(),
|
||||
st[1].c_str());
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* JOINCommand.cc
|
||||
*
|
||||
* 10/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version. Written, and finished.
|
||||
*
|
||||
* Makes cmaster join a registered channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: JOINCommand.cc,v 1.15 2008/04/16 20:34:39 danielaustin Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char JOINCommand_cc_rcsId[] = "$Id: JOINCommand.cc,v 1.15 2008/04/16 20:34:39 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool JOINCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.JOIN");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::join)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot isn't in the channel. */
|
||||
if (theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::already_on_chan, "I'm already in that channel!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_JOIN, "");
|
||||
|
||||
theChan->setInChan(true);
|
||||
/* force setting mode +R - it is probably set already, but doesn't hurt to check */
|
||||
bot->Join(theChan->getName(),
|
||||
"+R",
|
||||
theChan->getChannelTS(),
|
||||
true);
|
||||
bot->joinCount++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* KICKCommand.cc
|
||||
*
|
||||
* 30/12/2000 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version.
|
||||
*
|
||||
* KICK one or more users from a channel, with access checking.
|
||||
*
|
||||
* 2001-03-16: Perry Lorier <isomer@coders.net>
|
||||
* doesn't kick the initiator in a masskick
|
||||
*
|
||||
* Suggestion: Support several nicks by seperating them with a comma.
|
||||
* IE: /msg E kick #coder-com nick1,nick2,nick3 get outta
|
||||
* here!
|
||||
* 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.
|
||||
*
|
||||
* $Id: KICKCommand.cc,v 1.11 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "match.h"
|
||||
|
||||
const char KICKCommand_cc_rcsId[] = "$Id: KICKCommand.cc,v 1.11 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using namespace gnuworld;
|
||||
using namespace level;
|
||||
|
||||
bool KICKCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.KICK");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) return false;
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan) {
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan()) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::kick)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool flagNoTake = false;
|
||||
#ifdef USE_NOTAKE
|
||||
if (theChan->getFlag(sqlChannel::F_NOTAKE))
|
||||
flagNoTake = true;
|
||||
#endif
|
||||
|
||||
// *** Take Over Protection ***
|
||||
if (level < 500)
|
||||
if (!matchall(st[2]) && validUserMask(st[2]) && (flagNoTake))
|
||||
{
|
||||
//Revenge is Ignore
|
||||
if (theChan->getNoTake() == 1) return true;
|
||||
unsigned short banLevel = (unsigned short)level::set::notake;
|
||||
unsigned int banExpire = 100 * 86400;
|
||||
string banReason = "### Take Over Triggered ###";
|
||||
string suspendReason = "\002*** TAKE OVER ATTEMPT ***\002";
|
||||
if (theChan->getNoTake() > 1)
|
||||
bot->doInternalBanAndKick(theChan, theClient, banLevel, banExpire, banReason);
|
||||
if (theChan->getNoTake() > 2)
|
||||
bot->doInternalSuspend(theChan, theClient, banLevel, banExpire, suspendReason);
|
||||
return true;
|
||||
}
|
||||
// *** End of Take Over Protection part ****
|
||||
|
||||
/*
|
||||
* Wildcard or normal kick?
|
||||
*/
|
||||
vector <iClient*> toBoot;
|
||||
|
||||
if((bot->validUserMask(st[2])) && (level >= level::masskick))
|
||||
{
|
||||
/* Loop over all channel members, and match who to kick. */
|
||||
|
||||
for(Channel::userIterator chanUsers = tmpChan->userList_begin(); chanUsers != tmpChan->userList_end(); ++chanUsers)
|
||||
{
|
||||
ChannelUser* tmpUser = chanUsers->second;
|
||||
|
||||
if( (match(st[2], tmpUser->getClient()->getNickUserHost()) == 0) ||
|
||||
(match(st[2], tmpUser->getClient()->getRealNickUserHost()) == 0) )
|
||||
{
|
||||
/* Don't kick +k things */
|
||||
if ( !tmpUser->getClient()->getMode(iClient::MODE_SERVICES) && tmpUser->getClient() != theClient )
|
||||
{
|
||||
toBoot.push_back(tmpUser->getClient());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* Do a lookup on nickname, and check they are in the channel.
|
||||
*/
|
||||
|
||||
iClient* target = Network->findNick(st[2]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::dont_see_them).c_str(),
|
||||
st[2].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check they are on the channel.
|
||||
*/
|
||||
|
||||
ChannelUser* tmpChanUser = tmpChan->findUser(target) ;
|
||||
if (!tmpChanUser)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Don't kick +k things */
|
||||
if ( target->getMode(iClient::MODE_SERVICES) )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::wouldnt_appreciate,
|
||||
string("I don't think %s would appreciate that.")).c_str(),
|
||||
target->getNickName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
toBoot.push_back(target);
|
||||
}
|
||||
|
||||
if (toBoot.size() == 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::no_match,
|
||||
string("No Match!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
string args;
|
||||
if (st.size() >= 4)
|
||||
{
|
||||
args = st.assemble(3);
|
||||
} else
|
||||
{
|
||||
args = "No reason supplied";
|
||||
}
|
||||
|
||||
string reason = "(" + theUser->getUserName() + ") ";
|
||||
reason += args;
|
||||
|
||||
bot->Kick(tmpChan, toBoot, reason);
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* LBANLISTCommand.cc
|
||||
*
|
||||
* 13/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Lists internal bot banlist for a channel.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: LBANLISTCommand.cc,v 1.15 2007/08/07 21:22:29 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "cservice_config.h"
|
||||
#include "time.h"
|
||||
#include "banMatcher.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool LBANLISTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.LBANLIST");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is the channel registered?
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
return false;
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Show all results? */
|
||||
bool showAll = false;
|
||||
|
||||
for( StringTokenizer::const_iterator ptr = st.begin() ; ptr != st.end() ;
|
||||
++ptr )
|
||||
{
|
||||
if (string_lower(*ptr) == "-all")
|
||||
{
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient, false);
|
||||
if ( tmpUser && bot->getAdminAccessLevel(tmpUser) )
|
||||
{
|
||||
showAll = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::lbanlist_for,
|
||||
string("\002*** Ban List for channel %s ***\002")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
size_t results = 0;
|
||||
time_t ban_expires = 0;
|
||||
time_t ban_expires_d = 0;
|
||||
time_t ban_expires_f = 0;
|
||||
|
||||
for( std::map< int,sqlBan* >::const_iterator ptr = theChan->banList.begin() ; ptr != theChan->banList.end() ; ++ptr )
|
||||
{
|
||||
const sqlBan* theBan = ptr->second;
|
||||
ban_expires = theBan->getExpires();
|
||||
/* If its expired.. just don't show it - it'll be removed soon ;) */
|
||||
if ((ban_expires >= bot->currentTime()) || (ban_expires == 0))
|
||||
{
|
||||
// if (!match(fixAddress(st[2]), theBan->getBanMask()))
|
||||
if (match(st[2], theBan->getBanMask()) == 0)
|
||||
{
|
||||
results++;
|
||||
/* escape the loop if we exceed our ban limit */
|
||||
if ((results > MAX_LBAN_RESULTS) && !showAll)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (ban_expires > 0)
|
||||
{
|
||||
ban_expires_d = ban_expires - bot->currentTime();
|
||||
ban_expires_f = bot->currentTime() - ban_expires_d;
|
||||
}
|
||||
else
|
||||
ban_expires_f = 0;
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::lban_entry,
|
||||
string("%s %s Level: %i")).c_str(),
|
||||
theChan->getName().c_str(),
|
||||
theBan->getBanMask().c_str(),
|
||||
theBan->getLevel());
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::lban_added_by,
|
||||
string("ADDED BY: %s (%s)")).c_str(),
|
||||
theBan->getSetBy().c_str(),
|
||||
theBan->getReason().c_str());
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::lban_since,
|
||||
string("SINCE: %s")).c_str(),
|
||||
ctime(&theBan->getSetTS()));
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::lban_exp,
|
||||
string("EXP: %s")).c_str(),
|
||||
prettyDuration(ban_expires_f).c_str());
|
||||
}
|
||||
}
|
||||
} // for()
|
||||
|
||||
/* if there are more results than we are configured to show,
|
||||
tell the user (in their preferred language */
|
||||
if( (results > MAX_LBAN_RESULTS) && !showAll)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::more_than_max,
|
||||
string("There are more than %d matching entries.")).c_str(),
|
||||
MAX_LBAN_RESULTS);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::restrict_query,
|
||||
string("Please restrict your query.")));
|
||||
}
|
||||
else if (results > 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::lban_end,
|
||||
string("\002*** END ***\002")));
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::no_match,
|
||||
string("No match!")));
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,865 @@
|
||||
/**
|
||||
* LOGINCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: LOGINCommand.cc,v 1.67 2009/06/09 15:40:29 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "md5hash.h"
|
||||
#include "responses.h"
|
||||
#include "levels.h"
|
||||
#include "networkData.h"
|
||||
#include "cservice_config.h"
|
||||
#include "Network.h"
|
||||
#include "ip.h"
|
||||
#include "sqlIncompleteChannel.h"
|
||||
|
||||
const char LOGINCommand_cc_rcsId[] = "$Id: LOGINCommand.cc,v 1.67 2009/06/09 15:40:29 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
struct autoOpData {
|
||||
unsigned int channel_id;
|
||||
unsigned int flags;
|
||||
time_t suspend_expires;
|
||||
} aOp;
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
using namespace gnuworld;
|
||||
|
||||
bool LOGINCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.LOGIN");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Are we allowing logins yet?
|
||||
*/
|
||||
unsigned int useLoginDelay = bot->getConfigVar("USE_LOGIN_DELAY")->asInt();
|
||||
unsigned int loginTime = bot->getUplink()->getStartTime() + bot->loginDelay;
|
||||
if ( (useLoginDelay == 1) && (loginTime >= (unsigned int)bot->currentTime()) )
|
||||
{
|
||||
bot->Notice(theClient, "AUTHENTICATION FAILED as %s. (Unable "
|
||||
"to login during reconnection, please try again in "
|
||||
"%i seconds)",
|
||||
st[1].c_str(), (loginTime - bot->currentTime()));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check theClient isn't already logged in, if so, tell
|
||||
* them they shouldn't be.
|
||||
*/
|
||||
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient, false);
|
||||
if (tmpUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser, language::already_authed).c_str(),
|
||||
tmpUser->getUserName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if this client has exceeded their max logins
|
||||
*/
|
||||
|
||||
unsigned int maxFailedLogins = bot->getConfigVar("MAX_FAILED_LOGINS")->asInt();
|
||||
unsigned int failedLogins = bot->getFailedLogins(theClient);
|
||||
if ((maxFailedLogins > 0) && (failedLogins >= maxFailedLogins))
|
||||
{
|
||||
/* exceeded maximum failed logins */
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::max_failed_logins,
|
||||
string("AUTHENTICATION FAILED as %s (Exceeded maximum login failures for this session)")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the user record, confirm authorisation and attach the record
|
||||
* to this client.
|
||||
*/
|
||||
|
||||
if(st[1][0] == '#')
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient, "AUTHENTICATION FAILED as %s.", st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Force a refresh of the user's info from the db
|
||||
sqlUser* theUser = bot->getUserRecord(st[1]);
|
||||
if( !theUser )
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::not_registered,
|
||||
string("AUTHENTICATION FAILED as %s.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((theUser->getFlag(sqlUser::F_GLOBAL_SUSPEND)) && (!theUser->getFlag(sqlUser::F_POWER)))
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient, "AUTHENTICATION FAILED as %s. (Suspended)",
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
int pass_end = st.size();
|
||||
|
||||
#ifdef TOTP_AUTH_ENABLED
|
||||
bool totp_enabled = false;
|
||||
if(bot->totpAuthEnabled && theUser->getFlag(sqlUser::F_TOTP_ENABLED)) {
|
||||
if(st.size() < 4) {
|
||||
bot->Notice(theClient,"AUTHENTICATION FAILED as %s. (Missing TOTP token)",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
pass_end = st.size()-1;
|
||||
totp_enabled = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check password, if its wrong, bye bye.
|
||||
*/
|
||||
|
||||
unsigned int max_failed_logins = bot->getConfigVar("FAILED_LOGINS")->asInt();
|
||||
unsigned int failed_login_rate = bot->getConfigVar("FAILED_LOGINS_RATE")->asInt();
|
||||
|
||||
/* if it's not configured, default to every 15 minutes */
|
||||
if (failed_login_rate==0)
|
||||
failed_login_rate = 900;
|
||||
if ((!bot->isPasswordRight(theUser, st.assemble(2,pass_end)))
|
||||
&& (theUser->getRecoveryPassword() != st.assemble(2,pass_end)))
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::auth_failed,
|
||||
string("AUTHENTICATION FAILED as %s.")).c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
/* increment failed logins counter */
|
||||
theUser->incFailedLogins();
|
||||
if ((max_failed_logins > 0) && (theUser->getFailedLogins() > max_failed_logins) &&
|
||||
(theUser->getLastFailedLoginTS() < (time(NULL) - failed_login_rate)))
|
||||
{
|
||||
/* we have exceeded our maximum - alert relay channel */
|
||||
/* work out a checksum for the password. Yes, I could have
|
||||
* just used a checksum of the original password, but this
|
||||
* means it's harder to 'fool' the check digit with a real
|
||||
* password - create MD5 from original salt stored */
|
||||
unsigned char checksum;
|
||||
md5 hash;
|
||||
md5Digest digest;
|
||||
|
||||
if (theUser->getPassword().size() < 9)
|
||||
{
|
||||
checksum = 0;
|
||||
} else {
|
||||
string salt = theUser->getPassword().substr(0, 8);
|
||||
string guess = salt + st.assemble(2);
|
||||
|
||||
hash.update( (const unsigned char *)guess.c_str(), guess.size() );
|
||||
hash.report( digest );
|
||||
|
||||
checksum = 0;
|
||||
for (size_t i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||
{
|
||||
/* add ascii value to check digit */
|
||||
checksum += digest[i];
|
||||
}
|
||||
}
|
||||
|
||||
theUser->setLastFailedLoginTS(time(NULL));
|
||||
bot->logPrivAdminMessage("%d failed logins for %s (last attempt by %s, checksum %d).",
|
||||
theUser->getFailedLogins(),
|
||||
theUser->getUserName().c_str(),
|
||||
theClient->getRealNickUserHost().c_str(),
|
||||
checksum);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef TOTP_AUTH_ENABLED
|
||||
if (totp_enabled)
|
||||
{
|
||||
OathResult::OATH_RESULT_TYPE response = theUser->validateTOTP(st[st.size()-1].c_str());
|
||||
if (response != OathResult::OK)
|
||||
{
|
||||
if (response == OathResult::ERROR)
|
||||
{
|
||||
bot->Notice(theClient, "AUTHENTICATION FAILED as %s due to an error, please contact a CService representative", st[1].c_str());
|
||||
}
|
||||
if (response == OathResult::INVALID_TOKEN)
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::auth_failed_token,
|
||||
string("AUTHENTICATION FAILED as %s. (Invalid Token)")).c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
/* increment failed logins counter */
|
||||
theUser->incFailedLogins();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check if this is a privileged user, if so check against IP restrictions
|
||||
*/
|
||||
if ((bot->getAdminAccessLevel(theUser, true) > 0) && (!theUser->getFlag(sqlUser::F_ALUMNI)))
|
||||
{
|
||||
/* ok, they have "*" access (excluding alumni's) */
|
||||
if (!bot->checkIPR(theClient, theUser))
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient, "AUTHENTICATION FAILED as %s. (IPR)",
|
||||
st[1].c_str());
|
||||
/* notify the relay channel */
|
||||
bot->logAdminMessage("%s (%s) failed IPR check.",
|
||||
theClient->getNickName().c_str(),
|
||||
st[1].c_str());
|
||||
/* increment failed logins counter */
|
||||
theUser->incFailedLogins();
|
||||
if ((max_failed_logins > 0) && (theUser->getFailedLogins() > max_failed_logins) &&
|
||||
(theUser->getLastFailedLoginTS() < (time(NULL) - failed_login_rate)))
|
||||
{
|
||||
/* we have exceeded our maximum - alert relay channel */
|
||||
theUser->setLastFailedLoginTS(time(NULL));
|
||||
bot->logPrivAdminMessage("%d failed logins for %s (last attempt by %s).",
|
||||
theUser->getFailedLogins(),
|
||||
theUser->getUserName().c_str(),
|
||||
theClient->getRealNickUserHost().c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't exceed MAXLOGINS.
|
||||
*/
|
||||
|
||||
bool iploginallow = false;
|
||||
if(theUser->networkClientList.size() + 1 > theUser->getMaxLogins())
|
||||
{
|
||||
/* They have exceeded their maxlogins setting, but check if they
|
||||
are allowed to login from the same IP - only applies if their
|
||||
maxlogins is set to ONE */
|
||||
uint32_t iplogins = bot->getConfigVar("LOGINS_FROM_SAME_IP")->asInt();
|
||||
uint32_t iploginident = bot->getConfigVar("LOGINS_FROM_SAME_IP_AND_IDENT")->asInt();
|
||||
if ((theUser->getMaxLogins() == 1) && (iplogins > 1))
|
||||
{
|
||||
/* ok, we're using the multi-logins feature (0=disabled) */
|
||||
if (theUser->networkClientList.size() + 1 <= iplogins)
|
||||
{
|
||||
/* Check their IP from previous session against
|
||||
current IP. If it matches, allow the login.
|
||||
As this only applies if their maxlogin is 1, we
|
||||
know there is only 1 entry in their clientlist */
|
||||
if (theClient->getIP() == theUser->networkClientList.front()->getIP())
|
||||
{
|
||||
if (iploginident==1)
|
||||
{
|
||||
/* need to check ident here */
|
||||
string oldident = theUser->networkClientList.front()->getUserName();
|
||||
string newident = theClient->getUserName();
|
||||
if ((oldident[0]=='~') || (oldident==newident))
|
||||
{
|
||||
/* idents match (or they are unidented) - allow this login */
|
||||
iploginallow = true;
|
||||
}
|
||||
} else {
|
||||
/* don't need to check ident, this login is allowed */
|
||||
iploginallow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!iploginallow)
|
||||
{
|
||||
bot->setFailedLogins(theClient, failedLogins+1);
|
||||
bot->Notice(theClient, "AUTHENTICATION FAILED as %s. (Maximum "
|
||||
"concurrent logins exceeded).",
|
||||
theUser->getUserName().c_str());
|
||||
|
||||
string clientList;
|
||||
for( sqlUser::networkClientListType::iterator ptr = theUser->networkClientList.begin() ;
|
||||
ptr != theUser->networkClientList.end() ; )
|
||||
{
|
||||
clientList += (*ptr)->getNickUserHost();
|
||||
++ptr;
|
||||
if (ptr != theUser->networkClientList.end())
|
||||
{
|
||||
clientList += ", ";
|
||||
}
|
||||
} // for()
|
||||
|
||||
bot->Notice(theClient, "Current Sessions: %s", clientList.c_str());
|
||||
return false;
|
||||
} // for()
|
||||
}
|
||||
|
||||
/*
|
||||
* If this user account is already authed against, send a notice to the other
|
||||
* users warning them that someone else has logged in too.
|
||||
*/
|
||||
if(theUser->isAuthed())
|
||||
{
|
||||
bot->noticeAllAuthedClients(theUser,
|
||||
"%s has just authenticated as you (%s). "
|
||||
"If this is not you, your account may have been compromised. "
|
||||
"If you wish to suspend all your access as a precautionary measure, "
|
||||
"type '\002/msg %s@%s suspendme <password>'\002 and contact a "
|
||||
"CService representative to resolve the problem."
|
||||
" \002** Note: You will NOT be able to use your account after "
|
||||
"you issue this command **\002",
|
||||
theClient->getNickUserHost().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
bot->getNickName().c_str(),
|
||||
bot-> getUplinkName().c_str());
|
||||
}
|
||||
|
||||
/* check to see if we have a last seen time (bug workaround) - if not, make one */
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "SELECT last_seen FROM users_lastseen WHERE user_id="
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::sqlQuery> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( bot->SQLDb->Exec(queryString, true ) )
|
||||
//if (PGRES_TUPLES_OK == status)
|
||||
{
|
||||
if (bot->SQLDb->Tuples() < 1)
|
||||
{
|
||||
/* no rows returned - create a dummy record that will be updated
|
||||
* by setLastSeen after this loop
|
||||
*/
|
||||
stringstream updateQuery;
|
||||
updateQuery << "INSERT INTO users_lastseen (user_id,"
|
||||
<< "last_seen,last_updated) VALUES("
|
||||
<< theUser->getID()
|
||||
<< ",date_part('epoch', CURRENT_TIMESTAMP)::int,date_part('epoch', CURRENT_TIMESTAMP)::int)"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::sqlQuery> "
|
||||
<< updateQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
bot->SQLDb->Exec(updateQuery);
|
||||
}
|
||||
}
|
||||
/* update their details */
|
||||
theUser->setLastSeen(bot->currentTime(), theClient->getNickUserHost(),
|
||||
theClient->getNickName() + "!" + theClient->getUserName() + "@" + xIP( theClient->getIP()).GetNumericIP());
|
||||
theUser->setFlag(sqlUser::F_LOGGEDIN);
|
||||
theUser->addAuthedClient(theClient);
|
||||
|
||||
networkData* newData =
|
||||
static_cast< networkData* >( theClient->getCustomData(bot) ) ;
|
||||
if( NULL == newData )
|
||||
{
|
||||
bot->Notice( theClient,
|
||||
"Internal error." ) ;
|
||||
elog << "LOGINCommand> newData is NULL for: "
|
||||
<< theClient
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// Pointer back to the sqlUser from this iClient.
|
||||
newData->currentUser = theUser;
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::auth_success).c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
|
||||
/* set failed logins counter back to zero after alerting the user (if required) */
|
||||
if (bot->getConfigVar("ALERT_FAILED_LOGINS")->asInt()==1 &&
|
||||
theUser->getFailedLogins() > 0)
|
||||
{
|
||||
/* ok, alert the user */
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::auth_failed_logins,
|
||||
string("There were %d failed login attempts since your last successful login.")).c_str(),
|
||||
theUser->getFailedLogins());
|
||||
}
|
||||
theUser->setFailedLogins(0);
|
||||
theUser->setLastFailedLoginTS(0);
|
||||
|
||||
int tmpLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (tmpLevel > 0)
|
||||
{
|
||||
/* this is a privileged user, send a notice to _info */
|
||||
if (tmpLevel < 900)
|
||||
{
|
||||
/* regular admin, report to normal relay channel */
|
||||
bot->logAdminMessage("%s (%s) has authenticated (level %d)",
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
tmpLevel);
|
||||
} else {
|
||||
/* if this is a high level admin, report to privileged relay channel */
|
||||
bot->logPrivAdminMessage("%s (%s) has authenticated (level %d)",
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
tmpLevel);
|
||||
}
|
||||
} else {
|
||||
string greeting = bot->getResponse(theUser, language::greeting);
|
||||
if (!greeting.empty())
|
||||
{
|
||||
bot->Notice(theClient, greeting.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send out AC token onto the network.
|
||||
* The AC Token (Account) is read by ircu2.10.11 and any other
|
||||
* service on the net that cares and added to the Client structure.
|
||||
* Format:
|
||||
* [Source Server] AC [Authenticated User's Numeric] [Authenticated UserName]
|
||||
* Eg: AX AC APAFD gte
|
||||
*/
|
||||
server->UserLogin(theClient, theUser->getUserName(), bot);
|
||||
if (!theUser->getHostName().empty())
|
||||
server->SendOutFakeHost(theClient, theUser->getHostName().c_str(), bot);
|
||||
|
||||
/*
|
||||
* If the user account has been suspended, make sure they don't get
|
||||
* auto-opped.
|
||||
*/
|
||||
|
||||
if (theUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"..however your account has been suspended by a CService administrator."
|
||||
" You will be unable to use any channel access you may have.");
|
||||
return true;
|
||||
}
|
||||
|
||||
cservice::incompleteChanRegsType::const_iterator theApp = bot->incompleteChanRegs.find(theUser->getID());
|
||||
if (theApp != bot->incompleteChanRegs.end())
|
||||
{
|
||||
sqlIncompleteChannel *chanApp = theApp->second;
|
||||
string chanName = bot->getPendingChanName(chanApp->chanId);
|
||||
bot->Notice(theClient, "You have an incomplete channel application of %s", chanName.c_str());
|
||||
if (!chanApp->RealName.empty())
|
||||
{
|
||||
bot->Notice(theClient, "So far you've enumerated the following:");
|
||||
bot->Notice(theClient, "Your Real Name: %s", chanApp->RealName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your Real Name by typing /msg %s REGISTER %s REALNAME <Your RealName>", bot->getNickName().c_str(), chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(), chanName.c_str());
|
||||
}
|
||||
if ((!chanApp->RealName.empty()) && (chanApp->Description.empty()))
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your channel's description by typing /msg %s REGISTER %s DESCRIPTION <description>", bot->getNickName().c_str(),chanName.c_str());
|
||||
if (chanApp->supps.empty())
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),chanName.c_str());
|
||||
}
|
||||
if (!chanApp->Description.empty()) bot->Notice(theClient, "Description: %s", chanApp->Description.c_str());
|
||||
if ((!chanApp->RealName.empty()) && (!chanApp->Description.empty()))
|
||||
{
|
||||
bot->Notice(theClient,"Now enumerate your supporters by typing /msg %s REGISTER %s SUPPORTERS <supporter1 supporter2 supporter3 ...>", bot->getNickName().c_str(),chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),chanName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The fun part! For all channels this user has access on, and has
|
||||
* AUTOP set, and isn't already op'd on - do the deed.
|
||||
*/
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << "SELECT channel_id,flags,suspend_expires FROM "
|
||||
<< "levels WHERE user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "LOGIN> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
typedef vector < autoOpData > autoOpVectorType;
|
||||
autoOpVectorType autoOpVector;
|
||||
|
||||
for(unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
autoOpData current;
|
||||
|
||||
current.channel_id = atoi(bot->SQLDb->GetValue(i, 0));
|
||||
current.flags = atoi(bot->SQLDb->GetValue(i, 1));
|
||||
current.suspend_expires = atoi(bot->SQLDb->GetValue(i, 2));
|
||||
|
||||
autoOpVector.push_back( autoOpVectorType::value_type(current) );
|
||||
}
|
||||
|
||||
for (autoOpVectorType::const_iterator resultPtr = autoOpVector.begin();
|
||||
resultPtr != autoOpVector.end(); ++resultPtr)
|
||||
{
|
||||
|
||||
/* If the autoop flag isn't set in this record */
|
||||
if (!(resultPtr->flags & sqlLevel::F_AUTOOP) &&
|
||||
!(resultPtr->flags & sqlLevel::F_AUTOHALFOP) &&
|
||||
!(resultPtr->flags & sqlLevel::F_AUTOVOICE) &&
|
||||
!(resultPtr->flags & sqlLevel::F_AUTOINVITE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(resultPtr->channel_id);
|
||||
if (!theChan)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure the channel isn't suspended..
|
||||
*/
|
||||
|
||||
if (theChan->getFlag(sqlChannel::F_SUSPEND))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check if they're already opped.
|
||||
*/
|
||||
|
||||
Channel* netChan = Network->findChannel(theChan->getName());
|
||||
if (!netChan)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Don't attempt to op/invite if we're not in the channel, or not op'd.
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = netChan->findUser(bot->getInstance());
|
||||
if (!tmpBotUser)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!theChan->getInChan() || !tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Would probably be wise to check they're not suspended too :)
|
||||
* (*smack* Ace)
|
||||
*/
|
||||
|
||||
if(resultPtr->suspend_expires > bot->currentTime() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser = netChan->findUser(theClient) ;
|
||||
if(!tmpChanUser) {
|
||||
//The user is not in the channel, lets see if their autoinvite is on and act upon it
|
||||
if (resultPtr->flags & sqlLevel::F_AUTOINVITE) {
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if(level >= level::invite) {
|
||||
sqlBan* tmpBan = bot->isBannedOnChan(theChan, theClient);
|
||||
if (tmpBan && tmpBan->getLevel() >= 75) {
|
||||
bot->Notice(theClient, "Can't invite you to channel %s, you are banned", theChan->getName().c_str());
|
||||
continue;
|
||||
}
|
||||
bot->Invite(theClient,netChan);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the channel is NOOP.
|
||||
* N.B: If the channel is strictop, we op them.
|
||||
* They've just logged in! :P
|
||||
*/
|
||||
|
||||
if(theChan->getFlag(sqlChannel::F_NOOP))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check they aren't banned < 75 in the chan.
|
||||
*/
|
||||
|
||||
sqlBan* tmpBan = bot->isBannedOnChan(theChan, theClient);
|
||||
if( tmpBan) {
|
||||
if (tmpBan->getLevel() < 75) {
|
||||
continue;
|
||||
} else {
|
||||
bot->Kick(netChan,theClient,tmpBan->getReason());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If its AUTOOP, check for op's and do the deed.
|
||||
* Otherwise, its just AUTOVOICE :)
|
||||
*/
|
||||
|
||||
if (resultPtr->flags & sqlLevel::F_AUTOOP)
|
||||
{
|
||||
if(!tmpChanUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Op(netChan, theClient);
|
||||
}
|
||||
}
|
||||
else if (resultPtr->flags & sqlLevel::F_AUTOHALFOP)
|
||||
{
|
||||
if(!tmpChanUser->getMode(ChannelUser::MODE_H))
|
||||
{
|
||||
bot->HalfOp(netChan, theClient);
|
||||
}
|
||||
}
|
||||
else if ((resultPtr->flags & sqlLevel::F_AUTOVOICE) && (!theChan->getFlag(sqlChannel::F_NOVOICE)))
|
||||
{
|
||||
if(!tmpChanUser->getMode(ChannelUser::MODE_V))
|
||||
{
|
||||
bot->Voice(netChan, theClient);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* And last but by no means least, see if we have been nominated as
|
||||
* a supporter for a channel.
|
||||
*/
|
||||
|
||||
stringstream supporterQuery;
|
||||
supporterQuery << "SELECT channels.name FROM"
|
||||
<< " supporters,channels,pending WHERE"
|
||||
<< " supporters.channel_id = channels.id"
|
||||
<< " AND pending.channel_id = channels.id"
|
||||
<< " AND channels.registered_ts = 0"
|
||||
<< " AND supporters.support = '?'"
|
||||
<< " AND pending.status = 0"
|
||||
<< " AND user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::sqlQuery> "
|
||||
<< supporterQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(supporterQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "LOGIN> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
string channelName = bot->SQLDb->GetValue(i, 0);
|
||||
bot->Notice(theClient, "You have been named as a supporter in a "
|
||||
"new channel application for %s. You may visit the "
|
||||
"website to register your support or to make an "
|
||||
"objection. Alternatively, you can"
|
||||
" type '\002/msg %s support %s YES\002' or '\002/msg %s "
|
||||
"support %s NO\002' to confirm or deny your support.",
|
||||
channelName.c_str(),
|
||||
bot->getNickName().c_str(),
|
||||
channelName.c_str(),
|
||||
bot->getNickName().c_str(),
|
||||
channelName.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for modinfo notices.
|
||||
*/
|
||||
#ifdef USE_NOTICES
|
||||
stringstream noticeQuery;
|
||||
noticeQuery << "SELECT message FROM notices "
|
||||
<< "WHERE user_id = "
|
||||
<< theUser->getID()
|
||||
<< " ORDER BY last_updated ASC"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::sqlQuery> "
|
||||
<< noticeQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if (!bot->SQLDb->Exec(noticeQuery, true))
|
||||
{
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGINNoteAllAuthedClients::commit> Something went wrong: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
#endif
|
||||
bot->logDebugMessage("LOGINNoteAllAuthedClients",bot->SQLDb->ErrorMessage().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int count = bot->SQLDb->Tuples();
|
||||
if(count)
|
||||
for (unsigned int i=0; i<count; i++)
|
||||
bot->Notice(theClient,bot->SQLDb->GetValue(i,0).c_str());
|
||||
|
||||
/* Delete automatically the notices */
|
||||
|
||||
noticeQuery.str("");
|
||||
noticeQuery << "DELETE FROM notices WHERE user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
if (!bot->SQLDb->Exec(noticeQuery, true))
|
||||
{
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::deleteNotices::sqlQuery> "
|
||||
<< noticeQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
bot->logDebugMessage("LOGIN-DeleteNoteAllAuthedClients",bot->SQLDb->ErrorMessage().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* See if they have any notes, but first check if Notes are enabled.
|
||||
*/
|
||||
|
||||
#ifdef USE_NOTES
|
||||
#ifndef USE_USERS_NOTES
|
||||
if (theUser->getAdminAccessLevel() == 0)
|
||||
return true;
|
||||
#endif
|
||||
if(!theUser->getFlag(sqlUser::F_NONOTES))
|
||||
{
|
||||
stringstream noteQuery;
|
||||
noteQuery.str("");
|
||||
noteQuery << "SELECT message_id FROM notes "
|
||||
<< "WHERE user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "LOGIN::sqlQuery> "
|
||||
<< noteQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->SQLDb->Exec(noteQuery, true) ;
|
||||
|
||||
count = bot->SQLDb->Tuples();
|
||||
if(count)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::have_notes,string("You have %i note(s). To read them type /msg %s notes read all")).c_str(), count, bot->getNickName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (theUser->getFlag(sqlUser::F_AUTONICK))
|
||||
{
|
||||
iClient* tmpClient = Network->findNick(theUser->getNickName());
|
||||
if (tmpClient)
|
||||
{
|
||||
if (!tmpClient->getMode(iClient::MODE_SERVICES))
|
||||
{
|
||||
sqlUser* tmpUser2 = bot->isAuthed(tmpClient, false);
|
||||
if (!tmpUser2)
|
||||
{
|
||||
bot->generateNickName(tmpClient);
|
||||
}
|
||||
else if (tmpUser2->getUserName() != theUser->getUserName())
|
||||
{
|
||||
bot->generateNickName(tmpClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bot->Write("%s SN %s %s", bot->getCharYY().c_str(), theClient->getCharYYXXX().c_str(), theUser->getNickName().c_str());
|
||||
}
|
||||
|
||||
// If we have a login with recovery password, replace the actual password with the recovery password
|
||||
if (theUser->getRecoveryPassword() == st.assemble(2, pass_end))
|
||||
{
|
||||
string cryptpass = bot->CryptPass(theUser->getRecoveryPassword().c_str());
|
||||
theUser->setPassword(cryptpass.c_str());
|
||||
theUser->setRecoveryPassword(string());
|
||||
theUser->commit(theClient);
|
||||
}
|
||||
|
||||
// If successful login reached, the recovery password has to be cleared all the time
|
||||
theUser->setRecoveryPassword(string());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,493 @@
|
||||
/**
|
||||
* MODINFOCommand.cc
|
||||
*
|
||||
* 27/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Modifies a user's 'Level' record in a particular channel.
|
||||
*
|
||||
* Caveats:
|
||||
* 1. In the rare case of somebody attempting to MODINFO a forced access
|
||||
* that doesn't exist in the database, then the commit() will fail.
|
||||
* This is fine, as the modified record doesn't really exist anyway.
|
||||
* Shouldn't really happen, as trying to MODINFO a forced access doesn't
|
||||
* make sense - adduser and then MODINFO that :)
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: MODINFOCommand.cc,v 1.24 2010/04/10 19:49:57 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char MODINFOCommand_cc_rcsId[] = "$Id: MODINFOCommand.cc,v 1.24 2010/04/10 19:49:57 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool MODINFOCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.MODINFO");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 4 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
string command = string_upper(st[1]) == "TOTP" ? "TOTP" : string_upper(st[2]);
|
||||
if ((command != "ACCESS") && (command != "AUTOMODE") && (command != "INVITE") && (command != "TOTP"))
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(command != "INVITE" && command != "TOTP" && st.size() < 5 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (command == "TOTP") {
|
||||
if(bot->getAdminAccessLevel(theUser) < adminlevel::modinfo) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
sqlUser* modUser = bot->getUserRecord(st[1]);
|
||||
if(!modUser) {
|
||||
bot->Notice(theClient,"I can't find %s anywhere",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
if(theUser == modUser) {
|
||||
bot->Notice(theClient,"Sorry, you can not disable your own TOTP setting");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(string_upper(st[3]) == "OFF") {
|
||||
if(modUser->getFlag(sqlUser::F_TOTP_ENABLED)) {
|
||||
modUser->removeFlag(sqlUser::F_TOTP_ENABLED);
|
||||
if(!modUser->commit(theClient)) {
|
||||
bot->Notice(theClient,"Failed to disable totp for %s",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient,"TOTP Authentication disabled for %s",st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
bot->Notice(theClient,"TOTP Authentication already disabled for %s",st[1].c_str());
|
||||
return false;
|
||||
} else if(string_upper(st[3]) == "ON") {
|
||||
bot->Notice(theClient,"Cannot enable TOTP for other users");
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient,"Unknown option %s , valid option is OFF",st[3].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(st.size() < 4) {
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, check the channel is registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int required_level = (st[1] == "*") ? adminlevel::modinfo : level::modinfo;
|
||||
if (command == "INVITE")
|
||||
{
|
||||
required_level = level::modinfo_autoinvite;
|
||||
}
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < required_level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(command == "INVITE")
|
||||
{ //Handle modinfo INVITE
|
||||
if (bot->getAccessLevel(theUser,theChan) == 0)
|
||||
{
|
||||
/* forced users cant set their invite status on, as they have no level record for the channel */
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
if(st[1] == "*")
|
||||
{ //Admin channel?
|
||||
bot->Notice(theClient,"It is a mistake to think you can solve any major problems just with potatoes.");
|
||||
return false;
|
||||
}
|
||||
if(string_upper(st[3]) == "ON")
|
||||
{ //Time to enable INVITE option
|
||||
sqlLevel* aLevel = bot->getLevelRecord(theUser, theChan);
|
||||
aLevel->setFlag(sqlLevel::F_AUTOINVITE);
|
||||
aLevel->commit();
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::automode_invite,
|
||||
string("Set INVITE on login %s for channel %s")).c_str(),
|
||||
"ON", theChan->getName().c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
else if(string_upper(st[3]) == "OFF")
|
||||
{
|
||||
sqlLevel* aLevel = bot->getLevelRecord(theUser, theChan);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOINVITE);
|
||||
aLevel->commit();
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::automode_invite,
|
||||
string("Set INVITE on login %s for channel %s")).c_str(),
|
||||
"OFF",theChan->getName().c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
Usage(theClient);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the person we're trying to change actually exists.
|
||||
*/
|
||||
|
||||
sqlUser* targetUser = bot->getUserRecord(st[3]);
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered,
|
||||
string("Sorry, I don't know who %s is.")).c_str(), st[3].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check this user really does have access on this channel.
|
||||
*/
|
||||
|
||||
int targetLevel = bot->getAccessLevel(targetUser, theChan);
|
||||
if (targetLevel == 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::doesnt_have_access,
|
||||
string("%s doesn't appear to have access in %s.")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Figure out what they're doing - ACCESS or AUTOOP.
|
||||
*/
|
||||
|
||||
if (command == "ACCESS")
|
||||
{
|
||||
/*
|
||||
* Check we aren't trying to change someone with access
|
||||
* higher (or equal) than ours.
|
||||
*/
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level <= targetLevel)
|
||||
{
|
||||
/*
|
||||
* Let forced users modify their own user records in channels to
|
||||
* any setting.
|
||||
*/
|
||||
if (!bot->isForced(theChan, theUser))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::mod_access_higher,
|
||||
string("Cannot modify a user with equal or higher access than your own.")));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we aren't trying to set someone's access higher
|
||||
* than ours.
|
||||
*/
|
||||
int newAccess = atoi(st[4].c_str());
|
||||
|
||||
if (newAccess <= 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_access,
|
||||
string("Invalid access level.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((!theUser->getFlag(sqlUser::F_POWER)) && (newAccess > 999))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_access,
|
||||
string("Invalid access level.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((theUser->getFlag(sqlUser::F_POWER)) && (newAccess > 1000))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_access,
|
||||
string("Invalid access level.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level > 500) && (!theChan->getFlag(sqlChannel::F_SPECIAL)) && (st[1] != "*") && (newAccess > 500))
|
||||
{
|
||||
bot->Notice(theClient, "Access levels on regular channels cannot exceed 500 (except SPECIAL)");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* And finally, check they aren't trying to give someone
|
||||
* higher access than them.
|
||||
*/
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level <= newAccess)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_give_higher,
|
||||
string("Cannot give a user higher or equal access to your own.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlLevel* aLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
aLevel->setAccess(newAccess);
|
||||
aLevel->setLastModif(bot->currentTime());
|
||||
aLevel->setLastModifBy( string( "(" + theUser->getUserName() + ") " +theClient->getNickUserHost() ) );
|
||||
/* When modinfo access, it's proper to forget about unsuspend reason */
|
||||
if ((aLevel->getSuspendExpire() == 0) && (aLevel->getSuspendReason() != ""))
|
||||
aLevel->setSuspendReason(string());
|
||||
if ((aLevel->getFlag(sqlLevel::F_AUTOVOICE)) && (newAccess < level::voice))
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOVOICE);
|
||||
if ((aLevel->getFlag(sqlLevel::F_AUTOHALFOP)) && (newAccess < level::halfop))
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOHALFOP);
|
||||
if ((aLevel->getFlag(sqlLevel::F_AUTOOP)) && (newAccess < level::op))
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOOP);
|
||||
if ((theChan->getUserFlags() == 3) && (newAccess >= level::voice) && (!aLevel->getFlag(sqlLevel::F_AUTOVOICE)))
|
||||
aLevel->setFlag(sqlLevel::F_AUTOVOICE);
|
||||
if ((theChan->getUserFlags() == 2) && (newAccess >= level::halfop) && (!aLevel->getFlag(sqlLevel::F_AUTOHALFOP)))
|
||||
aLevel->setFlag(sqlLevel::F_AUTOHALFOP);
|
||||
if ((theChan->getUserFlags() == 1) && (newAccess >= level::op) && (!aLevel->getFlag(sqlLevel::F_AUTOOP)))
|
||||
aLevel->setFlag(sqlLevel::F_AUTOOP);
|
||||
|
||||
aLevel->commit();
|
||||
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::mod_access_to,
|
||||
string("Modified %s's access level on channel %s to %i")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str(),
|
||||
newAccess);
|
||||
if (targetUser != theUser)
|
||||
bot->NoteAllAuthedClients(targetUser, bot->getResponse(targetUser,language::acc_modif,string("Your access on %s has been modified from %i ti %i")).c_str(), theChan->getName().c_str(), targetLevel, newAccess);
|
||||
} // if( command == "ACCESS" )
|
||||
|
||||
if (command == "AUTOMODE")
|
||||
{
|
||||
|
||||
if(st[1] == "*")
|
||||
{ //Admin channel?
|
||||
bot->Notice(theClient,"If there's anything more important than my ego around, I want it caught and shot now.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we aren't trying to change someone with access higher
|
||||
* than ours. Also, make sure we can't change someone else's MODINFO
|
||||
* if they have the same access as we do.
|
||||
*/
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level < targetLevel) || ((level == targetLevel) && (targetUser != theUser)))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::mod_access_higher,
|
||||
string("Cannot modify a user with higher access than your own.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check for "ON" or "OFF" and act accordingly.
|
||||
*/
|
||||
|
||||
if (string_upper(st[4]) == "OP")
|
||||
{
|
||||
if (targetLevel < level::op) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuff_aop,
|
||||
string("Target user %s on channel %s has insufficient access for an automode OP")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
sqlLevel* aLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOVOICE);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOHALFOP);
|
||||
aLevel->setFlag(sqlLevel::F_AUTOOP);
|
||||
// aLevel->setLastModif(bot->currentTime());
|
||||
// aLevel->setLastModifBy(theClient->getNickUserHost());
|
||||
aLevel->commit();
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::automode_op,
|
||||
string("Set AUTOMODE to OP for %s on channel %s")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string_upper(st[4]) == "HALFOP")
|
||||
{
|
||||
if (targetLevel < level::halfop) {
|
||||
bot->Notice(theClient,
|
||||
/*bot->getResponse(theUser,
|
||||
language::insuff_aop,*/
|
||||
string("Target user %s on channel %s has insufficient access for an automode HALFOP")/*)*/.c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
sqlLevel* aLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOVOICE);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOOP);
|
||||
aLevel->setFlag(sqlLevel::F_AUTOHALFOP);
|
||||
// aLevel->setLastModif(bot->currentTime());
|
||||
// aLevel->setLastModifBy(theClient->getNickUserHost());
|
||||
aLevel->commit();
|
||||
|
||||
bot->Notice(theClient,
|
||||
/*bot->getResponse(theUser,
|
||||
language::automode_op,*/
|
||||
string("Set AUTOMODE to HALFOP for %s on channel %s")/*)*/.c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string_upper(st[4]) == "VOICE")
|
||||
{
|
||||
if (targetLevel < level::voice) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuff_avoice,
|
||||
string("Target user %s on channel %s has insufficient access for an automode VOICE")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
sqlLevel* aLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOOP);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOHALFOP);
|
||||
aLevel->setFlag(sqlLevel::F_AUTOVOICE);
|
||||
// aLevel->setLastModif(bot->currentTime());
|
||||
// aLevel->setLastModifBy(theClient->getNickUserHost());
|
||||
aLevel->commit();
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::automode_voice,
|
||||
string("Set AUTOMODE to VOICE for %s on channel %s")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string_upper(st[4]) == "NONE")
|
||||
{
|
||||
sqlLevel* aLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOOP);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOHALFOP);
|
||||
aLevel->removeFlag(sqlLevel::F_AUTOVOICE);
|
||||
// aLevel->setLastModif(bot->currentTime());
|
||||
// aLevel->setLastModifBy(theClient->getNickUserHost());
|
||||
aLevel->commit();
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::automode_none,
|
||||
string("Set AUTOMODE to NONE for %s on channel %s")).c_str(),
|
||||
targetUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* MOTDCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: MOTDCommand.cc,v 1.8 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char MOTDCommand_cc_rcsId[] = "$Id: MOTDCommand.cc,v 1.8 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool MOTDCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.MOTD");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() != 1 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::motd,
|
||||
string("No MOTD set.")));
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,104 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
# "$Id: Makefile.am,v 1.54 2009/06/25 19:05:23 mrbean_ Exp $"
|
||||
|
||||
lib_LTLIBRARIES = libcservice.la
|
||||
libcservice_la_LDFLAGS = -module -export-dynamic -L$(top_builddir)/db \
|
||||
-lgnuworldDB
|
||||
libcservice_la_CXXFLAGS = -I$(top_srcdir)/db -I${top_srcdir}/include \
|
||||
-I${top_srcdir}/libgnuworld
|
||||
|
||||
libcservice_la_SOURCES = cservice.cc \
|
||||
networkData.cc \
|
||||
sqlChannel.cc \
|
||||
sqlUser.cc \
|
||||
sqlLevel.cc \
|
||||
sqlBan.cc \
|
||||
sqlIncompleteChannel.cc \
|
||||
sqlPendingChannel.cc \
|
||||
sqlPendingTraffic.cc \
|
||||
csGline.cc \
|
||||
ACCESSCommand.cc \
|
||||
ACCEPTCommand.cc \
|
||||
ADDCOMMENTCommand.cc \
|
||||
ADDUSERCommand.cc \
|
||||
BANCommand.cc \
|
||||
BANLISTCommand.cc \
|
||||
CANCELCommand.cc \
|
||||
CHANINFOCommand.cc \
|
||||
CLEARMODECommand.cc \
|
||||
DEOPCommand.cc \
|
||||
DEHALFOPCommand.cc \
|
||||
DEVOICECommand.cc \
|
||||
FORCECommand.cc \
|
||||
HALFOPCommand.cc \
|
||||
HELPCommand.cc \
|
||||
HELLOCommand.cc \
|
||||
INVITECommand.cc \
|
||||
ISREGCommand.cc \
|
||||
JOINCommand.cc \
|
||||
KICKCommand.cc \
|
||||
LBANLISTCommand.cc \
|
||||
LOGINCommand.cc \
|
||||
MODINFOCommand.cc \
|
||||
MOTDCommand.cc \
|
||||
NEWPASSCommand.cc \
|
||||
NOTECommand.cc \
|
||||
OBJECTCommand.cc \
|
||||
OPCommand.cc \
|
||||
OPERJOINCommand.cc \
|
||||
OPERPARTCommand.cc \
|
||||
PARTCommand.cc \
|
||||
PURGECommand.cc \
|
||||
QUOTECommand.cc \
|
||||
RANDOMCommand.cc \
|
||||
REGISTERCommand.cc \
|
||||
REHASHCommand.cc \
|
||||
REJECTCommand.cc \
|
||||
REMIGNORECommand.cc \
|
||||
REMOVEALLCommand.cc \
|
||||
REMUSERCommand.cc \
|
||||
RENAMECommand.cc \
|
||||
SAYCommand.cc \
|
||||
SCANCommand.cc \
|
||||
SCANHOSTCommand.cc \
|
||||
SCANUNAMECommand.cc \
|
||||
SCANEMAILCommand.cc \
|
||||
SEARCHCommand.cc \
|
||||
SERVNOTICECommand.cc \
|
||||
SETCommand.cc \
|
||||
SHOWCOMMANDSCommand.cc \
|
||||
SHOWIGNORECommand.cc \
|
||||
SHUTDOWNCommand.cc \
|
||||
STATSCommand.cc \
|
||||
STATUSCommand.cc \
|
||||
SUPPORTCommand.cc \
|
||||
SUSPENDCommand.cc \
|
||||
SUSPENDMECommand.cc \
|
||||
TOPICCommand.cc \
|
||||
UNBANCommand.cc \
|
||||
UNFORCECommand.cc \
|
||||
UNSUSPENDCommand.cc \
|
||||
VERIFYCommand.cc \
|
||||
VOICECommand.cc \
|
||||
WHITELISTCommand.cc \
|
||||
CIDRBanMatcher.cc \
|
||||
HostBanMatcher.cc
|
||||
|
||||
EXTRA_DIST = banMatcher.h \
|
||||
constants.h \
|
||||
cserviceCommands.h \
|
||||
cservice_config.h \
|
||||
cservice.h \
|
||||
levels.h \
|
||||
networkData.h \
|
||||
responses.h \
|
||||
sqlBan.h \
|
||||
sqlChannel.h \
|
||||
sqlLevel.h \
|
||||
sqlIncompleteChannel.h \
|
||||
sqlPendingChannel.h \
|
||||
sqlPendingTraffic.h \
|
||||
sqlUser.h \
|
||||
csGline.h \
|
||||
README \
|
||||
RELEASE.NOTES
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,265 @@
|
||||
/**
|
||||
* NEWPASSCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: NEWPASSCommand.cc,v 1.17 2005/11/17 22:20:57 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "md5hash.h"
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "responses.h"
|
||||
#include "networkData.h"
|
||||
#include "cservice_config.h"
|
||||
#include "levels.h"
|
||||
|
||||
const char NEWPASSCommand_cc_rcsId[] = "$Id: NEWPASSCommand.cc,v 1.17 2005/11/17 22:20:57 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
const char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.$*_";
|
||||
|
||||
bool NEWPASSCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.NEWPASS");
|
||||
|
||||
#ifndef USE_NEWPASS
|
||||
bot->Notice(theClient, "To change your account password, please use the web interface.");
|
||||
return true;
|
||||
#else
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient, false);
|
||||
sqlUser* targetUser = tmpUser;
|
||||
if (!tmpUser)
|
||||
{
|
||||
if (bot->helloSendmailEnabled)
|
||||
{
|
||||
targetUser = bot->getUserRecord(st[1]);
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient, "I don't know who %s is.", st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
targetUser->generateRecoveryPassword();
|
||||
targetUser->setInstantiatedTS(::time(NULL));
|
||||
// Send the mail
|
||||
stringstream mailstream;
|
||||
mailstream << "The generated password is: " << targetUser->getRecoveryPassword().c_str() << endl;
|
||||
mailstream << theClient->getNickUserHost().c_str() << " requested a password reset to your username at this email address." << endl;
|
||||
mailstream << "If it wasn't you, you can safely ignore this message, your current password remains unchanged without a login with the generated password." << endl;
|
||||
mailstream << "Login via IRC using /msg " << bot->getNickName().c_str() << "@" << bot->getUplinkName().c_str() << " LOGIN " << targetUser->getUserName().c_str() << " " << targetUser->getRecoveryPassword().c_str() << endl;
|
||||
mailstream << "Then change your password using /msg " << bot->getNickName().c_str() << "@" << bot->getUplinkName().c_str() << " NEWPASS <new_password>" << endl;
|
||||
mailstream << ends;
|
||||
if (!bot->SendMail(targetUser->getEmail(), "Your CService account", mailstream))
|
||||
{
|
||||
bot->Notice(theClient, "An error occurred while sending newpass email, contact a CService representative.");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient, "Password reset successful.");
|
||||
bot->Notice(theClient, "Check your email (also in junk/spam) for the generated password.");
|
||||
if (targetUser->getFlag(sqlUser::F_TOTP_ENABLED))
|
||||
{
|
||||
targetUser->clearTotpKey();
|
||||
targetUser->clearTotpHexKey();
|
||||
targetUser->removeFlag(sqlUser::F_TOTP_ENABLED);
|
||||
if (!targetUser->commit(theClient))
|
||||
{
|
||||
bot->Notice(theClient, "Failed to disable TOTP authentication, please contact a CService representative.");
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, "\002 *** Your TOTP authentication data is also cleared! ***\002");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, You must be logged in to use this command.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int admAccess = (int)bot->getAdminAccessLevel(tmpUser);
|
||||
string newpass = st.assemble(1);
|
||||
|
||||
//bool notMe = false;
|
||||
if ((admAccess) && (st.size() > 2))
|
||||
{
|
||||
targetUser = bot->getUserRecord(st[1]);
|
||||
if (targetUser)
|
||||
{
|
||||
if (admAccess < level::newpass)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
newpass = st.assemble(2);
|
||||
sqlUser::networkClientListType::iterator clientItr = targetUser->networkClientList.begin();
|
||||
if (targetUser->networkClientList.size() > 0)
|
||||
{
|
||||
for ( ; clientItr != targetUser->networkClientList.end(); clientItr++)
|
||||
{
|
||||
iClient* tmpClient = *clientItr;
|
||||
if ((string_lower(newpass) == string_lower(targetUser->getUserName()))
|
||||
|| (string_lower(newpass) == string_lower(tmpClient->getNickName())))
|
||||
{
|
||||
bot->Notice(theClient,"The passphrase cannot be the target user's username or current nickname - syntax is: NEWPASS <targetUser> <new passphrase>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((string_lower(newpass) == string_lower(targetUser->getUserName())))
|
||||
{
|
||||
bot->Notice(theClient,"The passphrase cannot be the target user's username - syntax is: NEWPASS <targetUser> <new passphrase>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
targetUser = tmpUser;
|
||||
}
|
||||
/* Try and stop people using an invalid syntax.. */
|
||||
if ( (string_lower(newpass) == string_lower(targetUser->getUserName()))
|
||||
|| (string_lower(newpass) == string_lower(theClient->getNickName())) )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(targetUser,
|
||||
language::pass_cant_be_nick,
|
||||
string("Your passphrase cannot be your username or current nick - syntax is: NEWPASS <new passphrase>")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newpass.length() > 50)
|
||||
{
|
||||
bot->Notice(theClient, "Your passphrase cannot exceed 50 characters.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newpass.length() < 6)
|
||||
{
|
||||
bot->Notice(theClient, "Your passphrase cannot be less than 6 characters.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Work out some salt. */
|
||||
string salt;
|
||||
|
||||
// TODO: Why calling srand() here?
|
||||
srand(clock() * 1000000);
|
||||
|
||||
// TODO: What is the significance of '8' here?
|
||||
// Schema states a fixed 8 bytes of random salt are used in generating the
|
||||
// passowrd.
|
||||
for ( unsigned short int i = 0 ; i < 8; i++)
|
||||
{
|
||||
int randNo = 1+(int) (64.0*rand()/(RAND_MAX+1.0));
|
||||
salt += validChars[randNo];
|
||||
}
|
||||
|
||||
/* Work out a MD5 hash of our salt + password */
|
||||
|
||||
md5 hash; // MD5 hash algorithm object.
|
||||
md5Digest digest; // MD5Digest algorithm object.
|
||||
|
||||
// Prepend the salt to the password
|
||||
string newPass = salt + newpass;
|
||||
|
||||
// Take the md5 hash of this newPass string
|
||||
hash.update( (const unsigned char *)newPass.c_str(), newPass.size() );
|
||||
hash.report( digest );
|
||||
|
||||
/* Convert to Hex */
|
||||
|
||||
int data[ MD5_DIGEST_LENGTH ] = { 0 } ;
|
||||
for( size_t i = 0 ; i < MD5_DIGEST_LENGTH ; ++i )
|
||||
{
|
||||
data[ i ] = digest[ i ] ;
|
||||
}
|
||||
|
||||
stringstream output;
|
||||
output << std::hex;
|
||||
output.fill('0');
|
||||
for( size_t ii = 0; ii < MD5_DIGEST_LENGTH; ii++ )
|
||||
{
|
||||
output << std::setw(2) << data[ii];
|
||||
}
|
||||
output << ends;
|
||||
|
||||
// Prepend the md5 hash to the salt
|
||||
string finalPassword = salt + output.str().c_str();
|
||||
|
||||
targetUser->setPassword(finalPassword);
|
||||
|
||||
bool hasTotp = false;
|
||||
if (targetUser->getFlag(sqlUser::F_TOTP_ENABLED))
|
||||
{
|
||||
hasTotp = true;
|
||||
targetUser->clearTotpKey();
|
||||
targetUser->clearTotpHexKey();
|
||||
targetUser->removeFlag(sqlUser::F_TOTP_ENABLED);
|
||||
}
|
||||
|
||||
if (targetUser->commit(theClient))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::pass_changed,
|
||||
string("Password successfully changed.")));
|
||||
if (hasTotp)
|
||||
bot->Notice(theClient, "\002 *** Your TOTP authentication data is also cleared! ***\002");
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO
|
||||
bot->Notice(theClient, "NEWPASS: Unable to commit to database") ;
|
||||
}
|
||||
return true;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,295 @@
|
||||
/**
|
||||
* NOTESCommand.cc
|
||||
* Leave a note for another user account, or read your own Notes.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: NOTECommand.cc,v 1.8 2007/08/28 16:10:11 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "Network.h"
|
||||
#include "responses.h"
|
||||
#include "cservice.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char NOTECommand_cc_rcsId[] = "$Id: NOTECommand.cc,v 1.8 2007/08/28 16:10:11 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool NOTECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
|
||||
//If Admin's don't play, noone's playin' ...
|
||||
#ifndef USE_USERS_NOTES
|
||||
#ifndef USE_NOTES
|
||||
return true;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bot->incStat("COMMANDS.NOTE");
|
||||
|
||||
/* Is the user authorised? */
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if(!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/* No, from now on, All of Us is Playin' :P - Seven :P
|
||||
/* Only let admins play for now
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if(!level) return false;
|
||||
*/
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sending a Note?
|
||||
*/
|
||||
if (string_lower(st[1]) == "send")
|
||||
{
|
||||
/*
|
||||
* First, check this person exists.
|
||||
*/
|
||||
sqlUser* targetUser = bot->getUserRecord(st[2]);
|
||||
string message = st.assemble(3);
|
||||
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::not_registered,
|
||||
string("I don't know who %s is")).c_str(), st[2].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* They do? Great! lets see if we're currently allowed to send
|
||||
* a note.
|
||||
*
|
||||
* Firstly, does the target wish to have a nice quiet inbox?
|
||||
*/
|
||||
if (targetUser->getFlag(sqlUser::F_NONOTES))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::noaccpt_notes,
|
||||
string("%s doesn't accept Notes.")).c_str(),
|
||||
targetUser->getUserName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Do Admins gets notes from users? */
|
||||
#ifndef USERS_NOTE_ADMINS
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::noaccpt_notes,
|
||||
string("%s doesn't accept Notes.")).c_str(),
|
||||
targetUser->getUserName().c_str());
|
||||
return false;
|
||||
#endif
|
||||
/*
|
||||
* Have we exceeded the maximum number of Notes we can
|
||||
* send right now?
|
||||
*/
|
||||
|
||||
if( (unsigned int)(bot->currentTime() - theUser->getLastNote()) >= bot->noteDuration )
|
||||
{
|
||||
theUser->setLastNote(bot->currentTime());
|
||||
theUser->setNotesSent(0);
|
||||
}
|
||||
|
||||
if( ((unsigned int)(bot->currentTime() - theUser->getLastNote()) <= bot->noteDuration) && (theUser->getNotesSent() >= bot->noteLimit) )
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::exc_max_notes, string("You have exceeded the maximum number of notes you can send at this time, please try later.")).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump the note into the database.
|
||||
*/
|
||||
|
||||
/* .. SQL here .. */
|
||||
|
||||
static const char* queryHeader = "INSERT INTO notes (user_id,from_user_id,message,last_updated) VALUES (";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< targetUser->getID() << ", "
|
||||
<< theUser->getID() << ", '"
|
||||
<< escapeSQLChars(message) << "', "
|
||||
<< "date_part('epoch', CURRENT_TIMESTAMP)::int);"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "NOTECommand::Insert Note> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(queryString ) )
|
||||
// if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlBan::commit> Something went wrong: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
bot->Notice(theClient, "An unknown error occured delivering the note.");
|
||||
bot->Notice(theClient, bot->SQLDb->ErrorMessage().c_str());
|
||||
return false ;
|
||||
}
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::note_sended,string("Successfully delivered message to %s!")).c_str(), targetUser->getUserName().c_str());
|
||||
|
||||
bot->noticeAllAuthedClients(targetUser, bot->getResponse(targetUser, language::read_note_help,string("%s has just sent you a note. Type /msg %s notes read all to read it.")).c_str(),
|
||||
theUser->getUserName().c_str(), bot->getNickName().c_str());
|
||||
|
||||
theUser->setNotesSent(theUser->getNotesSent() + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reading a Note?
|
||||
*/
|
||||
if (string_lower(st[1]) == "read")
|
||||
{
|
||||
if(string_lower(st[2]) == "all")
|
||||
{
|
||||
/*
|
||||
* Perform a query to list all notes belonging to this user.
|
||||
*/
|
||||
stringstream allNotesQuery;
|
||||
allNotesQuery << "SELECT users.user_name, notes.message, notes.last_updated, message_id "
|
||||
<< "FROM notes,users "
|
||||
<< "WHERE notes.from_user_id = users.id "
|
||||
<< "AND notes.user_id = "
|
||||
<< theUser->getID()
|
||||
<< " ORDER BY notes.last_updated ASC"
|
||||
<< ends;
|
||||
|
||||
if( !bot->SQLDb->Exec( allNotesQuery, true ) )
|
||||
// if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SUPPORTCommand> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
|
||||
bot->Notice(theClient, "An unknown error occured while reading your notes.");
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (bot->SQLDb->Tuples() <= 0)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::have_nonotes,string("You have no notes.")).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int noteCount = bot->SQLDb->Tuples();
|
||||
|
||||
for (unsigned int i = 0 ; i < noteCount; i++)
|
||||
{
|
||||
string from = bot->SQLDb->GetValue(i,0);
|
||||
string theMessage = bot->SQLDb->GetValue(i,1);
|
||||
unsigned int when = atoi(bot->SQLDb->GetValue(i,2));
|
||||
unsigned int message_id = atoi(bot->SQLDb->GetValue(i,3));
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::message_id,string("\002NOTE\002 (Message-Id: %i): Recieved from %s, %s ago: %s")).c_str(),
|
||||
message_id, from.c_str(), prettyDuration(when).c_str(), theMessage.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::erase_note_help,string("To erase an individual note, type /msg %s notes erase <message-id>. To erase all your notes, type /msg %s notes erase all")).c_str(), bot->getNickName().c_str(), bot->getNickName().c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Erasing a Note?
|
||||
*/
|
||||
if (string_lower(st[1]) == "erase")
|
||||
{
|
||||
if(string_lower(st[2]) == "all")
|
||||
{
|
||||
stringstream queryString;
|
||||
queryString << "DELETE FROM notes where user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "NOTECommand::Delete Notes> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(queryString ) )
|
||||
// if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
bot->Notice(theClient, "An unknown error occured while deleting your notes.");
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::all_notes_erased,string("Successfully erased all your notes.")).c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* TOFINISH: Delete by message-id.
|
||||
*/
|
||||
|
||||
unsigned int messageId = atoi(st[2].c_str());
|
||||
if(!messageId)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::inv_messageid,string("Invalid message-id.")).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "DELETE FROM notes where user_id = "
|
||||
<< theUser->getID()
|
||||
<< " AND message_id = "
|
||||
<< messageId
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "NOTECommand::Delete Notes> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(queryString, true ) )
|
||||
// if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
bot->Notice(theClient, "An error occured while deleting note-id %i.", messageId);
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::erased_messageid,string("Successfully erased note with message-id %i.")).c_str(), messageId);
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* OBJECTCommand.cc
|
||||
*
|
||||
* 01/07/2012 - Gergo Focze <gergo_f@yahoo.com>
|
||||
* Initial Version.
|
||||
*
|
||||
* Make an objection for a channel under registration from IRC
|
||||
*
|
||||
* 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 <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char OBJECTCommand_cc_rcsId[] = "$Id: OBJECTCommand.cc,v 1.0 2012/07/01 12:11:10 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool OBJECTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.OBJECT");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if ( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
if (!theUser) return false;
|
||||
|
||||
/*
|
||||
* First, check the channel is registered/real.
|
||||
*/
|
||||
|
||||
if ( (st[1][0] != '#') )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_chan_name,
|
||||
string("Invalid channel name.")));
|
||||
return false;
|
||||
}
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_already_reg,
|
||||
string("%s is already registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
string objection = st.assemble(2);
|
||||
if ((objection.size() < 2) || (objection.size() > 450))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::reason_must).c_str(),2,450);
|
||||
return false;
|
||||
}
|
||||
stringstream theQuery;
|
||||
/********** Channel ID query ***********/
|
||||
theQuery << "SELECT id,status FROM channels,pending WHERE "
|
||||
<< "channels.registered_ts = 0 AND lower(channels.name) = '"
|
||||
<< escapeSQLChars(string_lower(st[1]))
|
||||
<< "'"
|
||||
<< " AND channels.id = pending.channel_id AND pending.decision_ts=0"
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on OBJECT.pending.status query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "OBJECT.pending.status query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
unsigned int chanId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
unsigned short status = atoi(bot->SQLDb->GetValue(0,1));
|
||||
if ((status >= 3) && (status <= 9))
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
/*** Check if already has a comment ***/
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT * FROM objections WHERE user_id="
|
||||
<< theUser->getID()
|
||||
<< " and channel_id = "
|
||||
<< chanId
|
||||
<< " AND admin_only='N'"
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on OBJECT.AlreadyComment query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "OBJECT.AlreadyComment query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (bot->SQLDb->Tuples() > 0)
|
||||
{
|
||||
bot->Notice(theClient,"You have already posted an objection for that channel.");
|
||||
return false;
|
||||
}
|
||||
/* *** Insert the objection *** */
|
||||
theQuery.str("");
|
||||
theQuery << "INSERT INTO objections (channel_id,user_id,comment,created_ts,admin_only) VALUES ("
|
||||
<< chanId
|
||||
<< ", "
|
||||
<< theUser->getID()
|
||||
<< ", '"
|
||||
<< objection
|
||||
<< "', date_part('epoch', CURRENT_TIMESTAMP)::int, 'N')"
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on OBJECT.InsertObjection query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "OBJECT.InsertObjection query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
bot->Notice(theClient,"An unknown error occured while posting objection.");
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient,"Objection posted successfully.");
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,326 @@
|
||||
/**
|
||||
* OPCommand.cc
|
||||
*
|
||||
* 20/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* 28/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Added multilingual support.
|
||||
*
|
||||
* 01/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Woo! First change of 2001. :)
|
||||
* Added duplicate checking to avoid people doing:
|
||||
* /msg e op #coder-com Gte Gte Gte Gte Gte Gte Gte {etc}
|
||||
* And flooding the target with notices.
|
||||
*
|
||||
* 2001-03-21 - Perry Lorier <isomer@coders.net>
|
||||
* added 'on chan' to the message
|
||||
*
|
||||
* OP's one or more users on a channel the user as access on.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: OPCommand.cc,v 1.29 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
using std::map ;
|
||||
|
||||
const char OPCommand_cc_rcsId[] = "$Id: OPCommand.cc,v 1.29 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool OPCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.OP");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::op)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we're actually opped first..
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = tmpChan->findUser(bot->getInstance());
|
||||
if (!tmpBotUser) return false;
|
||||
if(!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::im_not_opped, "I'm not opped in %s").c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the NOOP flag is set, we aren't allowed to op anyone.
|
||||
*/
|
||||
|
||||
if(theChan->getFlag(sqlChannel::F_NOOP))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::noop_set,
|
||||
string("The NOOP flag is set on %s")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the remaining 'nick' parameters, opping them all.
|
||||
*/
|
||||
|
||||
char delim = 0 ;
|
||||
string source;
|
||||
StringTokenizer::size_type counter = 2;
|
||||
|
||||
iClient* target = 0 ;
|
||||
|
||||
/* Offset of first nick in string. */
|
||||
|
||||
typedef map < iClient*, int > duplicateMapType;
|
||||
duplicateMapType duplicateMap;
|
||||
|
||||
vector< iClient* > opList; // List of clients to op.
|
||||
|
||||
if( st.size() < 3 ) /* No nicks provided, assume we op ourself. :) */
|
||||
{
|
||||
opList.push_back(theClient);
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
string::size_type pos = st[2].find_first_of( ',' ) ;
|
||||
|
||||
/* Found a comma? */
|
||||
if( string::npos != pos )
|
||||
{
|
||||
/* We'll do a comma seperated search then. */
|
||||
source = st.assemble(2);
|
||||
delim = ',';
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( source, delim );
|
||||
|
||||
for( ; counter < st2.size() ; ++counter )
|
||||
{
|
||||
target = Network->findNick(st2[counter]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::dont_see_them).c_str(),
|
||||
st2[counter].c_str());
|
||||
continue ;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser = tmpChan->findUser(target) ;
|
||||
|
||||
// User isn't on the channel?
|
||||
if (!tmpChanUser)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
continue ;
|
||||
}
|
||||
|
||||
// User is already opped?
|
||||
if(tmpChanUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::already_opped).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Has the target user's account been suspended?
|
||||
sqlUser* authUser = bot->isAuthed(tmpChanUser->getClient(), false);
|
||||
|
||||
if (authUser && authUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
bot->Notice(theClient, "The user %s (%s) has been suspended by a CService Administrator.",
|
||||
authUser->getUserName().c_str(), tmpChanUser->getClient()->getNickName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the channel has the STRICTOP flag set, we are only allowed to op people who
|
||||
* are authorised, and have access in this channel.
|
||||
*/
|
||||
|
||||
if(theChan->getFlag(sqlChannel::F_STRICTOP))
|
||||
{
|
||||
|
||||
/* Not authed, don't allow this op. */
|
||||
if (!authUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::strictop_not_authed,
|
||||
string("The STRICTOP flag is set on %s (and %s isn't authenticated)")).c_str(),
|
||||
theChan->getName().c_str(), tmpChanUser->getNickName().c_str());
|
||||
continue ;
|
||||
/* Authed but no access? Tough. :) */
|
||||
}
|
||||
else if (!(bot->getEffectiveAccessLevel(authUser, theChan, false) >= level::op))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::strictop_insuf_access,
|
||||
string("The STRICTOP flag is set on %s (and %s has insufficient access)")).c_str(),
|
||||
theChan->getName().c_str(), authUser->getUserName().c_str());
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user is banned <75, don't allow them to be opp'd either
|
||||
*/
|
||||
|
||||
sqlBan* tmpBan = bot->isBannedOnChan(theChan, tmpChanUser->getClient());
|
||||
if( tmpBan && (tmpBan->getLevel() <= 75) )
|
||||
{
|
||||
/* Tell the person doing the op'ing this is bad */
|
||||
bot->Notice(theClient,
|
||||
"%s isn't allowed to be opped on %s",
|
||||
tmpChanUser->getClient()->getNickName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Check for duplicates.
|
||||
duplicateMapType::iterator ptr = duplicateMap.find(target);
|
||||
|
||||
if(ptr == duplicateMap.end())
|
||||
{
|
||||
// Not a duplicate.
|
||||
opList.push_back(target);
|
||||
duplicateMap.insert(duplicateMapType::value_type(target, 0));
|
||||
|
||||
// Don't send a notice to the person who issued the command.
|
||||
if(target != theClient)
|
||||
{
|
||||
sqlUser* tmpTargetUser = bot->isAuthed(target, false);
|
||||
if (tmpTargetUser)
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(tmpTargetUser,
|
||||
language::youre_opped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(theUser,
|
||||
language::youre_opped_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
} // Don't send to person who issued.
|
||||
} // Not a duplicate.
|
||||
}
|
||||
|
||||
// Op them.
|
||||
bot->Op(tmpChan, opList);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* OPERJOINCommand.cc
|
||||
*
|
||||
* 10/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version. Written, and finished.
|
||||
*
|
||||
* Allows an oper to make cmaster join a registered channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: OPERJOINCommand.cc,v 1.16 2008/04/16 20:34:39 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char OPERJOINCommand_cc_rcsId[] = "$Id: OPERJOINCommand.cc,v 1.16 2008/04/16 20:34:39 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool OPERJOINCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.OPERJOIN");
|
||||
|
||||
#ifdef USE_OPERPARTJOIN
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user is an oper.
|
||||
*/
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
|
||||
if(!theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::ircops_only_cmd,
|
||||
"This command is reserved to IRC Operators"));
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
Channel* tmpChan = Network->findChannel(st[1]);
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg,
|
||||
"The channel %s doesn't appear to be registered").c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot isn't in the channel. */
|
||||
if (theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::already_on_chan,
|
||||
"I'm already in that channel!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tell the world.
|
||||
|
||||
bot->Wallops( "An IRC Operator is asking me to join channel %s",
|
||||
theChan->getName().c_str() ) ;
|
||||
|
||||
bot->logAdminMessage("%s is asking me to join channel %s",
|
||||
theClient->getNickUserHost().c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_OPERJOIN, "");
|
||||
|
||||
theChan->setInChan(true);
|
||||
bot->Join(theChan->getName(),
|
||||
theChan->getChannelMode(),
|
||||
theChan->getChannelTS(),
|
||||
true);
|
||||
bot->joinCount++;
|
||||
|
||||
if (tmpChan)
|
||||
{
|
||||
if(theChan->getFlag(sqlChannel::F_NOOP))
|
||||
{
|
||||
bot->deopAllOnChan(tmpChan);
|
||||
}
|
||||
if(theChan->getFlag(sqlChannel::F_STRICTOP))
|
||||
{
|
||||
bot->deopAllUnAuthedOnChan(tmpChan);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
#endif // USE_OPERPARTJOIN
|
||||
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* PARTCommand.cc
|
||||
*
|
||||
* 10/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version. Written, and finished.
|
||||
*
|
||||
* Allows an oper to part cmaster from a registered channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: OPERPARTCommand.cc,v 1.15 2008/04/16 20:34:39 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char OPERPARTCommand_cc_rcsId[] = "$Id: OPERPARTCommand.cc,v 1.15 2008/04/16 20:34:39 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool OPERPARTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.OPERPART");
|
||||
|
||||
#ifdef USE_OPERPARTJOIN
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the user is an oper.
|
||||
*/
|
||||
|
||||
// cservice::getResponse() will properly handle a NULL
|
||||
// sqlUser
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
|
||||
if(!theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::ircops_only_cmd,
|
||||
"This command is reserved to IRC Operators"));
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_OPERPART, "");
|
||||
|
||||
// Tell the world.
|
||||
|
||||
bot->Wallops( "An IRC Operator is asking me to leave channel %s",
|
||||
theChan->getName().c_str() ) ;
|
||||
|
||||
bot->logAdminMessage("%s is asking me to leave channel %s",
|
||||
theClient->getNickUserHost().c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
theChan->setInChan(false);
|
||||
bot->joinCount--;
|
||||
|
||||
bot->Part(theChan->getName(), "At the request of an IRC Operator");
|
||||
|
||||
return true;
|
||||
|
||||
#endif // USE_OPERPARTJOIN
|
||||
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* PARTCommand.cc
|
||||
*
|
||||
* 10/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version. Written, and finished.
|
||||
*
|
||||
* Makes cmaster leave a registered channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: PARTCommand.cc,v 1.17 2008/04/16 20:34:40 danielaustin Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char PARTCommand_cc_rcsId[] = "$Id: PARTCommand.cc,v 1.17 2008/04/16 20:34:40 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool PARTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.PART");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::part)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
theChan->setInChan(false);
|
||||
bot->joinCount--;
|
||||
|
||||
/* Forced access. */
|
||||
if (bot->isForced(theChan, theUser))
|
||||
{
|
||||
bot->Part(theChan->getName(), "At the request of a CService Administrator");
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_PART, "[CS-ADMIN]");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Write a log of this event.. */
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_PART, "");
|
||||
|
||||
string partReason = "At the request of " + theUser->getUserName();
|
||||
|
||||
bot->Part(theChan->getName(), partReason);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,410 @@
|
||||
/**
|
||||
* PURGECommand.cc
|
||||
*
|
||||
* 24/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Purges a channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: PURGECommand.cc,v 1.22 2008/04/16 20:34:40 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "dbHandle.h"
|
||||
#include "Network.h"
|
||||
#include "responses.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char PURGECommand_cc_rcsId[] = "$Id: PURGECommand.cc,v 1.22 2008/04/16 20:34:40 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool PURGECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.PURGE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Are we purging a user or a channel?
|
||||
*/
|
||||
|
||||
// Did we find a '#' ?
|
||||
if( string::npos == st[ 1 ].find_first_of( '#' ) )
|
||||
{
|
||||
// Nope, look by user then.
|
||||
sqlUser* tmpUser = bot->getUserRecord(st[1]);
|
||||
|
||||
if (!tmpUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered,
|
||||
string("The user %s doesn't appear to be registered.")).c_str(),
|
||||
st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level < level::userpurge)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(tmpUser);
|
||||
/*
|
||||
* Why I did these ??
|
||||
*
|
||||
if (admLevel)
|
||||
{
|
||||
bot->Notice(theClient, "Cannot purge any user with '*' access. Try to remove it's '*' access first.");
|
||||
return false;
|
||||
}
|
||||
if (tmpUser->getFlag(sqlUser::F_NOPURGE))
|
||||
{
|
||||
bot->Notice(theClient, "User %s has NOPURGE flag. Remove it first.", tmpUser->getUserName().c_str());
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level <= admLevel)/* && (tmpUser != theUser)*/) //<- reactivate this if admin can purge it's own user
|
||||
{
|
||||
bot->Notice(theClient, "Cannot purge a user with equal or higher access than your own");
|
||||
return false;
|
||||
}
|
||||
string userToDel = tmpUser->getUserName();
|
||||
if (bot->wipeUser(tmpUser->getID(), false))
|
||||
{
|
||||
bot->logAdminMessage("%s (%s) purged user %s", theClient->getNickName().c_str(), theUser->getUserName().c_str(), userToDel.c_str());
|
||||
bot->Notice(theClient, "Successfully purged user %s", userToDel.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->logDebugMessage("An error occured at a user purge command.");
|
||||
bot->Notice(theClient, "An error occured while purged user. Contact coders.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} //End of user purge
|
||||
|
||||
if (st.size() < 3)
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* First, check the channel isn't already registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if ((!theChan) || (st[1] == "*"))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("%s isn't registered with me")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level < level::chanpurge)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't purge the channel if NOPURGE is set.
|
||||
*/
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (theChan->getFlag(sqlChannel::F_NOPURGE))
|
||||
{
|
||||
bot->Notice(theClient, "%s has NOPURGE set, so I'm not purging it.",
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool reop;
|
||||
string reason;
|
||||
|
||||
if (!strcasecmp(st[2],"-noop"))
|
||||
{
|
||||
reason = st.assemble(3);
|
||||
reop = false;
|
||||
} else {
|
||||
reason = st.assemble(2);
|
||||
reop = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch some information about the owner of this channel, so we can
|
||||
* 'freeze' it for future investigation in the log.
|
||||
*/
|
||||
|
||||
stringstream managerQuery;
|
||||
managerQuery << "SELECT users.user_name,users.email "
|
||||
<< "FROM users,levels "
|
||||
<< "WHERE levels.user_id = users.id "
|
||||
<< "AND levels.access = 500 "
|
||||
<< "AND levels.channel_id = "
|
||||
<< theChan->getID()
|
||||
<< " LIMIT 1"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> "
|
||||
<< managerQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
string manager = "No Manager";
|
||||
string managerEmail = "No Email Address";
|
||||
|
||||
if( !bot->SQLDb->Exec(managerQuery, true ) )
|
||||
//if( status != PGRES_TUPLES_OK )
|
||||
{
|
||||
elog << "PURGE> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bot->SQLDb->Tuples() != 0)
|
||||
{
|
||||
manager = bot->SQLDb->GetValue(0,0);
|
||||
managerEmail = bot->SQLDb->GetValue(0,1);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we need to reop, do it here */
|
||||
if (reop)
|
||||
{
|
||||
/* iterate over the channel userlist */
|
||||
vector< iClient* > opList;
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
/* only parse the following if the channel exists on the network
|
||||
* if there is nobody in the channel, there is nobody to op.
|
||||
*/
|
||||
if (tmpChan)
|
||||
{
|
||||
for (Channel::userIterator chanUsers = tmpChan->userList_begin();
|
||||
chanUsers != tmpChan->userList_end(); ++chanUsers)
|
||||
{
|
||||
ChannelUser* tmpUser = chanUsers->second;
|
||||
iClient* tmpClient = tmpUser->getClient();
|
||||
sqlUser* tUser = bot->isAuthed(tmpClient, false);
|
||||
if (!tUser)
|
||||
continue;
|
||||
/* are they globally suspended? */
|
||||
if (tUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
continue;
|
||||
sqlLevel* theLevel = bot->getLevelRecord(tUser, theChan);
|
||||
/* check if they have access (and not suspended) */
|
||||
if (theLevel)
|
||||
{
|
||||
if (theLevel->getSuspendExpire() > bot->currentTime())
|
||||
continue;
|
||||
if (theLevel->getAccess() >= 100)
|
||||
{
|
||||
/* they're 100+, op them */
|
||||
opList.push_back(tmpClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* actually do the ops */
|
||||
if (!opList.empty())
|
||||
{
|
||||
/* check we are in the channel, and opped */
|
||||
ChannelUser* tmpBotUser = tmpChan->findUser(bot->getInstance());
|
||||
if (tmpBotUser)
|
||||
{
|
||||
if (!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
/* op ourselves so that we can do the reops */
|
||||
stringstream s;
|
||||
s << bot->getCharYY()
|
||||
<< " M "
|
||||
<< theChan->getName()
|
||||
<< " +o "
|
||||
<< bot->getCharYYXXX()
|
||||
<< ends;
|
||||
bot->Write( s );
|
||||
/* update the channel state */
|
||||
tmpBotUser->setMode(ChannelUser::MODE_O);
|
||||
}
|
||||
}
|
||||
/* do the ops - if we were not in the channel before, this will
|
||||
* auto-join and op the bot anyway.
|
||||
*/
|
||||
bot->Op(tmpChan, opList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset everything back to nice default values.
|
||||
*/
|
||||
|
||||
theChan->clearFlags();
|
||||
theChan->setMassDeopPro(3);
|
||||
theChan->setFloodPro(0);
|
||||
theChan->setNoTake(0);
|
||||
theChan->setURL("");
|
||||
theChan->setDescription("");
|
||||
theChan->setComment("");
|
||||
theChan->setKeywords("");
|
||||
theChan->setRegisteredTS(0);
|
||||
theChan->setChannelMode("+tn");
|
||||
theChan->commit();
|
||||
|
||||
/*
|
||||
* Permanently delete all associated Level records for this channel.
|
||||
*/
|
||||
|
||||
stringstream theQuery ;
|
||||
|
||||
theQuery << "DELETE FROM levels WHERE channel_id = "
|
||||
<< theChan->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(theQuery ) )
|
||||
//if( status != PGRES_COMMAND_OK )
|
||||
{
|
||||
elog << "PURGE> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bin 'em all.
|
||||
*/
|
||||
|
||||
cservice::sqlLevelHashType::const_iterator ptr = bot->sqlLevelCache.begin();
|
||||
cservice::sqlLevelHashType::key_type thePair;
|
||||
|
||||
while(ptr != bot->sqlLevelCache.end())
|
||||
{
|
||||
sqlLevel* tmpLevel = ptr->second;
|
||||
unsigned int channel_id = ptr->first.second;
|
||||
|
||||
if (channel_id == theChan->getID())
|
||||
{
|
||||
thePair = ptr->first;
|
||||
|
||||
#ifdef LOG_DEBUG
|
||||
elog << "Purging Level Record for: " << thePair.second << " (UID: " << thePair.first << ")" << endl;
|
||||
#endif
|
||||
|
||||
++ptr;
|
||||
bot->sqlLevelCache.erase(thePair);
|
||||
|
||||
delete(tmpLevel);
|
||||
} else
|
||||
{
|
||||
++ptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bot->logAdminMessage("%s (%s) has purged %s (%s)",
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str(),
|
||||
reason.c_str());
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::purged_chan,
|
||||
string("Purged channel %s")).c_str(),
|
||||
st[1].c_str());
|
||||
|
||||
bot->writeChannelLog(theChan,
|
||||
theClient,
|
||||
sqlChannel::EV_PURGE,
|
||||
"has purged " + theChan->getName() + " (" + reason + "), " +
|
||||
"Manager was " + manager + " (" + managerEmail + ")" );
|
||||
|
||||
/* Remove from cache.. part channel. */
|
||||
bot->sqlChannelCache.erase(theChan->getName());
|
||||
bot->sqlChannelIDCache.erase(theChan->getID());
|
||||
/* no longer interested in this channel */
|
||||
bot->getUplink()->UnRegisterChannelEvent( theChan->getName(), bot ) ;
|
||||
/* remove mode 'R' (no longer registered) */
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (tmpChan)
|
||||
bot->getUplink()->Mode(NULL, tmpChan, string("-R"), string() );
|
||||
bot->Part(theChan->getName());
|
||||
bot->joinCount--;
|
||||
|
||||
delete(theChan);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* QUOTECommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: QUOTECommand.cc,v 1.6 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cservice.h"
|
||||
//#include "sqlUser.h"
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char QUOTECommand_cc_rcsId[] = "$Id: QUOTECommand.cc,v 1.6 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
|
||||
bool QUOTECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.QUOTE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 1 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::quote)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
bot->Write( st.assemble(1) );
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* RANDOMCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: RANDOMCommand.cc,v 1.6 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "Network.h"
|
||||
#include "cservice.h"
|
||||
|
||||
const char RANDOMCommand_cc_rcsId[] = "$Id: RANDOMCommand.cc,v 1.6 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool RANDOMCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.RANDOM");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,46 @@
|
||||
Follow these steps to setup the database for the cservice module. This
|
||||
file assumes that postgresql is running and configured, and that you have
|
||||
access to add and modify databases within it.
|
||||
|
||||
Create the database
|
||||
-------------------
|
||||
> createdb cservice
|
||||
|
||||
Note that this assumes that the ccontrol database does not already exist.
|
||||
|
||||
Install the pl language
|
||||
-----------------------
|
||||
The following command assumes (in addition to above conditions) that the
|
||||
pgsql libraries are located in /usr/local/pgsql/lib:
|
||||
|
||||
> createlang plpgsql cservice -L /usr/local/pgsql/lib
|
||||
|
||||
Load the schema
|
||||
---------------
|
||||
Make sure you are in the gnuworld/doc directory.
|
||||
|
||||
> psql cservice < cservice.sql
|
||||
> psql cservice < language_table.sql
|
||||
> psql cservice < cservice.web.sql
|
||||
|
||||
Add administrator account
|
||||
-------------------------
|
||||
This command will add an account called 'Admin' with level 1000 access on
|
||||
channel '*'...use this power wisely, The Dark Side is very powerful.
|
||||
|
||||
> psql cservice < cservice.addme.sql
|
||||
|
||||
Using this account you will be able to login as Admin online with your
|
||||
cservice bot.
|
||||
|
||||
Username: Admin
|
||||
Password: temPass (be sure to change this)
|
||||
|
||||
All Done
|
||||
--------
|
||||
That's it for the sql stuff. Be sure to edit the configuration file for
|
||||
cmaster (../bin/cservice.conf), giving username, nickname, etc, and
|
||||
database information.
|
||||
|
||||
The GNUWorld development team
|
||||
|
||||
@@ -0,0 +1,567 @@
|
||||
/**
|
||||
* REGISTERCommand.cc
|
||||
*
|
||||
* 26/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Registers a channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: REGISTERCommand.cc,v 1.24 2009/07/31 07:29:13 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "dbHandle.h"
|
||||
#include "Network.h"
|
||||
#include "responses.h"
|
||||
|
||||
|
||||
const char REGISTERCommand_cc_rcsId[] = "$Id: REGISTERCommand.cc,v 1.24 2009/07/31 07:29:13 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::pair ;
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool REGISTERCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.REGISTER");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) return false;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
string::size_type pos = st[1].find_first_of( ',' ); /* Don't allow comma's in channel names. :) */
|
||||
|
||||
if ( (st[1][0] != '#') || (string::npos != pos))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_chan_name,
|
||||
string("Invalid channel name.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, check the channel isn't already registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan;
|
||||
theChan = bot->getChannelRecord(st[1]);
|
||||
if (theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_already_reg,
|
||||
string("%s is already registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
bool hasApp = false;
|
||||
sqlIncompleteChannel *chanApp = 0;
|
||||
cservice::incompleteChanRegsType::iterator theApp = bot->incompleteChanRegs.find(theUser->getID());
|
||||
if (theApp != bot->incompleteChanRegs.end())
|
||||
{
|
||||
hasApp = true;
|
||||
chanApp = theApp->second;
|
||||
}
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (((level < level::registercmd) && (level > 0)) && ((st.size() > 2) && (!hasApp)))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
#ifndef ALLOW_IRC_CHANREG
|
||||
if (level == 0)
|
||||
{
|
||||
bot->Notice(theClient, "Channel registration via IRC is disabled. Use website instead.");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
// Admin registration case !
|
||||
if ((level >= level::registercmd) && ((st.size() > 2) && (!hasApp)))
|
||||
{
|
||||
sqlUser* tmpUser = bot->getUserRecord(st[2]);
|
||||
if (!tmpUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered,
|
||||
string("The user %s doesn't appear to be registered.")).c_str(),
|
||||
st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (level < level::immune::registercmd)
|
||||
{
|
||||
if (!bot->isValidChannel(st[1]))
|
||||
{
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
bot->Notice(theClient, "Cannot register, channel is %s",bot->getCurrentValidResponse().c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bot->isValidUser(tmpUser->getUserName()))
|
||||
{
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
bot->Notice(theClient, "Cannot register, invalid target user (%s)",bot->getCurrentValidResponse().c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bot->isValidApplicant(tmpUser))
|
||||
{
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
if (bot->getCurrentValidResponse() == "ALREADY_HAVE_CHAN")
|
||||
{
|
||||
bot->Notice(theClient, "Target user already have a channel registered.");
|
||||
bot->validResponseString.clear();
|
||||
return false;
|
||||
}
|
||||
if (bot->getCurrentValidResponse() == "ALREADY_HAVE_PENDINGCHAN")
|
||||
{
|
||||
bot->Notice(theClient, "Target user already have a channel pending registration.");
|
||||
bot->validResponseString.clear();
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, bot->getCurrentValidResponse().c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} //level < immune::registercomd
|
||||
|
||||
if (bot->sqlRegisterChannel(theClient, tmpUser,st[1].c_str()))
|
||||
{
|
||||
//sqlChannel* newChan = bot->getChannelRecord(st[1]);
|
||||
theChan = bot->getChannelRecord(st[1]);
|
||||
bot->logAdminMessage("%s (%s) has registered %s to %s", theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(), st[1].c_str(), tmpUser->getUserName().c_str());
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::regged_chan,
|
||||
string("Registered channel %s to %s")).c_str(), st[1].c_str(),tmpUser->getUserName().c_str());
|
||||
//return true;
|
||||
} else {
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
bot->Notice(theClient, bot->validResponseString.c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // end of Admin registration case
|
||||
|
||||
//Normal user application case
|
||||
if (hasApp)
|
||||
{
|
||||
//bot->logDebugMessage("Performing normal registration");
|
||||
|
||||
if ((string_lower(chanApp->chanName) != (string_lower(st[1]))))
|
||||
{
|
||||
string chanName = chanApp->chanName;
|
||||
bot->Notice(theClient, "You have an incomplete channel application of %s", chanName.c_str());
|
||||
if (!chanApp->RealName.empty())
|
||||
{
|
||||
bot->Notice(theClient, "So far you've enumerated the following:");
|
||||
bot->Notice(theClient, "Your Real Name: %s", chanApp->RealName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your Real Name by typing /msg %s REGISTER %s REALNAME <Your RealName>", bot->getNickName().c_str(), chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(), chanName.c_str());
|
||||
}
|
||||
if ((!chanApp->RealName.empty()) && (chanApp->Description.empty()))
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your channel's description by typing /msg %s REGISTER %s DESCRIPTION <description>", bot->getNickName().c_str(),chanName.c_str());
|
||||
if (chanApp->supps.empty())
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),chanName.c_str());
|
||||
}
|
||||
if (!chanApp->Description.empty()) bot->Notice(theClient, "Description: %s", chanApp->Description.c_str());
|
||||
if ((!chanApp->RealName.empty()) && (!chanApp->Description.empty()))
|
||||
{
|
||||
bot->Notice(theClient,"Now enumerate your supporters by typing /msg %s REGISTER %s SUPPORTERS <supporter1 supporter2 supporter3 ...>", bot->getNickName().c_str(),chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s", bot->getNickName().c_str(),chanName.c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!hasApp)
|
||||
{
|
||||
if (!bot->isValidChannel(st[1]))
|
||||
{
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
bot->Notice(theClient, "Cannot register, channel is %s",bot->getCurrentValidResponse().c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bot->isValidUser(theUser->getUserName()))
|
||||
{
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
bot->Notice(theClient, "Cannot register, Your username is invalid (%s)",bot->getCurrentValidResponse().c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bot->isValidApplicant(theUser))
|
||||
{
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
if (bot->getCurrentValidResponse() == "TOO_NEW")
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, You can't register new channels at the moment.");
|
||||
bot->Notice(theClient, "Your username must have been created since at least %i days in order to apply for a new channel.",bot->MinDaysBeforeReg);
|
||||
bot->validResponseString.clear();
|
||||
return false;
|
||||
}
|
||||
if (bot->getCurrentValidResponse() == "ALREADY_HAVE_CHAN")
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, you already have a channel registered to you");
|
||||
bot->Notice(theClient, "You can only register \002ONE\002 channel.");
|
||||
bot->validResponseString.clear();
|
||||
return false;
|
||||
}
|
||||
if (bot->getCurrentValidResponse() == "ALREADY_HAVE_PENDINGCHAN")
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, you already have a channel pending registration to you");
|
||||
bot->Notice(theClient, "You can only register \002ONE\002 channel.");
|
||||
bot->validResponseString.clear();
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, bot->getCurrentValidResponse().c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
} //end of isValidApplicant
|
||||
|
||||
//The instant registration case
|
||||
if (bot->RequiredSupporters == 0)
|
||||
{
|
||||
if (bot->sqlRegisterChannel(bot->getInstance(), theUser, st[1].c_str()))
|
||||
{
|
||||
sqlChannel* newChan = bot->getChannelRecord(st[1]);
|
||||
bot->logAdminMessage("%s (%s) has registered %s to %s", bot->getNickName().c_str(),
|
||||
bot->getInstance()->getNickUserHost().c_str(), st[1].c_str(), theUser->getUserName().c_str());
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::regged_chan,
|
||||
string("Registered channel %s to %s")).c_str(), st[1].c_str(), theUser->getUserName().c_str());
|
||||
//return true;
|
||||
} else {
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
bot->Notice(theClient, bot->validResponseString.c_str());
|
||||
bot->logDebugMessage("The Judge Failed to (instant) register channel %s with reason:", st[1].c_str());
|
||||
bot->logDebugMessage(bot->validResponseString.c_str());
|
||||
bot->validResponseString.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//bot->logDebugMessage("Entering REGISTER.CheckReclaimQuery");
|
||||
//Add the registration query into the db (fresh insert, or reclaim)
|
||||
//Check if the channel exists in the 'channels' table with the registered_ts=0 than it was wiped,
|
||||
//and we need to do a reclaim
|
||||
bool reclaim = false;
|
||||
int chanId = bot->getPendingChanId(st[1]);
|
||||
if (chanId) reclaim = true;
|
||||
|
||||
if (reclaim)
|
||||
{
|
||||
bot->wipeChannel(chanId);
|
||||
stringstream theQuery;
|
||||
theQuery << "UPDATE channels SET name = '"
|
||||
<< escapeSQLChars(st[1])
|
||||
<< "', mass_deop_pro=0, flood_pro=0, flags=0, limit_offset=3, "
|
||||
<< "limit_period=20, limit_grace=1, limit_max=0, userflags=0, "
|
||||
<< "url='', description='', keywords='', registered_ts=0, "
|
||||
<< "channel_ts=0, channel_mode='', comment='', last_updated=date_part('epoch', CURRENT_TIMESTAMP)::int "
|
||||
<< "WHERE id = " << chanId
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{
|
||||
bot->logDebugMessage("Error on REGISTER.DoReclaimQuery");
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "REGISTER.DoReclaimQuery> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
} //else bot->logDebugMessage("Successfully reclaimed channel %s", st[1].c_str());
|
||||
}
|
||||
else //reclaim
|
||||
{
|
||||
stringstream theQuery;
|
||||
theQuery << "INSERT INTO channels (name,url,description,keywords,registered_ts,"
|
||||
<< "channel_ts,channel_mode,comment,last_updated,mass_deop_pro,flood_pro,"
|
||||
<< "flags,limit_offset,limit_period,limit_grace,limit_max,userflags"
|
||||
<< ") VALUES ('"
|
||||
<< escapeSQLChars(st[1])
|
||||
<< "','','','',0,0,'','',date_part('epoch', CURRENT_TIMESTAMP)::int,0,0,0,3,20,1,0,0)"
|
||||
<< ends;
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{
|
||||
bot->logDebugMessage("Error on REGISTER.InsertIntoQuery");
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "REGISTER.InsertIntoQuery> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{ //Also here we need to find out the new channels's id
|
||||
chanId = bot->getPendingChanId(st[1]);
|
||||
//bot->logDebugMessage("Successfully inserted new channel %s with id = %i", st[1].c_str(), chanId);
|
||||
}
|
||||
}
|
||||
|
||||
sqlIncompleteChannel* newApp = new (std::nothrow) sqlIncompleteChannel(bot->SQLDb);
|
||||
assert(newApp != 0);
|
||||
|
||||
bot->incompleteChanRegs.insert(cservice::incompleteChanRegsType::value_type(theUser->getID(),newApp));
|
||||
|
||||
newApp->chanName = st[1];
|
||||
newApp->chanId = chanId;
|
||||
if (!newApp->commitNewPending(theUser->getID(), chanId))
|
||||
{
|
||||
bot->logDebugMessage("Error on REGISTER.commitNewPending");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Ask after the Real Name
|
||||
bot->Notice(theClient,"Now specify your Real Name by typing /msg %s REGISTER %s REALNAME <Your RealName>", bot->getNickName().c_str(), st[1].c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(), st[1].c_str());
|
||||
return true;
|
||||
} //end of !hasApp, begin of hasApp
|
||||
|
||||
string chanName = chanApp->chanName; //bot->getPendingChanName(chanApp->chanId);
|
||||
string option;
|
||||
if (st.size() < 3) //No option specified, so we enumearate the current state
|
||||
{
|
||||
if (!chanApp->RealName.empty())
|
||||
{
|
||||
bot->Notice(theClient, "So far you've enumerated the following:");
|
||||
bot->Notice(theClient, "Your Real Name: %s", chanApp->RealName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your Real Name by typing /msg %s REGISTER %s REALNAME <Your RealName>", bot->getNickName().c_str(), chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(), chanName.c_str());
|
||||
}
|
||||
if ((!chanApp->RealName.empty()) && (chanApp->Description.empty()))
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your channel's description by typing /msg %s REGISTER %s DESCRIPTION <description>", bot->getNickName().c_str(),chanName.c_str());
|
||||
if (chanApp->supps.empty())
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),chanName.c_str());
|
||||
}
|
||||
if (!chanApp->Description.empty()) bot->Notice(theClient, "Description: %s", chanApp->Description.c_str());
|
||||
if ((!chanApp->RealName.empty()) && (!chanApp->Description.empty()))
|
||||
{
|
||||
bot->Notice(theClient,"Now enumerate your supporters by typing /msg %s REGISTER %s SUPPORTERS <supporter1 supporter2 supporter3 ...>", bot->getNickName().c_str(),chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s", bot->getNickName().c_str(),chanName.c_str());
|
||||
}
|
||||
}
|
||||
if (st.size() > 2) option = string_upper(st[2]);
|
||||
if (option == "DESC") option = "DESCRIPTION";
|
||||
if (option == "REALNAME")
|
||||
{
|
||||
string mngrName = st.assemble(3);
|
||||
if ((mngrName.size() < 2) || (mngrName.size() > 80))
|
||||
{
|
||||
bot->Notice(theClient,"Your realname must be 2 - 80 charcters long. Try again");
|
||||
return true;
|
||||
}
|
||||
chanApp->RealName = mngrName;
|
||||
chanApp->commitRealName();
|
||||
if (chanApp->Description.empty())
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your channel's description by typing /msg %s REGISTER %s DESCRIPTION <description>", bot->getNickName().c_str(),chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),chanName.c_str());
|
||||
return true;
|
||||
}
|
||||
if (chanApp->supps.empty())
|
||||
{
|
||||
bot->Notice(theClient,"Now enumerate your supporters by typing /msg %s REGISTER %s SUPPORTERS <supporter1 supporter2 supporter3 ...>", bot->getNickName().c_str(),chanName.c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),chanName.c_str());
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (option == "DESCRIPTION")
|
||||
{
|
||||
string desc = st.assemble(3);
|
||||
if ((desc.size() < 2) || (desc.size() > 300))
|
||||
{
|
||||
bot->Notice(theClient,"Your description must be 2 - 300 charcters long. Try again");
|
||||
return true;
|
||||
}
|
||||
chanApp->Description = desc;
|
||||
chanApp->commitDesc();
|
||||
if (chanApp->RealName.empty())
|
||||
{
|
||||
bot->Notice(theClient,"Now specify your Real Name by typing /msg %s REGISTER %s REALNAME <Your RealName>", bot->getNickName().c_str(), chanName.c_str());//st[1].c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(), chanName.c_str());//st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
if (chanApp->supps.empty())
|
||||
{
|
||||
bot->Notice(theClient,"Now enumerate your supporters by typing /msg %s REGISTER %s SUPPORTERS <supporter1 supporter2 supporter3 ...>", bot->getNickName().c_str(),st[1].c_str());
|
||||
bot->Notice(theClient,"To cancel/abort your application any time, type /msg %s CANCEL %s YES", bot->getNickName().c_str(),st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check the validity of the list of the supporters
|
||||
if (option == "SUPPORTERS")
|
||||
{
|
||||
for (unsigned int i = chanApp->supps.size(); i < bot->RequiredSupporters; i++)
|
||||
{
|
||||
string suppUserName;
|
||||
if (st.size() > (i+3)) suppUserName = st[3+i]; else suppUserName.empty();
|
||||
if ((suppUserName.empty()) && (i < bot->RequiredSupporters))
|
||||
{
|
||||
bot->Notice(theClient,"You need to enumerate %i supporters in order to complete your channel application.", bot->RequiredSupporters);
|
||||
return false;
|
||||
}
|
||||
sqlUser* suppUser = bot->getUserRecord(suppUserName);
|
||||
if (!suppUser)
|
||||
{
|
||||
bot->Notice(theClient, "Supporter \002%s\002 is Inexistent. Please check if you spelt the username correctly and try again.",suppUserName.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!bot->isValidUser(suppUserName))
|
||||
{
|
||||
bot->Notice(theClient,"Invalid supporter %s (%s)", suppUser->getUserName().c_str(), bot->getCurrentValidResponse().c_str());
|
||||
return false;
|
||||
}
|
||||
if (suppUser == theUser)
|
||||
{
|
||||
bot->Notice(theClient, "You cannot enumerate yourself as a supporter.");
|
||||
return false;
|
||||
}
|
||||
if (!bot->isValidSupporter(suppUserName))
|
||||
if (!bot->validResponseString.empty())
|
||||
{
|
||||
if (bot->getCurrentValidResponse() == "NEVER_LOGGED")
|
||||
{
|
||||
bot->Notice(theClient, "Supporter \002%s\002 has never logged in.", suppUser->getUserName().c_str());
|
||||
bot->Notice(theClient, "All your supporters must login to %s on IRC to apply to register a channel.",bot->getNickName().c_str());
|
||||
return false;
|
||||
}
|
||||
if (bot->getCurrentValidResponse() == "TOO_NEW")
|
||||
{
|
||||
bot->Notice(theClient, "Supporter \002%s\002 is too newly created.", suppUser->getUserName().c_str());
|
||||
bot->Notice(theClient, "All your supporters must login to %s on IRC at least %i days before to apply to register a channel.",bot->getNickName().c_str(), bot->MinDaysBeforeSupport);
|
||||
return false;
|
||||
}
|
||||
if (bot->getCurrentValidResponse() == "SEEN_LONG_AGO")
|
||||
{
|
||||
bot->Notice(theClient, "Supporter \002%s\002 was seen too long ago.", suppUser->getUserName().c_str());
|
||||
bot->Notice(theClient, "All your supporters must login to %s on IRC at least 21 days ago to apply to register a channel.", bot->getNickName().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sqlIncompleteChannel::supporterListType::iterator ptr = chanApp->supps.find(suppUser->getID());
|
||||
if (ptr != chanApp->supps.end())
|
||||
{
|
||||
bot->Notice(theClient, "Supporter \002%s\002 is enumerated multiple times", ptr->second->getUserName().c_str());
|
||||
chanApp->supps.clear();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
chanApp->supps.insert(sqlIncompleteChannel::supporterListType::value_type(suppUser->getID(),suppUser));
|
||||
}
|
||||
chanApp->commitSupporters();
|
||||
delete(chanApp); chanApp = 0;
|
||||
bot->incompleteChanRegs.erase(theUser->getID());
|
||||
|
||||
//We cannot write to a non existing NULL sqlChannel, so we nedd to create:
|
||||
unsigned int channel_ts = 0;
|
||||
Channel* tmpChan = Network->findChannel(chanName);
|
||||
channel_ts = tmpChan ? tmpChan->getCreationTime() : ::time(NULL);
|
||||
theChan = new (std::nothrow) sqlChannel(bot->SQLDb);
|
||||
theChan->setName(chanName);
|
||||
theChan->setChannelTS(channel_ts);
|
||||
theChan->setRegisteredTS(bot->currentTime());
|
||||
theChan->setChannelMode("+tn");
|
||||
theChan->setLastUsed(bot->currentTime());
|
||||
|
||||
bot->writeChannelLog(theChan, theClient, sqlChannel::EV_NEWAPP, "by " + theUser->getUserName());
|
||||
|
||||
bot->logAdminMessage("New channel application %s by (%s) %s", st[1].c_str(), theUser->getUserName().c_str(), theClient->getRealNickUserHost().c_str());
|
||||
bot->Notice(theClient,"Your application has been recorded.");
|
||||
bot->Notice(theClient,"Please allow 10-12 days for processing");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* REHASHCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: REHASHCommand.cc,v 1.6 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char REHASHCommand_cc_rcsId[] = "$Id: REHASHCommand.cc,v 1.6 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool REHASHCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.REHASH");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) return false;
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level < level::rehash_admin)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
string option = string_upper(st[1]);
|
||||
|
||||
if (option == "MOTD")
|
||||
{
|
||||
int lastupdate = bot->rehashMOTD();
|
||||
if (lastupdate > 0) {
|
||||
bot->Notice(theClient, "Done. Rehashed the MOTD, last updated %s ago.",
|
||||
prettyDuration(lastupdate).c_str(), lastupdate);
|
||||
return true;
|
||||
} else {
|
||||
bot->Notice(theClient, "Couldn't update the MOTD.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (option == "HELP")
|
||||
{
|
||||
bot->helpTable.clear();
|
||||
bot->loadHelpTable();
|
||||
bot->Notice(theClient, "Done. %i entries in help table.",
|
||||
bot->helpTable.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Options below require a higher level to rehash */
|
||||
if (level < level::rehash_coder)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option == "TRANSLATIONS")
|
||||
{
|
||||
bot->languageTable.clear();
|
||||
bot->translationTable.clear();
|
||||
bot->loadTranslationTable();
|
||||
bot->Notice(theClient, "Done. %i entries in language table.",
|
||||
bot->translationTable.size());
|
||||
}
|
||||
|
||||
if (option == "CONFIG")
|
||||
{
|
||||
bot->configTable.clear();
|
||||
bot->loadConfigData();
|
||||
bot->Notice(theClient, "Done. %i entries in config table.",
|
||||
bot->configTable.size());
|
||||
// TODO: Free up the memory allocated in building this table ;)
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,228 @@
|
||||
/**
|
||||
* REJECTCommand.cc
|
||||
*
|
||||
* 07/05/2012 - Gergo Focze <gergo_f@yahoo.com>
|
||||
* Initial Version.
|
||||
*
|
||||
* Channel reject command from IRC
|
||||
*
|
||||
* 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 <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char REJECTCommand_cc_rcsId[] = "$Id: REJECTCommand.cc,v 1.16 2012/05/07 19:23:36 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool REJECTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.REJECT");
|
||||
|
||||
string decision;
|
||||
string mngrUserName;
|
||||
unsigned int chanId;
|
||||
int level = 0;
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (theUser) level = bot->getAdminAccessLevel(theUser);
|
||||
if (level == 0) return true; //don't show anything to normal users ;)
|
||||
StringTokenizer st( Message ) ;
|
||||
if ( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
if (!theUser) return false;
|
||||
|
||||
/*
|
||||
* First, check the channel is registered/real.
|
||||
*/
|
||||
|
||||
if ( (st[1][0] != '#') )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_chan_name,
|
||||
string("Invalid channel name.")));
|
||||
return false;
|
||||
}
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_already_reg,
|
||||
string("%s is already registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (level < level::reject)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
decision = st.assemble(2);
|
||||
if (decision.size() > 300)
|
||||
{
|
||||
bot->Notice(theClient,"Decision cannot exceed 300 charcters.");
|
||||
return false;
|
||||
}
|
||||
decision = "by CService Admin<br>" + decision;
|
||||
stringstream theQuery;
|
||||
unsigned int lastdays = (unsigned int)bot->currentTime() - ((unsigned int)bot->daySeconds*5);
|
||||
/********** Channel ID query ***********/
|
||||
theQuery << "SELECT id,status FROM channels,pending WHERE "
|
||||
<< "channels.registered_ts = 0 AND lower(channels.name) = '"
|
||||
<< escapeSQLChars(string_lower(st[1]))
|
||||
<< "'"
|
||||
<< " AND channels.id = pending.channel_id AND (pending.decision_ts=0 OR (pending.decision_ts>0 AND pending.decision_ts>="
|
||||
<< lastdays
|
||||
<< "))"
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on REJECT.pending.status query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "REJECT.pending.status query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
chanId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
unsigned short status = atoi(bot->SQLDb->GetValue(0,1));
|
||||
if (status == 9)
|
||||
{ bot->Notice(theClient,"Channel %s is already rejected.",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
if (status == 3) //Accepted, so channel was previously Rejected
|
||||
{
|
||||
bot->Notice(theClient,"Channel %s is not in my applications list",st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
if ((status > 3) and (status < 8)) return false;
|
||||
//if ((status == 0) or (status == 1) or (status == 2) or (status == 8))
|
||||
/********** Update pending status ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "UPDATE pending SET status=9,last_updated=date_part('epoch', CURRENT_TIMESTAMP)::int,decision_ts=date_part('epoch', CURRENT_TIMESTAMP)::int,reviewed='Y',decision='"
|
||||
<< decision
|
||||
<< "',reviewed_by_id="
|
||||
<< theUser->getID()
|
||||
<<" WHERE channel_id="
|
||||
<< chanId
|
||||
//<< " AND (status='0' OR status='1' OR status='2' OR status='8')" //AND created_ts='
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on REJECT.UpdatePending query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "REJECT.UpdatePending query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
/********** Manager ID query ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT manager_id FROM pending WHERE channel_id="
|
||||
<< chanId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on REJECT.Manager_ID query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "REJECT.Manager_ID query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (bot->SQLDb->Tuples() == 0)
|
||||
{
|
||||
bot->logDebugMessage("Result NOT Found REJECT.Manager_ID query");
|
||||
return false;
|
||||
}
|
||||
unsigned int mngrId = atoi(bot->SQLDb->GetValue(0,0));
|
||||
/********** Update users LastSeen last_updated ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "UPDATE users_lastseen SET last_updated=date_part('epoch', CURRENT_TIMESTAMP)::int,last_seen=date_part('epoch', CURRENT_TIMESTAMP)::int WHERE user_id="
|
||||
<< mngrId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on REJECT.UsersLastseen last_updated");
|
||||
#ifdef LOG_SQL
|
||||
elog << "REJECT.UsersLastseen last_updated> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
/********** Manager username query ***********/
|
||||
theQuery.str("");
|
||||
theQuery << "SELECT user_name FROM users WHERE id="
|
||||
<< mngrId
|
||||
<< ends;
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
bot->logDebugMessage("Error on REJECT.Manager UserName Query");
|
||||
#ifdef LOG_SQL
|
||||
elog << "REJECT.Manager UserName Query> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
mngrUserName = bot->SQLDb->GetValue(0,0);
|
||||
bot->logAdminMessage("%s (%s) has rejected %s from %s", theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(), st[1].c_str(), mngrUserName.c_str());
|
||||
bot->Notice(theClient,"Rejected channel %s",st[1].c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,179 @@
|
||||
Newest changes at the top of the file:
|
||||
$Id: RELEASE.NOTES,v 1.31 2003/04/24 20:19:36 gte Exp $
|
||||
|
||||
CMaster 1.1pl13 - 24/04/2003
|
||||
* Allow opers to see the level 500 accesses a user has.
|
||||
|
||||
CMaster 1.1pl12 - 09/01/2003
|
||||
* Change sqlUser->Commit() method to accept an iClient, to ensure
|
||||
that last_updated_by is always set when the record is changed.
|
||||
* Add new methods to fetch config settings from the database instead
|
||||
of config files. (Not ready yet, everything needs to be moved over
|
||||
first).
|
||||
* Fix a typo in SUSPEND/UNSUSPEND syntax help.
|
||||
|
||||
CMaster 1.1pl11 - 24/12/2002
|
||||
* Add some more stats.
|
||||
* Try and update user.last-seen every 12 hours if they're logged in.
|
||||
* Fix some compiler moaning.
|
||||
* Fix a bug in the above auto-update seen code, writing a last-hostmask
|
||||
that may not have previously been cached.
|
||||
* Merry Xmas!
|
||||
|
||||
CMaster 1.1pl10 - 08/12/2002
|
||||
* Added some contributed patches:
|
||||
* Andrew Miller <a1kmm@mware.virtualave.net>
|
||||
* - Fix massdeop suspend bug.
|
||||
*
|
||||
* Alexander Maassen <outsider@key2peace.org>
|
||||
* - Fixed the pesky negative suspend expire issue.
|
||||
* - getResponse defaults to english if response for set language
|
||||
* has not been found.
|
||||
|
||||
CMaster 1.1pl9 - 19/10/2002
|
||||
* Added preloadUserCache - to fetch a few days worth of user
|
||||
accounts into memory before we hit the big +r'd net.burst :)
|
||||
|
||||
CMaster 1.1pl8 - 14/10/2002
|
||||
* Add some new commands for CS Admins to scan last hostmasks/usernames,
|
||||
etc. (Spike)
|
||||
* Don't try and tell a server off for op'ing a suspended user.
|
||||
* Convert the coder-com channel setting to a configuration variable (OUTSider)
|
||||
* Quick tweak to BAN/KICK command to kick users matching the banmask on their real-host,
|
||||
not just their hidden host.
|
||||
|
||||
CMaster 1.1pl7 - 01/04/2002
|
||||
* Added some basic memo-serv functionality. To use,
|
||||
check you have USE_NOTES defined in cservice_config.h
|
||||
and you have added the new "notes" table from cservice.sql
|
||||
to your database. Needs a bit more work/features, but for now
|
||||
its fairly difficult to mass-spam with.
|
||||
* X will now randomly kill a user on the network every 30 minutes
|
||||
until March 31st, 2003. The kill message will be formulated
|
||||
from the various works of Shakespeare.
|
||||
|
||||
CMaster 1.1pl6 - 23/02/2002
|
||||
* Add MAXLOGINS, to specify how many logins you wish to
|
||||
allow to your account at once.
|
||||
* DB Maintainence Required in this release:
|
||||
ALTER TABLE users ADD COLUMN maxlogins INT4 DEFAULT 1;
|
||||
UPDATE users SET maxlogins = 1;
|
||||
|
||||
CMaster 1.1pl5 - 04/12/2001
|
||||
* Remove ancient refrences to floodpro.
|
||||
* Fix case issue with suspend duration units.
|
||||
* Further tweaking to make floating limit less noisey.
|
||||
* Added a "grace" value to the floating limits, the limit will
|
||||
not be reset if the increment is smaller than "grace".
|
||||
* Added a "max" value to the floating limits, the limit will
|
||||
never pass this setting. Usefull to float the limit around
|
||||
and have it max when a chan gets too full, etc.
|
||||
* DB Maintainence Required in this release:
|
||||
ALTER TABLE channels ADD COLUMN limit_grace INT4 DEFAULT '1';
|
||||
ALTER TABLE channels ADD COLUMN limit_max INT4 DEFAULT '0';
|
||||
UPDATE channels SET limit_grace = 1;
|
||||
UPDATE channels SET limit_max = 0;
|
||||
|
||||
CMaster 1.1pl4 - 26/12/2001
|
||||
* Don't auto-part channels marked as SPECIAL.
|
||||
* Add "Floating Limit" support. (Ie: Set the channel +l to X
|
||||
above the total number of people in the channel every Y
|
||||
seconds.
|
||||
* DB Maintainence Required in this release:
|
||||
ALTER TABLE channels ADD COLUMN limit_offset INT4 DEFAULT '3';
|
||||
ALTER TABLE channels ADD COLUMN limit_period INT4 DEFAULT '20';
|
||||
UPDATE channels SET limit_offset = 3;
|
||||
UPDATE channels SET limit_period = 20;
|
||||
|
||||
CMaster 1.1pl3 - 07/12/2001
|
||||
* Make PURGE obey the NOPURGE flag.
|
||||
* Make PURGE automatically remove associated level records
|
||||
from the memory cache and the Db, and also remove flags,
|
||||
description, comments, etc.
|
||||
|
||||
[..TODO..]
|
||||
|
||||
CMaster 1.0pl8 - 25/07/2001
|
||||
* Modify BANLIST so you must have level 1+ in the channel now,
|
||||
however you can view channel bans from outside the channel
|
||||
now.
|
||||
* DB Maintainence to perform with this release:
|
||||
ALTER TABLE levels ADD COLUMN suspend_level INT4 DEFAULT '0';
|
||||
|
||||
CMaster 1.0pl7a - 20/07/2001
|
||||
* Add a new channel flag "LOCKED" to prevent normal
|
||||
users from using SET to modify channel settings.
|
||||
|
||||
CMaster 1.0pl7 - 15/07/2001
|
||||
* Global suspend now logs a few extra details, and unsuspends
|
||||
are now logged/displayed also.
|
||||
|
||||
CMaster 1.0pl6 - 27/06/2001
|
||||
* Disallow globally suspended users op's in registered
|
||||
channels.
|
||||
* New channel setting, "Comments", for admins to note a quick
|
||||
comment that will appear in CHANINFO.
|
||||
|
||||
* DB Maintainence to perform to be compatible with this
|
||||
release:
|
||||
|
||||
ALTER TABLE channels ADD COLUMN comment VARCHAR (300);
|
||||
ALTER TABLE pending ADD COLUMN unique_join_count INT4 DEFAULT '0';
|
||||
ALTER TABLE pending ADD COLUMN managername VARCHAR (80);
|
||||
|
||||
* Global user SUSPEND must now take a reason, in the form:
|
||||
/msg x suspend Plexus You have been assimilated.
|
||||
|
||||
CMaster 1.0pl5 - 20/05/2001
|
||||
* Add Vampire's (Alex Badea <vampire@go.ro>) code to make
|
||||
addition of new languages dynamic.
|
||||
* Prevent core in PURGE when channel doesn't have a manager.
|
||||
(Spotted by Planetarion Network).
|
||||
* New stuff to check traffic for 'Pending' registration
|
||||
channels.
|
||||
* New admin command to quickly remove all users from a
|
||||
channel.
|
||||
* Expire FORCE'd accesses in the hourly maintainence.
|
||||
* Move PART to a level 500 command to prevent abuse.
|
||||
* Decided to move last_seen from the user fetching query
|
||||
* to retrieve only when it is first accessed.
|
||||
|
||||
CMaster 1.0pl4 - 13/04/2001
|
||||
* Added REHASH command handler, to allow dynamic reloading
|
||||
of translation tables.
|
||||
* Fixed a rather obvious ommision that caused a memleak.
|
||||
|
||||
CMaster 1.0pl3 - 03/04/2001
|
||||
|
||||
* Fixed a bug in unsuspend that allowed users to unsuspend
|
||||
people above their access level.
|
||||
* Fixed a bug in suspend that set the duration to seconds
|
||||
when a user attempted to supply a reason.
|
||||
* Added (username) to the levels record when adding a user
|
||||
|
||||
CMaster 1.0pl2 - 18/03/2001
|
||||
|
||||
* Fixed a bug in ban that prevented the correct level being
|
||||
set with a varying number of parameters. (or no reason).
|
||||
* Fixed a bug in AUTOOP on Login, which op'd people in NOOP
|
||||
channels and if they where banned < level 75.
|
||||
* Spotted another old unixtime lying around in LBANLIST.
|
||||
* Make the AUTOOP on Login AUTOVOICE aswell.
|
||||
|
||||
Cmaster 1.0pl1 - 17/03/2001.
|
||||
|
||||
* Masskick no longer effects the person issuing the command.
|
||||
* Channel Keywords now display in the chaninfo command.
|
||||
* A bug that prevented < level 75 bans being set without a reason
|
||||
has been fixed.
|
||||
* A number of bugs relating to people being unable to set autoop/
|
||||
modinfo user accounts has been fixed.
|
||||
* Set 'DESC' will now work as well as set 'DESCRIPTION'.
|
||||
* Idle not-logged in user accounts now expire from the bot's cache
|
||||
hourly.
|
||||
* When you Login, you are now given op's in all channels you are
|
||||
currently in (with AUTOOP on) and have enough access in.
|
||||
* A bug causing duplicate bans being set during a MASSDEOPPRO kick
|
||||
has been resolved.
|
||||
|
||||
Cmaster 1.0 Jan 2001 - Initial Development and release.
|
||||
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* REMIGNORECommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: REMIGNORECommand.cc,v 1.10 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char REMIGNORECommand_cc_rcsId[] = "$Id: REMIGNORECommand.cc,v 1.10 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool REMIGNORECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.REMIGNORE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::remignore)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
for( cservice::silenceListType::iterator ptr = bot->silenceList.begin() ;
|
||||
ptr != bot->silenceList.end() ; ++ptr )
|
||||
{
|
||||
if ( string_lower(st[1]) == string_lower(ptr->first.c_str()) )
|
||||
{
|
||||
stringstream s;
|
||||
s << bot->getCharYYXXX()
|
||||
<< " SILENCE * -"
|
||||
<< ptr->first.c_str()
|
||||
<< ends;
|
||||
bot->Write( s );
|
||||
|
||||
/*
|
||||
* Locate this user by numeric.
|
||||
* If the numeric is still in use, clear the ignored flag.
|
||||
* If someone else has inherited this numeric, no prob,
|
||||
* its cleared anyway.
|
||||
*/
|
||||
|
||||
iClient* netClient = Network->findClient(ptr->second.second);
|
||||
if (netClient)
|
||||
{
|
||||
bot->setIgnored(netClient, false);
|
||||
}
|
||||
|
||||
bot->silenceList.erase(ptr);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::unsilenced,
|
||||
string("Removed %s from my ignore list")).c_str(),
|
||||
st[1].c_str());
|
||||
bot->logAdminMessage("%s (%s) has removed ignore: %s",
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
} // for()
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::couldnt_find_silence,
|
||||
string("Couldn't find %s in my silence list")).c_str(),
|
||||
st[1].c_str());
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* REMOVEALLCommand.
|
||||
*
|
||||
* Quickly clear a channels access list.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: REMOVEALLCommand.cc,v 1.7 2007/08/28 16:10:11 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "responses.h"
|
||||
#include "levels.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char REMOVEALLCommand_cc_rcsId[] = "$Id: REMOVEALLCommand.cc,v 1.7 2007/08/28 16:10:11 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::pair ;
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool REMOVEALLCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.REMOVEALL");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, check the channel is registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if ((!theChan) || (st[1] == "*"))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("%s isn't registered with me")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level < level::removeall)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Now, perform a fast query on the levels table for this channel.
|
||||
*/
|
||||
|
||||
stringstream clearAllQuery;
|
||||
clearAllQuery << "SELECT user_id FROM levels WHERE"
|
||||
<< " channel_id = "
|
||||
<< theChan->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> "
|
||||
<< clearAllQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(clearAllQuery, true ) )
|
||||
//if( status != PGRES_TUPLES_OK )
|
||||
{
|
||||
elog << "REMOVEALL> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate over all the results, checking if this access is in the
|
||||
* cache.
|
||||
* If so, remove it!
|
||||
*/
|
||||
|
||||
int delCounter = bot->SQLDb->Tuples();
|
||||
|
||||
for (unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
pair<int, int> thePair( atoi(bot->SQLDb->GetValue(i, 0)), theChan->getID() );
|
||||
|
||||
cservice::sqlLevelHashType::iterator ptr = bot->sqlLevelCache.find(thePair);
|
||||
if(ptr != bot->sqlLevelCache.end())
|
||||
{
|
||||
/*
|
||||
* Found it in the cache, free the memory and
|
||||
* remove it from the cache.
|
||||
*/
|
||||
|
||||
delete(ptr->second);
|
||||
bot->sqlLevelCache.erase(thePair);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Now the cache is clean, execute some SQL to eradicate the records
|
||||
* from the database.
|
||||
*/
|
||||
|
||||
stringstream deleteAllQuery;
|
||||
deleteAllQuery << "DELETE FROM levels WHERE"
|
||||
<< " channel_id = "
|
||||
<< theChan->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> "
|
||||
<< deleteAllQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if (bot->SQLDb->Exec(deleteAllQuery))
|
||||
{
|
||||
bot->Notice(theClient, "Done. Zapped %i access records from %s",
|
||||
delCounter, theChan->getName().c_str());
|
||||
bot->writeChannelLog(theChan,
|
||||
theClient,
|
||||
sqlChannel::EV_REMOVEALL, "" );
|
||||
} else
|
||||
{
|
||||
bot->Notice(theClient, "A database error occured while removing the access records.");
|
||||
bot->Notice(theClient, "Please contact a database administrator!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
* REMUSERCommand.cc
|
||||
*
|
||||
* 27/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Removes a users access from a particular channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: REMUSERCommand.cc,v 1.19 2010/04/10 18:56:06 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "Network.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "dbHandle.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char REMUSERCommand_cc_rcsId[] = "$Id: REMUSERCommand.cc,v 1.19 2010/04/10 18:56:06 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::pair ;
|
||||
using std::ends ;
|
||||
using std::endl ;
|
||||
using std::string ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool REMUSERCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.REMUSER");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char* queryHeader = "DELETE FROM levels WHERE ";
|
||||
|
||||
stringstream theQuery;
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser) return false;
|
||||
|
||||
/*
|
||||
* First, check the channel is registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan) {
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
sqlUser* targetUser = bot->getUserRecord(st[2]);
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (((level < level::remuser) || ((st[1] == "*") && (level < adminlevel::remuser))) && ((targetUser) && targetUser != theUser))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the person we're trying to remove actually exists.
|
||||
*/
|
||||
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered,
|
||||
string("Sorry, I don't know who %s is.")).c_str(),
|
||||
st[2].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check this user has access on this channel.
|
||||
*/
|
||||
|
||||
sqlLevel* tmpLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
|
||||
if (!tmpLevel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::doesnt_have_access,
|
||||
string("%s doesn't appear to have access in %s.")).c_str(),
|
||||
targetUser->getUserName().c_str(), theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int targetLevel = tmpLevel->getAccess();
|
||||
|
||||
/*
|
||||
* Check we aren't trying to remove someone with access higher than ours.
|
||||
* Unless they are trying to remove themself.. in which case its ok ;)
|
||||
*/
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level <= targetLevel) && (targetUser != theUser))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_rem_higher,
|
||||
string("Cannot remove a user with equal or higher access than your own")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((theChan->getName() == "*") && (targetUser == theUser)) && (!theUser->getFlag(sqlUser::F_POWER)))
|
||||
{
|
||||
/*bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_rem_higher,
|
||||
string("CSC has your soul! YOU CAN NEVER ESCAPE!")));*/
|
||||
bot->Notice(theClient,"CSC has your soul! YOU CAN NEVER ESCAPE!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((targetLevel == 500) && (targetUser == theUser))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_rem_owner_self,
|
||||
string("You can't remove yourself from a channel you own")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, build up the SQL query & execute it!
|
||||
*/
|
||||
theQuery << queryHeader
|
||||
<< "channel_id = " << theChan->getID()
|
||||
<< " AND user_id = " << targetUser->getID()
|
||||
<< ";" << ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> "
|
||||
<< theQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if (bot->SQLDb->Exec(theQuery))
|
||||
// if ((status = bot->SQLDb->Exec(theQuery.str().c_str())) ==
|
||||
//PGRES_COMMAND_OK)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::removed_user,
|
||||
string("Removed user %s from %s")).c_str(),
|
||||
targetUser->getUserName().c_str(), theChan->getName().c_str());
|
||||
if (targetUser != theUser)
|
||||
bot->NoteAllAuthedClients(targetUser, bot->getResponse(targetUser,language::acc_rem).c_str(), theChan->getName().c_str(), theUser->getUserName().c_str());
|
||||
|
||||
if (((theChan->getName() == "*") && (targetUser == theUser)) && (theUser->getFlag(sqlUser::F_POWER)))
|
||||
{
|
||||
bot->Notice(theClient,"CSC is You!! YOU CAN NEVER ESCAPE!");
|
||||
//bot->Notice(theClient,"I will always remember you!");
|
||||
}
|
||||
} else {
|
||||
bot->dbErrorMessage(theClient);
|
||||
}
|
||||
|
||||
/* Remove tmpLevel from the cache. (It has to be there, we just got it even if it wasnt..) */
|
||||
|
||||
pair<int, int> thePair;
|
||||
thePair = std::make_pair(tmpLevel->getUserId(), tmpLevel->getChannelId());
|
||||
bot->sqlLevelCache.erase(thePair);
|
||||
delete(tmpLevel);
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
//if (tmpChan) bot->deopAllUnAuthedOnChan(tmpChan);
|
||||
if (tmpChan) bot->deopSuspendedOnChan(tmpChan,targetUser);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* RENAMECommand.cc
|
||||
*
|
||||
* 10/06/2012 - Gergo Focze <gergo_f@yahoo.com>
|
||||
* Initial Version.
|
||||
*
|
||||
* Admin user rename command from IRC
|
||||
*
|
||||
* 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 <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "dbHandle.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char RENAMECommand_cc_rcsId[] = "$Id: RENAMECommand.cc,v 1.0 2012/06/10 09:25:13 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::pair ;
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace gnuworld;
|
||||
|
||||
bool RENAMECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.RENAME");
|
||||
|
||||
const char validChars[]
|
||||
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
int level = 0;
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (theUser) level = bot->getAdminAccessLevel(theUser);
|
||||
if (level == 0) return true; //don't show anything to normal users ;)
|
||||
StringTokenizer st( Message ) ;
|
||||
if ( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
if (!theUser) return false;
|
||||
|
||||
if (level < level::rename)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlUser* oldUser = bot->getUserRecord(st[1].c_str());
|
||||
if (!oldUser)
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::not_registered).c_str(),st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
string oldUserName = oldUser->getUserName();
|
||||
string newUserName = st[2];
|
||||
|
||||
/*** Check the new usernames validity ***/
|
||||
bool badName = false;
|
||||
|
||||
for( string::const_iterator ptr = newUserName.begin() ;
|
||||
ptr != newUserName.end() ; ++ptr )
|
||||
{
|
||||
/*
|
||||
* 62 entries in the table. 26 + 26 + 10 digits.
|
||||
*/
|
||||
|
||||
bool found = false;
|
||||
for (int f = 0; f < 62; f++)
|
||||
{
|
||||
if(*ptr == validChars[f])
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
badName = true;
|
||||
}
|
||||
}
|
||||
if (badName)
|
||||
{
|
||||
bot->Notice(theClient, "The new useraname must be made of letters (A-Z, a-z) and numbers (0-9).");
|
||||
return false;
|
||||
}
|
||||
|
||||
newUserName = escapeSQLChars(newUserName);
|
||||
|
||||
/*** Check if the new username is already in use ***/
|
||||
sqlUser* newUser = bot->getUserRecord(newUserName);
|
||||
if (newUser)
|
||||
{
|
||||
bot->Notice(theClient, "Username %s already exists!",newUserName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Also Update(rename) the username in the database */
|
||||
stringstream theQuery;
|
||||
theQuery.str("");
|
||||
theQuery << "UPDATE users SET user_name = '"
|
||||
<< newUserName
|
||||
<< "'"
|
||||
<< "WHERE lower(user_name) = '"
|
||||
<< string_lower(oldUserName)
|
||||
<< "'"
|
||||
<< ends;
|
||||
|
||||
if (!bot->SQLDb->Exec(theQuery, true))
|
||||
{
|
||||
#ifdef LOG_SQL
|
||||
//elog << "sqlQuery> " << theQuery.str().c_str() << endl;
|
||||
elog << "RENAME UPDATE SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
#endif
|
||||
bot->logDebugMessage("RENAME UPDATE SQL Error: ",bot->SQLDb->ErrorMessage().c_str());
|
||||
return false;
|
||||
}
|
||||
bot->updateUserCacheUserName(oldUser,newUserName);
|
||||
bot->Notice(theClient,"Successfully renamed username %s to %s",
|
||||
oldUserName.c_str(), newUserName.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* SAYCommand.cc
|
||||
*
|
||||
* 13/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Command to keep Kev happy :)
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SAYCommand.cc,v 1.9 2005/12/01 04:04:59 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "Network.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SAYCommand_cc_rcsId[] = "$Id: SAYCommand.cc,v 1.9 2005/12/01 04:04:59 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool SAYCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SAY");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::say)
|
||||
{
|
||||
/* CSC get far too many questions as to how to use these commands
|
||||
* so they prefer it kept quiet about 'em. Fair enough too.
|
||||
*
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* First, check the channel is registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
/* is this a "say" or "do" command? */
|
||||
if (tmpChan)
|
||||
{
|
||||
if (!match("SAY", st[0]))
|
||||
bot->Message(tmpChan, st.assemble(2));
|
||||
else
|
||||
bot->Message(tmpChan, "%cACTION %s%c",
|
||||
1, st.assemble(2).c_str(), 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* SCANCommand.cc
|
||||
*
|
||||
* Created on: Jan 07, 2016
|
||||
* Author: Seven
|
||||
* gergo_f@yahoo.com
|
||||
*
|
||||
* General purpose scan command:
|
||||
* - Find owner user of a nickname
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* SCANCommand.cc, v 1.0 2016.01.07 - Seven
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "dbHandle.h"
|
||||
#include "Network.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool SCANCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
|
||||
bot->incStat("COMMANDS.SCAN");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string option, value;
|
||||
option = string_upper(st[1]);
|
||||
if (st.size() > 2)
|
||||
value = st[2];
|
||||
|
||||
if ((option == "NICK") || (option == "NICKNAME"))
|
||||
{
|
||||
string nickOwner = bot->NickIsRegisteredTo(value);
|
||||
if (!nickOwner.empty())
|
||||
bot->Notice(theClient, "Nickname is registered to %s", nickOwner.c_str());
|
||||
else
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::no_match).c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} //namespace gnuworld
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* SCANEMAILCommand.cc
|
||||
*
|
||||
* 18/03/11 - Jochen Meesters <ekips@pandora.be>
|
||||
* Initial Version.
|
||||
*
|
||||
* 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 <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool SCANEMAILCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
|
||||
bot->incStat("COMMANDS.SCANEMAIL");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool showAll = false;
|
||||
|
||||
if(st.size() > 2)
|
||||
if(!strcasecmp(st[2],"-all"))
|
||||
showAll = true;
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level < level::scanemail)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
string email = string_lower(st[1]);
|
||||
|
||||
stringstream scanemailQuery;
|
||||
scanemailQuery << "SELECT user_name, email FROM users WHERE "
|
||||
<< "lower(email) LIKE '" << escapeSQLChars(searchSQL(email)) << "' LIMIT 50"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SCANEMAIL::sqlQuery> "
|
||||
<< scanemailQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( scanemailQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SCANEMAIL> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,"Found %i matches", bot->SQLDb->Tuples());
|
||||
|
||||
if( bot->SQLDb->Tuples() >= 50 )
|
||||
{
|
||||
bot->Notice(theClient, "More than 50 matches were found, please visit the website.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if((bot->SQLDb->Tuples() > 15) && (!showAll))
|
||||
{
|
||||
bot->Notice(theClient, "More than 15 matches were found without the use of -all, please visit the website.");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
string username = bot->SQLDb->GetValue(i, 0);
|
||||
string email = bot->SQLDb->GetValue(i, 1);
|
||||
bot->Notice(theClient, "Username: %s -- E-mail: %s", username.c_str(), email.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* SCANHOSTCommand.cc
|
||||
*
|
||||
* 08/10/2002 - Jochen Meesters <ekips@pandora.be>
|
||||
* Initial Version.
|
||||
*
|
||||
* Displays User name, and last hostmask
|
||||
* for users matching the search request.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SCANHOSTCommand.cc,v 1.7 2008/11/12 20:45:42 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool SCANHOSTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
|
||||
bot->incStat("COMMANDS.SCANHOST");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool showAll = false;
|
||||
|
||||
if(st.size() > 2)
|
||||
if(!strcasecmp(st[2],"-all"))
|
||||
showAll = true;
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level < level::scanhost)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
string host = string_lower(st[1]);
|
||||
|
||||
stringstream scanhostQuery;
|
||||
scanhostQuery << "SELECT users.user_name, users_lastseen.last_hostmask, users_lastseen.last_ip FROM users, users_lastseen WHERE "
|
||||
<< "users.id = users_lastseen.user_id AND "
|
||||
<< "(lower(users_lastseen.last_hostmask) LIKE '" << escapeSQLChars(searchSQL(host)) << "'"
|
||||
<< " OR lower(users_lastseen.last_ip) LIKE '" << escapeSQLChars(searchSQL(host)) << "') LIMIT 50"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SCANHOST::sqlQuery> "
|
||||
<< scanhostQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( scanhostQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SCANHOST> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,"Found %i matches", bot->SQLDb->Tuples());
|
||||
|
||||
if( bot->SQLDb->Tuples() >= 50 )
|
||||
{
|
||||
bot->Notice(theClient, "More than 50 matches were found, please visit the website.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if((bot->SQLDb->Tuples() > 15) && (!showAll))
|
||||
{
|
||||
bot->Notice(theClient, "More than 15 matches were found without the use of -all, please visit the website.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* use this to store the SQL result set (querying later would overwrite the results */
|
||||
typedef std::map< std::string, std::string > scanResultsType;
|
||||
scanResultsType scanResults;
|
||||
/* counter for matches not displayed */
|
||||
int matchCount = 0;
|
||||
|
||||
/* store the results in the map defined above */
|
||||
for (unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
string username = bot->SQLDb->GetValue(i, 0);
|
||||
string lasthost = bot->SQLDb->GetValue(i, 1) + " - Last IP: " + bot->SQLDb->GetValue(i, 2);
|
||||
scanResults.insert( std::make_pair(username, lasthost));
|
||||
}
|
||||
|
||||
/* use this for each user record (below) */
|
||||
unsigned short tmpadminLevel;
|
||||
/* iterate through the results, fetching user records for each */
|
||||
for (scanResultsType::const_iterator Itr = scanResults.begin();
|
||||
Itr != scanResults.end(); ++Itr)
|
||||
{
|
||||
string username = Itr->first;
|
||||
string lasthost = Itr->second;
|
||||
|
||||
/* check each user's access for purposes of IP hiding ONLY */
|
||||
sqlUser* tmpUser = bot->getUserRecord(username);
|
||||
if (tmpUser)
|
||||
{
|
||||
/* found user, fetch admin access level */
|
||||
sqlChannel* adminChan = bot->getChannelRecord("*");
|
||||
if (!adminChan)
|
||||
{
|
||||
/* cant find admin channel, assume no access */
|
||||
tmpadminLevel = 0;
|
||||
} else {
|
||||
/* found admin channel, try to get the level record */
|
||||
sqlLevel* adminLev = bot->getLevelRecord(tmpUser, adminChan);
|
||||
if (!adminLev)
|
||||
{
|
||||
/* no level record, assume no access */
|
||||
tmpadminLevel = 0;
|
||||
} else {
|
||||
/* found level record, set it */
|
||||
tmpadminLevel = adminLev->getAccess();
|
||||
}
|
||||
}
|
||||
|
||||
if ((tmpadminLevel>0 || tmpUser->getFlag(sqlUser::F_OPER)) && level<800)
|
||||
{
|
||||
/* increment counter of items not listed */
|
||||
matchCount++;
|
||||
} else {
|
||||
/* display entry */
|
||||
bot->Notice(theClient, "Username: %s -- Last hostmask: %s",
|
||||
username.c_str(), lasthost.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if we have not displayed any users due to IP hiding, explain here */
|
||||
if (matchCount > 0)
|
||||
{
|
||||
bot->Notice(theClient, "-- %d staff accounts matched this search, but were not listed",
|
||||
matchCount);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
scanResults.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* SCANUNAMECommand.cc
|
||||
*
|
||||
* 07/10/2002 - Jochen Meesters <ekips@pandora.be>
|
||||
* Initial Version.
|
||||
*
|
||||
* Displays User name and creation ip
|
||||
* for users matching the search request.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SCANUNAMECommand.cc,v 1.9 2007/08/28 16:10:11 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool SCANUNAMECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
|
||||
bot->incStat("COMMANDS.SCANUNAME");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool showAll = false;
|
||||
|
||||
if(st.size() > 2)
|
||||
if(!strcasecmp(st[2],"-all"))
|
||||
showAll = true;
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level < level::scanuname)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
string uname = string_lower(st[1]);
|
||||
|
||||
stringstream scanunameQuery;
|
||||
scanunameQuery << "SELECT user_name, signup_ip FROM users WHERE "
|
||||
<< "lower(user_name) LIKE '" << escapeSQLChars(searchSQL(uname)) << "' LIMIT 50"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SCANUNAME::sqlQuery> "
|
||||
<< scanunameQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( scanunameQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SCANUNAME> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,"Found %i matches", bot->SQLDb->Tuples());
|
||||
|
||||
if( bot->SQLDb->Tuples() >= 50 )
|
||||
{
|
||||
bot->Notice(theClient, "More than 50 matches were found, please visit the website.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if((bot->SQLDb->Tuples() > 15) && (!showAll))
|
||||
{
|
||||
bot->Notice(theClient, "More than 15 matches were found without the use of -all, please visit the website.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* use this to store the SQL result set (querying later would overwrite the results */
|
||||
typedef std::map< std::string, std::string > scanResultsType;
|
||||
scanResultsType scanResults;
|
||||
|
||||
/* store the results in the map defined above */
|
||||
for (unsigned int i = 0; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
string username = bot->SQLDb->GetValue(i, 0);
|
||||
string signupip = bot->SQLDb->GetValue(i, 1);
|
||||
|
||||
scanResults.insert( std::make_pair(username, signupip));
|
||||
}
|
||||
|
||||
/* use this for each user record (below) */
|
||||
unsigned short tmpadminLevel;
|
||||
|
||||
/* iterate through the results, fetching user records for each */
|
||||
for (scanResultsType::const_iterator Itr = scanResults.begin();
|
||||
Itr != scanResults.end(); ++Itr)
|
||||
{
|
||||
string username = Itr->first;
|
||||
string signupip = Itr->second;
|
||||
|
||||
/* check each user's access for purposes of IP hiding ONLY */
|
||||
sqlUser* tmpUser = bot->getUserRecord(username);
|
||||
if (tmpUser)
|
||||
{
|
||||
/* found user, fetch admin access level */
|
||||
sqlChannel* adminChan = bot->getChannelRecord("*");
|
||||
if (!adminChan)
|
||||
{
|
||||
/* cant find admin channel, assume no access */
|
||||
tmpadminLevel = 0;
|
||||
} else {
|
||||
/* found admin channel, try to get the level record */
|
||||
sqlLevel* adminLev = bot->getLevelRecord(tmpUser, adminChan);
|
||||
if (!adminLev)
|
||||
{
|
||||
/* no level record, assume no access */
|
||||
tmpadminLevel = 0;
|
||||
} else {
|
||||
/* found level record, set it */
|
||||
tmpadminLevel = adminLev->getAccess();
|
||||
}
|
||||
}
|
||||
bot->Notice(theClient, "Username: %s -- Signup ip: %s", username.c_str(),
|
||||
((tmpadminLevel>0 || tmpUser->getFlag(sqlUser::F_OPER)) && level<800)?"Not Available":signupip.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
scanResults.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* SEARCHCommand.cc
|
||||
*
|
||||
* 11/02/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Command written, and finished.
|
||||
*
|
||||
* Searches through the registered channels list, for a matching string in the channels'
|
||||
* keywords. Max 10 matches will be outputted.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SEARCHCommand.cc,v 1.11 2007/08/28 16:10:11 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "dbHandle.h"
|
||||
#include "responses.h"
|
||||
#include "cservice_config.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char SEARCHCommand_cc_rcsId[] = "$Id: SEARCHCommand.cc,v 1.11 2007/08/28 16:10:11 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
static const char* queryHeader = "SELECT channels.name,channels.keywords FROM channels ";
|
||||
static const char* queryCondition = "WHERE channels.keywords ~* ";
|
||||
static const char* queryFooter = "ORDER BY channels.name DESC LIMIT 100;";
|
||||
|
||||
bool SEARCHCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SEARCH");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
int chanLimit = 0;
|
||||
bool doChanLimit = false;
|
||||
bool doneChanLimit = false;
|
||||
|
||||
unsigned int posOfSearch = 1;
|
||||
for( StringTokenizer::const_iterator ptr = st.begin() ; ptr != st.end() ;
|
||||
++ptr )
|
||||
{
|
||||
if ((string_lower(*ptr) == "-min") && !doChanLimit)
|
||||
{
|
||||
doChanLimit = true;
|
||||
posOfSearch++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!doneChanLimit && doChanLimit)
|
||||
{
|
||||
chanLimit = atoi( (*ptr).c_str() );
|
||||
doneChanLimit = true;
|
||||
posOfSearch++;
|
||||
}
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string matchString = st.assemble(posOfSearch);
|
||||
|
||||
if (matchString.empty())
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t results = 0;
|
||||
|
||||
stringstream extraCond;
|
||||
extraCond << "'"
|
||||
<< escapeSQLChars(matchString)
|
||||
<< "' "
|
||||
<< ends;
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << queryHeader
|
||||
<< queryCondition
|
||||
<< extraCond.str().c_str()
|
||||
<< queryFooter
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SEARCH::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec(theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SEARCH> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
for( unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++ )
|
||||
{
|
||||
/*
|
||||
* Look to see if the channel exists in memory.
|
||||
*/
|
||||
Channel* tmpChan = Network->findChannel(bot->SQLDb->GetValue(i, 0));
|
||||
|
||||
/*
|
||||
* Yes it does, if we have specified a minimum level of users on the chan,
|
||||
* lets make sure we don't show quiet chans.
|
||||
*/
|
||||
|
||||
int chanMembers = -1;
|
||||
if(tmpChan) chanMembers = tmpChan->size();
|
||||
|
||||
if(chanMembers >= chanLimit)
|
||||
{
|
||||
results++;
|
||||
bot->Notice(theClient, "\026%-14s \026 - %s (%i users)",
|
||||
bot->SQLDb->GetValue(i, 0).c_str(),
|
||||
bot->SQLDb->GetValue(i, 1).c_str(),
|
||||
chanMembers);
|
||||
}
|
||||
|
||||
if(results >= MAX_SEARCH_RESULTS)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::exc_search,
|
||||
string("There are more than %i entries matching [%s]")).c_str(),
|
||||
MAX_SEARCH_RESULTS,
|
||||
matchString.c_str()
|
||||
);
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::restrict_search,
|
||||
string("Please restrict your search mask")).c_str()
|
||||
);
|
||||
break;
|
||||
}
|
||||
} // for()
|
||||
|
||||
if( 0 == results )
|
||||
{
|
||||
if(!chanLimit)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::no_search_match,
|
||||
string("No matching entries for [%s]")).c_str(),
|
||||
matchString.c_str() );
|
||||
} else {
|
||||
bot->Notice(theClient, "No matching entries for [%s] with a minimum of %i users.",
|
||||
matchString.c_str(), chanLimit);
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* SERVNOTICECommand.cc
|
||||
*
|
||||
* 03/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Sends a server notice to a channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SERVNOTICECommand.cc,v 1.5 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SERVNOTICECommand_cc_rcsId[] = "$Id: SERVNOTICECommand.cc,v 1.5 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::map ;
|
||||
|
||||
bool SERVNOTICECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SERVNOTICE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient admin access to do this.
|
||||
*/
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::servnotice)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(st[1]);
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
string theMessage = st.assemble(2);
|
||||
bot->serverNotice(tmpChan, "%s", theMessage.c_str());
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* SHOWCOMMANDSCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SHOWCOMMANDSCommand.cc,v 1.40 2012/05/08 20:02:09 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SHOWCOMMANDSCommand_cc_rcsId[] = "$Id: SHOWCOMMANDSCommand.cc,v 1.40 2012/05/08 20:02:09 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
static const char* lvl_1000_cmds = "\002Level 1000\002: anything";
|
||||
static const char* lvl_900_cmds = "\002Level 900\002: shutdown rehash";
|
||||
static const char* lvl_800_cmds = "\002Level 800\002: say servnotice";
|
||||
static const char* lvl_750_cmds = "\002Level 750\002: accept reject register purge removeall";
|
||||
static const char* lvl_600_cmds = "\002Level 600\002: remignore addcomment scanhost scanuname scanemail";
|
||||
|
||||
static const char* lvl_500_cmds = "\002Level 500\002: part";
|
||||
static const char* lvl_450_cmds = "\002Level 450\002: join set%s*";
|
||||
static const char* lvl_400_cmds = "\002Level 400\002: adduser clearmode* modinfo+ remuser";
|
||||
static const char* lvl_100_cmds = "\002Level 100\002: op deop invite suspend unsuspend";
|
||||
static const char* lvl_75_cmds = "\002Level 75\002: ban* unban*";
|
||||
static const char* lvl_50_cmds = "\002Level 50\002: kick%s topic";
|
||||
static const char* lvl_42_cmds = "\002Level 42\002: PANIC";
|
||||
static const char* lvl_25_cmds = "\002Level 25\002: voice devoice";
|
||||
static const char* lvl_1_cmds = "\002Level 1\002: banlist status%s";
|
||||
static const char* lvl_adm_cmds = "\002Level *\002: force unforce stats";
|
||||
static const char* lvl_0_cmds = "\002Level 0\002: access chaninfo info object help* lbanlist login motd* newpass showcommands showignore verify suspendme";
|
||||
|
||||
#ifdef USE_OPERPARTJOIN
|
||||
static const char* lvl_oper_cmds = "\002Level Oper\002: operjoin* operpart*";
|
||||
#else
|
||||
static const char* lvl_oper_cmds = "\002Level Oper\002: ";
|
||||
#endif
|
||||
|
||||
bool SHOWCOMMANDSCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SHOWCOMMANDS");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2)
|
||||
{
|
||||
bot->Notice(theClient, lvl_0_cmds);
|
||||
if(theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient, lvl_oper_cmds);
|
||||
}
|
||||
// bot->Notice(theClient, cmdFooter);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if (!theUser)
|
||||
{
|
||||
bot->Notice(theClient, lvl_0_cmds);
|
||||
if(theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient, lvl_oper_cmds);
|
||||
}
|
||||
// bot->Notice(theClient, cmdFooter);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the users access level.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
int admin = bot->getAdminAccessLevel(theUser);
|
||||
|
||||
if (level >= 1000) bot->Notice(theClient, lvl_1000_cmds);
|
||||
if (level >= 900) bot->Notice(theClient, lvl_900_cmds);
|
||||
if (level >= 800) bot->Notice(theClient, lvl_800_cmds);
|
||||
if (level >= 750) bot->Notice(theClient, lvl_750_cmds);
|
||||
if (level >= 600) bot->Notice(theClient, lvl_600_cmds);
|
||||
if (level >= 500) bot->Notice(theClient, lvl_500_cmds);
|
||||
if (level >= 450) bot->Notice(theClient, lvl_450_cmds,
|
||||
(level>=500) ? "+" : "");
|
||||
if (level >= 400) bot->Notice(theClient, lvl_400_cmds);
|
||||
if (level >= 100) bot->Notice(theClient, lvl_100_cmds);
|
||||
if (level >= 75) bot->Notice(theClient, lvl_75_cmds);
|
||||
if (level >= 50) bot->Notice(theClient, lvl_50_cmds,
|
||||
(level>=200) ? "+" : "");
|
||||
if (level == 42) bot->Notice(theClient, lvl_42_cmds);
|
||||
if (level >= 25) bot->Notice(theClient, lvl_25_cmds);
|
||||
if (level >= 1) bot->Notice(theClient, lvl_1_cmds,
|
||||
(level>=200||admin>0||theClient->isOper()) ? "+" : "");
|
||||
|
||||
if (admin >= level::force)
|
||||
{
|
||||
bot->Notice(theClient, lvl_adm_cmds);
|
||||
}
|
||||
|
||||
bot->Notice(theClient, lvl_0_cmds);
|
||||
if (theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient, lvl_oper_cmds);
|
||||
}
|
||||
// bot->Notice(theClient, cmdFooter);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* SHOWIGNORECommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SHOWIGNORECommand.cc,v 1.13 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SHOWIGNORECommand_cc_rcsId[] = "$Id: SHOWIGNORECommand.cc,v 1.13 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool SHOWIGNORECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SHOWIGNORE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 1 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
|
||||
// TODO: Violation of encapsulation
|
||||
if( bot->silenceList.empty() )
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::ignore_list_empty,
|
||||
string("Ignore list is empty")));
|
||||
return true ;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::ignore_list_start,
|
||||
string("Ignore list:")));
|
||||
|
||||
// TODO: Same as above
|
||||
for( cservice::silenceListType::const_iterator ptr = bot->silenceList.begin() ;
|
||||
ptr != bot->silenceList.end() ; ++ptr )
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::rpl_ignorelist, "%s for %i minutes").c_str(),
|
||||
ptr->first.c_str(),
|
||||
(((ptr->second.first - bot->currentTime()) / 60) % 60));
|
||||
count++;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::ignore_list_end,
|
||||
string("-- End of Ignore List")));
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* SHUTDOWNCommand.cc
|
||||
*
|
||||
* 28/12/2001 - Matthias Crauwels <ultimate_@wol.be>
|
||||
* Initial Version.
|
||||
*
|
||||
* Shuts down the bot and squits the server
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SHUTDOWNCommand.cc,v 1.8 2005/01/08 23:33:42 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SHUTDOWNCommand_cc_rcsId[] = "$Id: SHUTDOWNCommand.cc,v 1.8 2005/01/08 23:33:42 dan_karrels Exp $" ;
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool SHUTDOWNCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SHUTDOWN");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::shutdown)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
bot->logAdminMessage("%s issued the shutdown command! So long, and thanks for all the fish!", theClient->getNickName().c_str());
|
||||
|
||||
server->Shutdown( st.assemble( 1 ) ) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* STATSCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: STATSCommand.cc,v 1.7 2003/08/09 23:15:35 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char STATSCommand_cc_rcsId[] = "$Id: STATSCommand.cc,v 1.7 2003/08/09 23:15:35 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool STATSCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.STATS");
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, false);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((st.size() < 2) && (bot->getAdminAccessLevel(theUser) < 800)) return false;
|
||||
|
||||
if (st.size() >= 2)
|
||||
{
|
||||
/*
|
||||
* We have a parameter, lets do something interesting with it!
|
||||
*/
|
||||
|
||||
/* Don't show if they don't have any admin or coder-com access. */
|
||||
if ((st[1] == "*") && ((bot->getAdminAccessLevel(theUser)) || (bot->getCoderAccessLevel(theUser))))
|
||||
{
|
||||
bot->doCoderStats(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(st[1][0] == '#')
|
||||
{
|
||||
/*
|
||||
* Dump loads of internal info about this channel.
|
||||
*/
|
||||
Channel* tmpChan = Network->findChannel(st[1]);
|
||||
if(!tmpChan) { bot->Notice(theClient, "That channel doesn't exist on the network :("); return true; }
|
||||
|
||||
cservice::pendingChannelListType::iterator ptr = bot->pendingChannelList.find(tmpChan->getName());
|
||||
|
||||
if(ptr != bot->pendingChannelList.end())
|
||||
{
|
||||
sqlPendingChannel* tmpPending = ptr->second;
|
||||
bot->Notice(theClient, "---- Pending channel stats for %s ----", ptr->first.c_str());
|
||||
bot->Notice(theClient, "Channel ID: %i", tmpPending->channel_id);
|
||||
bot->Notice(theClient, "Join Count: %i", tmpPending->join_count);
|
||||
bot->Notice(theClient, "Unique Join Count: %i", tmpPending->unique_join_count);
|
||||
|
||||
|
||||
|
||||
bot->Notice(theClient, "# of entries in supporter list: %i", tmpPending->supporterList.size());
|
||||
|
||||
sqlPendingChannel::supporterListType::iterator sPtr = tmpPending->supporterList.begin();
|
||||
|
||||
for( ; sPtr != tmpPending->supporterList.end() ; ++sPtr )
|
||||
{
|
||||
bot->Notice(theClient, " - User ID: %i, Join count: %i", sPtr->first, sPtr->second);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bot->Notice(theClient, "# of entries in IP traffic checker list: %i", tmpPending->trafficList.size());
|
||||
|
||||
sqlPendingChannel::trafficListType::iterator tPtr = tmpPending->trafficList.begin();
|
||||
for( ; tPtr != tmpPending->trafficList.end() ; ++tPtr )
|
||||
{
|
||||
bot->Notice(theClient, " - IP #: %i (Channel ID: %i) (Join Count: %i)",
|
||||
tPtr->second->ip_number, tPtr->second->channel_id, tPtr->second->join_count);
|
||||
}
|
||||
} else {
|
||||
bot->Notice(theClient, "Channel doesn't have a pending application.");
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* Have a look to see if this is a server first..
|
||||
*/
|
||||
iServer* theServer = Network->findServerName( st[1] ) ;
|
||||
if(theServer)
|
||||
{
|
||||
bot->Notice(theClient, "Server: %s", theServer->getName().c_str());
|
||||
bot->Notice(theClient, " - Numeric: %s",
|
||||
theServer->getCharYY().c_str());
|
||||
bot->Notice(theClient, " - Connect Time: %i", theServer->getConnectTime());
|
||||
bot->Notice(theClient, " - Still Bursting? %s", theServer->isBursting() ? "Yes" : "No");
|
||||
}
|
||||
}
|
||||
|
||||
bot->Notice(theClient, "-- End of STATS");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bot->Notice(theClient, "CMaster Command/SQL Query Statistics:");
|
||||
for( cservice::statsMapType::iterator ptr = bot->statsMap.begin();
|
||||
ptr != bot->statsMap.end() ; ++ptr )
|
||||
{
|
||||
bot->Notice(theClient, "%s: %i", ptr->first.c_str(), ptr->second);
|
||||
}
|
||||
|
||||
bot->Notice(theClient, "-- End of STATS");
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/**
|
||||
* STATUSCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: STATUSCommand.cc,v 1.48 2007/12/26 20:38:57 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char STATUSCommand_cc_rcsId[] = "$Id: STATUSCommand.cc,v 1.48 2007/12/26 20:38:57 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::cout ;
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool STATUSCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.STATUS");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
if (st[1] == "*")
|
||||
{
|
||||
/*
|
||||
* Special case, display admin stat(u)s. - of all logged official stuff (Seven)
|
||||
*/
|
||||
|
||||
/* Don't show if they don't have any admin or coder-com access. */
|
||||
if (!bot->getAdminAccessLevel(theUser) && !bot->getCoderAccessLevel(theUser))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
//bot->doCoderStats(theClient); //moved to STATS * (Seven)
|
||||
bot->showAdmins(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
|
||||
// Let authenticated admins view status also.
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
|
||||
if ((level < level::status) && (admLevel <= 0) && !theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Display some fancy info about the channel.
|
||||
*/
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
|
||||
if (tmpChan)
|
||||
{
|
||||
// If the person has access >200, or is a 1+ admin (or and Oper).
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::status_chan_info,
|
||||
string("Channel %s has %d users (%i operators)")).c_str(),
|
||||
tmpChan->getName().c_str(),
|
||||
tmpChan->size(),
|
||||
bot->countChanOps(tmpChan) ) ;
|
||||
if ((level >= 200) || (admLevel >= 1) || theClient->isOper())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::status_mode,
|
||||
string("Mode is: %s")).c_str(),
|
||||
tmpChan->getModeString().c_str() ) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Are we on this channel?
|
||||
*/
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient, "I'm \002not\002 in this channel.");
|
||||
} else
|
||||
{
|
||||
bot->Notice(theClient, "I'm currently in this channel.");
|
||||
}
|
||||
|
||||
} // if( tmpChan )
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient, "I'm \002not\002 in this channel.");
|
||||
}
|
||||
|
||||
|
||||
bot->Notice(theClient, "MassDeopPro: %i", theChan->getMassDeopPro());
|
||||
|
||||
string flagsSet;
|
||||
if (admLevel > 0)
|
||||
{
|
||||
/* only "*" access can view certain flags */
|
||||
if (theChan->getFlag(sqlChannel::F_NOPURGE)) flagsSet += "NOPURGE ";
|
||||
if (theChan->getFlag(sqlChannel::F_SPECIAL)) flagsSet += "SPECIAL ";
|
||||
if (theChan->getFlag(sqlChannel::F_NOREG)) flagsSet += "NOREG ";
|
||||
if (theChan->getFlag(sqlChannel::F_NEVREG)) flagsSet += "NEVERREG ";
|
||||
if (theChan->getFlag(sqlChannel::F_CAUTION)) flagsSet += "CAUTION ";
|
||||
if (theChan->getFlag(sqlChannel::F_LOCKED)) flagsSet += "LOCKED ";
|
||||
if (theChan->getFlag(sqlChannel::F_NOFORCE)) flagsSet += "NOFORCE ";
|
||||
if (theChan->getFlag(sqlChannel::F_MIA)) flagsSet += "MIA ";
|
||||
}
|
||||
/* anyone with access can view the rest of the flags (below) */
|
||||
if (theChan->getFlag(sqlChannel::F_SUSPEND)) flagsSet += "SUSPEND ";
|
||||
if (theChan->getFlag(sqlChannel::F_TEMP)) flagsSet += "TEMP ";
|
||||
if (theChan->getFlag(sqlChannel::F_VACATION)) flagsSet += "VACATION ";
|
||||
if (theChan->getFlag(sqlChannel::F_ALWAYSOP)) flagsSet += "ALWAYSOP ";
|
||||
if (theChan->getFlag(sqlChannel::F_STRICTOP)) flagsSet += "STRICTOP ";
|
||||
if (theChan->getFlag(sqlChannel::F_NOOP)) flagsSet += "NOOP ";
|
||||
if (theChan->getFlag(sqlChannel::F_NOVOICE)) flagsSet += "NOVOICE ";
|
||||
if (theChan->getFlag(sqlChannel::F_AUTOTOPIC)) flagsSet += "AUTOTOPIC ";
|
||||
if (theChan->getFlag(sqlChannel::F_AUTOJOIN)) flagsSet += "AUTOJOIN ";
|
||||
if (((level >= level::set::notake) || (admLevel)) &&
|
||||
(theChan->getFlag(sqlChannel::F_NOTAKE)))
|
||||
{
|
||||
flagsSet += "NOTAKE (REV:";
|
||||
if (theChan->getNoTake() == 1) flagsSet += "IGNORE)";
|
||||
if (theChan->getNoTake() == 2) flagsSet += "BAN)";
|
||||
if (theChan->getNoTake() == 3) flagsSet += "SUSPEND)";
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::status_flags,
|
||||
string("Flags set: %s")).c_str(),flagsSet.c_str());
|
||||
|
||||
flagsSet.clear();
|
||||
|
||||
if (theChan->getFlag(sqlChannel::F_FLOATLIM))
|
||||
{
|
||||
stringstream floatLim;
|
||||
floatLim
|
||||
<< " FLOATLIM (MGN:"
|
||||
<< theChan->getLimitOffset()
|
||||
<< ", PRD:"
|
||||
<< theChan->getLimitPeriod()
|
||||
<< ", GRC:"
|
||||
<< theChan->getLimitGrace()
|
||||
<< ", MAX:"
|
||||
<< theChan->getLimitMax()
|
||||
<< ") "
|
||||
<< ends;
|
||||
flagsSet += floatLim.str().c_str();
|
||||
}
|
||||
/* show userflags (if not 'NONE') */
|
||||
if (theChan->getUserFlags() == 1) flagsSet += "USERFLAGS=OP ";
|
||||
else if (theChan->getUserFlags() == 2) flagsSet += "USERFLAGS=VOICE ";
|
||||
|
||||
bot->Notice(theClient,flagsSet.c_str());
|
||||
|
||||
/*
|
||||
* Get a list of authenticated users on this channel.
|
||||
*/
|
||||
|
||||
stringstream authQuery;
|
||||
authQuery << "SELECT users.user_name,levels.access FROM "
|
||||
<< "users,levels WHERE users.id = levels.user_id "
|
||||
<< "AND levels.channel_id = "
|
||||
<< theChan->getID()
|
||||
<< " ORDER BY levels.access DESC"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlQuery> "
|
||||
<< authQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( authQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "STATUS> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
string authList;
|
||||
string nextPerson;
|
||||
|
||||
bool showNick = false;
|
||||
|
||||
for (unsigned int i = 0 ; i < bot->SQLDb->Tuples(); i++)
|
||||
{
|
||||
/*
|
||||
* Look up this username in the cache.
|
||||
*/
|
||||
|
||||
cservice::sqlUserHashType::iterator ptr =
|
||||
bot->sqlUserCache.find(bot->SQLDb->GetValue(i, 0));
|
||||
|
||||
if(ptr != bot->sqlUserCache.end())
|
||||
{
|
||||
sqlUser* currentUser = ptr->second;
|
||||
if( !currentUser->isAuthed() )
|
||||
{
|
||||
continue ;
|
||||
}
|
||||
|
||||
nextPerson += bot->SQLDb->GetValue(i, 0);
|
||||
nextPerson += "/\002";
|
||||
|
||||
/*
|
||||
* Only show the online nickname if that person is in the target
|
||||
* channel.
|
||||
*
|
||||
* Loop around all people auth'd as this nick and append their nicks
|
||||
*/
|
||||
for( sqlUser::networkClientListType::iterator ptr = currentUser->networkClientList.begin() ;
|
||||
ptr != currentUser->networkClientList.end() ; ++ptr )
|
||||
{
|
||||
iClient* tmpClient = (*ptr);
|
||||
|
||||
showNick = false;
|
||||
|
||||
/* If we have admin access, always show the nick's of auth'd users. */
|
||||
showNick = admLevel;
|
||||
|
||||
/* Only show the nick of the client if he's actually in the channel */
|
||||
if (tmpChan) showNick = (tmpChan->findUser(tmpClient) || admLevel);
|
||||
|
||||
if (showNick)
|
||||
{
|
||||
nextPerson += "";
|
||||
nextPerson += tmpClient->getNickName();
|
||||
nextPerson += " ";
|
||||
}
|
||||
}
|
||||
|
||||
nextPerson += "\002[";
|
||||
nextPerson += bot->SQLDb->GetValue(i, 1);
|
||||
nextPerson += "] ";
|
||||
|
||||
/*
|
||||
* Will this string overflow our Notice buffer?
|
||||
* If so, dump it now..
|
||||
*/
|
||||
if(nextPerson.size() + authList.size() > 400)
|
||||
{
|
||||
bot->Notice(theClient, "Auth: %s", authList.c_str());
|
||||
authList.erase( authList.begin(), authList.end() );
|
||||
}
|
||||
|
||||
/*
|
||||
* Add it on to our list.
|
||||
*/
|
||||
|
||||
authList += nextPerson;
|
||||
nextPerson.erase( nextPerson.begin(), nextPerson.end() );
|
||||
}
|
||||
|
||||
|
||||
} // for()
|
||||
|
||||
bot->Notice(theClient, "Auth: %s", authList.c_str());
|
||||
|
||||
/*
|
||||
* Finally(!) display a quick list of everyone 'forced' on the
|
||||
* channel.
|
||||
*/
|
||||
|
||||
if (admLevel >= 1)
|
||||
{
|
||||
for(sqlChannel::forceMapType::const_iterator ptr = theChan->forceMap.begin();
|
||||
ptr != theChan->forceMap.end(); ++ptr)
|
||||
{
|
||||
if ((!theChan->getFlag(sqlChannel::F_NOFORCE)) || (admLevel >= level::immune::noforce))
|
||||
{
|
||||
bot->Notice(theClient, "Force: %s (%i)",
|
||||
ptr->second.second.c_str(), ptr->second.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (admLevel > level::admin::admin)
|
||||
{
|
||||
bot->Notice(theClient, "DB TS: %i -- IRC TS: %i",
|
||||
theChan->getChannelTS(), tmpChan ? tmpChan->getCreationTime() : 0 );
|
||||
}
|
||||
*/
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,411 @@
|
||||
/**
|
||||
* SUPPORTCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SUPPORTCommand.cc,v 1.9 2007/08/28 16:10:11 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
|
||||
const char SUPPORTCommand_cc_rcsId[] = "$Id: SUPPORTCommand.cc,v 1.9 2007/08/28 16:10:11 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool SUPPORTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SUPPORT");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string support = st[2];
|
||||
|
||||
/*
|
||||
* First, check they can type the command correctly.
|
||||
*/
|
||||
|
||||
char supportChar = '?';
|
||||
|
||||
if (string_lower(support) == "no")
|
||||
{
|
||||
supportChar = 'N';
|
||||
} else if (string_lower(support) == "yes")
|
||||
{
|
||||
supportChar = 'Y';
|
||||
} else
|
||||
{
|
||||
bot->Notice(theClient, "Valid SUPPORT choices are YES and NO.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Next, check to see if this channel is actually pending.
|
||||
*/
|
||||
|
||||
string channelName = st[1];
|
||||
|
||||
stringstream theQuery;
|
||||
|
||||
theQuery << "SELECT channels.id FROM pending,channels"
|
||||
<< " WHERE lower(channels.name) = '"
|
||||
<< escapeSQLChars(string_lower(channelName))
|
||||
<< "'"
|
||||
<< " AND channels.id = pending.channel_id"
|
||||
<< " AND pending.status = 0"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SUPPORTCommand> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (bot->SQLDb->Tuples() <= 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"The channel %s doesn't appear to have a pending application. Please ensure you have spelt the name correctly.",
|
||||
channelName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* So it is, lets check they haven't already voiced their support about this channel.
|
||||
*/
|
||||
|
||||
unsigned int channel_id = atoi(bot->SQLDb->GetValue(0, 0));
|
||||
|
||||
stringstream supQuery;
|
||||
supQuery << "SELECT support FROM supporters"
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< " AND user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< supQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( supQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SUPPORTCommand> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (bot->SQLDb->Tuples() <= 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"You don't appear to be listed as a supporter in %s, please ensure you have spelt the channel name correctly.",
|
||||
channelName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
string currentSupport = bot->SQLDb->GetValue(0, 0);
|
||||
|
||||
if ((currentSupport == "Y") || (currentSupport == "N"))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"You have already made your decision on supporting %s, you cannot change it.",
|
||||
channelName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save the changes.
|
||||
*/
|
||||
|
||||
stringstream updateQuery;
|
||||
updateQuery << "UPDATE supporters SET support = '"
|
||||
<< supportChar
|
||||
<< "'"
|
||||
<< ", last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int"
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< " AND user_id = "
|
||||
<< theUser->getID()
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< updateQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( updateQuery ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "SUPPORTCommand> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
|
||||
bot->Notice(theClient, "An Error occured whilst processing your support. Please contact a CService Administrator.");
|
||||
return false ;
|
||||
}
|
||||
|
||||
bot->Notice(theClient, "Done. Set your support for %s to %s.",
|
||||
channelName.c_str(), support.c_str());
|
||||
|
||||
bot->logDebugMessage("%s has set their support for %s to %c.",
|
||||
theUser->getUserName().c_str(), channelName.c_str(), supportChar);
|
||||
|
||||
/*
|
||||
* Right, now if they've voted "YES", and there are 10 supporters who have said YES
|
||||
* we move this to traffic check stage.
|
||||
*/
|
||||
|
||||
if (supportChar == 'Y')
|
||||
{
|
||||
/*
|
||||
* Check to see if all people have said 'Yes'.
|
||||
*/
|
||||
|
||||
stringstream tenQuery;
|
||||
tenQuery << "SELECT support FROM supporters"
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< tenQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( tenQuery, true ) )
|
||||
// if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SUPPORTCommand> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool allSupporting = true;
|
||||
|
||||
/*
|
||||
* Iterate over the results, if just one of the
|
||||
* supporter records isn't a Y, then its not
|
||||
* yet passed.
|
||||
*/
|
||||
|
||||
string support;
|
||||
int supporterCount = bot->SQLDb->Tuples();
|
||||
if (supporterCount < bot->RequiredSupporters) return false;
|
||||
|
||||
for (int i = 0 ; i < supporterCount; i++)
|
||||
{
|
||||
support = bot->SQLDb->GetValue(i,0);
|
||||
if (support != "Y") allSupporting = false;
|
||||
}
|
||||
|
||||
if (allSupporting)
|
||||
{
|
||||
stringstream updatePendingQuery;
|
||||
updatePendingQuery << "UPDATE pending SET status = '1',"
|
||||
<< " last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int,"
|
||||
<< " check_start_ts = date_part('epoch', CURRENT_TIMESTAMP)::int"
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< " AND status = '0'"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< updatePendingQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->SQLDb->Exec( updatePendingQuery.str().c_str() ) ;
|
||||
bot->logDebugMessage("%s has just made it to traffic check phase with %i supporters.",
|
||||
channelName.c_str(), supporterCount);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, if they don't support it - deny this application, and do all sorts
|
||||
* of other stuff.
|
||||
*/
|
||||
|
||||
if (supportChar == 'N')
|
||||
{
|
||||
/*
|
||||
* Reject the application.
|
||||
*/
|
||||
|
||||
stringstream updatePendingQuery;
|
||||
updatePendingQuery << "UPDATE pending SET status = '9',"
|
||||
<< " last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int,"
|
||||
<< " decision_ts = date_part('epoch', CURRENT_TIMESTAMP)::int,"
|
||||
<< " decision = '--AUTOMATIC (REGPROC)-- NON-SUPPORT'"
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< " AND status = '0'"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< updatePendingQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->SQLDb->Exec( updatePendingQuery.str().c_str() ) ;
|
||||
bot->logDebugMessage("%s has just been declined due to non-support.",
|
||||
channelName.c_str());
|
||||
|
||||
/*
|
||||
* Now, add some non-support entries.
|
||||
* First, get the username and email address of the channel manager.
|
||||
*/
|
||||
|
||||
stringstream mgrQuery;
|
||||
mgrQuery << "SELECT user_name,email FROM users,pending"
|
||||
<< " WHERE pending.manager_id = users.id "
|
||||
<< " AND pending.channel_id = "
|
||||
<< channel_id
|
||||
<< " AND pending.status = '9'"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< mgrQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( mgrQuery, true ) )
|
||||
// if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "SUPPORTCommand> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// TODO: Comparing unsigned against 0
|
||||
if(bot->SQLDb->Tuples() > 0)
|
||||
{
|
||||
string managerName = bot->SQLDb->GetValue(0,0);
|
||||
string managerEmail = bot->SQLDb->GetValue(0,1);
|
||||
int noregTime = bot->JudgeDaySeconds * bot->NoRegDaysOnNOSupport;
|
||||
static const char* cmdHeader = "INSERT INTO noreg (user_name,email,channel_name,type,expire_time,created_ts,set_by,reason) VALUES ";
|
||||
|
||||
stringstream noregQuery;
|
||||
noregQuery << cmdHeader
|
||||
<< "('', '','"
|
||||
<< escapeSQLChars(channelName) << "',"
|
||||
// << "1, (date_part('epoch', CURRENT_TIMESTAMP)::int + (86400*3)), date_part('epoch', CURRENT_TIMESTAMP)::int, '* REGPROC', '-NON SUPPORT-'"
|
||||
<< "1, (date_part('epoch', CURRENT_TIMESTAMP)::int + ("
|
||||
<< noregTime
|
||||
<< ")), date_part('epoch', CURRENT_TIMESTAMP)::int, '* REGPROC', '-NON SUPPORT-'"
|
||||
<< ")" << ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< noregQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->SQLDb->Exec( noregQuery.str().c_str() ) ;
|
||||
|
||||
/*
|
||||
* Add a user-based noreg entry too.
|
||||
*/
|
||||
|
||||
stringstream usernoregQuery;
|
||||
usernoregQuery << cmdHeader
|
||||
<< "('"
|
||||
<< escapeSQLChars(managerName) << "', '"
|
||||
<< escapeSQLChars(managerEmail) << "', "
|
||||
<< "'', "
|
||||
//<< "1, (date_part('epoch', CURRENT_TIMESTAMP)::int + (86400*3)), date_part('epoch', CURRENT_TIMESTAMP)::int, '* REGPROC', '-NON SUPPORT-'"
|
||||
<< "1, (date_part('epoch', CURRENT_TIMESTAMP)::int + ("
|
||||
<< noregTime
|
||||
<< ")), date_part('epoch', CURRENT_TIMESTAMP)::int, '* REGPROC', '-NON SUPPORT-'"
|
||||
<< ")" << ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< usernoregQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->SQLDb->Exec( usernoregQuery.str().c_str() ) ;
|
||||
|
||||
/*
|
||||
* Sigh, and a channel-log entry!
|
||||
*/
|
||||
|
||||
stringstream clogQuery;
|
||||
clogQuery << "INSERT INTO channellog (ts, channelid, event, message, last_updated) VALUES ("
|
||||
<< "date_part('epoch', CURRENT_TIMESTAMP)::int, "
|
||||
<< channel_id << ", "
|
||||
<< "1, 'Non-support by "
|
||||
<< escapeSQLChars(theUser->getUserName()) << "', "
|
||||
<< "date_part('epoch', CURRENT_TIMESTAMP)::int)"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "SUPPORTCommand::sqlQuery> "
|
||||
<< clogQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
bot->SQLDb->Exec( clogQuery.str().c_str() ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,365 @@
|
||||
/**
|
||||
* SUSPENDCommand.cc
|
||||
*
|
||||
* 06/01/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version, done with a fever :/
|
||||
*
|
||||
* Suspends an user on the specified channel, if suspend duration 0
|
||||
* is defined, the user will be unsuspended.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SUSPENDCommand.cc,v 1.29 2010/04/10 18:56:06 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SUSPENDCommand_cc_rcsId[] = "$Id: SUSPENDCommand.cc,v 1.29 2010/04/10 18:56:06 danielaustin Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool SUSPENDCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SUSPEND");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Is the user authenticated? */
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if(!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Trying to suspend a user, or a channel?
|
||||
* If there is no #, check this person's admin access..
|
||||
* If it passes, we can suspend a whole user account. <g>
|
||||
*/
|
||||
|
||||
if ((st[1][0] != '#') && (st[1][0] != '*'))
|
||||
{
|
||||
/* Got enough admin access? */
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level == 0)
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
if ((level > 0) && (level < level::globalsuspend))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Does this user account even exist? */
|
||||
sqlUser* targetUser = bot->getUserRecord(st[1]);
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::not_registered,
|
||||
string("I don't know who %s is")).c_str(),
|
||||
st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the target's admin access, if its >= ours, don't
|
||||
* allow it. :)
|
||||
*/
|
||||
|
||||
int targetLevel = bot->getAdminAccessLevel(targetUser);
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (targetLevel >= level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::suspend_access_higher,
|
||||
string("Cannot suspend a user with equal or higher access than your own.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (targetUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
bot->Notice(theClient, "%s is already suspended, you could always try execution?",
|
||||
targetUser->getUserName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Suspend them.
|
||||
targetUser->setFlag(sqlUser::F_GLOBAL_SUSPEND);
|
||||
targetUser->commit(theClient);
|
||||
bot->Notice(theClient, "%s has been globally suspended and will have level 0 access in all"
|
||||
" channels until unsuspended.",
|
||||
targetUser->getUserName().c_str());
|
||||
|
||||
if ((theUser->getFlag(sqlUser::F_POWER)) && (targetUser == theUser))
|
||||
bot->Notice(theClient,"CSC is You!! YOU CAN NEVER ESCAPE!");
|
||||
|
||||
targetUser->writeEvent(sqlUser::EV_SUSPEND, theUser, st.assemble(2));
|
||||
|
||||
//Deop the all newly suspended clients
|
||||
for (sqlUser::networkClientListType::iterator cliPtr = targetUser->networkClientList.begin();
|
||||
cliPtr != targetUser->networkClientList.end() ; ++cliPtr )
|
||||
{
|
||||
for (iClient::channelIterator chItr = (*cliPtr)->channels_begin(); chItr != (*cliPtr)->channels_end(); ++chItr)
|
||||
{
|
||||
ChannelUser* theChannelUser = (*chItr)->findUser(*cliPtr);
|
||||
sqlChannel* theChan = bot->getChannelRecord((*chItr)->getName());
|
||||
if ((theChan) && (theChannelUser->getMode(ChannelUser::MODE_O)))
|
||||
{
|
||||
sqlLevel* tmpLevel = bot->getLevelRecord(targetUser, theChan);
|
||||
if (tmpLevel)
|
||||
{
|
||||
std::pair<int, int> thePair;
|
||||
thePair = std::make_pair(tmpLevel->getUserId(), tmpLevel->getChannelId());
|
||||
bot->sqlLevelCache.erase(thePair);
|
||||
delete(tmpLevel);
|
||||
}
|
||||
bot->deopSuspendedOnChan(*chItr,targetUser);
|
||||
}
|
||||
}
|
||||
if (targetUser->getLanguageId() == 8)
|
||||
bot->Notice((*cliPtr),"Userul tau a fost suspendat global.");
|
||||
else
|
||||
bot->Notice((*cliPtr),"Your user account has been globally suspended.");
|
||||
}
|
||||
|
||||
bot->logAdminMessage("%s (%s) has globally suspended %s's user account.",
|
||||
theClient->getNickName().c_str(), theUser->getUserName().c_str(),
|
||||
targetUser->getUserName().c_str());
|
||||
|
||||
return true;
|
||||
} //end of Global user suspend, begin channel suspend
|
||||
|
||||
if( st.size() < 4 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Is the channel registered? */
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check level. */
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
int suspendLevel = level;
|
||||
if ((level < level::suspend) || (( st[1] == "*" ) && (level < adminlevel::suspend)))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check whether the user is in the access list. */
|
||||
sqlUser* Target = bot->getUserRecord(st[2]);
|
||||
if(!Target)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::not_registered,
|
||||
string("I don't know who %s is")).c_str(),
|
||||
st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
int usrLevel = bot->getAccessLevel(Target, theChan);
|
||||
if(!usrLevel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::doesnt_have_access,
|
||||
string("%s doesn't appear to have access in %s.")).c_str(),
|
||||
Target->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level <= usrLevel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::suspend_access_higher,
|
||||
string("Cannot suspend a user with equal or higher access than your own.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t finalDuration;
|
||||
string suspReason;
|
||||
|
||||
if (!IsTimeSpec(st[3])) //this means only a reason was specified, no duration, no level and we use the defaults
|
||||
{
|
||||
suspReason = st.assemble(3);
|
||||
finalDuration = 3 * 3600;
|
||||
}
|
||||
else finalDuration = extractTime(st[3], 60);
|
||||
|
||||
/* If we have a length at least of 5, then if the 5th param is a number then it is the susp level
|
||||
* else the reason is specified
|
||||
*/
|
||||
if ((st.size() > 4) && (suspReason.empty()))
|
||||
{
|
||||
if (IsNumeric(st[4])) suspendLevel = atoi(st[4].c_str());
|
||||
else suspReason = st.assemble(4);
|
||||
}
|
||||
|
||||
if ((st.size() > 5) && (suspReason.empty()))
|
||||
{
|
||||
suspReason = st.assemble(5);
|
||||
}
|
||||
/* Greater than a year? */
|
||||
if(finalDuration > 32140800 || finalDuration < 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::inval_suspend_dur,
|
||||
string("Invalid suspend duration.")));
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlLevel* aLevel = bot->getLevelRecord(Target, theChan);
|
||||
if (suspReason.empty()) suspReason = "No reason supplied.";
|
||||
|
||||
if( 0 == finalDuration )
|
||||
{
|
||||
if (theUser->getFlag(sqlUser::F_POWER)) level = bot->getAdminAccessLevel(theUser);
|
||||
/*
|
||||
* Was this suspension set with a higher suspend level?
|
||||
*/
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (aLevel->getSuspendLevel() > level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"Cannot unsuspend a user that was suspended at a higher level than your own access.");
|
||||
return false;
|
||||
}
|
||||
if ((suspReason.size() < 2) || (suspReason.size() > 300))
|
||||
{
|
||||
//bot->Notice(theClient,"Your reason must be 2 - 300 charcters long.");
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::reason_must).c_str(),2,300);
|
||||
return false;
|
||||
}
|
||||
aLevel->setSuspendLevel(0);
|
||||
aLevel->setSuspendExpire(finalDuration);
|
||||
aLevel->setSuspendBy(string());
|
||||
aLevel->setSuspendReason(suspReason);
|
||||
aLevel->setLastModif(bot->currentTime());
|
||||
aLevel->setLastModifBy( string( "("
|
||||
+ theUser->getUserName()
|
||||
+ ") "
|
||||
+ theClient->getNickUserHost() ) );
|
||||
|
||||
if( !aLevel->commit() )
|
||||
{
|
||||
bot->Notice( theClient,
|
||||
"Error updating channel status." );
|
||||
elog << "UNSUSPEND> SQL error"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::susp_cancelled,
|
||||
string("SUSPENSION for %s is cancelled")).c_str(),
|
||||
Target->getUserName().c_str());
|
||||
if (Target != theUser)
|
||||
bot->NoteAllAuthedClients(Target, bot->getResponse(Target,language::acc_unsusp).c_str(), theChan->getName().c_str());
|
||||
|
||||
return true;
|
||||
} //end of (0 == finalDuration) (unsuspend)
|
||||
|
||||
if (aLevel->getSuspendExpire() > bot->currentTime())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::already_susp,
|
||||
string("%s is already suspended on %s")).c_str(),
|
||||
Target->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((suspReason.size() < 2) || (suspReason.size() > 300))
|
||||
{
|
||||
//bot->Notice(theClient,"Your reason must be 2 - 300 charcters long.");
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::reason_must).c_str(),2,300);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((suspendLevel > level) || (suspendLevel > 500) || (suspendLevel <= 0))
|
||||
suspendLevel = level;
|
||||
|
||||
aLevel->setSuspendExpire(finalDuration + bot->currentTime());
|
||||
aLevel->setSuspendBy(theClient->getNickUserHost());
|
||||
aLevel->setSuspendLevel(suspendLevel);
|
||||
aLevel->setSuspendReason(suspReason);
|
||||
aLevel->setLastModif(bot->currentTime());
|
||||
aLevel->setLastModifBy( string( "("
|
||||
+ theUser->getUserName()
|
||||
+ ") "
|
||||
+ theClient->getNickUserHost() ) );
|
||||
|
||||
aLevel->commit();
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (tmpChan) bot->deopSuspendedOnChan(tmpChan,Target);
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::susp_set,
|
||||
string("SUSPENSION for %s will expire in %s")).c_str(),
|
||||
Target->getUserName().c_str(),
|
||||
prettyDuration(bot->currentTime() - finalDuration ).c_str());
|
||||
if (Target != theUser)
|
||||
bot->NoteAllAuthedClients(Target, bot->getResponse(Target,language::acc_susp).c_str(), theChan->getName().c_str());
|
||||
|
||||
if ((theUser->getFlag(sqlUser::F_POWER)) && (Target == theUser))
|
||||
bot->Notice(theClient,"CSC is You!! YOU CAN NEVER ESCAPE!");
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* SUSPENDMECommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: SUSPENDMECommand.cc,v 1.4 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char SUSPENDMECommand_cc_rcsId[] = "$Id: SUSPENDMECommand.cc,v 1.4 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool SUSPENDMECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.SUSPENDME");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check password, if its wrong, bye bye.
|
||||
*/
|
||||
|
||||
if (!bot->isPasswordRight(theUser, st.assemble(1)))
|
||||
{
|
||||
bot->Notice(theClient, "Self-suspension failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (theUser->networkClientList.size() <= 1)
|
||||
{
|
||||
bot->Notice(theClient, "Self-suspension failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(theUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
bot->Notice(theClient, "Self-suspension failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Suspend them.
|
||||
theUser->setFlag(sqlUser::F_GLOBAL_SUSPEND);
|
||||
theUser->commit(theClient);
|
||||
|
||||
//Deop the all newly suspended clients
|
||||
for (sqlUser::networkClientListType::iterator cliPtr = theUser->networkClientList.begin();
|
||||
cliPtr != theUser->networkClientList.end() ; ++cliPtr )
|
||||
{
|
||||
for (iClient::channelIterator chItr = (*cliPtr)->channels_begin(); chItr != (*cliPtr)->channels_end(); ++chItr)
|
||||
{
|
||||
ChannelUser* theChannelUser = (*chItr)->findUser(*cliPtr);
|
||||
sqlChannel* theChan = bot->getChannelRecord((*chItr)->getName());
|
||||
if ((theChan) && (theChannelUser->getMode(ChannelUser::MODE_O)))
|
||||
{
|
||||
sqlLevel* tmpLevel = bot->getLevelRecord(theUser, theChan);
|
||||
if (tmpLevel)
|
||||
{
|
||||
std::pair<int, int> thePair;
|
||||
thePair = std::make_pair(tmpLevel->getUserId(), tmpLevel->getChannelId());
|
||||
bot->sqlLevelCache.erase(thePair);
|
||||
delete(tmpLevel);
|
||||
}
|
||||
bot->deopSuspendedOnChan(*chItr,theUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bot->Notice(theClient, "You have been globally suspended and will have level 0 access in all"
|
||||
" channels until you are unsuspended by a CService administrator.");
|
||||
|
||||
theUser->writeEvent(sqlUser::EV_SUSPEND, theUser, "Self-Suspension");
|
||||
|
||||
bot->logAdminMessage("%s (%s) has globally suspended their own account.",
|
||||
theClient->getNickUserHost().c_str(), theUser->getUserName().c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* TOPICCommand.cc
|
||||
*
|
||||
* 26/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* 30/12/2000 - David Henriksen <david@itwebnet.dk>
|
||||
* Wrote TOPIC Command.
|
||||
*
|
||||
* Sets a topic in the channel.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: TOPICCommand.cc,v 1.13 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "Network.h"
|
||||
|
||||
const char TOPICCommand_cc_rcsId[] = "$Id: TOPICCommand.cc,v 1.13 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool TOPICCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.TOPIC");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if(!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if(level < level::topic)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cannot set topic, if the bot hasn't joined.
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if(!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Done with the checking.
|
||||
|
||||
string topic = st.assemble(2);
|
||||
|
||||
// Default ircu TOPICLEN - maxusername?
|
||||
// TODO: Put into config somewhere
|
||||
if( topic.size() > 145 )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::topic_max_len,
|
||||
string("ERROR: Topic cannot exceed 145 chars")));
|
||||
return false;
|
||||
}
|
||||
|
||||
stringstream s;
|
||||
s << bot->getCharYYXXX()
|
||||
<< " T "
|
||||
<< st[1]
|
||||
<< " :("
|
||||
<< theUser->getUserName()
|
||||
<< ") "
|
||||
<< topic
|
||||
<< ends;
|
||||
|
||||
bot->Write( s );
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,311 @@
|
||||
/**
|
||||
* UNBANCommand.cc
|
||||
*
|
||||
* 13/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Unbans a user from a channel.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: UNBANCommand.cc,v 1.22 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "match.h"
|
||||
#include "cidr.h"
|
||||
|
||||
const char UNBANCommand_cc_rcsId[] = "$Id: UNBANCommand.cc,v 1.22 2009/06/25 19:05:23 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
using namespace level;
|
||||
|
||||
bool UNBANCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.UNBAN");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is the user authorised?
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if(!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Is the channel registered? */
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* theChannel = Network->findChannel(theChan->getName());
|
||||
if (!theChannel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we're actually opped first..
|
||||
*/
|
||||
|
||||
ChannelUser* tmpBotUser = theChannel->findUser(bot->getInstance());
|
||||
if (!tmpBotUser) return false;
|
||||
if(!tmpBotUser->getMode(ChannelUser::MODE_O))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,
|
||||
language::im_not_opped, "I'm not opped in %s").c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check level.
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if(level < level::unban)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to "
|
||||
"perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Are they trying to unban by nick or hostmask?
|
||||
*/
|
||||
bool isNick = bot->validUserMask( st[2] ) ? false : true ;
|
||||
|
||||
/* Try by nickname first, remove any bans that match this users host */
|
||||
string banTarget ;
|
||||
bool isCIDR = false;
|
||||
if( isNick )
|
||||
{
|
||||
iClient* aNick = Network->findNick(st[2]);
|
||||
if(!aNick)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_find_on_chan,
|
||||
string("I can't find %s on channel %s")).c_str(),
|
||||
st[2].c_str(),
|
||||
theChan->getName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
banTarget = Channel::createUniformBan(aNick);
|
||||
}
|
||||
else
|
||||
{
|
||||
banTarget = st[2];
|
||||
isCIDR = xCIDR(banTarget).GetValid();
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over all bans, removing any that match our target
|
||||
*/
|
||||
std::map< int,sqlBan* >::iterator ptr = theChan->banList.begin();
|
||||
|
||||
size_t banCount = 0;
|
||||
unsigned short comparison = 0;
|
||||
unsigned short exactmatch = 0;
|
||||
vector <sqlBan*> oldBans;
|
||||
|
||||
while (ptr != theChan->banList.end())
|
||||
{
|
||||
sqlBan* theBan = ptr->second;
|
||||
/*
|
||||
* If we're matching by a users full host, reverse the way we check
|
||||
* banmask.
|
||||
*/
|
||||
|
||||
/* do a (case insensitive) literal match */
|
||||
if (!strcasecmp(theBan->getBanMask(), banTarget))
|
||||
exactmatch = 1;
|
||||
|
||||
if ( isNick )
|
||||
{
|
||||
comparison = match(theBan->getBanMask(), banTarget);
|
||||
}
|
||||
else if(!isCIDR)
|
||||
{
|
||||
comparison = match(banTarget, theBan->getBanMask());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
comparison = 1; //Its a cidr, No match
|
||||
}
|
||||
if ( comparison == 0 )
|
||||
{
|
||||
/* Matches! remove this ban - if we can. */
|
||||
if (theBan->getLevel() > level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_rem_ban,
|
||||
string("You have insufficient access to remove the ban %s from %s's database")).c_str(),
|
||||
theBan->getBanMask().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if it's an exact match, we want to only remove that ban */
|
||||
if (exactmatch == 1)
|
||||
{
|
||||
oldBans.clear();
|
||||
oldBans.push_back(theBan);
|
||||
break;
|
||||
} else {
|
||||
oldBans.push_back(theBan);
|
||||
}
|
||||
}
|
||||
} // if (banMatched)
|
||||
++ptr;
|
||||
|
||||
} // while()
|
||||
/*
|
||||
* Remove all the matching bans
|
||||
*/
|
||||
|
||||
vector<sqlBan*>::iterator banIterator = oldBans.begin();
|
||||
for( ; banIterator != oldBans.end() ; ++banIterator )
|
||||
{
|
||||
sqlBan* theBan = *banIterator ;
|
||||
|
||||
bot->UnBan(theChannel, theBan->getBanMask());
|
||||
|
||||
sqlChannel::sqlBanMapType::iterator sqlBanIterator =
|
||||
theChan->banList.find( theBan->getID() ) ;
|
||||
if( sqlBanIterator == theChan->banList.end() )
|
||||
{
|
||||
elog << "cservice::UNBAN> Unable to locate sqlBan, "
|
||||
<< "id: "
|
||||
<< theBan->getID()
|
||||
<< "mask: "
|
||||
<< theBan->getBanMask()
|
||||
<< endl ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
theChan->banList.erase( sqlBanIterator );
|
||||
theBan->deleteRecord();
|
||||
delete(theBan);
|
||||
banCount++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan through the channel banlist too, and attempt to match any.
|
||||
*/
|
||||
|
||||
Channel::const_banIterator cPtr = theChannel->banList_begin();
|
||||
while (cPtr != theChannel->banList_end())
|
||||
{
|
||||
if ( isNick )
|
||||
{
|
||||
comparison = match((*cPtr), banTarget);
|
||||
}
|
||||
else if (!isCIDR)
|
||||
{
|
||||
comparison = match(banTarget, (*cPtr));
|
||||
}
|
||||
|
||||
if (exactmatch == 1)
|
||||
{
|
||||
/* if we matched exactly above, we want to match exactly here too */
|
||||
comparison = strcasecmp((*cPtr), banTarget);
|
||||
}
|
||||
|
||||
if ( comparison == 0)
|
||||
{
|
||||
// Can't call xClient::UnBan inside the loop it will
|
||||
// modify without a return value.
|
||||
stringstream s;
|
||||
s << bot->getCharYYXXX()
|
||||
<< " M " << theChannel->getName()
|
||||
<< " -b " << (*cPtr)
|
||||
<< ends;
|
||||
bot->Write( s );
|
||||
|
||||
theChannel->removeBan(*cPtr);
|
||||
cPtr = theChannel->banList_begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
++cPtr;
|
||||
}
|
||||
|
||||
} // while()
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::bans_removed,
|
||||
string("Removed %i bans that matched %s")).c_str(),
|
||||
banCount, banTarget.c_str());
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* UNFORCECommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: UNFORCECommand.cc,v 1.10 2005/12/05 17:32:15 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char UNFORCECommand_cc_rcsId[] = "$Id: UNFORCECommand.cc,v 1.10 2005/12/05 17:32:15 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool UNFORCECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.UNFORCE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int admLevel = bot->getAdminAccessLevel(theUser);
|
||||
if (admLevel < level::force)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to "
|
||||
"perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, check the channel is registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if this userID is forced in this channel.
|
||||
*/
|
||||
|
||||
sqlChannel::forceMapType::iterator ptr
|
||||
= theChan->forceMap.find(theUser->getID());
|
||||
|
||||
/* If we found something, drop it. */
|
||||
if(ptr != theChan->forceMap.end())
|
||||
{
|
||||
theChan->forceMap.erase(theUser->getID());
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::rem_temp_access,
|
||||
string("Removed your temporary access of %i from channel %s")).c_str(),
|
||||
admLevel,
|
||||
theChan->getName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::no_forced_access,
|
||||
string("You don't appear to have a forced access in "
|
||||
"%s, perhaps it expired?")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* UNSUSPENDCommand.cc
|
||||
*
|
||||
* 06/01/2001 - David Henriksen <david@itwebnet.dk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Unsuspends a specified user on a channel.
|
||||
*
|
||||
* Caveats: None.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: UNSUSPENDCommand.cc,v 1.3 2012/06/02 15:50:15 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char UNSUSPENDCommand_cc_rcsId[] = "$Id: UNSUSPENDCommand.cc,v 1.3 2012/06/02 15:50:15 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using namespace level;
|
||||
|
||||
bool UNSUSPENDCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.UNSUSPEND");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is the user authorized?
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if(!theUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::no_longer_auth,
|
||||
string("Sorry, you are not authorised with me.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Trying to unsuspend a user, or a channel?
|
||||
* If there is no #, check this person's admin access.
|
||||
* If it passes, we can unsuspend a whole user account.
|
||||
* (Level 600)
|
||||
*/
|
||||
|
||||
if ((st[1][0] != '#') && (st[1][0] != '*'))
|
||||
{
|
||||
// Got enough admin access?
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (level < level::globalsuspend)
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Does this user account even exist?
|
||||
sqlUser* targetUser = bot->getUserRecord(st[1]);
|
||||
if (!targetUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::not_registered,
|
||||
string("I don't know who %s is")).c_str(),
|
||||
st[1].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetUser->getFlag(sqlUser::F_GLOBAL_SUSPEND))
|
||||
{
|
||||
bot->Notice(theClient, "%s isn't suspended.", targetUser->getUserName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Unsuspend them.
|
||||
targetUser->removeFlag(sqlUser::F_GLOBAL_SUSPEND);
|
||||
targetUser->commit(theClient);
|
||||
bot->Notice(theClient, "%s has been unsuspended.",
|
||||
targetUser->getUserName().c_str());
|
||||
|
||||
if (!targetUser->networkClientList.empty())
|
||||
{
|
||||
bot->updateUserLevels(targetUser);
|
||||
if (targetUser->getLanguageId() == 8)
|
||||
bot->noticeAllAuthedClients(targetUser,"Suspendarea globala de pe userul tau a fost anulat.");
|
||||
else
|
||||
bot->noticeAllAuthedClients(targetUser,"Your user account's global suspension has been cancelled.");
|
||||
}
|
||||
|
||||
targetUser->writeEvent(sqlUser::EV_UNSUSPEND, theUser, "");
|
||||
|
||||
bot->logAdminMessage("%s (%s) has unsuspended %s's user account.",
|
||||
theClient->getNickName().c_str(), theUser->getUserName().c_str(),
|
||||
targetUser->getUserName().c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Is the channel registered?
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
|
||||
if(!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg,
|
||||
string("Sorry, %s isn't registered with me.")).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check level.
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((level < level::unsuspend) || (( st[1] == "*" ) && (level < adminlevel::unsuspend)))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("Sorry, you have insufficient access to perform that command.")));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check whether the user is in the access list.
|
||||
sqlUser* Target = bot->getUserRecord(st[2]);
|
||||
if(!Target)
|
||||
{
|
||||
bot->Notice(theClient, "I don't know who %s is",
|
||||
st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlLevel* aLevel = bot->getLevelRecord(Target, theChan);
|
||||
if(!aLevel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::not_registered,
|
||||
string("I don't know who %s is")).c_str(),
|
||||
Target->getUserName().c_str(), theChan->getName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aLevel->getSuspendExpire() == 0)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::isnt_suspended,
|
||||
string("%s isn't suspended on %s")).c_str(),
|
||||
Target->getUserName().c_str(), theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, check we have access to perform the unsuspend.
|
||||
*/
|
||||
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if ((aLevel->getAccess()) >= level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"Cannot unsuspend a user with equal or higher access than your own.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Was this suspension set with a higher suspend level?
|
||||
*/
|
||||
if (!theUser->getFlag(sqlUser::F_POWER))
|
||||
if (aLevel->getSuspendLevel() > level)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
"Cannot unsuspend a user that was suspended at a higher level than your own access.");
|
||||
return false;
|
||||
}
|
||||
string reason = "No reason supplied";
|
||||
if (st.size() >= 4)
|
||||
{
|
||||
reason = st.assemble(3);
|
||||
if ((reason.size() < 2) || (reason.size() > 300))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser,language::reason_must).c_str(),2,300);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
aLevel->setSuspendLevel(0);
|
||||
aLevel->setSuspendExpire(0);
|
||||
aLevel->setSuspendBy(string());
|
||||
aLevel->setLastModif(bot->currentTime());
|
||||
aLevel->setLastModifBy( string( "("
|
||||
+ theUser->getUserName()
|
||||
+ ") "
|
||||
+ theClient->getNickUserHost() ) );
|
||||
aLevel->setSuspendReason(reason);
|
||||
if( !aLevel->commit() )
|
||||
{
|
||||
bot->Notice( theClient,
|
||||
"Error updating channel status." ) ;
|
||||
elog << "UNSUSPEND> SQL error"
|
||||
<< std::endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::susp_cancelled,
|
||||
string("SUSPENSION for %s is cancelled")).c_str(),
|
||||
Target->getUserName().c_str());
|
||||
if (Target != theUser)
|
||||
bot->NoteAllAuthedClients(Target, bot->getResponse(Target,language::acc_unsusp).c_str(), theChan->getName().c_str());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
/**
|
||||
* VERIFYCommand.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: VERIFYCommand.cc,v 1.24 2005/11/17 01:37:13 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
const char VERIFYCommand_cc_rcsId[] = "$Id: VERIFYCommand.cc,v 1.24 2005/11/17 01:37:13 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
|
||||
bool VERIFYCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.VERIFY");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
string extra;
|
||||
|
||||
sqlUser* tmpUser = bot->isAuthed(theClient, false);
|
||||
iClient* target = Network->findNick(st[1]);
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::dont_see_them,
|
||||
string("Sorry, I don't see %s anywhere.")).c_str(), st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target->getMode(iClient::MODE_SERVICES))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_service_bot,
|
||||
string("%s is an Official Undernet Service Bot.")).c_str(),
|
||||
target->getNickName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Firstly, deal with unauthenticated users.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(target, false);
|
||||
|
||||
if (target->isOper())
|
||||
{
|
||||
extra = bot->getResponse(tmpUser,
|
||||
language::is_also_an_ircop, " and an IRC operator");
|
||||
}
|
||||
|
||||
if (!theUser)
|
||||
{
|
||||
if(target->isOper())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_an_ircop,
|
||||
string("%s is an IRC operator")).c_str(),
|
||||
target->getNickUserHost().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_not_logged_in,
|
||||
string("%s is NOT logged in.")).c_str(),
|
||||
target->getNickUserHost().c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(bot->coderChan);
|
||||
//if (!theChan)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// TODO: Move all the levels to constants in levels.h
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser, true);
|
||||
int cLevel;
|
||||
if (!theChan)
|
||||
cLevel = 0;
|
||||
else
|
||||
cLevel = bot->getEffectiveAccessLevel(theUser, theChan, false);
|
||||
|
||||
if ( (0 == level) && (0 == cLevel) )
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::logged_in_as,
|
||||
string("%s is logged in as %s%s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
extra.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (level >= level::admin::base)
|
||||
{
|
||||
if (theUser->getFlag(sqlUser::F_ALUMNI))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_cservice_alumni,
|
||||
string("%s is a member of the CService Alumni%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((level >= level::admin::base) && (level <= level::admin::helper))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_cservice_rep,
|
||||
string("%s is an Official CService Representative%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
if ((level > level::admin::helper) && (level <= level::admin::admin))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_cservice_admin,
|
||||
string("%s is an Official CService Administrator%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
if ((level > level::admin::admin) && (level <= level::admin::coder))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_cservice_dev,
|
||||
string("%s is an Official CService Developer%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
#ifdef USE_CODER_LEVELS
|
||||
if ((cLevel >= level::coder::base) && (cLevel <= level::coder::contrib))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_coder_rep,
|
||||
string("%s is an Official Coder-Com Representative%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
if ((cLevel > level::coder::base) && (cLevel <= level::coder::contrib))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_coder_contrib,
|
||||
string("%s is an Official Coder-Com Contributer%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
if ((cLevel > level::coder::contrib) && (cLevel <= level::coder::devel))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_coder_devel,
|
||||
string("%s is an Official Coder-Com Developer%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
|
||||
if (cLevel > level::coder::devel)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(tmpUser,
|
||||
language::is_coder_senior,
|
||||
string("%s is an Official Coder-Com Senior%s and logged in as %s")).c_str(),
|
||||
target->getNickUserHost().c_str(),
|
||||
extra.c_str(),
|
||||
theUser->getUserName().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld.
|
||||
@@ -0,0 +1,264 @@
|
||||
/**
|
||||
* VOICECommand.cc
|
||||
*
|
||||
* 20/12/2000 - Perry Lorier <perry@coders.net>
|
||||
* Initial Version.
|
||||
*
|
||||
* 28/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Added multilingual support.
|
||||
*
|
||||
* 01/01/2001 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Added duplicate checking to avoid people doing:
|
||||
* /msg e voice #coder-com Gte Gte Gte Gte Gte Gte Gte {etc}
|
||||
* And flooding the target with notices.
|
||||
*
|
||||
* 2001-03-21 - Perry Lorier <Isomer@coders.net>
|
||||
* Added "on chan" to the message
|
||||
*
|
||||
* Voice's one or more users on a channel the user as access on.
|
||||
*
|
||||
* Caveats: None
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: VOICECommand.cc,v 1.21 2003/06/28 01:21:20 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "ELog.h"
|
||||
#include "cservice.h"
|
||||
#include "Network.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
|
||||
using std::map ;
|
||||
using std::vector ;
|
||||
|
||||
const char VOICECommand_cc_rcsId[] = "$Id: VOICECommand.cc,v 1.21 2003/06/28 01:21:20 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::map ;
|
||||
using std::vector ;
|
||||
|
||||
bool VOICECommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
bot->incStat("COMMANDS.VOICE");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
|
||||
if( st.size() < 2 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the channel is actually registered.
|
||||
*/
|
||||
|
||||
sqlChannel* theChan = bot->getChannelRecord(st[1]);
|
||||
if (!theChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::chan_not_reg).c_str(),
|
||||
st[1].c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check the bot is in the channel. */
|
||||
|
||||
if (!theChan->getInChan())
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::i_am_not_on_chan,
|
||||
string("I'm not in that channel!")));
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access on this channel.
|
||||
*/
|
||||
|
||||
int level = bot->getEffectiveAccessLevel(theUser, theChan, true);
|
||||
if (level < level::voice)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::insuf_access).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel* tmpChan = Network->findChannel(theChan->getName());
|
||||
if (!tmpChan)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser, language::chan_is_empty).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the NOVOICE flag is set, we aren't allowed to voice anyone.
|
||||
*/
|
||||
|
||||
if(theChan->getFlag(sqlChannel::F_NOVOICE))
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::novoice_set,
|
||||
string("The NOVOICE flag is set on %s")).c_str(),
|
||||
theChan->getName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
vector< iClient* > voiceList; // List of clients to Voice.
|
||||
|
||||
/*
|
||||
* Loop over the remaining 'nick' parameters, voicing them all.
|
||||
*/
|
||||
|
||||
char delim = 0;
|
||||
unsigned short counter = 2; // Offset of first nick in list.
|
||||
|
||||
string source;
|
||||
iClient* target = 0;
|
||||
|
||||
typedef map < iClient*, int > duplicateMapType;
|
||||
duplicateMapType duplicateMap;
|
||||
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
// No nicks provided, assume we voice ourself. :)
|
||||
voiceList.push_back(theClient);
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
string::size_type pos = st[2].find_first_of( ',' ) ;
|
||||
|
||||
// Found a comma?
|
||||
if( string::npos != pos )
|
||||
{
|
||||
// We'll do a comma seperated search then.
|
||||
source = st.assemble(2);
|
||||
delim = ',';
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = Message;
|
||||
delim = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
StringTokenizer st2( source, delim );
|
||||
|
||||
while (counter < st2.size())
|
||||
{
|
||||
target = Network->findNick(st2[counter]);
|
||||
|
||||
if(!target)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::dont_see_them).c_str(),
|
||||
st2[counter].c_str());
|
||||
counter++;
|
||||
continue ;
|
||||
}
|
||||
|
||||
ChannelUser* tmpChanUser = tmpChan->findUser(target) ;
|
||||
|
||||
// User isn't on the channel?
|
||||
if (!tmpChanUser)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::cant_find_on_chan).c_str(),
|
||||
target->getNickName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
counter++;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// User is already voiced?
|
||||
if(tmpChanUser->getMode(ChannelUser::MODE_V))
|
||||
{
|
||||
bot->Notice(theClient, bot->getResponse(theUser, language::already_voiced).c_str(),
|
||||
target->getNickName().c_str(), theChan->getName().c_str());
|
||||
counter++;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// Check for duplicates.
|
||||
duplicateMapType::iterator ptr = duplicateMap.find(target);
|
||||
if(ptr == duplicateMap.end())
|
||||
{
|
||||
// Not a duplicate.
|
||||
voiceList.push_back(target);
|
||||
duplicateMap.insert(duplicateMapType::value_type(target, 0));
|
||||
|
||||
// Don't send a notice to the person who issued the command.
|
||||
if(target != theClient)
|
||||
{
|
||||
sqlUser* tmpTargetUser = bot->isAuthed(target, false);
|
||||
if (tmpTargetUser)
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(tmpTargetUser,
|
||||
language::youre_voiced_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bot->Notice(target,
|
||||
bot->getResponse(theUser,
|
||||
language::youre_voiced_by).c_str(),
|
||||
theClient->getNickName().c_str(),
|
||||
theUser->getUserName().c_str(),
|
||||
theChan->getName().c_str());
|
||||
}
|
||||
} // Don't send to person who issued.
|
||||
} // Not a duplicate.
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
// Voice them.
|
||||
bot->Voice(tmpChan, voiceList);
|
||||
return true ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* WHITELISTCommand.cc
|
||||
*
|
||||
* 22/11/2011 - Jochen Meesters <ekips@pandora.be>
|
||||
* Initial Version.
|
||||
*
|
||||
* Adds, removes or views IP entries from
|
||||
* a whitelist, to be used by an external application.
|
||||
*
|
||||
* 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 <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "StringTokenizer.h"
|
||||
#include "cservice.h"
|
||||
#include "levels.h"
|
||||
#include "responses.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
bool WHITELISTCommand::Exec( iClient* theClient, const string& Message )
|
||||
{
|
||||
|
||||
bot->incStat("COMMANDS.WHITELIST");
|
||||
|
||||
StringTokenizer st( Message ) ;
|
||||
if( st.size() < 3 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fetch the sqlUser record attached to this client. If there isn't one,
|
||||
* they aren't logged in - tell them they should be.
|
||||
*/
|
||||
|
||||
sqlUser* theUser = bot->isAuthed(theClient, true);
|
||||
if (!theUser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the user has sufficient access for this command..
|
||||
*/
|
||||
|
||||
int level = bot->getAdminAccessLevel(theUser);
|
||||
if (level < level::whitelist)
|
||||
{
|
||||
bot->Notice(theClient,
|
||||
bot->getResponse(theUser,
|
||||
language::insuf_access,
|
||||
string("You have insufficient access to perform that command")));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ConnectionManager::isIpAddress(st[2]))
|
||||
{
|
||||
bot->Notice(theClient, "You can only supply a single IPv4 address in dot-decimal notation. (a.b.c.d)");
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream whitelistQuery;
|
||||
whitelistQuery << "SELECT ip, addedby, addedon, expiresat, reason FROM whitelist WHERE "
|
||||
<< "IP = '" << st[2] << "'" << ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "WHITELIST::sqlQuery> "
|
||||
<< whitelistQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( whitelistQuery, true ) )
|
||||
{
|
||||
elog << "WHITELIST> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool onList = false;
|
||||
string dbIP, dbAddedBy, dbReason;
|
||||
unsigned int dbAddedOn, dbExpires;
|
||||
if (bot->SQLDb->Tuples() > 0)
|
||||
{
|
||||
onList = true;
|
||||
dbIP = bot->SQLDb->GetValue(0, 0);
|
||||
dbAddedBy = bot->SQLDb->GetValue(0, 1);
|
||||
dbAddedOn = atoi(bot->SQLDb->GetValue(0, 2).c_str());
|
||||
dbExpires = atoi(bot->SQLDb->GetValue(0, 3).c_str());
|
||||
dbReason = bot->SQLDb->GetValue(0, 4);
|
||||
}
|
||||
|
||||
string option = string_upper(st[1]);
|
||||
|
||||
if (option == "ADD")
|
||||
{
|
||||
if( st.size() < 5 )
|
||||
{
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (onList) {
|
||||
bot->Notice(theClient, "The IP %s is already added to the whitelist.", st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int whiteTime;
|
||||
unsigned int maxWhiteTime = 86400;
|
||||
if (IsTimeSpec(st[3]))
|
||||
{
|
||||
whiteTime = extractTime(st[3], 3600);
|
||||
} else {
|
||||
if (st[3] == "*")
|
||||
{
|
||||
whiteTime = 0;
|
||||
} else {
|
||||
bot->Notice(theClient, "Please enter a valid duration.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((whiteTime == 0 || whiteTime > maxWhiteTime) && (level < level::whitelistadmin))
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, you can't use that duration.");
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int expireTime;
|
||||
if (whiteTime == 0) {
|
||||
expireTime = 0;
|
||||
} else {
|
||||
expireTime = bot->currentTime() + whiteTime;
|
||||
}
|
||||
|
||||
string whiteReason = st.assemble(4);
|
||||
// elog << st[1] << " " << st[2] << " " << whiteTime << " " << whiteReason << endl;
|
||||
|
||||
stringstream whitelistQuery;
|
||||
whitelistQuery << "INSERT INTO whitelist (IP, AddedBy, AddedOn, ExpiresAt, Reason) "
|
||||
<< "VALUES ('" << st[2] << "', '" << theUser->getUserName()
|
||||
<< "', date_part('epoch', CURRENT_TIMESTAMP)::int, " << expireTime << ", '"
|
||||
<< whiteReason << "')"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "WHITELIST::sqlQuery> "
|
||||
<< whitelistQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( whitelistQuery, true ) )
|
||||
{
|
||||
elog << "WHITELIST> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, "IP %s added to the whitelist.", st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (option == "REM" || option == "DEL")
|
||||
{
|
||||
if (!onList)
|
||||
{
|
||||
bot->Notice(theClient, "Can't find IP %s on the whitelist.", st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (dbExpires == 0 && level < level::whitelistadmin)
|
||||
{
|
||||
bot->Notice(theClient, "Sorry, you can't remove permanent whitelist entries.");
|
||||
return true;
|
||||
}
|
||||
|
||||
stringstream whitelistQuery;
|
||||
whitelistQuery << "DELETE FROM whitelist "
|
||||
<< "WHERE ip = '" << dbIP
|
||||
<< "'" << ends;
|
||||
#ifdef LOG_SQL
|
||||
elog << "WHITELIST::sqlQuery> "
|
||||
<< whitelistQuery.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !bot->SQLDb->Exec( whitelistQuery, true ) )
|
||||
{
|
||||
elog << "WHITELIST> SQL Error: "
|
||||
<< bot->SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false;
|
||||
}
|
||||
bot->Notice(theClient, "Removed IP %s from the whitelist.", st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (option == "VIEW")
|
||||
{
|
||||
if (!onList)
|
||||
{
|
||||
bot->Notice(theClient, "Can't find IP %s on the whitelist.", st[2].c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
const time_t timeAddedOn = (time_t)dbAddedOn;
|
||||
bot->Notice(theClient, "%s: Added on %s", dbIP.c_str(), ctime(&timeAddedOn));
|
||||
bot->Notice(theClient, "(expires in: %s) by %s -- %s",
|
||||
prettyDuration(bot->currentTime() - (dbExpires - bot->currentTime())).c_str(),
|
||||
dbAddedBy.c_str(), dbReason.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
Usage(theClient);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* banMatcher.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: banMatcher.h,v 1.3 2009/06/25 19:59:05 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __BANMATCHER_H
|
||||
#define __BANMATCHER_H "$Id: banMatcher.h,v 1.3 2009/06/25 19:59:05 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "iClient.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class banMatcher
|
||||
{
|
||||
|
||||
public:
|
||||
virtual bool matches(iClient*) = 0;
|
||||
|
||||
virtual ~banMatcher(){}
|
||||
} ;
|
||||
|
||||
}
|
||||
#endif // __BANMATCHER_H
|
||||
Vendored
+714
@@ -0,0 +1,714 @@
|
||||
#! /bin/sh
|
||||
|
||||
# From configure.in Revision:
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated automatically using autoconf version 2.13
|
||||
# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
|
||||
#
|
||||
# This configure script is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy, distribute and modify it.
|
||||
|
||||
# Defaults:
|
||||
ac_help=
|
||||
ac_default_prefix=/usr/local
|
||||
# Any additions from configure.in:
|
||||
|
||||
# Initialize some variables set by options.
|
||||
# The variables have the same names as the options, with
|
||||
# dashes changed to underlines.
|
||||
build=NONE
|
||||
cache_file=./config.cache
|
||||
exec_prefix=NONE
|
||||
host=NONE
|
||||
no_create=
|
||||
nonopt=NONE
|
||||
no_recursion=
|
||||
prefix=NONE
|
||||
program_prefix=NONE
|
||||
program_suffix=NONE
|
||||
program_transform_name=s,x,x,
|
||||
silent=
|
||||
site=
|
||||
srcdir=
|
||||
target=NONE
|
||||
verbose=
|
||||
x_includes=NONE
|
||||
x_libraries=NONE
|
||||
bindir='${exec_prefix}/bin'
|
||||
sbindir='${exec_prefix}/sbin'
|
||||
libexecdir='${exec_prefix}/libexec'
|
||||
datadir='${prefix}/share'
|
||||
sysconfdir='${prefix}/etc'
|
||||
sharedstatedir='${prefix}/com'
|
||||
localstatedir='${prefix}/var'
|
||||
libdir='${exec_prefix}/lib'
|
||||
includedir='${prefix}/include'
|
||||
oldincludedir='/usr/include'
|
||||
infodir='${prefix}/info'
|
||||
mandir='${prefix}/man'
|
||||
|
||||
# Initialize some other variables.
|
||||
subdirs=
|
||||
MFLAGS= MAKEFLAGS=
|
||||
SHELL=${CONFIG_SHELL-/bin/sh}
|
||||
# Maximum number of lines to put in a shell here document.
|
||||
ac_max_here_lines=12
|
||||
|
||||
ac_prev=
|
||||
for ac_option
|
||||
do
|
||||
|
||||
# If the previous option needs an argument, assign it.
|
||||
if test -n "$ac_prev"; then
|
||||
eval "$ac_prev=\$ac_option"
|
||||
ac_prev=
|
||||
continue
|
||||
fi
|
||||
|
||||
case "$ac_option" in
|
||||
-*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
|
||||
*) ac_optarg= ;;
|
||||
esac
|
||||
|
||||
# Accept the important Cygnus configure options, so we can diagnose typos.
|
||||
|
||||
case "$ac_option" in
|
||||
|
||||
-bindir | --bindir | --bindi | --bind | --bin | --bi)
|
||||
ac_prev=bindir ;;
|
||||
-bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
|
||||
bindir="$ac_optarg" ;;
|
||||
|
||||
-build | --build | --buil | --bui | --bu)
|
||||
ac_prev=build ;;
|
||||
-build=* | --build=* | --buil=* | --bui=* | --bu=*)
|
||||
build="$ac_optarg" ;;
|
||||
|
||||
-cache-file | --cache-file | --cache-fil | --cache-fi \
|
||||
| --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
|
||||
ac_prev=cache_file ;;
|
||||
-cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
|
||||
| --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
|
||||
cache_file="$ac_optarg" ;;
|
||||
|
||||
-datadir | --datadir | --datadi | --datad | --data | --dat | --da)
|
||||
ac_prev=datadir ;;
|
||||
-datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
|
||||
| --da=*)
|
||||
datadir="$ac_optarg" ;;
|
||||
|
||||
-disable-* | --disable-*)
|
||||
ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
|
||||
# Reject names that are not valid shell variable names.
|
||||
if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
|
||||
{ echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
|
||||
fi
|
||||
ac_feature=`echo $ac_feature| sed 's/-/_/g'`
|
||||
eval "enable_${ac_feature}=no" ;;
|
||||
|
||||
-enable-* | --enable-*)
|
||||
ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
|
||||
# Reject names that are not valid shell variable names.
|
||||
if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
|
||||
{ echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
|
||||
fi
|
||||
ac_feature=`echo $ac_feature| sed 's/-/_/g'`
|
||||
case "$ac_option" in
|
||||
*=*) ;;
|
||||
*) ac_optarg=yes ;;
|
||||
esac
|
||||
eval "enable_${ac_feature}='$ac_optarg'" ;;
|
||||
|
||||
-exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
|
||||
| --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
|
||||
| --exec | --exe | --ex)
|
||||
ac_prev=exec_prefix ;;
|
||||
-exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
|
||||
| --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
|
||||
| --exec=* | --exe=* | --ex=*)
|
||||
exec_prefix="$ac_optarg" ;;
|
||||
|
||||
-gas | --gas | --ga | --g)
|
||||
# Obsolete; use --with-gas.
|
||||
with_gas=yes ;;
|
||||
|
||||
-help | --help | --hel | --he)
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat << EOF
|
||||
Usage: configure [options] [host]
|
||||
Options: [defaults in brackets after descriptions]
|
||||
Configuration:
|
||||
--cache-file=FILE cache test results in FILE
|
||||
--help print this message
|
||||
--no-create do not create output files
|
||||
--quiet, --silent do not print \`checking...' messages
|
||||
--version print the version of autoconf that created configure
|
||||
Directory and file names:
|
||||
--prefix=PREFIX install architecture-independent files in PREFIX
|
||||
[$ac_default_prefix]
|
||||
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
|
||||
[same as prefix]
|
||||
--bindir=DIR user executables in DIR [EPREFIX/bin]
|
||||
--sbindir=DIR system admin executables in DIR [EPREFIX/sbin]
|
||||
--libexecdir=DIR program executables in DIR [EPREFIX/libexec]
|
||||
--datadir=DIR read-only architecture-independent data in DIR
|
||||
[PREFIX/share]
|
||||
--sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc]
|
||||
--sharedstatedir=DIR modifiable architecture-independent data in DIR
|
||||
[PREFIX/com]
|
||||
--localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var]
|
||||
--libdir=DIR object code libraries in DIR [EPREFIX/lib]
|
||||
--includedir=DIR C header files in DIR [PREFIX/include]
|
||||
--oldincludedir=DIR C header files for non-gcc in DIR [/usr/include]
|
||||
--infodir=DIR info documentation in DIR [PREFIX/info]
|
||||
--mandir=DIR man documentation in DIR [PREFIX/man]
|
||||
--srcdir=DIR find the sources in DIR [configure dir or ..]
|
||||
--program-prefix=PREFIX prepend PREFIX to installed program names
|
||||
--program-suffix=SUFFIX append SUFFIX to installed program names
|
||||
--program-transform-name=PROGRAM
|
||||
run sed PROGRAM on installed program names
|
||||
EOF
|
||||
cat << EOF
|
||||
Host type:
|
||||
--build=BUILD configure for building on BUILD [BUILD=HOST]
|
||||
--host=HOST configure for HOST [guessed]
|
||||
--target=TARGET configure for TARGET [TARGET=HOST]
|
||||
Features and packages:
|
||||
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
|
||||
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
|
||||
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
|
||||
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
|
||||
--x-includes=DIR X include files are in DIR
|
||||
--x-libraries=DIR X library files are in DIR
|
||||
EOF
|
||||
if test -n "$ac_help"; then
|
||||
echo "--enable and --with options recognized:$ac_help"
|
||||
fi
|
||||
exit 0 ;;
|
||||
|
||||
-host | --host | --hos | --ho)
|
||||
ac_prev=host ;;
|
||||
-host=* | --host=* | --hos=* | --ho=*)
|
||||
host="$ac_optarg" ;;
|
||||
|
||||
-includedir | --includedir | --includedi | --included | --include \
|
||||
| --includ | --inclu | --incl | --inc)
|
||||
ac_prev=includedir ;;
|
||||
-includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
|
||||
| --includ=* | --inclu=* | --incl=* | --inc=*)
|
||||
includedir="$ac_optarg" ;;
|
||||
|
||||
-infodir | --infodir | --infodi | --infod | --info | --inf)
|
||||
ac_prev=infodir ;;
|
||||
-infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
|
||||
infodir="$ac_optarg" ;;
|
||||
|
||||
-libdir | --libdir | --libdi | --libd)
|
||||
ac_prev=libdir ;;
|
||||
-libdir=* | --libdir=* | --libdi=* | --libd=*)
|
||||
libdir="$ac_optarg" ;;
|
||||
|
||||
-libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
|
||||
| --libexe | --libex | --libe)
|
||||
ac_prev=libexecdir ;;
|
||||
-libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
|
||||
| --libexe=* | --libex=* | --libe=*)
|
||||
libexecdir="$ac_optarg" ;;
|
||||
|
||||
-localstatedir | --localstatedir | --localstatedi | --localstated \
|
||||
| --localstate | --localstat | --localsta | --localst \
|
||||
| --locals | --local | --loca | --loc | --lo)
|
||||
ac_prev=localstatedir ;;
|
||||
-localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
|
||||
| --localstate=* | --localstat=* | --localsta=* | --localst=* \
|
||||
| --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
|
||||
localstatedir="$ac_optarg" ;;
|
||||
|
||||
-mandir | --mandir | --mandi | --mand | --man | --ma | --m)
|
||||
ac_prev=mandir ;;
|
||||
-mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
|
||||
mandir="$ac_optarg" ;;
|
||||
|
||||
-nfp | --nfp | --nf)
|
||||
# Obsolete; use --without-fp.
|
||||
with_fp=no ;;
|
||||
|
||||
-no-create | --no-create | --no-creat | --no-crea | --no-cre \
|
||||
| --no-cr | --no-c)
|
||||
no_create=yes ;;
|
||||
|
||||
-no-recursion | --no-recursion | --no-recursio | --no-recursi \
|
||||
| --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
|
||||
no_recursion=yes ;;
|
||||
|
||||
-oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
|
||||
| --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
|
||||
| --oldin | --oldi | --old | --ol | --o)
|
||||
ac_prev=oldincludedir ;;
|
||||
-oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
|
||||
| --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
|
||||
| --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
|
||||
oldincludedir="$ac_optarg" ;;
|
||||
|
||||
-prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
|
||||
ac_prev=prefix ;;
|
||||
-prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
|
||||
prefix="$ac_optarg" ;;
|
||||
|
||||
-program-prefix | --program-prefix | --program-prefi | --program-pref \
|
||||
| --program-pre | --program-pr | --program-p)
|
||||
ac_prev=program_prefix ;;
|
||||
-program-prefix=* | --program-prefix=* | --program-prefi=* \
|
||||
| --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
|
||||
program_prefix="$ac_optarg" ;;
|
||||
|
||||
-program-suffix | --program-suffix | --program-suffi | --program-suff \
|
||||
| --program-suf | --program-su | --program-s)
|
||||
ac_prev=program_suffix ;;
|
||||
-program-suffix=* | --program-suffix=* | --program-suffi=* \
|
||||
| --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
|
||||
program_suffix="$ac_optarg" ;;
|
||||
|
||||
-program-transform-name | --program-transform-name \
|
||||
| --program-transform-nam | --program-transform-na \
|
||||
| --program-transform-n | --program-transform- \
|
||||
| --program-transform | --program-transfor \
|
||||
| --program-transfo | --program-transf \
|
||||
| --program-trans | --program-tran \
|
||||
| --progr-tra | --program-tr | --program-t)
|
||||
ac_prev=program_transform_name ;;
|
||||
-program-transform-name=* | --program-transform-name=* \
|
||||
| --program-transform-nam=* | --program-transform-na=* \
|
||||
| --program-transform-n=* | --program-transform-=* \
|
||||
| --program-transform=* | --program-transfor=* \
|
||||
| --program-transfo=* | --program-transf=* \
|
||||
| --program-trans=* | --program-tran=* \
|
||||
| --progr-tra=* | --program-tr=* | --program-t=*)
|
||||
program_transform_name="$ac_optarg" ;;
|
||||
|
||||
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
|
||||
| -silent | --silent | --silen | --sile | --sil)
|
||||
silent=yes ;;
|
||||
|
||||
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
|
||||
ac_prev=sbindir ;;
|
||||
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
||||
| --sbi=* | --sb=*)
|
||||
sbindir="$ac_optarg" ;;
|
||||
|
||||
-sharedstatedir | --sharedstatedir | --sharedstatedi \
|
||||
| --sharedstated | --sharedstate | --sharedstat | --sharedsta \
|
||||
| --sharedst | --shareds | --shared | --share | --shar \
|
||||
| --sha | --sh)
|
||||
ac_prev=sharedstatedir ;;
|
||||
-sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
|
||||
| --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
|
||||
| --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
|
||||
| --sha=* | --sh=*)
|
||||
sharedstatedir="$ac_optarg" ;;
|
||||
|
||||
-site | --site | --sit)
|
||||
ac_prev=site ;;
|
||||
-site=* | --site=* | --sit=*)
|
||||
site="$ac_optarg" ;;
|
||||
|
||||
-srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
|
||||
ac_prev=srcdir ;;
|
||||
-srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
|
||||
srcdir="$ac_optarg" ;;
|
||||
|
||||
-sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
|
||||
| --syscon | --sysco | --sysc | --sys | --sy)
|
||||
ac_prev=sysconfdir ;;
|
||||
-sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
|
||||
| --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
|
||||
sysconfdir="$ac_optarg" ;;
|
||||
|
||||
-target | --target | --targe | --targ | --tar | --ta | --t)
|
||||
ac_prev=target ;;
|
||||
-target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
|
||||
target="$ac_optarg" ;;
|
||||
|
||||
-v | -verbose | --verbose | --verbos | --verbo | --verb)
|
||||
verbose=yes ;;
|
||||
|
||||
-version | --version | --versio | --versi | --vers)
|
||||
echo "configure generated by autoconf version 2.13"
|
||||
exit 0 ;;
|
||||
|
||||
-with-* | --with-*)
|
||||
ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
|
||||
# Reject names that are not valid shell variable names.
|
||||
if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
|
||||
{ echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
|
||||
fi
|
||||
ac_package=`echo $ac_package| sed 's/-/_/g'`
|
||||
case "$ac_option" in
|
||||
*=*) ;;
|
||||
*) ac_optarg=yes ;;
|
||||
esac
|
||||
eval "with_${ac_package}='$ac_optarg'" ;;
|
||||
|
||||
-without-* | --without-*)
|
||||
ac_package=`echo $ac_option|sed -e 's/-*without-//'`
|
||||
# Reject names that are not valid shell variable names.
|
||||
if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
|
||||
{ echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
|
||||
fi
|
||||
ac_package=`echo $ac_package| sed 's/-/_/g'`
|
||||
eval "with_${ac_package}=no" ;;
|
||||
|
||||
--x)
|
||||
# Obsolete; use --with-x.
|
||||
with_x=yes ;;
|
||||
|
||||
-x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
|
||||
| --x-incl | --x-inc | --x-in | --x-i)
|
||||
ac_prev=x_includes ;;
|
||||
-x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
|
||||
| --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
|
||||
x_includes="$ac_optarg" ;;
|
||||
|
||||
-x-libraries | --x-libraries | --x-librarie | --x-librari \
|
||||
| --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
|
||||
ac_prev=x_libraries ;;
|
||||
-x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
|
||||
| --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
|
||||
x_libraries="$ac_optarg" ;;
|
||||
|
||||
-*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
|
||||
;;
|
||||
|
||||
*)
|
||||
if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
|
||||
echo "configure: warning: $ac_option: invalid host type" 1>&2
|
||||
fi
|
||||
if test "x$nonopt" != xNONE; then
|
||||
{ echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
|
||||
fi
|
||||
nonopt="$ac_option"
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
if test -n "$ac_prev"; then
|
||||
{ echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
|
||||
fi
|
||||
|
||||
trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
|
||||
|
||||
# File descriptor usage:
|
||||
# 0 standard input
|
||||
# 1 file creation
|
||||
# 2 errors and warnings
|
||||
# 3 some systems may open it to /dev/tty
|
||||
# 4 used on the Kubota Titan
|
||||
# 6 checking for... messages and results
|
||||
# 5 compiler messages saved in config.log
|
||||
if test "$silent" = yes; then
|
||||
exec 6>/dev/null
|
||||
else
|
||||
exec 6>&1
|
||||
fi
|
||||
exec 5>./config.log
|
||||
|
||||
echo "\
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
" 1>&5
|
||||
|
||||
# Strip out --no-create and --no-recursion so they do not pile up.
|
||||
# Also quote any args containing shell metacharacters.
|
||||
ac_configure_args=
|
||||
for ac_arg
|
||||
do
|
||||
case "$ac_arg" in
|
||||
-no-create | --no-create | --no-creat | --no-crea | --no-cre \
|
||||
| --no-cr | --no-c) ;;
|
||||
-no-recursion | --no-recursion | --no-recursio | --no-recursi \
|
||||
| --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
|
||||
*" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
|
||||
ac_configure_args="$ac_configure_args '$ac_arg'" ;;
|
||||
*) ac_configure_args="$ac_configure_args $ac_arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# NLS nuisances.
|
||||
# Only set these to C if already set. These must not be set unconditionally
|
||||
# because not all systems understand e.g. LANG=C (notably SCO).
|
||||
# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
|
||||
# Non-C LC_CTYPE values break the ctype check.
|
||||
if test "${LANG+set}" = set; then LANG=C; export LANG; fi
|
||||
if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
|
||||
if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
|
||||
if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
|
||||
|
||||
# confdefs.h avoids OS command line length limits that DEFS can exceed.
|
||||
rm -rf conftest* confdefs.h
|
||||
# AIX cpp loses on an empty file, so make sure it contains at least a newline.
|
||||
echo > confdefs.h
|
||||
|
||||
# A filename unique to this package, relative to the directory that
|
||||
# configure is in, which we can look for to find out if srcdir is correct.
|
||||
ac_unique_file=cservice.cc
|
||||
|
||||
# Find the source files, if location was not specified.
|
||||
if test -z "$srcdir"; then
|
||||
ac_srcdir_defaulted=yes
|
||||
# Try the directory containing this script, then its parent.
|
||||
ac_prog=$0
|
||||
ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
|
||||
test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
|
||||
srcdir=$ac_confdir
|
||||
if test ! -r $srcdir/$ac_unique_file; then
|
||||
srcdir=..
|
||||
fi
|
||||
else
|
||||
ac_srcdir_defaulted=no
|
||||
fi
|
||||
if test ! -r $srcdir/$ac_unique_file; then
|
||||
if test "$ac_srcdir_defaulted" = yes; then
|
||||
{ echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
|
||||
else
|
||||
{ echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
|
||||
fi
|
||||
fi
|
||||
srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
|
||||
|
||||
# Prefer explicitly selected file to automatically selected ones.
|
||||
if test -z "$CONFIG_SITE"; then
|
||||
if test "x$prefix" != xNONE; then
|
||||
CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
|
||||
else
|
||||
CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
|
||||
fi
|
||||
fi
|
||||
for ac_site_file in $CONFIG_SITE; do
|
||||
if test -r "$ac_site_file"; then
|
||||
echo "loading site script $ac_site_file"
|
||||
. "$ac_site_file"
|
||||
fi
|
||||
done
|
||||
|
||||
if test -r "$cache_file"; then
|
||||
echo "loading cache $cache_file"
|
||||
. $cache_file
|
||||
else
|
||||
echo "creating cache $cache_file"
|
||||
> $cache_file
|
||||
fi
|
||||
|
||||
ac_ext=c
|
||||
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
|
||||
ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
|
||||
cross_compiling=$ac_cv_prog_cc_cross
|
||||
|
||||
ac_exeext=
|
||||
ac_objext=o
|
||||
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
|
||||
# Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
|
||||
if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
|
||||
ac_n= ac_c='
|
||||
' ac_t=' '
|
||||
else
|
||||
ac_n=-n ac_c= ac_t=
|
||||
fi
|
||||
else
|
||||
ac_n= ac_c='\c' ac_t=
|
||||
fi
|
||||
|
||||
|
||||
AM_INIT_AUTOMAKE(cmaster,0.0)
|
||||
|
||||
pgsql=no
|
||||
PGSQL_DIR=""
|
||||
|
||||
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
|
||||
echo "configure:532: checking how to run the C preprocessor" >&5
|
||||
# On Suns, sometimes $CPP names a directory.
|
||||
if test -n "$CPP" && test -d "$CPP"; then
|
||||
CPP=
|
||||
fi
|
||||
if test -z "$CPP"; then
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
# This must be in double quotes, not single quotes, because CPP may get
|
||||
# substituted into the Makefile and "${CC-cc}" will confuse make.
|
||||
CPP="${CC-cc} -E"
|
||||
# On the NeXT, cc -E runs the code through the compiler's parser,
|
||||
# not just through cpp.
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 547 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <assert.h>
|
||||
Syntax Error
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:553: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
:
|
||||
else
|
||||
echo "$ac_err" >&5
|
||||
echo "configure: failed program was:" >&5
|
||||
cat conftest.$ac_ext >&5
|
||||
rm -rf conftest*
|
||||
CPP="${CC-cc} -E -traditional-cpp"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 564 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <assert.h>
|
||||
Syntax Error
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:570: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
:
|
||||
else
|
||||
echo "$ac_err" >&5
|
||||
echo "configure: failed program was:" >&5
|
||||
cat conftest.$ac_ext >&5
|
||||
rm -rf conftest*
|
||||
CPP="${CC-cc} -nologo -E"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 581 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <assert.h>
|
||||
Syntax Error
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:587: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
:
|
||||
else
|
||||
echo "$ac_err" >&5
|
||||
echo "configure: failed program was:" >&5
|
||||
cat conftest.$ac_ext >&5
|
||||
rm -rf conftest*
|
||||
CPP=/lib/cpp
|
||||
fi
|
||||
rm -f conftest*
|
||||
fi
|
||||
rm -f conftest*
|
||||
fi
|
||||
rm -f conftest*
|
||||
ac_cv_prog_CPP="$CPP"
|
||||
fi
|
||||
CPP="$ac_cv_prog_CPP"
|
||||
else
|
||||
ac_cv_prog_CPP="$CPP"
|
||||
fi
|
||||
echo "$ac_t""$CPP" 1>&6
|
||||
|
||||
ac_safe=`echo "/usr/local/pgsql/libpq++.h" | sed 'y%./+-%__p_%'`
|
||||
echo $ac_n "checking for /usr/local/pgsql/libpq++.h""... $ac_c" 1>&6
|
||||
echo "configure:613: checking for /usr/local/pgsql/libpq++.h" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 618 "configure"
|
||||
#include "confdefs.h"
|
||||
#include </usr/local/pgsql/libpq++.h>
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:623: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_header_$ac_safe=yes"
|
||||
else
|
||||
echo "$ac_err" >&5
|
||||
echo "configure: failed program was:" >&5
|
||||
cat conftest.$ac_ext >&5
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_header_$ac_safe=no"
|
||||
fi
|
||||
rm -f conftest*
|
||||
fi
|
||||
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
|
||||
echo "$ac_t""yes" 1>&6
|
||||
pgsql=yes,
|
||||
PGSQL_DIR=/usr/local/pgsql
|
||||
else
|
||||
echo "$ac_t""no" 1>&6
|
||||
fi
|
||||
|
||||
|
||||
if test $pgsql = no; then
|
||||
ac_safe=`echo "/usr/include/pgsql" | sed 'y%./+-%__p_%'`
|
||||
echo $ac_n "checking for /usr/include/pgsql""... $ac_c" 1>&6
|
||||
echo "configure:649: checking for /usr/include/pgsql" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 654 "configure"
|
||||
#include "confdefs.h"
|
||||
#include </usr/include/pgsql>
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:659: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_header_$ac_safe=yes"
|
||||
else
|
||||
echo "$ac_err" >&5
|
||||
echo "configure: failed program was:" >&5
|
||||
cat conftest.$ac_ext >&5
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_header_$ac_safe=no"
|
||||
fi
|
||||
rm -f conftest*
|
||||
fi
|
||||
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
|
||||
echo "$ac_t""yes" 1>&6
|
||||
pgsql=yes,
|
||||
PGSQL_DIR=/usr/include/pgsql
|
||||
else
|
||||
echo "$ac_t""no" 1>&6
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if test $pgsql = no; then
|
||||
{ echo "configure: error: Unable to find PostGreSQL " 1>&2; exit 1; }
|
||||
fi
|
||||
|
||||
|
||||
|
||||
echo Finished configuring CMaster, everything looks good...
|
||||
echo
|
||||
s%@SHELL@%$SHELL%g
|
||||
s%@CFLAGS@%$CFLAGS%g
|
||||
s%@CPPFLAGS@%$CPPFLAGS%g
|
||||
s%@CXXFLAGS@%$CXXFLAGS%g
|
||||
s%@FFLAGS@%$FFLAGS%g
|
||||
s%@DEFS@%$DEFS%g
|
||||
s%@LDFLAGS@%$LDFLAGS%g
|
||||
s%@LIBS@%$LIBS%g
|
||||
s%@exec_prefix@%$exec_prefix%g
|
||||
s%@prefix@%$prefix%g
|
||||
s%@program_transform_name@%$program_transform_name%g
|
||||
s%@bindir@%$bindir%g
|
||||
s%@sbindir@%$sbindir%g
|
||||
s%@libexecdir@%$libexecdir%g
|
||||
s%@datadir@%$datadir%g
|
||||
s%@sysconfdir@%$sysconfdir%g
|
||||
s%@sharedstatedir@%$sharedstatedir%g
|
||||
s%@localstatedir@%$localstatedir%g
|
||||
s%@libdir@%$libdir%g
|
||||
s%@includedir@%$includedir%g
|
||||
s%@oldincludedir@%$oldincludedir%g
|
||||
s%@infodir@%$infodir%g
|
||||
s%@mandir@%$mandir%g
|
||||
s%@CPP@%$CPP%g
|
||||
s%@PGSQL_DIR@%$PGSQL_DIR%g
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* constants.h
|
||||
*
|
||||
* 27/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Defines constants used throughout the application.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: constants.h,v 1.24 2012/05/28 20:38:32 Seven Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CONSTANTS_H
|
||||
#define __CONSTANTS_H "$Id: constants.h,v 1.24 2012/05/28 20:38:32 Seven Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
/*
|
||||
* Comma separated lists of fields for use in retrieving various
|
||||
* articles of data.
|
||||
*/
|
||||
const std::string channel_fields = "id,name,flags,mass_deop_pro,flood_pro,url,description,comment,keywords,registered_ts,channel_ts,channel_mode,userflags,last_updated,limit_offset,limit_period,limit_grace,limit_max,welcome,max_bans,no_take";
|
||||
const std::string user_fields = "users.id,users.user_name,users.password,users.url,users.nickname,users.language_id,users.flags,users.last_updated_by,users.last_updated,users.email,users.maxlogins,users.verificationdata,users.totp_key,users.hostname,signup_ts,signup_ip,created_ts";
|
||||
const std::string level_fields = "channel_id,user_id,access,flags,suspend_expires,suspend_level,suspend_by,added,added_by,last_Modif,last_Modif_By,last_Updated,suspend_reason";
|
||||
const std::string ban_fields = "id,channel_id,banmask,set_by,set_ts,level,expires,reason,last_updated";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
* csGline.cc
|
||||
* Gline class
|
||||
*
|
||||
* 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 <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <ctime>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "dbHandle.h"
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "csGline.h"
|
||||
#include "cservice.h"
|
||||
#include "gnuworld_config.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::stringstream ;
|
||||
using std::ends ;
|
||||
|
||||
unsigned int csGline::numAllocated = 0;
|
||||
|
||||
csGline::csGline(dbHandle* _SQLDb)
|
||||
: Id(),
|
||||
AddedBy(),
|
||||
AddedOn( 0 ),
|
||||
Expires( 0 ),
|
||||
LastUpdated( 0 ),
|
||||
Reason(),
|
||||
SQLDb( _SQLDb )
|
||||
{
|
||||
++numAllocated;
|
||||
}
|
||||
|
||||
csGline::~csGline()
|
||||
{
|
||||
--numAllocated;
|
||||
}
|
||||
|
||||
bool csGline::Insert()
|
||||
{
|
||||
//First we gotta make sure, there is no old gline in the database
|
||||
static const char *Del = "DELETE FROM glines WHERE lower(host) = '";
|
||||
|
||||
stringstream delQuery;
|
||||
delQuery << Del
|
||||
<< escapeSQLChars(string_lower(Host)) << "'"
|
||||
<< ends;
|
||||
|
||||
|
||||
if( !SQLDb->Exec( delQuery ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "csGline::DeleteOnInsert> SQL Failure: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
|
||||
return false ;
|
||||
}
|
||||
//Now insert the new one
|
||||
static const char *Main = "INSERT INTO Glines (Host,AddedBy,AddedOn,ExpiresAt,LastUpdated,Reason) VALUES ('";
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << Main
|
||||
<< escapeSQLChars(Host) << "','"
|
||||
<< escapeSQLChars(AddedBy) << "',"
|
||||
<< AddedOn << ","
|
||||
<< Expires << ","
|
||||
<< LastUpdated << ",'"
|
||||
<< escapeSQLChars(Reason) << "')"
|
||||
<< ends;
|
||||
|
||||
elog << "Gline::Insert::sqlQuery> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
|
||||
if( SQLDb->Exec( theQuery ) )
|
||||
//if( PGRES_COMMAND_OK == status )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog << "cservice::Gline::Insert> SQL Failure: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool csGline::Update()
|
||||
{
|
||||
if(atoi(Id.c_str()) == -1) //saveGlines was false when this gline was added
|
||||
{
|
||||
return true;
|
||||
}
|
||||
static const char *Main = "UPDATE Glines SET Id = '";
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << Main
|
||||
<< Id
|
||||
<< "', Host = '"
|
||||
<< escapeSQLChars(Host)
|
||||
<< "', AddedBy = '"
|
||||
<< escapeSQLChars(AddedBy)
|
||||
<< "', AddedOn = "
|
||||
<< AddedOn
|
||||
<< ",ExpiresAt = "
|
||||
<< Expires
|
||||
<< ",LastUpdated = "
|
||||
<< LastUpdated
|
||||
<< ",Reason = '"
|
||||
<< escapeSQLChars(Reason) << "'"
|
||||
<< " WHERE Id = " << Id
|
||||
<< ends;
|
||||
|
||||
elog << "cservice::Gline::Update> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
|
||||
if( SQLDb->Exec( theQuery ) )
|
||||
//if( PGRES_COMMAND_OK == status )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog << "cservice::Gline::Update> SQL Failure: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool csGline::loadData(int GlineId)
|
||||
{
|
||||
static const char *Main = "SELECT Id,Host,AddedBy,AddedOn,ExpiresAt,LastUpdated,Reason FROM glines WHERE Id = ";
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << Main
|
||||
<< GlineId
|
||||
<< ends;
|
||||
|
||||
elog << "cservice::glineload> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
|
||||
if( !SQLDb->Exec( theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "csGline::load> SQL Failure: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(SQLDb->Tuples() < 6)
|
||||
return false;
|
||||
Id = SQLDb->GetValue(0,0);
|
||||
Host = SQLDb->GetValue(0,1);
|
||||
AddedBy = SQLDb->GetValue(0,2) ;
|
||||
AddedOn = static_cast< time_t >( unsigned(
|
||||
atoi( SQLDb->GetValue(0,3).c_str() ) )) ;
|
||||
Expires = static_cast< time_t >( unsigned(
|
||||
atoi( SQLDb->GetValue(0,4).c_str() ) )) ;
|
||||
LastUpdated = static_cast< time_t >( unsigned(
|
||||
atoi( SQLDb->GetValue(0,5).c_str() ) )) ;
|
||||
Reason = SQLDb->GetValue(0,6);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool csGline::loadData( const string & HostName)
|
||||
{
|
||||
static const char *Main = "SELECT Id,Host,AddedBy,AddedOn,ExpiresAt,LastUpdated,Reason FROM glines WHERE Host = '";
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << Main
|
||||
<< escapeSQLChars(HostName.c_str())
|
||||
<< "'" << ends;
|
||||
|
||||
elog << "cservice::loadData> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
|
||||
if( !SQLDb->Exec( theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
elog << "csGline::loadData> SQL Failure: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(SQLDb->Tuples() == 0) //If no gline was found
|
||||
return false;
|
||||
Id = SQLDb->GetValue(0,0);
|
||||
Host = SQLDb->GetValue(0,1);
|
||||
AddedBy = SQLDb->GetValue(0,2) ;
|
||||
AddedOn = static_cast< time_t >( atoi( SQLDb->GetValue(0,3).c_str() ) ) ;
|
||||
Expires = static_cast< time_t >( atoi( SQLDb->GetValue(0,4).c_str() ) ) ;
|
||||
LastUpdated = static_cast< time_t >( atoi( SQLDb->GetValue(0,5).c_str() ) ) ;
|
||||
Reason = SQLDb->GetValue(0,6);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool csGline::Delete()
|
||||
{
|
||||
if(atoi(Id.c_str()) == -1) //saveGlines was false when this gline was added
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char *Main = "DELETE FROM glines WHERE Id = ";
|
||||
|
||||
stringstream theQuery;
|
||||
theQuery << Main
|
||||
<< Id
|
||||
<< ends;
|
||||
|
||||
elog << "cservice::glineDelete> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
|
||||
if( SQLDb->Exec( theQuery ) )
|
||||
//if( PGRES_COMMAND_OK == status )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog << "csGline::csDelete> SQL Failure: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl ;
|
||||
|
||||
return false ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} //Namespace Gnuworld
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* csGline.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __CSGLINE_H
|
||||
#define __CSGLINE_H "$Id: csGline.h, 06/10/2011 Spike $"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "dbHandle.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::list ;
|
||||
|
||||
class csGline
|
||||
{
|
||||
public:
|
||||
|
||||
csGline(dbHandle*);
|
||||
|
||||
virtual ~csGline();
|
||||
//Mehods for getting info
|
||||
|
||||
inline const string& getId() const
|
||||
{ return Id; }
|
||||
|
||||
inline const string& getHost() const
|
||||
{ return Host; }
|
||||
|
||||
inline const string& getAddedBy() const
|
||||
{ return AddedBy; }
|
||||
|
||||
inline const time_t& getAddedOn() const
|
||||
{ return AddedOn; }
|
||||
|
||||
inline const time_t& getExpires() const
|
||||
{ return Expires; }
|
||||
|
||||
inline const time_t& getLastUpdated() const
|
||||
{ return LastUpdated; }
|
||||
|
||||
inline const string& getReason() const
|
||||
{ return Reason; }
|
||||
|
||||
|
||||
//Methods for setting info
|
||||
|
||||
inline void setId( const string& _Id )
|
||||
{ Id = _Id; }
|
||||
|
||||
inline void setHost( const string& _Host )
|
||||
{ Host = _Host; }
|
||||
|
||||
inline void setAddedBy( const string& _AddedBy )
|
||||
{ AddedBy = _AddedBy; }
|
||||
|
||||
inline void setAddedOn( const time_t& _AddedOn )
|
||||
{ AddedOn = _AddedOn; }
|
||||
|
||||
inline void setExpires( const time_t& _Expires )
|
||||
{ Expires = _Expires; }
|
||||
|
||||
inline void setLastUpdated( const time_t& _LastUpdated )
|
||||
{ LastUpdated = _LastUpdated; }
|
||||
|
||||
inline void setReason( const string& _Reason )
|
||||
{ Reason = _Reason; }
|
||||
|
||||
inline void setSqldb(dbHandle* _SQLDb)
|
||||
{ SQLDb = _SQLDb; }
|
||||
|
||||
//Methods for updating
|
||||
|
||||
bool Insert();
|
||||
|
||||
bool Update();
|
||||
|
||||
bool loadData( int );
|
||||
|
||||
bool loadData( const string & );
|
||||
|
||||
bool Delete();
|
||||
|
||||
static unsigned int numAllocated;
|
||||
|
||||
protected:
|
||||
string Id;
|
||||
string Host;
|
||||
string AddedBy;
|
||||
time_t AddedOn;
|
||||
time_t Expires;
|
||||
time_t LastUpdated;
|
||||
string Reason;
|
||||
dbHandle* SQLDb;
|
||||
|
||||
}; // class csGline
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,744 @@
|
||||
/**
|
||||
* cservice.h
|
||||
* Author: Greg Sikorski
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: cservice.h,v 1.120 2012/06/03 16:12:46 Seven Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CSERVICE_H
|
||||
#define __CSERVICE_H "$Id: cservice.h,v 1.120 2012/06/03 16:12:46 Seven Exp $"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "client.h"
|
||||
#include "iClient.h"
|
||||
#include "iServer.h"
|
||||
#include "EConfig.h"
|
||||
#include "cservice_config.h"
|
||||
#include "cserviceCommands.h"
|
||||
#include "sqlChannel.h"
|
||||
#include "sqlIncompleteChannel.h"
|
||||
#include "sqlUser.h"
|
||||
#include "sqlLevel.h"
|
||||
#include "sqlBan.h"
|
||||
#include "sqlPendingChannel.h"
|
||||
#include "csGline.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::vector ;
|
||||
using std::map ;
|
||||
|
||||
/*
|
||||
* Class for the configuration variables extracted from the database.
|
||||
* An attempted conversion to a number is stored in 'int_value' for
|
||||
* convenience.
|
||||
*/
|
||||
|
||||
class ConfigData
|
||||
{
|
||||
|
||||
public:
|
||||
string string_value;
|
||||
unsigned int int_value;
|
||||
|
||||
inline const string& asString() const
|
||||
{ return string_value ; }
|
||||
|
||||
inline const unsigned int& asInt() const
|
||||
{ return int_value ; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Sublcass the postgres API to create our own accessor
|
||||
* to get at the PID information.
|
||||
*/
|
||||
class Command;
|
||||
|
||||
class cservice : public xClient
|
||||
{
|
||||
protected:
|
||||
|
||||
EConfig* cserviceConfig; /* Configfile */
|
||||
typedef map< string, Command*, noCaseCompare > commandMapType ;
|
||||
typedef commandMapType::value_type pairType ;
|
||||
typedef map< unsigned int, unsigned int > ipMapType ;
|
||||
ipMapType ipFloodMap;
|
||||
commandMapType commandMap;
|
||||
#ifdef USE_COMMAND_LOG
|
||||
string commandlogPath;
|
||||
std::ofstream commandLog;
|
||||
#endif
|
||||
|
||||
public:
|
||||
dbHandle* SQLDb; /* PostgreSQL Database */
|
||||
string confSqlHost;
|
||||
string confSqlPass;
|
||||
string confSqlDb;
|
||||
string confSqlPort;
|
||||
string confSqlUser;
|
||||
string confCCChan;
|
||||
short connectRetries;
|
||||
unsigned int connectCheckFreq;
|
||||
unsigned int connectRetry;
|
||||
unsigned int limitCheckPeriod;
|
||||
|
||||
void checkDbConnectionStatus();
|
||||
string pendingPageURL;
|
||||
|
||||
cservice(const string& args);
|
||||
virtual ~cservice();
|
||||
|
||||
virtual void OnConnect();
|
||||
virtual void BurstChannels();
|
||||
virtual void OnPrivateMessage( iClient*, const string&,
|
||||
bool = false );
|
||||
virtual void OnAttach() ;
|
||||
virtual void OnShutdown( const string&);
|
||||
virtual bool isOnChannel( const string& ) const;
|
||||
virtual bool RegisterCommand( Command* ) ;
|
||||
virtual bool UnRegisterCommand( const string& ) ;
|
||||
virtual void OnChannelMode( Channel*, ChannelUser*,
|
||||
const xServer::modeVectorType& );
|
||||
virtual void OnChannelModeV( Channel*, ChannelUser*,
|
||||
const xServer::voiceVectorType& ) ;
|
||||
virtual void OnChannelModeO( Channel*, ChannelUser*,
|
||||
const xServer::opVectorType& ) ;
|
||||
virtual void OnChannelModeL( Channel*,
|
||||
bool, ChannelUser*, const unsigned int& );
|
||||
virtual void OnChannelModeK( Channel*,
|
||||
bool, ChannelUser*, const string& );
|
||||
virtual void OnChannelModeB( Channel*, ChannelUser*,
|
||||
const xServer::banVectorType& ) ;
|
||||
virtual void OnChannelEvent( const channelEventType& whichEvent,
|
||||
Channel* theChan,
|
||||
void* data1, void* data2, void* data3, void* data4 );
|
||||
virtual void OnEvent( const eventType&,
|
||||
void*, void*, void*, void*);
|
||||
virtual void OnCTCP( iClient* Sender,
|
||||
const string& CTCP,
|
||||
const string& Message,
|
||||
bool Secure = false ) ;
|
||||
virtual void OnTimer(const xServer::timerID&, void*);
|
||||
virtual bool Notice( const iClient* Target,
|
||||
const char* Message, ... ) ;
|
||||
virtual bool Notice( const iClient* Target, const string& ) ;
|
||||
virtual bool Notice( const std::string& Channel,
|
||||
const char* Message, ... ) ;
|
||||
virtual void OnWhois( iClient* sourceClient,
|
||||
iClient* targetClient );
|
||||
|
||||
/* Sends a notice to a channel from the server. */
|
||||
bool serverNotice( Channel*, const char*, ... );
|
||||
bool serverNotice( Channel*, const string& );
|
||||
|
||||
/* Log an administrative alert to the relay channel & log. */
|
||||
bool logAdminMessage(const char*, ... );
|
||||
|
||||
/* Log a priveleged administrative alert to the priv relay channel */
|
||||
bool logPrivAdminMessage(const char*, ... );
|
||||
|
||||
/* Log an debug message to the debug channel */
|
||||
bool logDebugMessage(const char*, ... );
|
||||
|
||||
/* Log into adminlog table the specified command string */
|
||||
bool sqlLogCommand(iClient*, const char*, ... );
|
||||
|
||||
/* Write a channel log */
|
||||
void writeChannelLog(sqlChannel*, iClient*, unsigned short, const string&);
|
||||
|
||||
/* get last channel event for specific timestamp */
|
||||
const string getLastChannelEvent(sqlChannel* theChannel,
|
||||
unsigned short eventType, unsigned int& eventTime);
|
||||
|
||||
typedef commandMapType::const_iterator constCommandIterator ;
|
||||
constCommandIterator command_begin() const
|
||||
{ return commandMap.begin() ; }
|
||||
|
||||
constCommandIterator command_end() const
|
||||
{ return commandMap.end() ; }
|
||||
|
||||
constCommandIterator findCommand( const string& theComm ) const
|
||||
{ return commandMap.find( theComm ) ; }
|
||||
|
||||
typedef map< string, csGline* > glineListType ;
|
||||
glineListType glineList ;
|
||||
|
||||
typedef glineListType::iterator glineIterator;
|
||||
|
||||
glineIterator gline_begin()
|
||||
{ return glineList.begin() ; }
|
||||
|
||||
glineIterator gline_end()
|
||||
{ return glineList.end() ; }
|
||||
|
||||
|
||||
/* returns true is IPR checking is required for this user */
|
||||
bool needIPRcheck( sqlUser* );
|
||||
|
||||
/* Returns the access sqlUser has in channel sqlChan. */
|
||||
short getAccessLevel( sqlUser*, sqlChannel* );
|
||||
|
||||
/* Returns the access sqlUser has in channel sqlChan taking into account
|
||||
* suspensions, etc.
|
||||
* If "bool" is true, then send sqlUser a notice about why they don't
|
||||
* have a particular access. */
|
||||
short getEffectiveAccessLevel( sqlUser*, sqlChannel*, bool );
|
||||
|
||||
/* Check if a client has passed IP restriction checks */
|
||||
bool passedIPR( iClient* );
|
||||
|
||||
/* Set (or clear) a client's IP restriction timestamp */
|
||||
void setIPRts( iClient*, unsigned int );
|
||||
|
||||
/* Checks a user against IP restrictions */
|
||||
bool checkIPR( iClient*, sqlUser* );
|
||||
|
||||
/* Get failed login counter for client */
|
||||
unsigned int getFailedLogins( iClient* );
|
||||
|
||||
/* Set failed login counter for client */
|
||||
void setFailedLogins( iClient*, unsigned int );
|
||||
|
||||
/* Returns what admin access a user has. */
|
||||
short getAdminAccessLevel( sqlUser*, bool = false);
|
||||
|
||||
/* Returns what access a user has in the coder channel */
|
||||
short getCoderAccessLevel( sqlUser* );
|
||||
|
||||
/* Fetch a user record for a user. */
|
||||
sqlUser* getUserRecord( const string& );
|
||||
|
||||
/* Fetch a user record for a user by Id number. (Seven) */
|
||||
sqlUser* getUserRecord( int );
|
||||
|
||||
/* Update a usernamerecord for a user in the user cache. */
|
||||
void updateUserCacheUserName(sqlUser*, const string& );
|
||||
|
||||
/* Checks if this client is logged in, returns a sqlUser if true.
|
||||
* If "bool" is true, send a notice to the client telling them off. */
|
||||
sqlUser* isAuthed(iClient*, bool );
|
||||
|
||||
/* Checks to see if this users is forced on this channel */
|
||||
unsigned short isForced(sqlChannel*, sqlUser*);
|
||||
|
||||
/* Fetch a channel record for a channel. */
|
||||
sqlChannel* getChannelRecord( const string& );
|
||||
sqlChannel* getChannelRecord( int );
|
||||
|
||||
/* Fetch a access level record for a user/channel combo. */
|
||||
sqlLevel* getLevelRecord(sqlUser*, sqlChannel*);
|
||||
|
||||
/* Fetch the user status flags. L = in cache, P = got password, U = Is authed. */
|
||||
string userStatusFlags( const string& );
|
||||
|
||||
/* Returns the current "Flood Points" this iClient has. */
|
||||
unsigned short getFloodPoints(iClient*);
|
||||
|
||||
/* Sets the flood counter for this iClient. */
|
||||
void setFloodPoints(iClient*, unsigned short);
|
||||
|
||||
/* Determins if a client is in "Flooded" state, and if so Notice them. */
|
||||
bool hasFlooded(iClient*, const string&);
|
||||
|
||||
/* Check if the nickname is already belongs to a sqlUser */
|
||||
string NickIsRegisteredTo(const string&);
|
||||
|
||||
/* generate a not used nickname based on a starting nickname */
|
||||
void generateNickName(iClient*);
|
||||
|
||||
/* Check if client's nickname belongs to him, if not generateNickName() */
|
||||
void validateNickName(iClient*);
|
||||
|
||||
/* Sets the timestamp for when we first recieved a msg from this client.
|
||||
* within the flood period. */
|
||||
void setLastRecieved(iClient*, time_t);
|
||||
|
||||
/* Find out when we first heard from this chap. */
|
||||
time_t getLastRecieved(iClient*);
|
||||
|
||||
void setOutputTotal(const iClient* theClient, unsigned int count);
|
||||
unsigned int getOutputTotal(const iClient* theClient);
|
||||
bool hasOutputFlooded(iClient*);
|
||||
|
||||
bool doXQLogin(iServer* , const string&, const string&);
|
||||
|
||||
// Typedef's for user/channel Hashmaps.
|
||||
// User hash, Key is Username.
|
||||
typedef map< string, sqlUser*, noCaseCompare > sqlUserHashType ;
|
||||
|
||||
// Channel hash, Key is channelname.
|
||||
typedef map< string, sqlChannel*, noCaseCompare > sqlChannelHashType ;
|
||||
typedef map< int, sqlChannel* > sqlChannelIDHashType ;
|
||||
|
||||
// Accesslevel cache, key is pair(chanid, userid).
|
||||
typedef map < std::pair <int, int>, sqlLevel* > sqlLevelHashType ;
|
||||
|
||||
/* Silence List */
|
||||
typedef map < string, std::pair < time_t, string > > silenceListType;
|
||||
silenceListType silenceList;
|
||||
|
||||
bool isIgnored(iClient*);
|
||||
void setIgnored(iClient*, bool);
|
||||
|
||||
// Cache of user records.
|
||||
sqlUserHashType sqlUserCache;
|
||||
|
||||
// Cache of channel records.
|
||||
sqlChannelHashType sqlChannelCache;
|
||||
|
||||
// Cache of channel records indexed by channel ID.
|
||||
sqlChannelIDHashType sqlChannelIDCache;
|
||||
|
||||
// Cache of Level records.
|
||||
sqlLevelHashType sqlLevelCache;
|
||||
|
||||
// Some counters for statistical purposes.
|
||||
unsigned int userHits;
|
||||
unsigned int userCacheHits;
|
||||
unsigned int channelHits;
|
||||
unsigned int channelCacheHits;
|
||||
unsigned int levelHits;
|
||||
unsigned int levelCacheHits;
|
||||
unsigned int banHits;
|
||||
unsigned int banCacheHits;
|
||||
unsigned int dbErrors;
|
||||
unsigned int joinCount;
|
||||
|
||||
/* No of seconds offset our local time is from server time. */
|
||||
int dbTimeOffset;
|
||||
|
||||
// To keep track of how many custom data chunks
|
||||
// we have allocated.
|
||||
unsigned int customDataAlloc;
|
||||
|
||||
// Flood/Notice relay channel - Loaded via config.
|
||||
// Added coderChan - Loaded via config.
|
||||
string relayChan;
|
||||
string privrelayChan;
|
||||
string debugChan;
|
||||
string coderChan;
|
||||
|
||||
// Loaded via config.
|
||||
// Interval at which we pick up updates from the Db.
|
||||
int updateInterval;
|
||||
|
||||
// Interval at which we check for expired bans/suspends.
|
||||
int expireInterval;
|
||||
|
||||
// Interval at which we attempt to purge the cache(s).
|
||||
int cacheInterval;
|
||||
|
||||
/* Interval at which we check for new webrelay messages. */
|
||||
int webrelayPeriod;
|
||||
|
||||
/* Duration in seconds at which an idle user/chan/level/ban
|
||||
* record should be purged from the cache. */
|
||||
int idleUserPeriod;
|
||||
int idleChannelPeriod;
|
||||
int idleLevelPeriod;
|
||||
|
||||
/* Interval in hours at which we check the database for last seen users
|
||||
* and should pe purged */
|
||||
int expireDBUserPeriod;
|
||||
|
||||
/* Interval in hours at which we check the database for channels
|
||||
* where manager is missing, and should set MIA flag */
|
||||
int expireDBChannelPeriod;
|
||||
|
||||
/* Duration in days, after the system purge unlogged users */
|
||||
int UsersExpireDBDays;
|
||||
|
||||
/* Duration in seconds at which a 'pending' channel should
|
||||
* be notified that it is so. */
|
||||
int pendingChanPeriod;
|
||||
|
||||
/* Duration in days, after the system starts setting MIA flag on a channel */
|
||||
int startMIA;
|
||||
|
||||
/* Duration in days, after the system purge a MIA flagged channel */
|
||||
int endMIA;
|
||||
|
||||
/* Length of an hour in seconds */
|
||||
int hourSeconds;
|
||||
|
||||
/* Length of a day in seconds */
|
||||
int daySeconds;
|
||||
|
||||
/* MIA starting description */
|
||||
string MIAStartDesc;
|
||||
|
||||
/* MIA URL */
|
||||
string MIAURL;
|
||||
|
||||
/* MIA ending description */
|
||||
string MIAEndDesc;
|
||||
|
||||
/* *** The Judge *** */
|
||||
unsigned int RequiredSupporters;
|
||||
unsigned int JudgeDaySeconds;
|
||||
unsigned int MinDaysBeforeReg;
|
||||
unsigned int MinDaysBeforeSupport;
|
||||
unsigned int MaxConcurrentSupports;
|
||||
//int MaxChannelsOwnCount;
|
||||
unsigned int NoRegDaysOnNOSupport;
|
||||
unsigned int RejectAppOnUserFraud;
|
||||
//int AcceptOnTrafficPass = 1;
|
||||
unsigned int RewievOnObject;
|
||||
unsigned int RewievsExpireTime;
|
||||
unsigned int PendingsExpireTime;
|
||||
unsigned int MaxDays;
|
||||
unsigned int Joins;
|
||||
unsigned int UniqueJoins;
|
||||
unsigned int MinSupporters;
|
||||
unsigned int MinSupportersJoin;
|
||||
unsigned int NotifyDays;
|
||||
unsigned int SupportDays;
|
||||
unsigned int ReviewerId;
|
||||
|
||||
/* Welcome messages for newly registered channels */
|
||||
string welcomeNewChanMessage;
|
||||
string welcomeNewChanTopic;
|
||||
|
||||
typedef map <int, sqlIncompleteChannel*> incompleteChanRegsType;
|
||||
incompleteChanRegsType incompleteChanRegs;
|
||||
|
||||
string validResponseString;
|
||||
void AddToValidResponseString(const string&);
|
||||
inline const string& getCurrentValidResponse() const
|
||||
{ return validResponseString; }
|
||||
|
||||
unsigned int getPendingChanId(const string&);
|
||||
const string getPendingChanName(unsigned int);
|
||||
bool isValidUser(const string&);
|
||||
bool isValidUser(const string&, iClient*);
|
||||
bool isValidSupporter(const string&);
|
||||
//bool isValidApplicant(const string&);
|
||||
bool isValidApplicant(sqlUser*);
|
||||
bool isValidChannel(const string&);
|
||||
bool isValidChannel(const string&, iClient*);
|
||||
bool RejectChannel(unsigned int, const string&);
|
||||
bool RewievChannel(unsigned int);
|
||||
bool AcceptChannel(unsigned int, const string&);
|
||||
bool sqlRegisterChannel(iClient*, sqlUser*, const string&);
|
||||
bool wipeChannel(unsigned int);
|
||||
void checkValidUsersAndChannelsState();
|
||||
void checkIncomings();
|
||||
void checkTrafficPass();
|
||||
void checkObjections();
|
||||
void checkAccepts();
|
||||
void checkRewievs();
|
||||
void cleanUpPendings();
|
||||
void loadIncompleteChanRegs();
|
||||
|
||||
/* End of The Judge */
|
||||
|
||||
// Input flood rate.
|
||||
unsigned int input_flood;
|
||||
unsigned int output_flood;
|
||||
int flood_duration;
|
||||
int topic_duration;
|
||||
|
||||
// Timestamp's of when we last checked the database for updates.
|
||||
time_t lastChannelRefresh;
|
||||
time_t lastUserRefresh;
|
||||
time_t lastLevelRefresh;
|
||||
time_t lastBanRefresh;
|
||||
|
||||
/* TimerID for checking on the database connection. */
|
||||
xServer::timerID dBconnection_timerID;
|
||||
|
||||
/* TimerID we recieve for checking for changes in the Db. */
|
||||
xServer::timerID update_timerID;
|
||||
|
||||
/* TimerID we recieve every XX seconds for expiration of bans/suspend. */
|
||||
xServer::timerID expire_timerID;
|
||||
|
||||
/* TimerID we recieve every XX hours for expiration of databse users. */
|
||||
xServer::timerID users_expire_timerID;
|
||||
|
||||
/* TimerID we recieve every XX hours for expiration of databse channels. */
|
||||
xServer::timerID channels_expire_timerID;
|
||||
|
||||
/* TimerID we recieve every XX hours for expiration of cached entries. */
|
||||
xServer::timerID cache_timerID;
|
||||
|
||||
/* TimerID we recieve every XX hours for the notification of pending channels. */
|
||||
xServer::timerID pending_timerID;
|
||||
|
||||
/* TimerID we recieve every seconds when we should check if a channel limit needs changing */
|
||||
xServer::timerID limit_timerID;
|
||||
|
||||
/* TimerID for checking for web-relay messages */
|
||||
xServer::timerID webrelay_timerID;
|
||||
|
||||
// Language definitions table (Loaded from Db).
|
||||
typedef map < string, std::pair <int, string> > languageTableType;
|
||||
languageTableType languageTable;
|
||||
|
||||
// Language translations table (Loaded from Db).
|
||||
typedef map < std::pair <int, int>, string > translationTableType ;
|
||||
translationTableType translationTable;
|
||||
|
||||
void loadTranslationTable();
|
||||
|
||||
int rehashMOTD();
|
||||
|
||||
// Method to retrieve a translation string.
|
||||
const string getResponse( sqlUser*, int , string = string() );
|
||||
|
||||
// Check for valid hostmask.
|
||||
virtual bool validUserMask(const string& userMask) const ;
|
||||
|
||||
/* Help topics (Loaded from Db) */
|
||||
typedef map < std::pair <int, string>, string > helpTableType;
|
||||
helpTableType helpTable;
|
||||
|
||||
void loadHelpTable();
|
||||
const string getHelpMessage(sqlUser*, string);
|
||||
|
||||
/**
|
||||
* Count channel ops.
|
||||
*/
|
||||
static size_t countChanOps(const Channel*);
|
||||
|
||||
void deVoiceAllOnChan(Channel*);
|
||||
|
||||
// Deop everyone on this channel.
|
||||
void deopAllOnChan(Channel*);
|
||||
void deopAllUnAuthedOnChan(Channel*);
|
||||
void deopSuspendedOnChan(Channel*, sqlUser*);
|
||||
void DoTheRightThing(Channel*);
|
||||
void DoTheRightThing();
|
||||
/* Sets a description (url) topic combo. */
|
||||
void doAutoTopic(sqlChannel*);
|
||||
|
||||
/* Automatically updates the floating limit for this channel */
|
||||
void doFloatingLimit(sqlChannel*, Channel*);
|
||||
|
||||
/* Bans & kicks a specified user with a specific reason */
|
||||
bool doInternalBanAndKick(sqlChannel*, iClient*, const string&);
|
||||
|
||||
/* Bans & kicks all client belonging to the IP addrees, with a specific level, period, reason */
|
||||
bool doInternalBanAndKick(sqlChannel*, iClient*, unsigned short, unsigned int, const string& theReason);
|
||||
|
||||
/* Bans & kicks all client belonging to a specified IP addrees, with a specific level, period, reason */
|
||||
bool doInternalBanAndKick(sqlChannel*, unsigned int, unsigned short, unsigned int, const string& theReason);
|
||||
|
||||
/* Suspends a specified user with a specific level, period, reason */
|
||||
bool doInternalSuspend(sqlChannel*, iClient*, unsigned short, unsigned int, const string& theReason);
|
||||
|
||||
/* G-lines a target client to a time-period, with the reason */
|
||||
bool doInternalGline(iClient*, const time_t&, const string&);
|
||||
|
||||
/* G-lines an xIP to a time-period, with the reason */
|
||||
bool doInternalGline(unsigned int, const time_t&, const string&);
|
||||
|
||||
/* Support function to check if a user is banned on a channel. */
|
||||
sqlBan* isBannedOnChan(sqlChannel*, iClient*);
|
||||
|
||||
/* Matches DB bans, and kicks supplied user if neccessary */
|
||||
bool checkBansOnJoin( Channel*, sqlChannel* , iClient* );
|
||||
|
||||
time_t currentTime() const ;
|
||||
|
||||
/* List of channels in 'pending' registration state. */
|
||||
typedef map < string, sqlPendingChannel*, noCaseCompare >
|
||||
pendingChannelListType;
|
||||
pendingChannelListType pendingChannelList;
|
||||
|
||||
/*
|
||||
* Load the pendingChannelList from the database.
|
||||
* This list contains details about channels currently
|
||||
* 'Pending' successful registration.
|
||||
*/
|
||||
|
||||
void loadPendingChannelList();
|
||||
|
||||
/*
|
||||
* Timer Functions.
|
||||
* These support functions are called at periodic
|
||||
* intervals to perform maintainence, etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Expire suspends, ignores and bans respectively.
|
||||
*/
|
||||
void expireSuspends();
|
||||
void expireSilence();
|
||||
void expireBans();
|
||||
bool expireGlines();
|
||||
bool expireWhitelist();
|
||||
|
||||
/*
|
||||
* Cache expiration functions.
|
||||
* To expire idle user/level/ban records from the
|
||||
* cache.
|
||||
* N.B: We'll never expire out channel records because
|
||||
* this information may be used to cancel 'unused'
|
||||
* channels.
|
||||
*/
|
||||
|
||||
void cacheExpireUsers();
|
||||
|
||||
void fixUsersLastSeen();
|
||||
/*
|
||||
* Expire Ban records, only if the channel
|
||||
* record is 'idle'.
|
||||
*/
|
||||
|
||||
void cacheExpireBans();
|
||||
|
||||
/*
|
||||
* Expire idle Level records.
|
||||
*/
|
||||
|
||||
void cacheExpireLevels();
|
||||
|
||||
bool deleteUserFromTable(unsigned int, const string&);
|
||||
bool wipeUser(unsigned int,bool);
|
||||
|
||||
void ExpireUsers();
|
||||
void DeleteChannel(sqlChannel*);
|
||||
void ExpireChannels();
|
||||
|
||||
/*
|
||||
* Process any Postgres notification requests,
|
||||
* reloading cached records if neccessary.
|
||||
*/
|
||||
void processDBUpdates();
|
||||
|
||||
/*
|
||||
* Send a generic Error Message, may log/etc at a later date.
|
||||
*/
|
||||
void dbErrorMessage(iClient*);
|
||||
|
||||
/*
|
||||
* Misc uncategorisable functions.
|
||||
*/
|
||||
|
||||
unsigned int preloadUserDays;
|
||||
|
||||
void preloadBanCache();
|
||||
void preloadChannelCache();
|
||||
void preloadLevelsCache();
|
||||
void preloadUserCache();
|
||||
|
||||
bool loadGlines();
|
||||
|
||||
void updateChannels();
|
||||
void updateUsers();
|
||||
void updateUserLevels(sqlUser*);
|
||||
void updateLevels();
|
||||
void updateBans();
|
||||
|
||||
void updateLimits();
|
||||
|
||||
bool addGline( csGline* );
|
||||
bool remGline( csGline* );
|
||||
csGline* findGline( const string& );
|
||||
|
||||
void addGlineToUplink(csGline* );
|
||||
|
||||
typedef map < string, int > statsMapType;
|
||||
statsMapType statsMap;
|
||||
|
||||
void incStat(const string& name);
|
||||
void incStat(const string& name, unsigned int amount);
|
||||
|
||||
void noticeAllAuthedClients(sqlUser* theUser, const char* Message, ... );
|
||||
void NoteAllAuthedClients(sqlUser* theUser, const char* Message, ... );
|
||||
|
||||
bool isPasswordRight(sqlUser*, const string&);
|
||||
|
||||
unsigned int totalCommands;
|
||||
|
||||
unsigned int loginDelay;
|
||||
|
||||
unsigned int noteDuration;
|
||||
unsigned int noteLimit;
|
||||
unsigned int MAXnotes;
|
||||
|
||||
unsigned int partIdleChan;
|
||||
|
||||
void doCoderStats(iClient* theClient);
|
||||
|
||||
void showAdmins(iClient* theClient);
|
||||
|
||||
typedef map< string, ConfigData*, noCaseCompare > configHashType;
|
||||
configHashType configTable;
|
||||
|
||||
/* Method to retrieve a configuration variable */
|
||||
ConfigData* getConfigVar(const string&);
|
||||
|
||||
/* A dummy config entry with nothing in it. */
|
||||
ConfigData empty_config;
|
||||
|
||||
/*
|
||||
* Method to pre-load the configTable above with everything thats
|
||||
* currently in the database.
|
||||
*/
|
||||
void loadConfigData();
|
||||
|
||||
void outputChannelAccesses(iClient*, sqlUser*, sqlUser*, unsigned int);
|
||||
|
||||
/*
|
||||
* Global filesystem level admin logging stream.
|
||||
*/
|
||||
|
||||
std::ofstream adminLog ;
|
||||
|
||||
string adminlogPath;
|
||||
|
||||
static string CryptPass( const string& pass ) ;
|
||||
|
||||
#ifdef ALLOW_HELLO
|
||||
typedef std::map< int, time_t > helloIPListType ;
|
||||
helloIPListType helloIPList ;
|
||||
unsigned int helloBlockPeriod ;
|
||||
bool helloSendmailEnabled;
|
||||
#endif // ALLOW_HELLO
|
||||
|
||||
string sendmailFrom;
|
||||
bool SendMail(const string& address, const string& subject, const std::stringstream& mailtext);
|
||||
|
||||
#ifdef TOTP_AUTH_ENABLED
|
||||
bool totpAuthEnabled;
|
||||
#endif
|
||||
string HostIsRegisteredTo(const string& );
|
||||
|
||||
typedef std::list<string> reservedHostsListType;
|
||||
reservedHostsListType reservedHostsList;
|
||||
|
||||
bool HostIsReserved(const string& );
|
||||
};
|
||||
|
||||
const string escapeSQLChars(const string& theString);
|
||||
const string searchSQL(const string& theString);
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __CSERVICE_H
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* cserviceCommands.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: cserviceCommands.h,v 1.37 2005/04/03 22:11:45 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CSERVICECOMMANDS_H
|
||||
#define __CSERVICECOMMANDS_H "$Id: cserviceCommands.h,v 1.37 2005/04/03 22:11:45 dan_karrels Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "iClient.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class cservice;
|
||||
class xServer;
|
||||
|
||||
class Command
|
||||
{
|
||||
|
||||
public:
|
||||
Command( cservice* _bot, const string& _commName,
|
||||
const string& _help, unsigned short _flood_points )
|
||||
: bot( _bot ),
|
||||
server( 0 ),
|
||||
commName( _commName ),
|
||||
help( _help ),
|
||||
flood_points( _flood_points )
|
||||
{}
|
||||
virtual ~Command() {}
|
||||
|
||||
/// Exec returns true if the command was successfully
|
||||
/// executed, false otherwise.
|
||||
virtual bool Exec( iClient*, const string& ) = 0 ;
|
||||
|
||||
void setServer( xServer* _server )
|
||||
{ server = _server ; }
|
||||
virtual string getInfo() const
|
||||
{ return commName + ' ' + help ; }
|
||||
virtual void Usage( iClient* theClient ) ;
|
||||
|
||||
inline const string& getName() const
|
||||
{ return commName ; }
|
||||
inline const string& getHelp() const
|
||||
{ return help ; }
|
||||
inline const unsigned short& getFloodPoints() const
|
||||
{ return flood_points; }
|
||||
|
||||
protected:
|
||||
cservice* bot ;
|
||||
xServer* server ;
|
||||
string commName ;
|
||||
string help ;
|
||||
unsigned short flood_points ;
|
||||
|
||||
} ;
|
||||
|
||||
#define DECLARE_COMMAND(commName) \
|
||||
class commName##Command : public Command \
|
||||
{ \
|
||||
public: \
|
||||
commName##Command( cservice* _bot, \
|
||||
const string& _commName, \
|
||||
const string& _help, \
|
||||
unsigned short _flood_points) \
|
||||
: Command( _bot, _commName, _help, _flood_points ) \
|
||||
{} \
|
||||
virtual bool Exec( iClient*, const string& ) ; \
|
||||
virtual ~commName##Command() {} \
|
||||
} ;
|
||||
|
||||
// Level 0 commands.
|
||||
|
||||
DECLARE_COMMAND( SHOWCOMMANDS )
|
||||
DECLARE_COMMAND( LOGIN )
|
||||
DECLARE_COMMAND( SEARCH )
|
||||
DECLARE_COMMAND( ACCESS )
|
||||
DECLARE_COMMAND( CHANINFO )
|
||||
DECLARE_COMMAND( MOTD )
|
||||
DECLARE_COMMAND( HELP )
|
||||
DECLARE_COMMAND( ISREG )
|
||||
DECLARE_COMMAND( SHOWIGNORE )
|
||||
DECLARE_COMMAND( VERIFY )
|
||||
DECLARE_COMMAND( RANDOM )
|
||||
DECLARE_COMMAND( SUPPORT )
|
||||
DECLARE_COMMAND( NOTE )
|
||||
DECLARE_COMMAND( OBJECT )
|
||||
DECLARE_COMMAND( CANCEL )
|
||||
|
||||
// Channel user level commands.
|
||||
|
||||
DECLARE_COMMAND( OP )
|
||||
DECLARE_COMMAND( HALFOP )
|
||||
DECLARE_COMMAND( VOICE )
|
||||
DECLARE_COMMAND( DEOP )
|
||||
DECLARE_COMMAND( DEHALFOP )
|
||||
DECLARE_COMMAND( DEVOICE )
|
||||
DECLARE_COMMAND( ADDUSER )
|
||||
DECLARE_COMMAND( REMUSER )
|
||||
DECLARE_COMMAND( MODINFO )
|
||||
DECLARE_COMMAND( SET )
|
||||
DECLARE_COMMAND( INVITE )
|
||||
DECLARE_COMMAND( TOPIC )
|
||||
DECLARE_COMMAND( BANLIST )
|
||||
DECLARE_COMMAND( KICK )
|
||||
DECLARE_COMMAND( STATUS )
|
||||
DECLARE_COMMAND( SUSPEND )
|
||||
DECLARE_COMMAND( UNSUSPEND )
|
||||
DECLARE_COMMAND( BAN )
|
||||
DECLARE_COMMAND( UNBAN )
|
||||
DECLARE_COMMAND( LBANLIST )
|
||||
DECLARE_COMMAND( NEWPASS )
|
||||
DECLARE_COMMAND( JOIN )
|
||||
DECLARE_COMMAND( PART )
|
||||
DECLARE_COMMAND( CLEARMODE )
|
||||
DECLARE_COMMAND( SUSPENDME )
|
||||
|
||||
// IRCop commands.
|
||||
|
||||
DECLARE_COMMAND( OPERJOIN )
|
||||
DECLARE_COMMAND( OPERPART )
|
||||
|
||||
// Admin level commands.
|
||||
|
||||
DECLARE_COMMAND( WHITELIST )
|
||||
DECLARE_COMMAND( SCAN )
|
||||
DECLARE_COMMAND( SCANHOST )
|
||||
DECLARE_COMMAND( SCANUNAME )
|
||||
DECLARE_COMMAND( SCANEMAIL )
|
||||
DECLARE_COMMAND( REGISTER )
|
||||
DECLARE_COMMAND( REMOVEALL )
|
||||
DECLARE_COMMAND( PURGE )
|
||||
DECLARE_COMMAND( ACCEPT )
|
||||
DECLARE_COMMAND( REJECT )
|
||||
DECLARE_COMMAND( RENAME )
|
||||
DECLARE_COMMAND( FORCE )
|
||||
DECLARE_COMMAND( UNFORCE )
|
||||
DECLARE_COMMAND( REMIGNORE )
|
||||
DECLARE_COMMAND( SERVNOTICE )
|
||||
DECLARE_COMMAND( SAY )
|
||||
DECLARE_COMMAND( QUOTE )
|
||||
DECLARE_COMMAND( REHASH )
|
||||
DECLARE_COMMAND( STATS )
|
||||
DECLARE_COMMAND( ADDCOMMENT )
|
||||
DECLARE_COMMAND( SHUTDOWN )
|
||||
DECLARE_COMMAND( HELLO )
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __CSERVICECOMMANDS_H
|
||||
@@ -0,0 +1,195 @@
|
||||
/**
|
||||
* cservice_config.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: cservice_config.h,v 1.14 2012/06/02 22:23:12 Seven Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CSERVICE_CONFIG_H
|
||||
#define __CSERVICE_CONFIG_H "$Id: cservice_config.h,v 1.14 2012/06/02 22:23:12 Seven Exp $"
|
||||
|
||||
/**
|
||||
* Define this if you wish for all SQL queries to be sent
|
||||
* the standard logging stream (elog).
|
||||
*/
|
||||
#define LOG_SQL
|
||||
|
||||
/**
|
||||
* Define this if you wish to log all cache hits.
|
||||
*/
|
||||
#define LOG_CACHE_HITS
|
||||
|
||||
/**
|
||||
* Define this if you wish for general debugging information
|
||||
* be logged.
|
||||
*/
|
||||
#define LOG_DEBUG
|
||||
|
||||
/**
|
||||
* The maximum number of results to return to the user on
|
||||
* an LBANLIST query.
|
||||
*/
|
||||
#define MAX_LBAN_RESULTS 10
|
||||
|
||||
/**
|
||||
* The maximum number of results to return to the user on
|
||||
* an ACCESS query.
|
||||
*/
|
||||
#define MAX_ACCESS_RESULTS 15
|
||||
|
||||
/**
|
||||
* The maximum number of search results to return to the user.
|
||||
*/
|
||||
#define MAX_SEARCH_RESULTS 10
|
||||
|
||||
/**
|
||||
* Do you want NEWPASS command or not?
|
||||
*/
|
||||
|
||||
#undef USE_NEWPASS
|
||||
|
||||
/**
|
||||
* Do you want to use the Noteserv functionality?
|
||||
*/
|
||||
|
||||
#define USE_NOTICES
|
||||
|
||||
/**
|
||||
* Do you want to use the Notices about any modification state?
|
||||
*/
|
||||
|
||||
#define USE_NOTES
|
||||
|
||||
/**
|
||||
* Do you want normal users to use the Noteserv functionality?
|
||||
*/
|
||||
|
||||
#define USE_USERS_NOTES
|
||||
|
||||
/**
|
||||
* Normal users can send notes to admins?
|
||||
*/
|
||||
|
||||
#define USERS_NOTE_ADMINS
|
||||
|
||||
/**
|
||||
* Do you want users and admins to get notification about their modification status?
|
||||
*/
|
||||
|
||||
#define USE_MODINFO_NOTES
|
||||
|
||||
/**
|
||||
* Users are able to set their URL(DESC,MOTTO)?
|
||||
*/
|
||||
|
||||
#define USE_USERS_URL
|
||||
|
||||
/**
|
||||
* Do you want silly oper-type people to mess around with channels?
|
||||
*/
|
||||
|
||||
#define USE_OPERPARTJOIN
|
||||
|
||||
/**
|
||||
* Do you want users to have the ability to set their own MAXLOGINS setting?
|
||||
*/
|
||||
|
||||
#define USE_SETMAXLOGINS
|
||||
|
||||
/**
|
||||
* Define this if you want to enable the HELLO command.
|
||||
*/
|
||||
#undef ALLOW_HELLO
|
||||
|
||||
/**
|
||||
* Define this if you want users to use HELLO command.
|
||||
*/
|
||||
#undef ALLOW_USERS_HELLO
|
||||
|
||||
/**
|
||||
* Define this if you want users to start channel registration process on IRC.
|
||||
* If it's disabled they are redirected to use website registration.
|
||||
*/
|
||||
#undef ALLOW_IRC_CHANREG
|
||||
|
||||
/**
|
||||
* Define this if you want to enable the WELCOME feature.
|
||||
*/
|
||||
#define USE_WELCOME
|
||||
|
||||
/**
|
||||
* Define this if you want the IP restriction to default to REJECT when no
|
||||
* entries are in the SQL table. Default setting allows login from any IP
|
||||
* if there are no entries for the username in the SQL table.
|
||||
*/
|
||||
#undef IPR_DEFAULT_REJECT
|
||||
|
||||
/**
|
||||
* Define this if you want to enable the 'cs.log' file (log of all commands
|
||||
* including login) - Default is to NOT enable the log as it poses a security
|
||||
* risk (it contains passwords)
|
||||
*/
|
||||
#undef USE_COMMAND_LOG
|
||||
|
||||
/**
|
||||
* Define this if you want TOTP authentication, note you must have liboath
|
||||
* installed, and configure --with-liboath for totp to work
|
||||
*/
|
||||
#undef TOTP_AUTH_ENABLED
|
||||
|
||||
/*
|
||||
* Do you want X to show and log OPMODES?
|
||||
*/
|
||||
#define CATCH_OPMODES
|
||||
|
||||
/**
|
||||
* Enable ANTITAKE channel flag and function?
|
||||
* Protection against msg X ban #chan *!*@*
|
||||
* Measures against the offender: suspend, remuser, kickban, etc.
|
||||
*/
|
||||
#define USE_NOTAKE
|
||||
|
||||
/**
|
||||
* Define this if you're using gnuworld with nefarious2 ircd
|
||||
* and want to enable features like nick registration
|
||||
*/
|
||||
#define USING_NEFARIOUS
|
||||
|
||||
/**
|
||||
* Define this if you're using gnuworld with nefarious2 ircd
|
||||
* and want to enable halfop.
|
||||
* Note: USING_NEFARIOUS must be enabled!
|
||||
*/
|
||||
#define USE_HALFOPS
|
||||
|
||||
/**
|
||||
* Enable this if you don't want users to set 'exotic' hostnames
|
||||
* like with colors, etc.
|
||||
*/
|
||||
#define VALIDATE_SET_HOSTNAME
|
||||
|
||||
/**
|
||||
* Enable this if you want to allow admins and opers to set restricted/reserved hosts
|
||||
*/
|
||||
#define ADMINS_USE_RESTRICTED_SETHOSTS
|
||||
|
||||
/**
|
||||
* Define this if you want to enable coder-access levels in VERIFYCommand
|
||||
*/
|
||||
#define USE_CODER_LEVELS
|
||||
|
||||
#endif // __CSERVICE_CONFIG_H
|
||||
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* levels.h
|
||||
*
|
||||
* 20/12/2000 - Perry Lorier <perry@coders.net>
|
||||
* Initial Version.
|
||||
*
|
||||
* Defines access level constants for use in command handlers.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: levels.h,v 1.4 2012/04/27 20:57:06 Seven Exp $
|
||||
*/
|
||||
|
||||
#ifndef __LEVELS_H
|
||||
#define __LEVELS_H "$Id: levels.h,v 1.4 2012/04/27 20:57:06 Seven Exp $"
|
||||
|
||||
namespace gnuworld {
|
||||
|
||||
namespace adminlevel {
|
||||
const int adduser = 800;
|
||||
const int remuser = 800;
|
||||
const int modinfo = 800;
|
||||
const int suspend = 600;
|
||||
const int unsuspend = 800;
|
||||
}
|
||||
|
||||
namespace level {
|
||||
const int access = 0;
|
||||
const int banlist = 0;
|
||||
const int chaninfo = 0;
|
||||
const int deauth = 0; // Depreciated?
|
||||
const int help = 0;
|
||||
const int lbanlist = 0;
|
||||
const int map = 0;
|
||||
const int motd = 0;
|
||||
|
||||
const int status = 1;
|
||||
const int force = 1; // And by definition, unforce.
|
||||
const int modinfo_autoinvite = 1;
|
||||
|
||||
const int voice = 25;
|
||||
const int devoice = 25;
|
||||
|
||||
const int kick = 50;
|
||||
const int topic = 50;
|
||||
|
||||
const int ban = 75;
|
||||
const int unban = 75;
|
||||
|
||||
const int dehalfop = 75;
|
||||
const int halfop = 75;
|
||||
|
||||
const int deop = 100;
|
||||
const int op = 100;
|
||||
const int invite = 100;
|
||||
const int suspend = 100;
|
||||
const int unsuspend = 100;
|
||||
|
||||
const int masskick = 200;
|
||||
const int status2 = 200; // Users can see the channel modes too
|
||||
|
||||
const int adduser = 400;
|
||||
const int clearmode = 400;
|
||||
const int modinfo = 400;
|
||||
const int remuser = 400;
|
||||
|
||||
const int join = 450;
|
||||
const int part = 500;
|
||||
const int setcmd = 450;
|
||||
|
||||
const int logs = 501; // Level that logs are visible at
|
||||
|
||||
const int addcommentcmd = 600;
|
||||
const int scanuname = 600;
|
||||
const int scanhost = 600;
|
||||
const int scanemail = 600;
|
||||
const int whitelist = 750;
|
||||
const int whitelistadmin = 800;
|
||||
const int registercmd = 750;
|
||||
const int globalsuspend = 750;
|
||||
const int rehash_admin = 800;
|
||||
const int rehash_coder = 900;
|
||||
|
||||
const int hello = 750;
|
||||
const int chanpurge = 750;
|
||||
const int userpurge = 750;
|
||||
const int removeall = 750;
|
||||
const int accept = 750;
|
||||
const int reject = 750;
|
||||
|
||||
const int remignore = 600;
|
||||
|
||||
const int servnotice = 800;
|
||||
const int say = 800;
|
||||
const int rename = 951;
|
||||
|
||||
const int nickset = 951;
|
||||
const int newpass = 951;
|
||||
|
||||
// Debug Commands
|
||||
const int shutdown = 900;
|
||||
const int quote = 1000;
|
||||
|
||||
namespace set {
|
||||
|
||||
const int floodpro = 400;
|
||||
const int alwaysop = 450;
|
||||
const int userflag = 450;
|
||||
const int autotopic = 450;
|
||||
const int url = 450;
|
||||
const int massdeoppro = 500;
|
||||
const int keywords = 450;
|
||||
const int floatlim = 450;
|
||||
|
||||
const int desc = 450;
|
||||
const int mode = 450;
|
||||
const int welcome = 450;
|
||||
const int notake = 500;
|
||||
const int novoice = 450;
|
||||
const int noop = 500;
|
||||
const int oponly = 500;
|
||||
const int strictop = 500;
|
||||
const int lang = 500;
|
||||
const int autojoin = 500;
|
||||
|
||||
const int nopurge = 501;
|
||||
const int comment = 600;
|
||||
const int locked = 600;
|
||||
const int special = 1000; //750
|
||||
const int noreg = 750;
|
||||
const int neverreg = 750;
|
||||
const int suspend = 600;
|
||||
const int tempman = 501;
|
||||
const int caution = 501;
|
||||
const int vacation = 501;
|
||||
const int mia = 600;
|
||||
const int noforce = 1000;
|
||||
}
|
||||
|
||||
namespace immune {
|
||||
const int massdeop = 450;
|
||||
const int suspendop = 450; // Immune from op'ing a suspended user.
|
||||
const int floodpro = 501;
|
||||
const int registercmd = 750;
|
||||
const int noforce = 1000;
|
||||
}
|
||||
|
||||
namespace admin {
|
||||
const int base = 1;
|
||||
const int helper = 500;
|
||||
const int admin = 949;
|
||||
const int coder = 1000;
|
||||
}
|
||||
|
||||
namespace coder {
|
||||
const int base = 1;
|
||||
const int contrib = 200;
|
||||
const int devel = 400;
|
||||
const int senior = 499;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* networkData.cc
|
||||
*
|
||||
* This class is used for storing/modifying "Runtime" specific data
|
||||
* applicable to a active iClient on the network.
|
||||
*
|
||||
* N.B: ENSURE this class is free'd on EVENT QUIT/KILL for the iClient
|
||||
* is it relating too or it'll leak. :)
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: networkData.cc,v 1.9 2005/12/27 13:27:59 kewlio Exp $
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "networkData.h"
|
||||
|
||||
const char networkData_h_rcsId[] = __NETWORKDATA_H ;
|
||||
const char networkData_cc_rcsId[] = "$Id: networkData.cc,v 1.9 2005/12/27 13:27:59 kewlio Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
|
||||
networkData::networkData()
|
||||
: messageTime( 0 ),
|
||||
outputCount( 0 ),
|
||||
flood_points( 0 ),
|
||||
currentUser( 0 ),
|
||||
ignored( false ),
|
||||
ipr_ts( 0 ),
|
||||
failed_logins( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
networkData::~networkData()
|
||||
{}
|
||||
|
||||
} // Namespace gnuworld.
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* networkData.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: networkData.h,v 1.9 2005/12/27 13:27:59 kewlio Exp $
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKDATA_H
|
||||
#define __NETWORKDATA_H "$Id: networkData.h,v 1.9 2005/12/27 13:27:59 kewlio Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
class sqlUser;
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class networkData
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
networkData() ;
|
||||
virtual ~networkData() ;
|
||||
|
||||
// Timestamp of when last message was recieved from this user.
|
||||
time_t messageTime;
|
||||
|
||||
// Count of all bytes outputted to this client.
|
||||
unsigned int outputCount;
|
||||
|
||||
// Total flood points accumulated by input from this client.
|
||||
unsigned int flood_points;
|
||||
|
||||
// Pointer to the sqlUser record of this user (if it exists).
|
||||
// Ie: If they're authed.
|
||||
sqlUser* currentUser;
|
||||
|
||||
// Are we ignored or not..
|
||||
bool ignored;
|
||||
|
||||
/* timestamp of the IP restriction that this client matched */
|
||||
unsigned int ipr_ts;
|
||||
|
||||
/* number of failed login attempts by this client */
|
||||
unsigned int failed_logins;
|
||||
} ;
|
||||
|
||||
#endif // __NETWORKDATA_H
|
||||
|
||||
} // Namespace gnuworld
|
||||
@@ -0,0 +1,254 @@
|
||||
/**
|
||||
* responses.h
|
||||
*
|
||||
* 28/12/2000 - Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
*
|
||||
* Defines 'response' ID's, unique references to textual responses
|
||||
* from the bot.
|
||||
*
|
||||
* Added NOFORCE, insufficient access for AUTOVOICE an AUTOOP responses - Seven <gergo_f@yahoo.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: responses.h,v 1.3 2012/05/13 01:25:52 Seven Exp $
|
||||
*/
|
||||
|
||||
#ifndef __RESPONSES_H
|
||||
#define __RESPONSES_H "$Id: responses.h,v 1.3 2012/05/13 01:25:52 Seven Exp $"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
namespace language
|
||||
{
|
||||
const int already_authed = 1;
|
||||
const int auth_success = 2;
|
||||
const int insuf_access = 3;
|
||||
const int chan_is_empty = 4;
|
||||
const int dont_see_them = 5;
|
||||
const int cant_find_on_chan = 6;
|
||||
const int chan_not_reg = 7;
|
||||
const int youre_opped_by = 8;
|
||||
const int youre_voiced_by = 9;
|
||||
const int youre_not_in_chan = 10;
|
||||
const int already_opped = 11;
|
||||
const int already_voiced = 12;
|
||||
const int youre_deopped_by = 13;
|
||||
const int youre_devoiced_by = 14;
|
||||
const int not_opped = 15;
|
||||
const int not_voiced = 16;
|
||||
const int auth_failed = 17;
|
||||
const int i_am_not_on_chan = 18;
|
||||
const int ban_level_range = 19;
|
||||
const int ban_duration = 20;
|
||||
const int ban_reason_size = 21;
|
||||
const int ban_exists = 22;
|
||||
const int ban_covered = 23;
|
||||
const int inval_min_lvl = 24;
|
||||
const int inval_max_lvl = 25;
|
||||
const int user_access_is = 26;
|
||||
const int channel_automode_is = 27;
|
||||
const int last_mod = 28;
|
||||
const int suspend_expires_in = 29;
|
||||
const int last_seen = 30;
|
||||
const int more_than_max = 31;
|
||||
const int restrict_query = 32;
|
||||
const int end_access_list = 33;
|
||||
const int no_match = 34;
|
||||
const int access_higher = 35;
|
||||
const int inval_access = 36;
|
||||
const int already_in_list = 37;
|
||||
const int add_success = 38;
|
||||
const int its_bad_mmkay = 39;
|
||||
const int end_ban_list = 40;
|
||||
|
||||
// "Unable to view user details (Invisible)"
|
||||
const int no_peeking = 41;
|
||||
const int info_about = 42;
|
||||
const int curr_logged_on = 43;
|
||||
const int url = 44;
|
||||
const int lang = 45;
|
||||
const int channels = 46;
|
||||
const int inp_flood = 47;
|
||||
const int out_flood = 48;
|
||||
const int reg_by = 49;
|
||||
const int last_seen_info = 50;
|
||||
const int desc = 51;
|
||||
const int flood_msg = 52;
|
||||
const int i_almost_flooded = 53;
|
||||
const int incomplete_cmd = 54;
|
||||
const int warn_secure = 55;
|
||||
const int not_logged_in = 56;
|
||||
const int chan_suspended = 57;
|
||||
const int user_suspended = 58;
|
||||
const int warn_noop = 59;
|
||||
const int warn_strictop = 60;
|
||||
const int warn_exceeded_maxdeop = 61;
|
||||
const int syntax = 62;
|
||||
const int temp_inc_access = 63;
|
||||
const int is_reg = 64;
|
||||
const int is_not_reg = 65;
|
||||
const int wouldnt_appreciate = 66;
|
||||
const int lbanlist_for = 67;
|
||||
const int lban_entry = 68;
|
||||
const int lban_added_by = 69;
|
||||
const int lban_since = 70;
|
||||
const int lban_exp = 71;
|
||||
const int lban_end = 72;
|
||||
|
||||
// user, not chan!
|
||||
const int not_registered = 73;
|
||||
const int no_longer_auth = 74;
|
||||
const int doesnt_have_access = 75;
|
||||
const int mod_access_higher = 76;
|
||||
const int cant_give_higher = 77;
|
||||
const int mod_access_to = 78;
|
||||
const int automode_op = 79;
|
||||
const int automode_voice = 80;
|
||||
const int automode_none = 81;
|
||||
const int pass_cant_be_nick = 82;
|
||||
const int pass_changed = 83;
|
||||
const int noop_set = 84;
|
||||
const int strictop_not_authed = 85;
|
||||
const int strictop_insuf_access = 86;
|
||||
const int purged_chan = 87;
|
||||
const int chan_already_reg = 88;
|
||||
const int inval_chan_name = 89;
|
||||
const int regged_chan = 90;
|
||||
const int unsilenced = 91;
|
||||
const int couldnt_find_silence = 92;
|
||||
const int cant_rem_higher = 93;
|
||||
const int cant_rem_owner_self = 94;
|
||||
const int removed_user = 95;
|
||||
const int invis_on = 96;
|
||||
const int invis_off = 97;
|
||||
const int set_cmd_status = 98;
|
||||
const int set_cmd_syntax_on_off = 99;
|
||||
const int userflags_syntax = 100;
|
||||
const int userflags_status = 101;
|
||||
const int massdeoppro_syntax = 102;
|
||||
const int massdeoppro_status = 103;
|
||||
const int floodpro_syntax = 104;
|
||||
const int floodpro_status = 105;
|
||||
const int desc_max_len = 106;
|
||||
const int desc_cleared = 107;
|
||||
const int desc_status = 108;
|
||||
const int url_max_len = 109;
|
||||
const int url_cleared = 110;
|
||||
const int url_status = 111;
|
||||
const int keywords_max_len = 112;
|
||||
const int keywords_status = 113;
|
||||
const int lang_set_to = 114;
|
||||
const int lang_invalid = 115;
|
||||
const int no_such_chan = 116;
|
||||
const int mode_invalid = 117;
|
||||
const int ignore_list_start = 118;
|
||||
const int ignore_list_empty = 119;
|
||||
const int ignore_list_end = 120;
|
||||
const int status_tagline = 121;
|
||||
const int status_chan_rec = 122;
|
||||
const int status_user_rec = 123;
|
||||
const int status_access_rec = 124;
|
||||
const int status_ban_rec = 125;
|
||||
const int status_last_user_not = 126;
|
||||
const int status_last_chan_not = 127;
|
||||
const int status_last_lvl_not = 128;
|
||||
const int status_last_ban_not = 129;
|
||||
const int status_data_alloc = 130;
|
||||
const int status_uptime = 131;
|
||||
const int status_chan_info = 132;
|
||||
const int status_mode = 133;
|
||||
const int status_flags = 134;
|
||||
const int suspend_access_higher = 135;
|
||||
const int bogus_time = 136;
|
||||
const int inval_suspend_dur = 137;
|
||||
const int susp_cancelled = 138;
|
||||
const int already_susp = 139;
|
||||
const int susp_set = 140;
|
||||
const int topic_max_len = 141;
|
||||
const int cant_rem_ban = 142;
|
||||
const int bans_removed = 143;
|
||||
const int rem_temp_access = 144;
|
||||
const int no_forced_access = 145;
|
||||
const int isnt_suspended = 146;
|
||||
const int is_an_ircop = 147;
|
||||
const int is_not_logged_in = 148;
|
||||
const int logged_in_as = 149;
|
||||
const int is_cservice_rep = 150;
|
||||
const int is_cservice_admin = 151;
|
||||
const int is_cservice_dev = 152;
|
||||
const int exc_search = 153;
|
||||
const int restrict_search = 154;
|
||||
const int no_search_match = 155;
|
||||
const int modeclear_done = 156;
|
||||
const int inv_invalid = 157;
|
||||
const int invalid_option = 158;
|
||||
const int is_service_bot = 159;
|
||||
const int is_coder_rep = 160;
|
||||
const int is_coder_contrib = 161;
|
||||
const int is_coder_devel = 162;
|
||||
const int is_coder_senior = 163;
|
||||
const int is_also_an_ircop = 164;
|
||||
const int ban_added = 165;
|
||||
const int ban_list_empty = 166;
|
||||
const int already_on_chan = 167;
|
||||
const int ircops_only_cmd = 168;
|
||||
const int im_not_op = 169;
|
||||
const int rpl_ignorelist = 170;
|
||||
const int im_not_opped = 171;
|
||||
const int keywords = 172;
|
||||
const int no_adduser = 173;
|
||||
const int noadduser_on = 174;
|
||||
const int noadduser_off = 175;
|
||||
const int auth_failed_logins = 176;
|
||||
const int max_failed_logins = 177;
|
||||
const int automode_invite = 178;
|
||||
const int chan_noforce = 179;
|
||||
const int insuff_avoice = 180;
|
||||
const int insuff_aop = 181;
|
||||
const int reason_must = 182;
|
||||
const int susp_reason = 183;
|
||||
const int unsusp_reason = 184;
|
||||
const int have_notes = 185;
|
||||
const int noaccpt_notes = 186;
|
||||
const int exc_max_notes = 187;
|
||||
const int note_sended = 188;
|
||||
const int read_note_help = 189;
|
||||
const int have_nonotes = 190;
|
||||
const int message_id = 191;
|
||||
const int erase_note_help = 192;
|
||||
const int all_notes_erased = 193;
|
||||
const int inv_messageid = 194;
|
||||
const int erased_messageid = 195;
|
||||
const int acc_susp = 196;
|
||||
const int acc_unsusp = 197;
|
||||
const int acc_new = 198;
|
||||
const int acc_modif = 199;
|
||||
const int acc_rem = 200;
|
||||
const int userurl_on = 201;
|
||||
const int userurl_off = 202;
|
||||
const int auth_failed_token = 203;
|
||||
const int novoice_set = 204;
|
||||
const int welcome_max_len = 205;
|
||||
const int welcome_cleared = 206;
|
||||
const int welcome_status = 207;
|
||||
const int is_cservice_alumni = 208;
|
||||
const int greeting = 9998;
|
||||
const int motd = 9999;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* sqlBan.cc
|
||||
*
|
||||
* Storage class for accessing Ban information either from the backend
|
||||
* or internal storage.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlBan.cc,v 1.11 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "sqlBan.h"
|
||||
#include "constants.h"
|
||||
#include "cservice.h"
|
||||
#include "cservice_config.h"
|
||||
#include "nickUserCidr.h"
|
||||
#include "HostBanMatcher.h"
|
||||
#include "CIDRBanMatcher.h"
|
||||
|
||||
const char sqlBan_h_rcsId[] = __SQLBAN_H ;
|
||||
const char sqlBan_cc_rcsId[] = "$Id: sqlBan.cc,v 1.11 2009/06/25 19:05:23 mrbean_ Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
sqlBan::sqlBan(dbHandle* _SQLDb)
|
||||
: id(0),
|
||||
channel_id(0),
|
||||
banmask(),
|
||||
set_by(),
|
||||
set_ts(0),
|
||||
level(0),
|
||||
expires(0),
|
||||
reason(),
|
||||
last_updated(0),
|
||||
SQLDb(_SQLDb)
|
||||
{
|
||||
matcher = NULL;
|
||||
|
||||
}
|
||||
|
||||
void sqlBan::setAllMembers(int row)
|
||||
{
|
||||
/*
|
||||
* Loads data from the Postgres backend.
|
||||
* Assumes SQLDb contains a valid results set for all Ban information.
|
||||
*/
|
||||
|
||||
id = atoi(SQLDb->GetValue(row, 0));
|
||||
channel_id = atoi(SQLDb->GetValue(row, 1));
|
||||
banmask = SQLDb->GetValue(row, 2);
|
||||
set_by = SQLDb->GetValue(row, 3);
|
||||
set_ts = atoi(SQLDb->GetValue(row, 4));
|
||||
level = atoi(SQLDb->GetValue(row, 5));
|
||||
expires = atoi(SQLDb->GetValue(row, 6));
|
||||
reason = SQLDb->GetValue(row, 7);
|
||||
last_updated = atoi(SQLDb->GetValue(row, 8));
|
||||
initMatcher();
|
||||
}
|
||||
|
||||
bool sqlBan::commit()
|
||||
{
|
||||
/*
|
||||
* Build an SQL statement to commit the transient data in this storage class
|
||||
* back into the database.
|
||||
*/
|
||||
|
||||
static const char* queryHeader = "UPDATE bans ";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< "SET channel_id = " << channel_id << ", "
|
||||
<< "set_by = '" << escapeSQLChars(set_by) << "', "
|
||||
<< "set_ts = " << set_ts << ", "
|
||||
<< "level = " << level << ", "
|
||||
<< "expires = " << expires << ", "
|
||||
<< "banmask = '" << escapeSQLChars(banmask) << "', "
|
||||
<< "reason = '" << escapeSQLChars(reason) << "', "
|
||||
<< "last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int "
|
||||
<< " WHERE id = " << id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlBan::commit> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
// TODO: Log to msgchan here.
|
||||
elog << "sqlBan::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool sqlBan::insertRecord()
|
||||
{
|
||||
/*
|
||||
* Build an SQL statement to insert this as a new record in the db.
|
||||
*/
|
||||
|
||||
static const char* queryHeader = "INSERT INTO bans (channel_id,banmask,set_by,set_ts,level,expires,reason,last_updated) VALUES (";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< channel_id << ", '"
|
||||
<< escapeSQLChars(banmask) << "', '"
|
||||
<< escapeSQLChars(set_by) << "', "
|
||||
<< set_ts << ", "
|
||||
<< level << ", "
|
||||
<< expires << ", '"
|
||||
<< escapeSQLChars(reason) << "', "
|
||||
<< "date_part('epoch', CURRENT_TIMESTAMP)::int); SELECT currval('bans_id_seq')"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlBan::insertRecord> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString, true ) )
|
||||
//if( PGRES_TUPLES_OK != status )
|
||||
{
|
||||
// TODO: Log to msgchan here.
|
||||
elog << "sqlBan::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
id = atoi(SQLDb->GetValue(0,0));
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool sqlBan::deleteRecord()
|
||||
{
|
||||
/*
|
||||
* Build an SQL statement to delete this record from the db.
|
||||
*/
|
||||
|
||||
static const char* queryHeader = "DELETE FROM bans WHERE id = ";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlBan::delete> "
|
||||
<< queryString.str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
// TODO: Log to msgchan here.
|
||||
elog << "sqlBan::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void sqlBan::initMatcher()
|
||||
{
|
||||
if(matcher)
|
||||
delete matcher;
|
||||
|
||||
xNickUserCIDR cidr = xNickUserCIDR(banmask);
|
||||
if(cidr.GetValid())
|
||||
{
|
||||
matcher = new CIDRBanMatcher(banmask);
|
||||
} else {
|
||||
matcher = new HostBanMatcher(banmask);
|
||||
}
|
||||
}
|
||||
|
||||
sqlBan::~sqlBan()
|
||||
{
|
||||
if(matcher)
|
||||
delete matcher;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // Namespace gnuworld.
|
||||
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* sqlBan.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlBan.h,v 1.8 2009/06/25 19:05:23 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __SQLBAN_H
|
||||
#define __SQLBAN_H "$Id: sqlBan.h,v 1.8 2009/06/25 19:05:23 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "dbHandle.h"
|
||||
#include "banMatcher.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class sqlBan
|
||||
{
|
||||
|
||||
public:
|
||||
sqlBan(dbHandle*) ;
|
||||
virtual ~sqlBan() ;
|
||||
|
||||
/*
|
||||
* Methods to get data atrributes.
|
||||
*/
|
||||
|
||||
inline const unsigned int& getID() const
|
||||
{ return id ; }
|
||||
|
||||
inline const unsigned int& getChannelID() const
|
||||
{ return channel_id ; }
|
||||
|
||||
inline const string& getBanMask() const
|
||||
{ return banmask ; }
|
||||
|
||||
inline const string& getSetBy() const
|
||||
{ return set_by ; }
|
||||
|
||||
inline const time_t& getSetTS() const
|
||||
{ return set_ts ; }
|
||||
|
||||
inline const unsigned short& getLevel() const
|
||||
{ return level ; }
|
||||
|
||||
inline const time_t& getExpires() const
|
||||
{ return expires ; }
|
||||
|
||||
inline const string& getReason() const
|
||||
{ return reason ; }
|
||||
|
||||
inline const time_t& getLastUpdated() const
|
||||
{ return last_updated ; }
|
||||
|
||||
inline banMatcher* getMatcher() const
|
||||
{ return matcher; }
|
||||
|
||||
/*
|
||||
* Methods to set data atrributes.
|
||||
*/
|
||||
|
||||
inline void setChannelID( const unsigned int& _channel_id )
|
||||
{ channel_id = _channel_id; }
|
||||
|
||||
inline void setBanMask( const string& _banmask )
|
||||
{ banmask = _banmask;
|
||||
initMatcher();}
|
||||
|
||||
inline void setSetBy( const string& _set_by )
|
||||
{ set_by = _set_by; }
|
||||
|
||||
inline void setSetTS( const time_t& _set_ts )
|
||||
{ set_ts = _set_ts; }
|
||||
|
||||
inline void setLevel( const unsigned short& _level )
|
||||
{ level = _level; }
|
||||
|
||||
inline void setExpires( const unsigned int& _expires )
|
||||
{ expires = _expires; }
|
||||
|
||||
inline void setReason( const string& _reason )
|
||||
{ reason = _reason; }
|
||||
|
||||
|
||||
bool commit();
|
||||
bool insertRecord();
|
||||
bool deleteRecord();
|
||||
|
||||
void setAllMembers(int);
|
||||
|
||||
void initMatcher();
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int id ;
|
||||
unsigned int channel_id ;
|
||||
string banmask ;
|
||||
string set_by ;
|
||||
time_t set_ts ;
|
||||
unsigned short level ;
|
||||
time_t expires ;
|
||||
string reason ;
|
||||
time_t last_updated ;
|
||||
|
||||
dbHandle* SQLDb;
|
||||
banMatcher* matcher;
|
||||
} ;
|
||||
|
||||
}
|
||||
#endif // __SQLBAN_H
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
* sqlChannel.cc
|
||||
*
|
||||
* Storage class for accessing user information either from the backend
|
||||
* or internal storage.
|
||||
*
|
||||
* 20/12/2000: Greg Sikorski <gte@atomicrevs.demon.co.uk>
|
||||
* Initial Version.
|
||||
* 30/12/2000: Moved static SQL data to constants.h --Gte
|
||||
* Set loadData up to take data from rows other than 0.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlChannel.cc,v 1.43 2007/08/28 16:10:12 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "sqlChannel.h"
|
||||
#include "constants.h"
|
||||
#include "cservice.h"
|
||||
#include "cservice_config.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
const char sqlChannel_h_rcsId[] = __SQLCHANNEL_H ;
|
||||
const char sqlChannel_cc_rcsId[] = "$Id: sqlChannel.cc,v 1.43 2007/08/28 16:10:12 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::stringstream ;
|
||||
using std::ends ;
|
||||
|
||||
const sqlChannel::flagType sqlChannel::F_NOPURGE = 0x00000001 ;
|
||||
const sqlChannel::flagType sqlChannel::F_SPECIAL = 0x00000002 ;
|
||||
const sqlChannel::flagType sqlChannel::F_NOREG = 0x00000004 ;
|
||||
const sqlChannel::flagType sqlChannel::F_NEVREG = 0x00000008 ;
|
||||
const sqlChannel::flagType sqlChannel::F_SUSPEND = 0x00000010 ;
|
||||
const sqlChannel::flagType sqlChannel::F_TEMP = 0x00000020 ;
|
||||
const sqlChannel::flagType sqlChannel::F_CAUTION = 0x00000040 ;
|
||||
const sqlChannel::flagType sqlChannel::F_VACATION = 0x00000080 ;
|
||||
const sqlChannel::flagType sqlChannel::F_LOCKED = 0x00000100 ;
|
||||
const sqlChannel::flagType sqlChannel::F_FLOATLIM = 0x00000200 ;
|
||||
const sqlChannel::flagType sqlChannel::F_MIA = 0x00000400 ;
|
||||
|
||||
const sqlChannel::flagType sqlChannel::F_ALWAYSOP = 0x00010000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_STRICTOP = 0x00020000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_NOOP = 0x00040000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_AUTOTOPIC = 0x00080000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_OPONLY = 0x00100000 ; // Deprecated
|
||||
const sqlChannel::flagType sqlChannel::F_AUTOJOIN = 0x00200000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_NOFORCE = 0x00400000 ; // Reserved for use by Planetarion.
|
||||
const sqlChannel::flagType sqlChannel::F_NOVOICE = 0x00800000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_NOTAKE = 0x01000000 ;
|
||||
const sqlChannel::flagType sqlChannel::F_FLOODPRO = 0x02000000 ;
|
||||
|
||||
const int sqlChannel::EV_MISC = 1 ;
|
||||
const int sqlChannel::EV_JOIN = 2 ;
|
||||
const int sqlChannel::EV_PART = 3 ;
|
||||
const int sqlChannel::EV_OPERJOIN = 4 ;
|
||||
const int sqlChannel::EV_OPERPART = 5 ;
|
||||
const int sqlChannel::EV_FORCE = 6 ;
|
||||
const int sqlChannel::EV_REGISTER = 7 ;
|
||||
const int sqlChannel::EV_PURGE = 8 ;
|
||||
|
||||
/* Manually added Comment */
|
||||
const int sqlChannel::EV_COMMENT = 9 ;
|
||||
const int sqlChannel::EV_REMOVEALL = 10 ;
|
||||
const int sqlChannel::EV_IDLE = 11 ;
|
||||
|
||||
/* other events */
|
||||
const int sqlChannel::EV_MGRCHANGE = 12 ;
|
||||
const int sqlChannel::EV_ADMREJECT = 13 ;
|
||||
const int sqlChannel::EV_WITHDRAW = 14 ;
|
||||
const int sqlChannel::EV_NEWAPP = 15 ;
|
||||
const int sqlChannel::EV_NONSUPPORT = 16 ;
|
||||
const int sqlChannel::EV_ADMREVIEW = 17 ;
|
||||
const int sqlChannel::EV_CLRREVIEW = 18 ;
|
||||
const int sqlChannel::EV_SUSPEND = 19 ;
|
||||
const int sqlChannel::EV_UNSUSPEND = 20 ;
|
||||
const int sqlChannel::EV_NOFORCE = 21 ;
|
||||
const int sqlChannel::EV_TAKE = 22 ;
|
||||
|
||||
sqlChannel::sqlChannel(dbHandle* _SQLDb)
|
||||
: id(0),
|
||||
name(),
|
||||
flags(0),
|
||||
mass_deop_pro(3),
|
||||
flood_pro(0),
|
||||
url(),
|
||||
description(),
|
||||
comment(),
|
||||
keywords(),
|
||||
welcome(),
|
||||
registered_ts(0),
|
||||
channel_ts(0),
|
||||
channel_mode(),
|
||||
userflags(0),
|
||||
last_topic(0),
|
||||
inChan(false),
|
||||
last_used(0),
|
||||
limit_offset(3),
|
||||
limit_period(20),
|
||||
last_limit_check(0),
|
||||
last_flood(0),
|
||||
limit_grace(2),
|
||||
limit_max(0),
|
||||
max_bans(0),
|
||||
no_take(0),
|
||||
SQLDb( _SQLDb )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool sqlChannel::loadData(const string& channelName)
|
||||
{
|
||||
/*
|
||||
* With the open database handle 'SQLDb', retrieve information about
|
||||
* 'channelName' and fill our member variables.
|
||||
*/
|
||||
|
||||
#ifdef LOG_DEBUG
|
||||
elog << "sqlChannel::loadData> Attempting to load data for"
|
||||
<< " channel-name: "
|
||||
<< channelName
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
stringstream queryString ;
|
||||
queryString << "SELECT "
|
||||
<< sql::channel_fields
|
||||
<< " FROM channels WHERE registered_ts <> 0"
|
||||
<< " AND lower(name) = '"
|
||||
<< escapeSQLChars(string_lower(channelName))
|
||||
<< "'"
|
||||
<< ends ;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlChannel::loadData> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( SQLDb->Exec(queryString, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
/*
|
||||
* If the channel doesn't exist, we won't get any rows back.
|
||||
*/
|
||||
|
||||
if(SQLDb->Tuples() < 1)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
setAllMembers(0);
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool sqlChannel::loadData(int channelID)
|
||||
{
|
||||
/*
|
||||
* With the open database handle 'SQLDb', retrieve information about
|
||||
* 'channelID' and fill our member variables.
|
||||
*/
|
||||
|
||||
#ifdef LOG_DEBUG
|
||||
elog << "sqlChannel::loadData> Attempting to load data for "
|
||||
<< "channel-id: "
|
||||
<< channelID
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "SELECT "
|
||||
<< sql::channel_fields
|
||||
<< " FROM channels WHERE registered_ts <> 0 AND id = "
|
||||
<< channelID
|
||||
<< ends ;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlChannel::loadData> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( SQLDb->Exec(queryString, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
/*
|
||||
* If the channel doesn't exist, we won't get any rows back.
|
||||
*/
|
||||
|
||||
if(SQLDb->Tuples() < 1)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
setAllMembers(0);
|
||||
return (true);
|
||||
}
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
void sqlChannel::setAllMembers(int row)
|
||||
{
|
||||
/*
|
||||
* Support function for both loadData's.
|
||||
* Assumes SQLDb contains a valid results set for all channel information.
|
||||
*/
|
||||
|
||||
id = atoi(SQLDb->GetValue(row, 0).c_str());
|
||||
name = SQLDb->GetValue(row, 1);
|
||||
flags = atoi(SQLDb->GetValue(row, 2).c_str());
|
||||
mass_deop_pro = atoi(SQLDb->GetValue(row,3).c_str());
|
||||
flood_pro = atoi(SQLDb->GetValue(row,4).c_str());
|
||||
url = SQLDb->GetValue(row,5);
|
||||
description = SQLDb->GetValue(row,6);
|
||||
comment = SQLDb->GetValue(row,7);
|
||||
keywords = SQLDb->GetValue(row,8);
|
||||
registered_ts = atoi(SQLDb->GetValue(row,9).c_str());
|
||||
channel_ts = atoi(SQLDb->GetValue(row,10).c_str());
|
||||
channel_mode = SQLDb->GetValue(row,11);
|
||||
userflags = atoi(SQLDb->GetValue(row,12));
|
||||
last_updated = atoi(SQLDb->GetValue(row,13));
|
||||
limit_offset = atoi(SQLDb->GetValue(row,14));
|
||||
limit_period = atoi(SQLDb->GetValue(row,15));
|
||||
limit_grace = atoi(SQLDb->GetValue(row,16));
|
||||
limit_max = atoi(SQLDb->GetValue(row,17));
|
||||
welcome = SQLDb->GetValue(row,18);
|
||||
max_bans = atoi(SQLDb->GetValue(row,19));
|
||||
no_take = atoi(SQLDb->GetValue(row,20));
|
||||
}
|
||||
|
||||
bool sqlChannel::commit()
|
||||
{
|
||||
/*
|
||||
* Build an SQL statement to commit the transient data in this storage class
|
||||
* back into the database.
|
||||
*/
|
||||
|
||||
static const char* queryHeader = "UPDATE channels ";
|
||||
static const char* queryCondition = "WHERE id = ";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< "SET flags = " << flags << ", "
|
||||
<< "mass_deop_pro = " << mass_deop_pro << ", "
|
||||
<< "flood_pro = " << flood_pro << ", "
|
||||
<< "url = '" << escapeSQLChars(url) << "', "
|
||||
<< "keywords = '" << escapeSQLChars(keywords) << "', "
|
||||
<< "welcome = '" << escapeSQLChars(welcome) << "', "
|
||||
<< "registered_ts = " << registered_ts << ", "
|
||||
<< "channel_ts = " << channel_ts << ", "
|
||||
<< "channel_mode = '" << escapeSQLChars(channel_mode) << "', "
|
||||
<< "userflags = " << userflags << ", "
|
||||
<< "last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int, "
|
||||
<< "limit_offset = " << limit_offset << ", "
|
||||
<< "limit_period = " << limit_period << ", "
|
||||
<< "limit_grace = " << limit_grace << ", "
|
||||
<< "limit_max = " << limit_max << ", "
|
||||
<< "max_bans = " << max_bans << ", "
|
||||
<< "description = '" << escapeSQLChars(description) << "', "
|
||||
<< "comment = '" << escapeSQLChars(comment) << "', "
|
||||
<< "no_take = " << no_take << " "
|
||||
<< queryCondition << id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlChannel::commit> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlChannel::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sqlChannel::insertRecord()
|
||||
{
|
||||
static const char* queryHeader = "INSERT INTO channels (name, flags, registered_ts, channel_ts, channel_mode, last_updated) VALUES (";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< "'" << escapeSQLChars(name) << "', "
|
||||
<< flags << ", "
|
||||
<< registered_ts << ", "
|
||||
<< channel_ts << ", '"
|
||||
<< escapeSQLChars(channel_mode) << "', "
|
||||
<< "date_part('epoch', CURRENT_TIMESTAMP)::int)"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlChannel::insertRecord> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
// TODO: Log to msgchan here.
|
||||
elog << "sqlChannel::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlChannel::~sqlChannel()
|
||||
{
|
||||
/* TODO: Clean up bans */
|
||||
}
|
||||
|
||||
} // Namespace gnuworld
|
||||
@@ -0,0 +1,370 @@
|
||||
/**
|
||||
* sqlChannel.h
|
||||
* Author: Greg Sikorski
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlChannel.h,v 1.47 2007/08/28 16:10:12 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __SQLCHANNEL_H
|
||||
#define __SQLCHANNEL_H "$Id: sqlChannel.h,v 1.47 2007/08/28 16:10:12 dan_karrels Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "dbHandle.h"
|
||||
#include "sqlBan.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::map ;
|
||||
using std::vector ;
|
||||
|
||||
class sqlChannel
|
||||
{
|
||||
|
||||
public:
|
||||
sqlChannel(dbHandle*) ;
|
||||
virtual ~sqlChannel() ;
|
||||
|
||||
typedef unsigned int flagType ;
|
||||
|
||||
static const flagType F_NOPURGE;
|
||||
static const flagType F_SPECIAL;
|
||||
static const flagType F_NOREG;
|
||||
static const flagType F_NEVREG;
|
||||
static const flagType F_SUSPEND;
|
||||
static const flagType F_TEMP;
|
||||
static const flagType F_CAUTION;
|
||||
static const flagType F_VACATION;
|
||||
static const flagType F_LOCKED;
|
||||
|
||||
static const flagType F_ALWAYSOP;
|
||||
static const flagType F_STRICTOP;
|
||||
static const flagType F_NOOP;
|
||||
static const flagType F_AUTOTOPIC;
|
||||
static const flagType F_OPONLY; // Deprecated.
|
||||
static const flagType F_AUTOJOIN;
|
||||
static const flagType F_FLOATLIM;
|
||||
static const flagType F_MIA; // MIA review tag
|
||||
static const flagType F_NOFORCE; // Reserved for use by Planetarion.
|
||||
static const flagType F_NOVOICE;
|
||||
static const flagType F_NOTAKE;
|
||||
static const flagType F_FLOODPRO;
|
||||
|
||||
/*
|
||||
* Channel 'Event' Flags, used in the channelog table.
|
||||
* These flags are used to filter channel log records.
|
||||
* in reports.
|
||||
*/
|
||||
|
||||
static const int EV_MISC;
|
||||
static const int EV_JOIN;
|
||||
static const int EV_PART;
|
||||
static const int EV_OPERJOIN;
|
||||
static const int EV_OPERPART;
|
||||
static const int EV_FORCE;
|
||||
static const int EV_REGISTER;
|
||||
static const int EV_PURGE;
|
||||
|
||||
/* Manually added Comment */
|
||||
static const int EV_COMMENT;
|
||||
static const int EV_REMOVEALL;
|
||||
static const int EV_IDLE;
|
||||
|
||||
/* other events */
|
||||
static const int EV_MGRCHANGE;
|
||||
static const int EV_ADMREJECT;
|
||||
static const int EV_WITHDRAW;
|
||||
static const int EV_NEWAPP;
|
||||
static const int EV_NONSUPPORT;
|
||||
static const int EV_ADMREVIEW;
|
||||
static const int EV_CLRREVIEW;
|
||||
static const int EV_SUSPEND;
|
||||
static const int EV_UNSUSPEND;
|
||||
static const int EV_NOFORCE;
|
||||
static const int EV_TAKE;
|
||||
|
||||
/*
|
||||
* Methods to get data attributes.
|
||||
*/
|
||||
|
||||
inline const unsigned int& getID() const
|
||||
{ return id ; }
|
||||
|
||||
inline const string& getName() const
|
||||
{ return name ; }
|
||||
|
||||
inline const flagType& getFlags() const
|
||||
{ return flags ; }
|
||||
|
||||
inline bool getFlag( const flagType& whichFlag ) const
|
||||
{ return (flags & whichFlag) ; }
|
||||
|
||||
inline const unsigned short int& getMassDeopPro() const
|
||||
{ return mass_deop_pro ; }
|
||||
|
||||
inline const unsigned int& getFloodPro() const
|
||||
{ return flood_pro ; }
|
||||
|
||||
inline const string& getURL() const
|
||||
{ return url ; }
|
||||
|
||||
inline const string& getDescription() const
|
||||
{ return description ; }
|
||||
|
||||
inline const string& getComment() const
|
||||
{ return comment ; }
|
||||
|
||||
inline const string& getKeywords() const
|
||||
{ return keywords ; }
|
||||
|
||||
inline const string& getWelcome() const
|
||||
{ return welcome ; }
|
||||
|
||||
inline const time_t& getRegisteredTS() const
|
||||
{ return registered_ts ; }
|
||||
|
||||
inline const time_t& getChannelTS() const
|
||||
{ return channel_ts ; }
|
||||
|
||||
inline const string& getChannelMode() const
|
||||
{ return channel_mode ; }
|
||||
|
||||
inline const unsigned short int& getUserFlags() const
|
||||
{ return userflags ; }
|
||||
|
||||
inline const time_t& getLastUpdated() const
|
||||
{ return last_updated ; }
|
||||
|
||||
inline const bool& getInChan() const
|
||||
{ return inChan; }
|
||||
|
||||
inline const time_t& getLastTopic() const
|
||||
{ return last_topic ; }
|
||||
|
||||
inline const time_t& getLastLimitCheck() const
|
||||
{ return last_limit_check ; }
|
||||
|
||||
inline const time_t& getLastUsed() const
|
||||
{ return last_used ; }
|
||||
|
||||
inline const unsigned int& getLimitOffset() const
|
||||
{ return limit_offset ; }
|
||||
|
||||
inline const time_t& getLimitPeriod() const
|
||||
{ return limit_period ; }
|
||||
|
||||
inline const unsigned int& getLimitGrace() const
|
||||
{ return limit_grace ; }
|
||||
|
||||
inline const unsigned int& getLimitMax() const
|
||||
{ return limit_max ; }
|
||||
|
||||
inline const unsigned int& getMaxBans() const
|
||||
{ return max_bans ; }
|
||||
|
||||
inline const unsigned int& getNoTake() const
|
||||
{ return no_take ; }
|
||||
/**
|
||||
* Load channel data from the backend using the channel name as
|
||||
* a key.
|
||||
*/
|
||||
bool loadData( const string& );
|
||||
|
||||
/**
|
||||
* Load channel data from the backend using the channel_id as a
|
||||
* key.
|
||||
*/
|
||||
bool loadData( int );
|
||||
|
||||
/*
|
||||
* Methods to set data atrributes.
|
||||
*/
|
||||
|
||||
// 'ID' is a primary key and cannot be altered.
|
||||
|
||||
inline void setID( const unsigned int& _id )
|
||||
{ id = _id; }
|
||||
|
||||
inline void setName( const string& _name )
|
||||
{ name = _name; }
|
||||
|
||||
inline void setFlag( const flagType& whichFlag )
|
||||
{ flags |= whichFlag; }
|
||||
|
||||
inline void removeFlag( const flagType& whichFlag )
|
||||
{ flags &= ~whichFlag; }
|
||||
|
||||
inline void clearFlags()
|
||||
{ flags = 0; }
|
||||
|
||||
inline void setMassDeopPro( const unsigned short int& _mass_deop_pro )
|
||||
{ mass_deop_pro = _mass_deop_pro; }
|
||||
|
||||
inline void setFloodPro( const unsigned int& _flood_pro )
|
||||
{ flood_pro = _flood_pro; }
|
||||
|
||||
inline void setAntiFlood( const bool& _antiflood )
|
||||
{ antiflood = _antiflood; }
|
||||
|
||||
inline void setLastFloodTime( const time_t& _last_flood )
|
||||
{ last_flood = _last_flood; }
|
||||
|
||||
inline void setURL( const string& _url )
|
||||
{ url = _url; }
|
||||
|
||||
inline void setDescription( const string& _description )
|
||||
{ description = _description; }
|
||||
|
||||
inline void setComment( const string& _comment )
|
||||
{ comment = _comment; }
|
||||
|
||||
inline void setKeywords( const string& _keywords )
|
||||
{ keywords = _keywords; }
|
||||
|
||||
inline void setWelcome( const string& _welcome )
|
||||
{ welcome = _welcome; }
|
||||
|
||||
inline void setRegisteredTS( const time_t& _registered_ts )
|
||||
{ registered_ts = _registered_ts; }
|
||||
|
||||
inline void setChannelTS( const time_t& _channel_ts )
|
||||
{ channel_ts = _channel_ts; }
|
||||
|
||||
inline void setChannelMode( const string& _channel_mode )
|
||||
{ channel_mode = _channel_mode; }
|
||||
|
||||
inline void setUserFlags( const unsigned short int& _userflags )
|
||||
{ userflags = _userflags; }
|
||||
|
||||
inline void setInChan( const bool& _inChan )
|
||||
{ inChan = _inChan; }
|
||||
|
||||
inline void setLastTopic( const time_t& _last_topic )
|
||||
{ last_topic = _last_topic; }
|
||||
|
||||
inline void setLastLimitCheck( const time_t& _last_limit_check )
|
||||
{ last_limit_check = _last_limit_check; }
|
||||
|
||||
inline void setLastUsed( const time_t& _last_used )
|
||||
{ last_used = _last_used; }
|
||||
|
||||
inline void setLimitOffset( const unsigned int& _limit_offset )
|
||||
{ limit_offset = _limit_offset; }
|
||||
|
||||
inline void setLimitPeriod( const time_t& _limit_period )
|
||||
{ limit_period = _limit_period; }
|
||||
|
||||
inline void setLimitGrace( const unsigned int& _limit_grace )
|
||||
{ limit_grace = _limit_grace; }
|
||||
|
||||
inline void setLimitMax( const unsigned int& _limit_max )
|
||||
{ limit_max = _limit_max; }
|
||||
|
||||
inline void setMaxBans( const unsigned int& _max_bans )
|
||||
{ max_bans = _max_bans; }
|
||||
|
||||
inline void setNoTake( const unsigned int& _no_take )
|
||||
{ no_take = _no_take; }
|
||||
/**
|
||||
* Method to perform a SQL 'UPDATE' and commit changes to this
|
||||
* object back to the database.
|
||||
*/
|
||||
bool commit();
|
||||
bool insertRecord();
|
||||
void setAllMembers(int);
|
||||
|
||||
void setAllFlood();
|
||||
void setFloodMsg(const unsigned short );
|
||||
void setFloodNotice(const unsigned short );
|
||||
void setFloodCTCP(const unsigned short );
|
||||
void setFloodPeriod(const unsigned short );
|
||||
void setRepeatCount(const unsigned short );
|
||||
|
||||
public:
|
||||
/*
|
||||
* Map with key user-id, contents level and username for
|
||||
* easy access
|
||||
* Stores UID's of admin users with forced accessse
|
||||
* on this channel
|
||||
*/
|
||||
|
||||
typedef map< unsigned int, std::pair < unsigned short, string > > forceMapType ;
|
||||
forceMapType forceMap;
|
||||
|
||||
typedef map < int,sqlBan*> sqlBanMapType;
|
||||
sqlBanMapType banList;
|
||||
|
||||
/* < repeater_xIP < Message, rep_count> > */
|
||||
typedef map < unsigned int, std::pair< string, unsigned int > > chanRepeatType;
|
||||
chanRepeatType chanRepeat;
|
||||
|
||||
/* < flooder_xIP < last_time, accumulated_floodcount > > */
|
||||
typedef map < unsigned int, std::pair < time_t, unsigned int > > chanFloodType ;
|
||||
chanFloodType msgFlood;
|
||||
chanFloodType noticeFlood;
|
||||
chanFloodType ctcpFlood;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int id ;
|
||||
string name ;
|
||||
flagType flags ;
|
||||
unsigned short mass_deop_pro ;
|
||||
unsigned int flood_pro ;
|
||||
unsigned short msg_period;
|
||||
unsigned short notice_period;
|
||||
unsigned short ctcp_period;
|
||||
unsigned short flood_period;
|
||||
unsigned short repeat_count;
|
||||
bool antiflood;
|
||||
string url ;
|
||||
string description ;
|
||||
string comment ;
|
||||
string keywords ;
|
||||
string welcome ;
|
||||
time_t registered_ts ;
|
||||
time_t channel_ts ;
|
||||
string channel_mode ;
|
||||
unsigned short userflags ;
|
||||
time_t last_updated ;
|
||||
time_t last_topic ;
|
||||
bool inChan;
|
||||
time_t last_used;
|
||||
unsigned int limit_offset;
|
||||
time_t limit_period;
|
||||
time_t last_limit_check;
|
||||
time_t last_flood; //last time when an antiflood measure was taken (kick/ban/gline)
|
||||
unsigned int limit_grace;
|
||||
unsigned int limit_max;
|
||||
unsigned int max_bans;
|
||||
unsigned int no_take;
|
||||
|
||||
dbHandle* SQLDb;
|
||||
|
||||
} ;
|
||||
|
||||
}
|
||||
|
||||
#endif // __SQLCHANNEL_H
|
||||
@@ -0,0 +1,321 @@
|
||||
/**
|
||||
* Seven - 2012.11.22
|
||||
* sqlIncompleteChannel.h
|
||||
*
|
||||
* Stores information about incomplete pending channels.
|
||||
*
|
||||
* 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 <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "sqlLevel.h"
|
||||
#include "sqlUser.h"
|
||||
#include "sqlChannel.h"
|
||||
#include "constants.h"
|
||||
#include "cservice_config.h"
|
||||
#include "sqlIncompleteChannel.h"
|
||||
#include "sqlPendingTraffic.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
sqlIncompleteChannel::sqlIncompleteChannel(dbHandle* _SQLDb)
|
||||
:chanId(0),
|
||||
RealName(),
|
||||
Description(),
|
||||
SQLDb(_SQLDb)
|
||||
{
|
||||
}
|
||||
|
||||
extern const string escapeSQLChars(const string& theString);
|
||||
/*{
|
||||
string retMe ;
|
||||
|
||||
for( string::const_iterator ptr = theString.begin() ;
|
||||
ptr != theString.end() ; ++ptr )
|
||||
{
|
||||
if( *ptr == '\'' )
|
||||
{
|
||||
retMe += "\\\047" ;
|
||||
}
|
||||
else if ( *ptr == '\\' )
|
||||
{
|
||||
retMe += "\\\134" ;
|
||||
}
|
||||
else
|
||||
{
|
||||
retMe += *ptr ;
|
||||
}
|
||||
}
|
||||
return retMe ;
|
||||
}*/
|
||||
|
||||
bool sqlIncompleteChannel::commitRealName()
|
||||
{
|
||||
stringstream queryString;
|
||||
queryString << "UPDATE pending SET managername = '"
|
||||
<< escapeSQLChars(RealName)
|
||||
<< "' WHERE channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitRealName> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sqlIncompleteChannel::commitDesc()
|
||||
{
|
||||
stringstream queryString;
|
||||
queryString << "UPDATE pending SET description = '"
|
||||
<< escapeSQLChars(Description)
|
||||
<< "' WHERE channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitRealName> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sqlIncompleteChannel::commitSupporters()
|
||||
{
|
||||
stringstream queryString;
|
||||
//We don't bother with updating the supporters table, simply delete the existing entries
|
||||
queryString << "DELETE FROM supporters WHERE channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlIncompleteChannel::commitSupportersDelete> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitSupportersDelete> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
//Now we simply insert back the supporters list we have
|
||||
for (supporterListType::iterator itr = supps.begin(); itr != supps.end(); ++itr)
|
||||
{
|
||||
queryString.str("");
|
||||
queryString << "INSERT INTO supporters (channel_id,user_id,reason,last_updated) VALUES ("
|
||||
<< chanId << ", " << itr->first << ", '', date_part('epoch', CURRENT_TIMESTAMP)::int)"
|
||||
<< ends;
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitSupporters> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
bool sqlIncompleteChannel::commit()
|
||||
{
|
||||
stringstream queryString;
|
||||
|
||||
if ((!Description.empty()) && (!supps.empty()))
|
||||
{
|
||||
//Inserting/Updating supporters list into the supporters table
|
||||
|
||||
//We don't bother with updating the supporters table, simply delete the existing entries
|
||||
queryString << "DELETE FROM supporters WHRE channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlIncompleteChannel::commitSupportersDelete> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitSupportersDelete> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
//Now we simply insert back the supporters list we have
|
||||
for (suppsType::iterator itr = supps.begin(); itr != supps.end(); ++itr)
|
||||
{
|
||||
queryString.str("");
|
||||
queryString << "INSERT INTO supporters (channel_id,user_id,reason,last_updated) VALUES ("
|
||||
<< chanId << ", " << itr->first << ", '', date_part('epoch', CURRENT_TIMESTAMP)::int)"
|
||||
<< ends;
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitSupporters> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((!RealName.empty()) && (Description.empty()))
|
||||
{
|
||||
queryString.str("");
|
||||
queryString << "UPDATE pending SET managername = '"
|
||||
<< escapeSQLChars(RealName)
|
||||
<< "' WHERE channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitRealName> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!Description.empty()) && (supps.empty()))
|
||||
{
|
||||
queryString.str("");
|
||||
queryString << "UPDATE pending SET description = '"
|
||||
<< escapeSQLChars(Description)
|
||||
<< "' WHERE channel_id = "
|
||||
<< chanId
|
||||
<< ends;
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitRealName> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
// Insert into the pendings table the new channel_id with it's managerId
|
||||
bool sqlIncompleteChannel::commitNewPending(unsigned int mngrId, unsigned int chanId)
|
||||
{
|
||||
stringstream theQuery;
|
||||
theQuery << "INSERT INTO pending (channel_id,manager_id,created_ts,decision_ts,decision,comments,description,managername,last_updated,reg_acknowledged,check_start_ts) "
|
||||
<< "VALUES (" << chanId << "," << mngrId << ",date_part('epoch', CURRENT_TIMESTAMP)::int,0,'','','','',date_part('epoch', CURRENT_TIMESTAMP)::int,'N',0)"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlIncompleteChannel::commitNewPending> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(theQuery, true ) )
|
||||
{
|
||||
elog << "sqlIncompleteChannel::commitNewPending> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void sqlIncompleteChannel::loadIncompleteChans()
|
||||
{
|
||||
|
||||
/*
|
||||
stringstream theQuery;
|
||||
theQuery << "SELECT ip_number, join_count FROM pending_traffic"
|
||||
<< " WHERE channel_id = " << channel_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlIncompleteChannel::loadIncompleteChans> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( SQLDb->Exec(theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
for (unsigned int i = 0 ; i < SQLDb->Tuples(); i++)
|
||||
{
|
||||
unsigned int theIp = atoi(SQLDb->GetValue(i, 0));
|
||||
// elog << "IP: " << theIp << endl;
|
||||
|
||||
sqlPendingTraffic* trafRecord = new sqlPendingTraffic(SQLDb);
|
||||
trafRecord->ip_number = theIp;
|
||||
trafRecord->join_count = atoi(SQLDb->GetValue(i, 1));
|
||||
trafRecord->channel_id = channel_id;
|
||||
|
||||
trafficList.insert(trafficListType::value_type(theIp, trafRecord));
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Seven - 2012.11.22
|
||||
* sqlIncompleteChannel.h
|
||||
*
|
||||
* Stores information about incomplete pending channels.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __SQLINCOMPLETECHANNEL_H
|
||||
#define __SQLINCOMPLETECHANNEL_H "$Id: sqlIncompleteChannel.h,v 1.0 2012/22/11 09:53:16 Seven Exp $"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "dbHandle.h"
|
||||
#include "sqlUser.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
|
||||
class sqlIncompleteChannel
|
||||
{
|
||||
public:
|
||||
sqlIncompleteChannel(dbHandle*);
|
||||
|
||||
//bool commit();
|
||||
bool commitRealName();
|
||||
bool commitDesc();
|
||||
bool commitSupporters();
|
||||
bool commitNewPending(unsigned int, unsigned int);
|
||||
void loadIncompleteChans();
|
||||
|
||||
unsigned int chanId;
|
||||
string chanName;
|
||||
string RealName;
|
||||
string Description;
|
||||
typedef std::map <unsigned int, sqlUser*> supporterListType;
|
||||
supporterListType supps;
|
||||
|
||||
dbHandle* SQLDb;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // __sqlIncompleteChannel_H
|
||||
@@ -0,0 +1,240 @@
|
||||
/**
|
||||
* sqlLevel.cc
|
||||
*
|
||||
* Storage class for accessing channel user/level information either
|
||||
* from the backend or internal storage.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlLevel.cc,v 1.23 2012/06/02 13:45:02 Seven Exp $
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "sqlLevel.h"
|
||||
#include "sqlUser.h"
|
||||
#include "sqlChannel.h"
|
||||
#include "constants.h"
|
||||
#include "cservice.h"
|
||||
#include "cservice_config.h"
|
||||
|
||||
const char sqlLevel_h_rcsId[] = __SQLLEVEL_H ;
|
||||
const char sqlLevel_cc_rcsId[] = "$Id: sqlLevel.cc,v 1.23 2012/06/02 13:45:02 Seven Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
const sqlLevel::flagType sqlLevel::F_AUTOOP = 0x01 ;
|
||||
const sqlLevel::flagType sqlLevel::F_PROTECT = 0x02 ;
|
||||
const sqlLevel::flagType sqlLevel::F_FORCED = 0x04 ;
|
||||
const sqlLevel::flagType sqlLevel::F_AUTOVOICE =0x08 ;
|
||||
const sqlLevel::flagType sqlLevel::F_ONDB = 0x10 ;
|
||||
const sqlLevel::flagType sqlLevel::F_AUTOINVITE = 0x20;
|
||||
const sqlLevel::flagType sqlLevel::F_AUTOHALFOP = 0x40;
|
||||
|
||||
sqlLevel::sqlLevel(dbHandle* _SQLDb)
|
||||
:channel_id(0),
|
||||
user_id(0),
|
||||
access(0),
|
||||
forced_access(0),
|
||||
flags(0),
|
||||
suspend_expires(0),
|
||||
suspend_level(0),
|
||||
suspend_by(),
|
||||
suspend_reason(),
|
||||
added(0),
|
||||
added_by(),
|
||||
last_modif(::time(NULL)),
|
||||
last_modif_by(),
|
||||
last_used(0),
|
||||
SQLDb( _SQLDb )
|
||||
{
|
||||
}
|
||||
|
||||
bool sqlLevel::loadData(unsigned int userID, unsigned int channelID)
|
||||
{
|
||||
/*
|
||||
* Fetch a matching Level record for this channel and user ID combo.
|
||||
*/
|
||||
|
||||
#ifdef LOG_DEBUG
|
||||
elog << "sqlLevel::loadData> Attempting to load level data for "
|
||||
<< "channel-id: "
|
||||
<< channelID
|
||||
<< " and user-id: "
|
||||
<< userID
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "SELECT "
|
||||
<< sql::level_fields
|
||||
<< " FROM levels WHERE channel_id = "
|
||||
<< channelID
|
||||
<< " AND user_id = "
|
||||
<< userID
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlLevel::loadData> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( SQLDb->Exec(queryString, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
/*
|
||||
* If this combo doesn't exist, we won't get any rows back.
|
||||
*/
|
||||
|
||||
if(SQLDb->Tuples() < 1)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
// Fetch dat from row 0
|
||||
setAllMembers(0);
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
void sqlLevel::setAllMembers(int row)
|
||||
{
|
||||
/*
|
||||
* Support function for both loadData's.
|
||||
* Assumes SQLDb contains a valid results set for all Level information.
|
||||
*/
|
||||
|
||||
channel_id = atoi(SQLDb->GetValue(row, 0));
|
||||
user_id = atoi(SQLDb->GetValue(row, 1));
|
||||
access = atoi(SQLDb->GetValue(row, 2));
|
||||
flags = atoi(SQLDb->GetValue(row, 3));
|
||||
suspend_expires = atoi(SQLDb->GetValue(row, 4));
|
||||
suspend_level = atoi(SQLDb->GetValue(row, 5));
|
||||
suspend_by = SQLDb->GetValue(row, 6);
|
||||
added = atoi(SQLDb->GetValue(row, 7));
|
||||
added_by = SQLDb->GetValue(row, 8);
|
||||
last_modif = atoi(SQLDb->GetValue(row, 9));
|
||||
last_modif_by = SQLDb->GetValue(row, 10);
|
||||
last_updated = atoi(SQLDb->GetValue(row, 11));
|
||||
suspend_reason = SQLDb->GetValue(row, 12);
|
||||
}
|
||||
|
||||
bool sqlLevel::commit()
|
||||
{
|
||||
/*
|
||||
* Build an SQL statement to commit the transient data in this
|
||||
* storage class back into the database.
|
||||
*/
|
||||
|
||||
static const char* queryHeader = "UPDATE levels ";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< "SET flags = " << flags << ", "
|
||||
<< "access = " << access << ", "
|
||||
<< "suspend_expires = " << suspend_expires << ", "
|
||||
<< "suspend_level = " << suspend_level << ", "
|
||||
<< "suspend_by = '" << escapeSQLChars(suspend_by) << "', "
|
||||
<< "suspend_reason = '" << escapeSQLChars(suspend_reason) << "', "
|
||||
<< "added = " << added << ", "
|
||||
<< "added_by = '" << escapeSQLChars(added_by) << "', "
|
||||
<< "last_modif = " << last_modif << ", "
|
||||
<< "last_modif_by = '" << escapeSQLChars(last_modif_by) << "', "
|
||||
<< "last_updated = date_part('epoch', CURRENT_TIMESTAMP)::int "
|
||||
<< " WHERE channel_id = " << channel_id
|
||||
<< " AND user_id = " << user_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlLevel::commit> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
// TODO: Log to msgchan here.
|
||||
elog << "sqlLevel::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sqlLevel::insertRecord()
|
||||
{
|
||||
static const char* queryHeader = "INSERT INTO levels (channel_id,user_id,access,flags,added,added_by,last_modif,last_modif_by,last_updated) VALUES (";
|
||||
|
||||
stringstream queryString;
|
||||
queryString << queryHeader
|
||||
<< channel_id << ", "
|
||||
<< user_id << ", "
|
||||
<< access << ", "
|
||||
<< flags << ", "
|
||||
<< added << ", '"
|
||||
<< escapeSQLChars(added_by) << "', "
|
||||
<< last_modif << ", '"
|
||||
<< escapeSQLChars(last_modif_by) << "', "
|
||||
<< "date_part('epoch', CURRENT_TIMESTAMP)::int)"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlLevel::insertRecord> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
// TODO: Log to msgchan here.
|
||||
elog << "sqlLevel::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlLevel::~sqlLevel()
|
||||
{
|
||||
}
|
||||
|
||||
} // Namespace gnuworld.
|
||||
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* sqlLevel.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlLevel.h,v 1.23 2012/06/02 13:37:51 Seven Exp $
|
||||
*/
|
||||
|
||||
#ifndef __SQLLEVEL_H
|
||||
#define __SQLLEVEL_H "$Id: sqlLevel.h,v 1.23 2012/06/02 13:37:51 Seven Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "dbHandle.h"
|
||||
|
||||
using std::string ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class sqlLevel
|
||||
{
|
||||
public:
|
||||
sqlLevel(dbHandle*) ;
|
||||
virtual ~sqlLevel() ;
|
||||
|
||||
typedef unsigned int flagType ;
|
||||
static const flagType F_AUTOOP;
|
||||
static const flagType F_PROTECT;
|
||||
static const flagType F_FORCED; // Deprecated.
|
||||
static const flagType F_AUTOVOICE;
|
||||
static const flagType F_ONDB; // Deprecated.
|
||||
static const flagType F_AUTOINVITE;
|
||||
static const flagType F_AUTOHALFOP;
|
||||
|
||||
/*
|
||||
* Methods to get data atrributes.
|
||||
*/
|
||||
|
||||
inline const unsigned int& getChannelId() const
|
||||
{ return channel_id ; }
|
||||
|
||||
inline const unsigned int& getUserId() const
|
||||
{ return user_id ; }
|
||||
|
||||
inline const unsigned short& getAccess() const
|
||||
{ return access ; }
|
||||
|
||||
inline const unsigned short& getForcedAccess() const
|
||||
{ return forced_access ; }
|
||||
|
||||
inline const flagType& getFlags() const
|
||||
{ return flags ; }
|
||||
|
||||
inline bool getFlag( const flagType& whichFlag ) const
|
||||
{ return (flags & whichFlag) ; }
|
||||
|
||||
inline const time_t& getSuspendExpire() const
|
||||
{ return suspend_expires ; }
|
||||
|
||||
inline const int& getSuspendLevel() const
|
||||
{ return suspend_level ; }
|
||||
|
||||
inline const string& getSuspendBy() const
|
||||
{ return suspend_by ; }
|
||||
|
||||
inline const string& getSuspendReason() const
|
||||
{ return suspend_reason ; }
|
||||
|
||||
inline const time_t& getAdded() const
|
||||
{ return added ; }
|
||||
|
||||
inline const string& getAddedBy() const
|
||||
{ return added_by ; }
|
||||
|
||||
inline const time_t& getLastModif() const
|
||||
{ return last_modif ; }
|
||||
|
||||
inline const string& getLastModifBy() const
|
||||
{ return last_modif_by ; }
|
||||
|
||||
inline const time_t& getLastUpdated() const
|
||||
{ return last_updated ; }
|
||||
|
||||
inline const time_t& getLastUsed() const
|
||||
{ return last_used ; }
|
||||
|
||||
/*
|
||||
* Methods to set data atrributes.
|
||||
*/
|
||||
|
||||
inline void setChannelId( const unsigned int& _channel_id )
|
||||
{ channel_id = _channel_id; }
|
||||
|
||||
inline void setUserId( const unsigned int& _user_id )
|
||||
{ user_id = _user_id; }
|
||||
|
||||
inline void setAccess( const unsigned short& _access )
|
||||
{ access = _access; }
|
||||
|
||||
inline void setForcedAccess( const unsigned short& _forced_access )
|
||||
{ forced_access = _forced_access; }
|
||||
|
||||
inline void setFlag( const flagType& whichFlag )
|
||||
{ flags |= whichFlag; }
|
||||
|
||||
inline void removeFlag( const flagType& whichFlag )
|
||||
{ flags &= ~whichFlag; }
|
||||
|
||||
inline void setSuspendLevel( const unsigned int& _suspend_level )
|
||||
{ suspend_level = _suspend_level; }
|
||||
|
||||
inline void setSuspendExpire( const time_t& _suspend_expires )
|
||||
{ suspend_expires = _suspend_expires; }
|
||||
|
||||
inline void setSuspendBy( const string& _suspend_by )
|
||||
{ suspend_by = _suspend_by; }
|
||||
|
||||
inline void setSuspendReason( const string& _suspend_reason )
|
||||
{ suspend_reason = _suspend_reason; }
|
||||
|
||||
inline void setAdded( const time_t& _added )
|
||||
{ added = _added; }
|
||||
|
||||
inline void setAddedBy( const string& _added_by )
|
||||
{ added_by = _added_by; }
|
||||
|
||||
inline void setLastModif( const time_t& _last_modif )
|
||||
{ last_modif = _last_modif; }
|
||||
|
||||
inline void setLastModifBy( const string& _last_modif_by )
|
||||
{ last_modif_by = _last_modif_by; }
|
||||
|
||||
inline void setLastUsed( const time_t& _last_used )
|
||||
{ last_used = _last_used; }
|
||||
|
||||
bool commit();
|
||||
bool insertRecord();
|
||||
bool loadData( unsigned int, unsigned int );
|
||||
void setAllMembers(int);
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int channel_id ;
|
||||
unsigned int user_id ;
|
||||
unsigned short access ;
|
||||
unsigned short forced_access ;
|
||||
flagType flags ;
|
||||
time_t suspend_expires ;
|
||||
int suspend_level ;
|
||||
string suspend_by ;
|
||||
string suspend_reason ;
|
||||
time_t added ;
|
||||
string added_by ;
|
||||
time_t last_modif ;
|
||||
string last_modif_by ;
|
||||
time_t last_updated ;
|
||||
time_t last_used;
|
||||
|
||||
dbHandle* SQLDb;
|
||||
} ;
|
||||
|
||||
}
|
||||
#endif // __SQLLEVEL_H
|
||||
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* sqlPendingChannel.cc
|
||||
*
|
||||
* Class which contains details about channels which are 'pending'
|
||||
* registration.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlPendingChannel.cc,v 1.10 2007/08/28 16:10:12 dan_karrels Exp $
|
||||
*
|
||||
* Seven - 2012.10.07
|
||||
* Added method loadSupportersTraffic() to track supoporter activity for a channel
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "sqlLevel.h"
|
||||
#include "sqlUser.h"
|
||||
#include "sqlChannel.h"
|
||||
#include "constants.h"
|
||||
#include "cservice_config.h"
|
||||
#include "sqlPendingChannel.h"
|
||||
#include "sqlPendingTraffic.h"
|
||||
|
||||
const char sqlPendingChannel_h_rcsId[] = __SQLPENDINGCHANNEL_H ;
|
||||
const char sqlPendingChannel_cc_rcsId[] = "$Id: sqlPendingChannel.cc,v 1.10 2007/08/28 16:10:12 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
sqlPendingChannel::sqlPendingChannel(dbHandle* _SQLDb)
|
||||
:channel_id(0),
|
||||
join_count(0),
|
||||
unique_join_count(0),
|
||||
SQLDb(_SQLDb)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor to clean up any memory this class may have
|
||||
* allocated.
|
||||
*/
|
||||
|
||||
sqlPendingChannel::~sqlPendingChannel()
|
||||
{
|
||||
for(trafficListType::iterator ptr = trafficList.begin();
|
||||
ptr != trafficList.end(); ++ptr)
|
||||
{
|
||||
sqlPendingTraffic* toDie = ptr->second;
|
||||
// elog << "Autocleanup of Traffic record for #" << toDie->ip_number << endl;
|
||||
delete(toDie);
|
||||
}
|
||||
|
||||
for(trafficListType::iterator ptr = uniqueSupporterList.begin();
|
||||
ptr != uniqueSupporterList.end(); ++ptr)
|
||||
{
|
||||
sqlPendingTraffic* toDie = ptr->second;
|
||||
// elog << "Autocleanup of Traffic record for #" << toDie->ip_number << endl;
|
||||
delete(toDie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void sqlPendingChannel::loadTrafficCache()
|
||||
{
|
||||
/*
|
||||
* Load all associated Traffic records for this channel.
|
||||
*/
|
||||
stringstream theQuery;
|
||||
theQuery << "SELECT ip_number, join_count FROM pending_traffic"
|
||||
<< " WHERE channel_id = " << channel_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlPendingChannel::loadTrafficCache> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( SQLDb->Exec(theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
for (unsigned int i = 0 ; i < SQLDb->Tuples(); i++)
|
||||
{
|
||||
unsigned int theIp = atoi(SQLDb->GetValue(i, 0));
|
||||
// elog << "IP: " << theIp << endl;
|
||||
|
||||
sqlPendingTraffic* trafRecord = new sqlPendingTraffic(SQLDb);
|
||||
trafRecord->ip_number = theIp;
|
||||
trafRecord->join_count = atoi(SQLDb->GetValue(i, 1));
|
||||
trafRecord->channel_id = channel_id;
|
||||
|
||||
trafficList.insert(trafficListType::value_type(theIp, trafRecord));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void sqlPendingChannel::loadSupportersTraffic()
|
||||
{
|
||||
stringstream theQuery;
|
||||
theQuery << "SELECT user_id,join_count FROM supporters"
|
||||
<< " WHERE channel_id = " << channel_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlPendingChannel::loadUniqueTrafficCache> "
|
||||
<< theQuery.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( SQLDb->Exec(theQuery, true ) )
|
||||
//if( PGRES_TUPLES_OK == status )
|
||||
{
|
||||
for (unsigned int i = 0 ; i < SQLDb->Tuples(); i++)
|
||||
{
|
||||
unsigned int userId = atoi(SQLDb->GetValue(i, 0));
|
||||
sqlPendingTraffic* trafRecord = new sqlPendingTraffic(SQLDb);
|
||||
trafRecord->ip_number = userId;
|
||||
trafRecord->join_count = atoi(SQLDb->GetValue(i, 1));
|
||||
trafRecord->channel_id = channel_id;
|
||||
|
||||
uniqueSupporterList.insert(trafficListType::value_type(userId, trafRecord));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool sqlPendingChannel::commit()
|
||||
{
|
||||
/*
|
||||
* This is a 3 step commit.
|
||||
* 1. Update pending record values with new join_count
|
||||
* and unique_join_count.
|
||||
* 2. Update supporters records with new supporter count.
|
||||
* 3. Update Traffic table with new traffic counts.
|
||||
*/
|
||||
|
||||
//elog << "Commiting Pending Channel Details: " << endl
|
||||
// << "Channel ID: " << channel_id << endl
|
||||
// << "Total Join Count: " << join_count
|
||||
// << endl;
|
||||
|
||||
/*
|
||||
* Set the number of unique joins to be the number
|
||||
* of elements in the IP traffic list.
|
||||
*/
|
||||
|
||||
unique_join_count = trafficList.size();
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "UPDATE pending SET "
|
||||
<< "join_count = " << join_count << ", "
|
||||
<< "unique_join_count = " << unique_join_count
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlPendingChannel::commit> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
|
||||
elog << "sqlPendingChannel::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Next, iterate over the supporters and commit those details.
|
||||
*/
|
||||
|
||||
for(supporterListType::iterator ptr = supporterList.begin();
|
||||
ptr != supporterList.end(); ++ptr)
|
||||
{
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool sqlPendingChannel::commitSupporter(unsigned int sup_id, unsigned int count)
|
||||
{
|
||||
stringstream queryString;
|
||||
queryString << "UPDATE supporters SET "
|
||||
<< "join_count = "
|
||||
<< count
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< " AND user_id = "
|
||||
<< sup_id
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlPendingChannel::commit> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
// if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlPendingChannel::commit> Error updating supporter "
|
||||
<< "record for " << sup_id << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* sqlPendingChannel.h
|
||||
*
|
||||
* Stores information about channels currently being registered.
|
||||
* We do a number of things to channels in this state ;)
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlPendingChannel.h,v 1.8 2007/08/28 16:10:12 dan_karrels Exp $
|
||||
* Seven - 2012.10.07
|
||||
* Added method loadSupportersTraffic() to track supoporter activity for a channel
|
||||
*/
|
||||
|
||||
#ifndef __SQLPENDINGCHANNEL_H
|
||||
#define __SQLPENDINGCHANNEL_H "$Id: sqlPendingChannel.h,v 1.8 2007/08/28 16:10:12 dan_karrels Exp $"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "sqlPendingTraffic.h"
|
||||
#include "dbHandle.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class sqlPendingChannel
|
||||
{
|
||||
public:
|
||||
sqlPendingChannel(dbHandle*);
|
||||
~sqlPendingChannel();
|
||||
|
||||
bool commit();
|
||||
bool commitSupporter(unsigned int, unsigned int);
|
||||
void loadTrafficCache();
|
||||
void loadSupportersTraffic();
|
||||
|
||||
unsigned int channel_id;
|
||||
unsigned int join_count;
|
||||
unsigned int unique_join_count;
|
||||
time_t checkStart;
|
||||
|
||||
typedef std::map < int, int > supporterListType;
|
||||
supporterListType supporterList;
|
||||
|
||||
typedef std::map < unsigned int, sqlPendingTraffic* > trafficListType;
|
||||
trafficListType trafficList;
|
||||
|
||||
/* With loadSupportersTraffic() we load the joincounts of every supporter for a given channel
|
||||
* in a trafficListType array.
|
||||
* The sqlPendingTraffic->ip_number we will use for supporter user_id
|
||||
*/
|
||||
trafficListType uniqueSupporterList;
|
||||
|
||||
dbHandle* SQLDb;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // __SQLPENDINGCHANNEL_H
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* sqlPendingTraffic.cc
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlPendingTraffic.cc,v 1.5 2007/08/28 16:10:12 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "misc.h"
|
||||
#include "sqlLevel.h"
|
||||
#include "sqlUser.h"
|
||||
#include "sqlChannel.h"
|
||||
#include "constants.h"
|
||||
#include "cservice_config.h"
|
||||
#include "sqlPendingTraffic.h"
|
||||
|
||||
const char sqlPendingTraffic_h_rcsId[] = __SQLPENDINGTRAFFIC_H ;
|
||||
const char sqlPendingTraffic_cc_rcsId[] = "$Id: sqlPendingTraffic.cc,v 1.5 2007/08/28 16:10:12 dan_karrels Exp $" ;
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
using std::string ;
|
||||
using std::endl ;
|
||||
using std::ends ;
|
||||
using std::stringstream ;
|
||||
|
||||
sqlPendingTraffic::sqlPendingTraffic(dbHandle* _SQLDb)
|
||||
:channel_id(0),
|
||||
ip_number(0),
|
||||
join_count(0),
|
||||
SQLDb(_SQLDb)
|
||||
{
|
||||
}
|
||||
|
||||
bool sqlPendingTraffic::insertRecord()
|
||||
{
|
||||
int theip_number = ip_number;
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "INSERT INTO pending_traffic (channel_id, ip_number, join_count) VALUES ("
|
||||
<< channel_id << ", "
|
||||
<< theip_number << ", "
|
||||
<< join_count << ")"
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlPendingTraffic::insertRecord> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
//if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlPendingTraffic::commit> Something went wrong: "
|
||||
<< SQLDb->ErrorMessage()
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sqlPendingTraffic::commit()
|
||||
{
|
||||
int theip_number = ip_number;
|
||||
|
||||
stringstream queryString;
|
||||
queryString << "UPDATE pending_traffic SET "
|
||||
<< "join_count = "
|
||||
<< join_count
|
||||
<< " WHERE channel_id = "
|
||||
<< channel_id
|
||||
<< " AND ip_number = "
|
||||
<< theip_number
|
||||
<< ends;
|
||||
|
||||
#ifdef LOG_SQL
|
||||
elog << "sqlPendingTraffic::commit> "
|
||||
<< queryString.str().c_str()
|
||||
<< endl;
|
||||
#endif
|
||||
|
||||
if( !SQLDb->Exec(queryString ) )
|
||||
// if( PGRES_COMMAND_OK != status )
|
||||
{
|
||||
elog << "sqlPendingTraffic::commit> Error updating pending_traffic "
|
||||
<< "record for " << ip_number << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* sqlPendingTraffic.h
|
||||
*
|
||||
* Stores information about the uniqueness of visitors to
|
||||
* pending channels.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id: sqlPendingTraffic.h,v 1.4 2007/08/28 16:10:12 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __SQLPENDINGTRAFFIC_H
|
||||
#define __SQLPENDINGTRAFFIC_H "$Id: sqlPendingTraffic.h,v 1.4 2007/08/28 16:10:12 dan_karrels Exp $"
|
||||
|
||||
#include "dbHandle.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class sqlPendingTraffic
|
||||
{
|
||||
|
||||
public:
|
||||
sqlPendingTraffic(dbHandle*);
|
||||
bool insertRecord();
|
||||
bool commit();
|
||||
|
||||
unsigned int channel_id;
|
||||
unsigned int ip_number;
|
||||
unsigned int join_count;
|
||||
|
||||
dbHandle* SQLDb;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // __SQLPENDINGTRAFFIC_H
|
||||
Loaded 100 of 870 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user