Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [NGINX][FPM]{PHAR...] Ustawienie bloku
Forum PHP.pl > Forum > Serwery WWW
kpt_lucek
Więc tak, jakiś czas temu przejąłem projekt, dość spory, spakowany w pharze, gzinflate() itd.

Projekt co prawda mogę rozpakować, ale wtedy sypie się autoload, composera zainstalować nie mogę (a projekt jest o niego oparty) bo:
- poprzednia firma wciskała swoje prywatne paczki
- jest tylko composer.lock


Poprzednio stało to wszystko na apache2, z magiczną konfiguracją, to czego potrzebuje to względnie działająca konfiguracja pod nginx (tak ma być i już). Przesiedziałem całą noc i niestety google nie pomogło w tej kwestii.
Zawartość pliku index.php:
  1. <?php
  2.  
  3. $web = 'web.php';
  4.  
  5. if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
  6. Phar::interceptFileFuncs();
  7. set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
  8.  
  9. include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
  10. return;
  11. }
  12.  
  13. if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
  14. Extract_Phar::go(true);
  15. $mimes = array(
  16. 'phps' => 2,
  17. 'c' => 'text/plain',
  18. 'cc' => 'text/plain',
  19. 'cpp' => 'text/plain',
  20. 'c++' => 'text/plain',
  21. 'dtd' => 'text/plain',
  22. 'h' => 'text/plain',
  23. 'log' => 'text/plain',
  24. 'rng' => 'text/plain',
  25. 'txt' => 'text/plain',
  26. 'xsd' => 'text/plain',
  27. 'php' => 1,
  28. 'inc' => 1,
  29. 'avi' => 'video/avi',
  30. 'bmp' => 'image/bmp',
  31. 'css' => 'text/css',
  32. 'gif' => 'image/gif',
  33. 'htm' => 'text/html',
  34. 'html' => 'text/html',
  35. 'htmls' => 'text/html',
  36. 'ico' => 'image/x-ico',
  37. 'jpe' => 'image/jpeg',
  38. 'jpg' => 'image/jpeg',
  39. 'jpeg' => 'image/jpeg',
  40. 'js' => 'application/x-javascript',
  41. 'midi' => 'audio/midi',
  42. 'mid' => 'audio/midi',
  43. 'mod' => 'audio/mod',
  44. 'mov' => 'movie/quicktime',
  45. 'mp3' => 'audio/mp3',
  46. 'mpg' => 'video/mpeg',
  47. 'mpeg' => 'video/mpeg',
  48. 'pdf' => 'application/pdf',
  49. 'png' => 'image/png',
  50. 'swf' => 'application/shockwave-flash',
  51. 'tif' => 'image/tiff',
  52. 'tiff' => 'image/tiff',
  53. 'wav' => 'audio/wav',
  54. 'xbm' => 'image/xbm',
  55. 'xml' => 'text/xml',
  56. );
  57.  
  58. header("Cache-Control: no-cache, must-revalidate");
  59. header("Pragma: no-cache");
  60.  
  61. $basename = basename(__FILE__);
  62. if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
  63. chdir(Extract_Phar::$temp);
  64. include $web;
  65. return;
  66. }
  67. $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
  68. if (!$pt || $pt == '/') {
  69. $pt = $web;
  70. header('HTTP/1.1 301 Moved Permanently');
  71. header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
  72. }
  73. $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
  74. if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
  75. header('HTTP/1.0 404 Not Found');
  76. echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
  77. }
  78. $b = pathinfo($a);
  79. if (!isset($b['extension'])) {
  80. header('Content-Type: text/plain');
  81. header('Content-Length: ' . filesize($a));
  82. }
  83. if (isset($mimes[$b['extension']])) {
  84. if ($mimes[$b['extension']] === 1) {
  85. include $a;
  86. }
  87. if ($mimes[$b['extension']] === 2) {
  88. }
  89. header('Content-Type: ' .$mimes[$b['extension']]);
  90. header('Content-Length: ' . filesize($a));
  91. }
  92. }
  93.  
  94. class Extract_Phar
  95. {
  96. static $temp;
  97. static $origdir;
  98. const GZ = 0x1000;
  99. const BZ2 = 0x2000;
  100. const MASK = 0x3000;
  101. const START = 'web.php';
  102. const LEN = 6681;
  103.  
  104. static function go($return = false)
  105. {
  106. $fp = fopen(__FILE__, 'rb');
  107. fseek($fp, self::LEN);
  108. $L = unpack('V', $a = (binary)fread($fp, 4));
  109. $m = (binary)'';
  110.  
  111. do {
  112. $read = 8192;
  113. if ($L[1] - strlen($m) < 8192) {
  114. $read = $L[1] - strlen($m);
  115. }
  116. $last = (binary)fread($fp, $read);
  117. $m .= $last;
  118. } while (strlen($last) && strlen($m) < $L[1]);
  119.  
  120. if (strlen($m) < $L[1]) {
  121. die('ERROR: manifest length read was "' .
  122. strlen($m) .'" should be "' .
  123. $L[1] . '"');
  124. }
  125.  
  126. $info = self::_unpack($m);
  127. $f = $info['c'];
  128.  
  129. if ($f & self::GZ) {
  130. if (!function_exists('gzinflate')) {
  131. die('Error: zlib extension is not enabled -' .
  132. ' gzinflate() function needed for zlib-compressed .phars');
  133. }
  134. }
  135.  
  136. if ($f & self::BZ2) {
  137. if (!function_exists('bzdecompress')) {
  138. die('Error: bzip2 extension is not enabled -' .
  139. ' bzdecompress() function needed for bz2-compressed .phars');
  140. }
  141. }
  142.  
  143. $temp = self::tmpdir();
  144.  
  145. if (!$temp || !is_writable($temp)) {
  146. $sessionpath = session_save_path();
  147. if (strpos ($sessionpath, ";") !== false)
  148. $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
  149. if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
  150. die('Could not locate temporary directory to extract phar');
  151. }
  152. $temp = $sessionpath;
  153. }
  154.  
  155. $temp .= '/pharextract/'.basename(__FILE__, '.phar');
  156. self::$temp = $temp;
  157. self::$origdir = getcwd();
  158. @mkdir($temp, 0777, true);
  159. $temp = realpath($temp);
  160.  
  161. if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
  162. self::_removeTmpFiles($temp, getcwd());
  163. @mkdir($temp, 0777, true);
  164. @file_put_contents($temp . '/' . md5_file(__FILE__), '');
  165.  
  166. foreach ($info['m'] as $path => $file) {
  167. $a = !file_exists(dirname($temp . '/' . $path));
  168. @mkdir(dirname($temp . '/' . $path), 0777, true);
  169.  
  170. if ($path[strlen($path) - 1] == '/') {
  171. @mkdir($temp . '/' . $path, 0777);
  172. } else {
  173. file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
  174. @chmod($temp . '/' . $path, 0666);
  175. }
  176. }
  177. }
  178.  
  179. chdir($temp);
  180.  
  181. if (!$return) {
  182. include self::START;
  183. }
  184. }
  185.  
  186. static function tmpdir()
  187. {
  188. if (strpos(PHP_OS, 'WIN') !== false) {
  189. if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
  190. return $var;
  191. }
  192. if (is_dir('/temp') || mkdir('/temp')) {
  193. return realpath('/temp');
  194. }
  195. return false;
  196. }
  197. if ($var = getenv('TMPDIR')) {
  198. return $var;
  199. }
  200. return realpath('/tmp');
  201. }
  202.  
  203. static function _unpack($m)
  204. {
  205. $info = unpack('V', substr($m, 0, 4));
  206. $l = unpack('V', substr($m, 10, 4));
  207. $m = substr($m, 14 + $l[1]);
  208. $s = unpack('V', substr($m, 0, 4));
  209. $o = 0;
  210. $start = 4 + $s[1];
  211. $ret['c'] = 0;
  212.  
  213. for ($i = 0; $i < $info[1]; $i++) {
  214. $len = unpack('V', substr($m, $start, 4));
  215. $start += 4;
  216. $savepath = substr($m, $start, $len[1]);
  217. $start += $len[1];
  218. $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
  219. $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
  220. & 0xffffffff);
  221. $ret['m'][$savepath][7] = $o;
  222. $o += $ret['m'][$savepath][2];
  223. $start += 24 + $ret['m'][$savepath][5];
  224. $ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
  225. }
  226. return $ret;
  227. }
  228.  
  229. static function extractFile($path, $entry, $fp)
  230. {
  231. $data = '';
  232. $c = $entry[2];
  233.  
  234. while ($c) {
  235. if ($c < 8192) {
  236. $data .= @fread($fp, $c);
  237. $c = 0;
  238. } else {
  239. $c -= 8192;
  240. $data .= @fread($fp, 8192);
  241. }
  242. }
  243.  
  244. if ($entry[4] & self::GZ) {
  245. $data = gzinflate($data);
  246. } elseif ($entry[4] & self::BZ2) {
  247. $data = bzdecompress($data);
  248. }
  249.  
  250. if (strlen($data) != $entry[0]) {
  251. die("Invalid internal .phar file (size error " . strlen($data) . " != " .
  252. $stat[7] . ")");
  253. }
  254.  
  255. if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
  256. die("Invalid internal .phar file (checksum error)");
  257. }
  258.  
  259. return $data;
  260. }
  261.  
  262. static function _removeTmpFiles($temp, $origdir)
  263. {
  264. chdir($temp);
  265.  
  266. foreach (glob('*') as $f) {
  267. if (file_exists($f)) {
  268. is_dir($f) ? @rmdir($f) : @unlink($f);
  269. if (file_exists($f) && is_dir($f)) {
  270. self::_removeTmpFiles($f, getcwd());
  271. }
  272. }
  273. }
  274.  
  275. @rmdir($temp);
  276. chdir($origdir);
  277. }
  278. }
  279.  
  280. Extract_Phar::go();
  281. __HALT_COMPILER(); ?>


Niżej są krzaki odpowiadające za zawartość paczki.


Dzięki za pomoc
Pyton_000
Ale w czym jest problem ? Bo chyba tutaj nie widzę nic skomplikowanego.

root ustawiasz tam gdzie masz index.php, location ~ \.php standardowy.

Lepiej napisz z czym jest problem.

To że jest composer.lock to nic nie szkodzi bo odpalając `composer install` to właśnie z niego brane są wpisy.
Prywatne paczki też nie są problemem, o ile były wpisane do composera repozytoria z których są zaciągane.

To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.