public function get_location($ip, $args = array())
 {
     if (!function_exists('geoip_open')) {
         require_once 'geoip.inc';
     }
     // setup database file and function
     if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
         $file = $this->get_db_dir() . IP_GEO_BLOCK_MAXMIND_IPV4_DAT;
     } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
         $file = $this->get_db_dir() . IP_GEO_BLOCK_MAXMIND_IPV6_DAT;
     } else {
         return array('errorMessage' => 'illegal format');
     }
     // open database and fetch data
     if (!file_exists($file) || null == ($geo = geoip_open($file, GEOIP_STANDARD))) {
         return FALSE;
     }
     switch ($geo->databaseType) {
         case GEOIP_COUNTRY_EDITION:
             $res = $this->location_country(geoip_country_code_by_addr($geo, $ip));
             break;
         case GEOIP_COUNTRY_EDITION_V6:
             $res = $this->location_country(geoip_country_code_by_addr_v6($geo, $ip));
             break;
         case GEOIP_CITY_EDITION_REV1:
             if (!class_exists('geoiprecord')) {
                 require_once 'geoipcity.inc';
             }
             $res = $this->location_city(geoip_record_by_addr($geo, $ip));
             break;
         case GEOIP_CITY_EDITION_REV1_V6:
             if (!class_exists('geoiprecord')) {
                 require_once 'geoipcity.inc';
             }
             $res = $this->location_city(geoip_record_by_addr_v6($geo, $ip));
             break;
         default:
             $res = array('errorMessage' => 'unknown database type');
     }
     geoip_close($geo);
     return $res;
 }
