Skip to content

Commit

Permalink
Change KickUser Lua API to allow hiding kick messages
Browse files Browse the repository at this point in the history
  • Loading branch information
RoLex committed Mar 14, 2021
1 parent 0d31495 commit 95c304d
Show file tree
Hide file tree
Showing 18 changed files with 499 additions and 320 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ message(STATUS)
message(STATUS "You can change build options with: -D{OPTION}=ON|OFF")
message(STATUS "You can turn on debug build with: -DDEFINE_DEBUG=ON")
message(STATUS "You can disable all plugins with: -DWITH_PLUGINS=OFF")
message(STATUS "You can turn on buffer reservation with: -DUSE_BUFFER_RESERVE=ON")
#message(STATUS "You can disable SSL secured connects with: -DUSE_SSL_CONNECTS=OFF")
message(STATUS "You can also disable specific plugins with: -DWITH_{NAME}=OFF")
message(STATUS "Plugin names: LUA PYTHON PERL FORBID CHATROOM IPLOG ISP MESSENGER STATS REPLACER FLOODPROT")
message(STATUS "If you get errors related to autosprintf, please try with: -DUSE_CUSTOM_AUTOSPRINTF=ON")
Expand All @@ -31,7 +33,7 @@ message(STATUS)
SET(VERLIHUB_VERSION_MAJOR 1)
SET(VERLIHUB_VERSION_MINOR 3)
SET(VERLIHUB_VERSION_PATCH 0)
SET(VERLIHUB_VERSION_TWEAK 1)
SET(VERLIHUB_VERSION_TWEAK 2)
SET(VERLIHUB_VERSION "${VERLIHUB_VERSION_MAJOR}.${VERLIHUB_VERSION_MINOR}.${VERLIHUB_VERSION_PATCH}.${VERLIHUB_VERSION_TWEAK}")
#SET(VERLIHUB_SOVERSION "${VERLIHUB_VERSION_MAJOR}.${VERLIHUB_VERSION_MINOR}.${VERLIHUB_VERSION_PATCH}")
SET(PROJECT_NAME "verlihub")
Expand Down Expand Up @@ -187,7 +189,7 @@ IF(NOT HAVE_GETOPT_H)
ENDIF(NOT HAVE_GETOPT_H)

ADD_DEFINITIONS(-DUSE_BUFFER_RESERVE)
OPTION(USE_BUFFER_RESERVE "Use buffer string reservation?" OFF) # use cmake -DUSE_BUFFER_RESERVE=ON to use buffer string reservation
OPTION(USE_BUFFER_RESERVE "Use buffer string reservation" OFF) # use cmake -DUSE_BUFFER_RESERVE=ON to use buffer string reservation

OPTION(DEFINE_DEBUG "Build the project using debugging code" OFF) # use cmake -DDEFINE_DEBUG=ON to enable debug

Expand All @@ -198,6 +200,10 @@ ELSE(DEFINE_DEBUG)
SET(CMAKE_BUILD_TYPE Release)
ENDIF(DEFINE_DEBUG)


#ADD_DEFINITIONS(-DUSE_SSL_CONNECTS)
#OPTION(USE_SSL_CONNECTS "Use SSL secured connects" ON) # use cmake -DUSE_SSL_CONNECTS=OFF to disable ssl

MESSAGE(STATUS "[ OK ] Build type: ${CMAKE_BUILD_TYPE}")
ADD_DEFINITIONS(-DHAVE_CONFIG_H)

Expand Down
16 changes: 8 additions & 8 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[*] Confirmed:
On start resolve hublist.te-home.net domain and update auth_ip field for registered user TEPinger
[*] Unconfirmed:
Fix creguserinfo.cpp for HAVE_LIBSSL and crypto stuff
?
[*] Confirmed:

On start resolve hublist.te-home.net domain and update auth_ip field for registered user TEPinger

[*] Unconfirmed:

