Просмотр файла dl/admin_backup.php

Размер файла: 9.09Kb
<? 
#********************************** AgS MOD DOWNLOAD CENTR SEA *************************************#
#***************************************************************************************************#
#  /||||||||||||||| *********************  /||||||||||||||| *********************  /||||||||||||||| #
# | ||||||||||||||| ********************* | ||||||||||||||| ********************* | ||||||||||||||| #
# | |||||/////||||| ********************* | |||||/////////  ********************* | |||||/////////  #
# | |||||   | ||||| ****** E-MAIL ******* | |||||           ****** WAP/WEB ****** | |||||           #
# | |||||   | ||||| *** [email protected] *** | |||||           * http://ags.h2m.ru * | ||||||||||||||| #
# | |||||   | ||||| ********************* | ||||||||||||||| ********************* | ||||||||||||||| #
# | |||||   | ||||| ********************* | |||||/////||||| ********************* |///////////||||| #
# | ||||||||||||||| ****** SKYPE ******** | |||||   | ||||| ***** MOD AUTHOR ****           | ||||| #
# | |||||////|||||| ***** agrizz15 ****** | |||||   | ||||| ***** Agris Cišs ****  /||||||||||||||| #
# | |||||   | ||||| ********************* | ||||||||||||||| ********************* | ||||||||||||||| #
# |/////    |/////  ********************* |///////////////  ********************* |///////////////  #
#***************************************************************************************************#
#********************************* MOD by AgS in 2010 @ LATVIA *************************************#


require_once"system/start.php";
require_once"system/config.php";
require_once"system/db.php";
require_once"system/head.php";
require_once"lng/$setup[lng]/lng.php";
require_once"system/functions.php";
require_once"system/cookies.php";
require_once"system/counter.php";


$structure_only=false;//Iegūstam netikai struktūru

/* Atļaujam tikai adminam */
if ($setup['adnick']==$_SESSION['log'] && $setup['adpass']==md5($_SESSION['par']) && $_SESSION['log']!="" && md5($_SESSION['par'])!="") {


/* Funkcija datu iegūšanai un apstrādei no MYSQL servera */
function mysqlbackup($MY_serveris,$MY_DB_user, $uid, $pwd, $structure_only, $crlf) {

/* Iegūstam MYSQL versiju */
$result=@mysql_query("SELECT VERSION() AS version");

if ($result != FALSE && @mysql_num_rows($result) > 0) {
$row   = @mysql_fetch_array($result);
$match = explode('.', $row['version']);
} else {
$result=@mysql_query("SHOW VARIABLES LIKE \'version\'"); 

if ($result != FALSE && @mysql_num_rows($result) > 0){
$row   = @mysql_fetch_row($result);
$match = explode('.', $row[1]);}}

/* Iegūstam versijas ciparus */
if (!isset($match) || !isset($match[0])) {
$match[0] = 3;}

if (!isset($match[1])) {
$match[1] = 21;}

if (!isset($match[2])) {
$match[2] = 0;}

if(!isset($row)) {
$row = '3.21.0';}

/* Definējam MYSQL versiju un ciparus */
define('MYSQL_INT_VERSION', (int)sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2])));
define('MYSQL_STR_VERSION', $row['version']);

unset($match);


/* Izvadam SQL faila sākumu */
$sql .= dl_167.$crlf;//Nosaukums
$sql .= dl_168.$crlf;//Laiks
$sql .= dl_169.': '.MYSQL_STR_VERSION.$crlf;//Serveris MYSQL
$sql .= dl_170.$crlf;//Saits
$sql .= dl_171.$crlf;//Hosts
$sql .= dl_172.$crlf;//Datubāze
$sql .= dl_173.$crlf;//E-Pasts


$sql .= $crlf.$crlf.$crlf;//atstarpe

out(1,$sql);


/* Iegūstam un apstrādājam datus */
$res=@mysql_list_tables($MY_DB_user);  
$nt=@mysql_num_rows($res);  