function bbc_extension_plugin($host, $addr)
{
    global $BBC_GEOIP_PATH, $gi;
    // First of all let's check if the include file exists
    if (!@file_exists($BBC_GEOIP_PATH . 'geoip.inc')) {
        bbc_msg('Missing geoip installation');
    }
    include_once $BBC_GEOIP_PATH . 'geoip.inc';
    // Bail out if the file exists but does not seem to be geoip
    if (!function_exists('geoip_open')) {
        return "";
    }
    if (preg_match('/^.{1,4}:/', $addr)) {
        $gi = geoip_open($BBC_GEOIP_PATH . "GeoIPv6.dat", GEOIP_STANDARD);
        $addr = geoip_country_code_by_addr_v6($gi, $addr);
    } else {
        $gi = geoip_open($BBC_GEOIP_PATH . "GeoIP.dat", GEOIP_STANDARD);
        $addr = geoip_country_code_by_addr($gi, $addr);
    }
    geoip_close($gi);
    return strtolower($addr);
}
Beispiel #3
0
function iqblockcountry_check_ipaddress($ip_address)
{
    if (!class_exists('GeoIP')) {
        include_once "geoip.inc";
    }
    if (is_file(IPV4DBFILE) && function_exists('geoip_open')) {
        $ipv4 = FALSE;
        $ipv6 = FALSE;
        if (iqblockcountry_is_valid_ipv4($ip_address)) {
            $ipv4 = TRUE;
        }
        if (iqblockcountry_is_valid_ipv6($ip_address)) {
            $ipv6 = TRUE;
        }
        if ($ipv4) {
            $gi = geoip_open(IPV4DBFILE, GEOIP_STANDARD);
            $country = geoip_country_code_by_addr($gi, $ip_address);
            geoip_close($gi);
        } elseif ($ipv6) {
            if (is_file(IPV6DBFILE)) {
                $gi = geoip_open(IPV6DBFILE, GEOIP_STANDARD);
                $country = geoip_country_code_by_addr_v6($gi, $ip_address);
                geoip_close($gi);
            } else {
                $country = 'ipv6';
            }
        } else {
            $country = "Unknown";
        }
    } elseif (get_option('blockcountry_geoapikey')) {
        $country = iqblockcountry_retrieve_geoipapi($ip_address);
    } else {
        $country = "Unknown";
    }
    return $country;
}
Beispiel #4
0
 public static function IP2Country($IP)
 {
     if (!(function_exists('geoip_open') && function_exists('geoip_country_code_by_addr') && function_exists('geoip_country_code_by_addr_v6'))) {
         require_once 'wfGeoIP.php';
     }
     if (filter_var($IP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) {
         $gi = geoip_open(dirname(__FILE__) . "/GeoIPv6.dat", GEOIP_STANDARD);
         $country = geoip_country_code_by_addr_v6($gi, $IP);
     } else {
         $gi = geoip_open(dirname(__FILE__) . "/GeoIP.dat", GEOIP_STANDARD);
         $country = geoip_country_code_by_addr($gi, $IP);
     }
     geoip_close($gi);
     return $country ? $country : '';
 }
Beispiel #5
0
function statisticsForm($type)
{
    global $db_con, $mysql_table_prefix, $log_dir, $include_dir, $sites_per_page, $search_script;
    global $debug, $thumb_dir, $start, $image_dir, $mysql_csize, $mysql_cacheon, $dba_act;
    global $index_id3, $delim, $thumb_folder;
    error_reporting(0);
    echo "<div class='submenu cntr'>|&nbsp;&nbsp;&nbsp;Database {$dba_act}&nbsp;&nbsp;with table prefix '{$mysql_table_prefix}'&nbsp;&nbsp;&nbsp;|</div>\n            <div class='submenu y4'>\n                <ul>\n                    <li><a href='admin.php?f=statistics&amp;type=keywords' title='Show list of Top 100 Keywords'>Top keywords</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=thumb_files' title='Show list of all indexed thumbnails.'>Indexed Thumbnails</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=pages' title='Show list of Largest Pages and their indexed file size'>Largest pages</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=spidering_log' title='Show list of Spidering Logs'>Spidering logs</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=autoindex' title='Show start time and index counter'>Auto Re-index log file</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=ids' title='Show list of intrusion attempts'>IDS log file</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=server_info' title='Show all available server info'>Server Info</a></li>\n                </ul>\n                <br /><br />\n                <ul>\n                    <li><a href='admin.php?f=statistics&amp;type=log' title='Show Search Log activity'>Search log</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=top_searches' title='Show list of the most popular on-line Searches'>Most popular searches</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=top_links' title='Show list of the most popular page links, clicked by the user'>Most popular page links</a></li>\n                    <li><a href='admin.php?f=statistics&amp;type=top_media' title='Show list of the most popular media flinks, clicked by the user'>Most popular media links</a></li>\n                </ul>\n            </div>\n            ";
    if ($type == "") {
        $cachedSumQuery = "SELECT sum(length(fulltxt)) from " . $mysql_table_prefix . "links";
        $result = $db_con->query($cachedSumQuery);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            printf("<p>{$cachedSumQuery}</p>");
            exit;
        }
        if ($row = $result->fetch_array(MYSQLI_NUM)) {
            $cachedSumSize = $row[0];
        }
        $cachedSumSize = number_format($cachedSumSize / 1024, 2);
        $sitesSizeQuery = "SELECT sum(size) from " . $mysql_table_prefix . "links";
        $result = $db_con->query("{$sitesSizeQuery}");
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            printf("<p>{$sitesSizeQuery}</p>");
            exit;
        }
        if ($row = $result->fetch_array(MYSQLI_NUM)) {
            $sitesSize = $row[0];
        }
        $sitesSize = number_format($sitesSize, 2);
        $sql_query = "SELECT ip from " . $mysql_table_prefix . "query_log";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        $query_tot = '0';
        $sql_query = "SELECT count(*) from " . $mysql_table_prefix . "query_log";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        if ($row = $result->fetch_array(MYSQLI_NUM)) {
            $query_tot = $row[0];
        }
        $page_clicks = '0';
        $sql_query = "SELECT sum(click_counter) from " . $mysql_table_prefix . "links";
        $result = $db_con->query($sql_query);
        if (!$db_con->errno) {
            if ($row = $result->fetch_array(MYSQLI_NUM)) {
                $page_clicks = $row[0];
            }
            $result = $db_con->query("SELECT count(*) from " . $mysql_table_prefix . "media");
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            if ($row = $result->fetch_array(MYSQLI_NUM)) {
                $media_tot = $row[0];
            }
            $media_clicks = '0';
            $sql_query = "SELECT * from " . $mysql_table_prefix . "media where click_counter > 0";
            $result = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            if ($row = $result->num_rows) {
                $media_clicks = $row;
            }
            $stats = getStatistics();
            echo "<div class='panel w60'>\n                        <dl class='tblhead'>\n                        <dt class='headline x2'>Overall Statistics :</dt><dd class='headline'>&nbsp;Counts</dd>\n                        <dt class='odrow bd x2'>Sites :</dt><dd class='odrow'>&nbsp;" . $stats['sites'] . "</dd>\n                        <dt class='evrow bd x2'>Links :</dt><dd class='evrow'>&nbsp;" . $stats['links'] . "</dd>\n                        <dt class='odrow bd x2'>Categories :</dt><dd class='odrow'>&nbsp;" . $stats['categories'] . "</dd>\n                        <dt class='evrow bd x2'>Keywords :</dt><dd class='evrow'>&nbsp;" . $stats['keywords'] . "</dd>\n                        <dt class='odrow bd x2'>Media files :</dt><dd class='odrow'>&nbsp;{$media_tot}</dd>\n                        <dt class='odrow bd x2'>Keyword link-relations :</dt><dd class='odrow'>&nbsp;" . $stats['index'] . "</dd>\n                        <dt class='evrow bd x2'>Cached texts total :</dt><dd class='evrow'>&nbsp;{$cachedSumSize} kb</dd>\n                        <dt class='odrow bd x2'>Sites size total :</dt><dd class='odrow'>&nbsp;{$sitesSize} kb</dd>\n                        <dt class='evrow bd x2'>Queries total :</dt><dd class='evrow'>&nbsp;{$query_tot}</dd>\n                        <dt class='odrow bd x2'>Page Link clicks total :</dt><dd class='odrow'>&nbsp;{$page_clicks}</dd>\n                        <dt class='odrow bd x2'>Media Link clicks total :</dt><dd class='odrow'>&nbsp;{$media_clicks}</dd>\n                     </dl>\n                    </div>\n                    ";
        } else {
            echo "\n                        <div class='submenu cntr'>\n                        <span class='warnadmin'>\n                    ";
            echo "<br /><br /><br />\n                        Invalid database table installation.\n                        <br />\n                        </span>\n                        </div>\n                        <br /><br />\n                    ";
            die;
        }
        echo "</div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'keywords') {
        $class = "evrow";
        $sql_query = "SELECT keyword, count(" . $mysql_table_prefix . "link_keyword.keyword_id) as x from " . $mysql_table_prefix . "keywords, " . $mysql_table_prefix . "link_keyword\n                    where " . $mysql_table_prefix . "keywords.keyword_id = " . $mysql_table_prefix . "link_keyword.keyword_id group by keyword order by x desc limit 30";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        $num_rows = $result->num_rows;
        if ($num_rows) {
            while ($row = $result->fetch_array(MYSQLI_NUM)) {
                $topwords[$row[0]] = $row[1];
            }
        }
        arsort($topwords);
        echo "<div class='panel'>\n                    <p class='headline cntr'>Top 100 Keywords</p>\n                ";
        $nloops = 1;
        do {
            $nloops++;
            $count = 1;
            echo "<div class='ltfloat x3'>\n                            <dl>\n                        <dt class='headline x2'>Keyword</dt><dd class='headline'>:&nbsp;Instances</dd>\n                    ";
            while ((list($word, $weight) = each($topwords)) && $count < 34) {
                $count++;
                if ($class == "evrow") {
                    $class = "odrow";
                } else {
                    $class = "evrow";
                }
                echo "<dt class='{$class}'><a href='../{$search_script}?query={$word}&amp;search=1' target='rel' title='View search results in new window'>" . trim(substr($word, 0, 35)) . "</a></dt>\n                        <dd class='{$class}'>:&nbsp;" . $weight . "</dd>\n                    ";
            }
            echo "</dl>\n                        </div>\n                    ";
        } while ($nloops <= 3);
        echo "<div class='clear'></div>\n                        <br />\n                        <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                        <br />\n                    </div>\n                </div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'pages') {
        $class = "evrow";
        echo "<div class='panel'>\n                    <dl class='tblhead'>\n                    <dt class='headline x8'>File Size</dt><dd class='headline cntr'>Links to Largest Pages</dd>\n                ";
        $sql_query = "SELECT " . $mysql_table_prefix . "links.link_id, url, length(fulltxt)  as x from " . $mysql_table_prefix . "links order by x desc LIMIT 20";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
            if ($class == "evrow") {
                $class = "odrow";
            } else {
                $class = "evrow";
            }
            $url = reconvert_url($row[1]);
            $sum = number_format($row[2] / 1024, 2);
            echo "<dt class='{$class} x8'>" . $sum . "kb&nbsp;&nbsp;&nbsp;</dt>\n                        <dd class='{$class}'><a href='{$url}' title='Open this page in new window' target='_blank'>" . $url . "</a></dd>\n                    ";
        }
        echo "</dl>\n                        <br />\n                        <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                        <br />\n                    </div>\n                </div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'top_searches') {
        $class = "evrow";
        echo "<div class='panel'>\n                    <p class='headline cntr sml'>Most Popular Searches (Top 50)</p>\n                    <table width='100%'>\n                        <tr>\n                            <td class='tblhead'>Query</td>\n                            <td class='tblhead'>Count</td>\n                            <td class='tblhead'>Media query</td>\n                            <td class='tblhead'>Average results</td>\n                            <td class='tblhead'>Last queried</td>\n                            <td class='tblhead'>Queried by IP</td>\n                            <td class='tblhead'>Country</td>\n                            <td class='tblhead'>Host name</td>\n                    </tr>\n                ";
        $sql_query = "SELECT query, count(*) as c, date_format(max(time), '%Y-%m-%d %H:%i:%s'), avg(results), media from " . $mysql_table_prefix . "query_log group by query order by c desc LIMIT 50";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
            if ($class == "evrow") {
                $class = "odrow";
            } else {
                $class = "evrow";
            }
            $word = $row[0];
            $times = $row[1];
            $date = $row[2];
            $media = $row[4];
            $avg = number_format($row[3], 0);
            $word = str_replace("\"", "", $word);
            $sql_query = "SELECT ip from " . $mysql_table_prefix . "query_log where query='{$word}' order by time desc ";
            $result1 = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $ips = $result1->fetch_array(MYSQLI_NUM);
            $ip = $ips[0];
            //$ip = "222.46.18.34";  // just for tests
            if (intval($ip) > 0) {
                $hostname = @gethostbyaddr($ip);
                //  very slow! comment this row, if not required
                if ($hostname == $ip) {
                    $hostname = "Unknown host";
                }
            } else {
                $hostname = "Unknown host";
                // a bad address.
            }
            //  convert any IP into IPv6
            $ip6 = IPv4To6($ip);
            //  find Country Code using the IPv6 database and IPV6 IPs
            $gi = geoip_open("GeoIPv6.dat", GEOIP_STANDARD);
            $cc = geoip_country_code_by_addr_v6($gi, $ip6);
            $country = geoip_country_name_by_addr_v6($gi, $ip6);
            geoip_close($gi);
            if ($media) {
                //  prepare a media search
                $sql_query = "query_m=" . $word . "&submit=Media&search=1&media_only=0&cat_sel0=&cat_sel1=&cat_sel2=&cat_sel3=&cat_sel4=&type=and&results=10&db=0&prefix=0";
            } else {
                //  prepare a text search
                $sql_query = "query_t=" . $word . "&submit=Text&search=1&media_only=0&cat_sel0=&cat_sel1=&cat_sel2=&cat_sel3=&cat_sel4=&type=and&mark=blau+markiert&results=10&db=0&prefix=0";
            }
            echo "<tr class='{$class} sml'>\n                        <td><a href='../{$search_script}?{$query}' target='_blank' title='Open this Log File in new window'>" . $word . "</a></td>\n                        <td class='cntr'> " . $times . "</td>\n                        <td class='cntr sml'> " . $media . "</td>\n                        <td class='cntr'> " . $avg . "</td>\n                        <td class='cntr'> " . $date . "</td>\n                        <td class='cntr'> " . $ip . "</td>\n                        <td class='cntr sml'> " . $cc . " - " . $country . "</td>\n                        <td class='cntr sml'> " . $hostname . "</td>\n                        </tr>\n                    ";
        }
        echo "\n                    </table>\n                    <br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br />\n                </div>\n              </div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'top_links') {
        $class = "evrow";
        echo "<div class='panel'>\n                    <p class='headline cntr sml'>Most Popular Links (Top 50)</p>\n                    <table width='100%'>\n                        <tr>\n                            <td class='tblhead'>Link</td>\n                            <td class='tblhead'>Total clicks</td>\n                            <td class='tblhead'>Last clicked</td>\n                            <td class='tblhead'>Last query</td>\n                            <td class='tblhead'>Queried<br />by IP</td>\n                            <td class='tblhead'>Country</td>\n                            <td class='tblhead'>Host name</td>\n                        </tr>\n                ";
        $sql_query = "SELECT url, click_counter, last_click, last_query  from " . $mysql_table_prefix . "links order by click_counter DESC, url LIMIT 50";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
            if ($class == "evrow") {
                $class = "odrow";
            } else {
                $class = "evrow";
            }
            $url = reconvert_url($row[0]);
            $click_counter = $row[1];
            $Timestamp = $row[2];
            $last_query = $row[3];
            if ($Timestamp != '0') {
                $last_click = date("Y-m-d H:i:s", $Timestamp);
                $sql_query = "SELECT ip from " . $mysql_table_prefix . "links where last_query='{$last_query}' order by last_click desc ";
                $result1 = $db_con->query($sql_query);
                $ips = $result1->fetch_array(MYSQLI_NUM);
                $ip = $ips[0];
                //$ip = "222.46.18.34";  // just for tests
                if (intval($ip) > 0) {
                    $hostname = @gethostbyaddr($ip);
                    //  very slow! comment this row, if not required
                    if ($hostname == $ip) {
                        $hostname = "Unknown host";
                    }
                } else {
                    $hostname = "Unknown host";
                    // a bad address.
                }
                //  convert any IP into IPv6
                $ip6 = IPv4To6($ip);
                //  find Country Code using the IPv6 database and IPV6 IPs
                $gi = geoip_open("GeoIPv6.dat", GEOIP_STANDARD);
                $cc = geoip_country_code_by_addr_v6($gi, $ip6);
                $country = geoip_country_name_by_addr_v6($gi, $ip6);
                geoip_close($gi);
                echo "<tr class='{$class} sml'>\n                                <td><a href='{$url}' target='rel' title='View link in new window'>" . htmlentities($url) . "</a></td>\n                                <td class='cntr sml'> " . $click_counter . "</td>\n                                <td class='cntr sml'> " . $last_click . "</td>\n                                <td class='cntr sml'> " . $last_query . "</td>\n                                <td class='cntr'> " . $ip . "</td>\n                                <td class='cntr sml'> " . $cc . " - " . $country . "</td>\n                                <td class='cntr sml'> " . $hostname . "</td>\n                            </tr>\n                        ";
            }
        }
        echo "\n                    </table>\n                    <br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br />\n                </div>\n              </div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'top_media') {
        $class = "evrow";
        echo "<div class='panel'>\n                    <p class='headline cntr sml'>Most Popular Media (Top 50)</p>\n                    <form action='' id='fdeltm'>\n                    <table width='100%'>\n                    <tr>\n                        <td colspan='5' class='odrow bd'>\n                            <input type='hidden' name='f' value='14' />\n                            <input class='sbmt' id='submit11' type='submit' value='Clear this statistics' title='Start statistics deletion'\n                                onclick=\"return confirm('Are you sure you want to delete the 'Most popular media' statistics?')\" />\n                        </td>\n                    </tr>\n                    <tr>\n                        <td class='tblhead'>Thumbnail</td>\n                        <td class='tblhead'>Details</td>\n                        <td class='tblhead'>Total clicks</td>\n                        <td class='tblhead'>Last clicked</td>\n                        <td class='tblhead'>Last query</td>\n                        <td class='tblhead'>Queried<br />by IP</td>\n                        <td class='tblhead'>Country</td>\n                        <td class='tblhead'>Host name</td>\n                    </tr>\n                ";
        $sql_query = "SELECT link_addr, media_link, thumbnail, title, type, click_counter, last_click, last_query  from " . $mysql_table_prefix . "media order by click_counter DESC, media_link LIMIT 50";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
            if ($class == "evrow") {
                $class = "odrow";
            } else {
                $class = "evrow";
            }
            $title = substr($row[3], 0, strpos($row[3], $delim));
            //  extract original title without transliterated words
            $name0 = basename($var[1]);
            //  extract file name
            $name = substr($name0, 0, strrpos($name0, "."));
            //  remove original suffix
            $last_query = $row[7];
            //  add folder path, db, table-prefix and add own suffix
            $file = utf8_decode("." . $thumb_folder . "/db" . $dba_act . "_" . $mysql_table_prefix . "_" . $name . ".gif");
            //  temporary save thumbnail in folder
            if (!($handle = fopen($file, "ab"))) {
                if ($debug > 0) {
                    print "Unable to open {$file} ";
                }
            }
            if (!fwrite($handle, $row[2])) {
                if ($debug > 0) {
                    print "Unable to write the file {$file}. No thumbnails will be presented";
                }
            }
            fclose($handle);
            if ($row[4] == 'audio') {
                // use dummy thumbnail
                $thumb_link = "{$image_dir}/notes60.gif";
            }
            if ($row[4] == 'video') {
                // use dummy thumbnail
                $thumb_link = "{$image_dir}/film60.gif";
            }
            if ($row[6] != '0') {
                $last_click = date("Y-m-d H:i:s", $row[6]);
                $sql_query = "SELECT ip from " . $mysql_table_prefix . "media where last_query='{$last_query}' order by last_click desc ";
                $result1 = $db_con->query($sql_query);
                if ($debug && $db_con->errno) {
                    $err_row = __LINE__ - 2;
                    printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                    if (__FUNCTION__) {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                    } else {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                    }
                    printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                    printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                    echo "<p> {$sql_query} </p>";
                    exit;
                }
                $ips = $result1->fetch_array(MYSQLI_NUM);
                $ip = $ips[0];
                //$ip = "222.46.18.34";  // just for tests
                if (intval($ip) > 0) {
                    $hostname = @gethostbyaddr($ip);
                    //  very slow! comment this row, if not required
                    if ($hostname == $ip) {
                        $hostname = "Unknown host";
                    }
                } else {
                    $hostname = "Unknown host";
                    // a bad address.
                }
                //  convert any IP into IPv6
                $ip6 = IPv4To6($ip);
                //  find Country Code using the IPv6 database and IPV6 IPs
                $gi = geoip_open("GeoIPv6.dat", GEOIP_STANDARD);
                $cc = geoip_country_code_by_addr_v6($gi, $ip6);
                $country = geoip_country_name_by_addr_v6($gi, $ip6);
                geoip_close($gi);
                echo "<tr class='{$class} sml'>\n                                <td class='cntr'><a href='{$row['1']}' target='rel' title='Open this object'><img src='{$file}' border='1' alt='Open this object' /></a></td>\n                                <td><strong>Title:</strong>&nbsp;&nbsp;{$title}\n                                <br /><br />\n                                <strong>Found at:</strong>&nbsp;<a href='{$row['0']}' target='rel' title='Open this page in a new window'>{$row['0']}</a></td>\n                                <td class='cntr sml'> " . $row[5] . "</td>\n                                <td class='cntr sml'> " . $last_click . "</td>\n                                <td class='cntr sml'> " . $row[7] . "</td>\n                                <td class='cntr'> " . $ip . "</td>\n                                <td class='cntr sml'> " . $cc . " - " . $country . "</td>\n                                <td class='cntr sml'> " . $hostname . "</td>\n                            </tr>\n                        ";
            }
        }
        echo "\n                    </table>\n                    </form>\n                    <br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br />\n                </div>\n              </div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'autoindex') {
        $i = "0";
        $logfolder = "./log/";
        if ($handle = opendir($logfolder)) {
            //  open log-folder
            echo "<div class='panel'>\n                ";
            while (false !== ($logfile = readdir($handle))) {
                //get all log files
                if (strstr($logfile, "db" . $dba_act . "_" . $mysql_table_prefix . "")) {
                    //separate only log files of current active db and table prefix
                    $att = '';
                    if (strstr($logfile, "._all")) {
                        //  this log file was created during 'Re-index all sites'
                        $att = "all";
                    } else {
                        //  this log file was created during individual site indexing
                        //  extract site_id from file name
                        $end = strrpos($logfile, "_");
                        $start = strpos($logfile, "._") + 2;
                        $site_id = substr($logfile, $start, $end - $start);
                        //  get URL according to actual site_id
                        $sql_query = "SELECT * from " . $mysql_table_prefix . "sites where site_id={$site_id}";
                        $result = $db_con->query($sql_query);
                        $row = $result->fetch_array(MYSQLI_ASSOC);
                        $site_url = $row['url'];
                    }
                    //  build some nice headlines for monitor output
                    if ($att) {
                        $headline = "Periodical Re-indexer<br /><br />Log file created during indexing all sites";
                    } else {
                        $headline = "<br >Periodical Re-indexer<br /><br />Log file created during indexing<br />{$site_url}<br />Site id: {$site_id}";
                    }
                    $content = @file("log/" . $logfile . "");
                    //  get content of the current logfile
                    //  output the periodical Re-indexer for each log file
                    $class = "evrow";
                    echo "<p class='headline cntr sml'>{$headline}</p>\n                <br />\n                <table width='50%'>\n                    <tr>\n                        <td class='tblhead'>Index counter</td>\n                        <td class='tblhead'>Started</td>\n                    </tr>\n                ";
                    foreach ($content as $thisrow) {
                        if ($class == "evrow") {
                            $class = "odrow";
                        } else {
                            $class = "evrow";
                        }
                        $counter = substr($thisrow, 0, strpos($thisrow, "count"));
                        $started = date("Y-m-d H:i:s", substr($thisrow, strpos($thisrow, "count") + 5));
                        //  if Auto-indexer already finished by count limit
                        if (strpos($thisrow, "inish")) {
                            $counter = "finished:";
                            $started = date("Y-m-d H:i:s", substr($thisrow, strpos($thisrow, "finished") + 8));
                        }
                        //  if Auto-indexer already finished because interval was too short
                        if (strpos($thisrow, "borted")) {
                            $counter = "Aborted because<br />interval too short";
                            $started = date("Y-m-d H:i:s", substr($thisrow, strpos($thisrow, "finished") + 7));
                        }
                        echo "    <tr class='{$class} sml'>\n                        <td class='cntr'>{$counter}</td>\n                        <td class='cntr'>{$started}</td>\n                    </tr>\n                ";
                    }
                    echo "</table>\n                <br /><br />\n                <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                <br /><br />\n                ";
                    $i++;
                }
            }
            if ($i < "1") {
                echo "<br />\n                <p class='cntr msg'>Note: <span class='warnadmin'>Currently no log file available</span></p>\n                ";
            }
        }
        echo "<br />\n            </div>\n            <br />\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'log') {
        $class = "evrow";
        echo "<div class='panel w100'>\n                    <p class='headline cntr sml'>Search Log (Latest 100)</p>\n                    <table width='100%'>\n                    <tr>\n                        <td class='tblhead'>Query</td>\n                        <td class='tblhead'>Media query</td>\n                        <td class='tblhead'>Results</td>\n                        <td class='tblhead'>Queried at:</td>\n                        <td class='tblhead'>Time taken</td>\n                        <td class='tblhead'>User IP</td>\n                        <td class='tblhead'>Country</td>\n                        <td class='tblhead'>Host name</td>\n                    </tr>\n                ";
        $sql_query = "SELECT query,  date_format(time, '%Y-%m-%d %H:%i:%s'), elapsed, results, ip, media from " . $mysql_table_prefix . "query_log order by time desc LIMIT 100";
        $result = $db_con->query($sql_query);
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
            if ($class == "evrow") {
                $class = "odrow";
            } else {
                $class = "evrow";
            }
            $query = '';
            $word = $row[0];
            $time = $row[1];
            $elapsed = $row[2];
            $results = $row[3];
            $ip = $row[4];
            $media = $row[5];
            //$ip = "222.46.18.34";  // just for tests
            if (intval($ip) > 0) {
                $hostname = @gethostbyaddr($ip);
                //  very slow! comment this row, if not required
                if ($hostname == $ip) {
                    $hostname = "Unknown host";
                }
            } else {
                $hostname = "Unknown host";
                // a bad address.
            }
            //  convert any IP into IPv6
            $ip6 = IPv4To6($ip);
            //  find Country Code using the IPv6 database and IPV6 IPs
            $gi = geoip_open("GeoIPv6.dat", GEOIP_STANDARD);
            $cc = geoip_country_code_by_addr_v6($gi, $ip6);
            $country = geoip_country_name_by_addr_v6($gi, $ip6);
            geoip_close($gi);
            if ($media) {
                //  prepare a media search
                $query = "query_m=" . $word . "&submit=Media&search=1&media_only=0&cat_sel0=&cat_sel1=&cat_sel2=&cat_sel3=&cat_sel4=&type=and&results=10&db=0&prefix=0";
            } else {
                //  prepare a text search
                $query = "query_t=" . $word . "&submit=Text&search=1&media_only=0&cat_sel0=&cat_sel1=&cat_sel2=&cat_sel3=&cat_sel4=&type=and&mark=blau+markiert&results=10&db=0&prefix=0";
            }
            echo "<tr class='{$class}'>\n                            <td><a href='../{$search_script}?{$query}' target='_blank' title='Open this Log File in new window'>" . $word . "</a></td>\n                            <td class='cntr sml'> " . $media . "</td>\n                            <td class='cntr sml'> " . $results . "</td>\n                            <td class='cntr sml'> " . $time . "</td>\n                            <td class='cntr sml'> " . $elapsed . "</td>\n                            <td class='cntr sml'> " . $ip . "</td>\n                            <td class='cntr sml'> " . $cc . " - " . $country . "</td>\n                            <td class='cntr sml'> " . $hostname . "</td>\n                        </tr>\n                    ";
        }
        echo "\n                    </table>\n                    <br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br />\n                </div>\n              </div>\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == 'spidering_log') {
        $class = "evrow";
        $files = get_dir_contents($log_dir);
        if (count($files) > 0) {
            echo "<div class='panel w75'>\n                        <p class='headline cntr'>Spidering Logs</p>\n                            <form action='' id='fdelfm'>\n                            <table width='100%'>\n                            <tr>\n                                <td class='tblhead'>File</td>\n                                <td class='tblhead'>Created</td>\n                                <td class='tblhead' width='25%'>Option</td>\n                            </tr>\n                            <tr>\n                                <td colspan='3' class='odrow cntr bd'>\n                                <input type='hidden' name='f' value='44'\n                                />\n                                <input class='sbmt' id='submit1' type='submit' value='Delete ALL log files' title='Start Log File deletion'\n                                onclick=\"return confirm('Are you sure you want to delete ALL log files? &nbsp;&nbsp;&nbsp;&nbsp;ATTENTION: A still running periodical indexing will be aborted.')\" />\n                                </td>\n                            </tr>\n                        ";
            for ($i = 0; $i < count($files); $i++) {
                $file = $files[$i];
                $year = substr($file, 4, 2);
                $month = substr($file, 6, 2);
                $day = substr($file, 8, 2);
                $hour = substr($file, 11, 2);
                $minute = substr($file, 14, 2);
                $second = substr($file, 17, 2);
                if ($class == "evrow") {
                    $class = "odrow";
                } else {
                    $class = "evrow";
                }
                echo "<tr class='{$class}'>\n                            <td class='cntr sml'>\n                            <a href='{$log_dir}/{$file}' target='_blank' title='Open this Log File in new window'>{$file}</a></td>\n                            ";
                if (strlen($file) > '13') {
                    if (strstr($file, "auto-indexer")) {
                        //  the log-file for the Auto Re-indexer
                        $logfile = "log/db" . $dba_act . "_" . $mysql_table_prefix . "._all_auto-indexer.log";
                        $content = @file($logfile);
                        //  content of the logfile
                        $started = date("Y-m-d H:i:s", substr($content[0], strpos($content[0], "count") + 5));
                        echo "  <td class='cntr sml'>{$started}</td>\n                                            <td class='cntr sml options'><a href='?f=delete_log&amp;file={$file}' class='options' title='Click to Delete this Log File'\n                                            onclick=\"return confirm('Are you sure you want to delete? {$file} &nbsp;&nbsp;&nbsp;&nbsp;ATTENTION: Deleting this Log File may abort periodical Re-indexing.')\">Delete</a></td>\n                                    ";
                    } else {
                        echo "  <td class='cntr sml'>20{$year}-{$month}-{$day} {$hour}:{$minute}.{$second}</td>\n                                            <td class='cntr sml options'><a href='?f=delete_log&amp;file={$file}' class='options' title='Click to Delete this Log File'\n                                            onclick=\"return confirm('Are you sure you want to delete '{$file}' Indexing Log File will be lost.')\">Delete</a></td>\n                                    ";
                    }
                } else {
                    echo "  <td></td><td></td>\n                                ";
                }
                echo "\n                        </tr>\n                        ";
            }
            echo "\n                        </table></form>\n                        <br />\n                        <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                        <br />\n                        </div>\n                    ";
        } else {
            echo "<br />\n                        <p class='cntr msg'>Note: <span class='warnadmin'>No saved spidering logs exist!</span></p>\n                        <br /> <br />\n                    ";
        }
        echo "</div>\n                    </div>\n                    </body>\n                    </html>\n                    ";
        exit;
    }
    if ($type == 'thumb_files') {
        if ($thumb_folder) {
            //  delete all former thumbnails in temporary folder
            clear_folder("." . $thumb_folder);
        }
        $class = "odrow";
        $files = array();
        $sql_query = "SELECT media_id from " . $mysql_table_prefix . "media";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        $thumb_count = $result->num_rows;
        if ($thumb_count) {
            while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
                $files[] = $row['media_id'];
            }
        }
        //Prepare thumbnails and their info for listing
        //$sites_per_page = '100'; // if you prefer another count than used for Sphiders result pages, uncomment this row and place your count of thumbnails per page here.
        $pages = ceil($thumb_count / $sites_per_page);
        // Calculate count of required pages
        if (empty($start)) {
            $start = '1';
        }
        // As $start is not yet defined this is required for the first result page
        if ($start == '1') {
            $from = '0';
            // Also for first page in order not to multipy with 0
        } else {
            $from = ($start - 1) * $sites_per_page;
            // First $num_row of actual page
        }
        $to = $thumb_count;
        // Last $num_row of actual page
        $rest = $thumb_count - $start;
        if ($thumb_count > $sites_per_page) {
            // Display more then one page?
            $rest = $thumb_count - $from;
            $to = $from + $rest;
            // $to for last page
            if ($rest > $sites_per_page) {
                $to = $from + $sites_per_page;
            }
            // Calculate $num_row of actual page
        }
        if ($thumb_count > '0') {
            $fromm = $from + 1;
            echo "<div class='panel'>\n            <p class='headline cntr sml'>Displaying thumbnails {$fromm} - {$to}&nbsp;&nbsp;from {$thumb_count}</p>\n            <form action='' id='fdelfm'>\n                <table width='100%'>\n                    <tr>\n                        <td class='tblhead' width='30%'>Thumbnail</td>\n                        <td class='tblhead'>Details</td>\n                        <td class='tblhead' width='20%'>Option</td>\n                    </tr>\n                    <tr>\n                        <td colspan='3' class='odrow bd'>\n                            <input type='hidden' name='f' value='49' />\n                            <input class='sbmt' id='submit1' type='submit' value='Delete ALL images' title='Start File deletion'\n                                onclick=\"return confirm('Are you sure you want to delete ALL indexed images \\n and ALL thumbnail files?')\" />\n                        </td>\n                    </tr>\n                ";
            for ($i = $from; $i < $to; $i++) {
                $this_thumb = $files[$i];
                $i_1 = $i + 1;
                //  so table output does not start with zero
                $result = $db_con->query("SELECT media_id, media_link, thumbnail, title from " . $mysql_table_prefix . "media where media_id like '{$this_thumb}'");
                if ($result->num_rows > '0') {
                    $var = $result->fetch_array(MYSQLI_NUM);
                    $media_id = $var[0];
                    $this_img = $var[1];
                    $title = substr($var[3], 0, strpos($var[3], $delim));
                    //  extract original title without transliterated words
                    $name0 = basename($var[1]);
                    //  extract file name
                    $name = substr($name0, 0, strrpos($name0, "."));
                    //  remove original suffix
                    //  add folder path, db, table-prefix and add own suffix
                    $file = utf8_decode("." . $thumb_folder . "/db" . $dba_act . "_" . $mysql_table_prefix . "_" . $name . ".gif");
                    //  temporary save thumbnail in folder
                    if (!($handle = fopen($file, "ab"))) {
                        if ($debug > 0) {
                            print "Unable to open {$file} ";
                        }
                    }
                    if (!fwrite($handle, $var[2])) {
                        if ($debug > 0) {
                            print "Unable to write the file {$file}. No thumbnails will be presented";
                        }
                    }
                    fclose($handle);
                }
                if ($class == "odrow") {
                    $class = "evrow";
                } else {
                    $class = "odrow";
                }
                echo "    <tr class='{$class}'>\n                        <td class='cntr x4'>\n                            <a href='{$this_img}' target='rel' title='View the real image (not only the thumbnail) in new window'><img src=\"{$file}\" border='1' alt=\"Thumbnail\" /></a>\n                        </td>\n                        <td class='lft sml'>\n                            <p> Thumb no.:&nbsp;&nbsp;&nbsp;{$i_1}</p>\n                            <p> File name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$name0}</p>\n                            <p> Title:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$title}</p>\n                            <p> Thumb_ID : &nbsp;&nbsp;{$media_id}</p>\n                            ";
                if ($index_id3 == '1') {
                    echo "<p><a href='" . $include_dir . "/show_id3.php?media_id={$media_id}' target='rel' title='Click here to see EXIF and ID3 Infos in a new window'>Show EXIF Info</a></p>\n                        ";
                }
                echo "</td>\n                        <td class='cntr sml options'>\n                            <a href='?f=delete_thumb&amp;file={$media_id}' class='options' title='Click to delete this thumbnail'\n                            onclick=\"return confirm('Are you sure you want to delete \\'{$name}\\'. \\nThumbnail file will be lost.')\">Delete</a>\n                        </td>\n                    </tr>\n                ";
            }
            echo "</table>\n            </form>\n            <br />\n            <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n            <br />\n            </div>\n            ";
            // Display end of table
            if ($thumb_count > 0) {
                echo "\n            <br />";
                if ($pages > 1) {
                    // If we have more than 1 result-page
                    echo "\n            <div class='submenu cntr'>\n                Result page: {$start} from {$pages}&nbsp;&nbsp;&nbsp;\n                ";
                    if ($start > 1) {
                        // Display 'First'
                        echo "\n                                    <a href='admin.php?f=statistics&amp;type=thumb_files&amp;start=1'>First</a>&nbsp;&nbsp;\n                                ";
                        if ($start > 5) {
                            // Display '-5'
                            $minus = $start - 5;
                            echo "\n                                    <a href='admin.php?f=statistics&amp;type=thumb_files&amp;start={$minus}'>- 5</a>&nbsp;&nbsp;\n                                ";
                        }
                    }
                    if ($start > 1) {
                        // Display 'Previous'
                        $prev = $start - 1;
                        echo "\n                                    <a href='admin.php?f=statistics&amp;type=thumb_files&amp;start={$prev}'>Previous</a>&nbsp;&nbsp;\n                                ";
                    }
                    if ($rest >= $sites_per_page) {
                        // Display 'Next'
                        $next = $start + 1;
                        echo "\n                                    <a href='admin.php?f=statistics&amp;type=thumb_files&amp;start={$next}' >Next</a>&nbsp;&nbsp;\n                                ";
                        if ($pages - $start > 5) {
                            // Display '+5'
                            $plus = $start + 5;
                            echo "\n                                     <a href='admin.php?f=statistics&amp;type=thumb_files&amp;start={$plus}'>+ 5</a>&nbsp;&nbsp;\n                                ";
                        }
                    }
                    if ($start < $pages) {
                        // Display 'Last'
                        echo "\n                                    <a href='admin.php?f=statistics&amp;type=thumb_files&amp;start={$pages}'>Last</a>\n                                ";
                    }
                    echo "</div>\n                        ";
                }
            }
        } else {
            echo "<br />\n                        <p class='cntr msg'>Note: <span class='warnadmin'>No saved thumbnails exist!</span></p>\n                        <br /> <br />\n                    ";
        }
        echo "\n            </div>\n        </body>\n    </html>\n                    ";
        exit;
    }
    if ($type == "ids") {
        $back = '';
        showIDS($back);
        exit;
    }
    if ($type = 'server_info') {
        $s_infos = str_replace("&", "&amp;", $_SERVER);
        $e_infos = str_replace("&", "&amp;", $_ENV);
        echo "<div class='submenu'>\n                    <ul>\n                    <li><a href='#serv_info'>Server</a></li>\n                    <li><a href='#en_info'>Environment</a></li>\n                    <li><a href='#mysql_info'>MySQL</a></li>\n                    <li><a href='#pdf_con'>PDF-converter</a></li>\n                    <li><a href='#gd_info'>Image func.</a></li>\n                    <li><a href='#php_ini'>php.ini file</a></li>\n                    <li><a href='admin.php?f=35'>PHP integration</a></li>\n                    <li><a href='#php_sec'>PHP security info</a></li>\n                    </ul>\n                    </div>\n                    <div class='tblhead sml'><a name='serv_info'>Server</a> </div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='20%' class='tblhead'>Key</td>\n                        <td class='tblhead'>Value</td>\n\n                    </tr>\n                ";
        $bgcolor = 'odrow';
        $i = 0;
        reset($s_infos);
        while (list($key, $value) = each($s_infos)) {
            echo "<tr class='{$bgcolor} cntr'>\n                            <td>{$key}</td>\n                            <td class='bordl'>{$value}</td>\n                        </tr>\n                    ";
            $i++;
            if ($bgcolor == 'odrow') {
                $bgcolor = 'evrow';
            } else {
                $bgcolor = 'odrow';
            }
        }
        echo "\n                    </table><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br /><br />\n                    <div class='headline cntr sml'><a name='en_info'>Environment</a></div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='20%' class='tblhead'>Key</td>\n                        <td class='tblhead'>Value</td>\n\n                    </tr>\n                ";
        $bgcolor = 'odrow';
        $i = 0;
        reset($e_infos);
        while (list($key, $value) = each($e_infos)) {
            echo "<tr class='{$bgcolor} cntr'>\n                            <td>{$key}</td>\n                            <td  class='bordl'>{$value}</td>\n                        </tr>\n                    ";
            $i++;
            if ($bgcolor == 'odrow') {
                $bgcolor = 'evrow';
            } else {
                $bgcolor = 'odrow';
            }
        }
        echo "\n                    </table><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                ";
        $server_version = $db_con->server_info;
        $host_info = $db_con->host_info;
        $client_info = $db_con->client_info;
        $protocol_version = $db_con->protocol_version;
        $sql_query = "SHOW STATUS LIKE 'Qcache_free_memory'";
        $status = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        $row = $status->fetch_array(MYSQLI_ASSOC);
        $cmem_size = $row['Value'];
        echo "<br /><br />\n                    <div class='headline cntr sml'><a name='mysql_info'>MySQL Info</a></div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='35%' class='tblhead'>Key</td>\n                        <td  class='tblhead'>Value</td>\n                    </tr>\n                ";
        $bgcolor = 'odrow';
        echo "\n                    <tr class='{$bgcolor} cntr'>\n                        <td>MySQL Server version</td>\n                        <td  class='bordl'>{$server_version}</td>\n                    </tr>\n                ";
        $bgcolor = 'evrow';
        echo "\n                    <tr class='{$bgcolor} cntr'>\n                        <td>Connection info</td>\n                        <td  class='bordl'>{$host_info}</td>\n                    </tr>\n                ";
        $bgcolor = 'odrow';
        echo "\n                    <tr class='{$bgcolor} cntr'>\n                        <td>Client library info</td>\n                        <td  class='bordl'>{$client_info}</td>\n                    </tr>\n                ";
        $bgcolor = 'evrow';
        echo "\n                    <tr class='{$bgcolor} cntr'>\n                        <td>MySQL protocol version</td>\n                        <td  class='bordl'>{$protocol_version}</td>\n                    </tr>\n                ";
        $bgcolor = 'odrow';
        echo "\n                    <tr class='{$bgcolor} cntr'>\n                        <td>Support for mysqli</td>\n                        <td  class='bordl'>See below as part of your PHP installation</td>\n                    </tr>\n                ";
        $bgcolor = 'evrow';
        echo "<tr><td></td><td></td></tr>\n                    <tr class='{$bgcolor} cntr'>\n                        <td>MySQL cache</td>\n                ";
        if ($cmem_size == '0') {
            echo "<td  class='warnadmin'>Cache is not initialized</td>";
        } else {
            echo "<td  class='bordl'>32 MByte initialized</td>\n                        </tr>\n                    ";
            $bgcolor = 'odrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Currently free cache size</td>\n                            <td  class='bordl'>{$cmem_size} Bytes</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_total_blocks'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $ctot_blocks = $row['Value'];
            $bgcolor = 'evrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Cache total blocks</td>\n                            <td  class='bordl'>{$ctot_blocks}</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_free_blocks'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $cfree_blocks = $row['Value'];
            $bgcolor = 'odrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Cache free blocks</td>\n                            <td  class='bordl'>{$cfree_blocks}</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_hits'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $cache_hits = $row['Value'];
            $bgcolor = 'evrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Cache hits</td>\n                            <td  class='bordl'>{$cache_hits}</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_inserts'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $cache_inserts = $row['Value'];
            $bgcolor = 'odrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Cache inserts</td>\n                            <td  class='bordl'>{$cache_inserts}</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_queries_in_cache'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $queries_in_cache = $row['Value'];
            $bgcolor = 'evrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Queries in cache</td>\n                            <td  class='bordl'>{$queries_in_cache}</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_not_cached'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $q_not_cached = $row['Value'];
            $bgcolor = 'odrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Queries not cached</td>\n                            <td  class='bordl'>{$q_not_cached}</td>\n                        </tr>\n                    ";
            $sql_query = "SHOW STATUS LIKE 'Qcache_lowmem_prunes'";
            $status = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $status->fetch_array(MYSQLI_ASSOC);
            $q_low_prun = $row['Value'];
            $bgcolor = 'evrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Not cached because low memory</td>\n                            <td  class='bordl'>{$q_low_prun}</td>\n                        </tr>\n                    ";
        }
        echo "\n                    </table><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                ";
        $os = '';
        $os = $_ENV['OS'];
        // not all shared hosting server will supply this info
        $admin_path = $_ENV['ORIG_PATH_TRANSLATED'];
        // that might work for shared hosting server
        $admin_file = $_SERVER['SCRIPT_FILENAME'];
        // should present the physical path
        $sdoc_root = $_SERVER['DOCUMENT_ROOT'];
        // this should provide every hoster (???)
        $edoc_root = $_ENV['DOCUMENT_ROOT'];
        // this should provide every hoster (???)
        echo "<br /><br />\n                    <div class='headline cntr sml'><a name='pdf_con'>PDF-converter relevant Info</a></div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='35%' class='tblhead'>Key</td>\n                        <td  class='tblhead'>Value</td>\n                    </tr>\n                ";
        $bgcolor = 'odrow';
        if ($os) {
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Operating System</td>\n                            <td  class='bordl'>{$os}</td>\n                        </tr>\n                    ";
            $bgcolor = 'evrow';
        }
        if (!$os) {
            $s_soft = $_SERVER['SERVER_SOFTWARE'];
            $sys_os = stripos($s_soft, "lin");
            if (!$sys_os) {
                $sys_os = stripos($s_soft, "uni");
                if (!$sys_os) {
                    $sys_os = stripos($s_soft, "win");
                }
            }
            if ($sys_os) {
                $os = substr($s_soft, $sys_os, '5');
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Operating System</td>\n                                <td  class='bordl'>{$os}</td>\n                            </tr>\n                        ";
                $bgcolor = 'evrow';
            } else {
                $s_sig = $_SERVER['SERVER_SIGNATURE'];
                $sys_os = stripos($s_sig, "lin");
                if (!$sys_os) {
                    $sys_os = stripos($s_sig, "uni");
                    if (!$sys_os) {
                        $sys_os = stripos($s_sig, "win");
                    }
                }
            }
            if ($sys_os) {
                $os = substr($s_sig, $sys_os, '5');
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Operating System</td>\n                                <td  class='bordl'>{$os}</td>\n                            </tr>\n                        ";
                $bgcolor = 'evrow';
            }
        }
        //  if ENV or SERVER_SIGNATURE or SERVER_SOFTWARE do not deliver OperatingSystem info, we will use the PHPinfo to extract it
        if (!$os) {
            $phpinfo = '';
            ob_start();
            // redirect output into buffer
            phpinfo();
            $phpinfo = ob_get_contents();
            // get all from phpinfo
            ob_end_clean();
            // clean buffer and close it
            //  extract OS information
            $start = stripos($phpinfo, "\"v\"") + 4;
            $end = stripos($phpinfo, "</td>", $start);
            $length = $end - $start;
            $os = substr($phpinfo, $start, $length);
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Operating System</td>\n                            <td  class='bordl'>{$os}</td>\n                        </tr>\n                    ";
            $bgcolor = 'evrow';
        }
        if ($admin_path) {
            $admin_path = str_replace("\\\\", "/", $admin_path);
            $admin_path = str_replace("\\", "/", $admin_path);
            $pdf_path = substr($admin_path, 0, strrpos($admin_path, "/"));
            $pdf_path = substr($pdf_path, 0, strrpos($pdf_path, "/"));
            $pdf_path = "" . $pdf_path . "/converter/pdftotext";
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Physical path to Sphider-plus Admin</td>\n                            <td  class='bordl'>{$admin_path}</td>\n                        </tr>\n                    ";
            $bgcolor = 'odrow';
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Physical path to the Linux / UNIX PDF-converter</td>\n                            <td  class='bordl'>{$pdf_path}</td>\n                        </tr>\n                    ";
            $bgcolor = 'evrow';
        } else {
            if ($admin_file) {
                $admin_file = str_replace("\\\\", "/", $admin_file);
                $admin_file = str_replace("\\", "/", $admin_file);
                $pdf_path = substr($admin_file, 0, strrpos($admin_file, "/"));
                $pdf_path = substr($pdf_path, 0, strrpos($pdf_path, "/"));
                $pdf_path = "" . $pdf_path . "/converter/pdftotext";
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Physical path to Sphider-plus Admin</td>\n                                <td  class='bordl'>{$admin_file}</td>\n                            </tr>\n                        ";
                $bgcolor = 'odrow';
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Physical path to the Linux / UNIX PDF-converter</td>\n                                <td  class='bordl'>{$pdf_path}</td>\n                            </tr>\n                        ";
                $bgcolor = 'evrow';
            }
        }
        if ($sdoc_root) {
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>Physical path to document root</td>\n                            <td  class='bordl'>{$sdoc_root}</td>\n                        </tr>\n                    ";
        } else {
            if ($edoc_root) {
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Physical path to document root</td>\n                                <td  class='bordl'>{$edoc_root}</td>\n                            </tr>\n                        ";
            }
        }
        if (!$admin_path && !$admin_file) {
            if ($sdoc_root) {
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Physical path to document root</td>\n                                <td  class='bordl'>{$sdoc_root}</td>\n                            </tr>\n                        ";
            }
            if ($edoc_root) {
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>Physical path to document root</td>\n                                <td  class='bordl'>{$edoc_root}</td>\n                            </tr>\n                        ";
            } else {
                echo "\n                            </table>\n                            <table width='98%'>\n                            <tr>\n                                <td>\n                                <span class='cntr warnadmin'><br />\n                                Attention: Your server does not deliver information about the physical path to Sphider-plus.<br />\n                                For LINUX and UNIX systems you will have to initialize the PDF converter manually.<br />\n                                For details see the file readme.pdf, chapter: PDF converter for Linux/UNIX systems.<br />\n                                <br /></span>\n                                </td>\n                            </tr>\n                        ";
            }
        }
        echo "\n                    </table><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a><br /><br />\n                ";
        if (function_exists(gd_info)) {
            $gd = gd_info();
            //  get details about image functions
        }
        echo "<br /><br />\n                    <div class='headline cntr sml'><a name='gd_info'>Info about Image Functions (GD-library)</a></div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='50%' class='tblhead'>Key</td>\n                        <td  class='tblhead'>Value</td>\n                    </tr>\n                ";
        if ($gd) {
            $bgcolor = "evrow";
            foreach ($gd as $key => $val) {
                if ($bgcolor == "evrow") {
                    $bgcolor = "odrow";
                } else {
                    $bgcolor = "evrow";
                }
                echo "\n                            <tr class='{$bgcolor} cntr'>\n                                <td>{$key}</td>\n                                <td class='bordl'>{$val}</td>\n                            </tr>\n                        ";
            }
        } else {
            echo "\n                        <tr class='warnadmin cntr'>\n                            <td>Image functions are not installed.</td>\n                            <td>You will need to compile PHP with the GD library.</td>\n                        </tr>\n                    ";
        }
        echo "\n                    </table><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a><br /><br />\n                ";
        echo "\n                    <div class='headline cntr sml'>PHP Info</div>\n                    <br />\n                    <div class='headline cntr sml'><a name='php_ini'>php.ini file</a></div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='20%' class='tblhead'>Key</td>\n                        <td class='tblhead'>Value</td>\n\n                    </tr>\n                ";
        $php_ini = str_replace("&", "&amp;", ini_get_all());
        $bgcolor = 'odrow';
        $i = 0;
        reset($php_ini);
        while (list($key, $value) = each($php_ini)) {
            echo "\n                        <tr class='{$bgcolor} cntr'>\n                            <td>{$key}</td>\n                            <td class='bordl'>\n                    ";
            print_r($value);
            echo "\n                            </td>\n                        </tr>\n                    ";
            $i++;
            if ($bgcolor == 'odrow') {
                $bgcolor = 'evrow';
            } else {
                $bgcolor = 'odrow';
            }
        }
        echo "\n                    </table>\n                    <br /><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br /><br />\n                    <div class='headline cntr sml'><a name='php_sec'>PHP security info</a></div>\n                    <table width='98%'>\n                    <tr>\n                        <td width='20%' class='tblhead'></td>\n                        <td class='tblhead'></td>\n\n                    </tr>\n                ";
        //phpsecinfo();   //  get PHP security information
        echo "\n                    </table>\n                    <br /><br />\n                    <a class='navup' href='#head' title='Jump to Page Top'>Top</a>\n                    <br /><br />\n                    </div>\n                ";
        exit;
    }
}
 public function testV6()
 {
     $gi = geoip_open("tests/data/GeoIPv6.dat", GEOIP_STANDARD);
     $this->assertEquals('JP', geoip_country_code_by_addr_v6($gi, '2001:200::'));
 }
