Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env php
- <?php
- $sudo = false;
- $cmd = ['sudo', '/bin/nano'];
- foreach(array_slice($argv, 1) as $arg) {
- $cmd[] = escapeshellarg($arg);
- if($sudo) {
- continue;
- }
- if(substr($arg, 0, 1) === '-') {
- continue;
- }
- if(file_exists($arg)) {
- if(!is_writable($arg)) {
- $sudo = true;
- }
- continue;
- }
- $dir = dirname($arg);
- if(is_dir($dir)) {
- if(!is_writable($dir)) {
- $sudo = true;
- }
- continue;
- }
- }
- if(!$sudo) {
- unset($cmd[0]);
- }
- passthru(implode(' ', $cmd));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement