Compare commits

..

No commits in common. "c55d4afa87d3a6d708679851adf252ce3e62f8eb" and "c49cecf3a688a5e94bf62d5d438a62a4c58a7b72" have entirely different histories.

2 changed files with 23 additions and 13 deletions

View file

@ -1,14 +1,22 @@
<?php
// Adapted from https://wiki.archlinux.org/index.php/Awstats
/**
* Run old CGI applications through PHP
* @author Adrian Kousz
* @link https://wiki.archlinux.org/index.php/Awstats Source
*/
// Prepare environment
$newenv = $_SERVER;
$newenv["SCRIPT_FILENAME"] = $_SERVER["X_SCRIPT_FILENAME"];
$newenv["SCRIPT_NAME"] = $_SERVER["X_SCRIPT_NAME"];
$xScriptFilename = $_SERVER["X_SCRIPT_FILENAME"];
$xScriptName = $_SERVER["X_SCRIPT_NAME"];
$newenv["SCRIPT_FILENAME"] = $xScriptFilename;
$newenv["SCRIPT_NAME"] = $xScriptName;
if (!is_executable($_SERVER["X_SCRIPT_FILENAME"]) || is_dir($_SERVER["X_SCRIPT_FILENAME"]))
// Check file
if (!is_executable($xScriptFilename) || is_dir($xScriptFilename))
error_exit(404, 'Not Found');
// Open process
@ -19,7 +27,7 @@ $descriptorspec = array(
array('pipe', 'w'),
);
$pipes = array();
$process = proc_open($_SERVER["X_SCRIPT_FILENAME"], $descriptorspec, $pipes, null, $newenv);
$process = proc_open($xScriptFilename, $descriptorspec, $pipes, null, $newenv);
if (!is_resource($process))
error_exit(500, 'Internal Server Error');
@ -28,26 +36,29 @@ if (!is_resource($process))
while (true) {
$head = fgets($pipes[1]);
if ($head === false || $head === "\r\n" || $head === "\n") break;
if ($head === "\r\n" || $head === "\n") break;
header($head);
}
fpassthru($pipes[1]);
// Log errors
$scriptErrors = '';
while ($line = fgets($pipes[2])) $scriptErrors .= $line;
$scriptErrors = trim($scriptErrors);
if ($scriptErrors) trigger_error($scriptErrors, E_USER_NOTICE);
// Close
$scriptErrors = trim(stream_get_contents($pipes[2]));
foreach ($pipes as $fh) fclose($fh);
$returnValue = proc_close($process);
if ($scriptErrors) trigger_error("Status=$returnValue Error=$scriptErrors", E_USER_ERROR);
exit;
proc_close($process);
// Exit helper
function error_exit($code, $msg)
{
$err = "Error executing $_SERVER[X_SCRIPT_FILENAME]: $msg";
header("$_SERVER[SERVER_PROTOCOL] $code $msg");
echo($msg);
trigger_error($err, E_USER_ERROR);
exit(1);
exit;
}

View file

@ -3,7 +3,6 @@ REGEDIT4
[HKEY_CURRENT_USER\Console]
"ColorTable00"=dword:00403010
"ColorTable07"=dword:00d0c8c0
"ColorTable09"=dword:00ff9933
"FaceName"="Oxygen Mono"
"FontFamily"=dword:00000036
"FontSize"=dword:000c0000