From 7e1b34cf892d0782b1663da00a221a6033c99f83 Mon Sep 17 00:00:00 2001 From: glix08 Date: Mon, 27 Jun 2011 21:39:46 +0000 Subject: [PATCH] r25 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Скрипты восстановления и конфиги. git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@25 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293 --- install/php-fpm+nginx/bash.txt | 5 + install/php-fpm+nginx/fastcgi_params | 31 ++ install/php-fpm+nginx/nginx.conf | 144 ++++++++ other/recover/converter/constants.php | 8 + other/recover/converter/functions.php | 486 ++++++++++++++++++++++++++ other/recover/converter/passwords.php | 2 + other/recover/converter/settings.php | 19 + other/recover/recover.php | 97 +++++ 8 files changed, 792 insertions(+) create mode 100644 install/php-fpm+nginx/bash.txt create mode 100644 install/php-fpm+nginx/fastcgi_params create mode 100644 install/php-fpm+nginx/nginx.conf create mode 100644 other/recover/converter/constants.php create mode 100644 other/recover/converter/functions.php create mode 100644 other/recover/converter/passwords.php create mode 100644 other/recover/converter/settings.php create mode 100644 other/recover/recover.php diff --git a/install/php-fpm+nginx/bash.txt b/install/php-fpm+nginx/bash.txt new file mode 100644 index 000000000..0cb7a314b --- /dev/null +++ b/install/php-fpm+nginx/bash.txt @@ -0,0 +1,5 @@ +$ mkdir /tmp/nginx +$ mkdir /tmp/nginx/fastcgi_temp +$ mkdir /tmp/nginx/client_temp + +$ mkdir /var/log/nginx/ \ No newline at end of file diff --git a/install/php-fpm+nginx/fastcgi_params b/install/php-fpm+nginx/fastcgi_params new file mode 100644 index 000000000..0758053db --- /dev/null +++ b/install/php-fpm+nginx/fastcgi_params @@ -0,0 +1,31 @@ +fastcgi_connect_timeout 60; +fastcgi_send_timeout 180; +fastcgi_read_timeout 180; +fastcgi_buffer_size 32k; +fastcgi_buffers 4 32k; +fastcgi_busy_buffers_size 32k; +fastcgi_temp_file_write_size 32k; +fastcgi_temp_path /tmp/nginx/fastcgi_temp 1 2; + +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; diff --git a/install/php-fpm+nginx/nginx.conf b/install/php-fpm+nginx/nginx.conf new file mode 100644 index 000000000..970e6703d --- /dev/null +++ b/install/php-fpm+nginx/nginx.conf @@ -0,0 +1,144 @@ +user www www; +worker_processes 4; + +#error_log /var/log/nginx/error.log; +#error_log /var/log/nginx/error.log notice; +#error_log /var/log/nginx/error.log info; + +pid /var/run/nginx.pid; + +worker_rlimit_nofile 1024; +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] $request ' + # '"$status" $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #log_format IP .$remote_addr.; + + access_log off; + + server_tokens off; + reset_timedout_connection on; + + sendfile on; + + # http://en.wikipedia.org/wiki/Asynchronous_I/O + # aio sendfile; + + output_buffers 1 64k; + + tcp_nopush on; + tcp_nodelay on; + send_lowat 12000; + log_not_found off; + + keepalive_timeout 65; + + limit_req_zone $binary_remote_addr zone=one:16m rate=5r/s; + + gzip on; + gzip_vary on; + gzip_min_length 2048; + gzip_comp_level 5; + gzip_http_version 1.0; + gzip_proxied any; + gzip_disable "msie6"; + gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + client_max_body_size 10m; + large_client_header_buffers 4 8k; + client_body_temp_path /tmp/nginx/client_temp 1 2; + + server { + #listen 80 default sndbuf=32k rcvbuf=8k accept_filter=httpready; + #listen [::]:80 default sndbuf=32k rcvbuf=8k accept_filter=httpready; + + listen 80 default sndbuf=32k rcvbuf=8k; + server_name sitedomain.ru; + + charset utf8; + + access_log off; + + location / { + root /var/www; + index index.html index.htm index.php; + } + + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + + # pass the PHP scripts to FastCGI server listening on /tmp/php.sock; + # + location ~ \.php$ { + #limit_req zone=one burst=20 nodelay; + #limit_req_log_level info; + + root /var/www; + fastcgi_index index.php; + fastcgi_pass unix:/tmp/php.sock; # 127.0.0.1:9000; + fastcgi_intercept_errors on; + + # FreeBSD Optimization + fastcgi_pass_request_body off; + client_body_in_file_only clean; + fastcgi_param REQUEST_BODY_FILE $request_body_file; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; + + include fastcgi_params; + } + + location ^~ /bt/ { + access_log off; +# if ( $query_string ~ "^uk=([^&?]{10})[&?]+(.*)$" ) { +# set $uk $1; +# set $qs $2&ip=$remote_addr; +# } +# if ( $query_string ~ "^uk=([^&?]{10})[&?]+((.*&|)ip=.*)$" ) { +# set $uk $1; +# set $qs $2; +# } +# if ( $qs ) { +# rewrite ^.*/([a-z]+)(\.php|)$ /$uk/$1?$qs break; +# } + rewrite ^/?(.*)$ /$1?ip=$remote_addr&$query_string break; + proxy_pass http://127.0.0.1:2710/; + } + + # Cached Images + location ~* \.(jpg|jpeg|gif|png|css|js|ico)$ { + root /var/www; + access_log off; + expires 30d; + add_header Cache-Control public; + } + + location ~ \/admin|backup\/ { + deny all; + # allow YOUR_IP; + } + # Deny folder (Sec. lvl1) + location ~ \/(cache|log|attach_mod|cache|config|includes|language|triggers)\/ { + deny all; + } + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # deny sql,tpl,db,inc,log + location ~ /\.ht { + deny all; + } + location ~ \.(.*sql|tpl|db|inc|log)$ { + deny all; + } + } +} \ No newline at end of file diff --git a/other/recover/converter/constants.php b/other/recover/converter/constants.php new file mode 100644 index 000000000..a49badd5d --- /dev/null +++ b/other/recover/converter/constants.php @@ -0,0 +1,8 @@ +" : ''; + $err = ''; + + echo '
'; + echo "OK - $sql". str_repeat(' ', 256) ."\n
"; + echo '
'; +} + +function hex2bin($h) +{ + if (!is_string($h)) return null; + $r=''; + for ($a=0; $afetch_row("SELECT MAX($column) AS $column FROM $table_name LIMIT 1"); + return $row[$column]; +} + +function get_count($table_name, $column) +{ + global $db; + + $row = $db->fetch_row("SELECT COUNT($column) AS $column FROM $table_name LIMIT 1"); + return $row[$column]; +} + +function set_auto_increment($table_name, $column, $val = null) +{ + global $db; + + if (empty($val)) + { + $row = $db->fetch_row("SELECT MAX($column) AS val FROM $table_name LIMIT 1"); + $db->sql_freeresult(); + $val = (int) $row['val'] + 1; + } + $db->query("ALTER TABLE $table_name auto_increment = $val"); +} + +//Users functions +function tp_users_cleanup() +{ + global $db; + + /* + if (!function_exists('user_delete')) require_once('./includes/functions_admin.php'); + + if ($row = $db->fetch_row("SELECT user_id FROM ". USERS_TABLE ." WHERE user_id NOT IN(". EXCLUDED_USERS_CSV .');')) + { + foreach ($row as $user) + { + user_delete($user['user_id']); + } + }*/ + $db->query('DELETE FROM '. USERS_TABLE .' WHERE user_id NOT IN('. EXCLUDED_USERS_CSV .')'); + $db->query('TRUNCATE '. BT_USERS_TABLE); +} + +function tp_user_level($tb_class) +{ + switch($tb_class) + { + case 0: + case 1: + case 2: + case 3: + $level = 0; + break; + case 4: + $level = 2; + break; + case 5: + case 6: + case 7: + $level = 1; + break; + default: + $level = 0; + break; + } + return $level; +} + +function convert_user($user) +{ + global $db; + + $user_data = array( + "user_id" => $user['id'], + "user_active" => ($user['enabled'] == 'yes') ? true : false, + "username" => $user['username'], + "user_password" => md5($user['password']), + "user_lastvisit" => $user['last_access'], + "user_regdate" => $user['added'], + "user_level" => tp_user_level($user['class']), + "user_lang" => $user['language'], + "user_dateformat" => "Y-m-d H:i", + //"user_opt" => , + "user_avatar" => !empty($user['avatar']) ? $user['avatar'] : null, + "user_avatar_type" => !empty($user['avatar']) ? 2 : null, + "user_email" => $user['email'], + "user_website" => $user['website'], + "user_icq" => $user['icq'], + "user_aim" => $user['aim'], + "user_yim" => $user['yahoo'], + "user_msnm" => $user['msn'], + ); + + $columns = $values = array(); + + foreach ($user_data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_columns = implode(',', $columns); + $sql_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO ". USERS_TABLE . " ($sql_columns) VALUES($sql_values);"); + + $bt_user_data = array( + "user_id" => $user['id'], + "auth_key" => make_rand_str(BT_AUTH_KEY_LENGTH), + "u_up_total" => $user['uploaded'], + "u_down_total" => $user['downloaded'], + ); + $columns = $values = array(); + + foreach ($bt_user_data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_bt_columns = implode(',', $columns); + $sql_bt_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO ". BT_USERS_TABLE . " ($sql_bt_columns) VALUES($sql_bt_values);"); +} + +//Torrents and categories functions +function tp_categories_cleanup() +{ + global $db; + + $db->query('DELETE FROM '. CATEGORIES_TABLE); +} + +function tp_add_category_old($id, $cat_title) +{ + global $db; + + $db->query("INSERT IGNORE INTO ". CATEGORIES_TABLE ." (cat_id, cat_title) + VALUES ($id, '". $db->escape($cat_title) ."')"); + return; +} + +function tp_add_category($cat_data) +{ + global $db; + + $columns = $values = array(); + + foreach ($cat_data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_bt_columns = implode(',', $columns); + $sql_bt_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO ". CATEGORIES_TABLE . " ($sql_bt_columns) VALUES($sql_bt_values);"); +} + +function tp_topics_cleanup() +{ + global $db; + + $db->query("TRUNCATE ". ATTACHMENTS_TABLE); + $db->query("TRUNCATE ". ATTACHMENTS_DESC_TABLE); + $db->query("TRUNCATE ". BT_TORRENTS_TABLE); + $db->query("TRUNCATE ". POSTS_TABLE); + $db->query("TRUNCATE ". POSTS_HTML_TABLE); + $db->query("TRUNCATE ". POSTS_SEARCH_TABLE); + $db->query("TRUNCATE ". POSTS_TEXT_TABLE); + $db->query("TRUNCATE ". TOPICS_TABLE); + /*if (!function_exists('topic_delete')) require_once('./includes/functions_admin.php'); + + if ($row = $db->fetch_row("SELECT topic_id FROM ". TOPICS_TABLE)) + { + foreach ($row as $topic) + { + topic_delete($topic['topic_id']); + } + }*/ + + return; +} + +function tp_add_topic($topic_data) +{ + global $db; + + $columns = $values = array(); + foreach ($topic_data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_columns = implode(',', $columns); + $sql_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO ". TOPICS_TABLE . " ($sql_columns) VALUES($sql_values);"); + return; +} + +function tp_add_post($post_data) +{ + global $db; + + foreach ($post_data as $key => $data) + { + $columns = $values = array(); + foreach ($data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_columns = implode(',', $columns); + $sql_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO bb_{$key} ($sql_columns) VALUES($sql_values);"); + } + return; +} + +function tp_add_attach($attach_data) +{ + global $db; + + foreach ($attach_data as $key => $data) + { + $columns = $values = array(); + foreach ($data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_columns = implode(',', $columns); + $sql_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO bb_{$key} ($sql_columns) VALUES($sql_values);"); + } + return; +} + +function make_img_path ($name) +{ + global $bb_cfg; + + return make_url("files/images/" . $name); +} + +function append_images($tor) +{ + $poster = $screens = ''; + switch(TR_TYPE) + { + case 'yse': + if(!empty($tor['image1'])) + { + $poster = "[img=right]".make_img_path($tor['image1'])."[/img]"; + } + if(!empty($tor['image2'])) + { + $screens = '[spoiler=""][img]'.make_img_path($tor['image2'])."[/img][/spoiler]"; + } + break; + case 'sky': + if(!empty($tor['poster'])) + { + $poster = "[img=right]".make_img_path($tor['poster'])."[/img]"; + } + $has_screens = !empty($tor['screenshot1']) || !empty($tor['screenshot2']) || !empty($tor['screenshot3']) || !empty($tor['screenshot4']); + if ($has_screens) + { + $screens .= '[spoiler=""]'; + for ($i = 1; $i<=4; $i++) + { + if(!empty($tor['screenshot'.$i])) + { + $screens .= "[img]".make_img_path($tor['screenshot'.$i])."[/img] \n"; + } + } + $screens .= "[/spoiler]"; + } + break; + } + return ($poster . $tor['descr'] . $screens); +} + +function convert_torrent($torrent) +{ + global $db; + + $topic_data = array( + "topic_id" => $torrent['topic_id'], + "forum_id" => $torrent['category'], + "topic_title" => $torrent['name'], + "topic_poster" => $torrent['owner'], + "topic_time" => $torrent['added'], + "topic_views" => $torrent['views'], + "topic_type" => ($torrent['sticky'] == 'yes') ? 1 : 0, + "topic_first_post_id" => $torrent['id'], + "topic_last_post_id" => $torrent['id'], + "topic_attachment" => 1, + "topic_dl_type" => 1, + "topic_last_post_time" => $torrent['added'], + ); + tp_add_topic($topic_data); + + $bbcode_uid = make_bbcode_uid(); + //$post_text = prepare_message($torrent['descr'], true, true, $bbcode_uid); + $post_text = stripslashes(prepare_message(addslashes(unprepare_message($torrent['descr'])), true, true, $bbcode_uid)); + + $post_data = array( + "posts" => array( + "post_id" => $torrent['post_id'], + "topic_id" => $torrent['topic_id'], + "forum_id" => $torrent['category'], + "poster_id" => $torrent['owner'], + "post_time" => $torrent['added'], + "post_attachment" => 1, + ), + "posts_text" => array( + "post_id" => $torrent['post_id'], + "bbcode_uid" => $bbcode_uid, + "post_text" => $post_text, + ), + "posts_search" => array( + "post_id" => $torrent['post_id'], + "search_words" => $torrent['search_text'], + ), + ); + tp_add_post($post_data); + + $attach_data = array( + "attachments" => array( + "attach_id" => $torrent['attach_id'], + "post_id" => $torrent['post_id'], + "user_id_1" => $torrent['owner'], + ), + "attachments_desc" => array( + "attach_id" => $torrent['attach_id'], + "physical_filename" => $torrent['id'] . ".torrent", + "real_filename" => $torrent['filename'], + "extension" => "torrent", + "mimetype" => "application/x-bittorrent", + "filesize" => @filesize(get_attachments_dir() .'/'. $torrent['id'] .".torrent"), + "filetime" => $torrent['added'], + "tracker_status" => 1, + ), + ); + tp_add_attach($attach_data); + + //Torrents + if (BDECODE) + { + $filename = get_attachments_dir() .'/'. $torrent['id'] .".torrent"; + if (!file_exists($filename)) + { + return; + } + if (!function_exists('bdecode_file')) include_once('./includes/functions_torrent.php'); + $tor = bdecode_file($filename); + $info = ($tor['info']) ? $tor['info'] : array(); + $info_hash = pack('H*', sha1(bencode($info))); + $info_hash_sql = rtrim($db->escape($info_hash), ' '); + } + else + { + $info_hash_sql = hex2bin($torrent['info_hash']); + } + + $torrent_data = array( + "info_hash" => $info_hash_sql, + "post_id" => $torrent['post_id'], + "poster_id" => $torrent['owner'], + "topic_id" => $torrent['topic_id'], + "forum_id" => $torrent['category'], + "attach_id" => $torrent['attach_id'], + "size" => $torrent['size'], + "reg_time" => $torrent['added'], + "complete_count" => $torrent['times_completed'], + "seeder_last_seen" => $torrent['lastseed'], + ); + + $columns = $values = array(); + + foreach ($torrent_data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_columns = implode(', ', $columns); + $sql_values = implode(', ', $values); + + $db->query("INSERT IGNORE INTO ". BT_TORRENTS_TABLE . " ($sql_columns) VALUES($sql_values);"); + return; +} + +//Comments functions +function convert_comment($comment) +{ + global $db; + + $bbcode_uid = make_bbcode_uid(); + $post_text = prepare_message($comment['text'], true, true, $bbcode_uid); + + $post_data = array( + "posts" => array( + "post_id" => $comment['id'], + "topic_id" => $comment['torrent'], + "forum_id" => $comment['category'], + "poster_id" => $comment['user'], + "post_time" => $comment['added'], + "poster_ip" => encode_ip($comment['ip']), + "post_edit_time" => $comment['editedat'], + "post_edit_count" => $comment['editedat'] ? 1 : 0, + ), + "posts_text" => array( + "post_id" => $comment['id'], + "bbcode_uid" => $bbcode_uid, + "post_text" => $post_text, + ), + ); + tp_add_post($post_data); + //add_search_words($comment['id'], stripslashes($post_text)); + return; +} + +//Forums functions +function tp_forums_cleanup() +{ + global $db; + + $db->query('TRUNCATE '. FORUMS_TABLE); +} + +function convert_cat($forum, $allow_torrents = true) +{ + global $db; + + $forum_data = array( + "forum_id" => $forum['id'], + "cat_id" => $forum['cat_id'], + "forum_name" => $forum['name'], + "forum_order" => $forum['sort'], + "allow_reg_tracker" => $allow_torrents, + "allow_dl_topic" => $allow_torrents, + ); + + $columns = $values = array(); + + foreach ($forum_data as $column => $value) + { + $columns[] = $column; + $values[] = "'". $db->escape($value) ."'"; + } + $sql_columns = implode(',', $columns); + $sql_values = implode(',', $values); + + $db->query("INSERT IGNORE INTO ". FORUMS_TABLE . " ($sql_columns) VALUES($sql_values);"); + return; +} diff --git a/other/recover/converter/passwords.php b/other/recover/converter/passwords.php new file mode 100644 index 000000000..5f7aafe87 --- /dev/null +++ b/other/recover/converter/passwords.php @@ -0,0 +1,2 @@ +session_start(); + +while (@ob_end_flush()); +ob_implicit_flush(); + +?> + + + + + + + + + +
+
+ +
+
+ + '; + + exit; +} +else +{ + +@ini_set('memory_limit', '512M'); +@ini_set('max_execution_time', @ini_get('max_execution_time') + 1200); + +$torrents_count = (int) get_count(BT_TORRENTS_TABLE, 'attach_id'); +$loops = (int) ceil($torrents_count / C_TORRENTS_PER_ONCE); + +$not_exist = array(); + +$attach_dir = get_attachments_dir() .'/'; + +for ($i = 0; $i < $loops; $i++) +{ + $start = $i * C_TORRENTS_PER_ONCE; + $offset = C_TORRENTS_PER_ONCE; + + $sql = "SELECT + tor.attach_id, tor.topic_id, ad.physical_filename + FROM ". BT_TORRENTS_TABLE ." tor + LEFT JOIN ". ATTACHMENTS_DESC_TABLE ." ad ON(ad.attach_id = tor.attach_id) + ORDER BY tor.attach_id + LIMIT $start, $offset"; + + $torrents = $db->fetch_rowset($sql); + $db->sql_freeresult(); + + foreach ($torrents as $torrent) + { + $filename = $attach_dir . $torrent['physical_filename']; + if (!file_exists($filename)) + { + $not_exist[] = ''. $filename .''; + } + else + { + $tor = bdecode_file($filename); + $info = (!empty($tor['info'])) ? $tor['info'] : array(); + $info_hash = pack('H*', sha1(bencode($info))); + $info_hash_sql = rtrim($db->escape($info_hash), ' '); + + $db->query("UPDATE ". BT_TORRENTS_TABLE ." + SET info_hash = '$info_hash_sql' + WHERE attach_id = {$torrent['attach_id']}"); + } + } +} + +print_ok ("Completed"); + +if(!empty($not_exist)) +{ + print_ok ("These torrents doesn't exist in filesystem: ". implode(', ', array_unique($not_exist))); +} + +}