-LogFileName=/var/log/rscriptd.log
+LogFileName=./rscriptd.log
ExecutersNum=1
-ConfigDir=/etc/rscriptd
+ConfigDir=./
Password=123456
Port=9999
UserTimeout=60
-ScriptOnConnect=/etc/rscriptd/OnConnect
-ScriptOnDisconnect=/etc/rscriptd/OnDisconnect
+ScriptOnConnect=./OnConnect
+ScriptOnDisconnect=./OnDisconnect
BeforeChgIPNotifierList(),
AfterChgIPNotifierList(),
onAddUserNotifier(*this),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "auth_ao"))
{
}
//-----------------------------------------------------------------------------
#include "stg/notifer.h"
#include "stg/user_ips.h"
#include "stg/user.h"
+#include "stg/logger.h"
extern "C" PLUGIN * GetPlugin();
AUTH_AO & auth;
} onDelUserNotifier;
+ PLUGIN_LOGGER logger;
friend class CHG_BEFORE_NOTIFIER<int>;
friend class CHG_AFTER_NOTIFIER<int>;
fin6(),
fin8(),
packetTypes(),
- WriteServLog(GetStgLogger()),
enabledDirs(0xFFffFFff),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "auth_ia"))
{
InitEncrypt(&ctxS, "pr7Hhen");
USER_PTR user;
if (users->FindByName(login, &user))
{
- WriteServLog("User's connect failed: user '%s' not found. IP %s",
- login,
- inet_ntostring(sip).c_str());
+ logger("User's connect failed: user '%s' not found. IP %s",
+ login,
+ inet_ntostring(sip).c_str());
printfd(__FILE__, "User '%s' NOT found!\n", login);
SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ!");
return -1;
{
printfd(__FILE__, "User %s. IP address is incorrect. IP %s\n",
user->GetLogin().c_str(), inet_ntostring(sip).c_str());
- WriteServLog("User %s. IP address is incorrect. IP %s",
- user->GetLogin().c_str(), inet_ntostring(sip).c_str());
+ logger("User %s. IP address is incorrect. IP %s",
+ user->GetLogin().c_str(), inet_ntostring(sip).c_str());
SendError(sip, sport, protoVer, "ðÏÌØÚÏ×ÁÔÅÌØ ÎÅ ÏÐÏÚÎÁÎ! ðÒÏ×ÅÒØÔÅ IP ÁÄÒÅÓ.");
return 0;
}
userPtr->GetLogin().c_str(),
inet_ntostring(sip).c_str(),
login.c_str());
- WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'",
- userPtr->GetLogin().c_str(),
- inet_ntostring(sip).c_str(),
- login.c_str());
+ logger("IP address already in use by user '%s'. IP %s, login: '%s'",
+ userPtr->GetLogin().c_str(),
+ inet_ntostring(sip).c_str(),
+ login.c_str());
SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
return 0;
}
it->second.user->GetLogin().c_str(),
inet_ntostring(sip).c_str(),
user->GetLogin().c_str());
- WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'",
- it->second.user->GetLogin().c_str(),
- inet_ntostring(sip).c_str(),
- user->GetLogin().c_str());
+ logger("IP address already in use by user '%s'. IP %s, login: '%s'",
+ it->second.user->GetLogin().c_str(),
+ inet_ntostring(sip).c_str(),
+ user->GetLogin().c_str());
SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
return 0;
}
{
SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ ÉÌÉ ÐÁÒÏÌØ!");
printfd(__FILE__, "Login or password is wrong!\n");
- WriteServLog("User's connect failed. User: '%s', ip %s. Wrong login or password",
- login.c_str(),
- inet_ntostring(sip).c_str());
+ logger("User's connect failed. User: '%s', ip %s. Wrong login or password",
+ login.c_str(),
+ inet_ntostring(sip).c_str());
ip2user.erase(it);
return 0;
}
printfd(__FILE__, "Login %s already in use from ip %s. IP %s\n",
login.c_str(), inet_ntostring(user->GetCurrIP()).c_str(),
inet_ntostring(sip).c_str());
- WriteServLog("Login %s already in use from ip %s. IP %s",
- login.c_str(),
- inet_ntostring(user->GetCurrIP()).c_str(),
- inet_ntostring(sip).c_str());
+ logger("Login %s already in use from ip %s. IP %s",
+ login.c_str(),
+ inet_ntostring(user->GetCurrIP()).c_str(),
+ inet_ntostring(sip).c_str());
SendError(sip, sport, protoVer, "÷ÁÛ ÌÏÇÉÎ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
ip2user.erase(it);
return 0;
#include "stg/blowfish.h"
#include "stg/logger.h"
#include "stg/utime.h"
+#include "stg/logger.h"
extern "C" PLUGIN * GetPlugin();
std::map<std::string, int> packetTypes;
- STG_LOGGER & WriteServLog;
-
uint32_t enabledDirs;
DEL_USER_NOTIFIER onDelUserNotifier;
+ PLUGIN_LOGGER logger;
+
friend class UnauthorizeUser;
};
//-----------------------------------------------------------------------------
LIBS += $(LIB_THREAD)
-STGLIBS = common
+STGLIBS = common \
+ logger
include ../../Makefile.in
portU(0),
sockTCP(-1),
sockUDP(-1),
- errorStr()
+ errorStr(),
+ logger(GetPluginLogger(GetStgLogger(), "cap_nf"))
{
}
#include "stg/os_int.h"
#include "stg/plugin.h"
#include "stg/module_settings.h"
+#include "stg/logger.h"
#define VERSION "CAP_NF v. 0.4"
#define START_POS 40
int sockTCP;
int sockUDP;
mutable std::string errorStr;
+ PLUGIN_LOGGER logger;
static void * RunUDP(void *);
static void * RunTCP(void *);
LIBS += $(LIB_THREAD)
-STGLIBS = common
+STGLIBS = common \
+ logger
include ../../Makefile.in
thread(),
nonstop(false),
isRunning(false),
- traffCnt(NULL)
+ traffCnt(NULL),
+ logger(GetPluginLogger(GetStgLogger(), "cap_divert"))
{
}
//-----------------------------------------------------------------------------
#include "stg/plugin.h"
#include "stg/module_settings.h"
+#include "stg/logger.h"
class USERS;
class TARIFFS;
bool isRunning;
TRAFFCOUNTER * traffCnt;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
LIBS += $(LIB_THREAD)
-STGLIBS = common
+STGLIBS = common \
+ logger
include ../../Makefile.in
isRunning(false),
capSock(-1),
settings(),
- traffCnt(NULL)
+ traffCnt(NULL),
+ logger(GetPluginLogger(GetStgLogger(), "cap_ether"))
{
}
//-----------------------------------------------------------------------------
#include "stg/os_int.h"
#include "stg/plugin.h"
#include "stg/module_settings.h"
+#include "stg/logger.h"
extern "C" PLUGIN * GetPlugin();
MODULE_SETTINGS settings;
TRAFFCOUNTER * traffCnt;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
LIBS += $(LIB_THREAD)
-STGLIBS = common
+STGLIBS = common \
+ logger
include ../../Makefile.in
nonstop(false),
isRunning(false),
capSock(-1),
- traffCnt(NULL)
+ traffCnt(NULL),
+ logger(GetPluginLogger(GetStgLogger(), "cap_ether"))
{
}
//-----------------------------------------------------------------------------
#include "stg/plugin.h"
#include "stg/module_settings.h"
+#include "stg/logger.h"
class USERS;
class TARIFFS;
int capSock;
TRAFFCOUNTER * traffCnt;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
LIBS += $(LIB_THREAD)
-STGLIBS = common
+STGLIBS = common \
+ logger
include ../../Makefile.in
isRunning(false),
capSock(-1),
traffCnt(NULL),
- buf()
+ buf(),
+ logger(GetPluginLogger(GetStgLogger(), "cap_ipq"))
{
memset(buf, 0, BUFSIZE);
}
#include "stg/plugin.h"
#include "stg/module_settings.h"
#include "stg/os_int.h"
+#include "stg/logger.h"
#define BUFSIZE (256)
#define PAYLOAD_LEN (96)
TRAFFCOUNTER * traffCnt;
unsigned char buf[BUFSIZE];
+
+ PLUGIN_LOGGER logger;
};
#endif
tid(),
cookies(),
dayFee(0),
- dirNames()
+ dirNames(),
+ logger(GetPluginLogger(GetStgLogger(), "conf_rpc"))
{
}
#include "stg/plugin.h"
#include "stg/admin_conf.h"
#include "stg/module_settings.h"
+#include "stg/logger.h"
#define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
PRIV priviledges;
};
-class RPC_CONFIG :public PLUGIN
+class RPC_CONFIG : public PLUGIN
{
public:
RPC_CONFIG();
ADMIN_INFO> cookies;
size_t dayFee;
std::vector<std::string> dirNames;
+ PLUGIN_LOGGER logger;
};
#endif
}
}
//-----------------------------------------------------------------------------
-CONFIGPROTO::CONFIGPROTO()
+CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
: answerList(),
requestList(),
adminIP(0),
nonstop(true),
state(0),
currAdmin(NULL),
- WriteServLog(GetStgLogger()),
+ logger(l),
listenSocket(-1),
parserGetServInfo(),
parserGetUsers(),
if (!xmlParser)
{
- WriteServLog("Couldn't allocate memory for parser.");
+ logger("Couldn't allocate memory for parser.");
exit(1);
}
if (XML_Parse(xmlParser, (*n).c_str(), len, done) == XML_STATUS_ERROR)
{
- WriteServLog("Invalid configuration request");
+ logger("Invalid configuration request");
printfd(__FILE__, "Parse error at line %d:\n%s\n",
XML_GetCurrentLineNumber(xmlParser),
XML_ErrorString(XML_GetErrorCode(xmlParser)));
//-----------------------------------------------------------------------------
class CONFIGPROTO {
public:
- CONFIGPROTO();
+ CONFIGPROTO(PLUGIN_LOGGER & l);
~CONFIGPROTO();
void SetPort(uint16_t port);
bool nonstop;
int state;
ADMIN * currAdmin;
- STG_LOGGER & WriteServLog;
+ PLUGIN_LOGGER & logger;
int listenSocket;
{
if (send(sock, ERR_HEADER, sizeof(ERR_HEADER) - 1, 0) < 0)
{
- WriteServLog("send ERR_HEADER error in SendHdrAnswer.");
+ logger("send ERR_HEADER error in SendHdrAnswer.");
return -1;
}
}
{
if (send(sock, OK_HEADER, sizeof(OK_HEADER) - 1, 0) < 0)
{
- WriteServLog("send OK_HEADER error in SendHdrAnswer.");
+ logger("send OK_HEADER error in SendHdrAnswer.");
return -1;
}
}
{
if (send(sock, OK_LOGIN, sizeof(OK_LOGIN) - 1, 0) < 0)
{
- WriteServLog("Send OK_LOGIN error in SendLoginAnswer.");
+ logger("Send OK_LOGIN error in SendLoginAnswer.");
return -1;
}
return 0;
{
if (send(sock, ERR_LOGINS, sizeof(ERR_LOGINS) - 1, 0) < 0)
{
- WriteServLog("send ERR_LOGIN error in SendLoginAnswer.");
+ logger("send ERR_LOGIN error in SendLoginAnswer.");
return -1;
}
}
{
if (send(sock, OK_LOGINS, sizeof(OK_LOGINS) - 1, 0) < 0)
{
- WriteServLog("send OK_LOGINS error in SendLoginSAnswer.");
+ logger("send OK_LOGINS error in SendLoginSAnswer.");
return -1;
}
}
//-----------------------------------------------------------------------------
void CONFIGPROTO::WriteLogAccessFailed(uint32_t ip)
{
-WriteServLog("Admin's connect failed. IP %s", inet_ntostring(ip).c_str());
+logger("Admin's connect failed. IP %s", inet_ntostring(ip).c_str());
}
//-----------------------------------------------------------------------------
thread(),
nonstop(false),
isRunning(false),
- config(),
+ logger(GetPluginLogger(GetStgLogger(), "conf_sg")),
+ config(logger),
users(NULL),
admins(NULL),
tariffs(NULL),
#include "stg/plugin.h"
#include "stg/store.h"
+#include "stg/logger.h"
#include "configproto.h"
extern "C" PLUGIN * GetPlugin();
pthread_t thread;
bool nonstop;
bool isRunning;
+ PLUGIN_LOGGER logger;
CONFIGPROTO config;
USERS * users;
ADMINS * admins;
ChgCurrIPNotifierList(),
ChgIPNotifierList(),
onAddUserNotifier(*this),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "ping"))
{
pthread_mutex_init(&mutex, NULL);
}
#include "stg/user_ips.h"
#include "stg/pinger.h"
#include "stg/users.h"
+#include "stg/logger.h"
extern "C" PLUGIN * GetPlugin();
ADD_USER_NONIFIER_PING onAddUserNotifier;
DEL_USER_NONIFIER_PING onDelUserNotifier;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
thread(),
mutex(),
sock(-1),
- packet()
+ packet(),
+ logger(GetPluginLogger(GetStgLogger(), "radius"))
{
InitEncrypt(&ctx, "");
}
#include "stg/users.h"
#include "stg/blowfish.h"
#include "stg/rad_packets.h"
+#include "stg/logger.h"
extern "C" PLUGIN * GetPlugin();
RAD_PACKET packet;
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
mutex(),
sock(0),
onAddUserNotifier(*this),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "rscript"))
{
pthread_mutex_init(&mutex, NULL);
}
#include "stg/users.h"
#include "stg/blowfish.h"
#include "stg/rs_packets.h"
+#include "stg/logger.h"
#include "nrmap_parser.h"
extern "C" PLUGIN * GetPlugin();
RS_ADD_USER_NONIFIER onAddUserNotifier;
RS_DEL_USER_NONIFIER onDelUserNotifier;
+ PLUGIN_LOGGER logger;
+
friend class UpdateRouter;
friend class DisconnectUser;
};
notifiers(),
addUserNotifier(*this),
delUserNotifier(*this),
- addDelTariffNotifier(*this)
+ addDelTariffNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "smux"))
{
pthread_mutex_init(&mutex, NULL);
#include "stg/module_settings.h"
#include "stg/notifer.h"
#include "stg/noncopyable.h"
+#include "stg/logger.h"
#include "sensors.h"
#include "tables.h"
ADD_USER_NOTIFIER addUserNotifier;
DEL_USER_NOTIFIER delUserNotifier;
ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
version("file_store v.1.04"),
storeSettings(),
settings(),
- mutex()
+ mutex(),
+ logger(GetPluginLogger(GetStgLogger(), "store_files"))
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#include "stg/store.h"
#include "stg/conffiles.h"
#include "stg/user_traff.h"
+#include "stg/logger.h"
//-----------------------------------------------------------------------------
extern "C" STORE * GetStore();
FILES_STORE_SETTINGS storeSettings;
MODULE_SETTINGS settings;
mutable pthread_mutex_t mutex;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
db(),
mutex(),
til(IBPP::ilConcurrency),
- tlr(IBPP::lrWait)
+ tlr(IBPP::lrWait),
+ logger(GetPluginLogger(GetStgLogger(), "store_firebird"))
{
pthread_mutex_init(&mutex, NULL);
}
#include "stg/store.h"
#include "stg/locker.h"
#include "stg/ibpp.h"
+#include "stg/logger.h"
struct ToLower {
char operator() (char c) const { return std::tolower(c); }
std::string version;
mutable std::string strError;
- mutable std::string db_server, db_database, db_user, db_password;
+ std::string db_server, db_database, db_user, db_password;
MODULE_SETTINGS settings;
mutable IBPP::Database db;
mutable pthread_mutex_t mutex;
- mutable IBPP::TIL til;
- mutable IBPP::TLR tlr;
+ IBPP::TIL til;
+ IBPP::TLR tlr;
+ PLUGIN_LOGGER logger;
int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const;
};
SRCS = ./mysql_store.cpp
STGLIBS = common \
- crypto
+ crypto \
+ logger
MYSQL_CFLAGS = $(shell mysql_config --cflags)
MYSQL_LDFLAGS = $(shell mysql_config --libs_r)
: errorStr(),
version("mysql_store v.0.67"),
storeSettings(),
- settings()
+ settings(),
+ logger(GetPluginLogger(GetStgLogger(), "store_mysql"))
{
};
//-----------------------------------------------------------------------------
#include "stg/module_settings.h"
#include "stg/store.h"
#include "stg/user_traff.h"
+#include "stg/logger.h"
using namespace std;
//-----------------------------------------------------------------------------
string version;
MYSQL_STORE_SETTINGS storeSettings;
MODULE_SETTINGS settings;
+
+ PLUGIN_LOGGER logger;
};
//-----------------------------------------------------------------------------
STGLIBS = common \
crypto \
- locker
+ locker \
+ logger
PG_CFLAGS = $(shell pg_config --includedir)
PG_LDFLAGS = $(shell pg_config --libdir)
mutex(),
version(0),
retries(3),
- connection(NULL)
+ connection(NULL),
+ logger(GetPluginLogger(GetStgLogger(), "store_postgresql"))
{
pthread_mutex_init(&mutex, NULL);
}
#include <map>
#include "stg/store.h"
+#include "stg/logger.h"
// Minimal DB version is 5
// Recommended DB version is 6 (support FreeMb logging on disconnects)
int retries;
PGconn * connection;
+
+ PLUGIN_LOGGER logger;
};
extern const volatile time_t stgTime;
class STG_LOGGER
{
friend STG_LOGGER & GetStgLogger();
+friend class PLUGIN_LOGGER;
public:
~STG_LOGGER();
pthread_mutex_t mutex;
};
//-----------------------------------------------------------------------------
+class PLUGIN_LOGGER : private STG_LOGGER
+{
+friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName);
+
+public:
+ PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs);
+ void operator()(const char * fmt, ...);
+
+private:
+ PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn);
+ std::string pluginName;
+};
+
+PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName);
#endif //STG_LOGGER_H
return s;
}
//-----------------------------------------------------------------------------
+PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn)
+ : STG_LOGGER(),
+ pluginName(pn)
+{
+ SetLogFileName(logger.fileName);
+}
+//-----------------------------------------------------------------------------
+PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs)
+ : STG_LOGGER(),
+ pluginName(rhs.pluginName)
+{
+ SetLogFileName(fileName);
+}
+//-----------------------------------------------------------------------------
+void PLUGIN_LOGGER::operator()(const char * fmt, ...)
+{
+char buff[2029];
+
+va_list vl;
+va_start(vl, fmt);
+vsnprintf(buff, sizeof(buff), fmt, vl);
+va_end(vl);
+
+STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff);
+}
+//-----------------------------------------------------------------------------
+PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName)
+{
+return PLUGIN_LOGGER(logger, pluginName);
+}
+//-----------------------------------------------------------------------------