├── README ├── src ├── base64.h ├── bnbt_private.h ├── bencode.h ├── server_v4.h ├── client_v4.h ├── resource.h ├── server.select.h ├── server.epoll.old.h ├── client.select.new.h ├── server.h ├── client.select.h ├── client.epoll.new.h ├── client.h ├── server.epoll.new.h ├── config.h ├── bnbt_mysql.h ├── sha1.h ├── atom.h ├── util_ntservice.h ├── html.h ├── tracker_log.cpp ├── link.h ├── md5.h ├── sha1.cpp ├── tracker_staff.cpp ├── bencode.cpp ├── bnbt_v4.h ├── util_ntservice.cpp ├── atom.cpp ├── bnbt (copy).h ├── bnbt.select.h ├── bnbt.h ├── tracker_file.cpp ├── server_v4.cpp ├── tracker_scrape.cpp └── server.epoll.old.cpp ├── stylesheets ├── filedump.xsl ├── filedump.xml └── rss.xsl └── bnbt.cfg.sample /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2005 Trevor Hogan 3 | // 4 | 5 | extern char *b64decode(const char *); 6 | -------------------------------------------------------------------------------- /src/bnbt_private.h: -------------------------------------------------------------------------------- 1 | /* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */ 2 | /* DO NOT EDIT ! */ 3 | 4 | #ifndef BNBT_PRIVATE_H 5 | #define BNBT_PRIVATE_H 6 | 7 | /* VERSION DEFINITIONS */ 8 | #define VER_STRING "8.1.3.5" 9 | #define VER_MAJOR 8 10 | #define VER_MINOR 1 11 | #define VER_RELEASE 3 12 | #define VER_BUILD 5 13 | #define COMPANY_NAME "" 14 | #define FILE_VERSION "8, 1, 3, 5" 15 | #define FILE_DESCRIPTION "A C++ BitTorrent Tracker" 16 | #define INTERNAL_NAME "" 17 | #define LEGAL_COPYRIGHT "" 18 | #define LEGAL_TRADEMARKS "" 19 | #define ORIGINAL_FILENAME "BNBT.exe" 20 | #define PRODUCT_NAME "XBNBT" 21 | #define PRODUCT_VERSION "8, 1, 3, 5" 22 | 23 | #endif /*BNBT_PRIVATE_H*/ 24 | -------------------------------------------------------------------------------- /src/bencode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2005 Trevor Hogan 3 | // 4 | 5 | #ifndef BENCODE_H 6 | #define BENCODE_H 7 | 8 | string EncodeInt( const CAtomInt &x ); 9 | string EncodeLong( const CAtomLong &x ); 10 | string EncodeString( const CAtomString &x ); 11 | string EncodeList( const CAtomList &x ); 12 | string EncodeDicti( const CAtomDicti &x ); 13 | string Encode( CAtom *pAtom ); 14 | 15 | // the decode functions allocate memory, so be SURE to delete it 16 | 17 | // CAtomInt *DecodeInt( const string &x, unsigned long iStart = 0 ); 18 | CAtomLong *DecodeLong( const string &x, unsigned long iStart = 0 ); 19 | CAtomString *DecodeString( const string &x, unsigned long iStart = 0 ); 20 | CAtomList *DecodeList( const string &x, unsigned long iStart = 0 ); 21 | CAtomDicti *DecodeDicti( const string &x, unsigned long iStart = 0 ); 22 | CAtom *Decode( const string &x, unsigned long iStart = 0 ); 23 | 24 | CAtom *DecodeFile( const char *szFile ); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/server_v4.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef SERVER_H 6 | #define SERVER_H 7 | 8 | class CServer 9 | { 10 | public: 11 | CServer( ); 12 | virtual ~CServer( ); 13 | 14 | void Kill( ); 15 | bool isDying( ); 16 | 17 | // returns true if the server should be killed 18 | 19 | bool Update( const bool &bBlock ); 20 | 21 | CTracker *getTracker( ); 22 | 23 | vector m_vecClients; 24 | 25 | private: 26 | bool m_bKill; 27 | 28 | CTracker *m_pTracker; 29 | 30 | unsigned int m_uiSocketTimeOut; 31 | string m_strBind; 32 | char m_cCompression; 33 | 34 | // tphogan - the server is listening on each of these sockets 35 | // the vector container will handle memory allocation for the SOCKET object 36 | 37 | vector m_vecListeners; 38 | 39 | // tphogan - helper function to add a new socket listener 40 | // returns true on success, false on error 41 | 42 | bool AddListener( struct sockaddr_in sin ); 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/client_v4.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef CLIENT_H 6 | #define CLIENT_H 7 | 8 | #define COMPRESS_NONE 0 9 | #define COMPRESS_DEFLATE 1 10 | #define COMPRESS_GZIP 2 11 | 12 | #define CS_RECVHEADERS 0 13 | #define CS_PROCESSHEADERS 1 14 | #define CS_RECVBODY 2 15 | #define CS_MAKERESPONSE 3 16 | #define CS_SEND 4 17 | 18 | #define GPBUF_SIZE 8192 19 | 20 | extern char gpBuf[GPBUF_SIZE]; 21 | 22 | class CClient 23 | { 24 | public: 25 | CClient( SOCKET &sckClient, struct sockaddr_in &sinAddress, const unsigned int &cuiTimeOut, const char &ccCompression ); 26 | virtual ~CClient( ); 27 | 28 | bool Update( ); 29 | 30 | void Reset( ); 31 | 32 | private: 33 | SOCKET m_sckClient; 34 | 35 | unsigned char m_ucState; 36 | unsigned int m_uiTimeOut; 37 | char m_cCompression; 38 | string m_strReceiveBuf; 39 | string m_strSendBuf; 40 | struct request_t rqst; 41 | struct response_t rsp; 42 | bool m_bKeepAlive; 43 | unsigned long m_ulLast; 44 | bool m_bReset; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by BNBT.rc 4 | // 5 | #define IDS_PROJNAME 100 6 | #define IDR_WMDMLOGGER 101 7 | #define IDS_LOG_SEV_INFO 201 8 | #define IDS_LOG_SEV_WARN 202 9 | #define IDS_LOG_SEV_ERROR 203 10 | #define IDS_LOG_DATETIME 204 11 | #define IDS_LOG_SRCNAME 205 12 | #define IDS_DEF_LOGFILE 301 13 | #define IDS_DEF_MAXSIZE 302 14 | #define IDS_DEF_SHRINKTOSIZE 303 15 | #define IDS_DEF_LOGENABLED 304 16 | #define IDS_MUTEX_TIMEOUT 401 17 | 18 | // Next default values for new objects 19 | // 20 | #ifdef APSTUDIO_INVOKED 21 | #ifndef APSTUDIO_READONLY_SYMBOLS 22 | #define _APS_NEXT_RESOURCE_VALUE 202 23 | #define _APS_NEXT_COMMAND_VALUE 32768 24 | #define _APS_NEXT_CONTROL_VALUE 201 25 | #define _APS_NEXT_SYMED_VALUE 101 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /src/server.select.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef SERVER_H 6 | #define SERVER_H 7 | 8 | class CServer 9 | { 10 | public: 11 | CServer( ); 12 | virtual ~CServer( ); 13 | 14 | void Kill( ); 15 | bool isDying( ); 16 | 17 | // returns true if the server should be killed 18 | 19 | bool Update( const bool &bBlock ); 20 | 21 | CTracker *getTracker( ); 22 | 23 | vector m_vecClients; 24 | 25 | private: 26 | bool m_bKill; 27 | 28 | CTracker *m_pTracker; 29 | 30 | unsigned int m_uiSocketTimeOut; 31 | string m_strBind; 32 | char m_cCompression; 33 | 34 | // tphogan - the server is listening on each of these sockets 35 | // the vector container will handle memory allocation for the SOCKET object 36 | 37 | vector m_vecListeners; 38 | 39 | // tphogan - helper function to add a new socket listener 40 | // returns true on success, false on error 41 | 42 | // bool AddListener( struct sockaddr_in sin ); 43 | bool AddListener( struct sockaddr_in6 sin ); 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/server.epoll.old.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef SERVER_H 6 | #define SERVER_H 7 | 8 | class CServer 9 | { 10 | public: 11 | CServer( ); 12 | virtual ~CServer( ); 13 | 14 | void Kill( ); 15 | bool isDying( ); 16 | 17 | // returns true if the server should be killed 18 | 19 | bool Update( const bool &bBlock ); 20 | 21 | CTracker *getTracker( ); 22 | 23 | vector m_vecClients; 24 | 25 | private: 26 | bool m_bKill; 27 | 28 | CTracker *m_pTracker; 29 | 30 | struct epoll_event ev, events[1024]; 31 | SOCKET epfd, nfds; 32 | 33 | unsigned int m_uiSocketTimeOut; 34 | string m_strBind; 35 | char m_cCompression; 36 | 37 | // tphogan - the server is listening on each of these sockets 38 | // the vector container will handle memory allocation for the SOCKET object 39 | 40 | vector m_vecListeners; 41 | 42 | // tphogan - helper function to add a new socket listener 43 | // returns true on success, false on error 44 | 45 | bool AddListener( struct sockaddr_in6 sin ); 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/client.select.new.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef CLIENT_H 6 | #define CLIENT_H 7 | 8 | #define COMPRESS_NONE 0 9 | #define COMPRESS_DEFLATE 1 10 | #define COMPRESS_GZIP 2 11 | 12 | #define CS_RECVHEADERS 0 13 | #define CS_PROCESSHEADERS 1 14 | #define CS_RECVBODY 2 15 | #define CS_MAKERESPONSE 3 16 | #define CS_SEND 4 17 | 18 | // #define GPBUF_SIZE 8192 19 | #define GPBUF_SIZE 16384 20 | 21 | extern char gpBuf[GPBUF_SIZE]; 22 | 23 | class CClient 24 | { 25 | public: 26 | CClient( SOCKET &sckClient, struct sockaddr_in6 &sinAddress, const unsigned int &cuiTimeOut, const char &ccCompression ); 27 | virtual ~CClient( ); 28 | 29 | bool Update( ); 30 | 31 | void Reset( ); 32 | 33 | private: 34 | SOCKET m_sckClient; 35 | 36 | unsigned char m_ucState; 37 | unsigned int m_uiTimeOut; 38 | char m_cCompression; 39 | string m_strReceiveBuf; 40 | string m_strSendBuf; 41 | struct request_t rqst; 42 | struct response_t rsp; 43 | bool m_bKeepAlive; 44 | unsigned long m_ulLast; 45 | bool m_bReset; 46 | bool m_bBlocked; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/server.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef SERVER_H 6 | #define SERVER_H 7 | 8 | class CServer 9 | { 10 | public: 11 | CServer( ); 12 | virtual ~CServer( ); 13 | 14 | void Kill( ); 15 | bool isDying( ); 16 | 17 | // returns true if the server should be killed 18 | 19 | bool Update( const bool &bBlock ); 20 | 21 | CTracker *getTracker( ); 22 | 23 | vector m_vecClients; 24 | 25 | CAtomList *m_pIPBlockedList; 26 | 27 | private: 28 | bool m_bKill; 29 | 30 | CTracker *m_pTracker; 31 | 32 | struct epoll_event ev, events[1024]; 33 | SOCKET epfd, nfds; 34 | 35 | unsigned int m_uiSocketTimeOut; 36 | string m_strBind; 37 | char m_cCompression; 38 | 39 | // tphogan - the server is listening on each of these sockets 40 | // the vector container will handle memory allocation for the SOCKET object 41 | 42 | vector m_vecListeners; 43 | 44 | // tphogan - helper function to add a new socket listener 45 | // returns true on success, false on error 46 | 47 | bool AddListener( struct sockaddr_in6 sin ); 48 | 49 | string m_strIPBlockFile; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/client.select.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef CLIENT_H 6 | #define CLIENT_H 7 | 8 | #define COMPRESS_NONE 0 9 | #define COMPRESS_DEFLATE 1 10 | #define COMPRESS_GZIP 2 11 | 12 | #define CS_RECVHEADERS 0 13 | #define CS_PROCESSHEADERS 1 14 | #define CS_RECVBODY 2 15 | #define CS_MAKERESPONSE 3 16 | #define CS_SEND 4 17 | 18 | #define GPBUF_SIZE 8192 19 | 20 | extern char gpBuf[GPBUF_SIZE]; 21 | 22 | class CClient 23 | { 24 | public: 25 | // CClient( SOCKET &sckClient, struct sockaddr_in &sinAddress, const unsigned int &cuiTimeOut, const char &ccCompression ); 26 | CClient( SOCKET &sckClient, struct sockaddr_in6 &sinAddress, const unsigned int &cuiTimeOut, const char &ccCompression ); 27 | virtual ~CClient( ); 28 | 29 | bool Update( ); 30 | 31 | void Reset( ); 32 | 33 | private: 34 | SOCKET m_sckClient; 35 | 36 | unsigned char m_ucState; 37 | unsigned int m_uiTimeOut; 38 | char m_cCompression; 39 | string m_strReceiveBuf; 40 | string m_strSendBuf; 41 | struct request_t rqst; 42 | struct response_t rsp; 43 | bool m_bKeepAlive; 44 | unsigned long m_ulLast; 45 | bool m_bReset; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/client.epoll.new.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef CLIENT_H 6 | #define CLIENT_H 7 | 8 | #define COMPRESS_NONE 0 9 | #define COMPRESS_DEFLATE 1 10 | #define COMPRESS_GZIP 2 11 | 12 | #define CS_RECVHEADERS 0 13 | #define CS_PROCESSHEADERS 1 14 | #define CS_RECVBODY 2 15 | #define CS_MAKERESPONSE 3 16 | #define CS_SEND 4 17 | 18 | // #define GPBUF_SIZE 8192 19 | #define GPBUF_SIZE 16384 20 | 21 | extern char gpBuf[GPBUF_SIZE]; 22 | 23 | class CClient 24 | { 25 | public: 26 | CClient( SOCKET &sckClient, struct sockaddr_in6 &sinAddress, const unsigned int &cuiTimeOut, const char &ccCompression ); 27 | virtual ~CClient( ); 28 | 29 | bool Update( struct epoll_event &ev_client ); 30 | 31 | void Reset( ); 32 | 33 | SOCKET m_sckClient; 34 | 35 | private: 36 | 37 | struct epoll_event ev; 38 | 39 | unsigned char m_ucState; 40 | unsigned int m_uiTimeOut; 41 | char m_cCompression; 42 | string m_strReceiveBuf; 43 | string m_strSendBuf; 44 | struct request_t rqst; 45 | struct response_t rsp; 46 | bool m_bKeepAlive; 47 | unsigned long m_ulLast; 48 | bool m_bReset; 49 | bool m_bBlocked; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/client.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef CLIENT_H 6 | #define CLIENT_H 7 | 8 | #define COMPRESS_NONE 0 9 | #define COMPRESS_DEFLATE 1 10 | #define COMPRESS_GZIP 2 11 | 12 | #define CS_RECVHEADERS 0 13 | #define CS_PROCESSHEADERS 1 14 | #define CS_RECVBODY 2 15 | #define CS_MAKERESPONSE 3 16 | #define CS_SEND 4 17 | 18 | // #define GPBUF_SIZE 8192 19 | #define GPBUF_SIZE 65536 20 | 21 | extern char gpBuf[GPBUF_SIZE]; 22 | 23 | class CClient 24 | { 25 | public: 26 | CClient( SOCKET &sckClient, struct sockaddr_in6 &sinAddress, const unsigned int &cuiTimeOut, const char &ccCompression ); 27 | virtual ~CClient( ); 28 | 29 | bool Update( ); 30 | 31 | void Reset( ); 32 | 33 | private: 34 | SOCKET m_sckClient; 35 | struct epoll_event ev, events[128]; 36 | SOCKET epfd_client, nfds; 37 | 38 | unsigned char m_ucState; 39 | unsigned int m_uiTimeOut; 40 | char m_cCompression; 41 | string m_strReceiveBuf; 42 | string m_strSendBuf; 43 | struct request_t rqst; 44 | struct response_t rsp; 45 | bool m_bKeepAlive; 46 | unsigned long m_ulLast; 47 | bool m_bReset; 48 | bool m_bFailed; 49 | bool m_bBlocked; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/server.epoll.new.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef SERVER_H 6 | #define SERVER_H 7 | 8 | class CServer 9 | { 10 | public: 11 | CServer( ); 12 | virtual ~CServer( ); 13 | 14 | void Kill( ); 15 | bool isDying( ); 16 | 17 | // returns true if the server should be killed 18 | 19 | bool Update( const bool &bBlock ); 20 | 21 | CTracker *getTracker( ); 22 | 23 | vector m_vecClients; 24 | 25 | SOCKET epfd_client, nfds_client; 26 | struct epoll_event events_client[1024]; 27 | 28 | CAtomList *m_pIPBlockedList; 29 | 30 | private: 31 | bool m_bKill; 32 | 33 | CTracker *m_pTracker; 34 | 35 | struct epoll_event ev, events[1024]; 36 | SOCKET epfd, nfds; 37 | 38 | unsigned int m_uiSocketTimeOut; 39 | string m_strBind; 40 | char m_cCompression; 41 | 42 | // tphogan - the server is listening on each of these sockets 43 | // the vector container will handle memory allocation for the SOCKET object 44 | 45 | vector m_vecListeners; 46 | 47 | // tphogan - helper function to add a new socket listener 48 | // returns true on success, false on error 49 | 50 | bool AddListener( struct sockaddr_in6 sin ); 51 | 52 | string m_strIPBlockFile; 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef CONFIG_H 6 | #define CONFIG_H 7 | 8 | #define CFG_FILE "bnbt.cfg" 9 | 10 | extern map gmapCFG; 11 | 12 | void CFG_Open( const char *szFile ); 13 | void CFG_SetInt( const string &cstrKey, const int &ciX ); 14 | void CFG_SetString( const string &cstrKey, const string &csX ); 15 | const int CFG_GetInt( const string &cstrKey, const int &ciX ); 16 | const string CFG_GetString( const string &cstrKey, const string &csX ); 17 | void CFG_Delete( const string &cstrKey ); 18 | void CFG_Close( const char *szFile ); 19 | void CFG_SetDefaults( ); 20 | 21 | /*** 22 | * 23 | * XBNBT Beta 81b.3.5 - A C++ BitTorrent Tracker 24 | * Copyright (C) 2003-2005 =Xotic= 25 | * 26 | * This library is free software; you can redistribute it and/or 27 | * modify it under the terms of the GNU Lesser General Public 28 | * License as published by the Free Software Foundation; either 29 | * version 2.1 of the License, or (at your option) any later version. 30 | * 31 | * This library is distributed in the hope that it will be useful, 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 34 | * Lesser General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU Lesser General Public 37 | * License along with this library; if not, write to the Free Software 38 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 39 | * 40 | ***/ 41 | 42 | #define LANG_CFG_FILE "lang.cfg" 43 | 44 | extern map gmapLANG_CFG; 45 | 46 | void LANG_CFG_Init( const char *szFile ); 47 | void LANG_CFG_Open( const char *szFile ); 48 | void LANG_CFG_SetString( const string &cstrKey, const string &csX ); 49 | const string LANG_CFG_GetString( const string &cstrKey, const string &csX ); 50 | void LANG_CFG_Delete( const string &cstrKey ); 51 | void LANG_CFG_Close( const char *szFile ); 52 | void LANG_CFG_SetDefaultsSort( ); 53 | void LANG_CFG_SetDefaultsErrorLog( ); 54 | void LANG_CFG_SetDefaultsXbnbt( ); 55 | void LANG_CFG_SetDefaults( ); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/bnbt_mysql.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | // Modified by =Xotic= 6 | 7 | #ifndef BNBT_MYSQL_H 8 | #define BNBT_MYSQL_H 9 | 10 | #if defined ( BNBT_MYSQL ) || defined ( XBNBT_MYSQL ) 11 | 12 | #include 13 | 14 | #if defined ( BNBT_MYSQL ) 15 | 16 | extern MYSQL *gpMySQL; 17 | extern string gstrMySQLHost; 18 | extern string gstrMySQLDatabase; 19 | extern string gstrMySQLUser; 20 | extern string gstrMySQLPassword; 21 | extern string gstrMySQLPrefix; 22 | extern unsigned int guiMySQLPort; 23 | 24 | extern map gmapMySQL; 25 | 26 | const string UTIL_StringToMySQL( const string &strString ); 27 | void UTIL_MySQLCreateTables( ); 28 | void UTIL_MySQLCreateDatabase( ); 29 | 30 | class CMySQLQuery 31 | { 32 | public: 33 | CMySQLQuery( const string cstrQuery ); 34 | virtual ~CMySQLQuery( ); 35 | 36 | const vector nextRow( ); 37 | const map nextRowMap( ); 38 | const unsigned long numRows( ); 39 | const unsigned long lastInsertID( ); 40 | private: 41 | MYSQL *pMySQL; 42 | MYSQL_RES *m_pRes; 43 | }; 44 | 45 | class CMySQLQueryLocal 46 | { 47 | public: 48 | CMySQLQueryLocal( ); 49 | virtual ~CMySQLQueryLocal( ); 50 | 51 | void query( const string cstrQuery ); 52 | const vector nextRow( ); 53 | const map nextRowMap( ); 54 | const unsigned long numRows( ); 55 | const unsigned long lastInsertID( ); 56 | private: 57 | MYSQL *pMySQL; 58 | MYSQL_RES *m_pRes; 59 | }; 60 | #endif 61 | 62 | #if defined ( XBNBT_MYSQL ) 63 | 64 | extern MYSQL *gpMySQLUsers; 65 | extern string gstrMySQLUsersHost; 66 | extern string gstrMySQLUsersDatabase; 67 | extern string gstrMySQLUsersUser; 68 | extern string gstrMySQLUsersPassword; 69 | extern string gstrMySQLUsersTable; 70 | extern string gstrMySQLUsersAdmin; 71 | extern unsigned int guiMySQLUsersPort; 72 | extern bool gbMySQLUsersOverrideUsers; 73 | extern unsigned char gucMySQLUsersMemberAccess; 74 | extern string gstrMySQLUsersName; 75 | 76 | const bool UTIL_StartMySQLUsers( ); 77 | //const string UTIL_StringToMySQLUsers( const string &cstrString ); 78 | const bool UTIL_OpenMySQLUsers(void); 79 | const bool UTIL_TestMySQLUsersColumn(void); 80 | const bool UTIL_SetMySQLUsersMemberDefaultAccess(void); 81 | const bool UTIL_SetMySQLUsersMemberAccess( const string &cstrMySQLUsersMember, const unsigned char &cucMySQLUsersAccess ); 82 | const bool UTIL_CreateMySQLUsersColumn(void); 83 | const bool UTIL_CloseMySQLUsers(void); 84 | 85 | class CMySQLUsersQuery 86 | { 87 | public: 88 | CMySQLUsersQuery( const string cstrQuery ); 89 | virtual ~CMySQLUsersQuery( ); 90 | 91 | const vector nextRow( ); 92 | private: 93 | MYSQL_RES *m_pRes; 94 | }; 95 | #endif 96 | 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | 100% free public domain implementation of the SHA-1 3 | algorithm by Dominik Reichl 4 | 5 | * modified by Trevor Hogan for use with BNBT * 6 | 7 | === Test Vectors (from FIPS PUB 180-1) === 8 | 9 | "abc" 10 | A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 11 | 12 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 13 | 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 14 | 15 | A million repetitions of "a" 16 | 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 17 | */ 18 | 19 | #ifndef ___SHA1_H___ 20 | #define ___SHA1_H___ 21 | 22 | // 23 | // SOLARIS USERS - IF YOUR SYSTEM IS LITTLE ENDIAN, REMOVE THE NEXT 3 LINES 24 | // also see bnbt.h 25 | // 26 | 27 | #if defined( __APPLE__ ) || defined( __SOLARIS__ ) 28 | #define BNBT_BIG_ENDIAN 29 | #endif 30 | 31 | //#include // Needed for file access 32 | //#include // Needed for memset and memcpy 33 | //#include // Needed for strcat and strcpy 34 | 35 | #define MAX_FILE_READ_BUFFER 8000 36 | 37 | class CSHA1 38 | { 39 | public: 40 | // Rotate x bits to the left 41 | #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits)))) 42 | 43 | #ifdef BNBT_BIG_ENDIAN 44 | #define SHABLK0(i) (block->l[i]) 45 | #else 46 | #define SHABLK0(i) (block->l[i] = (ROL32(block->l[i],24) & 0xFF00FF00) \ 47 | | (ROL32(block->l[i],8) & 0x00FF00FF)) 48 | #endif 49 | 50 | #define SHABLK(i) (block->l[i&15] = ROL32(block->l[(i+13)&15] ^ block->l[(i+8)&15] \ 51 | ^ block->l[(i+2)&15] ^ block->l[i&15],1)) 52 | 53 | // SHA-1 rounds 54 | #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } 55 | #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } 56 | #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); } 57 | #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); } 58 | #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); } 59 | 60 | typedef union { 61 | unsigned char c[64]; 62 | unsigned long l[16]; 63 | } SHA1_WORKSPACE_BLOCK; 64 | 65 | // Two different formats for ReportHash(...) 66 | enum { REPORT_HEX = 0, REPORT_DIGIT = 1 }; 67 | 68 | // Constructor and Destructor 69 | CSHA1(); 70 | virtual ~CSHA1(); 71 | 72 | unsigned long m_state[5]; 73 | unsigned long m_count[2]; 74 | unsigned char m_buffer[64]; 75 | unsigned char m_digest[20]; 76 | 77 | void Reset(); 78 | 79 | // Update the hash value 80 | void Update(const unsigned char* data, unsigned int len); 81 | 82 | // Finalize hash and report 83 | void Final(); 84 | void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX); 85 | void GetHash(unsigned char *uDest); 86 | 87 | private: 88 | // Private SHA-1 transformation 89 | void Transform(unsigned long state[5], const unsigned char buffer[64]); 90 | }; 91 | 92 | #endif // ___SHA1_H___ 93 | -------------------------------------------------------------------------------- /src/atom.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2005 Trevor Hogan 3 | // 4 | 5 | #ifndef ATOM_H 6 | #define ATOM_H 7 | 8 | class CAtom 9 | { 10 | public: 11 | virtual ~CAtom( ) { } 12 | 13 | virtual bool isLong( ) { return false; } 14 | virtual bool isList( ) { return false; } 15 | virtual bool isDicti( ) { return false; } 16 | 17 | virtual int EncodedLength( ) = 0; 18 | virtual int Length( ) = 0; 19 | virtual string toString( ) = 0; 20 | }; 21 | 22 | class CAtomInt : public CAtom 23 | { 24 | public: 25 | CAtomInt( ); 26 | CAtomInt( const int &iInt ); 27 | CAtomInt( const CAtomInt &c ); 28 | virtual ~CAtomInt( ); 29 | 30 | virtual int EncodedLength( ); 31 | virtual int Length( ); 32 | virtual string toString( ); 33 | 34 | int getValue( ) const; 35 | void setValue( const int &iInt ); 36 | 37 | private: 38 | int m_iInt; 39 | }; 40 | 41 | class CAtomLong : public CAtom 42 | { 43 | public: 44 | CAtomLong( ); 45 | CAtomLong( const int64 &iLong ); 46 | CAtomLong( const CAtomLong &c ); 47 | virtual ~CAtomLong( ); 48 | 49 | virtual int EncodedLength( ); 50 | virtual int Length( ); 51 | virtual string toString( ); 52 | 53 | int64 getValue( ) const; 54 | void setValue( const int64 &iLong ); 55 | 56 | private: 57 | int64 m_iLong; 58 | }; 59 | 60 | class CAtomString : public CAtom 61 | { 62 | public: 63 | CAtomString( ); 64 | CAtomString( const string &strString ); 65 | CAtomString( const CAtomString &c ); 66 | virtual ~CAtomString( ); 67 | 68 | virtual int EncodedLength( ); 69 | virtual int Length( ); 70 | virtual string toString( ); 71 | 72 | string getValue( ) const; 73 | void setValue( const string &strString ); 74 | 75 | private: 76 | string m_strString; 77 | }; 78 | 79 | class CAtomList : public CAtom 80 | { 81 | public: 82 | CAtomList( ); 83 | CAtomList( const vector &vecList ); 84 | CAtomList( const CAtomList &c ); 85 | virtual ~CAtomList( ); 86 | 87 | virtual bool isList( ) { return true; } 88 | 89 | virtual int EncodedLength( ); 90 | virtual int Length( ); 91 | virtual string toString( ); 92 | 93 | virtual bool isEmpty( ); 94 | virtual void clear( ); 95 | 96 | virtual void Randomize( ); 97 | 98 | vector getValue( ) const; 99 | vector *getValuePtr( ) const; 100 | void setValue( const vector &vecList ); 101 | 102 | void delItem( CAtom *atmItem ); 103 | void addItem( CAtom *atmItem ); 104 | 105 | private: 106 | vector m_vecList; 107 | }; 108 | 109 | class CAtomDicti : public CAtom 110 | { 111 | public: 112 | CAtomDicti( ); 113 | CAtomDicti( const CAtomDicti &c ); 114 | virtual ~CAtomDicti( ); 115 | 116 | virtual bool isDicti( ) { return true; } 117 | 118 | virtual int EncodedLength( ); 119 | virtual int Length( ); 120 | virtual string toString( ); 121 | 122 | virtual bool isEmpty( ); 123 | virtual void clear( ); 124 | 125 | map *getValuePtr( ) const; 126 | void setValue( const map &mapDicti ); 127 | 128 | void delItem( const string &strKey ); 129 | void eraseItem( const string &strKey ); 130 | CAtom *getItem( const string &strKey ); 131 | CAtom *getItem( const string &strKey, CAtom *pReturn ); 132 | void setItem( const string &strKey, CAtom *pValue ); 133 | 134 | private: 135 | map m_mapDicti; 136 | }; 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /stylesheets/filedump.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | 61 | 62 | 63 | 64 | 67 | 68 |
Hash 11 | 12 |
Torrent 17 | 18 |
Name 23 | 24 |
Added 29 | 30 |
Size 35 | 36 |
Files 41 | 42 |
Completed 47 | 48 |
Tag 53 | 54 |
Description 59 | 60 |
Uploader 65 | 66 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 83 | 86 | 89 | 92 | 95 | 98 | 99 | 100 |
IDIPUploadedDownloadedLeftConnected
81 | 82 | 84 | 85 | 87 | 88 | 90 | 91 | 93 | 94 | 96 | 97 |
101 |

