mirror of
https://github.com/3proxy/3proxy.git
synced 2025-04-21 19:52:08 +08:00
Logging for plugins fixed
This commit is contained in:
parent
ee8cdbc85b
commit
7973c8b757
@ -123,6 +123,7 @@ struct extparam conf = {
|
|||||||
doconnect, /* AUTHFUNC authfunc; */
|
doconnect, /* AUTHFUNC authfunc; */
|
||||||
NULL, /* BANDLIMFUNC bandlimfunc; */
|
NULL, /* BANDLIMFUNC bandlimfunc; */
|
||||||
NULL, /* TRAFCOUNTFUNC trafcountfunc; */
|
NULL, /* TRAFCOUNTFUNC trafcountfunc; */
|
||||||
|
NULL, /* void (*prelog)(struct clientparam * param); */
|
||||||
NULL, NULL, /* unsigned char *logtarget, *logformat; */
|
NULL, NULL, /* unsigned char *logtarget, *logformat; */
|
||||||
NULL, /* struct filemon * fmon; */
|
NULL, /* struct filemon * fmon; */
|
||||||
NULL, /* struct filter * filters; */
|
NULL, /* struct filter * filters; */
|
||||||
|
@ -33,9 +33,6 @@ struct srvparam logsrv;
|
|||||||
|
|
||||||
struct LOGGER;
|
struct LOGGER;
|
||||||
|
|
||||||
void(*prelog)(struct clientparam * param) = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
struct logevent {
|
struct logevent {
|
||||||
struct logevent *next;
|
struct logevent *next;
|
||||||
struct LOGGER *log;
|
struct LOGGER *log;
|
||||||
@ -353,7 +350,7 @@ void dolog(struct clientparam * param, const unsigned char *s){
|
|||||||
stdlog(s, strlen(s), &errlogger);
|
stdlog(s, strlen(s), &errlogger);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(prelog)prelog(param);
|
if(conf.prelog)conf.prelog(param);
|
||||||
if(!param->nolog && param->srv->log) {
|
if(!param->nolog && param->srv->log) {
|
||||||
struct logevent *evt;
|
struct logevent *evt;
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ struct symbol symbols[] = {
|
|||||||
{symbols+50, "checkpreACL", (void *) checkpreACL},
|
{symbols+50, "checkpreACL", (void *) checkpreACL},
|
||||||
{symbols+51, "dolog", (void *) dolog},
|
{symbols+51, "dolog", (void *) dolog},
|
||||||
{symbols+52, "logfuncs", (void *) &logfuncs},
|
{symbols+52, "logfuncs", (void *) &logfuncs},
|
||||||
{symbols+53, "prelog", (void *) &prelog},
|
|
||||||
{NULL, "", NULL}
|
{NULL, "", NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
PROXYFUNC tcppmfunc, proxyfunc, smtppfunc, ftpprfunc;
|
PROXYFUNC tcppmfunc, proxyfunc, smtppfunc, ftpprfunc;
|
||||||
static void (*dolog)(struct clientparam * param, const unsigned char *s);
|
static void (*pdolog)(struct clientparam * param, const unsigned char *s);
|
||||||
|
|
||||||
static struct pluginlink * pl;
|
static struct pluginlink * pl;
|
||||||
|
|
||||||
@ -239,25 +239,25 @@ int dossl(struct clientparam* param, SSL_CONN* ServerConnp, SSL_CONN* ClientConn
|
|||||||
ServerConn = ssl_handshake_to_server(param->remsock, (char *)param->hostname, &ServerCert, &errSSL);
|
ServerConn = ssl_handshake_to_server(param->remsock, (char *)param->hostname, &ServerCert, &errSSL);
|
||||||
if ( ServerConn == NULL || ServerCert == NULL ) {
|
if ( ServerConn == NULL || ServerCert == NULL ) {
|
||||||
param->res = 8011;
|
param->res = 8011;
|
||||||
dolog(param, (unsigned char *)"SSL handshake to server failed");
|
pdolog(param, (unsigned char *)"SSL handshake to server failed");
|
||||||
if(ServerConn == NULL) dolog(param, (unsigned char *)"ServerConn is NULL");
|
if(ServerConn == NULL) pdolog(param, (unsigned char *)"ServerConn is NULL");
|
||||||
if(ServerCert == NULL) dolog(param, (unsigned char *)"ServerCert is NULL");
|
if(ServerCert == NULL) pdolog(param, (unsigned char *)"ServerCert is NULL");
|
||||||
if(errSSL)dolog(param, (unsigned char *)errSSL);
|
if(errSSL)pdolog(param, (unsigned char *)errSSL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
FakeCert = ssl_copy_cert(ServerCert);
|
FakeCert = ssl_copy_cert(ServerCert);
|
||||||
if ( FakeCert == NULL ) {
|
if ( FakeCert == NULL ) {
|
||||||
param->res = 8012;
|
param->res = 8012;
|
||||||
_ssl_cert_free(ServerCert);
|
_ssl_cert_free(ServerCert);
|
||||||
dolog(param, (unsigned char *)"Failed to create certificate copy");
|
pdolog(param, (unsigned char *)"Failed to create certificate copy");
|
||||||
ssl_conn_free(ServerConn);
|
ssl_conn_free(ServerConn);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
ClientConn = ssl_handshake_to_client(param->clisock, FakeCert, &errSSL);
|
ClientConn = ssl_handshake_to_client(param->clisock, FakeCert, &errSSL);
|
||||||
if ( ClientConn == NULL ) {
|
if ( ClientConn == NULL ) {
|
||||||
param->res = 8012;
|
param->res = 8012;
|
||||||
dolog(param, (unsigned char *)"Handshake to client failed");
|
pdolog(param, (unsigned char *)"Handshake to client failed");
|
||||||
if(errSSL)dolog(param, (unsigned char *)errSSL);
|
if(errSSL)pdolog(param, (unsigned char *)errSSL);
|
||||||
_ssl_cert_free(ServerCert);
|
_ssl_cert_free(ServerCert);
|
||||||
_ssl_cert_free(FakeCert);
|
_ssl_cert_free(FakeCert);
|
||||||
ssl_conn_free(ServerConn);
|
ssl_conn_free(ServerConn);
|
||||||
@ -383,7 +383,7 @@ PLUGINAPI int PLUGINCALL ssl_plugin (struct pluginlink * pluginlink,
|
|||||||
int argc, char** argv){
|
int argc, char** argv){
|
||||||
|
|
||||||
pl = pluginlink;
|
pl = pluginlink;
|
||||||
dolog=pluginlink->findbyname("dolog");
|
pdolog=pluginlink->findbyname("dolog");
|
||||||
|
|
||||||
if(!ssl_loaded){
|
if(!ssl_loaded){
|
||||||
ssl_loaded = 1;
|
ssl_loaded = 1;
|
||||||
|
@ -4,4 +4,4 @@ TrafficPlugin$(OBJSUFFICS): TrafficPlugin.c
|
|||||||
$(CC) $(DCFLAGS) $(CFLAGS) TrafficPlugin.c
|
$(CC) $(DCFLAGS) $(CFLAGS) TrafficPlugin.c
|
||||||
|
|
||||||
$(BUILDDIR)TrafficPlugin$(DLSUFFICS): TrafficPlugin$(OBJSUFFICS)
|
$(BUILDDIR)TrafficPlugin$(DLSUFFICS): TrafficPlugin$(OBJSUFFICS)
|
||||||
$(LN) $(LNOUT)../../$(BUILDDIR)TrafficPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) TrafficPlugin$(OBJSUFFICS)
|
$(LN) $(LNOUT)../../$(BUILDDIR)TrafficPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) TrafficPlugin$(OBJSUFFICS) $(LIBS)
|
||||||
|
@ -28,8 +28,8 @@ int DBGLEVEL = 0;
|
|||||||
int already_loaded = 0;
|
int already_loaded = 0;
|
||||||
typedef int (* handler)(int argc, unsigned char ** argv);
|
typedef int (* handler)(int argc, unsigned char ** argv);
|
||||||
|
|
||||||
struct extparam * conf;
|
struct extparam * sconfp;
|
||||||
struct commands * commandhandlers;
|
struct commands * scommandhandlers;
|
||||||
struct pluginlink * pl;
|
struct pluginlink * pl;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -169,12 +169,9 @@ int h_trafcorrect(int argc, unsigned char ** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned short myhtons(unsigned short port) {
|
void(*origprelog)(struct clientparam * param) = NULL;
|
||||||
return (port << 8) | (port >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGFUNC origlogfunc;
|
void mylogfunc(struct clientparam * param) {
|
||||||
void mylogfunc(struct clientparam * param, const unsigned char * pz) {
|
|
||||||
PROXYSERVICE g_s = S_NOSERVICE;
|
PROXYSERVICE g_s = S_NOSERVICE;
|
||||||
int port;
|
int port;
|
||||||
int rule = 0;
|
int rule = 0;
|
||||||
@ -189,7 +186,7 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) {
|
|||||||
port = starttrafcorrect->port;
|
port = starttrafcorrect->port;
|
||||||
g_s = starttrafcorrect->p_service;
|
g_s = starttrafcorrect->p_service;
|
||||||
if (starttrafcorrect->p_service == S_NOSERVICE) g_s = param->service;
|
if (starttrafcorrect->p_service == S_NOSERVICE) g_s = param->service;
|
||||||
if (starttrafcorrect->port <= 0) port = myhtons(*SAPORT(¶m->sinsr));
|
if (starttrafcorrect->port <= 0) port = htons(*SAPORT(¶m->sinsr));
|
||||||
|
|
||||||
#ifndef NOPSTDINT
|
#ifndef NOPSTDINT
|
||||||
statssrv_before = param->statssrv64;
|
statssrv_before = param->statssrv64;
|
||||||
@ -199,7 +196,7 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) {
|
|||||||
statscli_before = param->statscli;
|
statscli_before = param->statscli;
|
||||||
#endif
|
#endif
|
||||||
rule++;
|
rule++;
|
||||||
if (((g_s == param->service) && (port == myhtons(*SAPORT(¶m->sinsr)))) ||
|
if (((g_s == param->service) && (port == htons(*SAPORT(¶m->sinsr)))) ||
|
||||||
( ((starttrafcorrect->type == UDP) &&
|
( ((starttrafcorrect->type == UDP) &&
|
||||||
((param->operation == UDPASSOC)||
|
((param->operation == UDPASSOC)||
|
||||||
(param->operation == DNSRESOLVE)||
|
(param->operation == DNSRESOLVE)||
|
||||||
@ -240,9 +237,9 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) {
|
|||||||
}
|
}
|
||||||
if (DBGLEVEL == 1) {
|
if (DBGLEVEL == 1) {
|
||||||
#ifndef NOPSTDINT
|
#ifndef NOPSTDINT
|
||||||
fprintf(stdout, "Port=%hd; Before: srv=%"PRINTF_INT64_MODIFIER"d, cli=%"PRINTF_INT64_MODIFIER"d; After: srv=%"PRINTF_INT64_MODIFIER"d, cli=%"PRINTF_INT64_MODIFIER"d; nreads=%ld; nwrites=%ld; Rule=%d\n",myhtons(*SAPORT(¶m->sinsr)), statssrv_before, statscli_before, param->statssrv64, param->statscli64,param->nreads,param->nwrites,rule);
|
fprintf(stdout, "Port=%hd; Before: srv=%"PRIu64", cli=%"PRIu64"; After: srv=%"PRIu64", cli=%"PRIu64"; nreads=%ld; nwrites=%ld; Rule=%d\n",htons(*SAPORT(¶m->sinsr)), statssrv_before, statscli_before, param->statssrv64, param->statscli64,param->nreads,param->nwrites,rule);
|
||||||
#else
|
#else
|
||||||
fprintf(stdout, "Port=%hd; Before: srv=%lu, cli=%lu; After: srv=%lu, cli=%lu; nreads=%ld; nwrites=%ld; Rule=%d\n",myhtons(param->sins.sin_port), statssrv_before, statscli_before, param->statssrv, param->statscli,param->nreads,param->nwrites,rule);
|
fprintf(stdout, "Port=%hd; Before: srv=%lu, cli=%lu; After: srv=%lu, cli=%lu; nreads=%ld; nwrites=%ld; Rule=%d\n",htons(*SAPORT(¶m->sins)), statssrv_before, statscli_before, param->statssrv, param->statscli,param->nreads,param->nwrites,rule);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ok = 1;
|
ok = 1;
|
||||||
@ -252,7 +249,7 @@ void mylogfunc(struct clientparam * param, const unsigned char * pz) {
|
|||||||
if ((!ok) && (DBGLEVEL == 1)) {
|
if ((!ok) && (DBGLEVEL == 1)) {
|
||||||
fprintf(stdout, "No rules specifed: service=%d, port=%d, operation=%d", param->service, *SAPORT(¶m->sinsr),param->operation);
|
fprintf(stdout, "No rules specifed: service=%d, port=%d, operation=%d", param->service, *SAPORT(¶m->sinsr),param->operation);
|
||||||
}
|
}
|
||||||
origlogfunc(param, pz);
|
if(origprelog)origprelog(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -277,8 +274,8 @@ BOOL WINAPI DllMain( HINSTANCE hModule,
|
|||||||
PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, char** argv) {
|
PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, char** argv) {
|
||||||
|
|
||||||
struct commands * starthandler;
|
struct commands * starthandler;
|
||||||
conf = pluginlink->conf;
|
sconfp = pluginlink->conf;
|
||||||
commandhandlers = pluginlink->commandhandlers;
|
scommandhandlers = pluginlink->commandhandlers;
|
||||||
pl = pluginlink;
|
pl = pluginlink;
|
||||||
|
|
||||||
if (argc>1) {
|
if (argc>1) {
|
||||||
@ -295,7 +292,7 @@ PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, char**
|
|||||||
}
|
}
|
||||||
already_loaded = 1;
|
already_loaded = 1;
|
||||||
/* äîáàâëÿåì êîìàíäó "trafcorrect" */
|
/* äîáàâëÿåì êîìàíäó "trafcorrect" */
|
||||||
starthandler = commandhandlers;
|
starthandler = scommandhandlers;
|
||||||
for ( ; starthandler->next; starthandler = starthandler->next);
|
for ( ; starthandler->next; starthandler = starthandler->next);
|
||||||
trafcorrect_handler.next = NULL;
|
trafcorrect_handler.next = NULL;
|
||||||
trafcorrect_handler.minargs = 1;
|
trafcorrect_handler.minargs = 1;
|
||||||
@ -305,8 +302,8 @@ PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, char**
|
|||||||
starthandler->next = &trafcorrect_handler;
|
starthandler->next = &trafcorrect_handler;
|
||||||
|
|
||||||
/* ïîäìåíÿåì conf->logfunc, ñ öåëüþ êîíòðîëèðîâàòü òðàôôèê */
|
/* ïîäìåíÿåì conf->logfunc, ñ öåëüþ êîíòðîëèðîâàòü òðàôôèê */
|
||||||
origlogfunc = conf->logfunc;
|
origprelog = sconfp->prelog;
|
||||||
conf->logfunc = mylogfunc;
|
sconfp->prelog = mylogfunc;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,6 +626,7 @@ struct extparam {
|
|||||||
AUTHFUNC authfunc;
|
AUTHFUNC authfunc;
|
||||||
BANDLIMFUNC bandlimfunc;
|
BANDLIMFUNC bandlimfunc;
|
||||||
TRAFCOUNTFUNC trafcountfunc;
|
TRAFCOUNTFUNC trafcountfunc;
|
||||||
|
void (*prelog)(struct clientparam * param);
|
||||||
unsigned char *logtarget, *logformat;
|
unsigned char *logtarget, *logformat;
|
||||||
struct filemon * fmon;
|
struct filemon * fmon;
|
||||||
struct filter * filters;
|
struct filter * filters;
|
||||||
|
Loading…
Reference in New Issue
Block a user