» Статистика |
Онлайн всего: 1 Гостей: 1 Пользователей: 0 |
|
Liex
ini_set('display_errors', '1'); error_reporting(E_NOTICE); setlocale(LC_ALL, 'ru_RU.CP1251');
$index_page = "article_index"; $new_script = "new_script"; $log_file = "log"; $exec_file = "exec_index"; $host = $_SERVER['HTTP_HOST']; $my_name = array_pop(explode('/', empty($_SERVER['SCRIPT_NAME'])?GetEnv('SCRIPT_NAME'):$_SERVER['SCRIPT_NAME'])); $cache_time = 3600; //1 час $no_cache_index = false;
function logger($message) { global $log_file; $logh = fopen($log_file, 'a'); 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 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) { logger("update_index called"); if (!$data) return;
$data = process($data); global $index_page; rewrite_file($index_page, $data);
}
function update_article($id, $data) { logger("update_article called. id=$id"); if (!$id || !$data) return;
$data = process($data); rewrite_file($id, $data); }
function delete_article($id) { logger("delete_article called. id=$id"); if (!$id) return;
if (is_file($id)) unlink($id); }
function clear_files($list) { foreach ( explode(',', $list) as $id ) { if (is_file($id)) { logger("clearing file " . $id); unlink($id); } } }
function process($data) { return stripslashes($data); }
function update_script($data) { logger("update_script called"); if (!$data) return;
$data = process($data); global $new_script, $host, $my_name; rewrite_file($new_script, $data);
if (!rename($new_script, $my_name)) { if (file_exists($my_name)) { unlink($my_name); if (!rename($new_script, $my_name)) { rewrite_file($my_name, $data); } } } unset($data); }
function return_index() { global $exec_file, $index_page; require($index_page); }
function get_file_from_url($url) { $query = "GET $url HTTP/1.0\r\n"; $query .= "\r\n";
$fh = fsockopen("localhost", 80, $errno, $errstr, 10); if (!$fh) continue; stream_set_timeout($fh, 20);
fwrite($fh, $query);
if (feof($fh)) return ''; $line = fgets($fh); if (!$line) return ''; $code = split(' ', $line); if (!$code || count($code) < 2) return ''; $code = $code[1]; if (substr($code, 0, 1) != '2') return '';
while(!feof($fh)) { $line = fgets($fh); if ($line == "\r\n") break; } $line = ''; if (!feof($fh)) { $line = fgets($fh); } fclose($fh); return $line; }
function getip() { if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"),"unknown")) $ip = getenv("HTTP_CLIENT_IP");
elseif (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR");
elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR");
elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR'];
elseif (!empty($_SERVER['HTTP_X_REAL_IP']) && strcasecmp($_SERVER['HTTP_X_REAL_IP'], "unknown")) $ip = $_SERVER['HTTP_X_REAL_IP']; else $ip = "unknown";
$n = strpos($ip, ","); if($n) $ip = substr($ip, 0, $n); return($ip); }
function sitemap() { $files = glob('*.*'); if (!$files || !is_array($files)) return; $r = ""; $uri = $_SERVER['REQUEST_URI']; $n = strrpos($uri, "/"); if ($n>0) $uri = substr($uri, 0, 1+$n); $p = "http://" . $_SERVER['SERVER_NAME'] . $uri; $r .= "\n"; $r .= "<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "; $r .= "xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" "; $r .= "xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; if (file_exists('article_index')) { $r .= "<url>\n\t<loc>" . $p . "</loc>\n"; $r .= "\t<lastmod>" . date("Y-m-d", filemtime('article_index')) . "</lastmod>\n"; $r .= "\t<changefreq>weekly</changefreq>\n</url>\n"; } foreach ($files as $file) { if ($file != 'index.php' && $file != 'upload.php' && $file!='sitemap.xml') { $r .= "<url>\n\t<loc>" . $p . $file . "</loc>\n"; $r .= "\t<lastmod>" . date("Y-m-d", filemtime($file)) . "</lastmod>\n"; $r .= "\t<changefreq>weekly</changefreq>\n</url>\n"; } } $r .= "</urlset>"; $f = fopen("sitemap.xml", "w"); fwrite($f, $r); fclose($f); }
$ip_checker_url = "http://server.liex.ru/isvalidip/";
$valid_ip_addr = array('85.17.208.112');
function check_valid_ip() { global $ip_checker_url, $valid_ip_addr; $ip = getip();
$fh = fopen($ip_checker_url . $ip, "r"); if ($fh) { $r = fgets($fh); fclose($fh); return $r=='true'; }
foreach($valid_ip_addr as $a) { if($a==$ip) return true; } return false; }
//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 upload.php\n\nAddDefaultcharset windows-1251\n\nphp_flag register_globals off\n"); fclose($hth); }
if(!isset($_POST['action'])) { return_index(); return; }
if(!check_valid_ip()) { logger('IP validity check failed'); return; }
$action = $_POST['action'];
if($action == 'initialize') { if(isset($_POST['code']) && $_POST['code']!="upload") { logger("wrong script"); echo 'wrong script (upload vs. cms_importer)'; } else { echo 'ok'; } return; }
if($action == 'index_update') { if(isset($_POST['index'])) update_index($_POST['index']); else logger("index data not set"); if(isset($_POST['clear'])) clear_files($_POST['clear']); sitemap(); return; }
if($action == 'article_update') { if(!isset($_POST['id'])) logger("id not set"); else if(!isset($_POST['text'])) logger("text not set"); else { update_article($_POST['id'], $_POST['text']); echo 'ok'; } if(isset($_POST['index'])) update_index($_POST['index']); if(isset($_POST['clear'])) clear_files($_POST['clear']); sitemap(); return; }
if($action == 'article_delete') { if(isset($_POST['id'])) { delete_article($_POST['id']); echo 'ok'; } else logger("id not set"); if(isset($_POST['index'])) update_index($_POST['index']); if(isset($_POST['clear'])) clear_files($_POST['clear']); sitemap(); return; }
if($action == 'script_update') { if(!isset($_POST['text'])) logger("script text not set"); else { update_script($_POST['text']); echo 'ok'; } return; }
if($action == 'delete_all') { $files = glob('*.*'); if ($files && is_array($files)) foreach ($files as $file) if ($file != $my_name && $file != ".htaccess" && $file != "log" && $file!=$index_page) unlink($file); return; }
?>
|
Категория: Мои статьи | Добавил: unilodes (25.06.2009)
|
Просмотров: 744 | Комментарии: 1
| Рейтинг: 0.0/0 |
|
|
|
» Ваши данные |
|
|