+++ /dev/null
-###############################################################################
-# $Id: Makefile,v 1.9 2008/12/04 17:09:40 faust Exp $
-###############################################################################
-
-include ../../../../../Makefile.conf
-
-PROG = mod_conf_sg-ng.so
-
-SRCS = ./stgconfig.cpp \
- ./creator.cpp \
- ./main_thread.cpp \
- ./config_thread.cpp \
- ./root_parser.cpp \
- ./parser_info.cpp \
- ./parser_getuser.cpp \
- ./parser_getusers.cpp
-
-LIBS += -lexpat \
- -lboost_thread-mt
-
-STGLIBS = common \
- logger \
- crypto
-
-include ../../Makefile.in
+++ /dev/null
-#include <expat.h>
-
-#include <cstring>
-#include <cerrno>
-#include <cassert>
-#include <iostream>
-
-#include <boost/thread/mutex.hpp>
-
-// TODO: Fix this shit!
-#include "../../../admins.h"
-
-#include "common.h"
-#include "proto.h"
-#include "config_thread.h"
-#include "root_parser.h"
-
-void DumpCrypto(const char * data, size_t size)
-{
- std::string dumpstr = "";
- for (unsigned i = 0; i < size; ++i) {
- std::string ch;
- strprintf(&ch, "%x", *(data + i));
- dumpstr += ch;
- }
- printfd(__FILE__, "Crypto dump: '%s'\n", dumpstr.c_str());
-}
-
-CONFIG_THREAD::CONFIG_THREAD(ADMINS * a, TARIFFS * t, USERS * u, const SETTINGS * s)
- : sd(-1),
- done(false),
- state(ST_NOOP),
- respCode(RESP::OK),
- admins(a),
- tariffs(t),
- users(u),
- settings(s)
-{
- /*printfd(__FILE__, "sizeof(REQ::HEADER) = %d\n", sizeof(REQ::HEADER));
- printfd(__FILE__, "sizeof(REQ::CRYPTO_HEADER) = %d\n", sizeof(REQ::CRYPTO_HEADER));
- printfd(__FILE__, "sizeof(RESP::HEADER) = %d\n", sizeof(RESP::HEADER));
- printfd(__FILE__, "sizeof(RESP::CRYPTO_HEADER) = %d\n", sizeof(RESP::CRYPTO_HEADER));*/
- assert(sizeof(REQ::HEADER) % 8 == 0);
- assert(sizeof(REQ::CRYPTO_HEADER) % 8 == 0);
- assert(sizeof(RESP::HEADER) % 8 == 0);
- assert(sizeof(RESP::CRYPTO_HEADER) % 8 == 0);
-
- iv = new unsigned char[8];
- memset(iv, 0, 8);
-}
-
-CONFIG_THREAD::CONFIG_THREAD(const CONFIG_THREAD & rvalue)
- : sd(rvalue.sd),
- remoteAddr(rvalue.remoteAddr),
- done(false),
- state(ST_NOOP),
- respCode(rvalue.respCode),
- admins(rvalue.admins),
- tariffs(rvalue.tariffs),
- users(rvalue.users),
- settings(rvalue.settings)
-{
- assert(!rvalue.done);
- iv = new unsigned char[8];
- memcpy(iv, rvalue.iv, 8);
-}
-
-CONFIG_THREAD & CONFIG_THREAD::operator=(const CONFIG_THREAD & rvalue)
-{
- assert(0 && "Never be here");
- return *this;
-}
-
-CONFIG_THREAD::~CONFIG_THREAD()
-{
- //assert(done);
- delete[] iv;
-}
-
-void CONFIG_THREAD::operator() ()
-{
- if (sd < 0) {
- printfd(__FILE__, "CONFIG_THREAD::operator()() Invalid socket descriptor\n");
- return;
- }
-
- if (ReadReq()) {
- Process();
- }
-
- WriteResp();
-
- close(sd);
-
- {
- boost::mutex::scoped_lock lock(mutex);
- done = true;
- }
-}
-
-bool CONFIG_THREAD::IsDone() const
-{
- boost::mutex::scoped_lock lock(mutex);
- return done;
-}
-
-void CONFIG_THREAD::SetConnection(int sock, struct sockaddr_in sin)
-{
- sd = sock;
- remoteAddr = sin;
-}
-
-bool CONFIG_THREAD::ReadBlock(void * dest, size_t & size, int timeout) const
-{
- unsigned readSize = 0;
- char * ptr = static_cast<char *>(dest);
- while (readSize < size) {
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = timeout * 1000;
-
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(sd, &rfds);
-
- int res = select(sd + 1, &rfds, NULL, NULL, &tv);
- /* Don't rely on the value of tv now! */
-
- if (res < 0) {
- printfd(__FILE__, "CONFIG_THREAD::ReadBlock() Select error: '%s'\n", strerror(errno));
- return false;
- }
-
- if (res == 0) {
- // Timeout
- size = readSize;
- return false;
- }
-
- res = read(sd, ptr + readSize, size - readSize);
-
- if (res == 0) { // EOF
- printfd(__FILE__, "CONFIG_THREAD::ReadBlock() EOF\n");
- return false;
- }
-
- // Ignore 'Interrupted system call' errors
- if (res < 0) {
- if (errno != EINTR) {
- printfd(__FILE__, "CONFIG_THREAD::ReadBlock() Read error: '%s'\n", strerror(errno));
- return false;
- } else {
- continue;
- }
- }
-
- readSize += res;
- }
-
- return true;
-}
-
-bool CONFIG_THREAD::WriteBlock(const void * source, size_t & size, int timeout) const
-{
- const char * ptr = static_cast<const char *>(source);
- unsigned writeSize = 0;
- while (writeSize < size) {
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = timeout * 1000;
-
- fd_set wfds;
- FD_ZERO(&wfds);
- FD_SET(sd, &wfds);
-
- int res = select(sd + 1, NULL, &wfds, NULL, &tv);
- /* Don't rely on the value of tv now! */
-
- if (res < 0) {
- printfd(__FILE__, "CONFIG_THREAD::WriteBlock() Select error: '%s'\n", strerror(errno));
- return false;
- }
-
- if (res == 0) {
- // Timeout
- size = writeSize;
- return false;
- }
-
- res = write(sd, ptr + writeSize, size - writeSize);
-
- // Ignore 'Interrupted system call' errors
- if (res < 0 && errno != EINTR) {
- printfd(__FILE__, "CONFIG_THREAD::WriteBlock() Write error: '%s'\n", strerror(errno));
- return false;
- }
-
- writeSize += res;
- }
-
- return true;
-}
-
-bool CONFIG_THREAD::ReadReq()
-{
- struct REQ::HEADER reqHeader;
-
- size_t size = sizeof(reqHeader);
- if (!ReadBlock(&reqHeader, size, 5000)) {
- state = ST_ERROR;
- message = "No request header within 5 sec";
- printfd(__FILE__, "CONFIG_THREAD::ReadReq() %s\n", message.c_str());
- return false;
- }
-
- if (strncmp(reqHeader.magic, PROTO_MAGIC, sizeof(reqHeader.magic))) {
- state = ST_ERROR;
- respCode = RESP::INVALID_MAGIC;
- message = "Invalid magic code in header";
- printfd(__FILE__, "CONFIG_THREAD::ReadReq() %s\n", message.c_str());
- return false;
- }
-
- uint32_t version = ntohl(reqHeader.version);
- if (version > (2 << 8 | 0)) {
- state = ST_ERROR;
- respCode = RESP::UNSUPPORTED_VERSION;
- message = "Unsupported version";
- printfd(__FILE__, "CONFIG_THREAD::ReadReq() %s (wanted: %d, actual: %d)\n", message.c_str(), (2 << 8 | 0), version);
- return false;
- }
-
- versionMinor = version & 0x0000FFFF;
- versionMajor = (version >> 8) & 0x0000FFFF;
-
- reqHeader.login[sizeof(reqHeader.login) - 1] = 0;
-
- login = reqHeader.login;
-
- if (!CheckLogin(login, password)) {
- state = ST_ERROR;
- respCode = RESP::INVALID_CREDENTIALS;
- message = "Unknown login";
- printfd(__FILE__, "CONFIG_THREAD::ReadReq() %s\n", message.c_str());
- return false;
- }
-
- return ReceiveData();
-}
-
-bool CONFIG_THREAD::ReceiveData()
-{
- unsigned char buffer[sizeof(struct REQ::CRYPTO_HEADER)];
- //unsigned char iv[] = "00000000";
- size_t size = sizeof(struct REQ::CRYPTO_HEADER);
-
- if (!ReadBlock(buffer, size, 5000)) {
- state = ST_ERROR;
- message = "No crypto header within 5 secs";
- printfd(__FILE__, "CONFIG_THREAD::ReceiveData() %s\n", message.c_str());
- return false;
- }
-
- BF_set_key(&key, password.length(), reinterpret_cast<const unsigned char *>(password.c_str()));
-
- struct REQ::CRYPTO_HEADER reqCryptoHeader;
-
- BF_cbc_encrypt(buffer, reinterpret_cast<unsigned char *>(&reqCryptoHeader), sizeof(struct REQ::CRYPTO_HEADER), &key, iv, BF_DECRYPT);
-
- reqCryptoHeader.login[sizeof(reqCryptoHeader.login) - 1] = 0;
-
- std::string cryptoLogin(reqCryptoHeader.login);
-
- if (login != cryptoLogin) {
- state = ST_ERROR;
- respCode = RESP::INVALID_CREDENTIALS;
- message = "Password is invalid";
- printfd(__FILE__, "CONFIG_THREAD::ReceiveData() %s\n", message.c_str());
- return false;
- }
-
- //assert(reqCryptoHeader.dataSize % 8 == 0);
-
- char block[1496];
- unsigned char cryptoBlock[1496];
- size_t length = 0;
- uint32_t dataSize = ntohl(reqCryptoHeader.dataSize);
-
- while (length < dataSize) {
- size_t delta = dataSize - length;
- if (delta > sizeof(cryptoBlock)) {
- delta = sizeof(cryptoBlock);
- }
- size_t bs = delta;
- ReadBlock(cryptoBlock, bs, 5000);
- if (bs != delta) {
- state = ST_ERROR;
- message = "No data within 5 secs";
- printfd(__FILE__, "CONFIG_THREAD::ReceiveData() %s\n", message.c_str());
- return false;
- }
-
- BF_cbc_encrypt(cryptoBlock, reinterpret_cast<unsigned char *>(block), bs, &key, iv, BF_DECRYPT);
-
- xml.append(block, bs);
-
- length += bs;
- }
-
- return true;
-}
-
-void CONFIG_THREAD::Process()
-{
- ROOT_PARSER parser(currAdmin, tariffs, users, settings);
-
- XML_Parser p;
-
- p= XML_ParserCreate(NULL);
- XML_SetElementHandler(p, &TagBegin, &TagEnd);
- XML_SetUserData(p, &parser);
-
- if (!XML_Parse(p, xml.c_str(), xml.length(), true)) {
- printfd(__FILE__, "CONFIG_THREAD::Process() Error: '%s' at line %d\n", XML_ErrorString(XML_GetErrorCode(p)), XML_GetCurrentLineNumber(p));
- //MakeErrorXML();
- }
-
- XML_ParserFree(p);
-
- xml = parser.GetResult();
-}
-
-void CONFIG_THREAD::WriteResp() const
-{
- RESP::HEADER respHeader;
-
- strncpy(respHeader.magic, PROTO_MAGIC, sizeof(respHeader.magic));
- respHeader.version = htonl(2 << 8 | 0);
- respHeader.code = respCode;
-
- RESP::CRYPTO_HEADER respCryptoHeader;
- strncpy(respCryptoHeader.login, login.c_str(), sizeof(respCryptoHeader.login));
- if (xml.size() % 8 == 0) {
- respCryptoHeader.dataSize = htonl(xml.size());
- } else {
- respCryptoHeader.dataSize = htonl((xml.size() / 8 + 1) * 8);
- }
-
- size_t size = sizeof(respHeader);
- if (!WriteBlock(&respHeader, size, 5000)) {
- printfd(__FILE__, "CONFIG_THREAD::WriteResp() Failed to send answer header\n");
- return;
- }
-
- if (state != ST_ERROR) {
- unsigned char buffer[sizeof(respCryptoHeader)];
- size = sizeof(respCryptoHeader);
-
- BF_cbc_encrypt(reinterpret_cast<unsigned char *>(&respCryptoHeader), buffer, size, &key, iv, BF_ENCRYPT);
-
- if (!WriteBlock(buffer, size, 5000)) {
- printfd(__FILE__, "CONFIG_THREAD::WriteResp() Failed to send answer crypto-header\n");
- return;
- }
-
- SendData();
- }
-}
-
-void CONFIG_THREAD::SendData() const
-{
- size_t pos = 0;
- std::string data(xml);
- if (data.size() % 8) {
- size_t delta = (data.size() / 8 + 1) * 8 - data.size();
- data.append(delta, ' ');
- }
- while (pos < data.size()) {
- unsigned char source[1496];
- unsigned char buffer[1496];
-
- size_t size;
- if (data.size() - pos > sizeof(source)) {
- memcpy(source, data.c_str() + pos, sizeof(source));
- size = sizeof(source);
- } else {
- memset(source, 0, sizeof(source));
- memcpy(source, data.c_str() + pos, data.size() - pos);
- size = data.size() - pos;
- }
-
- BF_cbc_encrypt(source, buffer, size, &key, iv, BF_ENCRYPT);
-
- if (!WriteBlock(buffer, size, 5000)) {
- printfd(__FILE__, "CONFIG_THREAD::SendData() Failed to write data block\n");
- return;
- }
-
- pos += size; // size?
- }
-
- return;
-}
-
-bool CONFIG_THREAD::CheckLogin(const std::string & login, std::string & password)
-{
- currAdmin = admins->FindAdmin(login);
-
- if (currAdmin == NULL) {
- printfd(__FILE__, "CONFIG_THREAD::CheckLogin() Admin '%s' not found\n", login.c_str());
- return false;
- }
-
- password = currAdmin->GetPassword();
-
- return true;
-}
-
-void CONFIG_THREAD::TagBegin(void * userData, const char * name, const char ** attr)
-{
- ROOT_PARSER * self = static_cast<ROOT_PARSER *>(userData);
- self->StartTag(name, attr);
-}
-
-void CONFIG_THREAD::TagEnd(void * userData, const char * name)
-{
- ROOT_PARSER * self = static_cast<ROOT_PARSER *>(userData);
- self->EndTag(name);
-}
+++ /dev/null
-#ifndef __CONFIG_THREAD_H__
-#define __CONFIG_THREAD_H__
-
-#include <arpa/inet.h>
-#include <openssl/blowfish.h>
-
-class ADMINS;
-class ADMIN;
-class TARIFFS;
-class USERS;
-class SETTINGS;
-
-namespace boost {
- class mutex;
-};
-
-class CONFIG_THREAD {
-public:
- CONFIG_THREAD(ADMINS * , TARIFFS * t, USERS * u, const SETTINGS * s);
- CONFIG_THREAD(const CONFIG_THREAD & rvalue);
- ~CONFIG_THREAD();
-
-
- void operator() ();
-
- void SetConnection(int sock, struct sockaddr_in sin);
- bool IsDone() const;
-
- enum {ST_NOOP, ST_OK, ST_ERROR};
-
-private:
- int sd;
- struct sockaddr_in remoteAddr;
- bool done;
- int state;
- uint16_t versionMinor;
- uint16_t versionMajor;
- std::string message;
- std::string login;
- std::string password;
- std::string xml;
- uint32_t respCode;
-
- BF_KEY key;
- unsigned char * iv;
-
- ADMINS * admins;
- TARIFFS * tariffs;
- USERS * users;
- const SETTINGS * settings;
- const ADMIN * currAdmin;
-
- mutable boost::mutex mutex;
-
- bool ReadBlock(void * dest, size_t & size, int timeout) const;
- bool WriteBlock(const void * source, size_t & size, int timeout) const;
-
- bool ReadReq();
- void Process();
- void WriteResp() const;
- //void MakeErrorXML();
-
- bool CheckLogin(const std::string & login, std::string & password);
- bool ReceiveData();
- void SendData() const;
-
- static void TagBegin(void * userData, const char * name, const char ** attr);
- static void TagEnd(void * userData, const char * name);
-
-
- CONFIG_THREAD & operator=(const CONFIG_THREAD & rvalue);
-};
-
-#endif
+++ /dev/null
-#include "stg/plugin_creator.h"
-#include "stgconfig.h"
-
-PLUGIN_CREATOR<STGCONFIG2> stgc;
-
-BASE_PLUGIN * GetPlugin()
-{
-return stgc.GetPlugin();
-}
+++ /dev/null
-#include <unistd.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-
-#include <cerrno>
-#include <cstring>
-
-#include <boost/thread.hpp>
-
-#include "common.h"
-
-#include "main_thread.h"
-#include "config_thread.h"
-
-MAIN_THREAD::MAIN_THREAD(ADMINS * a, TARIFFS * t, USERS * u, const SETTINGS * s)
- : running(true),
- sd(-1),
- port(44000),
- maxConnections(60),
- admins(a),
- tariffs(t),
- users(u),
- settings(s)
-{
-}
-
-MAIN_THREAD::~MAIN_THREAD()
-{
-}
-
-void MAIN_THREAD::operator() ()
-{
- if (!InitNetwork()) {
- return;
- }
-
- int counter = 0;
- while (running) {
- if (WaitConnection()) {
- AcceptConnection();
- }
- if (counter == 0) {
- CleanupThreads();
- }
- ++counter;
- counter = counter % 10; // Every 5 sec
- }
-
- close(sd);
-}
-
-bool MAIN_THREAD::InitNetwork()
-{
- struct sockaddr_in listenAddr;
-
- sd = socket(AF_INET, SOCK_STREAM, 0);
-
- if (sd < 0) {
- printfd(__FILE__, "MAIN_THREAD::InitNetwork() Socket creation failed: '%s'\n", strerror(errno));
- return false;
- }
-
- listenAddr.sin_family = AF_INET;
- listenAddr.sin_port = htons(port);
- listenAddr.sin_addr.s_addr = INADDR_ANY;
-
- if (bind(sd, (struct sockaddr*)&listenAddr, sizeof(listenAddr)) < 0) {
- printfd(__FILE__, "MAIN_THREAD::InitNetwork() Bind failed: '%s'\n", strerror(errno));
- return false;
- }
-
- if(listen(sd, 8) < 0) {
- printfd(__FILE__, "MAIN_THREAD::InitNetwork() Error starting to listen: '%s'\n", strerror(errno));
- return false;
- }
-
- return true;
-}
-
-bool MAIN_THREAD::WaitConnection()
-{
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(sd, &rfds);
-
- /* Wait up to five seconds. */
- struct timeval tv;
- tv.tv_sec = 1;
- tv.tv_usec = 0;
-
- int res = select(sd + 1, &rfds, NULL, NULL, &tv);
- /* Don't rely on the value of tv now! */
-
- if (res == -1) {
- printfd(__FILE__, "MAIN_THREAD::WaitConnection() Select failed: '%s'\n", strerror(errno));
- return false;
- }
-
- if (res && FD_ISSET(sd, &rfds)) {
- return true;
- }
-
- // Timeout
- return false;
-}
-
-void MAIN_THREAD::AcceptConnection()
-{
- if (connections.size() >= maxConnections) {
- CleanupThreads();
- if (connections.size() >= maxConnections) {
- return;
- }
- }
-
- struct sockaddr_in remoteAddr;
- socklen_t len = sizeof(remoteAddr);
- int newSD = accept(sd, (struct sockaddr *)&remoteAddr, &len);
-
- if (newSD < 0) {
- printfd(__FILE__, "MAIN_THREAD::AcceptConnection() Accept failed: '%s'\n", strerror(errno));
- return;
- }
-
- CONFIG_THREAD ct(admins, tariffs, users, settings);
- ct.SetConnection(newSD, remoteAddr);
-
- connections.push_back(ct);
- boost::thread thread(boost::ref(connections.back()));
- thread.detach();
-}
-
-void MAIN_THREAD::CleanupThreads()
-{
- connections.remove_if(
- std::mem_fun_ref(&CONFIG_THREAD::IsDone)
- );
- printfd(__FILE__, "MAIN_THREAD::CleanupThreads() Active threads: %d\n", connections.size());
-}
+++ /dev/null
-#ifndef __MAIN_THREAD_H__
-#define __MAIN_THREAD_H__
-
-#include <list>
-
-#include "os_int.h"
-
-class CONFIG_THREAD;
-class ADMINS;
-class TARIFFS;
-class USERS;
-class SETTINGS;
-
-class MAIN_THREAD {
-public:
- MAIN_THREAD(ADMINS * a, TARIFFS * t, USERS * u, const SETTINGS * s);
- ~MAIN_THREAD();
-
- void operator() ();
-
- void Stop() { running = false; };
- void SetPort(uint16_t p) { port = p; };
- void SetClasses(ADMINS * a,
- TARIFFS * t,
- USERS * u,
- const SETTINGS * s)
- {
- admins = a;
- tariffs = t;
- users = u;
- settings = s;
- };
-
- void SetMaxConnections(unsigned max) { maxConnections = max; };
-
-private:
- bool running;
- int sd;
- uint16_t port;
- unsigned maxConnections;
-
- ADMINS * admins;
- TARIFFS * tariffs;
- USERS * users;
- const SETTINGS * settings;
-
- std::list<CONFIG_THREAD> connections;
-
- bool InitNetwork();
- bool WaitConnection();
- void AcceptConnection();
- void CleanupThreads();
-
-};
-
-#endif
+++ /dev/null
-#ifndef __PARSER_H__
-#define __PARSER_H__
-
-#include <string>
-
-class PARSER {
- public:
- PARSER() {};
- virtual ~PARSER() {};
-
- virtual bool StartTag(const char * name, const char ** attr) = 0;
- virtual bool EndTag(const char * name) = 0;
- virtual const std::string & GetResult() const = 0;
-};
-
-#endif
+++ /dev/null
-// TODO: Fix this shit!
-#include "../../../admin.h"
-#include "../../../users.h"
-
-#include "parser_getuser.h"
-
-PARSER_GET_USER::PARSER_GET_USER(const ADMIN * ca, const USERS * u)
- : PARSER(),
- result("<error message=\"Not implemented yet\"/>"),
- currAdmin(ca),
- users(u)
-{
-}
-
-PARSER_GET_USER::~PARSER_GET_USER()
-{
-}
-
-bool PARSER_GET_USER::StartTag(const char * name, const char ** attr)
-{
- std::string tag(name);
- if (tag != "GetUser") {
- return false;
- }
-
- if (attr[0] == NULL || attr[1] == NULL) {
- return false;
- }
-
- login = attr[1];
-
- return true;
-}
-
-bool PARSER_GET_USER::EndTag(const char * name)
-{
- std::string tag(name);
- if (tag != "GetUser") {
- return false;
- }
-
- if (login == "") {
- result = "<error message=\"Login unspecified\"/>";
- return false;
- }
-
- user_iter ui;
-
- if (users->FindByName(login, &ui)) {
- result ="<error message=\"User not found\"/>";
- return false;
- }
-
- std::stringstream answer;
- answer << "<User>\n";
- answer << "\t<login value=\"" << ui->GetLogin() << "\"/>\n";
- if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd) {
- answer << "\t<password value=\"" << ui->property.password.Get() << "\"/>\n";
- } else {
- answer << "\t<password value=\"++++++++\"/>\n";
- }
- answer << "\t<cash value=\"" << ui->property.cash.Get() << "\"/>\n";
- answer << "\t<freemb value=\"" << ui->property.freeMb.Get() << "\"/>\n";
- answer << "\t<credit value=\"" << ui->property.credit.Get() << "\"/>\n";
- if (ui->property.nextTariff.Get() != "") {
- answer << "\t<tariff value=\"" << ui->property.tariffName.Get()
- << "/" << ui->property.nextTariff.Get() << "\"/>\n";
- } else {
- answer << "\t<tariff value=\"" << ui->property.tariffName.Get() << "\"/>\n";
- }
-
- std::string encoded;
- Encode12str(encoded, ui->property.note.Get());
- answer << "\t<note value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.phone.Get());
- answer << "\t<phone value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.address.Get());
- answer << "\t<address value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.email.Get());
- answer << "\t<email value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.realName.Get());
- answer << "\t<name value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.group.Get());
- answer << "\t<group value=\"" << encoded << "\"/>\n";
-
- // TODO: Fix this shit!
- // <SHIT_BEGIN>
- Encode12str(encoded, ui->property.userdata0.Get()); answer << "\t<userdata0 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata1.Get()); answer << "\t<userdata1 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata2.Get()); answer << "\t<userdata2 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata3.Get()); answer << "\t<userdata3 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata4.Get()); answer << "\t<userdata4 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata5.Get()); answer << "\t<userdata5 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata6.Get()); answer << "\t<userdata6 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata7.Get()); answer << "\t<userdata7 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata8.Get()); answer << "\t<userdata8 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata9.Get()); answer << "\t<userdata9 value=\"" << encoded << "\"/>\n";
- // <SHIT_END>
-
- answer << "\t<status value=\"" << ui->GetConnected() << "\"/>\n";
- answer << "\t<aonline value=\"" << ui->property.alwaysOnline.Get() << "\"/>\n";
- answer << "\t<currip value=\"" << inet_ntostring(ui->GetCurrIP()) << "\"/>\n";
- answer << "\t<pingtime value=\"" << ui->GetPingTime() << "\"/>\n";
- answer << "\t<ip value=\"" << ui->property.ips.Get() << "\"/>\n";
- answer << "\t<lastcash value=\"" << ui->property.lastCashAdd.Get() << "\"/>\n";
- answer << "\t<lasttimecash value=\"" << ui->property.lastCashAddTime.Get() << "\"/>\n";
- answer << "\t<lastactivitytime value=\"" << ui->property.lastActivityTime.Get() << "\"/>\n";
- answer << "\t<creditexpire value=\"" << ui->property.creditExpire.Get() << "\"/>\n";
- answer << "\t<down value=\"" << ui->property.down.Get() << "\"/>\n";
- answer << "\t<passive value=\"" << ui->property.passive.Get() << "\"/>\n";
- answer << "\t<disabledetailstat value=\"" << ui->property.disabledDetailStat.Get() << "\"/>\n";
-
- // TODO: Fix this shit!
- // <SHIT_BEGIN>
- answer << "\t<traff ";
- DIR_TRAFF up(ui->property.up.Get());
- DIR_TRAFF down(ui->property.down.Get());
- for (int i = 0; i < DIR_NUM; ++i) {
- answer << "MU" << i << "=\"" << up[i] << "\" ";
- answer << "MD" << i << "=\"" << down[i] << "\" ";
- }
- answer << "/>\n";
- // <SHIT_END>
-
- answer << "</User>";
-
- result = answer.str();
-
- return true;
-}
+++ /dev/null
-#ifndef __PARSER_GET_USER_H__
-#define __PSRSER_GET_USER_H__
-
-#include <string>
-
-#include "parser.h"
-
-class ADMIN;
-class USERS;
-
-class PARSER_GET_USER : public PARSER {
- public:
- PARSER_GET_USER(const ADMIN * ca, const USERS * u);
- ~PARSER_GET_USER();
-
- bool StartTag(const char * name, const char ** attr);
- bool EndTag(const char * name);
- const std::string & GetResult() const { return result; };
-
- private:
- std::string result;
- std::string login;
- const ADMIN * currAdmin;
- const USERS * users;
-};
-
-#endif
+++ /dev/null
-// TODO: Fix this shit!
-#include "../../../admin.h"
-#include "../../../users.h"
-
-#include "parser_getusers.h"
-
-PARSER_GET_USERS::PARSER_GET_USERS(const ADMIN * ca, USERS * u)
- : PARSER(),
- result("<error message=\"Not implemented yet\"/>"),
- currAdmin(ca),
- users(u)
-{
-}
-
-PARSER_GET_USERS::~PARSER_GET_USERS()
-{
-}
-
-bool PARSER_GET_USERS::StartTag(const char * name, const char ** attr)
-{
- std::string tag(name);
- if (tag != "GetUsers") {
- return false;
- }
-
- return true;
-}
-
-bool PARSER_GET_USERS::EndTag(const char * name)
-{
- std::string tag(name);
- if (tag != "GetUsers") {
- return false;
- }
-
- int handle = users->OpenSearch();
- if (!handle) {
- printfd(__FILE__, "PARSER_GET_USERS::EndTag() OpenSearch error\n");
- users->CloseSearch(handle);
- result = "<error message=\"Internal error (OpenSearch failed)\"/>";
- return false;
- }
-
- std::stringstream answer;
-
- answer << "<Users>\n";
-
- while (1) {
- user_iter ui;
-
- if (users->SearchNext(handle, &ui)) {
- break;
- }
-
- answer << "\t<User>\n";
- answer << "\t\t<login value=\"" << ui->GetLogin() << "\"/>\n";
- if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd) {
- answer << "\t\t<password value=\"" << ui->property.password.Get() << "\"/>\n";
- } else {
- answer << "\t\t<password value=\"++++++++\"/>\n";
- }
- answer << "\t\t<cash value=\"" << ui->property.cash.Get() << "\"/>\n";
- answer << "\t\t<freemb value=\"" << ui->property.freeMb.Get() << "\"/>\n";
- answer << "\t\t<credit value=\"" << ui->property.credit.Get() << "\"/>\n";
- if (ui->property.nextTariff.Get() != "") {
- answer << "\t\t<tariff value=\"" << ui->property.tariffName.Get()
- << "/" << ui->property.nextTariff.Get() << "\"/>\n";
- } else {
- answer << "\t\t<tariff value=\"" << ui->property.tariffName.Get() << "\"/>\n";
- }
-
- std::string encoded;
- Encode12str(encoded, ui->property.note.Get());
- answer << "\t\t<note value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.phone.Get());
- answer << "\t\t<phone value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.address.Get());
- answer << "\t\t<address value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.email.Get());
- answer << "\t\t<email value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.realName.Get());
- answer << "\t\t<name value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.group.Get());
- answer << "\t\t<group value=\"" << encoded << "\"/>\n";
-
- // TODO: Fix this shit!
- // <SHIT_BEGIN>
- Encode12str(encoded, ui->property.userdata0.Get()); answer << "\t\t<userdata0 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata1.Get()); answer << "\t\t<userdata1 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata2.Get()); answer << "\t\t<userdata2 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata3.Get()); answer << "\t\t<userdata3 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata4.Get()); answer << "\t\t<userdata4 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata5.Get()); answer << "\t\t<userdata5 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata6.Get()); answer << "\t\t<userdata6 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata7.Get()); answer << "\t\t<userdata7 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata8.Get()); answer << "\t\t<userdata8 value=\"" << encoded << "\"/>\n";
- Encode12str(encoded, ui->property.userdata9.Get()); answer << "\t\t<userdata9 value=\"" << encoded << "\"/>\n";
- // <SHIT_END>
-
- answer << "\t\t<status value=\"" << ui->GetConnected() << "\"/>\n";
- answer << "\t\t<aonline value=\"" << ui->property.alwaysOnline.Get() << "\"/>\n";
- answer << "\t\t<currip value=\"" << inet_ntostring(ui->GetCurrIP()) << "\"/>\n";
- answer << "\t\t<pingtime value=\"" << ui->GetPingTime() << "\"/>\n";
- answer << "\t\t<ip value=\"" << ui->property.ips.Get() << "\"/>\n";
- answer << "\t\t<lastcash value=\"" << ui->property.lastCashAdd.Get() << "\"/>\n";
- answer << "\t\t<lasttimecash value=\"" << ui->property.lastCashAddTime.Get() << "\"/>\n";
- answer << "\t\t<lastactivitytime value=\"" << ui->property.lastActivityTime.Get() << "\"/>\n";
- answer << "\t\t<creditexpire value=\"" << ui->property.creditExpire.Get() << "\"/>\n";
- answer << "\t\t<down value=\"" << ui->property.disabled.Get() << "\"/>\n";
- answer << "\t\t<passive value=\"" << ui->property.passive.Get() << "\"/>\n";
- answer << "\t\t<disabledetailstat value=\"" << ui->property.disabledDetailStat.Get() << "\"/>\n";
-
- // TODO: Fix this shit!
- // <SHIT_BEGIN>
- answer << "\t\t<traff ";
- DIR_TRAFF up(ui->property.up.Get());
- DIR_TRAFF down(ui->property.down.Get());
- for (int i = 0; i < DIR_NUM; ++i) {
- answer << "MU" << i << "=\"" << up[i] << "\" ";
- answer << "MD" << i << "=\"" << down[i] << "\" ";
- }
- answer << "/>\n";
- // <SHIT_END>
-
- answer << "\t</User>\n";
- }
-
- answer << "</Users>";
-
- users->CloseSearch(handle);
-
- result = answer.str();
-
- return true;
-}
+++ /dev/null
-#ifndef __PARSER_GET_USERS_H__
-#define __PSRSER_GET_USERS_H__
-
-#include <string>
-
-#include "parser.h"
-
-class ADMIN;
-class USERS;
-
-class PARSER_GET_USERS : public PARSER {
- public:
- PARSER_GET_USERS(const ADMIN * ca, USERS * u);
- ~PARSER_GET_USERS();
-
- bool StartTag(const char * name, const char ** attr);
- bool EndTag(const char * name);
- const std::string & GetResult() const { return result; };
-
- private:
- std::string result;
- const ADMIN * currAdmin;
- USERS * users;
-};
-
-#endif
+++ /dev/null
-#include <sys/utsname.h>
-
-#include <sstream>
-
-#include "version.h"
-// TODO: Fix this shit!
-#include "../../../settings.h"
-#include "parser_info.h"
-
-PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO(const SETTINGS * s, int tn, int un)
- : PARSER(),
- result("<error message=\"Not implemented\"/>"),
- settings(s),
- tariffsNum(tn),
- usersNum(un)
-{
-}
-
-PARSER_GET_SERVER_INFO::~PARSER_GET_SERVER_INFO()
-{
-}
-
-bool PARSER_GET_SERVER_INFO::StartTag(const char * name, const char ** attr)
-{
- std::string tag(name);
- if (tag != "GetServerInfo") {
- return false;
- }
-
- return true;
-}
-
-bool PARSER_GET_SERVER_INFO::EndTag(const char * name)
-{
- std::string tag(name);
- if (tag != "GetServerInfo") {
- return false;
- }
-
- std::stringstream answer;
- answer << "<ServerInfo>\n";
- answer << "\t<version value=\"" << SERVER_VERSION << "\"/>\n";
- answer << "\t<tariff_num value=\"" << tariffsNum << "\"/>\n";
- answer << "\t<tariff value=\"2\"/>\n";
- answer << "\t<users_num value=\"" << usersNum << "\"/>\n";
- struct utsname utsn;
- uname(&utsn);
- answer << "\t<uname value=\"" << utsn.sysname << " " << utsn.release << " " << utsn.machine << " " << utsn.nodename << "\"/>\n";
- answer << "\t<dir_num value=\"" << DIR_NUM << "\"/>\n";
- answer << "\t<day_fee value=\"" << settings->GetDayFee() << "\"/>\n";
- for (int i = 0; i < DIR_NUM; ++i) {
- std::string encoded;
- Encode12str(encoded, settings->GetDirName(i));
- answer << "\t<dir_name_" << i << " value=\"" << encoded << "\"/>\n";
- }
- answer << "</ServerInfo>";
-
- result = answer.str();
-
- return true;
-}
+++ /dev/null
-#ifndef __PARSER_INFO_H__
-#define __PARSER_INFO_H__
-
-#include "parser.h"
-
-class SETTINGS;
-
-class PARSER_GET_SERVER_INFO : public PARSER {
- public:
- PARSER_GET_SERVER_INFO(const SETTINGS * s, int tn, int un);
- ~PARSER_GET_SERVER_INFO();
-
- bool StartTag(const char * name, const char ** attr);
- bool EndTag(const char * name);
- const std::string & GetResult() const { return result; };
-
- private:
- std::string result;
- const SETTINGS * settings;
- int tariffsNum;
- int usersNum;
-};
-
-#endif
+++ /dev/null
-#ifndef __PROTO_H__
-#define __PROTO_H__
-
-#define PROTO_MAGIC "12345678"
-
-namespace REQ {
- struct HEADER {
- char magic[8];
- uint32_t version;
- char login[36];
- };
-
- struct CRYPTO_HEADER {
- char login[36];
- uint32_t dataSize;
- };
-}
-
-namespace RESP {
- enum {
- OK = 0,
- INVALID_MAGIC,
- UNSUPPORTED_VERSION,
- INVALID_CREDENTIALS
- };
-
- struct HEADER {
- char magic[8];
- uint32_t version;
- uint32_t code;
- };
-
- struct CRYPTO_HEADER {
- char login[36];
- uint32_t dataSize;
- };
-}
-
-#endif
+++ /dev/null
-#include <cassert>
-
-#include "common.h"
-
-// TODO: Fix this shit!
-#include "../../../tariffs.h"
-#include "../../../users.h"
-#include "../../../admin.h"
-#include "../../../settings.h"
-
-#include "parser_info.h"
-#include "parser_getuser.h"
-#include "parser_getusers.h"
-#include "root_parser.h"
-
-ROOT_PARSER::ROOT_PARSER(const ADMIN * ca, TARIFFS * t, USERS * u, const SETTINGS * s)
- : PARSER(),
- tariffs(t),
- users(u),
- currAdmin(ca),
- settings(s),
- handler(NULL),
- depth(0),
- handlerResult("<error message=\"Not implemented yet\"/>")
-{
- // new, new, new...
- handlers["GetServerInfo"] = new PARSER_GET_SERVER_INFO(settings,
- tariffs->GetTariffsNum(),
- users->GetUserNum());
- handlers["GetUser"] = new PARSER_GET_USER(currAdmin, users);
- handlers["GetUsers"] = new PARSER_GET_USERS(currAdmin, users);
-}
-
-ROOT_PARSER::~ROOT_PARSER()
-{
- std::map<std::string, PARSER *>::iterator it;
-
- for (it = handlers.begin(); it != handlers.end(); ++it) {
- delete it->second;
- }
-}
-
-bool ROOT_PARSER::StartTag(const char * name, const char ** attr)
-{
- if (depth == 0) {
- handlerResult = "<error message=\"Not implemented yet\"/>";
- Dispatch(name);
- }
-
- ++depth;
-
- //assert(handler != NULL);
-
- if (handler != NULL)
- return handler->StartTag(name, attr);
- else
- return false;
-}
-
-bool ROOT_PARSER::EndTag(const char * name)
-{
- assert(depth > 0);
-
- bool res;
- if (handler != NULL)
- res = handler->EndTag(name);
- else
- res = false;
-
- --depth;
-
- if (depth == 0) {
- if (handler != NULL) {
- handlerResult = handler->GetResult();
- }
- handler = NULL;
- }
-
- return res;
-}
-
-bool ROOT_PARSER::Dispatch(const std::string & name)
-{
- HMAP_ITERATOR it(handlers.find(name));
-
- if (it == handlers.end()) {
- printfd(__FILE__, "ROOT_PARSER::Dispatch() Handler for '%s' not found.\n", name.c_str());
- return false;
- }
-
- handler = it->second;
-
- return true;
-}
+++ /dev/null
-#ifndef __ROOT_PARSER_H__
-#define __ROOT_PARSER_H__
-
-#include <map>
-#include <string>
-
-#include "parser.h"
-
-class TARIFFS;
-class USERS;
-class ADMIN;
-class SETTINGS;
-
-class ROOT_PARSER : public PARSER {
- public:
- ROOT_PARSER(const ADMIN * ca, TARIFFS * t, USERS * u, const SETTINGS * s);
- ~ROOT_PARSER();
-
- bool StartTag(const char * name, const char ** attr);
- bool EndTag(const char * name);
- const std::string & GetResult() const { return handlerResult; };
-
- private:
- TARIFFS * tariffs;
- USERS * users;
- const ADMIN * currAdmin;
- const SETTINGS * settings;
-
- typedef std::map<std::string, PARSER *> HMAP;
- typedef HMAP::iterator HMAP_ITERATOR;
-
- HMAP handlers;
- PARSER * handler;
- int depth;
- std::string handlerResult;
-
- bool Dispatch(const std::string & name);
-};
-
-#endif
+++ /dev/null
-#include <boost/thread.hpp>
-
-#include "store.h"
-#include "module_settings.h"
-#include "common.h"
-#include "users.h"
-#include "tariffs.h"
-#include "admins.h"
-
-// TODO: Fix this shit!!!
-#include "../../../settings.h"
-
-#include "stgconfig.h"
-
-STGCONFIG2::STGCONFIG2()
- : users(NULL),
- tariffs(NULL),
- admins(NULL),
- store(NULL),
- stgSettings(NULL),
- ct(admins, tariffs, users, stgSettings)
-{
- thread = new boost::thread;
-}
-
-STGCONFIG2::~STGCONFIG2()
-{
- delete thread;
-}
-
-int STGCONFIG2::ParseSettings()
-{
- return 0;
-}
-
-int STGCONFIG2::Start()
-{
- ct.SetClasses(admins, tariffs, users, stgSettings);
- *thread = boost::thread(boost::ref(ct));
- return 0;
-}
-
-int STGCONFIG2::Stop()
-{
- ct.Stop();
- if (!thread->timed_join(boost::get_system_time() + boost::posix_time::milliseconds(5000))) {
- thread->detach();
- printfd(__FILE__, "STGCONFIG2::Stop() Thread not stopped.\n");
- errorStr = "Failed to stop config thread.";
- return -1;
- }
- return 0;
-}
-
-bool STGCONFIG2::IsRunning()
-{
- return true;
-}
+++ /dev/null
-#ifndef __STGCONFIG_H__
-#define __STGCONFIG_H__
-
-#include <string>
-
-#include "plugin.h"
-#include "os_int.h"
-#include "main_thread.h"
-
-#define PLUGIN_VERSION "stgconfig v.2.0"
-
-namespace boost {
- class thread;
-};
-
-class USERS;
-class TARIFFS;
-class ADMINS;
-class STORE;
-class TRAFFCOUNTER;
-class SETTINGS;
-
-class STGCONFIG2 : public PLUGIN {
-public:
- STGCONFIG2();
- virtual ~STGCONFIG2();
-
- void SetUsers(USERS * u) { users = u; }
- void SetTariffs(TARIFFS * t) { tariffs = t; }
- void SetAdmins(ADMINS * a) { admins = a; }
- void SetStore(STORE * s) { store = s; }
- void SetStgSettings(const SETTINGS * s) { stgSettings = s; }
- void SetSettings(const MODULE_SETTINGS & s) { modSettings = s; }
- int ParseSettings();
-
- int Start();
- int Stop();
- int Reload() { return 0; }
- bool IsRunning();
-
- const std::string & GetStrError() const { return errorStr; }
- const std::string GetVersion() const { return PLUGIN_VERSION; }
- uint16_t GetStartPosition() const { return 20; }
- uint16_t GetStopPosition() const { return 20; }
-
-private:
- USERS * users;
- TARIFFS * tariffs;
- ADMINS * admins;
- STORE * store;
- const SETTINGS * stgSettings;
- MODULE_SETTINGS modSettings;
-
- MAIN_THREAD ct;
-
- mutable std::string errorStr;
-
- boost::thread * thread;
-
-};
-
-extern "C" PLUGIN * GetPlugin();
-
-#endif
+++ /dev/null
-###############################################################################
-# $Id: Makefile,v 1.9 2008/12/04 17:09:40 faust Exp $
-###############################################################################
-
-include ../../../../../Makefile.conf
-
-PROG = mod_conf_sg2.so
-
-SRCS = ./stgconfig.cpp \
- ./rsconf.cpp \
- ./configproto.cpp \
- ./parser.cpp \
- ./parser_tariff.cpp \
- ./parser_admin.cpp
-
-LIBS += -lexpat \
- $(LIB_THREAD)
-
-STGLIBS = common \
- logger
-
-include ../../Makefile.in
-
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Date: 27.10.2002
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.20 $
- $Date: 2009/10/20 11:53:40 $
- $Author: faust $
- */
-
-
-//#include <string.h>
-//#include <stdio.h>
-#include <unistd.h>
-
-#include "configproto.h"
-
-//-----------------------------------------------------------------------------
-void ParseXMLStart(void *data, const char *el, const char **attr)
-{
-CONFIGPROTO * cp = (CONFIGPROTO*)(data);
-
-if (cp->currParser)
- {
- cp->currParser->SetAnswerList(&cp->answerList);
- cp->currParser->SetCurrAdmin(cp->currAdmin);
- cp->currParser->ParseStart(data, el, attr);
- }
-else
- {
- for (unsigned int i = 0; i < cp->dataParser.size(); i++)
- {
- cp->dataParser[i]->SetAnswerList(&cp->answerList);
- cp->currAdmin->SetAdminIP(cp->GetAdminIP());
- cp->dataParser[i]->SetCurrAdmin(cp->currAdmin);
- cp->dataParser[i]->Reset();
- if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
- {
- cp->currParser = cp->dataParser[i];
- break;
- }
- else
- {
- cp->dataParser[i]->Reset();
- }
- }
- }
-}
-//-----------------------------------------------------------------------------
-void ParseXMLEnd(void *data, const char *el)
-{
-CONFIGPROTO * cp = (CONFIGPROTO*)(data);
-if (cp->currParser)
- {
- if (cp->currParser->ParseEnd(data, el) == 0)
- {
- cp->currParser = NULL;
- }
- }
-else
- {
- for (unsigned int i = 0; i < cp->dataParser.size(); i++)
- {
- if (cp->dataParser[i]->ParseEnd(data, el) == 0)
- {
- break;
- }
- }
- }
-}
-//-----------------------------------------------------------------------------
-CONFIGPROTO::CONFIGPROTO()
- : adminIP(0),
- port(0),
- nonstop(1),
- state(0),
- currAdmin(NULL),
- WriteServLog(GetStgLogger()),
- outerSocket(0),
- listenSocket(0),
- admins(NULL),
- users(NULL),
- tariffs(NULL),
- store(NULL),
- settings(NULL),
- currParser(NULL)
-{
-dataParser.push_back(&parserGetServInfo);
-
-dataParser.push_back(&parserGetUsers);
-dataParser.push_back(&parserGetUser);
-dataParser.push_back(&parserChgUser);
-dataParser.push_back(&parserAddUser);
-dataParser.push_back(&parserDelUser);
-dataParser.push_back(&parserCheckUser);
-dataParser.push_back(&parserSendMessage);
-
-dataParser.push_back(&parserGetTariffs);
-dataParser.push_back(&parserAddTariff);
-dataParser.push_back(&parserDelTariff);
-dataParser.push_back(&parserChgTariff);
-
-dataParser.push_back(&parserGetAdmins);
-dataParser.push_back(&parserChgAdmin);
-dataParser.push_back(&parserDelAdmin);
-dataParser.push_back(&parserAddAdmin);
-
-xmlParser = XML_ParserCreate(NULL);
-
-if (!xmlParser)
- {
- WriteServLog("Couldn't allocate memory for parser.");
- exit(1);
- }
-
-//XML_SetElementHandler(parser, ParseXMLStart, ParseXMLEnd);
-}
-//-----------------------------------------------------------------------------
-CONFIGPROTO::~CONFIGPROTO()
-{
-XML_ParserFree(xmlParser);
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::ParseCommand()
-{
-list<string>::iterator n;
-int done = 0;
-char str[9];
-int len;
-
-if (requestList.empty())
- return 0;
-
-n = requestList.begin();
-
-strncpy(str, (*n).c_str(), 8);
-str[8] = 0;
-
-XML_ParserReset(xmlParser, NULL);
-XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
-XML_SetUserData(xmlParser, this);
-
-while(nonstop)
- {
- strncpy(str, (*n).c_str(), 8);
- str[8] = 0;
- len = strlen(str);
-
- n++;
- if (n == requestList.end())
- done = 1;
- n--;
-
- if (XML_Parse(xmlParser, (*n).c_str(), len, done) == XML_STATUS_ERROR)
- {
- WriteServLog("Invalid configuration request");
- printfd(__FILE__, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(xmlParser),
- XML_ErrorString(XML_GetErrorCode(xmlParser)));
- if (currParser)
- {
- printfd(__FILE__, "Parser reset\n");
- currParser->Reset();
- currParser = NULL;
- }
-
- return -1;
- }
-
- if (done)
- return 0;
-
- n++;
- }
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetPort(uint16_t p)
-{
-port = p;
-}
-//-----------------------------------------------------------------------------
-/*void CONFIGPROTO::SetHostAllow(HOSTALLOW *)
-{
-//hostAllow = ha;
-}*/
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetAdmins(ADMINS * a)
-{
-admins = a;
-for (unsigned int i = 0; i < dataParser.size(); i++)
- {
- dataParser[i]->SetAdmins(admins);
- }
-
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetUsers(USERS * u)
-{
-users = u;
-for (unsigned int i = 0; i < dataParser.size(); i++)
- {
- dataParser[i]->SetUsers(users);
- }
-
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetTariffs(TARIFFS * t)
-{
-tariffs = t;
-for (unsigned int i = 0; i < dataParser.size(); i++)
- {
- dataParser[i]->SetTariffs(tariffs);
- }
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetStore(STORE * s)
-{
-store = s;
-for (unsigned int i = 0; i < dataParser.size(); i++)
- {
- dataParser[i]->SetStore(s);
- }
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
-{
-settings = s;
-for (unsigned int i = 0; i < dataParser.size(); i++)
- {
- dataParser[i]->SetStgSettings(settings);
- }
-}
-//-----------------------------------------------------------------------------
-/*void CONFIGPROTO::Start()
-{
-finished = false;
-threadExited = false;
-status = starting;
-
-xmlParser = XML_ParserCreate(NULL);
-
-if (!xmlParser)
- {
- WriteServLog("Couldn't allocate memory for parser.");
- }
-
-pthread_create(&thrReciveSendConf, NULL, ReciveSendConf, this);
-status = started;
-}*/
-//-----------------------------------------------------------------------------
-/*int CONFIGPROTO::Stop()
-{
-nonstop = true;
-close(outerSocket);
-return 0;
-}*/
-//-----------------------------------------------------------------------------
-/*void CONFIGPROTO::Restart()
-{
-//Stop();
-//Start();
-}*/
-//-----------------------------------------------------------------------------
-/*CONF_STATUS CONFIGPROTO::Status()
-{
-//return status;
-}
-//-----------------------------------------------------------------------------
-*/
-const string & CONFIGPROTO::GetStrError()
-{
-return errorStr;
-}
-//-----------------------------------------------------------------------------
-uint32_t CONFIGPROTO::GetAdminIP()
-{
-return adminIP;
-}
-//-----------------------------------------------------------------------------
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.12 $
- $Date: 2009/10/15 14:46:17 $
- $Author: faust $
- */
-
-
-#ifndef CONFIGPROTO_H
-#define CONFIGPROTO_H
-
-#include <expat.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <string>
-
-#include "parser.h"
-#include "users.h"
-#include "admins.h"
-#include "tariffs.h"
-#include "logger.h"
-
-using namespace std;
-
-#define STG_HEADER "SG04"
-#define OK_HEADER "OKHD"
-#define ERR_HEADER "ERHD"
-#define OK_LOGIN "OKLG"
-#define ERR_LOGIN "ERLG"
-#define OK_LOGINS "OKLS"
-#define ERR_LOGINS "ERLS"
-
-//-----------------------------------------------------------------------------
-class CONFIGPROTO
-{
-public:
- CONFIGPROTO();
- ~CONFIGPROTO();
-
- void SetPort(uint16_t port);
- //void SetHostAllow(HOSTALLOW * ha);
- void SetAdmins(ADMINS * a);
- void SetUsers(USERS * u);
- void SetTariffs(TARIFFS * t);
- void SetStore(STORE * s);
- void SetStgSettings(const SETTINGS * s);
- const string & GetAdminLogin();
- uint32_t GetAdminIP();
- int Prepare();
- int Stop();
- const string & GetStrError();
- static void * Run(void * a);
-
-private:
- int RecvHdr(int sock);
- int RecvLogin(int sock);
- int SendLoginAnswer(int sock, int err);
- int SendHdrAnswer(int sock, int err);
- int RecvLoginS(int sock);
- int SendLoginSAnswer(int sock, int err);
- int RecvData(int sock);
- int SendDataAnswer(int sock);
- void SendError(const char * text);
- void WriteLogAccessFailed(uint32_t ip);
-
- int ParseCommand();
-
- list<string> answerList;
- list<string> requestList;
- uint32_t adminIP;
- string adminLogin;
- uint16_t port;
- pthread_t thrReciveSendConf;
- bool nonstop;
- int state;
- //HOSTALLOW * hostAllow;
- const ADMIN * currAdmin;
- STG_LOGGER & WriteServLog;
-
- int outerSocket;
- int listenSocket;
- struct sockaddr_in outerAddr;
- socklen_t outerAddrLen;
-
- PARSER_GET_SERVER_INFO parserGetServInfo;
-
- PARSER_GET_USERS parserGetUsers;
- PARSER_GET_USER parserGetUser;
- PARSER_CHG_USER parserChgUser;
- PARSER_ADD_USER parserAddUser;
- PARSER_DEL_USER parserDelUser;
- PARSER_CHECK_USER parserCheckUser;
- PARSER_SEND_MESSAGE parserSendMessage;
-
- PARSER_GET_ADMINS parserGetAdmins;
- PARSER_ADD_ADMIN parserAddAdmin;
- PARSER_DEL_ADMIN parserDelAdmin;
- PARSER_CHG_ADMIN parserChgAdmin;
-
- PARSER_GET_TARIFFS parserGetTariffs;
- PARSER_ADD_TARIFF parserAddTariff;
- PARSER_DEL_TARIFF parserDelTariff;
- PARSER_CHG_TARIFF parserChgTariff;
-
- ADMINS * admins;
- USERS * users;
- TARIFFS * tariffs;
- STORE * store;
- const SETTINGS * settings;
-
- BASE_PARSER * currParser;
- vector<BASE_PARSER*> dataParser;
-
- XML_Parser xmlParser;
-
- string errorStr;
-
- friend void ParseXMLStart(void *data, const char *el, const char **attr);
- friend void ParseXMLEnd(void *data, const char *el);
-};
-//-----------------------------------------------------------------------------
-#endif //CONFIGPROTO_H
+++ /dev/null
-#include <unistd.h>
-#include "net_configurator.h"
-#include "../../internal_configurator.h"
-
-//-----------------------------------------------------------------------------
-const string & NET_CONFIGURATOR_SETTINGS::GetStrError()
-{
-return strError;
-}
-//-----------------------------------------------------------------------------
-int NET_CONFIGURATOR_SETTINGS::ReadSettings(const CONFIGFILE &cf)
-{
-if (cf.ReadUShortInt("AdminPort", &port, 5555) != 0)
- {
- strError = "Cannot read parameter AdminPort.";
- return -1;
- }
-if (port < 1 || port > 65535)
- {
- strError = "Incorrect value AdminPort.";
- return -1;
- }
-
-string strOrder;
-cf.ReadString("AdminOrder", &strOrder, "allow,deny");
-if (hostAllow.ParseOrder(strOrder.c_str()) < 0)
- {
- strError = string("Error in parameter AdminOrder. ") + hostAllow.GetStrError();
- return -1;
- }
-
-string strAllow;
-cf.ReadString("AdminAllowFrom", &strAllow, "all");
-if (hostAllow.ParseHosts(strAllow.c_str(), hostsAllow) != 0)
- {
- strError = string("Error in parameter AdminAllowFrom. ") + hostAllow.GetStrError();
- return -1;
- }
-
-string strDeny;
-cf.ReadString("AdminDenyFrom", &strDeny, "");
-if (hostAllow.ParseHosts(strDeny.c_str(), hostsDeny) != 0)
- {
- strError = string("Error in parameter AdminDenyFrom. ") + hostAllow.GetStrError();
- return -1;
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-uint16_t NET_CONFIGURATOR_SETTINGS::GetPort()
-{
-return port;
-}
-//-----------------------------------------------------------------------------
-HOSTALLOW * NET_CONFIGURATOR_SETTINGS::GetHostAllow()
-{
-return &hostAllow;
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-NET_CONFIGURATOR::NET_CONFIGURATOR()
-{
-hostAllow = settings.GetHostAllow();
-}
-//-----------------------------------------------------------------------------
-NET_CONFIGURATOR::~NET_CONFIGURATOR()
-{
-
-}
-//-----------------------------------------------------------------------------
-void NET_CONFIGURATOR::SetStgConfigurator(BASE_INT_CONFIGURATOR * bsc)
-{
-stgConfigurator = bsc;
-cp.SetStgConfigurator(stgConfigurator);
-}
-//-----------------------------------------------------------------------------
-int NET_CONFIGURATOR::UserGetAll(string * login,
- USER_CONF_RES * conf,
- USER_STAT_RES * stat,
- time_t lastUpdate)
-{
-return 0;
-}
-//-----------------------------------------------------------------------------
-int NET_CONFIGURATOR::TatiffGetAll(TARIFF_CONF * conf)
-{
-return 0;
-}
-//-----------------------------------------------------------------------------
-int NET_CONFIGURATOR::AdminGetAll(ADMIN_CONF * conf)
-{
-return 0;
-}
-//-----------------------------------------------------------------------------
-const string & NET_CONFIGURATOR::GetStrError()
-{
-return strError;
-}
-//-----------------------------------------------------------------------------
-void NET_CONFIGURATOR::Start()
-{
-cp.SetPort(settings.GetPort());
-cp.SetHostAllow(settings.GetHostAllow());
-cp.Start();
-}
-//-----------------------------------------------------------------------------
-void NET_CONFIGURATOR::Stop()
-{
-cp.Stop();
-}
-//-----------------------------------------------------------------------------
-void NET_CONFIGURATOR::Restart()
-{
-cp.Restart();
-}
-//-----------------------------------------------------------------------------
-CONF_STATUS NET_CONFIGURATOR::Status()
-{
-return cp.Status();
-}
-//-----------------------------------------------------------------------------
-BASE_SETTINGS * NET_CONFIGURATOR::GetConfiguratorSettings()
-{
-return &settings;
-}
-//-----------------------------------------------------------------------------
-void NET_CONFIGURATOR::SetAdmins(const ADMINS * a)
-{
-cp.SetAdmins(a);
-}
-//-----------------------------------------------------------------------------
-
+++ /dev/null
- /*
- $Revision: 1.2 $
- $Date: 2005/10/30 21:34:28 $
- */
-
-#ifndef NET_CONFIGURATOR_H
-#define NET_CONFIGURATOR_H
-
-#include <time.h>
-#include <string>
-
-#include "../../base_ext_configurator.h"
-#include "../../base_int_configurator.h"
-#include "../../base_settings.h"
-#include "hostallow.h"
-#include "conffiles.h"
-#include "configproto.h"
-
-using namespace std;
-//-----------------------------------------------------------------------------
-class NET_CONFIGURATOR_SETTINGS: public BASE_SETTINGS
-{
-public:
- virtual ~NET_CONFIGURATOR_SETTINGS(){};
-virtual const string & GetStrError();
- virtual int ReadSettings(const CONFIGFILE & cf);
- uint16_t GetPort();
- HOSTALLOW * GetHostAllow();
-
-private:
- string strError;
- uint16_t port;
- HOSTALLOW hostAllow;
-};
-//-----------------------------------------------------------------------------
-class NET_CONFIGURATOR: public BASE_EXT_CONFIGURATOR
-{
-public:
- NET_CONFIGURATOR();
- virtual ~NET_CONFIGURATOR();
- virtual void SetStgConfigurator(BASE_INT_CONFIGURATOR *);
- virtual int UserGetAll(string * login,
- USER_CONF_RES * conf,
- USER_STAT_RES * stat,
- time_t lastUpdate);
- virtual int TatiffGetAll(TARIFF_CONF * conf);
- virtual int AdminGetAll(ADMIN_CONF * conf);
- virtual const string & GetStrError();
- virtual void Start();
- virtual void Stop();
- virtual void Restart();
- virtual CONF_STATUS Status();
- virtual BASE_SETTINGS * GetConfiguratorSettings();
- virtual void SetAdmins(const ADMINS * a);
-
-private:
- HOSTALLOW * hostAllow;
- BASE_INT_CONFIGURATOR * stgConfigurator;
- NET_CONFIGURATOR_SETTINGS settings;
- string strError;
- CONFIGPROTO cp;
-};
-//-----------------------------------------------------------------------------
-#endif //NET_CONFIGURATOR_H
-
+++ /dev/null
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include <sys/utsname.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sstream>
-
-#include "parser.h"
-#include "version.h"
-
-#define UNAME_LEN (256)
-//-----------------------------------------------------------------------------
-// GET SERVER INFO
-//-----------------------------------------------------------------------------
-int PARSER_GET_SERVER_INFO::ParseStart(void *, const char *el, const char **)
-{
-answerList->erase(answerList->begin(), answerList->end());
-if (strcasecmp(el, "GetServerInfo") == 0)
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_SERVER_INFO::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetServerInfo") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::CreateAnswer()
-{
-char s[UNAME_LEN + 128];
-char un[UNAME_LEN];
-struct utsname utsn;
-
-int tariff_type;
-
-tariff_type = 2;
-
-uname(&utsn);
-un[0] = 0;
-
-strcat(un, utsn.sysname);
-strcat(un, " ");
-strcat(un, utsn.release);
-strcat(un, " ");
-strcat(un, utsn.machine);
-strcat(un, " ");
-strcat(un, utsn.nodename);
-
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-answerList->push_back("<ServerInfo>");
-
-sprintf(s, "<version value=\"%s\"/>", SERVER_VERSION);
-answerList->push_back(s);
-
-sprintf(s, "<tariff_num value=\"%d\"/>", tariffs->GetTariffsNum());
-answerList->push_back(s);
-
-sprintf(s, "<tariff value=\"%d\"/>", 2);
-answerList->push_back(s);
-
-sprintf(s, "<users_num value=\"%d\"/>", users->GetUserNum());
-answerList->push_back(s);
-
-sprintf(s, "<uname value=\"%s\"/>", un);
-answerList->push_back(s);
-
-sprintf(s, "<dir_num value=\"%d\"/>", DIR_NUM);
-answerList->push_back(s);
-
-sprintf(s, "<day_fee value=\"%d\"/>", settings->GetDayFee());
-answerList->push_back(s);
-
-for (int i = 0; i< DIR_NUM; i++)
- {
- string dn2e;
- Encode12str(dn2e, settings->GetDirName(i));
- sprintf(s, "<dir_name_%d value=\"%s\"/>", i, dn2e.c_str());
- answerList->push_back(s);
- }
-
-answerList->push_back("</ServerInfo>");
-}
-//-----------------------------------------------------------------------------
-// GET USER
-//-----------------------------------------------------------------------------
-PARSER_GET_USER::PARSER_GET_USER()
-{
-
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseStart(void *, const char *el, const char **attr)
-{
-if (strcasecmp(el, "GetUser") == 0)
- {
- if (attr[0] && attr[1])
- login = attr[1];
- else
- {
- //login.clear();
- login.erase(login.begin(), login.end());
- return -1;
- }
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetUser") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::CreateAnswer()
-{
-string s;
-string enc;
-
-user_iter u;
-
-answerList->erase(answerList->begin(), answerList->end());
-
-if (users->FindByName(login, &u))
- {
- s = "<user result=\"error\"/>";
- answerList->push_back(s);
- return;
- }
-
-s = "<user result=\"ok\">";
-answerList->push_back(s);
-
-s = "<login value=\"" + u->GetLogin() + "\"/>";
-answerList->push_back(s);
-
-if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
- s = "<password value=\"" + u->property.password.Get() + "\" />";
-else
- s = "<password value=\"++++++\"/>";
-answerList->push_back(s);
-
-strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
-answerList->push_back(s);
-
-if (u->property.nextTariff.Get() != "")
- {
- strprintf(&s, "<tariff value=\"%s/%s\" />",
- u->property.tariffName.Get().c_str(),
- u->property.nextTariff.Get().c_str());
- }
-else
- {
- strprintf(&s, "<tariff value=\"%s\" />",
- u->property.tariffName.Get().c_str());
- }
-
-answerList->push_back(s);
-
-Encode12str(enc, u->property.note);
-s = "<note value=\"" + enc + "\" />";
-answerList->push_back(s);
-
-Encode12str(enc, u->property.phone);
-s = "<phone value=\"" + enc + "\" />";
-answerList->push_back(s);
-
-Encode12str(enc, u->property.address);
-s = "<address value=\"" + enc + "\" />";
-answerList->push_back(s);
-
-Encode12str(enc, u->property.email);
-s = "<email value=\"" + enc + "\" />";
-answerList->push_back(s);
-
-
-vector<USER_PROPERTY_LOGGED<string> *> userdata;
-userdata.push_back(u->property.userdata0.GetPointer());
-userdata.push_back(u->property.userdata1.GetPointer());
-userdata.push_back(u->property.userdata2.GetPointer());
-userdata.push_back(u->property.userdata3.GetPointer());
-userdata.push_back(u->property.userdata4.GetPointer());
-userdata.push_back(u->property.userdata5.GetPointer());
-userdata.push_back(u->property.userdata6.GetPointer());
-userdata.push_back(u->property.userdata7.GetPointer());
-userdata.push_back(u->property.userdata8.GetPointer());
-userdata.push_back(u->property.userdata9.GetPointer());
-
-string tmpI;
-for (unsigned i = 0; i < userdata.size(); i++)
- {
- Encode12str(enc, userdata[i]->Get());
- s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
- answerList->push_back(s);
- }
-
-Encode12str(enc, u->property.realName);
-s = "<name value=\"" + enc + "\" />";
-answerList->push_back(s);
-
-Encode12str(enc, u->property.group);
-s = "<GROUP value=\"" + enc + "\" />";
-answerList->push_back(s);
-
-strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
-answerList->push_back(s);
-
-strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
-answerList->push_back(s);
-
-strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
-answerList->push_back(s);
-
-stringstream sstr;
-sstr << u->property.ips.Get();
-strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
-answerList->push_back(s);
-
-char * ss;
-ss = new char[DIR_NUM*25*4 + 50];
-char st[50];
-sprintf(ss, "<traff");
-DIR_TRAFF upload;
-DIR_TRAFF download;
-download = u->property.down.Get();
-upload = u->property.up.Get();
-
-for (int j = 0; j < DIR_NUM; j++)
- {
- string s;
- x2str(upload[j], s);
- sprintf(st, " MU%d=\"%s\"", j, s.c_str());
- strcat(ss, st);
-
- x2str(download[j], s);
- sprintf(st, " MD%d=\"%s\"", j, s.c_str());
- strcat(ss, st);
-
- sprintf(st, " SU%d=\"0\"", j);
- strcat(ss, st);
-
- sprintf(st, " SD%d=\"0\"", j);
- strcat(ss, st);
- }
-strcat(ss, " />");
-answerList->push_back(ss);
-delete[] ss;
-
-strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
-answerList->push_back(s);
-
-strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
-answerList->push_back(s);
-
-strprintf(&s, "</user>");
-answerList->push_back(s);
-}
-//-----------------------------------------------------------------------------
-// GET USERS
-//-----------------------------------------------------------------------------
-PARSER_GET_USERS::PARSER_GET_USERS()
-{
-lastUserUpdateTime = 0;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USERS::ParseStart(void *, const char *el, const char ** attr)
-{
-/*if (attr && *attr && *(attr+1))
- {
- printfd(__FILE__, "attr=%s %s\n", *attr, *(attr+1));
- }
-else
- {
- printfd(__FILE__, "attr = NULL\n");
- }*/
-
-lastUpdateFound = false;
-if (strcasecmp(el, "GetUsers") == 0)
- {
- while (attr && *attr && *(attr+1))
- {
- if (strcasecmp(*attr, "LastUpdate") == 0)
- {
- if (str2x(*(attr+1), lastUserUpdateTime) == 0)
- {
- //printfd(__FILE__, "lastUserUpdateTime=%d\n", lastUserUpdateTime);
- lastUpdateFound = true;
- }
- else
- {
- //printfd(__FILE__, "NO lastUserUpdateTime\n");
- }
- }
- ++attr;
- }
-
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USERS::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetUsers") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::CreateAnswer()
-{
-answerList->erase(answerList->begin(), answerList->end());
-
-string s;
-string userStart;
-string traffStart;
-string traffMiddle;
-string traffFinish;
-string middle;
-string userFinish;
-
-
-string enc;
-
-user_iter u;
-
-int h = users->OpenSearch();
-if (!h)
- {
- printfd(__FILE__, "users->OpenSearch() error\n");
- users->CloseSearch(h);
- return;
- }
-string updateTime;
-x2str(time(NULL), updateTime);
-
-if (lastUpdateFound)
- answerList->push_back("<Users LastUpdate=\"" + updateTime + "\">");
-else
- answerList->push_back("<Users>");
-
-while (1)
- {
- if (users->SearchNext(h, &u))
- {
- break;
- }
- userStart = "<user login=\"" + u->GetLogin() + "\">";
- middle = "";
-
- if (u->property.password.ModificationTime() > lastUserUpdateTime)
- {
- if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
- s = "<password value=\"" + u->property.password.Get() + "\" />";
- else
- s = "<password value=\"++++++\"/>";
- middle += s;
- }
-
-
- if (u->property.cash.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
- middle += s;
- //printfd(__FILE__, "cash value=\"%f\"\n", u->property.cash.Get());
- }
-
-
- if (u->property.freeMb.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
- middle += s;
- }
-
- if (u->property.credit.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
- middle += s;
- }
-
- if (u->property.nextTariff.Get() != "")
- {
- if (u->property.tariffName.ModificationTime() > lastUserUpdateTime
- || u->property.nextTariff.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<tariff value=\"%s/%s\" />",
- u->property.tariffName.Get().c_str(),
- u->property.nextTariff.Get().c_str());
- middle += s;
- }
- }
- else
- {
- if (u->property.tariffName.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<tariff value=\"%s\" />",
- u->property.tariffName.Get().c_str());
- middle += s;
- }
- }
-
- if (u->property.note.ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, u->property.note);
- strprintf(&s, "<note value=\"%s\" />", enc.c_str());
- middle += s;
- }
-
- if (u->property.phone.ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, u->property.phone);
- strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
- middle += s;
- }
-
- if (u->property.address.ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, u->property.address);
- strprintf(&s, "<address value=\"%s\" />", enc.c_str());
- middle += s;
- }
-
- if (u->property.email.ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, u->property.email);
- strprintf(&s, "<email value=\"%s\" />", enc.c_str());
- middle += s;
- }
-
- vector<USER_PROPERTY_LOGGED<string> *> userdata;
- userdata.push_back(u->property.userdata0.GetPointer());
- userdata.push_back(u->property.userdata1.GetPointer());
- userdata.push_back(u->property.userdata2.GetPointer());
- userdata.push_back(u->property.userdata3.GetPointer());
- userdata.push_back(u->property.userdata4.GetPointer());
- userdata.push_back(u->property.userdata5.GetPointer());
- userdata.push_back(u->property.userdata6.GetPointer());
- userdata.push_back(u->property.userdata7.GetPointer());
- userdata.push_back(u->property.userdata8.GetPointer());
- userdata.push_back(u->property.userdata9.GetPointer());
-
- string tmpI;
- for (unsigned i = 0; i < userdata.size(); i++)
- {
- if (userdata[i]->ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, userdata[i]->Get());
- s = "<UserData" + x2str(i, tmpI) + " value=\"" + enc + "\" />";
- middle += s;
- }
- }
-
- if (u->property.realName.ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, u->property.realName);
- strprintf(&s, "<name value=\"%s\" />", enc.c_str());
- middle += s;
- }
-
- if (u->property.group.ModificationTime() > lastUserUpdateTime)
- {
- Encode12str(enc, u->property.group);
- strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
- middle += s;
- }
-
- if (u->property.alwaysOnline.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
- middle += s;
- }
-
- if (u->GetCurrIPModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
- middle += s;
- }
-
-
- if (u->GetConnectedModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
- middle += s;
- }
-
- if (u->GetPingTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<PingTime value=\"%lu\" />", u->GetPingTime());
- middle += s;
- }
-
- if (u->property.ips.ModificationTime() > lastUserUpdateTime)
- {
- stringstream sstr;
- sstr << u->property.ips.Get();
- strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
- middle += s;
- }
-
- char st[50];
- traffStart = "<traff";
- DIR_TRAFF upload;
- DIR_TRAFF download;
- download = u->property.down.Get();
- upload = u->property.up.Get();
- traffMiddle = "";
-
- if (u->property.up.ModificationTime() > lastUserUpdateTime)
- {
- for (int j = 0; j < DIR_NUM; j++)
- {
- string s;
- x2str(upload[j], s);
- sprintf(st, " MU%d=\"%s\" ", j, s.c_str());
- traffMiddle += st;
- }
- }
-
- if (u->property.down.ModificationTime() > lastUserUpdateTime)
- {
- for (int j = 0; j < DIR_NUM; j++)
- {
- x2str(download[j], s);
- sprintf(st, " MD%d=\"%s\" ", j, s.c_str());
- traffMiddle += st;
- }
- }
-
- traffFinish = " />";
- if (traffMiddle.length() > 0)
- {
- middle += traffStart;
- middle += traffMiddle;
- middle += traffFinish;
- }
-
- if (u->property.disabled.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
- middle += s;
- }
-
- if (u->property.disabledDetailStat.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
- middle += s;
- }
-
- //printfd(__FILE__, ">>>>> %s\n", s.c_str());
-
- if (u->property.passive.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
- middle += s;
- }
-
- if (u->property.lastCashAdd.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
- middle += s;
- }
-
- if (u->property.lastCashAddTime.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
- middle += s;
- }
-
-
- if (u->property.lastActivityTime.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
- middle += s;
- }
-
- if (u->property.creditExpire.ModificationTime() > lastUserUpdateTime)
- {
- strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
- middle += s;
- }
-
-
- userFinish = "</user>";
-
- if (middle.length() > 0)
- {
- /*printfd(__FILE__, "login: %s\n", u->GetLogin().c_str());
- printfd(__FILE__, "middle: %s\n", middle.c_str());*/
-
- answerList->push_back(userStart);
- answerList->push_back(middle);
- answerList->push_back(userFinish);
- }
- }
-
-users->CloseSearch(h);
-
-//answerList->push_back("</Users>");
-
-answerList->push_back("</Users>");
-}
-//-----------------------------------------------------------------------------
-// ADD USER
-//-----------------------------------------------------------------------------
-PARSER_ADD_USER::PARSER_ADD_USER()
-{
-depth = 0;
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_USER::ParseStart(void *, const char *el, const char **attr)
-{
-depth++;
-
-if (depth == 1)
- {
- if (strcasecmp(el, "AddUser") == 0)
- {
- return 0;
- }
- }
-else
- {
- if (strcasecmp(el, "login") == 0)
- {
- login = attr[1];
- return 0;
- }
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_USER::ParseEnd(void *, const char *el)
-{
-if (depth == 1)
- {
- if (strcasecmp(el, "AddUser") == 0)
- {
- CreateAnswer();
- depth--;
- return 0;
- }
- }
-
-depth--;
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_ADD_USER::Reset()
-{
-BASE_PARSER::Reset();
-depth = 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_ADD_USER::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-if (CheckUserData() == 0)
- {
- answerList->push_back("<AddUser result=\"ok\"/>");
- }
-else
- {
- answerList->push_back("<AddUser result=\"error\" reason=\"Access denied\"/>");
- }
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_USER::CheckUserData()
-{
-user_iter u;
-if (users->FindByName(login, &u))
- {
- return users->Add(login, *currAdmin);
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-// PARSER CHG USER
-//-----------------------------------------------------------------------------
-PARSER_CHG_USER::PARSER_CHG_USER()
-{
-usr = NULL;
-ucr = NULL;
-upr = NULL;
-downr = NULL;
-
-Reset();
-}
-//-----------------------------------------------------------------------------
-PARSER_CHG_USER::~PARSER_CHG_USER()
-{
-delete usr;
-delete ucr;
-delete[] upr;
-delete[] downr;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::Reset()
-{
-depth = 0;
-delete usr;
-
-delete ucr;
-
-delete[] upr;
-
-delete[] downr;
-
-usr = new USER_STAT_RES;
-ucr = new USER_CONF_RES;
-
-upr = new RESETABLE<uint64_t>[DIR_NUM];
-downr = new RESETABLE<uint64_t>[DIR_NUM];
-};
-//-----------------------------------------------------------------------------
-string PARSER_CHG_USER::EncChar2String(const char * strEnc)
-{
-string str;
-Decode21str(str, strEnc);
-return str;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_USER::ParseStart(void *, const char *el, const char **attr)
-{
-depth++;
-
-if (depth == 1)
- {
- if (strcasecmp(el, "SetUser") == 0)
- {
- return 0;
- }
- }
-else
- {
- //printfd(__FILE__, "el=%s\n", el);
- if (strcasecmp(el, "login") == 0)
- {
- login = attr[1];
- return 0;
- }
-
- if (strcasecmp(el, "ip") == 0)
- {
- try
- {
- ucr->ips = StrToIPS(attr[1]);
- }
- catch (...)
- {
- printfd(__FILE__, "StrToIPS Error!\n");
- }
- }
-
- if (strcasecmp(el, "password") == 0)
- {
- ucr->password = attr[1];
- return 0;
- }
-
- if (strcasecmp(el, "address") == 0)
- {
- ucr->address = EncChar2String(attr[1]);
- return 0;
- }
-
- if (strcasecmp(el, "aonline") == 0)
- {
- ucr->alwaysOnline = (*(attr[1]) != '0');
- return 0;
- }
-
- if (strcasecmp(el, "cash") == 0)
- {
- if (attr[2] && (strcasecmp(attr[2], "msg") == 0))
- {
- cashMsg = EncChar2String(attr[3]);
- }
-
- double cash;
- if (strtodouble2(attr[1], cash) == 0)
- usr->cash = cash;
-
- if (strcasecmp(attr[0], "set") == 0)
- cashMustBeAdded = false;
-
- if (strcasecmp(attr[0], "add") == 0)
- cashMustBeAdded = true;
-
- return 0;
- }
-
- if (strcasecmp(el, "CreditExpire") == 0)
- {
- long int creditExpire = 0;
- if (str2x(attr[1], creditExpire) == 0)
- ucr->creditExpire = (time_t)creditExpire;
-
- return 0;
- }
-
- if (strcasecmp(el, "credit") == 0)
- {
- double credit;
- if (strtodouble2(attr[1], credit) == 0)
- ucr->credit = credit;
- return 0;
- }
-
- if (strcasecmp(el, "freemb") == 0)
- {
- double freeMb;
- if (strtodouble2(attr[1], freeMb) == 0)
- usr->freeMb = freeMb;
- return 0;
- }
-
- if (strcasecmp(el, "down") == 0)
- {
- int down = 0;
- if (str2x(attr[1], down) == 0)
- ucr->disabled = down;
- return 0;
- }
-
- if (strcasecmp(el, "DisableDetailStat") == 0)
- {
- int disabledDetailStat = 0;
- if (str2x(attr[1], disabledDetailStat) == 0)
- ucr->disabledDetailStat = disabledDetailStat;
- return 0;
- }
-
- if (strcasecmp(el, "email") == 0)
- {
- ucr->email = EncChar2String(attr[1]);
- return 0;
- }
-
- for (int i = 0; i < USERDATA_NUM; i++)
- {
- char name[15];
- sprintf(name, "userdata%d", i);
- if (strcasecmp(el, name) == 0)
- {
- ucr->userdata[i] = EncChar2String(attr[1]);
- return 0;
- }
- }
-
- if (strcasecmp(el, "group") == 0)
- {
- ucr->group = EncChar2String(attr[1]);
- return 0;
- }
-
- if (strcasecmp(el, "note") == 0)
- {
- ucr->note = EncChar2String(attr[1]);
- return 0;
- }
-
- if (strcasecmp(el, "passive") == 0)
- {
- int passive = 0;
- if (str2x(attr[1], passive) == 0)
- ucr->passive = passive;
- return 0;
- }
-
- if (strcasecmp(el, "phone") == 0)
- {
- ucr->phone = EncChar2String(attr[1]);
- return 0;
- }
-
- if (strcasecmp(el, "Name") == 0)
- {
- ucr->realName = EncChar2String(attr[1]);
- return 0;
- }
-
- if (strcasecmp(el, "traff") == 0)
- {
- int j = 0;
- int dir;
- DIR_TRAFF dtu;
- DIR_TRAFF dtd;
- unsigned long long t = 0;
- while (attr[j])
- {
- dir = attr[j][2] - '0';
-
- if (strncasecmp(attr[j], "md", 2) == 0)
- {
- str2x(attr[j+1], t);
- dtd[dir] = t;
- downr[dir] = t;
- }
- if (strncasecmp(attr[j], "mu", 2) == 0)
- {
- str2x(attr[j+1], t);
- dtu[dir] = t;
- upr[dir] = t;
- }
- j+=2;
- }
- usr->down = dtd;
- usr->up = dtu;
- return 0;
- }
-
- if (strcasecmp(el, "tariff") == 0)
- {
- if (strcasecmp(attr[0], "now") == 0)
- ucr->tariffName = attr[1];
-
- if (strcasecmp(attr[0], "delayed") == 0)
- ucr->nextTariff = attr[1];
-
- return 0;
- }
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_USER::ParseEnd(void *, const char *el)
-{
-if (depth == 1)
- {
- if (strcasecmp(el, "SetUser") == 0)
- {
- AplayChanges();
- CreateAnswer();
- depth--;
- return 0;
- }
- }
-
-depth--;
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-switch (res)
- {
- case 0:
- answerList->push_back("<SetUser result=\"ok\"/>");
- break;
- case -1:
- answerList->push_back("<SetUser result=\"error\"/>");
- break;
- case -2:
- answerList->push_back("<SetUser result=\"error\"/>");
- break;
- default:
- answerList->push_back("<SetUser result=\"error\"/>");
- break;
- }
-
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_USER::CheckUserData()
-{
-return true;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_USER::AplayChanges()
-{
-user_iter u;
-
-res = 0;
-if (users->FindByName(login, &u))
- {
- res = -1;
- return -1;
- }
-
-if (!ucr->ips.res_empty())
- if (!u->property.ips.Set(ucr->ips.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->address.res_empty())
- if (!u->property.address.Set(ucr->address.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->alwaysOnline.res_empty())
- if (!u->property.alwaysOnline.Set(ucr->alwaysOnline.const_data(),
- currAdmin, login, store))
- res = -1;
-
-if (!ucr->creditExpire.res_empty())
- if (!u->property.creditExpire.Set(ucr->creditExpire.const_data(),
- currAdmin, login, store))
- res = -1;
-
-if (!ucr->credit.res_empty())
- if (!u->property.credit.Set(ucr->credit.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!usr->freeMb.res_empty())
- if (!u->property.freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->disabled.res_empty())
- if (!u->property.disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->disabledDetailStat.res_empty())
- if (!u->property.disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->email.res_empty())
- if (!u->property.email.Set(ucr->email.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->group.res_empty())
- if (!u->property.group.Set(ucr->group.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->note.res_empty())
- if (!u->property.note.Set(ucr->note.const_data(), currAdmin, login, store))
- res = -1;
-
-vector<USER_PROPERTY_LOGGED<string> *> userdata;
-userdata.push_back(u->property.userdata0.GetPointer());
-userdata.push_back(u->property.userdata1.GetPointer());
-userdata.push_back(u->property.userdata2.GetPointer());
-userdata.push_back(u->property.userdata3.GetPointer());
-userdata.push_back(u->property.userdata4.GetPointer());
-userdata.push_back(u->property.userdata5.GetPointer());
-userdata.push_back(u->property.userdata6.GetPointer());
-userdata.push_back(u->property.userdata7.GetPointer());
-userdata.push_back(u->property.userdata8.GetPointer());
-userdata.push_back(u->property.userdata9.GetPointer());
-
-for (int i = 0; i < (int)userdata.size(); i++)
- {
- if (!ucr->userdata[i].res_empty())
- {
- if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
- res = -1;
- }
- }
-
-if (!ucr->passive.res_empty())
- if (!u->property.passive.Set(ucr->passive.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->password.res_empty())
- if (!u->property.password.Set(ucr->password.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->phone.res_empty())
- if (!u->property.phone.Set(ucr->phone.const_data(), currAdmin, login, store))
- res = -1;
-
-if (!ucr->realName.res_empty())
- if (!u->property.realName.Set(ucr->realName.const_data(), currAdmin, login, store))
- res = -1;
-
-
-if (!usr->cash.res_empty())
- {
- //if (currAdmin->GetPriv()->userCash)
- {
- if (cashMustBeAdded)
- {
- if (!u->property.cash.Set(usr->cash.const_data() + u->property.cash,
- currAdmin,
- login,
- store,
- cashMsg))
- res = -1;
- }
- else
- {
- if (!u->property.cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
- res = -1;
- }
- }
- }
-
-
-if (!ucr->tariffName.res_empty())
- {
- if (tariffs->FindByName(ucr->tariffName.const_data()))
- {
- if (!u->property.tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
- res = -1;
- u->ResetNextTariff();
- }
- else
- {
- //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
- res = -1;
- }
- }
-
-if (!ucr->nextTariff.res_empty())
- {
- if (tariffs->FindByName(ucr->nextTariff.const_data()))
- {
- if (!u->property.nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
- res = -1;
- }
- else
- {
- //WriteServLog("SetUser: Tariff %s not found", ud.conf.tariffName.c_str());
- res = -1;
- }
- }
-
-DIR_TRAFF up = u->property.up;
-DIR_TRAFF down = u->property.down;
-int upCount = 0;
-int downCount = 0;
-for (int i = 0; i < DIR_NUM; i++)
- {
- if (!upr[i].res_empty())
- {
- up[i] = upr[i];
- upCount++;
- }
- if (!downr[i].res_empty())
- {
- down[i] = downr[i];
- downCount++;
- }
- }
-
-if (upCount)
- if (!u->property.up.Set(up, currAdmin, login, store))
- res = -1;
-
-if (downCount)
- if (!u->property.down.Set(down, currAdmin, login, store))
- res = -1;
-
-/*if (!usr->down.res_empty())
- {
- u->property.down.Set(usr->down.const_data(), currAdmin, login, store);
- }
-if (!usr->up.res_empty())
- {
- u->property.up.Set(usr->up.const_data(), currAdmin, login, store);
- }*/
-
-u->WriteConf();
-u->WriteStat();
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-// SEND MESSAGE
-//-----------------------------------------------------------------------------
-int PARSER_SEND_MESSAGE::ParseStart(void *, const char *el, const char **attr)
-{
-if (strcasecmp(el, "Message") == 0)
- {
- for (int i = 0; i < 14; i++)
- {
- if (attr[i] == NULL)
- {
- result = res_params_error;
- CreateAnswer();
- printfd(__FILE__, "To few parameters\n");
- return 0;
- }
- }
-
- for (int i = 0; i < 14; i+=2)
- {
- if (strcasecmp(attr[i], "login") == 0)
- {
- ParseLogins(attr[i+1]);
- /*if (users->FindByName(login, &u))
- {
- result = res_unknown;
- break;
- }*/
- }
-
- if (strcasecmp(attr[i], "MsgVer") == 0)
- {
- str2x(attr[i+1], msg.header.ver);
- if (msg.header.ver != 1)
- result = res_params_error;
- }
-
- if (strcasecmp(attr[i], "MsgType") == 0)
- {
- str2x(attr[i+1], msg.header.type);
- if (msg.header.type != 1)
- result = res_params_error;
- }
-
- if (strcasecmp(attr[i], "Repeat") == 0)
- {
- str2x(attr[i+1], msg.header.repeat);
- if (msg.header.repeat < 0)
- result = res_params_error;
- }
-
- if (strcasecmp(attr[i], "RepeatPeriod") == 0)
- {
- str2x(attr[i+1], msg.header.repeatPeriod);
- }
-
- if (strcasecmp(attr[i], "ShowTime") == 0)
- {
- str2x(attr[i+1], msg.header.showTime);
- }
-
- if (strcasecmp(attr[i], "Text") == 0)
- {
- Decode21str(msg.text, attr[i+1]);
- result = res_ok;
- }
- }
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_SEND_MESSAGE::ParseEnd(void *, const char *el)
-{
-//MSG msg;
-if (strcasecmp(el, "Message") == 0)
- {
- result = res_unknown;
- for (unsigned i = 0; i < logins.size(); i++)
- {
- if (users->FindByName(logins[i], &u))
- {
- printfd(__FILE__, "User not found. %s\n", logins[i].c_str());
- continue;
- }
- msg.header.creationTime = stgTime;
- u->AddMessage(&msg);
- result = res_ok;
- }
- /*if (result == res_ok)
- {
- if (strcmp(login, "*") == 0)
- {
- msg.text = text;
- msg.prio = pri;
- printfd(__FILE__, "SendMsg text: %s\n", text);
- users->GetAllUsers(SendMessageAllUsers, &msg);
- }
- else
- {
- u->AddMessage(pri, text);
- }
- }*/
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_SEND_MESSAGE::ParseLogins(const char * login)
-{
-char * p;
-char * l = new char[strlen(login) + 1];
-strcpy(l, login);
-p = strtok(l, ":");
-logins.clear();
-while(p)
- {
- logins.push_back(p);
- p = strtok(NULL, ":");
- }
-
-delete[] l;
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-//answerList->push_back("<SendMessageResult value=\"ok\"/>");
-//
-switch (result)
- {
- case res_ok:
- answerList->push_back("<SendMessageResult value=\"ok\"/>");
- break;
- case res_params_error:
- printfd(__FILE__, "res_params_error\n");
- answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
- break;
- case res_unknown:
- printfd(__FILE__, "res_unknown\n");
- answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
- break;
- default:
- printfd(__FILE__, "res_default\n");
- }
-
-}
-//-----------------------------------------------------------------------------
-// DEL USER
-//-----------------------------------------------------------------------------
-int PARSER_DEL_USER::ParseStart(void *, const char *el, const char **attr)
-{
-res = 0;
-if (strcasecmp(el, "DelUser") == 0)
- {
- if (attr[0] == NULL || attr[1] == NULL)
- {
- //CreateAnswer("Parameters error!");
- CreateAnswer();
- return 0;
- }
-
- if (users->FindByName(attr[1], &u))
- {
- res = 1;
- CreateAnswer();
- return 0;
- }
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_DEL_USER::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "DelUser") == 0)
- {
- if (!res)
- users->Del(u->GetLogin(), *currAdmin);
-
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_DEL_USER::CreateAnswer()
-{
-if (res)
- answerList->push_back("<DelUser value=\"error\" reason=\"User not found\"/>");
-else
- answerList->push_back("<DelUser value=\"ok\"/>");
-}
-//-----------------------------------------------------------------------------
-/*void PARSERDELUSER::CreateAnswer(char * mes)
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-char str[255];
-sprintf(str, "<DelUser value=\"%s\"/>", mes);
-answerList->push_back(str);
-}*/
-//-----------------------------------------------------------------------------
-// CHECK USER
-// <checkuser login="vasya" password=\"123456\"/>
-//-----------------------------------------------------------------------------
-int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
-{
-result = false;
-
-if (strcasecmp(el, "CheckUser") == 0)
- {
- if (attr[0] == NULL || attr[1] == NULL
- || attr[2] == NULL || attr[3] == NULL)
- {
- result = false;
- CreateAnswer();
- printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
- return 0;
- }
-
- user_iter user;
- if (users->FindByName(attr[1], &user))
- {
- result = false;
- CreateAnswer();
- printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
- return 0;
- }
-
- if (strcmp(user->property.password.Get().c_str(), attr[3]))
- {
- result = false;
- CreateAnswer();
- printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
- return 0;
- }
-
- result = true;
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHECK_USER::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "CheckUser") == 0)
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHECK_USER::CreateAnswer()
-{
-if (result)
- answerList->push_back("<CheckUser value=\"Ok\"/>");
-else
- answerList->push_back("<CheckUser value=\"Err\"/>");
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
+++ /dev/null
- /*
- $Revision: 1.18 $
- $Date: 2009/07/30 18:57:37 $
- $Author: nobunaga $
- */
-
-#ifndef PARSER_H
-#define PARSER_H
-
-#include <list>
-#include <string>
-
-using namespace std;
-
-#include "resetable.h"
-#include "const.h"
-#include "store.h"
-#include "admins.h"
-#include "users.h"
-#include "message.h"
-
-//-----------------------------------------------------------------------------
-class BASE_PARSER {
-public:
- BASE_PARSER()
- : admins(NULL),
- users(NULL),
- tariffs(NULL),
- store(NULL),
- settings(NULL),
- currAdmin(NULL),
- depth(0)
- { }
- virtual ~BASE_PARSER() {}
- virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
- virtual int ParseEnd(void *data, const char *el) = 0;
- virtual void CreateAnswer() = 0;
- virtual void SetAnswerList(list<string> * ansList) { answerList = ansList; }
-
- virtual void SetUsers(USERS * u) { users = u; }
- virtual void SetAdmins(ADMINS * a) { admins = a; }
- virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
- virtual void SetStore(STORE * s) { store = s; }
- virtual void SetStgSettings(const SETTINGS * s) { settings = s; }
-
- virtual void SetCurrAdmin(const ADMIN * cua) { currAdmin = cua; }
- virtual string & GetStrError() { return strError; }
- virtual void Reset(){ answerList->clear(); depth = 0; }
-protected:
- string strError;
- ADMINS * admins;
- USERS * users;
- TARIFFS * tariffs;
- STORE * store;
- const SETTINGS * settings;
- const ADMIN * currAdmin;
- int depth;
- list<string> * answerList;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_ADMINS: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-};
-//-----------------------------------------------------------------------------
-class PARSER_ADD_ADMIN: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- string adminToAdd;
-};
-//-----------------------------------------------------------------------------
-class PARSER_DEL_ADMIN: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- int CheckAttr(const char **attr);
- string adminToDel;
-};
-//-----------------------------------------------------------------------------
-class PARSER_CHG_ADMIN: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- RESETABLE<string> login;
- RESETABLE<string> password;
- RESETABLE<string> privAsString;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_SERVER_INFO: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-};
-
-//-----------------------------------------------------------------------------
-class PARSER_GET_USER: public BASE_PARSER {
-public:
- PARSER_GET_USER();
- ~PARSER_GET_USER() {}
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- string login;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_USERS: public BASE_PARSER {
-public:
- PARSER_GET_USERS();
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- time_t lastUserUpdateTime;
- bool lastUpdateFound;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_TARIFFS: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-};
-//-----------------------------------------------------------------------------
-class PARSER_ADD_TARIFF: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- string tariffToAdd;
-};
-//-----------------------------------------------------------------------------
-class PARSER_DEL_TARIFF: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- string tariffToDel;
-};
-//-----------------------------------------------------------------------------
-class PARSER_CHG_TARIFF: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- int ParseSlashedIntParams(int paramsNum, const string & s, int * params);
- int ParseSlashedDoubleParams(int paramsNum, const string & s, double * params);
- int CheckTariffData();
- int AplayChanges();
-
- TARIFF_DATA_RES td;
-};
-//-----------------------------------------------------------------------------/
-class PARSER_ADD_USER: public BASE_PARSER {
-public:
- PARSER_ADD_USER();
- virtual ~PARSER_ADD_USER() {}
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
- void Reset();
-private:
- int CheckUserData();
- string login;
-};
-//-----------------------------------------------------------------------------
-class PARSER_CHG_USER: public BASE_PARSER {
-public:
- PARSER_CHG_USER();
- ~PARSER_CHG_USER();
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
- void Reset();
-private:
- string EncChar2String(const char *);
-
- USER_STAT_RES * usr;
- USER_CONF_RES * ucr;
- RESETABLE<uint64_t> * upr;
- RESETABLE<uint64_t> * downr;
- string cashMsg;
- string login;
-
- int CheckUserData();
- int AplayChanges();
- bool cashMustBeAdded;
- int res;
-};
-//-----------------------------------------------------------------------------
-class PARSER_DEL_USER: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-
-private:
- int res;
- user_iter u;
-};
-//-----------------------------------------------------------------------------
-class PARSER_CHECK_USER: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- bool result;
-};
-//-----------------------------------------------------------------------------
-class PARSER_SEND_MESSAGE: public BASE_PARSER {
-public:
- int ParseStart(void *data, const char *el, const char **attr);
- int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- enum {res_ok, res_params_error, res_unknown};
- vector<string> logins;
- int ParseLogins(const char * logins);
- int result;
- STG_MSG msg;
- user_iter u;
-};
-//-----------------------------------------------------------------------------
-#endif
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-
-#include "parser.h"
-
-//-----------------------------------------------------------------------------
-// GET ADMINS
-//-----------------------------------------------------------------------------
-int PARSER_GET_ADMINS::ParseStart(void *, const char *el, const char **)
-{
-if (strcasecmp(el, "GetAdmins") == 0)
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_ADMINS::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetAdmins") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_ADMINS::CreateAnswer()
-{
-const PRIV * priv = currAdmin->GetPriv();
-if (!priv->adminChg)
- {
- //answerList->clear();
- answerList->erase(answerList->begin(), answerList->end());
-
- answerList->push_back("<Error Result=\"Error. Access denied.\"/>");
- return;
- }
-
-string s;
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-answerList->push_back("<Admins>");
-ADMIN_CONF ac;
-int h = admins->OpenSearch();
-
-unsigned int p;
-while (admins->SearchNext(h, &ac) == 0)
- {
- //memcpy(&p, &ac.priv, sizeof(unsigned int));
- p = (ac.priv.userStat << 0) +
- (ac.priv.userConf << 2) +
- (ac.priv.userCash << 4) +
- (ac.priv.userPasswd << 6) +
- (ac.priv.userAddDel << 8) +
- (ac.priv.adminChg << 10) +
- (ac.priv.tariffChg << 12);
- strprintf(&s, "<admin login=\"%s\" priv=\"%d\"/>", ac.login.c_str(), p);
- answerList->push_back(s);
- }
-admins->CloseSearch(h);
-answerList->push_back("</Admins>");
-}
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-// DEL ADMIN
-//-----------------------------------------------------------------------------
-int PARSER_DEL_ADMIN::ParseStart(void *, const char *el, const char **attr)
-{
-strError = "";
-if (strcasecmp(el, "DelAdmin") == 0)
- {
- adminToDel = attr[1];
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_DEL_ADMIN::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "DelAdmin") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_DEL_ADMIN::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-if (admins->Del(adminToDel, *currAdmin) == 0)
- {
- answerList->push_back("<DelAdmin Result=\"Ok\"/>");
- }
-else
- {
- string s;
- strprintf(&s, "<DelAdmin Result=\"Error. %s\"/>", admins->GetStrError().c_str());
- answerList->push_back(s);
- }
-}
-//-----------------------------------------------------------------------------
-int PARSER_DEL_ADMIN::CheckAttr(const char **attr)
-{
-/* <DelAdmin login=\"admin\">
- * attr[0] = "login" (word login)
- * attr[1] = login, value of login
- * attr[2] = NULL */
-
-if (strcasecmp(attr[0], "login") == 0 && attr[1] && !attr[2])
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-// ADD ADMIN
-//-----------------------------------------------------------------------------
-int PARSER_ADD_ADMIN::ParseStart(void *, const char *el, const char **attr)
-{
-if (strcasecmp(el, "AddAdmin") == 0)
- {
- adminToAdd = attr[1];
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_ADMIN::ParseEnd(void *, const char *el)
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-if (strcasecmp(el, "AddAdmin") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_ADD_ADMIN::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-if (admins->Add(adminToAdd, *currAdmin) == 0)
- {
- answerList->push_back("<AddAdmin Result=\"Ok\"/>");
- }
-else
- {
- string s;
- strprintf(&s, "<AddAdmin Result=\"Error. %s\"/>", admins->GetStrError().c_str());
- answerList->push_back(s);
- }
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-// CHG ADMIN
-//-----------------------------------------------------------------------------
-int PARSER_CHG_ADMIN::ParseStart(void *, const char *el, const char **attr)
-{
-if (strcasecmp(el, "ChgAdmin") == 0)
- {
- for (int i = 0; i < 6; i+=2)
- {
- printfd(__FILE__, "PARSER_CHG_ADMIN::attr[%d] = %s\n", i, attr[i]);
- if (attr[i] == NULL)
- break;
-
- if (strcasecmp(attr[i], "Login") == 0)
- {
- login = attr[i + 1];
- continue;
- }
-
- if (strcasecmp(attr[i], "Priv") == 0)
- {
- privAsString = attr[i + 1];
- continue;
- }
-
- if (strcasecmp(attr[i], "Password") == 0)
- {
- password = attr[i + 1];
- continue;
- }
- }
-
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_ADMIN::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "ChgAdmin") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_ADMIN::CreateAnswer()
-{
-answerList->erase(answerList->begin(), answerList->end());
-
-ADMIN_CONF conf;
-conf.login = login;
-if (!login.res_empty())
- {
- string s;
- //if (admins->FindAdmin(login.data()) != NULL)
- // {
- if (!password.res_empty())
- conf.password = password.data();
-
- if (!privAsString.res_empty())
- {
- int p = 0;
- if (str2x(privAsString.data().c_str(), p) < 0)
- {
- strprintf(&s, "<ChgAdmin Result = \"Incorrect parameter Priv.\"/>" );
- answerList->push_back(s);
- return;
- }
- //memcpy(&conf.priv, &p, sizeof(conf.priv));
- conf.priv.userStat = (p & 0x0003) >> 0x00; // 1+2
- conf.priv.userConf = (p & 0x000C) >> 0x02; // 4+8
- conf.priv.userCash = (p & 0x0030) >> 0x04; // 10+20
- conf.priv.userPasswd = (p & 0x00C0) >> 0x06; // 40+80
- conf.priv.userAddDel = (p & 0x0300) >> 0x08; // 100+200
- conf.priv.adminChg = (p & 0x0C00) >> 0x0A; // 400+800
- conf.priv.tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000
- }
-
- if (admins->Change(conf, *currAdmin) != 0)
- {
- strprintf(&s, "<ChgAdmin Result = \"%s\"/>", admins->GetStrError().c_str());
- answerList->push_back(s);
- }
- else
- {
- answerList->push_back("<ChgAdmin Result = \"Ok\"/>");
- }
- return;
- // }
- //strprintf(&s, "<ChgAdmin Result = \"%s\"/>", admins->GetStrError().c_str());
- //answerList->push_back(s);
- //return;
- }
-else
- {
- answerList->push_back("<ChgAdmin Result = \"Incorrect parameter login.\"/>");
- }
-}
-//-----------------------------------------------------------------------------*/
-
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-
-#include "parser.h"
-//#include "admins.h"
-//#include "tariff2.h"
-const int pt_mega = 1024 * 1024;
-//-----------------------------------------------------------------------------
-// GET TARIFFS
-//-----------------------------------------------------------------------------
-int PARSER_GET_TARIFFS::ParseStart(void *, const char *el, const char **)
-{
-if (strcasecmp(el, "GetTariffs") == 0)
- {
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_TARIFFS::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "GetTariffs") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_TARIFFS::CreateAnswer()
-{
-string s;
-char vs[100];
-int hd, hn, md, mn;
-
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-answerList->push_back("<Tariffs>");
-int h = tariffs->OpenSearch();
-
-TARIFF_DATA td;
-while (tariffs->SearchNext(h, &td) == 0)
- {
- s = "<tariff name=\"" + td.tariffConf.name + "\">";
- //printfd(__FILE__, "%s\n", s.c_str());
- answerList->push_back(s);
-
- for (int j = 0; j < DIR_NUM; j++)
- {
- hd = td.dirPrice[j].hDay;
- md = td.dirPrice[j].mDay;
-
- hn = td.dirPrice[j].hNight;
- mn = td.dirPrice[j].mNight;
-
- strprintf(&s, "<Time%d value=\"%d:%d-%d:%d\"/>", j, hd, md, hn, mn);
- answerList->push_back(s);
- }
-
- strprintf(&s, " <PriceDayA value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceDayA * pt_mega, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <PriceDayB value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceDayB * pt_mega, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <PriceNightA value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceNightA * pt_mega, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <PriceNightB value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%.5f%s", td.dirPrice[i].priceNightB * pt_mega, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <Threshold value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%d%s", td.dirPrice[i].threshold, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <SinglePrice value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%d%s", td.dirPrice[i].singlePrice, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <NoDiscount value=\"");
- for (int i = 0; i < DIR_NUM; i++)
- {
- snprintf(vs, 100, "%d%s", td.dirPrice[i].noDiscount, i+1 == DIR_NUM?"":"/");
- s += vs;
- }
- s += "\"/>";
- answerList->push_back(s);
-
- strprintf(&s, " <Fee value=\"%.5f\"/>", td.tariffConf.fee);
- answerList->push_back(s);
- //printfd(__FILE__, "%s\n", s.c_str());
-
- strprintf(&s, " <PassiveCost value=\"%.5f\"/>", td.tariffConf.passiveCost);
- answerList->push_back(s);
-
- strprintf(&s, " <Free value=\"%.5f\"/>", td.tariffConf.free);
- answerList->push_back(s);
-
- switch (td.tariffConf.traffType)
- {
- case TRAFF_UP:
- answerList->push_back("<TraffType value=\"up\"/>");
- break;
- case TRAFF_DOWN:
- answerList->push_back("<TraffType value=\"down\"/>");
- break;
- case TRAFF_UP_DOWN:
- answerList->push_back("<TraffType value=\"up+down\"/>");
- break;
- case TRAFF_MAX:
- answerList->push_back("<TraffType value=\"max\"/>");
- break;
- }
-
- answerList->push_back("</tariff>");
- }
-tariffs->CloseSearch(h);
-answerList->push_back("</Tariffs>");
-}
-//-----------------------------------------------------------------------------
-// ADD TARIFF
-//-----------------------------------------------------------------------------
-int PARSER_ADD_TARIFF::ParseStart(void *, const char *el, const char **attr)
-{
-if (strcasecmp(el, "AddTariff") == 0)
- {
- if (attr[1])
- {
- tariffToAdd = attr[1];
- }
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_ADD_TARIFF::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "AddTariff") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_ADD_TARIFF::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-if (tariffs->Add(tariffToAdd, *currAdmin) == 0)
- {
- answerList->push_back("<AddTariff Result=\"Ok\"/>");
- }
-else
- {
- string s;
- strprintf(&s, "<AddTariff Result=\"Error. %s\"/>", tariffs->GetStrError().c_str());
- answerList->push_back(s);
- }
-}
-//-----------------------------------------------------------------------------
-// DEL TARIFF
-//-----------------------------------------------------------------------------
-int PARSER_DEL_TARIFF::ParseStart(void *, const char *el, const char **attr)
-{
-strError = "";
-if (strcasecmp(el, "DelTariff") == 0)
- {
- tariffToDel = attr[1];
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_DEL_TARIFF::ParseEnd(void *, const char *el)
-{
-if (strcasecmp(el, "DelTariff") == 0)
- {
- CreateAnswer();
- return 0;
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_DEL_TARIFF::CreateAnswer()
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-if (tariffs->Del(tariffToDel, *currAdmin) == 0)
- {
- answerList->push_back("<DelTariff Result=\"Ok\"/>");
- }
-else
- {
- string s;
- strprintf(&s, "<DelTariff Result=\"Error. %s\"/>", tariffs->GetStrError().c_str());
- answerList->push_back(s);
- }
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-// CHG TARIFF
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-int PARSER_CHG_TARIFF::ParseSlashedIntParams(int paramsNum, const string & s, int * params)
-{
-char * str = new char[s.size() + 1];
-char * p;
-strcpy(str, s.c_str());
-p = strtok(str, "/");
-
-for (int i = 0; i < paramsNum; i++)
- {
- if (p == NULL)
- {
- delete[] str;
- return -1;
- }
-
- if (str2x(p, params[i]) != 0)
- {
- delete[] str;
- return -1;
- }
-
- p = strtok(NULL, "/");
- }
-
-delete[] str;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_TARIFF::ParseSlashedDoubleParams(int paramsNum, const string & s, double * params)
-{
-char * str = new char[s.size() + 1];
-char * p;
-strcpy(str, s.c_str());
-p = strtok(str, "/");
-
-for (int i = 0; i < paramsNum; i++)
- {
- if (p == NULL)
- {
- delete[] str;
- return -1;
- }
-
- if (strtodouble2(p, params[i]) != 0)
- {
- delete[] str;
- return -1;
- }
-
- p = strtok(NULL, "/");
- }
-
-delete[] str;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_TARIFF::ParseStart(void *, const char *el, const char **attr)
-{
-char st[50];
-double price[DIR_NUM];
-int t[DIR_NUM];
-depth++;
-
-if (depth == 1)
- {
- if (strcasecmp(el, "SetTariff") == 0)
- {
- td.tariffConf.name = attr[1];
- return 0;
- }
- }
-else
- {
- string s;
-
- if (strcasecmp(el, "PriceDayA") == 0)
- {
- s = attr[1];
- if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].priceDayA = price[j] / pt_mega;
- return 0;
- }
-
- if (strcasecmp(el, "PriceDayB") == 0)
- {
- s = attr[1];
- if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].priceDayB = price[j] / pt_mega;
- return 0;
- }
-
-
- if (strcasecmp(el, "PriceNightA") == 0)
- {
- s = attr[1];
- if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].priceNightA = price[j] / pt_mega;
- return 0;
- }
-
- if (strcasecmp(el, "PriceNightB") == 0)
- {
- s = attr[1];
- if (ParseSlashedDoubleParams(DIR_NUM, s, price) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].priceNightB = price[j] / pt_mega;
- return 0;
- }
-
- if (strcasecmp(el, "Threshold") == 0)
- {
- s = attr[1];
- if (ParseSlashedIntParams(DIR_NUM, s, t) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].threshold = t[j];
- return 0;
- }
-
- if (strcasecmp(el, "SinglePrice") == 0)
- {
- s = attr[1];
- if (ParseSlashedIntParams(DIR_NUM, s, t) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].singlePrice = t[j];
- return 0;
- }
-
- if (strcasecmp(el, "NoDiscount") == 0)
- {
- s = attr[1];
- if (ParseSlashedIntParams(DIR_NUM, s, t) == 0)
- for (int j = 0; j < DIR_NUM; j++)
- td.dirPrice[j].noDiscount = t[j];
- return 0;
- }
-
- for (int j = 0; j < DIR_NUM; j++)
- {
- snprintf(st, 50, "Time%d", j);
- if (strcasecmp(el, st) == 0)
- {
- int h1, m1, h2, m2;
- if (ParseTariffTimeStr(attr[1], h1, m1, h2, m2) == 0)
- {
- td.dirPrice[j].hDay = h1;
- td.dirPrice[j].mDay = m1;
- td.dirPrice[j].hNight = h2;
- td.dirPrice[j].mNight = m2;
- }
- return 0;
- }
- }
-
- if (strcasecmp(el, "Fee") == 0)
- {
- double fee;
- if (strtodouble2(attr[1], fee) == 0)
- td.tariffConf.fee = fee;
- return 0;
- }
-
- if (strcasecmp(el, "PassiveCost") == 0)
- {
- double pc;
- if (strtodouble2(attr[1], pc) == 0)
- td.tariffConf.passiveCost = pc;
- return 0;
- }
- if (strcasecmp(el, "Free") == 0)
- {
- double free;
- if (strtodouble2(attr[1], free) == 0)
- td.tariffConf.free = free;
- return 0;
- }
-
- if (strcasecmp(el, "TraffType") == 0)
- {
- if (strcasecmp(attr[1], "up") == 0)
- {
- td.tariffConf.traffType = TRAFF_UP;
- return 0;
- }
-
- if (strcasecmp(attr[1], "down") == 0)
- {
- td.tariffConf.traffType = TRAFF_DOWN;
- return 0;
- }
- if (strcasecmp(attr[1], "up+down") == 0)
- {
- td.tariffConf.traffType = TRAFF_UP_DOWN;
- return 0;
- }
- if (strcasecmp(attr[1], "max") == 0)
- {
- td.tariffConf.traffType = TRAFF_MAX;
- return 0;
- }
- return 0;
- }
- }
-return -1;
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_TARIFF::ParseEnd(void *, const char *el)
-{
-if (depth == 1)
- {
- if (strcasecmp(el, "SetTariff") == 0)
- {
- CreateAnswer();
- depth--;
- return 0;
- }
- }
-
-depth--;
-return -1;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_TARIFF::CreateAnswer()
-{
-answerList->erase(answerList->begin(), answerList->end());
-
-if (!td.tariffConf.name.data().empty())
- {
- TARIFF_DATA tariffData = td.GetData();
- if (tariffs->Chg(tariffData, *currAdmin) == 0)
- {
- answerList->push_back("<SetTariff Result=\"ok\"/>");
- return;
- }
- else
- {
- string s;
- strprintf(&s, "<SetTariff Result=\"Change tariff error! %s\"/>", tariffs->GetStrError().c_str());
- answerList->push_back(s);
- return;
- }
- }
-answerList->push_back("<SetTariff Result=\"Change tariff error!\"/>");
-}
-//-----------------------------------------------------------------------------
-
+++ /dev/null
-#ifndef __PROTO_H__
-#define __PROTO_H__
-
-namespace SGCONF2 {
-
-/*
- * --- Protocol structure (binary part) ---
- *
- * Request:
- * |---------------|
- * |PROTOHEADER |
- * |REQUESTHEADER |
- * |---------------|
- * | cryptodata |
- * ~~~~~~~~~~~~~~~~~
- * |---------------|
- *
- * Response:
- * |---------------|
- * |PROTOHEADER |
- * |RESPONSEHEADER |
- * | error message |
- * | cryptodata |
- * ~~~~~~~~~~~~~~~~~
- * |---------------|
- *
- */
-
- static char magic[8] = "STGCONF2";
-
- enum RESPONSECODES {
- E_OK = 0, // No error
- E_NET_ERROR, // Network error (i.e. - timeout)
- E_PROTO_ERROR, // Protocol error (invalid magic, unsupported version, etc.)
- E_INVALID_LOGIN,// Invalid login
- E_PERMISSIONS // Operation not permitted
- };
-
- struct PROTOHEADER {
- char magic[8];
- uint32_t version;
- };
-
- struct REQUESTHEADER {
- char login[32];
- };
-
- struct CRYPTOHEADER {
- char login[32];
- uint32_t dataSize; // Can't be 0
- };
-
- struct RESPONSEHEADER {
- uint32_t code;
- uint32_t errorMessageSize; // May be 0
- uint32_t dataSize; // May be 0
- };
-
-}
-
-#endif
+++ /dev/null
-/*
- * 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
- */
-
-/*******************************************************************
-*
-* DESCRIPTION: æÁÊÌ Ó ÏÓÎÏ×ÎÙÍÉ ÆÕÎËÃÉÑÍÉ ÄÌÑ ÓÅÔÅ×ÏÇÏ ÏÂÍÅÎÁ ÄÁÎÎÙÍÉ
-* Ó ÍÅÎÅÄÖÅÒÏÍ ËÌÉÅÎÔÏ×. ðÒÉÅÍ, ÐÅÒÅÄÁÞÁ É ÛÉÆÒÏ×ÁÎÉÅ ÓÏÏÂÝÅÎÉÊ.
-*
-* AUTHOR: Boris Mikhailenko <stg34@stargazer.dp.ua>
-*
-* $Revision: 1.20 $
-* $Date: 2009/10/31 15:44:02 $
-*
-*******************************************************************/
-
-#include <unistd.h>
-#include <stdio.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netinet/tcp.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <pthread.h>
-
-#ifdef LINUX
-#include <error.h>
-#endif
-
-#ifdef FREE_BSD
-#include <sys/errno.h>
-#endif
-
-#ifdef FREE_BSD5
-#include <sys/errno.h>
-#endif
-
-extern int errno;
-
-#include "configproto.h"
-
-enum CONF_STATE
- {
- confHdr,
- confLogin,
- confLoginCipher,
- confData
- };
-
-enum
- {
- ans_ok = 0,
- ans_err
- };
-
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::Prepare()
-{
-list<string> ansList; //óÀÄÁ ÂÕÄÅÔ ÐÏÍÅÝÅÎ ÏÔ×ÅÔ ÄÌÑ ÍÅÎÅÄÖÅÒÁ ËÌÉÅÎÔÏ×
-int res;
-struct sockaddr_in listenAddr;
-
-sigset_t sigmask, oldmask;
-sigemptyset(&sigmask);
-sigaddset(&sigmask, SIGINT);
-sigaddset(&sigmask, SIGTERM);
-sigaddset(&sigmask, SIGUSR1);
-sigaddset(&sigmask, SIGHUP);
-pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
-
-listenSocket = socket(PF_INET, SOCK_STREAM, 0);
-
-if (listenSocket < 0)
- {
- errorStr = "Create NET_CONFIGURATOR socket failed.";
- return -1;
- }
-
-listenAddr.sin_family = PF_INET;
-listenAddr.sin_port = htons(port);
-listenAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
-
-int lng = 1;
-
-if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4))
- {
- errorStr = "Setsockopt failed. " + string(strerror(errno));
- return -1;
- }
-
-res = bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr));
-
-if (res == -1)
- {
- errorStr = "Bind admin socket failed";
- return -1;
- }
-
-res = listen(listenSocket, 0);
-if (res == -1)
- {
- errorStr = "Listen admin socket failed";
- return -1;
- }
-outerAddrLen = sizeof(outerAddr);
-
-/*if (0 != fcntl(listenSocket, F_SETFL, O_NONBLOCK))
- {
- errorStr = "fcntl error!";
- return -1;
- }*/
-
-errorStr = "";
-nonstop = true;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::Stop()
-{
-nonstop = false;
-close(listenSocket);
-//TODO: Idiotism
-int sock;
-struct sockaddr_in addr;
-socklen_t addrLen;
-addr.sin_family = PF_INET;
-addr.sin_port = htons(port);
-addr.sin_addr.s_addr = inet_addr("127.0.0.1");
-
-addrLen = sizeof(outerAddr);
-sock = socket(PF_INET, SOCK_STREAM, 0);
-connect(sock, (sockaddr*)&addr, addrLen);
-close(sock);
-//Idiotism end
-return 0;
-}
-//-----------------------------------------------------------------------------
-// æÕÎËÃÉÑ ÏÂÝÅÎÉÑ Ó ËÏÎÆÉÇÕÒÁÔÏÒÏÍ
-void * CONFIGPROTO::Run(void * a)
-{
-/*
- * Function Name:ReciveSendConf
- * Parameters: void * a ÕËÁÚÁÔÅÌØ ÎÁ ÜËÚÅÍÐÌÑÒ ËÌÁÓÓÁ CONFIGPROTO
- * Description: üÔÁ ÆÕÎËÃÉÑ ÏÂÅÓÐÅÞÉ×ÁÅÔ ÓÅÔÅ×ÏÅ ×ÚÁÉÍÏÄÅÊÓÔ×ÉÅ
- * Ó íÅÎÅÄÖÅÒÏÍ ëÌÉÅÎÔÏ×. ÷ ÅÅ ÚÁÄÁÞÉ ×ÈÏÄÉÔ: ÐÒÉÅÍ ÚÁÐÒÏÓÏ× ÐÏ TCP/IP
- * ÉÈ ÒÁÓÛÉÆÒÏ×ËÁ, ÐÅÒÅÄÁÞÁ ÐÒÉÎÑÔÙÈ ÄÁÎÎÙÈ ÁÎÁÌÉÚÁÔÏÒÕ É ÏÔÐÒÁ×ËÁ ÏÔ×ÅÔÁ ÎÁÚÁÄ.
- * Returns: ×ÏÚ×ÒÁÝÁÅÔ NULL
- */
-
-CONFIGPROTO * cp = (CONFIGPROTO*)a;
-cp->state = confHdr;
-
-while (cp->nonstop)
- {
- cp->state = confHdr;
- cp->outerSocket = accept(cp->listenSocket,
- (struct sockaddr*)(&cp->outerAddr),
- &cp->outerAddrLen);
-
- if (!cp->nonstop)
- {
- continue;
- }
-
- if (cp->outerSocket == -1)
- {
- printfd(__FILE__, "accept failed\n");
- usleep(100000);
- continue;
- }
-
- cp->adminIP = *(unsigned int*)&(cp->outerAddr.sin_addr);
-
- /* TODO
- if (!cp->hostAllow->HostAllowed(cp->adminIP))
- {
- close(outerSocket);
- continue;
- }*/
-
- printfd(__FILE__, "Connection accepted from %s\n", inet_ntostring(cp->outerAddr.sin_addr.s_addr).c_str());
-
- if (cp->state == confHdr)
- {
- if (cp->RecvHdr(cp->outerSocket) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
- if (cp->state == confLogin)
- {
- if (cp->SendHdrAnswer(cp->outerSocket, ans_ok) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
-
- if (cp->RecvLogin(cp->outerSocket) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
-
- if (cp->state == confLoginCipher)
- {
- if (cp->SendLoginAnswer(cp->outerSocket, ans_ok) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
- if (cp->RecvLoginS(cp->outerSocket) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
-
- if (cp->state == confData)
- {
- if (cp->SendLoginSAnswer(cp->outerSocket, ans_ok) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
- if (cp->RecvData(cp->outerSocket) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
- cp->state = confHdr;
- }
- else
- {
- if (cp->SendLoginSAnswer(cp->outerSocket, ans_err) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
- cp->WriteLogAccessFailed(cp->adminIP);
- }
- }
- else
- {
- cp->WriteLogAccessFailed(cp->adminIP);
- }
- }
- else
- {
- cp->WriteLogAccessFailed(cp->adminIP);
- if (cp->SendHdrAnswer(cp->outerSocket, ans_err) < 0)
- {
- close(cp->outerSocket);
- continue;
- }
- }
- }
- else
- {
- cp->WriteLogAccessFailed(cp->adminIP);
- }
- close(cp->outerSocket);
- }
-
-return NULL;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::RecvHdr(int sock)
-{
-char buf[sizeof(STG_HEADER)];
-memset(buf, 0, sizeof(STG_HEADER));
-int ret;
-int stgHdrLen = strlen(STG_HEADER);
-for (int i = 0; i < stgHdrLen; i++)
- {
- ret = recv(sock, &buf[i], 1, 0);
- if (ret <= 0)
- {
- state = confHdr;
- return -1;
- }
- }
-
-if (0 == strncmp(buf, STG_HEADER, strlen(STG_HEADER)))
- {
- state = confLogin;
- return 0;
- }
-else
- {
- SendError("Bad request");
- }
-
-state = confHdr;
-return -1;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::SendHdrAnswer(int sock, int err)
-{
-int ret;
-
-if (err)
- {
- ret = send(sock, ERR_HEADER, sizeof(ERR_HEADER)-1, 0);
- if (ret < 0)
- {
- WriteServLog("send ERR_HEADER error in SendHdrAnswer.");
- return -1;
- }
- }
-else
- {
- ret = send(sock, OK_HEADER, sizeof(OK_HEADER)-1, 0);
- if (ret < 0)
- {
- WriteServLog("send OK_HEADER error in SendHdrAnswer.");
- return -1;
- }
- }
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::RecvLogin(int sock)
-{
-char login[ADM_LOGIN_LEN+1];
-int ret;
-
-memset(login, 0, ADM_LOGIN_LEN + 1);
-
-//printfd(__FILE__, "RecvLogin\n");
-
-/*for (int i = 0; i < ADM_LOGIN_LEN; i++)
- {
- ret = recv(sock, &login[i], 1, 0);
-
- if (ret <= 0)
- {
- close(sock);
- state = confHdr;
- return ENODATA;
- }
- }*/
-
-ret = recv(sock, login, ADM_LOGIN_LEN, 0);
-
-if (ret < 0)
- {
- // Error in network
- close(sock);
- state = confHdr;
- return ENODATA;
- }
-
-if (ret < ADM_LOGIN_LEN)
- {
- // Error in protocol
- close(sock);
- state = confHdr;
- return ENODATA;
- }
-
-currAdmin = admins->FindAdmin(login);
-adminLogin = login;
-state = confLoginCipher;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::SendLoginAnswer(int sock, int)
-{
-int ret;
-
-ret = send(sock, OK_LOGIN, sizeof(OK_LOGIN)-1, 0);
-if (ret < 0)
- {
- WriteServLog("Send OK_LOGIN error in SendLoginAnswer.");
- return -1;
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::RecvLoginS(int sock)
-{
-char loginS[ADM_LOGIN_LEN + 1];
-char login[ADM_LOGIN_LEN + 1];
-int ret;
-BLOWFISH_CTX ctx;
-memset(loginS, 0, ADM_LOGIN_LEN + 1);
-
-//printfd(__FILE__, "RecvLoginS\n");
-
-/*for (int i = 0; i < ADM_LOGIN_LEN; i++)
- {
- ret = recv(sock, &loginS[i], 1, 0);
-
- if (ret <= 0)
- {
- //printfd(__FILE__, "RecvLoginS close\n");
- close(sock);
- state = confHdr;
- return ENODATA;
- }
- }*/
-
-int total = 0;
-
-while (total < ADM_LOGIN_LEN)
- {
- ret = recv(sock, &loginS[total], ADM_LOGIN_LEN - total, 0);
-
- if (ret < 0)
- {
- // Network error
- printfd(__FILE__, "recv error: '%s'\n", strerror(errno));
- close(sock);
- state = confHdr;
- return ENODATA;
- }
-
- total += ret;
- }
-
-// TODO: implement select on socket
-/*if (total < ADM_LOGIN_LEN)
- {
- // Protocol error
- printfd(__FILE__, "Protocol error. Need %d bytes of cryptologin. Got %d bytes.\n", ADM_LOGIN_LEN, ret);
- close(sock);
- state = confHdr;
- return ENODATA;
- }*/
-
-if (currAdmin == NULL)
- {
- state = confHdr;
- return ENODATA;
- }
-
-EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
-
-for (int i = 0; i < ADM_LOGIN_LEN/8; i++)
- {
- DecodeString(login + i*8, loginS + i*8, &ctx);
- }
-
-if (currAdmin == admins->GetNoAdmin())
- {
- // If there are no admins registered in the system - give access with any password
- state = confData;
- return 0;
- }
-
-if (strncmp(currAdmin->GetLogin().c_str(), login, ADM_LOGIN_LEN) != 0)
- {
- state = confHdr;
- return ENODATA;
- }
-
-state = confData;
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::SendLoginSAnswer(int sock, int err)
-{
-int ret;
-
-if (err)
- {
- ret = send(sock, ERR_LOGINS, sizeof(ERR_LOGINS)-1, 0);
- if (ret < 0)
- {
- WriteServLog("send ERR_LOGIN error in SendLoginAnswer.");
- return -1;
- }
- }
-else
- {
- ret = send(sock, OK_LOGINS, sizeof(OK_LOGINS)-1, 0);
- if (ret < 0)
- {
- WriteServLog("send OK_LOGINS error in SendLoginSAnswer.");
- return -1;
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::RecvData(int sock)
-{
-//printfd(__FILE__, "RecvData\n");
-int n = 0;
-int ret;
-char bufferS[8];
-char buffer[9];
-
-buffer[8] = 0;
-
-requestList.clear();
-BLOWFISH_CTX ctx;
-
-EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
-
-while (1)
- {
- /*ret = recv(sock, &bufferS[n++], 1, 0);
- if (ret <= 0)
- {
- //printfd(__FILE__, "RecvData close\n");
- close(sock);
- return 0;
- }*/
- int total = 0;
- bool done = false;
- while (total < 8)
- {
- ret = recv(sock, &bufferS[total], 8 - total, 0);
- if (ret < 0)
- {
- // Network error
- close(sock);
- return 0;
- }
-
- if (ret < 8)
- {
- if (memchr(buffer, 0, ret) != NULL)
- {
- done = true;
- break;
- }
- }
-
- total += ret;
- }
-
- DecodeString(buffer, bufferS, &ctx);
- requestList.push_back(std::string(buffer, total));
-
- if (done || memchr(buffer, 0, total) != NULL)
- {
- // ëÏÎÅà ÐÏÓÙÌËÉ
- if (ParseCommand())
- {
- SendError("Bad command");
- }
- return SendDataAnswer(sock);
- }
-
- /*if (n == 8)
- {
- n = 0;
- DecodeString(buffer, bufferS, &ctx);
- requestList.push_back(std::string(buffer, 8));
- for (int j = 0; j < 8; j++)
- {
- if (buffer[j] == 0)
- {
- // ëÏÎÅà ÐÏÓÙÌËÉ
- if (ParseCommand())
- {
- SendError("Bad command");
- }
- return SendDataAnswer(sock);
- }
- }
- }*/
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-int CONFIGPROTO::SendDataAnswer(int sock)
-{
-list<string>::iterator li;
-li = answerList.begin();
-
-BLOWFISH_CTX ctx;
-
-char buff[8];
-char buffS[8];
-int n = 0;
-int k = 0;
-int ret = 0;
-
-EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
-
-while (li != answerList.end())
- {
- while ((*li).c_str()[k])
- {
- buff[n%8] = (*li).c_str()[k];
- n++;
- k++;
-
- if (n%8 == 0)
- {
- EncodeString(buffS, buff, &ctx);
- ret = send(sock, buffS, 8, 0);
- if (ret < 0)
- {
- return -1;
- }
- }
- }
- k = 0;// new node
- li++;
- }
-
-if (answerList.empty()) {
- return 0;
-}
-
-buff[n%8] = 0;
-EncodeString(buffS, buff, &ctx);
-
-answerList.clear();
-
-return send(sock, buffS, 8, 0);
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::SendError(const char * text)
-{
-char s[255];
-answerList.clear();
-sprintf(s, "<Error value=\"%s\"/>", text);
-answerList.push_back(s);
-}
-//-----------------------------------------------------------------------------
-void CONFIGPROTO::WriteLogAccessFailed(uint32_t ip)
-{
-WriteServLog("Admin's connect failed. IP %s", inet_ntostring(ip).c_str());
-}
-//-----------------------------------------------------------------------------
-
-
-
+++ /dev/null
-#include <cstdio>
-#include <cunistd>
-#include <csignal>
-#include <functional>
-#include <algorithm>
-
-#include "stg/plugin_creator.h"
-#include "stgconfig.h"
-#include "../../../tariffs.h"
-#include "../../../admins.h"
-#include "../../../users.h"
-
-PLUGIN_CREATOR<STG_CONFIG> stgc;
-
-BASE_PLUGIN * GetPlugin()
-{
-return stgc.GetPlugin();
-}
-
-STG_CONFIG_SETTINGS::STG_CONFIG_SETTINGS()
- : port(0)
-{
-}
-
-const string& STG_CONFIG_SETTINGS::GetStrError() const
-{
-return errorStr;
-}
-
-int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
-{
-int p;
-PARAM_VALUE pv;
-vector<PARAM_VALUE>::const_iterator pvi;
-///////////////////////////
-pv.param = "Port";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
- {
- errorStr = "Parameter \'Port\' not found.";
- printfd(__FILE__, "Parameter 'Port' not found\n");
- return -1;
- }
-if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
- {
- errorStr = "Cannot parse parameter \'Port\': " + errorStr;
- printfd(__FILE__, "%s\n", errorStr.c_str());
- return -1;
- }
-port = p;
-
-return 0;
-}
-
-uint16_t STG_CONFIG_SETTINGS::GetPort()
-{
-return port;
-}
-
-STG_CONFIG::STG_CONFIG()
- : running(false),
- stopped(true)
-{
-}
-
-string STG_CONFIG::GetVersion() const
-{
-return "Stg configurator v.2.00";
-}
-
-int STG_CONFIG::ParseSettings()
-{
-int ret = stgConfigSettings.ParseSettings(settings);
-if (ret)
- errorStr = stgConfigSettings.GetStrError();
-return ret;
-}
-
-int STG_CONFIG::Start()
-{
-if (running)
- return false;
-
-if (PrepareNetwork())
- return true;
-
-stopped = false;
-
-config.SetPort(stgConfigSettings.GetPort());
-config.SetAdmins(admins);
-config.SetUsers(users);
-config.SetTariffs(tariffs);
-config.SetStgSettings(stgSettings);
-config.SetStore(store);
-
-if (config.Prepare())
- {
- errorStr = config.GetStrError();
- return true;
- }
-
-if (pthread_create(&thread, NULL, Run, this))
- {
- errorStr = "Cannot create thread.";
- printfd(__FILE__, "Cannot create thread\n");
- return true;
- }
-
-errorStr = "";
-return false;
-}
-
-int STG_CONFIG::Stop()
-{
-if (!running)
- return false;
-
-running = false;
-
-config.Stop();
-
-//5 seconds to thread stops itself
-int i;
-for (i = 0; i < 25 && !stopped; i++)
- {
- usleep(200000);
- }
-
-//after 5 seconds waiting thread still running. now killing it
-if (!stopped)
- {
- //TODO pthread_cancel()
- if (pthread_kill(thread, SIGINT))
- {
- errorStr = "Cannot kill thread.";
- printfd(__FILE__, "Cannot kill thread\n");
- return FinalizeNetwork();
- }
- printfd(__FILE__, "STG_CONFIG killed\n");
- }
-
-return FinalizeNetwork();
-}
-
-void * STG_CONFIG::Run(void * d)
-{
-STG_CONFIG * stgConf = static_cast<STG_CONFIG *>(d);
-stgConf->running = true;
-
-stgConf->RealRun();
-
-stgConf->stopped = true;
-return NULL;
-}
-
-uint16_t STG_CONFIG::GetStartPosition() const
-{
-return 20;
-}
-
-uint16_t STG_CONFIG::GetStopPosition() const
-{
-return 20;
-}
-
-bool PrepareNetwork()
-{
-struct sockaddr_in local;
-
-local.sin_family = AF_INET;
-local.sin_port = htons(port);
-local.sin_addr.s_addr = INADDR_ANY;
-
-sd = socket(AF_INET, SOCK_STREAM, 0);
-if (sd < 0)
- {
- errorStr = "Error creating socket: '";
- errorStr += strerror(errno);
- errorStr += "'";
- return true;
- }
-
-if (bind(sd, static_cast<struct sockaddr *>(&local), sizeof(local)) < 0)
- {
- errorStr = "Error binding socket: '";
- errorStr += strerror(errno);
- errorStr += "'";
- return true;
- }
-
-return false;
-}
-
-bool FinalizeNetwork()
-{
-if (close(sd) < 0)
- {
- errorStr = "Error closing socket: '";
- errorStr += strerror(errno);
- errorStr += "'";
- return true;
- }
-return false;
-}
-
-void STG_CONFIG::RealRun()
-{
-if (listen(sd, 64) < 0)
- {
- errorStr = "Error listening socket: '";
- errorStr += strerror(errno);
- errorStr += "'";
- return;
- }
-
-fd_set rfds;
-
-FD_ZERO(&rfds);
-FD_SET(sd, &rfds);
-
-running = true;
-while (running)
- {
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 500000;
-
- int res = select(sd + 1, &rfds, NULL, NULL, &tv);
-
- if (res < 0)
- {
- // Error logging
- }
- else if (res == 0)
- {
- // Timeout
- }
- else
- {
- if (FD_ISSET(sd, &rfds))
- {
- AcceptConnection();
- }
- }
-
- // Reorder: right part is done
- std::list<ConnectionThread *>::iterator done(
- std::remove_if(
- connections.begin(),
- connections.end(),
- std::not1(std::mem_fun(&ConnectionThread::isDone))
- )
- );
- // Destruct done
- std::for_each(
- done,
- connections.end(),
- DeleteConnection());
- // Erase done
- std::erase(done, connections.end());
-
- }
-stopped = true;
-}
-
-void STG_CONFIG::AcceptConnection()
-{
-struct sockaddr_in remoteAddr;
-socklen_t len = sizeof(struct sockaddr_in);
-int rsd = accept(sd, &remoteAddr, &len);
-
-if (rsd < 0)
- {
- // Error logging
- }
-
-connections.push_back(new ConnectionThread(this, rsd, remoteAddr, users, admins, tariffs, store, stgSettings));
-}
+++ /dev/null
-#include <pthread.h>
-
-#include <string>
-#include <list>
-
-#include "plugin.h"
-#include "store.h"
-#include "configproto.h"
-
-using namespace std;
-
-extern "C" PLUGIN * GetPlugin();
-
-class STG_CONFIG;
-
-//-----------------------------------------------------------------------------
-class STG_CONFIG_SETTINGS {
-public:
- STG_CONFIG_SETTINGS();
- virtual ~STG_CONFIG_SETTINGS() {}
- const string & GetStrError() const;
- int ParseSettings(const MODULE_SETTINGS & s);
- uint16_t GetPort();
-private:
- string errorStr;
- int port;
-};
-//-----------------------------------------------------------------------------
-class STG_CONFIG: public PLUGIN {
-public:
- STG_CONFIG();
- virtual ~STG_CONFIG() {}
-
- void SetUsers(USERS * u) { users = u; }
- void SetTariffs(TARIFFS * t) { tariffs = t; }
- void SetAdmins(ADMINS * a) { admins = a; }
- void SetStore(STORE * s) { store = s; }
- void SetStgSettings(const SETTINGS * s) { stgConfigSettings = s; }
- void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
- int ParseSettings();
-
- int Start();
- int Stop();
- int Reload() { return 0; }
- bool IsRunning() { return running; }
-
- const string & GetStrError() const { return errorStr; }
- string GetVersion() const;
- uint16_t GetStartPosition() const;
- uint16_t GetStopPosition() const;
-
-private:
- static void * Run(void *);
- void RealRun();
- bool PrepareNetwork();
- bool FinalizeNetwork();
- void AcceptConnection();
-
- mutable string errorStr;
- STG_CONFIG_SETTINGS stgConfigSettings;
- pthread_t thread;
- bool running;
- bool stopped;
- CONFIGPROTO config;
- USERS * users;
- ADMINS * admins;
- TARIFFS * tariffs;
- STORE * store;
- MODULE_SETTINGS settings;
- const SETTINGS * stgSettings;
-
- std::list<ConnectionThread *> connections;
-
- int sd;
-};
-//-----------------------------------------------------------------------------
+++ /dev/null
-###############################################################################
-# $Id: Makefile,v 1.3 2009/03/03 15:49:35 faust Exp $
-###############################################################################
-DEFS = -DLINUX
-
-ifeq ($(OS),bsd)
-DEFS = -DFREE_BSD
-endif
-
-ifeq ($(OS),bsd5)
-DEFS = -DFREE_BSD5
-endif
-
-
-DIR_INCLUDE = ../../../../../include
-DIR_LIB = ../../../../../lib
-
-PROG = mod_conf_xr.so
-
-SRCS = ./xrconfig.cpp
-
-
-LIBS = $(LIB_THREAD)
-
-SEARCH_DIRS = -I $(DIR_INCLUDE)
-
-OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS))))
-
-CXXFLAGS = -g3 -Wall -fPIC
-LDFLAGS = -g3 -shared
-
-
-vpath %.a $(DIR_LIB)
-
-
-all: $(PROG)
-
-$(PROG): $(OBJS) $(LIBS)
- $(CC) $^ $(LDFLAGS) -o $(PROG)
-
-clean:
- rm -f deps $(PROG) *.o tags *.*~
-
-
-install:
- echo TODO
-
-uninstall:
- echo TODO
-
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(MAKECMDGOALS),uninstall)
-include deps
-endif
-endif
-
-deps: $(SRCS)
- @>deps ;\
- for file in $(SRCS); do\
- echo "`$(CC) $(CXXFLAGS) $(DEFS) $(SEARCH_DIRS) -MM $$file` Makefile" >> deps ;\
- echo -e '\t$$(CC) -c $$< $(CXXFLAGS) $(SEARCH_DIRS) $(DEFS)' >> deps ;\
- done
-
-
+++ /dev/null
-#include <stdio.h>
-#include <unistd.h>
-#include <signal.h>
-
-#include "stg/plugin_creator.h"
-#include "xrconfig.h"
-#include "../../../tariff2.h"
-#include "../../../admins.h"
-#include "../../../users.h"
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PLUGIN_CREATOR<XR_CONFIG> xrc;
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
-{
-return xrc.GetPlugin();
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-XR_CONFIG_SETTINGS::XR_CONFIG_SETTINGS()
- : port(0)
-{
-}
-//-----------------------------------------------------------------------------
-const string & XR_CONFIG_SETTINGS::GetStrError() const
-{
-return errorStr;
-}
-//-----------------------------------------------------------------------------
-int XR_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
-{
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-uint16_t XR_CONFIG_SETTINGS::GetPort()
-{
-return port;
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-const string XR_CONFIG::GetVersion() const
-{
-return "XR_configurator v.0.01";
-}
-//-----------------------------------------------------------------------------
-XR_CONFIG::XR_CONFIG()
-{
-isRunning = false;
-nonstop = false;
-}
-//-----------------------------------------------------------------------------
-void XR_CONFIG::SetUsers(USERS * u)
-{
-users = u;
-}
-//-----------------------------------------------------------------------------
-void XR_CONFIG::SetTariffs(TARIFFS * t)
-{
-tariffs = t;
-}
-//-----------------------------------------------------------------------------
-void XR_CONFIG::SetAdmins(ADMINS * a)
-{
-admins = a;
-}
-//-----------------------------------------------------------------------------
-void XR_CONFIG::SetStore(BASE_STORE * s)
-{
-store = s;
-}
-//-----------------------------------------------------------------------------
-void XR_CONFIG::SetStgSettings(const SETTINGS * s)
-{
-stgSettings = s;
-}
-//-----------------------------------------------------------------------------
-void XR_CONFIG::SetSettings(const MODULE_SETTINGS & s)
-{
-settings = s;
-}
-//-----------------------------------------------------------------------------
-int XR_CONFIG::ParseSettings()
-{
-int ret = xrConfigSettings.ParseSettings(settings);
-if (ret)
- errorStr = xrConfigSettings.GetStrError();
-return ret;
-}
-//-----------------------------------------------------------------------------
-const string & XR_CONFIG::GetStrError() const
-{
-return errorStr;
-}
-//-----------------------------------------------------------------------------
-int XR_CONFIG::Start()
-{
-if (isRunning)
- return 0;
-
-nonstop = true;
-
-config.SetPort(xrConfigSettings.GetPort());
-config.SetAdmins(admins);
-config.SetUsers(users);
-config.SetTariffs(tariffs);
-config.SetStgSettings(stgSettings);
-config.SetStore(store);
-
-if (config.Prepare())
- {
- errorStr = config.GetStrError();
- return -1;
- }
-
-if (pthread_create(&thread, NULL, Run, this))
- {
- errorStr = "Cannot create thread.";
- printfd(__FILE__, "Cannot create thread\n");
- return -1;
- }
-errorStr = "";
-return 0;
-}
-//-----------------------------------------------------------------------------
-int XR_CONFIG::Stop()
-{
-if (!isRunning)
- return 0;
-
-config.Stop();
-
-//5 seconds to thread stops itself
-int i;
-for (i = 0; i < 25; i++)
- {
- if (!isRunning)
- break;
-
- stgUsleep(200000);
- }
-
-//after 5 seconds waiting thread still running. now killing it
-if (isRunning)
- {
- //TODO pthread_cancel()
- if (pthread_kill(thread, SIGINT))
- {
- errorStr = "Cannot kill thread.";
- printfd(__FILE__, "Cannot kill thread\n");
- return -1;
- }
- printfd(__FILE__, "XR_CONFIG killed\n");
- }
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-bool XR_CONFIG::IsRunning()
-{
-return isRunning;
-}
-//-----------------------------------------------------------------------------
-void * XR_CONFIG::Run(void * d)
-{
-XR_CONFIG * stgConf = (XR_CONFIG *)d;
-stgConf->isRunning = true;
-
-stgConf->config.Run(&stgConf->config);
-
-stgConf->isRunning = false;
-return NULL;
-}
-//-----------------------------------------------------------------------------
-uint16_t XR_CONFIG::GetStartPosition() const
-{
-return 20;
-}
-//-----------------------------------------------------------------------------
-uint16_t XR_CONFIG::GetStopPosition() const
-{
-return 20;
-}
-//-----------------------------------------------------------------------------
-int XR_CONFIG::SetUserCash(const string & admLogin, const string & usrLogin, double cash) const
-{
-return 0;
-}
-//-----------------------------------------------------------------------------
-
+++ /dev/null
-#include <string>
-#include <pthread.h>
-#include "base_plugin.h"
-#include "common.h"
-
-using namespace std;
-
-extern "C" BASE_PLUGIN * GetPlugin();
-
-class STG_CONFIG;
-
-//-----------------------------------------------------------------------------
-class XR_CONFIG_SETTINGS
-{
-public:
- XR_CONFIG_SETTINGS();
- virtual ~XR_CONFIG_SETTINGS(){};
- const string & GetStrError() const;
- int ParseSettings(const MODULE_SETTINGS & s);
- uint16_t GetPort();
-
-private:
- string errorStr;
- int port;
-};
-//-----------------------------------------------------------------------------
-class XR_CONFIG :public BASE_PLUGIN
-{
-public:
- XR_CONFIG();
- virtual ~XR_CONFIG(){};
-
- void SetUsers(USERS * u);
- void SetTariffs(TARIFFS * t);
- void SetAdmins(ADMINS * a);
- void SetStore(BASE_STORE * s);
- void SetStgSettings(const SETTINGS * s);
- void SetSettings(const MODULE_SETTINGS & s);
- int ParseSettings();
-
- int Start();
- int Stop();
- int Reload() { return 0; };
- bool IsRunning();
-
- const string & GetStrError() const;
- const string GetVersion() const;
- uint16_t GetStartPosition() const;
- uint16_t GetStopPosition() const;
-
-private:
-
-
- int SetUserCash(const string & admLogin, const string & usrLogin, double cash) const;
-
- static void * Run(void *);
- mutable string errorStr;
- XR_CONFIG_SETTINGS xrConfigSettings;
- pthread_t thread;
- bool nonstop;
- bool isRunning;
-
- //CONFIGPROTO config;
-
- USERS * users;
- ADMINS * admins;
- TARIFFS * tariffs;
- BASE_STORE * store;
- MODULE_SETTINGS settings;
- const SETTINGS * stgSettings;
-};
-//-----------------------------------------------------------------------------
-
-
+++ /dev/null
-###############################################################################
-# $Id: Makefile,v 1.4 2007/09/26 14:07:28 faust Exp $
-###############################################################################
-
-include ../../../../../Makefile.conf
-
-LIBS += -lexpat
-
-ifeq ($(OS),linux)
-LIBS += -lpthread
-endif
-
-ifeq ($(OS),bsd)
-LIBS += -lc_r
-endif
-
-ifeq ($(OS),bsd5)
-LIBS += -lc_r
-endif
-
-PROG = mod_userstat.so
-
-SRCS = ./userstat.cpp \
- ./datathread.cpp
-
-LIBS += -lstgcommon \
- -lstgcrypto
-
-include ../../Makefile.in
-
+++ /dev/null
-#include "datathread.h"
-
-DataThread::DataThread()
- : tid(-1),
- users(NULL),
- store(NULL),
- sock(-1),
- done(true),
- pvList(NULL),
- data(NULL),
- dataSize(0)
-{
-xmlParser = XML_ParserCreate(NULL);
-if (!xmlParser)
- {
- printfd(__FILE__, "DataThread::DataThread() Failed to create parser\n");
- return;
- }
-XML_SetElementHandler(xmlParser, DTXMLStart, DTXMLEnd);
-}
-
-DataThread::~DataThread()
-{
-XML_ParserFree(xmlParser);
-}
-
-bool DataThread::Handle(int s)
-{
-if (users == NULL)
- {
- printfd(__FILE__, "DataThread::Handle() Users not set\n");
- return false;
- }
-if (store == NULL)
- {
- printfd(__FILE__, "DataThread::Handle() Storage not set\n");
- return false;
- }
-
-sock = s;
-
-if (pthread_create(&tid, NULL, Run, this))
- {
- printfd(__FILE__, "DataThread::Handle() Failed to create thread\n");
- return false;
- }
-if (pthread_detach(tid))
- {
- printfd(__FILE__, "DataThread::Handle() Cannot detach the thread\n");
- }
-return true;
-}
-
-void * DataThread::Run(void * self)
-{
-DataThread * dt = reinterpret_cast<DataThread *>(self);
-
-dt->done = false;
-
-if (dt->ReadRequest())
- {
- if (dt->DecodeRequest())
- {
- if (dt->ParseRequest())
- {
- if (dt->MakeAnswer())
- {
- printfd(__FILE__, "DataThread::Run() All done\n");
- }
- else
- {
- printfd(__FILE__, "DataThread::Run() Failed to answer the request\n");
- }
- }
- else
- {
- printfd(__FILE__, "DataThread::Run() Cannot parse the request\n");
- }
- }
- else
- {
- printfd(__FILE__, "DataThread::Run() Cannot decode the request\n");
- }
- }
-else
- {
- printfd(__FILE__, "DataThread::Run() Cannot read the request\n");
- }
-
-dt->Cleanup();
-
-return NULL;
-}
-
-bool DataThread::ReadRequest()
-{
-int32_t size;
-char * buf;
-
-int res = read(sock, &size, sizeof(size));
-if (res != sizeof(size))
- {
- printfd(__FILE__, "DataThread::ReadRequest() Reading login size failed! Wanted %d bytes, got %d bytes.\n", sizeof(size), res);
- done = true;
- return false;
- }
-
-if (size < 0)
- {
- printfd(__FILE__, "DataThread::ReadRequest() Invalid login size.\n");
- done = true;
- return false;
- }
-
-buf = new char[size];
-
-res = read(sock, buf, size);
-if (res != size)
- {
- printfd(__FILE__, "DataThread::ReadRequest() Reading login failed! Wanted %d bytes, got %d bytes.\n", size, res);
- delete[] buf;
- done = true;
- return false;
- }
-
-login.assign(buf, size);
-delete[] buf;
-
-res = read(sock, &size, sizeof(size));
-if (res != sizeof(size))
- {
- printfd(__FILE__, "DataThread::ReadRequest() Reading request size failed! Wanted %d bytes, got %d bytes.\n", sizeof(size), res);
- done = true;
- return false;
- }
-
-if (size < 0)
- {
- printfd(__FILE__, "DataThread::ReadRequest() Invalid request size.\n");
- done = true;
- return false;
- }
-
-data = new char[size + 1];
-dataSize = size;
-
-res = read(sock, data, size);
-if (res != size)
- {
- printfd(__FILE__, "DataThread::ReadRequest() Reading request failed! Wanted %d bytes, got %d bytes.\n", size, res);
- done = true;
- return false;
- }
-data[res] = 0;
-
-return true;
-}
-
-bool DataThread::DecodeRequest()
-{
-if (users->FindByName(login, &(uit)))
- {
- printfd(__FILE__, "DataThread::DecodeRequest() User '%s' not found.\n", login.c_str());
- done = true;
- return false;
- }
-
-std::string password = uit->property.password;
-
-BLOWFISH_CTX ctx;
-char * key = new char[password.length()];
-strncpy(key, password.c_str(), password.length());
-
-Blowfish_Init(&ctx,
- reinterpret_cast<unsigned char *>(key),
- password.length());
-
-for (int i = 0; i < dataSize / 8; ++i)
- {
- uint32_t a;
- uint32_t b;
- a = n2l(reinterpret_cast<unsigned char *>(data + i * 8));
- b = n2l(reinterpret_cast<unsigned char *>(data + i * 8 + 4));
- Blowfish_Decrypt(&ctx,
- &a,
- &b);
- l2n(a, reinterpret_cast<unsigned char *>(data + i * 8));
- l2n(b, reinterpret_cast<unsigned char *>(data + i * 8 + 4));
- }
-
-delete[] key;
-
-return true;
-}
-
-bool DataThread::ParseRequest()
-{
-if (XML_Parse(xmlParser, data, dataSize, 1) != XML_STATUS_OK)
- {
- printfd(__FILE__, "DataThread::ParseRequest() Failed to parse the request\n");
- request.isBad = true;
- return false;
- }
-return true;
-}
-
-bool DataThread::MakeAnswer()
-{
-if (MakeConf())
- {
- if (MakeStat())
- {
- if (SendAnswer())
- {
- // All is ok
- }
- else
- {
- printfd(__FILE__, "DataThread::MakeAnswer() Failed to send answer");
- return false;
- }
- }
- else
- {
- printfd(__FILE__, "DataThread::MakeAnswer() Failed to make stat answer\n");
- return false;
- }
- }
-else
- {
- printfd(__FILE__, "DataThread::MakeAnswer() Failed to make conf answer\n");
- return false;
- }
-
-return true;
-}
-
-void DataThread::Cleanup()
-{
-delete[] data;
-dataSize = 0;
-login = "";
-done = false;
-data = NULL;
-request.conf.erase(request.conf.begin(), request.conf.end());
-request.stat.erase(request.stat.begin(), request.stat.end());
-request.login = "";
-request.isOk = true;
-request.isBad = false;
-}
-
-void DataThread::ParseTag(const std::string & name, const char ** attr)
-{
-if (request.isBad)
- return;
-if (name == "request")
- {
- if (attr == NULL)
- {
- printfd(__FILE__, "DataThread::ParseTag() 'request' tag require an attribute\n");
- request.isBad = true;
- return;
- }
- else
- {
- std::string attrName(*attr++);
- std::string attrValue(*attr++);
- if (attr != NULL)
- {
- printfd(__FILE__, "DataThread::ParseTag() Extra attributes on tag 'request'\n");
- }
- if (attrName == "login")
- {
- if (attrValue != login)
- {
- printfd(__FILE__, "DataThread::ParseTag() Logins doesn't match\n");
- request.isBad = true;
- return;
- }
- }
- else
- {
- printfd(__FILE__, "DataThread::ParseTag() Unexpected attribute '%s'\n", attrName.c_str());
- request.isBad = true;
- return;
- }
- }
- }
-else if (name == "conf")
- {
- pvList = &(request.conf);
- }
-else if (name == "stat")
- {
- pvList = &(request.stat);
- }
-else
- {
- (*pvList)[name];
- }
-}
-
-bool DataThread::MakeConf()
-{
-return false;
-}
-
-bool DataThread::MakeStat()
-{
-return false;
-}
-
-bool DataThread::SendAnswer()
-{
-return false;
-}
-
-void DTXMLStart(void * data, const char * name, const char ** attr)
-{
-DataThread * dt = reinterpret_cast<DataThread *>(data);
-dt->ParseTag(name, attr);
-}
-
-void DTXMLEnd(void * data, const char * name)
-{
-//DataThread * dt = reinterpret_cast<DataThread *>(data);
-}
+++ /dev/null
-#ifndef __DATATHREAD_H__
-#define __DATATHREAD_H__
-
-#include <map>
-#include <string>
-
-#include <expat.h>
-#include <pthread.h>
-
-#include "common.h"
-#include "../../../users.h"
-
-uint32_t n2l(unsigned char * c)
-{
- uint32_t t = *c++ << 24;
- t += *c++ << 16;
- t += *c++ << 8;
- t += *c;
- return t;
-}
-
-void l2n(uint32_t t, unsigned char * c)
-{
- *c++ = t >> 24 & 0x000000FF;
- *c++ = t >> 16 & 0x000000FF;
- *c++ = t >> 8 & 0x000000FF;
- *c++ = t & 0x000000FF;
-}
-
-typedef std::map<std::string, std::string> PV_LIST;
-
-class DataThread {
-public:
- DataThread();
- ~DataThread();
-
- void SetUsers(USERS * u) { users = u; };
- void SetStore(BASE_STORE * s) { store = s; };
-
- bool isDone() const { return done; };
-
- bool Handle(int s);
-
- friend void DTXMLStart(void * data, const char * name, const char ** attr);
- friend void DTXMLEnd(void * data, const char * name);
-private:
- pthread_t tid;
- USERS * users;
- BASE_STORE * store;
- int sock;
- bool done;
- struct Request {
- PV_LIST conf;
- PV_LIST stat;
- std::string login;
- bool isOk;
- bool isBad;
- } request;
- PV_LIST * pvList;
- char * data;
- int32_t dataSize;
-
- std::string login;
- user_iter uit;
-
- XML_Parser xmlParser;
-
- static void * Run(void * self);
-
- bool ReadRequest();
- bool DecodeRequest();
- bool ParseRequest();
- bool MakeAnswer();
-
- bool MakeConf();
- bool MakeStat();
- bool SendAnswer();
-
- void Cleanup();
-
- void ParseTag(const std::string & name, const char ** attr);
-};
-
-void DTXMLStart(void * data, const char * name, const char ** attr);
-void DTXMLEnd(void * data, const char * name);
-
-#endif
+++ /dev/null
-#include <algorithm>
-#include <cstring>
-#include <cerrno>
-#include <arpa/inet.h>
-#include <csignal>
-
-#include "common.h"
-#include "../../../users.h"
-
-#include "userstat.h"
-
-BASE_PLUGIN * GetPlugin()
-{
-return new USERSTAT();
-}
-
-USERSTAT::USERSTAT()
- : isRunning(false),
- nonstop(false),
- errorStr(""),
- version(USTAT_VERSION),
- listenSocket(-1),
- maxThreads(16),
- port(5555),
- thread(0),
- users(NULL),
- store(NULL)
-{
-pthread_mutex_init(&mutex, NULL);
-}
-
-USERSTAT::~USERSTAT()
-{
-}
-
-int USERSTAT::ParseSettings()
-{
-vector<PARAM_VALUE>::iterator i;
-string s;
-
-for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
- {
- s = i->param;
- transform(s.begin(), s.end(), s.begin(), USERSTAT::ToLower());
- if (s == "port")
- {
- if (str2x<uint16_t>(*(i->value.begin()), port))
- {
- errorStr = "'Port' parameter must be a numeric value";
- printfd(__FILE__, "USERSTAT::ParseSettings() %s\n", errorStr.c_str());
- return -1;
- }
- }
- if (s == "maxthreads")
- {
- if (str2x<unsigned>(*(i->value.begin()), maxThreads))
- {
- errorStr = "'MaxThreads' parameter must be a numeric value";
- printfd(__FILE__, "USERSTAT::ParseSettings() %s\n", errorStr.c_str());
- return -1;
- }
- }
- }
-
-return 0;
-}
-
-int USERSTAT::Prepare()
-{
-listenSocket = socket(PF_INET, SOCK_STREAM, 0);
-
-if (listenSocket < 0)
- {
- errorStr = "Create USERSTAT socket failed.";
- printfd(__FILE__, "USERSTAT::Prepare() %s\n", errorStr.c_str());
- return -1;
- }
-
-printfd(__FILE__, "USERSTAT::Prepare() socket - ok\n");
-
-listenAddr.sin_family = PF_INET;
-listenAddr.sin_port = htons(port);
-listenAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
-
-int lng = 1;
-
-if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4))
- {
- errorStr = "Setsockopt failed. " + string(strerror(errno));
- printfd(__FILE__, "USERSTAT::Prepare() %s\n", errorStr.c_str());
- return -1;
- }
-
-printfd(__FILE__, "USERSTAT::Prepare() setsockopt - ok\n");
-
-int res = bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr));
-
-if (res == -1)
- {
- errorStr = "Bind USERSTAT socket failed";
- printfd(__FILE__, "USERSTAT::Prepare() %s\n", errorStr.c_str());
- return -1;
- }
-
-printfd(__FILE__, "USERSTAT::Prepare() bind - ok port: %d\n", port);
-
-res = listen(listenSocket, 0);
-if (res == -1)
- {
- errorStr = "Listen USERSTAT socket failed";
- printfd(__FILE__, "USERSTAT::Prepare() %s\n", errorStr.c_str());
- return -1;
- }
-printfd(__FILE__, "USERSTAT::Prepare() listen - ok\n");
-
-errorStr = "";
-return 0;
-}
-
-int USERSTAT::Finalize()
-{
-return close(listenSocket);
-}
-
-int USERSTAT::Start()
-{
-if (users == NULL) {
- errorStr = "Users must be set";
- printfd(__FILE__, "USERSTAT::Start() %s\n", errorStr.c_str());
- return -1;
-}
-if (store == NULL) {
- errorStr = "Store must be set";
- printfd(__FILE__, "USERSTAT::Start() %s\n", errorStr.c_str());
- return -1;
-}
-if (Prepare())
- {
- return -1;
- }
-nonstop = true;
-if (pthread_create(&thread, NULL, Run, this))
- {
- errorStr = "Cannot create thread";
- printfd(__FILE__, "USERSTAT::Start() %s\n", errorStr.c_str());
- return -1;
- }
-
-return 0;
-}
-
-int USERSTAT::Stop()
-{
-nonstop = false;
-if (pthread_kill(thread, SIGTERM))
- {
- errorStr = "Cannot send signal to thread";
- printfd(__FILE__, "USERSTAT::Stop() %s\n", errorStr.c_str());
- return -1;
- }
-for (int i = 0; i < 25; i++)
- {
- if (!isRunning)
- break;
-
- usleep(200000);
- }
-if (isRunning)
- {
- errorStr = "Cannot stop thread";
- printfd(__FILE__, "USERSTAT::Stop() %s\n", errorStr.c_str());
- return -1;
- }
-return 0;
-}
-
-void * USERSTAT::Run(void * t)
-{
-USERSTAT * us = reinterpret_cast<USERSTAT *>(t);
-pthread_t thread;
-int outerSocket;
-struct sockaddr_in outerAddr;
-socklen_t outerAddrLen;
-THREAD_INFO info;
-
-us->isRunning = true;
-while (us->nonstop)
- {
- outerSocket = accept(us->listenSocket, (struct sockaddr *)&outerAddr, &outerAddrLen);
- if (outerSocket > 0)
- {
- std::vector<THREAD_INFO>::iterator it;
- us->pool.erase(remove_if(us->pool.begin(), us->pool.end(), USERSTAT::IsDone()), us->pool.end());
-
- while (us->pool.size() >= us->maxThreads)
- usleep(200000);
-
- info.users = us->users;
- info.store = us->store;
- info.outerSocket = outerSocket;
- info.done = false;
-
- info.request.Reset();
-
- us->pool.push_back(info);
- it = us->pool.end();
- --it;
-
- if (pthread_create(&thread, NULL, Operate, &(*it)))
- {
- us->errorStr = "Cannot create thread";
- printfd(__FILE__, "USERSTAT::Run() %s\n", us->errorStr.c_str());
- }
- it->thread = thread;
- }
- }
-us->isRunning = false;
-return NULL;
-}
-
-void * USERSTAT::Operate(void * i)
-{
- THREAD_INFO * info = reinterpret_cast<THREAD_INFO *>(i);
- unsigned char * buf;
- int32_t size;
- char * login;
-
- int res = read(info->outerSocket, &size, sizeof(size));
- if (res != sizeof(size))
- {
- printfd(__FILE__, "USERSTAT::Operate() Reading stream size failed! Wanted %d bytes, got %d bytes.\n", sizeof(size), res);
- info->done = true;
- return NULL;
- }
-
- printfd(__FILE__, "USERSTAT::Operate() size = %d\n", size);
-
- if (size < 0) {
- printfd(__FILE__, "USERSTAT::Operate() Invalid data size.\n");
- info->done = true;
- return NULL;
- }
-
- login = new char[size];
-
- res = read(info->outerSocket, login, size);
- if (res != size)
- {
- printfd(__FILE__, "USERSTAT::Operate() Reading login failed! Wanted %d bytes, got %d bytes.\n", 32, res);
- info->done = true;
- return NULL;
- }
-
- std::string l;
- l.assign(login, size);
-
- res = read(info->outerSocket, &size, sizeof(size));
- if (res != sizeof(size))
- {
- printfd(__FILE__, "USERSTAT::Operate() Reading stream size failed! Wanted %d bytes, got %d bytes.\n", sizeof(size), res);
- info->done = true;
- return NULL;
- }
-
- printfd(__FILE__, "USERSTAT::Operate() size = %d\n", size);
-
- if (size < 0) {
- printfd(__FILE__, "USERSTAT::Operate() Invalid data size.\n");
- info->done = true;
- return NULL;
- }
-
- buf = new unsigned char[size];
- res = read(info->outerSocket, buf, size);
- if (res != size)
- {
- printfd(__FILE__, "USERSTAT::Operate() Reading stream failed! Wanted %d bytes, got %d bytes.\n", size, res);
- info->done = true;
- return NULL;
- }
- buf[res] = 0;
-
- printfd(__FILE__, "USERSTAT::Operate() Received data: %s\n", buf);
-
- if (info->users->FindByName(l, &(info->uit)))
- {
- printfd(__FILE__, "USERSTAT::Operate() User '%s' not found.\n", login);
- info->done = true;
- return NULL;
- }
-
- std::string password = info->uit->property.password;
-
- printfd(__FILE__, "USERSTAT::Operate() Requested user: '%s'\n", login);
- printfd(__FILE__, "USERSTAT::Operate() Encription init using password: '%s'\n", password.c_str());
-
- BLOWFISH_CTX ctx;
- char * key = new char[password.length()];
- strncpy(key, password.c_str(), password.length());
-
- Blowfish_Init(&ctx,
- reinterpret_cast<unsigned char *>(key),
- password.length());
-
- for (int i = 0; i < size / 8; ++i) {
- uint32_t a;
- uint32_t b;
- a = n2l(buf + i * 8);
- b = n2l(buf + i * 8 + 4);
- Blowfish_Decrypt(&ctx,
- &a,
- &b);
- l2n(a, buf + i * 8);
- l2n(b, buf + i * 8 + 4);
- }
-
- delete[] key;
-
- printfd(__FILE__, "USERSTAT::Operate() Received XML: %s\n", buf);
-
- if (XML_Parse(info->xmlParser,
- reinterpret_cast<char *>(buf),
- size,
- 1) != XML_STATUS_OK) {
- printfd(__FILE__, "USERSTAT::Operate() Invalid password\n", login);
- info->done = true;
- delete[] buf;
- return NULL;
- }
-
- if (!info->request.isOk) {
- printfd(__FILE__, "USERSTAT::Operate() Malformed XML\n");
- info->done = true;
- delete[] buf;
- return NULL;
- }
-
- info->Handle();
-
- std::cout << "USERSTAT::Operate() Request:" << std::endl;
- std::for_each(info->request.conf.begin(),
- info->request.conf.end(),
- THREAD_INFO::LinePrinter());
- std::for_each(info->request.stat.begin(),
- info->request.stat.end(),
- THREAD_INFO::LinePrinter());
-
- info->done = true;
- delete[] buf;
- return NULL;
-}
-
-void TIParseXMLStart(void * data, const char * name, const char ** attr)
-{
- THREAD_INFO * ti = reinterpret_cast<THREAD_INFO *>(data);
- if (strncmp(name, "request", 7) == 0) {
- if (attr == NULL) {
- printfd(__FILE__, "ParseXMLStart() 'reqest' tag require a 'login' parameter\n");
- ti->request.isOk |= false;
- return;
- } else {
- ti->request.login = *attr;
- }
- } else if (strncmp(name, "stat", 4)) {
- ti->pvList = &(ti->request.stat);
- } else if (strncmp(name, "conf", 4)) {
- ti->pvList = &(ti->request.conf);
- } else {
- if (ti->pvList == NULL) {
- printfd(__FILE__, "ParseXMLStart() Unexpected tag: '%s'\n", name);
- ti->request.isOk |= false;
- return;
- }
- (*ti->pvList)[name];
- }
-}
-
-void TIParseXMLEnd(void * data, const char * name)
-{
- THREAD_INFO * ti = reinterpret_cast<THREAD_INFO *>(data);
- if (strncmp(name, "stat", 4) == 0) {
- ti->pvList = NULL;
- } else if (strncmp(name, "conf", 4) == 0) {
- ti->pvList = NULL;
- } else if (strncmp(name, "request", 7) == 0) {
- }
-}
-
-THREAD_INFO::THREAD_INFO() : pvList(NULL),
- users(NULL),
- store(NULL),
- outerSocket(-1),
- done(true)
-{
- printfd(__FILE__, "THREAD_INFO::THREAD_INFO()\n");
- xmlParser = XML_ParserCreate(NULL);
-
- if (!xmlParser)
- {
- printfd(__FILE__, "USERSTAT::Run() Couldn't allocate memory for parser\n");
- }
-
- XML_ParserReset(xmlParser, NULL);
- XML_SetElementHandler(xmlParser, TIParseXMLStart, TIParseXMLEnd);
- XML_SetUserData(xmlParser, this);
-}
-
-THREAD_INFO::~THREAD_INFO()
-{
- printfd(__FILE__, "THREAD_INFO::~THREAD_INFO()\n");
- XML_ParserFree(xmlParser);
-}
-
-int THREAD_INFO::Handle()
-{
- if (!request.isOk)
- return -1;
-
- if (HandleStat())
- return -1;
-
- if (HandleConf())
- return -1;
-
- return 0;
-}
-
-int THREAD_INFO::HandleConf()
-{
- PV_LIST::iterator it(request.conf.begin());
-
- for (; it != request.conf.end(); ++it)
- {
- if (it->first == "password")
- {
- it->second = uit->property.password;
- }
- else if (it->first == "passive")
- {
- it->second = uit->property.passive;
- }
- else if (it->first == "disabled")
- {
- it->second = uit->property.disabled;
- }
- else if (it->first == "disabledDetailStat")
- {
- it->second = uit->property.disabledDetailStat;
- }
- else if (it->first == "alwaysOnline")
- {
- it->second = uit->property.alwaysOnline;
- }
- else if (it->first == "tariffName")
- {
- it->second = uit->property.tariffName;
- }
- else if (it->first == "address")
- {
- it->second = uit->property.address;
- }
- else if (it->first == "phone")
- {
- it->second = uit->property.phone;
- }
- else if (it->first == "email")
- {
- it->second = uit->property.email;
- }
- else if (it->first == "note")
- {
- it->second = uit->property.note;
- }
- else if (it->first == "realName")
- {
- it->second = uit->property.realName;
- }
- else if (it->first == "group")
- {
- it->second = uit->property.group;
- }
- else if (it->first == "credit")
- {
- it->second = uit->property.credit;
- }
- else if (it->first == "creditExpire")
- {
- it->second = uit->property.creditExpire;
- }
- else if (it->first == "nextTariff")
- {
- it->second = uit->property.nextTariff;
- }
- else
- {
- printfd(__FILE__, "THREAD_INFO::HandleConf() Invalid param: '%s'\n", it->first.c_str());
- }
- }
-
- return 0;
-}
-
-int THREAD_INFO::HandleStat()
-{
- PV_LIST::iterator it(request.conf.begin());
-
- for (; it != request.conf.end(); ++it)
- {
- if (it->first == "cash")
- {
- it->second = uit->property.password;
- }
- else
- {
- printfd(__FILE__, "THREAD_INFO::HandleConf() Invalid param: '%s'\n", it->first.c_str());
- }
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-/*
- $Revision: $
- $Date: $
- $Author: $
-*/
-
-#ifndef __USERSTAT_H__
-#define __USERSTAT_H__
-
-#include <string>
-#include <map>
-#include <functional>
-
-#include <pthread.h>
-#include <netinet/in.h>
-
-#include "base_plugin.h"
-
-#define USTAT_VERSION "UserStats 1.0_alt"
-
-extern "C" BASE_PLUGIN * GetPlugin();
-
-class USERSTAT : public BASE_PLUGIN
-{
-public:
- USERSTAT();
- ~USERSTAT();
-
- virtual void SetUsers(USERS * u) { users = u; }
- virtual void SetStore(BASE_STORE * st) { store = st; }
- virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
- virtual int ParseSettings();
-
- virtual int Start();
- virtual int Stop();
- virtual bool IsRunning() { return isRunning; }
- virtual const string & GetStrError() const { return errorStr; }
- virtual const string GetVersion() const { return version; }
- virtual uint16_t GetStartPosition() const { return 10; }
- virtual uint16_t GetStopPosition() const { return 10; }
-
-private:
- struct IsDone : public unary_function<DataThread, bool>
- {
- bool operator()(const DataThread & info) { return info.IsDone(); }
- };
- struct ToLower : public unary_function<char, char>
- {
- char operator() (char c) const { return std::tolower(c); }
- };
- bool isRunning;
- bool nonstop;
- std::string errorStr;
- std::string version;
- std::vector<DataThread> pool;
- int listenSocket;
- int threads;
- unsigned maxThreads;
- uint16_t port;
- struct sockaddr_in listenAddr;
- pthread_t thread;
- pthread_mutex_t mutex;
- USERS * users;
- BASE_STORE * store;
-
- MODULE_SETTINGS settings;
-
- int Prepare();
- int Finalize();
- static void * Run(void *);
- static void * Operate(void *);
-};
-
-#endif
+++ /dev/null
-../pg_driver.la
\ No newline at end of file
+++ /dev/null
-SOURCES=$(wildcard *.cpp)
-
-all: test_pg_driver pg_driver.so
-
-test_pg_driver: test_pg_driver.o
- $(CXX) $^ -ldl -o $@
-
-pg_driver.so: pg_driver.o
- $(CXX) $^ -shared -lpq -o $@
-
-clean:
- rm -f *.d *.o *.so test_pg_driver
-
-
--include $(subst .cpp,.d,$(SOURCES))
-
-%.d: %.cpp
- @$(CC) -MM $(CXXFLAGS) $< > $@.$$$$; \
- sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
- rm -f $@.$$$$
+++ /dev/null
-#include <sstream>
-
-#include "pg_driver.h"
-
-BASE_DB * CreateDriver()
-{
- return new PG_DRIVER();
-}
-
-void DestroyDriver(BASE_DB * drv)
-{
- delete drv;
-}
-
-PG_DRIVER::~PG_DRIVER()
-{
- if (conn != NULL)
- PQfinish(conn);
-}
-
-bool PG_DRIVER::Connect()
-{
- std::stringstream params;
- params << "host=" << host
- << "dbname=" << database
- << "user=" << user
- << "password=" << password;
- std::string str = params.str();
- conn = PQconnectdb(str.c_str());
- errorMsg = PQerrorMessage(conn);
- return PQstatus(conn) != CONNECTION_OK;
-}
-
-bool PG_DRIVER::Disconnect()
-{
- if (PQstatus(conn) == CONNECTION_OK) {
- PQfinish(conn);
- errorMsg = PQerrorMessage(conn);
- return PQstatus(conn) != CONNECTION_BAD;
- }
-
- return false;
-}
-
-bool PG_DRIVER::Query(const std::string & query)
-{
- cols.erase(cols.begin(), cols.end());
- cols.reserve(columns);
-
- PQclear(result);
- result = PQexec(conn, query.c_str());
- errorMsg = PQerrorMessage(conn);
- tuples = PQntuples(result);
- columns = PQnfields(result);
- affected = atoi(PQcmdTuples(result));
-
- if (tuples) {
- for (int i = 0; i < columns; ++i)
- cols.push_back(PQfname(result, i));
- }
-
- if (!result)
- return true;
-
- if (PQresultStatus(result) == PGRES_COMMAND_OK)
- return false;
-
- if (PQresultStatus(result) == PGRES_TUPLES_OK)
- return false;
-
- return true;
-}
-
-bool PG_DRIVER::Start()
-{
- return Query("BEGIN");
-}
-
-bool PG_DRIVER::Commit()
-{
- return Query("COMMIT");
-}
-
-bool PG_DRIVER::Rollback()
-{
- return Query("ROLLBACK");
-}
-
-BASE_DB::TUPLE PG_DRIVER::GetTuple(int n) const
-{
- BASE_DB::TUPLE tuple;
-
- for (int i = 0; i < columns; ++i)
- tuple[cols[i]] = PQgetvalue(result, n, i);
-
- return tuple;
-}
-
-BASE_DB::TUPLES PG_DRIVER::GetResult() const
-{
- BASE_DB::TUPLES tpls;
-
- for (int i = 0; i < tuples; ++i)
- tpls.push_back(GetTuple(i));
-
- return tpls;
-}
+++ /dev/null
-#ifndef __PG_DRIVER_H__
-#define __PG_DRIVER_H__
-
-#include <libpq-fe.h>
-
-#include "base_db.h"
-
-extern "C" BASE_DB * CreateDriver();
-extern "C" void DestroyDriver(BASE_DB *);
-
-class PG_DRIVER : public BASE_DB {
-public:
- virtual ~PG_DRIVER();
-
- virtual bool Connect();
- virtual bool Disconnect();
- virtual bool Query(const std::string &);
- virtual bool Start();
- virtual bool Commit();
- virtual bool Rollback();
-
- virtual BASE_DB::TUPLES GetResult() const;
- virtual BASE_DB::TUPLE GetTuple(int n = 0) const;
-
-private:
- PGconn * conn;
- PGresult * result;
- COLUMNS cols;
-};
-
-#endif
+++ /dev/null
-# pg_driver.la - a libtool library file
-# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.493 2008/02/01 16:58:18)
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# The name that we can dlopen(3).
-dlname=''
-
-# Names of this library.
-library_names=''
-
-# The name of the static archive.
-old_library='pg_driver.a'
-
-# Libraries that this one depends upon.
-dependency_libs=' -lpq'
-
-# Version information for pg_driver.
-current=
-age=
-revision=
-
-# Is this an already installed library?
-installed=no
-
-# Should we warn about portability when linking against -modules?
-shouldnotlink=yes
-
-# Files to dlopen/dlpreopen
-dlopen=''
-dlpreopen=''
-
-# Directory that this library needs to be installed in:
-libdir=''
+++ /dev/null
-# pg_driver.lo - a libtool object file
-# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.493 2008/02/01 16:58:18)
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# Name of the PIC object.
-pic_object='.libs/pg_driver.o'
-
-# Name of the non-PIC object.
-non_pic_object='pg_driver.o'
-
+++ /dev/null
-#include <iostream>
-#include <string>
-#include <sstream>
-
-#include <dlfcn.h>
-
-#include "base_db.h"
-
-int main(int argc, char ** argv)
-{
- BASE_DB * db;
-
- void * lh = dlopen("./pg_driver.so", RTLD_NOW | RTLD_GLOBAL);
-
- if (lh == NULL) {
- std::cout << "Error loading shared object file pg_driver.so. Reason: '" << dlerror() << "'" << std::endl;
- return EXIT_FAILURE;
- }
-
- CreateDriverFn CreateDriver = reinterpret_cast<CreateDriverFn>(dlsym(lh, "CreateDriver"));
- if (CreateDriver == NULL) {
- std::cout << "Error getting symbol 'CreateDriver' address. Reason: '" << dlerror() << "'" << std::endl;
- dlclose(lh);
- return EXIT_FAILURE;
- }
- DestroyDriverFn DestroyDriver = reinterpret_cast<DestroyDriverFn>(dlsym(lh, "DestroyDriver"));
- if (DestroyDriver == NULL) {
- std::cout << "Error getting symbol 'DestroyDriver' address. Reason: '" << dlerror() << "'" << std::endl;
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- db = CreateDriver();
-
- db->SetHost("localhost");
- db->SetDatabase("stargazer");
- db->SetUser("stg");
- db->SetPassword("123456");
-
- if (db->Connect()) {
- std::cout << "Error connecting db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- std::stringstream query;
- query << "SELECT * FROM information_schema.tables";
-
- if (db->Query(query.str())) {
- std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- db->Disconnect();
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- std::cout << "Tuples: " << db->GetTuples() << std::endl;
- std::cout << "Columns: " << db->GetColumns() << std::endl;
- BASE_DB::COLUMNS cols;
- BASE_DB::COLUMNS::iterator it;
- cols = db->GetColumnsNames();
- std::cout << "Cols count: " << cols.size() << std::endl;
- std::cout << "Columns names:" << std::endl;
- for (it = cols.begin(); it != cols.end(); ++it)
- std::cout << *it << " ";
- std::cout << std::endl;
-
- for (int i = 0; i < db->GetTuples(); ++i) {
- BASE_DB::TUPLE tuple(db->GetTuple(i));
- BASE_DB::TUPLE::iterator it;
- for (it = tuple.begin(); it != tuple.end(); ++it)
- std::cout << it->second << " ";
- std::cout << std::endl;
- }
-
- query.str("");
- query << "create table test ( id bigserial, message text )";
- if (db->Query(query.str())) {
- std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- db->Disconnect();
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- query.str("");
- query << "insert into test (message) values ('abc');";
- query << "insert into test (message) values ('def');";
- query << "insert into test (message) values ('zxc');";
- if (db->Query(query.str())) {
- std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- db->Disconnect();
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- query.str("");
- query << "SELECT * FROM test";
- if (db->Query(query.str())) {
- std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- db->Disconnect();
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
- std::cout << "Tuples: " << db->GetTuples() << std::endl;
- std::cout << "Columns: " << db->GetColumns() << std::endl;
- cols = db->GetColumnsNames();
- std::cout << "Cols count: " << cols.size() << std::endl;
- std::cout << "Columns names:" << std::endl;
- for (it = cols.begin(); it != cols.end(); ++it)
- std::cout << *it << " ";
- std::cout << std::endl;
-
- for (int i = 0; i < db->GetTuples(); ++i) {
- BASE_DB::TUPLE tuple(db->GetTuple(i));
- BASE_DB::TUPLE::iterator it;
- for (it = tuple.begin(); it != tuple.end(); ++it)
- std::cout << it->second << " ";
- std::cout << std::endl;
- }
-
- query.str("");
- query << "drop table test";
- if (db->Query(query.str())) {
- std::cout << "Error querying db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- db->Disconnect();
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- if (db->Disconnect()) {
- std::cout << "Error connecting db. Reason: '" << db->GetErrorMsg() << "'" << std::endl;
- DestroyDriver(db);
- dlclose(lh);
- return EXIT_FAILURE;
- }
-
- DestroyDriver(db);
-
- dlclose(lh);
-
- return EXIT_SUCCESS;
-}
+++ /dev/null
-include make.conf
-
-CFLAGS += -g3 -W -Wall -pedantic
-CFLAGS += $(DEFINES) -D_BSD_SOURCE
-
-CXXFLAGS += $(CFLAGS)
-
-SOURCES=logger.cpp lock.cpp traffcounter.cpp rules.cpp utils.cpp
-RULES_TESTER_SOURCES=logger.cpp rules.cpp utils.cpp rules_tester.cpp
-RULES_FINDER_TESTER_SOURCES=logger.cpp lock.cpp rules.cpp rules_finder.cpp utils.cpp rf_tester.cpp
-TC_TESTER_SOURCES=logger.cpp rules.cpp rules_finder.cpp utils.cpp traffcounter.cpp lock.cpp tc_tester.cpp
-LIBS=-lpthread
-PROG=st_core
-
-.PHONY: all tests clean
-
-#all: $(PROG)
-all: tests
-
-$(PROG): $(subst .cpp,.o,$(SOURCES))
- $(CXX) $^ $(LDFLAGS) $(LIBS) -o $@
-
-tests: rules_tester rf_tester tc_tester
-
-rules_tester: $(subst .cpp,.o,$(RULES_TESTER_SOURCES))
- $(CXX) $^ $(LDFLAGS) -o $@
-
-rf_tester: $(subst .cpp,.o,$(RULES_FINDER_TESTER_SOURCES))
- $(CXX) $^ $(LDFLAGS) -o $@
-
-tc_tester: $(subst .cpp,.o,$(TC_TESTER_SOURCES))
- $(CXX) $^ $(LDFLAGS) $(LIBS) -o $@
-
-clean:
- rm -f $(PROG) *.o *d rules_tester rf_tester tc_tester gmon.out
-
-ifneq ($(MAKECMDGOALS),distclean)
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(MAKECMDGOALS),uninstall)
--include $(subst .cpp,.d,$(SOURCES))
-endif
-endif
-endif
-
-%.d: %.cpp
- @$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
- sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
- rm -f $@.$$$$
+++ /dev/null
-#ifndef __CAPTURER_TC_IFACE_H__
-#define __CAPTURER_TC_IFACE_H__
-
-#ifdef HAVE_STDINT
- #include <stdint.h>
-#else
- #ifdef HAVE_INTTYPES
- #include <inttypes.h>
- #else
- #error "You need either stdint.h or inttypes.h to compile this!"
- #endif
-#endif
-
-namespace STG
-{
-
- class ICAPTURER_TC
- {
- public:
- virtual ~ICAPTURER_TC() {};
- virtual void AddPacket(const iphdr &, uint16_t, uint16_t) = 0;
- };
-
-}
-
-#endif
+++ /dev/null
-#!/bin/sh
-
-echo -n "checking os type... "
-OS=`uname`
-echo $OS
-
-echo -n "checking stdint.h... "
-if [ -f /usr/include/stdint.h ]
-then
- DEFINES="$DEFINES -DHAVE_STDINT"
- echo "ok"
-else
- echo "fail"
-
- echo -n "checking inttypes.h... "
- if [ -f /usr/include/inttypes.h ]
- then
- DEFINES="$DEFINES -DHAVE_INTTYPES"
- echo "ok"
- else
- echo "fail"
- echo "You need either stdint.h or inttypes.h to compile this"
- exit 1
- fi
-fi
-
-if [ "$OS"=="Linux" ]
-then
- DEFINES="$DEFINES -DLINUX"
- echo -n "checking gmake... "
- gmake --version > /dev/null 2> /dev/null
- if [ $? -eq 0 ]
- then
- MAKE="gmake"
- echo "ok"
- else
- echo "fail"
- echo -n "checking make... "
- make --version > /dev/null 2> /dev/null
- if [ $? -eq 0 ]
- then
- echo "ok"
- MAKE="make"
- else
- echo "fail"
- echo "You need a GNU Make to compile this"
- exit 1
- fi
- fi
-else
- if [ "$OS"=="FreeBSD" ]
- then
- DEFINES="$DEFINES -DFREEBSD"
- echo -n "checking gmake... "
- gmake --version > /dev/null 2> /dev/null
- if [ $? -eq 0 ]
- then
- echo "ok"
- MAKE="gmake"
- else
- echo "fail"
- echo "You need a GNU Make to use this"
- exit 1
- fi
- else
- echo "This version of software is only compatible with Linux and FreeBSD"
- exit 1
- fi
-fi
-
-echo "Configuration successfull. Details:"
-echo -e "\tOS: $OS"
-echo -e "\tGNU Make utility: $MAKE"
-echo -e "\nType $MAKE and $MAKE install now"
-
-rm -f make.conf
-echo "OS = $OS" >> make.conf
-echo "DEFINES = $DEFINES" >> make.conf
+++ /dev/null
-#include <cerrno>
-
-#include <pthread.h>
-
-#include "lock.h"
-
-
-SCOPED_LOCK::SCOPED_LOCK(pthread_mutex_t & mtx)
- : mutex(mtx)
-{
-pthread_mutex_lock(&mutex);
-}
-
-SCOPED_LOCK::~SCOPED_LOCK()
-{
-pthread_mutex_unlock(&mutex);
-}
+++ /dev/null
-#ifndef __SCOPED_LOCK_H__
-#define __SCOPED_LOCK_H__
-
-#include <pthread.h>
-
-class SCOPED_LOCK
-{
-public:
- SCOPED_LOCK(pthread_mutex_t & mtx);
- ~SCOPED_LOCK();
-private:
- pthread_mutex_t & mutex;
-
- SCOPED_LOCK(const SCOPED_LOCK & lock) : mutex(lock.mutex) {};
-};
-
-#endif
+++ /dev/null
-#include <string>
-#include <sstream>
-
-#include <ctime>
-
-#include "logger.h"
-
-using namespace std;
-
-STGLogger::~STGLogger()
-{
-}
-
-ostream & STGLogger::operator <<(const string & val)
-{
- LogDate();
- out << " " << val;
- return out;
-}
-
-void STGLogger::LogDate()
-{
- time_t t(time(NULL));
- struct tm * tt = localtime(&t);
- out << "[" << tt->tm_year + 1900 << "-";
- out << (tt->tm_mon + 1 < 10 ? "0" : "") << tt->tm_mon + 1 << "-";
- out << (tt->tm_mday < 10 ? "0" : "") << tt->tm_mday << " ";
- out << (tt->tm_hour < 10 ? "0" : "") << tt->tm_hour << ":";
- out << (tt->tm_min < 10 ? "0" : "") << tt->tm_min << ":";
- out << (tt->tm_sec < 10 ? "0" : "") << tt->tm_sec << "]";
-}
+++ /dev/null
-#ifndef __LOGGER_H__
-#define __LOGGER_H__
-
-#include <iostream>
-#include <string>
-
-#define LOG_IT (log << __FILE__ << ":" << __LINE__ << " ")
-
-class STGLogger {
-public:
- STGLogger() : out(std::cout) {};
- STGLogger(std::ostream & stream) : out(stream) {};
- ~STGLogger();
-
- std::ostream &operator <<(const std::string & val);
-private:
- void LogDate();
- std::ostream & out;
-};
-
-extern STGLogger log;
-
-#endif
+++ /dev/null
-/*
- * Network:
- * - server: 192.168.0.1
- * - user A: 192.168.0.2
- * - user B: 192.168.0.3
- *
- * External resources:
- * - host 1: 216.239.59.104
- * - host 2: 72.14.221.104
- * - host 3: 66.249.93.104
- * - host 4: 195.5.61.68
- *
- * Directions:
- * - Local: ALL 192.168.0.0/24
- * - DNS: TCP_UDP 195.5.61.68/32:53
- * - FTP: TCP 129.22.8.159/32:20-21
- * - World: ALL 0.0.0.0/0
- *
- */
-
-#include <cstdlib>
-#include <iostream>
-#include <string>
-#include <vector>
-#include <algorithm>
-
-#include <arpa/inet.h>
-
-#include "rules.h"
-#include "rules_finder.h"
-#include "logger.h"
-
-using namespace std;
-using namespace STG;
-
-STGLogger log;
-
-RULE MakeRule(const std::string & ip,
- const std::string & mask,
- uint16_t port1,
- uint16_t port2,
- int proto,
- int dir)
-{
- RULE rule;
-
- rule.ip = inet_addr(ip.c_str());
- rule.mask = inet_addr(mask.c_str());
- rule.port1 = port1;
- rule.port2 = port2;
- rule.proto = proto;
- rule.dir = dir;
-
- return rule;
-}
-
-RULES PrepareRules()
-{
- RULES rules;
- RULE local(MakeRule("192.168.0.0",
- "255.255.255.0",
- 0,
- 65535,
- -1,
- 0));
- RULE dns(MakeRule("195.5.61.68",
- "255.255.255.255",
- 53,
- 53,
- -1,
- 1));
- RULE ftp(MakeRule("129.22.8.159",
- "255.255.255.255",
- 20,
- 21,
- -1,
- 2));
- RULE world(MakeRule("0.0.0.0",
- "0.0.0.0",
- 0,
- 65535,
- -1,
- 3));
-
- rules.push_back(local);
-
- rules.push_back(dns);
-
- rules.push_back(ftp);
-
- rules.push_back(world);
-
- return rules;
-}
-
-PENDING_PACKET MakePacket(const std::string & from,
- const std::string & to,
- uint16_t sport,
- uint16_t dport,
- int proto,
- PENDING_PACKET::DIRECTION direction,
- int length)
-{
- iphdr hdr;
-
- hdr.ihl = 5;
- hdr.version = 4;
- hdr.tos = 0;
- hdr.tot_len = length;
- hdr.id = 0;
- hdr.frag_off = 50;
- hdr.ttl = 64;
- hdr.protocol = proto;
- hdr.check = 0;
- hdr.saddr = inet_addr(from.c_str());
- hdr.daddr = inet_addr(to.c_str());
-
- PENDING_PACKET packet(hdr, sport, dport);
-
- packet.direction = direction;
-
- return packet;
-}
-
-struct TEST_INFO {
- int wantedDir;
- int actualDir; // Parser error status
- bool stdException; // Parser throws an std execption
- bool otherException; // Parser throws another exception
- bool result;
-};
-
-struct RF_TESTER : public std::unary_function<std::pair<PENDING_PACKET, int>, void>
-{
-public:
- RF_TESTER(RULES_FINDER & r)
- : rf(r),
- testLog(),
- result(true)
- {
- };
- ~RF_TESTER()
- {
- PrintLog();
- if (result)
- exit(EXIT_SUCCESS);
- exit(EXIT_FAILURE);
- }
- void operator()(const std::pair<PENDING_PACKET, int> & entry)
- {
- TEST_INFO info;
- info.wantedDir = entry.second;
- info.actualDir = -1;
- info.stdException = false;
- info.otherException = false;
- info.result = true;
- try
- {
- info.actualDir = rf.GetDir(entry.first);
- }
- catch (std::exception & ex)
- {
- info.stdException = true;
- info.result = false;
- }
- catch (...)
- {
- info.otherException = true;
- info.result = false;
- }
- info.result &= (info.actualDir == info.wantedDir);
- result &= info.result;
- testLog.push_back(info);
- };
-
- void PrintLog()
- {
- int testNumber = 1;
- std::cout << "RF_TESTER results:\n";
- std::cout << "-----------------------------------------------------------------\n";
- std::vector<TEST_INFO>::const_iterator it;
- for (it = testLog.begin(); it != testLog.end(); ++it)
- {
- std::cout << "Test no.: " << testNumber++ << "\t"
- << "Correct dir: " << it->wantedDir << "\t"
- << "Actual dir:" << it->actualDir << "\t"
- << "STD exceptions: " << it->stdException << "\t"
- << "Other exceptions: " << it->otherException << "\t"
- << "Result: " << it->result << "\n";
- }
- std::cout << "-----------------------------------------------------------------\n";
- std::cout << "Final result: " << (result ? "passed" : "failed") << std::endl;
- }
-
- bool Result() const { return result; };
-private:
- RULES_FINDER & rf;
- std::vector<TEST_INFO> testLog;
- bool result;
-};
-
-int main()
-{
- RULES rules(PrepareRules());
- RULES_FINDER rf;
-
- rf.SetRules(rules);
-
- std::list<std::pair<PENDING_PACKET, int> > tests;
-
- // Local, SSH
- tests.push_back(make_pair(MakePacket("192.168.0.2", "192.168.0.1", 3214, 22, 6, PENDING_PACKET::OUTGOING, 0), 0));
- tests.push_back(make_pair(MakePacket("192.168.0.1", "192.168.0.2", 22, 3214, 6, PENDING_PACKET::OUTGOING, 0), 0));
- // Local, SSH, incorrect direction detection
- tests.push_back(make_pair(MakePacket("192.168.0.2", "192.168.0.1", 3214, 22, 6, PENDING_PACKET::INCOMING, 0), 0));
- tests.push_back(make_pair(MakePacket("192.168.0.1", "192.168.0.2", 22, 3214, 6, PENDING_PACKET::INCOMING, 0), 0));
- // Local, FTP
- tests.push_back(make_pair(MakePacket("192.168.0.2", "192.168.0.1", 3214, 20, 6, PENDING_PACKET::OUTGOING, 0), 0));
- tests.push_back(make_pair(MakePacket("192.168.0.1", "192.168.0.2", 21, 3214, 6, PENDING_PACKET::OUTGOING, 0), 0));
- // Local, DNS
- tests.push_back(make_pair(MakePacket("192.168.0.2", "192.168.0.1", 3214, 53, 6, PENDING_PACKET::OUTGOING, 0), 0));
- tests.push_back(make_pair(MakePacket("192.168.0.1", "192.168.0.2", 53, 3214, 6, PENDING_PACKET::OUTGOING, 0), 0));
- // Known DNS, DNS
- tests.push_back(make_pair(MakePacket("192.168.0.2", "195.5.61.68", 3210, 53, 6, PENDING_PACKET::OUTGOING, 0), 1));
- tests.push_back(make_pair(MakePacket("195.5.61.68", "192.168.0.2", 53, 3210, 6, PENDING_PACKET::INCOMING, 0), 1));
- // Known DNS, invalid ports
- tests.push_back(make_pair(MakePacket("192.168.0.2", "195.5.61.68", 3210, 54, 6, PENDING_PACKET::OUTGOING, 0), 3));
- tests.push_back(make_pair(MakePacket("195.5.61.68", "192.168.0.2", 20, 3210, 6, PENDING_PACKET::INCOMING, 0), 3));
- // Known FTP, FTP
- tests.push_back(make_pair(MakePacket("192.168.0.2", "129.22.8.159", 3241, 20, 6, PENDING_PACKET::OUTGOING, 0), 2));
- tests.push_back(make_pair(MakePacket("129.22.8.159", "192.168.0.2", 21, 3241, 6, PENDING_PACKET::INCOMING, 0), 2));
- // Known FTP, invalid ports
- tests.push_back(make_pair(MakePacket("192.168.0.2", "129.22.8.159", 3241, 53, 6, PENDING_PACKET::OUTGOING, 0), 3));
- tests.push_back(make_pair(MakePacket("129.22.8.159", "192.168.0.2", 22, 3241, 6, PENDING_PACKET::INCOMING, 0), 3));
-
- std::for_each(tests.begin(),
- tests.end(),
- RF_TESTER(rf));
-
- return EXIT_SUCCESS;
-}
+++ /dev/null
-ALL 62.16.0.0/19 DIR0
-ALL 62.64.64.0/18 DIR0
-ALL 62.72.160.0/19 DIR0
-ALL 62.80.160.0/19 DIR0
-ALL 62.149.0.0/19 DIR0
-ALL 62.176.0.0/21 DIR0
-ALL 62.182.80.0/21 DIR0
-ALL 62.182.120.0/21 DIR0
-ALL 62.182.152.0/21 DIR0
-ALL 62.182.160.0/21 DIR0
-ALL 62.205.128.0/19 DIR0
-ALL 62.216.32.0/21 DIR0
-ALL 62.221.32.0/22 DIR0
-ALL 62.221.37.0/24 DIR0
-ALL 62.221.38.0/23 DIR0
-ALL 62.221.40.0/21 DIR0
-ALL 62.221.48.0/20 DIR0
-ALL 62.221.64.0/19 DIR0
-ALL 62.244.0.0/18 DIR0
-ALL 64.18.0.0/20 DIR0
-ALL 64.233.160.0/19 DIR0
-ALL 66.102.0.0/20 DIR0
-ALL 66.249.64.0/19 DIR0
-ALL 72.14.192.0/18 DIR0
-ALL 74.125.0.0/16 DIR0
-ALL 77.47.128.0/17 DIR0
-ALL 77.52.0.0/16 DIR0
-ALL 77.73.88.0/21 DIR0
-ALL 77.75.144.0/21 DIR0
-ALL 77.75.156.0/24 DIR0
-ALL 77.87.32.0/21 DIR0
-ALL 77.87.144.0/20 DIR0
-ALL 77.87.192.0/21 DIR0
-ALL 77.88.0.0/18 DIR0
-ALL 77.88.192.0/18 DIR0
-ALL 77.90.192.0/18 DIR0
-ALL 77.91.128.0/18 DIR0
-ALL 77.93.32.0/20 DIR0
-ALL 77.93.48.0/22 DIR0
-ALL 77.94.160.0/19 DIR0
-ALL 77.95.16.0/21 DIR0
-ALL 77.109.0.0/18 DIR0
-ALL 77.120.32.0/20 DIR0
-ALL 77.120.48.0/22 DIR0
-ALL 77.120.56.0/21 DIR0
-ALL 77.120.64.0/18 DIR0
-ALL 77.120.128.0/18 DIR0
-ALL 77.120.192.0/19 DIR0
-ALL 77.120.224.0/20 DIR0
-ALL 77.120.240.0/22 DIR0
-ALL 77.121.0.0/16 DIR0
-ALL 77.122.0.0/15 DIR0
-ALL 77.222.128.0/19 DIR0
-ALL 77.235.96.0/19 DIR0
-ALL 77.239.160.0/21 DIR0
-ALL 77.239.168.0/24 DIR0
-ALL 77.239.170.0/23 DIR0
-ALL 77.239.172.0/22 DIR0
-ALL 77.239.176.0/20 DIR0
-ALL 77.242.160.0/20 DIR0
-ALL 77.244.32.0/21 DIR0
-ALL 77.244.40.0/22 DIR0
-ALL 77.244.44.0/23 DIR0
-ALL 77.247.16.0/20 DIR0
-ALL 77.247.216.0/21 DIR0
-ALL 78.24.72.0/21 DIR0
-ALL 78.25.0.0/19 DIR0
-ALL 78.25.32.0/20 DIR0
-ALL 78.25.48.0/21 DIR0
-ALL 78.25.58.0/23 DIR0
-ALL 78.25.60.0/22 DIR0
-ALL 78.26.128.0/17 DIR0
-ALL 78.27.128.0/17 DIR0
-ALL 78.30.192.0/18 DIR0
-ALL 78.31.176.0/21 DIR0
-ALL 78.31.232.0/21 DIR0
-ALL 78.31.248.0/21 DIR0
-ALL 78.109.16.0/20 DIR0
-ALL 78.111.16.0/21 DIR0
-ALL 78.111.176.0/20 DIR0
-ALL 78.111.208.0/20 DIR0
-ALL 78.137.0.0/19 DIR0
-ALL 78.137.32.0/24 DIR0
-ALL 78.137.34.0/24 DIR0
-ALL 78.152.160.0/19 DIR0
-ALL 78.154.160.0/19 DIR0
-ALL 78.159.32.0/19 DIR0
-ALL 79.110.16.0/20 DIR0
-ALL 79.110.32.0/19 DIR0
-ALL 79.110.64.0/20 DIR0
-ALL 79.110.96.0/20 DIR0
-ALL 79.110.128.0/18 DIR0
-ALL 79.110.208.0/20 DIR0
-ALL 79.110.224.0/20 DIR0
-ALL 79.124.96.0/21 DIR0
-ALL 79.124.104.0/22 DIR0
-ALL 79.124.108.0/23 DIR0
-ALL 79.124.110.0/24 DIR0
-ALL 79.124.128.0/17 DIR0
-ALL 79.135.192.0/19 DIR0
-ALL 79.140.0.0/20 DIR0
-ALL 79.142.192.0/20 DIR0
-ALL 79.143.32.0/20 DIR0
-ALL 79.171.120.0/21 DIR0
-ALL 79.174.0.0/19 DIR0
-ALL 80.67.208.0/20 DIR0
-ALL 80.70.64.0/20 DIR0
-ALL 80.70.80.0/24 DIR0
-ALL 80.70.82.0/23 DIR0
-ALL 80.73.0.0/20 DIR0
-ALL 80.77.32.0/20 DIR0
-ALL 80.78.32.0/19 DIR0
-ALL 80.84.176.0/20 DIR0
-ALL 80.87.148.0/22 DIR0
-ALL 80.87.152.0/22 DIR0
-ALL 80.90.230.0/23 DIR0
-ALL 80.90.236.0/24 DIR0
-ALL 80.90.238.0/23 DIR0
-ALL 80.91.160.0/19 DIR0
-ALL 80.92.224.0/20 DIR0
-ALL 80.93.112.0/20 DIR0
-ALL 80.94.240.0/20 DIR0
-ALL 80.243.144.0/20 DIR0
-ALL 80.245.112.0/20 DIR0
-ALL 80.249.224.0/20 DIR0
-ALL 80.252.128.0/19 DIR0
-ALL 80.252.240.0/20 DIR0
-ALL 80.254.0.0/20 DIR0
-ALL 80.255.64.0/20 DIR0
-ALL 81.17.128.0/20 DIR0
-ALL 81.21.0.0/20 DIR0
-ALL 81.22.128.0/20 DIR0
-ALL 81.23.16.0/20 DIR0
-ALL 81.24.208.0/20 DIR0
-ALL 81.25.224.0/20 DIR0
-ALL 81.26.144.0/20 DIR0
-ALL 81.30.160.0/20 DIR0
-ALL 81.90.224.0/20 DIR0
-ALL 81.95.176.0/20 DIR0
-ALL 82.144.192.0/19 DIR0
-ALL 82.193.96.0/19 DIR0
-ALL 83.97.104.0/21 DIR0
-ALL 83.137.88.0/21 DIR0
-ALL 83.138.48.0/24 DIR0
-ALL 83.138.51.0/24 DIR0
-ALL 83.138.52.0/22 DIR0
-ALL 83.142.232.0/21 DIR0
-ALL 83.143.232.0/21 DIR0
-ALL 83.170.192.0/18 DIR0
-ALL 83.218.224.0/19 DIR0
-ALL 84.47.128.0/18 DIR0
-ALL 85.90.192.0/19 DIR0
-ALL 85.91.96.0/19 DIR0
-ALL 85.114.192.0/19 DIR0
-ALL 85.117.129.0/24 DIR0
-ALL 85.159.0.0/21 DIR0
-ALL 85.198.128.0/18 DIR0
-ALL 85.202.160.0/20 DIR0
-ALL 85.202.192.0/20 DIR0
-ALL 85.223.128.0/17 DIR0
-ALL 85.238.96.0/19 DIR0
-ALL 86.110.192.0/23 DIR0
-ALL 86.111.224.0/21 DIR0
-ALL 87.238.152.0/23 DIR0
-ALL 87.238.155.0/24 DIR0
-ALL 87.238.157.0/24 DIR0
-ALL 87.238.158.0/23 DIR0
-ALL 87.250.224.0/19 DIR0
-ALL 88.81.224.0/19 DIR0
-ALL 88.84.192.0/19 DIR0
-ALL 88.154.0.0/15 DIR0
-ALL 88.208.8.0/23 DIR0
-ALL 88.214.64.0/18 DIR0
-ALL 89.19.96.0/19 DIR0
-ALL 89.21.64.0/19 DIR0
-ALL 89.28.200.0/21 DIR0
-ALL 89.105.224.0/21 DIR0
-ALL 89.105.236.0/22 DIR0
-ALL 89.105.240.0/20 DIR0
-ALL 89.107.24.0/21 DIR0
-ALL 89.162.128.0/17 DIR0
-ALL 89.185.0.0/19 DIR0
-ALL 89.187.0.0/23 DIR0
-ALL 89.187.3.0/24 DIR0
-ALL 89.187.4.0/24 DIR0
-ALL 89.200.232.0/21 DIR0
-ALL 89.200.248.0/21 DIR0
-ALL 89.207.184.0/21 DIR0
-ALL 89.209.0.0/16 DIR0
-ALL 89.248.238.0/23 DIR0
-ALL 89.251.16.0/21 DIR0
-ALL 89.252.0.0/19 DIR0
-ALL 89.252.32.0/20 DIR0
-ALL 89.252.48.0/21 DIR0
-ALL 89.252.56.0/22 DIR0
-ALL 89.252.60.0/23 DIR0
-ALL 89.252.62.0/24 DIR0
-ALL 91.90.8.0/21 DIR0
-ALL 91.90.16.0/21 DIR0
-ALL 91.103.120.0/21 DIR0
-ALL 91.123.144.0/20 DIR0
-ALL 91.142.160.0/20 DIR0
-ALL 91.145.192.0/18 DIR0
-ALL 91.189.128.0/21 DIR0
-ALL 91.192.4.0/22 DIR0
-ALL 91.192.44.0/22 DIR0
-ALL 91.192.84.0/22 DIR0
-ALL 91.192.128.0/22 DIR0
-ALL 91.192.136.0/22 DIR0
-ALL 91.192.152.0/21 DIR0
-ALL 91.192.160.0/22 DIR0
-ALL 91.192.180.0/22 DIR0
-ALL 91.192.184.0/22 DIR0
-ALL 91.192.216.0/22 DIR0
-ALL 91.193.8.0/22 DIR0
-ALL 91.193.32.0/22 DIR0
-ALL 91.193.68.0/23 DIR0
-ALL 91.193.76.0/22 DIR0
-ALL 91.193.80.0/22 DIR0
-ALL 91.193.104.0/22 DIR0
-ALL 91.193.124.0/22 DIR0
-ALL 91.193.164.0/22 DIR0
-ALL 91.193.172.0/22 DIR0
-ALL 91.193.204.0/22 DIR0
-ALL 91.193.220.0/22 DIR0
-ALL 91.193.232.0/22 DIR0
-ALL 91.193.252.0/22 DIR0
-ALL 91.194.34.0/23 DIR0
-ALL 91.194.50.0/23 DIR0
-ALL 91.194.56.0/23 DIR0
-ALL 91.194.72.0/23 DIR0
-ALL 91.194.78.0/23 DIR0
-ALL 91.194.80.0/23 DIR0
-ALL 91.194.88.0/23 DIR0
-ALL 91.194.124.0/23 DIR0
-ALL 91.194.134.0/23 DIR0
-ALL 91.194.162.0/23 DIR0
-ALL 91.194.238.0/23 DIR0
-ALL 91.194.250.0/23 DIR0
-ALL 91.195.10.0/23 DIR0
-ALL 91.195.12.0/23 DIR0
-ALL 91.195.20.0/23 DIR0
-ALL 91.195.52.0/23 DIR0
-ALL 91.195.68.0/23 DIR0
-ALL 91.195.74.0/23 DIR0
-ALL 91.195.86.0/23 DIR0
-ALL 91.195.90.0/23 DIR0
-ALL 91.195.96.0/23 DIR0
-ALL 91.195.120.0/23 DIR0
-ALL 91.195.156.0/23 DIR0
-ALL 91.195.172.0/23 DIR0
-ALL 91.195.184.0/23 DIR0
-ALL 91.195.214.0/23 DIR0
-ALL 91.195.230.0/23 DIR0
-ALL 91.195.244.0/23 DIR0
-ALL 91.195.248.0/23 DIR0
-ALL 91.196.0.0/22 DIR0
-ALL 91.196.52.0/22 DIR0
-ALL 91.196.60.0/22 DIR0
-ALL 91.196.80.0/22 DIR0
-ALL 91.196.88.0/21 DIR0
-ALL 91.196.96.0/21 DIR0
-ALL 91.196.120.0/22 DIR0
-ALL 91.196.132.0/22 DIR0
-ALL 91.196.148.0/22 DIR0
-ALL 91.196.156.0/22 DIR0
-ALL 91.196.160.0/24 DIR0
-ALL 91.196.164.0/22 DIR0
-ALL 91.196.178.0/24 DIR0
-ALL 91.196.192.0/22 DIR0
-ALL 91.196.196.0/23 DIR0
-ALL 91.196.228.0/22 DIR0
-ALL 91.197.4.0/22 DIR0
-ALL 91.197.16.0/22 DIR0
-ALL 91.197.44.0/22 DIR0
-ALL 91.197.48.0/22 DIR0
-ALL 91.197.56.0/22 DIR0
-ALL 91.197.80.0/22 DIR0
-ALL 91.197.128.0/21 DIR0
-ALL 91.197.144.0/22 DIR0
-ALL 91.197.168.0/22 DIR0
-ALL 91.197.184.0/22 DIR0
-ALL 91.197.216.0/21 DIR0
-ALL 91.197.236.0/22 DIR0
-ALL 91.197.252.0/22 DIR0
-ALL 91.198.1.0/24 DIR0
-ALL 91.198.10.0/24 DIR0
-ALL 91.198.20.0/24 DIR0
-ALL 91.198.34.0/24 DIR0
-ALL 91.198.36.0/24 DIR0
-ALL 91.198.50.0/24 DIR0
-ALL 91.198.83.0/24 DIR0
-ALL 91.198.86.0/24 DIR0
-ALL 91.198.101.0/24 DIR0
-ALL 91.198.116.0/24 DIR0
-ALL 91.198.133.0/24 DIR0
-ALL 91.198.140.0/24 DIR0
-ALL 91.198.143.0/24 DIR0
-ALL 91.198.153.0/24 DIR0
-ALL 91.198.175.0/24 DIR0
-ALL 91.198.188.0/24 DIR0
-ALL 91.198.233.0/24 DIR0
-ALL 91.198.235.0/24 DIR0
-ALL 91.198.249.0/24 DIR0
-ALL 91.199.13.0/24 DIR0
-ALL 91.199.28.0/24 DIR0
-ALL 91.199.33.0/24 DIR0
-ALL 91.199.35.0/24 DIR0
-ALL 91.199.37.0/24 DIR0
-ALL 91.199.54.0/24 DIR0
-ALL 91.199.75.0/24 DIR0
-ALL 91.199.82.0/24 DIR0
-ALL 91.199.91.0/24 DIR0
-ALL 91.199.92.0/23 DIR0
-ALL 91.199.106.0/24 DIR0
-ALL 91.199.115.0/24 DIR0
-ALL 91.199.138.0/23 DIR0
-ALL 91.199.144.0/24 DIR0
-ALL 91.199.182.0/24 DIR0
-ALL 91.199.188.0/24 DIR0
-ALL 91.199.194.0/24 DIR0
-ALL 91.199.206.0/24 DIR0
-ALL 91.199.222.0/24 DIR0
-ALL 91.199.245.0/24 DIR0
-ALL 91.200.0.0/20 DIR0
-ALL 91.200.40.0/23 DIR0
-ALL 91.200.44.0/22 DIR0
-ALL 91.200.52.0/22 DIR0
-ALL 91.200.56.0/22 DIR0
-ALL 91.200.72.0/22 DIR0
-ALL 91.200.104.0/22 DIR0
-ALL 91.200.112.0/22 DIR0
-ALL 91.200.136.0/22 DIR0
-ALL 91.200.160.0/22 DIR0
-ALL 91.200.180.0/22 DIR0
-ALL 91.200.200.0/22 DIR0
-ALL 91.200.212.0/22 DIR0
-ALL 91.200.220.0/22 DIR0
-ALL 91.200.232.0/22 DIR0
-ALL 91.200.244.0/22 DIR0
-ALL 91.200.248.0/21 DIR0
-ALL 91.201.24.0/22 DIR0
-ALL 91.201.36.0/22 DIR0
-ALL 91.201.40.0/22 DIR0
-ALL 91.201.68.0/22 DIR0
-ALL 91.201.84.0/22 DIR0
-ALL 91.201.96.0/22 DIR0
-ALL 91.201.108.0/22 DIR0
-ALL 91.201.124.0/22 DIR0
-ALL 91.201.144.0/22 DIR0
-ALL 91.201.156.0/22 DIR0
-ALL 91.201.168.0/22 DIR0
-ALL 91.201.180.0/22 DIR0
-ALL 91.201.188.0/22 DIR0
-ALL 91.201.196.0/22 DIR0
-ALL 91.201.212.0/22 DIR0
-ALL 91.201.224.0/22 DIR0
-ALL 91.201.232.0/21 DIR0
-ALL 91.201.240.0/21 DIR0
-ALL 91.201.252.0/22 DIR0
-ALL 91.202.0.0/22 DIR0
-ALL 91.202.8.0/22 DIR0
-ALL 91.202.39.0/24 DIR0
-ALL 91.202.52.0/22 DIR0
-ALL 91.202.56.0/22 DIR0
-ALL 91.202.72.0/22 DIR0
-ALL 91.202.104.0/21 DIR0
-ALL 91.202.128.0/21 DIR0
-ALL 91.202.144.0/22 DIR0
-ALL 91.202.160.0/22 DIR0
-ALL 91.202.208.0/21 DIR0
-ALL 91.202.232.0/22 DIR0
-ALL 91.202.240.0/21 DIR0
-ALL 91.203.4.0/22 DIR0
-ALL 91.203.12.0/22 DIR0
-ALL 91.203.24.0/22 DIR0
-ALL 91.203.48.0/22 DIR0
-ALL 91.203.60.0/22 DIR0
-ALL 91.203.76.0/22 DIR0
-ALL 91.203.88.0/21 DIR0
-ALL 91.203.112.0/22 DIR0
-ALL 91.203.136.0/21 DIR0
-ALL 91.203.144.0/22 DIR0
-ALL 91.203.164.0/22 DIR0
-ALL 91.204.36.0/22 DIR0
-ALL 91.204.40.0/21 DIR0
-ALL 91.204.48.0/22 DIR0
-ALL 91.204.60.0/22 DIR0
-ALL 91.204.76.0/22 DIR0
-ALL 91.204.84.0/22 DIR0
-ALL 91.204.92.0/22 DIR0
-ALL 91.204.120.0/22 DIR0
-ALL 91.204.132.0/22 DIR0
-ALL 91.204.180.0/22 DIR0
-ALL 91.204.196.0/22 DIR0
-ALL 91.204.212.0/22 DIR0
-ALL 91.205.16.0/22 DIR0
-ALL 91.205.64.0/22 DIR0
-ALL 91.205.80.0/22 DIR0
-ALL 91.205.108.0/22 DIR0
-ALL 91.205.164.0/22 DIR0
-ALL 91.206.110.0/23 DIR0
-ALL 91.206.186.0/23 DIR0
-ALL 91.206.200.0/23 DIR0
-ALL 91.206.212.0/23 DIR0
-ALL 91.206.218.0/23 DIR0
-ALL 91.206.226.0/23 DIR0
-ALL 91.207.4.0/22 DIR0
-ALL 91.207.8.0/23 DIR0
-ALL 91.207.44.0/22 DIR0
-ALL 91.207.54.0/23 DIR0
-ALL 91.207.60.0/23 DIR0
-ALL 91.207.98.0/23 DIR0
-ALL 91.207.122.0/23 DIR0
-ALL 91.207.146.0/23 DIR0
-ALL 91.207.210.0/23 DIR0
-ALL 91.207.224.0/23 DIR0
-ALL 91.208.25.0/24 DIR0
-ALL 91.208.52.0/24 DIR0
-ALL 91.208.65.0/24 DIR0
-ALL 91.208.97.0/24 DIR0
-ALL 91.208.116.0/24 DIR0
-ALL 91.208.127.0/24 DIR0
-ALL 91.208.153.0/24 DIR0
-ALL 91.208.154.0/24 DIR0
-ALL 91.208.208.0/24 DIR0
-ALL 91.209.11.0/24 DIR0
-ALL 91.209.24.0/24 DIR0
-ALL 91.209.54.0/24 DIR0
-ALL 91.210.8.0/21 DIR0
-ALL 91.210.20.0/22 DIR0
-ALL 91.210.28.0/22 DIR0
-ALL 91.210.32.0/21 DIR0
-ALL 91.210.92.0/22 DIR0
-ALL 91.210.96.0/22 DIR0
-ALL 91.210.120.0/22 DIR0
-ALL 91.210.148.0/22 DIR0
-ALL 92.49.192.0/21 DIR0
-ALL 92.49.208.0/20 DIR0
-ALL 92.49.224.0/19 DIR0
-ALL 92.240.96.0/21 DIR0
-ALL 92.240.104.0/22 DIR0
-ALL 92.240.112.0/21 DIR0
-ALL 92.240.120.0/22 DIR0
-ALL 92.240.124.0/23 DIR0
-ALL 92.240.126.0/24 DIR0
-ALL 92.242.96.0/19 DIR0
-ALL 92.244.96.0/19 DIR0
-ALL 92.249.64.0/18 DIR0
-ALL 93.72.0.0/13 DIR0
-ALL 93.89.208.0/20 DIR0
-ALL 93.126.64.0/18 DIR0
-ALL 93.127.0.0/24 DIR0
-ALL 93.127.6.0/23 DIR0
-ALL 93.127.8.0/21 DIR0
-ALL 93.127.16.0/20 DIR0
-ALL 93.127.32.0/21 DIR0
-ALL 93.127.48.0/21 DIR0
-ALL 93.157.8.0/21 DIR0
-ALL 93.157.24.0/21 DIR0
-ALL 93.158.128.0/18 DIR0
-ALL 93.175.224.0/20 DIR0
-ALL 93.178.192.0/22 DIR0
-ALL 93.178.204.0/23 DIR0
-ALL 93.178.206.0/24 DIR0
-ALL 93.178.210.0/23 DIR0
-ALL 93.180.192.0/18 DIR0
-ALL 93.183.192.0/18 DIR0
-ALL 93.185.192.0/19 DIR0
-ALL 93.188.32.0/21 DIR0
-ALL 93.190.40.0/21 DIR0
-ALL 94.27.0.0/17 DIR0
-ALL 94.74.64.0/18 DIR0
-ALL 94.76.96.0/21 DIR0
-ALL 94.100.208.0/20 DIR0
-ALL 94.124.160.0/21 DIR0
-ALL 94.125.120.0/21 DIR0
-ALL 94.130.0.0/15 DIR0
-ALL 94.153.0.0/16 DIR0
-ALL 94.154.0.0/17 DIR0
-ALL 94.154.128.0/18 DIR0
-ALL 94.158.16.0/20 DIR0
-ALL 94.158.32.0/20 DIR0
-ALL 94.158.64.0/19 DIR0
-ALL 94.158.144.0/20 DIR0
-ALL 94.240.128.0/18 DIR0
-ALL 94.248.0.0/17 DIR0
-ALL 193.0.227.0/24 DIR0
-ALL 193.0.228.0/24 DIR0
-ALL 193.0.240.0/24 DIR0
-ALL 193.0.247.0/24 DIR0
-ALL 193.16.45.0/24 DIR0
-ALL 193.16.47.0/24 DIR0
-ALL 193.16.101.0/24 DIR0
-ALL 193.16.158.0/24 DIR0
-ALL 193.16.233.0/24 DIR0
-ALL 193.16.247.0/24 DIR0
-ALL 193.17.46.0/24 DIR0
-ALL 193.17.69.0/24 DIR0
-ALL 193.17.75.0/24 DIR0
-ALL 193.17.174.0/24 DIR0
-ALL 193.17.208.0/24 DIR0
-ALL 193.17.213.0/24 DIR0
-ALL 193.17.216.0/23 DIR0
-ALL 193.17.253.0/24 DIR0
-ALL 193.19.74.0/23 DIR0
-ALL 193.19.84.0/22 DIR0
-ALL 193.19.100.0/23 DIR0
-ALL 193.19.108.0/22 DIR0
-ALL 193.19.132.0/22 DIR0
-ALL 193.19.144.0/22 DIR0
-ALL 193.19.152.0/23 DIR0
-ALL 193.19.184.0/22 DIR0
-ALL 193.19.228.0/22 DIR0
-ALL 193.19.240.0/21 DIR0
-ALL 193.19.252.0/22 DIR0
-ALL 193.22.84.0/24 DIR0
-ALL 193.22.140.0/24 DIR0
-ALL 193.23.53.0/24 DIR0
-ALL 193.23.60.0/24 DIR0
-ALL 193.23.122.0/24 DIR0
-ALL 193.23.157.0/24 DIR0
-ALL 193.23.181.0/24 DIR0
-ALL 193.23.183.0/24 DIR0
-ALL 193.23.225.0/24 DIR0
-ALL 193.24.25.0/24 DIR0
-ALL 193.24.30.0/24 DIR0
-ALL 193.25.176.0/23 DIR0
-ALL 193.25.255.0/24 DIR0
-ALL 193.26.3.0/24 DIR0
-ALL 193.26.13.0/24 DIR0
-ALL 193.26.20.0/24 DIR0
-ALL 193.26.27.0/24 DIR0
-ALL 193.26.134.0/24 DIR0
-ALL 193.27.0.0/24 DIR0
-ALL 193.27.47.0/24 DIR0
-ALL 193.27.80.0/23 DIR0
-ALL 193.27.234.0/23 DIR0
-ALL 193.27.242.0/23 DIR0
-ALL 193.28.85.0/24 DIR0
-ALL 193.28.87.0/24 DIR0
-ALL 193.28.92.0/24 DIR0
-ALL 193.28.156.0/24 DIR0
-ALL 193.28.177.0/24 DIR0
-ALL 193.28.184.0/24 DIR0
-ALL 193.28.186.0/24 DIR0
-ALL 193.28.190.0/24 DIR0
-ALL 193.28.200.0/24 DIR0
-ALL 193.29.203.0/24 DIR0
-ALL 193.29.204.0/24 DIR0
-ALL 193.29.220.0/24 DIR0
-ALL 193.30.240.0/22 DIR0
-ALL 193.32.21.0/24 DIR0
-ALL 193.33.48.0/23 DIR0
-ALL 193.33.54.0/23 DIR0
-ALL 193.33.64.0/23 DIR0
-ALL 193.33.104.0/23 DIR0
-ALL 193.33.146.0/23 DIR0
-ALL 193.33.172.0/23 DIR0
-ALL 193.33.194.0/23 DIR0
-ALL 193.33.196.0/23 DIR0
-ALL 193.33.202.0/23 DIR0
-ALL 193.33.206.0/23 DIR0
-ALL 193.33.212.0/23 DIR0
-ALL 193.33.236.0/23 DIR0
-ALL 193.34.20.0/22 DIR0
-ALL 193.34.60.0/22 DIR0
-ALL 193.34.72.0/21 DIR0
-ALL 193.34.92.0/22 DIR0
-ALL 193.34.128.0/23 DIR0
-ALL 193.34.140.0/23 DIR0
-ALL 193.34.154.0/23 DIR0
-ALL 193.34.168.0/23 DIR0
-ALL 193.34.172.0/23 DIR0
-ALL 193.35.25.0/24 DIR0
-ALL 193.37.133.0/24 DIR0
-ALL 193.37.141.0/24 DIR0
-ALL 193.37.156.0/24 DIR0
-ALL 193.39.69.0/24 DIR0
-ALL 193.39.72.0/24 DIR0
-ALL 193.39.75.0/24 DIR0
-ALL 193.39.76.0/23 DIR0
-ALL 193.39.114.0/24 DIR0
-ALL 193.39.118.0/24 DIR0
-ALL 193.41.4.0/23 DIR0
-ALL 193.41.38.0/24 DIR0
-ALL 193.41.48.0/23 DIR0
-ALL 193.41.51.0/24 DIR0
-ALL 193.41.60.0/22 DIR0
-ALL 193.41.80.0/24 DIR0
-ALL 193.41.88.0/24 DIR0
-ALL 193.41.128.0/22 DIR0
-ALL 193.41.160.0/22 DIR0
-ALL 193.41.172.0/22 DIR0
-ALL 193.41.184.0/22 DIR0
-ALL 193.41.218.0/23 DIR0
-ALL 193.41.239.0/24 DIR0
-ALL 193.43.95.0/24 DIR0
-ALL 193.43.222.0/23 DIR0
-ALL 193.43.248.0/21 DIR0
-ALL 193.46.46.0/24 DIR0
-ALL 193.46.66.0/24 DIR0
-ALL 193.46.81.0/24 DIR0
-ALL 193.46.86.0/24 DIR0
-ALL 193.46.89.0/24 DIR0
-ALL 193.46.201.0/24 DIR0
-ALL 193.46.210.0/24 DIR0
-ALL 193.47.85.0/24 DIR0
-ALL 193.47.137.0/24 DIR0
-ALL 193.47.145.0/24 DIR0
-ALL 193.47.166.0/24 DIR0
-ALL 193.58.251.0/24 DIR0
-ALL 193.84.17.0/24 DIR0
-ALL 193.84.23.0/24 DIR0
-ALL 193.84.50.0/24 DIR0
-ALL 193.84.72.0/24 DIR0
-ALL 193.84.76.0/23 DIR0
-ALL 193.84.90.0/24 DIR0
-ALL 193.93.12.0/22 DIR0
-ALL 193.93.16.0/22 DIR0
-ALL 193.93.48.0/22 DIR0
-ALL 193.93.76.0/22 DIR0
-ALL 193.93.100.0/22 DIR0
-ALL 193.93.108.0/22 DIR0
-ALL 193.93.116.0/22 DIR0
-ALL 193.93.160.0/22 DIR0
-ALL 193.93.184.0/21 DIR0
-ALL 193.93.192.0/22 DIR0
-ALL 193.93.228.0/22 DIR0
-ALL 193.108.38.0/23 DIR0
-ALL 193.108.46.0/23 DIR0
-ALL 193.108.48.0/22 DIR0
-ALL 193.108.56.0/22 DIR0
-ALL 193.108.102.0/23 DIR0
-ALL 193.108.104.0/23 DIR0
-ALL 193.108.112.0/21 DIR0
-ALL 193.108.120.0/22 DIR0
-ALL 193.108.128.0/22 DIR0
-ALL 193.108.162.0/23 DIR0
-ALL 193.108.170.0/23 DIR0
-ALL 193.108.209.0/24 DIR0
-ALL 193.108.226.0/23 DIR0
-ALL 193.108.236.0/23 DIR0
-ALL 193.108.240.0/22 DIR0
-ALL 193.108.248.0/22 DIR0
-ALL 193.109.8.0/22 DIR0
-ALL 193.109.80.0/24 DIR0
-ALL 193.109.93.0/24 DIR0
-ALL 193.109.100.0/22 DIR0
-ALL 193.109.118.0/24 DIR0
-ALL 193.109.128.0/23 DIR0
-ALL 193.109.144.0/22 DIR0
-ALL 193.109.160.0/21 DIR0
-ALL 193.109.240.0/23 DIR0
-ALL 193.109.248.0/23 DIR0
-ALL 193.110.16.0/21 DIR0
-ALL 193.110.72.0/21 DIR0
-ALL 193.110.89.0/24 DIR0
-ALL 193.110.106.0/23 DIR0
-ALL 193.110.112.0/22 DIR0
-ALL 193.110.124.0/22 DIR0
-ALL 193.110.160.0/22 DIR0
-ALL 193.110.172.0/22 DIR0
-ALL 193.110.176.0/23 DIR0
-ALL 193.110.184.0/23 DIR0
-ALL 193.110.188.0/23 DIR0
-ALL 193.111.6.0/23 DIR0
-ALL 193.111.8.0/23 DIR0
-ALL 193.111.83.0/24 DIR0
-ALL 193.111.114.0/23 DIR0
-ALL 193.111.126.0/23 DIR0
-ALL 193.111.156.0/22 DIR0
-ALL 193.111.173.0/24 DIR0
-ALL 193.111.188.0/22 DIR0
-ALL 193.111.204.0/23 DIR0
-ALL 193.111.239.0/24 DIR0
-ALL 193.111.240.0/22 DIR0
-ALL 193.111.248.0/22 DIR0
-ALL 193.124.48.0/24 DIR0
-ALL 193.124.54.0/24 DIR0
-ALL 193.124.57.0/24 DIR0
-ALL 193.124.59.0/24 DIR0
-ALL 193.124.60.0/23 DIR0
-ALL 193.124.70.0/24 DIR0
-ALL 193.124.76.0/22 DIR0
-ALL 193.124.229.0/24 DIR0
-ALL 193.138.77.0/24 DIR0
-ALL 193.138.84.0/24 DIR0
-ALL 193.138.87.0/24 DIR0
-ALL 193.138.93.0/24 DIR0
-ALL 193.138.114.0/24 DIR0
-ALL 193.138.122.0/24 DIR0
-ALL 193.138.132.0/22 DIR0
-ALL 193.138.144.0/22 DIR0
-ALL 193.138.184.0/22 DIR0
-ALL 193.138.236.0/22 DIR0
-ALL 193.138.244.0/22 DIR0
-ALL 193.142.124.0/24 DIR0
-ALL 193.142.213.0/24 DIR0
-ALL 193.142.218.0/23 DIR0
-ALL 193.142.221.0/24 DIR0
-ALL 193.151.12.0/22 DIR0
-ALL 193.151.56.0/22 DIR0
-ALL 193.151.104.0/22 DIR0
-ALL 193.151.240.0/21 DIR0
-ALL 193.151.252.0/22 DIR0
-ALL 193.164.92.0/22 DIR0
-ALL 193.164.130.0/24 DIR0
-ALL 193.164.149.0/24 DIR0
-ALL 193.178.34.0/24 DIR0
-ALL 193.178.124.0/22 DIR0
-ALL 193.178.144.0/22 DIR0
-ALL 193.178.162.0/24 DIR0
-ALL 193.178.190.0/23 DIR0
-ALL 193.178.228.0/23 DIR0
-ALL 193.178.236.0/23 DIR0
-ALL 193.178.248.0/22 DIR0
-ALL 193.186.9.0/24 DIR0
-ALL 193.186.15.0/24 DIR0
-ALL 193.188.254.0/24 DIR0
-ALL 193.189.96.0/23 DIR0
-ALL 193.189.126.0/23 DIR0
-ALL 193.192.36.0/23 DIR0
-ALL 193.193.192.0/19 DIR0
-ALL 193.200.22.0/24 DIR0
-ALL 193.200.32.0/23 DIR0
-ALL 193.200.36.0/22 DIR0
-ALL 193.200.64.0/23 DIR0
-ALL 193.200.68.0/23 DIR0
-ALL 193.200.84.0/23 DIR0
-ALL 193.200.151.0/24 DIR0
-ALL 193.200.160.0/23 DIR0
-ALL 193.200.173.0/24 DIR0
-ALL 193.200.175.0/24 DIR0
-ALL 193.200.179.0/24 DIR0
-ALL 193.200.183.0/24 DIR0
-ALL 193.200.190.0/24 DIR0
-ALL 193.200.205.0/24 DIR0
-ALL 193.200.209.0/24 DIR0
-ALL 193.200.212.0/24 DIR0
-ALL 193.200.219.0/24 DIR0
-ALL 193.200.229.0/24 DIR0
-ALL 193.200.248.0/24 DIR0
-ALL 193.200.255.0/24 DIR0
-ALL 193.201.60.0/22 DIR0
-ALL 193.201.80.0/22 DIR0
-ALL 193.201.98.0/23 DIR0
-ALL 193.201.100.0/24 DIR0
-ALL 193.201.116.0/23 DIR0
-ALL 193.201.140.0/22 DIR0
-ALL 193.201.175.0/24 DIR0
-ALL 193.201.198.0/23 DIR0
-ALL 193.201.206.0/23 DIR0
-ALL 193.201.208.0/22 DIR0
-ALL 193.201.216.0/22 DIR0
-ALL 193.201.224.0/22 DIR0
-ALL 193.202.21.0/24 DIR0
-ALL 193.202.110.0/24 DIR0
-ALL 193.202.118.0/24 DIR0
-ALL 193.203.110.0/23 DIR0
-ALL 193.203.218.0/23 DIR0
-ALL 193.203.236.0/23 DIR0
-ALL 193.218.144.0/22 DIR0
-ALL 193.219.99.0/24 DIR0
-ALL 193.219.124.0/24 DIR0
-ALL 193.222.111.0/24 DIR0
-ALL 193.222.140.0/24 DIR0
-ALL 193.223.98.0/24 DIR0
-ALL 193.227.97.0/24 DIR0
-ALL 193.227.115.0/24 DIR0
-ALL 193.227.119.0/24 DIR0
-ALL 193.227.120.0/24 DIR0
-ALL 193.227.206.0/23 DIR0
-ALL 193.227.208.0/22 DIR0
-ALL 193.227.230.0/23 DIR0
-ALL 193.227.250.0/23 DIR0
-ALL 193.228.2.0/24 DIR0
-ALL 193.232.65.0/24 DIR0
-ALL 193.238.20.0/22 DIR0
-ALL 193.238.32.0/22 DIR0
-ALL 193.238.96.0/22 DIR0
-ALL 193.238.108.0/22 DIR0
-ALL 193.238.116.0/22 DIR0
-ALL 193.238.152.0/22 DIR0
-ALL 193.238.192.0/22 DIR0
-ALL 193.239.24.0/22 DIR0
-ALL 193.239.68.0/23 DIR0
-ALL 193.239.72.0/22 DIR0
-ALL 193.239.128.0/23 DIR0
-ALL 193.239.132.0/24 DIR0
-ALL 193.239.142.0/23 DIR0
-ALL 193.239.152.0/23 DIR0
-ALL 193.239.170.0/23 DIR0
-ALL 193.239.178.0/23 DIR0
-ALL 193.239.228.0/23 DIR0
-ALL 193.239.234.0/23 DIR0
-ALL 193.239.238.0/23 DIR0
-ALL 193.239.250.0/23 DIR0
-ALL 193.239.254.0/23 DIR0
-ALL 193.242.114.0/24 DIR0
-ALL 193.243.152.0/23 DIR0
-ALL 193.243.156.0/22 DIR0
-ALL 193.254.196.0/23 DIR0
-ALL 193.254.216.0/22 DIR0
-ALL 193.254.220.0/23 DIR0
-ALL 193.254.224.0/22 DIR0
-ALL 193.254.232.0/22 DIR0
-ALL 194.0.88.0/22 DIR0
-ALL 194.0.104.0/22 DIR0
-ALL 194.0.116.0/23 DIR0
-ALL 194.0.131.0/24 DIR0
-ALL 194.0.138.0/24 DIR0
-ALL 194.0.148.0/24 DIR0
-ALL 194.0.150.0/24 DIR0
-ALL 194.0.187.0/24 DIR0
-ALL 194.0.200.0/24 DIR0
-ALL 194.0.206.0/24 DIR0
-ALL 194.0.218.0/24 DIR0
-ALL 194.0.231.0/24 DIR0
-ALL 194.1.193.0/24 DIR0
-ALL 194.1.195.0/24 DIR0
-ALL 194.6.196.0/22 DIR0
-ALL 194.6.231.0/24 DIR0
-ALL 194.6.232.0/23 DIR0
-ALL 194.8.51.0/24 DIR0
-ALL 194.8.56.0/24 DIR0
-ALL 194.8.64.0/23 DIR0
-ALL 194.9.0.0/23 DIR0
-ALL 194.9.14.0/23 DIR0
-ALL 194.9.26.0/23 DIR0
-ALL 194.9.36.0/23 DIR0
-ALL 194.9.50.0/23 DIR0
-ALL 194.9.68.0/23 DIR0
-ALL 194.15.147.0/24 DIR0
-ALL 194.24.162.0/23 DIR0
-ALL 194.24.182.0/23 DIR0
-ALL 194.24.184.0/22 DIR0
-ALL 194.24.190.0/23 DIR0
-ALL 194.24.236.0/23 DIR0
-ALL 194.24.246.0/23 DIR0
-ALL 194.29.60.0/22 DIR0
-ALL 194.29.184.0/22 DIR0
-ALL 194.29.205.0/24 DIR0
-ALL 194.30.163.0/24 DIR0
-ALL 194.30.168.0/24 DIR0
-ALL 194.30.170.0/24 DIR0
-ALL 194.30.172.0/24 DIR0
-ALL 194.33.15.0/24 DIR0
-ALL 194.33.180.0/23 DIR0
-ALL 194.33.188.0/23 DIR0
-ALL 194.37.248.0/24 DIR0
-ALL 194.42.192.0/20 DIR0
-ALL 194.44.0.0/24 DIR0
-ALL 194.44.2.0/23 DIR0
-ALL 194.44.5.0/24 DIR0
-ALL 194.44.7.0/24 DIR0
-ALL 194.44.8.0/22 DIR0
-ALL 194.44.13.0/24 DIR0
-ALL 194.44.14.0/23 DIR0
-ALL 194.44.16.0/22 DIR0
-ALL 194.44.21.0/24 DIR0
-ALL 194.44.22.0/23 DIR0
-ALL 194.44.24.0/23 DIR0
-ALL 194.44.27.0/24 DIR0
-ALL 194.44.28.0/22 DIR0
-ALL 194.44.32.0/20 DIR0
-ALL 194.44.48.0/24 DIR0
-ALL 194.44.50.0/24 DIR0
-ALL 194.44.53.0/24 DIR0
-ALL 194.44.54.0/23 DIR0
-ALL 194.44.56.0/21 DIR0
-ALL 194.44.64.0/24 DIR0
-ALL 194.44.66.0/23 DIR0
-ALL 194.44.69.0/24 DIR0
-ALL 194.44.70.0/23 DIR0
-ALL 194.44.72.0/21 DIR0
-ALL 194.44.80.0/22 DIR0
-ALL 194.44.88.0/23 DIR0
-ALL 194.44.91.0/24 DIR0
-ALL 194.44.92.0/22 DIR0
-ALL 194.44.96.0/21 DIR0
-ALL 194.44.104.0/22 DIR0
-ALL 194.44.108.0/23 DIR0
-ALL 194.44.111.0/24 DIR0
-ALL 194.44.112.0/23 DIR0
-ALL 194.44.114.0/24 DIR0
-ALL 194.44.116.0/22 DIR0
-ALL 194.44.120.0/22 DIR0
-ALL 194.44.126.0/23 DIR0
-ALL 194.44.128.0/20 DIR0
-ALL 194.44.144.0/21 DIR0
-ALL 194.44.152.0/22 DIR0
-ALL 194.44.156.0/23 DIR0
-ALL 194.44.158.0/24 DIR0
-ALL 194.44.160.0/23 DIR0
-ALL 194.44.163.0/24 DIR0
-ALL 194.44.164.0/22 DIR0
-ALL 194.44.168.0/21 DIR0
-ALL 194.44.176.0/22 DIR0
-ALL 194.44.181.0/24 DIR0
-ALL 194.44.182.0/23 DIR0
-ALL 194.44.184.0/22 DIR0
-ALL 194.44.188.0/24 DIR0
-ALL 194.44.190.0/23 DIR0
-ALL 194.44.192.0/18 DIR0
-ALL 194.48.175.0/24 DIR0
-ALL 194.48.212.0/24 DIR0
-ALL 194.50.0.0/24 DIR0
-ALL 194.50.9.0/24 DIR0
-ALL 194.50.85.0/24 DIR0
-ALL 194.50.98.0/24 DIR0
-ALL 194.50.114.0/24 DIR0
-ALL 194.50.116.0/24 DIR0
-ALL 194.50.119.0/24 DIR0
-ALL 194.50.125.0/24 DIR0
-ALL 194.50.161.0/24 DIR0
-ALL 194.50.167.0/24 DIR0
-ALL 194.50.169.0/24 DIR0
-ALL 194.50.254.0/24 DIR0
-ALL 194.54.80.0/22 DIR0
-ALL 194.54.88.0/22 DIR0
-ALL 194.54.152.0/21 DIR0
-ALL 194.54.184.0/22 DIR0
-ALL 194.58.82.0/24 DIR0
-ALL 194.60.69.0/24 DIR0
-ALL 194.60.77.0/24 DIR0
-ALL 194.63.140.0/22 DIR0
-ALL 194.79.8.0/22 DIR0
-ALL 194.79.20.0/22 DIR0
-ALL 194.79.60.0/22 DIR0
-ALL 194.88.1.0/24 DIR0
-ALL 194.88.138.0/23 DIR0
-ALL 194.88.150.0/23 DIR0
-ALL 194.88.152.0/23 DIR0
-ALL 194.88.206.0/23 DIR0
-ALL 194.88.218.0/23 DIR0
-ALL 194.88.220.0/23 DIR0
-ALL 194.93.160.0/19 DIR0
-ALL 194.99.240.0/22 DIR0
-ALL 194.105.136.0/23 DIR0
-ALL 194.105.144.0/23 DIR0
-ALL 194.106.208.0/23 DIR0
-ALL 194.106.216.0/22 DIR0
-ALL 194.107.21.0/24 DIR0
-ALL 194.110.79.0/24 DIR0
-ALL 194.110.126.0/24 DIR0
-ALL 194.110.129.0/24 DIR0
-ALL 194.110.210.0/24 DIR0
-ALL 194.110.219.0/24 DIR0
-ALL 194.110.248.0/24 DIR0
-ALL 194.110.252.0/24 DIR0
-ALL 194.110.254.0/24 DIR0
-ALL 194.114.132.0/22 DIR0
-ALL 194.114.136.0/22 DIR0
-ALL 194.116.162.0/23 DIR0
-ALL 194.116.170.0/23 DIR0
-ALL 194.116.194.0/23 DIR0
-ALL 194.116.228.0/23 DIR0
-ALL 194.116.232.0/23 DIR0
-ALL 194.116.238.0/23 DIR0
-ALL 194.116.244.0/23 DIR0
-ALL 194.125.224.0/22 DIR0
-ALL 194.125.244.0/23 DIR0
-ALL 194.125.248.0/23 DIR0
-ALL 194.126.180.0/22 DIR0
-ALL 194.126.204.0/24 DIR0
-ALL 194.126.224.0/24 DIR0
-ALL 194.135.249.0/24 DIR0
-ALL 194.140.228.0/24 DIR0
-ALL 194.140.237.0/24 DIR0
-ALL 194.143.136.0/23 DIR0
-ALL 194.143.144.0/22 DIR0
-ALL 194.145.117.0/24 DIR0
-ALL 194.145.198.0/23 DIR0
-ALL 194.145.214.0/23 DIR0
-ALL 194.145.216.0/23 DIR0
-ALL 194.145.220.0/23 DIR0
-ALL 194.146.110.0/24 DIR0
-ALL 194.146.112.0/24 DIR0
-ALL 194.146.132.0/22 DIR0
-ALL 194.146.136.0/21 DIR0
-ALL 194.146.156.0/23 DIR0
-ALL 194.146.188.0/22 DIR0
-ALL 194.146.196.0/22 DIR0
-ALL 194.146.220.0/22 DIR0
-ALL 194.146.228.0/22 DIR0
-ALL 194.150.72.0/21 DIR0
-ALL 194.150.92.0/22 DIR0
-ALL 194.150.104.0/22 DIR0
-ALL 194.150.174.0/23 DIR0
-ALL 194.150.192.0/23 DIR0
-ALL 194.150.204.0/23 DIR0
-ALL 194.150.220.0/23 DIR0
-ALL 194.150.232.0/23 DIR0
-ALL 194.153.128.0/23 DIR0
-ALL 194.153.148.0/23 DIR0
-ALL 194.165.46.0/24 DIR0
-ALL 194.165.62.0/24 DIR0
-ALL 194.169.193.0/24 DIR0
-ALL 194.169.205.0/24 DIR0
-ALL 194.169.206.0/23 DIR0
-ALL 194.169.210.0/24 DIR0
-ALL 194.169.238.0/24 DIR0
-ALL 194.176.97.0/24 DIR0
-ALL 194.183.160.0/19 DIR0
-ALL 194.187.28.0/22 DIR0
-ALL 194.187.48.0/22 DIR0
-ALL 194.187.56.0/22 DIR0
-ALL 194.187.104.0/21 DIR0
-ALL 194.187.128.0/22 DIR0
-ALL 194.187.148.0/22 DIR0
-ALL 194.187.152.0/22 DIR0
-ALL 194.187.208.0/24 DIR0
-ALL 194.187.216.0/22 DIR0
-ALL 194.187.228.0/22 DIR0
-ALL 194.213.6.0/24 DIR0
-ALL 194.213.23.0/24 DIR0
-ALL 194.220.139.0/24 DIR0
-ALL 194.220.172.0/24 DIR0
-ALL 194.242.53.0/24 DIR0
-ALL 194.242.60.0/24 DIR0
-ALL 194.242.96.0/22 DIR0
-ALL 194.242.100.0/23 DIR0
-ALL 194.242.102.0/24 DIR0
-ALL 194.242.116.0/22 DIR0
-ALL 194.246.99.0/24 DIR0
-ALL 194.246.104.0/23 DIR0
-ALL 194.246.116.0/23 DIR0
-ALL 194.246.120.0/23 DIR0
-ALL 195.2.236.0/23 DIR0
-ALL 195.2.242.0/23 DIR0
-ALL 195.3.128.0/21 DIR0
-ALL 195.3.148.0/22 DIR0
-ALL 195.3.156.0/22 DIR0
-ALL 195.3.196.0/22 DIR0
-ALL 195.3.204.0/22 DIR0
-ALL 195.3.236.0/22 DIR0
-ALL 195.3.244.0/22 DIR0
-ALL 195.5.108.0/23 DIR0
-ALL 195.5.124.0/23 DIR0
-ALL 195.5.184.0/24 DIR0
-ALL 195.8.200.0/23 DIR0
-ALL 195.8.218.0/23 DIR0
-ALL 195.9.87.0/24 DIR0
-ALL 195.9.247.0/24 DIR0
-ALL 195.10.210.0/24 DIR0
-ALL 195.10.218.0/24 DIR0
-ALL 195.12.36.0/22 DIR0
-ALL 195.14.17.0/24 DIR0
-ALL 195.20.4.0/22 DIR0
-ALL 195.20.28.0/22 DIR0
-ALL 195.20.96.0/23 DIR0
-ALL 195.20.100.0/22 DIR0
-ALL 195.20.118.0/23 DIR0
-ALL 195.20.124.0/23 DIR0
-ALL 195.20.128.0/19 DIR0
-ALL 195.22.112.0/22 DIR0
-ALL 195.22.130.0/23 DIR0
-ALL 195.22.132.0/23 DIR0
-ALL 195.22.140.0/23 DIR0
-ALL 195.24.128.0/19 DIR0
-ALL 195.24.234.0/24 DIR0
-ALL 195.24.252.0/23 DIR0
-ALL 195.26.16.0/22 DIR0
-ALL 195.26.64.0/22 DIR0
-ALL 195.26.80.0/21 DIR0
-ALL 195.26.92.0/22 DIR0
-ALL 195.28.0.0/23 DIR0
-ALL 195.28.186.0/23 DIR0
-ALL 195.34.74.0/23 DIR0
-ALL 195.34.90.0/23 DIR0
-ALL 195.34.94.0/23 DIR0
-ALL 195.34.196.0/22 DIR0
-ALL 195.34.204.0/22 DIR0
-ALL 195.35.65.0/24 DIR0
-ALL 195.38.16.0/23 DIR0
-ALL 195.38.18.0/24 DIR0
-ALL 195.39.196.0/23 DIR0
-ALL 195.39.210.0/23 DIR0
-ALL 195.39.214.0/23 DIR0
-ALL 195.39.232.0/23 DIR0
-ALL 195.39.240.0/22 DIR0
-ALL 195.39.248.0/23 DIR0
-ALL 195.39.252.0/23 DIR0
-ALL 195.42.126.0/23 DIR0
-ALL 195.42.130.0/23 DIR0
-ALL 195.42.136.0/23 DIR0
-ALL 195.43.40.0/22 DIR0
-ALL 195.43.146.0/24 DIR0
-ALL 195.43.148.0/24 DIR0
-ALL 195.46.56.0/22 DIR0
-ALL 195.47.202.0/24 DIR0
-ALL 195.47.219.0/24 DIR0
-ALL 195.47.248.0/24 DIR0
-ALL 195.47.253.0/24 DIR0
-ALL 195.49.128.0/22 DIR0
-ALL 195.49.148.0/22 DIR0
-ALL 195.49.164.0/22 DIR0
-ALL 195.58.224.0/19 DIR0
-ALL 195.60.66.0/23 DIR0
-ALL 195.60.70.0/23 DIR0
-ALL 195.60.174.0/23 DIR0
-ALL 195.60.184.0/23 DIR0
-ALL 195.60.200.0/23 DIR0
-ALL 195.60.224.0/24 DIR0
-ALL 195.60.226.0/24 DIR0
-ALL 195.62.14.0/23 DIR0
-ALL 195.62.24.0/23 DIR0
-ALL 195.62.36.0/23 DIR0
-ALL 195.64.136.0/23 DIR0
-ALL 195.64.142.0/23 DIR0
-ALL 195.64.148.0/23 DIR0
-ALL 195.64.166.0/23 DIR0
-ALL 195.64.190.0/23 DIR0
-ALL 195.64.224.0/19 DIR0
-ALL 195.66.65.0/24 DIR0
-ALL 195.66.66.0/24 DIR0
-ALL 195.66.79.0/24 DIR0
-ALL 195.66.87.0/24 DIR0
-ALL 195.66.93.0/24 DIR0
-ALL 195.66.105.0/24 DIR0
-ALL 195.66.136.0/23 DIR0
-ALL 195.66.140.0/23 DIR0
-ALL 195.66.152.0/23 DIR0
-ALL 195.66.156.0/23 DIR0
-ALL 195.66.192.0/19 DIR0
-ALL 195.68.196.0/23 DIR0
-ALL 195.68.202.0/23 DIR0
-ALL 195.68.210.0/23 DIR0
-ALL 195.68.216.0/22 DIR0
-ALL 195.68.222.0/23 DIR0
-ALL 195.69.76.0/22 DIR0
-ALL 195.69.84.0/22 DIR0
-ALL 195.69.132.0/22 DIR0
-ALL 195.69.168.0/22 DIR0
-ALL 195.69.176.0/23 DIR0
-ALL 195.69.179.0/24 DIR0
-ALL 195.69.184.0/22 DIR0
-ALL 195.69.196.0/22 DIR0
-ALL 195.69.200.0/22 DIR0
-ALL 195.69.220.0/22 DIR0
-ALL 195.69.244.0/22 DIR0
-ALL 195.69.248.0/22 DIR0
-ALL 195.72.144.0/22 DIR0
-ALL 195.72.156.0/22 DIR0
-ALL 195.74.67.0/24 DIR0
-ALL 195.78.38.0/23 DIR0
-ALL 195.78.58.0/23 DIR0
-ALL 195.78.68.0/23 DIR0
-ALL 195.78.92.0/23 DIR0
-ALL 195.78.232.0/22 DIR0
-ALL 195.78.244.0/22 DIR0
-ALL 195.78.252.0/23 DIR0
-ALL 195.80.231.0/24 DIR0
-ALL 195.80.232.0/24 DIR0
-ALL 195.82.150.0/23 DIR0
-ALL 195.85.198.0/24 DIR0
-ALL 195.85.214.0/24 DIR0
-ALL 195.85.219.0/24 DIR0
-ALL 195.85.250.0/24 DIR0
-ALL 195.90.122.0/23 DIR0
-ALL 195.93.138.0/23 DIR0
-ALL 195.93.154.0/23 DIR0
-ALL 195.93.160.0/23 DIR0
-ALL 195.93.172.0/23 DIR0
-ALL 195.93.184.0/23 DIR0
-ALL 195.93.190.0/23 DIR0
-ALL 195.93.204.0/23 DIR0
-ALL 195.93.212.0/22 DIR0
-ALL 195.95.139.0/24 DIR0
-ALL 195.95.147.0/24 DIR0
-ALL 195.95.151.0/24 DIR0
-ALL 195.95.157.0/24 DIR0
-ALL 195.95.165.0/24 DIR0
-ALL 195.95.171.0/24 DIR0
-ALL 195.95.189.0/24 DIR0
-ALL 195.95.206.0/23 DIR0
-ALL 195.95.210.0/23 DIR0
-ALL 195.95.222.0/23 DIR0
-ALL 195.95.232.0/23 DIR0
-ALL 195.110.6.0/23 DIR0
-ALL 195.114.6.0/23 DIR0
-ALL 195.114.30.0/23 DIR0
-ALL 195.114.96.0/23 DIR0
-ALL 195.114.120.0/23 DIR0
-ALL 195.114.128.0/19 DIR0
-ALL 195.123.0.0/16 DIR0
-ALL 195.128.16.0/22 DIR0
-ALL 195.128.56.0/21 DIR0
-ALL 195.128.178.0/23 DIR0
-ALL 195.128.182.0/23 DIR0
-ALL 195.128.230.0/23 DIR0
-ALL 195.128.248.0/23 DIR0
-ALL 195.128.252.0/23 DIR0
-ALL 195.135.196.0/22 DIR0
-ALL 195.137.167.0/24 DIR0
-ALL 195.137.192.0/23 DIR0
-ALL 195.137.196.0/23 DIR0
-ALL 195.137.202.0/23 DIR0
-ALL 195.137.226.0/23 DIR0
-ALL 195.137.232.0/23 DIR0
-ALL 195.137.240.0/23 DIR0
-ALL 195.137.244.0/23 DIR0
-ALL 195.137.250.0/23 DIR0
-ALL 195.138.64.0/19 DIR0
-ALL 195.138.160.0/19 DIR0
-ALL 195.138.193.0/24 DIR0
-ALL 195.138.198.0/24 DIR0
-ALL 195.138.217.0/24 DIR0
-ALL 195.138.218.0/24 DIR0
-ALL 195.140.160.0/22 DIR0
-ALL 195.140.168.0/22 DIR0
-ALL 195.140.176.0/22 DIR0
-ALL 195.140.224.0/22 DIR0
-ALL 195.140.244.0/22 DIR0
-ALL 195.144.6.0/24 DIR0
-ALL 195.144.21.0/24 DIR0
-ALL 195.144.25.0/24 DIR0
-ALL 195.144.28.0/24 DIR0
-ALL 195.149.70.0/24 DIR0
-ALL 195.149.90.0/24 DIR0
-ALL 195.149.96.0/24 DIR0
-ALL 195.149.108.0/23 DIR0
-ALL 195.149.112.0/24 DIR0
-ALL 195.149.114.0/24 DIR0
-ALL 195.149.125.0/24 DIR0
-ALL 195.160.192.0/22 DIR0
-ALL 195.160.220.0/22 DIR0
-ALL 195.160.232.0/22 DIR0
-ALL 195.177.68.0/22 DIR0
-ALL 195.177.72.0/22 DIR0
-ALL 195.177.92.0/22 DIR0
-ALL 195.177.112.0/21 DIR0
-ALL 195.177.124.0/22 DIR0
-ALL 195.177.208.0/23 DIR0
-ALL 195.177.222.0/23 DIR0
-ALL 195.177.236.0/22 DIR0
-ALL 195.177.240.0/23 DIR0
-ALL 195.178.128.0/19 DIR0
-ALL 195.182.0.0/24 DIR0
-ALL 195.182.7.0/24 DIR0
-ALL 195.182.21.0/24 DIR0
-ALL 195.182.22.0/24 DIR0
-ALL 195.182.192.0/22 DIR0
-ALL 195.184.70.0/24 DIR0
-ALL 195.184.80.0/23 DIR0
-ALL 195.184.192.0/19 DIR0
-ALL 195.189.8.0/22 DIR0
-ALL 195.189.16.0/22 DIR0
-ALL 195.189.44.0/22 DIR0
-ALL 195.189.48.0/22 DIR0
-ALL 195.189.60.0/22 DIR0
-ALL 195.189.96.0/22 DIR0
-ALL 195.189.104.0/22 DIR0
-ALL 195.189.200.0/23 DIR0
-ALL 195.189.214.0/23 DIR0
-ALL 195.189.226.0/23 DIR0
-ALL 195.189.228.0/23 DIR0
-ALL 195.189.234.0/23 DIR0
-ALL 195.189.240.0/23 DIR0
-ALL 195.189.246.0/23 DIR0
-ALL 195.189.248.0/23 DIR0
-ALL 195.190.13.0/24 DIR0
-ALL 195.200.64.0/23 DIR0
-ALL 195.200.90.0/23 DIR0
-ALL 195.200.196.0/24 DIR0
-ALL 195.200.221.0/24 DIR0
-ALL 195.206.224.0/21 DIR0
-ALL 195.214.192.0/21 DIR0
-ALL 195.214.208.0/21 DIR0
-ALL 195.214.220.0/22 DIR0
-ALL 195.214.236.0/22 DIR0
-ALL 195.216.204.0/23 DIR0
-ALL 195.216.206.0/24 DIR0
-ALL 195.216.210.0/23 DIR0
-ALL 195.216.212.0/23 DIR0
-ALL 195.216.226.0/24 DIR0
-ALL 195.216.248.0/24 DIR0
-ALL 195.225.52.0/23 DIR0
-ALL 195.225.96.0/22 DIR0
-ALL 195.225.112.0/22 DIR0
-ALL 195.225.144.0/22 DIR0
-ALL 195.225.156.0/22 DIR0
-ALL 195.225.228.0/22 DIR0
-ALL 195.230.96.0/24 DIR0
-ALL 195.230.103.0/24 DIR0
-ALL 195.230.115.0/24 DIR0
-ALL 195.230.128.0/19 DIR0
-ALL 195.234.61.0/24 DIR0
-ALL 195.234.68.0/22 DIR0
-ALL 195.234.72.0/22 DIR0
-ALL 195.234.112.0/22 DIR0
-ALL 195.234.132.0/24 DIR0
-ALL 195.234.148.0/24 DIR0
-ALL 195.234.174.0/24 DIR0
-ALL 195.234.200.0/22 DIR0
-ALL 195.234.212.0/22 DIR0
-ALL 195.234.220.0/22 DIR0
-ALL 195.238.92.0/23 DIR0
-ALL 195.238.176.0/21 DIR0
-ALL 195.238.188.0/22 DIR0
-ALL 195.242.94.0/23 DIR0
-ALL 195.242.112.0/22 DIR0
-ALL 195.242.148.0/22 DIR0
-ALL 195.242.161.0/24 DIR0
-ALL 195.242.200.0/22 DIR0
-ALL 195.244.4.0/23 DIR0
-ALL 195.244.8.0/23 DIR0
-ALL 195.245.76.0/23 DIR0
-ALL 195.245.80.0/23 DIR0
-ALL 195.245.96.0/23 DIR0
-ALL 195.245.112.0/23 DIR0
-ALL 195.245.118.0/23 DIR0
-ALL 195.245.120.0/23 DIR0
-ALL 195.245.200.0/24 DIR0
-ALL 195.245.215.0/24 DIR0
-ALL 195.245.221.0/24 DIR0
-ALL 195.245.249.0/24 DIR0
-ALL 195.245.253.0/24 DIR0
-ALL 195.246.104.0/23 DIR0
-ALL 195.246.217.0/24 DIR0
-ALL 195.248.93.0/24 DIR0
-ALL 195.248.160.0/19 DIR0
-ALL 195.248.234.0/23 DIR0
-ALL 195.250.36.0/24 DIR0
-ALL 195.250.43.0/24 DIR0
-ALL 195.250.62.0/24 DIR0
-ALL 195.254.142.0/23 DIR0
-ALL 195.254.150.0/23 DIR0
-ALL 209.62.181.0/24 DIR0
-ALL 209.62.187.0/24 DIR0
-ALL 209.62.189.0/24 DIR0
-ALL 209.85.128.0/17 DIR0
-ALL 212.1.64.0/18 DIR0
-ALL 212.2.128.0/19 DIR0
-ALL 212.3.96.0/19 DIR0
-ALL 212.8.32.0/19 DIR0
-ALL 212.9.224.0/19 DIR0
-ALL 212.15.128.0/19 DIR0
-ALL 212.22.192.0/20 DIR0
-ALL 212.26.128.0/19 DIR0
-ALL 212.28.64.0/19 DIR0
-ALL 212.35.160.0/19 DIR0
-ALL 212.40.32.0/19 DIR0
-ALL 212.42.64.0/19 DIR0
-ALL 212.58.160.0/19 DIR0
-ALL 212.66.32.0/19 DIR0
-ALL 212.68.160.0/19 DIR0
-ALL 212.74.234.0/24 DIR0
-ALL 212.80.32.0/19 DIR0
-ALL 212.82.192.0/19 DIR0
-ALL 212.86.96.0/19 DIR0
-ALL 212.86.225.0/24 DIR0
-ALL 212.86.226.0/24 DIR0
-ALL 212.86.228.0/22 DIR0
-ALL 212.86.232.0/21 DIR0
-ALL 212.86.240.0/20 DIR0
-ALL 212.87.160.0/19 DIR0
-ALL 212.90.96.0/20 DIR0
-ALL 212.90.112.0/23 DIR0
-ALL 212.90.116.0/23 DIR0
-ALL 212.90.124.0/22 DIR0
-ALL 212.90.160.0/19 DIR0
-ALL 212.92.224.0/19 DIR0
-ALL 212.109.32.0/19 DIR0
-ALL 212.111.192.0/19 DIR0
-ALL 212.113.32.0/20 DIR0
-ALL 212.115.224.0/19 DIR0
-ALL 212.178.0.0/19 DIR0
-ALL 213.130.0.0/20 DIR0
-ALL 213.130.16.0/23 DIR0
-ALL 213.130.18.0/24 DIR0
-ALL 213.130.20.0/22 DIR0
-ALL 213.130.24.0/21 DIR0
-ALL 213.133.160.0/19 DIR0
-ALL 213.135.64.0/23 DIR0
-ALL 213.135.67.0/24 DIR0
-ALL 213.135.68.0/22 DIR0
-ALL 213.135.72.0/21 DIR0
-ALL 213.151.0.0/19 DIR0
-ALL 213.154.192.0/19 DIR0
-ALL 213.155.0.0/19 DIR0
-ALL 213.156.64.0/19 DIR0
-ALL 213.159.224.0/19 DIR0
-ALL 213.160.128.0/19 DIR0
-ALL 213.169.64.0/19 DIR0
-ALL 213.180.192.0/19 DIR0
-ALL 213.186.112.0/20 DIR0
-ALL 213.186.192.0/19 DIR0
-ALL 213.200.32.0/23 DIR0
-ALL 213.200.43.0/24 DIR0
-ALL 213.208.160.0/19 DIR0
-ALL 213.227.192.0/18 DIR0
-ALL 213.231.0.0/18 DIR0
-ALL 213.238.0.0/22 DIR0
-ALL 213.238.16.0/24 DIR0
-ALL 213.238.20.0/24 DIR0
-ALL 213.238.24.0/24 DIR0
-ALL 213.238.28.0/24 DIR0
-ALL 216.73.80.0/24 DIR0
-ALL 216.73.87.0/24 DIR0
-ALL 216.239.32.0/19 DIR0
-ALL 217.9.0.0/24 DIR0
-ALL 217.9.4.0/24 DIR0
-ALL 217.12.192.0/19 DIR0
-ALL 217.19.208.0/20 DIR0
-ALL 217.24.160.0/20 DIR0
-ALL 217.25.192.0/20 DIR0
-ALL 217.27.144.0/20 DIR0
-ALL 217.28.254.0/24 DIR0
-ALL 217.65.240.0/21 DIR0
-ALL 217.66.96.0/20 DIR0
-ALL 217.73.128.0/20 DIR0
-ALL 217.76.192.0/20 DIR0
-ALL 217.77.208.0/20 DIR0
-ALL 217.112.208.0/20 DIR0
-ALL 217.114.32.0/20 DIR0
-ALL 217.117.64.0/20 DIR0
-ALL 217.144.64.0/20 DIR0
-ALL 217.146.240.0/20 DIR0
-ALL 217.147.160.0/21 DIR0
-ALL 217.147.168.0/24 DIR0
-ALL 217.175.80.0/20 DIR0
-ALL 217.196.160.0/20 DIR0
-ALL 217.198.128.0/20 DIR0
-ALL 217.199.208.0/20 DIR0
-ALL 217.199.224.0/20 DIR0
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.1.1.1 $
- $Date: 2009/02/24 08:13:03 $
- $Author: faust $
- */
-
-#include <fstream>
-#include <sstream>
-#include <cstdlib>
-#include <limits>
-#include <cerrno>
-#include <locale>
-
-#include <arpa/inet.h>
-#include <netdb.h>
-
-#include "rules.h"
-#include "utils.h"
-
-using namespace std;
-
-STG::RULES_PARSER::RULES_PARSER()
- : rules(),
- error(false),
- errorStream(""),
- protocols()
-{
-error = InitProtocols();
-}
-
-STG::RULES_PARSER::RULES_PARSER(const string & fileName)
- : rules(),
- error(false),
- errorStream(""),
- protocols()
-{
-error = InitProtocols();
-SetFile(fileName);
-}
-
-void STG::RULES_PARSER::SetFile(const string & fileName)
-{
-errorStream.str("");
-
-ifstream rulesFile(fileName.c_str());
-
-int lineNumber = 0;
-
-if (!rulesFile)
- {
- error = true;
- errorStream << "RULES_PARSER::SetFile - Error opening file '" << fileName << "'\n";
- return;
- }
-
-string line;
-
-rules.erase(rules.begin(), rules.end());
-
-while (getline(rulesFile, line))
- {
- lineNumber++;
- if (ParseLine(line))
- {
- error = true;
- errorStream << "RULES_PARSER::SetFile - Error parsing line at '" << fileName << ":" << lineNumber << "'\n";
- return;
- }
- }
-
-STG::RULE rule;
-
-// Adding lastest rule: ALL 0.0.0.0/0 NULL
-rule.dir = -1; //NULL
-rule.ip = 0; //0.0.0.0
-rule.mask = 0;
-rule.port1 = 0;
-rule.port2 = 65535;
-rule.proto = -1;
-
-rules.push_back(rule);
-
-errorStream.str("");
-
-return;
-}
-
-bool STG::RULES_PARSER::ParseLine(string line)
-{
-size_t pos;
-
-pos = line.find('#');
-if (pos != string::npos)
- {
- line = line.substr(0, pos);
- }
-
-if (line.empty())
- {
- return false;
- }
-
-size_t lpos = line.find_first_not_of("\t ", 0, 2);
-
-if (lpos == string::npos)
- {
- return false;
- }
-
-size_t rpos = line.find_first_of("\t ", lpos, 2);
-
-if (rpos == string::npos)
- {
- return false;
- }
-
-string proto(line.begin() + lpos, line.begin() + rpos);
-
-lpos = line.find_first_not_of("\t ", rpos, 2);
-
-if (lpos == string::npos)
- {
- return false;
- }
-
-rpos = line.find_first_of("\t ", lpos, 2);
-
-if (rpos == string::npos)
- {
- return false;
- }
-
-string address(line.begin() + lpos, line.begin() + rpos);
-
-lpos = line.find_first_not_of("\t ", rpos, 2);
-
-if (lpos == string::npos)
- {
- return false;
- }
-string direction(line.begin() + lpos, line.end());
-
-if (proto.empty() ||
- address.empty() ||
- direction.empty())
- {
- return false;
- }
-
-map<string, int>::const_iterator it(protocols.find(proto));
-
-if (it == protocols.end())
- {
- errorStream << "RULES_PARSER::ParseLine - Invalid protocol\n";
- return true;
- }
-
-STG::RULE rule;
-
-rule.proto = it->second;
-
-if (direction.length() < 4)
- {
- errorStream << "RULES_PARSER::ParseLine - Invalid direction\n";
- return true;
- }
-
-if (direction == "NULL")
- {
- rule.dir = -1;
- }
-else
- {
- string prefix(direction.begin(), direction.begin() + 3);
- direction = direction.substr(3, direction.length() - 3);
- if (prefix != "DIR")
- {
- errorStream << "RULES_PARSER::ParseLine - Invalid direction prefix\n";
- return true;
- }
- char * endptr;
- /*
- * 'cause strtol don't change errno on success
- * according to: http://www.opengroup.org/onlinepubs/000095399/functions/strtol.html
- */
- errno = 0;
- rule.dir = strtol(direction.c_str(), &endptr, 10);
-
- // Code from strtol(3) release 3.10
- if ((errno == ERANGE && (rule.dir == numeric_limits<int>::max() ||
- rule.dir == numeric_limits<int>::min()))
- || (errno != 0 && rule.dir == 0))
- {
- errorStream << "RULES_PARSER::ParseLine - Direction out of range\n";
- return true;
- }
- if (endptr == direction.c_str())
- {
- errorStream << "RULES_PARSER::ParseLine - Invalid direction\n";
- return true;
- }
- }
-
-if (ParseAddress(address, &rule))
- {
- errorStream << "RULES_PARSER::ParseLine - Invalid address\n";
- return true;
- }
-
-rules.push_back(rule);
-
-return false;
-}
-
-bool STG::RULES_PARSER::ParseAddress(const string & address, RULE * rule) const
-{
-// Format: <address>[/<mask>[:<port1>[-<port2>]]]
-size_t pos = address.find('/');
-string ip;
-string mask;
-string ports;
-
-if (pos != string::npos)
- {
- ip = address.substr(0, pos);
- mask = address.substr(pos + 1, address.length() - pos - 1);
- pos = mask.find(':');
- if (pos != string::npos)
- {
- ports = mask.substr(pos + 1, mask.length() - pos - 1);
- mask = mask.substr(0, pos);
- }
- else
- {
- ports = "0-65535";
- }
- }
-else
- {
- mask = "32";
- pos = address.find(':');
- if (pos != string::npos)
- {
- ip = address.substr(0, pos);
- ports = address.substr(pos + 1, address.length() - pos - 1);
- }
- else
- {
- ip = address;
- ports = "0-65536";
- }
- }
-
-struct in_addr ipaddr;
-
-if (!inet_aton(ip.c_str(), &ipaddr))
- {
- errorStream << "RULES_PARSER::ParseAddress - Invalid IP\n";
- return true;
- }
-
-rule->ip = ntohl(ipaddr.s_addr);
-
-if (ParseMask(mask, rule))
- {
- errorStream << "RULES_PARSER::ParseAddress - Error parsing mask\n";
- return true;
- }
-
-pos = ports.find('-');
-string port1;
-string port2;
-
-if (pos != string::npos)
- {
- port1 = ports.substr(0, pos);
- port2 = ports.substr(pos + 1, ports.length() - pos - 1);
- }
-else
- {
- port1 = port2 = ports;
- }
-
-if (ParsePorts(port1, port2, rule))
- {
- errorStream << "RULES_PARSER::ParseAddress - Error pasing ports\n";
- return true;
- }
-
-return false;
-}
-
-bool STG::RULES_PARSER::ParseMask(const string & mask, RULE * rule) const
-{
-char * endptr;
-
-errno = 0;
-/*
- * 'cause strtol don't change errno on success
- * according to: http://www.opengroup.org/onlinepubs/000095399/functions/strtol.html
- */
-rule->mask = strtol(mask.c_str(), &endptr, 10);
-
-if ((errno == ERANGE && (rule->mask == numeric_limits<uint32_t>::max() ||
- rule->mask == numeric_limits<uint32_t>::min()))
- || (errno != 0 && rule->mask == 0))
- {
- errorStream << "RULES_PARSER::ParseMask - Mask is out of range\n";
- return true;
- }
-
-if (endptr == NULL)
- {
- errorStream << "RULES_PARSER::ParseMask - NULL endptr\n";
- return true;
- }
-
-if (*endptr != '\0')
- {
- errorStream << "RULES_PARSER::ParseMask - Invalid mask\n";
- return true;
- }
-
-if (rule->mask > 32)
- {
- errorStream << "RULES_PARSER::ParseMask - Mask is greater than 32\n";
- return true;
- }
-
-rule->mask = 0xffFFffFF >> (32 - rule->mask);
-
-return false;
-}
-
-bool STG::RULES_PARSER::ParsePorts(const string & port1,
- const string & port2,
- RULE * rule) const
-{
-char * endptr;
-
-errno = 0;
-/*
- * 'cause strtol don't change errno on success
- * according to: http://www.opengroup.org/onlinepubs/000095399/functions/strtol.html
- */
-rule->port1 = strtol(port1.c_str(), &endptr, 10);
-
-if ((errno == ERANGE && (rule->port1 == numeric_limits<uint16_t>::max() ||
- rule->port1 == numeric_limits<uint16_t>::min()))
- || (errno != 0 && rule->port1 == 0))
- {
- errorStream << "RULES_PARSER::ParsePorts - Min port is out of range\n";
- return true;
- }
-
-if (endptr == NULL)
- {
- errorStream << "RULES_PARSER::ParsePorts - NULL endptr on min port\n";
- return true;
- }
-
-if (*endptr != '\0')
- {
- errorStream << "RULES_PARSER::ParsePorts - Invalid min port\n";
- return true;
- }
-
-errno = 0;
-/*
- * 'cause strtol don't change errno on success
- * according to: http://www.opengroup.org/onlinepubs/000095399/functions/strtol.html
- */
-rule->port2 = strtol(port2.c_str(), &endptr, 10);
-
-if ((errno == ERANGE && (rule->port2 == numeric_limits<uint16_t>::max() ||
- rule->port2 == numeric_limits<uint16_t>::min()))
- || (errno != 0 && rule->port2 == 0))
- {
- errorStream << "RULES_PARSER::ParseAddress - Max port is out of range\n";
- return true;
- }
-
-if (endptr == NULL)
- {
- errorStream << "RULES_PARSER::ParsePorts - NULL endptr on max port\n";
- return true;
- }
-
-if (*endptr != '\0')
- {
- errorStream << "RULES_PARSER::ParsePorts - Invalid max port\n";
- return true;
- }
-
-return false;
-}
-
-bool STG::RULES_PARSER::InitProtocols()
-{
-struct protoent * pe;
-
-locale loc("");
-
-protocols.erase(protocols.begin(), protocols.end());
-
-setprotoent(true); // Open link to /etc/protocols
-
-while ((pe = getprotoent()) != NULL)
- {
- string proto(pe->p_name);
- protocols.insert(make_pair(STG::ToUpper(pe->p_name, loc), pe->p_proto));
- }
-
-endprotoent();
-
-protocols["ALL"] = -1;
-protocols["TCP_UDP"] = -2;
-
-errorStream.str("");
-
-return protocols.empty();
-}
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.1.1.1 $
- $Date: 2009/02/24 08:13:03 $
- $Author: faust $
- */
-
-
-#ifndef __RULES_H__
-#define __RULES_H__
-
-#include <list>
-#include <string>
-#include <sstream>
-#include <map>
-
-#ifdef HAVE_STDINT
- #include <stdint.h>
-#else
- #ifdef HAVE_INTTYPES
- #include <inttypes.h>
- #else
- #error "You need either stdint.h or inttypes.h to compile this!"
- #endif
-#endif
-
-namespace STG
-{
-
- //-----------------------------------------------------------------------------
- struct RULE
- {
- uint32_t ip; // IP
- uint32_t mask; // Netmask
- uint16_t port1; // Port 1
- uint16_t port2; // Port 2
- int proto; // Protocol
- int dir; // Direction
- };
- //-----------------------------------------------------------------------------
- typedef std::list<RULE> RULES;
- //-----------------------------------------------------------------------------
- class RULES_PARSER
- {
- public:
- RULES_PARSER();
-
- RULES_PARSER(const std::string & fileName);
-
- ~RULES_PARSER() {};
-
- void SetFile(const std::string & fileName);
-
- const RULES & GetRules() const { return rules; };
- bool IsError() const { return error; };
- const std::string ErrorMsg() const { return errorStream.str(); };
-
- private:
- RULES rules;
- bool error;
- mutable std::stringstream errorStream;
- std::map<std::string, int> protocols;
-
- bool InitProtocols();
- bool ParseLine(std::string line);
- bool ParseAddress(const std::string & address, RULE * rule) const;
- bool ParseMask(const std::string & mask, RULE * rule) const;
- bool ParsePorts(const std::string & port1,
- const std::string & port2,
- RULE * rule) const;
- };
-
-}
-
-#endif // __RULES_H__
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.3 $
- $Date: 2009/10/12 08:46:05 $
- $Author: faust $
- */
-
-#include "rules_finder.h"
-#include "logger.h"
-#include "lock.h"
-
-STG::RULES_FINDER::RULES_FINDER()
-{
- pthread_mutex_init(&mutex, NULL);
-}
-
-STG::RULES_FINDER::~RULES_FINDER()
-{
- pthread_mutex_destroy(&mutex);
-}
-
-void STG::RULES_FINDER::SetRules(const RULES & r)
-{
-SCOPED_LOCK lock(mutex);
-rules = r;
-}
-
-int STG::RULES_FINDER::GetDir(const PENDING_PACKET & packet) const
-{
-bool addrMatch;
-bool portMatch;
-
-STG::RULES::const_iterator ln;
-int ruleLine(1);
-
-SCOPED_LOCK lock(mutex);
-
-ln = rules.begin();
-
-while (ln != rules.end())
- {
- addrMatch = false;
- portMatch = false;
-
- // Port range
- switch (packet.direction) {
- case PENDING_PACKET::INCOMING:
- portMatch = (packet.sport >= ln->port1) &&
- (packet.sport <= ln->port2);
- break;
- case PENDING_PACKET::OUTGOING:
- portMatch = (packet.dport >= ln->port1) &&
- (packet.dport <= ln->port2);
- break;
- case PENDING_PACKET::LOCAL:
- portMatch = ((packet.sport >= ln->port1) &&
- (packet.sport <= ln->port2)) ||
- ((packet.dport >= ln->port1) &&
- (packet.dport <= ln->port2));
- break;
- default:
- ++ruleLine;
- ++ln;
- continue;
- }
-
- if (!portMatch) {
- ++ruleLine;
- ++ln;
- continue;
- }
-
- /*portMatch = ((packet.sport >= ln->port1) &&
- (packet.sport <= ln->port2) &&
- (packet.direction == PENDING_PACKET::INCOMING)) ||
- ((packet.dport >= ln->port1) &&
- (packet.dport <= ln->port2) &&
- (packet.direction == PENDING_PACKET::OUTGOING));*/
-
- if (ln->proto != packet.proto)
- {
- // Is it a normal protcol number?
- if (ln->proto >= 0)
- {
- ++ruleLine;
- ++ln;
- continue;
- }
- else if (ln->proto == -2)
- {
- // -2 - TCP_UDP
- if (packet.proto != 6 &&
- packet.proto != 17)
- {
- ++ruleLine;
- ++ln;
- continue;
- }
- }
- // -1 - ALL
- }
-
- switch (packet.direction) {
- case PENDING_PACKET::INCOMING:
- // From outer world to us
- addrMatch = (packet.saddr & ln->mask) == ln->ip;
- break;
- case PENDING_PACKET::OUTGOING:
- // From us to outer world
- addrMatch = (packet.daddr & ln->mask) == ln->ip;
- break;
- case PENDING_PACKET::LOCAL:
- // From us to us
- addrMatch = (packet.saddr & ln->mask) == ln->ip ||
- (packet.daddr & ln->mask) == ln->ip;
- break;
- default:
- // From outer world to outer world
- ++ruleLine;
- ++ln;
- continue;
- }
-
-
- if (addrMatch)
- {
- // At this point ports and protocol are matched
- return ln->dir;
- }
-
- ++ruleLine;
- ++ln;
- } //while (ln != rules.end())
-
-return -1;
-}
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.2 $
- $Date: 2009/02/26 18:32:59 $
- $Author: faust $
- */
-
-
-#ifndef __RULES_FINDER_H__
-#define __RULES_FINDER_H__
-
-#include <pthread.h>
-
-#include "rules.h"
-#include "tc_packets.h"
-
-namespace STG
-{
-
- class RULES_FINDER
- {
- public:
- RULES_FINDER();
- ~RULES_FINDER();
-
- void SetRules(const RULES & r);
-
- int GetDir(const PENDING_PACKET & packet) const;
-
- private:
- RULES rules;
- mutable pthread_mutex_t mutex;
- };
-
-}
-
-#endif
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.1.1.1 $
- $Date: 2009/02/24 08:13:03 $
- $Author: faust $
- */
-
-#include <iostream>
-#include <cstdlib>
-#include <string>
-#include <map>
-#include <algorithm>
-#include <functional>
-
-#include "rules.h"
-#include "logger.h"
-
-using namespace STG;
-
-STGLogger log;
-
-typedef std::pair<std::string, bool> TEST_ENTRY;
-struct TEST_INFO {
- bool wantedError;
- bool actualError; // Parser error status
- bool stdException; // Parser throws an std execption
- bool otherException; // Parser throws another exception
- std::string message; // Parser error message
-};
-
-class RULES_PARSER_TESTER : public std::unary_function<std::pair<std::string, bool>, void> {
-public:
- RULES_PARSER_TESTER(RULES_PARSER & p) : parser(p),
- testLog(),
- testResult(),
- result(true)
- {
- };
- ~RULES_PARSER_TESTER()
- {
- PrintLog();
- if (result)
- exit(EXIT_SUCCESS);
- exit(EXIT_FAILURE);
- }
- void operator()(const std::pair<std::string, bool> & entry)
- {
- testLog[entry.first].wantedError = entry.second;
- testLog[entry.first].actualError = false;
- testLog[entry.first].stdException = false;
- testLog[entry.first].otherException = false;
- testLog[entry.first].message = "";
- testResult[entry.first] = true;
- try
- {
- parser.SetFile(entry.first);
- }
- catch (std::exception & ex)
- {
- testLog[entry.first].stdException = true;
- testResult[entry.first] &= false;
- }
- catch (...)
- {
- testLog[entry.first].otherException = true;
- testResult[entry.first] &= false;
- }
- testLog[entry.first].actualError = parser.IsError();
- testLog[entry.first].message = parser.ErrorMsg();
- testResult[entry.first] &= (parser.IsError() == entry.second);
- result &= testResult[entry.first];
- };
-
- void PrintLog()
- {
- std::cout << "RULES_PARSER_TESTER results:\n";
- std::cout << "-----------------------------------------------------------------\n";
- std::map<std::string, bool>::const_iterator it;
- for (it = testResult.begin(); it != testResult.end(); ++it)
- {
- std::cout << "File: '" << it->first << "'\t"
- << "Correct: " << testLog[it->first].wantedError << "\t"
- << "Actual:" << testLog[it->first].actualError << "\t"
- << "STD exceptions: " << testLog[it->first].stdException << "\t"
- << "Other exceptions: " << testLog[it->first].otherException << "\t"
- << "Result: " << it->second << "\n";
- if (!testLog[it->first].message.empty())
- {
- std::cout << "Messages: \n" << testLog[it->first].message << "\n";
- }
- }
- std::cout << "-----------------------------------------------------------------\n";
- std::cout << "Final result: " << (result ? "passed" : "failed") << std::endl;
- }
-
- bool Result() const { return result; };
-private:
- RULES_PARSER & parser;
- std::map<std::string, TEST_INFO> testLog;
- std::map<std::string, bool> testResult;
- bool result;
-};
-
-int main(int argc, char ** argv)
-{
-RULES_PARSER parser;
-std::map<std::string, bool> tests;
-
-tests["./test_rules"] = false;
-tests["./rules"] = false;
-tests["./test_rules_bad_address"] = true;
-tests["./test_rules_bad_port"] = true;
-tests["./test_rules_bad_mask"] = true;
-tests["./test_rules_bad_proto"] = true;
-tests["./test_rules_bad_dir_prefix"] = true;
-tests["./test_rules_bad_dir_range"] = true;
-tests["./test_rules_bad_dir"] = true;
-
-/*parser.SetFile("./rules");
-std::cout << parser.ErrorMsg() << std::endl;*/
-
-// TODO: find errors and write checks for regression
-
-std::for_each(tests.begin(),
- tests.end(),
- RULES_PARSER_TESTER(parser));
-
-return EXIT_FAILURE;
-}
+++ /dev/null
- | ips | pendingPackets| sessions | ip2sessions | rules |
-________________|_______________|_______________|_______________|_______________|_______________|
-SetRules | | | | | w |
-________________|_______________|_______________|_______________|_______________|_______________|
-AddPacket | r | w | | | |
-________________|_______________|_______________|_______________|_______________|_______________|
-AddIP | w | | | | |
-________________|_______________|_______________|_______________|_______________|_______________|
-GetIP | | | w | r | |
-________________|_______________|_______________|_______________|_______________|_______________|
-DeleteIP | w | | w | w | |
-________________|_______________|_______________|_______________|_______________|_______________|
-Process | | w | w | w | r |
-________________|_______________|_______________|_______________|_______________|_______________|
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.3 $
- $Date: 2009/04/10 14:14:49 $
- $Author: faust $
- */
-
-
-#ifndef __TC_PACKETS_H__
-#define __TC_PACKETS_H__
-
-#include <netinet/ip.h>
-
-#ifdef HAVE_STDINT
- #include <stdint.h>
-#else
- #ifdef HAVE_INTTYPES
- #include <inttypes.h>
- #else
- #error "You need either stdint.h or inttypes.h to compile this!"
- #endif
-#endif
-
-namespace STG
-{
-
- //-----------------------------------------------------------------------------
- /*
- * Session identifier
- * A session is an amount of bytes transfered in one direction between two
- * fixed addresses by one protocol.
- * In case of UDP/TCP session is also identified by ports.
- */
- struct SESSION_ID
- {
- SESSION_ID()
- : saddr(0),
- daddr(0),
- sport(0),
- dport(0),
- proto(0)
- {
- }
-
- SESSION_ID(const iphdr & ipHdr, uint16_t sp, uint16_t dp)
- : saddr(ipHdr.saddr),
- daddr(ipHdr.daddr),
- sport(sp),
- dport(dp),
- proto(ipHdr.protocol)
- {
- }
-
- uint32_t saddr;
- uint32_t daddr;
- uint16_t sport;
- uint16_t dport;
- uint8_t proto;
-
- bool operator ==(const SESSION_ID & rval)
- {
- return saddr == rval.saddr &&
- sport == rval.sport &&
- daddr == rval.daddr &&
- dport == rval.dport &&
- proto == rval.proto;
- }
- };
- //-----------------------------------------------------------------------------
- /*
- * Ordering functor to use SESSION_ID as key-type in maps
- */
- struct SESSION_LESS
- : public std::binary_function<SESSION_ID, SESSION_ID, bool> {
- bool operator()(const SESSION_ID & lval, const SESSION_ID & rval) const
- {
- if (lval.saddr > rval.saddr)
- return false;
- if (lval.saddr < rval.saddr)
- return true;
- if (lval.daddr > rval.daddr)
- return false;
- if (lval.daddr < rval.daddr)
- return true;
- if (lval.sport > rval.sport)
- return false;
- if (lval.sport < rval.sport)
- return true;
- if (lval.dport > rval.dport)
- return false;
- if (lval.dport < rval.dport)
- return true;
- if (lval.proto > rval.proto)
- return false;
- if (lval.proto < rval.proto)
- return true;
- return false;
- };
- };
- //-----------------------------------------------------------------------------
- /*
- * A packet in the incoming queue
- * Can create a new session or be attached to an existing one
- */
- struct PENDING_PACKET : public SESSION_ID
- {
- PENDING_PACKET()
- {
- }
- PENDING_PACKET(const iphdr & ipHdr, uint16_t sp, uint16_t dp)
- : SESSION_ID(ipHdr, sp, dp),
- length(ipHdr.tot_len),
- direction(FOREIGN)
- {
- }
-
- uint16_t length;
- enum DIRECTION
- {
- INCOMING = 0, // From outer world to user
- OUTGOING, // From user to outer world
- LOCAL, // From user to user
- FOREIGN // From outer world to outer world
- } direction;
- };
- //-----------------------------------------------------------------------------
- /*
- * Session length and meta-information
- * Used to identify data cost
- */
- struct SESSION_DATA
- {
- SESSION_DATA()
- {
- dir = -1; // NULL direction
- length = 0;
- };
-
- SESSION_DATA(const SESSION_DATA & sp)
- {
- dir = sp.dir;
- length = sp.length;
- };
-
- int dir;
- uint32_t length;
- };
- //-----------------------------------------------------------------------------
- /*
- * User-related types
- */
- typedef std::pair<SESSION_ID, SESSION_DATA> TRAFF_ITEM;
- typedef std::list<TRAFF_ITEM> TRAFF_DATA;
-
-}
-
-#endif
+++ /dev/null
-/*
- * Network:
- * - server: 192.168.0.1
- * - user A: 192.168.0.2
- * - user B: 192.168.0.3
- *
- * External resources:
- * - host 1: 216.239.59.104
- * - host 2: 72.14.221.104
- * - host 3: 66.249.93.104
- * - host 4: 195.5.61.68
- *
- * Directions:
- * - Local: ALL 192.168.0.0/24
- * - DNS: TCP_UDP 195.5.61.68/32:53
- * - FTP: TCP 129.22.8.159/32:20-21
- * - World: ALL 0.0.0.0/0
- *
- */
-
-
-
-#include <iostream>
-#include <algorithm>
-#include <functional>
-
-#include <arpa/inet.h>
-#include <netinet/ip.h>
-#include <sys/time.h>
-
-#include "rules.h"
-#include "traffcounter.h"
-#include "logger.h"
-
-using namespace std;
-using namespace STG;
-
-class StatPrinter: public unary_function<const TRAFF_ITEM &, void> {
-public:
- void operator()(const TRAFF_ITEM & item) const
- {
- LOG_IT << inet_ntoa(*(in_addr *)(&item.first.saddr));
- cout << ":" << item.first.sport;
- cout << " -> " << inet_ntoa(*(in_addr *)(&item.first.daddr));
- cout << ":" << item.first.dport;
- cout << "\tproto: " << item.first.proto;
- cout << "\tlength: " << item.second.length;
- cout << endl;
- }
-};
-
-STGLogger log;
-
-struct PACKET
-{
- iphdr hdr;
- uint16_t sport;
- uint16_t dport;
-};
-
-RULE MakeRule(const string & ip,
- const string & mask,
- uint16_t port1,
- uint16_t port2,
- int proto,
- int dir)
-{
- RULE rule;
-
- rule.ip = inet_addr(ip.c_str());
- rule.mask = inet_addr(mask.c_str());
- rule.port1 = port1;
- rule.port2 = port2;
- rule.proto = proto;
- rule.dir = dir;
-
- return rule;
-}
-
-RULES PrepareRules()
-{
- RULES rules;
- RULE local(MakeRule("192.168.0.0",
- "255.255.255.0",
- 0,
- 65535,
- -1,
- 0));
- RULE dns(MakeRule("195.5.61.68",
- "255.255.255.255",
- 53,
- 53,
- -1,
- 1));
- RULE ftp(MakeRule("129.22.8.159",
- "255.255.255.255",
- 20,
- 21,
- -1,
- 2));
- RULE world(MakeRule("0.0.0.0",
- "0.0.0.0",
- 0,
- 65535,
- -1,
- 3));
-
- rules.push_back(local);
-
- rules.push_back(dns);
-
- rules.push_back(ftp);
-
- rules.push_back(world);
-
- return rules;
-}
-
-iphdr MakePacket(const string & from,
- const string & to,
- int proto,
- uint16_t length)
-{
- iphdr hdr;
-
- hdr.ihl = 5;
- hdr.version = 4;
- hdr.tos = 0;
- hdr.tot_len = length;
- hdr.id = 0;
- hdr.frag_off = 50;
- hdr.ttl = 64;
- hdr.protocol = proto;
- hdr.check = 0;
- hdr.saddr = inet_addr(from.c_str());
- hdr.daddr = inet_addr(to.c_str());
-
- return hdr;
-}
-
-void PrepareTraffic(vector<PACKET> & pckts,
- const iphdr & skel,
- uint16_t sport,
- uint16_t dport,
- uint32_t in,
- uint32_t out,
- int packets)
-{
- PACKET inpacket;
- PACKET outpacket;
-
- inpacket.hdr = skel;
- outpacket.hdr = skel;
-
- outpacket.hdr.saddr ^= outpacket.hdr.daddr;
- outpacket.hdr.daddr ^= outpacket.hdr.saddr;
- outpacket.hdr.saddr ^= outpacket.hdr.daddr;
-
- inpacket.sport = sport;
- inpacket.dport = dport;
- outpacket.sport = dport;
- outpacket.dport = sport;
-
- inpacket.hdr.tot_len = in / packets;
- outpacket.hdr.tot_len = out / packets;
-
- for (int i = 0; i < packets; ++i) {
- //inpacket.hdr.daddr = outpacket.hdr.saddr = rand() * 32768 + rand();
- pckts.push_back(inpacket);
- pckts.push_back(outpacket);
- }
-}
-
-struct TC_TESTER : public unary_function<const PACKET &, void>
-{
-public:
- TC_TESTER(TRAFFCOUNTER & t)
- : tc(t)
- {}
-
- void operator () (const PACKET & p)
- {
- tc.AddPacket(p.hdr, p.sport, p.dport);
- }
-private:
- TRAFFCOUNTER & tc;
-};
-
-int main()
-{
- RULES rules(PrepareRules());
-
- TRAFFCOUNTER tc;
-
- vector<PACKET> packets;
-
- tc.SetRules(rules);
-
- if (tc.Start()) {
- LOG_IT << "::main() Error: traffcounter not started" << endl;
- return EXIT_FAILURE;
- }
-
- tc.AddIP(inet_addr("192.168.0.1")); // Server
- tc.AddIP(inet_addr("192.168.0.2")); // User A
- tc.AddIP(inet_addr("192.168.0.3")); // User B
-
- for (int i = 0; i < 10000; ++i) {
- tc.AddIP(rand() * 32768 + rand());
- }
-
- /*
- * A -> S
- * S -> A
- * A -> B
- * B -> A
- * A -> h1
- * h1 -> A
- * A -> h2
- * h2 -> A
- * A -> h3
- * h3 -> A
- * A -> h4
- * h4 -> A
- */
-
- timeval tv_from;
- timeval tv_to;
- gettimeofday(&tv_from, NULL);
- // S - local, A - local
- PrepareTraffic(packets, MakePacket("192.168.0.2", "192.168.0.1", 6, 0), 3215, 20, 1024 * 1024, 2048 * 1024, 512 * 2);
- // S - local, B - local
- PrepareTraffic(packets, MakePacket("192.168.0.3", "192.168.0.1", 6, 0), 5432, 22, 2048 * 1024, 1024 * 1024, 512 * 2);
- // A - local, B - local
- PrepareTraffic(packets, MakePacket("192.168.0.3", "192.168.0.2", 6, 0), 9875, 21, 2048 * 1024, 2048 * 1024, 512 * 2);
- // A - DNS
- //PrepareTraffic(packets, MakePacket("192.168.0.2", "195.5.61.68", 6, 0), 4521, 53, 1024 * 1024, 2048 * 1024, 512 * 2);
- // A - World
- //PrepareTraffic(packets, MakePacket("192.168.0.2", "195.5.61.68", 6, 0), 4521, 80, 1024 * 1024, 2048 * 1024, 512 * 2);
- // A - FTP
- //PrepareTraffic(packets, MakePacket("192.168.0.2", "129.22.8.159", 6, 0), 4522, 20, 512 * 1024, 512 * 1024, 512 * 2);
- // A - FTP
- //PrepareTraffic(packets, MakePacket("192.168.0.2", "129.22.8.159", 6, 0), 4522, 21, 512 * 1024, 4096 * 1024, 512 * 2);
- // B - World
- //PrepareTraffic(packets, MakePacket("192.168.0.3", "66.249.93.104", 6, 0), 3541, 80, 1024 * 1024, 1024 * 1024, 512 * 2);
- gettimeofday(&tv_to, NULL);
-
- uint64_t diff = tv_to.tv_sec - tv_from.tv_sec;
- diff *= 1000000;
- diff -= tv_from.tv_usec;
- diff += tv_to.tv_usec;
-
- LOG_IT << "::main() Prepared " << packets.size() << " packets by " << diff << " usecs" << endl;
-
- gettimeofday(&tv_from, NULL);
- for_each(packets.begin(),
- packets.end(),
- TC_TESTER(tc));
- gettimeofday(&tv_to, NULL);
-
- diff = tv_to.tv_sec - tv_from.tv_sec;
- diff *= 1000000;
- diff -= tv_from.tv_usec;
- diff += tv_to.tv_usec;
-
- LOG_IT << "::main() Recorded " << packets.size() << " packets by " << diff << " usecs" << endl;
-
- int p;
- while ((p = tc.PendingCount())) {
- LOG_IT << "::main() Pending packets: " << p << " at " << time(NULL) << endl;
- sleep(1);
- }
-
- TRAFF_DATA data;
-
- tc.DeleteIP(inet_addr("192.168.0.1"), &data);
- for_each(data.begin(),
- data.end(),
- StatPrinter());
- data.erase(data.begin(), data.end());
- tc.DeleteIP(inet_addr("192.168.0.2"), &data);
- for_each(data.begin(),
- data.end(),
- StatPrinter());
- data.erase(data.begin(), data.end());
- tc.DeleteIP(inet_addr("192.168.0.3"), &data);
- for_each(data.begin(),
- data.end(),
- StatPrinter());
- data.erase(data.begin(), data.end());
-
- if (tc.Stop()) {
- LOG_IT << "::main() Error: traffcounter not stopped" << endl;
- return EXIT_FAILURE;
- }
-
- LOG_IT << "::main() Sessions: " << tc.SessionsCount() << endl;
- LOG_IT << "::main() Cache hits: " << tc.CacheHits() << endl;
- LOG_IT << "::main() Cache misses: " << tc.CacheMisses() << endl;
- LOG_IT << "::main() Stream quality: " << tc.StreamQuality() << endl;
-
- return EXIT_SUCCESS;
-}
+++ /dev/null
-# foo bar baz
-
-UDP 10.0.0.0/24:1024-65535 DIR0 #blah-blah-blah
-
-TCP 192.168.1.1:21-22 DIR1
-
-ALL 192.168.2.0/16 DIR2
-
-GRE 192.168.3.0/24 NULL
-
-ALL 0.0.0.0 DIR3
-
+++ /dev/null
-
-UDP 10.0.0.0/24:1024-65535 DIR0
-
-TCP 192.168.1.1:21-22 DIR1
-ALL 192.168.2.0/16 DIR2
-ALL 0.0.0.a DIR3
-
+++ /dev/null
-
-UDP 10.0.0.0/24:1024-65535 DIR0
-
-TCP 192.168.1.1:21-22 DIRA
-ALL 192.168.2.0/16 DIR2
-ALL 0.0.0.0 DIR3
-
+++ /dev/null
-
-UDP 10.0.0.0/24:1024-65535 DIR0
-
-TCP 192.168.1.1:21-22 WOR1
-ALL 192.168.2.0/16 DIR2
-ALL 0.0.0.0 DIR3
-
-
+++ /dev/null
-
-
-UDP 10.0.0.0/24:1024-65535 DIR0
-
-TCP 192.168.1.1:21-22 DIR8945298579834755982745892734958
-ALL 192.168.2.0/16 DIR2
-ALL 0.0.0.0 DIR3
-
+++ /dev/null
-
-UDP 10.0.0.0/2a:1024-65535 DIR0
-
-TCP 192.168.1.1:21-22 DIR1
-ALL 192.168.2.0/16 DIR2
-ALL 0.0.0.0 DIR3
-
+++ /dev/null
-
-UDP 10.0.0.0/24:1024-65535 DIR0
-
-TCP 192.168.1.1:21-2a DIR1
-ALL 192.168.2.0/16 DIR2
-ALL 0.0.0.0 DIR3
-
+++ /dev/null
-
-UDP 10.0.0.0/24:1024-65535 DIR0
-
-TCP 192.168.1.1:21-22 DIR1
-QMTSP 192.168.2.0/16 DIR2
-ALL 0.0.0.0 DIR3
-
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.5 $
- $Date: 2009/10/12 08:43:32 $
- $Author: faust $
- */
-
-#include <csignal>
-#include <cassert>
-#include <algorithm>
-
-#include "traffcounter.h"
-#include "logger.h"
-#include "lock.h"
-#include "utils.h"
-
-//-----------------------------------------------------------------------------
-STG::TRAFFCOUNTER::TRAFFCOUNTER()
- : rulesFinder(),
- pendingPackets(),
- sessions(),
- cacheHits(0),
- cacheMisses(0),
- pendingCount(0),
- maxPending(0),
- ip2sessions(),
- stopped(true),
- running(false)
-{
-LOG_IT << "TRAFFCOUNTER::TRAFFCOUNTER()\n";
-pthread_mutex_init(&sessionMutex, NULL);
-pthread_mutex_init(&pendingMutex, NULL);
-pthread_mutex_init(&ipMutex, NULL);
-pthread_mutex_init(&rulesMutex, NULL);
-pthread_cond_init(&pendingCond, NULL);
-}
-//-----------------------------------------------------------------------------
-STG::TRAFFCOUNTER::~TRAFFCOUNTER()
-{
-LOG_IT << "TRAFFCOUNTER::~TRAFFCOUNTER()\n";
-pthread_cond_destroy(&pendingCond);
-pthread_mutex_destroy(&rulesMutex);
-pthread_mutex_destroy(&ipMutex);
-pthread_mutex_destroy(&pendingMutex);
-pthread_mutex_destroy(&sessionMutex);
-}
-//-----------------------------------------------------------------------------
-// Starting processing thread
-bool STG::TRAFFCOUNTER::Start()
-{
-LOG_IT << "TRAFFCOUNTER::Start()\n";
-
-if (running)
- return false;
-
-running = true;
-stopped = true;
-
-if (pthread_create(&thread, NULL, Run, this))
- {
- LOG_IT << "TRAFFCOUNTER::Start() Error: Cannot start thread!\n";
- return true;
- }
-
-return false;
-}
-//-----------------------------------------------------------------------------
-bool STG::TRAFFCOUNTER::Stop()
-{
-LOG_IT << "TRAFFCOUNTER::Stop()\n";
-LOG_IT << "maxPending: " << maxPending << std::endl;
-
-if (!running)
- return false;
-
-running = false;
-// Awake thread
-pthread_cond_signal(&pendingCond);
-
-//5 seconds to thread stops itself
-for (int i = 0; i < 25 && !stopped; ++i)
- {
- usleep(200000);
- }
-
-//after 5 seconds waiting thread still running. now kill it
-if (!stopped)
- {
- LOG_IT << "TRAFFCOUNTER::Stop() Killing thread\n";
- if (pthread_kill(thread, SIGINT))
- {
- return true;
- }
- LOG_IT << "TRAFFCOUNTER::Stop() Thread killed\n";
- }
-
-return false;
-}
-//-----------------------------------------------------------------------------
-double STG::TRAFFCOUNTER::StreamQuality() const
-{
-if (!cacheHits && !cacheMisses)
- {
- return 0;
- }
-
-double quality = cacheHits;
-return quality / (quality + cacheMisses);
-}
-//-----------------------------------------------------------------------------
-void STG::TRAFFCOUNTER::AddPacket(const iphdr & ipHdr, uint16_t sport, uint16_t dport)
-{
-/*
- * Intersects with AddIP (from user thread), DeleteIP (from user thread) and
- * Process (internal thread). AddPacket is calling from capturer's thread
- *
- * ips is affected by AddIP (logarithmic lock time) and
- * DeleteIP (from user thread)
- *
- * May be locked by AddIP or DeleteIP (from user thread)
- *
- * Lock AddIP (user thread) or DeleteIP (user thread)
- * Logarithmic lock time
- */
-
-bool srcExists;
-bool dstExists;
-
- {
- SCOPED_LOCK lock(ipMutex);
- srcExists = std::binary_search(ips.begin(), ips.end(), ipHdr.saddr);
- dstExists = std::binary_search(ips.begin(), ips.end(), ipHdr.daddr);
- }
-
-if (!srcExists &&
- !dstExists)
- {
- // Just drop the packet
- return;
- }
-
-STG::PENDING_PACKET p(ipHdr, sport, dport);
-
-// Packet classification
-if (srcExists)
- {
- if (dstExists)
- {
- // Both src and dst are countable
- p.direction = PENDING_PACKET::LOCAL;
- }
- else
- {
- // Src is countable
- p.direction = PENDING_PACKET::OUTGOING;
- }
- }
-else
- {
- if (dstExists)
- {
- // Dst is countable
- p.direction = PENDING_PACKET::INCOMING;
- }
- else
- {
- assert(0);
- // Not src nor dst are countable
- p.direction = PENDING_PACKET::FOREIGN;
- }
- }
-
-/*
- * pendingPackets is affected by Process (from internal thread)
- *
- * May be locked by Process (internal thread)
- *
- * Lock Process (internal thread)
- * Constant lock time
- */
-SCOPED_LOCK lock(pendingMutex);
-pendingPackets.push_back(p);
-pendingCount++;
-#ifdef STATISTIC
-if (pendingCount > maxPending)
- maxPending = pendingCount;
-#endif
-pthread_cond_signal(&pendingCond);
-
-}
-//-----------------------------------------------------------------------------
-void STG::TRAFFCOUNTER::AddIP(uint32_t ip)
-{
-/*
- * AddIP is calling from users and affect DeleteIP and AddPacket.
- * DeleteIP cannot be called concurrently with AddIP - it's the same
- * thread. AddPacket is calling from capturer's thread - concurrently
- * with AddIP.
- *
- * May be locked by AddPacket (from capturer's thread)
- * Logarithmic lock time
- *
- * Lock AddPacket (capturer's thread)
- * Logarithmic lock time
- */
-SCOPED_LOCK lock(ipMutex);
-IP_ITER it(std::lower_bound(ips.begin(), ips.end(), ip));
-
-if (it != ips.end() && *it == ip)
- {
- return;
- }
-// Insertion
-ips.insert(it, ip);
-}
-//-----------------------------------------------------------------------------
-void STG::TRAFFCOUNTER::DeleteIP(uint32_t ip, STG::TRAFF_DATA * traff)
-{
-/*
- * DeleteIP is calling from users and affect AddIP, AddPacket, GetIP and
- * Process. AddIP and GetIP cannot be called concurrently with DeleteIP - it's
- * the same thread. AddPacket is calling from capturer's thread - concurrently
- * with DeleteIP. Process is calling from internal thread - concurrently with
- * DeleteIP.
- *
- * May be locked by AddPacket (from capturer's thread)
- * Logarithmic lock time
- *
- * Lock AddPacket (capturer's thread)
- * Logarithmic lock time
- */
-
- {
- SCOPED_LOCK lock(ipMutex);
-
- IP_ITER it(std::lower_bound(ips.begin(), ips.end(), ip));
- if (it == ips.end())
- {
- return;
- }
- if (*it != ip)
- {
- return;
- }
-
- ips.erase(it);
- }
-
-// Get sessions for this ip
-std::pair<INDEX_ITER,
- INDEX_ITER> range;
-
-SCOPED_LOCK lock(sessionMutex);
-range = ip2sessions.equal_range(ip);
-std::list<INDEX_ITER> toDelete;
-
-// Lock session growing
-for (INDEX_ITER it = range.first; it != range.second; ++it)
- {
- traff->push_back(STG::TRAFF_ITEM(it->second->first, it->second->second));
-
- // Include self
- toDelete.push_back(it);
-
- /*if (ip == it->second->first.saddr)
- {
- toDelete.push_back(it->second->second.dIdx);
- }
- else
- {
- toDelete.push_back(it->second->second.sIdx);
- }*/
-
- --it->second->second.refCount;
-
- // Remove session
- /*
- * Normally we will lock here only in case of session between
- * two users from ips list
- */
- if (!it->second->second.refCount)
- {
- sessions.erase(it->second);
- }
- }
-
-// Remove indexes
-for (std::list<INDEX_ITER>::iterator it = toDelete.begin();
- it != toDelete.end();
- ++it)
- {
- ip2sessions.erase(*it);
- }
-}
-//-----------------------------------------------------------------------------
-void STG::TRAFFCOUNTER::GetIP(uint32_t ip, STG::TRAFF_DATA * traff)
-{
-/*
- * Normally we will lock here only in case of session between
- * two users from ips list
- */
-std::pair<INDEX_ITER,
- INDEX_ITER> range;
-
-SCOPED_LOCK lock(sessionMutex);
-range = ip2sessions.equal_range(ip);
-std::list<INDEX_ITER> toDelete;
-
-// TODO: replace with foreach
-for (SESSION_INDEX::iterator it = range.first;
- it != range.second;
- ++it)
- {
- traff->push_back(STG::TRAFF_ITEM(it->second->first, it->second->second));
- toDelete.push_back(it);
- --it->second->second.refCount;
- if (!it->second->second.refCount)
- {
- sessions.erase(it->second);
- }
- }
-
-for (std::list<INDEX_ITER>::iterator it = toDelete.begin();
- it != toDelete.end();
- ++it)
- {
- ip2sessions.erase(*it);
- }
-}
-//-----------------------------------------------------------------------------
-void * STG::TRAFFCOUNTER::Run(void * data)
-{
-STG::TRAFFCOUNTER * tc = static_cast<STG::TRAFFCOUNTER *>(data);
-tc->stopped = false;
-
-while (tc->running)
- {
- STG::PENDING_PACKET packet;
- {
- SCOPED_LOCK lock(tc->pendingMutex);
- if (tc->pendingPackets.empty())
- {
- pthread_cond_wait(&tc->pendingCond, &tc->pendingMutex);
- }
- if (!tc->running)
- {
- break;
- }
- packet = *tc->pendingPackets.begin();
- tc->pendingPackets.pop_front();
- --tc->pendingCount;
- }
- tc->Process(packet);
- }
-
-tc->stopped = true;
-return NULL;
-}
-//-----------------------------------------------------------------------------
-void STG::TRAFFCOUNTER::Process(const STG::PENDING_PACKET & p)
-{
-// Bypass on stop
-if (!running)
- return;
-
-// Fail on foreign packets
-if (p.direction == PENDING_PACKET::FOREIGN) {
- assert(0);
-}
-
-// Searching a new packet in a tree.
-SESSION_ITER si;
- {
- SCOPED_LOCK lock(sessionMutex);
- si = sessions.find(STG::SESSION_ID(p));
- }
-
-// Packet found - update length and time
-if (si != sessions.end())
- {
- // Grow session
- SCOPED_LOCK lock(sessionMutex);
- si->second.length += p.length;
- ++cacheHits;
- return;
- }
-
-++cacheMisses;
-
-// Packet not found - add new packet
-
-// This packet is alowed to create session
-STG::SESSION_ID sid(p);
-SESSION_FULL_DATA sd;
-
-// Identify a packet
- {
- SCOPED_LOCK lock(rulesMutex);
- sd.dir = rulesFinder.GetDir(p);
- }
-
-sd.length = p.length;
-
-if (p.direction == PENDING_PACKET::LOCAL)
- {
- sd.refCount = 2;
- }
-else
- {
- sd.refCount = 1;
- }
-
-// Create a session
-std::pair<SESSION_ITER,
- bool> sIt(sessions.insert(std::make_pair(sid, sd)));
- {
- SCOPED_LOCK lock(sessionMutex);
- std::pair<SESSION_ITER,
- bool> sIt(sessions.insert(std::make_pair(sid, sd)));
-
- // Create an indexes
- sIt.first->second.sIdx = ip2sessions.insert(std::make_pair(p.saddr, sIt.first));
- sIt.first->second.dIdx = ip2sessions.insert(std::make_pair(p.daddr, sIt.first));
- }
-
-}
-//-----------------------------------------------------------------------------
-void STG::TRAFFCOUNTER::SetRules(const STG::RULES & data)
-{
-/*
- * SetRules is calling from outside internel thread. Process is calling
- * from internal thread and calls DeterminateDir which use rules data.
- *
- * May be locked by DeterminateDir (Process) from internal thread.
- *
- * Lock DeterminateDir (Process) - internal thread.
- * Linear lock time
- */
-SCOPED_LOCK lock(rulesMutex);
-rulesFinder.SetRules(data);
-}
+++ /dev/null
-/*
- * 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
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.3 $
- $Date: 2009/04/10 14:15:46 $
- $Author: faust $
- */
-
-
-#ifndef TRAFFCOUNTER_H
-#define TRAFFCOUNTER_H
-
-#include <pthread.h>
-#include <netinet/ip.h>
-
-#ifdef HAVE_STDINT
- #include <stdint.h>
-#else
- #ifdef HAVE_INTTYPES
- #include <inttypes.h>
- #else
- #error "You need either stdint.h or inttypes.h to compile this!"
- #endif
-#endif
-
-#include <ctime>
-#include <list>
-#include <vector>
-#include <map>
-
-#include "rules.h"
-#include "rules_finder.h"
-#include "tc_packets.h"
-#include "user_tc_iface.h"
-#include "capturer_tc_iface.h"
-
-#define PACKET_TIMEOUT 300
-
-namespace STG
-{
-
- class TRAFFCOUNTER : public IUSER_TC, public ICAPTURER_TC
- {
- public:
- TRAFFCOUNTER();
- ~TRAFFCOUNTER();
-
- void SetRules(const RULES & data);
-
- bool Start();
- bool Stop();
-
- // Capturer API
- void AddPacket(const iphdr & ipHdr, uint16_t sport, uint16_t dport);
-
- // User API
- void AddIP(uint32_t ip);
- void DeleteIP(uint32_t ip, TRAFF_DATA * traff);
- void GetIP(uint32_t ip, TRAFF_DATA * traff);
-
- /*
- * Stream quality represents a "scatterness" of data stream
- * When sessions represend a large amount of information - it's a good
- * stream. Most of common-use protocols (HTTP, FTP, etc.) shows a good
- * stream quality.
- * When there are a lot of packet that creates a new streams - it's a
- * bad stream. p2p traffic has a bias to show a bad stream quality.
- */
- double StreamQuality() const;
- uint64_t PendingCount() const { return pendingCount; };
- uint64_t SessionsCount() const { return sessions.size(); };
- uint64_t IndexesCount() const { return ip2sessions.size(); };
- uint64_t CacheHits() const { return cacheHits; };
- uint64_t CacheMisses() const { return cacheMisses; };
-
- private:
- static void * Run(void * data);
-
- void Process(const PENDING_PACKET & p);
-
- RULES_FINDER rulesFinder;
-
- /*
- * SESSION_INDEX: ip -> SESSION_ITER
- * SESSIONS: SESSION_ID -> SESSION_DATA
- * -> SESSION_INDEX (saddr)
- * -> SESSION_INDEX (daddr)
- */
- struct SESSION_FULL_DATA; // Forward declaration
- typedef std::map<SESSION_ID, SESSION_FULL_DATA, SESSION_LESS> SESSIONS;
- typedef SESSIONS::iterator SESSION_ITER;
- /*
- * This structure is used to take a fast session access by IP
- * Normally, one IP can reffer multiple sessions. For each data stream there
- * are 2 sessions: incoming data and outgoing data.
- */
- typedef std::multimap<uint32_t, SESSION_ITER> SESSION_INDEX;
- typedef SESSION_INDEX::iterator INDEX_ITER;
- /*
- * Append session meta-information with back-indexes
- * In process of removing IP from TRAFFCOUNTER we need to remove indexes of
- * sessions, reffered by this IP. To prevent slow searching by index tree we
- * use 2 back-references: for source and destination IP.
- */
- struct SESSION_FULL_DATA : public SESSION_DATA
- {
- INDEX_ITER sIdx; // Back reference for fast index removing
- INDEX_ITER dIdx; // Back reference for fast index removing
- int refCount; // Reference count for packet removing
- };
-
- std::list<PENDING_PACKET> pendingPackets;
-
- SESSIONS sessions; // A map with sessions data
-
- /*
- * When pending packet appends a session - it's a "cache hit"
- * When pending packet creates a new session - it's a "cache miss"
- */
- uint64_t cacheHits;
- uint64_t cacheMisses;
- uint64_t pendingCount;
- uint64_t maxPending;
-
- SESSION_INDEX ip2sessions; // IP index for sessions data
-
- /*
- * A sorted vector of allowed/disallowed ips
- */
- std::vector<uint32_t> ips;
- typedef std::vector<uint32_t>::iterator IP_ITER;
-
- bool stopped;
- bool running;
-
- mutable pthread_mutex_t sessionMutex; // For sessions
- mutable pthread_mutex_t pendingMutex; // For pendinPackets
- mutable pthread_cond_t pendingCond; //
- mutable pthread_mutex_t ipMutex; // For ip list
- mutable pthread_mutex_t rulesMutex; // For rules list
- pthread_t thread;
-
- };
-
-}
-
-#endif //TRAFFCOUNTER_H
+++ /dev/null
-#ifndef __USER_TC_IFACE_H__
-#define __USER_TC_IFACE_H__
-
-#ifdef HAVE_STDINT
- #include <stdint.h>
-#else
- #ifdef HAVE_INTTYPES
- #include <inttypes.h>
- #else
- #error "You need either stdint.h or inttypes.h to compile this!"
- #endif
-#endif
-
-#include "tc_packets.h"
-
-namespace STG
-{
-
- class IUSER_TC
- {
- public:
- virtual ~IUSER_TC() {};
- virtual void AddIP(uint32_t) = 0;
- virtual void DeleteIP(uint32_t, TRAFF_DATA *) = 0;
- virtual void GetIP(uint32_t, TRAFF_DATA *) = 0;
- };
-
-}
-
-#endif
+++ /dev/null
-#include <algorithm>
-#include <functional>
-
-#include <iostream>
-#include <cerrno>
-#include <cstring>
-
-#include <arpa/inet.h>
-
-#include "utils.h"
-
-using namespace std;
-
-string STG::ToLower(const string & val, const locale & loc)
-{
- std::string res;
- transform(val.begin(),
- val.end(),
- back_inserter(res),
- STG::ToLowerHelper(loc));
- return res;
-}
-
-string STG::ToUpper(const string & val, const locale & loc)
-{
- std::string res;
- transform(val.begin(),
- val.end(),
- back_inserter(res),
- STG::ToUpperHelper(loc));
- return res;
-}
-
-string STG::Trim(const string & val, const locale & loc)
-{
- if (val.empty())
- return std::string();
- string::const_iterator first(find_if(
- val.begin(),
- val.end(),
- STG::IsNotSpace(loc)));
- string::const_reverse_iterator last(find_if(
- val.rbegin(),
- val.rend(),
- STG::IsNotSpace(loc)));
- if (first == val.end())
- return std::string();
- return std::string(first, last.base());
-}
-std::string inet_ntostring(uint32_t ip)
-{
- char buf[INET_ADDRSTRLEN + 1];
-
- return inet_ntop(AF_INET, &ip, buf, INET_ADDRSTRLEN);
-}
+++ /dev/null
-#ifndef __UTILS_H__
-#define __UTILS_H__
-
-#include <string>
-#include <locale>
-
-namespace STG
-{
-
-class IsNotSpace : public std::unary_function<bool, char> {
-public:
- IsNotSpace(const std::locale & l) : loc(l) {};
- bool operator() (char c)
- {
- return !std::use_facet<casefacet>(loc).is(std::ctype_base::space, c);
- };
-private:
- const std::locale & loc;
-
- typedef std::ctype<char> casefacet;
-};
-
-class ToLowerHelper : public std::unary_function<char, char> {
-public:
- ToLowerHelper(const std::locale & l) : loc(l) {};
- char operator() (char c)
- {
- return std::tolower(c, loc);
- };
-private:
- const std::locale & loc;
-};
-
-class ToUpperHelper : public std::unary_function<char, char> {
-public:
- ToUpperHelper(const std::locale & l) : loc(l) {};
- char operator() (char c)
- {
- return std::toupper(c, loc);
- };
-private:
- const std::locale & loc;
-};
-
-std::string Trim(const std::string & val, const std::locale & loc);
-std::string ToLower(const std::string & val, const std::locale & loc);
-std::string ToUpper(const std::string & val, const std::locale & loc);
-
-inline std::string Trim(const std::string & val)
- {
- return Trim(val, std::locale(""));
- }
-
-inline std::string ToLower(const std::string & val)
- {
- return ToLower(val, std::locale(""));
- }
-
-inline std::string ToUpper(const std::string & val)
- {
- return ToUpper(val, std::locale(""));
- }
-
-}
-
-std::string inet_ntostring(uint32_t ip);
-
-#endif