Beispiel #7
0
     default:
         $ip_parts = explode("/", $ip);
         $ip_start = $ip_parts[0];
         if (strpos($ip_start, ".") !== false) {
             $asn = geoip_name_by_addr($giasn, $ip_start);
         } else {
             $asn = geoip_name_by_addr_v6($giasn_v6, $ip_start);
         }
         $asn_details = explode(" ", $asn);
         $origin = str_replace("AS", "", $asn_details[0]);
         array_shift($asn_details);
         $asn_name = implode(" ", $asn_details);
         if (strpos($ip_start, ".") !== false) {
             $country = geoip_country_code_by_addr($gi, $ip_start);
         } else {
             $country = geoip_country_code_by_addr_v6($gi_v6, $ip_start);
         }
 }
 $records++;
 if ($records > 1) {
     fwrite($fp_1, $eol);
     fwrite($fp_3, $eol);
     fwrite($fp_4, $eol);
     fwrite($fp_5, $eol);
     fwrite($fp_6, $eol);
     fwrite($fp_7, $eol);
     fwrite($fp_8, $eol);
     fwrite($fp_9, $eol);
 }
 fputcsv_eol($fp_0, array(trim($ip), trim($origin), mb_convert_encoding(trim($asn_name), 'UTF-8', 'ISO-8859-1'), trim($country)), "\t", $eol);
 fwrite($fp_1, trim($ip));