Fix creguserinfo.cpp for HAVE_LIBSSL and crypto stuff
?
9 changes: 7 additions & 2 deletions plugins/lua/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ int _KickUser(lua_State *L)
return 2;
}

if (!lua_isstring(L, 2) || !lua_isstring(L, 3) || !lua_isstring(L, 4) || ((args >= 4) && !lua_isstring(L, 5)) || ((args >= 5) && !lua_isstring(L, 6))) {
if (!lua_isstring(L, 2) || !lua_isstring(L, 3) || !lua_isstring(L, 4) || ((args >= 4) && !lua_isstring(L, 5)) || ((args >= 5) && !lua_isstring(L, 6)) || ((args >= 6) && !lua_isnumber(L, 7))) {
luaerror(L, ERR_PARAM);
return 2;
}
Expand All @@ -1909,7 +1909,12 @@ int _KickUser(lua_State *L)
if (args >= 5)
note_usr = lua_tostring(L, 6);

if (!KickUser(oper.c_str(), nick.c_str(), why.c_str(), (note_op.size() ? note_op.c_str() : NULL), (note_usr.size() ? note_usr.c_str() : NULL))) {
int hide = 0;

if (args >= 6)
hide = lua_tonumber(L, 7);

if (!KickUser(oper.c_str(), nick.c_str(), why.c_str(), (note_op.size() ? note_op.c_str() : NULL), (note_usr.size() ? note_usr.c_str() : NULL), (hide == 1))) {
luaerror(L, ERR_CALL);
return 2;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/perl/README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Verlihub PerlScript plugin
Verlihub PerlScript plugin
91 changes: 82 additions & 9 deletions src/casyncconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ cAsyncConn::cAsyncConn(int desc, cAsyncSocketServer *s, tConnType ct): // incomi
mLineSizeMax(0),
mType(ct),
mxLine(NULL),
/*
#ifdef USE_SSL_CONNECTS
mSSLConn(NULL),
#endif
*/
meLineStatus(AC_LS_NO_LINE),
mBufEnd(0),
mBufReadPos(0),
Expand Down Expand Up @@ -219,6 +224,16 @@ void cAsyncConn::Close()
mWritable = false;
ok = false;

/*
#ifdef USE_SSL_CONNECTS
if (mSSLConn) {
SSL_shutdown(mSSLConn);
SSL_free(mSSLConn);
mSSLConn = NULL;
}
#endif
*/

if (mxServer)
mxServer->OnConnClose(this);

Expand Down Expand Up @@ -348,11 +363,25 @@ int cAsyncConn::ReadAll(const unsigned int tries, const unsigned int sleep)
//bool udp = (this->GetType() == eCT_CLIENTUDP);

//if (!udp) {
while (((buf_len = recv(mSockDesc, msBuffer.data(), MAX_MESS_SIZE, 0)) == -1) && ((errno == EAGAIN) || (errno == EINTR)) && (i++ <= tries)) {
//#if !defined _WIN32
::usleep(sleep);
//#endif
/*
#ifdef USE_SSL_CONNECTS
if (mSSLConn) {
while (((buf_len = SSL_read(mSSLConn, msBuffer.data(), MAX_MESS_SIZE)) == -1) && ((errno == EAGAIN) || (errno == EINTR)) && (i++ <= tries)) // todo: errno
::usleep(sleep);
} else {
#endif
*/
while (((buf_len = recv(mSockDesc, msBuffer.data(), MAX_MESS_SIZE, 0)) == -1) && ((errno == EAGAIN) || (errno == EINTR)) && (i++ <= tries)) {
//#if !defined _WIN32
::usleep(sleep);
//#endif
}
/*
#ifdef USE_SSL_CONNECTS
}
#endif
*/
/*
} else {
while (((buf_len = recvfrom(mSockDesc, msBuffer.data(), MAX_MESS_SIZE, 0, (struct sockaddr*)&mAddrIN, (socklen_t*)&addr_len)) == -1) && (i++ <= tries)) {
Expand All @@ -369,9 +398,6 @@ int cAsyncConn::ReadAll(const unsigned int tries, const unsigned int sleep)
if (Log(2)) // connection hung up
LogStream() << "User hung up" << endl;

CloseNow();
return -1;

} else {
if (Log(2))
LogStream() << "Read IO error: " << errno << " = " << strerror(errno) << endl;
Expand All @@ -395,6 +421,14 @@ int cAsyncConn::ReadAll(const unsigned int tries, const unsigned int sleep)
//}

} else { // received data
if ((buf_len > 2) && (msBuffer[0] == 0x16) && (msBuffer[1] == 0x03)) { // detect tls connection
if (Log(1))
LogStream() << "Closing TLS connection" << endl;

CloseNow(); // todo: eCR_TLS_SESS
return -1;
}

mBufEnd = buf_len;
msBuffer[mBufEnd] = '\0'; // end string

Expand All @@ -420,7 +454,14 @@ int cAsyncConn::SendAll(const char *buf, size_t &len)
//try {
//if (!udp) {
//#if !defined _WIN32
n = send(mSockDesc, buf + total, bytesleft, MSG_NOSIGNAL | MSG_DONTWAIT);
/*
#ifdef USE_SSL_CONNECTS
if (mSSLConn)
n = SSL_write(mSSLConn, buf + total, bytesleft);
else
#endif
*/
n = send(mSockDesc, buf + total, bytesleft, MSG_NOSIGNAL | MSG_DONTWAIT);
/*
#else
int RetryCount = 0;
Expand Down Expand Up @@ -462,7 +503,14 @@ int cAsyncConn::SendAll(const char *buf, size_t &len)
}
#else
//if (!udp)
n = send(mSockDesc, buf + total, bytesleft, 0);
/*
#ifdef USE_SSL_CONNECTS
if (mSSLConn)
n = SSL_write(mSSLConn, buf + total, bytesleft);
else
#endif
*/
n = send(mSockDesc, buf + total, bytesleft, 0);
/*
else
n = sendto(mSockDesc, buf + total, bytesleft, 0, (struct sockaddr*)&mAddrIN, sizeof(struct sockaddr));
Expand Down Expand Up @@ -739,6 +787,31 @@ tSocket cAsyncConn::AcceptSock(const unsigned int sleep, const unsigned int trie
if (Log(3))
LogStream() << "Accepted socket: " << socknum << endl;

/*
#ifdef USE_SSL_CONNECTS
if (mxServer && mxServer->mSSLCont) {
mSSLConn = SSL_new(mxServer->mSSLCont);
if (mSSLConn) {
SSL_set_fd(mSSLConn, socknum);
if (SSL_accept(mSSLConn) <= 0) {
if (Log(0))
LogStream() << "Failed to accept client SSL socket: " << socknum << endl;
ERR_print_errors_fp(stderr);
SSL_free(mSSLConn);
mSSLConn = NULL;
}
} else {
if (Log(0))
LogStream() << "Failed to create client SSL socket: " << socknum << endl;
}
}
#endif
*/

sSocketCounter++;
sockoptval_t yes = 1;

Expand Down
13 changes: 13 additions & 0 deletions src/casyncconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
#include <netinet/in.h>
//#endif

/*
#ifdef USE_SSL_CONNECTS
#include <openssl/ssl.h>
#endif
*/

#include <string>
#include <list>
#include <vector>
Expand Down Expand Up @@ -483,6 +489,13 @@ namespace nVerliHub {
return mSockDesc;
}

/*
#ifdef USE_SSL_CONNECTS
// ssl connection
SSL *mSSLConn;
#endif
*/

/**
* Write the given data into the output buffer.
* The content of the buffer may be flushed manually or when the buffer
Expand Down
55 changes: 54 additions & 1 deletion src/casyncsocketserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ cAsyncSocketServer::cAsyncSocketServer(int port):
mbRun(false),
mFactory(NULL),
mRunResult(0),
/*
#ifdef USE_SSL_CONNECTS
mSSLCont(NULL),
#endif
*/
mNowTreating(NULL)
{
/*
Expand Down Expand Up @@ -116,6 +121,45 @@ int cAsyncSocketServer::run()
mbRun = true;
vhLog(1) << "Main loop start" << endl;

/*
#ifdef USE_SSL_CONNECTS
// https://wiki.openssl.org/index.php/Simple_TLS_Server
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
const SSL_METHOD *meth = TLS_server_method(); // todo: detect version from ssl.h
mSSLCont = SSL_CTX_new(meth);
if (mSSLCont) {
SSL_CTX_set_options(mSSLCont, SSL_OP_NO_COMPRESSION); // no compression
SSL_CTX_set_min_proto_version(mSSLCont, TLS1_3_VERSION); // min version 1.3
SSL_CTX_set_max_proto_version(mSSLCont, TLS1_3_VERSION); // max version 1.3
SSL_CTX_set_ecdh_auto(mSSLCont, 1);
if (SSL_CTX_use_certificate_file(mSSLCont, "/home/rolex/.certs/FearDC.crt", SSL_FILETYPE_PEM) <= 0) { // todo: add config
vhLog(0) << ("Failed to apply SSL certificate to server SSL context") << endl;
ERR_print_errors_fp(stderr);
SSL_CTX_free(mSSLCont);
mSSLCont = NULL;
EVP_cleanup();
} else {
if (SSL_CTX_use_PrivateKey_file(mSSLCont, "/home/rolex/.certs/FearDC.key", SSL_FILETYPE_PEM) <= 0 ) { // todo: add config
vhLog(0) << ("Failed to apply SSL key to server SSL context") << endl;
ERR_print_errors_fp(stderr);
SSL_CTX_free(mSSLCont);
mSSLCont = NULL;
EVP_cleanup();
}
}
} else {
vhLog(0) << ("Failed to create server SSL context") << endl;
ERR_print_errors_fp(stderr);
EVP_cleanup();
}
#endif
*/

while (mbRun) {
mTime.Get(); // note: always current time, dont modify this container anywhere
TimeStep();
Expand All @@ -140,7 +184,6 @@ int cAsyncSocketServer::run()
}

vhLog(1) << "Main loop stop with code " << mRunResult << endl;

return mRunResult;
}

Expand Down Expand Up @@ -170,6 +213,16 @@ void cAsyncSocketServer::close()
}
}
}

/*
#ifdef USE_SSL_CONNECTS
if (mSSLCont) {
SSL_CTX_free(mSSLCont);
mSSLCont = NULL;
EVP_cleanup();
}
#endif
*/
}

