From 1fd7ee5b66aa918cc5e3e3f08565123d76b6778b Mon Sep 17 00:00:00 2001 From: hanyixuanten Date: Sun, 14 Jul 2024 19:54:48 +0800 Subject: [PATCH] add command:mkdir.fixbug.optimize command help --- static/help/help.txt | 3 ++- static/help/mkdir.txt | 2 ++ static/terminal.php/help.txt | 1 + terminal.php | 14 +++++++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 static/help/mkdir.txt diff --git a/static/help/help.txt b/static/help/help.txt index b854377..197c289 100644 --- a/static/help/help.txt +++ b/static/help/help.txt @@ -1 +1,2 @@ -help - displays the help message
\ No newline at end of file +help - displays the help message
+help [command] displays the help message for a specific command
\ No newline at end of file diff --git a/static/help/mkdir.txt b/static/help/mkdir.txt new file mode 100644 index 0000000..9f7890b --- /dev/null +++ b/static/help/mkdir.txt @@ -0,0 +1,2 @@ +mkdir - creates a new directory
+if the directory already exists, an error is returned
diff --git a/static/terminal.php/help.txt b/static/terminal.php/help.txt index e3bbb3f..b1ff1b0 100644 --- a/static/terminal.php/help.txt +++ b/static/terminal.php/help.txt @@ -1,4 +1,5 @@ clear - clears the screen
pwd - shows the working directory
+mkdir - creates a new directory
help - displays this help message
type help [command] to show more details
\ No newline at end of file diff --git a/terminal.php b/terminal.php index 0ed826a..dbf4b96 100644 --- a/terminal.php +++ b/terminal.php @@ -7,8 +7,8 @@ if (file_get_contents("recent.txt") == NULL) { if (file_get_contents("pwd.txt") == NULL) { file_put_contents("pwd.txt", "/"); } -if(!opendir("fileroot")){ - if(!mkdir("fileroot")){ +if (!opendir("fileroot")) { + if (!mkdir("fileroot")) { echo "Error creating directory.No permissions?"; exit(0); } @@ -29,7 +29,7 @@ if(!opendir("fileroot")){ ", FILE_APPEND); + file_put_contents("recent.txt", $pwd . " $ " . $_POST['command'] . "
", FILE_APPEND); $output_str = file_get_contents("recent.txt"); echo $output_str; if ($commands[0] == NULL) { @@ -37,6 +37,14 @@ if(!opendir("fileroot")){ exit(0); } else if ($commands[0] == "pwd") { file_put_contents("recent.txt", $pwd . "
", FILE_APPEND); + } else if ($commands[0] == "mkdir" && sizeof($commands) == 2) { + if (!opendir("fileroot/".$commands[1])) { + if (!mkdir("fileroot/".$commands[1])) { + file_put_contents("recent.txt", "Error creating directory.No permissions?
", FILE_APPEND); + } + } else { + file_put_contents("recent.txt", "Directory already exists.
", FILE_APPEND); + } } else if ($commands[0] == "clear") { file_put_contents("recent.txt", ""); } else if ($commands[0] == "help") {