Beispiel #8
0
#!/usr/bin/php -q
<?php 
// This code demonstrates how to lookup the country by IP Address
include "geoip.inc";
// Uncomment if querying against GeoIP/Lite City.
// include("geoipcity.inc");
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPv6.dat", GEOIP_STANDARD);
echo geoip_country_code_by_addr_v6($gi, "::24.24.24.24") . "\t" . geoip_country_name_by_addr_v6($gi, "::24.24.24.24") . "\n";
echo geoip_country_code_by_addr_v6($gi, "::80.24.24.24") . "\t" . geoip_country_name_by_addr_v6($gi, "::80.24.24.24") . "\n";
echo geoip_country_code_by_addr_v6($gi, "2001:4860:0:1001::68") . "\t" . geoip_country_name_by_addr_v6($gi, "2001:4860:0:1001::68") . "\n";
echo geoip_country_code_by_addr_v6($gi, "2001:67c:26c::") . "\t" . geoip_country_name_by_addr_v6($gi, "2001:67c:26c::") . "\n";
echo geoip_country_code_by_addr_v6($gi, "2001:67c:3a0:ffff:ffff:ffff:ffff:ffff") . "\t" . geoip_country_name_by_addr_v6($gi, "2001:67c:3a0:ffff:ffff:ffff:ffff:ffff") . "\n";
echo geoip_country_code_by_name_v6($gi, "ipv6.google.com") . "\t" . geoip_country_name_by_name_v6($gi, "ipv6.google.com") . "\n";
geoip_close($gi);
Beispiel #9
0
 /**
  * Uses a GeoIP database to get a visitor's location based on their IP address.
  *
  * This function will return different results based on the data used. If a city
  * database is used, it may return the country code, region code, city name, area
  * code, latitude, longitude and postal code of the visitor.
  *
  * Alternatively, if used with a country database, only the country code will be
  * returned.
  *
  * @param array $info Must have an 'ip' field.
  * @return array
  */
 public function getLocation($info)
 {
     $ip = $this->getIpFromInfo($info);
     $isIPv6 = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
     $result = array();
     $locationGeoIp = $this->getGeoIpInstance($key = 'loc');
     if ($locationGeoIp) {
         switch ($locationGeoIp->databaseType) {
             case GEOIP_CITY_EDITION_REV0:
                 // city database type
             // city database type
             case GEOIP_CITY_EDITION_REV1:
             case GEOIP_CITYCOMBINED_EDITION:
                 if ($isIPv6) {
                     $location = geoip_record_by_addr_v6($locationGeoIp, $ip);
                 } else {
                     $location = geoip_record_by_addr($locationGeoIp, $ip);
                 }
                 if (!empty($location)) {
                     $result[self::COUNTRY_CODE_KEY] = $location->country_code;
                     $result[self::REGION_CODE_KEY] = $location->region;
                     $result[self::CITY_NAME_KEY] = utf8_encode($location->city);
                     $result[self::AREA_CODE_KEY] = $location->area_code;
                     $result[self::LATITUDE_KEY] = $location->latitude;
                     $result[self::LONGITUDE_KEY] = $location->longitude;
                     $result[self::POSTAL_CODE_KEY] = $location->postal_code;
                 }
                 break;
             case GEOIP_REGION_EDITION_REV0:
                 // region database type
             // region database type
             case GEOIP_REGION_EDITION_REV1:
                 if ($isIPv6) {
                     // NOTE: geoip_region_by_addr_v6 does not exist (yet?), so we
                     // return the country code and an empty region code
                     $location = array(geoip_country_code_by_addr_v6($locationGeoIp, $ip), '');
                 } else {
                     $location = geoip_region_by_addr($locationGeoIp, $ip);
                 }
                 if (!empty($location)) {
                     $result[self::COUNTRY_CODE_KEY] = $location[0];
                     $result[self::REGION_CODE_KEY] = $location[1];
                 }
                 break;
             case GEOIP_COUNTRY_EDITION:
                 // country database type
                 if ($isIPv6) {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr_v6($locationGeoIp, $ip);
                 } else {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip);
                 }
                 break;
             default:
                 // unknown database type, log warning and fallback to country edition
                 Log::warning("Found unrecognized database type: %s", $locationGeoIp->databaseType);
                 if ($isIPv6) {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr_v6($locationGeoIp, $ip);
                 } else {
                     $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip);
                 }
                 break;
         }
     }
     // NOTE: ISP & ORG require commercial dbs to test. The code has been tested manually,
     // but not by system tests.
     $ispGeoIp = $this->getGeoIpInstance($key = 'isp');
     if ($ispGeoIp) {
         if ($isIPv6) {
             $isp = geoip_name_by_addr_v6($ispGeoIp, $ip);
         } else {
             $isp = geoip_org_by_addr($ispGeoIp, $ip);
         }
         if (!empty($isp)) {
             $result[self::ISP_KEY] = utf8_encode($isp);
         }
     }
     $orgGeoIp = $this->getGeoIpInstance($key = 'org');
     if ($orgGeoIp) {
         if ($isIPv6) {
             $org = geoip_name_by_addr_v6($orgGeoIp, $ip);
         } else {
             $org = geoip_org_by_addr($orgGeoIp, $ip);
         }
         if (!empty($org)) {
             $result[self::ORG_KEY] = utf8_encode($org);
         }
     }
     if (empty($result)) {
         return false;
     }
     $this->completeLocationResult($result);
     return $result;
 }
