@@ -168,6 +168,11 @@ discard block |
||
| 168 | 168 | if(isset($_POST['ajax'])) $this->ajax($_POST['ajax']); |
| 169 | 169 | else $this->main();exit; |
| 170 | 170 | } |
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param string $name |
|
| 174 | + * @param string $content |
|
| 175 | + */ |
|
| 171 | 176 | function saveToFile($name, $content){ |
| 172 | 177 | $fp = fopen($name, "w"); |
| 173 | 178 | fwrite($fp, $content); |
@@ -248,6 +253,12 @@ discard block |
||
| 248 | 253 | include('tmpl.php'); |
| 249 | 254 | echo sxd_tpl_page(); |
| 250 | 255 | } |
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param string $name |
|
| 259 | + * @param integer $ico |
|
| 260 | + * @param string $opt_name |
|
| 261 | + */ |
|
| 251 | 262 | function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
| 252 | 263 | $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
| 253 | 264 | return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
@@ -1313,6 +1324,10 @@ discard block |
||
| 1313 | 1324 | } |
| 1314 | 1325 | return $this->formatTree($tree, $objects); |
| 1315 | 1326 | } |
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * @param string $tree |
|
| 1330 | + */ |
|
| 1316 | 1331 | function getFileObjects($tree, $name, $formatTree = true){ |
| 1317 | 1332 | // Достаем таблицы |
| 1318 | 1333 | $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
@@ -1475,6 +1490,10 @@ discard block |
||
| 1475 | 1490 | function saveJob($job, $config){ |
| 1476 | 1491 | $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
| 1477 | 1492 | } |
| 1493 | + |
|
| 1494 | + /** |
|
| 1495 | + * @param string $mode |
|
| 1496 | + */ |
|
| 1478 | 1497 | function openFile($name, $mode){ |
| 1479 | 1498 | if($mode == 'r') { |
| 1480 | 1499 | if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
@@ -1552,6 +1571,9 @@ discard block |
||
| 1552 | 1571 | } |
| 1553 | 1572 | return substr_replace($str, $is_obj ? '}' : ']', -1); |
| 1554 | 1573 | } |
| 1574 | +/** |
|
| 1575 | + * @param string $ver |
|
| 1576 | + */ |
|
| 1555 | 1577 | function sxd_ver2int($ver){ |
| 1556 | 1578 | return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
| 1557 | 1579 | } |
@@ -22,1127 +22,1127 @@ discard block |
||
| 22 | 22 | $SXD->init(!empty($argc) && $argc > 1 ? $argv : false); |
| 23 | 23 | |
| 24 | 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', 20011); |
|
| 33 | - define('V_PHP', sxd_ver2int(phpversion())); |
|
| 34 | - $this->name = 'Sypex Dumper 2.0.11'; |
|
| 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 | - $this->cron_mode = true; |
|
| 90 | - set_time_limit($CFG['time_cron']); |
|
| 91 | - // Загружаем конфиг файл, если нужно |
|
| 92 | - $auth = $this->connect(); |
|
| 93 | - if($auth && !empty($this->CFG['sjob'])){ |
|
| 94 | - $this->ajax($this->loadJob($this->CFG['sjob'])); |
|
| 95 | - echo file_get_contents($this->JOB['file_log']); |
|
| 96 | - if(file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']); |
|
| 97 | - if(file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']); |
|
| 98 | - } |
|
| 99 | - else echo 'Auth error'; |
|
| 100 | - exit; |
|
| 101 | - } |
|
| 102 | - elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 103 | - $auth = false; |
|
| 104 | - $sfile = 'ses.php'; |
|
| 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', 20011); |
|
| 33 | + define('V_PHP', sxd_ver2int(phpversion())); |
|
| 34 | + $this->name = 'Sypex Dumper 2.0.11'; |
|
| 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 | + $this->cron_mode = true; |
|
| 90 | + set_time_limit($CFG['time_cron']); |
|
| 91 | + // Загружаем конфиг файл, если нужно |
|
| 92 | + $auth = $this->connect(); |
|
| 93 | + if($auth && !empty($this->CFG['sjob'])){ |
|
| 94 | + $this->ajax($this->loadJob($this->CFG['sjob'])); |
|
| 95 | + echo file_get_contents($this->JOB['file_log']); |
|
| 96 | + if(file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']); |
|
| 97 | + if(file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']); |
|
| 98 | + } |
|
| 99 | + else echo 'Auth error'; |
|
| 100 | + exit; |
|
| 101 | + } |
|
| 102 | + elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 103 | + $auth = false; |
|
| 104 | + $sfile = 'ses.php'; |
|
| 105 | 105 | |
| 106 | - if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){ |
|
| 107 | - include($sfile); |
|
| 108 | - if(isset($SES[$_COOKIE['sxd']])) { |
|
| 109 | - $auth = true; |
|
| 110 | - $this->CFG = $SES[$_COOKIE['sxd']]['cfg']; |
|
| 111 | - $this->SES = &$SES; |
|
| 112 | - $this->loadLang($this->CFG['lang']); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - if(!$auth) { |
|
| 116 | - $user = !empty($_POST['user']) ? $_POST['user'] : ''; |
|
| 117 | - $pass = !empty($_POST['pass']) ? $_POST['pass'] : ''; |
|
| 118 | - $host = !empty($_POST['host']) ? $_POST['host'] : (!empty($this->CFG['my_host']) ? $this->CFG['my_host'] : 'localhost'); |
|
| 119 | - $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306; |
|
| 120 | - $temp = preg_split('/\s+/', $this->CFG['auth']); |
|
| 121 | - if(!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']);} |
|
| 122 | - foreach($temp AS $a){ |
|
| 123 | - switch($a) { |
|
| 124 | - case 'cfg': if(empty($user)) {continue;} |
|
| 125 | - $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user']== $user && $CFG['pass'] == $pass; |
|
| 126 | - break; |
|
| 127 | - case 'mysql': if(empty($user)) {continue;} |
|
| 128 | - if($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue;} |
|
| 129 | - $auth = $this->connect($host, $port, $user, $pass); |
|
| 130 | - break; |
|
| 131 | - default: $file = 'auth_' . $a . '.php'; |
|
| 132 | - if(!file_exists($file)) continue; |
|
| 133 | - include $file; |
|
| 134 | - } |
|
| 135 | - if($auth) break; |
|
| 136 | - } |
|
| 137 | - if($auth){ |
|
| 138 | - $key = md5(rand(1,100000) . $user . microtime()); |
|
| 139 | - $CFG['lang'] = $this->LNG['name']; |
|
| 140 | - $_COOKIE['sxd'] = $key; |
|
| 141 | - $this->saveCFG(); |
|
| 142 | - if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | - else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 144 | - header("Location: ./"); |
|
| 145 | - exit; |
|
| 146 | - } |
|
| 147 | - foreach(array('user', 'pass', 'host', 'port') AS $key){ |
|
| 148 | - $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : ''; |
|
| 149 | - } |
|
| 150 | - $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : ''; |
|
| 151 | - } |
|
| 152 | - if (!$auth) { |
|
| 153 | - if(!empty($_POST['ajax'])){ |
|
| 154 | - echo "sxd.hideLoading();alert('Session not found');"; |
|
| 155 | - exit; |
|
| 156 | - } |
|
| 157 | - $this->lng_list = '<option value="auto">- auto -</opinion>'; |
|
| 158 | - if(!isset($this->langs)) {include('lang/list.php');$this->langs = &$langs;} |
|
| 159 | - foreach($this->langs AS $k => $v){ |
|
| 160 | - $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>"; |
|
| 161 | - } |
|
| 162 | - include('tmpl.php'); |
|
| 163 | - echo sxd_tpl_auth(); |
|
| 164 | - exit; |
|
| 165 | - } |
|
| 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();exit; |
|
| 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 | - if(V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error(); |
|
| 187 | - else mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 188 | - define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
|
| 189 | - } |
|
| 190 | - else { |
|
| 191 | - define('V_MYSQL', 0); |
|
| 192 | - $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 193 | - } |
|
| 194 | - $this->try = false; |
|
| 195 | - return V_MYSQL ? true: false; |
|
| 196 | - } |
|
| 197 | - function main(){ |
|
| 198 | - // Тулбар |
|
| 199 | - $this->VAR['toolbar'] = sxd_php2json( |
|
| 200 | - array( |
|
| 201 | - array('backup', $this->LNG['tbar_backup'], 1, 3), |
|
| 202 | - array('restore', $this->LNG['tbar_restore'], 2, 3), |
|
| 203 | - array('|'), |
|
| 204 | - array('files', $this->LNG['tbar_files'], 3, 1), |
|
| 205 | - array('services', $this->LNG['tbar_services'], 5, 1), |
|
| 206 | - array('|'), |
|
| 207 | - array('createdb', $this->LNG['tbar_createdb'], 7, 0), |
|
| 208 | - array('connects', $this->LNG['tbar_connects'], 6, 0), |
|
| 209 | - array('|'), |
|
| 210 | - array('options', $this->LNG['tbar_options'], 4, 1), |
|
| 211 | - array('|'), |
|
| 212 | - array('exit', $this->LNG['tbar_exit'], 8, 1), |
|
| 213 | - ) |
|
| 214 | - ); |
|
| 215 | - $this->db = 'temp'; |
|
| 216 | - $zip = array($this->LNG['zip_none']); |
|
| 217 | - if (function_exists("gzopen")) { |
|
| 218 | - for($i = 1; $i <10; $i++){ |
|
| 219 | - $zip[] = "GZip: {$i}"; |
|
| 220 | - } |
|
| 221 | - $zip[1] .= " ({$this->LNG['zip_min']})"; |
|
| 222 | - $zip[7] .= " ({$this->LNG['default']})"; |
|
| 223 | - } |
|
| 224 | - if (function_exists("bzopen")) { |
|
| 225 | - $zip[10] = "BZip"; |
|
| 226 | - } |
|
| 227 | - end($zip); |
|
| 228 | - $zip[key($zip)] .= " ({$this->LNG['zip_max']})"; |
|
| 229 | - $this->VAR['combos'] = |
|
| 230 | - $this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) . |
|
| 231 | - $this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) . |
|
| 232 | - $this->addCombo('backup_zip', 7, 10, 'zip', $zip) . |
|
| 233 | - $this->addCombo('restore_db', $this->db, 11, 'db') . |
|
| 234 | - $this->addCombo('restore_charset', 0, 9, 'charset') . |
|
| 235 | - $this->addCombo('restore_file', 0, 12, 'files', $this->getFileList()) . |
|
| 236 | - $this->addCombo('restore_type', 0, 13, 'types', array("CREATE + INSERT ({$this->LNG['default']})", 'TRUNCATE + INSERT', 'REPLACE', 'INSERT IGNORE')) . |
|
| 237 | - $this->addCombo('services_db', $this->db, 11, 'db') . |
|
| 238 | - $this->addCombo('services_check', 0, 5, 'check', array("- {$this->LNG['default']} -", 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED')) . |
|
| 239 | - $this->addCombo('services_repair', 0, 5, 'repair', array("- {$this->LNG['default']} -", 'QUICK', 'EXTENDED')) . |
|
| 240 | - $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) . |
|
| 241 | - $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset') |
|
| 242 | - ; |
|
| 243 | - if (!V_MYSQL) $this->VAR['combos'] .= $this->error; |
|
| 244 | - $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();"; |
|
| 245 | - $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">'); |
|
| 246 | - $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">'); |
|
| 106 | + if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){ |
|
| 107 | + include($sfile); |
|
| 108 | + if(isset($SES[$_COOKIE['sxd']])) { |
|
| 109 | + $auth = true; |
|
| 110 | + $this->CFG = $SES[$_COOKIE['sxd']]['cfg']; |
|
| 111 | + $this->SES = &$SES; |
|
| 112 | + $this->loadLang($this->CFG['lang']); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + if(!$auth) { |
|
| 116 | + $user = !empty($_POST['user']) ? $_POST['user'] : ''; |
|
| 117 | + $pass = !empty($_POST['pass']) ? $_POST['pass'] : ''; |
|
| 118 | + $host = !empty($_POST['host']) ? $_POST['host'] : (!empty($this->CFG['my_host']) ? $this->CFG['my_host'] : 'localhost'); |
|
| 119 | + $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306; |
|
| 120 | + $temp = preg_split('/\s+/', $this->CFG['auth']); |
|
| 121 | + if(!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']);} |
|
| 122 | + foreach($temp AS $a){ |
|
| 123 | + switch($a) { |
|
| 124 | + case 'cfg': if(empty($user)) {continue;} |
|
| 125 | + $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user']== $user && $CFG['pass'] == $pass; |
|
| 126 | + break; |
|
| 127 | + case 'mysql': if(empty($user)) {continue;} |
|
| 128 | + if($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue;} |
|
| 129 | + $auth = $this->connect($host, $port, $user, $pass); |
|
| 130 | + break; |
|
| 131 | + default: $file = 'auth_' . $a . '.php'; |
|
| 132 | + if(!file_exists($file)) continue; |
|
| 133 | + include $file; |
|
| 134 | + } |
|
| 135 | + if($auth) break; |
|
| 136 | + } |
|
| 137 | + if($auth){ |
|
| 138 | + $key = md5(rand(1,100000) . $user . microtime()); |
|
| 139 | + $CFG['lang'] = $this->LNG['name']; |
|
| 140 | + $_COOKIE['sxd'] = $key; |
|
| 141 | + $this->saveCFG(); |
|
| 142 | + if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | + else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 144 | + header("Location: ./"); |
|
| 145 | + exit; |
|
| 146 | + } |
|
| 147 | + foreach(array('user', 'pass', 'host', 'port') AS $key){ |
|
| 148 | + $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : ''; |
|
| 149 | + } |
|
| 150 | + $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : ''; |
|
| 151 | + } |
|
| 152 | + if (!$auth) { |
|
| 153 | + if(!empty($_POST['ajax'])){ |
|
| 154 | + echo "sxd.hideLoading();alert('Session not found');"; |
|
| 155 | + exit; |
|
| 156 | + } |
|
| 157 | + $this->lng_list = '<option value="auto">- auto -</opinion>'; |
|
| 158 | + if(!isset($this->langs)) {include('lang/list.php');$this->langs = &$langs;} |
|
| 159 | + foreach($this->langs AS $k => $v){ |
|
| 160 | + $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>"; |
|
| 161 | + } |
|
| 162 | + include('tmpl.php'); |
|
| 163 | + echo sxd_tpl_auth(); |
|
| 164 | + exit; |
|
| 165 | + } |
|
| 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();exit; |
|
| 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 | + if(V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error(); |
|
| 187 | + else mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 188 | + define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
|
| 189 | + } |
|
| 190 | + else { |
|
| 191 | + define('V_MYSQL', 0); |
|
| 192 | + $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 193 | + } |
|
| 194 | + $this->try = false; |
|
| 195 | + return V_MYSQL ? true: false; |
|
| 196 | + } |
|
| 197 | + function main(){ |
|
| 198 | + // Тулбар |
|
| 199 | + $this->VAR['toolbar'] = sxd_php2json( |
|
| 200 | + array( |
|
| 201 | + array('backup', $this->LNG['tbar_backup'], 1, 3), |
|
| 202 | + array('restore', $this->LNG['tbar_restore'], 2, 3), |
|
| 203 | + array('|'), |
|
| 204 | + array('files', $this->LNG['tbar_files'], 3, 1), |
|
| 205 | + array('services', $this->LNG['tbar_services'], 5, 1), |
|
| 206 | + array('|'), |
|
| 207 | + array('createdb', $this->LNG['tbar_createdb'], 7, 0), |
|
| 208 | + array('connects', $this->LNG['tbar_connects'], 6, 0), |
|
| 209 | + array('|'), |
|
| 210 | + array('options', $this->LNG['tbar_options'], 4, 1), |
|
| 211 | + array('|'), |
|
| 212 | + array('exit', $this->LNG['tbar_exit'], 8, 1), |
|
| 213 | + ) |
|
| 214 | + ); |
|
| 215 | + $this->db = 'temp'; |
|
| 216 | + $zip = array($this->LNG['zip_none']); |
|
| 217 | + if (function_exists("gzopen")) { |
|
| 218 | + for($i = 1; $i <10; $i++){ |
|
| 219 | + $zip[] = "GZip: {$i}"; |
|
| 220 | + } |
|
| 221 | + $zip[1] .= " ({$this->LNG['zip_min']})"; |
|
| 222 | + $zip[7] .= " ({$this->LNG['default']})"; |
|
| 223 | + } |
|
| 224 | + if (function_exists("bzopen")) { |
|
| 225 | + $zip[10] = "BZip"; |
|
| 226 | + } |
|
| 227 | + end($zip); |
|
| 228 | + $zip[key($zip)] .= " ({$this->LNG['zip_max']})"; |
|
| 229 | + $this->VAR['combos'] = |
|
| 230 | + $this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) . |
|
| 231 | + $this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) . |
|
| 232 | + $this->addCombo('backup_zip', 7, 10, 'zip', $zip) . |
|
| 233 | + $this->addCombo('restore_db', $this->db, 11, 'db') . |
|
| 234 | + $this->addCombo('restore_charset', 0, 9, 'charset') . |
|
| 235 | + $this->addCombo('restore_file', 0, 12, 'files', $this->getFileList()) . |
|
| 236 | + $this->addCombo('restore_type', 0, 13, 'types', array("CREATE + INSERT ({$this->LNG['default']})", 'TRUNCATE + INSERT', 'REPLACE', 'INSERT IGNORE')) . |
|
| 237 | + $this->addCombo('services_db', $this->db, 11, 'db') . |
|
| 238 | + $this->addCombo('services_check', 0, 5, 'check', array("- {$this->LNG['default']} -", 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED')) . |
|
| 239 | + $this->addCombo('services_repair', 0, 5, 'repair', array("- {$this->LNG['default']} -", 'QUICK', 'EXTENDED')) . |
|
| 240 | + $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) . |
|
| 241 | + $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset') |
|
| 242 | + ; |
|
| 243 | + if (!V_MYSQL) $this->VAR['combos'] .= $this->error; |
|
| 244 | + $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();"; |
|
| 245 | + $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">'); |
|
| 246 | + $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">'); |
|
| 247 | 247 | |
| 248 | - include('tmpl.php'); |
|
| 249 | - echo sxd_tpl_page(); |
|
| 250 | - } |
|
| 251 | - function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
|
| 252 | - $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
|
| 253 | - return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
|
| 254 | - } |
|
| 255 | - function ajax($req){ |
|
| 256 | - $res = ''; |
|
| 257 | - $act = $req['act']; |
|
| 258 | - if($req['act'] == 'run_savedjob'){ |
|
| 259 | - $req = $this->loadJob($req); |
|
| 260 | - } |
|
| 261 | - switch($req['act']){ |
|
| 262 | - case 'load_db': |
|
| 263 | - $res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']); |
|
| 264 | - break; |
|
| 265 | - case 'load_files': |
|
| 266 | - $res = $this->getFileObjects('restore', $req['value']); |
|
| 267 | - break; |
|
| 268 | - case 'filelist': |
|
| 269 | - $res = "sxd.clearOpt('files');sxd.addOpt(" . sxd_php2json(array('files' => $this->getFileList())) . ");"; |
|
| 270 | - break; |
|
| 271 | - case 'dblist': |
|
| 272 | - $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,'-');"; |
|
| 273 | - break; |
|
| 274 | - case 'load_connect': |
|
| 275 | - $CFG = $this->cfg2js($this->CFG); |
|
| 276 | - $res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}', |
|
| 248 | + include('tmpl.php'); |
|
| 249 | + echo sxd_tpl_page(); |
|
| 250 | + } |
|
| 251 | + function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
|
| 252 | + $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
|
| 253 | + return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
|
| 254 | + } |
|
| 255 | + function ajax($req){ |
|
| 256 | + $res = ''; |
|
| 257 | + $act = $req['act']; |
|
| 258 | + if($req['act'] == 'run_savedjob'){ |
|
| 259 | + $req = $this->loadJob($req); |
|
| 260 | + } |
|
| 261 | + switch($req['act']){ |
|
| 262 | + case 'load_db': |
|
| 263 | + $res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']); |
|
| 264 | + break; |
|
| 265 | + case 'load_files': |
|
| 266 | + $res = $this->getFileObjects('restore', $req['value']); |
|
| 267 | + break; |
|
| 268 | + case 'filelist': |
|
| 269 | + $res = "sxd.clearOpt('files');sxd.addOpt(" . sxd_php2json(array('files' => $this->getFileList())) . ");"; |
|
| 270 | + break; |
|
| 271 | + case 'dblist': |
|
| 272 | + $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,'-');"; |
|
| 273 | + break; |
|
| 274 | + case 'load_connect': |
|
| 275 | + $CFG = $this->cfg2js($this->CFG); |
|
| 276 | + $res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}', |
|
| 277 | 277 | z('con_pass').value = '', z('con_comp').checked = {$CFG['my_comp']}, z('con_db').value = '{$CFG['my_db']}', z('con_pass').changed = false;" ; |
| 278 | - break; |
|
| 279 | - case 'save_connect': |
|
| 280 | - $res = $this->saveConnect($req); |
|
| 281 | - break; |
|
| 282 | - case 'save_job': |
|
| 283 | - unset($req['act']); |
|
| 284 | - $this->saveJob('sj_' . $req['job'] , $req); |
|
| 285 | - $res = $this->getSavedJobs(); |
|
| 286 | - break; |
|
| 287 | - case 'add_db': |
|
| 288 | - $res = $this->addDb($req); |
|
| 289 | - break; |
|
| 290 | - case 'load_options': |
|
| 291 | - $CFG = $this->cfg2js($this->CFG); |
|
| 292 | - $res = "z('time_web').value = '{$CFG['time_web']}', z('time_cron').value = '{$CFG['time_cron']}', z('backup_path').value = '{$CFG['backup_path']}', |
|
| 278 | + break; |
|
| 279 | + case 'save_connect': |
|
| 280 | + $res = $this->saveConnect($req); |
|
| 281 | + break; |
|
| 282 | + case 'save_job': |
|
| 283 | + unset($req['act']); |
|
| 284 | + $this->saveJob('sj_' . $req['job'] , $req); |
|
| 285 | + $res = $this->getSavedJobs(); |
|
| 286 | + break; |
|
| 287 | + case 'add_db': |
|
| 288 | + $res = $this->addDb($req); |
|
| 289 | + break; |
|
| 290 | + case 'load_options': |
|
| 291 | + $CFG = $this->cfg2js($this->CFG); |
|
| 292 | + $res = "z('time_web').value = '{$CFG['time_web']}', z('time_cron').value = '{$CFG['time_cron']}', z('backup_path').value = '{$CFG['backup_path']}', |
|
| 293 | 293 | 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']};"; |
| 294 | - break; |
|
| 295 | - case 'save_options': |
|
| 296 | - $res = $this->saveOptions($req); |
|
| 297 | - break; |
|
| 298 | - case 'delete_file': |
|
| 299 | - if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
|
| 300 | - $file = $this->CFG['backup_path'] . $req['name']; |
|
| 301 | - if(file_exists($file)) unlink($file); |
|
| 302 | - } |
|
| 303 | - $res = $this->getFileListExtended(); |
|
| 304 | - break; |
|
| 305 | - case 'delete_db': |
|
| 306 | - $res = $this->deleteDB($req['name']); |
|
| 307 | - break; |
|
| 308 | - case 'load_files_ext': |
|
| 309 | - $res .= $this->getFileListExtended(); |
|
| 310 | - break; |
|
| 311 | - case 'services': |
|
| 312 | - $this->runServices($req); |
|
| 313 | - break; |
|
| 314 | - case 'backup': |
|
| 315 | - $this->addBackupJob($req); |
|
| 316 | - break; |
|
| 317 | - case 'restore': |
|
| 318 | - $this->addRestoreJob($req); |
|
| 319 | - break; |
|
| 320 | - case 'resume': |
|
| 321 | - $this->resumeJob($req); |
|
| 322 | - break; |
|
| 323 | - case 'exit': |
|
| 324 | - setcookie('sxd', '', 0); |
|
| 325 | - $res = "top.location.href = " . sxd_esc($this->CFG['exitURL']) . ";"; |
|
| 326 | - break; |
|
| 327 | - } |
|
| 328 | - echo $res; |
|
| 329 | - } |
|
| 330 | - function loadJob($job){ |
|
| 331 | - $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
|
| 332 | - if(!file_exists($file)) return; |
|
| 333 | - include($file); |
|
| 334 | - $JOB['act'] = $JOB['type']; |
|
| 335 | - $JOB['type'] = 'run'; |
|
| 336 | - return $JOB; |
|
| 337 | - } |
|
| 338 | - function deleteDB($name){ |
|
| 339 | - $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
|
| 340 | - if($r){ |
|
| 341 | - echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
|
| 342 | - } |
|
| 294 | + break; |
|
| 295 | + case 'save_options': |
|
| 296 | + $res = $this->saveOptions($req); |
|
| 297 | + break; |
|
| 298 | + case 'delete_file': |
|
| 299 | + if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
|
| 300 | + $file = $this->CFG['backup_path'] . $req['name']; |
|
| 301 | + if(file_exists($file)) unlink($file); |
|
| 302 | + } |
|
| 303 | + $res = $this->getFileListExtended(); |
|
| 304 | + break; |
|
| 305 | + case 'delete_db': |
|
| 306 | + $res = $this->deleteDB($req['name']); |
|
| 307 | + break; |
|
| 308 | + case 'load_files_ext': |
|
| 309 | + $res .= $this->getFileListExtended(); |
|
| 310 | + break; |
|
| 311 | + case 'services': |
|
| 312 | + $this->runServices($req); |
|
| 313 | + break; |
|
| 314 | + case 'backup': |
|
| 315 | + $this->addBackupJob($req); |
|
| 316 | + break; |
|
| 317 | + case 'restore': |
|
| 318 | + $this->addRestoreJob($req); |
|
| 319 | + break; |
|
| 320 | + case 'resume': |
|
| 321 | + $this->resumeJob($req); |
|
| 322 | + break; |
|
| 323 | + case 'exit': |
|
| 324 | + setcookie('sxd', '', 0); |
|
| 325 | + $res = "top.location.href = " . sxd_esc($this->CFG['exitURL']) . ";"; |
|
| 326 | + break; |
|
| 327 | + } |
|
| 328 | + echo $res; |
|
| 329 | + } |
|
| 330 | + function loadJob($job){ |
|
| 331 | + $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
|
| 332 | + if(!file_exists($file)) return; |
|
| 333 | + include($file); |
|
| 334 | + $JOB['act'] = $JOB['type']; |
|
| 335 | + $JOB['type'] = 'run'; |
|
| 336 | + return $JOB; |
|
| 337 | + } |
|
| 338 | + function deleteDB($name){ |
|
| 339 | + $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
|
| 340 | + if($r){ |
|
| 341 | + echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
|
| 342 | + } |
|
| 343 | 343 | else |
| 344 | - echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 345 | - } |
|
| 346 | - function cfg2js($cfg){ |
|
| 347 | - foreach($cfg AS $k => $v){ |
|
| 348 | - $cfg[$k] = sxd_esc($v, false); |
|
| 349 | - } |
|
| 350 | - return $cfg; |
|
| 351 | - } |
|
| 352 | - function addDb($req){ |
|
| 344 | + echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 345 | + } |
|
| 346 | + function cfg2js($cfg){ |
|
| 347 | + foreach($cfg AS $k => $v){ |
|
| 348 | + $cfg[$k] = sxd_esc($v, false); |
|
| 349 | + } |
|
| 350 | + return $cfg; |
|
| 351 | + } |
|
| 352 | + function addDb($req){ |
|
| 353 | 353 | $r = mysql_query('CREATE DATABASE `' . sxd_esc($req['name'], false) . '`' . (V_MYSQL > 40100 ? "CHARACTER SET {$req['charset']} COLLATE {$req['collate']}" : '')); |
| 354 | 354 | if($r) |
| 355 | - echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 355 | + echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 356 | 356 | else |
| 357 | - sxd_my_error(); |
|
| 358 | - } |
|
| 359 | - function saveConnect($req){ |
|
| 360 | - $this->CFG['my_host'] = $req['host']; |
|
| 361 | - $this->CFG['my_port'] = (int)$req['port']; |
|
| 362 | - $this->CFG['my_user'] = $req['user']; |
|
| 363 | - if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 364 | - $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
|
| 365 | - $this->CFG['my_db'] = $req['db']; |
|
| 366 | - $this->saveCFG(); |
|
| 357 | + sxd_my_error(); |
|
| 358 | + } |
|
| 359 | + function saveConnect($req){ |
|
| 360 | + $this->CFG['my_host'] = $req['host']; |
|
| 361 | + $this->CFG['my_port'] = (int)$req['port']; |
|
| 362 | + $this->CFG['my_user'] = $req['user']; |
|
| 363 | + if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 364 | + $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
|
| 365 | + $this->CFG['my_db'] = $req['db']; |
|
| 366 | + $this->saveCFG(); |
|
| 367 | 367 | $this->connect(); |
| 368 | 368 | if (V_MYSQL) { |
| 369 | - $tmp = array( |
|
| 370 | - 'db' => $this->getDBList(), |
|
| 371 | - 'charset' => $this->getCharsetList(), |
|
| 372 | - 'collation' => $this->getCollationList() |
|
| 373 | - ); |
|
| 374 | - 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,'-');"; |
|
| 375 | - } |
|
| 376 | - else { |
|
| 377 | - echo $this->error; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - function saveOptions($req){ |
|
| 381 | - $this->CFG['time_web'] = $req['time_web']; |
|
| 382 | - $this->CFG['time_cron'] = $req['time_cron']; |
|
| 383 | - $this->CFG['backup_path'] = $req['backup_path']; |
|
| 384 | - $this->CFG['backup_url'] = $req['backup_url']; |
|
| 385 | - $this->CFG['globstat'] = $req['globstat'] ? 1 : 0; |
|
| 386 | - $this->CFG['charsets'] = $req['charsets']; |
|
| 387 | - $this->CFG['only_create'] = $req['only_create']; |
|
| 388 | - $this->CFG['auth'] = $req['auth']; |
|
| 389 | - $this->CFG['confirm'] = $req['confirm']; |
|
| 390 | - $this->saveCFG(); |
|
| 391 | - } |
|
| 392 | - function saveCFG(){ |
|
| 393 | - if (isset($_COOKIE['sxd'])) { |
|
| 394 | - $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']); |
|
| 395 | - $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>"); |
|
| 396 | - } |
|
| 369 | + $tmp = array( |
|
| 370 | + 'db' => $this->getDBList(), |
|
| 371 | + 'charset' => $this->getCharsetList(), |
|
| 372 | + 'collation' => $this->getCollationList() |
|
| 373 | + ); |
|
| 374 | + 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,'-');"; |
|
| 375 | + } |
|
| 376 | + else { |
|
| 377 | + echo $this->error; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + function saveOptions($req){ |
|
| 381 | + $this->CFG['time_web'] = $req['time_web']; |
|
| 382 | + $this->CFG['time_cron'] = $req['time_cron']; |
|
| 383 | + $this->CFG['backup_path'] = $req['backup_path']; |
|
| 384 | + $this->CFG['backup_url'] = $req['backup_url']; |
|
| 385 | + $this->CFG['globstat'] = $req['globstat'] ? 1 : 0; |
|
| 386 | + $this->CFG['charsets'] = $req['charsets']; |
|
| 387 | + $this->CFG['only_create'] = $req['only_create']; |
|
| 388 | + $this->CFG['auth'] = $req['auth']; |
|
| 389 | + $this->CFG['confirm'] = $req['confirm']; |
|
| 390 | + $this->saveCFG(); |
|
| 391 | + } |
|
| 392 | + function saveCFG(){ |
|
| 393 | + if (isset($_COOKIE['sxd'])) { |
|
| 394 | + $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']); |
|
| 395 | + $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>"); |
|
| 396 | + } |
|
| 397 | 397 | if (!$this->virtualize){ |
| 398 | - $this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>"); |
|
| 398 | + $this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>"); |
|
| 399 | 399 | } |
| 400 | - } |
|
| 401 | - function runServices($job) { |
|
| 402 | - $serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR'); |
|
| 403 | - $add = array('check' => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED')); |
|
| 404 | - if(isset($serv[$job['type']])) { |
|
| 405 | - mysql_select_db($job['db']); |
|
| 406 | - $filter = $object = array(); |
|
| 407 | - $this->createFilters($job['obj'], $filter, $object); |
|
| 408 | - $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
|
| 409 | - if (!$r) return; |
|
| 410 | - $tables = array(); |
|
| 411 | - while($item = mysql_fetch_assoc($r)){ |
|
| 412 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue; |
|
| 413 | - if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`"; |
|
| 414 | - } |
|
| 415 | - $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
|
| 400 | + } |
|
| 401 | + function runServices($job) { |
|
| 402 | + $serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR'); |
|
| 403 | + $add = array('check' => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED')); |
|
| 404 | + if(isset($serv[$job['type']])) { |
|
| 405 | + mysql_select_db($job['db']); |
|
| 406 | + $filter = $object = array(); |
|
| 407 | + $this->createFilters($job['obj'], $filter, $object); |
|
| 408 | + $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
|
| 409 | + if (!$r) return; |
|
| 410 | + $tables = array(); |
|
| 411 | + while($item = mysql_fetch_assoc($r)){ |
|
| 412 | + if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue; |
|
| 413 | + if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`"; |
|
| 414 | + } |
|
| 415 | + $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
|
| 416 | 416 | |
| 417 | - if ($job['type'] == 'check' || $job['type'] == 'repair') { |
|
| 418 | - $sql .= isset($add[$job['type']][$job[$job['type']]]) ? ' ' . $add[$job['type']][$job[$job['type']]] : ''; |
|
| 419 | - } |
|
| 417 | + if ($job['type'] == 'check' || $job['type'] == 'repair') { |
|
| 418 | + $sql .= isset($add[$job['type']][$job[$job['type']]]) ? ' ' . $add[$job['type']][$job[$job['type']]] : ''; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - $r = mysql_query($sql) or sxd_my_error(); |
|
| 422 | - if (!$r) return; |
|
| 423 | - $res = array(); |
|
| 424 | - while($item = mysql_fetch_row($r)){ |
|
| 425 | - $res[] = $item; |
|
| 426 | - } |
|
| 427 | - echo 'sxd.result.add(' . sxd_php2json($res). ');'; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - function createFilters(&$obj, &$filter, &$object){ |
|
| 431 | - $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV'); |
|
| 432 | - foreach($types AS $type){ |
|
| 433 | - $filter[$type] = array(); |
|
| 434 | - $object[$type] = array(); |
|
| 435 | - if(!empty($obj[$type])){ |
|
| 436 | - foreach($obj[$type] AS $v){ |
|
| 437 | - if(strpos($v, '*') !== false) { |
|
| 438 | - $filter[$type][] = str_replace('*', '.*?', $v); |
|
| 439 | - } |
|
| 440 | - else { |
|
| 441 | - $object[$type][$v] = true; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - $filter[$type] = count($filter[$type]) > 0 ? '/^(' . implode('|', $filter[$type]) . ')$/i' : ''; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - function closeConnect(){ |
|
| 449 | - //return; |
|
| 450 | - @ignore_user_abort(1); |
|
| 451 | - header("SXD: {$this->name}"); |
|
| 452 | - $size = ob_get_length(); |
|
| 421 | + $r = mysql_query($sql) or sxd_my_error(); |
|
| 422 | + if (!$r) return; |
|
| 423 | + $res = array(); |
|
| 424 | + while($item = mysql_fetch_row($r)){ |
|
| 425 | + $res[] = $item; |
|
| 426 | + } |
|
| 427 | + echo 'sxd.result.add(' . sxd_php2json($res). ');'; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + function createFilters(&$obj, &$filter, &$object){ |
|
| 431 | + $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV'); |
|
| 432 | + foreach($types AS $type){ |
|
| 433 | + $filter[$type] = array(); |
|
| 434 | + $object[$type] = array(); |
|
| 435 | + if(!empty($obj[$type])){ |
|
| 436 | + foreach($obj[$type] AS $v){ |
|
| 437 | + if(strpos($v, '*') !== false) { |
|
| 438 | + $filter[$type][] = str_replace('*', '.*?', $v); |
|
| 439 | + } |
|
| 440 | + else { |
|
| 441 | + $object[$type][$v] = true; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + $filter[$type] = count($filter[$type]) > 0 ? '/^(' . implode('|', $filter[$type]) . ')$/i' : ''; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + function closeConnect(){ |
|
| 449 | + //return; |
|
| 450 | + @ignore_user_abort(1); |
|
| 451 | + header("SXD: {$this->name}"); |
|
| 452 | + $size = ob_get_length(); |
|
| 453 | 453 | // @fastcgi_finish_request(); |
| 454 | - header("Content-Length: {$size}"); |
|
| 455 | - header("Connection: close"); |
|
| 456 | - @ob_end_flush(); |
|
| 457 | - @flush(); |
|
| 458 | - } |
|
| 459 | - function resumeJob($job){ |
|
| 460 | - $this->closeConnect(); |
|
| 461 | - include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
|
| 462 | - $this->JOB = &$JOB; |
|
| 463 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 464 | - $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
|
| 465 | - $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
|
| 466 | - $t = fgets($this->fh_rtl); |
|
| 467 | - if(!empty($t)){ |
|
| 468 | - $this->rtl = explode("\t", $t); |
|
| 469 | - } |
|
| 470 | - else { |
|
| 471 | - $this->addLog($this->LNG['not_found_rtl']); |
|
| 472 | - exit; |
|
| 473 | - } |
|
| 474 | - // TODO: проверить удаление кодировки |
|
| 475 | - //$this->rtl[6] = ''; |
|
| 476 | - fseek($this->fh_rtl, 0); |
|
| 477 | - $this->rtl[1] = time(); |
|
| 478 | - $this->rtl[9] = 0; |
|
| 479 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 480 | - if ($this->JOB['act'] == 'backup') $this->runBackupJob(true); |
|
| 481 | - elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true); |
|
| 482 | - } |
|
| 483 | - function addRestoreJob($job) { |
|
| 484 | - $this->closeConnect(); |
|
| 485 | - $this->JOB = $job; |
|
| 486 | - // Создаем список объектов и фильтр |
|
| 487 | - $filter = $object = array(); |
|
| 488 | - $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 454 | + header("Content-Length: {$size}"); |
|
| 455 | + header("Connection: close"); |
|
| 456 | + @ob_end_flush(); |
|
| 457 | + @flush(); |
|
| 458 | + } |
|
| 459 | + function resumeJob($job){ |
|
| 460 | + $this->closeConnect(); |
|
| 461 | + include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
|
| 462 | + $this->JOB = &$JOB; |
|
| 463 | + if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 464 | + $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
|
| 465 | + $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
|
| 466 | + $t = fgets($this->fh_rtl); |
|
| 467 | + if(!empty($t)){ |
|
| 468 | + $this->rtl = explode("\t", $t); |
|
| 469 | + } |
|
| 470 | + else { |
|
| 471 | + $this->addLog($this->LNG['not_found_rtl']); |
|
| 472 | + exit; |
|
| 473 | + } |
|
| 474 | + // TODO: проверить удаление кодировки |
|
| 475 | + //$this->rtl[6] = ''; |
|
| 476 | + fseek($this->fh_rtl, 0); |
|
| 477 | + $this->rtl[1] = time(); |
|
| 478 | + $this->rtl[9] = 0; |
|
| 479 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 480 | + if ($this->JOB['act'] == 'backup') $this->runBackupJob(true); |
|
| 481 | + elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true); |
|
| 482 | + } |
|
| 483 | + function addRestoreJob($job) { |
|
| 484 | + $this->closeConnect(); |
|
| 485 | + $this->JOB = $job; |
|
| 486 | + // Создаем список объектов и фильтр |
|
| 487 | + $filter = $object = array(); |
|
| 488 | + $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 489 | 489 | |
| 490 | - $objects = $this->getFileObjects('restore', $this->JOB['file'], false); |
|
| 491 | - $todo = array(); |
|
| 492 | - $rows = 0; |
|
| 493 | - $this->tab_rows = array(); |
|
| 494 | - $todo = array(); |
|
| 495 | - foreach($objects AS $t => $list){ |
|
| 496 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 497 | - elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
|
| 498 | - if (empty($list)) continue; |
|
| 490 | + $objects = $this->getFileObjects('restore', $this->JOB['file'], false); |
|
| 491 | + $todo = array(); |
|
| 492 | + $rows = 0; |
|
| 493 | + $this->tab_rows = array(); |
|
| 494 | + $todo = array(); |
|
| 495 | + foreach($objects AS $t => $list){ |
|
| 496 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 497 | + elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
|
| 498 | + if (empty($list)) continue; |
|
| 499 | 499 | |
| 500 | - foreach($list AS $item){ |
|
| 501 | - switch($t){ |
|
| 502 | - case 'TA': |
|
| 503 | - $type = ''; |
|
| 504 | - if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
|
| 505 | - $type = empty($item[1]) ? 'TC' : 'TA'; |
|
| 506 | - } |
|
| 507 | - elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | - $type = 'TC'; |
|
| 509 | - } |
|
| 510 | - else continue; |
|
| 511 | - $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
|
| 512 | - $rows += $type == 'TA' ? $item[1] : 0; |
|
| 513 | - break; |
|
| 514 | - default: |
|
| 515 | - if(sxd_check($item, $object[$t], $filter[$t])) { |
|
| 516 | - $todo[$t][] = array($t, $item); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - $this->JOB['file_tmp'] = $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 522 | - $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 523 | - $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 524 | - $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
|
| 525 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 500 | + foreach($list AS $item){ |
|
| 501 | + switch($t){ |
|
| 502 | + case 'TA': |
|
| 503 | + $type = ''; |
|
| 504 | + if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
|
| 505 | + $type = empty($item[1]) ? 'TC' : 'TA'; |
|
| 506 | + } |
|
| 507 | + elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | + $type = 'TC'; |
|
| 509 | + } |
|
| 510 | + else continue; |
|
| 511 | + $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
|
| 512 | + $rows += $type == 'TA' ? $item[1] : 0; |
|
| 513 | + break; |
|
| 514 | + default: |
|
| 515 | + if(sxd_check($item, $object[$t], $filter[$t])) { |
|
| 516 | + $todo[$t][] = array($t, $item); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + $this->JOB['file_tmp'] = $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 522 | + $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 523 | + $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 524 | + $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
|
| 525 | + if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 526 | 526 | |
| 527 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 528 | - // Для чужих дампов определяем разделители строк |
|
| 529 | - if(is_null($this->JOB['obj'])) { |
|
| 530 | - $s = fread($this->fh_tmp, 2048); |
|
| 531 | - if(strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n"; |
|
| 532 | - elseif(strpos($s, "\n")) $this->JOB['eol'] = "\n"; |
|
| 533 | - else $this->JOB['eol'] = "\r"; |
|
| 534 | - $bom = strncmp($s, "\xEF\xBB\xBF", 3) == 0 ? 3 : ((strncmp($s, "\xFE\xFF", 2) == 0 || strncmp($s, "\xFF\xFE", 2) == 0) ? 2 : 0); |
|
| 535 | - fseek($this->fh_tmp, $bom); |
|
| 536 | - } |
|
| 537 | - $this->JOB['todo'] = $todo; |
|
| 538 | - $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 539 | - $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 540 | - $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 541 | - $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 542 | - $this->addLog(sprintf($this->LNG['restore_begin'], $this->JOB['db'])); |
|
| 543 | - $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}"); |
|
| 544 | - $this->runRestoreJob(); |
|
| 545 | - } |
|
| 546 | - function runRestoreJob($continue = false){ |
|
| 547 | - $ei = false; |
|
| 548 | - if($continue){ |
|
| 549 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 550 | - fseek($this->fh_tmp, $this->rtl[3]); |
|
| 551 | - if(!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 552 | - if($this->rtl[7] < $this->rtl[10]) $ei = true; |
|
| 553 | - } |
|
| 554 | - mysql_select_db($this->JOB['db']); |
|
| 555 | - if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 556 | - //mysql_query("SET NAMES 'UTF8'"); |
|
| 557 | - $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 558 | - $fcache = ''; |
|
| 559 | - $writes = 0; |
|
| 560 | - $old_charset = ''; |
|
| 561 | - $tab = ''; |
|
| 562 | - $seek = 0; |
|
| 563 | - $this->rtl[3] = ftell($this->fh_tmp); |
|
| 564 | - fseek($this->fh_rtl, 0); |
|
| 565 | - $this->rtl[1] = time(); |
|
| 566 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 567 | - $c = 0; |
|
| 568 | - switch($this->JOB['strategy']){ |
|
| 569 | - case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break; |
|
| 570 | - case 2: $tc = ''; $td = 'REPLACE'; break; |
|
| 571 | - case 3: $tc = ''; $td = 'INSERT IGNORE'; break; |
|
| 572 | - default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT'; |
|
| 573 | - } |
|
| 574 | - $tab_exists = array(); |
|
| 575 | - if($this->JOB['strategy'] > 0){ |
|
| 576 | - $r = mysql_query("SHOW TABLES") or sxd_my_error(); |
|
| 577 | - while($item = mysql_fetch_row($r)){ |
|
| 578 | - $tab_exists[$item[0]] = true; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - $insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : ''; |
|
| 582 | - //$enable_index = array(); |
|
| 583 | - if(V_MYSQL > 40014) { |
|
| 584 | - mysql_query("SET UNIQUE_CHECKS=0"); |
|
| 585 | - mysql_query("SET FOREIGN_KEY_CHECKS=0"); |
|
| 586 | - if(V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 587 | - if(V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0"); |
|
| 588 | - } |
|
| 589 | - $log_sql = false; |
|
| 590 | - $fields = ''; |
|
| 591 | - $time_old = time(); |
|
| 592 | - $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 593 | - while($q = sxd_read_sql($this->fh_tmp, $seek, $ei)){ |
|
| 594 | - if($time_old < time()) { |
|
| 595 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 596 | - $type = file_get_contents($this->JOB['file_stp']); |
|
| 597 | - $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 598 | - fseek($this->fh_rtl, 0); |
|
| 599 | - $this->rtl[1] = time(); |
|
| 600 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 601 | - /*if($type == 1) { |
|
| 527 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 528 | + // Для чужих дампов определяем разделители строк |
|
| 529 | + if(is_null($this->JOB['obj'])) { |
|
| 530 | + $s = fread($this->fh_tmp, 2048); |
|
| 531 | + if(strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n"; |
|
| 532 | + elseif(strpos($s, "\n")) $this->JOB['eol'] = "\n"; |
|
| 533 | + else $this->JOB['eol'] = "\r"; |
|
| 534 | + $bom = strncmp($s, "\xEF\xBB\xBF", 3) == 0 ? 3 : ((strncmp($s, "\xFE\xFF", 2) == 0 || strncmp($s, "\xFF\xFE", 2) == 0) ? 2 : 0); |
|
| 535 | + fseek($this->fh_tmp, $bom); |
|
| 536 | + } |
|
| 537 | + $this->JOB['todo'] = $todo; |
|
| 538 | + $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 539 | + $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 540 | + $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 541 | + $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 542 | + $this->addLog(sprintf($this->LNG['restore_begin'], $this->JOB['db'])); |
|
| 543 | + $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}"); |
|
| 544 | + $this->runRestoreJob(); |
|
| 545 | + } |
|
| 546 | + function runRestoreJob($continue = false){ |
|
| 547 | + $ei = false; |
|
| 548 | + if($continue){ |
|
| 549 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 550 | + fseek($this->fh_tmp, $this->rtl[3]); |
|
| 551 | + if(!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 552 | + if($this->rtl[7] < $this->rtl[10]) $ei = true; |
|
| 553 | + } |
|
| 554 | + mysql_select_db($this->JOB['db']); |
|
| 555 | + if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 556 | + //mysql_query("SET NAMES 'UTF8'"); |
|
| 557 | + $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 558 | + $fcache = ''; |
|
| 559 | + $writes = 0; |
|
| 560 | + $old_charset = ''; |
|
| 561 | + $tab = ''; |
|
| 562 | + $seek = 0; |
|
| 563 | + $this->rtl[3] = ftell($this->fh_tmp); |
|
| 564 | + fseek($this->fh_rtl, 0); |
|
| 565 | + $this->rtl[1] = time(); |
|
| 566 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 567 | + $c = 0; |
|
| 568 | + switch($this->JOB['strategy']){ |
|
| 569 | + case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break; |
|
| 570 | + case 2: $tc = ''; $td = 'REPLACE'; break; |
|
| 571 | + case 3: $tc = ''; $td = 'INSERT IGNORE'; break; |
|
| 572 | + default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT'; |
|
| 573 | + } |
|
| 574 | + $tab_exists = array(); |
|
| 575 | + if($this->JOB['strategy'] > 0){ |
|
| 576 | + $r = mysql_query("SHOW TABLES") or sxd_my_error(); |
|
| 577 | + while($item = mysql_fetch_row($r)){ |
|
| 578 | + $tab_exists[$item[0]] = true; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + $insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : ''; |
|
| 582 | + //$enable_index = array(); |
|
| 583 | + if(V_MYSQL > 40014) { |
|
| 584 | + mysql_query("SET UNIQUE_CHECKS=0"); |
|
| 585 | + mysql_query("SET FOREIGN_KEY_CHECKS=0"); |
|
| 586 | + if(V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 587 | + if(V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0"); |
|
| 588 | + } |
|
| 589 | + $log_sql = false; |
|
| 590 | + $fields = ''; |
|
| 591 | + $time_old = time(); |
|
| 592 | + $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 593 | + while($q = sxd_read_sql($this->fh_tmp, $seek, $ei)){ |
|
| 594 | + if($time_old < time()) { |
|
| 595 | + if(file_exists($this->JOB['file_stp'])){ |
|
| 596 | + $type = file_get_contents($this->JOB['file_stp']); |
|
| 597 | + $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 598 | + fseek($this->fh_rtl, 0); |
|
| 599 | + $this->rtl[1] = time(); |
|
| 600 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 601 | + /*if($type == 1) { |
|
| 602 | 602 | |
| 603 | 603 | }*/ |
| 604 | - unset($this->rtl); |
|
| 605 | - exit; |
|
| 606 | - } |
|
| 607 | - $time_old = time(); |
|
| 608 | - if($time_old >= $exit_time){ |
|
| 609 | - $this->rtl[9] = 3; |
|
| 610 | - fseek($this->fh_rtl, 0); |
|
| 611 | - $this->rtl[1] = time(); |
|
| 612 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 613 | - unset($this->rtl); |
|
| 614 | - exit; |
|
| 615 | - } |
|
| 616 | - clearstatcache(); |
|
| 617 | - } |
|
| 618 | - switch($q{0}){ |
|
| 619 | - case '(': |
|
| 620 | - if($continue) { |
|
| 621 | - $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 622 | - $continue = false; |
|
| 623 | - } |
|
| 624 | - $q = $insert . $q; |
|
| 625 | - $ex = 1; |
|
| 626 | - $c = 1; |
|
| 627 | - break; |
|
| 628 | - case 'I': |
|
| 629 | - if (preg_match('/^INSERT( INTO `(.+?)`) VALUES/', $q, $m)) { |
|
| 630 | - $insert = $td . $m[1] . $fields . " VALUES \n"; |
|
| 631 | - $tab = $m[2]; |
|
| 632 | - $this->rtl[7] = 0; |
|
| 633 | - $this->rtl[8] = 0; |
|
| 634 | - foreach($this->JOB['todo']['TA'] AS $t){ |
|
| 635 | - if($t[1] == $tab) { |
|
| 636 | - $this->rtl[8] = $t[2]; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - if($this->JOB['strategy']) { |
|
| 640 | - $q = substr_replace($q, $insert, 0, strlen($m[0])); |
|
| 641 | - } |
|
| 642 | - //mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error()); |
|
| 643 | - mysql_query("ALTER TABLE `{$tab}` DISABLE KEYS") or sxd_my_error(); |
|
| 644 | - //if(!empty($this->JOB['autoinc'])) mysql_query("ALTER TABLE `{$tab}` AUTO_INCREMENT = 1") or sxd_my_error(); |
|
| 645 | - $ex = 1; |
|
| 646 | - } |
|
| 647 | - break; |
|
| 648 | - case 'C': |
|
| 649 | - $ex = 1; |
|
| 650 | - if (preg_match('/^CREATE TABLE `/', $q)) { |
|
| 651 | - if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | - else { |
|
| 653 | - $ex = 1; |
|
| 654 | - if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 655 | - $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 656 | - } |
|
| 657 | - if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 658 | - } |
|
| 659 | - // Достаем имена полей таблицы |
|
| 660 | - $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
|
| 661 | - } |
|
| 662 | - break; |
|
| 663 | - case '#': // Команды для дампера |
|
| 664 | - if (preg_match("/\#\t(TC|TD|VI|PR|FU|TR|EV)`(.+?)`(([^_]+?)_.+?)?$/", $q, $m)) { |
|
| 665 | - //if(!empty($tab)) $enable_index[] = $tab; |
|
| 604 | + unset($this->rtl); |
|
| 605 | + exit; |
|
| 606 | + } |
|
| 607 | + $time_old = time(); |
|
| 608 | + if($time_old >= $exit_time){ |
|
| 609 | + $this->rtl[9] = 3; |
|
| 610 | + fseek($this->fh_rtl, 0); |
|
| 611 | + $this->rtl[1] = time(); |
|
| 612 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 613 | + unset($this->rtl); |
|
| 614 | + exit; |
|
| 615 | + } |
|
| 616 | + clearstatcache(); |
|
| 617 | + } |
|
| 618 | + switch($q{0}){ |
|
| 619 | + case '(': |
|
| 620 | + if($continue) { |
|
| 621 | + $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 622 | + $continue = false; |
|
| 623 | + } |
|
| 624 | + $q = $insert . $q; |
|
| 625 | + $ex = 1; |
|
| 626 | + $c = 1; |
|
| 627 | + break; |
|
| 628 | + case 'I': |
|
| 629 | + if (preg_match('/^INSERT( INTO `(.+?)`) VALUES/', $q, $m)) { |
|
| 630 | + $insert = $td . $m[1] . $fields . " VALUES \n"; |
|
| 631 | + $tab = $m[2]; |
|
| 632 | + $this->rtl[7] = 0; |
|
| 633 | + $this->rtl[8] = 0; |
|
| 634 | + foreach($this->JOB['todo']['TA'] AS $t){ |
|
| 635 | + if($t[1] == $tab) { |
|
| 636 | + $this->rtl[8] = $t[2]; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + if($this->JOB['strategy']) { |
|
| 640 | + $q = substr_replace($q, $insert, 0, strlen($m[0])); |
|
| 641 | + } |
|
| 642 | + //mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error()); |
|
| 643 | + mysql_query("ALTER TABLE `{$tab}` DISABLE KEYS") or sxd_my_error(); |
|
| 644 | + //if(!empty($this->JOB['autoinc'])) mysql_query("ALTER TABLE `{$tab}` AUTO_INCREMENT = 1") or sxd_my_error(); |
|
| 645 | + $ex = 1; |
|
| 646 | + } |
|
| 647 | + break; |
|
| 648 | + case 'C': |
|
| 649 | + $ex = 1; |
|
| 650 | + if (preg_match('/^CREATE TABLE `/', $q)) { |
|
| 651 | + if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | + else { |
|
| 653 | + $ex = 1; |
|
| 654 | + if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 655 | + $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 656 | + } |
|
| 657 | + if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 658 | + } |
|
| 659 | + // Достаем имена полей таблицы |
|
| 660 | + $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
|
| 661 | + } |
|
| 662 | + break; |
|
| 663 | + case '#': // Команды для дампера |
|
| 664 | + if (preg_match("/\#\t(TC|TD|VI|PR|FU|TR|EV)`(.+?)`(([^_]+?)_.+?)?$/", $q, $m)) { |
|
| 665 | + //if(!empty($tab)) $enable_index[] = $tab; |
|
| 666 | 666 | // $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : empty($m[3]) ? '' : $m[3]); |
| 667 | - $this->setNames('binary'); |
|
| 668 | - if($m[1] == 'TC') { |
|
| 669 | - $this->addLog(sprintf($this->LNG['restore_TC'], $m[2])); |
|
| 670 | - $insert = ''; |
|
| 671 | - $tab = ''; |
|
| 672 | - $this->rtl[4] = 'TD'; |
|
| 673 | - $this->rtl[5] = $m[2]; |
|
| 674 | - $ei = 0; |
|
| 675 | - if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
|
| 676 | - mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - elseif($m[1] == 'TD'){ |
|
| 680 | - $ei = 1; |
|
| 681 | - } |
|
| 682 | - else { |
|
| 683 | - $this->rtl[4] = $m[1]; |
|
| 684 | - $this->rtl[5] = $m[2]; |
|
| 685 | - $this->rtl[7] = 0; |
|
| 686 | - $this->rtl[8] = 0; |
|
| 687 | - mysql_query("DROP {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error(); |
|
| 688 | - $this->addLog(sprintf($this->LNG["restore_{$m[1]}"], $m[2])); |
|
| 689 | - $ei = 0; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - $ex = 0; |
|
| 693 | - break; |
|
| 694 | - default: |
|
| 695 | - $insert = ''; |
|
| 696 | - $ex = 1; |
|
| 697 | - } |
|
| 698 | - if($ex) { |
|
| 699 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 700 | - fseek($this->fh_rtl, 0); |
|
| 701 | - $this->rtl[1] = time(); |
|
| 702 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 703 | - if(mysql_query($q)) { |
|
| 704 | - if($insert) { |
|
| 705 | - $c = 1; |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - else { |
|
| 709 | - error_log(date('r') . "\n----------\n{$q}\n", 3, "backup/sql_error.log"); |
|
| 710 | - sxd_my_error(); |
|
| 711 | - } |
|
| 667 | + $this->setNames('binary'); |
|
| 668 | + if($m[1] == 'TC') { |
|
| 669 | + $this->addLog(sprintf($this->LNG['restore_TC'], $m[2])); |
|
| 670 | + $insert = ''; |
|
| 671 | + $tab = ''; |
|
| 672 | + $this->rtl[4] = 'TD'; |
|
| 673 | + $this->rtl[5] = $m[2]; |
|
| 674 | + $ei = 0; |
|
| 675 | + if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
|
| 676 | + mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + elseif($m[1] == 'TD'){ |
|
| 680 | + $ei = 1; |
|
| 681 | + } |
|
| 682 | + else { |
|
| 683 | + $this->rtl[4] = $m[1]; |
|
| 684 | + $this->rtl[5] = $m[2]; |
|
| 685 | + $this->rtl[7] = 0; |
|
| 686 | + $this->rtl[8] = 0; |
|
| 687 | + mysql_query("DROP {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error(); |
|
| 688 | + $this->addLog(sprintf($this->LNG["restore_{$m[1]}"], $m[2])); |
|
| 689 | + $ei = 0; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + $ex = 0; |
|
| 693 | + break; |
|
| 694 | + default: |
|
| 695 | + $insert = ''; |
|
| 696 | + $ex = 1; |
|
| 697 | + } |
|
| 698 | + if($ex) { |
|
| 699 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 700 | + fseek($this->fh_rtl, 0); |
|
| 701 | + $this->rtl[1] = time(); |
|
| 702 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 703 | + if(mysql_query($q)) { |
|
| 704 | + if($insert) { |
|
| 705 | + $c = 1; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + else { |
|
| 709 | + error_log(date('r') . "\n----------\n{$q}\n", 3, "backup/sql_error.log"); |
|
| 710 | + sxd_my_error(); |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - if($c){ |
|
| 714 | - $i = mysql_affected_rows(); |
|
| 715 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 716 | - $this->rtl[7] += $i; |
|
| 717 | - $this->rtl[10] += $i; |
|
| 718 | - fseek($this->fh_rtl, 0); |
|
| 719 | - $this->rtl[1] = time(); |
|
| 720 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 721 | - $c = 1; |
|
| 722 | - } |
|
| 723 | - } |
|
| 713 | + if($c){ |
|
| 714 | + $i = mysql_affected_rows(); |
|
| 715 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 716 | + $this->rtl[7] += $i; |
|
| 717 | + $this->rtl[10] += $i; |
|
| 718 | + fseek($this->fh_rtl, 0); |
|
| 719 | + $this->rtl[1] = time(); |
|
| 720 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 721 | + $c = 1; |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - } |
|
| 726 | - // Включаем ключи |
|
| 727 | - $this->addLog($this->LNG['restore_keys']); |
|
| 728 | - $this->rtl[4] = 'EK'; |
|
| 729 | - $this->rtl[5] = ''; |
|
| 730 | - $this->rtl[6] = ''; |
|
| 731 | - $this->rtl[7] = 0; |
|
| 732 | - $this->rtl[8] = 0; |
|
| 733 | - foreach($this->JOB['todo']['TA'] AS $tab){ |
|
| 734 | - if ($tab[0] == 'TC') continue; |
|
| 735 | - mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
|
| 736 | - $this->rtl[1] = time(); |
|
| 737 | - $this->rtl[5] = $tab[1]; |
|
| 738 | - fseek($this->fh_rtl, 0); |
|
| 739 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 740 | - } |
|
| 741 | - $this->rtl[4] = 'EOJ'; |
|
| 742 | - $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 725 | + } |
|
| 726 | + // Включаем ключи |
|
| 727 | + $this->addLog($this->LNG['restore_keys']); |
|
| 728 | + $this->rtl[4] = 'EK'; |
|
| 729 | + $this->rtl[5] = ''; |
|
| 730 | + $this->rtl[6] = ''; |
|
| 731 | + $this->rtl[7] = 0; |
|
| 732 | + $this->rtl[8] = 0; |
|
| 733 | + foreach($this->JOB['todo']['TA'] AS $tab){ |
|
| 734 | + if ($tab[0] == 'TC') continue; |
|
| 735 | + mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
|
| 736 | + $this->rtl[1] = time(); |
|
| 737 | + $this->rtl[5] = $tab[1]; |
|
| 738 | + fseek($this->fh_rtl, 0); |
|
| 739 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 740 | + } |
|
| 741 | + $this->rtl[4] = 'EOJ'; |
|
| 742 | + $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 743 | 743 | |
| 744 | - fseek($this->fh_rtl, 0); |
|
| 745 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 746 | - $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 747 | - fclose($this->fh_log); |
|
| 748 | - fclose($this->fh_rtl); |
|
| 749 | - } |
|
| 750 | - function runRestoreJobForeign($continue = false){ |
|
| 751 | - $ei = false; |
|
| 744 | + fseek($this->fh_rtl, 0); |
|
| 745 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 746 | + $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 747 | + fclose($this->fh_log); |
|
| 748 | + fclose($this->fh_rtl); |
|
| 749 | + } |
|
| 750 | + function runRestoreJobForeign($continue = false){ |
|
| 751 | + $ei = false; |
|
| 752 | 752 | |
| 753 | - $fcache = ''; |
|
| 754 | - $writes = 0; |
|
| 755 | - $old_charset = ''; |
|
| 756 | - $tab = ''; |
|
| 757 | - $seek = 0; |
|
| 758 | - $this->rtl[3] = ftell($this->fh_tmp); |
|
| 759 | - fseek($this->fh_rtl, 0); |
|
| 760 | - $this->rtl[1] = time(); |
|
| 761 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 762 | - $c = 0; |
|
| 753 | + $fcache = ''; |
|
| 754 | + $writes = 0; |
|
| 755 | + $old_charset = ''; |
|
| 756 | + $tab = ''; |
|
| 757 | + $seek = 0; |
|
| 758 | + $this->rtl[3] = ftell($this->fh_tmp); |
|
| 759 | + fseek($this->fh_rtl, 0); |
|
| 760 | + $this->rtl[1] = time(); |
|
| 761 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 762 | + $c = 0; |
|
| 763 | 763 | |
| 764 | - $log_sql = false; |
|
| 765 | - $fields = ''; |
|
| 766 | - $insert = ''; |
|
| 767 | - $last_tab = ''; |
|
| 768 | - $time_old = time(); |
|
| 769 | - $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 770 | - $delimiter = ";"; |
|
| 771 | - while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
|
| 772 | - $q = ltrim($q); |
|
| 773 | - if(empty($q)) break; |
|
| 774 | - if($time_old < time()) { |
|
| 775 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 776 | - $type = file_get_contents($this->JOB['file_stp']); |
|
| 777 | - $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 778 | - fseek($this->fh_rtl, 0); |
|
| 779 | - $this->rtl[1] = time(); |
|
| 780 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 781 | - /*if($type == 1) { |
|
| 764 | + $log_sql = false; |
|
| 765 | + $fields = ''; |
|
| 766 | + $insert = ''; |
|
| 767 | + $last_tab = ''; |
|
| 768 | + $time_old = time(); |
|
| 769 | + $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 770 | + $delimiter = ";"; |
|
| 771 | + while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
|
| 772 | + $q = ltrim($q); |
|
| 773 | + if(empty($q)) break; |
|
| 774 | + if($time_old < time()) { |
|
| 775 | + if(file_exists($this->JOB['file_stp'])){ |
|
| 776 | + $type = file_get_contents($this->JOB['file_stp']); |
|
| 777 | + $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 778 | + fseek($this->fh_rtl, 0); |
|
| 779 | + $this->rtl[1] = time(); |
|
| 780 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 781 | + /*if($type == 1) { |
|
| 782 | 782 | |
| 783 | 783 | }*/ |
| 784 | - unset($this->rtl); |
|
| 785 | - exit; |
|
| 786 | - } |
|
| 787 | - $time_old = time(); |
|
| 788 | - if($time_old >= $exit_time){ |
|
| 789 | - $this->rtl[9] = 3; |
|
| 790 | - fseek($this->fh_rtl, 0); |
|
| 791 | - $this->rtl[1] = time(); |
|
| 792 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 793 | - unset($this->rtl); |
|
| 794 | - exit; |
|
| 795 | - } |
|
| 796 | - clearstatcache(); |
|
| 797 | - } |
|
| 798 | - do { |
|
| 799 | - $repeat = false; |
|
| 800 | - //error_log("-----------------\n[{$q}]\n", 3, "q.log"); |
|
| 801 | - //if(empty($q)) {continue 2;} |
|
| 802 | - switch($q{0}){ |
|
| 803 | - case '(': |
|
| 804 | - if($continue) { |
|
| 805 | - $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 806 | - $continue = false; |
|
| 807 | - } |
|
| 808 | - $q = $insert . $q; |
|
| 809 | - $ex = 1; |
|
| 810 | - $c = 1; |
|
| 811 | - break; |
|
| 812 | - case 'I': |
|
| 784 | + unset($this->rtl); |
|
| 785 | + exit; |
|
| 786 | + } |
|
| 787 | + $time_old = time(); |
|
| 788 | + if($time_old >= $exit_time){ |
|
| 789 | + $this->rtl[9] = 3; |
|
| 790 | + fseek($this->fh_rtl, 0); |
|
| 791 | + $this->rtl[1] = time(); |
|
| 792 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 793 | + unset($this->rtl); |
|
| 794 | + exit; |
|
| 795 | + } |
|
| 796 | + clearstatcache(); |
|
| 797 | + } |
|
| 798 | + do { |
|
| 799 | + $repeat = false; |
|
| 800 | + //error_log("-----------------\n[{$q}]\n", 3, "q.log"); |
|
| 801 | + //if(empty($q)) {continue 2;} |
|
| 802 | + switch($q{0}){ |
|
| 803 | + case '(': |
|
| 804 | + if($continue) { |
|
| 805 | + $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 806 | + $continue = false; |
|
| 807 | + } |
|
| 808 | + $q = $insert . $q; |
|
| 809 | + $ex = 1; |
|
| 810 | + $c = 1; |
|
| 811 | + break; |
|
| 812 | + case 'I': |
|
| 813 | 813 | |
| 814 | - if (preg_match('/^(INSERT( INTO `?(.+?)`?).+?\sVALUES)/s', $q, $m)) { |
|
| 815 | - $insert = trim($m[1]) . ' '; |
|
| 816 | - $tab = $m[3]; |
|
| 817 | - $this->rtl[7] = 0; |
|
| 818 | - $this->rtl[8] = 0; |
|
| 819 | - $ex = 1; |
|
| 820 | - } |
|
| 821 | - break; |
|
| 822 | - case 'C': |
|
| 823 | - $ex = 1; |
|
| 824 | - $ei = 1; |
|
| 825 | - if (preg_match('/^CREATE TABLE.+?`(.+?)`/', $q, $m)) { |
|
| 826 | - $ex = 1; |
|
| 827 | - $tab = $m[1]; |
|
| 828 | - $this->addLog(sprintf($this->LNG['restore_TC'], $tab)); |
|
| 829 | - //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
|
| 830 | - if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 831 | - $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 832 | - } |
|
| 833 | - elseif(empty($this->JOB['charset'])){ |
|
| 834 | - if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
|
| 835 | - $this->setNames($charset[2]); |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - } |
|
| 839 | - break; |
|
| 840 | - case '-' && $q{1} == '-': |
|
| 841 | - case '#': |
|
| 842 | - $repeat = true; |
|
| 843 | - $q = ltrim(substr($q, strpos($q, $this->JOB['eol']))); |
|
| 844 | - $ex = 0; |
|
| 845 | - break; |
|
| 846 | - case '/': |
|
| 847 | - case 'S': |
|
| 848 | - if (preg_match('/SET NAMES (\w+)/', $q, $m)) { |
|
| 849 | - $this->JOB['charset'] = $m[1]; |
|
| 850 | - $this->setNames($this->JOB['charset']); |
|
| 851 | - $ex = 0; |
|
| 852 | - } |
|
| 853 | - else $ex = 1; |
|
| 854 | - break; |
|
| 855 | - default: |
|
| 856 | - $insert = ''; |
|
| 857 | - $ex = 1; |
|
| 858 | - $ei = 0; |
|
| 859 | - } |
|
| 860 | - } while ($repeat); |
|
| 861 | - if($ex) { |
|
| 862 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 863 | - fseek($this->fh_rtl, 0); |
|
| 864 | - $this->rtl[1] = time(); |
|
| 865 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 866 | - error_log("-----------------\n{$q}\n", 3, "sql.log"); |
|
| 867 | - if(mysql_query($q)) { |
|
| 868 | - if($insert) { |
|
| 869 | - $c = 1; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - else { |
|
| 873 | - error_log("-----------------\n{$q}\n", 3, "error.log"); |
|
| 874 | - sxd_my_error(); |
|
| 875 | - } |
|
| 814 | + if (preg_match('/^(INSERT( INTO `?(.+?)`?).+?\sVALUES)/s', $q, $m)) { |
|
| 815 | + $insert = trim($m[1]) . ' '; |
|
| 816 | + $tab = $m[3]; |
|
| 817 | + $this->rtl[7] = 0; |
|
| 818 | + $this->rtl[8] = 0; |
|
| 819 | + $ex = 1; |
|
| 820 | + } |
|
| 821 | + break; |
|
| 822 | + case 'C': |
|
| 823 | + $ex = 1; |
|
| 824 | + $ei = 1; |
|
| 825 | + if (preg_match('/^CREATE TABLE.+?`(.+?)`/', $q, $m)) { |
|
| 826 | + $ex = 1; |
|
| 827 | + $tab = $m[1]; |
|
| 828 | + $this->addLog(sprintf($this->LNG['restore_TC'], $tab)); |
|
| 829 | + //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
|
| 830 | + if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 831 | + $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 832 | + } |
|
| 833 | + elseif(empty($this->JOB['charset'])){ |
|
| 834 | + if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
|
| 835 | + $this->setNames($charset[2]); |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | + break; |
|
| 840 | + case '-' && $q{1} == '-': |
|
| 841 | + case '#': |
|
| 842 | + $repeat = true; |
|
| 843 | + $q = ltrim(substr($q, strpos($q, $this->JOB['eol']))); |
|
| 844 | + $ex = 0; |
|
| 845 | + break; |
|
| 846 | + case '/': |
|
| 847 | + case 'S': |
|
| 848 | + if (preg_match('/SET NAMES (\w+)/', $q, $m)) { |
|
| 849 | + $this->JOB['charset'] = $m[1]; |
|
| 850 | + $this->setNames($this->JOB['charset']); |
|
| 851 | + $ex = 0; |
|
| 852 | + } |
|
| 853 | + else $ex = 1; |
|
| 854 | + break; |
|
| 855 | + default: |
|
| 856 | + $insert = ''; |
|
| 857 | + $ex = 1; |
|
| 858 | + $ei = 0; |
|
| 859 | + } |
|
| 860 | + } while ($repeat); |
|
| 861 | + if($ex) { |
|
| 862 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 863 | + fseek($this->fh_rtl, 0); |
|
| 864 | + $this->rtl[1] = time(); |
|
| 865 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 866 | + error_log("-----------------\n{$q}\n", 3, "sql.log"); |
|
| 867 | + if(mysql_query($q)) { |
|
| 868 | + if($insert) { |
|
| 869 | + $c = 1; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + else { |
|
| 873 | + error_log("-----------------\n{$q}\n", 3, "error.log"); |
|
| 874 | + sxd_my_error(); |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | - if($c){ |
|
| 878 | - $i = mysql_affected_rows(); |
|
| 879 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 880 | - $this->rtl[7] += $i; |
|
| 881 | - $this->rtl[10] += $i; |
|
| 882 | - fseek($this->fh_rtl, 0); |
|
| 883 | - $this->rtl[1] = time(); |
|
| 884 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 885 | - $c = 1; |
|
| 886 | - } |
|
| 887 | - } |
|
| 877 | + if($c){ |
|
| 878 | + $i = mysql_affected_rows(); |
|
| 879 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 880 | + $this->rtl[7] += $i; |
|
| 881 | + $this->rtl[10] += $i; |
|
| 882 | + fseek($this->fh_rtl, 0); |
|
| 883 | + $this->rtl[1] = time(); |
|
| 884 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 885 | + $c = 1; |
|
| 886 | + } |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | - } |
|
| 889 | + } |
|
| 890 | 890 | |
| 891 | - $this->rtl[4] = 'EOJ'; |
|
| 892 | - $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 893 | - $this->rtl[7] = 0; |
|
| 894 | - $this->rtl[8] = 0; |
|
| 891 | + $this->rtl[4] = 'EOJ'; |
|
| 892 | + $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 893 | + $this->rtl[7] = 0; |
|
| 894 | + $this->rtl[8] = 0; |
|
| 895 | 895 | |
| 896 | - fseek($this->fh_rtl, 0); |
|
| 897 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 898 | - $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 899 | - fclose($this->fh_log); |
|
| 900 | - fclose($this->fh_rtl); |
|
| 901 | - } |
|
| 902 | - function addBackupJob($job) { |
|
| 903 | - $this->closeConnect(); |
|
| 904 | - // Создаем новое задание |
|
| 905 | - $this->JOB = $job; |
|
| 906 | - mysql_select_db($this->JOB['db']); |
|
| 907 | - // Создаем список объектов и фильтр |
|
| 908 | - $filter = $object = array(); |
|
| 909 | - $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 910 | - $queries = array( |
|
| 911 | - array('TABLE STATUS', 'Name', 'TA') |
|
| 912 | - ); |
|
| 913 | - if (V_MYSQL > 50014) { |
|
| 914 | - $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
|
| 915 | - $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
|
| 916 | - $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
|
| 917 | - if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 918 | - } |
|
| 919 | - $todo = $header = array(); |
|
| 920 | - $tabs = $rows = 0; |
|
| 921 | - $only_create = explode(' ', $this->CFG['only_create']); |
|
| 922 | - foreach($queries AS $query){ |
|
| 923 | - $t = $query[2]; |
|
| 924 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | - elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 926 | - $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
|
| 927 | - if (!$r) continue; |
|
| 928 | - $todo[$t] = array(); |
|
| 929 | - $header[$t] = array(); |
|
| 896 | + fseek($this->fh_rtl, 0); |
|
| 897 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 898 | + $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 899 | + fclose($this->fh_log); |
|
| 900 | + fclose($this->fh_rtl); |
|
| 901 | + } |
|
| 902 | + function addBackupJob($job) { |
|
| 903 | + $this->closeConnect(); |
|
| 904 | + // Создаем новое задание |
|
| 905 | + $this->JOB = $job; |
|
| 906 | + mysql_select_db($this->JOB['db']); |
|
| 907 | + // Создаем список объектов и фильтр |
|
| 908 | + $filter = $object = array(); |
|
| 909 | + $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 910 | + $queries = array( |
|
| 911 | + array('TABLE STATUS', 'Name', 'TA') |
|
| 912 | + ); |
|
| 913 | + if (V_MYSQL > 50014) { |
|
| 914 | + $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
|
| 915 | + $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
|
| 916 | + $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
|
| 917 | + if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 918 | + } |
|
| 919 | + $todo = $header = array(); |
|
| 920 | + $tabs = $rows = 0; |
|
| 921 | + $only_create = explode(' ', $this->CFG['only_create']); |
|
| 922 | + foreach($queries AS $query){ |
|
| 923 | + $t = $query[2]; |
|
| 924 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | + elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 926 | + $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
|
| 927 | + if (!$r) continue; |
|
| 928 | + $todo[$t] = array(); |
|
| 929 | + $header[$t] = array(); |
|
| 930 | 930 | |
| 931 | - while($item = mysql_fetch_assoc($r)){ |
|
| 932 | - $n = $item[$query[1]]; |
|
| 933 | - switch($t){ |
|
| 934 | - case 'TA': |
|
| 935 | - case 'TC': |
|
| 936 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 937 | - if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 938 | - $todo['VI'] = array(); |
|
| 939 | - $header['VI']= array(); |
|
| 940 | - } |
|
| 941 | - continue; |
|
| 942 | - } |
|
| 943 | - elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 944 | - $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
|
| 945 | - $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
|
| 946 | - } |
|
| 947 | - elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | - $t = 'TC'; |
|
| 949 | - $item['Rows'] = $item['Data_length'] = ''; |
|
| 950 | - } |
|
| 951 | - else continue; |
|
| 952 | - $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']); |
|
| 953 | - $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}"; |
|
| 954 | - $tabs++; |
|
| 955 | - $rows += $item['Rows']; |
|
| 956 | - break; |
|
| 957 | - default: |
|
| 958 | - if(sxd_check($n, $object[$t], $filter[$t])) { |
|
| 959 | - $todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : ''); |
|
| 960 | - $header[$t][] = $n; |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - } |
|
| 931 | + while($item = mysql_fetch_assoc($r)){ |
|
| 932 | + $n = $item[$query[1]]; |
|
| 933 | + switch($t){ |
|
| 934 | + case 'TA': |
|
| 935 | + case 'TC': |
|
| 936 | + if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 937 | + if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 938 | + $todo['VI'] = array(); |
|
| 939 | + $header['VI']= array(); |
|
| 940 | + } |
|
| 941 | + continue; |
|
| 942 | + } |
|
| 943 | + elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 944 | + $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
|
| 945 | + $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
|
| 946 | + } |
|
| 947 | + elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | + $t = 'TC'; |
|
| 949 | + $item['Rows'] = $item['Data_length'] = ''; |
|
| 950 | + } |
|
| 951 | + else continue; |
|
| 952 | + $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']); |
|
| 953 | + $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}"; |
|
| 954 | + $tabs++; |
|
| 955 | + $rows += $item['Rows']; |
|
| 956 | + break; |
|
| 957 | + default: |
|
| 958 | + if(sxd_check($n, $object[$t], $filter[$t])) { |
|
| 959 | + $todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : ''); |
|
| 960 | + $header[$t][] = $n; |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | 964 | |
| 965 | - } |
|
| 966 | - if (V_MYSQL > 50014 && (!empty($object['VI']) || !empty($filter['VI']))) { |
|
| 967 | - // Бэкап обзоров, нужно отсортировать зависимые |
|
| 968 | - $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(); |
|
| 969 | - $views = $dumped = $views_collation = array(); |
|
| 970 | - $re = "/`{$this->JOB['db']}`.`(.+?)`/"; |
|
| 971 | - while($item = mysql_fetch_assoc($r)){ |
|
| 972 | - preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m); |
|
| 973 | - $used = $m[1]; |
|
| 974 | - $views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : ''; |
|
| 975 | - $views[$item['table_name']] = $used; |
|
| 976 | - } |
|
| 965 | + } |
|
| 966 | + if (V_MYSQL > 50014 && (!empty($object['VI']) || !empty($filter['VI']))) { |
|
| 967 | + // Бэкап обзоров, нужно отсортировать зависимые |
|
| 968 | + $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(); |
|
| 969 | + $views = $dumped = $views_collation = array(); |
|
| 970 | + $re = "/`{$this->JOB['db']}`.`(.+?)`/"; |
|
| 971 | + while($item = mysql_fetch_assoc($r)){ |
|
| 972 | + preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m); |
|
| 973 | + $used = $m[1]; |
|
| 974 | + $views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : ''; |
|
| 975 | + $views[$item['table_name']] = $used; |
|
| 976 | + } |
|
| 977 | 977 | |
| 978 | - while (count($views) > 0) { |
|
| 979 | - foreach($views AS $n => $view) { |
|
| 980 | - $can_dumped = true; |
|
| 981 | - foreach($view AS $k) { |
|
| 982 | - if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
|
| 983 | - } |
|
| 984 | - if ($can_dumped) { |
|
| 985 | - if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 986 | - $todo['VI'][] = array('VI', $n, $views_collation[$n]); |
|
| 987 | - $header['VI'][] = $n; |
|
| 988 | - } |
|
| 989 | - $dumped[$n] = 1; |
|
| 990 | - unset($views[$n]); |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - unset($dumped); |
|
| 995 | - unset($views); |
|
| 996 | - unset($views_collation); |
|
| 997 | - } |
|
| 998 | - $this->JOB['file_tmp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.tmp'; |
|
| 999 | - $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 1000 | - $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 1001 | - $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
|
| 1002 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 1003 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
|
| 1004 | - $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']); |
|
| 1005 | - $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 1006 | - $this->JOB['todo'] = $todo; |
|
| 1007 | - $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 1008 | - $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, sxd_esc($this->JOB['comment'], false))) . "\n"; |
|
| 1009 | - foreach($header AS $t => $o){ |
|
| 1010 | - if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1011 | - } |
|
| 1012 | - $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 1013 | - $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 1014 | - $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 1015 | - $fcache .= "#EOH\n\n"; |
|
| 1016 | - $this->write($fcache); |
|
| 1017 | - $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db'])); |
|
| 1018 | - $this->runBackupJob(); |
|
| 1019 | - } |
|
| 1020 | - function runBackupJob($continue = false){ |
|
| 1021 | - if($continue){ |
|
| 1022 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a'); |
|
| 1023 | - mysql_select_db($this->JOB['db']); |
|
| 1024 | - } |
|
| 1025 | - mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1"); |
|
| 1026 | - $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 1027 | - $fcache = ''; |
|
| 1028 | - $writes = 0; |
|
| 978 | + while (count($views) > 0) { |
|
| 979 | + foreach($views AS $n => $view) { |
|
| 980 | + $can_dumped = true; |
|
| 981 | + foreach($view AS $k) { |
|
| 982 | + if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
|
| 983 | + } |
|
| 984 | + if ($can_dumped) { |
|
| 985 | + if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 986 | + $todo['VI'][] = array('VI', $n, $views_collation[$n]); |
|
| 987 | + $header['VI'][] = $n; |
|
| 988 | + } |
|
| 989 | + $dumped[$n] = 1; |
|
| 990 | + unset($views[$n]); |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + unset($dumped); |
|
| 995 | + unset($views); |
|
| 996 | + unset($views_collation); |
|
| 997 | + } |
|
| 998 | + $this->JOB['file_tmp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.tmp'; |
|
| 999 | + $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 1000 | + $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 1001 | + $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
|
| 1002 | + if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 1003 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
|
| 1004 | + $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']); |
|
| 1005 | + $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 1006 | + $this->JOB['todo'] = $todo; |
|
| 1007 | + $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 1008 | + $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, sxd_esc($this->JOB['comment'], false))) . "\n"; |
|
| 1009 | + foreach($header AS $t => $o){ |
|
| 1010 | + if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1011 | + } |
|
| 1012 | + $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 1013 | + $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 1014 | + $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 1015 | + $fcache .= "#EOH\n\n"; |
|
| 1016 | + $this->write($fcache); |
|
| 1017 | + $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db'])); |
|
| 1018 | + $this->runBackupJob(); |
|
| 1019 | + } |
|
| 1020 | + function runBackupJob($continue = false){ |
|
| 1021 | + if($continue){ |
|
| 1022 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a'); |
|
| 1023 | + mysql_select_db($this->JOB['db']); |
|
| 1024 | + } |
|
| 1025 | + mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1"); |
|
| 1026 | + $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 1027 | + $fcache = ''; |
|
| 1028 | + $writes = 0; |
|
| 1029 | 1029 | |
| 1030 | - if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1031 | - $time_old = time(); |
|
| 1032 | - $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 1033 | - $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
|
| 1034 | - foreach($this->JOB['todo'] AS $t => $o){ |
|
| 1035 | - if (empty($this->rtl[4])) $this->rtl[4] = $t; |
|
| 1036 | - elseif ($this->rtl[4] != $t) continue; |
|
| 1037 | - foreach($o AS $n){ |
|
| 1038 | - if (empty($this->rtl[5])) { |
|
| 1039 | - $this->rtl[5] = $n[1]; |
|
| 1040 | - $this->rtl[7] = 0; |
|
| 1041 | - $this->rtl[8] = !empty($n[4]) ? $n[4] : 0; |
|
| 1042 | - } |
|
| 1043 | - elseif ($this->rtl[5] != $n[1]) continue; |
|
| 1044 | - // Делаем бэкап |
|
| 1045 | - switch($n[0]){ |
|
| 1046 | - case 'TC': |
|
| 1047 | - case 'TD': |
|
| 1048 | - case 'TA': |
|
| 1049 | - $from = ''; |
|
| 1050 | - if ($n[0] == 'TC' || $this->rtl[7] == 0){ |
|
| 1051 | - // Бэкап структуры таблицы |
|
| 1052 | - $r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error(); |
|
| 1053 | - $item = mysql_fetch_assoc($r); |
|
| 1054 | - $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
|
| 1055 | - $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
|
| 1056 | - $this->rtl[7] = 0; |
|
| 1057 | - if($n[0] == 'TC' || !$n[4]) break; |
|
| 1058 | - // Бэкапим данные таблицы |
|
| 1059 | - $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
|
| 1060 | - } |
|
| 1061 | - else { |
|
| 1062 | - $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}"; |
|
| 1063 | - $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7])); |
|
| 1064 | - } |
|
| 1065 | - // Определяем типы полей |
|
| 1066 | - $notNum = array(); |
|
| 1067 | - $r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error(); |
|
| 1068 | - $fields = 0; |
|
| 1069 | - while($col = mysql_fetch_array($r)) { |
|
| 1070 | - // TODO: проверить типы SET, ENUM и BIT |
|
| 1071 | - $notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1; |
|
| 1072 | - $fields++; |
|
| 1073 | - } |
|
| 1074 | - $time_old = time(); |
|
| 1075 | - $z = 0; |
|
| 1076 | - // Достаем данные |
|
| 1077 | - $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}"); |
|
| 1078 | - while($row = mysql_fetch_row($r)) { |
|
| 1079 | - if (strlen($fcache) >= 61440) { |
|
| 1080 | - $z = 0; |
|
| 1081 | - if($time_old < time()) { |
|
| 1082 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 1083 | - $type = file_get_contents($this->JOB['file_stp']); |
|
| 1084 | - $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 1085 | - $this->write($fcache); |
|
| 1086 | - if($type == 1) { |
|
| 1030 | + if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1031 | + $time_old = time(); |
|
| 1032 | + $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 1033 | + $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
|
| 1034 | + foreach($this->JOB['todo'] AS $t => $o){ |
|
| 1035 | + if (empty($this->rtl[4])) $this->rtl[4] = $t; |
|
| 1036 | + elseif ($this->rtl[4] != $t) continue; |
|
| 1037 | + foreach($o AS $n){ |
|
| 1038 | + if (empty($this->rtl[5])) { |
|
| 1039 | + $this->rtl[5] = $n[1]; |
|
| 1040 | + $this->rtl[7] = 0; |
|
| 1041 | + $this->rtl[8] = !empty($n[4]) ? $n[4] : 0; |
|
| 1042 | + } |
|
| 1043 | + elseif ($this->rtl[5] != $n[1]) continue; |
|
| 1044 | + // Делаем бэкап |
|
| 1045 | + switch($n[0]){ |
|
| 1046 | + case 'TC': |
|
| 1047 | + case 'TD': |
|
| 1048 | + case 'TA': |
|
| 1049 | + $from = ''; |
|
| 1050 | + if ($n[0] == 'TC' || $this->rtl[7] == 0){ |
|
| 1051 | + // Бэкап структуры таблицы |
|
| 1052 | + $r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error(); |
|
| 1053 | + $item = mysql_fetch_assoc($r); |
|
| 1054 | + $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
|
| 1055 | + $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
|
| 1056 | + $this->rtl[7] = 0; |
|
| 1057 | + if($n[0] == 'TC' || !$n[4]) break; |
|
| 1058 | + // Бэкапим данные таблицы |
|
| 1059 | + $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
|
| 1060 | + } |
|
| 1061 | + else { |
|
| 1062 | + $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}"; |
|
| 1063 | + $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7])); |
|
| 1064 | + } |
|
| 1065 | + // Определяем типы полей |
|
| 1066 | + $notNum = array(); |
|
| 1067 | + $r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error(); |
|
| 1068 | + $fields = 0; |
|
| 1069 | + while($col = mysql_fetch_array($r)) { |
|
| 1070 | + // TODO: проверить типы SET, ENUM и BIT |
|
| 1071 | + $notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1; |
|
| 1072 | + $fields++; |
|
| 1073 | + } |
|
| 1074 | + $time_old = time(); |
|
| 1075 | + $z = 0; |
|
| 1076 | + // Достаем данные |
|
| 1077 | + $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}"); |
|
| 1078 | + while($row = mysql_fetch_row($r)) { |
|
| 1079 | + if (strlen($fcache) >= 61440) { |
|
| 1080 | + $z = 0; |
|
| 1081 | + if($time_old < time()) { |
|
| 1082 | + if(file_exists($this->JOB['file_stp'])){ |
|
| 1083 | + $type = file_get_contents($this->JOB['file_stp']); |
|
| 1084 | + $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 1085 | + $this->write($fcache); |
|
| 1086 | + if($type == 1) { |
|
| 1087 | 1087 | |
| 1088 | - } |
|
| 1089 | - unset($this->rtl); |
|
| 1090 | - exit; |
|
| 1091 | - } |
|
| 1092 | - $time_old = time(); |
|
| 1093 | - if($time_old >= $exit_time){ |
|
| 1094 | - $this->rtl[9] = 3; |
|
| 1095 | - $this->write($fcache); |
|
| 1096 | - unset($this->rtl); |
|
| 1097 | - exit; |
|
| 1098 | - } |
|
| 1099 | - clearstatcache(); |
|
| 1100 | - } |
|
| 1101 | - $this->write($fcache); |
|
| 1102 | - } |
|
| 1103 | - for($k = 0; $k < $fields; $k++){ |
|
| 1104 | - if(!isset($row[$k])) {$row[$k] = '\N';} |
|
| 1105 | - elseif($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк |
|
| 1106 | - } |
|
| 1107 | - $fcache .= '(' . implode(',', $row) . "),\n"; |
|
| 1108 | - $this->rtl[7]++; |
|
| 1109 | - $this->rtl[10]++; |
|
| 1110 | - } |
|
| 1111 | - unset($row); |
|
| 1112 | - mysql_free_result($r); |
|
| 1113 | - $fcache = substr_replace($fcache, "\t;\n", -2, 2); |
|
| 1114 | - break; |
|
| 1088 | + } |
|
| 1089 | + unset($this->rtl); |
|
| 1090 | + exit; |
|
| 1091 | + } |
|
| 1092 | + $time_old = time(); |
|
| 1093 | + if($time_old >= $exit_time){ |
|
| 1094 | + $this->rtl[9] = 3; |
|
| 1095 | + $this->write($fcache); |
|
| 1096 | + unset($this->rtl); |
|
| 1097 | + exit; |
|
| 1098 | + } |
|
| 1099 | + clearstatcache(); |
|
| 1100 | + } |
|
| 1101 | + $this->write($fcache); |
|
| 1102 | + } |
|
| 1103 | + for($k = 0; $k < $fields; $k++){ |
|
| 1104 | + if(!isset($row[$k])) {$row[$k] = '\N';} |
|
| 1105 | + elseif($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк |
|
| 1106 | + } |
|
| 1107 | + $fcache .= '(' . implode(',', $row) . "),\n"; |
|
| 1108 | + $this->rtl[7]++; |
|
| 1109 | + $this->rtl[10]++; |
|
| 1110 | + } |
|
| 1111 | + unset($row); |
|
| 1112 | + mysql_free_result($r); |
|
| 1113 | + $fcache = substr_replace($fcache, "\t;\n", -2, 2); |
|
| 1114 | + break; |
|
| 1115 | 1115 | |
| 1116 | - default: |
|
| 1117 | - if(V_MYSQL < 50121 && $n[0] == 'TR'){ |
|
| 1118 | - // SHOW CREATE TRIGGER отсутствует до MySQL 5.1.21 |
|
| 1119 | - $r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error(); |
|
| 1120 | - $item = mysql_fetch_assoc($r); |
|
| 1121 | - $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"; |
|
| 1122 | - } |
|
| 1123 | - else { |
|
| 1124 | - $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1])); |
|
| 1125 | - $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error(); |
|
| 1126 | - $item = mysql_fetch_assoc($r); |
|
| 1127 | - $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"; |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1116 | + default: |
|
| 1117 | + if(V_MYSQL < 50121 && $n[0] == 'TR'){ |
|
| 1118 | + // SHOW CREATE TRIGGER отсутствует до MySQL 5.1.21 |
|
| 1119 | + $r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error(); |
|
| 1120 | + $item = mysql_fetch_assoc($r); |
|
| 1121 | + $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"; |
|
| 1122 | + } |
|
| 1123 | + else { |
|
| 1124 | + $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1])); |
|
| 1125 | + $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error(); |
|
| 1126 | + $item = mysql_fetch_assoc($r); |
|
| 1127 | + $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"; |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - $this->rtl[5] = ''; |
|
| 1132 | - } |
|
| 1133 | - $this->rtl[4] = ''; |
|
| 1134 | - } |
|
| 1135 | - $this->rtl[4] = 'EOJ'; |
|
| 1136 | - $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 1137 | - $this->rtl[6] = ''; |
|
| 1138 | - $this->rtl[7] = 0; |
|
| 1139 | - $this->rtl[8] = 0; |
|
| 1140 | - $this->write($fcache); |
|
| 1141 | - fclose($this->fh_tmp); |
|
| 1142 | - rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
|
| 1143 | - $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
|
| 1144 | - if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1145 | - if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
|
| 1131 | + $this->rtl[5] = ''; |
|
| 1132 | + } |
|
| 1133 | + $this->rtl[4] = ''; |
|
| 1134 | + } |
|
| 1135 | + $this->rtl[4] = 'EOJ'; |
|
| 1136 | + $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 1137 | + $this->rtl[6] = ''; |
|
| 1138 | + $this->rtl[7] = 0; |
|
| 1139 | + $this->rtl[8] = 0; |
|
| 1140 | + $this->write($fcache); |
|
| 1141 | + fclose($this->fh_tmp); |
|
| 1142 | + rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
|
| 1143 | + $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
|
| 1144 | + if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1145 | + if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
|
| 1146 | 1146 | $this->addLog($this->LNG['autodelete']); |
| 1147 | 1147 | $deldate = ''; |
| 1148 | 1148 | if (!empty($this->JOB['del_time'])){ // Удаление по дням |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | $file_to_delete = count($files) - $this->JOB['del_count']; |
| 1170 | 1170 | foreach ($files AS $file){ |
| 1171 | 1171 | if ($file_to_delete-- > 0){ |
| 1172 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1172 | + if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1173 | 1173 | else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
| 1174 | 1174 | $deleted = true; |
| 1175 | 1175 | } |
@@ -1177,237 +1177,237 @@ discard block |
||
| 1177 | 1177 | } |
| 1178 | 1178 | } |
| 1179 | 1179 | if(!$deleted) $this->addLog($this->LNG['del_nothing']); |
| 1180 | - } |
|
| 1181 | - fclose($this->fh_log); |
|
| 1182 | - fclose($this->fh_rtl); |
|
| 1183 | - } |
|
| 1184 | - function setNames($collation){ |
|
| 1185 | - if(empty($collation)) return; |
|
| 1186 | - if($this->rtl[6] != $collation) { |
|
| 1187 | - mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
|
| 1188 | - /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
|
| 1189 | - $this->rtl[6] = $collation; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - function write(&$str){ |
|
| 1193 | - fseek($this->fh_rtl, 0); |
|
| 1194 | - $this->rtl[1] = time(); |
|
| 1195 | - $this->rtl[3] += fwrite($this->fh_tmp, $str); |
|
| 1196 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 1197 | - $str = ''; |
|
| 1198 | - } |
|
| 1199 | - function addLog($str, $type = 1){ |
|
| 1200 | - fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n"); |
|
| 1201 | - } |
|
| 1202 | - function getDBList(){ |
|
| 1203 | - $dbs = $items = array(); |
|
| 1180 | + } |
|
| 1181 | + fclose($this->fh_log); |
|
| 1182 | + fclose($this->fh_rtl); |
|
| 1183 | + } |
|
| 1184 | + function setNames($collation){ |
|
| 1185 | + if(empty($collation)) return; |
|
| 1186 | + if($this->rtl[6] != $collation) { |
|
| 1187 | + mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
|
| 1188 | + /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
|
| 1189 | + $this->rtl[6] = $collation; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + function write(&$str){ |
|
| 1193 | + fseek($this->fh_rtl, 0); |
|
| 1194 | + $this->rtl[1] = time(); |
|
| 1195 | + $this->rtl[3] += fwrite($this->fh_tmp, $str); |
|
| 1196 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 1197 | + $str = ''; |
|
| 1198 | + } |
|
| 1199 | + function addLog($str, $type = 1){ |
|
| 1200 | + fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n"); |
|
| 1201 | + } |
|
| 1202 | + function getDBList(){ |
|
| 1203 | + $dbs = $items = array(); |
|
| 1204 | 1204 | if (!V_MYSQL) return $dbs; |
| 1205 | 1205 | $qq = (V_MYSQL < 50000) ? '' : '\''; |
| 1206 | - if ($this->CFG['my_db']) { |
|
| 1207 | - $tmp = explode(',', $this->CFG['my_db']); |
|
| 1208 | - foreach($tmp AS $d){ |
|
| 1209 | - $d = trim($d); |
|
| 1210 | - $items[] = $qq . sxd_esc($d, false) . $qq; |
|
| 1211 | - $dbs[$d] = "{$d} (0)"; |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - else{ |
|
| 1215 | - $result = mysql_query("SHOW DATABASES") or sxd_my_error(); |
|
| 1216 | - while($item = mysql_fetch_row($result)){ |
|
| 1217 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1218 | - $items[] = $qq . sxd_esc($item[0], false) . $qq; |
|
| 1219 | - $dbs[$item[0]] = "{$item[0]} (0)"; |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - if(V_MYSQL < 50000){ |
|
| 1223 | - foreach($items AS $item){ |
|
| 1224 | - $tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error(); |
|
| 1225 | - if ($tables) { |
|
| 1226 | - $tabs = mysql_num_rows($tables); |
|
| 1227 | - $dbs[$item] = "{$item} ({$tabs})"; |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - else { |
|
| 1232 | - $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
|
| 1233 | - $result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error(); |
|
| 1234 | - while($item = mysql_fetch_row($result)){ |
|
| 1235 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1236 | - $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - return $dbs; |
|
| 1240 | - } |
|
| 1241 | - function getCharsetList(){ |
|
| 1242 | - $tmp = array(0 => '- auto -'); |
|
| 1243 | - if (!V_MYSQL) return $tmp; |
|
| 1244 | - if(V_MYSQL > 40101) { |
|
| 1245 | - $def_charsets = ''; |
|
| 1246 | - if(!empty($this->CFG['charsets'])){ |
|
| 1247 | - $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1248 | - } |
|
| 1249 | - $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
|
| 1250 | - if ($r) { |
|
| 1251 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1252 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - return $tmp; |
|
| 1257 | - } |
|
| 1258 | - function getCollationList(){ |
|
| 1259 | - $tmp = array(); |
|
| 1260 | - if (!V_MYSQL) return $tmp; |
|
| 1261 | - if(V_MYSQL > 40101) { |
|
| 1262 | - $def_charsets = ''; |
|
| 1263 | - if(!empty($this->CFG['charsets'])){ |
|
| 1264 | - $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1265 | - } |
|
| 1266 | - $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
|
| 1267 | - if ($r) { |
|
| 1268 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1269 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1273 | - return $tmp; |
|
| 1274 | - } |
|
| 1275 | - function getObjects($tree, $db_name){ |
|
| 1276 | - mysql_select_db($db_name); |
|
| 1277 | - // Достаем таблицы |
|
| 1278 | - $r = mysql_query('SHOW TABLE STATUS'); |
|
| 1279 | - $tab_prefix_last = $tab_prefix = '*'; |
|
| 1280 | - $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
|
| 1281 | - if($r){ |
|
| 1282 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1283 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 1284 | - $objects['VI'][]= $item['Name']; |
|
| 1285 | - } |
|
| 1286 | - else{ |
|
| 1287 | - $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
|
| 1288 | - } |
|
| 1289 | - } |
|
| 1206 | + if ($this->CFG['my_db']) { |
|
| 1207 | + $tmp = explode(',', $this->CFG['my_db']); |
|
| 1208 | + foreach($tmp AS $d){ |
|
| 1209 | + $d = trim($d); |
|
| 1210 | + $items[] = $qq . sxd_esc($d, false) . $qq; |
|
| 1211 | + $dbs[$d] = "{$d} (0)"; |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + else{ |
|
| 1215 | + $result = mysql_query("SHOW DATABASES") or sxd_my_error(); |
|
| 1216 | + while($item = mysql_fetch_row($result)){ |
|
| 1217 | + if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1218 | + $items[] = $qq . sxd_esc($item[0], false) . $qq; |
|
| 1219 | + $dbs[$item[0]] = "{$item[0]} (0)"; |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + if(V_MYSQL < 50000){ |
|
| 1223 | + foreach($items AS $item){ |
|
| 1224 | + $tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error(); |
|
| 1225 | + if ($tables) { |
|
| 1226 | + $tabs = mysql_num_rows($tables); |
|
| 1227 | + $dbs[$item] = "{$item} ({$tabs})"; |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + else { |
|
| 1232 | + $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
|
| 1233 | + $result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error(); |
|
| 1234 | + while($item = mysql_fetch_row($result)){ |
|
| 1235 | + if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1236 | + $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + return $dbs; |
|
| 1240 | + } |
|
| 1241 | + function getCharsetList(){ |
|
| 1242 | + $tmp = array(0 => '- auto -'); |
|
| 1243 | + if (!V_MYSQL) return $tmp; |
|
| 1244 | + if(V_MYSQL > 40101) { |
|
| 1245 | + $def_charsets = ''; |
|
| 1246 | + if(!empty($this->CFG['charsets'])){ |
|
| 1247 | + $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1248 | + } |
|
| 1249 | + $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
|
| 1250 | + if ($r) { |
|
| 1251 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1252 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + return $tmp; |
|
| 1257 | + } |
|
| 1258 | + function getCollationList(){ |
|
| 1259 | + $tmp = array(); |
|
| 1260 | + if (!V_MYSQL) return $tmp; |
|
| 1261 | + if(V_MYSQL > 40101) { |
|
| 1262 | + $def_charsets = ''; |
|
| 1263 | + if(!empty($this->CFG['charsets'])){ |
|
| 1264 | + $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1265 | + } |
|
| 1266 | + $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
|
| 1267 | + if ($r) { |
|
| 1268 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1269 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | + return $tmp; |
|
| 1274 | + } |
|
| 1275 | + function getObjects($tree, $db_name){ |
|
| 1276 | + mysql_select_db($db_name); |
|
| 1277 | + // Достаем таблицы |
|
| 1278 | + $r = mysql_query('SHOW TABLE STATUS'); |
|
| 1279 | + $tab_prefix_last = $tab_prefix = '*'; |
|
| 1280 | + $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
|
| 1281 | + if($r){ |
|
| 1282 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1283 | + if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 1284 | + $objects['VI'][]= $item['Name']; |
|
| 1285 | + } |
|
| 1286 | + else{ |
|
| 1287 | + $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
|
| 1288 | + } |
|
| 1289 | + } |
|
| 1290 | 1290 | |
| 1291 | - if (V_MYSQL > 50014 && $tree != 'services') { |
|
| 1292 | - $shows = array( |
|
| 1293 | - "PROCEDURE STATUS WHERE db='{$db_name}'", |
|
| 1294 | - "FUNCTION STATUS WHERE db='{$db_name}'", |
|
| 1295 | - 'TRIGGERS' |
|
| 1296 | - ); |
|
| 1297 | - if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1298 | - // TODO: Поправить проверку событий и триггеров |
|
| 1299 | - for($i = 0, $l = count($shows); $i < $l; $i++){ |
|
| 1300 | - $r = mysql_query('SHOW ' . $shows[$i]); |
|
| 1301 | - if($r && mysql_num_rows($r) > 0) { |
|
| 1302 | - $col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name'; |
|
| 1303 | - $type = substr($shows[$i], 0, 2); |
|
| 1304 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1305 | - $objects[$type][] = $item[$col_name]; |
|
| 1306 | - } |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - else { |
|
| 1311 | - $objects['VI'] = array(); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - return $this->formatTree($tree, $objects); |
|
| 1315 | - } |
|
| 1316 | - function getFileObjects($tree, $name, $formatTree = true){ |
|
| 1317 | - // Достаем таблицы |
|
| 1318 | - $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
|
| 1319 | - if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return ''; |
|
| 1320 | - $name = $this->CFG['backup_path'] . $name; |
|
| 1321 | - if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
|
| 1322 | - $fp = $this->openFile($name, 'r'); |
|
| 1323 | - $temp = fread($fp, 60000); |
|
| 1324 | - // Формат файла Sypex Dumper 2 - SXD20 |
|
| 1325 | - //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;"; |
|
| 1326 | - if(preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)){ |
|
| 1327 | - $head = explode("\n", $m[1]); |
|
| 1328 | - $h = explode('|', $head[0]); |
|
| 1329 | - for($i = 1, $c = count($head); $i < $c; $i++){ |
|
| 1330 | - $objects[substr($head[$i], 1,2)] = explode('|', substr($head[$i], 4)); |
|
| 1331 | - } |
|
| 1332 | - for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1333 | - $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
|
| 1334 | - } |
|
| 1335 | - } |
|
| 1336 | - else { |
|
| 1337 | - $h[9] = ''; |
|
| 1338 | - } |
|
| 1339 | - return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
|
| 1340 | - } |
|
| 1341 | - function formatTree($tree, &$objects){ |
|
| 1342 | - $obj = ''; |
|
| 1343 | - $pid = $row = 1; |
|
| 1344 | - $info = array( |
|
| 1345 | - 'TA' => array($this->LNG['obj_tables'], 1), |
|
| 1346 | - 'VI' => array($this->LNG['obj_views'], 3), |
|
| 1347 | - 'PR' => array($this->LNG['obj_procs'], 5), |
|
| 1348 | - 'FU' => array($this->LNG['obj_funcs'], 7), |
|
| 1349 | - 'TR' => array($this->LNG['obj_trigs'], 9), |
|
| 1350 | - 'EV' => array($this->LNG['obj_events'], 11) |
|
| 1351 | - ); |
|
| 1352 | - // Находим таблицы с префиксами |
|
| 1353 | - $tab_prefix_last = $tab_prefix = '*'; |
|
| 1354 | - for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1355 | - $t = $objects['TA'][$i]; |
|
| 1356 | - $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
|
| 1357 | - if ($tab_prefix != $tab_prefix_last) { |
|
| 1358 | - if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix; |
|
| 1359 | - $tab_prefix_last = $tab_prefix; |
|
| 1360 | - } |
|
| 1361 | - $objects['TA'][$tab_prefix][] = $t; |
|
| 1362 | - unset($objects['TA'][$i]); |
|
| 1363 | - } |
|
| 1364 | - foreach($objects AS $type => $o){ |
|
| 1365 | - if(!count($o)) continue; |
|
| 1366 | - if($type == 'TA') { |
|
| 1367 | - $open_childs = count($o['*']) > 1 ? 0 : 1; |
|
| 1368 | - $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
|
| 1369 | - $row++; |
|
| 1370 | - foreach($o['*'] AS $value){ |
|
| 1371 | - if(is_string($value)){ |
|
| 1372 | - if(count($o[$value]) > 1) { |
|
| 1373 | - $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],"; |
|
| 1374 | - $pid = $row++; |
|
| 1375 | - for($i = 0, $l = count($o[$value]); $i < $l; $i++){ |
|
| 1376 | - $checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1; |
|
| 1377 | - $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
|
| 1378 | - $row++; |
|
| 1379 | - } |
|
| 1380 | - } |
|
| 1381 | - else { |
|
| 1382 | - $value = $o[$value][0]; |
|
| 1383 | - } |
|
| 1384 | - } |
|
| 1385 | - //$pid = 1; |
|
| 1386 | - if (is_array($value)){ |
|
| 1387 | - $checked = ($value[1] == '' && $value[2] == '') ? 2 : 1; |
|
| 1388 | - $obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],"; |
|
| 1389 | - $row++; |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 1393 | - else { |
|
| 1394 | - $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
|
| 1395 | - $pid = $row++; |
|
| 1396 | - $info[$type][1]++; |
|
| 1397 | - for($i = 0, $l = count($o); $i < $l; $i++){ |
|
| 1398 | - $o[$i] = sxd_esc($o[$i], false); |
|
| 1399 | - $obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],"; |
|
| 1400 | - $row++; |
|
| 1401 | - } |
|
| 1402 | - } |
|
| 1403 | - } |
|
| 1404 | - $add = ''; |
|
| 1405 | - if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1406 | - return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add; |
|
| 1407 | - } |
|
| 1408 | - function getFileList(){ |
|
| 1409 | - $files = array(); |
|
| 1410 | - if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1291 | + if (V_MYSQL > 50014 && $tree != 'services') { |
|
| 1292 | + $shows = array( |
|
| 1293 | + "PROCEDURE STATUS WHERE db='{$db_name}'", |
|
| 1294 | + "FUNCTION STATUS WHERE db='{$db_name}'", |
|
| 1295 | + 'TRIGGERS' |
|
| 1296 | + ); |
|
| 1297 | + if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1298 | + // TODO: Поправить проверку событий и триггеров |
|
| 1299 | + for($i = 0, $l = count($shows); $i < $l; $i++){ |
|
| 1300 | + $r = mysql_query('SHOW ' . $shows[$i]); |
|
| 1301 | + if($r && mysql_num_rows($r) > 0) { |
|
| 1302 | + $col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name'; |
|
| 1303 | + $type = substr($shows[$i], 0, 2); |
|
| 1304 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1305 | + $objects[$type][] = $item[$col_name]; |
|
| 1306 | + } |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + else { |
|
| 1311 | + $objects['VI'] = array(); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + return $this->formatTree($tree, $objects); |
|
| 1315 | + } |
|
| 1316 | + function getFileObjects($tree, $name, $formatTree = true){ |
|
| 1317 | + // Достаем таблицы |
|
| 1318 | + $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
|
| 1319 | + if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return ''; |
|
| 1320 | + $name = $this->CFG['backup_path'] . $name; |
|
| 1321 | + if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
|
| 1322 | + $fp = $this->openFile($name, 'r'); |
|
| 1323 | + $temp = fread($fp, 60000); |
|
| 1324 | + // Формат файла Sypex Dumper 2 - SXD20 |
|
| 1325 | + //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;"; |
|
| 1326 | + if(preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)){ |
|
| 1327 | + $head = explode("\n", $m[1]); |
|
| 1328 | + $h = explode('|', $head[0]); |
|
| 1329 | + for($i = 1, $c = count($head); $i < $c; $i++){ |
|
| 1330 | + $objects[substr($head[$i], 1,2)] = explode('|', substr($head[$i], 4)); |
|
| 1331 | + } |
|
| 1332 | + for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1333 | + $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
|
| 1334 | + } |
|
| 1335 | + } |
|
| 1336 | + else { |
|
| 1337 | + $h[9] = ''; |
|
| 1338 | + } |
|
| 1339 | + return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
|
| 1340 | + } |
|
| 1341 | + function formatTree($tree, &$objects){ |
|
| 1342 | + $obj = ''; |
|
| 1343 | + $pid = $row = 1; |
|
| 1344 | + $info = array( |
|
| 1345 | + 'TA' => array($this->LNG['obj_tables'], 1), |
|
| 1346 | + 'VI' => array($this->LNG['obj_views'], 3), |
|
| 1347 | + 'PR' => array($this->LNG['obj_procs'], 5), |
|
| 1348 | + 'FU' => array($this->LNG['obj_funcs'], 7), |
|
| 1349 | + 'TR' => array($this->LNG['obj_trigs'], 9), |
|
| 1350 | + 'EV' => array($this->LNG['obj_events'], 11) |
|
| 1351 | + ); |
|
| 1352 | + // Находим таблицы с префиксами |
|
| 1353 | + $tab_prefix_last = $tab_prefix = '*'; |
|
| 1354 | + for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1355 | + $t = $objects['TA'][$i]; |
|
| 1356 | + $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
|
| 1357 | + if ($tab_prefix != $tab_prefix_last) { |
|
| 1358 | + if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix; |
|
| 1359 | + $tab_prefix_last = $tab_prefix; |
|
| 1360 | + } |
|
| 1361 | + $objects['TA'][$tab_prefix][] = $t; |
|
| 1362 | + unset($objects['TA'][$i]); |
|
| 1363 | + } |
|
| 1364 | + foreach($objects AS $type => $o){ |
|
| 1365 | + if(!count($o)) continue; |
|
| 1366 | + if($type == 'TA') { |
|
| 1367 | + $open_childs = count($o['*']) > 1 ? 0 : 1; |
|
| 1368 | + $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
|
| 1369 | + $row++; |
|
| 1370 | + foreach($o['*'] AS $value){ |
|
| 1371 | + if(is_string($value)){ |
|
| 1372 | + if(count($o[$value]) > 1) { |
|
| 1373 | + $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],"; |
|
| 1374 | + $pid = $row++; |
|
| 1375 | + for($i = 0, $l = count($o[$value]); $i < $l; $i++){ |
|
| 1376 | + $checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1; |
|
| 1377 | + $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
|
| 1378 | + $row++; |
|
| 1379 | + } |
|
| 1380 | + } |
|
| 1381 | + else { |
|
| 1382 | + $value = $o[$value][0]; |
|
| 1383 | + } |
|
| 1384 | + } |
|
| 1385 | + //$pid = 1; |
|
| 1386 | + if (is_array($value)){ |
|
| 1387 | + $checked = ($value[1] == '' && $value[2] == '') ? 2 : 1; |
|
| 1388 | + $obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],"; |
|
| 1389 | + $row++; |
|
| 1390 | + } |
|
| 1391 | + } |
|
| 1392 | + } |
|
| 1393 | + else { |
|
| 1394 | + $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
|
| 1395 | + $pid = $row++; |
|
| 1396 | + $info[$type][1]++; |
|
| 1397 | + for($i = 0, $l = count($o); $i < $l; $i++){ |
|
| 1398 | + $o[$i] = sxd_esc($o[$i], false); |
|
| 1399 | + $obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],"; |
|
| 1400 | + $row++; |
|
| 1401 | + } |
|
| 1402 | + } |
|
| 1403 | + } |
|
| 1404 | + $add = ''; |
|
| 1405 | + if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1406 | + return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add; |
|
| 1407 | + } |
|
| 1408 | + function getFileList(){ |
|
| 1409 | + $files = array(); |
|
| 1410 | + if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1411 | 1411 | while (false !== ($file = readdir($handle))) { |
| 1412 | 1412 | if (preg_match("/^.+?\.sql(\.(gz|bz2))?$/", $file)) { |
| 1413 | 1413 | $files[$file] = $file; |
@@ -1416,196 +1416,196 @@ discard block |
||
| 1416 | 1416 | closedir($handle); |
| 1417 | 1417 | } |
| 1418 | 1418 | ksort($files); |
| 1419 | - return $files; |
|
| 1420 | - } |
|
| 1421 | - function getSavedJobs(){ |
|
| 1422 | - $sj = array('sj_backup' => array(), 'sj_restore' => array(),); |
|
| 1423 | - if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1419 | + return $files; |
|
| 1420 | + } |
|
| 1421 | + function getSavedJobs(){ |
|
| 1422 | + $sj = array('sj_backup' => array(), 'sj_restore' => array(),); |
|
| 1423 | + if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1424 | 1424 | while (false !== ($file = readdir($handle))) { |
| 1425 | 1425 | if (preg_match("/^sj_(.+?)\.job.php$/", $file)) { |
| 1426 | - include($this->CFG['backup_path'] . $file); |
|
| 1426 | + include($this->CFG['backup_path'] . $file); |
|
| 1427 | 1427 | $sj['sj_' . $JOB['type']][$JOB['job']] = "<b>{$JOB['job']}</b><br><i>{$JOB['title']} </i>"; |
| 1428 | 1428 | } |
| 1429 | 1429 | } |
| 1430 | 1430 | closedir($handle); |
| 1431 | 1431 | } |
| 1432 | 1432 | if(count($sj['sj_backup']) > 0){ |
| 1433 | - ksort($sj['sj_backup']); |
|
| 1434 | - } |
|
| 1433 | + ksort($sj['sj_backup']); |
|
| 1434 | + } |
|
| 1435 | 1435 | else { |
| 1436 | - $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1437 | - } |
|
| 1438 | - if(count($sj['sj_restore']) > 0){ |
|
| 1439 | - ksort($sj['sj_restore']); |
|
| 1440 | - } |
|
| 1436 | + $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1437 | + } |
|
| 1438 | + if(count($sj['sj_restore']) > 0){ |
|
| 1439 | + ksort($sj['sj_restore']); |
|
| 1440 | + } |
|
| 1441 | 1441 | else { |
| 1442 | - $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1443 | - } |
|
| 1444 | - return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
|
| 1445 | - } |
|
| 1446 | - function getFileListExtended(){ |
|
| 1447 | - $files = array(); |
|
| 1448 | - if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1442 | + $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1443 | + } |
|
| 1444 | + return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
|
| 1445 | + } |
|
| 1446 | + function getFileListExtended(){ |
|
| 1447 | + $files = array(); |
|
| 1448 | + if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1449 | 1449 | while (false !== ($file = readdir($handle))) { |
| 1450 | 1450 | if (preg_match("/^.+?\.sql(\.(gz|bz2))?$/", $file, $m)) { |
| 1451 | 1451 | $fp = $this->openFile($this->CFG['backup_path'] . $file, 'r'); |
| 1452 | 1452 | $ext = !empty($m[2]) ? $m[2] : 'sql'; |
| 1453 | 1453 | $temp = fgets($fp); |
| 1454 | 1454 | if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){ |
| 1455 | - $h = explode('|', $m[1]); |
|
| 1456 | - $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); |
|
| 1457 | - } |
|
| 1458 | - elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1459 | - $h = explode('|', $m[1]); |
|
| 1460 | - $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); |
|
| 1461 | - } |
|
| 1462 | - else { |
|
| 1463 | - $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file); |
|
| 1464 | - } |
|
| 1455 | + $h = explode('|', $m[1]); |
|
| 1456 | + $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); |
|
| 1457 | + } |
|
| 1458 | + elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1459 | + $h = explode('|', $m[1]); |
|
| 1460 | + $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); |
|
| 1461 | + } |
|
| 1462 | + else { |
|
| 1463 | + $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file); |
|
| 1464 | + } |
|
| 1465 | 1465 | } |
| 1466 | 1466 | } |
| 1467 | 1467 | closedir($handle); |
| 1468 | 1468 | } |
| 1469 | 1469 | function s($a, $b){ |
| 1470 | - return strcmp($b[1], $a[1]); |
|
| 1471 | - } |
|
| 1470 | + return strcmp($b[1], $a[1]); |
|
| 1471 | + } |
|
| 1472 | 1472 | usort($files, 's'); |
| 1473 | - return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');'; |
|
| 1474 | - } |
|
| 1475 | - function saveJob($job, $config){ |
|
| 1476 | - $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
|
| 1477 | - } |
|
| 1478 | - function openFile($name, $mode){ |
|
| 1479 | - if($mode == 'r') { |
|
| 1480 | - if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1481 | - } |
|
| 1482 | - else{ |
|
| 1483 | - switch($this->JOB['zip']) { |
|
| 1484 | - case 0 : $this->JOB['file_ext'] = 'sql'; break; |
|
| 1485 | - case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
|
| 1486 | - default: $this->JOB['file_ext'] = 'sql.gz'; break; |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - switch ($this->JOB['file_ext']){ |
|
| 1490 | - case 'sql': |
|
| 1491 | - return fopen($name, "{$mode}b"); |
|
| 1492 | - break; |
|
| 1493 | - case 'sql.bz2': |
|
| 1494 | - return bzopen($name, $mode); |
|
| 1495 | - break; |
|
| 1496 | - case 'sql.gz': |
|
| 1497 | - return gzopen($name, $mode . ($mode == 'w' ? $this->JOB['zip'] : '')); |
|
| 1498 | - break; |
|
| 1499 | - default: return false; |
|
| 1500 | - } |
|
| 1501 | - } |
|
| 1473 | + return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');'; |
|
| 1474 | + } |
|
| 1475 | + function saveJob($job, $config){ |
|
| 1476 | + $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
|
| 1477 | + } |
|
| 1478 | + function openFile($name, $mode){ |
|
| 1479 | + if($mode == 'r') { |
|
| 1480 | + if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1481 | + } |
|
| 1482 | + else{ |
|
| 1483 | + switch($this->JOB['zip']) { |
|
| 1484 | + case 0 : $this->JOB['file_ext'] = 'sql'; break; |
|
| 1485 | + case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
|
| 1486 | + default: $this->JOB['file_ext'] = 'sql.gz'; break; |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + switch ($this->JOB['file_ext']){ |
|
| 1490 | + case 'sql': |
|
| 1491 | + return fopen($name, "{$mode}b"); |
|
| 1492 | + break; |
|
| 1493 | + case 'sql.bz2': |
|
| 1494 | + return bzopen($name, $mode); |
|
| 1495 | + break; |
|
| 1496 | + case 'sql.gz': |
|
| 1497 | + return gzopen($name, $mode . ($mode == 'w' ? $this->JOB['zip'] : '')); |
|
| 1498 | + break; |
|
| 1499 | + default: return false; |
|
| 1500 | + } |
|
| 1501 | + } |
|
| 1502 | 1502 | } |
| 1503 | 1503 | function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n"){ |
| 1504 | - static $l = ''; |
|
| 1505 | - static $r = 0; |
|
| 1506 | - $fs = ftell($f); |
|
| 1507 | - $delim_len = strlen($delimiter . $eol); |
|
| 1508 | - while($r || $s = fread($f, 61440)){ |
|
| 1509 | - if(!$r) $l .= $s; |
|
| 1510 | - $pos = strpos($l, $delimiter . $eol); |
|
| 1511 | - if ($pos !== false) { |
|
| 1512 | - // Есть окончание запроса |
|
| 1513 | - $q = substr($l, 0, $pos); |
|
| 1514 | - $l = substr($l, $pos+$delim_len); |
|
| 1515 | - $r = 1; |
|
| 1516 | - $seek = strlen($l); |
|
| 1517 | - return $q; |
|
| 1518 | - } |
|
| 1519 | - if($ei) { |
|
| 1520 | - $pos = strrpos($l, $eol); |
|
| 1521 | - if($pos > 0 && $l{$pos-1} === ',') { |
|
| 1522 | - // Окончание не найдено |
|
| 1523 | - $q = substr($l, 0, $pos-1); |
|
| 1524 | - $l = substr($l, $pos+ strlen($eol)); |
|
| 1525 | - $seek = strlen($l); |
|
| 1526 | - $r = 0; |
|
| 1527 | - return $q; |
|
| 1528 | - } |
|
| 1529 | - } |
|
| 1530 | - $r = 0; |
|
| 1531 | - } |
|
| 1532 | - if (!empty($l)) { |
|
| 1533 | - return $l; |
|
| 1534 | - } |
|
| 1535 | - return false; |
|
| 1504 | + static $l = ''; |
|
| 1505 | + static $r = 0; |
|
| 1506 | + $fs = ftell($f); |
|
| 1507 | + $delim_len = strlen($delimiter . $eol); |
|
| 1508 | + while($r || $s = fread($f, 61440)){ |
|
| 1509 | + if(!$r) $l .= $s; |
|
| 1510 | + $pos = strpos($l, $delimiter . $eol); |
|
| 1511 | + if ($pos !== false) { |
|
| 1512 | + // Есть окончание запроса |
|
| 1513 | + $q = substr($l, 0, $pos); |
|
| 1514 | + $l = substr($l, $pos+$delim_len); |
|
| 1515 | + $r = 1; |
|
| 1516 | + $seek = strlen($l); |
|
| 1517 | + return $q; |
|
| 1518 | + } |
|
| 1519 | + if($ei) { |
|
| 1520 | + $pos = strrpos($l, $eol); |
|
| 1521 | + if($pos > 0 && $l{$pos-1} === ',') { |
|
| 1522 | + // Окончание не найдено |
|
| 1523 | + $q = substr($l, 0, $pos-1); |
|
| 1524 | + $l = substr($l, $pos+ strlen($eol)); |
|
| 1525 | + $seek = strlen($l); |
|
| 1526 | + $r = 0; |
|
| 1527 | + return $q; |
|
| 1528 | + } |
|
| 1529 | + } |
|
| 1530 | + $r = 0; |
|
| 1531 | + } |
|
| 1532 | + if (!empty($l)) { |
|
| 1533 | + return $l; |
|
| 1534 | + } |
|
| 1535 | + return false; |
|
| 1536 | 1536 | } |
| 1537 | 1537 | function sxd_check($n, $obj, $filt){ |
| 1538 | - return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
|
| 1538 | + return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
|
| 1539 | 1539 | } |
| 1540 | 1540 | function sxd_php2json($obj){ |
| 1541 | - if(count($obj) == 0) return '[]'; |
|
| 1542 | - $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
|
| 1543 | - $str = $is_obj ? '{' : '['; |
|
| 1541 | + if(count($obj) == 0) return '[]'; |
|
| 1542 | + $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
|
| 1543 | + $str = $is_obj ? '{' : '['; |
|
| 1544 | 1544 | foreach ($obj AS $key => $value) { |
| 1545 | - $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
|
| 1545 | + $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
|
| 1546 | 1546 | if (is_array($value)) $str .= sxd_php2json($value); |
| 1547 | 1547 | elseif (is_null($value)) $str .= 'null'; |
| 1548 | 1548 | elseif (is_bool($value)) $str .= $value ? 'true' : 'false'; |
| 1549 | - elseif (is_numeric($value)) $str .= $value; |
|
| 1550 | - else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1551 | - $str .= ','; |
|
| 1549 | + elseif (is_numeric($value)) $str .= $value; |
|
| 1550 | + else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1551 | + $str .= ','; |
|
| 1552 | 1552 | } |
| 1553 | - return substr_replace($str, $is_obj ? '}' : ']', -1); |
|
| 1553 | + return substr_replace($str, $is_obj ? '}' : ']', -1); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | function sxd_ver2int($ver){ |
| 1556 | - return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
|
| 1556 | + return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
|
| 1557 | 1557 | } |
| 1558 | 1558 | function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){ |
| 1559 | 1559 | global $SXD; |
| 1560 | 1560 | if($SXD->try) return; |
| 1561 | - if($errno == 8192) return; |
|
| 1561 | + if($errno == 8192) return; |
|
| 1562 | 1562 | if(strpos($errmsg, 'timezone settings')) return; |
| 1563 | 1563 | $errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', |
| 1564 | - 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
|
| 1565 | - 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
|
| 1566 | - $str = sxd_esc("{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})", false); |
|
| 1567 | - if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1564 | + 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
|
| 1565 | + 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
|
| 1566 | + $str = sxd_esc("{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})", false); |
|
| 1567 | + if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1568 | 1568 | |
| 1569 | 1569 | if($errno == 8 || $errno == 1024) { |
| 1570 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1571 | - else { |
|
| 1572 | - fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
|
| 1573 | - } |
|
| 1574 | - } |
|
| 1570 | + if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1571 | + else { |
|
| 1572 | + fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
|
| 1573 | + } |
|
| 1574 | + } |
|
| 1575 | 1575 | elseif($errno < 1024) { |
| 1576 | - $SXD->error = true; |
|
| 1577 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1578 | - else { |
|
| 1579 | - $SXD->rtl[1] = time(); |
|
| 1580 | - $SXD->rtl[9] = 5; |
|
| 1581 | - fseek($SXD->fh_rtl, 0); |
|
| 1582 | - fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1583 | - fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t4\t{$str}\n"); |
|
| 1584 | - unset($SXD->rtl); |
|
| 1585 | - } |
|
| 1576 | + $SXD->error = true; |
|
| 1577 | + if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1578 | + else { |
|
| 1579 | + $SXD->rtl[1] = time(); |
|
| 1580 | + $SXD->rtl[9] = 5; |
|
| 1581 | + fseek($SXD->fh_rtl, 0); |
|
| 1582 | + fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1583 | + fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t4\t{$str}\n"); |
|
| 1584 | + unset($SXD->rtl); |
|
| 1585 | + } |
|
| 1586 | 1586 | |
| 1587 | - die; |
|
| 1588 | - } |
|
| 1587 | + die; |
|
| 1588 | + } |
|
| 1589 | 1589 | } |
| 1590 | 1590 | function sxd_esc($str, $quoted = true){ |
| 1591 | - return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'"); |
|
| 1591 | + return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'"); |
|
| 1592 | 1592 | } |
| 1593 | 1593 | function sxd_my_error(){ |
| 1594 | - trigger_error(mysql_error(), E_USER_ERROR); |
|
| 1594 | + trigger_error(mysql_error(), E_USER_ERROR); |
|
| 1595 | 1595 | } |
| 1596 | 1596 | function sxd_shutdown(){ |
| 1597 | - global $SXD; |
|
| 1598 | - if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
|
| 1599 | - $SXD->rtl[1] = time(); |
|
| 1600 | - if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
|
| 1601 | - $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
|
| 1602 | - $SXD->rtl[9] = !empty($type) ? $type : 2; |
|
| 1603 | - } |
|
| 1604 | - else $SXD->rtl[9] = 5; |
|
| 1605 | - fseek($SXD->fh_rtl, 0); |
|
| 1606 | - fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1607 | - } |
|
| 1597 | + global $SXD; |
|
| 1598 | + if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
|
| 1599 | + $SXD->rtl[1] = time(); |
|
| 1600 | + if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
|
| 1601 | + $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
|
| 1602 | + $SXD->rtl[9] = !empty($type) ? $type : 2; |
|
| 1603 | + } |
|
| 1604 | + else $SXD->rtl[9] = 5; |
|
| 1605 | + fseek($SXD->fh_rtl, 0); |
|
| 1606 | + fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1607 | + } |
|
| 1608 | 1608 | } |
| 1609 | 1609 | function sxd_antimagic($arr){ |
| 1610 | - return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr); |
|
| 1610 | + return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr); |
|
| 1611 | 1611 | } |
@@ -33,27 +33,27 @@ discard block |
||
| 33 | 33 | define('V_PHP', sxd_ver2int(phpversion())); |
| 34 | 34 | $this->name = 'Sypex Dumper 2.0.11'; |
| 35 | 35 | } |
| 36 | - function loadLang($lng_name = 'auto'){ |
|
| 37 | - if($lng_name == 'auto'){ |
|
| 36 | + function loadLang($lng_name = 'auto') { |
|
| 37 | + if ($lng_name == 'auto') { |
|
| 38 | 38 | include('lang/list.php'); |
| 39 | 39 | $this->langs = &$langs; |
| 40 | 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])){ |
|
| 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 | 44 | $lng_name = $l; |
| 45 | 45 | break; |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php"); |
|
| 50 | + if (file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php"); |
|
| 51 | 51 | else include("lang/lng_en.php"); |
| 52 | 52 | $this->LNG = &$LNG; |
| 53 | 53 | $this->LNG['name'] = $lng_name; |
| 54 | 54 | return true; |
| 55 | 55 | } |
| 56 | - function init($args = false){ |
|
| 56 | + function init($args = false) { |
|
| 57 | 57 | if (get_magic_quotes_gpc()) { |
| 58 | 58 | $_POST = sxd_antimagic($_POST); |
| 59 | 59 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->virtualize = false; |
| 67 | 67 | $this->cron_mode = false; |
| 68 | 68 | // Проверяем авторизацию и делаем коннект к базе |
| 69 | - if(empty($this->CFG['my_user'])){ |
|
| 69 | + if (empty($this->CFG['my_user'])) { |
|
| 70 | 70 | $this->CFG['my_host'] = 'localhost'; |
| 71 | 71 | $this->CFG['my_port'] = 3306; |
| 72 | 72 | $this->CFG['my_user'] = 'root'; |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | $this->CFG['my_db'] = ''; |
| 76 | 76 | } |
| 77 | 77 | if ($args) { // консольный режим |
| 78 | - foreach($args AS $key => $arg){ |
|
| 79 | - if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)){ |
|
| 78 | + foreach ($args AS $key => $arg) { |
|
| 79 | + if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)) { |
|
| 80 | 80 | switch ($m[1]) { |
| 81 | 81 | case 'h': $this->CFG['my_host'] = $m[2]; break; // хост |
| 82 | 82 | case 'o': $this->CFG['my_port'] = $m[2]; break; // порт |
@@ -90,73 +90,73 @@ discard block |
||
| 90 | 90 | set_time_limit($CFG['time_cron']); |
| 91 | 91 | // Загружаем конфиг файл, если нужно |
| 92 | 92 | $auth = $this->connect(); |
| 93 | - if($auth && !empty($this->CFG['sjob'])){ |
|
| 93 | + if ($auth && !empty($this->CFG['sjob'])) { |
|
| 94 | 94 | $this->ajax($this->loadJob($this->CFG['sjob'])); |
| 95 | 95 | echo file_get_contents($this->JOB['file_log']); |
| 96 | - if(file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']); |
|
| 97 | - if(file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']); |
|
| 96 | + if (file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']); |
|
| 97 | + if (file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']); |
|
| 98 | 98 | } |
| 99 | 99 | else echo 'Auth error'; |
| 100 | 100 | exit; |
| 101 | 101 | } |
| 102 | - elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 102 | + elseif (!empty($this->CFG['auth'])) { // Авторизация |
|
| 103 | 103 | $auth = false; |
| 104 | 104 | $sfile = 'ses.php'; |
| 105 | 105 | |
| 106 | - if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){ |
|
| 106 | + if (!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])) { |
|
| 107 | 107 | include($sfile); |
| 108 | - if(isset($SES[$_COOKIE['sxd']])) { |
|
| 108 | + if (isset($SES[$_COOKIE['sxd']])) { |
|
| 109 | 109 | $auth = true; |
| 110 | 110 | $this->CFG = $SES[$_COOKIE['sxd']]['cfg']; |
| 111 | 111 | $this->SES = &$SES; |
| 112 | 112 | $this->loadLang($this->CFG['lang']); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | - if(!$auth) { |
|
| 115 | + if (!$auth) { |
|
| 116 | 116 | $user = !empty($_POST['user']) ? $_POST['user'] : ''; |
| 117 | 117 | $pass = !empty($_POST['pass']) ? $_POST['pass'] : ''; |
| 118 | 118 | $host = !empty($_POST['host']) ? $_POST['host'] : (!empty($this->CFG['my_host']) ? $this->CFG['my_host'] : 'localhost'); |
| 119 | 119 | $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306; |
| 120 | 120 | $temp = preg_split('/\s+/', $this->CFG['auth']); |
| 121 | - if(!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']);} |
|
| 122 | - foreach($temp AS $a){ |
|
| 123 | - switch($a) { |
|
| 124 | - case 'cfg': if(empty($user)) {continue;} |
|
| 125 | - $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user']== $user && $CFG['pass'] == $pass; |
|
| 121 | + if (!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']); } |
|
| 122 | + foreach ($temp AS $a) { |
|
| 123 | + switch ($a) { |
|
| 124 | + case 'cfg': if (empty($user)) {continue; } |
|
| 125 | + $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user'] == $user && $CFG['pass'] == $pass; |
|
| 126 | 126 | break; |
| 127 | - case 'mysql': if(empty($user)) {continue;} |
|
| 128 | - if($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue;} |
|
| 127 | + case 'mysql': if (empty($user)) {continue; } |
|
| 128 | + if ($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue; } |
|
| 129 | 129 | $auth = $this->connect($host, $port, $user, $pass); |
| 130 | 130 | break; |
| 131 | 131 | default: $file = 'auth_' . $a . '.php'; |
| 132 | - if(!file_exists($file)) continue; |
|
| 132 | + if (!file_exists($file)) continue; |
|
| 133 | 133 | include $file; |
| 134 | 134 | } |
| 135 | - if($auth) break; |
|
| 135 | + if ($auth) break; |
|
| 136 | 136 | } |
| 137 | - if($auth){ |
|
| 138 | - $key = md5(rand(1,100000) . $user . microtime()); |
|
| 137 | + if ($auth) { |
|
| 138 | + $key = md5(rand(1, 100000) . $user . microtime()); |
|
| 139 | 139 | $CFG['lang'] = $this->LNG['name']; |
| 140 | 140 | $_COOKIE['sxd'] = $key; |
| 141 | 141 | $this->saveCFG(); |
| 142 | - if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 142 | + if (V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | 143 | else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
| 144 | 144 | header("Location: ./"); |
| 145 | 145 | exit; |
| 146 | 146 | } |
| 147 | - foreach(array('user', 'pass', 'host', 'port') AS $key){ |
|
| 147 | + foreach (array('user', 'pass', 'host', 'port') AS $key) { |
|
| 148 | 148 | $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : ''; |
| 149 | 149 | } |
| 150 | 150 | $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : ''; |
| 151 | 151 | } |
| 152 | 152 | if (!$auth) { |
| 153 | - if(!empty($_POST['ajax'])){ |
|
| 153 | + if (!empty($_POST['ajax'])) { |
|
| 154 | 154 | echo "sxd.hideLoading();alert('Session not found');"; |
| 155 | 155 | exit; |
| 156 | 156 | } |
| 157 | 157 | $this->lng_list = '<option value="auto">- auto -</opinion>'; |
| 158 | - if(!isset($this->langs)) {include('lang/list.php');$this->langs = &$langs;} |
|
| 159 | - foreach($this->langs AS $k => $v){ |
|
| 158 | + if (!isset($this->langs)) {include('lang/list.php'); $this->langs = &$langs; } |
|
| 159 | + foreach ($this->langs AS $k => $v) { |
|
| 160 | 160 | $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>"; |
| 161 | 161 | } |
| 162 | 162 | include('tmpl.php'); |
@@ -164,26 +164,26 @@ discard block |
||
| 164 | 164 | exit; |
| 165 | 165 | } |
| 166 | 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();exit; |
|
| 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(); exit; |
|
| 170 | 170 | } |
| 171 | - function saveToFile($name, $content){ |
|
| 171 | + function saveToFile($name, $content) { |
|
| 172 | 172 | $fp = fopen($name, "w"); |
| 173 | 173 | fwrite($fp, $content); |
| 174 | 174 | fclose($fp); |
| 175 | 175 | } |
| 176 | - function connect($host = null, $port = null, $user = null, $pass = null){ |
|
| 176 | + function connect($host = null, $port = null, $user = null, $pass = null) { |
|
| 177 | 177 | $this->error = ''; |
| 178 | 178 | $this->try = true; |
| 179 | - if(!empty($user) && isset($pass)) { |
|
| 179 | + if (!empty($user) && isset($pass)) { |
|
| 180 | 180 | $this->CFG['my_host'] = $host; |
| 181 | 181 | $this->CFG['my_port'] = $port; |
| 182 | 182 | $this->CFG['my_user'] = $user; |
| 183 | 183 | $this->CFG['my_pass'] = $pass; |
| 184 | 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 | - if(V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error(); |
|
| 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 | + if (V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error(); |
|
| 187 | 187 | else mysql_query('SET NAMES utf8') or sxd_my_error(); |
| 188 | 188 | define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
| 189 | 189 | } |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
| 193 | 193 | } |
| 194 | 194 | $this->try = false; |
| 195 | - return V_MYSQL ? true: false; |
|
| 195 | + return V_MYSQL ? true : false; |
|
| 196 | 196 | } |
| 197 | - function main(){ |
|
| 197 | + function main() { |
|
| 198 | 198 | // Тулбар |
| 199 | 199 | $this->VAR['toolbar'] = sxd_php2json( |
| 200 | 200 | array( |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $this->db = 'temp'; |
| 216 | 216 | $zip = array($this->LNG['zip_none']); |
| 217 | 217 | if (function_exists("gzopen")) { |
| 218 | - for($i = 1; $i <10; $i++){ |
|
| 218 | + for ($i = 1; $i < 10; $i++) { |
|
| 219 | 219 | $zip[] = "GZip: {$i}"; |
| 220 | 220 | } |
| 221 | 221 | $zip[1] .= " ({$this->LNG['zip_min']})"; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $zip[10] = "BZip"; |
| 226 | 226 | } |
| 227 | 227 | end($zip); |
| 228 | - $zip[key($zip)] .= " ({$this->LNG['zip_max']})"; |
|
| 228 | + $zip[key($zip)] .= " ({$this->LNG['zip_max']})"; |
|
| 229 | 229 | $this->VAR['combos'] = |
| 230 | 230 | $this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) . |
| 231 | 231 | $this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) . |
@@ -248,17 +248,17 @@ discard block |
||
| 248 | 248 | include('tmpl.php'); |
| 249 | 249 | echo sxd_tpl_page(); |
| 250 | 250 | } |
| 251 | - function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
|
| 251 | + function addCombo($name, $sel, $ico, $opt_name, $opts = '') { |
|
| 252 | 252 | $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
| 253 | 253 | return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
| 254 | 254 | } |
| 255 | - function ajax($req){ |
|
| 255 | + function ajax($req) { |
|
| 256 | 256 | $res = ''; |
| 257 | 257 | $act = $req['act']; |
| 258 | - if($req['act'] == 'run_savedjob'){ |
|
| 258 | + if ($req['act'] == 'run_savedjob') { |
|
| 259 | 259 | $req = $this->loadJob($req); |
| 260 | 260 | } |
| 261 | - switch($req['act']){ |
|
| 261 | + switch ($req['act']) { |
|
| 262 | 262 | case 'load_db': |
| 263 | 263 | $res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']); |
| 264 | 264 | break; |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | case 'load_connect': |
| 275 | 275 | $CFG = $this->cfg2js($this->CFG); |
| 276 | 276 | $res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}', |
| 277 | - z('con_pass').value = '', z('con_comp').checked = {$CFG['my_comp']}, z('con_db').value = '{$CFG['my_db']}', z('con_pass').changed = false;" ; |
|
| 277 | + z('con_pass').value = '', z('con_comp').checked = {$CFG['my_comp']}, z('con_db').value = '{$CFG['my_db']}', z('con_pass').changed = false;"; |
|
| 278 | 278 | break; |
| 279 | 279 | case 'save_connect': |
| 280 | 280 | $res = $this->saveConnect($req); |
| 281 | 281 | break; |
| 282 | 282 | case 'save_job': |
| 283 | 283 | unset($req['act']); |
| 284 | - $this->saveJob('sj_' . $req['job'] , $req); |
|
| 284 | + $this->saveJob('sj_' . $req['job'], $req); |
|
| 285 | 285 | $res = $this->getSavedJobs(); |
| 286 | 286 | break; |
| 287 | 287 | case 'add_db': |
@@ -296,9 +296,9 @@ discard block |
||
| 296 | 296 | $res = $this->saveOptions($req); |
| 297 | 297 | break; |
| 298 | 298 | case 'delete_file': |
| 299 | - if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
|
| 299 | + if (preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
|
| 300 | 300 | $file = $this->CFG['backup_path'] . $req['name']; |
| 301 | - if(file_exists($file)) unlink($file); |
|
| 301 | + if (file_exists($file)) unlink($file); |
|
| 302 | 302 | } |
| 303 | 303 | $res = $this->getFileListExtended(); |
| 304 | 304 | break; |
@@ -327,40 +327,40 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | echo $res; |
| 329 | 329 | } |
| 330 | - function loadJob($job){ |
|
| 330 | + function loadJob($job) { |
|
| 331 | 331 | $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
| 332 | - if(!file_exists($file)) return; |
|
| 332 | + if (!file_exists($file)) return; |
|
| 333 | 333 | include($file); |
| 334 | 334 | $JOB['act'] = $JOB['type']; |
| 335 | 335 | $JOB['type'] = 'run'; |
| 336 | 336 | return $JOB; |
| 337 | 337 | } |
| 338 | - function deleteDB($name){ |
|
| 338 | + function deleteDB($name) { |
|
| 339 | 339 | $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
| 340 | - if($r){ |
|
| 340 | + if ($r) { |
|
| 341 | 341 | echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
| 342 | 342 | } |
| 343 | 343 | else |
| 344 | 344 | echo "alert(" . sxd_esc(mysql_error()) . ");"; |
| 345 | 345 | } |
| 346 | - function cfg2js($cfg){ |
|
| 347 | - foreach($cfg AS $k => $v){ |
|
| 346 | + function cfg2js($cfg) { |
|
| 347 | + foreach ($cfg AS $k => $v) { |
|
| 348 | 348 | $cfg[$k] = sxd_esc($v, false); |
| 349 | 349 | } |
| 350 | 350 | return $cfg; |
| 351 | 351 | } |
| 352 | - function addDb($req){ |
|
| 352 | + function addDb($req) { |
|
| 353 | 353 | $r = mysql_query('CREATE DATABASE `' . sxd_esc($req['name'], false) . '`' . (V_MYSQL > 40100 ? "CHARACTER SET {$req['charset']} COLLATE {$req['collate']}" : '')); |
| 354 | - if($r) |
|
| 354 | + if ($r) |
|
| 355 | 355 | echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
| 356 | 356 | else |
| 357 | 357 | sxd_my_error(); |
| 358 | 358 | } |
| 359 | - function saveConnect($req){ |
|
| 359 | + function saveConnect($req) { |
|
| 360 | 360 | $this->CFG['my_host'] = $req['host']; |
| 361 | - $this->CFG['my_port'] = (int)$req['port']; |
|
| 361 | + $this->CFG['my_port'] = (int) $req['port']; |
|
| 362 | 362 | $this->CFG['my_user'] = $req['user']; |
| 363 | - if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 363 | + if (isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 364 | 364 | $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
| 365 | 365 | $this->CFG['my_db'] = $req['db']; |
| 366 | 366 | $this->saveCFG(); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | echo $this->error; |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | - function saveOptions($req){ |
|
| 380 | + function saveOptions($req) { |
|
| 381 | 381 | $this->CFG['time_web'] = $req['time_web']; |
| 382 | 382 | $this->CFG['time_cron'] = $req['time_cron']; |
| 383 | 383 | $this->CFG['backup_path'] = $req['backup_path']; |
@@ -389,28 +389,28 @@ discard block |
||
| 389 | 389 | $this->CFG['confirm'] = $req['confirm']; |
| 390 | 390 | $this->saveCFG(); |
| 391 | 391 | } |
| 392 | - function saveCFG(){ |
|
| 392 | + function saveCFG() { |
|
| 393 | 393 | if (isset($_COOKIE['sxd'])) { |
| 394 | 394 | $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']); |
| 395 | 395 | $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>"); |
| 396 | 396 | } |
| 397 | - if (!$this->virtualize){ |
|
| 397 | + if (!$this->virtualize) { |
|
| 398 | 398 | $this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>"); |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | function runServices($job) { |
| 402 | 402 | $serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR'); |
| 403 | 403 | $add = array('check' => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED')); |
| 404 | - if(isset($serv[$job['type']])) { |
|
| 404 | + if (isset($serv[$job['type']])) { |
|
| 405 | 405 | mysql_select_db($job['db']); |
| 406 | 406 | $filter = $object = array(); |
| 407 | 407 | $this->createFilters($job['obj'], $filter, $object); |
| 408 | 408 | $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
| 409 | 409 | if (!$r) return; |
| 410 | 410 | $tables = array(); |
| 411 | - while($item = mysql_fetch_assoc($r)){ |
|
| 412 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue; |
|
| 413 | - if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`"; |
|
| 411 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 412 | + if (V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue; |
|
| 413 | + if (sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`"; |
|
| 414 | 414 | } |
| 415 | 415 | $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
| 416 | 416 | |
@@ -421,20 +421,20 @@ discard block |
||
| 421 | 421 | $r = mysql_query($sql) or sxd_my_error(); |
| 422 | 422 | if (!$r) return; |
| 423 | 423 | $res = array(); |
| 424 | - while($item = mysql_fetch_row($r)){ |
|
| 424 | + while ($item = mysql_fetch_row($r)) { |
|
| 425 | 425 | $res[] = $item; |
| 426 | 426 | } |
| 427 | - echo 'sxd.result.add(' . sxd_php2json($res). ');'; |
|
| 427 | + echo 'sxd.result.add(' . sxd_php2json($res) . ');'; |
|
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | - function createFilters(&$obj, &$filter, &$object){ |
|
| 430 | + function createFilters(&$obj, &$filter, &$object) { |
|
| 431 | 431 | $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV'); |
| 432 | - foreach($types AS $type){ |
|
| 432 | + foreach ($types AS $type) { |
|
| 433 | 433 | $filter[$type] = array(); |
| 434 | 434 | $object[$type] = array(); |
| 435 | - if(!empty($obj[$type])){ |
|
| 436 | - foreach($obj[$type] AS $v){ |
|
| 437 | - if(strpos($v, '*') !== false) { |
|
| 435 | + if (!empty($obj[$type])) { |
|
| 436 | + foreach ($obj[$type] AS $v) { |
|
| 437 | + if (strpos($v, '*') !== false) { |
|
| 438 | 438 | $filter[$type][] = str_replace('*', '.*?', $v); |
| 439 | 439 | } |
| 440 | 440 | else { |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | - function closeConnect(){ |
|
| 448 | + function closeConnect() { |
|
| 449 | 449 | //return; |
| 450 | 450 | @ignore_user_abort(1); |
| 451 | 451 | header("SXD: {$this->name}"); |
@@ -456,15 +456,15 @@ discard block |
||
| 456 | 456 | @ob_end_flush(); |
| 457 | 457 | @flush(); |
| 458 | 458 | } |
| 459 | - function resumeJob($job){ |
|
| 459 | + function resumeJob($job) { |
|
| 460 | 460 | $this->closeConnect(); |
| 461 | 461 | include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
| 462 | 462 | $this->JOB = &$JOB; |
| 463 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 463 | + if (file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 464 | 464 | $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
| 465 | 465 | $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
| 466 | 466 | $t = fgets($this->fh_rtl); |
| 467 | - if(!empty($t)){ |
|
| 467 | + if (!empty($t)) { |
|
| 468 | 468 | $this->rtl = explode("\t", $t); |
| 469 | 469 | } |
| 470 | 470 | else { |
@@ -492,27 +492,27 @@ discard block |
||
| 492 | 492 | $rows = 0; |
| 493 | 493 | $this->tab_rows = array(); |
| 494 | 494 | $todo = array(); |
| 495 | - foreach($objects AS $t => $list){ |
|
| 496 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 497 | - elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
|
| 495 | + foreach ($objects AS $t => $list) { |
|
| 496 | + if ($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 497 | + elseif (empty($object[$t]) && empty($filter[$t])) {continue; } |
|
| 498 | 498 | if (empty($list)) continue; |
| 499 | 499 | |
| 500 | - foreach($list AS $item){ |
|
| 501 | - switch($t){ |
|
| 500 | + foreach ($list AS $item) { |
|
| 501 | + switch ($t) { |
|
| 502 | 502 | case 'TA': |
| 503 | 503 | $type = ''; |
| 504 | - if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
|
| 504 | + if (sxd_check($item[0], $object['TA'], $filter['TA'])) { |
|
| 505 | 505 | $type = empty($item[1]) ? 'TC' : 'TA'; |
| 506 | 506 | } |
| 507 | - elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 507 | + elseif (sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | 508 | $type = 'TC'; |
| 509 | 509 | } |
| 510 | 510 | else continue; |
| 511 | - $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
|
| 511 | + $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
|
| 512 | 512 | $rows += $type == 'TA' ? $item[1] : 0; |
| 513 | 513 | break; |
| 514 | 514 | default: |
| 515 | - if(sxd_check($item, $object[$t], $filter[$t])) { |
|
| 515 | + if (sxd_check($item, $object[$t], $filter[$t])) { |
|
| 516 | 516 | $todo[$t][] = array($t, $item); |
| 517 | 517 | } |
| 518 | 518 | } |
@@ -522,14 +522,14 @@ discard block |
||
| 522 | 522 | $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
| 523 | 523 | $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
| 524 | 524 | $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
| 525 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 525 | + if (file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 526 | 526 | |
| 527 | 527 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
| 528 | 528 | // Для чужих дампов определяем разделители строк |
| 529 | - if(is_null($this->JOB['obj'])) { |
|
| 529 | + if (is_null($this->JOB['obj'])) { |
|
| 530 | 530 | $s = fread($this->fh_tmp, 2048); |
| 531 | - if(strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n"; |
|
| 532 | - elseif(strpos($s, "\n")) $this->JOB['eol'] = "\n"; |
|
| 531 | + if (strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n"; |
|
| 532 | + elseif (strpos($s, "\n")) $this->JOB['eol'] = "\n"; |
|
| 533 | 533 | else $this->JOB['eol'] = "\r"; |
| 534 | 534 | $bom = strncmp($s, "\xEF\xBB\xBF", 3) == 0 ? 3 : ((strncmp($s, "\xFE\xFF", 2) == 0 || strncmp($s, "\xFF\xFE", 2) == 0) ? 2 : 0); |
| 535 | 535 | fseek($this->fh_tmp, $bom); |
@@ -543,16 +543,16 @@ discard block |
||
| 543 | 543 | $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}"); |
| 544 | 544 | $this->runRestoreJob(); |
| 545 | 545 | } |
| 546 | - function runRestoreJob($continue = false){ |
|
| 546 | + function runRestoreJob($continue = false) { |
|
| 547 | 547 | $ei = false; |
| 548 | - if($continue){ |
|
| 548 | + if ($continue) { |
|
| 549 | 549 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
| 550 | 550 | fseek($this->fh_tmp, $this->rtl[3]); |
| 551 | - if(!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 552 | - if($this->rtl[7] < $this->rtl[10]) $ei = true; |
|
| 551 | + if (!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 552 | + if ($this->rtl[7] < $this->rtl[10]) $ei = true; |
|
| 553 | 553 | } |
| 554 | 554 | mysql_select_db($this->JOB['db']); |
| 555 | - if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 555 | + if (is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 556 | 556 | //mysql_query("SET NAMES 'UTF8'"); |
| 557 | 557 | $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
| 558 | 558 | $fcache = ''; |
@@ -565,34 +565,34 @@ discard block |
||
| 565 | 565 | $this->rtl[1] = time(); |
| 566 | 566 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 567 | 567 | $c = 0; |
| 568 | - switch($this->JOB['strategy']){ |
|
| 568 | + switch ($this->JOB['strategy']) { |
|
| 569 | 569 | case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break; |
| 570 | 570 | case 2: $tc = ''; $td = 'REPLACE'; break; |
| 571 | 571 | case 3: $tc = ''; $td = 'INSERT IGNORE'; break; |
| 572 | 572 | default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT'; |
| 573 | 573 | } |
| 574 | 574 | $tab_exists = array(); |
| 575 | - if($this->JOB['strategy'] > 0){ |
|
| 575 | + if ($this->JOB['strategy'] > 0) { |
|
| 576 | 576 | $r = mysql_query("SHOW TABLES") or sxd_my_error(); |
| 577 | - while($item = mysql_fetch_row($r)){ |
|
| 577 | + while ($item = mysql_fetch_row($r)) { |
|
| 578 | 578 | $tab_exists[$item[0]] = true; |
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | $insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : ''; |
| 582 | 582 | //$enable_index = array(); |
| 583 | - if(V_MYSQL > 40014) { |
|
| 583 | + if (V_MYSQL > 40014) { |
|
| 584 | 584 | mysql_query("SET UNIQUE_CHECKS=0"); |
| 585 | 585 | mysql_query("SET FOREIGN_KEY_CHECKS=0"); |
| 586 | - if(V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 587 | - if(V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0"); |
|
| 586 | + if (V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 587 | + if (V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0"); |
|
| 588 | 588 | } |
| 589 | 589 | $log_sql = false; |
| 590 | 590 | $fields = ''; |
| 591 | 591 | $time_old = time(); |
| 592 | 592 | $exit_time = $time_old + $this->CFG['time_web'] - 1; |
| 593 | - while($q = sxd_read_sql($this->fh_tmp, $seek, $ei)){ |
|
| 594 | - if($time_old < time()) { |
|
| 595 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 593 | + while ($q = sxd_read_sql($this->fh_tmp, $seek, $ei)) { |
|
| 594 | + if ($time_old < time()) { |
|
| 595 | + if (file_exists($this->JOB['file_stp'])) { |
|
| 596 | 596 | $type = file_get_contents($this->JOB['file_stp']); |
| 597 | 597 | $this->rtl[9] = !empty($type) ? $type : 2; |
| 598 | 598 | fseek($this->fh_rtl, 0); |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | exit; |
| 606 | 606 | } |
| 607 | 607 | $time_old = time(); |
| 608 | - if($time_old >= $exit_time){ |
|
| 608 | + if ($time_old >= $exit_time) { |
|
| 609 | 609 | $this->rtl[9] = 3; |
| 610 | 610 | fseek($this->fh_rtl, 0); |
| 611 | 611 | $this->rtl[1] = time(); |
@@ -615,9 +615,9 @@ discard block |
||
| 615 | 615 | } |
| 616 | 616 | clearstatcache(); |
| 617 | 617 | } |
| 618 | - switch($q{0}){ |
|
| 618 | + switch ($q{0}) { |
|
| 619 | 619 | case '(': |
| 620 | - if($continue) { |
|
| 620 | + if ($continue) { |
|
| 621 | 621 | $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
| 622 | 622 | $continue = false; |
| 623 | 623 | } |
@@ -631,12 +631,12 @@ discard block |
||
| 631 | 631 | $tab = $m[2]; |
| 632 | 632 | $this->rtl[7] = 0; |
| 633 | 633 | $this->rtl[8] = 0; |
| 634 | - foreach($this->JOB['todo']['TA'] AS $t){ |
|
| 635 | - if($t[1] == $tab) { |
|
| 634 | + foreach ($this->JOB['todo']['TA'] AS $t) { |
|
| 635 | + if ($t[1] == $tab) { |
|
| 636 | 636 | $this->rtl[8] = $t[2]; |
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | - if($this->JOB['strategy']) { |
|
| 639 | + if ($this->JOB['strategy']) { |
|
| 640 | 640 | $q = substr_replace($q, $insert, 0, strlen($m[0])); |
| 641 | 641 | } |
| 642 | 642 | //mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error()); |
@@ -648,13 +648,13 @@ discard block |
||
| 648 | 648 | case 'C': |
| 649 | 649 | $ex = 1; |
| 650 | 650 | if (preg_match('/^CREATE TABLE `/', $q)) { |
| 651 | - if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 651 | + if ($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | 652 | else { |
| 653 | 653 | $ex = 1; |
| 654 | - if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 654 | + if ((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))) { |
|
| 655 | 655 | $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
| 656 | 656 | } |
| 657 | - if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 657 | + if (!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 658 | 658 | } |
| 659 | 659 | // Достаем имена полей таблицы |
| 660 | 660 | $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
@@ -665,18 +665,18 @@ discard block |
||
| 665 | 665 | //if(!empty($tab)) $enable_index[] = $tab; |
| 666 | 666 | // $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : empty($m[3]) ? '' : $m[3]); |
| 667 | 667 | $this->setNames('binary'); |
| 668 | - if($m[1] == 'TC') { |
|
| 668 | + if ($m[1] == 'TC') { |
|
| 669 | 669 | $this->addLog(sprintf($this->LNG['restore_TC'], $m[2])); |
| 670 | 670 | $insert = ''; |
| 671 | 671 | $tab = ''; |
| 672 | 672 | $this->rtl[4] = 'TD'; |
| 673 | 673 | $this->rtl[5] = $m[2]; |
| 674 | 674 | $ei = 0; |
| 675 | - if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
|
| 675 | + if ($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
|
| 676 | 676 | mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | - elseif($m[1] == 'TD'){ |
|
| 679 | + elseif ($m[1] == 'TD') { |
|
| 680 | 680 | $ei = 1; |
| 681 | 681 | } |
| 682 | 682 | else { |
@@ -695,13 +695,13 @@ discard block |
||
| 695 | 695 | $insert = ''; |
| 696 | 696 | $ex = 1; |
| 697 | 697 | } |
| 698 | - if($ex) { |
|
| 698 | + if ($ex) { |
|
| 699 | 699 | $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
| 700 | 700 | fseek($this->fh_rtl, 0); |
| 701 | 701 | $this->rtl[1] = time(); |
| 702 | 702 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 703 | - if(mysql_query($q)) { |
|
| 704 | - if($insert) { |
|
| 703 | + if (mysql_query($q)) { |
|
| 704 | + if ($insert) { |
|
| 705 | 705 | $c = 1; |
| 706 | 706 | } |
| 707 | 707 | } |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | sxd_my_error(); |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - if($c){ |
|
| 713 | + if ($c) { |
|
| 714 | 714 | $i = mysql_affected_rows(); |
| 715 | 715 | $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
| 716 | 716 | $this->rtl[7] += $i; |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | $this->rtl[6] = ''; |
| 731 | 731 | $this->rtl[7] = 0; |
| 732 | 732 | $this->rtl[8] = 0; |
| 733 | - foreach($this->JOB['todo']['TA'] AS $tab){ |
|
| 733 | + foreach ($this->JOB['todo']['TA'] AS $tab) { |
|
| 734 | 734 | if ($tab[0] == 'TC') continue; |
| 735 | 735 | mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
| 736 | 736 | $this->rtl[1] = time(); |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | fclose($this->fh_log); |
| 748 | 748 | fclose($this->fh_rtl); |
| 749 | 749 | } |
| 750 | - function runRestoreJobForeign($continue = false){ |
|
| 750 | + function runRestoreJobForeign($continue = false) { |
|
| 751 | 751 | $ei = false; |
| 752 | 752 | |
| 753 | 753 | $fcache = ''; |
@@ -768,11 +768,11 @@ discard block |
||
| 768 | 768 | $time_old = time(); |
| 769 | 769 | $exit_time = $time_old + $this->CFG['time_web'] - 1; |
| 770 | 770 | $delimiter = ";"; |
| 771 | - while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
|
| 771 | + while ($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])) { |
|
| 772 | 772 | $q = ltrim($q); |
| 773 | - if(empty($q)) break; |
|
| 774 | - if($time_old < time()) { |
|
| 775 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 773 | + if (empty($q)) break; |
|
| 774 | + if ($time_old < time()) { |
|
| 775 | + if (file_exists($this->JOB['file_stp'])) { |
|
| 776 | 776 | $type = file_get_contents($this->JOB['file_stp']); |
| 777 | 777 | $this->rtl[9] = !empty($type) ? $type : 2; |
| 778 | 778 | fseek($this->fh_rtl, 0); |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | exit; |
| 786 | 786 | } |
| 787 | 787 | $time_old = time(); |
| 788 | - if($time_old >= $exit_time){ |
|
| 788 | + if ($time_old >= $exit_time) { |
|
| 789 | 789 | $this->rtl[9] = 3; |
| 790 | 790 | fseek($this->fh_rtl, 0); |
| 791 | 791 | $this->rtl[1] = time(); |
@@ -799,9 +799,9 @@ discard block |
||
| 799 | 799 | $repeat = false; |
| 800 | 800 | //error_log("-----------------\n[{$q}]\n", 3, "q.log"); |
| 801 | 801 | //if(empty($q)) {continue 2;} |
| 802 | - switch($q{0}){ |
|
| 802 | + switch ($q{0}) { |
|
| 803 | 803 | case '(': |
| 804 | - if($continue) { |
|
| 804 | + if ($continue) { |
|
| 805 | 805 | $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
| 806 | 806 | $continue = false; |
| 807 | 807 | } |
@@ -827,11 +827,11 @@ discard block |
||
| 827 | 827 | $tab = $m[1]; |
| 828 | 828 | $this->addLog(sprintf($this->LNG['restore_TC'], $tab)); |
| 829 | 829 | //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
| 830 | - if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 830 | + if ((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))) { |
|
| 831 | 831 | $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
| 832 | 832 | } |
| 833 | - elseif(empty($this->JOB['charset'])){ |
|
| 834 | - if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
|
| 833 | + elseif (empty($this->JOB['charset'])) { |
|
| 834 | + if (preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)) { |
|
| 835 | 835 | $this->setNames($charset[2]); |
| 836 | 836 | } |
| 837 | 837 | } |
@@ -857,15 +857,15 @@ discard block |
||
| 857 | 857 | $ex = 1; |
| 858 | 858 | $ei = 0; |
| 859 | 859 | } |
| 860 | - } while ($repeat); |
|
| 861 | - if($ex) { |
|
| 860 | + } while ($repeat); |
|
| 861 | + if ($ex) { |
|
| 862 | 862 | $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
| 863 | 863 | fseek($this->fh_rtl, 0); |
| 864 | 864 | $this->rtl[1] = time(); |
| 865 | 865 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 866 | 866 | error_log("-----------------\n{$q}\n", 3, "sql.log"); |
| 867 | - if(mysql_query($q)) { |
|
| 868 | - if($insert) { |
|
| 867 | + if (mysql_query($q)) { |
|
| 868 | + if ($insert) { |
|
| 869 | 869 | $c = 1; |
| 870 | 870 | } |
| 871 | 871 | } |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | sxd_my_error(); |
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - if($c){ |
|
| 877 | + if ($c) { |
|
| 878 | 878 | $i = mysql_affected_rows(); |
| 879 | 879 | $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
| 880 | 880 | $this->rtl[7] += $i; |
@@ -914,37 +914,37 @@ discard block |
||
| 914 | 914 | $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
| 915 | 915 | $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
| 916 | 916 | $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
| 917 | - if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 917 | + if (V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 918 | 918 | } |
| 919 | 919 | $todo = $header = array(); |
| 920 | 920 | $tabs = $rows = 0; |
| 921 | 921 | $only_create = explode(' ', $this->CFG['only_create']); |
| 922 | - foreach($queries AS $query){ |
|
| 922 | + foreach ($queries AS $query) { |
|
| 923 | 923 | $t = $query[2]; |
| 924 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | - elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 924 | + if ($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | + elseif (empty($object[$t]) && empty($filter[$t])) continue; |
|
| 926 | 926 | $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
| 927 | 927 | if (!$r) continue; |
| 928 | 928 | $todo[$t] = array(); |
| 929 | 929 | $header[$t] = array(); |
| 930 | 930 | |
| 931 | - while($item = mysql_fetch_assoc($r)){ |
|
| 931 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 932 | 932 | $n = $item[$query[1]]; |
| 933 | - switch($t){ |
|
| 933 | + switch ($t) { |
|
| 934 | 934 | case 'TA': |
| 935 | 935 | case 'TC': |
| 936 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 937 | - if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 936 | + if (V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 937 | + if (sxd_check($n, $object['VI'], $filter['VI'])) { |
|
| 938 | 938 | $todo['VI'] = array(); |
| 939 | - $header['VI']= array(); |
|
| 939 | + $header['VI'] = array(); |
|
| 940 | 940 | } |
| 941 | 941 | continue; |
| 942 | 942 | } |
| 943 | - elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 943 | + elseif (sxd_check($n, $object['TA'], $filter['TA'])) { |
|
| 944 | 944 | $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
| 945 | 945 | $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
| 946 | 946 | } |
| 947 | - elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 947 | + elseif (sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | 948 | $t = 'TC'; |
| 949 | 949 | $item['Rows'] = $item['Data_length'] = ''; |
| 950 | 950 | } |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | $rows += $item['Rows']; |
| 956 | 956 | break; |
| 957 | 957 | default: |
| 958 | - if(sxd_check($n, $object[$t], $filter[$t])) { |
|
| 958 | + if (sxd_check($n, $object[$t], $filter[$t])) { |
|
| 959 | 959 | $todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : ''); |
| 960 | 960 | $header[$t][] = $n; |
| 961 | 961 | } |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | $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(); |
| 969 | 969 | $views = $dumped = $views_collation = array(); |
| 970 | 970 | $re = "/`{$this->JOB['db']}`.`(.+?)`/"; |
| 971 | - while($item = mysql_fetch_assoc($r)){ |
|
| 971 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 972 | 972 | preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m); |
| 973 | 973 | $used = $m[1]; |
| 974 | 974 | $views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : ''; |
@@ -976,13 +976,13 @@ discard block |
||
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | while (count($views) > 0) { |
| 979 | - foreach($views AS $n => $view) { |
|
| 979 | + foreach ($views AS $n => $view) { |
|
| 980 | 980 | $can_dumped = true; |
| 981 | - foreach($view AS $k) { |
|
| 981 | + foreach ($view AS $k) { |
|
| 982 | 982 | if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
| 983 | 983 | } |
| 984 | 984 | if ($can_dumped) { |
| 985 | - if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 985 | + if (sxd_check($n, $object['VI'], $filter['VI'])) { |
|
| 986 | 986 | $todo['VI'][] = array('VI', $n, $views_collation[$n]); |
| 987 | 987 | $header['VI'][] = $n; |
| 988 | 988 | } |
@@ -999,14 +999,14 @@ discard block |
||
| 999 | 999 | $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
| 1000 | 1000 | $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
| 1001 | 1001 | $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
| 1002 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 1002 | + if (file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 1003 | 1003 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
| 1004 | 1004 | $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']); |
| 1005 | 1005 | $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
| 1006 | 1006 | $this->JOB['todo'] = $todo; |
| 1007 | 1007 | $this->saveJob($this->JOB['job'], $this->JOB); |
| 1008 | 1008 | $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, sxd_esc($this->JOB['comment'], false))) . "\n"; |
| 1009 | - foreach($header AS $t => $o){ |
|
| 1009 | + foreach ($header AS $t => $o) { |
|
| 1010 | 1010 | if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
| 1011 | 1011 | } |
| 1012 | 1012 | $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
@@ -1017,8 +1017,8 @@ discard block |
||
| 1017 | 1017 | $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db'])); |
| 1018 | 1018 | $this->runBackupJob(); |
| 1019 | 1019 | } |
| 1020 | - function runBackupJob($continue = false){ |
|
| 1021 | - if($continue){ |
|
| 1020 | + function runBackupJob($continue = false) { |
|
| 1021 | + if ($continue) { |
|
| 1022 | 1022 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a'); |
| 1023 | 1023 | mysql_select_db($this->JOB['db']); |
| 1024 | 1024 | } |
@@ -1027,14 +1027,14 @@ discard block |
||
| 1027 | 1027 | $fcache = ''; |
| 1028 | 1028 | $writes = 0; |
| 1029 | 1029 | |
| 1030 | - if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1030 | + if (V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') . "'") or sxd_my_error(); |
|
| 1031 | 1031 | $time_old = time(); |
| 1032 | 1032 | $exit_time = $time_old + $this->CFG['time_web'] - 1; |
| 1033 | 1033 | $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
| 1034 | - foreach($this->JOB['todo'] AS $t => $o){ |
|
| 1034 | + foreach ($this->JOB['todo'] AS $t => $o) { |
|
| 1035 | 1035 | if (empty($this->rtl[4])) $this->rtl[4] = $t; |
| 1036 | 1036 | elseif ($this->rtl[4] != $t) continue; |
| 1037 | - foreach($o AS $n){ |
|
| 1037 | + foreach ($o AS $n) { |
|
| 1038 | 1038 | if (empty($this->rtl[5])) { |
| 1039 | 1039 | $this->rtl[5] = $n[1]; |
| 1040 | 1040 | $this->rtl[7] = 0; |
@@ -1042,19 +1042,19 @@ discard block |
||
| 1042 | 1042 | } |
| 1043 | 1043 | elseif ($this->rtl[5] != $n[1]) continue; |
| 1044 | 1044 | // Делаем бэкап |
| 1045 | - switch($n[0]){ |
|
| 1045 | + switch ($n[0]) { |
|
| 1046 | 1046 | case 'TC': |
| 1047 | 1047 | case 'TD': |
| 1048 | 1048 | case 'TA': |
| 1049 | 1049 | $from = ''; |
| 1050 | - if ($n[0] == 'TC' || $this->rtl[7] == 0){ |
|
| 1050 | + if ($n[0] == 'TC' || $this->rtl[7] == 0) { |
|
| 1051 | 1051 | // Бэкап структуры таблицы |
| 1052 | 1052 | $r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error(); |
| 1053 | 1053 | $item = mysql_fetch_assoc($r); |
| 1054 | 1054 | $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
| 1055 | 1055 | $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
| 1056 | 1056 | $this->rtl[7] = 0; |
| 1057 | - if($n[0] == 'TC' || !$n[4]) break; |
|
| 1057 | + if ($n[0] == 'TC' || !$n[4]) break; |
|
| 1058 | 1058 | // Бэкапим данные таблицы |
| 1059 | 1059 | $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
| 1060 | 1060 | } |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | $notNum = array(); |
| 1067 | 1067 | $r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error(); |
| 1068 | 1068 | $fields = 0; |
| 1069 | - while($col = mysql_fetch_array($r)) { |
|
| 1069 | + while ($col = mysql_fetch_array($r)) { |
|
| 1070 | 1070 | // TODO: проверить типы SET, ENUM и BIT |
| 1071 | 1071 | $notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1; |
| 1072 | 1072 | $fields++; |
@@ -1075,22 +1075,22 @@ discard block |
||
| 1075 | 1075 | $z = 0; |
| 1076 | 1076 | // Достаем данные |
| 1077 | 1077 | $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}"); |
| 1078 | - while($row = mysql_fetch_row($r)) { |
|
| 1078 | + while ($row = mysql_fetch_row($r)) { |
|
| 1079 | 1079 | if (strlen($fcache) >= 61440) { |
| 1080 | 1080 | $z = 0; |
| 1081 | - if($time_old < time()) { |
|
| 1082 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 1081 | + if ($time_old < time()) { |
|
| 1082 | + if (file_exists($this->JOB['file_stp'])) { |
|
| 1083 | 1083 | $type = file_get_contents($this->JOB['file_stp']); |
| 1084 | 1084 | $this->rtl[9] = !empty($type) ? $type : 2; |
| 1085 | 1085 | $this->write($fcache); |
| 1086 | - if($type == 1) { |
|
| 1086 | + if ($type == 1) { |
|
| 1087 | 1087 | |
| 1088 | 1088 | } |
| 1089 | 1089 | unset($this->rtl); |
| 1090 | 1090 | exit; |
| 1091 | 1091 | } |
| 1092 | 1092 | $time_old = time(); |
| 1093 | - if($time_old >= $exit_time){ |
|
| 1093 | + if ($time_old >= $exit_time) { |
|
| 1094 | 1094 | $this->rtl[9] = 3; |
| 1095 | 1095 | $this->write($fcache); |
| 1096 | 1096 | unset($this->rtl); |
@@ -1100,9 +1100,9 @@ discard block |
||
| 1100 | 1100 | } |
| 1101 | 1101 | $this->write($fcache); |
| 1102 | 1102 | } |
| 1103 | - for($k = 0; $k < $fields; $k++){ |
|
| 1104 | - if(!isset($row[$k])) {$row[$k] = '\N';} |
|
| 1105 | - elseif($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк |
|
| 1103 | + for ($k = 0; $k < $fields; $k++) { |
|
| 1104 | + if (!isset($row[$k])) {$row[$k] = '\N'; } |
|
| 1105 | + elseif ($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\''; } // TODO: Потестить скорость эскэйпинга строк |
|
| 1106 | 1106 | } |
| 1107 | 1107 | $fcache .= '(' . implode(',', $row) . "),\n"; |
| 1108 | 1108 | $this->rtl[7]++; |
@@ -1110,11 +1110,11 @@ discard block |
||
| 1110 | 1110 | } |
| 1111 | 1111 | unset($row); |
| 1112 | 1112 | mysql_free_result($r); |
| 1113 | - $fcache = substr_replace($fcache, "\t;\n", -2, 2); |
|
| 1113 | + $fcache = substr_replace($fcache, "\t;\n", -2, 2); |
|
| 1114 | 1114 | break; |
| 1115 | 1115 | |
| 1116 | 1116 | default: |
| 1117 | - if(V_MYSQL < 50121 && $n[0] == 'TR'){ |
|
| 1117 | + if (V_MYSQL < 50121 && $n[0] == 'TR') { |
|
| 1118 | 1118 | // SHOW CREATE TRIGGER отсутствует до MySQL 5.1.21 |
| 1119 | 1119 | $r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error(); |
| 1120 | 1120 | $item = mysql_fetch_assoc($r); |
@@ -1141,11 +1141,11 @@ discard block |
||
| 1141 | 1141 | fclose($this->fh_tmp); |
| 1142 | 1142 | rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
| 1143 | 1143 | $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
| 1144 | - if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1144 | + if (file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1145 | 1145 | if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
| 1146 | 1146 | $this->addLog($this->LNG['autodelete']); |
| 1147 | 1147 | $deldate = ''; |
| 1148 | - if (!empty($this->JOB['del_time'])){ // Удаление по дням |
|
| 1148 | + if (!empty($this->JOB['del_time'])) { // Удаление по дням |
|
| 1149 | 1149 | $deldate = date("Y-m-d_H-i-s", time() - intval($this->JOB['del_time']) * 86400); |
| 1150 | 1150 | } |
| 1151 | 1151 | $deleted = false; |
@@ -1155,72 +1155,72 @@ discard block |
||
| 1155 | 1155 | while (false !== ($file = readdir($dh))) { |
| 1156 | 1156 | if (preg_match("/^{$name}_(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})\.sql/", $file, $m)) { |
| 1157 | 1157 | if ($deldate && $m[1] < $deldate) { |
| 1158 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file)); |
|
| 1158 | + if (unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file)); |
|
| 1159 | 1159 | else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
| 1160 | 1160 | $deleted = true; |
| 1161 | 1161 | } |
| 1162 | - else {$files[$m[1]] = $file;} |
|
| 1162 | + else {$files[$m[1]] = $file; } |
|
| 1163 | 1163 | } |
| 1164 | 1164 | } |
| 1165 | 1165 | closedir($dh); |
| 1166 | 1166 | // Сортируем файлы по дате и удаляем самые старые |
| 1167 | - if (!empty($this->JOB['del_count'])){ |
|
| 1167 | + if (!empty($this->JOB['del_count'])) { |
|
| 1168 | 1168 | ksort($files); |
| 1169 | 1169 | $file_to_delete = count($files) - $this->JOB['del_count']; |
| 1170 | - foreach ($files AS $file){ |
|
| 1171 | - if ($file_to_delete-- > 0){ |
|
| 1172 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1170 | + foreach ($files AS $file) { |
|
| 1171 | + if ($file_to_delete-- > 0) { |
|
| 1172 | + if (unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1173 | 1173 | else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
| 1174 | 1174 | $deleted = true; |
| 1175 | 1175 | } |
| 1176 | 1176 | } |
| 1177 | 1177 | } |
| 1178 | 1178 | } |
| 1179 | - if(!$deleted) $this->addLog($this->LNG['del_nothing']); |
|
| 1179 | + if (!$deleted) $this->addLog($this->LNG['del_nothing']); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | fclose($this->fh_log); |
| 1182 | 1182 | fclose($this->fh_rtl); |
| 1183 | 1183 | } |
| 1184 | - function setNames($collation){ |
|
| 1185 | - if(empty($collation)) return; |
|
| 1186 | - if($this->rtl[6] != $collation) { |
|
| 1184 | + function setNames($collation) { |
|
| 1185 | + if (empty($collation)) return; |
|
| 1186 | + if ($this->rtl[6] != $collation) { |
|
| 1187 | 1187 | mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
| 1188 | 1188 | /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
| 1189 | 1189 | $this->rtl[6] = $collation; |
| 1190 | 1190 | } |
| 1191 | 1191 | } |
| 1192 | - function write(&$str){ |
|
| 1192 | + function write(&$str) { |
|
| 1193 | 1193 | fseek($this->fh_rtl, 0); |
| 1194 | 1194 | $this->rtl[1] = time(); |
| 1195 | 1195 | $this->rtl[3] += fwrite($this->fh_tmp, $str); |
| 1196 | 1196 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 1197 | 1197 | $str = ''; |
| 1198 | 1198 | } |
| 1199 | - function addLog($str, $type = 1){ |
|
| 1199 | + function addLog($str, $type = 1) { |
|
| 1200 | 1200 | fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n"); |
| 1201 | 1201 | } |
| 1202 | - function getDBList(){ |
|
| 1202 | + function getDBList() { |
|
| 1203 | 1203 | $dbs = $items = array(); |
| 1204 | 1204 | if (!V_MYSQL) return $dbs; |
| 1205 | 1205 | $qq = (V_MYSQL < 50000) ? '' : '\''; |
| 1206 | 1206 | if ($this->CFG['my_db']) { |
| 1207 | 1207 | $tmp = explode(',', $this->CFG['my_db']); |
| 1208 | - foreach($tmp AS $d){ |
|
| 1208 | + foreach ($tmp AS $d) { |
|
| 1209 | 1209 | $d = trim($d); |
| 1210 | 1210 | $items[] = $qq . sxd_esc($d, false) . $qq; |
| 1211 | 1211 | $dbs[$d] = "{$d} (0)"; |
| 1212 | 1212 | } |
| 1213 | 1213 | } |
| 1214 | - else{ |
|
| 1214 | + else { |
|
| 1215 | 1215 | $result = mysql_query("SHOW DATABASES") or sxd_my_error(); |
| 1216 | - while($item = mysql_fetch_row($result)){ |
|
| 1217 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1216 | + while ($item = mysql_fetch_row($result)) { |
|
| 1217 | + if ($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1218 | 1218 | $items[] = $qq . sxd_esc($item[0], false) . $qq; |
| 1219 | 1219 | $dbs[$item[0]] = "{$item[0]} (0)"; |
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | - if(V_MYSQL < 50000){ |
|
| 1223 | - foreach($items AS $item){ |
|
| 1222 | + if (V_MYSQL < 50000) { |
|
| 1223 | + foreach ($items AS $item) { |
|
| 1224 | 1224 | $tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error(); |
| 1225 | 1225 | if ($tables) { |
| 1226 | 1226 | $tabs = mysql_num_rows($tables); |
@@ -1231,59 +1231,59 @@ discard block |
||
| 1231 | 1231 | else { |
| 1232 | 1232 | $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
| 1233 | 1233 | $result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error(); |
| 1234 | - while($item = mysql_fetch_row($result)){ |
|
| 1235 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1234 | + while ($item = mysql_fetch_row($result)) { |
|
| 1235 | + if ($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1236 | 1236 | $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
| 1237 | 1237 | } |
| 1238 | 1238 | } |
| 1239 | 1239 | return $dbs; |
| 1240 | 1240 | } |
| 1241 | - function getCharsetList(){ |
|
| 1241 | + function getCharsetList() { |
|
| 1242 | 1242 | $tmp = array(0 => '- auto -'); |
| 1243 | 1243 | if (!V_MYSQL) return $tmp; |
| 1244 | - if(V_MYSQL > 40101) { |
|
| 1244 | + if (V_MYSQL > 40101) { |
|
| 1245 | 1245 | $def_charsets = ''; |
| 1246 | - if(!empty($this->CFG['charsets'])){ |
|
| 1247 | - $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1246 | + if (!empty($this->CFG['charsets'])) { |
|
| 1247 | + $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?', '*'), array('.', '\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
| 1250 | 1250 | if ($r) { |
| 1251 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1251 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 1252 | 1252 | if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
| 1253 | 1253 | } |
| 1254 | 1254 | } |
| 1255 | 1255 | } |
| 1256 | 1256 | return $tmp; |
| 1257 | 1257 | } |
| 1258 | - function getCollationList(){ |
|
| 1258 | + function getCollationList() { |
|
| 1259 | 1259 | $tmp = array(); |
| 1260 | 1260 | if (!V_MYSQL) return $tmp; |
| 1261 | - if(V_MYSQL > 40101) { |
|
| 1261 | + if (V_MYSQL > 40101) { |
|
| 1262 | 1262 | $def_charsets = ''; |
| 1263 | - if(!empty($this->CFG['charsets'])){ |
|
| 1264 | - $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1263 | + if (!empty($this->CFG['charsets'])) { |
|
| 1264 | + $def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?', '*'), array('.', '\w+?'), implode('|', $m[1])) . ')$/i' : ''; |
|
| 1265 | 1265 | } |
| 1266 | 1266 | $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
| 1267 | 1267 | if ($r) { |
| 1268 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1268 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 1269 | 1269 | if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
| 1270 | 1270 | } |
| 1271 | 1271 | } |
| 1272 | 1272 | } |
| 1273 | 1273 | return $tmp; |
| 1274 | 1274 | } |
| 1275 | - function getObjects($tree, $db_name){ |
|
| 1275 | + function getObjects($tree, $db_name) { |
|
| 1276 | 1276 | mysql_select_db($db_name); |
| 1277 | 1277 | // Достаем таблицы |
| 1278 | 1278 | $r = mysql_query('SHOW TABLE STATUS'); |
| 1279 | 1279 | $tab_prefix_last = $tab_prefix = '*'; |
| 1280 | 1280 | $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
| 1281 | - if($r){ |
|
| 1282 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1283 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 1284 | - $objects['VI'][]= $item['Name']; |
|
| 1281 | + if ($r) { |
|
| 1282 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 1283 | + if (V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 1284 | + $objects['VI'][] = $item['Name']; |
|
| 1285 | 1285 | } |
| 1286 | - else{ |
|
| 1286 | + else { |
|
| 1287 | 1287 | $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
| 1288 | 1288 | } |
| 1289 | 1289 | } |
@@ -1294,14 +1294,14 @@ discard block |
||
| 1294 | 1294 | "FUNCTION STATUS WHERE db='{$db_name}'", |
| 1295 | 1295 | 'TRIGGERS' |
| 1296 | 1296 | ); |
| 1297 | - if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1297 | + if (V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1298 | 1298 | // TODO: Поправить проверку событий и триггеров |
| 1299 | - for($i = 0, $l = count($shows); $i < $l; $i++){ |
|
| 1299 | + for ($i = 0, $l = count($shows); $i < $l; $i++) { |
|
| 1300 | 1300 | $r = mysql_query('SHOW ' . $shows[$i]); |
| 1301 | - if($r && mysql_num_rows($r) > 0) { |
|
| 1301 | + if ($r && mysql_num_rows($r) > 0) { |
|
| 1302 | 1302 | $col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name'; |
| 1303 | 1303 | $type = substr($shows[$i], 0, 2); |
| 1304 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1304 | + while ($item = mysql_fetch_assoc($r)) { |
|
| 1305 | 1305 | $objects[$type][] = $item[$col_name]; |
| 1306 | 1306 | } |
| 1307 | 1307 | } |
@@ -1313,32 +1313,32 @@ discard block |
||
| 1313 | 1313 | } |
| 1314 | 1314 | return $this->formatTree($tree, $objects); |
| 1315 | 1315 | } |
| 1316 | - function getFileObjects($tree, $name, $formatTree = true){ |
|
| 1316 | + function getFileObjects($tree, $name, $formatTree = true) { |
|
| 1317 | 1317 | // Достаем таблицы |
| 1318 | 1318 | $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
| 1319 | - if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return ''; |
|
| 1319 | + if (!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return ''; |
|
| 1320 | 1320 | $name = $this->CFG['backup_path'] . $name; |
| 1321 | - if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
|
| 1321 | + if (!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))"; } |
|
| 1322 | 1322 | $fp = $this->openFile($name, 'r'); |
| 1323 | 1323 | $temp = fread($fp, 60000); |
| 1324 | 1324 | // Формат файла Sypex Dumper 2 - SXD20 |
| 1325 | 1325 | //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;"; |
| 1326 | - if(preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)){ |
|
| 1326 | + if (preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)) { |
|
| 1327 | 1327 | $head = explode("\n", $m[1]); |
| 1328 | 1328 | $h = explode('|', $head[0]); |
| 1329 | - for($i = 1, $c = count($head); $i < $c; $i++){ |
|
| 1330 | - $objects[substr($head[$i], 1,2)] = explode('|', substr($head[$i], 4)); |
|
| 1329 | + for ($i = 1, $c = count($head); $i < $c; $i++) { |
|
| 1330 | + $objects[substr($head[$i], 1, 2)] = explode('|', substr($head[$i], 4)); |
|
| 1331 | 1331 | } |
| 1332 | - for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1332 | + for ($i = 0, $l = count($objects['TA']); $i < $l; $i++) { |
|
| 1333 | 1333 | $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
| 1334 | 1334 | } |
| 1335 | 1335 | } |
| 1336 | 1336 | else { |
| 1337 | 1337 | $h[9] = ''; |
| 1338 | 1338 | } |
| 1339 | - return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
|
| 1339 | + return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
|
| 1340 | 1340 | } |
| 1341 | - function formatTree($tree, &$objects){ |
|
| 1341 | + function formatTree($tree, &$objects) { |
|
| 1342 | 1342 | $obj = ''; |
| 1343 | 1343 | $pid = $row = 1; |
| 1344 | 1344 | $info = array( |
@@ -1351,7 +1351,7 @@ discard block |
||
| 1351 | 1351 | ); |
| 1352 | 1352 | // Находим таблицы с префиксами |
| 1353 | 1353 | $tab_prefix_last = $tab_prefix = '*'; |
| 1354 | - for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1354 | + for ($i = 0, $l = count($objects['TA']); $i < $l; $i++) { |
|
| 1355 | 1355 | $t = $objects['TA'][$i]; |
| 1356 | 1356 | $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
| 1357 | 1357 | if ($tab_prefix != $tab_prefix_last) { |
@@ -1361,18 +1361,18 @@ discard block |
||
| 1361 | 1361 | $objects['TA'][$tab_prefix][] = $t; |
| 1362 | 1362 | unset($objects['TA'][$i]); |
| 1363 | 1363 | } |
| 1364 | - foreach($objects AS $type => $o){ |
|
| 1365 | - if(!count($o)) continue; |
|
| 1366 | - if($type == 'TA') { |
|
| 1364 | + foreach ($objects AS $type => $o) { |
|
| 1365 | + if (!count($o)) continue; |
|
| 1366 | + if ($type == 'TA') { |
|
| 1367 | 1367 | $open_childs = count($o['*']) > 1 ? 0 : 1; |
| 1368 | 1368 | $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
| 1369 | 1369 | $row++; |
| 1370 | - foreach($o['*'] AS $value){ |
|
| 1371 | - if(is_string($value)){ |
|
| 1372 | - if(count($o[$value]) > 1) { |
|
| 1370 | + foreach ($o['*'] AS $value) { |
|
| 1371 | + if (is_string($value)) { |
|
| 1372 | + if (count($o[$value]) > 1) { |
|
| 1373 | 1373 | $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],"; |
| 1374 | 1374 | $pid = $row++; |
| 1375 | - for($i = 0, $l = count($o[$value]); $i < $l; $i++){ |
|
| 1375 | + for ($i = 0, $l = count($o[$value]); $i < $l; $i++) { |
|
| 1376 | 1376 | $checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1; |
| 1377 | 1377 | $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
| 1378 | 1378 | $row++; |
@@ -1383,7 +1383,7 @@ discard block |
||
| 1383 | 1383 | } |
| 1384 | 1384 | } |
| 1385 | 1385 | //$pid = 1; |
| 1386 | - if (is_array($value)){ |
|
| 1386 | + if (is_array($value)) { |
|
| 1387 | 1387 | $checked = ($value[1] == '' && $value[2] == '') ? 2 : 1; |
| 1388 | 1388 | $obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],"; |
| 1389 | 1389 | $row++; |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
| 1395 | 1395 | $pid = $row++; |
| 1396 | 1396 | $info[$type][1]++; |
| 1397 | - for($i = 0, $l = count($o); $i < $l; $i++){ |
|
| 1397 | + for ($i = 0, $l = count($o); $i < $l; $i++) { |
|
| 1398 | 1398 | $o[$i] = sxd_esc($o[$i], false); |
| 1399 | 1399 | $obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],"; |
| 1400 | 1400 | $row++; |
@@ -1402,10 +1402,10 @@ discard block |
||
| 1402 | 1402 | } |
| 1403 | 1403 | } |
| 1404 | 1404 | $add = ''; |
| 1405 | - if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1406 | - return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add; |
|
| 1405 | + if ($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1406 | + return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add; |
|
| 1407 | 1407 | } |
| 1408 | - function getFileList(){ |
|
| 1408 | + function getFileList() { |
|
| 1409 | 1409 | $files = array(); |
| 1410 | 1410 | if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
| 1411 | 1411 | while (false !== ($file = readdir($handle))) { |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | ksort($files); |
| 1419 | 1419 | return $files; |
| 1420 | 1420 | } |
| 1421 | - function getSavedJobs(){ |
|
| 1421 | + function getSavedJobs() { |
|
| 1422 | 1422 | $sj = array('sj_backup' => array(), 'sj_restore' => array(),); |
| 1423 | 1423 | if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
| 1424 | 1424 | while (false !== ($file = readdir($handle))) { |
@@ -1429,13 +1429,13 @@ discard block |
||
| 1429 | 1429 | } |
| 1430 | 1430 | closedir($handle); |
| 1431 | 1431 | } |
| 1432 | - if(count($sj['sj_backup']) > 0){ |
|
| 1432 | + if (count($sj['sj_backup']) > 0) { |
|
| 1433 | 1433 | ksort($sj['sj_backup']); |
| 1434 | 1434 | } |
| 1435 | 1435 | else { |
| 1436 | 1436 | $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
| 1437 | 1437 | } |
| 1438 | - if(count($sj['sj_restore']) > 0){ |
|
| 1438 | + if (count($sj['sj_restore']) > 0) { |
|
| 1439 | 1439 | ksort($sj['sj_restore']); |
| 1440 | 1440 | } |
| 1441 | 1441 | else { |
@@ -1443,7 +1443,7 @@ discard block |
||
| 1443 | 1443 | } |
| 1444 | 1444 | return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
| 1445 | 1445 | } |
| 1446 | - function getFileListExtended(){ |
|
| 1446 | + function getFileListExtended() { |
|
| 1447 | 1447 | $files = array(); |
| 1448 | 1448 | if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
| 1449 | 1449 | while (false !== ($file = readdir($handle))) { |
@@ -1451,11 +1451,11 @@ discard block |
||
| 1451 | 1451 | $fp = $this->openFile($this->CFG['backup_path'] . $file, 'r'); |
| 1452 | 1452 | $ext = !empty($m[2]) ? $m[2] : 'sql'; |
| 1453 | 1453 | $temp = fgets($fp); |
| 1454 | - if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){ |
|
| 1454 | + if (preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)) { |
|
| 1455 | 1455 | $h = explode('|', $m[1]); |
| 1456 | 1456 | $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); |
| 1457 | 1457 | } |
| 1458 | - elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1458 | + elseif (preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)) { |
|
| 1459 | 1459 | $h = explode('|', $m[1]); |
| 1460 | 1460 | $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); |
| 1461 | 1461 | } |
@@ -1466,27 +1466,27 @@ discard block |
||
| 1466 | 1466 | } |
| 1467 | 1467 | closedir($handle); |
| 1468 | 1468 | } |
| 1469 | - function s($a, $b){ |
|
| 1469 | + function s($a, $b) { |
|
| 1470 | 1470 | return strcmp($b[1], $a[1]); |
| 1471 | 1471 | } |
| 1472 | 1472 | usort($files, 's'); |
| 1473 | 1473 | return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');'; |
| 1474 | 1474 | } |
| 1475 | - function saveJob($job, $config){ |
|
| 1475 | + function saveJob($job, $config) { |
|
| 1476 | 1476 | $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
| 1477 | 1477 | } |
| 1478 | - function openFile($name, $mode){ |
|
| 1479 | - if($mode == 'r') { |
|
| 1480 | - if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1478 | + function openFile($name, $mode) { |
|
| 1479 | + if ($mode == 'r') { |
|
| 1480 | + if (preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1481 | 1481 | } |
| 1482 | - else{ |
|
| 1483 | - switch($this->JOB['zip']) { |
|
| 1482 | + else { |
|
| 1483 | + switch ($this->JOB['zip']) { |
|
| 1484 | 1484 | case 0 : $this->JOB['file_ext'] = 'sql'; break; |
| 1485 | 1485 | case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
| 1486 | 1486 | default: $this->JOB['file_ext'] = 'sql.gz'; break; |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
| 1489 | - switch ($this->JOB['file_ext']){ |
|
| 1489 | + switch ($this->JOB['file_ext']) { |
|
| 1490 | 1490 | case 'sql': |
| 1491 | 1491 | return fopen($name, "{$mode}b"); |
| 1492 | 1492 | break; |
@@ -1500,28 +1500,28 @@ discard block |
||
| 1500 | 1500 | } |
| 1501 | 1501 | } |
| 1502 | 1502 | } |
| 1503 | -function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n"){ |
|
| 1503 | +function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n") { |
|
| 1504 | 1504 | static $l = ''; |
| 1505 | 1505 | static $r = 0; |
| 1506 | 1506 | $fs = ftell($f); |
| 1507 | 1507 | $delim_len = strlen($delimiter . $eol); |
| 1508 | - while($r || $s = fread($f, 61440)){ |
|
| 1509 | - if(!$r) $l .= $s; |
|
| 1508 | + while ($r || $s = fread($f, 61440)) { |
|
| 1509 | + if (!$r) $l .= $s; |
|
| 1510 | 1510 | $pos = strpos($l, $delimiter . $eol); |
| 1511 | 1511 | if ($pos !== false) { |
| 1512 | 1512 | // Есть окончание запроса |
| 1513 | 1513 | $q = substr($l, 0, $pos); |
| 1514 | - $l = substr($l, $pos+$delim_len); |
|
| 1514 | + $l = substr($l, $pos + $delim_len); |
|
| 1515 | 1515 | $r = 1; |
| 1516 | 1516 | $seek = strlen($l); |
| 1517 | 1517 | return $q; |
| 1518 | 1518 | } |
| 1519 | - if($ei) { |
|
| 1519 | + if ($ei) { |
|
| 1520 | 1520 | $pos = strrpos($l, $eol); |
| 1521 | - if($pos > 0 && $l{$pos-1} === ',') { |
|
| 1521 | + if ($pos > 0 && $l{$pos - 1} === ',') { |
|
| 1522 | 1522 | // Окончание не найдено |
| 1523 | - $q = substr($l, 0, $pos-1); |
|
| 1524 | - $l = substr($l, $pos+ strlen($eol)); |
|
| 1523 | + $q = substr($l, 0, $pos - 1); |
|
| 1524 | + $l = substr($l, $pos + strlen($eol)); |
|
| 1525 | 1525 | $seek = strlen($l); |
| 1526 | 1526 | $r = 0; |
| 1527 | 1527 | return $q; |
@@ -1534,16 +1534,16 @@ discard block |
||
| 1534 | 1534 | } |
| 1535 | 1535 | return false; |
| 1536 | 1536 | } |
| 1537 | -function sxd_check($n, $obj, $filt){ |
|
| 1537 | +function sxd_check($n, $obj, $filt) { |
|
| 1538 | 1538 | return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
| 1539 | 1539 | } |
| 1540 | -function sxd_php2json($obj){ |
|
| 1541 | - if(count($obj) == 0) return '[]'; |
|
| 1540 | +function sxd_php2json($obj) { |
|
| 1541 | + if (count($obj) == 0) return '[]'; |
|
| 1542 | 1542 | $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
| 1543 | 1543 | $str = $is_obj ? '{' : '['; |
| 1544 | 1544 | foreach ($obj AS $key => $value) { |
| 1545 | 1545 | $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
| 1546 | - if (is_array($value)) $str .= sxd_php2json($value); |
|
| 1546 | + if (is_array($value)) $str .= sxd_php2json($value); |
|
| 1547 | 1547 | elseif (is_null($value)) $str .= 'null'; |
| 1548 | 1548 | elseif (is_bool($value)) $str .= $value ? 'true' : 'false'; |
| 1549 | 1549 | elseif (is_numeric($value)) $str .= $value; |
@@ -1552,27 +1552,27 @@ discard block |
||
| 1552 | 1552 | } |
| 1553 | 1553 | return substr_replace($str, $is_obj ? '}' : ']', -1); |
| 1554 | 1554 | } |
| 1555 | -function sxd_ver2int($ver){ |
|
| 1555 | +function sxd_ver2int($ver) { |
|
| 1556 | 1556 | return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
| 1557 | 1557 | } |
| 1558 | -function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){ |
|
| 1558 | +function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars) { |
|
| 1559 | 1559 | global $SXD; |
| 1560 | - if($SXD->try) return; |
|
| 1561 | - if($errno == 8192) return; |
|
| 1562 | - if(strpos($errmsg, 'timezone settings')) return; |
|
| 1560 | + if ($SXD->try) return; |
|
| 1561 | + if ($errno == 8192) return; |
|
| 1562 | + if (strpos($errmsg, 'timezone settings')) return; |
|
| 1563 | 1563 | $errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', |
| 1564 | 1564 | 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
| 1565 | 1565 | 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
| 1566 | 1566 | $str = sxd_esc("{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})", false); |
| 1567 | - if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1567 | + if (SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1568 | 1568 | |
| 1569 | - if($errno == 8 || $errno == 1024) { |
|
| 1569 | + if ($errno == 8 || $errno == 1024) { |
|
| 1570 | 1570 | if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
| 1571 | 1571 | else { |
| 1572 | 1572 | fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
| 1573 | 1573 | } |
| 1574 | 1574 | } |
| 1575 | - elseif($errno < 1024) { |
|
| 1575 | + elseif ($errno < 1024) { |
|
| 1576 | 1576 | $SXD->error = true; |
| 1577 | 1577 | if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
| 1578 | 1578 | else { |
@@ -1587,17 +1587,17 @@ discard block |
||
| 1587 | 1587 | die; |
| 1588 | 1588 | } |
| 1589 | 1589 | } |
| 1590 | -function sxd_esc($str, $quoted = true){ |
|
| 1590 | +function sxd_esc($str, $quoted = true) { |
|
| 1591 | 1591 | return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'"); |
| 1592 | 1592 | } |
| 1593 | -function sxd_my_error(){ |
|
| 1593 | +function sxd_my_error() { |
|
| 1594 | 1594 | trigger_error(mysql_error(), E_USER_ERROR); |
| 1595 | 1595 | } |
| 1596 | -function sxd_shutdown(){ |
|
| 1596 | +function sxd_shutdown() { |
|
| 1597 | 1597 | global $SXD; |
| 1598 | - if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
|
| 1598 | + if (isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
|
| 1599 | 1599 | $SXD->rtl[1] = time(); |
| 1600 | - if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
|
| 1600 | + if (!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])) { |
|
| 1601 | 1601 | $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
| 1602 | 1602 | $SXD->rtl[9] = !empty($type) ? $type : 2; |
| 1603 | 1603 | } |
@@ -1606,6 +1606,6 @@ discard block |
||
| 1606 | 1606 | fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
| 1607 | 1607 | } |
| 1608 | 1608 | } |
| 1609 | -function sxd_antimagic($arr){ |
|
| 1609 | +function sxd_antimagic($arr) { |
|
| 1610 | 1610 | return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr); |
| 1611 | 1611 | } |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | header("Content-Type: text/html; charset=utf-8"); |
| 15 | 15 | //error_reporting(E_ALL); |
| 16 | 16 | error_reporting(0); |
| 17 | -if (!ini_get('zlib.output_compression') && function_exists('ob_gzhandler')) ob_start('ob_gzhandler'); |
|
| 17 | +if (!ini_get('zlib.output_compression') && function_exists('ob_gzhandler')) { |
|
| 18 | + ob_start('ob_gzhandler'); |
|
| 19 | +} |
|
| 18 | 20 | set_error_handler('sxd_error_handler'); |
| 19 | 21 | register_shutdown_function('sxd_shutdown'); |
| 20 | 22 | $SXD = new Sypex_Dumper(); |
@@ -47,8 +49,11 @@ discard block |
||
| 47 | 49 | } |
| 48 | 50 | } |
| 49 | 51 | } |
| 50 | - if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php"); |
|
| 51 | - else include("lang/lng_en.php"); |
|
| 52 | + if(file_exists("lang/lng_{$lng_name}.php")) { |
|
| 53 | + include("lang/lng_{$lng_name}.php"); |
|
| 54 | + } else { |
|
| 55 | + include("lang/lng_en.php"); |
|
| 56 | + } |
|
| 52 | 57 | $this->LNG = &$LNG; |
| 53 | 58 | $this->LNG['name'] = $lng_name; |
| 54 | 59 | return true; |
@@ -59,8 +64,11 @@ discard block |
||
| 59 | 64 | } |
| 60 | 65 | include('cfg.php'); |
| 61 | 66 | $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'); |
|
| 67 | + if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 68 | + @set_time_limit($CFG['time_web']); |
|
| 69 | + } elseif (ini_get('max_execution_time') < $CFG['time_web']) { |
|
| 70 | + $CFG['time_web'] = ini_get('max_execution_time'); |
|
| 71 | + } |
|
| 64 | 72 | $this->CFG = &$CFG; |
| 65 | 73 | $this->try = false; |
| 66 | 74 | $this->virtualize = false; |
@@ -93,13 +101,17 @@ discard block |
||
| 93 | 101 | if($auth && !empty($this->CFG['sjob'])){ |
| 94 | 102 | $this->ajax($this->loadJob($this->CFG['sjob'])); |
| 95 | 103 | echo file_get_contents($this->JOB['file_log']); |
| 96 | - if(file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']); |
|
| 97 | - if(file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']); |
|
| 104 | + if(file_exists($this->JOB['file_log'])) { |
|
| 105 | + unlink($this->JOB['file_log']); |
|
| 106 | + } |
|
| 107 | + if(file_exists($this->JOB['file_rtl'])) { |
|
| 108 | + unlink($this->JOB['file_rtl']); |
|
| 109 | + } |
|
| 110 | + } else { |
|
| 111 | + echo 'Auth error'; |
|
| 98 | 112 | } |
| 99 | - else echo 'Auth error'; |
|
| 100 | 113 | exit; |
| 101 | - } |
|
| 102 | - elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 114 | + } elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 103 | 115 | $auth = false; |
| 104 | 116 | $sfile = 'ses.php'; |
| 105 | 117 | |
@@ -129,18 +141,25 @@ discard block |
||
| 129 | 141 | $auth = $this->connect($host, $port, $user, $pass); |
| 130 | 142 | break; |
| 131 | 143 | default: $file = 'auth_' . $a . '.php'; |
| 132 | - if(!file_exists($file)) continue; |
|
| 144 | + if(!file_exists($file)) { |
|
| 145 | + continue; |
|
| 146 | + } |
|
| 133 | 147 | include $file; |
| 134 | 148 | } |
| 135 | - if($auth) break; |
|
| 149 | + if($auth) { |
|
| 150 | + break; |
|
| 151 | + } |
|
| 136 | 152 | } |
| 137 | 153 | if($auth){ |
| 138 | 154 | $key = md5(rand(1,100000) . $user . microtime()); |
| 139 | 155 | $CFG['lang'] = $this->LNG['name']; |
| 140 | 156 | $_COOKIE['sxd'] = $key; |
| 141 | 157 | $this->saveCFG(); |
| 142 | - if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | - else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 158 | + if(V_PHP > 50200) { |
|
| 159 | + setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 160 | + } else { |
|
| 161 | + setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 162 | + } |
|
| 144 | 163 | header("Location: ./"); |
| 145 | 164 | exit; |
| 146 | 165 | } |
@@ -164,9 +183,15 @@ discard block |
||
| 164 | 183 | exit; |
| 165 | 184 | } |
| 166 | 185 | } |
| 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();exit; |
|
| 186 | + if(empty($_POST['ajax']['act']) || $_POST['ajax']['act'] != 'save_connect') { |
|
| 187 | + $this->connect(); |
|
| 188 | + } |
|
| 189 | + if(isset($_POST['ajax'])) { |
|
| 190 | + $this->ajax($_POST['ajax']); |
|
| 191 | + } else { |
|
| 192 | + $this->main(); |
|
| 193 | + } |
|
| 194 | + exit; |
|
| 170 | 195 | } |
| 171 | 196 | function saveToFile($name, $content){ |
| 172 | 197 | $fp = fopen($name, "w"); |
@@ -183,11 +208,13 @@ discard block |
||
| 183 | 208 | $this->CFG['my_pass'] = $pass; |
| 184 | 209 | } |
| 185 | 210 | 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 | - if(V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error(); |
|
| 187 | - else mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 211 | + if(V_PHP > 50202) { |
|
| 212 | + mysql_set_charset('utf8') or sxd_my_error(); |
|
| 213 | + } else { |
|
| 214 | + mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 215 | + } |
|
| 188 | 216 | define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
| 189 | - } |
|
| 190 | - else { |
|
| 217 | + } else { |
|
| 191 | 218 | define('V_MYSQL', 0); |
| 192 | 219 | $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
| 193 | 220 | } |
@@ -240,7 +267,9 @@ discard block |
||
| 240 | 267 | $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) . |
| 241 | 268 | $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset') |
| 242 | 269 | ; |
| 243 | - if (!V_MYSQL) $this->VAR['combos'] .= $this->error; |
|
| 270 | + if (!V_MYSQL) { |
|
| 271 | + $this->VAR['combos'] .= $this->error; |
|
| 272 | + } |
|
| 244 | 273 | $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();"; |
| 245 | 274 | $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">'); |
| 246 | 275 | $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">'); |
@@ -298,7 +327,9 @@ discard block |
||
| 298 | 327 | case 'delete_file': |
| 299 | 328 | if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
| 300 | 329 | $file = $this->CFG['backup_path'] . $req['name']; |
| 301 | - if(file_exists($file)) unlink($file); |
|
| 330 | + if(file_exists($file)) { |
|
| 331 | + unlink($file); |
|
| 332 | + } |
|
| 302 | 333 | } |
| 303 | 334 | $res = $this->getFileListExtended(); |
| 304 | 335 | break; |
@@ -329,7 +360,9 @@ discard block |
||
| 329 | 360 | } |
| 330 | 361 | function loadJob($job){ |
| 331 | 362 | $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
| 332 | - if(!file_exists($file)) return; |
|
| 363 | + if(!file_exists($file)) { |
|
| 364 | + return; |
|
| 365 | + } |
|
| 333 | 366 | include($file); |
| 334 | 367 | $JOB['act'] = $JOB['type']; |
| 335 | 368 | $JOB['type'] = 'run'; |
@@ -339,9 +372,9 @@ discard block |
||
| 339 | 372 | $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
| 340 | 373 | if($r){ |
| 341 | 374 | echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
| 342 | - } |
|
| 343 | - else |
|
| 344 | - echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 375 | + } else { |
|
| 376 | + echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 377 | + } |
|
| 345 | 378 | } |
| 346 | 379 | function cfg2js($cfg){ |
| 347 | 380 | foreach($cfg AS $k => $v){ |
@@ -351,16 +384,19 @@ discard block |
||
| 351 | 384 | } |
| 352 | 385 | function addDb($req){ |
| 353 | 386 | $r = mysql_query('CREATE DATABASE `' . sxd_esc($req['name'], false) . '`' . (V_MYSQL > 40100 ? "CHARACTER SET {$req['charset']} COLLATE {$req['collate']}" : '')); |
| 354 | - if($r) |
|
| 355 | - echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 356 | - else |
|
| 357 | - sxd_my_error(); |
|
| 387 | + if($r) { |
|
| 388 | + echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 389 | + } else { |
|
| 390 | + sxd_my_error(); |
|
| 391 | + } |
|
| 358 | 392 | } |
| 359 | 393 | function saveConnect($req){ |
| 360 | 394 | $this->CFG['my_host'] = $req['host']; |
| 361 | 395 | $this->CFG['my_port'] = (int)$req['port']; |
| 362 | 396 | $this->CFG['my_user'] = $req['user']; |
| 363 | - if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 397 | + if(isset($req['pass'])) { |
|
| 398 | + $this->CFG['my_pass'] = $req['pass']; |
|
| 399 | + } |
|
| 364 | 400 | $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
| 365 | 401 | $this->CFG['my_db'] = $req['db']; |
| 366 | 402 | $this->saveCFG(); |
@@ -372,8 +408,7 @@ discard block |
||
| 372 | 408 | 'collation' => $this->getCollationList() |
| 373 | 409 | ); |
| 374 | 410 | 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,'-');"; |
| 375 | - } |
|
| 376 | - else { |
|
| 411 | + } else { |
|
| 377 | 412 | echo $this->error; |
| 378 | 413 | } |
| 379 | 414 | } |
@@ -406,11 +441,17 @@ discard block |
||
| 406 | 441 | $filter = $object = array(); |
| 407 | 442 | $this->createFilters($job['obj'], $filter, $object); |
| 408 | 443 | $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
| 409 | - if (!$r) return; |
|
| 444 | + if (!$r) { |
|
| 445 | + return; |
|
| 446 | + } |
|
| 410 | 447 | $tables = array(); |
| 411 | 448 | while($item = mysql_fetch_assoc($r)){ |
| 412 | - if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue; |
|
| 413 | - if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`"; |
|
| 449 | + if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 450 | + continue; |
|
| 451 | + } |
|
| 452 | + if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) { |
|
| 453 | + $tables[] = "`{$item['Name']}`"; |
|
| 454 | + } |
|
| 414 | 455 | } |
| 415 | 456 | $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
| 416 | 457 | |
@@ -419,7 +460,9 @@ discard block |
||
| 419 | 460 | } |
| 420 | 461 | |
| 421 | 462 | $r = mysql_query($sql) or sxd_my_error(); |
| 422 | - if (!$r) return; |
|
| 463 | + if (!$r) { |
|
| 464 | + return; |
|
| 465 | + } |
|
| 423 | 466 | $res = array(); |
| 424 | 467 | while($item = mysql_fetch_row($r)){ |
| 425 | 468 | $res[] = $item; |
@@ -436,8 +479,7 @@ discard block |
||
| 436 | 479 | foreach($obj[$type] AS $v){ |
| 437 | 480 | if(strpos($v, '*') !== false) { |
| 438 | 481 | $filter[$type][] = str_replace('*', '.*?', $v); |
| 439 | - } |
|
| 440 | - else { |
|
| 482 | + } else { |
|
| 441 | 483 | $object[$type][$v] = true; |
| 442 | 484 | } |
| 443 | 485 | } |
@@ -460,14 +502,15 @@ discard block |
||
| 460 | 502 | $this->closeConnect(); |
| 461 | 503 | include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
| 462 | 504 | $this->JOB = &$JOB; |
| 463 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 505 | + if(file_exists($this->JOB['file_stp'])) { |
|
| 506 | + unlink($this->JOB['file_stp']); |
|
| 507 | + } |
|
| 464 | 508 | $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
| 465 | 509 | $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
| 466 | 510 | $t = fgets($this->fh_rtl); |
| 467 | 511 | if(!empty($t)){ |
| 468 | 512 | $this->rtl = explode("\t", $t); |
| 469 | - } |
|
| 470 | - else { |
|
| 513 | + } else { |
|
| 471 | 514 | $this->addLog($this->LNG['not_found_rtl']); |
| 472 | 515 | exit; |
| 473 | 516 | } |
@@ -477,8 +520,11 @@ discard block |
||
| 477 | 520 | $this->rtl[1] = time(); |
| 478 | 521 | $this->rtl[9] = 0; |
| 479 | 522 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 480 | - if ($this->JOB['act'] == 'backup') $this->runBackupJob(true); |
|
| 481 | - elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true); |
|
| 523 | + if ($this->JOB['act'] == 'backup') { |
|
| 524 | + $this->runBackupJob(true); |
|
| 525 | + } elseif ($this->JOB['act'] == 'restore') { |
|
| 526 | + $this->runRestoreJob(true); |
|
| 527 | + } |
|
| 482 | 528 | } |
| 483 | 529 | function addRestoreJob($job) { |
| 484 | 530 | $this->closeConnect(); |
@@ -493,9 +539,10 @@ discard block |
||
| 493 | 539 | $this->tab_rows = array(); |
| 494 | 540 | $todo = array(); |
| 495 | 541 | foreach($objects AS $t => $list){ |
| 496 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 497 | - elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
|
| 498 | - if (empty($list)) continue; |
|
| 542 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
|
| 543 | + if (empty($list)) { |
|
| 544 | + continue; |
|
| 545 | + } |
|
| 499 | 546 | |
| 500 | 547 | foreach($list AS $item){ |
| 501 | 548 | switch($t){ |
@@ -503,11 +550,11 @@ discard block |
||
| 503 | 550 | $type = ''; |
| 504 | 551 | if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
| 505 | 552 | $type = empty($item[1]) ? 'TC' : 'TA'; |
| 506 | - } |
|
| 507 | - elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 553 | + } elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | 554 | $type = 'TC'; |
| 555 | + } else { |
|
| 556 | + continue; |
|
| 509 | 557 | } |
| 510 | - else continue; |
|
| 511 | 558 | $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
| 512 | 559 | $rows += $type == 'TA' ? $item[1] : 0; |
| 513 | 560 | break; |
@@ -522,15 +569,21 @@ discard block |
||
| 522 | 569 | $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
| 523 | 570 | $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
| 524 | 571 | $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
| 525 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 572 | + if(file_exists($this->JOB['file_stp'])) { |
|
| 573 | + unlink($this->JOB['file_stp']); |
|
| 574 | + } |
|
| 526 | 575 | |
| 527 | 576 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
| 528 | 577 | // Для чужих дампов определяем разделители строк |
| 529 | 578 | if(is_null($this->JOB['obj'])) { |
| 530 | 579 | $s = fread($this->fh_tmp, 2048); |
| 531 | - if(strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n"; |
|
| 532 | - elseif(strpos($s, "\n")) $this->JOB['eol'] = "\n"; |
|
| 533 | - else $this->JOB['eol'] = "\r"; |
|
| 580 | + if(strpos($s, "\r\n")) { |
|
| 581 | + $this->JOB['eol'] = "\r\n"; |
|
| 582 | + } elseif(strpos($s, "\n")) { |
|
| 583 | + $this->JOB['eol'] = "\n"; |
|
| 584 | + } else { |
|
| 585 | + $this->JOB['eol'] = "\r"; |
|
| 586 | + } |
|
| 534 | 587 | $bom = strncmp($s, "\xEF\xBB\xBF", 3) == 0 ? 3 : ((strncmp($s, "\xFE\xFF", 2) == 0 || strncmp($s, "\xFF\xFE", 2) == 0) ? 2 : 0); |
| 535 | 588 | fseek($this->fh_tmp, $bom); |
| 536 | 589 | } |
@@ -548,11 +601,17 @@ discard block |
||
| 548 | 601 | if($continue){ |
| 549 | 602 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
| 550 | 603 | fseek($this->fh_tmp, $this->rtl[3]); |
| 551 | - if(!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 552 | - if($this->rtl[7] < $this->rtl[10]) $ei = true; |
|
| 604 | + if(!empty($this->rtl[6])) { |
|
| 605 | + $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 606 | + } |
|
| 607 | + if($this->rtl[7] < $this->rtl[10]) { |
|
| 608 | + $ei = true; |
|
| 609 | + } |
|
| 553 | 610 | } |
| 554 | 611 | mysql_select_db($this->JOB['db']); |
| 555 | - if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 612 | + if(is_null($this->JOB['obj'])) { |
|
| 613 | + $this->runRestoreJobForeign($continue); |
|
| 614 | + } |
|
| 556 | 615 | //mysql_query("SET NAMES 'UTF8'"); |
| 557 | 616 | $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
| 558 | 617 | $fcache = ''; |
@@ -583,8 +642,12 @@ discard block |
||
| 583 | 642 | if(V_MYSQL > 40014) { |
| 584 | 643 | mysql_query("SET UNIQUE_CHECKS=0"); |
| 585 | 644 | mysql_query("SET FOREIGN_KEY_CHECKS=0"); |
| 586 | - if(V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 587 | - if(V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0"); |
|
| 645 | + if(V_MYSQL > 40101) { |
|
| 646 | + mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 647 | + } |
|
| 648 | + if(V_MYSQL > 40111) { |
|
| 649 | + mysql_query("SET SQL_NOTES=0"); |
|
| 650 | + } |
|
| 588 | 651 | } |
| 589 | 652 | $log_sql = false; |
| 590 | 653 | $fields = ''; |
@@ -648,13 +711,16 @@ discard block |
||
| 648 | 711 | case 'C': |
| 649 | 712 | $ex = 1; |
| 650 | 713 | if (preg_match('/^CREATE TABLE `/', $q)) { |
| 651 | - if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | - else { |
|
| 714 | + if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) { |
|
| 715 | + $ex = 0; |
|
| 716 | + } else { |
|
| 653 | 717 | $ex = 1; |
| 654 | 718 | if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
| 655 | 719 | $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
| 656 | 720 | } |
| 657 | - if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 721 | + if(!empty($this->JOB['autoinc'])) { |
|
| 722 | + $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 723 | + } |
|
| 658 | 724 | } |
| 659 | 725 | // Достаем имена полей таблицы |
| 660 | 726 | $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
@@ -675,11 +741,9 @@ discard block |
||
| 675 | 741 | if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
| 676 | 742 | mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
| 677 | 743 | } |
| 678 | - } |
|
| 679 | - elseif($m[1] == 'TD'){ |
|
| 744 | + } elseif($m[1] == 'TD'){ |
|
| 680 | 745 | $ei = 1; |
| 681 | - } |
|
| 682 | - else { |
|
| 746 | + } else { |
|
| 683 | 747 | $this->rtl[4] = $m[1]; |
| 684 | 748 | $this->rtl[5] = $m[2]; |
| 685 | 749 | $this->rtl[7] = 0; |
@@ -704,8 +768,7 @@ discard block |
||
| 704 | 768 | if($insert) { |
| 705 | 769 | $c = 1; |
| 706 | 770 | } |
| 707 | - } |
|
| 708 | - else { |
|
| 771 | + } else { |
|
| 709 | 772 | error_log(date('r') . "\n----------\n{$q}\n", 3, "backup/sql_error.log"); |
| 710 | 773 | sxd_my_error(); |
| 711 | 774 | } |
@@ -731,7 +794,9 @@ discard block |
||
| 731 | 794 | $this->rtl[7] = 0; |
| 732 | 795 | $this->rtl[8] = 0; |
| 733 | 796 | foreach($this->JOB['todo']['TA'] AS $tab){ |
| 734 | - if ($tab[0] == 'TC') continue; |
|
| 797 | + if ($tab[0] == 'TC') { |
|
| 798 | + continue; |
|
| 799 | + } |
|
| 735 | 800 | mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
| 736 | 801 | $this->rtl[1] = time(); |
| 737 | 802 | $this->rtl[5] = $tab[1]; |
@@ -770,7 +835,9 @@ discard block |
||
| 770 | 835 | $delimiter = ";"; |
| 771 | 836 | while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
| 772 | 837 | $q = ltrim($q); |
| 773 | - if(empty($q)) break; |
|
| 838 | + if(empty($q)) { |
|
| 839 | + break; |
|
| 840 | + } |
|
| 774 | 841 | if($time_old < time()) { |
| 775 | 842 | if(file_exists($this->JOB['file_stp'])){ |
| 776 | 843 | $type = file_get_contents($this->JOB['file_stp']); |
@@ -829,8 +896,7 @@ discard block |
||
| 829 | 896 | //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
| 830 | 897 | if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
| 831 | 898 | $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
| 832 | - } |
|
| 833 | - elseif(empty($this->JOB['charset'])){ |
|
| 899 | + } elseif(empty($this->JOB['charset'])){ |
|
| 834 | 900 | if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
| 835 | 901 | $this->setNames($charset[2]); |
| 836 | 902 | } |
@@ -849,8 +915,9 @@ discard block |
||
| 849 | 915 | $this->JOB['charset'] = $m[1]; |
| 850 | 916 | $this->setNames($this->JOB['charset']); |
| 851 | 917 | $ex = 0; |
| 918 | + } else { |
|
| 919 | + $ex = 1; |
|
| 852 | 920 | } |
| 853 | - else $ex = 1; |
|
| 854 | 921 | break; |
| 855 | 922 | default: |
| 856 | 923 | $insert = ''; |
@@ -868,8 +935,7 @@ discard block |
||
| 868 | 935 | if($insert) { |
| 869 | 936 | $c = 1; |
| 870 | 937 | } |
| 871 | - } |
|
| 872 | - else { |
|
| 938 | + } else { |
|
| 873 | 939 | error_log("-----------------\n{$q}\n", 3, "error.log"); |
| 874 | 940 | sxd_my_error(); |
| 875 | 941 | } |
@@ -914,17 +980,22 @@ discard block |
||
| 914 | 980 | $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
| 915 | 981 | $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
| 916 | 982 | $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
| 917 | - if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 983 | + if(V_MYSQL > 50100) { |
|
| 984 | + $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 985 | + } |
|
| 918 | 986 | } |
| 919 | 987 | $todo = $header = array(); |
| 920 | 988 | $tabs = $rows = 0; |
| 921 | 989 | $only_create = explode(' ', $this->CFG['only_create']); |
| 922 | 990 | foreach($queries AS $query){ |
| 923 | 991 | $t = $query[2]; |
| 924 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | - elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 992 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} elseif(empty($object[$t]) && empty($filter[$t])) { |
|
| 993 | + continue; |
|
| 994 | + } |
|
| 926 | 995 | $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
| 927 | - if (!$r) continue; |
|
| 996 | + if (!$r) { |
|
| 997 | + continue; |
|
| 998 | + } |
|
| 928 | 999 | $todo[$t] = array(); |
| 929 | 1000 | $header[$t] = array(); |
| 930 | 1001 | |
@@ -939,16 +1010,15 @@ discard block |
||
| 939 | 1010 | $header['VI']= array(); |
| 940 | 1011 | } |
| 941 | 1012 | continue; |
| 942 | - } |
|
| 943 | - elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 1013 | + } elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 944 | 1014 | $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
| 945 | 1015 | $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
| 946 | - } |
|
| 947 | - elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 1016 | + } elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | 1017 | $t = 'TC'; |
| 949 | 1018 | $item['Rows'] = $item['Data_length'] = ''; |
| 1019 | + } else { |
|
| 1020 | + continue; |
|
| 950 | 1021 | } |
| 951 | - else continue; |
|
| 952 | 1022 | $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']); |
| 953 | 1023 | $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}"; |
| 954 | 1024 | $tabs++; |
@@ -979,7 +1049,9 @@ discard block |
||
| 979 | 1049 | foreach($views AS $n => $view) { |
| 980 | 1050 | $can_dumped = true; |
| 981 | 1051 | foreach($view AS $k) { |
| 982 | - if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
|
| 1052 | + if (isset($views[$k]) && !isset($dumped[$k])) { |
|
| 1053 | + $can_dumped = false; |
|
| 1054 | + } |
|
| 983 | 1055 | } |
| 984 | 1056 | if ($can_dumped) { |
| 985 | 1057 | if(sxd_check($n, $object['VI'], $filter['VI'])){ |
@@ -999,7 +1071,9 @@ discard block |
||
| 999 | 1071 | $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
| 1000 | 1072 | $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
| 1001 | 1073 | $this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp'; |
| 1002 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 1074 | + if(file_exists($this->JOB['file_stp'])) { |
|
| 1075 | + unlink($this->JOB['file_stp']); |
|
| 1076 | + } |
|
| 1003 | 1077 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
| 1004 | 1078 | $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']); |
| 1005 | 1079 | $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
@@ -1007,7 +1081,9 @@ discard block |
||
| 1007 | 1081 | $this->saveJob($this->JOB['job'], $this->JOB); |
| 1008 | 1082 | $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, sxd_esc($this->JOB['comment'], false))) . "\n"; |
| 1009 | 1083 | foreach($header AS $t => $o){ |
| 1010 | - if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1084 | + if (!empty($o)) { |
|
| 1085 | + $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1086 | + } |
|
| 1011 | 1087 | } |
| 1012 | 1088 | $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
| 1013 | 1089 | $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
@@ -1027,20 +1103,26 @@ discard block |
||
| 1027 | 1103 | $fcache = ''; |
| 1028 | 1104 | $writes = 0; |
| 1029 | 1105 | |
| 1030 | - if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1106 | + if(V_MYSQL > 40101) { |
|
| 1107 | + mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1108 | + } |
|
| 1031 | 1109 | $time_old = time(); |
| 1032 | 1110 | $exit_time = $time_old + $this->CFG['time_web'] - 1; |
| 1033 | 1111 | $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
| 1034 | 1112 | foreach($this->JOB['todo'] AS $t => $o){ |
| 1035 | - if (empty($this->rtl[4])) $this->rtl[4] = $t; |
|
| 1036 | - elseif ($this->rtl[4] != $t) continue; |
|
| 1113 | + if (empty($this->rtl[4])) { |
|
| 1114 | + $this->rtl[4] = $t; |
|
| 1115 | + } elseif ($this->rtl[4] != $t) { |
|
| 1116 | + continue; |
|
| 1117 | + } |
|
| 1037 | 1118 | foreach($o AS $n){ |
| 1038 | 1119 | if (empty($this->rtl[5])) { |
| 1039 | 1120 | $this->rtl[5] = $n[1]; |
| 1040 | 1121 | $this->rtl[7] = 0; |
| 1041 | 1122 | $this->rtl[8] = !empty($n[4]) ? $n[4] : 0; |
| 1123 | + } elseif ($this->rtl[5] != $n[1]) { |
|
| 1124 | + continue; |
|
| 1042 | 1125 | } |
| 1043 | - elseif ($this->rtl[5] != $n[1]) continue; |
|
| 1044 | 1126 | // Делаем бэкап |
| 1045 | 1127 | switch($n[0]){ |
| 1046 | 1128 | case 'TC': |
@@ -1054,11 +1136,12 @@ discard block |
||
| 1054 | 1136 | $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
| 1055 | 1137 | $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
| 1056 | 1138 | $this->rtl[7] = 0; |
| 1057 | - if($n[0] == 'TC' || !$n[4]) break; |
|
| 1139 | + if($n[0] == 'TC' || !$n[4]) { |
|
| 1140 | + break; |
|
| 1141 | + } |
|
| 1058 | 1142 | // Бэкапим данные таблицы |
| 1059 | 1143 | $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
| 1060 | - } |
|
| 1061 | - else { |
|
| 1144 | + } else { |
|
| 1062 | 1145 | $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}"; |
| 1063 | 1146 | $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7])); |
| 1064 | 1147 | } |
@@ -1101,8 +1184,7 @@ discard block |
||
| 1101 | 1184 | $this->write($fcache); |
| 1102 | 1185 | } |
| 1103 | 1186 | for($k = 0; $k < $fields; $k++){ |
| 1104 | - if(!isset($row[$k])) {$row[$k] = '\N';} |
|
| 1105 | - elseif($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк |
|
| 1187 | + if(!isset($row[$k])) {$row[$k] = '\N';} elseif($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк |
|
| 1106 | 1188 | } |
| 1107 | 1189 | $fcache .= '(' . implode(',', $row) . "),\n"; |
| 1108 | 1190 | $this->rtl[7]++; |
@@ -1119,8 +1201,7 @@ discard block |
||
| 1119 | 1201 | $r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error(); |
| 1120 | 1202 | $item = mysql_fetch_assoc($r); |
| 1121 | 1203 | $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"; |
| 1122 | - } |
|
| 1123 | - else { |
|
| 1204 | + } else { |
|
| 1124 | 1205 | $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1])); |
| 1125 | 1206 | $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error(); |
| 1126 | 1207 | $item = mysql_fetch_assoc($r); |
@@ -1141,7 +1222,9 @@ discard block |
||
| 1141 | 1222 | fclose($this->fh_tmp); |
| 1142 | 1223 | rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
| 1143 | 1224 | $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
| 1144 | - if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1225 | + if(file_exists('sxd2ftp.php')) { |
|
| 1226 | + include('sxd2ftp.php'); |
|
| 1227 | + } |
|
| 1145 | 1228 | if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
| 1146 | 1229 | $this->addLog($this->LNG['autodelete']); |
| 1147 | 1230 | $deldate = ''; |
@@ -1155,11 +1238,13 @@ discard block |
||
| 1155 | 1238 | while (false !== ($file = readdir($dh))) { |
| 1156 | 1239 | if (preg_match("/^{$name}_(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})\.sql/", $file, $m)) { |
| 1157 | 1240 | if ($deldate && $m[1] < $deldate) { |
| 1158 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file)); |
|
| 1159 | - else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1241 | + if(unlink($this->CFG['backup_path'] . $file)) { |
|
| 1242 | + $this->addLog(sprintf($this->LNG['del_by_date'], $file)); |
|
| 1243 | + } else { |
|
| 1244 | + $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1245 | + } |
|
| 1160 | 1246 | $deleted = true; |
| 1161 | - } |
|
| 1162 | - else {$files[$m[1]] = $file;} |
|
| 1247 | + } else {$files[$m[1]] = $file;} |
|
| 1163 | 1248 | } |
| 1164 | 1249 | } |
| 1165 | 1250 | closedir($dh); |
@@ -1169,20 +1254,27 @@ discard block |
||
| 1169 | 1254 | $file_to_delete = count($files) - $this->JOB['del_count']; |
| 1170 | 1255 | foreach ($files AS $file){ |
| 1171 | 1256 | if ($file_to_delete-- > 0){ |
| 1172 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1173 | - else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1257 | + if(unlink($this->CFG['backup_path'] . $file)) { |
|
| 1258 | + $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1259 | + } else { |
|
| 1260 | + $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1261 | + } |
|
| 1174 | 1262 | $deleted = true; |
| 1175 | 1263 | } |
| 1176 | 1264 | } |
| 1177 | 1265 | } |
| 1178 | 1266 | } |
| 1179 | - if(!$deleted) $this->addLog($this->LNG['del_nothing']); |
|
| 1267 | + if(!$deleted) { |
|
| 1268 | + $this->addLog($this->LNG['del_nothing']); |
|
| 1269 | + } |
|
| 1180 | 1270 | } |
| 1181 | 1271 | fclose($this->fh_log); |
| 1182 | 1272 | fclose($this->fh_rtl); |
| 1183 | 1273 | } |
| 1184 | 1274 | function setNames($collation){ |
| 1185 | - if(empty($collation)) return; |
|
| 1275 | + if(empty($collation)) { |
|
| 1276 | + return; |
|
| 1277 | + } |
|
| 1186 | 1278 | if($this->rtl[6] != $collation) { |
| 1187 | 1279 | mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
| 1188 | 1280 | /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
@@ -1201,7 +1293,9 @@ discard block |
||
| 1201 | 1293 | } |
| 1202 | 1294 | function getDBList(){ |
| 1203 | 1295 | $dbs = $items = array(); |
| 1204 | - if (!V_MYSQL) return $dbs; |
|
| 1296 | + if (!V_MYSQL) { |
|
| 1297 | + return $dbs; |
|
| 1298 | + } |
|
| 1205 | 1299 | $qq = (V_MYSQL < 50000) ? '' : '\''; |
| 1206 | 1300 | if ($this->CFG['my_db']) { |
| 1207 | 1301 | $tmp = explode(',', $this->CFG['my_db']); |
@@ -1210,11 +1304,12 @@ discard block |
||
| 1210 | 1304 | $items[] = $qq . sxd_esc($d, false) . $qq; |
| 1211 | 1305 | $dbs[$d] = "{$d} (0)"; |
| 1212 | 1306 | } |
| 1213 | - } |
|
| 1214 | - else{ |
|
| 1307 | + } else{ |
|
| 1215 | 1308 | $result = mysql_query("SHOW DATABASES") or sxd_my_error(); |
| 1216 | 1309 | while($item = mysql_fetch_row($result)){ |
| 1217 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1310 | + if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') { |
|
| 1311 | + continue; |
|
| 1312 | + } |
|
| 1218 | 1313 | $items[] = $qq . sxd_esc($item[0], false) . $qq; |
| 1219 | 1314 | $dbs[$item[0]] = "{$item[0]} (0)"; |
| 1220 | 1315 | } |
@@ -1227,12 +1322,13 @@ discard block |
||
| 1227 | 1322 | $dbs[$item] = "{$item} ({$tabs})"; |
| 1228 | 1323 | } |
| 1229 | 1324 | } |
| 1230 | - } |
|
| 1231 | - else { |
|
| 1325 | + } else { |
|
| 1232 | 1326 | $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
| 1233 | 1327 | $result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error(); |
| 1234 | 1328 | while($item = mysql_fetch_row($result)){ |
| 1235 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1329 | + if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') { |
|
| 1330 | + continue; |
|
| 1331 | + } |
|
| 1236 | 1332 | $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
| 1237 | 1333 | } |
| 1238 | 1334 | } |
@@ -1240,7 +1336,9 @@ discard block |
||
| 1240 | 1336 | } |
| 1241 | 1337 | function getCharsetList(){ |
| 1242 | 1338 | $tmp = array(0 => '- auto -'); |
| 1243 | - if (!V_MYSQL) return $tmp; |
|
| 1339 | + if (!V_MYSQL) { |
|
| 1340 | + return $tmp; |
|
| 1341 | + } |
|
| 1244 | 1342 | if(V_MYSQL > 40101) { |
| 1245 | 1343 | $def_charsets = ''; |
| 1246 | 1344 | if(!empty($this->CFG['charsets'])){ |
@@ -1249,7 +1347,10 @@ discard block |
||
| 1249 | 1347 | $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
| 1250 | 1348 | if ($r) { |
| 1251 | 1349 | while($item = mysql_fetch_assoc($r)){ |
| 1252 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
|
| 1350 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) { |
|
| 1351 | + $tmp[$item['Charset']] = "{$item['Charset']}"; |
|
| 1352 | + } |
|
| 1353 | + // ({$item['Description']}) |
|
| 1253 | 1354 | } |
| 1254 | 1355 | } |
| 1255 | 1356 | } |
@@ -1257,7 +1358,9 @@ discard block |
||
| 1257 | 1358 | } |
| 1258 | 1359 | function getCollationList(){ |
| 1259 | 1360 | $tmp = array(); |
| 1260 | - if (!V_MYSQL) return $tmp; |
|
| 1361 | + if (!V_MYSQL) { |
|
| 1362 | + return $tmp; |
|
| 1363 | + } |
|
| 1261 | 1364 | if(V_MYSQL > 40101) { |
| 1262 | 1365 | $def_charsets = ''; |
| 1263 | 1366 | if(!empty($this->CFG['charsets'])){ |
@@ -1266,7 +1369,9 @@ discard block |
||
| 1266 | 1369 | $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
| 1267 | 1370 | if ($r) { |
| 1268 | 1371 | while($item = mysql_fetch_assoc($r)){ |
| 1269 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1372 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) { |
|
| 1373 | + $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1374 | + } |
|
| 1270 | 1375 | } |
| 1271 | 1376 | } |
| 1272 | 1377 | } |
@@ -1282,8 +1387,7 @@ discard block |
||
| 1282 | 1387 | while($item = mysql_fetch_assoc($r)){ |
| 1283 | 1388 | if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
| 1284 | 1389 | $objects['VI'][]= $item['Name']; |
| 1285 | - } |
|
| 1286 | - else{ |
|
| 1390 | + } else{ |
|
| 1287 | 1391 | $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
| 1288 | 1392 | } |
| 1289 | 1393 | } |
@@ -1294,7 +1398,9 @@ discard block |
||
| 1294 | 1398 | "FUNCTION STATUS WHERE db='{$db_name}'", |
| 1295 | 1399 | 'TRIGGERS' |
| 1296 | 1400 | ); |
| 1297 | - if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1401 | + if(V_MYSQL > 50100) { |
|
| 1402 | + $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1403 | + } |
|
| 1298 | 1404 | // TODO: Поправить проверку событий и триггеров |
| 1299 | 1405 | for($i = 0, $l = count($shows); $i < $l; $i++){ |
| 1300 | 1406 | $r = mysql_query('SHOW ' . $shows[$i]); |
@@ -1306,8 +1412,7 @@ discard block |
||
| 1306 | 1412 | } |
| 1307 | 1413 | } |
| 1308 | 1414 | } |
| 1309 | - } |
|
| 1310 | - else { |
|
| 1415 | + } else { |
|
| 1311 | 1416 | $objects['VI'] = array(); |
| 1312 | 1417 | } |
| 1313 | 1418 | } |
@@ -1316,7 +1421,9 @@ discard block |
||
| 1316 | 1421 | function getFileObjects($tree, $name, $formatTree = true){ |
| 1317 | 1422 | // Достаем таблицы |
| 1318 | 1423 | $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
| 1319 | - if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return ''; |
|
| 1424 | + if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) { |
|
| 1425 | + return ''; |
|
| 1426 | + } |
|
| 1320 | 1427 | $name = $this->CFG['backup_path'] . $name; |
| 1321 | 1428 | if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
| 1322 | 1429 | $fp = $this->openFile($name, 'r'); |
@@ -1332,8 +1439,7 @@ discard block |
||
| 1332 | 1439 | for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
| 1333 | 1440 | $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
| 1334 | 1441 | } |
| 1335 | - } |
|
| 1336 | - else { |
|
| 1442 | + } else { |
|
| 1337 | 1443 | $h[9] = ''; |
| 1338 | 1444 | } |
| 1339 | 1445 | return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
@@ -1355,14 +1461,18 @@ discard block |
||
| 1355 | 1461 | $t = $objects['TA'][$i]; |
| 1356 | 1462 | $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
| 1357 | 1463 | if ($tab_prefix != $tab_prefix_last) { |
| 1358 | - if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix; |
|
| 1464 | + if ($tab_prefix != '*') { |
|
| 1465 | + $objects['TA']['*'][] = $tab_prefix; |
|
| 1466 | + } |
|
| 1359 | 1467 | $tab_prefix_last = $tab_prefix; |
| 1360 | 1468 | } |
| 1361 | 1469 | $objects['TA'][$tab_prefix][] = $t; |
| 1362 | 1470 | unset($objects['TA'][$i]); |
| 1363 | 1471 | } |
| 1364 | 1472 | foreach($objects AS $type => $o){ |
| 1365 | - if(!count($o)) continue; |
|
| 1473 | + if(!count($o)) { |
|
| 1474 | + continue; |
|
| 1475 | + } |
|
| 1366 | 1476 | if($type == 'TA') { |
| 1367 | 1477 | $open_childs = count($o['*']) > 1 ? 0 : 1; |
| 1368 | 1478 | $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
@@ -1377,8 +1487,7 @@ discard block |
||
| 1377 | 1487 | $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
| 1378 | 1488 | $row++; |
| 1379 | 1489 | } |
| 1380 | - } |
|
| 1381 | - else { |
|
| 1490 | + } else { |
|
| 1382 | 1491 | $value = $o[$value][0]; |
| 1383 | 1492 | } |
| 1384 | 1493 | } |
@@ -1389,8 +1498,7 @@ discard block |
||
| 1389 | 1498 | $row++; |
| 1390 | 1499 | } |
| 1391 | 1500 | } |
| 1392 | - } |
|
| 1393 | - else { |
|
| 1501 | + } else { |
|
| 1394 | 1502 | $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
| 1395 | 1503 | $pid = $row++; |
| 1396 | 1504 | $info[$type][1]++; |
@@ -1402,7 +1510,9 @@ discard block |
||
| 1402 | 1510 | } |
| 1403 | 1511 | } |
| 1404 | 1512 | $add = ''; |
| 1405 | - if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1513 | + if($tree == 'restore') { |
|
| 1514 | + $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1515 | + } |
|
| 1406 | 1516 | return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add; |
| 1407 | 1517 | } |
| 1408 | 1518 | function getFileList(){ |
@@ -1431,14 +1541,12 @@ discard block |
||
| 1431 | 1541 | } |
| 1432 | 1542 | if(count($sj['sj_backup']) > 0){ |
| 1433 | 1543 | ksort($sj['sj_backup']); |
| 1434 | - } |
|
| 1435 | - else { |
|
| 1544 | + } else { |
|
| 1436 | 1545 | $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
| 1437 | 1546 | } |
| 1438 | 1547 | if(count($sj['sj_restore']) > 0){ |
| 1439 | 1548 | ksort($sj['sj_restore']); |
| 1440 | - } |
|
| 1441 | - else { |
|
| 1549 | + } else { |
|
| 1442 | 1550 | $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
| 1443 | 1551 | } |
| 1444 | 1552 | return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
@@ -1454,12 +1562,10 @@ discard block |
||
| 1454 | 1562 | if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){ |
| 1455 | 1563 | $h = explode('|', $m[1]); |
| 1456 | 1564 | $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); |
| 1457 | - } |
|
| 1458 | - elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1565 | + } elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1459 | 1566 | $h = explode('|', $m[1]); |
| 1460 | 1567 | $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); |
| 1461 | - } |
|
| 1462 | - else { |
|
| 1568 | + } else { |
|
| 1463 | 1569 | $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file); |
| 1464 | 1570 | } |
| 1465 | 1571 | } |
@@ -1477,9 +1583,10 @@ discard block |
||
| 1477 | 1583 | } |
| 1478 | 1584 | function openFile($name, $mode){ |
| 1479 | 1585 | if($mode == 'r') { |
| 1480 | - if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1481 | - } |
|
| 1482 | - else{ |
|
| 1586 | + if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) { |
|
| 1587 | + $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1588 | + } |
|
| 1589 | + } else{ |
|
| 1483 | 1590 | switch($this->JOB['zip']) { |
| 1484 | 1591 | case 0 : $this->JOB['file_ext'] = 'sql'; break; |
| 1485 | 1592 | case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
@@ -1506,7 +1613,9 @@ discard block |
||
| 1506 | 1613 | $fs = ftell($f); |
| 1507 | 1614 | $delim_len = strlen($delimiter . $eol); |
| 1508 | 1615 | while($r || $s = fread($f, 61440)){ |
| 1509 | - if(!$r) $l .= $s; |
|
| 1616 | + if(!$r) { |
|
| 1617 | + $l .= $s; |
|
| 1618 | + } |
|
| 1510 | 1619 | $pos = strpos($l, $delimiter . $eol); |
| 1511 | 1620 | if ($pos !== false) { |
| 1512 | 1621 | // Есть окончание запроса |
@@ -1538,16 +1647,24 @@ discard block |
||
| 1538 | 1647 | return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
| 1539 | 1648 | } |
| 1540 | 1649 | function sxd_php2json($obj){ |
| 1541 | - if(count($obj) == 0) return '[]'; |
|
| 1650 | + if(count($obj) == 0) { |
|
| 1651 | + return '[]'; |
|
| 1652 | + } |
|
| 1542 | 1653 | $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
| 1543 | 1654 | $str = $is_obj ? '{' : '['; |
| 1544 | 1655 | foreach ($obj AS $key => $value) { |
| 1545 | 1656 | $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
| 1546 | - if (is_array($value)) $str .= sxd_php2json($value); |
|
| 1547 | - elseif (is_null($value)) $str .= 'null'; |
|
| 1548 | - elseif (is_bool($value)) $str .= $value ? 'true' : 'false'; |
|
| 1549 | - elseif (is_numeric($value)) $str .= $value; |
|
| 1550 | - else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1657 | + if (is_array($value)) { |
|
| 1658 | + $str .= sxd_php2json($value); |
|
| 1659 | + } elseif (is_null($value)) { |
|
| 1660 | + $str .= 'null'; |
|
| 1661 | + } elseif (is_bool($value)) { |
|
| 1662 | + $str .= $value ? 'true' : 'false'; |
|
| 1663 | + } elseif (is_numeric($value)) { |
|
| 1664 | + $str .= $value; |
|
| 1665 | + } else { |
|
| 1666 | + $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1667 | + } |
|
| 1551 | 1668 | $str .= ','; |
| 1552 | 1669 | } |
| 1553 | 1670 | return substr_replace($str, $is_obj ? '}' : ']', -1); |
@@ -1557,25 +1674,34 @@ discard block |
||
| 1557 | 1674 | } |
| 1558 | 1675 | function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){ |
| 1559 | 1676 | global $SXD; |
| 1560 | - if($SXD->try) return; |
|
| 1561 | - if($errno == 8192) return; |
|
| 1562 | - if(strpos($errmsg, 'timezone settings')) return; |
|
| 1677 | + if($SXD->try) { |
|
| 1678 | + return; |
|
| 1679 | + } |
|
| 1680 | + if($errno == 8192) { |
|
| 1681 | + return; |
|
| 1682 | + } |
|
| 1683 | + if(strpos($errmsg, 'timezone settings')) { |
|
| 1684 | + return; |
|
| 1685 | + } |
|
| 1563 | 1686 | $errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', |
| 1564 | 1687 | 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
| 1565 | 1688 | 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
| 1566 | 1689 | $str = sxd_esc("{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})", false); |
| 1567 | - if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1690 | + if(SXD_DEBUG) { |
|
| 1691 | + error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1692 | + } |
|
| 1568 | 1693 | |
| 1569 | 1694 | if($errno == 8 || $errno == 1024) { |
| 1570 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1571 | - else { |
|
| 1695 | + if (!$SXD->fh_log && !$SXD->fh_rtl) { |
|
| 1696 | + echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1697 | + } else { |
|
| 1572 | 1698 | fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
| 1573 | 1699 | } |
| 1574 | - } |
|
| 1575 | - elseif($errno < 1024) { |
|
| 1700 | + } elseif($errno < 1024) { |
|
| 1576 | 1701 | $SXD->error = true; |
| 1577 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1578 | - else { |
|
| 1702 | + if (!$SXD->fh_log && !$SXD->fh_rtl) { |
|
| 1703 | + echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1704 | + } else { |
|
| 1579 | 1705 | $SXD->rtl[1] = time(); |
| 1580 | 1706 | $SXD->rtl[9] = 5; |
| 1581 | 1707 | fseek($SXD->fh_rtl, 0); |
@@ -1600,8 +1726,9 @@ discard block |
||
| 1600 | 1726 | if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
| 1601 | 1727 | $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
| 1602 | 1728 | $SXD->rtl[9] = !empty($type) ? $type : 2; |
| 1729 | + } else { |
|
| 1730 | + $SXD->rtl[9] = 5; |
|
| 1603 | 1731 | } |
| 1604 | - else $SXD->rtl[9] = 5; |
|
| 1605 | 1732 | fseek($SXD->fh_rtl, 0); |
| 1606 | 1733 | fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
| 1607 | 1734 | } |
@@ -169,6 +169,10 @@ discard block |
||
| 169 | 169 | * @return bool |
| 170 | 170 | */ |
| 171 | 171 | // OK v4.5 |
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param string $account_name_unsafe |
|
| 175 | + */ |
|
| 172 | 176 | public function db_get_by_name($account_name_unsafe) { |
| 173 | 177 | $this->reset(); |
| 174 | 178 | |
@@ -203,6 +207,11 @@ discard block |
||
| 203 | 207 | * |
| 204 | 208 | */ |
| 205 | 209 | // OK v4.5 |
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param string $account_name_unsafe |
|
| 213 | + * @param string $email_unsafe |
|
| 214 | + */ |
|
| 206 | 215 | public function db_get_by_name_or_email($account_name_unsafe, $email_unsafe) { |
| 207 | 216 | $this->reset(); |
| 208 | 217 | |
@@ -218,6 +227,13 @@ discard block |
||
| 218 | 227 | * @throws Exception |
| 219 | 228 | */ |
| 220 | 229 | // OK v4.5 |
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param string $account_name_unsafe |
|
| 233 | + * @param string $password_raw |
|
| 234 | + * @param string $email_unsafe |
|
| 235 | + * @param string $language_unsafe |
|
| 236 | + */ |
|
| 221 | 237 | public function db_create($account_name_unsafe, $password_raw, $email_unsafe, $language_unsafe = null, $salt_unsafe = null) { |
| 222 | 238 | $this->reset(); |
| 223 | 239 | |
@@ -312,6 +328,10 @@ discard block |
||
| 312 | 328 | * @return int|string |
| 313 | 329 | */ |
| 314 | 330 | // OK 4.8 |
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @param double $metamatter |
|
| 334 | + */ |
|
| 315 | 335 | protected function db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe) { |
| 316 | 336 | $provider_id_safe = intval(core_auth::$main_provider->provider_id); |
| 317 | 337 | //$account_id_safe = $this->db->db_escape($this->account_id); |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | $this->reset(); |
| 79 | 79 | $this->db = is_object($db) ? $db : classSupernova::$db; |
| 80 | 80 | |
| 81 | - foreach($this->table_check as $table_name) { |
|
| 82 | - if(empty($this->db->table_list[$table_name])) { |
|
| 81 | + foreach ($this->table_check as $table_name) { |
|
| 82 | + if (empty($this->db->table_list[$table_name])) { |
|
| 83 | 83 | die('Если вы видите это сообщение первый раз после обновления релиза - просто перегрузите страницу.<br /> |
| 84 | 84 | В противном случае - сообщите Администрации сервера об ошибке.<br/> |
| 85 | 85 | Не хватает таблицы для работы системы авторизации: ' . $table_name); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | // OK v4.6 |
| 105 | 105 | public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
| 106 | - if(!$this->password_check($old_password_unsafe)) { |
|
| 106 | + if (!$this->password_check($old_password_unsafe)) { |
|
| 107 | 107 | return false; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | // OK v4.5 |
| 125 | 125 | public function assign_from_db_row($row) { |
| 126 | 126 | $this->reset(); |
| 127 | - if(empty($row) || !is_array($row)) { |
|
| 127 | + if (empty($row) || !is_array($row)) { |
|
| 128 | 128 | return false; |
| 129 | 129 | } |
| 130 | 130 | $this->account_id = $row['account_id']; |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | `account_email` = LOWER('{$email_safe}'), |
| 238 | 238 | `account_language` = '{$language_safe}'" |
| 239 | 239 | ); |
| 240 | - if(!$result) { |
|
| 240 | + if (!$result) { |
|
| 241 | 241 | throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if(!($account_id = $this->db->db_insert_id())) { |
|
| 244 | + if (!($account_id = $this->db->db_insert_id())) { |
|
| 245 | 245 | throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | WHERE `account_id` = '{$account_id_safe}'" |
| 272 | 272 | ) ? true : false; |
| 273 | 273 | |
| 274 | - if($result) { |
|
| 274 | + if ($result) { |
|
| 275 | 275 | $result = $this->db_get_by_id($this->account_id); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | public function metamatter_change($change_type, $metamatter, $comment = false, $already_changed = false) { |
| 352 | 352 | global $debug, $mm_change_legit, $config; |
| 353 | 353 | |
| 354 | - if(!$this->is_exists || !($metamatter = round(floatval($metamatter)))) { |
|
| 354 | + if (!$this->is_exists || !($metamatter = round(floatval($metamatter)))) { |
|
| 355 | 355 | $debug->error('Ошибка при попытке манипуляции с ММ'); |
| 356 | 356 | return false; |
| 357 | 357 | } |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | $mm_change_legit = true; |
| 362 | 362 | // $sn_data_metamatter_db_name = pname_resource_name(RES_METAMATTER); |
| 363 | - if($already_changed) { |
|
| 363 | + if ($already_changed) { |
|
| 364 | 364 | $metamatter_total_delta = 0; |
| 365 | 365 | $result = -1; |
| 366 | 366 | } else { |
@@ -373,13 +373,13 @@ discard block |
||
| 373 | 373 | ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$config->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : '') . |
| 374 | 374 | " WHERE `account_id` = {$account_id_safe}" |
| 375 | 375 | ); |
| 376 | - if(!$result) { |
|
| 376 | + if (!$result) { |
|
| 377 | 377 | $debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402); |
| 378 | 378 | } |
| 379 | 379 | $result = classSupernova::$db->db_affected_rows(); |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if(empty(core_auth::$user['id'])) { |
|
| 382 | + if (empty(core_auth::$user['id'])) { |
|
| 383 | 383 | $user_list = PlayerToAccountTranslate::db_translate_get_users_from_account_list(core_auth::$main_provider->provider_id, $this->account_id); |
| 384 | 384 | reset($user_list); |
| 385 | 385 | $user_id_unsafe = key($user_list); |
@@ -388,30 +388,30 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | $user_id_safe = $this->db->db_escape($user_id_unsafe); |
| 390 | 390 | |
| 391 | - if(!$result) { |
|
| 391 | + if (!$result) { |
|
| 392 | 392 | $debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if(!$already_changed) { |
|
| 395 | + if (!$already_changed) { |
|
| 396 | 396 | $this->account_metamatter += $metamatter; |
| 397 | 397 | $this->account_metamatter_total += $metamatter_total_delta; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - if(is_array($comment)) { |
|
| 400 | + if (is_array($comment)) { |
|
| 401 | 401 | $comment = call_user_func_array('sprintf', $comment); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | $result = $this->db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe); |
| 405 | 405 | |
| 406 | - if($metamatter > 0 && !empty($user_id_safe)) { |
|
| 406 | + if ($metamatter > 0 && !empty($user_id_safe)) { |
|
| 407 | 407 | $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id_safe} LIMIT 1 FOR UPDATE;", '', true); |
| 408 | - if($old_referral['id']) { |
|
| 408 | + if ($old_referral['id']) { |
|
| 409 | 409 | $dark_matter_from_metamatter = $metamatter * AFFILIATE_MM_TO_REFERRAL_DM; |
| 410 | 410 | doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter_from_metamatter}' WHERE `id` = {$user_id_safe} LIMIT 1;"); |
| 411 | 411 | $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id_safe} LIMIT 1;", '', true); |
| 412 | 412 | |
| 413 | 413 | $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0); |
| 414 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
| 414 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
| 415 | 415 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL_BOUGHT_MM, $partner_bonus, "Incoming MM From Referral ID {$user_id_safe}"); |
| 416 | 416 | } |
| 417 | 417 | } |
@@ -209,6 +209,10 @@ discard block |
||
| 209 | 209 | * @return array|bool|resource |
| 210 | 210 | */ |
| 211 | 211 | // OK v4.5 |
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @param string $salt_unsafe |
|
| 215 | + */ |
|
| 212 | 216 | public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
| 213 | 217 | $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe); |
| 214 | 218 | if($result) { |
@@ -218,6 +222,9 @@ discard block |
||
| 218 | 222 | return $result; |
| 219 | 223 | } |
| 220 | 224 | |
| 225 | + /** |
|
| 226 | + * @param Account $account_to_impersonate |
|
| 227 | + */ |
|
| 221 | 228 | public function impersonate($account_to_impersonate) { |
| 222 | 229 | $this->cookie_set($account_to_impersonate); |
| 223 | 230 | } |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | $this->prepare(); |
| 137 | 137 | |
| 138 | 138 | $this->manifest['active'] = false; |
| 139 | - if(!empty($this->config) && is_array($this->config['db'])) { |
|
| 139 | + if (!empty($this->config) && is_array($this->config['db'])) { |
|
| 140 | 140 | // БД, отличная от стандартной |
| 141 | 141 | $this->db = new db_mysql(); |
| 142 | 142 | |
| 143 | 143 | $this->db->sn_db_connect($this->config['db']); |
| 144 | - if($this->manifest['active'] = $this->db->connected) { |
|
| 144 | + if ($this->manifest['active'] = $this->db->connected) { |
|
| 145 | 145 | $this->provider_id = ACCOUNT_PROVIDER_CENTRAL; |
| 146 | 146 | |
| 147 | 147 | $this->domain = $this->config['domain']; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Fallback to local DB |
| 158 | - if(!$this->manifest['active']) { |
|
| 158 | + if (!$this->manifest['active']) { |
|
| 159 | 159 | $this->db = classSupernova::$db; |
| 160 | 160 | |
| 161 | 161 | $this->provider_id = ACCOUNT_PROVIDER_LOCAL; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | // OK v4.5 |
| 212 | 212 | public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
| 213 | 213 | $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe); |
| 214 | - if($result) { |
|
| 214 | + if ($result) { |
|
| 215 | 215 | $this->cookie_set(); |
| 216 | 216 | } |
| 217 | 217 | |
@@ -241,12 +241,12 @@ discard block |
||
| 241 | 241 | protected function password_reset_send_code() { |
| 242 | 242 | global $lang, $config; |
| 243 | 243 | |
| 244 | - if(!$this->is_password_reset) { |
|
| 244 | + if (!$this->is_password_reset) { |
|
| 245 | 245 | return $this->account_login_status; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Проверяем поддержку сброса пароля |
| 249 | - if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
| 249 | + if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
| 250 | 250 | return $this->account_login_status; |
| 251 | 251 | } |
| 252 | 252 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | unset($this->account); |
| 257 | 257 | $this->account = new Account($this->db); |
| 258 | 258 | |
| 259 | - if(!$this->account->db_get_by_email($email_unsafe)) { |
|
| 259 | + if (!$this->account->db_get_by_email($email_unsafe)) { |
|
| 260 | 260 | throw new Exception(PASSWORD_RESTORE_ERROR_EMAIL_NOT_EXISTS, ERR_ERROR); |
| 261 | 261 | // return $this->account_login_status; |
| 262 | 262 | } |
@@ -266,14 +266,14 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | // TODO - Проверять уровень доступа аккаунта! |
| 268 | 268 | // Аккаунты с АУТЛЕВЕЛ больше 0 - НЕ СБРАСЫВАЮТ ПАРОЛИ! |
| 269 | - foreach($user_list as $user_id => $user_data) { |
|
| 270 | - if($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) { |
|
| 269 | + foreach ($user_list as $user_id => $user_data) { |
|
| 270 | + if ($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) { |
|
| 271 | 271 | throw new Exception(PASSWORD_RESTORE_ERROR_ADMIN_ACCOUNT, ERR_ERROR); |
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | $confirmation = $this->confirmation->db_confirmation_get_latest_by_type_and_email(CONFIRM_PASSWORD_RESET, $email_unsafe); // OK 4.5 |
| 276 | - if(isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) { |
|
| 276 | + if (isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) { |
|
| 277 | 277 | throw new Exception(PASSWORD_RESTORE_ERROR_TOO_OFTEN, ERR_ERROR); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | ); |
| 291 | 291 | |
| 292 | 292 | $result = $result ? PASSWORD_RESTORE_SUCCESS_CODE_SENT : PASSWORD_RESTORE_ERROR_SENDING; |
| 293 | - } catch(Exception $e) { |
|
| 293 | + } catch (Exception $e) { |
|
| 294 | 294 | sn_db_transaction_rollback(); |
| 295 | 295 | $result = $e->getMessage(); |
| 296 | 296 | } |
@@ -306,46 +306,46 @@ discard block |
||
| 306 | 306 | protected function password_reset_confirm() { |
| 307 | 307 | global $lang, $config; |
| 308 | 308 | |
| 309 | - if(!$this->is_password_reset_confirm) { |
|
| 309 | + if (!$this->is_password_reset_confirm) { |
|
| 310 | 310 | return $this->account_login_status; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - if($this->account_login_status != LOGIN_UNDEFINED) { |
|
| 313 | + if ($this->account_login_status != LOGIN_UNDEFINED) { |
|
| 314 | 314 | return $this->account_login_status; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Проверяем поддержку сброса пароля |
| 318 | - if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
| 318 | + if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) { |
|
| 319 | 319 | return $this->account_login_status; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | try { |
| 323 | 323 | $code_unsafe = sys_get_param_str_unsafe('password_reset_code'); |
| 324 | - if(empty($code_unsafe)) { |
|
| 324 | + if (empty($code_unsafe)) { |
|
| 325 | 325 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_EMPTY, ERR_ERROR); |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | sn_db_transaction_start(); |
| 329 | 329 | $confirmation = $this->confirmation->db_confirmation_get_by_type_and_code(CONFIRM_PASSWORD_RESET, $code_unsafe); // OK 4.5 |
| 330 | 330 | |
| 331 | - if(empty($confirmation)) { |
|
| 331 | + if (empty($confirmation)) { |
|
| 332 | 332 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_WRONG, ERR_ERROR); |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if(SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) { |
|
| 335 | + if (SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) { |
|
| 336 | 336 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_TOO_OLD, ERR_ERROR); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | unset($this->account); |
| 340 | 340 | $this->account = new Account($this->db); |
| 341 | 341 | |
| 342 | - if(!$this->account->db_get_by_email($confirmation['email'])) { |
|
| 342 | + if (!$this->account->db_get_by_email($confirmation['email'])) { |
|
| 343 | 343 | throw new Exception(PASSWORD_RESTORE_ERROR_CODE_OK_BUT_NO_ACCOUNT_FOR_EMAIL, ERR_ERROR); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $new_password_unsafe = $this->make_random_password(); |
| 347 | 347 | $salt_unsafe = $this->password_salt_generate(); |
| 348 | - if(!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) { |
|
| 348 | + if (!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) { |
|
| 349 | 349 | // Ошибка смены пароля |
| 350 | 350 | throw new Exception(AUTH_ERROR_INTERNAL_PASSWORD_CHANGE_ON_RESTORE, ERR_ERROR); |
| 351 | 351 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | $this->cookie_set(); |
| 356 | 356 | $this->login_cookie(); |
| 357 | 357 | |
| 358 | - if($this->account_login_status == LOGIN_SUCCESS) { |
|
| 358 | + if ($this->account_login_status == LOGIN_SUCCESS) { |
|
| 359 | 359 | // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!! |
| 360 | 360 | $message_header = sprintf($lang['log_lost_email_title'], $config->game_name); |
| 361 | 361 | $message = sprintf($lang['log_lost_email_pass'], $config->game_name, $this->account->account_name, $new_password_unsafe); |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | // $users_translated = classSupernova::$auth->db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5 |
| 365 | 365 | $users_translated = PlayerToAccountTranslate::db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5 |
| 366 | - if(!empty($users_translated)) { |
|
| 366 | + if (!empty($users_translated)) { |
|
| 367 | 367 | // Отправляем в лички письмо о сбросе пароля |
| 368 | 368 | |
| 369 | 369 | // ПО ОПРЕДЕЛЕНИЮ в $users_translated только |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | $message = sys_bbcodeParse($message) . '<br><br>'; |
| 376 | 376 | // msg_send_simple_message($found_provider->data[F_USER_ID], 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['sys_login_register_message_title'], $message); |
| 377 | 377 | |
| 378 | - foreach($users_translated as $user_id => $providers_list) { |
|
| 378 | + foreach ($users_translated as $user_id => $providers_list) { |
|
| 379 | 379 | msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['sys_login_register_message_title'], $message); |
| 380 | 380 | } |
| 381 | 381 | } else { |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | $this->flog('Регистрация: начинаем. Провайдер ' . $this->provider_id); |
| 431 | 431 | |
| 432 | 432 | try { |
| 433 | - if(!$this->is_register) { |
|
| 433 | + if (!$this->is_register) { |
|
| 434 | 434 | $this->flog('Регистрация: не выставлен флаг регистрации - пропускаем'); |
| 435 | 435 | throw new Exception(LOGIN_UNDEFINED, ERR_ERROR); |
| 436 | 436 | } |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | // $this->account_check_duplicate_name_or_email($this->input_login_unsafe, $this->input_email_unsafe); |
| 443 | 443 | |
| 444 | 444 | $this->account->db_get_by_name_or_email($this->input_login_unsafe, $this->input_email_unsafe); |
| 445 | - if($this->account->is_exists) { |
|
| 446 | - if($this->account->account_email == $this->input_email_unsafe) { |
|
| 445 | + if ($this->account->is_exists) { |
|
| 446 | + if ($this->account->account_email == $this->input_email_unsafe) { |
|
| 447 | 447 | throw new Exception(REGISTER_ERROR_EMAIL_EXISTS, ERR_ERROR); |
| 448 | 448 | } else { |
| 449 | 449 | throw new Exception(REGISTER_ERROR_ACCOUNT_NAME_EXISTS, ERR_ERROR); |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | // А вот это пока не нужно. Трансляцией аккаунтов в юзеров и созданием новых юзеров для новозашедших аккаунтов занимается Auth |
| 483 | 483 | // $this->register_account(); |
| 484 | 484 | sn_db_transaction_commit(); |
| 485 | - } catch(Exception $e) { |
|
| 485 | + } catch (Exception $e) { |
|
| 486 | 486 | sn_db_transaction_rollback(); |
| 487 | 487 | $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false; |
| 488 | 488 | } |
@@ -498,15 +498,15 @@ discard block |
||
| 498 | 498 | */ |
| 499 | 499 | // OK v4.5 |
| 500 | 500 | protected function login_cookie() { |
| 501 | - if($this->account_login_status != LOGIN_UNDEFINED) { |
|
| 501 | + if ($this->account_login_status != LOGIN_UNDEFINED) { |
|
| 502 | 502 | return $this->account_login_status; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | // Пытаемся войти по куке |
| 506 | - if(!empty($_COOKIE[$this->cookie_name])) { |
|
| 506 | + if (!empty($_COOKIE[$this->cookie_name])) { |
|
| 507 | 507 | // Кто хотел - уже сконвертировал старые куки в новые |
| 508 | 508 | // Update оказывается - не все... |
| 509 | - if(count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) { |
|
| 509 | + if (count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) { |
|
| 510 | 510 | list($account_id_unsafe, $cookie_password_hash_salted, $user_remember_me) = explode(AUTH_COOKIE_DELIMETER, $_COOKIE[$this->cookie_name]); |
| 511 | 511 | } else { |
| 512 | 512 | list($account_id_unsafe, $user_name, $cookie_password_hash_salted, $user_remember_me) = explode("/%/", $_COOKIE[$this->cookie_name]); |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | // $account = $this->db_account_get_by_id($account_id_unsafe); |
| 516 | 516 | |
| 517 | - if( |
|
| 517 | + if ( |
|
| 518 | 518 | $this->account->db_get_by_id($account_id_unsafe) |
| 519 | 519 | && ($this->password_encode_for_cookie($this->account->account_password) == $cookie_password_hash_salted) |
| 520 | 520 | ) { |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - if($this->account_login_status != LOGIN_SUCCESS) { |
|
| 527 | + if ($this->account_login_status != LOGIN_SUCCESS) { |
|
| 528 | 528 | // Невалидная кука - чистим |
| 529 | 529 | $this->cookie_clear(); |
| 530 | 530 | } |
@@ -542,13 +542,13 @@ discard block |
||
| 542 | 542 | protected function login_username() { |
| 543 | 543 | // TODO - Логин по старым именам |
| 544 | 544 | try { |
| 545 | - if(!$this->is_login) { |
|
| 545 | + if (!$this->is_login) { |
|
| 546 | 546 | $this->flog('Логин: не выставлен флаг входа в игру - это не логин'); |
| 547 | 547 | throw new Exception(LOGIN_UNDEFINED, ERR_ERROR); |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | // TODO Пустое имя аккаунта |
| 551 | - if(!$this->input_login_unsafe) { |
|
| 551 | + if (!$this->input_login_unsafe) { |
|
| 552 | 552 | throw new Exception(LOGIN_UNDEFINED, ERR_ERROR); |
| 553 | 553 | } |
| 554 | 554 | |
@@ -558,11 +558,11 @@ discard block |
||
| 558 | 558 | // if(empty($account)) { |
| 559 | 559 | // throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR); |
| 560 | 560 | // } |
| 561 | - if(!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) { |
|
| 561 | + if (!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) { |
|
| 562 | 562 | throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR); |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - if(!$this->account->password_check($this->input_login_password_raw)) { |
|
| 565 | + if (!$this->account->password_check($this->input_login_password_raw)) { |
|
| 566 | 566 | throw new Exception(LOGIN_ERROR_PASSWORD, ERR_ERROR); |
| 567 | 567 | } |
| 568 | 568 | |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | |
| 571 | 571 | $this->cookie_set(); |
| 572 | 572 | $this->account_login_status = LOGIN_SUCCESS; |
| 573 | - } catch(Exception $e) { |
|
| 573 | + } catch (Exception $e) { |
|
| 574 | 574 | $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false; |
| 575 | 575 | } |
| 576 | 576 | |
@@ -592,11 +592,11 @@ discard block |
||
| 592 | 592 | protected function cookie_set($account_to_impersonate = null) { |
| 593 | 593 | $this_account = is_object($account_to_impersonate) ? $account_to_impersonate : $this->account; |
| 594 | 594 | |
| 595 | - if(!is_object($this_account) || !$this_account->is_exists) { |
|
| 595 | + if (!is_object($this_account) || !$this_account->is_exists) { |
|
| 596 | 596 | throw new Exception(LOGIN_ERROR_NO_ACCOUNT_FOR_COOKIE_SET, ERR_ERROR); |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - if(is_object($account_to_impersonate) && $account_to_impersonate->is_exists) { |
|
| 599 | + if (is_object($account_to_impersonate) && $account_to_impersonate->is_exists) { |
|
| 600 | 600 | sn_setcookie($this->cookie_name_impersonate, $_COOKIE[$this->cookie_name], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain); |
| 601 | 601 | } |
| 602 | 602 | |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | // OK v4.1 |
| 615 | 615 | protected function cookie_clear() { |
| 616 | 616 | // Автоматически вообще-то - если установлена кука имперсонатора - то чистим обычную, а куку имперсонатора - копируем в неё |
| 617 | - if(!empty($_COOKIE[$this->cookie_name_impersonate])) { |
|
| 617 | + if (!empty($_COOKIE[$this->cookie_name_impersonate])) { |
|
| 618 | 618 | sn_setcookie($this->cookie_name, $_COOKIE[$this->cookie_name_impersonate], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain); |
| 619 | 619 | sn_setcookie($this->cookie_name_impersonate, '', SN_TIME_NOW - PERIOD_WEEK, $this->sn_root_path, $this->domain); |
| 620 | 620 | } else { |
@@ -633,10 +633,10 @@ discard block |
||
| 633 | 633 | protected function login_validate_input() { |
| 634 | 634 | // Проверяем, что бы в начале и конце не было пустых символов |
| 635 | 635 | // TODO - при копировании Эксель -> Опера - в конце образуются пустые места. Это не должно быть проблемой! Вынести проверку пароля в регистрацию! |
| 636 | - if($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
| 636 | + if ($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
| 637 | 637 | throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR); |
| 638 | 638 | } |
| 639 | - if(!$this->input_login_password_raw) { |
|
| 639 | + if (!$this->input_login_password_raw) { |
|
| 640 | 640 | throw new Exception(LOGIN_ERROR_PASSWORD_EMPTY, ERR_ERROR); |
| 641 | 641 | } |
| 642 | 642 | } |
@@ -652,37 +652,37 @@ discard block |
||
| 652 | 652 | $this->login_validate_input(); |
| 653 | 653 | |
| 654 | 654 | // Если нет имени пользователя - NO GO! |
| 655 | - if(!$this->input_login_unsafe) { |
|
| 655 | + if (!$this->input_login_unsafe) { |
|
| 656 | 656 | throw new Exception(LOGIN_ERROR_USERNAME_EMPTY, ERR_ERROR); |
| 657 | 657 | } |
| 658 | 658 | // Если логин имеет запрещенные символы - NO GO! |
| 659 | - if(strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
| 659 | + if (strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
| 660 | 660 | throw new Exception(LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS, ERR_ERROR); |
| 661 | 661 | } |
| 662 | 662 | // Если логин меньше минимальной длины - NO GO! |
| 663 | - if(strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) { |
|
| 663 | + if (strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) { |
|
| 664 | 664 | throw new Exception(REGISTER_ERROR_USERNAME_SHORT, ERR_ERROR); |
| 665 | 665 | } |
| 666 | 666 | // Если пароль меньше минимальной длины - NO GO! |
| 667 | - if(strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) { |
|
| 667 | + if (strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) { |
|
| 668 | 668 | throw new Exception(REGISTER_ERROR_PASSWORD_INSECURE, ERR_ERROR); |
| 669 | 669 | } |
| 670 | 670 | // Если пароль имеет пробельные символы в начале или конце - NO GO! |
| 671 | - if($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
| 671 | + if ($this->input_login_password_raw != trim($this->input_login_password_raw)) { |
|
| 672 | 672 | throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR); |
| 673 | 673 | } |
| 674 | 674 | // Если пароль не совпадает с подтверждением - NO GO! То, что у пароля нет пробельных символов в начале/конце - мы уже проверили выше |
| 675 | 675 | //Если они есть у повтора - значит пароль и повтор не совпадут |
| 676 | - if($this->input_login_password_raw <> $this->input_login_password_raw_repeat) { |
|
| 676 | + if ($this->input_login_password_raw <> $this->input_login_password_raw_repeat) { |
|
| 677 | 677 | throw new Exception(REGISTER_ERROR_PASSWORD_DIFFERENT, ERR_ERROR); |
| 678 | 678 | } |
| 679 | 679 | // Если нет емейла - NO GO! |
| 680 | 680 | // TODO - регистрация без емейла |
| 681 | - if(!$this->input_email_unsafe) { |
|
| 681 | + if (!$this->input_email_unsafe) { |
|
| 682 | 682 | throw new Exception(REGISTER_ERROR_EMAIL_EMPTY, ERR_ERROR); |
| 683 | 683 | } |
| 684 | 684 | // Если емейл не является емейлом - NO GO! |
| 685 | - if(!is_email($this->input_email_unsafe)) { |
|
| 685 | + if (!is_email($this->input_email_unsafe)) { |
|
| 686 | 686 | throw new Exception(REGISTER_ERROR_EMAIL_WRONG, ERR_ERROR); |
| 687 | 687 | } |
| 688 | 688 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | return core_auth::make_random_password(); |
| 716 | 716 | } |
| 717 | 717 | protected function flog($message, $die = false) { |
| 718 | - if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
| 718 | + if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
| 719 | 719 | return; |
| 720 | 720 | } |
| 721 | 721 | list($called, $caller) = debug_backtrace(false); |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false; |
| 732 | 732 | |
| 733 | 733 | classSupernova::log_file("$message - $caller_name"); |
| 734 | - if($die) { |
|
| 734 | + if ($die) { |
|
| 735 | 735 | // pdump($caller); |
| 736 | 736 | // pdump(debug_backtrace(false)); |
| 737 | 737 | $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>"); |
@@ -81,6 +81,10 @@ discard block |
||
| 81 | 81 | // ------------------------------------------------------------------------- |
| 82 | 82 | // Here comes low-level functions - those that directly works with cacher engines |
| 83 | 83 | // ------------------------------------------------------------------------- |
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $name |
|
| 87 | + */ |
|
| 84 | 88 | public function __set($name, $value) { |
| 85 | 89 | switch ($name) { |
| 86 | 90 | case '_MODE': |
@@ -132,6 +136,9 @@ discard block |
||
| 132 | 136 | return null; |
| 133 | 137 | } |
| 134 | 138 | |
| 139 | + /** |
|
| 140 | + * @param string $name |
|
| 141 | + */ |
|
| 135 | 142 | public function __isset($name) { |
| 136 | 143 | switch (self::$mode) { |
| 137 | 144 | case CACHER_NO_CACHE: |
@@ -332,6 +339,9 @@ discard block |
||
| 332 | 339 | return self::$cacheObject; |
| 333 | 340 | } |
| 334 | 341 | |
| 342 | + /** |
|
| 343 | + * @param string $index |
|
| 344 | + */ |
|
| 335 | 345 | public function db_loadItem($index) { |
| 336 | 346 | $result = null; |
| 337 | 347 | if($index) { |
@@ -371,6 +381,9 @@ discard block |
||
| 371 | 381 | $this->db_saveItem(array_combine(array_keys($this->defaults), array_fill(0, count($this->defaults), null))); |
| 372 | 382 | } |
| 373 | 383 | |
| 384 | + /** |
|
| 385 | + * @param integer $value |
|
| 386 | + */ |
|
| 374 | 387 | public function db_saveItem($item_list, $value = NULL) { |
| 375 | 388 | if(empty($item_list)) { |
| 376 | 389 | return; |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | if(self::$mode === CACHER_NOT_INIT) { |
| 60 | 60 | self::$mode = CACHER_NO_CACHE; |
| 61 | 61 | if(!self::$data) { |
| 62 | - self::$data = array(); |
|
| 62 | + self::$data = array(); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | * Defining some constants |
| 14 | 14 | */ |
| 15 | 15 | define('CACHER_NOT_INIT', -1); |
| 16 | -define('CACHER_NO_CACHE', 0); |
|
| 17 | -define('CACHER_XCACHE' , 1); |
|
| 16 | +define('CACHER_NO_CACHE', 0); |
|
| 17 | +define('CACHER_XCACHE', 1); |
|
| 18 | 18 | |
| 19 | 19 | define('CACHER_LOCK_WAIT', 5); // maximum cacher wait for table unlock in seconds. Can be float |
| 20 | 20 | |
@@ -46,19 +46,19 @@ discard block |
||
| 46 | 46 | protected static $cacheObject; |
| 47 | 47 | |
| 48 | 48 | public function __construct($prefIn = 'CACHE_', $init_mode = false) { |
| 49 | - if( !($init_mode === false || $init_mode === CACHER_NO_CACHE || ($init_mode === CACHER_XCACHE && extension_loaded('xcache')) )) { |
|
| 49 | + if (!($init_mode === false || $init_mode === CACHER_NO_CACHE || ($init_mode === CACHER_XCACHE && extension_loaded('xcache')))) { |
|
| 50 | 50 | throw new UnexpectedValueException('Wrong work mode or current mode does not supported on your server'); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $this->prefix = $prefIn; |
| 54 | - if(extension_loaded('xcache') && ($init_mode === CACHER_XCACHE || $init_mode === false)) { |
|
| 55 | - if(self::$mode === CACHER_NOT_INIT) { |
|
| 54 | + if (extension_loaded('xcache') && ($init_mode === CACHER_XCACHE || $init_mode === false)) { |
|
| 55 | + if (self::$mode === CACHER_NOT_INIT) { |
|
| 56 | 56 | self::$mode = CACHER_XCACHE; |
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | - if(self::$mode === CACHER_NOT_INIT) { |
|
| 59 | + if (self::$mode === CACHER_NOT_INIT) { |
|
| 60 | 60 | self::$mode = CACHER_NO_CACHE; |
| 61 | - if(!self::$data) { |
|
| 61 | + if (!self::$data) { |
|
| 62 | 62 | self::$data = array(); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | default: |
| 95 | 95 | switch (self::$mode) { |
| 96 | 96 | case CACHER_NO_CACHE: |
| 97 | - self::$data[$this->prefix.$name] = $value; |
|
| 97 | + self::$data[$this->prefix . $name] = $value; |
|
| 98 | 98 | break; |
| 99 | 99 | |
| 100 | 100 | case CACHER_XCACHE: |
| 101 | - xcache_set($this->prefix.$name, $value); |
|
| 101 | + xcache_set($this->prefix . $name, $value); |
|
| 102 | 102 | break; |
| 103 | 103 | } |
| 104 | 104 | break; |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | default: |
| 119 | 119 | switch (self::$mode) { |
| 120 | 120 | case CACHER_NO_CACHE: |
| 121 | - return self::$data[$this->prefix.$name]; |
|
| 121 | + return self::$data[$this->prefix . $name]; |
|
| 122 | 122 | break; |
| 123 | 123 | |
| 124 | 124 | case CACHER_XCACHE: |
| 125 | - return xcache_get($this->prefix.$name); |
|
| 125 | + return xcache_get($this->prefix . $name); |
|
| 126 | 126 | break; |
| 127 | 127 | |
| 128 | 128 | } |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | public function __isset($name) { |
| 136 | 136 | switch (self::$mode) { |
| 137 | 137 | case CACHER_NO_CACHE: |
| 138 | - return isset(self::$data[$this->prefix.$name]); |
|
| 138 | + return isset(self::$data[$this->prefix . $name]); |
|
| 139 | 139 | break; |
| 140 | 140 | |
| 141 | 141 | case CACHER_XCACHE: |
| 142 | - return xcache_isset($this->prefix.$name) && ($this->__get($name) !== null); |
|
| 142 | + return xcache_isset($this->prefix . $name) && ($this->__get($name) !== null); |
|
| 143 | 143 | break; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | public function unset_by_prefix($prefix_unset = '') { |
| 162 | 162 | static $array_clear; |
| 163 | - !$array_clear ? $array_clear = function(&$v,$k,$p) { |
|
| 163 | + !$array_clear ? $array_clear = function(&$v, $k, $p) { |
|
| 164 | 164 | strpos($k, $p) === 0 ? $v = NULL : false; |
| 165 | 165 | } : false; |
| 166 | 166 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | break; |
| 173 | 173 | |
| 174 | 174 | case CACHER_XCACHE: |
| 175 | - if(!function_exists('xcache_unset_by_prefix')) { |
|
| 175 | + if (!function_exists('xcache_unset_by_prefix')) { |
|
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | return xcache_unset_by_prefix($this->prefix . $prefix_unset); |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | protected function make_element_name($args, $diff = 0) { |
| 189 | 189 | $num_args = count($args); |
| 190 | 190 | |
| 191 | - if($num_args < 1) { |
|
| 191 | + if ($num_args < 1) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $name = ''; |
| 196 | 196 | $aName = array(); |
| 197 | - for($i = 0; $i <= $num_args - 1 - $diff; $i++) { |
|
| 197 | + for ($i = 0; $i <= $num_args - 1 - $diff; $i++) { |
|
| 198 | 198 | $name .= "[{$args[$i]}]"; |
| 199 | 199 | array_unshift($aName, $name); |
| 200 | 200 | } |
@@ -206,15 +206,15 @@ discard block |
||
| 206 | 206 | $args = func_get_args(); |
| 207 | 207 | $name = $this->make_element_name($args, 1); |
| 208 | 208 | |
| 209 | - if(!$name) { |
|
| 209 | + if (!$name) { |
|
| 210 | 210 | return NULL; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if($this->$name[0] === NULL) { |
|
| 214 | - for($i = count($name) - 1; $i > 0; $i--) { |
|
| 213 | + if ($this->$name[0] === NULL) { |
|
| 214 | + for ($i = count($name) - 1; $i > 0; $i--) { |
|
| 215 | 215 | $cName = "{$name[$i]}_COUNT"; |
| 216 | - $cName1 = "{$name[$i-1]}_COUNT"; |
|
| 217 | - if($this->$cName1 == NULL || $i == 1) { |
|
| 216 | + $cName1 = "{$name[$i - 1]}_COUNT"; |
|
| 217 | + if ($this->$cName1 == NULL || $i == 1) { |
|
| 218 | 218 | $this->$cName++; |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | public function array_get() { |
| 228 | 228 | $name = $this->make_element_name(func_get_args()); |
| 229 | - if(!$name) { |
|
| 229 | + if (!$name) { |
|
| 230 | 230 | return NULL; |
| 231 | 231 | } |
| 232 | 232 | return $this->$name[0]; |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | public function array_count() { |
| 236 | 236 | $name = $this->make_element_name(func_get_args()); |
| 237 | - if(!$name) { |
|
| 237 | + if (!$name) { |
|
| 238 | 238 | return 0; |
| 239 | 239 | } |
| 240 | 240 | $cName = "{$name[0]}_COUNT"; |
| 241 | 241 | $retVal = $this->$cName; |
| 242 | - if(!$retVal) { |
|
| 242 | + if (!$retVal) { |
|
| 243 | 243 | $retVal = NULL; |
| 244 | 244 | } |
| 245 | 245 | return $retVal; |
@@ -248,18 +248,18 @@ discard block |
||
| 248 | 248 | public function array_unset() { |
| 249 | 249 | $name = $this->make_element_name(func_get_args()); |
| 250 | 250 | |
| 251 | - if(!$name) { |
|
| 251 | + if (!$name) { |
|
| 252 | 252 | return false; |
| 253 | 253 | } |
| 254 | 254 | $this->unset_by_prefix($name[0]); |
| 255 | 255 | |
| 256 | - for($i = 1; $i < count($name); $i++) { |
|
| 256 | + for ($i = 1; $i < count($name); $i++) { |
|
| 257 | 257 | $cName = "{$name[$i]}_COUNT"; |
| 258 | - $cName1 = "{$name[$i-1]}_COUNT"; |
|
| 258 | + $cName1 = "{$name[$i - 1]}_COUNT"; |
|
| 259 | 259 | |
| 260 | - if($i == 1 || $this->$cName1 === NULL) { |
|
| 260 | + if ($i == 1 || $this->$cName1 === NULL) { |
|
| 261 | 261 | $this->$cName--; |
| 262 | - if($this->$cName <= 0) { |
|
| 262 | + if ($this->$cName <= 0) { |
|
| 263 | 263 | unset($this->$cName); |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | $this->sql_index_field = "{$table_name}_name"; |
| 320 | 320 | $this->sql_value_field = "{$table_name}_value"; |
| 321 | 321 | |
| 322 | - if(!$this->_DB_LOADED) { |
|
| 322 | + if (!$this->_DB_LOADED) { |
|
| 323 | 323 | $this->db_loadAll(); |
| 324 | 324 | } |
| 325 | 325 | } |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | public function db_loadItem($index) { |
| 336 | 336 | $result = null; |
| 337 | - if($index) { |
|
| 337 | + if ($index) { |
|
| 338 | 338 | $index_safe = db_escape($index); |
| 339 | 339 | $result = doquery("SELECT `{$this->sql_value_field}` FROM `{{{$this->table_name}}}` WHERE `{$this->sql_index_field}` = '{$index_safe}' FOR UPDATE", true); |
| 340 | 340 | // В две строки - что бы быть уверенным в порядке выполнения |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $this->loadDefaults(); |
| 349 | 349 | |
| 350 | 350 | $query = doquery("SELECT * FROM {{{$this->table_name}}} FOR UPDATE;"); |
| 351 | - while($row = db_fetch($query)) { |
|
| 351 | + while ($row = db_fetch($query)) { |
|
| 352 | 352 | $this->$row[$this->sql_index_field] = $row[$this->sql_value_field]; |
| 353 | 353 | } |
| 354 | 354 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | public function loadDefaults() { |
| 359 | - foreach($this->defaults as $defName => $defValue) { |
|
| 359 | + foreach ($this->defaults as $defName => $defValue) { |
|
| 360 | 360 | $this->$defName = $defValue; |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | public function db_saveItem($item_list, $value = NULL) { |
| 375 | - if(empty($item_list)) { |
|
| 375 | + if (empty($item_list)) { |
|
| 376 | 376 | return; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | |
| 381 | 381 | // Сначала записываем данные в базу - что бы поймать все блокировки |
| 382 | 382 | $qry = array(); |
| 383 | - foreach($item_list as $item_name => $item_value) { |
|
| 384 | - if($item_name) { |
|
| 383 | + foreach ($item_list as $item_name => $item_value) { |
|
| 384 | + if ($item_name) { |
|
| 385 | 385 | $item_value = db_escape($item_value === NULL ? $this->$item_name : $item_value); |
| 386 | 386 | $item_name = db_escape($item_name); |
| 387 | 387 | $qry[] = "('{$item_name}', '{$item_value}')"; |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | doquery("REPLACE INTO `{{" . $this->table_name . "}}` (`{$this->sql_index_field}`, `{$this->sql_value_field}`) VALUES " . implode(',', $qry) . ";"); |
| 391 | 391 | |
| 392 | 392 | // И только после взятия блокировок - меняем значения в кэше |
| 393 | - foreach($item_list as $item_name => $item_value) { |
|
| 394 | - if($item_name && $item_value !== NULL) { |
|
| 393 | + foreach ($item_list as $item_name => $item_value) { |
|
| 394 | + if ($item_name && $item_value !== NULL) { |
|
| 395 | 395 | $this->$item_name = $item_value; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -419,9 +419,9 @@ discard block |
||
| 419 | 419 | 'advGoogleLeftMenuCode' => '(Place here code for banner)', |
| 420 | 420 | |
| 421 | 421 | // Alliance bonus calculations |
| 422 | - 'ali_bonus_algorithm' => 0, // Bonus calculation algorithm |
|
| 422 | + 'ali_bonus_algorithm' => 0, // Bonus calculation algorithm |
|
| 423 | 423 | 'ali_bonus_brackets' => 10, // Brackets count for ALI_BONUS_BY_RANK |
| 424 | - 'ali_bonus_brackets_divisor' => 10,// Bonus divisor for ALI_BONUS_BY_RANK |
|
| 424 | + 'ali_bonus_brackets_divisor' => 10, // Bonus divisor for ALI_BONUS_BY_RANK |
|
| 425 | 425 | 'ali_bonus_divisor' => 10000000, // Rank divisor for ALI_BONUS_BY_POINTS |
| 426 | 426 | 'ali_bonus_members' => 10, // Minumum alliace size to start using bonus |
| 427 | 427 | |
@@ -452,25 +452,25 @@ discard block |
||
| 452 | 452 | 'deuterium_basic_income' => 0, |
| 453 | 453 | 'eco_scale_storage' => 1, |
| 454 | 454 | 'eco_stockman_fleet' => '', // Black Market - Starting amount of s/h ship merchant to sell |
| 455 | - 'eco_stockman_fleet_populate' => 1, // Populate empty Stockman fleet with ships or not |
|
| 455 | + 'eco_stockman_fleet_populate' => 1, // Populate empty Stockman fleet with ships or not |
|
| 456 | 456 | 'empire_mercenary_base_period' => PERIOD_MONTH, // Base |
| 457 | 457 | 'empire_mercenary_temporary' => 0, // Temporary empire-wide mercenaries |
| 458 | 458 | 'energy_basic_income' => 0, |
| 459 | 459 | |
| 460 | 460 | // Bashing protection settings |
| 461 | - 'fleet_bashing_attacks' => 3, // Max amount of attack per wave - 3 by default |
|
| 462 | - 'fleet_bashing_interval' => 1800, // Maximum interval between attacks when they still count as one wave - 30m by default |
|
| 463 | - 'fleet_bashing_scope' => 86400, // Interval on which bashing waves counts - 24h by default |
|
| 464 | - 'fleet_bashing_war_delay' => 43200, // Delay before start bashing after declaring war to alliance - 12h by default |
|
| 465 | - 'fleet_bashing_waves' => 3, // Max amount of waves per day - 3 by default |
|
| 461 | + 'fleet_bashing_attacks' => 3, // Max amount of attack per wave - 3 by default |
|
| 462 | + 'fleet_bashing_interval' => 1800, // Maximum interval between attacks when they still count as one wave - 30m by default |
|
| 463 | + 'fleet_bashing_scope' => 86400, // Interval on which bashing waves counts - 24h by default |
|
| 464 | + 'fleet_bashing_war_delay' => 43200, // Delay before start bashing after declaring war to alliance - 12h by default |
|
| 465 | + 'fleet_bashing_waves' => 3, // Max amount of waves per day - 3 by default |
|
| 466 | 466 | |
| 467 | 467 | 'Fleet_Cdr' => 30, |
| 468 | 468 | 'fleet_speed' => 1, |
| 469 | 469 | |
| 470 | 470 | 'fleet_update_interval' => 4, |
| 471 | 471 | |
| 472 | - 'game_adminEmail' => 'root@localhost', // Admin's email to show to users |
|
| 473 | - 'game_counter' => 0, // Does built-in page hit counter is on? |
|
| 472 | + 'game_adminEmail' => 'root@localhost', // Admin's email to show to users |
|
| 473 | + 'game_counter' => 0, // Does built-in page hit counter is on? |
|
| 474 | 474 | // Defaults |
| 475 | 475 | 'game_default_language' => 'ru', |
| 476 | 476 | 'game_default_skin' => 'skins/EpicBlue/', |
@@ -484,13 +484,13 @@ discard block |
||
| 484 | 484 | 'game_maxSystem' => 199, |
| 485 | 485 | 'game_maxPlanet' => 15, |
| 486 | 486 | // Game global settings |
| 487 | - 'game_mode' => 0, // 0 - SuperNova, 1 - oGame |
|
| 487 | + 'game_mode' => 0, // 0 - SuperNova, 1 - oGame |
|
| 488 | 488 | 'game_name' => 'SuperNova', // Server name (would be on banners and on top of left menu) |
| 489 | 489 | |
| 490 | 490 | 'game_news_actual' => 259200, // How long announcement would be marked as "New". In seconds. Default - 3 days |
| 491 | - 'game_news_overview' => 3, // How much last news to show in Overview page |
|
| 491 | + 'game_news_overview' => 3, // How much last news to show in Overview page |
|
| 492 | 492 | // Noob protection |
| 493 | - 'game_noob_factor' => 5, // Multiplier to divide "stronger" and "weaker" users |
|
| 493 | + 'game_noob_factor' => 5, // Multiplier to divide "stronger" and "weaker" users |
|
| 494 | 494 | 'game_noob_points' => 5000, // Below this point user threated as noob. 0 to disable |
| 495 | 495 | |
| 496 | 496 | 'game_multiaccount_enabled' => 0, // 1 - allow interactions for players with same IP (multiaccounts) |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | 'payment_currency_exchange_wmu' => 30, |
| 540 | 540 | 'payment_currency_exchange_wmz' => 1, |
| 541 | 541 | |
| 542 | - 'payment_lot_price' => 1, // Lot price in default currency |
|
| 543 | - 'payment_lot_size' => 2500, // Lot size. Also service as minimum amount of DM that could be bought with one transaction |
|
| 542 | + 'payment_lot_price' => 1, // Lot price in default currency |
|
| 543 | + 'payment_lot_size' => 2500, // Lot size. Also service as minimum amount of DM that could be bought with one transaction |
|
| 544 | 544 | |
| 545 | 545 | 'planet_teleport_cost' => 50000, // |
| 546 | 546 | 'planet_teleport_timeout' => 86400, // |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | 'resource_multiplier' => 1, |
| 559 | 559 | |
| 560 | 560 | //Roleplay system |
| 561 | - 'rpg_bonus_divisor' => 10, // Amount of DM referral shoud get for partner have 1 DM bonus |
|
| 561 | + 'rpg_bonus_divisor' => 10, // Amount of DM referral shoud get for partner have 1 DM bonus |
|
| 562 | 562 | 'rpg_bonus_minimum' => 10000, // Minimum DM ammount for starting paying bonuses to affiliate |
| 563 | 563 | |
| 564 | 564 | // Black Market - General |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | public static function getInstance($gamePrefix = 'sn_', $table_name = 'config') { |
| 647 | - if(!isset(self::$cacheObject)) { |
|
| 647 | + if (!isset(self::$cacheObject)) { |
|
| 648 | 648 | $className = get_class(); |
| 649 | 649 | self::$cacheObject = new $className($gamePrefix, $table_name); |
| 650 | 650 | } |
@@ -18,6 +18,11 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!! |
| 20 | 20 | // TODO - OK 4.6 |
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param integer $confirmation_type_safe |
|
| 24 | + * @param string $email_unsafe |
|
| 25 | + */ |
|
| 21 | 26 | public function db_confirmation_get_latest_by_type_and_email($confirmation_type_safe, $email_unsafe) { |
| 22 | 27 | $email_safe = $this->db->db_escape($email_unsafe); |
| 23 | 28 | |
@@ -26,12 +31,21 @@ discard block |
||
| 26 | 31 | `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}' ORDER BY create_time DESC LIMIT 1;", true); |
| 27 | 32 | } |
| 28 | 33 | // TODO - OK 4.6 |
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param integer $confirmation_type_safe |
|
| 37 | + */ |
|
| 29 | 38 | public function db_confirmation_delete_by_type_and_email($confirmation_type_safe, $email_unsafe) { |
| 30 | 39 | $email_safe = $this->db->db_escape($email_unsafe); |
| 31 | 40 | |
| 32 | 41 | return $this->db->doquery("DELETE FROM {{confirmations}} WHERE `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}'"); |
| 33 | 42 | } |
| 34 | 43 | // TODO - OK 4.6 |
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param integer $confirmation_type_safe |
|
| 47 | + * @param string $email_unsafe |
|
| 48 | + */ |
|
| 35 | 49 | public function db_confirmation_get_unique_code_by_type_and_email($confirmation_type_safe, $email_unsafe) { |
| 36 | 50 | $email_safe = $this->db->db_escape($email_unsafe); |
| 37 | 51 | |
@@ -50,6 +64,11 @@ discard block |
||
| 50 | 64 | return $confirm_code_unsafe; |
| 51 | 65 | } |
| 52 | 66 | // TODO - OK 4.6 |
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param integer $confirmation_type_safe |
|
| 70 | + * @param string $confirmation_code_unsafe |
|
| 71 | + */ |
|
| 53 | 72 | public function db_confirmation_get_by_type_and_code($confirmation_type_safe, $confirmation_code_unsafe) { |
| 54 | 73 | $confirmation_code_safe = $this->db->db_escape($confirmation_code_unsafe); |
| 55 | 74 | |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | // $query = static::$db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' AND `type` = {$confirmation_type_safe} FOR UPDATE", true); |
| 42 | 42 | // Тип не нужен для проверки - код подтверждения должен быть уникален от слова "совсем" |
| 43 | 43 | $query = $this->db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' FOR UPDATE", true); |
| 44 | - } while($query); |
|
| 44 | + } while ($query); |
|
| 45 | 45 | |
| 46 | 46 | $this->db->doquery( |
| 47 | 47 | "REPLACE INTO {{confirmations}} |
@@ -829,10 +829,17 @@ |
||
| 829 | 829 | |
| 830 | 830 | // OK v4.5 |
| 831 | 831 | // TODO - REMEMBER_ME |
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * @param integer $period |
|
| 835 | + */ |
|
| 832 | 836 | protected static function cookie_set($value, $impersonate = false, $period = null) { |
| 833 | 837 | sn_setcookie($impersonate ? SN_COOKIE_U_I : SN_COOKIE_U, $value, $period === null ? SN_TIME_NOW + PERIOD_YEAR : $period, SN_ROOT_RELATIVE); |
| 834 | 838 | } |
| 835 | 839 | |
| 840 | + /** |
|
| 841 | + * @param string $message |
|
| 842 | + */ |
|
| 836 | 843 | protected static function flog($message, $die = false) { |
| 837 | 844 | if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
| 838 | 845 | return; |
@@ -199,18 +199,18 @@ discard block |
||
| 199 | 199 | // TODO Хотя тут может получится вечный цикл - ПОДУМАТЬ |
| 200 | 200 | // TODO Тут же можно пробовать провести попытку слияния аккаунтов - хотя это и очень небезопасно |
| 201 | 201 | |
| 202 | - if(sys_get_param('login_player_register_logout')) { |
|
| 202 | + if (sys_get_param('login_player_register_logout')) { |
|
| 203 | 203 | $this->logout(); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | $original_suggest = ''; |
| 207 | 207 | // Смотрим - есть ли у нас данные от пользователя |
| 208 | - if(($player_name_submitted = sys_get_param('submit_player_name'))) { |
|
| 208 | + if (($player_name_submitted = sys_get_param('submit_player_name'))) { |
|
| 209 | 209 | // Попытка регистрации нового игрока из данных, введенных пользователем |
| 210 | 210 | $this->player_suggested_name = sys_get_param_str_unsafe('player_suggested_name'); |
| 211 | 211 | } else { |
| 212 | - foreach($this->providers_authorised as $provider) { |
|
| 213 | - if($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5 |
|
| 212 | + foreach ($this->providers_authorised as $provider) { |
|
| 213 | + if ($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5 |
|
| 214 | 214 | $original_suggest = $provider->player_name_suggest(); |
| 215 | 215 | break; |
| 216 | 216 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // Если у нас провайдеры не дают имени и пользователь не дал свой вариант - это у нас первый логин в игру |
| 221 | - if(!$this->player_suggested_name) { |
|
| 221 | + if (!$this->player_suggested_name) { |
|
| 222 | 222 | $max_user_id = db_player_get_max_id(); // 4.5 |
| 223 | 223 | // TODO - предлагать имя игрока по локали |
| 224 | 224 | |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | sn_db_transaction_rollback(); |
| 228 | 228 | $this->player_suggested_name = 'Emperor ' . mt_rand($max_user_id + 1, $max_user_id + 1000); |
| 229 | 229 | sn_db_transaction_start(); |
| 230 | - } while(db_player_name_exists($this->player_suggested_name)); |
|
| 230 | + } while (db_player_name_exists($this->player_suggested_name)); |
|
| 231 | 231 | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if($player_name_submitted) { |
|
| 234 | + if ($player_name_submitted) { |
|
| 235 | 235 | $this->register_player_db_create($this->player_suggested_name); // OK 4.5 |
| 236 | - if($this->register_status == LOGIN_SUCCESS) { |
|
| 236 | + if ($this->register_status == LOGIN_SUCCESS) { |
|
| 237 | 237 | sys_redirect(SN_ROOT_VIRTUAL . 'overview.php'); |
| 238 | - } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) { |
|
| 238 | + } elseif ($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) { |
|
| 239 | 239 | // self::$player_suggested_name .= ' ' . $this->account->account_id; |
| 240 | 240 | } |
| 241 | 241 | // if(self::$login_status != LOGIN_SUCCESS) { |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | : false |
| 260 | 260 | ); |
| 261 | 261 | |
| 262 | - if($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
| 262 | + if ($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
| 263 | 263 | $prohibited_characters = array_map(function($value) { |
| 264 | 264 | return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'"; |
| 265 | 265 | }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED)); |
@@ -293,27 +293,27 @@ discard block |
||
| 293 | 293 | global $sn_module_list, $lang; |
| 294 | 294 | |
| 295 | 295 | // !self::$is_init ? self::init() : false; |
| 296 | - if(empty($sn_module_list['auth'])) { |
|
| 296 | + if (empty($sn_module_list['auth'])) { |
|
| 297 | 297 | die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}'); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false; |
| 301 | 301 | !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false; |
| 302 | - !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false; |
|
| 302 | + !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false; |
|
| 303 | 303 | |
| 304 | 304 | $this->auth_reset(); // OK v4.5 |
| 305 | 305 | |
| 306 | 306 | $this->providers = array(); |
| 307 | - foreach($sn_module_list['auth'] as $module_name => $module) { |
|
| 307 | + foreach ($sn_module_list['auth'] as $module_name => $module) { |
|
| 308 | 308 | $this->providers[$module->provider_id] = $module; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым! |
| 312 | 312 | |
| 313 | - foreach($this->providers as $provider_id => $provider) { |
|
| 313 | + foreach ($this->providers as $provider_id => $provider) { |
|
| 314 | 314 | $login_status = $provider->login(); // OK v4.5 |
| 315 | 315 | self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? $lang['sys_login_messages'][$provider->account_login_status] : dump($provider))); |
| 316 | - if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) { |
|
| 316 | + if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) { |
|
| 317 | 317 | $this->providers_authorised[$provider_id] = &$this->providers[$provider_id]; |
| 318 | 318 | |
| 319 | 319 | $this->user_id_to_provider = array_replace_recursive( |
@@ -321,15 +321,15 @@ discard block |
||
| 321 | 321 | // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5 |
| 322 | 322 | PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5 |
| 323 | 323 | ); |
| 324 | - } elseif($login_status != LOGIN_UNDEFINED) { |
|
| 324 | + } elseif ($login_status != LOGIN_UNDEFINED) { |
|
| 325 | 325 | $this->provider_error_list[$provider_id] = $login_status; |
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if(empty($this->providers_authorised)) { |
|
| 329 | + if (empty($this->providers_authorised)) { |
|
| 330 | 330 | // Ни один аккаунт не авторизирован |
| 331 | 331 | // Проверяем - есть ли у нас ошибки в аккаунтах? |
| 332 | - if(!empty($this->provider_error_list)) { |
|
| 332 | + if (!empty($this->provider_error_list)) { |
|
| 333 | 333 | // Если есть - выводим их |
| 334 | 334 | self::$login_status = reset($this->provider_error_list); |
| 335 | 335 | } |
@@ -344,12 +344,12 @@ discard block |
||
| 344 | 344 | // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users` |
| 345 | 345 | |
| 346 | 346 | // Остались ли у нас в списке доступные игроки? |
| 347 | - if(empty($this->accessible_user_row_list)) { |
|
| 347 | + if (empty($this->accessible_user_row_list)) { |
|
| 348 | 348 | // Нет ни одного игрока ни на одном авторизированном аккаунте |
| 349 | 349 | // Надо регать нового игрока |
| 350 | 350 | |
| 351 | 351 | // Сейчас происходит процесс регистрации игрока? |
| 352 | - if(!$this->is_player_register) { |
|
| 352 | + if (!$this->is_player_register) { |
|
| 353 | 353 | // Нет - отправляем на процесс регистрации |
| 354 | 354 | $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id')); |
| 355 | 355 | sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : '')); |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | // Да, есть доступные игроки, которые так же прописаны в базе |
| 359 | 359 | $this->get_active_user(); // 4.5 |
| 360 | 360 | |
| 361 | - if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) { |
|
| 361 | + if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) { |
|
| 362 | 362 | $a_user = db_user_by_id($this->is_impersonating); |
| 363 | 363 | $this->impersonator_username = $a_user['username']; |
| 364 | 364 | } |
@@ -366,9 +366,9 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | //Прописываем текущего игрока на все авторизированные аккаунты |
| 368 | 368 | // TODO - ИЛИ ВСЕХ ИГРОКОВ?? |
| 369 | - if(empty($this->is_impersonating)) { |
|
| 370 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
| 371 | - if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) { |
|
| 369 | + if (empty($this->is_impersonating)) { |
|
| 370 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
| 371 | + if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) { |
|
| 372 | 372 | // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']); |
| 373 | 373 | PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']); |
| 374 | 374 | $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true; |
@@ -378,9 +378,9 @@ discard block |
||
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if(empty(self::$user['id'])) { |
|
| 381 | + if (empty(self::$user['id'])) { |
|
| 382 | 382 | self::cookie_set(''); // OK 4.5 |
| 383 | - } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) { |
|
| 383 | + } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) { |
|
| 384 | 384 | self::cookie_set(self::$user['id']); // OK 4.5 |
| 385 | 385 | } |
| 386 | 386 | |
@@ -399,21 +399,21 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | // OK v4.7 |
| 401 | 401 | public function logout($redirect = true) { |
| 402 | - if(!empty($_COOKIE[SN_COOKIE_U_I])) { |
|
| 402 | + if (!empty($_COOKIE[SN_COOKIE_U_I])) { |
|
| 403 | 403 | self::cookie_set($_COOKIE[SN_COOKIE_U_I]); |
| 404 | 404 | self::cookie_set(0, true); |
| 405 | 405 | self::$main_provider->logout(); |
| 406 | 406 | } else { |
| 407 | - foreach($this->providers as $provider_name => $provider) { |
|
| 407 | + foreach ($this->providers as $provider_name => $provider) { |
|
| 408 | 408 | $provider->logout(); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | self::cookie_set(0); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - if($redirect === true) { |
|
| 414 | + if ($redirect === true) { |
|
| 415 | 415 | sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php')); |
| 416 | - } elseif($redirect !== false) { |
|
| 416 | + } elseif ($redirect !== false) { |
|
| 417 | 417 | sys_redirect($redirect); |
| 418 | 418 | } |
| 419 | 419 | } |
@@ -424,15 +424,15 @@ discard block |
||
| 424 | 424 | * @param $user_selected |
| 425 | 425 | */ |
| 426 | 426 | public function impersonate($user_selected) { |
| 427 | - if($_COOKIE[SN_COOKIE_U_I]) { |
|
| 427 | + if ($_COOKIE[SN_COOKIE_U_I]) { |
|
| 428 | 428 | die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) { |
|
| 431 | + if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) { |
|
| 432 | 432 | die('You can\'t impersonate - too low level'); // TODO: Log it |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if($this->auth_level_max_local <= $user_selected['authlevel']) { |
|
| 435 | + if ($this->auth_level_max_local <= $user_selected['authlevel']) { |
|
| 436 | 436 | die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it |
| 437 | 437 | } |
| 438 | 438 | |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]); |
| 441 | 441 | $account_to_impersonate = new Account(self::$main_provider->db); |
| 442 | 442 | $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']); |
| 443 | - if(!$account_to_impersonate->is_exists) { |
|
| 443 | + if (!$account_to_impersonate->is_exists) { |
|
| 444 | 444 | die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it |
| 445 | 445 | } |
| 446 | 446 | self::$main_provider->impersonate($account_to_impersonate); |
@@ -466,12 +466,12 @@ discard block |
||
| 466 | 466 | public function password_check($password_unsafe) { |
| 467 | 467 | $result = false; |
| 468 | 468 | |
| 469 | - if(empty($this->providers_authorised)) { |
|
| 469 | + if (empty($this->providers_authorised)) { |
|
| 470 | 470 | // TODO - такого быть не может! |
| 471 | 471 | self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true); |
| 472 | 472 | } else { |
| 473 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
| 474 | - if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) { |
|
| 473 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
| 474 | + if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) { |
|
| 475 | 475 | $result = $result || $provider->password_check($password_unsafe); |
| 476 | 476 | } |
| 477 | 477 | } |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | public function password_change($old_password_unsafe, $new_password_unsafe) { |
| 493 | 493 | global $lang; |
| 494 | 494 | |
| 495 | - if(empty($this->providers_authorised)) { |
|
| 495 | + if (empty($this->providers_authorised)) { |
|
| 496 | 496 | // TODO - такого быть не может! |
| 497 | 497 | self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true); |
| 498 | 498 | return false; |
@@ -505,8 +505,8 @@ discard block |
||
| 505 | 505 | $salt_unsafe = self::password_salt_generate(); |
| 506 | 506 | |
| 507 | 507 | $providers_changed_password = array(); |
| 508 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
| 509 | - if( |
|
| 508 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
| 509 | + if ( |
|
| 510 | 510 | !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE) |
| 511 | 511 | || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe) |
| 512 | 512 | ) { |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id); |
| 519 | 519 | |
| 520 | 520 | // Рассылаем уведомления о смене пароля в ЛС |
| 521 | - foreach($account_translation as $user_id => $provider_info) { |
|
| 521 | + foreach ($account_translation as $user_id => $provider_info) { |
|
| 522 | 522 | // TODO - УКазывать тип аккаунта, на котором сменён пароль |
| 523 | 523 | msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, |
| 524 | 524 | $lang['sys_administration'], $lang['sys_login_register_message_title'], |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | sn_db_transaction_start(); |
| 566 | 566 | // Проверить наличие такого имени в истории имён |
| 567 | 567 | |
| 568 | - if(db_player_name_exists($player_name_unsafe)) { |
|
| 568 | + if (db_player_name_exists($player_name_unsafe)) { |
|
| 569 | 569 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR); |
| 570 | 570 | } |
| 571 | 571 | |
@@ -573,11 +573,11 @@ discard block |
||
| 573 | 573 | $player_language = ''; |
| 574 | 574 | $player_email = ''; |
| 575 | 575 | // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте... |
| 576 | - foreach($this->providers_authorised as $provider) { |
|
| 577 | - if(!$player_language && $provider->account->account_language) { |
|
| 576 | + foreach ($this->providers_authorised as $provider) { |
|
| 577 | + if (!$player_language && $provider->account->account_language) { |
|
| 578 | 578 | $player_language = $provider->account->account_language; |
| 579 | 579 | } |
| 580 | - if(!$player_email && $provider->account->account_email) { |
|
| 580 | + if (!$player_email && $provider->account->account_email) { |
|
| 581 | 581 | $player_email = $provider->account->account_email; |
| 582 | 582 | } |
| 583 | 583 | } |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | )); |
| 594 | 594 | // Зарегестрировать на него аккаунты из self::$accounts_authorised |
| 595 | 595 | $a_user = self::$user; |
| 596 | - foreach($this->providers_authorised as $provider) { |
|
| 596 | + foreach ($this->providers_authorised as $provider) { |
|
| 597 | 597 | // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор |
| 598 | 598 | // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте... |
| 599 | 599 | // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']); |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | |
| 606 | 606 | sn_db_transaction_commit(); |
| 607 | 607 | $this->register_status = LOGIN_SUCCESS; |
| 608 | - } catch(Exception $e) { |
|
| 608 | + } catch (Exception $e) { |
|
| 609 | 609 | sn_db_transaction_rollback(); |
| 610 | 610 | |
| 611 | 611 | // Если старое имя занято |
@@ -624,10 +624,10 @@ discard block |
||
| 624 | 624 | // Пробиваем все ИД игроков по базе - есть ли вообще такие записи |
| 625 | 625 | // Вообще-то это не особо нужно - у нас по определению стоят констраинты |
| 626 | 626 | // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров |
| 627 | - foreach($this->user_id_to_provider as $user_id => $cork) { |
|
| 627 | + foreach ($this->user_id_to_provider as $user_id => $cork) { |
|
| 628 | 628 | $user = db_user_by_id($user_id); |
| 629 | 629 | // Если записи игрока в БД не существует? |
| 630 | - if(empty($user['id'])) { |
|
| 630 | + if (empty($user['id'])) { |
|
| 631 | 631 | // Удаляем этого и переходим к следующему |
| 632 | 632 | unset($this->user_id_to_provider[$user_id]); |
| 633 | 633 | // Де-регистрируем игрока из таблицы трансляции игроков |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | // OK v4.5 |
| 649 | 649 | protected function get_active_user() { |
| 650 | 650 | // Проверяем куку "текущего игрока" из браузера |
| 651 | - if( |
|
| 651 | + if ( |
|
| 652 | 652 | // Кука не пустая |
| 653 | 653 | ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U]) |
| 654 | 654 | // И в куке находится ID |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов |
| 676 | - if(empty(self::$user['id'])) { |
|
| 676 | + if (empty(self::$user['id'])) { |
|
| 677 | 677 | // Берем первого из доступных |
| 678 | 678 | // TODO - default_user |
| 679 | 679 | self::$user = reset($this->accessible_user_row_list); |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | |
| 698 | 698 | $result = array(); |
| 699 | 699 | |
| 700 | - if($user_id && empty($this->is_impersonating)) { |
|
| 700 | + if ($user_id && empty($this->is_impersonating)) { |
|
| 701 | 701 | // self::db_counter_insert(); |
| 702 | 702 | self::$device->db_counter_insert($user_id); |
| 703 | 703 | |
@@ -705,12 +705,12 @@ discard block |
||
| 705 | 705 | |
| 706 | 706 | sys_user_options_unpack($user); |
| 707 | 707 | |
| 708 | - if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) { |
|
| 708 | + if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) { |
|
| 709 | 709 | $user['banaday'] = 0; |
| 710 | 710 | $user['vacation'] = SN_TIME_NOW; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip']; |
|
| 713 | + $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip']; |
|
| 714 | 714 | $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain']; |
| 715 | 715 | |
| 716 | 716 | $result[F_BANNED_STATUS] = $user['banaday']; |
@@ -724,9 +724,9 @@ discard block |
||
| 724 | 724 | ); |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - if($extra = $config->security_ban_extra) { |
|
| 727 | + if ($extra = $config->security_ban_extra) { |
|
| 728 | 728 | $extra = explode(',', $extra); |
| 729 | - array_walk($extra,'trim'); |
|
| 729 | + array_walk($extra, 'trim'); |
|
| 730 | 730 | in_array(self::$device->device_id, $extra) and die(); |
| 731 | 731 | } |
| 732 | 732 | |
@@ -762,21 +762,21 @@ discard block |
||
| 762 | 762 | protected function register_player_name_validate($player_name_unsafe) { |
| 763 | 763 | // TODO - переделать под RAW-строки |
| 764 | 764 | // Если имя игрока пустое - NO GO! |
| 765 | - if(trim($player_name_unsafe) == '') { |
|
| 765 | + if (trim($player_name_unsafe) == '') { |
|
| 766 | 766 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR); |
| 767 | 767 | } |
| 768 | 768 | // Проверяем, что бы в начале и конце не было пустых символов |
| 769 | - if($player_name_unsafe != trim($player_name_unsafe)) { |
|
| 769 | + if ($player_name_unsafe != trim($player_name_unsafe)) { |
|
| 770 | 770 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR); |
| 771 | 771 | } |
| 772 | 772 | // Если логин имеет запрещенные символы - NO GO! |
| 773 | - if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
| 773 | + if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
| 774 | 774 | // TODO - выдавать в сообщение об ошибке список запрещенных символов |
| 775 | 775 | // TODO - заранее извещать игрока, какие символы являются запрещенными |
| 776 | 776 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR); |
| 777 | 777 | } |
| 778 | 778 | // Если логин меньше минимальной длины - NO GO! |
| 779 | - if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) { |
|
| 779 | + if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) { |
|
| 780 | 780 | // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока |
| 781 | 781 | // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени |
| 782 | 782 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR); |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | protected static function flog($message, $die = false) { |
| 837 | - if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
| 837 | + if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
| 838 | 838 | return; |
| 839 | 839 | } |
| 840 | 840 | list($called, $caller) = debug_backtrace(false); |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false; |
| 848 | 848 | |
| 849 | 849 | classSupernova::log_file("$message - $caller_name"); |
| 850 | - if($die) { |
|
| 850 | + if ($die) { |
|
| 851 | 851 | // pdump($caller); |
| 852 | 852 | // pdump(debug_backtrace(false)); |
| 853 | 853 | $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>"); |
@@ -180,6 +180,9 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
| 183 | + /** |
|
| 184 | + * @param string $query |
|
| 185 | + */ |
|
| 183 | 186 | function security_watch_user_queries($query) { |
| 184 | 187 | // TODO Заменить это на новый логгер |
| 185 | 188 | global $config, $is_watching, $user, $debug; |
@@ -202,6 +205,9 @@ discard block |
||
| 202 | 205 | } |
| 203 | 206 | |
| 204 | 207 | |
| 208 | + /** |
|
| 209 | + * @param string $query |
|
| 210 | + */ |
|
| 205 | 211 | function security_query_check_bad_words($query) { |
| 206 | 212 | global $user, $dm_change_legit, $mm_change_legit; |
| 207 | 213 | |
@@ -76,23 +76,23 @@ discard block |
||
| 76 | 76 | function sn_db_connect($external_db_settings = null) { |
| 77 | 77 | $this->db_disconnect(); |
| 78 | 78 | |
| 79 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
| 79 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
| 80 | 80 | $this->dbsettings = $external_db_settings; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if(empty($this->dbsettings)) { |
|
| 83 | + if (empty($this->dbsettings)) { |
|
| 84 | 84 | $this->load_db_settings(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
| 88 | - if(!empty($this->dbsettings)) { |
|
| 88 | + if (!empty($this->dbsettings)) { |
|
| 89 | 89 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
| 90 | 90 | $this->driver = new $driver_name(); |
| 91 | 91 | $this->db_prefix = $this->dbsettings['prefix']; |
| 92 | 92 | |
| 93 | 93 | $this->connected = $this->connected || $this->driver_connect(); |
| 94 | 94 | |
| 95 | - if($this->connected) { |
|
| 95 | + if ($this->connected) { |
|
| 96 | 96 | $this->table_list = $this->db_get_table_list(); |
| 97 | 97 | // TODO Проверка на пустоту |
| 98 | 98 | } |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | function driver_connect() { |
| 107 | 107 | global $debug; |
| 108 | 108 | |
| 109 | - if(!is_object($this->driver)) { |
|
| 109 | + if (!is_object($this->driver)) { |
|
| 110 | 110 | $debug->error_fatal('DB Error - No driver for MySQL found!'); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
| 113 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
| 114 | 114 | $debug->error_fatal('DB Error - WRONG MySQL driver!'); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | function db_disconnect() { |
| 121 | - if($this->connected) { |
|
| 121 | + if ($this->connected) { |
|
| 122 | 122 | $this->connected = !$this->driver_disconnect(); |
| 123 | 123 | $this->connected = false; |
| 124 | 124 | } |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
| 130 | 130 | global $numqueries, $debug, $sn_cache, $config; |
| 131 | 131 | |
| 132 | - if(!is_string($table)) { |
|
| 132 | + if (!is_string($table)) { |
|
| 133 | 133 | $fetch = $table; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if(!$this->connected) { |
|
| 136 | + if (!$this->connected) { |
|
| 137 | 137 | $this->sn_db_connect(); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -142,31 +142,31 @@ discard block |
||
| 142 | 142 | $skip_query_check or $this->security_query_check_bad_words($query); |
| 143 | 143 | |
| 144 | 144 | $sql = $query; |
| 145 | - if(strpos($sql, '{{') !== false) { |
|
| 145 | + if (strpos($sql, '{{') !== false) { |
|
| 146 | 146 | // foreach($sn_cache->tables as $tableName) { |
| 147 | - foreach($this->table_list as $tableName) { |
|
| 147 | + foreach ($this->table_list as $tableName) { |
|
| 148 | 148 | $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - if($config->debug) { |
|
| 152 | + if ($config->debug) { |
|
| 153 | 153 | $numqueries++; |
| 154 | 154 | $arr = debug_backtrace(); |
| 155 | - $file = end(explode('/',$arr[0]['file'])); |
|
| 155 | + $file = end(explode('/', $arr[0]['file'])); |
|
| 156 | 156 | $line = $arr[0]['line']; |
| 157 | 157 | $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>"); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if(defined('DEBUG_SQL_COMMENT')) { |
|
| 160 | + if (defined('DEBUG_SQL_COMMENT')) { |
|
| 161 | 161 | $backtrace = debug_backtrace(); |
| 162 | 162 | $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
| 163 | 163 | |
| 164 | 164 | $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
| 165 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
| 165 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
| 166 | 166 | $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if(defined('DEBUG_SQL_ERROR')) { |
|
| 169 | + if (defined('DEBUG_SQL_ERROR')) { |
|
| 170 | 170 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
| 171 | 171 | $debug->add_to_array($sql_comment); |
| 172 | 172 | // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql)); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $sql = $sql_commented; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error()."<br />$sql<br />",'SQL Error'); |
|
| 177 | + $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error() . "<br />$sql<br />", 'SQL Error'); |
|
| 178 | 178 | |
| 179 | 179 | return $fetch ? $this->db_fetch($sqlquery) : $sqlquery; |
| 180 | 180 | } |
@@ -184,16 +184,16 @@ discard block |
||
| 184 | 184 | // TODO Заменить это на новый логгер |
| 185 | 185 | global $config, $is_watching, $user, $debug; |
| 186 | 186 | |
| 187 | - if(!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array)) |
|
| 187 | + if (!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array)) |
|
| 188 | 188 | { |
| 189 | - if(!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
| 189 | + if (!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
| 190 | 190 | $is_watching = true; |
| 191 | 191 | $msg = "\$query = \"{$query}\"\n\r"; |
| 192 | - if(!empty($_POST)) { |
|
| 193 | - $msg .= "\n\r" . dump($_POST,'$_POST'); |
|
| 192 | + if (!empty($_POST)) { |
|
| 193 | + $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
| 194 | 194 | } |
| 195 | - if(!empty($_GET)) { |
|
| 196 | - $msg .= "\n\r" . dump($_GET,'$_GET'); |
|
| 195 | + if (!empty($_GET)) { |
|
| 196 | + $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
| 197 | 197 | } |
| 198 | 198 | $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
| 199 | 199 | $is_watching = false; |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | function security_query_check_bad_words($query) { |
| 206 | 206 | global $user, $dm_change_legit, $mm_change_legit; |
| 207 | 207 | |
| 208 | - switch(true) { |
|
| 208 | + switch (true) { |
|
| 209 | 209 | case stripos($query, 'RUNCATE TABL') != false: |
| 210 | 210 | case stripos($query, 'ROP TABL') != false: |
| 211 | 211 | case stripos($query, 'ENAME TABL') != false: |
@@ -216,33 +216,33 @@ discard block |
||
| 216 | 216 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
| 217 | 217 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
| 218 | 218 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
| 219 | - $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
| 219 | + $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
| 220 | 220 | $report .= ">Database Inforamation\n"; |
| 221 | - $report .= "\tID - ".$user['id']."\n"; |
|
| 222 | - $report .= "\tUser - ".$user['username']."\n"; |
|
| 223 | - $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
| 224 | - $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
| 225 | - $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
| 226 | - $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
| 227 | - $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
| 228 | - $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 229 | - $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
| 230 | - $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
| 221 | + $report .= "\tID - " . $user['id'] . "\n"; |
|
| 222 | + $report .= "\tUser - " . $user['username'] . "\n"; |
|
| 223 | + $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
| 224 | + $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
| 225 | + $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
| 226 | + $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
| 227 | + $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
| 228 | + $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 229 | + $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
| 230 | + $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
| 231 | 231 | $report .= "\n"; |
| 232 | 232 | |
| 233 | 233 | $report .= ">Query Information\n"; |
| 234 | - $report .= "\tQuery - ".$query."\n"; |
|
| 234 | + $report .= "\tQuery - " . $query . "\n"; |
|
| 235 | 235 | $report .= "\n"; |
| 236 | 236 | |
| 237 | 237 | $report .= ">\$_SERVER Information\n"; |
| 238 | - $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
| 239 | - $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
| 240 | - $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 241 | - $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
| 242 | - $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
| 243 | - $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
| 244 | - $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
| 245 | - $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
| 238 | + $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
| 239 | + $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
| 240 | + $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 241 | + $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
| 242 | + $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
| 243 | + $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
| 244 | + $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
| 245 | + $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
| 246 | 246 | |
| 247 | 247 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
| 248 | 248 | |
@@ -262,11 +262,11 @@ discard block |
||
| 262 | 262 | $prefix_length = strlen($this->db_prefix); |
| 263 | 263 | |
| 264 | 264 | $tl = array(); |
| 265 | - while($row = $this->db_fetch($query)) { |
|
| 266 | - foreach($row as $table_name) { |
|
| 267 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
| 265 | + while ($row = $this->db_fetch($query)) { |
|
| 266 | + foreach ($row as $table_name) { |
|
| 267 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
| 268 | 268 | $table_name = substr($table_name, $prefix_length); |
| 269 | - } elseif($prefixed_only) { |
|
| 269 | + } elseif ($prefixed_only) { |
|
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | 272 | // $table_name = str_replace($db_prefix, '', $table_name); |
@@ -55,6 +55,9 @@ |
||
| 55 | 55 | return true; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + /** |
|
| 59 | + * @param string $query_string |
|
| 60 | + */ |
|
| 58 | 61 | function mysql_query($query_string) { |
| 59 | 62 | return mysql_query($query_string, $this->link); |
| 60 | 63 | } |
@@ -30,17 +30,17 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | static $need_keys = array('server', 'user', 'pass', 'name', 'prefix'); |
| 32 | 32 | |
| 33 | - if($this->connected) { |
|
| 33 | + if ($this->connected) { |
|
| 34 | 34 | return true; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if(empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) { |
|
| 37 | + if (empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) { |
|
| 38 | 38 | $debug->error_fatal('There is missconfiguration in your config.php. Check it again', $this->mysql_error()); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // TODO !!!!!! DEBUG -> error!!!! |
| 42 | 42 | @$this->link = mysql_connect($settings['server'], $settings['user'], $settings['pass']); |
| 43 | - if(!is_resource($this->link)) { |
|
| 43 | + if (!is_resource($this->link)) { |
|
| 44 | 44 | $debug->error_fatal('DB Error - cannot connect to server', $this->mysql_error()); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | return mysql_real_escape_string($unescaped_string, $this->link); |
| 69 | 69 | } |
| 70 | 70 | function mysql_close_link() { |
| 71 | - if($this->connected) { |
|
| 71 | + if ($this->connected) { |
|
| 72 | 72 | $this->connected = false; |
| 73 | 73 | mysql_close($this->link); |
| 74 | 74 | unset($this->link); |
@@ -47,6 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * constuctor |
| 50 | + * @param template $template |
|
| 50 | 51 | */ |
| 51 | 52 | function template_compile(&$template) |
| 52 | 53 | { |
@@ -463,6 +464,7 @@ discard block |
||
| 463 | 464 | * Compile IF tags - much of this is from Smarty with |
| 464 | 465 | * some adaptions for our block level methods |
| 465 | 466 | * @access private |
| 467 | + * @param boolean $elseif |
|
| 466 | 468 | */ |
| 467 | 469 | function compile_tag_if($tag_args, $elseif) |
| 468 | 470 | { |
@@ -620,6 +622,7 @@ discard block |
||
| 620 | 622 | /** |
| 621 | 623 | * Compile DEFINE tags |
| 622 | 624 | * @access private |
| 625 | + * @param boolean $op |
|
| 623 | 626 | */ |
| 624 | 627 | function compile_tag_define($tag_args, $op) |
| 625 | 628 | { |
@@ -698,6 +701,7 @@ discard block |
||
| 698 | 701 | * parse expression |
| 699 | 702 | * This is from Smarty |
| 700 | 703 | * @access private |
| 704 | + * @param string $is_arg |
|
| 701 | 705 | */ |
| 702 | 706 | function _parse_is_expr($is_arg, $tokens) |
| 703 | 707 | { |
@@ -794,6 +798,8 @@ discard block |
||
| 794 | 798 | * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. |
| 795 | 799 | * NOTE: does not expect a trailing "." on the blockname. |
| 796 | 800 | * @access private |
| 801 | + * @param string $blockname |
|
| 802 | + * @param boolean $include_last_iterator |
|
| 797 | 803 | */ |
| 798 | 804 | function generate_block_data_ref($blockname, $include_last_iterator, $defop = false) |
| 799 | 805 | { |
@@ -832,6 +838,7 @@ discard block |
||
| 832 | 838 | /** |
| 833 | 839 | * Write compiled file to cache directory |
| 834 | 840 | * @access private |
| 841 | + * @param string $data |
|
| 835 | 842 | */ |
| 836 | 843 | function compile_write($handle, $data) |
| 837 | 844 | { |
@@ -857,6 +864,7 @@ discard block |
||
| 857 | 864 | /** |
| 858 | 865 | * Minifies template w/i PHP code by removing extra spaces |
| 859 | 866 | * @access private |
| 867 | + * @return string |
|
| 860 | 868 | */ |
| 861 | 869 | function minify($html) |
| 862 | 870 | { |
@@ -46,17 +46,17 @@ discard block |
||
| 46 | 46 | var $block_else_level = array(); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * constuctor |
|
| 50 | - */ |
|
| 49 | + * constuctor |
|
| 50 | + */ |
|
| 51 | 51 | function template_compile(&$template) |
| 52 | 52 | { |
| 53 | 53 | $this->template = &$template; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * Load template source from file |
|
| 58 | - * @access private |
|
| 59 | - */ |
|
| 57 | + * Load template source from file |
|
| 58 | + * @access private |
|
| 59 | + */ |
|
| 60 | 60 | function _tpl_load_file($handle, $store_in_db = false) |
| 61 | 61 | { |
| 62 | 62 | // Try and open template for read |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | - * Remove any PHP tags that do not belong, these regular expressions are derived from |
|
| 103 | - * the ones that exist in zend_language_scanner.l |
|
| 104 | - * @access private |
|
| 105 | - */ |
|
| 102 | + * Remove any PHP tags that do not belong, these regular expressions are derived from |
|
| 103 | + * the ones that exist in zend_language_scanner.l |
|
| 104 | + * @access private |
|
| 105 | + */ |
|
| 106 | 106 | function remove_php_tags(&$code) |
| 107 | 107 | { |
| 108 | 108 | // This matches the information gathered from the internal PHP lexer |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | - * The all seeing all doing compile method. Parts are inspired by or directly from Smarty |
|
| 120 | - * @access private |
|
| 121 | - */ |
|
| 119 | + * The all seeing all doing compile method. Parts are inspired by or directly from Smarty |
|
| 120 | + * @access private |
|
| 121 | + */ |
|
| 122 | 122 | function compile($code, $no_echo = false, $echo_var = '') |
| 123 | 123 | { |
| 124 | 124 | global $config; |
@@ -289,9 +289,9 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | - * Compile variables |
|
| 293 | - * @access private |
|
| 294 | - */ |
|
| 292 | + * Compile variables |
|
| 293 | + * @access private |
|
| 294 | + */ |
|
| 295 | 295 | function compile_var_tags(&$text_blocks) |
| 296 | 296 | { |
| 297 | 297 | // including $lang variable |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | - * Compile blocks |
|
| 358 | - * @access private |
|
| 359 | - */ |
|
| 357 | + * Compile blocks |
|
| 358 | + * @access private |
|
| 359 | + */ |
|
| 360 | 360 | function compile_tag_block($tag_args) |
| 361 | 361 | { |
| 362 | 362 | $no_nesting = false; |
@@ -442,14 +442,14 @@ discard block |
||
| 442 | 442 | $tag_template_php .= 'if ($_' . $tag_args . '_count) {'; |
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | - * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory |
|
| 446 | - * <code> |
|
| 447 | - * if (!$offset) |
|
| 448 | - * { |
|
| 449 | - * $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){'; |
|
| 450 | - * } |
|
| 451 | - * </code> |
|
| 452 | - */ |
|
| 445 | + * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory |
|
| 446 | + * <code> |
|
| 447 | + * if (!$offset) |
|
| 448 | + * { |
|
| 449 | + * $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){'; |
|
| 450 | + * } |
|
| 451 | + * </code> |
|
| 452 | + */ |
|
| 453 | 453 | |
| 454 | 454 | $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){'; |
| 455 | 455 | // $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;'; |
@@ -460,10 +460,10 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
| 463 | - * Compile IF tags - much of this is from Smarty with |
|
| 464 | - * some adaptions for our block level methods |
|
| 465 | - * @access private |
|
| 466 | - */ |
|
| 463 | + * Compile IF tags - much of this is from Smarty with |
|
| 464 | + * some adaptions for our block level methods |
|
| 465 | + * @access private |
|
| 466 | + */ |
|
| 467 | 467 | function compile_tag_if($tag_args, $elseif) |
| 468 | 468 | { |
| 469 | 469 | // Tokenize args for 'if' tag. |
@@ -618,9 +618,9 @@ discard block |
||
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Compile DEFINE tags |
|
| 622 | - * @access private |
|
| 623 | - */ |
|
| 621 | + * Compile DEFINE tags |
|
| 622 | + * @access private |
|
| 623 | + */ |
|
| 624 | 624 | function compile_tag_define($tag_args, $op) |
| 625 | 625 | { |
| 626 | 626 | preg_match('#^((?:[a-z0-9\-_]+\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (\'?)([^\']*)(\'?))?$#', $tag_args, $match); |
@@ -671,9 +671,9 @@ discard block |
||
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
| 674 | - * Compile INCLUDE tag |
|
| 675 | - * @access private |
|
| 676 | - */ |
|
| 674 | + * Compile INCLUDE tag |
|
| 675 | + * @access private |
|
| 676 | + */ |
|
| 677 | 677 | function compile_tag_include($tag_args) |
| 678 | 678 | { |
| 679 | 679 | // Process dynamic includes |
@@ -686,19 +686,19 @@ discard block |
||
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
| 689 | - * Compile INCLUDE_PHP tag |
|
| 690 | - * @access private |
|
| 691 | - */ |
|
| 689 | + * Compile INCLUDE_PHP tag |
|
| 690 | + * @access private |
|
| 691 | + */ |
|
| 692 | 692 | function compile_tag_include_php($tag_args) |
| 693 | 693 | { |
| 694 | 694 | return "\$this->_php_include('$tag_args');"; |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
| 698 | - * parse expression |
|
| 699 | - * This is from Smarty |
|
| 700 | - * @access private |
|
| 701 | - */ |
|
| 698 | + * parse expression |
|
| 699 | + * This is from Smarty |
|
| 700 | + * @access private |
|
| 701 | + */ |
|
| 702 | 702 | function _parse_is_expr($is_arg, $tokens) |
| 703 | 703 | { |
| 704 | 704 | $expr_end = 0; |
@@ -763,13 +763,13 @@ discard block |
||
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
| 766 | - * Generates a reference to the given variable inside the given (possibly nested) |
|
| 767 | - * block namespace. This is a string of the form: |
|
| 768 | - * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' |
|
| 769 | - * It's ready to be inserted into an "echo" line in one of the templates. |
|
| 770 | - * NOTE: expects a trailing "." on the namespace. |
|
| 771 | - * @access private |
|
| 772 | - */ |
|
| 766 | + * Generates a reference to the given variable inside the given (possibly nested) |
|
| 767 | + * block namespace. This is a string of the form: |
|
| 768 | + * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' |
|
| 769 | + * It's ready to be inserted into an "echo" line in one of the templates. |
|
| 770 | + * NOTE: expects a trailing "." on the namespace. |
|
| 771 | + * @access private |
|
| 772 | + */ |
|
| 773 | 773 | function generate_block_varref($namespace, $varname, $echo = true, $defop = false) |
| 774 | 774 | { |
| 775 | 775 | // Strip the trailing period. |
@@ -787,14 +787,14 @@ discard block |
||
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | /** |
| 790 | - * Generates a reference to the array of data values for the given |
|
| 791 | - * (possibly nested) block namespace. This is a string of the form: |
|
| 792 | - * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] |
|
| 793 | - * |
|
| 794 | - * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. |
|
| 795 | - * NOTE: does not expect a trailing "." on the blockname. |
|
| 796 | - * @access private |
|
| 797 | - */ |
|
| 790 | + * Generates a reference to the array of data values for the given |
|
| 791 | + * (possibly nested) block namespace. This is a string of the form: |
|
| 792 | + * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] |
|
| 793 | + * |
|
| 794 | + * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. |
|
| 795 | + * NOTE: does not expect a trailing "." on the blockname. |
|
| 796 | + * @access private |
|
| 797 | + */ |
|
| 798 | 798 | function generate_block_data_ref($blockname, $include_last_iterator, $defop = false) |
| 799 | 799 | { |
| 800 | 800 | // Get an array of the blocks involved. |
@@ -830,9 +830,9 @@ discard block |
||
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
| 833 | - * Write compiled file to cache directory |
|
| 834 | - * @access private |
|
| 835 | - */ |
|
| 833 | + * Write compiled file to cache directory |
|
| 834 | + * @access private |
|
| 835 | + */ |
|
| 836 | 836 | function compile_write($handle, $data) |
| 837 | 837 | { |
| 838 | 838 | $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . DOT_PHP_EX; |
@@ -855,9 +855,9 @@ discard block |
||
| 855 | 855 | |
| 856 | 856 | // Gorlum's minifier BOF |
| 857 | 857 | /** |
| 858 | - * Minifies template w/i PHP code by removing extra spaces |
|
| 859 | - * @access private |
|
| 860 | - */ |
|
| 858 | + * Minifies template w/i PHP code by removing extra spaces |
|
| 859 | + * @access private |
|
| 860 | + */ |
|
| 861 | 861 | function minify($html) |
| 862 | 862 | { |
| 863 | 863 | global $config; |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches); |
| 144 | 144 | $include_blocks = $matches[1]; |
| 145 | - if($include_blocks) |
|
| 145 | + if ($include_blocks) |
|
| 146 | 146 | { |
| 147 | - foreach($include_blocks as &$included_file) |
|
| 147 | + foreach ($include_blocks as &$included_file) |
|
| 148 | 148 | { |
| 149 | 149 | $included_file .= '.tpl.html'; |
| 150 | 150 | } |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | |
| 454 | 454 | $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){'; |
| 455 | 455 | // $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;'; |
| 456 | - $tag_template_php .= '$_'. $tag_args . '_val = &' . $varref . '[$_'. $tag_args. '_i];'; |
|
| 457 | - $tag_template_php .= '$this->_block_value["'. $tag_args . '"] = &' . $varref . '[$_'. $tag_args. '_i];'; |
|
| 456 | + $tag_template_php .= '$_' . $tag_args . '_val = &' . $varref . '[$_' . $tag_args . '_i];'; |
|
| 457 | + $tag_template_php .= '$this->_block_value["' . $tag_args . '"] = &' . $varref . '[$_' . $tag_args . '_i];'; |
|
| 458 | 458 | |
| 459 | 459 | return $tag_template_php; |
| 460 | 460 | } |
@@ -558,10 +558,10 @@ discard block |
||
| 558 | 558 | break; |
| 559 | 559 | |
| 560 | 560 | case 'is': |
| 561 | - $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1; |
|
| 561 | + $is_arg_start = ($tokens[$i - 1] == ')') ? array_pop($is_arg_stack) : $i - 1; |
|
| 562 | 562 | $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); |
| 563 | 563 | |
| 564 | - $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); |
|
| 564 | + $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1)); |
|
| 565 | 565 | |
| 566 | 566 | array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens); |
| 567 | 567 | |
@@ -821,11 +821,11 @@ discard block |
||
| 821 | 821 | } |
| 822 | 822 | else if ($include_last_iterator) |
| 823 | 823 | { |
| 824 | - return '$_'. $blocks[$blockcount] . '_val'; |
|
| 824 | + return '$_' . $blocks[$blockcount] . '_val'; |
|
| 825 | 825 | } |
| 826 | 826 | else |
| 827 | 827 | { |
| 828 | - return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']'; |
|
| 828 | + return '$_' . $blocks[$blockcount - 1] . '_val[\'' . $blocks[$blockcount] . '\']'; |
|
| 829 | 829 | } |
| 830 | 830 | } |
| 831 | 831 | |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | if ($fp = @fopen($filename, 'wb')) |
| 843 | 843 | { |
| 844 | 844 | @flock($fp, LOCK_EX); |
| 845 | - @fwrite ($fp, $data); |
|
| 845 | + @fwrite($fp, $data); |
|
| 846 | 846 | @flock($fp, LOCK_UN); |
| 847 | 847 | @fclose($fp); |
| 848 | 848 | |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | { |
| 863 | 863 | global $config; |
| 864 | 864 | |
| 865 | - if(!$config->tpl_minifier) |
|
| 865 | + if (!$config->tpl_minifier) |
|
| 866 | 866 | { |
| 867 | 867 | return $html; |
| 868 | 868 | } |
@@ -874,14 +874,14 @@ discard block |
||
| 874 | 874 | //$html = preg_replace('/[\r\n\t]+/', ' ', $html); |
| 875 | 875 | $html = preg_replace('/>[\s]*</', '><', $html); // Strip spacechars between tags |
| 876 | 876 | $html = preg_replace('/[\s]+/', ' ', $html); // Replace several spacechars with one space |
| 877 | - if(!empty($pre[0])) |
|
| 877 | + if (!empty($pre[0])) |
|
| 878 | 878 | { |
| 879 | - foreach($pre[0] as $tag) |
|
| 879 | + foreach ($pre[0] as $tag) |
|
| 880 | 880 | { |
| 881 | 881 | $tag = preg_replace('/^\ *\/\/[^\<]*?$/m', ' ', $tag); // Strips comments - except those that contains HTML comment inside |
| 882 | 882 | $tag = preg_replace('/[\ \t]{2,}/', ' ', $tag); // Replace several spaces by one |
| 883 | 883 | $tag = preg_replace('/\s{2,}/', "\r\n", $tag); // Replace several linefeeds by one |
| 884 | - $html = preg_replace('/#pre#/', $tag, $html,1); |
|
| 884 | + $html = preg_replace('/#pre#/', $tag, $html, 1); |
|
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
@@ -66,8 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | return; |
| 68 | 68 | trigger_error("template->_tpl_load_file(): File {$this->template->files[$handle]} does not exist or is empty", E_USER_ERROR); |
| 69 | - } |
|
| 70 | - else |
|
| 69 | + } else |
|
| 71 | 70 | { |
| 72 | 71 | $this->template->files[$handle] = $this->template->files_inherit[$handle]; |
| 73 | 72 | } |
@@ -225,15 +224,13 @@ discard block |
||
| 225 | 224 | $var = substr($temp, 2, -1); |
| 226 | 225 | //$file = $this->template->_tpldata['DEFINE']['.'][$var]; |
| 227 | 226 | $temp = "\$this->_tpldata['DEFINE']['.']['$var']"; |
| 228 | - } |
|
| 229 | - else |
|
| 227 | + } else |
|
| 230 | 228 | { |
| 231 | 229 | $var = substr($temp, 1, -1); |
| 232 | 230 | //$file = $this->template->_rootref[$var]; |
| 233 | 231 | $temp = "\$this->_rootref['$var']"; |
| 234 | 232 | } |
| 235 | - } |
|
| 236 | - else |
|
| 233 | + } else |
|
| 237 | 234 | { |
| 238 | 235 | $file = $temp; |
| 239 | 236 | } |
@@ -381,8 +378,7 @@ discard block |
||
| 381 | 378 | if ($match[2] < 0) |
| 382 | 379 | { |
| 383 | 380 | $loop_start = '($_' . $tag_args . '_count ' . $match[2] . ' < 0 ? 0 : $_' . $tag_args . '_count ' . $match[2] . ')'; |
| 384 | - } |
|
| 385 | - else |
|
| 381 | + } else |
|
| 386 | 382 | { |
| 387 | 383 | $loop_start = '($_' . $tag_args . '_count < ' . $match[2] . ' ? $_' . $tag_args . '_count : ' . $match[2] . ')'; |
| 388 | 384 | } |
@@ -390,17 +386,14 @@ discard block |
||
| 390 | 386 | if (strlen($match[3]) < 1 || $match[3] == -1) |
| 391 | 387 | { |
| 392 | 388 | $loop_end = '$_' . $tag_args . '_count'; |
| 393 | - } |
|
| 394 | - else if ($match[3] >= 0) |
|
| 389 | + } else if ($match[3] >= 0) |
|
| 395 | 390 | { |
| 396 | 391 | $loop_end = '(' . ($match[3] + 1) . ' > $_' . $tag_args . '_count ? $_' . $tag_args . '_count : ' . ($match[3] + 1) . ')'; |
| 397 | - } |
|
| 398 | - else //if ($match[3] < -1) |
|
| 392 | + } else //if ($match[3] < -1) |
|
| 399 | 393 | { |
| 400 | 394 | $loop_end = '$_' . $tag_args . '_count' . ($match[3] + 1); |
| 401 | 395 | } |
| 402 | - } |
|
| 403 | - else |
|
| 396 | + } else |
|
| 404 | 397 | { |
| 405 | 398 | $loop_start = 0; |
| 406 | 399 | $loop_end = '$_' . $tag_args . '_count'; |
@@ -413,8 +406,7 @@ discard block |
||
| 413 | 406 | { |
| 414 | 407 | // We need to implode $no_nesting times from the end... |
| 415 | 408 | $block = array_slice($this->block_names, -$no_nesting); |
| 416 | - } |
|
| 417 | - else |
|
| 409 | + } else |
|
| 418 | 410 | { |
| 419 | 411 | $block = $this->block_names; |
| 420 | 412 | } |
@@ -424,8 +416,7 @@ discard block |
||
| 424 | 416 | // Block is not nested. |
| 425 | 417 | $tag_template_php = '$_' . $tag_args . "_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;"; |
| 426 | 418 | $varref = "\$this->_tpldata['$tag_args']"; |
| 427 | - } |
|
| 428 | - else |
|
| 419 | + } else |
|
| 429 | 420 | { |
| 430 | 421 | // This block is nested. |
| 431 | 422 | // Generate a namespace string for this block. |
@@ -573,8 +564,7 @@ discard block |
||
| 573 | 564 | if (preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[A-Za-z])([A-Za-z0-9\-_]+)#s', $token, $varrefs)) |
| 574 | 565 | { |
| 575 | 566 | $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']' : (($varrefs[2]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$this->_rootref[\'' . $varrefs[3] . '\']'); |
| 576 | - } |
|
| 577 | - else if (preg_match('#^\.((?:[a-z0-9\-_]+\.?)+)$#s', $token, $varrefs)) |
|
| 567 | + } else if (preg_match('#^\.((?:[a-z0-9\-_]+\.?)+)$#s', $token, $varrefs)) |
|
| 578 | 568 | { |
| 579 | 569 | // Allow checking if loops are set with .loopname |
| 580 | 570 | // It is also possible to check the loop count by doing <!-- IF .loopname > 1 --> for example |
@@ -590,8 +580,7 @@ discard block |
||
| 590 | 580 | |
| 591 | 581 | // Add the block reference for the last child. |
| 592 | 582 | $varref .= "['" . $block . "']"; |
| 593 | - } |
|
| 594 | - else |
|
| 583 | + } else |
|
| 595 | 584 | { |
| 596 | 585 | $varref = '$this->_tpldata'; |
| 597 | 586 | |
@@ -599,8 +588,7 @@ discard block |
||
| 599 | 588 | $varref .= "['" . $blocks[0] . "']"; |
| 600 | 589 | } |
| 601 | 590 | $token = "sizeof($varref)"; |
| 602 | - } |
|
| 603 | - else if (!empty($token)) |
|
| 591 | + } else if (!empty($token)) |
|
| 604 | 592 | { |
| 605 | 593 | $token = '(' . $token . ')'; |
| 606 | 594 | } |
@@ -645,8 +633,7 @@ discard block |
||
| 645 | 633 | |
| 646 | 634 | // Now replace the php code |
| 647 | 635 | $match[4] = "'" . str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[4]) . "'"; |
| 648 | - } |
|
| 649 | - else |
|
| 636 | + } else |
|
| 650 | 637 | { |
| 651 | 638 | preg_match('#true|false|\.#i', $match[4], $type); |
| 652 | 639 | |
@@ -708,8 +695,7 @@ discard block |
||
| 708 | 695 | { |
| 709 | 696 | $negate_expr = true; |
| 710 | 697 | $expr_type = array_shift($tokens); |
| 711 | - } |
|
| 712 | - else |
|
| 698 | + } else |
|
| 713 | 699 | { |
| 714 | 700 | $expr_type = $first_token; |
| 715 | 701 | } |
@@ -722,8 +708,7 @@ discard block |
||
| 722 | 708 | $expr_end++; |
| 723 | 709 | $expr_arg = $tokens[$expr_end++]; |
| 724 | 710 | $expr = "!(($is_arg / $expr_arg) % $expr_arg)"; |
| 725 | - } |
|
| 726 | - else |
|
| 711 | + } else |
|
| 727 | 712 | { |
| 728 | 713 | $expr = "!($is_arg & 1)"; |
| 729 | 714 | } |
@@ -735,8 +720,7 @@ discard block |
||
| 735 | 720 | $expr_end++; |
| 736 | 721 | $expr_arg = $tokens[$expr_end++]; |
| 737 | 722 | $expr = "(($is_arg / $expr_arg) % $expr_arg)"; |
| 738 | - } |
|
| 739 | - else |
|
| 723 | + } else |
|
| 740 | 724 | { |
| 741 | 725 | $expr = "($is_arg & 1)"; |
| 742 | 726 | } |
@@ -818,12 +802,10 @@ discard block |
||
| 818 | 802 | $varref .= '[$_' . $blocks[$blockcount] . '_i]'; |
| 819 | 803 | } |
| 820 | 804 | return $varref; |
| 821 | - } |
|
| 822 | - else if ($include_last_iterator) |
|
| 805 | + } else if ($include_last_iterator) |
|
| 823 | 806 | { |
| 824 | 807 | return '$_'. $blocks[$blockcount] . '_val'; |
| 825 | - } |
|
| 826 | - else |
|
| 808 | + } else |
|
| 827 | 809 | { |
| 828 | 810 | return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']'; |
| 829 | 811 | } |