/*
Expand Down
15 changes: 14 additions & 1 deletion src/casyncsocketserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@
#include "ctimeout.h"
#include <list>
#include "cobj.h"
//#include "cconndc.h" // added
#include "casyncconn.h"
#include "cmeanfrequency.h"

/*
#ifdef USE_SSL_CONNECTS
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif
*/

using namespace std;

namespace nVerliHub {
Expand Down Expand Up @@ -126,6 +132,13 @@ namespace nVerliHub {
*/
int OnTimerBase(const cTime &now);

/*
#ifdef USE_SSL_CONNECTS
// ssl context
SSL_CTX* mSSLCont;
#endif
*/

/**
* Start the main loop.
* This ìs the method that calls OnTimerBase() and TimeStep()
Expand Down
2 changes: 1 addition & 1 deletion src/cconndc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cConnDC::cConnDC(int sd, cAsyncSocketServer *server):
//mNickListInProgress = false;
//mSkipNickList = false;
mConnType = NULL;
mCloseReason = 0;
mCloseReason = eCR_DEFAULT;
SetTimeOut(eTO_LOGIN, Server()->mC.timeout_length[eTO_LOGIN], server->mTime); // default login timeout
mGeoZone = -1;
mRegInfo = NULL;
Expand Down
Loading

0 comments on commit 95c304d

Please sign in to comment.