102 |
103 | 104 | 105 |
106 |
-------------------------------------------------------------------------------- /stylesheets/filedump.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/util_ntservice.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | /*********************************************************************** 6 | * NT Service code written by ConfusedFish and modified by Trevor Hogan * 7 | ***********************************************************************/ 8 | 9 | #ifndef UTIL_NTSERVICE_H 10 | #define UTIL_NTSERVICE_H 11 | 12 | // Values are 32 bit values layed out as follows: 13 | // 14 | // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 15 | // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 16 | // +---+-+-+-----------------------+-------------------------------+ 17 | // |Sev|C|R| Facility | Code | 18 | // +---+-+-+-----------------------+-------------------------------+ 19 | // 20 | // where 21 | // 22 | // Sev - is the severity code 23 | // 24 | // 00 - Success 25 | // 01 - Informational 26 | // 10 - Warning 27 | // 11 - Error 28 | // 29 | // C - is the Customer code flag 30 | // 31 | // R - is a reserved bit 32 | // 33 | // Facility - is the facility code 34 | // 35 | // Code - is the facility's status code 36 | // 37 | // 38 | // Define the facility codes 39 | 40 | // 41 | // Define the severity codes 42 | // 43 | 44 | // 45 | // MessageId: EVMSG_INSTALLED 46 | // 47 | // MessageText: 48 | // 49 | // The %1 service was installed. 50 | // 51 | 52 | #define EVMSG_INSTALLED 0x00000064L 53 | 54 | // 55 | // MessageId: EVMSG_REMOVED 56 | // 57 | // MessageText: 58 | // 59 | // The %1 service was removed. 60 | // 61 | 62 | #define EVMSG_REMOVED 0x00000065L 63 | 64 | // 65 | // MessageId: EVMSG_NOTREMOVED 66 | // 67 | // MessageText: 68 | // 69 | // The %1 service could not be removed. 70 | // 71 | 72 | #define EVMSG_NOTREMOVED 0x00000066L 73 | 74 | // 75 | // MessageId: EVMSG_CTRLHANDLERNOTINSTALLED 76 | // 77 | // MessageText: 78 | // 79 | // The control handler could not be installed. 80 | // 81 | 82 | #define EVMSG_CTRLHANDLERNOTINSTALLED 0x00000067L 83 | 84 | // 85 | // MessageId: EVMSG_FAILEDINIT 86 | // 87 | // MessageText: 88 | // 89 | // The initialization process failed. 90 | // 91 | 92 | #define EVMSG_FAILEDINIT 0x00000068L 93 | 94 | // 95 | // MessageId: EVMSG_STARTED 96 | // 97 | // MessageText: 98 | // 99 | // The service was started. 100 | // 101 | 102 | #define EVMSG_STARTED 0x00000069L 103 | 104 | // 105 | // MessageId: EVMSG_BADREQUEST 106 | // 107 | // MessageText: 108 | // 109 | // The service received an unsupported request. 110 | // 111 | 112 | #define EVMSG_BADREQUEST 0x0000006AL 113 | 114 | // 115 | // MessageId: EVMSG_DEBUG 116 | // 117 | // MessageText: 118 | // 119 | // Debug: %1 120 | // 121 | 122 | #define EVMSG_DEBUG 0x0000006BL 123 | 124 | // 125 | // MessageId: EVMSG_STOPPED 126 | // 127 | // MessageText: 128 | // 129 | // The service was stopped. 130 | // 131 | 132 | #define EVMSG_STOPPED 0x0000006CL 133 | 134 | bool UTIL_NTServiceTest( ); 135 | bool UTIL_NTServiceInstall( ); 136 | bool UTIL_NTServiceUninstall( ); 137 | bool UTIL_NTServiceStart( ); 138 | bool UTIL_NTServiceStop( ); 139 | 140 | void UTIL_NTLogEvent( WORD wType, DWORD dwID, const char *pszS1 = 0, const char *pszS2 = 0, const char *pszS3 = 0 ); 141 | 142 | void WINAPI NTServiceHandler( DWORD dwOpcode ); 143 | void WINAPI NTServiceMain( DWORD dwArgc, LPTSTR *lpszArgv ); 144 | 145 | extern SERVICE_STATUS_HANDLE ghServiceStatus; 146 | extern SERVICE_STATUS gssStatus; 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /src/html.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2005 Trevor Hogan 3 | // 4 | 5 | #ifndef HTML_H 6 | #define HTML_H 7 | 8 | #include "config.h" 9 | #include "tracker.h" 10 | // tphogan - reference http://www.greenend.org.uk/rjk/2003/03/inline.html 11 | 12 | static inline string HTML_MakeURLFromFQDN( const string &cstrFQDN, const unsigned int &cuiPort ) 13 | { 14 | if( !cstrFQDN.empty( ) && cuiPort > 0 ) 15 | return string( "http://" + cstrFQDN + ":" + CAtomInt( cuiPort ).toString( ) + RESPONSE_STR_SEPERATOR ); 16 | else 17 | return string( ); 18 | } 19 | 20 | static inline string JS_Noscript( ) 21 | { 22 | return "\n\n"; 23 | } 24 | 25 | // Submit Button 26 | static inline string Button_Submit( const string &cstrID, const string &cstrLabel ) 27 | { 28 | return ""; 29 | // return ""; 30 | } 31 | 32 | // Reset Button 33 | static inline string Button_Reset( const string &cstrID, const string &cstrLabel ) 34 | { 35 | return ""; 36 | } 37 | 38 | // Back Button 39 | static inline string Button_Back( const string &cstrID, const string &cstrLabel ) 40 | { 41 | return ""; 42 | } 43 | 44 | // Link Button 45 | static inline string Button_JS_Link( const string &cstrID, const string &cstrLabel, const string &cstrJSFunction ) 46 | { 47 | return ""; 48 | } 49 | 50 | // The target Javascript 51 | static inline string JS_Target( const string &cstrRel, const string &cstrTarget ) 52 | { 53 | string strTarget = string( ); 54 | 55 | // Display a message if javascript not supported by browser 56 | strTarget = JS_Noscript( ); 57 | 58 | if( !cstrRel.empty( ) && !cstrTarget.empty( ) ) 59 | { 60 | // This function facilitates the replacement of target="_blank" with an equivalent 61 | // in javascript fot HTML 4.01 Strict compliance 62 | // Usage: 63 | // where you used \n\n"; 67 | strTarget += "\n\n"; 79 | strTarget += "\n\n"; 80 | } 81 | 82 | return strTarget; 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/tracker_log.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | // =Xotic= Modified Source File 23 | 24 | #include 25 | 26 | #if defined ( WIN32 ) 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | #include "bnbt.h" 33 | #include "bnbt_mysql.h" 34 | #include "atom.h" 35 | #include "html.h" 36 | #include "config.h" 37 | #include "tracker.h" 38 | #include "util.h" 39 | 40 | void CTracker :: serverResponseLog( struct request_t *pRequest, struct response_t *pResponse ) 41 | { 42 | // Set the start time 43 | const struct bnbttv btv( UTIL_CurrentTime( ) ); 44 | 45 | // Verify that the IP is permitted to access the tracker 46 | if( m_ucIPBanMode != 0 ) 47 | if( IsIPBanned( pRequest, pResponse, btv, gmapLANG_CFG["log_page"], string( CSS_LOG ), NOT_INDEX ) ) 48 | return; 49 | 50 | if( !pRequest->user.strUID.empty( ) && ( pRequest->user.ucAccess & m_ucAccessViewLog ) ) 51 | { 52 | if( !gstrLogDir.empty( ) && !gstrLogFilePattern.empty( ) ) 53 | { 54 | unsigned int iShowLog = CFG_GetInt( "bnbt_log_show_day", 3 ); 55 | 56 | time_t tNow = time( 0 ); 57 | 58 | struct tm tmToday = *localtime( &tNow ); 59 | 60 | 61 | string strLog = string( ); 62 | 63 | // Output common HTML head 64 | HTML_Common_Begin( pRequest, pResponse, gmapLANG_CFG["log_page"], string( CSS_LOG ), string( ), NOT_INDEX, CODE_200 ); 65 | 66 | pResponse->strContent += ""; 68 | pResponse->strContent += "
"; 67 | pResponse->strContent += "

" + gmapLANG_CFG["log_top"] + "\n

\n"; 69 | 70 | for( unsigned int i = 0; i < iShowLog; i++ ) 71 | { 72 | 73 | mktime( &tmToday ); 74 | char pTime[256]; 75 | memset( pTime, 0, sizeof( pTime ) / sizeof( char ) ); 76 | strftime( pTime, sizeof( pTime ) / sizeof( char ), gstrLogFilePattern.data( ), &tmToday ); 77 | tmToday.tm_mday--; 78 | 79 | const string cstrFile( gstrLogDir + pTime ); 80 | 81 | pResponse->strContent += "\n"; 82 | pResponse->strContent += ""; 83 | pResponse->strContent += "\n"; 84 | 85 | } 86 | pResponse->strContent += "
" + cstrFile + "
\n\n"; 87 | 88 | tmToday = *localtime( &tNow ); 89 | 90 | for( unsigned int i = 0; i < iShowLog; i++ ) 91 | { 92 | mktime( &tmToday ); 93 | char pTime[256]; 94 | memset( pTime, 0, sizeof( pTime ) / sizeof( char ) ); 95 | strftime( pTime, sizeof( pTime ) / sizeof( char ), gstrLogFilePattern.data( ), &tmToday ); 96 | tmToday.tm_mday--; 97 | 98 | const string cstrFile( gstrLogDir + pTime ); 99 | 100 | if( access( string( cstrFile ).c_str( ), 0 ) == 0 ) 101 | strLog = UTIL_ReadFile( cstrFile.c_str( ) ); 102 | else 103 | strLog = string( ); 104 | 105 | pResponse->strContent += ""; 108 | if( !strLog.empty( ) ) 109 | { 110 | pResponse->strContent += "\n"; 115 | } 116 | pResponse->strContent += "
\n"; 106 | pResponse->strContent += "

" + UTIL_RemoveHTML( cstrFile ); 107 | pResponse->strContent += " - " + gmapLANG_CFG["log_top"] + "

\n"; 111 | pResponse->strContent += ""; 112 | pResponse->strContent += "\n\n"; 113 | 114 | pResponse->strContent += "
" + UTIL_RemoveHTML( strLog ) + "
\n\n"; 117 | } 118 | // Output common HTML tail 119 | HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_LOG ) ); 120 | } 121 | 122 | 123 | 124 | } 125 | else 126 | { 127 | // Not authorised 128 | 129 | // Output common HTML head 130 | HTML_Common_Begin( pRequest, pResponse, gmapLANG_CFG["log_page"], string( CSS_LOG ), string( ), NOT_INDEX, CODE_401 ); 131 | 132 | // Output common HTML tail 133 | HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_LOG ) ); 134 | } 135 | // } 136 | } 137 | -------------------------------------------------------------------------------- /src/link.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2003-2004 Trevor Hogan 3 | // 4 | 5 | #ifndef LINK_H 6 | #define LINK_H 7 | 8 | // 9 | // CLink 10 | // - one instance created on the secondary tracker to connect to the primary tracker 11 | // 12 | 13 | class CLink 14 | { 15 | public: 16 | CLink( ); 17 | virtual ~CLink( ); 18 | 19 | void Kill( ); 20 | void Go( ); 21 | 22 | string getName( ); 23 | 24 | void Queue( struct linkmsg_t lm ); 25 | 26 | private: 27 | bool m_bKill; 28 | 29 | string m_strIP; 30 | string m_strPass; 31 | 32 | SOCKET m_sckLink; 33 | 34 | // struct sockaddr_in sin; 35 | struct sockaddr_in6 sin; 36 | 37 | string m_strReceiveBuf; 38 | string m_strSendBuf; 39 | 40 | void Send( struct linkmsg_t lm ); 41 | struct linkmsg_t Receive( bool bBlock ); 42 | struct linkmsg_t Parse( ); 43 | 44 | CMutex m_mtxQueued; 45 | 46 | vector m_vecQueued; 47 | }; 48 | 49 | void StartLink( ); 50 | 51 | // 52 | // CLinkClient 53 | // - one instance created on the primary tracker for each secondary tracker 54 | // 55 | 56 | class CLinkClient 57 | { 58 | public: 59 | // CLinkClient( SOCKET sckLink, struct sockaddr_in sinAddress ); 60 | CLinkClient( SOCKET sckLink, struct sockaddr_in6 sinAddress ); 61 | virtual ~CLinkClient( ); 62 | 63 | void Kill( ); 64 | void Go( ); 65 | 66 | string getName( ); 67 | 68 | void Queue( struct linkmsg_t lm ); 69 | 70 | bool m_bActive; 71 | 72 | private: 73 | bool m_bKill; 74 | 75 | SOCKET m_sckLink; 76 | 77 | // struct sockaddr_in sin; 78 | struct sockaddr_in6 sin; 79 | 80 | string m_strReceiveBuf; 81 | string m_strSendBuf; 82 | 83 | void Send( struct linkmsg_t lm ); 84 | struct linkmsg_t Receive( bool bBlock ); 85 | struct linkmsg_t Parse( ); 86 | 87 | CMutex m_mtxQueued; 88 | 89 | vector m_vecQueued; 90 | }; 91 | 92 | void StartLinkClient( CLinkClient *pLinkClient ); 93 | 94 | // 95 | // CLinkServer 96 | // - one instance created on the primary tracker 97 | // 98 | 99 | class CLinkServer 100 | { 101 | public: 102 | CLinkServer( ); 103 | virtual ~CLinkServer( ); 104 | 105 | void Update( ); 106 | 107 | void Queue( struct linkmsg_t lm ); 108 | void Queue( struct linkmsg_t lm, string strExclude ); 109 | 110 | string m_strPass; 111 | 112 | CMutex m_mtxLinks; 113 | 114 | vector m_vecLinks; 115 | 116 | private: 117 | string m_strBind; 118 | 119 | SOCKET m_sckLinkServer; 120 | }; 121 | 122 | /*** 123 | * 124 | * XBNBT Beta 81b.3.5 - A C++ BitTorrent Tracker 125 | * Copyright (C) 2003-2004 =Xotic= 126 | * 127 | * This library is free software; you can redistribute it and/or 128 | * modify it under the terms of the GNU Lesser General Public 129 | * License as published by the Free Software Foundation; either 130 | * version 2.1 of the License, or (at your option) any later version. 131 | * 132 | * This library is distributed in the hope that it will be useful, 133 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 134 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 135 | * Lesser General Public License for more details. 136 | * 137 | * You should have received a copy of the GNU Lesser General Public 138 | * License along with this library; if not, write to the Free Software 139 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 140 | * 141 | ***/ 142 | 143 | // 144 | // CHUBLink 145 | // - one instance created on the secondary tracker to connect to the primary tracker 146 | // 147 | 148 | class CHUBLink 149 | { 150 | public: 151 | CHUBLink( ); 152 | virtual ~CHUBLink( ); 153 | 154 | void Kill( ); 155 | void Go( ); 156 | 157 | string getName( ); 158 | 159 | void Queue( struct linkmsg_t lm ); 160 | 161 | private: 162 | bool m_bKill; 163 | 164 | string m_strIP; 165 | string m_strPass; 166 | 167 | SOCKET m_sckLink; 168 | 169 | // struct sockaddr_in sin; 170 | struct sockaddr_in6 sin; 171 | 172 | string m_strReceiveBuf; 173 | string m_strSendBuf; 174 | 175 | void Send( struct linkmsg_t lm ); 176 | struct linkmsg_t Receive( bool bBlock ); 177 | struct linkmsg_t Parse( ); 178 | 179 | CMutex m_mtxQueued; 180 | 181 | vector m_vecQueued; 182 | }; 183 | 184 | void StartHUBLink( ); 185 | 186 | // 187 | // CHUBLinkClient 188 | // - one instance created on the primary tracker for each secondary tracker 189 | // 190 | 191 | class CHUBLinkClient 192 | { 193 | public: 194 | // CHUBLinkClient( SOCKET sckLink, struct sockaddr_in sinAddress ); 195 | CHUBLinkClient( SOCKET sckLink, struct sockaddr_in6 sinAddress ); 196 | virtual ~CHUBLinkClient( ); 197 | 198 | void Kill( ); 199 | void Go( ); 200 | 201 | string getName( ); 202 | 203 | void Queue( struct linkmsg_t lm ); 204 | 205 | bool m_bActive; 206 | 207 | private: 208 | bool m_bKill; 209 | 210 | SOCKET m_sckLink; 211 | 212 | // struct sockaddr_in sin; 213 | struct sockaddr_in6 sin; 214 | 215 | string m_strReceiveBuf; 216 | string m_strSendBuf; 217 | 218 | void Send( struct linkmsg_t lm ); 219 | struct linkmsg_t Receive( bool bBlock ); 220 | struct linkmsg_t Parse( ); 221 | 222 | CMutex m_mtxQueued; 223 | 224 | vector m_vecQueued; 225 | }; 226 | 227 | void StartHUBLinkClient( CHUBLinkClient *pLinkClient ); 228 | 229 | // 230 | // CHUBLinkServer 231 | // - one instance created on the primary tracker 232 | // 233 | 234 | class CHUBLinkServer 235 | { 236 | public: 237 | CHUBLinkServer( ); 238 | virtual ~CHUBLinkServer( ); 239 | 240 | void Update( ); 241 | 242 | void Queue( struct linkmsg_t lm ); 243 | void Queue( struct linkmsg_t lm, string strExclude ); 244 | 245 | string m_strPass; 246 | 247 | CMutex m_mtxLinks; 248 | 249 | vector m_vecLinks; 250 | 251 | private: 252 | string m_strBind; 253 | 254 | SOCKET m_sckLinkServer; 255 | }; 256 | 257 | #endif 258 | -------------------------------------------------------------------------------- /src/md5.h: -------------------------------------------------------------------------------- 1 | /* MD5.H - header file for MD5C.C 2 | */ 3 | 4 | /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 5 | rights reserved. 6 | 7 | License to copy and use this software is granted provided that it 8 | is identified as the "RSA Data Security, Inc. MD5 Message-Digest 9 | Algorithm" in all material mentioning or referencing this software 10 | or this function. 11 | 12 | License is also granted to make and use derivative works provided 13 | that such works are identified as "derived from the RSA Data 14 | Security, Inc. MD5 Message-Digest Algorithm" in all material 15 | mentioning or referencing the derived work. 16 | 17 | RSA Data Security, Inc. makes no representations concerning either 18 | the merchantability of this software or the suitability of this 19 | software for any particular purpose. It is provided "as is" 20 | without express or implied warranty of any kind. 21 | 22 | These notices must be retained in any copies of any part of this 23 | documentation and/or software. 24 | 25 | modified by Trevor Hogan for use with BNBT 26 | */ 27 | 28 | // =Xotic= Modified Source File 29 | 30 | #ifndef MD5_H 31 | #define MD5_H 32 | 33 | /* POINTER defines a generic pointer type */ 34 | typedef unsigned char *POINTER; 35 | typedef const unsigned char *CONSTPOINTER; 36 | 37 | /* UINT2 defines a two byte word */ 38 | typedef unsigned short int UINT2; 39 | 40 | /* UINT4 defines a four byte word */ 41 | typedef unsigned long int UINT4; 42 | 43 | #define PROTO_LIST(list) list 44 | 45 | /* MD5 context. */ 46 | typedef struct{ 47 | UINT4 state[4]; /* state (ABCD) */ 48 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ 49 | unsigned char buffer[64]; /* input buffer */ 50 | }MD5_CTX; 51 | 52 | void MD5Init PROTO_LIST ((MD5_CTX *)); 53 | void MD5Update PROTO_LIST ((MD5_CTX *, const unsigned char *, unsigned int)); 54 | void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); 55 | 56 | #if defined ( XBNBT_MYSQL ) 57 | ////////////////////////////////////////////////////////////////////// 58 | // 59 | // Interface for the CMD5 class. 60 | // 61 | ////////////////////////////////////////////////////////////////////// 62 | 63 | #if !defined(AFX_MD51_H__2A1EA377_D065_11D4_A8C8_0050DAC6D85C__INCLUDED_) 64 | #define AFX_MD51_H__2A1EA377_D065_11D4_A8C8_0050DAC6D85C__INCLUDED_ 65 | 66 | #ifdef _MSC_VER 67 | #if _MSC_VER > 1000 68 | #pragma once 69 | #endif // _MSC_VER > 1000 70 | #endif 71 | 72 | 73 | /*************************************************************************** 74 | 75 | This class is a utility wrapper for 'C' code contained in internet RFC 1321, 76 | "The MD5 Message-Digest Algorithm". 77 | 78 | It calculates a cryptological hash value, called a "digest" from a character 79 | string. For every unique character string the MD5 hash is guaranteed to be 80 | unique. The MD5 hash has the property that given the digest, it's 81 | thought to be impossible to get back to the plain text string with existing 82 | technology. In this implementation the digest is always a 32 digit hex number, 83 | regardless of the length of the input plaintext. 84 | 85 | This class is helpful for programs which store passwords. Rather than storing 86 | the password directly, the programmer should store the MD5 digest of the password. 87 | Then when the user enters a password, compute the MD5 digest of the input password. 88 | If it is identical to the stored digest, then the user 89 | has entered the correct password. It doesn't matter if an evil person sees the 90 | digest, since he or she can't get from the digest to the password. At least not 91 | unless the user enters a word out of the dictionary, since the evil person could 92 | hash the whole dictionary. One way to defeat a dictionary attack is to append 93 | a non-text character onto the password, so that even if the user enters a dumb 94 | password like "password", you just append some non alpha character to the entered 95 | password, i.e. password = "password" + "$". By always appending a nonalpha 96 | character, your stored digest isn't in the attacker's dictionary. You can 97 | then safely post the digest of the password on a highway billboard. 98 | 99 | Example pseudocode: 100 | { 101 | std::string storedPasswordDigest = GetPasswordDigestFromStorage(); 102 | std::string passwordEnteredbyUser; 103 | cout << "Enter password:" ; 104 | cin >> passwordEnteredbyUser; 105 | 106 | CMD5 md5(passwordEnteredbyUser.c_str()); //note c_str() returns a pointer to the std::string's character buffer, just like CString's "GetBuffer" member function. 107 | 108 | if(md5.getMD5Digest != storedPasswordDigest) 109 | { 110 | //user has entered an invalid password 111 | cout << "Incorrect password!"; 112 | exit(1); 113 | } 114 | 115 | //if we get here, then the user entered a valid password 116 | } 117 | ************************************************************************** 118 | Use this code as you see fit. It is provided "as is" 119 | without express or implied warranty of any kind. 120 | 121 | Jim Howard, jnhtx@jump.net 122 | ***************************************************************************/ 123 | 124 | class CMD5 125 | { 126 | public: 127 | CMD5(); //default ctor 128 | CMD5(const char* plainText); //set plaintext in ctor 129 | void setPlainText(const char* plainText);//set plaintext with a mutator, it's ok to 130 | //to call this multiple times, the digest is recalculated after each call. 131 | const char* getMD5Digest(); //access message digest (aka hash), return 0 if plaintext has not been set 132 | 133 | virtual ~CMD5(); 134 | private: 135 | bool calcDigest(); //this function computes the digest by calling the RFC 1321 'C' code 136 | 137 | bool m_digestValid; //false until the plaintext has been set and digest computed 138 | unsigned char m_digest[16]; //the numerical value of the digest 139 | char m_digestString[33]; //0 terminated string value of the digest expressed in hex digits 140 | char* m_plainText;//a pointer to the plain text. If casting away the const-ness 141 | //worries you, you could either make a local copy of the plain 142 | //text string instead of just pointing at the user's string or 143 | //modify the RFC 1321 code to take 'const' plaintext. 144 | }; 145 | 146 | #endif //!defined(AFX_MD51_H__2A1EA377_D065_11D4_A8C8_0050DAC6D85C__INCLUDED_) 147 | 148 | #endif //defined ( XBNBT_MYSQL ) 149 | 150 | #endif //MD5_H 151 | -------------------------------------------------------------------------------- /src/sha1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 100% free public domain implementation of the SHA-1 3 | algorithm by Dominik Reichl 4 | 5 | * modified by Trevor Hogan for use with BNBT * 6 | 7 | === Test Vectors (from FIPS PUB 180-1) === 8 | 9 | "abc" 10 | A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 11 | 12 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 13 | 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 14 | 15 | A million repetitions of "a" 16 | 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 17 | */ 18 | 19 | #include "bnbt.h" 20 | #include "sha1.h" 21 | 22 | 23 | CSHA1::CSHA1() 24 | { 25 | Reset(); 26 | } 27 | 28 | CSHA1::~CSHA1() 29 | { 30 | Reset(); 31 | } 32 | 33 | 34 | void CSHA1::Reset() 35 | { 36 | // SHA1 initialization constants 37 | m_state[0] = 0x67452301; 38 | m_state[1] = 0xEFCDAB89; 39 | m_state[2] = 0x98BADCFE; 40 | m_state[3] = 0x10325476; 41 | m_state[4] = 0xC3D2E1F0; 42 | 43 | m_count[0] = 0; 44 | m_count[1] = 0; 45 | } 46 | 47 | void CSHA1::Transform(unsigned long state[5], const unsigned char buffer[64]) 48 | { 49 | unsigned long a = 0; 50 | unsigned long b = 0; 51 | unsigned long c = 0; 52 | unsigned long d = 0; 53 | unsigned long e = 0; 54 | 55 | SHA1_WORKSPACE_BLOCK* block; 56 | static unsigned char workspace[64]; 57 | memset( workspace, 0, sizeof( workspace ) / sizeof( unsigned char ) ); 58 | block = (SHA1_WORKSPACE_BLOCK *)workspace; 59 | memcpy(block, buffer, sizeof( workspace ) / sizeof( unsigned char )); 60 | 61 | // Copy state[] to working vars 62 | a = state[0]; 63 | b = state[1]; 64 | c = state[2]; 65 | d = state[3]; 66 | e = state[4]; 67 | 68 | // 4 rounds of 20 operations each. Loop unrolled. 69 | R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); 70 | R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); 71 | R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); 72 | R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); 73 | R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); 74 | R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); 75 | R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); 76 | R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); 77 | R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); 78 | R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); 79 | R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); 80 | R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); 81 | R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); 82 | R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); 83 | R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); 84 | R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); 85 | R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); 86 | R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); 87 | R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); 88 | R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); 89 | 90 | // Add the working vars back into state[] 91 | state[0] += a; 92 | state[1] += b; 93 | state[2] += c; 94 | state[3] += d; 95 | state[4] += e; 96 | 97 | // Wipe variables 98 | a = 0; 99 | b = 0; 100 | c = 0; 101 | d = 0; 102 | e = 0; 103 | } 104 | 105 | // Use this function to hash in binary data and strings 106 | void CSHA1::Update(const unsigned char* data, unsigned int len) 107 | { 108 | unsigned long i = 0; 109 | unsigned long it2 = 0; 110 | 111 | it2 = (m_count[0] >> 3) & 63; 112 | 113 | if((m_count[0] += len << 3) < (len << 3)) m_count[1]++; 114 | 115 | m_count[1] += (len >> 29); 116 | 117 | if((it2 + len) > 63) 118 | { 119 | memcpy(&m_buffer[it2], data, (i = 64 - it2)); 120 | Transform(m_state, m_buffer); 121 | 122 | for (; i+63 < len; i += 64) 123 | { 124 | Transform(m_state, &data[i]); 125 | } 126 | 127 | it2 = 0; 128 | } 129 | else i = 0; 130 | 131 | memcpy(&m_buffer[it2], &data[i], len - i); 132 | } 133 | 134 | void CSHA1::Final() 135 | { 136 | unsigned long i = 0; 137 | unsigned long it2 = 0; 138 | unsigned char finalcount[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 139 | 140 | for (i = 0; i < sizeof( finalcount ) / sizeof( unsigned char ); i++) 141 | finalcount[i] = (unsigned char)((m_count[(i >= 4 ? 0 : 1)] 142 | >> ((3 - (i & 3)) * 8) ) & 255); // Endian independent 143 | 144 | Update((const unsigned char *)"\200", 1); 145 | 146 | while ((m_count[0] & 504) != 448) 147 | Update((const unsigned char *)"\0", 1); 148 | 149 | Update(finalcount, sizeof( finalcount ) / sizeof( unsigned char ) ); // Cause a SHA1Transform() 150 | 151 | for (i = 0; i < sizeof( m_digest ) / sizeof( unsigned char ); i++) 152 | { 153 | m_digest[i] = (unsigned char)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255); 154 | } 155 | 156 | // Wipe variables for security reasons 157 | i = 0; 158 | it2 = 0; 159 | memset( m_buffer, 0, sizeof( m_buffer ) / sizeof( unsigned char ) ); 160 | memset( m_state, 0, sizeof( m_state ) / sizeof( unsigned long ) ); 161 | memset( m_count, 0, sizeof( m_count ) / sizeof( unsigned long ) ); 162 | memset( finalcount, 0, sizeof( finalcount ) / sizeof( unsigned char ) ); 163 | 164 | Transform(m_state, m_buffer); 165 | } 166 | 167 | // Get the final hash as a pre-formatted string 168 | void CSHA1::ReportHash(char *szReport, unsigned char uReportType) 169 | { 170 | unsigned char i = 0; 171 | char szTemp[4]; 172 | memset( szTemp, 0, sizeof( szTemp ) / sizeof( char ) ); 173 | 174 | if(uReportType == REPORT_HEX) 175 | { 176 | snprintf( szTemp, sizeof( szTemp ) / sizeof( char ), "%02x", m_digest[0] ); 177 | strncat( szReport, szTemp, sizeof( szTemp ) / sizeof( char ) ); 178 | 179 | for(i = 1; i < sizeof( m_digest ) / sizeof( unsigned char ); i++) 180 | { 181 | memset( szTemp, 0, sizeof( szTemp ) / sizeof( char ) ); 182 | snprintf( szTemp, sizeof( szTemp ) / sizeof( char ), "%02x", m_digest[i] ); 183 | strncat( szReport, szTemp, sizeof( szTemp ) / sizeof( char ) ); 184 | } 185 | } 186 | else if(uReportType == REPORT_DIGIT) 187 | { 188 | snprintf( szTemp, sizeof( szTemp ) / sizeof( char ), "%u", m_digest[0] ); 189 | strncat( szReport, szTemp, sizeof( szTemp ) / sizeof( char ) ); 190 | 191 | for(i = 1; i < sizeof( m_digest ) / sizeof( unsigned char ); i++) 192 | { 193 | memset( szTemp, 0, sizeof( szTemp ) / sizeof( char ) ); 194 | snprintf( szTemp, sizeof( szTemp ) / sizeof( char ), " %u", m_digest[i] ); 195 | strncat( szReport, szTemp, sizeof( szTemp ) / sizeof( char ) ); 196 | } 197 | } 198 | else strncpy(szReport, "Error: Unknown report type!", ( sizeof( "Error: Unknown report type!" ) - 1 ) ); 199 | } 200 | 201 | // Get the raw message digest 202 | void CSHA1::GetHash(unsigned char *uDest) 203 | { 204 | memcpy( uDest, m_digest, sizeof( m_digest ) / sizeof( unsigned char ) ); 205 | } 206 | -------------------------------------------------------------------------------- /src/tracker_staff.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | // =Xotic= Modified Source File 23 | 24 | #include "bnbt.h" 25 | #include "bnbt_mysql.h" 26 | #include "atom.h" 27 | #include "html.h" 28 | #include "config.h" 29 | #include "sort.h" 30 | #include "tracker.h" 31 | #include "util.h" 32 | 33 | void CTracker :: serverResponseStaff( struct request_t *pRequest, struct response_t *pResponse ) 34 | { 35 | // Set the start time 36 | const struct bnbttv btv( UTIL_CurrentTime( ) ); 37 | 38 | // Verify that the IP is permitted to access the tracker 39 | if( m_ucIPBanMode != 0 ) 40 | if( IsIPBanned( pRequest, pResponse, btv, gmapLANG_CFG["staff_page"], string( CSS_STAFF ), NOT_INDEX ) ) 41 | return; 42 | 43 | // CMySQLQuery *pQuery = new CMySQLQuery( "SELECT buid,busername,bcreated,baccess,bgroup FROM users" ); 44 | // 45 | // vector vecQuery; 46 | 47 | // vecQuery.reserve(5); 48 | 49 | // vecQuery = pQuery->nextRow( ); 50 | 51 | // if( vecQuery.size( ) == 5 ) 52 | // { 53 | // Populate the users structure for display 54 | 55 | // const unsigned long culKeySize( (unsigned long)pQuery->numRows( ) ); 56 | 57 | // add the users into this structure one by one and sort it afterwards 58 | 59 | // struct user_t *pUsersT = new struct user_t[culKeySize]; 60 | 61 | unsigned long culKeySize = 0; 62 | 63 | struct user_t *pUsersT = 0; 64 | 65 | if( m_pCache ) 66 | { 67 | // m_pCache->ResetUsers( ); 68 | pUsersT = m_pCache->getCacheUsers( ); 69 | culKeySize = m_pCache->getSizeUsers( ); 70 | } 71 | 72 | unsigned long ulCount = 0; 73 | 74 | m_pCache->sortUsers( SORTU_ACREATED ); 75 | 76 | // qsort( pUsersT, culKeySize, sizeof( struct user_t ), asortuByCreated ); 77 | 78 | unsigned char ucAccess = ACCESS_ADMIN; 79 | unsigned char ucGroup = GROUP_VIP; 80 | 81 | if( !pRequest->user.strUID.empty( ) && ( pRequest->user.ucAccess & m_ucAccessView ) ) 82 | { 83 | HTML_Common_Begin( pRequest, pResponse, gmapLANG_CFG["staff_page"], string( CSS_STAFF ), string( ), NOT_INDEX, CODE_200 ); 84 | while( ucAccess > ACCESS_COMMENTS ) 85 | { 86 | // pResponse->strContent += "\n"; 89 | // pResponse->strContent += "
\n"; 87 | // pResponse->strContent += "

