PageRenderTime 68ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/sxd/index.php

https://code.google.com/p/dcloner/
PHP | 1956 lines | 1849 code | 39 blank | 68 comment | 357 complexity | 27335392d0ba2140b1559026d049fda7 MD5 | raw file
  1. <?php
  2. /***************************************************************************\
  3. | Sypex Dumper version 2.0.7 RC |
  4. | (c) 2003-2010 zapimir zapimir@zapimir.net http://sypex.net/ |
  5. | (c) 2005-2010 BINOVATOR info@sypex.net |
  6. |---------------------------------------------------------------------------|
  7. | created: 2003.09.02 19:07 modified: 2010.11.05 19:06 |
  8. |---------------------------------------------------------------------------|
  9. | Sypex Dumper is released under the terms of the BSD license |
  10. | http://sypex.net/bsd_license.txt |
  11. \***************************************************************************/
  12. header("Expires: Wed, 19 Nov 2008 19:19:19 GMT");
  13. header("Cache-Control: no-store, no-cache, must-revalidate");
  14. header("Content-Type: text/html; charset=utf-8");
  15. if(!ini_get('zlib.output_compression') && function_exists('ob_gzhandler')) ob_start('ob_gzhandler');
  16. //error_reporting(E_ALL);
  17. @set_magic_quotes_runtime(0);
  18. error_reporting(0);
  19. set_error_handler('sxd_error_handler');
  20. register_shutdown_function('sxd_shutdown');
  21. $SXD = new Sypex_Dumper();
  22. chdir(dirname(__FILE__));
  23. $SXD->init(!empty($argc) && $argc > 1 ? $argv : false);
  24. class Sypex_Dumper {
  25. function Sypex_Dumper() {
  26. define('C_DEFAULT', 1);
  27. define('C_RESULT', 2);
  28. define('C_ERROR', 3);
  29. define('C_WARNING', 4);
  30. define('SXD_DEBUG', false);
  31. define('TIMER', array_sum(explode(' ', microtime())));
  32. define('V_SXD', 20007);
  33. define('V_PHP', sxd_ver2int(phpversion()));
  34. $this->name = 'Sypex Dumper 2.0.7 RC';
  35. }
  36. function loadLang($lng_name = 'auto'){
  37. if($lng_name == 'auto'){
  38. include('lang/list.php');
  39. $this->langs = &$langs;
  40. $lng = 'en';
  41. if(preg_match_all('/[a-z]{2}(-[a-z]{2})?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $m)) {
  42. foreach($m[0] AS $l){
  43. if(isset($langs[$l])){
  44. $lng_name = $l;
  45. break;
  46. }
  47. }
  48. }
  49. }
  50. if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php");
  51. else include("lang/lng_en.php");
  52. $this->LNG = &$LNG;
  53. $this->LNG['name'] = $lng_name;
  54. return true;
  55. }
  56. function init($args = false){
  57. if (get_magic_quotes_gpc()) {
  58. $_POST = sxd_antimagic($_POST);
  59. }
  60. include('cfg.php');
  61. $this->loadLang($CFG['lang']);
  62. if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) @set_time_limit($CFG['time_web']);
  63. elseif (ini_get('max_execution_time') < $CFG['time_web']) $CFG['time_web'] = ini_get('max_execution_time');
  64. $this->CFG = &$CFG;
  65. $this->try = false;
  66. $this->virtualize = false;
  67. $this->cron_mode = false;
  68. // ????????? ??????????? ? ?????? ??????? ? ????
  69. if(empty($this->CFG['my_user'])){
  70. $this->CFG['my_host'] = 'localhost';
  71. $this->CFG['my_port'] = 3306;
  72. $this->CFG['my_user'] = 'root';
  73. $this->CFG['my_pass'] = '';
  74. $this->CFG['my_comp'] = 0;
  75. $this->CFG['my_db'] = '';
  76. }
  77. if ($args) { // ?????????? ?????
  78. foreach($args AS $key => $arg){
  79. if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)){
  80. switch ($m[1]) {
  81. case 'h': $this->CFG['my_host'] = $m[2]; break; // ????
  82. case 'o': $this->CFG['my_port'] = $m[2]; break; // ????
  83. case 'u': $this->CFG['my_user'] = $m[2]; break; // ?????
  84. case 'p': $this->CFG['my_pass'] = $m[2]; break; // ??????
  85. case 'j': $this->CFG['sjob'] = $m[2]; break; // job-????
  86. }
  87. }
  88. }
  89. set_time_limit($CFG['time_cron']);
  90. // ????????? ?????? ????, ???? ?????
  91. $auth = $this->connect();
  92. if($auth && !empty($this->CFG['sjob'])){
  93. $this->ajax($this->loadJob($this->CFG['sjob']));
  94. echo file_get_contents($this->JOB['file_log']);
  95. if(file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']);
  96. if(file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']);
  97. }
  98. else echo 'Auth error';
  99. exit;
  100. }
  101. elseif(!empty($this->CFG['auth'])){ // ???????????
  102. $auth = false;
  103. $sfile = 'ses.php';
  104. if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){
  105. include($sfile);
  106. if(isset($SES[$_COOKIE['sxd']])) {
  107. $auth = true;
  108. $this->CFG = $SES[$_COOKIE['sxd']]['cfg'];
  109. $this->SES = &$SES;
  110. $this->loadLang($this->CFG['lang']);
  111. }
  112. }
  113. if(!$auth) {
  114. $user = !empty($_POST['user']) ? $_POST['user'] : '';
  115. $pass = !empty($_POST['pass']) ? $_POST['pass'] : '';
  116. $host = !empty($_POST['host']) ? $_POST['host'] : 'localhost';
  117. $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306;
  118. $temp = preg_split('/\s+/', $this->CFG['auth']);
  119. if(!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']);}
  120. foreach($temp AS $a){
  121. switch($a) {
  122. case 'cfg': if(empty($user)) {continue;}
  123. $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user']== $user && $CFG['pass'] == $pass;
  124. break;
  125. case 'mysql': if(empty($user)) {continue;}
  126. $auth = $this->connect($host, $port, $user, $pass);
  127. break;
  128. default: $file = 'auth_' . $a . '.php';
  129. if(!file_exists($file)) continue;
  130. include $file;
  131. }
  132. if($auth) break;
  133. }
  134. if($auth){
  135. $key = md5(rand(1,100000) . $user . microtime());
  136. $CFG['lang'] = $this->LNG['name'];
  137. $_COOKIE['sxd'] = $key;
  138. $this->saveCFG();
  139. setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0);
  140. header("Location: ./");
  141. exit;
  142. }
  143. foreach(array('user', 'pass', 'host', 'port') AS $key){
  144. $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : '';
  145. }
  146. $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : '';
  147. }
  148. if (!$auth) {
  149. if(!empty($_POST['ajax'])){
  150. echo "sxd.hideLoading();alert('Session not found');";
  151. exit;
  152. }
  153. $this->lng_list = '<option value="auto">- auto -</opinion>';
  154. if(!isset($this->langs)) {include('lang/list.php');$this->langs = &$langs;}
  155. foreach($this->langs AS $k => $v){
  156. $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>";
  157. }
  158. echo sxd_tpl_auth();
  159. exit;
  160. }
  161. }
  162. /*if(!empty($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'exit') {
  163. setcookie('sxd', '', 0);
  164. header("Location: {$this->CFG['exitURL']}");
  165. exit;
  166. }*/
  167. if(empty($_POST['ajax']['act']) || $_POST['ajax']['act'] != 'save_connect') $this->connect();
  168. if(isset($_POST['ajax'])) $this->ajax($_POST['ajax']);
  169. else $this->main();
  170. }
  171. function saveToFile($name, $content){
  172. $fp = fopen($name, "w");
  173. fwrite($fp, $content);
  174. fclose($fp);
  175. }
  176. function connect($host = null, $port = null, $user = null, $pass = null){
  177. $this->error = '';
  178. $this->try = true;
  179. if(!empty($user) && isset($pass)) {
  180. $this->CFG['my_host'] = $host;
  181. $this->CFG['my_port'] = $port;
  182. $this->CFG['my_user'] = $user;
  183. $this->CFG['my_pass'] = $pass;
  184. }
  185. if(mysql_connect($this->CFG['my_host'] . ($this->CFG['my_host']{0} != ':' ? ":{$this->CFG['my_port']}" : ''), $this->CFG['my_user'], $this->CFG['my_pass'])) {
  186. mysql_query('SET NAMES utf8') or sxd_my_error();
  187. define('V_MYSQL', sxd_ver2int(mysql_get_server_info()));
  188. }
  189. else {
  190. define('V_MYSQL', 0);
  191. $this->error = "sxd.actions.tab_connects();alert('{" . mysql_escape_string(mysql_error()) . "');";
  192. }
  193. $this->try = false;
  194. return V_MYSQL ? true: false;
  195. }
  196. function main(){
  197. // ??????
  198. $this->VAR['toolbar'] = sxd_php2json(
  199. array(
  200. array('backup', $this->LNG['tbar_backup'], 1, 3),
  201. array('restore', $this->LNG['tbar_restore'], 2, 3),
  202. array('|'),
  203. array('files', $this->LNG['tbar_files'], 3, 1),
  204. array('services', $this->LNG['tbar_services'], 5, 1),
  205. array('|'),
  206. array('createdb', $this->LNG['tbar_createdb'], 7, 0),
  207. array('connects', $this->LNG['tbar_connects'], 6, 0),
  208. array('|'),
  209. array('options', $this->LNG['tbar_options'], 4, 1),
  210. array('|'),
  211. array('exit', $this->LNG['tbar_exit'], 8, 1),
  212. )
  213. );
  214. $this->db = 'temp';
  215. $zip = array($this->LNG['zip_none']);
  216. if (function_exists("gzopen")) {
  217. for($i = 1; $i <10; $i++){
  218. $zip[] = "GZip: {$i}";
  219. }
  220. $zip[1] .= " ({$this->LNG['zip_min']})";
  221. $zip[7] .= " ({$this->LNG['default']})";
  222. }
  223. if (function_exists("bzopen")) {
  224. $zip[10] = "BZip";
  225. }
  226. end($zip);
  227. $zip[key($zip)] .= " ({$this->LNG['zip_max']})";
  228. $this->VAR['combos'] =
  229. $this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) .
  230. $this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) .
  231. $this->addCombo('backup_zip', 7, 10, 'zip', $zip) .
  232. $this->addCombo('restore_db', $this->db, 11, 'db') .
  233. $this->addCombo('restore_charset', 0, 9, 'charset') .
  234. $this->addCombo('restore_file', 0, 12, 'files', $this->getFileList()) .
  235. $this->addCombo('restore_type', 0, 13, 'types', array("CREATE + INSERT ({$this->LNG['default']})", 'TRUNCATE + INSERT', 'REPLACE', 'INSERT IGNORE')) .
  236. $this->addCombo('services_db', $this->db, 11, 'db') .
  237. $this->addCombo('services_check', 0, 5, 'check', array("- {$this->LNG['default']} -", 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED')) .
  238. $this->addCombo('services_repair', 0, 5, 'repair', array("- {$this->LNG['default']} -", 'QUICK', 'EXTENDED')) .
  239. //$this->addCombo('services_charset', 0, 9, 'collation', $this->getCollationList()) .
  240. //$this->addCombo('services_charset_col', 0, 15, 'collation:services_charset').
  241. $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) .
  242. $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset')
  243. ;
  244. if (!V_MYSQL) $this->VAR['combos'] .= $this->error;
  245. $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();";
  246. $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">');
  247. $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">');
  248. echo sxd_tpl_page();
  249. }
  250. function addCombo($name, $sel, $ico, $opt_name, $opts = ''){
  251. $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'";
  252. return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n";
  253. }
  254. function ajax($req){
  255. $res = '';
  256. $act = $req['act'];
  257. if($req['act'] == 'run_savedjob'){
  258. $req = $this->loadJob($req);
  259. }
  260. switch($req['act']){
  261. case 'load_db':
  262. $res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']);
  263. break;
  264. case 'load_files':
  265. $res = $this->getFileObjects('restore', $req['value']);
  266. break;
  267. case 'filelist':
  268. $res = "sxd.clearOpt('files');sxd.addOpt(" . sxd_php2json(array('files' => $this->getFileList())) . ");";
  269. break;
  270. case 'dblist':
  271. $res = "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_db.select(0,'-');";
  272. break;
  273. case 'load_connect':
  274. $CFG = $this->cfg2js($this->CFG);
  275. $res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}',
  276. z('con_pass').value = '', z('con_comp').checked = {$CFG['my_comp']}, z('con_db').value = '{$CFG['my_db']}', z('con_pass').changed = false;" ;
  277. break;
  278. case 'save_connect':
  279. $res = $this->saveConnect($req);
  280. break;
  281. case 'save_job':
  282. unset($req['act']);
  283. $this->saveJob('sj_' . $req['job'] , $req);
  284. $res = $this->getSavedJobs();
  285. break;
  286. case 'add_db':
  287. $res = $this->addDb($req);
  288. break;
  289. case 'load_options':
  290. $CFG = $this->cfg2js($this->CFG);
  291. $res = "z('time_web').value = '{$CFG['time_web']}', z('time_cron').value = '{$CFG['time_cron']}', z('backup_path').value = '{$CFG['backup_path']}',
  292. z('backup_url').value = '{$CFG['backup_url']}', z('globstat').checked = {$CFG['globstat']}, z('charsets').value = '{$CFG['charsets']}', z('only_create').value = '{$CFG['only_create']}', z('auth').value = '{$CFG['auth']}', z('conf_import').checked = {$CFG['confirm']} & 1, z('conf_file').checked = {$CFG['confirm']} & 2, z('conf_db').checked = {$CFG['confirm']} & 4;sxd.confirms = {$this->CFG['confirm']};";
  293. break;
  294. case 'save_options':
  295. $res = $this->saveOptions($req);
  296. break;
  297. case 'delete_file':
  298. if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) {
  299. $file = $this->CFG['backup_path'] . $req['name'];
  300. if(file_exists($file)) unlink($file);
  301. }
  302. $res = $this->getFileListExtended();
  303. break;
  304. case 'delete_db':
  305. $res = $this->deleteDB($req['name']);
  306. break;
  307. case 'load_files_ext':
  308. $res .= $this->getFileListExtended();
  309. break;
  310. case 'services':
  311. $this->runServices($req);
  312. break;
  313. case 'backup':
  314. $this->addBackupJob($req);
  315. break;
  316. case 'restore':
  317. $this->addRestoreJob($req);
  318. break;
  319. case 'resume':
  320. $this->resumeJob($req);
  321. break;
  322. case 'exit':
  323. setcookie('sxd', '', 0);
  324. $res = "top.location.href = '" . mysql_escape_string($this->CFG['exitURL']) . "'";
  325. break;
  326. }
  327. echo $res;
  328. }
  329. function loadJob($job){
  330. $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php';
  331. if(!file_exists($file)) return;
  332. include($file);
  333. $JOB['act'] = $JOB['type'];
  334. $JOB['type'] = 'run';
  335. return $JOB;
  336. }
  337. function deleteDB($name){
  338. $r = mysql_query('DROP DATABASE `' . mysql_escape_string($name) . '`') or sxd_my_error();
  339. if($r){
  340. echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');";
  341. }
  342. else
  343. echo "alert('" . mysql_escape_string(mysql_error()) . "')";
  344. }
  345. function cfg2js($cfg){
  346. foreach($cfg AS $k => $v){
  347. $cfg[$k] = mysql_escape_string($v);
  348. }
  349. return $cfg;
  350. }
  351. function addDb($req){
  352. $r = mysql_query('CREATE DATABASE `' . mysql_escape_string($req['name']) . '`' . (V_MYSQL > 40100 ? "CHARACTER SET {$req['charset']} COLLATE {$req['collate']}" : ''));
  353. if($r)
  354. echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");";
  355. else
  356. sxd_my_error();
  357. }
  358. function saveConnect($req){
  359. $this->CFG['my_host'] = $req['host'];
  360. $this->CFG['my_port'] = (int)$req['port'];
  361. $this->CFG['my_user'] = $req['user'];
  362. if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass'];
  363. $this->CFG['my_comp'] = $req['comp'] ? 1 : 0;
  364. $this->CFG['my_db'] = $req['db'];
  365. $this->saveCFG();
  366. $this->connect();
  367. if (V_MYSQL) {
  368. $tmp = array(
  369. 'db' => $this->getDBList(),
  370. 'charset' => $this->getCharsetList(),
  371. 'collation' => $this->getCollationList()
  372. );
  373. echo "sxd.clearOpt('db');sxd.clearOpt('charset');sxd.clearOpt('collation');sxd.addOpt(" . sxd_php2json($tmp) . ");sxd.combos.backup_db.select(0,'-');sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_charset.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.db_charset.select(0,'-');";
  374. }
  375. else {
  376. echo $this->error;
  377. }
  378. }
  379. function saveOptions($req){
  380. $this->CFG['time_web'] = $req['time_web'];
  381. $this->CFG['time_cron'] = $req['time_cron'];
  382. $this->CFG['backup_path'] = $req['backup_path'];
  383. $this->CFG['backup_url'] = $req['backup_url'];
  384. $this->CFG['globstat'] = $req['globstat'] ? 1 : 0;
  385. $this->CFG['charsets'] = $req['charsets'];
  386. $this->CFG['only_create'] = $req['only_create'];
  387. $this->CFG['auth'] = $req['auth'];
  388. $this->CFG['confirm'] = $req['confirm'];
  389. $this->saveCFG();
  390. }
  391. function saveCFG(){
  392. if (isset($_COOKIE['sxd'])) {
  393. $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']);
  394. $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>");
  395. }
  396. if (!$this->virtualize){
  397. $this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>");
  398. }
  399. }
  400. function runServices($job) {
  401. $serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR');
  402. $add = array('check' => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED'));
  403. if(isset($serv[$job['type']])) {
  404. mysql_select_db($job['db']);
  405. $filter = $object = array();
  406. $this->createFilters($job['obj'], $filter, $object);
  407. $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error();
  408. if (!$r) return;
  409. $tables = array();
  410. while($item = mysql_fetch_assoc($r)){
  411. if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue;
  412. if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`";
  413. }
  414. $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables);
  415. if ($job['type'] == 'check' || $job['type'] == 'repair') {
  416. $sql .= isset($add[$job['type']][$job[$job['type']]]) ? ' ' . $add[$job['type']][$job[$job['type']]] : '';
  417. }
  418. $r = mysql_query($sql) or sxd_my_error();
  419. if (!$r) return;
  420. $res = array();
  421. while($item = mysql_fetch_row($r)){
  422. $res[] = $item;
  423. }
  424. echo 'sxd.result.add(' . sxd_php2json($res). ');';
  425. }
  426. }
  427. function createFilters(&$obj, &$filter, &$object){
  428. $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV');
  429. foreach($types AS $type){
  430. $filter[$type] = array();
  431. $object[$type] = array();
  432. if(!empty($obj[$type])){
  433. foreach($obj[$type] AS $v){
  434. if(strpos($v, '*') !== false) {
  435. $filter[$type][] = str_replace('*', '.*?', $v);
  436. }
  437. else {
  438. $object[$type][$v] = true;
  439. }
  440. }
  441. $filter[$type] = count($filter[$type]) > 0 ? '/^(' . implode('|', $filter[$type]) . ')$/i' : '';
  442. }
  443. }
  444. }
  445. function closeConnect(){
  446. //return;
  447. ignore_user_abort(1);
  448. header("SXD: {$this->name}");
  449. header("Connection: close");
  450. header("Content-Length: 0");
  451. ob_end_flush();
  452. flush();
  453. }
  454. function resumeJob($job){
  455. $this->closeConnect();
  456. include($this->CFG['backup_path'] . $job['job'] . '.job.php');
  457. $this->JOB = &$JOB;
  458. if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
  459. $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b');
  460. $this->fh_log = fopen($this->JOB['file_log'], 'ab');
  461. $t = fgets($this->fh_rtl);
  462. if(!empty($t)){
  463. $this->rtl = explode("\t", $t);
  464. }
  465. else {
  466. $this->addLog($this->LNG['not_found_rtl']);
  467. exit;
  468. }
  469. // TODO: ????????? ???????? ?????????
  470. //$this->rtl[6] = '';
  471. fseek($this->fh_rtl, 0);
  472. $this->rtl[1] = time();
  473. $this->rtl[9] = 0;
  474. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  475. if ($this->JOB['act'] == 'backup') $this->runBackupJob(true);
  476. elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true);
  477. }
  478. function addRestoreJob($job) {
  479. $this->closeConnect();
  480. $this->JOB = $job;
  481. // ??????? ?????? ???????? ? ??????
  482. $filter = $object = array();
  483. $this->createFilters($this->JOB['obj'], $filter, $object);
  484. $objects = $this->getFileObjects('restore', $this->JOB['file'], false);
  485. $todo = array();
  486. $rows = 0;
  487. $this->tab_rows = array();
  488. $todo = array();
  489. foreach($objects AS $t => $list){
  490. if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {}
  491. elseif(empty($object[$t]) && empty($filter[$t])) {continue;}
  492. if (empty($list)) continue;
  493. foreach($list AS $item){
  494. switch($t){
  495. case 'TA':
  496. $type = '';
  497. if(sxd_check($item[0], $object['TA'], $filter['TA'])){
  498. $type = empty($item[1]) ? 'TC' : 'TA';
  499. }
  500. elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) {
  501. $type = 'TC';
  502. }
  503. else continue;
  504. $todo['TA'][] = array($type, $item[0], $item[1], $item[2]);
  505. $rows += $type == 'TA' ? $item[1] : 0;
  506. break;
  507. default:
  508. if(sxd_check($item, $object[$t], $filter[$t])) {
  509. $todo[$t][] = array($t, $item);
  510. }
  511. }
  512. }
  513. }
  514. $this->JOB['file_tmp'] = $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file'];
  515. $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl';
  516. $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log';
  517. $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp';
  518. if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
  519. $this->JOB['todo'] = $todo;
  520. $this->saveJob($this->JOB['job'], $this->JOB);
  521. $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r');
  522. $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb');
  523. $this->fh_log = fopen($this->JOB['file_log'], 'wb');
  524. $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n");
  525. $this->addLog(sprintf($this->LNG['restore_begin'], $this->JOB['db']));
  526. $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}");
  527. $this->runRestoreJob();
  528. }
  529. function runRestoreJob($continue = false){
  530. $ei = false;
  531. if($continue){
  532. $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r');
  533. fseek($this->fh_tmp, $this->rtl[3]);
  534. if(!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]);
  535. if($this->rtl[7] < $this->rtl[10]) $ei = true;
  536. }
  537. mysql_select_db($this->JOB['db']);
  538. if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue);
  539. //mysql_query("SET NAMES 'UTF8'");
  540. $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event');
  541. $fcache = '';
  542. $writes = 0;
  543. $old_charset = '';
  544. $tab = '';
  545. $seek = 0;
  546. $this->rtl[3] = ftell($this->fh_tmp);
  547. fseek($this->fh_rtl, 0);
  548. $this->rtl[1] = time();
  549. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  550. $c = 0;
  551. switch($this->JOB['strategy']){
  552. case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break;
  553. case 2: $tc = ''; $td = 'REPLACE'; break;
  554. case 3: $tc = ''; $td = 'INSERT IGNORE'; break;
  555. default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT';
  556. }
  557. $tab_exists = array();
  558. if($this->JOB['strategy'] > 0){
  559. $r = mysql_query("SHOW TABLES") or sxd_my_error();
  560. while($item = mysql_fetch_row($r)){
  561. $tab_exists[$item[0]] = true;
  562. }
  563. }
  564. $insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : '';
  565. //$enable_index = array();
  566. if(V_MYSQL > 40014) {
  567. mysql_query("SET UNIQUE_CHECKS=0");
  568. mysql_query("SET FOREIGN_KEY_CHECKS=0");
  569. if(V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
  570. if(V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0");
  571. }
  572. $log_sql = false;
  573. $fields = '';
  574. $time_old = time();
  575. $exit_time = $time_old + $this->CFG['time_web'] - 1;
  576. while($q = sxd_read_sql($this->fh_tmp, $seek, $ei)){
  577. if($time_old < time()) {
  578. if(file_exists($this->JOB['file_stp'])){
  579. $type = file_get_contents($this->JOB['file_stp']);
  580. $this->rtl[9] = !empty($type) ? $type : 2;
  581. fseek($this->fh_rtl, 0);
  582. $this->rtl[1] = time();
  583. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  584. /*if($type == 1) {
  585. }*/
  586. unset($this->rtl);
  587. exit;
  588. }
  589. $time_old = time();
  590. if($time_old >= $exit_time){
  591. $this->rtl[9] = 3;
  592. fseek($this->fh_rtl, 0);
  593. $this->rtl[1] = time();
  594. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  595. unset($this->rtl);
  596. exit;
  597. }
  598. clearstatcache();
  599. }
  600. switch($q{0}){
  601. case '(':
  602. if($continue) {
  603. $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3]));
  604. $continue = false;
  605. }
  606. $q = $insert . $q;
  607. $ex = 1;
  608. $c = 1;
  609. break;
  610. case 'I':
  611. if (preg_match('/^INSERT( INTO `(.+?)`) VALUES/', $q, $m)) {
  612. $insert = $td . $m[1] . $fields . " VALUES \n";
  613. $tab = $m[2];
  614. $this->rtl[7] = 0;
  615. $this->rtl[8] = 0;
  616. foreach($this->JOB['todo']['TA'] AS $t){
  617. if($t[1] == $tab) {
  618. $this->rtl[8] = $t[2];
  619. }
  620. }
  621. if($this->JOB['strategy']) {
  622. $q = substr_replace($q, $insert, 0, strlen($m[0]));
  623. }
  624. //mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error());
  625. mysql_query("ALTER TABLE `{$tab}` DISABLE KEYS") or sxd_my_error();
  626. //if(!empty($this->JOB['autoinc'])) mysql_query("ALTER TABLE `{$tab}` AUTO_INCREMENT = 1") or sxd_my_error();
  627. $ex = 1;
  628. }
  629. break;
  630. case 'C':
  631. $ex = 1;
  632. if (preg_match('/^CREATE TABLE `/', $q)) {
  633. if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0;
  634. else {
  635. $ex = 1;
  636. if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){
  637. $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']);
  638. }
  639. if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q);
  640. }
  641. // ??????? ????? ????? ???????
  642. $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : '';
  643. }
  644. break;
  645. case '#': // ??????? ??? ???????
  646. if (preg_match("/\#\t(TC|TD|VI|PR|FU|TR|EV)`(.+?)`(([^_]+?)_.+?)?$/", $q, $m)) {
  647. //if(!empty($tab)) $enable_index[] = $tab;
  648. $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : empty($m[3]) ? '' : $m[3]);
  649. if($m[1] == 'TC') {
  650. $this->addLog(sprintf($this->LNG['restore_TC'], $m[2]));
  651. $insert = '';
  652. $tab = '';
  653. $this->rtl[4] = 'TD';
  654. $this->rtl[5] = $m[2];
  655. $ei = 0;
  656. if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) {
  657. mysql_query("{$tc} `{$m[2]}`") or sxd_my_error();
  658. }
  659. }
  660. elseif($m[1] == 'TD'){
  661. $ei = 1;
  662. }
  663. else {
  664. $this->rtl[4] = $m[1];
  665. $this->rtl[5] = $m[2];
  666. $this->rtl[7] = 0;
  667. $this->rtl[8] = 0;
  668. mysql_query("DROP {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error();
  669. $this->addLog(sprintf($this->LNG["restore_{$m[1]}"], $m[2]));
  670. $ei = 0;
  671. }
  672. }
  673. $ex = 0;
  674. break;
  675. default:
  676. $insert = '';
  677. $ex = 1;
  678. }
  679. if($ex) {
  680. //error_log("[index.php]\n{$q}\n", 3, "error.log");
  681. $this->rtl[3] = ftell($this->fh_tmp) - $seek;
  682. fseek($this->fh_rtl, 0);
  683. $this->rtl[1] = time();
  684. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  685. //error_log("\n---------------------\n{$q}", 3, "sql.log");
  686. if(mysql_query($q)) {
  687. if($insert) {
  688. $c = 1;
  689. }
  690. }
  691. else {
  692. error_log("[index.php]\n{$q}\n", 3, "error.log");
  693. sxd_my_error();
  694. }
  695. if($c){
  696. $i = mysql_affected_rows();
  697. $this->rtl[3] = ftell($this->fh_tmp) - $seek;
  698. $this->rtl[7] += $i;
  699. $this->rtl[10] += $i;
  700. fseek($this->fh_rtl, 0);
  701. $this->rtl[1] = time();
  702. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  703. $c = 1;
  704. }
  705. }
  706. }
  707. // ???????? ?????
  708. $this->addLog($this->LNG['restore_keys']);
  709. $this->rtl[4] = 'EK';
  710. $this->rtl[5] = '';
  711. $this->rtl[6] = '';
  712. $this->rtl[7] = 0;
  713. $this->rtl[8] = 0;
  714. foreach($this->JOB['todo']['TA'] AS $tab){
  715. if ($tab[0] == 'TC') continue;
  716. mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error();
  717. $this->rtl[1] = time();
  718. $this->rtl[5] = $tab[1];
  719. fseek($this->fh_rtl, 0);
  720. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  721. }
  722. $this->rtl[4] = 'EOJ';
  723. $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4);
  724. fseek($this->fh_rtl, 0);
  725. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  726. $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db']));
  727. fclose($this->fh_log);
  728. fclose($this->fh_rtl);
  729. }
  730. function runRestoreJobForeign($continue = false){
  731. $ei = false;
  732. $fcache = '';
  733. $writes = 0;
  734. $old_charset = '';
  735. $tab = '';
  736. $seek = 0;
  737. $this->rtl[3] = ftell($this->fh_tmp);
  738. fseek($this->fh_rtl, 0);
  739. $this->rtl[1] = time();
  740. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  741. $c = 0;
  742. $log_sql = false;
  743. $fields = '';
  744. $insert = '';
  745. $last_tab = '';
  746. $time_old = time();
  747. $exit_time = $time_old + $this->CFG['time_web'] - 1;
  748. $delimiter = ";\n";
  749. while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter)){
  750. $q = ltrim($q);
  751. if(empty($q)) break;
  752. if($time_old < time()) {
  753. if(file_exists($this->JOB['file_stp'])){
  754. $type = file_get_contents($this->JOB['file_stp']);
  755. $this->rtl[9] = !empty($type) ? $type : 2;
  756. fseek($this->fh_rtl, 0);
  757. $this->rtl[1] = time();
  758. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  759. /*if($type == 1) {
  760. }*/
  761. unset($this->rtl);
  762. exit;
  763. }
  764. $time_old = time();
  765. if($time_old >= $exit_time){
  766. $this->rtl[9] = 3;
  767. fseek($this->fh_rtl, 0);
  768. $this->rtl[1] = time();
  769. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  770. unset($this->rtl);
  771. exit;
  772. }
  773. clearstatcache();
  774. }
  775. do {
  776. $repeat = false;
  777. switch($q{0}){
  778. case '(':
  779. if($continue) {
  780. $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3]));
  781. $continue = false;
  782. }
  783. $q = $insert . $q;
  784. $ex = 1;
  785. $c = 1;
  786. break;
  787. case 'I':
  788. if (preg_match('/^(INSERT( INTO `(.+?)`)\s+?VALUES)/', $q, $m)) {
  789. $insert = trim($m[1]) . ' ';
  790. $tab = $m[3];
  791. $this->rtl[7] = 0;
  792. $this->rtl[8] = 0;
  793. $ex = 1;
  794. }
  795. break;
  796. case 'C':
  797. $ex = 1;
  798. $ei = 1;
  799. if (preg_match('/^CREATE TABLE.+?`(.+?)`/', $q, $m)) {
  800. $ex = 1;
  801. $tab = $m[1];
  802. $this->addLog(sprintf($this->LNG['restore_TC'], $tab));
  803. //mysql_query("DROP TABLE IF EXISTS `{$tab}`");
  804. if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){
  805. $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']);
  806. }
  807. elseif(empty($this->JOB['charset'])){
  808. if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){
  809. $this->setNames($charset[2]);
  810. }
  811. }
  812. }
  813. break;
  814. case '-' && $q{1} == '-':
  815. case '#':
  816. $repeat = true;
  817. $q = ltrim(substr($q, strpos($q, "\n")));
  818. $ex = 0;
  819. break;
  820. case '/':
  821. case 'S':
  822. if (preg_match('/SET NAMES (\w+)/', $q, $m)) {
  823. $this->JOB['charset'] = $m[1];
  824. $this->setNames($this->JOB['charset']);
  825. $ex = 0;
  826. }
  827. else $ex = 1;
  828. break;
  829. default:
  830. $insert = '';
  831. $ex = 1;
  832. $ei = 0;
  833. }
  834. } while ($repeat);
  835. if($ex) {
  836. //error_log("-----------------\n{$q}\n", 3, "sql.log");
  837. $this->rtl[3] = ftell($this->fh_tmp) - $seek;
  838. fseek($this->fh_rtl, 0);
  839. $this->rtl[1] = time();
  840. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  841. if(mysql_query($q)) {
  842. if($insert) {
  843. $c = 1;
  844. }
  845. }
  846. else {
  847. error_log("-----------------\n{$q}\n", 3, "error.log");
  848. sxd_my_error();
  849. }
  850. if($c){
  851. $i = mysql_affected_rows();
  852. $this->rtl[3] = ftell($this->fh_tmp) - $seek;
  853. $this->rtl[7] += $i;
  854. $this->rtl[10] += $i;
  855. fseek($this->fh_rtl, 0);
  856. $this->rtl[1] = time();
  857. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  858. $c = 1;
  859. }
  860. }
  861. }
  862. $this->rtl[4] = 'EOJ';
  863. $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4);
  864. $this->rtl[7] = 0;
  865. $this->rtl[8] = 0;
  866. fseek($this->fh_rtl, 0);
  867. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  868. $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db']));
  869. fclose($this->fh_log);
  870. fclose($this->fh_rtl);
  871. }
  872. function addBackupJob($job) {
  873. $this->closeConnect();
  874. // ??????? ????? ???????
  875. $this->JOB = $job;
  876. mysql_select_db($this->JOB['db']);
  877. // ??????? ?????? ???????? ? ??????
  878. $filter = $object = array();
  879. $this->createFilters($this->JOB['obj'], $filter, $object);
  880. $queries = array(
  881. array('TABLE STATUS', 'Name', 'TA')
  882. );
  883. if (V_MYSQL > 50014) {
  884. $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR');
  885. $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU');
  886. $queries[] = array('TRIGGERS', 'Trigger', 'TR');
  887. if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV');
  888. }
  889. $todo = $header = array();
  890. $tabs = $rows = 0;
  891. $only_create = explode(' ', $this->CFG['only_create']);
  892. foreach($queries AS $query){
  893. $t = $query[2];
  894. if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {}
  895. elseif(empty($object[$t]) && empty($filter[$t])) continue;
  896. $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error();
  897. if (!$r) continue;
  898. $todo[$t] = array();
  899. $header[$t] = array();
  900. while($item = mysql_fetch_assoc($r)){
  901. $n = $item[$query[1]];
  902. switch($t){
  903. case 'TA':
  904. case 'TC':
  905. if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) {
  906. if(sxd_check($n, $object['VI'], $filter['VI'])){
  907. $todo['VI'] = array();
  908. $header['VI']= array();
  909. }
  910. continue;
  911. }
  912. elseif(sxd_check($n, $object['TA'], $filter['TA'])){
  913. $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type'];
  914. $t = in_array($engine, $only_create) ? 'TC' : 'TA';
  915. }
  916. elseif(sxd_check($n, $object['TC'], $filter['TC'])) {
  917. $t = 'TC';
  918. $item['Rows'] = $item['Data_length'] = '';
  919. }
  920. else continue;
  921. $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']);
  922. $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}";
  923. $tabs++;
  924. $rows += $item['Rows'];
  925. break;
  926. default:
  927. if(sxd_check($n, $object[$t], $filter[$t])) {
  928. $todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : '');
  929. $header[$t][] = $n;
  930. }
  931. }
  932. }
  933. }
  934. if (V_MYSQL > 50014 && (!empty($object['VI']) || !empty($filter['VI']))) {
  935. // ????? ???????, ????? ????????????? ?????????
  936. $r = mysql_query("SELECT table_name, view_definition /*!50121 , collation_connection */ FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '{$this->JOB['db']}'") or sxd_my_error();
  937. $views = $dumped = $views_collation = array();
  938. $re = "/`{$this->JOB['db']}`.`(.+?)`/";
  939. while($item = mysql_fetch_assoc($r)){
  940. preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m);
  941. $used = $m[1];
  942. $views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : '';
  943. $views[$item['table_name']] = $used;
  944. }
  945. while (count($views) > 0) {
  946. foreach($views AS $n => $view) {
  947. $can_dumped = true;
  948. foreach($view AS $k) {
  949. if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false;
  950. }
  951. if ($can_dumped) {
  952. if(sxd_check($n, $object['VI'], $filter['VI'])){
  953. $todo['VI'][] = array('VI', $n, $views_collation[$n]);
  954. $header['VI'][] = $n;
  955. }
  956. $dumped[$n] = 1;
  957. unset($views[$n]);
  958. }
  959. }
  960. }
  961. unset($dumped);
  962. unset($views);
  963. unset($views_collation);
  964. }
  965. $this->JOB['file_tmp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.tmp';
  966. $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl';
  967. $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log';
  968. $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp';
  969. if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
  970. $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w');
  971. $this->JOB['file'] = sprintf('%s_%s.%s', (isset($this->JOB['title']) ? $this->JOB['job'] : $this->JOB['db']), date('Y-m-d_H-i-s'), $this->JOB['file_ext']);
  972. $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file'];
  973. $this->JOB['todo'] = $todo;
  974. $this->saveJob($this->JOB['job'], $this->JOB);
  975. $fcache = implode('|', array('#SXD20', V_SXD, V_MYSQL, V_PHP, date('Y.m.d H:i:s'), $this->JOB['db'], $this->JOB['charset'], $tabs, $rows, mysql_escape_string($this->JOB['comment']))) . "\n";
  976. foreach($header AS $t => $o){
  977. if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n";
  978. }
  979. $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb');
  980. $this->fh_log = fopen($this->JOB['file_log'], 'wb');
  981. $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n");
  982. $fcache .= "#EOH\n\n";
  983. $this->write($fcache);
  984. $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db']));
  985. $this->runBackupJob();
  986. }
  987. function runBackupJob($continue = false){
  988. if($continue){
  989. $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a');
  990. mysql_select_db($this->JOB['db']);
  991. }
  992. mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1");
  993. $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event');
  994. $fcache = '';
  995. $writes = 0;
  996. if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error();
  997. $time_old = time();
  998. $exit_time = $time_old + $this->CFG['time_web'] - 1;
  999. $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : '';
  1000. foreach($this->JOB['todo'] AS $t => $o){
  1001. if (empty($this->rtl[4])) $this->rtl[4] = $t;
  1002. elseif ($this->rtl[4] != $t) continue;
  1003. foreach($o AS $n){
  1004. if (empty($this->rtl[5])) {
  1005. $this->rtl[5] = $n[1];
  1006. $this->rtl[7] = 0;
  1007. $this->rtl[8] = !empty($n[4]) ? $n[4] : 0;
  1008. }
  1009. elseif ($this->rtl[5] != $n[1]) continue;
  1010. // ?????? ?????
  1011. switch($n[0]){
  1012. case 'TC':
  1013. case 'TD':
  1014. case 'TA':
  1015. $from = '';
  1016. if ($n[0] == 'TC' || $this->rtl[7] == 0){
  1017. // ????? ????????? ???????
  1018. $r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error();
  1019. $item = mysql_fetch_assoc($r);
  1020. $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n";
  1021. $this->addLog(sprintf($this->LNG['backup_TC'], $n[1]));
  1022. $this->rtl[7] = 0;
  1023. if($n[0] == 'TC' || !$n[4]) break;
  1024. // ??????? ?????? ???????
  1025. $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n";
  1026. }
  1027. else {
  1028. $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}";
  1029. $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7]));
  1030. }
  1031. // ?????????? ???? ?????
  1032. $notNum = array();
  1033. $r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error();
  1034. $fields = 0;
  1035. while($col = mysql_fetch_array($r)) {
  1036. // TODO: ????????? ???? SET, ENUM ? BIT
  1037. $notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1;
  1038. $fields++;
  1039. }
  1040. $time_old = time();
  1041. $z = 0;
  1042. // ??????? ??????
  1043. $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}");
  1044. while($row = mysql_fetch_row($r)) {
  1045. if (strlen($fcache) >= 61440) {
  1046. $z = 0;
  1047. if($time_old < time()) {
  1048. if(file_exists($this->JOB['file_stp'])){
  1049. $type = file_get_contents($this->JOB['file_stp']);
  1050. $this->rtl[9] = !empty($type) ? $type : 2;
  1051. $this->write($fcache);
  1052. if($type == 1) {
  1053. }
  1054. unset($this->rtl);
  1055. exit;
  1056. }
  1057. $time_old = time();
  1058. if($time_old >= $exit_time){
  1059. $this->rtl[9] = 3;
  1060. $this->write($fcache);
  1061. unset($this->rtl);
  1062. exit;
  1063. }
  1064. clearstatcache();
  1065. }
  1066. $this->write($fcache);
  1067. }
  1068. for($k = 0; $k < $fields; $k++){
  1069. if(!isset($row[$k])) {$row[$k] = '\N';}
  1070. elseif($notNum[$k]) {$row[$k] = '\'' . mysql_escape_string($row[$k]) . '\'';}
  1071. }
  1072. $fcache .= '(' . implode(',', $row) . "),\n";
  1073. $this->rtl[7]++;
  1074. $this->rtl[10]++;
  1075. }
  1076. unset($row);
  1077. mysql_free_result($r);
  1078. $fcache = substr_replace($fcache, "\t;\n", -2, 2);
  1079. break;
  1080. /*case 'VI':
  1081. case 'PR':
  1082. case 'FU':
  1083. case 'EV':
  1084. case 'TR':*/
  1085. default:
  1086. if(V_MYSQL < 50121 && $n[0] == 'TR'){
  1087. // SHOW CREATE TRIGGER ??????????? ?? MySQL 5.1.21
  1088. $r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error();
  1089. $item = mysql_fetch_assoc($r);
  1090. $fcache .= "#\tTR`{$n[1]}`{$n[2]}\t;\nCREATE TRIGGER `{$item['TRIGGER_NAME']}` {$item['ACTION_TIMING']} {$item['EVENT_MANIPULATION']} ON `{$item['EVENT_OBJECT_TABLE']}` FOR EACH ROW {$item['ACTION_STATEMENT']}\t;\n";
  1091. }
  1092. else {
  1093. $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1]));
  1094. $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error();
  1095. $item = mysql_fetch_assoc($r);
  1096. $fcache .= "#\t{$n[0]}`{$n[1]}`{$n[2]}\t;\n" . preg_replace("/DEFINER=`.+?`@`.+?` /", '', ($n[0] == 'TR' ? $item['SQL Original Statement'] : $item['Create ' . $types[$n[0]]])) . "\t;\n";
  1097. }
  1098. }
  1099. $this->rtl[5] = '';
  1100. }
  1101. $this->rtl[4] = '';
  1102. }
  1103. $this->rtl[4] = 'EOJ';
  1104. $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4);
  1105. $this->rtl[6] = '';
  1106. $this->rtl[7] = 0;
  1107. $this->rtl[8] = 0;
  1108. $this->write($fcache);
  1109. fclose($this->fh_tmp);
  1110. rename($this->JOB['file_tmp'], $this->JOB['file_name']);
  1111. $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db']));
  1112. if ($this->JOB['del_time'] || $this->JOB['del_count']) {
  1113. $this->addLog($this->LNG['autodelete']);
  1114. $deldate = '';
  1115. if (!empty($this->JOB['del_time'])){ // ???????? ?? ????
  1116. $deldate = date("Y-m-d_H-i-s", time() - intval($this->JOB['del_time']) * 86400);
  1117. }
  1118. $deleted = false;
  1119. if ($dh = opendir($this->CFG['backup_path'])) {
  1120. $files = array();
  1121. $name = isset($this->JOB['title']) ? $this->JOB['job'] : $this->JOB['db'];
  1122. while (false !== ($file = readdir($dh))) {
  1123. if (preg_match("/^{$name}_(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})\.sql/", $file, $m)) {
  1124. if ($deldate && $m[1] < $deldate) {
  1125. if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file));
  1126. else $this->addLog(sprintf($this->LNG['del_fail'], $file));
  1127. $deleted = true;
  1128. }
  1129. else {$files[$m[1]] = $file;}
  1130. }
  1131. }
  1132. closedir($dh);
  1133. // ????????? ????? ?? ???? ? ??????? ????? ??????
  1134. if (!empty($this->JOB['del_count'])){
  1135. ksort($files);
  1136. $file_to_delete = count($files) - $this->JOB['del_count'];
  1137. foreach ($files AS $file){
  1138. if ($file_to_delete-- > 0){
  1139. if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file));
  1140. else $this->addLog(sprintf($this->LNG['del_fail'], $file));
  1141. $deleted = true;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. if(!$deleted) $this->addLog($this->LNG['del_nothing']);
  1147. }
  1148. fclose($this->fh_log);
  1149. fclose($this->fh_rtl);
  1150. }
  1151. function setNames($collation){
  1152. if(empty($collation)) return;
  1153. if($this->rtl[6] != $collation) {
  1154. mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error();
  1155. /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation));
  1156. $this->rtl[6] = $collation;
  1157. }
  1158. }
  1159. function write(&$str){
  1160. fseek($this->fh_rtl, 0);
  1161. $this->rtl[1] = time();
  1162. $this->rtl[3] += fwrite($this->fh_tmp, $str);
  1163. fwrite($this->fh_rtl, implode("\t", $this->rtl));
  1164. $str = '';
  1165. }
  1166. function addLog($str, $type = 1){
  1167. fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n");
  1168. }
  1169. function getDBList(){
  1170. $dbs = $items = array();
  1171. if (!V_MYSQL) return $dbs;
  1172. $qq = (V_MYSQL < 50000) ? '' : '\'';
  1173. if ($this->CFG['my_db']) {
  1174. $tmp = explode(',', $this->CFG['my_db']);
  1175. foreach($tmp AS $d){
  1176. $d = trim($d);
  1177. $items[] = $qq . mysql_escape_string($d) . $qq;
  1178. $dbs[$d] = "{$d} (0)";
  1179. }
  1180. }
  1181. else{
  1182. $result = mysql_query("SHOW DATABASES") or sxd_my_error();
  1183. while($item = mysql_fetch_row($result)){
  1184. if($item[0] == 'information_schema' || $item[0] == 'mysql') continue;
  1185. $items[] = $qq . mysql_escape_string($item[0]) . $qq;
  1186. $dbs[$item[0]] = "{$item[0]} (0)";
  1187. }
  1188. }
  1189. if(V_MYSQL < 50000){
  1190. foreach($items AS $item){
  1191. $tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error();
  1192. if ($tables) {
  1193. $tabs = mysql_num_rows($tables);
  1194. $dbs[$item] = "{$item} ({$tabs})";
  1195. }
  1196. }
  1197. }
  1198. else {
  1199. $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : '';
  1200. $result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error();
  1201. while($item = mysql_fetch_row($result)){
  1202. if($item[0] == 'information_schema' || $item[0] == 'mysql') continue;
  1203. $dbs[$item[0]] = "{$item[0]} ({$item[1]})";
  1204. }
  1205. }
  1206. return $dbs;
  1207. }
  1208. function getCharsetList(){
  1209. $tmp = array(0 => '- auto -');
  1210. if (!V_MYSQL) return $tmp;
  1211. if(V_MYSQL > 40101) {
  1212. $def_charsets = '';
  1213. if(!empty($this->CFG['charsets'])){
  1214. $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : '';
  1215. }
  1216. $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error();
  1217. if ($r) {
  1218. while($item = mysql_fetch_assoc($r)){
  1219. if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']})
  1220. }
  1221. }
  1222. }
  1223. return $tmp;
  1224. }
  1225. function getCollationList(){
  1226. $tmp = array();
  1227. if (!V_MYSQL) return $tmp;
  1228. if(V_MYSQL > 40101) {
  1229. $def_charsets = '';
  1230. if(!empty($this->CFG['charsets'])){
  1231. $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : '';
  1232. }
  1233. $r = mysql_query("SHOW COLLATION") or sxd_my_error();
  1234. if ($r) {
  1235. while($item = mysql_fetch_assoc($r)){
  1236. if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0;
  1237. }
  1238. }
  1239. }
  1240. return $tmp;
  1241. }
  1242. function getObjects($tree, $db_name){
  1243. mysql_select_db($db_name);
  1244. // ??????? ???????
  1245. $r = mysql_query('SHOW TABLE STATUS');
  1246. $tab_prefix_last = $tab_prefix = '*';
  1247. $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array());
  1248. if($r){
  1249. while($item = mysql_fetch_assoc($r)){
  1250. if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) {
  1251. $objects['VI'][]= $item['Name'];
  1252. }
  1253. else{
  1254. $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']);
  1255. }
  1256. }
  1257. if (V_MYSQL > 50014 && $tree != 'services') {
  1258. $shows = array(
  1259. "PROCEDURE STATUS WHERE db='{$db_name}'",
  1260. "FUNCTION STATUS WHERE db='{$db_name}'",
  1261. 'TRIGGERS'
  1262. );
  1263. if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'";
  1264. // TODO: ????????? ???????? ??????? ? ?????????
  1265. for($i = 0, $l = count($shows); $i < $l; $i++){
  1266. $r = mysql_query('SHOW ' . $shows[$i]);
  1267. if($r && mysql_num_rows($r) > 0) {
  1268. $col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name';
  1269. $type = substr($shows[$i], 0, 2);
  1270. while($item = mysql_fetch_assoc($r)){
  1271. $objects[$type][] = $item[$col_name];
  1272. }
  1273. }
  1274. }
  1275. }
  1276. else {
  1277. $objects['VI'] = array();
  1278. }
  1279. }
  1280. return $this->formatTree($tree, $objects);
  1281. }
  1282. function getFileObjects($tree, $name, $formatTree = true){
  1283. // ??????? ???????
  1284. $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array());
  1285. if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return '';
  1286. $name = $this->CFG['backup_path'] . $name;
  1287. if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";}
  1288. $fp = $this->openFile($name, 'r');
  1289. $temp = fread($fp, 60000);
  1290. // ?????? ????? Sypex Dumper 2 - SXD20
  1291. //if(!preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)) return "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));z('restore_savejob').disabled = z('restore_runjob').disabled = true;";
  1292. if(preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)){
  1293. $head = explode("\n", $m[1]);
  1294. $h = explode('|', $head[0]);
  1295. for($i = 1, $c = count($head); $i < $c; $i++){
  1296. $objects[substr($head[$i], 1,2)] = explode('|', substr($head[$i], 4));
  1297. }
  1298. for($i = 0, $l = count($objects['TA']); $i < $l; $i++){
  1299. $objects['TA'][$i] = explode('`', $objects['TA'][$i]);
  1300. }
  1301. }
  1302. else {
  1303. $h[9] = '';
  1304. }
  1305. return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects;
  1306. }
  1307. function formatTree($tree, &$objects){
  1308. $obj = '';
  1309. $pid = $row = 1;
  1310. $info = array(
  1311. 'TA' => array($this->LNG['obj_tables'], 1),
  1312. 'VI' => array($this->LNG['obj_views'], 3),
  1313. 'PR' => array($this->LNG['obj_procs'], 5),
  1314. 'FU' => array($this->LNG['obj_funcs'], 7),
  1315. 'TR' => array($this->LNG['obj_trigs'], 9),
  1316. 'EV' => array($this->LNG['obj_events'], 11)
  1317. );
  1318. // ??????? ??????? ? ??????????
  1319. $tab_prefix_last = $tab_prefix = '*';
  1320. for($i = 0, $l = count($objects['TA']); $i < $l; $i++){
  1321. $t = $objects['TA'][$i];
  1322. $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*';
  1323. if ($tab_prefix != $tab_prefix_last) {
  1324. if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix;
  1325. $tab_prefix_last = $tab_prefix;
  1326. }
  1327. $objects['TA'][$tab_prefix][] = $t;
  1328. unset($objects['TA'][$i]);
  1329. }
  1330. foreach($objects AS $type => $o){
  1331. if(!count($o)) continue;
  1332. if($type == 'TA') {
  1333. $open_childs = count($o['*']) > 1 ? 0 : 1;
  1334. $obj .= "[{$row},0,'" . mysql_escape_string($info[$type][0]) . "',1,1,1],";
  1335. $row++;
  1336. foreach($o['*'] AS $value){
  1337. if(is_string($value)){
  1338. if(count($o[$value]) > 1) {
  1339. $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],";
  1340. $pid = $row++;
  1341. for($i = 0, $l = count($o[$value]); $i < $l; $i++){
  1342. $checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1;
  1343. $obj .= "[{$row},{$pid},'" . mysql_escape_string($o[$value][$i][0]) . "',2,{$checked},{$o[$value][$i][2]}],";
  1344. $row++;
  1345. }
  1346. }
  1347. else {
  1348. $value = $o[$value][0];
  1349. }
  1350. }
  1351. //$pid = 1;
  1352. if (is_array($value)){
  1353. $checked = ($value[1] == '' && $value[2] == '') ? 2 : 1;
  1354. $obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],";
  1355. $row++;
  1356. }
  1357. }
  1358. }
  1359. else {
  1360. $obj .= "[{$row},0,'" . mysql_escape_string($info[$type][0]) . "',{$info[$type][1]},1,1],";
  1361. $pid = $row++;
  1362. $info[$type][1]++;
  1363. for($i = 0, $l = count($o); $i < $l; $i++){
  1364. $o[$i] = mysql_escape_string($o[$i]);
  1365. $obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],";
  1366. $row++;
  1367. }
  1368. }
  1369. }
  1370. $add = '';
  1371. if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";";
  1372. return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add;
  1373. }
  1374. function getFileList(){
  1375. $files = array();
  1376. if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) {
  1377. while (false !== ($file = readdir($handle))) {
  1378. if (preg_match("/^.+?\.sql(\.(gz|bz2))?$/", $file)) {
  1379. $files[$file] = $file;
  1380. }
  1381. }
  1382. closedir($handle);
  1383. }
  1384. ksort($files);
  1385. return $files;
  1386. }
  1387. function getSavedJobs(){
  1388. $sj = array('sj_backup' => array(), 'sj_restore' => array(),);
  1389. if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) {
  1390. while (false !== ($file = readdir($handle))) {
  1391. if (preg_match("/^sj_(.+?)\.job.php$/", $file)) {
  1392. include($this->CFG['backup_path'] . $file);
  1393. $sj['sj_' . $JOB['type']][$JOB['job']] = "<b>{$JOB['job']}</b><br><i>{$JOB['title']}&nbsp;</i>";
  1394. }
  1395. }
  1396. closedir($handle);
  1397. }
  1398. if(count($sj['sj_backup']) > 0){
  1399. ksort($sj['sj_backup']);
  1400. }
  1401. else {
  1402. $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']);
  1403. }
  1404. if(count($sj['sj_restore']) > 0){
  1405. ksort($sj['sj_restore']);
  1406. }
  1407. else {
  1408. $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']);
  1409. }
  1410. return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");";
  1411. }
  1412. function getFileListExtended(){
  1413. $files = array();
  1414. if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) {
  1415. while (false !== ($file = readdir($handle))) {
  1416. if (preg_match("/^.+?\.sql(\.(gz|bz2))?$/", $file, $m)) {
  1417. $fp = $this->openFile($this->CFG['backup_path'] . $file, 'r');
  1418. $ext = !empty($m[2]) ? $m[2] : 'sql';
  1419. $temp = fgets($fp);
  1420. if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){
  1421. $h = explode('|', $m[1]);
  1422. $files[] = array($h[5], substr($h[4], 0, -3), $ext, $h[7], number_format($h[8], 0, '', ' '), filesize($this->CFG['backup_path'] . $file), $h[9], $file);
  1423. }
  1424. elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){
  1425. $h = explode('|', $m[1]);
  1426. $files[] = array($h[1], substr($h[3], 0, -3), $ext, $h[2], number_format($h[4], 0, '', ' '), filesize($this->CFG['backup_path'] . $file), 'SXD 1.0.x', $file);
  1427. }
  1428. else {
  1429. $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file);
  1430. }
  1431. }
  1432. }
  1433. closedir($handle);
  1434. }
  1435. function s($a, $b){
  1436. return strcmp($b[1], $a[1]);
  1437. }
  1438. usort($files, 's');
  1439. return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');';
  1440. }
  1441. function saveJob($job, $config){
  1442. $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>");
  1443. }
  1444. function openFile($name, $mode){
  1445. if($mode == 'r') {
  1446. if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]);
  1447. }
  1448. else{
  1449. switch($this->JOB['zip']) {
  1450. case 0 : $this->JOB['file_ext'] = 'sql'; break;
  1451. case 10: $this->JOB['file_ext'] = 'sql.bz2'; break;
  1452. default: $this->JOB['file_ext'] = 'sql.gz'; break;
  1453. }
  1454. }
  1455. switch ($this->JOB['file_ext']){
  1456. case 'sql':
  1457. return fopen($name, "{$mode}b");
  1458. break;
  1459. case 'sql.bz2':
  1460. return bzopen($name, $mode);
  1461. break;
  1462. case 'sql.gz':
  1463. return gzopen($name, $mode . ($mode == 'w' ? $this->JOB['zip'] : ''));
  1464. break;
  1465. default: return false;
  1466. }
  1467. }
  1468. }
  1469. function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;\n"){
  1470. static $l = '';
  1471. static $r = 0;
  1472. $fs = ftell($f);
  1473. $delim_len = strlen($delimiter);
  1474. while($r || $s = fread($f, 61440)){
  1475. if(!$r) $l .= $s;
  1476. $pos = strpos($l, $delimiter);
  1477. if ($pos !== false) {
  1478. // ???? ????????? ???????
  1479. $q = substr($l, 0, $pos);
  1480. $l = substr($l, $pos+$delim_len);
  1481. $r = 1;
  1482. $seek = strlen($l);
  1483. return $q;
  1484. }
  1485. if($ei) {
  1486. $pos = strrpos($l, "\n");
  1487. if($pos > 0 && $l{$pos-1} === ',') {
  1488. // ????????? ?? ???????
  1489. $q = substr($l, 0, $pos-1);
  1490. $l = substr($l, $pos+1);
  1491. $seek = strlen($l);
  1492. $r = 0;
  1493. return $q;
  1494. }
  1495. }
  1496. $r = 0;
  1497. }
  1498. if (!empty($l)) {
  1499. return $l;
  1500. }
  1501. return false;
  1502. }
  1503. function sxd_check($n, $obj, $filt){
  1504. return isset($obj[$n]) || ($filt && preg_match($filt, $n));
  1505. }
  1506. function sxd_php2json($obj){
  1507. if(count($obj) == 0) return '[]';
  1508. $is_obj = isset($obj[count($obj) - 1]) ? false : true;
  1509. $str = $is_obj ? '{' : '[';
  1510. foreach ($obj AS $key => $value) {
  1511. $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : '';
  1512. if (is_array($value)) $str .= sxd_php2json($value);
  1513. elseif (is_null($value)) $str .= 'null';
  1514. elseif (is_bool($value)) $str .= $value ? 'true' : 'false';
  1515. elseif (is_numeric($value)) $str .= $value;
  1516. else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'";
  1517. $str .= ',';
  1518. }
  1519. return substr_replace($str, $is_obj ? '}' : ']', -1);
  1520. }
  1521. function sxd_ver2int($ver){
  1522. return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0;
  1523. }
  1524. function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){
  1525. global $SXD;
  1526. if($SXD->try) return;
  1527. if(strpos($errmsg, 'timezone settings')) return;
  1528. $errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error',
  1529. 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice');
  1530. $str = "{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})";
  1531. if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "error.log");
  1532. if($errno == 8 || $errno == 1024) {
  1533. if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . mysql_escape_string($str) . "');" : $str;
  1534. else {
  1535. fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n");
  1536. }
  1537. }
  1538. elseif($errno < 1024) {
  1539. $SXD->error = true;
  1540. if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . mysql_escape_string($str) . "');" : $str;
  1541. else {
  1542. $SXD->rtl[1] = time();
  1543. $SXD->rtl[9] = 5;
  1544. fseek($SXD->fh_rtl, 0);
  1545. fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl));
  1546. fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t4\t{$str}\n");
  1547. unset($SXD->rtl);
  1548. }
  1549. die;
  1550. }
  1551. }
  1552. function sxd_my_error(){
  1553. trigger_error(mysql_error(), E_USER_ERROR);
  1554. }
  1555. function sxd_shutdown(){
  1556. global $SXD;
  1557. if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) {
  1558. $SXD->rtl[1] = time();
  1559. if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){
  1560. $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']);
  1561. $SXD->rtl[9] = !empty($type) ? $type : 2;
  1562. }
  1563. else $SXD->rtl[9] = 5;
  1564. fseek($SXD->fh_rtl, 0);
  1565. fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl));
  1566. }
  1567. }
  1568. function sxd_antimagic($arr){
  1569. return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr);
  1570. }
  1571. // Templates
  1572. function sxd_tpl_page(){
  1573. global $SXD;
  1574. return <<<HTML
  1575. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  1576. <html>
  1577. <head>
  1578. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  1579. <title>{$SXD->name}</title>
  1580. <link rel="stylesheet" type="text/css" href="load.php?sxd.v207.css">
  1581. <script type="text/javascript" src="load.php?sxd.v207.js"></script>
  1582. <script type="text/javascript" src="load.php?{$SXD->LNG['name']}.lng.js"></script>
  1583. <link rel="shortcut icon" href="load.php?favicon.v207.ico">
  1584. </head>
  1585. <body>
  1586. <div id="main_div">
  1587. <div id="header">{$SXD->name}</div>
  1588. <div id="sxdToolbar"></div>
  1589. <div id="name"><div id="loading"></div><b></b></div>
  1590. <div id="content" class="content">
  1591. <table cellspacing="0" id="tab_backup">
  1592. <tr>
  1593. <td width="242" valign="top">
  1594. <div class="caption">{$SXD->LNG['combo_db']}</div><div id="backup_db"></div>
  1595. <div class="caption">{$SXD->LNG['combo_charset']}</div><div id="backup_charset"></div>
  1596. <div class="caption">{$SXD->LNG['combo_zip']}</div><div id="backup_zip"></div>
  1597. <div class="caption">{$SXD->LNG['combo_comments']}</div>
  1598. <div class="border"><textarea cols="10" rows="3" id="backup_comment"></textarea></div>
  1599. <div class="caption" style="margin-top:12px;">
  1600. <fieldset><legend>{$SXD->LNG['del_legend']}</legend>
  1601. <div class="caption">&nbsp;– {$SXD->LNG['del_date']}</div>
  1602. <div class="caption">&nbsp;– {$SXD->LNG['del_count']}</div>
  1603. </fieldset>
  1604. </div>
  1605. </td>
  1606. <td width="308" valign="top">
  1607. <div class="caption">{$SXD->LNG['tree']}</div><div id=backup_tree class="zTree"></div>
  1608. </td>
  1609. </tr>
  1610. <tr><td></td><td align="right"><input type="button" value="{$SXD->LNG['btn_save']}" onclick="sxd.showDialog('savejob');z('sj_name').value = sxd.combos.backup_db.value;"> <input type="button" value="{$SXD->LNG['btn_exec']}" onclick="sxd.runBackup();"></td></tr>
  1611. </table>
  1612. <table cellspacing="0" id="tab_restore" style="display:none;">
  1613. <tr>
  1614. <td width="242" valign="top">
  1615. <div class="caption">{$SXD->LNG['combo_db']}</div><div id="restore_db"></div>
  1616. <div class="caption">{$SXD->LNG['combo_charset']}</div><div id="restore_charset"></div>
  1617. <div class="caption">{$SXD->LNG['combo_file']}</div><div id="restore_file"></div>
  1618. <div class="caption">{$SXD->LNG['combo_comments']}</div>
  1619. <div class="border"><textarea cols="10" rows="3" id="restore_comment" readonly></textarea></div>
  1620. <div class="caption">{$SXD->LNG['combo_strategy']}</div><div id="restore_type"></div>
  1621. <div class="caption" style="margin-top:17px;">
  1622. <fieldset><legend>{$SXD->LNG['ext_legend']}</legend>
  1623. <div class="caption"><label><input type="checkbox" id="correct"> {$SXD->LNG['correct']}</label></div>
  1624. <div class="caption"><label><input type="checkbox" id="autoinc"> {$SXD->LNG['autoinc']}</label></div>
  1625. </fieldset>
  1626. </div>
  1627. </td>
  1628. <td width="308" valign="top">
  1629. <div class="caption">{$SXD->LNG['tree']}</div><div id=restore_tree class="zTree"></div>
  1630. </td>
  1631. </tr>
  1632. <tr><td></td><td align="right"><input type="button" value="{$SXD->LNG['btn_save']}" onclick="sxd.showDialog('savejob');z('sj_name').value = sxd.combos.restore_db.value;" id=restore_savejob> <input type="button" value="{$SXD->LNG['btn_exec']}" onclick="sxd.runRestore();" id=restore_runjob></td></tr>
  1633. </table>
  1634. <table cellspacing="0" id="tab_log" style="display:none;">
  1635. <tr>
  1636. <td valign="top" colspan=2>
  1637. <div id=sxdGrid1></div>
  1638. </td>
  1639. </tr>
  1640. <tr><td colspan=2>
  1641. <table class=progress>
  1642. <tr><td>{$SXD->LNG['status_current']}</td><td><div id="sxdProc1"></div></td><td width=60>{$SXD->LNG['time_elapsed']}</td><td width=40 align=right id="sxdTime1">00:00</td></tr>
  1643. <tr><td>{$SXD->LNG['status_total']}</td><td><div id="sxdProc2"></div></td><td>{$SXD->LNG['time_left']}</td><td align=right id="sxdTime2">00:00</td></tr>
  1644. </table>
  1645. </td></tr>
  1646. <tr><td width="152"><input type="button" value="{$SXD->LNG['btn_clear']}" onclick="sxd.log.clear();"></td><td width="380" align="right">
  1647. <input type="button" value="{$SXD->LNG['btn_download']}" id="btn_down" onclick="sxd.runFiles('download', this.file);" style="display:none;">
  1648. <input type="button" value="{$SXD->LNG['btn_again']}" id="btn_again" onclick="sxd.runAgain();" disabled>
  1649. <input type="button" value="{$SXD->LNG['btn_stop']}" id="btn_stop" onclick="sxd.stopJob();" disabled>
  1650. <input type="button" value="{$SXD->LNG['btn_pause']}" id="btn_pause" onclick="sxd.pauseJob();" disabled>
  1651. <input type="button" value="{$SXD->LNG['btn_resume']}" id="btn_resume" onclick="sxd.resumeJob();" style="display:none;">
  1652. </td></tr>
  1653. </table>
  1654. <table cellspacing="0" id="tab_result" style="display:none;">
  1655. <tr>
  1656. <td valign="top">
  1657. <div id=sxdGrid3></div>
  1658. </td>
  1659. </tr>
  1660. <tr><td>
  1661. <input type="button" value="{$SXD->LNG['btn_clear']}" onclick="sxd.result.clear();">
  1662. </td></tr>
  1663. </table>
  1664. <table cellspacing="0" id="tab_files" style="display:none;">
  1665. <tr>
  1666. <td valign="top" colspan=2>
  1667. <div id=sxdGrid2></div>
  1668. </td>
  1669. </tr>
  1670. <tr><td width="242"><form id="save_file" method="GET" style="visibility:hidden;display:inline;" target=save></form><input type="button" value="{$SXD->LNG['btn_delete']}" onclick="sxd.runFiles('delete')"></td><td width="290" align="right">
  1671. <input type="button" value="{$SXD->LNG['btn_download']}" onclick="sxd.runFiles('download')">
  1672. <input type="button" value="{$SXD->LNG['btn_open']}" onclick="sxd.runFiles('open')">
  1673. </td></tr>
  1674. </table>
  1675. <table cellspacing="0" id="tab_services" style="display:none;">
  1676. <tr>
  1677. <td width="242" valign="top">
  1678. <div class="caption">{$SXD->LNG['combo_db']}</div><div id="services_db"></div>
  1679. <br>
  1680. <div class="caption">{$SXD->LNG['opt_check']}</div><div id="services_check"></div>
  1681. <div class="caption">{$SXD->LNG['opt_repair']}</div><div id="services_repair"></div>
  1682. </td>
  1683. <td width="308" valign="top">
  1684. <div class="caption">{$SXD->LNG['tree']}</div><div id=services_tree class="zTree"></div>
  1685. </td>
  1686. </tr>
  1687. <tr><td align="right" colspan=2><input type="button" value="{$SXD->LNG['btn_delete_db']}" onclick="sxd.runServices('delete')" style="float:left;"> <input type="button" value="{$SXD->LNG['btn_check']}" onclick="sxd.runServices('check')"> <input type="button" value="{$SXD->LNG['btn_repair']}" onclick="sxd.runServices('repair')"> <input type="button" value="{$SXD->LNG['btn_analyze']}" onclick="sxd.runServices('analyze')"> <input type="button" value="{$SXD->LNG['btn_optimize']}" onclick="sxd.runServices('optimize')"></td></tr>
  1688. </table>
  1689. <table cellspacing="0" id="tab_options" style="display:none;">
  1690. <tr>
  1691. <td valign="top" colspan=2>
  1692. <div style="height: 341px;">
  1693. <fieldset>
  1694. <legend>{$SXD->LNG['cfg_legend']}</legend>
  1695. <table cellspacing="0">
  1696. <tr>
  1697. <td width=190>{$SXD->LNG['cfg_time_web']}</td>
  1698. <td width=45><input type="text" id="time_web" style="width:40px;"></td>
  1699. <td align="right">{$SXD->LNG['cfg_time_cron']}</td>
  1700. <td width=40 align="right"><input type="text" id="time_cron" style="width:40px;"></td>
  1701. </tr>
  1702. <tr>
  1703. <td>{$SXD->LNG['cfg_backup_path']}</td>
  1704. <td colspan=3><input type="text" id="backup_path" style="width:351px;"></td>
  1705. </tr>
  1706. <tr>
  1707. <td>{$SXD->LNG['cfg_backup_url']}</td>
  1708. <td colspan=3><input type="text" id="backup_url" style="width:351px;"></td>
  1709. </tr>
  1710. <tr>
  1711. <td>{$SXD->LNG['cfg_globstat']}</td>
  1712. <td colspan=3><input type="checkbox" id="globstat" value="1"></td>
  1713. </tr>
  1714. </table>
  1715. </fieldset>
  1716. <fieldset>
  1717. <legend>{$SXD->LNG['cfg_confirm']}</legend>
  1718. <table cellspacing="0">
  1719. <tr>
  1720. <td width="33%"><label><input type="checkbox" id="conf_import" value="1"> {$SXD->LNG['cfg_conf_import']}</label></td>
  1721. <td width="34%"><label><input type="checkbox" id="conf_file" value="1"> {$SXD->LNG['cfg_conf_file']}</label></td>
  1722. <td width="33%"><label><input type="checkbox" id="conf_db" value="1"> {$SXD->LNG['cfg_conf_db']}</label></td>
  1723. </tr>
  1724. </table>
  1725. </fieldset>
  1726. <fieldset>
  1727. <legend>{$SXD->LNG['cfg_extended']}</legend>
  1728. <table cellspacing="0">
  1729. <tr>
  1730. <td width=190>{$SXD->LNG['cfg_charsets']}</td>
  1731. <td><input type="text" id="charsets" value="" style="width:351px;"></td>
  1732. </tr>
  1733. <tr>
  1734. <td>{$SXD->LNG['cfg_only_create']}</td>
  1735. <td><input type="text" id="only_create" value="" style="width:351px;"></td>
  1736. </tr>
  1737. <tr>
  1738. <td>{$SXD->LNG['cfg_auth']}</td>
  1739. <td><input type="text" id="auth" value="" style="width:351px;"></td>
  1740. </tr>
  1741. </table>
  1742. </fieldset>
  1743. </div>
  1744. </td>
  1745. </tr>
  1746. <tr><td align="right" colspan=2><input type="button" value="{$SXD->LNG['btn_save']}" onclick="sxd.saveOptions();"></td></tr>
  1747. </table>
  1748. </div>
  1749. </div>
  1750. <div id="overlay"></div>
  1751. <div class="dialog" id ="dia_connect">
  1752. <div class="header">{$SXD->LNG['con_header']}</div>
  1753. <div class="content">
  1754. <table cellspacing="5">
  1755. <tr>
  1756. <td valign="top">
  1757. <fieldset>
  1758. <legend>{$SXD->LNG['connect']}</legend>
  1759. <table cellspacing="3">
  1760. <tr>
  1761. <td width="80">{$SXD->LNG['my_host']}</td>
  1762. <td width="126"><input type="text" id="con_host" style="width:120px;"></td>
  1763. <td width="40" align="right">{$SXD->LNG['my_port']}</td>
  1764. <td width="36"><input type="text" id="con_port" maxlength="5" style="width:30px;"></td>
  1765. </tr>
  1766. <tr>
  1767. <td>{$SXD->LNG['my_user']}</td>
  1768. <td colspan="3"><input type="text" id="con_user" name="user" style="width:202px;"></td>
  1769. </tr>
  1770. <tr>
  1771. <td>{$SXD->LNG['my_pass']}</td>
  1772. <td colspan="3"><input type="password" id="con_pass" name="pass" title="{$SXD->LNG['my_pass_hidden']}" style="width:202px;" onchange="this.changed = true;"></td>
  1773. </tr>
  1774. <tr>
  1775. <td></td>
  1776. <td colspan="3"><label><input type="checkbox" id="con_comp" value="1"> {$SXD->LNG['my_comp']}</label></td>
  1777. </tr>
  1778. <tr>
  1779. <td>{$SXD->LNG['my_db']}</td>
  1780. <td colspan="3"><input type="text" id="con_db" style="width:202px;"></td>
  1781. </tr>
  1782. </table></fieldset>
  1783. </td>
  1784. </tr>
  1785. <tr class="buttons"><td align="right"><input type="button" value="{$SXD->LNG['btn_save']}" onclick="sxd.saveConnect();"><input type="button" value="{$SXD->LNG['btn_cancel']}" onclick="sxd.hideDialog('connect');"></td></tr>
  1786. </table>
  1787. </div>
  1788. </div>
  1789. <div class="dialog" id ="dia_savejob">
  1790. <div class="header">{$SXD->LNG['sj_header']}</div>
  1791. <div class="content">
  1792. <table cellspacing="5">
  1793. <tr>
  1794. <td valign="top">
  1795. <fieldset>
  1796. <legend>{$SXD->LNG['sj_job']}</legend>
  1797. <table cellspacing="3">
  1798. <tr>
  1799. <td width="80">{$SXD->LNG['sj_name']}</td>
  1800. <td><input type="text" id="sj_name" style="width:202px;" maxlength="12" value=""></td>
  1801. </tr>
  1802. <tr>
  1803. <td>{$SXD->LNG['sj_title']}</td>
  1804. <td><input type="text" id="sj_title" maxlength="64" style="width:202px;"></td>
  1805. </tr>
  1806. </table></fieldset>
  1807. </td>
  1808. </tr>
  1809. <tr class="buttons"><td align="right"><input type="button" value="{$SXD->LNG['btn_save']}" onclick="sxd.saveJob();"><input type="button" value="{$SXD->LNG['btn_cancel']}" onclick="sxd.hideDialog('savejob');"></td></tr>
  1810. </table>
  1811. </div>
  1812. </div>
  1813. <div class=dialog id="dia_createdb">
  1814. <div class="header">{$SXD->LNG['cdb_header']}</div>
  1815. <div class="content">
  1816. <table cellspacing="5">
  1817. <tr>
  1818. <td valign="top">
  1819. <fieldset>
  1820. <legend>{$SXD->LNG['cdb_detail']}</legend>
  1821. <table cellspacing="3">
  1822. <tr>
  1823. <td width="80">{$SXD->LNG['cdb_name']}</td>
  1824. <td width="202"><input type="text" id="db_name" value="my_db_1" style="width:202px;"></td>
  1825. </tr>
  1826. <tr>
  1827. <td>{$SXD->LNG['combo_charset']}</td>
  1828. <td><div id="db_charset"></div></td>
  1829. </tr>
  1830. <tr>
  1831. <td>{$SXD->LNG['combo_collate']}</td>
  1832. <td><div id="db_charset_col"></div></td>
  1833. </tr>
  1834. </table>
  1835. </fieldset>
  1836. </td>
  1837. </tr>
  1838. <tr class="buttons"><td align="right"><input type="button" value="{$SXD->LNG['btn_create']}" onclick="sxd.addDb();"><input type="button" value="{$SXD->LNG['btn_cancel']}" onclick="sxd.hideDialog('createdb');"></td></tr>
  1839. </table>
  1840. </div>
  1841. </div>
  1842. <div id=sxdMenu style="display:none;z-index:9999;"></div>
  1843. <script type="text/javascript">
  1844. sxd.init();
  1845. sxd.backupUrl = '{$SXD->CFG['backup_url']}';
  1846. sxd.tbar.init('sxdToolbar', {$SXD->VAR['toolbar']});
  1847. {$SXD->VAR['combos']}
  1848. sxd.actions.tab_backup();
  1849. </script>
  1850. </body>
  1851. </html>
  1852. HTML;
  1853. }
  1854. function sxd_tpl_auth($error = ''){
  1855. global $SXD;
  1856. return <<<HTML
  1857. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  1858. <html>
  1859. <head>
  1860. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  1861. <title>{$SXD->name}</title>
  1862. <link rel="shortcut icon" href="load.php?favicon.v207.ico">
  1863. <link rel="stylesheet" type="text/css" href="load.php?sxd.v207.css">
  1864. </head>
  1865. <body>
  1866. <div class="dialog" id="dia_auth">
  1867. <div class="header"><a href="http://sypex.net/">{$SXD->name}</a></div>
  1868. <div class="content" id="div_1" style="line-height:50px;text-align:center;">{$SXD->LNG['js_required']}</div>
  1869. <div class="content" id="div_2" style="display:none;">
  1870. <form method="post">
  1871. <table cellspacing="5">
  1872. <tr>
  1873. <td valign="top" colspan="3">
  1874. <fieldset>
  1875. <legend>{$SXD->LNG['auth']}</legend>
  1876. <table cellspacing="3">
  1877. <tr>
  1878. <td width="90">{$SXD->LNG['auth_user']}</td>
  1879. <td width="192"><input type="text" name="user" value="{$_POST['user']}" class="i202"></td>
  1880. </tr>
  1881. <tr>
  1882. <td>{$SXD->LNG['my_pass']}</td>
  1883. <td><input type="password" name="pass" value="{$_POST['pass']}" class="i202"></td>
  1884. </tr>
  1885. <tr>
  1886. <td></td>
  1887. <td><label><input type="checkbox" name="save" value="1"{$_POST['save']}> {$SXD->LNG['auth_remember']}</label></td>
  1888. </tr>
  1889. <tr>
  1890. <td>Language:</td>
  1891. <td><select type="text" name="lang" style="width:198px;" onChange="this.form.submit();">{$SXD->lng_list}</select></td>
  1892. </tr>
  1893. </table>
  1894. <table cellspacing="3" id="hst" style="display:none;">
  1895. <tr>
  1896. <td width="90">{$SXD->LNG['my_host']}</td>
  1897. <td width="116"><input type="text" name="host" style="width:110px;" value="{$_POST['host']}"></td>
  1898. <td width="40" align="right">{$SXD->LNG['my_port']}</td>
  1899. <td width="36"><input type="text" name="port" maxlength="5" style="width:30px;" value="{$_POST['port']}"></td>
  1900. </tr>
  1901. </table>
  1902. </fieldset>
  1903. </td>
  1904. </tr>
  1905. <tr class="buttons"><td align="left"><input type="button" value="{$SXD->LNG['btn_details']}" onclick="var s = document.getElementById('hst').style; s.display = (s.display == 'block') ? 'none' : 'block';"></td><td align="right"><input type="submit" value="{$SXD->LNG['btn_enter']}"></td></tr>
  1906. </table>
  1907. </form>
  1908. </div>
  1909. <script type="text/javascript">document.getElementById('div_1').style.display = 'none';document.getElementById('div_2').style.display = 'block';</script>
  1910. </div>
  1911. </body>
  1912. </html>
  1913. HTML;
  1914. }
  1915. ?>