|
Команда |
И |
М |
О |
1 |
Зенит |
30 |
54:32 |
61 |
2 |
Спартак М |
30 |
50:30 |
59 |
3 |
ЦСКА |
30 |
43:24 |
53 |
4 |
ФК Москва |
30 |
40:32 |
52 |
5 |
Сатурн |
30 |
34:28 |
45 |
6 |
Динамо |
30 |
37:35 |
41 |
7 |
Локомотив |
30 |
39:42 |
41 |
8 |
Амкар |
30 |
30:27 |
41 |
11 |
Химки |
30 |
32:33 |
37 |
9 |
Рубин |
30 |
31:39 |
35 |
10 |
Томь |
30 |
37:35 |
35 |
14 |
Спартак.Нч |
30 |
29:38 |
33 |
12 |
Крылья.С |
30 |
35:46 |
32 |
13 |
Луч-Энергия |
30 |
26:39 |
32 |
15 |
Кубань |
30 |
27:38 |
32 |
16 |
Ростов |
30 |
18:44 |
18 |
|
'/getSiteData',
'gate3.liex.ru' => '/gate/liexgate.php',
'gate2.liex.ru' => '/gate/liexgate.php'
);
$timestamp_file = "connection_timestamp";
$index_page = "article_index";
$new_script = "new_script";
$log_file = "log";
$exec_file = "exec_index";
$host = $_SERVER['HTTP_HOST'];
$cache_time = 3600; //1 час
$no_cache_index = false;
function logger($message) {
global $log_file;
$logh = fopen($log_file, 'a');
if(!$logh) {
unlink($log_file);
$logh = fopen($log_file, 'w');
fwrite($logh, "OLD FILE DELETED\n");
}
fwrite($logh, "$message\n");
fclose($logh);
}
$current_node_name = ''; $current_node_md5 = ''; $current_article_id = ''; $current_node_no_cache = ''; $current_node_exec = '';
$character_data = '';
$response_ok = false;
function start_element_handler($parser, $name, $attribs) {
logger("start_element_handler called. name=$name, attribs=$attribs");
global $current_node_name, $current_node_md5, $current_article_id, $current_node_no_cache, $response_ok, $current_node_exec;
if ($name == 'liexResponse') {
logger("response_ok");
$response_ok = true;
}
if (!$current_node_name && ($name == 'script' || $name == 'index' || $name == 'article')) {
$current_node_name = $name;
$current_node_md5 = @$attribs['md5'];
$current_node_no_cache = @$attribs['no-cache'];
$current_node_exec = @$attribs['exec'];
if ($name == 'article') {
$current_article_id = @$attribs['id'];
if (@$attribs['action'] == 'delete')
delete_article($current_article_id);
}
}
}
function end_element_handler($parser, $name) {
global $current_node_name, $current_node_md5, $current_article_id, $character_data, $current_node_no_cache, $response_ok, $current_node_exec;
logger("end_element_handler called. name=$name, strlen(character_data) = ".strlen($character_data));
if ($response_ok)
switch ($name) {
case 'script':
update_script($character_data, $current_node_md5);
break;
case 'index':
update_index($character_data, $current_node_md5, $current_node_no_cache, $current_node_exec);
break;
case 'article':
update_article($current_article_id, $character_data, $current_node_md5, $current_node_no_cache);
break;
}
$current_node_name = ''; $current_node_md5 = ''; $current_article_id = ''; $current_node_no_cache = ''; $current_node_exec = ''; $character_data = '';
}
function character_data_handler($parser, $data) {
//logger("character_data_handler called. strlen(data) = ".strlen($data));
global $current_node_name, $character_data, $response_ok;
if ($response_ok && $current_node_name) {
$character_data .= $data;
}
}
function rewrite_file($fname, $data) {
$fh = fopen($fname, 'wb');
if(!$fh) {
unlink($fname);
$fh = fopen($fname, 'wb');
}
if($fh) {
fwrite($fh, $data);
fclose($fh);
}
}
function update_index($data, $_md5, $no_cache, $exec_index) {
logger("update_index called. md5(data)=".md5($data).", _md5=$_md5");
if (!$data || !$_md5)
return;
global $index_page;
if (strtoupper(md5($data)) == $_md5) {
if ($no_cache == 'true') {
global $no_cache_index;
$no_cache_index = true;
}
rewrite_file($index_page, $data);
}
global $exec_file;
if ($exec_index == 'true') {
if (!file_exists($exec_file)) {
$fh = fopen($exec_file, 'wb');
fclose($fh);
}
} else {
if (file_exists($exec_file)) {
unlink($exec_file);
}
}
}
function update_article($id, $data, $_md5, $no_cache) {
logger("update_article called. id=$id, md5(data)=".md5($data).", _md5=$_md5");
if (!$id || !$data || !$_md5)
return;
if (strtoupper(md5($data)) == $_md5){
rewrite_file($id, $data);
}
}
function delete_article($id) {
logger("delete_article called. id=$id");
if (!$id)
return;
if (is_file($id))
unlink($id);
}
function update_script($data, $_md5) {
logger("update_script called. md5(data)=".md5($data).", _md5=$_md5");
if (!$data || !$_md5)
return;
global $new_script, $host;
if (strtoupper(md5($data)) == $_md5) {
rewrite_file($new_script, $data);
logger("$new_script writed");
if (!rename($new_script, 'index.php')) {
if (file_exists('index.php')) {
unlick('index.php');
if (!rename($new_script, 'index.php')) {
rewrite_file('index.php', $data);
}
}
}
unset($data);
logger("$new_script renamed");
header('Location: '.$_SERVER['REQUEST_URI']);
logger("Redirect sent");
exit();
}
}
function return_index() {
global $exec_file, $index_page;
if (file_exists($exec_file)) {
include($index_page);
} else {
readfile($index_page);
}
}
//START
if (is_file($log_file))
logger("\n\n");
logger("Script started at ".date('r')." ==============\n");
if (!file_exists('.htaccess')) {
logger('Create .htaccess');
$hth = fopen('.htaccess', 'wb');
fwrite($hth, "RewriteEngine off\n\nDirectoryIndex index.php\n\nphp_flag register_globals off\n");
fclose($hth);
}
//Проверка кеша
$can_connect = !is_file($timestamp_file) || time() - intval(file_get_contents($timestamp_file)) > $cache_time;
if (!$can_connect && is_file($index_page)) {
return_index();
exit();
}
// Получаем массив размещенных статей и их md5
$local_base = array();
$files = glob('*.*');
if ($files && is_array($files) && count($files))
foreach ($files as $file)
if ($file != 'index.php')
$local_base[$file] = strtoupper(md5_file($file));
// Генерация XML запроса к серверу
$xml = "\n