Exemple #1
0
function luc_StatAppend()
{
    global $wpdb, $StatPressV_Option, $userdata;
    $table_name = STATPRESS_V_TABLE_NAME;
    get_currentuserinfo();
    $feed = '';
    // Time
    $timestamp = current_time('timestamp');
    $vdate = gmdate("Ymd", $timestamp);
    $vtime = gmdate("H:i:s", $timestamp);
    // IP
    if (strnatcmp(phpversion(), '5.2.0') >= 0) {
        $ipAddress = htmlentities(luc_get_ip());
    } else {
        $ipAddress = htmlentities($_SERVER['REMOTE_ADDR']);
    }
    if (luc_CheckBanIP($ipAddress) === true) {
        return '';
    }
    // URL (requested)
    $urlRequested = luc_StatPressV_URL();
    $post_title = luc_post_title_Decode($urlRequested);
    $real_post = $post_title == $urlRequested ? 0 : 1;
    $referrer = isset($_SERVER['HTTP_REFERER']) ? esc_url_raw($_SERVER['HTTP_REFERER']) : '';
    $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '';
    $spider = luc_GetSpider($userAgent);
    if ($spider != '' and $StatPressV_Option['StatPressV_Dont_Collect_Spider'] == 'checked') {
        return '';
    }
    if ($spider != '') {
        $os = '';
        $browser = '';
    } else {
        // Trap feeds
        $prsurl = parse_url(get_bloginfo('url'));
        $feed = luc_StatPressV_Is_Feed($prsurl['scheme'] . '://' . $prsurl['host'] . htmlentities($_SERVER['REQUEST_URI']));
        // Get OS and browser
        $os = luc_GetOS($userAgent);
        $browser = luc_GetBrowser($userAgent);
        $refsearch = luc_GetSE($referrer);
        if ($refsearch !== null) {
            list($searchengine, $search_phrase) = explode("|", $refsearch);
        } else {
            $searchengine = "";
            $search_phrase = "";
        }
    }
    $code = explode(';', htmlentities($_SERVER['HTTP_ACCEPT_LANGUAGE']));
    $code = explode(',', $code[0]);
    $lang = explode('-', $code[0]);
    $language = $lang[0];
    $country = $lang[1];
    if ((!isset($lang[1]) or $StatPressV_Option['StatPressV_locate_IP'] == 'GeoIP') & ($StatPressV_Option['StatPressV_Use_GeoIP'] == 'checked' & function_exists('geoip_open'))) {
        // Use GeoIP? http://geolite.maxmind.com/download/geoip/api/php/
        // Open the database to read and save info
        $gi = geoip_open(luc_GeoIP_dbname('country'), GEOIP_STANDARD);
        $cc = geoip_country_code_by_addr($gi, $ipAddress);
        if ($cc !== false) {
            $country = $cc;
        } else {
            $country = NULL;
        }
    }
    // Auto-delete visits if...
    $today = gmdate('Ymd', current_time('timestamp'));
    if ($today != $StatPressV_Option['StatPressV_Delete_Today']) {
        $StatPressV_Option['StatPressV_Delete_Today'] = $today;
        if ($StatPressV_Option['StatPressV_AutoDelete_spider'] != '') {
            $t = gmdate("Ymd", strtotime('-' . $StatPressV_Option['StatPressV_AutoDelete_spider']));
            $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "' AND spider <> ''");
            $results = $wpdb->query('OPTIMIZE TABLE ' . $table_name);
        }
        if ($StatPressV_Option['StatPressV_AutoDelete'] != '') {
            $t = gmdate("Ymd", strtotime('-' . $StatPressV_Option['StatPressV_AutoDelete']));
            $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
            $results = $wpdb->query('OPTIMIZE TABLE ' . $table_name);
        }
        update_option('StatPressV_Option', $StatPressV_Option);
    }
    if (!is_user_logged_in() or $StatPressV_Option['StatPressV_Dont_Collect_Logged_User'] != 'checked' or $StatPressV_Option['StatPressV_Dont_Collect_Logged_User'] == 'checked' and !current_user_can($StatPressV_Option['StatPressV_Dont_Collect_Logged_User_MinPermit'])) {
        $result = $wpdb->insert($table_name, array('date' => $vdate, 'time' => $vtime, 'ip' => $ipAddress, 'urlrequested' => mysql_real_escape_string(strip_tags($urlRequested)), 'agent' => mysql_real_escape_string(strip_tags($userAgent)), 'referrer' => mysql_real_escape_string(strip_tags($referrer)), 'search' => mysql_real_escape_string(strip_tags($search_phrase)), 'os' => mysql_real_escape_string(strip_tags($os)), 'browser' => mysql_real_escape_string(strip_tags($browser)), 'searchengine' => mysql_real_escape_string(strip_tags($searchengine)), 'spider' => mysql_real_escape_string(strip_tags($spider)), 'feed' => $feed, 'user' => $userdata->user_login, 'timestamp' => $timestamp, 'language' => mysql_real_escape_string(strip_tags($language)), 'country' => mysql_real_escape_string(strip_tags($country)), 'realpost' => $real_post, 'post_title' => $post_title), array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%s'));
    }
}
function luc_spyvisitors()
{
    global $wpdb;
    global $StatPressV_Option;
    $action = "spyvisitors";
    $table_name = STATPRESS_V_TABLE_NAME;
    // number of IP or bot by page
    $LIMIT = $StatPressV_Option['StatPressV_SpyVisitor_IP_Per_Page'] ? $StatPressV_Option['StatPressV_SpyVisitor_IP_Per_Page'] : 20;
    $LIMIT_PROOF = $StatPressV_Option['StatPressV_SpyVisitor_Visits_Per_IP'] ? $StatPressV_Option['StatPressV_SpyVisitor_Visits_Per_IP'] : 20;
    $pp = luc_page_periode();
    // Number of distinct ip (unique visitors)
    $NumIP = $wpdb->get_var("SELECT count(distinct ip)\n\t\t\t\t\t\t\t\t\tFROM {$table_name}\n\t\t\t\t\t\t\t\t\tWHERE spider='' ;");
    $NP = ceil($NumIP / $LIMIT);
    $LimitValue = $pp * $LIMIT - $LIMIT;
    $sql = "SELECT *\n\t\t\t\t\tFROM {$table_name} as T1\n\t\t\t\t\tJOIN\n\t\t\t\t\t\t(SELECT max(id) as MaxId,ip\n\t\t\t\t\t\t\tFROM {$table_name}\n\t\t\t\t\t\t\tWHERE spider=''\n\t\t\t\t\t\t\tGROUP BY ip\n\t\t\t\t\t\t\tORDER BY MaxId DESC LIMIT {$LimitValue}, {$LIMIT}\n\t\t\t\t\t\t) as T2\n\t\t\t\t\tON T1.ip = T2.ip\n\t\t\t\t\tORDER BY MaxId DESC, id DESC;\n\t\t\t\t";
    $qry = $wpdb->get_results($sql);
    if ($StatPressV_Option['StatPressV_Use_GeoIP'] == 'checked' & function_exists('geoip_open')) {
        // Open the database to read and save info
        if (file_exists(luc_GeoIP_dbname('city'))) {
            $gic = geoip_open(luc_GeoIP_dbname('city'), GEOIP_STANDARD);
            $geoip_isok = true;
        }
    }
    echo "<div class='wrap'><h2>" . __('Visitor Spy', 'statpress') . "</h2>";
    ?>
<script>
	function ttogle(thediv){
	if (document.getElementById(thediv).style.display=="inline") {
	document.getElementById(thediv).style.display="none"
	} else {document.getElementById(thediv).style.display="inline"}
	}
</script>
<?php 
    $MaxId = 0;
    $num_row = 0;
    // Add pagination
    luc_insert_pagination_options("spyvisitors", $NumIP, $LIMIT);
    luc_print_pp_link($NP, $pp, $action);
    echo '<table class="widefat" id="mainspytab" name="mainspytab" width="99%" border="0" cellspacing="0" cellpadding="4">';
    foreach ($qry as $rk) {
        // Visitor Spy
        if ($MaxId != $rk->MaxId) {
            if ($geoip_isok === true) {
                $gir = GeoIP_record_by_addr($gic, $rk->ip);
            }
            echo "<thead><tr><th scope='colgroup' colspan='2'>";
            if ($rk->country != '') {
                echo "HTTP country " . luc_HTML_IMG($rk->country, 'country', false);
            } else {
                echo "Hostip country <IMG SRC='http://api.hostip.info/flag.php?ip=" . $rk->ip . "' border=0 width=18 height=12>  ";
            }
            if ($geoip_isok === true) {
                $lookupsvc = "GeoIP details";
            } else {
                $lookupsvc = "Hostip details";
            }
            echo "\t<strong><span><font size='2' color='#7b7b7b'> " . $rk->ip . " </font></span></strong>\n\t\t\t\t\t<span style='color:#006dca;cursor:pointer;border-bottom:1px dotted #AFD5F9;font-size:8pt;'\n\t\t\t\t\t\tonClick=ttogle('" . $rk->ip . "');>" . $lookupsvc . "</span></div>\n\t\t\t\t\t<div id='" . $rk->ip . "' name='" . $rk->ip . "'>";
            if ($geoip_isok === true) {
                echo "\t<small><br>\n\t\t\t\t\t\t\tCountry: " . utf8_encode($gir->country_name) . " (" . $gir->country_code . ")<br>\n\t\t\t\t\t\t\tCity: " . utf8_encode($gir->city) . "<br>\n\t\t\t\t\t\t\tLatitude/Longitude: <a href='http://maps.google.com/maps?q=" . $gir->latitude . "+" . $gir->longitude . "' target='_blank' title='Lookup latitude/longitude location on Google Maps...'>" . $gir->latitude . " " . $gir->longitude . "</a>\n\t\t\t\t\t\t</small>";
            } else {
                echo "\t<iframe style='overflow:hide;border:0px;width:100%;height:35px;font-family:helvetica;paddng:0;'\n\t\t\t\t\t\t\tscrolling='no' marginwidth=0 marginheight=0 src=http://api.hostip.info/get_html.php?ip=" . $rk->ip . ">\n\t\t\t\t\t\t</iframe>";
            }
            echo "\t<small>\n\t\t\t\t\t\t<br>" . $rk->os . "\n\t\t\t\t\t\t<br>" . $rk->browser . "\n\t\t\t\t\t\t<br>" . gethostbyaddr($rk->ip) . "\n\t\t\t\t\t\t<br>" . $rk->agent . "\n\t\t\t\t\t</small></div></th></tr></thead><tbody>\n\t\t\t\t\t<script> document.getElementById('" . $rk->ip . "').style.display='none';</script>\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td>" . luc_hdate($rk->date) . " " . $rk->time . "</td>\n\t\t\t\t\t<td>" . (isset($rk->post_title) ? $rk->post_title : luc_post_title_Decode(urldecode($rk->urlrequested))) . "";
            if ($rk->searchengine != '') {
                echo "<br><small>arrived from <b>" . $rk->searchengine . "</b> searching <a target='_blank' href='" . $rk->referrer . "' >" . urldecode($rk->search) . "</a></small>";
            } elseif ($rk->referrer != '' && strpos($rk->referrer, $home) === false) {
                echo "<br><small>arrived from <a target='_blank' href='" . $rk->referrer . "' >" . $rk->referrer . "</a></small>";
            }
            echo "</div></td></tr>\n";
            $MaxId = $rk->MaxId;
            $num_row = 1;
        } elseif ($num_row < $LIMIT_PROOF) {
            echo "<tr><td>" . luc_hdate($rk->date) . " " . $rk->time . "</td>\n\t\t\t\t\t\t<td>" . (isset($rk->post_title) ? $rk->post_title : luc_post_title_Decode(urldecode($rk->urlrequested))) . "";
            if ($rk->searchengine != '') {
                echo "<br><small>arrived from <b>" . $rk->searchengine . "</b> searching <a target='_blank' href='" . $rk->referrer . "' >" . urldecode($rk->search) . "</a></small>";
            } elseif ($rk->referrer != '' && strpos($rk->referrer, $home) === false) {
                echo "<br><small>arrived from <a target='_blank' href='" . $rk->referrer . "' >" . $rk->referrer . "</a></small>";
            }
            $num_row += 1;
            echo "</td></tr></tbody>";
        }
    }
    echo "</div></td></tr>\n</table>";
    luc_print_pp_link($NP, $pp, $action);
    echo "</div>";
    luc_StatPressV_load_time();
}
Exemple #3
0
function luc_GeoIP()
{
    global $StatPressV_Option;
    $ipAddress = htmlentities($_SERVER['REMOTE_ADDR']);
    $geoip = luc_GeoIP_get_data($ipAddress);
    if (file_exists(luc_GeoIP_dbname('country'))) {
        $stat = stat(luc_GeoIP_dbname('country'));
        $dbsize = number_format_i18n($stat['size']);
        $dbmtime = date_i18n('r', $stat['mtime']);
    } else {
        $StatPressV_Option['StatPressV_Use_GeoIP'] = '';
        update_option('StatPressV_Option', $StatPressV_Option);
    }
    if (file_exists(luc_GeoIP_dbname('city'))) {
        $statcity = stat(luc_GeoIP_dbname('city'));
        $dbcitysize = number_format_i18n($statcity['size']);
        $dbcitymtime = date_i18n('r', $statcity['mtime']);
    } else {
        $StatPressV_Option['StatPressV_Use_GeoIP'] = '';
        update_option('StatPressV_Option', $StatPressV_Option);
    }
    // Draw page
    ?>
	<table class='widefat'>
		<thead>
			<tr>
				<th scope='col' colspan='2'>GeoIP Lookup</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>
					
					<strong>Warning:</strong> GeoIP consumes lot of CPU time, its use is discouraged, do not use it or have permission from your host before activating.
					</br></br><input type=checkbox name='StatPressV_Use_GeoIP' id='StatPressV_Use_GeoIP' value='checked'/>
					<?php 
    echo $StatPressV_Option['StatPressV_Use_GeoIP'];
    ?>
 <label for='StatPressV_Use_GeoIP'>Enable (requires MaxMind GeoIP database files to be installed first)</label>
					
					
				</td>
				<td>
					<?php 
    if ($StatPressV_Option['StatPressV_Use_GeoIP'] == 'checked') {
        $geoipdb = luc_GeoIP_dbname('country');
        if (file_exists($geoipdb)) {
            echo "<span style='color:green'>Database OK</span>";
        } else {
            echo "<span style='color:red'>Database NOT found.  Please download and install databases first. Disabling Option! </span>";
            $StatPressV_Option['StatPressV_Use_GeoIP'] = '';
            update_option('StatPressV_Option', $StatPressV_Option);
        }
    }
    ?>
				</td>
			</tr>
			<tr>
				<td>
					<table class="form-table" width="100%">
						<tr>
							<td>
							<input type='button' id='dogeoipdbupdate' value='Download/update database from MaxMind' class='button-secondary'>
							<img src="<?php 
    echo STATPRESS_V_PLUGIN_URL;
    ?>
/images/ajax-loader.gif" id="geoipupdatedbLoader" style="display: none;" />
							<br /><br />
							<font size=2><b>WARNING!</b>  Downloading database updates from MaxMind <b>more than once per day</b> will get your <b>IP address banned!</b></font></td>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</tbody>
		<thead><tr>
						<th scope='col' colspan='2'>Indicate the preferred method to locate the country of visitors :</th>
					</tr>
			</thead>
			<tbody>
			<form method="post" >
   <tr><td>
       <input type="radio" name="StatPressV_locate_IP" value="browser" id="browser" <?php 
    if ($StatPressV_Option['StatPressV_locate_IP'] == 'browser') {
        echo 'checked';
    }
    ?>
	   /> <label for="browser">Store the country provided by the browser first, otherwise use GeoIP (default, recommended)</label><br />
       <input type="radio" name="StatPressV_locate_IP" value="GeoIP" id="GeoIP" <?php 
    if ($StatPressV_Option['StatPressV_locate_IP'] == 'GeoIP') {
        echo 'checked';
    }
    ?>
	   /> <label for="GeoIP">Always use GeoIP (accuracy 95%)</label><br />
   </td></tr>
</form>
</tbody>
		<thead><tr><th scope='col' colspan='2'>Status</th></tr></thead>
		<tbody>
		<tr>
			<td><strong>StatPressV GeoIP status:</strong></td>
	<?php 
    if ($StatPressV_Option['StatPressV_Use_GeoIP'] == 'checked') {
        echo "<td><span style='color:green'>Enabled</span></td>";
    } else {
        echo "<td><span style='color:red'>Disabled" . $geoipdb . "</span></td>";
    }
    ?>
		</tbody>
		<thead><tr><th scope='col' colspan='2'>Country database</th></tr></thead>
		<tbody>
		<tr>
			<td><strong>File status:</strong></td>
	<?php 
    if (!file_exists(luc_GeoIP_dbname('country'))) {
        echo "<td><span style='color:red'>Database NOT found" . $geoipdb . "</span></td></tr>";
        $StatPressV_Option['StatPressV_Use_GeoIP'] = '';
        update_option('StatPressV_Option', $StatPressV_Option);
    } else {
        echo "<td><span style='color:green'>Country database file exists</span></td>\r\n\t\t</tr>\r\n\t\t<tr><td><strong>File location:</strong></td>\r\n\t\t\t<td>" . luc_GeoIP_dbname('country') . "</td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<td><strong>File date (mtime):</strong></td>\r\n\t\t\t<td> {$dbmtime} </td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<td><strong>File size:</strong></td>\r\n\t\t\t<td> {$dbsize} bytes </td>\r\n\t\t</tr>";
    }
    ?>
		</tbody>

		<thead><tr><th scope='col' colspan='2'>City database</th></tr></thead>
		<tbody>
		<tr>
			<td><strong>File status:</strong></td>
	<?php 
    if (!file_exists(luc_GeoIP_dbname('city'))) {
        echo "<td><span style='color:red'>City database NOT found" . $geoipcitydb . "</span></td>";
        $StatPressV_Option['StatPressV_Use_GeoIP'] = '';
        update_option('StatPressV_Option', $StatPressV_Option);
    } else {
        echo "<td><span style='color:green'>City database file exists</span></td>\r\n\t\t<tr>\r\n\t\t\t<td><strong>File location:</strong></td>\r\n\t\t\t<td>" . luc_GeoIP_dbname('city') . "</td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<td><strong>File date (mtime):</strong></td>\r\n\t\t\t<td> {$dbcitymtime} </td>\r\n\t\t</tr>\r\n\t\t<tr>\r\n\t\t\t<td><strong>File size:</strong></td>\r\n\t\t\t<td> {$dbcitysize} bytes</td>\r\n\t\t</tr>";
    }
    ?>
		</tbody>
	<?php 
    if ($geoip !== false) {
        echo "\r\n\t\t\t<table class='widefat'>\r\n\t\t\t\t<thead><tr><th scope='col' colspan='4'>Your GeoIP Information ({$ipAddress})</th></tr></thead>\r\n\t\t\t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td><strong>Country:</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['cn'] . " (" . $geoip['cc'] . ")\r\n\t\t\t\t\t\t<IMG style='border:0px;height:16px;' alt='{$cn}' title='{$cn}' SRC='" . STATPRESS_V_PLUGIN_URL . '/images/domain/' . strtolower($geoip['cc']) . '.png' . "'></td>\r\n\t\t\t\t\t<td><strong>Continent Code:</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['continent_code'] . "</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td><strong>Region:</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['region'] . "</td>\r\n\t\t\t\t\t<td><strong>Area Code (USA Only):</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['area_code'] . "</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td><strong>City:</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['city'] . "</td>\r\n\t\t\t\t\t<td><strong>Postal Code (USA Only):</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['postal_code'] . "</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td><strong>Latitude/Longitude:</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['latitude'] . " " . $geoip['longitude'] . "</td>\r\n\t\t\t\t\t<td><strong>Metro Code (USA Only):</strong></td>\r\n\t\t\t\t\t<td>" . $geoip['metro_code'] . "</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t</tbody>\r\n\t\t\t</table>\r\n\t\t";
    }
    ?>
	</table>
	<div id='geoipupdatedbResultCountry'></div>
	<div id='geoipupdatedbResultCity'></div>
	<?php 
    //  End of GeoIP page
}
Exemple #4
0
function luc_GeoIP_update_db($edition = null)
{
    $edition = isset($_POST['edition']) ? $_POST['edition'] : $edition;
    $db = luc_GeoIP_dbname($edition);
    $db_dir = dirname($db);
    $db_gz = $db . '.gz';
    if ('city' == $edition) {
        $db_url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz";
    } else {
        if ('country' == $edition) {
            $db_url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz";
        } else {
            return false;
        }
    }
    if (is_dir($db_dir) === false) {
        mkdir($db_dir);
    }
    $db_gz_f = fopen($db_gz, "w");
    $host = parse_url($db_url, PHP_URL_HOST);
    ?>
		<table class='widefat'>
			<thead>
				<tr>
				<th scope='col'>Action</th>
				<th scope='col'>Information</th>
				<th scope='col' width="50px">Result</th>
				</tr>
			</thead>
			<tbody>
				<tr><td width="20%">Resolving hostname: </td><td><?php 
    _e($host);
    ?>
</td>
	<?php 
    if (gethostbyname($host) === $host) {
        echo "<td><span style='color:red'>[FAILED]</span></td></tr>";
    } else {
        if (function_exists('curl_init')) {
            echo "<td><span style='color:green'>[OK]</span></td></tr>";
            echo "<tr><td>Requesting: </td><td>" . $db_url . "</td>";
            $ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0';
            $ch = curl_init($db_url);
            curl_setopt($ch, CURLOPT_USERAGENT, $ua);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
            curl_setopt($ch, CURLOPT_FAILONERROR, true);
            curl_setopt($ch, CURLOPT_FILE, $db_gz_f);
            $execute = curl_exec($ch);
            // Check if any error occured
            if (curl_errno($ch)) {
                curl_close($ch);
                echo "<td><span style='color:red'>[FAILED]</span></td></tr>";
            } else {
                fclose($db_gz_f);
                $info = curl_getinfo($ch);
                curl_close($ch);
                clearstatcache();
                ?>
				<td><span style='color:green'>[OK]</span></td></tr>";
				<tr><td>Server response: </td><td><?php 
                _e($info['http_code']);
                ?>
</td><td><span style='color:green'>[OK]</span></td></tr>
				<tr><td>Content type: </td><td><?php 
                _e($info['content_type']);
                ?>
</td><td><span style='color:green'>[OK]</span></td></tr>
				<tr><td>Remote file time: </td><td><?php 
                _e($info['filetime']);
                ?>
</td><td><span style='color:green'>[OK]</span></td></tr>
				<tr><td>Bytes transfered: </td><td><?php 
                _e(number_format_i18n($info['size_download']));
                ?>
 bytes</td><td><span style='color:green'>[OK]</span></td></tr>
				<tr><td>Avg download speed: </td><td><?php 
                _e(number_format_i18n($info['speed_download']));
                ?>
 bytes/second</td><td><span style='color:green'>[OK]</span></td></tr>
				<tr><td>Time taken: </td><td><?php 
                _e($info['total_time']);
                ?>
</td><td><span style='color:green'>[OK]</span></td></tr>
				<?php 
                //  Check that the file is a plausable size
                if (filesize($db_gz) > 500000) {
                    // Remove old backup
                    if (file_exists($db . ".bak")) {
                        unlink($db . ".bak");
                    }
                    // Move exisiting database to backup
                    if (file_exists($db)) {
                        rename($db, $db . ".bak");
                    }
                    echo "<tr><td>Backing up old database:</td><td></td><td><span style='color:green'>[OK]</span></td></tr>";
                    // Unpack new database
                    if (luc_gunzip($db_gz, $db . ".new") !== true) {
                        echo "<tr><td>Unpacking archive:</td><td></td><td><span style='color:red'>[FAILED]</span></td></tr>";
                        // Restore backup file
                        if (file_exists($db)) {
                            rename($db . ".bak", $db);
                        }
                        echo "<tr><td>Restoring backup database:</td><td></td><td><span style='color:green'>[OK]</span></td></tr>";
                    } else {
                        echo "<tr><td>Unpacking archive:</td><td></td><td><span style='color:green'>[OK]</span></td></tr>";
                        // Rename new database
                        if (file_exists($db . ".new")) {
                            rename($db . ".new", $db);
                        }
                        // Remove gzip file
                        if (file_exists($db_gz)) {
                            unlink($db_gz);
                        }
                    }
                } else {
                    echo "<tr><td>Downloaded file size too small.  Aborted.</td><td></td><td><span style='color:red'>[FAILED]</span></td></tr>";
                }
            }
        } else {
            echo "<tr><td>Requesting: </td><td>PHP not built with cURL support: Manual install required</td><td><span style='color:red'>[FAILED]</span></td></tr>";
        }
        echo "</tbody></table>";
    }
    if (isset($_POST['edition'])) {
        die;
    }
}
Exemple #5
0
function luc_update_GeoIP($text, $date_from, $date_to)
{
    echo "<thead><tr><th scope='col' colspan='2'>Updating GeoIP country information</th></tr></thead>\n\t\t\t\t<tbody>\n\t\t\t\t<tr>";
    global $wpdb;
    $table_name = STATPRESS_V_TABLE_NAME;
    $gi = geoip_open(luc_GeoIP_dbname('country'), GEOIP_STANDARD);
    $qry_s = "SELECT ip\n\t\t\t\tFROM {$table_name}\n\t\t\t\tWHERE date BETWEEN {$date_from}\n\t\t\t\t\tAND {$date_to}\n\t\t\t\tGROUP BY ip;";
    $qry = $wpdb->get_results($qry_s);
    foreach ($qry as $rk) {
        $ipAddress = $rk->ip;
        $country = geoip_country_code_by_addr($gi, $ipAddress);
        $qry_u = "UPDATE {$table_name}\n\t\t\t\t\tSET country = '{$country}'\n\t\t\t\t\tWHERE date BETWEEN {$date_from}\n\t\t\t\t\t\tAND {$date_to}\n\t\t\t\t\t\tAND ip = '{$ipAddress}' ;";
        $wpdb->query($qry_u);
    }
    luc_update_footer($wpdb->num_queries, $date_to, $date_from);
    if (isset($text)) {
        $text .= ',';
    }
    $text = $text . " GeoIP";
    return $text;
}