compiler.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. if(!DEFINED('EGP'))
  3. exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
  4. if($go)
  5. {
  6. function createPostString($aPostFields)
  7. {
  8. foreach($aPostFields as $key => $value)
  9. $aPostFields[$key] = urlencode($key).'='. urlencode($value);
  10. return implode('&', $aPostFields);
  11. }
  12. $sql->query('SELECT `browser` FROM `users` WHERE `id`="'.$user['id'].'" LIMIT 1');
  13. $u_sql = $sql->get();
  14. $browser = base64_decode($u_sql['browser']);
  15. $file = $_FILES['file_code'];
  16. if(substr($file['name'], -4) != '.sma')
  17. sys::outjs(array('e' => 'Только .sma разрешается загружать'));
  18. $text = file_get_contents($file['tmp_name']);
  19. $textArray = explode("\n", $text);
  20. $postFields['fname'] = $file['name'];
  21. $postFields['scode'] = $textArray;
  22. $postFields['go'] = 'send';
  23. $ch = curl_init('http://amxmodx.org/webcompiler.cgi');
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  25. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3');
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, createPostString($postFields));
  27. $tresc = curl_exec($ch);
  28. sys::out($tresc);
  29. curl_close($ch);
  30. if(strpos($tresc, 'Your plugin successfully compiled!'))
  31. {
  32. $tresc = substr($tresc, strpos($tresc, "http://www.amxmodx.org/webcompiler.cgi?"));
  33. $ile = strpos($tresc, "</a>");
  34. $link = substr($tresc, 0, $ile);
  35. $tresc = substr($tresc, strpos($tresc, "Welcome to the AMX Mod X"));
  36. $ile = strpos($tresc, "</pre>");
  37. $inf = substr($tresc, 0, $ile);
  38. $inf = str_replace("\r\n","<br/ >", $inf);
  39. $out = '
  40. <br><center>Ваш плагин скомпилирован <span class="compiller_good"><b>удачно</b></span><br><br>
  41. Чтобы скачать пройдите по <a href="'.$link.'"><b>ссылке</b></a><br />
  42. <a href="javascript:void(0)" onclick="ShowHideLog(\'block_id\')">Посмотреть лог компиляции</a><br/><br/>
  43. <div id="block_id" style="display: none;">
  44. <pre>'.$inf.'</pre>
  45. </div>
  46. </center>';
  47. $good = "good.txt";
  48. if(!file_exists(FILES.$good))
  49. {
  50. $handle = fopen(FILES.$good, "w");
  51. $count_good = 0;
  52. fwrite($handle, $count_good);
  53. fclose($handle);
  54. }else{
  55. $file = file(FILES.$good);
  56. $count_good = $file[0];
  57. }
  58. $count_good++;
  59. $handle = fopen(FILES.$good, "w");
  60. fwrite($handle, $count_good);
  61. fclose($handle);
  62. }else{
  63. $ktory = strpos($tresc, "Your plugin failed to compile");
  64. $tresc = substr($tresc, $ktory + 63);
  65. $ile = strpos($tresc, "</pre>");
  66. $tresc = substr($tresc, 0, $ile);
  67. $out = '
  68. <br><center>Ваш плагин скомпилирован <span class="compiller_failed"><b>неудачно</b></span><br><br>
  69. <a href="javascript:void(0)" onclick="ShowHideLog(\'block_id\')">Посмотреть лог ошибок</a><br/><br/>
  70. <div id="block_id" style="display: none;">
  71. <pre>'.$tresc.'</pre>
  72. </div>
  73. </center>
  74. ';
  75. $failed = "failed.txt";
  76. if(!file_exists(FILES.$failed))
  77. {
  78. $handle = fopen(FILES.$failed, "w");
  79. $count_failed = 0;
  80. fwrite($handle, $count_failed);
  81. fclose($handle);
  82. }else{
  83. $file = file(FILES.$failed);
  84. $count_failed = $file[0];
  85. }
  86. $count_failed++;
  87. $handle = fopen(FILES.$failed, "w");
  88. fwrite($handle, $count_failed);
  89. fclose($handle);
  90. }
  91. }else{
  92. $good = "good.txt";
  93. $failed = "failed.txt";
  94. if(!file_exists(FILES.$good))
  95. {
  96. $handle = fopen(FILES.$good, "w");
  97. $count_good = 0;
  98. fwrite($handle, $count_good);
  99. fclose($handle);
  100. }else{
  101. $file = file(FILES.$good);
  102. $count_good = $file[0];
  103. }
  104. if(!file_exists(FILES.$failed))
  105. {
  106. $handle = fopen(FILES.$failed, "w");
  107. $count_failed = 0;
  108. fwrite($handle, $count_failed);
  109. fclose($handle);
  110. }else{
  111. $file = file(FILES.$failed);
  112. $count_failed = $file[0];
  113. }
  114. $html->get('compiler', 'sections/check');
  115. $html->set('success', $count_good);
  116. $html->set('failed', $count_failed);
  117. $html->pack('compilers');
  118. include(SEC.'check/index.php');
  119. }
  120. ?>