summaryrefslogtreecommitdiff
path: root/shell/bin
diff options
context:
space:
mode:
Diffstat (limited to 'shell/bin')
-rw-r--r--shell/bin/cat.php7
-rw-r--r--shell/bin/cd.php5
-rw-r--r--shell/bin/chmod.php13
-rw-r--r--shell/bin/echo.php6
-rw-r--r--shell/bin/editor.php21
-rw-r--r--shell/bin/help.php12
-rw-r--r--shell/bin/ls.php34
-rw-r--r--shell/bin/pwd.php5
-rw-r--r--shell/bin/rm.php8
-rw-r--r--shell/bin/stat.php67
-rw-r--r--shell/bin/whoami.php4
11 files changed, 182 insertions, 0 deletions
diff --git a/shell/bin/cat.php b/shell/bin/cat.php
new file mode 100644
index 0000000..fab9883
--- /dev/null
+++ b/shell/bin/cat.php
@@ -0,0 +1,7 @@
+<?php
+function main($args) {
+ $me = array_shift($args);
+ foreach ($args as $file) {
+ echo htmlentities(file_get_contents($file));
+ }
+}
diff --git a/shell/bin/cd.php b/shell/bin/cd.php
new file mode 100644
index 0000000..3679e88
--- /dev/null
+++ b/shell/bin/cd.php
@@ -0,0 +1,5 @@
+<?php
+function main($args) {
+ @$dir = $args[1];
+ return php_chdir($dir);
+}
diff --git a/shell/bin/chmod.php b/shell/bin/chmod.php
new file mode 100644
index 0000000..ca66f56
--- /dev/null
+++ b/shell/bin/chmod.php
@@ -0,0 +1,13 @@
+<?php
+function main($args) {
+ $me = array_shift($args);
+ if (count($args)<2) {
+ echo $me.': usage: '.$me.' MODE FILE1 [FILE2 [FILE2]]'."\n";
+ return 1;
+ } else {
+ $mode = array_shift($args);
+ foreach ($args as $file) {
+ chmod($file,octdec($mode));
+ }
+ }
+} \ No newline at end of file
diff --git a/shell/bin/echo.php b/shell/bin/echo.php
new file mode 100644
index 0000000..82487b0
--- /dev/null
+++ b/shell/bin/echo.php
@@ -0,0 +1,6 @@
+<?php
+function main($args) {
+ array_shift($args);
+ echo implode(' ',$args)."\n";
+ return 0;
+}
diff --git a/shell/bin/editor.php b/shell/bin/editor.php
new file mode 100644
index 0000000..6eac87e
--- /dev/null
+++ b/shell/bin/editor.php
@@ -0,0 +1,21 @@
+<?php
+function main($args) {
+ if (isset($_POST['stdin'])) {
+ if (isset($args[1])) {
+ file_put_contents($args[1],$_POST['stdin']);
+ } else {
+ echo $_POST['stdin'];
+ }
+ } else {
+ if (isset($args[1]) && file_exists($args[1])) {
+ $text = file_get_contents($args[1]);
+ } else {
+ $text = '';
+ }
+ echo '<div class="editor">';
+ echo '<input type="hidden" name="stddest" value="'.$_POST['c'].'" />';
+ echo '<textarea name="stdin">'.$text.'</textarea>'."\n";
+ echo '<input type="submit" value="save" />';
+ echo '</div>';
+ }
+}
diff --git a/shell/bin/help.php b/shell/bin/help.php
new file mode 100644
index 0000000..95d2641
--- /dev/null
+++ b/shell/bin/help.php
@@ -0,0 +1,12 @@
+<?php
+function main($args, $env) {
+ $commands = array();
+ foreach (explode(';',$env['PATH']) as $dir) {
+ $commands = array_merge($commands,glob($dir.'/*.php'));
+ }
+ foreach ($commands as $command) {
+ echo preg_replace('@.*/([^/]*)\.php$@',"\$1\n",$command);
+ }
+ return 0;
+}
+
diff --git a/shell/bin/ls.php b/shell/bin/ls.php
new file mode 100644
index 0000000..fa01f2e
--- /dev/null
+++ b/shell/bin/ls.php
@@ -0,0 +1,34 @@
+<?php
+function main($args) {
+ if (count($args)<2) {
+ $args[]='.';
+ }
+ $ret=0;
+ $me = array_shift($args);
+ foreach ($args as $name) {
+ if (file_exists($name)) {
+ if (is_dir($name)) {
+ @$dh = opendir($name);
+ if ($dh === false) {
+ echo $me.': can not open directory: `'.$name."'\n";
+ $ret++;
+ } else {
+ if (count($args)>1) { echo $name.":\n"; }
+ $files = array();
+ while (false !== ($file = readdir($dh))) {
+ $files[]="$file";
+ }
+ sort($files);
+ echo implode("\n",$files)."\n";
+ closedir($dh);
+ }
+ } else {
+ echo $name."\n";
+ }
+ } else {
+ echo $me.': file does not exist: `'.$name."'\n";
+ $ret++;
+ }
+ }
+ return $ret;
+}
diff --git a/shell/bin/pwd.php b/shell/bin/pwd.php
new file mode 100644
index 0000000..2b43d00
--- /dev/null
+++ b/shell/bin/pwd.php
@@ -0,0 +1,5 @@
+<?php
+function main($args) {
+ echo getcwd()."\n";
+}
+
diff --git a/shell/bin/rm.php b/shell/bin/rm.php
new file mode 100644
index 0000000..7bb7aef
--- /dev/null
+++ b/shell/bin/rm.php
@@ -0,0 +1,8 @@
+<?php
+function main($args) {
+ $me = array_shift($args);
+ foreach ($args as $file) {
+ unlink($file);
+ }
+}
+
diff --git a/shell/bin/stat.php b/shell/bin/stat.php
new file mode 100644
index 0000000..2a13743
--- /dev/null
+++ b/shell/bin/stat.php
@@ -0,0 +1,67 @@
+ <?php
+ function perms($perms) {
+ if (($perms & 0xC000) == 0xC000) {
+ $info = 's'; // Socket
+ } elseif (($perms & 0xA000) == 0xA000) {
+ $info = 'l'; // Symbolic Link
+ } elseif (($perms & 0x8000) == 0x8000) {
+ $info = '-'; // Regular
+ } elseif (($perms & 0x6000) == 0x6000) {
+ $info = 'b'; // Block special
+ } elseif (($perms & 0x4000) == 0x4000) {
+ $info = 'd'; // Directory
+ } elseif (($perms & 0x2000) == 0x2000) {
+ $info = 'c'; // Character special
+ } elseif (($perms & 0x1000) == 0x1000) {
+ $info = 'p'; // FIFO pipe
+ } else {
+ $info = 'u'; // Unknown
+ }
+
+ // Owner
+ $info .= (($perms & 0x0100) ? 'r' : '-');
+ $info .= (($perms & 0x0080) ? 'w' : '-');
+ $info .= (($perms & 0x0040) ?
+ (($perms & 0x0800) ? 's' : 'x' ) :
+ (($perms & 0x0800) ? 'S' : '-'));
+
+ // Group
+ $info .= (($perms & 0x0020) ? 'r' : '-');
+ $info .= (($perms & 0x0010) ? 'w' : '-');
+ $info .= (($perms & 0x0008) ?
+ (($perms & 0x0400) ? 's' : 'x' ) :
+ (($perms & 0x0400) ? 'S' : '-'));
+
+ // World
+ $info .= (($perms & 0x0004) ? 'r' : '-');
+ $info .= (($perms & 0x0002) ? 'w' : '-');
+ $info .= (($perms & 0x0001) ?
+ (($perms & 0x0200) ? 't' : 'x' ) :
+ (($perms & 0x0200) ? 'T' : '-'));
+
+ return '('.substr(sprintf('%o',$perms),-4).'/'.$info.')';
+}
+
+function main($args) {
+ $me = array_shift($args);
+ $ret = 0;
+ foreach ($args as $file) {
+ $data = stat($file);
+ if ($data === false) {
+ echo $me.': cannot stat file: `'.$file."'\n";
+ $ret++;
+ } else {
+ echo ' File: `'.$file."'\n";
+ echo ' Size: '.$data['size']."\t";
+ echo 'Blocks: '.$data['blocks']."\t";
+ //echo 'IO Block: ';
+ echo $data['rdev']."\n";
+ echo 'Device: '.$data['dev']."\t";
+ echo 'Inode: '.$data['ino']."\t";
+ echo 'Links: '.$data['nlink']."\n";
+ echo 'Access: '.perms($data['mode'])."\t";
+ echo "\n";
+ }
+ }
+ return $ret;
+} \ No newline at end of file
diff --git a/shell/bin/whoami.php b/shell/bin/whoami.php
new file mode 100644
index 0000000..84db5a1
--- /dev/null
+++ b/shell/bin/whoami.php
@@ -0,0 +1,4 @@
+<?php
+function main($args) {
+ echo get_current_user();
+}