Просмотр файла myzip/index.php

Размер файла: 14.26Kb
  1. <?php
  2. error_reporting(0);
  3. @header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  4. @header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  5. @header('Cache-Control: no-cache, forua=true');
  6. @header('Pragma: no-cache');
  7. @header('Content-Type: text/html; charset=utf-8');
  8. $log = ''; $pas = '';
  9. if((@preg_match('~^[a-z0-9]{3,33}$~i', $_GET['log']))&&(@preg_match('~^[a-z0-9]{3,33}$~i', $_GET['pas']))) {
  10. $log = htmlspecialchars($_GET['log'], ENT_QUOTES);
  11. $pas = htmlspecialchars($_GET['pas'], ENT_QUOTES);
  12. }
  13. @require('./conf.php');
  14. $ref = mt_rand(1000,9999);
  15. if(($log !== MYLOGIN)||($pas !== MYPASSWORD)) {
  16. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>'.
  17. '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.
  18. '<title>Вход</title>'.
  19. '<style type="text/css">'.
  20. 'input { font-size: 10pt; }'.
  21. '</style></head><body bgcolor="'.FONS.'" link="'.LINKS.'" text="'.TEXTS.'">'.
  22. '<form action="'.SURL.'/?ref='.$ref.'" method="get">'.
  23. '<p align="left" style="background-color: '.FORMS.'">'.
  24. '<small><u>Логин</u>:</small><br>'.
  25. '<input type="text" name="log" title="Логин" maxlength="33"><br>'.
  26. '<small><u>Пароль</u>:</small><br>'.
  27. '<input type="text" name="pas" title="Пароль" maxlength="33"><br>'.
  28. '<input type="submit" value="Войти!">'.
  29. '</p></form>'.
  30. '<p align="left">'.
  31. '<small>---<br><a href="'.MYSITE.'">'.NASITE.'</a></small>'.
  32. '</p></body></html>';
  33. exit; }
  34. $mod = intval($_GET['mod']);
  35. $name = '../'.@preg_replace('~\.*\.\/+~', '', @str_replace(chr(0), '', trim(rawurldecode($_GET['name']))));
  36. $rname = rawurlencode($name);
  37. $folder = '../'.@preg_replace('~\.*\.\/+~', '', @str_replace(chr(0), '', trim(rawurldecode($_GET['folder']))));
  38. $rfolder = rawurlencode($folder);
  39. $pk = trim(rawurldecode($_GET['pk']));
  40. $c = intval($_GET['c']);
  41. if($c < 1) { $c = 1; }
  42. $p = intval($_GET['p']);
  43. if($p < 1) { $p = 1; }
  44. $res = intval($_GET['res']);
  45. @require('./pclzip.php');
  46. switch($mod) {
  47. case 5:
  48. $file = str_replace('.|htaccess', '.htaccess', trim(rawurldecode($_GET['file'])));
  49. $rfile = rawurlencode(str_replace('.htaccess', '.|htaccess', $file));
  50. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>'.
  51. '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.
  52. '<title>Код файла</title>'.
  53. '</head><body bgcolor="'.FONS.'" link="'.LINKS.'" text="'.TEXTS.'">'.
  54. '<p align="left"><small>---<br>';
  55. if(is_file($name)) {
  56. if($zip = new PclZip($name)) {
  57. if($arrcon = $zip->extract(PCLZIP_OPT_BY_NAME, "$file", PCLZIP_OPT_EXTRACT_AS_STRING)) {
  58. echo 'Архив:<br>'.str_replace('$', '&#036;', htmlspecialchars($name, ENT_QUOTES)).'<br>'.
  59. 'Файл:<br>'.str_replace('$', '&#036;', htmlspecialchars($file, ENT_QUOTES)).'<br>---<br>';
  60. $arrstr = @explode("\n", rtrim(str_replace("\r", '', $arrcon[0]['content'])));
  61. $ct = count($arrstr);
  62. $allp = ceil($ct/ONPAGE);
  63. if($c > $allp) {
  64. $c = 1; }
  65. $ot = intval(ONPAGE * ($c - 1));
  66. if(($ot < 0)||($ot >= $ct)) { $ot = 0; }
  67. $do = intval(ONPAGE * $c);
  68. if(($do < 1)||($do > $ct)) { $do = $ct; }
  69. for($i = $ot; $i < $do; $i++) {
  70. echo ''.($i+1).'. <font color="'.CKOD.'">'.str_replace('$', '&#036;', htmlspecialchars($arrstr[$i], ENT_QUOTES)).'</font><br>'; }
  71. unset($arrcon);
  72. unset($arrstr);
  73. echo '---<br>Всего строк: '.$ct.'<br>Стр.: ';
  74. for($str = 1; $str <= $allp; $str++) {
  75. if(($str <> $c)&&($str < $c - LPAGE)&&($str == 1)) {
  76. echo '<a href="'.SURL.'/?mod=5&amp;name='.$rname.'&amp;file='.$rfile.'&amp;c='.$str.'&amp;p='.$p.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a> .. '; }
  77. if(($str < $c)&&($str >= $c - LPAGE)) {
  78. echo '<a href="'.SURL.'/?mod=5&amp;name='.$rname.'&amp;file='.$rfile.'&amp;c='.$str.'&amp;p='.$p.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a> '; }
  79. if($str == $c) {
  80. echo '<b><u>'.$str.'</u></b> '; }
  81. if(($str > $c)&&($str <= $c + LPAGE)) {
  82. echo '<a href="'.SURL.'/?mod=5&amp;name='.$rname.'&amp;file='.$rfile.'&amp;c='.$str.'&amp;p='.$p.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a> '; }
  83. if(($str <> $c)&&($str > $c + LPAGE)&&($str == $allp)) {
  84. echo '.. <a href="'.SURL.'/?mod=5&amp;name='.$rname.'&amp;file='.$rfile.'&amp;c='.$str.'&amp;p='.$p.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a>'; }
  85. } } else {
  86. echo 'Произошла ошибка.<br>Просмотр невозможен.';
  87. } } else {
  88. echo 'Произошла ошибка.<br>Просмотр невозможен.';
  89. } } else {
  90. echo 'Произошла ошибка.<br>Архива несуществует.'; }
  91. echo '<br>---<br><a href="'.SURL.'/?mod=1&amp;name='.$rname.'&amp;p='.$p.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">Просмотр архива</a><br>'.
  92. '---<br><a href="'.SURL.'/?log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">Меню</a></small>'.
  93. '</p></body></html>';
  94. break;
  95. case 4:
  96. $files = @array_map('trim', @array_map('rawurldecode', $_GET['files']));
  97. $res = 1;
  98. if(is_file($name)) {
  99. if($zip = new PclZip($name)) {
  100. if($zip->extract(PCLZIP_OPT_PATH, "$folder", PCLZIP_OPT_BY_NAME, $files) <> 0) {
  101. if(is_dir($folder)) {
  102. $res = 2; } } } }
  103. if($res == 2) {
  104. @header('Location: '.SURL.'/?mod=1&name='.$rname.'&p='.$p.'&pk='.$rfolder.'&log='.$log.'&pas='.$pas.'&res=2&ref='.$ref.'');
  105. } else {
  106. @header('Location: '.SURL.'/?mod=1&name='.$rname.'&p='.$p.'&log='.$log.'&pas='.$pas.'&res=1&ref='.$ref.'');
  107. }
  108. break;
  109. case 3:
  110. $res = 1;
  111. if(is_file($name)) {
  112. if($zip = new PclZip($name)) {
  113. if($zip->extract(PCLZIP_OPT_PATH, "$folder") <> 0) {
  114. if(is_dir($folder)) {
  115. $res = 3; } } } }
  116. if(intval($_GET['un']) == 1) {
  117. if($res == 3) {
  118. @header('Location: '.SURL.'/?log='.$log.'&pas='.$pas.'&name='.$rname.'&pk='.$rfolder.'&res=3&ref='.$ref.'');
  119. } else {
  120. @header('Location: '.SURL.'/?log='.$log.'&pas='.$pas.'&res=1&ref='.$ref.'');
  121. } } else {
  122. if($res == 3) {
  123. @header('Location: '.SURL.'/?mod=1&name='.$rname.'&p='.$p.'&pk='.$rfolder.'&log='.$log.'&pas='.$pas.'&res=3&ref='.$ref.'');
  124. } else {
  125. @header('Location: '.SURL.'/?mod=1&name='.$rname.'&p='.$p.'&log='.$log.'&pas='.$pas.'&res=1&ref='.$ref.'');
  126. } }
  127. break;
  128. case 2:
  129. $res = 1;
  130. if(@preg_match('~^\.\.\/.*[^\/]+$~', $name)) {
  131. $nm = basename($name);
  132. if(is_dir($name)) {
  133. if($zip = new PclZip(ZDIR.'/'.$nm.'.zip')) {
  134. if($zip->create("$name", PCLZIP_OPT_REMOVE_PATH, "$name") <> 0) {
  135. $res = 4; } } }
  136. elseif(is_file($name)) {
  137. $fnm = @preg_replace("~([^.]+).*~m", "\\1", $nm);
  138. if($zip = new PclZip(ZDIR.'/'.$fnm.'.zip')) {
  139. if($zip->create("$name", PCLZIP_OPT_REMOVE_ALL_PATH) <> 0) {
  140. $res = 5; } } } }
  141. if(($res == 4)||($res == 5)) {
  142. @header('Location: '.SURL.'/?log='.$log.'&pas='.$pas.'&name='.$rname.'&res='.$res.'&ref='.$ref.'');
  143. } else {
  144. @header('Location: '.SURL.'/?log='.$log.'&pas='.$pas.'&res=1&ref='.$ref.'');
  145. }
  146. break;
  147. case 1:
  148. function rsz($sz) {
  149. $sz = intval($sz);
  150. if(($sz >= 0)&&($sz < 1024)) {
  151. $rsz = round($sz/1000, 2).' K'; }
  152. elseif(($sz >= 1024)&&($sz < 1048576)) {
  153. $rsz = round($sz/1024, 2).' K'; }
  154. elseif($sz >= 1048576) {
  155. $rsz = round($sz/1024/1024, 2).' M'; }
  156. else { $rsz = '-'; }
  157. return $rsz; }
  158. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>'.
  159. '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.
  160. '<title>Просмотр</title>'.
  161. '<style type="text/css">'.
  162. 'textarea, input { font-size: 10pt; }'.
  163. '</style></head><body bgcolor="'.FONS.'" link="'.LINKS.'" text="'.TEXTS.'">'.
  164. '<p align="left"><small>---<br>';
  165. if(is_file($name)) {
  166. echo 'Архив:<br>'.str_replace('$', '&#036;', htmlspecialchars($name, ENT_QUOTES)).'<br>---<br>';
  167. if($zip = new PclZip($name)) {
  168. if($list = $zip->listContent()) {
  169. if($res == 2) {
  170. echo 'Файлы извлечены!<br>В папку:<br>'.str_replace('$', '&#036;', htmlspecialchars($pk, ENT_QUOTES)).'<br>---<br>'; }
  171. if($res == 3) {
  172. echo 'Разархивирован!<br>В папку:<br>'.str_replace('$', '&#036;', htmlspecialchars($pk, ENT_QUOTES)).'<br>---<br>'; }
  173. if($res == 1) {
  174. echo 'Произошла ошибка..<br>---<br>'; }
  175. $ct = count($list);
  176. $allp = ceil($ct/ONPAGE);
  177. if($p > $allp) {
  178. $p = 1; }
  179. $ot = intval(ONPAGE * ($p - 1));
  180. if(($ot < 0)||($ot >= $ct)) { $ot = 0; }
  181. $do = intval(ONPAGE * $p);
  182. if(($do < 1)||($do > $ct)) { $do = $ct; }
  183. echo '</small></p>';
  184. echo '<form action="'.SURL.'/?ref='.$ref.'" method="get">'.
  185. '<p align="left">'.
  186. '<input type="hidden" name="mod" value="4">'.
  187. '<input type="hidden" name="log" value="'.$log.'">'.
  188. '<input type="hidden" name="pas" value="'.$pas.'">'.
  189. '<input type="hidden" name="p" value="'.$p.'">'.
  190. '<small>';
  191. for($i = $ot; $i < $do; $i++) {
  192. echo '<input type="checkbox" name="files[]" value="'.rawurlencode($list[$i]['filename']).'"><br>';
  193. if(intval($list[$i]['folder']) == 0) {
  194. $sz = $list[$i]['compressed_size'];
  195. $szc = @rsz($sz);
  196. $sz = $list[$i]['size'];
  197. $szd = @rsz($sz);
  198. echo '&gt; <u><a href="'.SURL.'/?mod=5&amp;name='.$rname.'&amp;file='.rawurlencode(str_replace('.htaccess', '.|htaccess', $list[$i]['filename'])).'&amp;p='.$p.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.str_replace('$', '&#036;', htmlspecialchars($list[$i]['filename'], ENT_QUOTES)).'</a></u><br>'.
  199. '&gt; '.$szc.' / '.$szd.'<br>';
  200. } else {
  201. echo '&gt; <u>'.str_replace('$', '&#036;', htmlspecialchars($list[$i]['filename'], ENT_QUOTES)).'</u><br>'; }
  202. echo '&gt; '.@gmdate('d.m.y, H:i:s', intval($list[$i]['mtime'] + (3600 * TCORR))).'<br>'; }
  203. echo '---<br>';
  204. if($p == 1) {
  205. $drs = 0; $fls = 0;
  206. $sz = 0;
  207. for($s = 0; $s < $ct; $s++) {
  208. if(intval($list[$s]['folder']) == 1) {
  209. $drs += 1; } else {
  210. $fls += 1; }
  211. $sz += $list[$s]['size']; }
  212. $unzsz = @rsz($sz);
  213. $sz = @filesize($name);
  214. $zipsz = @rsz($sz);
  215. echo 'Объектов: '.$ct.'.<br>Всего папок: '.intval($drs).'.<br>Всего файлов: '.intval($fls).'.<br>Размер в Zip: '.$zipsz.'.<br>Размер UnZip: '.$unzsz.'.<br>'; }
  216. unset($list);
  217. echo 'Стр.: ';
  218. for($str = 1; $str <= $allp; $str++) {
  219. if(($str <> $p)&&($str < $p - LPAGE)&&($str == 1)) {
  220. echo '<a href="'.SURL.'/?mod=1&amp;name='.$rname.'&amp;p='.$str.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a> .. '; }
  221. if(($str < $p)&&($str >= $p - LPAGE)) {
  222. echo '<a href="'.SURL.'/?mod=1&amp;name='.$rname.'&amp;p='.$str.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a> '; }
  223. if($str == $p) {
  224. echo '<b><u>'.$str.'</u></b> '; }
  225. if(($str > $p)&&($str <= $p + LPAGE)) {
  226. echo '<a href="'.SURL.'/?mod=1&amp;name='.$rname.'&amp;p='.$str.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a> '; }
  227. if(($str <> $p)&&($str > $p + LPAGE)&&($str == $allp)) {
  228. echo '.. <a href="'.SURL.'/?mod=1&amp;name='.$rname.'&amp;p='.$str.'&amp;log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">'.$str.'</a>'; }
  229. }
  230. echo '<br>---</small></p>'.
  231. '<p align="left" style="background-color: '.FORMS.'">'.
  232. '<small><u>Извлечь файлы в</u>:</small><br>'.
  233. '<textarea name="folder" title="Папка" cols="20" rows="4">../</textarea>'.
  234. '<input type="hidden" name="name" value="'.$rname.'">'.
  235. '<input type="submit" value="Выполнить!">'.
  236. '</p></form>'.
  237. '<form action="'.SURL.'/?ref='.$ref.'" method="get">'.
  238. '<p align="left" style="background-color: '.FORMS.'">'.
  239. '<input type="hidden" name="mod" value="3">'.
  240. '<input type="hidden" name="log" value="'.$log.'">'.
  241. '<input type="hidden" name="pas" value="'.$pas.'">'.
  242. '<input type="hidden" name="p" value="'.$p.'">'.
  243. '<small>---<br><u>Разархивировать в</u>:</small><br>'.
  244. '<textarea name="folder" title="Папка" cols="20" rows="4">../</textarea>'.
  245. '<input type="hidden" name="name" value="'.$rname.'">'.
  246. '<input type="submit" value="Выполнить!">'.
  247. '</p></form>'.
  248. '<p align="left"><small>';
  249. } else {
  250. echo 'Произошла ошибка:<br>&quot;'.str_replace('$', '&#036;', htmlspecialchars($zip->errorInfo(true), ENT_QUOTES)).'&quot;...<br>';
  251. } } else {
  252. echo 'Произошла ошибка.<br>Просмотр невозможен.<br>';
  253. } } else {
  254. echo 'Произошла ошибка.<br>Архива несуществует.<br>';
  255. }
  256. echo '---<br><a href="'.SURL.'/?log='.$log.'&amp;pas='.$pas.'&amp;ref='.$ref.'">Меню</a><br>'.
  257. '---<br><a href="'.SURL.'/?ref='.$ref.'">Выход</a></small>'.
  258. '</p></body></html>';
  259. break;
  260. default:
  261. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>'.
  262. '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.
  263. '<title>Меню</title>'.
  264. '<style type="text/css">'.
  265. 'textarea, input, select { font-size: 10pt; }'.
  266. '</style></head><body bgcolor="'.FONS.'" link="'.LINKS.'" text="'.TEXTS.'">';
  267. if(($res >= 1)&&($res <= 5)&&($res <> 2)) {
  268. echo '<p align="left"><small>---<br>';
  269. if($res == 3) {
  270. echo 'Архив:<br>'.str_replace('$', '&#036;', htmlspecialchars($name, ENT_QUOTES)).'<br>разархивирован<br>в папку:<br>'.str_replace('$', '&#036;', htmlspecialchars($pk, ENT_QUOTES)).'<br>'; }
  271. if($res == 4) {
  272. echo 'Папка:<br>'.str_replace('$', '&#036;', htmlspecialchars($name, ENT_QUOTES)).'<br>архивирована!<br>'; }
  273. if($res == 5) {
  274. echo 'Файл:<br>'.str_replace('$', '&#036;', htmlspecialchars($name, ENT_QUOTES)).'<br>архивирован!<br>'; }
  275. if($res == 1) {
  276. echo 'Произошла ошибка..<br>'; }
  277. echo '</small></p>';
  278. }
  279. echo '<form action="'.SURL.'/?ref='.$ref.'" method="get">'.
  280. '<p align="left" style="background-color: '.FORMS.'">'.
  281. '<small>---<br><u>Относительный путь</u>:</small><br>'.
  282. '<textarea name="name" title="Путь" cols="20" rows="4">../</textarea><br>'.
  283. '<small><u>Разархивировать в</u>:</small><br>'.
  284. '<textarea name="folder" title="Папка" cols="20" rows="4">../</textarea><br>'.
  285. '<small><u>Режим</u>:</small><br>'.
  286. '<select name="mod">'.
  287. '<option value="1" selected>Просмотр архива</option>'.
  288. '<option value="3">Разархивация</option>'.
  289. '<option value="2">Архивация</option>'.
  290. '</select><br>'.
  291. '<input type="hidden" name="log" value="'.$log.'">'.
  292. '<input type="hidden" name="pas" value="'.$pas.'">'.
  293. '<input type="hidden" name="un" value="1">'.
  294. '<input type="submit" value="Выполнить!">'.
  295. '</p></form>';
  296. echo '<p align="left">'.
  297. '<small>---<br><a href="'.SURL.'/?ref='.$ref.'">Выход</a></small>'.
  298. '</p></body></html>';
  299. break; }
  300. ?>