123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?PHP
- /**
- * Copyright 2021, 2024 5 Mode
- *
- * This file is part of Bugzilla PHP Wrapper.
- *
- * Bugzilla PHP Wrapper is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Bugzilla PHP Wrapper is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Bugzilla PHP Wrapper. If not, see <https://www.gnu.org/licenses/>.
- *
- * index.php
- *
- * Bugzilla PHP Wrapper.
- *
- * @author Daniele Bonini <my25mb@aol.com>
- * @copyrights (c) 2016, 2024, 5 Mode
- */
-
- // Variables and constants
- define('BZ_WR_TIMEZONE', "Europe/Rome");
- define('BZ_WR_WEBSERVER', "nginx");
- $BZ_WR_COOKIE_PATH = "/";
- $BZ_WR_COOKIE_DOMAIN = "bugs.5mode.com";
- // SCRIPT_NAME
- $f = filter_input(INPUT_GET, 'perl_script')??"";
- $f = strip_tags($f);
- if ($f === "" || $f === "/") {
- $f = "/index.cgi";
- }
- if (substr($f,0,1)!=="/") {
- $f = "/".$f;
- }
-
- // QUERY_STRING
- $s = filter_input(INPUT_SERVER, 'QUERY_STRING');
- $s = explode("perl_script=$f", $s)[1];
- // Rebuilding the $_POST parameters..
- $formData = $_POST;
- foreach($formData as $key=>$val) {
- if ($f!=="/index.cgi" && ($key==="Bugzilla_login" || $key==="Bugzilla_password" || $key ==="Bugzilla_login_token" || $key==="GoAheadAndLogIn")) {
- } else {
- $s .= "&$key=".urlencode($val);
- }
- }
- if (substr($s,0,1) === "&") {
- $s = substr($s,1);
- }
- // SERVER VARIABLES
- putenv("QUERY_STRING=$s");
- putenv("local_timezone=".BZ_WR_TIMEZONE);
- putenv("SERVER_SOFTWARE=".BZ_WR_WEBSERVER);
- putenv("SERVER_NAME=" . $_SERVER['SERVER_NAME']);
- putenv("REQUEST_METHOD=" . $_SERVER['REQUEST_METHOD']);
- putenv("REMOTE_ADDR=" . $_SERVER['REMOTE_ADDR']);
- // Rebuilding the rest of $_SERVER variables environment..
- $serverEnvs = $_SERVER;
- foreach($serverEnvs as $key=>$val) {
- if (($key !== "QUERY_STRING") && ($key !== "SERVER_SOFTWARE") && ($key !== "SERVER_NAME") && ($key !== "REQUEST_METHOD") && ($key !== "REMOTE_ADDR")) {
- putenv("$key=".$val);
- }
- }
- $output = [];
- $r = exec("perl -T " . __DIR__ . $f, $output);
- if ($f==="/buglist.cgi" && array_count_values($output)['</html>']>1) {
- foreach($output as &$row) {
- if ($row === "</html>") {
- $row = "#### BLANK ####";
- break;
- } else {
- $row = "#### BLANK ####";
- }
- }
- }
- if ($f==="/for_debugging.cgi") {
- header("Content-Type: plain/html");
- echo("<html><body>");
- print_r($output);
- echo("</body></html>");
- exit(0);
-
- } else {
- $docParsing = false;
- foreach($output as $row) {
- if ($row!=="#### BLANK ####") {
- if ($row === "<!DOCTYPE html>") {
- $docParsing = true;
- }
- if ($docParsing) {
- echo($row."\n");
- } else {
- //echo("header=$row<br>");
- if (mb_strpos(strtolower($row), "set-cookie: bugzilla_login=") !== false) {
- // Parsing for the UserID on the Cookie request
- $userID = explode("=", explode(";", $row)[0])[1];
- // Creating the login cookie..
- $ret=@setcookie("Bugzilla_login", $userID, time() + 999999999, $BZ_WR_COOKIE_PATH, $BZ_WR_COOKIE_DOMAIN, true, true);
- //echo("ret=$ret<br>");
- if ($ret) {
- $_COOKIE["Bugzilla_login"] = $userID;
- }
- } else {
- if ((mb_strpos($row, "--------- =") === false) && (mb_strpos($row, "WARNING:") === false)) {
- header($row);
- }
- }
- }
- }
- }
- }
|