Skip to content

Commit

Permalink
Add chrooted environment mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vincepare committed Dec 10, 2017
1 parent 929f8ac commit 9a1f710
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ DirScan is bundled with a text reporter, but you can customize its output by cre
Download dirscan.phar, make it executable (chmod +x dirscan.phar) and rename it if you want. On Linux, store it to `/usr/local/bin` to make it available everywhere :

```
wget -O dirscan https://github.com/vincepare/DirScan/releases/download/1.2.1/dirscan.phar
wget -O dirscan https://github.com/vincepare/DirScan/releases/download/1.3.0/dirscan.phar
chmod +x dirscan
sudo mv dirscan /usr/local/bin/dirscan
```

##### Update
```
wget -O "$(which dirscan)" https://github.com/vincepare/DirScan/releases/download/1.2.1/dirscan.phar
wget -O "$(which dirscan)" https://github.com/vincepare/DirScan/releases/download/1.3.0/dirscan.phar
```

### Requirement
Expand Down
2 changes: 2 additions & 0 deletions src/CliReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function header($targets, $argv)
$header = !empty($this->format) ? $this->getRowFormatHeader($this->format) : $this->getRowHeader();
echo "date: ".date('r (U)')."\n";
echo "getenv(TZ): ".getenv('TZ')."\n";
echo getenv('DIRSCAN_CHROOT') ? "DIRSCAN_CHROOT: " . getenv('DIRSCAN_CHROOT') . "\n" : "";
echo getenv('DIRSCAN_PWD') ? "DIRSCAN_PWD: " . getenv('DIRSCAN_PWD') . "\n" : "";
echo "date_default_timezone_get: ".date_default_timezone_get()."\n";
if (defined('DIRSCAN_VERSION')) {
echo "dirscan version: ".DIRSCAN_VERSION."\n";
Expand Down
13 changes: 11 additions & 2 deletions src/dirscan
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* @copyright © 2015 Vincent Paré
* @license http://opensource.org/licenses/Apache-2.0
* @package DirScan
* @version 1.2.1
* @version 1.3.0
*/

ini_set('log_errors', 0);
ini_set('display_errors', 'stderr');

const DIRSCAN_VERSION = '1.2.1';
const DIRSCAN_VERSION = '1.3.0';

require __DIR__.'/DirScan.php';
require __DIR__.'/Reporter.php';
Expand Down Expand Up @@ -42,6 +42,15 @@ Options :
EOT;

// Handling chroot mode
if (getenv('DIRSCAN_CHROOT')) {
chroot(getenv('DIRSCAN_CHROOT'));
}

if (getenv('DIRSCAN_PWD')) {
chdir(getenv('DIRSCAN_PWD'));
}

// Get settings
date_default_timezone_set('UTC');
$longopts = array('help', 'version', 'deep', 'flat', 'access', 'htime', 'perms', 'same-device', 'full', 'format::');
Expand Down
15 changes: 13 additions & 2 deletions src/legacy/dirscan
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* @copyright © 2015 Vincent Paré
* @license http://opensource.org/licenses/Apache-2.0
* @package DirScan
* @version 1.2.1-legacy
* @version 1.3.0-legacy
*/

ini_set('log_errors', 0);
ini_set('display_errors', 'stderr');

define('DIRSCAN_VERSION', '1.2.1-legacy');
define('DIRSCAN_VERSION', '1.3.0-legacy');

// Disabling realpath cache on php <= 5.2
ini_set('realpath_cache_size', '0');
Expand All @@ -40,6 +40,15 @@ Options :
EOT;

// Handling chroot mode
if (getenv('DIRSCAN_CHROOT')) {
chroot(getenv('DIRSCAN_CHROOT'));
}

if (getenv('DIRSCAN_PWD')) {
chdir(getenv('DIRSCAN_PWD'));
}

// Short options warning
foreach ($argv as $key => $val) {
if (preg_match('#^-[^-]#', $val)) {
Expand Down Expand Up @@ -415,6 +424,8 @@ class CliReporter extends Reporter
$header = !empty($this->format) ? $this->getRowFormatHeader($this->format) : $this->getRowHeader();
echo "date: ".date('r (U)')."\n";
echo "getenv(TZ): ".getenv('TZ')."\n";
echo getenv('DIRSCAN_CHROOT') ? "DIRSCAN_CHROOT: " . getenv('DIRSCAN_CHROOT') . "\n" : "";
echo getenv('DIRSCAN_PWD') ? "DIRSCAN_PWD: " . getenv('DIRSCAN_PWD') . "\n" : "";
echo "date_default_timezone_get: ".date_default_timezone_get()."\n";
if (defined('DIRSCAN_VERSION')) {
echo "dirscan version: ".DIRSCAN_VERSION."\n";
Expand Down

0 comments on commit 9a1f710

Please sign in to comment.