for ($a=0;$a<$nt;$a++) {
$row=mysql_fetch_row($res);  
$tablename=$row[0];
$sql=$crlf."# ----------------------------------------".$crlf."# ".dl_174." '".$tablename."' ".dl_175." ".$crlf;

if (MYSQL_INT_VERSION >= 32321) {
$result=mysql_query("SHOW CREATE TABLE $tablename");

if ($result != FALSE && mysql_num_rows($result) > 0) {
$tmpres = mysql_fetch_array($result);
$pos = strpos($tmpres[1], ' (');
$tmpres[1] = substr($tmpres[1], 0, 13). $tmpres[0]. substr($tmpres[1], $pos);
$sql .= $tmpres[1].";".$crlf.$crlf;}
mysql_free_result($result);} else {
$sql.="CREATE TABLE $tablename(".$crlf;  
$result=mysql_query("show fields  from $tablename",$con);  

while ($row = mysql_fetch_array($result)) {
$sql .= "  ".$row['Field'];
$sql .= ' ' . $row['Type'];

if (isset($row['Default']) && $row['Default'] != '') {
$sql .= ' DEFAULT \'' . $row['Default'] . '\'';}

if ($row['Null'] != 'YES') {
$sql .= ' NOT NULL';}

if ($row['Extra'] != '') {
$sql .= ' ' . $row['Extra'];}
$sql .= ",".$crlf;}
mysql_free_result($result);
$sql = ereg_replace(',' . $crlf . '$', '', $sql);
$result = mysql_query("SHOW KEYS FROM $tablename");

while ($row = mysql_fetch_array($result)) {
$ISkeyname    = $row['Key_name'];
$IScomment  = (isset($row['Comment'])) ? $row['Comment'] : '';
$ISsub_part = (isset($row['Sub_part'])) ? $row['Sub_part'] : '';

if ($ISkeyname != 'PRIMARY' && $row['Non_unique'] == 0) {
$ISkeyname = "UNIQUE|$kname";}

if ($IScomment == 'FULLTEXT') {
$ISkeyname = 'FULLTEXT|$kname';}

if (!isset($index[$ISkeyname])) {
$index[$ISkeyname] = array();}

if ($ISsub_part > 1) {
$index[$ISkeyname][] = $row['Column_name'] . '(' . $ISsub_part . ')';} else {
$index[$ISkeyname][] = $row['Column_name'];}}
mysql_free_result($result);

while (list($x, $columns) = @each($index)) {
$sql     .= ",".$crlf;

if ($x == 'PRIMARY') {
$sql .= '  PRIMARY KEY (';} else if (substr($x, 0, 6) == 'UNIQUE') {
$sql .= '  UNIQUE ' . substr($x, 7) . ' (';} else if (substr($x, 0, 8) == 'FULLTEXT') {
$sql .= '  FULLTEXT ' . substr($x, 9) . ' (';} else {
$sql .= '  KEY ' . $x . ' (';}
$sql .= implode($columns, ', ') . ')';}
$sql .=  $crlf.");".$crlf.$crlf;}

out(1,$sql);

/* Pārbaudam vai vajaga iegūt tabulas saturu */
if ($structure_only == FALSE) {
$result = mysql_query("SELECT * FROM  $tablename");
$fields_cnt   = mysql_num_fields($result);

while ($row = mysql_fetch_row($result)) {
$table_list     = '(';

for ($j = 0; $j < $fields_cnt; $j++) {
$table_list .= mysql_field_name($result, $j) . ', ';}
$table_list = substr($table_list, 0, -2);
$table_list     .= ')';
$sql = 'INSERT INTO ' . $tablename. ' VALUES (';

for ($j = 0; $j < $fields_cnt; $j++) {

if (!isset($row[$j])) {
$sql .= ' NULL, ';} else if ($row[$j] == '0' || $row[$j] != '') {
$type = mysql_field_type($result, $j);

if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
$type == 'bigint'  ||$type == 'timestamp') {
$sql .= $row[$j] . ', ';}else {
$dummy  = '';
$srcstr = $row[$j];

for ($xx = 0; $xx < strlen($srcstr); $xx++) {
$yy = strlen($dummy);

if ($srcstr[$xx] == '\\')   $dummy .= '\\\\';
if ($srcstr[$xx] == '\'')   $dummy .= '\\\'';
if ($srcstr[$xx] == "\x00") $dummy .= '\0';
if ($srcstr[$xx] == "\x0a") $dummy .= '\n';
if ($srcstr[$xx] == "\x0d") $dummy .= '\r';
if ($srcstr[$xx] == "\x1a") $dummy .= '\Z';

if (strlen($dummy) == $yy)  $dummy .= $srcstr[$xx];}
$sql .= "'" . $dummy . "', ";}} else {
$sql .= "'', ";}}
$sql = ereg_replace(', $', '', $sql);
$sql .= ");".$crlf;

out(1,$sql);}

mysql_free_result($result);}}
return; }


/* Jaunas rindas pārnese, kas atkarīga no pārlūka */
function define_crlf() {
global $HTTP_USER_AGENT;

$ucrlf = "\n";

if (strstr($HTTP_USER_AGENT, 'Win')) {
$ucrlf = "\r\n";}else if (strstr($HTTP_USER_AGENT, 'Mac')) {
$ucrlf = "\r";}else {
$ucrlf = "\n";}
return $ucrlf;}


/* Izvades funkcija */
function out($fptr,$s)   {
echo $s; }


/* Iegūstam pārlūku */
if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
define('USER_BROWSER_AGENT', 'OPERA');} else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
define('USER_BROWSER_AGENT', 'IE');} else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
define('USER_BROWSER_AGENT', 'OMNIWEB');} else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
define('USER_BROWSER_AGENT', 'MOZILLA');} else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
define('USER_BROWSER_AGENT', 'KONQUEROR');} else {
define('USER_BROWSER_AGENT', 'OTHER');}


/* Izvadām MIME TYPE */
$mime_type = (USER_BROWSER_AGENT == 'IE' || USER_BROWSER_AGENT == 'OPERA')
? 'application/octetstream'
: 'application/octet-stream';

$now = gmdate('D, d M Y H:i:s') . ' GMT';//Laiks

$filename = $MY_DB_user;//SQL faila nosaukums
$ext = "sql";//SQL faila formāts
$crlf = define_crlf();//Definējam jaunas rindas pārnesi

header('Content-Type: ' . $mime_type);//Headers pārlūkam tipa atpazīšanai
header('Expires: ' . $now);// Laiks pārlūkam


/* Kēšošana */
if (USER_BROWSER_AGENT == 'IE') {
header('Content-Disposition: inline; filename="' . $filename . '.' . $ext . '"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');} else {
header('Content-Disposition: attachment; filename="' . $filename . '.' . $ext . '"');
header('Pragma: no-cache');

/* Funkcijas ievade ar datiem no DB.php */
mysqlbackup($MY_serveris,$MY_DB_user,$MY_DB,$MY_PW,$structure_only,$crlf);}

/* Svešiem cilvēkiem */
} else { header ("Location: index.php?sayer=404&".SID); exit;}


?>