" + UTIL_AccessToString( ucAccess ); 88 | // pResponse->strContent += "

\n"; 90 | // pResponse->strContent += ""; 91 | 92 | ulCount = 0; 93 | bool bFound = false; 94 | 95 | for( unsigned long ulKey = 0; ulKey < culKeySize; ulKey++ ) 96 | { 97 | if( ( pUsersT[ulKey].ucAccess & ucAccess ) && pUsersT[ulKey].ucGroup == 0 ) 98 | { 99 | if( !bFound ) 100 | { 101 | pResponse->strContent += "
\n"; 104 | pResponse->strContent += "\n"; 123 | pResponse->strContent += "
\n"; 102 | pResponse->strContent += "

" + UTIL_AccessToString( ucAccess ); 103 | pResponse->strContent += "

\n"; 105 | pResponse->strContent += ""; 106 | } 107 | bFound = true; 108 | if( ulCount > 0 && ( ulCount % 3 == 0 ) ) 109 | pResponse->strContent += "\n"; 110 | pResponse->strContent += ""; 113 | pUsersT[ulKey].ucAccess = pUsersT[ulKey].ucAccess & ucAccess; 114 | ulCount++; 115 | } 116 | } 117 | if( bFound ) 118 | { 119 | for( unsigned long ulKey = 0; ulKey < ( 3 - ulCount % 3 ) % 3; ulKey++ ) 120 | pResponse->strContent += ""; 121 | pResponse->strContent += "\n"; 122 | pResponse->strContent += "
"; 111 | pResponse->strContent += getUserLink( pUsersT[ulKey].strUID, pUsersT[ulKey].strLogin ); 112 | pResponse->strContent += "
\n\n"; 124 | } 125 | 126 | ucAccess = ucAccess >> 1; 127 | } 128 | 129 | while( ucGroup > 0 ) 130 | { 131 | // pResponse->strContent += "\n"; 134 | // pResponse->strContent += "
\n"; 132 | // pResponse->strContent += "

" + UTIL_GroupToString( ucGroup ); 133 | // pResponse->strContent += "

\n"; 135 | // pResponse->strContent += ""; 136 | 137 | bool bFound = false; 138 | ulCount = 0; 139 | 140 | for( unsigned long ulKey = 0; ulKey < culKeySize; ulKey++ ) 141 | { 142 | if( pUsersT[ulKey].ucGroup & ucGroup ) 143 | { 144 | if( !bFound ) 145 | { 146 | pResponse->strContent += "
\n"; 149 | pResponse->strContent += "\n"; 168 | pResponse->strContent += "
\n"; 147 | pResponse->strContent += "

" + UTIL_GroupToString( ucGroup ); 148 | pResponse->strContent += "

\n"; 150 | pResponse->strContent += ""; 151 | } 152 | bFound = true; 153 | if( ulCount > 0 && ( ulCount % 3 == 0 ) ) 154 | pResponse->strContent += "\n"; 155 | pResponse->strContent += ""; 158 | // pUsersT[ulKey].ucAccess = pUsersT[ulKey].ucAccess & ucAccess; 159 | ulCount++; 160 | } 161 | } 162 | if( bFound ) 163 | { 164 | for( unsigned long ulKey = 0; ulKey < ( 3 - ulCount % 3 ) % 3; ulKey++ ) 165 | pResponse->strContent += ""; 166 | pResponse->strContent += "\n"; 167 | pResponse->strContent += "
"; 156 | pResponse->strContent += getUserLink( pUsersT[ulKey].strUID, pUsersT[ulKey].strLogin ); 157 | pResponse->strContent += "
\n\n"; 169 | } 170 | 171 | ucGroup = ucGroup >> 1; 172 | } 173 | // Output common HTML tail 174 | HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_STAFF ) ); 175 | } 176 | else 177 | { 178 | // Not authorised 179 | 180 | // Output common HTML head 181 | HTML_Common_Begin( pRequest, pResponse, gmapLANG_CFG["staff_page"], string( CSS_STAFF ), string( ), NOT_INDEX, CODE_401 ); 182 | 183 | // Output common HTML tail 184 | HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_STAFF ) ); 185 | } 186 | // delete [] pUsersT; 187 | // } 188 | // delete pQuery; 189 | } 190 | -------------------------------------------------------------------------------- /stylesheets/rss.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <xsl:value-of select="//channel/title" /> 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | Channel Image: 17 | 18 | {image/title} 20 | 21 |
22 |
23 | Channel Title: 24 | 25 |
26 |
27 | Channel Description: 28 | 29 |
30 |
31 | Channel Published: 32 | 33 |
34 |
35 | Channel Last Build: 36 | 37 |
38 |
39 | Channel Category: 40 | 41 | 42 | 43 |
44 | 45 |

46 |
47 | Item Title: 48 | 49 |
50 |
51 |
52 | Item Infostat Title: 53 | 54 |
55 |
56 | Item Link: 57 | 58 | 59 | 60 |
61 |
62 |
63 |
64 | Item Download Title: 65 | 66 |
67 |
68 | Item Enclosure URL: 69 | 70 | 71 | 72 |
73 |
74 | Item Enclosure Length: 75 | 76 |
77 |
78 | Item Enclosure Type: 79 | 80 |
81 |
82 |
83 | Item Author: 84 | 85 | 86 | 87 |
88 |
89 | Item Published: 90 | 91 |
92 |
93 | Item Category: 94 | 95 | 96 | 97 |
98 |
99 | Item Description: 100 | 101 |
102 |
103 |
104 | Item Size Title: 105 | 106 |
107 |
108 | Item Size: 109 | 110 |
111 |
112 |
113 |
114 | Item Files Title: 115 | 116 |
117 |
118 | Item Files: 119 | 120 |
121 |
122 |
123 |
124 | Item Seeders Title: 125 | 126 |
127 |
128 | Item Seeders: 129 | 130 |
131 |
132 |
133 |
134 | Item Leechers Title: 135 | 136 |
137 |
138 | Item Leechers: 139 | 140 |
141 |
142 |
143 |
144 | Item Completed Title: 145 | 146 |
147 |
148 | Item Completed: 149 | 150 |
151 |
152 |
153 | Item Infolink: 154 | 155 | 156 | 157 |
158 |
159 |
160 | Item Comments Title: 161 | 162 |
163 |
164 | Item Comments: 165 | 166 | 167 | 168 |
169 |
170 |
171 |
172 | Item Infohash Title: 173 | 174 |
175 |
176 | Item Guid: 177 | 178 |
179 |
180 |
181 |

