index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?PHP
  2. /**
  3. * Copyright 2021, 2024 5 Mode
  4. *
  5. * This file is part of Bugzilla PHP Wrapper.
  6. *
  7. * Bugzilla PHP Wrapper is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Bugzilla PHP Wrapper is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Bugzilla PHP Wrapper. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * index.php
  21. *
  22. * Bugzilla PHP Wrapper description of the file.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2016, 2024, 5 Mode
  26. */
  27. // SCRIPT_NAME
  28. $f = filter_input(INPUT_GET, 'perl_script');
  29. if ($f === "" || $f === "/") {
  30. $f = "/index.cgi";
  31. }
  32. if (substr($f,0,1)!=="/") {
  33. $f = "/".$f;
  34. }
  35. // QUERY_STRING
  36. $s = filter_input(INPUT_SERVER, 'QUERY_STRING');
  37. $s = explode("perl_script=$f", $s)[1];
  38. // Rebuilding the $_POST parameters..
  39. $formData = $_POST;
  40. foreach($formData as $key=>$val) {
  41. if ($f!=="/index.cgi" && ($key==="Bugzilla_login" || $key==="Bugzilla_password" || $key ==="Bugzilla_login_token" || $key==="GoAheadAndLogIn")) {
  42. } else {
  43. $s .= "&$key=".urlencode($val);
  44. }
  45. }
  46. if (substr($s,0,1) === "&") {
  47. $s = substr($s,1);
  48. }
  49. // SERVER VARIABLES
  50. putenv("QUERY_STRING=$s");
  51. putenv("local_timezone=Europe/Rome");
  52. putenv("SERVER_SOFTWARE=nginx");
  53. putenv("SERVER_NAME=" . $_SERVER['SERVER_NAME']);
  54. putenv("REQUEST_METHOD=" . $_SERVER['REQUEST_METHOD']);
  55. //putenv("REMOTE_ADDR=".$_SERVER['REMOTE_ADDR']);
  56. // Rebuilding the rest of $_SERVER variables environment..
  57. $serverEnvs = $_SERVER;
  58. foreach($serverEnvs as $key=>$val) {
  59. if (($key !== "QUERY_STRING") && ($key !== "SERVER_SOFTWARE") && ($key !== "SERVER_NAME") && ($key !== "REQUEST_METHOD")) {
  60. putenv("$key=".$val);
  61. }
  62. }
  63. $output = [];
  64. $r = exec("perl -T " . __DIR__ . $f, $output);
  65. if ($f==="/buglist.cgi" && array_count_values($output)['</html>']>1) {
  66. foreach($output as &$row) {
  67. if ($row === "</html>") {
  68. $row = "#### BLANK ####";
  69. break;
  70. } else {
  71. $row = "#### BLANK ####";
  72. }
  73. }
  74. }
  75. if ($f==="/for_debugging.cgi") {
  76. header("Content-Type: plain/html");
  77. echo("<html><body>");
  78. print_r($output);
  79. echo("</body></html>");
  80. exit(0);
  81. } else {
  82. $docParsing = false;
  83. foreach($output as $row) {
  84. if ($row!=="#### BLANK ####") {
  85. if ($row === "<!DOCTYPE html>") {
  86. $docParsing = true;
  87. }
  88. if ($docParsing) {
  89. echo($row."\n");
  90. } else {
  91. // echo("header=$row<br>");
  92. if (mb_strpos(strtolower($row), "set-cookie: bugzilla_login=") !== false) {
  93. // Parsing for the UserID on the Cookie request
  94. $userID = explode("=", explode(";", $row)[0])[1];
  95. // Creating the login cookie..
  96. setcookie("Bugzilla_login", $userID, time() + 999999999, "/", "bugs.5mode.com", true, true);
  97. } else {
  98. if ((mb_strpos($row, "--------- =") === false) && (mb_strpos($row, "WARNING:") === false)) {
  99. header($row);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }