Skip to content

Commit

Permalink
Adjustments for default screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharthesavior committed Sep 14, 2024
1 parent 57c2060 commit fd35335
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
3 changes: 2 additions & 1 deletion jackit
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use Symfony\Component\Console\Application;

define('IS_PHAR', str_starts_with(__DIR__, 'phar:///'));
define('ROOT_DIR', IS_PHAR ? getcwd() : __DIR__);
define('CONFIG_FILE', __DIR__ . '/config/jacked-server.php');

const CONFIG_FILE = __DIR__ . '/config/jacked-server.php';
const MONITOR_CHANNEL = 'jacked-monitor';

$application = new Application;
Expand Down
19 changes: 2 additions & 17 deletions src/Commands/CompilePharCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$pharFile = $input->getArgument('output');
// $excludeDirs = ['tests', 'logs', 'docs'];

// clean up
if (file_exists($pharFile)) {
unlink($pharFile);
}
Expand All @@ -38,30 +38,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unlink($pharFile . '.gz');
}

// create phar
$phar = new Phar($pharFile);

// start buffering. Mandatory to modify stub to add shebang
$phar->startBuffering();

// Create the default stub from jackit.php entrypoint
$defaultStub = $phar->createDefaultStub('jackit');

// Add the rest of the apps files
$phar->buildFromDirectory(ROOT_DIR); // @phpstan-ignore-line

// Customize the stub to add the shebang
$defaultStub = $phar->createDefaultStub('jackit');
$stub = "#!/usr/bin/env php \n" . $defaultStub;

// Add the stub
$phar->setStub($stub);

$phar->stopBuffering();

// plus - compressing it into gzip
// $phar->compressFiles(Phar::GZ); // commented to avoid a known bug.

# Make the file executable
chmod($pharFile, 0770);

$output->writeln('<info>' . $pharFile . ' successfully created</info>');
Expand Down
12 changes: 12 additions & 0 deletions src/Services/Traits/HttpSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ protected function executeRequest(array $requestOptions, string $content, Respon
'requestOptions' => $requestOptions,
'content' => $content,
]);

if (
IS_PHAR
&& !file_exists(Arr::get($requestOptions, 'SCRIPT_FILENAME'))
&& Arr::get($requestOptions, 'REQUEST_URI') === '/'
) {
$response->write('<div style="width: 100%; text-align: center;">-- Jacked Server --</div>');
goto end_of_try;
}

$this->logger->info($this->logPrefix . 'Request Time: {time}', [
'time' => Carbon::now()->format('Y-m-d H:i:s'),
]);
Expand All @@ -169,6 +179,8 @@ protected function executeRequest(array $requestOptions, string $content, Respon
$result = $client->requestStream($requestOptions, $content, function ($data) use ($response) {
$response->write($data);
});

end_of_try:
} catch (Exception $e) {
$error = $e->getMessage();

Expand Down

0 comments on commit fd35335

Please sign in to comment.