182 |
183 | Channel Text Input: 184 |
185 | 188 | 189 | 190 | 196 | 197 | 198 |
199 |
200 |
201 | Channel Managing Editor: 202 | 203 | 204 | 205 |
206 |
207 | Channel Web Master: 208 | 209 | 210 | 211 |
212 |
213 | Channel Generator: 214 | 215 |
216 |
217 | Channel Copyright: 218 | 219 |
220 |
221 | 222 | 223 |
224 |
225 | -------------------------------------------------------------------------------- /src/bencode.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.5 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2005 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | #include "bnbt.h" 23 | #include "atom.h" 24 | #include "bencode.h" 25 | #include "util.h" 26 | 27 | string EncodeInt( const CAtomInt &x ) 28 | { 29 | char pBuf[128]; 30 | 31 | memset( pBuf, 0, sizeof( pBuf ) / sizeof( char ) ); 32 | 33 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%d", x.getValue( ) ); 34 | 35 | string strDest; 36 | 37 | strDest += "i"; 38 | strDest += pBuf; 39 | strDest += "e"; 40 | 41 | return strDest; 42 | } 43 | 44 | string EncodeLong( const CAtomLong &x ) 45 | { 46 | char pBuf[128]; 47 | 48 | memset( pBuf, 0, sizeof( pBuf ) / sizeof( char ) ); 49 | 50 | #if defined( WIN32 ) 51 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%I64d", x.getValue( ) ); 52 | #elif defined( __FREEBSD__ ) || defined( __OPENBSD__ ) || defined( __NETBSD__ ) 53 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%qd", x.getValue( ) ); 54 | #else 55 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%lld", x.getValue( ) ); 56 | #endif 57 | 58 | string strDest; 59 | 60 | strDest += "i"; 61 | strDest += pBuf; 62 | strDest += "e"; 63 | 64 | return strDest; 65 | } 66 | 67 | string EncodeString( const CAtomString &x ) 68 | { 69 | char pBuf[128]; 70 | 71 | memset( pBuf, 0, sizeof( pBuf ) / sizeof( char ) ); 72 | 73 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%u", (unsigned int)x.getValue( ).size( ) ); 74 | 75 | string strDest; 76 | 77 | strDest += pBuf; 78 | strDest += ":"; 79 | strDest += x.getValue( ); 80 | 81 | return strDest; 82 | } 83 | 84 | string EncodeList( const CAtomList &x ) 85 | { 86 | vector *pv = x.getValuePtr( ); 87 | 88 | string strDest; 89 | 90 | strDest += "l"; 91 | 92 | for( vector :: iterator i = pv->begin( ); i != pv->end( ); i++ ) 93 | { 94 | if( dynamic_cast( *i ) ) 95 | strDest += EncodeInt( *dynamic_cast( *i ) ); 96 | else if( dynamic_cast( *i ) ) 97 | strDest += EncodeLong( *dynamic_cast( *i ) ); 98 | else if( dynamic_cast( *i ) ) 99 | strDest += EncodeString( *dynamic_cast( *i ) ); 100 | else if( dynamic_cast( *i ) ) 101 | strDest += EncodeList( *dynamic_cast( *i ) ); 102 | else if( dynamic_cast( *i ) ) 103 | strDest += EncodeDicti( *dynamic_cast( *i ) ); 104 | } 105 | 106 | strDest += "e"; 107 | 108 | return strDest; 109 | } 110 | 111 | string EncodeDicti( const CAtomDicti &x ) 112 | { 113 | map *pmapDicti = x.getValuePtr( ); 114 | 115 | string strDest; 116 | 117 | strDest += "d"; 118 | 119 | for( map :: iterator i = pmapDicti->begin( ); i != pmapDicti->end( ); i++ ) 120 | { 121 | strDest += EncodeString( CAtomString( (*i).first ) ); 122 | 123 | if( dynamic_cast( (*i).second ) ) 124 | strDest += EncodeInt( *dynamic_cast( (*i).second ) ); 125 | else if( dynamic_cast( (*i).second ) ) 126 | strDest += EncodeLong( *dynamic_cast( (*i).second ) ); 127 | else if( dynamic_cast( (*i).second ) ) 128 | strDest += EncodeString( *dynamic_cast( (*i).second ) ); 129 | else if( dynamic_cast( (*i).second ) ) 130 | strDest += EncodeList( *dynamic_cast( (*i).second ) ); 131 | else if( dynamic_cast( (*i).second ) ) 132 | strDest += EncodeDicti( *dynamic_cast( (*i).second ) ); 133 | } 134 | 135 | strDest += "e"; 136 | 137 | return strDest; 138 | } 139 | 140 | string Encode( CAtom *pAtom ) 141 | { 142 | if( dynamic_cast( pAtom ) ) 143 | return EncodeInt( *dynamic_cast( pAtom ) ); 144 | else if( dynamic_cast( pAtom ) ) 145 | return EncodeLong( *dynamic_cast( pAtom ) ); 146 | else if( dynamic_cast( pAtom ) ) 147 | return EncodeString( *dynamic_cast( pAtom ) ); 148 | else if( dynamic_cast( pAtom ) ) 149 | return EncodeList( *dynamic_cast( pAtom ) ); 150 | else if( dynamic_cast( pAtom ) ) 151 | return EncodeDicti( *dynamic_cast( pAtom ) ); 152 | 153 | return string( ); 154 | } 155 | 156 | /* 157 | 158 | CAtomInt *DecodeInt( const string &x, unsigned long iStart ) 159 | { 160 | string :: size_type iEnd = x.find( "e" ); 161 | 162 | if( iEnd == string :: npos ) 163 | { 164 | UTIL_LogPrint( "error decoding int - couldn't find \"e\", halting decode\n" ); 165 | 166 | return 0; 167 | } 168 | 169 | return new CAtomInt( atoi( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ) ) ); 170 | } 171 | 172 | */ 173 | 174 | CAtomLong *DecodeLong( const string &x, unsigned long iStart ) 175 | { 176 | string :: size_type iEnd = x.find( "e", iStart ); 177 | 178 | if( iEnd == string :: npos ) 179 | { 180 | UTIL_LogPrint( "error decoding long - couldn't find \"e\", halting decode\n" ); 181 | 182 | return 0; 183 | } 184 | 185 | int64 i; 186 | 187 | #if defined( WIN32 ) 188 | sscanf( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ), "%I64d", &i ); 189 | #elif defined( __FREEBSD__ ) || defined( __OPENBSD__ ) || defined( __NETBSD__ ) 190 | sscanf( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ), "%qd", &i ); 191 | #else 192 | sscanf( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ), "%lld", &i ); 193 | #endif 194 | 195 | return new CAtomLong( i ); 196 | } 197 | 198 | CAtomString *DecodeString( const string &x, unsigned long iStart ) 199 | { 200 | string :: size_type iSplit = x.find_first_not_of( "1234567890", iStart ); 201 | 202 | if( iSplit == string :: npos ) 203 | { 204 | UTIL_LogPrint( "error decoding string - couldn't find \":\", halting decode\n" ); 205 | 206 | return 0; 207 | } 208 | 209 | return new CAtomString( x.substr( iSplit + 1, atoi( x.substr( iStart, iSplit - iStart ).c_str( ) ) ) ); 210 | } 211 | 212 | CAtomList *DecodeList( const string &x, unsigned long iStart ) 213 | { 214 | unsigned long i = iStart + 1; 215 | 216 | CAtomList *pList = new CAtomList( ); 217 | 218 | while( i < x.size( ) && x[i] != 'e' ) 219 | { 220 | CAtom *pAtom = Decode( x, i ); 221 | 222 | if( pAtom ) 223 | { 224 | i += pAtom->EncodedLength( ); 225 | 226 | pList->addItem( pAtom ); 227 | } 228 | else 229 | { 230 | UTIL_LogPrint( "error decoding list - error decoding list item, discarding list\n" ); 231 | 232 | delete pList; 233 | 234 | return 0; 235 | } 236 | } 237 | 238 | return pList; 239 | } 240 | 241 | CAtomDicti *DecodeDicti( const string &x, unsigned long iStart ) 242 | { 243 | unsigned long i = iStart + 1; 244 | 245 | CAtomDicti *pDicti = new CAtomDicti( ); 246 | 247 | while( i < x.size( ) && x[i] != 'e' ) 248 | { 249 | CAtom *pKey = Decode( x, i ); 250 | 251 | if( pKey && dynamic_cast( pKey ) ) 252 | { 253 | i += pKey->EncodedLength( ); 254 | 255 | string strKey = pKey->toString( ); 256 | 257 | delete pKey; 258 | 259 | if( i < x.size( ) ) 260 | { 261 | CAtom *pValue = Decode( x, i ); 262 | 263 | if( pValue ) 264 | { 265 | i += pValue->EncodedLength( ); 266 | 267 | pDicti->setItem( strKey, pValue ); 268 | } 269 | else 270 | { 271 | UTIL_LogPrint( "error decoding dictionary - error decoding value, discarding dictionary\n" ); 272 | 273 | delete pDicti; 274 | 275 | return 0; 276 | } 277 | } 278 | } 279 | else 280 | { 281 | UTIL_LogPrint( "error decoding dictionary - error decoding key, discarding dictionary\n" ); 282 | 283 | delete pDicti; 284 | 285 | return 0; 286 | } 287 | } 288 | 289 | return pDicti; 290 | } 291 | 292 | CAtom *Decode( const string &x, unsigned long iStart ) 293 | { 294 | if( iStart < x.size( ) ) 295 | { 296 | if( x[iStart] == 'i' ) 297 | return DecodeLong( x, iStart ); 298 | else if( isdigit( x[iStart] ) ) 299 | return DecodeString( x, iStart ); 300 | else if( x[iStart] == 'l' ) 301 | return DecodeList( x, iStart ); 302 | else if( x[iStart] == 'd' ) 303 | return DecodeDicti( x, iStart ); 304 | 305 | string temp = x.substr( iStart ); 306 | 307 | UTIL_LogPrint( "error decoding - found unexpected character %u, halting decode\n", (unsigned char)x[iStart] ); 308 | } 309 | else 310 | UTIL_LogPrint( "error decoding - out of range\n" ); 311 | 312 | return 0; 313 | } 314 | 315 | CAtom *DecodeFile( const char *szFile ) 316 | { 317 | FILE *pFile = FILE_ERROR; 318 | 319 | pFile = fopen( szFile, "rb" ); 320 | 321 | if( pFile == FILE_ERROR ) 322 | { 323 | UTIL_LogPrint( "warning - unable to open %s for reading\n", szFile ); 324 | 325 | return 0; 326 | } 327 | 328 | // Find the end of the file 329 | fseek( pFile, 0, SEEK_END ); 330 | 331 | // Remember the file size for later 332 | const unsigned long culFileSize( ftell( pFile ) ); 333 | 334 | // Reset to the start of the file 335 | fseek( pFile, 0, SEEK_SET ); 336 | 337 | // Allocate memory for the data buffer 338 | char *pData = (char *)malloc( sizeof( char ) * culFileSize ); 339 | 340 | // Read the data 341 | fread( pData, sizeof( char ), culFileSize, pFile ); 342 | 343 | // Close the file 344 | fclose( pFile ); 345 | 346 | // Place the data in a string 347 | const string cstrFile( pData, culFileSize ); 348 | 349 | // Free the data buffer memory 350 | free( pData ); 351 | 352 | // Return the decoded data 353 | return Decode( cstrFile ); 354 | } 355 | -------------------------------------------------------------------------------- /src/bnbt_v4.h: -------------------------------------------------------------------------------- 1 | // // Copyright (C) 2003-2004 Trevor Hogan 2 | // 3 | 4 | #ifndef BNBT_H 5 | #define BNBT_H 6 | 7 | // XBNBT 8 | #define XBNBT_VER string("XBNBT 81b.3.5") 9 | 10 | #if defined ( WIN32 ) 11 | #define FD_SETSIZE 256 12 | 13 | #include 14 | #include 15 | #else 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #endif 24 | 25 | // tphogan - these new includes may have broken BSD support 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | // tphogan - eliminate namespace pollution 36 | 37 | using std :: endl; 38 | using std :: ifstream; 39 | using std :: ofstream; 40 | using std :: map; 41 | using std :: multimap; 42 | using std :: pair; 43 | using std :: string; 44 | using std :: vector; 45 | 46 | #ifdef WIN32 47 | #define WIN32_LEAN_AND_MEAN 48 | #endif 49 | 50 | #ifdef __GNUWIN32__ 51 | #define unlink remove 52 | #endif 53 | 54 | // 55 | // SOLARIS USERS - IF YOUR SYSTEM IS LITTLE ENDIAN, REMOVE THE NEXT 3 LINES 56 | // also see sha1.h 57 | // 58 | 59 | #if defined( __APPLE__ ) || defined( __SOLARIS__ ) 60 | #define BNBT_BIG_ENDIAN 61 | #endif 62 | 63 | // large integers 64 | 65 | #ifdef WIN32 66 | typedef unsigned __int8 uint8; 67 | typedef __int64 int64; 68 | typedef unsigned __int64 uint64; 69 | #else 70 | typedef unsigned char uint8; 71 | typedef long long int64; 72 | typedef unsigned long long uint64; 73 | typedef unsigned long int DWORD; 74 | typedef unsigned short int WORD; 75 | typedef unsigned char BYTE; 76 | #endif 77 | 78 | #ifdef WIN32 79 | #define snprintf _snprintf 80 | #define vsnprintf _vsnprintf 81 | #endif 82 | 83 | // mutex 84 | 85 | class CMutex 86 | { 87 | public: 88 | #ifdef WIN32 89 | void Initialize( ) { InitializeCriticalSection( &cs ); } 90 | void Destroy( ) { DeleteCriticalSection( &cs ); } 91 | void Claim( ) { EnterCriticalSection( &cs ); } 92 | void Release( ) { LeaveCriticalSection( &cs ); } 93 | 94 | CRITICAL_SECTION cs; 95 | #else 96 | void Initialize( ) { pthread_mutex_init( &mtx, 0 ); } 97 | void Destroy( ) { pthread_mutex_destroy( &mtx ); } 98 | void Claim( ) { pthread_mutex_lock( &mtx ); } 99 | void Release( ) { pthread_mutex_unlock( &mtx ); } 100 | 101 | pthread_mutex_t mtx; 102 | #endif 103 | }; 104 | 105 | // stl 106 | 107 | #ifdef WIN32 108 | #pragma warning( disable : 4786 ) 109 | #endif 110 | 111 | // path seperator 112 | 113 | #ifdef WIN32 114 | #define PATH_SEP '\\' 115 | #define STR_PATH_SEP string( 1,PATH_SEP ) 116 | #else 117 | #define PATH_SEP '/' 118 | #define STR_PATH_SEP string( 1,PATH_SEP ) 119 | #endif 120 | 121 | #define CHAR_BS '\\' 122 | #define CHAR_FS '/' 123 | 124 | // Termination character character 125 | 126 | #define TERM_CHAR '\0' 127 | 128 | // this fixes MSVC loop scoping issues 129 | 130 | /* 131 | 132 | #ifdef WIN32 133 | #define for if( 0 ) { } else for 134 | #endif 135 | 136 | */ 137 | 138 | // time stuff 139 | 140 | unsigned long GetTime( ); 141 | 142 | #ifdef WIN32 143 | #define MILLISLEEP( x ) Sleep( x ) 144 | #else 145 | #define MILLISLEEP( x ) usleep( ( x ) * 1000 ) 146 | #endif 147 | 148 | // network 149 | 150 | #ifdef WIN32 151 | #define EADDRINUSE WSAEADDRINUSE 152 | #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 153 | #define EAFNOSUPPORT WSAEAFNOSUPPORT 154 | #define EALREADY WSAEALREADY 155 | #define ECONNABORTED WSAECONNABORTED 156 | #define ECONNREFUSED WSAECONNREFUSED 157 | #define ECONNRESET WSAECONNRESET 158 | #define EDESTADDRREQ WSAEDESTADDRREQ 159 | #define EDQUOT WSAEDQUOT 160 | #define EHOSTDOWN WSAEHOSTDOWN 161 | #define EHOSTUNREACH WSAEHOSTUNREACH 162 | #define EINPROGRESS WSAEINPROGRESS 163 | #define EISCONN WSAEISCONN 164 | #define ELOOP WSAELOOP 165 | #define EMSGSIZE WSAEMSGSIZE 166 | // defined in Windows 167 | //#define ENAMETOOLONG WSAENAMETOOLONG 168 | #define ENETDOWN WSAENETDOWN 169 | #define ENETRESET WSAENETRESET 170 | #define ENETUNREACH WSAENETUNREACH 171 | #define ENOBUFS WSAENOBUFS 172 | #define ENOPROTOOPT WSAENOPROTOOPT 173 | #define ENOTCONN WSAENOTCONN 174 | // defined in Windows 175 | //#define ENOTEMPTY WSAENOTEMPTY 176 | #define ENOTSOCK WSAENOTSOCK 177 | #define EOPNOTSUPP WSAEOPNOTSUPP 178 | #define EPFNOSUPPORT WSAEPFNOSUPPORT 179 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 180 | #define EPROTOTYPE WSAEPROTOTYPE 181 | #define EREMOTE WSAEREMOTE 182 | #define ESHUTDOWN WSAESHUTDOWN 183 | #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 184 | #define ESTALE WSAESTALE 185 | #define ETIMEDOUT WSAETIMEDOUT 186 | #define ETOOMANYREFS WSAETOOMANYREFS 187 | #define EUSERS WSAEUSERS 188 | #define EWOULDBLOCK WSAEWOULDBLOCK 189 | // defined in Windows 190 | //#define EFAULT WSAEFAULT 191 | #define ENETDOWN WSAENETDOWN 192 | // defined in Windows 193 | //#define EINTR WSAEINTR 194 | //#define EBADF WSAEBADF 195 | //#define EACCES WSAEACCES 196 | //#define EINVAL WSAEINVAL 197 | //#define EMFILE WSAEMFILE 198 | #define EPROCLIM WSAEPROCLIM 199 | #define SYSNOTREADY WSASYSNOTREADY 200 | #define VERNOTSUPPORTED WSAVERNOTSUPPORTED 201 | #define NOTINITIALISED WSANOTINITIALISED 202 | #define EDISCON WSAEDISCON 203 | #define ENOMORE WSAENOMORE 204 | #define ECANCELLED WSAECANCELLED 205 | #define EINVALIDPROCTABLE WSAEINVALIDPROCTABLE 206 | #define EINVALIDPROVIDER WSAEINVALIDPROVIDER 207 | #define EPROVIDERFAILEDINIT WSAEPROVIDERFAILEDINIT 208 | #define SYSCALLFAILURE WSASYSCALLFAILURE 209 | #define SERVICE_NOT_FOUND WSASERVICE_NOT_FOUND 210 | #define TYPE_NOT_FOUND WSATYPE_NOT_FOUND 211 | #define _E_NO_MORE WSA_E_NO_MORE 212 | #define _E_CANCELLED WSA_E_CANCELLED 213 | #define EREFUSED WSAEREFUSED 214 | #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 215 | #define TRY_AGAIN WSATRY_AGAIN 216 | #define NO_RECOVERY WSANO_RECOVERY 217 | #define NO_DATA WSANO_DATA 218 | // defined in Windows 219 | //#define NO_ADDRESS WSANO_DATA 220 | #endif 221 | 222 | #ifndef WIN32 223 | #define closesocket close 224 | typedef int SOCKET; 225 | extern int GetLastError( ); 226 | #endif 227 | 228 | extern const char *GetLastErrorString( ); 229 | 230 | #ifdef __APPLE__ 231 | typedef int socklen_t; 232 | typedef int sockopt_len_t; 233 | #endif 234 | 235 | #ifndef INVALID_SOCKET 236 | #define INVALID_SOCKET -1 237 | #endif 238 | 239 | #ifndef SOCKET_ERROR 240 | #define SOCKET_ERROR -1 241 | #endif 242 | 243 | #ifndef INADDR_NONE 244 | #define INADDR_NONE -1 245 | #endif 246 | 247 | #ifndef MSG_NOSIGNAL 248 | #define MSG_NOSIGNAL 0 249 | #endif 250 | 251 | #define FILE_ERROR 0 252 | #define DIR_ERROR -1 253 | 254 | class CAtom; 255 | class CAtomInt; 256 | class CAtomLong; 257 | class CAtomString; 258 | class CAtomList; 259 | class CAtomDicti; 260 | 261 | class CServer; 262 | class CTracker; 263 | class CClient; 264 | 265 | class CLink; 266 | class CLinkServer; 267 | 268 | class CHUBLink; 269 | class CHUBLinkServer; 270 | 271 | struct response_t 272 | { 273 | string strCode; 274 | multimap mapHeaders; 275 | string strContent; 276 | bool bCompressOK; 277 | }; 278 | 279 | // user access levels 280 | 281 | #define ACCESS_VIEW ( 1 << 0 ) // 1 282 | #define ACCESS_DL ( 1 << 1 ) // 2 283 | #define ACCESS_COMMENTS ( 1 << 2 ) // 4 284 | #define ACCESS_UPLOAD ( 1 << 3 ) // 8 285 | #define ACCESS_EDIT ( 1 << 4 ) // 16 286 | #define ACCESS_ADMIN ( 1 << 5 ) // 32 287 | #define ACCESS_SIGNUP ( 1 << 6 ) // 64 288 | 289 | // debug levels 290 | 291 | #define DEBUG_BNBT ( 1 << 0 ) // 1 292 | #define DEBUG_SERVER ( 1 << 1 ) // 2 293 | #define DEBUG_CLIENT ( 1 << 2 ) // 4 294 | #define DEBUG_TRACKER ( 1 << 3 ) // 8 295 | #define DEBUG_ANNOUNCE ( 1 << 4 ) // 16 296 | #define DEBUG_SCRAPE ( 1 << 5 ) // 32 297 | #define DEBUG_LOOPS ( 1 << 6 ) // 64 298 | 299 | struct user_t 300 | { 301 | string strLogin; 302 | string strLowerLogin; 303 | string strMD5; 304 | string strMail; 305 | string strLowerMail; 306 | string strCreated; 307 | unsigned char ucAccess; 308 | }; 309 | 310 | struct request_t 311 | { 312 | struct sockaddr_in sin; 313 | string strMethod; 314 | string strURL; 315 | // Harold - Adding Support for Multiple scrapes in a single /scrape call 316 | bool hasQuery; 317 | multimap multiParams; 318 | map mapParams; 319 | map mapHeaders; 320 | map mapCookies; 321 | struct user_t user; 322 | }; 323 | 324 | #define LINK_VER "TrackerLINK Ver. 0.1" 325 | 326 | #define LINKMSG_ERROR -1 327 | #define LINKMSG_NONE 0 // not transmitted 328 | #define LINKMSG_VERSION 1 329 | #define LINKMSG_INFO 2 330 | #define LINKMSG_PASSWORD 3 331 | #define LINKMSG_READY 4 332 | #define LINKMSG_ANNOUNCE 7 333 | #define LINKMSG_CLOSE 99 334 | 335 | struct linkmsg_t 336 | { 337 | long len; 338 | char type; 339 | string msg; 340 | }; 341 | 342 | // current version 343 | 344 | #define BNBT_VER "Beta 8.1" 345 | 346 | // Trinity edition 347 | /* 348 | #ifdef WIN32 349 | #define BNBT_SERVICE_NAME "BNBT Service" 350 | #endif 351 | */ 352 | 353 | extern CServer *gpServer; 354 | extern CLink *gpLink; 355 | extern CLinkServer *gpLinkServer; 356 | extern CHUBLink *gpHUBLink; 357 | extern CHUBLinkServer *gpHUBLinkServer; 358 | extern string gstrErrorLogDir; 359 | extern string gstrErrorLogFile; 360 | extern string gstrErrorLogFilePattern; 361 | extern FILE *gpErrorLog; 362 | extern string gstrAccessLogDir; 363 | extern string gstrAccessLogFilePattern; 364 | extern string gstrAccessLogFile; 365 | extern FILE *gpAccessLog; 366 | extern unsigned long gulErrorLogCount; 367 | extern unsigned long gulAccessLogCount; 368 | extern unsigned int guiFlushInterval; 369 | extern bool gbDebug; 370 | extern unsigned int guiMaxConns; 371 | extern unsigned int guiMaxRecvSize; 372 | extern string gstrStyle; 373 | extern string gstrCharSet; 374 | extern string gstrRealm; 375 | 376 | // The Trinity Edition - Modification Begins 377 | // Sets the NT Service Name variable as a global variable 378 | extern string gstrNTServiceName; 379 | 380 | // Threads 381 | extern CMutex gmtxOutput; 382 | 383 | // TCP window size 384 | extern unsigned int guiSO_RECBUF; 385 | extern unsigned int guiSO_SNDBUF; 386 | 387 | // Nagle 388 | extern bool gbTCP_NODELAY; 389 | 390 | // PID file 391 | extern string gstrPID; 392 | 393 | // Debug level 394 | extern unsigned char gucDebugLevel; 395 | 396 | // Mime types 397 | extern map gmapMime; 398 | 399 | // XBNBT XStats 400 | extern struct xbnbtstats_t gtXStats; 401 | 402 | // this is basically the old main( ), but it's here to make the NT Service code neater 403 | 404 | extern int bnbtmain( ); 405 | 406 | #endif 407 | -------------------------------------------------------------------------------- /src/util_ntservice.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | /*********************************************************************** 23 | * NT Service code written by ConfusedFish and modified by Trevor Hogan * 24 | ***********************************************************************/ 25 | 26 | // =Xotic= Modified Source File 27 | 28 | #include "bnbt.h" 29 | #include "config.h" 30 | #include "server.h" 31 | #include "util_ntservice.h" 32 | #include "util.h" 33 | 34 | bool UTIL_NTServiceTest( ) 35 | { 36 | // The Trinity Edition - Addition Begins 37 | // Custom NT Service Name Source Code Courtesy of CBTT 38 | CFG_Open( CFG_FILE ); 39 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 40 | CFG_Close( CFG_FILE ); 41 | 42 | // test if the service is installed or not 43 | 44 | bool bResult = false; 45 | 46 | // open the Service Control Manager 47 | 48 | SC_HANDLE hSCM = OpenSCManager( 0, 0, SC_MANAGER_ALL_ACCESS ); 49 | 50 | if( hSCM ) 51 | { 52 | // try to open the service 53 | 54 | SC_HANDLE hService = OpenService( hSCM, BNBT_SERVICE_NAME, SERVICE_QUERY_CONFIG ); 55 | 56 | if( hService ) 57 | { 58 | bResult = TRUE; 59 | 60 | CloseServiceHandle( hService ); 61 | } 62 | 63 | CloseServiceHandle( hSCM ); 64 | } 65 | 66 | return bResult; 67 | } 68 | 69 | bool UTIL_NTServiceInstall( ) 70 | { 71 | // Added by =Xotic= // The Trinity Edition - Addition Begins 72 | // Custom NT Service Name Source Code Courtesy of CBTT 73 | CFG_Open( CFG_FILE ); 74 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 75 | CFG_Close( CFG_FILE ); 76 | 77 | // open the Service Control Manager 78 | 79 | SC_HANDLE hSCM = OpenSCManager( 0, 0, SC_MANAGER_ALL_ACCESS ); 80 | 81 | if( !hSCM ) 82 | return false; 83 | 84 | // get the executable file path 85 | 86 | char szFilePath[_MAX_PATH]; 87 | memset( szFilePath, 0, sizeof( szFilePath ) / sizeof( char ) ); 88 | 89 | GetModuleFileName( 0, szFilePath, sizeof( szFilePath ) / sizeof( char ) ); 90 | 91 | // add the run as service parameter 92 | 93 | strncat( szFilePath, " -s", strlen( " -s" ) ); 94 | 95 | // create the service 96 | 97 | SC_HANDLE hService = CreateService( hSCM, 98 | BNBT_SERVICE_NAME, 99 | BNBT_SERVICE_NAME, 100 | SERVICE_ALL_ACCESS, 101 | SERVICE_WIN32_OWN_PROCESS, 102 | SERVICE_AUTO_START, 103 | SERVICE_ERROR_NORMAL, 104 | szFilePath, 105 | 0, 106 | 0, 107 | 0, 108 | 0, 109 | 0 ); 110 | 111 | if( !hService ) 112 | { 113 | CloseServiceHandle( hSCM ); 114 | 115 | return false; 116 | } 117 | 118 | // make registry entries to support logging messages to the EventLog 119 | 120 | char szKey[256]; 121 | memset( szKey, 0, sizeof( szKey ) / sizeof( char ) ); 122 | 123 | HKEY hKey = 0; 124 | 125 | strncpy( szKey, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\", sizeof( szKey ) / sizeof( char ) ); 126 | 127 | strncat( szKey, BNBT_SERVICE_NAME, strlen( BNBT_SERVICE_NAME ) ); 128 | 129 | if( RegCreateKey( HKEY_LOCAL_MACHINE, szKey, &hKey ) != ERROR_SUCCESS ) 130 | { 131 | CloseServiceHandle( hService ); 132 | CloseServiceHandle( hSCM ); 133 | 134 | return false; 135 | } 136 | 137 | RegSetValueEx( hKey, "EventMessageFile", 0, REG_EXPAND_SZ, (CONST BYTE *)szFilePath, (DWORD)strlen( szFilePath ) + 1 ); 138 | 139 | // set the supported types flags 140 | 141 | DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; 142 | 143 | RegSetValueEx( hKey, "TypesSupported", 0, REG_DWORD, (CONST BYTE *)&dwData, sizeof( DWORD ) ); 144 | 145 | RegCloseKey( hKey ); 146 | 147 | UTIL_NTLogEvent( EVENTLOG_INFORMATION_TYPE, EVMSG_INSTALLED, BNBT_SERVICE_NAME ); 148 | 149 | // tidy up 150 | 151 | CloseServiceHandle( hService ); 152 | CloseServiceHandle( hSCM ); 153 | 154 | return TRUE; 155 | } 156 | 157 | bool UTIL_NTServiceUninstall( ) 158 | { 159 | // Added by =Xotic= // The Trinity Edition - Addition Begins 160 | // Custom NT Service Name Source Code Courtesy of CBTT 161 | CFG_Open( CFG_FILE ); 162 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 163 | CFG_Close( CFG_FILE ); 164 | 165 | // open the Service Control Manager 166 | 167 | SC_HANDLE hSCM = OpenSCManager( 0, 0, SC_MANAGER_ALL_ACCESS ); 168 | 169 | if( !hSCM ) 170 | return false; 171 | 172 | bool bResult = false; 173 | 174 | SC_HANDLE hService = OpenService( hSCM, BNBT_SERVICE_NAME, DELETE ); 175 | 176 | if( hService ) 177 | { 178 | if( DeleteService( hService ) ) 179 | { 180 | UTIL_NTLogEvent( EVENTLOG_INFORMATION_TYPE, EVMSG_REMOVED, BNBT_SERVICE_NAME ); 181 | 182 | bResult = TRUE; 183 | } 184 | else 185 | UTIL_NTLogEvent( EVENTLOG_ERROR_TYPE, EVMSG_NOTREMOVED, BNBT_SERVICE_NAME ); 186 | 187 | CloseServiceHandle( hService ); 188 | } 189 | 190 | CloseServiceHandle( hSCM ); 191 | 192 | return bResult; 193 | } 194 | 195 | bool UTIL_NTServiceStart( ) 196 | { 197 | // Added by =Xotic= // The Trinity Edition - Addition Begins 198 | // Custom NT Service Name Source Code Courtesy of CBTT 199 | CFG_Open( CFG_FILE ); 200 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 201 | CFG_Close( CFG_FILE ); 202 | 203 | bool bResult = false; 204 | 205 | // open the Service Control Manager 206 | 207 | SC_HANDLE hSCM = OpenSCManager( 0, 0, SC_MANAGER_ALL_ACCESS ); 208 | 209 | if( hSCM ) 210 | { 211 | // try to open the service 212 | 213 | SC_HANDLE hService = OpenService( hSCM, BNBT_SERVICE_NAME, SERVICE_START ); 214 | 215 | if( hService ) 216 | { 217 | StartService( hService, 0, 0 ); 218 | 219 | bResult = TRUE; 220 | 221 | CloseServiceHandle( hService ); 222 | } 223 | 224 | // tidy up 225 | 226 | CloseServiceHandle( hSCM ); 227 | } 228 | 229 | return bResult; 230 | } 231 | 232 | bool UTIL_NTServiceStop( ) 233 | { 234 | // Added by =Xotic= // The Trinity Edition - Addition Begins 235 | // Custom NT Service Name Source Code Courtesy of CBTT 236 | CFG_Open( CFG_FILE ); 237 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 238 | CFG_Close( CFG_FILE ); 239 | 240 | bool bResult = false; 241 | 242 | // open the Service Control Manager 243 | 244 | SC_HANDLE hSCM = OpenSCManager( 0, 0, SC_MANAGER_ALL_ACCESS ); 245 | 246 | if( hSCM ) 247 | { 248 | // try to open the service 249 | 250 | SC_HANDLE hService = OpenService( hSCM, BNBT_SERVICE_NAME, SERVICE_STOP ); 251 | 252 | if( hService ) 253 | { 254 | SERVICE_STATUS ssStatus; 255 | 256 | if( ControlService( hService, SERVICE_CONTROL_STOP, &ssStatus ) ) 257 | bResult = TRUE; 258 | 259 | CloseServiceHandle( hService ); 260 | } 261 | 262 | CloseServiceHandle( hSCM ); 263 | } 264 | 265 | return bResult; 266 | } 267 | 268 | void UTIL_NTLogEvent( WORD wType, DWORD dwID, const char *pszS1, const char *pszS2, const char *pszS3 ) 269 | { 270 | // Added by =Xotic= // The Trinity Edition - Addition Begins 271 | // Custom NT Service Name Source Code Courtesy of CBTT 272 | CFG_Open( CFG_FILE ); 273 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 274 | CFG_Close( CFG_FILE ); 275 | 276 | // make an entry into the application event log 277 | 278 | const char *ps[3]; 279 | ps[0] = pszS1; 280 | ps[1] = pszS2; 281 | ps[2] = pszS3; 282 | 283 | unsigned char ucStr = 0; 284 | 285 | for( unsigned char ucCount = 0; ucCount < 3; ucCount++ ) 286 | { 287 | if( ps[ucCount] != 0 ) 288 | ucStr++; 289 | } 290 | 291 | // check if the event source has been registered, and if not then register it now 292 | 293 | HANDLE hNTEventSource = RegisterEventSource( 0, BNBT_SERVICE_NAME ); 294 | 295 | if( hNTEventSource ) 296 | { 297 | ReportEvent( hNTEventSource, wType, 0, dwID, 0, ucStr, 0, ps, 0 ); 298 | 299 | DeregisterEventSource( hNTEventSource ); 300 | } 301 | } 302 | 303 | void WINAPI NTServiceHandler( DWORD dwOpcode ) 304 | { 305 | // Added by =Xotic= // The Trinity Edition - Addition Begins 306 | // Custom NT Service Name Source Code Courtesy of CBTT 307 | CFG_Open( CFG_FILE ); 308 | #define BNBT_SERVICE_NAME const_cast (CFG_GetString( "cbtt_service_name", "BNBT Service" ).c_str()) 309 | CFG_Close( CFG_FILE ); 310 | 311 | // handle commands from the Service Control Manager 312 | 313 | if( dwOpcode == SERVICE_CONTROL_STOP ) 314 | { 315 | gssStatus.dwCurrentState = SERVICE_STOP_PENDING; 316 | 317 | SetServiceStatus( ghServiceStatus, &gssStatus ); 318 | 319 | gpServer->Kill( ); 320 | } 321 | 322 | SetServiceStatus( ghServiceStatus, &gssStatus ); 323 | } 324 | 325 | void WINAPI NTServiceMain( DWORD dwArgc, LPTSTR *lpszArgv ) 326 | { 327 | gssStatus.dwCheckPoint = 0; 328 | gssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; 329 | gssStatus.dwCurrentState = SERVICE_START_PENDING; 330 | gssStatus.dwServiceSpecificExitCode = 0; 331 | gssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; 332 | gssStatus.dwWaitHint = 0; 333 | gssStatus.dwWin32ExitCode = 0; 334 | 335 | // register the control request handler 336 | 337 | ghServiceStatus = RegisterServiceCtrlHandler( BNBT_SERVICE_NAME, NTServiceHandler ); 338 | 339 | if( !( ghServiceStatus ) ) 340 | return; 341 | 342 | SetServiceStatus( ghServiceStatus, &gssStatus ); 343 | 344 | gssStatus.dwWin32ExitCode = 0; 345 | gssStatus.dwCheckPoint = 0; 346 | gssStatus.dwWaitHint = 0; 347 | 348 | UTIL_NTLogEvent( EVENTLOG_INFORMATION_TYPE, EVMSG_STARTED ); 349 | 350 | // tell the Service Control Manager we started 351 | 352 | gssStatus.dwCurrentState = SERVICE_RUNNING; 353 | 354 | SetServiceStatus( ghServiceStatus, &gssStatus ); 355 | 356 | gssStatus.dwWin32ExitCode = 0; 357 | gssStatus.dwCheckPoint = 0; 358 | gssStatus.dwWaitHint = 0; 359 | 360 | // run the tracker 361 | 362 | bnbtmain( ); 363 | 364 | // tell the Service Control Manager we stopped 365 | 366 | UTIL_NTLogEvent( EVENTLOG_INFORMATION_TYPE, EVMSG_STOPPED ); 367 | 368 | gssStatus.dwCurrentState = SERVICE_STOPPED; 369 | 370 | SetServiceStatus( ghServiceStatus, &gssStatus ); 371 | } 372 | 373 | SERVICE_STATUS_HANDLE ghServiceStatus; 374 | SERVICE_STATUS gssStatus; 375 | -------------------------------------------------------------------------------- /src/atom.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.5 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2005 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | // =Xotic= Modified Source File 23 | 24 | #include "bnbt.h" 25 | #include "atom.h" 26 | #include "config.h" 27 | #include "util.h" 28 | 29 | // 30 | // CAtomInt 31 | // 32 | 33 | CAtomInt :: CAtomInt( ) 34 | { 35 | setValue( 0 ); 36 | } 37 | 38 | CAtomInt :: CAtomInt( const int &iInt ) 39 | { 40 | setValue( iInt ); 41 | } 42 | 43 | CAtomInt :: CAtomInt( const CAtomInt &c ) 44 | { 45 | // copy constructor 46 | 47 | setValue( c.getValue( ) ); 48 | } 49 | 50 | CAtomInt :: ~CAtomInt( ) 51 | { 52 | 53 | } 54 | 55 | int CAtomInt :: EncodedLength( ) 56 | { 57 | return (int)toString( ).size( ) + 2; 58 | } 59 | 60 | int CAtomInt :: Length( ) 61 | { 62 | return (int)toString( ).size( ); 63 | } 64 | 65 | string CAtomInt :: toString( ) 66 | { 67 | char pBuf[32]; 68 | memset( pBuf, 0, sizeof( pBuf ) / sizeof( char ) ); 69 | 70 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%d", getValue( ) ); 71 | 72 | return pBuf; 73 | } 74 | 75 | int CAtomInt :: getValue( ) const 76 | { 77 | return m_iInt; 78 | } 79 | 80 | void CAtomInt :: setValue( const int &iInt ) 81 | { 82 | m_iInt = iInt; 83 | } 84 | 85 | // 86 | // CAtomLong 87 | // 88 | 89 | CAtomLong :: CAtomLong( ) 90 | { 91 | setValue( 0 ); 92 | } 93 | 94 | CAtomLong :: CAtomLong( const int64 &iLong ) 95 | { 96 | setValue( iLong ); 97 | } 98 | 99 | CAtomLong :: CAtomLong( const CAtomLong &c ) 100 | { 101 | // copy constructor 102 | 103 | setValue( c.getValue( ) ); 104 | } 105 | 106 | CAtomLong :: ~CAtomLong( ) 107 | { 108 | 109 | } 110 | 111 | int CAtomLong :: EncodedLength( ) 112 | { 113 | return (int)toString( ).size( ) + 2; 114 | } 115 | 116 | int CAtomLong :: Length( ) 117 | { 118 | return (int)toString( ).size( ); 119 | } 120 | 121 | string CAtomLong :: toString( ) 122 | { 123 | char pBuf[32]; 124 | memset( pBuf, 0, sizeof( pBuf ) / sizeof( char ) ); 125 | 126 | #if defined( WIN32 ) 127 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%I64d", getValue( ) ); 128 | #elif defined( __FREEBSD__ ) || defined( __OPENBSD__ ) || defined( __NETBSD__ ) 129 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%qd", getValue( ) ); 130 | #else 131 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%lld", getValue( ) ); 132 | #endif 133 | 134 | return pBuf; 135 | } 136 | 137 | int64 CAtomLong :: getValue( ) const 138 | { 139 | return m_iLong; 140 | } 141 | 142 | void CAtomLong :: setValue( const int64 &iLong ) 143 | { 144 | m_iLong = iLong; 145 | } 146 | 147 | // 148 | // CAtomString 149 | // 150 | 151 | CAtomString :: CAtomString( ) 152 | { 153 | 154 | } 155 | 156 | CAtomString :: CAtomString( const string &strString ) 157 | { 158 | setValue( strString ); 159 | } 160 | 161 | CAtomString :: CAtomString( const CAtomString &c ) 162 | { 163 | // copy constructor 164 | 165 | setValue( c.getValue( ) ); 166 | } 167 | 168 | CAtomString :: ~CAtomString( ) 169 | { 170 | 171 | } 172 | 173 | int CAtomString :: EncodedLength( ) 174 | { 175 | const unsigned int cuiSize( (unsigned int)getValue( ).size( ) ); 176 | 177 | char pBuf[32]; 178 | memset( pBuf, 0, sizeof( pBuf ) / sizeof( char ) ); 179 | 180 | snprintf( pBuf, sizeof( pBuf ) / sizeof( char ), "%u", cuiSize ); 181 | 182 | return cuiSize + strlen( pBuf ) + 1; 183 | } 184 | 185 | int CAtomString :: Length( ) 186 | { 187 | return (int)getValue( ).size( ); 188 | } 189 | 190 | string CAtomString :: toString( ) 191 | { 192 | return getValue( ); 193 | } 194 | 195 | string CAtomString :: getValue( ) const 196 | { 197 | return m_strString; 198 | } 199 | 200 | void CAtomString :: setValue( const string &strString ) 201 | { 202 | m_strString = strString; 203 | } 204 | 205 | // 206 | // CAtomList 207 | // 208 | 209 | CAtomList :: CAtomList( ) 210 | { 211 | 212 | } 213 | 214 | CAtomList :: CAtomList( const vector &vecList ) 215 | { 216 | setValue( vecList ); 217 | } 218 | 219 | CAtomList :: CAtomList( const CAtomList &c ) 220 | { 221 | // copy constructor 222 | 223 | vector *pvecList = c.getValuePtr( ); 224 | 225 | for( vector :: iterator itAtom = pvecList->begin( ); itAtom != pvecList->end( ); itAtom++ ) 226 | { 227 | if( dynamic_cast( *itAtom ) ) 228 | addItem( new CAtomInt( *dynamic_cast( *itAtom ) ) ); 229 | else if( dynamic_cast( *itAtom ) ) 230 | addItem( new CAtomLong( *dynamic_cast( *itAtom ) ) ); 231 | else if( dynamic_cast( *itAtom ) ) 232 | addItem( new CAtomString( *dynamic_cast( *itAtom ) ) ); 233 | else if( dynamic_cast( *itAtom ) ) 234 | addItem( new CAtomList( *dynamic_cast( *itAtom ) ) ); 235 | else if( dynamic_cast( *itAtom ) ) 236 | addItem( new CAtomDicti( *dynamic_cast( *itAtom ) ) ); 237 | else 238 | UTIL_LogPrint( ( gmapLANG_CFG["atomlist_copy_warning"] + "\n" ).c_str( ) ); 239 | } 240 | } 241 | 242 | CAtomList :: ~CAtomList( ) 243 | { 244 | clear( ); 245 | } 246 | 247 | int CAtomList :: EncodedLength( ) 248 | { 249 | int iLen = 0; 250 | 251 | for( vector :: iterator itAtom = m_vecList.begin( ); itAtom != m_vecList.end( ); itAtom++ ) 252 | iLen += (*itAtom)->EncodedLength( ); 253 | 254 | return iLen + 2; 255 | } 256 | 257 | int CAtomList :: Length( ) 258 | { 259 | // nobody cares about you 260 | 261 | return 0; 262 | } 263 | 264 | string CAtomList :: toString( ) 265 | { 266 | return string( ); 267 | } 268 | 269 | bool CAtomList :: isEmpty( ) 270 | { 271 | return m_vecList.empty( ); 272 | } 273 | 274 | void CAtomList :: clear( ) 275 | { 276 | for( vector :: iterator itAtom = m_vecList.begin( ); itAtom != m_vecList.end( ); itAtom++ ) 277 | delete *itAtom; 278 | 279 | m_vecList.clear( ); 280 | } 281 | 282 | void CAtomList :: Randomize( ) 283 | { 284 | random_shuffle( m_vecList.begin( ), m_vecList.end( ) ); 285 | } 286 | 287 | vector CAtomList :: getValue( ) const 288 | { 289 | return m_vecList; 290 | } 291 | 292 | vector *CAtomList :: getValuePtr( ) const 293 | { 294 | return (vector *)&m_vecList; 295 | } 296 | 297 | void CAtomList :: setValue( const vector &vecList ) 298 | { 299 | m_vecList = vecList; 300 | } 301 | 302 | void CAtomList :: delItem( CAtom *atmItem ) 303 | { 304 | for( vector :: iterator itAtom = m_vecList.begin( ); itAtom != m_vecList.end( ); itAtom++ ) 305 | { 306 | if( *itAtom == atmItem ) 307 | { 308 | delete *itAtom; 309 | 310 | m_vecList.erase( itAtom ); 311 | 312 | return; 313 | } 314 | } 315 | } 316 | 317 | void CAtomList :: addItem( CAtom *atmItem ) 318 | { 319 | m_vecList.push_back( atmItem ); 320 | } 321 | 322 | // 323 | // CAtomDicti 324 | // 325 | 326 | CAtomDicti :: CAtomDicti( ) 327 | { 328 | 329 | } 330 | 331 | CAtomDicti :: CAtomDicti( const CAtomDicti &c ) 332 | { 333 | // copy constructor 334 | 335 | map *pmapDicti = c.getValuePtr( ); 336 | 337 | for( map :: iterator itAtom = pmapDicti->begin( ); itAtom != pmapDicti->end( ); itAtom++ ) 338 | { 339 | if( dynamic_cast( (*itAtom).second ) ) 340 | setItem( (*itAtom).first, new CAtomInt( *dynamic_cast( (*itAtom).second ) ) ); 341 | else if( dynamic_cast( (*itAtom).second ) ) 342 | setItem( (*itAtom).first, new CAtomLong( *dynamic_cast( (*itAtom).second ) ) ); 343 | else if( dynamic_cast( (*itAtom).second ) ) 344 | setItem( (*itAtom).first, new CAtomString( *dynamic_cast( (*itAtom).second ) ) ); 345 | else if( dynamic_cast( (*itAtom).second ) ) 346 | setItem( (*itAtom).first, new CAtomList( *dynamic_cast( (*itAtom).second ) ) ); 347 | else if( dynamic_cast( (*itAtom).second ) ) 348 | setItem( (*itAtom).first, new CAtomDicti( *dynamic_cast( (*itAtom).second ) ) ); 349 | else 350 | UTIL_LogPrint( ( gmapLANG_CFG["atomdicti_copy_warning"] + "\n" ).c_str( ) ); 351 | } 352 | } 353 | 354 | CAtomDicti :: ~CAtomDicti( ) 355 | { 356 | clear( ); 357 | } 358 | 359 | int CAtomDicti :: EncodedLength( ) 360 | { 361 | int iLen = 0; 362 | 363 | for( map :: iterator itAtom = m_mapDicti.begin( ); itAtom != m_mapDicti.end( ); itAtom++ ) 364 | iLen += CAtomString( (*itAtom).first ).EncodedLength( ) + (*itAtom).second->EncodedLength( ); 365 | 366 | return iLen + 2; 367 | } 368 | 369 | int CAtomDicti :: Length( ) 370 | { 371 | // nobody cares about you 372 | 373 | return 0; 374 | } 375 | 376 | string CAtomDicti :: toString( ) 377 | { 378 | return string( ); 379 | } 380 | 381 | bool CAtomDicti :: isEmpty( ) 382 | { 383 | return m_mapDicti.empty( ); 384 | } 385 | 386 | void CAtomDicti :: clear( ) 387 | { 388 | for( map :: iterator itAtom = m_mapDicti.begin( ); itAtom != m_mapDicti.end( ); itAtom++ ) 389 | delete (*itAtom).second; 390 | 391 | m_mapDicti.clear( ); 392 | } 393 | 394 | map *CAtomDicti :: getValuePtr( ) const 395 | { 396 | return (map *)&m_mapDicti; 397 | } 398 | 399 | void CAtomDicti :: delItem( const string &strKey ) 400 | { 401 | const map :: iterator itAtom( m_mapDicti.find( strKey ) ); 402 | 403 | if( itAtom != m_mapDicti.end( ) ) 404 | { 405 | delete (*itAtom).second; 406 | 407 | m_mapDicti.erase( itAtom ); 408 | } 409 | } 410 | 411 | void CAtomDicti :: eraseItem( const string &strKey ) 412 | { 413 | const map :: iterator itAtom( m_mapDicti.find( strKey ) ); 414 | 415 | if( itAtom != m_mapDicti.end( ) ) 416 | { 417 | 418 | m_mapDicti.erase( itAtom ); 419 | } 420 | } 421 | 422 | CAtom *CAtomDicti :: getItem( const string &strKey ) 423 | { 424 | const map :: iterator itAtom( m_mapDicti.find( strKey ) ); 425 | 426 | if( itAtom == m_mapDicti.end( ) ) 427 | return 0; 428 | else 429 | return (*itAtom).second; 430 | } 431 | 432 | CAtom *CAtomDicti :: getItem( const string &strKey, CAtom *pReturn ) 433 | { 434 | const map :: iterator itAtom( m_mapDicti.find( strKey ) ); 435 | 436 | if( itAtom == m_mapDicti.end( ) ) 437 | return pReturn; 438 | else 439 | return (*itAtom).second; 440 | } 441 | 442 | void CAtomDicti :: setItem( const string &strKey, CAtom *pValue ) 443 | { 444 | const map :: iterator itAtom( m_mapDicti.find( strKey ) ); 445 | 446 | if( itAtom == m_mapDicti.end( ) ) 447 | m_mapDicti.insert( pair( strKey, pValue ) ); 448 | else 449 | { 450 | delete (*itAtom).second; 451 | 452 | (*itAtom).second = pValue; 453 | } 454 | } 455 | -------------------------------------------------------------------------------- /src/bnbt (copy).h: -------------------------------------------------------------------------------- 1 | // // Copyright (C) 2003-2004 Trevor Hogan 2 | // 3 | 4 | #ifndef BNBT_H 5 | #define BNBT_H 6 | 7 | // XBNBT 8 | #define XBNBT_VER string("XBNBT 81b.3.5 ZiJing Mod") 9 | 10 | #if defined ( WIN32 ) 11 | #define FD_SETSIZE 256 12 | 13 | #include 14 | #include 15 | #else 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #endif 28 | 29 | // tphogan - these new includes may have broken BSD support 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | // tphogan - eliminate namespace pollution 40 | 41 | using std :: endl; 42 | using std :: ifstream; 43 | using std :: ofstream; 44 | using std :: map; 45 | using std :: multimap; 46 | using std :: pair; 47 | using std :: string; 48 | using std :: vector; 49 | 50 | #ifdef WIN32 51 | #define WIN32_LEAN_AND_MEAN 52 | #endif 53 | 54 | #ifdef __GNUWIN32__ 55 | #define unlink remove 56 | #endif 57 | 58 | // 59 | // SOLARIS USERS - IF YOUR SYSTEM IS LITTLE ENDIAN, REMOVE THE NEXT 3 LINES 60 | // also see sha1.h 61 | // 62 | 63 | #if defined( __APPLE__ ) || defined( __SOLARIS__ ) 64 | #define BNBT_BIG_ENDIAN 65 | #endif 66 | 67 | // large integers 68 | 69 | #ifdef WIN32 70 | typedef unsigned __int8 uint8; 71 | typedef __int64 int64; 72 | typedef unsigned __int64 uint64; 73 | #else 74 | typedef unsigned char uint8; 75 | typedef long long int64; 76 | typedef unsigned long long uint64; 77 | typedef unsigned long int DWORD; 78 | typedef unsigned short int WORD; 79 | typedef unsigned char BYTE; 80 | #endif 81 | 82 | #ifdef WIN32 83 | #define snprintf _snprintf 84 | #define vsnprintf _vsnprintf 85 | #endif 86 | 87 | // mutex 88 | 89 | class CMutex 90 | { 91 | public: 92 | #ifdef WIN32 93 | void Initialize( ) { InitializeCriticalSection( &cs ); } 94 | void Destroy( ) { DeleteCriticalSection( &cs ); } 95 | void Claim( ) { EnterCriticalSection( &cs ); } 96 | void Release( ) { LeaveCriticalSection( &cs ); } 97 | 98 | CRITICAL_SECTION cs; 99 | #else 100 | void Initialize( ) { pthread_mutex_init( &mtx, 0 ); } 101 | void Destroy( ) { pthread_mutex_destroy( &mtx ); } 102 | void Claim( ) { pthread_mutex_lock( &mtx ); } 103 | void Release( ) { pthread_mutex_unlock( &mtx ); } 104 | 105 | pthread_mutex_t mtx; 106 | #endif 107 | }; 108 | 109 | // stl 110 | 111 | #ifdef WIN32 112 | #pragma warning( disable : 4786 ) 113 | #endif 114 | 115 | // path seperator 116 | 117 | #ifdef WIN32 118 | #define PATH_SEP '\\' 119 | #define STR_PATH_SEP string( 1,PATH_SEP ) 120 | #else 121 | #define PATH_SEP '/' 122 | #define STR_PATH_SEP string( 1,PATH_SEP ) 123 | #endif 124 | 125 | #define CHAR_BS '\\' 126 | #define CHAR_FS '/' 127 | 128 | // Termination character character 129 | 130 | #define TERM_CHAR '\0' 131 | 132 | // this fixes MSVC loop scoping issues 133 | 134 | /* 135 | 136 | #ifdef WIN32 137 | #define for if( 0 ) { } else for 138 | #endif 139 | 140 | */ 141 | 142 | // time stuff 143 | 144 | unsigned long GetTime( ); 145 | unsigned long GetStartTime( ); 146 | 147 | #ifdef WIN32 148 | #define MILLISLEEP( x ) Sleep( x ) 149 | #else 150 | #define MILLISLEEP( x ) usleep( ( x ) * 1000 ) 151 | #endif 152 | 153 | // network 154 | 155 | #ifdef WIN32 156 | #define EADDRINUSE WSAEADDRINUSE 157 | #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 158 | #define EAFNOSUPPORT WSAEAFNOSUPPORT 159 | #define EALREADY WSAEALREADY 160 | #define ECONNABORTED WSAECONNABORTED 161 | #define ECONNREFUSED WSAECONNREFUSED 162 | #define ECONNRESET WSAECONNRESET 163 | #define EDESTADDRREQ WSAEDESTADDRREQ 164 | #define EDQUOT WSAEDQUOT 165 | #define EHOSTDOWN WSAEHOSTDOWN 166 | #define EHOSTUNREACH WSAEHOSTUNREACH 167 | #define EINPROGRESS WSAEINPROGRESS 168 | #define EISCONN WSAEISCONN 169 | #define ELOOP WSAELOOP 170 | #define EMSGSIZE WSAEMSGSIZE 171 | // defined in Windows 172 | //#define ENAMETOOLONG WSAENAMETOOLONG 173 | #define ENETDOWN WSAENETDOWN 174 | #define ENETRESET WSAENETRESET 175 | #define ENETUNREACH WSAENETUNREACH 176 | #define ENOBUFS WSAENOBUFS 177 | #define ENOPROTOOPT WSAENOPROTOOPT 178 | #define ENOTCONN WSAENOTCONN 179 | // defined in Windows 180 | //#define ENOTEMPTY WSAENOTEMPTY 181 | #define ENOTSOCK WSAENOTSOCK 182 | #define EOPNOTSUPP WSAEOPNOTSUPP 183 | #define EPFNOSUPPORT WSAEPFNOSUPPORT 184 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 185 | #define EPROTOTYPE WSAEPROTOTYPE 186 | #define EREMOTE WSAEREMOTE 187 | #define ESHUTDOWN WSAESHUTDOWN 188 | #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 189 | #define ESTALE WSAESTALE 190 | #define ETIMEDOUT WSAETIMEDOUT 191 | #define ETOOMANYREFS WSAETOOMANYREFS 192 | #define EUSERS WSAEUSERS 193 | #define EWOULDBLOCK WSAEWOULDBLOCK 194 | // defined in Windows 195 | //#define EFAULT WSAEFAULT 196 | #define ENETDOWN WSAENETDOWN 197 | // defined in Windows 198 | //#define EINTR WSAEINTR 199 | //#define EBADF WSAEBADF 200 | //#define EACCES WSAEACCES 201 | //#define EINVAL WSAEINVAL 202 | //#define EMFILE WSAEMFILE 203 | #define EPROCLIM WSAEPROCLIM 204 | #define SYSNOTREADY WSASYSNOTREADY 205 | #define VERNOTSUPPORTED WSAVERNOTSUPPORTED 206 | #define NOTINITIALISED WSANOTINITIALISED 207 | #define EDISCON WSAEDISCON 208 | #define ENOMORE WSAENOMORE 209 | #define ECANCELLED WSAECANCELLED 210 | #define EINVALIDPROCTABLE WSAEINVALIDPROCTABLE 211 | #define EINVALIDPROVIDER WSAEINVALIDPROVIDER 212 | #define EPROVIDERFAILEDINIT WSAEPROVIDERFAILEDINIT 213 | #define SYSCALLFAILURE WSASYSCALLFAILURE 214 | #define SERVICE_NOT_FOUND WSASERVICE_NOT_FOUND 215 | #define TYPE_NOT_FOUND WSATYPE_NOT_FOUND 216 | #define _E_NO_MORE WSA_E_NO_MORE 217 | #define _E_CANCELLED WSA_E_CANCELLED 218 | #define EREFUSED WSAEREFUSED 219 | #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 220 | #define TRY_AGAIN WSATRY_AGAIN 221 | #define NO_RECOVERY WSANO_RECOVERY 222 | #define NO_DATA WSANO_DATA 223 | // defined in Windows 224 | //#define NO_ADDRESS WSANO_DATA 225 | #endif 226 | 227 | #ifndef WIN32 228 | #define closesocket close 229 | typedef int SOCKET; 230 | extern int GetLastError( ); 231 | #endif 232 | 233 | extern const char *GetLastErrorString( ); 234 | 235 | #ifdef __APPLE__ 236 | typedef int socklen_t; 237 | typedef int sockopt_len_t; 238 | #endif 239 | 240 | #ifndef INVALID_SOCKET 241 | #define INVALID_SOCKET -1 242 | #endif 243 | 244 | #ifndef SOCKET_ERROR 245 | #define SOCKET_ERROR -1 246 | #endif 247 | 248 | #ifndef INADDR_NONE 249 | #define INADDR_NONE -1 250 | #endif 251 | 252 | #ifndef MSG_NOSIGNAL 253 | #define MSG_NOSIGNAL 0 254 | #endif 255 | 256 | #define FILE_ERROR 0 257 | #define DIR_ERROR -1 258 | 259 | class CAtom; 260 | class CAtomInt; 261 | class CAtomLong; 262 | class CAtomString; 263 | class CAtomList; 264 | class CAtomDicti; 265 | 266 | class CServer; 267 | class CTracker; 268 | class CClient; 269 | 270 | class CLink; 271 | class CLinkServer; 272 | 273 | class CHUBLink; 274 | class CHUBLinkServer; 275 | 276 | struct response_t 277 | { 278 | string strCode; 279 | multimap mapHeaders; 280 | string strContent; 281 | bool bCompressOK; 282 | }; 283 | 284 | // user access levels 285 | 286 | #define ACCESS_VIEW ( 1 << 0 ) // 1 287 | #define ACCESS_DL ( 1 << 1 ) // 2 288 | #define ACCESS_COMMENTS ( 1 << 2 ) // 4 289 | #define ACCESS_UPLOAD ( 1 << 3 ) // 8 290 | #define ACCESS_EDIT ( 1 << 4 ) // 16 291 | #define ACCESS_ADMIN ( 1 << 5 ) // 32 292 | #define ACCESS_LEADER ( 1 << 6 ) // 64 293 | 294 | // user group 295 | 296 | #define GROUP_FRIENDS ( 1 << 0 ) // 1 297 | #define GROUP_RETIRED ( 1 << 1 ) // 2 298 | #define GROUP_VIP ( 1 << 2 ) // 4 299 | 300 | // debug levels 301 | 302 | #define DEBUG_BNBT ( 1 << 0 ) // 1 303 | #define DEBUG_SERVER ( 1 << 1 ) // 2 304 | #define DEBUG_CLIENT ( 1 << 2 ) // 4 305 | #define DEBUG_TRACKER ( 1 << 3 ) // 8 306 | #define DEBUG_ANNOUNCE ( 1 << 4 ) // 16 307 | #define DEBUG_SCRAPE ( 1 << 5 ) // 32 308 | #define DEBUG_LOOPS ( 1 << 6 ) // 64 309 | 310 | struct user_t 311 | { 312 | string strLogin; 313 | string strLowerLogin; 314 | string strMD5; 315 | string strPasskey; 316 | string strMail; 317 | string strLowerMail; 318 | string strCreated; 319 | string strIP; 320 | unsigned char ucAccess; 321 | unsigned char ucGroup; 322 | string strUID; 323 | time_t tLast; 324 | time_t tLast_Index; 325 | int64 ulSeeding; 326 | int64 ulLeeching; 327 | int64 ulUploaded; 328 | int64 ulDownloaded; 329 | float flShareRatio; 330 | int64 ulBonus; 331 | float flSeedBonus; 332 | time_t tWarned; 333 | string strInvites; 334 | // unsigned int uiInvites; 335 | string strInviter; 336 | string strInviterID; 337 | }; 338 | 339 | struct request_t 340 | { 341 | // struct sockaddr_in sin; 342 | struct sockaddr_in6 sin; 343 | string strMethod; 344 | string strURL; 345 | // Harold - Adding Support for Multiple scrapes in a single /scrape call 346 | bool hasQuery; 347 | multimap multiParams; 348 | map mapParams; 349 | map mapHeaders; 350 | map mapCookies; 351 | struct user_t user; 352 | }; 353 | 354 | #define LINK_VER "TrackerLINK Ver. 0.1" 355 | 356 | #define LINKMSG_ERROR -1 357 | #define LINKMSG_NONE 0 // not transmitted 358 | #define LINKMSG_VERSION 1 359 | #define LINKMSG_INFO 2 360 | #define LINKMSG_PASSWORD 3 361 | #define LINKMSG_READY 4 362 | #define LINKMSG_ANNOUNCE 7 363 | #define LINKMSG_CLOSE 99 364 | 365 | struct linkmsg_t 366 | { 367 | long len; 368 | char type; 369 | string msg; 370 | }; 371 | 372 | // current version 373 | 374 | #define BNBT_VER "Beta 8.1" 375 | 376 | // Trinity edition 377 | /* 378 | #ifdef WIN32 379 | #define BNBT_SERVICE_NAME "BNBT Service" 380 | #endif 381 | */ 382 | 383 | extern CServer *gpServer; 384 | extern CLink *gpLink; 385 | extern CLinkServer *gpLinkServer; 386 | extern CHUBLink *gpHUBLink; 387 | extern CHUBLinkServer *gpHUBLinkServer; 388 | extern string gstrLogDir; 389 | extern string gstrLogFile; 390 | extern string gstrLogFilePattern; 391 | extern FILE *gpLog; 392 | extern string gstrErrorLogDir; 393 | extern string gstrErrorLogFile; 394 | extern string gstrErrorLogFilePattern; 395 | extern FILE *gpErrorLog; 396 | extern string gstrAccessLogDir; 397 | extern string gstrAccessLogFilePattern; 398 | extern string gstrAccessLogFile; 399 | extern FILE *gpAccessLog; 400 | extern unsigned long gulLogCount; 401 | extern unsigned long gulErrorLogCount; 402 | extern unsigned long gulAccessLogCount; 403 | extern unsigned int guiFlushInterval; 404 | extern bool gbDebug; 405 | extern unsigned long gulRestartServerNext; 406 | extern unsigned int guiRestartServerInterval; 407 | extern unsigned int guiMaxConns; 408 | extern unsigned int guiMaxRecvSize; 409 | extern string gstrStyle; 410 | extern string gstrCharSet; 411 | extern string gstrRealm; 412 | 413 | // The Trinity Edition - Modification Begins 414 | // Sets the NT Service Name variable as a global variable 415 | extern string gstrNTServiceName; 416 | 417 | // Threads 418 | extern CMutex gmtxOutput; 419 | 420 | // TCP window size 421 | extern unsigned int guiSO_RECBUF; 422 | extern unsigned int guiSO_SNDBUF; 423 | 424 | // Nagle 425 | extern bool gbTCP_NODELAY; 426 | 427 | // PID file 428 | extern string gstrPID; 429 | 430 | // Debug level 431 | extern unsigned char gucDebugLevel; 432 | 433 | // Mime types 434 | extern map gmapMime; 435 | 436 | // XBNBT XStats 437 | extern struct xbnbtstats_t gtXStats; 438 | 439 | // this is basically the old main( ), but it's here to make the NT Service code neater 440 | 441 | extern int bnbtmain( ); 442 | 443 | #endif 444 | -------------------------------------------------------------------------------- /src/bnbt.select.h: -------------------------------------------------------------------------------- 1 | // // Copyright (C) 2003-2004 Trevor Hogan 2 | // 3 | 4 | #ifndef BNBT_H 5 | #define BNBT_H 6 | 7 | // XBNBT 8 | #define XBNBT_VER string("XBNBT 81b.3.5 ZiJing Mod") 9 | 10 | #if defined ( WIN32 ) 11 | #define FD_SETSIZE 256 12 | 13 | #include 14 | #include 15 | #else 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #endif 28 | 29 | // tphogan - these new includes may have broken BSD support 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | // tphogan - eliminate namespace pollution 40 | 41 | using std :: endl; 42 | using std :: ifstream; 43 | using std :: ofstream; 44 | using std :: map; 45 | using std :: multimap; 46 | using std :: pair; 47 | using std :: string; 48 | using std :: vector; 49 | 50 | #ifdef WIN32 51 | #define WIN32_LEAN_AND_MEAN 52 | #endif 53 | 54 | #ifdef __GNUWIN32__ 55 | #define unlink remove 56 | #endif 57 | 58 | // 59 | // SOLARIS USERS - IF YOUR SYSTEM IS LITTLE ENDIAN, REMOVE THE NEXT 3 LINES 60 | // also see sha1.h 61 | // 62 | 63 | #if defined( __APPLE__ ) || defined( __SOLARIS__ ) 64 | #define BNBT_BIG_ENDIAN 65 | #endif 66 | 67 | // large integers 68 | 69 | #ifdef WIN32 70 | typedef unsigned __int8 uint8; 71 | typedef __int64 int64; 72 | typedef unsigned __int64 uint64; 73 | #else 74 | typedef unsigned char uint8; 75 | typedef long long int64; 76 | typedef unsigned long long uint64; 77 | typedef unsigned long int DWORD; 78 | typedef unsigned short int WORD; 79 | typedef unsigned char BYTE; 80 | #endif 81 | 82 | #ifdef WIN32 83 | #define snprintf _snprintf 84 | #define vsnprintf _vsnprintf 85 | #endif 86 | 87 | // mutex 88 | 89 | class CMutex 90 | { 91 | public: 92 | #ifdef WIN32 93 | void Initialize( ) { InitializeCriticalSection( &cs ); } 94 | void Destroy( ) { DeleteCriticalSection( &cs ); } 95 | void Claim( ) { EnterCriticalSection( &cs ); } 96 | void Release( ) { LeaveCriticalSection( &cs ); } 97 | 98 | CRITICAL_SECTION cs; 99 | #else 100 | void Initialize( ) { pthread_mutex_init( &mtx, 0 ); } 101 | void Destroy( ) { pthread_mutex_destroy( &mtx ); } 102 | void Claim( ) { pthread_mutex_lock( &mtx ); } 103 | void Release( ) { pthread_mutex_unlock( &mtx ); } 104 | 105 | pthread_mutex_t mtx; 106 | #endif 107 | }; 108 | 109 | // stl 110 | 111 | #ifdef WIN32 112 | #pragma warning( disable : 4786 ) 113 | #endif 114 | 115 | // path seperator 116 | 117 | #ifdef WIN32 118 | #define PATH_SEP '\\' 119 | #define STR_PATH_SEP string( 1,PATH_SEP ) 120 | #else 121 | #define PATH_SEP '/' 122 | #define STR_PATH_SEP string( 1,PATH_SEP ) 123 | #endif 124 | 125 | #define CHAR_BS '\\' 126 | #define CHAR_FS '/' 127 | 128 | // Termination character character 129 | 130 | #define TERM_CHAR '\0' 131 | 132 | // this fixes MSVC loop scoping issues 133 | 134 | /* 135 | 136 | #ifdef WIN32 137 | #define for if( 0 ) { } else for 138 | #endif 139 | 140 | */ 141 | 142 | // time stuff 143 | 144 | unsigned long GetTime( ); 145 | unsigned long GetStartTime( ); 146 | 147 | #ifdef WIN32 148 | #define MILLISLEEP( x ) Sleep( x ) 149 | #else 150 | #define MILLISLEEP( x ) usleep( ( x ) * 1000 ) 151 | #endif 152 | 153 | // network 154 | 155 | #ifdef WIN32 156 | #define EADDRINUSE WSAEADDRINUSE 157 | #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 158 | #define EAFNOSUPPORT WSAEAFNOSUPPORT 159 | #define EALREADY WSAEALREADY 160 | #define ECONNABORTED WSAECONNABORTED 161 | #define ECONNREFUSED WSAECONNREFUSED 162 | #define ECONNRESET WSAECONNRESET 163 | #define EDESTADDRREQ WSAEDESTADDRREQ 164 | #define EDQUOT WSAEDQUOT 165 | #define EHOSTDOWN WSAEHOSTDOWN 166 | #define EHOSTUNREACH WSAEHOSTUNREACH 167 | #define EINPROGRESS WSAEINPROGRESS 168 | #define EISCONN WSAEISCONN 169 | #define ELOOP WSAELOOP 170 | #define EMSGSIZE WSAEMSGSIZE 171 | // defined in Windows 172 | //#define ENAMETOOLONG WSAENAMETOOLONG 173 | #define ENETDOWN WSAENETDOWN 174 | #define ENETRESET WSAENETRESET 175 | #define ENETUNREACH WSAENETUNREACH 176 | #define ENOBUFS WSAENOBUFS 177 | #define ENOPROTOOPT WSAENOPROTOOPT 178 | #define ENOTCONN WSAENOTCONN 179 | // defined in Windows 180 | //#define ENOTEMPTY WSAENOTEMPTY 181 | #define ENOTSOCK WSAENOTSOCK 182 | #define EOPNOTSUPP WSAEOPNOTSUPP 183 | #define EPFNOSUPPORT WSAEPFNOSUPPORT 184 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 185 | #define EPROTOTYPE WSAEPROTOTYPE 186 | #define EREMOTE WSAEREMOTE 187 | #define ESHUTDOWN WSAESHUTDOWN 188 | #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 189 | #define ESTALE WSAESTALE 190 | #define ETIMEDOUT WSAETIMEDOUT 191 | #define ETOOMANYREFS WSAETOOMANYREFS 192 | #define EUSERS WSAEUSERS 193 | #define EWOULDBLOCK WSAEWOULDBLOCK 194 | // defined in Windows 195 | //#define EFAULT WSAEFAULT 196 | #define ENETDOWN WSAENETDOWN 197 | // defined in Windows 198 | //#define EINTR WSAEINTR 199 | //#define EBADF WSAEBADF 200 | //#define EACCES WSAEACCES 201 | //#define EINVAL WSAEINVAL 202 | //#define EMFILE WSAEMFILE 203 | #define EPROCLIM WSAEPROCLIM 204 | #define SYSNOTREADY WSASYSNOTREADY 205 | #define VERNOTSUPPORTED WSAVERNOTSUPPORTED 206 | #define NOTINITIALISED WSANOTINITIALISED 207 | #define EDISCON WSAEDISCON 208 | #define ENOMORE WSAENOMORE 209 | #define ECANCELLED WSAECANCELLED 210 | #define EINVALIDPROCTABLE WSAEINVALIDPROCTABLE 211 | #define EINVALIDPROVIDER WSAEINVALIDPROVIDER 212 | #define EPROVIDERFAILEDINIT WSAEPROVIDERFAILEDINIT 213 | #define SYSCALLFAILURE WSASYSCALLFAILURE 214 | #define SERVICE_NOT_FOUND WSASERVICE_NOT_FOUND 215 | #define TYPE_NOT_FOUND WSATYPE_NOT_FOUND 216 | #define _E_NO_MORE WSA_E_NO_MORE 217 | #define _E_CANCELLED WSA_E_CANCELLED 218 | #define EREFUSED WSAEREFUSED 219 | #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 220 | #define TRY_AGAIN WSATRY_AGAIN 221 | #define NO_RECOVERY WSANO_RECOVERY 222 | #define NO_DATA WSANO_DATA 223 | // defined in Windows 224 | //#define NO_ADDRESS WSANO_DATA 225 | #endif 226 | 227 | #ifndef WIN32 228 | #define closesocket close 229 | typedef int SOCKET; 230 | extern int GetLastError( ); 231 | #endif 232 | 233 | extern const char *GetLastErrorString( ); 234 | 235 | #ifdef __APPLE__ 236 | typedef int socklen_t; 237 | typedef int sockopt_len_t; 238 | #endif 239 | 240 | #ifndef INVALID_SOCKET 241 | #define INVALID_SOCKET -1 242 | #endif 243 | 244 | #ifndef SOCKET_ERROR 245 | #define SOCKET_ERROR -1 246 | #endif 247 | 248 | #ifndef INADDR_NONE 249 | #define INADDR_NONE -1 250 | #endif 251 | 252 | #ifndef MSG_NOSIGNAL 253 | #define MSG_NOSIGNAL 0 254 | #endif 255 | 256 | #define FILE_ERROR 0 257 | #define DIR_ERROR -1 258 | 259 | class CAtom; 260 | class CAtomInt; 261 | class CAtomLong; 262 | class CAtomString; 263 | class CAtomList; 264 | class CAtomDicti; 265 | 266 | class CServer; 267 | class CTracker; 268 | class CClient; 269 | 270 | class CLink; 271 | class CLinkServer; 272 | 273 | class CHUBLink; 274 | class CHUBLinkServer; 275 | 276 | struct response_t 277 | { 278 | string strCode; 279 | multimap mapHeaders; 280 | string strContent; 281 | bool bCompressOK; 282 | }; 283 | 284 | // user access levels 285 | 286 | #define ACCESS_VIEW ( 1 << 0 ) // 1 287 | #define ACCESS_DL ( 1 << 1 ) // 2 288 | #define ACCESS_COMMENTS ( 1 << 2 ) // 4 289 | #define ACCESS_UPLOAD ( 1 << 3 ) // 8 290 | #define ACCESS_EDIT ( 1 << 4 ) // 16 291 | #define ACCESS_ADMIN ( 1 << 5 ) // 32 292 | #define ACCESS_LEADER ( 1 << 6 ) // 64 293 | 294 | // user group 295 | 296 | #define GROUP_FRIENDS ( 1 << 0 ) // 1 297 | #define GROUP_RETIRED ( 1 << 1 ) // 2 298 | #define GROUP_VIP ( 1 << 2 ) // 4 299 | 300 | // debug levels 301 | 302 | #define DEBUG_BNBT ( 1 << 0 ) // 1 303 | #define DEBUG_SERVER ( 1 << 1 ) // 2 304 | #define DEBUG_CLIENT ( 1 << 2 ) // 4 305 | #define DEBUG_TRACKER ( 1 << 3 ) // 8 306 | #define DEBUG_ANNOUNCE ( 1 << 4 ) // 16 307 | #define DEBUG_SCRAPE ( 1 << 5 ) // 32 308 | #define DEBUG_LOOPS ( 1 << 6 ) // 64 309 | 310 | struct user_t 311 | { 312 | string strLogin; 313 | string strLowerLogin; 314 | string strMD5; 315 | string strPasskey; 316 | string strMail; 317 | string strLowerMail; 318 | string strCreated; 319 | string strIP; 320 | unsigned char ucAccess; 321 | unsigned char ucGroup; 322 | string strUID; 323 | time_t tLast; 324 | time_t tLast_Index; 325 | int64 ulSeeding; 326 | int64 ulLeeching; 327 | int64 ulUploaded; 328 | int64 ulDownloaded; 329 | float flShareRatio; 330 | int64 ulBonus; 331 | float flSeedBonus; 332 | time_t tWarned; 333 | string strInvites; 334 | // unsigned int uiInvites; 335 | string strInviter; 336 | string strInviterID; 337 | }; 338 | 339 | struct request_t 340 | { 341 | // struct sockaddr_in sin; 342 | struct sockaddr_in6 sin; 343 | string strMethod; 344 | string strURL; 345 | // Harold - Adding Support for Multiple scrapes in a single /scrape call 346 | bool hasQuery; 347 | multimap multiParams; 348 | map mapParams; 349 | map mapHeaders; 350 | map mapCookies; 351 | struct user_t user; 352 | }; 353 | 354 | #define LINK_VER "TrackerLINK Ver. 0.1" 355 | 356 | #define LINKMSG_ERROR -1 357 | #define LINKMSG_NONE 0 // not transmitted 358 | #define LINKMSG_VERSION 1 359 | #define LINKMSG_INFO 2 360 | #define LINKMSG_PASSWORD 3 361 | #define LINKMSG_READY 4 362 | #define LINKMSG_ANNOUNCE 7 363 | #define LINKMSG_CLOSE 99 364 | 365 | struct linkmsg_t 366 | { 367 | long len; 368 | char type; 369 | string msg; 370 | }; 371 | 372 | // current version 373 | 374 | #define BNBT_VER "Beta 8.1" 375 | 376 | // Trinity edition 377 | /* 378 | #ifdef WIN32 379 | #define BNBT_SERVICE_NAME "BNBT Service" 380 | #endif 381 | */ 382 | 383 | extern CServer *gpServer; 384 | extern CLink *gpLink; 385 | extern CLinkServer *gpLinkServer; 386 | extern CHUBLink *gpHUBLink; 387 | extern CHUBLinkServer *gpHUBLinkServer; 388 | extern string gstrLogDir; 389 | extern string gstrLogFile; 390 | extern string gstrLogFilePattern; 391 | extern FILE *gpLog; 392 | extern string gstrErrorLogDir; 393 | extern string gstrErrorLogFile; 394 | extern string gstrErrorLogFilePattern; 395 | extern FILE *gpErrorLog; 396 | extern string gstrAccessLogDir; 397 | extern string gstrAccessLogFilePattern; 398 | extern string gstrAccessLogFile; 399 | extern FILE *gpAccessLog; 400 | extern unsigned long gulLogCount; 401 | extern unsigned long gulErrorLogCount; 402 | extern unsigned long gulAccessLogCount; 403 | extern unsigned int guiFlushInterval; 404 | extern bool gbDebug; 405 | extern unsigned long gulRestartServerNext; 406 | extern unsigned int guiRestartServerInterval; 407 | extern unsigned int guiMaxConns; 408 | extern unsigned int guiMaxRecvSize; 409 | extern string gstrStyle; 410 | extern string gstrCharSet; 411 | extern string gstrRealm; 412 | 413 | // The Trinity Edition - Modification Begins 414 | // Sets the NT Service Name variable as a global variable 415 | extern string gstrNTServiceName; 416 | 417 | // Threads 418 | extern CMutex gmtxOutput; 419 | 420 | // TCP window size 421 | extern unsigned int guiSO_RECBUF; 422 | extern unsigned int guiSO_SNDBUF; 423 | 424 | // Nagle 425 | extern bool gbTCP_NODELAY; 426 | 427 | // PID file 428 | extern string gstrPID; 429 | 430 | // Debug level 431 | extern unsigned char gucDebugLevel; 432 | 433 | // Mime types 434 | extern map gmapMime; 435 | 436 | // XBNBT XStats 437 | extern struct xbnbtstats_t gtXStats; 438 | 439 | // this is basically the old main( ), but it's here to make the NT Service code neater 440 | 441 | extern int bnbtmain( ); 442 | 443 | #endif 444 | -------------------------------------------------------------------------------- /src/bnbt.h: -------------------------------------------------------------------------------- 1 | // // Copyright (C) 2003-2004 Trevor Hogan 2 | // 3 | 4 | #ifndef BNBT_H 5 | #define BNBT_H 6 | 7 | // XBNBT 8 | #define XBNBT_VER string("XBNBT 81b.3.5 ZiJing Mod") 9 | 10 | #if defined ( WIN32 ) 11 | #define FD_SETSIZE 256 12 | 13 | #include 14 | #include 15 | #else 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #endif 29 | 30 | // tphogan - these new includes may have broken BSD support 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // tphogan - eliminate namespace pollution 42 | 43 | using std :: endl; 44 | using std :: ifstream; 45 | using std :: ofstream; 46 | using std :: map; 47 | using std :: multimap; 48 | using std :: pair; 49 | using std :: string; 50 | using std :: set; 51 | using std :: vector; 52 | 53 | #ifdef WIN32 54 | #define WIN32_LEAN_AND_MEAN 55 | #endif 56 | 57 | #ifdef __GNUWIN32__ 58 | #define unlink remove 59 | #endif 60 | 61 | // 62 | // SOLARIS USERS - IF YOUR SYSTEM IS LITTLE ENDIAN, REMOVE THE NEXT 3 LINES 63 | // also see sha1.h 64 | // 65 | 66 | #if defined( __APPLE__ ) || defined( __SOLARIS__ ) 67 | #define BNBT_BIG_ENDIAN 68 | #endif 69 | 70 | // large integers 71 | 72 | #ifdef WIN32 73 | typedef unsigned __int8 uint8; 74 | typedef __int64 int64; 75 | typedef unsigned __int64 uint64; 76 | #else 77 | typedef unsigned char uint8; 78 | typedef long long int64; 79 | typedef unsigned long long uint64; 80 | typedef unsigned long int DWORD; 81 | typedef unsigned short int WORD; 82 | typedef unsigned char BYTE; 83 | #endif 84 | 85 | #ifdef WIN32 86 | #define snprintf _snprintf 87 | #define vsnprintf _vsnprintf 88 | #endif 89 | 90 | // mutex 91 | 92 | class CMutex 93 | { 94 | public: 95 | #ifdef WIN32 96 | void Initialize( ) { InitializeCriticalSection( &cs ); } 97 | void Destroy( ) { DeleteCriticalSection( &cs ); } 98 | void Claim( ) { EnterCriticalSection( &cs ); } 99 | void Release( ) { LeaveCriticalSection( &cs ); } 100 | 101 | CRITICAL_SECTION cs; 102 | #else 103 | void Initialize( ) { pthread_mutex_init( &mtx, 0 ); } 104 | void Destroy( ) { pthread_mutex_destroy( &mtx ); } 105 | void Claim( ) { pthread_mutex_lock( &mtx ); } 106 | void Release( ) { pthread_mutex_unlock( &mtx ); } 107 | 108 | pthread_mutex_t mtx; 109 | #endif 110 | }; 111 | 112 | // stl 113 | 114 | #ifdef WIN32 115 | #pragma warning( disable : 4786 ) 116 | #endif 117 | 118 | // path seperator 119 | 120 | #ifdef WIN32 121 | #define PATH_SEP '\\' 122 | #define STR_PATH_SEP string( 1,PATH_SEP ) 123 | #else 124 | #define PATH_SEP '/' 125 | #define STR_PATH_SEP string( 1,PATH_SEP ) 126 | #endif 127 | 128 | #define CHAR_BS '\\' 129 | #define CHAR_FS '/' 130 | 131 | // Termination character character 132 | 133 | #define TERM_CHAR '\0' 134 | 135 | // this fixes MSVC loop scoping issues 136 | 137 | /* 138 | 139 | #ifdef WIN32 140 | #define for if( 0 ) { } else for 141 | #endif 142 | 143 | */ 144 | 145 | // time stuff 146 | 147 | unsigned long GetTime( ); 148 | unsigned long GetStartTime( ); 149 | 150 | #ifdef WIN32 151 | #define MILLISLEEP( x ) Sleep( x ) 152 | #else 153 | #define MILLISLEEP( x ) usleep( ( x ) * 1000 ) 154 | #endif 155 | 156 | // network 157 | 158 | #ifdef WIN32 159 | #define EADDRINUSE WSAEADDRINUSE 160 | #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 161 | #define EAFNOSUPPORT WSAEAFNOSUPPORT 162 | #define EALREADY WSAEALREADY 163 | #define ECONNABORTED WSAECONNABORTED 164 | #define ECONNREFUSED WSAECONNREFUSED 165 | #define ECONNRESET WSAECONNRESET 166 | #define EDESTADDRREQ WSAEDESTADDRREQ 167 | #define EDQUOT WSAEDQUOT 168 | #define EHOSTDOWN WSAEHOSTDOWN 169 | #define EHOSTUNREACH WSAEHOSTUNREACH 170 | #define EINPROGRESS WSAEINPROGRESS 171 | #define EISCONN WSAEISCONN 172 | #define ELOOP WSAELOOP 173 | #define EMSGSIZE WSAEMSGSIZE 174 | // defined in Windows 175 | //#define ENAMETOOLONG WSAENAMETOOLONG 176 | #define ENETDOWN WSAENETDOWN 177 | #define ENETRESET WSAENETRESET 178 | #define ENETUNREACH WSAENETUNREACH 179 | #define ENOBUFS WSAENOBUFS 180 | #define ENOPROTOOPT WSAENOPROTOOPT 181 | #define ENOTCONN WSAENOTCONN 182 | // defined in Windows 183 | //#define ENOTEMPTY WSAENOTEMPTY 184 | #define ENOTSOCK WSAENOTSOCK 185 | #define EOPNOTSUPP WSAEOPNOTSUPP 186 | #define EPFNOSUPPORT WSAEPFNOSUPPORT 187 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 188 | #define EPROTOTYPE WSAEPROTOTYPE 189 | #define EREMOTE WSAEREMOTE 190 | #define ESHUTDOWN WSAESHUTDOWN 191 | #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 192 | #define ESTALE WSAESTALE 193 | #define ETIMEDOUT WSAETIMEDOUT 194 | #define ETOOMANYREFS WSAETOOMANYREFS 195 | #define EUSERS WSAEUSERS 196 | #define EWOULDBLOCK WSAEWOULDBLOCK 197 | // defined in Windows 198 | //#define EFAULT WSAEFAULT 199 | #define ENETDOWN WSAENETDOWN 200 | // defined in Windows 201 | //#define EINTR WSAEINTR 202 | //#define EBADF WSAEBADF 203 | //#define EACCES WSAEACCES 204 | //#define EINVAL WSAEINVAL 205 | //#define EMFILE WSAEMFILE 206 | #define EPROCLIM WSAEPROCLIM 207 | #define SYSNOTREADY WSASYSNOTREADY 208 | #define VERNOTSUPPORTED WSAVERNOTSUPPORTED 209 | #define NOTINITIALISED WSANOTINITIALISED 210 | #define EDISCON WSAEDISCON 211 | #define ENOMORE WSAENOMORE 212 | #define ECANCELLED WSAECANCELLED 213 | #define EINVALIDPROCTABLE WSAEINVALIDPROCTABLE 214 | #define EINVALIDPROVIDER WSAEINVALIDPROVIDER 215 | #define EPROVIDERFAILEDINIT WSAEPROVIDERFAILEDINIT 216 | #define SYSCALLFAILURE WSASYSCALLFAILURE 217 | #define SERVICE_NOT_FOUND WSASERVICE_NOT_FOUND 218 | #define TYPE_NOT_FOUND WSATYPE_NOT_FOUND 219 | #define _E_NO_MORE WSA_E_NO_MORE 220 | #define _E_CANCELLED WSA_E_CANCELLED 221 | #define EREFUSED WSAEREFUSED 222 | #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 223 | #define TRY_AGAIN WSATRY_AGAIN 224 | #define NO_RECOVERY WSANO_RECOVERY 225 | #define NO_DATA WSANO_DATA 226 | // defined in Windows 227 | //#define NO_ADDRESS WSANO_DATA 228 | #endif 229 | 230 | #ifndef WIN32 231 | #define closesocket close 232 | typedef int SOCKET; 233 | extern int GetLastError( ); 234 | #endif 235 | 236 | extern const char *GetLastErrorString( ); 237 | 238 | #ifdef __APPLE__ 239 | typedef int socklen_t; 240 | typedef int sockopt_len_t; 241 | #endif 242 | 243 | #ifndef INVALID_SOCKET 244 | #define INVALID_SOCKET -1 245 | #endif 246 | 247 | #ifndef SOCKET_ERROR 248 | #define SOCKET_ERROR -1 249 | #endif 250 | 251 | #ifndef INADDR_NONE 252 | #define INADDR_NONE -1 253 | #endif 254 | 255 | #ifndef MSG_NOSIGNAL 256 | #define MSG_NOSIGNAL 0 257 | #endif 258 | 259 | #define FILE_ERROR 0 260 | #define DIR_ERROR -1 261 | 262 | class CAtom; 263 | class CAtomInt; 264 | class CAtomLong; 265 | class CAtomString; 266 | class CAtomList; 267 | class CAtomDicti; 268 | 269 | class CServer; 270 | class CTracker; 271 | class CClient; 272 | class CCache; 273 | 274 | class CLink; 275 | class CLinkServer; 276 | 277 | class CHUBLink; 278 | class CHUBLinkServer; 279 | 280 | struct response_t 281 | { 282 | string strCode; 283 | multimap mapHeaders; 284 | string strContent; 285 | bool bCompressOK; 286 | }; 287 | 288 | // user access levels 289 | 290 | #define ACCESS_VIEW ( 1 << 0 ) // 1 291 | #define ACCESS_DL ( 1 << 1 ) // 2 292 | #define ACCESS_COMMENTS ( 1 << 2 ) // 4 293 | #define ACCESS_UPLOAD ( 1 << 3 ) // 8 294 | #define ACCESS_EDIT ( 1 << 4 ) // 16 295 | #define ACCESS_ADMIN ( 1 << 5 ) // 32 296 | #define ACCESS_LEADER ( 1 << 6 ) // 64 297 | 298 | // user group 299 | 300 | #define GROUP_FRIENDS ( 1 << 0 ) // 1 301 | #define GROUP_RETIRED ( 1 << 1 ) // 2 302 | #define GROUP_VIP ( 1 << 2 ) // 4 303 | 304 | // debug levels 305 | 306 | #define DEBUG_BNBT ( 1 << 0 ) // 1 307 | #define DEBUG_SERVER ( 1 << 1 ) // 2 308 | #define DEBUG_CLIENT ( 1 << 2 ) // 4 309 | #define DEBUG_TRACKER ( 1 << 3 ) // 8 310 | #define DEBUG_ANNOUNCE ( 1 << 4 ) // 16 311 | #define DEBUG_SCRAPE ( 1 << 5 ) // 32 312 | #define DEBUG_LOOPS ( 1 << 6 ) // 64 313 | 314 | struct user_t 315 | { 316 | string strUID; 317 | string strLogin; 318 | string strLowerLogin; 319 | string strMD5; 320 | string strPasskey; 321 | string strMail; 322 | string strLowerMail; 323 | string strCreated; 324 | string strIP; 325 | unsigned char ucAccess; 326 | unsigned char ucGroup; 327 | string strTitle; 328 | time_t tLast; 329 | // time_t tLast_Index; 330 | // time_t tLast_Info; 331 | // int64 ulSeeding; 332 | // int64 ulLeeching; 333 | // string strSeeding; 334 | // string strLeeching; 335 | int64 ulUploaded; 336 | int64 ulDownloaded; 337 | float flShareRatio; 338 | int64 ulBonus; 339 | float flSeedBonus; 340 | time_t tWarned; 341 | string strInvites; 342 | string strInviter; 343 | string strInviterID; 344 | unsigned char ucInvitable; 345 | // string strTalk; 346 | // string strTalkRef; 347 | }; 348 | 349 | struct request_t 350 | { 351 | // struct sockaddr_in sin; 352 | struct sockaddr_in6 sin; 353 | string strIP; 354 | string strMethod; 355 | string strURL; 356 | // Harold - Adding Support for Multiple scrapes in a single /scrape call 357 | bool hasQuery; 358 | multimap multiParams; 359 | map mapParams; 360 | map mapHeaders; 361 | map mapCookies; 362 | struct user_t user; 363 | }; 364 | 365 | #define LINK_VER "TrackerLINK Ver. 0.1" 366 | 367 | #define LINKMSG_ERROR -1 368 | #define LINKMSG_NONE 0 // not transmitted 369 | #define LINKMSG_VERSION 1 370 | #define LINKMSG_INFO 2 371 | #define LINKMSG_PASSWORD 3 372 | #define LINKMSG_READY 4 373 | #define LINKMSG_ANNOUNCE 7 374 | #define LINKMSG_CLOSE 99 375 | 376 | struct linkmsg_t 377 | { 378 | long len; 379 | char type; 380 | string msg; 381 | }; 382 | 383 | // current version 384 | 385 | #define BNBT_VER "Beta 8.1" 386 | 387 | // Trinity edition 388 | /* 389 | #ifdef WIN32 390 | #define BNBT_SERVICE_NAME "BNBT Service" 391 | #endif 392 | */ 393 | 394 | extern CServer *gpServer; 395 | extern CLink *gpLink; 396 | extern CLinkServer *gpLinkServer; 397 | extern CHUBLink *gpHUBLink; 398 | extern CHUBLinkServer *gpHUBLinkServer; 399 | extern string gstrLogDir; 400 | extern string gstrLogFile; 401 | extern string gstrLogFilePattern; 402 | extern FILE *gpLog; 403 | extern string gstrErrorLogDir; 404 | extern string gstrErrorLogFile; 405 | extern string gstrErrorLogFilePattern; 406 | extern FILE *gpErrorLog; 407 | extern string gstrAccessLogDir; 408 | extern string gstrAccessLogFilePattern; 409 | extern string gstrAccessLogFile; 410 | extern FILE *gpAccessLog; 411 | extern unsigned long gulLogCount; 412 | extern unsigned long gulErrorLogCount; 413 | extern unsigned long gulAccessLogCount; 414 | extern unsigned int guiFlushInterval; 415 | extern bool gbDebug; 416 | extern unsigned long gulRestartServerNext; 417 | extern unsigned int guiRestartServerInterval; 418 | extern unsigned int guiMaxConns; 419 | extern unsigned int guiMaxRecvSize; 420 | extern string gstrStyle; 421 | extern string gstrCharSet; 422 | extern string gstrRealm; 423 | extern string gstrPasswordKey; 424 | 425 | // The Trinity Edition - Modification Begins 426 | // Sets the NT Service Name variable as a global variable 427 | extern string gstrNTServiceName; 428 | 429 | // Threads 430 | extern CMutex gmtxOutput; 431 | extern CMutex gmtxMySQL; 432 | 433 | // TCP window size 434 | extern unsigned int guiSO_RECBUF; 435 | extern unsigned int guiSO_SNDBUF; 436 | 437 | // Nagle 438 | extern bool gbTCP_NODELAY; 439 | 440 | // PID file 441 | extern string gstrPID; 442 | 443 | // Debug level 444 | extern unsigned char gucDebugLevel; 445 | 446 | // Mime types 447 | extern map gmapMime; 448 | 449 | // XBNBT XStats 450 | extern struct xbnbtstats_t gtXStats; 451 | 452 | // this is basically the old main( ), but it's here to make the NT Service code neater 453 | 454 | extern int bnbtmain( ); 455 | 456 | #endif 457 | -------------------------------------------------------------------------------- /src/tracker_file.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | // =Xotic= Modified Source File 23 | 24 | #if defined ( WIN32 ) 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | #include "bnbt.h" 31 | #include "bnbt_mysql.h" 32 | #include "atom.h" 33 | #include "config.h" 34 | #include "tracker.h" 35 | #include "util.h" 36 | #include "gd.h" 37 | 38 | void CTracker :: serverResponseFile( struct request_t *pRequest, struct response_t *pResponse ) 39 | { 40 | // Set the start time 41 | const struct bnbttv btv( UTIL_CurrentTime( ) ); 42 | 43 | // Verify that the IP is permitted to access the tracker 44 | if( m_ucIPBanMode != 0 ) 45 | if( IsIPBanned( pRequest, pResponse, btv, "File server", string( CSS_INDEX ), NOT_INDEX ) ) 46 | return; 47 | 48 | // Forbidden requests 49 | if( m_strFileDir.empty( ) || pRequest->strURL.find( "..\\" ) != string :: npos || pRequest->strURL.find( "../" ) != string :: npos ) 50 | { 51 | // Output common HTML head 52 | HTML_Common_Begin( pRequest, pResponse, "File server: " + gmapLANG_CFG["server_response_403"], string( CSS_INDEX ), string( ), NOT_INDEX, CODE_403 ); 53 | 54 | // Output common HTML tail 55 | HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_INDEX ) ); 56 | 57 | return; 58 | } 59 | 60 | // User requires a level of authorisation 61 | // if( !( pRequest->user.ucAccess & ACCESS_VIEW ) || !( pRequest->user.ucAccess & ACCESS_UPLOAD ) ) 62 | // if( !( pRequest->user.ucAccess & m_ucAccessView ) ) 63 | // { 64 | // pResponse->strCode = "401 " + gmapLANG_CFG["server_response_401"]; 65 | //// pResponse->mapHeaders.insert( pair( "WWW-Authenticate", string( "Basic realm=\"" ) + gstrRealm + "\"" ) ); 66 | 67 | // return; 68 | // } 69 | 70 | // Strip bnbt_file_dir from request 71 | string strFile = ""; 72 | 73 | if( !m_strFileDir.empty( ) ) 74 | strFile = UTIL_EscapedToString( pRequest->strURL.substr( (int)m_strFileDir.size( ) + 1 ) ); 75 | else 76 | strFile = UTIL_EscapedToString( pRequest->strURL ); 77 | 78 | // Replace the path seperators for OS dependancy 79 | for( unsigned char ucPos = 0; ucPos < strFile.size( ); ucPos++ ) 80 | { 81 | if( strFile.substr( ucPos,1 ) == STR_PATH_SEP ) 82 | strFile.replace( ucPos, 1, STR_PATH_SEP ); 83 | } 84 | 85 | // Get the file extension from the request 86 | const string cstrExt( getFileExt( strFile ) ); 87 | 88 | // Make the local path from the bnbt_file_dir and the request 89 | const string cstrPath( m_strFileDir + strFile ); 90 | 91 | // Serve the file if it exists 92 | if( UTIL_CheckFile( cstrPath.c_str( ) ) ) 93 | { 94 | pResponse->strCode = "200 " + gmapLANG_CFG["server_response_200"]; 95 | 96 | pResponse->mapHeaders.insert( pair( "Content-Type", gmapMime[cstrExt] ) ); 97 | 98 | // cache for awhile 99 | 100 | time_t tNow = time( 0 ) + m_uiFileExpires * 60; 101 | char *szTime = asctime( gmtime( &tNow ) ); 102 | szTime[strlen( szTime ) - 1] = TERM_CHAR; 103 | 104 | pResponse->mapHeaders.insert( pair( "Expires", string( szTime ) + " GMT" ) ); 105 | 106 | pResponse->bCompressOK = false; 107 | 108 | pResponse->strContent = UTIL_ReadFile( cstrPath.c_str( ) ); 109 | } 110 | else 111 | { 112 | // Output common HTML head 113 | HTML_Common_Begin( pRequest, pResponse, "File server: " + gmapLANG_CFG["server_response_404"], string( CSS_INDEX ), string( ), NOT_INDEX, CODE_404 ); 114 | 115 | // Output common HTML tail 116 | HTML_Common_End( pRequest, pResponse, btv, NOT_INDEX, string( CSS_INDEX ) ); 117 | } 118 | } 119 | 120 | void CTracker :: serverResponseUserbar( struct request_t *pRequest, struct response_t *pResponse ) 121 | { 122 | // Set the start time 123 | const struct bnbttv btv( UTIL_CurrentTime( ) ); 124 | 125 | // Verify that the IP is permitted to access the tracker 126 | if( m_ucIPBanMode != 0 ) 127 | if( IsIPBanned( pRequest, pResponse, btv, "File server", string( CSS_INDEX ), NOT_INDEX ) ) 128 | return; 129 | 130 | pResponse->strCode = "200 " + gmapLANG_CFG["server_response_200"]; 131 | 132 | 133 | string strUserbar = pRequest->strURL.substr( 9 ); 134 | const string :: size_type ciExt( strUserbar.rfind( "." ) ); 135 | const string cstrExt( getFileExt( strUserbar ) ); 136 | 137 | if( ciExt != string :: npos && UTIL_ToLower( cstrExt ) == ".png" ) 138 | { 139 | string strUID = strUserbar.substr( 0, ciExt ); 140 | 141 | if( strUID.find_first_not_of( "1234567890" ) != string :: npos ) 142 | strUID.erase( ); 143 | 144 | if( !strUID.empty( ) ) 145 | { 146 | CMySQLQuery *pQueryUser = new CMySQLQuery( "SELECT busername,baccess,bgroup,buploaded,bdownloaded,bbonus FROM users WHERE buid=" + strUID ); 147 | 148 | vector vecQueryUser; 149 | 150 | vecQueryUser.reserve(6); 151 | 152 | vecQueryUser = pQueryUser->nextRow( ); 153 | 154 | delete pQueryUser; 155 | 156 | if( vecQueryUser.size( ) == 6 ) 157 | { 158 | int64 ulUploaded = 0; 159 | int64 ulDownloaded = 0; 160 | int64 ulBonus = 0; 161 | float flShareRatio = 0; 162 | 163 | unsigned char ucAccess = (unsigned char)atoi( vecQueryUser[1].c_str( ) ); 164 | unsigned char ucGroup = (unsigned char)atoi( vecQueryUser[2].c_str( ) ); 165 | ulUploaded = UTIL_StringTo64( vecQueryUser[3].c_str( ) ); 166 | ulDownloaded = UTIL_StringTo64( vecQueryUser[4].c_str( ) ); 167 | ulBonus = UTIL_StringTo64( vecQueryUser[5].c_str( ) ); 168 | if( ulDownloaded == 0 ) 169 | { 170 | if( ulUploaded == 0 ) 171 | flShareRatio = 0; 172 | else 173 | flShareRatio = -1; 174 | } 175 | else 176 | flShareRatio = (float)ulUploaded / (float)ulDownloaded; 177 | 178 | char szFloat[16]; 179 | string strShareRatio = string( ); 180 | if( ( -1.001 < flShareRatio ) && ( flShareRatio < -0.999 ) ) 181 | strShareRatio = gmapLANG_CFG["perfect"]; 182 | else 183 | { 184 | memset( szFloat, 0, sizeof( szFloat ) / sizeof( char ) ); 185 | snprintf( szFloat, sizeof( szFloat ) / sizeof( char ), "%0.3f", flShareRatio ); 186 | strShareRatio = string( szFloat ); 187 | } 188 | 189 | bool bShareRatioWarned = checkShareRatio( ulDownloaded, flShareRatio ); 190 | string strClass = UTIL_UserClass( ucAccess, ucGroup ); 191 | if( m_bRatioRestrict && bShareRatioWarned && strClass == gmapLANG_CFG["class_member"] ) 192 | strClass = "share_warned"; 193 | 194 | gdImagePtr imWorking = 0; 195 | gdImagePtr imMaster = 0; 196 | char *pData = 0; 197 | 198 | int brect[8]; 199 | 200 | string strFontEN = CFG_GetString( "userbar_font_en", string( ) ); 201 | string strFontCN = CFG_GetString( "userbar_font_cn", string( ) ); 202 | 203 | int iSize = 0; 204 | 205 | unsigned int uiXSize, uiYSize; 206 | unsigned int uiBg = 0; 207 | unsigned int uiUsercolor = 0; 208 | unsigned int uiFontcolor = 0; 209 | 210 | string strBgColor = CFG_GetString( "userbar_bg_color", string( "204,204,255" ) ); 211 | string strUserColor = CFG_GetString( "userbar_user_color_" + strClass, string( "0,0,0" ) ); 212 | string strFontColor = CFG_GetString( "userbar_font_color", string( "0,0,0" ) ); 213 | string strX = CFG_GetString( "userbar_x", string( "24,150,240,354,472" ) ); 214 | string strY = CFG_GetString( "userbar_y", string( "14,14,14,14,14" ) ); 215 | 216 | vector vecBgColor; 217 | vecBgColor.reserve(3); 218 | vector vecUserColor; 219 | vecUserColor.reserve(3); 220 | vector vecFontColor; 221 | vecFontColor.reserve(3); 222 | 223 | vector vecX; 224 | vecX.reserve(5); 225 | vector vecY; 226 | vecY.reserve(5); 227 | 228 | vecBgColor = UTIL_SplitToVector( strBgColor, "," ); 229 | vecUserColor = UTIL_SplitToVector( strUserColor, "," ); 230 | vecFontColor = UTIL_SplitToVector( strFontColor, "," ); 231 | vecX = UTIL_SplitToVector( strX, "," ); 232 | vecY = UTIL_SplitToVector( strY, "," ); 233 | 234 | int uiBgRed = atoi( vecBgColor[0].c_str( ) ); 235 | int uiBgGreen = atoi( vecBgColor[1].c_str( ) ); 236 | int uiBgBlue = atoi( vecBgColor[2].c_str( ) ); 237 | int uiUserRed = atoi( vecUserColor[0].c_str( ) ); 238 | int uiUserGreen = atoi( vecUserColor[1].c_str( ) ); 239 | int uiUserBlue = atoi( vecUserColor[2].c_str( ) ); 240 | int uiFontRed = atoi( vecFontColor[0].c_str( ) ); 241 | int uiFontGreen = atoi( vecFontColor[1].c_str( ) ); 242 | int uiFontBlue = atoi( vecFontColor[2].c_str( ) ); 243 | int uiX1 = atoi( vecX[0].c_str( ) ); 244 | int uiX2 = atoi( vecX[1].c_str( ) ); 245 | int uiX3 = atoi( vecX[2].c_str( ) ); 246 | int uiX4 = atoi( vecX[3].c_str( ) ); 247 | int uiX5 = atoi( vecX[4].c_str( ) ); 248 | int uiY1 = atoi( vecY[0].c_str( ) ); 249 | int uiY2 = atoi( vecY[1].c_str( ) ); 250 | int uiY3 = atoi( vecY[2].c_str( ) ); 251 | int uiY4 = atoi( vecY[3].c_str( ) ); 252 | int uiY5 = atoi( vecY[4].c_str( ) ); 253 | 254 | if( !userbar.strFile.empty( ) ) 255 | { 256 | imMaster = gdImageCreateFromPngPtr( userbar.strFile.size( ), (void *)userbar.strFile.c_str( ) ); 257 | } 258 | else 259 | imMaster = gdImageCreate( 550, 20 ); 260 | 261 | uiXSize = gdImageSX( imMaster ); 262 | uiYSize = gdImageSY( imMaster ); 263 | 264 | if( imMaster->trueColor != 0 ) 265 | imWorking = gdImageCreateTrueColor( uiXSize, uiYSize ); 266 | else 267 | imWorking = gdImageCreate( uiXSize, uiYSize ); 268 | 269 | gdImageCopy(imWorking, imMaster, 0, 0, 0, 0, uiXSize, uiYSize ); 270 | 271 | uiBg = gdImageColorResolve(imWorking, uiBgRed, uiBgGreen, uiBgBlue); 272 | uiUsercolor = gdImageColorResolve(imWorking, uiUserRed, uiUserGreen, uiUserBlue); 273 | 274 | uiFontcolor = gdImageColorResolve(imWorking, uiFontRed, uiFontGreen, uiFontBlue); 275 | 276 | gdImageStringFT( imWorking, &brect[0], uiUsercolor, (char *)strFontCN.c_str( ), 10.0, 0.0, uiX1, uiY1, (char *)vecQueryUser[0].c_str( ) ); 277 | gdImageStringFT( imWorking, &brect[0], uiFontcolor, (char *)strFontEN.c_str( ), 10.0, 0.0, uiX2, uiY2, (char *)UTIL_BytesToString( ulUploaded ).c_str( ) ); 278 | gdImageStringFT( imWorking, &brect[0], uiFontcolor, (char *)strFontEN.c_str( ), 10.0, 0.0, uiX3, uiY3, (char *)UTIL_BytesToString( ulDownloaded ).c_str( ) ); 279 | gdImageStringFT( imWorking, &brect[0], uiFontcolor, (char *)strFontEN.c_str( ), 10.0, 0.0, uiX4, uiY4, (char *)strShareRatio.c_str( ) ); 280 | gdImageStringFT( imWorking, &brect[0], uiFontcolor, (char *)strFontEN.c_str( ), 10.0, 0.0, uiX5, uiY5, (char *)string( CAtomLong( ulBonus / 100 ).toString( ) + "." + CAtomInt( ( ulBonus % 100 ) / 10 ).toString( ) + CAtomInt( ulBonus % 10 ).toString( ) ).c_str( ) ); 281 | 282 | // FILE *pImageoutFile = FILE_ERROR; 283 | // pImageoutFile = fopen( "test.png", "wb" ); 284 | // gdImagePngEx( imWorking, pImageoutFile, 0 ); 285 | // fclose( pImageoutFile ); 286 | // 287 | pData = (char *)gdImagePngPtrEx( imWorking, &iSize, 1 ); 288 | 289 | pResponse->mapHeaders.insert( pair( "Content-Type", gmapMime[cstrExt] ) ); 290 | 291 | // cache for awhile 292 | 293 | time_t tNow = time( 0 ) + 1 * 60; 294 | char *szTime = asctime( gmtime( &tNow ) ); 295 | szTime[strlen( szTime ) - 1] = TERM_CHAR; 296 | 297 | pResponse->mapHeaders.insert( pair( "Expires", string( szTime ) + " GMT" ) ); 298 | 299 | pResponse->bCompressOK = false; 300 | 301 | pResponse->strContent = string( pData, iSize ); 302 | 303 | gdImageDestroy( imWorking ); 304 | gdImageDestroy( imMaster ); 305 | gdFree( pData ); 306 | } 307 | } 308 | } 309 | 310 | } 311 | -------------------------------------------------------------------------------- /src/server_v4.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | // =Xotic= Modified Source File 23 | 24 | #include "bnbt.h" 25 | #include "atom.h" 26 | #include "client.h" 27 | #include "config.h" 28 | #include "server.h" 29 | #include "tracker.h" 30 | #include "util.h" 31 | 32 | #ifdef WIN32 33 | #include "util_ntservice.h" 34 | #endif 35 | 36 | CServer :: CServer( ) 37 | { 38 | m_vecClients.reserve( guiMaxConns ); 39 | 40 | m_bKill = false; 41 | 42 | m_uiSocketTimeOut = CFG_GetInt( "socket_timeout", 15 ); 43 | m_strBind = CFG_GetString( "bind", string( ) ); 44 | m_cCompression = (char)CFG_GetInt( "bnbt_compression_level", 6 ); 45 | 46 | // clamp compression 47 | 48 | if( m_cCompression > 9 ) 49 | m_cCompression = 9; 50 | 51 | struct sockaddr_in sin; 52 | 53 | memset( &sin, 0, sizeof( sin ) ); 54 | 55 | sin.sin_family = AF_INET; 56 | 57 | if( !m_strBind.empty( ) ) 58 | { 59 | // bind to m_strBind 60 | 61 | if( gbDebug && ( gucDebugLevel & DEBUG_SERVER ) ) 62 | UTIL_LogPrint( "server - binding to %s\n", m_strBind.c_str( ) ); 63 | 64 | sin.sin_addr.s_addr = inet_addr( m_strBind.c_str( ) ); 65 | 66 | if( sin.sin_addr.s_addr == INADDR_NONE || sin.sin_addr.s_addr == 0 ) 67 | { 68 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_bind"] + "\n" ).c_str( ), m_strBind.c_str( ) ); 69 | 70 | exit( 1 ); 71 | } 72 | } 73 | else 74 | { 75 | // bind to all available addresses 76 | 77 | if( gbDebug && ( gucDebugLevel & DEBUG_SERVER ) ) 78 | UTIL_LogPrint( ( gmapLANG_CFG["binding_to_all"] + "\n" ).c_str( ) ); 79 | 80 | sin.sin_addr.s_addr = INADDR_ANY; 81 | } 82 | 83 | // tphogan - legacy support, check for "port" config entry 84 | // by doing this here "port" will always be required 85 | // so in fact this isn't entirely legacy support since it'll continue to be used 86 | 87 | sin.sin_port = htons( (u_short)CFG_GetInt( "port", 6969 ) ) ; 88 | 89 | if( sin.sin_port == 0 ) 90 | UTIL_LogPrint( ( gmapLANG_CFG["binding_to_all"] + "\n" ).c_str( ), CAtomInt( CFG_GetInt( "port", 6969 ) ).toString( ).c_str( ) ); 91 | else if( !AddListener( sin ) ) 92 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_listen"] + "\n" ).c_str( ), CAtomInt( CFG_GetInt( "port", 6969 ) ).toString( ).c_str( ) ); 93 | else 94 | UTIL_LogPrint( ( gmapLANG_CFG["listen_on_port"] + "\n" ).c_str( ), CAtomInt( CFG_GetInt( "port", 6969 ) ).toString( ).c_str( ) ); 95 | 96 | // tphogan - retrieve list of ports from config file for multiport listeners 97 | // do we want to support multiple bindings as well? 98 | // this code will bind every socket to the same address 99 | 100 | unsigned char ucPort = 1; 101 | 102 | string strName = "port" + CAtomInt( ucPort ).toString( ); 103 | string strPort = CFG_GetString( strName, string( ) ); 104 | 105 | while( !strPort.empty( ) ) 106 | { 107 | sin.sin_port = htons( (u_short)atoi( strPort.c_str( ) ) ) ; 108 | 109 | if( sin.sin_port == 0 ) 110 | UTIL_LogPrint( ( gmapLANG_CFG["invalid_ports"] + "\n" ).c_str( ), strPort.c_str( ), strName.c_str( ) ); 111 | else if( !AddListener( sin ) ) 112 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_listens"] + "\n" ).c_str( ), strPort.c_str( ), strName.c_str( ) ); 113 | else 114 | UTIL_LogPrint( ( gmapLANG_CFG["listen_on_ports"] + "\n" ).c_str( ), strPort.c_str( ), strName.c_str( ) ); 115 | 116 | strName = "port" + CAtomInt( ++ucPort ).toString( ); 117 | strPort = CFG_GetString( strName, string( ) ); 118 | } 119 | 120 | // tphogan - we didn't exit on invalid ports above 121 | // so make sure we're listening on at least one valid port 122 | // however, since "port" is always forced greater than zero in CFG_SetDefaults 123 | // this should only happen if a valid port is denied for "port" 124 | // for example, address in use or not enough privs for ports < 1024 125 | 126 | if( m_vecListeners.empty( ) ) 127 | { 128 | UTIL_LogPrint( ( gmapLANG_CFG["not_listening"] + "\n" ).c_str( ) ); 129 | 130 | exit( 1 ); 131 | } 132 | 133 | m_pTracker = new CTracker( ); 134 | 135 | UTIL_LogPrint( ( gmapLANG_CFG["server_start"] + "\n" ).c_str( ) ); 136 | } 137 | 138 | CServer :: ~CServer( ) 139 | { 140 | for( vector :: iterator itListener = m_vecListeners.begin( ); itListener != m_vecListeners.end( ); itListener++ ) 141 | closesocket( *itListener ); 142 | 143 | for( vector :: iterator itClient = m_vecClients.begin( ); itClient != m_vecClients.end( ); itClient++ ) 144 | delete *itClient; 145 | 146 | m_vecListeners.clear( ); 147 | m_vecClients.clear( ); 148 | 149 | if( m_pTracker ) 150 | delete m_pTracker; 151 | 152 | m_pTracker = 0; 153 | 154 | UTIL_LogPrint( ( gmapLANG_CFG["server_exit"] + "\n" ).c_str( ) ); 155 | } 156 | 157 | void CServer :: Kill( ) 158 | { 159 | m_bKill = true; 160 | } 161 | 162 | bool CServer :: isDying( ) 163 | { 164 | return m_bKill; 165 | } 166 | 167 | bool CServer :: Update( const bool &bBlock ) 168 | { 169 | if( m_vecClients.size( ) < guiMaxConns ) 170 | { 171 | // tphogan - check every listener for new connections 172 | 173 | fd_set fdServer; 174 | FD_ZERO( &fdServer ); 175 | 176 | struct timeval tv; 177 | struct sockaddr_in adrFrom; 178 | int iAddrLen = 0; 179 | SOCKET sckClient = 0; 180 | 181 | for( vector :: iterator itListener = m_vecListeners.begin( ); itListener != m_vecListeners.end( ); itListener++ ) 182 | { 183 | FD_CLR( *itListener, &fdServer ); 184 | FD_SET( *itListener, &fdServer ); 185 | 186 | // tphogan - only block on the first listener 187 | // this is actually a bit of a hack but it don't feel like doing it "right" :) 188 | 189 | if( bBlock && itListener == m_vecListeners.begin( ) ) 190 | { 191 | // block for 100 ms to keep from eating up all cpu time 192 | 193 | tv.tv_sec = 0; 194 | tv.tv_usec = 100000; 195 | } 196 | else 197 | { 198 | tv.tv_sec = 0; 199 | tv.tv_usec = 0; 200 | } 201 | 202 | #ifdef WIN32 203 | if( select( 1, &fdServer, 0, 0, &tv ) == SOCKET_ERROR ) 204 | #else 205 | if( select( *itListener + 1, &fdServer, 0, 0, &tv ) == SOCKET_ERROR ) 206 | #endif 207 | { 208 | UTIL_LogPrint( ( gmapLANG_CFG["select_error"] + "\n" ).c_str( ), GetLastErrorString( ) ); 209 | 210 | FD_CLR( *itListener, &fdServer ); 211 | } 212 | 213 | if( FD_ISSET( *itListener, &fdServer ) !=0 ) 214 | { 215 | iAddrLen = sizeof( adrFrom ); 216 | 217 | #ifdef WIN32 218 | sckClient = accept( *itListener, (struct sockaddr *)&adrFrom, &iAddrLen ); 219 | 220 | if( sckClient == INVALID_SOCKET ) 221 | #else 222 | sckClient = accept( *itListener, (struct sockaddr *)&adrFrom, (socklen_t *)&iAddrLen ); 223 | 224 | if( sckClient == INVALID_SOCKET ) 225 | #endif 226 | UTIL_LogPrint( ( gmapLANG_CFG["accept_error"] + "\n" ).c_str( ), GetLastErrorString( ) ); 227 | else 228 | m_vecClients.push_back( new CClient( sckClient, adrFrom, m_uiSocketTimeOut, m_cCompression ) ); 229 | } 230 | } 231 | } 232 | else 233 | { 234 | // maximum connections reached 235 | 236 | // tphogan - reduced from 100 ms to 10 ms 237 | // it's very difficult to tell if the backlog is due to legitimate load or hung clients 238 | // hung clients don't eat CPU time so the server's CPU usage will skyrocket 239 | // but if it's due to load then sleeping for 100 ms is a terrible idea! 240 | // someone should take a look at this and rewrite it eventually 241 | 242 | UTIL_LogPrint( "Server Info - Max. connections reached\n" ); 243 | 244 | MILLISLEEP( 10 ); 245 | } 246 | 247 | // process the clients 248 | for( vector :: iterator itClient = m_vecClients.begin( ); itClient != m_vecClients.end( ); ) 249 | { 250 | if( (*itClient)->Update( ) ) 251 | { 252 | delete *itClient; 253 | 254 | itClient = m_vecClients.erase( itClient ); 255 | } 256 | else 257 | itClient++; 258 | } 259 | 260 | if( m_pTracker ) 261 | m_pTracker->Update( ); 262 | 263 | return m_bKill; 264 | } 265 | 266 | CTracker *CServer :: getTracker( ) 267 | { 268 | return m_pTracker; 269 | } 270 | 271 | bool CServer :: AddListener( struct sockaddr_in sin ) 272 | { 273 | SOCKET sckListener; 274 | 275 | // map protocol name to protocol number 276 | 277 | struct protoent *pPE; 278 | 279 | pPE = getprotobyname( "tcp" ); 280 | 281 | if( pPE == 0 ) 282 | { 283 | UTIL_LogPrint( ( gmapLANG_CFG["no_tcp_protocol"] + "\n" ).c_str( ), GetLastErrorString( ) ); 284 | 285 | return false; 286 | } 287 | 288 | // allocate socket 289 | 290 | sckListener = socket( PF_INET, SOCK_STREAM, pPE->p_proto ); 291 | 292 | if( sckListener == INVALID_SOCKET ) 293 | { 294 | UTIL_LogPrint( ( gmapLANG_CFG["not_allocated_socket"] + "\n" ).c_str( ), GetLastErrorString( ) ); 295 | 296 | return false; 297 | } 298 | 299 | #ifdef WIN32 300 | const unsigned int cuiOptVal( 1 ); 301 | 302 | // TCP window size 303 | // Send 304 | if( setsockopt( sckListener, SOL_SOCKET, SO_SNDBUF, (const char *)&guiSO_SNDBUF, sizeof(guiSO_SNDBUF) ) == SOCKET_ERROR ) 305 | UTIL_LogPrint( ( gmapLANG_CFG["no_sndbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 306 | 307 | // Receive 308 | if( setsockopt( sckListener, SOL_SOCKET, SO_RCVBUF, (const char *)&guiSO_RECBUF, sizeof(guiSO_RECBUF) ) == SOCKET_ERROR ) 309 | UTIL_LogPrint( ( gmapLANG_CFG["no_rcvbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 310 | 311 | // Allows the socket to be bound to an address that is already in use. 312 | if( setsockopt( sckListener, SOL_SOCKET, SO_REUSEADDR, (const char *)&cuiOptVal, sizeof( cuiOptVal ) ) == SOCKET_ERROR ) 313 | UTIL_LogPrint( ( gmapLANG_CFG["no_reuseaddr"] + "\n" ).c_str( ), GetLastErrorString( ) ); 314 | 315 | // Naggle's Algorithm 316 | if( setsockopt( sckListener, SOL_SOCKET, TCP_NODELAY, (const char *)&gbTCP_NODELAY, sizeof( int ) ) == SOCKET_ERROR ) 317 | UTIL_LogPrint( ( gmapLANG_CFG["no_nodelay"] + "\n" ).c_str( ), GetLastErrorString( ) ); 318 | 319 | // bind socket 320 | if( bind( sckListener, (SOCKADDR*)&sin, sizeof( sin ) ) == SOCKET_ERROR ) 321 | { 322 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_bind_socket"] + "\n" ).c_str( ), GetLastErrorString( ) ); 323 | 324 | return false; 325 | } 326 | #else 327 | const unsigned int cuiOptVal( 1 ); 328 | 329 | #ifdef SO_NOSIGPIPE 330 | // Ignore SIGPIPE - FreeBSD 331 | if( setsockopt( sckListener, SOL_SOCKET, SO_NOSIGPIPE, (const void *)&cuiOptVal, (socklen_t)sizeof( cuiOptVal ) ) == SOCKET_ERROR ) 332 | UTIL_LogPrint( ( gmapLANG_CFG["no_nosigpipe"] + "\n" ).c_str( ), GetLastErrorString( ) ); 333 | #endif 334 | 335 | #ifdef SO_SNDBUF 336 | // TCP window size Send 337 | if( setsockopt( sckListener, SOL_SOCKET, SO_SNDBUF, (const char *)&guiSO_SNDBUF, (socklen_t)sizeof( guiSO_SNDBUF ) ) == SOCKET_ERROR ) 338 | UTIL_LogPrint( ( gmapLANG_CFG["no_sndbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 339 | #endif 340 | 341 | #ifdef SO_RCVBUF 342 | // TCP window size Receive 343 | if( setsockopt( sckListener, SOL_SOCKET, SO_RCVBUF, (const char *)&guiSO_RECBUF, (socklen_t)sizeof( guiSO_RECBUF ) ) == SOCKET_ERROR ) 344 | UTIL_LogPrint( ( gmapLANG_CFG["no_rcvbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 345 | #endif 346 | 347 | #ifdef SO_REUSEADDR 348 | // Allows the socket to be bound to an address that is already in use. 349 | if( setsockopt( sckListener, SOL_SOCKET, SO_REUSEADDR, (const void *)&cuiOptVal, (socklen_t)sizeof( cuiOptVal ) ) == SOCKET_ERROR ); 350 | UTIL_LogPrint( ( gmapLANG_CFG["no_reuseaddr"] + "\n" ).c_str( ), GetLastErrorString( ) ); 351 | #endif 352 | 353 | #ifdef TCP_NODELAY 354 | // Nagle's Algorithm 355 | if( setsockopt( sckListener, SOL_SOCKET, TCP_NODELAY, (const char *)&gbTCP_NODELAY, (socklen_t)sizeof( int ) ) == SOCKET_ERROR ) 356 | UTIL_LogPrint( ( gmapLANG_CFG["no_nodelay"] + "\n" ).c_str( ), GetLastErrorString( ) ); 357 | #endif 358 | 359 | // bind 360 | if( bind( sckListener, (struct sockaddr *)&sin, sizeof( sin ) ) == SOCKET_ERROR ) 361 | { 362 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_bind_socket"] + "\n" ).c_str( ), GetLastErrorString( ) ); 363 | 364 | return false; 365 | } 366 | #endif 367 | 368 | // listen on the socket 369 | if( listen( sckListener, 1 ) == SOCKET_ERROR ) 370 | { 371 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_listen"] + "\n" ).c_str( ), GetLastErrorString( ) ); 372 | 373 | return false; 374 | } 375 | 376 | // Add the socket to the vector of sockets 377 | m_vecListeners.push_back( sckListener ); 378 | 379 | return true; 380 | } 381 | -------------------------------------------------------------------------------- /src/tracker_scrape.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | #include "bnbt.h" 23 | #include "bnbt_mysql.h" 24 | #include "atom.h" 25 | #include "bencode.h" 26 | #include "config.h" 27 | #include "tracker.h" 28 | #include "util.h" 29 | 30 | void CTracker :: serverResponseScrape( struct request_t *pRequest, struct response_t *pResponse ) 31 | { 32 | if( gbDebug ) 33 | if( gucDebugLevel & DEBUG_SCRAPE ) 34 | UTIL_LogPrint( "serverResponseScrape: started\n" ); 35 | 36 | // Is scrape allowed? 37 | if( !m_bAllowScrape ) 38 | { 39 | if( gbDebug ) 40 | if( gucDebugLevel & DEBUG_SCRAPE ) 41 | UTIL_LogPrint( "serverResponseScrape: scrape (disabled)\n" ); 42 | 43 | pResponse->strCode = "403 " + gmapLANG_CFG["server_response_403"]; 44 | 45 | gtXStats.scrape.iDisallowed++; 46 | 47 | if( gbDebug ) 48 | if( gucDebugLevel & DEBUG_SCRAPE ) 49 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 50 | 51 | return; 52 | } 53 | 54 | // Authorise scrape 55 | if( m_ucAuthScrapeAccess != 0 ) 56 | { 57 | if( gbDebug ) 58 | if( gucDebugLevel & DEBUG_SCRAPE ) 59 | UTIL_LogPrint( "serverResponseScrape: authorise (enabled)\n" ); 60 | 61 | if( !( pRequest->user.ucAccess & m_ucAuthScrapeAccess ) ) 62 | { 63 | pResponse->strCode = "401 " + gmapLANG_CFG["server_response_401"]; 64 | pResponse->mapHeaders.insert( pair( "Content-Type", gmapMime[".txt"] ) ); 65 | pResponse->mapHeaders.insert( pair( "WWW-Authenticate", string( "Basic realm=\"" ) + gstrRealm + "\"" ) ); 66 | pResponse->strContent = UTIL_FailureReason( gmapLANG_CFG["server_response_401"] ); 67 | pResponse->bCompressOK = false; 68 | 69 | gtXStats.scrape.iNotAuthorized++; 70 | 71 | if( gbDebug ) 72 | { 73 | if( gucDebugLevel & DEBUG_SCRAPE ) 74 | { 75 | UTIL_LogPrint( "serverResponseScrape: authorisation failed\n" ); 76 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 77 | } 78 | } 79 | 80 | return; 81 | } 82 | 83 | if( gbDebug ) 84 | if( gucDebugLevel & DEBUG_SCRAPE ) 85 | UTIL_LogPrint( "serverResponseScrape: authorisation passed\n" ); 86 | } 87 | 88 | // Set the HTTP code, headers and compession 89 | pResponse->strCode = "200 " + gmapLANG_CFG["server_response_200"]; 90 | pResponse->mapHeaders.insert( pair( "Content-Type", gmapMime[".txt"] ) ); 91 | pResponse->bCompressOK = true; 92 | 93 | // Verify that the IP is permitted to access the tracker 94 | if( m_ucIPBanMode != 0) 95 | { 96 | if( gbDebug ) 97 | if( gucDebugLevel & DEBUG_SCRAPE ) 98 | UTIL_LogPrint( "serverResponseScrape: IP banning (enabled)\n" ); 99 | 100 | // retrieve ip 101 | 102 | const string strTempIP( pRequest->mapParams["ip"] ); 103 | 104 | const string cstrIPConv( pRequest->strIP.c_str( ) ); 105 | 106 | switch( m_ucIPBanMode ) 107 | { 108 | case IP_BLACKLIST: 109 | if( UTIL_IsIPBanList( pRequest->strIP, m_pIPBannedList ) || UTIL_IsIPBanList( strTempIP, m_pIPBannedList ) ) 110 | { 111 | if( gbDebug ) 112 | if( gucDebugLevel & DEBUG_SCRAPE ) 113 | UTIL_LogPrint( "serverResponseScrape: IP blacklisted\n" ); 114 | 115 | pResponse->strContent = UTIL_FailureReason( gmapLANG_CFG["announce_ip_banned"] ); 116 | pResponse->bCompressOK = false; 117 | 118 | gtXStats.scrape.iNotAuthorized++; 119 | 120 | if( gbDebug ) 121 | if( gucDebugLevel & DEBUG_SCRAPE ) 122 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 123 | 124 | return; 125 | } 126 | 127 | break; 128 | case IP_VIPLIST: 129 | if( UTIL_IsIPBanList( pRequest->strIP, m_pIPBannedList ) || UTIL_IsIPBanList( strTempIP, m_pIPBannedList ) ) 130 | { 131 | if( gbDebug ) 132 | if( gucDebugLevel & DEBUG_SCRAPE ) 133 | UTIL_LogPrint( "serverResponseScrape: IP not cleared\n" ); 134 | 135 | pResponse->strContent = UTIL_FailureReason( gmapLANG_CFG["announce_ip_not_cleared"] ); 136 | pResponse->bCompressOK = false; 137 | 138 | gtXStats.scrape.iNotAuthorized++; 139 | 140 | if( gbDebug ) 141 | if( gucDebugLevel & DEBUG_SCRAPE ) 142 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 143 | 144 | return; 145 | } 146 | 147 | break; 148 | default: 149 | if( gbDebug ) 150 | if( gucDebugLevel & DEBUG_SCRAPE ) 151 | UTIL_LogPrint( "serverResponseScrape: IP banning method unknown (disabled)\n" ); 152 | } 153 | } 154 | else 155 | { 156 | if( gbDebug ) 157 | if( gucDebugLevel & DEBUG_SCRAPE ) 158 | UTIL_LogPrint( "serverResponseScrape: IP banning (disabled)\n" ); 159 | } 160 | 161 | // Peer ID/User Agent banning 162 | if( m_ucBanMode != 0 ) 163 | { 164 | if( gbDebug ) 165 | if( gucDebugLevel & DEBUG_SCRAPE ) 166 | UTIL_LogPrint( "serverResponseScrape: user agent banning (enabled)\n" ); 167 | 168 | string strUserAgent = string( ); 169 | 170 | const string strUserAgentA( pRequest->mapHeaders["User-Agent"] ); 171 | const string strUserAgentB( pRequest->mapHeaders["User-agent"] ); 172 | const string cstrPeerID( pRequest->mapParams["peer_id"] ); 173 | 174 | if( strUserAgentA.empty( ) && strUserAgentB.empty( ) ) 175 | strUserAgent = string( ); 176 | else if( strUserAgentA == strUserAgentB ) 177 | strUserAgent = strUserAgentA; 178 | else 179 | { 180 | if( !strUserAgentA.empty( ) && strUserAgentB.empty( ) ) 181 | strUserAgent = strUserAgentA; 182 | else if( strUserAgentA.empty( ) && !strUserAgentB.empty( ) ) 183 | strUserAgent = strUserAgentB; 184 | else if( !strUserAgentA.empty( ) && !strUserAgentB.empty( ) ) 185 | strUserAgent = strUserAgentB + "; spoof( " + strUserAgentA + " )"; 186 | } 187 | 188 | bool bClientBanned = UTIL_IsClientBanList( strUserAgent, m_pClientBannedList, true ); 189 | 190 | if( !bClientBanned ) 191 | bClientBanned = UTIL_IsClientBanList( cstrPeerID, m_pClientBannedList, false ); 192 | 193 | switch( m_ucBanMode ) 194 | { 195 | case ID_BLACKLIST: 196 | if ( bClientBanned ) 197 | { 198 | if( gbDebug ) 199 | if( gucDebugLevel & DEBUG_SCRAPE ) 200 | UTIL_LogPrint( "serverResponseScrape: ID or user agent blacklisted\n" ); 201 | 202 | pResponse->strContent = UTIL_FailureReason( gmapLANG_CFG["announce_client_banned"] ); 203 | pResponse->bCompressOK = false; 204 | 205 | gtXStats.scrape.iNotAuthorized++; 206 | 207 | if( gbDebug ) 208 | if( gucDebugLevel & DEBUG_SCRAPE ) 209 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 210 | 211 | return; 212 | } 213 | 214 | break; 215 | case ID_VIPLIST: 216 | if ( bClientBanned ) 217 | { 218 | if( gbDebug ) 219 | if( gucDebugLevel & DEBUG_SCRAPE ) 220 | UTIL_LogPrint( "serverResponseScrape: ID or user agent not cleared\n" ); 221 | 222 | pResponse->strContent = UTIL_FailureReason( gmapLANG_CFG["announce_client_banned"] ); 223 | pResponse->bCompressOK = false; 224 | 225 | gtXStats.scrape.iNotAuthorized++; 226 | 227 | if( gbDebug && ( gucDebugLevel & DEBUG_SCRAPE ) ) 228 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 229 | 230 | return; 231 | } 232 | 233 | break; 234 | default: 235 | if( gbDebug ) 236 | if( gucDebugLevel & DEBUG_SCRAPE ) 237 | UTIL_LogPrint( "serverResponseScrape: ID or user agent banning mode unknown (disabled)\n" ); 238 | } 239 | } 240 | else 241 | { 242 | if( gbDebug ) 243 | if( gucDebugLevel & DEBUG_SCRAPE ) 244 | UTIL_LogPrint( "serverResponseScrape: ID or user agent banning (disabled)\n" ); 245 | } 246 | 247 | // Refresh the fast cache 248 | // if( GetTime( ) > m_ulRefreshFastCacheNext ) 249 | // { 250 | // // Refresh 251 | // RefreshFastCache( ); 252 | 253 | // // Set the next refresh time 254 | // m_ulRefreshFastCacheNext = GetTime( ) + m_uiRefreshFastCacheInterval; 255 | // } 256 | 257 | // Create the dictionaries 258 | CAtomDicti *pScrape = new CAtomDicti( ); 259 | CAtomDicti *pFiles = new CAtomDicti( ); 260 | CAtomDicti *pFlags = new CAtomDicti( ); 261 | 262 | // Add the files and flags dictionaries to the scrape dictionary 263 | pScrape->setItem( "files", pFiles ); 264 | pScrape->setItem( "flags", pFlags ); 265 | 266 | // Set the minimum scrape request interval flag 267 | pFlags->setItem( "min_request_interval", new CAtomLong( m_uiMinRequestInterval ) ); 268 | 269 | CAtomDicti *pTorrent = 0; 270 | 271 | CMySQLQuery *pQuery = 0; 272 | 273 | vector vecQuery; 274 | vecQuery.reserve( 5 ); 275 | 276 | if ( !pRequest->hasQuery ) 277 | { 278 | // 279 | // full scrape 280 | // 281 | 282 | if( gbDebug ) 283 | if( gucDebugLevel & DEBUG_SCRAPE ) 284 | UTIL_LogPrint( "serverResponseScrape: no query, full scrape\n" ); 285 | 286 | pQuery = new CMySQLQuery( "SELECT bseeders,bleechers,bcompleted,bhash,bname FROM allowed" ); 287 | 288 | vecQuery = pQuery->nextRow( ); 289 | 290 | while( vecQuery.size( ) == 5 ) 291 | { 292 | pTorrent = new CAtomDicti( ); 293 | 294 | pTorrent->setItem( "complete", new CAtomInt( atoi( vecQuery[0].c_str( ) ) ) ); 295 | pTorrent->setItem( "incomplete", new CAtomInt( atoi( vecQuery[1].c_str( ) ) ) ); 296 | pTorrent->setItem( "downloaded", new CAtomInt( atoi( vecQuery[2].c_str( ) ) ) ); 297 | 298 | if( !vecQuery[4].empty( ) ) 299 | pTorrent->setItem( "name", new CAtomString( vecQuery[4] ) ); 300 | 301 | pFiles->setItem( vecQuery[3], pTorrent ); 302 | 303 | vecQuery = pQuery->nextRow( ); 304 | } 305 | 306 | delete pQuery; 307 | 308 | pResponse->strContent = Encode( pScrape ); 309 | 310 | delete pScrape; 311 | 312 | gtXStats.scrape.iFull++; 313 | 314 | if( gbDebug ) 315 | { 316 | if( gucDebugLevel & DEBUG_SCRAPE ) 317 | { 318 | UTIL_LogPrint( "serverResponseScrape: %s\n", pResponse->strContent.c_str( ) ); 319 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 320 | } 321 | } 322 | 323 | return; 324 | } 325 | else 326 | { 327 | // 328 | // single scrape 329 | // 330 | 331 | if( gbDebug ) 332 | if( gucDebugLevel & DEBUG_SCRAPE ) 333 | UTIL_LogPrint( "serverResponseScrape: has a query\n" ); 334 | 335 | // Initialise the mySQL query string before the loop 336 | string strQuery = string( ); 337 | 338 | unsigned int uiCount = 0; 339 | 340 | // Begin the multi hash scrape loop 341 | for( multimap :: iterator itInfoHash = pRequest->multiParams.lower_bound( "info_hash" ); itInfoHash != pRequest->multiParams.upper_bound( "info_hash" ); itInfoHash++ ) 342 | { 343 | strQuery = "SELECT bseeders,bleechers,bcompleted,bname FROM allowed WHERE bhash=\'" + UTIL_StringToMySQL( (*itInfoHash).second.c_str( ) ) + "\'"; 344 | 345 | pQuery = new CMySQLQuery( strQuery ); 346 | 347 | vecQuery.reserve(4); 348 | 349 | vecQuery = pQuery->nextRow( ); 350 | 351 | if( vecQuery.size( ) == 4 ) 352 | { 353 | pTorrent = new CAtomDicti( ); 354 | 355 | pTorrent->setItem( "complete", new CAtomInt( atoi( vecQuery[0].c_str( ) ) ) ); 356 | pTorrent->setItem( "incomplete", new CAtomInt( atoi( vecQuery[1].c_str( ) ) ) ); 357 | pTorrent->setItem( "downloaded", new CAtomInt( atoi( vecQuery[2].c_str( ) ) ) ); 358 | 359 | if( !vecQuery[3].empty( ) ) 360 | pTorrent->setItem( "name", new CAtomString( vecQuery[3] ) ); 361 | 362 | pFiles->setItem( (*itInfoHash).second , pTorrent ); 363 | } 364 | 365 | delete pQuery; 366 | 367 | uiCount++; 368 | } 369 | 370 | pResponse->strContent = Encode( pScrape ); 371 | 372 | delete pScrape; 373 | 374 | if( gbDebug ) 375 | { 376 | if( gucDebugLevel & DEBUG_SCRAPE ) 377 | { 378 | UTIL_LogPrint( "serverResponseScrape: torrents scraped(%u)\n", uiCount ); 379 | UTIL_LogPrint( "serverResponseScrape: %s\n", pResponse->strContent.c_str( ) ); 380 | } 381 | } 382 | 383 | if( uiCount == 1 ) 384 | gtXStats.scrape.iSingle++; 385 | else if( uiCount > 1 ) 386 | gtXStats.scrape.iMultiple++; 387 | } 388 | 389 | if( gbDebug ) 390 | if( gucDebugLevel & DEBUG_SCRAPE ) 391 | UTIL_LogPrint( "serverResponseScrape: completed\n" ); 392 | } 393 | -------------------------------------------------------------------------------- /bnbt.cfg.sample: -------------------------------------------------------------------------------- 1 | allowed_dir = torrents 2 | announce_interval = 900 3 | bind = 4 | bnbt_access_admin = 32 5 | bnbt_access_allow_offers = 16 6 | bnbt_access_bookmark = 2 7 | bnbt_access_comments = 4 8 | bnbt_access_comments_always = 16 9 | bnbt_access_comments_to_message = 8 10 | bnbt_access_create_users = 32 11 | bnbt_access_del_comments = 16 12 | bnbt_access_del_offers = 16 13 | bnbt_access_del_own = 1 14 | bnbt_access_del_torrents = 16 15 | bnbt_access_del_users = 32 16 | bnbt_access_down_announce = 2 17 | bnbt_access_down_torrents = 2 18 | bnbt_access_dump_xml = 32 19 | bnbt_access_edit_admins = 64 20 | bnbt_access_edit_comments = 16 21 | bnbt_access_edit_offers = 16 22 | bnbt_access_edit_own = 1 23 | bnbt_access_edit_torrents = 16 24 | bnbt_access_edit_users = 32 25 | bnbt_access_invites = 8 26 | bnbt_access_log_dir = 27 | bnbt_access_log_file_pattern = %Y-%m-%da.log 28 | bnbt_access_messages = 1 29 | bnbt_access_req = 2 30 | bnbt_access_rss = 1 31 | bnbt_access_show_ip = 16 32 | bnbt_access_signup = 1 33 | bnbt_access_signup_direct = 32 34 | bnbt_access_sort_ip = 32 35 | bnbt_access_upload_offers = 4 36 | bnbt_access_upload_posts = 32 37 | bnbt_access_upload_torrents = 8 38 | bnbt_access_user_detail = 16 39 | bnbt_access_view = 1 40 | bnbt_access_view_log = 32 41 | bnbt_access_view_offers = 1 42 | bnbt_access_view_stats = 1 43 | bnbt_access_view_torrents = 1 44 | bnbt_access_view_users = 16 45 | bnbt_access_view_xstates = 32 46 | bnbt_allow_comments = 1 47 | bnbt_allow_info_link = 0 48 | bnbt_allow_magnet_downloads = 0 49 | bnbt_allow_scrape = 1 50 | bnbt_allow_search = 1 51 | bnbt_allow_serve_local = 1 52 | bnbt_allow_sort = 1 53 | bnbt_allow_torrent_downloads = 1 54 | bnbt_announce_access_required = 0 55 | bnbt_announce_list_enable = 1 56 | bnbt_announcements_max = 3 57 | bnbt_archive_dir = 58 | bnbt_bonus_trade_enable = 1 59 | bnbt_bonus_trade_rate = 100 60 | bnbt_bonus_trade_ratio_limit = 5.0 61 | bnbt_charset = utf-8 62 | bnbt_comment_length = 800 63 | bnbt_compression_level = 6 64 | bnbt_count_unique_peers = 1 65 | bnbt_custom_announce = 66 | bnbt_custom_scrape = 67 | bnbt_debug = 0 68 | bnbt_debug_level = 9 69 | bnbt_delete_invalid = 0 70 | bnbt_delete_own_torrents = 1 71 | bnbt_dump_xml_dir = stylesheets 72 | bnbt_dump_xml_file = filedump.xml 73 | bnbt_dump_xml_interval = 600 74 | bnbt_dump_xml_peers = 1 75 | bnbt_dump_xml_url = 76 | bnbt_encodes = xvid|x264|mp3|ape|flac 77 | bnbt_error_log_dir = 78 | bnbt_error_log_file_pattern = %Y-%m-%de.log 79 | bnbt_external_torrent_dir = 80 | bnbt_faq_dir = faq 81 | bnbt_file_dir = files 82 | bnbt_file_expires = 1440 83 | bnbt_flush_interval = 100 84 | bnbt_force_announce_on_download = 1 85 | bnbt_force_announce_on_upload = 1 86 | bnbt_force_announce_url = http://yourdomain/announce 87 | bnbt_free_down_global = 0 88 | bnbt_free_global = 0 89 | bnbt_free_rule_1 = 101||!rmvb !flv ![rm]|0|100|100|0|100|3 90 | bnbt_free_rule_10 = 401 501 601||!rmvb !flv !f4v ![rm]|4|50|100|0|100|9 91 | bnbt_free_rule_11 = 401 501 601||!rmvb !flv !f4v ![rm]|8|30|100|0|100|12 92 | bnbt_free_rule_12 = 105 201 202 203 204 205 206 305||!rmvb !flv ![rm]|0|100|100|0|100|3 93 | bnbt_free_rule_13 = 105 201 202 203 204 205 206 305|720p 720a|!rmvb !flv ![rm]|0|50|100|0|100|6 94 | bnbt_free_rule_14 = 105 201 202 203 204 205 206 305|1080p 1080i|!rmvb !flv ![rm]|0|30|100|0|100|9 95 | bnbt_free_rule_2 = 102|||0|50|100|0|100|6 96 | bnbt_free_rule_3 = 103|||0|30|100|0|100|9 97 | bnbt_free_rule_4 = 104|||0|30|100|0|100|12 98 | bnbt_free_rule_5 = 701|||0|0|100|100|100|0 99 | bnbt_free_rule_6 = 301 302 303 304 305 306|ape flac wav|!mp3|0|100|100|0|100|3 100 | bnbt_free_rule_7 = 105||!rmvb !flv ![rm]|0|100|100|0|100|3 101 | bnbt_free_rule_8 = 401 501 601||!rmvb !flv !f4v ![rm]|1|100|100|0|100|3 102 | bnbt_free_rule_9 = 401 501 601||!rmvb !flv !f4v ![rm]|2|100|100|0|100|6 103 | bnbt_free_rule_down_default = 100 104 | bnbt_free_rule_time_default = 0 105 | bnbt_free_rule_up_default = 100 106 | bnbt_free_up_global = 100 107 | bnbt_get_seed_bonus_interval = 300 108 | bnbt_guest_access = 1 109 | bnbt_hot_count = 20 110 | bnbt_hot_day = 3 111 | bnbt_info_access_required = 0 112 | bnbt_invite_enable = 1 113 | bnbt_ipv6_enable = 1 114 | bnbt_language = zh 115 | bnbt_listen_backlog = 32 116 | bnbt_log_dir = log 117 | bnbt_log_file_pattern = %Y-%m-%d.log 118 | bnbt_log_show_day = 3 119 | bnbt_max_conns = 2048 120 | bnbt_max_peers_display = 500 121 | bnbt_max_recv_size = 3145728 122 | bnbt_max_torrents = 0 123 | bnbt_max_users = 29999 124 | bnbt_mediums = dvdrip|hdtv|bdrip|bluray 125 | bnbt_member_access = 7 126 | bnbt_message_length = 800 127 | bnbt_name_length = 16 128 | bnbt_new_interval_default = 3600 129 | bnbt_new_interval_min = 300 130 | bnbt_new_torrent_interval = 60 131 | bnbt_new_user_gift_bonus = 0 132 | bnbt_new_user_gift_downloaded = 0 133 | bnbt_new_user_gift_uploaded = 0 134 | bnbt_parse_on_start = 0 135 | bnbt_parse_on_upload = 1 136 | bnbt_password_key = SET YOUR OWN PASSWORD KEY 137 | bnbt_per_page = 50 138 | bnbt_pid_file = xbnbt.pid 139 | bnbt_private_tracker_flag = 0 140 | bnbt_public_option = 0 141 | bnbt_public_upload_dir = 142 | bnbt_qualities = 720p|1080i|1080p 143 | bnbt_rating = 144 | bnbt_ratio_day_limit = 1 145 | bnbt_ratio_restrict = 1 146 | bnbt_realm = XBNBT 147 | bnbt_refresh_config_interval = 60 148 | bnbt_refresh_fast_cache_interval = 30 149 | bnbt_refresh_imdb_interval = 1 150 | bnbt_refresh_static_interval = 10 151 | bnbt_restart_interval = 0 152 | bnbt_robots_txt = robots/robots.txt 153 | bnbt_rss_channel_copyright = 154 | bnbt_rss_channel_image_height = 0 155 | bnbt_rss_channel_image_url = favicon.ico 156 | bnbt_rss_channel_image_width = 0 157 | bnbt_rss_channel_managingeditor = 158 | bnbt_rss_channel_ttl = 60 159 | bnbt_rss_directory = stylesheets 160 | bnbt_rss_file = rss.html 161 | bnbt_rss_file_mode = 0 162 | bnbt_rss_interval = 30 163 | bnbt_rss_limit = 25 164 | bnbt_rss_online_dir = 165 | bnbt_rss_top_ten_file = topten.xml 166 | bnbt_rules_dir = rules 167 | bnbt_scrape_access_required = 0 168 | bnbt_share_control_down = 300|200|120|60|30|0 169 | bnbt_share_control_ratio = 0.7|0.6|0.5|0.4|0.3|-2 170 | bnbt_show_added = 1 171 | bnbt_show_added_index = 1 172 | bnbt_show_average_dl_rate = 1 173 | bnbt_show_average_left = 0 174 | bnbt_show_average_ul_rate = 1 175 | bnbt_show_completed = 1 176 | bnbt_show_file_comment = 0 177 | bnbt_show_file_contents = 1 178 | bnbt_show_gen_time = 0 179 | bnbt_show_header_footer = 1 180 | bnbt_show_info_hash = 0 181 | bnbt_show_left_as_progress = 0 182 | bnbt_show_max_left = 0 183 | bnbt_show_min_left = 0 184 | bnbt_show_navbar = 1 185 | bnbt_show_num_files = 0 186 | bnbt_show_peer_info = 3 187 | bnbt_show_share_ratios = 1 188 | bnbt_show_size = 1 189 | bnbt_show_stats = 1 190 | bnbt_show_transferred = 0 191 | bnbt_show_uploader = 1 192 | bnbt_show_uploader_ip = 0 193 | bnbt_show_validator = 0 194 | bnbt_signup_lily_enable = 0 195 | bnbt_static_footer = html/footer.html 196 | bnbt_static_header = html/header.html 197 | bnbt_stats_dump_interval = 300 198 | bnbt_stats_file = database/stats.bnbt 199 | bnbt_style_sheet = xbnbt.css 200 | bnbt_style_sheet_dir = stylesheets 201 | bnbt_style_sheet_url = 202 | bnbt_tag101 = 电影 (标清)|files/tagsnew/Movies_SD.PNG|files/tagsnew/Movies_SD.PNG 203 | bnbt_tag102 = 电影 (720p)|files/tagsnew/Movies_720p.PNG|files/tagsnew/Movies_720p.PNG 204 | bnbt_tag103 = 电影 (1080p)|files/tagsnew/Movies_1080p.PNG|files/tagsnew/Movies_1080p.PNG 205 | bnbt_tag104 = 电影 (原盘)|files/tagsnew/Movies_BluRay.PNG|files/tagsnew/Movies_BluRay.PNG 206 | bnbt_tag105 = 纪录片|files/tagsnew/Documentaries.PNG|files/tagsnew/Documentaries.PNG 207 | bnbt_tag201 = 剧集 (欧美)|files/tagsnew/TV_Western.PNG|files/tagsnew/TV_Western.PNG 208 | bnbt_tag202 = 剧集 (大陆)|files/tagsnew/TV_Cn.PNG|files/tagsnew/TV_Cn.PNG 209 | bnbt_tag203 = 剧集 (港台)|files/tagsnew/TV_hk_tw.PNG|files/tagsnew/TV_hk_tw.PNG 210 | bnbt_tag204 = 剧集 (日韩)|files/tagsnew/TV_Japan_korea.PNG|files/tagsnew/TV_Japan_korea.PNG 211 | bnbt_tag205 = 电视 (综艺)|files/tagsnew/TV_Shows.PNG|files/tagsnew/TV_Shows.PNG 212 | bnbt_tag206 = 电视 (体育)|files/tagsnew/TV_Sports.PNG|files/tagsnew/TV_Sports.PNG 213 | bnbt_tag301 = 音乐 (华语)|files/tagsnew/Music_Cn.PNG|files/tagsnew/Music_Cn.PNG 214 | bnbt_tag302 = 音乐 (欧美)|files/tagsnew/Music_Western.PNG|files/tagsnew/Music_Western.PNG 215 | bnbt_tag303 = 音乐 (日韩)|files/tagsnew/Music_Asia.PNG|files/tagsnew/Music_Asia.PNG 216 | bnbt_tag304 = 音乐 (古典)|files/tagsnew/Music_Classic.PNG|files/tagsnew/Music_Classic.PNG 217 | bnbt_tag305 = 音乐 (MV)|files/tagsnew/Music_Video.PNG|files/tagsnew/Music_Video.PNG 218 | bnbt_tag306 = 音乐 (其它)|files/tagsnew/Music_Others.PNG|files/tagsnew/Music_Others.PNG 219 | bnbt_tag401 = 动漫|files/tagsnew/Animations.PNG|files/tagsnew/Animations.PNG 220 | bnbt_tag501 = 游戏|files/tagsnew/Games.PNG|files/tagsnew/Games.PNG 221 | bnbt_tag601 = 软件|files/tagsnew/Applications.PNG|files/tagsnew/Applications.PNG 222 | bnbt_tag701 = 学习|files/tagsnew/Studies.PNG|files/tagsnew/Studies.PNG 223 | bnbt_tag801 = 图片|files/tagsnew/Pictures.PNG|files/tagsnew/Pictures.PNG 224 | bnbt_tag901 = 其它|files/tagsnew/Others.PNG|files/tagsnew/Others.PNG 225 | bnbt_talk_length = 140 226 | bnbt_thanks_bonus = 3 227 | bnbt_timer_interval = 3600 228 | bnbt_tlink_bind = 229 | bnbt_tlink_connect = 230 | bnbt_tlink_password = 231 | bnbt_tlink_port = 5204 232 | bnbt_tlink_server = 0 233 | bnbt_torrent_expires = 180 234 | bnbt_tracker_description = Powered by XBNBT ZiJing Mod 235 | bnbt_tracker_fqdn = 236 | bnbt_tracker_keywords = bittorrent, torrent, tracker, XBNBT 237 | bnbt_tracker_source = XBNBT 238 | bnbt_tracker_subtitle = 基于IPv6的简单高效分享平台 239 | bnbt_tracker_title = XBNBT 240 | bnbt_upload_dir = torrents 241 | bnbt_uploader_bonus_quota = 10 242 | bnbt_uploader_bonus_size_unit_mb = 10 243 | bnbt_use_announce_key = 1 244 | bnbt_use_mouseovers = 0 245 | bnbt_users_per_page = 50 246 | bnbt_webmaster = 247 | cbtt_ban_file = database/clientbans.bnbt 248 | cbtt_ban_mode = 2 249 | cbtt_blacklist_common_p2p_ports = 0 250 | cbtt_block_private_ip = 1 251 | cbtt_block_search_robots = 0 252 | cbtt_dont_compress_torrents = 1 253 | cbtt_ip_ban_mode = 1 254 | cbtt_ipban_file = database/bans.bnbt 255 | cbtt_ipblock_file = database/blocks.bnbt 256 | cbtt_restrict_overflow = 0 257 | cbtt_restrict_overflow_limit = 1099511627776 258 | cbtt_restricted_peer_spoofing = 0 259 | cbtt_service_name = BNBT Service 260 | downloader_timeout_interval = 1800 261 | favicon = favicon.ico 262 | favicon_dir = images 263 | image_bar_dir = images 264 | image_bar_fill = imagebarfill.png 265 | image_bar_trans = imagebartrans.png 266 | image_bar_url = 267 | keep_dead = 1 268 | max_give = 200 269 | min_request_interval = 1800 270 | mysql_cbtt_ttrader_support = 0 271 | mysql_database = bnbt 272 | mysql_host = localhost 273 | mysql_override_dstate = 0 274 | mysql_password = 275 | mysql_port = 3306 276 | mysql_refresh_allowed_interval = 0 277 | mysql_refresh_stats_interval = 600 278 | mysql_user = xbnbt 279 | offer_dir = offer 280 | only_local_override_ip = 0 281 | parse_allowed_interval = 0 282 | port = 80 283 | response_size = 50 284 | save_dfile_interval = 300 285 | show_names = 1 286 | socket_timeout = 15 287 | userbar = userbar.png 288 | userbar_dir = images 289 | userbar_font_cn = /usr/share/fonts/truetype/yahei/YaHei.Consolas.1.11b.ttf 290 | userbar_font_en = /usr/share/fonts/truetype/msttcorefonts/trebuc.ttf 291 | userbar_user_color_admin = 75,0,130 292 | userbar_user_color_friends = 255,140,0 293 | userbar_user_color_leader = 160,82,45 294 | userbar_user_color_member = 0,0,0 295 | userbar_user_color_moderator = 0,102,255 296 | userbar_user_color_retired = 28,198,213 297 | userbar_user_color_share_warned = 112,128,144 298 | userbar_user_color_uploader = 220,20,60 299 | userbar_user_color_vip = 0,159,0 300 | xbnbt_announce_list1 = 301 | xbnbt_dynstat_background = 0 302 | xbnbt_dynstat_dir = database 303 | xbnbt_dynstat_file = dynstat.bnbt 304 | xbnbt_dynstat_font = 305 | xbnbt_dynstat_font_blue = 255 306 | xbnbt_dynstat_font_green = 255 307 | xbnbt_dynstat_font_red = 255 308 | xbnbt_dynstat_generate = 0 309 | xbnbt_dynstat_interval = 10 310 | xbnbt_dynstat_jpg_quality = -1 311 | xbnbt_dynstat_link = 312 | xbnbt_dynstat_output_type = 0 313 | xbnbt_dynstat_png_compress = -1 314 | xbnbt_dynstat_savemode = 0 315 | xbnbt_dynstat_showlink = 0 316 | xbnbt_dynstat_skin = 0 317 | xbnbt_dynstat_skinfile = 318 | xbnbt_dynstat_x_size = 350 319 | xbnbt_dynstat_y_size = 80 320 | xbnbt_mysqlusers_database = forum 321 | xbnbt_mysqlusers_forums_admin = admin 322 | xbnbt_mysqlusers_forums_link = http://localhost/forums/index.php?act=Reg 323 | xbnbt_mysqlusers_host = localhost 324 | xbnbt_mysqlusers_ignore_group1 = 1 325 | xbnbt_mysqlusers_ignore_group2 = 2 326 | xbnbt_mysqlusers_ignore_group3 = 5 327 | xbnbt_mysqlusers_interval = 10 328 | xbnbt_mysqlusers_mode = 0 329 | xbnbt_mysqlusers_override_users = 0 330 | xbnbt_mysqlusers_password = 331 | xbnbt_mysqlusers_port = 3306 332 | xbnbt_mysqlusers_table = ibf_members 333 | xbnbt_mysqlusers_table_email = email 334 | xbnbt_mysqlusers_table_group = mgroup 335 | xbnbt_mysqlusers_table_id = id 336 | xbnbt_mysqlusers_table_joined = joined 337 | xbnbt_mysqlusers_table_name = name 338 | xbnbt_mysqlusers_table_password = password 339 | xbnbt_mysqlusers_user = 340 | xbnbt_rss_valid_image = images/valid-rss.png 341 | xbnbt_so_recbuf = 128 342 | xbnbt_so_sndbuf = 128 343 | xbnbt_tcp_nodelay = 0 344 | xbnbt_thlink_bind = 345 | xbnbt_thlink_connect = 346 | xbnbt_thlink_password = 347 | xbnbt_thlink_port = 5205 348 | xbnbt_thlink_server = 0 349 | xbnbt_use_buttons = 0 350 | xbnbt_users_online = 1 351 | -------------------------------------------------------------------------------- /src/server.epoll.old.cpp: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * BNBT Beta 8.0 - A C++ BitTorrent Tracker 4 | * Copyright (C) 2003-2004 Trevor Hogan 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | ***/ 21 | 22 | // =Xotic= Modified Source File 23 | 24 | #ifndef WIN32 25 | #include 26 | #endif 27 | 28 | #include "bnbt.h" 29 | #include "atom.h" 30 | #include "client.h" 31 | #include "config.h" 32 | #include "server.h" 33 | #include "tracker.h" 34 | #include "util.h" 35 | 36 | #ifdef WIN32 37 | #include "util_ntservice.h" 38 | #endif 39 | 40 | CServer :: CServer( ) 41 | { 42 | m_vecClients.reserve( guiMaxConns ); 43 | 44 | m_bKill = false; 45 | 46 | m_uiSocketTimeOut = CFG_GetInt( "socket_timeout", 15 ); 47 | m_strBind = CFG_GetString( "bind", string( ) ); 48 | m_cCompression = (char)CFG_GetInt( "bnbt_compression_level", 6 ); 49 | 50 | // clamp compression 51 | 52 | if( m_cCompression > 9 ) 53 | m_cCompression = 9; 54 | 55 | struct sockaddr_in6 sin; 56 | 57 | memset( &sin, 0, sizeof( sin ) ); 58 | 59 | sin.sin6_family = AF_INET6; 60 | 61 | if( !m_strBind.empty( ) ) 62 | { 63 | // bind to m_strBind 64 | 65 | if( gbDebug && ( gucDebugLevel & DEBUG_SERVER ) ) 66 | UTIL_LogPrint( "server - binding to %s\n", m_strBind.c_str( ) ); 67 | 68 | if( inet_pton( AF_INET6, m_strBind.c_str( ), &sin.sin6_addr ) == NULL ) 69 | { 70 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_bind"] + "\n" ).c_str( ), m_strBind.c_str( ) ); 71 | 72 | exit( 1 ); 73 | } 74 | } 75 | else 76 | { 77 | // bind to all available addresses 78 | 79 | if( gbDebug && ( gucDebugLevel & DEBUG_SERVER ) ) 80 | UTIL_LogPrint( ( gmapLANG_CFG["binding_to_all"] + "\n" ).c_str( ) ); 81 | 82 | sin.sin6_addr = in6addr_any; 83 | } 84 | 85 | epfd = epoll_create(1024); 86 | 87 | // tphogan - legacy support, check for "port" config entry 88 | // by doing this here "port" will always be required 89 | // so in fact this isn't entirely legacy support since it'll continue to be used 90 | 91 | // sin.sin6_len = sizeof(sin); 92 | 93 | sin.sin6_port = htons( (u_short)CFG_GetInt( "port", 6969 ) ) ; 94 | 95 | if( sin.sin6_port == 0 ) 96 | UTIL_LogPrint( ( gmapLANG_CFG["binding_to_all"] + "\n" ).c_str( ), CAtomInt( CFG_GetInt( "port", 6969 ) ).toString( ).c_str( ) ); 97 | else if( !AddListener( sin ) ) 98 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_listen"] + "\n" ).c_str( ), CAtomInt( CFG_GetInt( "port", 6969 ) ).toString( ).c_str( ) ); 99 | else 100 | UTIL_LogPrint( ( gmapLANG_CFG["listen_on_port"] + "\n" ).c_str( ), CAtomInt( CFG_GetInt( "port", 6969 ) ).toString( ).c_str( ) ); 101 | 102 | // tphogan - retrieve list of ports from config file for multiport listeners 103 | // do we want to support multiple bindings as well? 104 | // this code will bind every socket to the same address 105 | 106 | unsigned char ucPort = 1; 107 | 108 | string strName = "port" + CAtomInt( ucPort ).toString( ); 109 | string strPort = CFG_GetString( strName, string( ) ); 110 | 111 | while( !strPort.empty( ) ) 112 | { 113 | sin.sin6_port = htons( (u_short)atoi( strPort.c_str( ) ) ) ; 114 | 115 | if( sin.sin6_port == 0 ) 116 | UTIL_LogPrint( ( gmapLANG_CFG["invalid_ports"] + "\n" ).c_str( ), strPort.c_str( ), strName.c_str( ) ); 117 | else if( !AddListener( sin ) ) 118 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_listens"] + "\n" ).c_str( ), strPort.c_str( ), strName.c_str( ) ); 119 | else 120 | UTIL_LogPrint( ( gmapLANG_CFG["listen_on_ports"] + "\n" ).c_str( ), strPort.c_str( ), strName.c_str( ) ); 121 | 122 | strName = "port" + CAtomInt( ++ucPort ).toString( ); 123 | strPort = CFG_GetString( strName, string( ) ); 124 | } 125 | 126 | // tphogan - we didn't exit on invalid ports above 127 | // so make sure we're listening on at least one valid port 128 | // however, since "port" is always forced greater than zero in CFG_SetDefaults 129 | // this should only happen if a valid port is denied for "port" 130 | // for example, address in use or not enough privs for ports < 1024 131 | 132 | if( m_vecListeners.empty( ) ) 133 | { 134 | UTIL_LogPrint( ( gmapLANG_CFG["not_listening"] + "\n" ).c_str( ) ); 135 | 136 | exit( 1 ); 137 | } 138 | 139 | m_pTracker = new CTracker( ); 140 | 141 | UTIL_LogPrint( ( gmapLANG_CFG["server_start"] + "\n" ).c_str( ) ); 142 | } 143 | 144 | CServer :: ~CServer( ) 145 | { 146 | for( vector :: iterator itListener = m_vecListeners.begin( ); itListener != m_vecListeners.end( ); itListener++ ) 147 | { 148 | closesocket( *itListener ); 149 | 150 | // ev.data.fd = *itListener; 151 | // 152 | // ev.events = EPOLLIN; 153 | // 154 | // epoll_ctl( epfd, EPOLL_CTL_DEL, *itListener, &ev ); 155 | } 156 | 157 | close( epfd ); 158 | 159 | for( vector :: iterator itClient = m_vecClients.begin( ); itClient != m_vecClients.end( ); itClient++ ) 160 | delete *itClient; 161 | 162 | m_vecListeners.clear( ); 163 | m_vecClients.clear( ); 164 | 165 | if( m_pTracker ) 166 | delete m_pTracker; 167 | 168 | m_pTracker = 0; 169 | 170 | UTIL_LogPrint( ( gmapLANG_CFG["server_exit"] + "\n" ).c_str( ) ); 171 | } 172 | 173 | void CServer :: Kill( ) 174 | { 175 | m_bKill = true; 176 | } 177 | 178 | bool CServer :: isDying( ) 179 | { 180 | return m_bKill; 181 | } 182 | 183 | bool CServer :: Update( const bool &bBlock ) 184 | { 185 | if( m_vecClients.size( ) < guiMaxConns ) 186 | { 187 | // tphogan - check every listener for new connections 188 | 189 | // struct timeval tv; 190 | struct sockaddr_in6 adrFrom; 191 | int iAddrLen = 0; 192 | SOCKET sckClient = 0; 193 | 194 | // nfds = epoll_wait( epfd, events, guiMaxConns, 100 ); 195 | 196 | // if( bBlock ) 197 | // MILLISLEEP( 10 ); 198 | 199 | nfds = epoll_wait( epfd, events, 128, 5 ); 200 | 201 | for( int i = 0; i < nfds; i++ ) 202 | { 203 | for( vector :: iterator itListener = m_vecListeners.begin( ); itListener != m_vecListeners.end( ); itListener++ ) 204 | { 205 | if( events[i].data.fd == *itListener ) 206 | { 207 | iAddrLen = sizeof( adrFrom ); 208 | 209 | sckClient = accept( *itListener, (struct sockaddr *)&adrFrom, (socklen_t *)&iAddrLen ); 210 | 211 | if( sckClient == INVALID_SOCKET ) 212 | UTIL_LogPrint( ( gmapLANG_CFG["accept_error"] + "\n" ).c_str( ), GetLastErrorString( ) ); 213 | else 214 | m_vecClients.push_back( new CClient( sckClient, adrFrom, m_uiSocketTimeOut, m_cCompression ) ); 215 | } 216 | } 217 | } 218 | } 219 | else 220 | { 221 | // maximum connections reached 222 | 223 | // tphogan - reduced from 100 ms to 10 ms 224 | // it's very difficult to tell if the backlog is due to legitimate load or hung clients 225 | // hung clients don't eat CPU time so the server's CPU usage will skyrocket 226 | // but if it's due to load then sleeping for 100 ms is a terrible idea! 227 | // someone should take a look at this and rewrite it eventually 228 | 229 | UTIL_LogPrint( "Server Info - Max. connections reached\n" ); 230 | 231 | MILLISLEEP( 10 ); 232 | } 233 | 234 | // process the clients 235 | for( vector :: iterator itClient = m_vecClients.begin( ); itClient != m_vecClients.end( ); ) 236 | { 237 | if( (*itClient)->Update( ) ) 238 | { 239 | delete *itClient; 240 | 241 | itClient = m_vecClients.erase( itClient ); 242 | } 243 | else 244 | itClient++; 245 | } 246 | 247 | if( m_pTracker ) 248 | m_pTracker->Update( ); 249 | 250 | return m_bKill; 251 | } 252 | 253 | CTracker *CServer :: getTracker( ) 254 | { 255 | return m_pTracker; 256 | } 257 | 258 | bool CServer :: AddListener( struct sockaddr_in6 sin ) 259 | { 260 | SOCKET sckListener; 261 | 262 | // map protocol name to protocol number 263 | 264 | struct protoent *pPE; 265 | 266 | pPE = getprotobyname( "tcp" ); 267 | 268 | if( pPE == 0 ) 269 | { 270 | UTIL_LogPrint( ( gmapLANG_CFG["no_tcp_protocol"] + "\n" ).c_str( ), GetLastErrorString( ) ); 271 | 272 | return false; 273 | } 274 | 275 | // allocate socket 276 | 277 | sckListener = socket( PF_INET6, SOCK_STREAM, pPE->p_proto ); 278 | 279 | if( sckListener == INVALID_SOCKET ) 280 | { 281 | UTIL_LogPrint( ( gmapLANG_CFG["not_allocated_socket"] + "\n" ).c_str( ), GetLastErrorString( ) ); 282 | 283 | return false; 284 | } 285 | 286 | #ifdef WIN32 287 | const unsigned int cuiOptVal( 1 ); 288 | 289 | // TCP window size 290 | // Send 291 | if( setsockopt( sckListener, SOL_SOCKET, SO_SNDBUF, (const char *)&guiSO_SNDBUF, sizeof(guiSO_SNDBUF) ) == SOCKET_ERROR ) 292 | UTIL_LogPrint( ( gmapLANG_CFG["no_sndbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 293 | 294 | // Receive 295 | if( setsockopt( sckListener, SOL_SOCKET, SO_RCVBUF, (const char *)&guiSO_RECBUF, sizeof(guiSO_RECBUF) ) == SOCKET_ERROR ) 296 | UTIL_LogPrint( ( gmapLANG_CFG["no_rcvbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 297 | 298 | // Allows the socket to be bound to an address that is already in use. 299 | if( setsockopt( sckListener, SOL_SOCKET, SO_REUSEADDR, (const char *)&cuiOptVal, sizeof( cuiOptVal ) ) == SOCKET_ERROR ) 300 | UTIL_LogPrint( ( gmapLANG_CFG["no_reuseaddr"] + "\n" ).c_str( ), GetLastErrorString( ) ); 301 | 302 | // Naggle's Algorithm 303 | if( setsockopt( sckListener, SOL_SOCKET, TCP_NODELAY, (const char *)&gbTCP_NODELAY, sizeof( int ) ) == SOCKET_ERROR ) 304 | UTIL_LogPrint( ( gmapLANG_CFG["no_nodelay"] + "\n" ).c_str( ), GetLastErrorString( ) ); 305 | 306 | // bind socket 307 | if( bind( sckListener, (SOCKADDR*)&sin, sizeof( sin ) ) == SOCKET_ERROR ) 308 | { 309 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_bind_socket"] + "\n" ).c_str( ), GetLastErrorString( ) ); 310 | 311 | return false; 312 | } 313 | #else 314 | const unsigned int cuiOptVal( 1 ); 315 | 316 | #ifdef SO_NOSIGPIPE 317 | // Ignore SIGPIPE - FreeBSD 318 | if( setsockopt( sckListener, SOL_SOCKET, SO_NOSIGPIPE, (const void *)&cuiOptVal, (socklen_t)sizeof( cuiOptVal ) ) == SOCKET_ERROR ) 319 | UTIL_LogPrint( ( gmapLANG_CFG["no_nosigpipe"] + "\n" ).c_str( ), GetLastErrorString( ) ); 320 | #endif 321 | 322 | #ifdef SO_SNDBUF 323 | // TCP window size Send 324 | if( setsockopt( sckListener, SOL_SOCKET, SO_SNDBUF, (const char *)&guiSO_SNDBUF, (socklen_t)sizeof( guiSO_SNDBUF ) ) == SOCKET_ERROR ) 325 | UTIL_LogPrint( ( gmapLANG_CFG["no_sndbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 326 | #endif 327 | 328 | #ifdef SO_RCVBUF 329 | // TCP window size Receive 330 | if( setsockopt( sckListener, SOL_SOCKET, SO_RCVBUF, (const char *)&guiSO_RECBUF, (socklen_t)sizeof( guiSO_RECBUF ) ) == SOCKET_ERROR ) 331 | UTIL_LogPrint( ( gmapLANG_CFG["no_rcvbuf"] + "\n" ).c_str( ), GetLastErrorString( ) ); 332 | #endif 333 | 334 | #ifdef SO_REUSEADDR 335 | // Allows the socket to be bound to an address that is already in use. 336 | if( setsockopt( sckListener, SOL_SOCKET, SO_REUSEADDR, (const void *)&cuiOptVal, (socklen_t)sizeof( cuiOptVal ) ) == SOCKET_ERROR ); 337 | UTIL_LogPrint( ( gmapLANG_CFG["no_reuseaddr"] + "\n" ).c_str( ), GetLastErrorString( ) ); 338 | #endif 339 | 340 | #ifdef TCP_NODELAY 341 | // Nagle's Algorithm 342 | if( setsockopt( sckListener, SOL_SOCKET, TCP_NODELAY, (const char *)&gbTCP_NODELAY, (socklen_t)sizeof( int ) ) == SOCKET_ERROR ) 343 | UTIL_LogPrint( ( gmapLANG_CFG["no_nodelay"] + "\n" ).c_str( ), GetLastErrorString( ) ); 344 | #endif 345 | 346 | if( fcntl( sckListener, F_SETFL, fcntl( sckListener, F_GETFL ) | O_NONBLOCK ) == SOCKET_ERROR ) 347 | UTIL_LogPrint( "server warning: socket blocking (error %s)\n", GetLastErrorString( ) ); 348 | 349 | // bind 350 | if( bind( sckListener, (struct sockaddr *)&sin, sizeof( sin ) ) == SOCKET_ERROR ) 351 | { 352 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_bind_socket"] + "\n" ).c_str( ), GetLastErrorString( ) ); 353 | 354 | return false; 355 | } 356 | #endif 357 | 358 | // listen on the socket 359 | if( listen( sckListener, 1 ) == SOCKET_ERROR ) 360 | { 361 | UTIL_LogPrint( ( gmapLANG_CFG["unable_to_listen"] + "\n" ).c_str( ), GetLastErrorString( ) ); 362 | 363 | return false; 364 | } 365 | 366 | // Add the socket to the vector of sockets 367 | m_vecListeners.push_back( sckListener ); 368 | 369 | ev.data.fd = sckListener; 370 | 371 | ev.events = EPOLLIN | EPOLLET; 372 | 373 | if( epoll_ctl( epfd, EPOLL_CTL_ADD, sckListener, &ev ) == SOCKET_ERROR ) 374 | { 375 | UTIL_LogPrint( "client warning: epoll_ctl add (error %s)\n", GetLastErrorString( ) ); 376 | 377 | return false; 378 | } 379 | 380 | return true; 381 | } 382 | --------------------------------------------------------------------------------