Beispiel #10
0
 function get_country_code()
 {
     include_once '../geoip/geoip.php';
     $ip = getIP();
     if (strpos($ip, ":") === false) {
         //ipv4
         $gi = geoip_open("../geoip/GeoIP.dat", GEOIP_STANDARD);
         $country = geoip_country_code_by_addr($gi, $ip);
     } else {
         //ipv6
         $gi = geoip_open("../geoip/GeoIPv6.dat", GEOIP_STANDARD);
         $country = geoip_country_code_by_addr_v6($gi, $ip);
     }
     return $country;
 }
 protected function ip2Country($ip)
 {
     $wordfenceLib = realpath(dirname(__FILE__) . '/../lib');
     if (!(function_exists('geoip_open') && function_exists('geoip_country_code_by_addr') && function_exists('geoip_country_code_by_addr_v6'))) {
         require_once dirname(__FILE__) . '/wfWAFGeoIP.php';
     }
     if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) {
         $gi = geoip_open($wordfenceLib . "/GeoIPv6.dat", GEOIP_STANDARD);
         $country = geoip_country_code_by_addr_v6($gi, $ip);
     } else {
         $gi = geoip_open($wordfenceLib . "/GeoIP.dat", GEOIP_STANDARD);
         $country = geoip_country_code_by_addr($gi, $ip);
     }
     geoip_close($gi);
     return $country ? $country : '';
 }
        $IP = $IP_array[0];
    } elseif (!in_array("IPv6Loc", $IP_array)) {
        // Proxy IP
        $IP = "p" . $SimpleIP;
        $PROXY = true;
    }
    // GeoIP mode for country flags
    if (!class_exists("GeoIP")) {
        include_once "plugins/countryflags/geoip.inc";
    }
    if (in_array("IPv4", $IP_array)) {
        $gi = geoip_open("plugins/countryflags/GeoIP.dat", GEOIP_STANDARD);
        $COUNTRY_CODE = geoip_country_code_by_addr($gi, ltrim($IP, "p"));
    } elseif (in_array("IPv6", $IP_array)) {
        $gi6 = geoip_open("plugins/countryflags/GeoIPv6.dat", GEOIP_STANDARD);
        $COUNTRY_CODE = geoip_country_code_by_addr_v6($gi6, ltrim($IP, "p"));
    }
}
if (empty($COUNTRY_CODE)) {
    if ($PROXY && !in_array("IPv6Loc", $IP_array)) {
        $COUNTRY_CODE = "A1";
    } else {
        $COUNTRY_CODE = "LAN";
        $COUNTRY_NAME = "Other/LAN";
    }
}
if ($COUNTRY_CODE != "LAN") {
    $COUNTRY_NAME = $gi->GEOIP_COUNTRY_NAMES[$gi->GEOIP_COUNTRY_CODE_TO_NUMBER[$COUNTRY_CODE]];
}
if ($PROXY && $COUNTRY_CODE != "A1") {
    $COUNTRY_NAME .= " (Proxy Server)";